1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2021 Free Software Foundation, Inc.
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
12 This file is part of GDB.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 /* FIXME: Various die-reading functions need to be more careful with
28 reading off the end of the section.
29 E.g., load_partial_dies, read_partial_die. */
32 #include "dwarf2/read.h"
33 #include "dwarf2/abbrev.h"
34 #include "dwarf2/attribute.h"
35 #include "dwarf2/comp-unit.h"
36 #include "dwarf2/index-cache.h"
37 #include "dwarf2/index-common.h"
38 #include "dwarf2/leb.h"
39 #include "dwarf2/line-header.h"
40 #include "dwarf2/dwz.h"
41 #include "dwarf2/macro.h"
42 #include "dwarf2/die.h"
43 #include "dwarf2/sect-names.h"
44 #include "dwarf2/stringify.h"
45 #include "dwarf2/public.h"
54 #include "gdb-demangle.h"
55 #include "filenames.h" /* for DOSish file names */
57 #include "complaints.h"
58 #include "dwarf2/expr.h"
59 #include "dwarf2/loc.h"
60 #include "cp-support.h"
66 #include "typeprint.h"
71 #include "gdbcore.h" /* for gnutarget */
72 #include "gdb/gdb-index.h"
77 #include "namespace.h"
78 #include "gdbsupport/function-view.h"
79 #include "gdbsupport/gdb_optional.h"
80 #include "gdbsupport/underlying.h"
81 #include "gdbsupport/hash_enum.h"
82 #include "filename-seen-cache.h"
86 #include <unordered_map>
87 #include "gdbsupport/selftest.h"
88 #include "rust-lang.h"
89 #include "gdbsupport/pathstuff.h"
90 #include "count-one-bits.h"
92 /* When == 1, print basic high level tracing messages.
93 When > 1, be more verbose.
94 This is in contrast to the low level DIE reading of dwarf_die_debug. */
95 static unsigned int dwarf_read_debug
= 0;
97 /* Print a "dwarf-read" debug statement if dwarf_read_debug is >= 1. */
99 #define dwarf_read_debug_printf(fmt, ...) \
100 debug_prefixed_printf_cond (dwarf_read_debug >= 1, "dwarf-read", fmt, \
103 /* Print a "dwarf-read" debug statement if dwarf_read_debug is >= 2. */
105 #define dwarf_read_debug_printf_v(fmt, ...) \
106 debug_prefixed_printf_cond (dwarf_read_debug >= 2, "dwarf-read", fmt, \
109 /* When non-zero, dump DIEs after they are read in. */
110 static unsigned int dwarf_die_debug
= 0;
112 /* When non-zero, dump line number entries as they are read in. */
113 unsigned int dwarf_line_debug
= 0;
115 /* When true, cross-check physname against demangler. */
116 static bool check_physname
= false;
118 /* When true, do not reject deprecated .gdb_index sections. */
119 static bool use_deprecated_index_sections
= false;
121 /* This is used to store the data that is always per objfile. */
122 static const objfile_key
<dwarf2_per_objfile
> dwarf2_objfile_data_key
;
124 /* These are used to store the dwarf2_per_bfd objects.
126 objfiles having the same BFD, which doesn't require relocations, are going to
127 share a dwarf2_per_bfd object, which is held in the _bfd_data_key version.
129 Other objfiles are not going to share a dwarf2_per_bfd with any other
130 objfiles, so they'll have their own version kept in the _objfile_data_key
132 static const struct bfd_key
<dwarf2_per_bfd
> dwarf2_per_bfd_bfd_data_key
;
133 static const struct objfile_key
<dwarf2_per_bfd
> dwarf2_per_bfd_objfile_data_key
;
135 /* The "aclass" indices for various kinds of computed DWARF symbols. */
137 static int dwarf2_locexpr_index
;
138 static int dwarf2_loclist_index
;
139 static int dwarf2_locexpr_block_index
;
140 static int dwarf2_loclist_block_index
;
142 /* Size of .debug_loclists section header for 32-bit DWARF format. */
143 #define LOCLIST_HEADER_SIZE32 12
145 /* Size of .debug_loclists section header for 64-bit DWARF format. */
146 #define LOCLIST_HEADER_SIZE64 20
148 /* Size of .debug_rnglists section header for 32-bit DWARF format. */
149 #define RNGLIST_HEADER_SIZE32 12
151 /* Size of .debug_rnglists section header for 64-bit DWARF format. */
152 #define RNGLIST_HEADER_SIZE64 20
154 /* An index into a (C++) symbol name component in a symbol name as
155 recorded in the mapped_index's symbol table. For each C++ symbol
156 in the symbol table, we record one entry for the start of each
157 component in the symbol in a table of name components, and then
158 sort the table, in order to be able to binary search symbol names,
159 ignoring leading namespaces, both completion and regular look up.
160 For example, for symbol "A::B::C", we'll have an entry that points
161 to "A::B::C", another that points to "B::C", and another for "C".
162 Note that function symbols in GDB index have no parameter
163 information, just the function/method names. You can convert a
164 name_component to a "const char *" using the
165 'mapped_index::symbol_name_at(offset_type)' method. */
167 struct name_component
169 /* Offset in the symbol name where the component starts. Stored as
170 a (32-bit) offset instead of a pointer to save memory and improve
171 locality on 64-bit architectures. */
172 offset_type name_offset
;
174 /* The symbol's index in the symbol and constant pool tables of a
179 /* Base class containing bits shared by both .gdb_index and
180 .debug_name indexes. */
182 struct mapped_index_base
184 mapped_index_base () = default;
185 DISABLE_COPY_AND_ASSIGN (mapped_index_base
);
187 /* The name_component table (a sorted vector). See name_component's
188 description above. */
189 std::vector
<name_component
> name_components
;
191 /* How NAME_COMPONENTS is sorted. */
192 enum case_sensitivity name_components_casing
;
194 /* Return the number of names in the symbol table. */
195 virtual size_t symbol_name_count () const = 0;
197 /* Get the name of the symbol at IDX in the symbol table. */
198 virtual const char *symbol_name_at
199 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const = 0;
201 /* Return whether the name at IDX in the symbol table should be
203 virtual bool symbol_name_slot_invalid (offset_type idx
) const
208 /* Build the symbol name component sorted vector, if we haven't
210 void build_name_components (dwarf2_per_objfile
*per_objfile
);
212 /* Returns the lower (inclusive) and upper (exclusive) bounds of the
213 possible matches for LN_NO_PARAMS in the name component
215 std::pair
<std::vector
<name_component
>::const_iterator
,
216 std::vector
<name_component
>::const_iterator
>
217 find_name_components_bounds (const lookup_name_info
&ln_no_params
,
219 dwarf2_per_objfile
*per_objfile
) const;
221 /* Prevent deleting/destroying via a base class pointer. */
223 ~mapped_index_base() = default;
226 /* A description of the mapped index. The file format is described in
227 a comment by the code that writes the index. */
228 struct mapped_index final
: public mapped_index_base
230 /* A slot/bucket in the symbol table hash. */
231 struct symbol_table_slot
233 const offset_type name
;
234 const offset_type vec
;
237 /* Index data format version. */
240 /* The address table data. */
241 gdb::array_view
<const gdb_byte
> address_table
;
243 /* The symbol table, implemented as a hash table. */
244 gdb::array_view
<symbol_table_slot
> symbol_table
;
246 /* A pointer to the constant pool. */
247 const char *constant_pool
= nullptr;
249 bool symbol_name_slot_invalid (offset_type idx
) const override
251 const auto &bucket
= this->symbol_table
[idx
];
252 return bucket
.name
== 0 && bucket
.vec
== 0;
255 /* Convenience method to get at the name of the symbol at IDX in the
257 const char *symbol_name_at
258 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
259 { return this->constant_pool
+ MAYBE_SWAP (this->symbol_table
[idx
].name
); }
261 size_t symbol_name_count () const override
262 { return this->symbol_table
.size (); }
265 /* A description of the mapped .debug_names.
266 Uninitialized map has CU_COUNT 0. */
267 struct mapped_debug_names final
: public mapped_index_base
269 bfd_endian dwarf5_byte_order
;
270 bool dwarf5_is_dwarf64
;
271 bool augmentation_is_gdb
;
273 uint32_t cu_count
= 0;
274 uint32_t tu_count
, bucket_count
, name_count
;
275 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
276 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
277 const gdb_byte
*name_table_string_offs_reordered
;
278 const gdb_byte
*name_table_entry_offs_reordered
;
279 const gdb_byte
*entry_pool
;
286 /* Attribute name DW_IDX_*. */
289 /* Attribute form DW_FORM_*. */
292 /* Value if FORM is DW_FORM_implicit_const. */
293 LONGEST implicit_const
;
295 std::vector
<attr
> attr_vec
;
298 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
300 const char *namei_to_name
301 (uint32_t namei
, dwarf2_per_objfile
*per_objfile
) const;
303 /* Implementation of the mapped_index_base virtual interface, for
304 the name_components cache. */
306 const char *symbol_name_at
307 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
308 { return namei_to_name (idx
, per_objfile
); }
310 size_t symbol_name_count () const override
311 { return this->name_count
; }
314 /* See dwarf2read.h. */
317 get_dwarf2_per_objfile (struct objfile
*objfile
)
319 return dwarf2_objfile_data_key
.get (objfile
);
322 /* Default names of the debugging sections. */
324 /* Note that if the debugging section has been compressed, it might
325 have a name like .zdebug_info. */
327 const struct dwarf2_debug_sections dwarf2_elf_names
=
329 { ".debug_info", ".zdebug_info" },
330 { ".debug_abbrev", ".zdebug_abbrev" },
331 { ".debug_line", ".zdebug_line" },
332 { ".debug_loc", ".zdebug_loc" },
333 { ".debug_loclists", ".zdebug_loclists" },
334 { ".debug_macinfo", ".zdebug_macinfo" },
335 { ".debug_macro", ".zdebug_macro" },
336 { ".debug_str", ".zdebug_str" },
337 { ".debug_str_offsets", ".zdebug_str_offsets" },
338 { ".debug_line_str", ".zdebug_line_str" },
339 { ".debug_ranges", ".zdebug_ranges" },
340 { ".debug_rnglists", ".zdebug_rnglists" },
341 { ".debug_types", ".zdebug_types" },
342 { ".debug_addr", ".zdebug_addr" },
343 { ".debug_frame", ".zdebug_frame" },
344 { ".eh_frame", NULL
},
345 { ".gdb_index", ".zgdb_index" },
346 { ".debug_names", ".zdebug_names" },
347 { ".debug_aranges", ".zdebug_aranges" },
351 /* List of DWO/DWP sections. */
353 static const struct dwop_section_names
355 struct dwarf2_section_names abbrev_dwo
;
356 struct dwarf2_section_names info_dwo
;
357 struct dwarf2_section_names line_dwo
;
358 struct dwarf2_section_names loc_dwo
;
359 struct dwarf2_section_names loclists_dwo
;
360 struct dwarf2_section_names macinfo_dwo
;
361 struct dwarf2_section_names macro_dwo
;
362 struct dwarf2_section_names rnglists_dwo
;
363 struct dwarf2_section_names str_dwo
;
364 struct dwarf2_section_names str_offsets_dwo
;
365 struct dwarf2_section_names types_dwo
;
366 struct dwarf2_section_names cu_index
;
367 struct dwarf2_section_names tu_index
;
371 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
372 { ".debug_info.dwo", ".zdebug_info.dwo" },
373 { ".debug_line.dwo", ".zdebug_line.dwo" },
374 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
375 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
376 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
377 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
378 { ".debug_rnglists.dwo", ".zdebug_rnglists.dwo" },
379 { ".debug_str.dwo", ".zdebug_str.dwo" },
380 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
381 { ".debug_types.dwo", ".zdebug_types.dwo" },
382 { ".debug_cu_index", ".zdebug_cu_index" },
383 { ".debug_tu_index", ".zdebug_tu_index" },
386 /* local data types */
388 /* The location list and range list sections (.debug_loclists & .debug_rnglists)
389 begin with a header, which contains the following information. */
390 struct loclists_rnglists_header
392 /* A 4-byte or 12-byte length containing the length of the
393 set of entries for this compilation unit, not including the
394 length field itself. */
397 /* A 2-byte version identifier. */
400 /* A 1-byte unsigned integer containing the size in bytes of an address on
401 the target system. */
402 unsigned char addr_size
;
404 /* A 1-byte unsigned integer containing the size in bytes of a segment selector
405 on the target system. */
406 unsigned char segment_collector_size
;
408 /* A 4-byte count of the number of offsets that follow the header. */
409 unsigned int offset_entry_count
;
412 /* Type used for delaying computation of method physnames.
413 See comments for compute_delayed_physnames. */
414 struct delayed_method_info
416 /* The type to which the method is attached, i.e., its parent class. */
419 /* The index of the method in the type's function fieldlists. */
422 /* The index of the method in the fieldlist. */
425 /* The name of the DIE. */
428 /* The DIE associated with this method. */
429 struct die_info
*die
;
432 /* Internal state when decoding a particular compilation unit. */
435 explicit dwarf2_cu (dwarf2_per_cu_data
*per_cu
,
436 dwarf2_per_objfile
*per_objfile
);
438 DISABLE_COPY_AND_ASSIGN (dwarf2_cu
);
440 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
441 Create the set of symtabs used by this TU, or if this TU is sharing
442 symtabs with another TU and the symtabs have already been created
443 then restore those symtabs in the line header.
444 We don't need the pc/line-number mapping for type units. */
445 void setup_type_unit_groups (struct die_info
*die
);
447 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
448 buildsym_compunit constructor. */
449 struct compunit_symtab
*start_symtab (const char *name
,
450 const char *comp_dir
,
453 /* Reset the builder. */
454 void reset_builder () { m_builder
.reset (); }
456 /* Return a type that is a generic pointer type, the size of which
457 matches the address size given in the compilation unit header for
459 struct type
*addr_type () const;
461 /* Find an integer type the same size as the address size given in
462 the compilation unit header for this CU. UNSIGNED_P controls if
463 the integer is unsigned or not. */
464 struct type
*addr_sized_int_type (bool unsigned_p
) const;
466 /* The header of the compilation unit. */
467 struct comp_unit_head header
{};
469 /* Base address of this compilation unit. */
470 gdb::optional
<CORE_ADDR
> base_address
;
472 /* The language we are debugging. */
473 enum language language
= language_unknown
;
474 const struct language_defn
*language_defn
= nullptr;
476 const char *producer
= nullptr;
479 /* The symtab builder for this CU. This is only non-NULL when full
480 symbols are being read. */
481 std::unique_ptr
<buildsym_compunit
> m_builder
;
484 /* The generic symbol table building routines have separate lists for
485 file scope symbols and all all other scopes (local scopes). So
486 we need to select the right one to pass to add_symbol_to_list().
487 We do it by keeping a pointer to the correct list in list_in_scope.
489 FIXME: The original dwarf code just treated the file scope as the
490 first local scope, and all other local scopes as nested local
491 scopes, and worked fine. Check to see if we really need to
492 distinguish these in buildsym.c. */
493 struct pending
**list_in_scope
= nullptr;
495 /* Hash table holding all the loaded partial DIEs
496 with partial_die->offset.SECT_OFF as hash. */
497 htab_t partial_dies
= nullptr;
499 /* Storage for things with the same lifetime as this read-in compilation
500 unit, including partial DIEs. */
501 auto_obstack comp_unit_obstack
;
503 /* Backlink to our per_cu entry. */
504 struct dwarf2_per_cu_data
*per_cu
;
506 /* The dwarf2_per_objfile that owns this. */
507 dwarf2_per_objfile
*per_objfile
;
509 /* How many compilation units ago was this CU last referenced? */
512 /* A hash table of DIE cu_offset for following references with
513 die_info->offset.sect_off as hash. */
514 htab_t die_hash
= nullptr;
516 /* Full DIEs if read in. */
517 struct die_info
*dies
= nullptr;
519 /* A set of pointers to dwarf2_per_cu_data objects for compilation
520 units referenced by this one. Only set during full symbol processing;
521 partial symbol tables do not have dependencies. */
522 htab_t dependencies
= nullptr;
524 /* Header data from the line table, during full symbol processing. */
525 struct line_header
*line_header
= nullptr;
526 /* Non-NULL if LINE_HEADER is owned by this DWARF_CU. Otherwise,
527 it's owned by dwarf2_per_bfd::line_header_hash. If non-NULL,
528 this is the DW_TAG_compile_unit die for this CU. We'll hold on
529 to the line header as long as this DIE is being processed. See
530 process_die_scope. */
531 die_info
*line_header_die_owner
= nullptr;
533 /* A list of methods which need to have physnames computed
534 after all type information has been read. */
535 std::vector
<delayed_method_info
> method_list
;
537 /* To be copied to symtab->call_site_htab. */
538 htab_t call_site_htab
= nullptr;
540 /* Non-NULL if this CU came from a DWO file.
541 There is an invariant here that is important to remember:
542 Except for attributes copied from the top level DIE in the "main"
543 (or "stub") file in preparation for reading the DWO file
544 (e.g., DW_AT_addr_base), we KISS: there is only *one* CU.
545 Either there isn't a DWO file (in which case this is NULL and the point
546 is moot), or there is and either we're not going to read it (in which
547 case this is NULL) or there is and we are reading it (in which case this
549 struct dwo_unit
*dwo_unit
= nullptr;
551 /* The DW_AT_addr_base (DW_AT_GNU_addr_base) attribute if present.
552 Note this value comes from the Fission stub CU/TU's DIE. */
553 gdb::optional
<ULONGEST
> addr_base
;
555 /* The DW_AT_GNU_ranges_base attribute, if present.
557 This is only relevant in the context of pre-DWARF 5 split units. In this
558 context, there is a .debug_ranges section in the linked executable,
559 containing all the ranges data for all the compilation units. Each
560 skeleton/stub unit has (if needed) a DW_AT_GNU_ranges_base attribute that
561 indicates the base of its contribution to that section. The DW_AT_ranges
562 attributes in the split-unit are of the form DW_FORM_sec_offset and point
563 into the .debug_ranges section of the linked file. However, they are not
564 "true" DW_FORM_sec_offset, because they are relative to the base of their
565 compilation unit's contribution, rather than relative to the beginning of
566 the section. The DW_AT_GNU_ranges_base value must be added to it to make
567 it relative to the beginning of the section.
569 Note that the value is zero when we are not in a pre-DWARF 5 split-unit
570 case, so this value can be added without needing to know whether we are in
573 N.B. If a DW_AT_ranges attribute is found on the DW_TAG_compile_unit in the
574 skeleton/stub, it must not have the base added, as it already points to the
575 right place. And since the DW_TAG_compile_unit DIE in the split-unit can't
576 have a DW_AT_ranges attribute, we can use the
578 die->tag != DW_AT_compile_unit
580 to determine whether the base should be added or not. */
581 ULONGEST gnu_ranges_base
= 0;
583 /* The DW_AT_rnglists_base attribute, if present.
585 This is used when processing attributes of form DW_FORM_rnglistx in
586 non-split units. Attributes of this form found in a split unit don't
587 use it, as split-unit files have their own non-shared .debug_rnglists.dwo
589 ULONGEST rnglists_base
= 0;
591 /* The DW_AT_loclists_base attribute if present. */
592 ULONGEST loclist_base
= 0;
594 /* When reading debug info generated by older versions of rustc, we
595 have to rewrite some union types to be struct types with a
596 variant part. This rewriting must be done after the CU is fully
597 read in, because otherwise at the point of rewriting some struct
598 type might not have been fully processed. So, we keep a list of
599 all such types here and process them after expansion. */
600 std::vector
<struct type
*> rust_unions
;
602 /* The DW_AT_str_offsets_base attribute if present. For DWARF 4 version DWO
603 files, the value is implicitly zero. For DWARF 5 version DWO files, the
604 value is often implicit and is the size of the header of
605 .debug_str_offsets section (8 or 4, depending on the address size). */
606 gdb::optional
<ULONGEST
> str_offsets_base
;
608 /* Mark used when releasing cached dies. */
611 /* This CU references .debug_loc. See the symtab->locations_valid field.
612 This test is imperfect as there may exist optimized debug code not using
613 any location list and still facing inlining issues if handled as
614 unoptimized code. For a future better test see GCC PR other/32998. */
615 bool has_loclist
: 1;
617 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is true
618 if all the producer_is_* fields are valid. This information is cached
619 because profiling CU expansion showed excessive time spent in
620 producer_is_gxx_lt_4_6. */
621 bool checked_producer
: 1;
622 bool producer_is_gxx_lt_4_6
: 1;
623 bool producer_is_gcc_lt_4_3
: 1;
624 bool producer_is_icc
: 1;
625 bool producer_is_icc_lt_14
: 1;
626 bool producer_is_codewarrior
: 1;
628 /* When true, the file that we're processing is known to have
629 debugging info for C++ namespaces. GCC 3.3.x did not produce
630 this information, but later versions do. */
632 bool processing_has_namespace_info
: 1;
634 struct partial_die_info
*find_partial_die (sect_offset sect_off
);
636 /* If this CU was inherited by another CU (via specification,
637 abstract_origin, etc), this is the ancestor CU. */
640 /* Get the buildsym_compunit for this CU. */
641 buildsym_compunit
*get_builder ()
643 /* If this CU has a builder associated with it, use that. */
644 if (m_builder
!= nullptr)
645 return m_builder
.get ();
647 /* Otherwise, search ancestors for a valid builder. */
648 if (ancestor
!= nullptr)
649 return ancestor
->get_builder ();
655 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
656 This includes type_unit_group and quick_file_names. */
658 struct stmt_list_hash
660 /* The DWO unit this table is from or NULL if there is none. */
661 struct dwo_unit
*dwo_unit
;
663 /* Offset in .debug_line or .debug_line.dwo. */
664 sect_offset line_sect_off
;
667 /* Each element of dwarf2_per_bfd->type_unit_groups is a pointer to
668 an object of this type. This contains elements of type unit groups
669 that can be shared across objfiles. The non-shareable parts are in
670 type_unit_group_unshareable. */
672 struct type_unit_group
674 /* dwarf2read.c's main "handle" on a TU symtab.
675 To simplify things we create an artificial CU that "includes" all the
676 type units using this stmt_list so that the rest of the code still has
677 a "per_cu" handle on the symtab. */
678 struct dwarf2_per_cu_data per_cu
;
680 /* The TUs that share this DW_AT_stmt_list entry.
681 This is added to while parsing type units to build partial symtabs,
682 and is deleted afterwards and not used again. */
683 std::vector
<signatured_type
*> *tus
;
685 /* The data used to construct the hash key. */
686 struct stmt_list_hash hash
;
689 /* These sections are what may appear in a (real or virtual) DWO file. */
693 struct dwarf2_section_info abbrev
;
694 struct dwarf2_section_info line
;
695 struct dwarf2_section_info loc
;
696 struct dwarf2_section_info loclists
;
697 struct dwarf2_section_info macinfo
;
698 struct dwarf2_section_info macro
;
699 struct dwarf2_section_info rnglists
;
700 struct dwarf2_section_info str
;
701 struct dwarf2_section_info str_offsets
;
702 /* In the case of a virtual DWO file, these two are unused. */
703 struct dwarf2_section_info info
;
704 std::vector
<dwarf2_section_info
> types
;
707 /* CUs/TUs in DWP/DWO files. */
711 /* Backlink to the containing struct dwo_file. */
712 struct dwo_file
*dwo_file
;
714 /* The "id" that distinguishes this CU/TU.
715 .debug_info calls this "dwo_id", .debug_types calls this "signature".
716 Since signatures came first, we stick with it for consistency. */
719 /* The section this CU/TU lives in, in the DWO file. */
720 struct dwarf2_section_info
*section
;
722 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
723 sect_offset sect_off
;
726 /* For types, offset in the type's DIE of the type defined by this TU. */
727 cu_offset type_offset_in_tu
;
730 /* include/dwarf2.h defines the DWP section codes.
731 It defines a max value but it doesn't define a min value, which we
732 use for error checking, so provide one. */
734 enum dwp_v2_section_ids
739 /* Data for one DWO file.
741 This includes virtual DWO files (a virtual DWO file is a DWO file as it
742 appears in a DWP file). DWP files don't really have DWO files per se -
743 comdat folding of types "loses" the DWO file they came from, and from
744 a high level view DWP files appear to contain a mass of random types.
745 However, to maintain consistency with the non-DWP case we pretend DWP
746 files contain virtual DWO files, and we assign each TU with one virtual
747 DWO file (generally based on the line and abbrev section offsets -
748 a heuristic that seems to work in practice). */
752 dwo_file () = default;
753 DISABLE_COPY_AND_ASSIGN (dwo_file
);
755 /* The DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute.
756 For virtual DWO files the name is constructed from the section offsets
757 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
758 from related CU+TUs. */
759 const char *dwo_name
= nullptr;
761 /* The DW_AT_comp_dir attribute. */
762 const char *comp_dir
= nullptr;
764 /* The bfd, when the file is open. Otherwise this is NULL.
765 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
766 gdb_bfd_ref_ptr dbfd
;
768 /* The sections that make up this DWO file.
769 Remember that for virtual DWO files in DWP V2 or DWP V5, these are virtual
770 sections (for lack of a better name). */
771 struct dwo_sections sections
{};
773 /* The CUs in the file.
774 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
775 an extension to handle LLVM's Link Time Optimization output (where
776 multiple source files may be compiled into a single object/dwo pair). */
779 /* Table of TUs in the file.
780 Each element is a struct dwo_unit. */
784 /* These sections are what may appear in a DWP file. */
788 /* These are used by all DWP versions (1, 2 and 5). */
789 struct dwarf2_section_info str
;
790 struct dwarf2_section_info cu_index
;
791 struct dwarf2_section_info tu_index
;
793 /* These are only used by DWP version 2 and version 5 files.
794 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
795 sections are referenced by section number, and are not recorded here.
796 In DWP version 2 or 5 there is at most one copy of all these sections,
797 each section being (effectively) comprised of the concatenation of all of
798 the individual sections that exist in the version 1 format.
799 To keep the code simple we treat each of these concatenated pieces as a
800 section itself (a virtual section?). */
801 struct dwarf2_section_info abbrev
;
802 struct dwarf2_section_info info
;
803 struct dwarf2_section_info line
;
804 struct dwarf2_section_info loc
;
805 struct dwarf2_section_info loclists
;
806 struct dwarf2_section_info macinfo
;
807 struct dwarf2_section_info macro
;
808 struct dwarf2_section_info rnglists
;
809 struct dwarf2_section_info str_offsets
;
810 struct dwarf2_section_info types
;
813 /* These sections are what may appear in a virtual DWO file in DWP version 1.
814 A virtual DWO file is a DWO file as it appears in a DWP file. */
816 struct virtual_v1_dwo_sections
818 struct dwarf2_section_info abbrev
;
819 struct dwarf2_section_info line
;
820 struct dwarf2_section_info loc
;
821 struct dwarf2_section_info macinfo
;
822 struct dwarf2_section_info macro
;
823 struct dwarf2_section_info str_offsets
;
824 /* Each DWP hash table entry records one CU or one TU.
825 That is recorded here, and copied to dwo_unit.section. */
826 struct dwarf2_section_info info_or_types
;
829 /* Similar to virtual_v1_dwo_sections, but for DWP version 2 or 5.
830 In version 2, the sections of the DWO files are concatenated together
831 and stored in one section of that name. Thus each ELF section contains
832 several "virtual" sections. */
834 struct virtual_v2_or_v5_dwo_sections
836 bfd_size_type abbrev_offset
;
837 bfd_size_type abbrev_size
;
839 bfd_size_type line_offset
;
840 bfd_size_type line_size
;
842 bfd_size_type loc_offset
;
843 bfd_size_type loc_size
;
845 bfd_size_type loclists_offset
;
846 bfd_size_type loclists_size
;
848 bfd_size_type macinfo_offset
;
849 bfd_size_type macinfo_size
;
851 bfd_size_type macro_offset
;
852 bfd_size_type macro_size
;
854 bfd_size_type rnglists_offset
;
855 bfd_size_type rnglists_size
;
857 bfd_size_type str_offsets_offset
;
858 bfd_size_type str_offsets_size
;
860 /* Each DWP hash table entry records one CU or one TU.
861 That is recorded here, and copied to dwo_unit.section. */
862 bfd_size_type info_or_types_offset
;
863 bfd_size_type info_or_types_size
;
866 /* Contents of DWP hash tables. */
868 struct dwp_hash_table
870 uint32_t version
, nr_columns
;
871 uint32_t nr_units
, nr_slots
;
872 const gdb_byte
*hash_table
, *unit_table
;
877 const gdb_byte
*indices
;
881 /* This is indexed by column number and gives the id of the section
883 #define MAX_NR_V2_DWO_SECTIONS \
884 (1 /* .debug_info or .debug_types */ \
885 + 1 /* .debug_abbrev */ \
886 + 1 /* .debug_line */ \
887 + 1 /* .debug_loc */ \
888 + 1 /* .debug_str_offsets */ \
889 + 1 /* .debug_macro or .debug_macinfo */)
890 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
891 const gdb_byte
*offsets
;
892 const gdb_byte
*sizes
;
896 /* This is indexed by column number and gives the id of the section
898 #define MAX_NR_V5_DWO_SECTIONS \
899 (1 /* .debug_info */ \
900 + 1 /* .debug_abbrev */ \
901 + 1 /* .debug_line */ \
902 + 1 /* .debug_loclists */ \
903 + 1 /* .debug_str_offsets */ \
904 + 1 /* .debug_macro */ \
905 + 1 /* .debug_rnglists */)
906 int section_ids
[MAX_NR_V5_DWO_SECTIONS
];
907 const gdb_byte
*offsets
;
908 const gdb_byte
*sizes
;
913 /* Data for one DWP file. */
917 dwp_file (const char *name_
, gdb_bfd_ref_ptr
&&abfd
)
919 dbfd (std::move (abfd
))
923 /* Name of the file. */
926 /* File format version. */
930 gdb_bfd_ref_ptr dbfd
;
932 /* Section info for this file. */
933 struct dwp_sections sections
{};
935 /* Table of CUs in the file. */
936 const struct dwp_hash_table
*cus
= nullptr;
938 /* Table of TUs in the file. */
939 const struct dwp_hash_table
*tus
= nullptr;
941 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
945 /* Table to map ELF section numbers to their sections.
946 This is only needed for the DWP V1 file format. */
947 unsigned int num_sections
= 0;
948 asection
**elf_sections
= nullptr;
951 /* Struct used to pass misc. parameters to read_die_and_children, et
952 al. which are used for both .debug_info and .debug_types dies.
953 All parameters here are unchanging for the life of the call. This
954 struct exists to abstract away the constant parameters of die reading. */
956 struct die_reader_specs
958 /* The bfd of die_section. */
961 /* The CU of the DIE we are parsing. */
962 struct dwarf2_cu
*cu
;
964 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
965 struct dwo_file
*dwo_file
;
967 /* The section the die comes from.
968 This is either .debug_info or .debug_types, or the .dwo variants. */
969 struct dwarf2_section_info
*die_section
;
971 /* die_section->buffer. */
972 const gdb_byte
*buffer
;
974 /* The end of the buffer. */
975 const gdb_byte
*buffer_end
;
977 /* The abbreviation table to use when reading the DIEs. */
978 struct abbrev_table
*abbrev_table
;
981 /* A subclass of die_reader_specs that holds storage and has complex
982 constructor and destructor behavior. */
984 class cutu_reader
: public die_reader_specs
988 cutu_reader (dwarf2_per_cu_data
*this_cu
,
989 dwarf2_per_objfile
*per_objfile
,
990 struct abbrev_table
*abbrev_table
,
991 dwarf2_cu
*existing_cu
,
994 explicit cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
995 dwarf2_per_objfile
*per_objfile
,
996 struct dwarf2_cu
*parent_cu
= nullptr,
997 struct dwo_file
*dwo_file
= nullptr);
999 DISABLE_COPY_AND_ASSIGN (cutu_reader
);
1001 const gdb_byte
*info_ptr
= nullptr;
1002 struct die_info
*comp_unit_die
= nullptr;
1003 bool dummy_p
= false;
1005 /* Release the new CU, putting it on the chain. This cannot be done
1010 void init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
1011 dwarf2_per_objfile
*per_objfile
,
1012 dwarf2_cu
*existing_cu
);
1014 struct dwarf2_per_cu_data
*m_this_cu
;
1015 std::unique_ptr
<dwarf2_cu
> m_new_cu
;
1017 /* The ordinary abbreviation table. */
1018 abbrev_table_up m_abbrev_table_holder
;
1020 /* The DWO abbreviation table. */
1021 abbrev_table_up m_dwo_abbrev_table
;
1024 /* When we construct a partial symbol table entry we only
1025 need this much information. */
1026 struct partial_die_info
: public allocate_on_obstack
1028 partial_die_info (sect_offset sect_off
, const struct abbrev_info
*abbrev
);
1030 /* Disable assign but still keep copy ctor, which is needed
1031 load_partial_dies. */
1032 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
1034 /* Adjust the partial die before generating a symbol for it. This
1035 function may set the is_external flag or change the DIE's
1037 void fixup (struct dwarf2_cu
*cu
);
1039 /* Read a minimal amount of information into the minimal die
1041 const gdb_byte
*read (const struct die_reader_specs
*reader
,
1042 const struct abbrev_info
&abbrev
,
1043 const gdb_byte
*info_ptr
);
1045 /* Compute the name of this partial DIE. This memoizes the
1046 result, so it is safe to call multiple times. */
1047 const char *name (dwarf2_cu
*cu
);
1049 /* Offset of this DIE. */
1050 const sect_offset sect_off
;
1052 /* DWARF-2 tag for this DIE. */
1053 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1055 /* Assorted flags describing the data found in this DIE. */
1056 const unsigned int has_children
: 1;
1058 unsigned int is_external
: 1;
1059 unsigned int is_declaration
: 1;
1060 unsigned int has_type
: 1;
1061 unsigned int has_specification
: 1;
1062 unsigned int has_pc_info
: 1;
1063 unsigned int may_be_inlined
: 1;
1065 /* This DIE has been marked DW_AT_main_subprogram. */
1066 unsigned int main_subprogram
: 1;
1068 /* Flag set if the SCOPE field of this structure has been
1070 unsigned int scope_set
: 1;
1072 /* Flag set if the DIE has a byte_size attribute. */
1073 unsigned int has_byte_size
: 1;
1075 /* Flag set if the DIE has a DW_AT_const_value attribute. */
1076 unsigned int has_const_value
: 1;
1078 /* Flag set if any of the DIE's children are template arguments. */
1079 unsigned int has_template_arguments
: 1;
1081 /* Flag set if fixup has been called on this die. */
1082 unsigned int fixup_called
: 1;
1084 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1085 unsigned int is_dwz
: 1;
1087 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1088 unsigned int spec_is_dwz
: 1;
1090 unsigned int canonical_name
: 1;
1092 /* The name of this DIE. Normally the value of DW_AT_name, but
1093 sometimes a default name for unnamed DIEs. */
1094 const char *raw_name
= nullptr;
1096 /* The linkage name, if present. */
1097 const char *linkage_name
= nullptr;
1099 /* The scope to prepend to our children. This is generally
1100 allocated on the comp_unit_obstack, so will disappear
1101 when this compilation unit leaves the cache. */
1102 const char *scope
= nullptr;
1104 /* Some data associated with the partial DIE. The tag determines
1105 which field is live. */
1108 /* The location description associated with this DIE, if any. */
1109 struct dwarf_block
*locdesc
;
1110 /* The offset of an import, for DW_TAG_imported_unit. */
1111 sect_offset sect_off
;
1114 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1115 CORE_ADDR lowpc
= 0;
1116 CORE_ADDR highpc
= 0;
1118 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1119 DW_AT_sibling, if any. */
1120 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1121 could return DW_AT_sibling values to its caller load_partial_dies. */
1122 const gdb_byte
*sibling
= nullptr;
1124 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1125 DW_AT_specification (or DW_AT_abstract_origin or
1126 DW_AT_extension). */
1127 sect_offset spec_offset
{};
1129 /* Pointers to this DIE's parent, first child, and next sibling,
1131 struct partial_die_info
*die_parent
= nullptr;
1132 struct partial_die_info
*die_child
= nullptr;
1133 struct partial_die_info
*die_sibling
= nullptr;
1135 friend struct partial_die_info
*
1136 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1139 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1140 partial_die_info (sect_offset sect_off
)
1141 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1145 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1147 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1152 has_specification
= 0;
1155 main_subprogram
= 0;
1158 has_const_value
= 0;
1159 has_template_arguments
= 0;
1167 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1168 but this would require a corresponding change in unpack_field_as_long
1170 static int bits_per_byte
= 8;
1172 struct variant_part_builder
;
1174 /* When reading a variant, we track a bit more information about the
1175 field, and store it in an object of this type. */
1177 struct variant_field
1179 int first_field
= -1;
1180 int last_field
= -1;
1182 /* A variant can contain other variant parts. */
1183 std::vector
<variant_part_builder
> variant_parts
;
1185 /* If we see a DW_TAG_variant, then this will be set if this is the
1187 bool default_branch
= false;
1188 /* If we see a DW_AT_discr_value, then this will be the discriminant
1190 ULONGEST discriminant_value
= 0;
1191 /* If we see a DW_AT_discr_list, then this is a pointer to the list
1193 struct dwarf_block
*discr_list_data
= nullptr;
1196 /* This represents a DW_TAG_variant_part. */
1198 struct variant_part_builder
1200 /* The offset of the discriminant field. */
1201 sect_offset discriminant_offset
{};
1203 /* Variants that are direct children of this variant part. */
1204 std::vector
<variant_field
> variants
;
1206 /* True if we're currently reading a variant. */
1207 bool processing_variant
= false;
1212 int accessibility
= 0;
1214 /* Variant parts need to find the discriminant, which is a DIE
1215 reference. We track the section offset of each field to make
1218 struct field field
{};
1223 const char *name
= nullptr;
1224 std::vector
<struct fn_field
> fnfields
;
1227 /* The routines that read and process dies for a C struct or C++ class
1228 pass lists of data member fields and lists of member function fields
1229 in an instance of a field_info structure, as defined below. */
1232 /* List of data member and baseclasses fields. */
1233 std::vector
<struct nextfield
> fields
;
1234 std::vector
<struct nextfield
> baseclasses
;
1236 /* Set if the accessibility of one of the fields is not public. */
1237 bool non_public_fields
= false;
1239 /* Member function fieldlist array, contains name of possibly overloaded
1240 member function, number of overloaded member functions and a pointer
1241 to the head of the member function field chain. */
1242 std::vector
<struct fnfieldlist
> fnfieldlists
;
1244 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1245 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1246 std::vector
<struct decl_field
> typedef_field_list
;
1248 /* Nested types defined by this class and the number of elements in this
1250 std::vector
<struct decl_field
> nested_types_list
;
1252 /* If non-null, this is the variant part we are currently
1254 variant_part_builder
*current_variant_part
= nullptr;
1255 /* This holds all the top-level variant parts attached to the type
1257 std::vector
<variant_part_builder
> variant_parts
;
1259 /* Return the total number of fields (including baseclasses). */
1260 int nfields () const
1262 return fields
.size () + baseclasses
.size ();
1266 /* Loaded secondary compilation units are kept in memory until they
1267 have not been referenced for the processing of this many
1268 compilation units. Set this to zero to disable caching. Cache
1269 sizes of up to at least twenty will improve startup time for
1270 typical inter-CU-reference binaries, at an obvious memory cost. */
1271 static int dwarf_max_cache_age
= 5;
1273 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1274 struct cmd_list_element
*c
, const char *value
)
1276 fprintf_filtered (file
, _("The upper bound on the age of cached "
1277 "DWARF compilation units is %s.\n"),
1281 /* local function prototypes */
1283 static void dwarf2_find_base_address (struct die_info
*die
,
1284 struct dwarf2_cu
*cu
);
1286 static dwarf2_psymtab
*create_partial_symtab
1287 (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
1290 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1291 const gdb_byte
*info_ptr
,
1292 struct die_info
*type_unit_die
);
1294 static void dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
);
1296 static void scan_partial_symbols (struct partial_die_info
*,
1297 CORE_ADDR
*, CORE_ADDR
*,
1298 int, struct dwarf2_cu
*);
1300 static void add_partial_symbol (struct partial_die_info
*,
1301 struct dwarf2_cu
*);
1303 static void add_partial_namespace (struct partial_die_info
*pdi
,
1304 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1305 int set_addrmap
, struct dwarf2_cu
*cu
);
1307 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1308 CORE_ADDR
*highpc
, int set_addrmap
,
1309 struct dwarf2_cu
*cu
);
1311 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1312 struct dwarf2_cu
*cu
);
1314 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1315 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1316 int need_pc
, struct dwarf2_cu
*cu
);
1318 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1320 static struct partial_die_info
*load_partial_dies
1321 (const struct die_reader_specs
*, const gdb_byte
*, int);
1323 /* A pair of partial_die_info and compilation unit. */
1324 struct cu_partial_die_info
1326 /* The compilation unit of the partial_die_info. */
1327 struct dwarf2_cu
*cu
;
1328 /* A partial_die_info. */
1329 struct partial_die_info
*pdi
;
1331 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1337 cu_partial_die_info () = delete;
1340 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1341 struct dwarf2_cu
*);
1343 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1345 const struct attr_abbrev
*,
1348 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1349 struct attribute
*attr
, dwarf_tag tag
);
1351 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1353 static sect_offset
read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
1354 dwarf2_section_info
*, sect_offset
);
1356 static const char *read_indirect_string
1357 (dwarf2_per_objfile
*per_objfile
, bfd
*, const gdb_byte
*,
1358 const struct comp_unit_head
*, unsigned int *);
1360 static const char *read_indirect_string_at_offset
1361 (dwarf2_per_objfile
*per_objfile
, LONGEST str_offset
);
1363 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1367 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1368 ULONGEST str_index
);
1370 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1371 ULONGEST str_index
);
1373 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1375 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1376 struct dwarf2_cu
*);
1378 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1379 struct dwarf2_cu
*cu
);
1381 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1383 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1384 struct dwarf2_cu
*cu
);
1386 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1388 static struct die_info
*die_specification (struct die_info
*die
,
1389 struct dwarf2_cu
**);
1391 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1392 struct dwarf2_cu
*cu
);
1394 static void dwarf_decode_lines (struct line_header
*, const char *,
1395 struct dwarf2_cu
*, dwarf2_psymtab
*,
1396 CORE_ADDR
, int decode_mapping
);
1398 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1401 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1402 struct dwarf2_cu
*, struct symbol
* = NULL
);
1404 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1405 struct dwarf2_cu
*);
1407 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1410 struct obstack
*obstack
,
1411 struct dwarf2_cu
*cu
, LONGEST
*value
,
1412 const gdb_byte
**bytes
,
1413 struct dwarf2_locexpr_baton
**baton
);
1415 static struct type
*read_subrange_index_type (struct die_info
*die
,
1416 struct dwarf2_cu
*cu
);
1418 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1420 static int need_gnat_info (struct dwarf2_cu
*);
1422 static struct type
*die_descriptive_type (struct die_info
*,
1423 struct dwarf2_cu
*);
1425 static void set_descriptive_type (struct type
*, struct die_info
*,
1426 struct dwarf2_cu
*);
1428 static struct type
*die_containing_type (struct die_info
*,
1429 struct dwarf2_cu
*);
1431 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1432 struct dwarf2_cu
*);
1434 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1436 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1438 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1440 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1441 const char *suffix
, int physname
,
1442 struct dwarf2_cu
*cu
);
1444 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1446 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1448 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1450 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1452 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1454 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1456 /* Return the .debug_loclists section to use for cu. */
1457 static struct dwarf2_section_info
*cu_debug_loc_section (struct dwarf2_cu
*cu
);
1459 /* Return the .debug_rnglists section to use for cu. */
1460 static struct dwarf2_section_info
*cu_debug_rnglists_section
1461 (struct dwarf2_cu
*cu
, dwarf_tag tag
);
1463 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1464 values. Keep the items ordered with increasing constraints compliance. */
1467 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1468 PC_BOUNDS_NOT_PRESENT
,
1470 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1471 were present but they do not form a valid range of PC addresses. */
1474 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1477 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1481 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1482 CORE_ADDR
*, CORE_ADDR
*,
1486 static void get_scope_pc_bounds (struct die_info
*,
1487 CORE_ADDR
*, CORE_ADDR
*,
1488 struct dwarf2_cu
*);
1490 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1491 CORE_ADDR
, struct dwarf2_cu
*);
1493 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1494 struct dwarf2_cu
*);
1496 static void dwarf2_attach_fields_to_type (struct field_info
*,
1497 struct type
*, struct dwarf2_cu
*);
1499 static void dwarf2_add_member_fn (struct field_info
*,
1500 struct die_info
*, struct type
*,
1501 struct dwarf2_cu
*);
1503 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1505 struct dwarf2_cu
*);
1507 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1509 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1511 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1513 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1515 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1517 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1519 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1521 static struct type
*read_module_type (struct die_info
*die
,
1522 struct dwarf2_cu
*cu
);
1524 static const char *namespace_name (struct die_info
*die
,
1525 int *is_anonymous
, struct dwarf2_cu
*);
1527 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1529 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*,
1532 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1533 struct dwarf2_cu
*);
1535 static struct die_info
*read_die_and_siblings_1
1536 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1539 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1540 const gdb_byte
*info_ptr
,
1541 const gdb_byte
**new_info_ptr
,
1542 struct die_info
*parent
);
1544 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1545 struct die_info
**, const gdb_byte
*,
1548 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1549 struct die_info
**, const gdb_byte
*);
1551 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1553 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1556 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1558 static const char *dwarf2_full_name (const char *name
,
1559 struct die_info
*die
,
1560 struct dwarf2_cu
*cu
);
1562 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1563 struct dwarf2_cu
*cu
);
1565 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1566 struct dwarf2_cu
**);
1568 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1570 static void dump_die_for_error (struct die_info
*);
1572 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1575 /*static*/ void dump_die (struct die_info
*, int max_level
);
1577 static void store_in_ref_table (struct die_info
*,
1578 struct dwarf2_cu
*);
1580 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1581 const struct attribute
*,
1582 struct dwarf2_cu
**);
1584 static struct die_info
*follow_die_ref (struct die_info
*,
1585 const struct attribute
*,
1586 struct dwarf2_cu
**);
1588 static struct die_info
*follow_die_sig (struct die_info
*,
1589 const struct attribute
*,
1590 struct dwarf2_cu
**);
1592 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1593 struct dwarf2_cu
*);
1595 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1596 const struct attribute
*,
1597 struct dwarf2_cu
*);
1599 static void load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
1600 dwarf2_per_objfile
*per_objfile
);
1602 static void read_signatured_type (signatured_type
*sig_type
,
1603 dwarf2_per_objfile
*per_objfile
);
1605 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1606 struct die_info
*die
, struct dwarf2_cu
*cu
,
1607 struct dynamic_prop
*prop
, struct type
*type
);
1609 /* memory allocation interface */
1611 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1613 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1615 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1617 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1618 struct dwarf2_loclist_baton
*baton
,
1619 const struct attribute
*attr
);
1621 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1623 struct dwarf2_cu
*cu
,
1626 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1627 const gdb_byte
*info_ptr
,
1628 const struct abbrev_info
*abbrev
);
1630 static hashval_t
partial_die_hash (const void *item
);
1632 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1634 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1635 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1636 dwarf2_per_objfile
*per_objfile
);
1638 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1639 struct die_info
*comp_unit_die
,
1640 enum language pretend_language
);
1642 static struct type
*set_die_type (struct die_info
*, struct type
*,
1643 struct dwarf2_cu
*, bool = false);
1645 static void create_all_comp_units (dwarf2_per_objfile
*per_objfile
);
1647 static int create_all_type_units (dwarf2_per_objfile
*per_objfile
);
1649 static void load_full_comp_unit (dwarf2_per_cu_data
*per_cu
,
1650 dwarf2_per_objfile
*per_objfile
,
1651 dwarf2_cu
*existing_cu
,
1653 enum language pretend_language
);
1655 static void process_full_comp_unit (dwarf2_cu
*cu
,
1656 enum language pretend_language
);
1658 static void process_full_type_unit (dwarf2_cu
*cu
,
1659 enum language pretend_language
);
1661 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1662 struct dwarf2_per_cu_data
*);
1664 static void dwarf2_mark (struct dwarf2_cu
*);
1666 static struct type
*get_die_type_at_offset (sect_offset
,
1667 dwarf2_per_cu_data
*per_cu
,
1668 dwarf2_per_objfile
*per_objfile
);
1670 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1672 static void queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
1673 dwarf2_per_objfile
*per_objfile
,
1674 enum language pretend_language
);
1676 static void process_queue (dwarf2_per_objfile
*per_objfile
);
1678 /* Class, the destructor of which frees all allocated queue entries. This
1679 will only have work to do if an error was thrown while processing the
1680 dwarf. If no error was thrown then the queue entries should have all
1681 been processed, and freed, as we went along. */
1683 class dwarf2_queue_guard
1686 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1687 : m_per_objfile (per_objfile
)
1689 gdb_assert (!m_per_objfile
->per_bfd
->queue
.has_value ());
1691 m_per_objfile
->per_bfd
->queue
.emplace ();
1694 /* Free any entries remaining on the queue. There should only be
1695 entries left if we hit an error while processing the dwarf. */
1696 ~dwarf2_queue_guard ()
1698 gdb_assert (m_per_objfile
->per_bfd
->queue
.has_value ());
1700 m_per_objfile
->per_bfd
->queue
.reset ();
1703 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1706 dwarf2_per_objfile
*m_per_objfile
;
1709 dwarf2_queue_item::~dwarf2_queue_item ()
1711 /* Anything still marked queued is likely to be in an
1712 inconsistent state, so discard it. */
1715 per_objfile
->remove_cu (per_cu
);
1720 /* The return type of find_file_and_directory. Note, the enclosed
1721 string pointers are only valid while this object is valid. */
1723 struct file_and_directory
1725 /* The filename. This is never NULL. */
1728 /* The compilation directory. NULL if not known. If we needed to
1729 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1730 points directly to the DW_AT_comp_dir string attribute owned by
1731 the obstack that owns the DIE. */
1732 const char *comp_dir
;
1734 /* If we needed to build a new string for comp_dir, this is what
1735 owns the storage. */
1736 std::string comp_dir_storage
;
1739 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1740 struct dwarf2_cu
*cu
);
1742 static htab_up
allocate_signatured_type_table ();
1744 static htab_up
allocate_dwo_unit_table ();
1746 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1747 (dwarf2_per_objfile
*per_objfile
, struct dwp_file
*dwp_file
,
1748 const char *comp_dir
, ULONGEST signature
, int is_debug_types
);
1750 static struct dwp_file
*get_dwp_file (dwarf2_per_objfile
*per_objfile
);
1752 static struct dwo_unit
*lookup_dwo_comp_unit
1753 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
1754 ULONGEST signature
);
1756 static struct dwo_unit
*lookup_dwo_type_unit
1757 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
);
1759 static void queue_and_load_all_dwo_tus (dwarf2_cu
*cu
);
1761 /* A unique pointer to a dwo_file. */
1763 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1765 static void process_cu_includes (dwarf2_per_objfile
*per_objfile
);
1767 static void check_producer (struct dwarf2_cu
*cu
);
1769 static void free_line_header_voidp (void *arg
);
1771 /* Various complaints about symbol reading that don't abort the process. */
1774 dwarf2_debug_line_missing_file_complaint (void)
1776 complaint (_(".debug_line section has line data without a file"));
1780 dwarf2_debug_line_missing_end_sequence_complaint (void)
1782 complaint (_(".debug_line section has line "
1783 "program sequence without an end"));
1787 dwarf2_complex_location_expr_complaint (void)
1789 complaint (_("location expression too complex"));
1793 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1796 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1801 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1803 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1807 /* Hash function for line_header_hash. */
1810 line_header_hash (const struct line_header
*ofs
)
1812 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1815 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1818 line_header_hash_voidp (const void *item
)
1820 const struct line_header
*ofs
= (const struct line_header
*) item
;
1822 return line_header_hash (ofs
);
1825 /* Equality function for line_header_hash. */
1828 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1830 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1831 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1833 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1834 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
1839 /* See declaration. */
1841 dwarf2_per_bfd::dwarf2_per_bfd (bfd
*obfd
, const dwarf2_debug_sections
*names
,
1844 can_copy (can_copy_
)
1847 names
= &dwarf2_elf_names
;
1849 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1850 locate_sections (obfd
, sec
, *names
);
1853 dwarf2_per_bfd::~dwarf2_per_bfd ()
1855 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
1856 per_cu
->imported_symtabs_free ();
1858 for (signatured_type
*sig_type
: all_type_units
)
1859 sig_type
->per_cu
.imported_symtabs_free ();
1861 /* Everything else should be on this->obstack. */
1867 dwarf2_per_objfile::remove_all_cus ()
1869 gdb_assert (!this->per_bfd
->queue
.has_value ());
1871 for (auto pair
: m_dwarf2_cus
)
1874 m_dwarf2_cus
.clear ();
1877 /* A helper class that calls free_cached_comp_units on
1880 class free_cached_comp_units
1884 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1885 : m_per_objfile (per_objfile
)
1889 ~free_cached_comp_units ()
1891 m_per_objfile
->remove_all_cus ();
1894 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1898 dwarf2_per_objfile
*m_per_objfile
;
1904 dwarf2_per_objfile::symtab_set_p (const dwarf2_per_cu_data
*per_cu
) const
1906 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1908 return this->m_symtabs
[per_cu
->index
] != nullptr;
1914 dwarf2_per_objfile::get_symtab (const dwarf2_per_cu_data
*per_cu
) const
1916 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1918 return this->m_symtabs
[per_cu
->index
];
1924 dwarf2_per_objfile::set_symtab (const dwarf2_per_cu_data
*per_cu
,
1925 compunit_symtab
*symtab
)
1927 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1928 gdb_assert (this->m_symtabs
[per_cu
->index
] == nullptr);
1930 this->m_symtabs
[per_cu
->index
] = symtab
;
1933 /* Try to locate the sections we need for DWARF 2 debugging
1934 information and return true if we have enough to do something.
1935 NAMES points to the dwarf2 section names, or is NULL if the standard
1936 ELF names are used. CAN_COPY is true for formats where symbol
1937 interposition is possible and so symbol values must follow copy
1938 relocation rules. */
1941 dwarf2_has_info (struct objfile
*objfile
,
1942 const struct dwarf2_debug_sections
*names
,
1945 if (objfile
->flags
& OBJF_READNEVER
)
1948 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
1950 if (per_objfile
== NULL
)
1952 dwarf2_per_bfd
*per_bfd
;
1954 /* We can share a "dwarf2_per_bfd" with other objfiles if the BFD
1955 doesn't require relocations and if there aren't partial symbols
1956 from some other reader. */
1957 if (!objfile_has_partial_symbols (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
;
2153 /* DWARF quick_symbols_functions support. */
2155 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2156 unique line tables, so we maintain a separate table of all .debug_line
2157 derived entries to support the sharing.
2158 All the quick functions need is the list of file names. We discard the
2159 line_header when we're done and don't need to record it here. */
2160 struct quick_file_names
2162 /* The data used to construct the hash key. */
2163 struct stmt_list_hash hash
;
2165 /* The number of entries in file_names, real_names. */
2166 unsigned int num_file_names
;
2168 /* The file names from the line table, after being run through
2170 const char **file_names
;
2172 /* The file names from the line table after being run through
2173 gdb_realpath. These are computed lazily. */
2174 const char **real_names
;
2177 /* When using the index (and thus not using psymtabs), each CU has an
2178 object of this type. This is used to hold information needed by
2179 the various "quick" methods. */
2180 struct dwarf2_per_cu_quick_data
2182 /* The file table. This can be NULL if there was no file table
2183 or it's currently not read in.
2184 NOTE: This points into dwarf2_per_objfile->per_bfd->quick_file_names_table. */
2185 struct quick_file_names
*file_names
;
2187 /* A temporary mark bit used when iterating over all CUs in
2188 expand_symtabs_matching. */
2189 unsigned int mark
: 1;
2191 /* True if we've tried to read the file table and found there isn't one.
2192 There will be no point in trying to read it again next time. */
2193 unsigned int no_file_data
: 1;
2196 /* Utility hash function for a stmt_list_hash. */
2199 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2203 if (stmt_list_hash
->dwo_unit
!= NULL
)
2204 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2205 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2209 /* Utility equality function for a stmt_list_hash. */
2212 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2213 const struct stmt_list_hash
*rhs
)
2215 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2217 if (lhs
->dwo_unit
!= NULL
2218 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2221 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2224 /* Hash function for a quick_file_names. */
2227 hash_file_name_entry (const void *e
)
2229 const struct quick_file_names
*file_data
2230 = (const struct quick_file_names
*) e
;
2232 return hash_stmt_list_entry (&file_data
->hash
);
2235 /* Equality function for a quick_file_names. */
2238 eq_file_name_entry (const void *a
, const void *b
)
2240 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2241 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2243 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2246 /* Delete function for a quick_file_names. */
2249 delete_file_name_entry (void *e
)
2251 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2254 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2256 xfree ((void*) file_data
->file_names
[i
]);
2257 if (file_data
->real_names
)
2258 xfree ((void*) file_data
->real_names
[i
]);
2261 /* The space for the struct itself lives on the obstack, so we don't
2265 /* Create a quick_file_names hash table. */
2268 create_quick_file_names_table (unsigned int nr_initial_entries
)
2270 return htab_up (htab_create_alloc (nr_initial_entries
,
2271 hash_file_name_entry
, eq_file_name_entry
,
2272 delete_file_name_entry
, xcalloc
, xfree
));
2275 /* Read in CU (dwarf2_cu object) for PER_CU in the context of PER_OBJFILE. This
2276 function is unrelated to symtabs, symtab would have to be created afterwards.
2277 You should call age_cached_comp_units after processing the CU. */
2280 load_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
2283 if (per_cu
->is_debug_types
)
2284 load_full_type_unit (per_cu
, per_objfile
);
2286 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
2287 skip_partial
, language_minimal
);
2289 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
2291 return nullptr; /* Dummy CU. */
2293 dwarf2_find_base_address (cu
->dies
, cu
);
2298 /* Read in the symbols for PER_CU in the context of PER_OBJFILE. */
2301 dw2_do_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2302 dwarf2_per_objfile
*per_objfile
, bool skip_partial
)
2304 /* Skip type_unit_groups, reading the type units they contain
2305 is handled elsewhere. */
2306 if (per_cu
->type_unit_group_p ())
2310 /* The destructor of dwarf2_queue_guard frees any entries left on
2311 the queue. After this point we're guaranteed to leave this function
2312 with the dwarf queue empty. */
2313 dwarf2_queue_guard
q_guard (per_objfile
);
2315 if (!per_objfile
->symtab_set_p (per_cu
))
2317 queue_comp_unit (per_cu
, per_objfile
, language_minimal
);
2318 dwarf2_cu
*cu
= load_cu (per_cu
, per_objfile
, skip_partial
);
2320 /* If we just loaded a CU from a DWO, and we're working with an index
2321 that may badly handle TUs, load all the TUs in that DWO as well.
2322 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2323 if (!per_cu
->is_debug_types
2325 && cu
->dwo_unit
!= NULL
2326 && per_objfile
->per_bfd
->index_table
!= NULL
2327 && per_objfile
->per_bfd
->index_table
->version
<= 7
2328 /* DWP files aren't supported yet. */
2329 && get_dwp_file (per_objfile
) == NULL
)
2330 queue_and_load_all_dwo_tus (cu
);
2333 process_queue (per_objfile
);
2336 /* Age the cache, releasing compilation units that have not
2337 been used recently. */
2338 per_objfile
->age_comp_units ();
2341 /* Ensure that the symbols for PER_CU have been read in. DWARF2_PER_OBJFILE is
2342 the per-objfile for which this symtab is instantiated.
2344 Returns the resulting symbol table. */
2346 static struct compunit_symtab
*
2347 dw2_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2348 dwarf2_per_objfile
*per_objfile
,
2351 gdb_assert (per_objfile
->per_bfd
->using_index
);
2353 if (!per_objfile
->symtab_set_p (per_cu
))
2355 free_cached_comp_units
freer (per_objfile
);
2356 scoped_restore decrementer
= increment_reading_symtab ();
2357 dw2_do_instantiate_symtab (per_cu
, per_objfile
, skip_partial
);
2358 process_cu_includes (per_objfile
);
2361 return per_objfile
->get_symtab (per_cu
);
2364 /* See declaration. */
2366 dwarf2_per_cu_data
*
2367 dwarf2_per_bfd::get_cutu (int index
)
2369 if (index
>= this->all_comp_units
.size ())
2371 index
-= this->all_comp_units
.size ();
2372 gdb_assert (index
< this->all_type_units
.size ());
2373 return &this->all_type_units
[index
]->per_cu
;
2376 return this->all_comp_units
[index
];
2379 /* See declaration. */
2381 dwarf2_per_cu_data
*
2382 dwarf2_per_bfd::get_cu (int index
)
2384 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2386 return this->all_comp_units
[index
];
2389 /* See declaration. */
2392 dwarf2_per_bfd::get_tu (int index
)
2394 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2396 return this->all_type_units
[index
];
2401 dwarf2_per_cu_data
*
2402 dwarf2_per_bfd::allocate_per_cu ()
2404 dwarf2_per_cu_data
*result
= OBSTACK_ZALLOC (&obstack
, dwarf2_per_cu_data
);
2405 result
->per_bfd
= this;
2406 result
->index
= m_num_psymtabs
++;
2413 dwarf2_per_bfd::allocate_signatured_type ()
2415 signatured_type
*result
= OBSTACK_ZALLOC (&obstack
, signatured_type
);
2416 result
->per_cu
.per_bfd
= this;
2417 result
->per_cu
.index
= m_num_psymtabs
++;
2421 /* Return a new dwarf2_per_cu_data allocated on the per-bfd
2422 obstack, and constructed with the specified field values. */
2424 static dwarf2_per_cu_data
*
2425 create_cu_from_index_list (dwarf2_per_bfd
*per_bfd
,
2426 struct dwarf2_section_info
*section
,
2428 sect_offset sect_off
, ULONGEST length
)
2430 dwarf2_per_cu_data
*the_cu
= per_bfd
->allocate_per_cu ();
2431 the_cu
->sect_off
= sect_off
;
2432 the_cu
->length
= length
;
2433 the_cu
->section
= section
;
2434 the_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
2435 struct dwarf2_per_cu_quick_data
);
2436 the_cu
->is_dwz
= is_dwz
;
2440 /* A helper for create_cus_from_index that handles a given list of
2444 create_cus_from_index_list (dwarf2_per_bfd
*per_bfd
,
2445 const gdb_byte
*cu_list
, offset_type n_elements
,
2446 struct dwarf2_section_info
*section
,
2449 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2451 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2453 sect_offset sect_off
2454 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2455 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2458 dwarf2_per_cu_data
*per_cu
2459 = create_cu_from_index_list (per_bfd
, section
, is_dwz
, sect_off
,
2461 per_bfd
->all_comp_units
.push_back (per_cu
);
2465 /* Read the CU list from the mapped index, and use it to create all
2466 the CU objects for PER_BFD. */
2469 create_cus_from_index (dwarf2_per_bfd
*per_bfd
,
2470 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2471 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2473 gdb_assert (per_bfd
->all_comp_units
.empty ());
2474 per_bfd
->all_comp_units
.reserve ((cu_list_elements
+ dwz_elements
) / 2);
2476 create_cus_from_index_list (per_bfd
, cu_list
, cu_list_elements
,
2479 if (dwz_elements
== 0)
2482 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
2483 create_cus_from_index_list (per_bfd
, dwz_list
, dwz_elements
,
2487 /* Create the signatured type hash table from the index. */
2490 create_signatured_type_table_from_index
2491 (dwarf2_per_bfd
*per_bfd
, struct dwarf2_section_info
*section
,
2492 const gdb_byte
*bytes
, offset_type elements
)
2494 gdb_assert (per_bfd
->all_type_units
.empty ());
2495 per_bfd
->all_type_units
.reserve (elements
/ 3);
2497 htab_up sig_types_hash
= allocate_signatured_type_table ();
2499 for (offset_type i
= 0; i
< elements
; i
+= 3)
2501 struct signatured_type
*sig_type
;
2504 cu_offset type_offset_in_tu
;
2506 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2507 sect_offset sect_off
2508 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2510 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2512 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2515 sig_type
= per_bfd
->allocate_signatured_type ();
2516 sig_type
->signature
= signature
;
2517 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2518 sig_type
->per_cu
.is_debug_types
= 1;
2519 sig_type
->per_cu
.section
= section
;
2520 sig_type
->per_cu
.sect_off
= sect_off
;
2521 sig_type
->per_cu
.v
.quick
2522 = OBSTACK_ZALLOC (&per_bfd
->obstack
,
2523 struct dwarf2_per_cu_quick_data
);
2525 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2528 per_bfd
->all_type_units
.push_back (sig_type
);
2531 per_bfd
->signatured_types
= std::move (sig_types_hash
);
2534 /* Create the signatured type hash table from .debug_names. */
2537 create_signatured_type_table_from_debug_names
2538 (dwarf2_per_objfile
*per_objfile
,
2539 const mapped_debug_names
&map
,
2540 struct dwarf2_section_info
*section
,
2541 struct dwarf2_section_info
*abbrev_section
)
2543 struct objfile
*objfile
= per_objfile
->objfile
;
2545 section
->read (objfile
);
2546 abbrev_section
->read (objfile
);
2548 gdb_assert (per_objfile
->per_bfd
->all_type_units
.empty ());
2549 per_objfile
->per_bfd
->all_type_units
.reserve (map
.tu_count
);
2551 htab_up sig_types_hash
= allocate_signatured_type_table ();
2553 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2555 struct signatured_type
*sig_type
;
2558 sect_offset sect_off
2559 = (sect_offset
) (extract_unsigned_integer
2560 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2562 map
.dwarf5_byte_order
));
2564 comp_unit_head cu_header
;
2565 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
2567 section
->buffer
+ to_underlying (sect_off
),
2570 sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
2571 sig_type
->signature
= cu_header
.signature
;
2572 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2573 sig_type
->per_cu
.is_debug_types
= 1;
2574 sig_type
->per_cu
.section
= section
;
2575 sig_type
->per_cu
.sect_off
= sect_off
;
2576 sig_type
->per_cu
.v
.quick
2577 = OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
2578 struct dwarf2_per_cu_quick_data
);
2580 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2583 per_objfile
->per_bfd
->all_type_units
.push_back (sig_type
);
2586 per_objfile
->per_bfd
->signatured_types
= std::move (sig_types_hash
);
2589 /* Read the address map data from the mapped index, and use it to
2590 populate the objfile's psymtabs_addrmap. */
2593 create_addrmap_from_index (dwarf2_per_objfile
*per_objfile
,
2594 struct mapped_index
*index
)
2596 struct objfile
*objfile
= per_objfile
->objfile
;
2597 struct gdbarch
*gdbarch
= objfile
->arch ();
2598 const gdb_byte
*iter
, *end
;
2599 struct addrmap
*mutable_map
;
2602 auto_obstack temp_obstack
;
2604 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2606 iter
= index
->address_table
.data ();
2607 end
= iter
+ index
->address_table
.size ();
2609 baseaddr
= objfile
->text_section_offset ();
2613 ULONGEST hi
, lo
, cu_index
;
2614 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2616 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2618 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2623 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2624 hex_string (lo
), hex_string (hi
));
2628 if (cu_index
>= per_objfile
->per_bfd
->all_comp_units
.size ())
2630 complaint (_(".gdb_index address table has invalid CU number %u"),
2631 (unsigned) cu_index
);
2635 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2636 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2637 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2638 per_objfile
->per_bfd
->get_cu (cu_index
));
2641 objfile
->partial_symtabs
->psymtabs_addrmap
2642 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2645 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2646 populate the objfile's psymtabs_addrmap. */
2649 create_addrmap_from_aranges (dwarf2_per_objfile
*per_objfile
,
2650 struct dwarf2_section_info
*section
)
2652 struct objfile
*objfile
= per_objfile
->objfile
;
2653 bfd
*abfd
= objfile
->obfd
;
2654 struct gdbarch
*gdbarch
= objfile
->arch ();
2655 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2657 auto_obstack temp_obstack
;
2658 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2660 std::unordered_map
<sect_offset
,
2661 dwarf2_per_cu_data
*,
2662 gdb::hash_enum
<sect_offset
>>
2663 debug_info_offset_to_per_cu
;
2664 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
2666 const auto insertpair
2667 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
2668 if (!insertpair
.second
)
2670 warning (_("Section .debug_aranges in %s has duplicate "
2671 "debug_info_offset %s, ignoring .debug_aranges."),
2672 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2677 section
->read (objfile
);
2679 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2681 const gdb_byte
*addr
= section
->buffer
;
2683 while (addr
< section
->buffer
+ section
->size
)
2685 const gdb_byte
*const entry_addr
= addr
;
2686 unsigned int bytes_read
;
2688 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2692 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2693 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2694 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2695 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2697 warning (_("Section .debug_aranges in %s entry at offset %s "
2698 "length %s exceeds section length %s, "
2699 "ignoring .debug_aranges."),
2700 objfile_name (objfile
),
2701 plongest (entry_addr
- section
->buffer
),
2702 plongest (bytes_read
+ entry_length
),
2703 pulongest (section
->size
));
2707 /* The version number. */
2708 const uint16_t version
= read_2_bytes (abfd
, addr
);
2712 warning (_("Section .debug_aranges in %s entry at offset %s "
2713 "has unsupported version %d, ignoring .debug_aranges."),
2714 objfile_name (objfile
),
2715 plongest (entry_addr
- section
->buffer
), version
);
2719 const uint64_t debug_info_offset
2720 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2721 addr
+= offset_size
;
2722 const auto per_cu_it
2723 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2724 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2726 warning (_("Section .debug_aranges in %s entry at offset %s "
2727 "debug_info_offset %s does not exists, "
2728 "ignoring .debug_aranges."),
2729 objfile_name (objfile
),
2730 plongest (entry_addr
- section
->buffer
),
2731 pulongest (debug_info_offset
));
2734 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2736 const uint8_t address_size
= *addr
++;
2737 if (address_size
< 1 || address_size
> 8)
2739 warning (_("Section .debug_aranges in %s entry at offset %s "
2740 "address_size %u is invalid, ignoring .debug_aranges."),
2741 objfile_name (objfile
),
2742 plongest (entry_addr
- section
->buffer
), address_size
);
2746 const uint8_t segment_selector_size
= *addr
++;
2747 if (segment_selector_size
!= 0)
2749 warning (_("Section .debug_aranges in %s entry at offset %s "
2750 "segment_selector_size %u is not supported, "
2751 "ignoring .debug_aranges."),
2752 objfile_name (objfile
),
2753 plongest (entry_addr
- section
->buffer
),
2754 segment_selector_size
);
2758 /* Must pad to an alignment boundary that is twice the address
2759 size. It is undocumented by the DWARF standard but GCC does
2761 for (size_t padding
= ((-(addr
- section
->buffer
))
2762 & (2 * address_size
- 1));
2763 padding
> 0; padding
--)
2766 warning (_("Section .debug_aranges in %s entry at offset %s "
2767 "padding is not zero, ignoring .debug_aranges."),
2768 objfile_name (objfile
),
2769 plongest (entry_addr
- section
->buffer
));
2775 if (addr
+ 2 * address_size
> entry_end
)
2777 warning (_("Section .debug_aranges in %s entry at offset %s "
2778 "address list is not properly terminated, "
2779 "ignoring .debug_aranges."),
2780 objfile_name (objfile
),
2781 plongest (entry_addr
- section
->buffer
));
2784 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
2786 addr
+= address_size
;
2787 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
2789 addr
+= address_size
;
2790 if (start
== 0 && length
== 0)
2792 if (start
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
2794 /* Symbol was eliminated due to a COMDAT group. */
2797 ULONGEST end
= start
+ length
;
2798 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
2800 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
2802 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
2806 objfile
->partial_symtabs
->psymtabs_addrmap
2807 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2810 /* Find a slot in the mapped index INDEX for the object named NAME.
2811 If NAME is found, set *VEC_OUT to point to the CU vector in the
2812 constant pool and return true. If NAME cannot be found, return
2816 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2817 offset_type
**vec_out
)
2820 offset_type slot
, step
;
2821 int (*cmp
) (const char *, const char *);
2823 gdb::unique_xmalloc_ptr
<char> without_params
;
2824 if (current_language
->la_language
== language_cplus
2825 || current_language
->la_language
== language_fortran
2826 || current_language
->la_language
== language_d
)
2828 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2831 if (strchr (name
, '(') != NULL
)
2833 without_params
= cp_remove_params (name
);
2835 if (without_params
!= NULL
)
2836 name
= without_params
.get ();
2840 /* Index version 4 did not support case insensitive searches. But the
2841 indices for case insensitive languages are built in lowercase, therefore
2842 simulate our NAME being searched is also lowercased. */
2843 hash
= mapped_index_string_hash ((index
->version
== 4
2844 && case_sensitivity
== case_sensitive_off
2845 ? 5 : index
->version
),
2848 slot
= hash
& (index
->symbol_table
.size () - 1);
2849 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
2850 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2856 const auto &bucket
= index
->symbol_table
[slot
];
2857 if (bucket
.name
== 0 && bucket
.vec
== 0)
2860 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
2861 if (!cmp (name
, str
))
2863 *vec_out
= (offset_type
*) (index
->constant_pool
2864 + MAYBE_SWAP (bucket
.vec
));
2868 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
2872 /* A helper function that reads the .gdb_index from BUFFER and fills
2873 in MAP. FILENAME is the name of the file containing the data;
2874 it is used for error reporting. DEPRECATED_OK is true if it is
2875 ok to use deprecated sections.
2877 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2878 out parameters that are filled in with information about the CU and
2879 TU lists in the section.
2881 Returns true if all went well, false otherwise. */
2884 read_gdb_index_from_buffer (const char *filename
,
2886 gdb::array_view
<const gdb_byte
> buffer
,
2887 struct mapped_index
*map
,
2888 const gdb_byte
**cu_list
,
2889 offset_type
*cu_list_elements
,
2890 const gdb_byte
**types_list
,
2891 offset_type
*types_list_elements
)
2893 const gdb_byte
*addr
= &buffer
[0];
2895 /* Version check. */
2896 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
2897 /* Versions earlier than 3 emitted every copy of a psymbol. This
2898 causes the index to behave very poorly for certain requests. Version 3
2899 contained incomplete addrmap. So, it seems better to just ignore such
2903 static int warning_printed
= 0;
2904 if (!warning_printed
)
2906 warning (_("Skipping obsolete .gdb_index section in %s."),
2908 warning_printed
= 1;
2912 /* Index version 4 uses a different hash function than index version
2915 Versions earlier than 6 did not emit psymbols for inlined
2916 functions. Using these files will cause GDB not to be able to
2917 set breakpoints on inlined functions by name, so we ignore these
2918 indices unless the user has done
2919 "set use-deprecated-index-sections on". */
2920 if (version
< 6 && !deprecated_ok
)
2922 static int warning_printed
= 0;
2923 if (!warning_printed
)
2926 Skipping deprecated .gdb_index section in %s.\n\
2927 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2928 to use the section anyway."),
2930 warning_printed
= 1;
2934 /* Version 7 indices generated by gold refer to the CU for a symbol instead
2935 of the TU (for symbols coming from TUs),
2936 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
2937 Plus gold-generated indices can have duplicate entries for global symbols,
2938 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
2939 These are just performance bugs, and we can't distinguish gdb-generated
2940 indices from gold-generated ones, so issue no warning here. */
2942 /* Indexes with higher version than the one supported by GDB may be no
2943 longer backward compatible. */
2947 map
->version
= version
;
2949 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2952 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2953 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2957 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2958 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2959 - MAYBE_SWAP (metadata
[i
]))
2963 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2964 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
2966 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
2969 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2970 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
2972 = gdb::array_view
<mapped_index::symbol_table_slot
>
2973 ((mapped_index::symbol_table_slot
*) symbol_table
,
2974 (mapped_index::symbol_table_slot
*) symbol_table_end
);
2977 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
2982 /* Callback types for dwarf2_read_gdb_index. */
2984 typedef gdb::function_view
2985 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_bfd
*)>
2986 get_gdb_index_contents_ftype
;
2987 typedef gdb::function_view
2988 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
2989 get_gdb_index_contents_dwz_ftype
;
2991 /* Read .gdb_index. If everything went ok, initialize the "quick"
2992 elements of all the CUs and return 1. Otherwise, return 0. */
2995 dwarf2_read_gdb_index
2996 (dwarf2_per_objfile
*per_objfile
,
2997 get_gdb_index_contents_ftype get_gdb_index_contents
,
2998 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
3000 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3001 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3002 struct dwz_file
*dwz
;
3003 struct objfile
*objfile
= per_objfile
->objfile
;
3004 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
3006 gdb::array_view
<const gdb_byte
> main_index_contents
3007 = get_gdb_index_contents (objfile
, per_bfd
);
3009 if (main_index_contents
.empty ())
3012 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3013 if (!read_gdb_index_from_buffer (objfile_name (objfile
),
3014 use_deprecated_index_sections
,
3015 main_index_contents
, map
.get (), &cu_list
,
3016 &cu_list_elements
, &types_list
,
3017 &types_list_elements
))
3020 /* Don't use the index if it's empty. */
3021 if (map
->symbol_table
.empty ())
3024 /* If there is a .dwz file, read it so we can get its CU list as
3026 dwz
= dwarf2_get_dwz_file (per_bfd
);
3029 struct mapped_index dwz_map
;
3030 const gdb_byte
*dwz_types_ignore
;
3031 offset_type dwz_types_elements_ignore
;
3033 gdb::array_view
<const gdb_byte
> dwz_index_content
3034 = get_gdb_index_contents_dwz (objfile
, dwz
);
3036 if (dwz_index_content
.empty ())
3039 if (!read_gdb_index_from_buffer (bfd_get_filename (dwz
->dwz_bfd
.get ()),
3040 1, dwz_index_content
, &dwz_map
,
3041 &dwz_list
, &dwz_list_elements
,
3043 &dwz_types_elements_ignore
))
3045 warning (_("could not read '.gdb_index' section from %s; skipping"),
3046 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3051 create_cus_from_index (per_bfd
, cu_list
, cu_list_elements
, dwz_list
,
3054 if (types_list_elements
)
3056 /* We can only handle a single .debug_types when we have an
3058 if (per_bfd
->types
.size () != 1)
3061 dwarf2_section_info
*section
= &per_bfd
->types
[0];
3063 create_signatured_type_table_from_index (per_bfd
, section
, types_list
,
3064 types_list_elements
);
3067 create_addrmap_from_index (per_objfile
, map
.get ());
3069 per_bfd
->index_table
= std::move (map
);
3070 per_bfd
->using_index
= 1;
3071 per_bfd
->quick_file_names_table
=
3072 create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
3074 /* Save partial symtabs in the per_bfd object, for the benefit of subsequent
3075 objfiles using the same BFD. */
3076 gdb_assert (per_bfd
->partial_symtabs
== nullptr);
3077 per_bfd
->partial_symtabs
= objfile
->partial_symtabs
;
3082 /* die_reader_func for dw2_get_file_names. */
3085 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3086 struct die_info
*comp_unit_die
)
3088 struct dwarf2_cu
*cu
= reader
->cu
;
3089 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3090 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
3091 struct dwarf2_per_cu_data
*lh_cu
;
3092 struct attribute
*attr
;
3094 struct quick_file_names
*qfn
;
3096 gdb_assert (! this_cu
->is_debug_types
);
3098 /* Our callers never want to match partial units -- instead they
3099 will match the enclosing full CU. */
3100 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3102 this_cu
->v
.quick
->no_file_data
= 1;
3110 sect_offset line_offset
{};
3112 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3113 if (attr
!= nullptr && attr
->form_is_unsigned ())
3115 struct quick_file_names find_entry
;
3117 line_offset
= (sect_offset
) attr
->as_unsigned ();
3119 /* We may have already read in this line header (TU line header sharing).
3120 If we have we're done. */
3121 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3122 find_entry
.hash
.line_sect_off
= line_offset
;
3123 slot
= htab_find_slot (per_objfile
->per_bfd
->quick_file_names_table
.get (),
3124 &find_entry
, INSERT
);
3127 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3131 lh
= dwarf_decode_line_header (line_offset
, cu
);
3135 lh_cu
->v
.quick
->no_file_data
= 1;
3139 qfn
= XOBNEW (&per_objfile
->per_bfd
->obstack
, struct quick_file_names
);
3140 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3141 qfn
->hash
.line_sect_off
= line_offset
;
3142 gdb_assert (slot
!= NULL
);
3145 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3148 if (strcmp (fnd
.name
, "<unknown>") != 0)
3151 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3153 XOBNEWVEC (&per_objfile
->per_bfd
->obstack
, const char *,
3154 qfn
->num_file_names
);
3156 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3157 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3158 qfn
->file_names
[i
+ offset
] = lh
->file_full_name (i
+ 1,
3159 fnd
.comp_dir
).release ();
3160 qfn
->real_names
= NULL
;
3162 lh_cu
->v
.quick
->file_names
= qfn
;
3165 /* A helper for the "quick" functions which attempts to read the line
3166 table for THIS_CU. */
3168 static struct quick_file_names
*
3169 dw2_get_file_names (dwarf2_per_cu_data
*this_cu
,
3170 dwarf2_per_objfile
*per_objfile
)
3172 /* This should never be called for TUs. */
3173 gdb_assert (! this_cu
->is_debug_types
);
3174 /* Nor type unit groups. */
3175 gdb_assert (! this_cu
->type_unit_group_p ());
3177 if (this_cu
->v
.quick
->file_names
!= NULL
)
3178 return this_cu
->v
.quick
->file_names
;
3179 /* If we know there is no line data, no point in looking again. */
3180 if (this_cu
->v
.quick
->no_file_data
)
3183 cutu_reader
reader (this_cu
, per_objfile
);
3184 if (!reader
.dummy_p
)
3185 dw2_get_file_names_reader (&reader
, reader
.comp_unit_die
);
3187 if (this_cu
->v
.quick
->no_file_data
)
3189 return this_cu
->v
.quick
->file_names
;
3192 /* A helper for the "quick" functions which computes and caches the
3193 real path for a given file name from the line table. */
3196 dw2_get_real_path (dwarf2_per_objfile
*per_objfile
,
3197 struct quick_file_names
*qfn
, int index
)
3199 if (qfn
->real_names
== NULL
)
3200 qfn
->real_names
= OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
3201 qfn
->num_file_names
, const char *);
3203 if (qfn
->real_names
[index
] == NULL
)
3204 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3206 return qfn
->real_names
[index
];
3209 static struct symtab
*
3210 dw2_find_last_source_symtab (struct objfile
*objfile
)
3212 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3213 dwarf2_per_cu_data
*dwarf_cu
= per_objfile
->per_bfd
->all_comp_units
.back ();
3214 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, per_objfile
, false);
3219 return compunit_primary_filetab (cust
);
3222 /* Traversal function for dw2_forget_cached_source_info. */
3225 dw2_free_cached_file_names (void **slot
, void *info
)
3227 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3229 if (file_data
->real_names
)
3233 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3235 xfree ((void*) file_data
->real_names
[i
]);
3236 file_data
->real_names
[i
] = NULL
;
3244 dw2_forget_cached_source_info (struct objfile
*objfile
)
3246 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3248 htab_traverse_noresize (per_objfile
->per_bfd
->quick_file_names_table
.get (),
3249 dw2_free_cached_file_names
, NULL
);
3252 /* Helper function for dw2_map_symtabs_matching_filename that expands
3253 the symtabs and calls the iterator. */
3256 dw2_map_expand_apply (struct objfile
*objfile
,
3257 struct dwarf2_per_cu_data
*per_cu
,
3258 const char *name
, const char *real_path
,
3259 gdb::function_view
<bool (symtab
*)> callback
)
3261 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3263 /* Don't visit already-expanded CUs. */
3264 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3265 if (per_objfile
->symtab_set_p (per_cu
))
3268 /* This may expand more than one symtab, and we want to iterate over
3270 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3272 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3273 last_made
, callback
);
3276 /* Implementation of the map_symtabs_matching_filename method. */
3279 dw2_map_symtabs_matching_filename
3280 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3281 gdb::function_view
<bool (symtab
*)> callback
)
3283 const char *name_basename
= lbasename (name
);
3284 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3286 /* The rule is CUs specify all the files, including those used by
3287 any TU, so there's no need to scan TUs here. */
3289 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
3291 /* We only need to look at symtabs not already expanded. */
3292 if (per_objfile
->symtab_set_p (per_cu
))
3295 quick_file_names
*file_data
= dw2_get_file_names (per_cu
, per_objfile
);
3296 if (file_data
== NULL
)
3299 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3301 const char *this_name
= file_data
->file_names
[j
];
3302 const char *this_real_name
;
3304 if (compare_filenames_for_search (this_name
, name
))
3306 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3312 /* Before we invoke realpath, which can get expensive when many
3313 files are involved, do a quick comparison of the basenames. */
3314 if (! basenames_may_differ
3315 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3318 this_real_name
= dw2_get_real_path (per_objfile
, file_data
, j
);
3319 if (compare_filenames_for_search (this_real_name
, name
))
3321 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3327 if (real_path
!= NULL
)
3329 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3330 gdb_assert (IS_ABSOLUTE_PATH (name
));
3331 if (this_real_name
!= NULL
3332 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3334 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3346 /* Struct used to manage iterating over all CUs looking for a symbol. */
3348 struct dw2_symtab_iterator
3350 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3351 dwarf2_per_objfile
*per_objfile
;
3352 /* If set, only look for symbols that match that block. Valid values are
3353 GLOBAL_BLOCK and STATIC_BLOCK. */
3354 gdb::optional
<block_enum
> block_index
;
3355 /* The kind of symbol we're looking for. */
3357 /* The list of CUs from the index entry of the symbol,
3358 or NULL if not found. */
3360 /* The next element in VEC to look at. */
3362 /* The number of elements in VEC, or zero if there is no match. */
3364 /* Have we seen a global version of the symbol?
3365 If so we can ignore all further global instances.
3366 This is to work around gold/15646, inefficient gold-generated
3371 /* Initialize the index symtab iterator ITER, common part. */
3374 dw2_symtab_iter_init_common (struct dw2_symtab_iterator
*iter
,
3375 dwarf2_per_objfile
*per_objfile
,
3376 gdb::optional
<block_enum
> block_index
,
3379 iter
->per_objfile
= per_objfile
;
3380 iter
->block_index
= block_index
;
3381 iter
->domain
= domain
;
3383 iter
->global_seen
= 0;
3388 /* Initialize the index symtab iterator ITER, const char *NAME variant. */
3391 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3392 dwarf2_per_objfile
*per_objfile
,
3393 gdb::optional
<block_enum
> block_index
,
3397 dw2_symtab_iter_init_common (iter
, per_objfile
, block_index
, domain
);
3399 mapped_index
*index
= per_objfile
->per_bfd
->index_table
.get ();
3400 /* index is NULL if OBJF_READNOW. */
3404 if (find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3405 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3408 /* Initialize the index symtab iterator ITER, offset_type NAMEI variant. */
3411 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3412 dwarf2_per_objfile
*per_objfile
,
3413 gdb::optional
<block_enum
> block_index
,
3414 domain_enum domain
, offset_type namei
)
3416 dw2_symtab_iter_init_common (iter
, per_objfile
, block_index
, domain
);
3418 mapped_index
*index
= per_objfile
->per_bfd
->index_table
.get ();
3419 /* index is NULL if OBJF_READNOW. */
3423 gdb_assert (!index
->symbol_name_slot_invalid (namei
));
3424 const auto &bucket
= index
->symbol_table
[namei
];
3426 iter
->vec
= (offset_type
*) (index
->constant_pool
3427 + MAYBE_SWAP (bucket
.vec
));
3428 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3431 /* Return the next matching CU or NULL if there are no more. */
3433 static struct dwarf2_per_cu_data
*
3434 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3436 dwarf2_per_objfile
*per_objfile
= iter
->per_objfile
;
3438 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3440 offset_type cu_index_and_attrs
=
3441 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3442 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3443 gdb_index_symbol_kind symbol_kind
=
3444 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3445 /* Only check the symbol attributes if they're present.
3446 Indices prior to version 7 don't record them,
3447 and indices >= 7 may elide them for certain symbols
3448 (gold does this). */
3450 (per_objfile
->per_bfd
->index_table
->version
>= 7
3451 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3453 /* Don't crash on bad data. */
3454 if (cu_index
>= (per_objfile
->per_bfd
->all_comp_units
.size ()
3455 + per_objfile
->per_bfd
->all_type_units
.size ()))
3457 complaint (_(".gdb_index entry has bad CU index"
3458 " [in module %s]"), objfile_name (per_objfile
->objfile
));
3462 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (cu_index
);
3464 /* Skip if already read in. */
3465 if (per_objfile
->symtab_set_p (per_cu
))
3468 /* Check static vs global. */
3471 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3473 if (iter
->block_index
.has_value ())
3475 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3477 if (is_static
!= want_static
)
3481 /* Work around gold/15646. */
3483 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
3485 if (iter
->global_seen
)
3488 iter
->global_seen
= 1;
3492 /* Only check the symbol's kind if it has one. */
3495 switch (iter
->domain
)
3498 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3499 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3500 /* Some types are also in VAR_DOMAIN. */
3501 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3505 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3509 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3513 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3528 static struct compunit_symtab
*
3529 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
3530 const char *name
, domain_enum domain
)
3532 struct compunit_symtab
*stab_best
= NULL
;
3533 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3535 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
3537 struct dw2_symtab_iterator iter
;
3538 struct dwarf2_per_cu_data
*per_cu
;
3540 dw2_symtab_iter_init (&iter
, per_objfile
, block_index
, domain
, name
);
3542 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3544 struct symbol
*sym
, *with_opaque
= NULL
;
3545 struct compunit_symtab
*stab
3546 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3547 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
3548 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3550 sym
= block_find_symbol (block
, name
, domain
,
3551 block_find_non_opaque_type_preferred
,
3554 /* Some caution must be observed with overloaded functions
3555 and methods, since the index will not contain any overload
3556 information (but NAME might contain it). */
3559 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
3561 if (with_opaque
!= NULL
3562 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
3565 /* Keep looking through other CUs. */
3572 dw2_print_stats (struct objfile
*objfile
)
3574 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3575 int total
= (per_objfile
->per_bfd
->all_comp_units
.size ()
3576 + per_objfile
->per_bfd
->all_type_units
.size ());
3579 for (int i
= 0; i
< total
; ++i
)
3581 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (i
);
3583 if (!per_objfile
->symtab_set_p (per_cu
))
3586 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3587 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3590 /* This dumps minimal information about the index.
3591 It is called via "mt print objfiles".
3592 One use is to verify .gdb_index has been loaded by the
3593 gdb.dwarf2/gdb-index.exp testcase. */
3596 dw2_dump (struct objfile
*objfile
)
3598 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3600 gdb_assert (per_objfile
->per_bfd
->using_index
);
3601 printf_filtered (".gdb_index:");
3602 if (per_objfile
->per_bfd
->index_table
!= NULL
)
3604 printf_filtered (" version %d\n",
3605 per_objfile
->per_bfd
->index_table
->version
);
3608 printf_filtered (" faked for \"readnow\"\n");
3609 printf_filtered ("\n");
3613 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3614 const char *func_name
)
3616 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3618 struct dw2_symtab_iterator iter
;
3619 struct dwarf2_per_cu_data
*per_cu
;
3621 dw2_symtab_iter_init (&iter
, per_objfile
, {}, VAR_DOMAIN
, func_name
);
3623 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3624 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3629 dw2_expand_all_symtabs (struct objfile
*objfile
)
3631 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3632 int total_units
= (per_objfile
->per_bfd
->all_comp_units
.size ()
3633 + per_objfile
->per_bfd
->all_type_units
.size ());
3635 for (int i
= 0; i
< total_units
; ++i
)
3637 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (i
);
3639 /* We don't want to directly expand a partial CU, because if we
3640 read it with the wrong language, then assertion failures can
3641 be triggered later on. See PR symtab/23010. So, tell
3642 dw2_instantiate_symtab to skip partial CUs -- any important
3643 partial CU will be read via DW_TAG_imported_unit anyway. */
3644 dw2_instantiate_symtab (per_cu
, per_objfile
, true);
3649 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
3650 const char *fullname
)
3652 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3654 /* We don't need to consider type units here.
3655 This is only called for examining code, e.g. expand_line_sal.
3656 There can be an order of magnitude (or more) more type units
3657 than comp units, and we avoid them if we can. */
3659 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
3661 /* We only need to look at symtabs not already expanded. */
3662 if (per_objfile
->symtab_set_p (per_cu
))
3665 quick_file_names
*file_data
= dw2_get_file_names (per_cu
, per_objfile
);
3666 if (file_data
== NULL
)
3669 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3671 const char *this_fullname
= file_data
->file_names
[j
];
3673 if (filename_cmp (this_fullname
, fullname
) == 0)
3675 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3683 dw2_expand_symtabs_matching_symbol
3684 (mapped_index_base
&index
,
3685 const lookup_name_info
&lookup_name_in
,
3686 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3687 enum search_domain kind
,
3688 gdb::function_view
<bool (offset_type
)> match_callback
,
3689 dwarf2_per_objfile
*per_objfile
);
3692 dw2_expand_symtabs_matching_one
3693 (dwarf2_per_cu_data
*per_cu
,
3694 dwarf2_per_objfile
*per_objfile
,
3695 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
3696 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
);
3699 dw2_map_matching_symbols
3700 (struct objfile
*objfile
,
3701 const lookup_name_info
&name
, domain_enum domain
,
3703 gdb::function_view
<symbol_found_callback_ftype
> callback
,
3704 symbol_compare_ftype
*ordered_compare
)
3707 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3709 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
3711 if (per_objfile
->per_bfd
->index_table
!= nullptr)
3713 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
3715 const char *match_name
= name
.ada ().lookup_name ().c_str ();
3716 auto matcher
= [&] (const char *symname
)
3718 if (ordered_compare
== nullptr)
3720 return ordered_compare (symname
, match_name
) == 0;
3723 dw2_expand_symtabs_matching_symbol (index
, name
, matcher
, ALL_DOMAIN
,
3724 [&] (offset_type namei
)
3726 struct dw2_symtab_iterator iter
;
3727 struct dwarf2_per_cu_data
*per_cu
;
3729 dw2_symtab_iter_init (&iter
, per_objfile
, block_kind
, domain
,
3731 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3732 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
3739 /* We have -readnow: no .gdb_index, but no partial symtabs either. So,
3740 proceed assuming all symtabs have been read in. */
3743 for (compunit_symtab
*cust
: objfile
->compunits ())
3745 const struct block
*block
;
3749 block
= BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
3750 if (!iterate_over_symbols_terminated (block
, name
,
3756 /* Starting from a search name, return the string that finds the upper
3757 bound of all strings that start with SEARCH_NAME in a sorted name
3758 list. Returns the empty string to indicate that the upper bound is
3759 the end of the list. */
3762 make_sort_after_prefix_name (const char *search_name
)
3764 /* When looking to complete "func", we find the upper bound of all
3765 symbols that start with "func" by looking for where we'd insert
3766 the closest string that would follow "func" in lexicographical
3767 order. Usually, that's "func"-with-last-character-incremented,
3768 i.e. "fund". Mind non-ASCII characters, though. Usually those
3769 will be UTF-8 multi-byte sequences, but we can't be certain.
3770 Especially mind the 0xff character, which is a valid character in
3771 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3772 rule out compilers allowing it in identifiers. Note that
3773 conveniently, strcmp/strcasecmp are specified to compare
3774 characters interpreted as unsigned char. So what we do is treat
3775 the whole string as a base 256 number composed of a sequence of
3776 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3777 to 0, and carries 1 to the following more-significant position.
3778 If the very first character in SEARCH_NAME ends up incremented
3779 and carries/overflows, then the upper bound is the end of the
3780 list. The string after the empty string is also the empty
3783 Some examples of this operation:
3785 SEARCH_NAME => "+1" RESULT
3789 "\xff" "a" "\xff" => "\xff" "b"
3794 Then, with these symbols for example:
3800 completing "func" looks for symbols between "func" and
3801 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3802 which finds "func" and "func1", but not "fund".
3806 funcÿ (Latin1 'ÿ' [0xff])
3810 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3811 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3815 ÿÿ (Latin1 'ÿ' [0xff])
3818 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3819 the end of the list.
3821 std::string after
= search_name
;
3822 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3824 if (!after
.empty ())
3825 after
.back () = (unsigned char) after
.back () + 1;
3829 /* See declaration. */
3831 std::pair
<std::vector
<name_component
>::const_iterator
,
3832 std::vector
<name_component
>::const_iterator
>
3833 mapped_index_base::find_name_components_bounds
3834 (const lookup_name_info
&lookup_name_without_params
, language lang
,
3835 dwarf2_per_objfile
*per_objfile
) const
3838 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3840 const char *lang_name
3841 = lookup_name_without_params
.language_lookup_name (lang
);
3843 /* Comparison function object for lower_bound that matches against a
3844 given symbol name. */
3845 auto lookup_compare_lower
= [&] (const name_component
&elem
,
3848 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3849 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3850 return name_cmp (elem_name
, name
) < 0;
3853 /* Comparison function object for upper_bound that matches against a
3854 given symbol name. */
3855 auto lookup_compare_upper
= [&] (const char *name
,
3856 const name_component
&elem
)
3858 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3859 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3860 return name_cmp (name
, elem_name
) < 0;
3863 auto begin
= this->name_components
.begin ();
3864 auto end
= this->name_components
.end ();
3866 /* Find the lower bound. */
3869 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3872 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
3875 /* Find the upper bound. */
3878 if (lookup_name_without_params
.completion_mode ())
3880 /* In completion mode, we want UPPER to point past all
3881 symbols names that have the same prefix. I.e., with
3882 these symbols, and completing "func":
3884 function << lower bound
3886 other_function << upper bound
3888 We find the upper bound by looking for the insertion
3889 point of "func"-with-last-character-incremented,
3891 std::string after
= make_sort_after_prefix_name (lang_name
);
3894 return std::lower_bound (lower
, end
, after
.c_str (),
3895 lookup_compare_lower
);
3898 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
3901 return {lower
, upper
};
3904 /* See declaration. */
3907 mapped_index_base::build_name_components (dwarf2_per_objfile
*per_objfile
)
3909 if (!this->name_components
.empty ())
3912 this->name_components_casing
= case_sensitivity
;
3914 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3916 /* The code below only knows how to break apart components of C++
3917 symbol names (and other languages that use '::' as
3918 namespace/module separator) and Ada symbol names. */
3919 auto count
= this->symbol_name_count ();
3920 for (offset_type idx
= 0; idx
< count
; idx
++)
3922 if (this->symbol_name_slot_invalid (idx
))
3925 const char *name
= this->symbol_name_at (idx
, per_objfile
);
3927 /* Add each name component to the name component table. */
3928 unsigned int previous_len
= 0;
3930 if (strstr (name
, "::") != nullptr)
3932 for (unsigned int current_len
= cp_find_first_component (name
);
3933 name
[current_len
] != '\0';
3934 current_len
+= cp_find_first_component (name
+ current_len
))
3936 gdb_assert (name
[current_len
] == ':');
3937 this->name_components
.push_back ({previous_len
, idx
});
3938 /* Skip the '::'. */
3940 previous_len
= current_len
;
3945 /* Handle the Ada encoded (aka mangled) form here. */
3946 for (const char *iter
= strstr (name
, "__");
3948 iter
= strstr (iter
, "__"))
3950 this->name_components
.push_back ({previous_len
, idx
});
3952 previous_len
= iter
- name
;
3956 this->name_components
.push_back ({previous_len
, idx
});
3959 /* Sort name_components elements by name. */
3960 auto name_comp_compare
= [&] (const name_component
&left
,
3961 const name_component
&right
)
3963 const char *left_qualified
3964 = this->symbol_name_at (left
.idx
, per_objfile
);
3965 const char *right_qualified
3966 = this->symbol_name_at (right
.idx
, per_objfile
);
3968 const char *left_name
= left_qualified
+ left
.name_offset
;
3969 const char *right_name
= right_qualified
+ right
.name_offset
;
3971 return name_cmp (left_name
, right_name
) < 0;
3974 std::sort (this->name_components
.begin (),
3975 this->name_components
.end (),
3979 /* Helper for dw2_expand_symtabs_matching that works with a
3980 mapped_index_base instead of the containing objfile. This is split
3981 to a separate function in order to be able to unit test the
3982 name_components matching using a mock mapped_index_base. For each
3983 symbol name that matches, calls MATCH_CALLBACK, passing it the
3984 symbol's index in the mapped_index_base symbol table. */
3987 dw2_expand_symtabs_matching_symbol
3988 (mapped_index_base
&index
,
3989 const lookup_name_info
&lookup_name_in
,
3990 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3991 enum search_domain kind
,
3992 gdb::function_view
<bool (offset_type
)> match_callback
,
3993 dwarf2_per_objfile
*per_objfile
)
3995 lookup_name_info lookup_name_without_params
3996 = lookup_name_in
.make_ignore_params ();
3998 /* Build the symbol name component sorted vector, if we haven't
4000 index
.build_name_components (per_objfile
);
4002 /* The same symbol may appear more than once in the range though.
4003 E.g., if we're looking for symbols that complete "w", and we have
4004 a symbol named "w1::w2", we'll find the two name components for
4005 that same symbol in the range. To be sure we only call the
4006 callback once per symbol, we first collect the symbol name
4007 indexes that matched in a temporary vector and ignore
4009 std::vector
<offset_type
> matches
;
4011 struct name_and_matcher
4013 symbol_name_matcher_ftype
*matcher
;
4016 bool operator== (const name_and_matcher
&other
) const
4018 return matcher
== other
.matcher
&& strcmp (name
, other
.name
) == 0;
4022 /* A vector holding all the different symbol name matchers, for all
4024 std::vector
<name_and_matcher
> matchers
;
4026 for (int i
= 0; i
< nr_languages
; i
++)
4028 enum language lang_e
= (enum language
) i
;
4030 const language_defn
*lang
= language_def (lang_e
);
4031 symbol_name_matcher_ftype
*name_matcher
4032 = lang
->get_symbol_name_matcher (lookup_name_without_params
);
4034 name_and_matcher key
{
4036 lookup_name_without_params
.language_lookup_name (lang_e
)
4039 /* Don't insert the same comparison routine more than once.
4040 Note that we do this linear walk. This is not a problem in
4041 practice because the number of supported languages is
4043 if (std::find (matchers
.begin (), matchers
.end (), key
)
4046 matchers
.push_back (std::move (key
));
4049 = index
.find_name_components_bounds (lookup_name_without_params
,
4050 lang_e
, per_objfile
);
4052 /* Now for each symbol name in range, check to see if we have a name
4053 match, and if so, call the MATCH_CALLBACK callback. */
4055 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
4057 const char *qualified
4058 = index
.symbol_name_at (bounds
.first
->idx
, per_objfile
);
4060 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
4061 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4064 matches
.push_back (bounds
.first
->idx
);
4068 std::sort (matches
.begin (), matches
.end ());
4070 /* Finally call the callback, once per match. */
4072 for (offset_type idx
: matches
)
4076 if (!match_callback (idx
))
4082 /* Above we use a type wider than idx's for 'prev', since 0 and
4083 (offset_type)-1 are both possible values. */
4084 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4089 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4091 /* A mock .gdb_index/.debug_names-like name index table, enough to
4092 exercise dw2_expand_symtabs_matching_symbol, which works with the
4093 mapped_index_base interface. Builds an index from the symbol list
4094 passed as parameter to the constructor. */
4095 class mock_mapped_index
: public mapped_index_base
4098 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4099 : m_symbol_table (symbols
)
4102 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4104 /* Return the number of names in the symbol table. */
4105 size_t symbol_name_count () const override
4107 return m_symbol_table
.size ();
4110 /* Get the name of the symbol at IDX in the symbol table. */
4111 const char *symbol_name_at
4112 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
4114 return m_symbol_table
[idx
];
4118 gdb::array_view
<const char *> m_symbol_table
;
4121 /* Convenience function that converts a NULL pointer to a "<null>"
4122 string, to pass to print routines. */
4125 string_or_null (const char *str
)
4127 return str
!= NULL
? str
: "<null>";
4130 /* Check if a lookup_name_info built from
4131 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4132 index. EXPECTED_LIST is the list of expected matches, in expected
4133 matching order. If no match expected, then an empty list is
4134 specified. Returns true on success. On failure prints a warning
4135 indicating the file:line that failed, and returns false. */
4138 check_match (const char *file
, int line
,
4139 mock_mapped_index
&mock_index
,
4140 const char *name
, symbol_name_match_type match_type
,
4141 bool completion_mode
,
4142 std::initializer_list
<const char *> expected_list
,
4143 dwarf2_per_objfile
*per_objfile
)
4145 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4147 bool matched
= true;
4149 auto mismatch
= [&] (const char *expected_str
,
4152 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4153 "expected=\"%s\", got=\"%s\"\n"),
4155 (match_type
== symbol_name_match_type::FULL
4157 name
, string_or_null (expected_str
), string_or_null (got
));
4161 auto expected_it
= expected_list
.begin ();
4162 auto expected_end
= expected_list
.end ();
4164 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4166 [&] (offset_type idx
)
4168 const char *matched_name
= mock_index
.symbol_name_at (idx
, per_objfile
);
4169 const char *expected_str
4170 = expected_it
== expected_end
? NULL
: *expected_it
++;
4172 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4173 mismatch (expected_str
, matched_name
);
4177 const char *expected_str
4178 = expected_it
== expected_end
? NULL
: *expected_it
++;
4179 if (expected_str
!= NULL
)
4180 mismatch (expected_str
, NULL
);
4185 /* The symbols added to the mock mapped_index for testing (in
4187 static const char *test_symbols
[] = {
4196 "ns2::tmpl<int>::foo2",
4197 "(anonymous namespace)::A::B::C",
4199 /* These are used to check that the increment-last-char in the
4200 matching algorithm for completion doesn't match "t1_fund" when
4201 completing "t1_func". */
4207 /* A UTF-8 name with multi-byte sequences to make sure that
4208 cp-name-parser understands this as a single identifier ("função"
4209 is "function" in PT). */
4212 /* \377 (0xff) is Latin1 'ÿ'. */
4215 /* \377 (0xff) is Latin1 'ÿ'. */
4219 /* A name with all sorts of complications. Starts with "z" to make
4220 it easier for the completion tests below. */
4221 #define Z_SYM_NAME \
4222 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4223 "::tuple<(anonymous namespace)::ui*, " \
4224 "std::default_delete<(anonymous namespace)::ui>, void>"
4229 /* Returns true if the mapped_index_base::find_name_component_bounds
4230 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4231 in completion mode. */
4234 check_find_bounds_finds (mapped_index_base
&index
,
4235 const char *search_name
,
4236 gdb::array_view
<const char *> expected_syms
,
4237 dwarf2_per_objfile
*per_objfile
)
4239 lookup_name_info
lookup_name (search_name
,
4240 symbol_name_match_type::FULL
, true);
4242 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4246 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4247 if (distance
!= expected_syms
.size ())
4250 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4252 auto nc_elem
= bounds
.first
+ exp_elem
;
4253 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
, per_objfile
);
4254 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4261 /* Test the lower-level mapped_index::find_name_component_bounds
4265 test_mapped_index_find_name_component_bounds ()
4267 mock_mapped_index
mock_index (test_symbols
);
4269 mock_index
.build_name_components (NULL
/* per_objfile */);
4271 /* Test the lower-level mapped_index::find_name_component_bounds
4272 method in completion mode. */
4274 static const char *expected_syms
[] = {
4279 SELF_CHECK (check_find_bounds_finds
4280 (mock_index
, "t1_func", expected_syms
,
4281 NULL
/* per_objfile */));
4284 /* Check that the increment-last-char in the name matching algorithm
4285 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4287 static const char *expected_syms1
[] = {
4291 SELF_CHECK (check_find_bounds_finds
4292 (mock_index
, "\377", expected_syms1
, NULL
/* per_objfile */));
4294 static const char *expected_syms2
[] = {
4297 SELF_CHECK (check_find_bounds_finds
4298 (mock_index
, "\377\377", expected_syms2
,
4299 NULL
/* per_objfile */));
4303 /* Test dw2_expand_symtabs_matching_symbol. */
4306 test_dw2_expand_symtabs_matching_symbol ()
4308 mock_mapped_index
mock_index (test_symbols
);
4310 /* We let all tests run until the end even if some fails, for debug
4312 bool any_mismatch
= false;
4314 /* Create the expected symbols list (an initializer_list). Needed
4315 because lists have commas, and we need to pass them to CHECK,
4316 which is a macro. */
4317 #define EXPECT(...) { __VA_ARGS__ }
4319 /* Wrapper for check_match that passes down the current
4320 __FILE__/__LINE__. */
4321 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4322 any_mismatch |= !check_match (__FILE__, __LINE__, \
4324 NAME, MATCH_TYPE, COMPLETION_MODE, \
4325 EXPECTED_LIST, NULL)
4327 /* Identity checks. */
4328 for (const char *sym
: test_symbols
)
4330 /* Should be able to match all existing symbols. */
4331 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4334 /* Should be able to match all existing symbols with
4336 std::string with_params
= std::string (sym
) + "(int)";
4337 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4340 /* Should be able to match all existing symbols with
4341 parameters and qualifiers. */
4342 with_params
= std::string (sym
) + " ( int ) const";
4343 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4346 /* This should really find sym, but cp-name-parser.y doesn't
4347 know about lvalue/rvalue qualifiers yet. */
4348 with_params
= std::string (sym
) + " ( int ) &&";
4349 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4353 /* Check that the name matching algorithm for completion doesn't get
4354 confused with Latin1 'ÿ' / 0xff. */
4356 static const char str
[] = "\377";
4357 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4358 EXPECT ("\377", "\377\377123"));
4361 /* Check that the increment-last-char in the matching algorithm for
4362 completion doesn't match "t1_fund" when completing "t1_func". */
4364 static const char str
[] = "t1_func";
4365 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4366 EXPECT ("t1_func", "t1_func1"));
4369 /* Check that completion mode works at each prefix of the expected
4372 static const char str
[] = "function(int)";
4373 size_t len
= strlen (str
);
4376 for (size_t i
= 1; i
< len
; i
++)
4378 lookup
.assign (str
, i
);
4379 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4380 EXPECT ("function"));
4384 /* While "w" is a prefix of both components, the match function
4385 should still only be called once. */
4387 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4389 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4393 /* Same, with a "complicated" symbol. */
4395 static const char str
[] = Z_SYM_NAME
;
4396 size_t len
= strlen (str
);
4399 for (size_t i
= 1; i
< len
; i
++)
4401 lookup
.assign (str
, i
);
4402 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4403 EXPECT (Z_SYM_NAME
));
4407 /* In FULL mode, an incomplete symbol doesn't match. */
4409 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4413 /* A complete symbol with parameters matches any overload, since the
4414 index has no overload info. */
4416 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4417 EXPECT ("std::zfunction", "std::zfunction2"));
4418 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4419 EXPECT ("std::zfunction", "std::zfunction2"));
4420 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4421 EXPECT ("std::zfunction", "std::zfunction2"));
4424 /* Check that whitespace is ignored appropriately. A symbol with a
4425 template argument list. */
4427 static const char expected
[] = "ns::foo<int>";
4428 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4430 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4434 /* Check that whitespace is ignored appropriately. A symbol with a
4435 template argument list that includes a pointer. */
4437 static const char expected
[] = "ns::foo<char*>";
4438 /* Try both completion and non-completion modes. */
4439 static const bool completion_mode
[2] = {false, true};
4440 for (size_t i
= 0; i
< 2; i
++)
4442 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4443 completion_mode
[i
], EXPECT (expected
));
4444 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4445 completion_mode
[i
], EXPECT (expected
));
4447 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4448 completion_mode
[i
], EXPECT (expected
));
4449 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4450 completion_mode
[i
], EXPECT (expected
));
4455 /* Check method qualifiers are ignored. */
4456 static const char expected
[] = "ns::foo<char*>";
4457 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4458 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4459 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4460 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4461 CHECK_MATCH ("foo < char * > ( int ) const",
4462 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4463 CHECK_MATCH ("foo < char * > ( int ) &&",
4464 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4467 /* Test lookup names that don't match anything. */
4469 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4472 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4476 /* Some wild matching tests, exercising "(anonymous namespace)",
4477 which should not be confused with a parameter list. */
4479 static const char *syms
[] = {
4483 "A :: B :: C ( int )",
4488 for (const char *s
: syms
)
4490 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4491 EXPECT ("(anonymous namespace)::A::B::C"));
4496 static const char expected
[] = "ns2::tmpl<int>::foo2";
4497 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4499 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4503 SELF_CHECK (!any_mismatch
);
4512 test_mapped_index_find_name_component_bounds ();
4513 test_dw2_expand_symtabs_matching_symbol ();
4516 }} // namespace selftests::dw2_expand_symtabs_matching
4518 #endif /* GDB_SELF_TEST */
4520 /* If FILE_MATCHER is NULL or if PER_CU has
4521 dwarf2_per_cu_quick_data::MARK set (see
4522 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4523 EXPANSION_NOTIFY on it. */
4526 dw2_expand_symtabs_matching_one
4527 (dwarf2_per_cu_data
*per_cu
,
4528 dwarf2_per_objfile
*per_objfile
,
4529 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4530 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4532 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4534 bool symtab_was_null
= !per_objfile
->symtab_set_p (per_cu
);
4536 compunit_symtab
*symtab
4537 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
4538 gdb_assert (symtab
!= nullptr);
4540 if (expansion_notify
!= NULL
&& symtab_was_null
)
4541 expansion_notify (symtab
);
4545 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4546 matched, to expand corresponding CUs that were marked. IDX is the
4547 index of the symbol name that matched. */
4550 dw2_expand_marked_cus
4551 (dwarf2_per_objfile
*per_objfile
, offset_type idx
,
4552 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4553 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4556 offset_type
*vec
, vec_len
, vec_idx
;
4557 bool global_seen
= false;
4558 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4560 vec
= (offset_type
*) (index
.constant_pool
4561 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
4562 vec_len
= MAYBE_SWAP (vec
[0]);
4563 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4565 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
4566 /* This value is only valid for index versions >= 7. */
4567 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4568 gdb_index_symbol_kind symbol_kind
=
4569 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4570 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4571 /* Only check the symbol attributes if they're present.
4572 Indices prior to version 7 don't record them,
4573 and indices >= 7 may elide them for certain symbols
4574 (gold does this). */
4577 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4579 /* Work around gold/15646. */
4582 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
4590 /* Only check the symbol's kind if it has one. */
4595 case VARIABLES_DOMAIN
:
4596 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4599 case FUNCTIONS_DOMAIN
:
4600 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4604 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4607 case MODULES_DOMAIN
:
4608 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4616 /* Don't crash on bad data. */
4617 if (cu_index
>= (per_objfile
->per_bfd
->all_comp_units
.size ()
4618 + per_objfile
->per_bfd
->all_type_units
.size ()))
4620 complaint (_(".gdb_index entry has bad CU index"
4621 " [in module %s]"), objfile_name (per_objfile
->objfile
));
4625 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (cu_index
);
4626 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
4631 /* If FILE_MATCHER is non-NULL, set all the
4632 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4633 that match FILE_MATCHER. */
4636 dw_expand_symtabs_matching_file_matcher
4637 (dwarf2_per_objfile
*per_objfile
,
4638 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4640 if (file_matcher
== NULL
)
4643 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4645 NULL
, xcalloc
, xfree
));
4646 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4648 NULL
, xcalloc
, xfree
));
4650 /* The rule is CUs specify all the files, including those used by
4651 any TU, so there's no need to scan TUs here. */
4653 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4657 per_cu
->v
.quick
->mark
= 0;
4659 /* We only need to look at symtabs not already expanded. */
4660 if (per_objfile
->symtab_set_p (per_cu
))
4663 quick_file_names
*file_data
= dw2_get_file_names (per_cu
, per_objfile
);
4664 if (file_data
== NULL
)
4667 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4669 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4671 per_cu
->v
.quick
->mark
= 1;
4675 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4677 const char *this_real_name
;
4679 if (file_matcher (file_data
->file_names
[j
], false))
4681 per_cu
->v
.quick
->mark
= 1;
4685 /* Before we invoke realpath, which can get expensive when many
4686 files are involved, do a quick comparison of the basenames. */
4687 if (!basenames_may_differ
4688 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4692 this_real_name
= dw2_get_real_path (per_objfile
, file_data
, j
);
4693 if (file_matcher (this_real_name
, false))
4695 per_cu
->v
.quick
->mark
= 1;
4700 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4701 ? visited_found
.get ()
4702 : visited_not_found
.get (),
4709 dw2_expand_symtabs_matching
4710 (struct objfile
*objfile
,
4711 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4712 const lookup_name_info
*lookup_name
,
4713 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4714 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4715 enum search_domain kind
)
4717 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4719 /* index_table is NULL if OBJF_READNOW. */
4720 if (!per_objfile
->per_bfd
->index_table
)
4723 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
4725 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
4727 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4731 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
,
4732 file_matcher
, expansion_notify
);
4737 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4739 dw2_expand_symtabs_matching_symbol (index
, *lookup_name
,
4741 kind
, [&] (offset_type idx
)
4743 dw2_expand_marked_cus (per_objfile
, idx
, file_matcher
, expansion_notify
,
4749 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4752 static struct compunit_symtab
*
4753 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4758 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4759 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4762 if (cust
->includes
== NULL
)
4765 for (i
= 0; cust
->includes
[i
]; ++i
)
4767 struct compunit_symtab
*s
= cust
->includes
[i
];
4769 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4777 static struct compunit_symtab
*
4778 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
4779 struct bound_minimal_symbol msymbol
,
4781 struct obj_section
*section
,
4784 struct dwarf2_per_cu_data
*data
;
4785 struct compunit_symtab
*result
;
4787 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
4790 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4791 data
= (struct dwarf2_per_cu_data
*) addrmap_find
4792 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
4796 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4797 if (warn_if_readin
&& per_objfile
->symtab_set_p (data
))
4798 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4799 paddress (objfile
->arch (), pc
));
4801 result
= recursively_find_pc_sect_compunit_symtab
4802 (dw2_instantiate_symtab (data
, per_objfile
, false), pc
);
4804 gdb_assert (result
!= NULL
);
4809 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
4810 void *data
, int need_fullname
)
4812 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4814 if (!per_objfile
->per_bfd
->filenames_cache
)
4816 per_objfile
->per_bfd
->filenames_cache
.emplace ();
4818 htab_up
visited (htab_create_alloc (10,
4819 htab_hash_pointer
, htab_eq_pointer
,
4820 NULL
, xcalloc
, xfree
));
4822 /* The rule is CUs specify all the files, including those used
4823 by any TU, so there's no need to scan TUs here. We can
4824 ignore file names coming from already-expanded CUs. */
4826 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4828 if (per_objfile
->symtab_set_p (per_cu
))
4830 void **slot
= htab_find_slot (visited
.get (),
4831 per_cu
->v
.quick
->file_names
,
4834 *slot
= per_cu
->v
.quick
->file_names
;
4838 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4840 /* We only need to look at symtabs not already expanded. */
4841 if (per_objfile
->symtab_set_p (per_cu
))
4844 quick_file_names
*file_data
4845 = dw2_get_file_names (per_cu
, per_objfile
);
4846 if (file_data
== NULL
)
4849 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
4852 /* Already visited. */
4857 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4859 const char *filename
= file_data
->file_names
[j
];
4860 per_objfile
->per_bfd
->filenames_cache
->seen (filename
);
4865 per_objfile
->per_bfd
->filenames_cache
->traverse ([&] (const char *filename
)
4867 gdb::unique_xmalloc_ptr
<char> this_real_name
;
4870 this_real_name
= gdb_realpath (filename
);
4871 (*fun
) (filename
, this_real_name
.get (), data
);
4876 dw2_has_symbols (struct objfile
*objfile
)
4881 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
4884 dw2_find_last_source_symtab
,
4885 dw2_forget_cached_source_info
,
4886 dw2_map_symtabs_matching_filename
,
4891 dw2_expand_symtabs_for_function
,
4892 dw2_expand_all_symtabs
,
4893 dw2_expand_symtabs_with_fullname
,
4894 dw2_map_matching_symbols
,
4895 dw2_expand_symtabs_matching
,
4896 dw2_find_pc_sect_compunit_symtab
,
4898 dw2_map_symbol_filenames
4901 /* DWARF-5 debug_names reader. */
4903 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
4904 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
4906 /* A helper function that reads the .debug_names section in SECTION
4907 and fills in MAP. FILENAME is the name of the file containing the
4908 section; it is used for error reporting.
4910 Returns true if all went well, false otherwise. */
4913 read_debug_names_from_section (struct objfile
*objfile
,
4914 const char *filename
,
4915 struct dwarf2_section_info
*section
,
4916 mapped_debug_names
&map
)
4918 if (section
->empty ())
4921 /* Older elfutils strip versions could keep the section in the main
4922 executable while splitting it for the separate debug info file. */
4923 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
4926 section
->read (objfile
);
4928 map
.dwarf5_byte_order
= gdbarch_byte_order (objfile
->arch ());
4930 const gdb_byte
*addr
= section
->buffer
;
4932 bfd
*const abfd
= section
->get_bfd_owner ();
4934 unsigned int bytes_read
;
4935 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
4938 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
4939 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
4940 if (bytes_read
+ length
!= section
->size
)
4942 /* There may be multiple per-CU indices. */
4943 warning (_("Section .debug_names in %s length %s does not match "
4944 "section length %s, ignoring .debug_names."),
4945 filename
, plongest (bytes_read
+ length
),
4946 pulongest (section
->size
));
4950 /* The version number. */
4951 uint16_t version
= read_2_bytes (abfd
, addr
);
4955 warning (_("Section .debug_names in %s has unsupported version %d, "
4956 "ignoring .debug_names."),
4962 uint16_t padding
= read_2_bytes (abfd
, addr
);
4966 warning (_("Section .debug_names in %s has unsupported padding %d, "
4967 "ignoring .debug_names."),
4972 /* comp_unit_count - The number of CUs in the CU list. */
4973 map
.cu_count
= read_4_bytes (abfd
, addr
);
4976 /* local_type_unit_count - The number of TUs in the local TU
4978 map
.tu_count
= read_4_bytes (abfd
, addr
);
4981 /* foreign_type_unit_count - The number of TUs in the foreign TU
4983 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
4985 if (foreign_tu_count
!= 0)
4987 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
4988 "ignoring .debug_names."),
4989 filename
, static_cast<unsigned long> (foreign_tu_count
));
4993 /* bucket_count - The number of hash buckets in the hash lookup
4995 map
.bucket_count
= read_4_bytes (abfd
, addr
);
4998 /* name_count - The number of unique names in the index. */
4999 map
.name_count
= read_4_bytes (abfd
, addr
);
5002 /* abbrev_table_size - The size in bytes of the abbreviations
5004 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
5007 /* augmentation_string_size - The size in bytes of the augmentation
5008 string. This value is rounded up to a multiple of 4. */
5009 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
5011 map
.augmentation_is_gdb
= ((augmentation_string_size
5012 == sizeof (dwarf5_augmentation
))
5013 && memcmp (addr
, dwarf5_augmentation
,
5014 sizeof (dwarf5_augmentation
)) == 0);
5015 augmentation_string_size
+= (-augmentation_string_size
) & 3;
5016 addr
+= augmentation_string_size
;
5019 map
.cu_table_reordered
= addr
;
5020 addr
+= map
.cu_count
* map
.offset_size
;
5022 /* List of Local TUs */
5023 map
.tu_table_reordered
= addr
;
5024 addr
+= map
.tu_count
* map
.offset_size
;
5026 /* Hash Lookup Table */
5027 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5028 addr
+= map
.bucket_count
* 4;
5029 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5030 addr
+= map
.name_count
* 4;
5033 map
.name_table_string_offs_reordered
= addr
;
5034 addr
+= map
.name_count
* map
.offset_size
;
5035 map
.name_table_entry_offs_reordered
= addr
;
5036 addr
+= map
.name_count
* map
.offset_size
;
5038 const gdb_byte
*abbrev_table_start
= addr
;
5041 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5046 const auto insertpair
5047 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
5048 if (!insertpair
.second
)
5050 warning (_("Section .debug_names in %s has duplicate index %s, "
5051 "ignoring .debug_names."),
5052 filename
, pulongest (index_num
));
5055 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
5056 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5061 mapped_debug_names::index_val::attr attr
;
5062 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5064 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5066 if (attr
.form
== DW_FORM_implicit_const
)
5068 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
5072 if (attr
.dw_idx
== 0 && attr
.form
== 0)
5074 indexval
.attr_vec
.push_back (std::move (attr
));
5077 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
5079 warning (_("Section .debug_names in %s has abbreviation_table "
5080 "of size %s vs. written as %u, ignoring .debug_names."),
5081 filename
, plongest (addr
- abbrev_table_start
),
5085 map
.entry_pool
= addr
;
5090 /* A helper for create_cus_from_debug_names that handles the MAP's CU
5094 create_cus_from_debug_names_list (dwarf2_per_bfd
*per_bfd
,
5095 const mapped_debug_names
&map
,
5096 dwarf2_section_info
§ion
,
5099 if (!map
.augmentation_is_gdb
)
5101 for (uint32_t i
= 0; i
< map
.cu_count
; ++i
)
5103 sect_offset sect_off
5104 = (sect_offset
) (extract_unsigned_integer
5105 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5107 map
.dwarf5_byte_order
));
5108 /* We don't know the length of the CU, because the CU list in a
5109 .debug_names index can be incomplete, so we can't use the start
5110 of the next CU as end of this CU. We create the CUs here with
5111 length 0, and in cutu_reader::cutu_reader we'll fill in the
5113 dwarf2_per_cu_data
*per_cu
5114 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
,
5116 per_bfd
->all_comp_units
.push_back (per_cu
);
5121 sect_offset sect_off_prev
;
5122 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5124 sect_offset sect_off_next
;
5125 if (i
< map
.cu_count
)
5128 = (sect_offset
) (extract_unsigned_integer
5129 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5131 map
.dwarf5_byte_order
));
5134 sect_off_next
= (sect_offset
) section
.size
;
5137 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5138 dwarf2_per_cu_data
*per_cu
5139 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
,
5140 sect_off_prev
, length
);
5141 per_bfd
->all_comp_units
.push_back (per_cu
);
5143 sect_off_prev
= sect_off_next
;
5147 /* Read the CU list from the mapped index, and use it to create all
5148 the CU objects for this dwarf2_per_objfile. */
5151 create_cus_from_debug_names (dwarf2_per_bfd
*per_bfd
,
5152 const mapped_debug_names
&map
,
5153 const mapped_debug_names
&dwz_map
)
5155 gdb_assert (per_bfd
->all_comp_units
.empty ());
5156 per_bfd
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5158 create_cus_from_debug_names_list (per_bfd
, map
, per_bfd
->info
,
5159 false /* is_dwz */);
5161 if (dwz_map
.cu_count
== 0)
5164 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
5165 create_cus_from_debug_names_list (per_bfd
, dwz_map
, dwz
->info
,
5169 /* Read .debug_names. If everything went ok, initialize the "quick"
5170 elements of all the CUs and return true. Otherwise, return false. */
5173 dwarf2_read_debug_names (dwarf2_per_objfile
*per_objfile
)
5175 std::unique_ptr
<mapped_debug_names
> map (new mapped_debug_names
);
5176 mapped_debug_names dwz_map
;
5177 struct objfile
*objfile
= per_objfile
->objfile
;
5178 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5180 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5181 &per_objfile
->per_bfd
->debug_names
, *map
))
5184 /* Don't use the index if it's empty. */
5185 if (map
->name_count
== 0)
5188 /* If there is a .dwz file, read it so we can get its CU list as
5190 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
5193 if (!read_debug_names_from_section (objfile
,
5194 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5195 &dwz
->debug_names
, dwz_map
))
5197 warning (_("could not read '.debug_names' section from %s; skipping"),
5198 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5203 create_cus_from_debug_names (per_bfd
, *map
, dwz_map
);
5205 if (map
->tu_count
!= 0)
5207 /* We can only handle a single .debug_types when we have an
5209 if (per_bfd
->types
.size () != 1)
5212 dwarf2_section_info
*section
= &per_bfd
->types
[0];
5214 create_signatured_type_table_from_debug_names
5215 (per_objfile
, *map
, section
, &per_bfd
->abbrev
);
5218 create_addrmap_from_aranges (per_objfile
, &per_bfd
->debug_aranges
);
5220 per_bfd
->debug_names_table
= std::move (map
);
5221 per_bfd
->using_index
= 1;
5222 per_bfd
->quick_file_names_table
=
5223 create_quick_file_names_table (per_objfile
->per_bfd
->all_comp_units
.size ());
5225 /* Save partial symtabs in the per_bfd object, for the benefit of subsequent
5226 objfiles using the same BFD. */
5227 gdb_assert (per_bfd
->partial_symtabs
== nullptr);
5228 per_bfd
->partial_symtabs
= objfile
->partial_symtabs
;
5233 /* Type used to manage iterating over all CUs looking for a symbol for
5236 class dw2_debug_names_iterator
5239 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5240 gdb::optional
<block_enum
> block_index
,
5242 const char *name
, dwarf2_per_objfile
*per_objfile
)
5243 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5244 m_addr (find_vec_in_debug_names (map
, name
, per_objfile
)),
5245 m_per_objfile (per_objfile
)
5248 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5249 search_domain search
, uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5252 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
5253 m_per_objfile (per_objfile
)
5256 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5257 block_enum block_index
, domain_enum domain
,
5258 uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5259 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5260 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
5261 m_per_objfile (per_objfile
)
5264 /* Return the next matching CU or NULL if there are no more. */
5265 dwarf2_per_cu_data
*next ();
5268 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5270 dwarf2_per_objfile
*per_objfile
);
5271 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5273 dwarf2_per_objfile
*per_objfile
);
5275 /* The internalized form of .debug_names. */
5276 const mapped_debug_names
&m_map
;
5278 /* If set, only look for symbols that match that block. Valid values are
5279 GLOBAL_BLOCK and STATIC_BLOCK. */
5280 const gdb::optional
<block_enum
> m_block_index
;
5282 /* The kind of symbol we're looking for. */
5283 const domain_enum m_domain
= UNDEF_DOMAIN
;
5284 const search_domain m_search
= ALL_DOMAIN
;
5286 /* The list of CUs from the index entry of the symbol, or NULL if
5288 const gdb_byte
*m_addr
;
5290 dwarf2_per_objfile
*m_per_objfile
;
5294 mapped_debug_names::namei_to_name
5295 (uint32_t namei
, dwarf2_per_objfile
*per_objfile
) const
5297 const ULONGEST namei_string_offs
5298 = extract_unsigned_integer ((name_table_string_offs_reordered
5299 + namei
* offset_size
),
5302 return read_indirect_string_at_offset (per_objfile
, namei_string_offs
);
5305 /* Find a slot in .debug_names for the object named NAME. If NAME is
5306 found, return pointer to its pool data. If NAME cannot be found,
5310 dw2_debug_names_iterator::find_vec_in_debug_names
5311 (const mapped_debug_names
&map
, const char *name
,
5312 dwarf2_per_objfile
*per_objfile
)
5314 int (*cmp
) (const char *, const char *);
5316 gdb::unique_xmalloc_ptr
<char> without_params
;
5317 if (current_language
->la_language
== language_cplus
5318 || current_language
->la_language
== language_fortran
5319 || current_language
->la_language
== language_d
)
5321 /* NAME is already canonical. Drop any qualifiers as
5322 .debug_names does not contain any. */
5324 if (strchr (name
, '(') != NULL
)
5326 without_params
= cp_remove_params (name
);
5327 if (without_params
!= NULL
)
5328 name
= without_params
.get ();
5332 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5334 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5336 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5337 (map
.bucket_table_reordered
5338 + (full_hash
% map
.bucket_count
)), 4,
5339 map
.dwarf5_byte_order
);
5343 if (namei
>= map
.name_count
)
5345 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5347 namei
, map
.name_count
,
5348 objfile_name (per_objfile
->objfile
));
5354 const uint32_t namei_full_hash
5355 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5356 (map
.hash_table_reordered
+ namei
), 4,
5357 map
.dwarf5_byte_order
);
5358 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5361 if (full_hash
== namei_full_hash
)
5363 const char *const namei_string
= map
.namei_to_name (namei
, per_objfile
);
5365 #if 0 /* An expensive sanity check. */
5366 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5368 complaint (_("Wrong .debug_names hash for string at index %u "
5370 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5375 if (cmp (namei_string
, name
) == 0)
5377 const ULONGEST namei_entry_offs
5378 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5379 + namei
* map
.offset_size
),
5380 map
.offset_size
, map
.dwarf5_byte_order
);
5381 return map
.entry_pool
+ namei_entry_offs
;
5386 if (namei
>= map
.name_count
)
5392 dw2_debug_names_iterator::find_vec_in_debug_names
5393 (const mapped_debug_names
&map
, uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5395 if (namei
>= map
.name_count
)
5397 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5399 namei
, map
.name_count
,
5400 objfile_name (per_objfile
->objfile
));
5404 const ULONGEST namei_entry_offs
5405 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5406 + namei
* map
.offset_size
),
5407 map
.offset_size
, map
.dwarf5_byte_order
);
5408 return map
.entry_pool
+ namei_entry_offs
;
5411 /* See dw2_debug_names_iterator. */
5413 dwarf2_per_cu_data
*
5414 dw2_debug_names_iterator::next ()
5419 dwarf2_per_bfd
*per_bfd
= m_per_objfile
->per_bfd
;
5420 struct objfile
*objfile
= m_per_objfile
->objfile
;
5421 bfd
*const abfd
= objfile
->obfd
;
5425 unsigned int bytes_read
;
5426 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5427 m_addr
+= bytes_read
;
5431 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5432 if (indexval_it
== m_map
.abbrev_map
.cend ())
5434 complaint (_("Wrong .debug_names undefined abbrev code %s "
5436 pulongest (abbrev
), objfile_name (objfile
));
5439 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5440 enum class symbol_linkage
{
5444 } symbol_linkage_
= symbol_linkage::unknown
;
5445 dwarf2_per_cu_data
*per_cu
= NULL
;
5446 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5451 case DW_FORM_implicit_const
:
5452 ull
= attr
.implicit_const
;
5454 case DW_FORM_flag_present
:
5458 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5459 m_addr
+= bytes_read
;
5462 ull
= read_4_bytes (abfd
, m_addr
);
5466 ull
= read_8_bytes (abfd
, m_addr
);
5469 case DW_FORM_ref_sig8
:
5470 ull
= read_8_bytes (abfd
, m_addr
);
5474 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5475 dwarf_form_name (attr
.form
),
5476 objfile_name (objfile
));
5479 switch (attr
.dw_idx
)
5481 case DW_IDX_compile_unit
:
5482 /* Don't crash on bad data. */
5483 if (ull
>= m_per_objfile
->per_bfd
->all_comp_units
.size ())
5485 complaint (_(".debug_names entry has bad CU index %s"
5488 objfile_name (objfile
));
5491 per_cu
= per_bfd
->get_cutu (ull
);
5493 case DW_IDX_type_unit
:
5494 /* Don't crash on bad data. */
5495 if (ull
>= per_bfd
->all_type_units
.size ())
5497 complaint (_(".debug_names entry has bad TU index %s"
5500 objfile_name (objfile
));
5503 per_cu
= &per_bfd
->get_tu (ull
)->per_cu
;
5505 case DW_IDX_die_offset
:
5506 /* In a per-CU index (as opposed to a per-module index), index
5507 entries without CU attribute implicitly refer to the single CU. */
5509 per_cu
= per_bfd
->get_cu (0);
5511 case DW_IDX_GNU_internal
:
5512 if (!m_map
.augmentation_is_gdb
)
5514 symbol_linkage_
= symbol_linkage::static_
;
5516 case DW_IDX_GNU_external
:
5517 if (!m_map
.augmentation_is_gdb
)
5519 symbol_linkage_
= symbol_linkage::extern_
;
5524 /* Skip if already read in. */
5525 if (m_per_objfile
->symtab_set_p (per_cu
))
5528 /* Check static vs global. */
5529 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5531 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5532 const bool symbol_is_static
=
5533 symbol_linkage_
== symbol_linkage::static_
;
5534 if (want_static
!= symbol_is_static
)
5538 /* Match dw2_symtab_iter_next, symbol_kind
5539 and debug_names::psymbol_tag. */
5543 switch (indexval
.dwarf_tag
)
5545 case DW_TAG_variable
:
5546 case DW_TAG_subprogram
:
5547 /* Some types are also in VAR_DOMAIN. */
5548 case DW_TAG_typedef
:
5549 case DW_TAG_structure_type
:
5556 switch (indexval
.dwarf_tag
)
5558 case DW_TAG_typedef
:
5559 case DW_TAG_structure_type
:
5566 switch (indexval
.dwarf_tag
)
5569 case DW_TAG_variable
:
5576 switch (indexval
.dwarf_tag
)
5588 /* Match dw2_expand_symtabs_matching, symbol_kind and
5589 debug_names::psymbol_tag. */
5592 case VARIABLES_DOMAIN
:
5593 switch (indexval
.dwarf_tag
)
5595 case DW_TAG_variable
:
5601 case FUNCTIONS_DOMAIN
:
5602 switch (indexval
.dwarf_tag
)
5604 case DW_TAG_subprogram
:
5611 switch (indexval
.dwarf_tag
)
5613 case DW_TAG_typedef
:
5614 case DW_TAG_structure_type
:
5620 case MODULES_DOMAIN
:
5621 switch (indexval
.dwarf_tag
)
5635 static struct compunit_symtab
*
5636 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
5637 const char *name
, domain_enum domain
)
5639 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5641 const auto &mapp
= per_objfile
->per_bfd
->debug_names_table
;
5644 /* index is NULL if OBJF_READNOW. */
5647 const auto &map
= *mapp
;
5649 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
, per_objfile
);
5651 struct compunit_symtab
*stab_best
= NULL
;
5652 struct dwarf2_per_cu_data
*per_cu
;
5653 while ((per_cu
= iter
.next ()) != NULL
)
5655 struct symbol
*sym
, *with_opaque
= NULL
;
5656 compunit_symtab
*stab
5657 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
5658 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
5659 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
5661 sym
= block_find_symbol (block
, name
, domain
,
5662 block_find_non_opaque_type_preferred
,
5665 /* Some caution must be observed with overloaded functions and
5666 methods, since the index will not contain any overload
5667 information (but NAME might contain it). */
5670 && strcmp_iw (sym
->search_name (), name
) == 0)
5672 if (with_opaque
!= NULL
5673 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
5676 /* Keep looking through other CUs. */
5682 /* This dumps minimal information about .debug_names. It is called
5683 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5684 uses this to verify that .debug_names has been loaded. */
5687 dw2_debug_names_dump (struct objfile
*objfile
)
5689 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5691 gdb_assert (per_objfile
->per_bfd
->using_index
);
5692 printf_filtered (".debug_names:");
5693 if (per_objfile
->per_bfd
->debug_names_table
)
5694 printf_filtered (" exists\n");
5696 printf_filtered (" faked for \"readnow\"\n");
5697 printf_filtered ("\n");
5701 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
5702 const char *func_name
)
5704 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5706 /* per_objfile->per_bfd->debug_names_table is NULL if OBJF_READNOW. */
5707 if (per_objfile
->per_bfd
->debug_names_table
)
5709 const mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5711 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
,
5714 struct dwarf2_per_cu_data
*per_cu
;
5715 while ((per_cu
= iter
.next ()) != NULL
)
5716 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
5721 dw2_debug_names_map_matching_symbols
5722 (struct objfile
*objfile
,
5723 const lookup_name_info
&name
, domain_enum domain
,
5725 gdb::function_view
<symbol_found_callback_ftype
> callback
,
5726 symbol_compare_ftype
*ordered_compare
)
5728 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5730 /* debug_names_table is NULL if OBJF_READNOW. */
5731 if (!per_objfile
->per_bfd
->debug_names_table
)
5734 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5735 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
5737 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5738 auto matcher
= [&] (const char *symname
)
5740 if (ordered_compare
== nullptr)
5742 return ordered_compare (symname
, match_name
) == 0;
5745 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
5746 [&] (offset_type namei
)
5748 /* The name was matched, now expand corresponding CUs that were
5750 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
,
5753 struct dwarf2_per_cu_data
*per_cu
;
5754 while ((per_cu
= iter
.next ()) != NULL
)
5755 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
5760 /* It's a shame we couldn't do this inside the
5761 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
5762 that have already been expanded. Instead, this loop matches what
5763 the psymtab code does. */
5764 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
5766 compunit_symtab
*symtab
= per_objfile
->get_symtab (per_cu
);
5767 if (symtab
!= nullptr)
5769 const struct block
*block
5770 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (symtab
), block_kind
);
5771 if (!iterate_over_symbols_terminated (block
, name
,
5779 dw2_debug_names_expand_symtabs_matching
5780 (struct objfile
*objfile
,
5781 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5782 const lookup_name_info
*lookup_name
,
5783 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5784 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5785 enum search_domain kind
)
5787 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5789 /* debug_names_table is NULL if OBJF_READNOW. */
5790 if (!per_objfile
->per_bfd
->debug_names_table
)
5793 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
5795 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
5797 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
5801 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
5807 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5809 dw2_expand_symtabs_matching_symbol (map
, *lookup_name
,
5811 kind
, [&] (offset_type namei
)
5813 /* The name was matched, now expand corresponding CUs that were
5815 dw2_debug_names_iterator
iter (map
, kind
, namei
, per_objfile
);
5817 struct dwarf2_per_cu_data
*per_cu
;
5818 while ((per_cu
= iter
.next ()) != NULL
)
5819 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
5825 const struct quick_symbol_functions dwarf2_debug_names_functions
=
5828 dw2_find_last_source_symtab
,
5829 dw2_forget_cached_source_info
,
5830 dw2_map_symtabs_matching_filename
,
5831 dw2_debug_names_lookup_symbol
,
5834 dw2_debug_names_dump
,
5835 dw2_debug_names_expand_symtabs_for_function
,
5836 dw2_expand_all_symtabs
,
5837 dw2_expand_symtabs_with_fullname
,
5838 dw2_debug_names_map_matching_symbols
,
5839 dw2_debug_names_expand_symtabs_matching
,
5840 dw2_find_pc_sect_compunit_symtab
,
5842 dw2_map_symbol_filenames
5845 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5846 to either a dwarf2_per_bfd or dwz_file object. */
5848 template <typename T
>
5849 static gdb::array_view
<const gdb_byte
>
5850 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5852 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5854 if (section
->empty ())
5857 /* Older elfutils strip versions could keep the section in the main
5858 executable while splitting it for the separate debug info file. */
5859 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5862 section
->read (obj
);
5864 /* dwarf2_section_info::size is a bfd_size_type, while
5865 gdb::array_view works with size_t. On 32-bit hosts, with
5866 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5867 is 32-bit. So we need an explicit narrowing conversion here.
5868 This is fine, because it's impossible to allocate or mmap an
5869 array/buffer larger than what size_t can represent. */
5870 return gdb::make_array_view (section
->buffer
, section
->size
);
5873 /* Lookup the index cache for the contents of the index associated to
5876 static gdb::array_view
<const gdb_byte
>
5877 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_bfd
*dwarf2_per_bfd
)
5879 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5880 if (build_id
== nullptr)
5883 return global_index_cache
.lookup_gdb_index (build_id
,
5884 &dwarf2_per_bfd
->index_cache_res
);
5887 /* Same as the above, but for DWZ. */
5889 static gdb::array_view
<const gdb_byte
>
5890 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5892 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5893 if (build_id
== nullptr)
5896 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5899 /* See symfile.h. */
5902 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
5904 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5905 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5907 dwarf_read_debug_printf ("called");
5909 /* If we're about to read full symbols, don't bother with the
5910 indices. In this case we also don't care if some other debug
5911 format is making psymtabs, because they are all about to be
5913 if ((objfile
->flags
& OBJF_READNOW
))
5915 dwarf_read_debug_printf ("readnow requested");
5917 /* When using READNOW, the using_index flag (set below) indicates that
5918 PER_BFD was already initialized, when we loaded some other objfile. */
5919 if (per_bfd
->using_index
)
5921 dwarf_read_debug_printf ("using_index already set");
5922 *index_kind
= dw_index_kind::GDB_INDEX
;
5923 per_objfile
->resize_symtabs ();
5927 per_bfd
->using_index
= 1;
5928 create_all_comp_units (per_objfile
);
5929 create_all_type_units (per_objfile
);
5930 per_bfd
->quick_file_names_table
5931 = create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
5932 per_objfile
->resize_symtabs ();
5934 for (int i
= 0; i
< (per_bfd
->all_comp_units
.size ()
5935 + per_bfd
->all_type_units
.size ()); ++i
)
5937 dwarf2_per_cu_data
*per_cu
= per_bfd
->get_cutu (i
);
5939 per_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
5940 struct dwarf2_per_cu_quick_data
);
5943 /* Return 1 so that gdb sees the "quick" functions. However,
5944 these functions will be no-ops because we will have expanded
5946 *index_kind
= dw_index_kind::GDB_INDEX
;
5950 /* Was a debug names index already read when we processed an objfile sharing
5952 if (per_bfd
->debug_names_table
!= nullptr)
5954 dwarf_read_debug_printf ("re-using shared debug names table");
5955 *index_kind
= dw_index_kind::DEBUG_NAMES
;
5956 per_objfile
->objfile
->partial_symtabs
= per_bfd
->partial_symtabs
;
5957 per_objfile
->resize_symtabs ();
5961 /* Was a GDB index already read when we processed an objfile sharing
5963 if (per_bfd
->index_table
!= nullptr)
5965 dwarf_read_debug_printf ("re-using shared index table");
5966 *index_kind
= dw_index_kind::GDB_INDEX
;
5967 per_objfile
->objfile
->partial_symtabs
= per_bfd
->partial_symtabs
;
5968 per_objfile
->resize_symtabs ();
5972 /* There might already be partial symtabs built for this BFD. This happens
5973 when loading the same binary twice with the index-cache enabled. If so,
5974 don't try to read an index. The objfile / per_objfile initialization will
5975 be completed in dwarf2_build_psymtabs, in the standard partial symtabs
5977 if (per_bfd
->partial_symtabs
!= nullptr)
5979 dwarf_read_debug_printf ("re-using shared partial symtabs");
5983 if (dwarf2_read_debug_names (per_objfile
))
5985 dwarf_read_debug_printf ("found debug names");
5986 *index_kind
= dw_index_kind::DEBUG_NAMES
;
5987 per_objfile
->resize_symtabs ();
5991 if (dwarf2_read_gdb_index (per_objfile
,
5992 get_gdb_index_contents_from_section
<struct dwarf2_per_bfd
>,
5993 get_gdb_index_contents_from_section
<dwz_file
>))
5995 dwarf_read_debug_printf ("found gdb index from file");
5996 *index_kind
= dw_index_kind::GDB_INDEX
;
5997 per_objfile
->resize_symtabs ();
6001 /* ... otherwise, try to find the index in the index cache. */
6002 if (dwarf2_read_gdb_index (per_objfile
,
6003 get_gdb_index_contents_from_cache
,
6004 get_gdb_index_contents_from_cache_dwz
))
6006 dwarf_read_debug_printf ("found gdb index from cache");
6007 global_index_cache
.hit ();
6008 *index_kind
= dw_index_kind::GDB_INDEX
;
6009 per_objfile
->resize_symtabs ();
6013 global_index_cache
.miss ();
6019 /* Build a partial symbol table. */
6022 dwarf2_build_psymtabs (struct objfile
*objfile
)
6024 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
6025 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6027 if (per_bfd
->partial_symtabs
!= nullptr)
6029 /* Partial symbols were already read, so now we can simply
6031 objfile
->partial_symtabs
= per_bfd
->partial_symtabs
;
6032 per_objfile
->resize_symtabs ();
6038 /* This isn't really ideal: all the data we allocate on the
6039 objfile's obstack is still uselessly kept around. However,
6040 freeing it seems unsafe. */
6041 psymtab_discarder
psymtabs (objfile
);
6042 dwarf2_build_psymtabs_hard (per_objfile
);
6045 per_objfile
->resize_symtabs ();
6047 /* (maybe) store an index in the cache. */
6048 global_index_cache
.store (per_objfile
);
6050 catch (const gdb_exception_error
&except
)
6052 exception_print (gdb_stderr
, except
);
6055 /* Finish by setting the local reference to partial symtabs, so that
6056 we don't try to read them again if reading another objfile with the same
6057 BFD. If we can't in fact share, this won't make a difference anyway as
6058 the dwarf2_per_bfd object won't be shared. */
6059 per_bfd
->partial_symtabs
= objfile
->partial_symtabs
;
6062 /* Find the base address of the compilation unit for range lists and
6063 location lists. It will normally be specified by DW_AT_low_pc.
6064 In DWARF-3 draft 4, the base address could be overridden by
6065 DW_AT_entry_pc. It's been removed, but GCC still uses this for
6066 compilation units with discontinuous ranges. */
6069 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
6071 struct attribute
*attr
;
6073 cu
->base_address
.reset ();
6075 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
6076 if (attr
!= nullptr)
6077 cu
->base_address
= attr
->as_address ();
6080 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6081 if (attr
!= nullptr)
6082 cu
->base_address
= attr
->as_address ();
6086 /* Helper function that returns the proper abbrev section for
6089 static struct dwarf2_section_info
*
6090 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
6092 struct dwarf2_section_info
*abbrev
;
6093 dwarf2_per_bfd
*per_bfd
= this_cu
->per_bfd
;
6095 if (this_cu
->is_dwz
)
6096 abbrev
= &dwarf2_get_dwz_file (per_bfd
, true)->abbrev
;
6098 abbrev
= &per_bfd
->abbrev
;
6103 /* Fetch the abbreviation table offset from a comp or type unit header. */
6106 read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
6107 struct dwarf2_section_info
*section
,
6108 sect_offset sect_off
)
6110 bfd
*abfd
= section
->get_bfd_owner ();
6111 const gdb_byte
*info_ptr
;
6112 unsigned int initial_length_size
, offset_size
;
6115 section
->read (per_objfile
->objfile
);
6116 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
6117 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6118 offset_size
= initial_length_size
== 4 ? 4 : 8;
6119 info_ptr
+= initial_length_size
;
6121 version
= read_2_bytes (abfd
, info_ptr
);
6125 /* Skip unit type and address size. */
6129 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
6132 /* A partial symtab that is used only for include files. */
6133 struct dwarf2_include_psymtab
: public partial_symtab
6135 dwarf2_include_psymtab (const char *filename
, struct objfile
*objfile
)
6136 : partial_symtab (filename
, objfile
)
6140 void read_symtab (struct objfile
*objfile
) override
6142 /* It's an include file, no symbols to read for it.
6143 Everything is in the includer symtab. */
6145 /* The expansion of a dwarf2_include_psymtab is just a trigger for
6146 expansion of the includer psymtab. We use the dependencies[0] field to
6147 model the includer. But if we go the regular route of calling
6148 expand_psymtab here, and having expand_psymtab call expand_dependencies
6149 to expand the includer, we'll only use expand_psymtab on the includer
6150 (making it a non-toplevel psymtab), while if we expand the includer via
6151 another path, we'll use read_symtab (making it a toplevel psymtab).
6152 So, don't pretend a dwarf2_include_psymtab is an actual toplevel
6153 psymtab, and trigger read_symtab on the includer here directly. */
6154 includer ()->read_symtab (objfile
);
6157 void expand_psymtab (struct objfile
*objfile
) override
6159 /* This is not called by read_symtab, and should not be called by any
6160 expand_dependencies. */
6164 bool readin_p (struct objfile
*objfile
) const override
6166 return includer ()->readin_p (objfile
);
6169 compunit_symtab
*get_compunit_symtab (struct objfile
*objfile
) const override
6175 partial_symtab
*includer () const
6177 /* An include psymtab has exactly one dependency: the psymtab that
6179 gdb_assert (this->number_of_dependencies
== 1);
6180 return this->dependencies
[0];
6184 /* Allocate a new partial symtab for file named NAME and mark this new
6185 partial symtab as being an include of PST. */
6188 dwarf2_create_include_psymtab (const char *name
, dwarf2_psymtab
*pst
,
6189 struct objfile
*objfile
)
6191 dwarf2_include_psymtab
*subpst
= new dwarf2_include_psymtab (name
, objfile
);
6193 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6194 subpst
->dirname
= pst
->dirname
;
6196 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
6197 subpst
->dependencies
[0] = pst
;
6198 subpst
->number_of_dependencies
= 1;
6201 /* Read the Line Number Program data and extract the list of files
6202 included by the source file represented by PST. Build an include
6203 partial symtab for each of these included files. */
6206 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
6207 struct die_info
*die
,
6208 dwarf2_psymtab
*pst
)
6211 struct attribute
*attr
;
6213 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6214 if (attr
!= nullptr && attr
->form_is_unsigned ())
6215 lh
= dwarf_decode_line_header ((sect_offset
) attr
->as_unsigned (), cu
);
6217 return; /* No linetable, so no includes. */
6219 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
6220 that we pass in the raw text_low here; that is ok because we're
6221 only decoding the line table to make include partial symtabs, and
6222 so the addresses aren't really used. */
6223 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
6224 pst
->raw_text_low (), 1);
6228 hash_signatured_type (const void *item
)
6230 const struct signatured_type
*sig_type
6231 = (const struct signatured_type
*) item
;
6233 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6234 return sig_type
->signature
;
6238 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6240 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6241 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6243 return lhs
->signature
== rhs
->signature
;
6246 /* Allocate a hash table for signatured types. */
6249 allocate_signatured_type_table ()
6251 return htab_up (htab_create_alloc (41,
6252 hash_signatured_type
,
6254 NULL
, xcalloc
, xfree
));
6257 /* A helper function to add a signatured type CU to a table. */
6260 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6262 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6263 std::vector
<signatured_type
*> *all_type_units
6264 = (std::vector
<signatured_type
*> *) datum
;
6266 all_type_units
->push_back (sigt
);
6271 /* A helper for create_debug_types_hash_table. Read types from SECTION
6272 and fill them into TYPES_HTAB. It will process only type units,
6273 therefore DW_UT_type. */
6276 create_debug_type_hash_table (dwarf2_per_objfile
*per_objfile
,
6277 struct dwo_file
*dwo_file
,
6278 dwarf2_section_info
*section
, htab_up
&types_htab
,
6279 rcuh_kind section_kind
)
6281 struct objfile
*objfile
= per_objfile
->objfile
;
6282 struct dwarf2_section_info
*abbrev_section
;
6284 const gdb_byte
*info_ptr
, *end_ptr
;
6286 abbrev_section
= (dwo_file
!= NULL
6287 ? &dwo_file
->sections
.abbrev
6288 : &per_objfile
->per_bfd
->abbrev
);
6290 dwarf_read_debug_printf ("Reading %s for %s",
6291 section
->get_name (),
6292 abbrev_section
->get_file_name ());
6294 section
->read (objfile
);
6295 info_ptr
= section
->buffer
;
6297 if (info_ptr
== NULL
)
6300 /* We can't set abfd until now because the section may be empty or
6301 not present, in which case the bfd is unknown. */
6302 abfd
= section
->get_bfd_owner ();
6304 /* We don't use cutu_reader here because we don't need to read
6305 any dies: the signature is in the header. */
6307 end_ptr
= info_ptr
+ section
->size
;
6308 while (info_ptr
< end_ptr
)
6310 struct signatured_type
*sig_type
;
6311 struct dwo_unit
*dwo_tu
;
6313 const gdb_byte
*ptr
= info_ptr
;
6314 struct comp_unit_head header
;
6315 unsigned int length
;
6317 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6319 /* Initialize it due to a false compiler warning. */
6320 header
.signature
= -1;
6321 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6323 /* We need to read the type's signature in order to build the hash
6324 table, but we don't need anything else just yet. */
6326 ptr
= read_and_check_comp_unit_head (per_objfile
, &header
, section
,
6327 abbrev_section
, ptr
, section_kind
);
6329 length
= header
.get_length ();
6331 /* Skip dummy type units. */
6332 if (ptr
>= info_ptr
+ length
6333 || peek_abbrev_code (abfd
, ptr
) == 0
6334 || (header
.unit_type
!= DW_UT_type
6335 && header
.unit_type
!= DW_UT_split_type
))
6341 if (types_htab
== NULL
)
6344 types_htab
= allocate_dwo_unit_table ();
6346 types_htab
= allocate_signatured_type_table ();
6352 dwo_tu
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, dwo_unit
);
6353 dwo_tu
->dwo_file
= dwo_file
;
6354 dwo_tu
->signature
= header
.signature
;
6355 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6356 dwo_tu
->section
= section
;
6357 dwo_tu
->sect_off
= sect_off
;
6358 dwo_tu
->length
= length
;
6362 /* N.B.: type_offset is not usable if this type uses a DWO file.
6363 The real type_offset is in the DWO file. */
6365 sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
6366 sig_type
->signature
= header
.signature
;
6367 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6368 sig_type
->per_cu
.is_debug_types
= 1;
6369 sig_type
->per_cu
.section
= section
;
6370 sig_type
->per_cu
.sect_off
= sect_off
;
6371 sig_type
->per_cu
.length
= length
;
6374 slot
= htab_find_slot (types_htab
.get (),
6375 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6377 gdb_assert (slot
!= NULL
);
6380 sect_offset dup_sect_off
;
6384 const struct dwo_unit
*dup_tu
6385 = (const struct dwo_unit
*) *slot
;
6387 dup_sect_off
= dup_tu
->sect_off
;
6391 const struct signatured_type
*dup_tu
6392 = (const struct signatured_type
*) *slot
;
6394 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6397 complaint (_("debug type entry at offset %s is duplicate to"
6398 " the entry at offset %s, signature %s"),
6399 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6400 hex_string (header
.signature
));
6402 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6404 dwarf_read_debug_printf_v (" offset %s, signature %s",
6405 sect_offset_str (sect_off
),
6406 hex_string (header
.signature
));
6412 /* Create the hash table of all entries in the .debug_types
6413 (or .debug_types.dwo) section(s).
6414 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6415 otherwise it is NULL.
6417 The result is a pointer to the hash table or NULL if there are no types.
6419 Note: This function processes DWO files only, not DWP files. */
6422 create_debug_types_hash_table (dwarf2_per_objfile
*per_objfile
,
6423 struct dwo_file
*dwo_file
,
6424 gdb::array_view
<dwarf2_section_info
> type_sections
,
6425 htab_up
&types_htab
)
6427 for (dwarf2_section_info
§ion
: type_sections
)
6428 create_debug_type_hash_table (per_objfile
, dwo_file
, §ion
, types_htab
,
6432 /* Create the hash table of all entries in the .debug_types section,
6433 and initialize all_type_units.
6434 The result is zero if there is an error (e.g. missing .debug_types section),
6435 otherwise non-zero. */
6438 create_all_type_units (dwarf2_per_objfile
*per_objfile
)
6442 create_debug_type_hash_table (per_objfile
, NULL
, &per_objfile
->per_bfd
->info
,
6443 types_htab
, rcuh_kind::COMPILE
);
6444 create_debug_types_hash_table (per_objfile
, NULL
, per_objfile
->per_bfd
->types
,
6446 if (types_htab
== NULL
)
6448 per_objfile
->per_bfd
->signatured_types
= NULL
;
6452 per_objfile
->per_bfd
->signatured_types
= std::move (types_htab
);
6454 gdb_assert (per_objfile
->per_bfd
->all_type_units
.empty ());
6455 per_objfile
->per_bfd
->all_type_units
.reserve
6456 (htab_elements (per_objfile
->per_bfd
->signatured_types
.get ()));
6458 htab_traverse_noresize (per_objfile
->per_bfd
->signatured_types
.get (),
6459 add_signatured_type_cu_to_table
,
6460 &per_objfile
->per_bfd
->all_type_units
);
6465 /* Add an entry for signature SIG to dwarf2_per_objfile->per_bfd->signatured_types.
6466 If SLOT is non-NULL, it is the entry to use in the hash table.
6467 Otherwise we find one. */
6469 static struct signatured_type
*
6470 add_type_unit (dwarf2_per_objfile
*per_objfile
, ULONGEST sig
, void **slot
)
6472 if (per_objfile
->per_bfd
->all_type_units
.size ()
6473 == per_objfile
->per_bfd
->all_type_units
.capacity ())
6474 ++per_objfile
->per_bfd
->tu_stats
.nr_all_type_units_reallocs
;
6476 signatured_type
*sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
6478 per_objfile
->resize_symtabs ();
6480 per_objfile
->per_bfd
->all_type_units
.push_back (sig_type
);
6481 sig_type
->signature
= sig
;
6482 sig_type
->per_cu
.is_debug_types
= 1;
6483 if (per_objfile
->per_bfd
->using_index
)
6485 sig_type
->per_cu
.v
.quick
=
6486 OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
6487 struct dwarf2_per_cu_quick_data
);
6492 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6495 gdb_assert (*slot
== NULL
);
6497 /* The rest of sig_type must be filled in by the caller. */
6501 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6502 Fill in SIG_ENTRY with DWO_ENTRY. */
6505 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
*per_objfile
,
6506 struct signatured_type
*sig_entry
,
6507 struct dwo_unit
*dwo_entry
)
6509 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6511 /* Make sure we're not clobbering something we don't expect to. */
6512 gdb_assert (! sig_entry
->per_cu
.queued
);
6513 gdb_assert (per_objfile
->get_cu (&sig_entry
->per_cu
) == NULL
);
6514 if (per_bfd
->using_index
)
6516 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6517 gdb_assert (!per_objfile
->symtab_set_p (&sig_entry
->per_cu
));
6520 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6521 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6522 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6523 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6524 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6526 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6527 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6528 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6529 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6530 sig_entry
->per_cu
.per_bfd
= per_bfd
;
6531 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6532 sig_entry
->dwo_unit
= dwo_entry
;
6535 /* Subroutine of lookup_signatured_type.
6536 If we haven't read the TU yet, create the signatured_type data structure
6537 for a TU to be read in directly from a DWO file, bypassing the stub.
6538 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6539 using .gdb_index, then when reading a CU we want to stay in the DWO file
6540 containing that CU. Otherwise we could end up reading several other DWO
6541 files (due to comdat folding) to process the transitive closure of all the
6542 mentioned TUs, and that can be slow. The current DWO file will have every
6543 type signature that it needs.
6544 We only do this for .gdb_index because in the psymtab case we already have
6545 to read all the DWOs to build the type unit groups. */
6547 static struct signatured_type
*
6548 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6550 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6551 struct dwo_file
*dwo_file
;
6552 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6553 struct signatured_type find_sig_entry
, *sig_entry
;
6556 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
6558 /* If TU skeletons have been removed then we may not have read in any
6560 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6561 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6563 /* We only ever need to read in one copy of a signatured type.
6564 Use the global signatured_types array to do our own comdat-folding
6565 of types. If this is the first time we're reading this TU, and
6566 the TU has an entry in .gdb_index, replace the recorded data from
6567 .gdb_index with this TU. */
6569 find_sig_entry
.signature
= sig
;
6570 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6571 &find_sig_entry
, INSERT
);
6572 sig_entry
= (struct signatured_type
*) *slot
;
6574 /* We can get here with the TU already read, *or* in the process of being
6575 read. Don't reassign the global entry to point to this DWO if that's
6576 the case. Also note that if the TU is already being read, it may not
6577 have come from a DWO, the program may be a mix of Fission-compiled
6578 code and non-Fission-compiled code. */
6580 /* Have we already tried to read this TU?
6581 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6582 needn't exist in the global table yet). */
6583 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
6586 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6587 dwo_unit of the TU itself. */
6588 dwo_file
= cu
->dwo_unit
->dwo_file
;
6590 /* Ok, this is the first time we're reading this TU. */
6591 if (dwo_file
->tus
== NULL
)
6593 find_dwo_entry
.signature
= sig
;
6594 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6596 if (dwo_entry
== NULL
)
6599 /* If the global table doesn't have an entry for this TU, add one. */
6600 if (sig_entry
== NULL
)
6601 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6603 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6604 sig_entry
->per_cu
.tu_read
= 1;
6608 /* Subroutine of lookup_signatured_type.
6609 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6610 then try the DWP file. If the TU stub (skeleton) has been removed then
6611 it won't be in .gdb_index. */
6613 static struct signatured_type
*
6614 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6616 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6617 struct dwp_file
*dwp_file
= get_dwp_file (per_objfile
);
6618 struct dwo_unit
*dwo_entry
;
6619 struct signatured_type find_sig_entry
, *sig_entry
;
6622 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
6623 gdb_assert (dwp_file
!= NULL
);
6625 /* If TU skeletons have been removed then we may not have read in any
6627 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6628 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6630 find_sig_entry
.signature
= sig
;
6631 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6632 &find_sig_entry
, INSERT
);
6633 sig_entry
= (struct signatured_type
*) *slot
;
6635 /* Have we already tried to read this TU?
6636 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6637 needn't exist in the global table yet). */
6638 if (sig_entry
!= NULL
)
6641 if (dwp_file
->tus
== NULL
)
6643 dwo_entry
= lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, NULL
, sig
,
6644 1 /* is_debug_types */);
6645 if (dwo_entry
== NULL
)
6648 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6649 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6654 /* Lookup a signature based type for DW_FORM_ref_sig8.
6655 Returns NULL if signature SIG is not present in the table.
6656 It is up to the caller to complain about this. */
6658 static struct signatured_type
*
6659 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6661 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6663 if (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
)
6665 /* We're in a DWO/DWP file, and we're using .gdb_index.
6666 These cases require special processing. */
6667 if (get_dwp_file (per_objfile
) == NULL
)
6668 return lookup_dwo_signatured_type (cu
, sig
);
6670 return lookup_dwp_signatured_type (cu
, sig
);
6674 struct signatured_type find_entry
, *entry
;
6676 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6678 find_entry
.signature
= sig
;
6679 entry
= ((struct signatured_type
*)
6680 htab_find (per_objfile
->per_bfd
->signatured_types
.get (),
6686 /* Low level DIE reading support. */
6688 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6691 init_cu_die_reader (struct die_reader_specs
*reader
,
6692 struct dwarf2_cu
*cu
,
6693 struct dwarf2_section_info
*section
,
6694 struct dwo_file
*dwo_file
,
6695 struct abbrev_table
*abbrev_table
)
6697 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6698 reader
->abfd
= section
->get_bfd_owner ();
6700 reader
->dwo_file
= dwo_file
;
6701 reader
->die_section
= section
;
6702 reader
->buffer
= section
->buffer
;
6703 reader
->buffer_end
= section
->buffer
+ section
->size
;
6704 reader
->abbrev_table
= abbrev_table
;
6707 /* Subroutine of cutu_reader to simplify it.
6708 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6709 There's just a lot of work to do, and cutu_reader is big enough
6712 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6713 from it to the DIE in the DWO. If NULL we are skipping the stub.
6714 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6715 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6716 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6717 STUB_COMP_DIR may be non-NULL.
6718 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6719 are filled in with the info of the DIE from the DWO file.
6720 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6721 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6722 kept around for at least as long as *RESULT_READER.
6724 The result is non-zero if a valid (non-dummy) DIE was found. */
6727 read_cutu_die_from_dwo (dwarf2_cu
*cu
,
6728 struct dwo_unit
*dwo_unit
,
6729 struct die_info
*stub_comp_unit_die
,
6730 const char *stub_comp_dir
,
6731 struct die_reader_specs
*result_reader
,
6732 const gdb_byte
**result_info_ptr
,
6733 struct die_info
**result_comp_unit_die
,
6734 abbrev_table_up
*result_dwo_abbrev_table
)
6736 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6737 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6738 struct objfile
*objfile
= per_objfile
->objfile
;
6740 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6741 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6742 int i
,num_extra_attrs
;
6743 struct dwarf2_section_info
*dwo_abbrev_section
;
6744 struct die_info
*comp_unit_die
;
6746 /* At most one of these may be provided. */
6747 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6749 /* These attributes aren't processed until later:
6750 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6751 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6752 referenced later. However, these attributes are found in the stub
6753 which we won't have later. In order to not impose this complication
6754 on the rest of the code, we read them here and copy them to the
6763 if (stub_comp_unit_die
!= NULL
)
6765 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6767 if (!per_cu
->is_debug_types
)
6768 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6769 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6770 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6771 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6772 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6774 cu
->addr_base
= stub_comp_unit_die
->addr_base ();
6776 /* There should be a DW_AT_GNU_ranges_base attribute here (if needed).
6777 We need the value before we can process DW_AT_ranges values from the
6779 cu
->gnu_ranges_base
= stub_comp_unit_die
->gnu_ranges_base ();
6781 /* For DWARF5: record the DW_AT_rnglists_base value from the skeleton. If
6782 there are attributes of form DW_FORM_rnglistx in the skeleton, they'll
6783 need the rnglists base. Attributes of form DW_FORM_rnglistx in the
6784 split unit don't use it, as the DWO has its own .debug_rnglists.dwo
6786 cu
->rnglists_base
= stub_comp_unit_die
->rnglists_base ();
6788 else if (stub_comp_dir
!= NULL
)
6790 /* Reconstruct the comp_dir attribute to simplify the code below. */
6791 comp_dir
= OBSTACK_ZALLOC (&cu
->comp_unit_obstack
, struct attribute
);
6792 comp_dir
->name
= DW_AT_comp_dir
;
6793 comp_dir
->form
= DW_FORM_string
;
6794 comp_dir
->set_string_noncanonical (stub_comp_dir
);
6797 /* Set up for reading the DWO CU/TU. */
6798 cu
->dwo_unit
= dwo_unit
;
6799 dwarf2_section_info
*section
= dwo_unit
->section
;
6800 section
->read (objfile
);
6801 abfd
= section
->get_bfd_owner ();
6802 begin_info_ptr
= info_ptr
= (section
->buffer
6803 + to_underlying (dwo_unit
->sect_off
));
6804 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6806 if (per_cu
->is_debug_types
)
6808 signatured_type
*sig_type
= (struct signatured_type
*) per_cu
;
6810 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6811 section
, dwo_abbrev_section
,
6812 info_ptr
, rcuh_kind::TYPE
);
6813 /* This is not an assert because it can be caused by bad debug info. */
6814 if (sig_type
->signature
!= cu
->header
.signature
)
6816 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6817 " TU at offset %s [in module %s]"),
6818 hex_string (sig_type
->signature
),
6819 hex_string (cu
->header
.signature
),
6820 sect_offset_str (dwo_unit
->sect_off
),
6821 bfd_get_filename (abfd
));
6823 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6824 /* For DWOs coming from DWP files, we don't know the CU length
6825 nor the type's offset in the TU until now. */
6826 dwo_unit
->length
= cu
->header
.get_length ();
6827 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6829 /* Establish the type offset that can be used to lookup the type.
6830 For DWO files, we don't know it until now. */
6831 sig_type
->type_offset_in_section
6832 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6836 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6837 section
, dwo_abbrev_section
,
6838 info_ptr
, rcuh_kind::COMPILE
);
6839 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6840 /* For DWOs coming from DWP files, we don't know the CU length
6842 dwo_unit
->length
= cu
->header
.get_length ();
6845 dwo_abbrev_section
->read (objfile
);
6846 *result_dwo_abbrev_table
6847 = abbrev_table::read (dwo_abbrev_section
, cu
->header
.abbrev_sect_off
);
6848 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6849 result_dwo_abbrev_table
->get ());
6851 /* Read in the die, but leave space to copy over the attributes
6852 from the stub. This has the benefit of simplifying the rest of
6853 the code - all the work to maintain the illusion of a single
6854 DW_TAG_{compile,type}_unit DIE is done here. */
6855 num_extra_attrs
= ((stmt_list
!= NULL
)
6859 + (comp_dir
!= NULL
));
6860 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6863 /* Copy over the attributes from the stub to the DIE we just read in. */
6864 comp_unit_die
= *result_comp_unit_die
;
6865 i
= comp_unit_die
->num_attrs
;
6866 if (stmt_list
!= NULL
)
6867 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6869 comp_unit_die
->attrs
[i
++] = *low_pc
;
6870 if (high_pc
!= NULL
)
6871 comp_unit_die
->attrs
[i
++] = *high_pc
;
6873 comp_unit_die
->attrs
[i
++] = *ranges
;
6874 if (comp_dir
!= NULL
)
6875 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6876 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6878 if (dwarf_die_debug
)
6880 fprintf_unfiltered (gdb_stdlog
,
6881 "Read die from %s@0x%x of %s:\n",
6882 section
->get_name (),
6883 (unsigned) (begin_info_ptr
- section
->buffer
),
6884 bfd_get_filename (abfd
));
6885 dump_die (comp_unit_die
, dwarf_die_debug
);
6888 /* Skip dummy compilation units. */
6889 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6890 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6893 *result_info_ptr
= info_ptr
;
6897 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
6898 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
6899 signature is part of the header. */
6900 static gdb::optional
<ULONGEST
>
6901 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
6903 if (cu
->header
.version
>= 5)
6904 return cu
->header
.signature
;
6905 struct attribute
*attr
;
6906 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6907 if (attr
== nullptr || !attr
->form_is_unsigned ())
6908 return gdb::optional
<ULONGEST
> ();
6909 return attr
->as_unsigned ();
6912 /* Subroutine of cutu_reader to simplify it.
6913 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6914 Returns NULL if the specified DWO unit cannot be found. */
6916 static struct dwo_unit
*
6917 lookup_dwo_unit (dwarf2_cu
*cu
, die_info
*comp_unit_die
, const char *dwo_name
)
6919 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6920 struct dwo_unit
*dwo_unit
;
6921 const char *comp_dir
;
6923 gdb_assert (cu
!= NULL
);
6925 /* Yeah, we look dwo_name up again, but it simplifies the code. */
6926 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6927 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6929 if (per_cu
->is_debug_types
)
6930 dwo_unit
= lookup_dwo_type_unit (cu
, dwo_name
, comp_dir
);
6933 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
6935 if (!signature
.has_value ())
6936 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
6938 dwo_name
, bfd_get_filename (per_cu
->per_bfd
->obfd
));
6940 dwo_unit
= lookup_dwo_comp_unit (cu
, dwo_name
, comp_dir
, *signature
);
6946 /* Subroutine of cutu_reader to simplify it.
6947 See it for a description of the parameters.
6948 Read a TU directly from a DWO file, bypassing the stub. */
6951 cutu_reader::init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
6952 dwarf2_per_objfile
*per_objfile
,
6953 dwarf2_cu
*existing_cu
)
6955 struct signatured_type
*sig_type
;
6957 /* Verify we can do the following downcast, and that we have the
6959 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
6960 sig_type
= (struct signatured_type
*) this_cu
;
6961 gdb_assert (sig_type
->dwo_unit
!= NULL
);
6965 if (existing_cu
!= nullptr)
6968 gdb_assert (cu
->dwo_unit
== sig_type
->dwo_unit
);
6969 /* There's no need to do the rereading_dwo_cu handling that
6970 cutu_reader does since we don't read the stub. */
6974 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
6975 in per_objfile yet. */
6976 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
6977 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
6978 cu
= m_new_cu
.get ();
6981 /* A future optimization, if needed, would be to use an existing
6982 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
6983 could share abbrev tables. */
6985 if (read_cutu_die_from_dwo (cu
, sig_type
->dwo_unit
,
6986 NULL
/* stub_comp_unit_die */,
6987 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
6990 &m_dwo_abbrev_table
) == 0)
6997 /* Initialize a CU (or TU) and read its DIEs.
6998 If the CU defers to a DWO file, read the DWO file as well.
7000 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
7001 Otherwise the table specified in the comp unit header is read in and used.
7002 This is an optimization for when we already have the abbrev table.
7004 If EXISTING_CU is non-NULL, then use it. Otherwise, a new CU is
7007 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
7008 dwarf2_per_objfile
*per_objfile
,
7009 struct abbrev_table
*abbrev_table
,
7010 dwarf2_cu
*existing_cu
,
7012 : die_reader_specs
{},
7015 struct objfile
*objfile
= per_objfile
->objfile
;
7016 struct dwarf2_section_info
*section
= this_cu
->section
;
7017 bfd
*abfd
= section
->get_bfd_owner ();
7018 const gdb_byte
*begin_info_ptr
;
7019 struct signatured_type
*sig_type
= NULL
;
7020 struct dwarf2_section_info
*abbrev_section
;
7021 /* Non-zero if CU currently points to a DWO file and we need to
7022 reread it. When this happens we need to reread the skeleton die
7023 before we can reread the DWO file (this only applies to CUs, not TUs). */
7024 int rereading_dwo_cu
= 0;
7026 if (dwarf_die_debug
)
7027 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7028 this_cu
->is_debug_types
? "type" : "comp",
7029 sect_offset_str (this_cu
->sect_off
));
7031 /* If we're reading a TU directly from a DWO file, including a virtual DWO
7032 file (instead of going through the stub), short-circuit all of this. */
7033 if (this_cu
->reading_dwo_directly
)
7035 /* Narrow down the scope of possibilities to have to understand. */
7036 gdb_assert (this_cu
->is_debug_types
);
7037 gdb_assert (abbrev_table
== NULL
);
7038 init_tu_and_read_dwo_dies (this_cu
, per_objfile
, existing_cu
);
7042 /* This is cheap if the section is already read in. */
7043 section
->read (objfile
);
7045 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7047 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
7051 if (existing_cu
!= nullptr)
7054 /* If this CU is from a DWO file we need to start over, we need to
7055 refetch the attributes from the skeleton CU.
7056 This could be optimized by retrieving those attributes from when we
7057 were here the first time: the previous comp_unit_die was stored in
7058 comp_unit_obstack. But there's no data yet that we need this
7060 if (cu
->dwo_unit
!= NULL
)
7061 rereading_dwo_cu
= 1;
7065 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
7066 in per_objfile yet. */
7067 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
7068 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
7069 cu
= m_new_cu
.get ();
7072 /* Get the header. */
7073 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
7075 /* We already have the header, there's no need to read it in again. */
7076 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
7080 if (this_cu
->is_debug_types
)
7082 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
7083 section
, abbrev_section
,
7084 info_ptr
, rcuh_kind::TYPE
);
7086 /* Since per_cu is the first member of struct signatured_type,
7087 we can go from a pointer to one to a pointer to the other. */
7088 sig_type
= (struct signatured_type
*) this_cu
;
7089 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
7090 gdb_assert (sig_type
->type_offset_in_tu
7091 == cu
->header
.type_cu_offset_in_tu
);
7092 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7094 /* LENGTH has not been set yet for type units if we're
7095 using .gdb_index. */
7096 this_cu
->length
= cu
->header
.get_length ();
7098 /* Establish the type offset that can be used to lookup the type. */
7099 sig_type
->type_offset_in_section
=
7100 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
7102 this_cu
->dwarf_version
= cu
->header
.version
;
7106 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
7107 section
, abbrev_section
,
7109 rcuh_kind::COMPILE
);
7111 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7112 if (this_cu
->length
== 0)
7113 this_cu
->length
= cu
->header
.get_length ();
7115 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
7116 this_cu
->dwarf_version
= cu
->header
.version
;
7120 /* Skip dummy compilation units. */
7121 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7122 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7128 /* If we don't have them yet, read the abbrevs for this compilation unit.
7129 And if we need to read them now, make sure they're freed when we're
7131 if (abbrev_table
!= NULL
)
7132 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
7135 abbrev_section
->read (objfile
);
7136 m_abbrev_table_holder
7137 = abbrev_table::read (abbrev_section
, cu
->header
.abbrev_sect_off
);
7138 abbrev_table
= m_abbrev_table_holder
.get ();
7141 /* Read the top level CU/TU die. */
7142 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
7143 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7145 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
7151 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
7152 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
7153 table from the DWO file and pass the ownership over to us. It will be
7154 referenced from READER, so we must make sure to free it after we're done
7157 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
7158 DWO CU, that this test will fail (the attribute will not be present). */
7159 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7160 if (dwo_name
!= nullptr)
7162 struct dwo_unit
*dwo_unit
;
7163 struct die_info
*dwo_comp_unit_die
;
7165 if (comp_unit_die
->has_children
)
7167 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
7168 " has children (offset %s) [in module %s]"),
7169 sect_offset_str (this_cu
->sect_off
),
7170 bfd_get_filename (abfd
));
7172 dwo_unit
= lookup_dwo_unit (cu
, comp_unit_die
, dwo_name
);
7173 if (dwo_unit
!= NULL
)
7175 if (read_cutu_die_from_dwo (cu
, dwo_unit
,
7176 comp_unit_die
, NULL
,
7179 &m_dwo_abbrev_table
) == 0)
7185 comp_unit_die
= dwo_comp_unit_die
;
7189 /* Yikes, we couldn't find the rest of the DIE, we only have
7190 the stub. A complaint has already been logged. There's
7191 not much more we can do except pass on the stub DIE to
7192 die_reader_func. We don't want to throw an error on bad
7199 cutu_reader::keep ()
7201 /* Done, clean up. */
7202 gdb_assert (!dummy_p
);
7203 if (m_new_cu
!= NULL
)
7205 /* Save this dwarf2_cu in the per_objfile. The per_objfile owns it
7207 dwarf2_per_objfile
*per_objfile
= m_new_cu
->per_objfile
;
7208 per_objfile
->set_cu (m_this_cu
, m_new_cu
.release ());
7212 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
7213 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
7214 assumed to have already done the lookup to find the DWO file).
7216 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7217 THIS_CU->is_debug_types, but nothing else.
7219 We fill in THIS_CU->length.
7221 THIS_CU->cu is always freed when done.
7222 This is done in order to not leave THIS_CU->cu in a state where we have
7223 to care whether it refers to the "main" CU or the DWO CU.
7225 When parent_cu is passed, it is used to provide a default value for
7226 str_offsets_base and addr_base from the parent. */
7228 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
7229 dwarf2_per_objfile
*per_objfile
,
7230 struct dwarf2_cu
*parent_cu
,
7231 struct dwo_file
*dwo_file
)
7232 : die_reader_specs
{},
7235 struct objfile
*objfile
= per_objfile
->objfile
;
7236 struct dwarf2_section_info
*section
= this_cu
->section
;
7237 bfd
*abfd
= section
->get_bfd_owner ();
7238 struct dwarf2_section_info
*abbrev_section
;
7239 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7241 if (dwarf_die_debug
)
7242 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7243 this_cu
->is_debug_types
? "type" : "comp",
7244 sect_offset_str (this_cu
->sect_off
));
7246 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
7248 abbrev_section
= (dwo_file
!= NULL
7249 ? &dwo_file
->sections
.abbrev
7250 : get_abbrev_section_for_cu (this_cu
));
7252 /* This is cheap if the section is already read in. */
7253 section
->read (objfile
);
7255 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
7257 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7258 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &m_new_cu
->header
,
7259 section
, abbrev_section
, info_ptr
,
7260 (this_cu
->is_debug_types
7262 : rcuh_kind::COMPILE
));
7264 if (parent_cu
!= nullptr)
7266 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
7267 m_new_cu
->addr_base
= parent_cu
->addr_base
;
7269 this_cu
->length
= m_new_cu
->header
.get_length ();
7271 /* Skip dummy compilation units. */
7272 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7273 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7279 abbrev_section
->read (objfile
);
7280 m_abbrev_table_holder
7281 = abbrev_table::read (abbrev_section
, m_new_cu
->header
.abbrev_sect_off
);
7283 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
7284 m_abbrev_table_holder
.get ());
7285 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7289 /* Type Unit Groups.
7291 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7292 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7293 so that all types coming from the same compilation (.o file) are grouped
7294 together. A future step could be to put the types in the same symtab as
7295 the CU the types ultimately came from. */
7298 hash_type_unit_group (const void *item
)
7300 const struct type_unit_group
*tu_group
7301 = (const struct type_unit_group
*) item
;
7303 return hash_stmt_list_entry (&tu_group
->hash
);
7307 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7309 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7310 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7312 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7315 /* Allocate a hash table for type unit groups. */
7318 allocate_type_unit_groups_table ()
7320 return htab_up (htab_create_alloc (3,
7321 hash_type_unit_group
,
7323 NULL
, xcalloc
, xfree
));
7326 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7327 partial symtabs. We combine several TUs per psymtab to not let the size
7328 of any one psymtab grow too big. */
7329 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7330 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7332 /* Helper routine for get_type_unit_group.
7333 Create the type_unit_group object used to hold one or more TUs. */
7335 static struct type_unit_group
*
7336 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7338 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7339 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
7340 struct dwarf2_per_cu_data
*per_cu
;
7341 struct type_unit_group
*tu_group
;
7343 tu_group
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, type_unit_group
);
7344 per_cu
= &tu_group
->per_cu
;
7345 per_cu
->per_bfd
= per_bfd
;
7347 if (per_bfd
->using_index
)
7349 per_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
7350 struct dwarf2_per_cu_quick_data
);
7354 unsigned int line_offset
= to_underlying (line_offset_struct
);
7355 dwarf2_psymtab
*pst
;
7358 /* Give the symtab a useful name for debug purposes. */
7359 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7360 name
= string_printf ("<type_units_%d>",
7361 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7363 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7365 pst
= create_partial_symtab (per_cu
, per_objfile
, name
.c_str ());
7366 pst
->anonymous
= true;
7369 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7370 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7375 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7376 STMT_LIST is a DW_AT_stmt_list attribute. */
7378 static struct type_unit_group
*
7379 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7381 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7382 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7383 struct type_unit_group
*tu_group
;
7385 unsigned int line_offset
;
7386 struct type_unit_group type_unit_group_for_lookup
;
7388 if (per_objfile
->per_bfd
->type_unit_groups
== NULL
)
7389 per_objfile
->per_bfd
->type_unit_groups
= allocate_type_unit_groups_table ();
7391 /* Do we need to create a new group, or can we use an existing one? */
7393 if (stmt_list
!= nullptr && stmt_list
->form_is_unsigned ())
7395 line_offset
= stmt_list
->as_unsigned ();
7396 ++tu_stats
->nr_symtab_sharers
;
7400 /* Ugh, no stmt_list. Rare, but we have to handle it.
7401 We can do various things here like create one group per TU or
7402 spread them over multiple groups to split up the expansion work.
7403 To avoid worst case scenarios (too many groups or too large groups)
7404 we, umm, group them in bunches. */
7405 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7406 | (tu_stats
->nr_stmt_less_type_units
7407 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7408 ++tu_stats
->nr_stmt_less_type_units
;
7411 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7412 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7413 slot
= htab_find_slot (per_objfile
->per_bfd
->type_unit_groups
.get (),
7414 &type_unit_group_for_lookup
, INSERT
);
7417 tu_group
= (struct type_unit_group
*) *slot
;
7418 gdb_assert (tu_group
!= NULL
);
7422 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7423 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7425 ++tu_stats
->nr_symtabs
;
7431 /* Partial symbol tables. */
7433 /* Create a psymtab named NAME and assign it to PER_CU.
7435 The caller must fill in the following details:
7436 dirname, textlow, texthigh. */
7438 static dwarf2_psymtab
*
7439 create_partial_symtab (dwarf2_per_cu_data
*per_cu
,
7440 dwarf2_per_objfile
*per_objfile
,
7443 struct objfile
*objfile
= per_objfile
->objfile
;
7444 dwarf2_psymtab
*pst
;
7446 pst
= new dwarf2_psymtab (name
, objfile
, per_cu
);
7448 pst
->psymtabs_addrmap_supported
= true;
7450 /* This is the glue that links PST into GDB's symbol API. */
7451 per_cu
->v
.psymtab
= pst
;
7456 /* DIE reader function for process_psymtab_comp_unit. */
7459 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7460 const gdb_byte
*info_ptr
,
7461 struct die_info
*comp_unit_die
,
7462 enum language pretend_language
)
7464 struct dwarf2_cu
*cu
= reader
->cu
;
7465 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7466 struct objfile
*objfile
= per_objfile
->objfile
;
7467 struct gdbarch
*gdbarch
= objfile
->arch ();
7468 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7470 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7471 dwarf2_psymtab
*pst
;
7472 enum pc_bounds_kind cu_bounds_kind
;
7473 const char *filename
;
7475 gdb_assert (! per_cu
->is_debug_types
);
7477 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
7479 /* Allocate a new partial symbol table structure. */
7480 gdb::unique_xmalloc_ptr
<char> debug_filename
;
7481 static const char artificial
[] = "<artificial>";
7482 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7483 if (filename
== NULL
)
7485 else if (strcmp (filename
, artificial
) == 0)
7487 debug_filename
.reset (concat (artificial
, "@",
7488 sect_offset_str (per_cu
->sect_off
),
7490 filename
= debug_filename
.get ();
7493 pst
= create_partial_symtab (per_cu
, per_objfile
, filename
);
7495 /* This must be done before calling dwarf2_build_include_psymtabs. */
7496 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7498 baseaddr
= objfile
->text_section_offset ();
7500 dwarf2_find_base_address (comp_unit_die
, cu
);
7502 /* Possibly set the default values of LOWPC and HIGHPC from
7504 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7505 &best_highpc
, cu
, pst
);
7506 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7509 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7512 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7514 /* Store the contiguous range if it is not empty; it can be
7515 empty for CUs with no code. */
7516 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
7520 /* Check if comp unit has_children.
7521 If so, read the rest of the partial symbols from this comp unit.
7522 If not, there's no more debug_info for this comp unit. */
7523 if (comp_unit_die
->has_children
)
7525 struct partial_die_info
*first_die
;
7526 CORE_ADDR lowpc
, highpc
;
7528 lowpc
= ((CORE_ADDR
) -1);
7529 highpc
= ((CORE_ADDR
) 0);
7531 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7533 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7534 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7536 /* If we didn't find a lowpc, set it to highpc to avoid
7537 complaints from `maint check'. */
7538 if (lowpc
== ((CORE_ADDR
) -1))
7541 /* If the compilation unit didn't have an explicit address range,
7542 then use the information extracted from its child dies. */
7543 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7546 best_highpc
= highpc
;
7549 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7550 best_lowpc
+ baseaddr
)
7552 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7553 best_highpc
+ baseaddr
)
7558 if (!cu
->per_cu
->imported_symtabs_empty ())
7561 int len
= cu
->per_cu
->imported_symtabs_size ();
7563 /* Fill in 'dependencies' here; we fill in 'users' in a
7565 pst
->number_of_dependencies
= len
;
7567 = objfile
->partial_symtabs
->allocate_dependencies (len
);
7568 for (i
= 0; i
< len
; ++i
)
7570 pst
->dependencies
[i
]
7571 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7574 cu
->per_cu
->imported_symtabs_free ();
7577 /* Get the list of files included in the current compilation unit,
7578 and build a psymtab for each of them. */
7579 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
7581 dwarf_read_debug_printf ("Psymtab for %s unit @%s: %s - %s"
7582 ", %d global, %d static syms",
7583 per_cu
->is_debug_types
? "type" : "comp",
7584 sect_offset_str (per_cu
->sect_off
),
7585 paddress (gdbarch
, pst
->text_low (objfile
)),
7586 paddress (gdbarch
, pst
->text_high (objfile
)),
7587 (int) pst
->global_psymbols
.size (),
7588 (int) pst
->static_psymbols
.size ());
7591 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7592 Process compilation unit THIS_CU for a psymtab. */
7595 process_psymtab_comp_unit (dwarf2_per_cu_data
*this_cu
,
7596 dwarf2_per_objfile
*per_objfile
,
7597 bool want_partial_unit
,
7598 enum language pretend_language
)
7600 /* If this compilation unit was already read in, free the
7601 cached copy in order to read it in again. This is
7602 necessary because we skipped some symbols when we first
7603 read in the compilation unit (see load_partial_dies).
7604 This problem could be avoided, but the benefit is unclear. */
7605 per_objfile
->remove_cu (this_cu
);
7607 cutu_reader
reader (this_cu
, per_objfile
, nullptr, nullptr, false);
7609 switch (reader
.comp_unit_die
->tag
)
7611 case DW_TAG_compile_unit
:
7612 this_cu
->unit_type
= DW_UT_compile
;
7614 case DW_TAG_partial_unit
:
7615 this_cu
->unit_type
= DW_UT_partial
;
7617 case DW_TAG_type_unit
:
7618 this_cu
->unit_type
= DW_UT_type
;
7628 else if (this_cu
->is_debug_types
)
7629 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7630 reader
.comp_unit_die
);
7631 else if (want_partial_unit
7632 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7633 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7634 reader
.comp_unit_die
,
7637 this_cu
->lang
= reader
.cu
->language
;
7639 /* Age out any secondary CUs. */
7640 per_objfile
->age_comp_units ();
7643 /* Reader function for build_type_psymtabs. */
7646 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7647 const gdb_byte
*info_ptr
,
7648 struct die_info
*type_unit_die
)
7650 dwarf2_per_objfile
*per_objfile
= reader
->cu
->per_objfile
;
7651 struct dwarf2_cu
*cu
= reader
->cu
;
7652 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7653 struct signatured_type
*sig_type
;
7654 struct type_unit_group
*tu_group
;
7655 struct attribute
*attr
;
7656 struct partial_die_info
*first_die
;
7657 CORE_ADDR lowpc
, highpc
;
7658 dwarf2_psymtab
*pst
;
7660 gdb_assert (per_cu
->is_debug_types
);
7661 sig_type
= (struct signatured_type
*) per_cu
;
7663 if (! type_unit_die
->has_children
)
7666 attr
= type_unit_die
->attr (DW_AT_stmt_list
);
7667 tu_group
= get_type_unit_group (cu
, attr
);
7669 if (tu_group
->tus
== nullptr)
7670 tu_group
->tus
= new std::vector
<signatured_type
*>;
7671 tu_group
->tus
->push_back (sig_type
);
7673 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7674 pst
= create_partial_symtab (per_cu
, per_objfile
, "");
7675 pst
->anonymous
= true;
7677 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7679 lowpc
= (CORE_ADDR
) -1;
7680 highpc
= (CORE_ADDR
) 0;
7681 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7686 /* Struct used to sort TUs by their abbreviation table offset. */
7688 struct tu_abbrev_offset
7690 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7691 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7694 signatured_type
*sig_type
;
7695 sect_offset abbrev_offset
;
7698 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
7701 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
7702 const struct tu_abbrev_offset
&b
)
7704 return a
.abbrev_offset
< b
.abbrev_offset
;
7707 /* Efficiently read all the type units.
7708 This does the bulk of the work for build_type_psymtabs.
7710 The efficiency is because we sort TUs by the abbrev table they use and
7711 only read each abbrev table once. In one program there are 200K TUs
7712 sharing 8K abbrev tables.
7714 The main purpose of this function is to support building the
7715 dwarf2_per_objfile->per_bfd->type_unit_groups table.
7716 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7717 can collapse the search space by grouping them by stmt_list.
7718 The savings can be significant, in the same program from above the 200K TUs
7719 share 8K stmt_list tables.
7721 FUNC is expected to call get_type_unit_group, which will create the
7722 struct type_unit_group if necessary and add it to
7723 dwarf2_per_objfile->per_bfd->type_unit_groups. */
7726 build_type_psymtabs_1 (dwarf2_per_objfile
*per_objfile
)
7728 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7729 abbrev_table_up abbrev_table
;
7730 sect_offset abbrev_offset
;
7732 /* It's up to the caller to not call us multiple times. */
7733 gdb_assert (per_objfile
->per_bfd
->type_unit_groups
== NULL
);
7735 if (per_objfile
->per_bfd
->all_type_units
.empty ())
7738 /* TUs typically share abbrev tables, and there can be way more TUs than
7739 abbrev tables. Sort by abbrev table to reduce the number of times we
7740 read each abbrev table in.
7741 Alternatives are to punt or to maintain a cache of abbrev tables.
7742 This is simpler and efficient enough for now.
7744 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7745 symtab to use). Typically TUs with the same abbrev offset have the same
7746 stmt_list value too so in practice this should work well.
7748 The basic algorithm here is:
7750 sort TUs by abbrev table
7751 for each TU with same abbrev table:
7752 read abbrev table if first user
7753 read TU top level DIE
7754 [IWBN if DWO skeletons had DW_AT_stmt_list]
7757 dwarf_read_debug_printf ("Building type unit groups ...");
7759 /* Sort in a separate table to maintain the order of all_type_units
7760 for .gdb_index: TU indices directly index all_type_units. */
7761 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7762 sorted_by_abbrev
.reserve (per_objfile
->per_bfd
->all_type_units
.size ());
7764 for (signatured_type
*sig_type
: per_objfile
->per_bfd
->all_type_units
)
7765 sorted_by_abbrev
.emplace_back
7766 (sig_type
, read_abbrev_offset (per_objfile
, sig_type
->per_cu
.section
,
7767 sig_type
->per_cu
.sect_off
));
7769 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
7770 sort_tu_by_abbrev_offset
);
7772 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7774 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7776 /* Switch to the next abbrev table if necessary. */
7777 if (abbrev_table
== NULL
7778 || tu
.abbrev_offset
!= abbrev_offset
)
7780 abbrev_offset
= tu
.abbrev_offset
;
7781 per_objfile
->per_bfd
->abbrev
.read (per_objfile
->objfile
);
7783 abbrev_table::read (&per_objfile
->per_bfd
->abbrev
, abbrev_offset
);
7784 ++tu_stats
->nr_uniq_abbrev_tables
;
7787 cutu_reader
reader (&tu
.sig_type
->per_cu
, per_objfile
,
7788 abbrev_table
.get (), nullptr, false);
7789 if (!reader
.dummy_p
)
7790 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7791 reader
.comp_unit_die
);
7795 /* Print collected type unit statistics. */
7798 print_tu_stats (dwarf2_per_objfile
*per_objfile
)
7800 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7802 dwarf_read_debug_printf ("Type unit statistics:");
7803 dwarf_read_debug_printf (" %zu TUs",
7804 per_objfile
->per_bfd
->all_type_units
.size ());
7805 dwarf_read_debug_printf (" %d uniq abbrev tables",
7806 tu_stats
->nr_uniq_abbrev_tables
);
7807 dwarf_read_debug_printf (" %d symtabs from stmt_list entries",
7808 tu_stats
->nr_symtabs
);
7809 dwarf_read_debug_printf (" %d symtab sharers",
7810 tu_stats
->nr_symtab_sharers
);
7811 dwarf_read_debug_printf (" %d type units without a stmt_list",
7812 tu_stats
->nr_stmt_less_type_units
);
7813 dwarf_read_debug_printf (" %d all_type_units reallocs",
7814 tu_stats
->nr_all_type_units_reallocs
);
7817 /* Traversal function for build_type_psymtabs. */
7820 build_type_psymtab_dependencies (void **slot
, void *info
)
7822 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
7823 struct objfile
*objfile
= per_objfile
->objfile
;
7824 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7825 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
7826 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7827 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7830 gdb_assert (len
> 0);
7831 gdb_assert (per_cu
->type_unit_group_p ());
7833 pst
->number_of_dependencies
= len
;
7834 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
7835 for (i
= 0; i
< len
; ++i
)
7837 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7838 gdb_assert (iter
->per_cu
.is_debug_types
);
7839 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
7840 iter
->type_unit_group
= tu_group
;
7843 delete tu_group
->tus
;
7844 tu_group
->tus
= nullptr;
7849 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7850 Build partial symbol tables for the .debug_types comp-units. */
7853 build_type_psymtabs (dwarf2_per_objfile
*per_objfile
)
7855 if (! create_all_type_units (per_objfile
))
7858 build_type_psymtabs_1 (per_objfile
);
7861 /* Traversal function for process_skeletonless_type_unit.
7862 Read a TU in a DWO file and build partial symbols for it. */
7865 process_skeletonless_type_unit (void **slot
, void *info
)
7867 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7868 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
7869 struct signatured_type find_entry
, *entry
;
7871 /* If this TU doesn't exist in the global table, add it and read it in. */
7873 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
7874 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
7876 find_entry
.signature
= dwo_unit
->signature
;
7877 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
7878 &find_entry
, INSERT
);
7879 /* If we've already seen this type there's nothing to do. What's happening
7880 is we're doing our own version of comdat-folding here. */
7884 /* This does the job that create_all_type_units would have done for
7886 entry
= add_type_unit (per_objfile
, dwo_unit
->signature
, slot
);
7887 fill_in_sig_entry_from_dwo_entry (per_objfile
, entry
, dwo_unit
);
7890 /* This does the job that build_type_psymtabs_1 would have done. */
7891 cutu_reader
reader (&entry
->per_cu
, per_objfile
, nullptr, nullptr, false);
7892 if (!reader
.dummy_p
)
7893 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7894 reader
.comp_unit_die
);
7899 /* Traversal function for process_skeletonless_type_units. */
7902 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7904 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7906 if (dwo_file
->tus
!= NULL
)
7907 htab_traverse_noresize (dwo_file
->tus
.get (),
7908 process_skeletonless_type_unit
, info
);
7913 /* Scan all TUs of DWO files, verifying we've processed them.
7914 This is needed in case a TU was emitted without its skeleton.
7915 Note: This can't be done until we know what all the DWO files are. */
7918 process_skeletonless_type_units (dwarf2_per_objfile
*per_objfile
)
7920 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
7921 if (get_dwp_file (per_objfile
) == NULL
7922 && per_objfile
->per_bfd
->dwo_files
!= NULL
)
7924 htab_traverse_noresize (per_objfile
->per_bfd
->dwo_files
.get (),
7925 process_dwo_file_for_skeletonless_type_units
,
7930 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
7933 set_partial_user (dwarf2_per_objfile
*per_objfile
)
7935 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
7937 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7942 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
7944 /* Set the 'user' field only if it is not already set. */
7945 if (pst
->dependencies
[j
]->user
== NULL
)
7946 pst
->dependencies
[j
]->user
= pst
;
7951 /* Build the partial symbol table by doing a quick pass through the
7952 .debug_info and .debug_abbrev sections. */
7955 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
)
7957 struct objfile
*objfile
= per_objfile
->objfile
;
7959 dwarf_read_debug_printf ("Building psymtabs of objfile %s ...",
7960 objfile_name (objfile
));
7962 scoped_restore restore_reading_psyms
7963 = make_scoped_restore (&per_objfile
->per_bfd
->reading_partial_symbols
,
7966 per_objfile
->per_bfd
->info
.read (objfile
);
7968 /* Any cached compilation units will be linked by the per-objfile
7969 read_in_chain. Make sure to free them when we're done. */
7970 free_cached_comp_units
freer (per_objfile
);
7972 build_type_psymtabs (per_objfile
);
7974 create_all_comp_units (per_objfile
);
7976 /* Create a temporary address map on a temporary obstack. We later
7977 copy this to the final obstack. */
7978 auto_obstack temp_obstack
;
7980 scoped_restore save_psymtabs_addrmap
7981 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
7982 addrmap_create_mutable (&temp_obstack
));
7984 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
7986 if (per_cu
->v
.psymtab
!= NULL
)
7987 /* In case a forward DW_TAG_imported_unit has read the CU already. */
7989 process_psymtab_comp_unit (per_cu
, per_objfile
, false,
7993 /* This has to wait until we read the CUs, we need the list of DWOs. */
7994 process_skeletonless_type_units (per_objfile
);
7996 /* Now that all TUs have been processed we can fill in the dependencies. */
7997 if (per_objfile
->per_bfd
->type_unit_groups
!= NULL
)
7999 htab_traverse_noresize (per_objfile
->per_bfd
->type_unit_groups
.get (),
8000 build_type_psymtab_dependencies
, per_objfile
);
8003 if (dwarf_read_debug
> 0)
8004 print_tu_stats (per_objfile
);
8006 set_partial_user (per_objfile
);
8008 objfile
->partial_symtabs
->psymtabs_addrmap
8009 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
8010 objfile
->partial_symtabs
->obstack ());
8011 /* At this point we want to keep the address map. */
8012 save_psymtabs_addrmap
.release ();
8014 dwarf_read_debug_printf ("Done building psymtabs of %s",
8015 objfile_name (objfile
));
8018 /* Load the partial DIEs for a secondary CU into memory.
8019 This is also used when rereading a primary CU with load_all_dies. */
8022 load_partial_comp_unit (dwarf2_per_cu_data
*this_cu
,
8023 dwarf2_per_objfile
*per_objfile
,
8024 dwarf2_cu
*existing_cu
)
8026 cutu_reader
reader (this_cu
, per_objfile
, nullptr, existing_cu
, false);
8028 if (!reader
.dummy_p
)
8030 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
8033 /* Check if comp unit has_children.
8034 If so, read the rest of the partial symbols from this comp unit.
8035 If not, there's no more debug_info for this comp unit. */
8036 if (reader
.comp_unit_die
->has_children
)
8037 load_partial_dies (&reader
, reader
.info_ptr
, 0);
8044 read_comp_units_from_section (dwarf2_per_objfile
*per_objfile
,
8045 struct dwarf2_section_info
*section
,
8046 struct dwarf2_section_info
*abbrev_section
,
8047 unsigned int is_dwz
)
8049 const gdb_byte
*info_ptr
;
8050 struct objfile
*objfile
= per_objfile
->objfile
;
8052 dwarf_read_debug_printf ("Reading %s for %s",
8053 section
->get_name (),
8054 section
->get_file_name ());
8056 section
->read (objfile
);
8058 info_ptr
= section
->buffer
;
8060 while (info_ptr
< section
->buffer
+ section
->size
)
8062 struct dwarf2_per_cu_data
*this_cu
;
8064 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
8066 comp_unit_head cu_header
;
8067 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
8068 abbrev_section
, info_ptr
,
8069 rcuh_kind::COMPILE
);
8071 /* Save the compilation unit for later lookup. */
8072 if (cu_header
.unit_type
!= DW_UT_type
)
8073 this_cu
= per_objfile
->per_bfd
->allocate_per_cu ();
8076 auto sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
8077 sig_type
->signature
= cu_header
.signature
;
8078 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
8079 this_cu
= &sig_type
->per_cu
;
8081 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
8082 this_cu
->sect_off
= sect_off
;
8083 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
8084 this_cu
->is_dwz
= is_dwz
;
8085 this_cu
->section
= section
;
8087 per_objfile
->per_bfd
->all_comp_units
.push_back (this_cu
);
8089 info_ptr
= info_ptr
+ this_cu
->length
;
8093 /* Create a list of all compilation units in OBJFILE.
8094 This is only done for -readnow and building partial symtabs. */
8097 create_all_comp_units (dwarf2_per_objfile
*per_objfile
)
8099 gdb_assert (per_objfile
->per_bfd
->all_comp_units
.empty ());
8100 read_comp_units_from_section (per_objfile
, &per_objfile
->per_bfd
->info
,
8101 &per_objfile
->per_bfd
->abbrev
, 0);
8103 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
8105 read_comp_units_from_section (per_objfile
, &dwz
->info
, &dwz
->abbrev
, 1);
8108 /* Process all loaded DIEs for compilation unit CU, starting at
8109 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
8110 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
8111 DW_AT_ranges). See the comments of add_partial_subprogram on how
8112 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
8115 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
8116 CORE_ADDR
*highpc
, int set_addrmap
,
8117 struct dwarf2_cu
*cu
)
8119 struct partial_die_info
*pdi
;
8121 /* Now, march along the PDI's, descending into ones which have
8122 interesting children but skipping the children of the other ones,
8123 until we reach the end of the compilation unit. */
8131 /* Anonymous namespaces or modules have no name but have interesting
8132 children, so we need to look at them. Ditto for anonymous
8135 if (pdi
->raw_name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
8136 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
8137 || pdi
->tag
== DW_TAG_imported_unit
8138 || pdi
->tag
== DW_TAG_inlined_subroutine
)
8142 case DW_TAG_subprogram
:
8143 case DW_TAG_inlined_subroutine
:
8144 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8145 if (cu
->language
== language_cplus
)
8146 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8149 case DW_TAG_constant
:
8150 case DW_TAG_variable
:
8151 case DW_TAG_typedef
:
8152 case DW_TAG_union_type
:
8153 if (!pdi
->is_declaration
8154 || (pdi
->tag
== DW_TAG_variable
&& pdi
->is_external
))
8156 add_partial_symbol (pdi
, cu
);
8159 case DW_TAG_class_type
:
8160 case DW_TAG_interface_type
:
8161 case DW_TAG_structure_type
:
8162 if (!pdi
->is_declaration
)
8164 add_partial_symbol (pdi
, cu
);
8166 if ((cu
->language
== language_rust
8167 || cu
->language
== language_cplus
) && pdi
->has_children
)
8168 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8171 case DW_TAG_enumeration_type
:
8172 if (!pdi
->is_declaration
)
8173 add_partial_enumeration (pdi
, cu
);
8175 case DW_TAG_base_type
:
8176 case DW_TAG_subrange_type
:
8177 /* File scope base type definitions are added to the partial
8179 add_partial_symbol (pdi
, cu
);
8181 case DW_TAG_namespace
:
8182 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8185 if (!pdi
->is_declaration
)
8186 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8188 case DW_TAG_imported_unit
:
8190 struct dwarf2_per_cu_data
*per_cu
;
8192 /* For now we don't handle imported units in type units. */
8193 if (cu
->per_cu
->is_debug_types
)
8195 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8196 " supported in type units [in module %s]"),
8197 objfile_name (cu
->per_objfile
->objfile
));
8200 per_cu
= dwarf2_find_containing_comp_unit
8201 (pdi
->d
.sect_off
, pdi
->is_dwz
, cu
->per_objfile
);
8203 /* Go read the partial unit, if needed. */
8204 if (per_cu
->v
.psymtab
== NULL
)
8205 process_psymtab_comp_unit (per_cu
, cu
->per_objfile
, true,
8208 cu
->per_cu
->imported_symtabs_push (per_cu
);
8211 case DW_TAG_imported_declaration
:
8212 add_partial_symbol (pdi
, cu
);
8219 /* If the die has a sibling, skip to the sibling. */
8221 pdi
= pdi
->die_sibling
;
8225 /* Functions used to compute the fully scoped name of a partial DIE.
8227 Normally, this is simple. For C++, the parent DIE's fully scoped
8228 name is concatenated with "::" and the partial DIE's name.
8229 Enumerators are an exception; they use the scope of their parent
8230 enumeration type, i.e. the name of the enumeration type is not
8231 prepended to the enumerator.
8233 There are two complexities. One is DW_AT_specification; in this
8234 case "parent" means the parent of the target of the specification,
8235 instead of the direct parent of the DIE. The other is compilers
8236 which do not emit DW_TAG_namespace; in this case we try to guess
8237 the fully qualified name of structure types from their members'
8238 linkage names. This must be done using the DIE's children rather
8239 than the children of any DW_AT_specification target. We only need
8240 to do this for structures at the top level, i.e. if the target of
8241 any DW_AT_specification (if any; otherwise the DIE itself) does not
8244 /* Compute the scope prefix associated with PDI's parent, in
8245 compilation unit CU. The result will be allocated on CU's
8246 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8247 field. NULL is returned if no prefix is necessary. */
8249 partial_die_parent_scope (struct partial_die_info
*pdi
,
8250 struct dwarf2_cu
*cu
)
8252 const char *grandparent_scope
;
8253 struct partial_die_info
*parent
, *real_pdi
;
8255 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8256 then this means the parent of the specification DIE. */
8259 while (real_pdi
->has_specification
)
8261 auto res
= find_partial_die (real_pdi
->spec_offset
,
8262 real_pdi
->spec_is_dwz
, cu
);
8267 parent
= real_pdi
->die_parent
;
8271 if (parent
->scope_set
)
8272 return parent
->scope
;
8276 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8278 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8279 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8280 Work around this problem here. */
8281 if (cu
->language
== language_cplus
8282 && parent
->tag
== DW_TAG_namespace
8283 && strcmp (parent
->name (cu
), "::") == 0
8284 && grandparent_scope
== NULL
)
8286 parent
->scope
= NULL
;
8287 parent
->scope_set
= 1;
8291 /* Nested subroutines in Fortran get a prefix. */
8292 if (pdi
->tag
== DW_TAG_enumerator
)
8293 /* Enumerators should not get the name of the enumeration as a prefix. */
8294 parent
->scope
= grandparent_scope
;
8295 else if (parent
->tag
== DW_TAG_namespace
8296 || parent
->tag
== DW_TAG_module
8297 || parent
->tag
== DW_TAG_structure_type
8298 || parent
->tag
== DW_TAG_class_type
8299 || parent
->tag
== DW_TAG_interface_type
8300 || parent
->tag
== DW_TAG_union_type
8301 || parent
->tag
== DW_TAG_enumeration_type
8302 || (cu
->language
== language_fortran
8303 && parent
->tag
== DW_TAG_subprogram
8304 && pdi
->tag
== DW_TAG_subprogram
))
8306 if (grandparent_scope
== NULL
)
8307 parent
->scope
= parent
->name (cu
);
8309 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8311 parent
->name (cu
), 0, cu
);
8315 /* FIXME drow/2004-04-01: What should we be doing with
8316 function-local names? For partial symbols, we should probably be
8318 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8319 dwarf_tag_name (parent
->tag
),
8320 sect_offset_str (pdi
->sect_off
));
8321 parent
->scope
= grandparent_scope
;
8324 parent
->scope_set
= 1;
8325 return parent
->scope
;
8328 /* Return the fully scoped name associated with PDI, from compilation unit
8329 CU. The result will be allocated with malloc. */
8331 static gdb::unique_xmalloc_ptr
<char>
8332 partial_die_full_name (struct partial_die_info
*pdi
,
8333 struct dwarf2_cu
*cu
)
8335 const char *parent_scope
;
8337 /* If this is a template instantiation, we can not work out the
8338 template arguments from partial DIEs. So, unfortunately, we have
8339 to go through the full DIEs. At least any work we do building
8340 types here will be reused if full symbols are loaded later. */
8341 if (pdi
->has_template_arguments
)
8345 if (pdi
->name (cu
) != NULL
&& strchr (pdi
->name (cu
), '<') == NULL
)
8347 struct die_info
*die
;
8348 struct attribute attr
;
8349 struct dwarf2_cu
*ref_cu
= cu
;
8351 /* DW_FORM_ref_addr is using section offset. */
8352 attr
.name
= (enum dwarf_attribute
) 0;
8353 attr
.form
= DW_FORM_ref_addr
;
8354 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8355 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8357 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8361 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8362 if (parent_scope
== NULL
)
8365 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8371 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8373 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
8374 struct objfile
*objfile
= per_objfile
->objfile
;
8375 struct gdbarch
*gdbarch
= objfile
->arch ();
8377 const char *actual_name
= NULL
;
8380 baseaddr
= objfile
->text_section_offset ();
8382 gdb::unique_xmalloc_ptr
<char> built_actual_name
8383 = partial_die_full_name (pdi
, cu
);
8384 if (built_actual_name
!= NULL
)
8385 actual_name
= built_actual_name
.get ();
8387 if (actual_name
== NULL
)
8388 actual_name
= pdi
->name (cu
);
8390 partial_symbol psymbol
;
8391 memset (&psymbol
, 0, sizeof (psymbol
));
8392 psymbol
.ginfo
.set_language (cu
->language
, &objfile
->objfile_obstack
);
8393 psymbol
.ginfo
.set_section_index (-1);
8395 /* The code below indicates that the psymbol should be installed by
8397 gdb::optional
<psymbol_placement
> where
;
8401 case DW_TAG_inlined_subroutine
:
8402 case DW_TAG_subprogram
:
8403 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8405 if (pdi
->is_external
8406 || cu
->language
== language_ada
8407 || (cu
->language
== language_fortran
8408 && pdi
->die_parent
!= NULL
8409 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8411 /* Normally, only "external" DIEs are part of the global scope.
8412 But in Ada and Fortran, we want to be able to access nested
8413 procedures globally. So all Ada and Fortran subprograms are
8414 stored in the global scope. */
8415 where
= psymbol_placement::GLOBAL
;
8418 where
= psymbol_placement::STATIC
;
8420 psymbol
.domain
= VAR_DOMAIN
;
8421 psymbol
.aclass
= LOC_BLOCK
;
8422 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
8423 psymbol
.ginfo
.value
.address
= addr
;
8425 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8426 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8428 case DW_TAG_constant
:
8429 psymbol
.domain
= VAR_DOMAIN
;
8430 psymbol
.aclass
= LOC_STATIC
;
8431 where
= (pdi
->is_external
8432 ? psymbol_placement::GLOBAL
8433 : psymbol_placement::STATIC
);
8435 case DW_TAG_variable
:
8437 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8441 && !per_objfile
->per_bfd
->has_section_at_zero
)
8443 /* A global or static variable may also have been stripped
8444 out by the linker if unused, in which case its address
8445 will be nullified; do not add such variables into partial
8446 symbol table then. */
8448 else if (pdi
->is_external
)
8451 Don't enter into the minimal symbol tables as there is
8452 a minimal symbol table entry from the ELF symbols already.
8453 Enter into partial symbol table if it has a location
8454 descriptor or a type.
8455 If the location descriptor is missing, new_symbol will create
8456 a LOC_UNRESOLVED symbol, the address of the variable will then
8457 be determined from the minimal symbol table whenever the variable
8459 The address for the partial symbol table entry is not
8460 used by GDB, but it comes in handy for debugging partial symbol
8463 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8465 psymbol
.domain
= VAR_DOMAIN
;
8466 psymbol
.aclass
= LOC_STATIC
;
8467 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
8468 psymbol
.ginfo
.value
.address
= addr
;
8469 where
= psymbol_placement::GLOBAL
;
8474 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8476 /* Static Variable. Skip symbols whose value we cannot know (those
8477 without location descriptors or constant values). */
8478 if (!has_loc
&& !pdi
->has_const_value
)
8481 psymbol
.domain
= VAR_DOMAIN
;
8482 psymbol
.aclass
= LOC_STATIC
;
8483 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
8485 psymbol
.ginfo
.value
.address
= addr
;
8486 where
= psymbol_placement::STATIC
;
8489 case DW_TAG_array_type
:
8490 case DW_TAG_typedef
:
8491 case DW_TAG_base_type
:
8492 case DW_TAG_subrange_type
:
8493 psymbol
.domain
= VAR_DOMAIN
;
8494 psymbol
.aclass
= LOC_TYPEDEF
;
8495 where
= psymbol_placement::STATIC
;
8497 case DW_TAG_imported_declaration
:
8498 case DW_TAG_namespace
:
8499 psymbol
.domain
= VAR_DOMAIN
;
8500 psymbol
.aclass
= LOC_TYPEDEF
;
8501 where
= psymbol_placement::GLOBAL
;
8504 /* With Fortran 77 there might be a "BLOCK DATA" module
8505 available without any name. If so, we skip the module as it
8506 doesn't bring any value. */
8507 if (actual_name
!= nullptr)
8509 psymbol
.domain
= MODULE_DOMAIN
;
8510 psymbol
.aclass
= LOC_TYPEDEF
;
8511 where
= psymbol_placement::GLOBAL
;
8514 case DW_TAG_class_type
:
8515 case DW_TAG_interface_type
:
8516 case DW_TAG_structure_type
:
8517 case DW_TAG_union_type
:
8518 case DW_TAG_enumeration_type
:
8519 /* Skip external references. The DWARF standard says in the section
8520 about "Structure, Union, and Class Type Entries": "An incomplete
8521 structure, union or class type is represented by a structure,
8522 union or class entry that does not have a byte size attribute
8523 and that has a DW_AT_declaration attribute." */
8524 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8527 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8528 static vs. global. */
8529 psymbol
.domain
= STRUCT_DOMAIN
;
8530 psymbol
.aclass
= LOC_TYPEDEF
;
8531 where
= (cu
->language
== language_cplus
8532 ? psymbol_placement::GLOBAL
8533 : psymbol_placement::STATIC
);
8535 case DW_TAG_enumerator
:
8536 psymbol
.domain
= VAR_DOMAIN
;
8537 psymbol
.aclass
= LOC_CONST
;
8538 where
= (cu
->language
== language_cplus
8539 ? psymbol_placement::GLOBAL
8540 : psymbol_placement::STATIC
);
8546 if (where
.has_value ())
8548 if (built_actual_name
!= nullptr)
8549 actual_name
= objfile
->intern (actual_name
);
8550 if (pdi
->linkage_name
== nullptr || cu
->language
== language_ada
)
8551 psymbol
.ginfo
.set_linkage_name (actual_name
);
8554 psymbol
.ginfo
.set_demangled_name (actual_name
,
8555 &objfile
->objfile_obstack
);
8556 psymbol
.ginfo
.set_linkage_name (pdi
->linkage_name
);
8558 cu
->per_cu
->v
.psymtab
->add_psymbol (psymbol
, *where
, objfile
);
8562 /* Read a partial die corresponding to a namespace; also, add a symbol
8563 corresponding to that namespace to the symbol table. NAMESPACE is
8564 the name of the enclosing namespace. */
8567 add_partial_namespace (struct partial_die_info
*pdi
,
8568 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8569 int set_addrmap
, struct dwarf2_cu
*cu
)
8571 /* Add a symbol for the namespace. */
8573 add_partial_symbol (pdi
, cu
);
8575 /* Now scan partial symbols in that namespace. */
8577 if (pdi
->has_children
)
8578 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8581 /* Read a partial die corresponding to a Fortran module. */
8584 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8585 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8587 /* Add a symbol for the namespace. */
8589 add_partial_symbol (pdi
, cu
);
8591 /* Now scan partial symbols in that module. */
8593 if (pdi
->has_children
)
8594 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8597 /* Read a partial die corresponding to a subprogram or an inlined
8598 subprogram and create a partial symbol for that subprogram.
8599 When the CU language allows it, this routine also defines a partial
8600 symbol for each nested subprogram that this subprogram contains.
8601 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8602 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8604 PDI may also be a lexical block, in which case we simply search
8605 recursively for subprograms defined inside that lexical block.
8606 Again, this is only performed when the CU language allows this
8607 type of definitions. */
8610 add_partial_subprogram (struct partial_die_info
*pdi
,
8611 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8612 int set_addrmap
, struct dwarf2_cu
*cu
)
8614 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8616 if (pdi
->has_pc_info
)
8618 if (pdi
->lowpc
< *lowpc
)
8619 *lowpc
= pdi
->lowpc
;
8620 if (pdi
->highpc
> *highpc
)
8621 *highpc
= pdi
->highpc
;
8624 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8625 struct gdbarch
*gdbarch
= objfile
->arch ();
8627 CORE_ADDR this_highpc
;
8628 CORE_ADDR this_lowpc
;
8630 baseaddr
= objfile
->text_section_offset ();
8632 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8633 pdi
->lowpc
+ baseaddr
)
8636 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8637 pdi
->highpc
+ baseaddr
)
8639 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8640 this_lowpc
, this_highpc
- 1,
8641 cu
->per_cu
->v
.psymtab
);
8645 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8647 if (!pdi
->is_declaration
)
8648 /* Ignore subprogram DIEs that do not have a name, they are
8649 illegal. Do not emit a complaint at this point, we will
8650 do so when we convert this psymtab into a symtab. */
8652 add_partial_symbol (pdi
, cu
);
8656 if (! pdi
->has_children
)
8659 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
8661 pdi
= pdi
->die_child
;
8665 if (pdi
->tag
== DW_TAG_subprogram
8666 || pdi
->tag
== DW_TAG_inlined_subroutine
8667 || pdi
->tag
== DW_TAG_lexical_block
)
8668 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8669 pdi
= pdi
->die_sibling
;
8674 /* Read a partial die corresponding to an enumeration type. */
8677 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8678 struct dwarf2_cu
*cu
)
8680 struct partial_die_info
*pdi
;
8682 if (enum_pdi
->name (cu
) != NULL
)
8683 add_partial_symbol (enum_pdi
, cu
);
8685 pdi
= enum_pdi
->die_child
;
8688 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->raw_name
== NULL
)
8689 complaint (_("malformed enumerator DIE ignored"));
8691 add_partial_symbol (pdi
, cu
);
8692 pdi
= pdi
->die_sibling
;
8696 /* Return the initial uleb128 in the die at INFO_PTR. */
8699 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8701 unsigned int bytes_read
;
8703 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8706 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8707 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8709 Return the corresponding abbrev, or NULL if the number is zero (indicating
8710 an empty DIE). In either case *BYTES_READ will be set to the length of
8711 the initial number. */
8713 static const struct abbrev_info
*
8714 peek_die_abbrev (const die_reader_specs
&reader
,
8715 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8717 dwarf2_cu
*cu
= reader
.cu
;
8718 bfd
*abfd
= reader
.abfd
;
8719 unsigned int abbrev_number
8720 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8722 if (abbrev_number
== 0)
8725 const abbrev_info
*abbrev
8726 = reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8729 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8730 " at offset %s [in module %s]"),
8731 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8732 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8738 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8739 Returns a pointer to the end of a series of DIEs, terminated by an empty
8740 DIE. Any children of the skipped DIEs will also be skipped. */
8742 static const gdb_byte
*
8743 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8747 unsigned int bytes_read
;
8748 const abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
,
8752 return info_ptr
+ bytes_read
;
8754 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8758 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8759 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8760 abbrev corresponding to that skipped uleb128 should be passed in
8761 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8764 static const gdb_byte
*
8765 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8766 const struct abbrev_info
*abbrev
)
8768 unsigned int bytes_read
;
8769 struct attribute attr
;
8770 bfd
*abfd
= reader
->abfd
;
8771 struct dwarf2_cu
*cu
= reader
->cu
;
8772 const gdb_byte
*buffer
= reader
->buffer
;
8773 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8774 unsigned int form
, i
;
8776 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8778 /* The only abbrev we care about is DW_AT_sibling. */
8779 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8781 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
8782 if (attr
.form
== DW_FORM_ref_addr
)
8783 complaint (_("ignoring absolute DW_AT_sibling"));
8786 sect_offset off
= attr
.get_ref_die_offset ();
8787 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8789 if (sibling_ptr
< info_ptr
)
8790 complaint (_("DW_AT_sibling points backwards"));
8791 else if (sibling_ptr
> reader
->buffer_end
)
8792 reader
->die_section
->overflow_complaint ();
8798 /* If it isn't DW_AT_sibling, skip this attribute. */
8799 form
= abbrev
->attrs
[i
].form
;
8803 case DW_FORM_ref_addr
:
8804 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8805 and later it is offset sized. */
8806 if (cu
->header
.version
== 2)
8807 info_ptr
+= cu
->header
.addr_size
;
8809 info_ptr
+= cu
->header
.offset_size
;
8811 case DW_FORM_GNU_ref_alt
:
8812 info_ptr
+= cu
->header
.offset_size
;
8815 info_ptr
+= cu
->header
.addr_size
;
8823 case DW_FORM_flag_present
:
8824 case DW_FORM_implicit_const
:
8841 case DW_FORM_ref_sig8
:
8844 case DW_FORM_data16
:
8847 case DW_FORM_string
:
8848 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8849 info_ptr
+= bytes_read
;
8851 case DW_FORM_sec_offset
:
8853 case DW_FORM_GNU_strp_alt
:
8854 info_ptr
+= cu
->header
.offset_size
;
8856 case DW_FORM_exprloc
:
8858 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8859 info_ptr
+= bytes_read
;
8861 case DW_FORM_block1
:
8862 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8864 case DW_FORM_block2
:
8865 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8867 case DW_FORM_block4
:
8868 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8874 case DW_FORM_ref_udata
:
8875 case DW_FORM_GNU_addr_index
:
8876 case DW_FORM_GNU_str_index
:
8877 case DW_FORM_rnglistx
:
8878 case DW_FORM_loclistx
:
8879 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8881 case DW_FORM_indirect
:
8882 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8883 info_ptr
+= bytes_read
;
8884 /* We need to continue parsing from here, so just go back to
8886 goto skip_attribute
;
8889 error (_("Dwarf Error: Cannot handle %s "
8890 "in DWARF reader [in module %s]"),
8891 dwarf_form_name (form
),
8892 bfd_get_filename (abfd
));
8896 if (abbrev
->has_children
)
8897 return skip_children (reader
, info_ptr
);
8902 /* Locate ORIG_PDI's sibling.
8903 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8905 static const gdb_byte
*
8906 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8907 struct partial_die_info
*orig_pdi
,
8908 const gdb_byte
*info_ptr
)
8910 /* Do we know the sibling already? */
8912 if (orig_pdi
->sibling
)
8913 return orig_pdi
->sibling
;
8915 /* Are there any children to deal with? */
8917 if (!orig_pdi
->has_children
)
8920 /* Skip the children the long way. */
8922 return skip_children (reader
, info_ptr
);
8925 /* Expand this partial symbol table into a full symbol table. SELF is
8929 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
8931 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8933 gdb_assert (!per_objfile
->symtab_set_p (per_cu_data
));
8935 /* If this psymtab is constructed from a debug-only objfile, the
8936 has_section_at_zero flag will not necessarily be correct. We
8937 can get the correct value for this flag by looking at the data
8938 associated with the (presumably stripped) associated objfile. */
8939 if (objfile
->separate_debug_objfile_backlink
)
8941 dwarf2_per_objfile
*per_objfile_backlink
8942 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
8944 per_objfile
->per_bfd
->has_section_at_zero
8945 = per_objfile_backlink
->per_bfd
->has_section_at_zero
;
8948 expand_psymtab (objfile
);
8950 process_cu_includes (per_objfile
);
8953 /* Reading in full CUs. */
8955 /* Add PER_CU to the queue. */
8958 queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
8959 dwarf2_per_objfile
*per_objfile
,
8960 enum language pretend_language
)
8964 gdb_assert (per_objfile
->per_bfd
->queue
.has_value ());
8965 per_cu
->per_bfd
->queue
->emplace (per_cu
, per_objfile
, pretend_language
);
8968 /* If PER_CU is not yet expanded of queued for expansion, add it to the queue.
8970 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
8973 Return true if maybe_queue_comp_unit requires the caller to load the CU's
8974 DIEs, false otherwise.
8976 Explanation: there is an invariant that if a CU is queued for expansion
8977 (present in `dwarf2_per_bfd::queue`), then its DIEs are loaded
8978 (a dwarf2_cu object exists for this CU, and `dwarf2_per_objfile::get_cu`
8979 returns non-nullptr). If the CU gets enqueued by this function but its DIEs
8980 are not yet loaded, the the caller must load the CU's DIEs to ensure the
8981 invariant is respected.
8983 The caller is therefore not required to load the CU's DIEs (we return false)
8986 - the CU is already expanded, and therefore does not get enqueued
8987 - the CU gets enqueued for expansion, but its DIEs are already loaded
8989 Note that the caller should not use this function's return value as an
8990 indicator of whether the CU's DIEs are loaded right now, it should check
8991 that by calling `dwarf2_per_objfile::get_cu` instead. */
8994 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
8995 dwarf2_per_cu_data
*per_cu
,
8996 dwarf2_per_objfile
*per_objfile
,
8997 enum language pretend_language
)
8999 /* We may arrive here during partial symbol reading, if we need full
9000 DIEs to process an unusual case (e.g. template arguments). Do
9001 not queue PER_CU, just tell our caller to load its DIEs. */
9002 if (per_cu
->per_bfd
->reading_partial_symbols
)
9004 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
9006 if (cu
== NULL
|| cu
->dies
== NULL
)
9011 /* Mark the dependence relation so that we don't flush PER_CU
9013 if (dependent_cu
!= NULL
)
9014 dwarf2_add_dependence (dependent_cu
, per_cu
);
9016 /* If it's already on the queue, we have nothing to do. */
9019 /* Verify the invariant that if a CU is queued for expansion, its DIEs are
9021 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
9023 /* If the CU is queued for expansion, it should not already be
9025 gdb_assert (!per_objfile
->symtab_set_p (per_cu
));
9027 /* The DIEs are already loaded, the caller doesn't need to do it. */
9031 bool queued
= false;
9032 if (!per_objfile
->symtab_set_p (per_cu
))
9034 /* Add it to the queue. */
9035 queue_comp_unit (per_cu
, per_objfile
, pretend_language
);
9039 /* If the compilation unit is already loaded, just mark it as
9041 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
9045 /* Ask the caller to load the CU's DIEs if the CU got enqueued for expansion
9046 and the DIEs are not already loaded. */
9047 return queued
&& cu
== nullptr;
9050 /* Process the queue. */
9053 process_queue (dwarf2_per_objfile
*per_objfile
)
9055 dwarf_read_debug_printf ("Expanding one or more symtabs of objfile %s ...",
9056 objfile_name (per_objfile
->objfile
));
9058 /* The queue starts out with one item, but following a DIE reference
9059 may load a new CU, adding it to the end of the queue. */
9060 while (!per_objfile
->per_bfd
->queue
->empty ())
9062 dwarf2_queue_item
&item
= per_objfile
->per_bfd
->queue
->front ();
9063 dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
9065 if (!per_objfile
->symtab_set_p (per_cu
))
9067 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
9069 /* Skip dummy CUs. */
9072 unsigned int debug_print_threshold
;
9075 if (per_cu
->is_debug_types
)
9077 struct signatured_type
*sig_type
=
9078 (struct signatured_type
*) per_cu
;
9080 sprintf (buf
, "TU %s at offset %s",
9081 hex_string (sig_type
->signature
),
9082 sect_offset_str (per_cu
->sect_off
));
9083 /* There can be 100s of TUs.
9084 Only print them in verbose mode. */
9085 debug_print_threshold
= 2;
9089 sprintf (buf
, "CU at offset %s",
9090 sect_offset_str (per_cu
->sect_off
));
9091 debug_print_threshold
= 1;
9094 if (dwarf_read_debug
>= debug_print_threshold
)
9095 dwarf_read_debug_printf ("Expanding symtab of %s", buf
);
9097 if (per_cu
->is_debug_types
)
9098 process_full_type_unit (cu
, item
.pretend_language
);
9100 process_full_comp_unit (cu
, item
.pretend_language
);
9102 if (dwarf_read_debug
>= debug_print_threshold
)
9103 dwarf_read_debug_printf ("Done expanding %s", buf
);
9108 per_objfile
->per_bfd
->queue
->pop ();
9111 dwarf_read_debug_printf ("Done expanding symtabs of %s.",
9112 objfile_name (per_objfile
->objfile
));
9115 /* Read in full symbols for PST, and anything it depends on. */
9118 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
9120 gdb_assert (!readin_p (objfile
));
9122 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9123 free_cached_comp_units
freer (per_objfile
);
9124 expand_dependencies (objfile
);
9126 dw2_do_instantiate_symtab (per_cu_data
, per_objfile
, false);
9127 gdb_assert (get_compunit_symtab (objfile
) != nullptr);
9130 /* See psympriv.h. */
9133 dwarf2_psymtab::readin_p (struct objfile
*objfile
) const
9135 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9136 return per_objfile
->symtab_set_p (per_cu_data
);
9139 /* See psympriv.h. */
9142 dwarf2_psymtab::get_compunit_symtab (struct objfile
*objfile
) const
9144 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9145 return per_objfile
->get_symtab (per_cu_data
);
9148 /* Trivial hash function for die_info: the hash value of a DIE
9149 is its offset in .debug_info for this objfile. */
9152 die_hash (const void *item
)
9154 const struct die_info
*die
= (const struct die_info
*) item
;
9156 return to_underlying (die
->sect_off
);
9159 /* Trivial comparison function for die_info structures: two DIEs
9160 are equal if they have the same offset. */
9163 die_eq (const void *item_lhs
, const void *item_rhs
)
9165 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
9166 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
9168 return die_lhs
->sect_off
== die_rhs
->sect_off
;
9171 /* Load the DIEs associated with PER_CU into memory.
9173 In some cases, the caller, while reading partial symbols, will need to load
9174 the full symbols for the CU for some reason. It will already have a
9175 dwarf2_cu object for THIS_CU and pass it as EXISTING_CU, so it can be re-used
9176 rather than creating a new one. */
9179 load_full_comp_unit (dwarf2_per_cu_data
*this_cu
,
9180 dwarf2_per_objfile
*per_objfile
,
9181 dwarf2_cu
*existing_cu
,
9183 enum language pretend_language
)
9185 gdb_assert (! this_cu
->is_debug_types
);
9187 cutu_reader
reader (this_cu
, per_objfile
, NULL
, existing_cu
, skip_partial
);
9191 struct dwarf2_cu
*cu
= reader
.cu
;
9192 const gdb_byte
*info_ptr
= reader
.info_ptr
;
9194 gdb_assert (cu
->die_hash
== NULL
);
9196 htab_create_alloc_ex (cu
->header
.length
/ 12,
9200 &cu
->comp_unit_obstack
,
9201 hashtab_obstack_allocate
,
9202 dummy_obstack_deallocate
);
9204 if (reader
.comp_unit_die
->has_children
)
9205 reader
.comp_unit_die
->child
9206 = read_die_and_siblings (&reader
, reader
.info_ptr
,
9207 &info_ptr
, reader
.comp_unit_die
);
9208 cu
->dies
= reader
.comp_unit_die
;
9209 /* comp_unit_die is not stored in die_hash, no need. */
9211 /* We try not to read any attributes in this function, because not
9212 all CUs needed for references have been loaded yet, and symbol
9213 table processing isn't initialized. But we have to set the CU language,
9214 or we won't be able to build types correctly.
9215 Similarly, if we do not read the producer, we can not apply
9216 producer-specific interpretation. */
9217 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
9222 /* Add a DIE to the delayed physname list. */
9225 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
9226 const char *name
, struct die_info
*die
,
9227 struct dwarf2_cu
*cu
)
9229 struct delayed_method_info mi
;
9231 mi
.fnfield_index
= fnfield_index
;
9235 cu
->method_list
.push_back (mi
);
9238 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
9239 "const" / "volatile". If so, decrements LEN by the length of the
9240 modifier and return true. Otherwise return false. */
9244 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
9246 size_t mod_len
= sizeof (mod
) - 1;
9247 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
9255 /* Compute the physnames of any methods on the CU's method list.
9257 The computation of method physnames is delayed in order to avoid the
9258 (bad) condition that one of the method's formal parameters is of an as yet
9262 compute_delayed_physnames (struct dwarf2_cu
*cu
)
9264 /* Only C++ delays computing physnames. */
9265 if (cu
->method_list
.empty ())
9267 gdb_assert (cu
->language
== language_cplus
);
9269 for (const delayed_method_info
&mi
: cu
->method_list
)
9271 const char *physname
;
9272 struct fn_fieldlist
*fn_flp
9273 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9274 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9275 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9276 = physname
? physname
: "";
9278 /* Since there's no tag to indicate whether a method is a
9279 const/volatile overload, extract that information out of the
9281 if (physname
!= NULL
)
9283 size_t len
= strlen (physname
);
9287 if (physname
[len
] == ')') /* shortcut */
9289 else if (check_modifier (physname
, len
, " const"))
9290 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9291 else if (check_modifier (physname
, len
, " volatile"))
9292 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9299 /* The list is no longer needed. */
9300 cu
->method_list
.clear ();
9303 /* Go objects should be embedded in a DW_TAG_module DIE,
9304 and it's not clear if/how imported objects will appear.
9305 To keep Go support simple until that's worked out,
9306 go back through what we've read and create something usable.
9307 We could do this while processing each DIE, and feels kinda cleaner,
9308 but that way is more invasive.
9309 This is to, for example, allow the user to type "p var" or "b main"
9310 without having to specify the package name, and allow lookups
9311 of module.object to work in contexts that use the expression
9315 fixup_go_packaging (struct dwarf2_cu
*cu
)
9317 gdb::unique_xmalloc_ptr
<char> package_name
;
9318 struct pending
*list
;
9321 for (list
= *cu
->get_builder ()->get_global_symbols ();
9325 for (i
= 0; i
< list
->nsyms
; ++i
)
9327 struct symbol
*sym
= list
->symbol
[i
];
9329 if (sym
->language () == language_go
9330 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9332 gdb::unique_xmalloc_ptr
<char> this_package_name
9333 (go_symbol_package_name (sym
));
9335 if (this_package_name
== NULL
)
9337 if (package_name
== NULL
)
9338 package_name
= std::move (this_package_name
);
9341 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9342 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9343 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9344 (symbol_symtab (sym
) != NULL
9345 ? symtab_to_filename_for_display
9346 (symbol_symtab (sym
))
9347 : objfile_name (objfile
)),
9348 this_package_name
.get (), package_name
.get ());
9354 if (package_name
!= NULL
)
9356 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9357 const char *saved_package_name
= objfile
->intern (package_name
.get ());
9358 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9359 saved_package_name
);
9362 sym
= new (&objfile
->objfile_obstack
) symbol
;
9363 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9364 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9365 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9366 e.g., "main" finds the "main" module and not C's main(). */
9367 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9368 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9369 SYMBOL_TYPE (sym
) = type
;
9371 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9375 /* Allocate a fully-qualified name consisting of the two parts on the
9379 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9381 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9384 /* A helper that allocates a variant part to attach to a Rust enum
9385 type. OBSTACK is where the results should be allocated. TYPE is
9386 the type we're processing. DISCRIMINANT_INDEX is the index of the
9387 discriminant. It must be the index of one of the fields of TYPE,
9388 or -1 to mean there is no discriminant (univariant enum).
9389 DEFAULT_INDEX is the index of the default field; or -1 if there is
9390 no default. RANGES is indexed by "effective" field number (the
9391 field index, but omitting the discriminant and default fields) and
9392 must hold the discriminant values used by the variants. Note that
9393 RANGES must have a lifetime at least as long as OBSTACK -- either
9394 already allocated on it, or static. */
9397 alloc_rust_variant (struct obstack
*obstack
, struct type
*type
,
9398 int discriminant_index
, int default_index
,
9399 gdb::array_view
<discriminant_range
> ranges
)
9401 /* When DISCRIMINANT_INDEX == -1, we have a univariant enum. */
9402 gdb_assert (discriminant_index
== -1
9403 || (discriminant_index
>= 0
9404 && discriminant_index
< type
->num_fields ()));
9405 gdb_assert (default_index
== -1
9406 || (default_index
>= 0 && default_index
< type
->num_fields ()));
9408 /* We have one variant for each non-discriminant field. */
9409 int n_variants
= type
->num_fields ();
9410 if (discriminant_index
!= -1)
9413 variant
*variants
= new (obstack
) variant
[n_variants
];
9416 for (int i
= 0; i
< type
->num_fields (); ++i
)
9418 if (i
== discriminant_index
)
9421 variants
[var_idx
].first_field
= i
;
9422 variants
[var_idx
].last_field
= i
+ 1;
9424 /* The default field does not need a range, but other fields do.
9425 We skipped the discriminant above. */
9426 if (i
!= default_index
)
9428 variants
[var_idx
].discriminants
= ranges
.slice (range_idx
, 1);
9435 gdb_assert (range_idx
== ranges
.size ());
9436 gdb_assert (var_idx
== n_variants
);
9438 variant_part
*part
= new (obstack
) variant_part
;
9439 part
->discriminant_index
= discriminant_index
;
9440 /* If there is no discriminant, then whether it is signed is of no
9443 = (discriminant_index
== -1
9445 : type
->field (discriminant_index
).type ()->is_unsigned ());
9446 part
->variants
= gdb::array_view
<variant
> (variants
, n_variants
);
9448 void *storage
= obstack_alloc (obstack
, sizeof (gdb::array_view
<variant_part
>));
9449 gdb::array_view
<variant_part
> *prop_value
9450 = new (storage
) gdb::array_view
<variant_part
> (part
, 1);
9452 struct dynamic_prop prop
;
9453 prop
.set_variant_parts (prop_value
);
9455 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
9458 /* Some versions of rustc emitted enums in an unusual way.
9460 Ordinary enums were emitted as unions. The first element of each
9461 structure in the union was named "RUST$ENUM$DISR". This element
9462 held the discriminant.
9464 These versions of Rust also implemented the "non-zero"
9465 optimization. When the enum had two values, and one is empty and
9466 the other holds a pointer that cannot be zero, the pointer is used
9467 as the discriminant, with a zero value meaning the empty variant.
9468 Here, the union's first member is of the form
9469 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9470 where the fieldnos are the indices of the fields that should be
9471 traversed in order to find the field (which may be several fields deep)
9472 and the variantname is the name of the variant of the case when the
9475 This function recognizes whether TYPE is of one of these forms,
9476 and, if so, smashes it to be a variant type. */
9479 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9481 gdb_assert (type
->code () == TYPE_CODE_UNION
);
9483 /* We don't need to deal with empty enums. */
9484 if (type
->num_fields () == 0)
9487 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9488 if (type
->num_fields () == 1
9489 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9491 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9493 /* Decode the field name to find the offset of the
9495 ULONGEST bit_offset
= 0;
9496 struct type
*field_type
= type
->field (0).type ();
9497 while (name
[0] >= '0' && name
[0] <= '9')
9500 unsigned long index
= strtoul (name
, &tail
, 10);
9503 || index
>= field_type
->num_fields ()
9504 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9505 != FIELD_LOC_KIND_BITPOS
))
9507 complaint (_("Could not parse Rust enum encoding string \"%s\""
9509 TYPE_FIELD_NAME (type
, 0),
9510 objfile_name (objfile
));
9515 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9516 field_type
= field_type
->field (index
).type ();
9519 /* Smash this type to be a structure type. We have to do this
9520 because the type has already been recorded. */
9521 type
->set_code (TYPE_CODE_STRUCT
);
9522 type
->set_num_fields (3);
9523 /* Save the field we care about. */
9524 struct field saved_field
= type
->field (0);
9526 ((struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
)));
9528 /* Put the discriminant at index 0. */
9529 type
->field (0).set_type (field_type
);
9530 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9531 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9532 SET_FIELD_BITPOS (type
->field (0), bit_offset
);
9534 /* The order of fields doesn't really matter, so put the real
9535 field at index 1 and the data-less field at index 2. */
9536 type
->field (1) = saved_field
;
9537 TYPE_FIELD_NAME (type
, 1)
9538 = rust_last_path_segment (type
->field (1).type ()->name ());
9539 type
->field (1).type ()->set_name
9540 (rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9541 TYPE_FIELD_NAME (type
, 1)));
9543 const char *dataless_name
9544 = rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9546 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9548 type
->field (2).set_type (dataless_type
);
9549 /* NAME points into the original discriminant name, which
9550 already has the correct lifetime. */
9551 TYPE_FIELD_NAME (type
, 2) = name
;
9552 SET_FIELD_BITPOS (type
->field (2), 0);
9554 /* Indicate that this is a variant type. */
9555 static discriminant_range ranges
[1] = { { 0, 0 } };
9556 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1, ranges
);
9558 /* A union with a single anonymous field is probably an old-style
9560 else if (type
->num_fields () == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
9562 /* Smash this type to be a structure type. We have to do this
9563 because the type has already been recorded. */
9564 type
->set_code (TYPE_CODE_STRUCT
);
9566 struct type
*field_type
= type
->field (0).type ();
9567 const char *variant_name
9568 = rust_last_path_segment (field_type
->name ());
9569 TYPE_FIELD_NAME (type
, 0) = variant_name
;
9570 field_type
->set_name
9571 (rust_fully_qualify (&objfile
->objfile_obstack
,
9572 type
->name (), variant_name
));
9574 alloc_rust_variant (&objfile
->objfile_obstack
, type
, -1, 0, {});
9578 struct type
*disr_type
= nullptr;
9579 for (int i
= 0; i
< type
->num_fields (); ++i
)
9581 disr_type
= type
->field (i
).type ();
9583 if (disr_type
->code () != TYPE_CODE_STRUCT
)
9585 /* All fields of a true enum will be structs. */
9588 else if (disr_type
->num_fields () == 0)
9590 /* Could be data-less variant, so keep going. */
9591 disr_type
= nullptr;
9593 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9594 "RUST$ENUM$DISR") != 0)
9596 /* Not a Rust enum. */
9606 /* If we got here without a discriminant, then it's probably
9608 if (disr_type
== nullptr)
9611 /* Smash this type to be a structure type. We have to do this
9612 because the type has already been recorded. */
9613 type
->set_code (TYPE_CODE_STRUCT
);
9615 /* Make space for the discriminant field. */
9616 struct field
*disr_field
= &disr_type
->field (0);
9618 = (struct field
*) TYPE_ZALLOC (type
, ((type
->num_fields () + 1)
9619 * sizeof (struct field
)));
9620 memcpy (new_fields
+ 1, type
->fields (),
9621 type
->num_fields () * sizeof (struct field
));
9622 type
->set_fields (new_fields
);
9623 type
->set_num_fields (type
->num_fields () + 1);
9625 /* Install the discriminant at index 0 in the union. */
9626 type
->field (0) = *disr_field
;
9627 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9628 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9630 /* We need a way to find the correct discriminant given a
9631 variant name. For convenience we build a map here. */
9632 struct type
*enum_type
= disr_field
->type ();
9633 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9634 for (int i
= 0; i
< enum_type
->num_fields (); ++i
)
9636 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9639 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9640 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9644 int n_fields
= type
->num_fields ();
9645 /* We don't need a range entry for the discriminant, but we do
9646 need one for every other field, as there is no default
9648 discriminant_range
*ranges
= XOBNEWVEC (&objfile
->objfile_obstack
,
9651 /* Skip the discriminant here. */
9652 for (int i
= 1; i
< n_fields
; ++i
)
9654 /* Find the final word in the name of this variant's type.
9655 That name can be used to look up the correct
9657 const char *variant_name
9658 = rust_last_path_segment (type
->field (i
).type ()->name ());
9660 auto iter
= discriminant_map
.find (variant_name
);
9661 if (iter
!= discriminant_map
.end ())
9663 ranges
[i
- 1].low
= iter
->second
;
9664 ranges
[i
- 1].high
= iter
->second
;
9667 /* In Rust, each element should have the size of the
9669 TYPE_LENGTH (type
->field (i
).type ()) = TYPE_LENGTH (type
);
9671 /* Remove the discriminant field, if it exists. */
9672 struct type
*sub_type
= type
->field (i
).type ();
9673 if (sub_type
->num_fields () > 0)
9675 sub_type
->set_num_fields (sub_type
->num_fields () - 1);
9676 sub_type
->set_fields (sub_type
->fields () + 1);
9678 TYPE_FIELD_NAME (type
, i
) = variant_name
;
9680 (rust_fully_qualify (&objfile
->objfile_obstack
,
9681 type
->name (), variant_name
));
9684 /* Indicate that this is a variant type. */
9685 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, -1,
9686 gdb::array_view
<discriminant_range
> (ranges
,
9691 /* Rewrite some Rust unions to be structures with variants parts. */
9694 rust_union_quirks (struct dwarf2_cu
*cu
)
9696 gdb_assert (cu
->language
== language_rust
);
9697 for (type
*type_
: cu
->rust_unions
)
9698 quirk_rust_enum (type_
, cu
->per_objfile
->objfile
);
9699 /* We don't need this any more. */
9700 cu
->rust_unions
.clear ();
9705 type_unit_group_unshareable
*
9706 dwarf2_per_objfile::get_type_unit_group_unshareable (type_unit_group
*tu_group
)
9708 auto iter
= this->m_type_units
.find (tu_group
);
9709 if (iter
!= this->m_type_units
.end ())
9710 return iter
->second
.get ();
9712 type_unit_group_unshareable_up
uniq (new type_unit_group_unshareable
);
9713 type_unit_group_unshareable
*result
= uniq
.get ();
9714 this->m_type_units
[tu_group
] = std::move (uniq
);
9719 dwarf2_per_objfile::get_type_for_signatured_type
9720 (signatured_type
*sig_type
) const
9722 auto iter
= this->m_type_map
.find (sig_type
);
9723 if (iter
== this->m_type_map
.end ())
9726 return iter
->second
;
9729 void dwarf2_per_objfile::set_type_for_signatured_type
9730 (signatured_type
*sig_type
, struct type
*type
)
9732 gdb_assert (this->m_type_map
.find (sig_type
) == this->m_type_map
.end ());
9734 this->m_type_map
[sig_type
] = type
;
9737 /* A helper function for computing the list of all symbol tables
9738 included by PER_CU. */
9741 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9742 htab_t all_children
, htab_t all_type_symtabs
,
9743 dwarf2_per_cu_data
*per_cu
,
9744 dwarf2_per_objfile
*per_objfile
,
9745 struct compunit_symtab
*immediate_parent
)
9747 void **slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9750 /* This inclusion and its children have been processed. */
9756 /* Only add a CU if it has a symbol table. */
9757 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9760 /* If this is a type unit only add its symbol table if we haven't
9761 seen it yet (type unit per_cu's can share symtabs). */
9762 if (per_cu
->is_debug_types
)
9764 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9768 result
->push_back (cust
);
9769 if (cust
->user
== NULL
)
9770 cust
->user
= immediate_parent
;
9775 result
->push_back (cust
);
9776 if (cust
->user
== NULL
)
9777 cust
->user
= immediate_parent
;
9781 if (!per_cu
->imported_symtabs_empty ())
9782 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9784 recursively_compute_inclusions (result
, all_children
,
9785 all_type_symtabs
, ptr
, per_objfile
,
9790 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9794 compute_compunit_symtab_includes (dwarf2_per_cu_data
*per_cu
,
9795 dwarf2_per_objfile
*per_objfile
)
9797 gdb_assert (! per_cu
->is_debug_types
);
9799 if (!per_cu
->imported_symtabs_empty ())
9802 std::vector
<compunit_symtab
*> result_symtabs
;
9803 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9805 /* If we don't have a symtab, we can just skip this case. */
9809 htab_up
all_children (htab_create_alloc (1, htab_hash_pointer
,
9811 NULL
, xcalloc
, xfree
));
9812 htab_up
all_type_symtabs (htab_create_alloc (1, htab_hash_pointer
,
9814 NULL
, xcalloc
, xfree
));
9816 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9818 recursively_compute_inclusions (&result_symtabs
, all_children
.get (),
9819 all_type_symtabs
.get (), ptr
,
9823 /* Now we have a transitive closure of all the included symtabs. */
9824 len
= result_symtabs
.size ();
9826 = XOBNEWVEC (&per_objfile
->objfile
->objfile_obstack
,
9827 struct compunit_symtab
*, len
+ 1);
9828 memcpy (cust
->includes
, result_symtabs
.data (),
9829 len
* sizeof (compunit_symtab
*));
9830 cust
->includes
[len
] = NULL
;
9834 /* Compute the 'includes' field for the symtabs of all the CUs we just
9838 process_cu_includes (dwarf2_per_objfile
*per_objfile
)
9840 for (dwarf2_per_cu_data
*iter
: per_objfile
->per_bfd
->just_read_cus
)
9842 if (! iter
->is_debug_types
)
9843 compute_compunit_symtab_includes (iter
, per_objfile
);
9846 per_objfile
->per_bfd
->just_read_cus
.clear ();
9849 /* Generate full symbol information for CU, whose DIEs have
9850 already been loaded into memory. */
9853 process_full_comp_unit (dwarf2_cu
*cu
, enum language pretend_language
)
9855 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9856 struct objfile
*objfile
= per_objfile
->objfile
;
9857 struct gdbarch
*gdbarch
= objfile
->arch ();
9858 CORE_ADDR lowpc
, highpc
;
9859 struct compunit_symtab
*cust
;
9861 struct block
*static_block
;
9864 baseaddr
= objfile
->text_section_offset ();
9866 /* Clear the list here in case something was left over. */
9867 cu
->method_list
.clear ();
9869 cu
->language
= pretend_language
;
9870 cu
->language_defn
= language_def (cu
->language
);
9872 dwarf2_find_base_address (cu
->dies
, cu
);
9874 /* Do line number decoding in read_file_scope () */
9875 process_die (cu
->dies
, cu
);
9877 /* For now fudge the Go package. */
9878 if (cu
->language
== language_go
)
9879 fixup_go_packaging (cu
);
9881 /* Now that we have processed all the DIEs in the CU, all the types
9882 should be complete, and it should now be safe to compute all of the
9884 compute_delayed_physnames (cu
);
9886 if (cu
->language
== language_rust
)
9887 rust_union_quirks (cu
);
9889 /* Some compilers don't define a DW_AT_high_pc attribute for the
9890 compilation unit. If the DW_AT_high_pc is missing, synthesize
9891 it, by scanning the DIE's below the compilation unit. */
9892 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9894 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9895 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
9897 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9898 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9899 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9900 addrmap to help ensure it has an accurate map of pc values belonging to
9902 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9904 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
9905 SECT_OFF_TEXT (objfile
),
9910 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9912 /* Set symtab language to language from DW_AT_language. If the
9913 compilation is from a C file generated by language preprocessors, do
9914 not set the language if it was already deduced by start_subfile. */
9915 if (!(cu
->language
== language_c
9916 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
9917 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9919 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9920 produce DW_AT_location with location lists but it can be possibly
9921 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9922 there were bugs in prologue debug info, fixed later in GCC-4.5
9923 by "unwind info for epilogues" patch (which is not directly related).
9925 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9926 needed, it would be wrong due to missing DW_AT_producer there.
9928 Still one can confuse GDB by using non-standard GCC compilation
9929 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9931 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9932 cust
->locations_valid
= 1;
9934 if (gcc_4_minor
>= 5)
9935 cust
->epilogue_unwind_valid
= 1;
9937 cust
->call_site_htab
= cu
->call_site_htab
;
9940 per_objfile
->set_symtab (cu
->per_cu
, cust
);
9942 /* Push it for inclusion processing later. */
9943 per_objfile
->per_bfd
->just_read_cus
.push_back (cu
->per_cu
);
9945 /* Not needed any more. */
9946 cu
->reset_builder ();
9949 /* Generate full symbol information for type unit CU, whose DIEs have
9950 already been loaded into memory. */
9953 process_full_type_unit (dwarf2_cu
*cu
,
9954 enum language pretend_language
)
9956 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9957 struct objfile
*objfile
= per_objfile
->objfile
;
9958 struct compunit_symtab
*cust
;
9959 struct signatured_type
*sig_type
;
9961 gdb_assert (cu
->per_cu
->is_debug_types
);
9962 sig_type
= (struct signatured_type
*) cu
->per_cu
;
9964 /* Clear the list here in case something was left over. */
9965 cu
->method_list
.clear ();
9967 cu
->language
= pretend_language
;
9968 cu
->language_defn
= language_def (cu
->language
);
9970 /* The symbol tables are set up in read_type_unit_scope. */
9971 process_die (cu
->dies
, cu
);
9973 /* For now fudge the Go package. */
9974 if (cu
->language
== language_go
)
9975 fixup_go_packaging (cu
);
9977 /* Now that we have processed all the DIEs in the CU, all the types
9978 should be complete, and it should now be safe to compute all of the
9980 compute_delayed_physnames (cu
);
9982 if (cu
->language
== language_rust
)
9983 rust_union_quirks (cu
);
9985 /* TUs share symbol tables.
9986 If this is the first TU to use this symtab, complete the construction
9987 of it with end_expandable_symtab. Otherwise, complete the addition of
9988 this TU's symbols to the existing symtab. */
9989 type_unit_group_unshareable
*tug_unshare
=
9990 per_objfile
->get_type_unit_group_unshareable (sig_type
->type_unit_group
);
9991 if (tug_unshare
->compunit_symtab
== NULL
)
9993 buildsym_compunit
*builder
= cu
->get_builder ();
9994 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
9995 tug_unshare
->compunit_symtab
= cust
;
9999 /* Set symtab language to language from DW_AT_language. If the
10000 compilation is from a C file generated by language preprocessors,
10001 do not set the language if it was already deduced by
10003 if (!(cu
->language
== language_c
10004 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
10005 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10010 cu
->get_builder ()->augment_type_symtab ();
10011 cust
= tug_unshare
->compunit_symtab
;
10014 per_objfile
->set_symtab (cu
->per_cu
, cust
);
10016 /* Not needed any more. */
10017 cu
->reset_builder ();
10020 /* Process an imported unit DIE. */
10023 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10025 struct attribute
*attr
;
10027 /* For now we don't handle imported units in type units. */
10028 if (cu
->per_cu
->is_debug_types
)
10030 error (_("Dwarf Error: DW_TAG_imported_unit is not"
10031 " supported in type units [in module %s]"),
10032 objfile_name (cu
->per_objfile
->objfile
));
10035 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10038 sect_offset sect_off
= attr
->get_ref_die_offset ();
10039 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
10040 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10041 dwarf2_per_cu_data
*per_cu
10042 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
, per_objfile
);
10044 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
10045 into another compilation unit, at root level. Regard this as a hint,
10047 if (die
->parent
&& die
->parent
->parent
== NULL
10048 && per_cu
->unit_type
== DW_UT_compile
10049 && per_cu
->lang
== language_cplus
)
10052 /* If necessary, add it to the queue and load its DIEs. */
10053 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->language
))
10054 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
10055 false, cu
->language
);
10057 cu
->per_cu
->imported_symtabs_push (per_cu
);
10061 /* RAII object that represents a process_die scope: i.e.,
10062 starts/finishes processing a DIE. */
10063 class process_die_scope
10066 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
10067 : m_die (die
), m_cu (cu
)
10069 /* We should only be processing DIEs not already in process. */
10070 gdb_assert (!m_die
->in_process
);
10071 m_die
->in_process
= true;
10074 ~process_die_scope ()
10076 m_die
->in_process
= false;
10078 /* If we're done processing the DIE for the CU that owns the line
10079 header, we don't need the line header anymore. */
10080 if (m_cu
->line_header_die_owner
== m_die
)
10082 delete m_cu
->line_header
;
10083 m_cu
->line_header
= NULL
;
10084 m_cu
->line_header_die_owner
= NULL
;
10093 /* Process a die and its children. */
10096 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10098 process_die_scope
scope (die
, cu
);
10102 case DW_TAG_padding
:
10104 case DW_TAG_compile_unit
:
10105 case DW_TAG_partial_unit
:
10106 read_file_scope (die
, cu
);
10108 case DW_TAG_type_unit
:
10109 read_type_unit_scope (die
, cu
);
10111 case DW_TAG_subprogram
:
10112 /* Nested subprograms in Fortran get a prefix. */
10113 if (cu
->language
== language_fortran
10114 && die
->parent
!= NULL
10115 && die
->parent
->tag
== DW_TAG_subprogram
)
10116 cu
->processing_has_namespace_info
= true;
10117 /* Fall through. */
10118 case DW_TAG_inlined_subroutine
:
10119 read_func_scope (die
, cu
);
10121 case DW_TAG_lexical_block
:
10122 case DW_TAG_try_block
:
10123 case DW_TAG_catch_block
:
10124 read_lexical_block_scope (die
, cu
);
10126 case DW_TAG_call_site
:
10127 case DW_TAG_GNU_call_site
:
10128 read_call_site_scope (die
, cu
);
10130 case DW_TAG_class_type
:
10131 case DW_TAG_interface_type
:
10132 case DW_TAG_structure_type
:
10133 case DW_TAG_union_type
:
10134 process_structure_scope (die
, cu
);
10136 case DW_TAG_enumeration_type
:
10137 process_enumeration_scope (die
, cu
);
10140 /* These dies have a type, but processing them does not create
10141 a symbol or recurse to process the children. Therefore we can
10142 read them on-demand through read_type_die. */
10143 case DW_TAG_subroutine_type
:
10144 case DW_TAG_set_type
:
10145 case DW_TAG_pointer_type
:
10146 case DW_TAG_ptr_to_member_type
:
10147 case DW_TAG_reference_type
:
10148 case DW_TAG_rvalue_reference_type
:
10149 case DW_TAG_string_type
:
10152 case DW_TAG_array_type
:
10153 /* We only need to handle this case for Ada -- in other
10154 languages, it's normal for the compiler to emit a typedef
10156 if (cu
->language
!= language_ada
)
10159 case DW_TAG_base_type
:
10160 case DW_TAG_subrange_type
:
10161 case DW_TAG_typedef
:
10162 /* Add a typedef symbol for the type definition, if it has a
10164 new_symbol (die
, read_type_die (die
, cu
), cu
);
10166 case DW_TAG_common_block
:
10167 read_common_block (die
, cu
);
10169 case DW_TAG_common_inclusion
:
10171 case DW_TAG_namespace
:
10172 cu
->processing_has_namespace_info
= true;
10173 read_namespace (die
, cu
);
10175 case DW_TAG_module
:
10176 cu
->processing_has_namespace_info
= true;
10177 read_module (die
, cu
);
10179 case DW_TAG_imported_declaration
:
10180 cu
->processing_has_namespace_info
= true;
10181 if (read_namespace_alias (die
, cu
))
10183 /* The declaration is not a global namespace alias. */
10184 /* Fall through. */
10185 case DW_TAG_imported_module
:
10186 cu
->processing_has_namespace_info
= true;
10187 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
10188 || cu
->language
!= language_fortran
))
10189 complaint (_("Tag '%s' has unexpected children"),
10190 dwarf_tag_name (die
->tag
));
10191 read_import_statement (die
, cu
);
10194 case DW_TAG_imported_unit
:
10195 process_imported_unit_die (die
, cu
);
10198 case DW_TAG_variable
:
10199 read_variable (die
, cu
);
10203 new_symbol (die
, NULL
, cu
);
10208 /* DWARF name computation. */
10210 /* A helper function for dwarf2_compute_name which determines whether DIE
10211 needs to have the name of the scope prepended to the name listed in the
10215 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10217 struct attribute
*attr
;
10221 case DW_TAG_namespace
:
10222 case DW_TAG_typedef
:
10223 case DW_TAG_class_type
:
10224 case DW_TAG_interface_type
:
10225 case DW_TAG_structure_type
:
10226 case DW_TAG_union_type
:
10227 case DW_TAG_enumeration_type
:
10228 case DW_TAG_enumerator
:
10229 case DW_TAG_subprogram
:
10230 case DW_TAG_inlined_subroutine
:
10231 case DW_TAG_member
:
10232 case DW_TAG_imported_declaration
:
10235 case DW_TAG_variable
:
10236 case DW_TAG_constant
:
10237 /* We only need to prefix "globally" visible variables. These include
10238 any variable marked with DW_AT_external or any variable that
10239 lives in a namespace. [Variables in anonymous namespaces
10240 require prefixing, but they are not DW_AT_external.] */
10242 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
10244 struct dwarf2_cu
*spec_cu
= cu
;
10246 return die_needs_namespace (die_specification (die
, &spec_cu
),
10250 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10251 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
10252 && die
->parent
->tag
!= DW_TAG_module
)
10254 /* A variable in a lexical block of some kind does not need a
10255 namespace, even though in C++ such variables may be external
10256 and have a mangled name. */
10257 if (die
->parent
->tag
== DW_TAG_lexical_block
10258 || die
->parent
->tag
== DW_TAG_try_block
10259 || die
->parent
->tag
== DW_TAG_catch_block
10260 || die
->parent
->tag
== DW_TAG_subprogram
)
10269 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
10270 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10271 defined for the given DIE. */
10273 static struct attribute
*
10274 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
10276 struct attribute
*attr
;
10278 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
10280 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10285 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10286 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10287 defined for the given DIE. */
10289 static const char *
10290 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10292 const char *linkage_name
;
10294 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10295 if (linkage_name
== NULL
)
10296 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10298 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
10299 See https://github.com/rust-lang/rust/issues/32925. */
10300 if (cu
->language
== language_rust
&& linkage_name
!= NULL
10301 && strchr (linkage_name
, '{') != NULL
)
10302 linkage_name
= NULL
;
10304 return linkage_name
;
10307 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10308 compute the physname for the object, which include a method's:
10309 - formal parameters (C++),
10310 - receiver type (Go),
10312 The term "physname" is a bit confusing.
10313 For C++, for example, it is the demangled name.
10314 For Go, for example, it's the mangled name.
10316 For Ada, return the DIE's linkage name rather than the fully qualified
10317 name. PHYSNAME is ignored..
10319 The result is allocated on the objfile->per_bfd's obstack and
10322 static const char *
10323 dwarf2_compute_name (const char *name
,
10324 struct die_info
*die
, struct dwarf2_cu
*cu
,
10327 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10330 name
= dwarf2_name (die
, cu
);
10332 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10333 but otherwise compute it by typename_concat inside GDB.
10334 FIXME: Actually this is not really true, or at least not always true.
10335 It's all very confusing. compute_and_set_names doesn't try to demangle
10336 Fortran names because there is no mangling standard. So new_symbol
10337 will set the demangled name to the result of dwarf2_full_name, and it is
10338 the demangled name that GDB uses if it exists. */
10339 if (cu
->language
== language_ada
10340 || (cu
->language
== language_fortran
&& physname
))
10342 /* For Ada unit, we prefer the linkage name over the name, as
10343 the former contains the exported name, which the user expects
10344 to be able to reference. Ideally, we want the user to be able
10345 to reference this entity using either natural or linkage name,
10346 but we haven't started looking at this enhancement yet. */
10347 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10349 if (linkage_name
!= NULL
)
10350 return linkage_name
;
10353 /* These are the only languages we know how to qualify names in. */
10355 && (cu
->language
== language_cplus
10356 || cu
->language
== language_fortran
|| cu
->language
== language_d
10357 || cu
->language
== language_rust
))
10359 if (die_needs_namespace (die
, cu
))
10361 const char *prefix
;
10362 const char *canonical_name
= NULL
;
10366 prefix
= determine_prefix (die
, cu
);
10367 if (*prefix
!= '\0')
10369 gdb::unique_xmalloc_ptr
<char> prefixed_name
10370 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10372 buf
.puts (prefixed_name
.get ());
10377 /* Template parameters may be specified in the DIE's DW_AT_name, or
10378 as children with DW_TAG_template_type_param or
10379 DW_TAG_value_type_param. If the latter, add them to the name
10380 here. If the name already has template parameters, then
10381 skip this step; some versions of GCC emit both, and
10382 it is more efficient to use the pre-computed name.
10384 Something to keep in mind about this process: it is very
10385 unlikely, or in some cases downright impossible, to produce
10386 something that will match the mangled name of a function.
10387 If the definition of the function has the same debug info,
10388 we should be able to match up with it anyway. But fallbacks
10389 using the minimal symbol, for instance to find a method
10390 implemented in a stripped copy of libstdc++, will not work.
10391 If we do not have debug info for the definition, we will have to
10392 match them up some other way.
10394 When we do name matching there is a related problem with function
10395 templates; two instantiated function templates are allowed to
10396 differ only by their return types, which we do not add here. */
10398 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10400 struct attribute
*attr
;
10401 struct die_info
*child
;
10403 const language_defn
*cplus_lang
= language_def (cu
->language
);
10405 die
->building_fullname
= 1;
10407 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10411 const gdb_byte
*bytes
;
10412 struct dwarf2_locexpr_baton
*baton
;
10415 if (child
->tag
!= DW_TAG_template_type_param
10416 && child
->tag
!= DW_TAG_template_value_param
)
10427 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10430 complaint (_("template parameter missing DW_AT_type"));
10431 buf
.puts ("UNKNOWN_TYPE");
10434 type
= die_type (child
, cu
);
10436 if (child
->tag
== DW_TAG_template_type_param
)
10438 cplus_lang
->print_type (type
, "", &buf
, -1, 0,
10439 &type_print_raw_options
);
10443 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10446 complaint (_("template parameter missing "
10447 "DW_AT_const_value"));
10448 buf
.puts ("UNKNOWN_VALUE");
10452 dwarf2_const_value_attr (attr
, type
, name
,
10453 &cu
->comp_unit_obstack
, cu
,
10454 &value
, &bytes
, &baton
);
10456 if (type
->has_no_signedness ())
10457 /* GDB prints characters as NUMBER 'CHAR'. If that's
10458 changed, this can use value_print instead. */
10459 cplus_lang
->printchar (value
, type
, &buf
);
10462 struct value_print_options opts
;
10465 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10469 baton
->per_objfile
);
10470 else if (bytes
!= NULL
)
10472 v
= allocate_value (type
);
10473 memcpy (value_contents_writeable (v
), bytes
,
10474 TYPE_LENGTH (type
));
10477 v
= value_from_longest (type
, value
);
10479 /* Specify decimal so that we do not depend on
10481 get_formatted_print_options (&opts
, 'd');
10483 value_print (v
, &buf
, &opts
);
10488 die
->building_fullname
= 0;
10492 /* Close the argument list, with a space if necessary
10493 (nested templates). */
10494 if (!buf
.empty () && buf
.string ().back () == '>')
10501 /* For C++ methods, append formal parameter type
10502 information, if PHYSNAME. */
10504 if (physname
&& die
->tag
== DW_TAG_subprogram
10505 && cu
->language
== language_cplus
)
10507 struct type
*type
= read_type_die (die
, cu
);
10509 c_type_print_args (type
, &buf
, 1, cu
->language
,
10510 &type_print_raw_options
);
10512 if (cu
->language
== language_cplus
)
10514 /* Assume that an artificial first parameter is
10515 "this", but do not crash if it is not. RealView
10516 marks unnamed (and thus unused) parameters as
10517 artificial; there is no way to differentiate
10519 if (type
->num_fields () > 0
10520 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10521 && type
->field (0).type ()->code () == TYPE_CODE_PTR
10522 && TYPE_CONST (TYPE_TARGET_TYPE (type
->field (0).type ())))
10523 buf
.puts (" const");
10527 const std::string
&intermediate_name
= buf
.string ();
10529 if (cu
->language
== language_cplus
)
10531 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10534 /* If we only computed INTERMEDIATE_NAME, or if
10535 INTERMEDIATE_NAME is already canonical, then we need to
10537 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10538 name
= objfile
->intern (intermediate_name
);
10540 name
= canonical_name
;
10547 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10548 If scope qualifiers are appropriate they will be added. The result
10549 will be allocated on the storage_obstack, or NULL if the DIE does
10550 not have a name. NAME may either be from a previous call to
10551 dwarf2_name or NULL.
10553 The output string will be canonicalized (if C++). */
10555 static const char *
10556 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10558 return dwarf2_compute_name (name
, die
, cu
, 0);
10561 /* Construct a physname for the given DIE in CU. NAME may either be
10562 from a previous call to dwarf2_name or NULL. The result will be
10563 allocated on the objfile_objstack or NULL if the DIE does not have a
10566 The output string will be canonicalized (if C++). */
10568 static const char *
10569 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10571 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10572 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10575 /* In this case dwarf2_compute_name is just a shortcut not building anything
10577 if (!die_needs_namespace (die
, cu
))
10578 return dwarf2_compute_name (name
, die
, cu
, 1);
10580 if (cu
->language
!= language_rust
)
10581 mangled
= dw2_linkage_name (die
, cu
);
10583 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10585 gdb::unique_xmalloc_ptr
<char> demangled
;
10586 if (mangled
!= NULL
)
10589 if (language_def (cu
->language
)->store_sym_names_in_linkage_form_p ())
10591 /* Do nothing (do not demangle the symbol name). */
10595 /* Use DMGL_RET_DROP for C++ template functions to suppress
10596 their return type. It is easier for GDB users to search
10597 for such functions as `name(params)' than `long name(params)'.
10598 In such case the minimal symbol names do not match the full
10599 symbol names but for template functions there is never a need
10600 to look up their definition from their declaration so
10601 the only disadvantage remains the minimal symbol variant
10602 `long name(params)' does not have the proper inferior type. */
10603 demangled
.reset (gdb_demangle (mangled
,
10604 (DMGL_PARAMS
| DMGL_ANSI
10605 | DMGL_RET_DROP
)));
10608 canon
= demangled
.get ();
10616 if (canon
== NULL
|| check_physname
)
10618 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10620 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10622 /* It may not mean a bug in GDB. The compiler could also
10623 compute DW_AT_linkage_name incorrectly. But in such case
10624 GDB would need to be bug-to-bug compatible. */
10626 complaint (_("Computed physname <%s> does not match demangled <%s> "
10627 "(from linkage <%s>) - DIE at %s [in module %s]"),
10628 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10629 objfile_name (objfile
));
10631 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10632 is available here - over computed PHYSNAME. It is safer
10633 against both buggy GDB and buggy compilers. */
10647 retval
= objfile
->intern (retval
);
10652 /* Inspect DIE in CU for a namespace alias. If one exists, record
10653 a new symbol for it.
10655 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10658 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10660 struct attribute
*attr
;
10662 /* If the die does not have a name, this is not a namespace
10664 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10668 struct die_info
*d
= die
;
10669 struct dwarf2_cu
*imported_cu
= cu
;
10671 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10672 keep inspecting DIEs until we hit the underlying import. */
10673 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10674 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10676 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10680 d
= follow_die_ref (d
, attr
, &imported_cu
);
10681 if (d
->tag
!= DW_TAG_imported_declaration
)
10685 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10687 complaint (_("DIE at %s has too many recursively imported "
10688 "declarations"), sect_offset_str (d
->sect_off
));
10695 sect_offset sect_off
= attr
->get_ref_die_offset ();
10697 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, cu
->per_objfile
);
10698 if (type
!= NULL
&& type
->code () == TYPE_CODE_NAMESPACE
)
10700 /* This declaration is a global namespace alias. Add
10701 a symbol for it whose type is the aliased namespace. */
10702 new_symbol (die
, type
, cu
);
10711 /* Return the using directives repository (global or local?) to use in the
10712 current context for CU.
10714 For Ada, imported declarations can materialize renamings, which *may* be
10715 global. However it is impossible (for now?) in DWARF to distinguish
10716 "external" imported declarations and "static" ones. As all imported
10717 declarations seem to be static in all other languages, make them all CU-wide
10718 global only in Ada. */
10720 static struct using_direct
**
10721 using_directives (struct dwarf2_cu
*cu
)
10723 if (cu
->language
== language_ada
10724 && cu
->get_builder ()->outermost_context_p ())
10725 return cu
->get_builder ()->get_global_using_directives ();
10727 return cu
->get_builder ()->get_local_using_directives ();
10730 /* Read the import statement specified by the given die and record it. */
10733 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10735 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10736 struct attribute
*import_attr
;
10737 struct die_info
*imported_die
, *child_die
;
10738 struct dwarf2_cu
*imported_cu
;
10739 const char *imported_name
;
10740 const char *imported_name_prefix
;
10741 const char *canonical_name
;
10742 const char *import_alias
;
10743 const char *imported_declaration
= NULL
;
10744 const char *import_prefix
;
10745 std::vector
<const char *> excludes
;
10747 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10748 if (import_attr
== NULL
)
10750 complaint (_("Tag '%s' has no DW_AT_import"),
10751 dwarf_tag_name (die
->tag
));
10756 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10757 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10758 if (imported_name
== NULL
)
10760 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10762 The import in the following code:
10776 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10777 <52> DW_AT_decl_file : 1
10778 <53> DW_AT_decl_line : 6
10779 <54> DW_AT_import : <0x75>
10780 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10781 <59> DW_AT_name : B
10782 <5b> DW_AT_decl_file : 1
10783 <5c> DW_AT_decl_line : 2
10784 <5d> DW_AT_type : <0x6e>
10786 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10787 <76> DW_AT_byte_size : 4
10788 <77> DW_AT_encoding : 5 (signed)
10790 imports the wrong die ( 0x75 instead of 0x58 ).
10791 This case will be ignored until the gcc bug is fixed. */
10795 /* Figure out the local name after import. */
10796 import_alias
= dwarf2_name (die
, cu
);
10798 /* Figure out where the statement is being imported to. */
10799 import_prefix
= determine_prefix (die
, cu
);
10801 /* Figure out what the scope of the imported die is and prepend it
10802 to the name of the imported die. */
10803 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10805 if (imported_die
->tag
!= DW_TAG_namespace
10806 && imported_die
->tag
!= DW_TAG_module
)
10808 imported_declaration
= imported_name
;
10809 canonical_name
= imported_name_prefix
;
10811 else if (strlen (imported_name_prefix
) > 0)
10812 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10813 imported_name_prefix
,
10814 (cu
->language
== language_d
? "." : "::"),
10815 imported_name
, (char *) NULL
);
10817 canonical_name
= imported_name
;
10819 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
10820 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10821 child_die
= child_die
->sibling
)
10823 /* DWARF-4: A Fortran use statement with a “rename list” may be
10824 represented by an imported module entry with an import attribute
10825 referring to the module and owned entries corresponding to those
10826 entities that are renamed as part of being imported. */
10828 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10830 complaint (_("child DW_TAG_imported_declaration expected "
10831 "- DIE at %s [in module %s]"),
10832 sect_offset_str (child_die
->sect_off
),
10833 objfile_name (objfile
));
10837 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10838 if (import_attr
== NULL
)
10840 complaint (_("Tag '%s' has no DW_AT_import"),
10841 dwarf_tag_name (child_die
->tag
));
10846 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10848 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10849 if (imported_name
== NULL
)
10851 complaint (_("child DW_TAG_imported_declaration has unknown "
10852 "imported name - DIE at %s [in module %s]"),
10853 sect_offset_str (child_die
->sect_off
),
10854 objfile_name (objfile
));
10858 excludes
.push_back (imported_name
);
10860 process_die (child_die
, cu
);
10863 add_using_directive (using_directives (cu
),
10867 imported_declaration
,
10870 &objfile
->objfile_obstack
);
10873 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10874 types, but gives them a size of zero. Starting with version 14,
10875 ICC is compatible with GCC. */
10878 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10880 if (!cu
->checked_producer
)
10881 check_producer (cu
);
10883 return cu
->producer_is_icc_lt_14
;
10886 /* ICC generates a DW_AT_type for C void functions. This was observed on
10887 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10888 which says that void functions should not have a DW_AT_type. */
10891 producer_is_icc (struct dwarf2_cu
*cu
)
10893 if (!cu
->checked_producer
)
10894 check_producer (cu
);
10896 return cu
->producer_is_icc
;
10899 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10900 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10901 this, it was first present in GCC release 4.3.0. */
10904 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10906 if (!cu
->checked_producer
)
10907 check_producer (cu
);
10909 return cu
->producer_is_gcc_lt_4_3
;
10912 static file_and_directory
10913 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10915 file_and_directory res
;
10917 /* Find the filename. Do not use dwarf2_name here, since the filename
10918 is not a source language identifier. */
10919 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
10920 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
10922 if (res
.comp_dir
== NULL
10923 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
10924 && IS_ABSOLUTE_PATH (res
.name
))
10926 res
.comp_dir_storage
= ldirname (res
.name
);
10927 if (!res
.comp_dir_storage
.empty ())
10928 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
10930 if (res
.comp_dir
!= NULL
)
10932 /* Irix 6.2 native cc prepends <machine>.: to the compilation
10933 directory, get rid of it. */
10934 const char *cp
= strchr (res
.comp_dir
, ':');
10936 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
10937 res
.comp_dir
= cp
+ 1;
10940 if (res
.name
== NULL
)
10941 res
.name
= "<unknown>";
10946 /* Handle DW_AT_stmt_list for a compilation unit.
10947 DIE is the DW_TAG_compile_unit die for CU.
10948 COMP_DIR is the compilation directory. LOWPC is passed to
10949 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
10952 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
10953 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
10955 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10956 struct attribute
*attr
;
10957 struct line_header line_header_local
;
10958 hashval_t line_header_local_hash
;
10960 int decode_mapping
;
10962 gdb_assert (! cu
->per_cu
->is_debug_types
);
10964 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
10965 if (attr
== NULL
|| !attr
->form_is_unsigned ())
10968 sect_offset line_offset
= (sect_offset
) attr
->as_unsigned ();
10970 /* The line header hash table is only created if needed (it exists to
10971 prevent redundant reading of the line table for partial_units).
10972 If we're given a partial_unit, we'll need it. If we're given a
10973 compile_unit, then use the line header hash table if it's already
10974 created, but don't create one just yet. */
10976 if (per_objfile
->line_header_hash
== NULL
10977 && die
->tag
== DW_TAG_partial_unit
)
10979 per_objfile
->line_header_hash
10980 .reset (htab_create_alloc (127, line_header_hash_voidp
,
10981 line_header_eq_voidp
,
10982 free_line_header_voidp
,
10986 line_header_local
.sect_off
= line_offset
;
10987 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
10988 line_header_local_hash
= line_header_hash (&line_header_local
);
10989 if (per_objfile
->line_header_hash
!= NULL
)
10991 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
10992 &line_header_local
,
10993 line_header_local_hash
, NO_INSERT
);
10995 /* For DW_TAG_compile_unit we need info like symtab::linetable which
10996 is not present in *SLOT (since if there is something in *SLOT then
10997 it will be for a partial_unit). */
10998 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
11000 gdb_assert (*slot
!= NULL
);
11001 cu
->line_header
= (struct line_header
*) *slot
;
11006 /* dwarf_decode_line_header does not yet provide sufficient information.
11007 We always have to call also dwarf_decode_lines for it. */
11008 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
11012 cu
->line_header
= lh
.release ();
11013 cu
->line_header_die_owner
= die
;
11015 if (per_objfile
->line_header_hash
== NULL
)
11019 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
11020 &line_header_local
,
11021 line_header_local_hash
, INSERT
);
11022 gdb_assert (slot
!= NULL
);
11024 if (slot
!= NULL
&& *slot
== NULL
)
11026 /* This newly decoded line number information unit will be owned
11027 by line_header_hash hash table. */
11028 *slot
= cu
->line_header
;
11029 cu
->line_header_die_owner
= NULL
;
11033 /* We cannot free any current entry in (*slot) as that struct line_header
11034 may be already used by multiple CUs. Create only temporary decoded
11035 line_header for this CU - it may happen at most once for each line
11036 number information unit. And if we're not using line_header_hash
11037 then this is what we want as well. */
11038 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
11040 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
11041 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
11046 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
11049 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11051 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
11052 struct objfile
*objfile
= per_objfile
->objfile
;
11053 struct gdbarch
*gdbarch
= objfile
->arch ();
11054 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
11055 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
11056 struct attribute
*attr
;
11057 struct die_info
*child_die
;
11058 CORE_ADDR baseaddr
;
11060 prepare_one_comp_unit (cu
, die
, cu
->language
);
11061 baseaddr
= objfile
->text_section_offset ();
11063 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
11065 /* If we didn't find a lowpc, set it to highpc to avoid complaints
11066 from finish_block. */
11067 if (lowpc
== ((CORE_ADDR
) -1))
11069 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11071 file_and_directory fnd
= find_file_and_directory (die
, cu
);
11073 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
11074 standardised yet. As a workaround for the language detection we fall
11075 back to the DW_AT_producer string. */
11076 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
11077 cu
->language
= language_opencl
;
11079 /* Similar hack for Go. */
11080 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
11081 set_cu_language (DW_LANG_Go
, cu
);
11083 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
11085 /* Decode line number information if present. We do this before
11086 processing child DIEs, so that the line header table is available
11087 for DW_AT_decl_file. */
11088 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
11090 /* Process all dies in compilation unit. */
11091 if (die
->child
!= NULL
)
11093 child_die
= die
->child
;
11094 while (child_die
&& child_die
->tag
)
11096 process_die (child_die
, cu
);
11097 child_die
= child_die
->sibling
;
11101 /* Decode macro information, if present. Dwarf 2 macro information
11102 refers to information in the line number info statement program
11103 header, so we can only read it if we've read the header
11105 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
11107 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
11108 if (attr
!= nullptr && attr
->form_is_unsigned () && cu
->line_header
)
11110 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
11111 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
11113 dwarf_decode_macros (cu
, attr
->as_unsigned (), 1);
11117 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
11118 if (attr
!= nullptr && attr
->form_is_unsigned () && cu
->line_header
)
11120 unsigned int macro_offset
= attr
->as_unsigned ();
11122 dwarf_decode_macros (cu
, macro_offset
, 0);
11128 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
11130 struct type_unit_group
*tu_group
;
11132 struct attribute
*attr
;
11134 struct signatured_type
*sig_type
;
11136 gdb_assert (per_cu
->is_debug_types
);
11137 sig_type
= (struct signatured_type
*) per_cu
;
11139 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
11141 /* If we're using .gdb_index (includes -readnow) then
11142 per_cu->type_unit_group may not have been set up yet. */
11143 if (sig_type
->type_unit_group
== NULL
)
11144 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
11145 tu_group
= sig_type
->type_unit_group
;
11147 /* If we've already processed this stmt_list there's no real need to
11148 do it again, we could fake it and just recreate the part we need
11149 (file name,index -> symtab mapping). If data shows this optimization
11150 is useful we can do it then. */
11151 type_unit_group_unshareable
*tug_unshare
11152 = per_objfile
->get_type_unit_group_unshareable (tu_group
);
11153 first_time
= tug_unshare
->compunit_symtab
== NULL
;
11155 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
11158 if (attr
!= NULL
&& attr
->form_is_unsigned ())
11160 sect_offset line_offset
= (sect_offset
) attr
->as_unsigned ();
11161 lh
= dwarf_decode_line_header (line_offset
, this);
11166 start_symtab ("", NULL
, 0);
11169 gdb_assert (tug_unshare
->symtabs
== NULL
);
11170 gdb_assert (m_builder
== nullptr);
11171 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
11172 m_builder
.reset (new struct buildsym_compunit
11173 (COMPUNIT_OBJFILE (cust
), "",
11174 COMPUNIT_DIRNAME (cust
),
11175 compunit_language (cust
),
11177 list_in_scope
= get_builder ()->get_file_symbols ();
11182 line_header
= lh
.release ();
11183 line_header_die_owner
= die
;
11187 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
11189 /* Note: We don't assign tu_group->compunit_symtab yet because we're
11190 still initializing it, and our caller (a few levels up)
11191 process_full_type_unit still needs to know if this is the first
11194 tug_unshare
->symtabs
11195 = XOBNEWVEC (&COMPUNIT_OBJFILE (cust
)->objfile_obstack
,
11196 struct symtab
*, line_header
->file_names_size ());
11198 auto &file_names
= line_header
->file_names ();
11199 for (i
= 0; i
< file_names
.size (); ++i
)
11201 file_entry
&fe
= file_names
[i
];
11202 dwarf2_start_subfile (this, fe
.name
,
11203 fe
.include_dir (line_header
));
11204 buildsym_compunit
*b
= get_builder ();
11205 if (b
->get_current_subfile ()->symtab
== NULL
)
11207 /* NOTE: start_subfile will recognize when it's been
11208 passed a file it has already seen. So we can't
11209 assume there's a simple mapping from
11210 cu->line_header->file_names to subfiles, plus
11211 cu->line_header->file_names may contain dups. */
11212 b
->get_current_subfile ()->symtab
11213 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
11216 fe
.symtab
= b
->get_current_subfile ()->symtab
;
11217 tug_unshare
->symtabs
[i
] = fe
.symtab
;
11222 gdb_assert (m_builder
== nullptr);
11223 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
11224 m_builder
.reset (new struct buildsym_compunit
11225 (COMPUNIT_OBJFILE (cust
), "",
11226 COMPUNIT_DIRNAME (cust
),
11227 compunit_language (cust
),
11229 list_in_scope
= get_builder ()->get_file_symbols ();
11231 auto &file_names
= line_header
->file_names ();
11232 for (i
= 0; i
< file_names
.size (); ++i
)
11234 file_entry
&fe
= file_names
[i
];
11235 fe
.symtab
= tug_unshare
->symtabs
[i
];
11239 /* The main symtab is allocated last. Type units don't have DW_AT_name
11240 so they don't have a "real" (so to speak) symtab anyway.
11241 There is later code that will assign the main symtab to all symbols
11242 that don't have one. We need to handle the case of a symbol with a
11243 missing symtab (DW_AT_decl_file) anyway. */
11246 /* Process DW_TAG_type_unit.
11247 For TUs we want to skip the first top level sibling if it's not the
11248 actual type being defined by this TU. In this case the first top
11249 level sibling is there to provide context only. */
11252 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11254 struct die_info
*child_die
;
11256 prepare_one_comp_unit (cu
, die
, language_minimal
);
11258 /* Initialize (or reinitialize) the machinery for building symtabs.
11259 We do this before processing child DIEs, so that the line header table
11260 is available for DW_AT_decl_file. */
11261 cu
->setup_type_unit_groups (die
);
11263 if (die
->child
!= NULL
)
11265 child_die
= die
->child
;
11266 while (child_die
&& child_die
->tag
)
11268 process_die (child_die
, cu
);
11269 child_die
= child_die
->sibling
;
11276 http://gcc.gnu.org/wiki/DebugFission
11277 http://gcc.gnu.org/wiki/DebugFissionDWP
11279 To simplify handling of both DWO files ("object" files with the DWARF info)
11280 and DWP files (a file with the DWOs packaged up into one file), we treat
11281 DWP files as having a collection of virtual DWO files. */
11284 hash_dwo_file (const void *item
)
11286 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11289 hash
= htab_hash_string (dwo_file
->dwo_name
);
11290 if (dwo_file
->comp_dir
!= NULL
)
11291 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11296 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11298 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11299 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11301 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11303 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11304 return lhs
->comp_dir
== rhs
->comp_dir
;
11305 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11308 /* Allocate a hash table for DWO files. */
11311 allocate_dwo_file_hash_table ()
11313 auto delete_dwo_file
= [] (void *item
)
11315 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
11320 return htab_up (htab_create_alloc (41,
11327 /* Lookup DWO file DWO_NAME. */
11330 lookup_dwo_file_slot (dwarf2_per_objfile
*per_objfile
,
11331 const char *dwo_name
,
11332 const char *comp_dir
)
11334 struct dwo_file find_entry
;
11337 if (per_objfile
->per_bfd
->dwo_files
== NULL
)
11338 per_objfile
->per_bfd
->dwo_files
= allocate_dwo_file_hash_table ();
11340 find_entry
.dwo_name
= dwo_name
;
11341 find_entry
.comp_dir
= comp_dir
;
11342 slot
= htab_find_slot (per_objfile
->per_bfd
->dwo_files
.get (), &find_entry
,
11349 hash_dwo_unit (const void *item
)
11351 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11353 /* This drops the top 32 bits of the id, but is ok for a hash. */
11354 return dwo_unit
->signature
;
11358 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11360 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11361 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11363 /* The signature is assumed to be unique within the DWO file.
11364 So while object file CU dwo_id's always have the value zero,
11365 that's OK, assuming each object file DWO file has only one CU,
11366 and that's the rule for now. */
11367 return lhs
->signature
== rhs
->signature
;
11370 /* Allocate a hash table for DWO CUs,TUs.
11371 There is one of these tables for each of CUs,TUs for each DWO file. */
11374 allocate_dwo_unit_table ()
11376 /* Start out with a pretty small number.
11377 Generally DWO files contain only one CU and maybe some TUs. */
11378 return htab_up (htab_create_alloc (3,
11381 NULL
, xcalloc
, xfree
));
11384 /* die_reader_func for create_dwo_cu. */
11387 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11388 const gdb_byte
*info_ptr
,
11389 struct die_info
*comp_unit_die
,
11390 struct dwo_file
*dwo_file
,
11391 struct dwo_unit
*dwo_unit
)
11393 struct dwarf2_cu
*cu
= reader
->cu
;
11394 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11395 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11397 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11398 if (!signature
.has_value ())
11400 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11401 " its dwo_id [in module %s]"),
11402 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11406 dwo_unit
->dwo_file
= dwo_file
;
11407 dwo_unit
->signature
= *signature
;
11408 dwo_unit
->section
= section
;
11409 dwo_unit
->sect_off
= sect_off
;
11410 dwo_unit
->length
= cu
->per_cu
->length
;
11412 dwarf_read_debug_printf (" offset %s, dwo_id %s",
11413 sect_offset_str (sect_off
),
11414 hex_string (dwo_unit
->signature
));
11417 /* Create the dwo_units for the CUs in a DWO_FILE.
11418 Note: This function processes DWO files only, not DWP files. */
11421 create_cus_hash_table (dwarf2_per_objfile
*per_objfile
,
11422 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11423 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
11425 struct objfile
*objfile
= per_objfile
->objfile
;
11426 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
11427 const gdb_byte
*info_ptr
, *end_ptr
;
11429 section
.read (objfile
);
11430 info_ptr
= section
.buffer
;
11432 if (info_ptr
== NULL
)
11435 dwarf_read_debug_printf ("Reading %s for %s:",
11436 section
.get_name (),
11437 section
.get_file_name ());
11439 end_ptr
= info_ptr
+ section
.size
;
11440 while (info_ptr
< end_ptr
)
11442 struct dwarf2_per_cu_data per_cu
;
11443 struct dwo_unit read_unit
{};
11444 struct dwo_unit
*dwo_unit
;
11446 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11448 memset (&per_cu
, 0, sizeof (per_cu
));
11449 per_cu
.per_bfd
= per_bfd
;
11450 per_cu
.is_debug_types
= 0;
11451 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11452 per_cu
.section
= §ion
;
11454 cutu_reader
reader (&per_cu
, per_objfile
, cu
, &dwo_file
);
11455 if (!reader
.dummy_p
)
11456 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11457 &dwo_file
, &read_unit
);
11458 info_ptr
+= per_cu
.length
;
11460 // If the unit could not be parsed, skip it.
11461 if (read_unit
.dwo_file
== NULL
)
11464 if (cus_htab
== NULL
)
11465 cus_htab
= allocate_dwo_unit_table ();
11467 dwo_unit
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
11469 *dwo_unit
= read_unit
;
11470 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11471 gdb_assert (slot
!= NULL
);
11474 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11475 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11477 complaint (_("debug cu entry at offset %s is duplicate to"
11478 " the entry at offset %s, signature %s"),
11479 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11480 hex_string (dwo_unit
->signature
));
11482 *slot
= (void *)dwo_unit
;
11486 /* DWP file .debug_{cu,tu}_index section format:
11487 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11488 [ref: http://dwarfstd.org/doc/DWARF5.pdf, sect 7.3.5 "DWARF Package Files"]
11490 DWP Versions 1 & 2 are older, pre-standard format versions. The first
11491 officially standard DWP format was published with DWARF v5 and is called
11492 Version 5. There are no versions 3 or 4.
11496 Both index sections have the same format, and serve to map a 64-bit
11497 signature to a set of section numbers. Each section begins with a header,
11498 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11499 indexes, and a pool of 32-bit section numbers. The index sections will be
11500 aligned at 8-byte boundaries in the file.
11502 The index section header consists of:
11504 V, 32 bit version number
11506 N, 32 bit number of compilation units or type units in the index
11507 M, 32 bit number of slots in the hash table
11509 Numbers are recorded using the byte order of the application binary.
11511 The hash table begins at offset 16 in the section, and consists of an array
11512 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11513 order of the application binary). Unused slots in the hash table are 0.
11514 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11516 The parallel table begins immediately after the hash table
11517 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11518 array of 32-bit indexes (using the byte order of the application binary),
11519 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11520 table contains a 32-bit index into the pool of section numbers. For unused
11521 hash table slots, the corresponding entry in the parallel table will be 0.
11523 The pool of section numbers begins immediately following the hash table
11524 (at offset 16 + 12 * M from the beginning of the section). The pool of
11525 section numbers consists of an array of 32-bit words (using the byte order
11526 of the application binary). Each item in the array is indexed starting
11527 from 0. The hash table entry provides the index of the first section
11528 number in the set. Additional section numbers in the set follow, and the
11529 set is terminated by a 0 entry (section number 0 is not used in ELF).
11531 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11532 section must be the first entry in the set, and the .debug_abbrev.dwo must
11533 be the second entry. Other members of the set may follow in any order.
11537 DWP Versions 2 and 5:
11539 DWP Versions 2 and 5 combine all the .debug_info, etc. sections into one,
11540 and the entries in the index tables are now offsets into these sections.
11541 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11544 Index Section Contents:
11546 Hash Table of Signatures dwp_hash_table.hash_table
11547 Parallel Table of Indices dwp_hash_table.unit_table
11548 Table of Section Offsets dwp_hash_table.{v2|v5}.{section_ids,offsets}
11549 Table of Section Sizes dwp_hash_table.{v2|v5}.sizes
11551 The index section header consists of:
11553 V, 32 bit version number
11554 L, 32 bit number of columns in the table of section offsets
11555 N, 32 bit number of compilation units or type units in the index
11556 M, 32 bit number of slots in the hash table
11558 Numbers are recorded using the byte order of the application binary.
11560 The hash table has the same format as version 1.
11561 The parallel table of indices has the same format as version 1,
11562 except that the entries are origin-1 indices into the table of sections
11563 offsets and the table of section sizes.
11565 The table of offsets begins immediately following the parallel table
11566 (at offset 16 + 12 * M from the beginning of the section). The table is
11567 a two-dimensional array of 32-bit words (using the byte order of the
11568 application binary), with L columns and N+1 rows, in row-major order.
11569 Each row in the array is indexed starting from 0. The first row provides
11570 a key to the remaining rows: each column in this row provides an identifier
11571 for a debug section, and the offsets in the same column of subsequent rows
11572 refer to that section. The section identifiers for Version 2 are:
11574 DW_SECT_INFO 1 .debug_info.dwo
11575 DW_SECT_TYPES 2 .debug_types.dwo
11576 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11577 DW_SECT_LINE 4 .debug_line.dwo
11578 DW_SECT_LOC 5 .debug_loc.dwo
11579 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11580 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11581 DW_SECT_MACRO 8 .debug_macro.dwo
11583 The section identifiers for Version 5 are:
11585 DW_SECT_INFO_V5 1 .debug_info.dwo
11586 DW_SECT_RESERVED_V5 2 --
11587 DW_SECT_ABBREV_V5 3 .debug_abbrev.dwo
11588 DW_SECT_LINE_V5 4 .debug_line.dwo
11589 DW_SECT_LOCLISTS_V5 5 .debug_loclists.dwo
11590 DW_SECT_STR_OFFSETS_V5 6 .debug_str_offsets.dwo
11591 DW_SECT_MACRO_V5 7 .debug_macro.dwo
11592 DW_SECT_RNGLISTS_V5 8 .debug_rnglists.dwo
11594 The offsets provided by the CU and TU index sections are the base offsets
11595 for the contributions made by each CU or TU to the corresponding section
11596 in the package file. Each CU and TU header contains an abbrev_offset
11597 field, used to find the abbreviations table for that CU or TU within the
11598 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11599 be interpreted as relative to the base offset given in the index section.
11600 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11601 should be interpreted as relative to the base offset for .debug_line.dwo,
11602 and offsets into other debug sections obtained from DWARF attributes should
11603 also be interpreted as relative to the corresponding base offset.
11605 The table of sizes begins immediately following the table of offsets.
11606 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11607 with L columns and N rows, in row-major order. Each row in the array is
11608 indexed starting from 1 (row 0 is shared by the two tables).
11612 Hash table lookup is handled the same in version 1 and 2:
11614 We assume that N and M will not exceed 2^32 - 1.
11615 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11617 Given a 64-bit compilation unit signature or a type signature S, an entry
11618 in the hash table is located as follows:
11620 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11621 the low-order k bits all set to 1.
11623 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11625 3) If the hash table entry at index H matches the signature, use that
11626 entry. If the hash table entry at index H is unused (all zeroes),
11627 terminate the search: the signature is not present in the table.
11629 4) Let H = (H + H') modulo M. Repeat at Step 3.
11631 Because M > N and H' and M are relatively prime, the search is guaranteed
11632 to stop at an unused slot or find the match. */
11634 /* Create a hash table to map DWO IDs to their CU/TU entry in
11635 .debug_{info,types}.dwo in DWP_FILE.
11636 Returns NULL if there isn't one.
11637 Note: This function processes DWP files only, not DWO files. */
11639 static struct dwp_hash_table
*
11640 create_dwp_hash_table (dwarf2_per_objfile
*per_objfile
,
11641 struct dwp_file
*dwp_file
, int is_debug_types
)
11643 struct objfile
*objfile
= per_objfile
->objfile
;
11644 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11645 const gdb_byte
*index_ptr
, *index_end
;
11646 struct dwarf2_section_info
*index
;
11647 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11648 struct dwp_hash_table
*htab
;
11650 if (is_debug_types
)
11651 index
= &dwp_file
->sections
.tu_index
;
11653 index
= &dwp_file
->sections
.cu_index
;
11655 if (index
->empty ())
11657 index
->read (objfile
);
11659 index_ptr
= index
->buffer
;
11660 index_end
= index_ptr
+ index
->size
;
11662 /* For Version 5, the version is really 2 bytes of data & 2 bytes of padding.
11663 For now it's safe to just read 4 bytes (particularly as it's difficult to
11664 tell if you're dealing with Version 5 before you've read the version). */
11665 version
= read_4_bytes (dbfd
, index_ptr
);
11667 if (version
== 2 || version
== 5)
11668 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11672 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11674 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11677 if (version
!= 1 && version
!= 2 && version
!= 5)
11679 error (_("Dwarf Error: unsupported DWP file version (%s)"
11680 " [in module %s]"),
11681 pulongest (version
), dwp_file
->name
);
11683 if (nr_slots
!= (nr_slots
& -nr_slots
))
11685 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11686 " is not power of 2 [in module %s]"),
11687 pulongest (nr_slots
), dwp_file
->name
);
11690 htab
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwp_hash_table
);
11691 htab
->version
= version
;
11692 htab
->nr_columns
= nr_columns
;
11693 htab
->nr_units
= nr_units
;
11694 htab
->nr_slots
= nr_slots
;
11695 htab
->hash_table
= index_ptr
;
11696 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11698 /* Exit early if the table is empty. */
11699 if (nr_slots
== 0 || nr_units
== 0
11700 || (version
== 2 && nr_columns
== 0)
11701 || (version
== 5 && nr_columns
== 0))
11703 /* All must be zero. */
11704 if (nr_slots
!= 0 || nr_units
!= 0
11705 || (version
== 2 && nr_columns
!= 0)
11706 || (version
== 5 && nr_columns
!= 0))
11708 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11709 " all zero [in modules %s]"),
11717 htab
->section_pool
.v1
.indices
=
11718 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11719 /* It's harder to decide whether the section is too small in v1.
11720 V1 is deprecated anyway so we punt. */
11722 else if (version
== 2)
11724 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11725 int *ids
= htab
->section_pool
.v2
.section_ids
;
11726 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11727 /* Reverse map for error checking. */
11728 int ids_seen
[DW_SECT_MAX
+ 1];
11731 if (nr_columns
< 2)
11733 error (_("Dwarf Error: bad DWP hash table, too few columns"
11734 " in section table [in module %s]"),
11737 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11739 error (_("Dwarf Error: bad DWP hash table, too many columns"
11740 " in section table [in module %s]"),
11743 memset (ids
, 255, sizeof_ids
);
11744 memset (ids_seen
, 255, sizeof (ids_seen
));
11745 for (i
= 0; i
< nr_columns
; ++i
)
11747 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11749 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11751 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11752 " in section table [in module %s]"),
11753 id
, dwp_file
->name
);
11755 if (ids_seen
[id
] != -1)
11757 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11758 " id %d in section table [in module %s]"),
11759 id
, dwp_file
->name
);
11764 /* Must have exactly one info or types section. */
11765 if (((ids_seen
[DW_SECT_INFO
] != -1)
11766 + (ids_seen
[DW_SECT_TYPES
] != -1))
11769 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11770 " DWO info/types section [in module %s]"),
11773 /* Must have an abbrev section. */
11774 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11776 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11777 " section [in module %s]"),
11780 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11781 htab
->section_pool
.v2
.sizes
=
11782 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11783 * nr_units
* nr_columns
);
11784 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11785 * nr_units
* nr_columns
))
11788 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11789 " [in module %s]"),
11793 else /* version == 5 */
11795 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11796 int *ids
= htab
->section_pool
.v5
.section_ids
;
11797 size_t sizeof_ids
= sizeof (htab
->section_pool
.v5
.section_ids
);
11798 /* Reverse map for error checking. */
11799 int ids_seen
[DW_SECT_MAX_V5
+ 1];
11801 if (nr_columns
< 2)
11803 error (_("Dwarf Error: bad DWP hash table, too few columns"
11804 " in section table [in module %s]"),
11807 if (nr_columns
> MAX_NR_V5_DWO_SECTIONS
)
11809 error (_("Dwarf Error: bad DWP hash table, too many columns"
11810 " in section table [in module %s]"),
11813 memset (ids
, 255, sizeof_ids
);
11814 memset (ids_seen
, 255, sizeof (ids_seen
));
11815 for (int i
= 0; i
< nr_columns
; ++i
)
11817 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11819 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX_V5
)
11821 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11822 " in section table [in module %s]"),
11823 id
, dwp_file
->name
);
11825 if (ids_seen
[id
] != -1)
11827 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11828 " id %d in section table [in module %s]"),
11829 id
, dwp_file
->name
);
11834 /* Must have seen an info section. */
11835 if (ids_seen
[DW_SECT_INFO_V5
] == -1)
11837 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11838 " DWO info/types section [in module %s]"),
11841 /* Must have an abbrev section. */
11842 if (ids_seen
[DW_SECT_ABBREV_V5
] == -1)
11844 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11845 " section [in module %s]"),
11848 htab
->section_pool
.v5
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11849 htab
->section_pool
.v5
.sizes
11850 = htab
->section_pool
.v5
.offsets
+ (sizeof (uint32_t)
11851 * nr_units
* nr_columns
);
11852 if ((htab
->section_pool
.v5
.sizes
+ (sizeof (uint32_t)
11853 * nr_units
* nr_columns
))
11856 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11857 " [in module %s]"),
11865 /* Update SECTIONS with the data from SECTP.
11867 This function is like the other "locate" section routines, but in
11868 this context the sections to read comes from the DWP V1 hash table,
11869 not the full ELF section table.
11871 The result is non-zero for success, or zero if an error was found. */
11874 locate_v1_virtual_dwo_sections (asection
*sectp
,
11875 struct virtual_v1_dwo_sections
*sections
)
11877 const struct dwop_section_names
*names
= &dwop_section_names
;
11879 if (names
->abbrev_dwo
.matches (sectp
->name
))
11881 /* There can be only one. */
11882 if (sections
->abbrev
.s
.section
!= NULL
)
11884 sections
->abbrev
.s
.section
= sectp
;
11885 sections
->abbrev
.size
= bfd_section_size (sectp
);
11887 else if (names
->info_dwo
.matches (sectp
->name
)
11888 || names
->types_dwo
.matches (sectp
->name
))
11890 /* There can be only one. */
11891 if (sections
->info_or_types
.s
.section
!= NULL
)
11893 sections
->info_or_types
.s
.section
= sectp
;
11894 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11896 else if (names
->line_dwo
.matches (sectp
->name
))
11898 /* There can be only one. */
11899 if (sections
->line
.s
.section
!= NULL
)
11901 sections
->line
.s
.section
= sectp
;
11902 sections
->line
.size
= bfd_section_size (sectp
);
11904 else if (names
->loc_dwo
.matches (sectp
->name
))
11906 /* There can be only one. */
11907 if (sections
->loc
.s
.section
!= NULL
)
11909 sections
->loc
.s
.section
= sectp
;
11910 sections
->loc
.size
= bfd_section_size (sectp
);
11912 else if (names
->macinfo_dwo
.matches (sectp
->name
))
11914 /* There can be only one. */
11915 if (sections
->macinfo
.s
.section
!= NULL
)
11917 sections
->macinfo
.s
.section
= sectp
;
11918 sections
->macinfo
.size
= bfd_section_size (sectp
);
11920 else if (names
->macro_dwo
.matches (sectp
->name
))
11922 /* There can be only one. */
11923 if (sections
->macro
.s
.section
!= NULL
)
11925 sections
->macro
.s
.section
= sectp
;
11926 sections
->macro
.size
= bfd_section_size (sectp
);
11928 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
11930 /* There can be only one. */
11931 if (sections
->str_offsets
.s
.section
!= NULL
)
11933 sections
->str_offsets
.s
.section
= sectp
;
11934 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11938 /* No other kind of section is valid. */
11945 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11946 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11947 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11948 This is for DWP version 1 files. */
11950 static struct dwo_unit
*
11951 create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
*per_objfile
,
11952 struct dwp_file
*dwp_file
,
11953 uint32_t unit_index
,
11954 const char *comp_dir
,
11955 ULONGEST signature
, int is_debug_types
)
11957 const struct dwp_hash_table
*dwp_htab
=
11958 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11959 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11960 const char *kind
= is_debug_types
? "TU" : "CU";
11961 struct dwo_file
*dwo_file
;
11962 struct dwo_unit
*dwo_unit
;
11963 struct virtual_v1_dwo_sections sections
;
11964 void **dwo_file_slot
;
11967 gdb_assert (dwp_file
->version
== 1);
11969 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V1 file: %s",
11970 kind
, pulongest (unit_index
), hex_string (signature
),
11973 /* Fetch the sections of this DWO unit.
11974 Put a limit on the number of sections we look for so that bad data
11975 doesn't cause us to loop forever. */
11977 #define MAX_NR_V1_DWO_SECTIONS \
11978 (1 /* .debug_info or .debug_types */ \
11979 + 1 /* .debug_abbrev */ \
11980 + 1 /* .debug_line */ \
11981 + 1 /* .debug_loc */ \
11982 + 1 /* .debug_str_offsets */ \
11983 + 1 /* .debug_macro or .debug_macinfo */ \
11984 + 1 /* trailing zero */)
11986 memset (§ions
, 0, sizeof (sections
));
11988 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
11991 uint32_t section_nr
=
11992 read_4_bytes (dbfd
,
11993 dwp_htab
->section_pool
.v1
.indices
11994 + (unit_index
+ i
) * sizeof (uint32_t));
11996 if (section_nr
== 0)
11998 if (section_nr
>= dwp_file
->num_sections
)
12000 error (_("Dwarf Error: bad DWP hash table, section number too large"
12001 " [in module %s]"),
12005 sectp
= dwp_file
->elf_sections
[section_nr
];
12006 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
12008 error (_("Dwarf Error: bad DWP hash table, invalid section found"
12009 " [in module %s]"),
12015 || sections
.info_or_types
.empty ()
12016 || sections
.abbrev
.empty ())
12018 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
12019 " [in module %s]"),
12022 if (i
== MAX_NR_V1_DWO_SECTIONS
)
12024 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
12025 " [in module %s]"),
12029 /* It's easier for the rest of the code if we fake a struct dwo_file and
12030 have dwo_unit "live" in that. At least for now.
12032 The DWP file can be made up of a random collection of CUs and TUs.
12033 However, for each CU + set of TUs that came from the same original DWO
12034 file, we can combine them back into a virtual DWO file to save space
12035 (fewer struct dwo_file objects to allocate). Remember that for really
12036 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12038 std::string virtual_dwo_name
=
12039 string_printf ("virtual-dwo/%d-%d-%d-%d",
12040 sections
.abbrev
.get_id (),
12041 sections
.line
.get_id (),
12042 sections
.loc
.get_id (),
12043 sections
.str_offsets
.get_id ());
12044 /* Can we use an existing virtual DWO file? */
12045 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
12047 /* Create one if necessary. */
12048 if (*dwo_file_slot
== NULL
)
12050 dwarf_read_debug_printf ("Creating virtual DWO: %s",
12051 virtual_dwo_name
.c_str ());
12053 dwo_file
= new struct dwo_file
;
12054 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
12055 dwo_file
->comp_dir
= comp_dir
;
12056 dwo_file
->sections
.abbrev
= sections
.abbrev
;
12057 dwo_file
->sections
.line
= sections
.line
;
12058 dwo_file
->sections
.loc
= sections
.loc
;
12059 dwo_file
->sections
.macinfo
= sections
.macinfo
;
12060 dwo_file
->sections
.macro
= sections
.macro
;
12061 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
12062 /* The "str" section is global to the entire DWP file. */
12063 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12064 /* The info or types section is assigned below to dwo_unit,
12065 there's no need to record it in dwo_file.
12066 Also, we can't simply record type sections in dwo_file because
12067 we record a pointer into the vector in dwo_unit. As we collect more
12068 types we'll grow the vector and eventually have to reallocate space
12069 for it, invalidating all copies of pointers into the previous
12071 *dwo_file_slot
= dwo_file
;
12075 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
12076 virtual_dwo_name
.c_str ());
12078 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12081 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12082 dwo_unit
->dwo_file
= dwo_file
;
12083 dwo_unit
->signature
= signature
;
12084 dwo_unit
->section
=
12085 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12086 *dwo_unit
->section
= sections
.info_or_types
;
12087 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12092 /* Subroutine of create_dwo_unit_in_dwp_v2 and create_dwo_unit_in_dwp_v5 to
12093 simplify them. Given a pointer to the containing section SECTION, and
12094 OFFSET,SIZE of the piece within that section used by a TU/CU, return a
12095 virtual section of just that piece. */
12097 static struct dwarf2_section_info
12098 create_dwp_v2_or_v5_section (dwarf2_per_objfile
*per_objfile
,
12099 struct dwarf2_section_info
*section
,
12100 bfd_size_type offset
, bfd_size_type size
)
12102 struct dwarf2_section_info result
;
12105 gdb_assert (section
!= NULL
);
12106 gdb_assert (!section
->is_virtual
);
12108 memset (&result
, 0, sizeof (result
));
12109 result
.s
.containing_section
= section
;
12110 result
.is_virtual
= true;
12115 sectp
= section
->get_bfd_section ();
12117 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
12118 bounds of the real section. This is a pretty-rare event, so just
12119 flag an error (easier) instead of a warning and trying to cope. */
12121 || offset
+ size
> bfd_section_size (sectp
))
12123 error (_("Dwarf Error: Bad DWP V2 or V5 section info, doesn't fit"
12124 " in section %s [in module %s]"),
12125 sectp
? bfd_section_name (sectp
) : "<unknown>",
12126 objfile_name (per_objfile
->objfile
));
12129 result
.virtual_offset
= offset
;
12130 result
.size
= size
;
12134 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12135 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12136 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12137 This is for DWP version 2 files. */
12139 static struct dwo_unit
*
12140 create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
*per_objfile
,
12141 struct dwp_file
*dwp_file
,
12142 uint32_t unit_index
,
12143 const char *comp_dir
,
12144 ULONGEST signature
, int is_debug_types
)
12146 const struct dwp_hash_table
*dwp_htab
=
12147 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12148 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12149 const char *kind
= is_debug_types
? "TU" : "CU";
12150 struct dwo_file
*dwo_file
;
12151 struct dwo_unit
*dwo_unit
;
12152 struct virtual_v2_or_v5_dwo_sections sections
;
12153 void **dwo_file_slot
;
12156 gdb_assert (dwp_file
->version
== 2);
12158 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V2 file: %s",
12159 kind
, pulongest (unit_index
), hex_string (signature
),
12162 /* Fetch the section offsets of this DWO unit. */
12164 memset (§ions
, 0, sizeof (sections
));
12166 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12168 uint32_t offset
= read_4_bytes (dbfd
,
12169 dwp_htab
->section_pool
.v2
.offsets
12170 + (((unit_index
- 1) * dwp_htab
->nr_columns
12172 * sizeof (uint32_t)));
12173 uint32_t size
= read_4_bytes (dbfd
,
12174 dwp_htab
->section_pool
.v2
.sizes
12175 + (((unit_index
- 1) * dwp_htab
->nr_columns
12177 * sizeof (uint32_t)));
12179 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
12182 case DW_SECT_TYPES
:
12183 sections
.info_or_types_offset
= offset
;
12184 sections
.info_or_types_size
= size
;
12186 case DW_SECT_ABBREV
:
12187 sections
.abbrev_offset
= offset
;
12188 sections
.abbrev_size
= size
;
12191 sections
.line_offset
= offset
;
12192 sections
.line_size
= size
;
12195 sections
.loc_offset
= offset
;
12196 sections
.loc_size
= size
;
12198 case DW_SECT_STR_OFFSETS
:
12199 sections
.str_offsets_offset
= offset
;
12200 sections
.str_offsets_size
= size
;
12202 case DW_SECT_MACINFO
:
12203 sections
.macinfo_offset
= offset
;
12204 sections
.macinfo_size
= size
;
12206 case DW_SECT_MACRO
:
12207 sections
.macro_offset
= offset
;
12208 sections
.macro_size
= size
;
12213 /* It's easier for the rest of the code if we fake a struct dwo_file and
12214 have dwo_unit "live" in that. At least for now.
12216 The DWP file can be made up of a random collection of CUs and TUs.
12217 However, for each CU + set of TUs that came from the same original DWO
12218 file, we can combine them back into a virtual DWO file to save space
12219 (fewer struct dwo_file objects to allocate). Remember that for really
12220 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12222 std::string virtual_dwo_name
=
12223 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
12224 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12225 (long) (sections
.line_size
? sections
.line_offset
: 0),
12226 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
12227 (long) (sections
.str_offsets_size
12228 ? sections
.str_offsets_offset
: 0));
12229 /* Can we use an existing virtual DWO file? */
12230 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
12232 /* Create one if necessary. */
12233 if (*dwo_file_slot
== NULL
)
12235 dwarf_read_debug_printf ("Creating virtual DWO: %s",
12236 virtual_dwo_name
.c_str ());
12238 dwo_file
= new struct dwo_file
;
12239 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
12240 dwo_file
->comp_dir
= comp_dir
;
12241 dwo_file
->sections
.abbrev
=
12242 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.abbrev
,
12243 sections
.abbrev_offset
,
12244 sections
.abbrev_size
);
12245 dwo_file
->sections
.line
=
12246 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.line
,
12247 sections
.line_offset
,
12248 sections
.line_size
);
12249 dwo_file
->sections
.loc
=
12250 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.loc
,
12251 sections
.loc_offset
, sections
.loc_size
);
12252 dwo_file
->sections
.macinfo
=
12253 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.macinfo
,
12254 sections
.macinfo_offset
,
12255 sections
.macinfo_size
);
12256 dwo_file
->sections
.macro
=
12257 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.macro
,
12258 sections
.macro_offset
,
12259 sections
.macro_size
);
12260 dwo_file
->sections
.str_offsets
=
12261 create_dwp_v2_or_v5_section (per_objfile
,
12262 &dwp_file
->sections
.str_offsets
,
12263 sections
.str_offsets_offset
,
12264 sections
.str_offsets_size
);
12265 /* The "str" section is global to the entire DWP file. */
12266 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12267 /* The info or types section is assigned below to dwo_unit,
12268 there's no need to record it in dwo_file.
12269 Also, we can't simply record type sections in dwo_file because
12270 we record a pointer into the vector in dwo_unit. As we collect more
12271 types we'll grow the vector and eventually have to reallocate space
12272 for it, invalidating all copies of pointers into the previous
12274 *dwo_file_slot
= dwo_file
;
12278 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
12279 virtual_dwo_name
.c_str ());
12281 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12284 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12285 dwo_unit
->dwo_file
= dwo_file
;
12286 dwo_unit
->signature
= signature
;
12287 dwo_unit
->section
=
12288 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12289 *dwo_unit
->section
= create_dwp_v2_or_v5_section
12292 ? &dwp_file
->sections
.types
12293 : &dwp_file
->sections
.info
,
12294 sections
.info_or_types_offset
,
12295 sections
.info_or_types_size
);
12296 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12301 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12302 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12303 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12304 This is for DWP version 5 files. */
12306 static struct dwo_unit
*
12307 create_dwo_unit_in_dwp_v5 (dwarf2_per_objfile
*per_objfile
,
12308 struct dwp_file
*dwp_file
,
12309 uint32_t unit_index
,
12310 const char *comp_dir
,
12311 ULONGEST signature
, int is_debug_types
)
12313 const struct dwp_hash_table
*dwp_htab
12314 = is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12315 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12316 const char *kind
= is_debug_types
? "TU" : "CU";
12317 struct dwo_file
*dwo_file
;
12318 struct dwo_unit
*dwo_unit
;
12319 struct virtual_v2_or_v5_dwo_sections sections
{};
12320 void **dwo_file_slot
;
12322 gdb_assert (dwp_file
->version
== 5);
12324 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V5 file: %s",
12325 kind
, pulongest (unit_index
), hex_string (signature
),
12328 /* Fetch the section offsets of this DWO unit. */
12330 /* memset (§ions, 0, sizeof (sections)); */
12332 for (int i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12334 uint32_t offset
= read_4_bytes (dbfd
,
12335 dwp_htab
->section_pool
.v5
.offsets
12336 + (((unit_index
- 1)
12337 * dwp_htab
->nr_columns
12339 * sizeof (uint32_t)));
12340 uint32_t size
= read_4_bytes (dbfd
,
12341 dwp_htab
->section_pool
.v5
.sizes
12342 + (((unit_index
- 1) * dwp_htab
->nr_columns
12344 * sizeof (uint32_t)));
12346 switch (dwp_htab
->section_pool
.v5
.section_ids
[i
])
12348 case DW_SECT_ABBREV_V5
:
12349 sections
.abbrev_offset
= offset
;
12350 sections
.abbrev_size
= size
;
12352 case DW_SECT_INFO_V5
:
12353 sections
.info_or_types_offset
= offset
;
12354 sections
.info_or_types_size
= size
;
12356 case DW_SECT_LINE_V5
:
12357 sections
.line_offset
= offset
;
12358 sections
.line_size
= size
;
12360 case DW_SECT_LOCLISTS_V5
:
12361 sections
.loclists_offset
= offset
;
12362 sections
.loclists_size
= size
;
12364 case DW_SECT_MACRO_V5
:
12365 sections
.macro_offset
= offset
;
12366 sections
.macro_size
= size
;
12368 case DW_SECT_RNGLISTS_V5
:
12369 sections
.rnglists_offset
= offset
;
12370 sections
.rnglists_size
= size
;
12372 case DW_SECT_STR_OFFSETS_V5
:
12373 sections
.str_offsets_offset
= offset
;
12374 sections
.str_offsets_size
= size
;
12376 case DW_SECT_RESERVED_V5
:
12382 /* It's easier for the rest of the code if we fake a struct dwo_file and
12383 have dwo_unit "live" in that. At least for now.
12385 The DWP file can be made up of a random collection of CUs and TUs.
12386 However, for each CU + set of TUs that came from the same original DWO
12387 file, we can combine them back into a virtual DWO file to save space
12388 (fewer struct dwo_file objects to allocate). Remember that for really
12389 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12391 std::string virtual_dwo_name
=
12392 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld-%ld-%ld",
12393 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12394 (long) (sections
.line_size
? sections
.line_offset
: 0),
12395 (long) (sections
.loclists_size
? sections
.loclists_offset
: 0),
12396 (long) (sections
.str_offsets_size
12397 ? sections
.str_offsets_offset
: 0),
12398 (long) (sections
.macro_size
? sections
.macro_offset
: 0),
12399 (long) (sections
.rnglists_size
? sections
.rnglists_offset
: 0));
12400 /* Can we use an existing virtual DWO file? */
12401 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
,
12402 virtual_dwo_name
.c_str (),
12404 /* Create one if necessary. */
12405 if (*dwo_file_slot
== NULL
)
12407 dwarf_read_debug_printf ("Creating virtual DWO: %s",
12408 virtual_dwo_name
.c_str ());
12410 dwo_file
= new struct dwo_file
;
12411 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
12412 dwo_file
->comp_dir
= comp_dir
;
12413 dwo_file
->sections
.abbrev
=
12414 create_dwp_v2_or_v5_section (per_objfile
,
12415 &dwp_file
->sections
.abbrev
,
12416 sections
.abbrev_offset
,
12417 sections
.abbrev_size
);
12418 dwo_file
->sections
.line
=
12419 create_dwp_v2_or_v5_section (per_objfile
,
12420 &dwp_file
->sections
.line
,
12421 sections
.line_offset
, sections
.line_size
);
12422 dwo_file
->sections
.macro
=
12423 create_dwp_v2_or_v5_section (per_objfile
,
12424 &dwp_file
->sections
.macro
,
12425 sections
.macro_offset
,
12426 sections
.macro_size
);
12427 dwo_file
->sections
.loclists
=
12428 create_dwp_v2_or_v5_section (per_objfile
,
12429 &dwp_file
->sections
.loclists
,
12430 sections
.loclists_offset
,
12431 sections
.loclists_size
);
12432 dwo_file
->sections
.rnglists
=
12433 create_dwp_v2_or_v5_section (per_objfile
,
12434 &dwp_file
->sections
.rnglists
,
12435 sections
.rnglists_offset
,
12436 sections
.rnglists_size
);
12437 dwo_file
->sections
.str_offsets
=
12438 create_dwp_v2_or_v5_section (per_objfile
,
12439 &dwp_file
->sections
.str_offsets
,
12440 sections
.str_offsets_offset
,
12441 sections
.str_offsets_size
);
12442 /* The "str" section is global to the entire DWP file. */
12443 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12444 /* The info or types section is assigned below to dwo_unit,
12445 there's no need to record it in dwo_file.
12446 Also, we can't simply record type sections in dwo_file because
12447 we record a pointer into the vector in dwo_unit. As we collect more
12448 types we'll grow the vector and eventually have to reallocate space
12449 for it, invalidating all copies of pointers into the previous
12451 *dwo_file_slot
= dwo_file
;
12455 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
12456 virtual_dwo_name
.c_str ());
12458 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12461 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12462 dwo_unit
->dwo_file
= dwo_file
;
12463 dwo_unit
->signature
= signature
;
12465 = XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12466 *dwo_unit
->section
= create_dwp_v2_or_v5_section (per_objfile
,
12467 &dwp_file
->sections
.info
,
12468 sections
.info_or_types_offset
,
12469 sections
.info_or_types_size
);
12470 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12475 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12476 Returns NULL if the signature isn't found. */
12478 static struct dwo_unit
*
12479 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
*per_objfile
,
12480 struct dwp_file
*dwp_file
, const char *comp_dir
,
12481 ULONGEST signature
, int is_debug_types
)
12483 const struct dwp_hash_table
*dwp_htab
=
12484 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12485 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12486 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12487 uint32_t hash
= signature
& mask
;
12488 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12491 struct dwo_unit find_dwo_cu
;
12493 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12494 find_dwo_cu
.signature
= signature
;
12495 slot
= htab_find_slot (is_debug_types
12496 ? dwp_file
->loaded_tus
.get ()
12497 : dwp_file
->loaded_cus
.get (),
12498 &find_dwo_cu
, INSERT
);
12501 return (struct dwo_unit
*) *slot
;
12503 /* Use a for loop so that we don't loop forever on bad debug info. */
12504 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12506 ULONGEST signature_in_table
;
12508 signature_in_table
=
12509 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12510 if (signature_in_table
== signature
)
12512 uint32_t unit_index
=
12513 read_4_bytes (dbfd
,
12514 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12516 if (dwp_file
->version
== 1)
12518 *slot
= create_dwo_unit_in_dwp_v1 (per_objfile
, dwp_file
,
12519 unit_index
, comp_dir
,
12520 signature
, is_debug_types
);
12522 else if (dwp_file
->version
== 2)
12524 *slot
= create_dwo_unit_in_dwp_v2 (per_objfile
, dwp_file
,
12525 unit_index
, comp_dir
,
12526 signature
, is_debug_types
);
12528 else /* version == 5 */
12530 *slot
= create_dwo_unit_in_dwp_v5 (per_objfile
, dwp_file
,
12531 unit_index
, comp_dir
,
12532 signature
, is_debug_types
);
12534 return (struct dwo_unit
*) *slot
;
12536 if (signature_in_table
== 0)
12538 hash
= (hash
+ hash2
) & mask
;
12541 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12542 " [in module %s]"),
12546 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12547 Open the file specified by FILE_NAME and hand it off to BFD for
12548 preliminary analysis. Return a newly initialized bfd *, which
12549 includes a canonicalized copy of FILE_NAME.
12550 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12551 SEARCH_CWD is true if the current directory is to be searched.
12552 It will be searched before debug-file-directory.
12553 If successful, the file is added to the bfd include table of the
12554 objfile's bfd (see gdb_bfd_record_inclusion).
12555 If unable to find/open the file, return NULL.
12556 NOTE: This function is derived from symfile_bfd_open. */
12558 static gdb_bfd_ref_ptr
12559 try_open_dwop_file (dwarf2_per_objfile
*per_objfile
,
12560 const char *file_name
, int is_dwp
, int search_cwd
)
12563 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12564 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12565 to debug_file_directory. */
12566 const char *search_path
;
12567 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12569 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12572 if (*debug_file_directory
!= '\0')
12574 search_path_holder
.reset (concat (".", dirname_separator_string
,
12575 debug_file_directory
,
12577 search_path
= search_path_holder
.get ();
12583 search_path
= debug_file_directory
;
12585 openp_flags flags
= OPF_RETURN_REALPATH
;
12587 flags
|= OPF_SEARCH_IN_PATH
;
12589 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12590 desc
= openp (search_path
, flags
, file_name
,
12591 O_RDONLY
| O_BINARY
, &absolute_name
);
12595 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12597 if (sym_bfd
== NULL
)
12599 bfd_set_cacheable (sym_bfd
.get (), 1);
12601 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12604 /* Success. Record the bfd as having been included by the objfile's bfd.
12605 This is important because things like demangled_names_hash lives in the
12606 objfile's per_bfd space and may have references to things like symbol
12607 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12608 gdb_bfd_record_inclusion (per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12613 /* Try to open DWO file FILE_NAME.
12614 COMP_DIR is the DW_AT_comp_dir attribute.
12615 The result is the bfd handle of the file.
12616 If there is a problem finding or opening the file, return NULL.
12617 Upon success, the canonicalized path of the file is stored in the bfd,
12618 same as symfile_bfd_open. */
12620 static gdb_bfd_ref_ptr
12621 open_dwo_file (dwarf2_per_objfile
*per_objfile
,
12622 const char *file_name
, const char *comp_dir
)
12624 if (IS_ABSOLUTE_PATH (file_name
))
12625 return try_open_dwop_file (per_objfile
, file_name
,
12626 0 /*is_dwp*/, 0 /*search_cwd*/);
12628 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12630 if (comp_dir
!= NULL
)
12632 gdb::unique_xmalloc_ptr
<char> path_to_try
12633 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12635 /* NOTE: If comp_dir is a relative path, this will also try the
12636 search path, which seems useful. */
12637 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, path_to_try
.get (),
12639 1 /*search_cwd*/));
12644 /* That didn't work, try debug-file-directory, which, despite its name,
12645 is a list of paths. */
12647 if (*debug_file_directory
== '\0')
12650 return try_open_dwop_file (per_objfile
, file_name
,
12651 0 /*is_dwp*/, 1 /*search_cwd*/);
12654 /* This function is mapped across the sections and remembers the offset and
12655 size of each of the DWO debugging sections we are interested in. */
12658 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
,
12659 dwo_sections
*dwo_sections
)
12661 const struct dwop_section_names
*names
= &dwop_section_names
;
12663 if (names
->abbrev_dwo
.matches (sectp
->name
))
12665 dwo_sections
->abbrev
.s
.section
= sectp
;
12666 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12668 else if (names
->info_dwo
.matches (sectp
->name
))
12670 dwo_sections
->info
.s
.section
= sectp
;
12671 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12673 else if (names
->line_dwo
.matches (sectp
->name
))
12675 dwo_sections
->line
.s
.section
= sectp
;
12676 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12678 else if (names
->loc_dwo
.matches (sectp
->name
))
12680 dwo_sections
->loc
.s
.section
= sectp
;
12681 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12683 else if (names
->loclists_dwo
.matches (sectp
->name
))
12685 dwo_sections
->loclists
.s
.section
= sectp
;
12686 dwo_sections
->loclists
.size
= bfd_section_size (sectp
);
12688 else if (names
->macinfo_dwo
.matches (sectp
->name
))
12690 dwo_sections
->macinfo
.s
.section
= sectp
;
12691 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12693 else if (names
->macro_dwo
.matches (sectp
->name
))
12695 dwo_sections
->macro
.s
.section
= sectp
;
12696 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12698 else if (names
->rnglists_dwo
.matches (sectp
->name
))
12700 dwo_sections
->rnglists
.s
.section
= sectp
;
12701 dwo_sections
->rnglists
.size
= bfd_section_size (sectp
);
12703 else if (names
->str_dwo
.matches (sectp
->name
))
12705 dwo_sections
->str
.s
.section
= sectp
;
12706 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12708 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12710 dwo_sections
->str_offsets
.s
.section
= sectp
;
12711 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12713 else if (names
->types_dwo
.matches (sectp
->name
))
12715 struct dwarf2_section_info type_section
;
12717 memset (&type_section
, 0, sizeof (type_section
));
12718 type_section
.s
.section
= sectp
;
12719 type_section
.size
= bfd_section_size (sectp
);
12720 dwo_sections
->types
.push_back (type_section
);
12724 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12725 by PER_CU. This is for the non-DWP case.
12726 The result is NULL if DWO_NAME can't be found. */
12728 static struct dwo_file
*
12729 open_and_init_dwo_file (dwarf2_cu
*cu
, const char *dwo_name
,
12730 const char *comp_dir
)
12732 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
12734 gdb_bfd_ref_ptr dbfd
= open_dwo_file (per_objfile
, dwo_name
, comp_dir
);
12737 dwarf_read_debug_printf ("DWO file not found: %s", dwo_name
);
12742 dwo_file_up
dwo_file (new struct dwo_file
);
12743 dwo_file
->dwo_name
= dwo_name
;
12744 dwo_file
->comp_dir
= comp_dir
;
12745 dwo_file
->dbfd
= std::move (dbfd
);
12747 for (asection
*sec
: gdb_bfd_sections (dwo_file
->dbfd
))
12748 dwarf2_locate_dwo_sections (dwo_file
->dbfd
.get (), sec
,
12749 &dwo_file
->sections
);
12751 create_cus_hash_table (per_objfile
, cu
, *dwo_file
, dwo_file
->sections
.info
,
12754 if (cu
->per_cu
->dwarf_version
< 5)
12756 create_debug_types_hash_table (per_objfile
, dwo_file
.get (),
12757 dwo_file
->sections
.types
, dwo_file
->tus
);
12761 create_debug_type_hash_table (per_objfile
, dwo_file
.get (),
12762 &dwo_file
->sections
.info
, dwo_file
->tus
,
12763 rcuh_kind::COMPILE
);
12766 dwarf_read_debug_printf ("DWO file found: %s", dwo_name
);
12768 return dwo_file
.release ();
12771 /* This function is mapped across the sections and remembers the offset and
12772 size of each of the DWP debugging sections common to version 1 and 2 that
12773 we are interested in. */
12776 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12777 dwp_file
*dwp_file
)
12779 const struct dwop_section_names
*names
= &dwop_section_names
;
12780 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12782 /* Record the ELF section number for later lookup: this is what the
12783 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12784 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12785 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12787 /* Look for specific sections that we need. */
12788 if (names
->str_dwo
.matches (sectp
->name
))
12790 dwp_file
->sections
.str
.s
.section
= sectp
;
12791 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12793 else if (names
->cu_index
.matches (sectp
->name
))
12795 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12796 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12798 else if (names
->tu_index
.matches (sectp
->name
))
12800 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12801 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12805 /* This function is mapped across the sections and remembers the offset and
12806 size of each of the DWP version 2 debugging sections that we are interested
12807 in. This is split into a separate function because we don't know if we
12808 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
12811 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12813 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12814 const struct dwop_section_names
*names
= &dwop_section_names
;
12815 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12817 /* Record the ELF section number for later lookup: this is what the
12818 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12819 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12820 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12822 /* Look for specific sections that we need. */
12823 if (names
->abbrev_dwo
.matches (sectp
->name
))
12825 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12826 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12828 else if (names
->info_dwo
.matches (sectp
->name
))
12830 dwp_file
->sections
.info
.s
.section
= sectp
;
12831 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12833 else if (names
->line_dwo
.matches (sectp
->name
))
12835 dwp_file
->sections
.line
.s
.section
= sectp
;
12836 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12838 else if (names
->loc_dwo
.matches (sectp
->name
))
12840 dwp_file
->sections
.loc
.s
.section
= sectp
;
12841 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12843 else if (names
->macinfo_dwo
.matches (sectp
->name
))
12845 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12846 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12848 else if (names
->macro_dwo
.matches (sectp
->name
))
12850 dwp_file
->sections
.macro
.s
.section
= sectp
;
12851 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12853 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12855 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12856 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12858 else if (names
->types_dwo
.matches (sectp
->name
))
12860 dwp_file
->sections
.types
.s
.section
= sectp
;
12861 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12865 /* This function is mapped across the sections and remembers the offset and
12866 size of each of the DWP version 5 debugging sections that we are interested
12867 in. This is split into a separate function because we don't know if we
12868 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
12871 dwarf2_locate_v5_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12873 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12874 const struct dwop_section_names
*names
= &dwop_section_names
;
12875 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12877 /* Record the ELF section number for later lookup: this is what the
12878 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12879 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12880 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12882 /* Look for specific sections that we need. */
12883 if (names
->abbrev_dwo
.matches (sectp
->name
))
12885 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12886 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12888 else if (names
->info_dwo
.matches (sectp
->name
))
12890 dwp_file
->sections
.info
.s
.section
= sectp
;
12891 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12893 else if (names
->line_dwo
.matches (sectp
->name
))
12895 dwp_file
->sections
.line
.s
.section
= sectp
;
12896 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12898 else if (names
->loclists_dwo
.matches (sectp
->name
))
12900 dwp_file
->sections
.loclists
.s
.section
= sectp
;
12901 dwp_file
->sections
.loclists
.size
= bfd_section_size (sectp
);
12903 else if (names
->macro_dwo
.matches (sectp
->name
))
12905 dwp_file
->sections
.macro
.s
.section
= sectp
;
12906 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12908 else if (names
->rnglists_dwo
.matches (sectp
->name
))
12910 dwp_file
->sections
.rnglists
.s
.section
= sectp
;
12911 dwp_file
->sections
.rnglists
.size
= bfd_section_size (sectp
);
12913 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12915 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12916 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12920 /* Hash function for dwp_file loaded CUs/TUs. */
12923 hash_dwp_loaded_cutus (const void *item
)
12925 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12927 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12928 return dwo_unit
->signature
;
12931 /* Equality function for dwp_file loaded CUs/TUs. */
12934 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12936 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12937 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12939 return dua
->signature
== dub
->signature
;
12942 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12945 allocate_dwp_loaded_cutus_table ()
12947 return htab_up (htab_create_alloc (3,
12948 hash_dwp_loaded_cutus
,
12949 eq_dwp_loaded_cutus
,
12950 NULL
, xcalloc
, xfree
));
12953 /* Try to open DWP file FILE_NAME.
12954 The result is the bfd handle of the file.
12955 If there is a problem finding or opening the file, return NULL.
12956 Upon success, the canonicalized path of the file is stored in the bfd,
12957 same as symfile_bfd_open. */
12959 static gdb_bfd_ref_ptr
12960 open_dwp_file (dwarf2_per_objfile
*per_objfile
, const char *file_name
)
12962 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, file_name
,
12964 1 /*search_cwd*/));
12968 /* Work around upstream bug 15652.
12969 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12970 [Whether that's a "bug" is debatable, but it is getting in our way.]
12971 We have no real idea where the dwp file is, because gdb's realpath-ing
12972 of the executable's path may have discarded the needed info.
12973 [IWBN if the dwp file name was recorded in the executable, akin to
12974 .gnu_debuglink, but that doesn't exist yet.]
12975 Strip the directory from FILE_NAME and search again. */
12976 if (*debug_file_directory
!= '\0')
12978 /* Don't implicitly search the current directory here.
12979 If the user wants to search "." to handle this case,
12980 it must be added to debug-file-directory. */
12981 return try_open_dwop_file (per_objfile
, lbasename (file_name
),
12989 /* Initialize the use of the DWP file for the current objfile.
12990 By convention the name of the DWP file is ${objfile}.dwp.
12991 The result is NULL if it can't be found. */
12993 static std::unique_ptr
<struct dwp_file
>
12994 open_and_init_dwp_file (dwarf2_per_objfile
*per_objfile
)
12996 struct objfile
*objfile
= per_objfile
->objfile
;
12998 /* Try to find first .dwp for the binary file before any symbolic links
13001 /* If the objfile is a debug file, find the name of the real binary
13002 file and get the name of dwp file from there. */
13003 std::string dwp_name
;
13004 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
13006 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
13007 const char *backlink_basename
= lbasename (backlink
->original_name
);
13009 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
13012 dwp_name
= objfile
->original_name
;
13014 dwp_name
+= ".dwp";
13016 gdb_bfd_ref_ptr
dbfd (open_dwp_file (per_objfile
, dwp_name
.c_str ()));
13018 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
13020 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
13021 dwp_name
= objfile_name (objfile
);
13022 dwp_name
+= ".dwp";
13023 dbfd
= open_dwp_file (per_objfile
, dwp_name
.c_str ());
13028 dwarf_read_debug_printf ("DWP file not found: %s", dwp_name
.c_str ());
13030 return std::unique_ptr
<dwp_file
> ();
13033 const char *name
= bfd_get_filename (dbfd
.get ());
13034 std::unique_ptr
<struct dwp_file
> dwp_file
13035 (new struct dwp_file (name
, std::move (dbfd
)));
13037 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
13038 dwp_file
->elf_sections
=
13039 OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
13040 dwp_file
->num_sections
, asection
*);
13042 for (asection
*sec
: gdb_bfd_sections (dwp_file
->dbfd
))
13043 dwarf2_locate_common_dwp_sections (dwp_file
->dbfd
.get (), sec
,
13046 dwp_file
->cus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 0);
13048 dwp_file
->tus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 1);
13050 /* The DWP file version is stored in the hash table. Oh well. */
13051 if (dwp_file
->cus
&& dwp_file
->tus
13052 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
13054 /* Technically speaking, we should try to limp along, but this is
13055 pretty bizarre. We use pulongest here because that's the established
13056 portability solution (e.g, we cannot use %u for uint32_t). */
13057 error (_("Dwarf Error: DWP file CU version %s doesn't match"
13058 " TU version %s [in DWP file %s]"),
13059 pulongest (dwp_file
->cus
->version
),
13060 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
13064 dwp_file
->version
= dwp_file
->cus
->version
;
13065 else if (dwp_file
->tus
)
13066 dwp_file
->version
= dwp_file
->tus
->version
;
13068 dwp_file
->version
= 2;
13070 for (asection
*sec
: gdb_bfd_sections (dwp_file
->dbfd
))
13072 if (dwp_file
->version
== 2)
13073 dwarf2_locate_v2_dwp_sections (dwp_file
->dbfd
.get (), sec
,
13076 dwarf2_locate_v5_dwp_sections (dwp_file
->dbfd
.get (), sec
,
13080 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
13081 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
13083 dwarf_read_debug_printf ("DWP file found: %s", dwp_file
->name
);
13084 dwarf_read_debug_printf (" %s CUs, %s TUs",
13085 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
13086 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
13091 /* Wrapper around open_and_init_dwp_file, only open it once. */
13093 static struct dwp_file
*
13094 get_dwp_file (dwarf2_per_objfile
*per_objfile
)
13096 if (!per_objfile
->per_bfd
->dwp_checked
)
13098 per_objfile
->per_bfd
->dwp_file
= open_and_init_dwp_file (per_objfile
);
13099 per_objfile
->per_bfd
->dwp_checked
= 1;
13101 return per_objfile
->per_bfd
->dwp_file
.get ();
13104 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
13105 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
13106 or in the DWP file for the objfile, referenced by THIS_UNIT.
13107 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
13108 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
13110 This is called, for example, when wanting to read a variable with a
13111 complex location. Therefore we don't want to do file i/o for every call.
13112 Therefore we don't want to look for a DWO file on every call.
13113 Therefore we first see if we've already seen SIGNATURE in a DWP file,
13114 then we check if we've already seen DWO_NAME, and only THEN do we check
13117 The result is a pointer to the dwo_unit object or NULL if we didn't find it
13118 (dwo_id mismatch or couldn't find the DWO/DWP file). */
13120 static struct dwo_unit
*
13121 lookup_dwo_cutu (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
13122 ULONGEST signature
, int is_debug_types
)
13124 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13125 struct objfile
*objfile
= per_objfile
->objfile
;
13126 const char *kind
= is_debug_types
? "TU" : "CU";
13127 void **dwo_file_slot
;
13128 struct dwo_file
*dwo_file
;
13129 struct dwp_file
*dwp_file
;
13131 /* First see if there's a DWP file.
13132 If we have a DWP file but didn't find the DWO inside it, don't
13133 look for the original DWO file. It makes gdb behave differently
13134 depending on whether one is debugging in the build tree. */
13136 dwp_file
= get_dwp_file (per_objfile
);
13137 if (dwp_file
!= NULL
)
13139 const struct dwp_hash_table
*dwp_htab
=
13140 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
13142 if (dwp_htab
!= NULL
)
13144 struct dwo_unit
*dwo_cutu
=
13145 lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, comp_dir
, signature
,
13148 if (dwo_cutu
!= NULL
)
13150 dwarf_read_debug_printf ("Virtual DWO %s %s found: @%s",
13151 kind
, hex_string (signature
),
13152 host_address_to_string (dwo_cutu
));
13160 /* No DWP file, look for the DWO file. */
13162 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, dwo_name
, comp_dir
);
13163 if (*dwo_file_slot
== NULL
)
13165 /* Read in the file and build a table of the CUs/TUs it contains. */
13166 *dwo_file_slot
= open_and_init_dwo_file (cu
, dwo_name
, comp_dir
);
13168 /* NOTE: This will be NULL if unable to open the file. */
13169 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
13171 if (dwo_file
!= NULL
)
13173 struct dwo_unit
*dwo_cutu
= NULL
;
13175 if (is_debug_types
&& dwo_file
->tus
)
13177 struct dwo_unit find_dwo_cutu
;
13179 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13180 find_dwo_cutu
.signature
= signature
;
13182 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
13185 else if (!is_debug_types
&& dwo_file
->cus
)
13187 struct dwo_unit find_dwo_cutu
;
13189 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13190 find_dwo_cutu
.signature
= signature
;
13191 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
13195 if (dwo_cutu
!= NULL
)
13197 dwarf_read_debug_printf ("DWO %s %s(%s) found: @%s",
13198 kind
, dwo_name
, hex_string (signature
),
13199 host_address_to_string (dwo_cutu
));
13206 /* We didn't find it. This could mean a dwo_id mismatch, or
13207 someone deleted the DWO/DWP file, or the search path isn't set up
13208 correctly to find the file. */
13210 dwarf_read_debug_printf ("DWO %s %s(%s) not found",
13211 kind
, dwo_name
, hex_string (signature
));
13213 /* This is a warning and not a complaint because it can be caused by
13214 pilot error (e.g., user accidentally deleting the DWO). */
13216 /* Print the name of the DWP file if we looked there, helps the user
13217 better diagnose the problem. */
13218 std::string dwp_text
;
13220 if (dwp_file
!= NULL
)
13221 dwp_text
= string_printf (" [in DWP file %s]",
13222 lbasename (dwp_file
->name
));
13224 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
13225 " [in module %s]"),
13226 kind
, dwo_name
, hex_string (signature
), dwp_text
.c_str (), kind
,
13227 sect_offset_str (cu
->per_cu
->sect_off
), objfile_name (objfile
));
13232 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
13233 See lookup_dwo_cutu_unit for details. */
13235 static struct dwo_unit
*
13236 lookup_dwo_comp_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
13237 ULONGEST signature
)
13239 gdb_assert (!cu
->per_cu
->is_debug_types
);
13241 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, signature
, 0);
13244 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
13245 See lookup_dwo_cutu_unit for details. */
13247 static struct dwo_unit
*
13248 lookup_dwo_type_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
)
13250 gdb_assert (cu
->per_cu
->is_debug_types
);
13252 signatured_type
*sig_type
= (signatured_type
*) cu
->per_cu
;
13254 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, sig_type
->signature
, 1);
13257 /* Traversal function for queue_and_load_all_dwo_tus. */
13260 queue_and_load_dwo_tu (void **slot
, void *info
)
13262 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
13263 dwarf2_cu
*cu
= (dwarf2_cu
*) info
;
13264 ULONGEST signature
= dwo_unit
->signature
;
13265 signatured_type
*sig_type
= lookup_dwo_signatured_type (cu
, signature
);
13267 if (sig_type
!= NULL
)
13269 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
13271 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
13272 a real dependency of PER_CU on SIG_TYPE. That is detected later
13273 while processing PER_CU. */
13274 if (maybe_queue_comp_unit (NULL
, sig_cu
, cu
->per_objfile
, cu
->language
))
13275 load_full_type_unit (sig_cu
, cu
->per_objfile
);
13276 cu
->per_cu
->imported_symtabs_push (sig_cu
);
13282 /* Queue all TUs contained in the DWO of CU to be read in.
13283 The DWO may have the only definition of the type, though it may not be
13284 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
13285 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
13288 queue_and_load_all_dwo_tus (dwarf2_cu
*cu
)
13290 struct dwo_unit
*dwo_unit
;
13291 struct dwo_file
*dwo_file
;
13293 gdb_assert (cu
!= nullptr);
13294 gdb_assert (!cu
->per_cu
->is_debug_types
);
13295 gdb_assert (get_dwp_file (cu
->per_objfile
) == nullptr);
13297 dwo_unit
= cu
->dwo_unit
;
13298 gdb_assert (dwo_unit
!= NULL
);
13300 dwo_file
= dwo_unit
->dwo_file
;
13301 if (dwo_file
->tus
!= NULL
)
13302 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
, cu
);
13305 /* Read in various DIEs. */
13307 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
13308 Inherit only the children of the DW_AT_abstract_origin DIE not being
13309 already referenced by DW_AT_abstract_origin from the children of the
13313 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
13315 struct die_info
*child_die
;
13316 sect_offset
*offsetp
;
13317 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
13318 struct die_info
*origin_die
;
13319 /* Iterator of the ORIGIN_DIE children. */
13320 struct die_info
*origin_child_die
;
13321 struct attribute
*attr
;
13322 struct dwarf2_cu
*origin_cu
;
13323 struct pending
**origin_previous_list_in_scope
;
13325 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13329 /* Note that following die references may follow to a die in a
13333 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
13335 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
13337 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
13338 origin_cu
->list_in_scope
= cu
->list_in_scope
;
13340 if (die
->tag
!= origin_die
->tag
13341 && !(die
->tag
== DW_TAG_inlined_subroutine
13342 && origin_die
->tag
== DW_TAG_subprogram
))
13343 complaint (_("DIE %s and its abstract origin %s have different tags"),
13344 sect_offset_str (die
->sect_off
),
13345 sect_offset_str (origin_die
->sect_off
));
13347 std::vector
<sect_offset
> offsets
;
13349 for (child_die
= die
->child
;
13350 child_die
&& child_die
->tag
;
13351 child_die
= child_die
->sibling
)
13353 struct die_info
*child_origin_die
;
13354 struct dwarf2_cu
*child_origin_cu
;
13356 /* We are trying to process concrete instance entries:
13357 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
13358 it's not relevant to our analysis here. i.e. detecting DIEs that are
13359 present in the abstract instance but not referenced in the concrete
13361 if (child_die
->tag
== DW_TAG_call_site
13362 || child_die
->tag
== DW_TAG_GNU_call_site
)
13365 /* For each CHILD_DIE, find the corresponding child of
13366 ORIGIN_DIE. If there is more than one layer of
13367 DW_AT_abstract_origin, follow them all; there shouldn't be,
13368 but GCC versions at least through 4.4 generate this (GCC PR
13370 child_origin_die
= child_die
;
13371 child_origin_cu
= cu
;
13374 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
13378 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
13382 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
13383 counterpart may exist. */
13384 if (child_origin_die
!= child_die
)
13386 if (child_die
->tag
!= child_origin_die
->tag
13387 && !(child_die
->tag
== DW_TAG_inlined_subroutine
13388 && child_origin_die
->tag
== DW_TAG_subprogram
))
13389 complaint (_("Child DIE %s and its abstract origin %s have "
13391 sect_offset_str (child_die
->sect_off
),
13392 sect_offset_str (child_origin_die
->sect_off
));
13393 if (child_origin_die
->parent
!= origin_die
)
13394 complaint (_("Child DIE %s and its abstract origin %s have "
13395 "different parents"),
13396 sect_offset_str (child_die
->sect_off
),
13397 sect_offset_str (child_origin_die
->sect_off
));
13399 offsets
.push_back (child_origin_die
->sect_off
);
13402 std::sort (offsets
.begin (), offsets
.end ());
13403 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
13404 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
13405 if (offsetp
[-1] == *offsetp
)
13406 complaint (_("Multiple children of DIE %s refer "
13407 "to DIE %s as their abstract origin"),
13408 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
13410 offsetp
= offsets
.data ();
13411 origin_child_die
= origin_die
->child
;
13412 while (origin_child_die
&& origin_child_die
->tag
)
13414 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13415 while (offsetp
< offsets_end
13416 && *offsetp
< origin_child_die
->sect_off
)
13418 if (offsetp
>= offsets_end
13419 || *offsetp
> origin_child_die
->sect_off
)
13421 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13422 Check whether we're already processing ORIGIN_CHILD_DIE.
13423 This can happen with mutually referenced abstract_origins.
13425 if (!origin_child_die
->in_process
)
13426 process_die (origin_child_die
, origin_cu
);
13428 origin_child_die
= origin_child_die
->sibling
;
13430 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13432 if (cu
!= origin_cu
)
13433 compute_delayed_physnames (origin_cu
);
13437 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13439 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13440 struct gdbarch
*gdbarch
= objfile
->arch ();
13441 struct context_stack
*newobj
;
13444 struct die_info
*child_die
;
13445 struct attribute
*attr
, *call_line
, *call_file
;
13447 CORE_ADDR baseaddr
;
13448 struct block
*block
;
13449 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13450 std::vector
<struct symbol
*> template_args
;
13451 struct template_symbol
*templ_func
= NULL
;
13455 /* If we do not have call site information, we can't show the
13456 caller of this inlined function. That's too confusing, so
13457 only use the scope for local variables. */
13458 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13459 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13460 if (call_line
== NULL
|| call_file
== NULL
)
13462 read_lexical_block_scope (die
, cu
);
13467 baseaddr
= objfile
->text_section_offset ();
13469 name
= dwarf2_name (die
, cu
);
13471 /* Ignore functions with missing or empty names. These are actually
13472 illegal according to the DWARF standard. */
13475 complaint (_("missing name for subprogram DIE at %s"),
13476 sect_offset_str (die
->sect_off
));
13480 /* Ignore functions with missing or invalid low and high pc attributes. */
13481 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13482 <= PC_BOUNDS_INVALID
)
13484 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13485 if (attr
== nullptr || !attr
->as_boolean ())
13486 complaint (_("cannot get low and high bounds "
13487 "for subprogram DIE at %s"),
13488 sect_offset_str (die
->sect_off
));
13492 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13493 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13495 /* If we have any template arguments, then we must allocate a
13496 different sort of symbol. */
13497 for (child_die
= die
->child
; child_die
; child_die
= child_die
->sibling
)
13499 if (child_die
->tag
== DW_TAG_template_type_param
13500 || child_die
->tag
== DW_TAG_template_value_param
)
13502 templ_func
= new (&objfile
->objfile_obstack
) template_symbol
;
13503 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13508 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13509 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13510 (struct symbol
*) templ_func
);
13512 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13513 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
13516 /* If there is a location expression for DW_AT_frame_base, record
13518 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13519 if (attr
!= nullptr)
13520 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13522 /* If there is a location for the static link, record it. */
13523 newobj
->static_link
= NULL
;
13524 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13525 if (attr
!= nullptr)
13527 newobj
->static_link
13528 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13529 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13533 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13535 if (die
->child
!= NULL
)
13537 child_die
= die
->child
;
13538 while (child_die
&& child_die
->tag
)
13540 if (child_die
->tag
== DW_TAG_template_type_param
13541 || child_die
->tag
== DW_TAG_template_value_param
)
13543 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13546 template_args
.push_back (arg
);
13549 process_die (child_die
, cu
);
13550 child_die
= child_die
->sibling
;
13554 inherit_abstract_dies (die
, cu
);
13556 /* If we have a DW_AT_specification, we might need to import using
13557 directives from the context of the specification DIE. See the
13558 comment in determine_prefix. */
13559 if (cu
->language
== language_cplus
13560 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13562 struct dwarf2_cu
*spec_cu
= cu
;
13563 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13567 child_die
= spec_die
->child
;
13568 while (child_die
&& child_die
->tag
)
13570 if (child_die
->tag
== DW_TAG_imported_module
)
13571 process_die (child_die
, spec_cu
);
13572 child_die
= child_die
->sibling
;
13575 /* In some cases, GCC generates specification DIEs that
13576 themselves contain DW_AT_specification attributes. */
13577 spec_die
= die_specification (spec_die
, &spec_cu
);
13581 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13582 /* Make a block for the local symbols within. */
13583 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13584 cstk
.static_link
, lowpc
, highpc
);
13586 /* For C++, set the block's scope. */
13587 if ((cu
->language
== language_cplus
13588 || cu
->language
== language_fortran
13589 || cu
->language
== language_d
13590 || cu
->language
== language_rust
)
13591 && cu
->processing_has_namespace_info
)
13592 block_set_scope (block
, determine_prefix (die
, cu
),
13593 &objfile
->objfile_obstack
);
13595 /* If we have address ranges, record them. */
13596 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13598 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13600 /* Attach template arguments to function. */
13601 if (!template_args
.empty ())
13603 gdb_assert (templ_func
!= NULL
);
13605 templ_func
->n_template_arguments
= template_args
.size ();
13606 templ_func
->template_arguments
13607 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13608 templ_func
->n_template_arguments
);
13609 memcpy (templ_func
->template_arguments
,
13610 template_args
.data (),
13611 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13613 /* Make sure that the symtab is set on the new symbols. Even
13614 though they don't appear in this symtab directly, other parts
13615 of gdb assume that symbols do, and this is reasonably
13617 for (symbol
*sym
: template_args
)
13618 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13621 /* In C++, we can have functions nested inside functions (e.g., when
13622 a function declares a class that has methods). This means that
13623 when we finish processing a function scope, we may need to go
13624 back to building a containing block's symbol lists. */
13625 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13626 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13628 /* If we've finished processing a top-level function, subsequent
13629 symbols go in the file symbol list. */
13630 if (cu
->get_builder ()->outermost_context_p ())
13631 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13634 /* Process all the DIES contained within a lexical block scope. Start
13635 a new scope, process the dies, and then close the scope. */
13638 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13640 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13641 struct gdbarch
*gdbarch
= objfile
->arch ();
13642 CORE_ADDR lowpc
, highpc
;
13643 struct die_info
*child_die
;
13644 CORE_ADDR baseaddr
;
13646 baseaddr
= objfile
->text_section_offset ();
13648 /* Ignore blocks with missing or invalid low and high pc attributes. */
13649 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13650 as multiple lexical blocks? Handling children in a sane way would
13651 be nasty. Might be easier to properly extend generic blocks to
13652 describe ranges. */
13653 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13655 case PC_BOUNDS_NOT_PRESENT
:
13656 /* DW_TAG_lexical_block has no attributes, process its children as if
13657 there was no wrapping by that DW_TAG_lexical_block.
13658 GCC does no longer produces such DWARF since GCC r224161. */
13659 for (child_die
= die
->child
;
13660 child_die
!= NULL
&& child_die
->tag
;
13661 child_die
= child_die
->sibling
)
13663 /* We might already be processing this DIE. This can happen
13664 in an unusual circumstance -- where a subroutine A
13665 appears lexically in another subroutine B, but A actually
13666 inlines B. The recursion is broken here, rather than in
13667 inherit_abstract_dies, because it seems better to simply
13668 drop concrete children here. */
13669 if (!child_die
->in_process
)
13670 process_die (child_die
, cu
);
13673 case PC_BOUNDS_INVALID
:
13676 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13677 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13679 cu
->get_builder ()->push_context (0, lowpc
);
13680 if (die
->child
!= NULL
)
13682 child_die
= die
->child
;
13683 while (child_die
&& child_die
->tag
)
13685 process_die (child_die
, cu
);
13686 child_die
= child_die
->sibling
;
13689 inherit_abstract_dies (die
, cu
);
13690 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13692 if (*cu
->get_builder ()->get_local_symbols () != NULL
13693 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13695 struct block
*block
13696 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13697 cstk
.start_addr
, highpc
);
13699 /* Note that recording ranges after traversing children, as we
13700 do here, means that recording a parent's ranges entails
13701 walking across all its children's ranges as they appear in
13702 the address map, which is quadratic behavior.
13704 It would be nicer to record the parent's ranges before
13705 traversing its children, simply overriding whatever you find
13706 there. But since we don't even decide whether to create a
13707 block until after we've traversed its children, that's hard
13709 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13711 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13712 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13715 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13718 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13720 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13721 struct objfile
*objfile
= per_objfile
->objfile
;
13722 struct gdbarch
*gdbarch
= objfile
->arch ();
13723 CORE_ADDR pc
, baseaddr
;
13724 struct attribute
*attr
;
13725 struct call_site
*call_site
, call_site_local
;
13728 struct die_info
*child_die
;
13730 baseaddr
= objfile
->text_section_offset ();
13732 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13735 /* This was a pre-DWARF-5 GNU extension alias
13736 for DW_AT_call_return_pc. */
13737 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13741 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13742 "DIE %s [in module %s]"),
13743 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13746 pc
= attr
->as_address () + baseaddr
;
13747 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13749 if (cu
->call_site_htab
== NULL
)
13750 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13751 NULL
, &objfile
->objfile_obstack
,
13752 hashtab_obstack_allocate
, NULL
);
13753 call_site_local
.pc
= pc
;
13754 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13757 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13758 "DIE %s [in module %s]"),
13759 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13760 objfile_name (objfile
));
13764 /* Count parameters at the caller. */
13767 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13768 child_die
= child_die
->sibling
)
13770 if (child_die
->tag
!= DW_TAG_call_site_parameter
13771 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13773 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13774 "DW_TAG_call_site child DIE %s [in module %s]"),
13775 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13776 objfile_name (objfile
));
13784 = ((struct call_site
*)
13785 obstack_alloc (&objfile
->objfile_obstack
,
13786 sizeof (*call_site
)
13787 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13789 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13790 call_site
->pc
= pc
;
13792 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13793 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13795 struct die_info
*func_die
;
13797 /* Skip also over DW_TAG_inlined_subroutine. */
13798 for (func_die
= die
->parent
;
13799 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13800 && func_die
->tag
!= DW_TAG_subroutine_type
;
13801 func_die
= func_die
->parent
);
13803 /* DW_AT_call_all_calls is a superset
13804 of DW_AT_call_all_tail_calls. */
13806 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13807 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13808 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13809 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13811 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13812 not complete. But keep CALL_SITE for look ups via call_site_htab,
13813 both the initial caller containing the real return address PC and
13814 the final callee containing the current PC of a chain of tail
13815 calls do not need to have the tail call list complete. But any
13816 function candidate for a virtual tail call frame searched via
13817 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13818 determined unambiguously. */
13822 struct type
*func_type
= NULL
;
13825 func_type
= get_die_type (func_die
, cu
);
13826 if (func_type
!= NULL
)
13828 gdb_assert (func_type
->code () == TYPE_CODE_FUNC
);
13830 /* Enlist this call site to the function. */
13831 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13832 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13835 complaint (_("Cannot find function owning DW_TAG_call_site "
13836 "DIE %s [in module %s]"),
13837 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13841 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13843 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13845 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13848 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13849 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13851 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13852 if (!attr
|| (attr
->form_is_block () && attr
->as_block ()->size
== 0))
13853 /* Keep NULL DWARF_BLOCK. */;
13854 else if (attr
->form_is_block ())
13856 struct dwarf2_locexpr_baton
*dlbaton
;
13857 struct dwarf_block
*block
= attr
->as_block ();
13859 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13860 dlbaton
->data
= block
->data
;
13861 dlbaton
->size
= block
->size
;
13862 dlbaton
->per_objfile
= per_objfile
;
13863 dlbaton
->per_cu
= cu
->per_cu
;
13865 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13867 else if (attr
->form_is_ref ())
13869 struct dwarf2_cu
*target_cu
= cu
;
13870 struct die_info
*target_die
;
13872 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13873 gdb_assert (target_cu
->per_objfile
->objfile
== objfile
);
13874 if (die_is_declaration (target_die
, target_cu
))
13876 const char *target_physname
;
13878 /* Prefer the mangled name; otherwise compute the demangled one. */
13879 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13880 if (target_physname
== NULL
)
13881 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13882 if (target_physname
== NULL
)
13883 complaint (_("DW_AT_call_target target DIE has invalid "
13884 "physname, for referencing DIE %s [in module %s]"),
13885 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13887 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13893 /* DW_AT_entry_pc should be preferred. */
13894 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13895 <= PC_BOUNDS_INVALID
)
13896 complaint (_("DW_AT_call_target target DIE has invalid "
13897 "low pc, for referencing DIE %s [in module %s]"),
13898 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13901 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13902 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
13907 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13908 "block nor reference, for DIE %s [in module %s]"),
13909 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13911 call_site
->per_cu
= cu
->per_cu
;
13912 call_site
->per_objfile
= per_objfile
;
13914 for (child_die
= die
->child
;
13915 child_die
&& child_die
->tag
;
13916 child_die
= child_die
->sibling
)
13918 struct call_site_parameter
*parameter
;
13919 struct attribute
*loc
, *origin
;
13921 if (child_die
->tag
!= DW_TAG_call_site_parameter
13922 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13924 /* Already printed the complaint above. */
13928 gdb_assert (call_site
->parameter_count
< nparams
);
13929 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13931 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13932 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13933 register is contained in DW_AT_call_value. */
13935 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13936 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13937 if (origin
== NULL
)
13939 /* This was a pre-DWARF-5 GNU extension alias
13940 for DW_AT_call_parameter. */
13941 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13943 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
13945 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13947 sect_offset sect_off
= origin
->get_ref_die_offset ();
13948 if (!cu
->header
.offset_in_cu_p (sect_off
))
13950 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13951 binding can be done only inside one CU. Such referenced DIE
13952 therefore cannot be even moved to DW_TAG_partial_unit. */
13953 complaint (_("DW_AT_call_parameter offset is not in CU for "
13954 "DW_TAG_call_site child DIE %s [in module %s]"),
13955 sect_offset_str (child_die
->sect_off
),
13956 objfile_name (objfile
));
13959 parameter
->u
.param_cu_off
13960 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13962 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
13964 complaint (_("No DW_FORM_block* DW_AT_location for "
13965 "DW_TAG_call_site child DIE %s [in module %s]"),
13966 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13971 struct dwarf_block
*block
= loc
->as_block ();
13973 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13974 (block
->data
, &block
->data
[block
->size
]);
13975 if (parameter
->u
.dwarf_reg
!= -1)
13976 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13977 else if (dwarf_block_to_sp_offset (gdbarch
, block
->data
,
13978 &block
->data
[block
->size
],
13979 ¶meter
->u
.fb_offset
))
13980 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13983 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13984 "for DW_FORM_block* DW_AT_location is supported for "
13985 "DW_TAG_call_site child DIE %s "
13987 sect_offset_str (child_die
->sect_off
),
13988 objfile_name (objfile
));
13993 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13995 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13996 if (attr
== NULL
|| !attr
->form_is_block ())
13998 complaint (_("No DW_FORM_block* DW_AT_call_value for "
13999 "DW_TAG_call_site child DIE %s [in module %s]"),
14000 sect_offset_str (child_die
->sect_off
),
14001 objfile_name (objfile
));
14005 struct dwarf_block
*block
= attr
->as_block ();
14006 parameter
->value
= block
->data
;
14007 parameter
->value_size
= block
->size
;
14009 /* Parameters are not pre-cleared by memset above. */
14010 parameter
->data_value
= NULL
;
14011 parameter
->data_value_size
= 0;
14012 call_site
->parameter_count
++;
14014 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
14016 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
14017 if (attr
!= nullptr)
14019 if (!attr
->form_is_block ())
14020 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
14021 "DW_TAG_call_site child DIE %s [in module %s]"),
14022 sect_offset_str (child_die
->sect_off
),
14023 objfile_name (objfile
));
14026 block
= attr
->as_block ();
14027 parameter
->data_value
= block
->data
;
14028 parameter
->data_value_size
= block
->size
;
14034 /* Helper function for read_variable. If DIE represents a virtual
14035 table, then return the type of the concrete object that is
14036 associated with the virtual table. Otherwise, return NULL. */
14038 static struct type
*
14039 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14041 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
14045 /* Find the type DIE. */
14046 struct die_info
*type_die
= NULL
;
14047 struct dwarf2_cu
*type_cu
= cu
;
14049 if (attr
->form_is_ref ())
14050 type_die
= follow_die_ref (die
, attr
, &type_cu
);
14051 if (type_die
== NULL
)
14054 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
14056 return die_containing_type (type_die
, type_cu
);
14059 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
14062 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
14064 struct rust_vtable_symbol
*storage
= NULL
;
14066 if (cu
->language
== language_rust
)
14068 struct type
*containing_type
= rust_containing_type (die
, cu
);
14070 if (containing_type
!= NULL
)
14072 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14074 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol
;
14075 storage
->concrete_type
= containing_type
;
14076 storage
->subclass
= SYMBOL_RUST_VTABLE
;
14080 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
14081 struct attribute
*abstract_origin
14082 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
14083 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
14084 if (res
== NULL
&& loc
&& abstract_origin
)
14086 /* We have a variable without a name, but with a location and an abstract
14087 origin. This may be a concrete instance of an abstract variable
14088 referenced from an DW_OP_GNU_variable_value, so save it to find it back
14090 struct dwarf2_cu
*origin_cu
= cu
;
14091 struct die_info
*origin_die
14092 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
14093 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14094 per_objfile
->per_bfd
->abstract_to_concrete
14095 [origin_die
->sect_off
].push_back (die
->sect_off
);
14099 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
14100 reading .debug_rnglists.
14101 Callback's type should be:
14102 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14103 Return true if the attributes are present and valid, otherwise,
14106 template <typename Callback
>
14108 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
14109 dwarf_tag tag
, Callback
&&callback
)
14111 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14112 struct objfile
*objfile
= per_objfile
->objfile
;
14113 bfd
*obfd
= objfile
->obfd
;
14114 /* Base address selection entry. */
14115 gdb::optional
<CORE_ADDR
> base
;
14116 const gdb_byte
*buffer
;
14117 CORE_ADDR baseaddr
;
14118 bool overflow
= false;
14119 ULONGEST addr_index
;
14120 struct dwarf2_section_info
*rnglists_section
;
14122 base
= cu
->base_address
;
14123 rnglists_section
= cu_debug_rnglists_section (cu
, tag
);
14124 rnglists_section
->read (objfile
);
14126 if (offset
>= rnglists_section
->size
)
14128 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14132 buffer
= rnglists_section
->buffer
+ offset
;
14134 baseaddr
= objfile
->text_section_offset ();
14138 /* Initialize it due to a false compiler warning. */
14139 CORE_ADDR range_beginning
= 0, range_end
= 0;
14140 const gdb_byte
*buf_end
= (rnglists_section
->buffer
14141 + rnglists_section
->size
);
14142 unsigned int bytes_read
;
14144 if (buffer
== buf_end
)
14149 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
14152 case DW_RLE_end_of_list
:
14154 case DW_RLE_base_address
:
14155 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14160 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
14161 buffer
+= bytes_read
;
14163 case DW_RLE_base_addressx
:
14164 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14165 buffer
+= bytes_read
;
14166 base
= read_addr_index (cu
, addr_index
);
14168 case DW_RLE_start_length
:
14169 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14174 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
14176 buffer
+= bytes_read
;
14177 range_end
= (range_beginning
14178 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
14179 buffer
+= bytes_read
;
14180 if (buffer
> buf_end
)
14186 case DW_RLE_startx_length
:
14187 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14188 buffer
+= bytes_read
;
14189 range_beginning
= read_addr_index (cu
, addr_index
);
14190 if (buffer
> buf_end
)
14195 range_end
= (range_beginning
14196 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
14197 buffer
+= bytes_read
;
14199 case DW_RLE_offset_pair
:
14200 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14201 buffer
+= bytes_read
;
14202 if (buffer
> buf_end
)
14207 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14208 buffer
+= bytes_read
;
14209 if (buffer
> buf_end
)
14215 case DW_RLE_start_end
:
14216 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
14221 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
14223 buffer
+= bytes_read
;
14224 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
14225 buffer
+= bytes_read
;
14227 case DW_RLE_startx_endx
:
14228 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14229 buffer
+= bytes_read
;
14230 range_beginning
= read_addr_index (cu
, addr_index
);
14231 if (buffer
> buf_end
)
14236 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14237 buffer
+= bytes_read
;
14238 range_end
= read_addr_index (cu
, addr_index
);
14241 complaint (_("Invalid .debug_rnglists data (no base address)"));
14244 if (rlet
== DW_RLE_end_of_list
|| overflow
)
14246 if (rlet
== DW_RLE_base_address
)
14249 if (range_beginning
> range_end
)
14251 /* Inverted range entries are invalid. */
14252 complaint (_("Invalid .debug_rnglists data (inverted range)"));
14256 /* Empty range entries have no effect. */
14257 if (range_beginning
== range_end
)
14260 /* Only DW_RLE_offset_pair needs the base address added. */
14261 if (rlet
== DW_RLE_offset_pair
)
14263 if (!base
.has_value ())
14265 /* We have no valid base address for the DW_RLE_offset_pair. */
14266 complaint (_("Invalid .debug_rnglists data (no base address for "
14267 "DW_RLE_offset_pair)"));
14271 range_beginning
+= *base
;
14272 range_end
+= *base
;
14275 /* A not-uncommon case of bad debug info.
14276 Don't pollute the addrmap with bad data. */
14277 if (range_beginning
+ baseaddr
== 0
14278 && !per_objfile
->per_bfd
->has_section_at_zero
)
14280 complaint (_(".debug_rnglists entry has start address of zero"
14281 " [in module %s]"), objfile_name (objfile
));
14285 callback (range_beginning
, range_end
);
14290 complaint (_("Offset %d is not terminated "
14291 "for DW_AT_ranges attribute"),
14299 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
14300 Callback's type should be:
14301 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14302 Return 1 if the attributes are present and valid, otherwise, return 0. */
14304 template <typename Callback
>
14306 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
, dwarf_tag tag
,
14307 Callback
&&callback
)
14309 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14310 struct objfile
*objfile
= per_objfile
->objfile
;
14311 struct comp_unit_head
*cu_header
= &cu
->header
;
14312 bfd
*obfd
= objfile
->obfd
;
14313 unsigned int addr_size
= cu_header
->addr_size
;
14314 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
14315 /* Base address selection entry. */
14316 gdb::optional
<CORE_ADDR
> base
;
14317 unsigned int dummy
;
14318 const gdb_byte
*buffer
;
14319 CORE_ADDR baseaddr
;
14321 if (cu_header
->version
>= 5)
14322 return dwarf2_rnglists_process (offset
, cu
, tag
, callback
);
14324 base
= cu
->base_address
;
14326 per_objfile
->per_bfd
->ranges
.read (objfile
);
14327 if (offset
>= per_objfile
->per_bfd
->ranges
.size
)
14329 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14333 buffer
= per_objfile
->per_bfd
->ranges
.buffer
+ offset
;
14335 baseaddr
= objfile
->text_section_offset ();
14339 CORE_ADDR range_beginning
, range_end
;
14341 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
14342 buffer
+= addr_size
;
14343 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
14344 buffer
+= addr_size
;
14345 offset
+= 2 * addr_size
;
14347 /* An end of list marker is a pair of zero addresses. */
14348 if (range_beginning
== 0 && range_end
== 0)
14349 /* Found the end of list entry. */
14352 /* Each base address selection entry is a pair of 2 values.
14353 The first is the largest possible address, the second is
14354 the base address. Check for a base address here. */
14355 if ((range_beginning
& mask
) == mask
)
14357 /* If we found the largest possible address, then we already
14358 have the base address in range_end. */
14363 if (!base
.has_value ())
14365 /* We have no valid base address for the ranges
14367 complaint (_("Invalid .debug_ranges data (no base address)"));
14371 if (range_beginning
> range_end
)
14373 /* Inverted range entries are invalid. */
14374 complaint (_("Invalid .debug_ranges data (inverted range)"));
14378 /* Empty range entries have no effect. */
14379 if (range_beginning
== range_end
)
14382 range_beginning
+= *base
;
14383 range_end
+= *base
;
14385 /* A not-uncommon case of bad debug info.
14386 Don't pollute the addrmap with bad data. */
14387 if (range_beginning
+ baseaddr
== 0
14388 && !per_objfile
->per_bfd
->has_section_at_zero
)
14390 complaint (_(".debug_ranges entry has start address of zero"
14391 " [in module %s]"), objfile_name (objfile
));
14395 callback (range_beginning
, range_end
);
14401 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
14402 Return 1 if the attributes are present and valid, otherwise, return 0.
14403 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
14406 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
14407 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
14408 dwarf2_psymtab
*ranges_pst
, dwarf_tag tag
)
14410 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14411 struct gdbarch
*gdbarch
= objfile
->arch ();
14412 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
14415 CORE_ADDR high
= 0;
14418 retval
= dwarf2_ranges_process (offset
, cu
, tag
,
14419 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
14421 if (ranges_pst
!= NULL
)
14426 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14427 range_beginning
+ baseaddr
)
14429 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14430 range_end
+ baseaddr
)
14432 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
14433 lowpc
, highpc
- 1, ranges_pst
);
14436 /* FIXME: This is recording everything as a low-high
14437 segment of consecutive addresses. We should have a
14438 data structure for discontiguous block ranges
14442 low
= range_beginning
;
14448 if (range_beginning
< low
)
14449 low
= range_beginning
;
14450 if (range_end
> high
)
14458 /* If the first entry is an end-of-list marker, the range
14459 describes an empty scope, i.e. no instructions. */
14465 *high_return
= high
;
14469 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14470 definition for the return value. *LOWPC and *HIGHPC are set iff
14471 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14473 static enum pc_bounds_kind
14474 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14475 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14476 dwarf2_psymtab
*pst
)
14478 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14479 struct attribute
*attr
;
14480 struct attribute
*attr_high
;
14482 CORE_ADDR high
= 0;
14483 enum pc_bounds_kind ret
;
14485 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14488 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14489 if (attr
!= nullptr)
14491 low
= attr
->as_address ();
14492 high
= attr_high
->as_address ();
14493 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14497 /* Found high w/o low attribute. */
14498 return PC_BOUNDS_INVALID
;
14500 /* Found consecutive range of addresses. */
14501 ret
= PC_BOUNDS_HIGH_LOW
;
14505 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14506 if (attr
!= nullptr && attr
->form_is_unsigned ())
14508 /* Offset in the .debug_ranges or .debug_rnglist section (depending
14509 on DWARF version). */
14510 ULONGEST ranges_offset
= attr
->as_unsigned ();
14512 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
14514 if (die
->tag
!= DW_TAG_compile_unit
)
14515 ranges_offset
+= cu
->gnu_ranges_base
;
14517 /* Value of the DW_AT_ranges attribute is the offset in the
14518 .debug_ranges section. */
14519 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
,
14521 return PC_BOUNDS_INVALID
;
14522 /* Found discontinuous range of addresses. */
14523 ret
= PC_BOUNDS_RANGES
;
14526 return PC_BOUNDS_NOT_PRESENT
;
14529 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14531 return PC_BOUNDS_INVALID
;
14533 /* When using the GNU linker, .gnu.linkonce. sections are used to
14534 eliminate duplicate copies of functions and vtables and such.
14535 The linker will arbitrarily choose one and discard the others.
14536 The AT_*_pc values for such functions refer to local labels in
14537 these sections. If the section from that file was discarded, the
14538 labels are not in the output, so the relocs get a value of 0.
14539 If this is a discarded function, mark the pc bounds as invalid,
14540 so that GDB will ignore it. */
14541 if (low
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
14542 return PC_BOUNDS_INVALID
;
14550 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14551 its low and high PC addresses. Do nothing if these addresses could not
14552 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14553 and HIGHPC to the high address if greater than HIGHPC. */
14556 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14557 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14558 struct dwarf2_cu
*cu
)
14560 CORE_ADDR low
, high
;
14561 struct die_info
*child
= die
->child
;
14563 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14565 *lowpc
= std::min (*lowpc
, low
);
14566 *highpc
= std::max (*highpc
, high
);
14569 /* If the language does not allow nested subprograms (either inside
14570 subprograms or lexical blocks), we're done. */
14571 if (cu
->language
!= language_ada
)
14574 /* Check all the children of the given DIE. If it contains nested
14575 subprograms, then check their pc bounds. Likewise, we need to
14576 check lexical blocks as well, as they may also contain subprogram
14578 while (child
&& child
->tag
)
14580 if (child
->tag
== DW_TAG_subprogram
14581 || child
->tag
== DW_TAG_lexical_block
)
14582 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14583 child
= child
->sibling
;
14587 /* Get the low and high pc's represented by the scope DIE, and store
14588 them in *LOWPC and *HIGHPC. If the correct values can't be
14589 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14592 get_scope_pc_bounds (struct die_info
*die
,
14593 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14594 struct dwarf2_cu
*cu
)
14596 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14597 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14598 CORE_ADDR current_low
, current_high
;
14600 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14601 >= PC_BOUNDS_RANGES
)
14603 best_low
= current_low
;
14604 best_high
= current_high
;
14608 struct die_info
*child
= die
->child
;
14610 while (child
&& child
->tag
)
14612 switch (child
->tag
) {
14613 case DW_TAG_subprogram
:
14614 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14616 case DW_TAG_namespace
:
14617 case DW_TAG_module
:
14618 /* FIXME: carlton/2004-01-16: Should we do this for
14619 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14620 that current GCC's always emit the DIEs corresponding
14621 to definitions of methods of classes as children of a
14622 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14623 the DIEs giving the declarations, which could be
14624 anywhere). But I don't see any reason why the
14625 standards says that they have to be there. */
14626 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14628 if (current_low
!= ((CORE_ADDR
) -1))
14630 best_low
= std::min (best_low
, current_low
);
14631 best_high
= std::max (best_high
, current_high
);
14639 child
= child
->sibling
;
14644 *highpc
= best_high
;
14647 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14651 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14652 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14654 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14655 struct gdbarch
*gdbarch
= objfile
->arch ();
14656 struct attribute
*attr
;
14657 struct attribute
*attr_high
;
14659 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14662 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14663 if (attr
!= nullptr)
14665 CORE_ADDR low
= attr
->as_address ();
14666 CORE_ADDR high
= attr_high
->as_address ();
14668 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14671 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14672 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14673 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14677 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14678 if (attr
!= nullptr && attr
->form_is_unsigned ())
14680 /* Offset in the .debug_ranges or .debug_rnglist section (depending
14681 on DWARF version). */
14682 ULONGEST ranges_offset
= attr
->as_unsigned ();
14684 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
14686 if (die
->tag
!= DW_TAG_compile_unit
)
14687 ranges_offset
+= cu
->gnu_ranges_base
;
14689 std::vector
<blockrange
> blockvec
;
14690 dwarf2_ranges_process (ranges_offset
, cu
, die
->tag
,
14691 [&] (CORE_ADDR start
, CORE_ADDR end
)
14695 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14696 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14697 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14698 blockvec
.emplace_back (start
, end
);
14701 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14705 /* Check whether the producer field indicates either of GCC < 4.6, or the
14706 Intel C/C++ compiler, and cache the result in CU. */
14709 check_producer (struct dwarf2_cu
*cu
)
14713 if (cu
->producer
== NULL
)
14715 /* For unknown compilers expect their behavior is DWARF version
14718 GCC started to support .debug_types sections by -gdwarf-4 since
14719 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14720 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14721 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14722 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14724 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14726 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14727 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14729 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14731 cu
->producer_is_icc
= true;
14732 cu
->producer_is_icc_lt_14
= major
< 14;
14734 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14735 cu
->producer_is_codewarrior
= true;
14738 /* For other non-GCC compilers, expect their behavior is DWARF version
14742 cu
->checked_producer
= true;
14745 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14746 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14747 during 4.6.0 experimental. */
14750 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14752 if (!cu
->checked_producer
)
14753 check_producer (cu
);
14755 return cu
->producer_is_gxx_lt_4_6
;
14759 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14760 with incorrect is_stmt attributes. */
14763 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14765 if (!cu
->checked_producer
)
14766 check_producer (cu
);
14768 return cu
->producer_is_codewarrior
;
14771 /* Return the accessibility of DIE, as given by DW_AT_accessibility.
14772 If that attribute is not available, return the appropriate
14775 static enum dwarf_access_attribute
14776 dwarf2_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14778 attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14779 if (attr
!= nullptr)
14781 LONGEST value
= attr
->constant_value (-1);
14782 if (value
== DW_ACCESS_public
14783 || value
== DW_ACCESS_protected
14784 || value
== DW_ACCESS_private
)
14785 return (dwarf_access_attribute
) value
;
14786 complaint (_("Unhandled DW_AT_accessibility value (%s)"),
14790 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14792 /* The default DWARF 2 accessibility for members is public, the default
14793 accessibility for inheritance is private. */
14795 if (die
->tag
!= DW_TAG_inheritance
)
14796 return DW_ACCESS_public
;
14798 return DW_ACCESS_private
;
14802 /* DWARF 3+ defines the default accessibility a different way. The same
14803 rules apply now for DW_TAG_inheritance as for the members and it only
14804 depends on the container kind. */
14806 if (die
->parent
->tag
== DW_TAG_class_type
)
14807 return DW_ACCESS_private
;
14809 return DW_ACCESS_public
;
14813 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14814 offset. If the attribute was not found return 0, otherwise return
14815 1. If it was found but could not properly be handled, set *OFFSET
14819 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14822 struct attribute
*attr
;
14824 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14829 /* Note that we do not check for a section offset first here.
14830 This is because DW_AT_data_member_location is new in DWARF 4,
14831 so if we see it, we can assume that a constant form is really
14832 a constant and not a section offset. */
14833 if (attr
->form_is_constant ())
14834 *offset
= attr
->constant_value (0);
14835 else if (attr
->form_is_section_offset ())
14836 dwarf2_complex_location_expr_complaint ();
14837 else if (attr
->form_is_block ())
14838 *offset
= decode_locdesc (attr
->as_block (), cu
);
14840 dwarf2_complex_location_expr_complaint ();
14848 /* Look for DW_AT_data_member_location and store the results in FIELD. */
14851 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14852 struct field
*field
)
14854 struct attribute
*attr
;
14856 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14859 if (attr
->form_is_constant ())
14861 LONGEST offset
= attr
->constant_value (0);
14862 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14864 else if (attr
->form_is_section_offset ())
14865 dwarf2_complex_location_expr_complaint ();
14866 else if (attr
->form_is_block ())
14869 CORE_ADDR offset
= decode_locdesc (attr
->as_block (), cu
, &handled
);
14871 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14874 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14875 struct objfile
*objfile
= per_objfile
->objfile
;
14876 struct dwarf2_locexpr_baton
*dlbaton
14877 = XOBNEW (&objfile
->objfile_obstack
,
14878 struct dwarf2_locexpr_baton
);
14879 dlbaton
->data
= attr
->as_block ()->data
;
14880 dlbaton
->size
= attr
->as_block ()->size
;
14881 /* When using this baton, we want to compute the address
14882 of the field, not the value. This is why
14883 is_reference is set to false here. */
14884 dlbaton
->is_reference
= false;
14885 dlbaton
->per_objfile
= per_objfile
;
14886 dlbaton
->per_cu
= cu
->per_cu
;
14888 SET_FIELD_DWARF_BLOCK (*field
, dlbaton
);
14892 dwarf2_complex_location_expr_complaint ();
14896 /* Add an aggregate field to the field list. */
14899 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14900 struct dwarf2_cu
*cu
)
14902 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14903 struct gdbarch
*gdbarch
= objfile
->arch ();
14904 struct nextfield
*new_field
;
14905 struct attribute
*attr
;
14907 const char *fieldname
= "";
14909 if (die
->tag
== DW_TAG_inheritance
)
14911 fip
->baseclasses
.emplace_back ();
14912 new_field
= &fip
->baseclasses
.back ();
14916 fip
->fields
.emplace_back ();
14917 new_field
= &fip
->fields
.back ();
14920 new_field
->offset
= die
->sect_off
;
14922 new_field
->accessibility
= dwarf2_access_attribute (die
, cu
);
14923 if (new_field
->accessibility
!= DW_ACCESS_public
)
14924 fip
->non_public_fields
= true;
14926 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14927 if (attr
!= nullptr)
14928 new_field
->virtuality
= attr
->as_virtuality ();
14930 new_field
->virtuality
= DW_VIRTUALITY_none
;
14932 fp
= &new_field
->field
;
14934 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14936 /* Data member other than a C++ static data member. */
14938 /* Get type of field. */
14939 fp
->set_type (die_type (die
, cu
));
14941 SET_FIELD_BITPOS (*fp
, 0);
14943 /* Get bit size of field (zero if none). */
14944 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14945 if (attr
!= nullptr)
14947 FIELD_BITSIZE (*fp
) = attr
->constant_value (0);
14951 FIELD_BITSIZE (*fp
) = 0;
14954 /* Get bit offset of field. */
14955 handle_data_member_location (die
, cu
, fp
);
14956 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14957 if (attr
!= nullptr && attr
->form_is_constant ())
14959 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14961 /* For big endian bits, the DW_AT_bit_offset gives the
14962 additional bit offset from the MSB of the containing
14963 anonymous object to the MSB of the field. We don't
14964 have to do anything special since we don't need to
14965 know the size of the anonymous object. */
14966 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14967 + attr
->constant_value (0)));
14971 /* For little endian bits, compute the bit offset to the
14972 MSB of the anonymous object, subtract off the number of
14973 bits from the MSB of the field to the MSB of the
14974 object, and then subtract off the number of bits of
14975 the field itself. The result is the bit offset of
14976 the LSB of the field. */
14977 int anonymous_size
;
14978 int bit_offset
= attr
->constant_value (0);
14980 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14981 if (attr
!= nullptr && attr
->form_is_constant ())
14983 /* The size of the anonymous object containing
14984 the bit field is explicit, so use the
14985 indicated size (in bytes). */
14986 anonymous_size
= attr
->constant_value (0);
14990 /* The size of the anonymous object containing
14991 the bit field must be inferred from the type
14992 attribute of the data member containing the
14994 anonymous_size
= TYPE_LENGTH (fp
->type ());
14996 SET_FIELD_BITPOS (*fp
,
14997 (FIELD_BITPOS (*fp
)
14998 + anonymous_size
* bits_per_byte
14999 - bit_offset
- FIELD_BITSIZE (*fp
)));
15002 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
15004 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
15005 + attr
->constant_value (0)));
15007 /* Get name of field. */
15008 fieldname
= dwarf2_name (die
, cu
);
15009 if (fieldname
== NULL
)
15012 /* The name is already allocated along with this objfile, so we don't
15013 need to duplicate it for the type. */
15014 fp
->name
= fieldname
;
15016 /* Change accessibility for artificial fields (e.g. virtual table
15017 pointer or virtual base class pointer) to private. */
15018 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
15020 FIELD_ARTIFICIAL (*fp
) = 1;
15021 new_field
->accessibility
= DW_ACCESS_private
;
15022 fip
->non_public_fields
= true;
15025 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
15027 /* C++ static member. */
15029 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
15030 is a declaration, but all versions of G++ as of this writing
15031 (so through at least 3.2.1) incorrectly generate
15032 DW_TAG_variable tags. */
15034 const char *physname
;
15036 /* Get name of field. */
15037 fieldname
= dwarf2_name (die
, cu
);
15038 if (fieldname
== NULL
)
15041 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15043 /* Only create a symbol if this is an external value.
15044 new_symbol checks this and puts the value in the global symbol
15045 table, which we want. If it is not external, new_symbol
15046 will try to put the value in cu->list_in_scope which is wrong. */
15047 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
15049 /* A static const member, not much different than an enum as far as
15050 we're concerned, except that we can support more types. */
15051 new_symbol (die
, NULL
, cu
);
15054 /* Get physical name. */
15055 physname
= dwarf2_physname (fieldname
, die
, cu
);
15057 /* The name is already allocated along with this objfile, so we don't
15058 need to duplicate it for the type. */
15059 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
15060 fp
->set_type (die_type (die
, cu
));
15061 FIELD_NAME (*fp
) = fieldname
;
15063 else if (die
->tag
== DW_TAG_inheritance
)
15065 /* C++ base class field. */
15066 handle_data_member_location (die
, cu
, fp
);
15067 FIELD_BITSIZE (*fp
) = 0;
15068 fp
->set_type (die_type (die
, cu
));
15069 FIELD_NAME (*fp
) = fp
->type ()->name ();
15072 gdb_assert_not_reached ("missing case in dwarf2_add_field");
15075 /* Can the type given by DIE define another type? */
15078 type_can_define_types (const struct die_info
*die
)
15082 case DW_TAG_typedef
:
15083 case DW_TAG_class_type
:
15084 case DW_TAG_structure_type
:
15085 case DW_TAG_union_type
:
15086 case DW_TAG_enumeration_type
:
15094 /* Add a type definition defined in the scope of the FIP's class. */
15097 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
15098 struct dwarf2_cu
*cu
)
15100 struct decl_field fp
;
15101 memset (&fp
, 0, sizeof (fp
));
15103 gdb_assert (type_can_define_types (die
));
15105 /* Get name of field. NULL is okay here, meaning an anonymous type. */
15106 fp
.name
= dwarf2_name (die
, cu
);
15107 fp
.type
= read_type_die (die
, cu
);
15109 /* Save accessibility. */
15110 dwarf_access_attribute accessibility
= dwarf2_access_attribute (die
, cu
);
15111 switch (accessibility
)
15113 case DW_ACCESS_public
:
15114 /* The assumed value if neither private nor protected. */
15116 case DW_ACCESS_private
:
15119 case DW_ACCESS_protected
:
15120 fp
.is_protected
= 1;
15124 if (die
->tag
== DW_TAG_typedef
)
15125 fip
->typedef_field_list
.push_back (fp
);
15127 fip
->nested_types_list
.push_back (fp
);
15130 /* A convenience typedef that's used when finding the discriminant
15131 field for a variant part. */
15132 typedef std::unordered_map
<sect_offset
, int, gdb::hash_enum
<sect_offset
>>
15135 /* Compute the discriminant range for a given variant. OBSTACK is
15136 where the results will be stored. VARIANT is the variant to
15137 process. IS_UNSIGNED indicates whether the discriminant is signed
15140 static const gdb::array_view
<discriminant_range
>
15141 convert_variant_range (struct obstack
*obstack
, const variant_field
&variant
,
15144 std::vector
<discriminant_range
> ranges
;
15146 if (variant
.default_branch
)
15149 if (variant
.discr_list_data
== nullptr)
15151 discriminant_range r
15152 = {variant
.discriminant_value
, variant
.discriminant_value
};
15153 ranges
.push_back (r
);
15157 gdb::array_view
<const gdb_byte
> data (variant
.discr_list_data
->data
,
15158 variant
.discr_list_data
->size
);
15159 while (!data
.empty ())
15161 if (data
[0] != DW_DSC_range
&& data
[0] != DW_DSC_label
)
15163 complaint (_("invalid discriminant marker: %d"), data
[0]);
15166 bool is_range
= data
[0] == DW_DSC_range
;
15167 data
= data
.slice (1);
15169 ULONGEST low
, high
;
15170 unsigned int bytes_read
;
15174 complaint (_("DW_AT_discr_list missing low value"));
15178 low
= read_unsigned_leb128 (nullptr, data
.data (), &bytes_read
);
15180 low
= (ULONGEST
) read_signed_leb128 (nullptr, data
.data (),
15182 data
= data
.slice (bytes_read
);
15188 complaint (_("DW_AT_discr_list missing high value"));
15192 high
= read_unsigned_leb128 (nullptr, data
.data (),
15195 high
= (LONGEST
) read_signed_leb128 (nullptr, data
.data (),
15197 data
= data
.slice (bytes_read
);
15202 ranges
.push_back ({ low
, high
});
15206 discriminant_range
*result
= XOBNEWVEC (obstack
, discriminant_range
,
15208 std::copy (ranges
.begin (), ranges
.end (), result
);
15209 return gdb::array_view
<discriminant_range
> (result
, ranges
.size ());
15212 static const gdb::array_view
<variant_part
> create_variant_parts
15213 (struct obstack
*obstack
,
15214 const offset_map_type
&offset_map
,
15215 struct field_info
*fi
,
15216 const std::vector
<variant_part_builder
> &variant_parts
);
15218 /* Fill in a "struct variant" for a given variant field. RESULT is
15219 the variant to fill in. OBSTACK is where any needed allocations
15220 will be done. OFFSET_MAP holds the mapping from section offsets to
15221 fields for the type. FI describes the fields of the type we're
15222 processing. FIELD is the variant field we're converting. */
15225 create_one_variant (variant
&result
, struct obstack
*obstack
,
15226 const offset_map_type
&offset_map
,
15227 struct field_info
*fi
, const variant_field
&field
)
15229 result
.discriminants
= convert_variant_range (obstack
, field
, false);
15230 result
.first_field
= field
.first_field
+ fi
->baseclasses
.size ();
15231 result
.last_field
= field
.last_field
+ fi
->baseclasses
.size ();
15232 result
.parts
= create_variant_parts (obstack
, offset_map
, fi
,
15233 field
.variant_parts
);
15236 /* Fill in a "struct variant_part" for a given variant part. RESULT
15237 is the variant part to fill in. OBSTACK is where any needed
15238 allocations will be done. OFFSET_MAP holds the mapping from
15239 section offsets to fields for the type. FI describes the fields of
15240 the type we're processing. BUILDER is the variant part to be
15244 create_one_variant_part (variant_part
&result
,
15245 struct obstack
*obstack
,
15246 const offset_map_type
&offset_map
,
15247 struct field_info
*fi
,
15248 const variant_part_builder
&builder
)
15250 auto iter
= offset_map
.find (builder
.discriminant_offset
);
15251 if (iter
== offset_map
.end ())
15253 result
.discriminant_index
= -1;
15254 /* Doesn't matter. */
15255 result
.is_unsigned
= false;
15259 result
.discriminant_index
= iter
->second
;
15261 = fi
->fields
[result
.discriminant_index
].field
.type ()->is_unsigned ();
15264 size_t n
= builder
.variants
.size ();
15265 variant
*output
= new (obstack
) variant
[n
];
15266 for (size_t i
= 0; i
< n
; ++i
)
15267 create_one_variant (output
[i
], obstack
, offset_map
, fi
,
15268 builder
.variants
[i
]);
15270 result
.variants
= gdb::array_view
<variant
> (output
, n
);
15273 /* Create a vector of variant parts that can be attached to a type.
15274 OBSTACK is where any needed allocations will be done. OFFSET_MAP
15275 holds the mapping from section offsets to fields for the type. FI
15276 describes the fields of the type we're processing. VARIANT_PARTS
15277 is the vector to convert. */
15279 static const gdb::array_view
<variant_part
>
15280 create_variant_parts (struct obstack
*obstack
,
15281 const offset_map_type
&offset_map
,
15282 struct field_info
*fi
,
15283 const std::vector
<variant_part_builder
> &variant_parts
)
15285 if (variant_parts
.empty ())
15288 size_t n
= variant_parts
.size ();
15289 variant_part
*result
= new (obstack
) variant_part
[n
];
15290 for (size_t i
= 0; i
< n
; ++i
)
15291 create_one_variant_part (result
[i
], obstack
, offset_map
, fi
,
15294 return gdb::array_view
<variant_part
> (result
, n
);
15297 /* Compute the variant part vector for FIP, attaching it to TYPE when
15301 add_variant_property (struct field_info
*fip
, struct type
*type
,
15302 struct dwarf2_cu
*cu
)
15304 /* Map section offsets of fields to their field index. Note the
15305 field index here does not take the number of baseclasses into
15307 offset_map_type offset_map
;
15308 for (int i
= 0; i
< fip
->fields
.size (); ++i
)
15309 offset_map
[fip
->fields
[i
].offset
] = i
;
15311 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15312 gdb::array_view
<variant_part
> parts
15313 = create_variant_parts (&objfile
->objfile_obstack
, offset_map
, fip
,
15314 fip
->variant_parts
);
15316 struct dynamic_prop prop
;
15317 prop
.set_variant_parts ((gdb::array_view
<variant_part
> *)
15318 obstack_copy (&objfile
->objfile_obstack
, &parts
,
15321 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
15324 /* Create the vector of fields, and attach it to the type. */
15327 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
15328 struct dwarf2_cu
*cu
)
15330 int nfields
= fip
->nfields ();
15332 /* Record the field count, allocate space for the array of fields,
15333 and create blank accessibility bitfields if necessary. */
15334 type
->set_num_fields (nfields
);
15336 ((struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
));
15338 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
15340 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15342 TYPE_FIELD_PRIVATE_BITS (type
) =
15343 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15344 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
15346 TYPE_FIELD_PROTECTED_BITS (type
) =
15347 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15348 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
15350 TYPE_FIELD_IGNORE_BITS (type
) =
15351 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15352 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
15355 /* If the type has baseclasses, allocate and clear a bit vector for
15356 TYPE_FIELD_VIRTUAL_BITS. */
15357 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
15359 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
15360 unsigned char *pointer
;
15362 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15363 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
15364 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
15365 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
15366 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
15369 if (!fip
->variant_parts
.empty ())
15370 add_variant_property (fip
, type
, cu
);
15372 /* Copy the saved-up fields into the field vector. */
15373 for (int i
= 0; i
< nfields
; ++i
)
15375 struct nextfield
&field
15376 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
15377 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
15379 type
->field (i
) = field
.field
;
15380 switch (field
.accessibility
)
15382 case DW_ACCESS_private
:
15383 if (cu
->language
!= language_ada
)
15384 SET_TYPE_FIELD_PRIVATE (type
, i
);
15387 case DW_ACCESS_protected
:
15388 if (cu
->language
!= language_ada
)
15389 SET_TYPE_FIELD_PROTECTED (type
, i
);
15392 case DW_ACCESS_public
:
15396 /* Unknown accessibility. Complain and treat it as public. */
15398 complaint (_("unsupported accessibility %d"),
15399 field
.accessibility
);
15403 if (i
< fip
->baseclasses
.size ())
15405 switch (field
.virtuality
)
15407 case DW_VIRTUALITY_virtual
:
15408 case DW_VIRTUALITY_pure_virtual
:
15409 if (cu
->language
== language_ada
)
15410 error (_("unexpected virtuality in component of Ada type"));
15411 SET_TYPE_FIELD_VIRTUAL (type
, i
);
15418 /* Return true if this member function is a constructor, false
15422 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15424 const char *fieldname
;
15425 const char *type_name
;
15428 if (die
->parent
== NULL
)
15431 if (die
->parent
->tag
!= DW_TAG_structure_type
15432 && die
->parent
->tag
!= DW_TAG_union_type
15433 && die
->parent
->tag
!= DW_TAG_class_type
)
15436 fieldname
= dwarf2_name (die
, cu
);
15437 type_name
= dwarf2_name (die
->parent
, cu
);
15438 if (fieldname
== NULL
|| type_name
== NULL
)
15441 len
= strlen (fieldname
);
15442 return (strncmp (fieldname
, type_name
, len
) == 0
15443 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15446 /* Add a member function to the proper fieldlist. */
15449 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15450 struct type
*type
, struct dwarf2_cu
*cu
)
15452 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15453 struct attribute
*attr
;
15455 struct fnfieldlist
*flp
= nullptr;
15456 struct fn_field
*fnp
;
15457 const char *fieldname
;
15458 struct type
*this_type
;
15460 if (cu
->language
== language_ada
)
15461 error (_("unexpected member function in Ada type"));
15463 /* Get name of member function. */
15464 fieldname
= dwarf2_name (die
, cu
);
15465 if (fieldname
== NULL
)
15468 /* Look up member function name in fieldlist. */
15469 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15471 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15473 flp
= &fip
->fnfieldlists
[i
];
15478 /* Create a new fnfieldlist if necessary. */
15479 if (flp
== nullptr)
15481 fip
->fnfieldlists
.emplace_back ();
15482 flp
= &fip
->fnfieldlists
.back ();
15483 flp
->name
= fieldname
;
15484 i
= fip
->fnfieldlists
.size () - 1;
15487 /* Create a new member function field and add it to the vector of
15489 flp
->fnfields
.emplace_back ();
15490 fnp
= &flp
->fnfields
.back ();
15492 /* Delay processing of the physname until later. */
15493 if (cu
->language
== language_cplus
)
15494 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15498 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15499 fnp
->physname
= physname
? physname
: "";
15502 fnp
->type
= alloc_type (objfile
);
15503 this_type
= read_type_die (die
, cu
);
15504 if (this_type
&& this_type
->code () == TYPE_CODE_FUNC
)
15506 int nparams
= this_type
->num_fields ();
15508 /* TYPE is the domain of this method, and THIS_TYPE is the type
15509 of the method itself (TYPE_CODE_METHOD). */
15510 smash_to_method_type (fnp
->type
, type
,
15511 TYPE_TARGET_TYPE (this_type
),
15512 this_type
->fields (),
15513 this_type
->num_fields (),
15514 this_type
->has_varargs ());
15516 /* Handle static member functions.
15517 Dwarf2 has no clean way to discern C++ static and non-static
15518 member functions. G++ helps GDB by marking the first
15519 parameter for non-static member functions (which is the this
15520 pointer) as artificial. We obtain this information from
15521 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15522 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15523 fnp
->voffset
= VOFFSET_STATIC
;
15526 complaint (_("member function type missing for '%s'"),
15527 dwarf2_full_name (fieldname
, die
, cu
));
15529 /* Get fcontext from DW_AT_containing_type if present. */
15530 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15531 fnp
->fcontext
= die_containing_type (die
, cu
);
15533 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15534 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15536 /* Get accessibility. */
15537 dwarf_access_attribute accessibility
= dwarf2_access_attribute (die
, cu
);
15538 switch (accessibility
)
15540 case DW_ACCESS_private
:
15541 fnp
->is_private
= 1;
15543 case DW_ACCESS_protected
:
15544 fnp
->is_protected
= 1;
15548 /* Check for artificial methods. */
15549 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15550 if (attr
&& attr
->as_boolean ())
15551 fnp
->is_artificial
= 1;
15553 /* Check for defaulted methods. */
15554 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
15555 if (attr
!= nullptr)
15556 fnp
->defaulted
= attr
->defaulted ();
15558 /* Check for deleted methods. */
15559 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
15560 if (attr
!= nullptr && attr
->as_boolean ())
15561 fnp
->is_deleted
= 1;
15563 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15565 /* Get index in virtual function table if it is a virtual member
15566 function. For older versions of GCC, this is an offset in the
15567 appropriate virtual table, as specified by DW_AT_containing_type.
15568 For everyone else, it is an expression to be evaluated relative
15569 to the object address. */
15571 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15572 if (attr
!= nullptr)
15574 if (attr
->form_is_block () && attr
->as_block ()->size
> 0)
15576 struct dwarf_block
*block
= attr
->as_block ();
15578 if (block
->data
[0] == DW_OP_constu
)
15580 /* Old-style GCC. */
15581 fnp
->voffset
= decode_locdesc (block
, cu
) + 2;
15583 else if (block
->data
[0] == DW_OP_deref
15584 || (block
->size
> 1
15585 && block
->data
[0] == DW_OP_deref_size
15586 && block
->data
[1] == cu
->header
.addr_size
))
15588 fnp
->voffset
= decode_locdesc (block
, cu
);
15589 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15590 dwarf2_complex_location_expr_complaint ();
15592 fnp
->voffset
/= cu
->header
.addr_size
;
15596 dwarf2_complex_location_expr_complaint ();
15598 if (!fnp
->fcontext
)
15600 /* If there is no `this' field and no DW_AT_containing_type,
15601 we cannot actually find a base class context for the
15603 if (this_type
->num_fields () == 0
15604 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15606 complaint (_("cannot determine context for virtual member "
15607 "function \"%s\" (offset %s)"),
15608 fieldname
, sect_offset_str (die
->sect_off
));
15613 = TYPE_TARGET_TYPE (this_type
->field (0).type ());
15617 else if (attr
->form_is_section_offset ())
15619 dwarf2_complex_location_expr_complaint ();
15623 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15629 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15630 if (attr
!= nullptr && attr
->as_virtuality () != DW_VIRTUALITY_none
)
15632 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15633 complaint (_("Member function \"%s\" (offset %s) is virtual "
15634 "but the vtable offset is not specified"),
15635 fieldname
, sect_offset_str (die
->sect_off
));
15636 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15637 TYPE_CPLUS_DYNAMIC (type
) = 1;
15642 /* Create the vector of member function fields, and attach it to the type. */
15645 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15646 struct dwarf2_cu
*cu
)
15648 if (cu
->language
== language_ada
)
15649 error (_("unexpected member functions in Ada type"));
15651 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15652 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15654 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15656 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15658 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15659 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15661 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15662 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15663 fn_flp
->fn_fields
= (struct fn_field
*)
15664 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15666 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15667 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15670 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15673 /* Returns non-zero if NAME is the name of a vtable member in CU's
15674 language, zero otherwise. */
15676 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15678 static const char vptr
[] = "_vptr";
15680 /* Look for the C++ form of the vtable. */
15681 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15687 /* GCC outputs unnamed structures that are really pointers to member
15688 functions, with the ABI-specified layout. If TYPE describes
15689 such a structure, smash it into a member function type.
15691 GCC shouldn't do this; it should just output pointer to member DIEs.
15692 This is GCC PR debug/28767. */
15695 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15697 struct type
*pfn_type
, *self_type
, *new_type
;
15699 /* Check for a structure with no name and two children. */
15700 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15703 /* Check for __pfn and __delta members. */
15704 if (TYPE_FIELD_NAME (type
, 0) == NULL
15705 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15706 || TYPE_FIELD_NAME (type
, 1) == NULL
15707 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15710 /* Find the type of the method. */
15711 pfn_type
= type
->field (0).type ();
15712 if (pfn_type
== NULL
15713 || pfn_type
->code () != TYPE_CODE_PTR
15714 || TYPE_TARGET_TYPE (pfn_type
)->code () != TYPE_CODE_FUNC
)
15717 /* Look for the "this" argument. */
15718 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15719 if (pfn_type
->num_fields () == 0
15720 /* || pfn_type->field (0).type () == NULL */
15721 || pfn_type
->field (0).type ()->code () != TYPE_CODE_PTR
)
15724 self_type
= TYPE_TARGET_TYPE (pfn_type
->field (0).type ());
15725 new_type
= alloc_type (objfile
);
15726 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15727 pfn_type
->fields (), pfn_type
->num_fields (),
15728 pfn_type
->has_varargs ());
15729 smash_to_methodptr_type (type
, new_type
);
15732 /* Helper for quirk_ada_thick_pointer. If TYPE is an array type that
15733 requires rewriting, then copy it and return the updated copy.
15734 Otherwise return nullptr. */
15736 static struct type
*
15737 rewrite_array_type (struct type
*type
)
15739 if (type
->code () != TYPE_CODE_ARRAY
)
15742 struct type
*index_type
= type
->index_type ();
15743 range_bounds
*current_bounds
= index_type
->bounds ();
15745 /* Handle multi-dimensional arrays. */
15746 struct type
*new_target
= rewrite_array_type (TYPE_TARGET_TYPE (type
));
15747 if (new_target
== nullptr)
15749 /* Maybe we don't need to rewrite this array. */
15750 if (current_bounds
->low
.kind () == PROP_CONST
15751 && current_bounds
->high
.kind () == PROP_CONST
)
15755 /* Either the target type was rewritten, or the bounds have to be
15756 updated. Either way we want to copy the type and update
15758 struct type
*copy
= copy_type (type
);
15759 int nfields
= copy
->num_fields ();
15761 = ((struct field
*) TYPE_ZALLOC (copy
,
15762 nfields
* sizeof (struct field
)));
15763 memcpy (new_fields
, copy
->fields (), nfields
* sizeof (struct field
));
15764 copy
->set_fields (new_fields
);
15765 if (new_target
!= nullptr)
15766 TYPE_TARGET_TYPE (copy
) = new_target
;
15768 struct type
*index_copy
= copy_type (index_type
);
15769 range_bounds
*bounds
15770 = (struct range_bounds
*) TYPE_ZALLOC (index_copy
,
15771 sizeof (range_bounds
));
15772 *bounds
= *current_bounds
;
15773 bounds
->low
.set_const_val (1);
15774 bounds
->high
.set_const_val (0);
15775 index_copy
->set_bounds (bounds
);
15776 copy
->set_index_type (index_copy
);
15781 /* While some versions of GCC will generate complicated DWARF for an
15782 array (see quirk_ada_thick_pointer), more recent versions were
15783 modified to emit an explicit thick pointer structure. However, in
15784 this case, the array still has DWARF expressions for its ranges,
15785 and these must be ignored. */
15788 quirk_ada_thick_pointer_struct (struct die_info
*die
, struct dwarf2_cu
*cu
,
15791 gdb_assert (cu
->language
== language_ada
);
15793 /* Check for a structure with two children. */
15794 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15797 /* Check for P_ARRAY and P_BOUNDS members. */
15798 if (TYPE_FIELD_NAME (type
, 0) == NULL
15799 || strcmp (TYPE_FIELD_NAME (type
, 0), "P_ARRAY") != 0
15800 || TYPE_FIELD_NAME (type
, 1) == NULL
15801 || strcmp (TYPE_FIELD_NAME (type
, 1), "P_BOUNDS") != 0)
15804 /* Make sure we're looking at a pointer to an array. */
15805 if (type
->field (0).type ()->code () != TYPE_CODE_PTR
)
15808 /* The Ada code already knows how to handle these types, so all that
15809 we need to do is turn the bounds into static bounds. However, we
15810 don't want to rewrite existing array or index types in-place,
15811 because those may be referenced in other contexts where this
15812 rewriting is undesirable. */
15813 struct type
*new_ary_type
15814 = rewrite_array_type (TYPE_TARGET_TYPE (type
->field (0).type ()));
15815 if (new_ary_type
!= nullptr)
15816 type
->field (0).set_type (lookup_pointer_type (new_ary_type
));
15819 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15820 appropriate error checking and issuing complaints if there is a
15824 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15826 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15828 if (attr
== nullptr)
15831 if (!attr
->form_is_constant ())
15833 complaint (_("DW_AT_alignment must have constant form"
15834 " - DIE at %s [in module %s]"),
15835 sect_offset_str (die
->sect_off
),
15836 objfile_name (cu
->per_objfile
->objfile
));
15840 LONGEST val
= attr
->constant_value (0);
15843 complaint (_("DW_AT_alignment value must not be negative"
15844 " - DIE at %s [in module %s]"),
15845 sect_offset_str (die
->sect_off
),
15846 objfile_name (cu
->per_objfile
->objfile
));
15849 ULONGEST align
= val
;
15853 complaint (_("DW_AT_alignment value must not be zero"
15854 " - DIE at %s [in module %s]"),
15855 sect_offset_str (die
->sect_off
),
15856 objfile_name (cu
->per_objfile
->objfile
));
15859 if ((align
& (align
- 1)) != 0)
15861 complaint (_("DW_AT_alignment value must be a power of 2"
15862 " - DIE at %s [in module %s]"),
15863 sect_offset_str (die
->sect_off
),
15864 objfile_name (cu
->per_objfile
->objfile
));
15871 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15872 the alignment for TYPE. */
15875 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15878 if (!set_type_align (type
, get_alignment (cu
, die
)))
15879 complaint (_("DW_AT_alignment value too large"
15880 " - DIE at %s [in module %s]"),
15881 sect_offset_str (die
->sect_off
),
15882 objfile_name (cu
->per_objfile
->objfile
));
15885 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15886 constant for a type, according to DWARF5 spec, Table 5.5. */
15889 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
15894 case DW_CC_pass_by_reference
:
15895 case DW_CC_pass_by_value
:
15899 complaint (_("unrecognized DW_AT_calling_convention value "
15900 "(%s) for a type"), pulongest (value
));
15905 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15906 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
15907 also according to GNU-specific values (see include/dwarf2.h). */
15910 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
15915 case DW_CC_program
:
15919 case DW_CC_GNU_renesas_sh
:
15920 case DW_CC_GNU_borland_fastcall_i386
:
15921 case DW_CC_GDB_IBM_OpenCL
:
15925 complaint (_("unrecognized DW_AT_calling_convention value "
15926 "(%s) for a subroutine"), pulongest (value
));
15931 /* Called when we find the DIE that starts a structure or union scope
15932 (definition) to create a type for the structure or union. Fill in
15933 the type's name and general properties; the members will not be
15934 processed until process_structure_scope. A symbol table entry for
15935 the type will also not be done until process_structure_scope (assuming
15936 the type has a name).
15938 NOTE: we need to call these functions regardless of whether or not the
15939 DIE has a DW_AT_name attribute, since it might be an anonymous
15940 structure or union. This gets the type entered into our set of
15941 user defined types. */
15943 static struct type
*
15944 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15946 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15948 struct attribute
*attr
;
15951 /* If the definition of this type lives in .debug_types, read that type.
15952 Don't follow DW_AT_specification though, that will take us back up
15953 the chain and we want to go down. */
15954 attr
= die
->attr (DW_AT_signature
);
15955 if (attr
!= nullptr)
15957 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15959 /* The type's CU may not be the same as CU.
15960 Ensure TYPE is recorded with CU in die_type_hash. */
15961 return set_die_type (die
, type
, cu
);
15964 type
= alloc_type (objfile
);
15965 INIT_CPLUS_SPECIFIC (type
);
15967 name
= dwarf2_name (die
, cu
);
15970 if (cu
->language
== language_cplus
15971 || cu
->language
== language_d
15972 || cu
->language
== language_rust
)
15974 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15976 /* dwarf2_full_name might have already finished building the DIE's
15977 type. If so, there is no need to continue. */
15978 if (get_die_type (die
, cu
) != NULL
)
15979 return get_die_type (die
, cu
);
15981 type
->set_name (full_name
);
15985 /* The name is already allocated along with this objfile, so
15986 we don't need to duplicate it for the type. */
15987 type
->set_name (name
);
15991 if (die
->tag
== DW_TAG_structure_type
)
15993 type
->set_code (TYPE_CODE_STRUCT
);
15995 else if (die
->tag
== DW_TAG_union_type
)
15997 type
->set_code (TYPE_CODE_UNION
);
16001 type
->set_code (TYPE_CODE_STRUCT
);
16004 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
16005 TYPE_DECLARED_CLASS (type
) = 1;
16007 /* Store the calling convention in the type if it's available in
16008 the die. Otherwise the calling convention remains set to
16009 the default value DW_CC_normal. */
16010 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
16011 if (attr
!= nullptr
16012 && is_valid_DW_AT_calling_convention_for_type (attr
->constant_value (0)))
16014 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16015 TYPE_CPLUS_CALLING_CONVENTION (type
)
16016 = (enum dwarf_calling_convention
) (attr
->constant_value (0));
16019 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16020 if (attr
!= nullptr)
16022 if (attr
->form_is_constant ())
16023 TYPE_LENGTH (type
) = attr
->constant_value (0);
16026 struct dynamic_prop prop
;
16027 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
16028 type
->add_dyn_prop (DYN_PROP_BYTE_SIZE
, prop
);
16029 TYPE_LENGTH (type
) = 0;
16034 TYPE_LENGTH (type
) = 0;
16037 maybe_set_alignment (cu
, die
, type
);
16039 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
16041 /* ICC<14 does not output the required DW_AT_declaration on
16042 incomplete types, but gives them a size of zero. */
16043 type
->set_is_stub (true);
16046 type
->set_stub_is_supported (true);
16048 if (die_is_declaration (die
, cu
))
16049 type
->set_is_stub (true);
16050 else if (attr
== NULL
&& die
->child
== NULL
16051 && producer_is_realview (cu
->producer
))
16052 /* RealView does not output the required DW_AT_declaration
16053 on incomplete types. */
16054 type
->set_is_stub (true);
16056 /* We need to add the type field to the die immediately so we don't
16057 infinitely recurse when dealing with pointers to the structure
16058 type within the structure itself. */
16059 set_die_type (die
, type
, cu
);
16061 /* set_die_type should be already done. */
16062 set_descriptive_type (type
, die
, cu
);
16067 static void handle_struct_member_die
16068 (struct die_info
*child_die
,
16070 struct field_info
*fi
,
16071 std::vector
<struct symbol
*> *template_args
,
16072 struct dwarf2_cu
*cu
);
16074 /* A helper for handle_struct_member_die that handles
16075 DW_TAG_variant_part. */
16078 handle_variant_part (struct die_info
*die
, struct type
*type
,
16079 struct field_info
*fi
,
16080 std::vector
<struct symbol
*> *template_args
,
16081 struct dwarf2_cu
*cu
)
16083 variant_part_builder
*new_part
;
16084 if (fi
->current_variant_part
== nullptr)
16086 fi
->variant_parts
.emplace_back ();
16087 new_part
= &fi
->variant_parts
.back ();
16089 else if (!fi
->current_variant_part
->processing_variant
)
16091 complaint (_("nested DW_TAG_variant_part seen "
16092 "- DIE at %s [in module %s]"),
16093 sect_offset_str (die
->sect_off
),
16094 objfile_name (cu
->per_objfile
->objfile
));
16099 variant_field
¤t
= fi
->current_variant_part
->variants
.back ();
16100 current
.variant_parts
.emplace_back ();
16101 new_part
= ¤t
.variant_parts
.back ();
16104 /* When we recurse, we want callees to add to this new variant
16106 scoped_restore save_current_variant_part
16107 = make_scoped_restore (&fi
->current_variant_part
, new_part
);
16109 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
16112 /* It's a univariant form, an extension we support. */
16114 else if (discr
->form_is_ref ())
16116 struct dwarf2_cu
*target_cu
= cu
;
16117 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
16119 new_part
->discriminant_offset
= target_die
->sect_off
;
16123 complaint (_("DW_AT_discr does not have DIE reference form"
16124 " - DIE at %s [in module %s]"),
16125 sect_offset_str (die
->sect_off
),
16126 objfile_name (cu
->per_objfile
->objfile
));
16129 for (die_info
*child_die
= die
->child
;
16131 child_die
= child_die
->sibling
)
16132 handle_struct_member_die (child_die
, type
, fi
, template_args
, cu
);
16135 /* A helper for handle_struct_member_die that handles
16139 handle_variant (struct die_info
*die
, struct type
*type
,
16140 struct field_info
*fi
,
16141 std::vector
<struct symbol
*> *template_args
,
16142 struct dwarf2_cu
*cu
)
16144 if (fi
->current_variant_part
== nullptr)
16146 complaint (_("saw DW_TAG_variant outside DW_TAG_variant_part "
16147 "- DIE at %s [in module %s]"),
16148 sect_offset_str (die
->sect_off
),
16149 objfile_name (cu
->per_objfile
->objfile
));
16152 if (fi
->current_variant_part
->processing_variant
)
16154 complaint (_("nested DW_TAG_variant seen "
16155 "- DIE at %s [in module %s]"),
16156 sect_offset_str (die
->sect_off
),
16157 objfile_name (cu
->per_objfile
->objfile
));
16161 scoped_restore save_processing_variant
16162 = make_scoped_restore (&fi
->current_variant_part
->processing_variant
,
16165 fi
->current_variant_part
->variants
.emplace_back ();
16166 variant_field
&variant
= fi
->current_variant_part
->variants
.back ();
16167 variant
.first_field
= fi
->fields
.size ();
16169 /* In a variant we want to get the discriminant and also add a
16170 field for our sole member child. */
16171 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr_value
, cu
);
16172 if (discr
== nullptr || !discr
->form_is_constant ())
16174 discr
= dwarf2_attr (die
, DW_AT_discr_list
, cu
);
16175 if (discr
== nullptr || discr
->as_block ()->size
== 0)
16176 variant
.default_branch
= true;
16178 variant
.discr_list_data
= discr
->as_block ();
16181 variant
.discriminant_value
= discr
->constant_value (0);
16183 for (die_info
*variant_child
= die
->child
;
16184 variant_child
!= NULL
;
16185 variant_child
= variant_child
->sibling
)
16186 handle_struct_member_die (variant_child
, type
, fi
, template_args
, cu
);
16188 variant
.last_field
= fi
->fields
.size ();
16191 /* A helper for process_structure_scope that handles a single member
16195 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
16196 struct field_info
*fi
,
16197 std::vector
<struct symbol
*> *template_args
,
16198 struct dwarf2_cu
*cu
)
16200 if (child_die
->tag
== DW_TAG_member
16201 || child_die
->tag
== DW_TAG_variable
)
16203 /* NOTE: carlton/2002-11-05: A C++ static data member
16204 should be a DW_TAG_member that is a declaration, but
16205 all versions of G++ as of this writing (so through at
16206 least 3.2.1) incorrectly generate DW_TAG_variable
16207 tags for them instead. */
16208 dwarf2_add_field (fi
, child_die
, cu
);
16210 else if (child_die
->tag
== DW_TAG_subprogram
)
16212 /* Rust doesn't have member functions in the C++ sense.
16213 However, it does emit ordinary functions as children
16214 of a struct DIE. */
16215 if (cu
->language
== language_rust
)
16216 read_func_scope (child_die
, cu
);
16219 /* C++ member function. */
16220 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
16223 else if (child_die
->tag
== DW_TAG_inheritance
)
16225 /* C++ base class field. */
16226 dwarf2_add_field (fi
, child_die
, cu
);
16228 else if (type_can_define_types (child_die
))
16229 dwarf2_add_type_defn (fi
, child_die
, cu
);
16230 else if (child_die
->tag
== DW_TAG_template_type_param
16231 || child_die
->tag
== DW_TAG_template_value_param
)
16233 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
16236 template_args
->push_back (arg
);
16238 else if (child_die
->tag
== DW_TAG_variant_part
)
16239 handle_variant_part (child_die
, type
, fi
, template_args
, cu
);
16240 else if (child_die
->tag
== DW_TAG_variant
)
16241 handle_variant (child_die
, type
, fi
, template_args
, cu
);
16244 /* Finish creating a structure or union type, including filling in
16245 its members and creating a symbol for it. */
16248 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16250 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16251 struct die_info
*child_die
;
16254 type
= get_die_type (die
, cu
);
16256 type
= read_structure_type (die
, cu
);
16258 bool has_template_parameters
= false;
16259 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
16261 struct field_info fi
;
16262 std::vector
<struct symbol
*> template_args
;
16264 child_die
= die
->child
;
16266 while (child_die
&& child_die
->tag
)
16268 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
16269 child_die
= child_die
->sibling
;
16272 /* Attach template arguments to type. */
16273 if (!template_args
.empty ())
16275 has_template_parameters
= true;
16276 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16277 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
16278 TYPE_TEMPLATE_ARGUMENTS (type
)
16279 = XOBNEWVEC (&objfile
->objfile_obstack
,
16281 TYPE_N_TEMPLATE_ARGUMENTS (type
));
16282 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
16283 template_args
.data (),
16284 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
16285 * sizeof (struct symbol
*)));
16288 /* Attach fields and member functions to the type. */
16289 if (fi
.nfields () > 0)
16290 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
16291 if (!fi
.fnfieldlists
.empty ())
16293 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
16295 /* Get the type which refers to the base class (possibly this
16296 class itself) which contains the vtable pointer for the current
16297 class from the DW_AT_containing_type attribute. This use of
16298 DW_AT_containing_type is a GNU extension. */
16300 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
16302 struct type
*t
= die_containing_type (die
, cu
);
16304 set_type_vptr_basetype (type
, t
);
16309 /* Our own class provides vtbl ptr. */
16310 for (i
= t
->num_fields () - 1;
16311 i
>= TYPE_N_BASECLASSES (t
);
16314 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
16316 if (is_vtable_name (fieldname
, cu
))
16318 set_type_vptr_fieldno (type
, i
);
16323 /* Complain if virtual function table field not found. */
16324 if (i
< TYPE_N_BASECLASSES (t
))
16325 complaint (_("virtual function table pointer "
16326 "not found when defining class '%s'"),
16327 type
->name () ? type
->name () : "");
16331 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
16334 else if (cu
->producer
16335 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
16337 /* The IBM XLC compiler does not provide direct indication
16338 of the containing type, but the vtable pointer is
16339 always named __vfp. */
16343 for (i
= type
->num_fields () - 1;
16344 i
>= TYPE_N_BASECLASSES (type
);
16347 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
16349 set_type_vptr_fieldno (type
, i
);
16350 set_type_vptr_basetype (type
, type
);
16357 /* Copy fi.typedef_field_list linked list elements content into the
16358 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
16359 if (!fi
.typedef_field_list
.empty ())
16361 int count
= fi
.typedef_field_list
.size ();
16363 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16364 TYPE_TYPEDEF_FIELD_ARRAY (type
)
16365 = ((struct decl_field
*)
16367 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
16368 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
16370 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
16371 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
16374 /* Copy fi.nested_types_list linked list elements content into the
16375 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
16376 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
16378 int count
= fi
.nested_types_list
.size ();
16380 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16381 TYPE_NESTED_TYPES_ARRAY (type
)
16382 = ((struct decl_field
*)
16383 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
16384 TYPE_NESTED_TYPES_COUNT (type
) = count
;
16386 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
16387 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
16391 quirk_gcc_member_function_pointer (type
, objfile
);
16392 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
16393 cu
->rust_unions
.push_back (type
);
16394 else if (cu
->language
== language_ada
)
16395 quirk_ada_thick_pointer_struct (die
, cu
, type
);
16397 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
16398 snapshots) has been known to create a die giving a declaration
16399 for a class that has, as a child, a die giving a definition for a
16400 nested class. So we have to process our children even if the
16401 current die is a declaration. Normally, of course, a declaration
16402 won't have any children at all. */
16404 child_die
= die
->child
;
16406 while (child_die
!= NULL
&& child_die
->tag
)
16408 if (child_die
->tag
== DW_TAG_member
16409 || child_die
->tag
== DW_TAG_variable
16410 || child_die
->tag
== DW_TAG_inheritance
16411 || child_die
->tag
== DW_TAG_template_value_param
16412 || child_die
->tag
== DW_TAG_template_type_param
)
16417 process_die (child_die
, cu
);
16419 child_die
= child_die
->sibling
;
16422 /* Do not consider external references. According to the DWARF standard,
16423 these DIEs are identified by the fact that they have no byte_size
16424 attribute, and a declaration attribute. */
16425 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
16426 || !die_is_declaration (die
, cu
)
16427 || dwarf2_attr (die
, DW_AT_signature
, cu
) != NULL
)
16429 struct symbol
*sym
= new_symbol (die
, type
, cu
);
16431 if (has_template_parameters
)
16433 struct symtab
*symtab
;
16434 if (sym
!= nullptr)
16435 symtab
= symbol_symtab (sym
);
16436 else if (cu
->line_header
!= nullptr)
16438 /* Any related symtab will do. */
16440 = cu
->line_header
->file_names ()[0].symtab
;
16445 complaint (_("could not find suitable "
16446 "symtab for template parameter"
16447 " - DIE at %s [in module %s]"),
16448 sect_offset_str (die
->sect_off
),
16449 objfile_name (objfile
));
16452 if (symtab
!= nullptr)
16454 /* Make sure that the symtab is set on the new symbols.
16455 Even though they don't appear in this symtab directly,
16456 other parts of gdb assume that symbols do, and this is
16457 reasonably true. */
16458 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
16459 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
16465 /* Assuming DIE is an enumeration type, and TYPE is its associated
16466 type, update TYPE using some information only available in DIE's
16467 children. In particular, the fields are computed. */
16470 update_enumeration_type_from_children (struct die_info
*die
,
16472 struct dwarf2_cu
*cu
)
16474 struct die_info
*child_die
;
16475 int unsigned_enum
= 1;
16478 auto_obstack obstack
;
16479 std::vector
<struct field
> fields
;
16481 for (child_die
= die
->child
;
16482 child_die
!= NULL
&& child_die
->tag
;
16483 child_die
= child_die
->sibling
)
16485 struct attribute
*attr
;
16487 const gdb_byte
*bytes
;
16488 struct dwarf2_locexpr_baton
*baton
;
16491 if (child_die
->tag
!= DW_TAG_enumerator
)
16494 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16498 name
= dwarf2_name (child_die
, cu
);
16500 name
= "<anonymous enumerator>";
16502 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16503 &value
, &bytes
, &baton
);
16511 if (count_one_bits_ll (value
) >= 2)
16515 fields
.emplace_back ();
16516 struct field
&field
= fields
.back ();
16517 FIELD_NAME (field
) = dwarf2_physname (name
, child_die
, cu
);
16518 SET_FIELD_ENUMVAL (field
, value
);
16521 if (!fields
.empty ())
16523 type
->set_num_fields (fields
.size ());
16526 TYPE_ALLOC (type
, sizeof (struct field
) * fields
.size ()));
16527 memcpy (type
->fields (), fields
.data (),
16528 sizeof (struct field
) * fields
.size ());
16532 type
->set_is_unsigned (true);
16535 TYPE_FLAG_ENUM (type
) = 1;
16538 /* Given a DW_AT_enumeration_type die, set its type. We do not
16539 complete the type's fields yet, or create any symbols. */
16541 static struct type
*
16542 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16544 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16546 struct attribute
*attr
;
16549 /* If the definition of this type lives in .debug_types, read that type.
16550 Don't follow DW_AT_specification though, that will take us back up
16551 the chain and we want to go down. */
16552 attr
= die
->attr (DW_AT_signature
);
16553 if (attr
!= nullptr)
16555 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16557 /* The type's CU may not be the same as CU.
16558 Ensure TYPE is recorded with CU in die_type_hash. */
16559 return set_die_type (die
, type
, cu
);
16562 type
= alloc_type (objfile
);
16564 type
->set_code (TYPE_CODE_ENUM
);
16565 name
= dwarf2_full_name (NULL
, die
, cu
);
16567 type
->set_name (name
);
16569 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16572 struct type
*underlying_type
= die_type (die
, cu
);
16574 TYPE_TARGET_TYPE (type
) = underlying_type
;
16577 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16578 if (attr
!= nullptr)
16580 TYPE_LENGTH (type
) = attr
->constant_value (0);
16584 TYPE_LENGTH (type
) = 0;
16587 maybe_set_alignment (cu
, die
, type
);
16589 /* The enumeration DIE can be incomplete. In Ada, any type can be
16590 declared as private in the package spec, and then defined only
16591 inside the package body. Such types are known as Taft Amendment
16592 Types. When another package uses such a type, an incomplete DIE
16593 may be generated by the compiler. */
16594 if (die_is_declaration (die
, cu
))
16595 type
->set_is_stub (true);
16597 /* If this type has an underlying type that is not a stub, then we
16598 may use its attributes. We always use the "unsigned" attribute
16599 in this situation, because ordinarily we guess whether the type
16600 is unsigned -- but the guess can be wrong and the underlying type
16601 can tell us the reality. However, we defer to a local size
16602 attribute if one exists, because this lets the compiler override
16603 the underlying type if needed. */
16604 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_TARGET_TYPE (type
)->is_stub ())
16606 struct type
*underlying_type
= TYPE_TARGET_TYPE (type
);
16607 underlying_type
= check_typedef (underlying_type
);
16609 type
->set_is_unsigned (underlying_type
->is_unsigned ());
16611 if (TYPE_LENGTH (type
) == 0)
16612 TYPE_LENGTH (type
) = TYPE_LENGTH (underlying_type
);
16614 if (TYPE_RAW_ALIGN (type
) == 0
16615 && TYPE_RAW_ALIGN (underlying_type
) != 0)
16616 set_type_align (type
, TYPE_RAW_ALIGN (underlying_type
));
16619 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16621 set_die_type (die
, type
, cu
);
16623 /* Finish the creation of this type by using the enum's children.
16624 Note that, as usual, this must come after set_die_type to avoid
16625 infinite recursion when trying to compute the names of the
16627 update_enumeration_type_from_children (die
, type
, cu
);
16632 /* Given a pointer to a die which begins an enumeration, process all
16633 the dies that define the members of the enumeration, and create the
16634 symbol for the enumeration type.
16636 NOTE: We reverse the order of the element list. */
16639 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16641 struct type
*this_type
;
16643 this_type
= get_die_type (die
, cu
);
16644 if (this_type
== NULL
)
16645 this_type
= read_enumeration_type (die
, cu
);
16647 if (die
->child
!= NULL
)
16649 struct die_info
*child_die
;
16652 child_die
= die
->child
;
16653 while (child_die
&& child_die
->tag
)
16655 if (child_die
->tag
!= DW_TAG_enumerator
)
16657 process_die (child_die
, cu
);
16661 name
= dwarf2_name (child_die
, cu
);
16663 new_symbol (child_die
, this_type
, cu
);
16666 child_die
= child_die
->sibling
;
16670 /* If we are reading an enum from a .debug_types unit, and the enum
16671 is a declaration, and the enum is not the signatured type in the
16672 unit, then we do not want to add a symbol for it. Adding a
16673 symbol would in some cases obscure the true definition of the
16674 enum, giving users an incomplete type when the definition is
16675 actually available. Note that we do not want to do this for all
16676 enums which are just declarations, because C++0x allows forward
16677 enum declarations. */
16678 if (cu
->per_cu
->is_debug_types
16679 && die_is_declaration (die
, cu
))
16681 struct signatured_type
*sig_type
;
16683 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16684 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16685 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16689 new_symbol (die
, this_type
, cu
);
16692 /* Helper function for quirk_ada_thick_pointer that examines a bounds
16693 expression for an index type and finds the corresponding field
16694 offset in the hidden "P_BOUNDS" structure. Returns true on success
16695 and updates *FIELD, false if it fails to recognize an
16699 recognize_bound_expression (struct die_info
*die
, enum dwarf_attribute name
,
16700 int *bounds_offset
, struct field
*field
,
16701 struct dwarf2_cu
*cu
)
16703 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
16704 if (attr
== nullptr || !attr
->form_is_block ())
16707 const struct dwarf_block
*block
= attr
->as_block ();
16708 const gdb_byte
*start
= block
->data
;
16709 const gdb_byte
*end
= block
->data
+ block
->size
;
16711 /* The expression to recognize generally looks like:
16713 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16714 DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
16716 However, the second "plus_uconst" may be missing:
16718 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16719 DW_OP_deref_size: 4)
16721 This happens when the field is at the start of the structure.
16723 Also, the final deref may not be sized:
16725 (DW_OP_push_object_address; DW_OP_plus_uconst: 4; DW_OP_deref;
16728 This happens when the size of the index type happens to be the
16729 same as the architecture's word size. This can occur with or
16730 without the second plus_uconst. */
16732 if (end
- start
< 2)
16734 if (*start
++ != DW_OP_push_object_address
)
16736 if (*start
++ != DW_OP_plus_uconst
)
16739 uint64_t this_bound_off
;
16740 start
= gdb_read_uleb128 (start
, end
, &this_bound_off
);
16741 if (start
== nullptr || (int) this_bound_off
!= this_bound_off
)
16743 /* Update *BOUNDS_OFFSET if needed, or alternatively verify that it
16744 is consistent among all bounds. */
16745 if (*bounds_offset
== -1)
16746 *bounds_offset
= this_bound_off
;
16747 else if (*bounds_offset
!= this_bound_off
)
16750 if (start
== end
|| *start
++ != DW_OP_deref
)
16756 else if (*start
== DW_OP_deref_size
|| *start
== DW_OP_deref
)
16758 /* This means an offset of 0. */
16760 else if (*start
++ != DW_OP_plus_uconst
)
16764 /* The size is the parameter to DW_OP_plus_uconst. */
16766 start
= gdb_read_uleb128 (start
, end
, &val
);
16767 if (start
== nullptr)
16769 if ((int) val
!= val
)
16778 if (*start
== DW_OP_deref_size
)
16780 start
= gdb_read_uleb128 (start
+ 1, end
, &size
);
16781 if (start
== nullptr)
16784 else if (*start
== DW_OP_deref
)
16786 size
= cu
->header
.addr_size
;
16792 SET_FIELD_BITPOS (*field
, 8 * offset
);
16793 if (size
!= TYPE_LENGTH (field
->type ()))
16794 FIELD_BITSIZE (*field
) = 8 * size
;
16799 /* With -fgnat-encodings=minimal, gcc will emit some unusual DWARF for
16800 some kinds of Ada arrays:
16802 <1><11db>: Abbrev Number: 7 (DW_TAG_array_type)
16803 <11dc> DW_AT_name : (indirect string, offset: 0x1bb8): string
16804 <11e0> DW_AT_data_location: 2 byte block: 97 6
16805 (DW_OP_push_object_address; DW_OP_deref)
16806 <11e3> DW_AT_type : <0x1173>
16807 <11e7> DW_AT_sibling : <0x1201>
16808 <2><11eb>: Abbrev Number: 8 (DW_TAG_subrange_type)
16809 <11ec> DW_AT_type : <0x1206>
16810 <11f0> DW_AT_lower_bound : 6 byte block: 97 23 8 6 94 4
16811 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16812 DW_OP_deref_size: 4)
16813 <11f7> DW_AT_upper_bound : 8 byte block: 97 23 8 6 23 4 94 4
16814 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16815 DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
16817 This actually represents a "thick pointer", which is a structure
16818 with two elements: one that is a pointer to the array data, and one
16819 that is a pointer to another structure; this second structure holds
16822 This returns a new type on success, or nullptr if this didn't
16823 recognize the type. */
16825 static struct type
*
16826 quirk_ada_thick_pointer (struct die_info
*die
, struct dwarf2_cu
*cu
,
16829 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
16830 /* So far we've only seen this with block form. */
16831 if (attr
== nullptr || !attr
->form_is_block ())
16834 /* Note that this will fail if the structure layout is changed by
16835 the compiler. However, we have no good way to recognize some
16836 other layout, because we don't know what expression the compiler
16837 might choose to emit should this happen. */
16838 struct dwarf_block
*blk
= attr
->as_block ();
16840 || blk
->data
[0] != DW_OP_push_object_address
16841 || blk
->data
[1] != DW_OP_deref
)
16844 int bounds_offset
= -1;
16845 int max_align
= -1;
16846 std::vector
<struct field
> range_fields
;
16847 for (struct die_info
*child_die
= die
->child
;
16849 child_die
= child_die
->sibling
)
16851 if (child_die
->tag
== DW_TAG_subrange_type
)
16853 struct type
*underlying
= read_subrange_index_type (child_die
, cu
);
16855 int this_align
= type_align (underlying
);
16856 if (this_align
> max_align
)
16857 max_align
= this_align
;
16859 range_fields
.emplace_back ();
16860 range_fields
.emplace_back ();
16862 struct field
&lower
= range_fields
[range_fields
.size () - 2];
16863 struct field
&upper
= range_fields
[range_fields
.size () - 1];
16865 lower
.set_type (underlying
);
16866 FIELD_ARTIFICIAL (lower
) = 1;
16868 upper
.set_type (underlying
);
16869 FIELD_ARTIFICIAL (upper
) = 1;
16871 if (!recognize_bound_expression (child_die
, DW_AT_lower_bound
,
16872 &bounds_offset
, &lower
, cu
)
16873 || !recognize_bound_expression (child_die
, DW_AT_upper_bound
,
16874 &bounds_offset
, &upper
, cu
))
16879 /* This shouldn't really happen, but double-check that we found
16880 where the bounds are stored. */
16881 if (bounds_offset
== -1)
16884 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16885 for (int i
= 0; i
< range_fields
.size (); i
+= 2)
16889 /* Set the name of each field in the bounds. */
16890 xsnprintf (name
, sizeof (name
), "LB%d", i
/ 2);
16891 FIELD_NAME (range_fields
[i
]) = objfile
->intern (name
);
16892 xsnprintf (name
, sizeof (name
), "UB%d", i
/ 2);
16893 FIELD_NAME (range_fields
[i
+ 1]) = objfile
->intern (name
);
16896 struct type
*bounds
= alloc_type (objfile
);
16897 bounds
->set_code (TYPE_CODE_STRUCT
);
16899 bounds
->set_num_fields (range_fields
.size ());
16901 ((struct field
*) TYPE_ALLOC (bounds
, (bounds
->num_fields ()
16902 * sizeof (struct field
))));
16903 memcpy (bounds
->fields (), range_fields
.data (),
16904 bounds
->num_fields () * sizeof (struct field
));
16906 int last_fieldno
= range_fields
.size () - 1;
16907 int bounds_size
= (TYPE_FIELD_BITPOS (bounds
, last_fieldno
) / 8
16908 + TYPE_LENGTH (bounds
->field (last_fieldno
).type ()));
16909 TYPE_LENGTH (bounds
) = align_up (bounds_size
, max_align
);
16911 /* Rewrite the existing array type in place. Specifically, we
16912 remove any dynamic properties we might have read, and we replace
16913 the index types. */
16914 struct type
*iter
= type
;
16915 for (int i
= 0; i
< range_fields
.size (); i
+= 2)
16917 gdb_assert (iter
->code () == TYPE_CODE_ARRAY
);
16918 iter
->main_type
->dyn_prop_list
= nullptr;
16919 iter
->set_index_type
16920 (create_static_range_type (NULL
, bounds
->field (i
).type (), 1, 0));
16921 iter
= TYPE_TARGET_TYPE (iter
);
16924 struct type
*result
= alloc_type (objfile
);
16925 result
->set_code (TYPE_CODE_STRUCT
);
16927 result
->set_num_fields (2);
16929 ((struct field
*) TYPE_ZALLOC (result
, (result
->num_fields ()
16930 * sizeof (struct field
))));
16932 /* The names are chosen to coincide with what the compiler does with
16933 -fgnat-encodings=all, which the Ada code in gdb already
16935 TYPE_FIELD_NAME (result
, 0) = "P_ARRAY";
16936 result
->field (0).set_type (lookup_pointer_type (type
));
16938 TYPE_FIELD_NAME (result
, 1) = "P_BOUNDS";
16939 result
->field (1).set_type (lookup_pointer_type (bounds
));
16940 SET_FIELD_BITPOS (result
->field (1), 8 * bounds_offset
);
16942 result
->set_name (type
->name ());
16943 TYPE_LENGTH (result
) = (TYPE_LENGTH (result
->field (0).type ())
16944 + TYPE_LENGTH (result
->field (1).type ()));
16949 /* Extract all information from a DW_TAG_array_type DIE and put it in
16950 the DIE's type field. For now, this only handles one dimensional
16953 static struct type
*
16954 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16956 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16957 struct die_info
*child_die
;
16959 struct type
*element_type
, *range_type
, *index_type
;
16960 struct attribute
*attr
;
16962 struct dynamic_prop
*byte_stride_prop
= NULL
;
16963 unsigned int bit_stride
= 0;
16965 element_type
= die_type (die
, cu
);
16967 /* The die_type call above may have already set the type for this DIE. */
16968 type
= get_die_type (die
, cu
);
16972 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16976 struct type
*prop_type
= cu
->addr_sized_int_type (false);
16979 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16980 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
16984 complaint (_("unable to read array DW_AT_byte_stride "
16985 " - DIE at %s [in module %s]"),
16986 sect_offset_str (die
->sect_off
),
16987 objfile_name (cu
->per_objfile
->objfile
));
16988 /* Ignore this attribute. We will likely not be able to print
16989 arrays of this type correctly, but there is little we can do
16990 to help if we cannot read the attribute's value. */
16991 byte_stride_prop
= NULL
;
16995 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16997 bit_stride
= attr
->constant_value (0);
16999 /* Irix 6.2 native cc creates array types without children for
17000 arrays with unspecified length. */
17001 if (die
->child
== NULL
)
17003 index_type
= objfile_type (objfile
)->builtin_int
;
17004 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
17005 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
17006 byte_stride_prop
, bit_stride
);
17007 return set_die_type (die
, type
, cu
);
17010 std::vector
<struct type
*> range_types
;
17011 child_die
= die
->child
;
17012 while (child_die
&& child_die
->tag
)
17014 if (child_die
->tag
== DW_TAG_subrange_type
)
17016 struct type
*child_type
= read_type_die (child_die
, cu
);
17018 if (child_type
!= NULL
)
17020 /* The range type was succesfully read. Save it for the
17021 array type creation. */
17022 range_types
.push_back (child_type
);
17025 child_die
= child_die
->sibling
;
17028 if (range_types
.empty ())
17030 complaint (_("unable to find array range - DIE at %s [in module %s]"),
17031 sect_offset_str (die
->sect_off
),
17032 objfile_name (cu
->per_objfile
->objfile
));
17036 /* Dwarf2 dimensions are output from left to right, create the
17037 necessary array types in backwards order. */
17039 type
= element_type
;
17041 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
17045 while (i
< range_types
.size ())
17047 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
17048 byte_stride_prop
, bit_stride
);
17050 byte_stride_prop
= nullptr;
17055 size_t ndim
= range_types
.size ();
17058 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
17059 byte_stride_prop
, bit_stride
);
17061 byte_stride_prop
= nullptr;
17065 gdb_assert (type
!= element_type
);
17067 /* Understand Dwarf2 support for vector types (like they occur on
17068 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
17069 array type. This is not part of the Dwarf2/3 standard yet, but a
17070 custom vendor extension. The main difference between a regular
17071 array and the vector variant is that vectors are passed by value
17073 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
17074 if (attr
!= nullptr)
17075 make_vector_type (type
);
17077 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
17078 implementation may choose to implement triple vectors using this
17080 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17081 if (attr
!= nullptr && attr
->form_is_unsigned ())
17083 if (attr
->as_unsigned () >= TYPE_LENGTH (type
))
17084 TYPE_LENGTH (type
) = attr
->as_unsigned ();
17086 complaint (_("DW_AT_byte_size for array type smaller "
17087 "than the total size of elements"));
17090 name
= dwarf2_name (die
, cu
);
17092 type
->set_name (name
);
17094 maybe_set_alignment (cu
, die
, type
);
17096 struct type
*replacement_type
= nullptr;
17097 if (cu
->language
== language_ada
)
17099 replacement_type
= quirk_ada_thick_pointer (die
, cu
, type
);
17100 if (replacement_type
!= nullptr)
17101 type
= replacement_type
;
17104 /* Install the type in the die. */
17105 set_die_type (die
, type
, cu
, replacement_type
!= nullptr);
17107 /* set_die_type should be already done. */
17108 set_descriptive_type (type
, die
, cu
);
17113 static enum dwarf_array_dim_ordering
17114 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
17116 struct attribute
*attr
;
17118 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
17120 if (attr
!= nullptr)
17122 LONGEST val
= attr
->constant_value (-1);
17123 if (val
== DW_ORD_row_major
|| val
== DW_ORD_col_major
)
17124 return (enum dwarf_array_dim_ordering
) val
;
17127 /* GNU F77 is a special case, as at 08/2004 array type info is the
17128 opposite order to the dwarf2 specification, but data is still
17129 laid out as per normal fortran.
17131 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
17132 version checking. */
17134 if (cu
->language
== language_fortran
17135 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
17137 return DW_ORD_row_major
;
17140 switch (cu
->language_defn
->array_ordering ())
17142 case array_column_major
:
17143 return DW_ORD_col_major
;
17144 case array_row_major
:
17146 return DW_ORD_row_major
;
17150 /* Extract all information from a DW_TAG_set_type DIE and put it in
17151 the DIE's type field. */
17153 static struct type
*
17154 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17156 struct type
*domain_type
, *set_type
;
17157 struct attribute
*attr
;
17159 domain_type
= die_type (die
, cu
);
17161 /* The die_type call above may have already set the type for this DIE. */
17162 set_type
= get_die_type (die
, cu
);
17166 set_type
= create_set_type (NULL
, domain_type
);
17168 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17169 if (attr
!= nullptr && attr
->form_is_unsigned ())
17170 TYPE_LENGTH (set_type
) = attr
->as_unsigned ();
17172 maybe_set_alignment (cu
, die
, set_type
);
17174 return set_die_type (die
, set_type
, cu
);
17177 /* A helper for read_common_block that creates a locexpr baton.
17178 SYM is the symbol which we are marking as computed.
17179 COMMON_DIE is the DIE for the common block.
17180 COMMON_LOC is the location expression attribute for the common
17182 MEMBER_LOC is the location expression attribute for the particular
17183 member of the common block that we are processing.
17184 CU is the CU from which the above come. */
17187 mark_common_block_symbol_computed (struct symbol
*sym
,
17188 struct die_info
*common_die
,
17189 struct attribute
*common_loc
,
17190 struct attribute
*member_loc
,
17191 struct dwarf2_cu
*cu
)
17193 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
17194 struct objfile
*objfile
= per_objfile
->objfile
;
17195 struct dwarf2_locexpr_baton
*baton
;
17197 unsigned int cu_off
;
17198 enum bfd_endian byte_order
= gdbarch_byte_order (objfile
->arch ());
17199 LONGEST offset
= 0;
17201 gdb_assert (common_loc
&& member_loc
);
17202 gdb_assert (common_loc
->form_is_block ());
17203 gdb_assert (member_loc
->form_is_block ()
17204 || member_loc
->form_is_constant ());
17206 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
17207 baton
->per_objfile
= per_objfile
;
17208 baton
->per_cu
= cu
->per_cu
;
17209 gdb_assert (baton
->per_cu
);
17211 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
17213 if (member_loc
->form_is_constant ())
17215 offset
= member_loc
->constant_value (0);
17216 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
17219 baton
->size
+= member_loc
->as_block ()->size
;
17221 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
17224 *ptr
++ = DW_OP_call4
;
17225 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
17226 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
17229 if (member_loc
->form_is_constant ())
17231 *ptr
++ = DW_OP_addr
;
17232 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
17233 ptr
+= cu
->header
.addr_size
;
17237 /* We have to copy the data here, because DW_OP_call4 will only
17238 use a DW_AT_location attribute. */
17239 struct dwarf_block
*block
= member_loc
->as_block ();
17240 memcpy (ptr
, block
->data
, block
->size
);
17241 ptr
+= block
->size
;
17244 *ptr
++ = DW_OP_plus
;
17245 gdb_assert (ptr
- baton
->data
== baton
->size
);
17247 SYMBOL_LOCATION_BATON (sym
) = baton
;
17248 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
17251 /* Create appropriate locally-scoped variables for all the
17252 DW_TAG_common_block entries. Also create a struct common_block
17253 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
17254 is used to separate the common blocks name namespace from regular
17258 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
17260 struct attribute
*attr
;
17262 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
17263 if (attr
!= nullptr)
17265 /* Support the .debug_loc offsets. */
17266 if (attr
->form_is_block ())
17270 else if (attr
->form_is_section_offset ())
17272 dwarf2_complex_location_expr_complaint ();
17277 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17278 "common block member");
17283 if (die
->child
!= NULL
)
17285 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17286 struct die_info
*child_die
;
17287 size_t n_entries
= 0, size
;
17288 struct common_block
*common_block
;
17289 struct symbol
*sym
;
17291 for (child_die
= die
->child
;
17292 child_die
&& child_die
->tag
;
17293 child_die
= child_die
->sibling
)
17296 size
= (sizeof (struct common_block
)
17297 + (n_entries
- 1) * sizeof (struct symbol
*));
17299 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
17301 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
17302 common_block
->n_entries
= 0;
17304 for (child_die
= die
->child
;
17305 child_die
&& child_die
->tag
;
17306 child_die
= child_die
->sibling
)
17308 /* Create the symbol in the DW_TAG_common_block block in the current
17310 sym
= new_symbol (child_die
, NULL
, cu
);
17313 struct attribute
*member_loc
;
17315 common_block
->contents
[common_block
->n_entries
++] = sym
;
17317 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
17321 /* GDB has handled this for a long time, but it is
17322 not specified by DWARF. It seems to have been
17323 emitted by gfortran at least as recently as:
17324 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
17325 complaint (_("Variable in common block has "
17326 "DW_AT_data_member_location "
17327 "- DIE at %s [in module %s]"),
17328 sect_offset_str (child_die
->sect_off
),
17329 objfile_name (objfile
));
17331 if (member_loc
->form_is_section_offset ())
17332 dwarf2_complex_location_expr_complaint ();
17333 else if (member_loc
->form_is_constant ()
17334 || member_loc
->form_is_block ())
17336 if (attr
!= nullptr)
17337 mark_common_block_symbol_computed (sym
, die
, attr
,
17341 dwarf2_complex_location_expr_complaint ();
17346 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
17347 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
17351 /* Create a type for a C++ namespace. */
17353 static struct type
*
17354 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17356 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17357 const char *previous_prefix
, *name
;
17361 /* For extensions, reuse the type of the original namespace. */
17362 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
17364 struct die_info
*ext_die
;
17365 struct dwarf2_cu
*ext_cu
= cu
;
17367 ext_die
= dwarf2_extension (die
, &ext_cu
);
17368 type
= read_type_die (ext_die
, ext_cu
);
17370 /* EXT_CU may not be the same as CU.
17371 Ensure TYPE is recorded with CU in die_type_hash. */
17372 return set_die_type (die
, type
, cu
);
17375 name
= namespace_name (die
, &is_anonymous
, cu
);
17377 /* Now build the name of the current namespace. */
17379 previous_prefix
= determine_prefix (die
, cu
);
17380 if (previous_prefix
[0] != '\0')
17381 name
= typename_concat (&objfile
->objfile_obstack
,
17382 previous_prefix
, name
, 0, cu
);
17384 /* Create the type. */
17385 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
17387 return set_die_type (die
, type
, cu
);
17390 /* Read a namespace scope. */
17393 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
17395 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17398 /* Add a symbol associated to this if we haven't seen the namespace
17399 before. Also, add a using directive if it's an anonymous
17402 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
17406 type
= read_type_die (die
, cu
);
17407 new_symbol (die
, type
, cu
);
17409 namespace_name (die
, &is_anonymous
, cu
);
17412 const char *previous_prefix
= determine_prefix (die
, cu
);
17414 std::vector
<const char *> excludes
;
17415 add_using_directive (using_directives (cu
),
17416 previous_prefix
, type
->name (), NULL
,
17417 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
17421 if (die
->child
!= NULL
)
17423 struct die_info
*child_die
= die
->child
;
17425 while (child_die
&& child_die
->tag
)
17427 process_die (child_die
, cu
);
17428 child_die
= child_die
->sibling
;
17433 /* Read a Fortran module as type. This DIE can be only a declaration used for
17434 imported module. Still we need that type as local Fortran "use ... only"
17435 declaration imports depend on the created type in determine_prefix. */
17437 static struct type
*
17438 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17440 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17441 const char *module_name
;
17444 module_name
= dwarf2_name (die
, cu
);
17445 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
17447 return set_die_type (die
, type
, cu
);
17450 /* Read a Fortran module. */
17453 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
17455 struct die_info
*child_die
= die
->child
;
17458 type
= read_type_die (die
, cu
);
17459 new_symbol (die
, type
, cu
);
17461 while (child_die
&& child_die
->tag
)
17463 process_die (child_die
, cu
);
17464 child_die
= child_die
->sibling
;
17468 /* Return the name of the namespace represented by DIE. Set
17469 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
17472 static const char *
17473 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
17475 struct die_info
*current_die
;
17476 const char *name
= NULL
;
17478 /* Loop through the extensions until we find a name. */
17480 for (current_die
= die
;
17481 current_die
!= NULL
;
17482 current_die
= dwarf2_extension (die
, &cu
))
17484 /* We don't use dwarf2_name here so that we can detect the absence
17485 of a name -> anonymous namespace. */
17486 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
17492 /* Is it an anonymous namespace? */
17494 *is_anonymous
= (name
== NULL
);
17496 name
= CP_ANONYMOUS_NAMESPACE_STR
;
17501 /* Extract all information from a DW_TAG_pointer_type DIE and add to
17502 the user defined type vector. */
17504 static struct type
*
17505 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17507 struct gdbarch
*gdbarch
= cu
->per_objfile
->objfile
->arch ();
17508 struct comp_unit_head
*cu_header
= &cu
->header
;
17510 struct attribute
*attr_byte_size
;
17511 struct attribute
*attr_address_class
;
17512 int byte_size
, addr_class
;
17513 struct type
*target_type
;
17515 target_type
= die_type (die
, cu
);
17517 /* The die_type call above may have already set the type for this DIE. */
17518 type
= get_die_type (die
, cu
);
17522 type
= lookup_pointer_type (target_type
);
17524 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17525 if (attr_byte_size
)
17526 byte_size
= attr_byte_size
->constant_value (cu_header
->addr_size
);
17528 byte_size
= cu_header
->addr_size
;
17530 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
17531 if (attr_address_class
)
17532 addr_class
= attr_address_class
->constant_value (DW_ADDR_none
);
17534 addr_class
= DW_ADDR_none
;
17536 ULONGEST alignment
= get_alignment (cu
, die
);
17538 /* If the pointer size, alignment, or address class is different
17539 than the default, create a type variant marked as such and set
17540 the length accordingly. */
17541 if (TYPE_LENGTH (type
) != byte_size
17542 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
17543 && alignment
!= TYPE_RAW_ALIGN (type
))
17544 || addr_class
!= DW_ADDR_none
)
17546 if (gdbarch_address_class_type_flags_p (gdbarch
))
17548 type_instance_flags type_flags
17549 = gdbarch_address_class_type_flags (gdbarch
, byte_size
,
17551 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
17553 type
= make_type_with_address_space (type
, type_flags
);
17555 else if (TYPE_LENGTH (type
) != byte_size
)
17557 complaint (_("invalid pointer size %d"), byte_size
);
17559 else if (TYPE_RAW_ALIGN (type
) != alignment
)
17561 complaint (_("Invalid DW_AT_alignment"
17562 " - DIE at %s [in module %s]"),
17563 sect_offset_str (die
->sect_off
),
17564 objfile_name (cu
->per_objfile
->objfile
));
17568 /* Should we also complain about unhandled address classes? */
17572 TYPE_LENGTH (type
) = byte_size
;
17573 set_type_align (type
, alignment
);
17574 return set_die_type (die
, type
, cu
);
17577 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
17578 the user defined type vector. */
17580 static struct type
*
17581 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17584 struct type
*to_type
;
17585 struct type
*domain
;
17587 to_type
= die_type (die
, cu
);
17588 domain
= die_containing_type (die
, cu
);
17590 /* The calls above may have already set the type for this DIE. */
17591 type
= get_die_type (die
, cu
);
17595 if (check_typedef (to_type
)->code () == TYPE_CODE_METHOD
)
17596 type
= lookup_methodptr_type (to_type
);
17597 else if (check_typedef (to_type
)->code () == TYPE_CODE_FUNC
)
17599 struct type
*new_type
= alloc_type (cu
->per_objfile
->objfile
);
17601 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
17602 to_type
->fields (), to_type
->num_fields (),
17603 to_type
->has_varargs ());
17604 type
= lookup_methodptr_type (new_type
);
17607 type
= lookup_memberptr_type (to_type
, domain
);
17609 return set_die_type (die
, type
, cu
);
17612 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
17613 the user defined type vector. */
17615 static struct type
*
17616 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17617 enum type_code refcode
)
17619 struct comp_unit_head
*cu_header
= &cu
->header
;
17620 struct type
*type
, *target_type
;
17621 struct attribute
*attr
;
17623 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
17625 target_type
= die_type (die
, cu
);
17627 /* The die_type call above may have already set the type for this DIE. */
17628 type
= get_die_type (die
, cu
);
17632 type
= lookup_reference_type (target_type
, refcode
);
17633 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17634 if (attr
!= nullptr)
17636 TYPE_LENGTH (type
) = attr
->constant_value (cu_header
->addr_size
);
17640 TYPE_LENGTH (type
) = cu_header
->addr_size
;
17642 maybe_set_alignment (cu
, die
, type
);
17643 return set_die_type (die
, type
, cu
);
17646 /* Add the given cv-qualifiers to the element type of the array. GCC
17647 outputs DWARF type qualifiers that apply to an array, not the
17648 element type. But GDB relies on the array element type to carry
17649 the cv-qualifiers. This mimics section 6.7.3 of the C99
17652 static struct type
*
17653 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17654 struct type
*base_type
, int cnst
, int voltl
)
17656 struct type
*el_type
, *inner_array
;
17658 base_type
= copy_type (base_type
);
17659 inner_array
= base_type
;
17661 while (TYPE_TARGET_TYPE (inner_array
)->code () == TYPE_CODE_ARRAY
)
17663 TYPE_TARGET_TYPE (inner_array
) =
17664 copy_type (TYPE_TARGET_TYPE (inner_array
));
17665 inner_array
= TYPE_TARGET_TYPE (inner_array
);
17668 el_type
= TYPE_TARGET_TYPE (inner_array
);
17669 cnst
|= TYPE_CONST (el_type
);
17670 voltl
|= TYPE_VOLATILE (el_type
);
17671 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
17673 return set_die_type (die
, base_type
, cu
);
17676 static struct type
*
17677 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17679 struct type
*base_type
, *cv_type
;
17681 base_type
= die_type (die
, cu
);
17683 /* The die_type call above may have already set the type for this DIE. */
17684 cv_type
= get_die_type (die
, cu
);
17688 /* In case the const qualifier is applied to an array type, the element type
17689 is so qualified, not the array type (section 6.7.3 of C99). */
17690 if (base_type
->code () == TYPE_CODE_ARRAY
)
17691 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
17693 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
17694 return set_die_type (die
, cv_type
, cu
);
17697 static struct type
*
17698 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17700 struct type
*base_type
, *cv_type
;
17702 base_type
= die_type (die
, cu
);
17704 /* The die_type call above may have already set the type for this DIE. */
17705 cv_type
= get_die_type (die
, cu
);
17709 /* In case the volatile qualifier is applied to an array type, the
17710 element type is so qualified, not the array type (section 6.7.3
17712 if (base_type
->code () == TYPE_CODE_ARRAY
)
17713 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17715 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17716 return set_die_type (die
, cv_type
, cu
);
17719 /* Handle DW_TAG_restrict_type. */
17721 static struct type
*
17722 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17724 struct type
*base_type
, *cv_type
;
17726 base_type
= die_type (die
, cu
);
17728 /* The die_type call above may have already set the type for this DIE. */
17729 cv_type
= get_die_type (die
, cu
);
17733 cv_type
= make_restrict_type (base_type
);
17734 return set_die_type (die
, cv_type
, cu
);
17737 /* Handle DW_TAG_atomic_type. */
17739 static struct type
*
17740 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17742 struct type
*base_type
, *cv_type
;
17744 base_type
= die_type (die
, cu
);
17746 /* The die_type call above may have already set the type for this DIE. */
17747 cv_type
= get_die_type (die
, cu
);
17751 cv_type
= make_atomic_type (base_type
);
17752 return set_die_type (die
, cv_type
, cu
);
17755 /* Extract all information from a DW_TAG_string_type DIE and add to
17756 the user defined type vector. It isn't really a user defined type,
17757 but it behaves like one, with other DIE's using an AT_user_def_type
17758 attribute to reference it. */
17760 static struct type
*
17761 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17763 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17764 struct gdbarch
*gdbarch
= objfile
->arch ();
17765 struct type
*type
, *range_type
, *index_type
, *char_type
;
17766 struct attribute
*attr
;
17767 struct dynamic_prop prop
;
17768 bool length_is_constant
= true;
17771 /* There are a couple of places where bit sizes might be made use of
17772 when parsing a DW_TAG_string_type, however, no producer that we know
17773 of make use of these. Handling bit sizes that are a multiple of the
17774 byte size is easy enough, but what about other bit sizes? Lets deal
17775 with that problem when we have to. Warn about these attributes being
17776 unsupported, then parse the type and ignore them like we always
17778 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
17779 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
17781 static bool warning_printed
= false;
17782 if (!warning_printed
)
17784 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
17785 "currently supported on DW_TAG_string_type."));
17786 warning_printed
= true;
17790 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17791 if (attr
!= nullptr && !attr
->form_is_constant ())
17793 /* The string length describes the location at which the length of
17794 the string can be found. The size of the length field can be
17795 specified with one of the attributes below. */
17796 struct type
*prop_type
;
17797 struct attribute
*len
17798 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
17799 if (len
== nullptr)
17800 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17801 if (len
!= nullptr && len
->form_is_constant ())
17803 /* Pass 0 as the default as we know this attribute is constant
17804 and the default value will not be returned. */
17805 LONGEST sz
= len
->constant_value (0);
17806 prop_type
= cu
->per_objfile
->int_type (sz
, true);
17810 /* If the size is not specified then we assume it is the size of
17811 an address on this target. */
17812 prop_type
= cu
->addr_sized_int_type (true);
17815 /* Convert the attribute into a dynamic property. */
17816 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
17819 length_is_constant
= false;
17821 else if (attr
!= nullptr)
17823 /* This DW_AT_string_length just contains the length with no
17824 indirection. There's no need to create a dynamic property in this
17825 case. Pass 0 for the default value as we know it will not be
17826 returned in this case. */
17827 length
= attr
->constant_value (0);
17829 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
17831 /* We don't currently support non-constant byte sizes for strings. */
17832 length
= attr
->constant_value (1);
17836 /* Use 1 as a fallback length if we have nothing else. */
17840 index_type
= objfile_type (objfile
)->builtin_int
;
17841 if (length_is_constant
)
17842 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17845 struct dynamic_prop low_bound
;
17847 low_bound
.set_const_val (1);
17848 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
17850 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17851 type
= create_string_type (NULL
, char_type
, range_type
);
17853 return set_die_type (die
, type
, cu
);
17856 /* Assuming that DIE corresponds to a function, returns nonzero
17857 if the function is prototyped. */
17860 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17862 struct attribute
*attr
;
17864 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17865 if (attr
&& attr
->as_boolean ())
17868 /* The DWARF standard implies that the DW_AT_prototyped attribute
17869 is only meaningful for C, but the concept also extends to other
17870 languages that allow unprototyped functions (Eg: Objective C).
17871 For all other languages, assume that functions are always
17873 if (cu
->language
!= language_c
17874 && cu
->language
!= language_objc
17875 && cu
->language
!= language_opencl
)
17878 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17879 prototyped and unprototyped functions; default to prototyped,
17880 since that is more common in modern code (and RealView warns
17881 about unprototyped functions). */
17882 if (producer_is_realview (cu
->producer
))
17888 /* Handle DIES due to C code like:
17892 int (*funcp)(int a, long l);
17896 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17898 static struct type
*
17899 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17901 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17902 struct type
*type
; /* Type that this function returns. */
17903 struct type
*ftype
; /* Function that returns above type. */
17904 struct attribute
*attr
;
17906 type
= die_type (die
, cu
);
17908 /* The die_type call above may have already set the type for this DIE. */
17909 ftype
= get_die_type (die
, cu
);
17913 ftype
= lookup_function_type (type
);
17915 if (prototyped_function_p (die
, cu
))
17916 ftype
->set_is_prototyped (true);
17918 /* Store the calling convention in the type if it's available in
17919 the subroutine die. Otherwise set the calling convention to
17920 the default value DW_CC_normal. */
17921 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17922 if (attr
!= nullptr
17923 && is_valid_DW_AT_calling_convention_for_subroutine (attr
->constant_value (0)))
17924 TYPE_CALLING_CONVENTION (ftype
)
17925 = (enum dwarf_calling_convention
) attr
->constant_value (0);
17926 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17927 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17929 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17931 /* Record whether the function returns normally to its caller or not
17932 if the DWARF producer set that information. */
17933 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17934 if (attr
&& attr
->as_boolean ())
17935 TYPE_NO_RETURN (ftype
) = 1;
17937 /* We need to add the subroutine type to the die immediately so
17938 we don't infinitely recurse when dealing with parameters
17939 declared as the same subroutine type. */
17940 set_die_type (die
, ftype
, cu
);
17942 if (die
->child
!= NULL
)
17944 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17945 struct die_info
*child_die
;
17946 int nparams
, iparams
;
17948 /* Count the number of parameters.
17949 FIXME: GDB currently ignores vararg functions, but knows about
17950 vararg member functions. */
17952 child_die
= die
->child
;
17953 while (child_die
&& child_die
->tag
)
17955 if (child_die
->tag
== DW_TAG_formal_parameter
)
17957 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17958 ftype
->set_has_varargs (true);
17960 child_die
= child_die
->sibling
;
17963 /* Allocate storage for parameters and fill them in. */
17964 ftype
->set_num_fields (nparams
);
17966 ((struct field
*) TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
)));
17968 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17969 even if we error out during the parameters reading below. */
17970 for (iparams
= 0; iparams
< nparams
; iparams
++)
17971 ftype
->field (iparams
).set_type (void_type
);
17974 child_die
= die
->child
;
17975 while (child_die
&& child_die
->tag
)
17977 if (child_die
->tag
== DW_TAG_formal_parameter
)
17979 struct type
*arg_type
;
17981 /* DWARF version 2 has no clean way to discern C++
17982 static and non-static member functions. G++ helps
17983 GDB by marking the first parameter for non-static
17984 member functions (which is the this pointer) as
17985 artificial. We pass this information to
17986 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17988 DWARF version 3 added DW_AT_object_pointer, which GCC
17989 4.5 does not yet generate. */
17990 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17991 if (attr
!= nullptr)
17992 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = attr
->as_boolean ();
17994 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17995 arg_type
= die_type (child_die
, cu
);
17997 /* RealView does not mark THIS as const, which the testsuite
17998 expects. GCC marks THIS as const in method definitions,
17999 but not in the class specifications (GCC PR 43053). */
18000 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
18001 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
18004 struct dwarf2_cu
*arg_cu
= cu
;
18005 const char *name
= dwarf2_name (child_die
, cu
);
18007 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
18008 if (attr
!= nullptr)
18010 /* If the compiler emits this, use it. */
18011 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
18014 else if (name
&& strcmp (name
, "this") == 0)
18015 /* Function definitions will have the argument names. */
18017 else if (name
== NULL
&& iparams
== 0)
18018 /* Declarations may not have the names, so like
18019 elsewhere in GDB, assume an artificial first
18020 argument is "this". */
18024 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
18028 ftype
->field (iparams
).set_type (arg_type
);
18031 child_die
= child_die
->sibling
;
18038 static struct type
*
18039 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
18041 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18042 const char *name
= NULL
;
18043 struct type
*this_type
, *target_type
;
18045 name
= dwarf2_full_name (NULL
, die
, cu
);
18046 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
18047 this_type
->set_target_is_stub (true);
18048 set_die_type (die
, this_type
, cu
);
18049 target_type
= die_type (die
, cu
);
18050 if (target_type
!= this_type
)
18051 TYPE_TARGET_TYPE (this_type
) = target_type
;
18054 /* Self-referential typedefs are, it seems, not allowed by the DWARF
18055 spec and cause infinite loops in GDB. */
18056 complaint (_("Self-referential DW_TAG_typedef "
18057 "- DIE at %s [in module %s]"),
18058 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
18059 TYPE_TARGET_TYPE (this_type
) = NULL
;
18063 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
18064 anonymous typedefs, which is, strictly speaking, invalid DWARF.
18065 Handle these by just returning the target type, rather than
18066 constructing an anonymous typedef type and trying to handle this
18068 set_die_type (die
, target_type
, cu
);
18069 return target_type
;
18074 /* Helper for get_dwarf2_rational_constant that computes the value of
18075 a given gmp_mpz given an attribute. */
18078 get_mpz (struct dwarf2_cu
*cu
, gdb_mpz
*value
, struct attribute
*attr
)
18080 /* GCC will sometimes emit a 16-byte constant value as a DWARF
18081 location expression that pushes an implicit value. */
18082 if (attr
->form
== DW_FORM_exprloc
)
18084 dwarf_block
*blk
= attr
->as_block ();
18085 if (blk
->size
> 0 && blk
->data
[0] == DW_OP_implicit_value
)
18088 const gdb_byte
*ptr
= safe_read_uleb128 (blk
->data
+ 1,
18089 blk
->data
+ blk
->size
,
18091 if (ptr
- blk
->data
+ len
<= blk
->size
)
18093 mpz_import (value
->val
, len
,
18094 bfd_big_endian (cu
->per_objfile
->objfile
->obfd
) ? 1 : -1,
18100 /* On failure set it to 1. */
18101 *value
= gdb_mpz (1);
18103 else if (attr
->form_is_block ())
18105 dwarf_block
*blk
= attr
->as_block ();
18106 mpz_import (value
->val
, blk
->size
,
18107 bfd_big_endian (cu
->per_objfile
->objfile
->obfd
) ? 1 : -1,
18108 1, 0, 0, blk
->data
);
18111 *value
= gdb_mpz (attr
->constant_value (1));
18114 /* Assuming DIE is a rational DW_TAG_constant, read the DIE's
18115 numerator and denominator into NUMERATOR and DENOMINATOR (resp).
18117 If the numerator and/or numerator attribute is missing,
18118 a complaint is filed, and NUMERATOR and DENOMINATOR are left
18122 get_dwarf2_rational_constant (struct die_info
*die
, struct dwarf2_cu
*cu
,
18123 gdb_mpz
*numerator
, gdb_mpz
*denominator
)
18125 struct attribute
*num_attr
, *denom_attr
;
18127 num_attr
= dwarf2_attr (die
, DW_AT_GNU_numerator
, cu
);
18128 if (num_attr
== nullptr)
18129 complaint (_("DW_AT_GNU_numerator missing in %s DIE at %s"),
18130 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
18132 denom_attr
= dwarf2_attr (die
, DW_AT_GNU_denominator
, cu
);
18133 if (denom_attr
== nullptr)
18134 complaint (_("DW_AT_GNU_denominator missing in %s DIE at %s"),
18135 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
18137 if (num_attr
== nullptr || denom_attr
== nullptr)
18140 get_mpz (cu
, numerator
, num_attr
);
18141 get_mpz (cu
, denominator
, denom_attr
);
18144 /* Same as get_dwarf2_rational_constant, but extracting an unsigned
18145 rational constant, rather than a signed one.
18147 If the rational constant has a negative value, a complaint
18148 is filed, and NUMERATOR and DENOMINATOR are left untouched. */
18151 get_dwarf2_unsigned_rational_constant (struct die_info
*die
,
18152 struct dwarf2_cu
*cu
,
18153 gdb_mpz
*numerator
,
18154 gdb_mpz
*denominator
)
18159 get_dwarf2_rational_constant (die
, cu
, &num
, &denom
);
18160 if (mpz_sgn (num
.val
) == -1 && mpz_sgn (denom
.val
) == -1)
18162 mpz_neg (num
.val
, num
.val
);
18163 mpz_neg (denom
.val
, denom
.val
);
18165 else if (mpz_sgn (num
.val
) == -1)
18167 complaint (_("unexpected negative value for DW_AT_GNU_numerator"
18169 sect_offset_str (die
->sect_off
));
18172 else if (mpz_sgn (denom
.val
) == -1)
18174 complaint (_("unexpected negative value for DW_AT_GNU_denominator"
18176 sect_offset_str (die
->sect_off
));
18180 *numerator
= std::move (num
);
18181 *denominator
= std::move (denom
);
18184 /* Assuming that ENCODING is a string whose contents starting at the
18185 K'th character is "_nn" where "nn" is a decimal number, scan that
18186 number and set RESULT to the value. K is updated to point to the
18187 character immediately following the number.
18189 If the string does not conform to the format described above, false
18190 is returned, and K may or may not be changed. */
18193 ada_get_gnat_encoded_number (const char *encoding
, int &k
, gdb_mpz
*result
)
18195 /* The next character should be an underscore ('_') followed
18197 if (encoding
[k
] != '_' || !isdigit (encoding
[k
+ 1]))
18200 /* Skip the underscore. */
18204 /* Determine the number of digits for our number. */
18205 while (isdigit (encoding
[k
]))
18210 std::string
copy (&encoding
[start
], k
- start
);
18211 if (mpz_set_str (result
->val
, copy
.c_str (), 10) == -1)
18217 /* Scan two numbers from ENCODING at OFFSET, assuming the string is of
18218 the form _NN_DD, where NN and DD are decimal numbers. Set NUM and
18219 DENOM, update OFFSET, and return true on success. Return false on
18223 ada_get_gnat_encoded_ratio (const char *encoding
, int &offset
,
18224 gdb_mpz
*num
, gdb_mpz
*denom
)
18226 if (!ada_get_gnat_encoded_number (encoding
, offset
, num
))
18228 return ada_get_gnat_encoded_number (encoding
, offset
, denom
);
18231 /* Assuming DIE corresponds to a fixed point type, finish the creation
18232 of the corresponding TYPE by setting its type-specific data. CU is
18233 the DIE's CU. SUFFIX is the "XF" type name suffix coming from GNAT
18234 encodings. It is nullptr if the GNAT encoding should be
18238 finish_fixed_point_type (struct type
*type
, const char *suffix
,
18239 struct die_info
*die
, struct dwarf2_cu
*cu
)
18241 gdb_assert (type
->code () == TYPE_CODE_FIXED_POINT
18242 && TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_FIXED_POINT
);
18244 /* If GNAT encodings are preferred, don't examine the
18246 struct attribute
*attr
= nullptr;
18247 if (suffix
== nullptr)
18249 attr
= dwarf2_attr (die
, DW_AT_binary_scale
, cu
);
18250 if (attr
== nullptr)
18251 attr
= dwarf2_attr (die
, DW_AT_decimal_scale
, cu
);
18252 if (attr
== nullptr)
18253 attr
= dwarf2_attr (die
, DW_AT_small
, cu
);
18256 /* Numerator and denominator of our fixed-point type's scaling factor.
18257 The default is a scaling factor of 1, which we use as a fallback
18258 when we are not able to decode it (problem with the debugging info,
18259 unsupported forms, bug in GDB, etc...). Using that as the default
18260 allows us to at least print the unscaled value, which might still
18261 be useful to a user. */
18262 gdb_mpz
scale_num (1);
18263 gdb_mpz
scale_denom (1);
18265 if (attr
== nullptr)
18268 if (suffix
!= nullptr
18269 && ada_get_gnat_encoded_ratio (suffix
, offset
, &scale_num
,
18271 /* The number might be encoded as _nn_dd_nn_dd, where the
18272 second ratio is the 'small value. In this situation, we
18273 want the second value. */
18274 && (suffix
[offset
] != '_'
18275 || ada_get_gnat_encoded_ratio (suffix
, offset
, &scale_num
,
18282 /* Scaling factor not found. Assume a scaling factor of 1,
18283 and hope for the best. At least the user will be able to
18284 see the encoded value. */
18287 complaint (_("no scale found for fixed-point type (DIE at %s)"),
18288 sect_offset_str (die
->sect_off
));
18291 else if (attr
->name
== DW_AT_binary_scale
)
18293 LONGEST scale_exp
= attr
->constant_value (0);
18294 gdb_mpz
*num_or_denom
= scale_exp
> 0 ? &scale_num
: &scale_denom
;
18296 mpz_mul_2exp (num_or_denom
->val
, num_or_denom
->val
, std::abs (scale_exp
));
18298 else if (attr
->name
== DW_AT_decimal_scale
)
18300 LONGEST scale_exp
= attr
->constant_value (0);
18301 gdb_mpz
*num_or_denom
= scale_exp
> 0 ? &scale_num
: &scale_denom
;
18303 mpz_ui_pow_ui (num_or_denom
->val
, 10, std::abs (scale_exp
));
18305 else if (attr
->name
== DW_AT_small
)
18307 struct die_info
*scale_die
;
18308 struct dwarf2_cu
*scale_cu
= cu
;
18310 scale_die
= follow_die_ref (die
, attr
, &scale_cu
);
18311 if (scale_die
->tag
== DW_TAG_constant
)
18312 get_dwarf2_unsigned_rational_constant (scale_die
, scale_cu
,
18313 &scale_num
, &scale_denom
);
18315 complaint (_("%s DIE not supported as target of DW_AT_small attribute"
18317 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
18321 complaint (_("unsupported scale attribute %s for fixed-point type"
18323 dwarf_attr_name (attr
->name
),
18324 sect_offset_str (die
->sect_off
));
18327 gdb_mpq
&scaling_factor
= type
->fixed_point_info ().scaling_factor
;
18328 mpz_set (mpq_numref (scaling_factor
.val
), scale_num
.val
);
18329 mpz_set (mpq_denref (scaling_factor
.val
), scale_denom
.val
);
18330 mpq_canonicalize (scaling_factor
.val
);
18333 /* The gnat-encoding suffix for fixed point. */
18335 #define GNAT_FIXED_POINT_SUFFIX "___XF_"
18337 /* If NAME encodes an Ada fixed-point type, return a pointer to the
18338 "XF" suffix of the name. The text after this is what encodes the
18339 'small and 'delta information. Otherwise, return nullptr. */
18341 static const char *
18342 gnat_encoded_fixed_point_type_info (const char *name
)
18344 return strstr (name
, GNAT_FIXED_POINT_SUFFIX
);
18347 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
18348 (which may be different from NAME) to the architecture back-end to allow
18349 it to guess the correct format if necessary. */
18351 static struct type
*
18352 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
18353 const char *name_hint
, enum bfd_endian byte_order
)
18355 struct gdbarch
*gdbarch
= objfile
->arch ();
18356 const struct floatformat
**format
;
18359 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
18361 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
18363 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18368 /* Allocate an integer type of size BITS and name NAME. */
18370 static struct type
*
18371 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
18372 int bits
, int unsigned_p
, const char *name
)
18376 /* Versions of Intel's C Compiler generate an integer type called "void"
18377 instead of using DW_TAG_unspecified_type. This has been seen on
18378 at least versions 14, 17, and 18. */
18379 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
18380 && strcmp (name
, "void") == 0)
18381 type
= objfile_type (objfile
)->builtin_void
;
18383 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
18388 /* Return true if DIE has a DW_AT_small attribute whose value is
18389 a constant rational, where both the numerator and denominator
18392 CU is the DIE's Compilation Unit. */
18395 has_zero_over_zero_small_attribute (struct die_info
*die
,
18396 struct dwarf2_cu
*cu
)
18398 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_small
, cu
);
18399 if (attr
== nullptr)
18402 struct dwarf2_cu
*scale_cu
= cu
;
18403 struct die_info
*scale_die
18404 = follow_die_ref (die
, attr
, &scale_cu
);
18406 if (scale_die
->tag
!= DW_TAG_constant
)
18409 gdb_mpz
num (1), denom (1);
18410 get_dwarf2_rational_constant (scale_die
, cu
, &num
, &denom
);
18411 return mpz_sgn (num
.val
) == 0 && mpz_sgn (denom
.val
) == 0;
18414 /* Initialise and return a floating point type of size BITS suitable for
18415 use as a component of a complex number. The NAME_HINT is passed through
18416 when initialising the floating point type and is the name of the complex
18419 As DWARF doesn't currently provide an explicit name for the components
18420 of a complex number, but it can be helpful to have these components
18421 named, we try to select a suitable name based on the size of the
18423 static struct type
*
18424 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
18425 struct objfile
*objfile
,
18426 int bits
, const char *name_hint
,
18427 enum bfd_endian byte_order
)
18429 gdbarch
*gdbarch
= objfile
->arch ();
18430 struct type
*tt
= nullptr;
18432 /* Try to find a suitable floating point builtin type of size BITS.
18433 We're going to use the name of this type as the name for the complex
18434 target type that we are about to create. */
18435 switch (cu
->language
)
18437 case language_fortran
:
18441 tt
= builtin_f_type (gdbarch
)->builtin_real
;
18444 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
18446 case 96: /* The x86-32 ABI specifies 96-bit long double. */
18448 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
18456 tt
= builtin_type (gdbarch
)->builtin_float
;
18459 tt
= builtin_type (gdbarch
)->builtin_double
;
18461 case 96: /* The x86-32 ABI specifies 96-bit long double. */
18463 tt
= builtin_type (gdbarch
)->builtin_long_double
;
18469 /* If the type we found doesn't match the size we were looking for, then
18470 pretend we didn't find a type at all, the complex target type we
18471 create will then be nameless. */
18472 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
18475 const char *name
= (tt
== nullptr) ? nullptr : tt
->name ();
18476 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
18479 /* Find a representation of a given base type and install
18480 it in the TYPE field of the die. */
18482 static struct type
*
18483 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18485 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18487 struct attribute
*attr
;
18488 int encoding
= 0, bits
= 0;
18492 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
18493 if (attr
!= nullptr && attr
->form_is_constant ())
18494 encoding
= attr
->constant_value (0);
18495 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18496 if (attr
!= nullptr)
18497 bits
= attr
->constant_value (0) * TARGET_CHAR_BIT
;
18498 name
= dwarf2_name (die
, cu
);
18500 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
18502 arch
= objfile
->arch ();
18503 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
18505 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
18506 if (attr
!= nullptr && attr
->form_is_constant ())
18508 int endianity
= attr
->constant_value (0);
18513 byte_order
= BFD_ENDIAN_BIG
;
18515 case DW_END_little
:
18516 byte_order
= BFD_ENDIAN_LITTLE
;
18519 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
18524 if ((encoding
== DW_ATE_signed_fixed
|| encoding
== DW_ATE_unsigned_fixed
)
18525 && cu
->language
== language_ada
18526 && has_zero_over_zero_small_attribute (die
, cu
))
18528 /* brobecker/2018-02-24: This is a fixed point type for which
18529 the scaling factor is represented as fraction whose value
18530 does not make sense (zero divided by zero), so we should
18531 normally never see these. However, there is a small category
18532 of fixed point types for which GNAT is unable to provide
18533 the scaling factor via the standard DWARF mechanisms, and
18534 for which the info is provided via the GNAT encodings instead.
18535 This is likely what this DIE is about. */
18536 encoding
= (encoding
== DW_ATE_signed_fixed
18538 : DW_ATE_unsigned
);
18541 /* With GNAT encodings, fixed-point information will be encoded in
18542 the type name. Note that this can also occur with the above
18543 zero-over-zero case, which is why this is a separate "if" rather
18544 than an "else if". */
18545 const char *gnat_encoding_suffix
= nullptr;
18546 if ((encoding
== DW_ATE_signed
|| encoding
== DW_ATE_unsigned
)
18547 && cu
->language
== language_ada
18548 && name
!= nullptr)
18550 gnat_encoding_suffix
= gnat_encoded_fixed_point_type_info (name
);
18551 if (gnat_encoding_suffix
!= nullptr)
18553 gdb_assert (startswith (gnat_encoding_suffix
,
18554 GNAT_FIXED_POINT_SUFFIX
));
18555 name
= obstack_strndup (&cu
->per_objfile
->objfile
->objfile_obstack
,
18556 name
, gnat_encoding_suffix
- name
);
18557 /* Use -1 here so that SUFFIX points at the "_" after the
18559 gnat_encoding_suffix
+= strlen (GNAT_FIXED_POINT_SUFFIX
) - 1;
18561 encoding
= (encoding
== DW_ATE_signed
18562 ? DW_ATE_signed_fixed
18563 : DW_ATE_unsigned_fixed
);
18569 case DW_ATE_address
:
18570 /* Turn DW_ATE_address into a void * pointer. */
18571 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
18572 type
= init_pointer_type (objfile
, bits
, name
, type
);
18574 case DW_ATE_boolean
:
18575 type
= init_boolean_type (objfile
, bits
, 1, name
);
18577 case DW_ATE_complex_float
:
18578 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
18580 if (type
->code () == TYPE_CODE_ERROR
)
18582 if (name
== nullptr)
18584 struct obstack
*obstack
18585 = &cu
->per_objfile
->objfile
->objfile_obstack
;
18586 name
= obconcat (obstack
, "_Complex ", type
->name (),
18589 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18592 type
= init_complex_type (name
, type
);
18594 case DW_ATE_decimal_float
:
18595 type
= init_decfloat_type (objfile
, bits
, name
);
18598 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
18600 case DW_ATE_signed
:
18601 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
18603 case DW_ATE_unsigned
:
18604 if (cu
->language
== language_fortran
18606 && startswith (name
, "character("))
18607 type
= init_character_type (objfile
, bits
, 1, name
);
18609 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18611 case DW_ATE_signed_char
:
18612 if (cu
->language
== language_ada
|| cu
->language
== language_m2
18613 || cu
->language
== language_pascal
18614 || cu
->language
== language_fortran
)
18615 type
= init_character_type (objfile
, bits
, 0, name
);
18617 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
18619 case DW_ATE_unsigned_char
:
18620 if (cu
->language
== language_ada
|| cu
->language
== language_m2
18621 || cu
->language
== language_pascal
18622 || cu
->language
== language_fortran
18623 || cu
->language
== language_rust
)
18624 type
= init_character_type (objfile
, bits
, 1, name
);
18626 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18631 type
= builtin_type (arch
)->builtin_char16
;
18632 else if (bits
== 32)
18633 type
= builtin_type (arch
)->builtin_char32
;
18636 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
18638 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18640 return set_die_type (die
, type
, cu
);
18643 case DW_ATE_signed_fixed
:
18644 type
= init_fixed_point_type (objfile
, bits
, 0, name
);
18645 finish_fixed_point_type (type
, gnat_encoding_suffix
, die
, cu
);
18647 case DW_ATE_unsigned_fixed
:
18648 type
= init_fixed_point_type (objfile
, bits
, 1, name
);
18649 finish_fixed_point_type (type
, gnat_encoding_suffix
, die
, cu
);
18653 complaint (_("unsupported DW_AT_encoding: '%s'"),
18654 dwarf_type_encoding_name (encoding
));
18655 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18659 if (name
&& strcmp (name
, "char") == 0)
18660 type
->set_has_no_signedness (true);
18662 maybe_set_alignment (cu
, die
, type
);
18664 type
->set_endianity_is_not_default (gdbarch_byte_order (arch
) != byte_order
);
18666 if (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_INT
)
18668 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
18669 if (attr
!= nullptr && attr
->as_unsigned () <= 8 * TYPE_LENGTH (type
))
18671 unsigned real_bit_size
= attr
->as_unsigned ();
18672 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
18673 /* Only use the attributes if they make sense together. */
18674 if (attr
== nullptr
18675 || (attr
->as_unsigned () + real_bit_size
18676 <= 8 * TYPE_LENGTH (type
)))
18678 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_size
18680 if (attr
!= nullptr)
18681 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_offset
18682 = attr
->as_unsigned ();
18687 return set_die_type (die
, type
, cu
);
18690 /* Parse dwarf attribute if it's a block, reference or constant and put the
18691 resulting value of the attribute into struct bound_prop.
18692 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
18695 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
18696 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
18697 struct type
*default_type
)
18699 struct dwarf2_property_baton
*baton
;
18700 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
18701 struct objfile
*objfile
= per_objfile
->objfile
;
18702 struct obstack
*obstack
= &objfile
->objfile_obstack
;
18704 gdb_assert (default_type
!= NULL
);
18706 if (attr
== NULL
|| prop
== NULL
)
18709 if (attr
->form_is_block ())
18711 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18712 baton
->property_type
= default_type
;
18713 baton
->locexpr
.per_cu
= cu
->per_cu
;
18714 baton
->locexpr
.per_objfile
= per_objfile
;
18716 struct dwarf_block
*block
= attr
->as_block ();
18717 baton
->locexpr
.size
= block
->size
;
18718 baton
->locexpr
.data
= block
->data
;
18719 switch (attr
->name
)
18721 case DW_AT_string_length
:
18722 baton
->locexpr
.is_reference
= true;
18725 baton
->locexpr
.is_reference
= false;
18729 prop
->set_locexpr (baton
);
18730 gdb_assert (prop
->baton () != NULL
);
18732 else if (attr
->form_is_ref ())
18734 struct dwarf2_cu
*target_cu
= cu
;
18735 struct die_info
*target_die
;
18736 struct attribute
*target_attr
;
18738 target_die
= follow_die_ref (die
, attr
, &target_cu
);
18739 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
18740 if (target_attr
== NULL
)
18741 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
18743 if (target_attr
== NULL
)
18746 switch (target_attr
->name
)
18748 case DW_AT_location
:
18749 if (target_attr
->form_is_section_offset ())
18751 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18752 baton
->property_type
= die_type (target_die
, target_cu
);
18753 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
18754 prop
->set_loclist (baton
);
18755 gdb_assert (prop
->baton () != NULL
);
18757 else if (target_attr
->form_is_block ())
18759 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18760 baton
->property_type
= die_type (target_die
, target_cu
);
18761 baton
->locexpr
.per_cu
= cu
->per_cu
;
18762 baton
->locexpr
.per_objfile
= per_objfile
;
18763 struct dwarf_block
*block
= target_attr
->as_block ();
18764 baton
->locexpr
.size
= block
->size
;
18765 baton
->locexpr
.data
= block
->data
;
18766 baton
->locexpr
.is_reference
= true;
18767 prop
->set_locexpr (baton
);
18768 gdb_assert (prop
->baton () != NULL
);
18772 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18773 "dynamic property");
18777 case DW_AT_data_member_location
:
18781 if (!handle_data_member_location (target_die
, target_cu
,
18785 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18786 baton
->property_type
= read_type_die (target_die
->parent
,
18788 baton
->offset_info
.offset
= offset
;
18789 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
18790 prop
->set_addr_offset (baton
);
18795 else if (attr
->form_is_constant ())
18796 prop
->set_const_val (attr
->constant_value (0));
18799 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
18800 dwarf2_name (die
, cu
));
18810 dwarf2_per_objfile::int_type (int size_in_bytes
, bool unsigned_p
) const
18812 struct type
*int_type
;
18814 /* Helper macro to examine the various builtin types. */
18815 #define TRY_TYPE(F) \
18816 int_type = (unsigned_p \
18817 ? objfile_type (objfile)->builtin_unsigned_ ## F \
18818 : objfile_type (objfile)->builtin_ ## F); \
18819 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
18826 TRY_TYPE (long_long
);
18830 gdb_assert_not_reached ("unable to find suitable integer type");
18836 dwarf2_cu::addr_sized_int_type (bool unsigned_p
) const
18838 int addr_size
= this->per_cu
->addr_size ();
18839 return this->per_objfile
->int_type (addr_size
, unsigned_p
);
18842 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
18843 present (which is valid) then compute the default type based on the
18844 compilation units address size. */
18846 static struct type
*
18847 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18849 struct type
*index_type
= die_type (die
, cu
);
18851 /* Dwarf-2 specifications explicitly allows to create subrange types
18852 without specifying a base type.
18853 In that case, the base type must be set to the type of
18854 the lower bound, upper bound or count, in that order, if any of these
18855 three attributes references an object that has a type.
18856 If no base type is found, the Dwarf-2 specifications say that
18857 a signed integer type of size equal to the size of an address should
18859 For the following C code: `extern char gdb_int [];'
18860 GCC produces an empty range DIE.
18861 FIXME: muller/2010-05-28: Possible references to object for low bound,
18862 high bound or count are not yet handled by this code. */
18863 if (index_type
->code () == TYPE_CODE_VOID
)
18864 index_type
= cu
->addr_sized_int_type (false);
18869 /* Read the given DW_AT_subrange DIE. */
18871 static struct type
*
18872 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18874 struct type
*base_type
, *orig_base_type
;
18875 struct type
*range_type
;
18876 struct attribute
*attr
;
18877 struct dynamic_prop low
, high
;
18878 int low_default_is_valid
;
18879 int high_bound_is_count
= 0;
18881 ULONGEST negative_mask
;
18883 orig_base_type
= read_subrange_index_type (die
, cu
);
18885 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
18886 whereas the real type might be. So, we use ORIG_BASE_TYPE when
18887 creating the range type, but we use the result of check_typedef
18888 when examining properties of the type. */
18889 base_type
= check_typedef (orig_base_type
);
18891 /* The die_type call above may have already set the type for this DIE. */
18892 range_type
= get_die_type (die
, cu
);
18896 high
.set_const_val (0);
18898 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
18899 omitting DW_AT_lower_bound. */
18900 switch (cu
->language
)
18903 case language_cplus
:
18904 low
.set_const_val (0);
18905 low_default_is_valid
= 1;
18907 case language_fortran
:
18908 low
.set_const_val (1);
18909 low_default_is_valid
= 1;
18912 case language_objc
:
18913 case language_rust
:
18914 low
.set_const_val (0);
18915 low_default_is_valid
= (cu
->header
.version
>= 4);
18919 case language_pascal
:
18920 low
.set_const_val (1);
18921 low_default_is_valid
= (cu
->header
.version
>= 4);
18924 low
.set_const_val (0);
18925 low_default_is_valid
= 0;
18929 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
18930 if (attr
!= nullptr)
18931 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
18932 else if (!low_default_is_valid
)
18933 complaint (_("Missing DW_AT_lower_bound "
18934 "- DIE at %s [in module %s]"),
18935 sect_offset_str (die
->sect_off
),
18936 objfile_name (cu
->per_objfile
->objfile
));
18938 struct attribute
*attr_ub
, *attr_count
;
18939 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
18940 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18942 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
18943 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18945 /* If bounds are constant do the final calculation here. */
18946 if (low
.kind () == PROP_CONST
&& high
.kind () == PROP_CONST
)
18947 high
.set_const_val (low
.const_val () + high
.const_val () - 1);
18949 high_bound_is_count
= 1;
18953 if (attr_ub
!= NULL
)
18954 complaint (_("Unresolved DW_AT_upper_bound "
18955 "- DIE at %s [in module %s]"),
18956 sect_offset_str (die
->sect_off
),
18957 objfile_name (cu
->per_objfile
->objfile
));
18958 if (attr_count
!= NULL
)
18959 complaint (_("Unresolved DW_AT_count "
18960 "- DIE at %s [in module %s]"),
18961 sect_offset_str (die
->sect_off
),
18962 objfile_name (cu
->per_objfile
->objfile
));
18967 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
18968 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
18969 bias
= bias_attr
->constant_value (0);
18971 /* Normally, the DWARF producers are expected to use a signed
18972 constant form (Eg. DW_FORM_sdata) to express negative bounds.
18973 But this is unfortunately not always the case, as witnessed
18974 with GCC, for instance, where the ambiguous DW_FORM_dataN form
18975 is used instead. To work around that ambiguity, we treat
18976 the bounds as signed, and thus sign-extend their values, when
18977 the base type is signed. */
18979 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
18980 if (low
.kind () == PROP_CONST
18981 && !base_type
->is_unsigned () && (low
.const_val () & negative_mask
))
18982 low
.set_const_val (low
.const_val () | negative_mask
);
18983 if (high
.kind () == PROP_CONST
18984 && !base_type
->is_unsigned () && (high
.const_val () & negative_mask
))
18985 high
.set_const_val (high
.const_val () | negative_mask
);
18987 /* Check for bit and byte strides. */
18988 struct dynamic_prop byte_stride_prop
;
18989 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
18990 if (attr_byte_stride
!= nullptr)
18992 struct type
*prop_type
= cu
->addr_sized_int_type (false);
18993 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
18997 struct dynamic_prop bit_stride_prop
;
18998 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
18999 if (attr_bit_stride
!= nullptr)
19001 /* It only makes sense to have either a bit or byte stride. */
19002 if (attr_byte_stride
!= nullptr)
19004 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
19005 "- DIE at %s [in module %s]"),
19006 sect_offset_str (die
->sect_off
),
19007 objfile_name (cu
->per_objfile
->objfile
));
19008 attr_bit_stride
= nullptr;
19012 struct type
*prop_type
= cu
->addr_sized_int_type (false);
19013 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
19018 if (attr_byte_stride
!= nullptr
19019 || attr_bit_stride
!= nullptr)
19021 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
19022 struct dynamic_prop
*stride
19023 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
19026 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
19027 &high
, bias
, stride
, byte_stride_p
);
19030 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
19032 if (high_bound_is_count
)
19033 range_type
->bounds ()->flag_upper_bound_is_count
= 1;
19035 /* Ada expects an empty array on no boundary attributes. */
19036 if (attr
== NULL
&& cu
->language
!= language_ada
)
19037 range_type
->bounds ()->high
.set_undefined ();
19039 name
= dwarf2_name (die
, cu
);
19041 range_type
->set_name (name
);
19043 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
19044 if (attr
!= nullptr)
19045 TYPE_LENGTH (range_type
) = attr
->constant_value (0);
19047 maybe_set_alignment (cu
, die
, range_type
);
19049 set_die_type (die
, range_type
, cu
);
19051 /* set_die_type should be already done. */
19052 set_descriptive_type (range_type
, die
, cu
);
19057 static struct type
*
19058 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
19062 type
= init_type (cu
->per_objfile
->objfile
, TYPE_CODE_VOID
, 0, NULL
);
19063 type
->set_name (dwarf2_name (die
, cu
));
19065 /* In Ada, an unspecified type is typically used when the description
19066 of the type is deferred to a different unit. When encountering
19067 such a type, we treat it as a stub, and try to resolve it later on,
19069 if (cu
->language
== language_ada
)
19070 type
->set_is_stub (true);
19072 return set_die_type (die
, type
, cu
);
19075 /* Read a single die and all its descendents. Set the die's sibling
19076 field to NULL; set other fields in the die correctly, and set all
19077 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
19078 location of the info_ptr after reading all of those dies. PARENT
19079 is the parent of the die in question. */
19081 static struct die_info
*
19082 read_die_and_children (const struct die_reader_specs
*reader
,
19083 const gdb_byte
*info_ptr
,
19084 const gdb_byte
**new_info_ptr
,
19085 struct die_info
*parent
)
19087 struct die_info
*die
;
19088 const gdb_byte
*cur_ptr
;
19090 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
19093 *new_info_ptr
= cur_ptr
;
19096 store_in_ref_table (die
, reader
->cu
);
19098 if (die
->has_children
)
19099 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
19103 *new_info_ptr
= cur_ptr
;
19106 die
->sibling
= NULL
;
19107 die
->parent
= parent
;
19111 /* Read a die, all of its descendents, and all of its siblings; set
19112 all of the fields of all of the dies correctly. Arguments are as
19113 in read_die_and_children. */
19115 static struct die_info
*
19116 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
19117 const gdb_byte
*info_ptr
,
19118 const gdb_byte
**new_info_ptr
,
19119 struct die_info
*parent
)
19121 struct die_info
*first_die
, *last_sibling
;
19122 const gdb_byte
*cur_ptr
;
19124 cur_ptr
= info_ptr
;
19125 first_die
= last_sibling
= NULL
;
19129 struct die_info
*die
19130 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
19134 *new_info_ptr
= cur_ptr
;
19141 last_sibling
->sibling
= die
;
19143 last_sibling
= die
;
19147 /* Read a die, all of its descendents, and all of its siblings; set
19148 all of the fields of all of the dies correctly. Arguments are as
19149 in read_die_and_children.
19150 This the main entry point for reading a DIE and all its children. */
19152 static struct die_info
*
19153 read_die_and_siblings (const struct die_reader_specs
*reader
,
19154 const gdb_byte
*info_ptr
,
19155 const gdb_byte
**new_info_ptr
,
19156 struct die_info
*parent
)
19158 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
19159 new_info_ptr
, parent
);
19161 if (dwarf_die_debug
)
19163 fprintf_unfiltered (gdb_stdlog
,
19164 "Read die from %s@0x%x of %s:\n",
19165 reader
->die_section
->get_name (),
19166 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
19167 bfd_get_filename (reader
->abfd
));
19168 dump_die (die
, dwarf_die_debug
);
19174 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
19176 The caller is responsible for filling in the extra attributes
19177 and updating (*DIEP)->num_attrs.
19178 Set DIEP to point to a newly allocated die with its information,
19179 except for its child, sibling, and parent fields. */
19181 static const gdb_byte
*
19182 read_full_die_1 (const struct die_reader_specs
*reader
,
19183 struct die_info
**diep
, const gdb_byte
*info_ptr
,
19184 int num_extra_attrs
)
19186 unsigned int abbrev_number
, bytes_read
, i
;
19187 const struct abbrev_info
*abbrev
;
19188 struct die_info
*die
;
19189 struct dwarf2_cu
*cu
= reader
->cu
;
19190 bfd
*abfd
= reader
->abfd
;
19192 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
19193 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19194 info_ptr
+= bytes_read
;
19195 if (!abbrev_number
)
19201 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
19203 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
19205 bfd_get_filename (abfd
));
19207 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
19208 die
->sect_off
= sect_off
;
19209 die
->tag
= abbrev
->tag
;
19210 die
->abbrev
= abbrev_number
;
19211 die
->has_children
= abbrev
->has_children
;
19213 /* Make the result usable.
19214 The caller needs to update num_attrs after adding the extra
19216 die
->num_attrs
= abbrev
->num_attrs
;
19218 bool any_need_reprocess
= false;
19219 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
19221 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
19223 if (die
->attrs
[i
].requires_reprocessing_p ())
19224 any_need_reprocess
= true;
19227 struct attribute
*attr
= die
->attr (DW_AT_str_offsets_base
);
19228 if (attr
!= nullptr && attr
->form_is_unsigned ())
19229 cu
->str_offsets_base
= attr
->as_unsigned ();
19231 attr
= die
->attr (DW_AT_loclists_base
);
19232 if (attr
!= nullptr)
19233 cu
->loclist_base
= attr
->as_unsigned ();
19235 auto maybe_addr_base
= die
->addr_base ();
19236 if (maybe_addr_base
.has_value ())
19237 cu
->addr_base
= *maybe_addr_base
;
19239 attr
= die
->attr (DW_AT_rnglists_base
);
19240 if (attr
!= nullptr)
19241 cu
->rnglists_base
= attr
->as_unsigned ();
19243 if (any_need_reprocess
)
19245 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
19247 if (die
->attrs
[i
].requires_reprocessing_p ())
19248 read_attribute_reprocess (reader
, &die
->attrs
[i
], die
->tag
);
19255 /* Read a die and all its attributes.
19256 Set DIEP to point to a newly allocated die with its information,
19257 except for its child, sibling, and parent fields. */
19259 static const gdb_byte
*
19260 read_full_die (const struct die_reader_specs
*reader
,
19261 struct die_info
**diep
, const gdb_byte
*info_ptr
)
19263 const gdb_byte
*result
;
19265 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
19267 if (dwarf_die_debug
)
19269 fprintf_unfiltered (gdb_stdlog
,
19270 "Read die from %s@0x%x of %s:\n",
19271 reader
->die_section
->get_name (),
19272 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
19273 bfd_get_filename (reader
->abfd
));
19274 dump_die (*diep
, dwarf_die_debug
);
19281 /* Returns nonzero if TAG represents a type that we might generate a partial
19285 is_type_tag_for_partial (int tag
, enum language lang
)
19290 /* Some types that would be reasonable to generate partial symbols for,
19291 that we don't at present. Note that normally this does not
19292 matter, mainly because C compilers don't give names to these
19293 types, but instead emit DW_TAG_typedef. */
19294 case DW_TAG_file_type
:
19295 case DW_TAG_ptr_to_member_type
:
19296 case DW_TAG_set_type
:
19297 case DW_TAG_string_type
:
19298 case DW_TAG_subroutine_type
:
19301 /* GNAT may emit an array with a name, but no typedef, so we
19302 need to make a symbol in this case. */
19303 case DW_TAG_array_type
:
19304 return lang
== language_ada
;
19306 case DW_TAG_base_type
:
19307 case DW_TAG_class_type
:
19308 case DW_TAG_interface_type
:
19309 case DW_TAG_enumeration_type
:
19310 case DW_TAG_structure_type
:
19311 case DW_TAG_subrange_type
:
19312 case DW_TAG_typedef
:
19313 case DW_TAG_union_type
:
19320 /* Load all DIEs that are interesting for partial symbols into memory. */
19322 static struct partial_die_info
*
19323 load_partial_dies (const struct die_reader_specs
*reader
,
19324 const gdb_byte
*info_ptr
, int building_psymtab
)
19326 struct dwarf2_cu
*cu
= reader
->cu
;
19327 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19328 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
19329 unsigned int bytes_read
;
19330 unsigned int load_all
= 0;
19331 int nesting_level
= 1;
19336 gdb_assert (cu
->per_cu
!= NULL
);
19337 if (cu
->per_cu
->load_all_dies
)
19341 = htab_create_alloc_ex (cu
->header
.length
/ 12,
19345 &cu
->comp_unit_obstack
,
19346 hashtab_obstack_allocate
,
19347 dummy_obstack_deallocate
);
19351 const abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
,
19354 /* A NULL abbrev means the end of a series of children. */
19355 if (abbrev
== NULL
)
19357 if (--nesting_level
== 0)
19360 info_ptr
+= bytes_read
;
19361 last_die
= parent_die
;
19362 parent_die
= parent_die
->die_parent
;
19366 /* Check for template arguments. We never save these; if
19367 they're seen, we just mark the parent, and go on our way. */
19368 if (parent_die
!= NULL
19369 && cu
->language
== language_cplus
19370 && (abbrev
->tag
== DW_TAG_template_type_param
19371 || abbrev
->tag
== DW_TAG_template_value_param
))
19373 parent_die
->has_template_arguments
= 1;
19377 /* We don't need a partial DIE for the template argument. */
19378 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
19383 /* We only recurse into c++ subprograms looking for template arguments.
19384 Skip their other children. */
19386 && cu
->language
== language_cplus
19387 && parent_die
!= NULL
19388 && parent_die
->tag
== DW_TAG_subprogram
19389 && abbrev
->tag
!= DW_TAG_inlined_subroutine
)
19391 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
19395 /* Check whether this DIE is interesting enough to save. Normally
19396 we would not be interested in members here, but there may be
19397 later variables referencing them via DW_AT_specification (for
19398 static members). */
19400 && !is_type_tag_for_partial (abbrev
->tag
, cu
->language
)
19401 && abbrev
->tag
!= DW_TAG_constant
19402 && abbrev
->tag
!= DW_TAG_enumerator
19403 && abbrev
->tag
!= DW_TAG_subprogram
19404 && abbrev
->tag
!= DW_TAG_inlined_subroutine
19405 && abbrev
->tag
!= DW_TAG_lexical_block
19406 && abbrev
->tag
!= DW_TAG_variable
19407 && abbrev
->tag
!= DW_TAG_namespace
19408 && abbrev
->tag
!= DW_TAG_module
19409 && abbrev
->tag
!= DW_TAG_member
19410 && abbrev
->tag
!= DW_TAG_imported_unit
19411 && abbrev
->tag
!= DW_TAG_imported_declaration
)
19413 /* Otherwise we skip to the next sibling, if any. */
19414 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
19418 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
19421 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
19423 /* This two-pass algorithm for processing partial symbols has a
19424 high cost in cache pressure. Thus, handle some simple cases
19425 here which cover the majority of C partial symbols. DIEs
19426 which neither have specification tags in them, nor could have
19427 specification tags elsewhere pointing at them, can simply be
19428 processed and discarded.
19430 This segment is also optional; scan_partial_symbols and
19431 add_partial_symbol will handle these DIEs if we chain
19432 them in normally. When compilers which do not emit large
19433 quantities of duplicate debug information are more common,
19434 this code can probably be removed. */
19436 /* Any complete simple types at the top level (pretty much all
19437 of them, for a language without namespaces), can be processed
19439 if (parent_die
== NULL
19440 && pdi
.has_specification
== 0
19441 && pdi
.is_declaration
== 0
19442 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
19443 || pdi
.tag
== DW_TAG_base_type
19444 || pdi
.tag
== DW_TAG_array_type
19445 || pdi
.tag
== DW_TAG_subrange_type
))
19447 if (building_psymtab
&& pdi
.raw_name
!= NULL
)
19448 add_partial_symbol (&pdi
, cu
);
19450 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
19454 /* The exception for DW_TAG_typedef with has_children above is
19455 a workaround of GCC PR debug/47510. In the case of this complaint
19456 type_name_or_error will error on such types later.
19458 GDB skipped children of DW_TAG_typedef by the shortcut above and then
19459 it could not find the child DIEs referenced later, this is checked
19460 above. In correct DWARF DW_TAG_typedef should have no children. */
19462 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
19463 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
19464 "- DIE at %s [in module %s]"),
19465 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
19467 /* If we're at the second level, and we're an enumerator, and
19468 our parent has no specification (meaning possibly lives in a
19469 namespace elsewhere), then we can add the partial symbol now
19470 instead of queueing it. */
19471 if (pdi
.tag
== DW_TAG_enumerator
19472 && parent_die
!= NULL
19473 && parent_die
->die_parent
== NULL
19474 && parent_die
->tag
== DW_TAG_enumeration_type
19475 && parent_die
->has_specification
== 0)
19477 if (pdi
.raw_name
== NULL
)
19478 complaint (_("malformed enumerator DIE ignored"));
19479 else if (building_psymtab
)
19480 add_partial_symbol (&pdi
, cu
);
19482 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
19486 struct partial_die_info
*part_die
19487 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
19489 /* We'll save this DIE so link it in. */
19490 part_die
->die_parent
= parent_die
;
19491 part_die
->die_sibling
= NULL
;
19492 part_die
->die_child
= NULL
;
19494 if (last_die
&& last_die
== parent_die
)
19495 last_die
->die_child
= part_die
;
19497 last_die
->die_sibling
= part_die
;
19499 last_die
= part_die
;
19501 if (first_die
== NULL
)
19502 first_die
= part_die
;
19504 /* Maybe add the DIE to the hash table. Not all DIEs that we
19505 find interesting need to be in the hash table, because we
19506 also have the parent/sibling/child chains; only those that we
19507 might refer to by offset later during partial symbol reading.
19509 For now this means things that might have be the target of a
19510 DW_AT_specification, DW_AT_abstract_origin, or
19511 DW_AT_extension. DW_AT_extension will refer only to
19512 namespaces; DW_AT_abstract_origin refers to functions (and
19513 many things under the function DIE, but we do not recurse
19514 into function DIEs during partial symbol reading) and
19515 possibly variables as well; DW_AT_specification refers to
19516 declarations. Declarations ought to have the DW_AT_declaration
19517 flag. It happens that GCC forgets to put it in sometimes, but
19518 only for functions, not for types.
19520 Adding more things than necessary to the hash table is harmless
19521 except for the performance cost. Adding too few will result in
19522 wasted time in find_partial_die, when we reread the compilation
19523 unit with load_all_dies set. */
19526 || abbrev
->tag
== DW_TAG_constant
19527 || abbrev
->tag
== DW_TAG_subprogram
19528 || abbrev
->tag
== DW_TAG_variable
19529 || abbrev
->tag
== DW_TAG_namespace
19530 || part_die
->is_declaration
)
19534 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
19535 to_underlying (part_die
->sect_off
),
19540 /* For some DIEs we want to follow their children (if any). For C
19541 we have no reason to follow the children of structures; for other
19542 languages we have to, so that we can get at method physnames
19543 to infer fully qualified class names, for DW_AT_specification,
19544 and for C++ template arguments. For C++, we also look one level
19545 inside functions to find template arguments (if the name of the
19546 function does not already contain the template arguments).
19548 For Ada and Fortran, we need to scan the children of subprograms
19549 and lexical blocks as well because these languages allow the
19550 definition of nested entities that could be interesting for the
19551 debugger, such as nested subprograms for instance. */
19552 if (last_die
->has_children
19554 || last_die
->tag
== DW_TAG_namespace
19555 || last_die
->tag
== DW_TAG_module
19556 || last_die
->tag
== DW_TAG_enumeration_type
19557 || (cu
->language
== language_cplus
19558 && last_die
->tag
== DW_TAG_subprogram
19559 && (last_die
->raw_name
== NULL
19560 || strchr (last_die
->raw_name
, '<') == NULL
))
19561 || (cu
->language
!= language_c
19562 && (last_die
->tag
== DW_TAG_class_type
19563 || last_die
->tag
== DW_TAG_interface_type
19564 || last_die
->tag
== DW_TAG_structure_type
19565 || last_die
->tag
== DW_TAG_union_type
))
19566 || ((cu
->language
== language_ada
19567 || cu
->language
== language_fortran
)
19568 && (last_die
->tag
== DW_TAG_subprogram
19569 || last_die
->tag
== DW_TAG_lexical_block
))))
19572 parent_die
= last_die
;
19576 /* Otherwise we skip to the next sibling, if any. */
19577 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
19579 /* Back to the top, do it again. */
19583 partial_die_info::partial_die_info (sect_offset sect_off_
,
19584 const struct abbrev_info
*abbrev
)
19585 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
19589 /* See class definition. */
19592 partial_die_info::name (dwarf2_cu
*cu
)
19594 if (!canonical_name
&& raw_name
!= nullptr)
19596 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19597 raw_name
= dwarf2_canonicalize_name (raw_name
, cu
, objfile
);
19598 canonical_name
= 1;
19604 /* Read a minimal amount of information into the minimal die structure.
19605 INFO_PTR should point just after the initial uleb128 of a DIE. */
19608 partial_die_info::read (const struct die_reader_specs
*reader
,
19609 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
19611 struct dwarf2_cu
*cu
= reader
->cu
;
19612 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19614 int has_low_pc_attr
= 0;
19615 int has_high_pc_attr
= 0;
19616 int high_pc_relative
= 0;
19618 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
19621 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
], info_ptr
);
19622 /* String and address offsets that need to do the reprocessing have
19623 already been read at this point, so there is no need to wait until
19624 the loop terminates to do the reprocessing. */
19625 if (attr
.requires_reprocessing_p ())
19626 read_attribute_reprocess (reader
, &attr
, tag
);
19627 /* Store the data if it is of an attribute we want to keep in a
19628 partial symbol table. */
19634 case DW_TAG_compile_unit
:
19635 case DW_TAG_partial_unit
:
19636 case DW_TAG_type_unit
:
19637 /* Compilation units have a DW_AT_name that is a filename, not
19638 a source language identifier. */
19639 case DW_TAG_enumeration_type
:
19640 case DW_TAG_enumerator
:
19641 /* These tags always have simple identifiers already; no need
19642 to canonicalize them. */
19643 canonical_name
= 1;
19644 raw_name
= attr
.as_string ();
19647 canonical_name
= 0;
19648 raw_name
= attr
.as_string ();
19652 case DW_AT_linkage_name
:
19653 case DW_AT_MIPS_linkage_name
:
19654 /* Note that both forms of linkage name might appear. We
19655 assume they will be the same, and we only store the last
19657 linkage_name
= attr
.as_string ();
19660 has_low_pc_attr
= 1;
19661 lowpc
= attr
.as_address ();
19663 case DW_AT_high_pc
:
19664 has_high_pc_attr
= 1;
19665 highpc
= attr
.as_address ();
19666 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
19667 high_pc_relative
= 1;
19669 case DW_AT_location
:
19670 /* Support the .debug_loc offsets. */
19671 if (attr
.form_is_block ())
19673 d
.locdesc
= attr
.as_block ();
19675 else if (attr
.form_is_section_offset ())
19677 dwarf2_complex_location_expr_complaint ();
19681 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
19682 "partial symbol information");
19685 case DW_AT_external
:
19686 is_external
= attr
.as_boolean ();
19688 case DW_AT_declaration
:
19689 is_declaration
= attr
.as_boolean ();
19694 case DW_AT_abstract_origin
:
19695 case DW_AT_specification
:
19696 case DW_AT_extension
:
19697 has_specification
= 1;
19698 spec_offset
= attr
.get_ref_die_offset ();
19699 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19700 || cu
->per_cu
->is_dwz
);
19702 case DW_AT_sibling
:
19703 /* Ignore absolute siblings, they might point outside of
19704 the current compile unit. */
19705 if (attr
.form
== DW_FORM_ref_addr
)
19706 complaint (_("ignoring absolute DW_AT_sibling"));
19709 const gdb_byte
*buffer
= reader
->buffer
;
19710 sect_offset off
= attr
.get_ref_die_offset ();
19711 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
19713 if (sibling_ptr
< info_ptr
)
19714 complaint (_("DW_AT_sibling points backwards"));
19715 else if (sibling_ptr
> reader
->buffer_end
)
19716 reader
->die_section
->overflow_complaint ();
19718 sibling
= sibling_ptr
;
19721 case DW_AT_byte_size
:
19724 case DW_AT_const_value
:
19725 has_const_value
= 1;
19727 case DW_AT_calling_convention
:
19728 /* DWARF doesn't provide a way to identify a program's source-level
19729 entry point. DW_AT_calling_convention attributes are only meant
19730 to describe functions' calling conventions.
19732 However, because it's a necessary piece of information in
19733 Fortran, and before DWARF 4 DW_CC_program was the only
19734 piece of debugging information whose definition refers to
19735 a 'main program' at all, several compilers marked Fortran
19736 main programs with DW_CC_program --- even when those
19737 functions use the standard calling conventions.
19739 Although DWARF now specifies a way to provide this
19740 information, we support this practice for backward
19742 if (attr
.constant_value (0) == DW_CC_program
19743 && cu
->language
== language_fortran
)
19744 main_subprogram
= 1;
19748 LONGEST value
= attr
.constant_value (-1);
19749 if (value
== DW_INL_inlined
19750 || value
== DW_INL_declared_inlined
)
19751 may_be_inlined
= 1;
19756 if (tag
== DW_TAG_imported_unit
)
19758 d
.sect_off
= attr
.get_ref_die_offset ();
19759 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19760 || cu
->per_cu
->is_dwz
);
19764 case DW_AT_main_subprogram
:
19765 main_subprogram
= attr
.as_boolean ();
19770 /* Offset in the .debug_ranges or .debug_rnglist section (depending
19771 on DWARF version). */
19772 ULONGEST ranges_offset
= attr
.as_unsigned ();
19774 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
19776 if (tag
!= DW_TAG_compile_unit
)
19777 ranges_offset
+= cu
->gnu_ranges_base
;
19779 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
19790 /* For Ada, if both the name and the linkage name appear, we prefer
19791 the latter. This lets "catch exception" work better, regardless
19792 of the order in which the name and linkage name were emitted.
19793 Really, though, this is just a workaround for the fact that gdb
19794 doesn't store both the name and the linkage name. */
19795 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
19796 raw_name
= linkage_name
;
19798 if (high_pc_relative
)
19801 if (has_low_pc_attr
&& has_high_pc_attr
)
19803 /* When using the GNU linker, .gnu.linkonce. sections are used to
19804 eliminate duplicate copies of functions and vtables and such.
19805 The linker will arbitrarily choose one and discard the others.
19806 The AT_*_pc values for such functions refer to local labels in
19807 these sections. If the section from that file was discarded, the
19808 labels are not in the output, so the relocs get a value of 0.
19809 If this is a discarded function, mark the pc bounds as invalid,
19810 so that GDB will ignore it. */
19811 if (lowpc
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
19813 struct objfile
*objfile
= per_objfile
->objfile
;
19814 struct gdbarch
*gdbarch
= objfile
->arch ();
19816 complaint (_("DW_AT_low_pc %s is zero "
19817 "for DIE at %s [in module %s]"),
19818 paddress (gdbarch
, lowpc
),
19819 sect_offset_str (sect_off
),
19820 objfile_name (objfile
));
19822 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
19823 else if (lowpc
>= highpc
)
19825 struct objfile
*objfile
= per_objfile
->objfile
;
19826 struct gdbarch
*gdbarch
= objfile
->arch ();
19828 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
19829 "for DIE at %s [in module %s]"),
19830 paddress (gdbarch
, lowpc
),
19831 paddress (gdbarch
, highpc
),
19832 sect_offset_str (sect_off
),
19833 objfile_name (objfile
));
19842 /* Find a cached partial DIE at OFFSET in CU. */
19844 struct partial_die_info
*
19845 dwarf2_cu::find_partial_die (sect_offset sect_off
)
19847 struct partial_die_info
*lookup_die
= NULL
;
19848 struct partial_die_info
part_die (sect_off
);
19850 lookup_die
= ((struct partial_die_info
*)
19851 htab_find_with_hash (partial_dies
, &part_die
,
19852 to_underlying (sect_off
)));
19857 /* Find a partial DIE at OFFSET, which may or may not be in CU,
19858 except in the case of .debug_types DIEs which do not reference
19859 outside their CU (they do however referencing other types via
19860 DW_FORM_ref_sig8). */
19862 static const struct cu_partial_die_info
19863 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
19865 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19866 struct objfile
*objfile
= per_objfile
->objfile
;
19867 struct partial_die_info
*pd
= NULL
;
19869 if (offset_in_dwz
== cu
->per_cu
->is_dwz
19870 && cu
->header
.offset_in_cu_p (sect_off
))
19872 pd
= cu
->find_partial_die (sect_off
);
19875 /* We missed recording what we needed.
19876 Load all dies and try again. */
19880 /* TUs don't reference other CUs/TUs (except via type signatures). */
19881 if (cu
->per_cu
->is_debug_types
)
19883 error (_("Dwarf Error: Type Unit at offset %s contains"
19884 " external reference to offset %s [in module %s].\n"),
19885 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
19886 bfd_get_filename (objfile
->obfd
));
19888 dwarf2_per_cu_data
*per_cu
19889 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
19892 cu
= per_objfile
->get_cu (per_cu
);
19893 if (cu
== NULL
|| cu
->partial_dies
== NULL
)
19894 load_partial_comp_unit (per_cu
, per_objfile
, nullptr);
19896 cu
= per_objfile
->get_cu (per_cu
);
19899 pd
= cu
->find_partial_die (sect_off
);
19902 /* If we didn't find it, and not all dies have been loaded,
19903 load them all and try again. */
19905 if (pd
== NULL
&& cu
->per_cu
->load_all_dies
== 0)
19907 cu
->per_cu
->load_all_dies
= 1;
19909 /* This is nasty. When we reread the DIEs, somewhere up the call chain
19910 THIS_CU->cu may already be in use. So we can't just free it and
19911 replace its DIEs with the ones we read in. Instead, we leave those
19912 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
19913 and clobber THIS_CU->cu->partial_dies with the hash table for the new
19915 load_partial_comp_unit (cu
->per_cu
, per_objfile
, cu
);
19917 pd
= cu
->find_partial_die (sect_off
);
19921 error (_("Dwarf Error: Cannot not find DIE at %s [from module %s]\n"),
19922 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
19926 /* See if we can figure out if the class lives in a namespace. We do
19927 this by looking for a member function; its demangled name will
19928 contain namespace info, if there is any. */
19931 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
19932 struct dwarf2_cu
*cu
)
19934 /* NOTE: carlton/2003-10-07: Getting the info this way changes
19935 what template types look like, because the demangler
19936 frequently doesn't give the same name as the debug info. We
19937 could fix this by only using the demangled name to get the
19938 prefix (but see comment in read_structure_type). */
19940 struct partial_die_info
*real_pdi
;
19941 struct partial_die_info
*child_pdi
;
19943 /* If this DIE (this DIE's specification, if any) has a parent, then
19944 we should not do this. We'll prepend the parent's fully qualified
19945 name when we create the partial symbol. */
19947 real_pdi
= struct_pdi
;
19948 while (real_pdi
->has_specification
)
19950 auto res
= find_partial_die (real_pdi
->spec_offset
,
19951 real_pdi
->spec_is_dwz
, cu
);
19952 real_pdi
= res
.pdi
;
19956 if (real_pdi
->die_parent
!= NULL
)
19959 for (child_pdi
= struct_pdi
->die_child
;
19961 child_pdi
= child_pdi
->die_sibling
)
19963 if (child_pdi
->tag
== DW_TAG_subprogram
19964 && child_pdi
->linkage_name
!= NULL
)
19966 gdb::unique_xmalloc_ptr
<char> actual_class_name
19967 (cu
->language_defn
->class_name_from_physname
19968 (child_pdi
->linkage_name
));
19969 if (actual_class_name
!= NULL
)
19971 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19972 struct_pdi
->raw_name
= objfile
->intern (actual_class_name
.get ());
19973 struct_pdi
->canonical_name
= 1;
19980 /* Return true if a DIE with TAG may have the DW_AT_const_value
19984 can_have_DW_AT_const_value_p (enum dwarf_tag tag
)
19988 case DW_TAG_constant
:
19989 case DW_TAG_enumerator
:
19990 case DW_TAG_formal_parameter
:
19991 case DW_TAG_template_value_param
:
19992 case DW_TAG_variable
:
20000 partial_die_info::fixup (struct dwarf2_cu
*cu
)
20002 /* Once we've fixed up a die, there's no point in doing so again.
20003 This also avoids a memory leak if we were to call
20004 guess_partial_die_structure_name multiple times. */
20008 /* If we found a reference attribute and the DIE has no name, try
20009 to find a name in the referred to DIE. */
20011 if (raw_name
== NULL
&& has_specification
)
20013 struct partial_die_info
*spec_die
;
20015 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
20016 spec_die
= res
.pdi
;
20019 spec_die
->fixup (cu
);
20021 if (spec_die
->raw_name
)
20023 raw_name
= spec_die
->raw_name
;
20024 canonical_name
= spec_die
->canonical_name
;
20026 /* Copy DW_AT_external attribute if it is set. */
20027 if (spec_die
->is_external
)
20028 is_external
= spec_die
->is_external
;
20032 if (!has_const_value
&& has_specification
20033 && can_have_DW_AT_const_value_p (tag
))
20035 struct partial_die_info
*spec_die
;
20037 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
20038 spec_die
= res
.pdi
;
20041 spec_die
->fixup (cu
);
20043 if (spec_die
->has_const_value
)
20045 /* Copy DW_AT_const_value attribute if it is set. */
20046 has_const_value
= spec_die
->has_const_value
;
20050 /* Set default names for some unnamed DIEs. */
20052 if (raw_name
== NULL
&& tag
== DW_TAG_namespace
)
20054 raw_name
= CP_ANONYMOUS_NAMESPACE_STR
;
20055 canonical_name
= 1;
20058 /* If there is no parent die to provide a namespace, and there are
20059 children, see if we can determine the namespace from their linkage
20061 if (cu
->language
== language_cplus
20062 && !cu
->per_objfile
->per_bfd
->types
.empty ()
20063 && die_parent
== NULL
20065 && (tag
== DW_TAG_class_type
20066 || tag
== DW_TAG_structure_type
20067 || tag
== DW_TAG_union_type
))
20068 guess_partial_die_structure_name (this, cu
);
20070 /* GCC might emit a nameless struct or union that has a linkage
20071 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
20072 if (raw_name
== NULL
20073 && (tag
== DW_TAG_class_type
20074 || tag
== DW_TAG_interface_type
20075 || tag
== DW_TAG_structure_type
20076 || tag
== DW_TAG_union_type
)
20077 && linkage_name
!= NULL
)
20079 gdb::unique_xmalloc_ptr
<char> demangled
20080 (gdb_demangle (linkage_name
, DMGL_TYPES
));
20081 if (demangled
!= nullptr)
20085 /* Strip any leading namespaces/classes, keep only the base name.
20086 DW_AT_name for named DIEs does not contain the prefixes. */
20087 base
= strrchr (demangled
.get (), ':');
20088 if (base
&& base
> demangled
.get () && base
[-1] == ':')
20091 base
= demangled
.get ();
20093 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20094 raw_name
= objfile
->intern (base
);
20095 canonical_name
= 1;
20102 /* Read the .debug_loclists or .debug_rnglists header (they are the same format)
20103 contents from the given SECTION in the HEADER.
20105 HEADER_OFFSET is the offset of the header in the section. */
20107 read_loclists_rnglists_header (struct loclists_rnglists_header
*header
,
20108 struct dwarf2_section_info
*section
,
20109 sect_offset header_offset
)
20111 unsigned int bytes_read
;
20112 bfd
*abfd
= section
->get_bfd_owner ();
20113 const gdb_byte
*info_ptr
= section
->buffer
+ to_underlying (header_offset
);
20115 header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
20116 info_ptr
+= bytes_read
;
20118 header
->version
= read_2_bytes (abfd
, info_ptr
);
20121 header
->addr_size
= read_1_byte (abfd
, info_ptr
);
20124 header
->segment_collector_size
= read_1_byte (abfd
, info_ptr
);
20127 header
->offset_entry_count
= read_4_bytes (abfd
, info_ptr
);
20130 /* Return the DW_AT_loclists_base value for the CU. */
20132 lookup_loclist_base (struct dwarf2_cu
*cu
)
20134 /* For the .dwo unit, the loclist_base points to the first offset following
20135 the header. The header consists of the following entities-
20136 1. Unit Length (4 bytes for 32 bit DWARF format, and 12 bytes for the 64
20138 2. version (2 bytes)
20139 3. address size (1 byte)
20140 4. segment selector size (1 byte)
20141 5. offset entry count (4 bytes)
20142 These sizes are derived as per the DWARFv5 standard. */
20143 if (cu
->dwo_unit
!= nullptr)
20145 if (cu
->header
.initial_length_size
== 4)
20146 return LOCLIST_HEADER_SIZE32
;
20147 return LOCLIST_HEADER_SIZE64
;
20149 return cu
->loclist_base
;
20152 /* Given a DW_FORM_loclistx value LOCLIST_INDEX, fetch the offset from the
20153 array of offsets in the .debug_loclists section. */
20156 read_loclist_index (struct dwarf2_cu
*cu
, ULONGEST loclist_index
)
20158 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20159 struct objfile
*objfile
= per_objfile
->objfile
;
20160 bfd
*abfd
= objfile
->obfd
;
20161 ULONGEST loclist_header_size
=
20162 (cu
->header
.initial_length_size
== 4 ? LOCLIST_HEADER_SIZE32
20163 : LOCLIST_HEADER_SIZE64
);
20164 ULONGEST loclist_base
= lookup_loclist_base (cu
);
20166 /* Offset in .debug_loclists of the offset for LOCLIST_INDEX. */
20167 ULONGEST start_offset
=
20168 loclist_base
+ loclist_index
* cu
->header
.offset_size
;
20170 /* Get loclists section. */
20171 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
20173 /* Read the loclists section content. */
20174 section
->read (objfile
);
20175 if (section
->buffer
== NULL
)
20176 error (_("DW_FORM_loclistx used without .debug_loclists "
20177 "section [in module %s]"), objfile_name (objfile
));
20179 /* DW_AT_loclists_base points after the .debug_loclists contribution header,
20180 so if loclist_base is smaller than the header size, we have a problem. */
20181 if (loclist_base
< loclist_header_size
)
20182 error (_("DW_AT_loclists_base is smaller than header size [in module %s]"),
20183 objfile_name (objfile
));
20185 /* Read the header of the loclists contribution. */
20186 struct loclists_rnglists_header header
;
20187 read_loclists_rnglists_header (&header
, section
,
20188 (sect_offset
) (loclist_base
- loclist_header_size
));
20190 /* Verify the loclist index is valid. */
20191 if (loclist_index
>= header
.offset_entry_count
)
20192 error (_("DW_FORM_loclistx pointing outside of "
20193 ".debug_loclists offset array [in module %s]"),
20194 objfile_name (objfile
));
20196 /* Validate that reading won't go beyond the end of the section. */
20197 if (start_offset
+ cu
->header
.offset_size
> section
->size
)
20198 error (_("Reading DW_FORM_loclistx index beyond end of"
20199 ".debug_loclists section [in module %s]"),
20200 objfile_name (objfile
));
20202 const gdb_byte
*info_ptr
= section
->buffer
+ start_offset
;
20204 if (cu
->header
.offset_size
== 4)
20205 return (sect_offset
) (bfd_get_32 (abfd
, info_ptr
) + loclist_base
);
20207 return (sect_offset
) (bfd_get_64 (abfd
, info_ptr
) + loclist_base
);
20210 /* Given a DW_FORM_rnglistx value RNGLIST_INDEX, fetch the offset from the
20211 array of offsets in the .debug_rnglists section. */
20214 read_rnglist_index (struct dwarf2_cu
*cu
, ULONGEST rnglist_index
,
20217 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
20218 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20219 bfd
*abfd
= objfile
->obfd
;
20220 ULONGEST rnglist_header_size
=
20221 (cu
->header
.initial_length_size
== 4 ? RNGLIST_HEADER_SIZE32
20222 : RNGLIST_HEADER_SIZE64
);
20224 /* When reading a DW_FORM_rnglistx from a DWO, we read from the DWO's
20225 .debug_rnglists.dwo section. The rnglists base given in the skeleton
20227 ULONGEST rnglist_base
=
20228 (cu
->dwo_unit
!= nullptr) ? rnglist_header_size
: cu
->rnglists_base
;
20230 /* Offset in .debug_rnglists of the offset for RNGLIST_INDEX. */
20231 ULONGEST start_offset
=
20232 rnglist_base
+ rnglist_index
* cu
->header
.offset_size
;
20234 /* Get rnglists section. */
20235 struct dwarf2_section_info
*section
= cu_debug_rnglists_section (cu
, tag
);
20237 /* Read the rnglists section content. */
20238 section
->read (objfile
);
20239 if (section
->buffer
== nullptr)
20240 error (_("DW_FORM_rnglistx used without .debug_rnglists section "
20242 objfile_name (objfile
));
20244 /* DW_AT_rnglists_base points after the .debug_rnglists contribution header,
20245 so if rnglist_base is smaller than the header size, we have a problem. */
20246 if (rnglist_base
< rnglist_header_size
)
20247 error (_("DW_AT_rnglists_base is smaller than header size [in module %s]"),
20248 objfile_name (objfile
));
20250 /* Read the header of the rnglists contribution. */
20251 struct loclists_rnglists_header header
;
20252 read_loclists_rnglists_header (&header
, section
,
20253 (sect_offset
) (rnglist_base
- rnglist_header_size
));
20255 /* Verify the rnglist index is valid. */
20256 if (rnglist_index
>= header
.offset_entry_count
)
20257 error (_("DW_FORM_rnglistx index pointing outside of "
20258 ".debug_rnglists offset array [in module %s]"),
20259 objfile_name (objfile
));
20261 /* Validate that reading won't go beyond the end of the section. */
20262 if (start_offset
+ cu
->header
.offset_size
> section
->size
)
20263 error (_("Reading DW_FORM_rnglistx index beyond end of"
20264 ".debug_rnglists section [in module %s]"),
20265 objfile_name (objfile
));
20267 const gdb_byte
*info_ptr
= section
->buffer
+ start_offset
;
20269 if (cu
->header
.offset_size
== 4)
20270 return (sect_offset
) (read_4_bytes (abfd
, info_ptr
) + rnglist_base
);
20272 return (sect_offset
) (read_8_bytes (abfd
, info_ptr
) + rnglist_base
);
20275 /* Process the attributes that had to be skipped in the first round. These
20276 attributes are the ones that need str_offsets_base or addr_base attributes.
20277 They could not have been processed in the first round, because at the time
20278 the values of str_offsets_base or addr_base may not have been known. */
20280 read_attribute_reprocess (const struct die_reader_specs
*reader
,
20281 struct attribute
*attr
, dwarf_tag tag
)
20283 struct dwarf2_cu
*cu
= reader
->cu
;
20284 switch (attr
->form
)
20286 case DW_FORM_addrx
:
20287 case DW_FORM_GNU_addr_index
:
20288 attr
->set_address (read_addr_index (cu
,
20289 attr
->as_unsigned_reprocess ()));
20291 case DW_FORM_loclistx
:
20293 sect_offset loclists_sect_off
20294 = read_loclist_index (cu
, attr
->as_unsigned_reprocess ());
20296 attr
->set_unsigned (to_underlying (loclists_sect_off
));
20299 case DW_FORM_rnglistx
:
20301 sect_offset rnglists_sect_off
20302 = read_rnglist_index (cu
, attr
->as_unsigned_reprocess (), tag
);
20304 attr
->set_unsigned (to_underlying (rnglists_sect_off
));
20308 case DW_FORM_strx1
:
20309 case DW_FORM_strx2
:
20310 case DW_FORM_strx3
:
20311 case DW_FORM_strx4
:
20312 case DW_FORM_GNU_str_index
:
20314 unsigned int str_index
= attr
->as_unsigned_reprocess ();
20315 gdb_assert (!attr
->canonical_string_p ());
20316 if (reader
->dwo_file
!= NULL
)
20317 attr
->set_string_noncanonical (read_dwo_str_index (reader
,
20320 attr
->set_string_noncanonical (read_stub_str_index (cu
,
20325 gdb_assert_not_reached (_("Unexpected DWARF form."));
20329 /* Read an attribute value described by an attribute form. */
20331 static const gdb_byte
*
20332 read_attribute_value (const struct die_reader_specs
*reader
,
20333 struct attribute
*attr
, unsigned form
,
20334 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
20336 struct dwarf2_cu
*cu
= reader
->cu
;
20337 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20338 struct objfile
*objfile
= per_objfile
->objfile
;
20339 bfd
*abfd
= reader
->abfd
;
20340 struct comp_unit_head
*cu_header
= &cu
->header
;
20341 unsigned int bytes_read
;
20342 struct dwarf_block
*blk
;
20344 attr
->form
= (enum dwarf_form
) form
;
20347 case DW_FORM_ref_addr
:
20348 if (cu_header
->version
== 2)
20349 attr
->set_unsigned (cu_header
->read_address (abfd
, info_ptr
,
20352 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
20354 info_ptr
+= bytes_read
;
20356 case DW_FORM_GNU_ref_alt
:
20357 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
20359 info_ptr
+= bytes_read
;
20363 struct gdbarch
*gdbarch
= objfile
->arch ();
20364 CORE_ADDR addr
= cu_header
->read_address (abfd
, info_ptr
, &bytes_read
);
20365 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
);
20366 attr
->set_address (addr
);
20367 info_ptr
+= bytes_read
;
20370 case DW_FORM_block2
:
20371 blk
= dwarf_alloc_block (cu
);
20372 blk
->size
= read_2_bytes (abfd
, info_ptr
);
20374 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20375 info_ptr
+= blk
->size
;
20376 attr
->set_block (blk
);
20378 case DW_FORM_block4
:
20379 blk
= dwarf_alloc_block (cu
);
20380 blk
->size
= read_4_bytes (abfd
, info_ptr
);
20382 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20383 info_ptr
+= blk
->size
;
20384 attr
->set_block (blk
);
20386 case DW_FORM_data2
:
20387 attr
->set_unsigned (read_2_bytes (abfd
, info_ptr
));
20390 case DW_FORM_data4
:
20391 attr
->set_unsigned (read_4_bytes (abfd
, info_ptr
));
20394 case DW_FORM_data8
:
20395 attr
->set_unsigned (read_8_bytes (abfd
, info_ptr
));
20398 case DW_FORM_data16
:
20399 blk
= dwarf_alloc_block (cu
);
20401 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
20403 attr
->set_block (blk
);
20405 case DW_FORM_sec_offset
:
20406 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
20408 info_ptr
+= bytes_read
;
20410 case DW_FORM_loclistx
:
20412 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20414 info_ptr
+= bytes_read
;
20417 case DW_FORM_string
:
20418 attr
->set_string_noncanonical (read_direct_string (abfd
, info_ptr
,
20420 info_ptr
+= bytes_read
;
20423 if (!cu
->per_cu
->is_dwz
)
20425 attr
->set_string_noncanonical
20426 (read_indirect_string (per_objfile
,
20427 abfd
, info_ptr
, cu_header
,
20429 info_ptr
+= bytes_read
;
20433 case DW_FORM_line_strp
:
20434 if (!cu
->per_cu
->is_dwz
)
20436 attr
->set_string_noncanonical
20437 (per_objfile
->read_line_string (info_ptr
, cu_header
,
20439 info_ptr
+= bytes_read
;
20443 case DW_FORM_GNU_strp_alt
:
20445 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
, true);
20446 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
20449 attr
->set_string_noncanonical
20450 (dwz
->read_string (objfile
, str_offset
));
20451 info_ptr
+= bytes_read
;
20454 case DW_FORM_exprloc
:
20455 case DW_FORM_block
:
20456 blk
= dwarf_alloc_block (cu
);
20457 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20458 info_ptr
+= bytes_read
;
20459 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20460 info_ptr
+= blk
->size
;
20461 attr
->set_block (blk
);
20463 case DW_FORM_block1
:
20464 blk
= dwarf_alloc_block (cu
);
20465 blk
->size
= read_1_byte (abfd
, info_ptr
);
20467 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20468 info_ptr
+= blk
->size
;
20469 attr
->set_block (blk
);
20471 case DW_FORM_data1
:
20473 attr
->set_unsigned (read_1_byte (abfd
, info_ptr
));
20476 case DW_FORM_flag_present
:
20477 attr
->set_unsigned (1);
20479 case DW_FORM_sdata
:
20480 attr
->set_signed (read_signed_leb128 (abfd
, info_ptr
, &bytes_read
));
20481 info_ptr
+= bytes_read
;
20483 case DW_FORM_rnglistx
:
20485 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20487 info_ptr
+= bytes_read
;
20490 case DW_FORM_udata
:
20491 attr
->set_unsigned (read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
20492 info_ptr
+= bytes_read
;
20495 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20496 + read_1_byte (abfd
, info_ptr
)));
20500 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20501 + read_2_bytes (abfd
, info_ptr
)));
20505 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20506 + read_4_bytes (abfd
, info_ptr
)));
20510 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20511 + read_8_bytes (abfd
, info_ptr
)));
20514 case DW_FORM_ref_sig8
:
20515 attr
->set_signature (read_8_bytes (abfd
, info_ptr
));
20518 case DW_FORM_ref_udata
:
20519 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20520 + read_unsigned_leb128 (abfd
, info_ptr
,
20522 info_ptr
+= bytes_read
;
20524 case DW_FORM_indirect
:
20525 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20526 info_ptr
+= bytes_read
;
20527 if (form
== DW_FORM_implicit_const
)
20529 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
20530 info_ptr
+= bytes_read
;
20532 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
20535 case DW_FORM_implicit_const
:
20536 attr
->set_signed (implicit_const
);
20538 case DW_FORM_addrx
:
20539 case DW_FORM_GNU_addr_index
:
20540 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20542 info_ptr
+= bytes_read
;
20545 case DW_FORM_strx1
:
20546 case DW_FORM_strx2
:
20547 case DW_FORM_strx3
:
20548 case DW_FORM_strx4
:
20549 case DW_FORM_GNU_str_index
:
20551 ULONGEST str_index
;
20552 if (form
== DW_FORM_strx1
)
20554 str_index
= read_1_byte (abfd
, info_ptr
);
20557 else if (form
== DW_FORM_strx2
)
20559 str_index
= read_2_bytes (abfd
, info_ptr
);
20562 else if (form
== DW_FORM_strx3
)
20564 str_index
= read_3_bytes (abfd
, info_ptr
);
20567 else if (form
== DW_FORM_strx4
)
20569 str_index
= read_4_bytes (abfd
, info_ptr
);
20574 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20575 info_ptr
+= bytes_read
;
20577 attr
->set_unsigned_reprocess (str_index
);
20581 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
20582 dwarf_form_name (form
),
20583 bfd_get_filename (abfd
));
20587 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
20588 attr
->form
= DW_FORM_GNU_ref_alt
;
20590 /* We have seen instances where the compiler tried to emit a byte
20591 size attribute of -1 which ended up being encoded as an unsigned
20592 0xffffffff. Although 0xffffffff is technically a valid size value,
20593 an object of this size seems pretty unlikely so we can relatively
20594 safely treat these cases as if the size attribute was invalid and
20595 treat them as zero by default. */
20596 if (attr
->name
== DW_AT_byte_size
20597 && form
== DW_FORM_data4
20598 && attr
->as_unsigned () >= 0xffffffff)
20601 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
20602 hex_string (attr
->as_unsigned ()));
20603 attr
->set_unsigned (0);
20609 /* Read an attribute described by an abbreviated attribute. */
20611 static const gdb_byte
*
20612 read_attribute (const struct die_reader_specs
*reader
,
20613 struct attribute
*attr
, const struct attr_abbrev
*abbrev
,
20614 const gdb_byte
*info_ptr
)
20616 attr
->name
= abbrev
->name
;
20617 attr
->string_is_canonical
= 0;
20618 attr
->requires_reprocessing
= 0;
20619 return read_attribute_value (reader
, attr
, abbrev
->form
,
20620 abbrev
->implicit_const
, info_ptr
);
20623 /* Return pointer to string at .debug_str offset STR_OFFSET. */
20625 static const char *
20626 read_indirect_string_at_offset (dwarf2_per_objfile
*per_objfile
,
20627 LONGEST str_offset
)
20629 return per_objfile
->per_bfd
->str
.read_string (per_objfile
->objfile
,
20630 str_offset
, "DW_FORM_strp");
20633 /* Return pointer to string at .debug_str offset as read from BUF.
20634 BUF is assumed to be in a compilation unit described by CU_HEADER.
20635 Return *BYTES_READ_PTR count of bytes read from BUF. */
20637 static const char *
20638 read_indirect_string (dwarf2_per_objfile
*per_objfile
, bfd
*abfd
,
20639 const gdb_byte
*buf
,
20640 const struct comp_unit_head
*cu_header
,
20641 unsigned int *bytes_read_ptr
)
20643 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
20645 return read_indirect_string_at_offset (per_objfile
, str_offset
);
20651 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
20652 const struct comp_unit_head
*cu_header
,
20653 unsigned int *bytes_read_ptr
)
20655 bfd
*abfd
= objfile
->obfd
;
20656 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
20658 return per_bfd
->line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
20661 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
20662 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
20663 ADDR_SIZE is the size of addresses from the CU header. */
20666 read_addr_index_1 (dwarf2_per_objfile
*per_objfile
, unsigned int addr_index
,
20667 gdb::optional
<ULONGEST
> addr_base
, int addr_size
)
20669 struct objfile
*objfile
= per_objfile
->objfile
;
20670 bfd
*abfd
= objfile
->obfd
;
20671 const gdb_byte
*info_ptr
;
20672 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
20674 per_objfile
->per_bfd
->addr
.read (objfile
);
20675 if (per_objfile
->per_bfd
->addr
.buffer
== NULL
)
20676 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
20677 objfile_name (objfile
));
20678 if (addr_base_or_zero
+ addr_index
* addr_size
20679 >= per_objfile
->per_bfd
->addr
.size
)
20680 error (_("DW_FORM_addr_index pointing outside of "
20681 ".debug_addr section [in module %s]"),
20682 objfile_name (objfile
));
20683 info_ptr
= (per_objfile
->per_bfd
->addr
.buffer
+ addr_base_or_zero
20684 + addr_index
* addr_size
);
20685 if (addr_size
== 4)
20686 return bfd_get_32 (abfd
, info_ptr
);
20688 return bfd_get_64 (abfd
, info_ptr
);
20691 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
20694 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
20696 return read_addr_index_1 (cu
->per_objfile
, addr_index
,
20697 cu
->addr_base
, cu
->header
.addr_size
);
20700 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
20703 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
20704 unsigned int *bytes_read
)
20706 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
20707 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
20709 return read_addr_index (cu
, addr_index
);
20715 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
,
20716 dwarf2_per_objfile
*per_objfile
,
20717 unsigned int addr_index
)
20719 struct dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
20720 gdb::optional
<ULONGEST
> addr_base
;
20723 /* We need addr_base and addr_size.
20724 If we don't have PER_CU->cu, we have to get it.
20725 Nasty, but the alternative is storing the needed info in PER_CU,
20726 which at this point doesn't seem justified: it's not clear how frequently
20727 it would get used and it would increase the size of every PER_CU.
20728 Entry points like dwarf2_per_cu_addr_size do a similar thing
20729 so we're not in uncharted territory here.
20730 Alas we need to be a bit more complicated as addr_base is contained
20733 We don't need to read the entire CU(/TU).
20734 We just need the header and top level die.
20736 IWBN to use the aging mechanism to let us lazily later discard the CU.
20737 For now we skip this optimization. */
20741 addr_base
= cu
->addr_base
;
20742 addr_size
= cu
->header
.addr_size
;
20746 cutu_reader
reader (per_cu
, per_objfile
, nullptr, nullptr, false);
20747 addr_base
= reader
.cu
->addr_base
;
20748 addr_size
= reader
.cu
->header
.addr_size
;
20751 return read_addr_index_1 (per_objfile
, addr_index
, addr_base
, addr_size
);
20754 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
20755 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
20758 static const char *
20759 read_str_index (struct dwarf2_cu
*cu
,
20760 struct dwarf2_section_info
*str_section
,
20761 struct dwarf2_section_info
*str_offsets_section
,
20762 ULONGEST str_offsets_base
, ULONGEST str_index
)
20764 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20765 struct objfile
*objfile
= per_objfile
->objfile
;
20766 const char *objf_name
= objfile_name (objfile
);
20767 bfd
*abfd
= objfile
->obfd
;
20768 const gdb_byte
*info_ptr
;
20769 ULONGEST str_offset
;
20770 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
20772 str_section
->read (objfile
);
20773 str_offsets_section
->read (objfile
);
20774 if (str_section
->buffer
== NULL
)
20775 error (_("%s used without %s section"
20776 " in CU at offset %s [in module %s]"),
20777 form_name
, str_section
->get_name (),
20778 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20779 if (str_offsets_section
->buffer
== NULL
)
20780 error (_("%s used without %s section"
20781 " in CU at offset %s [in module %s]"),
20782 form_name
, str_section
->get_name (),
20783 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20784 info_ptr
= (str_offsets_section
->buffer
20786 + str_index
* cu
->header
.offset_size
);
20787 if (cu
->header
.offset_size
== 4)
20788 str_offset
= bfd_get_32 (abfd
, info_ptr
);
20790 str_offset
= bfd_get_64 (abfd
, info_ptr
);
20791 if (str_offset
>= str_section
->size
)
20792 error (_("Offset from %s pointing outside of"
20793 " .debug_str.dwo section in CU at offset %s [in module %s]"),
20794 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20795 return (const char *) (str_section
->buffer
+ str_offset
);
20798 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
20800 static const char *
20801 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
20803 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
20804 ? reader
->cu
->header
.addr_size
: 0;
20805 return read_str_index (reader
->cu
,
20806 &reader
->dwo_file
->sections
.str
,
20807 &reader
->dwo_file
->sections
.str_offsets
,
20808 str_offsets_base
, str_index
);
20811 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
20813 static const char *
20814 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
20816 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20817 const char *objf_name
= objfile_name (objfile
);
20818 static const char form_name
[] = "DW_FORM_GNU_str_index";
20819 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
20821 if (!cu
->str_offsets_base
.has_value ())
20822 error (_("%s used in Fission stub without %s"
20823 " in CU at offset 0x%lx [in module %s]"),
20824 form_name
, str_offsets_attr_name
,
20825 (long) cu
->header
.offset_size
, objf_name
);
20827 return read_str_index (cu
,
20828 &cu
->per_objfile
->per_bfd
->str
,
20829 &cu
->per_objfile
->per_bfd
->str_offsets
,
20830 *cu
->str_offsets_base
, str_index
);
20833 /* Return the length of an LEB128 number in BUF. */
20836 leb128_size (const gdb_byte
*buf
)
20838 const gdb_byte
*begin
= buf
;
20844 if ((byte
& 128) == 0)
20845 return buf
- begin
;
20850 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
20859 cu
->language
= language_c
;
20862 case DW_LANG_C_plus_plus
:
20863 case DW_LANG_C_plus_plus_11
:
20864 case DW_LANG_C_plus_plus_14
:
20865 cu
->language
= language_cplus
;
20868 cu
->language
= language_d
;
20870 case DW_LANG_Fortran77
:
20871 case DW_LANG_Fortran90
:
20872 case DW_LANG_Fortran95
:
20873 case DW_LANG_Fortran03
:
20874 case DW_LANG_Fortran08
:
20875 cu
->language
= language_fortran
;
20878 cu
->language
= language_go
;
20880 case DW_LANG_Mips_Assembler
:
20881 cu
->language
= language_asm
;
20883 case DW_LANG_Ada83
:
20884 case DW_LANG_Ada95
:
20885 cu
->language
= language_ada
;
20887 case DW_LANG_Modula2
:
20888 cu
->language
= language_m2
;
20890 case DW_LANG_Pascal83
:
20891 cu
->language
= language_pascal
;
20894 cu
->language
= language_objc
;
20897 case DW_LANG_Rust_old
:
20898 cu
->language
= language_rust
;
20900 case DW_LANG_Cobol74
:
20901 case DW_LANG_Cobol85
:
20903 cu
->language
= language_minimal
;
20906 cu
->language_defn
= language_def (cu
->language
);
20909 /* Return the named attribute or NULL if not there. */
20911 static struct attribute
*
20912 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20917 struct attribute
*spec
= NULL
;
20919 for (i
= 0; i
< die
->num_attrs
; ++i
)
20921 if (die
->attrs
[i
].name
== name
)
20922 return &die
->attrs
[i
];
20923 if (die
->attrs
[i
].name
== DW_AT_specification
20924 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
20925 spec
= &die
->attrs
[i
];
20931 die
= follow_die_ref (die
, spec
, &cu
);
20937 /* Return the string associated with a string-typed attribute, or NULL if it
20938 is either not found or is of an incorrect type. */
20940 static const char *
20941 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20943 struct attribute
*attr
;
20944 const char *str
= NULL
;
20946 attr
= dwarf2_attr (die
, name
, cu
);
20950 str
= attr
->as_string ();
20951 if (str
== nullptr)
20952 complaint (_("string type expected for attribute %s for "
20953 "DIE at %s in module %s"),
20954 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
20955 objfile_name (cu
->per_objfile
->objfile
));
20961 /* Return the dwo name or NULL if not present. If present, it is in either
20962 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
20963 static const char *
20964 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
20966 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
20967 if (dwo_name
== nullptr)
20968 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
20972 /* Return non-zero iff the attribute NAME is defined for the given DIE,
20973 and holds a non-zero value. This function should only be used for
20974 DW_FORM_flag or DW_FORM_flag_present attributes. */
20977 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
20979 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
20981 return attr
!= nullptr && attr
->as_boolean ();
20985 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
20987 /* A DIE is a declaration if it has a DW_AT_declaration attribute
20988 which value is non-zero. However, we have to be careful with
20989 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
20990 (via dwarf2_flag_true_p) follows this attribute. So we may
20991 end up accidently finding a declaration attribute that belongs
20992 to a different DIE referenced by the specification attribute,
20993 even though the given DIE does not have a declaration attribute. */
20994 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
20995 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
20998 /* Return the die giving the specification for DIE, if there is
20999 one. *SPEC_CU is the CU containing DIE on input, and the CU
21000 containing the return value on output. If there is no
21001 specification, but there is an abstract origin, that is
21004 static struct die_info
*
21005 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
21007 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
21010 if (spec_attr
== NULL
)
21011 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
21013 if (spec_attr
== NULL
)
21016 return follow_die_ref (die
, spec_attr
, spec_cu
);
21019 /* Stub for free_line_header to match void * callback types. */
21022 free_line_header_voidp (void *arg
)
21024 struct line_header
*lh
= (struct line_header
*) arg
;
21029 /* A convenience function to find the proper .debug_line section for a CU. */
21031 static struct dwarf2_section_info
*
21032 get_debug_line_section (struct dwarf2_cu
*cu
)
21034 struct dwarf2_section_info
*section
;
21035 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21037 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
21039 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
21040 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
21041 else if (cu
->per_cu
->is_dwz
)
21043 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
, true);
21045 section
= &dwz
->line
;
21048 section
= &per_objfile
->per_bfd
->line
;
21053 /* Read the statement program header starting at OFFSET in
21054 .debug_line, or .debug_line.dwo. Return a pointer
21055 to a struct line_header, allocated using xmalloc.
21056 Returns NULL if there is a problem reading the header, e.g., if it
21057 has a version we don't understand.
21059 NOTE: the strings in the include directory and file name tables of
21060 the returned object point into the dwarf line section buffer,
21061 and must not be freed. */
21063 static line_header_up
21064 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
21066 struct dwarf2_section_info
*section
;
21067 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21069 section
= get_debug_line_section (cu
);
21070 section
->read (per_objfile
->objfile
);
21071 if (section
->buffer
== NULL
)
21073 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
21074 complaint (_("missing .debug_line.dwo section"));
21076 complaint (_("missing .debug_line section"));
21080 return dwarf_decode_line_header (sect_off
, cu
->per_cu
->is_dwz
,
21081 per_objfile
, section
, &cu
->header
);
21084 /* Subroutine of dwarf_decode_lines to simplify it.
21085 Return the file name of the psymtab for the given file_entry.
21086 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
21087 If space for the result is malloc'd, *NAME_HOLDER will be set.
21088 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
21090 static const char *
21091 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
21092 const dwarf2_psymtab
*pst
,
21093 const char *comp_dir
,
21094 gdb::unique_xmalloc_ptr
<char> *name_holder
)
21096 const char *include_name
= fe
.name
;
21097 const char *include_name_to_compare
= include_name
;
21098 const char *pst_filename
;
21101 const char *dir_name
= fe
.include_dir (lh
);
21103 gdb::unique_xmalloc_ptr
<char> hold_compare
;
21104 if (!IS_ABSOLUTE_PATH (include_name
)
21105 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
21107 /* Avoid creating a duplicate psymtab for PST.
21108 We do this by comparing INCLUDE_NAME and PST_FILENAME.
21109 Before we do the comparison, however, we need to account
21110 for DIR_NAME and COMP_DIR.
21111 First prepend dir_name (if non-NULL). If we still don't
21112 have an absolute path prepend comp_dir (if non-NULL).
21113 However, the directory we record in the include-file's
21114 psymtab does not contain COMP_DIR (to match the
21115 corresponding symtab(s)).
21120 bash$ gcc -g ./hello.c
21121 include_name = "hello.c"
21123 DW_AT_comp_dir = comp_dir = "/tmp"
21124 DW_AT_name = "./hello.c"
21128 if (dir_name
!= NULL
)
21130 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
21131 include_name
, (char *) NULL
));
21132 include_name
= name_holder
->get ();
21133 include_name_to_compare
= include_name
;
21135 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
21137 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
21138 include_name
, (char *) NULL
));
21139 include_name_to_compare
= hold_compare
.get ();
21143 pst_filename
= pst
->filename
;
21144 gdb::unique_xmalloc_ptr
<char> copied_name
;
21145 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
21147 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
21148 pst_filename
, (char *) NULL
));
21149 pst_filename
= copied_name
.get ();
21152 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
21156 return include_name
;
21159 /* State machine to track the state of the line number program. */
21161 class lnp_state_machine
21164 /* Initialize a machine state for the start of a line number
21166 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
21167 bool record_lines_p
);
21169 file_entry
*current_file ()
21171 /* lh->file_names is 0-based, but the file name numbers in the
21172 statement program are 1-based. */
21173 return m_line_header
->file_name_at (m_file
);
21176 /* Record the line in the state machine. END_SEQUENCE is true if
21177 we're processing the end of a sequence. */
21178 void record_line (bool end_sequence
);
21180 /* Check ADDRESS is -1, or zero and less than UNRELOCATED_LOWPC, and if true
21181 nop-out rest of the lines in this sequence. */
21182 void check_line_address (struct dwarf2_cu
*cu
,
21183 const gdb_byte
*line_ptr
,
21184 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
21186 void handle_set_discriminator (unsigned int discriminator
)
21188 m_discriminator
= discriminator
;
21189 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
21192 /* Handle DW_LNE_set_address. */
21193 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
21196 address
+= baseaddr
;
21197 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
21200 /* Handle DW_LNS_advance_pc. */
21201 void handle_advance_pc (CORE_ADDR adjust
);
21203 /* Handle a special opcode. */
21204 void handle_special_opcode (unsigned char op_code
);
21206 /* Handle DW_LNS_advance_line. */
21207 void handle_advance_line (int line_delta
)
21209 advance_line (line_delta
);
21212 /* Handle DW_LNS_set_file. */
21213 void handle_set_file (file_name_index file
);
21215 /* Handle DW_LNS_negate_stmt. */
21216 void handle_negate_stmt ()
21218 m_is_stmt
= !m_is_stmt
;
21221 /* Handle DW_LNS_const_add_pc. */
21222 void handle_const_add_pc ();
21224 /* Handle DW_LNS_fixed_advance_pc. */
21225 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
21227 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21231 /* Handle DW_LNS_copy. */
21232 void handle_copy ()
21234 record_line (false);
21235 m_discriminator
= 0;
21238 /* Handle DW_LNE_end_sequence. */
21239 void handle_end_sequence ()
21241 m_currently_recording_lines
= true;
21245 /* Advance the line by LINE_DELTA. */
21246 void advance_line (int line_delta
)
21248 m_line
+= line_delta
;
21250 if (line_delta
!= 0)
21251 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
21254 struct dwarf2_cu
*m_cu
;
21256 gdbarch
*m_gdbarch
;
21258 /* True if we're recording lines.
21259 Otherwise we're building partial symtabs and are just interested in
21260 finding include files mentioned by the line number program. */
21261 bool m_record_lines_p
;
21263 /* The line number header. */
21264 line_header
*m_line_header
;
21266 /* These are part of the standard DWARF line number state machine,
21267 and initialized according to the DWARF spec. */
21269 unsigned char m_op_index
= 0;
21270 /* The line table index of the current file. */
21271 file_name_index m_file
= 1;
21272 unsigned int m_line
= 1;
21274 /* These are initialized in the constructor. */
21276 CORE_ADDR m_address
;
21278 unsigned int m_discriminator
;
21280 /* Additional bits of state we need to track. */
21282 /* The last file that we called dwarf2_start_subfile for.
21283 This is only used for TLLs. */
21284 unsigned int m_last_file
= 0;
21285 /* The last file a line number was recorded for. */
21286 struct subfile
*m_last_subfile
= NULL
;
21288 /* The address of the last line entry. */
21289 CORE_ADDR m_last_address
;
21291 /* Set to true when a previous line at the same address (using
21292 m_last_address) had m_is_stmt true. This is reset to false when a
21293 line entry at a new address (m_address different to m_last_address) is
21295 bool m_stmt_at_address
= false;
21297 /* When true, record the lines we decode. */
21298 bool m_currently_recording_lines
= false;
21300 /* The last line number that was recorded, used to coalesce
21301 consecutive entries for the same line. This can happen, for
21302 example, when discriminators are present. PR 17276. */
21303 unsigned int m_last_line
= 0;
21304 bool m_line_has_non_zero_discriminator
= false;
21308 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
21310 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
21311 / m_line_header
->maximum_ops_per_instruction
)
21312 * m_line_header
->minimum_instruction_length
);
21313 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21314 m_op_index
= ((m_op_index
+ adjust
)
21315 % m_line_header
->maximum_ops_per_instruction
);
21319 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
21321 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
21322 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
21323 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
21324 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
21325 / m_line_header
->maximum_ops_per_instruction
)
21326 * m_line_header
->minimum_instruction_length
);
21327 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21328 m_op_index
= ((m_op_index
+ adj_opcode_d
)
21329 % m_line_header
->maximum_ops_per_instruction
);
21331 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
21332 advance_line (line_delta
);
21333 record_line (false);
21334 m_discriminator
= 0;
21338 lnp_state_machine::handle_set_file (file_name_index file
)
21342 const file_entry
*fe
= current_file ();
21344 dwarf2_debug_line_missing_file_complaint ();
21345 else if (m_record_lines_p
)
21347 const char *dir
= fe
->include_dir (m_line_header
);
21349 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21350 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
21351 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
21356 lnp_state_machine::handle_const_add_pc ()
21359 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
21362 = (((m_op_index
+ adjust
)
21363 / m_line_header
->maximum_ops_per_instruction
)
21364 * m_line_header
->minimum_instruction_length
);
21366 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21367 m_op_index
= ((m_op_index
+ adjust
)
21368 % m_line_header
->maximum_ops_per_instruction
);
21371 /* Return non-zero if we should add LINE to the line number table.
21372 LINE is the line to add, LAST_LINE is the last line that was added,
21373 LAST_SUBFILE is the subfile for LAST_LINE.
21374 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
21375 had a non-zero discriminator.
21377 We have to be careful in the presence of discriminators.
21378 E.g., for this line:
21380 for (i = 0; i < 100000; i++);
21382 clang can emit four line number entries for that one line,
21383 each with a different discriminator.
21384 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
21386 However, we want gdb to coalesce all four entries into one.
21387 Otherwise the user could stepi into the middle of the line and
21388 gdb would get confused about whether the pc really was in the
21389 middle of the line.
21391 Things are further complicated by the fact that two consecutive
21392 line number entries for the same line is a heuristic used by gcc
21393 to denote the end of the prologue. So we can't just discard duplicate
21394 entries, we have to be selective about it. The heuristic we use is
21395 that we only collapse consecutive entries for the same line if at least
21396 one of those entries has a non-zero discriminator. PR 17276.
21398 Note: Addresses in the line number state machine can never go backwards
21399 within one sequence, thus this coalescing is ok. */
21402 dwarf_record_line_p (struct dwarf2_cu
*cu
,
21403 unsigned int line
, unsigned int last_line
,
21404 int line_has_non_zero_discriminator
,
21405 struct subfile
*last_subfile
)
21407 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
21409 if (line
!= last_line
)
21411 /* Same line for the same file that we've seen already.
21412 As a last check, for pr 17276, only record the line if the line
21413 has never had a non-zero discriminator. */
21414 if (!line_has_non_zero_discriminator
)
21419 /* Use the CU's builder to record line number LINE beginning at
21420 address ADDRESS in the line table of subfile SUBFILE. */
21423 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21424 unsigned int line
, CORE_ADDR address
, bool is_stmt
,
21425 struct dwarf2_cu
*cu
)
21427 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
21429 if (dwarf_line_debug
)
21431 fprintf_unfiltered (gdb_stdlog
,
21432 "Recording line %u, file %s, address %s\n",
21433 line
, lbasename (subfile
->name
),
21434 paddress (gdbarch
, address
));
21438 cu
->get_builder ()->record_line (subfile
, line
, addr
, is_stmt
);
21441 /* Subroutine of dwarf_decode_lines_1 to simplify it.
21442 Mark the end of a set of line number records.
21443 The arguments are the same as for dwarf_record_line_1.
21444 If SUBFILE is NULL the request is ignored. */
21447 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21448 CORE_ADDR address
, struct dwarf2_cu
*cu
)
21450 if (subfile
== NULL
)
21453 if (dwarf_line_debug
)
21455 fprintf_unfiltered (gdb_stdlog
,
21456 "Finishing current line, file %s, address %s\n",
21457 lbasename (subfile
->name
),
21458 paddress (gdbarch
, address
));
21461 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, true, cu
);
21465 lnp_state_machine::record_line (bool end_sequence
)
21467 if (dwarf_line_debug
)
21469 fprintf_unfiltered (gdb_stdlog
,
21470 "Processing actual line %u: file %u,"
21471 " address %s, is_stmt %u, discrim %u%s\n",
21473 paddress (m_gdbarch
, m_address
),
21474 m_is_stmt
, m_discriminator
,
21475 (end_sequence
? "\t(end sequence)" : ""));
21478 file_entry
*fe
= current_file ();
21481 dwarf2_debug_line_missing_file_complaint ();
21482 /* For now we ignore lines not starting on an instruction boundary.
21483 But not when processing end_sequence for compatibility with the
21484 previous version of the code. */
21485 else if (m_op_index
== 0 || end_sequence
)
21487 fe
->included_p
= 1;
21488 if (m_record_lines_p
)
21490 /* When we switch files we insert an end maker in the first file,
21491 switch to the second file and add a new line entry. The
21492 problem is that the end marker inserted in the first file will
21493 discard any previous line entries at the same address. If the
21494 line entries in the first file are marked as is-stmt, while
21495 the new line in the second file is non-stmt, then this means
21496 the end marker will discard is-stmt lines so we can have a
21497 non-stmt line. This means that there are less addresses at
21498 which the user can insert a breakpoint.
21500 To improve this we track the last address in m_last_address,
21501 and whether we have seen an is-stmt at this address. Then
21502 when switching files, if we have seen a stmt at the current
21503 address, and we are switching to create a non-stmt line, then
21504 discard the new line. */
21506 = m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ();
21507 bool ignore_this_line
21508 = ((file_changed
&& !end_sequence
&& m_last_address
== m_address
21509 && !m_is_stmt
&& m_stmt_at_address
)
21510 || (!end_sequence
&& m_line
== 0));
21512 if ((file_changed
&& !ignore_this_line
) || end_sequence
)
21514 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
21515 m_currently_recording_lines
? m_cu
: nullptr);
21518 if (!end_sequence
&& !ignore_this_line
)
21520 bool is_stmt
= producer_is_codewarrior (m_cu
) || m_is_stmt
;
21522 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
21523 m_line_has_non_zero_discriminator
,
21526 buildsym_compunit
*builder
= m_cu
->get_builder ();
21527 dwarf_record_line_1 (m_gdbarch
,
21528 builder
->get_current_subfile (),
21529 m_line
, m_address
, is_stmt
,
21530 m_currently_recording_lines
? m_cu
: nullptr);
21532 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21533 m_last_line
= m_line
;
21538 /* Track whether we have seen any m_is_stmt true at m_address in case we
21539 have multiple line table entries all at m_address. */
21540 if (m_last_address
!= m_address
)
21542 m_stmt_at_address
= false;
21543 m_last_address
= m_address
;
21545 m_stmt_at_address
|= m_is_stmt
;
21548 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
21549 line_header
*lh
, bool record_lines_p
)
21553 m_record_lines_p
= record_lines_p
;
21554 m_line_header
= lh
;
21556 m_currently_recording_lines
= true;
21558 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
21559 was a line entry for it so that the backend has a chance to adjust it
21560 and also record it in case it needs it. This is currently used by MIPS
21561 code, cf. `mips_adjust_dwarf2_line'. */
21562 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
21563 m_is_stmt
= lh
->default_is_stmt
;
21564 m_discriminator
= 0;
21566 m_last_address
= m_address
;
21567 m_stmt_at_address
= false;
21571 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
21572 const gdb_byte
*line_ptr
,
21573 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
21575 /* Linkers resolve a symbolic relocation referencing a GC'd function to 0 or
21576 -1. If ADDRESS is 0, ignoring the opcode will err if the text section is
21577 located at 0x0. In this case, additionally check that if
21578 ADDRESS < UNRELOCATED_LOWPC. */
21580 if ((address
== 0 && address
< unrelocated_lowpc
)
21581 || address
== (CORE_ADDR
) -1)
21583 /* This line table is for a function which has been
21584 GCd by the linker. Ignore it. PR gdb/12528 */
21586 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21587 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
21589 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
21590 line_offset
, objfile_name (objfile
));
21591 m_currently_recording_lines
= false;
21592 /* Note: m_currently_recording_lines is left as false until we see
21593 DW_LNE_end_sequence. */
21597 /* Subroutine of dwarf_decode_lines to simplify it.
21598 Process the line number information in LH.
21599 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
21600 program in order to set included_p for every referenced header. */
21603 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
21604 const int decode_for_pst_p
, CORE_ADDR lowpc
)
21606 const gdb_byte
*line_ptr
, *extended_end
;
21607 const gdb_byte
*line_end
;
21608 unsigned int bytes_read
, extended_len
;
21609 unsigned char op_code
, extended_op
;
21610 CORE_ADDR baseaddr
;
21611 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21612 bfd
*abfd
= objfile
->obfd
;
21613 struct gdbarch
*gdbarch
= objfile
->arch ();
21614 /* True if we're recording line info (as opposed to building partial
21615 symtabs and just interested in finding include files mentioned by
21616 the line number program). */
21617 bool record_lines_p
= !decode_for_pst_p
;
21619 baseaddr
= objfile
->text_section_offset ();
21621 line_ptr
= lh
->statement_program_start
;
21622 line_end
= lh
->statement_program_end
;
21624 /* Read the statement sequences until there's nothing left. */
21625 while (line_ptr
< line_end
)
21627 /* The DWARF line number program state machine. Reset the state
21628 machine at the start of each sequence. */
21629 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
21630 bool end_sequence
= false;
21632 if (record_lines_p
)
21634 /* Start a subfile for the current file of the state
21636 const file_entry
*fe
= state_machine
.current_file ();
21639 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
21642 /* Decode the table. */
21643 while (line_ptr
< line_end
&& !end_sequence
)
21645 op_code
= read_1_byte (abfd
, line_ptr
);
21648 if (op_code
>= lh
->opcode_base
)
21650 /* Special opcode. */
21651 state_machine
.handle_special_opcode (op_code
);
21653 else switch (op_code
)
21655 case DW_LNS_extended_op
:
21656 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
21658 line_ptr
+= bytes_read
;
21659 extended_end
= line_ptr
+ extended_len
;
21660 extended_op
= read_1_byte (abfd
, line_ptr
);
21662 if (DW_LNE_lo_user
<= extended_op
21663 && extended_op
<= DW_LNE_hi_user
)
21665 /* Vendor extension, ignore. */
21666 line_ptr
= extended_end
;
21669 switch (extended_op
)
21671 case DW_LNE_end_sequence
:
21672 state_machine
.handle_end_sequence ();
21673 end_sequence
= true;
21675 case DW_LNE_set_address
:
21678 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
21679 line_ptr
+= bytes_read
;
21681 state_machine
.check_line_address (cu
, line_ptr
,
21682 lowpc
- baseaddr
, address
);
21683 state_machine
.handle_set_address (baseaddr
, address
);
21686 case DW_LNE_define_file
:
21688 const char *cur_file
;
21689 unsigned int mod_time
, length
;
21692 cur_file
= read_direct_string (abfd
, line_ptr
,
21694 line_ptr
+= bytes_read
;
21695 dindex
= (dir_index
)
21696 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21697 line_ptr
+= bytes_read
;
21699 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21700 line_ptr
+= bytes_read
;
21702 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21703 line_ptr
+= bytes_read
;
21704 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
21707 case DW_LNE_set_discriminator
:
21709 /* The discriminator is not interesting to the
21710 debugger; just ignore it. We still need to
21711 check its value though:
21712 if there are consecutive entries for the same
21713 (non-prologue) line we want to coalesce them.
21716 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21717 line_ptr
+= bytes_read
;
21719 state_machine
.handle_set_discriminator (discr
);
21723 complaint (_("mangled .debug_line section"));
21726 /* Make sure that we parsed the extended op correctly. If e.g.
21727 we expected a different address size than the producer used,
21728 we may have read the wrong number of bytes. */
21729 if (line_ptr
!= extended_end
)
21731 complaint (_("mangled .debug_line section"));
21736 state_machine
.handle_copy ();
21738 case DW_LNS_advance_pc
:
21741 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21742 line_ptr
+= bytes_read
;
21744 state_machine
.handle_advance_pc (adjust
);
21747 case DW_LNS_advance_line
:
21750 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
21751 line_ptr
+= bytes_read
;
21753 state_machine
.handle_advance_line (line_delta
);
21756 case DW_LNS_set_file
:
21758 file_name_index file
21759 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
21761 line_ptr
+= bytes_read
;
21763 state_machine
.handle_set_file (file
);
21766 case DW_LNS_set_column
:
21767 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21768 line_ptr
+= bytes_read
;
21770 case DW_LNS_negate_stmt
:
21771 state_machine
.handle_negate_stmt ();
21773 case DW_LNS_set_basic_block
:
21775 /* Add to the address register of the state machine the
21776 address increment value corresponding to special opcode
21777 255. I.e., this value is scaled by the minimum
21778 instruction length since special opcode 255 would have
21779 scaled the increment. */
21780 case DW_LNS_const_add_pc
:
21781 state_machine
.handle_const_add_pc ();
21783 case DW_LNS_fixed_advance_pc
:
21785 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
21788 state_machine
.handle_fixed_advance_pc (addr_adj
);
21793 /* Unknown standard opcode, ignore it. */
21796 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
21798 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21799 line_ptr
+= bytes_read
;
21806 dwarf2_debug_line_missing_end_sequence_complaint ();
21808 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
21809 in which case we still finish recording the last line). */
21810 state_machine
.record_line (true);
21814 /* Decode the Line Number Program (LNP) for the given line_header
21815 structure and CU. The actual information extracted and the type
21816 of structures created from the LNP depends on the value of PST.
21818 1. If PST is NULL, then this procedure uses the data from the program
21819 to create all necessary symbol tables, and their linetables.
21821 2. If PST is not NULL, this procedure reads the program to determine
21822 the list of files included by the unit represented by PST, and
21823 builds all the associated partial symbol tables.
21825 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
21826 It is used for relative paths in the line table.
21827 NOTE: When processing partial symtabs (pst != NULL),
21828 comp_dir == pst->dirname.
21830 NOTE: It is important that psymtabs have the same file name (via strcmp)
21831 as the corresponding symtab. Since COMP_DIR is not used in the name of the
21832 symtab we don't use it in the name of the psymtabs we create.
21833 E.g. expand_line_sal requires this when finding psymtabs to expand.
21834 A good testcase for this is mb-inline.exp.
21836 LOWPC is the lowest address in CU (or 0 if not known).
21838 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
21839 for its PC<->lines mapping information. Otherwise only the filename
21840 table is read in. */
21843 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
21844 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
21845 CORE_ADDR lowpc
, int decode_mapping
)
21847 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21848 const int decode_for_pst_p
= (pst
!= NULL
);
21850 if (decode_mapping
)
21851 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
21853 if (decode_for_pst_p
)
21855 /* Now that we're done scanning the Line Header Program, we can
21856 create the psymtab of each included file. */
21857 for (auto &file_entry
: lh
->file_names ())
21858 if (file_entry
.included_p
== 1)
21860 gdb::unique_xmalloc_ptr
<char> name_holder
;
21861 const char *include_name
=
21862 psymtab_include_file_name (lh
, file_entry
, pst
,
21863 comp_dir
, &name_holder
);
21864 if (include_name
!= NULL
)
21865 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
21870 /* Make sure a symtab is created for every file, even files
21871 which contain only variables (i.e. no code with associated
21873 buildsym_compunit
*builder
= cu
->get_builder ();
21874 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
21876 for (auto &fe
: lh
->file_names ())
21878 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
21879 if (builder
->get_current_subfile ()->symtab
== NULL
)
21881 builder
->get_current_subfile ()->symtab
21882 = allocate_symtab (cust
,
21883 builder
->get_current_subfile ()->name
);
21885 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
21890 /* Start a subfile for DWARF. FILENAME is the name of the file and
21891 DIRNAME the name of the source directory which contains FILENAME
21892 or NULL if not known.
21893 This routine tries to keep line numbers from identical absolute and
21894 relative file names in a common subfile.
21896 Using the `list' example from the GDB testsuite, which resides in
21897 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
21898 of /srcdir/list0.c yields the following debugging information for list0.c:
21900 DW_AT_name: /srcdir/list0.c
21901 DW_AT_comp_dir: /compdir
21902 files.files[0].name: list0.h
21903 files.files[0].dir: /srcdir
21904 files.files[1].name: list0.c
21905 files.files[1].dir: /srcdir
21907 The line number information for list0.c has to end up in a single
21908 subfile, so that `break /srcdir/list0.c:1' works as expected.
21909 start_subfile will ensure that this happens provided that we pass the
21910 concatenation of files.files[1].dir and files.files[1].name as the
21914 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
21915 const char *dirname
)
21917 gdb::unique_xmalloc_ptr
<char> copy
;
21919 /* In order not to lose the line information directory,
21920 we concatenate it to the filename when it makes sense.
21921 Note that the Dwarf3 standard says (speaking of filenames in line
21922 information): ``The directory index is ignored for file names
21923 that represent full path names''. Thus ignoring dirname in the
21924 `else' branch below isn't an issue. */
21926 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
21928 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
21929 filename
= copy
.get ();
21932 cu
->get_builder ()->start_subfile (filename
);
21935 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
21936 buildsym_compunit constructor. */
21938 struct compunit_symtab
*
21939 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
21942 gdb_assert (m_builder
== nullptr);
21944 m_builder
.reset (new struct buildsym_compunit
21945 (this->per_objfile
->objfile
,
21946 name
, comp_dir
, language
, low_pc
));
21948 list_in_scope
= get_builder ()->get_file_symbols ();
21950 get_builder ()->record_debugformat ("DWARF 2");
21951 get_builder ()->record_producer (producer
);
21953 processing_has_namespace_info
= false;
21955 return get_builder ()->get_compunit_symtab ();
21959 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
21960 struct dwarf2_cu
*cu
)
21962 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21963 struct comp_unit_head
*cu_header
= &cu
->header
;
21965 /* NOTE drow/2003-01-30: There used to be a comment and some special
21966 code here to turn a symbol with DW_AT_external and a
21967 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
21968 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
21969 with some versions of binutils) where shared libraries could have
21970 relocations against symbols in their debug information - the
21971 minimal symbol would have the right address, but the debug info
21972 would not. It's no longer necessary, because we will explicitly
21973 apply relocations when we read in the debug information now. */
21975 /* A DW_AT_location attribute with no contents indicates that a
21976 variable has been optimized away. */
21977 if (attr
->form_is_block () && attr
->as_block ()->size
== 0)
21979 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21983 /* Handle one degenerate form of location expression specially, to
21984 preserve GDB's previous behavior when section offsets are
21985 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
21986 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
21988 if (attr
->form_is_block ())
21990 struct dwarf_block
*block
= attr
->as_block ();
21992 if ((block
->data
[0] == DW_OP_addr
21993 && block
->size
== 1 + cu_header
->addr_size
)
21994 || ((block
->data
[0] == DW_OP_GNU_addr_index
21995 || block
->data
[0] == DW_OP_addrx
)
21997 == 1 + leb128_size (&block
->data
[1]))))
21999 unsigned int dummy
;
22001 if (block
->data
[0] == DW_OP_addr
)
22002 SET_SYMBOL_VALUE_ADDRESS
22003 (sym
, cu
->header
.read_address (objfile
->obfd
,
22007 SET_SYMBOL_VALUE_ADDRESS
22008 (sym
, read_addr_index_from_leb128 (cu
, block
->data
+ 1,
22010 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
22011 fixup_symbol_section (sym
, objfile
);
22012 SET_SYMBOL_VALUE_ADDRESS
22014 SYMBOL_VALUE_ADDRESS (sym
)
22015 + objfile
->section_offsets
[sym
->section_index ()]);
22020 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
22021 expression evaluator, and use LOC_COMPUTED only when necessary
22022 (i.e. when the value of a register or memory location is
22023 referenced, or a thread-local block, etc.). Then again, it might
22024 not be worthwhile. I'm assuming that it isn't unless performance
22025 or memory numbers show me otherwise. */
22027 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
22029 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
22030 cu
->has_loclist
= true;
22033 /* Given a pointer to a DWARF information entry, figure out if we need
22034 to make a symbol table entry for it, and if so, create a new entry
22035 and return a pointer to it.
22036 If TYPE is NULL, determine symbol type from the die, otherwise
22037 used the passed type.
22038 If SPACE is not NULL, use it to hold the new symbol. If it is
22039 NULL, allocate a new symbol on the objfile's obstack. */
22041 static struct symbol
*
22042 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
22043 struct symbol
*space
)
22045 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22046 struct objfile
*objfile
= per_objfile
->objfile
;
22047 struct gdbarch
*gdbarch
= objfile
->arch ();
22048 struct symbol
*sym
= NULL
;
22050 struct attribute
*attr
= NULL
;
22051 struct attribute
*attr2
= NULL
;
22052 CORE_ADDR baseaddr
;
22053 struct pending
**list_to_add
= NULL
;
22055 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
22057 baseaddr
= objfile
->text_section_offset ();
22059 name
= dwarf2_name (die
, cu
);
22062 int suppress_add
= 0;
22067 sym
= new (&objfile
->objfile_obstack
) symbol
;
22068 OBJSTAT (objfile
, n_syms
++);
22070 /* Cache this symbol's name and the name's demangled form (if any). */
22071 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
22072 /* Fortran does not have mangling standard and the mangling does differ
22073 between gfortran, iFort etc. */
22074 const char *physname
22075 = (cu
->language
== language_fortran
22076 ? dwarf2_full_name (name
, die
, cu
)
22077 : dwarf2_physname (name
, die
, cu
));
22078 const char *linkagename
= dw2_linkage_name (die
, cu
);
22080 if (linkagename
== nullptr || cu
->language
== language_ada
)
22081 sym
->set_linkage_name (physname
);
22084 sym
->set_demangled_name (physname
, &objfile
->objfile_obstack
);
22085 sym
->set_linkage_name (linkagename
);
22088 /* Default assumptions.
22089 Use the passed type or decode it from the die. */
22090 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
22091 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
22093 SYMBOL_TYPE (sym
) = type
;
22095 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
22096 attr
= dwarf2_attr (die
,
22097 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
22099 if (attr
!= nullptr)
22100 SYMBOL_LINE (sym
) = attr
->constant_value (0);
22102 attr
= dwarf2_attr (die
,
22103 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
22105 if (attr
!= nullptr && attr
->is_nonnegative ())
22107 file_name_index file_index
22108 = (file_name_index
) attr
->as_nonnegative ();
22109 struct file_entry
*fe
;
22111 if (cu
->line_header
!= NULL
)
22112 fe
= cu
->line_header
->file_name_at (file_index
);
22117 complaint (_("file index out of range"));
22119 symbol_set_symtab (sym
, fe
->symtab
);
22125 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
22126 if (attr
!= nullptr)
22130 addr
= attr
->as_address ();
22131 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
22132 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
22133 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
22136 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
22137 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
22138 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
22139 add_symbol_to_list (sym
, cu
->list_in_scope
);
22141 case DW_TAG_subprogram
:
22142 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
22144 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
22145 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
22146 if ((attr2
!= nullptr && attr2
->as_boolean ())
22147 || cu
->language
== language_ada
22148 || cu
->language
== language_fortran
)
22150 /* Subprograms marked external are stored as a global symbol.
22151 Ada and Fortran subprograms, whether marked external or
22152 not, are always stored as a global symbol, because we want
22153 to be able to access them globally. For instance, we want
22154 to be able to break on a nested subprogram without having
22155 to specify the context. */
22156 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22160 list_to_add
= cu
->list_in_scope
;
22163 case DW_TAG_inlined_subroutine
:
22164 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
22166 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
22167 SYMBOL_INLINED (sym
) = 1;
22168 list_to_add
= cu
->list_in_scope
;
22170 case DW_TAG_template_value_param
:
22172 /* Fall through. */
22173 case DW_TAG_constant
:
22174 case DW_TAG_variable
:
22175 case DW_TAG_member
:
22176 /* Compilation with minimal debug info may result in
22177 variables with missing type entries. Change the
22178 misleading `void' type to something sensible. */
22179 if (SYMBOL_TYPE (sym
)->code () == TYPE_CODE_VOID
)
22180 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
22182 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22183 /* In the case of DW_TAG_member, we should only be called for
22184 static const members. */
22185 if (die
->tag
== DW_TAG_member
)
22187 /* dwarf2_add_field uses die_is_declaration,
22188 so we do the same. */
22189 gdb_assert (die_is_declaration (die
, cu
));
22192 if (attr
!= nullptr)
22194 dwarf2_const_value (attr
, sym
, cu
);
22195 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
22198 if (attr2
!= nullptr && attr2
->as_boolean ())
22199 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22201 list_to_add
= cu
->list_in_scope
;
22205 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22206 if (attr
!= nullptr)
22208 var_decode_location (attr
, sym
, cu
);
22209 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
22211 /* Fortran explicitly imports any global symbols to the local
22212 scope by DW_TAG_common_block. */
22213 if (cu
->language
== language_fortran
&& die
->parent
22214 && die
->parent
->tag
== DW_TAG_common_block
)
22217 if (SYMBOL_CLASS (sym
) == LOC_STATIC
22218 && SYMBOL_VALUE_ADDRESS (sym
) == 0
22219 && !per_objfile
->per_bfd
->has_section_at_zero
)
22221 /* When a static variable is eliminated by the linker,
22222 the corresponding debug information is not stripped
22223 out, but the variable address is set to null;
22224 do not add such variables into symbol table. */
22226 else if (attr2
!= nullptr && attr2
->as_boolean ())
22228 if (SYMBOL_CLASS (sym
) == LOC_STATIC
22229 && (objfile
->flags
& OBJF_MAINLINE
) == 0
22230 && per_objfile
->per_bfd
->can_copy
)
22232 /* A global static variable might be subject to
22233 copy relocation. We first check for a local
22234 minsym, though, because maybe the symbol was
22235 marked hidden, in which case this would not
22237 bound_minimal_symbol found
22238 = (lookup_minimal_symbol_linkage
22239 (sym
->linkage_name (), objfile
));
22240 if (found
.minsym
!= nullptr)
22241 sym
->maybe_copied
= 1;
22244 /* A variable with DW_AT_external is never static,
22245 but it may be block-scoped. */
22247 = ((cu
->list_in_scope
22248 == cu
->get_builder ()->get_file_symbols ())
22249 ? cu
->get_builder ()->get_global_symbols ()
22250 : cu
->list_in_scope
);
22253 list_to_add
= cu
->list_in_scope
;
22257 /* We do not know the address of this symbol.
22258 If it is an external symbol and we have type information
22259 for it, enter the symbol as a LOC_UNRESOLVED symbol.
22260 The address of the variable will then be determined from
22261 the minimal symbol table whenever the variable is
22263 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
22265 /* Fortran explicitly imports any global symbols to the local
22266 scope by DW_TAG_common_block. */
22267 if (cu
->language
== language_fortran
&& die
->parent
22268 && die
->parent
->tag
== DW_TAG_common_block
)
22270 /* SYMBOL_CLASS doesn't matter here because
22271 read_common_block is going to reset it. */
22273 list_to_add
= cu
->list_in_scope
;
22275 else if (attr2
!= nullptr && attr2
->as_boolean ()
22276 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
22278 /* A variable with DW_AT_external is never static, but it
22279 may be block-scoped. */
22281 = ((cu
->list_in_scope
22282 == cu
->get_builder ()->get_file_symbols ())
22283 ? cu
->get_builder ()->get_global_symbols ()
22284 : cu
->list_in_scope
);
22286 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
22288 else if (!die_is_declaration (die
, cu
))
22290 /* Use the default LOC_OPTIMIZED_OUT class. */
22291 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
22293 list_to_add
= cu
->list_in_scope
;
22297 case DW_TAG_formal_parameter
:
22299 /* If we are inside a function, mark this as an argument. If
22300 not, we might be looking at an argument to an inlined function
22301 when we do not have enough information to show inlined frames;
22302 pretend it's a local variable in that case so that the user can
22304 struct context_stack
*curr
22305 = cu
->get_builder ()->get_current_context_stack ();
22306 if (curr
!= nullptr && curr
->name
!= nullptr)
22307 SYMBOL_IS_ARGUMENT (sym
) = 1;
22308 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22309 if (attr
!= nullptr)
22311 var_decode_location (attr
, sym
, cu
);
22313 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22314 if (attr
!= nullptr)
22316 dwarf2_const_value (attr
, sym
, cu
);
22319 list_to_add
= cu
->list_in_scope
;
22322 case DW_TAG_unspecified_parameters
:
22323 /* From varargs functions; gdb doesn't seem to have any
22324 interest in this information, so just ignore it for now.
22327 case DW_TAG_template_type_param
:
22329 /* Fall through. */
22330 case DW_TAG_class_type
:
22331 case DW_TAG_interface_type
:
22332 case DW_TAG_structure_type
:
22333 case DW_TAG_union_type
:
22334 case DW_TAG_set_type
:
22335 case DW_TAG_enumeration_type
:
22336 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22337 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
22340 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
22341 really ever be static objects: otherwise, if you try
22342 to, say, break of a class's method and you're in a file
22343 which doesn't mention that class, it won't work unless
22344 the check for all static symbols in lookup_symbol_aux
22345 saves you. See the OtherFileClass tests in
22346 gdb.c++/namespace.exp. */
22350 buildsym_compunit
*builder
= cu
->get_builder ();
22352 = (cu
->list_in_scope
== builder
->get_file_symbols ()
22353 && cu
->language
== language_cplus
22354 ? builder
->get_global_symbols ()
22355 : cu
->list_in_scope
);
22357 /* The semantics of C++ state that "struct foo {
22358 ... }" also defines a typedef for "foo". */
22359 if (cu
->language
== language_cplus
22360 || cu
->language
== language_ada
22361 || cu
->language
== language_d
22362 || cu
->language
== language_rust
)
22364 /* The symbol's name is already allocated along
22365 with this objfile, so we don't need to
22366 duplicate it for the type. */
22367 if (SYMBOL_TYPE (sym
)->name () == 0)
22368 SYMBOL_TYPE (sym
)->set_name (sym
->search_name ());
22373 case DW_TAG_typedef
:
22374 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22375 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
22376 list_to_add
= cu
->list_in_scope
;
22378 case DW_TAG_array_type
:
22379 case DW_TAG_base_type
:
22380 case DW_TAG_subrange_type
:
22381 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22382 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
22383 list_to_add
= cu
->list_in_scope
;
22385 case DW_TAG_enumerator
:
22386 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22387 if (attr
!= nullptr)
22389 dwarf2_const_value (attr
, sym
, cu
);
22392 /* NOTE: carlton/2003-11-10: See comment above in the
22393 DW_TAG_class_type, etc. block. */
22396 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
22397 && cu
->language
== language_cplus
22398 ? cu
->get_builder ()->get_global_symbols ()
22399 : cu
->list_in_scope
);
22402 case DW_TAG_imported_declaration
:
22403 case DW_TAG_namespace
:
22404 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22405 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22407 case DW_TAG_module
:
22408 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22409 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
22410 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22412 case DW_TAG_common_block
:
22413 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
22414 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
22415 add_symbol_to_list (sym
, cu
->list_in_scope
);
22418 /* Not a tag we recognize. Hopefully we aren't processing
22419 trash data, but since we must specifically ignore things
22420 we don't recognize, there is nothing else we should do at
22422 complaint (_("unsupported tag: '%s'"),
22423 dwarf_tag_name (die
->tag
));
22429 sym
->hash_next
= objfile
->template_symbols
;
22430 objfile
->template_symbols
= sym
;
22431 list_to_add
= NULL
;
22434 if (list_to_add
!= NULL
)
22435 add_symbol_to_list (sym
, list_to_add
);
22437 /* For the benefit of old versions of GCC, check for anonymous
22438 namespaces based on the demangled name. */
22439 if (!cu
->processing_has_namespace_info
22440 && cu
->language
== language_cplus
)
22441 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
22446 /* Given an attr with a DW_FORM_dataN value in host byte order,
22447 zero-extend it as appropriate for the symbol's type. The DWARF
22448 standard (v4) is not entirely clear about the meaning of using
22449 DW_FORM_dataN for a constant with a signed type, where the type is
22450 wider than the data. The conclusion of a discussion on the DWARF
22451 list was that this is unspecified. We choose to always zero-extend
22452 because that is the interpretation long in use by GCC. */
22455 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
22456 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
22458 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22459 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
22460 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
22461 LONGEST l
= attr
->constant_value (0);
22463 if (bits
< sizeof (*value
) * 8)
22465 l
&= ((LONGEST
) 1 << bits
) - 1;
22468 else if (bits
== sizeof (*value
) * 8)
22472 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
22473 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
22480 /* Read a constant value from an attribute. Either set *VALUE, or if
22481 the value does not fit in *VALUE, set *BYTES - either already
22482 allocated on the objfile obstack, or newly allocated on OBSTACK,
22483 or, set *BATON, if we translated the constant to a location
22487 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
22488 const char *name
, struct obstack
*obstack
,
22489 struct dwarf2_cu
*cu
,
22490 LONGEST
*value
, const gdb_byte
**bytes
,
22491 struct dwarf2_locexpr_baton
**baton
)
22493 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22494 struct objfile
*objfile
= per_objfile
->objfile
;
22495 struct comp_unit_head
*cu_header
= &cu
->header
;
22496 struct dwarf_block
*blk
;
22497 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
22498 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22504 switch (attr
->form
)
22507 case DW_FORM_addrx
:
22508 case DW_FORM_GNU_addr_index
:
22512 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
22513 dwarf2_const_value_length_mismatch_complaint (name
,
22514 cu_header
->addr_size
,
22515 TYPE_LENGTH (type
));
22516 /* Symbols of this form are reasonably rare, so we just
22517 piggyback on the existing location code rather than writing
22518 a new implementation of symbol_computed_ops. */
22519 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
22520 (*baton
)->per_objfile
= per_objfile
;
22521 (*baton
)->per_cu
= cu
->per_cu
;
22522 gdb_assert ((*baton
)->per_cu
);
22524 (*baton
)->size
= 2 + cu_header
->addr_size
;
22525 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
22526 (*baton
)->data
= data
;
22528 data
[0] = DW_OP_addr
;
22529 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
22530 byte_order
, attr
->as_address ());
22531 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
22534 case DW_FORM_string
:
22537 case DW_FORM_GNU_str_index
:
22538 case DW_FORM_GNU_strp_alt
:
22539 /* The string is already allocated on the objfile obstack, point
22541 *bytes
= (const gdb_byte
*) attr
->as_string ();
22543 case DW_FORM_block1
:
22544 case DW_FORM_block2
:
22545 case DW_FORM_block4
:
22546 case DW_FORM_block
:
22547 case DW_FORM_exprloc
:
22548 case DW_FORM_data16
:
22549 blk
= attr
->as_block ();
22550 if (TYPE_LENGTH (type
) != blk
->size
)
22551 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
22552 TYPE_LENGTH (type
));
22553 *bytes
= blk
->data
;
22556 /* The DW_AT_const_value attributes are supposed to carry the
22557 symbol's value "represented as it would be on the target
22558 architecture." By the time we get here, it's already been
22559 converted to host endianness, so we just need to sign- or
22560 zero-extend it as appropriate. */
22561 case DW_FORM_data1
:
22562 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
22564 case DW_FORM_data2
:
22565 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
22567 case DW_FORM_data4
:
22568 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
22570 case DW_FORM_data8
:
22571 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
22574 case DW_FORM_sdata
:
22575 case DW_FORM_implicit_const
:
22576 *value
= attr
->as_signed ();
22579 case DW_FORM_udata
:
22580 *value
= attr
->as_unsigned ();
22584 complaint (_("unsupported const value attribute form: '%s'"),
22585 dwarf_form_name (attr
->form
));
22592 /* Copy constant value from an attribute to a symbol. */
22595 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
22596 struct dwarf2_cu
*cu
)
22598 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22600 const gdb_byte
*bytes
;
22601 struct dwarf2_locexpr_baton
*baton
;
22603 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
22604 sym
->print_name (),
22605 &objfile
->objfile_obstack
, cu
,
22606 &value
, &bytes
, &baton
);
22610 SYMBOL_LOCATION_BATON (sym
) = baton
;
22611 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
22613 else if (bytes
!= NULL
)
22615 SYMBOL_VALUE_BYTES (sym
) = bytes
;
22616 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
22620 SYMBOL_VALUE (sym
) = value
;
22621 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
22625 /* Return the type of the die in question using its DW_AT_type attribute. */
22627 static struct type
*
22628 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22630 struct attribute
*type_attr
;
22632 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
22635 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22636 /* A missing DW_AT_type represents a void type. */
22637 return objfile_type (objfile
)->builtin_void
;
22640 return lookup_die_type (die
, type_attr
, cu
);
22643 /* True iff CU's producer generates GNAT Ada auxiliary information
22644 that allows to find parallel types through that information instead
22645 of having to do expensive parallel lookups by type name. */
22648 need_gnat_info (struct dwarf2_cu
*cu
)
22650 /* Assume that the Ada compiler was GNAT, which always produces
22651 the auxiliary information. */
22652 return (cu
->language
== language_ada
);
22655 /* Return the auxiliary type of the die in question using its
22656 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
22657 attribute is not present. */
22659 static struct type
*
22660 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22662 struct attribute
*type_attr
;
22664 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
22668 return lookup_die_type (die
, type_attr
, cu
);
22671 /* If DIE has a descriptive_type attribute, then set the TYPE's
22672 descriptive type accordingly. */
22675 set_descriptive_type (struct type
*type
, struct die_info
*die
,
22676 struct dwarf2_cu
*cu
)
22678 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
22680 if (descriptive_type
)
22682 ALLOCATE_GNAT_AUX_TYPE (type
);
22683 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
22687 /* Return the containing type of the die in question using its
22688 DW_AT_containing_type attribute. */
22690 static struct type
*
22691 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22693 struct attribute
*type_attr
;
22694 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22696 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
22698 error (_("Dwarf Error: Problem turning containing type into gdb type "
22699 "[in module %s]"), objfile_name (objfile
));
22701 return lookup_die_type (die
, type_attr
, cu
);
22704 /* Return an error marker type to use for the ill formed type in DIE/CU. */
22706 static struct type
*
22707 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
22709 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22710 struct objfile
*objfile
= per_objfile
->objfile
;
22713 std::string message
22714 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
22715 objfile_name (objfile
),
22716 sect_offset_str (cu
->header
.sect_off
),
22717 sect_offset_str (die
->sect_off
));
22718 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
22720 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
22723 /* Look up the type of DIE in CU using its type attribute ATTR.
22724 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
22725 DW_AT_containing_type.
22726 If there is no type substitute an error marker. */
22728 static struct type
*
22729 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
22730 struct dwarf2_cu
*cu
)
22732 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22733 struct objfile
*objfile
= per_objfile
->objfile
;
22734 struct type
*this_type
;
22736 gdb_assert (attr
->name
== DW_AT_type
22737 || attr
->name
== DW_AT_GNAT_descriptive_type
22738 || attr
->name
== DW_AT_containing_type
);
22740 /* First see if we have it cached. */
22742 if (attr
->form
== DW_FORM_GNU_ref_alt
)
22744 struct dwarf2_per_cu_data
*per_cu
;
22745 sect_offset sect_off
= attr
->get_ref_die_offset ();
22747 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1, per_objfile
);
22748 this_type
= get_die_type_at_offset (sect_off
, per_cu
, per_objfile
);
22750 else if (attr
->form_is_ref ())
22752 sect_offset sect_off
= attr
->get_ref_die_offset ();
22754 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, per_objfile
);
22756 else if (attr
->form
== DW_FORM_ref_sig8
)
22758 ULONGEST signature
= attr
->as_signature ();
22760 return get_signatured_type (die
, signature
, cu
);
22764 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
22765 " at %s [in module %s]"),
22766 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
22767 objfile_name (objfile
));
22768 return build_error_marker_type (cu
, die
);
22771 /* If not cached we need to read it in. */
22773 if (this_type
== NULL
)
22775 struct die_info
*type_die
= NULL
;
22776 struct dwarf2_cu
*type_cu
= cu
;
22778 if (attr
->form_is_ref ())
22779 type_die
= follow_die_ref (die
, attr
, &type_cu
);
22780 if (type_die
== NULL
)
22781 return build_error_marker_type (cu
, die
);
22782 /* If we find the type now, it's probably because the type came
22783 from an inter-CU reference and the type's CU got expanded before
22785 this_type
= read_type_die (type_die
, type_cu
);
22788 /* If we still don't have a type use an error marker. */
22790 if (this_type
== NULL
)
22791 return build_error_marker_type (cu
, die
);
22796 /* Return the type in DIE, CU.
22797 Returns NULL for invalid types.
22799 This first does a lookup in die_type_hash,
22800 and only reads the die in if necessary.
22802 NOTE: This can be called when reading in partial or full symbols. */
22804 static struct type
*
22805 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
22807 struct type
*this_type
;
22809 this_type
= get_die_type (die
, cu
);
22813 return read_type_die_1 (die
, cu
);
22816 /* Read the type in DIE, CU.
22817 Returns NULL for invalid types. */
22819 static struct type
*
22820 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
22822 struct type
*this_type
= NULL
;
22826 case DW_TAG_class_type
:
22827 case DW_TAG_interface_type
:
22828 case DW_TAG_structure_type
:
22829 case DW_TAG_union_type
:
22830 this_type
= read_structure_type (die
, cu
);
22832 case DW_TAG_enumeration_type
:
22833 this_type
= read_enumeration_type (die
, cu
);
22835 case DW_TAG_subprogram
:
22836 case DW_TAG_subroutine_type
:
22837 case DW_TAG_inlined_subroutine
:
22838 this_type
= read_subroutine_type (die
, cu
);
22840 case DW_TAG_array_type
:
22841 this_type
= read_array_type (die
, cu
);
22843 case DW_TAG_set_type
:
22844 this_type
= read_set_type (die
, cu
);
22846 case DW_TAG_pointer_type
:
22847 this_type
= read_tag_pointer_type (die
, cu
);
22849 case DW_TAG_ptr_to_member_type
:
22850 this_type
= read_tag_ptr_to_member_type (die
, cu
);
22852 case DW_TAG_reference_type
:
22853 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
22855 case DW_TAG_rvalue_reference_type
:
22856 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
22858 case DW_TAG_const_type
:
22859 this_type
= read_tag_const_type (die
, cu
);
22861 case DW_TAG_volatile_type
:
22862 this_type
= read_tag_volatile_type (die
, cu
);
22864 case DW_TAG_restrict_type
:
22865 this_type
= read_tag_restrict_type (die
, cu
);
22867 case DW_TAG_string_type
:
22868 this_type
= read_tag_string_type (die
, cu
);
22870 case DW_TAG_typedef
:
22871 this_type
= read_typedef (die
, cu
);
22873 case DW_TAG_subrange_type
:
22874 this_type
= read_subrange_type (die
, cu
);
22876 case DW_TAG_base_type
:
22877 this_type
= read_base_type (die
, cu
);
22879 case DW_TAG_unspecified_type
:
22880 this_type
= read_unspecified_type (die
, cu
);
22882 case DW_TAG_namespace
:
22883 this_type
= read_namespace_type (die
, cu
);
22885 case DW_TAG_module
:
22886 this_type
= read_module_type (die
, cu
);
22888 case DW_TAG_atomic_type
:
22889 this_type
= read_tag_atomic_type (die
, cu
);
22892 complaint (_("unexpected tag in read_type_die: '%s'"),
22893 dwarf_tag_name (die
->tag
));
22900 /* See if we can figure out if the class lives in a namespace. We do
22901 this by looking for a member function; its demangled name will
22902 contain namespace info, if there is any.
22903 Return the computed name or NULL.
22904 Space for the result is allocated on the objfile's obstack.
22905 This is the full-die version of guess_partial_die_structure_name.
22906 In this case we know DIE has no useful parent. */
22908 static const char *
22909 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22911 struct die_info
*spec_die
;
22912 struct dwarf2_cu
*spec_cu
;
22913 struct die_info
*child
;
22914 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22917 spec_die
= die_specification (die
, &spec_cu
);
22918 if (spec_die
!= NULL
)
22924 for (child
= die
->child
;
22926 child
= child
->sibling
)
22928 if (child
->tag
== DW_TAG_subprogram
)
22930 const char *linkage_name
= dw2_linkage_name (child
, cu
);
22932 if (linkage_name
!= NULL
)
22934 gdb::unique_xmalloc_ptr
<char> actual_name
22935 (cu
->language_defn
->class_name_from_physname (linkage_name
));
22936 const char *name
= NULL
;
22938 if (actual_name
!= NULL
)
22940 const char *die_name
= dwarf2_name (die
, cu
);
22942 if (die_name
!= NULL
22943 && strcmp (die_name
, actual_name
.get ()) != 0)
22945 /* Strip off the class name from the full name.
22946 We want the prefix. */
22947 int die_name_len
= strlen (die_name
);
22948 int actual_name_len
= strlen (actual_name
.get ());
22949 const char *ptr
= actual_name
.get ();
22951 /* Test for '::' as a sanity check. */
22952 if (actual_name_len
> die_name_len
+ 2
22953 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
22954 name
= obstack_strndup (
22955 &objfile
->per_bfd
->storage_obstack
,
22956 ptr
, actual_name_len
- die_name_len
- 2);
22967 /* GCC might emit a nameless typedef that has a linkage name. Determine the
22968 prefix part in such case. See
22969 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22971 static const char *
22972 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22974 struct attribute
*attr
;
22977 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
22978 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
22981 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
22984 attr
= dw2_linkage_name_attr (die
, cu
);
22985 const char *attr_name
= attr
->as_string ();
22986 if (attr
== NULL
|| attr_name
== NULL
)
22989 /* dwarf2_name had to be already called. */
22990 gdb_assert (attr
->canonical_string_p ());
22992 /* Strip the base name, keep any leading namespaces/classes. */
22993 base
= strrchr (attr_name
, ':');
22994 if (base
== NULL
|| base
== attr_name
|| base
[-1] != ':')
22997 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22998 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
23000 &base
[-1] - attr_name
);
23003 /* Return the name of the namespace/class that DIE is defined within,
23004 or "" if we can't tell. The caller should not xfree the result.
23006 For example, if we're within the method foo() in the following
23016 then determine_prefix on foo's die will return "N::C". */
23018 static const char *
23019 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
23021 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23022 struct die_info
*parent
, *spec_die
;
23023 struct dwarf2_cu
*spec_cu
;
23024 struct type
*parent_type
;
23025 const char *retval
;
23027 if (cu
->language
!= language_cplus
23028 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
23029 && cu
->language
!= language_rust
)
23032 retval
= anonymous_struct_prefix (die
, cu
);
23036 /* We have to be careful in the presence of DW_AT_specification.
23037 For example, with GCC 3.4, given the code
23041 // Definition of N::foo.
23045 then we'll have a tree of DIEs like this:
23047 1: DW_TAG_compile_unit
23048 2: DW_TAG_namespace // N
23049 3: DW_TAG_subprogram // declaration of N::foo
23050 4: DW_TAG_subprogram // definition of N::foo
23051 DW_AT_specification // refers to die #3
23053 Thus, when processing die #4, we have to pretend that we're in
23054 the context of its DW_AT_specification, namely the contex of die
23057 spec_die
= die_specification (die
, &spec_cu
);
23058 if (spec_die
== NULL
)
23059 parent
= die
->parent
;
23062 parent
= spec_die
->parent
;
23066 if (parent
== NULL
)
23068 else if (parent
->building_fullname
)
23071 const char *parent_name
;
23073 /* It has been seen on RealView 2.2 built binaries,
23074 DW_TAG_template_type_param types actually _defined_ as
23075 children of the parent class:
23078 template class <class Enum> Class{};
23079 Class<enum E> class_e;
23081 1: DW_TAG_class_type (Class)
23082 2: DW_TAG_enumeration_type (E)
23083 3: DW_TAG_enumerator (enum1:0)
23084 3: DW_TAG_enumerator (enum2:1)
23086 2: DW_TAG_template_type_param
23087 DW_AT_type DW_FORM_ref_udata (E)
23089 Besides being broken debug info, it can put GDB into an
23090 infinite loop. Consider:
23092 When we're building the full name for Class<E>, we'll start
23093 at Class, and go look over its template type parameters,
23094 finding E. We'll then try to build the full name of E, and
23095 reach here. We're now trying to build the full name of E,
23096 and look over the parent DIE for containing scope. In the
23097 broken case, if we followed the parent DIE of E, we'd again
23098 find Class, and once again go look at its template type
23099 arguments, etc., etc. Simply don't consider such parent die
23100 as source-level parent of this die (it can't be, the language
23101 doesn't allow it), and break the loop here. */
23102 name
= dwarf2_name (die
, cu
);
23103 parent_name
= dwarf2_name (parent
, cu
);
23104 complaint (_("template param type '%s' defined within parent '%s'"),
23105 name
? name
: "<unknown>",
23106 parent_name
? parent_name
: "<unknown>");
23110 switch (parent
->tag
)
23112 case DW_TAG_namespace
:
23113 parent_type
= read_type_die (parent
, cu
);
23114 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
23115 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
23116 Work around this problem here. */
23117 if (cu
->language
== language_cplus
23118 && strcmp (parent_type
->name (), "::") == 0)
23120 /* We give a name to even anonymous namespaces. */
23121 return parent_type
->name ();
23122 case DW_TAG_class_type
:
23123 case DW_TAG_interface_type
:
23124 case DW_TAG_structure_type
:
23125 case DW_TAG_union_type
:
23126 case DW_TAG_module
:
23127 parent_type
= read_type_die (parent
, cu
);
23128 if (parent_type
->name () != NULL
)
23129 return parent_type
->name ();
23131 /* An anonymous structure is only allowed non-static data
23132 members; no typedefs, no member functions, et cetera.
23133 So it does not need a prefix. */
23135 case DW_TAG_compile_unit
:
23136 case DW_TAG_partial_unit
:
23137 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
23138 if (cu
->language
== language_cplus
23139 && !per_objfile
->per_bfd
->types
.empty ()
23140 && die
->child
!= NULL
23141 && (die
->tag
== DW_TAG_class_type
23142 || die
->tag
== DW_TAG_structure_type
23143 || die
->tag
== DW_TAG_union_type
))
23145 const char *name
= guess_full_die_structure_name (die
, cu
);
23150 case DW_TAG_subprogram
:
23151 /* Nested subroutines in Fortran get a prefix with the name
23152 of the parent's subroutine. */
23153 if (cu
->language
== language_fortran
)
23155 if ((die
->tag
== DW_TAG_subprogram
)
23156 && (dwarf2_name (parent
, cu
) != NULL
))
23157 return dwarf2_name (parent
, cu
);
23159 return determine_prefix (parent
, cu
);
23160 case DW_TAG_enumeration_type
:
23161 parent_type
= read_type_die (parent
, cu
);
23162 if (TYPE_DECLARED_CLASS (parent_type
))
23164 if (parent_type
->name () != NULL
)
23165 return parent_type
->name ();
23168 /* Fall through. */
23170 return determine_prefix (parent
, cu
);
23174 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
23175 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
23176 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
23177 an obconcat, otherwise allocate storage for the result. The CU argument is
23178 used to determine the language and hence, the appropriate separator. */
23180 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
23183 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
23184 int physname
, struct dwarf2_cu
*cu
)
23186 const char *lead
= "";
23189 if (suffix
== NULL
|| suffix
[0] == '\0'
23190 || prefix
== NULL
|| prefix
[0] == '\0')
23192 else if (cu
->language
== language_d
)
23194 /* For D, the 'main' function could be defined in any module, but it
23195 should never be prefixed. */
23196 if (strcmp (suffix
, "D main") == 0)
23204 else if (cu
->language
== language_fortran
&& physname
)
23206 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
23207 DW_AT_MIPS_linkage_name is preferred and used instead. */
23215 if (prefix
== NULL
)
23217 if (suffix
== NULL
)
23224 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
23226 strcpy (retval
, lead
);
23227 strcat (retval
, prefix
);
23228 strcat (retval
, sep
);
23229 strcat (retval
, suffix
);
23234 /* We have an obstack. */
23235 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
23239 /* Get name of a die, return NULL if not found. */
23241 static const char *
23242 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
23243 struct objfile
*objfile
)
23245 if (name
&& cu
->language
== language_cplus
)
23247 gdb::unique_xmalloc_ptr
<char> canon_name
23248 = cp_canonicalize_string (name
);
23250 if (canon_name
!= nullptr)
23251 name
= objfile
->intern (canon_name
.get ());
23257 /* Get name of a die, return NULL if not found.
23258 Anonymous namespaces are converted to their magic string. */
23260 static const char *
23261 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
23263 struct attribute
*attr
;
23264 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
23266 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
23267 const char *attr_name
= attr
== nullptr ? nullptr : attr
->as_string ();
23268 if (attr_name
== nullptr
23269 && die
->tag
!= DW_TAG_namespace
23270 && die
->tag
!= DW_TAG_class_type
23271 && die
->tag
!= DW_TAG_interface_type
23272 && die
->tag
!= DW_TAG_structure_type
23273 && die
->tag
!= DW_TAG_union_type
)
23278 case DW_TAG_compile_unit
:
23279 case DW_TAG_partial_unit
:
23280 /* Compilation units have a DW_AT_name that is a filename, not
23281 a source language identifier. */
23282 case DW_TAG_enumeration_type
:
23283 case DW_TAG_enumerator
:
23284 /* These tags always have simple identifiers already; no need
23285 to canonicalize them. */
23288 case DW_TAG_namespace
:
23289 if (attr_name
!= nullptr)
23291 return CP_ANONYMOUS_NAMESPACE_STR
;
23293 case DW_TAG_class_type
:
23294 case DW_TAG_interface_type
:
23295 case DW_TAG_structure_type
:
23296 case DW_TAG_union_type
:
23297 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
23298 structures or unions. These were of the form "._%d" in GCC 4.1,
23299 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
23300 and GCC 4.4. We work around this problem by ignoring these. */
23301 if (attr_name
!= nullptr
23302 && (startswith (attr_name
, "._")
23303 || startswith (attr_name
, "<anonymous")))
23306 /* GCC might emit a nameless typedef that has a linkage name. See
23307 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
23308 if (!attr
|| attr_name
== NULL
)
23310 attr
= dw2_linkage_name_attr (die
, cu
);
23311 attr_name
= attr
== nullptr ? nullptr : attr
->as_string ();
23312 if (attr
== NULL
|| attr_name
== NULL
)
23315 /* Avoid demangling attr_name the second time on a second
23316 call for the same DIE. */
23317 if (!attr
->canonical_string_p ())
23319 gdb::unique_xmalloc_ptr
<char> demangled
23320 (gdb_demangle (attr_name
, DMGL_TYPES
));
23321 if (demangled
== nullptr)
23324 attr
->set_string_canonical (objfile
->intern (demangled
.get ()));
23325 attr_name
= attr
->as_string ();
23328 /* Strip any leading namespaces/classes, keep only the
23329 base name. DW_AT_name for named DIEs does not
23330 contain the prefixes. */
23331 const char *base
= strrchr (attr_name
, ':');
23332 if (base
&& base
> attr_name
&& base
[-1] == ':')
23343 if (!attr
->canonical_string_p ())
23344 attr
->set_string_canonical (dwarf2_canonicalize_name (attr_name
, cu
,
23346 return attr
->as_string ();
23349 /* Return the die that this die in an extension of, or NULL if there
23350 is none. *EXT_CU is the CU containing DIE on input, and the CU
23351 containing the return value on output. */
23353 static struct die_info
*
23354 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
23356 struct attribute
*attr
;
23358 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
23362 return follow_die_ref (die
, attr
, ext_cu
);
23366 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
23370 print_spaces (indent
, f
);
23371 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
23372 dwarf_tag_name (die
->tag
), die
->abbrev
,
23373 sect_offset_str (die
->sect_off
));
23375 if (die
->parent
!= NULL
)
23377 print_spaces (indent
, f
);
23378 fprintf_unfiltered (f
, " parent at offset: %s\n",
23379 sect_offset_str (die
->parent
->sect_off
));
23382 print_spaces (indent
, f
);
23383 fprintf_unfiltered (f
, " has children: %s\n",
23384 dwarf_bool_name (die
->child
!= NULL
));
23386 print_spaces (indent
, f
);
23387 fprintf_unfiltered (f
, " attributes:\n");
23389 for (i
= 0; i
< die
->num_attrs
; ++i
)
23391 print_spaces (indent
, f
);
23392 fprintf_unfiltered (f
, " %s (%s) ",
23393 dwarf_attr_name (die
->attrs
[i
].name
),
23394 dwarf_form_name (die
->attrs
[i
].form
));
23396 switch (die
->attrs
[i
].form
)
23399 case DW_FORM_addrx
:
23400 case DW_FORM_GNU_addr_index
:
23401 fprintf_unfiltered (f
, "address: ");
23402 fputs_filtered (hex_string (die
->attrs
[i
].as_address ()), f
);
23404 case DW_FORM_block2
:
23405 case DW_FORM_block4
:
23406 case DW_FORM_block
:
23407 case DW_FORM_block1
:
23408 fprintf_unfiltered (f
, "block: size %s",
23409 pulongest (die
->attrs
[i
].as_block ()->size
));
23411 case DW_FORM_exprloc
:
23412 fprintf_unfiltered (f
, "expression: size %s",
23413 pulongest (die
->attrs
[i
].as_block ()->size
));
23415 case DW_FORM_data16
:
23416 fprintf_unfiltered (f
, "constant of 16 bytes");
23418 case DW_FORM_ref_addr
:
23419 fprintf_unfiltered (f
, "ref address: ");
23420 fputs_filtered (hex_string (die
->attrs
[i
].as_unsigned ()), f
);
23422 case DW_FORM_GNU_ref_alt
:
23423 fprintf_unfiltered (f
, "alt ref address: ");
23424 fputs_filtered (hex_string (die
->attrs
[i
].as_unsigned ()), f
);
23430 case DW_FORM_ref_udata
:
23431 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
23432 (long) (die
->attrs
[i
].as_unsigned ()));
23434 case DW_FORM_data1
:
23435 case DW_FORM_data2
:
23436 case DW_FORM_data4
:
23437 case DW_FORM_data8
:
23438 case DW_FORM_udata
:
23439 fprintf_unfiltered (f
, "constant: %s",
23440 pulongest (die
->attrs
[i
].as_unsigned ()));
23442 case DW_FORM_sec_offset
:
23443 fprintf_unfiltered (f
, "section offset: %s",
23444 pulongest (die
->attrs
[i
].as_unsigned ()));
23446 case DW_FORM_ref_sig8
:
23447 fprintf_unfiltered (f
, "signature: %s",
23448 hex_string (die
->attrs
[i
].as_signature ()));
23450 case DW_FORM_string
:
23452 case DW_FORM_line_strp
:
23454 case DW_FORM_GNU_str_index
:
23455 case DW_FORM_GNU_strp_alt
:
23456 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
23457 die
->attrs
[i
].as_string ()
23458 ? die
->attrs
[i
].as_string () : "",
23459 die
->attrs
[i
].canonical_string_p () ? "is" : "not");
23462 if (die
->attrs
[i
].as_boolean ())
23463 fprintf_unfiltered (f
, "flag: TRUE");
23465 fprintf_unfiltered (f
, "flag: FALSE");
23467 case DW_FORM_flag_present
:
23468 fprintf_unfiltered (f
, "flag: TRUE");
23470 case DW_FORM_indirect
:
23471 /* The reader will have reduced the indirect form to
23472 the "base form" so this form should not occur. */
23473 fprintf_unfiltered (f
,
23474 "unexpected attribute form: DW_FORM_indirect");
23476 case DW_FORM_sdata
:
23477 case DW_FORM_implicit_const
:
23478 fprintf_unfiltered (f
, "constant: %s",
23479 plongest (die
->attrs
[i
].as_signed ()));
23482 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
23483 die
->attrs
[i
].form
);
23486 fprintf_unfiltered (f
, "\n");
23491 dump_die_for_error (struct die_info
*die
)
23493 dump_die_shallow (gdb_stderr
, 0, die
);
23497 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
23499 int indent
= level
* 4;
23501 gdb_assert (die
!= NULL
);
23503 if (level
>= max_level
)
23506 dump_die_shallow (f
, indent
, die
);
23508 if (die
->child
!= NULL
)
23510 print_spaces (indent
, f
);
23511 fprintf_unfiltered (f
, " Children:");
23512 if (level
+ 1 < max_level
)
23514 fprintf_unfiltered (f
, "\n");
23515 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
23519 fprintf_unfiltered (f
,
23520 " [not printed, max nesting level reached]\n");
23524 if (die
->sibling
!= NULL
&& level
> 0)
23526 dump_die_1 (f
, level
, max_level
, die
->sibling
);
23530 /* This is called from the pdie macro in gdbinit.in.
23531 It's not static so gcc will keep a copy callable from gdb. */
23534 dump_die (struct die_info
*die
, int max_level
)
23536 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
23540 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
23544 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
23545 to_underlying (die
->sect_off
),
23551 /* Follow reference or signature attribute ATTR of SRC_DIE.
23552 On entry *REF_CU is the CU of SRC_DIE.
23553 On exit *REF_CU is the CU of the result. */
23555 static struct die_info
*
23556 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23557 struct dwarf2_cu
**ref_cu
)
23559 struct die_info
*die
;
23561 if (attr
->form_is_ref ())
23562 die
= follow_die_ref (src_die
, attr
, ref_cu
);
23563 else if (attr
->form
== DW_FORM_ref_sig8
)
23564 die
= follow_die_sig (src_die
, attr
, ref_cu
);
23567 dump_die_for_error (src_die
);
23568 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
23569 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23575 /* Follow reference OFFSET.
23576 On entry *REF_CU is the CU of the source die referencing OFFSET.
23577 On exit *REF_CU is the CU of the result.
23578 Returns NULL if OFFSET is invalid. */
23580 static struct die_info
*
23581 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
23582 struct dwarf2_cu
**ref_cu
)
23584 struct die_info temp_die
;
23585 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
23586 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23588 gdb_assert (cu
->per_cu
!= NULL
);
23592 dwarf_read_debug_printf_v ("source CU offset: %s, target offset: %s, "
23593 "source CU contains target offset: %d",
23594 sect_offset_str (cu
->per_cu
->sect_off
),
23595 sect_offset_str (sect_off
),
23596 cu
->header
.offset_in_cu_p (sect_off
));
23598 if (cu
->per_cu
->is_debug_types
)
23600 /* .debug_types CUs cannot reference anything outside their CU.
23601 If they need to, they have to reference a signatured type via
23602 DW_FORM_ref_sig8. */
23603 if (!cu
->header
.offset_in_cu_p (sect_off
))
23606 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
23607 || !cu
->header
.offset_in_cu_p (sect_off
))
23609 struct dwarf2_per_cu_data
*per_cu
;
23611 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23614 dwarf_read_debug_printf_v ("target CU offset: %s, "
23615 "target CU DIEs loaded: %d",
23616 sect_offset_str (per_cu
->sect_off
),
23617 per_objfile
->get_cu (per_cu
) != nullptr);
23619 /* If necessary, add it to the queue and load its DIEs.
23621 Even if maybe_queue_comp_unit doesn't require us to load the CU's DIEs,
23622 it doesn't mean they are currently loaded. Since we require them
23623 to be loaded, we must check for ourselves. */
23624 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->language
)
23625 || per_objfile
->get_cu (per_cu
) == nullptr)
23626 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
23627 false, cu
->language
);
23629 target_cu
= per_objfile
->get_cu (per_cu
);
23630 gdb_assert (target_cu
!= nullptr);
23632 else if (cu
->dies
== NULL
)
23634 /* We're loading full DIEs during partial symbol reading. */
23635 gdb_assert (per_objfile
->per_bfd
->reading_partial_symbols
);
23636 load_full_comp_unit (cu
->per_cu
, per_objfile
, cu
, false,
23640 *ref_cu
= target_cu
;
23641 temp_die
.sect_off
= sect_off
;
23643 if (target_cu
!= cu
)
23644 target_cu
->ancestor
= cu
;
23646 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
23648 to_underlying (sect_off
));
23651 /* Follow reference attribute ATTR of SRC_DIE.
23652 On entry *REF_CU is the CU of SRC_DIE.
23653 On exit *REF_CU is the CU of the result. */
23655 static struct die_info
*
23656 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
23657 struct dwarf2_cu
**ref_cu
)
23659 sect_offset sect_off
= attr
->get_ref_die_offset ();
23660 struct dwarf2_cu
*cu
= *ref_cu
;
23661 struct die_info
*die
;
23663 die
= follow_die_offset (sect_off
,
23664 (attr
->form
== DW_FORM_GNU_ref_alt
23665 || cu
->per_cu
->is_dwz
),
23668 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
23669 "at %s [in module %s]"),
23670 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
23671 objfile_name (cu
->per_objfile
->objfile
));
23678 struct dwarf2_locexpr_baton
23679 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
23680 dwarf2_per_cu_data
*per_cu
,
23681 dwarf2_per_objfile
*per_objfile
,
23682 gdb::function_view
<CORE_ADDR ()> get_frame_pc
,
23683 bool resolve_abstract_p
)
23685 struct die_info
*die
;
23686 struct attribute
*attr
;
23687 struct dwarf2_locexpr_baton retval
;
23688 struct objfile
*objfile
= per_objfile
->objfile
;
23690 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23692 cu
= load_cu (per_cu
, per_objfile
, false);
23696 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23697 Instead just throw an error, not much else we can do. */
23698 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23699 sect_offset_str (sect_off
), objfile_name (objfile
));
23702 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23704 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23705 sect_offset_str (sect_off
), objfile_name (objfile
));
23707 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23708 if (!attr
&& resolve_abstract_p
23709 && (per_objfile
->per_bfd
->abstract_to_concrete
.find (die
->sect_off
)
23710 != per_objfile
->per_bfd
->abstract_to_concrete
.end ()))
23712 CORE_ADDR pc
= get_frame_pc ();
23713 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
23714 struct gdbarch
*gdbarch
= objfile
->arch ();
23716 for (const auto &cand_off
23717 : per_objfile
->per_bfd
->abstract_to_concrete
[die
->sect_off
])
23719 struct dwarf2_cu
*cand_cu
= cu
;
23720 struct die_info
*cand
23721 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
23724 || cand
->parent
->tag
!= DW_TAG_subprogram
)
23727 CORE_ADDR pc_low
, pc_high
;
23728 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
23729 if (pc_low
== ((CORE_ADDR
) -1))
23731 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
23732 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
23733 if (!(pc_low
<= pc
&& pc
< pc_high
))
23737 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23744 /* DWARF: "If there is no such attribute, then there is no effect.".
23745 DATA is ignored if SIZE is 0. */
23747 retval
.data
= NULL
;
23750 else if (attr
->form_is_section_offset ())
23752 struct dwarf2_loclist_baton loclist_baton
;
23753 CORE_ADDR pc
= get_frame_pc ();
23756 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
23758 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
23760 retval
.size
= size
;
23764 if (!attr
->form_is_block ())
23765 error (_("Dwarf Error: DIE at %s referenced in module %s "
23766 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
23767 sect_offset_str (sect_off
), objfile_name (objfile
));
23769 struct dwarf_block
*block
= attr
->as_block ();
23770 retval
.data
= block
->data
;
23771 retval
.size
= block
->size
;
23773 retval
.per_objfile
= per_objfile
;
23774 retval
.per_cu
= cu
->per_cu
;
23776 per_objfile
->age_comp_units ();
23783 struct dwarf2_locexpr_baton
23784 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
23785 dwarf2_per_cu_data
*per_cu
,
23786 dwarf2_per_objfile
*per_objfile
,
23787 gdb::function_view
<CORE_ADDR ()> get_frame_pc
)
23789 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
23791 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, per_objfile
,
23795 /* Write a constant of a given type as target-ordered bytes into
23798 static const gdb_byte
*
23799 write_constant_as_bytes (struct obstack
*obstack
,
23800 enum bfd_endian byte_order
,
23807 *len
= TYPE_LENGTH (type
);
23808 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23809 store_unsigned_integer (result
, *len
, byte_order
, value
);
23817 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
23818 dwarf2_per_cu_data
*per_cu
,
23819 dwarf2_per_objfile
*per_objfile
,
23823 struct die_info
*die
;
23824 struct attribute
*attr
;
23825 const gdb_byte
*result
= NULL
;
23828 enum bfd_endian byte_order
;
23829 struct objfile
*objfile
= per_objfile
->objfile
;
23831 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23833 cu
= load_cu (per_cu
, per_objfile
, false);
23837 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23838 Instead just throw an error, not much else we can do. */
23839 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23840 sect_offset_str (sect_off
), objfile_name (objfile
));
23843 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23845 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23846 sect_offset_str (sect_off
), objfile_name (objfile
));
23848 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23852 byte_order
= (bfd_big_endian (objfile
->obfd
)
23853 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
23855 switch (attr
->form
)
23858 case DW_FORM_addrx
:
23859 case DW_FORM_GNU_addr_index
:
23863 *len
= cu
->header
.addr_size
;
23864 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23865 store_unsigned_integer (tem
, *len
, byte_order
, attr
->as_address ());
23869 case DW_FORM_string
:
23872 case DW_FORM_GNU_str_index
:
23873 case DW_FORM_GNU_strp_alt
:
23874 /* The string is already allocated on the objfile obstack, point
23877 const char *attr_name
= attr
->as_string ();
23878 result
= (const gdb_byte
*) attr_name
;
23879 *len
= strlen (attr_name
);
23882 case DW_FORM_block1
:
23883 case DW_FORM_block2
:
23884 case DW_FORM_block4
:
23885 case DW_FORM_block
:
23886 case DW_FORM_exprloc
:
23887 case DW_FORM_data16
:
23889 struct dwarf_block
*block
= attr
->as_block ();
23890 result
= block
->data
;
23891 *len
= block
->size
;
23895 /* The DW_AT_const_value attributes are supposed to carry the
23896 symbol's value "represented as it would be on the target
23897 architecture." By the time we get here, it's already been
23898 converted to host endianness, so we just need to sign- or
23899 zero-extend it as appropriate. */
23900 case DW_FORM_data1
:
23901 type
= die_type (die
, cu
);
23902 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
23903 if (result
== NULL
)
23904 result
= write_constant_as_bytes (obstack
, byte_order
,
23907 case DW_FORM_data2
:
23908 type
= die_type (die
, cu
);
23909 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
23910 if (result
== NULL
)
23911 result
= write_constant_as_bytes (obstack
, byte_order
,
23914 case DW_FORM_data4
:
23915 type
= die_type (die
, cu
);
23916 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
23917 if (result
== NULL
)
23918 result
= write_constant_as_bytes (obstack
, byte_order
,
23921 case DW_FORM_data8
:
23922 type
= die_type (die
, cu
);
23923 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
23924 if (result
== NULL
)
23925 result
= write_constant_as_bytes (obstack
, byte_order
,
23929 case DW_FORM_sdata
:
23930 case DW_FORM_implicit_const
:
23931 type
= die_type (die
, cu
);
23932 result
= write_constant_as_bytes (obstack
, byte_order
,
23933 type
, attr
->as_signed (), len
);
23936 case DW_FORM_udata
:
23937 type
= die_type (die
, cu
);
23938 result
= write_constant_as_bytes (obstack
, byte_order
,
23939 type
, attr
->as_unsigned (), len
);
23943 complaint (_("unsupported const value attribute form: '%s'"),
23944 dwarf_form_name (attr
->form
));
23954 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
23955 dwarf2_per_cu_data
*per_cu
,
23956 dwarf2_per_objfile
*per_objfile
)
23958 struct die_info
*die
;
23960 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23962 cu
= load_cu (per_cu
, per_objfile
, false);
23967 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23971 return die_type (die
, cu
);
23977 dwarf2_get_die_type (cu_offset die_offset
,
23978 dwarf2_per_cu_data
*per_cu
,
23979 dwarf2_per_objfile
*per_objfile
)
23981 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
23982 return get_die_type_at_offset (die_offset_sect
, per_cu
, per_objfile
);
23985 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
23986 On entry *REF_CU is the CU of SRC_DIE.
23987 On exit *REF_CU is the CU of the result.
23988 Returns NULL if the referenced DIE isn't found. */
23990 static struct die_info
*
23991 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
23992 struct dwarf2_cu
**ref_cu
)
23994 struct die_info temp_die
;
23995 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
23996 struct die_info
*die
;
23997 dwarf2_per_objfile
*per_objfile
= (*ref_cu
)->per_objfile
;
24000 /* While it might be nice to assert sig_type->type == NULL here,
24001 we can get here for DW_AT_imported_declaration where we need
24002 the DIE not the type. */
24004 /* If necessary, add it to the queue and load its DIEs.
24006 Even if maybe_queue_comp_unit doesn't require us to load the CU's DIEs,
24007 it doesn't mean they are currently loaded. Since we require them
24008 to be loaded, we must check for ourselves. */
24009 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, per_objfile
,
24011 || per_objfile
->get_cu (&sig_type
->per_cu
) == nullptr)
24012 read_signatured_type (sig_type
, per_objfile
);
24014 sig_cu
= per_objfile
->get_cu (&sig_type
->per_cu
);
24015 gdb_assert (sig_cu
!= NULL
);
24016 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
24017 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
24018 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
24019 to_underlying (temp_die
.sect_off
));
24022 /* For .gdb_index version 7 keep track of included TUs.
24023 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
24024 if (per_objfile
->per_bfd
->index_table
!= NULL
24025 && per_objfile
->per_bfd
->index_table
->version
<= 7)
24027 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
24032 sig_cu
->ancestor
= cu
;
24040 /* Follow signatured type referenced by ATTR in SRC_DIE.
24041 On entry *REF_CU is the CU of SRC_DIE.
24042 On exit *REF_CU is the CU of the result.
24043 The result is the DIE of the type.
24044 If the referenced type cannot be found an error is thrown. */
24046 static struct die_info
*
24047 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
24048 struct dwarf2_cu
**ref_cu
)
24050 ULONGEST signature
= attr
->as_signature ();
24051 struct signatured_type
*sig_type
;
24052 struct die_info
*die
;
24054 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
24056 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
24057 /* sig_type will be NULL if the signatured type is missing from
24059 if (sig_type
== NULL
)
24061 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
24062 " from DIE at %s [in module %s]"),
24063 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
24064 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
24067 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
24070 dump_die_for_error (src_die
);
24071 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
24072 " from DIE at %s [in module %s]"),
24073 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
24074 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
24080 /* Get the type specified by SIGNATURE referenced in DIE/CU,
24081 reading in and processing the type unit if necessary. */
24083 static struct type
*
24084 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
24085 struct dwarf2_cu
*cu
)
24087 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24088 struct signatured_type
*sig_type
;
24089 struct dwarf2_cu
*type_cu
;
24090 struct die_info
*type_die
;
24093 sig_type
= lookup_signatured_type (cu
, signature
);
24094 /* sig_type will be NULL if the signatured type is missing from
24096 if (sig_type
== NULL
)
24098 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
24099 " from DIE at %s [in module %s]"),
24100 hex_string (signature
), sect_offset_str (die
->sect_off
),
24101 objfile_name (per_objfile
->objfile
));
24102 return build_error_marker_type (cu
, die
);
24105 /* If we already know the type we're done. */
24106 type
= per_objfile
->get_type_for_signatured_type (sig_type
);
24107 if (type
!= nullptr)
24111 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
24112 if (type_die
!= NULL
)
24114 /* N.B. We need to call get_die_type to ensure only one type for this DIE
24115 is created. This is important, for example, because for c++ classes
24116 we need TYPE_NAME set which is only done by new_symbol. Blech. */
24117 type
= read_type_die (type_die
, type_cu
);
24120 complaint (_("Dwarf Error: Cannot build signatured type %s"
24121 " referenced from DIE at %s [in module %s]"),
24122 hex_string (signature
), sect_offset_str (die
->sect_off
),
24123 objfile_name (per_objfile
->objfile
));
24124 type
= build_error_marker_type (cu
, die
);
24129 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
24130 " from DIE at %s [in module %s]"),
24131 hex_string (signature
), sect_offset_str (die
->sect_off
),
24132 objfile_name (per_objfile
->objfile
));
24133 type
= build_error_marker_type (cu
, die
);
24136 per_objfile
->set_type_for_signatured_type (sig_type
, type
);
24141 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
24142 reading in and processing the type unit if necessary. */
24144 static struct type
*
24145 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
24146 struct dwarf2_cu
*cu
) /* ARI: editCase function */
24148 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
24149 if (attr
->form_is_ref ())
24151 struct dwarf2_cu
*type_cu
= cu
;
24152 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
24154 return read_type_die (type_die
, type_cu
);
24156 else if (attr
->form
== DW_FORM_ref_sig8
)
24158 return get_signatured_type (die
, attr
->as_signature (), cu
);
24162 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24164 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
24165 " at %s [in module %s]"),
24166 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
24167 objfile_name (per_objfile
->objfile
));
24168 return build_error_marker_type (cu
, die
);
24172 /* Load the DIEs associated with type unit PER_CU into memory. */
24175 load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
24176 dwarf2_per_objfile
*per_objfile
)
24178 struct signatured_type
*sig_type
;
24180 /* Caller is responsible for ensuring type_unit_groups don't get here. */
24181 gdb_assert (! per_cu
->type_unit_group_p ());
24183 /* We have the per_cu, but we need the signatured_type.
24184 Fortunately this is an easy translation. */
24185 gdb_assert (per_cu
->is_debug_types
);
24186 sig_type
= (struct signatured_type
*) per_cu
;
24188 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
24190 read_signatured_type (sig_type
, per_objfile
);
24192 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
24195 /* Read in a signatured type and build its CU and DIEs.
24196 If the type is a stub for the real type in a DWO file,
24197 read in the real type from the DWO file as well. */
24200 read_signatured_type (signatured_type
*sig_type
,
24201 dwarf2_per_objfile
*per_objfile
)
24203 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
24205 gdb_assert (per_cu
->is_debug_types
);
24206 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
24208 cutu_reader
reader (per_cu
, per_objfile
, nullptr, nullptr, false);
24210 if (!reader
.dummy_p
)
24212 struct dwarf2_cu
*cu
= reader
.cu
;
24213 const gdb_byte
*info_ptr
= reader
.info_ptr
;
24215 gdb_assert (cu
->die_hash
== NULL
);
24217 htab_create_alloc_ex (cu
->header
.length
/ 12,
24221 &cu
->comp_unit_obstack
,
24222 hashtab_obstack_allocate
,
24223 dummy_obstack_deallocate
);
24225 if (reader
.comp_unit_die
->has_children
)
24226 reader
.comp_unit_die
->child
24227 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
24228 reader
.comp_unit_die
);
24229 cu
->dies
= reader
.comp_unit_die
;
24230 /* comp_unit_die is not stored in die_hash, no need. */
24232 /* We try not to read any attributes in this function, because
24233 not all CUs needed for references have been loaded yet, and
24234 symbol table processing isn't initialized. But we have to
24235 set the CU language, or we won't be able to build types
24236 correctly. Similarly, if we do not read the producer, we can
24237 not apply producer-specific interpretation. */
24238 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
24243 sig_type
->per_cu
.tu_read
= 1;
24246 /* Decode simple location descriptions.
24247 Given a pointer to a dwarf block that defines a location, compute
24248 the location and return the value. If COMPUTED is non-null, it is
24249 set to true to indicate that decoding was successful, and false
24250 otherwise. If COMPUTED is null, then this function may emit a
24254 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
, bool *computed
)
24256 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
24258 size_t size
= blk
->size
;
24259 const gdb_byte
*data
= blk
->data
;
24260 CORE_ADDR stack
[64];
24262 unsigned int bytes_read
, unsnd
;
24265 if (computed
!= nullptr)
24271 stack
[++stacki
] = 0;
24310 stack
[++stacki
] = op
- DW_OP_lit0
;
24345 stack
[++stacki
] = op
- DW_OP_reg0
;
24348 if (computed
== nullptr)
24349 dwarf2_complex_location_expr_complaint ();
24356 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
24358 stack
[++stacki
] = unsnd
;
24361 if (computed
== nullptr)
24362 dwarf2_complex_location_expr_complaint ();
24369 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
24374 case DW_OP_const1u
:
24375 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
24379 case DW_OP_const1s
:
24380 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
24384 case DW_OP_const2u
:
24385 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
24389 case DW_OP_const2s
:
24390 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
24394 case DW_OP_const4u
:
24395 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
24399 case DW_OP_const4s
:
24400 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
24404 case DW_OP_const8u
:
24405 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
24410 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
24416 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
24421 stack
[stacki
+ 1] = stack
[stacki
];
24426 stack
[stacki
- 1] += stack
[stacki
];
24430 case DW_OP_plus_uconst
:
24431 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
24437 stack
[stacki
- 1] -= stack
[stacki
];
24442 /* If we're not the last op, then we definitely can't encode
24443 this using GDB's address_class enum. This is valid for partial
24444 global symbols, although the variable's address will be bogus
24448 if (computed
== nullptr)
24449 dwarf2_complex_location_expr_complaint ();
24455 case DW_OP_GNU_push_tls_address
:
24456 case DW_OP_form_tls_address
:
24457 /* The top of the stack has the offset from the beginning
24458 of the thread control block at which the variable is located. */
24459 /* Nothing should follow this operator, so the top of stack would
24461 /* This is valid for partial global symbols, but the variable's
24462 address will be bogus in the psymtab. Make it always at least
24463 non-zero to not look as a variable garbage collected by linker
24464 which have DW_OP_addr 0. */
24467 if (computed
== nullptr)
24468 dwarf2_complex_location_expr_complaint ();
24475 case DW_OP_GNU_uninit
:
24476 if (computed
!= nullptr)
24481 case DW_OP_GNU_addr_index
:
24482 case DW_OP_GNU_const_index
:
24483 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
24489 if (computed
== nullptr)
24491 const char *name
= get_DW_OP_name (op
);
24494 complaint (_("unsupported stack op: '%s'"),
24497 complaint (_("unsupported stack op: '%02x'"),
24501 return (stack
[stacki
]);
24504 /* Enforce maximum stack depth of SIZE-1 to avoid writing
24505 outside of the allocated space. Also enforce minimum>0. */
24506 if (stacki
>= ARRAY_SIZE (stack
) - 1)
24508 if (computed
== nullptr)
24509 complaint (_("location description stack overflow"));
24515 if (computed
== nullptr)
24516 complaint (_("location description stack underflow"));
24521 if (computed
!= nullptr)
24523 return (stack
[stacki
]);
24526 /* memory allocation interface */
24528 static struct dwarf_block
*
24529 dwarf_alloc_block (struct dwarf2_cu
*cu
)
24531 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
24534 static struct die_info
*
24535 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
24537 struct die_info
*die
;
24538 size_t size
= sizeof (struct die_info
);
24541 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
24543 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
24544 memset (die
, 0, sizeof (struct die_info
));
24550 /* Macro support. */
24552 /* An overload of dwarf_decode_macros that finds the correct section
24553 and ensures it is read in before calling the other overload. */
24556 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
24557 int section_is_gnu
)
24559 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24560 struct objfile
*objfile
= per_objfile
->objfile
;
24561 const struct line_header
*lh
= cu
->line_header
;
24562 unsigned int offset_size
= cu
->header
.offset_size
;
24563 struct dwarf2_section_info
*section
;
24564 const char *section_name
;
24566 if (cu
->dwo_unit
!= nullptr)
24568 if (section_is_gnu
)
24570 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
24571 section_name
= ".debug_macro.dwo";
24575 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
24576 section_name
= ".debug_macinfo.dwo";
24581 if (section_is_gnu
)
24583 section
= &per_objfile
->per_bfd
->macro
;
24584 section_name
= ".debug_macro";
24588 section
= &per_objfile
->per_bfd
->macinfo
;
24589 section_name
= ".debug_macinfo";
24593 section
->read (objfile
);
24594 if (section
->buffer
== nullptr)
24596 complaint (_("missing %s section"), section_name
);
24600 buildsym_compunit
*builder
= cu
->get_builder ();
24602 struct dwarf2_section_info
*str_offsets_section
;
24603 struct dwarf2_section_info
*str_section
;
24604 ULONGEST str_offsets_base
;
24606 if (cu
->dwo_unit
!= nullptr)
24608 str_offsets_section
= &cu
->dwo_unit
->dwo_file
24609 ->sections
.str_offsets
;
24610 str_section
= &cu
->dwo_unit
->dwo_file
->sections
.str
;
24611 str_offsets_base
= cu
->header
.addr_size
;
24615 str_offsets_section
= &per_objfile
->per_bfd
->str_offsets
;
24616 str_section
= &per_objfile
->per_bfd
->str
;
24617 str_offsets_base
= *cu
->str_offsets_base
;
24620 dwarf_decode_macros (per_objfile
, builder
, section
, lh
,
24621 offset_size
, offset
, str_section
, str_offsets_section
,
24622 str_offsets_base
, section_is_gnu
);
24625 /* Return the .debug_loc section to use for CU.
24626 For DWO files use .debug_loc.dwo. */
24628 static struct dwarf2_section_info
*
24629 cu_debug_loc_section (struct dwarf2_cu
*cu
)
24631 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24635 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24637 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
24639 return (cu
->header
.version
>= 5 ? &per_objfile
->per_bfd
->loclists
24640 : &per_objfile
->per_bfd
->loc
);
24643 /* Return the .debug_rnglists section to use for CU. */
24644 static struct dwarf2_section_info
*
24645 cu_debug_rnglists_section (struct dwarf2_cu
*cu
, dwarf_tag tag
)
24647 if (cu
->header
.version
< 5)
24648 error (_(".debug_rnglists section cannot be used in DWARF %d"),
24649 cu
->header
.version
);
24650 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
24652 /* Make sure we read the .debug_rnglists section from the file that
24653 contains the DW_AT_ranges attribute we are reading. Normally that
24654 would be the .dwo file, if there is one. However for DW_TAG_compile_unit
24655 or DW_TAG_skeleton unit, we always want to read from objfile/linked
24657 if (cu
->dwo_unit
!= nullptr
24658 && tag
!= DW_TAG_compile_unit
24659 && tag
!= DW_TAG_skeleton_unit
)
24661 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24663 if (sections
->rnglists
.size
> 0)
24664 return §ions
->rnglists
;
24666 error (_(".debug_rnglists section is missing from .dwo file."));
24668 return &dwarf2_per_objfile
->per_bfd
->rnglists
;
24671 /* A helper function that fills in a dwarf2_loclist_baton. */
24674 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
24675 struct dwarf2_loclist_baton
*baton
,
24676 const struct attribute
*attr
)
24678 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24679 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24681 section
->read (per_objfile
->objfile
);
24683 baton
->per_objfile
= per_objfile
;
24684 baton
->per_cu
= cu
->per_cu
;
24685 gdb_assert (baton
->per_cu
);
24686 /* We don't know how long the location list is, but make sure we
24687 don't run off the edge of the section. */
24688 baton
->size
= section
->size
- attr
->as_unsigned ();
24689 baton
->data
= section
->buffer
+ attr
->as_unsigned ();
24690 if (cu
->base_address
.has_value ())
24691 baton
->base_address
= *cu
->base_address
;
24693 baton
->base_address
= 0;
24694 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
24698 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
24699 struct dwarf2_cu
*cu
, int is_block
)
24701 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24702 struct objfile
*objfile
= per_objfile
->objfile
;
24703 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24705 if (attr
->form_is_section_offset ()
24706 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
24707 the section. If so, fall through to the complaint in the
24709 && attr
->as_unsigned () < section
->get_size (objfile
))
24711 struct dwarf2_loclist_baton
*baton
;
24713 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
24715 fill_in_loclist_baton (cu
, baton
, attr
);
24717 if (!cu
->base_address
.has_value ())
24718 complaint (_("Location list used without "
24719 "specifying the CU base address."));
24721 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24722 ? dwarf2_loclist_block_index
24723 : dwarf2_loclist_index
);
24724 SYMBOL_LOCATION_BATON (sym
) = baton
;
24728 struct dwarf2_locexpr_baton
*baton
;
24730 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
24731 baton
->per_objfile
= per_objfile
;
24732 baton
->per_cu
= cu
->per_cu
;
24733 gdb_assert (baton
->per_cu
);
24735 if (attr
->form_is_block ())
24737 /* Note that we're just copying the block's data pointer
24738 here, not the actual data. We're still pointing into the
24739 info_buffer for SYM's objfile; right now we never release
24740 that buffer, but when we do clean up properly this may
24742 struct dwarf_block
*block
= attr
->as_block ();
24743 baton
->size
= block
->size
;
24744 baton
->data
= block
->data
;
24748 dwarf2_invalid_attrib_class_complaint ("location description",
24749 sym
->natural_name ());
24753 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24754 ? dwarf2_locexpr_block_index
24755 : dwarf2_locexpr_index
);
24756 SYMBOL_LOCATION_BATON (sym
) = baton
;
24762 const comp_unit_head
*
24763 dwarf2_per_cu_data::get_header () const
24765 if (!m_header_read_in
)
24767 const gdb_byte
*info_ptr
24768 = this->section
->buffer
+ to_underlying (this->sect_off
);
24770 memset (&m_header
, 0, sizeof (m_header
));
24772 read_comp_unit_head (&m_header
, info_ptr
, this->section
,
24773 rcuh_kind::COMPILE
);
24775 m_header_read_in
= true;
24784 dwarf2_per_cu_data::addr_size () const
24786 return this->get_header ()->addr_size
;
24792 dwarf2_per_cu_data::offset_size () const
24794 return this->get_header ()->offset_size
;
24800 dwarf2_per_cu_data::ref_addr_size () const
24802 const comp_unit_head
*header
= this->get_header ();
24804 if (header
->version
== 2)
24805 return header
->addr_size
;
24807 return header
->offset_size
;
24813 dwarf2_cu::addr_type () const
24815 struct objfile
*objfile
= this->per_objfile
->objfile
;
24816 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
24817 struct type
*addr_type
= lookup_pointer_type (void_type
);
24818 int addr_size
= this->per_cu
->addr_size ();
24820 if (TYPE_LENGTH (addr_type
) == addr_size
)
24823 addr_type
= addr_sized_int_type (addr_type
->is_unsigned ());
24827 /* A helper function for dwarf2_find_containing_comp_unit that returns
24828 the index of the result, and that searches a vector. It will
24829 return a result even if the offset in question does not actually
24830 occur in any CU. This is separate so that it can be unit
24834 dwarf2_find_containing_comp_unit
24835 (sect_offset sect_off
,
24836 unsigned int offset_in_dwz
,
24837 const std::vector
<dwarf2_per_cu_data
*> &all_comp_units
)
24842 high
= all_comp_units
.size () - 1;
24845 struct dwarf2_per_cu_data
*mid_cu
;
24846 int mid
= low
+ (high
- low
) / 2;
24848 mid_cu
= all_comp_units
[mid
];
24849 if (mid_cu
->is_dwz
> offset_in_dwz
24850 || (mid_cu
->is_dwz
== offset_in_dwz
24851 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
24856 gdb_assert (low
== high
);
24860 /* Locate the .debug_info compilation unit from CU's objfile which contains
24861 the DIE at OFFSET. Raises an error on failure. */
24863 static struct dwarf2_per_cu_data
*
24864 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
24865 unsigned int offset_in_dwz
,
24866 dwarf2_per_objfile
*per_objfile
)
24868 int low
= dwarf2_find_containing_comp_unit
24869 (sect_off
, offset_in_dwz
, per_objfile
->per_bfd
->all_comp_units
);
24870 dwarf2_per_cu_data
*this_cu
= per_objfile
->per_bfd
->all_comp_units
[low
];
24872 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
24874 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
24875 error (_("Dwarf Error: could not find partial DIE containing "
24876 "offset %s [in module %s]"),
24877 sect_offset_str (sect_off
),
24878 bfd_get_filename (per_objfile
->objfile
->obfd
));
24880 gdb_assert (per_objfile
->per_bfd
->all_comp_units
[low
-1]->sect_off
24882 return per_objfile
->per_bfd
->all_comp_units
[low
-1];
24886 if (low
== per_objfile
->per_bfd
->all_comp_units
.size () - 1
24887 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
24888 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
24889 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
24896 namespace selftests
{
24897 namespace find_containing_comp_unit
{
24902 struct dwarf2_per_cu_data one
{};
24903 struct dwarf2_per_cu_data two
{};
24904 struct dwarf2_per_cu_data three
{};
24905 struct dwarf2_per_cu_data four
{};
24908 two
.sect_off
= sect_offset (one
.length
);
24913 four
.sect_off
= sect_offset (three
.length
);
24917 std::vector
<dwarf2_per_cu_data
*> units
;
24918 units
.push_back (&one
);
24919 units
.push_back (&two
);
24920 units
.push_back (&three
);
24921 units
.push_back (&four
);
24925 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
24926 SELF_CHECK (units
[result
] == &one
);
24927 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
24928 SELF_CHECK (units
[result
] == &one
);
24929 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
24930 SELF_CHECK (units
[result
] == &two
);
24932 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
24933 SELF_CHECK (units
[result
] == &three
);
24934 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
24935 SELF_CHECK (units
[result
] == &three
);
24936 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
24937 SELF_CHECK (units
[result
] == &four
);
24943 #endif /* GDB_SELF_TEST */
24945 /* Initialize dwarf2_cu to read PER_CU, in the context of PER_OBJFILE. */
24947 dwarf2_cu::dwarf2_cu (dwarf2_per_cu_data
*per_cu
,
24948 dwarf2_per_objfile
*per_objfile
)
24950 per_objfile (per_objfile
),
24952 has_loclist (false),
24953 checked_producer (false),
24954 producer_is_gxx_lt_4_6 (false),
24955 producer_is_gcc_lt_4_3 (false),
24956 producer_is_icc (false),
24957 producer_is_icc_lt_14 (false),
24958 producer_is_codewarrior (false),
24959 processing_has_namespace_info (false)
24963 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
24966 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
24967 enum language pretend_language
)
24969 struct attribute
*attr
;
24971 /* Set the language we're debugging. */
24972 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
24973 if (attr
!= nullptr)
24974 set_cu_language (attr
->constant_value (0), cu
);
24977 cu
->language
= pretend_language
;
24978 cu
->language_defn
= language_def (cu
->language
);
24981 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
24987 dwarf2_per_objfile::get_cu (dwarf2_per_cu_data
*per_cu
)
24989 auto it
= m_dwarf2_cus
.find (per_cu
);
24990 if (it
== m_dwarf2_cus
.end ())
24999 dwarf2_per_objfile::set_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_cu
*cu
)
25001 gdb_assert (this->get_cu (per_cu
) == nullptr);
25003 m_dwarf2_cus
[per_cu
] = cu
;
25009 dwarf2_per_objfile::age_comp_units ()
25011 dwarf_read_debug_printf_v ("running");
25013 /* This is not expected to be called in the middle of CU expansion. There is
25014 an invariant that if a CU is in the CUs-to-expand queue, its DIEs are
25015 loaded in memory. Calling age_comp_units while the queue is in use could
25016 make us free the DIEs for a CU that is in the queue and therefore break
25018 gdb_assert (!this->per_bfd
->queue
.has_value ());
25020 /* Start by clearing all marks. */
25021 for (auto pair
: m_dwarf2_cus
)
25022 pair
.second
->mark
= false;
25024 /* Traverse all CUs, mark them and their dependencies if used recently
25026 for (auto pair
: m_dwarf2_cus
)
25028 dwarf2_cu
*cu
= pair
.second
;
25031 if (cu
->last_used
<= dwarf_max_cache_age
)
25035 /* Delete all CUs still not marked. */
25036 for (auto it
= m_dwarf2_cus
.begin (); it
!= m_dwarf2_cus
.end ();)
25038 dwarf2_cu
*cu
= it
->second
;
25042 dwarf_read_debug_printf_v ("deleting old CU %s",
25043 sect_offset_str (cu
->per_cu
->sect_off
));
25045 it
= m_dwarf2_cus
.erase (it
);
25055 dwarf2_per_objfile::remove_cu (dwarf2_per_cu_data
*per_cu
)
25057 auto it
= m_dwarf2_cus
.find (per_cu
);
25058 if (it
== m_dwarf2_cus
.end ())
25063 m_dwarf2_cus
.erase (it
);
25066 dwarf2_per_objfile::~dwarf2_per_objfile ()
25071 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
25072 We store these in a hash table separate from the DIEs, and preserve them
25073 when the DIEs are flushed out of cache.
25075 The CU "per_cu" pointer is needed because offset alone is not enough to
25076 uniquely identify the type. A file may have multiple .debug_types sections,
25077 or the type may come from a DWO file. Furthermore, while it's more logical
25078 to use per_cu->section+offset, with Fission the section with the data is in
25079 the DWO file but we don't know that section at the point we need it.
25080 We have to use something in dwarf2_per_cu_data (or the pointer to it)
25081 because we can enter the lookup routine, get_die_type_at_offset, from
25082 outside this file, and thus won't necessarily have PER_CU->cu.
25083 Fortunately, PER_CU is stable for the life of the objfile. */
25085 struct dwarf2_per_cu_offset_and_type
25087 const struct dwarf2_per_cu_data
*per_cu
;
25088 sect_offset sect_off
;
25092 /* Hash function for a dwarf2_per_cu_offset_and_type. */
25095 per_cu_offset_and_type_hash (const void *item
)
25097 const struct dwarf2_per_cu_offset_and_type
*ofs
25098 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
25100 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
25103 /* Equality function for a dwarf2_per_cu_offset_and_type. */
25106 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
25108 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
25109 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
25110 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
25111 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
25113 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
25114 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
25117 /* Set the type associated with DIE to TYPE. Save it in CU's hash
25118 table if necessary. For convenience, return TYPE.
25120 The DIEs reading must have careful ordering to:
25121 * Not cause infinite loops trying to read in DIEs as a prerequisite for
25122 reading current DIE.
25123 * Not trying to dereference contents of still incompletely read in types
25124 while reading in other DIEs.
25125 * Enable referencing still incompletely read in types just by a pointer to
25126 the type without accessing its fields.
25128 Therefore caller should follow these rules:
25129 * Try to fetch any prerequisite types we may need to build this DIE type
25130 before building the type and calling set_die_type.
25131 * After building type call set_die_type for current DIE as soon as
25132 possible before fetching more types to complete the current type.
25133 * Make the type as complete as possible before fetching more types. */
25135 static struct type
*
25136 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
25137 bool skip_data_location
)
25139 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
25140 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
25141 struct objfile
*objfile
= per_objfile
->objfile
;
25142 struct attribute
*attr
;
25143 struct dynamic_prop prop
;
25145 /* For Ada types, make sure that the gnat-specific data is always
25146 initialized (if not already set). There are a few types where
25147 we should not be doing so, because the type-specific area is
25148 already used to hold some other piece of info (eg: TYPE_CODE_FLT
25149 where the type-specific area is used to store the floatformat).
25150 But this is not a problem, because the gnat-specific information
25151 is actually not needed for these types. */
25152 if (need_gnat_info (cu
)
25153 && type
->code () != TYPE_CODE_FUNC
25154 && type
->code () != TYPE_CODE_FLT
25155 && type
->code () != TYPE_CODE_METHODPTR
25156 && type
->code () != TYPE_CODE_MEMBERPTR
25157 && type
->code () != TYPE_CODE_METHOD
25158 && type
->code () != TYPE_CODE_FIXED_POINT
25159 && !HAVE_GNAT_AUX_INFO (type
))
25160 INIT_GNAT_SPECIFIC (type
);
25162 /* Read DW_AT_allocated and set in type. */
25163 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
25166 struct type
*prop_type
= cu
->addr_sized_int_type (false);
25167 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
25168 type
->add_dyn_prop (DYN_PROP_ALLOCATED
, prop
);
25171 /* Read DW_AT_associated and set in type. */
25172 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
25175 struct type
*prop_type
= cu
->addr_sized_int_type (false);
25176 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
25177 type
->add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
);
25180 /* Read DW_AT_data_location and set in type. */
25181 if (!skip_data_location
)
25183 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
25184 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
25185 type
->add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
);
25188 if (per_objfile
->die_type_hash
== NULL
)
25189 per_objfile
->die_type_hash
25190 = htab_up (htab_create_alloc (127,
25191 per_cu_offset_and_type_hash
,
25192 per_cu_offset_and_type_eq
,
25193 NULL
, xcalloc
, xfree
));
25195 ofs
.per_cu
= cu
->per_cu
;
25196 ofs
.sect_off
= die
->sect_off
;
25198 slot
= (struct dwarf2_per_cu_offset_and_type
**)
25199 htab_find_slot (per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
25201 complaint (_("A problem internal to GDB: DIE %s has type already set"),
25202 sect_offset_str (die
->sect_off
));
25203 *slot
= XOBNEW (&objfile
->objfile_obstack
,
25204 struct dwarf2_per_cu_offset_and_type
);
25209 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
25210 or return NULL if the die does not have a saved type. */
25212 static struct type
*
25213 get_die_type_at_offset (sect_offset sect_off
,
25214 dwarf2_per_cu_data
*per_cu
,
25215 dwarf2_per_objfile
*per_objfile
)
25217 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
25219 if (per_objfile
->die_type_hash
== NULL
)
25222 ofs
.per_cu
= per_cu
;
25223 ofs
.sect_off
= sect_off
;
25224 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
25225 htab_find (per_objfile
->die_type_hash
.get (), &ofs
));
25232 /* Look up the type for DIE in CU in die_type_hash,
25233 or return NULL if DIE does not have a saved type. */
25235 static struct type
*
25236 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
25238 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
, cu
->per_objfile
);
25241 /* Add a dependence relationship from CU to REF_PER_CU. */
25244 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
25245 struct dwarf2_per_cu_data
*ref_per_cu
)
25249 if (cu
->dependencies
== NULL
)
25251 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
25252 NULL
, &cu
->comp_unit_obstack
,
25253 hashtab_obstack_allocate
,
25254 dummy_obstack_deallocate
);
25256 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
25258 *slot
= ref_per_cu
;
25261 /* Subroutine of dwarf2_mark to pass to htab_traverse.
25262 Set the mark field in every compilation unit in the
25263 cache that we must keep because we are keeping CU.
25265 DATA is the dwarf2_per_objfile object in which to look up CUs. */
25268 dwarf2_mark_helper (void **slot
, void *data
)
25270 dwarf2_per_cu_data
*per_cu
= (dwarf2_per_cu_data
*) *slot
;
25271 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) data
;
25272 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
25274 /* cu->dependencies references may not yet have been ever read if QUIT aborts
25275 reading of the chain. As such dependencies remain valid it is not much
25276 useful to track and undo them during QUIT cleanups. */
25285 if (cu
->dependencies
!= nullptr)
25286 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, per_objfile
);
25291 /* Set the mark field in CU and in every other compilation unit in the
25292 cache that we must keep because we are keeping CU. */
25295 dwarf2_mark (struct dwarf2_cu
*cu
)
25302 if (cu
->dependencies
!= nullptr)
25303 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, cu
->per_objfile
);
25306 /* Trivial hash function for partial_die_info: the hash value of a DIE
25307 is its offset in .debug_info for this objfile. */
25310 partial_die_hash (const void *item
)
25312 const struct partial_die_info
*part_die
25313 = (const struct partial_die_info
*) item
;
25315 return to_underlying (part_die
->sect_off
);
25318 /* Trivial comparison function for partial_die_info structures: two DIEs
25319 are equal if they have the same offset. */
25322 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
25324 const struct partial_die_info
*part_die_lhs
25325 = (const struct partial_die_info
*) item_lhs
;
25326 const struct partial_die_info
*part_die_rhs
25327 = (const struct partial_die_info
*) item_rhs
;
25329 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
25332 struct cmd_list_element
*set_dwarf_cmdlist
;
25333 struct cmd_list_element
*show_dwarf_cmdlist
;
25336 show_check_physname (struct ui_file
*file
, int from_tty
,
25337 struct cmd_list_element
*c
, const char *value
)
25339 fprintf_filtered (file
,
25340 _("Whether to check \"physname\" is %s.\n"),
25344 void _initialize_dwarf2_read ();
25346 _initialize_dwarf2_read ()
25348 add_basic_prefix_cmd ("dwarf", class_maintenance
, _("\
25349 Set DWARF specific variables.\n\
25350 Configure DWARF variables such as the cache size."),
25351 &set_dwarf_cmdlist
, "maintenance set dwarf ",
25352 0/*allow-unknown*/, &maintenance_set_cmdlist
);
25354 add_show_prefix_cmd ("dwarf", class_maintenance
, _("\
25355 Show DWARF specific variables.\n\
25356 Show DWARF variables such as the cache size."),
25357 &show_dwarf_cmdlist
, "maintenance show dwarf ",
25358 0/*allow-unknown*/, &maintenance_show_cmdlist
);
25360 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
25361 &dwarf_max_cache_age
, _("\
25362 Set the upper bound on the age of cached DWARF compilation units."), _("\
25363 Show the upper bound on the age of cached DWARF compilation units."), _("\
25364 A higher limit means that cached compilation units will be stored\n\
25365 in memory longer, and more total memory will be used. Zero disables\n\
25366 caching, which can slow down startup."),
25368 show_dwarf_max_cache_age
,
25369 &set_dwarf_cmdlist
,
25370 &show_dwarf_cmdlist
);
25372 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
25373 Set debugging of the DWARF reader."), _("\
25374 Show debugging of the DWARF reader."), _("\
25375 When enabled (non-zero), debugging messages are printed during DWARF\n\
25376 reading and symtab expansion. A value of 1 (one) provides basic\n\
25377 information. A value greater than 1 provides more verbose information."),
25380 &setdebuglist
, &showdebuglist
);
25382 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
25383 Set debugging of the DWARF DIE reader."), _("\
25384 Show debugging of the DWARF DIE reader."), _("\
25385 When enabled (non-zero), DIEs are dumped after they are read in.\n\
25386 The value is the maximum depth to print."),
25389 &setdebuglist
, &showdebuglist
);
25391 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
25392 Set debugging of the dwarf line reader."), _("\
25393 Show debugging of the dwarf line reader."), _("\
25394 When enabled (non-zero), line number entries are dumped as they are read in.\n\
25395 A value of 1 (one) provides basic information.\n\
25396 A value greater than 1 provides more verbose information."),
25399 &setdebuglist
, &showdebuglist
);
25401 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
25402 Set cross-checking of \"physname\" code against demangler."), _("\
25403 Show cross-checking of \"physname\" code against demangler."), _("\
25404 When enabled, GDB's internal \"physname\" code is checked against\n\
25406 NULL
, show_check_physname
,
25407 &setdebuglist
, &showdebuglist
);
25409 add_setshow_boolean_cmd ("use-deprecated-index-sections",
25410 no_class
, &use_deprecated_index_sections
, _("\
25411 Set whether to use deprecated gdb_index sections."), _("\
25412 Show whether to use deprecated gdb_index sections."), _("\
25413 When enabled, deprecated .gdb_index sections are used anyway.\n\
25414 Normally they are ignored either because of a missing feature or\n\
25415 performance issue.\n\
25416 Warning: This option must be enabled before gdb reads the file."),
25419 &setlist
, &showlist
);
25421 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
25422 &dwarf2_locexpr_funcs
);
25423 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
25424 &dwarf2_loclist_funcs
);
25426 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
25427 &dwarf2_block_frame_base_locexpr_funcs
);
25428 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
25429 &dwarf2_block_frame_base_loclist_funcs
);
25432 selftests::register_test ("dw2_expand_symtabs_matching",
25433 selftests::dw2_expand_symtabs_matching::run_test
);
25434 selftests::register_test ("dwarf2_find_containing_comp_unit",
25435 selftests::find_containing_comp_unit::run_test
);