1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2020 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/index-cache.h"
36 #include "dwarf2/index-common.h"
37 #include "dwarf2/leb.h"
46 #include "gdb-demangle.h"
47 #include "filenames.h" /* for DOSish file names */
50 #include "complaints.h"
51 #include "dwarf2/expr.h"
52 #include "dwarf2/loc.h"
53 #include "cp-support.h"
59 #include "typeprint.h"
64 #include "gdbcore.h" /* for gnutarget */
65 #include "gdb/gdb-index.h"
70 #include "namespace.h"
71 #include "gdbsupport/function-view.h"
72 #include "gdbsupport/gdb_optional.h"
73 #include "gdbsupport/underlying.h"
74 #include "gdbsupport/hash_enum.h"
75 #include "filename-seen-cache.h"
79 #include <unordered_map>
80 #include "gdbsupport/selftest.h"
81 #include "rust-lang.h"
82 #include "gdbsupport/pathstuff.h"
84 /* When == 1, print basic high level tracing messages.
85 When > 1, be more verbose.
86 This is in contrast to the low level DIE reading of dwarf_die_debug. */
87 static unsigned int dwarf_read_debug
= 0;
89 /* When non-zero, dump DIEs after they are read in. */
90 static unsigned int dwarf_die_debug
= 0;
92 /* When non-zero, dump line number entries as they are read in. */
93 static unsigned int dwarf_line_debug
= 0;
95 /* When true, cross-check physname against demangler. */
96 static bool check_physname
= false;
98 /* When true, do not reject deprecated .gdb_index sections. */
99 static bool use_deprecated_index_sections
= false;
101 static const struct objfile_key
<dwarf2_per_objfile
> dwarf2_objfile_data_key
;
103 /* The "aclass" indices for various kinds of computed DWARF symbols. */
105 static int dwarf2_locexpr_index
;
106 static int dwarf2_loclist_index
;
107 static int dwarf2_locexpr_block_index
;
108 static int dwarf2_loclist_block_index
;
110 /* An index into a (C++) symbol name component in a symbol name as
111 recorded in the mapped_index's symbol table. For each C++ symbol
112 in the symbol table, we record one entry for the start of each
113 component in the symbol in a table of name components, and then
114 sort the table, in order to be able to binary search symbol names,
115 ignoring leading namespaces, both completion and regular look up.
116 For example, for symbol "A::B::C", we'll have an entry that points
117 to "A::B::C", another that points to "B::C", and another for "C".
118 Note that function symbols in GDB index have no parameter
119 information, just the function/method names. You can convert a
120 name_component to a "const char *" using the
121 'mapped_index::symbol_name_at(offset_type)' method. */
123 struct name_component
125 /* Offset in the symbol name where the component starts. Stored as
126 a (32-bit) offset instead of a pointer to save memory and improve
127 locality on 64-bit architectures. */
128 offset_type name_offset
;
130 /* The symbol's index in the symbol and constant pool tables of a
135 /* Base class containing bits shared by both .gdb_index and
136 .debug_name indexes. */
138 struct mapped_index_base
140 mapped_index_base () = default;
141 DISABLE_COPY_AND_ASSIGN (mapped_index_base
);
143 /* The name_component table (a sorted vector). See name_component's
144 description above. */
145 std::vector
<name_component
> name_components
;
147 /* How NAME_COMPONENTS is sorted. */
148 enum case_sensitivity name_components_casing
;
150 /* Return the number of names in the symbol table. */
151 virtual size_t symbol_name_count () const = 0;
153 /* Get the name of the symbol at IDX in the symbol table. */
154 virtual const char *symbol_name_at (offset_type idx
) const = 0;
156 /* Return whether the name at IDX in the symbol table should be
158 virtual bool symbol_name_slot_invalid (offset_type idx
) const
163 /* Build the symbol name component sorted vector, if we haven't
165 void build_name_components ();
167 /* Returns the lower (inclusive) and upper (exclusive) bounds of the
168 possible matches for LN_NO_PARAMS in the name component
170 std::pair
<std::vector
<name_component
>::const_iterator
,
171 std::vector
<name_component
>::const_iterator
>
172 find_name_components_bounds (const lookup_name_info
&ln_no_params
,
173 enum language lang
) const;
175 /* Prevent deleting/destroying via a base class pointer. */
177 ~mapped_index_base() = default;
180 /* A description of the mapped index. The file format is described in
181 a comment by the code that writes the index. */
182 struct mapped_index final
: public mapped_index_base
184 /* A slot/bucket in the symbol table hash. */
185 struct symbol_table_slot
187 const offset_type name
;
188 const offset_type vec
;
191 /* Index data format version. */
194 /* The address table data. */
195 gdb::array_view
<const gdb_byte
> address_table
;
197 /* The symbol table, implemented as a hash table. */
198 gdb::array_view
<symbol_table_slot
> symbol_table
;
200 /* A pointer to the constant pool. */
201 const char *constant_pool
= nullptr;
203 bool symbol_name_slot_invalid (offset_type idx
) const override
205 const auto &bucket
= this->symbol_table
[idx
];
206 return bucket
.name
== 0 && bucket
.vec
== 0;
209 /* Convenience method to get at the name of the symbol at IDX in the
211 const char *symbol_name_at (offset_type idx
) const override
212 { return this->constant_pool
+ MAYBE_SWAP (this->symbol_table
[idx
].name
); }
214 size_t symbol_name_count () const override
215 { return this->symbol_table
.size (); }
218 /* A description of the mapped .debug_names.
219 Uninitialized map has CU_COUNT 0. */
220 struct mapped_debug_names final
: public mapped_index_base
222 mapped_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile_
)
223 : dwarf2_per_objfile (dwarf2_per_objfile_
)
226 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
227 bfd_endian dwarf5_byte_order
;
228 bool dwarf5_is_dwarf64
;
229 bool augmentation_is_gdb
;
231 uint32_t cu_count
= 0;
232 uint32_t tu_count
, bucket_count
, name_count
;
233 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
234 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
235 const gdb_byte
*name_table_string_offs_reordered
;
236 const gdb_byte
*name_table_entry_offs_reordered
;
237 const gdb_byte
*entry_pool
;
244 /* Attribute name DW_IDX_*. */
247 /* Attribute form DW_FORM_*. */
250 /* Value if FORM is DW_FORM_implicit_const. */
251 LONGEST implicit_const
;
253 std::vector
<attr
> attr_vec
;
256 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
258 const char *namei_to_name (uint32_t namei
) const;
260 /* Implementation of the mapped_index_base virtual interface, for
261 the name_components cache. */
263 const char *symbol_name_at (offset_type idx
) const override
264 { return namei_to_name (idx
); }
266 size_t symbol_name_count () const override
267 { return this->name_count
; }
270 /* See dwarf2read.h. */
273 get_dwarf2_per_objfile (struct objfile
*objfile
)
275 return dwarf2_objfile_data_key
.get (objfile
);
278 /* Default names of the debugging sections. */
280 /* Note that if the debugging section has been compressed, it might
281 have a name like .zdebug_info. */
283 static const struct dwarf2_debug_sections dwarf2_elf_names
=
285 { ".debug_info", ".zdebug_info" },
286 { ".debug_abbrev", ".zdebug_abbrev" },
287 { ".debug_line", ".zdebug_line" },
288 { ".debug_loc", ".zdebug_loc" },
289 { ".debug_loclists", ".zdebug_loclists" },
290 { ".debug_macinfo", ".zdebug_macinfo" },
291 { ".debug_macro", ".zdebug_macro" },
292 { ".debug_str", ".zdebug_str" },
293 { ".debug_str_offsets", ".zdebug_str_offsets" },
294 { ".debug_line_str", ".zdebug_line_str" },
295 { ".debug_ranges", ".zdebug_ranges" },
296 { ".debug_rnglists", ".zdebug_rnglists" },
297 { ".debug_types", ".zdebug_types" },
298 { ".debug_addr", ".zdebug_addr" },
299 { ".debug_frame", ".zdebug_frame" },
300 { ".eh_frame", NULL
},
301 { ".gdb_index", ".zgdb_index" },
302 { ".debug_names", ".zdebug_names" },
303 { ".debug_aranges", ".zdebug_aranges" },
307 /* List of DWO/DWP sections. */
309 static const struct dwop_section_names
311 struct dwarf2_section_names abbrev_dwo
;
312 struct dwarf2_section_names info_dwo
;
313 struct dwarf2_section_names line_dwo
;
314 struct dwarf2_section_names loc_dwo
;
315 struct dwarf2_section_names loclists_dwo
;
316 struct dwarf2_section_names macinfo_dwo
;
317 struct dwarf2_section_names macro_dwo
;
318 struct dwarf2_section_names str_dwo
;
319 struct dwarf2_section_names str_offsets_dwo
;
320 struct dwarf2_section_names types_dwo
;
321 struct dwarf2_section_names cu_index
;
322 struct dwarf2_section_names tu_index
;
326 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
327 { ".debug_info.dwo", ".zdebug_info.dwo" },
328 { ".debug_line.dwo", ".zdebug_line.dwo" },
329 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
330 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
331 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
332 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
333 { ".debug_str.dwo", ".zdebug_str.dwo" },
334 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
335 { ".debug_types.dwo", ".zdebug_types.dwo" },
336 { ".debug_cu_index", ".zdebug_cu_index" },
337 { ".debug_tu_index", ".zdebug_tu_index" },
340 /* local data types */
342 /* The data in a compilation unit header, after target2host
343 translation, looks like this. */
344 struct comp_unit_head
348 unsigned char addr_size
;
349 unsigned char signed_addr_p
;
350 sect_offset abbrev_sect_off
;
352 /* Size of file offsets; either 4 or 8. */
353 unsigned int offset_size
;
355 /* Size of the length field; either 4 or 12. */
356 unsigned int initial_length_size
;
358 enum dwarf_unit_type unit_type
;
360 /* Offset to the first byte of this compilation unit header in the
361 .debug_info section, for resolving relative reference dies. */
362 sect_offset sect_off
;
364 /* Offset to first die in this cu from the start of the cu.
365 This will be the first byte following the compilation unit header. */
366 cu_offset first_die_cu_offset
;
369 /* 64-bit signature of this unit. For type units, it denotes the signature of
370 the type (DW_UT_type in DWARF 4, additionally DW_UT_split_type in DWARF 5).
371 Also used in DWARF 5, to denote the dwo id when the unit type is
372 DW_UT_skeleton or DW_UT_split_compile. */
375 /* For types, offset in the type's DIE of the type defined by this TU. */
376 cu_offset type_cu_offset_in_tu
;
379 /* Type used for delaying computation of method physnames.
380 See comments for compute_delayed_physnames. */
381 struct delayed_method_info
383 /* The type to which the method is attached, i.e., its parent class. */
386 /* The index of the method in the type's function fieldlists. */
389 /* The index of the method in the fieldlist. */
392 /* The name of the DIE. */
395 /* The DIE associated with this method. */
396 struct die_info
*die
;
399 /* Internal state when decoding a particular compilation unit. */
402 explicit dwarf2_cu (struct dwarf2_per_cu_data
*per_cu
);
405 DISABLE_COPY_AND_ASSIGN (dwarf2_cu
);
407 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
408 Create the set of symtabs used by this TU, or if this TU is sharing
409 symtabs with another TU and the symtabs have already been created
410 then restore those symtabs in the line header.
411 We don't need the pc/line-number mapping for type units. */
412 void setup_type_unit_groups (struct die_info
*die
);
414 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
415 buildsym_compunit constructor. */
416 struct compunit_symtab
*start_symtab (const char *name
,
417 const char *comp_dir
,
420 /* Reset the builder. */
421 void reset_builder () { m_builder
.reset (); }
423 /* The header of the compilation unit. */
424 struct comp_unit_head header
{};
426 /* Base address of this compilation unit. */
427 CORE_ADDR base_address
= 0;
429 /* Non-zero if base_address has been set. */
432 /* The language we are debugging. */
433 enum language language
= language_unknown
;
434 const struct language_defn
*language_defn
= nullptr;
436 const char *producer
= nullptr;
439 /* The symtab builder for this CU. This is only non-NULL when full
440 symbols are being read. */
441 std::unique_ptr
<buildsym_compunit
> m_builder
;
444 /* The generic symbol table building routines have separate lists for
445 file scope symbols and all all other scopes (local scopes). So
446 we need to select the right one to pass to add_symbol_to_list().
447 We do it by keeping a pointer to the correct list in list_in_scope.
449 FIXME: The original dwarf code just treated the file scope as the
450 first local scope, and all other local scopes as nested local
451 scopes, and worked fine. Check to see if we really need to
452 distinguish these in buildsym.c. */
453 struct pending
**list_in_scope
= nullptr;
455 /* Hash table holding all the loaded partial DIEs
456 with partial_die->offset.SECT_OFF as hash. */
457 htab_t partial_dies
= nullptr;
459 /* Storage for things with the same lifetime as this read-in compilation
460 unit, including partial DIEs. */
461 auto_obstack comp_unit_obstack
;
463 /* When multiple dwarf2_cu structures are living in memory, this field
464 chains them all together, so that they can be released efficiently.
465 We will probably also want a generation counter so that most-recently-used
466 compilation units are cached... */
467 struct dwarf2_per_cu_data
*read_in_chain
= nullptr;
469 /* Backlink to our per_cu entry. */
470 struct dwarf2_per_cu_data
*per_cu
;
472 /* How many compilation units ago was this CU last referenced? */
475 /* A hash table of DIE cu_offset for following references with
476 die_info->offset.sect_off as hash. */
477 htab_t die_hash
= nullptr;
479 /* Full DIEs if read in. */
480 struct die_info
*dies
= nullptr;
482 /* A set of pointers to dwarf2_per_cu_data objects for compilation
483 units referenced by this one. Only set during full symbol processing;
484 partial symbol tables do not have dependencies. */
485 htab_t dependencies
= nullptr;
487 /* Header data from the line table, during full symbol processing. */
488 struct line_header
*line_header
= nullptr;
489 /* Non-NULL if LINE_HEADER is owned by this DWARF_CU. Otherwise,
490 it's owned by dwarf2_per_objfile::line_header_hash. If non-NULL,
491 this is the DW_TAG_compile_unit die for this CU. We'll hold on
492 to the line header as long as this DIE is being processed. See
493 process_die_scope. */
494 die_info
*line_header_die_owner
= nullptr;
496 /* A list of methods which need to have physnames computed
497 after all type information has been read. */
498 std::vector
<delayed_method_info
> method_list
;
500 /* To be copied to symtab->call_site_htab. */
501 htab_t call_site_htab
= nullptr;
503 /* Non-NULL if this CU came from a DWO file.
504 There is an invariant here that is important to remember:
505 Except for attributes copied from the top level DIE in the "main"
506 (or "stub") file in preparation for reading the DWO file
507 (e.g., DW_AT_addr_base), we KISS: there is only *one* CU.
508 Either there isn't a DWO file (in which case this is NULL and the point
509 is moot), or there is and either we're not going to read it (in which
510 case this is NULL) or there is and we are reading it (in which case this
512 struct dwo_unit
*dwo_unit
= nullptr;
514 /* The DW_AT_addr_base (DW_AT_GNU_addr_base) attribute if present.
515 Note this value comes from the Fission stub CU/TU's DIE. */
516 gdb::optional
<ULONGEST
> addr_base
;
518 /* The DW_AT_rnglists_base attribute if present.
519 Note this value comes from the Fission stub CU/TU's DIE.
520 Also note that the value is zero in the non-DWO case so this value can
521 be used without needing to know whether DWO files are in use or not.
522 N.B. This does not apply to DW_AT_ranges appearing in
523 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
524 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
525 DW_AT_rnglists_base *would* have to be applied, and we'd have to care
526 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
527 ULONGEST ranges_base
= 0;
529 /* When reading debug info generated by older versions of rustc, we
530 have to rewrite some union types to be struct types with a
531 variant part. This rewriting must be done after the CU is fully
532 read in, because otherwise at the point of rewriting some struct
533 type might not have been fully processed. So, we keep a list of
534 all such types here and process them after expansion. */
535 std::vector
<struct type
*> rust_unions
;
537 /* The DW_AT_str_offsets_base attribute if present. For DWARF 4 version DWO
538 files, the value is implicitly zero. For DWARF 5 version DWO files, the
539 value is often implicit and is the size of the header of
540 .debug_str_offsets section (8 or 4, depending on the address size). */
541 gdb::optional
<ULONGEST
> str_offsets_base
;
543 /* Mark used when releasing cached dies. */
546 /* This CU references .debug_loc. See the symtab->locations_valid field.
547 This test is imperfect as there may exist optimized debug code not using
548 any location list and still facing inlining issues if handled as
549 unoptimized code. For a future better test see GCC PR other/32998. */
550 bool has_loclist
: 1;
552 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is true
553 if all the producer_is_* fields are valid. This information is cached
554 because profiling CU expansion showed excessive time spent in
555 producer_is_gxx_lt_4_6. */
556 bool checked_producer
: 1;
557 bool producer_is_gxx_lt_4_6
: 1;
558 bool producer_is_gcc_lt_4_3
: 1;
559 bool producer_is_icc
: 1;
560 bool producer_is_icc_lt_14
: 1;
561 bool producer_is_codewarrior
: 1;
563 /* When true, the file that we're processing is known to have
564 debugging info for C++ namespaces. GCC 3.3.x did not produce
565 this information, but later versions do. */
567 bool processing_has_namespace_info
: 1;
569 struct partial_die_info
*find_partial_die (sect_offset sect_off
);
571 /* If this CU was inherited by another CU (via specification,
572 abstract_origin, etc), this is the ancestor CU. */
575 /* Get the buildsym_compunit for this CU. */
576 buildsym_compunit
*get_builder ()
578 /* If this CU has a builder associated with it, use that. */
579 if (m_builder
!= nullptr)
580 return m_builder
.get ();
582 /* Otherwise, search ancestors for a valid builder. */
583 if (ancestor
!= nullptr)
584 return ancestor
->get_builder ();
590 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
591 This includes type_unit_group and quick_file_names. */
593 struct stmt_list_hash
595 /* The DWO unit this table is from or NULL if there is none. */
596 struct dwo_unit
*dwo_unit
;
598 /* Offset in .debug_line or .debug_line.dwo. */
599 sect_offset line_sect_off
;
602 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
603 an object of this type. */
605 struct type_unit_group
607 /* dwarf2read.c's main "handle" on a TU symtab.
608 To simplify things we create an artificial CU that "includes" all the
609 type units using this stmt_list so that the rest of the code still has
610 a "per_cu" handle on the symtab.
611 This PER_CU is recognized by having no section. */
612 #define IS_TYPE_UNIT_GROUP(per_cu) ((per_cu)->section == NULL)
613 struct dwarf2_per_cu_data per_cu
;
615 /* The TUs that share this DW_AT_stmt_list entry.
616 This is added to while parsing type units to build partial symtabs,
617 and is deleted afterwards and not used again. */
618 std::vector
<signatured_type
*> *tus
;
620 /* The compunit symtab.
621 Type units in a group needn't all be defined in the same source file,
622 so we create an essentially anonymous symtab as the compunit symtab. */
623 struct compunit_symtab
*compunit_symtab
;
625 /* The data used to construct the hash key. */
626 struct stmt_list_hash hash
;
628 /* The number of symtabs from the line header.
629 The value here must match line_header.num_file_names. */
630 unsigned int num_symtabs
;
632 /* The symbol tables for this TU (obtained from the files listed in
634 WARNING: The order of entries here must match the order of entries
635 in the line header. After the first TU using this type_unit_group, the
636 line header for the subsequent TUs is recreated from this. This is done
637 because we need to use the same symtabs for each TU using the same
638 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
639 there's no guarantee the line header doesn't have duplicate entries. */
640 struct symtab
**symtabs
;
643 /* These sections are what may appear in a (real or virtual) DWO file. */
647 struct dwarf2_section_info abbrev
;
648 struct dwarf2_section_info line
;
649 struct dwarf2_section_info loc
;
650 struct dwarf2_section_info loclists
;
651 struct dwarf2_section_info macinfo
;
652 struct dwarf2_section_info macro
;
653 struct dwarf2_section_info str
;
654 struct dwarf2_section_info str_offsets
;
655 /* In the case of a virtual DWO file, these two are unused. */
656 struct dwarf2_section_info info
;
657 std::vector
<dwarf2_section_info
> types
;
660 /* CUs/TUs in DWP/DWO files. */
664 /* Backlink to the containing struct dwo_file. */
665 struct dwo_file
*dwo_file
;
667 /* The "id" that distinguishes this CU/TU.
668 .debug_info calls this "dwo_id", .debug_types calls this "signature".
669 Since signatures came first, we stick with it for consistency. */
672 /* The section this CU/TU lives in, in the DWO file. */
673 struct dwarf2_section_info
*section
;
675 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
676 sect_offset sect_off
;
679 /* For types, offset in the type's DIE of the type defined by this TU. */
680 cu_offset type_offset_in_tu
;
683 /* include/dwarf2.h defines the DWP section codes.
684 It defines a max value but it doesn't define a min value, which we
685 use for error checking, so provide one. */
687 enum dwp_v2_section_ids
692 /* Data for one DWO file.
694 This includes virtual DWO files (a virtual DWO file is a DWO file as it
695 appears in a DWP file). DWP files don't really have DWO files per se -
696 comdat folding of types "loses" the DWO file they came from, and from
697 a high level view DWP files appear to contain a mass of random types.
698 However, to maintain consistency with the non-DWP case we pretend DWP
699 files contain virtual DWO files, and we assign each TU with one virtual
700 DWO file (generally based on the line and abbrev section offsets -
701 a heuristic that seems to work in practice). */
705 dwo_file () = default;
706 DISABLE_COPY_AND_ASSIGN (dwo_file
);
708 /* The DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute.
709 For virtual DWO files the name is constructed from the section offsets
710 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
711 from related CU+TUs. */
712 const char *dwo_name
= nullptr;
714 /* The DW_AT_comp_dir attribute. */
715 const char *comp_dir
= nullptr;
717 /* The bfd, when the file is open. Otherwise this is NULL.
718 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
719 gdb_bfd_ref_ptr dbfd
;
721 /* The sections that make up this DWO file.
722 Remember that for virtual DWO files in DWP V2, these are virtual
723 sections (for lack of a better name). */
724 struct dwo_sections sections
{};
726 /* The CUs in the file.
727 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
728 an extension to handle LLVM's Link Time Optimization output (where
729 multiple source files may be compiled into a single object/dwo pair). */
732 /* Table of TUs in the file.
733 Each element is a struct dwo_unit. */
737 /* These sections are what may appear in a DWP file. */
741 /* These are used by both DWP version 1 and 2. */
742 struct dwarf2_section_info str
;
743 struct dwarf2_section_info cu_index
;
744 struct dwarf2_section_info tu_index
;
746 /* These are only used by DWP version 2 files.
747 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
748 sections are referenced by section number, and are not recorded here.
749 In DWP version 2 there is at most one copy of all these sections, each
750 section being (effectively) comprised of the concatenation of all of the
751 individual sections that exist in the version 1 format.
752 To keep the code simple we treat each of these concatenated pieces as a
753 section itself (a virtual section?). */
754 struct dwarf2_section_info abbrev
;
755 struct dwarf2_section_info info
;
756 struct dwarf2_section_info line
;
757 struct dwarf2_section_info loc
;
758 struct dwarf2_section_info macinfo
;
759 struct dwarf2_section_info macro
;
760 struct dwarf2_section_info str_offsets
;
761 struct dwarf2_section_info types
;
764 /* These sections are what may appear in a virtual DWO file in DWP version 1.
765 A virtual DWO file is a DWO file as it appears in a DWP file. */
767 struct virtual_v1_dwo_sections
769 struct dwarf2_section_info abbrev
;
770 struct dwarf2_section_info line
;
771 struct dwarf2_section_info loc
;
772 struct dwarf2_section_info macinfo
;
773 struct dwarf2_section_info macro
;
774 struct dwarf2_section_info str_offsets
;
775 /* Each DWP hash table entry records one CU or one TU.
776 That is recorded here, and copied to dwo_unit.section. */
777 struct dwarf2_section_info info_or_types
;
780 /* Similar to virtual_v1_dwo_sections, but for DWP version 2.
781 In version 2, the sections of the DWO files are concatenated together
782 and stored in one section of that name. Thus each ELF section contains
783 several "virtual" sections. */
785 struct virtual_v2_dwo_sections
787 bfd_size_type abbrev_offset
;
788 bfd_size_type abbrev_size
;
790 bfd_size_type line_offset
;
791 bfd_size_type line_size
;
793 bfd_size_type loc_offset
;
794 bfd_size_type loc_size
;
796 bfd_size_type macinfo_offset
;
797 bfd_size_type macinfo_size
;
799 bfd_size_type macro_offset
;
800 bfd_size_type macro_size
;
802 bfd_size_type str_offsets_offset
;
803 bfd_size_type str_offsets_size
;
805 /* Each DWP hash table entry records one CU or one TU.
806 That is recorded here, and copied to dwo_unit.section. */
807 bfd_size_type info_or_types_offset
;
808 bfd_size_type info_or_types_size
;
811 /* Contents of DWP hash tables. */
813 struct dwp_hash_table
815 uint32_t version
, nr_columns
;
816 uint32_t nr_units
, nr_slots
;
817 const gdb_byte
*hash_table
, *unit_table
;
822 const gdb_byte
*indices
;
826 /* This is indexed by column number and gives the id of the section
828 #define MAX_NR_V2_DWO_SECTIONS \
829 (1 /* .debug_info or .debug_types */ \
830 + 1 /* .debug_abbrev */ \
831 + 1 /* .debug_line */ \
832 + 1 /* .debug_loc */ \
833 + 1 /* .debug_str_offsets */ \
834 + 1 /* .debug_macro or .debug_macinfo */)
835 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
836 const gdb_byte
*offsets
;
837 const gdb_byte
*sizes
;
842 /* Data for one DWP file. */
846 dwp_file (const char *name_
, gdb_bfd_ref_ptr
&&abfd
)
848 dbfd (std::move (abfd
))
852 /* Name of the file. */
855 /* File format version. */
859 gdb_bfd_ref_ptr dbfd
;
861 /* Section info for this file. */
862 struct dwp_sections sections
{};
864 /* Table of CUs in the file. */
865 const struct dwp_hash_table
*cus
= nullptr;
867 /* Table of TUs in the file. */
868 const struct dwp_hash_table
*tus
= nullptr;
870 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
874 /* Table to map ELF section numbers to their sections.
875 This is only needed for the DWP V1 file format. */
876 unsigned int num_sections
= 0;
877 asection
**elf_sections
= nullptr;
880 /* Struct used to pass misc. parameters to read_die_and_children, et
881 al. which are used for both .debug_info and .debug_types dies.
882 All parameters here are unchanging for the life of the call. This
883 struct exists to abstract away the constant parameters of die reading. */
885 struct die_reader_specs
887 /* The bfd of die_section. */
890 /* The CU of the DIE we are parsing. */
891 struct dwarf2_cu
*cu
;
893 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
894 struct dwo_file
*dwo_file
;
896 /* The section the die comes from.
897 This is either .debug_info or .debug_types, or the .dwo variants. */
898 struct dwarf2_section_info
*die_section
;
900 /* die_section->buffer. */
901 const gdb_byte
*buffer
;
903 /* The end of the buffer. */
904 const gdb_byte
*buffer_end
;
906 /* The abbreviation table to use when reading the DIEs. */
907 struct abbrev_table
*abbrev_table
;
910 /* A subclass of die_reader_specs that holds storage and has complex
911 constructor and destructor behavior. */
913 class cutu_reader
: public die_reader_specs
917 cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
918 struct abbrev_table
*abbrev_table
,
919 int use_existing_cu
, int keep
,
922 explicit cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
923 struct dwarf2_cu
*parent_cu
= nullptr,
924 struct dwo_file
*dwo_file
= nullptr);
928 DISABLE_COPY_AND_ASSIGN (cutu_reader
);
930 const gdb_byte
*info_ptr
= nullptr;
931 struct die_info
*comp_unit_die
= nullptr;
932 bool dummy_p
= false;
935 void init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
936 int use_existing_cu
, int keep
);
938 struct dwarf2_per_cu_data
*m_this_cu
;
940 std::unique_ptr
<dwarf2_cu
> m_new_cu
;
942 /* The ordinary abbreviation table. */
943 abbrev_table_up m_abbrev_table_holder
;
945 /* The DWO abbreviation table. */
946 abbrev_table_up m_dwo_abbrev_table
;
949 /* dir_index is 1-based in DWARF 4 and before, and is 0-based in DWARF 5 and
951 typedef int dir_index
;
953 /* file_name_index is 1-based in DWARF 4 and before, and is 0-based in DWARF 5
955 typedef int file_name_index
;
959 file_entry () = default;
961 file_entry (const char *name_
, dir_index d_index_
,
962 unsigned int mod_time_
, unsigned int length_
)
965 mod_time (mod_time_
),
969 /* Return the include directory at D_INDEX stored in LH. Returns
970 NULL if D_INDEX is out of bounds. */
971 const char *include_dir (const line_header
*lh
) const;
973 /* The file name. Note this is an observing pointer. The memory is
974 owned by debug_line_buffer. */
977 /* The directory index (1-based). */
978 dir_index d_index
{};
980 unsigned int mod_time
{};
982 unsigned int length
{};
984 /* True if referenced by the Line Number Program. */
987 /* The associated symbol table, if any. */
988 struct symtab
*symtab
{};
991 /* The line number information for a compilation unit (found in the
992 .debug_line section) begins with a "statement program header",
993 which contains the following information. */
1000 /* Add an entry to the include directory table. */
1001 void add_include_dir (const char *include_dir
);
1003 /* Add an entry to the file name table. */
1004 void add_file_name (const char *name
, dir_index d_index
,
1005 unsigned int mod_time
, unsigned int length
);
1007 /* Return the include dir at INDEX (0-based in DWARF 5 and 1-based before).
1008 Returns NULL if INDEX is out of bounds. */
1009 const char *include_dir_at (dir_index index
) const
1015 vec_index
= index
- 1;
1016 if (vec_index
< 0 || vec_index
>= m_include_dirs
.size ())
1018 return m_include_dirs
[vec_index
];
1021 bool is_valid_file_index (int file_index
)
1024 return 0 <= file_index
&& file_index
< file_names_size ();
1025 return 1 <= file_index
&& file_index
<= file_names_size ();
1028 /* Return the file name at INDEX (0-based in DWARF 5 and 1-based before).
1029 Returns NULL if INDEX is out of bounds. */
1030 file_entry
*file_name_at (file_name_index index
)
1036 vec_index
= index
- 1;
1037 if (vec_index
< 0 || vec_index
>= m_file_names
.size ())
1039 return &m_file_names
[vec_index
];
1042 /* The indexes are 0-based in DWARF 5 and 1-based in DWARF 4. Therefore,
1043 this method should only be used to iterate through all file entries in an
1044 index-agnostic manner. */
1045 std::vector
<file_entry
> &file_names ()
1046 { return m_file_names
; }
1048 /* Offset of line number information in .debug_line section. */
1049 sect_offset sect_off
{};
1051 /* OFFSET is for struct dwz_file associated with dwarf2_per_objfile. */
1052 unsigned offset_in_dwz
: 1; /* Can't initialize bitfields in-class. */
1054 unsigned int total_length
{};
1055 unsigned short version
{};
1056 unsigned int header_length
{};
1057 unsigned char minimum_instruction_length
{};
1058 unsigned char maximum_ops_per_instruction
{};
1059 unsigned char default_is_stmt
{};
1061 unsigned char line_range
{};
1062 unsigned char opcode_base
{};
1064 /* standard_opcode_lengths[i] is the number of operands for the
1065 standard opcode whose value is i. This means that
1066 standard_opcode_lengths[0] is unused, and the last meaningful
1067 element is standard_opcode_lengths[opcode_base - 1]. */
1068 std::unique_ptr
<unsigned char[]> standard_opcode_lengths
;
1070 int file_names_size ()
1071 { return m_file_names
.size(); }
1073 /* The start and end of the statement program following this
1074 header. These point into dwarf2_per_objfile->line_buffer. */
1075 const gdb_byte
*statement_program_start
{}, *statement_program_end
{};
1077 /* Return the full name of file number I in this object's file name
1078 table. Use COMP_DIR as the name of the current directory of the
1079 compilation. The result is allocated using xmalloc; the caller
1080 is responsible for freeing it. */
1081 gdb::unique_xmalloc_ptr
<char> file_full_name (int file
,
1082 const char *comp_dir
);
1084 /* Return file name relative to the compilation directory of file
1085 number I in this object's file name table. The result is
1086 allocated using xmalloc; the caller is responsible for freeing
1088 gdb::unique_xmalloc_ptr
<char> file_file_name (int file
);
1091 /* The include_directories table. Note these are observing
1092 pointers. The memory is owned by debug_line_buffer. */
1093 std::vector
<const char *> m_include_dirs
;
1095 /* The file_names table. This is private because the meaning of indexes
1096 differs among DWARF versions (The first valid index is 1 in DWARF 4 and
1097 before, and is 0 in DWARF 5 and later). So the client should use
1098 file_name_at method for access. */
1099 std::vector
<file_entry
> m_file_names
;
1102 typedef std::unique_ptr
<line_header
> line_header_up
;
1105 file_entry::include_dir (const line_header
*lh
) const
1107 return lh
->include_dir_at (d_index
);
1110 /* When we construct a partial symbol table entry we only
1111 need this much information. */
1112 struct partial_die_info
: public allocate_on_obstack
1114 partial_die_info (sect_offset sect_off
, struct abbrev_info
*abbrev
);
1116 /* Disable assign but still keep copy ctor, which is needed
1117 load_partial_dies. */
1118 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
1120 /* Adjust the partial die before generating a symbol for it. This
1121 function may set the is_external flag or change the DIE's
1123 void fixup (struct dwarf2_cu
*cu
);
1125 /* Read a minimal amount of information into the minimal die
1127 const gdb_byte
*read (const struct die_reader_specs
*reader
,
1128 const struct abbrev_info
&abbrev
,
1129 const gdb_byte
*info_ptr
);
1131 /* Offset of this DIE. */
1132 const sect_offset sect_off
;
1134 /* DWARF-2 tag for this DIE. */
1135 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1137 /* Assorted flags describing the data found in this DIE. */
1138 const unsigned int has_children
: 1;
1140 unsigned int is_external
: 1;
1141 unsigned int is_declaration
: 1;
1142 unsigned int has_type
: 1;
1143 unsigned int has_specification
: 1;
1144 unsigned int has_pc_info
: 1;
1145 unsigned int may_be_inlined
: 1;
1147 /* This DIE has been marked DW_AT_main_subprogram. */
1148 unsigned int main_subprogram
: 1;
1150 /* Flag set if the SCOPE field of this structure has been
1152 unsigned int scope_set
: 1;
1154 /* Flag set if the DIE has a byte_size attribute. */
1155 unsigned int has_byte_size
: 1;
1157 /* Flag set if the DIE has a DW_AT_const_value attribute. */
1158 unsigned int has_const_value
: 1;
1160 /* Flag set if any of the DIE's children are template arguments. */
1161 unsigned int has_template_arguments
: 1;
1163 /* Flag set if fixup has been called on this die. */
1164 unsigned int fixup_called
: 1;
1166 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1167 unsigned int is_dwz
: 1;
1169 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1170 unsigned int spec_is_dwz
: 1;
1172 /* The name of this DIE. Normally the value of DW_AT_name, but
1173 sometimes a default name for unnamed DIEs. */
1174 const char *name
= nullptr;
1176 /* The linkage name, if present. */
1177 const char *linkage_name
= nullptr;
1179 /* The scope to prepend to our children. This is generally
1180 allocated on the comp_unit_obstack, so will disappear
1181 when this compilation unit leaves the cache. */
1182 const char *scope
= nullptr;
1184 /* Some data associated with the partial DIE. The tag determines
1185 which field is live. */
1188 /* The location description associated with this DIE, if any. */
1189 struct dwarf_block
*locdesc
;
1190 /* The offset of an import, for DW_TAG_imported_unit. */
1191 sect_offset sect_off
;
1194 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1195 CORE_ADDR lowpc
= 0;
1196 CORE_ADDR highpc
= 0;
1198 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1199 DW_AT_sibling, if any. */
1200 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1201 could return DW_AT_sibling values to its caller load_partial_dies. */
1202 const gdb_byte
*sibling
= nullptr;
1204 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1205 DW_AT_specification (or DW_AT_abstract_origin or
1206 DW_AT_extension). */
1207 sect_offset spec_offset
{};
1209 /* Pointers to this DIE's parent, first child, and next sibling,
1211 struct partial_die_info
*die_parent
= nullptr;
1212 struct partial_die_info
*die_child
= nullptr;
1213 struct partial_die_info
*die_sibling
= nullptr;
1215 friend struct partial_die_info
*
1216 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1219 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1220 partial_die_info (sect_offset sect_off
)
1221 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1225 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1227 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1232 has_specification
= 0;
1235 main_subprogram
= 0;
1238 has_const_value
= 0;
1239 has_template_arguments
= 0;
1246 /* This data structure holds a complete die structure. */
1249 /* DWARF-2 tag for this DIE. */
1250 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1252 /* Number of attributes */
1253 unsigned char num_attrs
;
1255 /* True if we're presently building the full type name for the
1256 type derived from this DIE. */
1257 unsigned char building_fullname
: 1;
1259 /* True if this die is in process. PR 16581. */
1260 unsigned char in_process
: 1;
1262 /* True if this DIE has children. */
1263 unsigned char has_children
: 1;
1266 unsigned int abbrev
;
1268 /* Offset in .debug_info or .debug_types section. */
1269 sect_offset sect_off
;
1271 /* The dies in a compilation unit form an n-ary tree. PARENT
1272 points to this die's parent; CHILD points to the first child of
1273 this node; and all the children of a given node are chained
1274 together via their SIBLING fields. */
1275 struct die_info
*child
; /* Its first child, if any. */
1276 struct die_info
*sibling
; /* Its next sibling, if any. */
1277 struct die_info
*parent
; /* Its parent, if any. */
1279 /* An array of attributes, with NUM_ATTRS elements. There may be
1280 zero, but it's not common and zero-sized arrays are not
1281 sufficiently portable C. */
1282 struct attribute attrs
[1];
1285 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1286 but this would require a corresponding change in unpack_field_as_long
1288 static int bits_per_byte
= 8;
1290 /* When reading a variant or variant part, we track a bit more
1291 information about the field, and store it in an object of this
1294 struct variant_field
1296 /* If we see a DW_TAG_variant, then this will be the discriminant
1298 ULONGEST discriminant_value
;
1299 /* If we see a DW_TAG_variant, then this will be set if this is the
1301 bool default_branch
;
1302 /* While reading a DW_TAG_variant_part, this will be set if this
1303 field is the discriminant. */
1304 bool is_discriminant
;
1309 int accessibility
= 0;
1311 /* Extra information to describe a variant or variant part. */
1312 struct variant_field variant
{};
1313 struct field field
{};
1318 const char *name
= nullptr;
1319 std::vector
<struct fn_field
> fnfields
;
1322 /* The routines that read and process dies for a C struct or C++ class
1323 pass lists of data member fields and lists of member function fields
1324 in an instance of a field_info structure, as defined below. */
1327 /* List of data member and baseclasses fields. */
1328 std::vector
<struct nextfield
> fields
;
1329 std::vector
<struct nextfield
> baseclasses
;
1331 /* Number of fields (including baseclasses). */
1334 /* Set if the accessibility of one of the fields is not public. */
1335 int non_public_fields
= 0;
1337 /* Member function fieldlist array, contains name of possibly overloaded
1338 member function, number of overloaded member functions and a pointer
1339 to the head of the member function field chain. */
1340 std::vector
<struct fnfieldlist
> fnfieldlists
;
1342 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1343 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1344 std::vector
<struct decl_field
> typedef_field_list
;
1346 /* Nested types defined by this class and the number of elements in this
1348 std::vector
<struct decl_field
> nested_types_list
;
1351 /* Loaded secondary compilation units are kept in memory until they
1352 have not been referenced for the processing of this many
1353 compilation units. Set this to zero to disable caching. Cache
1354 sizes of up to at least twenty will improve startup time for
1355 typical inter-CU-reference binaries, at an obvious memory cost. */
1356 static int dwarf_max_cache_age
= 5;
1358 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1359 struct cmd_list_element
*c
, const char *value
)
1361 fprintf_filtered (file
, _("The upper bound on the age of cached "
1362 "DWARF compilation units is %s.\n"),
1366 /* local function prototypes */
1368 static void dwarf2_find_base_address (struct die_info
*die
,
1369 struct dwarf2_cu
*cu
);
1371 static dwarf2_psymtab
*create_partial_symtab
1372 (struct dwarf2_per_cu_data
*per_cu
, const char *name
);
1374 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1375 const gdb_byte
*info_ptr
,
1376 struct die_info
*type_unit_die
);
1378 static void dwarf2_build_psymtabs_hard
1379 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1381 static void scan_partial_symbols (struct partial_die_info
*,
1382 CORE_ADDR
*, CORE_ADDR
*,
1383 int, struct dwarf2_cu
*);
1385 static void add_partial_symbol (struct partial_die_info
*,
1386 struct dwarf2_cu
*);
1388 static void add_partial_namespace (struct partial_die_info
*pdi
,
1389 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1390 int set_addrmap
, struct dwarf2_cu
*cu
);
1392 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1393 CORE_ADDR
*highpc
, int set_addrmap
,
1394 struct dwarf2_cu
*cu
);
1396 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1397 struct dwarf2_cu
*cu
);
1399 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1400 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1401 int need_pc
, struct dwarf2_cu
*cu
);
1403 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1405 static struct partial_die_info
*load_partial_dies
1406 (const struct die_reader_specs
*, const gdb_byte
*, int);
1408 /* A pair of partial_die_info and compilation unit. */
1409 struct cu_partial_die_info
1411 /* The compilation unit of the partial_die_info. */
1412 struct dwarf2_cu
*cu
;
1413 /* A partial_die_info. */
1414 struct partial_die_info
*pdi
;
1416 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1422 cu_partial_die_info () = delete;
1425 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1426 struct dwarf2_cu
*);
1428 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1429 struct attribute
*, struct attr_abbrev
*,
1430 const gdb_byte
*, bool *need_reprocess
);
1432 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1433 struct attribute
*attr
);
1435 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1437 static CORE_ADDR
read_address (bfd
*, const gdb_byte
*ptr
, struct dwarf2_cu
*,
1440 static LONGEST
read_initial_length (bfd
*, const gdb_byte
*, unsigned int *);
1442 static LONGEST read_checked_initial_length_and_offset
1443 (bfd
*, const gdb_byte
*, const struct comp_unit_head
*,
1444 unsigned int *, unsigned int *);
1446 static LONGEST
read_offset (bfd
*, const gdb_byte
*,
1447 const struct comp_unit_head
*,
1450 static LONGEST
read_offset_1 (bfd
*, const gdb_byte
*, unsigned int);
1452 static sect_offset read_abbrev_offset
1453 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1454 struct dwarf2_section_info
*, sect_offset
);
1456 static const gdb_byte
*read_n_bytes (bfd
*, const gdb_byte
*, unsigned int);
1458 static const char *read_direct_string (bfd
*, const gdb_byte
*, unsigned int *);
1460 static const char *read_indirect_string
1461 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1462 const struct comp_unit_head
*, unsigned int *);
1464 static const char *read_indirect_line_string
1465 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1466 const struct comp_unit_head
*, unsigned int *);
1468 static const char *read_indirect_string_at_offset
1469 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
1470 LONGEST str_offset
);
1472 static const char *read_indirect_string_from_dwz
1473 (struct objfile
*objfile
, struct dwz_file
*, LONGEST
);
1475 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1479 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1480 ULONGEST str_index
);
1482 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1483 ULONGEST str_index
);
1485 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1487 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1488 struct dwarf2_cu
*);
1490 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1493 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1494 struct dwarf2_cu
*cu
);
1496 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1498 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1499 struct dwarf2_cu
*cu
);
1501 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1503 static struct die_info
*die_specification (struct die_info
*die
,
1504 struct dwarf2_cu
**);
1506 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1507 struct dwarf2_cu
*cu
);
1509 static void dwarf_decode_lines (struct line_header
*, const char *,
1510 struct dwarf2_cu
*, dwarf2_psymtab
*,
1511 CORE_ADDR
, int decode_mapping
);
1513 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1516 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1517 struct dwarf2_cu
*, struct symbol
* = NULL
);
1519 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1520 struct dwarf2_cu
*);
1522 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1525 struct obstack
*obstack
,
1526 struct dwarf2_cu
*cu
, LONGEST
*value
,
1527 const gdb_byte
**bytes
,
1528 struct dwarf2_locexpr_baton
**baton
);
1530 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1532 static int need_gnat_info (struct dwarf2_cu
*);
1534 static struct type
*die_descriptive_type (struct die_info
*,
1535 struct dwarf2_cu
*);
1537 static void set_descriptive_type (struct type
*, struct die_info
*,
1538 struct dwarf2_cu
*);
1540 static struct type
*die_containing_type (struct die_info
*,
1541 struct dwarf2_cu
*);
1543 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1544 struct dwarf2_cu
*);
1546 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1548 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1550 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1552 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1553 const char *suffix
, int physname
,
1554 struct dwarf2_cu
*cu
);
1556 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1558 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1560 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1562 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1564 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1566 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1568 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1569 struct dwarf2_cu
*, dwarf2_psymtab
*);
1571 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1572 values. Keep the items ordered with increasing constraints compliance. */
1575 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1576 PC_BOUNDS_NOT_PRESENT
,
1578 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1579 were present but they do not form a valid range of PC addresses. */
1582 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1585 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1589 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1590 CORE_ADDR
*, CORE_ADDR
*,
1594 static void get_scope_pc_bounds (struct die_info
*,
1595 CORE_ADDR
*, CORE_ADDR
*,
1596 struct dwarf2_cu
*);
1598 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1599 CORE_ADDR
, struct dwarf2_cu
*);
1601 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1602 struct dwarf2_cu
*);
1604 static void dwarf2_attach_fields_to_type (struct field_info
*,
1605 struct type
*, struct dwarf2_cu
*);
1607 static void dwarf2_add_member_fn (struct field_info
*,
1608 struct die_info
*, struct type
*,
1609 struct dwarf2_cu
*);
1611 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1613 struct dwarf2_cu
*);
1615 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1617 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1619 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1621 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1623 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1625 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1627 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1629 static struct type
*read_module_type (struct die_info
*die
,
1630 struct dwarf2_cu
*cu
);
1632 static const char *namespace_name (struct die_info
*die
,
1633 int *is_anonymous
, struct dwarf2_cu
*);
1635 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1637 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1639 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1640 struct dwarf2_cu
*);
1642 static struct die_info
*read_die_and_siblings_1
1643 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1646 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1647 const gdb_byte
*info_ptr
,
1648 const gdb_byte
**new_info_ptr
,
1649 struct die_info
*parent
);
1651 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1652 struct die_info
**, const gdb_byte
*,
1655 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1656 struct die_info
**, const gdb_byte
*);
1658 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1660 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1663 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1665 static const char *dwarf2_full_name (const char *name
,
1666 struct die_info
*die
,
1667 struct dwarf2_cu
*cu
);
1669 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1670 struct dwarf2_cu
*cu
);
1672 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1673 struct dwarf2_cu
**);
1675 static const char *dwarf_tag_name (unsigned int);
1677 static const char *dwarf_attr_name (unsigned int);
1679 static const char *dwarf_unit_type_name (int unit_type
);
1681 static const char *dwarf_form_name (unsigned int);
1683 static const char *dwarf_bool_name (unsigned int);
1685 static const char *dwarf_type_encoding_name (unsigned int);
1687 static struct die_info
*sibling_die (struct die_info
*);
1689 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1691 static void dump_die_for_error (struct die_info
*);
1693 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1696 /*static*/ void dump_die (struct die_info
*, int max_level
);
1698 static void store_in_ref_table (struct die_info
*,
1699 struct dwarf2_cu
*);
1701 static sect_offset
dwarf2_get_ref_die_offset (const struct attribute
*);
1703 static LONGEST
dwarf2_get_attr_constant_value (const struct attribute
*, int);
1705 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1706 const struct attribute
*,
1707 struct dwarf2_cu
**);
1709 static struct die_info
*follow_die_ref (struct die_info
*,
1710 const struct attribute
*,
1711 struct dwarf2_cu
**);
1713 static struct die_info
*follow_die_sig (struct die_info
*,
1714 const struct attribute
*,
1715 struct dwarf2_cu
**);
1717 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1718 struct dwarf2_cu
*);
1720 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1721 const struct attribute
*,
1722 struct dwarf2_cu
*);
1724 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1726 static void read_signatured_type (struct signatured_type
*);
1728 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1729 struct die_info
*die
, struct dwarf2_cu
*cu
,
1730 struct dynamic_prop
*prop
, struct type
*type
);
1732 /* memory allocation interface */
1734 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1736 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1738 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1740 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1741 struct dwarf2_loclist_baton
*baton
,
1742 const struct attribute
*attr
);
1744 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1746 struct dwarf2_cu
*cu
,
1749 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1750 const gdb_byte
*info_ptr
,
1751 struct abbrev_info
*abbrev
);
1753 static hashval_t
partial_die_hash (const void *item
);
1755 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1757 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1758 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1759 struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1761 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1762 struct die_info
*comp_unit_die
,
1763 enum language pretend_language
);
1765 static void age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1767 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1769 static struct type
*set_die_type (struct die_info
*, struct type
*,
1770 struct dwarf2_cu
*);
1772 static void create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1774 static int create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1776 static void load_full_comp_unit (struct dwarf2_per_cu_data
*, bool,
1779 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1782 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1785 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1786 struct dwarf2_per_cu_data
*);
1788 static void dwarf2_mark (struct dwarf2_cu
*);
1790 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1792 static struct type
*get_die_type_at_offset (sect_offset
,
1793 struct dwarf2_per_cu_data
*);
1795 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1797 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1798 enum language pretend_language
);
1800 static void process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1802 static struct type
*dwarf2_per_cu_addr_type (struct dwarf2_per_cu_data
*per_cu
);
1803 static struct type
*dwarf2_per_cu_addr_sized_int_type
1804 (struct dwarf2_per_cu_data
*per_cu
, bool unsigned_p
);
1805 static struct type
*dwarf2_per_cu_int_type
1806 (struct dwarf2_per_cu_data
*per_cu
, int size_in_bytes
,
1809 /* Class, the destructor of which frees all allocated queue entries. This
1810 will only have work to do if an error was thrown while processing the
1811 dwarf. If no error was thrown then the queue entries should have all
1812 been processed, and freed, as we went along. */
1814 class dwarf2_queue_guard
1817 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1818 : m_per_objfile (per_objfile
)
1822 /* Free any entries remaining on the queue. There should only be
1823 entries left if we hit an error while processing the dwarf. */
1824 ~dwarf2_queue_guard ()
1826 /* Ensure that no memory is allocated by the queue. */
1827 std::queue
<dwarf2_queue_item
> empty
;
1828 std::swap (m_per_objfile
->queue
, empty
);
1831 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1834 dwarf2_per_objfile
*m_per_objfile
;
1837 dwarf2_queue_item::~dwarf2_queue_item ()
1839 /* Anything still marked queued is likely to be in an
1840 inconsistent state, so discard it. */
1843 if (per_cu
->cu
!= NULL
)
1844 free_one_cached_comp_unit (per_cu
);
1849 /* The return type of find_file_and_directory. Note, the enclosed
1850 string pointers are only valid while this object is valid. */
1852 struct file_and_directory
1854 /* The filename. This is never NULL. */
1857 /* The compilation directory. NULL if not known. If we needed to
1858 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1859 points directly to the DW_AT_comp_dir string attribute owned by
1860 the obstack that owns the DIE. */
1861 const char *comp_dir
;
1863 /* If we needed to build a new string for comp_dir, this is what
1864 owns the storage. */
1865 std::string comp_dir_storage
;
1868 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1869 struct dwarf2_cu
*cu
);
1871 /* Expected enum dwarf_unit_type for read_comp_unit_head. */
1872 enum class rcuh_kind
{ COMPILE
, TYPE
};
1874 static const gdb_byte
*read_and_check_comp_unit_head
1875 (struct dwarf2_per_objfile
* dwarf2_per_objfile
,
1876 struct comp_unit_head
*header
,
1877 struct dwarf2_section_info
*section
,
1878 struct dwarf2_section_info
*abbrev_section
, const gdb_byte
*info_ptr
,
1879 rcuh_kind section_kind
);
1881 static htab_up
allocate_signatured_type_table (struct objfile
*objfile
);
1883 static htab_up
allocate_dwo_unit_table (struct objfile
*objfile
);
1885 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1886 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1887 struct dwp_file
*dwp_file
, const char *comp_dir
,
1888 ULONGEST signature
, int is_debug_types
);
1890 static struct dwp_file
*get_dwp_file
1891 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1893 static struct dwo_unit
*lookup_dwo_comp_unit
1894 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
1896 static struct dwo_unit
*lookup_dwo_type_unit
1897 (struct signatured_type
*, const char *, const char *);
1899 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
1901 /* A unique pointer to a dwo_file. */
1903 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1905 static void process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1907 static void check_producer (struct dwarf2_cu
*cu
);
1909 static void free_line_header_voidp (void *arg
);
1911 /* Various complaints about symbol reading that don't abort the process. */
1914 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
1916 complaint (_("statement list doesn't fit in .debug_line section"));
1920 dwarf2_debug_line_missing_file_complaint (void)
1922 complaint (_(".debug_line section has line data without a file"));
1926 dwarf2_debug_line_missing_end_sequence_complaint (void)
1928 complaint (_(".debug_line section has line "
1929 "program sequence without an end"));
1933 dwarf2_complex_location_expr_complaint (void)
1935 complaint (_("location expression too complex"));
1939 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1942 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1947 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
1949 complaint (_("debug info runs off end of %s section"
1951 section
->get_name (),
1952 section
->get_file_name ());
1956 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
1958 complaint (_("macro debug info contains a "
1959 "malformed macro definition:\n`%s'"),
1964 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1966 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1970 /* Hash function for line_header_hash. */
1973 line_header_hash (const struct line_header
*ofs
)
1975 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1978 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1981 line_header_hash_voidp (const void *item
)
1983 const struct line_header
*ofs
= (const struct line_header
*) item
;
1985 return line_header_hash (ofs
);
1988 /* Equality function for line_header_hash. */
1991 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1993 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1994 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1996 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1997 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
2002 /* See declaration. */
2004 dwarf2_per_objfile::dwarf2_per_objfile (struct objfile
*objfile_
,
2005 const dwarf2_debug_sections
*names
,
2007 : objfile (objfile_
),
2008 can_copy (can_copy_
)
2011 names
= &dwarf2_elf_names
;
2013 bfd
*obfd
= objfile
->obfd
;
2015 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
2016 locate_sections (obfd
, sec
, *names
);
2019 dwarf2_per_objfile::~dwarf2_per_objfile ()
2021 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
2022 free_cached_comp_units ();
2024 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
2025 per_cu
->imported_symtabs_free ();
2027 for (signatured_type
*sig_type
: all_type_units
)
2028 sig_type
->per_cu
.imported_symtabs_free ();
2030 /* Everything else should be on the objfile obstack. */
2033 /* See declaration. */
2036 dwarf2_per_objfile::free_cached_comp_units ()
2038 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
2039 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
2040 while (per_cu
!= NULL
)
2042 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
2045 *last_chain
= next_cu
;
2050 /* A helper class that calls free_cached_comp_units on
2053 class free_cached_comp_units
2057 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
2058 : m_per_objfile (per_objfile
)
2062 ~free_cached_comp_units ()
2064 m_per_objfile
->free_cached_comp_units ();
2067 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
2071 dwarf2_per_objfile
*m_per_objfile
;
2074 /* Try to locate the sections we need for DWARF 2 debugging
2075 information and return true if we have enough to do something.
2076 NAMES points to the dwarf2 section names, or is NULL if the standard
2077 ELF names are used. CAN_COPY is true for formats where symbol
2078 interposition is possible and so symbol values must follow copy
2079 relocation rules. */
2082 dwarf2_has_info (struct objfile
*objfile
,
2083 const struct dwarf2_debug_sections
*names
,
2086 if (objfile
->flags
& OBJF_READNEVER
)
2089 struct dwarf2_per_objfile
*dwarf2_per_objfile
2090 = get_dwarf2_per_objfile (objfile
);
2092 if (dwarf2_per_objfile
== NULL
)
2093 dwarf2_per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
,
2097 return (!dwarf2_per_objfile
->info
.is_virtual
2098 && dwarf2_per_objfile
->info
.s
.section
!= NULL
2099 && !dwarf2_per_objfile
->abbrev
.is_virtual
2100 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
2103 /* When loading sections, we look either for uncompressed section or for
2104 compressed section names. */
2107 section_is_p (const char *section_name
,
2108 const struct dwarf2_section_names
*names
)
2110 if (names
->normal
!= NULL
2111 && strcmp (section_name
, names
->normal
) == 0)
2113 if (names
->compressed
!= NULL
2114 && strcmp (section_name
, names
->compressed
) == 0)
2119 /* See declaration. */
2122 dwarf2_per_objfile::locate_sections (bfd
*abfd
, asection
*sectp
,
2123 const dwarf2_debug_sections
&names
)
2125 flagword aflag
= bfd_section_flags (sectp
);
2127 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
2130 else if (elf_section_data (sectp
)->this_hdr
.sh_size
2131 > bfd_get_file_size (abfd
))
2133 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
2134 warning (_("Discarding section %s which has a section size (%s"
2135 ") larger than the file size [in module %s]"),
2136 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
2137 bfd_get_filename (abfd
));
2139 else if (section_is_p (sectp
->name
, &names
.info
))
2141 this->info
.s
.section
= sectp
;
2142 this->info
.size
= bfd_section_size (sectp
);
2144 else if (section_is_p (sectp
->name
, &names
.abbrev
))
2146 this->abbrev
.s
.section
= sectp
;
2147 this->abbrev
.size
= bfd_section_size (sectp
);
2149 else if (section_is_p (sectp
->name
, &names
.line
))
2151 this->line
.s
.section
= sectp
;
2152 this->line
.size
= bfd_section_size (sectp
);
2154 else if (section_is_p (sectp
->name
, &names
.loc
))
2156 this->loc
.s
.section
= sectp
;
2157 this->loc
.size
= bfd_section_size (sectp
);
2159 else if (section_is_p (sectp
->name
, &names
.loclists
))
2161 this->loclists
.s
.section
= sectp
;
2162 this->loclists
.size
= bfd_section_size (sectp
);
2164 else if (section_is_p (sectp
->name
, &names
.macinfo
))
2166 this->macinfo
.s
.section
= sectp
;
2167 this->macinfo
.size
= bfd_section_size (sectp
);
2169 else if (section_is_p (sectp
->name
, &names
.macro
))
2171 this->macro
.s
.section
= sectp
;
2172 this->macro
.size
= bfd_section_size (sectp
);
2174 else if (section_is_p (sectp
->name
, &names
.str
))
2176 this->str
.s
.section
= sectp
;
2177 this->str
.size
= bfd_section_size (sectp
);
2179 else if (section_is_p (sectp
->name
, &names
.str_offsets
))
2181 this->str_offsets
.s
.section
= sectp
;
2182 this->str_offsets
.size
= bfd_section_size (sectp
);
2184 else if (section_is_p (sectp
->name
, &names
.line_str
))
2186 this->line_str
.s
.section
= sectp
;
2187 this->line_str
.size
= bfd_section_size (sectp
);
2189 else if (section_is_p (sectp
->name
, &names
.addr
))
2191 this->addr
.s
.section
= sectp
;
2192 this->addr
.size
= bfd_section_size (sectp
);
2194 else if (section_is_p (sectp
->name
, &names
.frame
))
2196 this->frame
.s
.section
= sectp
;
2197 this->frame
.size
= bfd_section_size (sectp
);
2199 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
2201 this->eh_frame
.s
.section
= sectp
;
2202 this->eh_frame
.size
= bfd_section_size (sectp
);
2204 else if (section_is_p (sectp
->name
, &names
.ranges
))
2206 this->ranges
.s
.section
= sectp
;
2207 this->ranges
.size
= bfd_section_size (sectp
);
2209 else if (section_is_p (sectp
->name
, &names
.rnglists
))
2211 this->rnglists
.s
.section
= sectp
;
2212 this->rnglists
.size
= bfd_section_size (sectp
);
2214 else if (section_is_p (sectp
->name
, &names
.types
))
2216 struct dwarf2_section_info type_section
;
2218 memset (&type_section
, 0, sizeof (type_section
));
2219 type_section
.s
.section
= sectp
;
2220 type_section
.size
= bfd_section_size (sectp
);
2222 this->types
.push_back (type_section
);
2224 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
2226 this->gdb_index
.s
.section
= sectp
;
2227 this->gdb_index
.size
= bfd_section_size (sectp
);
2229 else if (section_is_p (sectp
->name
, &names
.debug_names
))
2231 this->debug_names
.s
.section
= sectp
;
2232 this->debug_names
.size
= bfd_section_size (sectp
);
2234 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
2236 this->debug_aranges
.s
.section
= sectp
;
2237 this->debug_aranges
.size
= bfd_section_size (sectp
);
2240 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2241 && bfd_section_vma (sectp
) == 0)
2242 this->has_section_at_zero
= true;
2245 /* A helper function that returns the size of a section in a safe way.
2246 If you are positive that the section has been read before using the
2247 size, then it is safe to refer to the dwarf2_section_info object's
2248 "size" field directly. In other cases, you must call this
2249 function, because for compressed sections the size field is not set
2250 correctly until the section has been read. */
2252 static bfd_size_type
2253 dwarf2_section_size (struct objfile
*objfile
,
2254 struct dwarf2_section_info
*info
)
2257 info
->read (objfile
);
2261 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2265 dwarf2_get_section_info (struct objfile
*objfile
,
2266 enum dwarf2_section_enum sect
,
2267 asection
**sectp
, const gdb_byte
**bufp
,
2268 bfd_size_type
*sizep
)
2270 struct dwarf2_per_objfile
*data
= dwarf2_objfile_data_key
.get (objfile
);
2271 struct dwarf2_section_info
*info
;
2273 /* We may see an objfile without any DWARF, in which case we just
2284 case DWARF2_DEBUG_FRAME
:
2285 info
= &data
->frame
;
2287 case DWARF2_EH_FRAME
:
2288 info
= &data
->eh_frame
;
2291 gdb_assert_not_reached ("unexpected section");
2294 info
->read (objfile
);
2296 *sectp
= info
->get_bfd_section ();
2297 *bufp
= info
->buffer
;
2298 *sizep
= info
->size
;
2301 /* A helper function to find the sections for a .dwz file. */
2304 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2306 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2308 /* Note that we only support the standard ELF names, because .dwz
2309 is ELF-only (at the time of writing). */
2310 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2312 dwz_file
->abbrev
.s
.section
= sectp
;
2313 dwz_file
->abbrev
.size
= bfd_section_size (sectp
);
2315 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2317 dwz_file
->info
.s
.section
= sectp
;
2318 dwz_file
->info
.size
= bfd_section_size (sectp
);
2320 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2322 dwz_file
->str
.s
.section
= sectp
;
2323 dwz_file
->str
.size
= bfd_section_size (sectp
);
2325 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2327 dwz_file
->line
.s
.section
= sectp
;
2328 dwz_file
->line
.size
= bfd_section_size (sectp
);
2330 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2332 dwz_file
->macro
.s
.section
= sectp
;
2333 dwz_file
->macro
.size
= bfd_section_size (sectp
);
2335 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2337 dwz_file
->gdb_index
.s
.section
= sectp
;
2338 dwz_file
->gdb_index
.size
= bfd_section_size (sectp
);
2340 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2342 dwz_file
->debug_names
.s
.section
= sectp
;
2343 dwz_file
->debug_names
.size
= bfd_section_size (sectp
);
2347 /* See dwarf2read.h. */
2350 dwarf2_get_dwz_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
2352 const char *filename
;
2353 bfd_size_type buildid_len_arg
;
2357 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2358 return dwarf2_per_objfile
->dwz_file
.get ();
2360 bfd_set_error (bfd_error_no_error
);
2361 gdb::unique_xmalloc_ptr
<char> data
2362 (bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2363 &buildid_len_arg
, &buildid
));
2366 if (bfd_get_error () == bfd_error_no_error
)
2368 error (_("could not read '.gnu_debugaltlink' section: %s"),
2369 bfd_errmsg (bfd_get_error ()));
2372 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2374 buildid_len
= (size_t) buildid_len_arg
;
2376 filename
= data
.get ();
2378 std::string abs_storage
;
2379 if (!IS_ABSOLUTE_PATH (filename
))
2381 gdb::unique_xmalloc_ptr
<char> abs
2382 = gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2384 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2385 filename
= abs_storage
.c_str ();
2388 /* First try the file name given in the section. If that doesn't
2389 work, try to use the build-id instead. */
2390 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
, -1));
2391 if (dwz_bfd
!= NULL
)
2393 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2394 dwz_bfd
.reset (nullptr);
2397 if (dwz_bfd
== NULL
)
2398 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2400 if (dwz_bfd
== NULL
)
2401 error (_("could not find '.gnu_debugaltlink' file for %s"),
2402 objfile_name (dwarf2_per_objfile
->objfile
));
2404 std::unique_ptr
<struct dwz_file
> result
2405 (new struct dwz_file (std::move (dwz_bfd
)));
2407 bfd_map_over_sections (result
->dwz_bfd
.get (), locate_dwz_sections
,
2410 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
,
2411 result
->dwz_bfd
.get ());
2412 dwarf2_per_objfile
->dwz_file
= std::move (result
);
2413 return dwarf2_per_objfile
->dwz_file
.get ();
2416 /* DWARF quick_symbols_functions support. */
2418 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2419 unique line tables, so we maintain a separate table of all .debug_line
2420 derived entries to support the sharing.
2421 All the quick functions need is the list of file names. We discard the
2422 line_header when we're done and don't need to record it here. */
2423 struct quick_file_names
2425 /* The data used to construct the hash key. */
2426 struct stmt_list_hash hash
;
2428 /* The number of entries in file_names, real_names. */
2429 unsigned int num_file_names
;
2431 /* The file names from the line table, after being run through
2433 const char **file_names
;
2435 /* The file names from the line table after being run through
2436 gdb_realpath. These are computed lazily. */
2437 const char **real_names
;
2440 /* When using the index (and thus not using psymtabs), each CU has an
2441 object of this type. This is used to hold information needed by
2442 the various "quick" methods. */
2443 struct dwarf2_per_cu_quick_data
2445 /* The file table. This can be NULL if there was no file table
2446 or it's currently not read in.
2447 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2448 struct quick_file_names
*file_names
;
2450 /* The corresponding symbol table. This is NULL if symbols for this
2451 CU have not yet been read. */
2452 struct compunit_symtab
*compunit_symtab
;
2454 /* A temporary mark bit used when iterating over all CUs in
2455 expand_symtabs_matching. */
2456 unsigned int mark
: 1;
2458 /* True if we've tried to read the file table and found there isn't one.
2459 There will be no point in trying to read it again next time. */
2460 unsigned int no_file_data
: 1;
2463 /* Utility hash function for a stmt_list_hash. */
2466 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2470 if (stmt_list_hash
->dwo_unit
!= NULL
)
2471 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2472 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2476 /* Utility equality function for a stmt_list_hash. */
2479 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2480 const struct stmt_list_hash
*rhs
)
2482 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2484 if (lhs
->dwo_unit
!= NULL
2485 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2488 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2491 /* Hash function for a quick_file_names. */
2494 hash_file_name_entry (const void *e
)
2496 const struct quick_file_names
*file_data
2497 = (const struct quick_file_names
*) e
;
2499 return hash_stmt_list_entry (&file_data
->hash
);
2502 /* Equality function for a quick_file_names. */
2505 eq_file_name_entry (const void *a
, const void *b
)
2507 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2508 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2510 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2513 /* Delete function for a quick_file_names. */
2516 delete_file_name_entry (void *e
)
2518 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2521 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2523 xfree ((void*) file_data
->file_names
[i
]);
2524 if (file_data
->real_names
)
2525 xfree ((void*) file_data
->real_names
[i
]);
2528 /* The space for the struct itself lives on objfile_obstack,
2529 so we don't free it here. */
2532 /* Create a quick_file_names hash table. */
2535 create_quick_file_names_table (unsigned int nr_initial_entries
)
2537 return htab_up (htab_create_alloc (nr_initial_entries
,
2538 hash_file_name_entry
, eq_file_name_entry
,
2539 delete_file_name_entry
, xcalloc
, xfree
));
2542 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2543 have to be created afterwards. You should call age_cached_comp_units after
2544 processing PER_CU->CU. dw2_setup must have been already called. */
2547 load_cu (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2549 if (per_cu
->is_debug_types
)
2550 load_full_type_unit (per_cu
);
2552 load_full_comp_unit (per_cu
, skip_partial
, language_minimal
);
2554 if (per_cu
->cu
== NULL
)
2555 return; /* Dummy CU. */
2557 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2560 /* Read in the symbols for PER_CU. */
2563 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2565 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2567 /* Skip type_unit_groups, reading the type units they contain
2568 is handled elsewhere. */
2569 if (IS_TYPE_UNIT_GROUP (per_cu
))
2572 /* The destructor of dwarf2_queue_guard frees any entries left on
2573 the queue. After this point we're guaranteed to leave this function
2574 with the dwarf queue empty. */
2575 dwarf2_queue_guard
q_guard (dwarf2_per_objfile
);
2577 if (dwarf2_per_objfile
->using_index
2578 ? per_cu
->v
.quick
->compunit_symtab
== NULL
2579 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2581 queue_comp_unit (per_cu
, language_minimal
);
2582 load_cu (per_cu
, skip_partial
);
2584 /* If we just loaded a CU from a DWO, and we're working with an index
2585 that may badly handle TUs, load all the TUs in that DWO as well.
2586 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2587 if (!per_cu
->is_debug_types
2588 && per_cu
->cu
!= NULL
2589 && per_cu
->cu
->dwo_unit
!= NULL
2590 && dwarf2_per_objfile
->index_table
!= NULL
2591 && dwarf2_per_objfile
->index_table
->version
<= 7
2592 /* DWP files aren't supported yet. */
2593 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
2594 queue_and_load_all_dwo_tus (per_cu
);
2597 process_queue (dwarf2_per_objfile
);
2599 /* Age the cache, releasing compilation units that have not
2600 been used recently. */
2601 age_cached_comp_units (dwarf2_per_objfile
);
2604 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2605 the objfile from which this CU came. Returns the resulting symbol
2608 static struct compunit_symtab
*
2609 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2611 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2613 gdb_assert (dwarf2_per_objfile
->using_index
);
2614 if (!per_cu
->v
.quick
->compunit_symtab
)
2616 free_cached_comp_units
freer (dwarf2_per_objfile
);
2617 scoped_restore decrementer
= increment_reading_symtab ();
2618 dw2_do_instantiate_symtab (per_cu
, skip_partial
);
2619 process_cu_includes (dwarf2_per_objfile
);
2622 return per_cu
->v
.quick
->compunit_symtab
;
2625 /* See declaration. */
2627 dwarf2_per_cu_data
*
2628 dwarf2_per_objfile::get_cutu (int index
)
2630 if (index
>= this->all_comp_units
.size ())
2632 index
-= this->all_comp_units
.size ();
2633 gdb_assert (index
< this->all_type_units
.size ());
2634 return &this->all_type_units
[index
]->per_cu
;
2637 return this->all_comp_units
[index
];
2640 /* See declaration. */
2642 dwarf2_per_cu_data
*
2643 dwarf2_per_objfile::get_cu (int index
)
2645 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2647 return this->all_comp_units
[index
];
2650 /* See declaration. */
2653 dwarf2_per_objfile::get_tu (int index
)
2655 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2657 return this->all_type_units
[index
];
2660 /* Return a new dwarf2_per_cu_data allocated on OBJFILE's
2661 objfile_obstack, and constructed with the specified field
2664 static dwarf2_per_cu_data
*
2665 create_cu_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2666 struct dwarf2_section_info
*section
,
2668 sect_offset sect_off
, ULONGEST length
)
2670 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2671 dwarf2_per_cu_data
*the_cu
2672 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2673 struct dwarf2_per_cu_data
);
2674 the_cu
->sect_off
= sect_off
;
2675 the_cu
->length
= length
;
2676 the_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
2677 the_cu
->section
= section
;
2678 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2679 struct dwarf2_per_cu_quick_data
);
2680 the_cu
->is_dwz
= is_dwz
;
2684 /* A helper for create_cus_from_index that handles a given list of
2688 create_cus_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2689 const gdb_byte
*cu_list
, offset_type n_elements
,
2690 struct dwarf2_section_info
*section
,
2693 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2695 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2697 sect_offset sect_off
2698 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2699 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2702 dwarf2_per_cu_data
*per_cu
2703 = create_cu_from_index_list (dwarf2_per_objfile
, section
, is_dwz
,
2705 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
2709 /* Read the CU list from the mapped index, and use it to create all
2710 the CU objects for this objfile. */
2713 create_cus_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2714 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2715 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2717 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
2718 dwarf2_per_objfile
->all_comp_units
.reserve
2719 ((cu_list_elements
+ dwz_elements
) / 2);
2721 create_cus_from_index_list (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
2722 &dwarf2_per_objfile
->info
, 0);
2724 if (dwz_elements
== 0)
2727 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
2728 create_cus_from_index_list (dwarf2_per_objfile
, dwz_list
, dwz_elements
,
2732 /* Create the signatured type hash table from the index. */
2735 create_signatured_type_table_from_index
2736 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2737 struct dwarf2_section_info
*section
,
2738 const gdb_byte
*bytes
,
2739 offset_type elements
)
2741 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2743 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
2744 dwarf2_per_objfile
->all_type_units
.reserve (elements
/ 3);
2746 htab_up sig_types_hash
= allocate_signatured_type_table (objfile
);
2748 for (offset_type i
= 0; i
< elements
; i
+= 3)
2750 struct signatured_type
*sig_type
;
2753 cu_offset type_offset_in_tu
;
2755 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2756 sect_offset sect_off
2757 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2759 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2761 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2764 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2765 struct signatured_type
);
2766 sig_type
->signature
= signature
;
2767 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2768 sig_type
->per_cu
.is_debug_types
= 1;
2769 sig_type
->per_cu
.section
= section
;
2770 sig_type
->per_cu
.sect_off
= sect_off
;
2771 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
2772 sig_type
->per_cu
.v
.quick
2773 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2774 struct dwarf2_per_cu_quick_data
);
2776 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2779 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
2782 dwarf2_per_objfile
->signatured_types
= std::move (sig_types_hash
);
2785 /* Create the signatured type hash table from .debug_names. */
2788 create_signatured_type_table_from_debug_names
2789 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2790 const mapped_debug_names
&map
,
2791 struct dwarf2_section_info
*section
,
2792 struct dwarf2_section_info
*abbrev_section
)
2794 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2796 section
->read (objfile
);
2797 abbrev_section
->read (objfile
);
2799 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
2800 dwarf2_per_objfile
->all_type_units
.reserve (map
.tu_count
);
2802 htab_up sig_types_hash
= allocate_signatured_type_table (objfile
);
2804 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2806 struct signatured_type
*sig_type
;
2809 sect_offset sect_off
2810 = (sect_offset
) (extract_unsigned_integer
2811 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2813 map
.dwarf5_byte_order
));
2815 comp_unit_head cu_header
;
2816 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
2818 section
->buffer
+ to_underlying (sect_off
),
2821 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2822 struct signatured_type
);
2823 sig_type
->signature
= cu_header
.signature
;
2824 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2825 sig_type
->per_cu
.is_debug_types
= 1;
2826 sig_type
->per_cu
.section
= section
;
2827 sig_type
->per_cu
.sect_off
= sect_off
;
2828 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
2829 sig_type
->per_cu
.v
.quick
2830 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2831 struct dwarf2_per_cu_quick_data
);
2833 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2836 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
2839 dwarf2_per_objfile
->signatured_types
= std::move (sig_types_hash
);
2842 /* Read the address map data from the mapped index, and use it to
2843 populate the objfile's psymtabs_addrmap. */
2846 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2847 struct mapped_index
*index
)
2849 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2850 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2851 const gdb_byte
*iter
, *end
;
2852 struct addrmap
*mutable_map
;
2855 auto_obstack temp_obstack
;
2857 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2859 iter
= index
->address_table
.data ();
2860 end
= iter
+ index
->address_table
.size ();
2862 baseaddr
= objfile
->text_section_offset ();
2866 ULONGEST hi
, lo
, cu_index
;
2867 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2869 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2871 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2876 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2877 hex_string (lo
), hex_string (hi
));
2881 if (cu_index
>= dwarf2_per_objfile
->all_comp_units
.size ())
2883 complaint (_(".gdb_index address table has invalid CU number %u"),
2884 (unsigned) cu_index
);
2888 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2889 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2890 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2891 dwarf2_per_objfile
->get_cu (cu_index
));
2894 objfile
->partial_symtabs
->psymtabs_addrmap
2895 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2898 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2899 populate the objfile's psymtabs_addrmap. */
2902 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2903 struct dwarf2_section_info
*section
)
2905 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2906 bfd
*abfd
= objfile
->obfd
;
2907 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2908 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2910 auto_obstack temp_obstack
;
2911 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2913 std::unordered_map
<sect_offset
,
2914 dwarf2_per_cu_data
*,
2915 gdb::hash_enum
<sect_offset
>>
2916 debug_info_offset_to_per_cu
;
2917 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
2919 const auto insertpair
2920 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
2921 if (!insertpair
.second
)
2923 warning (_("Section .debug_aranges in %s has duplicate "
2924 "debug_info_offset %s, ignoring .debug_aranges."),
2925 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2930 section
->read (objfile
);
2932 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2934 const gdb_byte
*addr
= section
->buffer
;
2936 while (addr
< section
->buffer
+ section
->size
)
2938 const gdb_byte
*const entry_addr
= addr
;
2939 unsigned int bytes_read
;
2941 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2945 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2946 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2947 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2948 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2950 warning (_("Section .debug_aranges in %s entry at offset %s "
2951 "length %s exceeds section length %s, "
2952 "ignoring .debug_aranges."),
2953 objfile_name (objfile
),
2954 plongest (entry_addr
- section
->buffer
),
2955 plongest (bytes_read
+ entry_length
),
2956 pulongest (section
->size
));
2960 /* The version number. */
2961 const uint16_t version
= read_2_bytes (abfd
, addr
);
2965 warning (_("Section .debug_aranges in %s entry at offset %s "
2966 "has unsupported version %d, ignoring .debug_aranges."),
2967 objfile_name (objfile
),
2968 plongest (entry_addr
- section
->buffer
), version
);
2972 const uint64_t debug_info_offset
2973 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2974 addr
+= offset_size
;
2975 const auto per_cu_it
2976 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2977 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2979 warning (_("Section .debug_aranges in %s entry at offset %s "
2980 "debug_info_offset %s does not exists, "
2981 "ignoring .debug_aranges."),
2982 objfile_name (objfile
),
2983 plongest (entry_addr
- section
->buffer
),
2984 pulongest (debug_info_offset
));
2987 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2989 const uint8_t address_size
= *addr
++;
2990 if (address_size
< 1 || address_size
> 8)
2992 warning (_("Section .debug_aranges in %s entry at offset %s "
2993 "address_size %u is invalid, ignoring .debug_aranges."),
2994 objfile_name (objfile
),
2995 plongest (entry_addr
- section
->buffer
), address_size
);
2999 const uint8_t segment_selector_size
= *addr
++;
3000 if (segment_selector_size
!= 0)
3002 warning (_("Section .debug_aranges in %s entry at offset %s "
3003 "segment_selector_size %u is not supported, "
3004 "ignoring .debug_aranges."),
3005 objfile_name (objfile
),
3006 plongest (entry_addr
- section
->buffer
),
3007 segment_selector_size
);
3011 /* Must pad to an alignment boundary that is twice the address
3012 size. It is undocumented by the DWARF standard but GCC does
3014 for (size_t padding
= ((-(addr
- section
->buffer
))
3015 & (2 * address_size
- 1));
3016 padding
> 0; padding
--)
3019 warning (_("Section .debug_aranges in %s entry at offset %s "
3020 "padding is not zero, ignoring .debug_aranges."),
3021 objfile_name (objfile
),
3022 plongest (entry_addr
- section
->buffer
));
3028 if (addr
+ 2 * address_size
> entry_end
)
3030 warning (_("Section .debug_aranges in %s entry at offset %s "
3031 "address list is not properly terminated, "
3032 "ignoring .debug_aranges."),
3033 objfile_name (objfile
),
3034 plongest (entry_addr
- section
->buffer
));
3037 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
3039 addr
+= address_size
;
3040 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
3042 addr
+= address_size
;
3043 if (start
== 0 && length
== 0)
3045 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
3047 /* Symbol was eliminated due to a COMDAT group. */
3050 ULONGEST end
= start
+ length
;
3051 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
3053 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
3055 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
3059 objfile
->partial_symtabs
->psymtabs_addrmap
3060 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
3063 /* Find a slot in the mapped index INDEX for the object named NAME.
3064 If NAME is found, set *VEC_OUT to point to the CU vector in the
3065 constant pool and return true. If NAME cannot be found, return
3069 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
3070 offset_type
**vec_out
)
3073 offset_type slot
, step
;
3074 int (*cmp
) (const char *, const char *);
3076 gdb::unique_xmalloc_ptr
<char> without_params
;
3077 if (current_language
->la_language
== language_cplus
3078 || current_language
->la_language
== language_fortran
3079 || current_language
->la_language
== language_d
)
3081 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
3084 if (strchr (name
, '(') != NULL
)
3086 without_params
= cp_remove_params (name
);
3088 if (without_params
!= NULL
)
3089 name
= without_params
.get ();
3093 /* Index version 4 did not support case insensitive searches. But the
3094 indices for case insensitive languages are built in lowercase, therefore
3095 simulate our NAME being searched is also lowercased. */
3096 hash
= mapped_index_string_hash ((index
->version
== 4
3097 && case_sensitivity
== case_sensitive_off
3098 ? 5 : index
->version
),
3101 slot
= hash
& (index
->symbol_table
.size () - 1);
3102 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
3103 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
3109 const auto &bucket
= index
->symbol_table
[slot
];
3110 if (bucket
.name
== 0 && bucket
.vec
== 0)
3113 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
3114 if (!cmp (name
, str
))
3116 *vec_out
= (offset_type
*) (index
->constant_pool
3117 + MAYBE_SWAP (bucket
.vec
));
3121 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
3125 /* A helper function that reads the .gdb_index from BUFFER and fills
3126 in MAP. FILENAME is the name of the file containing the data;
3127 it is used for error reporting. DEPRECATED_OK is true if it is
3128 ok to use deprecated sections.
3130 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
3131 out parameters that are filled in with information about the CU and
3132 TU lists in the section.
3134 Returns true if all went well, false otherwise. */
3137 read_gdb_index_from_buffer (struct objfile
*objfile
,
3138 const char *filename
,
3140 gdb::array_view
<const gdb_byte
> buffer
,
3141 struct mapped_index
*map
,
3142 const gdb_byte
**cu_list
,
3143 offset_type
*cu_list_elements
,
3144 const gdb_byte
**types_list
,
3145 offset_type
*types_list_elements
)
3147 const gdb_byte
*addr
= &buffer
[0];
3149 /* Version check. */
3150 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
3151 /* Versions earlier than 3 emitted every copy of a psymbol. This
3152 causes the index to behave very poorly for certain requests. Version 3
3153 contained incomplete addrmap. So, it seems better to just ignore such
3157 static int warning_printed
= 0;
3158 if (!warning_printed
)
3160 warning (_("Skipping obsolete .gdb_index section in %s."),
3162 warning_printed
= 1;
3166 /* Index version 4 uses a different hash function than index version
3169 Versions earlier than 6 did not emit psymbols for inlined
3170 functions. Using these files will cause GDB not to be able to
3171 set breakpoints on inlined functions by name, so we ignore these
3172 indices unless the user has done
3173 "set use-deprecated-index-sections on". */
3174 if (version
< 6 && !deprecated_ok
)
3176 static int warning_printed
= 0;
3177 if (!warning_printed
)
3180 Skipping deprecated .gdb_index section in %s.\n\
3181 Do \"set use-deprecated-index-sections on\" before the file is read\n\
3182 to use the section anyway."),
3184 warning_printed
= 1;
3188 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3189 of the TU (for symbols coming from TUs),
3190 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3191 Plus gold-generated indices can have duplicate entries for global symbols,
3192 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3193 These are just performance bugs, and we can't distinguish gdb-generated
3194 indices from gold-generated ones, so issue no warning here. */
3196 /* Indexes with higher version than the one supported by GDB may be no
3197 longer backward compatible. */
3201 map
->version
= version
;
3203 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3206 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3207 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3211 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3212 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3213 - MAYBE_SWAP (metadata
[i
]))
3217 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3218 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3220 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
3223 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3224 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3226 = gdb::array_view
<mapped_index::symbol_table_slot
>
3227 ((mapped_index::symbol_table_slot
*) symbol_table
,
3228 (mapped_index::symbol_table_slot
*) symbol_table_end
);
3231 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3236 /* Callback types for dwarf2_read_gdb_index. */
3238 typedef gdb::function_view
3239 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_objfile
*)>
3240 get_gdb_index_contents_ftype
;
3241 typedef gdb::function_view
3242 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
3243 get_gdb_index_contents_dwz_ftype
;
3245 /* Read .gdb_index. If everything went ok, initialize the "quick"
3246 elements of all the CUs and return 1. Otherwise, return 0. */
3249 dwarf2_read_gdb_index
3250 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3251 get_gdb_index_contents_ftype get_gdb_index_contents
,
3252 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
3254 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3255 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3256 struct dwz_file
*dwz
;
3257 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3259 gdb::array_view
<const gdb_byte
> main_index_contents
3260 = get_gdb_index_contents (objfile
, dwarf2_per_objfile
);
3262 if (main_index_contents
.empty ())
3265 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3266 if (!read_gdb_index_from_buffer (objfile
, objfile_name (objfile
),
3267 use_deprecated_index_sections
,
3268 main_index_contents
, map
.get (), &cu_list
,
3269 &cu_list_elements
, &types_list
,
3270 &types_list_elements
))
3273 /* Don't use the index if it's empty. */
3274 if (map
->symbol_table
.empty ())
3277 /* If there is a .dwz file, read it so we can get its CU list as
3279 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3282 struct mapped_index dwz_map
;
3283 const gdb_byte
*dwz_types_ignore
;
3284 offset_type dwz_types_elements_ignore
;
3286 gdb::array_view
<const gdb_byte
> dwz_index_content
3287 = get_gdb_index_contents_dwz (objfile
, dwz
);
3289 if (dwz_index_content
.empty ())
3292 if (!read_gdb_index_from_buffer (objfile
,
3293 bfd_get_filename (dwz
->dwz_bfd
.get ()),
3294 1, dwz_index_content
, &dwz_map
,
3295 &dwz_list
, &dwz_list_elements
,
3297 &dwz_types_elements_ignore
))
3299 warning (_("could not read '.gdb_index' section from %s; skipping"),
3300 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3305 create_cus_from_index (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3306 dwz_list
, dwz_list_elements
);
3308 if (types_list_elements
)
3310 /* We can only handle a single .debug_types when we have an
3312 if (dwarf2_per_objfile
->types
.size () != 1)
3315 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
3317 create_signatured_type_table_from_index (dwarf2_per_objfile
, section
,
3318 types_list
, types_list_elements
);
3321 create_addrmap_from_index (dwarf2_per_objfile
, map
.get ());
3323 dwarf2_per_objfile
->index_table
= std::move (map
);
3324 dwarf2_per_objfile
->using_index
= 1;
3325 dwarf2_per_objfile
->quick_file_names_table
=
3326 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
3331 /* die_reader_func for dw2_get_file_names. */
3334 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3335 const gdb_byte
*info_ptr
,
3336 struct die_info
*comp_unit_die
)
3338 struct dwarf2_cu
*cu
= reader
->cu
;
3339 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3340 struct dwarf2_per_objfile
*dwarf2_per_objfile
3341 = cu
->per_cu
->dwarf2_per_objfile
;
3342 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3343 struct dwarf2_per_cu_data
*lh_cu
;
3344 struct attribute
*attr
;
3346 struct quick_file_names
*qfn
;
3348 gdb_assert (! this_cu
->is_debug_types
);
3350 /* Our callers never want to match partial units -- instead they
3351 will match the enclosing full CU. */
3352 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3354 this_cu
->v
.quick
->no_file_data
= 1;
3362 sect_offset line_offset
{};
3364 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3365 if (attr
!= nullptr)
3367 struct quick_file_names find_entry
;
3369 line_offset
= (sect_offset
) DW_UNSND (attr
);
3371 /* We may have already read in this line header (TU line header sharing).
3372 If we have we're done. */
3373 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3374 find_entry
.hash
.line_sect_off
= line_offset
;
3375 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
.get (),
3376 &find_entry
, INSERT
);
3379 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3383 lh
= dwarf_decode_line_header (line_offset
, cu
);
3387 lh_cu
->v
.quick
->no_file_data
= 1;
3391 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
3392 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3393 qfn
->hash
.line_sect_off
= line_offset
;
3394 gdb_assert (slot
!= NULL
);
3397 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3400 if (strcmp (fnd
.name
, "<unknown>") != 0)
3403 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3405 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, qfn
->num_file_names
);
3407 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3408 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3409 qfn
->file_names
[i
+ offset
] = lh
->file_full_name (i
+ 1,
3410 fnd
.comp_dir
).release ();
3411 qfn
->real_names
= NULL
;
3413 lh_cu
->v
.quick
->file_names
= qfn
;
3416 /* A helper for the "quick" functions which attempts to read the line
3417 table for THIS_CU. */
3419 static struct quick_file_names
*
3420 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3422 /* This should never be called for TUs. */
3423 gdb_assert (! this_cu
->is_debug_types
);
3424 /* Nor type unit groups. */
3425 gdb_assert (! IS_TYPE_UNIT_GROUP (this_cu
));
3427 if (this_cu
->v
.quick
->file_names
!= NULL
)
3428 return this_cu
->v
.quick
->file_names
;
3429 /* If we know there is no line data, no point in looking again. */
3430 if (this_cu
->v
.quick
->no_file_data
)
3433 cutu_reader
reader (this_cu
);
3434 if (!reader
.dummy_p
)
3435 dw2_get_file_names_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
);
3437 if (this_cu
->v
.quick
->no_file_data
)
3439 return this_cu
->v
.quick
->file_names
;
3442 /* A helper for the "quick" functions which computes and caches the
3443 real path for a given file name from the line table. */
3446 dw2_get_real_path (struct objfile
*objfile
,
3447 struct quick_file_names
*qfn
, int index
)
3449 if (qfn
->real_names
== NULL
)
3450 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3451 qfn
->num_file_names
, const char *);
3453 if (qfn
->real_names
[index
] == NULL
)
3454 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3456 return qfn
->real_names
[index
];
3459 static struct symtab
*
3460 dw2_find_last_source_symtab (struct objfile
*objfile
)
3462 struct dwarf2_per_objfile
*dwarf2_per_objfile
3463 = get_dwarf2_per_objfile (objfile
);
3464 dwarf2_per_cu_data
*dwarf_cu
= dwarf2_per_objfile
->all_comp_units
.back ();
3465 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, false);
3470 return compunit_primary_filetab (cust
);
3473 /* Traversal function for dw2_forget_cached_source_info. */
3476 dw2_free_cached_file_names (void **slot
, void *info
)
3478 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3480 if (file_data
->real_names
)
3484 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3486 xfree ((void*) file_data
->real_names
[i
]);
3487 file_data
->real_names
[i
] = NULL
;
3495 dw2_forget_cached_source_info (struct objfile
*objfile
)
3497 struct dwarf2_per_objfile
*dwarf2_per_objfile
3498 = get_dwarf2_per_objfile (objfile
);
3500 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
.get (),
3501 dw2_free_cached_file_names
, NULL
);
3504 /* Helper function for dw2_map_symtabs_matching_filename that expands
3505 the symtabs and calls the iterator. */
3508 dw2_map_expand_apply (struct objfile
*objfile
,
3509 struct dwarf2_per_cu_data
*per_cu
,
3510 const char *name
, const char *real_path
,
3511 gdb::function_view
<bool (symtab
*)> callback
)
3513 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3515 /* Don't visit already-expanded CUs. */
3516 if (per_cu
->v
.quick
->compunit_symtab
)
3519 /* This may expand more than one symtab, and we want to iterate over
3521 dw2_instantiate_symtab (per_cu
, false);
3523 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3524 last_made
, callback
);
3527 /* Implementation of the map_symtabs_matching_filename method. */
3530 dw2_map_symtabs_matching_filename
3531 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3532 gdb::function_view
<bool (symtab
*)> callback
)
3534 const char *name_basename
= lbasename (name
);
3535 struct dwarf2_per_objfile
*dwarf2_per_objfile
3536 = get_dwarf2_per_objfile (objfile
);
3538 /* The rule is CUs specify all the files, including those used by
3539 any TU, so there's no need to scan TUs here. */
3541 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3543 /* We only need to look at symtabs not already expanded. */
3544 if (per_cu
->v
.quick
->compunit_symtab
)
3547 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3548 if (file_data
== NULL
)
3551 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3553 const char *this_name
= file_data
->file_names
[j
];
3554 const char *this_real_name
;
3556 if (compare_filenames_for_search (this_name
, name
))
3558 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3564 /* Before we invoke realpath, which can get expensive when many
3565 files are involved, do a quick comparison of the basenames. */
3566 if (! basenames_may_differ
3567 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3570 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3571 if (compare_filenames_for_search (this_real_name
, name
))
3573 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3579 if (real_path
!= NULL
)
3581 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3582 gdb_assert (IS_ABSOLUTE_PATH (name
));
3583 if (this_real_name
!= NULL
3584 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3586 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3598 /* Struct used to manage iterating over all CUs looking for a symbol. */
3600 struct dw2_symtab_iterator
3602 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3603 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
3604 /* If set, only look for symbols that match that block. Valid values are
3605 GLOBAL_BLOCK and STATIC_BLOCK. */
3606 gdb::optional
<block_enum
> block_index
;
3607 /* The kind of symbol we're looking for. */
3609 /* The list of CUs from the index entry of the symbol,
3610 or NULL if not found. */
3612 /* The next element in VEC to look at. */
3614 /* The number of elements in VEC, or zero if there is no match. */
3616 /* Have we seen a global version of the symbol?
3617 If so we can ignore all further global instances.
3618 This is to work around gold/15646, inefficient gold-generated
3623 /* Initialize the index symtab iterator ITER. */
3626 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3627 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3628 gdb::optional
<block_enum
> block_index
,
3632 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3633 iter
->block_index
= block_index
;
3634 iter
->domain
= domain
;
3636 iter
->global_seen
= 0;
3638 mapped_index
*index
= dwarf2_per_objfile
->index_table
.get ();
3640 /* index is NULL if OBJF_READNOW. */
3641 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3642 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3650 /* Return the next matching CU or NULL if there are no more. */
3652 static struct dwarf2_per_cu_data
*
3653 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3655 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
3657 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3659 offset_type cu_index_and_attrs
=
3660 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3661 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3662 gdb_index_symbol_kind symbol_kind
=
3663 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3664 /* Only check the symbol attributes if they're present.
3665 Indices prior to version 7 don't record them,
3666 and indices >= 7 may elide them for certain symbols
3667 (gold does this). */
3669 (dwarf2_per_objfile
->index_table
->version
>= 7
3670 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3672 /* Don't crash on bad data. */
3673 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
3674 + dwarf2_per_objfile
->all_type_units
.size ()))
3676 complaint (_(".gdb_index entry has bad CU index"
3678 objfile_name (dwarf2_per_objfile
->objfile
));
3682 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
3684 /* Skip if already read in. */
3685 if (per_cu
->v
.quick
->compunit_symtab
)
3688 /* Check static vs global. */
3691 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3693 if (iter
->block_index
.has_value ())
3695 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3697 if (is_static
!= want_static
)
3701 /* Work around gold/15646. */
3702 if (!is_static
&& iter
->global_seen
)
3705 iter
->global_seen
= 1;
3708 /* Only check the symbol's kind if it has one. */
3711 switch (iter
->domain
)
3714 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3715 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3716 /* Some types are also in VAR_DOMAIN. */
3717 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3721 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3725 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3729 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3744 static struct compunit_symtab
*
3745 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
3746 const char *name
, domain_enum domain
)
3748 struct compunit_symtab
*stab_best
= NULL
;
3749 struct dwarf2_per_objfile
*dwarf2_per_objfile
3750 = get_dwarf2_per_objfile (objfile
);
3752 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
3754 struct dw2_symtab_iterator iter
;
3755 struct dwarf2_per_cu_data
*per_cu
;
3757 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, block_index
, domain
, name
);
3759 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3761 struct symbol
*sym
, *with_opaque
= NULL
;
3762 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
3763 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
3764 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3766 sym
= block_find_symbol (block
, name
, domain
,
3767 block_find_non_opaque_type_preferred
,
3770 /* Some caution must be observed with overloaded functions
3771 and methods, since the index will not contain any overload
3772 information (but NAME might contain it). */
3775 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
3777 if (with_opaque
!= NULL
3778 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
3781 /* Keep looking through other CUs. */
3788 dw2_print_stats (struct objfile
*objfile
)
3790 struct dwarf2_per_objfile
*dwarf2_per_objfile
3791 = get_dwarf2_per_objfile (objfile
);
3792 int total
= (dwarf2_per_objfile
->all_comp_units
.size ()
3793 + dwarf2_per_objfile
->all_type_units
.size ());
3796 for (int i
= 0; i
< total
; ++i
)
3798 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
3800 if (!per_cu
->v
.quick
->compunit_symtab
)
3803 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3804 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3807 /* This dumps minimal information about the index.
3808 It is called via "mt print objfiles".
3809 One use is to verify .gdb_index has been loaded by the
3810 gdb.dwarf2/gdb-index.exp testcase. */
3813 dw2_dump (struct objfile
*objfile
)
3815 struct dwarf2_per_objfile
*dwarf2_per_objfile
3816 = get_dwarf2_per_objfile (objfile
);
3818 gdb_assert (dwarf2_per_objfile
->using_index
);
3819 printf_filtered (".gdb_index:");
3820 if (dwarf2_per_objfile
->index_table
!= NULL
)
3822 printf_filtered (" version %d\n",
3823 dwarf2_per_objfile
->index_table
->version
);
3826 printf_filtered (" faked for \"readnow\"\n");
3827 printf_filtered ("\n");
3831 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3832 const char *func_name
)
3834 struct dwarf2_per_objfile
*dwarf2_per_objfile
3835 = get_dwarf2_per_objfile (objfile
);
3837 struct dw2_symtab_iterator iter
;
3838 struct dwarf2_per_cu_data
*per_cu
;
3840 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, {}, VAR_DOMAIN
, func_name
);
3842 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3843 dw2_instantiate_symtab (per_cu
, false);
3848 dw2_expand_all_symtabs (struct objfile
*objfile
)
3850 struct dwarf2_per_objfile
*dwarf2_per_objfile
3851 = get_dwarf2_per_objfile (objfile
);
3852 int total_units
= (dwarf2_per_objfile
->all_comp_units
.size ()
3853 + dwarf2_per_objfile
->all_type_units
.size ());
3855 for (int i
= 0; i
< total_units
; ++i
)
3857 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
3859 /* We don't want to directly expand a partial CU, because if we
3860 read it with the wrong language, then assertion failures can
3861 be triggered later on. See PR symtab/23010. So, tell
3862 dw2_instantiate_symtab to skip partial CUs -- any important
3863 partial CU will be read via DW_TAG_imported_unit anyway. */
3864 dw2_instantiate_symtab (per_cu
, true);
3869 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
3870 const char *fullname
)
3872 struct dwarf2_per_objfile
*dwarf2_per_objfile
3873 = get_dwarf2_per_objfile (objfile
);
3875 /* We don't need to consider type units here.
3876 This is only called for examining code, e.g. expand_line_sal.
3877 There can be an order of magnitude (or more) more type units
3878 than comp units, and we avoid them if we can. */
3880 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3882 /* We only need to look at symtabs not already expanded. */
3883 if (per_cu
->v
.quick
->compunit_symtab
)
3886 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3887 if (file_data
== NULL
)
3890 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3892 const char *this_fullname
= file_data
->file_names
[j
];
3894 if (filename_cmp (this_fullname
, fullname
) == 0)
3896 dw2_instantiate_symtab (per_cu
, false);
3904 dw2_map_matching_symbols
3905 (struct objfile
*objfile
,
3906 const lookup_name_info
&name
, domain_enum domain
,
3908 gdb::function_view
<symbol_found_callback_ftype
> callback
,
3909 symbol_compare_ftype
*ordered_compare
)
3911 /* Currently unimplemented; used for Ada. The function can be called if the
3912 current language is Ada for a non-Ada objfile using GNU index. As Ada
3913 does not look for non-Ada symbols this function should just return. */
3916 /* Starting from a search name, return the string that finds the upper
3917 bound of all strings that start with SEARCH_NAME in a sorted name
3918 list. Returns the empty string to indicate that the upper bound is
3919 the end of the list. */
3922 make_sort_after_prefix_name (const char *search_name
)
3924 /* When looking to complete "func", we find the upper bound of all
3925 symbols that start with "func" by looking for where we'd insert
3926 the closest string that would follow "func" in lexicographical
3927 order. Usually, that's "func"-with-last-character-incremented,
3928 i.e. "fund". Mind non-ASCII characters, though. Usually those
3929 will be UTF-8 multi-byte sequences, but we can't be certain.
3930 Especially mind the 0xff character, which is a valid character in
3931 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3932 rule out compilers allowing it in identifiers. Note that
3933 conveniently, strcmp/strcasecmp are specified to compare
3934 characters interpreted as unsigned char. So what we do is treat
3935 the whole string as a base 256 number composed of a sequence of
3936 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3937 to 0, and carries 1 to the following more-significant position.
3938 If the very first character in SEARCH_NAME ends up incremented
3939 and carries/overflows, then the upper bound is the end of the
3940 list. The string after the empty string is also the empty
3943 Some examples of this operation:
3945 SEARCH_NAME => "+1" RESULT
3949 "\xff" "a" "\xff" => "\xff" "b"
3954 Then, with these symbols for example:
3960 completing "func" looks for symbols between "func" and
3961 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3962 which finds "func" and "func1", but not "fund".
3966 funcÿ (Latin1 'ÿ' [0xff])
3970 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3971 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3975 ÿÿ (Latin1 'ÿ' [0xff])
3978 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3979 the end of the list.
3981 std::string after
= search_name
;
3982 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3984 if (!after
.empty ())
3985 after
.back () = (unsigned char) after
.back () + 1;
3989 /* See declaration. */
3991 std::pair
<std::vector
<name_component
>::const_iterator
,
3992 std::vector
<name_component
>::const_iterator
>
3993 mapped_index_base::find_name_components_bounds
3994 (const lookup_name_info
&lookup_name_without_params
, language lang
) const
3997 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3999 const char *lang_name
4000 = lookup_name_without_params
.language_lookup_name (lang
).c_str ();
4002 /* Comparison function object for lower_bound that matches against a
4003 given symbol name. */
4004 auto lookup_compare_lower
= [&] (const name_component
&elem
,
4007 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4008 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4009 return name_cmp (elem_name
, name
) < 0;
4012 /* Comparison function object for upper_bound that matches against a
4013 given symbol name. */
4014 auto lookup_compare_upper
= [&] (const char *name
,
4015 const name_component
&elem
)
4017 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4018 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4019 return name_cmp (name
, elem_name
) < 0;
4022 auto begin
= this->name_components
.begin ();
4023 auto end
= this->name_components
.end ();
4025 /* Find the lower bound. */
4028 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
4031 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
4034 /* Find the upper bound. */
4037 if (lookup_name_without_params
.completion_mode ())
4039 /* In completion mode, we want UPPER to point past all
4040 symbols names that have the same prefix. I.e., with
4041 these symbols, and completing "func":
4043 function << lower bound
4045 other_function << upper bound
4047 We find the upper bound by looking for the insertion
4048 point of "func"-with-last-character-incremented,
4050 std::string after
= make_sort_after_prefix_name (lang_name
);
4053 return std::lower_bound (lower
, end
, after
.c_str (),
4054 lookup_compare_lower
);
4057 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
4060 return {lower
, upper
};
4063 /* See declaration. */
4066 mapped_index_base::build_name_components ()
4068 if (!this->name_components
.empty ())
4071 this->name_components_casing
= case_sensitivity
;
4073 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4075 /* The code below only knows how to break apart components of C++
4076 symbol names (and other languages that use '::' as
4077 namespace/module separator) and Ada symbol names. */
4078 auto count
= this->symbol_name_count ();
4079 for (offset_type idx
= 0; idx
< count
; idx
++)
4081 if (this->symbol_name_slot_invalid (idx
))
4084 const char *name
= this->symbol_name_at (idx
);
4086 /* Add each name component to the name component table. */
4087 unsigned int previous_len
= 0;
4089 if (strstr (name
, "::") != nullptr)
4091 for (unsigned int current_len
= cp_find_first_component (name
);
4092 name
[current_len
] != '\0';
4093 current_len
+= cp_find_first_component (name
+ current_len
))
4095 gdb_assert (name
[current_len
] == ':');
4096 this->name_components
.push_back ({previous_len
, idx
});
4097 /* Skip the '::'. */
4099 previous_len
= current_len
;
4104 /* Handle the Ada encoded (aka mangled) form here. */
4105 for (const char *iter
= strstr (name
, "__");
4107 iter
= strstr (iter
, "__"))
4109 this->name_components
.push_back ({previous_len
, idx
});
4111 previous_len
= iter
- name
;
4115 this->name_components
.push_back ({previous_len
, idx
});
4118 /* Sort name_components elements by name. */
4119 auto name_comp_compare
= [&] (const name_component
&left
,
4120 const name_component
&right
)
4122 const char *left_qualified
= this->symbol_name_at (left
.idx
);
4123 const char *right_qualified
= this->symbol_name_at (right
.idx
);
4125 const char *left_name
= left_qualified
+ left
.name_offset
;
4126 const char *right_name
= right_qualified
+ right
.name_offset
;
4128 return name_cmp (left_name
, right_name
) < 0;
4131 std::sort (this->name_components
.begin (),
4132 this->name_components
.end (),
4136 /* Helper for dw2_expand_symtabs_matching that works with a
4137 mapped_index_base instead of the containing objfile. This is split
4138 to a separate function in order to be able to unit test the
4139 name_components matching using a mock mapped_index_base. For each
4140 symbol name that matches, calls MATCH_CALLBACK, passing it the
4141 symbol's index in the mapped_index_base symbol table. */
4144 dw2_expand_symtabs_matching_symbol
4145 (mapped_index_base
&index
,
4146 const lookup_name_info
&lookup_name_in
,
4147 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4148 enum search_domain kind
,
4149 gdb::function_view
<bool (offset_type
)> match_callback
)
4151 lookup_name_info lookup_name_without_params
4152 = lookup_name_in
.make_ignore_params ();
4154 /* Build the symbol name component sorted vector, if we haven't
4156 index
.build_name_components ();
4158 /* The same symbol may appear more than once in the range though.
4159 E.g., if we're looking for symbols that complete "w", and we have
4160 a symbol named "w1::w2", we'll find the two name components for
4161 that same symbol in the range. To be sure we only call the
4162 callback once per symbol, we first collect the symbol name
4163 indexes that matched in a temporary vector and ignore
4165 std::vector
<offset_type
> matches
;
4167 struct name_and_matcher
4169 symbol_name_matcher_ftype
*matcher
;
4170 const std::string
&name
;
4172 bool operator== (const name_and_matcher
&other
) const
4174 return matcher
== other
.matcher
&& name
== other
.name
;
4178 /* A vector holding all the different symbol name matchers, for all
4180 std::vector
<name_and_matcher
> matchers
;
4182 for (int i
= 0; i
< nr_languages
; i
++)
4184 enum language lang_e
= (enum language
) i
;
4186 const language_defn
*lang
= language_def (lang_e
);
4187 symbol_name_matcher_ftype
*name_matcher
4188 = get_symbol_name_matcher (lang
, lookup_name_without_params
);
4190 name_and_matcher key
{
4192 lookup_name_without_params
.language_lookup_name (lang_e
)
4195 /* Don't insert the same comparison routine more than once.
4196 Note that we do this linear walk. This is not a problem in
4197 practice because the number of supported languages is
4199 if (std::find (matchers
.begin (), matchers
.end (), key
)
4202 matchers
.push_back (std::move (key
));
4205 = index
.find_name_components_bounds (lookup_name_without_params
,
4208 /* Now for each symbol name in range, check to see if we have a name
4209 match, and if so, call the MATCH_CALLBACK callback. */
4211 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
4213 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
4215 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
4216 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4219 matches
.push_back (bounds
.first
->idx
);
4223 std::sort (matches
.begin (), matches
.end ());
4225 /* Finally call the callback, once per match. */
4227 for (offset_type idx
: matches
)
4231 if (!match_callback (idx
))
4237 /* Above we use a type wider than idx's for 'prev', since 0 and
4238 (offset_type)-1 are both possible values. */
4239 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4244 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4246 /* A mock .gdb_index/.debug_names-like name index table, enough to
4247 exercise dw2_expand_symtabs_matching_symbol, which works with the
4248 mapped_index_base interface. Builds an index from the symbol list
4249 passed as parameter to the constructor. */
4250 class mock_mapped_index
: public mapped_index_base
4253 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4254 : m_symbol_table (symbols
)
4257 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4259 /* Return the number of names in the symbol table. */
4260 size_t symbol_name_count () const override
4262 return m_symbol_table
.size ();
4265 /* Get the name of the symbol at IDX in the symbol table. */
4266 const char *symbol_name_at (offset_type idx
) const override
4268 return m_symbol_table
[idx
];
4272 gdb::array_view
<const char *> m_symbol_table
;
4275 /* Convenience function that converts a NULL pointer to a "<null>"
4276 string, to pass to print routines. */
4279 string_or_null (const char *str
)
4281 return str
!= NULL
? str
: "<null>";
4284 /* Check if a lookup_name_info built from
4285 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4286 index. EXPECTED_LIST is the list of expected matches, in expected
4287 matching order. If no match expected, then an empty list is
4288 specified. Returns true on success. On failure prints a warning
4289 indicating the file:line that failed, and returns false. */
4292 check_match (const char *file
, int line
,
4293 mock_mapped_index
&mock_index
,
4294 const char *name
, symbol_name_match_type match_type
,
4295 bool completion_mode
,
4296 std::initializer_list
<const char *> expected_list
)
4298 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4300 bool matched
= true;
4302 auto mismatch
= [&] (const char *expected_str
,
4305 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4306 "expected=\"%s\", got=\"%s\"\n"),
4308 (match_type
== symbol_name_match_type::FULL
4310 name
, string_or_null (expected_str
), string_or_null (got
));
4314 auto expected_it
= expected_list
.begin ();
4315 auto expected_end
= expected_list
.end ();
4317 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4319 [&] (offset_type idx
)
4321 const char *matched_name
= mock_index
.symbol_name_at (idx
);
4322 const char *expected_str
4323 = expected_it
== expected_end
? NULL
: *expected_it
++;
4325 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4326 mismatch (expected_str
, matched_name
);
4330 const char *expected_str
4331 = expected_it
== expected_end
? NULL
: *expected_it
++;
4332 if (expected_str
!= NULL
)
4333 mismatch (expected_str
, NULL
);
4338 /* The symbols added to the mock mapped_index for testing (in
4340 static const char *test_symbols
[] = {
4349 "ns2::tmpl<int>::foo2",
4350 "(anonymous namespace)::A::B::C",
4352 /* These are used to check that the increment-last-char in the
4353 matching algorithm for completion doesn't match "t1_fund" when
4354 completing "t1_func". */
4360 /* A UTF-8 name with multi-byte sequences to make sure that
4361 cp-name-parser understands this as a single identifier ("função"
4362 is "function" in PT). */
4365 /* \377 (0xff) is Latin1 'ÿ'. */
4368 /* \377 (0xff) is Latin1 'ÿ'. */
4372 /* A name with all sorts of complications. Starts with "z" to make
4373 it easier for the completion tests below. */
4374 #define Z_SYM_NAME \
4375 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4376 "::tuple<(anonymous namespace)::ui*, " \
4377 "std::default_delete<(anonymous namespace)::ui>, void>"
4382 /* Returns true if the mapped_index_base::find_name_component_bounds
4383 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4384 in completion mode. */
4387 check_find_bounds_finds (mapped_index_base
&index
,
4388 const char *search_name
,
4389 gdb::array_view
<const char *> expected_syms
)
4391 lookup_name_info
lookup_name (search_name
,
4392 symbol_name_match_type::FULL
, true);
4394 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4397 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4398 if (distance
!= expected_syms
.size ())
4401 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4403 auto nc_elem
= bounds
.first
+ exp_elem
;
4404 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
4405 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4412 /* Test the lower-level mapped_index::find_name_component_bounds
4416 test_mapped_index_find_name_component_bounds ()
4418 mock_mapped_index
mock_index (test_symbols
);
4420 mock_index
.build_name_components ();
4422 /* Test the lower-level mapped_index::find_name_component_bounds
4423 method in completion mode. */
4425 static const char *expected_syms
[] = {
4430 SELF_CHECK (check_find_bounds_finds (mock_index
,
4431 "t1_func", expected_syms
));
4434 /* Check that the increment-last-char in the name matching algorithm
4435 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4437 static const char *expected_syms1
[] = {
4441 SELF_CHECK (check_find_bounds_finds (mock_index
,
4442 "\377", expected_syms1
));
4444 static const char *expected_syms2
[] = {
4447 SELF_CHECK (check_find_bounds_finds (mock_index
,
4448 "\377\377", expected_syms2
));
4452 /* Test dw2_expand_symtabs_matching_symbol. */
4455 test_dw2_expand_symtabs_matching_symbol ()
4457 mock_mapped_index
mock_index (test_symbols
);
4459 /* We let all tests run until the end even if some fails, for debug
4461 bool any_mismatch
= false;
4463 /* Create the expected symbols list (an initializer_list). Needed
4464 because lists have commas, and we need to pass them to CHECK,
4465 which is a macro. */
4466 #define EXPECT(...) { __VA_ARGS__ }
4468 /* Wrapper for check_match that passes down the current
4469 __FILE__/__LINE__. */
4470 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4471 any_mismatch |= !check_match (__FILE__, __LINE__, \
4473 NAME, MATCH_TYPE, COMPLETION_MODE, \
4476 /* Identity checks. */
4477 for (const char *sym
: test_symbols
)
4479 /* Should be able to match all existing symbols. */
4480 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4483 /* Should be able to match all existing symbols with
4485 std::string with_params
= std::string (sym
) + "(int)";
4486 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4489 /* Should be able to match all existing symbols with
4490 parameters and qualifiers. */
4491 with_params
= std::string (sym
) + " ( int ) const";
4492 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4495 /* This should really find sym, but cp-name-parser.y doesn't
4496 know about lvalue/rvalue qualifiers yet. */
4497 with_params
= std::string (sym
) + " ( int ) &&";
4498 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4502 /* Check that the name matching algorithm for completion doesn't get
4503 confused with Latin1 'ÿ' / 0xff. */
4505 static const char str
[] = "\377";
4506 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4507 EXPECT ("\377", "\377\377123"));
4510 /* Check that the increment-last-char in the matching algorithm for
4511 completion doesn't match "t1_fund" when completing "t1_func". */
4513 static const char str
[] = "t1_func";
4514 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4515 EXPECT ("t1_func", "t1_func1"));
4518 /* Check that completion mode works at each prefix of the expected
4521 static const char str
[] = "function(int)";
4522 size_t len
= strlen (str
);
4525 for (size_t i
= 1; i
< len
; i
++)
4527 lookup
.assign (str
, i
);
4528 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4529 EXPECT ("function"));
4533 /* While "w" is a prefix of both components, the match function
4534 should still only be called once. */
4536 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4538 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4542 /* Same, with a "complicated" symbol. */
4544 static const char str
[] = Z_SYM_NAME
;
4545 size_t len
= strlen (str
);
4548 for (size_t i
= 1; i
< len
; i
++)
4550 lookup
.assign (str
, i
);
4551 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4552 EXPECT (Z_SYM_NAME
));
4556 /* In FULL mode, an incomplete symbol doesn't match. */
4558 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4562 /* A complete symbol with parameters matches any overload, since the
4563 index has no overload info. */
4565 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4566 EXPECT ("std::zfunction", "std::zfunction2"));
4567 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4568 EXPECT ("std::zfunction", "std::zfunction2"));
4569 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4570 EXPECT ("std::zfunction", "std::zfunction2"));
4573 /* Check that whitespace is ignored appropriately. A symbol with a
4574 template argument list. */
4576 static const char expected
[] = "ns::foo<int>";
4577 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4579 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4583 /* Check that whitespace is ignored appropriately. A symbol with a
4584 template argument list that includes a pointer. */
4586 static const char expected
[] = "ns::foo<char*>";
4587 /* Try both completion and non-completion modes. */
4588 static const bool completion_mode
[2] = {false, true};
4589 for (size_t i
= 0; i
< 2; i
++)
4591 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4592 completion_mode
[i
], EXPECT (expected
));
4593 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4594 completion_mode
[i
], EXPECT (expected
));
4596 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4597 completion_mode
[i
], EXPECT (expected
));
4598 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4599 completion_mode
[i
], EXPECT (expected
));
4604 /* Check method qualifiers are ignored. */
4605 static const char expected
[] = "ns::foo<char*>";
4606 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4607 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4608 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4609 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4610 CHECK_MATCH ("foo < char * > ( int ) const",
4611 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4612 CHECK_MATCH ("foo < char * > ( int ) &&",
4613 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4616 /* Test lookup names that don't match anything. */
4618 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4621 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4625 /* Some wild matching tests, exercising "(anonymous namespace)",
4626 which should not be confused with a parameter list. */
4628 static const char *syms
[] = {
4632 "A :: B :: C ( int )",
4637 for (const char *s
: syms
)
4639 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4640 EXPECT ("(anonymous namespace)::A::B::C"));
4645 static const char expected
[] = "ns2::tmpl<int>::foo2";
4646 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4648 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4652 SELF_CHECK (!any_mismatch
);
4661 test_mapped_index_find_name_component_bounds ();
4662 test_dw2_expand_symtabs_matching_symbol ();
4665 }} // namespace selftests::dw2_expand_symtabs_matching
4667 #endif /* GDB_SELF_TEST */
4669 /* If FILE_MATCHER is NULL or if PER_CU has
4670 dwarf2_per_cu_quick_data::MARK set (see
4671 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4672 EXPANSION_NOTIFY on it. */
4675 dw2_expand_symtabs_matching_one
4676 (struct dwarf2_per_cu_data
*per_cu
,
4677 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4678 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4680 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4682 bool symtab_was_null
4683 = (per_cu
->v
.quick
->compunit_symtab
== NULL
);
4685 dw2_instantiate_symtab (per_cu
, false);
4687 if (expansion_notify
!= NULL
4689 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
4690 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
4694 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4695 matched, to expand corresponding CUs that were marked. IDX is the
4696 index of the symbol name that matched. */
4699 dw2_expand_marked_cus
4700 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
4701 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4702 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4705 offset_type
*vec
, vec_len
, vec_idx
;
4706 bool global_seen
= false;
4707 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
4709 vec
= (offset_type
*) (index
.constant_pool
4710 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
4711 vec_len
= MAYBE_SWAP (vec
[0]);
4712 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4714 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
4715 /* This value is only valid for index versions >= 7. */
4716 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4717 gdb_index_symbol_kind symbol_kind
=
4718 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4719 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4720 /* Only check the symbol attributes if they're present.
4721 Indices prior to version 7 don't record them,
4722 and indices >= 7 may elide them for certain symbols
4723 (gold does this). */
4726 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4728 /* Work around gold/15646. */
4731 if (!is_static
&& global_seen
)
4737 /* Only check the symbol's kind if it has one. */
4742 case VARIABLES_DOMAIN
:
4743 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4746 case FUNCTIONS_DOMAIN
:
4747 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4751 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4754 case MODULES_DOMAIN
:
4755 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4763 /* Don't crash on bad data. */
4764 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
4765 + dwarf2_per_objfile
->all_type_units
.size ()))
4767 complaint (_(".gdb_index entry has bad CU index"
4769 objfile_name (dwarf2_per_objfile
->objfile
));
4773 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
4774 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
4779 /* If FILE_MATCHER is non-NULL, set all the
4780 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4781 that match FILE_MATCHER. */
4784 dw_expand_symtabs_matching_file_matcher
4785 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4786 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4788 if (file_matcher
== NULL
)
4791 objfile
*const objfile
= dwarf2_per_objfile
->objfile
;
4793 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4795 NULL
, xcalloc
, xfree
));
4796 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4798 NULL
, xcalloc
, xfree
));
4800 /* The rule is CUs specify all the files, including those used by
4801 any TU, so there's no need to scan TUs here. */
4803 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4807 per_cu
->v
.quick
->mark
= 0;
4809 /* We only need to look at symtabs not already expanded. */
4810 if (per_cu
->v
.quick
->compunit_symtab
)
4813 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4814 if (file_data
== NULL
)
4817 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4819 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4821 per_cu
->v
.quick
->mark
= 1;
4825 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4827 const char *this_real_name
;
4829 if (file_matcher (file_data
->file_names
[j
], false))
4831 per_cu
->v
.quick
->mark
= 1;
4835 /* Before we invoke realpath, which can get expensive when many
4836 files are involved, do a quick comparison of the basenames. */
4837 if (!basenames_may_differ
4838 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4842 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
4843 if (file_matcher (this_real_name
, false))
4845 per_cu
->v
.quick
->mark
= 1;
4850 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4851 ? visited_found
.get ()
4852 : visited_not_found
.get (),
4859 dw2_expand_symtabs_matching
4860 (struct objfile
*objfile
,
4861 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4862 const lookup_name_info
&lookup_name
,
4863 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4864 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4865 enum search_domain kind
)
4867 struct dwarf2_per_objfile
*dwarf2_per_objfile
4868 = get_dwarf2_per_objfile (objfile
);
4870 /* index_table is NULL if OBJF_READNOW. */
4871 if (!dwarf2_per_objfile
->index_table
)
4874 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
4876 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
4878 dw2_expand_symtabs_matching_symbol (index
, lookup_name
,
4880 kind
, [&] (offset_type idx
)
4882 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
4883 expansion_notify
, kind
);
4888 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4891 static struct compunit_symtab
*
4892 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4897 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4898 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4901 if (cust
->includes
== NULL
)
4904 for (i
= 0; cust
->includes
[i
]; ++i
)
4906 struct compunit_symtab
*s
= cust
->includes
[i
];
4908 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4916 static struct compunit_symtab
*
4917 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
4918 struct bound_minimal_symbol msymbol
,
4920 struct obj_section
*section
,
4923 struct dwarf2_per_cu_data
*data
;
4924 struct compunit_symtab
*result
;
4926 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
4929 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4930 data
= (struct dwarf2_per_cu_data
*) addrmap_find
4931 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
4935 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
4936 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4937 paddress (get_objfile_arch (objfile
), pc
));
4940 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
,
4943 gdb_assert (result
!= NULL
);
4948 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
4949 void *data
, int need_fullname
)
4951 struct dwarf2_per_objfile
*dwarf2_per_objfile
4952 = get_dwarf2_per_objfile (objfile
);
4954 if (!dwarf2_per_objfile
->filenames_cache
)
4956 dwarf2_per_objfile
->filenames_cache
.emplace ();
4958 htab_up
visited (htab_create_alloc (10,
4959 htab_hash_pointer
, htab_eq_pointer
,
4960 NULL
, xcalloc
, xfree
));
4962 /* The rule is CUs specify all the files, including those used
4963 by any TU, so there's no need to scan TUs here. We can
4964 ignore file names coming from already-expanded CUs. */
4966 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4968 if (per_cu
->v
.quick
->compunit_symtab
)
4970 void **slot
= htab_find_slot (visited
.get (),
4971 per_cu
->v
.quick
->file_names
,
4974 *slot
= per_cu
->v
.quick
->file_names
;
4978 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4980 /* We only need to look at symtabs not already expanded. */
4981 if (per_cu
->v
.quick
->compunit_symtab
)
4984 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4985 if (file_data
== NULL
)
4988 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
4991 /* Already visited. */
4996 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4998 const char *filename
= file_data
->file_names
[j
];
4999 dwarf2_per_objfile
->filenames_cache
->seen (filename
);
5004 dwarf2_per_objfile
->filenames_cache
->traverse ([&] (const char *filename
)
5006 gdb::unique_xmalloc_ptr
<char> this_real_name
;
5009 this_real_name
= gdb_realpath (filename
);
5010 (*fun
) (filename
, this_real_name
.get (), data
);
5015 dw2_has_symbols (struct objfile
*objfile
)
5020 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
5023 dw2_find_last_source_symtab
,
5024 dw2_forget_cached_source_info
,
5025 dw2_map_symtabs_matching_filename
,
5029 dw2_expand_symtabs_for_function
,
5030 dw2_expand_all_symtabs
,
5031 dw2_expand_symtabs_with_fullname
,
5032 dw2_map_matching_symbols
,
5033 dw2_expand_symtabs_matching
,
5034 dw2_find_pc_sect_compunit_symtab
,
5036 dw2_map_symbol_filenames
5039 /* DWARF-5 debug_names reader. */
5041 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
5042 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
5044 /* A helper function that reads the .debug_names section in SECTION
5045 and fills in MAP. FILENAME is the name of the file containing the
5046 section; it is used for error reporting.
5048 Returns true if all went well, false otherwise. */
5051 read_debug_names_from_section (struct objfile
*objfile
,
5052 const char *filename
,
5053 struct dwarf2_section_info
*section
,
5054 mapped_debug_names
&map
)
5056 if (section
->empty ())
5059 /* Older elfutils strip versions could keep the section in the main
5060 executable while splitting it for the separate debug info file. */
5061 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5064 section
->read (objfile
);
5066 map
.dwarf5_byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
5068 const gdb_byte
*addr
= section
->buffer
;
5070 bfd
*const abfd
= section
->get_bfd_owner ();
5072 unsigned int bytes_read
;
5073 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
5076 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
5077 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
5078 if (bytes_read
+ length
!= section
->size
)
5080 /* There may be multiple per-CU indices. */
5081 warning (_("Section .debug_names in %s length %s does not match "
5082 "section length %s, ignoring .debug_names."),
5083 filename
, plongest (bytes_read
+ length
),
5084 pulongest (section
->size
));
5088 /* The version number. */
5089 uint16_t version
= read_2_bytes (abfd
, addr
);
5093 warning (_("Section .debug_names in %s has unsupported version %d, "
5094 "ignoring .debug_names."),
5100 uint16_t padding
= read_2_bytes (abfd
, addr
);
5104 warning (_("Section .debug_names in %s has unsupported padding %d, "
5105 "ignoring .debug_names."),
5110 /* comp_unit_count - The number of CUs in the CU list. */
5111 map
.cu_count
= read_4_bytes (abfd
, addr
);
5114 /* local_type_unit_count - The number of TUs in the local TU
5116 map
.tu_count
= read_4_bytes (abfd
, addr
);
5119 /* foreign_type_unit_count - The number of TUs in the foreign TU
5121 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
5123 if (foreign_tu_count
!= 0)
5125 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
5126 "ignoring .debug_names."),
5127 filename
, static_cast<unsigned long> (foreign_tu_count
));
5131 /* bucket_count - The number of hash buckets in the hash lookup
5133 map
.bucket_count
= read_4_bytes (abfd
, addr
);
5136 /* name_count - The number of unique names in the index. */
5137 map
.name_count
= read_4_bytes (abfd
, addr
);
5140 /* abbrev_table_size - The size in bytes of the abbreviations
5142 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
5145 /* augmentation_string_size - The size in bytes of the augmentation
5146 string. This value is rounded up to a multiple of 4. */
5147 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
5149 map
.augmentation_is_gdb
= ((augmentation_string_size
5150 == sizeof (dwarf5_augmentation
))
5151 && memcmp (addr
, dwarf5_augmentation
,
5152 sizeof (dwarf5_augmentation
)) == 0);
5153 augmentation_string_size
+= (-augmentation_string_size
) & 3;
5154 addr
+= augmentation_string_size
;
5157 map
.cu_table_reordered
= addr
;
5158 addr
+= map
.cu_count
* map
.offset_size
;
5160 /* List of Local TUs */
5161 map
.tu_table_reordered
= addr
;
5162 addr
+= map
.tu_count
* map
.offset_size
;
5164 /* Hash Lookup Table */
5165 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5166 addr
+= map
.bucket_count
* 4;
5167 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5168 addr
+= map
.name_count
* 4;
5171 map
.name_table_string_offs_reordered
= addr
;
5172 addr
+= map
.name_count
* map
.offset_size
;
5173 map
.name_table_entry_offs_reordered
= addr
;
5174 addr
+= map
.name_count
* map
.offset_size
;
5176 const gdb_byte
*abbrev_table_start
= addr
;
5179 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5184 const auto insertpair
5185 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
5186 if (!insertpair
.second
)
5188 warning (_("Section .debug_names in %s has duplicate index %s, "
5189 "ignoring .debug_names."),
5190 filename
, pulongest (index_num
));
5193 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
5194 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5199 mapped_debug_names::index_val::attr attr
;
5200 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5202 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5204 if (attr
.form
== DW_FORM_implicit_const
)
5206 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
5210 if (attr
.dw_idx
== 0 && attr
.form
== 0)
5212 indexval
.attr_vec
.push_back (std::move (attr
));
5215 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
5217 warning (_("Section .debug_names in %s has abbreviation_table "
5218 "of size %s vs. written as %u, ignoring .debug_names."),
5219 filename
, plongest (addr
- abbrev_table_start
),
5223 map
.entry_pool
= addr
;
5228 /* A helper for create_cus_from_debug_names that handles the MAP's CU
5232 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5233 const mapped_debug_names
&map
,
5234 dwarf2_section_info
§ion
,
5237 sect_offset sect_off_prev
;
5238 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5240 sect_offset sect_off_next
;
5241 if (i
< map
.cu_count
)
5244 = (sect_offset
) (extract_unsigned_integer
5245 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5247 map
.dwarf5_byte_order
));
5250 sect_off_next
= (sect_offset
) section
.size
;
5253 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5254 dwarf2_per_cu_data
*per_cu
5255 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
5256 sect_off_prev
, length
);
5257 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
5259 sect_off_prev
= sect_off_next
;
5263 /* Read the CU list from the mapped index, and use it to create all
5264 the CU objects for this dwarf2_per_objfile. */
5267 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5268 const mapped_debug_names
&map
,
5269 const mapped_debug_names
&dwz_map
)
5271 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
5272 dwarf2_per_objfile
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5274 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
5275 dwarf2_per_objfile
->info
,
5276 false /* is_dwz */);
5278 if (dwz_map
.cu_count
== 0)
5281 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5282 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
5286 /* Read .debug_names. If everything went ok, initialize the "quick"
5287 elements of all the CUs and return true. Otherwise, return false. */
5290 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
5292 std::unique_ptr
<mapped_debug_names
> map
5293 (new mapped_debug_names (dwarf2_per_objfile
));
5294 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
5295 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5297 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5298 &dwarf2_per_objfile
->debug_names
,
5302 /* Don't use the index if it's empty. */
5303 if (map
->name_count
== 0)
5306 /* If there is a .dwz file, read it so we can get its CU list as
5308 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5311 if (!read_debug_names_from_section (objfile
,
5312 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5313 &dwz
->debug_names
, dwz_map
))
5315 warning (_("could not read '.debug_names' section from %s; skipping"),
5316 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5321 create_cus_from_debug_names (dwarf2_per_objfile
, *map
, dwz_map
);
5323 if (map
->tu_count
!= 0)
5325 /* We can only handle a single .debug_types when we have an
5327 if (dwarf2_per_objfile
->types
.size () != 1)
5330 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
5332 create_signatured_type_table_from_debug_names
5333 (dwarf2_per_objfile
, *map
, section
, &dwarf2_per_objfile
->abbrev
);
5336 create_addrmap_from_aranges (dwarf2_per_objfile
,
5337 &dwarf2_per_objfile
->debug_aranges
);
5339 dwarf2_per_objfile
->debug_names_table
= std::move (map
);
5340 dwarf2_per_objfile
->using_index
= 1;
5341 dwarf2_per_objfile
->quick_file_names_table
=
5342 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
5347 /* Type used to manage iterating over all CUs looking for a symbol for
5350 class dw2_debug_names_iterator
5353 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5354 gdb::optional
<block_enum
> block_index
,
5357 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5358 m_addr (find_vec_in_debug_names (map
, name
))
5361 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5362 search_domain search
, uint32_t namei
)
5365 m_addr (find_vec_in_debug_names (map
, namei
))
5368 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5369 block_enum block_index
, domain_enum domain
,
5371 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5372 m_addr (find_vec_in_debug_names (map
, namei
))
5375 /* Return the next matching CU or NULL if there are no more. */
5376 dwarf2_per_cu_data
*next ();
5379 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5381 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5384 /* The internalized form of .debug_names. */
5385 const mapped_debug_names
&m_map
;
5387 /* If set, only look for symbols that match that block. Valid values are
5388 GLOBAL_BLOCK and STATIC_BLOCK. */
5389 const gdb::optional
<block_enum
> m_block_index
;
5391 /* The kind of symbol we're looking for. */
5392 const domain_enum m_domain
= UNDEF_DOMAIN
;
5393 const search_domain m_search
= ALL_DOMAIN
;
5395 /* The list of CUs from the index entry of the symbol, or NULL if
5397 const gdb_byte
*m_addr
;
5401 mapped_debug_names::namei_to_name (uint32_t namei
) const
5403 const ULONGEST namei_string_offs
5404 = extract_unsigned_integer ((name_table_string_offs_reordered
5405 + namei
* offset_size
),
5408 return read_indirect_string_at_offset
5409 (dwarf2_per_objfile
, dwarf2_per_objfile
->objfile
->obfd
, namei_string_offs
);
5412 /* Find a slot in .debug_names for the object named NAME. If NAME is
5413 found, return pointer to its pool data. If NAME cannot be found,
5417 dw2_debug_names_iterator::find_vec_in_debug_names
5418 (const mapped_debug_names
&map
, const char *name
)
5420 int (*cmp
) (const char *, const char *);
5422 gdb::unique_xmalloc_ptr
<char> without_params
;
5423 if (current_language
->la_language
== language_cplus
5424 || current_language
->la_language
== language_fortran
5425 || current_language
->la_language
== language_d
)
5427 /* NAME is already canonical. Drop any qualifiers as
5428 .debug_names does not contain any. */
5430 if (strchr (name
, '(') != NULL
)
5432 without_params
= cp_remove_params (name
);
5433 if (without_params
!= NULL
)
5434 name
= without_params
.get ();
5438 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5440 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5442 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5443 (map
.bucket_table_reordered
5444 + (full_hash
% map
.bucket_count
)), 4,
5445 map
.dwarf5_byte_order
);
5449 if (namei
>= map
.name_count
)
5451 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5453 namei
, map
.name_count
,
5454 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5460 const uint32_t namei_full_hash
5461 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5462 (map
.hash_table_reordered
+ namei
), 4,
5463 map
.dwarf5_byte_order
);
5464 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5467 if (full_hash
== namei_full_hash
)
5469 const char *const namei_string
= map
.namei_to_name (namei
);
5471 #if 0 /* An expensive sanity check. */
5472 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5474 complaint (_("Wrong .debug_names hash for string at index %u "
5476 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5481 if (cmp (namei_string
, name
) == 0)
5483 const ULONGEST namei_entry_offs
5484 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5485 + namei
* map
.offset_size
),
5486 map
.offset_size
, map
.dwarf5_byte_order
);
5487 return map
.entry_pool
+ namei_entry_offs
;
5492 if (namei
>= map
.name_count
)
5498 dw2_debug_names_iterator::find_vec_in_debug_names
5499 (const mapped_debug_names
&map
, uint32_t namei
)
5501 if (namei
>= map
.name_count
)
5503 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5505 namei
, map
.name_count
,
5506 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5510 const ULONGEST namei_entry_offs
5511 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5512 + namei
* map
.offset_size
),
5513 map
.offset_size
, map
.dwarf5_byte_order
);
5514 return map
.entry_pool
+ namei_entry_offs
;
5517 /* See dw2_debug_names_iterator. */
5519 dwarf2_per_cu_data
*
5520 dw2_debug_names_iterator::next ()
5525 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
5526 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5527 bfd
*const abfd
= objfile
->obfd
;
5531 unsigned int bytes_read
;
5532 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5533 m_addr
+= bytes_read
;
5537 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5538 if (indexval_it
== m_map
.abbrev_map
.cend ())
5540 complaint (_("Wrong .debug_names undefined abbrev code %s "
5542 pulongest (abbrev
), objfile_name (objfile
));
5545 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5546 enum class symbol_linkage
{
5550 } symbol_linkage_
= symbol_linkage::unknown
;
5551 dwarf2_per_cu_data
*per_cu
= NULL
;
5552 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5557 case DW_FORM_implicit_const
:
5558 ull
= attr
.implicit_const
;
5560 case DW_FORM_flag_present
:
5564 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5565 m_addr
+= bytes_read
;
5568 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5569 dwarf_form_name (attr
.form
),
5570 objfile_name (objfile
));
5573 switch (attr
.dw_idx
)
5575 case DW_IDX_compile_unit
:
5576 /* Don't crash on bad data. */
5577 if (ull
>= dwarf2_per_objfile
->all_comp_units
.size ())
5579 complaint (_(".debug_names entry has bad CU index %s"
5582 objfile_name (dwarf2_per_objfile
->objfile
));
5585 per_cu
= dwarf2_per_objfile
->get_cutu (ull
);
5587 case DW_IDX_type_unit
:
5588 /* Don't crash on bad data. */
5589 if (ull
>= dwarf2_per_objfile
->all_type_units
.size ())
5591 complaint (_(".debug_names entry has bad TU index %s"
5594 objfile_name (dwarf2_per_objfile
->objfile
));
5597 per_cu
= &dwarf2_per_objfile
->get_tu (ull
)->per_cu
;
5599 case DW_IDX_GNU_internal
:
5600 if (!m_map
.augmentation_is_gdb
)
5602 symbol_linkage_
= symbol_linkage::static_
;
5604 case DW_IDX_GNU_external
:
5605 if (!m_map
.augmentation_is_gdb
)
5607 symbol_linkage_
= symbol_linkage::extern_
;
5612 /* Skip if already read in. */
5613 if (per_cu
->v
.quick
->compunit_symtab
)
5616 /* Check static vs global. */
5617 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5619 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5620 const bool symbol_is_static
=
5621 symbol_linkage_
== symbol_linkage::static_
;
5622 if (want_static
!= symbol_is_static
)
5626 /* Match dw2_symtab_iter_next, symbol_kind
5627 and debug_names::psymbol_tag. */
5631 switch (indexval
.dwarf_tag
)
5633 case DW_TAG_variable
:
5634 case DW_TAG_subprogram
:
5635 /* Some types are also in VAR_DOMAIN. */
5636 case DW_TAG_typedef
:
5637 case DW_TAG_structure_type
:
5644 switch (indexval
.dwarf_tag
)
5646 case DW_TAG_typedef
:
5647 case DW_TAG_structure_type
:
5654 switch (indexval
.dwarf_tag
)
5657 case DW_TAG_variable
:
5664 switch (indexval
.dwarf_tag
)
5676 /* Match dw2_expand_symtabs_matching, symbol_kind and
5677 debug_names::psymbol_tag. */
5680 case VARIABLES_DOMAIN
:
5681 switch (indexval
.dwarf_tag
)
5683 case DW_TAG_variable
:
5689 case FUNCTIONS_DOMAIN
:
5690 switch (indexval
.dwarf_tag
)
5692 case DW_TAG_subprogram
:
5699 switch (indexval
.dwarf_tag
)
5701 case DW_TAG_typedef
:
5702 case DW_TAG_structure_type
:
5708 case MODULES_DOMAIN
:
5709 switch (indexval
.dwarf_tag
)
5723 static struct compunit_symtab
*
5724 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
5725 const char *name
, domain_enum domain
)
5727 struct dwarf2_per_objfile
*dwarf2_per_objfile
5728 = get_dwarf2_per_objfile (objfile
);
5730 const auto &mapp
= dwarf2_per_objfile
->debug_names_table
;
5733 /* index is NULL if OBJF_READNOW. */
5736 const auto &map
= *mapp
;
5738 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
);
5740 struct compunit_symtab
*stab_best
= NULL
;
5741 struct dwarf2_per_cu_data
*per_cu
;
5742 while ((per_cu
= iter
.next ()) != NULL
)
5744 struct symbol
*sym
, *with_opaque
= NULL
;
5745 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
5746 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
5747 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
5749 sym
= block_find_symbol (block
, name
, domain
,
5750 block_find_non_opaque_type_preferred
,
5753 /* Some caution must be observed with overloaded functions and
5754 methods, since the index will not contain any overload
5755 information (but NAME might contain it). */
5758 && strcmp_iw (sym
->search_name (), name
) == 0)
5760 if (with_opaque
!= NULL
5761 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
5764 /* Keep looking through other CUs. */
5770 /* This dumps minimal information about .debug_names. It is called
5771 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5772 uses this to verify that .debug_names has been loaded. */
5775 dw2_debug_names_dump (struct objfile
*objfile
)
5777 struct dwarf2_per_objfile
*dwarf2_per_objfile
5778 = get_dwarf2_per_objfile (objfile
);
5780 gdb_assert (dwarf2_per_objfile
->using_index
);
5781 printf_filtered (".debug_names:");
5782 if (dwarf2_per_objfile
->debug_names_table
)
5783 printf_filtered (" exists\n");
5785 printf_filtered (" faked for \"readnow\"\n");
5786 printf_filtered ("\n");
5790 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
5791 const char *func_name
)
5793 struct dwarf2_per_objfile
*dwarf2_per_objfile
5794 = get_dwarf2_per_objfile (objfile
);
5796 /* dwarf2_per_objfile->debug_names_table is NULL if OBJF_READNOW. */
5797 if (dwarf2_per_objfile
->debug_names_table
)
5799 const mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5801 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
);
5803 struct dwarf2_per_cu_data
*per_cu
;
5804 while ((per_cu
= iter
.next ()) != NULL
)
5805 dw2_instantiate_symtab (per_cu
, false);
5810 dw2_debug_names_map_matching_symbols
5811 (struct objfile
*objfile
,
5812 const lookup_name_info
&name
, domain_enum domain
,
5814 gdb::function_view
<symbol_found_callback_ftype
> callback
,
5815 symbol_compare_ftype
*ordered_compare
)
5817 struct dwarf2_per_objfile
*dwarf2_per_objfile
5818 = get_dwarf2_per_objfile (objfile
);
5820 /* debug_names_table is NULL if OBJF_READNOW. */
5821 if (!dwarf2_per_objfile
->debug_names_table
)
5824 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5825 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
5827 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5828 auto matcher
= [&] (const char *symname
)
5830 if (ordered_compare
== nullptr)
5832 return ordered_compare (symname
, match_name
) == 0;
5835 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
5836 [&] (offset_type namei
)
5838 /* The name was matched, now expand corresponding CUs that were
5840 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
);
5842 struct dwarf2_per_cu_data
*per_cu
;
5843 while ((per_cu
= iter
.next ()) != NULL
)
5844 dw2_expand_symtabs_matching_one (per_cu
, nullptr, nullptr);
5848 /* It's a shame we couldn't do this inside the
5849 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
5850 that have already been expanded. Instead, this loop matches what
5851 the psymtab code does. */
5852 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5854 struct compunit_symtab
*cust
= per_cu
->v
.quick
->compunit_symtab
;
5855 if (cust
!= nullptr)
5857 const struct block
*block
5858 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
5859 if (!iterate_over_symbols_terminated (block
, name
,
5867 dw2_debug_names_expand_symtabs_matching
5868 (struct objfile
*objfile
,
5869 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5870 const lookup_name_info
&lookup_name
,
5871 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5872 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5873 enum search_domain kind
)
5875 struct dwarf2_per_objfile
*dwarf2_per_objfile
5876 = get_dwarf2_per_objfile (objfile
);
5878 /* debug_names_table is NULL if OBJF_READNOW. */
5879 if (!dwarf2_per_objfile
->debug_names_table
)
5882 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5884 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5886 dw2_expand_symtabs_matching_symbol (map
, lookup_name
,
5888 kind
, [&] (offset_type namei
)
5890 /* The name was matched, now expand corresponding CUs that were
5892 dw2_debug_names_iterator
iter (map
, kind
, namei
);
5894 struct dwarf2_per_cu_data
*per_cu
;
5895 while ((per_cu
= iter
.next ()) != NULL
)
5896 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5902 const struct quick_symbol_functions dwarf2_debug_names_functions
=
5905 dw2_find_last_source_symtab
,
5906 dw2_forget_cached_source_info
,
5907 dw2_map_symtabs_matching_filename
,
5908 dw2_debug_names_lookup_symbol
,
5910 dw2_debug_names_dump
,
5911 dw2_debug_names_expand_symtabs_for_function
,
5912 dw2_expand_all_symtabs
,
5913 dw2_expand_symtabs_with_fullname
,
5914 dw2_debug_names_map_matching_symbols
,
5915 dw2_debug_names_expand_symtabs_matching
,
5916 dw2_find_pc_sect_compunit_symtab
,
5918 dw2_map_symbol_filenames
5921 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5922 to either a dwarf2_per_objfile or dwz_file object. */
5924 template <typename T
>
5925 static gdb::array_view
<const gdb_byte
>
5926 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5928 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5930 if (section
->empty ())
5933 /* Older elfutils strip versions could keep the section in the main
5934 executable while splitting it for the separate debug info file. */
5935 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5938 section
->read (obj
);
5940 /* dwarf2_section_info::size is a bfd_size_type, while
5941 gdb::array_view works with size_t. On 32-bit hosts, with
5942 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5943 is 32-bit. So we need an explicit narrowing conversion here.
5944 This is fine, because it's impossible to allocate or mmap an
5945 array/buffer larger than what size_t can represent. */
5946 return gdb::make_array_view (section
->buffer
, section
->size
);
5949 /* Lookup the index cache for the contents of the index associated to
5952 static gdb::array_view
<const gdb_byte
>
5953 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_objfile
*dwarf2_obj
)
5955 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5956 if (build_id
== nullptr)
5959 return global_index_cache
.lookup_gdb_index (build_id
,
5960 &dwarf2_obj
->index_cache_res
);
5963 /* Same as the above, but for DWZ. */
5965 static gdb::array_view
<const gdb_byte
>
5966 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5968 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5969 if (build_id
== nullptr)
5972 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5975 /* See symfile.h. */
5978 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
5980 struct dwarf2_per_objfile
*dwarf2_per_objfile
5981 = get_dwarf2_per_objfile (objfile
);
5983 /* If we're about to read full symbols, don't bother with the
5984 indices. In this case we also don't care if some other debug
5985 format is making psymtabs, because they are all about to be
5987 if ((objfile
->flags
& OBJF_READNOW
))
5989 dwarf2_per_objfile
->using_index
= 1;
5990 create_all_comp_units (dwarf2_per_objfile
);
5991 create_all_type_units (dwarf2_per_objfile
);
5992 dwarf2_per_objfile
->quick_file_names_table
5993 = create_quick_file_names_table
5994 (dwarf2_per_objfile
->all_comp_units
.size ());
5996 for (int i
= 0; i
< (dwarf2_per_objfile
->all_comp_units
.size ()
5997 + dwarf2_per_objfile
->all_type_units
.size ()); ++i
)
5999 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
6001 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6002 struct dwarf2_per_cu_quick_data
);
6005 /* Return 1 so that gdb sees the "quick" functions. However,
6006 these functions will be no-ops because we will have expanded
6008 *index_kind
= dw_index_kind::GDB_INDEX
;
6012 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
6014 *index_kind
= dw_index_kind::DEBUG_NAMES
;
6018 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
6019 get_gdb_index_contents_from_section
<struct dwarf2_per_objfile
>,
6020 get_gdb_index_contents_from_section
<dwz_file
>))
6022 *index_kind
= dw_index_kind::GDB_INDEX
;
6026 /* ... otherwise, try to find the index in the index cache. */
6027 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
6028 get_gdb_index_contents_from_cache
,
6029 get_gdb_index_contents_from_cache_dwz
))
6031 global_index_cache
.hit ();
6032 *index_kind
= dw_index_kind::GDB_INDEX
;
6036 global_index_cache
.miss ();
6042 /* Build a partial symbol table. */
6045 dwarf2_build_psymtabs (struct objfile
*objfile
)
6047 struct dwarf2_per_objfile
*dwarf2_per_objfile
6048 = get_dwarf2_per_objfile (objfile
);
6050 init_psymbol_list (objfile
, 1024);
6054 /* This isn't really ideal: all the data we allocate on the
6055 objfile's obstack is still uselessly kept around. However,
6056 freeing it seems unsafe. */
6057 psymtab_discarder
psymtabs (objfile
);
6058 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
6061 /* (maybe) store an index in the cache. */
6062 global_index_cache
.store (dwarf2_per_objfile
);
6064 catch (const gdb_exception_error
&except
)
6066 exception_print (gdb_stderr
, except
);
6070 /* Return the total length of the CU described by HEADER. */
6073 get_cu_length (const struct comp_unit_head
*header
)
6075 return header
->initial_length_size
+ header
->length
;
6078 /* Return TRUE if SECT_OFF is within CU_HEADER. */
6081 offset_in_cu_p (const comp_unit_head
*cu_header
, sect_offset sect_off
)
6083 sect_offset bottom
= cu_header
->sect_off
;
6084 sect_offset top
= cu_header
->sect_off
+ get_cu_length (cu_header
);
6086 return sect_off
>= bottom
&& sect_off
< top
;
6089 /* Find the base address of the compilation unit for range lists and
6090 location lists. It will normally be specified by DW_AT_low_pc.
6091 In DWARF-3 draft 4, the base address could be overridden by
6092 DW_AT_entry_pc. It's been removed, but GCC still uses this for
6093 compilation units with discontinuous ranges. */
6096 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
6098 struct attribute
*attr
;
6101 cu
->base_address
= 0;
6103 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
6104 if (attr
!= nullptr)
6106 cu
->base_address
= attr
->value_as_address ();
6111 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6112 if (attr
!= nullptr)
6114 cu
->base_address
= attr
->value_as_address ();
6120 /* Read in the comp unit header information from the debug_info at info_ptr.
6121 Use rcuh_kind::COMPILE as the default type if not known by the caller.
6122 NOTE: This leaves members offset, first_die_offset to be filled in
6125 static const gdb_byte
*
6126 read_comp_unit_head (struct comp_unit_head
*cu_header
,
6127 const gdb_byte
*info_ptr
,
6128 struct dwarf2_section_info
*section
,
6129 rcuh_kind section_kind
)
6132 unsigned int bytes_read
;
6133 const char *filename
= section
->get_file_name ();
6134 bfd
*abfd
= section
->get_bfd_owner ();
6136 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
6137 cu_header
->initial_length_size
= bytes_read
;
6138 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
6139 info_ptr
+= bytes_read
;
6140 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
6141 if (cu_header
->version
< 2 || cu_header
->version
> 5)
6142 error (_("Dwarf Error: wrong version in compilation unit header "
6143 "(is %d, should be 2, 3, 4 or 5) [in module %s]"),
6144 cu_header
->version
, filename
);
6146 if (cu_header
->version
< 5)
6147 switch (section_kind
)
6149 case rcuh_kind::COMPILE
:
6150 cu_header
->unit_type
= DW_UT_compile
;
6152 case rcuh_kind::TYPE
:
6153 cu_header
->unit_type
= DW_UT_type
;
6156 internal_error (__FILE__
, __LINE__
,
6157 _("read_comp_unit_head: invalid section_kind"));
6161 cu_header
->unit_type
= static_cast<enum dwarf_unit_type
>
6162 (read_1_byte (abfd
, info_ptr
));
6164 switch (cu_header
->unit_type
)
6168 case DW_UT_skeleton
:
6169 case DW_UT_split_compile
:
6170 if (section_kind
!= rcuh_kind::COMPILE
)
6171 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6172 "(is %s, should be %s) [in module %s]"),
6173 dwarf_unit_type_name (cu_header
->unit_type
),
6174 dwarf_unit_type_name (DW_UT_type
), filename
);
6177 case DW_UT_split_type
:
6178 section_kind
= rcuh_kind::TYPE
;
6181 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6182 "(is %#04x, should be one of: %s, %s, %s, %s or %s) "
6183 "[in module %s]"), cu_header
->unit_type
,
6184 dwarf_unit_type_name (DW_UT_compile
),
6185 dwarf_unit_type_name (DW_UT_skeleton
),
6186 dwarf_unit_type_name (DW_UT_split_compile
),
6187 dwarf_unit_type_name (DW_UT_type
),
6188 dwarf_unit_type_name (DW_UT_split_type
), filename
);
6191 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6194 cu_header
->abbrev_sect_off
= (sect_offset
) read_offset (abfd
, info_ptr
,
6197 info_ptr
+= bytes_read
;
6198 if (cu_header
->version
< 5)
6200 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6203 signed_addr
= bfd_get_sign_extend_vma (abfd
);
6204 if (signed_addr
< 0)
6205 internal_error (__FILE__
, __LINE__
,
6206 _("read_comp_unit_head: dwarf from non elf file"));
6207 cu_header
->signed_addr_p
= signed_addr
;
6209 bool header_has_signature
= section_kind
== rcuh_kind::TYPE
6210 || cu_header
->unit_type
== DW_UT_skeleton
6211 || cu_header
->unit_type
== DW_UT_split_compile
;
6213 if (header_has_signature
)
6215 cu_header
->signature
= read_8_bytes (abfd
, info_ptr
);
6219 if (section_kind
== rcuh_kind::TYPE
)
6221 LONGEST type_offset
;
6222 type_offset
= read_offset (abfd
, info_ptr
, cu_header
, &bytes_read
);
6223 info_ptr
+= bytes_read
;
6224 cu_header
->type_cu_offset_in_tu
= (cu_offset
) type_offset
;
6225 if (to_underlying (cu_header
->type_cu_offset_in_tu
) != type_offset
)
6226 error (_("Dwarf Error: Too big type_offset in compilation unit "
6227 "header (is %s) [in module %s]"), plongest (type_offset
),
6234 /* Helper function that returns the proper abbrev section for
6237 static struct dwarf2_section_info
*
6238 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
6240 struct dwarf2_section_info
*abbrev
;
6241 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6243 if (this_cu
->is_dwz
)
6244 abbrev
= &dwarf2_get_dwz_file (dwarf2_per_objfile
)->abbrev
;
6246 abbrev
= &dwarf2_per_objfile
->abbrev
;
6251 /* Subroutine of read_and_check_comp_unit_head and
6252 read_and_check_type_unit_head to simplify them.
6253 Perform various error checking on the header. */
6256 error_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6257 struct comp_unit_head
*header
,
6258 struct dwarf2_section_info
*section
,
6259 struct dwarf2_section_info
*abbrev_section
)
6261 const char *filename
= section
->get_file_name ();
6263 if (to_underlying (header
->abbrev_sect_off
)
6264 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
, abbrev_section
))
6265 error (_("Dwarf Error: bad offset (%s) in compilation unit header "
6266 "(offset %s + 6) [in module %s]"),
6267 sect_offset_str (header
->abbrev_sect_off
),
6268 sect_offset_str (header
->sect_off
),
6271 /* Cast to ULONGEST to use 64-bit arithmetic when possible to
6272 avoid potential 32-bit overflow. */
6273 if (((ULONGEST
) header
->sect_off
+ get_cu_length (header
))
6275 error (_("Dwarf Error: bad length (0x%x) in compilation unit header "
6276 "(offset %s + 0) [in module %s]"),
6277 header
->length
, sect_offset_str (header
->sect_off
),
6281 /* Read in a CU/TU header and perform some basic error checking.
6282 The contents of the header are stored in HEADER.
6283 The result is a pointer to the start of the first DIE. */
6285 static const gdb_byte
*
6286 read_and_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6287 struct comp_unit_head
*header
,
6288 struct dwarf2_section_info
*section
,
6289 struct dwarf2_section_info
*abbrev_section
,
6290 const gdb_byte
*info_ptr
,
6291 rcuh_kind section_kind
)
6293 const gdb_byte
*beg_of_comp_unit
= info_ptr
;
6295 header
->sect_off
= (sect_offset
) (beg_of_comp_unit
- section
->buffer
);
6297 info_ptr
= read_comp_unit_head (header
, info_ptr
, section
, section_kind
);
6299 header
->first_die_cu_offset
= (cu_offset
) (info_ptr
- beg_of_comp_unit
);
6301 error_check_comp_unit_head (dwarf2_per_objfile
, header
, section
,
6307 /* Fetch the abbreviation table offset from a comp or type unit header. */
6310 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6311 struct dwarf2_section_info
*section
,
6312 sect_offset sect_off
)
6314 bfd
*abfd
= section
->get_bfd_owner ();
6315 const gdb_byte
*info_ptr
;
6316 unsigned int initial_length_size
, offset_size
;
6319 section
->read (dwarf2_per_objfile
->objfile
);
6320 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
6321 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6322 offset_size
= initial_length_size
== 4 ? 4 : 8;
6323 info_ptr
+= initial_length_size
;
6325 version
= read_2_bytes (abfd
, info_ptr
);
6329 /* Skip unit type and address size. */
6333 return (sect_offset
) read_offset_1 (abfd
, info_ptr
, offset_size
);
6336 /* Allocate a new partial symtab for file named NAME and mark this new
6337 partial symtab as being an include of PST. */
6340 dwarf2_create_include_psymtab (const char *name
, dwarf2_psymtab
*pst
,
6341 struct objfile
*objfile
)
6343 dwarf2_psymtab
*subpst
= new dwarf2_psymtab (name
, objfile
);
6345 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6347 /* It shares objfile->objfile_obstack. */
6348 subpst
->dirname
= pst
->dirname
;
6351 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
6352 subpst
->dependencies
[0] = pst
;
6353 subpst
->number_of_dependencies
= 1;
6355 /* No private part is necessary for include psymtabs. This property
6356 can be used to differentiate between such include psymtabs and
6357 the regular ones. */
6358 subpst
->per_cu_data
= nullptr;
6361 /* Read the Line Number Program data and extract the list of files
6362 included by the source file represented by PST. Build an include
6363 partial symtab for each of these included files. */
6366 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
6367 struct die_info
*die
,
6368 dwarf2_psymtab
*pst
)
6371 struct attribute
*attr
;
6373 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6374 if (attr
!= nullptr)
6375 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
6377 return; /* No linetable, so no includes. */
6379 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
6380 that we pass in the raw text_low here; that is ok because we're
6381 only decoding the line table to make include partial symtabs, and
6382 so the addresses aren't really used. */
6383 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
6384 pst
->raw_text_low (), 1);
6388 hash_signatured_type (const void *item
)
6390 const struct signatured_type
*sig_type
6391 = (const struct signatured_type
*) item
;
6393 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6394 return sig_type
->signature
;
6398 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6400 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6401 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6403 return lhs
->signature
== rhs
->signature
;
6406 /* Allocate a hash table for signatured types. */
6409 allocate_signatured_type_table (struct objfile
*objfile
)
6411 return htab_up (htab_create_alloc (41,
6412 hash_signatured_type
,
6414 NULL
, xcalloc
, xfree
));
6417 /* A helper function to add a signatured type CU to a table. */
6420 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6422 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6423 std::vector
<signatured_type
*> *all_type_units
6424 = (std::vector
<signatured_type
*> *) datum
;
6426 all_type_units
->push_back (sigt
);
6431 /* A helper for create_debug_types_hash_table. Read types from SECTION
6432 and fill them into TYPES_HTAB. It will process only type units,
6433 therefore DW_UT_type. */
6436 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6437 struct dwo_file
*dwo_file
,
6438 dwarf2_section_info
*section
, htab_up
&types_htab
,
6439 rcuh_kind section_kind
)
6441 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6442 struct dwarf2_section_info
*abbrev_section
;
6444 const gdb_byte
*info_ptr
, *end_ptr
;
6446 abbrev_section
= (dwo_file
!= NULL
6447 ? &dwo_file
->sections
.abbrev
6448 : &dwarf2_per_objfile
->abbrev
);
6450 if (dwarf_read_debug
)
6451 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6452 section
->get_name (),
6453 abbrev_section
->get_file_name ());
6455 section
->read (objfile
);
6456 info_ptr
= section
->buffer
;
6458 if (info_ptr
== NULL
)
6461 /* We can't set abfd until now because the section may be empty or
6462 not present, in which case the bfd is unknown. */
6463 abfd
= section
->get_bfd_owner ();
6465 /* We don't use cutu_reader here because we don't need to read
6466 any dies: the signature is in the header. */
6468 end_ptr
= info_ptr
+ section
->size
;
6469 while (info_ptr
< end_ptr
)
6471 struct signatured_type
*sig_type
;
6472 struct dwo_unit
*dwo_tu
;
6474 const gdb_byte
*ptr
= info_ptr
;
6475 struct comp_unit_head header
;
6476 unsigned int length
;
6478 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6480 /* Initialize it due to a false compiler warning. */
6481 header
.signature
= -1;
6482 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6484 /* We need to read the type's signature in order to build the hash
6485 table, but we don't need anything else just yet. */
6487 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
6488 abbrev_section
, ptr
, section_kind
);
6490 length
= get_cu_length (&header
);
6492 /* Skip dummy type units. */
6493 if (ptr
>= info_ptr
+ length
6494 || peek_abbrev_code (abfd
, ptr
) == 0
6495 || header
.unit_type
!= DW_UT_type
)
6501 if (types_htab
== NULL
)
6504 types_htab
= allocate_dwo_unit_table (objfile
);
6506 types_htab
= allocate_signatured_type_table (objfile
);
6512 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6514 dwo_tu
->dwo_file
= dwo_file
;
6515 dwo_tu
->signature
= header
.signature
;
6516 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6517 dwo_tu
->section
= section
;
6518 dwo_tu
->sect_off
= sect_off
;
6519 dwo_tu
->length
= length
;
6523 /* N.B.: type_offset is not usable if this type uses a DWO file.
6524 The real type_offset is in the DWO file. */
6526 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6527 struct signatured_type
);
6528 sig_type
->signature
= header
.signature
;
6529 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6530 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6531 sig_type
->per_cu
.is_debug_types
= 1;
6532 sig_type
->per_cu
.section
= section
;
6533 sig_type
->per_cu
.sect_off
= sect_off
;
6534 sig_type
->per_cu
.length
= length
;
6537 slot
= htab_find_slot (types_htab
.get (),
6538 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6540 gdb_assert (slot
!= NULL
);
6543 sect_offset dup_sect_off
;
6547 const struct dwo_unit
*dup_tu
6548 = (const struct dwo_unit
*) *slot
;
6550 dup_sect_off
= dup_tu
->sect_off
;
6554 const struct signatured_type
*dup_tu
6555 = (const struct signatured_type
*) *slot
;
6557 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6560 complaint (_("debug type entry at offset %s is duplicate to"
6561 " the entry at offset %s, signature %s"),
6562 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6563 hex_string (header
.signature
));
6565 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6567 if (dwarf_read_debug
> 1)
6568 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6569 sect_offset_str (sect_off
),
6570 hex_string (header
.signature
));
6576 /* Create the hash table of all entries in the .debug_types
6577 (or .debug_types.dwo) section(s).
6578 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6579 otherwise it is NULL.
6581 The result is a pointer to the hash table or NULL if there are no types.
6583 Note: This function processes DWO files only, not DWP files. */
6586 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6587 struct dwo_file
*dwo_file
,
6588 gdb::array_view
<dwarf2_section_info
> type_sections
,
6589 htab_up
&types_htab
)
6591 for (dwarf2_section_info
§ion
: type_sections
)
6592 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, §ion
,
6593 types_htab
, rcuh_kind::TYPE
);
6596 /* Create the hash table of all entries in the .debug_types section,
6597 and initialize all_type_units.
6598 The result is zero if there is an error (e.g. missing .debug_types section),
6599 otherwise non-zero. */
6602 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6606 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
6607 &dwarf2_per_objfile
->info
, types_htab
,
6608 rcuh_kind::COMPILE
);
6609 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
6610 dwarf2_per_objfile
->types
, types_htab
);
6611 if (types_htab
== NULL
)
6613 dwarf2_per_objfile
->signatured_types
= NULL
;
6617 dwarf2_per_objfile
->signatured_types
= std::move (types_htab
);
6619 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
6620 dwarf2_per_objfile
->all_type_units
.reserve
6621 (htab_elements (dwarf2_per_objfile
->signatured_types
.get ()));
6623 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
.get (),
6624 add_signatured_type_cu_to_table
,
6625 &dwarf2_per_objfile
->all_type_units
);
6630 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
6631 If SLOT is non-NULL, it is the entry to use in the hash table.
6632 Otherwise we find one. */
6634 static struct signatured_type
*
6635 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
6638 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6640 if (dwarf2_per_objfile
->all_type_units
.size ()
6641 == dwarf2_per_objfile
->all_type_units
.capacity ())
6642 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
6644 signatured_type
*sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6645 struct signatured_type
);
6647 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
6648 sig_type
->signature
= sig
;
6649 sig_type
->per_cu
.is_debug_types
= 1;
6650 if (dwarf2_per_objfile
->using_index
)
6652 sig_type
->per_cu
.v
.quick
=
6653 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6654 struct dwarf2_per_cu_quick_data
);
6659 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6662 gdb_assert (*slot
== NULL
);
6664 /* The rest of sig_type must be filled in by the caller. */
6668 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6669 Fill in SIG_ENTRY with DWO_ENTRY. */
6672 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6673 struct signatured_type
*sig_entry
,
6674 struct dwo_unit
*dwo_entry
)
6676 /* Make sure we're not clobbering something we don't expect to. */
6677 gdb_assert (! sig_entry
->per_cu
.queued
);
6678 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
6679 if (dwarf2_per_objfile
->using_index
)
6681 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6682 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
6685 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6686 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6687 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6688 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6689 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6691 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6692 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6693 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6694 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6695 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6696 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6697 sig_entry
->dwo_unit
= dwo_entry
;
6700 /* Subroutine of lookup_signatured_type.
6701 If we haven't read the TU yet, create the signatured_type data structure
6702 for a TU to be read in directly from a DWO file, bypassing the stub.
6703 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6704 using .gdb_index, then when reading a CU we want to stay in the DWO file
6705 containing that CU. Otherwise we could end up reading several other DWO
6706 files (due to comdat folding) to process the transitive closure of all the
6707 mentioned TUs, and that can be slow. The current DWO file will have every
6708 type signature that it needs.
6709 We only do this for .gdb_index because in the psymtab case we already have
6710 to read all the DWOs to build the type unit groups. */
6712 static struct signatured_type
*
6713 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6715 struct dwarf2_per_objfile
*dwarf2_per_objfile
6716 = cu
->per_cu
->dwarf2_per_objfile
;
6717 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6718 struct dwo_file
*dwo_file
;
6719 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6720 struct signatured_type find_sig_entry
, *sig_entry
;
6723 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6725 /* If TU skeletons have been removed then we may not have read in any
6727 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6729 dwarf2_per_objfile
->signatured_types
6730 = allocate_signatured_type_table (objfile
);
6733 /* We only ever need to read in one copy of a signatured type.
6734 Use the global signatured_types array to do our own comdat-folding
6735 of types. If this is the first time we're reading this TU, and
6736 the TU has an entry in .gdb_index, replace the recorded data from
6737 .gdb_index with this TU. */
6739 find_sig_entry
.signature
= sig
;
6740 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6741 &find_sig_entry
, INSERT
);
6742 sig_entry
= (struct signatured_type
*) *slot
;
6744 /* We can get here with the TU already read, *or* in the process of being
6745 read. Don't reassign the global entry to point to this DWO if that's
6746 the case. Also note that if the TU is already being read, it may not
6747 have come from a DWO, the program may be a mix of Fission-compiled
6748 code and non-Fission-compiled code. */
6750 /* Have we already tried to read this TU?
6751 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6752 needn't exist in the global table yet). */
6753 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
6756 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6757 dwo_unit of the TU itself. */
6758 dwo_file
= cu
->dwo_unit
->dwo_file
;
6760 /* Ok, this is the first time we're reading this TU. */
6761 if (dwo_file
->tus
== NULL
)
6763 find_dwo_entry
.signature
= sig
;
6764 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6766 if (dwo_entry
== NULL
)
6769 /* If the global table doesn't have an entry for this TU, add one. */
6770 if (sig_entry
== NULL
)
6771 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6773 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6774 sig_entry
->per_cu
.tu_read
= 1;
6778 /* Subroutine of lookup_signatured_type.
6779 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6780 then try the DWP file. If the TU stub (skeleton) has been removed then
6781 it won't be in .gdb_index. */
6783 static struct signatured_type
*
6784 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6786 struct dwarf2_per_objfile
*dwarf2_per_objfile
6787 = cu
->per_cu
->dwarf2_per_objfile
;
6788 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6789 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
6790 struct dwo_unit
*dwo_entry
;
6791 struct signatured_type find_sig_entry
, *sig_entry
;
6794 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6795 gdb_assert (dwp_file
!= NULL
);
6797 /* If TU skeletons have been removed then we may not have read in any
6799 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6801 dwarf2_per_objfile
->signatured_types
6802 = allocate_signatured_type_table (objfile
);
6805 find_sig_entry
.signature
= sig
;
6806 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6807 &find_sig_entry
, INSERT
);
6808 sig_entry
= (struct signatured_type
*) *slot
;
6810 /* Have we already tried to read this TU?
6811 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6812 needn't exist in the global table yet). */
6813 if (sig_entry
!= NULL
)
6816 if (dwp_file
->tus
== NULL
)
6818 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
6819 sig
, 1 /* is_debug_types */);
6820 if (dwo_entry
== NULL
)
6823 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6824 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6829 /* Lookup a signature based type for DW_FORM_ref_sig8.
6830 Returns NULL if signature SIG is not present in the table.
6831 It is up to the caller to complain about this. */
6833 static struct signatured_type
*
6834 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6836 struct dwarf2_per_objfile
*dwarf2_per_objfile
6837 = cu
->per_cu
->dwarf2_per_objfile
;
6840 && dwarf2_per_objfile
->using_index
)
6842 /* We're in a DWO/DWP file, and we're using .gdb_index.
6843 These cases require special processing. */
6844 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
6845 return lookup_dwo_signatured_type (cu
, sig
);
6847 return lookup_dwp_signatured_type (cu
, sig
);
6851 struct signatured_type find_entry
, *entry
;
6853 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6855 find_entry
.signature
= sig
;
6856 entry
= ((struct signatured_type
*)
6857 htab_find (dwarf2_per_objfile
->signatured_types
.get (),
6863 /* Return the address base of the compile unit, which, if exists, is stored
6864 either at the attribute DW_AT_GNU_addr_base, or DW_AT_addr_base. */
6865 static gdb::optional
<ULONGEST
>
6866 lookup_addr_base (struct die_info
*comp_unit_die
)
6868 struct attribute
*attr
;
6869 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_addr_base
);
6870 if (attr
== nullptr)
6871 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_GNU_addr_base
);
6872 if (attr
== nullptr)
6873 return gdb::optional
<ULONGEST
> ();
6874 return DW_UNSND (attr
);
6877 /* Return range lists base of the compile unit, which, if exists, is stored
6878 either at the attribute DW_AT_rnglists_base or DW_AT_GNU_ranges_base. */
6880 lookup_ranges_base (struct die_info
*comp_unit_die
)
6882 struct attribute
*attr
;
6883 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_rnglists_base
);
6884 if (attr
== nullptr)
6885 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_GNU_ranges_base
);
6886 if (attr
== nullptr)
6888 return DW_UNSND (attr
);
6891 /* Low level DIE reading support. */
6893 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6896 init_cu_die_reader (struct die_reader_specs
*reader
,
6897 struct dwarf2_cu
*cu
,
6898 struct dwarf2_section_info
*section
,
6899 struct dwo_file
*dwo_file
,
6900 struct abbrev_table
*abbrev_table
)
6902 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6903 reader
->abfd
= section
->get_bfd_owner ();
6905 reader
->dwo_file
= dwo_file
;
6906 reader
->die_section
= section
;
6907 reader
->buffer
= section
->buffer
;
6908 reader
->buffer_end
= section
->buffer
+ section
->size
;
6909 reader
->abbrev_table
= abbrev_table
;
6912 /* Subroutine of cutu_reader to simplify it.
6913 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6914 There's just a lot of work to do, and cutu_reader is big enough
6917 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6918 from it to the DIE in the DWO. If NULL we are skipping the stub.
6919 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6920 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6921 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6922 STUB_COMP_DIR may be non-NULL.
6923 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6924 are filled in with the info of the DIE from the DWO file.
6925 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6926 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6927 kept around for at least as long as *RESULT_READER.
6929 The result is non-zero if a valid (non-dummy) DIE was found. */
6932 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
6933 struct dwo_unit
*dwo_unit
,
6934 struct die_info
*stub_comp_unit_die
,
6935 const char *stub_comp_dir
,
6936 struct die_reader_specs
*result_reader
,
6937 const gdb_byte
**result_info_ptr
,
6938 struct die_info
**result_comp_unit_die
,
6939 abbrev_table_up
*result_dwo_abbrev_table
)
6941 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6942 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6943 struct dwarf2_cu
*cu
= this_cu
->cu
;
6945 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6946 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6947 int i
,num_extra_attrs
;
6948 struct dwarf2_section_info
*dwo_abbrev_section
;
6949 struct die_info
*comp_unit_die
;
6951 /* At most one of these may be provided. */
6952 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6954 /* These attributes aren't processed until later:
6955 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6956 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6957 referenced later. However, these attributes are found in the stub
6958 which we won't have later. In order to not impose this complication
6959 on the rest of the code, we read them here and copy them to the
6968 if (stub_comp_unit_die
!= NULL
)
6970 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6972 if (! this_cu
->is_debug_types
)
6973 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6974 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6975 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6976 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6977 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6979 cu
->addr_base
= lookup_addr_base (stub_comp_unit_die
);
6981 /* There should be a DW_AT_rnglists_base (DW_AT_GNU_ranges_base) attribute
6982 here (if needed). We need the value before we can process
6984 cu
->ranges_base
= lookup_ranges_base (stub_comp_unit_die
);
6986 else if (stub_comp_dir
!= NULL
)
6988 /* Reconstruct the comp_dir attribute to simplify the code below. */
6989 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
6990 comp_dir
->name
= DW_AT_comp_dir
;
6991 comp_dir
->form
= DW_FORM_string
;
6992 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
6993 DW_STRING (comp_dir
) = stub_comp_dir
;
6996 /* Set up for reading the DWO CU/TU. */
6997 cu
->dwo_unit
= dwo_unit
;
6998 dwarf2_section_info
*section
= dwo_unit
->section
;
6999 section
->read (objfile
);
7000 abfd
= section
->get_bfd_owner ();
7001 begin_info_ptr
= info_ptr
= (section
->buffer
7002 + to_underlying (dwo_unit
->sect_off
));
7003 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
7005 if (this_cu
->is_debug_types
)
7007 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
7009 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7010 &cu
->header
, section
,
7012 info_ptr
, rcuh_kind::TYPE
);
7013 /* This is not an assert because it can be caused by bad debug info. */
7014 if (sig_type
->signature
!= cu
->header
.signature
)
7016 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
7017 " TU at offset %s [in module %s]"),
7018 hex_string (sig_type
->signature
),
7019 hex_string (cu
->header
.signature
),
7020 sect_offset_str (dwo_unit
->sect_off
),
7021 bfd_get_filename (abfd
));
7023 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7024 /* For DWOs coming from DWP files, we don't know the CU length
7025 nor the type's offset in the TU until now. */
7026 dwo_unit
->length
= get_cu_length (&cu
->header
);
7027 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
7029 /* Establish the type offset that can be used to lookup the type.
7030 For DWO files, we don't know it until now. */
7031 sig_type
->type_offset_in_section
7032 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
7036 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7037 &cu
->header
, section
,
7039 info_ptr
, rcuh_kind::COMPILE
);
7040 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7041 /* For DWOs coming from DWP files, we don't know the CU length
7043 dwo_unit
->length
= get_cu_length (&cu
->header
);
7046 *result_dwo_abbrev_table
7047 = abbrev_table::read (objfile
, dwo_abbrev_section
,
7048 cu
->header
.abbrev_sect_off
);
7049 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
7050 result_dwo_abbrev_table
->get ());
7052 /* Read in the die, but leave space to copy over the attributes
7053 from the stub. This has the benefit of simplifying the rest of
7054 the code - all the work to maintain the illusion of a single
7055 DW_TAG_{compile,type}_unit DIE is done here. */
7056 num_extra_attrs
= ((stmt_list
!= NULL
)
7060 + (comp_dir
!= NULL
));
7061 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
7064 /* Copy over the attributes from the stub to the DIE we just read in. */
7065 comp_unit_die
= *result_comp_unit_die
;
7066 i
= comp_unit_die
->num_attrs
;
7067 if (stmt_list
!= NULL
)
7068 comp_unit_die
->attrs
[i
++] = *stmt_list
;
7070 comp_unit_die
->attrs
[i
++] = *low_pc
;
7071 if (high_pc
!= NULL
)
7072 comp_unit_die
->attrs
[i
++] = *high_pc
;
7074 comp_unit_die
->attrs
[i
++] = *ranges
;
7075 if (comp_dir
!= NULL
)
7076 comp_unit_die
->attrs
[i
++] = *comp_dir
;
7077 comp_unit_die
->num_attrs
+= num_extra_attrs
;
7079 if (dwarf_die_debug
)
7081 fprintf_unfiltered (gdb_stdlog
,
7082 "Read die from %s@0x%x of %s:\n",
7083 section
->get_name (),
7084 (unsigned) (begin_info_ptr
- section
->buffer
),
7085 bfd_get_filename (abfd
));
7086 dump_die (comp_unit_die
, dwarf_die_debug
);
7089 /* Skip dummy compilation units. */
7090 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
7091 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7094 *result_info_ptr
= info_ptr
;
7098 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
7099 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
7100 signature is part of the header. */
7101 static gdb::optional
<ULONGEST
>
7102 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
7104 if (cu
->header
.version
>= 5)
7105 return cu
->header
.signature
;
7106 struct attribute
*attr
;
7107 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
7108 if (attr
== nullptr)
7109 return gdb::optional
<ULONGEST
> ();
7110 return DW_UNSND (attr
);
7113 /* Subroutine of cutu_reader to simplify it.
7114 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
7115 Returns NULL if the specified DWO unit cannot be found. */
7117 static struct dwo_unit
*
7118 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
7119 struct die_info
*comp_unit_die
,
7120 const char *dwo_name
)
7122 struct dwarf2_cu
*cu
= this_cu
->cu
;
7123 struct dwo_unit
*dwo_unit
;
7124 const char *comp_dir
;
7126 gdb_assert (cu
!= NULL
);
7128 /* Yeah, we look dwo_name up again, but it simplifies the code. */
7129 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7130 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7132 if (this_cu
->is_debug_types
)
7134 struct signatured_type
*sig_type
;
7136 /* Since this_cu is the first member of struct signatured_type,
7137 we can go from a pointer to one to a pointer to the other. */
7138 sig_type
= (struct signatured_type
*) this_cu
;
7139 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
7143 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
7144 if (!signature
.has_value ())
7145 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
7147 dwo_name
, objfile_name (this_cu
->dwarf2_per_objfile
->objfile
));
7148 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
7155 /* Subroutine of cutu_reader to simplify it.
7156 See it for a description of the parameters.
7157 Read a TU directly from a DWO file, bypassing the stub. */
7160 cutu_reader::init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
7161 int use_existing_cu
, int keep
)
7163 struct signatured_type
*sig_type
;
7164 struct die_reader_specs reader
;
7166 /* Verify we can do the following downcast, and that we have the
7168 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
7169 sig_type
= (struct signatured_type
*) this_cu
;
7170 gdb_assert (sig_type
->dwo_unit
!= NULL
);
7172 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7174 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
7175 /* There's no need to do the rereading_dwo_cu handling that
7176 cutu_reader does since we don't read the stub. */
7180 /* If !use_existing_cu, this_cu->cu must be NULL. */
7181 gdb_assert (this_cu
->cu
== NULL
);
7182 m_new_cu
.reset (new dwarf2_cu (this_cu
));
7185 /* A future optimization, if needed, would be to use an existing
7186 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
7187 could share abbrev tables. */
7189 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
7190 NULL
/* stub_comp_unit_die */,
7191 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
7194 &m_dwo_abbrev_table
) == 0)
7201 /* Initialize a CU (or TU) and read its DIEs.
7202 If the CU defers to a DWO file, read the DWO file as well.
7204 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
7205 Otherwise the table specified in the comp unit header is read in and used.
7206 This is an optimization for when we already have the abbrev table.
7208 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
7209 Otherwise, a new CU is allocated with xmalloc.
7211 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
7212 read_in_chain. Otherwise the dwarf2_cu data is freed at the
7215 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
7216 struct abbrev_table
*abbrev_table
,
7217 int use_existing_cu
, int keep
,
7219 : die_reader_specs
{},
7220 m_this_cu (this_cu
),
7223 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7224 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7225 struct dwarf2_section_info
*section
= this_cu
->section
;
7226 bfd
*abfd
= section
->get_bfd_owner ();
7227 struct dwarf2_cu
*cu
;
7228 const gdb_byte
*begin_info_ptr
;
7229 struct signatured_type
*sig_type
= NULL
;
7230 struct dwarf2_section_info
*abbrev_section
;
7231 /* Non-zero if CU currently points to a DWO file and we need to
7232 reread it. When this happens we need to reread the skeleton die
7233 before we can reread the DWO file (this only applies to CUs, not TUs). */
7234 int rereading_dwo_cu
= 0;
7236 if (dwarf_die_debug
)
7237 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7238 this_cu
->is_debug_types
? "type" : "comp",
7239 sect_offset_str (this_cu
->sect_off
));
7241 if (use_existing_cu
)
7244 /* If we're reading a TU directly from a DWO file, including a virtual DWO
7245 file (instead of going through the stub), short-circuit all of this. */
7246 if (this_cu
->reading_dwo_directly
)
7248 /* Narrow down the scope of possibilities to have to understand. */
7249 gdb_assert (this_cu
->is_debug_types
);
7250 gdb_assert (abbrev_table
== NULL
);
7251 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
, keep
);
7255 /* This is cheap if the section is already read in. */
7256 section
->read (objfile
);
7258 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7260 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
7262 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7265 /* If this CU is from a DWO file we need to start over, we need to
7266 refetch the attributes from the skeleton CU.
7267 This could be optimized by retrieving those attributes from when we
7268 were here the first time: the previous comp_unit_die was stored in
7269 comp_unit_obstack. But there's no data yet that we need this
7271 if (cu
->dwo_unit
!= NULL
)
7272 rereading_dwo_cu
= 1;
7276 /* If !use_existing_cu, this_cu->cu must be NULL. */
7277 gdb_assert (this_cu
->cu
== NULL
);
7278 m_new_cu
.reset (new dwarf2_cu (this_cu
));
7279 cu
= m_new_cu
.get ();
7282 /* Get the header. */
7283 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
7285 /* We already have the header, there's no need to read it in again. */
7286 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
7290 if (this_cu
->is_debug_types
)
7292 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7293 &cu
->header
, section
,
7294 abbrev_section
, info_ptr
,
7297 /* Since per_cu is the first member of struct signatured_type,
7298 we can go from a pointer to one to a pointer to the other. */
7299 sig_type
= (struct signatured_type
*) this_cu
;
7300 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
7301 gdb_assert (sig_type
->type_offset_in_tu
7302 == cu
->header
.type_cu_offset_in_tu
);
7303 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7305 /* LENGTH has not been set yet for type units if we're
7306 using .gdb_index. */
7307 this_cu
->length
= get_cu_length (&cu
->header
);
7309 /* Establish the type offset that can be used to lookup the type. */
7310 sig_type
->type_offset_in_section
=
7311 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
7313 this_cu
->dwarf_version
= cu
->header
.version
;
7317 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7318 &cu
->header
, section
,
7321 rcuh_kind::COMPILE
);
7323 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7324 gdb_assert (this_cu
->length
== get_cu_length (&cu
->header
));
7325 this_cu
->dwarf_version
= cu
->header
.version
;
7329 /* Skip dummy compilation units. */
7330 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7331 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7337 /* If we don't have them yet, read the abbrevs for this compilation unit.
7338 And if we need to read them now, make sure they're freed when we're
7340 if (abbrev_table
!= NULL
)
7341 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
7344 m_abbrev_table_holder
7345 = abbrev_table::read (objfile
, abbrev_section
,
7346 cu
->header
.abbrev_sect_off
);
7347 abbrev_table
= m_abbrev_table_holder
.get ();
7350 /* Read the top level CU/TU die. */
7351 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
7352 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7354 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
7360 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
7361 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
7362 table from the DWO file and pass the ownership over to us. It will be
7363 referenced from READER, so we must make sure to free it after we're done
7366 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
7367 DWO CU, that this test will fail (the attribute will not be present). */
7368 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7369 if (dwo_name
!= nullptr)
7371 struct dwo_unit
*dwo_unit
;
7372 struct die_info
*dwo_comp_unit_die
;
7374 if (comp_unit_die
->has_children
)
7376 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
7377 " has children (offset %s) [in module %s]"),
7378 sect_offset_str (this_cu
->sect_off
),
7379 bfd_get_filename (abfd
));
7381 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
, dwo_name
);
7382 if (dwo_unit
!= NULL
)
7384 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
7385 comp_unit_die
, NULL
,
7388 &m_dwo_abbrev_table
) == 0)
7394 comp_unit_die
= dwo_comp_unit_die
;
7398 /* Yikes, we couldn't find the rest of the DIE, we only have
7399 the stub. A complaint has already been logged. There's
7400 not much more we can do except pass on the stub DIE to
7401 die_reader_func. We don't want to throw an error on bad
7407 cutu_reader::~cutu_reader ()
7409 /* Done, clean up. */
7410 if (m_new_cu
!= NULL
&& m_keep
&& !dummy_p
)
7412 struct dwarf2_per_objfile
*dwarf2_per_objfile
7413 = m_this_cu
->dwarf2_per_objfile
;
7414 /* Link this CU into read_in_chain. */
7415 m_this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
7416 dwarf2_per_objfile
->read_in_chain
= m_this_cu
;
7417 /* The chain owns it now. */
7418 m_new_cu
.release ();
7422 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
7423 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
7424 assumed to have already done the lookup to find the DWO file).
7426 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7427 THIS_CU->is_debug_types, but nothing else.
7429 We fill in THIS_CU->length.
7431 THIS_CU->cu is always freed when done.
7432 This is done in order to not leave THIS_CU->cu in a state where we have
7433 to care whether it refers to the "main" CU or the DWO CU.
7435 When parent_cu is passed, it is used to provide a default value for
7436 str_offsets_base and addr_base from the parent. */
7438 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
7439 struct dwarf2_cu
*parent_cu
,
7440 struct dwo_file
*dwo_file
)
7441 : die_reader_specs
{},
7444 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7445 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7446 struct dwarf2_section_info
*section
= this_cu
->section
;
7447 bfd
*abfd
= section
->get_bfd_owner ();
7448 struct dwarf2_section_info
*abbrev_section
;
7449 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7451 if (dwarf_die_debug
)
7452 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7453 this_cu
->is_debug_types
? "type" : "comp",
7454 sect_offset_str (this_cu
->sect_off
));
7456 gdb_assert (this_cu
->cu
== NULL
);
7458 abbrev_section
= (dwo_file
!= NULL
7459 ? &dwo_file
->sections
.abbrev
7460 : get_abbrev_section_for_cu (this_cu
));
7462 /* This is cheap if the section is already read in. */
7463 section
->read (objfile
);
7465 m_new_cu
.reset (new dwarf2_cu (this_cu
));
7467 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7468 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7469 &m_new_cu
->header
, section
,
7470 abbrev_section
, info_ptr
,
7471 (this_cu
->is_debug_types
7473 : rcuh_kind::COMPILE
));
7475 if (parent_cu
!= nullptr)
7477 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
7478 m_new_cu
->addr_base
= parent_cu
->addr_base
;
7480 this_cu
->length
= get_cu_length (&m_new_cu
->header
);
7482 /* Skip dummy compilation units. */
7483 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7484 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7490 m_abbrev_table_holder
7491 = abbrev_table::read (objfile
, abbrev_section
,
7492 m_new_cu
->header
.abbrev_sect_off
);
7494 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
7495 m_abbrev_table_holder
.get ());
7496 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7500 /* Type Unit Groups.
7502 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7503 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7504 so that all types coming from the same compilation (.o file) are grouped
7505 together. A future step could be to put the types in the same symtab as
7506 the CU the types ultimately came from. */
7509 hash_type_unit_group (const void *item
)
7511 const struct type_unit_group
*tu_group
7512 = (const struct type_unit_group
*) item
;
7514 return hash_stmt_list_entry (&tu_group
->hash
);
7518 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7520 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7521 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7523 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7526 /* Allocate a hash table for type unit groups. */
7529 allocate_type_unit_groups_table (struct objfile
*objfile
)
7531 return htab_up (htab_create_alloc (3,
7532 hash_type_unit_group
,
7534 NULL
, xcalloc
, xfree
));
7537 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7538 partial symtabs. We combine several TUs per psymtab to not let the size
7539 of any one psymtab grow too big. */
7540 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7541 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7543 /* Helper routine for get_type_unit_group.
7544 Create the type_unit_group object used to hold one or more TUs. */
7546 static struct type_unit_group
*
7547 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7549 struct dwarf2_per_objfile
*dwarf2_per_objfile
7550 = cu
->per_cu
->dwarf2_per_objfile
;
7551 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7552 struct dwarf2_per_cu_data
*per_cu
;
7553 struct type_unit_group
*tu_group
;
7555 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7556 struct type_unit_group
);
7557 per_cu
= &tu_group
->per_cu
;
7558 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7560 if (dwarf2_per_objfile
->using_index
)
7562 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7563 struct dwarf2_per_cu_quick_data
);
7567 unsigned int line_offset
= to_underlying (line_offset_struct
);
7568 dwarf2_psymtab
*pst
;
7571 /* Give the symtab a useful name for debug purposes. */
7572 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7573 name
= string_printf ("<type_units_%d>",
7574 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7576 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7578 pst
= create_partial_symtab (per_cu
, name
.c_str ());
7579 pst
->anonymous
= true;
7582 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7583 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7588 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7589 STMT_LIST is a DW_AT_stmt_list attribute. */
7591 static struct type_unit_group
*
7592 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7594 struct dwarf2_per_objfile
*dwarf2_per_objfile
7595 = cu
->per_cu
->dwarf2_per_objfile
;
7596 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7597 struct type_unit_group
*tu_group
;
7599 unsigned int line_offset
;
7600 struct type_unit_group type_unit_group_for_lookup
;
7602 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
7604 dwarf2_per_objfile
->type_unit_groups
=
7605 allocate_type_unit_groups_table (dwarf2_per_objfile
->objfile
);
7608 /* Do we need to create a new group, or can we use an existing one? */
7612 line_offset
= DW_UNSND (stmt_list
);
7613 ++tu_stats
->nr_symtab_sharers
;
7617 /* Ugh, no stmt_list. Rare, but we have to handle it.
7618 We can do various things here like create one group per TU or
7619 spread them over multiple groups to split up the expansion work.
7620 To avoid worst case scenarios (too many groups or too large groups)
7621 we, umm, group them in bunches. */
7622 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7623 | (tu_stats
->nr_stmt_less_type_units
7624 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7625 ++tu_stats
->nr_stmt_less_type_units
;
7628 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7629 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7630 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
.get (),
7631 &type_unit_group_for_lookup
, INSERT
);
7634 tu_group
= (struct type_unit_group
*) *slot
;
7635 gdb_assert (tu_group
!= NULL
);
7639 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7640 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7642 ++tu_stats
->nr_symtabs
;
7648 /* Partial symbol tables. */
7650 /* Create a psymtab named NAME and assign it to PER_CU.
7652 The caller must fill in the following details:
7653 dirname, textlow, texthigh. */
7655 static dwarf2_psymtab
*
7656 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
7658 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
7659 dwarf2_psymtab
*pst
;
7661 pst
= new dwarf2_psymtab (name
, objfile
, 0);
7663 pst
->psymtabs_addrmap_supported
= true;
7665 /* This is the glue that links PST into GDB's symbol API. */
7666 pst
->per_cu_data
= per_cu
;
7667 per_cu
->v
.psymtab
= pst
;
7672 /* DIE reader function for process_psymtab_comp_unit. */
7675 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7676 const gdb_byte
*info_ptr
,
7677 struct die_info
*comp_unit_die
,
7678 int want_partial_unit
,
7679 enum language pretend_language
)
7681 struct dwarf2_cu
*cu
= reader
->cu
;
7682 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
7683 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7684 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7686 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7687 dwarf2_psymtab
*pst
;
7688 enum pc_bounds_kind cu_bounds_kind
;
7689 const char *filename
;
7691 if (comp_unit_die
->tag
== DW_TAG_partial_unit
&& !want_partial_unit
)
7694 gdb_assert (! per_cu
->is_debug_types
);
7696 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
7698 /* Allocate a new partial symbol table structure. */
7699 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7700 if (filename
== NULL
)
7703 pst
= create_partial_symtab (per_cu
, filename
);
7705 /* This must be done before calling dwarf2_build_include_psymtabs. */
7706 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7708 baseaddr
= objfile
->text_section_offset ();
7710 dwarf2_find_base_address (comp_unit_die
, cu
);
7712 /* Possibly set the default values of LOWPC and HIGHPC from
7714 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7715 &best_highpc
, cu
, pst
);
7716 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7719 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7722 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7724 /* Store the contiguous range if it is not empty; it can be
7725 empty for CUs with no code. */
7726 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
7730 /* Check if comp unit has_children.
7731 If so, read the rest of the partial symbols from this comp unit.
7732 If not, there's no more debug_info for this comp unit. */
7733 if (comp_unit_die
->has_children
)
7735 struct partial_die_info
*first_die
;
7736 CORE_ADDR lowpc
, highpc
;
7738 lowpc
= ((CORE_ADDR
) -1);
7739 highpc
= ((CORE_ADDR
) 0);
7741 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7743 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7744 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7746 /* If we didn't find a lowpc, set it to highpc to avoid
7747 complaints from `maint check'. */
7748 if (lowpc
== ((CORE_ADDR
) -1))
7751 /* If the compilation unit didn't have an explicit address range,
7752 then use the information extracted from its child dies. */
7753 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7756 best_highpc
= highpc
;
7759 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7760 best_lowpc
+ baseaddr
)
7762 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7763 best_highpc
+ baseaddr
)
7766 end_psymtab_common (objfile
, pst
);
7768 if (!cu
->per_cu
->imported_symtabs_empty ())
7771 int len
= cu
->per_cu
->imported_symtabs_size ();
7773 /* Fill in 'dependencies' here; we fill in 'users' in a
7775 pst
->number_of_dependencies
= len
;
7777 = objfile
->partial_symtabs
->allocate_dependencies (len
);
7778 for (i
= 0; i
< len
; ++i
)
7780 pst
->dependencies
[i
]
7781 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7784 cu
->per_cu
->imported_symtabs_free ();
7787 /* Get the list of files included in the current compilation unit,
7788 and build a psymtab for each of them. */
7789 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
7791 if (dwarf_read_debug
)
7792 fprintf_unfiltered (gdb_stdlog
,
7793 "Psymtab for %s unit @%s: %s - %s"
7794 ", %d global, %d static syms\n",
7795 per_cu
->is_debug_types
? "type" : "comp",
7796 sect_offset_str (per_cu
->sect_off
),
7797 paddress (gdbarch
, pst
->text_low (objfile
)),
7798 paddress (gdbarch
, pst
->text_high (objfile
)),
7799 pst
->n_global_syms
, pst
->n_static_syms
);
7802 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7803 Process compilation unit THIS_CU for a psymtab. */
7806 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
7807 int want_partial_unit
,
7808 enum language pretend_language
)
7810 /* If this compilation unit was already read in, free the
7811 cached copy in order to read it in again. This is
7812 necessary because we skipped some symbols when we first
7813 read in the compilation unit (see load_partial_dies).
7814 This problem could be avoided, but the benefit is unclear. */
7815 if (this_cu
->cu
!= NULL
)
7816 free_one_cached_comp_unit (this_cu
);
7818 cutu_reader
reader (this_cu
, NULL
, 0, 0, false);
7824 else if (this_cu
->is_debug_types
)
7825 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7826 reader
.comp_unit_die
);
7828 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7829 reader
.comp_unit_die
,
7833 /* Age out any secondary CUs. */
7834 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
7837 /* Reader function for build_type_psymtabs. */
7840 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7841 const gdb_byte
*info_ptr
,
7842 struct die_info
*type_unit_die
)
7844 struct dwarf2_per_objfile
*dwarf2_per_objfile
7845 = reader
->cu
->per_cu
->dwarf2_per_objfile
;
7846 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7847 struct dwarf2_cu
*cu
= reader
->cu
;
7848 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7849 struct signatured_type
*sig_type
;
7850 struct type_unit_group
*tu_group
;
7851 struct attribute
*attr
;
7852 struct partial_die_info
*first_die
;
7853 CORE_ADDR lowpc
, highpc
;
7854 dwarf2_psymtab
*pst
;
7856 gdb_assert (per_cu
->is_debug_types
);
7857 sig_type
= (struct signatured_type
*) per_cu
;
7859 if (! type_unit_die
->has_children
)
7862 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
7863 tu_group
= get_type_unit_group (cu
, attr
);
7865 if (tu_group
->tus
== nullptr)
7866 tu_group
->tus
= new std::vector
<signatured_type
*>;
7867 tu_group
->tus
->push_back (sig_type
);
7869 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7870 pst
= create_partial_symtab (per_cu
, "");
7871 pst
->anonymous
= true;
7873 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7875 lowpc
= (CORE_ADDR
) -1;
7876 highpc
= (CORE_ADDR
) 0;
7877 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7879 end_psymtab_common (objfile
, pst
);
7882 /* Struct used to sort TUs by their abbreviation table offset. */
7884 struct tu_abbrev_offset
7886 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7887 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7890 signatured_type
*sig_type
;
7891 sect_offset abbrev_offset
;
7894 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
7897 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
7898 const struct tu_abbrev_offset
&b
)
7900 return a
.abbrev_offset
< b
.abbrev_offset
;
7903 /* Efficiently read all the type units.
7904 This does the bulk of the work for build_type_psymtabs.
7906 The efficiency is because we sort TUs by the abbrev table they use and
7907 only read each abbrev table once. In one program there are 200K TUs
7908 sharing 8K abbrev tables.
7910 The main purpose of this function is to support building the
7911 dwarf2_per_objfile->type_unit_groups table.
7912 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7913 can collapse the search space by grouping them by stmt_list.
7914 The savings can be significant, in the same program from above the 200K TUs
7915 share 8K stmt_list tables.
7917 FUNC is expected to call get_type_unit_group, which will create the
7918 struct type_unit_group if necessary and add it to
7919 dwarf2_per_objfile->type_unit_groups. */
7922 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7924 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7925 abbrev_table_up abbrev_table
;
7926 sect_offset abbrev_offset
;
7928 /* It's up to the caller to not call us multiple times. */
7929 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
7931 if (dwarf2_per_objfile
->all_type_units
.empty ())
7934 /* TUs typically share abbrev tables, and there can be way more TUs than
7935 abbrev tables. Sort by abbrev table to reduce the number of times we
7936 read each abbrev table in.
7937 Alternatives are to punt or to maintain a cache of abbrev tables.
7938 This is simpler and efficient enough for now.
7940 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7941 symtab to use). Typically TUs with the same abbrev offset have the same
7942 stmt_list value too so in practice this should work well.
7944 The basic algorithm here is:
7946 sort TUs by abbrev table
7947 for each TU with same abbrev table:
7948 read abbrev table if first user
7949 read TU top level DIE
7950 [IWBN if DWO skeletons had DW_AT_stmt_list]
7953 if (dwarf_read_debug
)
7954 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
7956 /* Sort in a separate table to maintain the order of all_type_units
7957 for .gdb_index: TU indices directly index all_type_units. */
7958 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7959 sorted_by_abbrev
.reserve (dwarf2_per_objfile
->all_type_units
.size ());
7961 for (signatured_type
*sig_type
: dwarf2_per_objfile
->all_type_units
)
7962 sorted_by_abbrev
.emplace_back
7963 (sig_type
, read_abbrev_offset (dwarf2_per_objfile
,
7964 sig_type
->per_cu
.section
,
7965 sig_type
->per_cu
.sect_off
));
7967 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
7968 sort_tu_by_abbrev_offset
);
7970 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7972 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7974 /* Switch to the next abbrev table if necessary. */
7975 if (abbrev_table
== NULL
7976 || tu
.abbrev_offset
!= abbrev_offset
)
7978 abbrev_offset
= tu
.abbrev_offset
;
7980 abbrev_table::read (dwarf2_per_objfile
->objfile
,
7981 &dwarf2_per_objfile
->abbrev
,
7983 ++tu_stats
->nr_uniq_abbrev_tables
;
7986 cutu_reader
reader (&tu
.sig_type
->per_cu
, abbrev_table
.get (),
7988 if (!reader
.dummy_p
)
7989 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7990 reader
.comp_unit_die
);
7994 /* Print collected type unit statistics. */
7997 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7999 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8001 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
8002 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
8003 dwarf2_per_objfile
->all_type_units
.size ());
8004 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
8005 tu_stats
->nr_uniq_abbrev_tables
);
8006 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
8007 tu_stats
->nr_symtabs
);
8008 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
8009 tu_stats
->nr_symtab_sharers
);
8010 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
8011 tu_stats
->nr_stmt_less_type_units
);
8012 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
8013 tu_stats
->nr_all_type_units_reallocs
);
8016 /* Traversal function for build_type_psymtabs. */
8019 build_type_psymtab_dependencies (void **slot
, void *info
)
8021 struct dwarf2_per_objfile
*dwarf2_per_objfile
8022 = (struct dwarf2_per_objfile
*) info
;
8023 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8024 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
8025 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
8026 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
8027 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
8030 gdb_assert (len
> 0);
8031 gdb_assert (IS_TYPE_UNIT_GROUP (per_cu
));
8033 pst
->number_of_dependencies
= len
;
8034 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
8035 for (i
= 0; i
< len
; ++i
)
8037 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
8038 gdb_assert (iter
->per_cu
.is_debug_types
);
8039 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
8040 iter
->type_unit_group
= tu_group
;
8043 delete tu_group
->tus
;
8044 tu_group
->tus
= nullptr;
8049 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8050 Build partial symbol tables for the .debug_types comp-units. */
8053 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8055 if (! create_all_type_units (dwarf2_per_objfile
))
8058 build_type_psymtabs_1 (dwarf2_per_objfile
);
8061 /* Traversal function for process_skeletonless_type_unit.
8062 Read a TU in a DWO file and build partial symbols for it. */
8065 process_skeletonless_type_unit (void **slot
, void *info
)
8067 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
8068 struct dwarf2_per_objfile
*dwarf2_per_objfile
8069 = (struct dwarf2_per_objfile
*) info
;
8070 struct signatured_type find_entry
, *entry
;
8072 /* If this TU doesn't exist in the global table, add it and read it in. */
8074 if (dwarf2_per_objfile
->signatured_types
== NULL
)
8076 dwarf2_per_objfile
->signatured_types
8077 = allocate_signatured_type_table (dwarf2_per_objfile
->objfile
);
8080 find_entry
.signature
= dwo_unit
->signature
;
8081 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
8082 &find_entry
, INSERT
);
8083 /* If we've already seen this type there's nothing to do. What's happening
8084 is we're doing our own version of comdat-folding here. */
8088 /* This does the job that create_all_type_units would have done for
8090 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
8091 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
8094 /* This does the job that build_type_psymtabs_1 would have done. */
8095 cutu_reader
reader (&entry
->per_cu
, NULL
, 0, 0, false);
8096 if (!reader
.dummy_p
)
8097 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
8098 reader
.comp_unit_die
);
8103 /* Traversal function for process_skeletonless_type_units. */
8106 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
8108 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
8110 if (dwo_file
->tus
!= NULL
)
8111 htab_traverse_noresize (dwo_file
->tus
.get (),
8112 process_skeletonless_type_unit
, info
);
8117 /* Scan all TUs of DWO files, verifying we've processed them.
8118 This is needed in case a TU was emitted without its skeleton.
8119 Note: This can't be done until we know what all the DWO files are. */
8122 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8124 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
8125 if (get_dwp_file (dwarf2_per_objfile
) == NULL
8126 && dwarf2_per_objfile
->dwo_files
!= NULL
)
8128 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
.get (),
8129 process_dwo_file_for_skeletonless_type_units
,
8130 dwarf2_per_objfile
);
8134 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
8137 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8139 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
8141 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
8146 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
8148 /* Set the 'user' field only if it is not already set. */
8149 if (pst
->dependencies
[j
]->user
== NULL
)
8150 pst
->dependencies
[j
]->user
= pst
;
8155 /* Build the partial symbol table by doing a quick pass through the
8156 .debug_info and .debug_abbrev sections. */
8159 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8161 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8163 if (dwarf_read_debug
)
8165 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
8166 objfile_name (objfile
));
8169 dwarf2_per_objfile
->reading_partial_symbols
= 1;
8171 dwarf2_per_objfile
->info
.read (objfile
);
8173 /* Any cached compilation units will be linked by the per-objfile
8174 read_in_chain. Make sure to free them when we're done. */
8175 free_cached_comp_units
freer (dwarf2_per_objfile
);
8177 build_type_psymtabs (dwarf2_per_objfile
);
8179 create_all_comp_units (dwarf2_per_objfile
);
8181 /* Create a temporary address map on a temporary obstack. We later
8182 copy this to the final obstack. */
8183 auto_obstack temp_obstack
;
8185 scoped_restore save_psymtabs_addrmap
8186 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
8187 addrmap_create_mutable (&temp_obstack
));
8189 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
8190 process_psymtab_comp_unit (per_cu
, 0, language_minimal
);
8192 /* This has to wait until we read the CUs, we need the list of DWOs. */
8193 process_skeletonless_type_units (dwarf2_per_objfile
);
8195 /* Now that all TUs have been processed we can fill in the dependencies. */
8196 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
8198 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
.get (),
8199 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
8202 if (dwarf_read_debug
)
8203 print_tu_stats (dwarf2_per_objfile
);
8205 set_partial_user (dwarf2_per_objfile
);
8207 objfile
->partial_symtabs
->psymtabs_addrmap
8208 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
8209 objfile
->partial_symtabs
->obstack ());
8210 /* At this point we want to keep the address map. */
8211 save_psymtabs_addrmap
.release ();
8213 if (dwarf_read_debug
)
8214 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
8215 objfile_name (objfile
));
8218 /* Load the partial DIEs for a secondary CU into memory.
8219 This is also used when rereading a primary CU with load_all_dies. */
8222 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
8224 cutu_reader
reader (this_cu
, NULL
, 1, 1, false);
8226 if (!reader
.dummy_p
)
8228 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
8231 /* Check if comp unit has_children.
8232 If so, read the rest of the partial symbols from this comp unit.
8233 If not, there's no more debug_info for this comp unit. */
8234 if (reader
.comp_unit_die
->has_children
)
8235 load_partial_dies (&reader
, reader
.info_ptr
, 0);
8240 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
8241 struct dwarf2_section_info
*section
,
8242 struct dwarf2_section_info
*abbrev_section
,
8243 unsigned int is_dwz
)
8245 const gdb_byte
*info_ptr
;
8246 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8248 if (dwarf_read_debug
)
8249 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
8250 section
->get_name (),
8251 section
->get_file_name ());
8253 section
->read (objfile
);
8255 info_ptr
= section
->buffer
;
8257 while (info_ptr
< section
->buffer
+ section
->size
)
8259 struct dwarf2_per_cu_data
*this_cu
;
8261 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
8263 comp_unit_head cu_header
;
8264 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
8265 abbrev_section
, info_ptr
,
8266 rcuh_kind::COMPILE
);
8268 /* Save the compilation unit for later lookup. */
8269 if (cu_header
.unit_type
!= DW_UT_type
)
8271 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
8272 struct dwarf2_per_cu_data
);
8273 memset (this_cu
, 0, sizeof (*this_cu
));
8277 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
8278 struct signatured_type
);
8279 memset (sig_type
, 0, sizeof (*sig_type
));
8280 sig_type
->signature
= cu_header
.signature
;
8281 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
8282 this_cu
= &sig_type
->per_cu
;
8284 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
8285 this_cu
->sect_off
= sect_off
;
8286 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
8287 this_cu
->is_dwz
= is_dwz
;
8288 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
8289 this_cu
->section
= section
;
8291 dwarf2_per_objfile
->all_comp_units
.push_back (this_cu
);
8293 info_ptr
= info_ptr
+ this_cu
->length
;
8297 /* Create a list of all compilation units in OBJFILE.
8298 This is only done for -readnow and building partial symtabs. */
8301 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8303 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
8304 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->info
,
8305 &dwarf2_per_objfile
->abbrev
, 0);
8307 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
8309 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
8313 /* Process all loaded DIEs for compilation unit CU, starting at
8314 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
8315 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
8316 DW_AT_ranges). See the comments of add_partial_subprogram on how
8317 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
8320 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
8321 CORE_ADDR
*highpc
, int set_addrmap
,
8322 struct dwarf2_cu
*cu
)
8324 struct partial_die_info
*pdi
;
8326 /* Now, march along the PDI's, descending into ones which have
8327 interesting children but skipping the children of the other ones,
8328 until we reach the end of the compilation unit. */
8336 /* Anonymous namespaces or modules have no name but have interesting
8337 children, so we need to look at them. Ditto for anonymous
8340 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
8341 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
8342 || pdi
->tag
== DW_TAG_imported_unit
8343 || pdi
->tag
== DW_TAG_inlined_subroutine
)
8347 case DW_TAG_subprogram
:
8348 case DW_TAG_inlined_subroutine
:
8349 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8351 case DW_TAG_constant
:
8352 case DW_TAG_variable
:
8353 case DW_TAG_typedef
:
8354 case DW_TAG_union_type
:
8355 if (!pdi
->is_declaration
)
8357 add_partial_symbol (pdi
, cu
);
8360 case DW_TAG_class_type
:
8361 case DW_TAG_interface_type
:
8362 case DW_TAG_structure_type
:
8363 if (!pdi
->is_declaration
)
8365 add_partial_symbol (pdi
, cu
);
8367 if ((cu
->language
== language_rust
8368 || cu
->language
== language_cplus
) && pdi
->has_children
)
8369 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8372 case DW_TAG_enumeration_type
:
8373 if (!pdi
->is_declaration
)
8374 add_partial_enumeration (pdi
, cu
);
8376 case DW_TAG_base_type
:
8377 case DW_TAG_subrange_type
:
8378 /* File scope base type definitions are added to the partial
8380 add_partial_symbol (pdi
, cu
);
8382 case DW_TAG_namespace
:
8383 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8386 if (!pdi
->is_declaration
)
8387 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8389 case DW_TAG_imported_unit
:
8391 struct dwarf2_per_cu_data
*per_cu
;
8393 /* For now we don't handle imported units in type units. */
8394 if (cu
->per_cu
->is_debug_types
)
8396 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8397 " supported in type units [in module %s]"),
8398 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
8401 per_cu
= dwarf2_find_containing_comp_unit
8402 (pdi
->d
.sect_off
, pdi
->is_dwz
,
8403 cu
->per_cu
->dwarf2_per_objfile
);
8405 /* Go read the partial unit, if needed. */
8406 if (per_cu
->v
.psymtab
== NULL
)
8407 process_psymtab_comp_unit (per_cu
, 1, cu
->language
);
8409 cu
->per_cu
->imported_symtabs_push (per_cu
);
8412 case DW_TAG_imported_declaration
:
8413 add_partial_symbol (pdi
, cu
);
8420 /* If the die has a sibling, skip to the sibling. */
8422 pdi
= pdi
->die_sibling
;
8426 /* Functions used to compute the fully scoped name of a partial DIE.
8428 Normally, this is simple. For C++, the parent DIE's fully scoped
8429 name is concatenated with "::" and the partial DIE's name.
8430 Enumerators are an exception; they use the scope of their parent
8431 enumeration type, i.e. the name of the enumeration type is not
8432 prepended to the enumerator.
8434 There are two complexities. One is DW_AT_specification; in this
8435 case "parent" means the parent of the target of the specification,
8436 instead of the direct parent of the DIE. The other is compilers
8437 which do not emit DW_TAG_namespace; in this case we try to guess
8438 the fully qualified name of structure types from their members'
8439 linkage names. This must be done using the DIE's children rather
8440 than the children of any DW_AT_specification target. We only need
8441 to do this for structures at the top level, i.e. if the target of
8442 any DW_AT_specification (if any; otherwise the DIE itself) does not
8445 /* Compute the scope prefix associated with PDI's parent, in
8446 compilation unit CU. The result will be allocated on CU's
8447 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8448 field. NULL is returned if no prefix is necessary. */
8450 partial_die_parent_scope (struct partial_die_info
*pdi
,
8451 struct dwarf2_cu
*cu
)
8453 const char *grandparent_scope
;
8454 struct partial_die_info
*parent
, *real_pdi
;
8456 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8457 then this means the parent of the specification DIE. */
8460 while (real_pdi
->has_specification
)
8462 auto res
= find_partial_die (real_pdi
->spec_offset
,
8463 real_pdi
->spec_is_dwz
, cu
);
8468 parent
= real_pdi
->die_parent
;
8472 if (parent
->scope_set
)
8473 return parent
->scope
;
8477 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8479 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8480 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8481 Work around this problem here. */
8482 if (cu
->language
== language_cplus
8483 && parent
->tag
== DW_TAG_namespace
8484 && strcmp (parent
->name
, "::") == 0
8485 && grandparent_scope
== NULL
)
8487 parent
->scope
= NULL
;
8488 parent
->scope_set
= 1;
8492 /* Nested subroutines in Fortran get a prefix. */
8493 if (pdi
->tag
== DW_TAG_enumerator
)
8494 /* Enumerators should not get the name of the enumeration as a prefix. */
8495 parent
->scope
= grandparent_scope
;
8496 else if (parent
->tag
== DW_TAG_namespace
8497 || parent
->tag
== DW_TAG_module
8498 || parent
->tag
== DW_TAG_structure_type
8499 || parent
->tag
== DW_TAG_class_type
8500 || parent
->tag
== DW_TAG_interface_type
8501 || parent
->tag
== DW_TAG_union_type
8502 || parent
->tag
== DW_TAG_enumeration_type
8503 || (cu
->language
== language_fortran
8504 && parent
->tag
== DW_TAG_subprogram
8505 && pdi
->tag
== DW_TAG_subprogram
))
8507 if (grandparent_scope
== NULL
)
8508 parent
->scope
= parent
->name
;
8510 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8512 parent
->name
, 0, cu
);
8516 /* FIXME drow/2004-04-01: What should we be doing with
8517 function-local names? For partial symbols, we should probably be
8519 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8520 dwarf_tag_name (parent
->tag
),
8521 sect_offset_str (pdi
->sect_off
));
8522 parent
->scope
= grandparent_scope
;
8525 parent
->scope_set
= 1;
8526 return parent
->scope
;
8529 /* Return the fully scoped name associated with PDI, from compilation unit
8530 CU. The result will be allocated with malloc. */
8532 static gdb::unique_xmalloc_ptr
<char>
8533 partial_die_full_name (struct partial_die_info
*pdi
,
8534 struct dwarf2_cu
*cu
)
8536 const char *parent_scope
;
8538 /* If this is a template instantiation, we can not work out the
8539 template arguments from partial DIEs. So, unfortunately, we have
8540 to go through the full DIEs. At least any work we do building
8541 types here will be reused if full symbols are loaded later. */
8542 if (pdi
->has_template_arguments
)
8546 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
8548 struct die_info
*die
;
8549 struct attribute attr
;
8550 struct dwarf2_cu
*ref_cu
= cu
;
8552 /* DW_FORM_ref_addr is using section offset. */
8553 attr
.name
= (enum dwarf_attribute
) 0;
8554 attr
.form
= DW_FORM_ref_addr
;
8555 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8556 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8558 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8562 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8563 if (parent_scope
== NULL
)
8566 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8571 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8573 struct dwarf2_per_objfile
*dwarf2_per_objfile
8574 = cu
->per_cu
->dwarf2_per_objfile
;
8575 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8576 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8578 const char *actual_name
= NULL
;
8581 baseaddr
= objfile
->text_section_offset ();
8583 gdb::unique_xmalloc_ptr
<char> built_actual_name
8584 = partial_die_full_name (pdi
, cu
);
8585 if (built_actual_name
!= NULL
)
8586 actual_name
= built_actual_name
.get ();
8588 if (actual_name
== NULL
)
8589 actual_name
= pdi
->name
;
8593 case DW_TAG_inlined_subroutine
:
8594 case DW_TAG_subprogram
:
8595 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8597 if (pdi
->is_external
8598 || cu
->language
== language_ada
8599 || (cu
->language
== language_fortran
8600 && pdi
->die_parent
!= NULL
8601 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8603 /* Normally, only "external" DIEs are part of the global scope.
8604 But in Ada and Fortran, we want to be able to access nested
8605 procedures globally. So all Ada and Fortran subprograms are
8606 stored in the global scope. */
8607 add_psymbol_to_list (actual_name
,
8608 built_actual_name
!= NULL
,
8609 VAR_DOMAIN
, LOC_BLOCK
,
8610 SECT_OFF_TEXT (objfile
),
8611 psymbol_placement::GLOBAL
,
8613 cu
->language
, objfile
);
8617 add_psymbol_to_list (actual_name
,
8618 built_actual_name
!= NULL
,
8619 VAR_DOMAIN
, LOC_BLOCK
,
8620 SECT_OFF_TEXT (objfile
),
8621 psymbol_placement::STATIC
,
8622 addr
, cu
->language
, objfile
);
8625 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8626 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8628 case DW_TAG_constant
:
8629 add_psymbol_to_list (actual_name
,
8630 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
8631 -1, (pdi
->is_external
8632 ? psymbol_placement::GLOBAL
8633 : psymbol_placement::STATIC
),
8634 0, cu
->language
, objfile
);
8636 case DW_TAG_variable
:
8638 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8642 && !dwarf2_per_objfile
->has_section_at_zero
)
8644 /* A global or static variable may also have been stripped
8645 out by the linker if unused, in which case its address
8646 will be nullified; do not add such variables into partial
8647 symbol table then. */
8649 else if (pdi
->is_external
)
8652 Don't enter into the minimal symbol tables as there is
8653 a minimal symbol table entry from the ELF symbols already.
8654 Enter into partial symbol table if it has a location
8655 descriptor or a type.
8656 If the location descriptor is missing, new_symbol will create
8657 a LOC_UNRESOLVED symbol, the address of the variable will then
8658 be determined from the minimal symbol table whenever the variable
8660 The address for the partial symbol table entry is not
8661 used by GDB, but it comes in handy for debugging partial symbol
8664 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8665 add_psymbol_to_list (actual_name
,
8666 built_actual_name
!= NULL
,
8667 VAR_DOMAIN
, LOC_STATIC
,
8668 SECT_OFF_TEXT (objfile
),
8669 psymbol_placement::GLOBAL
,
8670 addr
, cu
->language
, objfile
);
8674 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8676 /* Static Variable. Skip symbols whose value we cannot know (those
8677 without location descriptors or constant values). */
8678 if (!has_loc
&& !pdi
->has_const_value
)
8681 add_psymbol_to_list (actual_name
,
8682 built_actual_name
!= NULL
,
8683 VAR_DOMAIN
, LOC_STATIC
,
8684 SECT_OFF_TEXT (objfile
),
8685 psymbol_placement::STATIC
,
8687 cu
->language
, objfile
);
8690 case DW_TAG_typedef
:
8691 case DW_TAG_base_type
:
8692 case DW_TAG_subrange_type
:
8693 add_psymbol_to_list (actual_name
,
8694 built_actual_name
!= NULL
,
8695 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
8696 psymbol_placement::STATIC
,
8697 0, cu
->language
, objfile
);
8699 case DW_TAG_imported_declaration
:
8700 case DW_TAG_namespace
:
8701 add_psymbol_to_list (actual_name
,
8702 built_actual_name
!= NULL
,
8703 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
8704 psymbol_placement::GLOBAL
,
8705 0, cu
->language
, objfile
);
8708 /* With Fortran 77 there might be a "BLOCK DATA" module
8709 available without any name. If so, we skip the module as it
8710 doesn't bring any value. */
8711 if (actual_name
!= nullptr)
8712 add_psymbol_to_list (actual_name
,
8713 built_actual_name
!= NULL
,
8714 MODULE_DOMAIN
, LOC_TYPEDEF
, -1,
8715 psymbol_placement::GLOBAL
,
8716 0, cu
->language
, objfile
);
8718 case DW_TAG_class_type
:
8719 case DW_TAG_interface_type
:
8720 case DW_TAG_structure_type
:
8721 case DW_TAG_union_type
:
8722 case DW_TAG_enumeration_type
:
8723 /* Skip external references. The DWARF standard says in the section
8724 about "Structure, Union, and Class Type Entries": "An incomplete
8725 structure, union or class type is represented by a structure,
8726 union or class entry that does not have a byte size attribute
8727 and that has a DW_AT_declaration attribute." */
8728 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8731 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8732 static vs. global. */
8733 add_psymbol_to_list (actual_name
,
8734 built_actual_name
!= NULL
,
8735 STRUCT_DOMAIN
, LOC_TYPEDEF
, -1,
8736 cu
->language
== language_cplus
8737 ? psymbol_placement::GLOBAL
8738 : psymbol_placement::STATIC
,
8739 0, cu
->language
, objfile
);
8742 case DW_TAG_enumerator
:
8743 add_psymbol_to_list (actual_name
,
8744 built_actual_name
!= NULL
,
8745 VAR_DOMAIN
, LOC_CONST
, -1,
8746 cu
->language
== language_cplus
8747 ? psymbol_placement::GLOBAL
8748 : psymbol_placement::STATIC
,
8749 0, cu
->language
, objfile
);
8756 /* Read a partial die corresponding to a namespace; also, add a symbol
8757 corresponding to that namespace to the symbol table. NAMESPACE is
8758 the name of the enclosing namespace. */
8761 add_partial_namespace (struct partial_die_info
*pdi
,
8762 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8763 int set_addrmap
, struct dwarf2_cu
*cu
)
8765 /* Add a symbol for the namespace. */
8767 add_partial_symbol (pdi
, cu
);
8769 /* Now scan partial symbols in that namespace. */
8771 if (pdi
->has_children
)
8772 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8775 /* Read a partial die corresponding to a Fortran module. */
8778 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8779 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8781 /* Add a symbol for the namespace. */
8783 add_partial_symbol (pdi
, cu
);
8785 /* Now scan partial symbols in that module. */
8787 if (pdi
->has_children
)
8788 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8791 /* Read a partial die corresponding to a subprogram or an inlined
8792 subprogram and create a partial symbol for that subprogram.
8793 When the CU language allows it, this routine also defines a partial
8794 symbol for each nested subprogram that this subprogram contains.
8795 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8796 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8798 PDI may also be a lexical block, in which case we simply search
8799 recursively for subprograms defined inside that lexical block.
8800 Again, this is only performed when the CU language allows this
8801 type of definitions. */
8804 add_partial_subprogram (struct partial_die_info
*pdi
,
8805 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8806 int set_addrmap
, struct dwarf2_cu
*cu
)
8808 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8810 if (pdi
->has_pc_info
)
8812 if (pdi
->lowpc
< *lowpc
)
8813 *lowpc
= pdi
->lowpc
;
8814 if (pdi
->highpc
> *highpc
)
8815 *highpc
= pdi
->highpc
;
8818 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
8819 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8821 CORE_ADDR this_highpc
;
8822 CORE_ADDR this_lowpc
;
8824 baseaddr
= objfile
->text_section_offset ();
8826 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8827 pdi
->lowpc
+ baseaddr
)
8830 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8831 pdi
->highpc
+ baseaddr
)
8833 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8834 this_lowpc
, this_highpc
- 1,
8835 cu
->per_cu
->v
.psymtab
);
8839 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8841 if (!pdi
->is_declaration
)
8842 /* Ignore subprogram DIEs that do not have a name, they are
8843 illegal. Do not emit a complaint at this point, we will
8844 do so when we convert this psymtab into a symtab. */
8846 add_partial_symbol (pdi
, cu
);
8850 if (! pdi
->has_children
)
8853 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
8855 pdi
= pdi
->die_child
;
8859 if (pdi
->tag
== DW_TAG_subprogram
8860 || pdi
->tag
== DW_TAG_inlined_subroutine
8861 || pdi
->tag
== DW_TAG_lexical_block
)
8862 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8863 pdi
= pdi
->die_sibling
;
8868 /* Read a partial die corresponding to an enumeration type. */
8871 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8872 struct dwarf2_cu
*cu
)
8874 struct partial_die_info
*pdi
;
8876 if (enum_pdi
->name
!= NULL
)
8877 add_partial_symbol (enum_pdi
, cu
);
8879 pdi
= enum_pdi
->die_child
;
8882 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
8883 complaint (_("malformed enumerator DIE ignored"));
8885 add_partial_symbol (pdi
, cu
);
8886 pdi
= pdi
->die_sibling
;
8890 /* Return the initial uleb128 in the die at INFO_PTR. */
8893 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8895 unsigned int bytes_read
;
8897 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8900 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8901 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8903 Return the corresponding abbrev, or NULL if the number is zero (indicating
8904 an empty DIE). In either case *BYTES_READ will be set to the length of
8905 the initial number. */
8907 static struct abbrev_info
*
8908 peek_die_abbrev (const die_reader_specs
&reader
,
8909 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8911 dwarf2_cu
*cu
= reader
.cu
;
8912 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
8913 unsigned int abbrev_number
8914 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8916 if (abbrev_number
== 0)
8919 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8922 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8923 " at offset %s [in module %s]"),
8924 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8925 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8931 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8932 Returns a pointer to the end of a series of DIEs, terminated by an empty
8933 DIE. Any children of the skipped DIEs will also be skipped. */
8935 static const gdb_byte
*
8936 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8940 unsigned int bytes_read
;
8941 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
8944 return info_ptr
+ bytes_read
;
8946 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8950 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8951 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8952 abbrev corresponding to that skipped uleb128 should be passed in
8953 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8956 static const gdb_byte
*
8957 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8958 struct abbrev_info
*abbrev
)
8960 unsigned int bytes_read
;
8961 struct attribute attr
;
8962 bfd
*abfd
= reader
->abfd
;
8963 struct dwarf2_cu
*cu
= reader
->cu
;
8964 const gdb_byte
*buffer
= reader
->buffer
;
8965 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8966 unsigned int form
, i
;
8968 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8970 /* The only abbrev we care about is DW_AT_sibling. */
8971 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8974 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
,
8976 if (attr
.form
== DW_FORM_ref_addr
)
8977 complaint (_("ignoring absolute DW_AT_sibling"));
8980 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
8981 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8983 if (sibling_ptr
< info_ptr
)
8984 complaint (_("DW_AT_sibling points backwards"));
8985 else if (sibling_ptr
> reader
->buffer_end
)
8986 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
8992 /* If it isn't DW_AT_sibling, skip this attribute. */
8993 form
= abbrev
->attrs
[i
].form
;
8997 case DW_FORM_ref_addr
:
8998 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8999 and later it is offset sized. */
9000 if (cu
->header
.version
== 2)
9001 info_ptr
+= cu
->header
.addr_size
;
9003 info_ptr
+= cu
->header
.offset_size
;
9005 case DW_FORM_GNU_ref_alt
:
9006 info_ptr
+= cu
->header
.offset_size
;
9009 info_ptr
+= cu
->header
.addr_size
;
9017 case DW_FORM_flag_present
:
9018 case DW_FORM_implicit_const
:
9035 case DW_FORM_ref_sig8
:
9038 case DW_FORM_data16
:
9041 case DW_FORM_string
:
9042 read_direct_string (abfd
, info_ptr
, &bytes_read
);
9043 info_ptr
+= bytes_read
;
9045 case DW_FORM_sec_offset
:
9047 case DW_FORM_GNU_strp_alt
:
9048 info_ptr
+= cu
->header
.offset_size
;
9050 case DW_FORM_exprloc
:
9052 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9053 info_ptr
+= bytes_read
;
9055 case DW_FORM_block1
:
9056 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
9058 case DW_FORM_block2
:
9059 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
9061 case DW_FORM_block4
:
9062 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
9068 case DW_FORM_ref_udata
:
9069 case DW_FORM_GNU_addr_index
:
9070 case DW_FORM_GNU_str_index
:
9071 case DW_FORM_rnglistx
:
9072 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
9074 case DW_FORM_indirect
:
9075 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9076 info_ptr
+= bytes_read
;
9077 /* We need to continue parsing from here, so just go back to
9079 goto skip_attribute
;
9082 error (_("Dwarf Error: Cannot handle %s "
9083 "in DWARF reader [in module %s]"),
9084 dwarf_form_name (form
),
9085 bfd_get_filename (abfd
));
9089 if (abbrev
->has_children
)
9090 return skip_children (reader
, info_ptr
);
9095 /* Locate ORIG_PDI's sibling.
9096 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
9098 static const gdb_byte
*
9099 locate_pdi_sibling (const struct die_reader_specs
*reader
,
9100 struct partial_die_info
*orig_pdi
,
9101 const gdb_byte
*info_ptr
)
9103 /* Do we know the sibling already? */
9105 if (orig_pdi
->sibling
)
9106 return orig_pdi
->sibling
;
9108 /* Are there any children to deal with? */
9110 if (!orig_pdi
->has_children
)
9113 /* Skip the children the long way. */
9115 return skip_children (reader
, info_ptr
);
9118 /* Expand this partial symbol table into a full symbol table. SELF is
9122 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
9124 struct dwarf2_per_objfile
*dwarf2_per_objfile
9125 = get_dwarf2_per_objfile (objfile
);
9127 gdb_assert (!readin
);
9128 /* If this psymtab is constructed from a debug-only objfile, the
9129 has_section_at_zero flag will not necessarily be correct. We
9130 can get the correct value for this flag by looking at the data
9131 associated with the (presumably stripped) associated objfile. */
9132 if (objfile
->separate_debug_objfile_backlink
)
9134 struct dwarf2_per_objfile
*dpo_backlink
9135 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
9137 dwarf2_per_objfile
->has_section_at_zero
9138 = dpo_backlink
->has_section_at_zero
;
9141 dwarf2_per_objfile
->reading_partial_symbols
= 0;
9143 expand_psymtab (objfile
);
9145 process_cu_includes (dwarf2_per_objfile
);
9148 /* Reading in full CUs. */
9150 /* Add PER_CU to the queue. */
9153 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9154 enum language pretend_language
)
9157 per_cu
->dwarf2_per_objfile
->queue
.emplace (per_cu
, pretend_language
);
9160 /* If PER_CU is not yet queued, add it to the queue.
9161 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
9163 The result is non-zero if PER_CU was queued, otherwise the result is zero
9164 meaning either PER_CU is already queued or it is already loaded.
9166 N.B. There is an invariant here that if a CU is queued then it is loaded.
9167 The caller is required to load PER_CU if we return non-zero. */
9170 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
9171 struct dwarf2_per_cu_data
*per_cu
,
9172 enum language pretend_language
)
9174 /* We may arrive here during partial symbol reading, if we need full
9175 DIEs to process an unusual case (e.g. template arguments). Do
9176 not queue PER_CU, just tell our caller to load its DIEs. */
9177 if (per_cu
->dwarf2_per_objfile
->reading_partial_symbols
)
9179 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
9184 /* Mark the dependence relation so that we don't flush PER_CU
9186 if (dependent_cu
!= NULL
)
9187 dwarf2_add_dependence (dependent_cu
, per_cu
);
9189 /* If it's already on the queue, we have nothing to do. */
9193 /* If the compilation unit is already loaded, just mark it as
9195 if (per_cu
->cu
!= NULL
)
9197 per_cu
->cu
->last_used
= 0;
9201 /* Add it to the queue. */
9202 queue_comp_unit (per_cu
, pretend_language
);
9207 /* Process the queue. */
9210 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9212 if (dwarf_read_debug
)
9214 fprintf_unfiltered (gdb_stdlog
,
9215 "Expanding one or more symtabs of objfile %s ...\n",
9216 objfile_name (dwarf2_per_objfile
->objfile
));
9219 /* The queue starts out with one item, but following a DIE reference
9220 may load a new CU, adding it to the end of the queue. */
9221 while (!dwarf2_per_objfile
->queue
.empty ())
9223 dwarf2_queue_item
&item
= dwarf2_per_objfile
->queue
.front ();
9225 if ((dwarf2_per_objfile
->using_index
9226 ? !item
.per_cu
->v
.quick
->compunit_symtab
9227 : (item
.per_cu
->v
.psymtab
&& !item
.per_cu
->v
.psymtab
->readin
))
9228 /* Skip dummy CUs. */
9229 && item
.per_cu
->cu
!= NULL
)
9231 struct dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
9232 unsigned int debug_print_threshold
;
9235 if (per_cu
->is_debug_types
)
9237 struct signatured_type
*sig_type
=
9238 (struct signatured_type
*) per_cu
;
9240 sprintf (buf
, "TU %s at offset %s",
9241 hex_string (sig_type
->signature
),
9242 sect_offset_str (per_cu
->sect_off
));
9243 /* There can be 100s of TUs.
9244 Only print them in verbose mode. */
9245 debug_print_threshold
= 2;
9249 sprintf (buf
, "CU at offset %s",
9250 sect_offset_str (per_cu
->sect_off
));
9251 debug_print_threshold
= 1;
9254 if (dwarf_read_debug
>= debug_print_threshold
)
9255 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
9257 if (per_cu
->is_debug_types
)
9258 process_full_type_unit (per_cu
, item
.pretend_language
);
9260 process_full_comp_unit (per_cu
, item
.pretend_language
);
9262 if (dwarf_read_debug
>= debug_print_threshold
)
9263 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
9266 item
.per_cu
->queued
= 0;
9267 dwarf2_per_objfile
->queue
.pop ();
9270 if (dwarf_read_debug
)
9272 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
9273 objfile_name (dwarf2_per_objfile
->objfile
));
9277 /* Read in full symbols for PST, and anything it depends on. */
9280 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
9282 struct dwarf2_per_cu_data
*per_cu
;
9287 read_dependencies (objfile
);
9289 per_cu
= per_cu_data
;
9293 /* It's an include file, no symbols to read for it.
9294 Everything is in the parent symtab. */
9299 dw2_do_instantiate_symtab (per_cu
, false);
9302 /* Trivial hash function for die_info: the hash value of a DIE
9303 is its offset in .debug_info for this objfile. */
9306 die_hash (const void *item
)
9308 const struct die_info
*die
= (const struct die_info
*) item
;
9310 return to_underlying (die
->sect_off
);
9313 /* Trivial comparison function for die_info structures: two DIEs
9314 are equal if they have the same offset. */
9317 die_eq (const void *item_lhs
, const void *item_rhs
)
9319 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
9320 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
9322 return die_lhs
->sect_off
== die_rhs
->sect_off
;
9325 /* Load the DIEs associated with PER_CU into memory. */
9328 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
9330 enum language pretend_language
)
9332 gdb_assert (! this_cu
->is_debug_types
);
9334 cutu_reader
reader (this_cu
, NULL
, 1, 1, skip_partial
);
9338 struct dwarf2_cu
*cu
= reader
.cu
;
9339 const gdb_byte
*info_ptr
= reader
.info_ptr
;
9341 gdb_assert (cu
->die_hash
== NULL
);
9343 htab_create_alloc_ex (cu
->header
.length
/ 12,
9347 &cu
->comp_unit_obstack
,
9348 hashtab_obstack_allocate
,
9349 dummy_obstack_deallocate
);
9351 if (reader
.comp_unit_die
->has_children
)
9352 reader
.comp_unit_die
->child
9353 = read_die_and_siblings (&reader
, reader
.info_ptr
,
9354 &info_ptr
, reader
.comp_unit_die
);
9355 cu
->dies
= reader
.comp_unit_die
;
9356 /* comp_unit_die is not stored in die_hash, no need. */
9358 /* We try not to read any attributes in this function, because not
9359 all CUs needed for references have been loaded yet, and symbol
9360 table processing isn't initialized. But we have to set the CU language,
9361 or we won't be able to build types correctly.
9362 Similarly, if we do not read the producer, we can not apply
9363 producer-specific interpretation. */
9364 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
9367 /* Add a DIE to the delayed physname list. */
9370 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
9371 const char *name
, struct die_info
*die
,
9372 struct dwarf2_cu
*cu
)
9374 struct delayed_method_info mi
;
9376 mi
.fnfield_index
= fnfield_index
;
9380 cu
->method_list
.push_back (mi
);
9383 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
9384 "const" / "volatile". If so, decrements LEN by the length of the
9385 modifier and return true. Otherwise return false. */
9389 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
9391 size_t mod_len
= sizeof (mod
) - 1;
9392 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
9400 /* Compute the physnames of any methods on the CU's method list.
9402 The computation of method physnames is delayed in order to avoid the
9403 (bad) condition that one of the method's formal parameters is of an as yet
9407 compute_delayed_physnames (struct dwarf2_cu
*cu
)
9409 /* Only C++ delays computing physnames. */
9410 if (cu
->method_list
.empty ())
9412 gdb_assert (cu
->language
== language_cplus
);
9414 for (const delayed_method_info
&mi
: cu
->method_list
)
9416 const char *physname
;
9417 struct fn_fieldlist
*fn_flp
9418 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9419 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9420 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9421 = physname
? physname
: "";
9423 /* Since there's no tag to indicate whether a method is a
9424 const/volatile overload, extract that information out of the
9426 if (physname
!= NULL
)
9428 size_t len
= strlen (physname
);
9432 if (physname
[len
] == ')') /* shortcut */
9434 else if (check_modifier (physname
, len
, " const"))
9435 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9436 else if (check_modifier (physname
, len
, " volatile"))
9437 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9444 /* The list is no longer needed. */
9445 cu
->method_list
.clear ();
9448 /* Go objects should be embedded in a DW_TAG_module DIE,
9449 and it's not clear if/how imported objects will appear.
9450 To keep Go support simple until that's worked out,
9451 go back through what we've read and create something usable.
9452 We could do this while processing each DIE, and feels kinda cleaner,
9453 but that way is more invasive.
9454 This is to, for example, allow the user to type "p var" or "b main"
9455 without having to specify the package name, and allow lookups
9456 of module.object to work in contexts that use the expression
9460 fixup_go_packaging (struct dwarf2_cu
*cu
)
9462 gdb::unique_xmalloc_ptr
<char> package_name
;
9463 struct pending
*list
;
9466 for (list
= *cu
->get_builder ()->get_global_symbols ();
9470 for (i
= 0; i
< list
->nsyms
; ++i
)
9472 struct symbol
*sym
= list
->symbol
[i
];
9474 if (sym
->language () == language_go
9475 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9477 gdb::unique_xmalloc_ptr
<char> this_package_name
9478 (go_symbol_package_name (sym
));
9480 if (this_package_name
== NULL
)
9482 if (package_name
== NULL
)
9483 package_name
= std::move (this_package_name
);
9486 struct objfile
*objfile
9487 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9488 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9489 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9490 (symbol_symtab (sym
) != NULL
9491 ? symtab_to_filename_for_display
9492 (symbol_symtab (sym
))
9493 : objfile_name (objfile
)),
9494 this_package_name
.get (), package_name
.get ());
9500 if (package_name
!= NULL
)
9502 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9503 const char *saved_package_name
9504 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
, package_name
.get ());
9505 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9506 saved_package_name
);
9509 sym
= allocate_symbol (objfile
);
9510 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9511 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9512 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9513 e.g., "main" finds the "main" module and not C's main(). */
9514 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9515 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9516 SYMBOL_TYPE (sym
) = type
;
9518 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9522 /* Allocate a fully-qualified name consisting of the two parts on the
9526 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9528 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9531 /* A helper that allocates a struct discriminant_info to attach to a
9534 static struct discriminant_info
*
9535 alloc_discriminant_info (struct type
*type
, int discriminant_index
,
9538 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9539 gdb_assert (discriminant_index
== -1
9540 || (discriminant_index
>= 0
9541 && discriminant_index
< TYPE_NFIELDS (type
)));
9542 gdb_assert (default_index
== -1
9543 || (default_index
>= 0 && default_index
< TYPE_NFIELDS (type
)));
9545 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
9547 struct discriminant_info
*disc
9548 = ((struct discriminant_info
*)
9550 offsetof (struct discriminant_info
, discriminants
)
9551 + TYPE_NFIELDS (type
) * sizeof (disc
->discriminants
[0])));
9552 disc
->default_index
= default_index
;
9553 disc
->discriminant_index
= discriminant_index
;
9555 struct dynamic_prop prop
;
9556 prop
.kind
= PROP_UNDEFINED
;
9557 prop
.data
.baton
= disc
;
9559 add_dyn_prop (DYN_PROP_DISCRIMINATED
, prop
, type
);
9564 /* Some versions of rustc emitted enums in an unusual way.
9566 Ordinary enums were emitted as unions. The first element of each
9567 structure in the union was named "RUST$ENUM$DISR". This element
9568 held the discriminant.
9570 These versions of Rust also implemented the "non-zero"
9571 optimization. When the enum had two values, and one is empty and
9572 the other holds a pointer that cannot be zero, the pointer is used
9573 as the discriminant, with a zero value meaning the empty variant.
9574 Here, the union's first member is of the form
9575 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9576 where the fieldnos are the indices of the fields that should be
9577 traversed in order to find the field (which may be several fields deep)
9578 and the variantname is the name of the variant of the case when the
9581 This function recognizes whether TYPE is of one of these forms,
9582 and, if so, smashes it to be a variant type. */
9585 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9587 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9589 /* We don't need to deal with empty enums. */
9590 if (TYPE_NFIELDS (type
) == 0)
9593 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9594 if (TYPE_NFIELDS (type
) == 1
9595 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9597 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9599 /* Decode the field name to find the offset of the
9601 ULONGEST bit_offset
= 0;
9602 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9603 while (name
[0] >= '0' && name
[0] <= '9')
9606 unsigned long index
= strtoul (name
, &tail
, 10);
9609 || index
>= TYPE_NFIELDS (field_type
)
9610 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9611 != FIELD_LOC_KIND_BITPOS
))
9613 complaint (_("Could not parse Rust enum encoding string \"%s\""
9615 TYPE_FIELD_NAME (type
, 0),
9616 objfile_name (objfile
));
9621 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9622 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
9625 /* Make a union to hold the variants. */
9626 struct type
*union_type
= alloc_type (objfile
);
9627 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9628 TYPE_NFIELDS (union_type
) = 3;
9629 TYPE_FIELDS (union_type
)
9630 = (struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
));
9631 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9632 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9634 /* Put the discriminant must at index 0. */
9635 TYPE_FIELD_TYPE (union_type
, 0) = field_type
;
9636 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
9637 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
9638 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 0), bit_offset
);
9640 /* The order of fields doesn't really matter, so put the real
9641 field at index 1 and the data-less field at index 2. */
9642 struct discriminant_info
*disc
9643 = alloc_discriminant_info (union_type
, 0, 1);
9644 TYPE_FIELD (union_type
, 1) = TYPE_FIELD (type
, 0);
9645 TYPE_FIELD_NAME (union_type
, 1)
9646 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1)));
9647 TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1))
9648 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9649 TYPE_FIELD_NAME (union_type
, 1));
9651 const char *dataless_name
9652 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9654 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9656 TYPE_FIELD_TYPE (union_type
, 2) = dataless_type
;
9657 /* NAME points into the original discriminant name, which
9658 already has the correct lifetime. */
9659 TYPE_FIELD_NAME (union_type
, 2) = name
;
9660 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 2), 0);
9661 disc
->discriminants
[2] = 0;
9663 /* Smash this type to be a structure type. We have to do this
9664 because the type has already been recorded. */
9665 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9666 TYPE_NFIELDS (type
) = 1;
9668 = (struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
));
9670 /* Install the variant part. */
9671 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9672 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9673 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9675 /* A union with a single anonymous field is probably an old-style
9677 else if (TYPE_NFIELDS (type
) == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
9679 /* Smash this type to be a structure type. We have to do this
9680 because the type has already been recorded. */
9681 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9683 /* Make a union to hold the variants. */
9684 struct type
*union_type
= alloc_type (objfile
);
9685 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9686 TYPE_NFIELDS (union_type
) = TYPE_NFIELDS (type
);
9687 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9688 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9689 TYPE_FIELDS (union_type
) = TYPE_FIELDS (type
);
9691 struct type
*field_type
= TYPE_FIELD_TYPE (union_type
, 0);
9692 const char *variant_name
9693 = rust_last_path_segment (TYPE_NAME (field_type
));
9694 TYPE_FIELD_NAME (union_type
, 0) = variant_name
;
9695 TYPE_NAME (field_type
)
9696 = rust_fully_qualify (&objfile
->objfile_obstack
,
9697 TYPE_NAME (type
), variant_name
);
9699 /* Install the union in the outer struct type. */
9700 TYPE_NFIELDS (type
) = 1;
9702 = (struct field
*) TYPE_ZALLOC (union_type
, sizeof (struct field
));
9703 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9704 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9705 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9707 alloc_discriminant_info (union_type
, -1, 0);
9711 struct type
*disr_type
= nullptr;
9712 for (int i
= 0; i
< TYPE_NFIELDS (type
); ++i
)
9714 disr_type
= TYPE_FIELD_TYPE (type
, i
);
9716 if (TYPE_CODE (disr_type
) != TYPE_CODE_STRUCT
)
9718 /* All fields of a true enum will be structs. */
9721 else if (TYPE_NFIELDS (disr_type
) == 0)
9723 /* Could be data-less variant, so keep going. */
9724 disr_type
= nullptr;
9726 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9727 "RUST$ENUM$DISR") != 0)
9729 /* Not a Rust enum. */
9739 /* If we got here without a discriminant, then it's probably
9741 if (disr_type
== nullptr)
9744 /* Smash this type to be a structure type. We have to do this
9745 because the type has already been recorded. */
9746 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9748 /* Make a union to hold the variants. */
9749 struct field
*disr_field
= &TYPE_FIELD (disr_type
, 0);
9750 struct type
*union_type
= alloc_type (objfile
);
9751 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9752 TYPE_NFIELDS (union_type
) = 1 + TYPE_NFIELDS (type
);
9753 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9754 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9755 TYPE_FIELDS (union_type
)
9756 = (struct field
*) TYPE_ZALLOC (union_type
,
9757 (TYPE_NFIELDS (union_type
)
9758 * sizeof (struct field
)));
9760 memcpy (TYPE_FIELDS (union_type
) + 1, TYPE_FIELDS (type
),
9761 TYPE_NFIELDS (type
) * sizeof (struct field
));
9763 /* Install the discriminant at index 0 in the union. */
9764 TYPE_FIELD (union_type
, 0) = *disr_field
;
9765 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
9766 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
9768 /* Install the union in the outer struct type. */
9769 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9770 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9771 TYPE_NFIELDS (type
) = 1;
9773 /* Set the size and offset of the union type. */
9774 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9776 /* We need a way to find the correct discriminant given a
9777 variant name. For convenience we build a map here. */
9778 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
9779 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9780 for (int i
= 0; i
< TYPE_NFIELDS (enum_type
); ++i
)
9782 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9785 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9786 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9790 int n_fields
= TYPE_NFIELDS (union_type
);
9791 struct discriminant_info
*disc
9792 = alloc_discriminant_info (union_type
, 0, -1);
9793 /* Skip the discriminant here. */
9794 for (int i
= 1; i
< n_fields
; ++i
)
9796 /* Find the final word in the name of this variant's type.
9797 That name can be used to look up the correct
9799 const char *variant_name
9800 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
,
9803 auto iter
= discriminant_map
.find (variant_name
);
9804 if (iter
!= discriminant_map
.end ())
9805 disc
->discriminants
[i
] = iter
->second
;
9807 /* Remove the discriminant field, if it exists. */
9808 struct type
*sub_type
= TYPE_FIELD_TYPE (union_type
, i
);
9809 if (TYPE_NFIELDS (sub_type
) > 0)
9811 --TYPE_NFIELDS (sub_type
);
9812 ++TYPE_FIELDS (sub_type
);
9814 TYPE_FIELD_NAME (union_type
, i
) = variant_name
;
9815 TYPE_NAME (sub_type
)
9816 = rust_fully_qualify (&objfile
->objfile_obstack
,
9817 TYPE_NAME (type
), variant_name
);
9822 /* Rewrite some Rust unions to be structures with variants parts. */
9825 rust_union_quirks (struct dwarf2_cu
*cu
)
9827 gdb_assert (cu
->language
== language_rust
);
9828 for (type
*type_
: cu
->rust_unions
)
9829 quirk_rust_enum (type_
, cu
->per_cu
->dwarf2_per_objfile
->objfile
);
9830 /* We don't need this any more. */
9831 cu
->rust_unions
.clear ();
9834 /* Return the symtab for PER_CU. This works properly regardless of
9835 whether we're using the index or psymtabs. */
9837 static struct compunit_symtab
*
9838 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
9840 return (per_cu
->dwarf2_per_objfile
->using_index
9841 ? per_cu
->v
.quick
->compunit_symtab
9842 : per_cu
->v
.psymtab
->compunit_symtab
);
9845 /* A helper function for computing the list of all symbol tables
9846 included by PER_CU. */
9849 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9850 htab_t all_children
, htab_t all_type_symtabs
,
9851 struct dwarf2_per_cu_data
*per_cu
,
9852 struct compunit_symtab
*immediate_parent
)
9855 struct compunit_symtab
*cust
;
9857 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9860 /* This inclusion and its children have been processed. */
9865 /* Only add a CU if it has a symbol table. */
9866 cust
= get_compunit_symtab (per_cu
);
9869 /* If this is a type unit only add its symbol table if we haven't
9870 seen it yet (type unit per_cu's can share symtabs). */
9871 if (per_cu
->is_debug_types
)
9873 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9877 result
->push_back (cust
);
9878 if (cust
->user
== NULL
)
9879 cust
->user
= immediate_parent
;
9884 result
->push_back (cust
);
9885 if (cust
->user
== NULL
)
9886 cust
->user
= immediate_parent
;
9890 if (!per_cu
->imported_symtabs_empty ())
9891 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9893 recursively_compute_inclusions (result
, all_children
,
9894 all_type_symtabs
, ptr
, cust
);
9898 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9902 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
9904 gdb_assert (! per_cu
->is_debug_types
);
9906 if (!per_cu
->imported_symtabs_empty ())
9909 std::vector
<compunit_symtab
*> result_symtabs
;
9910 htab_t all_children
, all_type_symtabs
;
9911 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
9913 /* If we don't have a symtab, we can just skip this case. */
9917 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9918 NULL
, xcalloc
, xfree
);
9919 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9920 NULL
, xcalloc
, xfree
);
9922 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9924 recursively_compute_inclusions (&result_symtabs
, all_children
,
9925 all_type_symtabs
, ptr
, cust
);
9928 /* Now we have a transitive closure of all the included symtabs. */
9929 len
= result_symtabs
.size ();
9931 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
9932 struct compunit_symtab
*, len
+ 1);
9933 memcpy (cust
->includes
, result_symtabs
.data (),
9934 len
* sizeof (compunit_symtab
*));
9935 cust
->includes
[len
] = NULL
;
9937 htab_delete (all_children
);
9938 htab_delete (all_type_symtabs
);
9942 /* Compute the 'includes' field for the symtabs of all the CUs we just
9946 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9948 for (dwarf2_per_cu_data
*iter
: dwarf2_per_objfile
->just_read_cus
)
9950 if (! iter
->is_debug_types
)
9951 compute_compunit_symtab_includes (iter
);
9954 dwarf2_per_objfile
->just_read_cus
.clear ();
9957 /* Generate full symbol information for PER_CU, whose DIEs have
9958 already been loaded into memory. */
9961 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9962 enum language pretend_language
)
9964 struct dwarf2_cu
*cu
= per_cu
->cu
;
9965 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
9966 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9967 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9968 CORE_ADDR lowpc
, highpc
;
9969 struct compunit_symtab
*cust
;
9971 struct block
*static_block
;
9974 baseaddr
= objfile
->text_section_offset ();
9976 /* Clear the list here in case something was left over. */
9977 cu
->method_list
.clear ();
9979 cu
->language
= pretend_language
;
9980 cu
->language_defn
= language_def (cu
->language
);
9982 /* Do line number decoding in read_file_scope () */
9983 process_die (cu
->dies
, cu
);
9985 /* For now fudge the Go package. */
9986 if (cu
->language
== language_go
)
9987 fixup_go_packaging (cu
);
9989 /* Now that we have processed all the DIEs in the CU, all the types
9990 should be complete, and it should now be safe to compute all of the
9992 compute_delayed_physnames (cu
);
9994 if (cu
->language
== language_rust
)
9995 rust_union_quirks (cu
);
9997 /* Some compilers don't define a DW_AT_high_pc attribute for the
9998 compilation unit. If the DW_AT_high_pc is missing, synthesize
9999 it, by scanning the DIE's below the compilation unit. */
10000 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
10002 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
10003 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
10005 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
10006 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
10007 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
10008 addrmap to help ensure it has an accurate map of pc values belonging to
10010 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
10012 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
10013 SECT_OFF_TEXT (objfile
),
10018 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
10020 /* Set symtab language to language from DW_AT_language. If the
10021 compilation is from a C file generated by language preprocessors, do
10022 not set the language if it was already deduced by start_subfile. */
10023 if (!(cu
->language
== language_c
10024 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
10025 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10027 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
10028 produce DW_AT_location with location lists but it can be possibly
10029 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
10030 there were bugs in prologue debug info, fixed later in GCC-4.5
10031 by "unwind info for epilogues" patch (which is not directly related).
10033 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
10034 needed, it would be wrong due to missing DW_AT_producer there.
10036 Still one can confuse GDB by using non-standard GCC compilation
10037 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
10039 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
10040 cust
->locations_valid
= 1;
10042 if (gcc_4_minor
>= 5)
10043 cust
->epilogue_unwind_valid
= 1;
10045 cust
->call_site_htab
= cu
->call_site_htab
;
10048 if (dwarf2_per_objfile
->using_index
)
10049 per_cu
->v
.quick
->compunit_symtab
= cust
;
10052 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
10053 pst
->compunit_symtab
= cust
;
10054 pst
->readin
= true;
10057 /* Push it for inclusion processing later. */
10058 dwarf2_per_objfile
->just_read_cus
.push_back (per_cu
);
10060 /* Not needed any more. */
10061 cu
->reset_builder ();
10064 /* Generate full symbol information for type unit PER_CU, whose DIEs have
10065 already been loaded into memory. */
10068 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
10069 enum language pretend_language
)
10071 struct dwarf2_cu
*cu
= per_cu
->cu
;
10072 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10073 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10074 struct compunit_symtab
*cust
;
10075 struct signatured_type
*sig_type
;
10077 gdb_assert (per_cu
->is_debug_types
);
10078 sig_type
= (struct signatured_type
*) per_cu
;
10080 /* Clear the list here in case something was left over. */
10081 cu
->method_list
.clear ();
10083 cu
->language
= pretend_language
;
10084 cu
->language_defn
= language_def (cu
->language
);
10086 /* The symbol tables are set up in read_type_unit_scope. */
10087 process_die (cu
->dies
, cu
);
10089 /* For now fudge the Go package. */
10090 if (cu
->language
== language_go
)
10091 fixup_go_packaging (cu
);
10093 /* Now that we have processed all the DIEs in the CU, all the types
10094 should be complete, and it should now be safe to compute all of the
10096 compute_delayed_physnames (cu
);
10098 if (cu
->language
== language_rust
)
10099 rust_union_quirks (cu
);
10101 /* TUs share symbol tables.
10102 If this is the first TU to use this symtab, complete the construction
10103 of it with end_expandable_symtab. Otherwise, complete the addition of
10104 this TU's symbols to the existing symtab. */
10105 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
10107 buildsym_compunit
*builder
= cu
->get_builder ();
10108 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
10109 sig_type
->type_unit_group
->compunit_symtab
= cust
;
10113 /* Set symtab language to language from DW_AT_language. If the
10114 compilation is from a C file generated by language preprocessors,
10115 do not set the language if it was already deduced by
10117 if (!(cu
->language
== language_c
10118 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
10119 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10124 cu
->get_builder ()->augment_type_symtab ();
10125 cust
= sig_type
->type_unit_group
->compunit_symtab
;
10128 if (dwarf2_per_objfile
->using_index
)
10129 per_cu
->v
.quick
->compunit_symtab
= cust
;
10132 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
10133 pst
->compunit_symtab
= cust
;
10134 pst
->readin
= true;
10137 /* Not needed any more. */
10138 cu
->reset_builder ();
10141 /* Process an imported unit DIE. */
10144 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10146 struct attribute
*attr
;
10148 /* For now we don't handle imported units in type units. */
10149 if (cu
->per_cu
->is_debug_types
)
10151 error (_("Dwarf Error: DW_TAG_imported_unit is not"
10152 " supported in type units [in module %s]"),
10153 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
10156 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10159 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
10160 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
10161 dwarf2_per_cu_data
*per_cu
10162 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
10163 cu
->per_cu
->dwarf2_per_objfile
);
10165 /* If necessary, add it to the queue and load its DIEs. */
10166 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
10167 load_full_comp_unit (per_cu
, false, cu
->language
);
10169 cu
->per_cu
->imported_symtabs_push (per_cu
);
10173 /* RAII object that represents a process_die scope: i.e.,
10174 starts/finishes processing a DIE. */
10175 class process_die_scope
10178 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
10179 : m_die (die
), m_cu (cu
)
10181 /* We should only be processing DIEs not already in process. */
10182 gdb_assert (!m_die
->in_process
);
10183 m_die
->in_process
= true;
10186 ~process_die_scope ()
10188 m_die
->in_process
= false;
10190 /* If we're done processing the DIE for the CU that owns the line
10191 header, we don't need the line header anymore. */
10192 if (m_cu
->line_header_die_owner
== m_die
)
10194 delete m_cu
->line_header
;
10195 m_cu
->line_header
= NULL
;
10196 m_cu
->line_header_die_owner
= NULL
;
10205 /* Process a die and its children. */
10208 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10210 process_die_scope
scope (die
, cu
);
10214 case DW_TAG_padding
:
10216 case DW_TAG_compile_unit
:
10217 case DW_TAG_partial_unit
:
10218 read_file_scope (die
, cu
);
10220 case DW_TAG_type_unit
:
10221 read_type_unit_scope (die
, cu
);
10223 case DW_TAG_subprogram
:
10224 /* Nested subprograms in Fortran get a prefix. */
10225 if (cu
->language
== language_fortran
10226 && die
->parent
!= NULL
10227 && die
->parent
->tag
== DW_TAG_subprogram
)
10228 cu
->processing_has_namespace_info
= true;
10229 /* Fall through. */
10230 case DW_TAG_inlined_subroutine
:
10231 read_func_scope (die
, cu
);
10233 case DW_TAG_lexical_block
:
10234 case DW_TAG_try_block
:
10235 case DW_TAG_catch_block
:
10236 read_lexical_block_scope (die
, cu
);
10238 case DW_TAG_call_site
:
10239 case DW_TAG_GNU_call_site
:
10240 read_call_site_scope (die
, cu
);
10242 case DW_TAG_class_type
:
10243 case DW_TAG_interface_type
:
10244 case DW_TAG_structure_type
:
10245 case DW_TAG_union_type
:
10246 process_structure_scope (die
, cu
);
10248 case DW_TAG_enumeration_type
:
10249 process_enumeration_scope (die
, cu
);
10252 /* These dies have a type, but processing them does not create
10253 a symbol or recurse to process the children. Therefore we can
10254 read them on-demand through read_type_die. */
10255 case DW_TAG_subroutine_type
:
10256 case DW_TAG_set_type
:
10257 case DW_TAG_array_type
:
10258 case DW_TAG_pointer_type
:
10259 case DW_TAG_ptr_to_member_type
:
10260 case DW_TAG_reference_type
:
10261 case DW_TAG_rvalue_reference_type
:
10262 case DW_TAG_string_type
:
10265 case DW_TAG_base_type
:
10266 case DW_TAG_subrange_type
:
10267 case DW_TAG_typedef
:
10268 /* Add a typedef symbol for the type definition, if it has a
10270 new_symbol (die
, read_type_die (die
, cu
), cu
);
10272 case DW_TAG_common_block
:
10273 read_common_block (die
, cu
);
10275 case DW_TAG_common_inclusion
:
10277 case DW_TAG_namespace
:
10278 cu
->processing_has_namespace_info
= true;
10279 read_namespace (die
, cu
);
10281 case DW_TAG_module
:
10282 cu
->processing_has_namespace_info
= true;
10283 read_module (die
, cu
);
10285 case DW_TAG_imported_declaration
:
10286 cu
->processing_has_namespace_info
= true;
10287 if (read_namespace_alias (die
, cu
))
10289 /* The declaration is not a global namespace alias. */
10290 /* Fall through. */
10291 case DW_TAG_imported_module
:
10292 cu
->processing_has_namespace_info
= true;
10293 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
10294 || cu
->language
!= language_fortran
))
10295 complaint (_("Tag '%s' has unexpected children"),
10296 dwarf_tag_name (die
->tag
));
10297 read_import_statement (die
, cu
);
10300 case DW_TAG_imported_unit
:
10301 process_imported_unit_die (die
, cu
);
10304 case DW_TAG_variable
:
10305 read_variable (die
, cu
);
10309 new_symbol (die
, NULL
, cu
);
10314 /* DWARF name computation. */
10316 /* A helper function for dwarf2_compute_name which determines whether DIE
10317 needs to have the name of the scope prepended to the name listed in the
10321 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10323 struct attribute
*attr
;
10327 case DW_TAG_namespace
:
10328 case DW_TAG_typedef
:
10329 case DW_TAG_class_type
:
10330 case DW_TAG_interface_type
:
10331 case DW_TAG_structure_type
:
10332 case DW_TAG_union_type
:
10333 case DW_TAG_enumeration_type
:
10334 case DW_TAG_enumerator
:
10335 case DW_TAG_subprogram
:
10336 case DW_TAG_inlined_subroutine
:
10337 case DW_TAG_member
:
10338 case DW_TAG_imported_declaration
:
10341 case DW_TAG_variable
:
10342 case DW_TAG_constant
:
10343 /* We only need to prefix "globally" visible variables. These include
10344 any variable marked with DW_AT_external or any variable that
10345 lives in a namespace. [Variables in anonymous namespaces
10346 require prefixing, but they are not DW_AT_external.] */
10348 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
10350 struct dwarf2_cu
*spec_cu
= cu
;
10352 return die_needs_namespace (die_specification (die
, &spec_cu
),
10356 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10357 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
10358 && die
->parent
->tag
!= DW_TAG_module
)
10360 /* A variable in a lexical block of some kind does not need a
10361 namespace, even though in C++ such variables may be external
10362 and have a mangled name. */
10363 if (die
->parent
->tag
== DW_TAG_lexical_block
10364 || die
->parent
->tag
== DW_TAG_try_block
10365 || die
->parent
->tag
== DW_TAG_catch_block
10366 || die
->parent
->tag
== DW_TAG_subprogram
)
10375 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
10376 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10377 defined for the given DIE. */
10379 static struct attribute
*
10380 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
10382 struct attribute
*attr
;
10384 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
10386 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10391 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10392 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10393 defined for the given DIE. */
10395 static const char *
10396 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10398 const char *linkage_name
;
10400 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10401 if (linkage_name
== NULL
)
10402 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10404 return linkage_name
;
10407 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10408 compute the physname for the object, which include a method's:
10409 - formal parameters (C++),
10410 - receiver type (Go),
10412 The term "physname" is a bit confusing.
10413 For C++, for example, it is the demangled name.
10414 For Go, for example, it's the mangled name.
10416 For Ada, return the DIE's linkage name rather than the fully qualified
10417 name. PHYSNAME is ignored..
10419 The result is allocated on the objfile_obstack and canonicalized. */
10421 static const char *
10422 dwarf2_compute_name (const char *name
,
10423 struct die_info
*die
, struct dwarf2_cu
*cu
,
10426 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10429 name
= dwarf2_name (die
, cu
);
10431 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10432 but otherwise compute it by typename_concat inside GDB.
10433 FIXME: Actually this is not really true, or at least not always true.
10434 It's all very confusing. compute_and_set_names doesn't try to demangle
10435 Fortran names because there is no mangling standard. So new_symbol
10436 will set the demangled name to the result of dwarf2_full_name, and it is
10437 the demangled name that GDB uses if it exists. */
10438 if (cu
->language
== language_ada
10439 || (cu
->language
== language_fortran
&& physname
))
10441 /* For Ada unit, we prefer the linkage name over the name, as
10442 the former contains the exported name, which the user expects
10443 to be able to reference. Ideally, we want the user to be able
10444 to reference this entity using either natural or linkage name,
10445 but we haven't started looking at this enhancement yet. */
10446 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10448 if (linkage_name
!= NULL
)
10449 return linkage_name
;
10452 /* These are the only languages we know how to qualify names in. */
10454 && (cu
->language
== language_cplus
10455 || cu
->language
== language_fortran
|| cu
->language
== language_d
10456 || cu
->language
== language_rust
))
10458 if (die_needs_namespace (die
, cu
))
10460 const char *prefix
;
10461 const char *canonical_name
= NULL
;
10465 prefix
= determine_prefix (die
, cu
);
10466 if (*prefix
!= '\0')
10468 gdb::unique_xmalloc_ptr
<char> prefixed_name
10469 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10471 buf
.puts (prefixed_name
.get ());
10476 /* Template parameters may be specified in the DIE's DW_AT_name, or
10477 as children with DW_TAG_template_type_param or
10478 DW_TAG_value_type_param. If the latter, add them to the name
10479 here. If the name already has template parameters, then
10480 skip this step; some versions of GCC emit both, and
10481 it is more efficient to use the pre-computed name.
10483 Something to keep in mind about this process: it is very
10484 unlikely, or in some cases downright impossible, to produce
10485 something that will match the mangled name of a function.
10486 If the definition of the function has the same debug info,
10487 we should be able to match up with it anyway. But fallbacks
10488 using the minimal symbol, for instance to find a method
10489 implemented in a stripped copy of libstdc++, will not work.
10490 If we do not have debug info for the definition, we will have to
10491 match them up some other way.
10493 When we do name matching there is a related problem with function
10494 templates; two instantiated function templates are allowed to
10495 differ only by their return types, which we do not add here. */
10497 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10499 struct attribute
*attr
;
10500 struct die_info
*child
;
10503 die
->building_fullname
= 1;
10505 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10509 const gdb_byte
*bytes
;
10510 struct dwarf2_locexpr_baton
*baton
;
10513 if (child
->tag
!= DW_TAG_template_type_param
10514 && child
->tag
!= DW_TAG_template_value_param
)
10525 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10528 complaint (_("template parameter missing DW_AT_type"));
10529 buf
.puts ("UNKNOWN_TYPE");
10532 type
= die_type (child
, cu
);
10534 if (child
->tag
== DW_TAG_template_type_param
)
10536 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10537 &type_print_raw_options
);
10541 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10544 complaint (_("template parameter missing "
10545 "DW_AT_const_value"));
10546 buf
.puts ("UNKNOWN_VALUE");
10550 dwarf2_const_value_attr (attr
, type
, name
,
10551 &cu
->comp_unit_obstack
, cu
,
10552 &value
, &bytes
, &baton
);
10554 if (TYPE_NOSIGN (type
))
10555 /* GDB prints characters as NUMBER 'CHAR'. If that's
10556 changed, this can use value_print instead. */
10557 c_printchar (value
, type
, &buf
);
10560 struct value_print_options opts
;
10563 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10567 else if (bytes
!= NULL
)
10569 v
= allocate_value (type
);
10570 memcpy (value_contents_writeable (v
), bytes
,
10571 TYPE_LENGTH (type
));
10574 v
= value_from_longest (type
, value
);
10576 /* Specify decimal so that we do not depend on
10578 get_formatted_print_options (&opts
, 'd');
10580 value_print (v
, &buf
, &opts
);
10585 die
->building_fullname
= 0;
10589 /* Close the argument list, with a space if necessary
10590 (nested templates). */
10591 if (!buf
.empty () && buf
.string ().back () == '>')
10598 /* For C++ methods, append formal parameter type
10599 information, if PHYSNAME. */
10601 if (physname
&& die
->tag
== DW_TAG_subprogram
10602 && cu
->language
== language_cplus
)
10604 struct type
*type
= read_type_die (die
, cu
);
10606 c_type_print_args (type
, &buf
, 1, cu
->language
,
10607 &type_print_raw_options
);
10609 if (cu
->language
== language_cplus
)
10611 /* Assume that an artificial first parameter is
10612 "this", but do not crash if it is not. RealView
10613 marks unnamed (and thus unused) parameters as
10614 artificial; there is no way to differentiate
10616 if (TYPE_NFIELDS (type
) > 0
10617 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10618 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
10619 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
10621 buf
.puts (" const");
10625 const std::string
&intermediate_name
= buf
.string ();
10627 if (cu
->language
== language_cplus
)
10629 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10630 &objfile
->per_bfd
->storage_obstack
);
10632 /* If we only computed INTERMEDIATE_NAME, or if
10633 INTERMEDIATE_NAME is already canonical, then we need to
10634 copy it to the appropriate obstack. */
10635 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10636 name
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
10637 intermediate_name
);
10639 name
= canonical_name
;
10646 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10647 If scope qualifiers are appropriate they will be added. The result
10648 will be allocated on the storage_obstack, or NULL if the DIE does
10649 not have a name. NAME may either be from a previous call to
10650 dwarf2_name or NULL.
10652 The output string will be canonicalized (if C++). */
10654 static const char *
10655 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10657 return dwarf2_compute_name (name
, die
, cu
, 0);
10660 /* Construct a physname for the given DIE in CU. NAME may either be
10661 from a previous call to dwarf2_name or NULL. The result will be
10662 allocated on the objfile_objstack or NULL if the DIE does not have a
10665 The output string will be canonicalized (if C++). */
10667 static const char *
10668 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10670 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10671 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10674 /* In this case dwarf2_compute_name is just a shortcut not building anything
10676 if (!die_needs_namespace (die
, cu
))
10677 return dwarf2_compute_name (name
, die
, cu
, 1);
10679 mangled
= dw2_linkage_name (die
, cu
);
10681 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
10682 See https://github.com/rust-lang/rust/issues/32925. */
10683 if (cu
->language
== language_rust
&& mangled
!= NULL
10684 && strchr (mangled
, '{') != NULL
)
10687 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10689 gdb::unique_xmalloc_ptr
<char> demangled
;
10690 if (mangled
!= NULL
)
10693 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
10695 /* Do nothing (do not demangle the symbol name). */
10697 else if (cu
->language
== language_go
)
10699 /* This is a lie, but we already lie to the caller new_symbol.
10700 new_symbol assumes we return the mangled name.
10701 This just undoes that lie until things are cleaned up. */
10705 /* Use DMGL_RET_DROP for C++ template functions to suppress
10706 their return type. It is easier for GDB users to search
10707 for such functions as `name(params)' than `long name(params)'.
10708 In such case the minimal symbol names do not match the full
10709 symbol names but for template functions there is never a need
10710 to look up their definition from their declaration so
10711 the only disadvantage remains the minimal symbol variant
10712 `long name(params)' does not have the proper inferior type. */
10713 demangled
.reset (gdb_demangle (mangled
,
10714 (DMGL_PARAMS
| DMGL_ANSI
10715 | DMGL_RET_DROP
)));
10718 canon
= demangled
.get ();
10726 if (canon
== NULL
|| check_physname
)
10728 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10730 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10732 /* It may not mean a bug in GDB. The compiler could also
10733 compute DW_AT_linkage_name incorrectly. But in such case
10734 GDB would need to be bug-to-bug compatible. */
10736 complaint (_("Computed physname <%s> does not match demangled <%s> "
10737 "(from linkage <%s>) - DIE at %s [in module %s]"),
10738 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10739 objfile_name (objfile
));
10741 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10742 is available here - over computed PHYSNAME. It is safer
10743 against both buggy GDB and buggy compilers. */
10757 retval
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
, retval
);
10762 /* Inspect DIE in CU for a namespace alias. If one exists, record
10763 a new symbol for it.
10765 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10768 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10770 struct attribute
*attr
;
10772 /* If the die does not have a name, this is not a namespace
10774 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10778 struct die_info
*d
= die
;
10779 struct dwarf2_cu
*imported_cu
= cu
;
10781 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10782 keep inspecting DIEs until we hit the underlying import. */
10783 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10784 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10786 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10790 d
= follow_die_ref (d
, attr
, &imported_cu
);
10791 if (d
->tag
!= DW_TAG_imported_declaration
)
10795 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10797 complaint (_("DIE at %s has too many recursively imported "
10798 "declarations"), sect_offset_str (d
->sect_off
));
10805 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
10807 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
10808 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
10810 /* This declaration is a global namespace alias. Add
10811 a symbol for it whose type is the aliased namespace. */
10812 new_symbol (die
, type
, cu
);
10821 /* Return the using directives repository (global or local?) to use in the
10822 current context for CU.
10824 For Ada, imported declarations can materialize renamings, which *may* be
10825 global. However it is impossible (for now?) in DWARF to distinguish
10826 "external" imported declarations and "static" ones. As all imported
10827 declarations seem to be static in all other languages, make them all CU-wide
10828 global only in Ada. */
10830 static struct using_direct
**
10831 using_directives (struct dwarf2_cu
*cu
)
10833 if (cu
->language
== language_ada
10834 && cu
->get_builder ()->outermost_context_p ())
10835 return cu
->get_builder ()->get_global_using_directives ();
10837 return cu
->get_builder ()->get_local_using_directives ();
10840 /* Read the import statement specified by the given die and record it. */
10843 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10845 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10846 struct attribute
*import_attr
;
10847 struct die_info
*imported_die
, *child_die
;
10848 struct dwarf2_cu
*imported_cu
;
10849 const char *imported_name
;
10850 const char *imported_name_prefix
;
10851 const char *canonical_name
;
10852 const char *import_alias
;
10853 const char *imported_declaration
= NULL
;
10854 const char *import_prefix
;
10855 std::vector
<const char *> excludes
;
10857 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10858 if (import_attr
== NULL
)
10860 complaint (_("Tag '%s' has no DW_AT_import"),
10861 dwarf_tag_name (die
->tag
));
10866 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10867 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10868 if (imported_name
== NULL
)
10870 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10872 The import in the following code:
10886 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10887 <52> DW_AT_decl_file : 1
10888 <53> DW_AT_decl_line : 6
10889 <54> DW_AT_import : <0x75>
10890 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10891 <59> DW_AT_name : B
10892 <5b> DW_AT_decl_file : 1
10893 <5c> DW_AT_decl_line : 2
10894 <5d> DW_AT_type : <0x6e>
10896 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10897 <76> DW_AT_byte_size : 4
10898 <77> DW_AT_encoding : 5 (signed)
10900 imports the wrong die ( 0x75 instead of 0x58 ).
10901 This case will be ignored until the gcc bug is fixed. */
10905 /* Figure out the local name after import. */
10906 import_alias
= dwarf2_name (die
, cu
);
10908 /* Figure out where the statement is being imported to. */
10909 import_prefix
= determine_prefix (die
, cu
);
10911 /* Figure out what the scope of the imported die is and prepend it
10912 to the name of the imported die. */
10913 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10915 if (imported_die
->tag
!= DW_TAG_namespace
10916 && imported_die
->tag
!= DW_TAG_module
)
10918 imported_declaration
= imported_name
;
10919 canonical_name
= imported_name_prefix
;
10921 else if (strlen (imported_name_prefix
) > 0)
10922 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10923 imported_name_prefix
,
10924 (cu
->language
== language_d
? "." : "::"),
10925 imported_name
, (char *) NULL
);
10927 canonical_name
= imported_name
;
10929 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
10930 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10931 child_die
= sibling_die (child_die
))
10933 /* DWARF-4: A Fortran use statement with a “rename list” may be
10934 represented by an imported module entry with an import attribute
10935 referring to the module and owned entries corresponding to those
10936 entities that are renamed as part of being imported. */
10938 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10940 complaint (_("child DW_TAG_imported_declaration expected "
10941 "- DIE at %s [in module %s]"),
10942 sect_offset_str (child_die
->sect_off
),
10943 objfile_name (objfile
));
10947 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10948 if (import_attr
== NULL
)
10950 complaint (_("Tag '%s' has no DW_AT_import"),
10951 dwarf_tag_name (child_die
->tag
));
10956 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10958 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10959 if (imported_name
== NULL
)
10961 complaint (_("child DW_TAG_imported_declaration has unknown "
10962 "imported name - DIE at %s [in module %s]"),
10963 sect_offset_str (child_die
->sect_off
),
10964 objfile_name (objfile
));
10968 excludes
.push_back (imported_name
);
10970 process_die (child_die
, cu
);
10973 add_using_directive (using_directives (cu
),
10977 imported_declaration
,
10980 &objfile
->objfile_obstack
);
10983 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10984 types, but gives them a size of zero. Starting with version 14,
10985 ICC is compatible with GCC. */
10988 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10990 if (!cu
->checked_producer
)
10991 check_producer (cu
);
10993 return cu
->producer_is_icc_lt_14
;
10996 /* ICC generates a DW_AT_type for C void functions. This was observed on
10997 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10998 which says that void functions should not have a DW_AT_type. */
11001 producer_is_icc (struct dwarf2_cu
*cu
)
11003 if (!cu
->checked_producer
)
11004 check_producer (cu
);
11006 return cu
->producer_is_icc
;
11009 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
11010 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
11011 this, it was first present in GCC release 4.3.0. */
11014 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
11016 if (!cu
->checked_producer
)
11017 check_producer (cu
);
11019 return cu
->producer_is_gcc_lt_4_3
;
11022 static file_and_directory
11023 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
11025 file_and_directory res
;
11027 /* Find the filename. Do not use dwarf2_name here, since the filename
11028 is not a source language identifier. */
11029 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
11030 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
11032 if (res
.comp_dir
== NULL
11033 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
11034 && IS_ABSOLUTE_PATH (res
.name
))
11036 res
.comp_dir_storage
= ldirname (res
.name
);
11037 if (!res
.comp_dir_storage
.empty ())
11038 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
11040 if (res
.comp_dir
!= NULL
)
11042 /* Irix 6.2 native cc prepends <machine>.: to the compilation
11043 directory, get rid of it. */
11044 const char *cp
= strchr (res
.comp_dir
, ':');
11046 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
11047 res
.comp_dir
= cp
+ 1;
11050 if (res
.name
== NULL
)
11051 res
.name
= "<unknown>";
11056 /* Handle DW_AT_stmt_list for a compilation unit.
11057 DIE is the DW_TAG_compile_unit die for CU.
11058 COMP_DIR is the compilation directory. LOWPC is passed to
11059 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
11062 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
11063 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
11065 struct dwarf2_per_objfile
*dwarf2_per_objfile
11066 = cu
->per_cu
->dwarf2_per_objfile
;
11067 struct attribute
*attr
;
11068 struct line_header line_header_local
;
11069 hashval_t line_header_local_hash
;
11071 int decode_mapping
;
11073 gdb_assert (! cu
->per_cu
->is_debug_types
);
11075 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
11079 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11081 /* The line header hash table is only created if needed (it exists to
11082 prevent redundant reading of the line table for partial_units).
11083 If we're given a partial_unit, we'll need it. If we're given a
11084 compile_unit, then use the line header hash table if it's already
11085 created, but don't create one just yet. */
11087 if (dwarf2_per_objfile
->line_header_hash
== NULL
11088 && die
->tag
== DW_TAG_partial_unit
)
11090 dwarf2_per_objfile
->line_header_hash
11091 .reset (htab_create_alloc (127, line_header_hash_voidp
,
11092 line_header_eq_voidp
,
11093 free_line_header_voidp
,
11097 line_header_local
.sect_off
= line_offset
;
11098 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
11099 line_header_local_hash
= line_header_hash (&line_header_local
);
11100 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
11102 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
.get (),
11103 &line_header_local
,
11104 line_header_local_hash
, NO_INSERT
);
11106 /* For DW_TAG_compile_unit we need info like symtab::linetable which
11107 is not present in *SLOT (since if there is something in *SLOT then
11108 it will be for a partial_unit). */
11109 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
11111 gdb_assert (*slot
!= NULL
);
11112 cu
->line_header
= (struct line_header
*) *slot
;
11117 /* dwarf_decode_line_header does not yet provide sufficient information.
11118 We always have to call also dwarf_decode_lines for it. */
11119 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
11123 cu
->line_header
= lh
.release ();
11124 cu
->line_header_die_owner
= die
;
11126 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
11130 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
.get (),
11131 &line_header_local
,
11132 line_header_local_hash
, INSERT
);
11133 gdb_assert (slot
!= NULL
);
11135 if (slot
!= NULL
&& *slot
== NULL
)
11137 /* This newly decoded line number information unit will be owned
11138 by line_header_hash hash table. */
11139 *slot
= cu
->line_header
;
11140 cu
->line_header_die_owner
= NULL
;
11144 /* We cannot free any current entry in (*slot) as that struct line_header
11145 may be already used by multiple CUs. Create only temporary decoded
11146 line_header for this CU - it may happen at most once for each line
11147 number information unit. And if we're not using line_header_hash
11148 then this is what we want as well. */
11149 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
11151 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
11152 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
11157 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
11160 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11162 struct dwarf2_per_objfile
*dwarf2_per_objfile
11163 = cu
->per_cu
->dwarf2_per_objfile
;
11164 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11165 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11166 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
11167 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
11168 struct attribute
*attr
;
11169 struct die_info
*child_die
;
11170 CORE_ADDR baseaddr
;
11172 prepare_one_comp_unit (cu
, die
, cu
->language
);
11173 baseaddr
= objfile
->text_section_offset ();
11175 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
11177 /* If we didn't find a lowpc, set it to highpc to avoid complaints
11178 from finish_block. */
11179 if (lowpc
== ((CORE_ADDR
) -1))
11181 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11183 file_and_directory fnd
= find_file_and_directory (die
, cu
);
11185 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
11186 standardised yet. As a workaround for the language detection we fall
11187 back to the DW_AT_producer string. */
11188 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
11189 cu
->language
= language_opencl
;
11191 /* Similar hack for Go. */
11192 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
11193 set_cu_language (DW_LANG_Go
, cu
);
11195 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
11197 /* Decode line number information if present. We do this before
11198 processing child DIEs, so that the line header table is available
11199 for DW_AT_decl_file. */
11200 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
11202 /* Process all dies in compilation unit. */
11203 if (die
->child
!= NULL
)
11205 child_die
= die
->child
;
11206 while (child_die
&& child_die
->tag
)
11208 process_die (child_die
, cu
);
11209 child_die
= sibling_die (child_die
);
11213 /* Decode macro information, if present. Dwarf 2 macro information
11214 refers to information in the line number info statement program
11215 header, so we can only read it if we've read the header
11217 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
11219 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
11220 if (attr
&& cu
->line_header
)
11222 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
11223 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
11225 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
11229 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
11230 if (attr
&& cu
->line_header
)
11232 unsigned int macro_offset
= DW_UNSND (attr
);
11234 dwarf_decode_macros (cu
, macro_offset
, 0);
11240 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
11242 struct type_unit_group
*tu_group
;
11244 struct attribute
*attr
;
11246 struct signatured_type
*sig_type
;
11248 gdb_assert (per_cu
->is_debug_types
);
11249 sig_type
= (struct signatured_type
*) per_cu
;
11251 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
11253 /* If we're using .gdb_index (includes -readnow) then
11254 per_cu->type_unit_group may not have been set up yet. */
11255 if (sig_type
->type_unit_group
== NULL
)
11256 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
11257 tu_group
= sig_type
->type_unit_group
;
11259 /* If we've already processed this stmt_list there's no real need to
11260 do it again, we could fake it and just recreate the part we need
11261 (file name,index -> symtab mapping). If data shows this optimization
11262 is useful we can do it then. */
11263 first_time
= tu_group
->compunit_symtab
== NULL
;
11265 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
11270 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11271 lh
= dwarf_decode_line_header (line_offset
, this);
11276 start_symtab ("", NULL
, 0);
11279 gdb_assert (tu_group
->symtabs
== NULL
);
11280 gdb_assert (m_builder
== nullptr);
11281 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
11282 m_builder
.reset (new struct buildsym_compunit
11283 (COMPUNIT_OBJFILE (cust
), "",
11284 COMPUNIT_DIRNAME (cust
),
11285 compunit_language (cust
),
11291 line_header
= lh
.release ();
11292 line_header_die_owner
= die
;
11296 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
11298 /* Note: We don't assign tu_group->compunit_symtab yet because we're
11299 still initializing it, and our caller (a few levels up)
11300 process_full_type_unit still needs to know if this is the first
11303 tu_group
->num_symtabs
= line_header
->file_names_size ();
11304 tu_group
->symtabs
= XNEWVEC (struct symtab
*,
11305 line_header
->file_names_size ());
11307 auto &file_names
= line_header
->file_names ();
11308 for (i
= 0; i
< file_names
.size (); ++i
)
11310 file_entry
&fe
= file_names
[i
];
11311 dwarf2_start_subfile (this, fe
.name
,
11312 fe
.include_dir (line_header
));
11313 buildsym_compunit
*b
= get_builder ();
11314 if (b
->get_current_subfile ()->symtab
== NULL
)
11316 /* NOTE: start_subfile will recognize when it's been
11317 passed a file it has already seen. So we can't
11318 assume there's a simple mapping from
11319 cu->line_header->file_names to subfiles, plus
11320 cu->line_header->file_names may contain dups. */
11321 b
->get_current_subfile ()->symtab
11322 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
11325 fe
.symtab
= b
->get_current_subfile ()->symtab
;
11326 tu_group
->symtabs
[i
] = fe
.symtab
;
11331 gdb_assert (m_builder
== nullptr);
11332 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
11333 m_builder
.reset (new struct buildsym_compunit
11334 (COMPUNIT_OBJFILE (cust
), "",
11335 COMPUNIT_DIRNAME (cust
),
11336 compunit_language (cust
),
11339 auto &file_names
= line_header
->file_names ();
11340 for (i
= 0; i
< file_names
.size (); ++i
)
11342 file_entry
&fe
= file_names
[i
];
11343 fe
.symtab
= tu_group
->symtabs
[i
];
11347 /* The main symtab is allocated last. Type units don't have DW_AT_name
11348 so they don't have a "real" (so to speak) symtab anyway.
11349 There is later code that will assign the main symtab to all symbols
11350 that don't have one. We need to handle the case of a symbol with a
11351 missing symtab (DW_AT_decl_file) anyway. */
11354 /* Process DW_TAG_type_unit.
11355 For TUs we want to skip the first top level sibling if it's not the
11356 actual type being defined by this TU. In this case the first top
11357 level sibling is there to provide context only. */
11360 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11362 struct die_info
*child_die
;
11364 prepare_one_comp_unit (cu
, die
, language_minimal
);
11366 /* Initialize (or reinitialize) the machinery for building symtabs.
11367 We do this before processing child DIEs, so that the line header table
11368 is available for DW_AT_decl_file. */
11369 cu
->setup_type_unit_groups (die
);
11371 if (die
->child
!= NULL
)
11373 child_die
= die
->child
;
11374 while (child_die
&& child_die
->tag
)
11376 process_die (child_die
, cu
);
11377 child_die
= sibling_die (child_die
);
11384 http://gcc.gnu.org/wiki/DebugFission
11385 http://gcc.gnu.org/wiki/DebugFissionDWP
11387 To simplify handling of both DWO files ("object" files with the DWARF info)
11388 and DWP files (a file with the DWOs packaged up into one file), we treat
11389 DWP files as having a collection of virtual DWO files. */
11392 hash_dwo_file (const void *item
)
11394 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11397 hash
= htab_hash_string (dwo_file
->dwo_name
);
11398 if (dwo_file
->comp_dir
!= NULL
)
11399 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11404 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11406 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11407 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11409 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11411 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11412 return lhs
->comp_dir
== rhs
->comp_dir
;
11413 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11416 /* Allocate a hash table for DWO files. */
11419 allocate_dwo_file_hash_table (struct objfile
*objfile
)
11421 auto delete_dwo_file
= [] (void *item
)
11423 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
11428 return htab_up (htab_create_alloc (41,
11435 /* Lookup DWO file DWO_NAME. */
11438 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11439 const char *dwo_name
,
11440 const char *comp_dir
)
11442 struct dwo_file find_entry
;
11445 if (dwarf2_per_objfile
->dwo_files
== NULL
)
11446 dwarf2_per_objfile
->dwo_files
11447 = allocate_dwo_file_hash_table (dwarf2_per_objfile
->objfile
);
11449 find_entry
.dwo_name
= dwo_name
;
11450 find_entry
.comp_dir
= comp_dir
;
11451 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
.get (), &find_entry
,
11458 hash_dwo_unit (const void *item
)
11460 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11462 /* This drops the top 32 bits of the id, but is ok for a hash. */
11463 return dwo_unit
->signature
;
11467 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11469 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11470 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11472 /* The signature is assumed to be unique within the DWO file.
11473 So while object file CU dwo_id's always have the value zero,
11474 that's OK, assuming each object file DWO file has only one CU,
11475 and that's the rule for now. */
11476 return lhs
->signature
== rhs
->signature
;
11479 /* Allocate a hash table for DWO CUs,TUs.
11480 There is one of these tables for each of CUs,TUs for each DWO file. */
11483 allocate_dwo_unit_table (struct objfile
*objfile
)
11485 /* Start out with a pretty small number.
11486 Generally DWO files contain only one CU and maybe some TUs. */
11487 return htab_up (htab_create_alloc (3,
11490 NULL
, xcalloc
, xfree
));
11493 /* die_reader_func for create_dwo_cu. */
11496 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11497 const gdb_byte
*info_ptr
,
11498 struct die_info
*comp_unit_die
,
11499 struct dwo_file
*dwo_file
,
11500 struct dwo_unit
*dwo_unit
)
11502 struct dwarf2_cu
*cu
= reader
->cu
;
11503 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11504 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11506 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11507 if (!signature
.has_value ())
11509 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11510 " its dwo_id [in module %s]"),
11511 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11515 dwo_unit
->dwo_file
= dwo_file
;
11516 dwo_unit
->signature
= *signature
;
11517 dwo_unit
->section
= section
;
11518 dwo_unit
->sect_off
= sect_off
;
11519 dwo_unit
->length
= cu
->per_cu
->length
;
11521 if (dwarf_read_debug
)
11522 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11523 sect_offset_str (sect_off
),
11524 hex_string (dwo_unit
->signature
));
11527 /* Create the dwo_units for the CUs in a DWO_FILE.
11528 Note: This function processes DWO files only, not DWP files. */
11531 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11532 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11533 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
11535 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11536 const gdb_byte
*info_ptr
, *end_ptr
;
11538 section
.read (objfile
);
11539 info_ptr
= section
.buffer
;
11541 if (info_ptr
== NULL
)
11544 if (dwarf_read_debug
)
11546 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11547 section
.get_name (),
11548 section
.get_file_name ());
11551 end_ptr
= info_ptr
+ section
.size
;
11552 while (info_ptr
< end_ptr
)
11554 struct dwarf2_per_cu_data per_cu
;
11555 struct dwo_unit read_unit
{};
11556 struct dwo_unit
*dwo_unit
;
11558 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11560 memset (&per_cu
, 0, sizeof (per_cu
));
11561 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
11562 per_cu
.is_debug_types
= 0;
11563 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11564 per_cu
.section
= §ion
;
11566 cutu_reader
reader (&per_cu
, cu
, &dwo_file
);
11567 if (!reader
.dummy_p
)
11568 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11569 &dwo_file
, &read_unit
);
11570 info_ptr
+= per_cu
.length
;
11572 // If the unit could not be parsed, skip it.
11573 if (read_unit
.dwo_file
== NULL
)
11576 if (cus_htab
== NULL
)
11577 cus_htab
= allocate_dwo_unit_table (objfile
);
11579 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11580 *dwo_unit
= read_unit
;
11581 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11582 gdb_assert (slot
!= NULL
);
11585 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11586 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11588 complaint (_("debug cu entry at offset %s is duplicate to"
11589 " the entry at offset %s, signature %s"),
11590 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11591 hex_string (dwo_unit
->signature
));
11593 *slot
= (void *)dwo_unit
;
11597 /* DWP file .debug_{cu,tu}_index section format:
11598 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11602 Both index sections have the same format, and serve to map a 64-bit
11603 signature to a set of section numbers. Each section begins with a header,
11604 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11605 indexes, and a pool of 32-bit section numbers. The index sections will be
11606 aligned at 8-byte boundaries in the file.
11608 The index section header consists of:
11610 V, 32 bit version number
11612 N, 32 bit number of compilation units or type units in the index
11613 M, 32 bit number of slots in the hash table
11615 Numbers are recorded using the byte order of the application binary.
11617 The hash table begins at offset 16 in the section, and consists of an array
11618 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11619 order of the application binary). Unused slots in the hash table are 0.
11620 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11622 The parallel table begins immediately after the hash table
11623 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11624 array of 32-bit indexes (using the byte order of the application binary),
11625 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11626 table contains a 32-bit index into the pool of section numbers. For unused
11627 hash table slots, the corresponding entry in the parallel table will be 0.
11629 The pool of section numbers begins immediately following the hash table
11630 (at offset 16 + 12 * M from the beginning of the section). The pool of
11631 section numbers consists of an array of 32-bit words (using the byte order
11632 of the application binary). Each item in the array is indexed starting
11633 from 0. The hash table entry provides the index of the first section
11634 number in the set. Additional section numbers in the set follow, and the
11635 set is terminated by a 0 entry (section number 0 is not used in ELF).
11637 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11638 section must be the first entry in the set, and the .debug_abbrev.dwo must
11639 be the second entry. Other members of the set may follow in any order.
11645 DWP Version 2 combines all the .debug_info, etc. sections into one,
11646 and the entries in the index tables are now offsets into these sections.
11647 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11650 Index Section Contents:
11652 Hash Table of Signatures dwp_hash_table.hash_table
11653 Parallel Table of Indices dwp_hash_table.unit_table
11654 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
11655 Table of Section Sizes dwp_hash_table.v2.sizes
11657 The index section header consists of:
11659 V, 32 bit version number
11660 L, 32 bit number of columns in the table of section offsets
11661 N, 32 bit number of compilation units or type units in the index
11662 M, 32 bit number of slots in the hash table
11664 Numbers are recorded using the byte order of the application binary.
11666 The hash table has the same format as version 1.
11667 The parallel table of indices has the same format as version 1,
11668 except that the entries are origin-1 indices into the table of sections
11669 offsets and the table of section sizes.
11671 The table of offsets begins immediately following the parallel table
11672 (at offset 16 + 12 * M from the beginning of the section). The table is
11673 a two-dimensional array of 32-bit words (using the byte order of the
11674 application binary), with L columns and N+1 rows, in row-major order.
11675 Each row in the array is indexed starting from 0. The first row provides
11676 a key to the remaining rows: each column in this row provides an identifier
11677 for a debug section, and the offsets in the same column of subsequent rows
11678 refer to that section. The section identifiers are:
11680 DW_SECT_INFO 1 .debug_info.dwo
11681 DW_SECT_TYPES 2 .debug_types.dwo
11682 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11683 DW_SECT_LINE 4 .debug_line.dwo
11684 DW_SECT_LOC 5 .debug_loc.dwo
11685 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11686 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11687 DW_SECT_MACRO 8 .debug_macro.dwo
11689 The offsets provided by the CU and TU index sections are the base offsets
11690 for the contributions made by each CU or TU to the corresponding section
11691 in the package file. Each CU and TU header contains an abbrev_offset
11692 field, used to find the abbreviations table for that CU or TU within the
11693 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11694 be interpreted as relative to the base offset given in the index section.
11695 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11696 should be interpreted as relative to the base offset for .debug_line.dwo,
11697 and offsets into other debug sections obtained from DWARF attributes should
11698 also be interpreted as relative to the corresponding base offset.
11700 The table of sizes begins immediately following the table of offsets.
11701 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11702 with L columns and N rows, in row-major order. Each row in the array is
11703 indexed starting from 1 (row 0 is shared by the two tables).
11707 Hash table lookup is handled the same in version 1 and 2:
11709 We assume that N and M will not exceed 2^32 - 1.
11710 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11712 Given a 64-bit compilation unit signature or a type signature S, an entry
11713 in the hash table is located as follows:
11715 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11716 the low-order k bits all set to 1.
11718 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11720 3) If the hash table entry at index H matches the signature, use that
11721 entry. If the hash table entry at index H is unused (all zeroes),
11722 terminate the search: the signature is not present in the table.
11724 4) Let H = (H + H') modulo M. Repeat at Step 3.
11726 Because M > N and H' and M are relatively prime, the search is guaranteed
11727 to stop at an unused slot or find the match. */
11729 /* Create a hash table to map DWO IDs to their CU/TU entry in
11730 .debug_{info,types}.dwo in DWP_FILE.
11731 Returns NULL if there isn't one.
11732 Note: This function processes DWP files only, not DWO files. */
11734 static struct dwp_hash_table
*
11735 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11736 struct dwp_file
*dwp_file
, int is_debug_types
)
11738 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11739 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11740 const gdb_byte
*index_ptr
, *index_end
;
11741 struct dwarf2_section_info
*index
;
11742 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11743 struct dwp_hash_table
*htab
;
11745 if (is_debug_types
)
11746 index
= &dwp_file
->sections
.tu_index
;
11748 index
= &dwp_file
->sections
.cu_index
;
11750 if (index
->empty ())
11752 index
->read (objfile
);
11754 index_ptr
= index
->buffer
;
11755 index_end
= index_ptr
+ index
->size
;
11757 version
= read_4_bytes (dbfd
, index_ptr
);
11760 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11764 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11766 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11769 if (version
!= 1 && version
!= 2)
11771 error (_("Dwarf Error: unsupported DWP file version (%s)"
11772 " [in module %s]"),
11773 pulongest (version
), dwp_file
->name
);
11775 if (nr_slots
!= (nr_slots
& -nr_slots
))
11777 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11778 " is not power of 2 [in module %s]"),
11779 pulongest (nr_slots
), dwp_file
->name
);
11782 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
11783 htab
->version
= version
;
11784 htab
->nr_columns
= nr_columns
;
11785 htab
->nr_units
= nr_units
;
11786 htab
->nr_slots
= nr_slots
;
11787 htab
->hash_table
= index_ptr
;
11788 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11790 /* Exit early if the table is empty. */
11791 if (nr_slots
== 0 || nr_units
== 0
11792 || (version
== 2 && nr_columns
== 0))
11794 /* All must be zero. */
11795 if (nr_slots
!= 0 || nr_units
!= 0
11796 || (version
== 2 && nr_columns
!= 0))
11798 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11799 " all zero [in modules %s]"),
11807 htab
->section_pool
.v1
.indices
=
11808 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11809 /* It's harder to decide whether the section is too small in v1.
11810 V1 is deprecated anyway so we punt. */
11814 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11815 int *ids
= htab
->section_pool
.v2
.section_ids
;
11816 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11817 /* Reverse map for error checking. */
11818 int ids_seen
[DW_SECT_MAX
+ 1];
11821 if (nr_columns
< 2)
11823 error (_("Dwarf Error: bad DWP hash table, too few columns"
11824 " in section table [in module %s]"),
11827 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11829 error (_("Dwarf Error: bad DWP hash table, too many columns"
11830 " in section table [in module %s]"),
11833 memset (ids
, 255, sizeof_ids
);
11834 memset (ids_seen
, 255, sizeof (ids_seen
));
11835 for (i
= 0; i
< nr_columns
; ++i
)
11837 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11839 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11841 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11842 " in section table [in module %s]"),
11843 id
, dwp_file
->name
);
11845 if (ids_seen
[id
] != -1)
11847 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11848 " id %d in section table [in module %s]"),
11849 id
, dwp_file
->name
);
11854 /* Must have exactly one info or types section. */
11855 if (((ids_seen
[DW_SECT_INFO
] != -1)
11856 + (ids_seen
[DW_SECT_TYPES
] != -1))
11859 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11860 " DWO info/types section [in module %s]"),
11863 /* Must have an abbrev section. */
11864 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11866 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11867 " section [in module %s]"),
11870 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11871 htab
->section_pool
.v2
.sizes
=
11872 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11873 * nr_units
* nr_columns
);
11874 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11875 * nr_units
* nr_columns
))
11878 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11879 " [in module %s]"),
11887 /* Update SECTIONS with the data from SECTP.
11889 This function is like the other "locate" section routines that are
11890 passed to bfd_map_over_sections, but in this context the sections to
11891 read comes from the DWP V1 hash table, not the full ELF section table.
11893 The result is non-zero for success, or zero if an error was found. */
11896 locate_v1_virtual_dwo_sections (asection
*sectp
,
11897 struct virtual_v1_dwo_sections
*sections
)
11899 const struct dwop_section_names
*names
= &dwop_section_names
;
11901 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
11903 /* There can be only one. */
11904 if (sections
->abbrev
.s
.section
!= NULL
)
11906 sections
->abbrev
.s
.section
= sectp
;
11907 sections
->abbrev
.size
= bfd_section_size (sectp
);
11909 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
11910 || section_is_p (sectp
->name
, &names
->types_dwo
))
11912 /* There can be only one. */
11913 if (sections
->info_or_types
.s
.section
!= NULL
)
11915 sections
->info_or_types
.s
.section
= sectp
;
11916 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11918 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
11920 /* There can be only one. */
11921 if (sections
->line
.s
.section
!= NULL
)
11923 sections
->line
.s
.section
= sectp
;
11924 sections
->line
.size
= bfd_section_size (sectp
);
11926 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
11928 /* There can be only one. */
11929 if (sections
->loc
.s
.section
!= NULL
)
11931 sections
->loc
.s
.section
= sectp
;
11932 sections
->loc
.size
= bfd_section_size (sectp
);
11934 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
11936 /* There can be only one. */
11937 if (sections
->macinfo
.s
.section
!= NULL
)
11939 sections
->macinfo
.s
.section
= sectp
;
11940 sections
->macinfo
.size
= bfd_section_size (sectp
);
11942 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
11944 /* There can be only one. */
11945 if (sections
->macro
.s
.section
!= NULL
)
11947 sections
->macro
.s
.section
= sectp
;
11948 sections
->macro
.size
= bfd_section_size (sectp
);
11950 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
11952 /* There can be only one. */
11953 if (sections
->str_offsets
.s
.section
!= NULL
)
11955 sections
->str_offsets
.s
.section
= sectp
;
11956 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11960 /* No other kind of section is valid. */
11967 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11968 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11969 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11970 This is for DWP version 1 files. */
11972 static struct dwo_unit
*
11973 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11974 struct dwp_file
*dwp_file
,
11975 uint32_t unit_index
,
11976 const char *comp_dir
,
11977 ULONGEST signature
, int is_debug_types
)
11979 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11980 const struct dwp_hash_table
*dwp_htab
=
11981 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11982 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11983 const char *kind
= is_debug_types
? "TU" : "CU";
11984 struct dwo_file
*dwo_file
;
11985 struct dwo_unit
*dwo_unit
;
11986 struct virtual_v1_dwo_sections sections
;
11987 void **dwo_file_slot
;
11990 gdb_assert (dwp_file
->version
== 1);
11992 if (dwarf_read_debug
)
11994 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
11996 pulongest (unit_index
), hex_string (signature
),
12000 /* Fetch the sections of this DWO unit.
12001 Put a limit on the number of sections we look for so that bad data
12002 doesn't cause us to loop forever. */
12004 #define MAX_NR_V1_DWO_SECTIONS \
12005 (1 /* .debug_info or .debug_types */ \
12006 + 1 /* .debug_abbrev */ \
12007 + 1 /* .debug_line */ \
12008 + 1 /* .debug_loc */ \
12009 + 1 /* .debug_str_offsets */ \
12010 + 1 /* .debug_macro or .debug_macinfo */ \
12011 + 1 /* trailing zero */)
12013 memset (§ions
, 0, sizeof (sections
));
12015 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
12018 uint32_t section_nr
=
12019 read_4_bytes (dbfd
,
12020 dwp_htab
->section_pool
.v1
.indices
12021 + (unit_index
+ i
) * sizeof (uint32_t));
12023 if (section_nr
== 0)
12025 if (section_nr
>= dwp_file
->num_sections
)
12027 error (_("Dwarf Error: bad DWP hash table, section number too large"
12028 " [in module %s]"),
12032 sectp
= dwp_file
->elf_sections
[section_nr
];
12033 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
12035 error (_("Dwarf Error: bad DWP hash table, invalid section found"
12036 " [in module %s]"),
12042 || sections
.info_or_types
.empty ()
12043 || sections
.abbrev
.empty ())
12045 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
12046 " [in module %s]"),
12049 if (i
== MAX_NR_V1_DWO_SECTIONS
)
12051 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
12052 " [in module %s]"),
12056 /* It's easier for the rest of the code if we fake a struct dwo_file and
12057 have dwo_unit "live" in that. At least for now.
12059 The DWP file can be made up of a random collection of CUs and TUs.
12060 However, for each CU + set of TUs that came from the same original DWO
12061 file, we can combine them back into a virtual DWO file to save space
12062 (fewer struct dwo_file objects to allocate). Remember that for really
12063 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12065 std::string virtual_dwo_name
=
12066 string_printf ("virtual-dwo/%d-%d-%d-%d",
12067 sections
.abbrev
.get_id (),
12068 sections
.line
.get_id (),
12069 sections
.loc
.get_id (),
12070 sections
.str_offsets
.get_id ());
12071 /* Can we use an existing virtual DWO file? */
12072 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12073 virtual_dwo_name
.c_str (),
12075 /* Create one if necessary. */
12076 if (*dwo_file_slot
== NULL
)
12078 if (dwarf_read_debug
)
12080 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12081 virtual_dwo_name
.c_str ());
12083 dwo_file
= new struct dwo_file
;
12084 dwo_file
->dwo_name
= obstack_strdup (&objfile
->objfile_obstack
,
12086 dwo_file
->comp_dir
= comp_dir
;
12087 dwo_file
->sections
.abbrev
= sections
.abbrev
;
12088 dwo_file
->sections
.line
= sections
.line
;
12089 dwo_file
->sections
.loc
= sections
.loc
;
12090 dwo_file
->sections
.macinfo
= sections
.macinfo
;
12091 dwo_file
->sections
.macro
= sections
.macro
;
12092 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
12093 /* The "str" section is global to the entire DWP file. */
12094 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12095 /* The info or types section is assigned below to dwo_unit,
12096 there's no need to record it in dwo_file.
12097 Also, we can't simply record type sections in dwo_file because
12098 we record a pointer into the vector in dwo_unit. As we collect more
12099 types we'll grow the vector and eventually have to reallocate space
12100 for it, invalidating all copies of pointers into the previous
12102 *dwo_file_slot
= dwo_file
;
12106 if (dwarf_read_debug
)
12108 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12109 virtual_dwo_name
.c_str ());
12111 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12114 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12115 dwo_unit
->dwo_file
= dwo_file
;
12116 dwo_unit
->signature
= signature
;
12117 dwo_unit
->section
=
12118 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12119 *dwo_unit
->section
= sections
.info_or_types
;
12120 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12125 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
12126 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
12127 piece within that section used by a TU/CU, return a virtual section
12128 of just that piece. */
12130 static struct dwarf2_section_info
12131 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12132 struct dwarf2_section_info
*section
,
12133 bfd_size_type offset
, bfd_size_type size
)
12135 struct dwarf2_section_info result
;
12138 gdb_assert (section
!= NULL
);
12139 gdb_assert (!section
->is_virtual
);
12141 memset (&result
, 0, sizeof (result
));
12142 result
.s
.containing_section
= section
;
12143 result
.is_virtual
= true;
12148 sectp
= section
->get_bfd_section ();
12150 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
12151 bounds of the real section. This is a pretty-rare event, so just
12152 flag an error (easier) instead of a warning and trying to cope. */
12154 || offset
+ size
> bfd_section_size (sectp
))
12156 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
12157 " in section %s [in module %s]"),
12158 sectp
? bfd_section_name (sectp
) : "<unknown>",
12159 objfile_name (dwarf2_per_objfile
->objfile
));
12162 result
.virtual_offset
= offset
;
12163 result
.size
= size
;
12167 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12168 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12169 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12170 This is for DWP version 2 files. */
12172 static struct dwo_unit
*
12173 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12174 struct dwp_file
*dwp_file
,
12175 uint32_t unit_index
,
12176 const char *comp_dir
,
12177 ULONGEST signature
, int is_debug_types
)
12179 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12180 const struct dwp_hash_table
*dwp_htab
=
12181 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12182 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12183 const char *kind
= is_debug_types
? "TU" : "CU";
12184 struct dwo_file
*dwo_file
;
12185 struct dwo_unit
*dwo_unit
;
12186 struct virtual_v2_dwo_sections sections
;
12187 void **dwo_file_slot
;
12190 gdb_assert (dwp_file
->version
== 2);
12192 if (dwarf_read_debug
)
12194 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
12196 pulongest (unit_index
), hex_string (signature
),
12200 /* Fetch the section offsets of this DWO unit. */
12202 memset (§ions
, 0, sizeof (sections
));
12204 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12206 uint32_t offset
= read_4_bytes (dbfd
,
12207 dwp_htab
->section_pool
.v2
.offsets
12208 + (((unit_index
- 1) * dwp_htab
->nr_columns
12210 * sizeof (uint32_t)));
12211 uint32_t size
= read_4_bytes (dbfd
,
12212 dwp_htab
->section_pool
.v2
.sizes
12213 + (((unit_index
- 1) * dwp_htab
->nr_columns
12215 * sizeof (uint32_t)));
12217 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
12220 case DW_SECT_TYPES
:
12221 sections
.info_or_types_offset
= offset
;
12222 sections
.info_or_types_size
= size
;
12224 case DW_SECT_ABBREV
:
12225 sections
.abbrev_offset
= offset
;
12226 sections
.abbrev_size
= size
;
12229 sections
.line_offset
= offset
;
12230 sections
.line_size
= size
;
12233 sections
.loc_offset
= offset
;
12234 sections
.loc_size
= size
;
12236 case DW_SECT_STR_OFFSETS
:
12237 sections
.str_offsets_offset
= offset
;
12238 sections
.str_offsets_size
= size
;
12240 case DW_SECT_MACINFO
:
12241 sections
.macinfo_offset
= offset
;
12242 sections
.macinfo_size
= size
;
12244 case DW_SECT_MACRO
:
12245 sections
.macro_offset
= offset
;
12246 sections
.macro_size
= size
;
12251 /* It's easier for the rest of the code if we fake a struct dwo_file and
12252 have dwo_unit "live" in that. At least for now.
12254 The DWP file can be made up of a random collection of CUs and TUs.
12255 However, for each CU + set of TUs that came from the same original DWO
12256 file, we can combine them back into a virtual DWO file to save space
12257 (fewer struct dwo_file objects to allocate). Remember that for really
12258 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12260 std::string virtual_dwo_name
=
12261 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
12262 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12263 (long) (sections
.line_size
? sections
.line_offset
: 0),
12264 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
12265 (long) (sections
.str_offsets_size
12266 ? sections
.str_offsets_offset
: 0));
12267 /* Can we use an existing virtual DWO file? */
12268 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12269 virtual_dwo_name
.c_str (),
12271 /* Create one if necessary. */
12272 if (*dwo_file_slot
== NULL
)
12274 if (dwarf_read_debug
)
12276 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12277 virtual_dwo_name
.c_str ());
12279 dwo_file
= new struct dwo_file
;
12280 dwo_file
->dwo_name
= obstack_strdup (&objfile
->objfile_obstack
,
12282 dwo_file
->comp_dir
= comp_dir
;
12283 dwo_file
->sections
.abbrev
=
12284 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
12285 sections
.abbrev_offset
, sections
.abbrev_size
);
12286 dwo_file
->sections
.line
=
12287 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
12288 sections
.line_offset
, sections
.line_size
);
12289 dwo_file
->sections
.loc
=
12290 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
12291 sections
.loc_offset
, sections
.loc_size
);
12292 dwo_file
->sections
.macinfo
=
12293 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
12294 sections
.macinfo_offset
, sections
.macinfo_size
);
12295 dwo_file
->sections
.macro
=
12296 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
12297 sections
.macro_offset
, sections
.macro_size
);
12298 dwo_file
->sections
.str_offsets
=
12299 create_dwp_v2_section (dwarf2_per_objfile
,
12300 &dwp_file
->sections
.str_offsets
,
12301 sections
.str_offsets_offset
,
12302 sections
.str_offsets_size
);
12303 /* The "str" section is global to the entire DWP file. */
12304 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12305 /* The info or types section is assigned below to dwo_unit,
12306 there's no need to record it in dwo_file.
12307 Also, we can't simply record type sections in dwo_file because
12308 we record a pointer into the vector in dwo_unit. As we collect more
12309 types we'll grow the vector and eventually have to reallocate space
12310 for it, invalidating all copies of pointers into the previous
12312 *dwo_file_slot
= dwo_file
;
12316 if (dwarf_read_debug
)
12318 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12319 virtual_dwo_name
.c_str ());
12321 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12324 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12325 dwo_unit
->dwo_file
= dwo_file
;
12326 dwo_unit
->signature
= signature
;
12327 dwo_unit
->section
=
12328 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12329 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
12331 ? &dwp_file
->sections
.types
12332 : &dwp_file
->sections
.info
,
12333 sections
.info_or_types_offset
,
12334 sections
.info_or_types_size
);
12335 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12340 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12341 Returns NULL if the signature isn't found. */
12343 static struct dwo_unit
*
12344 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12345 struct dwp_file
*dwp_file
, const char *comp_dir
,
12346 ULONGEST signature
, int is_debug_types
)
12348 const struct dwp_hash_table
*dwp_htab
=
12349 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12350 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12351 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12352 uint32_t hash
= signature
& mask
;
12353 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12356 struct dwo_unit find_dwo_cu
;
12358 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12359 find_dwo_cu
.signature
= signature
;
12360 slot
= htab_find_slot (is_debug_types
12361 ? dwp_file
->loaded_tus
.get ()
12362 : dwp_file
->loaded_cus
.get (),
12363 &find_dwo_cu
, INSERT
);
12366 return (struct dwo_unit
*) *slot
;
12368 /* Use a for loop so that we don't loop forever on bad debug info. */
12369 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12371 ULONGEST signature_in_table
;
12373 signature_in_table
=
12374 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12375 if (signature_in_table
== signature
)
12377 uint32_t unit_index
=
12378 read_4_bytes (dbfd
,
12379 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12381 if (dwp_file
->version
== 1)
12383 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
12384 dwp_file
, unit_index
,
12385 comp_dir
, signature
,
12390 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
12391 dwp_file
, unit_index
,
12392 comp_dir
, signature
,
12395 return (struct dwo_unit
*) *slot
;
12397 if (signature_in_table
== 0)
12399 hash
= (hash
+ hash2
) & mask
;
12402 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12403 " [in module %s]"),
12407 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12408 Open the file specified by FILE_NAME and hand it off to BFD for
12409 preliminary analysis. Return a newly initialized bfd *, which
12410 includes a canonicalized copy of FILE_NAME.
12411 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12412 SEARCH_CWD is true if the current directory is to be searched.
12413 It will be searched before debug-file-directory.
12414 If successful, the file is added to the bfd include table of the
12415 objfile's bfd (see gdb_bfd_record_inclusion).
12416 If unable to find/open the file, return NULL.
12417 NOTE: This function is derived from symfile_bfd_open. */
12419 static gdb_bfd_ref_ptr
12420 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12421 const char *file_name
, int is_dwp
, int search_cwd
)
12424 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12425 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12426 to debug_file_directory. */
12427 const char *search_path
;
12428 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12430 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12433 if (*debug_file_directory
!= '\0')
12435 search_path_holder
.reset (concat (".", dirname_separator_string
,
12436 debug_file_directory
,
12438 search_path
= search_path_holder
.get ();
12444 search_path
= debug_file_directory
;
12446 openp_flags flags
= OPF_RETURN_REALPATH
;
12448 flags
|= OPF_SEARCH_IN_PATH
;
12450 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12451 desc
= openp (search_path
, flags
, file_name
,
12452 O_RDONLY
| O_BINARY
, &absolute_name
);
12456 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12458 if (sym_bfd
== NULL
)
12460 bfd_set_cacheable (sym_bfd
.get (), 1);
12462 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12465 /* Success. Record the bfd as having been included by the objfile's bfd.
12466 This is important because things like demangled_names_hash lives in the
12467 objfile's per_bfd space and may have references to things like symbol
12468 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12469 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12474 /* Try to open DWO file FILE_NAME.
12475 COMP_DIR is the DW_AT_comp_dir attribute.
12476 The result is the bfd handle of the file.
12477 If there is a problem finding or opening the file, return NULL.
12478 Upon success, the canonicalized path of the file is stored in the bfd,
12479 same as symfile_bfd_open. */
12481 static gdb_bfd_ref_ptr
12482 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12483 const char *file_name
, const char *comp_dir
)
12485 if (IS_ABSOLUTE_PATH (file_name
))
12486 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12487 0 /*is_dwp*/, 0 /*search_cwd*/);
12489 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12491 if (comp_dir
!= NULL
)
12493 gdb::unique_xmalloc_ptr
<char> path_to_try
12494 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12496 /* NOTE: If comp_dir is a relative path, this will also try the
12497 search path, which seems useful. */
12498 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
12499 path_to_try
.get (),
12501 1 /*search_cwd*/));
12506 /* That didn't work, try debug-file-directory, which, despite its name,
12507 is a list of paths. */
12509 if (*debug_file_directory
== '\0')
12512 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12513 0 /*is_dwp*/, 1 /*search_cwd*/);
12516 /* This function is mapped across the sections and remembers the offset and
12517 size of each of the DWO debugging sections we are interested in. */
12520 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12522 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12523 const struct dwop_section_names
*names
= &dwop_section_names
;
12525 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12527 dwo_sections
->abbrev
.s
.section
= sectp
;
12528 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12530 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12532 dwo_sections
->info
.s
.section
= sectp
;
12533 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12535 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12537 dwo_sections
->line
.s
.section
= sectp
;
12538 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12540 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12542 dwo_sections
->loc
.s
.section
= sectp
;
12543 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12545 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12547 dwo_sections
->macinfo
.s
.section
= sectp
;
12548 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12550 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12552 dwo_sections
->macro
.s
.section
= sectp
;
12553 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12555 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12557 dwo_sections
->str
.s
.section
= sectp
;
12558 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12560 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12562 dwo_sections
->str_offsets
.s
.section
= sectp
;
12563 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12565 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12567 struct dwarf2_section_info type_section
;
12569 memset (&type_section
, 0, sizeof (type_section
));
12570 type_section
.s
.section
= sectp
;
12571 type_section
.size
= bfd_section_size (sectp
);
12572 dwo_sections
->types
.push_back (type_section
);
12576 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12577 by PER_CU. This is for the non-DWP case.
12578 The result is NULL if DWO_NAME can't be found. */
12580 static struct dwo_file
*
12581 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
12582 const char *dwo_name
, const char *comp_dir
)
12584 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
12586 gdb_bfd_ref_ptr dbfd
= open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
);
12589 if (dwarf_read_debug
)
12590 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
12594 dwo_file_up
dwo_file (new struct dwo_file
);
12595 dwo_file
->dwo_name
= dwo_name
;
12596 dwo_file
->comp_dir
= comp_dir
;
12597 dwo_file
->dbfd
= std::move (dbfd
);
12599 bfd_map_over_sections (dwo_file
->dbfd
.get (), dwarf2_locate_dwo_sections
,
12600 &dwo_file
->sections
);
12602 create_cus_hash_table (dwarf2_per_objfile
, per_cu
->cu
, *dwo_file
,
12603 dwo_file
->sections
.info
, dwo_file
->cus
);
12605 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
.get (),
12606 dwo_file
->sections
.types
, dwo_file
->tus
);
12608 if (dwarf_read_debug
)
12609 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
12611 return dwo_file
.release ();
12614 /* This function is mapped across the sections and remembers the offset and
12615 size of each of the DWP debugging sections common to version 1 and 2 that
12616 we are interested in. */
12619 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12620 void *dwp_file_ptr
)
12622 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12623 const struct dwop_section_names
*names
= &dwop_section_names
;
12624 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12626 /* Record the ELF section number for later lookup: this is what the
12627 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12628 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12629 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12631 /* Look for specific sections that we need. */
12632 if (section_is_p (sectp
->name
, &names
->str_dwo
))
12634 dwp_file
->sections
.str
.s
.section
= sectp
;
12635 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12637 else if (section_is_p (sectp
->name
, &names
->cu_index
))
12639 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12640 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12642 else if (section_is_p (sectp
->name
, &names
->tu_index
))
12644 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12645 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12649 /* This function is mapped across the sections and remembers the offset and
12650 size of each of the DWP version 2 debugging sections that we are interested
12651 in. This is split into a separate function because we don't know if we
12652 have version 1 or 2 until we parse the cu_index/tu_index sections. */
12655 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12657 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12658 const struct dwop_section_names
*names
= &dwop_section_names
;
12659 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12661 /* Record the ELF section number for later lookup: this is what the
12662 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12663 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12664 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12666 /* Look for specific sections that we need. */
12667 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12669 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12670 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12672 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12674 dwp_file
->sections
.info
.s
.section
= sectp
;
12675 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12677 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12679 dwp_file
->sections
.line
.s
.section
= sectp
;
12680 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12682 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12684 dwp_file
->sections
.loc
.s
.section
= sectp
;
12685 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12687 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12689 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12690 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12692 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12694 dwp_file
->sections
.macro
.s
.section
= sectp
;
12695 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12697 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12699 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12700 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12702 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12704 dwp_file
->sections
.types
.s
.section
= sectp
;
12705 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12709 /* Hash function for dwp_file loaded CUs/TUs. */
12712 hash_dwp_loaded_cutus (const void *item
)
12714 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12716 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12717 return dwo_unit
->signature
;
12720 /* Equality function for dwp_file loaded CUs/TUs. */
12723 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12725 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12726 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12728 return dua
->signature
== dub
->signature
;
12731 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12734 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
12736 return htab_up (htab_create_alloc (3,
12737 hash_dwp_loaded_cutus
,
12738 eq_dwp_loaded_cutus
,
12739 NULL
, xcalloc
, xfree
));
12742 /* Try to open DWP file FILE_NAME.
12743 The result is the bfd handle of the file.
12744 If there is a problem finding or opening the file, return NULL.
12745 Upon success, the canonicalized path of the file is stored in the bfd,
12746 same as symfile_bfd_open. */
12748 static gdb_bfd_ref_ptr
12749 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12750 const char *file_name
)
12752 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12754 1 /*search_cwd*/));
12758 /* Work around upstream bug 15652.
12759 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12760 [Whether that's a "bug" is debatable, but it is getting in our way.]
12761 We have no real idea where the dwp file is, because gdb's realpath-ing
12762 of the executable's path may have discarded the needed info.
12763 [IWBN if the dwp file name was recorded in the executable, akin to
12764 .gnu_debuglink, but that doesn't exist yet.]
12765 Strip the directory from FILE_NAME and search again. */
12766 if (*debug_file_directory
!= '\0')
12768 /* Don't implicitly search the current directory here.
12769 If the user wants to search "." to handle this case,
12770 it must be added to debug-file-directory. */
12771 return try_open_dwop_file (dwarf2_per_objfile
,
12772 lbasename (file_name
), 1 /*is_dwp*/,
12779 /* Initialize the use of the DWP file for the current objfile.
12780 By convention the name of the DWP file is ${objfile}.dwp.
12781 The result is NULL if it can't be found. */
12783 static std::unique_ptr
<struct dwp_file
>
12784 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12786 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12788 /* Try to find first .dwp for the binary file before any symbolic links
12791 /* If the objfile is a debug file, find the name of the real binary
12792 file and get the name of dwp file from there. */
12793 std::string dwp_name
;
12794 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
12796 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
12797 const char *backlink_basename
= lbasename (backlink
->original_name
);
12799 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
12802 dwp_name
= objfile
->original_name
;
12804 dwp_name
+= ".dwp";
12806 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
12808 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
12810 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
12811 dwp_name
= objfile_name (objfile
);
12812 dwp_name
+= ".dwp";
12813 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
12818 if (dwarf_read_debug
)
12819 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
12820 return std::unique_ptr
<dwp_file
> ();
12823 const char *name
= bfd_get_filename (dbfd
.get ());
12824 std::unique_ptr
<struct dwp_file
> dwp_file
12825 (new struct dwp_file (name
, std::move (dbfd
)));
12827 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
12828 dwp_file
->elf_sections
=
12829 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
12830 dwp_file
->num_sections
, asection
*);
12832 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12833 dwarf2_locate_common_dwp_sections
,
12836 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12839 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12842 /* The DWP file version is stored in the hash table. Oh well. */
12843 if (dwp_file
->cus
&& dwp_file
->tus
12844 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
12846 /* Technically speaking, we should try to limp along, but this is
12847 pretty bizarre. We use pulongest here because that's the established
12848 portability solution (e.g, we cannot use %u for uint32_t). */
12849 error (_("Dwarf Error: DWP file CU version %s doesn't match"
12850 " TU version %s [in DWP file %s]"),
12851 pulongest (dwp_file
->cus
->version
),
12852 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
12856 dwp_file
->version
= dwp_file
->cus
->version
;
12857 else if (dwp_file
->tus
)
12858 dwp_file
->version
= dwp_file
->tus
->version
;
12860 dwp_file
->version
= 2;
12862 if (dwp_file
->version
== 2)
12863 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12864 dwarf2_locate_v2_dwp_sections
,
12867 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table (objfile
);
12868 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table (objfile
);
12870 if (dwarf_read_debug
)
12872 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
12873 fprintf_unfiltered (gdb_stdlog
,
12874 " %s CUs, %s TUs\n",
12875 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
12876 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
12882 /* Wrapper around open_and_init_dwp_file, only open it once. */
12884 static struct dwp_file
*
12885 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12887 if (! dwarf2_per_objfile
->dwp_checked
)
12889 dwarf2_per_objfile
->dwp_file
12890 = open_and_init_dwp_file (dwarf2_per_objfile
);
12891 dwarf2_per_objfile
->dwp_checked
= 1;
12893 return dwarf2_per_objfile
->dwp_file
.get ();
12896 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
12897 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
12898 or in the DWP file for the objfile, referenced by THIS_UNIT.
12899 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
12900 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
12902 This is called, for example, when wanting to read a variable with a
12903 complex location. Therefore we don't want to do file i/o for every call.
12904 Therefore we don't want to look for a DWO file on every call.
12905 Therefore we first see if we've already seen SIGNATURE in a DWP file,
12906 then we check if we've already seen DWO_NAME, and only THEN do we check
12909 The result is a pointer to the dwo_unit object or NULL if we didn't find it
12910 (dwo_id mismatch or couldn't find the DWO/DWP file). */
12912 static struct dwo_unit
*
12913 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
12914 const char *dwo_name
, const char *comp_dir
,
12915 ULONGEST signature
, int is_debug_types
)
12917 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_unit
->dwarf2_per_objfile
;
12918 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12919 const char *kind
= is_debug_types
? "TU" : "CU";
12920 void **dwo_file_slot
;
12921 struct dwo_file
*dwo_file
;
12922 struct dwp_file
*dwp_file
;
12924 /* First see if there's a DWP file.
12925 If we have a DWP file but didn't find the DWO inside it, don't
12926 look for the original DWO file. It makes gdb behave differently
12927 depending on whether one is debugging in the build tree. */
12929 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
12930 if (dwp_file
!= NULL
)
12932 const struct dwp_hash_table
*dwp_htab
=
12933 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12935 if (dwp_htab
!= NULL
)
12937 struct dwo_unit
*dwo_cutu
=
12938 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
12939 signature
, is_debug_types
);
12941 if (dwo_cutu
!= NULL
)
12943 if (dwarf_read_debug
)
12945 fprintf_unfiltered (gdb_stdlog
,
12946 "Virtual DWO %s %s found: @%s\n",
12947 kind
, hex_string (signature
),
12948 host_address_to_string (dwo_cutu
));
12956 /* No DWP file, look for the DWO file. */
12958 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12959 dwo_name
, comp_dir
);
12960 if (*dwo_file_slot
== NULL
)
12962 /* Read in the file and build a table of the CUs/TUs it contains. */
12963 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
12965 /* NOTE: This will be NULL if unable to open the file. */
12966 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12968 if (dwo_file
!= NULL
)
12970 struct dwo_unit
*dwo_cutu
= NULL
;
12972 if (is_debug_types
&& dwo_file
->tus
)
12974 struct dwo_unit find_dwo_cutu
;
12976 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12977 find_dwo_cutu
.signature
= signature
;
12979 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
12982 else if (!is_debug_types
&& dwo_file
->cus
)
12984 struct dwo_unit find_dwo_cutu
;
12986 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12987 find_dwo_cutu
.signature
= signature
;
12988 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
12992 if (dwo_cutu
!= NULL
)
12994 if (dwarf_read_debug
)
12996 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
12997 kind
, dwo_name
, hex_string (signature
),
12998 host_address_to_string (dwo_cutu
));
13005 /* We didn't find it. This could mean a dwo_id mismatch, or
13006 someone deleted the DWO/DWP file, or the search path isn't set up
13007 correctly to find the file. */
13009 if (dwarf_read_debug
)
13011 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
13012 kind
, dwo_name
, hex_string (signature
));
13015 /* This is a warning and not a complaint because it can be caused by
13016 pilot error (e.g., user accidentally deleting the DWO). */
13018 /* Print the name of the DWP file if we looked there, helps the user
13019 better diagnose the problem. */
13020 std::string dwp_text
;
13022 if (dwp_file
!= NULL
)
13023 dwp_text
= string_printf (" [in DWP file %s]",
13024 lbasename (dwp_file
->name
));
13026 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
13027 " [in module %s]"),
13028 kind
, dwo_name
, hex_string (signature
),
13030 this_unit
->is_debug_types
? "TU" : "CU",
13031 sect_offset_str (this_unit
->sect_off
), objfile_name (objfile
));
13036 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
13037 See lookup_dwo_cutu_unit for details. */
13039 static struct dwo_unit
*
13040 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
13041 const char *dwo_name
, const char *comp_dir
,
13042 ULONGEST signature
)
13044 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
13047 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
13048 See lookup_dwo_cutu_unit for details. */
13050 static struct dwo_unit
*
13051 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
13052 const char *dwo_name
, const char *comp_dir
)
13054 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
13057 /* Traversal function for queue_and_load_all_dwo_tus. */
13060 queue_and_load_dwo_tu (void **slot
, void *info
)
13062 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
13063 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
13064 ULONGEST signature
= dwo_unit
->signature
;
13065 struct signatured_type
*sig_type
=
13066 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
13068 if (sig_type
!= NULL
)
13070 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
13072 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
13073 a real dependency of PER_CU on SIG_TYPE. That is detected later
13074 while processing PER_CU. */
13075 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
13076 load_full_type_unit (sig_cu
);
13077 per_cu
->imported_symtabs_push (sig_cu
);
13083 /* Queue all TUs contained in the DWO of PER_CU to be read in.
13084 The DWO may have the only definition of the type, though it may not be
13085 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
13086 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
13089 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
13091 struct dwo_unit
*dwo_unit
;
13092 struct dwo_file
*dwo_file
;
13094 gdb_assert (!per_cu
->is_debug_types
);
13095 gdb_assert (get_dwp_file (per_cu
->dwarf2_per_objfile
) == NULL
);
13096 gdb_assert (per_cu
->cu
!= NULL
);
13098 dwo_unit
= per_cu
->cu
->dwo_unit
;
13099 gdb_assert (dwo_unit
!= NULL
);
13101 dwo_file
= dwo_unit
->dwo_file
;
13102 if (dwo_file
->tus
!= NULL
)
13103 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
,
13107 /* Read in various DIEs. */
13109 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
13110 Inherit only the children of the DW_AT_abstract_origin DIE not being
13111 already referenced by DW_AT_abstract_origin from the children of the
13115 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
13117 struct die_info
*child_die
;
13118 sect_offset
*offsetp
;
13119 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
13120 struct die_info
*origin_die
;
13121 /* Iterator of the ORIGIN_DIE children. */
13122 struct die_info
*origin_child_die
;
13123 struct attribute
*attr
;
13124 struct dwarf2_cu
*origin_cu
;
13125 struct pending
**origin_previous_list_in_scope
;
13127 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13131 /* Note that following die references may follow to a die in a
13135 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
13137 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
13139 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
13140 origin_cu
->list_in_scope
= cu
->list_in_scope
;
13142 if (die
->tag
!= origin_die
->tag
13143 && !(die
->tag
== DW_TAG_inlined_subroutine
13144 && origin_die
->tag
== DW_TAG_subprogram
))
13145 complaint (_("DIE %s and its abstract origin %s have different tags"),
13146 sect_offset_str (die
->sect_off
),
13147 sect_offset_str (origin_die
->sect_off
));
13149 std::vector
<sect_offset
> offsets
;
13151 for (child_die
= die
->child
;
13152 child_die
&& child_die
->tag
;
13153 child_die
= sibling_die (child_die
))
13155 struct die_info
*child_origin_die
;
13156 struct dwarf2_cu
*child_origin_cu
;
13158 /* We are trying to process concrete instance entries:
13159 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
13160 it's not relevant to our analysis here. i.e. detecting DIEs that are
13161 present in the abstract instance but not referenced in the concrete
13163 if (child_die
->tag
== DW_TAG_call_site
13164 || child_die
->tag
== DW_TAG_GNU_call_site
)
13167 /* For each CHILD_DIE, find the corresponding child of
13168 ORIGIN_DIE. If there is more than one layer of
13169 DW_AT_abstract_origin, follow them all; there shouldn't be,
13170 but GCC versions at least through 4.4 generate this (GCC PR
13172 child_origin_die
= child_die
;
13173 child_origin_cu
= cu
;
13176 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
13180 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
13184 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
13185 counterpart may exist. */
13186 if (child_origin_die
!= child_die
)
13188 if (child_die
->tag
!= child_origin_die
->tag
13189 && !(child_die
->tag
== DW_TAG_inlined_subroutine
13190 && child_origin_die
->tag
== DW_TAG_subprogram
))
13191 complaint (_("Child DIE %s and its abstract origin %s have "
13193 sect_offset_str (child_die
->sect_off
),
13194 sect_offset_str (child_origin_die
->sect_off
));
13195 if (child_origin_die
->parent
!= origin_die
)
13196 complaint (_("Child DIE %s and its abstract origin %s have "
13197 "different parents"),
13198 sect_offset_str (child_die
->sect_off
),
13199 sect_offset_str (child_origin_die
->sect_off
));
13201 offsets
.push_back (child_origin_die
->sect_off
);
13204 std::sort (offsets
.begin (), offsets
.end ());
13205 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
13206 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
13207 if (offsetp
[-1] == *offsetp
)
13208 complaint (_("Multiple children of DIE %s refer "
13209 "to DIE %s as their abstract origin"),
13210 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
13212 offsetp
= offsets
.data ();
13213 origin_child_die
= origin_die
->child
;
13214 while (origin_child_die
&& origin_child_die
->tag
)
13216 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13217 while (offsetp
< offsets_end
13218 && *offsetp
< origin_child_die
->sect_off
)
13220 if (offsetp
>= offsets_end
13221 || *offsetp
> origin_child_die
->sect_off
)
13223 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13224 Check whether we're already processing ORIGIN_CHILD_DIE.
13225 This can happen with mutually referenced abstract_origins.
13227 if (!origin_child_die
->in_process
)
13228 process_die (origin_child_die
, origin_cu
);
13230 origin_child_die
= sibling_die (origin_child_die
);
13232 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13234 if (cu
!= origin_cu
)
13235 compute_delayed_physnames (origin_cu
);
13239 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13241 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13242 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13243 struct context_stack
*newobj
;
13246 struct die_info
*child_die
;
13247 struct attribute
*attr
, *call_line
, *call_file
;
13249 CORE_ADDR baseaddr
;
13250 struct block
*block
;
13251 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13252 std::vector
<struct symbol
*> template_args
;
13253 struct template_symbol
*templ_func
= NULL
;
13257 /* If we do not have call site information, we can't show the
13258 caller of this inlined function. That's too confusing, so
13259 only use the scope for local variables. */
13260 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13261 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13262 if (call_line
== NULL
|| call_file
== NULL
)
13264 read_lexical_block_scope (die
, cu
);
13269 baseaddr
= objfile
->text_section_offset ();
13271 name
= dwarf2_name (die
, cu
);
13273 /* Ignore functions with missing or empty names. These are actually
13274 illegal according to the DWARF standard. */
13277 complaint (_("missing name for subprogram DIE at %s"),
13278 sect_offset_str (die
->sect_off
));
13282 /* Ignore functions with missing or invalid low and high pc attributes. */
13283 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13284 <= PC_BOUNDS_INVALID
)
13286 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13287 if (!attr
|| !DW_UNSND (attr
))
13288 complaint (_("cannot get low and high bounds "
13289 "for subprogram DIE at %s"),
13290 sect_offset_str (die
->sect_off
));
13294 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13295 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13297 /* If we have any template arguments, then we must allocate a
13298 different sort of symbol. */
13299 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
13301 if (child_die
->tag
== DW_TAG_template_type_param
13302 || child_die
->tag
== DW_TAG_template_value_param
)
13304 templ_func
= allocate_template_symbol (objfile
);
13305 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13310 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13311 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13312 (struct symbol
*) templ_func
);
13314 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13315 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
13318 /* If there is a location expression for DW_AT_frame_base, record
13320 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13321 if (attr
!= nullptr)
13322 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13324 /* If there is a location for the static link, record it. */
13325 newobj
->static_link
= NULL
;
13326 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13327 if (attr
!= nullptr)
13329 newobj
->static_link
13330 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13331 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13332 dwarf2_per_cu_addr_type (cu
->per_cu
));
13335 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13337 if (die
->child
!= NULL
)
13339 child_die
= die
->child
;
13340 while (child_die
&& child_die
->tag
)
13342 if (child_die
->tag
== DW_TAG_template_type_param
13343 || child_die
->tag
== DW_TAG_template_value_param
)
13345 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13348 template_args
.push_back (arg
);
13351 process_die (child_die
, cu
);
13352 child_die
= sibling_die (child_die
);
13356 inherit_abstract_dies (die
, cu
);
13358 /* If we have a DW_AT_specification, we might need to import using
13359 directives from the context of the specification DIE. See the
13360 comment in determine_prefix. */
13361 if (cu
->language
== language_cplus
13362 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13364 struct dwarf2_cu
*spec_cu
= cu
;
13365 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13369 child_die
= spec_die
->child
;
13370 while (child_die
&& child_die
->tag
)
13372 if (child_die
->tag
== DW_TAG_imported_module
)
13373 process_die (child_die
, spec_cu
);
13374 child_die
= sibling_die (child_die
);
13377 /* In some cases, GCC generates specification DIEs that
13378 themselves contain DW_AT_specification attributes. */
13379 spec_die
= die_specification (spec_die
, &spec_cu
);
13383 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13384 /* Make a block for the local symbols within. */
13385 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13386 cstk
.static_link
, lowpc
, highpc
);
13388 /* For C++, set the block's scope. */
13389 if ((cu
->language
== language_cplus
13390 || cu
->language
== language_fortran
13391 || cu
->language
== language_d
13392 || cu
->language
== language_rust
)
13393 && cu
->processing_has_namespace_info
)
13394 block_set_scope (block
, determine_prefix (die
, cu
),
13395 &objfile
->objfile_obstack
);
13397 /* If we have address ranges, record them. */
13398 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13400 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13402 /* Attach template arguments to function. */
13403 if (!template_args
.empty ())
13405 gdb_assert (templ_func
!= NULL
);
13407 templ_func
->n_template_arguments
= template_args
.size ();
13408 templ_func
->template_arguments
13409 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13410 templ_func
->n_template_arguments
);
13411 memcpy (templ_func
->template_arguments
,
13412 template_args
.data (),
13413 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13415 /* Make sure that the symtab is set on the new symbols. Even
13416 though they don't appear in this symtab directly, other parts
13417 of gdb assume that symbols do, and this is reasonably
13419 for (symbol
*sym
: template_args
)
13420 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13423 /* In C++, we can have functions nested inside functions (e.g., when
13424 a function declares a class that has methods). This means that
13425 when we finish processing a function scope, we may need to go
13426 back to building a containing block's symbol lists. */
13427 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13428 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13430 /* If we've finished processing a top-level function, subsequent
13431 symbols go in the file symbol list. */
13432 if (cu
->get_builder ()->outermost_context_p ())
13433 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13436 /* Process all the DIES contained within a lexical block scope. Start
13437 a new scope, process the dies, and then close the scope. */
13440 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13442 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13443 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13444 CORE_ADDR lowpc
, highpc
;
13445 struct die_info
*child_die
;
13446 CORE_ADDR baseaddr
;
13448 baseaddr
= objfile
->text_section_offset ();
13450 /* Ignore blocks with missing or invalid low and high pc attributes. */
13451 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13452 as multiple lexical blocks? Handling children in a sane way would
13453 be nasty. Might be easier to properly extend generic blocks to
13454 describe ranges. */
13455 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13457 case PC_BOUNDS_NOT_PRESENT
:
13458 /* DW_TAG_lexical_block has no attributes, process its children as if
13459 there was no wrapping by that DW_TAG_lexical_block.
13460 GCC does no longer produces such DWARF since GCC r224161. */
13461 for (child_die
= die
->child
;
13462 child_die
!= NULL
&& child_die
->tag
;
13463 child_die
= sibling_die (child_die
))
13464 process_die (child_die
, cu
);
13466 case PC_BOUNDS_INVALID
:
13469 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13470 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13472 cu
->get_builder ()->push_context (0, lowpc
);
13473 if (die
->child
!= NULL
)
13475 child_die
= die
->child
;
13476 while (child_die
&& child_die
->tag
)
13478 process_die (child_die
, cu
);
13479 child_die
= sibling_die (child_die
);
13482 inherit_abstract_dies (die
, cu
);
13483 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13485 if (*cu
->get_builder ()->get_local_symbols () != NULL
13486 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13488 struct block
*block
13489 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13490 cstk
.start_addr
, highpc
);
13492 /* Note that recording ranges after traversing children, as we
13493 do here, means that recording a parent's ranges entails
13494 walking across all its children's ranges as they appear in
13495 the address map, which is quadratic behavior.
13497 It would be nicer to record the parent's ranges before
13498 traversing its children, simply overriding whatever you find
13499 there. But since we don't even decide whether to create a
13500 block until after we've traversed its children, that's hard
13502 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13504 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13505 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13508 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13511 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13513 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13514 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13515 CORE_ADDR pc
, baseaddr
;
13516 struct attribute
*attr
;
13517 struct call_site
*call_site
, call_site_local
;
13520 struct die_info
*child_die
;
13522 baseaddr
= objfile
->text_section_offset ();
13524 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13527 /* This was a pre-DWARF-5 GNU extension alias
13528 for DW_AT_call_return_pc. */
13529 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13533 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13534 "DIE %s [in module %s]"),
13535 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13538 pc
= attr
->value_as_address () + baseaddr
;
13539 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13541 if (cu
->call_site_htab
== NULL
)
13542 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13543 NULL
, &objfile
->objfile_obstack
,
13544 hashtab_obstack_allocate
, NULL
);
13545 call_site_local
.pc
= pc
;
13546 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13549 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13550 "DIE %s [in module %s]"),
13551 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13552 objfile_name (objfile
));
13556 /* Count parameters at the caller. */
13559 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13560 child_die
= sibling_die (child_die
))
13562 if (child_die
->tag
!= DW_TAG_call_site_parameter
13563 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13565 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13566 "DW_TAG_call_site child DIE %s [in module %s]"),
13567 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13568 objfile_name (objfile
));
13576 = ((struct call_site
*)
13577 obstack_alloc (&objfile
->objfile_obstack
,
13578 sizeof (*call_site
)
13579 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13581 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13582 call_site
->pc
= pc
;
13584 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13585 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13587 struct die_info
*func_die
;
13589 /* Skip also over DW_TAG_inlined_subroutine. */
13590 for (func_die
= die
->parent
;
13591 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13592 && func_die
->tag
!= DW_TAG_subroutine_type
;
13593 func_die
= func_die
->parent
);
13595 /* DW_AT_call_all_calls is a superset
13596 of DW_AT_call_all_tail_calls. */
13598 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13599 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13600 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13601 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13603 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13604 not complete. But keep CALL_SITE for look ups via call_site_htab,
13605 both the initial caller containing the real return address PC and
13606 the final callee containing the current PC of a chain of tail
13607 calls do not need to have the tail call list complete. But any
13608 function candidate for a virtual tail call frame searched via
13609 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13610 determined unambiguously. */
13614 struct type
*func_type
= NULL
;
13617 func_type
= get_die_type (func_die
, cu
);
13618 if (func_type
!= NULL
)
13620 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
13622 /* Enlist this call site to the function. */
13623 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13624 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13627 complaint (_("Cannot find function owning DW_TAG_call_site "
13628 "DIE %s [in module %s]"),
13629 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13633 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13635 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13637 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13640 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13641 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13643 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13644 if (!attr
|| (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0))
13645 /* Keep NULL DWARF_BLOCK. */;
13646 else if (attr
->form_is_block ())
13648 struct dwarf2_locexpr_baton
*dlbaton
;
13650 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13651 dlbaton
->data
= DW_BLOCK (attr
)->data
;
13652 dlbaton
->size
= DW_BLOCK (attr
)->size
;
13653 dlbaton
->per_cu
= cu
->per_cu
;
13655 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13657 else if (attr
->form_is_ref ())
13659 struct dwarf2_cu
*target_cu
= cu
;
13660 struct die_info
*target_die
;
13662 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13663 gdb_assert (target_cu
->per_cu
->dwarf2_per_objfile
->objfile
== objfile
);
13664 if (die_is_declaration (target_die
, target_cu
))
13666 const char *target_physname
;
13668 /* Prefer the mangled name; otherwise compute the demangled one. */
13669 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13670 if (target_physname
== NULL
)
13671 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13672 if (target_physname
== NULL
)
13673 complaint (_("DW_AT_call_target target DIE has invalid "
13674 "physname, for referencing DIE %s [in module %s]"),
13675 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13677 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13683 /* DW_AT_entry_pc should be preferred. */
13684 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13685 <= PC_BOUNDS_INVALID
)
13686 complaint (_("DW_AT_call_target target DIE has invalid "
13687 "low pc, for referencing DIE %s [in module %s]"),
13688 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13691 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13692 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
13697 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13698 "block nor reference, for DIE %s [in module %s]"),
13699 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13701 call_site
->per_cu
= cu
->per_cu
;
13703 for (child_die
= die
->child
;
13704 child_die
&& child_die
->tag
;
13705 child_die
= sibling_die (child_die
))
13707 struct call_site_parameter
*parameter
;
13708 struct attribute
*loc
, *origin
;
13710 if (child_die
->tag
!= DW_TAG_call_site_parameter
13711 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13713 /* Already printed the complaint above. */
13717 gdb_assert (call_site
->parameter_count
< nparams
);
13718 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13720 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13721 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13722 register is contained in DW_AT_call_value. */
13724 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13725 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13726 if (origin
== NULL
)
13728 /* This was a pre-DWARF-5 GNU extension alias
13729 for DW_AT_call_parameter. */
13730 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13732 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
13734 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13736 sect_offset sect_off
13737 = (sect_offset
) dwarf2_get_ref_die_offset (origin
);
13738 if (!offset_in_cu_p (&cu
->header
, sect_off
))
13740 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13741 binding can be done only inside one CU. Such referenced DIE
13742 therefore cannot be even moved to DW_TAG_partial_unit. */
13743 complaint (_("DW_AT_call_parameter offset is not in CU for "
13744 "DW_TAG_call_site child DIE %s [in module %s]"),
13745 sect_offset_str (child_die
->sect_off
),
13746 objfile_name (objfile
));
13749 parameter
->u
.param_cu_off
13750 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13752 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
13754 complaint (_("No DW_FORM_block* DW_AT_location for "
13755 "DW_TAG_call_site child DIE %s [in module %s]"),
13756 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13761 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13762 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
13763 if (parameter
->u
.dwarf_reg
!= -1)
13764 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13765 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
13766 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
13767 ¶meter
->u
.fb_offset
))
13768 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13771 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13772 "for DW_FORM_block* DW_AT_location is supported for "
13773 "DW_TAG_call_site child DIE %s "
13775 sect_offset_str (child_die
->sect_off
),
13776 objfile_name (objfile
));
13781 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13783 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13784 if (attr
== NULL
|| !attr
->form_is_block ())
13786 complaint (_("No DW_FORM_block* DW_AT_call_value for "
13787 "DW_TAG_call_site child DIE %s [in module %s]"),
13788 sect_offset_str (child_die
->sect_off
),
13789 objfile_name (objfile
));
13792 parameter
->value
= DW_BLOCK (attr
)->data
;
13793 parameter
->value_size
= DW_BLOCK (attr
)->size
;
13795 /* Parameters are not pre-cleared by memset above. */
13796 parameter
->data_value
= NULL
;
13797 parameter
->data_value_size
= 0;
13798 call_site
->parameter_count
++;
13800 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
13802 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
13803 if (attr
!= nullptr)
13805 if (!attr
->form_is_block ())
13806 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
13807 "DW_TAG_call_site child DIE %s [in module %s]"),
13808 sect_offset_str (child_die
->sect_off
),
13809 objfile_name (objfile
));
13812 parameter
->data_value
= DW_BLOCK (attr
)->data
;
13813 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
13819 /* Helper function for read_variable. If DIE represents a virtual
13820 table, then return the type of the concrete object that is
13821 associated with the virtual table. Otherwise, return NULL. */
13823 static struct type
*
13824 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13826 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13830 /* Find the type DIE. */
13831 struct die_info
*type_die
= NULL
;
13832 struct dwarf2_cu
*type_cu
= cu
;
13834 if (attr
->form_is_ref ())
13835 type_die
= follow_die_ref (die
, attr
, &type_cu
);
13836 if (type_die
== NULL
)
13839 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
13841 return die_containing_type (type_die
, type_cu
);
13844 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
13847 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
13849 struct rust_vtable_symbol
*storage
= NULL
;
13851 if (cu
->language
== language_rust
)
13853 struct type
*containing_type
= rust_containing_type (die
, cu
);
13855 if (containing_type
!= NULL
)
13857 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13859 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol ();
13860 initialize_objfile_symbol (storage
);
13861 storage
->concrete_type
= containing_type
;
13862 storage
->subclass
= SYMBOL_RUST_VTABLE
;
13866 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
13867 struct attribute
*abstract_origin
13868 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13869 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
13870 if (res
== NULL
&& loc
&& abstract_origin
)
13872 /* We have a variable without a name, but with a location and an abstract
13873 origin. This may be a concrete instance of an abstract variable
13874 referenced from an DW_OP_GNU_variable_value, so save it to find it back
13876 struct dwarf2_cu
*origin_cu
= cu
;
13877 struct die_info
*origin_die
13878 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
13879 dwarf2_per_objfile
*dpo
= cu
->per_cu
->dwarf2_per_objfile
;
13880 dpo
->abstract_to_concrete
[origin_die
->sect_off
].push_back (die
->sect_off
);
13884 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
13885 reading .debug_rnglists.
13886 Callback's type should be:
13887 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13888 Return true if the attributes are present and valid, otherwise,
13891 template <typename Callback
>
13893 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
13894 Callback
&&callback
)
13896 struct dwarf2_per_objfile
*dwarf2_per_objfile
13897 = cu
->per_cu
->dwarf2_per_objfile
;
13898 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13899 bfd
*obfd
= objfile
->obfd
;
13900 /* Base address selection entry. */
13903 const gdb_byte
*buffer
;
13904 CORE_ADDR baseaddr
;
13905 bool overflow
= false;
13907 found_base
= cu
->base_known
;
13908 base
= cu
->base_address
;
13910 dwarf2_per_objfile
->rnglists
.read (objfile
);
13911 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
13913 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13917 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
13919 baseaddr
= objfile
->text_section_offset ();
13923 /* Initialize it due to a false compiler warning. */
13924 CORE_ADDR range_beginning
= 0, range_end
= 0;
13925 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
13926 + dwarf2_per_objfile
->rnglists
.size
);
13927 unsigned int bytes_read
;
13929 if (buffer
== buf_end
)
13934 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
13937 case DW_RLE_end_of_list
:
13939 case DW_RLE_base_address
:
13940 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13945 base
= read_address (obfd
, buffer
, cu
, &bytes_read
);
13947 buffer
+= bytes_read
;
13949 case DW_RLE_start_length
:
13950 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13955 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
13956 buffer
+= bytes_read
;
13957 range_end
= (range_beginning
13958 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13959 buffer
+= bytes_read
;
13960 if (buffer
> buf_end
)
13966 case DW_RLE_offset_pair
:
13967 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13968 buffer
+= bytes_read
;
13969 if (buffer
> buf_end
)
13974 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13975 buffer
+= bytes_read
;
13976 if (buffer
> buf_end
)
13982 case DW_RLE_start_end
:
13983 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
13988 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
13989 buffer
+= bytes_read
;
13990 range_end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
13991 buffer
+= bytes_read
;
13994 complaint (_("Invalid .debug_rnglists data (no base address)"));
13997 if (rlet
== DW_RLE_end_of_list
|| overflow
)
13999 if (rlet
== DW_RLE_base_address
)
14004 /* We have no valid base address for the ranges
14006 complaint (_("Invalid .debug_rnglists data (no base address)"));
14010 if (range_beginning
> range_end
)
14012 /* Inverted range entries are invalid. */
14013 complaint (_("Invalid .debug_rnglists data (inverted range)"));
14017 /* Empty range entries have no effect. */
14018 if (range_beginning
== range_end
)
14021 range_beginning
+= base
;
14024 /* A not-uncommon case of bad debug info.
14025 Don't pollute the addrmap with bad data. */
14026 if (range_beginning
+ baseaddr
== 0
14027 && !dwarf2_per_objfile
->has_section_at_zero
)
14029 complaint (_(".debug_rnglists entry has start address of zero"
14030 " [in module %s]"), objfile_name (objfile
));
14034 callback (range_beginning
, range_end
);
14039 complaint (_("Offset %d is not terminated "
14040 "for DW_AT_ranges attribute"),
14048 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
14049 Callback's type should be:
14050 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14051 Return 1 if the attributes are present and valid, otherwise, return 0. */
14053 template <typename Callback
>
14055 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
14056 Callback
&&callback
)
14058 struct dwarf2_per_objfile
*dwarf2_per_objfile
14059 = cu
->per_cu
->dwarf2_per_objfile
;
14060 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14061 struct comp_unit_head
*cu_header
= &cu
->header
;
14062 bfd
*obfd
= objfile
->obfd
;
14063 unsigned int addr_size
= cu_header
->addr_size
;
14064 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
14065 /* Base address selection entry. */
14068 unsigned int dummy
;
14069 const gdb_byte
*buffer
;
14070 CORE_ADDR baseaddr
;
14072 if (cu_header
->version
>= 5)
14073 return dwarf2_rnglists_process (offset
, cu
, callback
);
14075 found_base
= cu
->base_known
;
14076 base
= cu
->base_address
;
14078 dwarf2_per_objfile
->ranges
.read (objfile
);
14079 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
14081 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14085 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
14087 baseaddr
= objfile
->text_section_offset ();
14091 CORE_ADDR range_beginning
, range_end
;
14093 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
14094 buffer
+= addr_size
;
14095 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
14096 buffer
+= addr_size
;
14097 offset
+= 2 * addr_size
;
14099 /* An end of list marker is a pair of zero addresses. */
14100 if (range_beginning
== 0 && range_end
== 0)
14101 /* Found the end of list entry. */
14104 /* Each base address selection entry is a pair of 2 values.
14105 The first is the largest possible address, the second is
14106 the base address. Check for a base address here. */
14107 if ((range_beginning
& mask
) == mask
)
14109 /* If we found the largest possible address, then we already
14110 have the base address in range_end. */
14118 /* We have no valid base address for the ranges
14120 complaint (_("Invalid .debug_ranges data (no base address)"));
14124 if (range_beginning
> range_end
)
14126 /* Inverted range entries are invalid. */
14127 complaint (_("Invalid .debug_ranges data (inverted range)"));
14131 /* Empty range entries have no effect. */
14132 if (range_beginning
== range_end
)
14135 range_beginning
+= base
;
14138 /* A not-uncommon case of bad debug info.
14139 Don't pollute the addrmap with bad data. */
14140 if (range_beginning
+ baseaddr
== 0
14141 && !dwarf2_per_objfile
->has_section_at_zero
)
14143 complaint (_(".debug_ranges entry has start address of zero"
14144 " [in module %s]"), objfile_name (objfile
));
14148 callback (range_beginning
, range_end
);
14154 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
14155 Return 1 if the attributes are present and valid, otherwise, return 0.
14156 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
14159 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
14160 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
14161 dwarf2_psymtab
*ranges_pst
)
14163 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14164 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14165 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
14168 CORE_ADDR high
= 0;
14171 retval
= dwarf2_ranges_process (offset
, cu
,
14172 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
14174 if (ranges_pst
!= NULL
)
14179 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14180 range_beginning
+ baseaddr
)
14182 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14183 range_end
+ baseaddr
)
14185 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
14186 lowpc
, highpc
- 1, ranges_pst
);
14189 /* FIXME: This is recording everything as a low-high
14190 segment of consecutive addresses. We should have a
14191 data structure for discontiguous block ranges
14195 low
= range_beginning
;
14201 if (range_beginning
< low
)
14202 low
= range_beginning
;
14203 if (range_end
> high
)
14211 /* If the first entry is an end-of-list marker, the range
14212 describes an empty scope, i.e. no instructions. */
14218 *high_return
= high
;
14222 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14223 definition for the return value. *LOWPC and *HIGHPC are set iff
14224 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14226 static enum pc_bounds_kind
14227 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14228 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14229 dwarf2_psymtab
*pst
)
14231 struct dwarf2_per_objfile
*dwarf2_per_objfile
14232 = cu
->per_cu
->dwarf2_per_objfile
;
14233 struct attribute
*attr
;
14234 struct attribute
*attr_high
;
14236 CORE_ADDR high
= 0;
14237 enum pc_bounds_kind ret
;
14239 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14242 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14243 if (attr
!= nullptr)
14245 low
= attr
->value_as_address ();
14246 high
= attr_high
->value_as_address ();
14247 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14251 /* Found high w/o low attribute. */
14252 return PC_BOUNDS_INVALID
;
14254 /* Found consecutive range of addresses. */
14255 ret
= PC_BOUNDS_HIGH_LOW
;
14259 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14262 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14263 We take advantage of the fact that DW_AT_ranges does not appear
14264 in DW_TAG_compile_unit of DWO files. */
14265 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14266 unsigned int ranges_offset
= (DW_UNSND (attr
)
14267 + (need_ranges_base
14271 /* Value of the DW_AT_ranges attribute is the offset in the
14272 .debug_ranges section. */
14273 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
14274 return PC_BOUNDS_INVALID
;
14275 /* Found discontinuous range of addresses. */
14276 ret
= PC_BOUNDS_RANGES
;
14279 return PC_BOUNDS_NOT_PRESENT
;
14282 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14284 return PC_BOUNDS_INVALID
;
14286 /* When using the GNU linker, .gnu.linkonce. sections are used to
14287 eliminate duplicate copies of functions and vtables and such.
14288 The linker will arbitrarily choose one and discard the others.
14289 The AT_*_pc values for such functions refer to local labels in
14290 these sections. If the section from that file was discarded, the
14291 labels are not in the output, so the relocs get a value of 0.
14292 If this is a discarded function, mark the pc bounds as invalid,
14293 so that GDB will ignore it. */
14294 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
14295 return PC_BOUNDS_INVALID
;
14303 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14304 its low and high PC addresses. Do nothing if these addresses could not
14305 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14306 and HIGHPC to the high address if greater than HIGHPC. */
14309 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14310 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14311 struct dwarf2_cu
*cu
)
14313 CORE_ADDR low
, high
;
14314 struct die_info
*child
= die
->child
;
14316 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14318 *lowpc
= std::min (*lowpc
, low
);
14319 *highpc
= std::max (*highpc
, high
);
14322 /* If the language does not allow nested subprograms (either inside
14323 subprograms or lexical blocks), we're done. */
14324 if (cu
->language
!= language_ada
)
14327 /* Check all the children of the given DIE. If it contains nested
14328 subprograms, then check their pc bounds. Likewise, we need to
14329 check lexical blocks as well, as they may also contain subprogram
14331 while (child
&& child
->tag
)
14333 if (child
->tag
== DW_TAG_subprogram
14334 || child
->tag
== DW_TAG_lexical_block
)
14335 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14336 child
= sibling_die (child
);
14340 /* Get the low and high pc's represented by the scope DIE, and store
14341 them in *LOWPC and *HIGHPC. If the correct values can't be
14342 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14345 get_scope_pc_bounds (struct die_info
*die
,
14346 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14347 struct dwarf2_cu
*cu
)
14349 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14350 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14351 CORE_ADDR current_low
, current_high
;
14353 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14354 >= PC_BOUNDS_RANGES
)
14356 best_low
= current_low
;
14357 best_high
= current_high
;
14361 struct die_info
*child
= die
->child
;
14363 while (child
&& child
->tag
)
14365 switch (child
->tag
) {
14366 case DW_TAG_subprogram
:
14367 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14369 case DW_TAG_namespace
:
14370 case DW_TAG_module
:
14371 /* FIXME: carlton/2004-01-16: Should we do this for
14372 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14373 that current GCC's always emit the DIEs corresponding
14374 to definitions of methods of classes as children of a
14375 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14376 the DIEs giving the declarations, which could be
14377 anywhere). But I don't see any reason why the
14378 standards says that they have to be there. */
14379 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14381 if (current_low
!= ((CORE_ADDR
) -1))
14383 best_low
= std::min (best_low
, current_low
);
14384 best_high
= std::max (best_high
, current_high
);
14392 child
= sibling_die (child
);
14397 *highpc
= best_high
;
14400 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14404 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14405 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14407 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14408 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14409 struct attribute
*attr
;
14410 struct attribute
*attr_high
;
14412 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14415 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14416 if (attr
!= nullptr)
14418 CORE_ADDR low
= attr
->value_as_address ();
14419 CORE_ADDR high
= attr_high
->value_as_address ();
14421 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14424 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14425 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14426 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14430 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14431 if (attr
!= nullptr)
14433 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14434 We take advantage of the fact that DW_AT_ranges does not appear
14435 in DW_TAG_compile_unit of DWO files. */
14436 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14438 /* The value of the DW_AT_ranges attribute is the offset of the
14439 address range list in the .debug_ranges section. */
14440 unsigned long offset
= (DW_UNSND (attr
)
14441 + (need_ranges_base
? cu
->ranges_base
: 0));
14443 std::vector
<blockrange
> blockvec
;
14444 dwarf2_ranges_process (offset
, cu
,
14445 [&] (CORE_ADDR start
, CORE_ADDR end
)
14449 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14450 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14451 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14452 blockvec
.emplace_back (start
, end
);
14455 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14459 /* Check whether the producer field indicates either of GCC < 4.6, or the
14460 Intel C/C++ compiler, and cache the result in CU. */
14463 check_producer (struct dwarf2_cu
*cu
)
14467 if (cu
->producer
== NULL
)
14469 /* For unknown compilers expect their behavior is DWARF version
14472 GCC started to support .debug_types sections by -gdwarf-4 since
14473 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14474 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14475 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14476 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14478 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14480 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14481 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14483 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14485 cu
->producer_is_icc
= true;
14486 cu
->producer_is_icc_lt_14
= major
< 14;
14488 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14489 cu
->producer_is_codewarrior
= true;
14492 /* For other non-GCC compilers, expect their behavior is DWARF version
14496 cu
->checked_producer
= true;
14499 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14500 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14501 during 4.6.0 experimental. */
14504 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14506 if (!cu
->checked_producer
)
14507 check_producer (cu
);
14509 return cu
->producer_is_gxx_lt_4_6
;
14513 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14514 with incorrect is_stmt attributes. */
14517 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14519 if (!cu
->checked_producer
)
14520 check_producer (cu
);
14522 return cu
->producer_is_codewarrior
;
14525 /* Return the default accessibility type if it is not overridden by
14526 DW_AT_accessibility. */
14528 static enum dwarf_access_attribute
14529 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14531 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14533 /* The default DWARF 2 accessibility for members is public, the default
14534 accessibility for inheritance is private. */
14536 if (die
->tag
!= DW_TAG_inheritance
)
14537 return DW_ACCESS_public
;
14539 return DW_ACCESS_private
;
14543 /* DWARF 3+ defines the default accessibility a different way. The same
14544 rules apply now for DW_TAG_inheritance as for the members and it only
14545 depends on the container kind. */
14547 if (die
->parent
->tag
== DW_TAG_class_type
)
14548 return DW_ACCESS_private
;
14550 return DW_ACCESS_public
;
14554 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14555 offset. If the attribute was not found return 0, otherwise return
14556 1. If it was found but could not properly be handled, set *OFFSET
14560 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14563 struct attribute
*attr
;
14565 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14570 /* Note that we do not check for a section offset first here.
14571 This is because DW_AT_data_member_location is new in DWARF 4,
14572 so if we see it, we can assume that a constant form is really
14573 a constant and not a section offset. */
14574 if (attr
->form_is_constant ())
14575 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
14576 else if (attr
->form_is_section_offset ())
14577 dwarf2_complex_location_expr_complaint ();
14578 else if (attr
->form_is_block ())
14579 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14581 dwarf2_complex_location_expr_complaint ();
14589 /* Add an aggregate field to the field list. */
14592 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14593 struct dwarf2_cu
*cu
)
14595 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14596 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14597 struct nextfield
*new_field
;
14598 struct attribute
*attr
;
14600 const char *fieldname
= "";
14602 if (die
->tag
== DW_TAG_inheritance
)
14604 fip
->baseclasses
.emplace_back ();
14605 new_field
= &fip
->baseclasses
.back ();
14609 fip
->fields
.emplace_back ();
14610 new_field
= &fip
->fields
.back ();
14615 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14616 if (attr
!= nullptr)
14617 new_field
->accessibility
= DW_UNSND (attr
);
14619 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
14620 if (new_field
->accessibility
!= DW_ACCESS_public
)
14621 fip
->non_public_fields
= 1;
14623 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14624 if (attr
!= nullptr)
14625 new_field
->virtuality
= DW_UNSND (attr
);
14627 new_field
->virtuality
= DW_VIRTUALITY_none
;
14629 fp
= &new_field
->field
;
14631 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14635 /* Data member other than a C++ static data member. */
14637 /* Get type of field. */
14638 fp
->type
= die_type (die
, cu
);
14640 SET_FIELD_BITPOS (*fp
, 0);
14642 /* Get bit size of field (zero if none). */
14643 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14644 if (attr
!= nullptr)
14646 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
14650 FIELD_BITSIZE (*fp
) = 0;
14653 /* Get bit offset of field. */
14654 if (handle_data_member_location (die
, cu
, &offset
))
14655 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
14656 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14657 if (attr
!= nullptr)
14659 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14661 /* For big endian bits, the DW_AT_bit_offset gives the
14662 additional bit offset from the MSB of the containing
14663 anonymous object to the MSB of the field. We don't
14664 have to do anything special since we don't need to
14665 know the size of the anonymous object. */
14666 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
14670 /* For little endian bits, compute the bit offset to the
14671 MSB of the anonymous object, subtract off the number of
14672 bits from the MSB of the field to the MSB of the
14673 object, and then subtract off the number of bits of
14674 the field itself. The result is the bit offset of
14675 the LSB of the field. */
14676 int anonymous_size
;
14677 int bit_offset
= DW_UNSND (attr
);
14679 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14680 if (attr
!= nullptr)
14682 /* The size of the anonymous object containing
14683 the bit field is explicit, so use the
14684 indicated size (in bytes). */
14685 anonymous_size
= DW_UNSND (attr
);
14689 /* The size of the anonymous object containing
14690 the bit field must be inferred from the type
14691 attribute of the data member containing the
14693 anonymous_size
= TYPE_LENGTH (fp
->type
);
14695 SET_FIELD_BITPOS (*fp
,
14696 (FIELD_BITPOS (*fp
)
14697 + anonymous_size
* bits_per_byte
14698 - bit_offset
- FIELD_BITSIZE (*fp
)));
14701 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14703 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14704 + dwarf2_get_attr_constant_value (attr
, 0)));
14706 /* Get name of field. */
14707 fieldname
= dwarf2_name (die
, cu
);
14708 if (fieldname
== NULL
)
14711 /* The name is already allocated along with this objfile, so we don't
14712 need to duplicate it for the type. */
14713 fp
->name
= fieldname
;
14715 /* Change accessibility for artificial fields (e.g. virtual table
14716 pointer or virtual base class pointer) to private. */
14717 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
14719 FIELD_ARTIFICIAL (*fp
) = 1;
14720 new_field
->accessibility
= DW_ACCESS_private
;
14721 fip
->non_public_fields
= 1;
14724 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
14726 /* C++ static member. */
14728 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
14729 is a declaration, but all versions of G++ as of this writing
14730 (so through at least 3.2.1) incorrectly generate
14731 DW_TAG_variable tags. */
14733 const char *physname
;
14735 /* Get name of field. */
14736 fieldname
= dwarf2_name (die
, cu
);
14737 if (fieldname
== NULL
)
14740 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14742 /* Only create a symbol if this is an external value.
14743 new_symbol checks this and puts the value in the global symbol
14744 table, which we want. If it is not external, new_symbol
14745 will try to put the value in cu->list_in_scope which is wrong. */
14746 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
14748 /* A static const member, not much different than an enum as far as
14749 we're concerned, except that we can support more types. */
14750 new_symbol (die
, NULL
, cu
);
14753 /* Get physical name. */
14754 physname
= dwarf2_physname (fieldname
, die
, cu
);
14756 /* The name is already allocated along with this objfile, so we don't
14757 need to duplicate it for the type. */
14758 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
14759 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14760 FIELD_NAME (*fp
) = fieldname
;
14762 else if (die
->tag
== DW_TAG_inheritance
)
14766 /* C++ base class field. */
14767 if (handle_data_member_location (die
, cu
, &offset
))
14768 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
14769 FIELD_BITSIZE (*fp
) = 0;
14770 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14771 FIELD_NAME (*fp
) = TYPE_NAME (fp
->type
);
14773 else if (die
->tag
== DW_TAG_variant_part
)
14775 /* process_structure_scope will treat this DIE as a union. */
14776 process_structure_scope (die
, cu
);
14778 /* The variant part is relative to the start of the enclosing
14780 SET_FIELD_BITPOS (*fp
, 0);
14781 fp
->type
= get_die_type (die
, cu
);
14782 fp
->artificial
= 1;
14783 fp
->name
= "<<variant>>";
14785 /* Normally a DW_TAG_variant_part won't have a size, but our
14786 representation requires one, so set it to the maximum of the
14787 child sizes, being sure to account for the offset at which
14788 each child is seen. */
14789 if (TYPE_LENGTH (fp
->type
) == 0)
14792 for (int i
= 0; i
< TYPE_NFIELDS (fp
->type
); ++i
)
14794 unsigned len
= ((TYPE_FIELD_BITPOS (fp
->type
, i
) + 7) / 8
14795 + TYPE_LENGTH (TYPE_FIELD_TYPE (fp
->type
, i
)));
14799 TYPE_LENGTH (fp
->type
) = max
;
14803 gdb_assert_not_reached ("missing case in dwarf2_add_field");
14806 /* Can the type given by DIE define another type? */
14809 type_can_define_types (const struct die_info
*die
)
14813 case DW_TAG_typedef
:
14814 case DW_TAG_class_type
:
14815 case DW_TAG_structure_type
:
14816 case DW_TAG_union_type
:
14817 case DW_TAG_enumeration_type
:
14825 /* Add a type definition defined in the scope of the FIP's class. */
14828 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
14829 struct dwarf2_cu
*cu
)
14831 struct decl_field fp
;
14832 memset (&fp
, 0, sizeof (fp
));
14834 gdb_assert (type_can_define_types (die
));
14836 /* Get name of field. NULL is okay here, meaning an anonymous type. */
14837 fp
.name
= dwarf2_name (die
, cu
);
14838 fp
.type
= read_type_die (die
, cu
);
14840 /* Save accessibility. */
14841 enum dwarf_access_attribute accessibility
;
14842 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14844 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14846 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14847 switch (accessibility
)
14849 case DW_ACCESS_public
:
14850 /* The assumed value if neither private nor protected. */
14852 case DW_ACCESS_private
:
14855 case DW_ACCESS_protected
:
14856 fp
.is_protected
= 1;
14859 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
14862 if (die
->tag
== DW_TAG_typedef
)
14863 fip
->typedef_field_list
.push_back (fp
);
14865 fip
->nested_types_list
.push_back (fp
);
14868 /* Create the vector of fields, and attach it to the type. */
14871 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
14872 struct dwarf2_cu
*cu
)
14874 int nfields
= fip
->nfields
;
14876 /* Record the field count, allocate space for the array of fields,
14877 and create blank accessibility bitfields if necessary. */
14878 TYPE_NFIELDS (type
) = nfields
;
14879 TYPE_FIELDS (type
) = (struct field
*)
14880 TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
);
14882 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
14884 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14886 TYPE_FIELD_PRIVATE_BITS (type
) =
14887 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14888 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
14890 TYPE_FIELD_PROTECTED_BITS (type
) =
14891 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14892 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
14894 TYPE_FIELD_IGNORE_BITS (type
) =
14895 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14896 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
14899 /* If the type has baseclasses, allocate and clear a bit vector for
14900 TYPE_FIELD_VIRTUAL_BITS. */
14901 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
14903 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
14904 unsigned char *pointer
;
14906 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14907 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
14908 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
14909 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
14910 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
14913 if (TYPE_FLAG_DISCRIMINATED_UNION (type
))
14915 struct discriminant_info
*di
= alloc_discriminant_info (type
, -1, -1);
14917 for (int index
= 0; index
< nfields
; ++index
)
14919 struct nextfield
&field
= fip
->fields
[index
];
14921 if (field
.variant
.is_discriminant
)
14922 di
->discriminant_index
= index
;
14923 else if (field
.variant
.default_branch
)
14924 di
->default_index
= index
;
14926 di
->discriminants
[index
] = field
.variant
.discriminant_value
;
14930 /* Copy the saved-up fields into the field vector. */
14931 for (int i
= 0; i
< nfields
; ++i
)
14933 struct nextfield
&field
14934 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
14935 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
14937 TYPE_FIELD (type
, i
) = field
.field
;
14938 switch (field
.accessibility
)
14940 case DW_ACCESS_private
:
14941 if (cu
->language
!= language_ada
)
14942 SET_TYPE_FIELD_PRIVATE (type
, i
);
14945 case DW_ACCESS_protected
:
14946 if (cu
->language
!= language_ada
)
14947 SET_TYPE_FIELD_PROTECTED (type
, i
);
14950 case DW_ACCESS_public
:
14954 /* Unknown accessibility. Complain and treat it as public. */
14956 complaint (_("unsupported accessibility %d"),
14957 field
.accessibility
);
14961 if (i
< fip
->baseclasses
.size ())
14963 switch (field
.virtuality
)
14965 case DW_VIRTUALITY_virtual
:
14966 case DW_VIRTUALITY_pure_virtual
:
14967 if (cu
->language
== language_ada
)
14968 error (_("unexpected virtuality in component of Ada type"));
14969 SET_TYPE_FIELD_VIRTUAL (type
, i
);
14976 /* Return true if this member function is a constructor, false
14980 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
14982 const char *fieldname
;
14983 const char *type_name
;
14986 if (die
->parent
== NULL
)
14989 if (die
->parent
->tag
!= DW_TAG_structure_type
14990 && die
->parent
->tag
!= DW_TAG_union_type
14991 && die
->parent
->tag
!= DW_TAG_class_type
)
14994 fieldname
= dwarf2_name (die
, cu
);
14995 type_name
= dwarf2_name (die
->parent
, cu
);
14996 if (fieldname
== NULL
|| type_name
== NULL
)
14999 len
= strlen (fieldname
);
15000 return (strncmp (fieldname
, type_name
, len
) == 0
15001 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15004 /* Check if the given VALUE is a recognized enum
15005 dwarf_defaulted_attribute constant according to DWARF5 spec,
15009 is_valid_DW_AT_defaulted (ULONGEST value
)
15013 case DW_DEFAULTED_no
:
15014 case DW_DEFAULTED_in_class
:
15015 case DW_DEFAULTED_out_of_class
:
15019 complaint (_("unrecognized DW_AT_defaulted value (%s)"), pulongest (value
));
15023 /* Add a member function to the proper fieldlist. */
15026 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15027 struct type
*type
, struct dwarf2_cu
*cu
)
15029 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15030 struct attribute
*attr
;
15032 struct fnfieldlist
*flp
= nullptr;
15033 struct fn_field
*fnp
;
15034 const char *fieldname
;
15035 struct type
*this_type
;
15036 enum dwarf_access_attribute accessibility
;
15038 if (cu
->language
== language_ada
)
15039 error (_("unexpected member function in Ada type"));
15041 /* Get name of member function. */
15042 fieldname
= dwarf2_name (die
, cu
);
15043 if (fieldname
== NULL
)
15046 /* Look up member function name in fieldlist. */
15047 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15049 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15051 flp
= &fip
->fnfieldlists
[i
];
15056 /* Create a new fnfieldlist if necessary. */
15057 if (flp
== nullptr)
15059 fip
->fnfieldlists
.emplace_back ();
15060 flp
= &fip
->fnfieldlists
.back ();
15061 flp
->name
= fieldname
;
15062 i
= fip
->fnfieldlists
.size () - 1;
15065 /* Create a new member function field and add it to the vector of
15067 flp
->fnfields
.emplace_back ();
15068 fnp
= &flp
->fnfields
.back ();
15070 /* Delay processing of the physname until later. */
15071 if (cu
->language
== language_cplus
)
15072 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15076 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15077 fnp
->physname
= physname
? physname
: "";
15080 fnp
->type
= alloc_type (objfile
);
15081 this_type
= read_type_die (die
, cu
);
15082 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
15084 int nparams
= TYPE_NFIELDS (this_type
);
15086 /* TYPE is the domain of this method, and THIS_TYPE is the type
15087 of the method itself (TYPE_CODE_METHOD). */
15088 smash_to_method_type (fnp
->type
, type
,
15089 TYPE_TARGET_TYPE (this_type
),
15090 TYPE_FIELDS (this_type
),
15091 TYPE_NFIELDS (this_type
),
15092 TYPE_VARARGS (this_type
));
15094 /* Handle static member functions.
15095 Dwarf2 has no clean way to discern C++ static and non-static
15096 member functions. G++ helps GDB by marking the first
15097 parameter for non-static member functions (which is the this
15098 pointer) as artificial. We obtain this information from
15099 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15100 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15101 fnp
->voffset
= VOFFSET_STATIC
;
15104 complaint (_("member function type missing for '%s'"),
15105 dwarf2_full_name (fieldname
, die
, cu
));
15107 /* Get fcontext from DW_AT_containing_type if present. */
15108 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15109 fnp
->fcontext
= die_containing_type (die
, cu
);
15111 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15112 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15114 /* Get accessibility. */
15115 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15116 if (attr
!= nullptr)
15117 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15119 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15120 switch (accessibility
)
15122 case DW_ACCESS_private
:
15123 fnp
->is_private
= 1;
15125 case DW_ACCESS_protected
:
15126 fnp
->is_protected
= 1;
15130 /* Check for artificial methods. */
15131 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15132 if (attr
&& DW_UNSND (attr
) != 0)
15133 fnp
->is_artificial
= 1;
15135 /* Check for defaulted methods. */
15136 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
15137 if (attr
!= nullptr && is_valid_DW_AT_defaulted (DW_UNSND (attr
)))
15138 fnp
->defaulted
= (enum dwarf_defaulted_attribute
) DW_UNSND (attr
);
15140 /* Check for deleted methods. */
15141 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
15142 if (attr
!= nullptr && DW_UNSND (attr
) != 0)
15143 fnp
->is_deleted
= 1;
15145 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15147 /* Get index in virtual function table if it is a virtual member
15148 function. For older versions of GCC, this is an offset in the
15149 appropriate virtual table, as specified by DW_AT_containing_type.
15150 For everyone else, it is an expression to be evaluated relative
15151 to the object address. */
15153 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15154 if (attr
!= nullptr)
15156 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
> 0)
15158 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
15160 /* Old-style GCC. */
15161 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
15163 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
15164 || (DW_BLOCK (attr
)->size
> 1
15165 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
15166 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
15168 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15169 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15170 dwarf2_complex_location_expr_complaint ();
15172 fnp
->voffset
/= cu
->header
.addr_size
;
15176 dwarf2_complex_location_expr_complaint ();
15178 if (!fnp
->fcontext
)
15180 /* If there is no `this' field and no DW_AT_containing_type,
15181 we cannot actually find a base class context for the
15183 if (TYPE_NFIELDS (this_type
) == 0
15184 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15186 complaint (_("cannot determine context for virtual member "
15187 "function \"%s\" (offset %s)"),
15188 fieldname
, sect_offset_str (die
->sect_off
));
15193 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
15197 else if (attr
->form_is_section_offset ())
15199 dwarf2_complex_location_expr_complaint ();
15203 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15209 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15210 if (attr
&& DW_UNSND (attr
))
15212 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15213 complaint (_("Member function \"%s\" (offset %s) is virtual "
15214 "but the vtable offset is not specified"),
15215 fieldname
, sect_offset_str (die
->sect_off
));
15216 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15217 TYPE_CPLUS_DYNAMIC (type
) = 1;
15222 /* Create the vector of member function fields, and attach it to the type. */
15225 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15226 struct dwarf2_cu
*cu
)
15228 if (cu
->language
== language_ada
)
15229 error (_("unexpected member functions in Ada type"));
15231 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15232 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15234 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15236 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15238 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15239 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15241 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15242 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15243 fn_flp
->fn_fields
= (struct fn_field
*)
15244 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15246 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15247 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15250 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15253 /* Returns non-zero if NAME is the name of a vtable member in CU's
15254 language, zero otherwise. */
15256 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15258 static const char vptr
[] = "_vptr";
15260 /* Look for the C++ form of the vtable. */
15261 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15267 /* GCC outputs unnamed structures that are really pointers to member
15268 functions, with the ABI-specified layout. If TYPE describes
15269 such a structure, smash it into a member function type.
15271 GCC shouldn't do this; it should just output pointer to member DIEs.
15272 This is GCC PR debug/28767. */
15275 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15277 struct type
*pfn_type
, *self_type
, *new_type
;
15279 /* Check for a structure with no name and two children. */
15280 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
15283 /* Check for __pfn and __delta members. */
15284 if (TYPE_FIELD_NAME (type
, 0) == NULL
15285 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15286 || TYPE_FIELD_NAME (type
, 1) == NULL
15287 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15290 /* Find the type of the method. */
15291 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
15292 if (pfn_type
== NULL
15293 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
15294 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
15297 /* Look for the "this" argument. */
15298 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15299 if (TYPE_NFIELDS (pfn_type
) == 0
15300 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
15301 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
15304 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
15305 new_type
= alloc_type (objfile
);
15306 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15307 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
15308 TYPE_VARARGS (pfn_type
));
15309 smash_to_methodptr_type (type
, new_type
);
15312 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15313 appropriate error checking and issuing complaints if there is a
15317 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15319 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15321 if (attr
== nullptr)
15324 if (!attr
->form_is_constant ())
15326 complaint (_("DW_AT_alignment must have constant form"
15327 " - DIE at %s [in module %s]"),
15328 sect_offset_str (die
->sect_off
),
15329 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15334 if (attr
->form
== DW_FORM_sdata
)
15336 LONGEST val
= DW_SND (attr
);
15339 complaint (_("DW_AT_alignment value must not be negative"
15340 " - DIE at %s [in module %s]"),
15341 sect_offset_str (die
->sect_off
),
15342 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15348 align
= DW_UNSND (attr
);
15352 complaint (_("DW_AT_alignment value must not be zero"
15353 " - DIE at %s [in module %s]"),
15354 sect_offset_str (die
->sect_off
),
15355 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15358 if ((align
& (align
- 1)) != 0)
15360 complaint (_("DW_AT_alignment value must be a power of 2"
15361 " - DIE at %s [in module %s]"),
15362 sect_offset_str (die
->sect_off
),
15363 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15370 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15371 the alignment for TYPE. */
15374 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15377 if (!set_type_align (type
, get_alignment (cu
, die
)))
15378 complaint (_("DW_AT_alignment value too large"
15379 " - DIE at %s [in module %s]"),
15380 sect_offset_str (die
->sect_off
),
15381 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15384 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15385 constant for a type, according to DWARF5 spec, Table 5.5. */
15388 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
15393 case DW_CC_pass_by_reference
:
15394 case DW_CC_pass_by_value
:
15398 complaint (_("unrecognized DW_AT_calling_convention value "
15399 "(%s) for a type"), pulongest (value
));
15404 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15405 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
15406 also according to GNU-specific values (see include/dwarf2.h). */
15409 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
15414 case DW_CC_program
:
15418 case DW_CC_GNU_renesas_sh
:
15419 case DW_CC_GNU_borland_fastcall_i386
:
15420 case DW_CC_GDB_IBM_OpenCL
:
15424 complaint (_("unrecognized DW_AT_calling_convention value "
15425 "(%s) for a subroutine"), pulongest (value
));
15430 /* Called when we find the DIE that starts a structure or union scope
15431 (definition) to create a type for the structure or union. Fill in
15432 the type's name and general properties; the members will not be
15433 processed until process_structure_scope. A symbol table entry for
15434 the type will also not be done until process_structure_scope (assuming
15435 the type has a name).
15437 NOTE: we need to call these functions regardless of whether or not the
15438 DIE has a DW_AT_name attribute, since it might be an anonymous
15439 structure or union. This gets the type entered into our set of
15440 user defined types. */
15442 static struct type
*
15443 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15445 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15447 struct attribute
*attr
;
15450 /* If the definition of this type lives in .debug_types, read that type.
15451 Don't follow DW_AT_specification though, that will take us back up
15452 the chain and we want to go down. */
15453 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
15454 if (attr
!= nullptr)
15456 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15458 /* The type's CU may not be the same as CU.
15459 Ensure TYPE is recorded with CU in die_type_hash. */
15460 return set_die_type (die
, type
, cu
);
15463 type
= alloc_type (objfile
);
15464 INIT_CPLUS_SPECIFIC (type
);
15466 name
= dwarf2_name (die
, cu
);
15469 if (cu
->language
== language_cplus
15470 || cu
->language
== language_d
15471 || cu
->language
== language_rust
)
15473 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15475 /* dwarf2_full_name might have already finished building the DIE's
15476 type. If so, there is no need to continue. */
15477 if (get_die_type (die
, cu
) != NULL
)
15478 return get_die_type (die
, cu
);
15480 TYPE_NAME (type
) = full_name
;
15484 /* The name is already allocated along with this objfile, so
15485 we don't need to duplicate it for the type. */
15486 TYPE_NAME (type
) = name
;
15490 if (die
->tag
== DW_TAG_structure_type
)
15492 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15494 else if (die
->tag
== DW_TAG_union_type
)
15496 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15498 else if (die
->tag
== DW_TAG_variant_part
)
15500 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15501 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
15505 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15508 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15509 TYPE_DECLARED_CLASS (type
) = 1;
15511 /* Store the calling convention in the type if it's available in
15512 the die. Otherwise the calling convention remains set to
15513 the default value DW_CC_normal. */
15514 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15515 if (attr
!= nullptr
15516 && is_valid_DW_AT_calling_convention_for_type (DW_UNSND (attr
)))
15518 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15519 TYPE_CPLUS_CALLING_CONVENTION (type
)
15520 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
15523 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15524 if (attr
!= nullptr)
15526 if (attr
->form_is_constant ())
15527 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15530 /* For the moment, dynamic type sizes are not supported
15531 by GDB's struct type. The actual size is determined
15532 on-demand when resolving the type of a given object,
15533 so set the type's length to zero for now. Otherwise,
15534 we record an expression as the length, and that expression
15535 could lead to a very large value, which could eventually
15536 lead to us trying to allocate that much memory when creating
15537 a value of that type. */
15538 TYPE_LENGTH (type
) = 0;
15543 TYPE_LENGTH (type
) = 0;
15546 maybe_set_alignment (cu
, die
, type
);
15548 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15550 /* ICC<14 does not output the required DW_AT_declaration on
15551 incomplete types, but gives them a size of zero. */
15552 TYPE_STUB (type
) = 1;
15555 TYPE_STUB_SUPPORTED (type
) = 1;
15557 if (die_is_declaration (die
, cu
))
15558 TYPE_STUB (type
) = 1;
15559 else if (attr
== NULL
&& die
->child
== NULL
15560 && producer_is_realview (cu
->producer
))
15561 /* RealView does not output the required DW_AT_declaration
15562 on incomplete types. */
15563 TYPE_STUB (type
) = 1;
15565 /* We need to add the type field to the die immediately so we don't
15566 infinitely recurse when dealing with pointers to the structure
15567 type within the structure itself. */
15568 set_die_type (die
, type
, cu
);
15570 /* set_die_type should be already done. */
15571 set_descriptive_type (type
, die
, cu
);
15576 /* A helper for process_structure_scope that handles a single member
15580 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15581 struct field_info
*fi
,
15582 std::vector
<struct symbol
*> *template_args
,
15583 struct dwarf2_cu
*cu
)
15585 if (child_die
->tag
== DW_TAG_member
15586 || child_die
->tag
== DW_TAG_variable
15587 || child_die
->tag
== DW_TAG_variant_part
)
15589 /* NOTE: carlton/2002-11-05: A C++ static data member
15590 should be a DW_TAG_member that is a declaration, but
15591 all versions of G++ as of this writing (so through at
15592 least 3.2.1) incorrectly generate DW_TAG_variable
15593 tags for them instead. */
15594 dwarf2_add_field (fi
, child_die
, cu
);
15596 else if (child_die
->tag
== DW_TAG_subprogram
)
15598 /* Rust doesn't have member functions in the C++ sense.
15599 However, it does emit ordinary functions as children
15600 of a struct DIE. */
15601 if (cu
->language
== language_rust
)
15602 read_func_scope (child_die
, cu
);
15605 /* C++ member function. */
15606 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15609 else if (child_die
->tag
== DW_TAG_inheritance
)
15611 /* C++ base class field. */
15612 dwarf2_add_field (fi
, child_die
, cu
);
15614 else if (type_can_define_types (child_die
))
15615 dwarf2_add_type_defn (fi
, child_die
, cu
);
15616 else if (child_die
->tag
== DW_TAG_template_type_param
15617 || child_die
->tag
== DW_TAG_template_value_param
)
15619 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15622 template_args
->push_back (arg
);
15624 else if (child_die
->tag
== DW_TAG_variant
)
15626 /* In a variant we want to get the discriminant and also add a
15627 field for our sole member child. */
15628 struct attribute
*discr
= dwarf2_attr (child_die
, DW_AT_discr_value
, cu
);
15630 for (die_info
*variant_child
= child_die
->child
;
15631 variant_child
!= NULL
;
15632 variant_child
= sibling_die (variant_child
))
15634 if (variant_child
->tag
== DW_TAG_member
)
15636 handle_struct_member_die (variant_child
, type
, fi
,
15637 template_args
, cu
);
15638 /* Only handle the one. */
15643 /* We don't handle this but we might as well report it if we see
15645 if (dwarf2_attr (child_die
, DW_AT_discr_list
, cu
) != nullptr)
15646 complaint (_("DW_AT_discr_list is not supported yet"
15647 " - DIE at %s [in module %s]"),
15648 sect_offset_str (child_die
->sect_off
),
15649 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15651 /* The first field was just added, so we can stash the
15652 discriminant there. */
15653 gdb_assert (!fi
->fields
.empty ());
15655 fi
->fields
.back ().variant
.default_branch
= true;
15657 fi
->fields
.back ().variant
.discriminant_value
= DW_UNSND (discr
);
15661 /* Finish creating a structure or union type, including filling in
15662 its members and creating a symbol for it. */
15665 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15667 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15668 struct die_info
*child_die
;
15671 type
= get_die_type (die
, cu
);
15673 type
= read_structure_type (die
, cu
);
15675 /* When reading a DW_TAG_variant_part, we need to notice when we
15676 read the discriminant member, so we can record it later in the
15677 discriminant_info. */
15678 bool is_variant_part
= TYPE_FLAG_DISCRIMINATED_UNION (type
);
15679 sect_offset discr_offset
{};
15680 bool has_template_parameters
= false;
15682 if (is_variant_part
)
15684 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15687 /* Maybe it's a univariant form, an extension we support.
15688 In this case arrange not to check the offset. */
15689 is_variant_part
= false;
15691 else if (discr
->form_is_ref ())
15693 struct dwarf2_cu
*target_cu
= cu
;
15694 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15696 discr_offset
= target_die
->sect_off
;
15700 complaint (_("DW_AT_discr does not have DIE reference form"
15701 " - DIE at %s [in module %s]"),
15702 sect_offset_str (die
->sect_off
),
15703 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15704 is_variant_part
= false;
15708 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15710 struct field_info fi
;
15711 std::vector
<struct symbol
*> template_args
;
15713 child_die
= die
->child
;
15715 while (child_die
&& child_die
->tag
)
15717 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15719 if (is_variant_part
&& discr_offset
== child_die
->sect_off
)
15720 fi
.fields
.back ().variant
.is_discriminant
= true;
15722 child_die
= sibling_die (child_die
);
15725 /* Attach template arguments to type. */
15726 if (!template_args
.empty ())
15728 has_template_parameters
= true;
15729 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15730 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15731 TYPE_TEMPLATE_ARGUMENTS (type
)
15732 = XOBNEWVEC (&objfile
->objfile_obstack
,
15734 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15735 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15736 template_args
.data (),
15737 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15738 * sizeof (struct symbol
*)));
15741 /* Attach fields and member functions to the type. */
15743 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15744 if (!fi
.fnfieldlists
.empty ())
15746 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15748 /* Get the type which refers to the base class (possibly this
15749 class itself) which contains the vtable pointer for the current
15750 class from the DW_AT_containing_type attribute. This use of
15751 DW_AT_containing_type is a GNU extension. */
15753 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15755 struct type
*t
= die_containing_type (die
, cu
);
15757 set_type_vptr_basetype (type
, t
);
15762 /* Our own class provides vtbl ptr. */
15763 for (i
= TYPE_NFIELDS (t
) - 1;
15764 i
>= TYPE_N_BASECLASSES (t
);
15767 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
15769 if (is_vtable_name (fieldname
, cu
))
15771 set_type_vptr_fieldno (type
, i
);
15776 /* Complain if virtual function table field not found. */
15777 if (i
< TYPE_N_BASECLASSES (t
))
15778 complaint (_("virtual function table pointer "
15779 "not found when defining class '%s'"),
15780 TYPE_NAME (type
) ? TYPE_NAME (type
) : "");
15784 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
15787 else if (cu
->producer
15788 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
15790 /* The IBM XLC compiler does not provide direct indication
15791 of the containing type, but the vtable pointer is
15792 always named __vfp. */
15796 for (i
= TYPE_NFIELDS (type
) - 1;
15797 i
>= TYPE_N_BASECLASSES (type
);
15800 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
15802 set_type_vptr_fieldno (type
, i
);
15803 set_type_vptr_basetype (type
, type
);
15810 /* Copy fi.typedef_field_list linked list elements content into the
15811 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
15812 if (!fi
.typedef_field_list
.empty ())
15814 int count
= fi
.typedef_field_list
.size ();
15816 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15817 TYPE_TYPEDEF_FIELD_ARRAY (type
)
15818 = ((struct decl_field
*)
15820 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
15821 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
15823 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
15824 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
15827 /* Copy fi.nested_types_list linked list elements content into the
15828 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
15829 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
15831 int count
= fi
.nested_types_list
.size ();
15833 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15834 TYPE_NESTED_TYPES_ARRAY (type
)
15835 = ((struct decl_field
*)
15836 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
15837 TYPE_NESTED_TYPES_COUNT (type
) = count
;
15839 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
15840 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
15844 quirk_gcc_member_function_pointer (type
, objfile
);
15845 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
15846 cu
->rust_unions
.push_back (type
);
15848 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
15849 snapshots) has been known to create a die giving a declaration
15850 for a class that has, as a child, a die giving a definition for a
15851 nested class. So we have to process our children even if the
15852 current die is a declaration. Normally, of course, a declaration
15853 won't have any children at all. */
15855 child_die
= die
->child
;
15857 while (child_die
!= NULL
&& child_die
->tag
)
15859 if (child_die
->tag
== DW_TAG_member
15860 || child_die
->tag
== DW_TAG_variable
15861 || child_die
->tag
== DW_TAG_inheritance
15862 || child_die
->tag
== DW_TAG_template_value_param
15863 || child_die
->tag
== DW_TAG_template_type_param
)
15868 process_die (child_die
, cu
);
15870 child_die
= sibling_die (child_die
);
15873 /* Do not consider external references. According to the DWARF standard,
15874 these DIEs are identified by the fact that they have no byte_size
15875 attribute, and a declaration attribute. */
15876 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
15877 || !die_is_declaration (die
, cu
))
15879 struct symbol
*sym
= new_symbol (die
, type
, cu
);
15881 if (has_template_parameters
)
15883 struct symtab
*symtab
;
15884 if (sym
!= nullptr)
15885 symtab
= symbol_symtab (sym
);
15886 else if (cu
->line_header
!= nullptr)
15888 /* Any related symtab will do. */
15890 = cu
->line_header
->file_names ()[0].symtab
;
15895 complaint (_("could not find suitable "
15896 "symtab for template parameter"
15897 " - DIE at %s [in module %s]"),
15898 sect_offset_str (die
->sect_off
),
15899 objfile_name (objfile
));
15902 if (symtab
!= nullptr)
15904 /* Make sure that the symtab is set on the new symbols.
15905 Even though they don't appear in this symtab directly,
15906 other parts of gdb assume that symbols do, and this is
15907 reasonably true. */
15908 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
15909 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
15915 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
15916 update TYPE using some information only available in DIE's children. */
15919 update_enumeration_type_from_children (struct die_info
*die
,
15921 struct dwarf2_cu
*cu
)
15923 struct die_info
*child_die
;
15924 int unsigned_enum
= 1;
15928 auto_obstack obstack
;
15930 for (child_die
= die
->child
;
15931 child_die
!= NULL
&& child_die
->tag
;
15932 child_die
= sibling_die (child_die
))
15934 struct attribute
*attr
;
15936 const gdb_byte
*bytes
;
15937 struct dwarf2_locexpr_baton
*baton
;
15940 if (child_die
->tag
!= DW_TAG_enumerator
)
15943 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
15947 name
= dwarf2_name (child_die
, cu
);
15949 name
= "<anonymous enumerator>";
15951 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
15952 &value
, &bytes
, &baton
);
15958 else if ((mask
& value
) != 0)
15963 /* If we already know that the enum type is neither unsigned, nor
15964 a flag type, no need to look at the rest of the enumerates. */
15965 if (!unsigned_enum
&& !flag_enum
)
15970 TYPE_UNSIGNED (type
) = 1;
15972 TYPE_FLAG_ENUM (type
) = 1;
15975 /* Given a DW_AT_enumeration_type die, set its type. We do not
15976 complete the type's fields yet, or create any symbols. */
15978 static struct type
*
15979 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15981 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15983 struct attribute
*attr
;
15986 /* If the definition of this type lives in .debug_types, read that type.
15987 Don't follow DW_AT_specification though, that will take us back up
15988 the chain and we want to go down. */
15989 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
15990 if (attr
!= nullptr)
15992 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15994 /* The type's CU may not be the same as CU.
15995 Ensure TYPE is recorded with CU in die_type_hash. */
15996 return set_die_type (die
, type
, cu
);
15999 type
= alloc_type (objfile
);
16001 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
16002 name
= dwarf2_full_name (NULL
, die
, cu
);
16004 TYPE_NAME (type
) = name
;
16006 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16009 struct type
*underlying_type
= die_type (die
, cu
);
16011 TYPE_TARGET_TYPE (type
) = underlying_type
;
16014 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16015 if (attr
!= nullptr)
16017 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16021 TYPE_LENGTH (type
) = 0;
16024 maybe_set_alignment (cu
, die
, type
);
16026 /* The enumeration DIE can be incomplete. In Ada, any type can be
16027 declared as private in the package spec, and then defined only
16028 inside the package body. Such types are known as Taft Amendment
16029 Types. When another package uses such a type, an incomplete DIE
16030 may be generated by the compiler. */
16031 if (die_is_declaration (die
, cu
))
16032 TYPE_STUB (type
) = 1;
16034 /* Finish the creation of this type by using the enum's children.
16035 We must call this even when the underlying type has been provided
16036 so that we can determine if we're looking at a "flag" enum. */
16037 update_enumeration_type_from_children (die
, type
, cu
);
16039 /* If this type has an underlying type that is not a stub, then we
16040 may use its attributes. We always use the "unsigned" attribute
16041 in this situation, because ordinarily we guess whether the type
16042 is unsigned -- but the guess can be wrong and the underlying type
16043 can tell us the reality. However, we defer to a local size
16044 attribute if one exists, because this lets the compiler override
16045 the underlying type if needed. */
16046 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
16048 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
16049 if (TYPE_LENGTH (type
) == 0)
16050 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
16051 if (TYPE_RAW_ALIGN (type
) == 0
16052 && TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)) != 0)
16053 set_type_align (type
, TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)));
16056 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16058 return set_die_type (die
, type
, cu
);
16061 /* Given a pointer to a die which begins an enumeration, process all
16062 the dies that define the members of the enumeration, and create the
16063 symbol for the enumeration type.
16065 NOTE: We reverse the order of the element list. */
16068 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16070 struct type
*this_type
;
16072 this_type
= get_die_type (die
, cu
);
16073 if (this_type
== NULL
)
16074 this_type
= read_enumeration_type (die
, cu
);
16076 if (die
->child
!= NULL
)
16078 struct die_info
*child_die
;
16079 struct symbol
*sym
;
16080 std::vector
<struct field
> fields
;
16083 child_die
= die
->child
;
16084 while (child_die
&& child_die
->tag
)
16086 if (child_die
->tag
!= DW_TAG_enumerator
)
16088 process_die (child_die
, cu
);
16092 name
= dwarf2_name (child_die
, cu
);
16095 sym
= new_symbol (child_die
, this_type
, cu
);
16097 fields
.emplace_back ();
16098 struct field
&field
= fields
.back ();
16100 FIELD_NAME (field
) = sym
->linkage_name ();
16101 FIELD_TYPE (field
) = NULL
;
16102 SET_FIELD_ENUMVAL (field
, SYMBOL_VALUE (sym
));
16103 FIELD_BITSIZE (field
) = 0;
16107 child_die
= sibling_die (child_die
);
16110 if (!fields
.empty ())
16112 TYPE_NFIELDS (this_type
) = fields
.size ();
16113 TYPE_FIELDS (this_type
) = (struct field
*)
16114 TYPE_ALLOC (this_type
, sizeof (struct field
) * fields
.size ());
16115 memcpy (TYPE_FIELDS (this_type
), fields
.data (),
16116 sizeof (struct field
) * fields
.size ());
16120 /* If we are reading an enum from a .debug_types unit, and the enum
16121 is a declaration, and the enum is not the signatured type in the
16122 unit, then we do not want to add a symbol for it. Adding a
16123 symbol would in some cases obscure the true definition of the
16124 enum, giving users an incomplete type when the definition is
16125 actually available. Note that we do not want to do this for all
16126 enums which are just declarations, because C++0x allows forward
16127 enum declarations. */
16128 if (cu
->per_cu
->is_debug_types
16129 && die_is_declaration (die
, cu
))
16131 struct signatured_type
*sig_type
;
16133 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16134 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16135 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16139 new_symbol (die
, this_type
, cu
);
16142 /* Extract all information from a DW_TAG_array_type DIE and put it in
16143 the DIE's type field. For now, this only handles one dimensional
16146 static struct type
*
16147 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16149 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16150 struct die_info
*child_die
;
16152 struct type
*element_type
, *range_type
, *index_type
;
16153 struct attribute
*attr
;
16155 struct dynamic_prop
*byte_stride_prop
= NULL
;
16156 unsigned int bit_stride
= 0;
16158 element_type
= die_type (die
, cu
);
16160 /* The die_type call above may have already set the type for this DIE. */
16161 type
= get_die_type (die
, cu
);
16165 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16169 struct type
*prop_type
16170 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
16173 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16174 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
16178 complaint (_("unable to read array DW_AT_byte_stride "
16179 " - DIE at %s [in module %s]"),
16180 sect_offset_str (die
->sect_off
),
16181 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16182 /* Ignore this attribute. We will likely not be able to print
16183 arrays of this type correctly, but there is little we can do
16184 to help if we cannot read the attribute's value. */
16185 byte_stride_prop
= NULL
;
16189 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16191 bit_stride
= DW_UNSND (attr
);
16193 /* Irix 6.2 native cc creates array types without children for
16194 arrays with unspecified length. */
16195 if (die
->child
== NULL
)
16197 index_type
= objfile_type (objfile
)->builtin_int
;
16198 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16199 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16200 byte_stride_prop
, bit_stride
);
16201 return set_die_type (die
, type
, cu
);
16204 std::vector
<struct type
*> range_types
;
16205 child_die
= die
->child
;
16206 while (child_die
&& child_die
->tag
)
16208 if (child_die
->tag
== DW_TAG_subrange_type
)
16210 struct type
*child_type
= read_type_die (child_die
, cu
);
16212 if (child_type
!= NULL
)
16214 /* The range type was succesfully read. Save it for the
16215 array type creation. */
16216 range_types
.push_back (child_type
);
16219 child_die
= sibling_die (child_die
);
16222 /* Dwarf2 dimensions are output from left to right, create the
16223 necessary array types in backwards order. */
16225 type
= element_type
;
16227 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16231 while (i
< range_types
.size ())
16232 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16233 byte_stride_prop
, bit_stride
);
16237 size_t ndim
= range_types
.size ();
16239 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16240 byte_stride_prop
, bit_stride
);
16243 /* Understand Dwarf2 support for vector types (like they occur on
16244 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16245 array type. This is not part of the Dwarf2/3 standard yet, but a
16246 custom vendor extension. The main difference between a regular
16247 array and the vector variant is that vectors are passed by value
16249 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16250 if (attr
!= nullptr)
16251 make_vector_type (type
);
16253 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16254 implementation may choose to implement triple vectors using this
16256 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16257 if (attr
!= nullptr)
16259 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
16260 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16262 complaint (_("DW_AT_byte_size for array type smaller "
16263 "than the total size of elements"));
16266 name
= dwarf2_name (die
, cu
);
16268 TYPE_NAME (type
) = name
;
16270 maybe_set_alignment (cu
, die
, type
);
16272 /* Install the type in the die. */
16273 set_die_type (die
, type
, cu
);
16275 /* set_die_type should be already done. */
16276 set_descriptive_type (type
, die
, cu
);
16281 static enum dwarf_array_dim_ordering
16282 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16284 struct attribute
*attr
;
16286 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16288 if (attr
!= nullptr)
16289 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
16291 /* GNU F77 is a special case, as at 08/2004 array type info is the
16292 opposite order to the dwarf2 specification, but data is still
16293 laid out as per normal fortran.
16295 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16296 version checking. */
16298 if (cu
->language
== language_fortran
16299 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16301 return DW_ORD_row_major
;
16304 switch (cu
->language_defn
->la_array_ordering
)
16306 case array_column_major
:
16307 return DW_ORD_col_major
;
16308 case array_row_major
:
16310 return DW_ORD_row_major
;
16314 /* Extract all information from a DW_TAG_set_type DIE and put it in
16315 the DIE's type field. */
16317 static struct type
*
16318 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16320 struct type
*domain_type
, *set_type
;
16321 struct attribute
*attr
;
16323 domain_type
= die_type (die
, cu
);
16325 /* The die_type call above may have already set the type for this DIE. */
16326 set_type
= get_die_type (die
, cu
);
16330 set_type
= create_set_type (NULL
, domain_type
);
16332 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16333 if (attr
!= nullptr)
16334 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
16336 maybe_set_alignment (cu
, die
, set_type
);
16338 return set_die_type (die
, set_type
, cu
);
16341 /* A helper for read_common_block that creates a locexpr baton.
16342 SYM is the symbol which we are marking as computed.
16343 COMMON_DIE is the DIE for the common block.
16344 COMMON_LOC is the location expression attribute for the common
16346 MEMBER_LOC is the location expression attribute for the particular
16347 member of the common block that we are processing.
16348 CU is the CU from which the above come. */
16351 mark_common_block_symbol_computed (struct symbol
*sym
,
16352 struct die_info
*common_die
,
16353 struct attribute
*common_loc
,
16354 struct attribute
*member_loc
,
16355 struct dwarf2_cu
*cu
)
16357 struct dwarf2_per_objfile
*dwarf2_per_objfile
16358 = cu
->per_cu
->dwarf2_per_objfile
;
16359 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16360 struct dwarf2_locexpr_baton
*baton
;
16362 unsigned int cu_off
;
16363 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
16364 LONGEST offset
= 0;
16366 gdb_assert (common_loc
&& member_loc
);
16367 gdb_assert (common_loc
->form_is_block ());
16368 gdb_assert (member_loc
->form_is_block ()
16369 || member_loc
->form_is_constant ());
16371 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16372 baton
->per_cu
= cu
->per_cu
;
16373 gdb_assert (baton
->per_cu
);
16375 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16377 if (member_loc
->form_is_constant ())
16379 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
16380 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16383 baton
->size
+= DW_BLOCK (member_loc
)->size
;
16385 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16388 *ptr
++ = DW_OP_call4
;
16389 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16390 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16393 if (member_loc
->form_is_constant ())
16395 *ptr
++ = DW_OP_addr
;
16396 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16397 ptr
+= cu
->header
.addr_size
;
16401 /* We have to copy the data here, because DW_OP_call4 will only
16402 use a DW_AT_location attribute. */
16403 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
16404 ptr
+= DW_BLOCK (member_loc
)->size
;
16407 *ptr
++ = DW_OP_plus
;
16408 gdb_assert (ptr
- baton
->data
== baton
->size
);
16410 SYMBOL_LOCATION_BATON (sym
) = baton
;
16411 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16414 /* Create appropriate locally-scoped variables for all the
16415 DW_TAG_common_block entries. Also create a struct common_block
16416 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16417 is used to separate the common blocks name namespace from regular
16421 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16423 struct attribute
*attr
;
16425 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16426 if (attr
!= nullptr)
16428 /* Support the .debug_loc offsets. */
16429 if (attr
->form_is_block ())
16433 else if (attr
->form_is_section_offset ())
16435 dwarf2_complex_location_expr_complaint ();
16440 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16441 "common block member");
16446 if (die
->child
!= NULL
)
16448 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16449 struct die_info
*child_die
;
16450 size_t n_entries
= 0, size
;
16451 struct common_block
*common_block
;
16452 struct symbol
*sym
;
16454 for (child_die
= die
->child
;
16455 child_die
&& child_die
->tag
;
16456 child_die
= sibling_die (child_die
))
16459 size
= (sizeof (struct common_block
)
16460 + (n_entries
- 1) * sizeof (struct symbol
*));
16462 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16464 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16465 common_block
->n_entries
= 0;
16467 for (child_die
= die
->child
;
16468 child_die
&& child_die
->tag
;
16469 child_die
= sibling_die (child_die
))
16471 /* Create the symbol in the DW_TAG_common_block block in the current
16473 sym
= new_symbol (child_die
, NULL
, cu
);
16476 struct attribute
*member_loc
;
16478 common_block
->contents
[common_block
->n_entries
++] = sym
;
16480 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16484 /* GDB has handled this for a long time, but it is
16485 not specified by DWARF. It seems to have been
16486 emitted by gfortran at least as recently as:
16487 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16488 complaint (_("Variable in common block has "
16489 "DW_AT_data_member_location "
16490 "- DIE at %s [in module %s]"),
16491 sect_offset_str (child_die
->sect_off
),
16492 objfile_name (objfile
));
16494 if (member_loc
->form_is_section_offset ())
16495 dwarf2_complex_location_expr_complaint ();
16496 else if (member_loc
->form_is_constant ()
16497 || member_loc
->form_is_block ())
16499 if (attr
!= nullptr)
16500 mark_common_block_symbol_computed (sym
, die
, attr
,
16504 dwarf2_complex_location_expr_complaint ();
16509 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16510 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16514 /* Create a type for a C++ namespace. */
16516 static struct type
*
16517 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16519 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16520 const char *previous_prefix
, *name
;
16524 /* For extensions, reuse the type of the original namespace. */
16525 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16527 struct die_info
*ext_die
;
16528 struct dwarf2_cu
*ext_cu
= cu
;
16530 ext_die
= dwarf2_extension (die
, &ext_cu
);
16531 type
= read_type_die (ext_die
, ext_cu
);
16533 /* EXT_CU may not be the same as CU.
16534 Ensure TYPE is recorded with CU in die_type_hash. */
16535 return set_die_type (die
, type
, cu
);
16538 name
= namespace_name (die
, &is_anonymous
, cu
);
16540 /* Now build the name of the current namespace. */
16542 previous_prefix
= determine_prefix (die
, cu
);
16543 if (previous_prefix
[0] != '\0')
16544 name
= typename_concat (&objfile
->objfile_obstack
,
16545 previous_prefix
, name
, 0, cu
);
16547 /* Create the type. */
16548 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16550 return set_die_type (die
, type
, cu
);
16553 /* Read a namespace scope. */
16556 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16558 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16561 /* Add a symbol associated to this if we haven't seen the namespace
16562 before. Also, add a using directive if it's an anonymous
16565 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16569 type
= read_type_die (die
, cu
);
16570 new_symbol (die
, type
, cu
);
16572 namespace_name (die
, &is_anonymous
, cu
);
16575 const char *previous_prefix
= determine_prefix (die
, cu
);
16577 std::vector
<const char *> excludes
;
16578 add_using_directive (using_directives (cu
),
16579 previous_prefix
, TYPE_NAME (type
), NULL
,
16580 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16584 if (die
->child
!= NULL
)
16586 struct die_info
*child_die
= die
->child
;
16588 while (child_die
&& child_die
->tag
)
16590 process_die (child_die
, cu
);
16591 child_die
= sibling_die (child_die
);
16596 /* Read a Fortran module as type. This DIE can be only a declaration used for
16597 imported module. Still we need that type as local Fortran "use ... only"
16598 declaration imports depend on the created type in determine_prefix. */
16600 static struct type
*
16601 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16603 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16604 const char *module_name
;
16607 module_name
= dwarf2_name (die
, cu
);
16608 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16610 return set_die_type (die
, type
, cu
);
16613 /* Read a Fortran module. */
16616 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16618 struct die_info
*child_die
= die
->child
;
16621 type
= read_type_die (die
, cu
);
16622 new_symbol (die
, type
, cu
);
16624 while (child_die
&& child_die
->tag
)
16626 process_die (child_die
, cu
);
16627 child_die
= sibling_die (child_die
);
16631 /* Return the name of the namespace represented by DIE. Set
16632 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16635 static const char *
16636 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16638 struct die_info
*current_die
;
16639 const char *name
= NULL
;
16641 /* Loop through the extensions until we find a name. */
16643 for (current_die
= die
;
16644 current_die
!= NULL
;
16645 current_die
= dwarf2_extension (die
, &cu
))
16647 /* We don't use dwarf2_name here so that we can detect the absence
16648 of a name -> anonymous namespace. */
16649 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16655 /* Is it an anonymous namespace? */
16657 *is_anonymous
= (name
== NULL
);
16659 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16664 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16665 the user defined type vector. */
16667 static struct type
*
16668 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16670 struct gdbarch
*gdbarch
16671 = get_objfile_arch (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16672 struct comp_unit_head
*cu_header
= &cu
->header
;
16674 struct attribute
*attr_byte_size
;
16675 struct attribute
*attr_address_class
;
16676 int byte_size
, addr_class
;
16677 struct type
*target_type
;
16679 target_type
= die_type (die
, cu
);
16681 /* The die_type call above may have already set the type for this DIE. */
16682 type
= get_die_type (die
, cu
);
16686 type
= lookup_pointer_type (target_type
);
16688 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16689 if (attr_byte_size
)
16690 byte_size
= DW_UNSND (attr_byte_size
);
16692 byte_size
= cu_header
->addr_size
;
16694 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
16695 if (attr_address_class
)
16696 addr_class
= DW_UNSND (attr_address_class
);
16698 addr_class
= DW_ADDR_none
;
16700 ULONGEST alignment
= get_alignment (cu
, die
);
16702 /* If the pointer size, alignment, or address class is different
16703 than the default, create a type variant marked as such and set
16704 the length accordingly. */
16705 if (TYPE_LENGTH (type
) != byte_size
16706 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
16707 && alignment
!= TYPE_RAW_ALIGN (type
))
16708 || addr_class
!= DW_ADDR_none
)
16710 if (gdbarch_address_class_type_flags_p (gdbarch
))
16714 type_flags
= gdbarch_address_class_type_flags
16715 (gdbarch
, byte_size
, addr_class
);
16716 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
16718 type
= make_type_with_address_space (type
, type_flags
);
16720 else if (TYPE_LENGTH (type
) != byte_size
)
16722 complaint (_("invalid pointer size %d"), byte_size
);
16724 else if (TYPE_RAW_ALIGN (type
) != alignment
)
16726 complaint (_("Invalid DW_AT_alignment"
16727 " - DIE at %s [in module %s]"),
16728 sect_offset_str (die
->sect_off
),
16729 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16733 /* Should we also complain about unhandled address classes? */
16737 TYPE_LENGTH (type
) = byte_size
;
16738 set_type_align (type
, alignment
);
16739 return set_die_type (die
, type
, cu
);
16742 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
16743 the user defined type vector. */
16745 static struct type
*
16746 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16749 struct type
*to_type
;
16750 struct type
*domain
;
16752 to_type
= die_type (die
, cu
);
16753 domain
= die_containing_type (die
, cu
);
16755 /* The calls above may have already set the type for this DIE. */
16756 type
= get_die_type (die
, cu
);
16760 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
16761 type
= lookup_methodptr_type (to_type
);
16762 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
16764 struct type
*new_type
16765 = alloc_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16767 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
16768 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
16769 TYPE_VARARGS (to_type
));
16770 type
= lookup_methodptr_type (new_type
);
16773 type
= lookup_memberptr_type (to_type
, domain
);
16775 return set_die_type (die
, type
, cu
);
16778 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
16779 the user defined type vector. */
16781 static struct type
*
16782 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16783 enum type_code refcode
)
16785 struct comp_unit_head
*cu_header
= &cu
->header
;
16786 struct type
*type
, *target_type
;
16787 struct attribute
*attr
;
16789 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
16791 target_type
= die_type (die
, cu
);
16793 /* The die_type call above may have already set the type for this DIE. */
16794 type
= get_die_type (die
, cu
);
16798 type
= lookup_reference_type (target_type
, refcode
);
16799 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16800 if (attr
!= nullptr)
16802 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16806 TYPE_LENGTH (type
) = cu_header
->addr_size
;
16808 maybe_set_alignment (cu
, die
, type
);
16809 return set_die_type (die
, type
, cu
);
16812 /* Add the given cv-qualifiers to the element type of the array. GCC
16813 outputs DWARF type qualifiers that apply to an array, not the
16814 element type. But GDB relies on the array element type to carry
16815 the cv-qualifiers. This mimics section 6.7.3 of the C99
16818 static struct type
*
16819 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16820 struct type
*base_type
, int cnst
, int voltl
)
16822 struct type
*el_type
, *inner_array
;
16824 base_type
= copy_type (base_type
);
16825 inner_array
= base_type
;
16827 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
16829 TYPE_TARGET_TYPE (inner_array
) =
16830 copy_type (TYPE_TARGET_TYPE (inner_array
));
16831 inner_array
= TYPE_TARGET_TYPE (inner_array
);
16834 el_type
= TYPE_TARGET_TYPE (inner_array
);
16835 cnst
|= TYPE_CONST (el_type
);
16836 voltl
|= TYPE_VOLATILE (el_type
);
16837 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
16839 return set_die_type (die
, base_type
, cu
);
16842 static struct type
*
16843 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16845 struct type
*base_type
, *cv_type
;
16847 base_type
= die_type (die
, cu
);
16849 /* The die_type call above may have already set the type for this DIE. */
16850 cv_type
= get_die_type (die
, cu
);
16854 /* In case the const qualifier is applied to an array type, the element type
16855 is so qualified, not the array type (section 6.7.3 of C99). */
16856 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
16857 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
16859 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
16860 return set_die_type (die
, cv_type
, cu
);
16863 static struct type
*
16864 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16866 struct type
*base_type
, *cv_type
;
16868 base_type
= die_type (die
, cu
);
16870 /* The die_type call above may have already set the type for this DIE. */
16871 cv_type
= get_die_type (die
, cu
);
16875 /* In case the volatile qualifier is applied to an array type, the
16876 element type is so qualified, not the array type (section 6.7.3
16878 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
16879 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
16881 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
16882 return set_die_type (die
, cv_type
, cu
);
16885 /* Handle DW_TAG_restrict_type. */
16887 static struct type
*
16888 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16890 struct type
*base_type
, *cv_type
;
16892 base_type
= die_type (die
, cu
);
16894 /* The die_type call above may have already set the type for this DIE. */
16895 cv_type
= get_die_type (die
, cu
);
16899 cv_type
= make_restrict_type (base_type
);
16900 return set_die_type (die
, cv_type
, cu
);
16903 /* Handle DW_TAG_atomic_type. */
16905 static struct type
*
16906 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16908 struct type
*base_type
, *cv_type
;
16910 base_type
= die_type (die
, cu
);
16912 /* The die_type call above may have already set the type for this DIE. */
16913 cv_type
= get_die_type (die
, cu
);
16917 cv_type
= make_atomic_type (base_type
);
16918 return set_die_type (die
, cv_type
, cu
);
16921 /* Extract all information from a DW_TAG_string_type DIE and add to
16922 the user defined type vector. It isn't really a user defined type,
16923 but it behaves like one, with other DIE's using an AT_user_def_type
16924 attribute to reference it. */
16926 static struct type
*
16927 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16929 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16930 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16931 struct type
*type
, *range_type
, *index_type
, *char_type
;
16932 struct attribute
*attr
;
16933 struct dynamic_prop prop
;
16934 bool length_is_constant
= true;
16937 /* There are a couple of places where bit sizes might be made use of
16938 when parsing a DW_TAG_string_type, however, no producer that we know
16939 of make use of these. Handling bit sizes that are a multiple of the
16940 byte size is easy enough, but what about other bit sizes? Lets deal
16941 with that problem when we have to. Warn about these attributes being
16942 unsupported, then parse the type and ignore them like we always
16944 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
16945 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
16947 static bool warning_printed
= false;
16948 if (!warning_printed
)
16950 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
16951 "currently supported on DW_TAG_string_type."));
16952 warning_printed
= true;
16956 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
16957 if (attr
!= nullptr && !attr
->form_is_constant ())
16959 /* The string length describes the location at which the length of
16960 the string can be found. The size of the length field can be
16961 specified with one of the attributes below. */
16962 struct type
*prop_type
;
16963 struct attribute
*len
16964 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
16965 if (len
== nullptr)
16966 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16967 if (len
!= nullptr && len
->form_is_constant ())
16969 /* Pass 0 as the default as we know this attribute is constant
16970 and the default value will not be returned. */
16971 LONGEST sz
= dwarf2_get_attr_constant_value (len
, 0);
16972 prop_type
= dwarf2_per_cu_int_type (cu
->per_cu
, sz
, true);
16976 /* If the size is not specified then we assume it is the size of
16977 an address on this target. */
16978 prop_type
= dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, true);
16981 /* Convert the attribute into a dynamic property. */
16982 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
16985 length_is_constant
= false;
16987 else if (attr
!= nullptr)
16989 /* This DW_AT_string_length just contains the length with no
16990 indirection. There's no need to create a dynamic property in this
16991 case. Pass 0 for the default value as we know it will not be
16992 returned in this case. */
16993 length
= dwarf2_get_attr_constant_value (attr
, 0);
16995 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
16997 /* We don't currently support non-constant byte sizes for strings. */
16998 length
= dwarf2_get_attr_constant_value (attr
, 1);
17002 /* Use 1 as a fallback length if we have nothing else. */
17006 index_type
= objfile_type (objfile
)->builtin_int
;
17007 if (length_is_constant
)
17008 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17011 struct dynamic_prop low_bound
;
17013 low_bound
.kind
= PROP_CONST
;
17014 low_bound
.data
.const_val
= 1;
17015 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
17017 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17018 type
= create_string_type (NULL
, char_type
, range_type
);
17020 return set_die_type (die
, type
, cu
);
17023 /* Assuming that DIE corresponds to a function, returns nonzero
17024 if the function is prototyped. */
17027 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17029 struct attribute
*attr
;
17031 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17032 if (attr
&& (DW_UNSND (attr
) != 0))
17035 /* The DWARF standard implies that the DW_AT_prototyped attribute
17036 is only meaningful for C, but the concept also extends to other
17037 languages that allow unprototyped functions (Eg: Objective C).
17038 For all other languages, assume that functions are always
17040 if (cu
->language
!= language_c
17041 && cu
->language
!= language_objc
17042 && cu
->language
!= language_opencl
)
17045 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17046 prototyped and unprototyped functions; default to prototyped,
17047 since that is more common in modern code (and RealView warns
17048 about unprototyped functions). */
17049 if (producer_is_realview (cu
->producer
))
17055 /* Handle DIES due to C code like:
17059 int (*funcp)(int a, long l);
17063 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17065 static struct type
*
17066 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17068 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17069 struct type
*type
; /* Type that this function returns. */
17070 struct type
*ftype
; /* Function that returns above type. */
17071 struct attribute
*attr
;
17073 type
= die_type (die
, cu
);
17075 /* The die_type call above may have already set the type for this DIE. */
17076 ftype
= get_die_type (die
, cu
);
17080 ftype
= lookup_function_type (type
);
17082 if (prototyped_function_p (die
, cu
))
17083 TYPE_PROTOTYPED (ftype
) = 1;
17085 /* Store the calling convention in the type if it's available in
17086 the subroutine die. Otherwise set the calling convention to
17087 the default value DW_CC_normal. */
17088 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17089 if (attr
!= nullptr
17090 && is_valid_DW_AT_calling_convention_for_subroutine (DW_UNSND (attr
)))
17091 TYPE_CALLING_CONVENTION (ftype
)
17092 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
17093 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17094 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17096 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17098 /* Record whether the function returns normally to its caller or not
17099 if the DWARF producer set that information. */
17100 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17101 if (attr
&& (DW_UNSND (attr
) != 0))
17102 TYPE_NO_RETURN (ftype
) = 1;
17104 /* We need to add the subroutine type to the die immediately so
17105 we don't infinitely recurse when dealing with parameters
17106 declared as the same subroutine type. */
17107 set_die_type (die
, ftype
, cu
);
17109 if (die
->child
!= NULL
)
17111 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17112 struct die_info
*child_die
;
17113 int nparams
, iparams
;
17115 /* Count the number of parameters.
17116 FIXME: GDB currently ignores vararg functions, but knows about
17117 vararg member functions. */
17119 child_die
= die
->child
;
17120 while (child_die
&& child_die
->tag
)
17122 if (child_die
->tag
== DW_TAG_formal_parameter
)
17124 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17125 TYPE_VARARGS (ftype
) = 1;
17126 child_die
= sibling_die (child_die
);
17129 /* Allocate storage for parameters and fill them in. */
17130 TYPE_NFIELDS (ftype
) = nparams
;
17131 TYPE_FIELDS (ftype
) = (struct field
*)
17132 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
17134 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17135 even if we error out during the parameters reading below. */
17136 for (iparams
= 0; iparams
< nparams
; iparams
++)
17137 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
17140 child_die
= die
->child
;
17141 while (child_die
&& child_die
->tag
)
17143 if (child_die
->tag
== DW_TAG_formal_parameter
)
17145 struct type
*arg_type
;
17147 /* DWARF version 2 has no clean way to discern C++
17148 static and non-static member functions. G++ helps
17149 GDB by marking the first parameter for non-static
17150 member functions (which is the this pointer) as
17151 artificial. We pass this information to
17152 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17154 DWARF version 3 added DW_AT_object_pointer, which GCC
17155 4.5 does not yet generate. */
17156 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17157 if (attr
!= nullptr)
17158 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
17160 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17161 arg_type
= die_type (child_die
, cu
);
17163 /* RealView does not mark THIS as const, which the testsuite
17164 expects. GCC marks THIS as const in method definitions,
17165 but not in the class specifications (GCC PR 43053). */
17166 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17167 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17170 struct dwarf2_cu
*arg_cu
= cu
;
17171 const char *name
= dwarf2_name (child_die
, cu
);
17173 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17174 if (attr
!= nullptr)
17176 /* If the compiler emits this, use it. */
17177 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17180 else if (name
&& strcmp (name
, "this") == 0)
17181 /* Function definitions will have the argument names. */
17183 else if (name
== NULL
&& iparams
== 0)
17184 /* Declarations may not have the names, so like
17185 elsewhere in GDB, assume an artificial first
17186 argument is "this". */
17190 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17194 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
17197 child_die
= sibling_die (child_die
);
17204 static struct type
*
17205 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17207 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17208 const char *name
= NULL
;
17209 struct type
*this_type
, *target_type
;
17211 name
= dwarf2_full_name (NULL
, die
, cu
);
17212 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17213 TYPE_TARGET_STUB (this_type
) = 1;
17214 set_die_type (die
, this_type
, cu
);
17215 target_type
= die_type (die
, cu
);
17216 if (target_type
!= this_type
)
17217 TYPE_TARGET_TYPE (this_type
) = target_type
;
17220 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17221 spec and cause infinite loops in GDB. */
17222 complaint (_("Self-referential DW_TAG_typedef "
17223 "- DIE at %s [in module %s]"),
17224 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17225 TYPE_TARGET_TYPE (this_type
) = NULL
;
17230 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17231 (which may be different from NAME) to the architecture back-end to allow
17232 it to guess the correct format if necessary. */
17234 static struct type
*
17235 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17236 const char *name_hint
, enum bfd_endian byte_order
)
17238 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17239 const struct floatformat
**format
;
17242 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17244 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
17246 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17251 /* Allocate an integer type of size BITS and name NAME. */
17253 static struct type
*
17254 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
17255 int bits
, int unsigned_p
, const char *name
)
17259 /* Versions of Intel's C Compiler generate an integer type called "void"
17260 instead of using DW_TAG_unspecified_type. This has been seen on
17261 at least versions 14, 17, and 18. */
17262 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
17263 && strcmp (name
, "void") == 0)
17264 type
= objfile_type (objfile
)->builtin_void
;
17266 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
17271 /* Initialise and return a floating point type of size BITS suitable for
17272 use as a component of a complex number. The NAME_HINT is passed through
17273 when initialising the floating point type and is the name of the complex
17276 As DWARF doesn't currently provide an explicit name for the components
17277 of a complex number, but it can be helpful to have these components
17278 named, we try to select a suitable name based on the size of the
17280 static struct type
*
17281 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
17282 struct objfile
*objfile
,
17283 int bits
, const char *name_hint
,
17284 enum bfd_endian byte_order
)
17286 gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17287 struct type
*tt
= nullptr;
17289 /* Try to find a suitable floating point builtin type of size BITS.
17290 We're going to use the name of this type as the name for the complex
17291 target type that we are about to create. */
17292 switch (cu
->language
)
17294 case language_fortran
:
17298 tt
= builtin_f_type (gdbarch
)->builtin_real
;
17301 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
17303 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17305 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
17313 tt
= builtin_type (gdbarch
)->builtin_float
;
17316 tt
= builtin_type (gdbarch
)->builtin_double
;
17318 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17320 tt
= builtin_type (gdbarch
)->builtin_long_double
;
17326 /* If the type we found doesn't match the size we were looking for, then
17327 pretend we didn't find a type at all, the complex target type we
17328 create will then be nameless. */
17329 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
17332 const char *name
= (tt
== nullptr) ? nullptr : TYPE_NAME (tt
);
17333 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
17336 /* Find a representation of a given base type and install
17337 it in the TYPE field of the die. */
17339 static struct type
*
17340 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17342 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17344 struct attribute
*attr
;
17345 int encoding
= 0, bits
= 0;
17349 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17350 if (attr
!= nullptr)
17351 encoding
= DW_UNSND (attr
);
17352 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17353 if (attr
!= nullptr)
17354 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
17355 name
= dwarf2_name (die
, cu
);
17357 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
17359 arch
= get_objfile_arch (objfile
);
17360 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
17362 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
17365 int endianity
= DW_UNSND (attr
);
17370 byte_order
= BFD_ENDIAN_BIG
;
17372 case DW_END_little
:
17373 byte_order
= BFD_ENDIAN_LITTLE
;
17376 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
17383 case DW_ATE_address
:
17384 /* Turn DW_ATE_address into a void * pointer. */
17385 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
17386 type
= init_pointer_type (objfile
, bits
, name
, type
);
17388 case DW_ATE_boolean
:
17389 type
= init_boolean_type (objfile
, bits
, 1, name
);
17391 case DW_ATE_complex_float
:
17392 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
17394 type
= init_complex_type (objfile
, name
, type
);
17396 case DW_ATE_decimal_float
:
17397 type
= init_decfloat_type (objfile
, bits
, name
);
17400 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
17402 case DW_ATE_signed
:
17403 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17405 case DW_ATE_unsigned
:
17406 if (cu
->language
== language_fortran
17408 && startswith (name
, "character("))
17409 type
= init_character_type (objfile
, bits
, 1, name
);
17411 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17413 case DW_ATE_signed_char
:
17414 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17415 || cu
->language
== language_pascal
17416 || cu
->language
== language_fortran
)
17417 type
= init_character_type (objfile
, bits
, 0, name
);
17419 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17421 case DW_ATE_unsigned_char
:
17422 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17423 || cu
->language
== language_pascal
17424 || cu
->language
== language_fortran
17425 || cu
->language
== language_rust
)
17426 type
= init_character_type (objfile
, bits
, 1, name
);
17428 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17433 type
= builtin_type (arch
)->builtin_char16
;
17434 else if (bits
== 32)
17435 type
= builtin_type (arch
)->builtin_char32
;
17438 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
17440 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17442 return set_die_type (die
, type
, cu
);
17447 complaint (_("unsupported DW_AT_encoding: '%s'"),
17448 dwarf_type_encoding_name (encoding
));
17449 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17453 if (name
&& strcmp (name
, "char") == 0)
17454 TYPE_NOSIGN (type
) = 1;
17456 maybe_set_alignment (cu
, die
, type
);
17458 TYPE_ENDIANITY_NOT_DEFAULT (type
) = gdbarch_byte_order (arch
) != byte_order
;
17460 return set_die_type (die
, type
, cu
);
17463 /* Parse dwarf attribute if it's a block, reference or constant and put the
17464 resulting value of the attribute into struct bound_prop.
17465 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17468 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17469 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
17470 struct type
*default_type
)
17472 struct dwarf2_property_baton
*baton
;
17473 struct obstack
*obstack
17474 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
17476 gdb_assert (default_type
!= NULL
);
17478 if (attr
== NULL
|| prop
== NULL
)
17481 if (attr
->form_is_block ())
17483 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17484 baton
->property_type
= default_type
;
17485 baton
->locexpr
.per_cu
= cu
->per_cu
;
17486 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17487 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17488 switch (attr
->name
)
17490 case DW_AT_string_length
:
17491 baton
->locexpr
.is_reference
= true;
17494 baton
->locexpr
.is_reference
= false;
17497 prop
->data
.baton
= baton
;
17498 prop
->kind
= PROP_LOCEXPR
;
17499 gdb_assert (prop
->data
.baton
!= NULL
);
17501 else if (attr
->form_is_ref ())
17503 struct dwarf2_cu
*target_cu
= cu
;
17504 struct die_info
*target_die
;
17505 struct attribute
*target_attr
;
17507 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17508 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17509 if (target_attr
== NULL
)
17510 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17512 if (target_attr
== NULL
)
17515 switch (target_attr
->name
)
17517 case DW_AT_location
:
17518 if (target_attr
->form_is_section_offset ())
17520 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17521 baton
->property_type
= die_type (target_die
, target_cu
);
17522 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17523 prop
->data
.baton
= baton
;
17524 prop
->kind
= PROP_LOCLIST
;
17525 gdb_assert (prop
->data
.baton
!= NULL
);
17527 else if (target_attr
->form_is_block ())
17529 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17530 baton
->property_type
= die_type (target_die
, target_cu
);
17531 baton
->locexpr
.per_cu
= cu
->per_cu
;
17532 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17533 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17534 baton
->locexpr
.is_reference
= true;
17535 prop
->data
.baton
= baton
;
17536 prop
->kind
= PROP_LOCEXPR
;
17537 gdb_assert (prop
->data
.baton
!= NULL
);
17541 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17542 "dynamic property");
17546 case DW_AT_data_member_location
:
17550 if (!handle_data_member_location (target_die
, target_cu
,
17554 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17555 baton
->property_type
= read_type_die (target_die
->parent
,
17557 baton
->offset_info
.offset
= offset
;
17558 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17559 prop
->data
.baton
= baton
;
17560 prop
->kind
= PROP_ADDR_OFFSET
;
17565 else if (attr
->form_is_constant ())
17567 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
17568 prop
->kind
= PROP_CONST
;
17572 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17573 dwarf2_name (die
, cu
));
17580 /* Find an integer type SIZE_IN_BYTES bytes in size and return it.
17581 UNSIGNED_P controls if the integer is unsigned or not. */
17583 static struct type
*
17584 dwarf2_per_cu_int_type (struct dwarf2_per_cu_data
*per_cu
,
17585 int size_in_bytes
, bool unsigned_p
)
17587 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
17588 struct type
*int_type
;
17590 /* Helper macro to examine the various builtin types. */
17591 #define TRY_TYPE(F) \
17592 int_type = (unsigned_p \
17593 ? objfile_type (objfile)->builtin_unsigned_ ## F \
17594 : objfile_type (objfile)->builtin_ ## F); \
17595 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
17602 TRY_TYPE (long_long
);
17606 gdb_assert_not_reached ("unable to find suitable integer type");
17609 /* Find an integer type the same size as the address size given in the
17610 compilation unit header for PER_CU. UNSIGNED_P controls if the integer
17611 is unsigned or not. */
17613 static struct type
*
17614 dwarf2_per_cu_addr_sized_int_type (struct dwarf2_per_cu_data
*per_cu
,
17617 int addr_size
= dwarf2_per_cu_addr_size (per_cu
);
17618 return dwarf2_per_cu_int_type (per_cu
, addr_size
, unsigned_p
);
17621 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
17622 present (which is valid) then compute the default type based on the
17623 compilation units address size. */
17625 static struct type
*
17626 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17628 struct type
*index_type
= die_type (die
, cu
);
17630 /* Dwarf-2 specifications explicitly allows to create subrange types
17631 without specifying a base type.
17632 In that case, the base type must be set to the type of
17633 the lower bound, upper bound or count, in that order, if any of these
17634 three attributes references an object that has a type.
17635 If no base type is found, the Dwarf-2 specifications say that
17636 a signed integer type of size equal to the size of an address should
17638 For the following C code: `extern char gdb_int [];'
17639 GCC produces an empty range DIE.
17640 FIXME: muller/2010-05-28: Possible references to object for low bound,
17641 high bound or count are not yet handled by this code. */
17642 if (TYPE_CODE (index_type
) == TYPE_CODE_VOID
)
17643 index_type
= dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
17648 /* Read the given DW_AT_subrange DIE. */
17650 static struct type
*
17651 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17653 struct type
*base_type
, *orig_base_type
;
17654 struct type
*range_type
;
17655 struct attribute
*attr
;
17656 struct dynamic_prop low
, high
;
17657 int low_default_is_valid
;
17658 int high_bound_is_count
= 0;
17660 ULONGEST negative_mask
;
17662 orig_base_type
= read_subrange_index_type (die
, cu
);
17664 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17665 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17666 creating the range type, but we use the result of check_typedef
17667 when examining properties of the type. */
17668 base_type
= check_typedef (orig_base_type
);
17670 /* The die_type call above may have already set the type for this DIE. */
17671 range_type
= get_die_type (die
, cu
);
17675 low
.kind
= PROP_CONST
;
17676 high
.kind
= PROP_CONST
;
17677 high
.data
.const_val
= 0;
17679 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17680 omitting DW_AT_lower_bound. */
17681 switch (cu
->language
)
17684 case language_cplus
:
17685 low
.data
.const_val
= 0;
17686 low_default_is_valid
= 1;
17688 case language_fortran
:
17689 low
.data
.const_val
= 1;
17690 low_default_is_valid
= 1;
17693 case language_objc
:
17694 case language_rust
:
17695 low
.data
.const_val
= 0;
17696 low_default_is_valid
= (cu
->header
.version
>= 4);
17700 case language_pascal
:
17701 low
.data
.const_val
= 1;
17702 low_default_is_valid
= (cu
->header
.version
>= 4);
17705 low
.data
.const_val
= 0;
17706 low_default_is_valid
= 0;
17710 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
17711 if (attr
!= nullptr)
17712 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
17713 else if (!low_default_is_valid
)
17714 complaint (_("Missing DW_AT_lower_bound "
17715 "- DIE at %s [in module %s]"),
17716 sect_offset_str (die
->sect_off
),
17717 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17719 struct attribute
*attr_ub
, *attr_count
;
17720 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
17721 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17723 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
17724 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17726 /* If bounds are constant do the final calculation here. */
17727 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
17728 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
17730 high_bound_is_count
= 1;
17734 if (attr_ub
!= NULL
)
17735 complaint (_("Unresolved DW_AT_upper_bound "
17736 "- DIE at %s [in module %s]"),
17737 sect_offset_str (die
->sect_off
),
17738 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17739 if (attr_count
!= NULL
)
17740 complaint (_("Unresolved DW_AT_count "
17741 "- DIE at %s [in module %s]"),
17742 sect_offset_str (die
->sect_off
),
17743 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17748 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
17749 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
17750 bias
= dwarf2_get_attr_constant_value (bias_attr
, 0);
17752 /* Normally, the DWARF producers are expected to use a signed
17753 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17754 But this is unfortunately not always the case, as witnessed
17755 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17756 is used instead. To work around that ambiguity, we treat
17757 the bounds as signed, and thus sign-extend their values, when
17758 the base type is signed. */
17760 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
17761 if (low
.kind
== PROP_CONST
17762 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
17763 low
.data
.const_val
|= negative_mask
;
17764 if (high
.kind
== PROP_CONST
17765 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
17766 high
.data
.const_val
|= negative_mask
;
17768 /* Check for bit and byte strides. */
17769 struct dynamic_prop byte_stride_prop
;
17770 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
17771 if (attr_byte_stride
!= nullptr)
17773 struct type
*prop_type
17774 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
17775 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
17779 struct dynamic_prop bit_stride_prop
;
17780 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
17781 if (attr_bit_stride
!= nullptr)
17783 /* It only makes sense to have either a bit or byte stride. */
17784 if (attr_byte_stride
!= nullptr)
17786 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
17787 "- DIE at %s [in module %s]"),
17788 sect_offset_str (die
->sect_off
),
17789 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17790 attr_bit_stride
= nullptr;
17794 struct type
*prop_type
17795 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
17796 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
17801 if (attr_byte_stride
!= nullptr
17802 || attr_bit_stride
!= nullptr)
17804 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
17805 struct dynamic_prop
*stride
17806 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
17809 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
17810 &high
, bias
, stride
, byte_stride_p
);
17813 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
17815 if (high_bound_is_count
)
17816 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
17818 /* Ada expects an empty array on no boundary attributes. */
17819 if (attr
== NULL
&& cu
->language
!= language_ada
)
17820 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
17822 name
= dwarf2_name (die
, cu
);
17824 TYPE_NAME (range_type
) = name
;
17826 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17827 if (attr
!= nullptr)
17828 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
17830 maybe_set_alignment (cu
, die
, range_type
);
17832 set_die_type (die
, range_type
, cu
);
17834 /* set_die_type should be already done. */
17835 set_descriptive_type (range_type
, die
, cu
);
17840 static struct type
*
17841 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17845 type
= init_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
, TYPE_CODE_VOID
,0,
17847 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
17849 /* In Ada, an unspecified type is typically used when the description
17850 of the type is deferred to a different unit. When encountering
17851 such a type, we treat it as a stub, and try to resolve it later on,
17853 if (cu
->language
== language_ada
)
17854 TYPE_STUB (type
) = 1;
17856 return set_die_type (die
, type
, cu
);
17859 /* Read a single die and all its descendents. Set the die's sibling
17860 field to NULL; set other fields in the die correctly, and set all
17861 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
17862 location of the info_ptr after reading all of those dies. PARENT
17863 is the parent of the die in question. */
17865 static struct die_info
*
17866 read_die_and_children (const struct die_reader_specs
*reader
,
17867 const gdb_byte
*info_ptr
,
17868 const gdb_byte
**new_info_ptr
,
17869 struct die_info
*parent
)
17871 struct die_info
*die
;
17872 const gdb_byte
*cur_ptr
;
17874 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
17877 *new_info_ptr
= cur_ptr
;
17880 store_in_ref_table (die
, reader
->cu
);
17882 if (die
->has_children
)
17883 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
17887 *new_info_ptr
= cur_ptr
;
17890 die
->sibling
= NULL
;
17891 die
->parent
= parent
;
17895 /* Read a die, all of its descendents, and all of its siblings; set
17896 all of the fields of all of the dies correctly. Arguments are as
17897 in read_die_and_children. */
17899 static struct die_info
*
17900 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
17901 const gdb_byte
*info_ptr
,
17902 const gdb_byte
**new_info_ptr
,
17903 struct die_info
*parent
)
17905 struct die_info
*first_die
, *last_sibling
;
17906 const gdb_byte
*cur_ptr
;
17908 cur_ptr
= info_ptr
;
17909 first_die
= last_sibling
= NULL
;
17913 struct die_info
*die
17914 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
17918 *new_info_ptr
= cur_ptr
;
17925 last_sibling
->sibling
= die
;
17927 last_sibling
= die
;
17931 /* Read a die, all of its descendents, and all of its siblings; set
17932 all of the fields of all of the dies correctly. Arguments are as
17933 in read_die_and_children.
17934 This the main entry point for reading a DIE and all its children. */
17936 static struct die_info
*
17937 read_die_and_siblings (const struct die_reader_specs
*reader
,
17938 const gdb_byte
*info_ptr
,
17939 const gdb_byte
**new_info_ptr
,
17940 struct die_info
*parent
)
17942 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
17943 new_info_ptr
, parent
);
17945 if (dwarf_die_debug
)
17947 fprintf_unfiltered (gdb_stdlog
,
17948 "Read die from %s@0x%x of %s:\n",
17949 reader
->die_section
->get_name (),
17950 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17951 bfd_get_filename (reader
->abfd
));
17952 dump_die (die
, dwarf_die_debug
);
17958 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
17960 The caller is responsible for filling in the extra attributes
17961 and updating (*DIEP)->num_attrs.
17962 Set DIEP to point to a newly allocated die with its information,
17963 except for its child, sibling, and parent fields. */
17965 static const gdb_byte
*
17966 read_full_die_1 (const struct die_reader_specs
*reader
,
17967 struct die_info
**diep
, const gdb_byte
*info_ptr
,
17968 int num_extra_attrs
)
17970 unsigned int abbrev_number
, bytes_read
, i
;
17971 struct abbrev_info
*abbrev
;
17972 struct die_info
*die
;
17973 struct dwarf2_cu
*cu
= reader
->cu
;
17974 bfd
*abfd
= reader
->abfd
;
17976 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
17977 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
17978 info_ptr
+= bytes_read
;
17979 if (!abbrev_number
)
17985 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
17987 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
17989 bfd_get_filename (abfd
));
17991 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
17992 die
->sect_off
= sect_off
;
17993 die
->tag
= abbrev
->tag
;
17994 die
->abbrev
= abbrev_number
;
17995 die
->has_children
= abbrev
->has_children
;
17997 /* Make the result usable.
17998 The caller needs to update num_attrs after adding the extra
18000 die
->num_attrs
= abbrev
->num_attrs
;
18002 std::vector
<int> indexes_that_need_reprocess
;
18003 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18005 bool need_reprocess
;
18007 read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
18008 info_ptr
, &need_reprocess
);
18009 if (need_reprocess
)
18010 indexes_that_need_reprocess
.push_back (i
);
18013 struct attribute
*attr
= dwarf2_attr_no_follow (die
, DW_AT_str_offsets_base
);
18014 if (attr
!= nullptr)
18015 cu
->str_offsets_base
= DW_UNSND (attr
);
18017 auto maybe_addr_base
= lookup_addr_base(die
);
18018 if (maybe_addr_base
.has_value ())
18019 cu
->addr_base
= *maybe_addr_base
;
18020 for (int index
: indexes_that_need_reprocess
)
18021 read_attribute_reprocess (reader
, &die
->attrs
[index
]);
18026 /* Read a die and all its attributes.
18027 Set DIEP to point to a newly allocated die with its information,
18028 except for its child, sibling, and parent fields. */
18030 static const gdb_byte
*
18031 read_full_die (const struct die_reader_specs
*reader
,
18032 struct die_info
**diep
, const gdb_byte
*info_ptr
)
18034 const gdb_byte
*result
;
18036 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
18038 if (dwarf_die_debug
)
18040 fprintf_unfiltered (gdb_stdlog
,
18041 "Read die from %s@0x%x of %s:\n",
18042 reader
->die_section
->get_name (),
18043 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18044 bfd_get_filename (reader
->abfd
));
18045 dump_die (*diep
, dwarf_die_debug
);
18052 /* Returns nonzero if TAG represents a type that we might generate a partial
18056 is_type_tag_for_partial (int tag
)
18061 /* Some types that would be reasonable to generate partial symbols for,
18062 that we don't at present. */
18063 case DW_TAG_array_type
:
18064 case DW_TAG_file_type
:
18065 case DW_TAG_ptr_to_member_type
:
18066 case DW_TAG_set_type
:
18067 case DW_TAG_string_type
:
18068 case DW_TAG_subroutine_type
:
18070 case DW_TAG_base_type
:
18071 case DW_TAG_class_type
:
18072 case DW_TAG_interface_type
:
18073 case DW_TAG_enumeration_type
:
18074 case DW_TAG_structure_type
:
18075 case DW_TAG_subrange_type
:
18076 case DW_TAG_typedef
:
18077 case DW_TAG_union_type
:
18084 /* Load all DIEs that are interesting for partial symbols into memory. */
18086 static struct partial_die_info
*
18087 load_partial_dies (const struct die_reader_specs
*reader
,
18088 const gdb_byte
*info_ptr
, int building_psymtab
)
18090 struct dwarf2_cu
*cu
= reader
->cu
;
18091 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18092 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18093 unsigned int bytes_read
;
18094 unsigned int load_all
= 0;
18095 int nesting_level
= 1;
18100 gdb_assert (cu
->per_cu
!= NULL
);
18101 if (cu
->per_cu
->load_all_dies
)
18105 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18109 &cu
->comp_unit_obstack
,
18110 hashtab_obstack_allocate
,
18111 dummy_obstack_deallocate
);
18115 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
18117 /* A NULL abbrev means the end of a series of children. */
18118 if (abbrev
== NULL
)
18120 if (--nesting_level
== 0)
18123 info_ptr
+= bytes_read
;
18124 last_die
= parent_die
;
18125 parent_die
= parent_die
->die_parent
;
18129 /* Check for template arguments. We never save these; if
18130 they're seen, we just mark the parent, and go on our way. */
18131 if (parent_die
!= NULL
18132 && cu
->language
== language_cplus
18133 && (abbrev
->tag
== DW_TAG_template_type_param
18134 || abbrev
->tag
== DW_TAG_template_value_param
))
18136 parent_die
->has_template_arguments
= 1;
18140 /* We don't need a partial DIE for the template argument. */
18141 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18146 /* We only recurse into c++ subprograms looking for template arguments.
18147 Skip their other children. */
18149 && cu
->language
== language_cplus
18150 && parent_die
!= NULL
18151 && parent_die
->tag
== DW_TAG_subprogram
)
18153 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18157 /* Check whether this DIE is interesting enough to save. Normally
18158 we would not be interested in members here, but there may be
18159 later variables referencing them via DW_AT_specification (for
18160 static members). */
18162 && !is_type_tag_for_partial (abbrev
->tag
)
18163 && abbrev
->tag
!= DW_TAG_constant
18164 && abbrev
->tag
!= DW_TAG_enumerator
18165 && abbrev
->tag
!= DW_TAG_subprogram
18166 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18167 && abbrev
->tag
!= DW_TAG_lexical_block
18168 && abbrev
->tag
!= DW_TAG_variable
18169 && abbrev
->tag
!= DW_TAG_namespace
18170 && abbrev
->tag
!= DW_TAG_module
18171 && abbrev
->tag
!= DW_TAG_member
18172 && abbrev
->tag
!= DW_TAG_imported_unit
18173 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18175 /* Otherwise we skip to the next sibling, if any. */
18176 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18180 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
18183 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
18185 /* This two-pass algorithm for processing partial symbols has a
18186 high cost in cache pressure. Thus, handle some simple cases
18187 here which cover the majority of C partial symbols. DIEs
18188 which neither have specification tags in them, nor could have
18189 specification tags elsewhere pointing at them, can simply be
18190 processed and discarded.
18192 This segment is also optional; scan_partial_symbols and
18193 add_partial_symbol will handle these DIEs if we chain
18194 them in normally. When compilers which do not emit large
18195 quantities of duplicate debug information are more common,
18196 this code can probably be removed. */
18198 /* Any complete simple types at the top level (pretty much all
18199 of them, for a language without namespaces), can be processed
18201 if (parent_die
== NULL
18202 && pdi
.has_specification
== 0
18203 && pdi
.is_declaration
== 0
18204 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
18205 || pdi
.tag
== DW_TAG_base_type
18206 || pdi
.tag
== DW_TAG_subrange_type
))
18208 if (building_psymtab
&& pdi
.name
!= NULL
)
18209 add_psymbol_to_list (pdi
.name
, false,
18210 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
18211 psymbol_placement::STATIC
,
18212 0, cu
->language
, objfile
);
18213 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18217 /* The exception for DW_TAG_typedef with has_children above is
18218 a workaround of GCC PR debug/47510. In the case of this complaint
18219 type_name_or_error will error on such types later.
18221 GDB skipped children of DW_TAG_typedef by the shortcut above and then
18222 it could not find the child DIEs referenced later, this is checked
18223 above. In correct DWARF DW_TAG_typedef should have no children. */
18225 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
18226 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
18227 "- DIE at %s [in module %s]"),
18228 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
18230 /* If we're at the second level, and we're an enumerator, and
18231 our parent has no specification (meaning possibly lives in a
18232 namespace elsewhere), then we can add the partial symbol now
18233 instead of queueing it. */
18234 if (pdi
.tag
== DW_TAG_enumerator
18235 && parent_die
!= NULL
18236 && parent_die
->die_parent
== NULL
18237 && parent_die
->tag
== DW_TAG_enumeration_type
18238 && parent_die
->has_specification
== 0)
18240 if (pdi
.name
== NULL
)
18241 complaint (_("malformed enumerator DIE ignored"));
18242 else if (building_psymtab
)
18243 add_psymbol_to_list (pdi
.name
, false,
18244 VAR_DOMAIN
, LOC_CONST
, -1,
18245 cu
->language
== language_cplus
18246 ? psymbol_placement::GLOBAL
18247 : psymbol_placement::STATIC
,
18248 0, cu
->language
, objfile
);
18250 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18254 struct partial_die_info
*part_die
18255 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
18257 /* We'll save this DIE so link it in. */
18258 part_die
->die_parent
= parent_die
;
18259 part_die
->die_sibling
= NULL
;
18260 part_die
->die_child
= NULL
;
18262 if (last_die
&& last_die
== parent_die
)
18263 last_die
->die_child
= part_die
;
18265 last_die
->die_sibling
= part_die
;
18267 last_die
= part_die
;
18269 if (first_die
== NULL
)
18270 first_die
= part_die
;
18272 /* Maybe add the DIE to the hash table. Not all DIEs that we
18273 find interesting need to be in the hash table, because we
18274 also have the parent/sibling/child chains; only those that we
18275 might refer to by offset later during partial symbol reading.
18277 For now this means things that might have be the target of a
18278 DW_AT_specification, DW_AT_abstract_origin, or
18279 DW_AT_extension. DW_AT_extension will refer only to
18280 namespaces; DW_AT_abstract_origin refers to functions (and
18281 many things under the function DIE, but we do not recurse
18282 into function DIEs during partial symbol reading) and
18283 possibly variables as well; DW_AT_specification refers to
18284 declarations. Declarations ought to have the DW_AT_declaration
18285 flag. It happens that GCC forgets to put it in sometimes, but
18286 only for functions, not for types.
18288 Adding more things than necessary to the hash table is harmless
18289 except for the performance cost. Adding too few will result in
18290 wasted time in find_partial_die, when we reread the compilation
18291 unit with load_all_dies set. */
18294 || abbrev
->tag
== DW_TAG_constant
18295 || abbrev
->tag
== DW_TAG_subprogram
18296 || abbrev
->tag
== DW_TAG_variable
18297 || abbrev
->tag
== DW_TAG_namespace
18298 || part_die
->is_declaration
)
18302 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
18303 to_underlying (part_die
->sect_off
),
18308 /* For some DIEs we want to follow their children (if any). For C
18309 we have no reason to follow the children of structures; for other
18310 languages we have to, so that we can get at method physnames
18311 to infer fully qualified class names, for DW_AT_specification,
18312 and for C++ template arguments. For C++, we also look one level
18313 inside functions to find template arguments (if the name of the
18314 function does not already contain the template arguments).
18316 For Ada and Fortran, we need to scan the children of subprograms
18317 and lexical blocks as well because these languages allow the
18318 definition of nested entities that could be interesting for the
18319 debugger, such as nested subprograms for instance. */
18320 if (last_die
->has_children
18322 || last_die
->tag
== DW_TAG_namespace
18323 || last_die
->tag
== DW_TAG_module
18324 || last_die
->tag
== DW_TAG_enumeration_type
18325 || (cu
->language
== language_cplus
18326 && last_die
->tag
== DW_TAG_subprogram
18327 && (last_die
->name
== NULL
18328 || strchr (last_die
->name
, '<') == NULL
))
18329 || (cu
->language
!= language_c
18330 && (last_die
->tag
== DW_TAG_class_type
18331 || last_die
->tag
== DW_TAG_interface_type
18332 || last_die
->tag
== DW_TAG_structure_type
18333 || last_die
->tag
== DW_TAG_union_type
))
18334 || ((cu
->language
== language_ada
18335 || cu
->language
== language_fortran
)
18336 && (last_die
->tag
== DW_TAG_subprogram
18337 || last_die
->tag
== DW_TAG_lexical_block
))))
18340 parent_die
= last_die
;
18344 /* Otherwise we skip to the next sibling, if any. */
18345 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
18347 /* Back to the top, do it again. */
18351 partial_die_info::partial_die_info (sect_offset sect_off_
,
18352 struct abbrev_info
*abbrev
)
18353 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
18357 /* Read a minimal amount of information into the minimal die structure.
18358 INFO_PTR should point just after the initial uleb128 of a DIE. */
18361 partial_die_info::read (const struct die_reader_specs
*reader
,
18362 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
18364 struct dwarf2_cu
*cu
= reader
->cu
;
18365 struct dwarf2_per_objfile
*dwarf2_per_objfile
18366 = cu
->per_cu
->dwarf2_per_objfile
;
18368 int has_low_pc_attr
= 0;
18369 int has_high_pc_attr
= 0;
18370 int high_pc_relative
= 0;
18372 std::vector
<struct attribute
> attr_vec (abbrev
.num_attrs
);
18373 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
18375 bool need_reprocess
;
18376 info_ptr
= read_attribute (reader
, &attr_vec
[i
], &abbrev
.attrs
[i
],
18377 info_ptr
, &need_reprocess
);
18378 /* String and address offsets that need to do the reprocessing have
18379 already been read at this point, so there is no need to wait until
18380 the loop terminates to do the reprocessing. */
18381 if (need_reprocess
)
18382 read_attribute_reprocess (reader
, &attr_vec
[i
]);
18383 attribute
&attr
= attr_vec
[i
];
18384 /* Store the data if it is of an attribute we want to keep in a
18385 partial symbol table. */
18391 case DW_TAG_compile_unit
:
18392 case DW_TAG_partial_unit
:
18393 case DW_TAG_type_unit
:
18394 /* Compilation units have a DW_AT_name that is a filename, not
18395 a source language identifier. */
18396 case DW_TAG_enumeration_type
:
18397 case DW_TAG_enumerator
:
18398 /* These tags always have simple identifiers already; no need
18399 to canonicalize them. */
18400 name
= DW_STRING (&attr
);
18404 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18407 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
18408 &objfile
->per_bfd
->storage_obstack
);
18413 case DW_AT_linkage_name
:
18414 case DW_AT_MIPS_linkage_name
:
18415 /* Note that both forms of linkage name might appear. We
18416 assume they will be the same, and we only store the last
18418 linkage_name
= DW_STRING (&attr
);
18421 has_low_pc_attr
= 1;
18422 lowpc
= attr
.value_as_address ();
18424 case DW_AT_high_pc
:
18425 has_high_pc_attr
= 1;
18426 highpc
= attr
.value_as_address ();
18427 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
18428 high_pc_relative
= 1;
18430 case DW_AT_location
:
18431 /* Support the .debug_loc offsets. */
18432 if (attr
.form_is_block ())
18434 d
.locdesc
= DW_BLOCK (&attr
);
18436 else if (attr
.form_is_section_offset ())
18438 dwarf2_complex_location_expr_complaint ();
18442 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18443 "partial symbol information");
18446 case DW_AT_external
:
18447 is_external
= DW_UNSND (&attr
);
18449 case DW_AT_declaration
:
18450 is_declaration
= DW_UNSND (&attr
);
18455 case DW_AT_abstract_origin
:
18456 case DW_AT_specification
:
18457 case DW_AT_extension
:
18458 has_specification
= 1;
18459 spec_offset
= dwarf2_get_ref_die_offset (&attr
);
18460 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18461 || cu
->per_cu
->is_dwz
);
18463 case DW_AT_sibling
:
18464 /* Ignore absolute siblings, they might point outside of
18465 the current compile unit. */
18466 if (attr
.form
== DW_FORM_ref_addr
)
18467 complaint (_("ignoring absolute DW_AT_sibling"));
18470 const gdb_byte
*buffer
= reader
->buffer
;
18471 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
18472 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
18474 if (sibling_ptr
< info_ptr
)
18475 complaint (_("DW_AT_sibling points backwards"));
18476 else if (sibling_ptr
> reader
->buffer_end
)
18477 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
18479 sibling
= sibling_ptr
;
18482 case DW_AT_byte_size
:
18485 case DW_AT_const_value
:
18486 has_const_value
= 1;
18488 case DW_AT_calling_convention
:
18489 /* DWARF doesn't provide a way to identify a program's source-level
18490 entry point. DW_AT_calling_convention attributes are only meant
18491 to describe functions' calling conventions.
18493 However, because it's a necessary piece of information in
18494 Fortran, and before DWARF 4 DW_CC_program was the only
18495 piece of debugging information whose definition refers to
18496 a 'main program' at all, several compilers marked Fortran
18497 main programs with DW_CC_program --- even when those
18498 functions use the standard calling conventions.
18500 Although DWARF now specifies a way to provide this
18501 information, we support this practice for backward
18503 if (DW_UNSND (&attr
) == DW_CC_program
18504 && cu
->language
== language_fortran
)
18505 main_subprogram
= 1;
18508 if (DW_UNSND (&attr
) == DW_INL_inlined
18509 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
18510 may_be_inlined
= 1;
18514 if (tag
== DW_TAG_imported_unit
)
18516 d
.sect_off
= dwarf2_get_ref_die_offset (&attr
);
18517 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18518 || cu
->per_cu
->is_dwz
);
18522 case DW_AT_main_subprogram
:
18523 main_subprogram
= DW_UNSND (&attr
);
18528 /* It would be nice to reuse dwarf2_get_pc_bounds here,
18529 but that requires a full DIE, so instead we just
18531 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
18532 unsigned int ranges_offset
= (DW_UNSND (&attr
)
18533 + (need_ranges_base
18537 /* Value of the DW_AT_ranges attribute is the offset in the
18538 .debug_ranges section. */
18539 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
18550 /* For Ada, if both the name and the linkage name appear, we prefer
18551 the latter. This lets "catch exception" work better, regardless
18552 of the order in which the name and linkage name were emitted.
18553 Really, though, this is just a workaround for the fact that gdb
18554 doesn't store both the name and the linkage name. */
18555 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
18556 name
= linkage_name
;
18558 if (high_pc_relative
)
18561 if (has_low_pc_attr
&& has_high_pc_attr
)
18563 /* When using the GNU linker, .gnu.linkonce. sections are used to
18564 eliminate duplicate copies of functions and vtables and such.
18565 The linker will arbitrarily choose one and discard the others.
18566 The AT_*_pc values for such functions refer to local labels in
18567 these sections. If the section from that file was discarded, the
18568 labels are not in the output, so the relocs get a value of 0.
18569 If this is a discarded function, mark the pc bounds as invalid,
18570 so that GDB will ignore it. */
18571 if (lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
18573 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18574 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18576 complaint (_("DW_AT_low_pc %s is zero "
18577 "for DIE at %s [in module %s]"),
18578 paddress (gdbarch
, lowpc
),
18579 sect_offset_str (sect_off
),
18580 objfile_name (objfile
));
18582 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
18583 else if (lowpc
>= highpc
)
18585 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18586 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18588 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
18589 "for DIE at %s [in module %s]"),
18590 paddress (gdbarch
, lowpc
),
18591 paddress (gdbarch
, highpc
),
18592 sect_offset_str (sect_off
),
18593 objfile_name (objfile
));
18602 /* Find a cached partial DIE at OFFSET in CU. */
18604 struct partial_die_info
*
18605 dwarf2_cu::find_partial_die (sect_offset sect_off
)
18607 struct partial_die_info
*lookup_die
= NULL
;
18608 struct partial_die_info
part_die (sect_off
);
18610 lookup_die
= ((struct partial_die_info
*)
18611 htab_find_with_hash (partial_dies
, &part_die
,
18612 to_underlying (sect_off
)));
18617 /* Find a partial DIE at OFFSET, which may or may not be in CU,
18618 except in the case of .debug_types DIEs which do not reference
18619 outside their CU (they do however referencing other types via
18620 DW_FORM_ref_sig8). */
18622 static const struct cu_partial_die_info
18623 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
18625 struct dwarf2_per_objfile
*dwarf2_per_objfile
18626 = cu
->per_cu
->dwarf2_per_objfile
;
18627 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18628 struct dwarf2_per_cu_data
*per_cu
= NULL
;
18629 struct partial_die_info
*pd
= NULL
;
18631 if (offset_in_dwz
== cu
->per_cu
->is_dwz
18632 && offset_in_cu_p (&cu
->header
, sect_off
))
18634 pd
= cu
->find_partial_die (sect_off
);
18637 /* We missed recording what we needed.
18638 Load all dies and try again. */
18639 per_cu
= cu
->per_cu
;
18643 /* TUs don't reference other CUs/TUs (except via type signatures). */
18644 if (cu
->per_cu
->is_debug_types
)
18646 error (_("Dwarf Error: Type Unit at offset %s contains"
18647 " external reference to offset %s [in module %s].\n"),
18648 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
18649 bfd_get_filename (objfile
->obfd
));
18651 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
18652 dwarf2_per_objfile
);
18654 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
18655 load_partial_comp_unit (per_cu
);
18657 per_cu
->cu
->last_used
= 0;
18658 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18661 /* If we didn't find it, and not all dies have been loaded,
18662 load them all and try again. */
18664 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
18666 per_cu
->load_all_dies
= 1;
18668 /* This is nasty. When we reread the DIEs, somewhere up the call chain
18669 THIS_CU->cu may already be in use. So we can't just free it and
18670 replace its DIEs with the ones we read in. Instead, we leave those
18671 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
18672 and clobber THIS_CU->cu->partial_dies with the hash table for the new
18674 load_partial_comp_unit (per_cu
);
18676 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18680 internal_error (__FILE__
, __LINE__
,
18681 _("could not find partial DIE %s "
18682 "in cache [from module %s]\n"),
18683 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
18684 return { per_cu
->cu
, pd
};
18687 /* See if we can figure out if the class lives in a namespace. We do
18688 this by looking for a member function; its demangled name will
18689 contain namespace info, if there is any. */
18692 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
18693 struct dwarf2_cu
*cu
)
18695 /* NOTE: carlton/2003-10-07: Getting the info this way changes
18696 what template types look like, because the demangler
18697 frequently doesn't give the same name as the debug info. We
18698 could fix this by only using the demangled name to get the
18699 prefix (but see comment in read_structure_type). */
18701 struct partial_die_info
*real_pdi
;
18702 struct partial_die_info
*child_pdi
;
18704 /* If this DIE (this DIE's specification, if any) has a parent, then
18705 we should not do this. We'll prepend the parent's fully qualified
18706 name when we create the partial symbol. */
18708 real_pdi
= struct_pdi
;
18709 while (real_pdi
->has_specification
)
18711 auto res
= find_partial_die (real_pdi
->spec_offset
,
18712 real_pdi
->spec_is_dwz
, cu
);
18713 real_pdi
= res
.pdi
;
18717 if (real_pdi
->die_parent
!= NULL
)
18720 for (child_pdi
= struct_pdi
->die_child
;
18722 child_pdi
= child_pdi
->die_sibling
)
18724 if (child_pdi
->tag
== DW_TAG_subprogram
18725 && child_pdi
->linkage_name
!= NULL
)
18727 gdb::unique_xmalloc_ptr
<char> actual_class_name
18728 (language_class_name_from_physname (cu
->language_defn
,
18729 child_pdi
->linkage_name
));
18730 if (actual_class_name
!= NULL
)
18732 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18734 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
18735 actual_class_name
.get ());
18743 partial_die_info::fixup (struct dwarf2_cu
*cu
)
18745 /* Once we've fixed up a die, there's no point in doing so again.
18746 This also avoids a memory leak if we were to call
18747 guess_partial_die_structure_name multiple times. */
18751 /* If we found a reference attribute and the DIE has no name, try
18752 to find a name in the referred to DIE. */
18754 if (name
== NULL
&& has_specification
)
18756 struct partial_die_info
*spec_die
;
18758 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18759 spec_die
= res
.pdi
;
18762 spec_die
->fixup (cu
);
18764 if (spec_die
->name
)
18766 name
= spec_die
->name
;
18768 /* Copy DW_AT_external attribute if it is set. */
18769 if (spec_die
->is_external
)
18770 is_external
= spec_die
->is_external
;
18774 /* Set default names for some unnamed DIEs. */
18776 if (name
== NULL
&& tag
== DW_TAG_namespace
)
18777 name
= CP_ANONYMOUS_NAMESPACE_STR
;
18779 /* If there is no parent die to provide a namespace, and there are
18780 children, see if we can determine the namespace from their linkage
18782 if (cu
->language
== language_cplus
18783 && !cu
->per_cu
->dwarf2_per_objfile
->types
.empty ()
18784 && die_parent
== NULL
18786 && (tag
== DW_TAG_class_type
18787 || tag
== DW_TAG_structure_type
18788 || tag
== DW_TAG_union_type
))
18789 guess_partial_die_structure_name (this, cu
);
18791 /* GCC might emit a nameless struct or union that has a linkage
18792 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
18794 && (tag
== DW_TAG_class_type
18795 || tag
== DW_TAG_interface_type
18796 || tag
== DW_TAG_structure_type
18797 || tag
== DW_TAG_union_type
)
18798 && linkage_name
!= NULL
)
18800 gdb::unique_xmalloc_ptr
<char> demangled
18801 (gdb_demangle (linkage_name
, DMGL_TYPES
));
18802 if (demangled
!= nullptr)
18806 /* Strip any leading namespaces/classes, keep only the base name.
18807 DW_AT_name for named DIEs does not contain the prefixes. */
18808 base
= strrchr (demangled
.get (), ':');
18809 if (base
&& base
> demangled
.get () && base
[-1] == ':')
18812 base
= demangled
.get ();
18814 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18815 name
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
, base
);
18822 /* Process the attributes that had to be skipped in the first round. These
18823 attributes are the ones that need str_offsets_base or addr_base attributes.
18824 They could not have been processed in the first round, because at the time
18825 the values of str_offsets_base or addr_base may not have been known. */
18826 void read_attribute_reprocess (const struct die_reader_specs
*reader
,
18827 struct attribute
*attr
)
18829 struct dwarf2_cu
*cu
= reader
->cu
;
18830 switch (attr
->form
)
18832 case DW_FORM_addrx
:
18833 case DW_FORM_GNU_addr_index
:
18834 DW_ADDR (attr
) = read_addr_index (cu
, DW_UNSND (attr
));
18837 case DW_FORM_strx1
:
18838 case DW_FORM_strx2
:
18839 case DW_FORM_strx3
:
18840 case DW_FORM_strx4
:
18841 case DW_FORM_GNU_str_index
:
18843 unsigned int str_index
= DW_UNSND (attr
);
18844 if (reader
->dwo_file
!= NULL
)
18846 DW_STRING (attr
) = read_dwo_str_index (reader
, str_index
);
18847 DW_STRING_IS_CANONICAL (attr
) = 0;
18851 DW_STRING (attr
) = read_stub_str_index (cu
, str_index
);
18852 DW_STRING_IS_CANONICAL (attr
) = 0;
18857 gdb_assert_not_reached (_("Unexpected DWARF form."));
18861 /* Read an attribute value described by an attribute form. */
18863 static const gdb_byte
*
18864 read_attribute_value (const struct die_reader_specs
*reader
,
18865 struct attribute
*attr
, unsigned form
,
18866 LONGEST implicit_const
, const gdb_byte
*info_ptr
,
18867 bool *need_reprocess
)
18869 struct dwarf2_cu
*cu
= reader
->cu
;
18870 struct dwarf2_per_objfile
*dwarf2_per_objfile
18871 = cu
->per_cu
->dwarf2_per_objfile
;
18872 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18873 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18874 bfd
*abfd
= reader
->abfd
;
18875 struct comp_unit_head
*cu_header
= &cu
->header
;
18876 unsigned int bytes_read
;
18877 struct dwarf_block
*blk
;
18878 *need_reprocess
= false;
18880 attr
->form
= (enum dwarf_form
) form
;
18883 case DW_FORM_ref_addr
:
18884 if (cu
->header
.version
== 2)
18885 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
18887 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
18888 &cu
->header
, &bytes_read
);
18889 info_ptr
+= bytes_read
;
18891 case DW_FORM_GNU_ref_alt
:
18892 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
18893 info_ptr
+= bytes_read
;
18896 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
18897 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
18898 info_ptr
+= bytes_read
;
18900 case DW_FORM_block2
:
18901 blk
= dwarf_alloc_block (cu
);
18902 blk
->size
= read_2_bytes (abfd
, info_ptr
);
18904 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18905 info_ptr
+= blk
->size
;
18906 DW_BLOCK (attr
) = blk
;
18908 case DW_FORM_block4
:
18909 blk
= dwarf_alloc_block (cu
);
18910 blk
->size
= read_4_bytes (abfd
, info_ptr
);
18912 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18913 info_ptr
+= blk
->size
;
18914 DW_BLOCK (attr
) = blk
;
18916 case DW_FORM_data2
:
18917 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
18920 case DW_FORM_data4
:
18921 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
18924 case DW_FORM_data8
:
18925 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
18928 case DW_FORM_data16
:
18929 blk
= dwarf_alloc_block (cu
);
18931 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
18933 DW_BLOCK (attr
) = blk
;
18935 case DW_FORM_sec_offset
:
18936 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
18937 info_ptr
+= bytes_read
;
18939 case DW_FORM_string
:
18940 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
18941 DW_STRING_IS_CANONICAL (attr
) = 0;
18942 info_ptr
+= bytes_read
;
18945 if (!cu
->per_cu
->is_dwz
)
18947 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
18948 abfd
, info_ptr
, cu_header
,
18950 DW_STRING_IS_CANONICAL (attr
) = 0;
18951 info_ptr
+= bytes_read
;
18955 case DW_FORM_line_strp
:
18956 if (!cu
->per_cu
->is_dwz
)
18958 DW_STRING (attr
) = read_indirect_line_string (dwarf2_per_objfile
,
18960 cu_header
, &bytes_read
);
18961 DW_STRING_IS_CANONICAL (attr
) = 0;
18962 info_ptr
+= bytes_read
;
18966 case DW_FORM_GNU_strp_alt
:
18968 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
18969 LONGEST str_offset
= read_offset (abfd
, info_ptr
, cu_header
,
18972 DW_STRING (attr
) = read_indirect_string_from_dwz (objfile
,
18974 DW_STRING_IS_CANONICAL (attr
) = 0;
18975 info_ptr
+= bytes_read
;
18978 case DW_FORM_exprloc
:
18979 case DW_FORM_block
:
18980 blk
= dwarf_alloc_block (cu
);
18981 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18982 info_ptr
+= bytes_read
;
18983 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18984 info_ptr
+= blk
->size
;
18985 DW_BLOCK (attr
) = blk
;
18987 case DW_FORM_block1
:
18988 blk
= dwarf_alloc_block (cu
);
18989 blk
->size
= read_1_byte (abfd
, info_ptr
);
18991 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18992 info_ptr
+= blk
->size
;
18993 DW_BLOCK (attr
) = blk
;
18995 case DW_FORM_data1
:
18996 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19000 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19003 case DW_FORM_flag_present
:
19004 DW_UNSND (attr
) = 1;
19006 case DW_FORM_sdata
:
19007 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19008 info_ptr
+= bytes_read
;
19010 case DW_FORM_udata
:
19011 case DW_FORM_rnglistx
:
19012 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19013 info_ptr
+= bytes_read
;
19016 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19017 + read_1_byte (abfd
, info_ptr
));
19021 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19022 + read_2_bytes (abfd
, info_ptr
));
19026 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19027 + read_4_bytes (abfd
, info_ptr
));
19031 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19032 + read_8_bytes (abfd
, info_ptr
));
19035 case DW_FORM_ref_sig8
:
19036 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
19039 case DW_FORM_ref_udata
:
19040 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19041 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
19042 info_ptr
+= bytes_read
;
19044 case DW_FORM_indirect
:
19045 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19046 info_ptr
+= bytes_read
;
19047 if (form
== DW_FORM_implicit_const
)
19049 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19050 info_ptr
+= bytes_read
;
19052 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
19053 info_ptr
, need_reprocess
);
19055 case DW_FORM_implicit_const
:
19056 DW_SND (attr
) = implicit_const
;
19058 case DW_FORM_addrx
:
19059 case DW_FORM_GNU_addr_index
:
19060 *need_reprocess
= true;
19061 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19062 info_ptr
+= bytes_read
;
19065 case DW_FORM_strx1
:
19066 case DW_FORM_strx2
:
19067 case DW_FORM_strx3
:
19068 case DW_FORM_strx4
:
19069 case DW_FORM_GNU_str_index
:
19071 ULONGEST str_index
;
19072 if (form
== DW_FORM_strx1
)
19074 str_index
= read_1_byte (abfd
, info_ptr
);
19077 else if (form
== DW_FORM_strx2
)
19079 str_index
= read_2_bytes (abfd
, info_ptr
);
19082 else if (form
== DW_FORM_strx3
)
19084 str_index
= read_3_bytes (abfd
, info_ptr
);
19087 else if (form
== DW_FORM_strx4
)
19089 str_index
= read_4_bytes (abfd
, info_ptr
);
19094 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19095 info_ptr
+= bytes_read
;
19097 *need_reprocess
= true;
19098 DW_UNSND (attr
) = str_index
;
19102 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
19103 dwarf_form_name (form
),
19104 bfd_get_filename (abfd
));
19108 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
19109 attr
->form
= DW_FORM_GNU_ref_alt
;
19111 /* We have seen instances where the compiler tried to emit a byte
19112 size attribute of -1 which ended up being encoded as an unsigned
19113 0xffffffff. Although 0xffffffff is technically a valid size value,
19114 an object of this size seems pretty unlikely so we can relatively
19115 safely treat these cases as if the size attribute was invalid and
19116 treat them as zero by default. */
19117 if (attr
->name
== DW_AT_byte_size
19118 && form
== DW_FORM_data4
19119 && DW_UNSND (attr
) >= 0xffffffff)
19122 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
19123 hex_string (DW_UNSND (attr
)));
19124 DW_UNSND (attr
) = 0;
19130 /* Read an attribute described by an abbreviated attribute. */
19132 static const gdb_byte
*
19133 read_attribute (const struct die_reader_specs
*reader
,
19134 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
19135 const gdb_byte
*info_ptr
, bool *need_reprocess
)
19137 attr
->name
= abbrev
->name
;
19138 return read_attribute_value (reader
, attr
, abbrev
->form
,
19139 abbrev
->implicit_const
, info_ptr
,
19144 read_address (bfd
*abfd
, const gdb_byte
*buf
, struct dwarf2_cu
*cu
,
19145 unsigned int *bytes_read
)
19147 struct comp_unit_head
*cu_header
= &cu
->header
;
19148 CORE_ADDR retval
= 0;
19150 if (cu_header
->signed_addr_p
)
19152 switch (cu_header
->addr_size
)
19155 retval
= bfd_get_signed_16 (abfd
, buf
);
19158 retval
= bfd_get_signed_32 (abfd
, buf
);
19161 retval
= bfd_get_signed_64 (abfd
, buf
);
19164 internal_error (__FILE__
, __LINE__
,
19165 _("read_address: bad switch, signed [in module %s]"),
19166 bfd_get_filename (abfd
));
19171 switch (cu_header
->addr_size
)
19174 retval
= bfd_get_16 (abfd
, buf
);
19177 retval
= bfd_get_32 (abfd
, buf
);
19180 retval
= bfd_get_64 (abfd
, buf
);
19183 internal_error (__FILE__
, __LINE__
,
19184 _("read_address: bad switch, "
19185 "unsigned [in module %s]"),
19186 bfd_get_filename (abfd
));
19190 *bytes_read
= cu_header
->addr_size
;
19194 /* Read the initial length from a section. The (draft) DWARF 3
19195 specification allows the initial length to take up either 4 bytes
19196 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
19197 bytes describe the length and all offsets will be 8 bytes in length
19200 An older, non-standard 64-bit format is also handled by this
19201 function. The older format in question stores the initial length
19202 as an 8-byte quantity without an escape value. Lengths greater
19203 than 2^32 aren't very common which means that the initial 4 bytes
19204 is almost always zero. Since a length value of zero doesn't make
19205 sense for the 32-bit format, this initial zero can be considered to
19206 be an escape value which indicates the presence of the older 64-bit
19207 format. As written, the code can't detect (old format) lengths
19208 greater than 4GB. If it becomes necessary to handle lengths
19209 somewhat larger than 4GB, we could allow other small values (such
19210 as the non-sensical values of 1, 2, and 3) to also be used as
19211 escape values indicating the presence of the old format.
19213 The value returned via bytes_read should be used to increment the
19214 relevant pointer after calling read_initial_length().
19216 [ Note: read_initial_length() and read_offset() are based on the
19217 document entitled "DWARF Debugging Information Format", revision
19218 3, draft 8, dated November 19, 2001. This document was obtained
19221 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
19223 This document is only a draft and is subject to change. (So beware.)
19225 Details regarding the older, non-standard 64-bit format were
19226 determined empirically by examining 64-bit ELF files produced by
19227 the SGI toolchain on an IRIX 6.5 machine.
19229 - Kevin, July 16, 2002
19233 read_initial_length (bfd
*abfd
, const gdb_byte
*buf
, unsigned int *bytes_read
)
19235 LONGEST length
= bfd_get_32 (abfd
, buf
);
19237 if (length
== 0xffffffff)
19239 length
= bfd_get_64 (abfd
, buf
+ 4);
19242 else if (length
== 0)
19244 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
19245 length
= bfd_get_64 (abfd
, buf
);
19256 /* Cover function for read_initial_length.
19257 Returns the length of the object at BUF, and stores the size of the
19258 initial length in *BYTES_READ and stores the size that offsets will be in
19260 If the initial length size is not equivalent to that specified in
19261 CU_HEADER then issue a complaint.
19262 This is useful when reading non-comp-unit headers. */
19265 read_checked_initial_length_and_offset (bfd
*abfd
, const gdb_byte
*buf
,
19266 const struct comp_unit_head
*cu_header
,
19267 unsigned int *bytes_read
,
19268 unsigned int *offset_size
)
19270 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
19272 gdb_assert (cu_header
->initial_length_size
== 4
19273 || cu_header
->initial_length_size
== 8
19274 || cu_header
->initial_length_size
== 12);
19276 if (cu_header
->initial_length_size
!= *bytes_read
)
19277 complaint (_("intermixed 32-bit and 64-bit DWARF sections"));
19279 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
19283 /* Read an offset from the data stream. The size of the offset is
19284 given by cu_header->offset_size. */
19287 read_offset (bfd
*abfd
, const gdb_byte
*buf
,
19288 const struct comp_unit_head
*cu_header
,
19289 unsigned int *bytes_read
)
19291 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
19293 *bytes_read
= cu_header
->offset_size
;
19297 /* Read an offset from the data stream. */
19300 read_offset_1 (bfd
*abfd
, const gdb_byte
*buf
, unsigned int offset_size
)
19302 LONGEST retval
= 0;
19304 switch (offset_size
)
19307 retval
= bfd_get_32 (abfd
, buf
);
19310 retval
= bfd_get_64 (abfd
, buf
);
19313 internal_error (__FILE__
, __LINE__
,
19314 _("read_offset_1: bad switch [in module %s]"),
19315 bfd_get_filename (abfd
));
19321 static const gdb_byte
*
19322 read_n_bytes (bfd
*abfd
, const gdb_byte
*buf
, unsigned int size
)
19324 /* If the size of a host char is 8 bits, we can return a pointer
19325 to the buffer, otherwise we have to copy the data to a buffer
19326 allocated on the temporary obstack. */
19327 gdb_assert (HOST_CHAR_BIT
== 8);
19331 static const char *
19332 read_direct_string (bfd
*abfd
, const gdb_byte
*buf
,
19333 unsigned int *bytes_read_ptr
)
19335 /* If the size of a host char is 8 bits, we can return a pointer
19336 to the string, otherwise we have to copy the string to a buffer
19337 allocated on the temporary obstack. */
19338 gdb_assert (HOST_CHAR_BIT
== 8);
19341 *bytes_read_ptr
= 1;
19344 *bytes_read_ptr
= strlen ((const char *) buf
) + 1;
19345 return (const char *) buf
;
19348 /* Return pointer to string at section SECT offset STR_OFFSET with error
19349 reporting strings FORM_NAME and SECT_NAME. */
19351 static const char *
19352 read_indirect_string_at_offset_from (struct objfile
*objfile
,
19353 bfd
*abfd
, LONGEST str_offset
,
19354 struct dwarf2_section_info
*sect
,
19355 const char *form_name
,
19356 const char *sect_name
)
19358 sect
->read (objfile
);
19359 if (sect
->buffer
== NULL
)
19360 error (_("%s used without %s section [in module %s]"),
19361 form_name
, sect_name
, bfd_get_filename (abfd
));
19362 if (str_offset
>= sect
->size
)
19363 error (_("%s pointing outside of %s section [in module %s]"),
19364 form_name
, sect_name
, bfd_get_filename (abfd
));
19365 gdb_assert (HOST_CHAR_BIT
== 8);
19366 if (sect
->buffer
[str_offset
] == '\0')
19368 return (const char *) (sect
->buffer
+ str_offset
);
19371 /* Return pointer to string at .debug_str offset STR_OFFSET. */
19373 static const char *
19374 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19375 bfd
*abfd
, LONGEST str_offset
)
19377 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
19379 &dwarf2_per_objfile
->str
,
19380 "DW_FORM_strp", ".debug_str");
19383 /* Return pointer to string at .debug_line_str offset STR_OFFSET. */
19385 static const char *
19386 read_indirect_line_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19387 bfd
*abfd
, LONGEST str_offset
)
19389 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
19391 &dwarf2_per_objfile
->line_str
,
19392 "DW_FORM_line_strp",
19393 ".debug_line_str");
19396 /* Read a string at offset STR_OFFSET in the .debug_str section from
19397 the .dwz file DWZ. Throw an error if the offset is too large. If
19398 the string consists of a single NUL byte, return NULL; otherwise
19399 return a pointer to the string. */
19401 static const char *
19402 read_indirect_string_from_dwz (struct objfile
*objfile
, struct dwz_file
*dwz
,
19403 LONGEST str_offset
)
19405 dwz
->str
.read (objfile
);
19407 if (dwz
->str
.buffer
== NULL
)
19408 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
19409 "section [in module %s]"),
19410 bfd_get_filename (dwz
->dwz_bfd
.get ()));
19411 if (str_offset
>= dwz
->str
.size
)
19412 error (_("DW_FORM_GNU_strp_alt pointing outside of "
19413 ".debug_str section [in module %s]"),
19414 bfd_get_filename (dwz
->dwz_bfd
.get ()));
19415 gdb_assert (HOST_CHAR_BIT
== 8);
19416 if (dwz
->str
.buffer
[str_offset
] == '\0')
19418 return (const char *) (dwz
->str
.buffer
+ str_offset
);
19421 /* Return pointer to string at .debug_str offset as read from BUF.
19422 BUF is assumed to be in a compilation unit described by CU_HEADER.
19423 Return *BYTES_READ_PTR count of bytes read from BUF. */
19425 static const char *
19426 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
19427 const gdb_byte
*buf
,
19428 const struct comp_unit_head
*cu_header
,
19429 unsigned int *bytes_read_ptr
)
19431 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
19433 return read_indirect_string_at_offset (dwarf2_per_objfile
, abfd
, str_offset
);
19436 /* Return pointer to string at .debug_line_str offset as read from BUF.
19437 BUF is assumed to be in a compilation unit described by CU_HEADER.
19438 Return *BYTES_READ_PTR count of bytes read from BUF. */
19440 static const char *
19441 read_indirect_line_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19442 bfd
*abfd
, const gdb_byte
*buf
,
19443 const struct comp_unit_head
*cu_header
,
19444 unsigned int *bytes_read_ptr
)
19446 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
19448 return read_indirect_line_string_at_offset (dwarf2_per_objfile
, abfd
,
19452 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
19453 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
19454 ADDR_SIZE is the size of addresses from the CU header. */
19457 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19458 unsigned int addr_index
, gdb::optional
<ULONGEST
> addr_base
,
19461 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19462 bfd
*abfd
= objfile
->obfd
;
19463 const gdb_byte
*info_ptr
;
19464 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
19466 dwarf2_per_objfile
->addr
.read (objfile
);
19467 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
19468 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
19469 objfile_name (objfile
));
19470 if (addr_base_or_zero
+ addr_index
* addr_size
19471 >= dwarf2_per_objfile
->addr
.size
)
19472 error (_("DW_FORM_addr_index pointing outside of "
19473 ".debug_addr section [in module %s]"),
19474 objfile_name (objfile
));
19475 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
19476 + addr_base_or_zero
+ addr_index
* addr_size
);
19477 if (addr_size
== 4)
19478 return bfd_get_32 (abfd
, info_ptr
);
19480 return bfd_get_64 (abfd
, info_ptr
);
19483 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
19486 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
19488 return read_addr_index_1 (cu
->per_cu
->dwarf2_per_objfile
, addr_index
,
19489 cu
->addr_base
, cu
->header
.addr_size
);
19492 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
19495 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
19496 unsigned int *bytes_read
)
19498 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
19499 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
19501 return read_addr_index (cu
, addr_index
);
19504 /* Given an index in .debug_addr, fetch the value.
19505 NOTE: This can be called during dwarf expression evaluation,
19506 long after the debug information has been read, and thus per_cu->cu
19507 may no longer exist. */
19510 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
19511 unsigned int addr_index
)
19513 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
19514 struct dwarf2_cu
*cu
= per_cu
->cu
;
19515 gdb::optional
<ULONGEST
> addr_base
;
19518 /* We need addr_base and addr_size.
19519 If we don't have PER_CU->cu, we have to get it.
19520 Nasty, but the alternative is storing the needed info in PER_CU,
19521 which at this point doesn't seem justified: it's not clear how frequently
19522 it would get used and it would increase the size of every PER_CU.
19523 Entry points like dwarf2_per_cu_addr_size do a similar thing
19524 so we're not in uncharted territory here.
19525 Alas we need to be a bit more complicated as addr_base is contained
19528 We don't need to read the entire CU(/TU).
19529 We just need the header and top level die.
19531 IWBN to use the aging mechanism to let us lazily later discard the CU.
19532 For now we skip this optimization. */
19536 addr_base
= cu
->addr_base
;
19537 addr_size
= cu
->header
.addr_size
;
19541 cutu_reader
reader (per_cu
, NULL
, 0, 0, false);
19542 addr_base
= reader
.cu
->addr_base
;
19543 addr_size
= reader
.cu
->header
.addr_size
;
19546 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
19550 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
19551 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
19554 static const char *
19555 read_str_index (struct dwarf2_cu
*cu
,
19556 struct dwarf2_section_info
*str_section
,
19557 struct dwarf2_section_info
*str_offsets_section
,
19558 ULONGEST str_offsets_base
, ULONGEST str_index
)
19560 struct dwarf2_per_objfile
*dwarf2_per_objfile
19561 = cu
->per_cu
->dwarf2_per_objfile
;
19562 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19563 const char *objf_name
= objfile_name (objfile
);
19564 bfd
*abfd
= objfile
->obfd
;
19565 const gdb_byte
*info_ptr
;
19566 ULONGEST str_offset
;
19567 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
19569 str_section
->read (objfile
);
19570 str_offsets_section
->read (objfile
);
19571 if (str_section
->buffer
== NULL
)
19572 error (_("%s used without %s section"
19573 " in CU at offset %s [in module %s]"),
19574 form_name
, str_section
->get_name (),
19575 sect_offset_str (cu
->header
.sect_off
), objf_name
);
19576 if (str_offsets_section
->buffer
== NULL
)
19577 error (_("%s used without %s section"
19578 " in CU at offset %s [in module %s]"),
19579 form_name
, str_section
->get_name (),
19580 sect_offset_str (cu
->header
.sect_off
), objf_name
);
19581 info_ptr
= (str_offsets_section
->buffer
19583 + str_index
* cu
->header
.offset_size
);
19584 if (cu
->header
.offset_size
== 4)
19585 str_offset
= bfd_get_32 (abfd
, info_ptr
);
19587 str_offset
= bfd_get_64 (abfd
, info_ptr
);
19588 if (str_offset
>= str_section
->size
)
19589 error (_("Offset from %s pointing outside of"
19590 " .debug_str.dwo section in CU at offset %s [in module %s]"),
19591 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19592 return (const char *) (str_section
->buffer
+ str_offset
);
19595 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
19597 static const char *
19598 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
19600 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
19601 ? reader
->cu
->header
.addr_size
: 0;
19602 return read_str_index (reader
->cu
,
19603 &reader
->dwo_file
->sections
.str
,
19604 &reader
->dwo_file
->sections
.str_offsets
,
19605 str_offsets_base
, str_index
);
19608 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
19610 static const char *
19611 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
19613 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19614 const char *objf_name
= objfile_name (objfile
);
19615 static const char form_name
[] = "DW_FORM_GNU_str_index";
19616 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
19618 if (!cu
->str_offsets_base
.has_value ())
19619 error (_("%s used in Fission stub without %s"
19620 " in CU at offset 0x%lx [in module %s]"),
19621 form_name
, str_offsets_attr_name
,
19622 (long) cu
->header
.offset_size
, objf_name
);
19624 return read_str_index (cu
,
19625 &cu
->per_cu
->dwarf2_per_objfile
->str
,
19626 &cu
->per_cu
->dwarf2_per_objfile
->str_offsets
,
19627 *cu
->str_offsets_base
, str_index
);
19630 /* Return the length of an LEB128 number in BUF. */
19633 leb128_size (const gdb_byte
*buf
)
19635 const gdb_byte
*begin
= buf
;
19641 if ((byte
& 128) == 0)
19642 return buf
- begin
;
19647 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
19656 cu
->language
= language_c
;
19659 case DW_LANG_C_plus_plus
:
19660 case DW_LANG_C_plus_plus_11
:
19661 case DW_LANG_C_plus_plus_14
:
19662 cu
->language
= language_cplus
;
19665 cu
->language
= language_d
;
19667 case DW_LANG_Fortran77
:
19668 case DW_LANG_Fortran90
:
19669 case DW_LANG_Fortran95
:
19670 case DW_LANG_Fortran03
:
19671 case DW_LANG_Fortran08
:
19672 cu
->language
= language_fortran
;
19675 cu
->language
= language_go
;
19677 case DW_LANG_Mips_Assembler
:
19678 cu
->language
= language_asm
;
19680 case DW_LANG_Ada83
:
19681 case DW_LANG_Ada95
:
19682 cu
->language
= language_ada
;
19684 case DW_LANG_Modula2
:
19685 cu
->language
= language_m2
;
19687 case DW_LANG_Pascal83
:
19688 cu
->language
= language_pascal
;
19691 cu
->language
= language_objc
;
19694 case DW_LANG_Rust_old
:
19695 cu
->language
= language_rust
;
19697 case DW_LANG_Cobol74
:
19698 case DW_LANG_Cobol85
:
19700 cu
->language
= language_minimal
;
19703 cu
->language_defn
= language_def (cu
->language
);
19706 /* Return the named attribute or NULL if not there. */
19708 static struct attribute
*
19709 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19714 struct attribute
*spec
= NULL
;
19716 for (i
= 0; i
< die
->num_attrs
; ++i
)
19718 if (die
->attrs
[i
].name
== name
)
19719 return &die
->attrs
[i
];
19720 if (die
->attrs
[i
].name
== DW_AT_specification
19721 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
19722 spec
= &die
->attrs
[i
];
19728 die
= follow_die_ref (die
, spec
, &cu
);
19734 /* Return the named attribute or NULL if not there,
19735 but do not follow DW_AT_specification, etc.
19736 This is for use in contexts where we're reading .debug_types dies.
19737 Following DW_AT_specification, DW_AT_abstract_origin will take us
19738 back up the chain, and we want to go down. */
19740 static struct attribute
*
19741 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
19745 for (i
= 0; i
< die
->num_attrs
; ++i
)
19746 if (die
->attrs
[i
].name
== name
)
19747 return &die
->attrs
[i
];
19752 /* Return the string associated with a string-typed attribute, or NULL if it
19753 is either not found or is of an incorrect type. */
19755 static const char *
19756 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19758 struct attribute
*attr
;
19759 const char *str
= NULL
;
19761 attr
= dwarf2_attr (die
, name
, cu
);
19765 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
19766 || attr
->form
== DW_FORM_string
19767 || attr
->form
== DW_FORM_strx
19768 || attr
->form
== DW_FORM_strx1
19769 || attr
->form
== DW_FORM_strx2
19770 || attr
->form
== DW_FORM_strx3
19771 || attr
->form
== DW_FORM_strx4
19772 || attr
->form
== DW_FORM_GNU_str_index
19773 || attr
->form
== DW_FORM_GNU_strp_alt
)
19774 str
= DW_STRING (attr
);
19776 complaint (_("string type expected for attribute %s for "
19777 "DIE at %s in module %s"),
19778 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
19779 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
19785 /* Return the dwo name or NULL if not present. If present, it is in either
19786 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
19787 static const char *
19788 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
19790 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
19791 if (dwo_name
== nullptr)
19792 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
19796 /* Return non-zero iff the attribute NAME is defined for the given DIE,
19797 and holds a non-zero value. This function should only be used for
19798 DW_FORM_flag or DW_FORM_flag_present attributes. */
19801 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
19803 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
19805 return (attr
&& DW_UNSND (attr
));
19809 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
19811 /* A DIE is a declaration if it has a DW_AT_declaration attribute
19812 which value is non-zero. However, we have to be careful with
19813 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
19814 (via dwarf2_flag_true_p) follows this attribute. So we may
19815 end up accidently finding a declaration attribute that belongs
19816 to a different DIE referenced by the specification attribute,
19817 even though the given DIE does not have a declaration attribute. */
19818 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
19819 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
19822 /* Return the die giving the specification for DIE, if there is
19823 one. *SPEC_CU is the CU containing DIE on input, and the CU
19824 containing the return value on output. If there is no
19825 specification, but there is an abstract origin, that is
19828 static struct die_info
*
19829 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
19831 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
19834 if (spec_attr
== NULL
)
19835 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
19837 if (spec_attr
== NULL
)
19840 return follow_die_ref (die
, spec_attr
, spec_cu
);
19843 /* Stub for free_line_header to match void * callback types. */
19846 free_line_header_voidp (void *arg
)
19848 struct line_header
*lh
= (struct line_header
*) arg
;
19854 line_header::add_include_dir (const char *include_dir
)
19856 if (dwarf_line_debug
>= 2)
19860 new_size
= m_include_dirs
.size ();
19862 new_size
= m_include_dirs
.size () + 1;
19863 fprintf_unfiltered (gdb_stdlog
, "Adding dir %zu: %s\n",
19864 new_size
, include_dir
);
19866 m_include_dirs
.push_back (include_dir
);
19870 line_header::add_file_name (const char *name
,
19872 unsigned int mod_time
,
19873 unsigned int length
)
19875 if (dwarf_line_debug
>= 2)
19879 new_size
= file_names_size ();
19881 new_size
= file_names_size () + 1;
19882 fprintf_unfiltered (gdb_stdlog
, "Adding file %zu: %s\n",
19885 m_file_names
.emplace_back (name
, d_index
, mod_time
, length
);
19888 /* A convenience function to find the proper .debug_line section for a CU. */
19890 static struct dwarf2_section_info
*
19891 get_debug_line_section (struct dwarf2_cu
*cu
)
19893 struct dwarf2_section_info
*section
;
19894 struct dwarf2_per_objfile
*dwarf2_per_objfile
19895 = cu
->per_cu
->dwarf2_per_objfile
;
19897 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
19899 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19900 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
19901 else if (cu
->per_cu
->is_dwz
)
19903 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19905 section
= &dwz
->line
;
19908 section
= &dwarf2_per_objfile
->line
;
19913 /* Read directory or file name entry format, starting with byte of
19914 format count entries, ULEB128 pairs of entry formats, ULEB128 of
19915 entries count and the entries themselves in the described entry
19919 read_formatted_entries (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19920 bfd
*abfd
, const gdb_byte
**bufp
,
19921 struct line_header
*lh
,
19922 const struct comp_unit_head
*cu_header
,
19923 void (*callback
) (struct line_header
*lh
,
19926 unsigned int mod_time
,
19927 unsigned int length
))
19929 gdb_byte format_count
, formati
;
19930 ULONGEST data_count
, datai
;
19931 const gdb_byte
*buf
= *bufp
;
19932 const gdb_byte
*format_header_data
;
19933 unsigned int bytes_read
;
19935 format_count
= read_1_byte (abfd
, buf
);
19937 format_header_data
= buf
;
19938 for (formati
= 0; formati
< format_count
; formati
++)
19940 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
19942 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
19946 data_count
= read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
19948 for (datai
= 0; datai
< data_count
; datai
++)
19950 const gdb_byte
*format
= format_header_data
;
19951 struct file_entry fe
;
19953 for (formati
= 0; formati
< format_count
; formati
++)
19955 ULONGEST content_type
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
19956 format
+= bytes_read
;
19958 ULONGEST form
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
19959 format
+= bytes_read
;
19961 gdb::optional
<const char *> string
;
19962 gdb::optional
<unsigned int> uint
;
19966 case DW_FORM_string
:
19967 string
.emplace (read_direct_string (abfd
, buf
, &bytes_read
));
19971 case DW_FORM_line_strp
:
19972 string
.emplace (read_indirect_line_string (dwarf2_per_objfile
,
19979 case DW_FORM_data1
:
19980 uint
.emplace (read_1_byte (abfd
, buf
));
19984 case DW_FORM_data2
:
19985 uint
.emplace (read_2_bytes (abfd
, buf
));
19989 case DW_FORM_data4
:
19990 uint
.emplace (read_4_bytes (abfd
, buf
));
19994 case DW_FORM_data8
:
19995 uint
.emplace (read_8_bytes (abfd
, buf
));
19999 case DW_FORM_data16
:
20000 /* This is used for MD5, but file_entry does not record MD5s. */
20004 case DW_FORM_udata
:
20005 uint
.emplace (read_unsigned_leb128 (abfd
, buf
, &bytes_read
));
20009 case DW_FORM_block
:
20010 /* It is valid only for DW_LNCT_timestamp which is ignored by
20015 switch (content_type
)
20018 if (string
.has_value ())
20021 case DW_LNCT_directory_index
:
20022 if (uint
.has_value ())
20023 fe
.d_index
= (dir_index
) *uint
;
20025 case DW_LNCT_timestamp
:
20026 if (uint
.has_value ())
20027 fe
.mod_time
= *uint
;
20030 if (uint
.has_value ())
20036 complaint (_("Unknown format content type %s"),
20037 pulongest (content_type
));
20041 callback (lh
, fe
.name
, fe
.d_index
, fe
.mod_time
, fe
.length
);
20047 /* Read the statement program header starting at OFFSET in
20048 .debug_line, or .debug_line.dwo. Return a pointer
20049 to a struct line_header, allocated using xmalloc.
20050 Returns NULL if there is a problem reading the header, e.g., if it
20051 has a version we don't understand.
20053 NOTE: the strings in the include directory and file name tables of
20054 the returned object point into the dwarf line section buffer,
20055 and must not be freed. */
20057 static line_header_up
20058 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
20060 const gdb_byte
*line_ptr
;
20061 unsigned int bytes_read
, offset_size
;
20063 const char *cur_dir
, *cur_file
;
20064 struct dwarf2_section_info
*section
;
20066 struct dwarf2_per_objfile
*dwarf2_per_objfile
20067 = cu
->per_cu
->dwarf2_per_objfile
;
20069 section
= get_debug_line_section (cu
);
20070 section
->read (dwarf2_per_objfile
->objfile
);
20071 if (section
->buffer
== NULL
)
20073 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20074 complaint (_("missing .debug_line.dwo section"));
20076 complaint (_("missing .debug_line section"));
20080 /* We can't do this until we know the section is non-empty.
20081 Only then do we know we have such a section. */
20082 abfd
= section
->get_bfd_owner ();
20084 /* Make sure that at least there's room for the total_length field.
20085 That could be 12 bytes long, but we're just going to fudge that. */
20086 if (to_underlying (sect_off
) + 4 >= section
->size
)
20088 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20092 line_header_up
lh (new line_header ());
20094 lh
->sect_off
= sect_off
;
20095 lh
->offset_in_dwz
= cu
->per_cu
->is_dwz
;
20097 line_ptr
= section
->buffer
+ to_underlying (sect_off
);
20099 /* Read in the header. */
20101 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
20102 &bytes_read
, &offset_size
);
20103 line_ptr
+= bytes_read
;
20105 const gdb_byte
*start_here
= line_ptr
;
20107 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
20109 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20112 lh
->statement_program_end
= start_here
+ lh
->total_length
;
20113 lh
->version
= read_2_bytes (abfd
, line_ptr
);
20115 if (lh
->version
> 5)
20117 /* This is a version we don't understand. The format could have
20118 changed in ways we don't handle properly so just punt. */
20119 complaint (_("unsupported version in .debug_line section"));
20122 if (lh
->version
>= 5)
20124 gdb_byte segment_selector_size
;
20126 /* Skip address size. */
20127 read_1_byte (abfd
, line_ptr
);
20130 segment_selector_size
= read_1_byte (abfd
, line_ptr
);
20132 if (segment_selector_size
!= 0)
20134 complaint (_("unsupported segment selector size %u "
20135 "in .debug_line section"),
20136 segment_selector_size
);
20140 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
20141 line_ptr
+= offset_size
;
20142 lh
->statement_program_start
= line_ptr
+ lh
->header_length
;
20143 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
20145 if (lh
->version
>= 4)
20147 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
20151 lh
->maximum_ops_per_instruction
= 1;
20153 if (lh
->maximum_ops_per_instruction
== 0)
20155 lh
->maximum_ops_per_instruction
= 1;
20156 complaint (_("invalid maximum_ops_per_instruction "
20157 "in `.debug_line' section"));
20160 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
20162 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
20164 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
20166 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
20168 lh
->standard_opcode_lengths
.reset (new unsigned char[lh
->opcode_base
]);
20170 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
20171 for (i
= 1; i
< lh
->opcode_base
; ++i
)
20173 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
20177 if (lh
->version
>= 5)
20179 /* Read directory table. */
20180 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20182 [] (struct line_header
*header
, const char *name
,
20183 dir_index d_index
, unsigned int mod_time
,
20184 unsigned int length
)
20186 header
->add_include_dir (name
);
20189 /* Read file name table. */
20190 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20192 [] (struct line_header
*header
, const char *name
,
20193 dir_index d_index
, unsigned int mod_time
,
20194 unsigned int length
)
20196 header
->add_file_name (name
, d_index
, mod_time
, length
);
20201 /* Read directory table. */
20202 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20204 line_ptr
+= bytes_read
;
20205 lh
->add_include_dir (cur_dir
);
20207 line_ptr
+= bytes_read
;
20209 /* Read file name table. */
20210 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20212 unsigned int mod_time
, length
;
20215 line_ptr
+= bytes_read
;
20216 d_index
= (dir_index
) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20217 line_ptr
+= bytes_read
;
20218 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20219 line_ptr
+= bytes_read
;
20220 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20221 line_ptr
+= bytes_read
;
20223 lh
->add_file_name (cur_file
, d_index
, mod_time
, length
);
20225 line_ptr
+= bytes_read
;
20228 if (line_ptr
> (section
->buffer
+ section
->size
))
20229 complaint (_("line number info header doesn't "
20230 "fit in `.debug_line' section"));
20235 /* Subroutine of dwarf_decode_lines to simplify it.
20236 Return the file name of the psymtab for the given file_entry.
20237 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20238 If space for the result is malloc'd, *NAME_HOLDER will be set.
20239 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
20241 static const char *
20242 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
20243 const dwarf2_psymtab
*pst
,
20244 const char *comp_dir
,
20245 gdb::unique_xmalloc_ptr
<char> *name_holder
)
20247 const char *include_name
= fe
.name
;
20248 const char *include_name_to_compare
= include_name
;
20249 const char *pst_filename
;
20252 const char *dir_name
= fe
.include_dir (lh
);
20254 gdb::unique_xmalloc_ptr
<char> hold_compare
;
20255 if (!IS_ABSOLUTE_PATH (include_name
)
20256 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
20258 /* Avoid creating a duplicate psymtab for PST.
20259 We do this by comparing INCLUDE_NAME and PST_FILENAME.
20260 Before we do the comparison, however, we need to account
20261 for DIR_NAME and COMP_DIR.
20262 First prepend dir_name (if non-NULL). If we still don't
20263 have an absolute path prepend comp_dir (if non-NULL).
20264 However, the directory we record in the include-file's
20265 psymtab does not contain COMP_DIR (to match the
20266 corresponding symtab(s)).
20271 bash$ gcc -g ./hello.c
20272 include_name = "hello.c"
20274 DW_AT_comp_dir = comp_dir = "/tmp"
20275 DW_AT_name = "./hello.c"
20279 if (dir_name
!= NULL
)
20281 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
20282 include_name
, (char *) NULL
));
20283 include_name
= name_holder
->get ();
20284 include_name_to_compare
= include_name
;
20286 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
20288 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
20289 include_name
, (char *) NULL
));
20290 include_name_to_compare
= hold_compare
.get ();
20294 pst_filename
= pst
->filename
;
20295 gdb::unique_xmalloc_ptr
<char> copied_name
;
20296 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
20298 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
20299 pst_filename
, (char *) NULL
));
20300 pst_filename
= copied_name
.get ();
20303 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
20307 return include_name
;
20310 /* State machine to track the state of the line number program. */
20312 class lnp_state_machine
20315 /* Initialize a machine state for the start of a line number
20317 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
20318 bool record_lines_p
);
20320 file_entry
*current_file ()
20322 /* lh->file_names is 0-based, but the file name numbers in the
20323 statement program are 1-based. */
20324 return m_line_header
->file_name_at (m_file
);
20327 /* Record the line in the state machine. END_SEQUENCE is true if
20328 we're processing the end of a sequence. */
20329 void record_line (bool end_sequence
);
20331 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
20332 nop-out rest of the lines in this sequence. */
20333 void check_line_address (struct dwarf2_cu
*cu
,
20334 const gdb_byte
*line_ptr
,
20335 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
20337 void handle_set_discriminator (unsigned int discriminator
)
20339 m_discriminator
= discriminator
;
20340 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
20343 /* Handle DW_LNE_set_address. */
20344 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
20347 address
+= baseaddr
;
20348 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
20351 /* Handle DW_LNS_advance_pc. */
20352 void handle_advance_pc (CORE_ADDR adjust
);
20354 /* Handle a special opcode. */
20355 void handle_special_opcode (unsigned char op_code
);
20357 /* Handle DW_LNS_advance_line. */
20358 void handle_advance_line (int line_delta
)
20360 advance_line (line_delta
);
20363 /* Handle DW_LNS_set_file. */
20364 void handle_set_file (file_name_index file
);
20366 /* Handle DW_LNS_negate_stmt. */
20367 void handle_negate_stmt ()
20369 m_is_stmt
= !m_is_stmt
;
20372 /* Handle DW_LNS_const_add_pc. */
20373 void handle_const_add_pc ();
20375 /* Handle DW_LNS_fixed_advance_pc. */
20376 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
20378 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20382 /* Handle DW_LNS_copy. */
20383 void handle_copy ()
20385 record_line (false);
20386 m_discriminator
= 0;
20389 /* Handle DW_LNE_end_sequence. */
20390 void handle_end_sequence ()
20392 m_currently_recording_lines
= true;
20396 /* Advance the line by LINE_DELTA. */
20397 void advance_line (int line_delta
)
20399 m_line
+= line_delta
;
20401 if (line_delta
!= 0)
20402 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20405 struct dwarf2_cu
*m_cu
;
20407 gdbarch
*m_gdbarch
;
20409 /* True if we're recording lines.
20410 Otherwise we're building partial symtabs and are just interested in
20411 finding include files mentioned by the line number program. */
20412 bool m_record_lines_p
;
20414 /* The line number header. */
20415 line_header
*m_line_header
;
20417 /* These are part of the standard DWARF line number state machine,
20418 and initialized according to the DWARF spec. */
20420 unsigned char m_op_index
= 0;
20421 /* The line table index of the current file. */
20422 file_name_index m_file
= 1;
20423 unsigned int m_line
= 1;
20425 /* These are initialized in the constructor. */
20427 CORE_ADDR m_address
;
20429 unsigned int m_discriminator
;
20431 /* Additional bits of state we need to track. */
20433 /* The last file that we called dwarf2_start_subfile for.
20434 This is only used for TLLs. */
20435 unsigned int m_last_file
= 0;
20436 /* The last file a line number was recorded for. */
20437 struct subfile
*m_last_subfile
= NULL
;
20439 /* When true, record the lines we decode. */
20440 bool m_currently_recording_lines
= false;
20442 /* The last line number that was recorded, used to coalesce
20443 consecutive entries for the same line. This can happen, for
20444 example, when discriminators are present. PR 17276. */
20445 unsigned int m_last_line
= 0;
20446 bool m_line_has_non_zero_discriminator
= false;
20450 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
20452 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
20453 / m_line_header
->maximum_ops_per_instruction
)
20454 * m_line_header
->minimum_instruction_length
);
20455 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20456 m_op_index
= ((m_op_index
+ adjust
)
20457 % m_line_header
->maximum_ops_per_instruction
);
20461 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
20463 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
20464 CORE_ADDR addr_adj
= (((m_op_index
20465 + (adj_opcode
/ m_line_header
->line_range
))
20466 / m_line_header
->maximum_ops_per_instruction
)
20467 * m_line_header
->minimum_instruction_length
);
20468 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20469 m_op_index
= ((m_op_index
+ (adj_opcode
/ m_line_header
->line_range
))
20470 % m_line_header
->maximum_ops_per_instruction
);
20472 int line_delta
= (m_line_header
->line_base
20473 + (adj_opcode
% m_line_header
->line_range
));
20474 advance_line (line_delta
);
20475 record_line (false);
20476 m_discriminator
= 0;
20480 lnp_state_machine::handle_set_file (file_name_index file
)
20484 const file_entry
*fe
= current_file ();
20486 dwarf2_debug_line_missing_file_complaint ();
20487 else if (m_record_lines_p
)
20489 const char *dir
= fe
->include_dir (m_line_header
);
20491 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20492 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20493 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
20498 lnp_state_machine::handle_const_add_pc ()
20501 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
20504 = (((m_op_index
+ adjust
)
20505 / m_line_header
->maximum_ops_per_instruction
)
20506 * m_line_header
->minimum_instruction_length
);
20508 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20509 m_op_index
= ((m_op_index
+ adjust
)
20510 % m_line_header
->maximum_ops_per_instruction
);
20513 /* Return non-zero if we should add LINE to the line number table.
20514 LINE is the line to add, LAST_LINE is the last line that was added,
20515 LAST_SUBFILE is the subfile for LAST_LINE.
20516 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
20517 had a non-zero discriminator.
20519 We have to be careful in the presence of discriminators.
20520 E.g., for this line:
20522 for (i = 0; i < 100000; i++);
20524 clang can emit four line number entries for that one line,
20525 each with a different discriminator.
20526 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
20528 However, we want gdb to coalesce all four entries into one.
20529 Otherwise the user could stepi into the middle of the line and
20530 gdb would get confused about whether the pc really was in the
20531 middle of the line.
20533 Things are further complicated by the fact that two consecutive
20534 line number entries for the same line is a heuristic used by gcc
20535 to denote the end of the prologue. So we can't just discard duplicate
20536 entries, we have to be selective about it. The heuristic we use is
20537 that we only collapse consecutive entries for the same line if at least
20538 one of those entries has a non-zero discriminator. PR 17276.
20540 Note: Addresses in the line number state machine can never go backwards
20541 within one sequence, thus this coalescing is ok. */
20544 dwarf_record_line_p (struct dwarf2_cu
*cu
,
20545 unsigned int line
, unsigned int last_line
,
20546 int line_has_non_zero_discriminator
,
20547 struct subfile
*last_subfile
)
20549 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
20551 if (line
!= last_line
)
20553 /* Same line for the same file that we've seen already.
20554 As a last check, for pr 17276, only record the line if the line
20555 has never had a non-zero discriminator. */
20556 if (!line_has_non_zero_discriminator
)
20561 /* Use the CU's builder to record line number LINE beginning at
20562 address ADDRESS in the line table of subfile SUBFILE. */
20565 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20566 unsigned int line
, CORE_ADDR address
,
20567 struct dwarf2_cu
*cu
)
20569 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
20571 if (dwarf_line_debug
)
20573 fprintf_unfiltered (gdb_stdlog
,
20574 "Recording line %u, file %s, address %s\n",
20575 line
, lbasename (subfile
->name
),
20576 paddress (gdbarch
, address
));
20580 cu
->get_builder ()->record_line (subfile
, line
, addr
);
20583 /* Subroutine of dwarf_decode_lines_1 to simplify it.
20584 Mark the end of a set of line number records.
20585 The arguments are the same as for dwarf_record_line_1.
20586 If SUBFILE is NULL the request is ignored. */
20589 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20590 CORE_ADDR address
, struct dwarf2_cu
*cu
)
20592 if (subfile
== NULL
)
20595 if (dwarf_line_debug
)
20597 fprintf_unfiltered (gdb_stdlog
,
20598 "Finishing current line, file %s, address %s\n",
20599 lbasename (subfile
->name
),
20600 paddress (gdbarch
, address
));
20603 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, cu
);
20607 lnp_state_machine::record_line (bool end_sequence
)
20609 if (dwarf_line_debug
)
20611 fprintf_unfiltered (gdb_stdlog
,
20612 "Processing actual line %u: file %u,"
20613 " address %s, is_stmt %u, discrim %u%s\n",
20615 paddress (m_gdbarch
, m_address
),
20616 m_is_stmt
, m_discriminator
,
20617 (end_sequence
? "\t(end sequence)" : ""));
20620 file_entry
*fe
= current_file ();
20623 dwarf2_debug_line_missing_file_complaint ();
20624 /* For now we ignore lines not starting on an instruction boundary.
20625 But not when processing end_sequence for compatibility with the
20626 previous version of the code. */
20627 else if (m_op_index
== 0 || end_sequence
)
20629 fe
->included_p
= 1;
20630 if (m_record_lines_p
20631 && (producer_is_codewarrior (m_cu
) || m_is_stmt
|| end_sequence
))
20633 if (m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ()
20636 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
20637 m_currently_recording_lines
? m_cu
: nullptr);
20642 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
20643 m_line_has_non_zero_discriminator
,
20646 buildsym_compunit
*builder
= m_cu
->get_builder ();
20647 dwarf_record_line_1 (m_gdbarch
,
20648 builder
->get_current_subfile (),
20650 m_currently_recording_lines
? m_cu
: nullptr);
20652 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20653 m_last_line
= m_line
;
20659 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
20660 line_header
*lh
, bool record_lines_p
)
20664 m_record_lines_p
= record_lines_p
;
20665 m_line_header
= lh
;
20667 m_currently_recording_lines
= true;
20669 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
20670 was a line entry for it so that the backend has a chance to adjust it
20671 and also record it in case it needs it. This is currently used by MIPS
20672 code, cf. `mips_adjust_dwarf2_line'. */
20673 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
20674 m_is_stmt
= lh
->default_is_stmt
;
20675 m_discriminator
= 0;
20679 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
20680 const gdb_byte
*line_ptr
,
20681 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
20683 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
20684 the pc range of the CU. However, we restrict the test to only ADDRESS
20685 values of zero to preserve GDB's previous behaviour which is to handle
20686 the specific case of a function being GC'd by the linker. */
20688 if (address
== 0 && address
< unrelocated_lowpc
)
20690 /* This line table is for a function which has been
20691 GCd by the linker. Ignore it. PR gdb/12528 */
20693 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20694 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
20696 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
20697 line_offset
, objfile_name (objfile
));
20698 m_currently_recording_lines
= false;
20699 /* Note: m_currently_recording_lines is left as false until we see
20700 DW_LNE_end_sequence. */
20704 /* Subroutine of dwarf_decode_lines to simplify it.
20705 Process the line number information in LH.
20706 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
20707 program in order to set included_p for every referenced header. */
20710 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
20711 const int decode_for_pst_p
, CORE_ADDR lowpc
)
20713 const gdb_byte
*line_ptr
, *extended_end
;
20714 const gdb_byte
*line_end
;
20715 unsigned int bytes_read
, extended_len
;
20716 unsigned char op_code
, extended_op
;
20717 CORE_ADDR baseaddr
;
20718 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20719 bfd
*abfd
= objfile
->obfd
;
20720 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
20721 /* True if we're recording line info (as opposed to building partial
20722 symtabs and just interested in finding include files mentioned by
20723 the line number program). */
20724 bool record_lines_p
= !decode_for_pst_p
;
20726 baseaddr
= objfile
->text_section_offset ();
20728 line_ptr
= lh
->statement_program_start
;
20729 line_end
= lh
->statement_program_end
;
20731 /* Read the statement sequences until there's nothing left. */
20732 while (line_ptr
< line_end
)
20734 /* The DWARF line number program state machine. Reset the state
20735 machine at the start of each sequence. */
20736 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
20737 bool end_sequence
= false;
20739 if (record_lines_p
)
20741 /* Start a subfile for the current file of the state
20743 const file_entry
*fe
= state_machine
.current_file ();
20746 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
20749 /* Decode the table. */
20750 while (line_ptr
< line_end
&& !end_sequence
)
20752 op_code
= read_1_byte (abfd
, line_ptr
);
20755 if (op_code
>= lh
->opcode_base
)
20757 /* Special opcode. */
20758 state_machine
.handle_special_opcode (op_code
);
20760 else switch (op_code
)
20762 case DW_LNS_extended_op
:
20763 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
20765 line_ptr
+= bytes_read
;
20766 extended_end
= line_ptr
+ extended_len
;
20767 extended_op
= read_1_byte (abfd
, line_ptr
);
20769 switch (extended_op
)
20771 case DW_LNE_end_sequence
:
20772 state_machine
.handle_end_sequence ();
20773 end_sequence
= true;
20775 case DW_LNE_set_address
:
20778 = read_address (abfd
, line_ptr
, cu
, &bytes_read
);
20779 line_ptr
+= bytes_read
;
20781 state_machine
.check_line_address (cu
, line_ptr
,
20782 lowpc
- baseaddr
, address
);
20783 state_machine
.handle_set_address (baseaddr
, address
);
20786 case DW_LNE_define_file
:
20788 const char *cur_file
;
20789 unsigned int mod_time
, length
;
20792 cur_file
= read_direct_string (abfd
, line_ptr
,
20794 line_ptr
+= bytes_read
;
20795 dindex
= (dir_index
)
20796 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20797 line_ptr
+= bytes_read
;
20799 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20800 line_ptr
+= bytes_read
;
20802 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20803 line_ptr
+= bytes_read
;
20804 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
20807 case DW_LNE_set_discriminator
:
20809 /* The discriminator is not interesting to the
20810 debugger; just ignore it. We still need to
20811 check its value though:
20812 if there are consecutive entries for the same
20813 (non-prologue) line we want to coalesce them.
20816 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20817 line_ptr
+= bytes_read
;
20819 state_machine
.handle_set_discriminator (discr
);
20823 complaint (_("mangled .debug_line section"));
20826 /* Make sure that we parsed the extended op correctly. If e.g.
20827 we expected a different address size than the producer used,
20828 we may have read the wrong number of bytes. */
20829 if (line_ptr
!= extended_end
)
20831 complaint (_("mangled .debug_line section"));
20836 state_machine
.handle_copy ();
20838 case DW_LNS_advance_pc
:
20841 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20842 line_ptr
+= bytes_read
;
20844 state_machine
.handle_advance_pc (adjust
);
20847 case DW_LNS_advance_line
:
20850 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
20851 line_ptr
+= bytes_read
;
20853 state_machine
.handle_advance_line (line_delta
);
20856 case DW_LNS_set_file
:
20858 file_name_index file
20859 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
20861 line_ptr
+= bytes_read
;
20863 state_machine
.handle_set_file (file
);
20866 case DW_LNS_set_column
:
20867 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20868 line_ptr
+= bytes_read
;
20870 case DW_LNS_negate_stmt
:
20871 state_machine
.handle_negate_stmt ();
20873 case DW_LNS_set_basic_block
:
20875 /* Add to the address register of the state machine the
20876 address increment value corresponding to special opcode
20877 255. I.e., this value is scaled by the minimum
20878 instruction length since special opcode 255 would have
20879 scaled the increment. */
20880 case DW_LNS_const_add_pc
:
20881 state_machine
.handle_const_add_pc ();
20883 case DW_LNS_fixed_advance_pc
:
20885 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
20888 state_machine
.handle_fixed_advance_pc (addr_adj
);
20893 /* Unknown standard opcode, ignore it. */
20896 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
20898 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20899 line_ptr
+= bytes_read
;
20906 dwarf2_debug_line_missing_end_sequence_complaint ();
20908 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
20909 in which case we still finish recording the last line). */
20910 state_machine
.record_line (true);
20914 /* Decode the Line Number Program (LNP) for the given line_header
20915 structure and CU. The actual information extracted and the type
20916 of structures created from the LNP depends on the value of PST.
20918 1. If PST is NULL, then this procedure uses the data from the program
20919 to create all necessary symbol tables, and their linetables.
20921 2. If PST is not NULL, this procedure reads the program to determine
20922 the list of files included by the unit represented by PST, and
20923 builds all the associated partial symbol tables.
20925 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20926 It is used for relative paths in the line table.
20927 NOTE: When processing partial symtabs (pst != NULL),
20928 comp_dir == pst->dirname.
20930 NOTE: It is important that psymtabs have the same file name (via strcmp)
20931 as the corresponding symtab. Since COMP_DIR is not used in the name of the
20932 symtab we don't use it in the name of the psymtabs we create.
20933 E.g. expand_line_sal requires this when finding psymtabs to expand.
20934 A good testcase for this is mb-inline.exp.
20936 LOWPC is the lowest address in CU (or 0 if not known).
20938 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
20939 for its PC<->lines mapping information. Otherwise only the filename
20940 table is read in. */
20943 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
20944 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
20945 CORE_ADDR lowpc
, int decode_mapping
)
20947 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20948 const int decode_for_pst_p
= (pst
!= NULL
);
20950 if (decode_mapping
)
20951 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
20953 if (decode_for_pst_p
)
20955 /* Now that we're done scanning the Line Header Program, we can
20956 create the psymtab of each included file. */
20957 for (auto &file_entry
: lh
->file_names ())
20958 if (file_entry
.included_p
== 1)
20960 gdb::unique_xmalloc_ptr
<char> name_holder
;
20961 const char *include_name
=
20962 psymtab_include_file_name (lh
, file_entry
, pst
,
20963 comp_dir
, &name_holder
);
20964 if (include_name
!= NULL
)
20965 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
20970 /* Make sure a symtab is created for every file, even files
20971 which contain only variables (i.e. no code with associated
20973 buildsym_compunit
*builder
= cu
->get_builder ();
20974 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
20976 for (auto &fe
: lh
->file_names ())
20978 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
20979 if (builder
->get_current_subfile ()->symtab
== NULL
)
20981 builder
->get_current_subfile ()->symtab
20982 = allocate_symtab (cust
,
20983 builder
->get_current_subfile ()->name
);
20985 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
20990 /* Start a subfile for DWARF. FILENAME is the name of the file and
20991 DIRNAME the name of the source directory which contains FILENAME
20992 or NULL if not known.
20993 This routine tries to keep line numbers from identical absolute and
20994 relative file names in a common subfile.
20996 Using the `list' example from the GDB testsuite, which resides in
20997 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
20998 of /srcdir/list0.c yields the following debugging information for list0.c:
21000 DW_AT_name: /srcdir/list0.c
21001 DW_AT_comp_dir: /compdir
21002 files.files[0].name: list0.h
21003 files.files[0].dir: /srcdir
21004 files.files[1].name: list0.c
21005 files.files[1].dir: /srcdir
21007 The line number information for list0.c has to end up in a single
21008 subfile, so that `break /srcdir/list0.c:1' works as expected.
21009 start_subfile will ensure that this happens provided that we pass the
21010 concatenation of files.files[1].dir and files.files[1].name as the
21014 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
21015 const char *dirname
)
21017 gdb::unique_xmalloc_ptr
<char> copy
;
21019 /* In order not to lose the line information directory,
21020 we concatenate it to the filename when it makes sense.
21021 Note that the Dwarf3 standard says (speaking of filenames in line
21022 information): ``The directory index is ignored for file names
21023 that represent full path names''. Thus ignoring dirname in the
21024 `else' branch below isn't an issue. */
21026 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
21028 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
21029 filename
= copy
.get ();
21032 cu
->get_builder ()->start_subfile (filename
);
21035 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
21036 buildsym_compunit constructor. */
21038 struct compunit_symtab
*
21039 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
21042 gdb_assert (m_builder
== nullptr);
21044 m_builder
.reset (new struct buildsym_compunit
21045 (per_cu
->dwarf2_per_objfile
->objfile
,
21046 name
, comp_dir
, language
, low_pc
));
21048 list_in_scope
= get_builder ()->get_file_symbols ();
21050 get_builder ()->record_debugformat ("DWARF 2");
21051 get_builder ()->record_producer (producer
);
21053 processing_has_namespace_info
= false;
21055 return get_builder ()->get_compunit_symtab ();
21059 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
21060 struct dwarf2_cu
*cu
)
21062 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21063 struct comp_unit_head
*cu_header
= &cu
->header
;
21065 /* NOTE drow/2003-01-30: There used to be a comment and some special
21066 code here to turn a symbol with DW_AT_external and a
21067 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
21068 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
21069 with some versions of binutils) where shared libraries could have
21070 relocations against symbols in their debug information - the
21071 minimal symbol would have the right address, but the debug info
21072 would not. It's no longer necessary, because we will explicitly
21073 apply relocations when we read in the debug information now. */
21075 /* A DW_AT_location attribute with no contents indicates that a
21076 variable has been optimized away. */
21077 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0)
21079 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21083 /* Handle one degenerate form of location expression specially, to
21084 preserve GDB's previous behavior when section offsets are
21085 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
21086 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
21088 if (attr
->form_is_block ()
21089 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
21090 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
21091 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
21092 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
21093 && (DW_BLOCK (attr
)->size
21094 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
21096 unsigned int dummy
;
21098 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
21099 SET_SYMBOL_VALUE_ADDRESS (sym
,
21100 read_address (objfile
->obfd
,
21101 DW_BLOCK (attr
)->data
+ 1,
21104 SET_SYMBOL_VALUE_ADDRESS
21105 (sym
, read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1,
21107 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
21108 fixup_symbol_section (sym
, objfile
);
21109 SET_SYMBOL_VALUE_ADDRESS
21111 SYMBOL_VALUE_ADDRESS (sym
)
21112 + objfile
->section_offsets
[SYMBOL_SECTION (sym
)]);
21116 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
21117 expression evaluator, and use LOC_COMPUTED only when necessary
21118 (i.e. when the value of a register or memory location is
21119 referenced, or a thread-local block, etc.). Then again, it might
21120 not be worthwhile. I'm assuming that it isn't unless performance
21121 or memory numbers show me otherwise. */
21123 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
21125 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
21126 cu
->has_loclist
= true;
21129 /* Given a pointer to a DWARF information entry, figure out if we need
21130 to make a symbol table entry for it, and if so, create a new entry
21131 and return a pointer to it.
21132 If TYPE is NULL, determine symbol type from the die, otherwise
21133 used the passed type.
21134 If SPACE is not NULL, use it to hold the new symbol. If it is
21135 NULL, allocate a new symbol on the objfile's obstack. */
21137 static struct symbol
*
21138 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
21139 struct symbol
*space
)
21141 struct dwarf2_per_objfile
*dwarf2_per_objfile
21142 = cu
->per_cu
->dwarf2_per_objfile
;
21143 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21144 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21145 struct symbol
*sym
= NULL
;
21147 struct attribute
*attr
= NULL
;
21148 struct attribute
*attr2
= NULL
;
21149 CORE_ADDR baseaddr
;
21150 struct pending
**list_to_add
= NULL
;
21152 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
21154 baseaddr
= objfile
->text_section_offset ();
21156 name
= dwarf2_name (die
, cu
);
21159 const char *linkagename
;
21160 int suppress_add
= 0;
21165 sym
= allocate_symbol (objfile
);
21166 OBJSTAT (objfile
, n_syms
++);
21168 /* Cache this symbol's name and the name's demangled form (if any). */
21169 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
21170 linkagename
= dwarf2_physname (name
, die
, cu
);
21171 sym
->compute_and_set_names (linkagename
, false, objfile
->per_bfd
);
21173 /* Fortran does not have mangling standard and the mangling does differ
21174 between gfortran, iFort etc. */
21175 if (cu
->language
== language_fortran
21176 && symbol_get_demangled_name (sym
) == NULL
)
21177 symbol_set_demangled_name (sym
,
21178 dwarf2_full_name (name
, die
, cu
),
21181 /* Default assumptions.
21182 Use the passed type or decode it from the die. */
21183 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21184 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21186 SYMBOL_TYPE (sym
) = type
;
21188 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
21189 attr
= dwarf2_attr (die
,
21190 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
21192 if (attr
!= nullptr)
21194 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
21197 attr
= dwarf2_attr (die
,
21198 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
21200 if (attr
!= nullptr)
21202 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
21203 struct file_entry
*fe
;
21205 if (cu
->line_header
!= NULL
)
21206 fe
= cu
->line_header
->file_name_at (file_index
);
21211 complaint (_("file index out of range"));
21213 symbol_set_symtab (sym
, fe
->symtab
);
21219 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
21220 if (attr
!= nullptr)
21224 addr
= attr
->value_as_address ();
21225 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
21226 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
21228 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
21229 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
21230 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
21231 add_symbol_to_list (sym
, cu
->list_in_scope
);
21233 case DW_TAG_subprogram
:
21234 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21236 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21237 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21238 if ((attr2
&& (DW_UNSND (attr2
) != 0))
21239 || cu
->language
== language_ada
21240 || cu
->language
== language_fortran
)
21242 /* Subprograms marked external are stored as a global symbol.
21243 Ada and Fortran subprograms, whether marked external or
21244 not, are always stored as a global symbol, because we want
21245 to be able to access them globally. For instance, we want
21246 to be able to break on a nested subprogram without having
21247 to specify the context. */
21248 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21252 list_to_add
= cu
->list_in_scope
;
21255 case DW_TAG_inlined_subroutine
:
21256 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21258 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21259 SYMBOL_INLINED (sym
) = 1;
21260 list_to_add
= cu
->list_in_scope
;
21262 case DW_TAG_template_value_param
:
21264 /* Fall through. */
21265 case DW_TAG_constant
:
21266 case DW_TAG_variable
:
21267 case DW_TAG_member
:
21268 /* Compilation with minimal debug info may result in
21269 variables with missing type entries. Change the
21270 misleading `void' type to something sensible. */
21271 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
21272 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
21274 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21275 /* In the case of DW_TAG_member, we should only be called for
21276 static const members. */
21277 if (die
->tag
== DW_TAG_member
)
21279 /* dwarf2_add_field uses die_is_declaration,
21280 so we do the same. */
21281 gdb_assert (die_is_declaration (die
, cu
));
21284 if (attr
!= nullptr)
21286 dwarf2_const_value (attr
, sym
, cu
);
21287 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21290 if (attr2
&& (DW_UNSND (attr2
) != 0))
21291 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21293 list_to_add
= cu
->list_in_scope
;
21297 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21298 if (attr
!= nullptr)
21300 var_decode_location (attr
, sym
, cu
);
21301 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21303 /* Fortran explicitly imports any global symbols to the local
21304 scope by DW_TAG_common_block. */
21305 if (cu
->language
== language_fortran
&& die
->parent
21306 && die
->parent
->tag
== DW_TAG_common_block
)
21309 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21310 && SYMBOL_VALUE_ADDRESS (sym
) == 0
21311 && !dwarf2_per_objfile
->has_section_at_zero
)
21313 /* When a static variable is eliminated by the linker,
21314 the corresponding debug information is not stripped
21315 out, but the variable address is set to null;
21316 do not add such variables into symbol table. */
21318 else if (attr2
&& (DW_UNSND (attr2
) != 0))
21320 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21321 && (objfile
->flags
& OBJF_MAINLINE
) == 0
21322 && dwarf2_per_objfile
->can_copy
)
21324 /* A global static variable might be subject to
21325 copy relocation. We first check for a local
21326 minsym, though, because maybe the symbol was
21327 marked hidden, in which case this would not
21329 bound_minimal_symbol found
21330 = (lookup_minimal_symbol_linkage
21331 (sym
->linkage_name (), objfile
));
21332 if (found
.minsym
!= nullptr)
21333 sym
->maybe_copied
= 1;
21336 /* A variable with DW_AT_external is never static,
21337 but it may be block-scoped. */
21339 = ((cu
->list_in_scope
21340 == cu
->get_builder ()->get_file_symbols ())
21341 ? cu
->get_builder ()->get_global_symbols ()
21342 : cu
->list_in_scope
);
21345 list_to_add
= cu
->list_in_scope
;
21349 /* We do not know the address of this symbol.
21350 If it is an external symbol and we have type information
21351 for it, enter the symbol as a LOC_UNRESOLVED symbol.
21352 The address of the variable will then be determined from
21353 the minimal symbol table whenever the variable is
21355 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21357 /* Fortran explicitly imports any global symbols to the local
21358 scope by DW_TAG_common_block. */
21359 if (cu
->language
== language_fortran
&& die
->parent
21360 && die
->parent
->tag
== DW_TAG_common_block
)
21362 /* SYMBOL_CLASS doesn't matter here because
21363 read_common_block is going to reset it. */
21365 list_to_add
= cu
->list_in_scope
;
21367 else if (attr2
&& (DW_UNSND (attr2
) != 0)
21368 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
21370 /* A variable with DW_AT_external is never static, but it
21371 may be block-scoped. */
21373 = ((cu
->list_in_scope
21374 == cu
->get_builder ()->get_file_symbols ())
21375 ? cu
->get_builder ()->get_global_symbols ()
21376 : cu
->list_in_scope
);
21378 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21380 else if (!die_is_declaration (die
, cu
))
21382 /* Use the default LOC_OPTIMIZED_OUT class. */
21383 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
21385 list_to_add
= cu
->list_in_scope
;
21389 case DW_TAG_formal_parameter
:
21391 /* If we are inside a function, mark this as an argument. If
21392 not, we might be looking at an argument to an inlined function
21393 when we do not have enough information to show inlined frames;
21394 pretend it's a local variable in that case so that the user can
21396 struct context_stack
*curr
21397 = cu
->get_builder ()->get_current_context_stack ();
21398 if (curr
!= nullptr && curr
->name
!= nullptr)
21399 SYMBOL_IS_ARGUMENT (sym
) = 1;
21400 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21401 if (attr
!= nullptr)
21403 var_decode_location (attr
, sym
, cu
);
21405 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21406 if (attr
!= nullptr)
21408 dwarf2_const_value (attr
, sym
, cu
);
21411 list_to_add
= cu
->list_in_scope
;
21414 case DW_TAG_unspecified_parameters
:
21415 /* From varargs functions; gdb doesn't seem to have any
21416 interest in this information, so just ignore it for now.
21419 case DW_TAG_template_type_param
:
21421 /* Fall through. */
21422 case DW_TAG_class_type
:
21423 case DW_TAG_interface_type
:
21424 case DW_TAG_structure_type
:
21425 case DW_TAG_union_type
:
21426 case DW_TAG_set_type
:
21427 case DW_TAG_enumeration_type
:
21428 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21429 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
21432 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
21433 really ever be static objects: otherwise, if you try
21434 to, say, break of a class's method and you're in a file
21435 which doesn't mention that class, it won't work unless
21436 the check for all static symbols in lookup_symbol_aux
21437 saves you. See the OtherFileClass tests in
21438 gdb.c++/namespace.exp. */
21442 buildsym_compunit
*builder
= cu
->get_builder ();
21444 = (cu
->list_in_scope
== builder
->get_file_symbols ()
21445 && cu
->language
== language_cplus
21446 ? builder
->get_global_symbols ()
21447 : cu
->list_in_scope
);
21449 /* The semantics of C++ state that "struct foo {
21450 ... }" also defines a typedef for "foo". */
21451 if (cu
->language
== language_cplus
21452 || cu
->language
== language_ada
21453 || cu
->language
== language_d
21454 || cu
->language
== language_rust
)
21456 /* The symbol's name is already allocated along
21457 with this objfile, so we don't need to
21458 duplicate it for the type. */
21459 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
21460 TYPE_NAME (SYMBOL_TYPE (sym
)) = sym
->search_name ();
21465 case DW_TAG_typedef
:
21466 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21467 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21468 list_to_add
= cu
->list_in_scope
;
21470 case DW_TAG_base_type
:
21471 case DW_TAG_subrange_type
:
21472 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21473 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21474 list_to_add
= cu
->list_in_scope
;
21476 case DW_TAG_enumerator
:
21477 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21478 if (attr
!= nullptr)
21480 dwarf2_const_value (attr
, sym
, cu
);
21483 /* NOTE: carlton/2003-11-10: See comment above in the
21484 DW_TAG_class_type, etc. block. */
21487 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
21488 && cu
->language
== language_cplus
21489 ? cu
->get_builder ()->get_global_symbols ()
21490 : cu
->list_in_scope
);
21493 case DW_TAG_imported_declaration
:
21494 case DW_TAG_namespace
:
21495 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21496 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21498 case DW_TAG_module
:
21499 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21500 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
21501 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21503 case DW_TAG_common_block
:
21504 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
21505 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
21506 add_symbol_to_list (sym
, cu
->list_in_scope
);
21509 /* Not a tag we recognize. Hopefully we aren't processing
21510 trash data, but since we must specifically ignore things
21511 we don't recognize, there is nothing else we should do at
21513 complaint (_("unsupported tag: '%s'"),
21514 dwarf_tag_name (die
->tag
));
21520 sym
->hash_next
= objfile
->template_symbols
;
21521 objfile
->template_symbols
= sym
;
21522 list_to_add
= NULL
;
21525 if (list_to_add
!= NULL
)
21526 add_symbol_to_list (sym
, list_to_add
);
21528 /* For the benefit of old versions of GCC, check for anonymous
21529 namespaces based on the demangled name. */
21530 if (!cu
->processing_has_namespace_info
21531 && cu
->language
== language_cplus
)
21532 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
21537 /* Given an attr with a DW_FORM_dataN value in host byte order,
21538 zero-extend it as appropriate for the symbol's type. The DWARF
21539 standard (v4) is not entirely clear about the meaning of using
21540 DW_FORM_dataN for a constant with a signed type, where the type is
21541 wider than the data. The conclusion of a discussion on the DWARF
21542 list was that this is unspecified. We choose to always zero-extend
21543 because that is the interpretation long in use by GCC. */
21546 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
21547 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
21549 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21550 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
21551 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
21552 LONGEST l
= DW_UNSND (attr
);
21554 if (bits
< sizeof (*value
) * 8)
21556 l
&= ((LONGEST
) 1 << bits
) - 1;
21559 else if (bits
== sizeof (*value
) * 8)
21563 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
21564 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
21571 /* Read a constant value from an attribute. Either set *VALUE, or if
21572 the value does not fit in *VALUE, set *BYTES - either already
21573 allocated on the objfile obstack, or newly allocated on OBSTACK,
21574 or, set *BATON, if we translated the constant to a location
21578 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
21579 const char *name
, struct obstack
*obstack
,
21580 struct dwarf2_cu
*cu
,
21581 LONGEST
*value
, const gdb_byte
**bytes
,
21582 struct dwarf2_locexpr_baton
**baton
)
21584 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21585 struct comp_unit_head
*cu_header
= &cu
->header
;
21586 struct dwarf_block
*blk
;
21587 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
21588 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
21594 switch (attr
->form
)
21597 case DW_FORM_addrx
:
21598 case DW_FORM_GNU_addr_index
:
21602 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
21603 dwarf2_const_value_length_mismatch_complaint (name
,
21604 cu_header
->addr_size
,
21605 TYPE_LENGTH (type
));
21606 /* Symbols of this form are reasonably rare, so we just
21607 piggyback on the existing location code rather than writing
21608 a new implementation of symbol_computed_ops. */
21609 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
21610 (*baton
)->per_cu
= cu
->per_cu
;
21611 gdb_assert ((*baton
)->per_cu
);
21613 (*baton
)->size
= 2 + cu_header
->addr_size
;
21614 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
21615 (*baton
)->data
= data
;
21617 data
[0] = DW_OP_addr
;
21618 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
21619 byte_order
, DW_ADDR (attr
));
21620 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
21623 case DW_FORM_string
:
21626 case DW_FORM_GNU_str_index
:
21627 case DW_FORM_GNU_strp_alt
:
21628 /* DW_STRING is already allocated on the objfile obstack, point
21630 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
21632 case DW_FORM_block1
:
21633 case DW_FORM_block2
:
21634 case DW_FORM_block4
:
21635 case DW_FORM_block
:
21636 case DW_FORM_exprloc
:
21637 case DW_FORM_data16
:
21638 blk
= DW_BLOCK (attr
);
21639 if (TYPE_LENGTH (type
) != blk
->size
)
21640 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
21641 TYPE_LENGTH (type
));
21642 *bytes
= blk
->data
;
21645 /* The DW_AT_const_value attributes are supposed to carry the
21646 symbol's value "represented as it would be on the target
21647 architecture." By the time we get here, it's already been
21648 converted to host endianness, so we just need to sign- or
21649 zero-extend it as appropriate. */
21650 case DW_FORM_data1
:
21651 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
21653 case DW_FORM_data2
:
21654 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
21656 case DW_FORM_data4
:
21657 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
21659 case DW_FORM_data8
:
21660 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
21663 case DW_FORM_sdata
:
21664 case DW_FORM_implicit_const
:
21665 *value
= DW_SND (attr
);
21668 case DW_FORM_udata
:
21669 *value
= DW_UNSND (attr
);
21673 complaint (_("unsupported const value attribute form: '%s'"),
21674 dwarf_form_name (attr
->form
));
21681 /* Copy constant value from an attribute to a symbol. */
21684 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
21685 struct dwarf2_cu
*cu
)
21687 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21689 const gdb_byte
*bytes
;
21690 struct dwarf2_locexpr_baton
*baton
;
21692 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
21693 sym
->print_name (),
21694 &objfile
->objfile_obstack
, cu
,
21695 &value
, &bytes
, &baton
);
21699 SYMBOL_LOCATION_BATON (sym
) = baton
;
21700 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
21702 else if (bytes
!= NULL
)
21704 SYMBOL_VALUE_BYTES (sym
) = bytes
;
21705 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
21709 SYMBOL_VALUE (sym
) = value
;
21710 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
21714 /* Return the type of the die in question using its DW_AT_type attribute. */
21716 static struct type
*
21717 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21719 struct attribute
*type_attr
;
21721 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
21724 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21725 /* A missing DW_AT_type represents a void type. */
21726 return objfile_type (objfile
)->builtin_void
;
21729 return lookup_die_type (die
, type_attr
, cu
);
21732 /* True iff CU's producer generates GNAT Ada auxiliary information
21733 that allows to find parallel types through that information instead
21734 of having to do expensive parallel lookups by type name. */
21737 need_gnat_info (struct dwarf2_cu
*cu
)
21739 /* Assume that the Ada compiler was GNAT, which always produces
21740 the auxiliary information. */
21741 return (cu
->language
== language_ada
);
21744 /* Return the auxiliary type of the die in question using its
21745 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
21746 attribute is not present. */
21748 static struct type
*
21749 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21751 struct attribute
*type_attr
;
21753 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
21757 return lookup_die_type (die
, type_attr
, cu
);
21760 /* If DIE has a descriptive_type attribute, then set the TYPE's
21761 descriptive type accordingly. */
21764 set_descriptive_type (struct type
*type
, struct die_info
*die
,
21765 struct dwarf2_cu
*cu
)
21767 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
21769 if (descriptive_type
)
21771 ALLOCATE_GNAT_AUX_TYPE (type
);
21772 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
21776 /* Return the containing type of the die in question using its
21777 DW_AT_containing_type attribute. */
21779 static struct type
*
21780 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21782 struct attribute
*type_attr
;
21783 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21785 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
21787 error (_("Dwarf Error: Problem turning containing type into gdb type "
21788 "[in module %s]"), objfile_name (objfile
));
21790 return lookup_die_type (die
, type_attr
, cu
);
21793 /* Return an error marker type to use for the ill formed type in DIE/CU. */
21795 static struct type
*
21796 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
21798 struct dwarf2_per_objfile
*dwarf2_per_objfile
21799 = cu
->per_cu
->dwarf2_per_objfile
;
21800 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21803 std::string message
21804 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
21805 objfile_name (objfile
),
21806 sect_offset_str (cu
->header
.sect_off
),
21807 sect_offset_str (die
->sect_off
));
21808 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
21810 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
21813 /* Look up the type of DIE in CU using its type attribute ATTR.
21814 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
21815 DW_AT_containing_type.
21816 If there is no type substitute an error marker. */
21818 static struct type
*
21819 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
21820 struct dwarf2_cu
*cu
)
21822 struct dwarf2_per_objfile
*dwarf2_per_objfile
21823 = cu
->per_cu
->dwarf2_per_objfile
;
21824 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21825 struct type
*this_type
;
21827 gdb_assert (attr
->name
== DW_AT_type
21828 || attr
->name
== DW_AT_GNAT_descriptive_type
21829 || attr
->name
== DW_AT_containing_type
);
21831 /* First see if we have it cached. */
21833 if (attr
->form
== DW_FORM_GNU_ref_alt
)
21835 struct dwarf2_per_cu_data
*per_cu
;
21836 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
21838 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
21839 dwarf2_per_objfile
);
21840 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
21842 else if (attr
->form_is_ref ())
21844 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
21846 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
21848 else if (attr
->form
== DW_FORM_ref_sig8
)
21850 ULONGEST signature
= DW_SIGNATURE (attr
);
21852 return get_signatured_type (die
, signature
, cu
);
21856 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
21857 " at %s [in module %s]"),
21858 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
21859 objfile_name (objfile
));
21860 return build_error_marker_type (cu
, die
);
21863 /* If not cached we need to read it in. */
21865 if (this_type
== NULL
)
21867 struct die_info
*type_die
= NULL
;
21868 struct dwarf2_cu
*type_cu
= cu
;
21870 if (attr
->form_is_ref ())
21871 type_die
= follow_die_ref (die
, attr
, &type_cu
);
21872 if (type_die
== NULL
)
21873 return build_error_marker_type (cu
, die
);
21874 /* If we find the type now, it's probably because the type came
21875 from an inter-CU reference and the type's CU got expanded before
21877 this_type
= read_type_die (type_die
, type_cu
);
21880 /* If we still don't have a type use an error marker. */
21882 if (this_type
== NULL
)
21883 return build_error_marker_type (cu
, die
);
21888 /* Return the type in DIE, CU.
21889 Returns NULL for invalid types.
21891 This first does a lookup in die_type_hash,
21892 and only reads the die in if necessary.
21894 NOTE: This can be called when reading in partial or full symbols. */
21896 static struct type
*
21897 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
21899 struct type
*this_type
;
21901 this_type
= get_die_type (die
, cu
);
21905 return read_type_die_1 (die
, cu
);
21908 /* Read the type in DIE, CU.
21909 Returns NULL for invalid types. */
21911 static struct type
*
21912 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
21914 struct type
*this_type
= NULL
;
21918 case DW_TAG_class_type
:
21919 case DW_TAG_interface_type
:
21920 case DW_TAG_structure_type
:
21921 case DW_TAG_union_type
:
21922 this_type
= read_structure_type (die
, cu
);
21924 case DW_TAG_enumeration_type
:
21925 this_type
= read_enumeration_type (die
, cu
);
21927 case DW_TAG_subprogram
:
21928 case DW_TAG_subroutine_type
:
21929 case DW_TAG_inlined_subroutine
:
21930 this_type
= read_subroutine_type (die
, cu
);
21932 case DW_TAG_array_type
:
21933 this_type
= read_array_type (die
, cu
);
21935 case DW_TAG_set_type
:
21936 this_type
= read_set_type (die
, cu
);
21938 case DW_TAG_pointer_type
:
21939 this_type
= read_tag_pointer_type (die
, cu
);
21941 case DW_TAG_ptr_to_member_type
:
21942 this_type
= read_tag_ptr_to_member_type (die
, cu
);
21944 case DW_TAG_reference_type
:
21945 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
21947 case DW_TAG_rvalue_reference_type
:
21948 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
21950 case DW_TAG_const_type
:
21951 this_type
= read_tag_const_type (die
, cu
);
21953 case DW_TAG_volatile_type
:
21954 this_type
= read_tag_volatile_type (die
, cu
);
21956 case DW_TAG_restrict_type
:
21957 this_type
= read_tag_restrict_type (die
, cu
);
21959 case DW_TAG_string_type
:
21960 this_type
= read_tag_string_type (die
, cu
);
21962 case DW_TAG_typedef
:
21963 this_type
= read_typedef (die
, cu
);
21965 case DW_TAG_subrange_type
:
21966 this_type
= read_subrange_type (die
, cu
);
21968 case DW_TAG_base_type
:
21969 this_type
= read_base_type (die
, cu
);
21971 case DW_TAG_unspecified_type
:
21972 this_type
= read_unspecified_type (die
, cu
);
21974 case DW_TAG_namespace
:
21975 this_type
= read_namespace_type (die
, cu
);
21977 case DW_TAG_module
:
21978 this_type
= read_module_type (die
, cu
);
21980 case DW_TAG_atomic_type
:
21981 this_type
= read_tag_atomic_type (die
, cu
);
21984 complaint (_("unexpected tag in read_type_die: '%s'"),
21985 dwarf_tag_name (die
->tag
));
21992 /* See if we can figure out if the class lives in a namespace. We do
21993 this by looking for a member function; its demangled name will
21994 contain namespace info, if there is any.
21995 Return the computed name or NULL.
21996 Space for the result is allocated on the objfile's obstack.
21997 This is the full-die version of guess_partial_die_structure_name.
21998 In this case we know DIE has no useful parent. */
22000 static const char *
22001 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22003 struct die_info
*spec_die
;
22004 struct dwarf2_cu
*spec_cu
;
22005 struct die_info
*child
;
22006 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22009 spec_die
= die_specification (die
, &spec_cu
);
22010 if (spec_die
!= NULL
)
22016 for (child
= die
->child
;
22018 child
= child
->sibling
)
22020 if (child
->tag
== DW_TAG_subprogram
)
22022 const char *linkage_name
= dw2_linkage_name (child
, cu
);
22024 if (linkage_name
!= NULL
)
22026 gdb::unique_xmalloc_ptr
<char> actual_name
22027 (language_class_name_from_physname (cu
->language_defn
,
22029 const char *name
= NULL
;
22031 if (actual_name
!= NULL
)
22033 const char *die_name
= dwarf2_name (die
, cu
);
22035 if (die_name
!= NULL
22036 && strcmp (die_name
, actual_name
.get ()) != 0)
22038 /* Strip off the class name from the full name.
22039 We want the prefix. */
22040 int die_name_len
= strlen (die_name
);
22041 int actual_name_len
= strlen (actual_name
.get ());
22042 const char *ptr
= actual_name
.get ();
22044 /* Test for '::' as a sanity check. */
22045 if (actual_name_len
> die_name_len
+ 2
22046 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
22047 name
= obstack_strndup (
22048 &objfile
->per_bfd
->storage_obstack
,
22049 ptr
, actual_name_len
- die_name_len
- 2);
22060 /* GCC might emit a nameless typedef that has a linkage name. Determine the
22061 prefix part in such case. See
22062 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22064 static const char *
22065 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22067 struct attribute
*attr
;
22070 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
22071 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
22074 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
22077 attr
= dw2_linkage_name_attr (die
, cu
);
22078 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22081 /* dwarf2_name had to be already called. */
22082 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
22084 /* Strip the base name, keep any leading namespaces/classes. */
22085 base
= strrchr (DW_STRING (attr
), ':');
22086 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
22089 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22090 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
22092 &base
[-1] - DW_STRING (attr
));
22095 /* Return the name of the namespace/class that DIE is defined within,
22096 or "" if we can't tell. The caller should not xfree the result.
22098 For example, if we're within the method foo() in the following
22108 then determine_prefix on foo's die will return "N::C". */
22110 static const char *
22111 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22113 struct dwarf2_per_objfile
*dwarf2_per_objfile
22114 = cu
->per_cu
->dwarf2_per_objfile
;
22115 struct die_info
*parent
, *spec_die
;
22116 struct dwarf2_cu
*spec_cu
;
22117 struct type
*parent_type
;
22118 const char *retval
;
22120 if (cu
->language
!= language_cplus
22121 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
22122 && cu
->language
!= language_rust
)
22125 retval
= anonymous_struct_prefix (die
, cu
);
22129 /* We have to be careful in the presence of DW_AT_specification.
22130 For example, with GCC 3.4, given the code
22134 // Definition of N::foo.
22138 then we'll have a tree of DIEs like this:
22140 1: DW_TAG_compile_unit
22141 2: DW_TAG_namespace // N
22142 3: DW_TAG_subprogram // declaration of N::foo
22143 4: DW_TAG_subprogram // definition of N::foo
22144 DW_AT_specification // refers to die #3
22146 Thus, when processing die #4, we have to pretend that we're in
22147 the context of its DW_AT_specification, namely the contex of die
22150 spec_die
= die_specification (die
, &spec_cu
);
22151 if (spec_die
== NULL
)
22152 parent
= die
->parent
;
22155 parent
= spec_die
->parent
;
22159 if (parent
== NULL
)
22161 else if (parent
->building_fullname
)
22164 const char *parent_name
;
22166 /* It has been seen on RealView 2.2 built binaries,
22167 DW_TAG_template_type_param types actually _defined_ as
22168 children of the parent class:
22171 template class <class Enum> Class{};
22172 Class<enum E> class_e;
22174 1: DW_TAG_class_type (Class)
22175 2: DW_TAG_enumeration_type (E)
22176 3: DW_TAG_enumerator (enum1:0)
22177 3: DW_TAG_enumerator (enum2:1)
22179 2: DW_TAG_template_type_param
22180 DW_AT_type DW_FORM_ref_udata (E)
22182 Besides being broken debug info, it can put GDB into an
22183 infinite loop. Consider:
22185 When we're building the full name for Class<E>, we'll start
22186 at Class, and go look over its template type parameters,
22187 finding E. We'll then try to build the full name of E, and
22188 reach here. We're now trying to build the full name of E,
22189 and look over the parent DIE for containing scope. In the
22190 broken case, if we followed the parent DIE of E, we'd again
22191 find Class, and once again go look at its template type
22192 arguments, etc., etc. Simply don't consider such parent die
22193 as source-level parent of this die (it can't be, the language
22194 doesn't allow it), and break the loop here. */
22195 name
= dwarf2_name (die
, cu
);
22196 parent_name
= dwarf2_name (parent
, cu
);
22197 complaint (_("template param type '%s' defined within parent '%s'"),
22198 name
? name
: "<unknown>",
22199 parent_name
? parent_name
: "<unknown>");
22203 switch (parent
->tag
)
22205 case DW_TAG_namespace
:
22206 parent_type
= read_type_die (parent
, cu
);
22207 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
22208 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
22209 Work around this problem here. */
22210 if (cu
->language
== language_cplus
22211 && strcmp (TYPE_NAME (parent_type
), "::") == 0)
22213 /* We give a name to even anonymous namespaces. */
22214 return TYPE_NAME (parent_type
);
22215 case DW_TAG_class_type
:
22216 case DW_TAG_interface_type
:
22217 case DW_TAG_structure_type
:
22218 case DW_TAG_union_type
:
22219 case DW_TAG_module
:
22220 parent_type
= read_type_die (parent
, cu
);
22221 if (TYPE_NAME (parent_type
) != NULL
)
22222 return TYPE_NAME (parent_type
);
22224 /* An anonymous structure is only allowed non-static data
22225 members; no typedefs, no member functions, et cetera.
22226 So it does not need a prefix. */
22228 case DW_TAG_compile_unit
:
22229 case DW_TAG_partial_unit
:
22230 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
22231 if (cu
->language
== language_cplus
22232 && !dwarf2_per_objfile
->types
.empty ()
22233 && die
->child
!= NULL
22234 && (die
->tag
== DW_TAG_class_type
22235 || die
->tag
== DW_TAG_structure_type
22236 || die
->tag
== DW_TAG_union_type
))
22238 const char *name
= guess_full_die_structure_name (die
, cu
);
22243 case DW_TAG_subprogram
:
22244 /* Nested subroutines in Fortran get a prefix with the name
22245 of the parent's subroutine. */
22246 if (cu
->language
== language_fortran
)
22248 if ((die
->tag
== DW_TAG_subprogram
)
22249 && (dwarf2_name (parent
, cu
) != NULL
))
22250 return dwarf2_name (parent
, cu
);
22252 return determine_prefix (parent
, cu
);
22253 case DW_TAG_enumeration_type
:
22254 parent_type
= read_type_die (parent
, cu
);
22255 if (TYPE_DECLARED_CLASS (parent_type
))
22257 if (TYPE_NAME (parent_type
) != NULL
)
22258 return TYPE_NAME (parent_type
);
22261 /* Fall through. */
22263 return determine_prefix (parent
, cu
);
22267 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
22268 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
22269 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
22270 an obconcat, otherwise allocate storage for the result. The CU argument is
22271 used to determine the language and hence, the appropriate separator. */
22273 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
22276 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
22277 int physname
, struct dwarf2_cu
*cu
)
22279 const char *lead
= "";
22282 if (suffix
== NULL
|| suffix
[0] == '\0'
22283 || prefix
== NULL
|| prefix
[0] == '\0')
22285 else if (cu
->language
== language_d
)
22287 /* For D, the 'main' function could be defined in any module, but it
22288 should never be prefixed. */
22289 if (strcmp (suffix
, "D main") == 0)
22297 else if (cu
->language
== language_fortran
&& physname
)
22299 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
22300 DW_AT_MIPS_linkage_name is preferred and used instead. */
22308 if (prefix
== NULL
)
22310 if (suffix
== NULL
)
22317 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
22319 strcpy (retval
, lead
);
22320 strcat (retval
, prefix
);
22321 strcat (retval
, sep
);
22322 strcat (retval
, suffix
);
22327 /* We have an obstack. */
22328 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
22332 /* Return sibling of die, NULL if no sibling. */
22334 static struct die_info
*
22335 sibling_die (struct die_info
*die
)
22337 return die
->sibling
;
22340 /* Get name of a die, return NULL if not found. */
22342 static const char *
22343 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
22344 struct obstack
*obstack
)
22346 if (name
&& cu
->language
== language_cplus
)
22348 std::string canon_name
= cp_canonicalize_string (name
);
22350 if (!canon_name
.empty ())
22352 if (canon_name
!= name
)
22353 name
= obstack_strdup (obstack
, canon_name
);
22360 /* Get name of a die, return NULL if not found.
22361 Anonymous namespaces are converted to their magic string. */
22363 static const char *
22364 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22366 struct attribute
*attr
;
22367 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22369 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
22370 if ((!attr
|| !DW_STRING (attr
))
22371 && die
->tag
!= DW_TAG_namespace
22372 && die
->tag
!= DW_TAG_class_type
22373 && die
->tag
!= DW_TAG_interface_type
22374 && die
->tag
!= DW_TAG_structure_type
22375 && die
->tag
!= DW_TAG_union_type
)
22380 case DW_TAG_compile_unit
:
22381 case DW_TAG_partial_unit
:
22382 /* Compilation units have a DW_AT_name that is a filename, not
22383 a source language identifier. */
22384 case DW_TAG_enumeration_type
:
22385 case DW_TAG_enumerator
:
22386 /* These tags always have simple identifiers already; no need
22387 to canonicalize them. */
22388 return DW_STRING (attr
);
22390 case DW_TAG_namespace
:
22391 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
22392 return DW_STRING (attr
);
22393 return CP_ANONYMOUS_NAMESPACE_STR
;
22395 case DW_TAG_class_type
:
22396 case DW_TAG_interface_type
:
22397 case DW_TAG_structure_type
:
22398 case DW_TAG_union_type
:
22399 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
22400 structures or unions. These were of the form "._%d" in GCC 4.1,
22401 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
22402 and GCC 4.4. We work around this problem by ignoring these. */
22403 if (attr
&& DW_STRING (attr
)
22404 && (startswith (DW_STRING (attr
), "._")
22405 || startswith (DW_STRING (attr
), "<anonymous")))
22408 /* GCC might emit a nameless typedef that has a linkage name. See
22409 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22410 if (!attr
|| DW_STRING (attr
) == NULL
)
22412 attr
= dw2_linkage_name_attr (die
, cu
);
22413 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22416 /* Avoid demangling DW_STRING (attr) the second time on a second
22417 call for the same DIE. */
22418 if (!DW_STRING_IS_CANONICAL (attr
))
22420 gdb::unique_xmalloc_ptr
<char> demangled
22421 (gdb_demangle (DW_STRING (attr
), DMGL_TYPES
));
22425 /* FIXME: we already did this for the partial symbol... */
22427 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
22429 DW_STRING_IS_CANONICAL (attr
) = 1;
22431 /* Strip any leading namespaces/classes, keep only the base name.
22432 DW_AT_name for named DIEs does not contain the prefixes. */
22433 base
= strrchr (DW_STRING (attr
), ':');
22434 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
22437 return DW_STRING (attr
);
22446 if (!DW_STRING_IS_CANONICAL (attr
))
22449 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
22450 &objfile
->per_bfd
->storage_obstack
);
22451 DW_STRING_IS_CANONICAL (attr
) = 1;
22453 return DW_STRING (attr
);
22456 /* Return the die that this die in an extension of, or NULL if there
22457 is none. *EXT_CU is the CU containing DIE on input, and the CU
22458 containing the return value on output. */
22460 static struct die_info
*
22461 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
22463 struct attribute
*attr
;
22465 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
22469 return follow_die_ref (die
, attr
, ext_cu
);
22472 /* A convenience function that returns an "unknown" DWARF name,
22473 including the value of V. STR is the name of the entity being
22474 printed, e.g., "TAG". */
22476 static const char *
22477 dwarf_unknown (const char *str
, unsigned v
)
22479 char *cell
= get_print_cell ();
22480 xsnprintf (cell
, PRINT_CELL_SIZE
, "DW_%s_<unknown: %u>", str
, v
);
22484 /* Convert a DIE tag into its string name. */
22486 static const char *
22487 dwarf_tag_name (unsigned tag
)
22489 const char *name
= get_DW_TAG_name (tag
);
22492 return dwarf_unknown ("TAG", tag
);
22497 /* Convert a DWARF attribute code into its string name. */
22499 static const char *
22500 dwarf_attr_name (unsigned attr
)
22504 #ifdef MIPS /* collides with DW_AT_HP_block_index */
22505 if (attr
== DW_AT_MIPS_fde
)
22506 return "DW_AT_MIPS_fde";
22508 if (attr
== DW_AT_HP_block_index
)
22509 return "DW_AT_HP_block_index";
22512 name
= get_DW_AT_name (attr
);
22515 return dwarf_unknown ("AT", attr
);
22520 /* Convert a unit type to corresponding DW_UT name. */
22522 static const char *
22523 dwarf_unit_type_name (int unit_type
) {
22527 return "DW_UT_compile (0x01)";
22529 return "DW_UT_type (0x02)";
22531 return "DW_UT_partial (0x03)";
22533 return "DW_UT_skeleton (0x04)";
22535 return "DW_UT_split_compile (0x05)";
22537 return "DW_UT_split_type (0x06)";
22539 return "DW_UT_lo_user (0x80)";
22541 return "DW_UT_hi_user (0xff)";
22547 /* Convert a DWARF value form code into its string name. */
22549 static const char *
22550 dwarf_form_name (unsigned form
)
22552 const char *name
= get_DW_FORM_name (form
);
22555 return dwarf_unknown ("FORM", form
);
22560 static const char *
22561 dwarf_bool_name (unsigned mybool
)
22569 /* Convert a DWARF type code into its string name. */
22571 static const char *
22572 dwarf_type_encoding_name (unsigned enc
)
22574 const char *name
= get_DW_ATE_name (enc
);
22577 return dwarf_unknown ("ATE", enc
);
22583 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
22587 print_spaces (indent
, f
);
22588 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
22589 dwarf_tag_name (die
->tag
), die
->abbrev
,
22590 sect_offset_str (die
->sect_off
));
22592 if (die
->parent
!= NULL
)
22594 print_spaces (indent
, f
);
22595 fprintf_unfiltered (f
, " parent at offset: %s\n",
22596 sect_offset_str (die
->parent
->sect_off
));
22599 print_spaces (indent
, f
);
22600 fprintf_unfiltered (f
, " has children: %s\n",
22601 dwarf_bool_name (die
->child
!= NULL
));
22603 print_spaces (indent
, f
);
22604 fprintf_unfiltered (f
, " attributes:\n");
22606 for (i
= 0; i
< die
->num_attrs
; ++i
)
22608 print_spaces (indent
, f
);
22609 fprintf_unfiltered (f
, " %s (%s) ",
22610 dwarf_attr_name (die
->attrs
[i
].name
),
22611 dwarf_form_name (die
->attrs
[i
].form
));
22613 switch (die
->attrs
[i
].form
)
22616 case DW_FORM_addrx
:
22617 case DW_FORM_GNU_addr_index
:
22618 fprintf_unfiltered (f
, "address: ");
22619 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
22621 case DW_FORM_block2
:
22622 case DW_FORM_block4
:
22623 case DW_FORM_block
:
22624 case DW_FORM_block1
:
22625 fprintf_unfiltered (f
, "block: size %s",
22626 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22628 case DW_FORM_exprloc
:
22629 fprintf_unfiltered (f
, "expression: size %s",
22630 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22632 case DW_FORM_data16
:
22633 fprintf_unfiltered (f
, "constant of 16 bytes");
22635 case DW_FORM_ref_addr
:
22636 fprintf_unfiltered (f
, "ref address: ");
22637 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22639 case DW_FORM_GNU_ref_alt
:
22640 fprintf_unfiltered (f
, "alt ref address: ");
22641 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22647 case DW_FORM_ref_udata
:
22648 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
22649 (long) (DW_UNSND (&die
->attrs
[i
])));
22651 case DW_FORM_data1
:
22652 case DW_FORM_data2
:
22653 case DW_FORM_data4
:
22654 case DW_FORM_data8
:
22655 case DW_FORM_udata
:
22656 case DW_FORM_sdata
:
22657 fprintf_unfiltered (f
, "constant: %s",
22658 pulongest (DW_UNSND (&die
->attrs
[i
])));
22660 case DW_FORM_sec_offset
:
22661 fprintf_unfiltered (f
, "section offset: %s",
22662 pulongest (DW_UNSND (&die
->attrs
[i
])));
22664 case DW_FORM_ref_sig8
:
22665 fprintf_unfiltered (f
, "signature: %s",
22666 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
22668 case DW_FORM_string
:
22670 case DW_FORM_line_strp
:
22672 case DW_FORM_GNU_str_index
:
22673 case DW_FORM_GNU_strp_alt
:
22674 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
22675 DW_STRING (&die
->attrs
[i
])
22676 ? DW_STRING (&die
->attrs
[i
]) : "",
22677 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
22680 if (DW_UNSND (&die
->attrs
[i
]))
22681 fprintf_unfiltered (f
, "flag: TRUE");
22683 fprintf_unfiltered (f
, "flag: FALSE");
22685 case DW_FORM_flag_present
:
22686 fprintf_unfiltered (f
, "flag: TRUE");
22688 case DW_FORM_indirect
:
22689 /* The reader will have reduced the indirect form to
22690 the "base form" so this form should not occur. */
22691 fprintf_unfiltered (f
,
22692 "unexpected attribute form: DW_FORM_indirect");
22694 case DW_FORM_implicit_const
:
22695 fprintf_unfiltered (f
, "constant: %s",
22696 plongest (DW_SND (&die
->attrs
[i
])));
22699 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
22700 die
->attrs
[i
].form
);
22703 fprintf_unfiltered (f
, "\n");
22708 dump_die_for_error (struct die_info
*die
)
22710 dump_die_shallow (gdb_stderr
, 0, die
);
22714 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
22716 int indent
= level
* 4;
22718 gdb_assert (die
!= NULL
);
22720 if (level
>= max_level
)
22723 dump_die_shallow (f
, indent
, die
);
22725 if (die
->child
!= NULL
)
22727 print_spaces (indent
, f
);
22728 fprintf_unfiltered (f
, " Children:");
22729 if (level
+ 1 < max_level
)
22731 fprintf_unfiltered (f
, "\n");
22732 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
22736 fprintf_unfiltered (f
,
22737 " [not printed, max nesting level reached]\n");
22741 if (die
->sibling
!= NULL
&& level
> 0)
22743 dump_die_1 (f
, level
, max_level
, die
->sibling
);
22747 /* This is called from the pdie macro in gdbinit.in.
22748 It's not static so gcc will keep a copy callable from gdb. */
22751 dump_die (struct die_info
*die
, int max_level
)
22753 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
22757 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
22761 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
22762 to_underlying (die
->sect_off
),
22768 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
22772 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
22774 if (attr
->form_is_ref ())
22775 return (sect_offset
) DW_UNSND (attr
);
22777 complaint (_("unsupported die ref attribute form: '%s'"),
22778 dwarf_form_name (attr
->form
));
22782 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
22783 * the value held by the attribute is not constant. */
22786 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
22788 if (attr
->form
== DW_FORM_sdata
|| attr
->form
== DW_FORM_implicit_const
)
22789 return DW_SND (attr
);
22790 else if (attr
->form
== DW_FORM_udata
22791 || attr
->form
== DW_FORM_data1
22792 || attr
->form
== DW_FORM_data2
22793 || attr
->form
== DW_FORM_data4
22794 || attr
->form
== DW_FORM_data8
)
22795 return DW_UNSND (attr
);
22798 /* For DW_FORM_data16 see attribute::form_is_constant. */
22799 complaint (_("Attribute value is not a constant (%s)"),
22800 dwarf_form_name (attr
->form
));
22801 return default_value
;
22805 /* Follow reference or signature attribute ATTR of SRC_DIE.
22806 On entry *REF_CU is the CU of SRC_DIE.
22807 On exit *REF_CU is the CU of the result. */
22809 static struct die_info
*
22810 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22811 struct dwarf2_cu
**ref_cu
)
22813 struct die_info
*die
;
22815 if (attr
->form_is_ref ())
22816 die
= follow_die_ref (src_die
, attr
, ref_cu
);
22817 else if (attr
->form
== DW_FORM_ref_sig8
)
22818 die
= follow_die_sig (src_die
, attr
, ref_cu
);
22821 dump_die_for_error (src_die
);
22822 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
22823 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22829 /* Follow reference OFFSET.
22830 On entry *REF_CU is the CU of the source die referencing OFFSET.
22831 On exit *REF_CU is the CU of the result.
22832 Returns NULL if OFFSET is invalid. */
22834 static struct die_info
*
22835 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
22836 struct dwarf2_cu
**ref_cu
)
22838 struct die_info temp_die
;
22839 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
22840 struct dwarf2_per_objfile
*dwarf2_per_objfile
22841 = cu
->per_cu
->dwarf2_per_objfile
;
22843 gdb_assert (cu
->per_cu
!= NULL
);
22847 if (cu
->per_cu
->is_debug_types
)
22849 /* .debug_types CUs cannot reference anything outside their CU.
22850 If they need to, they have to reference a signatured type via
22851 DW_FORM_ref_sig8. */
22852 if (!offset_in_cu_p (&cu
->header
, sect_off
))
22855 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
22856 || !offset_in_cu_p (&cu
->header
, sect_off
))
22858 struct dwarf2_per_cu_data
*per_cu
;
22860 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
22861 dwarf2_per_objfile
);
22863 /* If necessary, add it to the queue and load its DIEs. */
22864 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
22865 load_full_comp_unit (per_cu
, false, cu
->language
);
22867 target_cu
= per_cu
->cu
;
22869 else if (cu
->dies
== NULL
)
22871 /* We're loading full DIEs during partial symbol reading. */
22872 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
22873 load_full_comp_unit (cu
->per_cu
, false, language_minimal
);
22876 *ref_cu
= target_cu
;
22877 temp_die
.sect_off
= sect_off
;
22879 if (target_cu
!= cu
)
22880 target_cu
->ancestor
= cu
;
22882 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
22884 to_underlying (sect_off
));
22887 /* Follow reference attribute ATTR of SRC_DIE.
22888 On entry *REF_CU is the CU of SRC_DIE.
22889 On exit *REF_CU is the CU of the result. */
22891 static struct die_info
*
22892 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
22893 struct dwarf2_cu
**ref_cu
)
22895 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22896 struct dwarf2_cu
*cu
= *ref_cu
;
22897 struct die_info
*die
;
22899 die
= follow_die_offset (sect_off
,
22900 (attr
->form
== DW_FORM_GNU_ref_alt
22901 || cu
->per_cu
->is_dwz
),
22904 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
22905 "at %s [in module %s]"),
22906 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
22907 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
22912 /* Return DWARF block referenced by DW_AT_location of DIE at SECT_OFF at PER_CU.
22913 Returned value is intended for DW_OP_call*. Returned
22914 dwarf2_locexpr_baton->data has lifetime of
22915 PER_CU->DWARF2_PER_OBJFILE->OBJFILE. */
22917 struct dwarf2_locexpr_baton
22918 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
22919 struct dwarf2_per_cu_data
*per_cu
,
22920 CORE_ADDR (*get_frame_pc
) (void *baton
),
22921 void *baton
, bool resolve_abstract_p
)
22923 struct dwarf2_cu
*cu
;
22924 struct die_info
*die
;
22925 struct attribute
*attr
;
22926 struct dwarf2_locexpr_baton retval
;
22927 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
22928 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22930 if (per_cu
->cu
== NULL
)
22931 load_cu (per_cu
, false);
22935 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22936 Instead just throw an error, not much else we can do. */
22937 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22938 sect_offset_str (sect_off
), objfile_name (objfile
));
22941 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22943 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22944 sect_offset_str (sect_off
), objfile_name (objfile
));
22946 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22947 if (!attr
&& resolve_abstract_p
22948 && (dwarf2_per_objfile
->abstract_to_concrete
.find (die
->sect_off
)
22949 != dwarf2_per_objfile
->abstract_to_concrete
.end ()))
22951 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22952 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
22953 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
22955 for (const auto &cand_off
22956 : dwarf2_per_objfile
->abstract_to_concrete
[die
->sect_off
])
22958 struct dwarf2_cu
*cand_cu
= cu
;
22959 struct die_info
*cand
22960 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
22963 || cand
->parent
->tag
!= DW_TAG_subprogram
)
22966 CORE_ADDR pc_low
, pc_high
;
22967 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
22968 if (pc_low
== ((CORE_ADDR
) -1))
22970 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
22971 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
22972 if (!(pc_low
<= pc
&& pc
< pc_high
))
22976 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22983 /* DWARF: "If there is no such attribute, then there is no effect.".
22984 DATA is ignored if SIZE is 0. */
22986 retval
.data
= NULL
;
22989 else if (attr
->form_is_section_offset ())
22991 struct dwarf2_loclist_baton loclist_baton
;
22992 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22995 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
22997 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
22999 retval
.size
= size
;
23003 if (!attr
->form_is_block ())
23004 error (_("Dwarf Error: DIE at %s referenced in module %s "
23005 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
23006 sect_offset_str (sect_off
), objfile_name (objfile
));
23008 retval
.data
= DW_BLOCK (attr
)->data
;
23009 retval
.size
= DW_BLOCK (attr
)->size
;
23011 retval
.per_cu
= cu
->per_cu
;
23013 age_cached_comp_units (dwarf2_per_objfile
);
23018 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
23021 struct dwarf2_locexpr_baton
23022 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
23023 struct dwarf2_per_cu_data
*per_cu
,
23024 CORE_ADDR (*get_frame_pc
) (void *baton
),
23027 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
23029 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
23032 /* Write a constant of a given type as target-ordered bytes into
23035 static const gdb_byte
*
23036 write_constant_as_bytes (struct obstack
*obstack
,
23037 enum bfd_endian byte_order
,
23044 *len
= TYPE_LENGTH (type
);
23045 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23046 store_unsigned_integer (result
, *len
, byte_order
, value
);
23051 /* If the DIE at OFFSET in PER_CU has a DW_AT_const_value, return a
23052 pointer to the constant bytes and set LEN to the length of the
23053 data. If memory is needed, allocate it on OBSTACK. If the DIE
23054 does not have a DW_AT_const_value, return NULL. */
23057 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
23058 struct dwarf2_per_cu_data
*per_cu
,
23059 struct obstack
*obstack
,
23062 struct dwarf2_cu
*cu
;
23063 struct die_info
*die
;
23064 struct attribute
*attr
;
23065 const gdb_byte
*result
= NULL
;
23068 enum bfd_endian byte_order
;
23069 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
23071 if (per_cu
->cu
== NULL
)
23072 load_cu (per_cu
, false);
23076 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23077 Instead just throw an error, not much else we can do. */
23078 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23079 sect_offset_str (sect_off
), objfile_name (objfile
));
23082 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23084 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23085 sect_offset_str (sect_off
), objfile_name (objfile
));
23087 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23091 byte_order
= (bfd_big_endian (objfile
->obfd
)
23092 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
23094 switch (attr
->form
)
23097 case DW_FORM_addrx
:
23098 case DW_FORM_GNU_addr_index
:
23102 *len
= cu
->header
.addr_size
;
23103 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23104 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
23108 case DW_FORM_string
:
23111 case DW_FORM_GNU_str_index
:
23112 case DW_FORM_GNU_strp_alt
:
23113 /* DW_STRING is already allocated on the objfile obstack, point
23115 result
= (const gdb_byte
*) DW_STRING (attr
);
23116 *len
= strlen (DW_STRING (attr
));
23118 case DW_FORM_block1
:
23119 case DW_FORM_block2
:
23120 case DW_FORM_block4
:
23121 case DW_FORM_block
:
23122 case DW_FORM_exprloc
:
23123 case DW_FORM_data16
:
23124 result
= DW_BLOCK (attr
)->data
;
23125 *len
= DW_BLOCK (attr
)->size
;
23128 /* The DW_AT_const_value attributes are supposed to carry the
23129 symbol's value "represented as it would be on the target
23130 architecture." By the time we get here, it's already been
23131 converted to host endianness, so we just need to sign- or
23132 zero-extend it as appropriate. */
23133 case DW_FORM_data1
:
23134 type
= die_type (die
, cu
);
23135 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
23136 if (result
== NULL
)
23137 result
= write_constant_as_bytes (obstack
, byte_order
,
23140 case DW_FORM_data2
:
23141 type
= die_type (die
, cu
);
23142 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
23143 if (result
== NULL
)
23144 result
= write_constant_as_bytes (obstack
, byte_order
,
23147 case DW_FORM_data4
:
23148 type
= die_type (die
, cu
);
23149 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
23150 if (result
== NULL
)
23151 result
= write_constant_as_bytes (obstack
, byte_order
,
23154 case DW_FORM_data8
:
23155 type
= die_type (die
, cu
);
23156 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
23157 if (result
== NULL
)
23158 result
= write_constant_as_bytes (obstack
, byte_order
,
23162 case DW_FORM_sdata
:
23163 case DW_FORM_implicit_const
:
23164 type
= die_type (die
, cu
);
23165 result
= write_constant_as_bytes (obstack
, byte_order
,
23166 type
, DW_SND (attr
), len
);
23169 case DW_FORM_udata
:
23170 type
= die_type (die
, cu
);
23171 result
= write_constant_as_bytes (obstack
, byte_order
,
23172 type
, DW_UNSND (attr
), len
);
23176 complaint (_("unsupported const value attribute form: '%s'"),
23177 dwarf_form_name (attr
->form
));
23184 /* Return the type of the die at OFFSET in PER_CU. Return NULL if no
23185 valid type for this die is found. */
23188 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
23189 struct dwarf2_per_cu_data
*per_cu
)
23191 struct dwarf2_cu
*cu
;
23192 struct die_info
*die
;
23194 if (per_cu
->cu
== NULL
)
23195 load_cu (per_cu
, false);
23200 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23204 return die_type (die
, cu
);
23207 /* Return the type of the DIE at DIE_OFFSET in the CU named by
23211 dwarf2_get_die_type (cu_offset die_offset
,
23212 struct dwarf2_per_cu_data
*per_cu
)
23214 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
23215 return get_die_type_at_offset (die_offset_sect
, per_cu
);
23218 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
23219 On entry *REF_CU is the CU of SRC_DIE.
23220 On exit *REF_CU is the CU of the result.
23221 Returns NULL if the referenced DIE isn't found. */
23223 static struct die_info
*
23224 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
23225 struct dwarf2_cu
**ref_cu
)
23227 struct die_info temp_die
;
23228 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
23229 struct die_info
*die
;
23231 /* While it might be nice to assert sig_type->type == NULL here,
23232 we can get here for DW_AT_imported_declaration where we need
23233 the DIE not the type. */
23235 /* If necessary, add it to the queue and load its DIEs. */
23237 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
23238 read_signatured_type (sig_type
);
23240 sig_cu
= sig_type
->per_cu
.cu
;
23241 gdb_assert (sig_cu
!= NULL
);
23242 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
23243 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
23244 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
23245 to_underlying (temp_die
.sect_off
));
23248 struct dwarf2_per_objfile
*dwarf2_per_objfile
23249 = (*ref_cu
)->per_cu
->dwarf2_per_objfile
;
23251 /* For .gdb_index version 7 keep track of included TUs.
23252 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
23253 if (dwarf2_per_objfile
->index_table
!= NULL
23254 && dwarf2_per_objfile
->index_table
->version
<= 7)
23256 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
23261 sig_cu
->ancestor
= cu
;
23269 /* Follow signatured type referenced by ATTR in SRC_DIE.
23270 On entry *REF_CU is the CU of SRC_DIE.
23271 On exit *REF_CU is the CU of the result.
23272 The result is the DIE of the type.
23273 If the referenced type cannot be found an error is thrown. */
23275 static struct die_info
*
23276 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23277 struct dwarf2_cu
**ref_cu
)
23279 ULONGEST signature
= DW_SIGNATURE (attr
);
23280 struct signatured_type
*sig_type
;
23281 struct die_info
*die
;
23283 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
23285 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
23286 /* sig_type will be NULL if the signatured type is missing from
23288 if (sig_type
== NULL
)
23290 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23291 " from DIE at %s [in module %s]"),
23292 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23293 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23296 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
23299 dump_die_for_error (src_die
);
23300 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23301 " from DIE at %s [in module %s]"),
23302 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23303 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23309 /* Get the type specified by SIGNATURE referenced in DIE/CU,
23310 reading in and processing the type unit if necessary. */
23312 static struct type
*
23313 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
23314 struct dwarf2_cu
*cu
)
23316 struct dwarf2_per_objfile
*dwarf2_per_objfile
23317 = cu
->per_cu
->dwarf2_per_objfile
;
23318 struct signatured_type
*sig_type
;
23319 struct dwarf2_cu
*type_cu
;
23320 struct die_info
*type_die
;
23323 sig_type
= lookup_signatured_type (cu
, signature
);
23324 /* sig_type will be NULL if the signatured type is missing from
23326 if (sig_type
== NULL
)
23328 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23329 " from DIE at %s [in module %s]"),
23330 hex_string (signature
), sect_offset_str (die
->sect_off
),
23331 objfile_name (dwarf2_per_objfile
->objfile
));
23332 return build_error_marker_type (cu
, die
);
23335 /* If we already know the type we're done. */
23336 if (sig_type
->type
!= NULL
)
23337 return sig_type
->type
;
23340 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
23341 if (type_die
!= NULL
)
23343 /* N.B. We need to call get_die_type to ensure only one type for this DIE
23344 is created. This is important, for example, because for c++ classes
23345 we need TYPE_NAME set which is only done by new_symbol. Blech. */
23346 type
= read_type_die (type_die
, type_cu
);
23349 complaint (_("Dwarf Error: Cannot build signatured type %s"
23350 " referenced from DIE at %s [in module %s]"),
23351 hex_string (signature
), sect_offset_str (die
->sect_off
),
23352 objfile_name (dwarf2_per_objfile
->objfile
));
23353 type
= build_error_marker_type (cu
, die
);
23358 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23359 " from DIE at %s [in module %s]"),
23360 hex_string (signature
), sect_offset_str (die
->sect_off
),
23361 objfile_name (dwarf2_per_objfile
->objfile
));
23362 type
= build_error_marker_type (cu
, die
);
23364 sig_type
->type
= type
;
23369 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
23370 reading in and processing the type unit if necessary. */
23372 static struct type
*
23373 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
23374 struct dwarf2_cu
*cu
) /* ARI: editCase function */
23376 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
23377 if (attr
->form_is_ref ())
23379 struct dwarf2_cu
*type_cu
= cu
;
23380 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
23382 return read_type_die (type_die
, type_cu
);
23384 else if (attr
->form
== DW_FORM_ref_sig8
)
23386 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
23390 struct dwarf2_per_objfile
*dwarf2_per_objfile
23391 = cu
->per_cu
->dwarf2_per_objfile
;
23393 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
23394 " at %s [in module %s]"),
23395 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
23396 objfile_name (dwarf2_per_objfile
->objfile
));
23397 return build_error_marker_type (cu
, die
);
23401 /* Load the DIEs associated with type unit PER_CU into memory. */
23404 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
23406 struct signatured_type
*sig_type
;
23408 /* Caller is responsible for ensuring type_unit_groups don't get here. */
23409 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
23411 /* We have the per_cu, but we need the signatured_type.
23412 Fortunately this is an easy translation. */
23413 gdb_assert (per_cu
->is_debug_types
);
23414 sig_type
= (struct signatured_type
*) per_cu
;
23416 gdb_assert (per_cu
->cu
== NULL
);
23418 read_signatured_type (sig_type
);
23420 gdb_assert (per_cu
->cu
!= NULL
);
23423 /* Read in a signatured type and build its CU and DIEs.
23424 If the type is a stub for the real type in a DWO file,
23425 read in the real type from the DWO file as well. */
23428 read_signatured_type (struct signatured_type
*sig_type
)
23430 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
23432 gdb_assert (per_cu
->is_debug_types
);
23433 gdb_assert (per_cu
->cu
== NULL
);
23435 cutu_reader
reader (per_cu
, NULL
, 0, 1, false);
23437 if (!reader
.dummy_p
)
23439 struct dwarf2_cu
*cu
= reader
.cu
;
23440 const gdb_byte
*info_ptr
= reader
.info_ptr
;
23442 gdb_assert (cu
->die_hash
== NULL
);
23444 htab_create_alloc_ex (cu
->header
.length
/ 12,
23448 &cu
->comp_unit_obstack
,
23449 hashtab_obstack_allocate
,
23450 dummy_obstack_deallocate
);
23452 if (reader
.comp_unit_die
->has_children
)
23453 reader
.comp_unit_die
->child
23454 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
23455 reader
.comp_unit_die
);
23456 cu
->dies
= reader
.comp_unit_die
;
23457 /* comp_unit_die is not stored in die_hash, no need. */
23459 /* We try not to read any attributes in this function, because
23460 not all CUs needed for references have been loaded yet, and
23461 symbol table processing isn't initialized. But we have to
23462 set the CU language, or we won't be able to build types
23463 correctly. Similarly, if we do not read the producer, we can
23464 not apply producer-specific interpretation. */
23465 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
23468 sig_type
->per_cu
.tu_read
= 1;
23471 /* Decode simple location descriptions.
23472 Given a pointer to a dwarf block that defines a location, compute
23473 the location and return the value.
23475 NOTE drow/2003-11-18: This function is called in two situations
23476 now: for the address of static or global variables (partial symbols
23477 only) and for offsets into structures which are expected to be
23478 (more or less) constant. The partial symbol case should go away,
23479 and only the constant case should remain. That will let this
23480 function complain more accurately. A few special modes are allowed
23481 without complaint for global variables (for instance, global
23482 register values and thread-local values).
23484 A location description containing no operations indicates that the
23485 object is optimized out. The return value is 0 for that case.
23486 FIXME drow/2003-11-16: No callers check for this case any more; soon all
23487 callers will only want a very basic result and this can become a
23490 Note that stack[0] is unused except as a default error return. */
23493 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
23495 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
23497 size_t size
= blk
->size
;
23498 const gdb_byte
*data
= blk
->data
;
23499 CORE_ADDR stack
[64];
23501 unsigned int bytes_read
, unsnd
;
23507 stack
[++stacki
] = 0;
23546 stack
[++stacki
] = op
- DW_OP_lit0
;
23581 stack
[++stacki
] = op
- DW_OP_reg0
;
23583 dwarf2_complex_location_expr_complaint ();
23587 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
23589 stack
[++stacki
] = unsnd
;
23591 dwarf2_complex_location_expr_complaint ();
23595 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
23600 case DW_OP_const1u
:
23601 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
23605 case DW_OP_const1s
:
23606 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
23610 case DW_OP_const2u
:
23611 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
23615 case DW_OP_const2s
:
23616 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
23620 case DW_OP_const4u
:
23621 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
23625 case DW_OP_const4s
:
23626 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
23630 case DW_OP_const8u
:
23631 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
23636 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
23642 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
23647 stack
[stacki
+ 1] = stack
[stacki
];
23652 stack
[stacki
- 1] += stack
[stacki
];
23656 case DW_OP_plus_uconst
:
23657 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
23663 stack
[stacki
- 1] -= stack
[stacki
];
23668 /* If we're not the last op, then we definitely can't encode
23669 this using GDB's address_class enum. This is valid for partial
23670 global symbols, although the variable's address will be bogus
23673 dwarf2_complex_location_expr_complaint ();
23676 case DW_OP_GNU_push_tls_address
:
23677 case DW_OP_form_tls_address
:
23678 /* The top of the stack has the offset from the beginning
23679 of the thread control block at which the variable is located. */
23680 /* Nothing should follow this operator, so the top of stack would
23682 /* This is valid for partial global symbols, but the variable's
23683 address will be bogus in the psymtab. Make it always at least
23684 non-zero to not look as a variable garbage collected by linker
23685 which have DW_OP_addr 0. */
23687 dwarf2_complex_location_expr_complaint ();
23691 case DW_OP_GNU_uninit
:
23695 case DW_OP_GNU_addr_index
:
23696 case DW_OP_GNU_const_index
:
23697 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
23704 const char *name
= get_DW_OP_name (op
);
23707 complaint (_("unsupported stack op: '%s'"),
23710 complaint (_("unsupported stack op: '%02x'"),
23714 return (stack
[stacki
]);
23717 /* Enforce maximum stack depth of SIZE-1 to avoid writing
23718 outside of the allocated space. Also enforce minimum>0. */
23719 if (stacki
>= ARRAY_SIZE (stack
) - 1)
23721 complaint (_("location description stack overflow"));
23727 complaint (_("location description stack underflow"));
23731 return (stack
[stacki
]);
23734 /* memory allocation interface */
23736 static struct dwarf_block
*
23737 dwarf_alloc_block (struct dwarf2_cu
*cu
)
23739 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
23742 static struct die_info
*
23743 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
23745 struct die_info
*die
;
23746 size_t size
= sizeof (struct die_info
);
23749 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
23751 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
23752 memset (die
, 0, sizeof (struct die_info
));
23757 /* Macro support. */
23759 gdb::unique_xmalloc_ptr
<char>
23760 line_header::file_file_name (int file
)
23762 /* Is the file number a valid index into the line header's file name
23763 table? Remember that file numbers start with one, not zero. */
23764 if (is_valid_file_index (file
))
23766 const file_entry
*fe
= file_name_at (file
);
23768 if (!IS_ABSOLUTE_PATH (fe
->name
))
23770 const char *dir
= fe
->include_dir (this);
23772 return gdb::unique_xmalloc_ptr
<char> (concat (dir
, SLASH_STRING
,
23776 return make_unique_xstrdup (fe
->name
);
23780 /* The compiler produced a bogus file number. We can at least
23781 record the macro definitions made in the file, even if we
23782 won't be able to find the file by name. */
23783 char fake_name
[80];
23785 xsnprintf (fake_name
, sizeof (fake_name
),
23786 "<bad macro file number %d>", file
);
23788 complaint (_("bad file number in macro information (%d)"),
23791 return make_unique_xstrdup (fake_name
);
23795 gdb::unique_xmalloc_ptr
<char>
23796 line_header::file_full_name (int file
, const char *comp_dir
)
23798 /* Is the file number a valid index into the line header's file name
23799 table? Remember that file numbers start with one, not zero. */
23800 if (is_valid_file_index (file
))
23802 gdb::unique_xmalloc_ptr
<char> relative
= file_file_name (file
);
23804 if (IS_ABSOLUTE_PATH (relative
.get ()) || comp_dir
== NULL
)
23806 return gdb::unique_xmalloc_ptr
<char> (concat (comp_dir
, SLASH_STRING
,
23811 return file_file_name (file
);
23815 static struct macro_source_file
*
23816 macro_start_file (struct dwarf2_cu
*cu
,
23817 int file
, int line
,
23818 struct macro_source_file
*current_file
,
23819 struct line_header
*lh
)
23821 /* File name relative to the compilation directory of this source file. */
23822 gdb::unique_xmalloc_ptr
<char> file_name
= lh
->file_file_name (file
);
23824 if (! current_file
)
23826 /* Note: We don't create a macro table for this compilation unit
23827 at all until we actually get a filename. */
23828 struct macro_table
*macro_table
= cu
->get_builder ()->get_macro_table ();
23830 /* If we have no current file, then this must be the start_file
23831 directive for the compilation unit's main source file. */
23832 current_file
= macro_set_main (macro_table
, file_name
.get ());
23833 macro_define_special (macro_table
);
23836 current_file
= macro_include (current_file
, line
, file_name
.get ());
23838 return current_file
;
23841 static const char *
23842 consume_improper_spaces (const char *p
, const char *body
)
23846 complaint (_("macro definition contains spaces "
23847 "in formal argument list:\n`%s'"),
23859 parse_macro_definition (struct macro_source_file
*file
, int line
,
23864 /* The body string takes one of two forms. For object-like macro
23865 definitions, it should be:
23867 <macro name> " " <definition>
23869 For function-like macro definitions, it should be:
23871 <macro name> "() " <definition>
23873 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
23875 Spaces may appear only where explicitly indicated, and in the
23878 The Dwarf 2 spec says that an object-like macro's name is always
23879 followed by a space, but versions of GCC around March 2002 omit
23880 the space when the macro's definition is the empty string.
23882 The Dwarf 2 spec says that there should be no spaces between the
23883 formal arguments in a function-like macro's formal argument list,
23884 but versions of GCC around March 2002 include spaces after the
23888 /* Find the extent of the macro name. The macro name is terminated
23889 by either a space or null character (for an object-like macro) or
23890 an opening paren (for a function-like macro). */
23891 for (p
= body
; *p
; p
++)
23892 if (*p
== ' ' || *p
== '(')
23895 if (*p
== ' ' || *p
== '\0')
23897 /* It's an object-like macro. */
23898 int name_len
= p
- body
;
23899 std::string
name (body
, name_len
);
23900 const char *replacement
;
23903 replacement
= body
+ name_len
+ 1;
23906 dwarf2_macro_malformed_definition_complaint (body
);
23907 replacement
= body
+ name_len
;
23910 macro_define_object (file
, line
, name
.c_str (), replacement
);
23912 else if (*p
== '(')
23914 /* It's a function-like macro. */
23915 std::string
name (body
, p
- body
);
23918 char **argv
= XNEWVEC (char *, argv_size
);
23922 p
= consume_improper_spaces (p
, body
);
23924 /* Parse the formal argument list. */
23925 while (*p
&& *p
!= ')')
23927 /* Find the extent of the current argument name. */
23928 const char *arg_start
= p
;
23930 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
23933 if (! *p
|| p
== arg_start
)
23934 dwarf2_macro_malformed_definition_complaint (body
);
23937 /* Make sure argv has room for the new argument. */
23938 if (argc
>= argv_size
)
23941 argv
= XRESIZEVEC (char *, argv
, argv_size
);
23944 argv
[argc
++] = savestring (arg_start
, p
- arg_start
);
23947 p
= consume_improper_spaces (p
, body
);
23949 /* Consume the comma, if present. */
23954 p
= consume_improper_spaces (p
, body
);
23963 /* Perfectly formed definition, no complaints. */
23964 macro_define_function (file
, line
, name
.c_str (),
23965 argc
, (const char **) argv
,
23967 else if (*p
== '\0')
23969 /* Complain, but do define it. */
23970 dwarf2_macro_malformed_definition_complaint (body
);
23971 macro_define_function (file
, line
, name
.c_str (),
23972 argc
, (const char **) argv
,
23976 /* Just complain. */
23977 dwarf2_macro_malformed_definition_complaint (body
);
23980 /* Just complain. */
23981 dwarf2_macro_malformed_definition_complaint (body
);
23986 for (i
= 0; i
< argc
; i
++)
23992 dwarf2_macro_malformed_definition_complaint (body
);
23995 /* Skip some bytes from BYTES according to the form given in FORM.
23996 Returns the new pointer. */
23998 static const gdb_byte
*
23999 skip_form_bytes (bfd
*abfd
, const gdb_byte
*bytes
, const gdb_byte
*buffer_end
,
24000 enum dwarf_form form
,
24001 unsigned int offset_size
,
24002 struct dwarf2_section_info
*section
)
24004 unsigned int bytes_read
;
24008 case DW_FORM_data1
:
24013 case DW_FORM_data2
:
24017 case DW_FORM_data4
:
24021 case DW_FORM_data8
:
24025 case DW_FORM_data16
:
24029 case DW_FORM_string
:
24030 read_direct_string (abfd
, bytes
, &bytes_read
);
24031 bytes
+= bytes_read
;
24034 case DW_FORM_sec_offset
:
24036 case DW_FORM_GNU_strp_alt
:
24037 bytes
+= offset_size
;
24040 case DW_FORM_block
:
24041 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
24042 bytes
+= bytes_read
;
24045 case DW_FORM_block1
:
24046 bytes
+= 1 + read_1_byte (abfd
, bytes
);
24048 case DW_FORM_block2
:
24049 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
24051 case DW_FORM_block4
:
24052 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
24055 case DW_FORM_addrx
:
24056 case DW_FORM_sdata
:
24058 case DW_FORM_udata
:
24059 case DW_FORM_GNU_addr_index
:
24060 case DW_FORM_GNU_str_index
:
24061 bytes
= gdb_skip_leb128 (bytes
, buffer_end
);
24064 dwarf2_section_buffer_overflow_complaint (section
);
24069 case DW_FORM_implicit_const
:
24074 complaint (_("invalid form 0x%x in `%s'"),
24075 form
, section
->get_name ());
24083 /* A helper for dwarf_decode_macros that handles skipping an unknown
24084 opcode. Returns an updated pointer to the macro data buffer; or,
24085 on error, issues a complaint and returns NULL. */
24087 static const gdb_byte
*
24088 skip_unknown_opcode (unsigned int opcode
,
24089 const gdb_byte
**opcode_definitions
,
24090 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24092 unsigned int offset_size
,
24093 struct dwarf2_section_info
*section
)
24095 unsigned int bytes_read
, i
;
24097 const gdb_byte
*defn
;
24099 if (opcode_definitions
[opcode
] == NULL
)
24101 complaint (_("unrecognized DW_MACFINO opcode 0x%x"),
24106 defn
= opcode_definitions
[opcode
];
24107 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
24108 defn
+= bytes_read
;
24110 for (i
= 0; i
< arg
; ++i
)
24112 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
,
24113 (enum dwarf_form
) defn
[i
], offset_size
,
24115 if (mac_ptr
== NULL
)
24117 /* skip_form_bytes already issued the complaint. */
24125 /* A helper function which parses the header of a macro section.
24126 If the macro section is the extended (for now called "GNU") type,
24127 then this updates *OFFSET_SIZE. Returns a pointer to just after
24128 the header, or issues a complaint and returns NULL on error. */
24130 static const gdb_byte
*
24131 dwarf_parse_macro_header (const gdb_byte
**opcode_definitions
,
24133 const gdb_byte
*mac_ptr
,
24134 unsigned int *offset_size
,
24135 int section_is_gnu
)
24137 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
24139 if (section_is_gnu
)
24141 unsigned int version
, flags
;
24143 version
= read_2_bytes (abfd
, mac_ptr
);
24144 if (version
!= 4 && version
!= 5)
24146 complaint (_("unrecognized version `%d' in .debug_macro section"),
24152 flags
= read_1_byte (abfd
, mac_ptr
);
24154 *offset_size
= (flags
& 1) ? 8 : 4;
24156 if ((flags
& 2) != 0)
24157 /* We don't need the line table offset. */
24158 mac_ptr
+= *offset_size
;
24160 /* Vendor opcode descriptions. */
24161 if ((flags
& 4) != 0)
24163 unsigned int i
, count
;
24165 count
= read_1_byte (abfd
, mac_ptr
);
24167 for (i
= 0; i
< count
; ++i
)
24169 unsigned int opcode
, bytes_read
;
24172 opcode
= read_1_byte (abfd
, mac_ptr
);
24174 opcode_definitions
[opcode
] = mac_ptr
;
24175 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24176 mac_ptr
+= bytes_read
;
24185 /* A helper for dwarf_decode_macros that handles the GNU extensions,
24186 including DW_MACRO_import. */
24189 dwarf_decode_macro_bytes (struct dwarf2_cu
*cu
,
24191 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24192 struct macro_source_file
*current_file
,
24193 struct line_header
*lh
,
24194 struct dwarf2_section_info
*section
,
24195 int section_is_gnu
, int section_is_dwz
,
24196 unsigned int offset_size
,
24197 htab_t include_hash
)
24199 struct dwarf2_per_objfile
*dwarf2_per_objfile
24200 = cu
->per_cu
->dwarf2_per_objfile
;
24201 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24202 enum dwarf_macro_record_type macinfo_type
;
24203 int at_commandline
;
24204 const gdb_byte
*opcode_definitions
[256];
24206 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
24207 &offset_size
, section_is_gnu
);
24208 if (mac_ptr
== NULL
)
24210 /* We already issued a complaint. */
24214 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
24215 GDB is still reading the definitions from command line. First
24216 DW_MACINFO_start_file will need to be ignored as it was already executed
24217 to create CURRENT_FILE for the main source holding also the command line
24218 definitions. On first met DW_MACINFO_start_file this flag is reset to
24219 normally execute all the remaining DW_MACINFO_start_file macinfos. */
24221 at_commandline
= 1;
24225 /* Do we at least have room for a macinfo type byte? */
24226 if (mac_ptr
>= mac_end
)
24228 dwarf2_section_buffer_overflow_complaint (section
);
24232 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
24235 /* Note that we rely on the fact that the corresponding GNU and
24236 DWARF constants are the same. */
24238 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
24239 switch (macinfo_type
)
24241 /* A zero macinfo type indicates the end of the macro
24246 case DW_MACRO_define
:
24247 case DW_MACRO_undef
:
24248 case DW_MACRO_define_strp
:
24249 case DW_MACRO_undef_strp
:
24250 case DW_MACRO_define_sup
:
24251 case DW_MACRO_undef_sup
:
24253 unsigned int bytes_read
;
24258 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24259 mac_ptr
+= bytes_read
;
24261 if (macinfo_type
== DW_MACRO_define
24262 || macinfo_type
== DW_MACRO_undef
)
24264 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24265 mac_ptr
+= bytes_read
;
24269 LONGEST str_offset
;
24271 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
24272 mac_ptr
+= offset_size
;
24274 if (macinfo_type
== DW_MACRO_define_sup
24275 || macinfo_type
== DW_MACRO_undef_sup
24278 struct dwz_file
*dwz
24279 = dwarf2_get_dwz_file (dwarf2_per_objfile
);
24281 body
= read_indirect_string_from_dwz (objfile
,
24285 body
= read_indirect_string_at_offset (dwarf2_per_objfile
,
24289 is_define
= (macinfo_type
== DW_MACRO_define
24290 || macinfo_type
== DW_MACRO_define_strp
24291 || macinfo_type
== DW_MACRO_define_sup
);
24292 if (! current_file
)
24294 /* DWARF violation as no main source is present. */
24295 complaint (_("debug info with no main source gives macro %s "
24297 is_define
? _("definition") : _("undefinition"),
24301 if ((line
== 0 && !at_commandline
)
24302 || (line
!= 0 && at_commandline
))
24303 complaint (_("debug info gives %s macro %s with %s line %d: %s"),
24304 at_commandline
? _("command-line") : _("in-file"),
24305 is_define
? _("definition") : _("undefinition"),
24306 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
24310 /* Fedora's rpm-build's "debugedit" binary
24311 corrupted .debug_macro sections.
24314 https://bugzilla.redhat.com/show_bug.cgi?id=1708786 */
24315 complaint (_("debug info gives %s invalid macro %s "
24316 "without body (corrupted?) at line %d "
24318 at_commandline
? _("command-line") : _("in-file"),
24319 is_define
? _("definition") : _("undefinition"),
24320 line
, current_file
->filename
);
24322 else if (is_define
)
24323 parse_macro_definition (current_file
, line
, body
);
24326 gdb_assert (macinfo_type
== DW_MACRO_undef
24327 || macinfo_type
== DW_MACRO_undef_strp
24328 || macinfo_type
== DW_MACRO_undef_sup
);
24329 macro_undef (current_file
, line
, body
);
24334 case DW_MACRO_start_file
:
24336 unsigned int bytes_read
;
24339 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24340 mac_ptr
+= bytes_read
;
24341 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24342 mac_ptr
+= bytes_read
;
24344 if ((line
== 0 && !at_commandline
)
24345 || (line
!= 0 && at_commandline
))
24346 complaint (_("debug info gives source %d included "
24347 "from %s at %s line %d"),
24348 file
, at_commandline
? _("command-line") : _("file"),
24349 line
== 0 ? _("zero") : _("non-zero"), line
);
24351 if (at_commandline
)
24353 /* This DW_MACRO_start_file was executed in the
24355 at_commandline
= 0;
24358 current_file
= macro_start_file (cu
, file
, line
, current_file
,
24363 case DW_MACRO_end_file
:
24364 if (! current_file
)
24365 complaint (_("macro debug info has an unmatched "
24366 "`close_file' directive"));
24369 current_file
= current_file
->included_by
;
24370 if (! current_file
)
24372 enum dwarf_macro_record_type next_type
;
24374 /* GCC circa March 2002 doesn't produce the zero
24375 type byte marking the end of the compilation
24376 unit. Complain if it's not there, but exit no
24379 /* Do we at least have room for a macinfo type byte? */
24380 if (mac_ptr
>= mac_end
)
24382 dwarf2_section_buffer_overflow_complaint (section
);
24386 /* We don't increment mac_ptr here, so this is just
24389 = (enum dwarf_macro_record_type
) read_1_byte (abfd
,
24391 if (next_type
!= 0)
24392 complaint (_("no terminating 0-type entry for "
24393 "macros in `.debug_macinfo' section"));
24400 case DW_MACRO_import
:
24401 case DW_MACRO_import_sup
:
24405 bfd
*include_bfd
= abfd
;
24406 struct dwarf2_section_info
*include_section
= section
;
24407 const gdb_byte
*include_mac_end
= mac_end
;
24408 int is_dwz
= section_is_dwz
;
24409 const gdb_byte
*new_mac_ptr
;
24411 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
24412 mac_ptr
+= offset_size
;
24414 if (macinfo_type
== DW_MACRO_import_sup
)
24416 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
24418 dwz
->macro
.read (objfile
);
24420 include_section
= &dwz
->macro
;
24421 include_bfd
= include_section
->get_bfd_owner ();
24422 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
24426 new_mac_ptr
= include_section
->buffer
+ offset
;
24427 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
24431 /* This has actually happened; see
24432 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
24433 complaint (_("recursive DW_MACRO_import in "
24434 ".debug_macro section"));
24438 *slot
= (void *) new_mac_ptr
;
24440 dwarf_decode_macro_bytes (cu
, include_bfd
, new_mac_ptr
,
24441 include_mac_end
, current_file
, lh
,
24442 section
, section_is_gnu
, is_dwz
,
24443 offset_size
, include_hash
);
24445 htab_remove_elt (include_hash
, (void *) new_mac_ptr
);
24450 case DW_MACINFO_vendor_ext
:
24451 if (!section_is_gnu
)
24453 unsigned int bytes_read
;
24455 /* This reads the constant, but since we don't recognize
24456 any vendor extensions, we ignore it. */
24457 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24458 mac_ptr
+= bytes_read
;
24459 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24460 mac_ptr
+= bytes_read
;
24462 /* We don't recognize any vendor extensions. */
24468 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
24469 mac_ptr
, mac_end
, abfd
, offset_size
,
24471 if (mac_ptr
== NULL
)
24476 } while (macinfo_type
!= 0);
24480 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
24481 int section_is_gnu
)
24483 struct dwarf2_per_objfile
*dwarf2_per_objfile
24484 = cu
->per_cu
->dwarf2_per_objfile
;
24485 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24486 struct line_header
*lh
= cu
->line_header
;
24488 const gdb_byte
*mac_ptr
, *mac_end
;
24489 struct macro_source_file
*current_file
= 0;
24490 enum dwarf_macro_record_type macinfo_type
;
24491 unsigned int offset_size
= cu
->header
.offset_size
;
24492 const gdb_byte
*opcode_definitions
[256];
24494 struct dwarf2_section_info
*section
;
24495 const char *section_name
;
24497 if (cu
->dwo_unit
!= NULL
)
24499 if (section_is_gnu
)
24501 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
24502 section_name
= ".debug_macro.dwo";
24506 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
24507 section_name
= ".debug_macinfo.dwo";
24512 if (section_is_gnu
)
24514 section
= &dwarf2_per_objfile
->macro
;
24515 section_name
= ".debug_macro";
24519 section
= &dwarf2_per_objfile
->macinfo
;
24520 section_name
= ".debug_macinfo";
24524 section
->read (objfile
);
24525 if (section
->buffer
== NULL
)
24527 complaint (_("missing %s section"), section_name
);
24530 abfd
= section
->get_bfd_owner ();
24532 /* First pass: Find the name of the base filename.
24533 This filename is needed in order to process all macros whose definition
24534 (or undefinition) comes from the command line. These macros are defined
24535 before the first DW_MACINFO_start_file entry, and yet still need to be
24536 associated to the base file.
24538 To determine the base file name, we scan the macro definitions until we
24539 reach the first DW_MACINFO_start_file entry. We then initialize
24540 CURRENT_FILE accordingly so that any macro definition found before the
24541 first DW_MACINFO_start_file can still be associated to the base file. */
24543 mac_ptr
= section
->buffer
+ offset
;
24544 mac_end
= section
->buffer
+ section
->size
;
24546 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
24547 &offset_size
, section_is_gnu
);
24548 if (mac_ptr
== NULL
)
24550 /* We already issued a complaint. */
24556 /* Do we at least have room for a macinfo type byte? */
24557 if (mac_ptr
>= mac_end
)
24559 /* Complaint is printed during the second pass as GDB will probably
24560 stop the first pass earlier upon finding
24561 DW_MACINFO_start_file. */
24565 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
24568 /* Note that we rely on the fact that the corresponding GNU and
24569 DWARF constants are the same. */
24571 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
24572 switch (macinfo_type
)
24574 /* A zero macinfo type indicates the end of the macro
24579 case DW_MACRO_define
:
24580 case DW_MACRO_undef
:
24581 /* Only skip the data by MAC_PTR. */
24583 unsigned int bytes_read
;
24585 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24586 mac_ptr
+= bytes_read
;
24587 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24588 mac_ptr
+= bytes_read
;
24592 case DW_MACRO_start_file
:
24594 unsigned int bytes_read
;
24597 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24598 mac_ptr
+= bytes_read
;
24599 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24600 mac_ptr
+= bytes_read
;
24602 current_file
= macro_start_file (cu
, file
, line
, current_file
, lh
);
24606 case DW_MACRO_end_file
:
24607 /* No data to skip by MAC_PTR. */
24610 case DW_MACRO_define_strp
:
24611 case DW_MACRO_undef_strp
:
24612 case DW_MACRO_define_sup
:
24613 case DW_MACRO_undef_sup
:
24615 unsigned int bytes_read
;
24617 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24618 mac_ptr
+= bytes_read
;
24619 mac_ptr
+= offset_size
;
24623 case DW_MACRO_import
:
24624 case DW_MACRO_import_sup
:
24625 /* Note that, according to the spec, a transparent include
24626 chain cannot call DW_MACRO_start_file. So, we can just
24627 skip this opcode. */
24628 mac_ptr
+= offset_size
;
24631 case DW_MACINFO_vendor_ext
:
24632 /* Only skip the data by MAC_PTR. */
24633 if (!section_is_gnu
)
24635 unsigned int bytes_read
;
24637 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24638 mac_ptr
+= bytes_read
;
24639 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24640 mac_ptr
+= bytes_read
;
24645 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
24646 mac_ptr
, mac_end
, abfd
, offset_size
,
24648 if (mac_ptr
== NULL
)
24653 } while (macinfo_type
!= 0 && current_file
== NULL
);
24655 /* Second pass: Process all entries.
24657 Use the AT_COMMAND_LINE flag to determine whether we are still processing
24658 command-line macro definitions/undefinitions. This flag is unset when we
24659 reach the first DW_MACINFO_start_file entry. */
24661 htab_up
include_hash (htab_create_alloc (1, htab_hash_pointer
,
24663 NULL
, xcalloc
, xfree
));
24664 mac_ptr
= section
->buffer
+ offset
;
24665 slot
= htab_find_slot (include_hash
.get (), mac_ptr
, INSERT
);
24666 *slot
= (void *) mac_ptr
;
24667 dwarf_decode_macro_bytes (cu
, abfd
, mac_ptr
, mac_end
,
24668 current_file
, lh
, section
,
24669 section_is_gnu
, 0, offset_size
,
24670 include_hash
.get ());
24673 /* Return the .debug_loc section to use for CU.
24674 For DWO files use .debug_loc.dwo. */
24676 static struct dwarf2_section_info
*
24677 cu_debug_loc_section (struct dwarf2_cu
*cu
)
24679 struct dwarf2_per_objfile
*dwarf2_per_objfile
24680 = cu
->per_cu
->dwarf2_per_objfile
;
24684 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24686 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
24688 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
24689 : &dwarf2_per_objfile
->loc
);
24692 /* A helper function that fills in a dwarf2_loclist_baton. */
24695 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
24696 struct dwarf2_loclist_baton
*baton
,
24697 const struct attribute
*attr
)
24699 struct dwarf2_per_objfile
*dwarf2_per_objfile
24700 = cu
->per_cu
->dwarf2_per_objfile
;
24701 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24703 section
->read (dwarf2_per_objfile
->objfile
);
24705 baton
->per_cu
= cu
->per_cu
;
24706 gdb_assert (baton
->per_cu
);
24707 /* We don't know how long the location list is, but make sure we
24708 don't run off the edge of the section. */
24709 baton
->size
= section
->size
- DW_UNSND (attr
);
24710 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
24711 baton
->base_address
= cu
->base_address
;
24712 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
24716 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
24717 struct dwarf2_cu
*cu
, int is_block
)
24719 struct dwarf2_per_objfile
*dwarf2_per_objfile
24720 = cu
->per_cu
->dwarf2_per_objfile
;
24721 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24722 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24724 if (attr
->form_is_section_offset ()
24725 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
24726 the section. If so, fall through to the complaint in the
24728 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
24730 struct dwarf2_loclist_baton
*baton
;
24732 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
24734 fill_in_loclist_baton (cu
, baton
, attr
);
24736 if (cu
->base_known
== 0)
24737 complaint (_("Location list used without "
24738 "specifying the CU base address."));
24740 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24741 ? dwarf2_loclist_block_index
24742 : dwarf2_loclist_index
);
24743 SYMBOL_LOCATION_BATON (sym
) = baton
;
24747 struct dwarf2_locexpr_baton
*baton
;
24749 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
24750 baton
->per_cu
= cu
->per_cu
;
24751 gdb_assert (baton
->per_cu
);
24753 if (attr
->form_is_block ())
24755 /* Note that we're just copying the block's data pointer
24756 here, not the actual data. We're still pointing into the
24757 info_buffer for SYM's objfile; right now we never release
24758 that buffer, but when we do clean up properly this may
24760 baton
->size
= DW_BLOCK (attr
)->size
;
24761 baton
->data
= DW_BLOCK (attr
)->data
;
24765 dwarf2_invalid_attrib_class_complaint ("location description",
24766 sym
->natural_name ());
24770 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24771 ? dwarf2_locexpr_block_index
24772 : dwarf2_locexpr_index
);
24773 SYMBOL_LOCATION_BATON (sym
) = baton
;
24777 /* Return the OBJFILE associated with the compilation unit CU. If CU
24778 came from a separate debuginfo file, then the master objfile is
24782 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
24784 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
24786 /* Return the master objfile, so that we can report and look up the
24787 correct file containing this variable. */
24788 if (objfile
->separate_debug_objfile_backlink
)
24789 objfile
= objfile
->separate_debug_objfile_backlink
;
24794 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
24795 (CU_HEADERP is unused in such case) or prepare a temporary copy at
24796 CU_HEADERP first. */
24798 static const struct comp_unit_head
*
24799 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
24800 struct dwarf2_per_cu_data
*per_cu
)
24802 const gdb_byte
*info_ptr
;
24805 return &per_cu
->cu
->header
;
24807 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
24809 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
24810 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
24811 rcuh_kind::COMPILE
);
24816 /* Return the address size given in the compilation unit header for CU. */
24819 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
24821 struct comp_unit_head cu_header_local
;
24822 const struct comp_unit_head
*cu_headerp
;
24824 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
24826 return cu_headerp
->addr_size
;
24829 /* Return the offset size given in the compilation unit header for CU. */
24832 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
24834 struct comp_unit_head cu_header_local
;
24835 const struct comp_unit_head
*cu_headerp
;
24837 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
24839 return cu_headerp
->offset_size
;
24842 /* See its dwarf2loc.h declaration. */
24845 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
24847 struct comp_unit_head cu_header_local
;
24848 const struct comp_unit_head
*cu_headerp
;
24850 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
24852 if (cu_headerp
->version
== 2)
24853 return cu_headerp
->addr_size
;
24855 return cu_headerp
->offset_size
;
24858 /* Return the text offset of the CU. The returned offset comes from
24859 this CU's objfile. If this objfile came from a separate debuginfo
24860 file, then the offset may be different from the corresponding
24861 offset in the parent objfile. */
24864 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
24866 return per_cu
->dwarf2_per_objfile
->objfile
->text_section_offset ();
24869 /* Return a type that is a generic pointer type, the size of which matches
24870 the address size given in the compilation unit header for PER_CU. */
24871 static struct type
*
24872 dwarf2_per_cu_addr_type (struct dwarf2_per_cu_data
*per_cu
)
24874 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
24875 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
24876 struct type
*addr_type
= lookup_pointer_type (void_type
);
24877 int addr_size
= dwarf2_per_cu_addr_size (per_cu
);
24879 if (TYPE_LENGTH (addr_type
) == addr_size
)
24883 = dwarf2_per_cu_addr_sized_int_type (per_cu
, TYPE_UNSIGNED (addr_type
));
24887 /* Return DWARF version number of PER_CU. */
24890 dwarf2_version (struct dwarf2_per_cu_data
*per_cu
)
24892 return per_cu
->dwarf_version
;
24895 /* Locate the .debug_info compilation unit from CU's objfile which contains
24896 the DIE at OFFSET. Raises an error on failure. */
24898 static struct dwarf2_per_cu_data
*
24899 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
24900 unsigned int offset_in_dwz
,
24901 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
24903 struct dwarf2_per_cu_data
*this_cu
;
24907 high
= dwarf2_per_objfile
->all_comp_units
.size () - 1;
24910 struct dwarf2_per_cu_data
*mid_cu
;
24911 int mid
= low
+ (high
- low
) / 2;
24913 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
24914 if (mid_cu
->is_dwz
> offset_in_dwz
24915 || (mid_cu
->is_dwz
== offset_in_dwz
24916 && mid_cu
->sect_off
+ mid_cu
->length
>= sect_off
))
24921 gdb_assert (low
== high
);
24922 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
24923 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
24925 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
24926 error (_("Dwarf Error: could not find partial DIE containing "
24927 "offset %s [in module %s]"),
24928 sect_offset_str (sect_off
),
24929 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
24931 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
24933 return dwarf2_per_objfile
->all_comp_units
[low
-1];
24937 if (low
== dwarf2_per_objfile
->all_comp_units
.size () - 1
24938 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
24939 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
24940 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
24945 /* Initialize dwarf2_cu CU, owned by PER_CU. */
24947 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data
*per_cu_
)
24948 : per_cu (per_cu_
),
24950 has_loclist (false),
24951 checked_producer (false),
24952 producer_is_gxx_lt_4_6 (false),
24953 producer_is_gcc_lt_4_3 (false),
24954 producer_is_icc (false),
24955 producer_is_icc_lt_14 (false),
24956 producer_is_codewarrior (false),
24957 processing_has_namespace_info (false)
24962 /* Destroy a dwarf2_cu. */
24964 dwarf2_cu::~dwarf2_cu ()
24969 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
24972 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
24973 enum language pretend_language
)
24975 struct attribute
*attr
;
24977 /* Set the language we're debugging. */
24978 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
24979 if (attr
!= nullptr)
24980 set_cu_language (DW_UNSND (attr
), cu
);
24983 cu
->language
= pretend_language
;
24984 cu
->language_defn
= language_def (cu
->language
);
24987 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
24990 /* Increase the age counter on each cached compilation unit, and free
24991 any that are too old. */
24994 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
24996 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
24998 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
24999 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25000 while (per_cu
!= NULL
)
25002 per_cu
->cu
->last_used
++;
25003 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
25004 dwarf2_mark (per_cu
->cu
);
25005 per_cu
= per_cu
->cu
->read_in_chain
;
25008 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25009 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25010 while (per_cu
!= NULL
)
25012 struct dwarf2_per_cu_data
*next_cu
;
25014 next_cu
= per_cu
->cu
->read_in_chain
;
25016 if (!per_cu
->cu
->mark
)
25019 *last_chain
= next_cu
;
25022 last_chain
= &per_cu
->cu
->read_in_chain
;
25028 /* Remove a single compilation unit from the cache. */
25031 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
25033 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25034 struct dwarf2_per_objfile
*dwarf2_per_objfile
25035 = target_per_cu
->dwarf2_per_objfile
;
25037 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25038 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25039 while (per_cu
!= NULL
)
25041 struct dwarf2_per_cu_data
*next_cu
;
25043 next_cu
= per_cu
->cu
->read_in_chain
;
25045 if (per_cu
== target_per_cu
)
25049 *last_chain
= next_cu
;
25053 last_chain
= &per_cu
->cu
->read_in_chain
;
25059 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
25060 We store these in a hash table separate from the DIEs, and preserve them
25061 when the DIEs are flushed out of cache.
25063 The CU "per_cu" pointer is needed because offset alone is not enough to
25064 uniquely identify the type. A file may have multiple .debug_types sections,
25065 or the type may come from a DWO file. Furthermore, while it's more logical
25066 to use per_cu->section+offset, with Fission the section with the data is in
25067 the DWO file but we don't know that section at the point we need it.
25068 We have to use something in dwarf2_per_cu_data (or the pointer to it)
25069 because we can enter the lookup routine, get_die_type_at_offset, from
25070 outside this file, and thus won't necessarily have PER_CU->cu.
25071 Fortunately, PER_CU is stable for the life of the objfile. */
25073 struct dwarf2_per_cu_offset_and_type
25075 const struct dwarf2_per_cu_data
*per_cu
;
25076 sect_offset sect_off
;
25080 /* Hash function for a dwarf2_per_cu_offset_and_type. */
25083 per_cu_offset_and_type_hash (const void *item
)
25085 const struct dwarf2_per_cu_offset_and_type
*ofs
25086 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
25088 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
25091 /* Equality function for a dwarf2_per_cu_offset_and_type. */
25094 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
25096 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
25097 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
25098 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
25099 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
25101 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
25102 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
25105 /* Set the type associated with DIE to TYPE. Save it in CU's hash
25106 table if necessary. For convenience, return TYPE.
25108 The DIEs reading must have careful ordering to:
25109 * Not cause infinite loops trying to read in DIEs as a prerequisite for
25110 reading current DIE.
25111 * Not trying to dereference contents of still incompletely read in types
25112 while reading in other DIEs.
25113 * Enable referencing still incompletely read in types just by a pointer to
25114 the type without accessing its fields.
25116 Therefore caller should follow these rules:
25117 * Try to fetch any prerequisite types we may need to build this DIE type
25118 before building the type and calling set_die_type.
25119 * After building type call set_die_type for current DIE as soon as
25120 possible before fetching more types to complete the current type.
25121 * Make the type as complete as possible before fetching more types. */
25123 static struct type
*
25124 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
25126 struct dwarf2_per_objfile
*dwarf2_per_objfile
25127 = cu
->per_cu
->dwarf2_per_objfile
;
25128 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
25129 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25130 struct attribute
*attr
;
25131 struct dynamic_prop prop
;
25133 /* For Ada types, make sure that the gnat-specific data is always
25134 initialized (if not already set). There are a few types where
25135 we should not be doing so, because the type-specific area is
25136 already used to hold some other piece of info (eg: TYPE_CODE_FLT
25137 where the type-specific area is used to store the floatformat).
25138 But this is not a problem, because the gnat-specific information
25139 is actually not needed for these types. */
25140 if (need_gnat_info (cu
)
25141 && TYPE_CODE (type
) != TYPE_CODE_FUNC
25142 && TYPE_CODE (type
) != TYPE_CODE_FLT
25143 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
25144 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
25145 && TYPE_CODE (type
) != TYPE_CODE_METHOD
25146 && !HAVE_GNAT_AUX_INFO (type
))
25147 INIT_GNAT_SPECIFIC (type
);
25149 /* Read DW_AT_allocated and set in type. */
25150 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
25151 if (attr
!= NULL
&& attr
->form_is_block ())
25153 struct type
*prop_type
25154 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
25155 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
25156 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
);
25158 else if (attr
!= NULL
)
25160 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
25161 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25162 sect_offset_str (die
->sect_off
));
25165 /* Read DW_AT_associated and set in type. */
25166 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
25167 if (attr
!= NULL
&& attr
->form_is_block ())
25169 struct type
*prop_type
25170 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
25171 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
25172 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
);
25174 else if (attr
!= NULL
)
25176 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
25177 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25178 sect_offset_str (die
->sect_off
));
25181 /* Read DW_AT_data_location and set in type. */
25182 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
25183 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
,
25184 dwarf2_per_cu_addr_type (cu
->per_cu
)))
25185 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
);
25187 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25188 dwarf2_per_objfile
->die_type_hash
25189 = htab_up (htab_create_alloc (127,
25190 per_cu_offset_and_type_hash
,
25191 per_cu_offset_and_type_eq
,
25192 NULL
, xcalloc
, xfree
));
25194 ofs
.per_cu
= cu
->per_cu
;
25195 ofs
.sect_off
= die
->sect_off
;
25197 slot
= (struct dwarf2_per_cu_offset_and_type
**)
25198 htab_find_slot (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
25200 complaint (_("A problem internal to GDB: DIE %s has type already set"),
25201 sect_offset_str (die
->sect_off
));
25202 *slot
= XOBNEW (&objfile
->objfile_obstack
,
25203 struct dwarf2_per_cu_offset_and_type
);
25208 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
25209 or return NULL if the die does not have a saved type. */
25211 static struct type
*
25212 get_die_type_at_offset (sect_offset sect_off
,
25213 struct dwarf2_per_cu_data
*per_cu
)
25215 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
25216 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
25218 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25221 ofs
.per_cu
= per_cu
;
25222 ofs
.sect_off
= sect_off
;
25223 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
25224 htab_find (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
));
25231 /* Look up the type for DIE in CU in die_type_hash,
25232 or return NULL if DIE does not have a saved type. */
25234 static struct type
*
25235 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
25237 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
25240 /* Add a dependence relationship from CU to REF_PER_CU. */
25243 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
25244 struct dwarf2_per_cu_data
*ref_per_cu
)
25248 if (cu
->dependencies
== NULL
)
25250 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
25251 NULL
, &cu
->comp_unit_obstack
,
25252 hashtab_obstack_allocate
,
25253 dummy_obstack_deallocate
);
25255 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
25257 *slot
= ref_per_cu
;
25260 /* Subroutine of dwarf2_mark to pass to htab_traverse.
25261 Set the mark field in every compilation unit in the
25262 cache that we must keep because we are keeping CU. */
25265 dwarf2_mark_helper (void **slot
, void *data
)
25267 struct dwarf2_per_cu_data
*per_cu
;
25269 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
25271 /* cu->dependencies references may not yet have been ever read if QUIT aborts
25272 reading of the chain. As such dependencies remain valid it is not much
25273 useful to track and undo them during QUIT cleanups. */
25274 if (per_cu
->cu
== NULL
)
25277 if (per_cu
->cu
->mark
)
25279 per_cu
->cu
->mark
= true;
25281 if (per_cu
->cu
->dependencies
!= NULL
)
25282 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
25287 /* Set the mark field in CU and in every other compilation unit in the
25288 cache that we must keep because we are keeping CU. */
25291 dwarf2_mark (struct dwarf2_cu
*cu
)
25296 if (cu
->dependencies
!= NULL
)
25297 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
25301 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
25305 per_cu
->cu
->mark
= false;
25306 per_cu
= per_cu
->cu
->read_in_chain
;
25310 /* Trivial hash function for partial_die_info: the hash value of a DIE
25311 is its offset in .debug_info for this objfile. */
25314 partial_die_hash (const void *item
)
25316 const struct partial_die_info
*part_die
25317 = (const struct partial_die_info
*) item
;
25319 return to_underlying (part_die
->sect_off
);
25322 /* Trivial comparison function for partial_die_info structures: two DIEs
25323 are equal if they have the same offset. */
25326 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
25328 const struct partial_die_info
*part_die_lhs
25329 = (const struct partial_die_info
*) item_lhs
;
25330 const struct partial_die_info
*part_die_rhs
25331 = (const struct partial_die_info
*) item_rhs
;
25333 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
25336 struct cmd_list_element
*set_dwarf_cmdlist
;
25337 struct cmd_list_element
*show_dwarf_cmdlist
;
25340 set_dwarf_cmd (const char *args
, int from_tty
)
25342 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
25347 show_dwarf_cmd (const char *args
, int from_tty
)
25349 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
25353 show_check_physname (struct ui_file
*file
, int from_tty
,
25354 struct cmd_list_element
*c
, const char *value
)
25356 fprintf_filtered (file
,
25357 _("Whether to check \"physname\" is %s.\n"),
25361 void _initialize_dwarf2_read ();
25363 _initialize_dwarf2_read ()
25365 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
25366 Set DWARF specific variables.\n\
25367 Configure DWARF variables such as the cache size."),
25368 &set_dwarf_cmdlist
, "maintenance set dwarf ",
25369 0/*allow-unknown*/, &maintenance_set_cmdlist
);
25371 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
25372 Show DWARF specific variables.\n\
25373 Show DWARF variables such as the cache size."),
25374 &show_dwarf_cmdlist
, "maintenance show dwarf ",
25375 0/*allow-unknown*/, &maintenance_show_cmdlist
);
25377 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
25378 &dwarf_max_cache_age
, _("\
25379 Set the upper bound on the age of cached DWARF compilation units."), _("\
25380 Show the upper bound on the age of cached DWARF compilation units."), _("\
25381 A higher limit means that cached compilation units will be stored\n\
25382 in memory longer, and more total memory will be used. Zero disables\n\
25383 caching, which can slow down startup."),
25385 show_dwarf_max_cache_age
,
25386 &set_dwarf_cmdlist
,
25387 &show_dwarf_cmdlist
);
25389 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
25390 Set debugging of the DWARF reader."), _("\
25391 Show debugging of the DWARF reader."), _("\
25392 When enabled (non-zero), debugging messages are printed during DWARF\n\
25393 reading and symtab expansion. A value of 1 (one) provides basic\n\
25394 information. A value greater than 1 provides more verbose information."),
25397 &setdebuglist
, &showdebuglist
);
25399 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
25400 Set debugging of the DWARF DIE reader."), _("\
25401 Show debugging of the DWARF DIE reader."), _("\
25402 When enabled (non-zero), DIEs are dumped after they are read in.\n\
25403 The value is the maximum depth to print."),
25406 &setdebuglist
, &showdebuglist
);
25408 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
25409 Set debugging of the dwarf line reader."), _("\
25410 Show debugging of the dwarf line reader."), _("\
25411 When enabled (non-zero), line number entries are dumped as they are read in.\n\
25412 A value of 1 (one) provides basic information.\n\
25413 A value greater than 1 provides more verbose information."),
25416 &setdebuglist
, &showdebuglist
);
25418 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
25419 Set cross-checking of \"physname\" code against demangler."), _("\
25420 Show cross-checking of \"physname\" code against demangler."), _("\
25421 When enabled, GDB's internal \"physname\" code is checked against\n\
25423 NULL
, show_check_physname
,
25424 &setdebuglist
, &showdebuglist
);
25426 add_setshow_boolean_cmd ("use-deprecated-index-sections",
25427 no_class
, &use_deprecated_index_sections
, _("\
25428 Set whether to use deprecated gdb_index sections."), _("\
25429 Show whether to use deprecated gdb_index sections."), _("\
25430 When enabled, deprecated .gdb_index sections are used anyway.\n\
25431 Normally they are ignored either because of a missing feature or\n\
25432 performance issue.\n\
25433 Warning: This option must be enabled before gdb reads the file."),
25436 &setlist
, &showlist
);
25438 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
25439 &dwarf2_locexpr_funcs
);
25440 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
25441 &dwarf2_loclist_funcs
);
25443 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
25444 &dwarf2_block_frame_base_locexpr_funcs
);
25445 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
25446 &dwarf2_block_frame_base_loclist_funcs
);
25449 selftests::register_test ("dw2_expand_symtabs_matching",
25450 selftests::dw2_expand_symtabs_matching::run_test
);