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 "dwarf2read.h"
33 #include "dwarf2/abbrev.h"
34 #include "dwarf2/attribute.h"
35 #include "dwarf-index-cache.h"
36 #include "dwarf-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 "dwarf2expr.h"
52 #include "dwarf2loc.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 *. */
871 htab_t loaded_cus
{};
872 htab_t loaded_tus
{};
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 value of the DW_AT_comp_dir attribute. */
907 const char *comp_dir
;
909 /* The abbreviation table to use when reading the DIEs. */
910 struct abbrev_table
*abbrev_table
;
913 /* A subclass of die_reader_specs that holds storage and has complex
914 constructor and destructor behavior. */
916 class cutu_reader
: public die_reader_specs
920 cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
921 struct abbrev_table
*abbrev_table
,
922 int use_existing_cu
, int keep
,
925 explicit cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
926 struct dwarf2_cu
*parent_cu
= nullptr,
927 struct dwo_file
*dwo_file
= nullptr);
931 DISABLE_COPY_AND_ASSIGN (cutu_reader
);
933 const gdb_byte
*info_ptr
= nullptr;
934 struct die_info
*comp_unit_die
= nullptr;
935 int has_children
= 0;
936 bool dummy_p
= false;
939 void init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
940 int use_existing_cu
, int keep
);
942 struct dwarf2_per_cu_data
*m_this_cu
;
944 std::unique_ptr
<dwarf2_cu
> m_new_cu
;
946 /* The ordinary abbreviation table. */
947 abbrev_table_up m_abbrev_table_holder
;
949 /* The DWO abbreviation table. */
950 abbrev_table_up m_dwo_abbrev_table
;
953 /* dir_index is 1-based in DWARF 4 and before, and is 0-based in DWARF 5 and
955 typedef int dir_index
;
957 /* file_name_index is 1-based in DWARF 4 and before, and is 0-based in DWARF 5
959 typedef int file_name_index
;
963 file_entry () = default;
965 file_entry (const char *name_
, dir_index d_index_
,
966 unsigned int mod_time_
, unsigned int length_
)
969 mod_time (mod_time_
),
973 /* Return the include directory at D_INDEX stored in LH. Returns
974 NULL if D_INDEX is out of bounds. */
975 const char *include_dir (const line_header
*lh
) const;
977 /* The file name. Note this is an observing pointer. The memory is
978 owned by debug_line_buffer. */
981 /* The directory index (1-based). */
982 dir_index d_index
{};
984 unsigned int mod_time
{};
986 unsigned int length
{};
988 /* True if referenced by the Line Number Program. */
991 /* The associated symbol table, if any. */
992 struct symtab
*symtab
{};
995 /* The line number information for a compilation unit (found in the
996 .debug_line section) begins with a "statement program header",
997 which contains the following information. */
1004 /* Add an entry to the include directory table. */
1005 void add_include_dir (const char *include_dir
);
1007 /* Add an entry to the file name table. */
1008 void add_file_name (const char *name
, dir_index d_index
,
1009 unsigned int mod_time
, unsigned int length
);
1011 /* Return the include dir at INDEX (0-based in DWARF 5 and 1-based before).
1012 Returns NULL if INDEX is out of bounds. */
1013 const char *include_dir_at (dir_index index
) const
1019 vec_index
= index
- 1;
1020 if (vec_index
< 0 || vec_index
>= m_include_dirs
.size ())
1022 return m_include_dirs
[vec_index
];
1025 bool is_valid_file_index (int file_index
)
1028 return 0 <= file_index
&& file_index
< file_names_size ();
1029 return 1 <= file_index
&& file_index
<= file_names_size ();
1032 /* Return the file name at INDEX (0-based in DWARF 5 and 1-based before).
1033 Returns NULL if INDEX is out of bounds. */
1034 file_entry
*file_name_at (file_name_index index
)
1040 vec_index
= index
- 1;
1041 if (vec_index
< 0 || vec_index
>= m_file_names
.size ())
1043 return &m_file_names
[vec_index
];
1046 /* The indexes are 0-based in DWARF 5 and 1-based in DWARF 4. Therefore,
1047 this method should only be used to iterate through all file entries in an
1048 index-agnostic manner. */
1049 std::vector
<file_entry
> &file_names ()
1050 { return m_file_names
; }
1052 /* Offset of line number information in .debug_line section. */
1053 sect_offset sect_off
{};
1055 /* OFFSET is for struct dwz_file associated with dwarf2_per_objfile. */
1056 unsigned offset_in_dwz
: 1; /* Can't initialize bitfields in-class. */
1058 unsigned int total_length
{};
1059 unsigned short version
{};
1060 unsigned int header_length
{};
1061 unsigned char minimum_instruction_length
{};
1062 unsigned char maximum_ops_per_instruction
{};
1063 unsigned char default_is_stmt
{};
1065 unsigned char line_range
{};
1066 unsigned char opcode_base
{};
1068 /* standard_opcode_lengths[i] is the number of operands for the
1069 standard opcode whose value is i. This means that
1070 standard_opcode_lengths[0] is unused, and the last meaningful
1071 element is standard_opcode_lengths[opcode_base - 1]. */
1072 std::unique_ptr
<unsigned char[]> standard_opcode_lengths
;
1074 int file_names_size ()
1075 { return m_file_names
.size(); }
1077 /* The start and end of the statement program following this
1078 header. These point into dwarf2_per_objfile->line_buffer. */
1079 const gdb_byte
*statement_program_start
{}, *statement_program_end
{};
1082 /* The include_directories table. Note these are observing
1083 pointers. The memory is owned by debug_line_buffer. */
1084 std::vector
<const char *> m_include_dirs
;
1086 /* The file_names table. This is private because the meaning of indexes
1087 differs among DWARF versions (The first valid index is 1 in DWARF 4 and
1088 before, and is 0 in DWARF 5 and later). So the client should use
1089 file_name_at method for access. */
1090 std::vector
<file_entry
> m_file_names
;
1093 typedef std::unique_ptr
<line_header
> line_header_up
;
1096 file_entry::include_dir (const line_header
*lh
) const
1098 return lh
->include_dir_at (d_index
);
1101 /* When we construct a partial symbol table entry we only
1102 need this much information. */
1103 struct partial_die_info
: public allocate_on_obstack
1105 partial_die_info (sect_offset sect_off
, struct abbrev_info
*abbrev
);
1107 /* Disable assign but still keep copy ctor, which is needed
1108 load_partial_dies. */
1109 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
1111 /* Adjust the partial die before generating a symbol for it. This
1112 function may set the is_external flag or change the DIE's
1114 void fixup (struct dwarf2_cu
*cu
);
1116 /* Read a minimal amount of information into the minimal die
1118 const gdb_byte
*read (const struct die_reader_specs
*reader
,
1119 const struct abbrev_info
&abbrev
,
1120 const gdb_byte
*info_ptr
);
1122 /* Offset of this DIE. */
1123 const sect_offset sect_off
;
1125 /* DWARF-2 tag for this DIE. */
1126 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1128 /* Assorted flags describing the data found in this DIE. */
1129 const unsigned int has_children
: 1;
1131 unsigned int is_external
: 1;
1132 unsigned int is_declaration
: 1;
1133 unsigned int has_type
: 1;
1134 unsigned int has_specification
: 1;
1135 unsigned int has_pc_info
: 1;
1136 unsigned int may_be_inlined
: 1;
1138 /* This DIE has been marked DW_AT_main_subprogram. */
1139 unsigned int main_subprogram
: 1;
1141 /* Flag set if the SCOPE field of this structure has been
1143 unsigned int scope_set
: 1;
1145 /* Flag set if the DIE has a byte_size attribute. */
1146 unsigned int has_byte_size
: 1;
1148 /* Flag set if the DIE has a DW_AT_const_value attribute. */
1149 unsigned int has_const_value
: 1;
1151 /* Flag set if any of the DIE's children are template arguments. */
1152 unsigned int has_template_arguments
: 1;
1154 /* Flag set if fixup has been called on this die. */
1155 unsigned int fixup_called
: 1;
1157 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1158 unsigned int is_dwz
: 1;
1160 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1161 unsigned int spec_is_dwz
: 1;
1163 /* The name of this DIE. Normally the value of DW_AT_name, but
1164 sometimes a default name for unnamed DIEs. */
1165 const char *name
= nullptr;
1167 /* The linkage name, if present. */
1168 const char *linkage_name
= nullptr;
1170 /* The scope to prepend to our children. This is generally
1171 allocated on the comp_unit_obstack, so will disappear
1172 when this compilation unit leaves the cache. */
1173 const char *scope
= nullptr;
1175 /* Some data associated with the partial DIE. The tag determines
1176 which field is live. */
1179 /* The location description associated with this DIE, if any. */
1180 struct dwarf_block
*locdesc
;
1181 /* The offset of an import, for DW_TAG_imported_unit. */
1182 sect_offset sect_off
;
1185 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1186 CORE_ADDR lowpc
= 0;
1187 CORE_ADDR highpc
= 0;
1189 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1190 DW_AT_sibling, if any. */
1191 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1192 could return DW_AT_sibling values to its caller load_partial_dies. */
1193 const gdb_byte
*sibling
= nullptr;
1195 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1196 DW_AT_specification (or DW_AT_abstract_origin or
1197 DW_AT_extension). */
1198 sect_offset spec_offset
{};
1200 /* Pointers to this DIE's parent, first child, and next sibling,
1202 struct partial_die_info
*die_parent
= nullptr;
1203 struct partial_die_info
*die_child
= nullptr;
1204 struct partial_die_info
*die_sibling
= nullptr;
1206 friend struct partial_die_info
*
1207 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1210 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1211 partial_die_info (sect_offset sect_off
)
1212 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1216 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1218 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1223 has_specification
= 0;
1226 main_subprogram
= 0;
1229 has_const_value
= 0;
1230 has_template_arguments
= 0;
1237 /* This data structure holds a complete die structure. */
1240 /* DWARF-2 tag for this DIE. */
1241 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1243 /* Number of attributes */
1244 unsigned char num_attrs
;
1246 /* True if we're presently building the full type name for the
1247 type derived from this DIE. */
1248 unsigned char building_fullname
: 1;
1250 /* True if this die is in process. PR 16581. */
1251 unsigned char in_process
: 1;
1254 unsigned int abbrev
;
1256 /* Offset in .debug_info or .debug_types section. */
1257 sect_offset sect_off
;
1259 /* The dies in a compilation unit form an n-ary tree. PARENT
1260 points to this die's parent; CHILD points to the first child of
1261 this node; and all the children of a given node are chained
1262 together via their SIBLING fields. */
1263 struct die_info
*child
; /* Its first child, if any. */
1264 struct die_info
*sibling
; /* Its next sibling, if any. */
1265 struct die_info
*parent
; /* Its parent, if any. */
1267 /* An array of attributes, with NUM_ATTRS elements. There may be
1268 zero, but it's not common and zero-sized arrays are not
1269 sufficiently portable C. */
1270 struct attribute attrs
[1];
1273 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1274 but this would require a corresponding change in unpack_field_as_long
1276 static int bits_per_byte
= 8;
1278 /* When reading a variant or variant part, we track a bit more
1279 information about the field, and store it in an object of this
1282 struct variant_field
1284 /* If we see a DW_TAG_variant, then this will be the discriminant
1286 ULONGEST discriminant_value
;
1287 /* If we see a DW_TAG_variant, then this will be set if this is the
1289 bool default_branch
;
1290 /* While reading a DW_TAG_variant_part, this will be set if this
1291 field is the discriminant. */
1292 bool is_discriminant
;
1297 int accessibility
= 0;
1299 /* Extra information to describe a variant or variant part. */
1300 struct variant_field variant
{};
1301 struct field field
{};
1306 const char *name
= nullptr;
1307 std::vector
<struct fn_field
> fnfields
;
1310 /* The routines that read and process dies for a C struct or C++ class
1311 pass lists of data member fields and lists of member function fields
1312 in an instance of a field_info structure, as defined below. */
1315 /* List of data member and baseclasses fields. */
1316 std::vector
<struct nextfield
> fields
;
1317 std::vector
<struct nextfield
> baseclasses
;
1319 /* Number of fields (including baseclasses). */
1322 /* Set if the accessibility of one of the fields is not public. */
1323 int non_public_fields
= 0;
1325 /* Member function fieldlist array, contains name of possibly overloaded
1326 member function, number of overloaded member functions and a pointer
1327 to the head of the member function field chain. */
1328 std::vector
<struct fnfieldlist
> fnfieldlists
;
1330 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1331 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1332 std::vector
<struct decl_field
> typedef_field_list
;
1334 /* Nested types defined by this class and the number of elements in this
1336 std::vector
<struct decl_field
> nested_types_list
;
1339 /* One item on the queue of compilation units to read in full symbols
1341 struct dwarf2_queue_item
1343 struct dwarf2_per_cu_data
*per_cu
;
1344 enum language pretend_language
;
1345 struct dwarf2_queue_item
*next
;
1348 /* The current queue. */
1349 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
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
,
1379 static void dwarf2_build_psymtabs_hard
1380 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1382 static void scan_partial_symbols (struct partial_die_info
*,
1383 CORE_ADDR
*, CORE_ADDR
*,
1384 int, struct dwarf2_cu
*);
1386 static void add_partial_symbol (struct partial_die_info
*,
1387 struct dwarf2_cu
*);
1389 static void add_partial_namespace (struct partial_die_info
*pdi
,
1390 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1391 int set_addrmap
, struct dwarf2_cu
*cu
);
1393 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1394 CORE_ADDR
*highpc
, int set_addrmap
,
1395 struct dwarf2_cu
*cu
);
1397 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1398 struct dwarf2_cu
*cu
);
1400 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1401 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1402 int need_pc
, struct dwarf2_cu
*cu
);
1404 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1406 static struct partial_die_info
*load_partial_dies
1407 (const struct die_reader_specs
*, const gdb_byte
*, int);
1409 /* A pair of partial_die_info and compilation unit. */
1410 struct cu_partial_die_info
1412 /* The compilation unit of the partial_die_info. */
1413 struct dwarf2_cu
*cu
;
1414 /* A partial_die_info. */
1415 struct partial_die_info
*pdi
;
1417 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1423 cu_partial_die_info () = delete;
1426 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1427 struct dwarf2_cu
*);
1429 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1430 struct attribute
*, struct attr_abbrev
*,
1431 const gdb_byte
*, bool *need_reprocess
);
1433 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1434 struct attribute
*attr
);
1436 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1438 static CORE_ADDR
read_address (bfd
*, const gdb_byte
*ptr
, struct dwarf2_cu
*,
1441 static LONGEST
read_initial_length (bfd
*, const gdb_byte
*, unsigned int *);
1443 static LONGEST read_checked_initial_length_and_offset
1444 (bfd
*, const gdb_byte
*, const struct comp_unit_head
*,
1445 unsigned int *, unsigned int *);
1447 static LONGEST
read_offset (bfd
*, const gdb_byte
*,
1448 const struct comp_unit_head
*,
1451 static LONGEST
read_offset_1 (bfd
*, const gdb_byte
*, unsigned int);
1453 static sect_offset read_abbrev_offset
1454 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1455 struct dwarf2_section_info
*, sect_offset
);
1457 static const gdb_byte
*read_n_bytes (bfd
*, const gdb_byte
*, unsigned int);
1459 static const char *read_direct_string (bfd
*, const gdb_byte
*, unsigned int *);
1461 static const char *read_indirect_string
1462 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1463 const struct comp_unit_head
*, unsigned int *);
1465 static const char *read_indirect_line_string
1466 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1467 const struct comp_unit_head
*, unsigned int *);
1469 static const char *read_indirect_string_at_offset
1470 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
1471 LONGEST str_offset
);
1473 static const char *read_indirect_string_from_dwz
1474 (struct objfile
*objfile
, struct dwz_file
*, LONGEST
);
1476 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1480 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1481 ULONGEST str_index
);
1483 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1484 ULONGEST str_index
);
1486 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1488 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1489 struct dwarf2_cu
*);
1491 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1494 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1495 struct dwarf2_cu
*cu
);
1497 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1499 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1500 struct dwarf2_cu
*cu
);
1502 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1504 static struct die_info
*die_specification (struct die_info
*die
,
1505 struct dwarf2_cu
**);
1507 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1508 struct dwarf2_cu
*cu
);
1510 static void dwarf_decode_lines (struct line_header
*, const char *,
1511 struct dwarf2_cu
*, dwarf2_psymtab
*,
1512 CORE_ADDR
, int decode_mapping
);
1514 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1517 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1518 struct dwarf2_cu
*, struct symbol
* = NULL
);
1520 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1521 struct dwarf2_cu
*);
1523 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1526 struct obstack
*obstack
,
1527 struct dwarf2_cu
*cu
, LONGEST
*value
,
1528 const gdb_byte
**bytes
,
1529 struct dwarf2_locexpr_baton
**baton
);
1531 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1533 static int need_gnat_info (struct dwarf2_cu
*);
1535 static struct type
*die_descriptive_type (struct die_info
*,
1536 struct dwarf2_cu
*);
1538 static void set_descriptive_type (struct type
*, struct die_info
*,
1539 struct dwarf2_cu
*);
1541 static struct type
*die_containing_type (struct die_info
*,
1542 struct dwarf2_cu
*);
1544 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1545 struct dwarf2_cu
*);
1547 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1549 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1551 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1553 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1554 const char *suffix
, int physname
,
1555 struct dwarf2_cu
*cu
);
1557 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1559 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1561 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1563 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1565 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1567 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1569 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1570 struct dwarf2_cu
*, dwarf2_psymtab
*);
1572 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1573 values. Keep the items ordered with increasing constraints compliance. */
1576 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1577 PC_BOUNDS_NOT_PRESENT
,
1579 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1580 were present but they do not form a valid range of PC addresses. */
1583 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1586 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1590 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1591 CORE_ADDR
*, CORE_ADDR
*,
1595 static void get_scope_pc_bounds (struct die_info
*,
1596 CORE_ADDR
*, CORE_ADDR
*,
1597 struct dwarf2_cu
*);
1599 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1600 CORE_ADDR
, struct dwarf2_cu
*);
1602 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1603 struct dwarf2_cu
*);
1605 static void dwarf2_attach_fields_to_type (struct field_info
*,
1606 struct type
*, struct dwarf2_cu
*);
1608 static void dwarf2_add_member_fn (struct field_info
*,
1609 struct die_info
*, struct type
*,
1610 struct dwarf2_cu
*);
1612 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1614 struct dwarf2_cu
*);
1616 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1618 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1620 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1622 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1624 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1626 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1628 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1630 static struct type
*read_module_type (struct die_info
*die
,
1631 struct dwarf2_cu
*cu
);
1633 static const char *namespace_name (struct die_info
*die
,
1634 int *is_anonymous
, struct dwarf2_cu
*);
1636 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1638 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1640 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1641 struct dwarf2_cu
*);
1643 static struct die_info
*read_die_and_siblings_1
1644 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1647 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1648 const gdb_byte
*info_ptr
,
1649 const gdb_byte
**new_info_ptr
,
1650 struct die_info
*parent
);
1652 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1653 struct die_info
**, const gdb_byte
*,
1656 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1657 struct die_info
**, const gdb_byte
*,
1660 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1662 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1665 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1667 static const char *dwarf2_full_name (const char *name
,
1668 struct die_info
*die
,
1669 struct dwarf2_cu
*cu
);
1671 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1672 struct dwarf2_cu
*cu
);
1674 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1675 struct dwarf2_cu
**);
1677 static const char *dwarf_tag_name (unsigned int);
1679 static const char *dwarf_attr_name (unsigned int);
1681 static const char *dwarf_unit_type_name (int unit_type
);
1683 static const char *dwarf_form_name (unsigned int);
1685 static const char *dwarf_bool_name (unsigned int);
1687 static const char *dwarf_type_encoding_name (unsigned int);
1689 static struct die_info
*sibling_die (struct die_info
*);
1691 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1693 static void dump_die_for_error (struct die_info
*);
1695 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1698 /*static*/ void dump_die (struct die_info
*, int max_level
);
1700 static void store_in_ref_table (struct die_info
*,
1701 struct dwarf2_cu
*);
1703 static sect_offset
dwarf2_get_ref_die_offset (const struct attribute
*);
1705 static LONGEST
dwarf2_get_attr_constant_value (const struct attribute
*, int);
1707 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1708 const struct attribute
*,
1709 struct dwarf2_cu
**);
1711 static struct die_info
*follow_die_ref (struct die_info
*,
1712 const struct attribute
*,
1713 struct dwarf2_cu
**);
1715 static struct die_info
*follow_die_sig (struct die_info
*,
1716 const struct attribute
*,
1717 struct dwarf2_cu
**);
1719 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1720 struct dwarf2_cu
*);
1722 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1723 const struct attribute
*,
1724 struct dwarf2_cu
*);
1726 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1728 static void read_signatured_type (struct signatured_type
*);
1730 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1731 struct die_info
*die
, struct dwarf2_cu
*cu
,
1732 struct dynamic_prop
*prop
, struct type
*type
);
1734 /* memory allocation interface */
1736 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1738 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1740 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1742 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1743 struct dwarf2_loclist_baton
*baton
,
1744 const struct attribute
*attr
);
1746 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1748 struct dwarf2_cu
*cu
,
1751 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1752 const gdb_byte
*info_ptr
,
1753 struct abbrev_info
*abbrev
);
1755 static hashval_t
partial_die_hash (const void *item
);
1757 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1759 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1760 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1761 struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1763 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1764 struct die_info
*comp_unit_die
,
1765 enum language pretend_language
);
1767 static void age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1769 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1771 static struct type
*set_die_type (struct die_info
*, struct type
*,
1772 struct dwarf2_cu
*);
1774 static void create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1776 static int create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1778 static void load_full_comp_unit (struct dwarf2_per_cu_data
*, bool,
1781 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1784 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1787 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1788 struct dwarf2_per_cu_data
*);
1790 static void dwarf2_mark (struct dwarf2_cu
*);
1792 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1794 static struct type
*get_die_type_at_offset (sect_offset
,
1795 struct dwarf2_per_cu_data
*);
1797 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1799 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1800 enum language pretend_language
);
1802 static void process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1804 static struct type
*dwarf2_per_cu_addr_type (struct dwarf2_per_cu_data
*per_cu
);
1805 static struct type
*dwarf2_per_cu_addr_sized_int_type
1806 (struct dwarf2_per_cu_data
*per_cu
, bool unsigned_p
);
1807 static struct type
*dwarf2_per_cu_int_type
1808 (struct dwarf2_per_cu_data
*per_cu
, int size_in_bytes
,
1811 /* Class, the destructor of which frees all allocated queue entries. This
1812 will only have work to do if an error was thrown while processing the
1813 dwarf. If no error was thrown then the queue entries should have all
1814 been processed, and freed, as we went along. */
1816 class dwarf2_queue_guard
1819 dwarf2_queue_guard () = default;
1821 /* Free any entries remaining on the queue. There should only be
1822 entries left if we hit an error while processing the dwarf. */
1823 ~dwarf2_queue_guard ()
1825 struct dwarf2_queue_item
*item
, *last
;
1827 item
= dwarf2_queue
;
1830 /* Anything still marked queued is likely to be in an
1831 inconsistent state, so discard it. */
1832 if (item
->per_cu
->queued
)
1834 if (item
->per_cu
->cu
!= NULL
)
1835 free_one_cached_comp_unit (item
->per_cu
);
1836 item
->per_cu
->queued
= 0;
1844 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
1848 /* The return type of find_file_and_directory. Note, the enclosed
1849 string pointers are only valid while this object is valid. */
1851 struct file_and_directory
1853 /* The filename. This is never NULL. */
1856 /* The compilation directory. NULL if not known. If we needed to
1857 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1858 points directly to the DW_AT_comp_dir string attribute owned by
1859 the obstack that owns the DIE. */
1860 const char *comp_dir
;
1862 /* If we needed to build a new string for comp_dir, this is what
1863 owns the storage. */
1864 std::string comp_dir_storage
;
1867 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1868 struct dwarf2_cu
*cu
);
1870 static char *file_full_name (int file
, struct line_header
*lh
,
1871 const char *comp_dir
);
1873 /* Expected enum dwarf_unit_type for read_comp_unit_head. */
1874 enum class rcuh_kind
{ COMPILE
, TYPE
};
1876 static const gdb_byte
*read_and_check_comp_unit_head
1877 (struct dwarf2_per_objfile
* dwarf2_per_objfile
,
1878 struct comp_unit_head
*header
,
1879 struct dwarf2_section_info
*section
,
1880 struct dwarf2_section_info
*abbrev_section
, const gdb_byte
*info_ptr
,
1881 rcuh_kind section_kind
);
1883 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1885 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
1887 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1888 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1889 struct dwp_file
*dwp_file
, const char *comp_dir
,
1890 ULONGEST signature
, int is_debug_types
);
1892 static struct dwp_file
*get_dwp_file
1893 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1895 static struct dwo_unit
*lookup_dwo_comp_unit
1896 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
1898 static struct dwo_unit
*lookup_dwo_type_unit
1899 (struct signatured_type
*, const char *, const char *);
1901 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
1903 /* A unique pointer to a dwo_file. */
1905 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1907 static void process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1909 static void check_producer (struct dwarf2_cu
*cu
);
1911 static void free_line_header_voidp (void *arg
);
1913 /* Various complaints about symbol reading that don't abort the process. */
1916 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
1918 complaint (_("statement list doesn't fit in .debug_line section"));
1922 dwarf2_debug_line_missing_file_complaint (void)
1924 complaint (_(".debug_line section has line data without a file"));
1928 dwarf2_debug_line_missing_end_sequence_complaint (void)
1930 complaint (_(".debug_line section has line "
1931 "program sequence without an end"));
1935 dwarf2_complex_location_expr_complaint (void)
1937 complaint (_("location expression too complex"));
1941 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1944 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1949 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
1951 complaint (_("debug info runs off end of %s section"
1953 section
->get_name (),
1954 section
->get_file_name ());
1958 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
1960 complaint (_("macro debug info contains a "
1961 "malformed macro definition:\n`%s'"),
1966 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1968 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1972 /* Hash function for line_header_hash. */
1975 line_header_hash (const struct line_header
*ofs
)
1977 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1980 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1983 line_header_hash_voidp (const void *item
)
1985 const struct line_header
*ofs
= (const struct line_header
*) item
;
1987 return line_header_hash (ofs
);
1990 /* Equality function for line_header_hash. */
1993 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1995 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1996 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1998 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1999 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
2004 /* See declaration. */
2006 dwarf2_per_objfile::dwarf2_per_objfile (struct objfile
*objfile_
,
2007 const dwarf2_debug_sections
*names
,
2009 : objfile (objfile_
),
2010 can_copy (can_copy_
)
2013 names
= &dwarf2_elf_names
;
2015 bfd
*obfd
= objfile
->obfd
;
2017 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
2018 locate_sections (obfd
, sec
, *names
);
2021 dwarf2_per_objfile::~dwarf2_per_objfile ()
2023 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
2024 free_cached_comp_units ();
2026 if (quick_file_names_table
)
2027 htab_delete (quick_file_names_table
);
2029 if (line_header_hash
)
2030 htab_delete (line_header_hash
);
2032 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
2033 per_cu
->imported_symtabs_free ();
2035 for (signatured_type
*sig_type
: all_type_units
)
2036 sig_type
->per_cu
.imported_symtabs_free ();
2038 /* Everything else should be on the objfile obstack. */
2041 /* See declaration. */
2044 dwarf2_per_objfile::free_cached_comp_units ()
2046 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
2047 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
2048 while (per_cu
!= NULL
)
2050 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
2053 *last_chain
= next_cu
;
2058 /* A helper class that calls free_cached_comp_units on
2061 class free_cached_comp_units
2065 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
2066 : m_per_objfile (per_objfile
)
2070 ~free_cached_comp_units ()
2072 m_per_objfile
->free_cached_comp_units ();
2075 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
2079 dwarf2_per_objfile
*m_per_objfile
;
2082 /* Try to locate the sections we need for DWARF 2 debugging
2083 information and return true if we have enough to do something.
2084 NAMES points to the dwarf2 section names, or is NULL if the standard
2085 ELF names are used. CAN_COPY is true for formats where symbol
2086 interposition is possible and so symbol values must follow copy
2087 relocation rules. */
2090 dwarf2_has_info (struct objfile
*objfile
,
2091 const struct dwarf2_debug_sections
*names
,
2094 if (objfile
->flags
& OBJF_READNEVER
)
2097 struct dwarf2_per_objfile
*dwarf2_per_objfile
2098 = get_dwarf2_per_objfile (objfile
);
2100 if (dwarf2_per_objfile
== NULL
)
2101 dwarf2_per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
,
2105 return (!dwarf2_per_objfile
->info
.is_virtual
2106 && dwarf2_per_objfile
->info
.s
.section
!= NULL
2107 && !dwarf2_per_objfile
->abbrev
.is_virtual
2108 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
2111 /* When loading sections, we look either for uncompressed section or for
2112 compressed section names. */
2115 section_is_p (const char *section_name
,
2116 const struct dwarf2_section_names
*names
)
2118 if (names
->normal
!= NULL
2119 && strcmp (section_name
, names
->normal
) == 0)
2121 if (names
->compressed
!= NULL
2122 && strcmp (section_name
, names
->compressed
) == 0)
2127 /* See declaration. */
2130 dwarf2_per_objfile::locate_sections (bfd
*abfd
, asection
*sectp
,
2131 const dwarf2_debug_sections
&names
)
2133 flagword aflag
= bfd_section_flags (sectp
);
2135 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
2138 else if (elf_section_data (sectp
)->this_hdr
.sh_size
2139 > bfd_get_file_size (abfd
))
2141 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
2142 warning (_("Discarding section %s which has a section size (%s"
2143 ") larger than the file size [in module %s]"),
2144 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
2145 bfd_get_filename (abfd
));
2147 else if (section_is_p (sectp
->name
, &names
.info
))
2149 this->info
.s
.section
= sectp
;
2150 this->info
.size
= bfd_section_size (sectp
);
2152 else if (section_is_p (sectp
->name
, &names
.abbrev
))
2154 this->abbrev
.s
.section
= sectp
;
2155 this->abbrev
.size
= bfd_section_size (sectp
);
2157 else if (section_is_p (sectp
->name
, &names
.line
))
2159 this->line
.s
.section
= sectp
;
2160 this->line
.size
= bfd_section_size (sectp
);
2162 else if (section_is_p (sectp
->name
, &names
.loc
))
2164 this->loc
.s
.section
= sectp
;
2165 this->loc
.size
= bfd_section_size (sectp
);
2167 else if (section_is_p (sectp
->name
, &names
.loclists
))
2169 this->loclists
.s
.section
= sectp
;
2170 this->loclists
.size
= bfd_section_size (sectp
);
2172 else if (section_is_p (sectp
->name
, &names
.macinfo
))
2174 this->macinfo
.s
.section
= sectp
;
2175 this->macinfo
.size
= bfd_section_size (sectp
);
2177 else if (section_is_p (sectp
->name
, &names
.macro
))
2179 this->macro
.s
.section
= sectp
;
2180 this->macro
.size
= bfd_section_size (sectp
);
2182 else if (section_is_p (sectp
->name
, &names
.str
))
2184 this->str
.s
.section
= sectp
;
2185 this->str
.size
= bfd_section_size (sectp
);
2187 else if (section_is_p (sectp
->name
, &names
.str_offsets
))
2189 this->str_offsets
.s
.section
= sectp
;
2190 this->str_offsets
.size
= bfd_section_size (sectp
);
2192 else if (section_is_p (sectp
->name
, &names
.line_str
))
2194 this->line_str
.s
.section
= sectp
;
2195 this->line_str
.size
= bfd_section_size (sectp
);
2197 else if (section_is_p (sectp
->name
, &names
.addr
))
2199 this->addr
.s
.section
= sectp
;
2200 this->addr
.size
= bfd_section_size (sectp
);
2202 else if (section_is_p (sectp
->name
, &names
.frame
))
2204 this->frame
.s
.section
= sectp
;
2205 this->frame
.size
= bfd_section_size (sectp
);
2207 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
2209 this->eh_frame
.s
.section
= sectp
;
2210 this->eh_frame
.size
= bfd_section_size (sectp
);
2212 else if (section_is_p (sectp
->name
, &names
.ranges
))
2214 this->ranges
.s
.section
= sectp
;
2215 this->ranges
.size
= bfd_section_size (sectp
);
2217 else if (section_is_p (sectp
->name
, &names
.rnglists
))
2219 this->rnglists
.s
.section
= sectp
;
2220 this->rnglists
.size
= bfd_section_size (sectp
);
2222 else if (section_is_p (sectp
->name
, &names
.types
))
2224 struct dwarf2_section_info type_section
;
2226 memset (&type_section
, 0, sizeof (type_section
));
2227 type_section
.s
.section
= sectp
;
2228 type_section
.size
= bfd_section_size (sectp
);
2230 this->types
.push_back (type_section
);
2232 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
2234 this->gdb_index
.s
.section
= sectp
;
2235 this->gdb_index
.size
= bfd_section_size (sectp
);
2237 else if (section_is_p (sectp
->name
, &names
.debug_names
))
2239 this->debug_names
.s
.section
= sectp
;
2240 this->debug_names
.size
= bfd_section_size (sectp
);
2242 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
2244 this->debug_aranges
.s
.section
= sectp
;
2245 this->debug_aranges
.size
= bfd_section_size (sectp
);
2248 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2249 && bfd_section_vma (sectp
) == 0)
2250 this->has_section_at_zero
= true;
2253 /* A helper function that returns the size of a section in a safe way.
2254 If you are positive that the section has been read before using the
2255 size, then it is safe to refer to the dwarf2_section_info object's
2256 "size" field directly. In other cases, you must call this
2257 function, because for compressed sections the size field is not set
2258 correctly until the section has been read. */
2260 static bfd_size_type
2261 dwarf2_section_size (struct objfile
*objfile
,
2262 struct dwarf2_section_info
*info
)
2265 info
->read (objfile
);
2269 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2273 dwarf2_get_section_info (struct objfile
*objfile
,
2274 enum dwarf2_section_enum sect
,
2275 asection
**sectp
, const gdb_byte
**bufp
,
2276 bfd_size_type
*sizep
)
2278 struct dwarf2_per_objfile
*data
= dwarf2_objfile_data_key
.get (objfile
);
2279 struct dwarf2_section_info
*info
;
2281 /* We may see an objfile without any DWARF, in which case we just
2292 case DWARF2_DEBUG_FRAME
:
2293 info
= &data
->frame
;
2295 case DWARF2_EH_FRAME
:
2296 info
= &data
->eh_frame
;
2299 gdb_assert_not_reached ("unexpected section");
2302 info
->read (objfile
);
2304 *sectp
= info
->get_bfd_section ();
2305 *bufp
= info
->buffer
;
2306 *sizep
= info
->size
;
2309 /* A helper function to find the sections for a .dwz file. */
2312 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2314 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2316 /* Note that we only support the standard ELF names, because .dwz
2317 is ELF-only (at the time of writing). */
2318 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2320 dwz_file
->abbrev
.s
.section
= sectp
;
2321 dwz_file
->abbrev
.size
= bfd_section_size (sectp
);
2323 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2325 dwz_file
->info
.s
.section
= sectp
;
2326 dwz_file
->info
.size
= bfd_section_size (sectp
);
2328 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2330 dwz_file
->str
.s
.section
= sectp
;
2331 dwz_file
->str
.size
= bfd_section_size (sectp
);
2333 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2335 dwz_file
->line
.s
.section
= sectp
;
2336 dwz_file
->line
.size
= bfd_section_size (sectp
);
2338 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2340 dwz_file
->macro
.s
.section
= sectp
;
2341 dwz_file
->macro
.size
= bfd_section_size (sectp
);
2343 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2345 dwz_file
->gdb_index
.s
.section
= sectp
;
2346 dwz_file
->gdb_index
.size
= bfd_section_size (sectp
);
2348 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2350 dwz_file
->debug_names
.s
.section
= sectp
;
2351 dwz_file
->debug_names
.size
= bfd_section_size (sectp
);
2355 /* See dwarf2read.h. */
2358 dwarf2_get_dwz_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
2360 const char *filename
;
2361 bfd_size_type buildid_len_arg
;
2365 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2366 return dwarf2_per_objfile
->dwz_file
.get ();
2368 bfd_set_error (bfd_error_no_error
);
2369 gdb::unique_xmalloc_ptr
<char> data
2370 (bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2371 &buildid_len_arg
, &buildid
));
2374 if (bfd_get_error () == bfd_error_no_error
)
2376 error (_("could not read '.gnu_debugaltlink' section: %s"),
2377 bfd_errmsg (bfd_get_error ()));
2380 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2382 buildid_len
= (size_t) buildid_len_arg
;
2384 filename
= data
.get ();
2386 std::string abs_storage
;
2387 if (!IS_ABSOLUTE_PATH (filename
))
2389 gdb::unique_xmalloc_ptr
<char> abs
2390 = gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2392 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2393 filename
= abs_storage
.c_str ();
2396 /* First try the file name given in the section. If that doesn't
2397 work, try to use the build-id instead. */
2398 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
, -1));
2399 if (dwz_bfd
!= NULL
)
2401 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2402 dwz_bfd
.reset (nullptr);
2405 if (dwz_bfd
== NULL
)
2406 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2408 if (dwz_bfd
== NULL
)
2409 error (_("could not find '.gnu_debugaltlink' file for %s"),
2410 objfile_name (dwarf2_per_objfile
->objfile
));
2412 std::unique_ptr
<struct dwz_file
> result
2413 (new struct dwz_file (std::move (dwz_bfd
)));
2415 bfd_map_over_sections (result
->dwz_bfd
.get (), locate_dwz_sections
,
2418 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
,
2419 result
->dwz_bfd
.get ());
2420 dwarf2_per_objfile
->dwz_file
= std::move (result
);
2421 return dwarf2_per_objfile
->dwz_file
.get ();
2424 /* DWARF quick_symbols_functions support. */
2426 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2427 unique line tables, so we maintain a separate table of all .debug_line
2428 derived entries to support the sharing.
2429 All the quick functions need is the list of file names. We discard the
2430 line_header when we're done and don't need to record it here. */
2431 struct quick_file_names
2433 /* The data used to construct the hash key. */
2434 struct stmt_list_hash hash
;
2436 /* The number of entries in file_names, real_names. */
2437 unsigned int num_file_names
;
2439 /* The file names from the line table, after being run through
2441 const char **file_names
;
2443 /* The file names from the line table after being run through
2444 gdb_realpath. These are computed lazily. */
2445 const char **real_names
;
2448 /* When using the index (and thus not using psymtabs), each CU has an
2449 object of this type. This is used to hold information needed by
2450 the various "quick" methods. */
2451 struct dwarf2_per_cu_quick_data
2453 /* The file table. This can be NULL if there was no file table
2454 or it's currently not read in.
2455 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2456 struct quick_file_names
*file_names
;
2458 /* The corresponding symbol table. This is NULL if symbols for this
2459 CU have not yet been read. */
2460 struct compunit_symtab
*compunit_symtab
;
2462 /* A temporary mark bit used when iterating over all CUs in
2463 expand_symtabs_matching. */
2464 unsigned int mark
: 1;
2466 /* True if we've tried to read the file table and found there isn't one.
2467 There will be no point in trying to read it again next time. */
2468 unsigned int no_file_data
: 1;
2471 /* Utility hash function for a stmt_list_hash. */
2474 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2478 if (stmt_list_hash
->dwo_unit
!= NULL
)
2479 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2480 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2484 /* Utility equality function for a stmt_list_hash. */
2487 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2488 const struct stmt_list_hash
*rhs
)
2490 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2492 if (lhs
->dwo_unit
!= NULL
2493 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2496 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2499 /* Hash function for a quick_file_names. */
2502 hash_file_name_entry (const void *e
)
2504 const struct quick_file_names
*file_data
2505 = (const struct quick_file_names
*) e
;
2507 return hash_stmt_list_entry (&file_data
->hash
);
2510 /* Equality function for a quick_file_names. */
2513 eq_file_name_entry (const void *a
, const void *b
)
2515 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2516 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2518 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2521 /* Delete function for a quick_file_names. */
2524 delete_file_name_entry (void *e
)
2526 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2529 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2531 xfree ((void*) file_data
->file_names
[i
]);
2532 if (file_data
->real_names
)
2533 xfree ((void*) file_data
->real_names
[i
]);
2536 /* The space for the struct itself lives on objfile_obstack,
2537 so we don't free it here. */
2540 /* Create a quick_file_names hash table. */
2543 create_quick_file_names_table (unsigned int nr_initial_entries
)
2545 return htab_create_alloc (nr_initial_entries
,
2546 hash_file_name_entry
, eq_file_name_entry
,
2547 delete_file_name_entry
, xcalloc
, xfree
);
2550 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2551 have to be created afterwards. You should call age_cached_comp_units after
2552 processing PER_CU->CU. dw2_setup must have been already called. */
2555 load_cu (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2557 if (per_cu
->is_debug_types
)
2558 load_full_type_unit (per_cu
);
2560 load_full_comp_unit (per_cu
, skip_partial
, language_minimal
);
2562 if (per_cu
->cu
== NULL
)
2563 return; /* Dummy CU. */
2565 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2568 /* Read in the symbols for PER_CU. */
2571 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2573 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2575 /* Skip type_unit_groups, reading the type units they contain
2576 is handled elsewhere. */
2577 if (IS_TYPE_UNIT_GROUP (per_cu
))
2580 /* The destructor of dwarf2_queue_guard frees any entries left on
2581 the queue. After this point we're guaranteed to leave this function
2582 with the dwarf queue empty. */
2583 dwarf2_queue_guard q_guard
;
2585 if (dwarf2_per_objfile
->using_index
2586 ? per_cu
->v
.quick
->compunit_symtab
== NULL
2587 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2589 queue_comp_unit (per_cu
, language_minimal
);
2590 load_cu (per_cu
, skip_partial
);
2592 /* If we just loaded a CU from a DWO, and we're working with an index
2593 that may badly handle TUs, load all the TUs in that DWO as well.
2594 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2595 if (!per_cu
->is_debug_types
2596 && per_cu
->cu
!= NULL
2597 && per_cu
->cu
->dwo_unit
!= NULL
2598 && dwarf2_per_objfile
->index_table
!= NULL
2599 && dwarf2_per_objfile
->index_table
->version
<= 7
2600 /* DWP files aren't supported yet. */
2601 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
2602 queue_and_load_all_dwo_tus (per_cu
);
2605 process_queue (dwarf2_per_objfile
);
2607 /* Age the cache, releasing compilation units that have not
2608 been used recently. */
2609 age_cached_comp_units (dwarf2_per_objfile
);
2612 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2613 the objfile from which this CU came. Returns the resulting symbol
2616 static struct compunit_symtab
*
2617 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2619 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2621 gdb_assert (dwarf2_per_objfile
->using_index
);
2622 if (!per_cu
->v
.quick
->compunit_symtab
)
2624 free_cached_comp_units
freer (dwarf2_per_objfile
);
2625 scoped_restore decrementer
= increment_reading_symtab ();
2626 dw2_do_instantiate_symtab (per_cu
, skip_partial
);
2627 process_cu_includes (dwarf2_per_objfile
);
2630 return per_cu
->v
.quick
->compunit_symtab
;
2633 /* See declaration. */
2635 dwarf2_per_cu_data
*
2636 dwarf2_per_objfile::get_cutu (int index
)
2638 if (index
>= this->all_comp_units
.size ())
2640 index
-= this->all_comp_units
.size ();
2641 gdb_assert (index
< this->all_type_units
.size ());
2642 return &this->all_type_units
[index
]->per_cu
;
2645 return this->all_comp_units
[index
];
2648 /* See declaration. */
2650 dwarf2_per_cu_data
*
2651 dwarf2_per_objfile::get_cu (int index
)
2653 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2655 return this->all_comp_units
[index
];
2658 /* See declaration. */
2661 dwarf2_per_objfile::get_tu (int index
)
2663 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2665 return this->all_type_units
[index
];
2668 /* Return a new dwarf2_per_cu_data allocated on OBJFILE's
2669 objfile_obstack, and constructed with the specified field
2672 static dwarf2_per_cu_data
*
2673 create_cu_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2674 struct dwarf2_section_info
*section
,
2676 sect_offset sect_off
, ULONGEST length
)
2678 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2679 dwarf2_per_cu_data
*the_cu
2680 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2681 struct dwarf2_per_cu_data
);
2682 the_cu
->sect_off
= sect_off
;
2683 the_cu
->length
= length
;
2684 the_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
2685 the_cu
->section
= section
;
2686 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2687 struct dwarf2_per_cu_quick_data
);
2688 the_cu
->is_dwz
= is_dwz
;
2692 /* A helper for create_cus_from_index that handles a given list of
2696 create_cus_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2697 const gdb_byte
*cu_list
, offset_type n_elements
,
2698 struct dwarf2_section_info
*section
,
2701 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2703 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2705 sect_offset sect_off
2706 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2707 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2710 dwarf2_per_cu_data
*per_cu
2711 = create_cu_from_index_list (dwarf2_per_objfile
, section
, is_dwz
,
2713 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
2717 /* Read the CU list from the mapped index, and use it to create all
2718 the CU objects for this objfile. */
2721 create_cus_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2722 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2723 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2725 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
2726 dwarf2_per_objfile
->all_comp_units
.reserve
2727 ((cu_list_elements
+ dwz_elements
) / 2);
2729 create_cus_from_index_list (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
2730 &dwarf2_per_objfile
->info
, 0);
2732 if (dwz_elements
== 0)
2735 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
2736 create_cus_from_index_list (dwarf2_per_objfile
, dwz_list
, dwz_elements
,
2740 /* Create the signatured type hash table from the index. */
2743 create_signatured_type_table_from_index
2744 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2745 struct dwarf2_section_info
*section
,
2746 const gdb_byte
*bytes
,
2747 offset_type elements
)
2749 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2751 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
2752 dwarf2_per_objfile
->all_type_units
.reserve (elements
/ 3);
2754 htab_t sig_types_hash
= allocate_signatured_type_table (objfile
);
2756 for (offset_type i
= 0; i
< elements
; i
+= 3)
2758 struct signatured_type
*sig_type
;
2761 cu_offset type_offset_in_tu
;
2763 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2764 sect_offset sect_off
2765 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2767 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2769 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2772 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2773 struct signatured_type
);
2774 sig_type
->signature
= signature
;
2775 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2776 sig_type
->per_cu
.is_debug_types
= 1;
2777 sig_type
->per_cu
.section
= section
;
2778 sig_type
->per_cu
.sect_off
= sect_off
;
2779 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
2780 sig_type
->per_cu
.v
.quick
2781 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2782 struct dwarf2_per_cu_quick_data
);
2784 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
2787 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
2790 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
2793 /* Create the signatured type hash table from .debug_names. */
2796 create_signatured_type_table_from_debug_names
2797 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2798 const mapped_debug_names
&map
,
2799 struct dwarf2_section_info
*section
,
2800 struct dwarf2_section_info
*abbrev_section
)
2802 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2804 section
->read (objfile
);
2805 abbrev_section
->read (objfile
);
2807 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
2808 dwarf2_per_objfile
->all_type_units
.reserve (map
.tu_count
);
2810 htab_t sig_types_hash
= allocate_signatured_type_table (objfile
);
2812 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2814 struct signatured_type
*sig_type
;
2817 sect_offset sect_off
2818 = (sect_offset
) (extract_unsigned_integer
2819 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2821 map
.dwarf5_byte_order
));
2823 comp_unit_head cu_header
;
2824 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
2826 section
->buffer
+ to_underlying (sect_off
),
2829 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2830 struct signatured_type
);
2831 sig_type
->signature
= cu_header
.signature
;
2832 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2833 sig_type
->per_cu
.is_debug_types
= 1;
2834 sig_type
->per_cu
.section
= section
;
2835 sig_type
->per_cu
.sect_off
= sect_off
;
2836 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
2837 sig_type
->per_cu
.v
.quick
2838 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2839 struct dwarf2_per_cu_quick_data
);
2841 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
2844 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
2847 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
2850 /* Read the address map data from the mapped index, and use it to
2851 populate the objfile's psymtabs_addrmap. */
2854 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2855 struct mapped_index
*index
)
2857 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2858 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2859 const gdb_byte
*iter
, *end
;
2860 struct addrmap
*mutable_map
;
2863 auto_obstack temp_obstack
;
2865 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2867 iter
= index
->address_table
.data ();
2868 end
= iter
+ index
->address_table
.size ();
2870 baseaddr
= objfile
->text_section_offset ();
2874 ULONGEST hi
, lo
, cu_index
;
2875 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2877 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2879 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2884 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2885 hex_string (lo
), hex_string (hi
));
2889 if (cu_index
>= dwarf2_per_objfile
->all_comp_units
.size ())
2891 complaint (_(".gdb_index address table has invalid CU number %u"),
2892 (unsigned) cu_index
);
2896 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2897 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2898 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2899 dwarf2_per_objfile
->get_cu (cu_index
));
2902 objfile
->partial_symtabs
->psymtabs_addrmap
2903 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2906 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2907 populate the objfile's psymtabs_addrmap. */
2910 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2911 struct dwarf2_section_info
*section
)
2913 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2914 bfd
*abfd
= objfile
->obfd
;
2915 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2916 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2918 auto_obstack temp_obstack
;
2919 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2921 std::unordered_map
<sect_offset
,
2922 dwarf2_per_cu_data
*,
2923 gdb::hash_enum
<sect_offset
>>
2924 debug_info_offset_to_per_cu
;
2925 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
2927 const auto insertpair
2928 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
2929 if (!insertpair
.second
)
2931 warning (_("Section .debug_aranges in %s has duplicate "
2932 "debug_info_offset %s, ignoring .debug_aranges."),
2933 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2938 section
->read (objfile
);
2940 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2942 const gdb_byte
*addr
= section
->buffer
;
2944 while (addr
< section
->buffer
+ section
->size
)
2946 const gdb_byte
*const entry_addr
= addr
;
2947 unsigned int bytes_read
;
2949 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2953 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2954 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2955 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2956 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2958 warning (_("Section .debug_aranges in %s entry at offset %s "
2959 "length %s exceeds section length %s, "
2960 "ignoring .debug_aranges."),
2961 objfile_name (objfile
),
2962 plongest (entry_addr
- section
->buffer
),
2963 plongest (bytes_read
+ entry_length
),
2964 pulongest (section
->size
));
2968 /* The version number. */
2969 const uint16_t version
= read_2_bytes (abfd
, addr
);
2973 warning (_("Section .debug_aranges in %s entry at offset %s "
2974 "has unsupported version %d, ignoring .debug_aranges."),
2975 objfile_name (objfile
),
2976 plongest (entry_addr
- section
->buffer
), version
);
2980 const uint64_t debug_info_offset
2981 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2982 addr
+= offset_size
;
2983 const auto per_cu_it
2984 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2985 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2987 warning (_("Section .debug_aranges in %s entry at offset %s "
2988 "debug_info_offset %s does not exists, "
2989 "ignoring .debug_aranges."),
2990 objfile_name (objfile
),
2991 plongest (entry_addr
- section
->buffer
),
2992 pulongest (debug_info_offset
));
2995 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2997 const uint8_t address_size
= *addr
++;
2998 if (address_size
< 1 || address_size
> 8)
3000 warning (_("Section .debug_aranges in %s entry at offset %s "
3001 "address_size %u is invalid, ignoring .debug_aranges."),
3002 objfile_name (objfile
),
3003 plongest (entry_addr
- section
->buffer
), address_size
);
3007 const uint8_t segment_selector_size
= *addr
++;
3008 if (segment_selector_size
!= 0)
3010 warning (_("Section .debug_aranges in %s entry at offset %s "
3011 "segment_selector_size %u is not supported, "
3012 "ignoring .debug_aranges."),
3013 objfile_name (objfile
),
3014 plongest (entry_addr
- section
->buffer
),
3015 segment_selector_size
);
3019 /* Must pad to an alignment boundary that is twice the address
3020 size. It is undocumented by the DWARF standard but GCC does
3022 for (size_t padding
= ((-(addr
- section
->buffer
))
3023 & (2 * address_size
- 1));
3024 padding
> 0; padding
--)
3027 warning (_("Section .debug_aranges in %s entry at offset %s "
3028 "padding is not zero, ignoring .debug_aranges."),
3029 objfile_name (objfile
),
3030 plongest (entry_addr
- section
->buffer
));
3036 if (addr
+ 2 * address_size
> entry_end
)
3038 warning (_("Section .debug_aranges in %s entry at offset %s "
3039 "address list is not properly terminated, "
3040 "ignoring .debug_aranges."),
3041 objfile_name (objfile
),
3042 plongest (entry_addr
- section
->buffer
));
3045 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
3047 addr
+= address_size
;
3048 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
3050 addr
+= address_size
;
3051 if (start
== 0 && length
== 0)
3053 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
3055 /* Symbol was eliminated due to a COMDAT group. */
3058 ULONGEST end
= start
+ length
;
3059 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
3061 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
3063 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
3067 objfile
->partial_symtabs
->psymtabs_addrmap
3068 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
3071 /* Find a slot in the mapped index INDEX for the object named NAME.
3072 If NAME is found, set *VEC_OUT to point to the CU vector in the
3073 constant pool and return true. If NAME cannot be found, return
3077 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
3078 offset_type
**vec_out
)
3081 offset_type slot
, step
;
3082 int (*cmp
) (const char *, const char *);
3084 gdb::unique_xmalloc_ptr
<char> without_params
;
3085 if (current_language
->la_language
== language_cplus
3086 || current_language
->la_language
== language_fortran
3087 || current_language
->la_language
== language_d
)
3089 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
3092 if (strchr (name
, '(') != NULL
)
3094 without_params
= cp_remove_params (name
);
3096 if (without_params
!= NULL
)
3097 name
= without_params
.get ();
3101 /* Index version 4 did not support case insensitive searches. But the
3102 indices for case insensitive languages are built in lowercase, therefore
3103 simulate our NAME being searched is also lowercased. */
3104 hash
= mapped_index_string_hash ((index
->version
== 4
3105 && case_sensitivity
== case_sensitive_off
3106 ? 5 : index
->version
),
3109 slot
= hash
& (index
->symbol_table
.size () - 1);
3110 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
3111 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
3117 const auto &bucket
= index
->symbol_table
[slot
];
3118 if (bucket
.name
== 0 && bucket
.vec
== 0)
3121 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
3122 if (!cmp (name
, str
))
3124 *vec_out
= (offset_type
*) (index
->constant_pool
3125 + MAYBE_SWAP (bucket
.vec
));
3129 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
3133 /* A helper function that reads the .gdb_index from BUFFER and fills
3134 in MAP. FILENAME is the name of the file containing the data;
3135 it is used for error reporting. DEPRECATED_OK is true if it is
3136 ok to use deprecated sections.
3138 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
3139 out parameters that are filled in with information about the CU and
3140 TU lists in the section.
3142 Returns true if all went well, false otherwise. */
3145 read_gdb_index_from_buffer (struct objfile
*objfile
,
3146 const char *filename
,
3148 gdb::array_view
<const gdb_byte
> buffer
,
3149 struct mapped_index
*map
,
3150 const gdb_byte
**cu_list
,
3151 offset_type
*cu_list_elements
,
3152 const gdb_byte
**types_list
,
3153 offset_type
*types_list_elements
)
3155 const gdb_byte
*addr
= &buffer
[0];
3157 /* Version check. */
3158 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
3159 /* Versions earlier than 3 emitted every copy of a psymbol. This
3160 causes the index to behave very poorly for certain requests. Version 3
3161 contained incomplete addrmap. So, it seems better to just ignore such
3165 static int warning_printed
= 0;
3166 if (!warning_printed
)
3168 warning (_("Skipping obsolete .gdb_index section in %s."),
3170 warning_printed
= 1;
3174 /* Index version 4 uses a different hash function than index version
3177 Versions earlier than 6 did not emit psymbols for inlined
3178 functions. Using these files will cause GDB not to be able to
3179 set breakpoints on inlined functions by name, so we ignore these
3180 indices unless the user has done
3181 "set use-deprecated-index-sections on". */
3182 if (version
< 6 && !deprecated_ok
)
3184 static int warning_printed
= 0;
3185 if (!warning_printed
)
3188 Skipping deprecated .gdb_index section in %s.\n\
3189 Do \"set use-deprecated-index-sections on\" before the file is read\n\
3190 to use the section anyway."),
3192 warning_printed
= 1;
3196 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3197 of the TU (for symbols coming from TUs),
3198 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3199 Plus gold-generated indices can have duplicate entries for global symbols,
3200 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3201 These are just performance bugs, and we can't distinguish gdb-generated
3202 indices from gold-generated ones, so issue no warning here. */
3204 /* Indexes with higher version than the one supported by GDB may be no
3205 longer backward compatible. */
3209 map
->version
= version
;
3211 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3214 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3215 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3219 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3220 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3221 - MAYBE_SWAP (metadata
[i
]))
3225 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3226 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3228 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
3231 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3232 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3234 = gdb::array_view
<mapped_index::symbol_table_slot
>
3235 ((mapped_index::symbol_table_slot
*) symbol_table
,
3236 (mapped_index::symbol_table_slot
*) symbol_table_end
);
3239 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3244 /* Callback types for dwarf2_read_gdb_index. */
3246 typedef gdb::function_view
3247 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_objfile
*)>
3248 get_gdb_index_contents_ftype
;
3249 typedef gdb::function_view
3250 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
3251 get_gdb_index_contents_dwz_ftype
;
3253 /* Read .gdb_index. If everything went ok, initialize the "quick"
3254 elements of all the CUs and return 1. Otherwise, return 0. */
3257 dwarf2_read_gdb_index
3258 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3259 get_gdb_index_contents_ftype get_gdb_index_contents
,
3260 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
3262 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3263 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3264 struct dwz_file
*dwz
;
3265 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3267 gdb::array_view
<const gdb_byte
> main_index_contents
3268 = get_gdb_index_contents (objfile
, dwarf2_per_objfile
);
3270 if (main_index_contents
.empty ())
3273 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3274 if (!read_gdb_index_from_buffer (objfile
, objfile_name (objfile
),
3275 use_deprecated_index_sections
,
3276 main_index_contents
, map
.get (), &cu_list
,
3277 &cu_list_elements
, &types_list
,
3278 &types_list_elements
))
3281 /* Don't use the index if it's empty. */
3282 if (map
->symbol_table
.empty ())
3285 /* If there is a .dwz file, read it so we can get its CU list as
3287 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3290 struct mapped_index dwz_map
;
3291 const gdb_byte
*dwz_types_ignore
;
3292 offset_type dwz_types_elements_ignore
;
3294 gdb::array_view
<const gdb_byte
> dwz_index_content
3295 = get_gdb_index_contents_dwz (objfile
, dwz
);
3297 if (dwz_index_content
.empty ())
3300 if (!read_gdb_index_from_buffer (objfile
,
3301 bfd_get_filename (dwz
->dwz_bfd
.get ()),
3302 1, dwz_index_content
, &dwz_map
,
3303 &dwz_list
, &dwz_list_elements
,
3305 &dwz_types_elements_ignore
))
3307 warning (_("could not read '.gdb_index' section from %s; skipping"),
3308 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3313 create_cus_from_index (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3314 dwz_list
, dwz_list_elements
);
3316 if (types_list_elements
)
3318 /* We can only handle a single .debug_types when we have an
3320 if (dwarf2_per_objfile
->types
.size () != 1)
3323 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
3325 create_signatured_type_table_from_index (dwarf2_per_objfile
, section
,
3326 types_list
, types_list_elements
);
3329 create_addrmap_from_index (dwarf2_per_objfile
, map
.get ());
3331 dwarf2_per_objfile
->index_table
= std::move (map
);
3332 dwarf2_per_objfile
->using_index
= 1;
3333 dwarf2_per_objfile
->quick_file_names_table
=
3334 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
3339 /* die_reader_func for dw2_get_file_names. */
3342 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3343 const gdb_byte
*info_ptr
,
3344 struct die_info
*comp_unit_die
,
3347 struct dwarf2_cu
*cu
= reader
->cu
;
3348 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3349 struct dwarf2_per_objfile
*dwarf2_per_objfile
3350 = cu
->per_cu
->dwarf2_per_objfile
;
3351 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3352 struct dwarf2_per_cu_data
*lh_cu
;
3353 struct attribute
*attr
;
3355 struct quick_file_names
*qfn
;
3357 gdb_assert (! this_cu
->is_debug_types
);
3359 /* Our callers never want to match partial units -- instead they
3360 will match the enclosing full CU. */
3361 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3363 this_cu
->v
.quick
->no_file_data
= 1;
3371 sect_offset line_offset
{};
3373 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3374 if (attr
!= nullptr)
3376 struct quick_file_names find_entry
;
3378 line_offset
= (sect_offset
) DW_UNSND (attr
);
3380 /* We may have already read in this line header (TU line header sharing).
3381 If we have we're done. */
3382 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3383 find_entry
.hash
.line_sect_off
= line_offset
;
3384 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
3385 &find_entry
, INSERT
);
3388 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3392 lh
= dwarf_decode_line_header (line_offset
, cu
);
3396 lh_cu
->v
.quick
->no_file_data
= 1;
3400 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
3401 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3402 qfn
->hash
.line_sect_off
= line_offset
;
3403 gdb_assert (slot
!= NULL
);
3406 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3409 if (strcmp (fnd
.name
, "<unknown>") != 0)
3412 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3414 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, qfn
->num_file_names
);
3416 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3417 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3418 qfn
->file_names
[i
+ offset
] = file_full_name (i
+ 1, lh
.get (), fnd
.comp_dir
);
3419 qfn
->real_names
= NULL
;
3421 lh_cu
->v
.quick
->file_names
= qfn
;
3424 /* A helper for the "quick" functions which attempts to read the line
3425 table for THIS_CU. */
3427 static struct quick_file_names
*
3428 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3430 /* This should never be called for TUs. */
3431 gdb_assert (! this_cu
->is_debug_types
);
3432 /* Nor type unit groups. */
3433 gdb_assert (! IS_TYPE_UNIT_GROUP (this_cu
));
3435 if (this_cu
->v
.quick
->file_names
!= NULL
)
3436 return this_cu
->v
.quick
->file_names
;
3437 /* If we know there is no line data, no point in looking again. */
3438 if (this_cu
->v
.quick
->no_file_data
)
3441 cutu_reader
reader (this_cu
);
3442 if (!reader
.dummy_p
)
3443 dw2_get_file_names_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
3444 reader
.has_children
);
3446 if (this_cu
->v
.quick
->no_file_data
)
3448 return this_cu
->v
.quick
->file_names
;
3451 /* A helper for the "quick" functions which computes and caches the
3452 real path for a given file name from the line table. */
3455 dw2_get_real_path (struct objfile
*objfile
,
3456 struct quick_file_names
*qfn
, int index
)
3458 if (qfn
->real_names
== NULL
)
3459 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3460 qfn
->num_file_names
, const char *);
3462 if (qfn
->real_names
[index
] == NULL
)
3463 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3465 return qfn
->real_names
[index
];
3468 static struct symtab
*
3469 dw2_find_last_source_symtab (struct objfile
*objfile
)
3471 struct dwarf2_per_objfile
*dwarf2_per_objfile
3472 = get_dwarf2_per_objfile (objfile
);
3473 dwarf2_per_cu_data
*dwarf_cu
= dwarf2_per_objfile
->all_comp_units
.back ();
3474 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, false);
3479 return compunit_primary_filetab (cust
);
3482 /* Traversal function for dw2_forget_cached_source_info. */
3485 dw2_free_cached_file_names (void **slot
, void *info
)
3487 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3489 if (file_data
->real_names
)
3493 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3495 xfree ((void*) file_data
->real_names
[i
]);
3496 file_data
->real_names
[i
] = NULL
;
3504 dw2_forget_cached_source_info (struct objfile
*objfile
)
3506 struct dwarf2_per_objfile
*dwarf2_per_objfile
3507 = get_dwarf2_per_objfile (objfile
);
3509 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
3510 dw2_free_cached_file_names
, NULL
);
3513 /* Helper function for dw2_map_symtabs_matching_filename that expands
3514 the symtabs and calls the iterator. */
3517 dw2_map_expand_apply (struct objfile
*objfile
,
3518 struct dwarf2_per_cu_data
*per_cu
,
3519 const char *name
, const char *real_path
,
3520 gdb::function_view
<bool (symtab
*)> callback
)
3522 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3524 /* Don't visit already-expanded CUs. */
3525 if (per_cu
->v
.quick
->compunit_symtab
)
3528 /* This may expand more than one symtab, and we want to iterate over
3530 dw2_instantiate_symtab (per_cu
, false);
3532 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3533 last_made
, callback
);
3536 /* Implementation of the map_symtabs_matching_filename method. */
3539 dw2_map_symtabs_matching_filename
3540 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3541 gdb::function_view
<bool (symtab
*)> callback
)
3543 const char *name_basename
= lbasename (name
);
3544 struct dwarf2_per_objfile
*dwarf2_per_objfile
3545 = get_dwarf2_per_objfile (objfile
);
3547 /* The rule is CUs specify all the files, including those used by
3548 any TU, so there's no need to scan TUs here. */
3550 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3552 /* We only need to look at symtabs not already expanded. */
3553 if (per_cu
->v
.quick
->compunit_symtab
)
3556 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3557 if (file_data
== NULL
)
3560 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3562 const char *this_name
= file_data
->file_names
[j
];
3563 const char *this_real_name
;
3565 if (compare_filenames_for_search (this_name
, name
))
3567 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3573 /* Before we invoke realpath, which can get expensive when many
3574 files are involved, do a quick comparison of the basenames. */
3575 if (! basenames_may_differ
3576 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3579 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3580 if (compare_filenames_for_search (this_real_name
, name
))
3582 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3588 if (real_path
!= NULL
)
3590 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3591 gdb_assert (IS_ABSOLUTE_PATH (name
));
3592 if (this_real_name
!= NULL
3593 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3595 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3607 /* Struct used to manage iterating over all CUs looking for a symbol. */
3609 struct dw2_symtab_iterator
3611 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3612 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
3613 /* If set, only look for symbols that match that block. Valid values are
3614 GLOBAL_BLOCK and STATIC_BLOCK. */
3615 gdb::optional
<block_enum
> block_index
;
3616 /* The kind of symbol we're looking for. */
3618 /* The list of CUs from the index entry of the symbol,
3619 or NULL if not found. */
3621 /* The next element in VEC to look at. */
3623 /* The number of elements in VEC, or zero if there is no match. */
3625 /* Have we seen a global version of the symbol?
3626 If so we can ignore all further global instances.
3627 This is to work around gold/15646, inefficient gold-generated
3632 /* Initialize the index symtab iterator ITER. */
3635 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3636 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3637 gdb::optional
<block_enum
> block_index
,
3641 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3642 iter
->block_index
= block_index
;
3643 iter
->domain
= domain
;
3645 iter
->global_seen
= 0;
3647 mapped_index
*index
= dwarf2_per_objfile
->index_table
.get ();
3649 /* index is NULL if OBJF_READNOW. */
3650 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3651 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3659 /* Return the next matching CU or NULL if there are no more. */
3661 static struct dwarf2_per_cu_data
*
3662 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3664 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
3666 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3668 offset_type cu_index_and_attrs
=
3669 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3670 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3671 gdb_index_symbol_kind symbol_kind
=
3672 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3673 /* Only check the symbol attributes if they're present.
3674 Indices prior to version 7 don't record them,
3675 and indices >= 7 may elide them for certain symbols
3676 (gold does this). */
3678 (dwarf2_per_objfile
->index_table
->version
>= 7
3679 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3681 /* Don't crash on bad data. */
3682 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
3683 + dwarf2_per_objfile
->all_type_units
.size ()))
3685 complaint (_(".gdb_index entry has bad CU index"
3687 objfile_name (dwarf2_per_objfile
->objfile
));
3691 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
3693 /* Skip if already read in. */
3694 if (per_cu
->v
.quick
->compunit_symtab
)
3697 /* Check static vs global. */
3700 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3702 if (iter
->block_index
.has_value ())
3704 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3706 if (is_static
!= want_static
)
3710 /* Work around gold/15646. */
3711 if (!is_static
&& iter
->global_seen
)
3714 iter
->global_seen
= 1;
3717 /* Only check the symbol's kind if it has one. */
3720 switch (iter
->domain
)
3723 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3724 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3725 /* Some types are also in VAR_DOMAIN. */
3726 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3730 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3734 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3738 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3753 static struct compunit_symtab
*
3754 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
3755 const char *name
, domain_enum domain
)
3757 struct compunit_symtab
*stab_best
= NULL
;
3758 struct dwarf2_per_objfile
*dwarf2_per_objfile
3759 = get_dwarf2_per_objfile (objfile
);
3761 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
3763 struct dw2_symtab_iterator iter
;
3764 struct dwarf2_per_cu_data
*per_cu
;
3766 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, block_index
, domain
, name
);
3768 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3770 struct symbol
*sym
, *with_opaque
= NULL
;
3771 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
3772 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
3773 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3775 sym
= block_find_symbol (block
, name
, domain
,
3776 block_find_non_opaque_type_preferred
,
3779 /* Some caution must be observed with overloaded functions
3780 and methods, since the index will not contain any overload
3781 information (but NAME might contain it). */
3784 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
3786 if (with_opaque
!= NULL
3787 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
3790 /* Keep looking through other CUs. */
3797 dw2_print_stats (struct objfile
*objfile
)
3799 struct dwarf2_per_objfile
*dwarf2_per_objfile
3800 = get_dwarf2_per_objfile (objfile
);
3801 int total
= (dwarf2_per_objfile
->all_comp_units
.size ()
3802 + dwarf2_per_objfile
->all_type_units
.size ());
3805 for (int i
= 0; i
< total
; ++i
)
3807 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
3809 if (!per_cu
->v
.quick
->compunit_symtab
)
3812 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3813 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3816 /* This dumps minimal information about the index.
3817 It is called via "mt print objfiles".
3818 One use is to verify .gdb_index has been loaded by the
3819 gdb.dwarf2/gdb-index.exp testcase. */
3822 dw2_dump (struct objfile
*objfile
)
3824 struct dwarf2_per_objfile
*dwarf2_per_objfile
3825 = get_dwarf2_per_objfile (objfile
);
3827 gdb_assert (dwarf2_per_objfile
->using_index
);
3828 printf_filtered (".gdb_index:");
3829 if (dwarf2_per_objfile
->index_table
!= NULL
)
3831 printf_filtered (" version %d\n",
3832 dwarf2_per_objfile
->index_table
->version
);
3835 printf_filtered (" faked for \"readnow\"\n");
3836 printf_filtered ("\n");
3840 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3841 const char *func_name
)
3843 struct dwarf2_per_objfile
*dwarf2_per_objfile
3844 = get_dwarf2_per_objfile (objfile
);
3846 struct dw2_symtab_iterator iter
;
3847 struct dwarf2_per_cu_data
*per_cu
;
3849 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, {}, VAR_DOMAIN
, func_name
);
3851 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3852 dw2_instantiate_symtab (per_cu
, false);
3857 dw2_expand_all_symtabs (struct objfile
*objfile
)
3859 struct dwarf2_per_objfile
*dwarf2_per_objfile
3860 = get_dwarf2_per_objfile (objfile
);
3861 int total_units
= (dwarf2_per_objfile
->all_comp_units
.size ()
3862 + dwarf2_per_objfile
->all_type_units
.size ());
3864 for (int i
= 0; i
< total_units
; ++i
)
3866 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
3868 /* We don't want to directly expand a partial CU, because if we
3869 read it with the wrong language, then assertion failures can
3870 be triggered later on. See PR symtab/23010. So, tell
3871 dw2_instantiate_symtab to skip partial CUs -- any important
3872 partial CU will be read via DW_TAG_imported_unit anyway. */
3873 dw2_instantiate_symtab (per_cu
, true);
3878 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
3879 const char *fullname
)
3881 struct dwarf2_per_objfile
*dwarf2_per_objfile
3882 = get_dwarf2_per_objfile (objfile
);
3884 /* We don't need to consider type units here.
3885 This is only called for examining code, e.g. expand_line_sal.
3886 There can be an order of magnitude (or more) more type units
3887 than comp units, and we avoid them if we can. */
3889 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3891 /* We only need to look at symtabs not already expanded. */
3892 if (per_cu
->v
.quick
->compunit_symtab
)
3895 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3896 if (file_data
== NULL
)
3899 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3901 const char *this_fullname
= file_data
->file_names
[j
];
3903 if (filename_cmp (this_fullname
, fullname
) == 0)
3905 dw2_instantiate_symtab (per_cu
, false);
3913 dw2_map_matching_symbols
3914 (struct objfile
*objfile
,
3915 const lookup_name_info
&name
, domain_enum domain
,
3917 gdb::function_view
<symbol_found_callback_ftype
> callback
,
3918 symbol_compare_ftype
*ordered_compare
)
3920 /* Currently unimplemented; used for Ada. The function can be called if the
3921 current language is Ada for a non-Ada objfile using GNU index. As Ada
3922 does not look for non-Ada symbols this function should just return. */
3925 /* Starting from a search name, return the string that finds the upper
3926 bound of all strings that start with SEARCH_NAME in a sorted name
3927 list. Returns the empty string to indicate that the upper bound is
3928 the end of the list. */
3931 make_sort_after_prefix_name (const char *search_name
)
3933 /* When looking to complete "func", we find the upper bound of all
3934 symbols that start with "func" by looking for where we'd insert
3935 the closest string that would follow "func" in lexicographical
3936 order. Usually, that's "func"-with-last-character-incremented,
3937 i.e. "fund". Mind non-ASCII characters, though. Usually those
3938 will be UTF-8 multi-byte sequences, but we can't be certain.
3939 Especially mind the 0xff character, which is a valid character in
3940 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3941 rule out compilers allowing it in identifiers. Note that
3942 conveniently, strcmp/strcasecmp are specified to compare
3943 characters interpreted as unsigned char. So what we do is treat
3944 the whole string as a base 256 number composed of a sequence of
3945 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3946 to 0, and carries 1 to the following more-significant position.
3947 If the very first character in SEARCH_NAME ends up incremented
3948 and carries/overflows, then the upper bound is the end of the
3949 list. The string after the empty string is also the empty
3952 Some examples of this operation:
3954 SEARCH_NAME => "+1" RESULT
3958 "\xff" "a" "\xff" => "\xff" "b"
3963 Then, with these symbols for example:
3969 completing "func" looks for symbols between "func" and
3970 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3971 which finds "func" and "func1", but not "fund".
3975 funcÿ (Latin1 'ÿ' [0xff])
3979 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3980 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3984 ÿÿ (Latin1 'ÿ' [0xff])
3987 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3988 the end of the list.
3990 std::string after
= search_name
;
3991 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3993 if (!after
.empty ())
3994 after
.back () = (unsigned char) after
.back () + 1;
3998 /* See declaration. */
4000 std::pair
<std::vector
<name_component
>::const_iterator
,
4001 std::vector
<name_component
>::const_iterator
>
4002 mapped_index_base::find_name_components_bounds
4003 (const lookup_name_info
&lookup_name_without_params
, language lang
) const
4006 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4008 const char *lang_name
4009 = lookup_name_without_params
.language_lookup_name (lang
).c_str ();
4011 /* Comparison function object for lower_bound that matches against a
4012 given symbol name. */
4013 auto lookup_compare_lower
= [&] (const name_component
&elem
,
4016 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4017 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4018 return name_cmp (elem_name
, name
) < 0;
4021 /* Comparison function object for upper_bound that matches against a
4022 given symbol name. */
4023 auto lookup_compare_upper
= [&] (const char *name
,
4024 const name_component
&elem
)
4026 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4027 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4028 return name_cmp (name
, elem_name
) < 0;
4031 auto begin
= this->name_components
.begin ();
4032 auto end
= this->name_components
.end ();
4034 /* Find the lower bound. */
4037 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
4040 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
4043 /* Find the upper bound. */
4046 if (lookup_name_without_params
.completion_mode ())
4048 /* In completion mode, we want UPPER to point past all
4049 symbols names that have the same prefix. I.e., with
4050 these symbols, and completing "func":
4052 function << lower bound
4054 other_function << upper bound
4056 We find the upper bound by looking for the insertion
4057 point of "func"-with-last-character-incremented,
4059 std::string after
= make_sort_after_prefix_name (lang_name
);
4062 return std::lower_bound (lower
, end
, after
.c_str (),
4063 lookup_compare_lower
);
4066 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
4069 return {lower
, upper
};
4072 /* See declaration. */
4075 mapped_index_base::build_name_components ()
4077 if (!this->name_components
.empty ())
4080 this->name_components_casing
= case_sensitivity
;
4082 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4084 /* The code below only knows how to break apart components of C++
4085 symbol names (and other languages that use '::' as
4086 namespace/module separator) and Ada symbol names. */
4087 auto count
= this->symbol_name_count ();
4088 for (offset_type idx
= 0; idx
< count
; idx
++)
4090 if (this->symbol_name_slot_invalid (idx
))
4093 const char *name
= this->symbol_name_at (idx
);
4095 /* Add each name component to the name component table. */
4096 unsigned int previous_len
= 0;
4098 if (strstr (name
, "::") != nullptr)
4100 for (unsigned int current_len
= cp_find_first_component (name
);
4101 name
[current_len
] != '\0';
4102 current_len
+= cp_find_first_component (name
+ current_len
))
4104 gdb_assert (name
[current_len
] == ':');
4105 this->name_components
.push_back ({previous_len
, idx
});
4106 /* Skip the '::'. */
4108 previous_len
= current_len
;
4113 /* Handle the Ada encoded (aka mangled) form here. */
4114 for (const char *iter
= strstr (name
, "__");
4116 iter
= strstr (iter
, "__"))
4118 this->name_components
.push_back ({previous_len
, idx
});
4120 previous_len
= iter
- name
;
4124 this->name_components
.push_back ({previous_len
, idx
});
4127 /* Sort name_components elements by name. */
4128 auto name_comp_compare
= [&] (const name_component
&left
,
4129 const name_component
&right
)
4131 const char *left_qualified
= this->symbol_name_at (left
.idx
);
4132 const char *right_qualified
= this->symbol_name_at (right
.idx
);
4134 const char *left_name
= left_qualified
+ left
.name_offset
;
4135 const char *right_name
= right_qualified
+ right
.name_offset
;
4137 return name_cmp (left_name
, right_name
) < 0;
4140 std::sort (this->name_components
.begin (),
4141 this->name_components
.end (),
4145 /* Helper for dw2_expand_symtabs_matching that works with a
4146 mapped_index_base instead of the containing objfile. This is split
4147 to a separate function in order to be able to unit test the
4148 name_components matching using a mock mapped_index_base. For each
4149 symbol name that matches, calls MATCH_CALLBACK, passing it the
4150 symbol's index in the mapped_index_base symbol table. */
4153 dw2_expand_symtabs_matching_symbol
4154 (mapped_index_base
&index
,
4155 const lookup_name_info
&lookup_name_in
,
4156 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4157 enum search_domain kind
,
4158 gdb::function_view
<bool (offset_type
)> match_callback
)
4160 lookup_name_info lookup_name_without_params
4161 = lookup_name_in
.make_ignore_params ();
4163 /* Build the symbol name component sorted vector, if we haven't
4165 index
.build_name_components ();
4167 /* The same symbol may appear more than once in the range though.
4168 E.g., if we're looking for symbols that complete "w", and we have
4169 a symbol named "w1::w2", we'll find the two name components for
4170 that same symbol in the range. To be sure we only call the
4171 callback once per symbol, we first collect the symbol name
4172 indexes that matched in a temporary vector and ignore
4174 std::vector
<offset_type
> matches
;
4176 struct name_and_matcher
4178 symbol_name_matcher_ftype
*matcher
;
4179 const std::string
&name
;
4181 bool operator== (const name_and_matcher
&other
) const
4183 return matcher
== other
.matcher
&& name
== other
.name
;
4187 /* A vector holding all the different symbol name matchers, for all
4189 std::vector
<name_and_matcher
> matchers
;
4191 for (int i
= 0; i
< nr_languages
; i
++)
4193 enum language lang_e
= (enum language
) i
;
4195 const language_defn
*lang
= language_def (lang_e
);
4196 symbol_name_matcher_ftype
*name_matcher
4197 = get_symbol_name_matcher (lang
, lookup_name_without_params
);
4199 name_and_matcher key
{
4201 lookup_name_without_params
.language_lookup_name (lang_e
)
4204 /* Don't insert the same comparison routine more than once.
4205 Note that we do this linear walk. This is not a problem in
4206 practice because the number of supported languages is
4208 if (std::find (matchers
.begin (), matchers
.end (), key
)
4211 matchers
.push_back (std::move (key
));
4214 = index
.find_name_components_bounds (lookup_name_without_params
,
4217 /* Now for each symbol name in range, check to see if we have a name
4218 match, and if so, call the MATCH_CALLBACK callback. */
4220 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
4222 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
4224 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
4225 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4228 matches
.push_back (bounds
.first
->idx
);
4232 std::sort (matches
.begin (), matches
.end ());
4234 /* Finally call the callback, once per match. */
4236 for (offset_type idx
: matches
)
4240 if (!match_callback (idx
))
4246 /* Above we use a type wider than idx's for 'prev', since 0 and
4247 (offset_type)-1 are both possible values. */
4248 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4253 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4255 /* A mock .gdb_index/.debug_names-like name index table, enough to
4256 exercise dw2_expand_symtabs_matching_symbol, which works with the
4257 mapped_index_base interface. Builds an index from the symbol list
4258 passed as parameter to the constructor. */
4259 class mock_mapped_index
: public mapped_index_base
4262 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4263 : m_symbol_table (symbols
)
4266 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4268 /* Return the number of names in the symbol table. */
4269 size_t symbol_name_count () const override
4271 return m_symbol_table
.size ();
4274 /* Get the name of the symbol at IDX in the symbol table. */
4275 const char *symbol_name_at (offset_type idx
) const override
4277 return m_symbol_table
[idx
];
4281 gdb::array_view
<const char *> m_symbol_table
;
4284 /* Convenience function that converts a NULL pointer to a "<null>"
4285 string, to pass to print routines. */
4288 string_or_null (const char *str
)
4290 return str
!= NULL
? str
: "<null>";
4293 /* Check if a lookup_name_info built from
4294 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4295 index. EXPECTED_LIST is the list of expected matches, in expected
4296 matching order. If no match expected, then an empty list is
4297 specified. Returns true on success. On failure prints a warning
4298 indicating the file:line that failed, and returns false. */
4301 check_match (const char *file
, int line
,
4302 mock_mapped_index
&mock_index
,
4303 const char *name
, symbol_name_match_type match_type
,
4304 bool completion_mode
,
4305 std::initializer_list
<const char *> expected_list
)
4307 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4309 bool matched
= true;
4311 auto mismatch
= [&] (const char *expected_str
,
4314 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4315 "expected=\"%s\", got=\"%s\"\n"),
4317 (match_type
== symbol_name_match_type::FULL
4319 name
, string_or_null (expected_str
), string_or_null (got
));
4323 auto expected_it
= expected_list
.begin ();
4324 auto expected_end
= expected_list
.end ();
4326 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4328 [&] (offset_type idx
)
4330 const char *matched_name
= mock_index
.symbol_name_at (idx
);
4331 const char *expected_str
4332 = expected_it
== expected_end
? NULL
: *expected_it
++;
4334 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4335 mismatch (expected_str
, matched_name
);
4339 const char *expected_str
4340 = expected_it
== expected_end
? NULL
: *expected_it
++;
4341 if (expected_str
!= NULL
)
4342 mismatch (expected_str
, NULL
);
4347 /* The symbols added to the mock mapped_index for testing (in
4349 static const char *test_symbols
[] = {
4358 "ns2::tmpl<int>::foo2",
4359 "(anonymous namespace)::A::B::C",
4361 /* These are used to check that the increment-last-char in the
4362 matching algorithm for completion doesn't match "t1_fund" when
4363 completing "t1_func". */
4369 /* A UTF-8 name with multi-byte sequences to make sure that
4370 cp-name-parser understands this as a single identifier ("função"
4371 is "function" in PT). */
4374 /* \377 (0xff) is Latin1 'ÿ'. */
4377 /* \377 (0xff) is Latin1 'ÿ'. */
4381 /* A name with all sorts of complications. Starts with "z" to make
4382 it easier for the completion tests below. */
4383 #define Z_SYM_NAME \
4384 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4385 "::tuple<(anonymous namespace)::ui*, " \
4386 "std::default_delete<(anonymous namespace)::ui>, void>"
4391 /* Returns true if the mapped_index_base::find_name_component_bounds
4392 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4393 in completion mode. */
4396 check_find_bounds_finds (mapped_index_base
&index
,
4397 const char *search_name
,
4398 gdb::array_view
<const char *> expected_syms
)
4400 lookup_name_info
lookup_name (search_name
,
4401 symbol_name_match_type::FULL
, true);
4403 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4406 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4407 if (distance
!= expected_syms
.size ())
4410 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4412 auto nc_elem
= bounds
.first
+ exp_elem
;
4413 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
4414 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4421 /* Test the lower-level mapped_index::find_name_component_bounds
4425 test_mapped_index_find_name_component_bounds ()
4427 mock_mapped_index
mock_index (test_symbols
);
4429 mock_index
.build_name_components ();
4431 /* Test the lower-level mapped_index::find_name_component_bounds
4432 method in completion mode. */
4434 static const char *expected_syms
[] = {
4439 SELF_CHECK (check_find_bounds_finds (mock_index
,
4440 "t1_func", expected_syms
));
4443 /* Check that the increment-last-char in the name matching algorithm
4444 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4446 static const char *expected_syms1
[] = {
4450 SELF_CHECK (check_find_bounds_finds (mock_index
,
4451 "\377", expected_syms1
));
4453 static const char *expected_syms2
[] = {
4456 SELF_CHECK (check_find_bounds_finds (mock_index
,
4457 "\377\377", expected_syms2
));
4461 /* Test dw2_expand_symtabs_matching_symbol. */
4464 test_dw2_expand_symtabs_matching_symbol ()
4466 mock_mapped_index
mock_index (test_symbols
);
4468 /* We let all tests run until the end even if some fails, for debug
4470 bool any_mismatch
= false;
4472 /* Create the expected symbols list (an initializer_list). Needed
4473 because lists have commas, and we need to pass them to CHECK,
4474 which is a macro. */
4475 #define EXPECT(...) { __VA_ARGS__ }
4477 /* Wrapper for check_match that passes down the current
4478 __FILE__/__LINE__. */
4479 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4480 any_mismatch |= !check_match (__FILE__, __LINE__, \
4482 NAME, MATCH_TYPE, COMPLETION_MODE, \
4485 /* Identity checks. */
4486 for (const char *sym
: test_symbols
)
4488 /* Should be able to match all existing symbols. */
4489 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4492 /* Should be able to match all existing symbols with
4494 std::string with_params
= std::string (sym
) + "(int)";
4495 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4498 /* Should be able to match all existing symbols with
4499 parameters and qualifiers. */
4500 with_params
= std::string (sym
) + " ( int ) const";
4501 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4504 /* This should really find sym, but cp-name-parser.y doesn't
4505 know about lvalue/rvalue qualifiers yet. */
4506 with_params
= std::string (sym
) + " ( int ) &&";
4507 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4511 /* Check that the name matching algorithm for completion doesn't get
4512 confused with Latin1 'ÿ' / 0xff. */
4514 static const char str
[] = "\377";
4515 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4516 EXPECT ("\377", "\377\377123"));
4519 /* Check that the increment-last-char in the matching algorithm for
4520 completion doesn't match "t1_fund" when completing "t1_func". */
4522 static const char str
[] = "t1_func";
4523 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4524 EXPECT ("t1_func", "t1_func1"));
4527 /* Check that completion mode works at each prefix of the expected
4530 static const char str
[] = "function(int)";
4531 size_t len
= strlen (str
);
4534 for (size_t i
= 1; i
< len
; i
++)
4536 lookup
.assign (str
, i
);
4537 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4538 EXPECT ("function"));
4542 /* While "w" is a prefix of both components, the match function
4543 should still only be called once. */
4545 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4547 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4551 /* Same, with a "complicated" symbol. */
4553 static const char str
[] = Z_SYM_NAME
;
4554 size_t len
= strlen (str
);
4557 for (size_t i
= 1; i
< len
; i
++)
4559 lookup
.assign (str
, i
);
4560 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4561 EXPECT (Z_SYM_NAME
));
4565 /* In FULL mode, an incomplete symbol doesn't match. */
4567 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4571 /* A complete symbol with parameters matches any overload, since the
4572 index has no overload info. */
4574 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4575 EXPECT ("std::zfunction", "std::zfunction2"));
4576 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4577 EXPECT ("std::zfunction", "std::zfunction2"));
4578 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4579 EXPECT ("std::zfunction", "std::zfunction2"));
4582 /* Check that whitespace is ignored appropriately. A symbol with a
4583 template argument list. */
4585 static const char expected
[] = "ns::foo<int>";
4586 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4588 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4592 /* Check that whitespace is ignored appropriately. A symbol with a
4593 template argument list that includes a pointer. */
4595 static const char expected
[] = "ns::foo<char*>";
4596 /* Try both completion and non-completion modes. */
4597 static const bool completion_mode
[2] = {false, true};
4598 for (size_t i
= 0; i
< 2; i
++)
4600 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4601 completion_mode
[i
], EXPECT (expected
));
4602 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4603 completion_mode
[i
], EXPECT (expected
));
4605 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4606 completion_mode
[i
], EXPECT (expected
));
4607 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4608 completion_mode
[i
], EXPECT (expected
));
4613 /* Check method qualifiers are ignored. */
4614 static const char expected
[] = "ns::foo<char*>";
4615 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4616 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4617 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4618 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4619 CHECK_MATCH ("foo < char * > ( int ) const",
4620 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4621 CHECK_MATCH ("foo < char * > ( int ) &&",
4622 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4625 /* Test lookup names that don't match anything. */
4627 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4630 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4634 /* Some wild matching tests, exercising "(anonymous namespace)",
4635 which should not be confused with a parameter list. */
4637 static const char *syms
[] = {
4641 "A :: B :: C ( int )",
4646 for (const char *s
: syms
)
4648 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4649 EXPECT ("(anonymous namespace)::A::B::C"));
4654 static const char expected
[] = "ns2::tmpl<int>::foo2";
4655 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4657 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4661 SELF_CHECK (!any_mismatch
);
4670 test_mapped_index_find_name_component_bounds ();
4671 test_dw2_expand_symtabs_matching_symbol ();
4674 }} // namespace selftests::dw2_expand_symtabs_matching
4676 #endif /* GDB_SELF_TEST */
4678 /* If FILE_MATCHER is NULL or if PER_CU has
4679 dwarf2_per_cu_quick_data::MARK set (see
4680 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4681 EXPANSION_NOTIFY on it. */
4684 dw2_expand_symtabs_matching_one
4685 (struct dwarf2_per_cu_data
*per_cu
,
4686 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4687 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4689 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4691 bool symtab_was_null
4692 = (per_cu
->v
.quick
->compunit_symtab
== NULL
);
4694 dw2_instantiate_symtab (per_cu
, false);
4696 if (expansion_notify
!= NULL
4698 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
4699 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
4703 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4704 matched, to expand corresponding CUs that were marked. IDX is the
4705 index of the symbol name that matched. */
4708 dw2_expand_marked_cus
4709 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
4710 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4711 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4714 offset_type
*vec
, vec_len
, vec_idx
;
4715 bool global_seen
= false;
4716 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
4718 vec
= (offset_type
*) (index
.constant_pool
4719 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
4720 vec_len
= MAYBE_SWAP (vec
[0]);
4721 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4723 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
4724 /* This value is only valid for index versions >= 7. */
4725 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4726 gdb_index_symbol_kind symbol_kind
=
4727 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4728 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4729 /* Only check the symbol attributes if they're present.
4730 Indices prior to version 7 don't record them,
4731 and indices >= 7 may elide them for certain symbols
4732 (gold does this). */
4735 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4737 /* Work around gold/15646. */
4740 if (!is_static
&& global_seen
)
4746 /* Only check the symbol's kind if it has one. */
4751 case VARIABLES_DOMAIN
:
4752 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4755 case FUNCTIONS_DOMAIN
:
4756 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4760 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4763 case MODULES_DOMAIN
:
4764 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4772 /* Don't crash on bad data. */
4773 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
4774 + dwarf2_per_objfile
->all_type_units
.size ()))
4776 complaint (_(".gdb_index entry has bad CU index"
4778 objfile_name (dwarf2_per_objfile
->objfile
));
4782 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
4783 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
4788 /* If FILE_MATCHER is non-NULL, set all the
4789 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4790 that match FILE_MATCHER. */
4793 dw_expand_symtabs_matching_file_matcher
4794 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4795 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4797 if (file_matcher
== NULL
)
4800 objfile
*const objfile
= dwarf2_per_objfile
->objfile
;
4802 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4804 NULL
, xcalloc
, xfree
));
4805 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4807 NULL
, xcalloc
, xfree
));
4809 /* The rule is CUs specify all the files, including those used by
4810 any TU, so there's no need to scan TUs here. */
4812 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4816 per_cu
->v
.quick
->mark
= 0;
4818 /* We only need to look at symtabs not already expanded. */
4819 if (per_cu
->v
.quick
->compunit_symtab
)
4822 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4823 if (file_data
== NULL
)
4826 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4828 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4830 per_cu
->v
.quick
->mark
= 1;
4834 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4836 const char *this_real_name
;
4838 if (file_matcher (file_data
->file_names
[j
], false))
4840 per_cu
->v
.quick
->mark
= 1;
4844 /* Before we invoke realpath, which can get expensive when many
4845 files are involved, do a quick comparison of the basenames. */
4846 if (!basenames_may_differ
4847 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4851 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
4852 if (file_matcher (this_real_name
, false))
4854 per_cu
->v
.quick
->mark
= 1;
4859 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4860 ? visited_found
.get ()
4861 : visited_not_found
.get (),
4868 dw2_expand_symtabs_matching
4869 (struct objfile
*objfile
,
4870 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4871 const lookup_name_info
&lookup_name
,
4872 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4873 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4874 enum search_domain kind
)
4876 struct dwarf2_per_objfile
*dwarf2_per_objfile
4877 = get_dwarf2_per_objfile (objfile
);
4879 /* index_table is NULL if OBJF_READNOW. */
4880 if (!dwarf2_per_objfile
->index_table
)
4883 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
4885 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
4887 dw2_expand_symtabs_matching_symbol (index
, lookup_name
,
4889 kind
, [&] (offset_type idx
)
4891 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
4892 expansion_notify
, kind
);
4897 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4900 static struct compunit_symtab
*
4901 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4906 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4907 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4910 if (cust
->includes
== NULL
)
4913 for (i
= 0; cust
->includes
[i
]; ++i
)
4915 struct compunit_symtab
*s
= cust
->includes
[i
];
4917 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4925 static struct compunit_symtab
*
4926 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
4927 struct bound_minimal_symbol msymbol
,
4929 struct obj_section
*section
,
4932 struct dwarf2_per_cu_data
*data
;
4933 struct compunit_symtab
*result
;
4935 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
4938 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4939 data
= (struct dwarf2_per_cu_data
*) addrmap_find
4940 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
4944 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
4945 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4946 paddress (get_objfile_arch (objfile
), pc
));
4949 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
,
4952 gdb_assert (result
!= NULL
);
4957 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
4958 void *data
, int need_fullname
)
4960 struct dwarf2_per_objfile
*dwarf2_per_objfile
4961 = get_dwarf2_per_objfile (objfile
);
4963 if (!dwarf2_per_objfile
->filenames_cache
)
4965 dwarf2_per_objfile
->filenames_cache
.emplace ();
4967 htab_up
visited (htab_create_alloc (10,
4968 htab_hash_pointer
, htab_eq_pointer
,
4969 NULL
, xcalloc
, xfree
));
4971 /* The rule is CUs specify all the files, including those used
4972 by any TU, so there's no need to scan TUs here. We can
4973 ignore file names coming from already-expanded CUs. */
4975 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4977 if (per_cu
->v
.quick
->compunit_symtab
)
4979 void **slot
= htab_find_slot (visited
.get (),
4980 per_cu
->v
.quick
->file_names
,
4983 *slot
= per_cu
->v
.quick
->file_names
;
4987 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4989 /* We only need to look at symtabs not already expanded. */
4990 if (per_cu
->v
.quick
->compunit_symtab
)
4993 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4994 if (file_data
== NULL
)
4997 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
5000 /* Already visited. */
5005 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
5007 const char *filename
= file_data
->file_names
[j
];
5008 dwarf2_per_objfile
->filenames_cache
->seen (filename
);
5013 dwarf2_per_objfile
->filenames_cache
->traverse ([&] (const char *filename
)
5015 gdb::unique_xmalloc_ptr
<char> this_real_name
;
5018 this_real_name
= gdb_realpath (filename
);
5019 (*fun
) (filename
, this_real_name
.get (), data
);
5024 dw2_has_symbols (struct objfile
*objfile
)
5029 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
5032 dw2_find_last_source_symtab
,
5033 dw2_forget_cached_source_info
,
5034 dw2_map_symtabs_matching_filename
,
5038 dw2_expand_symtabs_for_function
,
5039 dw2_expand_all_symtabs
,
5040 dw2_expand_symtabs_with_fullname
,
5041 dw2_map_matching_symbols
,
5042 dw2_expand_symtabs_matching
,
5043 dw2_find_pc_sect_compunit_symtab
,
5045 dw2_map_symbol_filenames
5048 /* DWARF-5 debug_names reader. */
5050 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
5051 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
5053 /* A helper function that reads the .debug_names section in SECTION
5054 and fills in MAP. FILENAME is the name of the file containing the
5055 section; it is used for error reporting.
5057 Returns true if all went well, false otherwise. */
5060 read_debug_names_from_section (struct objfile
*objfile
,
5061 const char *filename
,
5062 struct dwarf2_section_info
*section
,
5063 mapped_debug_names
&map
)
5065 if (section
->empty ())
5068 /* Older elfutils strip versions could keep the section in the main
5069 executable while splitting it for the separate debug info file. */
5070 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5073 section
->read (objfile
);
5075 map
.dwarf5_byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
5077 const gdb_byte
*addr
= section
->buffer
;
5079 bfd
*const abfd
= section
->get_bfd_owner ();
5081 unsigned int bytes_read
;
5082 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
5085 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
5086 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
5087 if (bytes_read
+ length
!= section
->size
)
5089 /* There may be multiple per-CU indices. */
5090 warning (_("Section .debug_names in %s length %s does not match "
5091 "section length %s, ignoring .debug_names."),
5092 filename
, plongest (bytes_read
+ length
),
5093 pulongest (section
->size
));
5097 /* The version number. */
5098 uint16_t version
= read_2_bytes (abfd
, addr
);
5102 warning (_("Section .debug_names in %s has unsupported version %d, "
5103 "ignoring .debug_names."),
5109 uint16_t padding
= read_2_bytes (abfd
, addr
);
5113 warning (_("Section .debug_names in %s has unsupported padding %d, "
5114 "ignoring .debug_names."),
5119 /* comp_unit_count - The number of CUs in the CU list. */
5120 map
.cu_count
= read_4_bytes (abfd
, addr
);
5123 /* local_type_unit_count - The number of TUs in the local TU
5125 map
.tu_count
= read_4_bytes (abfd
, addr
);
5128 /* foreign_type_unit_count - The number of TUs in the foreign TU
5130 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
5132 if (foreign_tu_count
!= 0)
5134 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
5135 "ignoring .debug_names."),
5136 filename
, static_cast<unsigned long> (foreign_tu_count
));
5140 /* bucket_count - The number of hash buckets in the hash lookup
5142 map
.bucket_count
= read_4_bytes (abfd
, addr
);
5145 /* name_count - The number of unique names in the index. */
5146 map
.name_count
= read_4_bytes (abfd
, addr
);
5149 /* abbrev_table_size - The size in bytes of the abbreviations
5151 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
5154 /* augmentation_string_size - The size in bytes of the augmentation
5155 string. This value is rounded up to a multiple of 4. */
5156 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
5158 map
.augmentation_is_gdb
= ((augmentation_string_size
5159 == sizeof (dwarf5_augmentation
))
5160 && memcmp (addr
, dwarf5_augmentation
,
5161 sizeof (dwarf5_augmentation
)) == 0);
5162 augmentation_string_size
+= (-augmentation_string_size
) & 3;
5163 addr
+= augmentation_string_size
;
5166 map
.cu_table_reordered
= addr
;
5167 addr
+= map
.cu_count
* map
.offset_size
;
5169 /* List of Local TUs */
5170 map
.tu_table_reordered
= addr
;
5171 addr
+= map
.tu_count
* map
.offset_size
;
5173 /* Hash Lookup Table */
5174 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5175 addr
+= map
.bucket_count
* 4;
5176 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5177 addr
+= map
.name_count
* 4;
5180 map
.name_table_string_offs_reordered
= addr
;
5181 addr
+= map
.name_count
* map
.offset_size
;
5182 map
.name_table_entry_offs_reordered
= addr
;
5183 addr
+= map
.name_count
* map
.offset_size
;
5185 const gdb_byte
*abbrev_table_start
= addr
;
5188 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5193 const auto insertpair
5194 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
5195 if (!insertpair
.second
)
5197 warning (_("Section .debug_names in %s has duplicate index %s, "
5198 "ignoring .debug_names."),
5199 filename
, pulongest (index_num
));
5202 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
5203 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5208 mapped_debug_names::index_val::attr attr
;
5209 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5211 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5213 if (attr
.form
== DW_FORM_implicit_const
)
5215 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
5219 if (attr
.dw_idx
== 0 && attr
.form
== 0)
5221 indexval
.attr_vec
.push_back (std::move (attr
));
5224 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
5226 warning (_("Section .debug_names in %s has abbreviation_table "
5227 "of size %s vs. written as %u, ignoring .debug_names."),
5228 filename
, plongest (addr
- abbrev_table_start
),
5232 map
.entry_pool
= addr
;
5237 /* A helper for create_cus_from_debug_names that handles the MAP's CU
5241 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5242 const mapped_debug_names
&map
,
5243 dwarf2_section_info
§ion
,
5246 sect_offset sect_off_prev
;
5247 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5249 sect_offset sect_off_next
;
5250 if (i
< map
.cu_count
)
5253 = (sect_offset
) (extract_unsigned_integer
5254 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5256 map
.dwarf5_byte_order
));
5259 sect_off_next
= (sect_offset
) section
.size
;
5262 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5263 dwarf2_per_cu_data
*per_cu
5264 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
5265 sect_off_prev
, length
);
5266 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
5268 sect_off_prev
= sect_off_next
;
5272 /* Read the CU list from the mapped index, and use it to create all
5273 the CU objects for this dwarf2_per_objfile. */
5276 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5277 const mapped_debug_names
&map
,
5278 const mapped_debug_names
&dwz_map
)
5280 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
5281 dwarf2_per_objfile
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5283 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
5284 dwarf2_per_objfile
->info
,
5285 false /* is_dwz */);
5287 if (dwz_map
.cu_count
== 0)
5290 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5291 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
5295 /* Read .debug_names. If everything went ok, initialize the "quick"
5296 elements of all the CUs and return true. Otherwise, return false. */
5299 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
5301 std::unique_ptr
<mapped_debug_names
> map
5302 (new mapped_debug_names (dwarf2_per_objfile
));
5303 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
5304 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5306 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5307 &dwarf2_per_objfile
->debug_names
,
5311 /* Don't use the index if it's empty. */
5312 if (map
->name_count
== 0)
5315 /* If there is a .dwz file, read it so we can get its CU list as
5317 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5320 if (!read_debug_names_from_section (objfile
,
5321 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5322 &dwz
->debug_names
, dwz_map
))
5324 warning (_("could not read '.debug_names' section from %s; skipping"),
5325 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5330 create_cus_from_debug_names (dwarf2_per_objfile
, *map
, dwz_map
);
5332 if (map
->tu_count
!= 0)
5334 /* We can only handle a single .debug_types when we have an
5336 if (dwarf2_per_objfile
->types
.size () != 1)
5339 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
5341 create_signatured_type_table_from_debug_names
5342 (dwarf2_per_objfile
, *map
, section
, &dwarf2_per_objfile
->abbrev
);
5345 create_addrmap_from_aranges (dwarf2_per_objfile
,
5346 &dwarf2_per_objfile
->debug_aranges
);
5348 dwarf2_per_objfile
->debug_names_table
= std::move (map
);
5349 dwarf2_per_objfile
->using_index
= 1;
5350 dwarf2_per_objfile
->quick_file_names_table
=
5351 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
5356 /* Type used to manage iterating over all CUs looking for a symbol for
5359 class dw2_debug_names_iterator
5362 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5363 gdb::optional
<block_enum
> block_index
,
5366 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5367 m_addr (find_vec_in_debug_names (map
, name
))
5370 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5371 search_domain search
, uint32_t namei
)
5374 m_addr (find_vec_in_debug_names (map
, namei
))
5377 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5378 block_enum block_index
, domain_enum domain
,
5380 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5381 m_addr (find_vec_in_debug_names (map
, namei
))
5384 /* Return the next matching CU or NULL if there are no more. */
5385 dwarf2_per_cu_data
*next ();
5388 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5390 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5393 /* The internalized form of .debug_names. */
5394 const mapped_debug_names
&m_map
;
5396 /* If set, only look for symbols that match that block. Valid values are
5397 GLOBAL_BLOCK and STATIC_BLOCK. */
5398 const gdb::optional
<block_enum
> m_block_index
;
5400 /* The kind of symbol we're looking for. */
5401 const domain_enum m_domain
= UNDEF_DOMAIN
;
5402 const search_domain m_search
= ALL_DOMAIN
;
5404 /* The list of CUs from the index entry of the symbol, or NULL if
5406 const gdb_byte
*m_addr
;
5410 mapped_debug_names::namei_to_name (uint32_t namei
) const
5412 const ULONGEST namei_string_offs
5413 = extract_unsigned_integer ((name_table_string_offs_reordered
5414 + namei
* offset_size
),
5417 return read_indirect_string_at_offset
5418 (dwarf2_per_objfile
, dwarf2_per_objfile
->objfile
->obfd
, namei_string_offs
);
5421 /* Find a slot in .debug_names for the object named NAME. If NAME is
5422 found, return pointer to its pool data. If NAME cannot be found,
5426 dw2_debug_names_iterator::find_vec_in_debug_names
5427 (const mapped_debug_names
&map
, const char *name
)
5429 int (*cmp
) (const char *, const char *);
5431 gdb::unique_xmalloc_ptr
<char> without_params
;
5432 if (current_language
->la_language
== language_cplus
5433 || current_language
->la_language
== language_fortran
5434 || current_language
->la_language
== language_d
)
5436 /* NAME is already canonical. Drop any qualifiers as
5437 .debug_names does not contain any. */
5439 if (strchr (name
, '(') != NULL
)
5441 without_params
= cp_remove_params (name
);
5442 if (without_params
!= NULL
)
5443 name
= without_params
.get ();
5447 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5449 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5451 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5452 (map
.bucket_table_reordered
5453 + (full_hash
% map
.bucket_count
)), 4,
5454 map
.dwarf5_byte_order
);
5458 if (namei
>= map
.name_count
)
5460 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5462 namei
, map
.name_count
,
5463 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5469 const uint32_t namei_full_hash
5470 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5471 (map
.hash_table_reordered
+ namei
), 4,
5472 map
.dwarf5_byte_order
);
5473 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5476 if (full_hash
== namei_full_hash
)
5478 const char *const namei_string
= map
.namei_to_name (namei
);
5480 #if 0 /* An expensive sanity check. */
5481 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5483 complaint (_("Wrong .debug_names hash for string at index %u "
5485 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5490 if (cmp (namei_string
, name
) == 0)
5492 const ULONGEST namei_entry_offs
5493 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5494 + namei
* map
.offset_size
),
5495 map
.offset_size
, map
.dwarf5_byte_order
);
5496 return map
.entry_pool
+ namei_entry_offs
;
5501 if (namei
>= map
.name_count
)
5507 dw2_debug_names_iterator::find_vec_in_debug_names
5508 (const mapped_debug_names
&map
, uint32_t namei
)
5510 if (namei
>= map
.name_count
)
5512 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5514 namei
, map
.name_count
,
5515 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5519 const ULONGEST namei_entry_offs
5520 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5521 + namei
* map
.offset_size
),
5522 map
.offset_size
, map
.dwarf5_byte_order
);
5523 return map
.entry_pool
+ namei_entry_offs
;
5526 /* See dw2_debug_names_iterator. */
5528 dwarf2_per_cu_data
*
5529 dw2_debug_names_iterator::next ()
5534 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
5535 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5536 bfd
*const abfd
= objfile
->obfd
;
5540 unsigned int bytes_read
;
5541 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5542 m_addr
+= bytes_read
;
5546 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5547 if (indexval_it
== m_map
.abbrev_map
.cend ())
5549 complaint (_("Wrong .debug_names undefined abbrev code %s "
5551 pulongest (abbrev
), objfile_name (objfile
));
5554 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5555 enum class symbol_linkage
{
5559 } symbol_linkage_
= symbol_linkage::unknown
;
5560 dwarf2_per_cu_data
*per_cu
= NULL
;
5561 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5566 case DW_FORM_implicit_const
:
5567 ull
= attr
.implicit_const
;
5569 case DW_FORM_flag_present
:
5573 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5574 m_addr
+= bytes_read
;
5577 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5578 dwarf_form_name (attr
.form
),
5579 objfile_name (objfile
));
5582 switch (attr
.dw_idx
)
5584 case DW_IDX_compile_unit
:
5585 /* Don't crash on bad data. */
5586 if (ull
>= dwarf2_per_objfile
->all_comp_units
.size ())
5588 complaint (_(".debug_names entry has bad CU index %s"
5591 objfile_name (dwarf2_per_objfile
->objfile
));
5594 per_cu
= dwarf2_per_objfile
->get_cutu (ull
);
5596 case DW_IDX_type_unit
:
5597 /* Don't crash on bad data. */
5598 if (ull
>= dwarf2_per_objfile
->all_type_units
.size ())
5600 complaint (_(".debug_names entry has bad TU index %s"
5603 objfile_name (dwarf2_per_objfile
->objfile
));
5606 per_cu
= &dwarf2_per_objfile
->get_tu (ull
)->per_cu
;
5608 case DW_IDX_GNU_internal
:
5609 if (!m_map
.augmentation_is_gdb
)
5611 symbol_linkage_
= symbol_linkage::static_
;
5613 case DW_IDX_GNU_external
:
5614 if (!m_map
.augmentation_is_gdb
)
5616 symbol_linkage_
= symbol_linkage::extern_
;
5621 /* Skip if already read in. */
5622 if (per_cu
->v
.quick
->compunit_symtab
)
5625 /* Check static vs global. */
5626 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5628 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5629 const bool symbol_is_static
=
5630 symbol_linkage_
== symbol_linkage::static_
;
5631 if (want_static
!= symbol_is_static
)
5635 /* Match dw2_symtab_iter_next, symbol_kind
5636 and debug_names::psymbol_tag. */
5640 switch (indexval
.dwarf_tag
)
5642 case DW_TAG_variable
:
5643 case DW_TAG_subprogram
:
5644 /* Some types are also in VAR_DOMAIN. */
5645 case DW_TAG_typedef
:
5646 case DW_TAG_structure_type
:
5653 switch (indexval
.dwarf_tag
)
5655 case DW_TAG_typedef
:
5656 case DW_TAG_structure_type
:
5663 switch (indexval
.dwarf_tag
)
5666 case DW_TAG_variable
:
5673 switch (indexval
.dwarf_tag
)
5685 /* Match dw2_expand_symtabs_matching, symbol_kind and
5686 debug_names::psymbol_tag. */
5689 case VARIABLES_DOMAIN
:
5690 switch (indexval
.dwarf_tag
)
5692 case DW_TAG_variable
:
5698 case FUNCTIONS_DOMAIN
:
5699 switch (indexval
.dwarf_tag
)
5701 case DW_TAG_subprogram
:
5708 switch (indexval
.dwarf_tag
)
5710 case DW_TAG_typedef
:
5711 case DW_TAG_structure_type
:
5717 case MODULES_DOMAIN
:
5718 switch (indexval
.dwarf_tag
)
5732 static struct compunit_symtab
*
5733 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
5734 const char *name
, domain_enum domain
)
5736 struct dwarf2_per_objfile
*dwarf2_per_objfile
5737 = get_dwarf2_per_objfile (objfile
);
5739 const auto &mapp
= dwarf2_per_objfile
->debug_names_table
;
5742 /* index is NULL if OBJF_READNOW. */
5745 const auto &map
= *mapp
;
5747 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
);
5749 struct compunit_symtab
*stab_best
= NULL
;
5750 struct dwarf2_per_cu_data
*per_cu
;
5751 while ((per_cu
= iter
.next ()) != NULL
)
5753 struct symbol
*sym
, *with_opaque
= NULL
;
5754 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
5755 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
5756 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
5758 sym
= block_find_symbol (block
, name
, domain
,
5759 block_find_non_opaque_type_preferred
,
5762 /* Some caution must be observed with overloaded functions and
5763 methods, since the index will not contain any overload
5764 information (but NAME might contain it). */
5767 && strcmp_iw (sym
->search_name (), name
) == 0)
5769 if (with_opaque
!= NULL
5770 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
5773 /* Keep looking through other CUs. */
5779 /* This dumps minimal information about .debug_names. It is called
5780 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5781 uses this to verify that .debug_names has been loaded. */
5784 dw2_debug_names_dump (struct objfile
*objfile
)
5786 struct dwarf2_per_objfile
*dwarf2_per_objfile
5787 = get_dwarf2_per_objfile (objfile
);
5789 gdb_assert (dwarf2_per_objfile
->using_index
);
5790 printf_filtered (".debug_names:");
5791 if (dwarf2_per_objfile
->debug_names_table
)
5792 printf_filtered (" exists\n");
5794 printf_filtered (" faked for \"readnow\"\n");
5795 printf_filtered ("\n");
5799 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
5800 const char *func_name
)
5802 struct dwarf2_per_objfile
*dwarf2_per_objfile
5803 = get_dwarf2_per_objfile (objfile
);
5805 /* dwarf2_per_objfile->debug_names_table is NULL if OBJF_READNOW. */
5806 if (dwarf2_per_objfile
->debug_names_table
)
5808 const mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5810 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
);
5812 struct dwarf2_per_cu_data
*per_cu
;
5813 while ((per_cu
= iter
.next ()) != NULL
)
5814 dw2_instantiate_symtab (per_cu
, false);
5819 dw2_debug_names_map_matching_symbols
5820 (struct objfile
*objfile
,
5821 const lookup_name_info
&name
, domain_enum domain
,
5823 gdb::function_view
<symbol_found_callback_ftype
> callback
,
5824 symbol_compare_ftype
*ordered_compare
)
5826 struct dwarf2_per_objfile
*dwarf2_per_objfile
5827 = get_dwarf2_per_objfile (objfile
);
5829 /* debug_names_table is NULL if OBJF_READNOW. */
5830 if (!dwarf2_per_objfile
->debug_names_table
)
5833 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5834 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
5836 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5837 auto matcher
= [&] (const char *symname
)
5839 if (ordered_compare
== nullptr)
5841 return ordered_compare (symname
, match_name
) == 0;
5844 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
5845 [&] (offset_type namei
)
5847 /* The name was matched, now expand corresponding CUs that were
5849 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
);
5851 struct dwarf2_per_cu_data
*per_cu
;
5852 while ((per_cu
= iter
.next ()) != NULL
)
5853 dw2_expand_symtabs_matching_one (per_cu
, nullptr, nullptr);
5857 /* It's a shame we couldn't do this inside the
5858 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
5859 that have already been expanded. Instead, this loop matches what
5860 the psymtab code does. */
5861 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5863 struct compunit_symtab
*cust
= per_cu
->v
.quick
->compunit_symtab
;
5864 if (cust
!= nullptr)
5866 const struct block
*block
5867 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
5868 if (!iterate_over_symbols_terminated (block
, name
,
5876 dw2_debug_names_expand_symtabs_matching
5877 (struct objfile
*objfile
,
5878 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5879 const lookup_name_info
&lookup_name
,
5880 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5881 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5882 enum search_domain kind
)
5884 struct dwarf2_per_objfile
*dwarf2_per_objfile
5885 = get_dwarf2_per_objfile (objfile
);
5887 /* debug_names_table is NULL if OBJF_READNOW. */
5888 if (!dwarf2_per_objfile
->debug_names_table
)
5891 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5893 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5895 dw2_expand_symtabs_matching_symbol (map
, lookup_name
,
5897 kind
, [&] (offset_type namei
)
5899 /* The name was matched, now expand corresponding CUs that were
5901 dw2_debug_names_iterator
iter (map
, kind
, namei
);
5903 struct dwarf2_per_cu_data
*per_cu
;
5904 while ((per_cu
= iter
.next ()) != NULL
)
5905 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5911 const struct quick_symbol_functions dwarf2_debug_names_functions
=
5914 dw2_find_last_source_symtab
,
5915 dw2_forget_cached_source_info
,
5916 dw2_map_symtabs_matching_filename
,
5917 dw2_debug_names_lookup_symbol
,
5919 dw2_debug_names_dump
,
5920 dw2_debug_names_expand_symtabs_for_function
,
5921 dw2_expand_all_symtabs
,
5922 dw2_expand_symtabs_with_fullname
,
5923 dw2_debug_names_map_matching_symbols
,
5924 dw2_debug_names_expand_symtabs_matching
,
5925 dw2_find_pc_sect_compunit_symtab
,
5927 dw2_map_symbol_filenames
5930 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5931 to either a dwarf2_per_objfile or dwz_file object. */
5933 template <typename T
>
5934 static gdb::array_view
<const gdb_byte
>
5935 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5937 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5939 if (section
->empty ())
5942 /* Older elfutils strip versions could keep the section in the main
5943 executable while splitting it for the separate debug info file. */
5944 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5947 section
->read (obj
);
5949 /* dwarf2_section_info::size is a bfd_size_type, while
5950 gdb::array_view works with size_t. On 32-bit hosts, with
5951 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5952 is 32-bit. So we need an explicit narrowing conversion here.
5953 This is fine, because it's impossible to allocate or mmap an
5954 array/buffer larger than what size_t can represent. */
5955 return gdb::make_array_view (section
->buffer
, section
->size
);
5958 /* Lookup the index cache for the contents of the index associated to
5961 static gdb::array_view
<const gdb_byte
>
5962 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_objfile
*dwarf2_obj
)
5964 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5965 if (build_id
== nullptr)
5968 return global_index_cache
.lookup_gdb_index (build_id
,
5969 &dwarf2_obj
->index_cache_res
);
5972 /* Same as the above, but for DWZ. */
5974 static gdb::array_view
<const gdb_byte
>
5975 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5977 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5978 if (build_id
== nullptr)
5981 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5984 /* See symfile.h. */
5987 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
5989 struct dwarf2_per_objfile
*dwarf2_per_objfile
5990 = get_dwarf2_per_objfile (objfile
);
5992 /* If we're about to read full symbols, don't bother with the
5993 indices. In this case we also don't care if some other debug
5994 format is making psymtabs, because they are all about to be
5996 if ((objfile
->flags
& OBJF_READNOW
))
5998 dwarf2_per_objfile
->using_index
= 1;
5999 create_all_comp_units (dwarf2_per_objfile
);
6000 create_all_type_units (dwarf2_per_objfile
);
6001 dwarf2_per_objfile
->quick_file_names_table
6002 = create_quick_file_names_table
6003 (dwarf2_per_objfile
->all_comp_units
.size ());
6005 for (int i
= 0; i
< (dwarf2_per_objfile
->all_comp_units
.size ()
6006 + dwarf2_per_objfile
->all_type_units
.size ()); ++i
)
6008 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
6010 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6011 struct dwarf2_per_cu_quick_data
);
6014 /* Return 1 so that gdb sees the "quick" functions. However,
6015 these functions will be no-ops because we will have expanded
6017 *index_kind
= dw_index_kind::GDB_INDEX
;
6021 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
6023 *index_kind
= dw_index_kind::DEBUG_NAMES
;
6027 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
6028 get_gdb_index_contents_from_section
<struct dwarf2_per_objfile
>,
6029 get_gdb_index_contents_from_section
<dwz_file
>))
6031 *index_kind
= dw_index_kind::GDB_INDEX
;
6035 /* ... otherwise, try to find the index in the index cache. */
6036 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
6037 get_gdb_index_contents_from_cache
,
6038 get_gdb_index_contents_from_cache_dwz
))
6040 global_index_cache
.hit ();
6041 *index_kind
= dw_index_kind::GDB_INDEX
;
6045 global_index_cache
.miss ();
6051 /* Build a partial symbol table. */
6054 dwarf2_build_psymtabs (struct objfile
*objfile
)
6056 struct dwarf2_per_objfile
*dwarf2_per_objfile
6057 = get_dwarf2_per_objfile (objfile
);
6059 init_psymbol_list (objfile
, 1024);
6063 /* This isn't really ideal: all the data we allocate on the
6064 objfile's obstack is still uselessly kept around. However,
6065 freeing it seems unsafe. */
6066 psymtab_discarder
psymtabs (objfile
);
6067 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
6070 /* (maybe) store an index in the cache. */
6071 global_index_cache
.store (dwarf2_per_objfile
);
6073 catch (const gdb_exception_error
&except
)
6075 exception_print (gdb_stderr
, except
);
6079 /* Return the total length of the CU described by HEADER. */
6082 get_cu_length (const struct comp_unit_head
*header
)
6084 return header
->initial_length_size
+ header
->length
;
6087 /* Return TRUE if SECT_OFF is within CU_HEADER. */
6090 offset_in_cu_p (const comp_unit_head
*cu_header
, sect_offset sect_off
)
6092 sect_offset bottom
= cu_header
->sect_off
;
6093 sect_offset top
= cu_header
->sect_off
+ get_cu_length (cu_header
);
6095 return sect_off
>= bottom
&& sect_off
< top
;
6098 /* Find the base address of the compilation unit for range lists and
6099 location lists. It will normally be specified by DW_AT_low_pc.
6100 In DWARF-3 draft 4, the base address could be overridden by
6101 DW_AT_entry_pc. It's been removed, but GCC still uses this for
6102 compilation units with discontinuous ranges. */
6105 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
6107 struct attribute
*attr
;
6110 cu
->base_address
= 0;
6112 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
6113 if (attr
!= nullptr)
6115 cu
->base_address
= attr
->value_as_address ();
6120 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6121 if (attr
!= nullptr)
6123 cu
->base_address
= attr
->value_as_address ();
6129 /* Read in the comp unit header information from the debug_info at info_ptr.
6130 Use rcuh_kind::COMPILE as the default type if not known by the caller.
6131 NOTE: This leaves members offset, first_die_offset to be filled in
6134 static const gdb_byte
*
6135 read_comp_unit_head (struct comp_unit_head
*cu_header
,
6136 const gdb_byte
*info_ptr
,
6137 struct dwarf2_section_info
*section
,
6138 rcuh_kind section_kind
)
6141 unsigned int bytes_read
;
6142 const char *filename
= section
->get_file_name ();
6143 bfd
*abfd
= section
->get_bfd_owner ();
6145 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
6146 cu_header
->initial_length_size
= bytes_read
;
6147 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
6148 info_ptr
+= bytes_read
;
6149 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
6150 if (cu_header
->version
< 2 || cu_header
->version
> 5)
6151 error (_("Dwarf Error: wrong version in compilation unit header "
6152 "(is %d, should be 2, 3, 4 or 5) [in module %s]"),
6153 cu_header
->version
, filename
);
6155 if (cu_header
->version
< 5)
6156 switch (section_kind
)
6158 case rcuh_kind::COMPILE
:
6159 cu_header
->unit_type
= DW_UT_compile
;
6161 case rcuh_kind::TYPE
:
6162 cu_header
->unit_type
= DW_UT_type
;
6165 internal_error (__FILE__
, __LINE__
,
6166 _("read_comp_unit_head: invalid section_kind"));
6170 cu_header
->unit_type
= static_cast<enum dwarf_unit_type
>
6171 (read_1_byte (abfd
, info_ptr
));
6173 switch (cu_header
->unit_type
)
6177 case DW_UT_skeleton
:
6178 case DW_UT_split_compile
:
6179 if (section_kind
!= rcuh_kind::COMPILE
)
6180 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6181 "(is %s, should be %s) [in module %s]"),
6182 dwarf_unit_type_name (cu_header
->unit_type
),
6183 dwarf_unit_type_name (DW_UT_type
), filename
);
6186 case DW_UT_split_type
:
6187 section_kind
= rcuh_kind::TYPE
;
6190 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6191 "(is %#04x, should be one of: %s, %s, %s, %s or %s) "
6192 "[in module %s]"), cu_header
->unit_type
,
6193 dwarf_unit_type_name (DW_UT_compile
),
6194 dwarf_unit_type_name (DW_UT_skeleton
),
6195 dwarf_unit_type_name (DW_UT_split_compile
),
6196 dwarf_unit_type_name (DW_UT_type
),
6197 dwarf_unit_type_name (DW_UT_split_type
), filename
);
6200 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6203 cu_header
->abbrev_sect_off
= (sect_offset
) read_offset (abfd
, info_ptr
,
6206 info_ptr
+= bytes_read
;
6207 if (cu_header
->version
< 5)
6209 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6212 signed_addr
= bfd_get_sign_extend_vma (abfd
);
6213 if (signed_addr
< 0)
6214 internal_error (__FILE__
, __LINE__
,
6215 _("read_comp_unit_head: dwarf from non elf file"));
6216 cu_header
->signed_addr_p
= signed_addr
;
6218 bool header_has_signature
= section_kind
== rcuh_kind::TYPE
6219 || cu_header
->unit_type
== DW_UT_skeleton
6220 || cu_header
->unit_type
== DW_UT_split_compile
;
6222 if (header_has_signature
)
6224 cu_header
->signature
= read_8_bytes (abfd
, info_ptr
);
6228 if (section_kind
== rcuh_kind::TYPE
)
6230 LONGEST type_offset
;
6231 type_offset
= read_offset (abfd
, info_ptr
, cu_header
, &bytes_read
);
6232 info_ptr
+= bytes_read
;
6233 cu_header
->type_cu_offset_in_tu
= (cu_offset
) type_offset
;
6234 if (to_underlying (cu_header
->type_cu_offset_in_tu
) != type_offset
)
6235 error (_("Dwarf Error: Too big type_offset in compilation unit "
6236 "header (is %s) [in module %s]"), plongest (type_offset
),
6243 /* Helper function that returns the proper abbrev section for
6246 static struct dwarf2_section_info
*
6247 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
6249 struct dwarf2_section_info
*abbrev
;
6250 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6252 if (this_cu
->is_dwz
)
6253 abbrev
= &dwarf2_get_dwz_file (dwarf2_per_objfile
)->abbrev
;
6255 abbrev
= &dwarf2_per_objfile
->abbrev
;
6260 /* Subroutine of read_and_check_comp_unit_head and
6261 read_and_check_type_unit_head to simplify them.
6262 Perform various error checking on the header. */
6265 error_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6266 struct comp_unit_head
*header
,
6267 struct dwarf2_section_info
*section
,
6268 struct dwarf2_section_info
*abbrev_section
)
6270 const char *filename
= section
->get_file_name ();
6272 if (to_underlying (header
->abbrev_sect_off
)
6273 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
, abbrev_section
))
6274 error (_("Dwarf Error: bad offset (%s) in compilation unit header "
6275 "(offset %s + 6) [in module %s]"),
6276 sect_offset_str (header
->abbrev_sect_off
),
6277 sect_offset_str (header
->sect_off
),
6280 /* Cast to ULONGEST to use 64-bit arithmetic when possible to
6281 avoid potential 32-bit overflow. */
6282 if (((ULONGEST
) header
->sect_off
+ get_cu_length (header
))
6284 error (_("Dwarf Error: bad length (0x%x) in compilation unit header "
6285 "(offset %s + 0) [in module %s]"),
6286 header
->length
, sect_offset_str (header
->sect_off
),
6290 /* Read in a CU/TU header and perform some basic error checking.
6291 The contents of the header are stored in HEADER.
6292 The result is a pointer to the start of the first DIE. */
6294 static const gdb_byte
*
6295 read_and_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6296 struct comp_unit_head
*header
,
6297 struct dwarf2_section_info
*section
,
6298 struct dwarf2_section_info
*abbrev_section
,
6299 const gdb_byte
*info_ptr
,
6300 rcuh_kind section_kind
)
6302 const gdb_byte
*beg_of_comp_unit
= info_ptr
;
6304 header
->sect_off
= (sect_offset
) (beg_of_comp_unit
- section
->buffer
);
6306 info_ptr
= read_comp_unit_head (header
, info_ptr
, section
, section_kind
);
6308 header
->first_die_cu_offset
= (cu_offset
) (info_ptr
- beg_of_comp_unit
);
6310 error_check_comp_unit_head (dwarf2_per_objfile
, header
, section
,
6316 /* Fetch the abbreviation table offset from a comp or type unit header. */
6319 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6320 struct dwarf2_section_info
*section
,
6321 sect_offset sect_off
)
6323 bfd
*abfd
= section
->get_bfd_owner ();
6324 const gdb_byte
*info_ptr
;
6325 unsigned int initial_length_size
, offset_size
;
6328 section
->read (dwarf2_per_objfile
->objfile
);
6329 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
6330 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6331 offset_size
= initial_length_size
== 4 ? 4 : 8;
6332 info_ptr
+= initial_length_size
;
6334 version
= read_2_bytes (abfd
, info_ptr
);
6338 /* Skip unit type and address size. */
6342 return (sect_offset
) read_offset_1 (abfd
, info_ptr
, offset_size
);
6345 /* Allocate a new partial symtab for file named NAME and mark this new
6346 partial symtab as being an include of PST. */
6349 dwarf2_create_include_psymtab (const char *name
, dwarf2_psymtab
*pst
,
6350 struct objfile
*objfile
)
6352 dwarf2_psymtab
*subpst
= new dwarf2_psymtab (name
, objfile
);
6354 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6356 /* It shares objfile->objfile_obstack. */
6357 subpst
->dirname
= pst
->dirname
;
6360 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
6361 subpst
->dependencies
[0] = pst
;
6362 subpst
->number_of_dependencies
= 1;
6364 /* No private part is necessary for include psymtabs. This property
6365 can be used to differentiate between such include psymtabs and
6366 the regular ones. */
6367 subpst
->per_cu_data
= nullptr;
6370 /* Read the Line Number Program data and extract the list of files
6371 included by the source file represented by PST. Build an include
6372 partial symtab for each of these included files. */
6375 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
6376 struct die_info
*die
,
6377 dwarf2_psymtab
*pst
)
6380 struct attribute
*attr
;
6382 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6383 if (attr
!= nullptr)
6384 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
6386 return; /* No linetable, so no includes. */
6388 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
6389 that we pass in the raw text_low here; that is ok because we're
6390 only decoding the line table to make include partial symtabs, and
6391 so the addresses aren't really used. */
6392 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
6393 pst
->raw_text_low (), 1);
6397 hash_signatured_type (const void *item
)
6399 const struct signatured_type
*sig_type
6400 = (const struct signatured_type
*) item
;
6402 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6403 return sig_type
->signature
;
6407 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6409 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6410 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6412 return lhs
->signature
== rhs
->signature
;
6415 /* Allocate a hash table for signatured types. */
6418 allocate_signatured_type_table (struct objfile
*objfile
)
6420 return htab_create_alloc_ex (41,
6421 hash_signatured_type
,
6424 &objfile
->objfile_obstack
,
6425 hashtab_obstack_allocate
,
6426 dummy_obstack_deallocate
);
6429 /* A helper function to add a signatured type CU to a table. */
6432 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6434 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6435 std::vector
<signatured_type
*> *all_type_units
6436 = (std::vector
<signatured_type
*> *) datum
;
6438 all_type_units
->push_back (sigt
);
6443 /* A helper for create_debug_types_hash_table. Read types from SECTION
6444 and fill them into TYPES_HTAB. It will process only type units,
6445 therefore DW_UT_type. */
6448 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6449 struct dwo_file
*dwo_file
,
6450 dwarf2_section_info
*section
, htab_t
&types_htab
,
6451 rcuh_kind section_kind
)
6453 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6454 struct dwarf2_section_info
*abbrev_section
;
6456 const gdb_byte
*info_ptr
, *end_ptr
;
6458 abbrev_section
= (dwo_file
!= NULL
6459 ? &dwo_file
->sections
.abbrev
6460 : &dwarf2_per_objfile
->abbrev
);
6462 if (dwarf_read_debug
)
6463 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6464 section
->get_name (),
6465 abbrev_section
->get_file_name ());
6467 section
->read (objfile
);
6468 info_ptr
= section
->buffer
;
6470 if (info_ptr
== NULL
)
6473 /* We can't set abfd until now because the section may be empty or
6474 not present, in which case the bfd is unknown. */
6475 abfd
= section
->get_bfd_owner ();
6477 /* We don't use cutu_reader here because we don't need to read
6478 any dies: the signature is in the header. */
6480 end_ptr
= info_ptr
+ section
->size
;
6481 while (info_ptr
< end_ptr
)
6483 struct signatured_type
*sig_type
;
6484 struct dwo_unit
*dwo_tu
;
6486 const gdb_byte
*ptr
= info_ptr
;
6487 struct comp_unit_head header
;
6488 unsigned int length
;
6490 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6492 /* Initialize it due to a false compiler warning. */
6493 header
.signature
= -1;
6494 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6496 /* We need to read the type's signature in order to build the hash
6497 table, but we don't need anything else just yet. */
6499 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
6500 abbrev_section
, ptr
, section_kind
);
6502 length
= get_cu_length (&header
);
6504 /* Skip dummy type units. */
6505 if (ptr
>= info_ptr
+ length
6506 || peek_abbrev_code (abfd
, ptr
) == 0
6507 || header
.unit_type
!= DW_UT_type
)
6513 if (types_htab
== NULL
)
6516 types_htab
= allocate_dwo_unit_table (objfile
);
6518 types_htab
= allocate_signatured_type_table (objfile
);
6524 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6526 dwo_tu
->dwo_file
= dwo_file
;
6527 dwo_tu
->signature
= header
.signature
;
6528 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6529 dwo_tu
->section
= section
;
6530 dwo_tu
->sect_off
= sect_off
;
6531 dwo_tu
->length
= length
;
6535 /* N.B.: type_offset is not usable if this type uses a DWO file.
6536 The real type_offset is in the DWO file. */
6538 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6539 struct signatured_type
);
6540 sig_type
->signature
= header
.signature
;
6541 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6542 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6543 sig_type
->per_cu
.is_debug_types
= 1;
6544 sig_type
->per_cu
.section
= section
;
6545 sig_type
->per_cu
.sect_off
= sect_off
;
6546 sig_type
->per_cu
.length
= length
;
6549 slot
= htab_find_slot (types_htab
,
6550 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6552 gdb_assert (slot
!= NULL
);
6555 sect_offset dup_sect_off
;
6559 const struct dwo_unit
*dup_tu
6560 = (const struct dwo_unit
*) *slot
;
6562 dup_sect_off
= dup_tu
->sect_off
;
6566 const struct signatured_type
*dup_tu
6567 = (const struct signatured_type
*) *slot
;
6569 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6572 complaint (_("debug type entry at offset %s is duplicate to"
6573 " the entry at offset %s, signature %s"),
6574 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6575 hex_string (header
.signature
));
6577 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6579 if (dwarf_read_debug
> 1)
6580 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6581 sect_offset_str (sect_off
),
6582 hex_string (header
.signature
));
6588 /* Create the hash table of all entries in the .debug_types
6589 (or .debug_types.dwo) section(s).
6590 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6591 otherwise it is NULL.
6593 The result is a pointer to the hash table or NULL if there are no types.
6595 Note: This function processes DWO files only, not DWP files. */
6598 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6599 struct dwo_file
*dwo_file
,
6600 gdb::array_view
<dwarf2_section_info
> type_sections
,
6603 for (dwarf2_section_info
§ion
: type_sections
)
6604 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, §ion
,
6605 types_htab
, rcuh_kind::TYPE
);
6608 /* Create the hash table of all entries in the .debug_types section,
6609 and initialize all_type_units.
6610 The result is zero if there is an error (e.g. missing .debug_types section),
6611 otherwise non-zero. */
6614 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6616 htab_t types_htab
= NULL
;
6618 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
6619 &dwarf2_per_objfile
->info
, types_htab
,
6620 rcuh_kind::COMPILE
);
6621 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
6622 dwarf2_per_objfile
->types
, types_htab
);
6623 if (types_htab
== NULL
)
6625 dwarf2_per_objfile
->signatured_types
= NULL
;
6629 dwarf2_per_objfile
->signatured_types
= types_htab
;
6631 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
6632 dwarf2_per_objfile
->all_type_units
.reserve (htab_elements (types_htab
));
6634 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
,
6635 &dwarf2_per_objfile
->all_type_units
);
6640 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
6641 If SLOT is non-NULL, it is the entry to use in the hash table.
6642 Otherwise we find one. */
6644 static struct signatured_type
*
6645 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
6648 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6650 if (dwarf2_per_objfile
->all_type_units
.size ()
6651 == dwarf2_per_objfile
->all_type_units
.capacity ())
6652 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
6654 signatured_type
*sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6655 struct signatured_type
);
6657 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
6658 sig_type
->signature
= sig
;
6659 sig_type
->per_cu
.is_debug_types
= 1;
6660 if (dwarf2_per_objfile
->using_index
)
6662 sig_type
->per_cu
.v
.quick
=
6663 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6664 struct dwarf2_per_cu_quick_data
);
6669 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
6672 gdb_assert (*slot
== NULL
);
6674 /* The rest of sig_type must be filled in by the caller. */
6678 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6679 Fill in SIG_ENTRY with DWO_ENTRY. */
6682 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6683 struct signatured_type
*sig_entry
,
6684 struct dwo_unit
*dwo_entry
)
6686 /* Make sure we're not clobbering something we don't expect to. */
6687 gdb_assert (! sig_entry
->per_cu
.queued
);
6688 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
6689 if (dwarf2_per_objfile
->using_index
)
6691 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6692 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
6695 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6696 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6697 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6698 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6699 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6701 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6702 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6703 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6704 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6705 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6706 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6707 sig_entry
->dwo_unit
= dwo_entry
;
6710 /* Subroutine of lookup_signatured_type.
6711 If we haven't read the TU yet, create the signatured_type data structure
6712 for a TU to be read in directly from a DWO file, bypassing the stub.
6713 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6714 using .gdb_index, then when reading a CU we want to stay in the DWO file
6715 containing that CU. Otherwise we could end up reading several other DWO
6716 files (due to comdat folding) to process the transitive closure of all the
6717 mentioned TUs, and that can be slow. The current DWO file will have every
6718 type signature that it needs.
6719 We only do this for .gdb_index because in the psymtab case we already have
6720 to read all the DWOs to build the type unit groups. */
6722 static struct signatured_type
*
6723 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6725 struct dwarf2_per_objfile
*dwarf2_per_objfile
6726 = cu
->per_cu
->dwarf2_per_objfile
;
6727 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6728 struct dwo_file
*dwo_file
;
6729 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6730 struct signatured_type find_sig_entry
, *sig_entry
;
6733 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6735 /* If TU skeletons have been removed then we may not have read in any
6737 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6739 dwarf2_per_objfile
->signatured_types
6740 = allocate_signatured_type_table (objfile
);
6743 /* We only ever need to read in one copy of a signatured type.
6744 Use the global signatured_types array to do our own comdat-folding
6745 of types. If this is the first time we're reading this TU, and
6746 the TU has an entry in .gdb_index, replace the recorded data from
6747 .gdb_index with this TU. */
6749 find_sig_entry
.signature
= sig
;
6750 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
6751 &find_sig_entry
, INSERT
);
6752 sig_entry
= (struct signatured_type
*) *slot
;
6754 /* We can get here with the TU already read, *or* in the process of being
6755 read. Don't reassign the global entry to point to this DWO if that's
6756 the case. Also note that if the TU is already being read, it may not
6757 have come from a DWO, the program may be a mix of Fission-compiled
6758 code and non-Fission-compiled code. */
6760 /* Have we already tried to read this TU?
6761 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6762 needn't exist in the global table yet). */
6763 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
6766 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6767 dwo_unit of the TU itself. */
6768 dwo_file
= cu
->dwo_unit
->dwo_file
;
6770 /* Ok, this is the first time we're reading this TU. */
6771 if (dwo_file
->tus
== NULL
)
6773 find_dwo_entry
.signature
= sig
;
6774 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_entry
);
6775 if (dwo_entry
== NULL
)
6778 /* If the global table doesn't have an entry for this TU, add one. */
6779 if (sig_entry
== NULL
)
6780 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6782 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6783 sig_entry
->per_cu
.tu_read
= 1;
6787 /* Subroutine of lookup_signatured_type.
6788 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6789 then try the DWP file. If the TU stub (skeleton) has been removed then
6790 it won't be in .gdb_index. */
6792 static struct signatured_type
*
6793 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6795 struct dwarf2_per_objfile
*dwarf2_per_objfile
6796 = cu
->per_cu
->dwarf2_per_objfile
;
6797 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6798 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
6799 struct dwo_unit
*dwo_entry
;
6800 struct signatured_type find_sig_entry
, *sig_entry
;
6803 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6804 gdb_assert (dwp_file
!= NULL
);
6806 /* If TU skeletons have been removed then we may not have read in any
6808 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6810 dwarf2_per_objfile
->signatured_types
6811 = allocate_signatured_type_table (objfile
);
6814 find_sig_entry
.signature
= sig
;
6815 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
6816 &find_sig_entry
, INSERT
);
6817 sig_entry
= (struct signatured_type
*) *slot
;
6819 /* Have we already tried to read this TU?
6820 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6821 needn't exist in the global table yet). */
6822 if (sig_entry
!= NULL
)
6825 if (dwp_file
->tus
== NULL
)
6827 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
6828 sig
, 1 /* is_debug_types */);
6829 if (dwo_entry
== NULL
)
6832 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6833 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6838 /* Lookup a signature based type for DW_FORM_ref_sig8.
6839 Returns NULL if signature SIG is not present in the table.
6840 It is up to the caller to complain about this. */
6842 static struct signatured_type
*
6843 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6845 struct dwarf2_per_objfile
*dwarf2_per_objfile
6846 = cu
->per_cu
->dwarf2_per_objfile
;
6849 && dwarf2_per_objfile
->using_index
)
6851 /* We're in a DWO/DWP file, and we're using .gdb_index.
6852 These cases require special processing. */
6853 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
6854 return lookup_dwo_signatured_type (cu
, sig
);
6856 return lookup_dwp_signatured_type (cu
, sig
);
6860 struct signatured_type find_entry
, *entry
;
6862 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6864 find_entry
.signature
= sig
;
6865 entry
= ((struct signatured_type
*)
6866 htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
));
6871 /* Return the address base of the compile unit, which, if exists, is stored
6872 either at the attribute DW_AT_GNU_addr_base, or DW_AT_addr_base. */
6873 static gdb::optional
<ULONGEST
>
6874 lookup_addr_base (struct die_info
*comp_unit_die
)
6876 struct attribute
*attr
;
6877 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_addr_base
);
6878 if (attr
== nullptr)
6879 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_GNU_addr_base
);
6880 if (attr
== nullptr)
6881 return gdb::optional
<ULONGEST
> ();
6882 return DW_UNSND (attr
);
6885 /* Return range lists base of the compile unit, which, if exists, is stored
6886 either at the attribute DW_AT_rnglists_base or DW_AT_GNU_ranges_base. */
6888 lookup_ranges_base (struct die_info
*comp_unit_die
)
6890 struct attribute
*attr
;
6891 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_rnglists_base
);
6892 if (attr
== nullptr)
6893 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_GNU_ranges_base
);
6894 if (attr
== nullptr)
6896 return DW_UNSND (attr
);
6899 /* Low level DIE reading support. */
6901 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6904 init_cu_die_reader (struct die_reader_specs
*reader
,
6905 struct dwarf2_cu
*cu
,
6906 struct dwarf2_section_info
*section
,
6907 struct dwo_file
*dwo_file
,
6908 struct abbrev_table
*abbrev_table
)
6910 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6911 reader
->abfd
= section
->get_bfd_owner ();
6913 reader
->dwo_file
= dwo_file
;
6914 reader
->die_section
= section
;
6915 reader
->buffer
= section
->buffer
;
6916 reader
->buffer_end
= section
->buffer
+ section
->size
;
6917 reader
->comp_dir
= NULL
;
6918 reader
->abbrev_table
= abbrev_table
;
6921 /* Subroutine of cutu_reader to simplify it.
6922 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6923 There's just a lot of work to do, and cutu_reader is big enough
6926 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6927 from it to the DIE in the DWO. If NULL we are skipping the stub.
6928 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6929 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6930 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6931 STUB_COMP_DIR may be non-NULL.
6932 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE,*RESULT_HAS_CHILDREN
6933 are filled in with the info of the DIE from the DWO file.
6934 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6935 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6936 kept around for at least as long as *RESULT_READER.
6938 The result is non-zero if a valid (non-dummy) DIE was found. */
6941 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
6942 struct dwo_unit
*dwo_unit
,
6943 struct die_info
*stub_comp_unit_die
,
6944 const char *stub_comp_dir
,
6945 struct die_reader_specs
*result_reader
,
6946 const gdb_byte
**result_info_ptr
,
6947 struct die_info
**result_comp_unit_die
,
6948 int *result_has_children
,
6949 abbrev_table_up
*result_dwo_abbrev_table
)
6951 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6952 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6953 struct dwarf2_cu
*cu
= this_cu
->cu
;
6955 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6956 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6957 int i
,num_extra_attrs
;
6958 struct dwarf2_section_info
*dwo_abbrev_section
;
6959 struct die_info
*comp_unit_die
;
6961 /* At most one of these may be provided. */
6962 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6964 /* These attributes aren't processed until later:
6965 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6966 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6967 referenced later. However, these attributes are found in the stub
6968 which we won't have later. In order to not impose this complication
6969 on the rest of the code, we read them here and copy them to the
6978 if (stub_comp_unit_die
!= NULL
)
6980 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6982 if (! this_cu
->is_debug_types
)
6983 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6984 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6985 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6986 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6987 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6989 cu
->addr_base
= lookup_addr_base (stub_comp_unit_die
);
6991 /* There should be a DW_AT_rnglists_base (DW_AT_GNU_ranges_base) attribute
6992 here (if needed). We need the value before we can process
6994 cu
->ranges_base
= lookup_ranges_base (stub_comp_unit_die
);
6996 else if (stub_comp_dir
!= NULL
)
6998 /* Reconstruct the comp_dir attribute to simplify the code below. */
6999 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
7000 comp_dir
->name
= DW_AT_comp_dir
;
7001 comp_dir
->form
= DW_FORM_string
;
7002 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
7003 DW_STRING (comp_dir
) = stub_comp_dir
;
7006 /* Set up for reading the DWO CU/TU. */
7007 cu
->dwo_unit
= dwo_unit
;
7008 dwarf2_section_info
*section
= dwo_unit
->section
;
7009 section
->read (objfile
);
7010 abfd
= section
->get_bfd_owner ();
7011 begin_info_ptr
= info_ptr
= (section
->buffer
7012 + to_underlying (dwo_unit
->sect_off
));
7013 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
7015 if (this_cu
->is_debug_types
)
7017 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
7019 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7020 &cu
->header
, section
,
7022 info_ptr
, rcuh_kind::TYPE
);
7023 /* This is not an assert because it can be caused by bad debug info. */
7024 if (sig_type
->signature
!= cu
->header
.signature
)
7026 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
7027 " TU at offset %s [in module %s]"),
7028 hex_string (sig_type
->signature
),
7029 hex_string (cu
->header
.signature
),
7030 sect_offset_str (dwo_unit
->sect_off
),
7031 bfd_get_filename (abfd
));
7033 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7034 /* For DWOs coming from DWP files, we don't know the CU length
7035 nor the type's offset in the TU until now. */
7036 dwo_unit
->length
= get_cu_length (&cu
->header
);
7037 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
7039 /* Establish the type offset that can be used to lookup the type.
7040 For DWO files, we don't know it until now. */
7041 sig_type
->type_offset_in_section
7042 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
7046 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7047 &cu
->header
, section
,
7049 info_ptr
, rcuh_kind::COMPILE
);
7050 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7051 /* For DWOs coming from DWP files, we don't know the CU length
7053 dwo_unit
->length
= get_cu_length (&cu
->header
);
7056 *result_dwo_abbrev_table
7057 = abbrev_table_read_table (objfile
, dwo_abbrev_section
,
7058 cu
->header
.abbrev_sect_off
);
7059 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
7060 result_dwo_abbrev_table
->get ());
7062 /* Read in the die, but leave space to copy over the attributes
7063 from the stub. This has the benefit of simplifying the rest of
7064 the code - all the work to maintain the illusion of a single
7065 DW_TAG_{compile,type}_unit DIE is done here. */
7066 num_extra_attrs
= ((stmt_list
!= NULL
)
7070 + (comp_dir
!= NULL
));
7071 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
7072 result_has_children
, num_extra_attrs
);
7074 /* Copy over the attributes from the stub to the DIE we just read in. */
7075 comp_unit_die
= *result_comp_unit_die
;
7076 i
= comp_unit_die
->num_attrs
;
7077 if (stmt_list
!= NULL
)
7078 comp_unit_die
->attrs
[i
++] = *stmt_list
;
7080 comp_unit_die
->attrs
[i
++] = *low_pc
;
7081 if (high_pc
!= NULL
)
7082 comp_unit_die
->attrs
[i
++] = *high_pc
;
7084 comp_unit_die
->attrs
[i
++] = *ranges
;
7085 if (comp_dir
!= NULL
)
7086 comp_unit_die
->attrs
[i
++] = *comp_dir
;
7087 comp_unit_die
->num_attrs
+= num_extra_attrs
;
7089 if (dwarf_die_debug
)
7091 fprintf_unfiltered (gdb_stdlog
,
7092 "Read die from %s@0x%x of %s:\n",
7093 section
->get_name (),
7094 (unsigned) (begin_info_ptr
- section
->buffer
),
7095 bfd_get_filename (abfd
));
7096 dump_die (comp_unit_die
, dwarf_die_debug
);
7099 /* Save the comp_dir attribute. If there is no DWP file then we'll read
7100 TUs by skipping the stub and going directly to the entry in the DWO file.
7101 However, skipping the stub means we won't get DW_AT_comp_dir, so we have
7102 to get it via circuitous means. Blech. */
7103 if (comp_dir
!= NULL
)
7104 result_reader
->comp_dir
= DW_STRING (comp_dir
);
7106 /* Skip dummy compilation units. */
7107 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
7108 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7111 *result_info_ptr
= info_ptr
;
7115 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
7116 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
7117 signature is part of the header. */
7118 static gdb::optional
<ULONGEST
>
7119 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
7121 if (cu
->header
.version
>= 5)
7122 return cu
->header
.signature
;
7123 struct attribute
*attr
;
7124 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
7125 if (attr
== nullptr)
7126 return gdb::optional
<ULONGEST
> ();
7127 return DW_UNSND (attr
);
7130 /* Subroutine of cutu_reader to simplify it.
7131 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
7132 Returns NULL if the specified DWO unit cannot be found. */
7134 static struct dwo_unit
*
7135 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
7136 struct die_info
*comp_unit_die
,
7137 const char *dwo_name
)
7139 struct dwarf2_cu
*cu
= this_cu
->cu
;
7140 struct dwo_unit
*dwo_unit
;
7141 const char *comp_dir
;
7143 gdb_assert (cu
!= NULL
);
7145 /* Yeah, we look dwo_name up again, but it simplifies the code. */
7146 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7147 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7149 if (this_cu
->is_debug_types
)
7151 struct signatured_type
*sig_type
;
7153 /* Since this_cu is the first member of struct signatured_type,
7154 we can go from a pointer to one to a pointer to the other. */
7155 sig_type
= (struct signatured_type
*) this_cu
;
7156 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
7160 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
7161 if (!signature
.has_value ())
7162 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
7164 dwo_name
, objfile_name (this_cu
->dwarf2_per_objfile
->objfile
));
7165 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
7172 /* Subroutine of cutu_reader to simplify it.
7173 See it for a description of the parameters.
7174 Read a TU directly from a DWO file, bypassing the stub. */
7177 cutu_reader::init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
7178 int use_existing_cu
, int keep
)
7180 struct signatured_type
*sig_type
;
7181 struct die_reader_specs reader
;
7183 /* Verify we can do the following downcast, and that we have the
7185 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
7186 sig_type
= (struct signatured_type
*) this_cu
;
7187 gdb_assert (sig_type
->dwo_unit
!= NULL
);
7189 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7191 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
7192 /* There's no need to do the rereading_dwo_cu handling that
7193 cutu_reader does since we don't read the stub. */
7197 /* If !use_existing_cu, this_cu->cu must be NULL. */
7198 gdb_assert (this_cu
->cu
== NULL
);
7199 m_new_cu
.reset (new dwarf2_cu (this_cu
));
7202 /* A future optimization, if needed, would be to use an existing
7203 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
7204 could share abbrev tables. */
7206 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
7207 NULL
/* stub_comp_unit_die */,
7208 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
7210 &comp_unit_die
, &has_children
,
7211 &m_dwo_abbrev_table
) == 0)
7218 /* Initialize a CU (or TU) and read its DIEs.
7219 If the CU defers to a DWO file, read the DWO file as well.
7221 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
7222 Otherwise the table specified in the comp unit header is read in and used.
7223 This is an optimization for when we already have the abbrev table.
7225 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
7226 Otherwise, a new CU is allocated with xmalloc.
7228 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
7229 read_in_chain. Otherwise the dwarf2_cu data is freed at the
7232 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
7233 struct abbrev_table
*abbrev_table
,
7234 int use_existing_cu
, int keep
,
7236 : die_reader_specs
{},
7237 m_this_cu (this_cu
),
7240 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7241 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7242 struct dwarf2_section_info
*section
= this_cu
->section
;
7243 bfd
*abfd
= section
->get_bfd_owner ();
7244 struct dwarf2_cu
*cu
;
7245 const gdb_byte
*begin_info_ptr
;
7246 struct signatured_type
*sig_type
= NULL
;
7247 struct dwarf2_section_info
*abbrev_section
;
7248 /* Non-zero if CU currently points to a DWO file and we need to
7249 reread it. When this happens we need to reread the skeleton die
7250 before we can reread the DWO file (this only applies to CUs, not TUs). */
7251 int rereading_dwo_cu
= 0;
7253 if (dwarf_die_debug
)
7254 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7255 this_cu
->is_debug_types
? "type" : "comp",
7256 sect_offset_str (this_cu
->sect_off
));
7258 if (use_existing_cu
)
7261 /* If we're reading a TU directly from a DWO file, including a virtual DWO
7262 file (instead of going through the stub), short-circuit all of this. */
7263 if (this_cu
->reading_dwo_directly
)
7265 /* Narrow down the scope of possibilities to have to understand. */
7266 gdb_assert (this_cu
->is_debug_types
);
7267 gdb_assert (abbrev_table
== NULL
);
7268 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
, keep
);
7272 /* This is cheap if the section is already read in. */
7273 section
->read (objfile
);
7275 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7277 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
7279 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7282 /* If this CU is from a DWO file we need to start over, we need to
7283 refetch the attributes from the skeleton CU.
7284 This could be optimized by retrieving those attributes from when we
7285 were here the first time: the previous comp_unit_die was stored in
7286 comp_unit_obstack. But there's no data yet that we need this
7288 if (cu
->dwo_unit
!= NULL
)
7289 rereading_dwo_cu
= 1;
7293 /* If !use_existing_cu, this_cu->cu must be NULL. */
7294 gdb_assert (this_cu
->cu
== NULL
);
7295 m_new_cu
.reset (new dwarf2_cu (this_cu
));
7296 cu
= m_new_cu
.get ();
7299 /* Get the header. */
7300 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
7302 /* We already have the header, there's no need to read it in again. */
7303 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
7307 if (this_cu
->is_debug_types
)
7309 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7310 &cu
->header
, section
,
7311 abbrev_section
, info_ptr
,
7314 /* Since per_cu is the first member of struct signatured_type,
7315 we can go from a pointer to one to a pointer to the other. */
7316 sig_type
= (struct signatured_type
*) this_cu
;
7317 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
7318 gdb_assert (sig_type
->type_offset_in_tu
7319 == cu
->header
.type_cu_offset_in_tu
);
7320 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7322 /* LENGTH has not been set yet for type units if we're
7323 using .gdb_index. */
7324 this_cu
->length
= get_cu_length (&cu
->header
);
7326 /* Establish the type offset that can be used to lookup the type. */
7327 sig_type
->type_offset_in_section
=
7328 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
7330 this_cu
->dwarf_version
= cu
->header
.version
;
7334 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7335 &cu
->header
, section
,
7338 rcuh_kind::COMPILE
);
7340 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7341 gdb_assert (this_cu
->length
== get_cu_length (&cu
->header
));
7342 this_cu
->dwarf_version
= cu
->header
.version
;
7346 /* Skip dummy compilation units. */
7347 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7348 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7354 /* If we don't have them yet, read the abbrevs for this compilation unit.
7355 And if we need to read them now, make sure they're freed when we're
7357 if (abbrev_table
!= NULL
)
7358 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
7361 m_abbrev_table_holder
7362 = abbrev_table_read_table (objfile
, abbrev_section
,
7363 cu
->header
.abbrev_sect_off
);
7364 abbrev_table
= m_abbrev_table_holder
.get ();
7367 /* Read the top level CU/TU die. */
7368 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
7369 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
, &has_children
);
7371 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
7377 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
7378 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
7379 table from the DWO file and pass the ownership over to us. It will be
7380 referenced from READER, so we must make sure to free it after we're done
7383 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
7384 DWO CU, that this test will fail (the attribute will not be present). */
7385 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7386 if (dwo_name
!= nullptr)
7388 struct dwo_unit
*dwo_unit
;
7389 struct die_info
*dwo_comp_unit_die
;
7393 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
7394 " has children (offset %s) [in module %s]"),
7395 sect_offset_str (this_cu
->sect_off
),
7396 bfd_get_filename (abfd
));
7398 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
, dwo_name
);
7399 if (dwo_unit
!= NULL
)
7401 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
7402 comp_unit_die
, NULL
,
7404 &dwo_comp_unit_die
, &has_children
,
7405 &m_dwo_abbrev_table
) == 0)
7411 comp_unit_die
= dwo_comp_unit_die
;
7415 /* Yikes, we couldn't find the rest of the DIE, we only have
7416 the stub. A complaint has already been logged. There's
7417 not much more we can do except pass on the stub DIE to
7418 die_reader_func. We don't want to throw an error on bad
7424 cutu_reader::~cutu_reader ()
7426 /* Done, clean up. */
7427 if (m_new_cu
!= NULL
&& m_keep
&& !dummy_p
)
7429 struct dwarf2_per_objfile
*dwarf2_per_objfile
7430 = m_this_cu
->dwarf2_per_objfile
;
7431 /* Link this CU into read_in_chain. */
7432 m_this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
7433 dwarf2_per_objfile
->read_in_chain
= m_this_cu
;
7434 /* The chain owns it now. */
7435 m_new_cu
.release ();
7439 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
7440 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
7441 assumed to have already done the lookup to find the DWO file).
7443 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7444 THIS_CU->is_debug_types, but nothing else.
7446 We fill in THIS_CU->length.
7448 THIS_CU->cu is always freed when done.
7449 This is done in order to not leave THIS_CU->cu in a state where we have
7450 to care whether it refers to the "main" CU or the DWO CU.
7452 When parent_cu is passed, it is used to provide a default value for
7453 str_offsets_base and addr_base from the parent. */
7455 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
7456 struct dwarf2_cu
*parent_cu
,
7457 struct dwo_file
*dwo_file
)
7458 : die_reader_specs
{},
7461 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7462 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7463 struct dwarf2_section_info
*section
= this_cu
->section
;
7464 bfd
*abfd
= section
->get_bfd_owner ();
7465 struct dwarf2_section_info
*abbrev_section
;
7466 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7469 if (dwarf_die_debug
)
7470 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7471 this_cu
->is_debug_types
? "type" : "comp",
7472 sect_offset_str (this_cu
->sect_off
));
7474 gdb_assert (this_cu
->cu
== NULL
);
7476 abbrev_section
= (dwo_file
!= NULL
7477 ? &dwo_file
->sections
.abbrev
7478 : get_abbrev_section_for_cu (this_cu
));
7480 /* This is cheap if the section is already read in. */
7481 section
->read (objfile
);
7483 m_new_cu
.reset (new dwarf2_cu (this_cu
));
7485 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7486 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7487 &m_new_cu
->header
, section
,
7488 abbrev_section
, info_ptr
,
7489 (this_cu
->is_debug_types
7491 : rcuh_kind::COMPILE
));
7493 if (parent_cu
!= nullptr)
7495 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
7496 m_new_cu
->addr_base
= parent_cu
->addr_base
;
7498 this_cu
->length
= get_cu_length (&m_new_cu
->header
);
7500 /* Skip dummy compilation units. */
7501 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7502 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7508 m_abbrev_table_holder
7509 = abbrev_table_read_table (objfile
, abbrev_section
,
7510 m_new_cu
->header
.abbrev_sect_off
);
7512 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
7513 m_abbrev_table_holder
.get ());
7514 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
, &has_children
);
7518 /* Type Unit Groups.
7520 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7521 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7522 so that all types coming from the same compilation (.o file) are grouped
7523 together. A future step could be to put the types in the same symtab as
7524 the CU the types ultimately came from. */
7527 hash_type_unit_group (const void *item
)
7529 const struct type_unit_group
*tu_group
7530 = (const struct type_unit_group
*) item
;
7532 return hash_stmt_list_entry (&tu_group
->hash
);
7536 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7538 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7539 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7541 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7544 /* Allocate a hash table for type unit groups. */
7547 allocate_type_unit_groups_table (struct objfile
*objfile
)
7549 return htab_create_alloc_ex (3,
7550 hash_type_unit_group
,
7553 &objfile
->objfile_obstack
,
7554 hashtab_obstack_allocate
,
7555 dummy_obstack_deallocate
);
7558 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7559 partial symtabs. We combine several TUs per psymtab to not let the size
7560 of any one psymtab grow too big. */
7561 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7562 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7564 /* Helper routine for get_type_unit_group.
7565 Create the type_unit_group object used to hold one or more TUs. */
7567 static struct type_unit_group
*
7568 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7570 struct dwarf2_per_objfile
*dwarf2_per_objfile
7571 = cu
->per_cu
->dwarf2_per_objfile
;
7572 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7573 struct dwarf2_per_cu_data
*per_cu
;
7574 struct type_unit_group
*tu_group
;
7576 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7577 struct type_unit_group
);
7578 per_cu
= &tu_group
->per_cu
;
7579 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7581 if (dwarf2_per_objfile
->using_index
)
7583 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7584 struct dwarf2_per_cu_quick_data
);
7588 unsigned int line_offset
= to_underlying (line_offset_struct
);
7589 dwarf2_psymtab
*pst
;
7592 /* Give the symtab a useful name for debug purposes. */
7593 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7594 name
= string_printf ("<type_units_%d>",
7595 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7597 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7599 pst
= create_partial_symtab (per_cu
, name
.c_str ());
7600 pst
->anonymous
= true;
7603 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7604 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7609 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7610 STMT_LIST is a DW_AT_stmt_list attribute. */
7612 static struct type_unit_group
*
7613 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7615 struct dwarf2_per_objfile
*dwarf2_per_objfile
7616 = cu
->per_cu
->dwarf2_per_objfile
;
7617 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7618 struct type_unit_group
*tu_group
;
7620 unsigned int line_offset
;
7621 struct type_unit_group type_unit_group_for_lookup
;
7623 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
7625 dwarf2_per_objfile
->type_unit_groups
=
7626 allocate_type_unit_groups_table (dwarf2_per_objfile
->objfile
);
7629 /* Do we need to create a new group, or can we use an existing one? */
7633 line_offset
= DW_UNSND (stmt_list
);
7634 ++tu_stats
->nr_symtab_sharers
;
7638 /* Ugh, no stmt_list. Rare, but we have to handle it.
7639 We can do various things here like create one group per TU or
7640 spread them over multiple groups to split up the expansion work.
7641 To avoid worst case scenarios (too many groups or too large groups)
7642 we, umm, group them in bunches. */
7643 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7644 | (tu_stats
->nr_stmt_less_type_units
7645 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7646 ++tu_stats
->nr_stmt_less_type_units
;
7649 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7650 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7651 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
,
7652 &type_unit_group_for_lookup
, INSERT
);
7655 tu_group
= (struct type_unit_group
*) *slot
;
7656 gdb_assert (tu_group
!= NULL
);
7660 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7661 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7663 ++tu_stats
->nr_symtabs
;
7669 /* Partial symbol tables. */
7671 /* Create a psymtab named NAME and assign it to PER_CU.
7673 The caller must fill in the following details:
7674 dirname, textlow, texthigh. */
7676 static dwarf2_psymtab
*
7677 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
7679 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
7680 dwarf2_psymtab
*pst
;
7682 pst
= new dwarf2_psymtab (name
, objfile
, 0);
7684 pst
->psymtabs_addrmap_supported
= true;
7686 /* This is the glue that links PST into GDB's symbol API. */
7687 pst
->per_cu_data
= per_cu
;
7688 per_cu
->v
.psymtab
= pst
;
7693 /* DIE reader function for process_psymtab_comp_unit. */
7696 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7697 const gdb_byte
*info_ptr
,
7698 struct die_info
*comp_unit_die
,
7700 int want_partial_unit
,
7701 enum language pretend_language
)
7703 struct dwarf2_cu
*cu
= reader
->cu
;
7704 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
7705 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7706 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7708 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7709 dwarf2_psymtab
*pst
;
7710 enum pc_bounds_kind cu_bounds_kind
;
7711 const char *filename
;
7713 if (comp_unit_die
->tag
== DW_TAG_partial_unit
&& !want_partial_unit
)
7716 gdb_assert (! per_cu
->is_debug_types
);
7718 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
7720 /* Allocate a new partial symbol table structure. */
7721 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7722 if (filename
== NULL
)
7725 pst
= create_partial_symtab (per_cu
, filename
);
7727 /* This must be done before calling dwarf2_build_include_psymtabs. */
7728 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7730 baseaddr
= objfile
->text_section_offset ();
7732 dwarf2_find_base_address (comp_unit_die
, cu
);
7734 /* Possibly set the default values of LOWPC and HIGHPC from
7736 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7737 &best_highpc
, cu
, pst
);
7738 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7741 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7744 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7746 /* Store the contiguous range if it is not empty; it can be
7747 empty for CUs with no code. */
7748 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
7752 /* Check if comp unit has_children.
7753 If so, read the rest of the partial symbols from this comp unit.
7754 If not, there's no more debug_info for this comp unit. */
7757 struct partial_die_info
*first_die
;
7758 CORE_ADDR lowpc
, highpc
;
7760 lowpc
= ((CORE_ADDR
) -1);
7761 highpc
= ((CORE_ADDR
) 0);
7763 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7765 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7766 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7768 /* If we didn't find a lowpc, set it to highpc to avoid
7769 complaints from `maint check'. */
7770 if (lowpc
== ((CORE_ADDR
) -1))
7773 /* If the compilation unit didn't have an explicit address range,
7774 then use the information extracted from its child dies. */
7775 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7778 best_highpc
= highpc
;
7781 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7782 best_lowpc
+ baseaddr
)
7784 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7785 best_highpc
+ baseaddr
)
7788 end_psymtab_common (objfile
, pst
);
7790 if (!cu
->per_cu
->imported_symtabs_empty ())
7793 int len
= cu
->per_cu
->imported_symtabs_size ();
7795 /* Fill in 'dependencies' here; we fill in 'users' in a
7797 pst
->number_of_dependencies
= len
;
7799 = objfile
->partial_symtabs
->allocate_dependencies (len
);
7800 for (i
= 0; i
< len
; ++i
)
7802 pst
->dependencies
[i
]
7803 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7806 cu
->per_cu
->imported_symtabs_free ();
7809 /* Get the list of files included in the current compilation unit,
7810 and build a psymtab for each of them. */
7811 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
7813 if (dwarf_read_debug
)
7814 fprintf_unfiltered (gdb_stdlog
,
7815 "Psymtab for %s unit @%s: %s - %s"
7816 ", %d global, %d static syms\n",
7817 per_cu
->is_debug_types
? "type" : "comp",
7818 sect_offset_str (per_cu
->sect_off
),
7819 paddress (gdbarch
, pst
->text_low (objfile
)),
7820 paddress (gdbarch
, pst
->text_high (objfile
)),
7821 pst
->n_global_syms
, pst
->n_static_syms
);
7824 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7825 Process compilation unit THIS_CU for a psymtab. */
7828 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
7829 int want_partial_unit
,
7830 enum language pretend_language
)
7832 /* If this compilation unit was already read in, free the
7833 cached copy in order to read it in again. This is
7834 necessary because we skipped some symbols when we first
7835 read in the compilation unit (see load_partial_dies).
7836 This problem could be avoided, but the benefit is unclear. */
7837 if (this_cu
->cu
!= NULL
)
7838 free_one_cached_comp_unit (this_cu
);
7840 cutu_reader
reader (this_cu
, NULL
, 0, 0, false);
7846 else if (this_cu
->is_debug_types
)
7847 build_type_psymtabs_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
7848 reader
.has_children
);
7850 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7851 reader
.comp_unit_die
,
7852 reader
.has_children
,
7856 /* Age out any secondary CUs. */
7857 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
7860 /* Reader function for build_type_psymtabs. */
7863 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7864 const gdb_byte
*info_ptr
,
7865 struct die_info
*type_unit_die
,
7868 struct dwarf2_per_objfile
*dwarf2_per_objfile
7869 = reader
->cu
->per_cu
->dwarf2_per_objfile
;
7870 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7871 struct dwarf2_cu
*cu
= reader
->cu
;
7872 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7873 struct signatured_type
*sig_type
;
7874 struct type_unit_group
*tu_group
;
7875 struct attribute
*attr
;
7876 struct partial_die_info
*first_die
;
7877 CORE_ADDR lowpc
, highpc
;
7878 dwarf2_psymtab
*pst
;
7880 gdb_assert (per_cu
->is_debug_types
);
7881 sig_type
= (struct signatured_type
*) per_cu
;
7886 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
7887 tu_group
= get_type_unit_group (cu
, attr
);
7889 if (tu_group
->tus
== nullptr)
7890 tu_group
->tus
= new std::vector
<signatured_type
*>;
7891 tu_group
->tus
->push_back (sig_type
);
7893 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7894 pst
= create_partial_symtab (per_cu
, "");
7895 pst
->anonymous
= true;
7897 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7899 lowpc
= (CORE_ADDR
) -1;
7900 highpc
= (CORE_ADDR
) 0;
7901 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7903 end_psymtab_common (objfile
, pst
);
7906 /* Struct used to sort TUs by their abbreviation table offset. */
7908 struct tu_abbrev_offset
7910 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7911 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7914 signatured_type
*sig_type
;
7915 sect_offset abbrev_offset
;
7918 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
7921 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
7922 const struct tu_abbrev_offset
&b
)
7924 return a
.abbrev_offset
< b
.abbrev_offset
;
7927 /* Efficiently read all the type units.
7928 This does the bulk of the work for build_type_psymtabs.
7930 The efficiency is because we sort TUs by the abbrev table they use and
7931 only read each abbrev table once. In one program there are 200K TUs
7932 sharing 8K abbrev tables.
7934 The main purpose of this function is to support building the
7935 dwarf2_per_objfile->type_unit_groups table.
7936 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7937 can collapse the search space by grouping them by stmt_list.
7938 The savings can be significant, in the same program from above the 200K TUs
7939 share 8K stmt_list tables.
7941 FUNC is expected to call get_type_unit_group, which will create the
7942 struct type_unit_group if necessary and add it to
7943 dwarf2_per_objfile->type_unit_groups. */
7946 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7948 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7949 abbrev_table_up abbrev_table
;
7950 sect_offset abbrev_offset
;
7952 /* It's up to the caller to not call us multiple times. */
7953 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
7955 if (dwarf2_per_objfile
->all_type_units
.empty ())
7958 /* TUs typically share abbrev tables, and there can be way more TUs than
7959 abbrev tables. Sort by abbrev table to reduce the number of times we
7960 read each abbrev table in.
7961 Alternatives are to punt or to maintain a cache of abbrev tables.
7962 This is simpler and efficient enough for now.
7964 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7965 symtab to use). Typically TUs with the same abbrev offset have the same
7966 stmt_list value too so in practice this should work well.
7968 The basic algorithm here is:
7970 sort TUs by abbrev table
7971 for each TU with same abbrev table:
7972 read abbrev table if first user
7973 read TU top level DIE
7974 [IWBN if DWO skeletons had DW_AT_stmt_list]
7977 if (dwarf_read_debug
)
7978 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
7980 /* Sort in a separate table to maintain the order of all_type_units
7981 for .gdb_index: TU indices directly index all_type_units. */
7982 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7983 sorted_by_abbrev
.reserve (dwarf2_per_objfile
->all_type_units
.size ());
7985 for (signatured_type
*sig_type
: dwarf2_per_objfile
->all_type_units
)
7986 sorted_by_abbrev
.emplace_back
7987 (sig_type
, read_abbrev_offset (dwarf2_per_objfile
,
7988 sig_type
->per_cu
.section
,
7989 sig_type
->per_cu
.sect_off
));
7991 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
7992 sort_tu_by_abbrev_offset
);
7994 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7996 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7998 /* Switch to the next abbrev table if necessary. */
7999 if (abbrev_table
== NULL
8000 || tu
.abbrev_offset
!= abbrev_offset
)
8002 abbrev_offset
= tu
.abbrev_offset
;
8004 abbrev_table_read_table (dwarf2_per_objfile
->objfile
,
8005 &dwarf2_per_objfile
->abbrev
,
8007 ++tu_stats
->nr_uniq_abbrev_tables
;
8010 cutu_reader
reader (&tu
.sig_type
->per_cu
, abbrev_table
.get (),
8012 if (!reader
.dummy_p
)
8013 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
8014 reader
.comp_unit_die
,
8015 reader
.has_children
);
8019 /* Print collected type unit statistics. */
8022 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8024 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8026 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
8027 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
8028 dwarf2_per_objfile
->all_type_units
.size ());
8029 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
8030 tu_stats
->nr_uniq_abbrev_tables
);
8031 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
8032 tu_stats
->nr_symtabs
);
8033 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
8034 tu_stats
->nr_symtab_sharers
);
8035 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
8036 tu_stats
->nr_stmt_less_type_units
);
8037 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
8038 tu_stats
->nr_all_type_units_reallocs
);
8041 /* Traversal function for build_type_psymtabs. */
8044 build_type_psymtab_dependencies (void **slot
, void *info
)
8046 struct dwarf2_per_objfile
*dwarf2_per_objfile
8047 = (struct dwarf2_per_objfile
*) info
;
8048 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8049 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
8050 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
8051 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
8052 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
8055 gdb_assert (len
> 0);
8056 gdb_assert (IS_TYPE_UNIT_GROUP (per_cu
));
8058 pst
->number_of_dependencies
= len
;
8059 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
8060 for (i
= 0; i
< len
; ++i
)
8062 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
8063 gdb_assert (iter
->per_cu
.is_debug_types
);
8064 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
8065 iter
->type_unit_group
= tu_group
;
8068 delete tu_group
->tus
;
8069 tu_group
->tus
= nullptr;
8074 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8075 Build partial symbol tables for the .debug_types comp-units. */
8078 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8080 if (! create_all_type_units (dwarf2_per_objfile
))
8083 build_type_psymtabs_1 (dwarf2_per_objfile
);
8086 /* Traversal function for process_skeletonless_type_unit.
8087 Read a TU in a DWO file and build partial symbols for it. */
8090 process_skeletonless_type_unit (void **slot
, void *info
)
8092 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
8093 struct dwarf2_per_objfile
*dwarf2_per_objfile
8094 = (struct dwarf2_per_objfile
*) info
;
8095 struct signatured_type find_entry
, *entry
;
8097 /* If this TU doesn't exist in the global table, add it and read it in. */
8099 if (dwarf2_per_objfile
->signatured_types
== NULL
)
8101 dwarf2_per_objfile
->signatured_types
8102 = allocate_signatured_type_table (dwarf2_per_objfile
->objfile
);
8105 find_entry
.signature
= dwo_unit
->signature
;
8106 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
, &find_entry
,
8108 /* If we've already seen this type there's nothing to do. What's happening
8109 is we're doing our own version of comdat-folding here. */
8113 /* This does the job that create_all_type_units would have done for
8115 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
8116 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
8119 /* This does the job that build_type_psymtabs_1 would have done. */
8120 cutu_reader
reader (&entry
->per_cu
, NULL
, 0, 0, false);
8121 if (!reader
.dummy_p
)
8122 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
8123 reader
.comp_unit_die
, reader
.has_children
);
8128 /* Traversal function for process_skeletonless_type_units. */
8131 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
8133 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
8135 if (dwo_file
->tus
!= NULL
)
8137 htab_traverse_noresize (dwo_file
->tus
,
8138 process_skeletonless_type_unit
, info
);
8144 /* Scan all TUs of DWO files, verifying we've processed them.
8145 This is needed in case a TU was emitted without its skeleton.
8146 Note: This can't be done until we know what all the DWO files are. */
8149 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8151 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
8152 if (get_dwp_file (dwarf2_per_objfile
) == NULL
8153 && dwarf2_per_objfile
->dwo_files
!= NULL
)
8155 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
.get (),
8156 process_dwo_file_for_skeletonless_type_units
,
8157 dwarf2_per_objfile
);
8161 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
8164 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8166 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
8168 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
8173 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
8175 /* Set the 'user' field only if it is not already set. */
8176 if (pst
->dependencies
[j
]->user
== NULL
)
8177 pst
->dependencies
[j
]->user
= pst
;
8182 /* Build the partial symbol table by doing a quick pass through the
8183 .debug_info and .debug_abbrev sections. */
8186 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8188 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8190 if (dwarf_read_debug
)
8192 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
8193 objfile_name (objfile
));
8196 dwarf2_per_objfile
->reading_partial_symbols
= 1;
8198 dwarf2_per_objfile
->info
.read (objfile
);
8200 /* Any cached compilation units will be linked by the per-objfile
8201 read_in_chain. Make sure to free them when we're done. */
8202 free_cached_comp_units
freer (dwarf2_per_objfile
);
8204 build_type_psymtabs (dwarf2_per_objfile
);
8206 create_all_comp_units (dwarf2_per_objfile
);
8208 /* Create a temporary address map on a temporary obstack. We later
8209 copy this to the final obstack. */
8210 auto_obstack temp_obstack
;
8212 scoped_restore save_psymtabs_addrmap
8213 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
8214 addrmap_create_mutable (&temp_obstack
));
8216 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
8217 process_psymtab_comp_unit (per_cu
, 0, language_minimal
);
8219 /* This has to wait until we read the CUs, we need the list of DWOs. */
8220 process_skeletonless_type_units (dwarf2_per_objfile
);
8222 /* Now that all TUs have been processed we can fill in the dependencies. */
8223 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
8225 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
8226 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
8229 if (dwarf_read_debug
)
8230 print_tu_stats (dwarf2_per_objfile
);
8232 set_partial_user (dwarf2_per_objfile
);
8234 objfile
->partial_symtabs
->psymtabs_addrmap
8235 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
8236 objfile
->partial_symtabs
->obstack ());
8237 /* At this point we want to keep the address map. */
8238 save_psymtabs_addrmap
.release ();
8240 if (dwarf_read_debug
)
8241 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
8242 objfile_name (objfile
));
8245 /* Load the partial DIEs for a secondary CU into memory.
8246 This is also used when rereading a primary CU with load_all_dies. */
8249 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
8251 cutu_reader
reader (this_cu
, NULL
, 1, 1, false);
8253 if (!reader
.dummy_p
)
8255 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
8258 /* Check if comp unit has_children.
8259 If so, read the rest of the partial symbols from this comp unit.
8260 If not, there's no more debug_info for this comp unit. */
8261 if (reader
.has_children
)
8262 load_partial_dies (&reader
, reader
.info_ptr
, 0);
8267 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
8268 struct dwarf2_section_info
*section
,
8269 struct dwarf2_section_info
*abbrev_section
,
8270 unsigned int is_dwz
)
8272 const gdb_byte
*info_ptr
;
8273 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8275 if (dwarf_read_debug
)
8276 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
8277 section
->get_name (),
8278 section
->get_file_name ());
8280 section
->read (objfile
);
8282 info_ptr
= section
->buffer
;
8284 while (info_ptr
< section
->buffer
+ section
->size
)
8286 struct dwarf2_per_cu_data
*this_cu
;
8288 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
8290 comp_unit_head cu_header
;
8291 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
8292 abbrev_section
, info_ptr
,
8293 rcuh_kind::COMPILE
);
8295 /* Save the compilation unit for later lookup. */
8296 if (cu_header
.unit_type
!= DW_UT_type
)
8298 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
8299 struct dwarf2_per_cu_data
);
8300 memset (this_cu
, 0, sizeof (*this_cu
));
8304 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
8305 struct signatured_type
);
8306 memset (sig_type
, 0, sizeof (*sig_type
));
8307 sig_type
->signature
= cu_header
.signature
;
8308 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
8309 this_cu
= &sig_type
->per_cu
;
8311 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
8312 this_cu
->sect_off
= sect_off
;
8313 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
8314 this_cu
->is_dwz
= is_dwz
;
8315 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
8316 this_cu
->section
= section
;
8318 dwarf2_per_objfile
->all_comp_units
.push_back (this_cu
);
8320 info_ptr
= info_ptr
+ this_cu
->length
;
8324 /* Create a list of all compilation units in OBJFILE.
8325 This is only done for -readnow and building partial symtabs. */
8328 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8330 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
8331 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->info
,
8332 &dwarf2_per_objfile
->abbrev
, 0);
8334 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
8336 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
8340 /* Process all loaded DIEs for compilation unit CU, starting at
8341 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
8342 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
8343 DW_AT_ranges). See the comments of add_partial_subprogram on how
8344 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
8347 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
8348 CORE_ADDR
*highpc
, int set_addrmap
,
8349 struct dwarf2_cu
*cu
)
8351 struct partial_die_info
*pdi
;
8353 /* Now, march along the PDI's, descending into ones which have
8354 interesting children but skipping the children of the other ones,
8355 until we reach the end of the compilation unit. */
8363 /* Anonymous namespaces or modules have no name but have interesting
8364 children, so we need to look at them. Ditto for anonymous
8367 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
8368 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
8369 || pdi
->tag
== DW_TAG_imported_unit
8370 || pdi
->tag
== DW_TAG_inlined_subroutine
)
8374 case DW_TAG_subprogram
:
8375 case DW_TAG_inlined_subroutine
:
8376 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8378 case DW_TAG_constant
:
8379 case DW_TAG_variable
:
8380 case DW_TAG_typedef
:
8381 case DW_TAG_union_type
:
8382 if (!pdi
->is_declaration
)
8384 add_partial_symbol (pdi
, cu
);
8387 case DW_TAG_class_type
:
8388 case DW_TAG_interface_type
:
8389 case DW_TAG_structure_type
:
8390 if (!pdi
->is_declaration
)
8392 add_partial_symbol (pdi
, cu
);
8394 if ((cu
->language
== language_rust
8395 || cu
->language
== language_cplus
) && pdi
->has_children
)
8396 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8399 case DW_TAG_enumeration_type
:
8400 if (!pdi
->is_declaration
)
8401 add_partial_enumeration (pdi
, cu
);
8403 case DW_TAG_base_type
:
8404 case DW_TAG_subrange_type
:
8405 /* File scope base type definitions are added to the partial
8407 add_partial_symbol (pdi
, cu
);
8409 case DW_TAG_namespace
:
8410 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8413 if (!pdi
->is_declaration
)
8414 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8416 case DW_TAG_imported_unit
:
8418 struct dwarf2_per_cu_data
*per_cu
;
8420 /* For now we don't handle imported units in type units. */
8421 if (cu
->per_cu
->is_debug_types
)
8423 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8424 " supported in type units [in module %s]"),
8425 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
8428 per_cu
= dwarf2_find_containing_comp_unit
8429 (pdi
->d
.sect_off
, pdi
->is_dwz
,
8430 cu
->per_cu
->dwarf2_per_objfile
);
8432 /* Go read the partial unit, if needed. */
8433 if (per_cu
->v
.psymtab
== NULL
)
8434 process_psymtab_comp_unit (per_cu
, 1, cu
->language
);
8436 cu
->per_cu
->imported_symtabs_push (per_cu
);
8439 case DW_TAG_imported_declaration
:
8440 add_partial_symbol (pdi
, cu
);
8447 /* If the die has a sibling, skip to the sibling. */
8449 pdi
= pdi
->die_sibling
;
8453 /* Functions used to compute the fully scoped name of a partial DIE.
8455 Normally, this is simple. For C++, the parent DIE's fully scoped
8456 name is concatenated with "::" and the partial DIE's name.
8457 Enumerators are an exception; they use the scope of their parent
8458 enumeration type, i.e. the name of the enumeration type is not
8459 prepended to the enumerator.
8461 There are two complexities. One is DW_AT_specification; in this
8462 case "parent" means the parent of the target of the specification,
8463 instead of the direct parent of the DIE. The other is compilers
8464 which do not emit DW_TAG_namespace; in this case we try to guess
8465 the fully qualified name of structure types from their members'
8466 linkage names. This must be done using the DIE's children rather
8467 than the children of any DW_AT_specification target. We only need
8468 to do this for structures at the top level, i.e. if the target of
8469 any DW_AT_specification (if any; otherwise the DIE itself) does not
8472 /* Compute the scope prefix associated with PDI's parent, in
8473 compilation unit CU. The result will be allocated on CU's
8474 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8475 field. NULL is returned if no prefix is necessary. */
8477 partial_die_parent_scope (struct partial_die_info
*pdi
,
8478 struct dwarf2_cu
*cu
)
8480 const char *grandparent_scope
;
8481 struct partial_die_info
*parent
, *real_pdi
;
8483 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8484 then this means the parent of the specification DIE. */
8487 while (real_pdi
->has_specification
)
8489 auto res
= find_partial_die (real_pdi
->spec_offset
,
8490 real_pdi
->spec_is_dwz
, cu
);
8495 parent
= real_pdi
->die_parent
;
8499 if (parent
->scope_set
)
8500 return parent
->scope
;
8504 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8506 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8507 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8508 Work around this problem here. */
8509 if (cu
->language
== language_cplus
8510 && parent
->tag
== DW_TAG_namespace
8511 && strcmp (parent
->name
, "::") == 0
8512 && grandparent_scope
== NULL
)
8514 parent
->scope
= NULL
;
8515 parent
->scope_set
= 1;
8519 /* Nested subroutines in Fortran get a prefix. */
8520 if (pdi
->tag
== DW_TAG_enumerator
)
8521 /* Enumerators should not get the name of the enumeration as a prefix. */
8522 parent
->scope
= grandparent_scope
;
8523 else if (parent
->tag
== DW_TAG_namespace
8524 || parent
->tag
== DW_TAG_module
8525 || parent
->tag
== DW_TAG_structure_type
8526 || parent
->tag
== DW_TAG_class_type
8527 || parent
->tag
== DW_TAG_interface_type
8528 || parent
->tag
== DW_TAG_union_type
8529 || parent
->tag
== DW_TAG_enumeration_type
8530 || (cu
->language
== language_fortran
8531 && parent
->tag
== DW_TAG_subprogram
8532 && pdi
->tag
== DW_TAG_subprogram
))
8534 if (grandparent_scope
== NULL
)
8535 parent
->scope
= parent
->name
;
8537 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8539 parent
->name
, 0, cu
);
8543 /* FIXME drow/2004-04-01: What should we be doing with
8544 function-local names? For partial symbols, we should probably be
8546 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8547 dwarf_tag_name (parent
->tag
),
8548 sect_offset_str (pdi
->sect_off
));
8549 parent
->scope
= grandparent_scope
;
8552 parent
->scope_set
= 1;
8553 return parent
->scope
;
8556 /* Return the fully scoped name associated with PDI, from compilation unit
8557 CU. The result will be allocated with malloc. */
8559 static gdb::unique_xmalloc_ptr
<char>
8560 partial_die_full_name (struct partial_die_info
*pdi
,
8561 struct dwarf2_cu
*cu
)
8563 const char *parent_scope
;
8565 /* If this is a template instantiation, we can not work out the
8566 template arguments from partial DIEs. So, unfortunately, we have
8567 to go through the full DIEs. At least any work we do building
8568 types here will be reused if full symbols are loaded later. */
8569 if (pdi
->has_template_arguments
)
8573 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
8575 struct die_info
*die
;
8576 struct attribute attr
;
8577 struct dwarf2_cu
*ref_cu
= cu
;
8579 /* DW_FORM_ref_addr is using section offset. */
8580 attr
.name
= (enum dwarf_attribute
) 0;
8581 attr
.form
= DW_FORM_ref_addr
;
8582 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8583 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8585 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8589 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8590 if (parent_scope
== NULL
)
8593 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8598 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8600 struct dwarf2_per_objfile
*dwarf2_per_objfile
8601 = cu
->per_cu
->dwarf2_per_objfile
;
8602 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8603 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8605 const char *actual_name
= NULL
;
8608 baseaddr
= objfile
->text_section_offset ();
8610 gdb::unique_xmalloc_ptr
<char> built_actual_name
8611 = partial_die_full_name (pdi
, cu
);
8612 if (built_actual_name
!= NULL
)
8613 actual_name
= built_actual_name
.get ();
8615 if (actual_name
== NULL
)
8616 actual_name
= pdi
->name
;
8620 case DW_TAG_inlined_subroutine
:
8621 case DW_TAG_subprogram
:
8622 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8624 if (pdi
->is_external
8625 || cu
->language
== language_ada
8626 || (cu
->language
== language_fortran
8627 && pdi
->die_parent
!= NULL
8628 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8630 /* Normally, only "external" DIEs are part of the global scope.
8631 But in Ada and Fortran, we want to be able to access nested
8632 procedures globally. So all Ada and Fortran subprograms are
8633 stored in the global scope. */
8634 add_psymbol_to_list (actual_name
,
8635 built_actual_name
!= NULL
,
8636 VAR_DOMAIN
, LOC_BLOCK
,
8637 SECT_OFF_TEXT (objfile
),
8638 psymbol_placement::GLOBAL
,
8640 cu
->language
, objfile
);
8644 add_psymbol_to_list (actual_name
,
8645 built_actual_name
!= NULL
,
8646 VAR_DOMAIN
, LOC_BLOCK
,
8647 SECT_OFF_TEXT (objfile
),
8648 psymbol_placement::STATIC
,
8649 addr
, cu
->language
, objfile
);
8652 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8653 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8655 case DW_TAG_constant
:
8656 add_psymbol_to_list (actual_name
,
8657 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
8658 -1, (pdi
->is_external
8659 ? psymbol_placement::GLOBAL
8660 : psymbol_placement::STATIC
),
8661 0, cu
->language
, objfile
);
8663 case DW_TAG_variable
:
8665 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8669 && !dwarf2_per_objfile
->has_section_at_zero
)
8671 /* A global or static variable may also have been stripped
8672 out by the linker if unused, in which case its address
8673 will be nullified; do not add such variables into partial
8674 symbol table then. */
8676 else if (pdi
->is_external
)
8679 Don't enter into the minimal symbol tables as there is
8680 a minimal symbol table entry from the ELF symbols already.
8681 Enter into partial symbol table if it has a location
8682 descriptor or a type.
8683 If the location descriptor is missing, new_symbol will create
8684 a LOC_UNRESOLVED symbol, the address of the variable will then
8685 be determined from the minimal symbol table whenever the variable
8687 The address for the partial symbol table entry is not
8688 used by GDB, but it comes in handy for debugging partial symbol
8691 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8692 add_psymbol_to_list (actual_name
,
8693 built_actual_name
!= NULL
,
8694 VAR_DOMAIN
, LOC_STATIC
,
8695 SECT_OFF_TEXT (objfile
),
8696 psymbol_placement::GLOBAL
,
8697 addr
, cu
->language
, objfile
);
8701 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8703 /* Static Variable. Skip symbols whose value we cannot know (those
8704 without location descriptors or constant values). */
8705 if (!has_loc
&& !pdi
->has_const_value
)
8708 add_psymbol_to_list (actual_name
,
8709 built_actual_name
!= NULL
,
8710 VAR_DOMAIN
, LOC_STATIC
,
8711 SECT_OFF_TEXT (objfile
),
8712 psymbol_placement::STATIC
,
8714 cu
->language
, objfile
);
8717 case DW_TAG_typedef
:
8718 case DW_TAG_base_type
:
8719 case DW_TAG_subrange_type
:
8720 add_psymbol_to_list (actual_name
,
8721 built_actual_name
!= NULL
,
8722 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
8723 psymbol_placement::STATIC
,
8724 0, cu
->language
, objfile
);
8726 case DW_TAG_imported_declaration
:
8727 case DW_TAG_namespace
:
8728 add_psymbol_to_list (actual_name
,
8729 built_actual_name
!= NULL
,
8730 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
8731 psymbol_placement::GLOBAL
,
8732 0, cu
->language
, objfile
);
8735 /* With Fortran 77 there might be a "BLOCK DATA" module
8736 available without any name. If so, we skip the module as it
8737 doesn't bring any value. */
8738 if (actual_name
!= nullptr)
8739 add_psymbol_to_list (actual_name
,
8740 built_actual_name
!= NULL
,
8741 MODULE_DOMAIN
, LOC_TYPEDEF
, -1,
8742 psymbol_placement::GLOBAL
,
8743 0, cu
->language
, objfile
);
8745 case DW_TAG_class_type
:
8746 case DW_TAG_interface_type
:
8747 case DW_TAG_structure_type
:
8748 case DW_TAG_union_type
:
8749 case DW_TAG_enumeration_type
:
8750 /* Skip external references. The DWARF standard says in the section
8751 about "Structure, Union, and Class Type Entries": "An incomplete
8752 structure, union or class type is represented by a structure,
8753 union or class entry that does not have a byte size attribute
8754 and that has a DW_AT_declaration attribute." */
8755 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8758 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8759 static vs. global. */
8760 add_psymbol_to_list (actual_name
,
8761 built_actual_name
!= NULL
,
8762 STRUCT_DOMAIN
, LOC_TYPEDEF
, -1,
8763 cu
->language
== language_cplus
8764 ? psymbol_placement::GLOBAL
8765 : psymbol_placement::STATIC
,
8766 0, cu
->language
, objfile
);
8769 case DW_TAG_enumerator
:
8770 add_psymbol_to_list (actual_name
,
8771 built_actual_name
!= NULL
,
8772 VAR_DOMAIN
, LOC_CONST
, -1,
8773 cu
->language
== language_cplus
8774 ? psymbol_placement::GLOBAL
8775 : psymbol_placement::STATIC
,
8776 0, cu
->language
, objfile
);
8783 /* Read a partial die corresponding to a namespace; also, add a symbol
8784 corresponding to that namespace to the symbol table. NAMESPACE is
8785 the name of the enclosing namespace. */
8788 add_partial_namespace (struct partial_die_info
*pdi
,
8789 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8790 int set_addrmap
, struct dwarf2_cu
*cu
)
8792 /* Add a symbol for the namespace. */
8794 add_partial_symbol (pdi
, cu
);
8796 /* Now scan partial symbols in that namespace. */
8798 if (pdi
->has_children
)
8799 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8802 /* Read a partial die corresponding to a Fortran module. */
8805 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8806 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8808 /* Add a symbol for the namespace. */
8810 add_partial_symbol (pdi
, cu
);
8812 /* Now scan partial symbols in that module. */
8814 if (pdi
->has_children
)
8815 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8818 /* Read a partial die corresponding to a subprogram or an inlined
8819 subprogram and create a partial symbol for that subprogram.
8820 When the CU language allows it, this routine also defines a partial
8821 symbol for each nested subprogram that this subprogram contains.
8822 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8823 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8825 PDI may also be a lexical block, in which case we simply search
8826 recursively for subprograms defined inside that lexical block.
8827 Again, this is only performed when the CU language allows this
8828 type of definitions. */
8831 add_partial_subprogram (struct partial_die_info
*pdi
,
8832 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8833 int set_addrmap
, struct dwarf2_cu
*cu
)
8835 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8837 if (pdi
->has_pc_info
)
8839 if (pdi
->lowpc
< *lowpc
)
8840 *lowpc
= pdi
->lowpc
;
8841 if (pdi
->highpc
> *highpc
)
8842 *highpc
= pdi
->highpc
;
8845 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
8846 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8848 CORE_ADDR this_highpc
;
8849 CORE_ADDR this_lowpc
;
8851 baseaddr
= objfile
->text_section_offset ();
8853 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8854 pdi
->lowpc
+ baseaddr
)
8857 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8858 pdi
->highpc
+ baseaddr
)
8860 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8861 this_lowpc
, this_highpc
- 1,
8862 cu
->per_cu
->v
.psymtab
);
8866 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8868 if (!pdi
->is_declaration
)
8869 /* Ignore subprogram DIEs that do not have a name, they are
8870 illegal. Do not emit a complaint at this point, we will
8871 do so when we convert this psymtab into a symtab. */
8873 add_partial_symbol (pdi
, cu
);
8877 if (! pdi
->has_children
)
8880 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
8882 pdi
= pdi
->die_child
;
8886 if (pdi
->tag
== DW_TAG_subprogram
8887 || pdi
->tag
== DW_TAG_inlined_subroutine
8888 || pdi
->tag
== DW_TAG_lexical_block
)
8889 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8890 pdi
= pdi
->die_sibling
;
8895 /* Read a partial die corresponding to an enumeration type. */
8898 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8899 struct dwarf2_cu
*cu
)
8901 struct partial_die_info
*pdi
;
8903 if (enum_pdi
->name
!= NULL
)
8904 add_partial_symbol (enum_pdi
, cu
);
8906 pdi
= enum_pdi
->die_child
;
8909 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
8910 complaint (_("malformed enumerator DIE ignored"));
8912 add_partial_symbol (pdi
, cu
);
8913 pdi
= pdi
->die_sibling
;
8917 /* Return the initial uleb128 in the die at INFO_PTR. */
8920 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8922 unsigned int bytes_read
;
8924 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8927 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8928 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8930 Return the corresponding abbrev, or NULL if the number is zero (indicating
8931 an empty DIE). In either case *BYTES_READ will be set to the length of
8932 the initial number. */
8934 static struct abbrev_info
*
8935 peek_die_abbrev (const die_reader_specs
&reader
,
8936 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8938 dwarf2_cu
*cu
= reader
.cu
;
8939 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
8940 unsigned int abbrev_number
8941 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8943 if (abbrev_number
== 0)
8946 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8949 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8950 " at offset %s [in module %s]"),
8951 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8952 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8958 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8959 Returns a pointer to the end of a series of DIEs, terminated by an empty
8960 DIE. Any children of the skipped DIEs will also be skipped. */
8962 static const gdb_byte
*
8963 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8967 unsigned int bytes_read
;
8968 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
8971 return info_ptr
+ bytes_read
;
8973 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8977 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8978 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8979 abbrev corresponding to that skipped uleb128 should be passed in
8980 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8983 static const gdb_byte
*
8984 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8985 struct abbrev_info
*abbrev
)
8987 unsigned int bytes_read
;
8988 struct attribute attr
;
8989 bfd
*abfd
= reader
->abfd
;
8990 struct dwarf2_cu
*cu
= reader
->cu
;
8991 const gdb_byte
*buffer
= reader
->buffer
;
8992 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8993 unsigned int form
, i
;
8995 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8997 /* The only abbrev we care about is DW_AT_sibling. */
8998 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
9001 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
,
9003 if (attr
.form
== DW_FORM_ref_addr
)
9004 complaint (_("ignoring absolute DW_AT_sibling"));
9007 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
9008 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
9010 if (sibling_ptr
< info_ptr
)
9011 complaint (_("DW_AT_sibling points backwards"));
9012 else if (sibling_ptr
> reader
->buffer_end
)
9013 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
9019 /* If it isn't DW_AT_sibling, skip this attribute. */
9020 form
= abbrev
->attrs
[i
].form
;
9024 case DW_FORM_ref_addr
:
9025 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
9026 and later it is offset sized. */
9027 if (cu
->header
.version
== 2)
9028 info_ptr
+= cu
->header
.addr_size
;
9030 info_ptr
+= cu
->header
.offset_size
;
9032 case DW_FORM_GNU_ref_alt
:
9033 info_ptr
+= cu
->header
.offset_size
;
9036 info_ptr
+= cu
->header
.addr_size
;
9044 case DW_FORM_flag_present
:
9045 case DW_FORM_implicit_const
:
9062 case DW_FORM_ref_sig8
:
9065 case DW_FORM_data16
:
9068 case DW_FORM_string
:
9069 read_direct_string (abfd
, info_ptr
, &bytes_read
);
9070 info_ptr
+= bytes_read
;
9072 case DW_FORM_sec_offset
:
9074 case DW_FORM_GNU_strp_alt
:
9075 info_ptr
+= cu
->header
.offset_size
;
9077 case DW_FORM_exprloc
:
9079 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9080 info_ptr
+= bytes_read
;
9082 case DW_FORM_block1
:
9083 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
9085 case DW_FORM_block2
:
9086 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
9088 case DW_FORM_block4
:
9089 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
9095 case DW_FORM_ref_udata
:
9096 case DW_FORM_GNU_addr_index
:
9097 case DW_FORM_GNU_str_index
:
9098 case DW_FORM_rnglistx
:
9099 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
9101 case DW_FORM_indirect
:
9102 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9103 info_ptr
+= bytes_read
;
9104 /* We need to continue parsing from here, so just go back to
9106 goto skip_attribute
;
9109 error (_("Dwarf Error: Cannot handle %s "
9110 "in DWARF reader [in module %s]"),
9111 dwarf_form_name (form
),
9112 bfd_get_filename (abfd
));
9116 if (abbrev
->has_children
)
9117 return skip_children (reader
, info_ptr
);
9122 /* Locate ORIG_PDI's sibling.
9123 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
9125 static const gdb_byte
*
9126 locate_pdi_sibling (const struct die_reader_specs
*reader
,
9127 struct partial_die_info
*orig_pdi
,
9128 const gdb_byte
*info_ptr
)
9130 /* Do we know the sibling already? */
9132 if (orig_pdi
->sibling
)
9133 return orig_pdi
->sibling
;
9135 /* Are there any children to deal with? */
9137 if (!orig_pdi
->has_children
)
9140 /* Skip the children the long way. */
9142 return skip_children (reader
, info_ptr
);
9145 /* Expand this partial symbol table into a full symbol table. SELF is
9149 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
9151 struct dwarf2_per_objfile
*dwarf2_per_objfile
9152 = get_dwarf2_per_objfile (objfile
);
9154 gdb_assert (!readin
);
9155 /* If this psymtab is constructed from a debug-only objfile, the
9156 has_section_at_zero flag will not necessarily be correct. We
9157 can get the correct value for this flag by looking at the data
9158 associated with the (presumably stripped) associated objfile. */
9159 if (objfile
->separate_debug_objfile_backlink
)
9161 struct dwarf2_per_objfile
*dpo_backlink
9162 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
9164 dwarf2_per_objfile
->has_section_at_zero
9165 = dpo_backlink
->has_section_at_zero
;
9168 dwarf2_per_objfile
->reading_partial_symbols
= 0;
9170 expand_psymtab (objfile
);
9172 process_cu_includes (dwarf2_per_objfile
);
9175 /* Reading in full CUs. */
9177 /* Add PER_CU to the queue. */
9180 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9181 enum language pretend_language
)
9183 struct dwarf2_queue_item
*item
;
9186 item
= XNEW (struct dwarf2_queue_item
);
9187 item
->per_cu
= per_cu
;
9188 item
->pretend_language
= pretend_language
;
9191 if (dwarf2_queue
== NULL
)
9192 dwarf2_queue
= item
;
9194 dwarf2_queue_tail
->next
= item
;
9196 dwarf2_queue_tail
= item
;
9199 /* If PER_CU is not yet queued, add it to the queue.
9200 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
9202 The result is non-zero if PER_CU was queued, otherwise the result is zero
9203 meaning either PER_CU is already queued or it is already loaded.
9205 N.B. There is an invariant here that if a CU is queued then it is loaded.
9206 The caller is required to load PER_CU if we return non-zero. */
9209 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
9210 struct dwarf2_per_cu_data
*per_cu
,
9211 enum language pretend_language
)
9213 /* We may arrive here during partial symbol reading, if we need full
9214 DIEs to process an unusual case (e.g. template arguments). Do
9215 not queue PER_CU, just tell our caller to load its DIEs. */
9216 if (per_cu
->dwarf2_per_objfile
->reading_partial_symbols
)
9218 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
9223 /* Mark the dependence relation so that we don't flush PER_CU
9225 if (dependent_cu
!= NULL
)
9226 dwarf2_add_dependence (dependent_cu
, per_cu
);
9228 /* If it's already on the queue, we have nothing to do. */
9232 /* If the compilation unit is already loaded, just mark it as
9234 if (per_cu
->cu
!= NULL
)
9236 per_cu
->cu
->last_used
= 0;
9240 /* Add it to the queue. */
9241 queue_comp_unit (per_cu
, pretend_language
);
9246 /* Process the queue. */
9249 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9251 struct dwarf2_queue_item
*item
, *next_item
;
9253 if (dwarf_read_debug
)
9255 fprintf_unfiltered (gdb_stdlog
,
9256 "Expanding one or more symtabs of objfile %s ...\n",
9257 objfile_name (dwarf2_per_objfile
->objfile
));
9260 /* The queue starts out with one item, but following a DIE reference
9261 may load a new CU, adding it to the end of the queue. */
9262 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
9264 if ((dwarf2_per_objfile
->using_index
9265 ? !item
->per_cu
->v
.quick
->compunit_symtab
9266 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
9267 /* Skip dummy CUs. */
9268 && item
->per_cu
->cu
!= NULL
)
9270 struct dwarf2_per_cu_data
*per_cu
= item
->per_cu
;
9271 unsigned int debug_print_threshold
;
9274 if (per_cu
->is_debug_types
)
9276 struct signatured_type
*sig_type
=
9277 (struct signatured_type
*) per_cu
;
9279 sprintf (buf
, "TU %s at offset %s",
9280 hex_string (sig_type
->signature
),
9281 sect_offset_str (per_cu
->sect_off
));
9282 /* There can be 100s of TUs.
9283 Only print them in verbose mode. */
9284 debug_print_threshold
= 2;
9288 sprintf (buf
, "CU at offset %s",
9289 sect_offset_str (per_cu
->sect_off
));
9290 debug_print_threshold
= 1;
9293 if (dwarf_read_debug
>= debug_print_threshold
)
9294 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
9296 if (per_cu
->is_debug_types
)
9297 process_full_type_unit (per_cu
, item
->pretend_language
);
9299 process_full_comp_unit (per_cu
, item
->pretend_language
);
9301 if (dwarf_read_debug
>= debug_print_threshold
)
9302 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
9305 item
->per_cu
->queued
= 0;
9306 next_item
= item
->next
;
9310 dwarf2_queue_tail
= NULL
;
9312 if (dwarf_read_debug
)
9314 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
9315 objfile_name (dwarf2_per_objfile
->objfile
));
9319 /* Read in full symbols for PST, and anything it depends on. */
9322 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
9324 struct dwarf2_per_cu_data
*per_cu
;
9329 read_dependencies (objfile
);
9331 per_cu
= per_cu_data
;
9335 /* It's an include file, no symbols to read for it.
9336 Everything is in the parent symtab. */
9341 dw2_do_instantiate_symtab (per_cu
, false);
9344 /* Trivial hash function for die_info: the hash value of a DIE
9345 is its offset in .debug_info for this objfile. */
9348 die_hash (const void *item
)
9350 const struct die_info
*die
= (const struct die_info
*) item
;
9352 return to_underlying (die
->sect_off
);
9355 /* Trivial comparison function for die_info structures: two DIEs
9356 are equal if they have the same offset. */
9359 die_eq (const void *item_lhs
, const void *item_rhs
)
9361 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
9362 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
9364 return die_lhs
->sect_off
== die_rhs
->sect_off
;
9367 /* Load the DIEs associated with PER_CU into memory. */
9370 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
9372 enum language pretend_language
)
9374 gdb_assert (! this_cu
->is_debug_types
);
9376 cutu_reader
reader (this_cu
, NULL
, 1, 1, skip_partial
);
9380 struct dwarf2_cu
*cu
= reader
.cu
;
9381 const gdb_byte
*info_ptr
= reader
.info_ptr
;
9383 gdb_assert (cu
->die_hash
== NULL
);
9385 htab_create_alloc_ex (cu
->header
.length
/ 12,
9389 &cu
->comp_unit_obstack
,
9390 hashtab_obstack_allocate
,
9391 dummy_obstack_deallocate
);
9393 if (reader
.has_children
)
9394 reader
.comp_unit_die
->child
9395 = read_die_and_siblings (&reader
, reader
.info_ptr
,
9396 &info_ptr
, reader
.comp_unit_die
);
9397 cu
->dies
= reader
.comp_unit_die
;
9398 /* comp_unit_die is not stored in die_hash, no need. */
9400 /* We try not to read any attributes in this function, because not
9401 all CUs needed for references have been loaded yet, and symbol
9402 table processing isn't initialized. But we have to set the CU language,
9403 or we won't be able to build types correctly.
9404 Similarly, if we do not read the producer, we can not apply
9405 producer-specific interpretation. */
9406 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
9409 /* Add a DIE to the delayed physname list. */
9412 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
9413 const char *name
, struct die_info
*die
,
9414 struct dwarf2_cu
*cu
)
9416 struct delayed_method_info mi
;
9418 mi
.fnfield_index
= fnfield_index
;
9422 cu
->method_list
.push_back (mi
);
9425 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
9426 "const" / "volatile". If so, decrements LEN by the length of the
9427 modifier and return true. Otherwise return false. */
9431 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
9433 size_t mod_len
= sizeof (mod
) - 1;
9434 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
9442 /* Compute the physnames of any methods on the CU's method list.
9444 The computation of method physnames is delayed in order to avoid the
9445 (bad) condition that one of the method's formal parameters is of an as yet
9449 compute_delayed_physnames (struct dwarf2_cu
*cu
)
9451 /* Only C++ delays computing physnames. */
9452 if (cu
->method_list
.empty ())
9454 gdb_assert (cu
->language
== language_cplus
);
9456 for (const delayed_method_info
&mi
: cu
->method_list
)
9458 const char *physname
;
9459 struct fn_fieldlist
*fn_flp
9460 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9461 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9462 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9463 = physname
? physname
: "";
9465 /* Since there's no tag to indicate whether a method is a
9466 const/volatile overload, extract that information out of the
9468 if (physname
!= NULL
)
9470 size_t len
= strlen (physname
);
9474 if (physname
[len
] == ')') /* shortcut */
9476 else if (check_modifier (physname
, len
, " const"))
9477 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9478 else if (check_modifier (physname
, len
, " volatile"))
9479 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9486 /* The list is no longer needed. */
9487 cu
->method_list
.clear ();
9490 /* Go objects should be embedded in a DW_TAG_module DIE,
9491 and it's not clear if/how imported objects will appear.
9492 To keep Go support simple until that's worked out,
9493 go back through what we've read and create something usable.
9494 We could do this while processing each DIE, and feels kinda cleaner,
9495 but that way is more invasive.
9496 This is to, for example, allow the user to type "p var" or "b main"
9497 without having to specify the package name, and allow lookups
9498 of module.object to work in contexts that use the expression
9502 fixup_go_packaging (struct dwarf2_cu
*cu
)
9504 gdb::unique_xmalloc_ptr
<char> package_name
;
9505 struct pending
*list
;
9508 for (list
= *cu
->get_builder ()->get_global_symbols ();
9512 for (i
= 0; i
< list
->nsyms
; ++i
)
9514 struct symbol
*sym
= list
->symbol
[i
];
9516 if (sym
->language () == language_go
9517 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9519 gdb::unique_xmalloc_ptr
<char> this_package_name
9520 (go_symbol_package_name (sym
));
9522 if (this_package_name
== NULL
)
9524 if (package_name
== NULL
)
9525 package_name
= std::move (this_package_name
);
9528 struct objfile
*objfile
9529 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9530 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9531 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9532 (symbol_symtab (sym
) != NULL
9533 ? symtab_to_filename_for_display
9534 (symbol_symtab (sym
))
9535 : objfile_name (objfile
)),
9536 this_package_name
.get (), package_name
.get ());
9542 if (package_name
!= NULL
)
9544 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9545 const char *saved_package_name
9546 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
, package_name
.get ());
9547 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9548 saved_package_name
);
9551 sym
= allocate_symbol (objfile
);
9552 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9553 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9554 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9555 e.g., "main" finds the "main" module and not C's main(). */
9556 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9557 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9558 SYMBOL_TYPE (sym
) = type
;
9560 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9564 /* Allocate a fully-qualified name consisting of the two parts on the
9568 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9570 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9573 /* A helper that allocates a struct discriminant_info to attach to a
9576 static struct discriminant_info
*
9577 alloc_discriminant_info (struct type
*type
, int discriminant_index
,
9580 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9581 gdb_assert (discriminant_index
== -1
9582 || (discriminant_index
>= 0
9583 && discriminant_index
< TYPE_NFIELDS (type
)));
9584 gdb_assert (default_index
== -1
9585 || (default_index
>= 0 && default_index
< TYPE_NFIELDS (type
)));
9587 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
9589 struct discriminant_info
*disc
9590 = ((struct discriminant_info
*)
9592 offsetof (struct discriminant_info
, discriminants
)
9593 + TYPE_NFIELDS (type
) * sizeof (disc
->discriminants
[0])));
9594 disc
->default_index
= default_index
;
9595 disc
->discriminant_index
= discriminant_index
;
9597 struct dynamic_prop prop
;
9598 prop
.kind
= PROP_UNDEFINED
;
9599 prop
.data
.baton
= disc
;
9601 add_dyn_prop (DYN_PROP_DISCRIMINATED
, prop
, type
);
9606 /* Some versions of rustc emitted enums in an unusual way.
9608 Ordinary enums were emitted as unions. The first element of each
9609 structure in the union was named "RUST$ENUM$DISR". This element
9610 held the discriminant.
9612 These versions of Rust also implemented the "non-zero"
9613 optimization. When the enum had two values, and one is empty and
9614 the other holds a pointer that cannot be zero, the pointer is used
9615 as the discriminant, with a zero value meaning the empty variant.
9616 Here, the union's first member is of the form
9617 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9618 where the fieldnos are the indices of the fields that should be
9619 traversed in order to find the field (which may be several fields deep)
9620 and the variantname is the name of the variant of the case when the
9623 This function recognizes whether TYPE is of one of these forms,
9624 and, if so, smashes it to be a variant type. */
9627 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9629 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9631 /* We don't need to deal with empty enums. */
9632 if (TYPE_NFIELDS (type
) == 0)
9635 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9636 if (TYPE_NFIELDS (type
) == 1
9637 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9639 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9641 /* Decode the field name to find the offset of the
9643 ULONGEST bit_offset
= 0;
9644 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9645 while (name
[0] >= '0' && name
[0] <= '9')
9648 unsigned long index
= strtoul (name
, &tail
, 10);
9651 || index
>= TYPE_NFIELDS (field_type
)
9652 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9653 != FIELD_LOC_KIND_BITPOS
))
9655 complaint (_("Could not parse Rust enum encoding string \"%s\""
9657 TYPE_FIELD_NAME (type
, 0),
9658 objfile_name (objfile
));
9663 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9664 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
9667 /* Make a union to hold the variants. */
9668 struct type
*union_type
= alloc_type (objfile
);
9669 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9670 TYPE_NFIELDS (union_type
) = 3;
9671 TYPE_FIELDS (union_type
)
9672 = (struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
));
9673 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9674 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9676 /* Put the discriminant must at index 0. */
9677 TYPE_FIELD_TYPE (union_type
, 0) = field_type
;
9678 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
9679 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
9680 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 0), bit_offset
);
9682 /* The order of fields doesn't really matter, so put the real
9683 field at index 1 and the data-less field at index 2. */
9684 struct discriminant_info
*disc
9685 = alloc_discriminant_info (union_type
, 0, 1);
9686 TYPE_FIELD (union_type
, 1) = TYPE_FIELD (type
, 0);
9687 TYPE_FIELD_NAME (union_type
, 1)
9688 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1)));
9689 TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1))
9690 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9691 TYPE_FIELD_NAME (union_type
, 1));
9693 const char *dataless_name
9694 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9696 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9698 TYPE_FIELD_TYPE (union_type
, 2) = dataless_type
;
9699 /* NAME points into the original discriminant name, which
9700 already has the correct lifetime. */
9701 TYPE_FIELD_NAME (union_type
, 2) = name
;
9702 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 2), 0);
9703 disc
->discriminants
[2] = 0;
9705 /* Smash this type to be a structure type. We have to do this
9706 because the type has already been recorded. */
9707 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9708 TYPE_NFIELDS (type
) = 1;
9710 = (struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
));
9712 /* Install the variant part. */
9713 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9714 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9715 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9717 /* A union with a single anonymous field is probably an old-style
9719 else if (TYPE_NFIELDS (type
) == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
9721 /* Smash this type to be a structure type. We have to do this
9722 because the type has already been recorded. */
9723 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9725 /* Make a union to hold the variants. */
9726 struct type
*union_type
= alloc_type (objfile
);
9727 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9728 TYPE_NFIELDS (union_type
) = TYPE_NFIELDS (type
);
9729 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9730 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9731 TYPE_FIELDS (union_type
) = TYPE_FIELDS (type
);
9733 struct type
*field_type
= TYPE_FIELD_TYPE (union_type
, 0);
9734 const char *variant_name
9735 = rust_last_path_segment (TYPE_NAME (field_type
));
9736 TYPE_FIELD_NAME (union_type
, 0) = variant_name
;
9737 TYPE_NAME (field_type
)
9738 = rust_fully_qualify (&objfile
->objfile_obstack
,
9739 TYPE_NAME (type
), variant_name
);
9741 /* Install the union in the outer struct type. */
9742 TYPE_NFIELDS (type
) = 1;
9744 = (struct field
*) TYPE_ZALLOC (union_type
, sizeof (struct field
));
9745 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9746 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9747 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9749 alloc_discriminant_info (union_type
, -1, 0);
9753 struct type
*disr_type
= nullptr;
9754 for (int i
= 0; i
< TYPE_NFIELDS (type
); ++i
)
9756 disr_type
= TYPE_FIELD_TYPE (type
, i
);
9758 if (TYPE_CODE (disr_type
) != TYPE_CODE_STRUCT
)
9760 /* All fields of a true enum will be structs. */
9763 else if (TYPE_NFIELDS (disr_type
) == 0)
9765 /* Could be data-less variant, so keep going. */
9766 disr_type
= nullptr;
9768 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9769 "RUST$ENUM$DISR") != 0)
9771 /* Not a Rust enum. */
9781 /* If we got here without a discriminant, then it's probably
9783 if (disr_type
== nullptr)
9786 /* Smash this type to be a structure type. We have to do this
9787 because the type has already been recorded. */
9788 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9790 /* Make a union to hold the variants. */
9791 struct field
*disr_field
= &TYPE_FIELD (disr_type
, 0);
9792 struct type
*union_type
= alloc_type (objfile
);
9793 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9794 TYPE_NFIELDS (union_type
) = 1 + TYPE_NFIELDS (type
);
9795 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9796 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9797 TYPE_FIELDS (union_type
)
9798 = (struct field
*) TYPE_ZALLOC (union_type
,
9799 (TYPE_NFIELDS (union_type
)
9800 * sizeof (struct field
)));
9802 memcpy (TYPE_FIELDS (union_type
) + 1, TYPE_FIELDS (type
),
9803 TYPE_NFIELDS (type
) * sizeof (struct field
));
9805 /* Install the discriminant at index 0 in the union. */
9806 TYPE_FIELD (union_type
, 0) = *disr_field
;
9807 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
9808 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
9810 /* Install the union in the outer struct type. */
9811 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9812 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9813 TYPE_NFIELDS (type
) = 1;
9815 /* Set the size and offset of the union type. */
9816 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9818 /* We need a way to find the correct discriminant given a
9819 variant name. For convenience we build a map here. */
9820 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
9821 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9822 for (int i
= 0; i
< TYPE_NFIELDS (enum_type
); ++i
)
9824 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9827 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9828 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9832 int n_fields
= TYPE_NFIELDS (union_type
);
9833 struct discriminant_info
*disc
9834 = alloc_discriminant_info (union_type
, 0, -1);
9835 /* Skip the discriminant here. */
9836 for (int i
= 1; i
< n_fields
; ++i
)
9838 /* Find the final word in the name of this variant's type.
9839 That name can be used to look up the correct
9841 const char *variant_name
9842 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
,
9845 auto iter
= discriminant_map
.find (variant_name
);
9846 if (iter
!= discriminant_map
.end ())
9847 disc
->discriminants
[i
] = iter
->second
;
9849 /* Remove the discriminant field, if it exists. */
9850 struct type
*sub_type
= TYPE_FIELD_TYPE (union_type
, i
);
9851 if (TYPE_NFIELDS (sub_type
) > 0)
9853 --TYPE_NFIELDS (sub_type
);
9854 ++TYPE_FIELDS (sub_type
);
9856 TYPE_FIELD_NAME (union_type
, i
) = variant_name
;
9857 TYPE_NAME (sub_type
)
9858 = rust_fully_qualify (&objfile
->objfile_obstack
,
9859 TYPE_NAME (type
), variant_name
);
9864 /* Rewrite some Rust unions to be structures with variants parts. */
9867 rust_union_quirks (struct dwarf2_cu
*cu
)
9869 gdb_assert (cu
->language
== language_rust
);
9870 for (type
*type_
: cu
->rust_unions
)
9871 quirk_rust_enum (type_
, cu
->per_cu
->dwarf2_per_objfile
->objfile
);
9872 /* We don't need this any more. */
9873 cu
->rust_unions
.clear ();
9876 /* Return the symtab for PER_CU. This works properly regardless of
9877 whether we're using the index or psymtabs. */
9879 static struct compunit_symtab
*
9880 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
9882 return (per_cu
->dwarf2_per_objfile
->using_index
9883 ? per_cu
->v
.quick
->compunit_symtab
9884 : per_cu
->v
.psymtab
->compunit_symtab
);
9887 /* A helper function for computing the list of all symbol tables
9888 included by PER_CU. */
9891 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9892 htab_t all_children
, htab_t all_type_symtabs
,
9893 struct dwarf2_per_cu_data
*per_cu
,
9894 struct compunit_symtab
*immediate_parent
)
9897 struct compunit_symtab
*cust
;
9899 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9902 /* This inclusion and its children have been processed. */
9907 /* Only add a CU if it has a symbol table. */
9908 cust
= get_compunit_symtab (per_cu
);
9911 /* If this is a type unit only add its symbol table if we haven't
9912 seen it yet (type unit per_cu's can share symtabs). */
9913 if (per_cu
->is_debug_types
)
9915 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9919 result
->push_back (cust
);
9920 if (cust
->user
== NULL
)
9921 cust
->user
= immediate_parent
;
9926 result
->push_back (cust
);
9927 if (cust
->user
== NULL
)
9928 cust
->user
= immediate_parent
;
9932 if (!per_cu
->imported_symtabs_empty ())
9933 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9935 recursively_compute_inclusions (result
, all_children
,
9936 all_type_symtabs
, ptr
, cust
);
9940 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9944 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
9946 gdb_assert (! per_cu
->is_debug_types
);
9948 if (!per_cu
->imported_symtabs_empty ())
9951 std::vector
<compunit_symtab
*> result_symtabs
;
9952 htab_t all_children
, all_type_symtabs
;
9953 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
9955 /* If we don't have a symtab, we can just skip this case. */
9959 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9960 NULL
, xcalloc
, xfree
);
9961 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9962 NULL
, xcalloc
, xfree
);
9964 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9966 recursively_compute_inclusions (&result_symtabs
, all_children
,
9967 all_type_symtabs
, ptr
, cust
);
9970 /* Now we have a transitive closure of all the included symtabs. */
9971 len
= result_symtabs
.size ();
9973 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
9974 struct compunit_symtab
*, len
+ 1);
9975 memcpy (cust
->includes
, result_symtabs
.data (),
9976 len
* sizeof (compunit_symtab
*));
9977 cust
->includes
[len
] = NULL
;
9979 htab_delete (all_children
);
9980 htab_delete (all_type_symtabs
);
9984 /* Compute the 'includes' field for the symtabs of all the CUs we just
9988 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9990 for (dwarf2_per_cu_data
*iter
: dwarf2_per_objfile
->just_read_cus
)
9992 if (! iter
->is_debug_types
)
9993 compute_compunit_symtab_includes (iter
);
9996 dwarf2_per_objfile
->just_read_cus
.clear ();
9999 /* Generate full symbol information for PER_CU, whose DIEs have
10000 already been loaded into memory. */
10003 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
10004 enum language pretend_language
)
10006 struct dwarf2_cu
*cu
= per_cu
->cu
;
10007 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10008 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10009 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10010 CORE_ADDR lowpc
, highpc
;
10011 struct compunit_symtab
*cust
;
10012 CORE_ADDR baseaddr
;
10013 struct block
*static_block
;
10016 baseaddr
= objfile
->text_section_offset ();
10018 /* Clear the list here in case something was left over. */
10019 cu
->method_list
.clear ();
10021 cu
->language
= pretend_language
;
10022 cu
->language_defn
= language_def (cu
->language
);
10024 /* Do line number decoding in read_file_scope () */
10025 process_die (cu
->dies
, cu
);
10027 /* For now fudge the Go package. */
10028 if (cu
->language
== language_go
)
10029 fixup_go_packaging (cu
);
10031 /* Now that we have processed all the DIEs in the CU, all the types
10032 should be complete, and it should now be safe to compute all of the
10034 compute_delayed_physnames (cu
);
10036 if (cu
->language
== language_rust
)
10037 rust_union_quirks (cu
);
10039 /* Some compilers don't define a DW_AT_high_pc attribute for the
10040 compilation unit. If the DW_AT_high_pc is missing, synthesize
10041 it, by scanning the DIE's below the compilation unit. */
10042 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
10044 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
10045 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
10047 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
10048 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
10049 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
10050 addrmap to help ensure it has an accurate map of pc values belonging to
10052 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
10054 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
10055 SECT_OFF_TEXT (objfile
),
10060 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
10062 /* Set symtab language to language from DW_AT_language. If the
10063 compilation is from a C file generated by language preprocessors, do
10064 not set the language if it was already deduced by start_subfile. */
10065 if (!(cu
->language
== language_c
10066 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
10067 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10069 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
10070 produce DW_AT_location with location lists but it can be possibly
10071 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
10072 there were bugs in prologue debug info, fixed later in GCC-4.5
10073 by "unwind info for epilogues" patch (which is not directly related).
10075 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
10076 needed, it would be wrong due to missing DW_AT_producer there.
10078 Still one can confuse GDB by using non-standard GCC compilation
10079 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
10081 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
10082 cust
->locations_valid
= 1;
10084 if (gcc_4_minor
>= 5)
10085 cust
->epilogue_unwind_valid
= 1;
10087 cust
->call_site_htab
= cu
->call_site_htab
;
10090 if (dwarf2_per_objfile
->using_index
)
10091 per_cu
->v
.quick
->compunit_symtab
= cust
;
10094 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
10095 pst
->compunit_symtab
= cust
;
10096 pst
->readin
= true;
10099 /* Push it for inclusion processing later. */
10100 dwarf2_per_objfile
->just_read_cus
.push_back (per_cu
);
10102 /* Not needed any more. */
10103 cu
->reset_builder ();
10106 /* Generate full symbol information for type unit PER_CU, whose DIEs have
10107 already been loaded into memory. */
10110 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
10111 enum language pretend_language
)
10113 struct dwarf2_cu
*cu
= per_cu
->cu
;
10114 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10115 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10116 struct compunit_symtab
*cust
;
10117 struct signatured_type
*sig_type
;
10119 gdb_assert (per_cu
->is_debug_types
);
10120 sig_type
= (struct signatured_type
*) per_cu
;
10122 /* Clear the list here in case something was left over. */
10123 cu
->method_list
.clear ();
10125 cu
->language
= pretend_language
;
10126 cu
->language_defn
= language_def (cu
->language
);
10128 /* The symbol tables are set up in read_type_unit_scope. */
10129 process_die (cu
->dies
, cu
);
10131 /* For now fudge the Go package. */
10132 if (cu
->language
== language_go
)
10133 fixup_go_packaging (cu
);
10135 /* Now that we have processed all the DIEs in the CU, all the types
10136 should be complete, and it should now be safe to compute all of the
10138 compute_delayed_physnames (cu
);
10140 if (cu
->language
== language_rust
)
10141 rust_union_quirks (cu
);
10143 /* TUs share symbol tables.
10144 If this is the first TU to use this symtab, complete the construction
10145 of it with end_expandable_symtab. Otherwise, complete the addition of
10146 this TU's symbols to the existing symtab. */
10147 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
10149 buildsym_compunit
*builder
= cu
->get_builder ();
10150 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
10151 sig_type
->type_unit_group
->compunit_symtab
= cust
;
10155 /* Set symtab language to language from DW_AT_language. If the
10156 compilation is from a C file generated by language preprocessors,
10157 do not set the language if it was already deduced by
10159 if (!(cu
->language
== language_c
10160 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
10161 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10166 cu
->get_builder ()->augment_type_symtab ();
10167 cust
= sig_type
->type_unit_group
->compunit_symtab
;
10170 if (dwarf2_per_objfile
->using_index
)
10171 per_cu
->v
.quick
->compunit_symtab
= cust
;
10174 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
10175 pst
->compunit_symtab
= cust
;
10176 pst
->readin
= true;
10179 /* Not needed any more. */
10180 cu
->reset_builder ();
10183 /* Process an imported unit DIE. */
10186 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10188 struct attribute
*attr
;
10190 /* For now we don't handle imported units in type units. */
10191 if (cu
->per_cu
->is_debug_types
)
10193 error (_("Dwarf Error: DW_TAG_imported_unit is not"
10194 " supported in type units [in module %s]"),
10195 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
10198 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10201 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
10202 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
10203 dwarf2_per_cu_data
*per_cu
10204 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
10205 cu
->per_cu
->dwarf2_per_objfile
);
10207 /* If necessary, add it to the queue and load its DIEs. */
10208 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
10209 load_full_comp_unit (per_cu
, false, cu
->language
);
10211 cu
->per_cu
->imported_symtabs_push (per_cu
);
10215 /* RAII object that represents a process_die scope: i.e.,
10216 starts/finishes processing a DIE. */
10217 class process_die_scope
10220 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
10221 : m_die (die
), m_cu (cu
)
10223 /* We should only be processing DIEs not already in process. */
10224 gdb_assert (!m_die
->in_process
);
10225 m_die
->in_process
= true;
10228 ~process_die_scope ()
10230 m_die
->in_process
= false;
10232 /* If we're done processing the DIE for the CU that owns the line
10233 header, we don't need the line header anymore. */
10234 if (m_cu
->line_header_die_owner
== m_die
)
10236 delete m_cu
->line_header
;
10237 m_cu
->line_header
= NULL
;
10238 m_cu
->line_header_die_owner
= NULL
;
10247 /* Process a die and its children. */
10250 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10252 process_die_scope
scope (die
, cu
);
10256 case DW_TAG_padding
:
10258 case DW_TAG_compile_unit
:
10259 case DW_TAG_partial_unit
:
10260 read_file_scope (die
, cu
);
10262 case DW_TAG_type_unit
:
10263 read_type_unit_scope (die
, cu
);
10265 case DW_TAG_subprogram
:
10266 /* Nested subprograms in Fortran get a prefix. */
10267 if (cu
->language
== language_fortran
10268 && die
->parent
!= NULL
10269 && die
->parent
->tag
== DW_TAG_subprogram
)
10270 cu
->processing_has_namespace_info
= true;
10271 /* Fall through. */
10272 case DW_TAG_inlined_subroutine
:
10273 read_func_scope (die
, cu
);
10275 case DW_TAG_lexical_block
:
10276 case DW_TAG_try_block
:
10277 case DW_TAG_catch_block
:
10278 read_lexical_block_scope (die
, cu
);
10280 case DW_TAG_call_site
:
10281 case DW_TAG_GNU_call_site
:
10282 read_call_site_scope (die
, cu
);
10284 case DW_TAG_class_type
:
10285 case DW_TAG_interface_type
:
10286 case DW_TAG_structure_type
:
10287 case DW_TAG_union_type
:
10288 process_structure_scope (die
, cu
);
10290 case DW_TAG_enumeration_type
:
10291 process_enumeration_scope (die
, cu
);
10294 /* These dies have a type, but processing them does not create
10295 a symbol or recurse to process the children. Therefore we can
10296 read them on-demand through read_type_die. */
10297 case DW_TAG_subroutine_type
:
10298 case DW_TAG_set_type
:
10299 case DW_TAG_array_type
:
10300 case DW_TAG_pointer_type
:
10301 case DW_TAG_ptr_to_member_type
:
10302 case DW_TAG_reference_type
:
10303 case DW_TAG_rvalue_reference_type
:
10304 case DW_TAG_string_type
:
10307 case DW_TAG_base_type
:
10308 case DW_TAG_subrange_type
:
10309 case DW_TAG_typedef
:
10310 /* Add a typedef symbol for the type definition, if it has a
10312 new_symbol (die
, read_type_die (die
, cu
), cu
);
10314 case DW_TAG_common_block
:
10315 read_common_block (die
, cu
);
10317 case DW_TAG_common_inclusion
:
10319 case DW_TAG_namespace
:
10320 cu
->processing_has_namespace_info
= true;
10321 read_namespace (die
, cu
);
10323 case DW_TAG_module
:
10324 cu
->processing_has_namespace_info
= true;
10325 read_module (die
, cu
);
10327 case DW_TAG_imported_declaration
:
10328 cu
->processing_has_namespace_info
= true;
10329 if (read_namespace_alias (die
, cu
))
10331 /* The declaration is not a global namespace alias. */
10332 /* Fall through. */
10333 case DW_TAG_imported_module
:
10334 cu
->processing_has_namespace_info
= true;
10335 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
10336 || cu
->language
!= language_fortran
))
10337 complaint (_("Tag '%s' has unexpected children"),
10338 dwarf_tag_name (die
->tag
));
10339 read_import_statement (die
, cu
);
10342 case DW_TAG_imported_unit
:
10343 process_imported_unit_die (die
, cu
);
10346 case DW_TAG_variable
:
10347 read_variable (die
, cu
);
10351 new_symbol (die
, NULL
, cu
);
10356 /* DWARF name computation. */
10358 /* A helper function for dwarf2_compute_name which determines whether DIE
10359 needs to have the name of the scope prepended to the name listed in the
10363 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10365 struct attribute
*attr
;
10369 case DW_TAG_namespace
:
10370 case DW_TAG_typedef
:
10371 case DW_TAG_class_type
:
10372 case DW_TAG_interface_type
:
10373 case DW_TAG_structure_type
:
10374 case DW_TAG_union_type
:
10375 case DW_TAG_enumeration_type
:
10376 case DW_TAG_enumerator
:
10377 case DW_TAG_subprogram
:
10378 case DW_TAG_inlined_subroutine
:
10379 case DW_TAG_member
:
10380 case DW_TAG_imported_declaration
:
10383 case DW_TAG_variable
:
10384 case DW_TAG_constant
:
10385 /* We only need to prefix "globally" visible variables. These include
10386 any variable marked with DW_AT_external or any variable that
10387 lives in a namespace. [Variables in anonymous namespaces
10388 require prefixing, but they are not DW_AT_external.] */
10390 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
10392 struct dwarf2_cu
*spec_cu
= cu
;
10394 return die_needs_namespace (die_specification (die
, &spec_cu
),
10398 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10399 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
10400 && die
->parent
->tag
!= DW_TAG_module
)
10402 /* A variable in a lexical block of some kind does not need a
10403 namespace, even though in C++ such variables may be external
10404 and have a mangled name. */
10405 if (die
->parent
->tag
== DW_TAG_lexical_block
10406 || die
->parent
->tag
== DW_TAG_try_block
10407 || die
->parent
->tag
== DW_TAG_catch_block
10408 || die
->parent
->tag
== DW_TAG_subprogram
)
10417 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
10418 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10419 defined for the given DIE. */
10421 static struct attribute
*
10422 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
10424 struct attribute
*attr
;
10426 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
10428 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10433 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10434 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10435 defined for the given DIE. */
10437 static const char *
10438 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10440 const char *linkage_name
;
10442 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10443 if (linkage_name
== NULL
)
10444 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10446 return linkage_name
;
10449 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10450 compute the physname for the object, which include a method's:
10451 - formal parameters (C++),
10452 - receiver type (Go),
10454 The term "physname" is a bit confusing.
10455 For C++, for example, it is the demangled name.
10456 For Go, for example, it's the mangled name.
10458 For Ada, return the DIE's linkage name rather than the fully qualified
10459 name. PHYSNAME is ignored..
10461 The result is allocated on the objfile_obstack and canonicalized. */
10463 static const char *
10464 dwarf2_compute_name (const char *name
,
10465 struct die_info
*die
, struct dwarf2_cu
*cu
,
10468 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10471 name
= dwarf2_name (die
, cu
);
10473 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10474 but otherwise compute it by typename_concat inside GDB.
10475 FIXME: Actually this is not really true, or at least not always true.
10476 It's all very confusing. compute_and_set_names doesn't try to demangle
10477 Fortran names because there is no mangling standard. So new_symbol
10478 will set the demangled name to the result of dwarf2_full_name, and it is
10479 the demangled name that GDB uses if it exists. */
10480 if (cu
->language
== language_ada
10481 || (cu
->language
== language_fortran
&& physname
))
10483 /* For Ada unit, we prefer the linkage name over the name, as
10484 the former contains the exported name, which the user expects
10485 to be able to reference. Ideally, we want the user to be able
10486 to reference this entity using either natural or linkage name,
10487 but we haven't started looking at this enhancement yet. */
10488 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10490 if (linkage_name
!= NULL
)
10491 return linkage_name
;
10494 /* These are the only languages we know how to qualify names in. */
10496 && (cu
->language
== language_cplus
10497 || cu
->language
== language_fortran
|| cu
->language
== language_d
10498 || cu
->language
== language_rust
))
10500 if (die_needs_namespace (die
, cu
))
10502 const char *prefix
;
10503 const char *canonical_name
= NULL
;
10507 prefix
= determine_prefix (die
, cu
);
10508 if (*prefix
!= '\0')
10510 gdb::unique_xmalloc_ptr
<char> prefixed_name
10511 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10513 buf
.puts (prefixed_name
.get ());
10518 /* Template parameters may be specified in the DIE's DW_AT_name, or
10519 as children with DW_TAG_template_type_param or
10520 DW_TAG_value_type_param. If the latter, add them to the name
10521 here. If the name already has template parameters, then
10522 skip this step; some versions of GCC emit both, and
10523 it is more efficient to use the pre-computed name.
10525 Something to keep in mind about this process: it is very
10526 unlikely, or in some cases downright impossible, to produce
10527 something that will match the mangled name of a function.
10528 If the definition of the function has the same debug info,
10529 we should be able to match up with it anyway. But fallbacks
10530 using the minimal symbol, for instance to find a method
10531 implemented in a stripped copy of libstdc++, will not work.
10532 If we do not have debug info for the definition, we will have to
10533 match them up some other way.
10535 When we do name matching there is a related problem with function
10536 templates; two instantiated function templates are allowed to
10537 differ only by their return types, which we do not add here. */
10539 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10541 struct attribute
*attr
;
10542 struct die_info
*child
;
10545 die
->building_fullname
= 1;
10547 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10551 const gdb_byte
*bytes
;
10552 struct dwarf2_locexpr_baton
*baton
;
10555 if (child
->tag
!= DW_TAG_template_type_param
10556 && child
->tag
!= DW_TAG_template_value_param
)
10567 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10570 complaint (_("template parameter missing DW_AT_type"));
10571 buf
.puts ("UNKNOWN_TYPE");
10574 type
= die_type (child
, cu
);
10576 if (child
->tag
== DW_TAG_template_type_param
)
10578 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10579 &type_print_raw_options
);
10583 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10586 complaint (_("template parameter missing "
10587 "DW_AT_const_value"));
10588 buf
.puts ("UNKNOWN_VALUE");
10592 dwarf2_const_value_attr (attr
, type
, name
,
10593 &cu
->comp_unit_obstack
, cu
,
10594 &value
, &bytes
, &baton
);
10596 if (TYPE_NOSIGN (type
))
10597 /* GDB prints characters as NUMBER 'CHAR'. If that's
10598 changed, this can use value_print instead. */
10599 c_printchar (value
, type
, &buf
);
10602 struct value_print_options opts
;
10605 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10609 else if (bytes
!= NULL
)
10611 v
= allocate_value (type
);
10612 memcpy (value_contents_writeable (v
), bytes
,
10613 TYPE_LENGTH (type
));
10616 v
= value_from_longest (type
, value
);
10618 /* Specify decimal so that we do not depend on
10620 get_formatted_print_options (&opts
, 'd');
10622 value_print (v
, &buf
, &opts
);
10627 die
->building_fullname
= 0;
10631 /* Close the argument list, with a space if necessary
10632 (nested templates). */
10633 if (!buf
.empty () && buf
.string ().back () == '>')
10640 /* For C++ methods, append formal parameter type
10641 information, if PHYSNAME. */
10643 if (physname
&& die
->tag
== DW_TAG_subprogram
10644 && cu
->language
== language_cplus
)
10646 struct type
*type
= read_type_die (die
, cu
);
10648 c_type_print_args (type
, &buf
, 1, cu
->language
,
10649 &type_print_raw_options
);
10651 if (cu
->language
== language_cplus
)
10653 /* Assume that an artificial first parameter is
10654 "this", but do not crash if it is not. RealView
10655 marks unnamed (and thus unused) parameters as
10656 artificial; there is no way to differentiate
10658 if (TYPE_NFIELDS (type
) > 0
10659 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10660 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
10661 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
10663 buf
.puts (" const");
10667 const std::string
&intermediate_name
= buf
.string ();
10669 if (cu
->language
== language_cplus
)
10671 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10672 &objfile
->per_bfd
->storage_obstack
);
10674 /* If we only computed INTERMEDIATE_NAME, or if
10675 INTERMEDIATE_NAME is already canonical, then we need to
10676 copy it to the appropriate obstack. */
10677 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10678 name
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
10679 intermediate_name
);
10681 name
= canonical_name
;
10688 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10689 If scope qualifiers are appropriate they will be added. The result
10690 will be allocated on the storage_obstack, or NULL if the DIE does
10691 not have a name. NAME may either be from a previous call to
10692 dwarf2_name or NULL.
10694 The output string will be canonicalized (if C++). */
10696 static const char *
10697 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10699 return dwarf2_compute_name (name
, die
, cu
, 0);
10702 /* Construct a physname for the given DIE in CU. NAME may either be
10703 from a previous call to dwarf2_name or NULL. The result will be
10704 allocated on the objfile_objstack or NULL if the DIE does not have a
10707 The output string will be canonicalized (if C++). */
10709 static const char *
10710 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10712 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10713 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10716 /* In this case dwarf2_compute_name is just a shortcut not building anything
10718 if (!die_needs_namespace (die
, cu
))
10719 return dwarf2_compute_name (name
, die
, cu
, 1);
10721 mangled
= dw2_linkage_name (die
, cu
);
10723 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
10724 See https://github.com/rust-lang/rust/issues/32925. */
10725 if (cu
->language
== language_rust
&& mangled
!= NULL
10726 && strchr (mangled
, '{') != NULL
)
10729 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10731 gdb::unique_xmalloc_ptr
<char> demangled
;
10732 if (mangled
!= NULL
)
10735 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
10737 /* Do nothing (do not demangle the symbol name). */
10739 else if (cu
->language
== language_go
)
10741 /* This is a lie, but we already lie to the caller new_symbol.
10742 new_symbol assumes we return the mangled name.
10743 This just undoes that lie until things are cleaned up. */
10747 /* Use DMGL_RET_DROP for C++ template functions to suppress
10748 their return type. It is easier for GDB users to search
10749 for such functions as `name(params)' than `long name(params)'.
10750 In such case the minimal symbol names do not match the full
10751 symbol names but for template functions there is never a need
10752 to look up their definition from their declaration so
10753 the only disadvantage remains the minimal symbol variant
10754 `long name(params)' does not have the proper inferior type. */
10755 demangled
.reset (gdb_demangle (mangled
,
10756 (DMGL_PARAMS
| DMGL_ANSI
10757 | DMGL_RET_DROP
)));
10760 canon
= demangled
.get ();
10768 if (canon
== NULL
|| check_physname
)
10770 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10772 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10774 /* It may not mean a bug in GDB. The compiler could also
10775 compute DW_AT_linkage_name incorrectly. But in such case
10776 GDB would need to be bug-to-bug compatible. */
10778 complaint (_("Computed physname <%s> does not match demangled <%s> "
10779 "(from linkage <%s>) - DIE at %s [in module %s]"),
10780 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10781 objfile_name (objfile
));
10783 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10784 is available here - over computed PHYSNAME. It is safer
10785 against both buggy GDB and buggy compilers. */
10799 retval
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
, retval
);
10804 /* Inspect DIE in CU for a namespace alias. If one exists, record
10805 a new symbol for it.
10807 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10810 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10812 struct attribute
*attr
;
10814 /* If the die does not have a name, this is not a namespace
10816 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10820 struct die_info
*d
= die
;
10821 struct dwarf2_cu
*imported_cu
= cu
;
10823 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10824 keep inspecting DIEs until we hit the underlying import. */
10825 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10826 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10828 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10832 d
= follow_die_ref (d
, attr
, &imported_cu
);
10833 if (d
->tag
!= DW_TAG_imported_declaration
)
10837 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10839 complaint (_("DIE at %s has too many recursively imported "
10840 "declarations"), sect_offset_str (d
->sect_off
));
10847 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
10849 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
10850 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
10852 /* This declaration is a global namespace alias. Add
10853 a symbol for it whose type is the aliased namespace. */
10854 new_symbol (die
, type
, cu
);
10863 /* Return the using directives repository (global or local?) to use in the
10864 current context for CU.
10866 For Ada, imported declarations can materialize renamings, which *may* be
10867 global. However it is impossible (for now?) in DWARF to distinguish
10868 "external" imported declarations and "static" ones. As all imported
10869 declarations seem to be static in all other languages, make them all CU-wide
10870 global only in Ada. */
10872 static struct using_direct
**
10873 using_directives (struct dwarf2_cu
*cu
)
10875 if (cu
->language
== language_ada
10876 && cu
->get_builder ()->outermost_context_p ())
10877 return cu
->get_builder ()->get_global_using_directives ();
10879 return cu
->get_builder ()->get_local_using_directives ();
10882 /* Read the import statement specified by the given die and record it. */
10885 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10887 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10888 struct attribute
*import_attr
;
10889 struct die_info
*imported_die
, *child_die
;
10890 struct dwarf2_cu
*imported_cu
;
10891 const char *imported_name
;
10892 const char *imported_name_prefix
;
10893 const char *canonical_name
;
10894 const char *import_alias
;
10895 const char *imported_declaration
= NULL
;
10896 const char *import_prefix
;
10897 std::vector
<const char *> excludes
;
10899 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10900 if (import_attr
== NULL
)
10902 complaint (_("Tag '%s' has no DW_AT_import"),
10903 dwarf_tag_name (die
->tag
));
10908 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10909 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10910 if (imported_name
== NULL
)
10912 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10914 The import in the following code:
10928 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10929 <52> DW_AT_decl_file : 1
10930 <53> DW_AT_decl_line : 6
10931 <54> DW_AT_import : <0x75>
10932 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10933 <59> DW_AT_name : B
10934 <5b> DW_AT_decl_file : 1
10935 <5c> DW_AT_decl_line : 2
10936 <5d> DW_AT_type : <0x6e>
10938 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10939 <76> DW_AT_byte_size : 4
10940 <77> DW_AT_encoding : 5 (signed)
10942 imports the wrong die ( 0x75 instead of 0x58 ).
10943 This case will be ignored until the gcc bug is fixed. */
10947 /* Figure out the local name after import. */
10948 import_alias
= dwarf2_name (die
, cu
);
10950 /* Figure out where the statement is being imported to. */
10951 import_prefix
= determine_prefix (die
, cu
);
10953 /* Figure out what the scope of the imported die is and prepend it
10954 to the name of the imported die. */
10955 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10957 if (imported_die
->tag
!= DW_TAG_namespace
10958 && imported_die
->tag
!= DW_TAG_module
)
10960 imported_declaration
= imported_name
;
10961 canonical_name
= imported_name_prefix
;
10963 else if (strlen (imported_name_prefix
) > 0)
10964 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10965 imported_name_prefix
,
10966 (cu
->language
== language_d
? "." : "::"),
10967 imported_name
, (char *) NULL
);
10969 canonical_name
= imported_name
;
10971 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
10972 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10973 child_die
= sibling_die (child_die
))
10975 /* DWARF-4: A Fortran use statement with a “rename list” may be
10976 represented by an imported module entry with an import attribute
10977 referring to the module and owned entries corresponding to those
10978 entities that are renamed as part of being imported. */
10980 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10982 complaint (_("child DW_TAG_imported_declaration expected "
10983 "- DIE at %s [in module %s]"),
10984 sect_offset_str (child_die
->sect_off
),
10985 objfile_name (objfile
));
10989 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10990 if (import_attr
== NULL
)
10992 complaint (_("Tag '%s' has no DW_AT_import"),
10993 dwarf_tag_name (child_die
->tag
));
10998 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
11000 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11001 if (imported_name
== NULL
)
11003 complaint (_("child DW_TAG_imported_declaration has unknown "
11004 "imported name - DIE at %s [in module %s]"),
11005 sect_offset_str (child_die
->sect_off
),
11006 objfile_name (objfile
));
11010 excludes
.push_back (imported_name
);
11012 process_die (child_die
, cu
);
11015 add_using_directive (using_directives (cu
),
11019 imported_declaration
,
11022 &objfile
->objfile_obstack
);
11025 /* ICC<14 does not output the required DW_AT_declaration on incomplete
11026 types, but gives them a size of zero. Starting with version 14,
11027 ICC is compatible with GCC. */
11030 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
11032 if (!cu
->checked_producer
)
11033 check_producer (cu
);
11035 return cu
->producer_is_icc_lt_14
;
11038 /* ICC generates a DW_AT_type for C void functions. This was observed on
11039 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
11040 which says that void functions should not have a DW_AT_type. */
11043 producer_is_icc (struct dwarf2_cu
*cu
)
11045 if (!cu
->checked_producer
)
11046 check_producer (cu
);
11048 return cu
->producer_is_icc
;
11051 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
11052 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
11053 this, it was first present in GCC release 4.3.0. */
11056 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
11058 if (!cu
->checked_producer
)
11059 check_producer (cu
);
11061 return cu
->producer_is_gcc_lt_4_3
;
11064 static file_and_directory
11065 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
11067 file_and_directory res
;
11069 /* Find the filename. Do not use dwarf2_name here, since the filename
11070 is not a source language identifier. */
11071 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
11072 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
11074 if (res
.comp_dir
== NULL
11075 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
11076 && IS_ABSOLUTE_PATH (res
.name
))
11078 res
.comp_dir_storage
= ldirname (res
.name
);
11079 if (!res
.comp_dir_storage
.empty ())
11080 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
11082 if (res
.comp_dir
!= NULL
)
11084 /* Irix 6.2 native cc prepends <machine>.: to the compilation
11085 directory, get rid of it. */
11086 const char *cp
= strchr (res
.comp_dir
, ':');
11088 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
11089 res
.comp_dir
= cp
+ 1;
11092 if (res
.name
== NULL
)
11093 res
.name
= "<unknown>";
11098 /* Handle DW_AT_stmt_list for a compilation unit.
11099 DIE is the DW_TAG_compile_unit die for CU.
11100 COMP_DIR is the compilation directory. LOWPC is passed to
11101 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
11104 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
11105 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
11107 struct dwarf2_per_objfile
*dwarf2_per_objfile
11108 = cu
->per_cu
->dwarf2_per_objfile
;
11109 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11110 struct attribute
*attr
;
11111 struct line_header line_header_local
;
11112 hashval_t line_header_local_hash
;
11114 int decode_mapping
;
11116 gdb_assert (! cu
->per_cu
->is_debug_types
);
11118 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
11122 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11124 /* The line header hash table is only created if needed (it exists to
11125 prevent redundant reading of the line table for partial_units).
11126 If we're given a partial_unit, we'll need it. If we're given a
11127 compile_unit, then use the line header hash table if it's already
11128 created, but don't create one just yet. */
11130 if (dwarf2_per_objfile
->line_header_hash
== NULL
11131 && die
->tag
== DW_TAG_partial_unit
)
11133 dwarf2_per_objfile
->line_header_hash
11134 = htab_create_alloc_ex (127, line_header_hash_voidp
,
11135 line_header_eq_voidp
,
11136 free_line_header_voidp
,
11137 &objfile
->objfile_obstack
,
11138 hashtab_obstack_allocate
,
11139 dummy_obstack_deallocate
);
11142 line_header_local
.sect_off
= line_offset
;
11143 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
11144 line_header_local_hash
= line_header_hash (&line_header_local
);
11145 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
11147 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11148 &line_header_local
,
11149 line_header_local_hash
, NO_INSERT
);
11151 /* For DW_TAG_compile_unit we need info like symtab::linetable which
11152 is not present in *SLOT (since if there is something in *SLOT then
11153 it will be for a partial_unit). */
11154 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
11156 gdb_assert (*slot
!= NULL
);
11157 cu
->line_header
= (struct line_header
*) *slot
;
11162 /* dwarf_decode_line_header does not yet provide sufficient information.
11163 We always have to call also dwarf_decode_lines for it. */
11164 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
11168 cu
->line_header
= lh
.release ();
11169 cu
->line_header_die_owner
= die
;
11171 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
11175 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11176 &line_header_local
,
11177 line_header_local_hash
, INSERT
);
11178 gdb_assert (slot
!= NULL
);
11180 if (slot
!= NULL
&& *slot
== NULL
)
11182 /* This newly decoded line number information unit will be owned
11183 by line_header_hash hash table. */
11184 *slot
= cu
->line_header
;
11185 cu
->line_header_die_owner
= NULL
;
11189 /* We cannot free any current entry in (*slot) as that struct line_header
11190 may be already used by multiple CUs. Create only temporary decoded
11191 line_header for this CU - it may happen at most once for each line
11192 number information unit. And if we're not using line_header_hash
11193 then this is what we want as well. */
11194 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
11196 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
11197 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
11202 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
11205 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11207 struct dwarf2_per_objfile
*dwarf2_per_objfile
11208 = cu
->per_cu
->dwarf2_per_objfile
;
11209 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11210 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11211 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
11212 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
11213 struct attribute
*attr
;
11214 struct die_info
*child_die
;
11215 CORE_ADDR baseaddr
;
11217 prepare_one_comp_unit (cu
, die
, cu
->language
);
11218 baseaddr
= objfile
->text_section_offset ();
11220 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
11222 /* If we didn't find a lowpc, set it to highpc to avoid complaints
11223 from finish_block. */
11224 if (lowpc
== ((CORE_ADDR
) -1))
11226 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11228 file_and_directory fnd
= find_file_and_directory (die
, cu
);
11230 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
11231 standardised yet. As a workaround for the language detection we fall
11232 back to the DW_AT_producer string. */
11233 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
11234 cu
->language
= language_opencl
;
11236 /* Similar hack for Go. */
11237 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
11238 set_cu_language (DW_LANG_Go
, cu
);
11240 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
11242 /* Decode line number information if present. We do this before
11243 processing child DIEs, so that the line header table is available
11244 for DW_AT_decl_file. */
11245 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
11247 /* Process all dies in compilation unit. */
11248 if (die
->child
!= NULL
)
11250 child_die
= die
->child
;
11251 while (child_die
&& child_die
->tag
)
11253 process_die (child_die
, cu
);
11254 child_die
= sibling_die (child_die
);
11258 /* Decode macro information, if present. Dwarf 2 macro information
11259 refers to information in the line number info statement program
11260 header, so we can only read it if we've read the header
11262 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
11264 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
11265 if (attr
&& cu
->line_header
)
11267 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
11268 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
11270 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
11274 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
11275 if (attr
&& cu
->line_header
)
11277 unsigned int macro_offset
= DW_UNSND (attr
);
11279 dwarf_decode_macros (cu
, macro_offset
, 0);
11285 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
11287 struct type_unit_group
*tu_group
;
11289 struct attribute
*attr
;
11291 struct signatured_type
*sig_type
;
11293 gdb_assert (per_cu
->is_debug_types
);
11294 sig_type
= (struct signatured_type
*) per_cu
;
11296 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
11298 /* If we're using .gdb_index (includes -readnow) then
11299 per_cu->type_unit_group may not have been set up yet. */
11300 if (sig_type
->type_unit_group
== NULL
)
11301 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
11302 tu_group
= sig_type
->type_unit_group
;
11304 /* If we've already processed this stmt_list there's no real need to
11305 do it again, we could fake it and just recreate the part we need
11306 (file name,index -> symtab mapping). If data shows this optimization
11307 is useful we can do it then. */
11308 first_time
= tu_group
->compunit_symtab
== NULL
;
11310 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
11315 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11316 lh
= dwarf_decode_line_header (line_offset
, this);
11321 start_symtab ("", NULL
, 0);
11324 gdb_assert (tu_group
->symtabs
== NULL
);
11325 gdb_assert (m_builder
== nullptr);
11326 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
11327 m_builder
.reset (new struct buildsym_compunit
11328 (COMPUNIT_OBJFILE (cust
), "",
11329 COMPUNIT_DIRNAME (cust
),
11330 compunit_language (cust
),
11336 line_header
= lh
.release ();
11337 line_header_die_owner
= die
;
11341 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
11343 /* Note: We don't assign tu_group->compunit_symtab yet because we're
11344 still initializing it, and our caller (a few levels up)
11345 process_full_type_unit still needs to know if this is the first
11348 tu_group
->num_symtabs
= line_header
->file_names_size ();
11349 tu_group
->symtabs
= XNEWVEC (struct symtab
*,
11350 line_header
->file_names_size ());
11352 auto &file_names
= line_header
->file_names ();
11353 for (i
= 0; i
< file_names
.size (); ++i
)
11355 file_entry
&fe
= file_names
[i
];
11356 dwarf2_start_subfile (this, fe
.name
,
11357 fe
.include_dir (line_header
));
11358 buildsym_compunit
*b
= get_builder ();
11359 if (b
->get_current_subfile ()->symtab
== NULL
)
11361 /* NOTE: start_subfile will recognize when it's been
11362 passed a file it has already seen. So we can't
11363 assume there's a simple mapping from
11364 cu->line_header->file_names to subfiles, plus
11365 cu->line_header->file_names may contain dups. */
11366 b
->get_current_subfile ()->symtab
11367 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
11370 fe
.symtab
= b
->get_current_subfile ()->symtab
;
11371 tu_group
->symtabs
[i
] = fe
.symtab
;
11376 gdb_assert (m_builder
== nullptr);
11377 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
11378 m_builder
.reset (new struct buildsym_compunit
11379 (COMPUNIT_OBJFILE (cust
), "",
11380 COMPUNIT_DIRNAME (cust
),
11381 compunit_language (cust
),
11384 auto &file_names
= line_header
->file_names ();
11385 for (i
= 0; i
< file_names
.size (); ++i
)
11387 file_entry
&fe
= file_names
[i
];
11388 fe
.symtab
= tu_group
->symtabs
[i
];
11392 /* The main symtab is allocated last. Type units don't have DW_AT_name
11393 so they don't have a "real" (so to speak) symtab anyway.
11394 There is later code that will assign the main symtab to all symbols
11395 that don't have one. We need to handle the case of a symbol with a
11396 missing symtab (DW_AT_decl_file) anyway. */
11399 /* Process DW_TAG_type_unit.
11400 For TUs we want to skip the first top level sibling if it's not the
11401 actual type being defined by this TU. In this case the first top
11402 level sibling is there to provide context only. */
11405 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11407 struct die_info
*child_die
;
11409 prepare_one_comp_unit (cu
, die
, language_minimal
);
11411 /* Initialize (or reinitialize) the machinery for building symtabs.
11412 We do this before processing child DIEs, so that the line header table
11413 is available for DW_AT_decl_file. */
11414 cu
->setup_type_unit_groups (die
);
11416 if (die
->child
!= NULL
)
11418 child_die
= die
->child
;
11419 while (child_die
&& child_die
->tag
)
11421 process_die (child_die
, cu
);
11422 child_die
= sibling_die (child_die
);
11429 http://gcc.gnu.org/wiki/DebugFission
11430 http://gcc.gnu.org/wiki/DebugFissionDWP
11432 To simplify handling of both DWO files ("object" files with the DWARF info)
11433 and DWP files (a file with the DWOs packaged up into one file), we treat
11434 DWP files as having a collection of virtual DWO files. */
11437 hash_dwo_file (const void *item
)
11439 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11442 hash
= htab_hash_string (dwo_file
->dwo_name
);
11443 if (dwo_file
->comp_dir
!= NULL
)
11444 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11449 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11451 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11452 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11454 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11456 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11457 return lhs
->comp_dir
== rhs
->comp_dir
;
11458 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11461 /* Allocate a hash table for DWO files. */
11464 allocate_dwo_file_hash_table (struct objfile
*objfile
)
11466 auto delete_dwo_file
= [] (void *item
)
11468 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
11473 return htab_up (htab_create_alloc_ex (41,
11477 &objfile
->objfile_obstack
,
11478 hashtab_obstack_allocate
,
11479 dummy_obstack_deallocate
));
11482 /* Lookup DWO file DWO_NAME. */
11485 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11486 const char *dwo_name
,
11487 const char *comp_dir
)
11489 struct dwo_file find_entry
;
11492 if (dwarf2_per_objfile
->dwo_files
== NULL
)
11493 dwarf2_per_objfile
->dwo_files
11494 = allocate_dwo_file_hash_table (dwarf2_per_objfile
->objfile
);
11496 find_entry
.dwo_name
= dwo_name
;
11497 find_entry
.comp_dir
= comp_dir
;
11498 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
.get (), &find_entry
,
11505 hash_dwo_unit (const void *item
)
11507 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11509 /* This drops the top 32 bits of the id, but is ok for a hash. */
11510 return dwo_unit
->signature
;
11514 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11516 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11517 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11519 /* The signature is assumed to be unique within the DWO file.
11520 So while object file CU dwo_id's always have the value zero,
11521 that's OK, assuming each object file DWO file has only one CU,
11522 and that's the rule for now. */
11523 return lhs
->signature
== rhs
->signature
;
11526 /* Allocate a hash table for DWO CUs,TUs.
11527 There is one of these tables for each of CUs,TUs for each DWO file. */
11530 allocate_dwo_unit_table (struct objfile
*objfile
)
11532 /* Start out with a pretty small number.
11533 Generally DWO files contain only one CU and maybe some TUs. */
11534 return htab_create_alloc_ex (3,
11538 &objfile
->objfile_obstack
,
11539 hashtab_obstack_allocate
,
11540 dummy_obstack_deallocate
);
11543 /* die_reader_func for create_dwo_cu. */
11546 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11547 const gdb_byte
*info_ptr
,
11548 struct die_info
*comp_unit_die
,
11550 struct dwo_file
*dwo_file
,
11551 struct dwo_unit
*dwo_unit
)
11553 struct dwarf2_cu
*cu
= reader
->cu
;
11554 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11555 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11557 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11558 if (!signature
.has_value ())
11560 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11561 " its dwo_id [in module %s]"),
11562 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11566 dwo_unit
->dwo_file
= dwo_file
;
11567 dwo_unit
->signature
= *signature
;
11568 dwo_unit
->section
= section
;
11569 dwo_unit
->sect_off
= sect_off
;
11570 dwo_unit
->length
= cu
->per_cu
->length
;
11572 if (dwarf_read_debug
)
11573 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11574 sect_offset_str (sect_off
),
11575 hex_string (dwo_unit
->signature
));
11578 /* Create the dwo_units for the CUs in a DWO_FILE.
11579 Note: This function processes DWO files only, not DWP files. */
11582 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11583 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11584 dwarf2_section_info
§ion
, htab_t
&cus_htab
)
11586 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11587 const gdb_byte
*info_ptr
, *end_ptr
;
11589 section
.read (objfile
);
11590 info_ptr
= section
.buffer
;
11592 if (info_ptr
== NULL
)
11595 if (dwarf_read_debug
)
11597 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11598 section
.get_name (),
11599 section
.get_file_name ());
11602 end_ptr
= info_ptr
+ section
.size
;
11603 while (info_ptr
< end_ptr
)
11605 struct dwarf2_per_cu_data per_cu
;
11606 struct dwo_unit read_unit
{};
11607 struct dwo_unit
*dwo_unit
;
11609 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11611 memset (&per_cu
, 0, sizeof (per_cu
));
11612 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
11613 per_cu
.is_debug_types
= 0;
11614 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11615 per_cu
.section
= §ion
;
11617 cutu_reader
reader (&per_cu
, cu
, &dwo_file
);
11618 if (!reader
.dummy_p
)
11619 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11620 reader
.has_children
, &dwo_file
, &read_unit
);
11621 info_ptr
+= per_cu
.length
;
11623 // If the unit could not be parsed, skip it.
11624 if (read_unit
.dwo_file
== NULL
)
11627 if (cus_htab
== NULL
)
11628 cus_htab
= allocate_dwo_unit_table (objfile
);
11630 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11631 *dwo_unit
= read_unit
;
11632 slot
= htab_find_slot (cus_htab
, dwo_unit
, INSERT
);
11633 gdb_assert (slot
!= NULL
);
11636 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11637 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11639 complaint (_("debug cu entry at offset %s is duplicate to"
11640 " the entry at offset %s, signature %s"),
11641 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11642 hex_string (dwo_unit
->signature
));
11644 *slot
= (void *)dwo_unit
;
11648 /* DWP file .debug_{cu,tu}_index section format:
11649 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11653 Both index sections have the same format, and serve to map a 64-bit
11654 signature to a set of section numbers. Each section begins with a header,
11655 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11656 indexes, and a pool of 32-bit section numbers. The index sections will be
11657 aligned at 8-byte boundaries in the file.
11659 The index section header consists of:
11661 V, 32 bit version number
11663 N, 32 bit number of compilation units or type units in the index
11664 M, 32 bit number of slots in the hash table
11666 Numbers are recorded using the byte order of the application binary.
11668 The hash table begins at offset 16 in the section, and consists of an array
11669 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11670 order of the application binary). Unused slots in the hash table are 0.
11671 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11673 The parallel table begins immediately after the hash table
11674 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11675 array of 32-bit indexes (using the byte order of the application binary),
11676 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11677 table contains a 32-bit index into the pool of section numbers. For unused
11678 hash table slots, the corresponding entry in the parallel table will be 0.
11680 The pool of section numbers begins immediately following the hash table
11681 (at offset 16 + 12 * M from the beginning of the section). The pool of
11682 section numbers consists of an array of 32-bit words (using the byte order
11683 of the application binary). Each item in the array is indexed starting
11684 from 0. The hash table entry provides the index of the first section
11685 number in the set. Additional section numbers in the set follow, and the
11686 set is terminated by a 0 entry (section number 0 is not used in ELF).
11688 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11689 section must be the first entry in the set, and the .debug_abbrev.dwo must
11690 be the second entry. Other members of the set may follow in any order.
11696 DWP Version 2 combines all the .debug_info, etc. sections into one,
11697 and the entries in the index tables are now offsets into these sections.
11698 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11701 Index Section Contents:
11703 Hash Table of Signatures dwp_hash_table.hash_table
11704 Parallel Table of Indices dwp_hash_table.unit_table
11705 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
11706 Table of Section Sizes dwp_hash_table.v2.sizes
11708 The index section header consists of:
11710 V, 32 bit version number
11711 L, 32 bit number of columns in the table of section offsets
11712 N, 32 bit number of compilation units or type units in the index
11713 M, 32 bit number of slots in the hash table
11715 Numbers are recorded using the byte order of the application binary.
11717 The hash table has the same format as version 1.
11718 The parallel table of indices has the same format as version 1,
11719 except that the entries are origin-1 indices into the table of sections
11720 offsets and the table of section sizes.
11722 The table of offsets begins immediately following the parallel table
11723 (at offset 16 + 12 * M from the beginning of the section). The table is
11724 a two-dimensional array of 32-bit words (using the byte order of the
11725 application binary), with L columns and N+1 rows, in row-major order.
11726 Each row in the array is indexed starting from 0. The first row provides
11727 a key to the remaining rows: each column in this row provides an identifier
11728 for a debug section, and the offsets in the same column of subsequent rows
11729 refer to that section. The section identifiers are:
11731 DW_SECT_INFO 1 .debug_info.dwo
11732 DW_SECT_TYPES 2 .debug_types.dwo
11733 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11734 DW_SECT_LINE 4 .debug_line.dwo
11735 DW_SECT_LOC 5 .debug_loc.dwo
11736 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11737 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11738 DW_SECT_MACRO 8 .debug_macro.dwo
11740 The offsets provided by the CU and TU index sections are the base offsets
11741 for the contributions made by each CU or TU to the corresponding section
11742 in the package file. Each CU and TU header contains an abbrev_offset
11743 field, used to find the abbreviations table for that CU or TU within the
11744 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11745 be interpreted as relative to the base offset given in the index section.
11746 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11747 should be interpreted as relative to the base offset for .debug_line.dwo,
11748 and offsets into other debug sections obtained from DWARF attributes should
11749 also be interpreted as relative to the corresponding base offset.
11751 The table of sizes begins immediately following the table of offsets.
11752 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11753 with L columns and N rows, in row-major order. Each row in the array is
11754 indexed starting from 1 (row 0 is shared by the two tables).
11758 Hash table lookup is handled the same in version 1 and 2:
11760 We assume that N and M will not exceed 2^32 - 1.
11761 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11763 Given a 64-bit compilation unit signature or a type signature S, an entry
11764 in the hash table is located as follows:
11766 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11767 the low-order k bits all set to 1.
11769 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11771 3) If the hash table entry at index H matches the signature, use that
11772 entry. If the hash table entry at index H is unused (all zeroes),
11773 terminate the search: the signature is not present in the table.
11775 4) Let H = (H + H') modulo M. Repeat at Step 3.
11777 Because M > N and H' and M are relatively prime, the search is guaranteed
11778 to stop at an unused slot or find the match. */
11780 /* Create a hash table to map DWO IDs to their CU/TU entry in
11781 .debug_{info,types}.dwo in DWP_FILE.
11782 Returns NULL if there isn't one.
11783 Note: This function processes DWP files only, not DWO files. */
11785 static struct dwp_hash_table
*
11786 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11787 struct dwp_file
*dwp_file
, int is_debug_types
)
11789 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11790 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11791 const gdb_byte
*index_ptr
, *index_end
;
11792 struct dwarf2_section_info
*index
;
11793 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11794 struct dwp_hash_table
*htab
;
11796 if (is_debug_types
)
11797 index
= &dwp_file
->sections
.tu_index
;
11799 index
= &dwp_file
->sections
.cu_index
;
11801 if (index
->empty ())
11803 index
->read (objfile
);
11805 index_ptr
= index
->buffer
;
11806 index_end
= index_ptr
+ index
->size
;
11808 version
= read_4_bytes (dbfd
, index_ptr
);
11811 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11815 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11817 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11820 if (version
!= 1 && version
!= 2)
11822 error (_("Dwarf Error: unsupported DWP file version (%s)"
11823 " [in module %s]"),
11824 pulongest (version
), dwp_file
->name
);
11826 if (nr_slots
!= (nr_slots
& -nr_slots
))
11828 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11829 " is not power of 2 [in module %s]"),
11830 pulongest (nr_slots
), dwp_file
->name
);
11833 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
11834 htab
->version
= version
;
11835 htab
->nr_columns
= nr_columns
;
11836 htab
->nr_units
= nr_units
;
11837 htab
->nr_slots
= nr_slots
;
11838 htab
->hash_table
= index_ptr
;
11839 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11841 /* Exit early if the table is empty. */
11842 if (nr_slots
== 0 || nr_units
== 0
11843 || (version
== 2 && nr_columns
== 0))
11845 /* All must be zero. */
11846 if (nr_slots
!= 0 || nr_units
!= 0
11847 || (version
== 2 && nr_columns
!= 0))
11849 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11850 " all zero [in modules %s]"),
11858 htab
->section_pool
.v1
.indices
=
11859 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11860 /* It's harder to decide whether the section is too small in v1.
11861 V1 is deprecated anyway so we punt. */
11865 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11866 int *ids
= htab
->section_pool
.v2
.section_ids
;
11867 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11868 /* Reverse map for error checking. */
11869 int ids_seen
[DW_SECT_MAX
+ 1];
11872 if (nr_columns
< 2)
11874 error (_("Dwarf Error: bad DWP hash table, too few columns"
11875 " in section table [in module %s]"),
11878 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11880 error (_("Dwarf Error: bad DWP hash table, too many columns"
11881 " in section table [in module %s]"),
11884 memset (ids
, 255, sizeof_ids
);
11885 memset (ids_seen
, 255, sizeof (ids_seen
));
11886 for (i
= 0; i
< nr_columns
; ++i
)
11888 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11890 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11892 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11893 " in section table [in module %s]"),
11894 id
, dwp_file
->name
);
11896 if (ids_seen
[id
] != -1)
11898 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11899 " id %d in section table [in module %s]"),
11900 id
, dwp_file
->name
);
11905 /* Must have exactly one info or types section. */
11906 if (((ids_seen
[DW_SECT_INFO
] != -1)
11907 + (ids_seen
[DW_SECT_TYPES
] != -1))
11910 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11911 " DWO info/types section [in module %s]"),
11914 /* Must have an abbrev section. */
11915 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11917 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11918 " section [in module %s]"),
11921 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11922 htab
->section_pool
.v2
.sizes
=
11923 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11924 * nr_units
* nr_columns
);
11925 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11926 * nr_units
* nr_columns
))
11929 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11930 " [in module %s]"),
11938 /* Update SECTIONS with the data from SECTP.
11940 This function is like the other "locate" section routines that are
11941 passed to bfd_map_over_sections, but in this context the sections to
11942 read comes from the DWP V1 hash table, not the full ELF section table.
11944 The result is non-zero for success, or zero if an error was found. */
11947 locate_v1_virtual_dwo_sections (asection
*sectp
,
11948 struct virtual_v1_dwo_sections
*sections
)
11950 const struct dwop_section_names
*names
= &dwop_section_names
;
11952 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
11954 /* There can be only one. */
11955 if (sections
->abbrev
.s
.section
!= NULL
)
11957 sections
->abbrev
.s
.section
= sectp
;
11958 sections
->abbrev
.size
= bfd_section_size (sectp
);
11960 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
11961 || section_is_p (sectp
->name
, &names
->types_dwo
))
11963 /* There can be only one. */
11964 if (sections
->info_or_types
.s
.section
!= NULL
)
11966 sections
->info_or_types
.s
.section
= sectp
;
11967 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11969 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
11971 /* There can be only one. */
11972 if (sections
->line
.s
.section
!= NULL
)
11974 sections
->line
.s
.section
= sectp
;
11975 sections
->line
.size
= bfd_section_size (sectp
);
11977 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
11979 /* There can be only one. */
11980 if (sections
->loc
.s
.section
!= NULL
)
11982 sections
->loc
.s
.section
= sectp
;
11983 sections
->loc
.size
= bfd_section_size (sectp
);
11985 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
11987 /* There can be only one. */
11988 if (sections
->macinfo
.s
.section
!= NULL
)
11990 sections
->macinfo
.s
.section
= sectp
;
11991 sections
->macinfo
.size
= bfd_section_size (sectp
);
11993 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
11995 /* There can be only one. */
11996 if (sections
->macro
.s
.section
!= NULL
)
11998 sections
->macro
.s
.section
= sectp
;
11999 sections
->macro
.size
= bfd_section_size (sectp
);
12001 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12003 /* There can be only one. */
12004 if (sections
->str_offsets
.s
.section
!= NULL
)
12006 sections
->str_offsets
.s
.section
= sectp
;
12007 sections
->str_offsets
.size
= bfd_section_size (sectp
);
12011 /* No other kind of section is valid. */
12018 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12019 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12020 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12021 This is for DWP version 1 files. */
12023 static struct dwo_unit
*
12024 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12025 struct dwp_file
*dwp_file
,
12026 uint32_t unit_index
,
12027 const char *comp_dir
,
12028 ULONGEST signature
, int is_debug_types
)
12030 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12031 const struct dwp_hash_table
*dwp_htab
=
12032 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12033 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12034 const char *kind
= is_debug_types
? "TU" : "CU";
12035 struct dwo_file
*dwo_file
;
12036 struct dwo_unit
*dwo_unit
;
12037 struct virtual_v1_dwo_sections sections
;
12038 void **dwo_file_slot
;
12041 gdb_assert (dwp_file
->version
== 1);
12043 if (dwarf_read_debug
)
12045 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
12047 pulongest (unit_index
), hex_string (signature
),
12051 /* Fetch the sections of this DWO unit.
12052 Put a limit on the number of sections we look for so that bad data
12053 doesn't cause us to loop forever. */
12055 #define MAX_NR_V1_DWO_SECTIONS \
12056 (1 /* .debug_info or .debug_types */ \
12057 + 1 /* .debug_abbrev */ \
12058 + 1 /* .debug_line */ \
12059 + 1 /* .debug_loc */ \
12060 + 1 /* .debug_str_offsets */ \
12061 + 1 /* .debug_macro or .debug_macinfo */ \
12062 + 1 /* trailing zero */)
12064 memset (§ions
, 0, sizeof (sections
));
12066 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
12069 uint32_t section_nr
=
12070 read_4_bytes (dbfd
,
12071 dwp_htab
->section_pool
.v1
.indices
12072 + (unit_index
+ i
) * sizeof (uint32_t));
12074 if (section_nr
== 0)
12076 if (section_nr
>= dwp_file
->num_sections
)
12078 error (_("Dwarf Error: bad DWP hash table, section number too large"
12079 " [in module %s]"),
12083 sectp
= dwp_file
->elf_sections
[section_nr
];
12084 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
12086 error (_("Dwarf Error: bad DWP hash table, invalid section found"
12087 " [in module %s]"),
12093 || sections
.info_or_types
.empty ()
12094 || sections
.abbrev
.empty ())
12096 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
12097 " [in module %s]"),
12100 if (i
== MAX_NR_V1_DWO_SECTIONS
)
12102 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
12103 " [in module %s]"),
12107 /* It's easier for the rest of the code if we fake a struct dwo_file and
12108 have dwo_unit "live" in that. At least for now.
12110 The DWP file can be made up of a random collection of CUs and TUs.
12111 However, for each CU + set of TUs that came from the same original DWO
12112 file, we can combine them back into a virtual DWO file to save space
12113 (fewer struct dwo_file objects to allocate). Remember that for really
12114 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12116 std::string virtual_dwo_name
=
12117 string_printf ("virtual-dwo/%d-%d-%d-%d",
12118 sections
.abbrev
.get_id (),
12119 sections
.line
.get_id (),
12120 sections
.loc
.get_id (),
12121 sections
.str_offsets
.get_id ());
12122 /* Can we use an existing virtual DWO file? */
12123 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12124 virtual_dwo_name
.c_str (),
12126 /* Create one if necessary. */
12127 if (*dwo_file_slot
== NULL
)
12129 if (dwarf_read_debug
)
12131 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12132 virtual_dwo_name
.c_str ());
12134 dwo_file
= new struct dwo_file
;
12135 dwo_file
->dwo_name
= obstack_strdup (&objfile
->objfile_obstack
,
12137 dwo_file
->comp_dir
= comp_dir
;
12138 dwo_file
->sections
.abbrev
= sections
.abbrev
;
12139 dwo_file
->sections
.line
= sections
.line
;
12140 dwo_file
->sections
.loc
= sections
.loc
;
12141 dwo_file
->sections
.macinfo
= sections
.macinfo
;
12142 dwo_file
->sections
.macro
= sections
.macro
;
12143 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
12144 /* The "str" section is global to the entire DWP file. */
12145 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12146 /* The info or types section is assigned below to dwo_unit,
12147 there's no need to record it in dwo_file.
12148 Also, we can't simply record type sections in dwo_file because
12149 we record a pointer into the vector in dwo_unit. As we collect more
12150 types we'll grow the vector and eventually have to reallocate space
12151 for it, invalidating all copies of pointers into the previous
12153 *dwo_file_slot
= dwo_file
;
12157 if (dwarf_read_debug
)
12159 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12160 virtual_dwo_name
.c_str ());
12162 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12165 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12166 dwo_unit
->dwo_file
= dwo_file
;
12167 dwo_unit
->signature
= signature
;
12168 dwo_unit
->section
=
12169 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12170 *dwo_unit
->section
= sections
.info_or_types
;
12171 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12176 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
12177 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
12178 piece within that section used by a TU/CU, return a virtual section
12179 of just that piece. */
12181 static struct dwarf2_section_info
12182 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12183 struct dwarf2_section_info
*section
,
12184 bfd_size_type offset
, bfd_size_type size
)
12186 struct dwarf2_section_info result
;
12189 gdb_assert (section
!= NULL
);
12190 gdb_assert (!section
->is_virtual
);
12192 memset (&result
, 0, sizeof (result
));
12193 result
.s
.containing_section
= section
;
12194 result
.is_virtual
= true;
12199 sectp
= section
->get_bfd_section ();
12201 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
12202 bounds of the real section. This is a pretty-rare event, so just
12203 flag an error (easier) instead of a warning and trying to cope. */
12205 || offset
+ size
> bfd_section_size (sectp
))
12207 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
12208 " in section %s [in module %s]"),
12209 sectp
? bfd_section_name (sectp
) : "<unknown>",
12210 objfile_name (dwarf2_per_objfile
->objfile
));
12213 result
.virtual_offset
= offset
;
12214 result
.size
= size
;
12218 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12219 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12220 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12221 This is for DWP version 2 files. */
12223 static struct dwo_unit
*
12224 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12225 struct dwp_file
*dwp_file
,
12226 uint32_t unit_index
,
12227 const char *comp_dir
,
12228 ULONGEST signature
, int is_debug_types
)
12230 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12231 const struct dwp_hash_table
*dwp_htab
=
12232 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12233 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12234 const char *kind
= is_debug_types
? "TU" : "CU";
12235 struct dwo_file
*dwo_file
;
12236 struct dwo_unit
*dwo_unit
;
12237 struct virtual_v2_dwo_sections sections
;
12238 void **dwo_file_slot
;
12241 gdb_assert (dwp_file
->version
== 2);
12243 if (dwarf_read_debug
)
12245 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
12247 pulongest (unit_index
), hex_string (signature
),
12251 /* Fetch the section offsets of this DWO unit. */
12253 memset (§ions
, 0, sizeof (sections
));
12255 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12257 uint32_t offset
= read_4_bytes (dbfd
,
12258 dwp_htab
->section_pool
.v2
.offsets
12259 + (((unit_index
- 1) * dwp_htab
->nr_columns
12261 * sizeof (uint32_t)));
12262 uint32_t size
= read_4_bytes (dbfd
,
12263 dwp_htab
->section_pool
.v2
.sizes
12264 + (((unit_index
- 1) * dwp_htab
->nr_columns
12266 * sizeof (uint32_t)));
12268 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
12271 case DW_SECT_TYPES
:
12272 sections
.info_or_types_offset
= offset
;
12273 sections
.info_or_types_size
= size
;
12275 case DW_SECT_ABBREV
:
12276 sections
.abbrev_offset
= offset
;
12277 sections
.abbrev_size
= size
;
12280 sections
.line_offset
= offset
;
12281 sections
.line_size
= size
;
12284 sections
.loc_offset
= offset
;
12285 sections
.loc_size
= size
;
12287 case DW_SECT_STR_OFFSETS
:
12288 sections
.str_offsets_offset
= offset
;
12289 sections
.str_offsets_size
= size
;
12291 case DW_SECT_MACINFO
:
12292 sections
.macinfo_offset
= offset
;
12293 sections
.macinfo_size
= size
;
12295 case DW_SECT_MACRO
:
12296 sections
.macro_offset
= offset
;
12297 sections
.macro_size
= size
;
12302 /* It's easier for the rest of the code if we fake a struct dwo_file and
12303 have dwo_unit "live" in that. At least for now.
12305 The DWP file can be made up of a random collection of CUs and TUs.
12306 However, for each CU + set of TUs that came from the same original DWO
12307 file, we can combine them back into a virtual DWO file to save space
12308 (fewer struct dwo_file objects to allocate). Remember that for really
12309 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12311 std::string virtual_dwo_name
=
12312 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
12313 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12314 (long) (sections
.line_size
? sections
.line_offset
: 0),
12315 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
12316 (long) (sections
.str_offsets_size
12317 ? sections
.str_offsets_offset
: 0));
12318 /* Can we use an existing virtual DWO file? */
12319 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12320 virtual_dwo_name
.c_str (),
12322 /* Create one if necessary. */
12323 if (*dwo_file_slot
== NULL
)
12325 if (dwarf_read_debug
)
12327 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12328 virtual_dwo_name
.c_str ());
12330 dwo_file
= new struct dwo_file
;
12331 dwo_file
->dwo_name
= obstack_strdup (&objfile
->objfile_obstack
,
12333 dwo_file
->comp_dir
= comp_dir
;
12334 dwo_file
->sections
.abbrev
=
12335 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
12336 sections
.abbrev_offset
, sections
.abbrev_size
);
12337 dwo_file
->sections
.line
=
12338 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
12339 sections
.line_offset
, sections
.line_size
);
12340 dwo_file
->sections
.loc
=
12341 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
12342 sections
.loc_offset
, sections
.loc_size
);
12343 dwo_file
->sections
.macinfo
=
12344 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
12345 sections
.macinfo_offset
, sections
.macinfo_size
);
12346 dwo_file
->sections
.macro
=
12347 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
12348 sections
.macro_offset
, sections
.macro_size
);
12349 dwo_file
->sections
.str_offsets
=
12350 create_dwp_v2_section (dwarf2_per_objfile
,
12351 &dwp_file
->sections
.str_offsets
,
12352 sections
.str_offsets_offset
,
12353 sections
.str_offsets_size
);
12354 /* The "str" section is global to the entire DWP file. */
12355 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12356 /* The info or types section is assigned below to dwo_unit,
12357 there's no need to record it in dwo_file.
12358 Also, we can't simply record type sections in dwo_file because
12359 we record a pointer into the vector in dwo_unit. As we collect more
12360 types we'll grow the vector and eventually have to reallocate space
12361 for it, invalidating all copies of pointers into the previous
12363 *dwo_file_slot
= dwo_file
;
12367 if (dwarf_read_debug
)
12369 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12370 virtual_dwo_name
.c_str ());
12372 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12375 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12376 dwo_unit
->dwo_file
= dwo_file
;
12377 dwo_unit
->signature
= signature
;
12378 dwo_unit
->section
=
12379 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12380 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
12382 ? &dwp_file
->sections
.types
12383 : &dwp_file
->sections
.info
,
12384 sections
.info_or_types_offset
,
12385 sections
.info_or_types_size
);
12386 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12391 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12392 Returns NULL if the signature isn't found. */
12394 static struct dwo_unit
*
12395 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12396 struct dwp_file
*dwp_file
, const char *comp_dir
,
12397 ULONGEST signature
, int is_debug_types
)
12399 const struct dwp_hash_table
*dwp_htab
=
12400 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12401 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12402 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12403 uint32_t hash
= signature
& mask
;
12404 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12407 struct dwo_unit find_dwo_cu
;
12409 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12410 find_dwo_cu
.signature
= signature
;
12411 slot
= htab_find_slot (is_debug_types
12412 ? dwp_file
->loaded_tus
12413 : dwp_file
->loaded_cus
,
12414 &find_dwo_cu
, INSERT
);
12417 return (struct dwo_unit
*) *slot
;
12419 /* Use a for loop so that we don't loop forever on bad debug info. */
12420 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12422 ULONGEST signature_in_table
;
12424 signature_in_table
=
12425 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12426 if (signature_in_table
== signature
)
12428 uint32_t unit_index
=
12429 read_4_bytes (dbfd
,
12430 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12432 if (dwp_file
->version
== 1)
12434 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
12435 dwp_file
, unit_index
,
12436 comp_dir
, signature
,
12441 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
12442 dwp_file
, unit_index
,
12443 comp_dir
, signature
,
12446 return (struct dwo_unit
*) *slot
;
12448 if (signature_in_table
== 0)
12450 hash
= (hash
+ hash2
) & mask
;
12453 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12454 " [in module %s]"),
12458 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12459 Open the file specified by FILE_NAME and hand it off to BFD for
12460 preliminary analysis. Return a newly initialized bfd *, which
12461 includes a canonicalized copy of FILE_NAME.
12462 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12463 SEARCH_CWD is true if the current directory is to be searched.
12464 It will be searched before debug-file-directory.
12465 If successful, the file is added to the bfd include table of the
12466 objfile's bfd (see gdb_bfd_record_inclusion).
12467 If unable to find/open the file, return NULL.
12468 NOTE: This function is derived from symfile_bfd_open. */
12470 static gdb_bfd_ref_ptr
12471 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12472 const char *file_name
, int is_dwp
, int search_cwd
)
12475 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12476 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12477 to debug_file_directory. */
12478 const char *search_path
;
12479 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12481 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12484 if (*debug_file_directory
!= '\0')
12486 search_path_holder
.reset (concat (".", dirname_separator_string
,
12487 debug_file_directory
,
12489 search_path
= search_path_holder
.get ();
12495 search_path
= debug_file_directory
;
12497 openp_flags flags
= OPF_RETURN_REALPATH
;
12499 flags
|= OPF_SEARCH_IN_PATH
;
12501 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12502 desc
= openp (search_path
, flags
, file_name
,
12503 O_RDONLY
| O_BINARY
, &absolute_name
);
12507 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12509 if (sym_bfd
== NULL
)
12511 bfd_set_cacheable (sym_bfd
.get (), 1);
12513 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12516 /* Success. Record the bfd as having been included by the objfile's bfd.
12517 This is important because things like demangled_names_hash lives in the
12518 objfile's per_bfd space and may have references to things like symbol
12519 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12520 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12525 /* Try to open DWO file FILE_NAME.
12526 COMP_DIR is the DW_AT_comp_dir attribute.
12527 The result is the bfd handle of the file.
12528 If there is a problem finding or opening the file, return NULL.
12529 Upon success, the canonicalized path of the file is stored in the bfd,
12530 same as symfile_bfd_open. */
12532 static gdb_bfd_ref_ptr
12533 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12534 const char *file_name
, const char *comp_dir
)
12536 if (IS_ABSOLUTE_PATH (file_name
))
12537 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12538 0 /*is_dwp*/, 0 /*search_cwd*/);
12540 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12542 if (comp_dir
!= NULL
)
12544 gdb::unique_xmalloc_ptr
<char> path_to_try
12545 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12547 /* NOTE: If comp_dir is a relative path, this will also try the
12548 search path, which seems useful. */
12549 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
12550 path_to_try
.get (),
12552 1 /*search_cwd*/));
12557 /* That didn't work, try debug-file-directory, which, despite its name,
12558 is a list of paths. */
12560 if (*debug_file_directory
== '\0')
12563 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12564 0 /*is_dwp*/, 1 /*search_cwd*/);
12567 /* This function is mapped across the sections and remembers the offset and
12568 size of each of the DWO debugging sections we are interested in. */
12571 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12573 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12574 const struct dwop_section_names
*names
= &dwop_section_names
;
12576 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12578 dwo_sections
->abbrev
.s
.section
= sectp
;
12579 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12581 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12583 dwo_sections
->info
.s
.section
= sectp
;
12584 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12586 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12588 dwo_sections
->line
.s
.section
= sectp
;
12589 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12591 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12593 dwo_sections
->loc
.s
.section
= sectp
;
12594 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12596 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12598 dwo_sections
->macinfo
.s
.section
= sectp
;
12599 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12601 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12603 dwo_sections
->macro
.s
.section
= sectp
;
12604 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12606 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12608 dwo_sections
->str
.s
.section
= sectp
;
12609 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12611 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12613 dwo_sections
->str_offsets
.s
.section
= sectp
;
12614 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12616 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12618 struct dwarf2_section_info type_section
;
12620 memset (&type_section
, 0, sizeof (type_section
));
12621 type_section
.s
.section
= sectp
;
12622 type_section
.size
= bfd_section_size (sectp
);
12623 dwo_sections
->types
.push_back (type_section
);
12627 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12628 by PER_CU. This is for the non-DWP case.
12629 The result is NULL if DWO_NAME can't be found. */
12631 static struct dwo_file
*
12632 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
12633 const char *dwo_name
, const char *comp_dir
)
12635 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
12637 gdb_bfd_ref_ptr dbfd
= open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
);
12640 if (dwarf_read_debug
)
12641 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
12645 dwo_file_up
dwo_file (new struct dwo_file
);
12646 dwo_file
->dwo_name
= dwo_name
;
12647 dwo_file
->comp_dir
= comp_dir
;
12648 dwo_file
->dbfd
= std::move (dbfd
);
12650 bfd_map_over_sections (dwo_file
->dbfd
.get (), dwarf2_locate_dwo_sections
,
12651 &dwo_file
->sections
);
12653 create_cus_hash_table (dwarf2_per_objfile
, per_cu
->cu
, *dwo_file
,
12654 dwo_file
->sections
.info
, dwo_file
->cus
);
12656 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
.get (),
12657 dwo_file
->sections
.types
, dwo_file
->tus
);
12659 if (dwarf_read_debug
)
12660 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
12662 return dwo_file
.release ();
12665 /* This function is mapped across the sections and remembers the offset and
12666 size of each of the DWP debugging sections common to version 1 and 2 that
12667 we are interested in. */
12670 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12671 void *dwp_file_ptr
)
12673 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12674 const struct dwop_section_names
*names
= &dwop_section_names
;
12675 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12677 /* Record the ELF section number for later lookup: this is what the
12678 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12679 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12680 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12682 /* Look for specific sections that we need. */
12683 if (section_is_p (sectp
->name
, &names
->str_dwo
))
12685 dwp_file
->sections
.str
.s
.section
= sectp
;
12686 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12688 else if (section_is_p (sectp
->name
, &names
->cu_index
))
12690 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12691 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12693 else if (section_is_p (sectp
->name
, &names
->tu_index
))
12695 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12696 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12700 /* This function is mapped across the sections and remembers the offset and
12701 size of each of the DWP version 2 debugging sections that we are interested
12702 in. This is split into a separate function because we don't know if we
12703 have version 1 or 2 until we parse the cu_index/tu_index sections. */
12706 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12708 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12709 const struct dwop_section_names
*names
= &dwop_section_names
;
12710 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12712 /* Record the ELF section number for later lookup: this is what the
12713 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12714 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12715 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12717 /* Look for specific sections that we need. */
12718 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12720 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12721 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12723 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12725 dwp_file
->sections
.info
.s
.section
= sectp
;
12726 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12728 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12730 dwp_file
->sections
.line
.s
.section
= sectp
;
12731 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12733 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12735 dwp_file
->sections
.loc
.s
.section
= sectp
;
12736 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12738 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12740 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12741 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12743 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12745 dwp_file
->sections
.macro
.s
.section
= sectp
;
12746 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12748 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12750 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12751 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12753 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12755 dwp_file
->sections
.types
.s
.section
= sectp
;
12756 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12760 /* Hash function for dwp_file loaded CUs/TUs. */
12763 hash_dwp_loaded_cutus (const void *item
)
12765 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12767 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12768 return dwo_unit
->signature
;
12771 /* Equality function for dwp_file loaded CUs/TUs. */
12774 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12776 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12777 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12779 return dua
->signature
== dub
->signature
;
12782 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12785 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
12787 return htab_create_alloc_ex (3,
12788 hash_dwp_loaded_cutus
,
12789 eq_dwp_loaded_cutus
,
12791 &objfile
->objfile_obstack
,
12792 hashtab_obstack_allocate
,
12793 dummy_obstack_deallocate
);
12796 /* Try to open DWP file FILE_NAME.
12797 The result is the bfd handle of the file.
12798 If there is a problem finding or opening the file, return NULL.
12799 Upon success, the canonicalized path of the file is stored in the bfd,
12800 same as symfile_bfd_open. */
12802 static gdb_bfd_ref_ptr
12803 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12804 const char *file_name
)
12806 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12808 1 /*search_cwd*/));
12812 /* Work around upstream bug 15652.
12813 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12814 [Whether that's a "bug" is debatable, but it is getting in our way.]
12815 We have no real idea where the dwp file is, because gdb's realpath-ing
12816 of the executable's path may have discarded the needed info.
12817 [IWBN if the dwp file name was recorded in the executable, akin to
12818 .gnu_debuglink, but that doesn't exist yet.]
12819 Strip the directory from FILE_NAME and search again. */
12820 if (*debug_file_directory
!= '\0')
12822 /* Don't implicitly search the current directory here.
12823 If the user wants to search "." to handle this case,
12824 it must be added to debug-file-directory. */
12825 return try_open_dwop_file (dwarf2_per_objfile
,
12826 lbasename (file_name
), 1 /*is_dwp*/,
12833 /* Initialize the use of the DWP file for the current objfile.
12834 By convention the name of the DWP file is ${objfile}.dwp.
12835 The result is NULL if it can't be found. */
12837 static std::unique_ptr
<struct dwp_file
>
12838 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12840 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12842 /* Try to find first .dwp for the binary file before any symbolic links
12845 /* If the objfile is a debug file, find the name of the real binary
12846 file and get the name of dwp file from there. */
12847 std::string dwp_name
;
12848 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
12850 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
12851 const char *backlink_basename
= lbasename (backlink
->original_name
);
12853 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
12856 dwp_name
= objfile
->original_name
;
12858 dwp_name
+= ".dwp";
12860 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
12862 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
12864 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
12865 dwp_name
= objfile_name (objfile
);
12866 dwp_name
+= ".dwp";
12867 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
12872 if (dwarf_read_debug
)
12873 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
12874 return std::unique_ptr
<dwp_file
> ();
12877 const char *name
= bfd_get_filename (dbfd
.get ());
12878 std::unique_ptr
<struct dwp_file
> dwp_file
12879 (new struct dwp_file (name
, std::move (dbfd
)));
12881 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
12882 dwp_file
->elf_sections
=
12883 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
12884 dwp_file
->num_sections
, asection
*);
12886 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12887 dwarf2_locate_common_dwp_sections
,
12890 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12893 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12896 /* The DWP file version is stored in the hash table. Oh well. */
12897 if (dwp_file
->cus
&& dwp_file
->tus
12898 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
12900 /* Technically speaking, we should try to limp along, but this is
12901 pretty bizarre. We use pulongest here because that's the established
12902 portability solution (e.g, we cannot use %u for uint32_t). */
12903 error (_("Dwarf Error: DWP file CU version %s doesn't match"
12904 " TU version %s [in DWP file %s]"),
12905 pulongest (dwp_file
->cus
->version
),
12906 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
12910 dwp_file
->version
= dwp_file
->cus
->version
;
12911 else if (dwp_file
->tus
)
12912 dwp_file
->version
= dwp_file
->tus
->version
;
12914 dwp_file
->version
= 2;
12916 if (dwp_file
->version
== 2)
12917 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12918 dwarf2_locate_v2_dwp_sections
,
12921 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table (objfile
);
12922 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table (objfile
);
12924 if (dwarf_read_debug
)
12926 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
12927 fprintf_unfiltered (gdb_stdlog
,
12928 " %s CUs, %s TUs\n",
12929 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
12930 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
12936 /* Wrapper around open_and_init_dwp_file, only open it once. */
12938 static struct dwp_file
*
12939 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12941 if (! dwarf2_per_objfile
->dwp_checked
)
12943 dwarf2_per_objfile
->dwp_file
12944 = open_and_init_dwp_file (dwarf2_per_objfile
);
12945 dwarf2_per_objfile
->dwp_checked
= 1;
12947 return dwarf2_per_objfile
->dwp_file
.get ();
12950 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
12951 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
12952 or in the DWP file for the objfile, referenced by THIS_UNIT.
12953 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
12954 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
12956 This is called, for example, when wanting to read a variable with a
12957 complex location. Therefore we don't want to do file i/o for every call.
12958 Therefore we don't want to look for a DWO file on every call.
12959 Therefore we first see if we've already seen SIGNATURE in a DWP file,
12960 then we check if we've already seen DWO_NAME, and only THEN do we check
12963 The result is a pointer to the dwo_unit object or NULL if we didn't find it
12964 (dwo_id mismatch or couldn't find the DWO/DWP file). */
12966 static struct dwo_unit
*
12967 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
12968 const char *dwo_name
, const char *comp_dir
,
12969 ULONGEST signature
, int is_debug_types
)
12971 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_unit
->dwarf2_per_objfile
;
12972 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12973 const char *kind
= is_debug_types
? "TU" : "CU";
12974 void **dwo_file_slot
;
12975 struct dwo_file
*dwo_file
;
12976 struct dwp_file
*dwp_file
;
12978 /* First see if there's a DWP file.
12979 If we have a DWP file but didn't find the DWO inside it, don't
12980 look for the original DWO file. It makes gdb behave differently
12981 depending on whether one is debugging in the build tree. */
12983 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
12984 if (dwp_file
!= NULL
)
12986 const struct dwp_hash_table
*dwp_htab
=
12987 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12989 if (dwp_htab
!= NULL
)
12991 struct dwo_unit
*dwo_cutu
=
12992 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
12993 signature
, is_debug_types
);
12995 if (dwo_cutu
!= NULL
)
12997 if (dwarf_read_debug
)
12999 fprintf_unfiltered (gdb_stdlog
,
13000 "Virtual DWO %s %s found: @%s\n",
13001 kind
, hex_string (signature
),
13002 host_address_to_string (dwo_cutu
));
13010 /* No DWP file, look for the DWO file. */
13012 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
13013 dwo_name
, comp_dir
);
13014 if (*dwo_file_slot
== NULL
)
13016 /* Read in the file and build a table of the CUs/TUs it contains. */
13017 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
13019 /* NOTE: This will be NULL if unable to open the file. */
13020 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
13022 if (dwo_file
!= NULL
)
13024 struct dwo_unit
*dwo_cutu
= NULL
;
13026 if (is_debug_types
&& dwo_file
->tus
)
13028 struct dwo_unit find_dwo_cutu
;
13030 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13031 find_dwo_cutu
.signature
= signature
;
13033 = (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_cutu
);
13035 else if (!is_debug_types
&& dwo_file
->cus
)
13037 struct dwo_unit find_dwo_cutu
;
13039 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13040 find_dwo_cutu
.signature
= signature
;
13041 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
,
13045 if (dwo_cutu
!= NULL
)
13047 if (dwarf_read_debug
)
13049 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
13050 kind
, dwo_name
, hex_string (signature
),
13051 host_address_to_string (dwo_cutu
));
13058 /* We didn't find it. This could mean a dwo_id mismatch, or
13059 someone deleted the DWO/DWP file, or the search path isn't set up
13060 correctly to find the file. */
13062 if (dwarf_read_debug
)
13064 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
13065 kind
, dwo_name
, hex_string (signature
));
13068 /* This is a warning and not a complaint because it can be caused by
13069 pilot error (e.g., user accidentally deleting the DWO). */
13071 /* Print the name of the DWP file if we looked there, helps the user
13072 better diagnose the problem. */
13073 std::string dwp_text
;
13075 if (dwp_file
!= NULL
)
13076 dwp_text
= string_printf (" [in DWP file %s]",
13077 lbasename (dwp_file
->name
));
13079 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
13080 " [in module %s]"),
13081 kind
, dwo_name
, hex_string (signature
),
13083 this_unit
->is_debug_types
? "TU" : "CU",
13084 sect_offset_str (this_unit
->sect_off
), objfile_name (objfile
));
13089 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
13090 See lookup_dwo_cutu_unit for details. */
13092 static struct dwo_unit
*
13093 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
13094 const char *dwo_name
, const char *comp_dir
,
13095 ULONGEST signature
)
13097 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
13100 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
13101 See lookup_dwo_cutu_unit for details. */
13103 static struct dwo_unit
*
13104 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
13105 const char *dwo_name
, const char *comp_dir
)
13107 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
13110 /* Traversal function for queue_and_load_all_dwo_tus. */
13113 queue_and_load_dwo_tu (void **slot
, void *info
)
13115 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
13116 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
13117 ULONGEST signature
= dwo_unit
->signature
;
13118 struct signatured_type
*sig_type
=
13119 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
13121 if (sig_type
!= NULL
)
13123 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
13125 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
13126 a real dependency of PER_CU on SIG_TYPE. That is detected later
13127 while processing PER_CU. */
13128 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
13129 load_full_type_unit (sig_cu
);
13130 per_cu
->imported_symtabs_push (sig_cu
);
13136 /* Queue all TUs contained in the DWO of PER_CU to be read in.
13137 The DWO may have the only definition of the type, though it may not be
13138 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
13139 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
13142 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
13144 struct dwo_unit
*dwo_unit
;
13145 struct dwo_file
*dwo_file
;
13147 gdb_assert (!per_cu
->is_debug_types
);
13148 gdb_assert (get_dwp_file (per_cu
->dwarf2_per_objfile
) == NULL
);
13149 gdb_assert (per_cu
->cu
!= NULL
);
13151 dwo_unit
= per_cu
->cu
->dwo_unit
;
13152 gdb_assert (dwo_unit
!= NULL
);
13154 dwo_file
= dwo_unit
->dwo_file
;
13155 if (dwo_file
->tus
!= NULL
)
13156 htab_traverse_noresize (dwo_file
->tus
, queue_and_load_dwo_tu
, per_cu
);
13159 /* Read in various DIEs. */
13161 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
13162 Inherit only the children of the DW_AT_abstract_origin DIE not being
13163 already referenced by DW_AT_abstract_origin from the children of the
13167 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
13169 struct die_info
*child_die
;
13170 sect_offset
*offsetp
;
13171 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
13172 struct die_info
*origin_die
;
13173 /* Iterator of the ORIGIN_DIE children. */
13174 struct die_info
*origin_child_die
;
13175 struct attribute
*attr
;
13176 struct dwarf2_cu
*origin_cu
;
13177 struct pending
**origin_previous_list_in_scope
;
13179 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13183 /* Note that following die references may follow to a die in a
13187 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
13189 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
13191 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
13192 origin_cu
->list_in_scope
= cu
->list_in_scope
;
13194 if (die
->tag
!= origin_die
->tag
13195 && !(die
->tag
== DW_TAG_inlined_subroutine
13196 && origin_die
->tag
== DW_TAG_subprogram
))
13197 complaint (_("DIE %s and its abstract origin %s have different tags"),
13198 sect_offset_str (die
->sect_off
),
13199 sect_offset_str (origin_die
->sect_off
));
13201 std::vector
<sect_offset
> offsets
;
13203 for (child_die
= die
->child
;
13204 child_die
&& child_die
->tag
;
13205 child_die
= sibling_die (child_die
))
13207 struct die_info
*child_origin_die
;
13208 struct dwarf2_cu
*child_origin_cu
;
13210 /* We are trying to process concrete instance entries:
13211 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
13212 it's not relevant to our analysis here. i.e. detecting DIEs that are
13213 present in the abstract instance but not referenced in the concrete
13215 if (child_die
->tag
== DW_TAG_call_site
13216 || child_die
->tag
== DW_TAG_GNU_call_site
)
13219 /* For each CHILD_DIE, find the corresponding child of
13220 ORIGIN_DIE. If there is more than one layer of
13221 DW_AT_abstract_origin, follow them all; there shouldn't be,
13222 but GCC versions at least through 4.4 generate this (GCC PR
13224 child_origin_die
= child_die
;
13225 child_origin_cu
= cu
;
13228 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
13232 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
13236 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
13237 counterpart may exist. */
13238 if (child_origin_die
!= child_die
)
13240 if (child_die
->tag
!= child_origin_die
->tag
13241 && !(child_die
->tag
== DW_TAG_inlined_subroutine
13242 && child_origin_die
->tag
== DW_TAG_subprogram
))
13243 complaint (_("Child DIE %s and its abstract origin %s have "
13245 sect_offset_str (child_die
->sect_off
),
13246 sect_offset_str (child_origin_die
->sect_off
));
13247 if (child_origin_die
->parent
!= origin_die
)
13248 complaint (_("Child DIE %s and its abstract origin %s have "
13249 "different parents"),
13250 sect_offset_str (child_die
->sect_off
),
13251 sect_offset_str (child_origin_die
->sect_off
));
13253 offsets
.push_back (child_origin_die
->sect_off
);
13256 std::sort (offsets
.begin (), offsets
.end ());
13257 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
13258 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
13259 if (offsetp
[-1] == *offsetp
)
13260 complaint (_("Multiple children of DIE %s refer "
13261 "to DIE %s as their abstract origin"),
13262 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
13264 offsetp
= offsets
.data ();
13265 origin_child_die
= origin_die
->child
;
13266 while (origin_child_die
&& origin_child_die
->tag
)
13268 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13269 while (offsetp
< offsets_end
13270 && *offsetp
< origin_child_die
->sect_off
)
13272 if (offsetp
>= offsets_end
13273 || *offsetp
> origin_child_die
->sect_off
)
13275 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13276 Check whether we're already processing ORIGIN_CHILD_DIE.
13277 This can happen with mutually referenced abstract_origins.
13279 if (!origin_child_die
->in_process
)
13280 process_die (origin_child_die
, origin_cu
);
13282 origin_child_die
= sibling_die (origin_child_die
);
13284 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13286 if (cu
!= origin_cu
)
13287 compute_delayed_physnames (origin_cu
);
13291 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13293 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13294 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13295 struct context_stack
*newobj
;
13298 struct die_info
*child_die
;
13299 struct attribute
*attr
, *call_line
, *call_file
;
13301 CORE_ADDR baseaddr
;
13302 struct block
*block
;
13303 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13304 std::vector
<struct symbol
*> template_args
;
13305 struct template_symbol
*templ_func
= NULL
;
13309 /* If we do not have call site information, we can't show the
13310 caller of this inlined function. That's too confusing, so
13311 only use the scope for local variables. */
13312 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13313 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13314 if (call_line
== NULL
|| call_file
== NULL
)
13316 read_lexical_block_scope (die
, cu
);
13321 baseaddr
= objfile
->text_section_offset ();
13323 name
= dwarf2_name (die
, cu
);
13325 /* Ignore functions with missing or empty names. These are actually
13326 illegal according to the DWARF standard. */
13329 complaint (_("missing name for subprogram DIE at %s"),
13330 sect_offset_str (die
->sect_off
));
13334 /* Ignore functions with missing or invalid low and high pc attributes. */
13335 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13336 <= PC_BOUNDS_INVALID
)
13338 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13339 if (!attr
|| !DW_UNSND (attr
))
13340 complaint (_("cannot get low and high bounds "
13341 "for subprogram DIE at %s"),
13342 sect_offset_str (die
->sect_off
));
13346 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13347 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13349 /* If we have any template arguments, then we must allocate a
13350 different sort of symbol. */
13351 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
13353 if (child_die
->tag
== DW_TAG_template_type_param
13354 || child_die
->tag
== DW_TAG_template_value_param
)
13356 templ_func
= allocate_template_symbol (objfile
);
13357 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13362 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13363 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13364 (struct symbol
*) templ_func
);
13366 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13367 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
13370 /* If there is a location expression for DW_AT_frame_base, record
13372 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13373 if (attr
!= nullptr)
13374 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13376 /* If there is a location for the static link, record it. */
13377 newobj
->static_link
= NULL
;
13378 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13379 if (attr
!= nullptr)
13381 newobj
->static_link
13382 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13383 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13384 dwarf2_per_cu_addr_type (cu
->per_cu
));
13387 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13389 if (die
->child
!= NULL
)
13391 child_die
= die
->child
;
13392 while (child_die
&& child_die
->tag
)
13394 if (child_die
->tag
== DW_TAG_template_type_param
13395 || child_die
->tag
== DW_TAG_template_value_param
)
13397 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13400 template_args
.push_back (arg
);
13403 process_die (child_die
, cu
);
13404 child_die
= sibling_die (child_die
);
13408 inherit_abstract_dies (die
, cu
);
13410 /* If we have a DW_AT_specification, we might need to import using
13411 directives from the context of the specification DIE. See the
13412 comment in determine_prefix. */
13413 if (cu
->language
== language_cplus
13414 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13416 struct dwarf2_cu
*spec_cu
= cu
;
13417 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13421 child_die
= spec_die
->child
;
13422 while (child_die
&& child_die
->tag
)
13424 if (child_die
->tag
== DW_TAG_imported_module
)
13425 process_die (child_die
, spec_cu
);
13426 child_die
= sibling_die (child_die
);
13429 /* In some cases, GCC generates specification DIEs that
13430 themselves contain DW_AT_specification attributes. */
13431 spec_die
= die_specification (spec_die
, &spec_cu
);
13435 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13436 /* Make a block for the local symbols within. */
13437 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13438 cstk
.static_link
, lowpc
, highpc
);
13440 /* For C++, set the block's scope. */
13441 if ((cu
->language
== language_cplus
13442 || cu
->language
== language_fortran
13443 || cu
->language
== language_d
13444 || cu
->language
== language_rust
)
13445 && cu
->processing_has_namespace_info
)
13446 block_set_scope (block
, determine_prefix (die
, cu
),
13447 &objfile
->objfile_obstack
);
13449 /* If we have address ranges, record them. */
13450 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13452 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13454 /* Attach template arguments to function. */
13455 if (!template_args
.empty ())
13457 gdb_assert (templ_func
!= NULL
);
13459 templ_func
->n_template_arguments
= template_args
.size ();
13460 templ_func
->template_arguments
13461 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13462 templ_func
->n_template_arguments
);
13463 memcpy (templ_func
->template_arguments
,
13464 template_args
.data (),
13465 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13467 /* Make sure that the symtab is set on the new symbols. Even
13468 though they don't appear in this symtab directly, other parts
13469 of gdb assume that symbols do, and this is reasonably
13471 for (symbol
*sym
: template_args
)
13472 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13475 /* In C++, we can have functions nested inside functions (e.g., when
13476 a function declares a class that has methods). This means that
13477 when we finish processing a function scope, we may need to go
13478 back to building a containing block's symbol lists. */
13479 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13480 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13482 /* If we've finished processing a top-level function, subsequent
13483 symbols go in the file symbol list. */
13484 if (cu
->get_builder ()->outermost_context_p ())
13485 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13488 /* Process all the DIES contained within a lexical block scope. Start
13489 a new scope, process the dies, and then close the scope. */
13492 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13494 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13495 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13496 CORE_ADDR lowpc
, highpc
;
13497 struct die_info
*child_die
;
13498 CORE_ADDR baseaddr
;
13500 baseaddr
= objfile
->text_section_offset ();
13502 /* Ignore blocks with missing or invalid low and high pc attributes. */
13503 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13504 as multiple lexical blocks? Handling children in a sane way would
13505 be nasty. Might be easier to properly extend generic blocks to
13506 describe ranges. */
13507 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13509 case PC_BOUNDS_NOT_PRESENT
:
13510 /* DW_TAG_lexical_block has no attributes, process its children as if
13511 there was no wrapping by that DW_TAG_lexical_block.
13512 GCC does no longer produces such DWARF since GCC r224161. */
13513 for (child_die
= die
->child
;
13514 child_die
!= NULL
&& child_die
->tag
;
13515 child_die
= sibling_die (child_die
))
13516 process_die (child_die
, cu
);
13518 case PC_BOUNDS_INVALID
:
13521 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13522 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13524 cu
->get_builder ()->push_context (0, lowpc
);
13525 if (die
->child
!= NULL
)
13527 child_die
= die
->child
;
13528 while (child_die
&& child_die
->tag
)
13530 process_die (child_die
, cu
);
13531 child_die
= sibling_die (child_die
);
13534 inherit_abstract_dies (die
, cu
);
13535 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13537 if (*cu
->get_builder ()->get_local_symbols () != NULL
13538 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13540 struct block
*block
13541 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13542 cstk
.start_addr
, highpc
);
13544 /* Note that recording ranges after traversing children, as we
13545 do here, means that recording a parent's ranges entails
13546 walking across all its children's ranges as they appear in
13547 the address map, which is quadratic behavior.
13549 It would be nicer to record the parent's ranges before
13550 traversing its children, simply overriding whatever you find
13551 there. But since we don't even decide whether to create a
13552 block until after we've traversed its children, that's hard
13554 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13556 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13557 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13560 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13563 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13565 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13566 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13567 CORE_ADDR pc
, baseaddr
;
13568 struct attribute
*attr
;
13569 struct call_site
*call_site
, call_site_local
;
13572 struct die_info
*child_die
;
13574 baseaddr
= objfile
->text_section_offset ();
13576 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13579 /* This was a pre-DWARF-5 GNU extension alias
13580 for DW_AT_call_return_pc. */
13581 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13585 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13586 "DIE %s [in module %s]"),
13587 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13590 pc
= attr
->value_as_address () + baseaddr
;
13591 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13593 if (cu
->call_site_htab
== NULL
)
13594 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13595 NULL
, &objfile
->objfile_obstack
,
13596 hashtab_obstack_allocate
, NULL
);
13597 call_site_local
.pc
= pc
;
13598 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13601 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13602 "DIE %s [in module %s]"),
13603 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13604 objfile_name (objfile
));
13608 /* Count parameters at the caller. */
13611 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13612 child_die
= sibling_die (child_die
))
13614 if (child_die
->tag
!= DW_TAG_call_site_parameter
13615 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13617 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13618 "DW_TAG_call_site child DIE %s [in module %s]"),
13619 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13620 objfile_name (objfile
));
13628 = ((struct call_site
*)
13629 obstack_alloc (&objfile
->objfile_obstack
,
13630 sizeof (*call_site
)
13631 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13633 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13634 call_site
->pc
= pc
;
13636 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13637 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13639 struct die_info
*func_die
;
13641 /* Skip also over DW_TAG_inlined_subroutine. */
13642 for (func_die
= die
->parent
;
13643 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13644 && func_die
->tag
!= DW_TAG_subroutine_type
;
13645 func_die
= func_die
->parent
);
13647 /* DW_AT_call_all_calls is a superset
13648 of DW_AT_call_all_tail_calls. */
13650 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13651 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13652 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13653 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13655 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13656 not complete. But keep CALL_SITE for look ups via call_site_htab,
13657 both the initial caller containing the real return address PC and
13658 the final callee containing the current PC of a chain of tail
13659 calls do not need to have the tail call list complete. But any
13660 function candidate for a virtual tail call frame searched via
13661 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13662 determined unambiguously. */
13666 struct type
*func_type
= NULL
;
13669 func_type
= get_die_type (func_die
, cu
);
13670 if (func_type
!= NULL
)
13672 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
13674 /* Enlist this call site to the function. */
13675 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13676 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13679 complaint (_("Cannot find function owning DW_TAG_call_site "
13680 "DIE %s [in module %s]"),
13681 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13685 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13687 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13689 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13692 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13693 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13695 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13696 if (!attr
|| (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0))
13697 /* Keep NULL DWARF_BLOCK. */;
13698 else if (attr
->form_is_block ())
13700 struct dwarf2_locexpr_baton
*dlbaton
;
13702 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13703 dlbaton
->data
= DW_BLOCK (attr
)->data
;
13704 dlbaton
->size
= DW_BLOCK (attr
)->size
;
13705 dlbaton
->per_cu
= cu
->per_cu
;
13707 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13709 else if (attr
->form_is_ref ())
13711 struct dwarf2_cu
*target_cu
= cu
;
13712 struct die_info
*target_die
;
13714 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13715 gdb_assert (target_cu
->per_cu
->dwarf2_per_objfile
->objfile
== objfile
);
13716 if (die_is_declaration (target_die
, target_cu
))
13718 const char *target_physname
;
13720 /* Prefer the mangled name; otherwise compute the demangled one. */
13721 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13722 if (target_physname
== NULL
)
13723 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13724 if (target_physname
== NULL
)
13725 complaint (_("DW_AT_call_target target DIE has invalid "
13726 "physname, for referencing DIE %s [in module %s]"),
13727 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13729 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13735 /* DW_AT_entry_pc should be preferred. */
13736 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13737 <= PC_BOUNDS_INVALID
)
13738 complaint (_("DW_AT_call_target target DIE has invalid "
13739 "low pc, for referencing DIE %s [in module %s]"),
13740 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13743 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13744 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
13749 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13750 "block nor reference, for DIE %s [in module %s]"),
13751 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13753 call_site
->per_cu
= cu
->per_cu
;
13755 for (child_die
= die
->child
;
13756 child_die
&& child_die
->tag
;
13757 child_die
= sibling_die (child_die
))
13759 struct call_site_parameter
*parameter
;
13760 struct attribute
*loc
, *origin
;
13762 if (child_die
->tag
!= DW_TAG_call_site_parameter
13763 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13765 /* Already printed the complaint above. */
13769 gdb_assert (call_site
->parameter_count
< nparams
);
13770 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13772 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13773 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13774 register is contained in DW_AT_call_value. */
13776 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13777 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13778 if (origin
== NULL
)
13780 /* This was a pre-DWARF-5 GNU extension alias
13781 for DW_AT_call_parameter. */
13782 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13784 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
13786 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13788 sect_offset sect_off
13789 = (sect_offset
) dwarf2_get_ref_die_offset (origin
);
13790 if (!offset_in_cu_p (&cu
->header
, sect_off
))
13792 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13793 binding can be done only inside one CU. Such referenced DIE
13794 therefore cannot be even moved to DW_TAG_partial_unit. */
13795 complaint (_("DW_AT_call_parameter offset is not in CU for "
13796 "DW_TAG_call_site child DIE %s [in module %s]"),
13797 sect_offset_str (child_die
->sect_off
),
13798 objfile_name (objfile
));
13801 parameter
->u
.param_cu_off
13802 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13804 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
13806 complaint (_("No DW_FORM_block* DW_AT_location for "
13807 "DW_TAG_call_site child DIE %s [in module %s]"),
13808 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13813 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13814 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
13815 if (parameter
->u
.dwarf_reg
!= -1)
13816 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13817 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
13818 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
13819 ¶meter
->u
.fb_offset
))
13820 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13823 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13824 "for DW_FORM_block* DW_AT_location is supported for "
13825 "DW_TAG_call_site child DIE %s "
13827 sect_offset_str (child_die
->sect_off
),
13828 objfile_name (objfile
));
13833 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13835 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13836 if (attr
== NULL
|| !attr
->form_is_block ())
13838 complaint (_("No DW_FORM_block* DW_AT_call_value for "
13839 "DW_TAG_call_site child DIE %s [in module %s]"),
13840 sect_offset_str (child_die
->sect_off
),
13841 objfile_name (objfile
));
13844 parameter
->value
= DW_BLOCK (attr
)->data
;
13845 parameter
->value_size
= DW_BLOCK (attr
)->size
;
13847 /* Parameters are not pre-cleared by memset above. */
13848 parameter
->data_value
= NULL
;
13849 parameter
->data_value_size
= 0;
13850 call_site
->parameter_count
++;
13852 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
13854 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
13855 if (attr
!= nullptr)
13857 if (!attr
->form_is_block ())
13858 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
13859 "DW_TAG_call_site child DIE %s [in module %s]"),
13860 sect_offset_str (child_die
->sect_off
),
13861 objfile_name (objfile
));
13864 parameter
->data_value
= DW_BLOCK (attr
)->data
;
13865 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
13871 /* Helper function for read_variable. If DIE represents a virtual
13872 table, then return the type of the concrete object that is
13873 associated with the virtual table. Otherwise, return NULL. */
13875 static struct type
*
13876 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13878 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13882 /* Find the type DIE. */
13883 struct die_info
*type_die
= NULL
;
13884 struct dwarf2_cu
*type_cu
= cu
;
13886 if (attr
->form_is_ref ())
13887 type_die
= follow_die_ref (die
, attr
, &type_cu
);
13888 if (type_die
== NULL
)
13891 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
13893 return die_containing_type (type_die
, type_cu
);
13896 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
13899 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
13901 struct rust_vtable_symbol
*storage
= NULL
;
13903 if (cu
->language
== language_rust
)
13905 struct type
*containing_type
= rust_containing_type (die
, cu
);
13907 if (containing_type
!= NULL
)
13909 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13911 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol ();
13912 initialize_objfile_symbol (storage
);
13913 storage
->concrete_type
= containing_type
;
13914 storage
->subclass
= SYMBOL_RUST_VTABLE
;
13918 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
13919 struct attribute
*abstract_origin
13920 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13921 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
13922 if (res
== NULL
&& loc
&& abstract_origin
)
13924 /* We have a variable without a name, but with a location and an abstract
13925 origin. This may be a concrete instance of an abstract variable
13926 referenced from an DW_OP_GNU_variable_value, so save it to find it back
13928 struct dwarf2_cu
*origin_cu
= cu
;
13929 struct die_info
*origin_die
13930 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
13931 dwarf2_per_objfile
*dpo
= cu
->per_cu
->dwarf2_per_objfile
;
13932 dpo
->abstract_to_concrete
[origin_die
->sect_off
].push_back (die
->sect_off
);
13936 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
13937 reading .debug_rnglists.
13938 Callback's type should be:
13939 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13940 Return true if the attributes are present and valid, otherwise,
13943 template <typename Callback
>
13945 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
13946 Callback
&&callback
)
13948 struct dwarf2_per_objfile
*dwarf2_per_objfile
13949 = cu
->per_cu
->dwarf2_per_objfile
;
13950 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13951 bfd
*obfd
= objfile
->obfd
;
13952 /* Base address selection entry. */
13955 const gdb_byte
*buffer
;
13956 CORE_ADDR baseaddr
;
13957 bool overflow
= false;
13959 found_base
= cu
->base_known
;
13960 base
= cu
->base_address
;
13962 dwarf2_per_objfile
->rnglists
.read (objfile
);
13963 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
13965 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13969 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
13971 baseaddr
= objfile
->text_section_offset ();
13975 /* Initialize it due to a false compiler warning. */
13976 CORE_ADDR range_beginning
= 0, range_end
= 0;
13977 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
13978 + dwarf2_per_objfile
->rnglists
.size
);
13979 unsigned int bytes_read
;
13981 if (buffer
== buf_end
)
13986 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
13989 case DW_RLE_end_of_list
:
13991 case DW_RLE_base_address
:
13992 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13997 base
= read_address (obfd
, buffer
, cu
, &bytes_read
);
13999 buffer
+= bytes_read
;
14001 case DW_RLE_start_length
:
14002 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14007 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14008 buffer
+= bytes_read
;
14009 range_end
= (range_beginning
14010 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
14011 buffer
+= bytes_read
;
14012 if (buffer
> buf_end
)
14018 case DW_RLE_offset_pair
:
14019 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14020 buffer
+= bytes_read
;
14021 if (buffer
> buf_end
)
14026 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14027 buffer
+= bytes_read
;
14028 if (buffer
> buf_end
)
14034 case DW_RLE_start_end
:
14035 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
14040 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14041 buffer
+= bytes_read
;
14042 range_end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14043 buffer
+= bytes_read
;
14046 complaint (_("Invalid .debug_rnglists data (no base address)"));
14049 if (rlet
== DW_RLE_end_of_list
|| overflow
)
14051 if (rlet
== DW_RLE_base_address
)
14056 /* We have no valid base address for the ranges
14058 complaint (_("Invalid .debug_rnglists data (no base address)"));
14062 if (range_beginning
> range_end
)
14064 /* Inverted range entries are invalid. */
14065 complaint (_("Invalid .debug_rnglists data (inverted range)"));
14069 /* Empty range entries have no effect. */
14070 if (range_beginning
== range_end
)
14073 range_beginning
+= base
;
14076 /* A not-uncommon case of bad debug info.
14077 Don't pollute the addrmap with bad data. */
14078 if (range_beginning
+ baseaddr
== 0
14079 && !dwarf2_per_objfile
->has_section_at_zero
)
14081 complaint (_(".debug_rnglists entry has start address of zero"
14082 " [in module %s]"), objfile_name (objfile
));
14086 callback (range_beginning
, range_end
);
14091 complaint (_("Offset %d is not terminated "
14092 "for DW_AT_ranges attribute"),
14100 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
14101 Callback's type should be:
14102 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14103 Return 1 if the attributes are present and valid, otherwise, return 0. */
14105 template <typename Callback
>
14107 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
14108 Callback
&&callback
)
14110 struct dwarf2_per_objfile
*dwarf2_per_objfile
14111 = cu
->per_cu
->dwarf2_per_objfile
;
14112 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14113 struct comp_unit_head
*cu_header
= &cu
->header
;
14114 bfd
*obfd
= objfile
->obfd
;
14115 unsigned int addr_size
= cu_header
->addr_size
;
14116 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
14117 /* Base address selection entry. */
14120 unsigned int dummy
;
14121 const gdb_byte
*buffer
;
14122 CORE_ADDR baseaddr
;
14124 if (cu_header
->version
>= 5)
14125 return dwarf2_rnglists_process (offset
, cu
, callback
);
14127 found_base
= cu
->base_known
;
14128 base
= cu
->base_address
;
14130 dwarf2_per_objfile
->ranges
.read (objfile
);
14131 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
14133 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14137 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
14139 baseaddr
= objfile
->text_section_offset ();
14143 CORE_ADDR range_beginning
, range_end
;
14145 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
14146 buffer
+= addr_size
;
14147 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
14148 buffer
+= addr_size
;
14149 offset
+= 2 * addr_size
;
14151 /* An end of list marker is a pair of zero addresses. */
14152 if (range_beginning
== 0 && range_end
== 0)
14153 /* Found the end of list entry. */
14156 /* Each base address selection entry is a pair of 2 values.
14157 The first is the largest possible address, the second is
14158 the base address. Check for a base address here. */
14159 if ((range_beginning
& mask
) == mask
)
14161 /* If we found the largest possible address, then we already
14162 have the base address in range_end. */
14170 /* We have no valid base address for the ranges
14172 complaint (_("Invalid .debug_ranges data (no base address)"));
14176 if (range_beginning
> range_end
)
14178 /* Inverted range entries are invalid. */
14179 complaint (_("Invalid .debug_ranges data (inverted range)"));
14183 /* Empty range entries have no effect. */
14184 if (range_beginning
== range_end
)
14187 range_beginning
+= base
;
14190 /* A not-uncommon case of bad debug info.
14191 Don't pollute the addrmap with bad data. */
14192 if (range_beginning
+ baseaddr
== 0
14193 && !dwarf2_per_objfile
->has_section_at_zero
)
14195 complaint (_(".debug_ranges entry has start address of zero"
14196 " [in module %s]"), objfile_name (objfile
));
14200 callback (range_beginning
, range_end
);
14206 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
14207 Return 1 if the attributes are present and valid, otherwise, return 0.
14208 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
14211 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
14212 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
14213 dwarf2_psymtab
*ranges_pst
)
14215 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14216 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14217 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
14220 CORE_ADDR high
= 0;
14223 retval
= dwarf2_ranges_process (offset
, cu
,
14224 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
14226 if (ranges_pst
!= NULL
)
14231 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14232 range_beginning
+ baseaddr
)
14234 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14235 range_end
+ baseaddr
)
14237 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
14238 lowpc
, highpc
- 1, ranges_pst
);
14241 /* FIXME: This is recording everything as a low-high
14242 segment of consecutive addresses. We should have a
14243 data structure for discontiguous block ranges
14247 low
= range_beginning
;
14253 if (range_beginning
< low
)
14254 low
= range_beginning
;
14255 if (range_end
> high
)
14263 /* If the first entry is an end-of-list marker, the range
14264 describes an empty scope, i.e. no instructions. */
14270 *high_return
= high
;
14274 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14275 definition for the return value. *LOWPC and *HIGHPC are set iff
14276 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14278 static enum pc_bounds_kind
14279 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14280 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14281 dwarf2_psymtab
*pst
)
14283 struct dwarf2_per_objfile
*dwarf2_per_objfile
14284 = cu
->per_cu
->dwarf2_per_objfile
;
14285 struct attribute
*attr
;
14286 struct attribute
*attr_high
;
14288 CORE_ADDR high
= 0;
14289 enum pc_bounds_kind ret
;
14291 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14294 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14295 if (attr
!= nullptr)
14297 low
= attr
->value_as_address ();
14298 high
= attr_high
->value_as_address ();
14299 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14303 /* Found high w/o low attribute. */
14304 return PC_BOUNDS_INVALID
;
14306 /* Found consecutive range of addresses. */
14307 ret
= PC_BOUNDS_HIGH_LOW
;
14311 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14314 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14315 We take advantage of the fact that DW_AT_ranges does not appear
14316 in DW_TAG_compile_unit of DWO files. */
14317 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14318 unsigned int ranges_offset
= (DW_UNSND (attr
)
14319 + (need_ranges_base
14323 /* Value of the DW_AT_ranges attribute is the offset in the
14324 .debug_ranges section. */
14325 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
14326 return PC_BOUNDS_INVALID
;
14327 /* Found discontinuous range of addresses. */
14328 ret
= PC_BOUNDS_RANGES
;
14331 return PC_BOUNDS_NOT_PRESENT
;
14334 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14336 return PC_BOUNDS_INVALID
;
14338 /* When using the GNU linker, .gnu.linkonce. sections are used to
14339 eliminate duplicate copies of functions and vtables and such.
14340 The linker will arbitrarily choose one and discard the others.
14341 The AT_*_pc values for such functions refer to local labels in
14342 these sections. If the section from that file was discarded, the
14343 labels are not in the output, so the relocs get a value of 0.
14344 If this is a discarded function, mark the pc bounds as invalid,
14345 so that GDB will ignore it. */
14346 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
14347 return PC_BOUNDS_INVALID
;
14355 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14356 its low and high PC addresses. Do nothing if these addresses could not
14357 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14358 and HIGHPC to the high address if greater than HIGHPC. */
14361 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14362 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14363 struct dwarf2_cu
*cu
)
14365 CORE_ADDR low
, high
;
14366 struct die_info
*child
= die
->child
;
14368 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14370 *lowpc
= std::min (*lowpc
, low
);
14371 *highpc
= std::max (*highpc
, high
);
14374 /* If the language does not allow nested subprograms (either inside
14375 subprograms or lexical blocks), we're done. */
14376 if (cu
->language
!= language_ada
)
14379 /* Check all the children of the given DIE. If it contains nested
14380 subprograms, then check their pc bounds. Likewise, we need to
14381 check lexical blocks as well, as they may also contain subprogram
14383 while (child
&& child
->tag
)
14385 if (child
->tag
== DW_TAG_subprogram
14386 || child
->tag
== DW_TAG_lexical_block
)
14387 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14388 child
= sibling_die (child
);
14392 /* Get the low and high pc's represented by the scope DIE, and store
14393 them in *LOWPC and *HIGHPC. If the correct values can't be
14394 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14397 get_scope_pc_bounds (struct die_info
*die
,
14398 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14399 struct dwarf2_cu
*cu
)
14401 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14402 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14403 CORE_ADDR current_low
, current_high
;
14405 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14406 >= PC_BOUNDS_RANGES
)
14408 best_low
= current_low
;
14409 best_high
= current_high
;
14413 struct die_info
*child
= die
->child
;
14415 while (child
&& child
->tag
)
14417 switch (child
->tag
) {
14418 case DW_TAG_subprogram
:
14419 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14421 case DW_TAG_namespace
:
14422 case DW_TAG_module
:
14423 /* FIXME: carlton/2004-01-16: Should we do this for
14424 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14425 that current GCC's always emit the DIEs corresponding
14426 to definitions of methods of classes as children of a
14427 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14428 the DIEs giving the declarations, which could be
14429 anywhere). But I don't see any reason why the
14430 standards says that they have to be there. */
14431 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14433 if (current_low
!= ((CORE_ADDR
) -1))
14435 best_low
= std::min (best_low
, current_low
);
14436 best_high
= std::max (best_high
, current_high
);
14444 child
= sibling_die (child
);
14449 *highpc
= best_high
;
14452 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14456 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14457 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14459 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14460 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14461 struct attribute
*attr
;
14462 struct attribute
*attr_high
;
14464 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14467 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14468 if (attr
!= nullptr)
14470 CORE_ADDR low
= attr
->value_as_address ();
14471 CORE_ADDR high
= attr_high
->value_as_address ();
14473 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14476 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14477 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14478 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14482 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14483 if (attr
!= nullptr)
14485 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14486 We take advantage of the fact that DW_AT_ranges does not appear
14487 in DW_TAG_compile_unit of DWO files. */
14488 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14490 /* The value of the DW_AT_ranges attribute is the offset of the
14491 address range list in the .debug_ranges section. */
14492 unsigned long offset
= (DW_UNSND (attr
)
14493 + (need_ranges_base
? cu
->ranges_base
: 0));
14495 std::vector
<blockrange
> blockvec
;
14496 dwarf2_ranges_process (offset
, cu
,
14497 [&] (CORE_ADDR start
, CORE_ADDR end
)
14501 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14502 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14503 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14504 blockvec
.emplace_back (start
, end
);
14507 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14511 /* Check whether the producer field indicates either of GCC < 4.6, or the
14512 Intel C/C++ compiler, and cache the result in CU. */
14515 check_producer (struct dwarf2_cu
*cu
)
14519 if (cu
->producer
== NULL
)
14521 /* For unknown compilers expect their behavior is DWARF version
14524 GCC started to support .debug_types sections by -gdwarf-4 since
14525 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14526 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14527 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14528 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14530 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14532 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14533 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14535 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14537 cu
->producer_is_icc
= true;
14538 cu
->producer_is_icc_lt_14
= major
< 14;
14540 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14541 cu
->producer_is_codewarrior
= true;
14544 /* For other non-GCC compilers, expect their behavior is DWARF version
14548 cu
->checked_producer
= true;
14551 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14552 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14553 during 4.6.0 experimental. */
14556 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14558 if (!cu
->checked_producer
)
14559 check_producer (cu
);
14561 return cu
->producer_is_gxx_lt_4_6
;
14565 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14566 with incorrect is_stmt attributes. */
14569 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14571 if (!cu
->checked_producer
)
14572 check_producer (cu
);
14574 return cu
->producer_is_codewarrior
;
14577 /* Return the default accessibility type if it is not overridden by
14578 DW_AT_accessibility. */
14580 static enum dwarf_access_attribute
14581 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14583 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14585 /* The default DWARF 2 accessibility for members is public, the default
14586 accessibility for inheritance is private. */
14588 if (die
->tag
!= DW_TAG_inheritance
)
14589 return DW_ACCESS_public
;
14591 return DW_ACCESS_private
;
14595 /* DWARF 3+ defines the default accessibility a different way. The same
14596 rules apply now for DW_TAG_inheritance as for the members and it only
14597 depends on the container kind. */
14599 if (die
->parent
->tag
== DW_TAG_class_type
)
14600 return DW_ACCESS_private
;
14602 return DW_ACCESS_public
;
14606 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14607 offset. If the attribute was not found return 0, otherwise return
14608 1. If it was found but could not properly be handled, set *OFFSET
14612 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14615 struct attribute
*attr
;
14617 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14622 /* Note that we do not check for a section offset first here.
14623 This is because DW_AT_data_member_location is new in DWARF 4,
14624 so if we see it, we can assume that a constant form is really
14625 a constant and not a section offset. */
14626 if (attr
->form_is_constant ())
14627 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
14628 else if (attr
->form_is_section_offset ())
14629 dwarf2_complex_location_expr_complaint ();
14630 else if (attr
->form_is_block ())
14631 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14633 dwarf2_complex_location_expr_complaint ();
14641 /* Add an aggregate field to the field list. */
14644 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14645 struct dwarf2_cu
*cu
)
14647 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14648 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14649 struct nextfield
*new_field
;
14650 struct attribute
*attr
;
14652 const char *fieldname
= "";
14654 if (die
->tag
== DW_TAG_inheritance
)
14656 fip
->baseclasses
.emplace_back ();
14657 new_field
= &fip
->baseclasses
.back ();
14661 fip
->fields
.emplace_back ();
14662 new_field
= &fip
->fields
.back ();
14667 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14668 if (attr
!= nullptr)
14669 new_field
->accessibility
= DW_UNSND (attr
);
14671 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
14672 if (new_field
->accessibility
!= DW_ACCESS_public
)
14673 fip
->non_public_fields
= 1;
14675 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14676 if (attr
!= nullptr)
14677 new_field
->virtuality
= DW_UNSND (attr
);
14679 new_field
->virtuality
= DW_VIRTUALITY_none
;
14681 fp
= &new_field
->field
;
14683 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14687 /* Data member other than a C++ static data member. */
14689 /* Get type of field. */
14690 fp
->type
= die_type (die
, cu
);
14692 SET_FIELD_BITPOS (*fp
, 0);
14694 /* Get bit size of field (zero if none). */
14695 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14696 if (attr
!= nullptr)
14698 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
14702 FIELD_BITSIZE (*fp
) = 0;
14705 /* Get bit offset of field. */
14706 if (handle_data_member_location (die
, cu
, &offset
))
14707 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
14708 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14709 if (attr
!= nullptr)
14711 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14713 /* For big endian bits, the DW_AT_bit_offset gives the
14714 additional bit offset from the MSB of the containing
14715 anonymous object to the MSB of the field. We don't
14716 have to do anything special since we don't need to
14717 know the size of the anonymous object. */
14718 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
14722 /* For little endian bits, compute the bit offset to the
14723 MSB of the anonymous object, subtract off the number of
14724 bits from the MSB of the field to the MSB of the
14725 object, and then subtract off the number of bits of
14726 the field itself. The result is the bit offset of
14727 the LSB of the field. */
14728 int anonymous_size
;
14729 int bit_offset
= DW_UNSND (attr
);
14731 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14732 if (attr
!= nullptr)
14734 /* The size of the anonymous object containing
14735 the bit field is explicit, so use the
14736 indicated size (in bytes). */
14737 anonymous_size
= DW_UNSND (attr
);
14741 /* The size of the anonymous object containing
14742 the bit field must be inferred from the type
14743 attribute of the data member containing the
14745 anonymous_size
= TYPE_LENGTH (fp
->type
);
14747 SET_FIELD_BITPOS (*fp
,
14748 (FIELD_BITPOS (*fp
)
14749 + anonymous_size
* bits_per_byte
14750 - bit_offset
- FIELD_BITSIZE (*fp
)));
14753 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14755 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14756 + dwarf2_get_attr_constant_value (attr
, 0)));
14758 /* Get name of field. */
14759 fieldname
= dwarf2_name (die
, cu
);
14760 if (fieldname
== NULL
)
14763 /* The name is already allocated along with this objfile, so we don't
14764 need to duplicate it for the type. */
14765 fp
->name
= fieldname
;
14767 /* Change accessibility for artificial fields (e.g. virtual table
14768 pointer or virtual base class pointer) to private. */
14769 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
14771 FIELD_ARTIFICIAL (*fp
) = 1;
14772 new_field
->accessibility
= DW_ACCESS_private
;
14773 fip
->non_public_fields
= 1;
14776 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
14778 /* C++ static member. */
14780 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
14781 is a declaration, but all versions of G++ as of this writing
14782 (so through at least 3.2.1) incorrectly generate
14783 DW_TAG_variable tags. */
14785 const char *physname
;
14787 /* Get name of field. */
14788 fieldname
= dwarf2_name (die
, cu
);
14789 if (fieldname
== NULL
)
14792 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14794 /* Only create a symbol if this is an external value.
14795 new_symbol checks this and puts the value in the global symbol
14796 table, which we want. If it is not external, new_symbol
14797 will try to put the value in cu->list_in_scope which is wrong. */
14798 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
14800 /* A static const member, not much different than an enum as far as
14801 we're concerned, except that we can support more types. */
14802 new_symbol (die
, NULL
, cu
);
14805 /* Get physical name. */
14806 physname
= dwarf2_physname (fieldname
, die
, cu
);
14808 /* The name is already allocated along with this objfile, so we don't
14809 need to duplicate it for the type. */
14810 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
14811 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14812 FIELD_NAME (*fp
) = fieldname
;
14814 else if (die
->tag
== DW_TAG_inheritance
)
14818 /* C++ base class field. */
14819 if (handle_data_member_location (die
, cu
, &offset
))
14820 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
14821 FIELD_BITSIZE (*fp
) = 0;
14822 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14823 FIELD_NAME (*fp
) = TYPE_NAME (fp
->type
);
14825 else if (die
->tag
== DW_TAG_variant_part
)
14827 /* process_structure_scope will treat this DIE as a union. */
14828 process_structure_scope (die
, cu
);
14830 /* The variant part is relative to the start of the enclosing
14832 SET_FIELD_BITPOS (*fp
, 0);
14833 fp
->type
= get_die_type (die
, cu
);
14834 fp
->artificial
= 1;
14835 fp
->name
= "<<variant>>";
14837 /* Normally a DW_TAG_variant_part won't have a size, but our
14838 representation requires one, so set it to the maximum of the
14839 child sizes, being sure to account for the offset at which
14840 each child is seen. */
14841 if (TYPE_LENGTH (fp
->type
) == 0)
14844 for (int i
= 0; i
< TYPE_NFIELDS (fp
->type
); ++i
)
14846 unsigned len
= ((TYPE_FIELD_BITPOS (fp
->type
, i
) + 7) / 8
14847 + TYPE_LENGTH (TYPE_FIELD_TYPE (fp
->type
, i
)));
14851 TYPE_LENGTH (fp
->type
) = max
;
14855 gdb_assert_not_reached ("missing case in dwarf2_add_field");
14858 /* Can the type given by DIE define another type? */
14861 type_can_define_types (const struct die_info
*die
)
14865 case DW_TAG_typedef
:
14866 case DW_TAG_class_type
:
14867 case DW_TAG_structure_type
:
14868 case DW_TAG_union_type
:
14869 case DW_TAG_enumeration_type
:
14877 /* Add a type definition defined in the scope of the FIP's class. */
14880 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
14881 struct dwarf2_cu
*cu
)
14883 struct decl_field fp
;
14884 memset (&fp
, 0, sizeof (fp
));
14886 gdb_assert (type_can_define_types (die
));
14888 /* Get name of field. NULL is okay here, meaning an anonymous type. */
14889 fp
.name
= dwarf2_name (die
, cu
);
14890 fp
.type
= read_type_die (die
, cu
);
14892 /* Save accessibility. */
14893 enum dwarf_access_attribute accessibility
;
14894 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14896 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14898 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14899 switch (accessibility
)
14901 case DW_ACCESS_public
:
14902 /* The assumed value if neither private nor protected. */
14904 case DW_ACCESS_private
:
14907 case DW_ACCESS_protected
:
14908 fp
.is_protected
= 1;
14911 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
14914 if (die
->tag
== DW_TAG_typedef
)
14915 fip
->typedef_field_list
.push_back (fp
);
14917 fip
->nested_types_list
.push_back (fp
);
14920 /* Create the vector of fields, and attach it to the type. */
14923 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
14924 struct dwarf2_cu
*cu
)
14926 int nfields
= fip
->nfields
;
14928 /* Record the field count, allocate space for the array of fields,
14929 and create blank accessibility bitfields if necessary. */
14930 TYPE_NFIELDS (type
) = nfields
;
14931 TYPE_FIELDS (type
) = (struct field
*)
14932 TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
);
14934 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
14936 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14938 TYPE_FIELD_PRIVATE_BITS (type
) =
14939 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14940 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
14942 TYPE_FIELD_PROTECTED_BITS (type
) =
14943 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14944 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
14946 TYPE_FIELD_IGNORE_BITS (type
) =
14947 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14948 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
14951 /* If the type has baseclasses, allocate and clear a bit vector for
14952 TYPE_FIELD_VIRTUAL_BITS. */
14953 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
14955 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
14956 unsigned char *pointer
;
14958 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14959 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
14960 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
14961 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
14962 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
14965 if (TYPE_FLAG_DISCRIMINATED_UNION (type
))
14967 struct discriminant_info
*di
= alloc_discriminant_info (type
, -1, -1);
14969 for (int index
= 0; index
< nfields
; ++index
)
14971 struct nextfield
&field
= fip
->fields
[index
];
14973 if (field
.variant
.is_discriminant
)
14974 di
->discriminant_index
= index
;
14975 else if (field
.variant
.default_branch
)
14976 di
->default_index
= index
;
14978 di
->discriminants
[index
] = field
.variant
.discriminant_value
;
14982 /* Copy the saved-up fields into the field vector. */
14983 for (int i
= 0; i
< nfields
; ++i
)
14985 struct nextfield
&field
14986 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
14987 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
14989 TYPE_FIELD (type
, i
) = field
.field
;
14990 switch (field
.accessibility
)
14992 case DW_ACCESS_private
:
14993 if (cu
->language
!= language_ada
)
14994 SET_TYPE_FIELD_PRIVATE (type
, i
);
14997 case DW_ACCESS_protected
:
14998 if (cu
->language
!= language_ada
)
14999 SET_TYPE_FIELD_PROTECTED (type
, i
);
15002 case DW_ACCESS_public
:
15006 /* Unknown accessibility. Complain and treat it as public. */
15008 complaint (_("unsupported accessibility %d"),
15009 field
.accessibility
);
15013 if (i
< fip
->baseclasses
.size ())
15015 switch (field
.virtuality
)
15017 case DW_VIRTUALITY_virtual
:
15018 case DW_VIRTUALITY_pure_virtual
:
15019 if (cu
->language
== language_ada
)
15020 error (_("unexpected virtuality in component of Ada type"));
15021 SET_TYPE_FIELD_VIRTUAL (type
, i
);
15028 /* Return true if this member function is a constructor, false
15032 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15034 const char *fieldname
;
15035 const char *type_name
;
15038 if (die
->parent
== NULL
)
15041 if (die
->parent
->tag
!= DW_TAG_structure_type
15042 && die
->parent
->tag
!= DW_TAG_union_type
15043 && die
->parent
->tag
!= DW_TAG_class_type
)
15046 fieldname
= dwarf2_name (die
, cu
);
15047 type_name
= dwarf2_name (die
->parent
, cu
);
15048 if (fieldname
== NULL
|| type_name
== NULL
)
15051 len
= strlen (fieldname
);
15052 return (strncmp (fieldname
, type_name
, len
) == 0
15053 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15056 /* Check if the given VALUE is a recognized enum
15057 dwarf_defaulted_attribute constant according to DWARF5 spec,
15061 is_valid_DW_AT_defaulted (ULONGEST value
)
15065 case DW_DEFAULTED_no
:
15066 case DW_DEFAULTED_in_class
:
15067 case DW_DEFAULTED_out_of_class
:
15071 complaint (_("unrecognized DW_AT_defaulted value (%s)"), pulongest (value
));
15075 /* Add a member function to the proper fieldlist. */
15078 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15079 struct type
*type
, struct dwarf2_cu
*cu
)
15081 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15082 struct attribute
*attr
;
15084 struct fnfieldlist
*flp
= nullptr;
15085 struct fn_field
*fnp
;
15086 const char *fieldname
;
15087 struct type
*this_type
;
15088 enum dwarf_access_attribute accessibility
;
15090 if (cu
->language
== language_ada
)
15091 error (_("unexpected member function in Ada type"));
15093 /* Get name of member function. */
15094 fieldname
= dwarf2_name (die
, cu
);
15095 if (fieldname
== NULL
)
15098 /* Look up member function name in fieldlist. */
15099 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15101 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15103 flp
= &fip
->fnfieldlists
[i
];
15108 /* Create a new fnfieldlist if necessary. */
15109 if (flp
== nullptr)
15111 fip
->fnfieldlists
.emplace_back ();
15112 flp
= &fip
->fnfieldlists
.back ();
15113 flp
->name
= fieldname
;
15114 i
= fip
->fnfieldlists
.size () - 1;
15117 /* Create a new member function field and add it to the vector of
15119 flp
->fnfields
.emplace_back ();
15120 fnp
= &flp
->fnfields
.back ();
15122 /* Delay processing of the physname until later. */
15123 if (cu
->language
== language_cplus
)
15124 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15128 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15129 fnp
->physname
= physname
? physname
: "";
15132 fnp
->type
= alloc_type (objfile
);
15133 this_type
= read_type_die (die
, cu
);
15134 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
15136 int nparams
= TYPE_NFIELDS (this_type
);
15138 /* TYPE is the domain of this method, and THIS_TYPE is the type
15139 of the method itself (TYPE_CODE_METHOD). */
15140 smash_to_method_type (fnp
->type
, type
,
15141 TYPE_TARGET_TYPE (this_type
),
15142 TYPE_FIELDS (this_type
),
15143 TYPE_NFIELDS (this_type
),
15144 TYPE_VARARGS (this_type
));
15146 /* Handle static member functions.
15147 Dwarf2 has no clean way to discern C++ static and non-static
15148 member functions. G++ helps GDB by marking the first
15149 parameter for non-static member functions (which is the this
15150 pointer) as artificial. We obtain this information from
15151 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15152 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15153 fnp
->voffset
= VOFFSET_STATIC
;
15156 complaint (_("member function type missing for '%s'"),
15157 dwarf2_full_name (fieldname
, die
, cu
));
15159 /* Get fcontext from DW_AT_containing_type if present. */
15160 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15161 fnp
->fcontext
= die_containing_type (die
, cu
);
15163 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15164 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15166 /* Get accessibility. */
15167 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15168 if (attr
!= nullptr)
15169 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15171 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15172 switch (accessibility
)
15174 case DW_ACCESS_private
:
15175 fnp
->is_private
= 1;
15177 case DW_ACCESS_protected
:
15178 fnp
->is_protected
= 1;
15182 /* Check for artificial methods. */
15183 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15184 if (attr
&& DW_UNSND (attr
) != 0)
15185 fnp
->is_artificial
= 1;
15187 /* Check for defaulted methods. */
15188 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
15189 if (attr
!= nullptr && is_valid_DW_AT_defaulted (DW_UNSND (attr
)))
15190 fnp
->defaulted
= (enum dwarf_defaulted_attribute
) DW_UNSND (attr
);
15192 /* Check for deleted methods. */
15193 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
15194 if (attr
!= nullptr && DW_UNSND (attr
) != 0)
15195 fnp
->is_deleted
= 1;
15197 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15199 /* Get index in virtual function table if it is a virtual member
15200 function. For older versions of GCC, this is an offset in the
15201 appropriate virtual table, as specified by DW_AT_containing_type.
15202 For everyone else, it is an expression to be evaluated relative
15203 to the object address. */
15205 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15206 if (attr
!= nullptr)
15208 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
> 0)
15210 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
15212 /* Old-style GCC. */
15213 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
15215 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
15216 || (DW_BLOCK (attr
)->size
> 1
15217 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
15218 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
15220 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15221 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15222 dwarf2_complex_location_expr_complaint ();
15224 fnp
->voffset
/= cu
->header
.addr_size
;
15228 dwarf2_complex_location_expr_complaint ();
15230 if (!fnp
->fcontext
)
15232 /* If there is no `this' field and no DW_AT_containing_type,
15233 we cannot actually find a base class context for the
15235 if (TYPE_NFIELDS (this_type
) == 0
15236 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15238 complaint (_("cannot determine context for virtual member "
15239 "function \"%s\" (offset %s)"),
15240 fieldname
, sect_offset_str (die
->sect_off
));
15245 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
15249 else if (attr
->form_is_section_offset ())
15251 dwarf2_complex_location_expr_complaint ();
15255 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15261 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15262 if (attr
&& DW_UNSND (attr
))
15264 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15265 complaint (_("Member function \"%s\" (offset %s) is virtual "
15266 "but the vtable offset is not specified"),
15267 fieldname
, sect_offset_str (die
->sect_off
));
15268 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15269 TYPE_CPLUS_DYNAMIC (type
) = 1;
15274 /* Create the vector of member function fields, and attach it to the type. */
15277 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15278 struct dwarf2_cu
*cu
)
15280 if (cu
->language
== language_ada
)
15281 error (_("unexpected member functions in Ada type"));
15283 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15284 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15286 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15288 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15290 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15291 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15293 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15294 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15295 fn_flp
->fn_fields
= (struct fn_field
*)
15296 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15298 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15299 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15302 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15305 /* Returns non-zero if NAME is the name of a vtable member in CU's
15306 language, zero otherwise. */
15308 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15310 static const char vptr
[] = "_vptr";
15312 /* Look for the C++ form of the vtable. */
15313 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15319 /* GCC outputs unnamed structures that are really pointers to member
15320 functions, with the ABI-specified layout. If TYPE describes
15321 such a structure, smash it into a member function type.
15323 GCC shouldn't do this; it should just output pointer to member DIEs.
15324 This is GCC PR debug/28767. */
15327 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15329 struct type
*pfn_type
, *self_type
, *new_type
;
15331 /* Check for a structure with no name and two children. */
15332 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
15335 /* Check for __pfn and __delta members. */
15336 if (TYPE_FIELD_NAME (type
, 0) == NULL
15337 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15338 || TYPE_FIELD_NAME (type
, 1) == NULL
15339 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15342 /* Find the type of the method. */
15343 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
15344 if (pfn_type
== NULL
15345 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
15346 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
15349 /* Look for the "this" argument. */
15350 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15351 if (TYPE_NFIELDS (pfn_type
) == 0
15352 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
15353 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
15356 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
15357 new_type
= alloc_type (objfile
);
15358 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15359 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
15360 TYPE_VARARGS (pfn_type
));
15361 smash_to_methodptr_type (type
, new_type
);
15364 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15365 appropriate error checking and issuing complaints if there is a
15369 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15371 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15373 if (attr
== nullptr)
15376 if (!attr
->form_is_constant ())
15378 complaint (_("DW_AT_alignment must have constant form"
15379 " - DIE at %s [in module %s]"),
15380 sect_offset_str (die
->sect_off
),
15381 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15386 if (attr
->form
== DW_FORM_sdata
)
15388 LONGEST val
= DW_SND (attr
);
15391 complaint (_("DW_AT_alignment value must not be negative"
15392 " - DIE at %s [in module %s]"),
15393 sect_offset_str (die
->sect_off
),
15394 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15400 align
= DW_UNSND (attr
);
15404 complaint (_("DW_AT_alignment value must not be zero"
15405 " - DIE at %s [in module %s]"),
15406 sect_offset_str (die
->sect_off
),
15407 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15410 if ((align
& (align
- 1)) != 0)
15412 complaint (_("DW_AT_alignment value must be a power of 2"
15413 " - DIE at %s [in module %s]"),
15414 sect_offset_str (die
->sect_off
),
15415 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15422 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15423 the alignment for TYPE. */
15426 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15429 if (!set_type_align (type
, get_alignment (cu
, die
)))
15430 complaint (_("DW_AT_alignment value too large"
15431 " - DIE at %s [in module %s]"),
15432 sect_offset_str (die
->sect_off
),
15433 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15436 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15437 constant for a type, according to DWARF5 spec, Table 5.5. */
15440 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
15445 case DW_CC_pass_by_reference
:
15446 case DW_CC_pass_by_value
:
15450 complaint (_("unrecognized DW_AT_calling_convention value "
15451 "(%s) for a type"), pulongest (value
));
15456 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15457 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
15458 also according to GNU-specific values (see include/dwarf2.h). */
15461 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
15466 case DW_CC_program
:
15470 case DW_CC_GNU_renesas_sh
:
15471 case DW_CC_GNU_borland_fastcall_i386
:
15472 case DW_CC_GDB_IBM_OpenCL
:
15476 complaint (_("unrecognized DW_AT_calling_convention value "
15477 "(%s) for a subroutine"), pulongest (value
));
15482 /* Called when we find the DIE that starts a structure or union scope
15483 (definition) to create a type for the structure or union. Fill in
15484 the type's name and general properties; the members will not be
15485 processed until process_structure_scope. A symbol table entry for
15486 the type will also not be done until process_structure_scope (assuming
15487 the type has a name).
15489 NOTE: we need to call these functions regardless of whether or not the
15490 DIE has a DW_AT_name attribute, since it might be an anonymous
15491 structure or union. This gets the type entered into our set of
15492 user defined types. */
15494 static struct type
*
15495 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15497 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15499 struct attribute
*attr
;
15502 /* If the definition of this type lives in .debug_types, read that type.
15503 Don't follow DW_AT_specification though, that will take us back up
15504 the chain and we want to go down. */
15505 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
15506 if (attr
!= nullptr)
15508 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15510 /* The type's CU may not be the same as CU.
15511 Ensure TYPE is recorded with CU in die_type_hash. */
15512 return set_die_type (die
, type
, cu
);
15515 type
= alloc_type (objfile
);
15516 INIT_CPLUS_SPECIFIC (type
);
15518 name
= dwarf2_name (die
, cu
);
15521 if (cu
->language
== language_cplus
15522 || cu
->language
== language_d
15523 || cu
->language
== language_rust
)
15525 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15527 /* dwarf2_full_name might have already finished building the DIE's
15528 type. If so, there is no need to continue. */
15529 if (get_die_type (die
, cu
) != NULL
)
15530 return get_die_type (die
, cu
);
15532 TYPE_NAME (type
) = full_name
;
15536 /* The name is already allocated along with this objfile, so
15537 we don't need to duplicate it for the type. */
15538 TYPE_NAME (type
) = name
;
15542 if (die
->tag
== DW_TAG_structure_type
)
15544 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15546 else if (die
->tag
== DW_TAG_union_type
)
15548 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15550 else if (die
->tag
== DW_TAG_variant_part
)
15552 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15553 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
15557 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15560 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15561 TYPE_DECLARED_CLASS (type
) = 1;
15563 /* Store the calling convention in the type if it's available in
15564 the die. Otherwise the calling convention remains set to
15565 the default value DW_CC_normal. */
15566 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15567 if (attr
!= nullptr
15568 && is_valid_DW_AT_calling_convention_for_type (DW_UNSND (attr
)))
15570 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15571 TYPE_CPLUS_CALLING_CONVENTION (type
)
15572 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
15575 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15576 if (attr
!= nullptr)
15578 if (attr
->form_is_constant ())
15579 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15582 /* For the moment, dynamic type sizes are not supported
15583 by GDB's struct type. The actual size is determined
15584 on-demand when resolving the type of a given object,
15585 so set the type's length to zero for now. Otherwise,
15586 we record an expression as the length, and that expression
15587 could lead to a very large value, which could eventually
15588 lead to us trying to allocate that much memory when creating
15589 a value of that type. */
15590 TYPE_LENGTH (type
) = 0;
15595 TYPE_LENGTH (type
) = 0;
15598 maybe_set_alignment (cu
, die
, type
);
15600 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15602 /* ICC<14 does not output the required DW_AT_declaration on
15603 incomplete types, but gives them a size of zero. */
15604 TYPE_STUB (type
) = 1;
15607 TYPE_STUB_SUPPORTED (type
) = 1;
15609 if (die_is_declaration (die
, cu
))
15610 TYPE_STUB (type
) = 1;
15611 else if (attr
== NULL
&& die
->child
== NULL
15612 && producer_is_realview (cu
->producer
))
15613 /* RealView does not output the required DW_AT_declaration
15614 on incomplete types. */
15615 TYPE_STUB (type
) = 1;
15617 /* We need to add the type field to the die immediately so we don't
15618 infinitely recurse when dealing with pointers to the structure
15619 type within the structure itself. */
15620 set_die_type (die
, type
, cu
);
15622 /* set_die_type should be already done. */
15623 set_descriptive_type (type
, die
, cu
);
15628 /* A helper for process_structure_scope that handles a single member
15632 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15633 struct field_info
*fi
,
15634 std::vector
<struct symbol
*> *template_args
,
15635 struct dwarf2_cu
*cu
)
15637 if (child_die
->tag
== DW_TAG_member
15638 || child_die
->tag
== DW_TAG_variable
15639 || child_die
->tag
== DW_TAG_variant_part
)
15641 /* NOTE: carlton/2002-11-05: A C++ static data member
15642 should be a DW_TAG_member that is a declaration, but
15643 all versions of G++ as of this writing (so through at
15644 least 3.2.1) incorrectly generate DW_TAG_variable
15645 tags for them instead. */
15646 dwarf2_add_field (fi
, child_die
, cu
);
15648 else if (child_die
->tag
== DW_TAG_subprogram
)
15650 /* Rust doesn't have member functions in the C++ sense.
15651 However, it does emit ordinary functions as children
15652 of a struct DIE. */
15653 if (cu
->language
== language_rust
)
15654 read_func_scope (child_die
, cu
);
15657 /* C++ member function. */
15658 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15661 else if (child_die
->tag
== DW_TAG_inheritance
)
15663 /* C++ base class field. */
15664 dwarf2_add_field (fi
, child_die
, cu
);
15666 else if (type_can_define_types (child_die
))
15667 dwarf2_add_type_defn (fi
, child_die
, cu
);
15668 else if (child_die
->tag
== DW_TAG_template_type_param
15669 || child_die
->tag
== DW_TAG_template_value_param
)
15671 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15674 template_args
->push_back (arg
);
15676 else if (child_die
->tag
== DW_TAG_variant
)
15678 /* In a variant we want to get the discriminant and also add a
15679 field for our sole member child. */
15680 struct attribute
*discr
= dwarf2_attr (child_die
, DW_AT_discr_value
, cu
);
15682 for (die_info
*variant_child
= child_die
->child
;
15683 variant_child
!= NULL
;
15684 variant_child
= sibling_die (variant_child
))
15686 if (variant_child
->tag
== DW_TAG_member
)
15688 handle_struct_member_die (variant_child
, type
, fi
,
15689 template_args
, cu
);
15690 /* Only handle the one. */
15695 /* We don't handle this but we might as well report it if we see
15697 if (dwarf2_attr (child_die
, DW_AT_discr_list
, cu
) != nullptr)
15698 complaint (_("DW_AT_discr_list is not supported yet"
15699 " - DIE at %s [in module %s]"),
15700 sect_offset_str (child_die
->sect_off
),
15701 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15703 /* The first field was just added, so we can stash the
15704 discriminant there. */
15705 gdb_assert (!fi
->fields
.empty ());
15707 fi
->fields
.back ().variant
.default_branch
= true;
15709 fi
->fields
.back ().variant
.discriminant_value
= DW_UNSND (discr
);
15713 /* Finish creating a structure or union type, including filling in
15714 its members and creating a symbol for it. */
15717 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15719 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15720 struct die_info
*child_die
;
15723 type
= get_die_type (die
, cu
);
15725 type
= read_structure_type (die
, cu
);
15727 /* When reading a DW_TAG_variant_part, we need to notice when we
15728 read the discriminant member, so we can record it later in the
15729 discriminant_info. */
15730 bool is_variant_part
= TYPE_FLAG_DISCRIMINATED_UNION (type
);
15731 sect_offset discr_offset
{};
15732 bool has_template_parameters
= false;
15734 if (is_variant_part
)
15736 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15739 /* Maybe it's a univariant form, an extension we support.
15740 In this case arrange not to check the offset. */
15741 is_variant_part
= false;
15743 else if (discr
->form_is_ref ())
15745 struct dwarf2_cu
*target_cu
= cu
;
15746 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15748 discr_offset
= target_die
->sect_off
;
15752 complaint (_("DW_AT_discr does not have DIE reference form"
15753 " - DIE at %s [in module %s]"),
15754 sect_offset_str (die
->sect_off
),
15755 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15756 is_variant_part
= false;
15760 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15762 struct field_info fi
;
15763 std::vector
<struct symbol
*> template_args
;
15765 child_die
= die
->child
;
15767 while (child_die
&& child_die
->tag
)
15769 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15771 if (is_variant_part
&& discr_offset
== child_die
->sect_off
)
15772 fi
.fields
.back ().variant
.is_discriminant
= true;
15774 child_die
= sibling_die (child_die
);
15777 /* Attach template arguments to type. */
15778 if (!template_args
.empty ())
15780 has_template_parameters
= true;
15781 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15782 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15783 TYPE_TEMPLATE_ARGUMENTS (type
)
15784 = XOBNEWVEC (&objfile
->objfile_obstack
,
15786 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15787 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15788 template_args
.data (),
15789 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15790 * sizeof (struct symbol
*)));
15793 /* Attach fields and member functions to the type. */
15795 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15796 if (!fi
.fnfieldlists
.empty ())
15798 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15800 /* Get the type which refers to the base class (possibly this
15801 class itself) which contains the vtable pointer for the current
15802 class from the DW_AT_containing_type attribute. This use of
15803 DW_AT_containing_type is a GNU extension. */
15805 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15807 struct type
*t
= die_containing_type (die
, cu
);
15809 set_type_vptr_basetype (type
, t
);
15814 /* Our own class provides vtbl ptr. */
15815 for (i
= TYPE_NFIELDS (t
) - 1;
15816 i
>= TYPE_N_BASECLASSES (t
);
15819 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
15821 if (is_vtable_name (fieldname
, cu
))
15823 set_type_vptr_fieldno (type
, i
);
15828 /* Complain if virtual function table field not found. */
15829 if (i
< TYPE_N_BASECLASSES (t
))
15830 complaint (_("virtual function table pointer "
15831 "not found when defining class '%s'"),
15832 TYPE_NAME (type
) ? TYPE_NAME (type
) : "");
15836 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
15839 else if (cu
->producer
15840 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
15842 /* The IBM XLC compiler does not provide direct indication
15843 of the containing type, but the vtable pointer is
15844 always named __vfp. */
15848 for (i
= TYPE_NFIELDS (type
) - 1;
15849 i
>= TYPE_N_BASECLASSES (type
);
15852 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
15854 set_type_vptr_fieldno (type
, i
);
15855 set_type_vptr_basetype (type
, type
);
15862 /* Copy fi.typedef_field_list linked list elements content into the
15863 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
15864 if (!fi
.typedef_field_list
.empty ())
15866 int count
= fi
.typedef_field_list
.size ();
15868 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15869 TYPE_TYPEDEF_FIELD_ARRAY (type
)
15870 = ((struct decl_field
*)
15872 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
15873 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
15875 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
15876 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
15879 /* Copy fi.nested_types_list linked list elements content into the
15880 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
15881 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
15883 int count
= fi
.nested_types_list
.size ();
15885 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15886 TYPE_NESTED_TYPES_ARRAY (type
)
15887 = ((struct decl_field
*)
15888 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
15889 TYPE_NESTED_TYPES_COUNT (type
) = count
;
15891 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
15892 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
15896 quirk_gcc_member_function_pointer (type
, objfile
);
15897 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
15898 cu
->rust_unions
.push_back (type
);
15900 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
15901 snapshots) has been known to create a die giving a declaration
15902 for a class that has, as a child, a die giving a definition for a
15903 nested class. So we have to process our children even if the
15904 current die is a declaration. Normally, of course, a declaration
15905 won't have any children at all. */
15907 child_die
= die
->child
;
15909 while (child_die
!= NULL
&& child_die
->tag
)
15911 if (child_die
->tag
== DW_TAG_member
15912 || child_die
->tag
== DW_TAG_variable
15913 || child_die
->tag
== DW_TAG_inheritance
15914 || child_die
->tag
== DW_TAG_template_value_param
15915 || child_die
->tag
== DW_TAG_template_type_param
)
15920 process_die (child_die
, cu
);
15922 child_die
= sibling_die (child_die
);
15925 /* Do not consider external references. According to the DWARF standard,
15926 these DIEs are identified by the fact that they have no byte_size
15927 attribute, and a declaration attribute. */
15928 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
15929 || !die_is_declaration (die
, cu
))
15931 struct symbol
*sym
= new_symbol (die
, type
, cu
);
15933 if (has_template_parameters
)
15935 struct symtab
*symtab
;
15936 if (sym
!= nullptr)
15937 symtab
= symbol_symtab (sym
);
15938 else if (cu
->line_header
!= nullptr)
15940 /* Any related symtab will do. */
15942 = cu
->line_header
->file_names ()[0].symtab
;
15947 complaint (_("could not find suitable "
15948 "symtab for template parameter"
15949 " - DIE at %s [in module %s]"),
15950 sect_offset_str (die
->sect_off
),
15951 objfile_name (objfile
));
15954 if (symtab
!= nullptr)
15956 /* Make sure that the symtab is set on the new symbols.
15957 Even though they don't appear in this symtab directly,
15958 other parts of gdb assume that symbols do, and this is
15959 reasonably true. */
15960 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
15961 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
15967 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
15968 update TYPE using some information only available in DIE's children. */
15971 update_enumeration_type_from_children (struct die_info
*die
,
15973 struct dwarf2_cu
*cu
)
15975 struct die_info
*child_die
;
15976 int unsigned_enum
= 1;
15980 auto_obstack obstack
;
15982 for (child_die
= die
->child
;
15983 child_die
!= NULL
&& child_die
->tag
;
15984 child_die
= sibling_die (child_die
))
15986 struct attribute
*attr
;
15988 const gdb_byte
*bytes
;
15989 struct dwarf2_locexpr_baton
*baton
;
15992 if (child_die
->tag
!= DW_TAG_enumerator
)
15995 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
15999 name
= dwarf2_name (child_die
, cu
);
16001 name
= "<anonymous enumerator>";
16003 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16004 &value
, &bytes
, &baton
);
16010 else if ((mask
& value
) != 0)
16015 /* If we already know that the enum type is neither unsigned, nor
16016 a flag type, no need to look at the rest of the enumerates. */
16017 if (!unsigned_enum
&& !flag_enum
)
16022 TYPE_UNSIGNED (type
) = 1;
16024 TYPE_FLAG_ENUM (type
) = 1;
16027 /* Given a DW_AT_enumeration_type die, set its type. We do not
16028 complete the type's fields yet, or create any symbols. */
16030 static struct type
*
16031 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16033 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16035 struct attribute
*attr
;
16038 /* If the definition of this type lives in .debug_types, read that type.
16039 Don't follow DW_AT_specification though, that will take us back up
16040 the chain and we want to go down. */
16041 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
16042 if (attr
!= nullptr)
16044 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16046 /* The type's CU may not be the same as CU.
16047 Ensure TYPE is recorded with CU in die_type_hash. */
16048 return set_die_type (die
, type
, cu
);
16051 type
= alloc_type (objfile
);
16053 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
16054 name
= dwarf2_full_name (NULL
, die
, cu
);
16056 TYPE_NAME (type
) = name
;
16058 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16061 struct type
*underlying_type
= die_type (die
, cu
);
16063 TYPE_TARGET_TYPE (type
) = underlying_type
;
16066 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16067 if (attr
!= nullptr)
16069 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16073 TYPE_LENGTH (type
) = 0;
16076 maybe_set_alignment (cu
, die
, type
);
16078 /* The enumeration DIE can be incomplete. In Ada, any type can be
16079 declared as private in the package spec, and then defined only
16080 inside the package body. Such types are known as Taft Amendment
16081 Types. When another package uses such a type, an incomplete DIE
16082 may be generated by the compiler. */
16083 if (die_is_declaration (die
, cu
))
16084 TYPE_STUB (type
) = 1;
16086 /* Finish the creation of this type by using the enum's children.
16087 We must call this even when the underlying type has been provided
16088 so that we can determine if we're looking at a "flag" enum. */
16089 update_enumeration_type_from_children (die
, type
, cu
);
16091 /* If this type has an underlying type that is not a stub, then we
16092 may use its attributes. We always use the "unsigned" attribute
16093 in this situation, because ordinarily we guess whether the type
16094 is unsigned -- but the guess can be wrong and the underlying type
16095 can tell us the reality. However, we defer to a local size
16096 attribute if one exists, because this lets the compiler override
16097 the underlying type if needed. */
16098 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
16100 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
16101 if (TYPE_LENGTH (type
) == 0)
16102 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
16103 if (TYPE_RAW_ALIGN (type
) == 0
16104 && TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)) != 0)
16105 set_type_align (type
, TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)));
16108 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16110 return set_die_type (die
, type
, cu
);
16113 /* Given a pointer to a die which begins an enumeration, process all
16114 the dies that define the members of the enumeration, and create the
16115 symbol for the enumeration type.
16117 NOTE: We reverse the order of the element list. */
16120 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16122 struct type
*this_type
;
16124 this_type
= get_die_type (die
, cu
);
16125 if (this_type
== NULL
)
16126 this_type
= read_enumeration_type (die
, cu
);
16128 if (die
->child
!= NULL
)
16130 struct die_info
*child_die
;
16131 struct symbol
*sym
;
16132 std::vector
<struct field
> fields
;
16135 child_die
= die
->child
;
16136 while (child_die
&& child_die
->tag
)
16138 if (child_die
->tag
!= DW_TAG_enumerator
)
16140 process_die (child_die
, cu
);
16144 name
= dwarf2_name (child_die
, cu
);
16147 sym
= new_symbol (child_die
, this_type
, cu
);
16149 fields
.emplace_back ();
16150 struct field
&field
= fields
.back ();
16152 FIELD_NAME (field
) = sym
->linkage_name ();
16153 FIELD_TYPE (field
) = NULL
;
16154 SET_FIELD_ENUMVAL (field
, SYMBOL_VALUE (sym
));
16155 FIELD_BITSIZE (field
) = 0;
16159 child_die
= sibling_die (child_die
);
16162 if (!fields
.empty ())
16164 TYPE_NFIELDS (this_type
) = fields
.size ();
16165 TYPE_FIELDS (this_type
) = (struct field
*)
16166 TYPE_ALLOC (this_type
, sizeof (struct field
) * fields
.size ());
16167 memcpy (TYPE_FIELDS (this_type
), fields
.data (),
16168 sizeof (struct field
) * fields
.size ());
16172 /* If we are reading an enum from a .debug_types unit, and the enum
16173 is a declaration, and the enum is not the signatured type in the
16174 unit, then we do not want to add a symbol for it. Adding a
16175 symbol would in some cases obscure the true definition of the
16176 enum, giving users an incomplete type when the definition is
16177 actually available. Note that we do not want to do this for all
16178 enums which are just declarations, because C++0x allows forward
16179 enum declarations. */
16180 if (cu
->per_cu
->is_debug_types
16181 && die_is_declaration (die
, cu
))
16183 struct signatured_type
*sig_type
;
16185 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16186 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16187 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16191 new_symbol (die
, this_type
, cu
);
16194 /* Extract all information from a DW_TAG_array_type DIE and put it in
16195 the DIE's type field. For now, this only handles one dimensional
16198 static struct type
*
16199 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16201 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16202 struct die_info
*child_die
;
16204 struct type
*element_type
, *range_type
, *index_type
;
16205 struct attribute
*attr
;
16207 struct dynamic_prop
*byte_stride_prop
= NULL
;
16208 unsigned int bit_stride
= 0;
16210 element_type
= die_type (die
, cu
);
16212 /* The die_type call above may have already set the type for this DIE. */
16213 type
= get_die_type (die
, cu
);
16217 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16221 struct type
*prop_type
16222 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
16225 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16226 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
16230 complaint (_("unable to read array DW_AT_byte_stride "
16231 " - DIE at %s [in module %s]"),
16232 sect_offset_str (die
->sect_off
),
16233 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16234 /* Ignore this attribute. We will likely not be able to print
16235 arrays of this type correctly, but there is little we can do
16236 to help if we cannot read the attribute's value. */
16237 byte_stride_prop
= NULL
;
16241 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16243 bit_stride
= DW_UNSND (attr
);
16245 /* Irix 6.2 native cc creates array types without children for
16246 arrays with unspecified length. */
16247 if (die
->child
== NULL
)
16249 index_type
= objfile_type (objfile
)->builtin_int
;
16250 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16251 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16252 byte_stride_prop
, bit_stride
);
16253 return set_die_type (die
, type
, cu
);
16256 std::vector
<struct type
*> range_types
;
16257 child_die
= die
->child
;
16258 while (child_die
&& child_die
->tag
)
16260 if (child_die
->tag
== DW_TAG_subrange_type
)
16262 struct type
*child_type
= read_type_die (child_die
, cu
);
16264 if (child_type
!= NULL
)
16266 /* The range type was succesfully read. Save it for the
16267 array type creation. */
16268 range_types
.push_back (child_type
);
16271 child_die
= sibling_die (child_die
);
16274 /* Dwarf2 dimensions are output from left to right, create the
16275 necessary array types in backwards order. */
16277 type
= element_type
;
16279 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16283 while (i
< range_types
.size ())
16284 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16285 byte_stride_prop
, bit_stride
);
16289 size_t ndim
= range_types
.size ();
16291 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16292 byte_stride_prop
, bit_stride
);
16295 /* Understand Dwarf2 support for vector types (like they occur on
16296 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16297 array type. This is not part of the Dwarf2/3 standard yet, but a
16298 custom vendor extension. The main difference between a regular
16299 array and the vector variant is that vectors are passed by value
16301 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16302 if (attr
!= nullptr)
16303 make_vector_type (type
);
16305 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16306 implementation may choose to implement triple vectors using this
16308 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16309 if (attr
!= nullptr)
16311 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
16312 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16314 complaint (_("DW_AT_byte_size for array type smaller "
16315 "than the total size of elements"));
16318 name
= dwarf2_name (die
, cu
);
16320 TYPE_NAME (type
) = name
;
16322 maybe_set_alignment (cu
, die
, type
);
16324 /* Install the type in the die. */
16325 set_die_type (die
, type
, cu
);
16327 /* set_die_type should be already done. */
16328 set_descriptive_type (type
, die
, cu
);
16333 static enum dwarf_array_dim_ordering
16334 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16336 struct attribute
*attr
;
16338 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16340 if (attr
!= nullptr)
16341 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
16343 /* GNU F77 is a special case, as at 08/2004 array type info is the
16344 opposite order to the dwarf2 specification, but data is still
16345 laid out as per normal fortran.
16347 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16348 version checking. */
16350 if (cu
->language
== language_fortran
16351 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16353 return DW_ORD_row_major
;
16356 switch (cu
->language_defn
->la_array_ordering
)
16358 case array_column_major
:
16359 return DW_ORD_col_major
;
16360 case array_row_major
:
16362 return DW_ORD_row_major
;
16366 /* Extract all information from a DW_TAG_set_type DIE and put it in
16367 the DIE's type field. */
16369 static struct type
*
16370 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16372 struct type
*domain_type
, *set_type
;
16373 struct attribute
*attr
;
16375 domain_type
= die_type (die
, cu
);
16377 /* The die_type call above may have already set the type for this DIE. */
16378 set_type
= get_die_type (die
, cu
);
16382 set_type
= create_set_type (NULL
, domain_type
);
16384 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16385 if (attr
!= nullptr)
16386 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
16388 maybe_set_alignment (cu
, die
, set_type
);
16390 return set_die_type (die
, set_type
, cu
);
16393 /* A helper for read_common_block that creates a locexpr baton.
16394 SYM is the symbol which we are marking as computed.
16395 COMMON_DIE is the DIE for the common block.
16396 COMMON_LOC is the location expression attribute for the common
16398 MEMBER_LOC is the location expression attribute for the particular
16399 member of the common block that we are processing.
16400 CU is the CU from which the above come. */
16403 mark_common_block_symbol_computed (struct symbol
*sym
,
16404 struct die_info
*common_die
,
16405 struct attribute
*common_loc
,
16406 struct attribute
*member_loc
,
16407 struct dwarf2_cu
*cu
)
16409 struct dwarf2_per_objfile
*dwarf2_per_objfile
16410 = cu
->per_cu
->dwarf2_per_objfile
;
16411 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16412 struct dwarf2_locexpr_baton
*baton
;
16414 unsigned int cu_off
;
16415 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
16416 LONGEST offset
= 0;
16418 gdb_assert (common_loc
&& member_loc
);
16419 gdb_assert (common_loc
->form_is_block ());
16420 gdb_assert (member_loc
->form_is_block ()
16421 || member_loc
->form_is_constant ());
16423 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16424 baton
->per_cu
= cu
->per_cu
;
16425 gdb_assert (baton
->per_cu
);
16427 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16429 if (member_loc
->form_is_constant ())
16431 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
16432 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16435 baton
->size
+= DW_BLOCK (member_loc
)->size
;
16437 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16440 *ptr
++ = DW_OP_call4
;
16441 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16442 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16445 if (member_loc
->form_is_constant ())
16447 *ptr
++ = DW_OP_addr
;
16448 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16449 ptr
+= cu
->header
.addr_size
;
16453 /* We have to copy the data here, because DW_OP_call4 will only
16454 use a DW_AT_location attribute. */
16455 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
16456 ptr
+= DW_BLOCK (member_loc
)->size
;
16459 *ptr
++ = DW_OP_plus
;
16460 gdb_assert (ptr
- baton
->data
== baton
->size
);
16462 SYMBOL_LOCATION_BATON (sym
) = baton
;
16463 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16466 /* Create appropriate locally-scoped variables for all the
16467 DW_TAG_common_block entries. Also create a struct common_block
16468 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16469 is used to separate the common blocks name namespace from regular
16473 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16475 struct attribute
*attr
;
16477 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16478 if (attr
!= nullptr)
16480 /* Support the .debug_loc offsets. */
16481 if (attr
->form_is_block ())
16485 else if (attr
->form_is_section_offset ())
16487 dwarf2_complex_location_expr_complaint ();
16492 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16493 "common block member");
16498 if (die
->child
!= NULL
)
16500 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16501 struct die_info
*child_die
;
16502 size_t n_entries
= 0, size
;
16503 struct common_block
*common_block
;
16504 struct symbol
*sym
;
16506 for (child_die
= die
->child
;
16507 child_die
&& child_die
->tag
;
16508 child_die
= sibling_die (child_die
))
16511 size
= (sizeof (struct common_block
)
16512 + (n_entries
- 1) * sizeof (struct symbol
*));
16514 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16516 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16517 common_block
->n_entries
= 0;
16519 for (child_die
= die
->child
;
16520 child_die
&& child_die
->tag
;
16521 child_die
= sibling_die (child_die
))
16523 /* Create the symbol in the DW_TAG_common_block block in the current
16525 sym
= new_symbol (child_die
, NULL
, cu
);
16528 struct attribute
*member_loc
;
16530 common_block
->contents
[common_block
->n_entries
++] = sym
;
16532 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16536 /* GDB has handled this for a long time, but it is
16537 not specified by DWARF. It seems to have been
16538 emitted by gfortran at least as recently as:
16539 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16540 complaint (_("Variable in common block has "
16541 "DW_AT_data_member_location "
16542 "- DIE at %s [in module %s]"),
16543 sect_offset_str (child_die
->sect_off
),
16544 objfile_name (objfile
));
16546 if (member_loc
->form_is_section_offset ())
16547 dwarf2_complex_location_expr_complaint ();
16548 else if (member_loc
->form_is_constant ()
16549 || member_loc
->form_is_block ())
16551 if (attr
!= nullptr)
16552 mark_common_block_symbol_computed (sym
, die
, attr
,
16556 dwarf2_complex_location_expr_complaint ();
16561 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16562 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16566 /* Create a type for a C++ namespace. */
16568 static struct type
*
16569 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16571 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16572 const char *previous_prefix
, *name
;
16576 /* For extensions, reuse the type of the original namespace. */
16577 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16579 struct die_info
*ext_die
;
16580 struct dwarf2_cu
*ext_cu
= cu
;
16582 ext_die
= dwarf2_extension (die
, &ext_cu
);
16583 type
= read_type_die (ext_die
, ext_cu
);
16585 /* EXT_CU may not be the same as CU.
16586 Ensure TYPE is recorded with CU in die_type_hash. */
16587 return set_die_type (die
, type
, cu
);
16590 name
= namespace_name (die
, &is_anonymous
, cu
);
16592 /* Now build the name of the current namespace. */
16594 previous_prefix
= determine_prefix (die
, cu
);
16595 if (previous_prefix
[0] != '\0')
16596 name
= typename_concat (&objfile
->objfile_obstack
,
16597 previous_prefix
, name
, 0, cu
);
16599 /* Create the type. */
16600 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16602 return set_die_type (die
, type
, cu
);
16605 /* Read a namespace scope. */
16608 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16610 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16613 /* Add a symbol associated to this if we haven't seen the namespace
16614 before. Also, add a using directive if it's an anonymous
16617 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16621 type
= read_type_die (die
, cu
);
16622 new_symbol (die
, type
, cu
);
16624 namespace_name (die
, &is_anonymous
, cu
);
16627 const char *previous_prefix
= determine_prefix (die
, cu
);
16629 std::vector
<const char *> excludes
;
16630 add_using_directive (using_directives (cu
),
16631 previous_prefix
, TYPE_NAME (type
), NULL
,
16632 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16636 if (die
->child
!= NULL
)
16638 struct die_info
*child_die
= die
->child
;
16640 while (child_die
&& child_die
->tag
)
16642 process_die (child_die
, cu
);
16643 child_die
= sibling_die (child_die
);
16648 /* Read a Fortran module as type. This DIE can be only a declaration used for
16649 imported module. Still we need that type as local Fortran "use ... only"
16650 declaration imports depend on the created type in determine_prefix. */
16652 static struct type
*
16653 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16655 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16656 const char *module_name
;
16659 module_name
= dwarf2_name (die
, cu
);
16660 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16662 return set_die_type (die
, type
, cu
);
16665 /* Read a Fortran module. */
16668 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16670 struct die_info
*child_die
= die
->child
;
16673 type
= read_type_die (die
, cu
);
16674 new_symbol (die
, type
, cu
);
16676 while (child_die
&& child_die
->tag
)
16678 process_die (child_die
, cu
);
16679 child_die
= sibling_die (child_die
);
16683 /* Return the name of the namespace represented by DIE. Set
16684 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16687 static const char *
16688 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16690 struct die_info
*current_die
;
16691 const char *name
= NULL
;
16693 /* Loop through the extensions until we find a name. */
16695 for (current_die
= die
;
16696 current_die
!= NULL
;
16697 current_die
= dwarf2_extension (die
, &cu
))
16699 /* We don't use dwarf2_name here so that we can detect the absence
16700 of a name -> anonymous namespace. */
16701 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16707 /* Is it an anonymous namespace? */
16709 *is_anonymous
= (name
== NULL
);
16711 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16716 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16717 the user defined type vector. */
16719 static struct type
*
16720 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16722 struct gdbarch
*gdbarch
16723 = get_objfile_arch (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16724 struct comp_unit_head
*cu_header
= &cu
->header
;
16726 struct attribute
*attr_byte_size
;
16727 struct attribute
*attr_address_class
;
16728 int byte_size
, addr_class
;
16729 struct type
*target_type
;
16731 target_type
= die_type (die
, cu
);
16733 /* The die_type call above may have already set the type for this DIE. */
16734 type
= get_die_type (die
, cu
);
16738 type
= lookup_pointer_type (target_type
);
16740 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16741 if (attr_byte_size
)
16742 byte_size
= DW_UNSND (attr_byte_size
);
16744 byte_size
= cu_header
->addr_size
;
16746 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
16747 if (attr_address_class
)
16748 addr_class
= DW_UNSND (attr_address_class
);
16750 addr_class
= DW_ADDR_none
;
16752 ULONGEST alignment
= get_alignment (cu
, die
);
16754 /* If the pointer size, alignment, or address class is different
16755 than the default, create a type variant marked as such and set
16756 the length accordingly. */
16757 if (TYPE_LENGTH (type
) != byte_size
16758 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
16759 && alignment
!= TYPE_RAW_ALIGN (type
))
16760 || addr_class
!= DW_ADDR_none
)
16762 if (gdbarch_address_class_type_flags_p (gdbarch
))
16766 type_flags
= gdbarch_address_class_type_flags
16767 (gdbarch
, byte_size
, addr_class
);
16768 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
16770 type
= make_type_with_address_space (type
, type_flags
);
16772 else if (TYPE_LENGTH (type
) != byte_size
)
16774 complaint (_("invalid pointer size %d"), byte_size
);
16776 else if (TYPE_RAW_ALIGN (type
) != alignment
)
16778 complaint (_("Invalid DW_AT_alignment"
16779 " - DIE at %s [in module %s]"),
16780 sect_offset_str (die
->sect_off
),
16781 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16785 /* Should we also complain about unhandled address classes? */
16789 TYPE_LENGTH (type
) = byte_size
;
16790 set_type_align (type
, alignment
);
16791 return set_die_type (die
, type
, cu
);
16794 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
16795 the user defined type vector. */
16797 static struct type
*
16798 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16801 struct type
*to_type
;
16802 struct type
*domain
;
16804 to_type
= die_type (die
, cu
);
16805 domain
= die_containing_type (die
, cu
);
16807 /* The calls above may have already set the type for this DIE. */
16808 type
= get_die_type (die
, cu
);
16812 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
16813 type
= lookup_methodptr_type (to_type
);
16814 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
16816 struct type
*new_type
16817 = alloc_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16819 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
16820 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
16821 TYPE_VARARGS (to_type
));
16822 type
= lookup_methodptr_type (new_type
);
16825 type
= lookup_memberptr_type (to_type
, domain
);
16827 return set_die_type (die
, type
, cu
);
16830 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
16831 the user defined type vector. */
16833 static struct type
*
16834 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16835 enum type_code refcode
)
16837 struct comp_unit_head
*cu_header
= &cu
->header
;
16838 struct type
*type
, *target_type
;
16839 struct attribute
*attr
;
16841 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
16843 target_type
= die_type (die
, cu
);
16845 /* The die_type call above may have already set the type for this DIE. */
16846 type
= get_die_type (die
, cu
);
16850 type
= lookup_reference_type (target_type
, refcode
);
16851 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16852 if (attr
!= nullptr)
16854 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16858 TYPE_LENGTH (type
) = cu_header
->addr_size
;
16860 maybe_set_alignment (cu
, die
, type
);
16861 return set_die_type (die
, type
, cu
);
16864 /* Add the given cv-qualifiers to the element type of the array. GCC
16865 outputs DWARF type qualifiers that apply to an array, not the
16866 element type. But GDB relies on the array element type to carry
16867 the cv-qualifiers. This mimics section 6.7.3 of the C99
16870 static struct type
*
16871 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16872 struct type
*base_type
, int cnst
, int voltl
)
16874 struct type
*el_type
, *inner_array
;
16876 base_type
= copy_type (base_type
);
16877 inner_array
= base_type
;
16879 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
16881 TYPE_TARGET_TYPE (inner_array
) =
16882 copy_type (TYPE_TARGET_TYPE (inner_array
));
16883 inner_array
= TYPE_TARGET_TYPE (inner_array
);
16886 el_type
= TYPE_TARGET_TYPE (inner_array
);
16887 cnst
|= TYPE_CONST (el_type
);
16888 voltl
|= TYPE_VOLATILE (el_type
);
16889 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
16891 return set_die_type (die
, base_type
, cu
);
16894 static struct type
*
16895 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16897 struct type
*base_type
, *cv_type
;
16899 base_type
= die_type (die
, cu
);
16901 /* The die_type call above may have already set the type for this DIE. */
16902 cv_type
= get_die_type (die
, cu
);
16906 /* In case the const qualifier is applied to an array type, the element type
16907 is so qualified, not the array type (section 6.7.3 of C99). */
16908 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
16909 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
16911 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
16912 return set_die_type (die
, cv_type
, cu
);
16915 static struct type
*
16916 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16918 struct type
*base_type
, *cv_type
;
16920 base_type
= die_type (die
, cu
);
16922 /* The die_type call above may have already set the type for this DIE. */
16923 cv_type
= get_die_type (die
, cu
);
16927 /* In case the volatile qualifier is applied to an array type, the
16928 element type is so qualified, not the array type (section 6.7.3
16930 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
16931 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
16933 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
16934 return set_die_type (die
, cv_type
, cu
);
16937 /* Handle DW_TAG_restrict_type. */
16939 static struct type
*
16940 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16942 struct type
*base_type
, *cv_type
;
16944 base_type
= die_type (die
, cu
);
16946 /* The die_type call above may have already set the type for this DIE. */
16947 cv_type
= get_die_type (die
, cu
);
16951 cv_type
= make_restrict_type (base_type
);
16952 return set_die_type (die
, cv_type
, cu
);
16955 /* Handle DW_TAG_atomic_type. */
16957 static struct type
*
16958 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16960 struct type
*base_type
, *cv_type
;
16962 base_type
= die_type (die
, cu
);
16964 /* The die_type call above may have already set the type for this DIE. */
16965 cv_type
= get_die_type (die
, cu
);
16969 cv_type
= make_atomic_type (base_type
);
16970 return set_die_type (die
, cv_type
, cu
);
16973 /* Extract all information from a DW_TAG_string_type DIE and add to
16974 the user defined type vector. It isn't really a user defined type,
16975 but it behaves like one, with other DIE's using an AT_user_def_type
16976 attribute to reference it. */
16978 static struct type
*
16979 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16981 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16982 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16983 struct type
*type
, *range_type
, *index_type
, *char_type
;
16984 struct attribute
*attr
;
16985 struct dynamic_prop prop
;
16986 bool length_is_constant
= true;
16989 /* There are a couple of places where bit sizes might be made use of
16990 when parsing a DW_TAG_string_type, however, no producer that we know
16991 of make use of these. Handling bit sizes that are a multiple of the
16992 byte size is easy enough, but what about other bit sizes? Lets deal
16993 with that problem when we have to. Warn about these attributes being
16994 unsupported, then parse the type and ignore them like we always
16996 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
16997 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
16999 static bool warning_printed
= false;
17000 if (!warning_printed
)
17002 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
17003 "currently supported on DW_TAG_string_type."));
17004 warning_printed
= true;
17008 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17009 if (attr
!= nullptr && !attr
->form_is_constant ())
17011 /* The string length describes the location at which the length of
17012 the string can be found. The size of the length field can be
17013 specified with one of the attributes below. */
17014 struct type
*prop_type
;
17015 struct attribute
*len
17016 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
17017 if (len
== nullptr)
17018 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17019 if (len
!= nullptr && len
->form_is_constant ())
17021 /* Pass 0 as the default as we know this attribute is constant
17022 and the default value will not be returned. */
17023 LONGEST sz
= dwarf2_get_attr_constant_value (len
, 0);
17024 prop_type
= dwarf2_per_cu_int_type (cu
->per_cu
, sz
, true);
17028 /* If the size is not specified then we assume it is the size of
17029 an address on this target. */
17030 prop_type
= dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, true);
17033 /* Convert the attribute into a dynamic property. */
17034 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
17037 length_is_constant
= false;
17039 else if (attr
!= nullptr)
17041 /* This DW_AT_string_length just contains the length with no
17042 indirection. There's no need to create a dynamic property in this
17043 case. Pass 0 for the default value as we know it will not be
17044 returned in this case. */
17045 length
= dwarf2_get_attr_constant_value (attr
, 0);
17047 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
17049 /* We don't currently support non-constant byte sizes for strings. */
17050 length
= dwarf2_get_attr_constant_value (attr
, 1);
17054 /* Use 1 as a fallback length if we have nothing else. */
17058 index_type
= objfile_type (objfile
)->builtin_int
;
17059 if (length_is_constant
)
17060 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17063 struct dynamic_prop low_bound
;
17065 low_bound
.kind
= PROP_CONST
;
17066 low_bound
.data
.const_val
= 1;
17067 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
17069 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17070 type
= create_string_type (NULL
, char_type
, range_type
);
17072 return set_die_type (die
, type
, cu
);
17075 /* Assuming that DIE corresponds to a function, returns nonzero
17076 if the function is prototyped. */
17079 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17081 struct attribute
*attr
;
17083 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17084 if (attr
&& (DW_UNSND (attr
) != 0))
17087 /* The DWARF standard implies that the DW_AT_prototyped attribute
17088 is only meaningful for C, but the concept also extends to other
17089 languages that allow unprototyped functions (Eg: Objective C).
17090 For all other languages, assume that functions are always
17092 if (cu
->language
!= language_c
17093 && cu
->language
!= language_objc
17094 && cu
->language
!= language_opencl
)
17097 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17098 prototyped and unprototyped functions; default to prototyped,
17099 since that is more common in modern code (and RealView warns
17100 about unprototyped functions). */
17101 if (producer_is_realview (cu
->producer
))
17107 /* Handle DIES due to C code like:
17111 int (*funcp)(int a, long l);
17115 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17117 static struct type
*
17118 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17120 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17121 struct type
*type
; /* Type that this function returns. */
17122 struct type
*ftype
; /* Function that returns above type. */
17123 struct attribute
*attr
;
17125 type
= die_type (die
, cu
);
17127 /* The die_type call above may have already set the type for this DIE. */
17128 ftype
= get_die_type (die
, cu
);
17132 ftype
= lookup_function_type (type
);
17134 if (prototyped_function_p (die
, cu
))
17135 TYPE_PROTOTYPED (ftype
) = 1;
17137 /* Store the calling convention in the type if it's available in
17138 the subroutine die. Otherwise set the calling convention to
17139 the default value DW_CC_normal. */
17140 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17141 if (attr
!= nullptr
17142 && is_valid_DW_AT_calling_convention_for_subroutine (DW_UNSND (attr
)))
17143 TYPE_CALLING_CONVENTION (ftype
)
17144 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
17145 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17146 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17148 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17150 /* Record whether the function returns normally to its caller or not
17151 if the DWARF producer set that information. */
17152 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17153 if (attr
&& (DW_UNSND (attr
) != 0))
17154 TYPE_NO_RETURN (ftype
) = 1;
17156 /* We need to add the subroutine type to the die immediately so
17157 we don't infinitely recurse when dealing with parameters
17158 declared as the same subroutine type. */
17159 set_die_type (die
, ftype
, cu
);
17161 if (die
->child
!= NULL
)
17163 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17164 struct die_info
*child_die
;
17165 int nparams
, iparams
;
17167 /* Count the number of parameters.
17168 FIXME: GDB currently ignores vararg functions, but knows about
17169 vararg member functions. */
17171 child_die
= die
->child
;
17172 while (child_die
&& child_die
->tag
)
17174 if (child_die
->tag
== DW_TAG_formal_parameter
)
17176 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17177 TYPE_VARARGS (ftype
) = 1;
17178 child_die
= sibling_die (child_die
);
17181 /* Allocate storage for parameters and fill them in. */
17182 TYPE_NFIELDS (ftype
) = nparams
;
17183 TYPE_FIELDS (ftype
) = (struct field
*)
17184 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
17186 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17187 even if we error out during the parameters reading below. */
17188 for (iparams
= 0; iparams
< nparams
; iparams
++)
17189 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
17192 child_die
= die
->child
;
17193 while (child_die
&& child_die
->tag
)
17195 if (child_die
->tag
== DW_TAG_formal_parameter
)
17197 struct type
*arg_type
;
17199 /* DWARF version 2 has no clean way to discern C++
17200 static and non-static member functions. G++ helps
17201 GDB by marking the first parameter for non-static
17202 member functions (which is the this pointer) as
17203 artificial. We pass this information to
17204 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17206 DWARF version 3 added DW_AT_object_pointer, which GCC
17207 4.5 does not yet generate. */
17208 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17209 if (attr
!= nullptr)
17210 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
17212 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17213 arg_type
= die_type (child_die
, cu
);
17215 /* RealView does not mark THIS as const, which the testsuite
17216 expects. GCC marks THIS as const in method definitions,
17217 but not in the class specifications (GCC PR 43053). */
17218 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17219 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17222 struct dwarf2_cu
*arg_cu
= cu
;
17223 const char *name
= dwarf2_name (child_die
, cu
);
17225 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17226 if (attr
!= nullptr)
17228 /* If the compiler emits this, use it. */
17229 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17232 else if (name
&& strcmp (name
, "this") == 0)
17233 /* Function definitions will have the argument names. */
17235 else if (name
== NULL
&& iparams
== 0)
17236 /* Declarations may not have the names, so like
17237 elsewhere in GDB, assume an artificial first
17238 argument is "this". */
17242 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17246 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
17249 child_die
= sibling_die (child_die
);
17256 static struct type
*
17257 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17259 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17260 const char *name
= NULL
;
17261 struct type
*this_type
, *target_type
;
17263 name
= dwarf2_full_name (NULL
, die
, cu
);
17264 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17265 TYPE_TARGET_STUB (this_type
) = 1;
17266 set_die_type (die
, this_type
, cu
);
17267 target_type
= die_type (die
, cu
);
17268 if (target_type
!= this_type
)
17269 TYPE_TARGET_TYPE (this_type
) = target_type
;
17272 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17273 spec and cause infinite loops in GDB. */
17274 complaint (_("Self-referential DW_TAG_typedef "
17275 "- DIE at %s [in module %s]"),
17276 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17277 TYPE_TARGET_TYPE (this_type
) = NULL
;
17282 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17283 (which may be different from NAME) to the architecture back-end to allow
17284 it to guess the correct format if necessary. */
17286 static struct type
*
17287 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17288 const char *name_hint
, enum bfd_endian byte_order
)
17290 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17291 const struct floatformat
**format
;
17294 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17296 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
17298 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17303 /* Allocate an integer type of size BITS and name NAME. */
17305 static struct type
*
17306 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
17307 int bits
, int unsigned_p
, const char *name
)
17311 /* Versions of Intel's C Compiler generate an integer type called "void"
17312 instead of using DW_TAG_unspecified_type. This has been seen on
17313 at least versions 14, 17, and 18. */
17314 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
17315 && strcmp (name
, "void") == 0)
17316 type
= objfile_type (objfile
)->builtin_void
;
17318 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
17323 /* Initialise and return a floating point type of size BITS suitable for
17324 use as a component of a complex number. The NAME_HINT is passed through
17325 when initialising the floating point type and is the name of the complex
17328 As DWARF doesn't currently provide an explicit name for the components
17329 of a complex number, but it can be helpful to have these components
17330 named, we try to select a suitable name based on the size of the
17332 static struct type
*
17333 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
17334 struct objfile
*objfile
,
17335 int bits
, const char *name_hint
,
17336 enum bfd_endian byte_order
)
17338 gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17339 struct type
*tt
= nullptr;
17341 /* Try to find a suitable floating point builtin type of size BITS.
17342 We're going to use the name of this type as the name for the complex
17343 target type that we are about to create. */
17344 switch (cu
->language
)
17346 case language_fortran
:
17350 tt
= builtin_f_type (gdbarch
)->builtin_real
;
17353 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
17355 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17357 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
17365 tt
= builtin_type (gdbarch
)->builtin_float
;
17368 tt
= builtin_type (gdbarch
)->builtin_double
;
17370 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17372 tt
= builtin_type (gdbarch
)->builtin_long_double
;
17378 /* If the type we found doesn't match the size we were looking for, then
17379 pretend we didn't find a type at all, the complex target type we
17380 create will then be nameless. */
17381 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
17384 const char *name
= (tt
== nullptr) ? nullptr : TYPE_NAME (tt
);
17385 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
17388 /* Find a representation of a given base type and install
17389 it in the TYPE field of the die. */
17391 static struct type
*
17392 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17394 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17396 struct attribute
*attr
;
17397 int encoding
= 0, bits
= 0;
17401 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17402 if (attr
!= nullptr)
17403 encoding
= DW_UNSND (attr
);
17404 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17405 if (attr
!= nullptr)
17406 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
17407 name
= dwarf2_name (die
, cu
);
17409 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
17411 arch
= get_objfile_arch (objfile
);
17412 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
17414 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
17417 int endianity
= DW_UNSND (attr
);
17422 byte_order
= BFD_ENDIAN_BIG
;
17424 case DW_END_little
:
17425 byte_order
= BFD_ENDIAN_LITTLE
;
17428 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
17435 case DW_ATE_address
:
17436 /* Turn DW_ATE_address into a void * pointer. */
17437 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
17438 type
= init_pointer_type (objfile
, bits
, name
, type
);
17440 case DW_ATE_boolean
:
17441 type
= init_boolean_type (objfile
, bits
, 1, name
);
17443 case DW_ATE_complex_float
:
17444 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
17446 type
= init_complex_type (objfile
, name
, type
);
17448 case DW_ATE_decimal_float
:
17449 type
= init_decfloat_type (objfile
, bits
, name
);
17452 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
17454 case DW_ATE_signed
:
17455 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17457 case DW_ATE_unsigned
:
17458 if (cu
->language
== language_fortran
17460 && startswith (name
, "character("))
17461 type
= init_character_type (objfile
, bits
, 1, name
);
17463 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17465 case DW_ATE_signed_char
:
17466 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17467 || cu
->language
== language_pascal
17468 || cu
->language
== language_fortran
)
17469 type
= init_character_type (objfile
, bits
, 0, name
);
17471 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17473 case DW_ATE_unsigned_char
:
17474 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17475 || cu
->language
== language_pascal
17476 || cu
->language
== language_fortran
17477 || cu
->language
== language_rust
)
17478 type
= init_character_type (objfile
, bits
, 1, name
);
17480 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17485 type
= builtin_type (arch
)->builtin_char16
;
17486 else if (bits
== 32)
17487 type
= builtin_type (arch
)->builtin_char32
;
17490 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
17492 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17494 return set_die_type (die
, type
, cu
);
17499 complaint (_("unsupported DW_AT_encoding: '%s'"),
17500 dwarf_type_encoding_name (encoding
));
17501 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17505 if (name
&& strcmp (name
, "char") == 0)
17506 TYPE_NOSIGN (type
) = 1;
17508 maybe_set_alignment (cu
, die
, type
);
17510 TYPE_ENDIANITY_NOT_DEFAULT (type
) = gdbarch_byte_order (arch
) != byte_order
;
17512 return set_die_type (die
, type
, cu
);
17515 /* Parse dwarf attribute if it's a block, reference or constant and put the
17516 resulting value of the attribute into struct bound_prop.
17517 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17520 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17521 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
17522 struct type
*default_type
)
17524 struct dwarf2_property_baton
*baton
;
17525 struct obstack
*obstack
17526 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
17528 gdb_assert (default_type
!= NULL
);
17530 if (attr
== NULL
|| prop
== NULL
)
17533 if (attr
->form_is_block ())
17535 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17536 baton
->property_type
= default_type
;
17537 baton
->locexpr
.per_cu
= cu
->per_cu
;
17538 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17539 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17540 switch (attr
->name
)
17542 case DW_AT_string_length
:
17543 baton
->locexpr
.is_reference
= true;
17546 baton
->locexpr
.is_reference
= false;
17549 prop
->data
.baton
= baton
;
17550 prop
->kind
= PROP_LOCEXPR
;
17551 gdb_assert (prop
->data
.baton
!= NULL
);
17553 else if (attr
->form_is_ref ())
17555 struct dwarf2_cu
*target_cu
= cu
;
17556 struct die_info
*target_die
;
17557 struct attribute
*target_attr
;
17559 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17560 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17561 if (target_attr
== NULL
)
17562 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17564 if (target_attr
== NULL
)
17567 switch (target_attr
->name
)
17569 case DW_AT_location
:
17570 if (target_attr
->form_is_section_offset ())
17572 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17573 baton
->property_type
= die_type (target_die
, target_cu
);
17574 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17575 prop
->data
.baton
= baton
;
17576 prop
->kind
= PROP_LOCLIST
;
17577 gdb_assert (prop
->data
.baton
!= NULL
);
17579 else if (target_attr
->form_is_block ())
17581 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17582 baton
->property_type
= die_type (target_die
, target_cu
);
17583 baton
->locexpr
.per_cu
= cu
->per_cu
;
17584 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17585 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17586 baton
->locexpr
.is_reference
= true;
17587 prop
->data
.baton
= baton
;
17588 prop
->kind
= PROP_LOCEXPR
;
17589 gdb_assert (prop
->data
.baton
!= NULL
);
17593 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17594 "dynamic property");
17598 case DW_AT_data_member_location
:
17602 if (!handle_data_member_location (target_die
, target_cu
,
17606 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17607 baton
->property_type
= read_type_die (target_die
->parent
,
17609 baton
->offset_info
.offset
= offset
;
17610 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17611 prop
->data
.baton
= baton
;
17612 prop
->kind
= PROP_ADDR_OFFSET
;
17617 else if (attr
->form_is_constant ())
17619 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
17620 prop
->kind
= PROP_CONST
;
17624 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17625 dwarf2_name (die
, cu
));
17632 /* Find an integer type SIZE_IN_BYTES bytes in size and return it.
17633 UNSIGNED_P controls if the integer is unsigned or not. */
17635 static struct type
*
17636 dwarf2_per_cu_int_type (struct dwarf2_per_cu_data
*per_cu
,
17637 int size_in_bytes
, bool unsigned_p
)
17639 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
17640 struct type
*int_type
;
17642 /* Helper macro to examine the various builtin types. */
17643 #define TRY_TYPE(F) \
17644 int_type = (unsigned_p \
17645 ? objfile_type (objfile)->builtin_unsigned_ ## F \
17646 : objfile_type (objfile)->builtin_ ## F); \
17647 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
17654 TRY_TYPE (long_long
);
17658 gdb_assert_not_reached ("unable to find suitable integer type");
17661 /* Find an integer type the same size as the address size given in the
17662 compilation unit header for PER_CU. UNSIGNED_P controls if the integer
17663 is unsigned or not. */
17665 static struct type
*
17666 dwarf2_per_cu_addr_sized_int_type (struct dwarf2_per_cu_data
*per_cu
,
17669 int addr_size
= dwarf2_per_cu_addr_size (per_cu
);
17670 return dwarf2_per_cu_int_type (per_cu
, addr_size
, unsigned_p
);
17673 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
17674 present (which is valid) then compute the default type based on the
17675 compilation units address size. */
17677 static struct type
*
17678 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17680 struct type
*index_type
= die_type (die
, cu
);
17682 /* Dwarf-2 specifications explicitly allows to create subrange types
17683 without specifying a base type.
17684 In that case, the base type must be set to the type of
17685 the lower bound, upper bound or count, in that order, if any of these
17686 three attributes references an object that has a type.
17687 If no base type is found, the Dwarf-2 specifications say that
17688 a signed integer type of size equal to the size of an address should
17690 For the following C code: `extern char gdb_int [];'
17691 GCC produces an empty range DIE.
17692 FIXME: muller/2010-05-28: Possible references to object for low bound,
17693 high bound or count are not yet handled by this code. */
17694 if (TYPE_CODE (index_type
) == TYPE_CODE_VOID
)
17695 index_type
= dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
17700 /* Read the given DW_AT_subrange DIE. */
17702 static struct type
*
17703 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17705 struct type
*base_type
, *orig_base_type
;
17706 struct type
*range_type
;
17707 struct attribute
*attr
;
17708 struct dynamic_prop low
, high
;
17709 int low_default_is_valid
;
17710 int high_bound_is_count
= 0;
17712 ULONGEST negative_mask
;
17714 orig_base_type
= read_subrange_index_type (die
, cu
);
17716 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17717 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17718 creating the range type, but we use the result of check_typedef
17719 when examining properties of the type. */
17720 base_type
= check_typedef (orig_base_type
);
17722 /* The die_type call above may have already set the type for this DIE. */
17723 range_type
= get_die_type (die
, cu
);
17727 low
.kind
= PROP_CONST
;
17728 high
.kind
= PROP_CONST
;
17729 high
.data
.const_val
= 0;
17731 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17732 omitting DW_AT_lower_bound. */
17733 switch (cu
->language
)
17736 case language_cplus
:
17737 low
.data
.const_val
= 0;
17738 low_default_is_valid
= 1;
17740 case language_fortran
:
17741 low
.data
.const_val
= 1;
17742 low_default_is_valid
= 1;
17745 case language_objc
:
17746 case language_rust
:
17747 low
.data
.const_val
= 0;
17748 low_default_is_valid
= (cu
->header
.version
>= 4);
17752 case language_pascal
:
17753 low
.data
.const_val
= 1;
17754 low_default_is_valid
= (cu
->header
.version
>= 4);
17757 low
.data
.const_val
= 0;
17758 low_default_is_valid
= 0;
17762 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
17763 if (attr
!= nullptr)
17764 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
17765 else if (!low_default_is_valid
)
17766 complaint (_("Missing DW_AT_lower_bound "
17767 "- DIE at %s [in module %s]"),
17768 sect_offset_str (die
->sect_off
),
17769 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17771 struct attribute
*attr_ub
, *attr_count
;
17772 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
17773 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17775 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
17776 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17778 /* If bounds are constant do the final calculation here. */
17779 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
17780 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
17782 high_bound_is_count
= 1;
17786 if (attr_ub
!= NULL
)
17787 complaint (_("Unresolved DW_AT_upper_bound "
17788 "- DIE at %s [in module %s]"),
17789 sect_offset_str (die
->sect_off
),
17790 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17791 if (attr_count
!= NULL
)
17792 complaint (_("Unresolved DW_AT_count "
17793 "- DIE at %s [in module %s]"),
17794 sect_offset_str (die
->sect_off
),
17795 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17800 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
17801 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
17802 bias
= dwarf2_get_attr_constant_value (bias_attr
, 0);
17804 /* Normally, the DWARF producers are expected to use a signed
17805 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17806 But this is unfortunately not always the case, as witnessed
17807 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17808 is used instead. To work around that ambiguity, we treat
17809 the bounds as signed, and thus sign-extend their values, when
17810 the base type is signed. */
17812 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
17813 if (low
.kind
== PROP_CONST
17814 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
17815 low
.data
.const_val
|= negative_mask
;
17816 if (high
.kind
== PROP_CONST
17817 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
17818 high
.data
.const_val
|= negative_mask
;
17820 /* Check for bit and byte strides. */
17821 struct dynamic_prop byte_stride_prop
;
17822 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
17823 if (attr_byte_stride
!= nullptr)
17825 struct type
*prop_type
17826 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
17827 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
17831 struct dynamic_prop bit_stride_prop
;
17832 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
17833 if (attr_bit_stride
!= nullptr)
17835 /* It only makes sense to have either a bit or byte stride. */
17836 if (attr_byte_stride
!= nullptr)
17838 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
17839 "- DIE at %s [in module %s]"),
17840 sect_offset_str (die
->sect_off
),
17841 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17842 attr_bit_stride
= nullptr;
17846 struct type
*prop_type
17847 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
17848 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
17853 if (attr_byte_stride
!= nullptr
17854 || attr_bit_stride
!= nullptr)
17856 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
17857 struct dynamic_prop
*stride
17858 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
17861 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
17862 &high
, bias
, stride
, byte_stride_p
);
17865 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
17867 if (high_bound_is_count
)
17868 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
17870 /* Ada expects an empty array on no boundary attributes. */
17871 if (attr
== NULL
&& cu
->language
!= language_ada
)
17872 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
17874 name
= dwarf2_name (die
, cu
);
17876 TYPE_NAME (range_type
) = name
;
17878 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17879 if (attr
!= nullptr)
17880 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
17882 maybe_set_alignment (cu
, die
, range_type
);
17884 set_die_type (die
, range_type
, cu
);
17886 /* set_die_type should be already done. */
17887 set_descriptive_type (range_type
, die
, cu
);
17892 static struct type
*
17893 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17897 type
= init_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
, TYPE_CODE_VOID
,0,
17899 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
17901 /* In Ada, an unspecified type is typically used when the description
17902 of the type is deferred to a different unit. When encountering
17903 such a type, we treat it as a stub, and try to resolve it later on,
17905 if (cu
->language
== language_ada
)
17906 TYPE_STUB (type
) = 1;
17908 return set_die_type (die
, type
, cu
);
17911 /* Read a single die and all its descendents. Set the die's sibling
17912 field to NULL; set other fields in the die correctly, and set all
17913 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
17914 location of the info_ptr after reading all of those dies. PARENT
17915 is the parent of the die in question. */
17917 static struct die_info
*
17918 read_die_and_children (const struct die_reader_specs
*reader
,
17919 const gdb_byte
*info_ptr
,
17920 const gdb_byte
**new_info_ptr
,
17921 struct die_info
*parent
)
17923 struct die_info
*die
;
17924 const gdb_byte
*cur_ptr
;
17927 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, &has_children
, 0);
17930 *new_info_ptr
= cur_ptr
;
17933 store_in_ref_table (die
, reader
->cu
);
17936 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
17940 *new_info_ptr
= cur_ptr
;
17943 die
->sibling
= NULL
;
17944 die
->parent
= parent
;
17948 /* Read a die, all of its descendents, and all of its siblings; set
17949 all of the fields of all of the dies correctly. Arguments are as
17950 in read_die_and_children. */
17952 static struct die_info
*
17953 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
17954 const gdb_byte
*info_ptr
,
17955 const gdb_byte
**new_info_ptr
,
17956 struct die_info
*parent
)
17958 struct die_info
*first_die
, *last_sibling
;
17959 const gdb_byte
*cur_ptr
;
17961 cur_ptr
= info_ptr
;
17962 first_die
= last_sibling
= NULL
;
17966 struct die_info
*die
17967 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
17971 *new_info_ptr
= cur_ptr
;
17978 last_sibling
->sibling
= die
;
17980 last_sibling
= die
;
17984 /* Read a die, all of its descendents, and all of its siblings; set
17985 all of the fields of all of the dies correctly. Arguments are as
17986 in read_die_and_children.
17987 This the main entry point for reading a DIE and all its children. */
17989 static struct die_info
*
17990 read_die_and_siblings (const struct die_reader_specs
*reader
,
17991 const gdb_byte
*info_ptr
,
17992 const gdb_byte
**new_info_ptr
,
17993 struct die_info
*parent
)
17995 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
17996 new_info_ptr
, parent
);
17998 if (dwarf_die_debug
)
18000 fprintf_unfiltered (gdb_stdlog
,
18001 "Read die from %s@0x%x of %s:\n",
18002 reader
->die_section
->get_name (),
18003 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18004 bfd_get_filename (reader
->abfd
));
18005 dump_die (die
, dwarf_die_debug
);
18011 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
18013 The caller is responsible for filling in the extra attributes
18014 and updating (*DIEP)->num_attrs.
18015 Set DIEP to point to a newly allocated die with its information,
18016 except for its child, sibling, and parent fields.
18017 Set HAS_CHILDREN to tell whether the die has children or not. */
18019 static const gdb_byte
*
18020 read_full_die_1 (const struct die_reader_specs
*reader
,
18021 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18022 int *has_children
, int num_extra_attrs
)
18024 unsigned int abbrev_number
, bytes_read
, i
;
18025 struct abbrev_info
*abbrev
;
18026 struct die_info
*die
;
18027 struct dwarf2_cu
*cu
= reader
->cu
;
18028 bfd
*abfd
= reader
->abfd
;
18030 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
18031 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18032 info_ptr
+= bytes_read
;
18033 if (!abbrev_number
)
18040 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
18042 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
18044 bfd_get_filename (abfd
));
18046 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
18047 die
->sect_off
= sect_off
;
18048 die
->tag
= abbrev
->tag
;
18049 die
->abbrev
= abbrev_number
;
18051 /* Make the result usable.
18052 The caller needs to update num_attrs after adding the extra
18054 die
->num_attrs
= abbrev
->num_attrs
;
18056 std::vector
<int> indexes_that_need_reprocess
;
18057 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18059 bool need_reprocess
;
18061 read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
18062 info_ptr
, &need_reprocess
);
18063 if (need_reprocess
)
18064 indexes_that_need_reprocess
.push_back (i
);
18067 struct attribute
*attr
= dwarf2_attr_no_follow (die
, DW_AT_str_offsets_base
);
18068 if (attr
!= nullptr)
18069 cu
->str_offsets_base
= DW_UNSND (attr
);
18071 auto maybe_addr_base
= lookup_addr_base(die
);
18072 if (maybe_addr_base
.has_value ())
18073 cu
->addr_base
= *maybe_addr_base
;
18074 for (int index
: indexes_that_need_reprocess
)
18075 read_attribute_reprocess (reader
, &die
->attrs
[index
]);
18077 *has_children
= abbrev
->has_children
;
18081 /* Read a die and all its attributes.
18082 Set DIEP to point to a newly allocated die with its information,
18083 except for its child, sibling, and parent fields.
18084 Set HAS_CHILDREN to tell whether the die has children or not. */
18086 static const gdb_byte
*
18087 read_full_die (const struct die_reader_specs
*reader
,
18088 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18091 const gdb_byte
*result
;
18093 result
= read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
18095 if (dwarf_die_debug
)
18097 fprintf_unfiltered (gdb_stdlog
,
18098 "Read die from %s@0x%x of %s:\n",
18099 reader
->die_section
->get_name (),
18100 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18101 bfd_get_filename (reader
->abfd
));
18102 dump_die (*diep
, dwarf_die_debug
);
18109 /* Returns nonzero if TAG represents a type that we might generate a partial
18113 is_type_tag_for_partial (int tag
)
18118 /* Some types that would be reasonable to generate partial symbols for,
18119 that we don't at present. */
18120 case DW_TAG_array_type
:
18121 case DW_TAG_file_type
:
18122 case DW_TAG_ptr_to_member_type
:
18123 case DW_TAG_set_type
:
18124 case DW_TAG_string_type
:
18125 case DW_TAG_subroutine_type
:
18127 case DW_TAG_base_type
:
18128 case DW_TAG_class_type
:
18129 case DW_TAG_interface_type
:
18130 case DW_TAG_enumeration_type
:
18131 case DW_TAG_structure_type
:
18132 case DW_TAG_subrange_type
:
18133 case DW_TAG_typedef
:
18134 case DW_TAG_union_type
:
18141 /* Load all DIEs that are interesting for partial symbols into memory. */
18143 static struct partial_die_info
*
18144 load_partial_dies (const struct die_reader_specs
*reader
,
18145 const gdb_byte
*info_ptr
, int building_psymtab
)
18147 struct dwarf2_cu
*cu
= reader
->cu
;
18148 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18149 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18150 unsigned int bytes_read
;
18151 unsigned int load_all
= 0;
18152 int nesting_level
= 1;
18157 gdb_assert (cu
->per_cu
!= NULL
);
18158 if (cu
->per_cu
->load_all_dies
)
18162 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18166 &cu
->comp_unit_obstack
,
18167 hashtab_obstack_allocate
,
18168 dummy_obstack_deallocate
);
18172 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
18174 /* A NULL abbrev means the end of a series of children. */
18175 if (abbrev
== NULL
)
18177 if (--nesting_level
== 0)
18180 info_ptr
+= bytes_read
;
18181 last_die
= parent_die
;
18182 parent_die
= parent_die
->die_parent
;
18186 /* Check for template arguments. We never save these; if
18187 they're seen, we just mark the parent, and go on our way. */
18188 if (parent_die
!= NULL
18189 && cu
->language
== language_cplus
18190 && (abbrev
->tag
== DW_TAG_template_type_param
18191 || abbrev
->tag
== DW_TAG_template_value_param
))
18193 parent_die
->has_template_arguments
= 1;
18197 /* We don't need a partial DIE for the template argument. */
18198 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18203 /* We only recurse into c++ subprograms looking for template arguments.
18204 Skip their other children. */
18206 && cu
->language
== language_cplus
18207 && parent_die
!= NULL
18208 && parent_die
->tag
== DW_TAG_subprogram
)
18210 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18214 /* Check whether this DIE is interesting enough to save. Normally
18215 we would not be interested in members here, but there may be
18216 later variables referencing them via DW_AT_specification (for
18217 static members). */
18219 && !is_type_tag_for_partial (abbrev
->tag
)
18220 && abbrev
->tag
!= DW_TAG_constant
18221 && abbrev
->tag
!= DW_TAG_enumerator
18222 && abbrev
->tag
!= DW_TAG_subprogram
18223 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18224 && abbrev
->tag
!= DW_TAG_lexical_block
18225 && abbrev
->tag
!= DW_TAG_variable
18226 && abbrev
->tag
!= DW_TAG_namespace
18227 && abbrev
->tag
!= DW_TAG_module
18228 && abbrev
->tag
!= DW_TAG_member
18229 && abbrev
->tag
!= DW_TAG_imported_unit
18230 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18232 /* Otherwise we skip to the next sibling, if any. */
18233 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18237 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
18240 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
18242 /* This two-pass algorithm for processing partial symbols has a
18243 high cost in cache pressure. Thus, handle some simple cases
18244 here which cover the majority of C partial symbols. DIEs
18245 which neither have specification tags in them, nor could have
18246 specification tags elsewhere pointing at them, can simply be
18247 processed and discarded.
18249 This segment is also optional; scan_partial_symbols and
18250 add_partial_symbol will handle these DIEs if we chain
18251 them in normally. When compilers which do not emit large
18252 quantities of duplicate debug information are more common,
18253 this code can probably be removed. */
18255 /* Any complete simple types at the top level (pretty much all
18256 of them, for a language without namespaces), can be processed
18258 if (parent_die
== NULL
18259 && pdi
.has_specification
== 0
18260 && pdi
.is_declaration
== 0
18261 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
18262 || pdi
.tag
== DW_TAG_base_type
18263 || pdi
.tag
== DW_TAG_subrange_type
))
18265 if (building_psymtab
&& pdi
.name
!= NULL
)
18266 add_psymbol_to_list (pdi
.name
, false,
18267 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
18268 psymbol_placement::STATIC
,
18269 0, cu
->language
, objfile
);
18270 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18274 /* The exception for DW_TAG_typedef with has_children above is
18275 a workaround of GCC PR debug/47510. In the case of this complaint
18276 type_name_or_error will error on such types later.
18278 GDB skipped children of DW_TAG_typedef by the shortcut above and then
18279 it could not find the child DIEs referenced later, this is checked
18280 above. In correct DWARF DW_TAG_typedef should have no children. */
18282 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
18283 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
18284 "- DIE at %s [in module %s]"),
18285 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
18287 /* If we're at the second level, and we're an enumerator, and
18288 our parent has no specification (meaning possibly lives in a
18289 namespace elsewhere), then we can add the partial symbol now
18290 instead of queueing it. */
18291 if (pdi
.tag
== DW_TAG_enumerator
18292 && parent_die
!= NULL
18293 && parent_die
->die_parent
== NULL
18294 && parent_die
->tag
== DW_TAG_enumeration_type
18295 && parent_die
->has_specification
== 0)
18297 if (pdi
.name
== NULL
)
18298 complaint (_("malformed enumerator DIE ignored"));
18299 else if (building_psymtab
)
18300 add_psymbol_to_list (pdi
.name
, false,
18301 VAR_DOMAIN
, LOC_CONST
, -1,
18302 cu
->language
== language_cplus
18303 ? psymbol_placement::GLOBAL
18304 : psymbol_placement::STATIC
,
18305 0, cu
->language
, objfile
);
18307 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18311 struct partial_die_info
*part_die
18312 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
18314 /* We'll save this DIE so link it in. */
18315 part_die
->die_parent
= parent_die
;
18316 part_die
->die_sibling
= NULL
;
18317 part_die
->die_child
= NULL
;
18319 if (last_die
&& last_die
== parent_die
)
18320 last_die
->die_child
= part_die
;
18322 last_die
->die_sibling
= part_die
;
18324 last_die
= part_die
;
18326 if (first_die
== NULL
)
18327 first_die
= part_die
;
18329 /* Maybe add the DIE to the hash table. Not all DIEs that we
18330 find interesting need to be in the hash table, because we
18331 also have the parent/sibling/child chains; only those that we
18332 might refer to by offset later during partial symbol reading.
18334 For now this means things that might have be the target of a
18335 DW_AT_specification, DW_AT_abstract_origin, or
18336 DW_AT_extension. DW_AT_extension will refer only to
18337 namespaces; DW_AT_abstract_origin refers to functions (and
18338 many things under the function DIE, but we do not recurse
18339 into function DIEs during partial symbol reading) and
18340 possibly variables as well; DW_AT_specification refers to
18341 declarations. Declarations ought to have the DW_AT_declaration
18342 flag. It happens that GCC forgets to put it in sometimes, but
18343 only for functions, not for types.
18345 Adding more things than necessary to the hash table is harmless
18346 except for the performance cost. Adding too few will result in
18347 wasted time in find_partial_die, when we reread the compilation
18348 unit with load_all_dies set. */
18351 || abbrev
->tag
== DW_TAG_constant
18352 || abbrev
->tag
== DW_TAG_subprogram
18353 || abbrev
->tag
== DW_TAG_variable
18354 || abbrev
->tag
== DW_TAG_namespace
18355 || part_die
->is_declaration
)
18359 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
18360 to_underlying (part_die
->sect_off
),
18365 /* For some DIEs we want to follow their children (if any). For C
18366 we have no reason to follow the children of structures; for other
18367 languages we have to, so that we can get at method physnames
18368 to infer fully qualified class names, for DW_AT_specification,
18369 and for C++ template arguments. For C++, we also look one level
18370 inside functions to find template arguments (if the name of the
18371 function does not already contain the template arguments).
18373 For Ada and Fortran, we need to scan the children of subprograms
18374 and lexical blocks as well because these languages allow the
18375 definition of nested entities that could be interesting for the
18376 debugger, such as nested subprograms for instance. */
18377 if (last_die
->has_children
18379 || last_die
->tag
== DW_TAG_namespace
18380 || last_die
->tag
== DW_TAG_module
18381 || last_die
->tag
== DW_TAG_enumeration_type
18382 || (cu
->language
== language_cplus
18383 && last_die
->tag
== DW_TAG_subprogram
18384 && (last_die
->name
== NULL
18385 || strchr (last_die
->name
, '<') == NULL
))
18386 || (cu
->language
!= language_c
18387 && (last_die
->tag
== DW_TAG_class_type
18388 || last_die
->tag
== DW_TAG_interface_type
18389 || last_die
->tag
== DW_TAG_structure_type
18390 || last_die
->tag
== DW_TAG_union_type
))
18391 || ((cu
->language
== language_ada
18392 || cu
->language
== language_fortran
)
18393 && (last_die
->tag
== DW_TAG_subprogram
18394 || last_die
->tag
== DW_TAG_lexical_block
))))
18397 parent_die
= last_die
;
18401 /* Otherwise we skip to the next sibling, if any. */
18402 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
18404 /* Back to the top, do it again. */
18408 partial_die_info::partial_die_info (sect_offset sect_off_
,
18409 struct abbrev_info
*abbrev
)
18410 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
18414 /* Read a minimal amount of information into the minimal die structure.
18415 INFO_PTR should point just after the initial uleb128 of a DIE. */
18418 partial_die_info::read (const struct die_reader_specs
*reader
,
18419 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
18421 struct dwarf2_cu
*cu
= reader
->cu
;
18422 struct dwarf2_per_objfile
*dwarf2_per_objfile
18423 = cu
->per_cu
->dwarf2_per_objfile
;
18425 int has_low_pc_attr
= 0;
18426 int has_high_pc_attr
= 0;
18427 int high_pc_relative
= 0;
18429 std::vector
<struct attribute
> attr_vec (abbrev
.num_attrs
);
18430 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
18432 bool need_reprocess
;
18433 info_ptr
= read_attribute (reader
, &attr_vec
[i
], &abbrev
.attrs
[i
],
18434 info_ptr
, &need_reprocess
);
18435 /* String and address offsets that need to do the reprocessing have
18436 already been read at this point, so there is no need to wait until
18437 the loop terminates to do the reprocessing. */
18438 if (need_reprocess
)
18439 read_attribute_reprocess (reader
, &attr_vec
[i
]);
18440 attribute
&attr
= attr_vec
[i
];
18441 /* Store the data if it is of an attribute we want to keep in a
18442 partial symbol table. */
18448 case DW_TAG_compile_unit
:
18449 case DW_TAG_partial_unit
:
18450 case DW_TAG_type_unit
:
18451 /* Compilation units have a DW_AT_name that is a filename, not
18452 a source language identifier. */
18453 case DW_TAG_enumeration_type
:
18454 case DW_TAG_enumerator
:
18455 /* These tags always have simple identifiers already; no need
18456 to canonicalize them. */
18457 name
= DW_STRING (&attr
);
18461 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18464 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
18465 &objfile
->per_bfd
->storage_obstack
);
18470 case DW_AT_linkage_name
:
18471 case DW_AT_MIPS_linkage_name
:
18472 /* Note that both forms of linkage name might appear. We
18473 assume they will be the same, and we only store the last
18475 linkage_name
= DW_STRING (&attr
);
18478 has_low_pc_attr
= 1;
18479 lowpc
= attr
.value_as_address ();
18481 case DW_AT_high_pc
:
18482 has_high_pc_attr
= 1;
18483 highpc
= attr
.value_as_address ();
18484 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
18485 high_pc_relative
= 1;
18487 case DW_AT_location
:
18488 /* Support the .debug_loc offsets. */
18489 if (attr
.form_is_block ())
18491 d
.locdesc
= DW_BLOCK (&attr
);
18493 else if (attr
.form_is_section_offset ())
18495 dwarf2_complex_location_expr_complaint ();
18499 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18500 "partial symbol information");
18503 case DW_AT_external
:
18504 is_external
= DW_UNSND (&attr
);
18506 case DW_AT_declaration
:
18507 is_declaration
= DW_UNSND (&attr
);
18512 case DW_AT_abstract_origin
:
18513 case DW_AT_specification
:
18514 case DW_AT_extension
:
18515 has_specification
= 1;
18516 spec_offset
= dwarf2_get_ref_die_offset (&attr
);
18517 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18518 || cu
->per_cu
->is_dwz
);
18520 case DW_AT_sibling
:
18521 /* Ignore absolute siblings, they might point outside of
18522 the current compile unit. */
18523 if (attr
.form
== DW_FORM_ref_addr
)
18524 complaint (_("ignoring absolute DW_AT_sibling"));
18527 const gdb_byte
*buffer
= reader
->buffer
;
18528 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
18529 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
18531 if (sibling_ptr
< info_ptr
)
18532 complaint (_("DW_AT_sibling points backwards"));
18533 else if (sibling_ptr
> reader
->buffer_end
)
18534 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
18536 sibling
= sibling_ptr
;
18539 case DW_AT_byte_size
:
18542 case DW_AT_const_value
:
18543 has_const_value
= 1;
18545 case DW_AT_calling_convention
:
18546 /* DWARF doesn't provide a way to identify a program's source-level
18547 entry point. DW_AT_calling_convention attributes are only meant
18548 to describe functions' calling conventions.
18550 However, because it's a necessary piece of information in
18551 Fortran, and before DWARF 4 DW_CC_program was the only
18552 piece of debugging information whose definition refers to
18553 a 'main program' at all, several compilers marked Fortran
18554 main programs with DW_CC_program --- even when those
18555 functions use the standard calling conventions.
18557 Although DWARF now specifies a way to provide this
18558 information, we support this practice for backward
18560 if (DW_UNSND (&attr
) == DW_CC_program
18561 && cu
->language
== language_fortran
)
18562 main_subprogram
= 1;
18565 if (DW_UNSND (&attr
) == DW_INL_inlined
18566 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
18567 may_be_inlined
= 1;
18571 if (tag
== DW_TAG_imported_unit
)
18573 d
.sect_off
= dwarf2_get_ref_die_offset (&attr
);
18574 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18575 || cu
->per_cu
->is_dwz
);
18579 case DW_AT_main_subprogram
:
18580 main_subprogram
= DW_UNSND (&attr
);
18585 /* It would be nice to reuse dwarf2_get_pc_bounds here,
18586 but that requires a full DIE, so instead we just
18588 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
18589 unsigned int ranges_offset
= (DW_UNSND (&attr
)
18590 + (need_ranges_base
18594 /* Value of the DW_AT_ranges attribute is the offset in the
18595 .debug_ranges section. */
18596 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
18607 /* For Ada, if both the name and the linkage name appear, we prefer
18608 the latter. This lets "catch exception" work better, regardless
18609 of the order in which the name and linkage name were emitted.
18610 Really, though, this is just a workaround for the fact that gdb
18611 doesn't store both the name and the linkage name. */
18612 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
18613 name
= linkage_name
;
18615 if (high_pc_relative
)
18618 if (has_low_pc_attr
&& has_high_pc_attr
)
18620 /* When using the GNU linker, .gnu.linkonce. sections are used to
18621 eliminate duplicate copies of functions and vtables and such.
18622 The linker will arbitrarily choose one and discard the others.
18623 The AT_*_pc values for such functions refer to local labels in
18624 these sections. If the section from that file was discarded, the
18625 labels are not in the output, so the relocs get a value of 0.
18626 If this is a discarded function, mark the pc bounds as invalid,
18627 so that GDB will ignore it. */
18628 if (lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
18630 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18631 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18633 complaint (_("DW_AT_low_pc %s is zero "
18634 "for DIE at %s [in module %s]"),
18635 paddress (gdbarch
, lowpc
),
18636 sect_offset_str (sect_off
),
18637 objfile_name (objfile
));
18639 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
18640 else if (lowpc
>= highpc
)
18642 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18643 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18645 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
18646 "for DIE at %s [in module %s]"),
18647 paddress (gdbarch
, lowpc
),
18648 paddress (gdbarch
, highpc
),
18649 sect_offset_str (sect_off
),
18650 objfile_name (objfile
));
18659 /* Find a cached partial DIE at OFFSET in CU. */
18661 struct partial_die_info
*
18662 dwarf2_cu::find_partial_die (sect_offset sect_off
)
18664 struct partial_die_info
*lookup_die
= NULL
;
18665 struct partial_die_info
part_die (sect_off
);
18667 lookup_die
= ((struct partial_die_info
*)
18668 htab_find_with_hash (partial_dies
, &part_die
,
18669 to_underlying (sect_off
)));
18674 /* Find a partial DIE at OFFSET, which may or may not be in CU,
18675 except in the case of .debug_types DIEs which do not reference
18676 outside their CU (they do however referencing other types via
18677 DW_FORM_ref_sig8). */
18679 static const struct cu_partial_die_info
18680 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
18682 struct dwarf2_per_objfile
*dwarf2_per_objfile
18683 = cu
->per_cu
->dwarf2_per_objfile
;
18684 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18685 struct dwarf2_per_cu_data
*per_cu
= NULL
;
18686 struct partial_die_info
*pd
= NULL
;
18688 if (offset_in_dwz
== cu
->per_cu
->is_dwz
18689 && offset_in_cu_p (&cu
->header
, sect_off
))
18691 pd
= cu
->find_partial_die (sect_off
);
18694 /* We missed recording what we needed.
18695 Load all dies and try again. */
18696 per_cu
= cu
->per_cu
;
18700 /* TUs don't reference other CUs/TUs (except via type signatures). */
18701 if (cu
->per_cu
->is_debug_types
)
18703 error (_("Dwarf Error: Type Unit at offset %s contains"
18704 " external reference to offset %s [in module %s].\n"),
18705 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
18706 bfd_get_filename (objfile
->obfd
));
18708 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
18709 dwarf2_per_objfile
);
18711 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
18712 load_partial_comp_unit (per_cu
);
18714 per_cu
->cu
->last_used
= 0;
18715 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18718 /* If we didn't find it, and not all dies have been loaded,
18719 load them all and try again. */
18721 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
18723 per_cu
->load_all_dies
= 1;
18725 /* This is nasty. When we reread the DIEs, somewhere up the call chain
18726 THIS_CU->cu may already be in use. So we can't just free it and
18727 replace its DIEs with the ones we read in. Instead, we leave those
18728 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
18729 and clobber THIS_CU->cu->partial_dies with the hash table for the new
18731 load_partial_comp_unit (per_cu
);
18733 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18737 internal_error (__FILE__
, __LINE__
,
18738 _("could not find partial DIE %s "
18739 "in cache [from module %s]\n"),
18740 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
18741 return { per_cu
->cu
, pd
};
18744 /* See if we can figure out if the class lives in a namespace. We do
18745 this by looking for a member function; its demangled name will
18746 contain namespace info, if there is any. */
18749 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
18750 struct dwarf2_cu
*cu
)
18752 /* NOTE: carlton/2003-10-07: Getting the info this way changes
18753 what template types look like, because the demangler
18754 frequently doesn't give the same name as the debug info. We
18755 could fix this by only using the demangled name to get the
18756 prefix (but see comment in read_structure_type). */
18758 struct partial_die_info
*real_pdi
;
18759 struct partial_die_info
*child_pdi
;
18761 /* If this DIE (this DIE's specification, if any) has a parent, then
18762 we should not do this. We'll prepend the parent's fully qualified
18763 name when we create the partial symbol. */
18765 real_pdi
= struct_pdi
;
18766 while (real_pdi
->has_specification
)
18768 auto res
= find_partial_die (real_pdi
->spec_offset
,
18769 real_pdi
->spec_is_dwz
, cu
);
18770 real_pdi
= res
.pdi
;
18774 if (real_pdi
->die_parent
!= NULL
)
18777 for (child_pdi
= struct_pdi
->die_child
;
18779 child_pdi
= child_pdi
->die_sibling
)
18781 if (child_pdi
->tag
== DW_TAG_subprogram
18782 && child_pdi
->linkage_name
!= NULL
)
18784 gdb::unique_xmalloc_ptr
<char> actual_class_name
18785 (language_class_name_from_physname (cu
->language_defn
,
18786 child_pdi
->linkage_name
));
18787 if (actual_class_name
!= NULL
)
18789 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18791 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
18792 actual_class_name
.get ());
18800 partial_die_info::fixup (struct dwarf2_cu
*cu
)
18802 /* Once we've fixed up a die, there's no point in doing so again.
18803 This also avoids a memory leak if we were to call
18804 guess_partial_die_structure_name multiple times. */
18808 /* If we found a reference attribute and the DIE has no name, try
18809 to find a name in the referred to DIE. */
18811 if (name
== NULL
&& has_specification
)
18813 struct partial_die_info
*spec_die
;
18815 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18816 spec_die
= res
.pdi
;
18819 spec_die
->fixup (cu
);
18821 if (spec_die
->name
)
18823 name
= spec_die
->name
;
18825 /* Copy DW_AT_external attribute if it is set. */
18826 if (spec_die
->is_external
)
18827 is_external
= spec_die
->is_external
;
18831 /* Set default names for some unnamed DIEs. */
18833 if (name
== NULL
&& tag
== DW_TAG_namespace
)
18834 name
= CP_ANONYMOUS_NAMESPACE_STR
;
18836 /* If there is no parent die to provide a namespace, and there are
18837 children, see if we can determine the namespace from their linkage
18839 if (cu
->language
== language_cplus
18840 && !cu
->per_cu
->dwarf2_per_objfile
->types
.empty ()
18841 && die_parent
== NULL
18843 && (tag
== DW_TAG_class_type
18844 || tag
== DW_TAG_structure_type
18845 || tag
== DW_TAG_union_type
))
18846 guess_partial_die_structure_name (this, cu
);
18848 /* GCC might emit a nameless struct or union that has a linkage
18849 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
18851 && (tag
== DW_TAG_class_type
18852 || tag
== DW_TAG_interface_type
18853 || tag
== DW_TAG_structure_type
18854 || tag
== DW_TAG_union_type
)
18855 && linkage_name
!= NULL
)
18857 gdb::unique_xmalloc_ptr
<char> demangled
18858 (gdb_demangle (linkage_name
, DMGL_TYPES
));
18859 if (demangled
!= nullptr)
18863 /* Strip any leading namespaces/classes, keep only the base name.
18864 DW_AT_name for named DIEs does not contain the prefixes. */
18865 base
= strrchr (demangled
.get (), ':');
18866 if (base
&& base
> demangled
.get () && base
[-1] == ':')
18869 base
= demangled
.get ();
18871 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18872 name
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
, base
);
18879 /* Process the attributes that had to be skipped in the first round. These
18880 attributes are the ones that need str_offsets_base or addr_base attributes.
18881 They could not have been processed in the first round, because at the time
18882 the values of str_offsets_base or addr_base may not have been known. */
18883 void read_attribute_reprocess (const struct die_reader_specs
*reader
,
18884 struct attribute
*attr
)
18886 struct dwarf2_cu
*cu
= reader
->cu
;
18887 switch (attr
->form
)
18889 case DW_FORM_addrx
:
18890 case DW_FORM_GNU_addr_index
:
18891 DW_ADDR (attr
) = read_addr_index (cu
, DW_UNSND (attr
));
18894 case DW_FORM_strx1
:
18895 case DW_FORM_strx2
:
18896 case DW_FORM_strx3
:
18897 case DW_FORM_strx4
:
18898 case DW_FORM_GNU_str_index
:
18900 unsigned int str_index
= DW_UNSND (attr
);
18901 if (reader
->dwo_file
!= NULL
)
18903 DW_STRING (attr
) = read_dwo_str_index (reader
, str_index
);
18904 DW_STRING_IS_CANONICAL (attr
) = 0;
18908 DW_STRING (attr
) = read_stub_str_index (cu
, str_index
);
18909 DW_STRING_IS_CANONICAL (attr
) = 0;
18914 gdb_assert_not_reached (_("Unexpected DWARF form."));
18918 /* Read an attribute value described by an attribute form. */
18920 static const gdb_byte
*
18921 read_attribute_value (const struct die_reader_specs
*reader
,
18922 struct attribute
*attr
, unsigned form
,
18923 LONGEST implicit_const
, const gdb_byte
*info_ptr
,
18924 bool *need_reprocess
)
18926 struct dwarf2_cu
*cu
= reader
->cu
;
18927 struct dwarf2_per_objfile
*dwarf2_per_objfile
18928 = cu
->per_cu
->dwarf2_per_objfile
;
18929 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18930 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18931 bfd
*abfd
= reader
->abfd
;
18932 struct comp_unit_head
*cu_header
= &cu
->header
;
18933 unsigned int bytes_read
;
18934 struct dwarf_block
*blk
;
18935 *need_reprocess
= false;
18937 attr
->form
= (enum dwarf_form
) form
;
18940 case DW_FORM_ref_addr
:
18941 if (cu
->header
.version
== 2)
18942 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
18944 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
18945 &cu
->header
, &bytes_read
);
18946 info_ptr
+= bytes_read
;
18948 case DW_FORM_GNU_ref_alt
:
18949 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
18950 info_ptr
+= bytes_read
;
18953 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
18954 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
18955 info_ptr
+= bytes_read
;
18957 case DW_FORM_block2
:
18958 blk
= dwarf_alloc_block (cu
);
18959 blk
->size
= read_2_bytes (abfd
, info_ptr
);
18961 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18962 info_ptr
+= blk
->size
;
18963 DW_BLOCK (attr
) = blk
;
18965 case DW_FORM_block4
:
18966 blk
= dwarf_alloc_block (cu
);
18967 blk
->size
= read_4_bytes (abfd
, info_ptr
);
18969 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18970 info_ptr
+= blk
->size
;
18971 DW_BLOCK (attr
) = blk
;
18973 case DW_FORM_data2
:
18974 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
18977 case DW_FORM_data4
:
18978 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
18981 case DW_FORM_data8
:
18982 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
18985 case DW_FORM_data16
:
18986 blk
= dwarf_alloc_block (cu
);
18988 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
18990 DW_BLOCK (attr
) = blk
;
18992 case DW_FORM_sec_offset
:
18993 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
18994 info_ptr
+= bytes_read
;
18996 case DW_FORM_string
:
18997 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
18998 DW_STRING_IS_CANONICAL (attr
) = 0;
18999 info_ptr
+= bytes_read
;
19002 if (!cu
->per_cu
->is_dwz
)
19004 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
19005 abfd
, info_ptr
, cu_header
,
19007 DW_STRING_IS_CANONICAL (attr
) = 0;
19008 info_ptr
+= bytes_read
;
19012 case DW_FORM_line_strp
:
19013 if (!cu
->per_cu
->is_dwz
)
19015 DW_STRING (attr
) = read_indirect_line_string (dwarf2_per_objfile
,
19017 cu_header
, &bytes_read
);
19018 DW_STRING_IS_CANONICAL (attr
) = 0;
19019 info_ptr
+= bytes_read
;
19023 case DW_FORM_GNU_strp_alt
:
19025 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19026 LONGEST str_offset
= read_offset (abfd
, info_ptr
, cu_header
,
19029 DW_STRING (attr
) = read_indirect_string_from_dwz (objfile
,
19031 DW_STRING_IS_CANONICAL (attr
) = 0;
19032 info_ptr
+= bytes_read
;
19035 case DW_FORM_exprloc
:
19036 case DW_FORM_block
:
19037 blk
= dwarf_alloc_block (cu
);
19038 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19039 info_ptr
+= bytes_read
;
19040 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19041 info_ptr
+= blk
->size
;
19042 DW_BLOCK (attr
) = blk
;
19044 case DW_FORM_block1
:
19045 blk
= dwarf_alloc_block (cu
);
19046 blk
->size
= read_1_byte (abfd
, info_ptr
);
19048 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19049 info_ptr
+= blk
->size
;
19050 DW_BLOCK (attr
) = blk
;
19052 case DW_FORM_data1
:
19053 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19057 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19060 case DW_FORM_flag_present
:
19061 DW_UNSND (attr
) = 1;
19063 case DW_FORM_sdata
:
19064 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19065 info_ptr
+= bytes_read
;
19067 case DW_FORM_udata
:
19068 case DW_FORM_rnglistx
:
19069 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19070 info_ptr
+= bytes_read
;
19073 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19074 + read_1_byte (abfd
, info_ptr
));
19078 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19079 + read_2_bytes (abfd
, info_ptr
));
19083 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19084 + read_4_bytes (abfd
, info_ptr
));
19088 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19089 + read_8_bytes (abfd
, info_ptr
));
19092 case DW_FORM_ref_sig8
:
19093 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
19096 case DW_FORM_ref_udata
:
19097 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19098 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
19099 info_ptr
+= bytes_read
;
19101 case DW_FORM_indirect
:
19102 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19103 info_ptr
+= bytes_read
;
19104 if (form
== DW_FORM_implicit_const
)
19106 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19107 info_ptr
+= bytes_read
;
19109 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
19110 info_ptr
, need_reprocess
);
19112 case DW_FORM_implicit_const
:
19113 DW_SND (attr
) = implicit_const
;
19115 case DW_FORM_addrx
:
19116 case DW_FORM_GNU_addr_index
:
19117 *need_reprocess
= true;
19118 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19119 info_ptr
+= bytes_read
;
19122 case DW_FORM_strx1
:
19123 case DW_FORM_strx2
:
19124 case DW_FORM_strx3
:
19125 case DW_FORM_strx4
:
19126 case DW_FORM_GNU_str_index
:
19128 ULONGEST str_index
;
19129 if (form
== DW_FORM_strx1
)
19131 str_index
= read_1_byte (abfd
, info_ptr
);
19134 else if (form
== DW_FORM_strx2
)
19136 str_index
= read_2_bytes (abfd
, info_ptr
);
19139 else if (form
== DW_FORM_strx3
)
19141 str_index
= read_3_bytes (abfd
, info_ptr
);
19144 else if (form
== DW_FORM_strx4
)
19146 str_index
= read_4_bytes (abfd
, info_ptr
);
19151 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19152 info_ptr
+= bytes_read
;
19154 *need_reprocess
= true;
19155 DW_UNSND (attr
) = str_index
;
19159 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
19160 dwarf_form_name (form
),
19161 bfd_get_filename (abfd
));
19165 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
19166 attr
->form
= DW_FORM_GNU_ref_alt
;
19168 /* We have seen instances where the compiler tried to emit a byte
19169 size attribute of -1 which ended up being encoded as an unsigned
19170 0xffffffff. Although 0xffffffff is technically a valid size value,
19171 an object of this size seems pretty unlikely so we can relatively
19172 safely treat these cases as if the size attribute was invalid and
19173 treat them as zero by default. */
19174 if (attr
->name
== DW_AT_byte_size
19175 && form
== DW_FORM_data4
19176 && DW_UNSND (attr
) >= 0xffffffff)
19179 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
19180 hex_string (DW_UNSND (attr
)));
19181 DW_UNSND (attr
) = 0;
19187 /* Read an attribute described by an abbreviated attribute. */
19189 static const gdb_byte
*
19190 read_attribute (const struct die_reader_specs
*reader
,
19191 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
19192 const gdb_byte
*info_ptr
, bool *need_reprocess
)
19194 attr
->name
= abbrev
->name
;
19195 return read_attribute_value (reader
, attr
, abbrev
->form
,
19196 abbrev
->implicit_const
, info_ptr
,
19201 read_address (bfd
*abfd
, const gdb_byte
*buf
, struct dwarf2_cu
*cu
,
19202 unsigned int *bytes_read
)
19204 struct comp_unit_head
*cu_header
= &cu
->header
;
19205 CORE_ADDR retval
= 0;
19207 if (cu_header
->signed_addr_p
)
19209 switch (cu_header
->addr_size
)
19212 retval
= bfd_get_signed_16 (abfd
, buf
);
19215 retval
= bfd_get_signed_32 (abfd
, buf
);
19218 retval
= bfd_get_signed_64 (abfd
, buf
);
19221 internal_error (__FILE__
, __LINE__
,
19222 _("read_address: bad switch, signed [in module %s]"),
19223 bfd_get_filename (abfd
));
19228 switch (cu_header
->addr_size
)
19231 retval
= bfd_get_16 (abfd
, buf
);
19234 retval
= bfd_get_32 (abfd
, buf
);
19237 retval
= bfd_get_64 (abfd
, buf
);
19240 internal_error (__FILE__
, __LINE__
,
19241 _("read_address: bad switch, "
19242 "unsigned [in module %s]"),
19243 bfd_get_filename (abfd
));
19247 *bytes_read
= cu_header
->addr_size
;
19251 /* Read the initial length from a section. The (draft) DWARF 3
19252 specification allows the initial length to take up either 4 bytes
19253 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
19254 bytes describe the length and all offsets will be 8 bytes in length
19257 An older, non-standard 64-bit format is also handled by this
19258 function. The older format in question stores the initial length
19259 as an 8-byte quantity without an escape value. Lengths greater
19260 than 2^32 aren't very common which means that the initial 4 bytes
19261 is almost always zero. Since a length value of zero doesn't make
19262 sense for the 32-bit format, this initial zero can be considered to
19263 be an escape value which indicates the presence of the older 64-bit
19264 format. As written, the code can't detect (old format) lengths
19265 greater than 4GB. If it becomes necessary to handle lengths
19266 somewhat larger than 4GB, we could allow other small values (such
19267 as the non-sensical values of 1, 2, and 3) to also be used as
19268 escape values indicating the presence of the old format.
19270 The value returned via bytes_read should be used to increment the
19271 relevant pointer after calling read_initial_length().
19273 [ Note: read_initial_length() and read_offset() are based on the
19274 document entitled "DWARF Debugging Information Format", revision
19275 3, draft 8, dated November 19, 2001. This document was obtained
19278 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
19280 This document is only a draft and is subject to change. (So beware.)
19282 Details regarding the older, non-standard 64-bit format were
19283 determined empirically by examining 64-bit ELF files produced by
19284 the SGI toolchain on an IRIX 6.5 machine.
19286 - Kevin, July 16, 2002
19290 read_initial_length (bfd
*abfd
, const gdb_byte
*buf
, unsigned int *bytes_read
)
19292 LONGEST length
= bfd_get_32 (abfd
, buf
);
19294 if (length
== 0xffffffff)
19296 length
= bfd_get_64 (abfd
, buf
+ 4);
19299 else if (length
== 0)
19301 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
19302 length
= bfd_get_64 (abfd
, buf
);
19313 /* Cover function for read_initial_length.
19314 Returns the length of the object at BUF, and stores the size of the
19315 initial length in *BYTES_READ and stores the size that offsets will be in
19317 If the initial length size is not equivalent to that specified in
19318 CU_HEADER then issue a complaint.
19319 This is useful when reading non-comp-unit headers. */
19322 read_checked_initial_length_and_offset (bfd
*abfd
, const gdb_byte
*buf
,
19323 const struct comp_unit_head
*cu_header
,
19324 unsigned int *bytes_read
,
19325 unsigned int *offset_size
)
19327 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
19329 gdb_assert (cu_header
->initial_length_size
== 4
19330 || cu_header
->initial_length_size
== 8
19331 || cu_header
->initial_length_size
== 12);
19333 if (cu_header
->initial_length_size
!= *bytes_read
)
19334 complaint (_("intermixed 32-bit and 64-bit DWARF sections"));
19336 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
19340 /* Read an offset from the data stream. The size of the offset is
19341 given by cu_header->offset_size. */
19344 read_offset (bfd
*abfd
, const gdb_byte
*buf
,
19345 const struct comp_unit_head
*cu_header
,
19346 unsigned int *bytes_read
)
19348 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
19350 *bytes_read
= cu_header
->offset_size
;
19354 /* Read an offset from the data stream. */
19357 read_offset_1 (bfd
*abfd
, const gdb_byte
*buf
, unsigned int offset_size
)
19359 LONGEST retval
= 0;
19361 switch (offset_size
)
19364 retval
= bfd_get_32 (abfd
, buf
);
19367 retval
= bfd_get_64 (abfd
, buf
);
19370 internal_error (__FILE__
, __LINE__
,
19371 _("read_offset_1: bad switch [in module %s]"),
19372 bfd_get_filename (abfd
));
19378 static const gdb_byte
*
19379 read_n_bytes (bfd
*abfd
, const gdb_byte
*buf
, unsigned int size
)
19381 /* If the size of a host char is 8 bits, we can return a pointer
19382 to the buffer, otherwise we have to copy the data to a buffer
19383 allocated on the temporary obstack. */
19384 gdb_assert (HOST_CHAR_BIT
== 8);
19388 static const char *
19389 read_direct_string (bfd
*abfd
, const gdb_byte
*buf
,
19390 unsigned int *bytes_read_ptr
)
19392 /* If the size of a host char is 8 bits, we can return a pointer
19393 to the string, otherwise we have to copy the string to a buffer
19394 allocated on the temporary obstack. */
19395 gdb_assert (HOST_CHAR_BIT
== 8);
19398 *bytes_read_ptr
= 1;
19401 *bytes_read_ptr
= strlen ((const char *) buf
) + 1;
19402 return (const char *) buf
;
19405 /* Return pointer to string at section SECT offset STR_OFFSET with error
19406 reporting strings FORM_NAME and SECT_NAME. */
19408 static const char *
19409 read_indirect_string_at_offset_from (struct objfile
*objfile
,
19410 bfd
*abfd
, LONGEST str_offset
,
19411 struct dwarf2_section_info
*sect
,
19412 const char *form_name
,
19413 const char *sect_name
)
19415 sect
->read (objfile
);
19416 if (sect
->buffer
== NULL
)
19417 error (_("%s used without %s section [in module %s]"),
19418 form_name
, sect_name
, bfd_get_filename (abfd
));
19419 if (str_offset
>= sect
->size
)
19420 error (_("%s pointing outside of %s section [in module %s]"),
19421 form_name
, sect_name
, bfd_get_filename (abfd
));
19422 gdb_assert (HOST_CHAR_BIT
== 8);
19423 if (sect
->buffer
[str_offset
] == '\0')
19425 return (const char *) (sect
->buffer
+ str_offset
);
19428 /* Return pointer to string at .debug_str offset STR_OFFSET. */
19430 static const char *
19431 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19432 bfd
*abfd
, LONGEST str_offset
)
19434 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
19436 &dwarf2_per_objfile
->str
,
19437 "DW_FORM_strp", ".debug_str");
19440 /* Return pointer to string at .debug_line_str offset STR_OFFSET. */
19442 static const char *
19443 read_indirect_line_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19444 bfd
*abfd
, LONGEST str_offset
)
19446 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
19448 &dwarf2_per_objfile
->line_str
,
19449 "DW_FORM_line_strp",
19450 ".debug_line_str");
19453 /* Read a string at offset STR_OFFSET in the .debug_str section from
19454 the .dwz file DWZ. Throw an error if the offset is too large. If
19455 the string consists of a single NUL byte, return NULL; otherwise
19456 return a pointer to the string. */
19458 static const char *
19459 read_indirect_string_from_dwz (struct objfile
*objfile
, struct dwz_file
*dwz
,
19460 LONGEST str_offset
)
19462 dwz
->str
.read (objfile
);
19464 if (dwz
->str
.buffer
== NULL
)
19465 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
19466 "section [in module %s]"),
19467 bfd_get_filename (dwz
->dwz_bfd
.get ()));
19468 if (str_offset
>= dwz
->str
.size
)
19469 error (_("DW_FORM_GNU_strp_alt pointing outside of "
19470 ".debug_str section [in module %s]"),
19471 bfd_get_filename (dwz
->dwz_bfd
.get ()));
19472 gdb_assert (HOST_CHAR_BIT
== 8);
19473 if (dwz
->str
.buffer
[str_offset
] == '\0')
19475 return (const char *) (dwz
->str
.buffer
+ str_offset
);
19478 /* Return pointer to string at .debug_str offset as read from BUF.
19479 BUF is assumed to be in a compilation unit described by CU_HEADER.
19480 Return *BYTES_READ_PTR count of bytes read from BUF. */
19482 static const char *
19483 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
19484 const gdb_byte
*buf
,
19485 const struct comp_unit_head
*cu_header
,
19486 unsigned int *bytes_read_ptr
)
19488 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
19490 return read_indirect_string_at_offset (dwarf2_per_objfile
, abfd
, str_offset
);
19493 /* Return pointer to string at .debug_line_str offset as read from BUF.
19494 BUF is assumed to be in a compilation unit described by CU_HEADER.
19495 Return *BYTES_READ_PTR count of bytes read from BUF. */
19497 static const char *
19498 read_indirect_line_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19499 bfd
*abfd
, const gdb_byte
*buf
,
19500 const struct comp_unit_head
*cu_header
,
19501 unsigned int *bytes_read_ptr
)
19503 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
19505 return read_indirect_line_string_at_offset (dwarf2_per_objfile
, abfd
,
19509 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
19510 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
19511 ADDR_SIZE is the size of addresses from the CU header. */
19514 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19515 unsigned int addr_index
, gdb::optional
<ULONGEST
> addr_base
,
19518 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19519 bfd
*abfd
= objfile
->obfd
;
19520 const gdb_byte
*info_ptr
;
19521 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
19523 dwarf2_per_objfile
->addr
.read (objfile
);
19524 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
19525 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
19526 objfile_name (objfile
));
19527 if (addr_base_or_zero
+ addr_index
* addr_size
19528 >= dwarf2_per_objfile
->addr
.size
)
19529 error (_("DW_FORM_addr_index pointing outside of "
19530 ".debug_addr section [in module %s]"),
19531 objfile_name (objfile
));
19532 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
19533 + addr_base_or_zero
+ addr_index
* addr_size
);
19534 if (addr_size
== 4)
19535 return bfd_get_32 (abfd
, info_ptr
);
19537 return bfd_get_64 (abfd
, info_ptr
);
19540 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
19543 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
19545 return read_addr_index_1 (cu
->per_cu
->dwarf2_per_objfile
, addr_index
,
19546 cu
->addr_base
, cu
->header
.addr_size
);
19549 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
19552 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
19553 unsigned int *bytes_read
)
19555 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
19556 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
19558 return read_addr_index (cu
, addr_index
);
19561 /* Given an index in .debug_addr, fetch the value.
19562 NOTE: This can be called during dwarf expression evaluation,
19563 long after the debug information has been read, and thus per_cu->cu
19564 may no longer exist. */
19567 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
19568 unsigned int addr_index
)
19570 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
19571 struct dwarf2_cu
*cu
= per_cu
->cu
;
19572 gdb::optional
<ULONGEST
> addr_base
;
19575 /* We need addr_base and addr_size.
19576 If we don't have PER_CU->cu, we have to get it.
19577 Nasty, but the alternative is storing the needed info in PER_CU,
19578 which at this point doesn't seem justified: it's not clear how frequently
19579 it would get used and it would increase the size of every PER_CU.
19580 Entry points like dwarf2_per_cu_addr_size do a similar thing
19581 so we're not in uncharted territory here.
19582 Alas we need to be a bit more complicated as addr_base is contained
19585 We don't need to read the entire CU(/TU).
19586 We just need the header and top level die.
19588 IWBN to use the aging mechanism to let us lazily later discard the CU.
19589 For now we skip this optimization. */
19593 addr_base
= cu
->addr_base
;
19594 addr_size
= cu
->header
.addr_size
;
19598 cutu_reader
reader (per_cu
, NULL
, 0, 0, false);
19599 addr_base
= reader
.cu
->addr_base
;
19600 addr_size
= reader
.cu
->header
.addr_size
;
19603 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
19607 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
19608 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
19611 static const char *
19612 read_str_index (struct dwarf2_cu
*cu
,
19613 struct dwarf2_section_info
*str_section
,
19614 struct dwarf2_section_info
*str_offsets_section
,
19615 ULONGEST str_offsets_base
, ULONGEST str_index
)
19617 struct dwarf2_per_objfile
*dwarf2_per_objfile
19618 = cu
->per_cu
->dwarf2_per_objfile
;
19619 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19620 const char *objf_name
= objfile_name (objfile
);
19621 bfd
*abfd
= objfile
->obfd
;
19622 const gdb_byte
*info_ptr
;
19623 ULONGEST str_offset
;
19624 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
19626 str_section
->read (objfile
);
19627 str_offsets_section
->read (objfile
);
19628 if (str_section
->buffer
== NULL
)
19629 error (_("%s used without %s section"
19630 " in CU at offset %s [in module %s]"),
19631 form_name
, str_section
->get_name (),
19632 sect_offset_str (cu
->header
.sect_off
), objf_name
);
19633 if (str_offsets_section
->buffer
== NULL
)
19634 error (_("%s used without %s section"
19635 " in CU at offset %s [in module %s]"),
19636 form_name
, str_section
->get_name (),
19637 sect_offset_str (cu
->header
.sect_off
), objf_name
);
19638 info_ptr
= (str_offsets_section
->buffer
19640 + str_index
* cu
->header
.offset_size
);
19641 if (cu
->header
.offset_size
== 4)
19642 str_offset
= bfd_get_32 (abfd
, info_ptr
);
19644 str_offset
= bfd_get_64 (abfd
, info_ptr
);
19645 if (str_offset
>= str_section
->size
)
19646 error (_("Offset from %s pointing outside of"
19647 " .debug_str.dwo section in CU at offset %s [in module %s]"),
19648 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19649 return (const char *) (str_section
->buffer
+ str_offset
);
19652 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
19654 static const char *
19655 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
19657 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
19658 ? reader
->cu
->header
.addr_size
: 0;
19659 return read_str_index (reader
->cu
,
19660 &reader
->dwo_file
->sections
.str
,
19661 &reader
->dwo_file
->sections
.str_offsets
,
19662 str_offsets_base
, str_index
);
19665 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
19667 static const char *
19668 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
19670 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19671 const char *objf_name
= objfile_name (objfile
);
19672 static const char form_name
[] = "DW_FORM_GNU_str_index";
19673 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
19675 if (!cu
->str_offsets_base
.has_value ())
19676 error (_("%s used in Fission stub without %s"
19677 " in CU at offset 0x%lx [in module %s]"),
19678 form_name
, str_offsets_attr_name
,
19679 (long) cu
->header
.offset_size
, objf_name
);
19681 return read_str_index (cu
,
19682 &cu
->per_cu
->dwarf2_per_objfile
->str
,
19683 &cu
->per_cu
->dwarf2_per_objfile
->str_offsets
,
19684 *cu
->str_offsets_base
, str_index
);
19687 /* Return the length of an LEB128 number in BUF. */
19690 leb128_size (const gdb_byte
*buf
)
19692 const gdb_byte
*begin
= buf
;
19698 if ((byte
& 128) == 0)
19699 return buf
- begin
;
19704 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
19713 cu
->language
= language_c
;
19716 case DW_LANG_C_plus_plus
:
19717 case DW_LANG_C_plus_plus_11
:
19718 case DW_LANG_C_plus_plus_14
:
19719 cu
->language
= language_cplus
;
19722 cu
->language
= language_d
;
19724 case DW_LANG_Fortran77
:
19725 case DW_LANG_Fortran90
:
19726 case DW_LANG_Fortran95
:
19727 case DW_LANG_Fortran03
:
19728 case DW_LANG_Fortran08
:
19729 cu
->language
= language_fortran
;
19732 cu
->language
= language_go
;
19734 case DW_LANG_Mips_Assembler
:
19735 cu
->language
= language_asm
;
19737 case DW_LANG_Ada83
:
19738 case DW_LANG_Ada95
:
19739 cu
->language
= language_ada
;
19741 case DW_LANG_Modula2
:
19742 cu
->language
= language_m2
;
19744 case DW_LANG_Pascal83
:
19745 cu
->language
= language_pascal
;
19748 cu
->language
= language_objc
;
19751 case DW_LANG_Rust_old
:
19752 cu
->language
= language_rust
;
19754 case DW_LANG_Cobol74
:
19755 case DW_LANG_Cobol85
:
19757 cu
->language
= language_minimal
;
19760 cu
->language_defn
= language_def (cu
->language
);
19763 /* Return the named attribute or NULL if not there. */
19765 static struct attribute
*
19766 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19771 struct attribute
*spec
= NULL
;
19773 for (i
= 0; i
< die
->num_attrs
; ++i
)
19775 if (die
->attrs
[i
].name
== name
)
19776 return &die
->attrs
[i
];
19777 if (die
->attrs
[i
].name
== DW_AT_specification
19778 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
19779 spec
= &die
->attrs
[i
];
19785 die
= follow_die_ref (die
, spec
, &cu
);
19791 /* Return the named attribute or NULL if not there,
19792 but do not follow DW_AT_specification, etc.
19793 This is for use in contexts where we're reading .debug_types dies.
19794 Following DW_AT_specification, DW_AT_abstract_origin will take us
19795 back up the chain, and we want to go down. */
19797 static struct attribute
*
19798 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
19802 for (i
= 0; i
< die
->num_attrs
; ++i
)
19803 if (die
->attrs
[i
].name
== name
)
19804 return &die
->attrs
[i
];
19809 /* Return the string associated with a string-typed attribute, or NULL if it
19810 is either not found or is of an incorrect type. */
19812 static const char *
19813 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19815 struct attribute
*attr
;
19816 const char *str
= NULL
;
19818 attr
= dwarf2_attr (die
, name
, cu
);
19822 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
19823 || attr
->form
== DW_FORM_string
19824 || attr
->form
== DW_FORM_strx
19825 || attr
->form
== DW_FORM_strx1
19826 || attr
->form
== DW_FORM_strx2
19827 || attr
->form
== DW_FORM_strx3
19828 || attr
->form
== DW_FORM_strx4
19829 || attr
->form
== DW_FORM_GNU_str_index
19830 || attr
->form
== DW_FORM_GNU_strp_alt
)
19831 str
= DW_STRING (attr
);
19833 complaint (_("string type expected for attribute %s for "
19834 "DIE at %s in module %s"),
19835 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
19836 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
19842 /* Return the dwo name or NULL if not present. If present, it is in either
19843 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
19844 static const char *
19845 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
19847 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
19848 if (dwo_name
== nullptr)
19849 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
19853 /* Return non-zero iff the attribute NAME is defined for the given DIE,
19854 and holds a non-zero value. This function should only be used for
19855 DW_FORM_flag or DW_FORM_flag_present attributes. */
19858 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
19860 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
19862 return (attr
&& DW_UNSND (attr
));
19866 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
19868 /* A DIE is a declaration if it has a DW_AT_declaration attribute
19869 which value is non-zero. However, we have to be careful with
19870 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
19871 (via dwarf2_flag_true_p) follows this attribute. So we may
19872 end up accidently finding a declaration attribute that belongs
19873 to a different DIE referenced by the specification attribute,
19874 even though the given DIE does not have a declaration attribute. */
19875 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
19876 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
19879 /* Return the die giving the specification for DIE, if there is
19880 one. *SPEC_CU is the CU containing DIE on input, and the CU
19881 containing the return value on output. If there is no
19882 specification, but there is an abstract origin, that is
19885 static struct die_info
*
19886 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
19888 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
19891 if (spec_attr
== NULL
)
19892 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
19894 if (spec_attr
== NULL
)
19897 return follow_die_ref (die
, spec_attr
, spec_cu
);
19900 /* Stub for free_line_header to match void * callback types. */
19903 free_line_header_voidp (void *arg
)
19905 struct line_header
*lh
= (struct line_header
*) arg
;
19911 line_header::add_include_dir (const char *include_dir
)
19913 if (dwarf_line_debug
>= 2)
19917 new_size
= m_include_dirs
.size ();
19919 new_size
= m_include_dirs
.size () + 1;
19920 fprintf_unfiltered (gdb_stdlog
, "Adding dir %zu: %s\n",
19921 new_size
, include_dir
);
19923 m_include_dirs
.push_back (include_dir
);
19927 line_header::add_file_name (const char *name
,
19929 unsigned int mod_time
,
19930 unsigned int length
)
19932 if (dwarf_line_debug
>= 2)
19936 new_size
= file_names_size ();
19938 new_size
= file_names_size () + 1;
19939 fprintf_unfiltered (gdb_stdlog
, "Adding file %zu: %s\n",
19942 m_file_names
.emplace_back (name
, d_index
, mod_time
, length
);
19945 /* A convenience function to find the proper .debug_line section for a CU. */
19947 static struct dwarf2_section_info
*
19948 get_debug_line_section (struct dwarf2_cu
*cu
)
19950 struct dwarf2_section_info
*section
;
19951 struct dwarf2_per_objfile
*dwarf2_per_objfile
19952 = cu
->per_cu
->dwarf2_per_objfile
;
19954 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
19956 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19957 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
19958 else if (cu
->per_cu
->is_dwz
)
19960 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19962 section
= &dwz
->line
;
19965 section
= &dwarf2_per_objfile
->line
;
19970 /* Read directory or file name entry format, starting with byte of
19971 format count entries, ULEB128 pairs of entry formats, ULEB128 of
19972 entries count and the entries themselves in the described entry
19976 read_formatted_entries (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19977 bfd
*abfd
, const gdb_byte
**bufp
,
19978 struct line_header
*lh
,
19979 const struct comp_unit_head
*cu_header
,
19980 void (*callback
) (struct line_header
*lh
,
19983 unsigned int mod_time
,
19984 unsigned int length
))
19986 gdb_byte format_count
, formati
;
19987 ULONGEST data_count
, datai
;
19988 const gdb_byte
*buf
= *bufp
;
19989 const gdb_byte
*format_header_data
;
19990 unsigned int bytes_read
;
19992 format_count
= read_1_byte (abfd
, buf
);
19994 format_header_data
= buf
;
19995 for (formati
= 0; formati
< format_count
; formati
++)
19997 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
19999 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20003 data_count
= read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20005 for (datai
= 0; datai
< data_count
; datai
++)
20007 const gdb_byte
*format
= format_header_data
;
20008 struct file_entry fe
;
20010 for (formati
= 0; formati
< format_count
; formati
++)
20012 ULONGEST content_type
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20013 format
+= bytes_read
;
20015 ULONGEST form
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20016 format
+= bytes_read
;
20018 gdb::optional
<const char *> string
;
20019 gdb::optional
<unsigned int> uint
;
20023 case DW_FORM_string
:
20024 string
.emplace (read_direct_string (abfd
, buf
, &bytes_read
));
20028 case DW_FORM_line_strp
:
20029 string
.emplace (read_indirect_line_string (dwarf2_per_objfile
,
20036 case DW_FORM_data1
:
20037 uint
.emplace (read_1_byte (abfd
, buf
));
20041 case DW_FORM_data2
:
20042 uint
.emplace (read_2_bytes (abfd
, buf
));
20046 case DW_FORM_data4
:
20047 uint
.emplace (read_4_bytes (abfd
, buf
));
20051 case DW_FORM_data8
:
20052 uint
.emplace (read_8_bytes (abfd
, buf
));
20056 case DW_FORM_data16
:
20057 /* This is used for MD5, but file_entry does not record MD5s. */
20061 case DW_FORM_udata
:
20062 uint
.emplace (read_unsigned_leb128 (abfd
, buf
, &bytes_read
));
20066 case DW_FORM_block
:
20067 /* It is valid only for DW_LNCT_timestamp which is ignored by
20072 switch (content_type
)
20075 if (string
.has_value ())
20078 case DW_LNCT_directory_index
:
20079 if (uint
.has_value ())
20080 fe
.d_index
= (dir_index
) *uint
;
20082 case DW_LNCT_timestamp
:
20083 if (uint
.has_value ())
20084 fe
.mod_time
= *uint
;
20087 if (uint
.has_value ())
20093 complaint (_("Unknown format content type %s"),
20094 pulongest (content_type
));
20098 callback (lh
, fe
.name
, fe
.d_index
, fe
.mod_time
, fe
.length
);
20104 /* Read the statement program header starting at OFFSET in
20105 .debug_line, or .debug_line.dwo. Return a pointer
20106 to a struct line_header, allocated using xmalloc.
20107 Returns NULL if there is a problem reading the header, e.g., if it
20108 has a version we don't understand.
20110 NOTE: the strings in the include directory and file name tables of
20111 the returned object point into the dwarf line section buffer,
20112 and must not be freed. */
20114 static line_header_up
20115 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
20117 const gdb_byte
*line_ptr
;
20118 unsigned int bytes_read
, offset_size
;
20120 const char *cur_dir
, *cur_file
;
20121 struct dwarf2_section_info
*section
;
20123 struct dwarf2_per_objfile
*dwarf2_per_objfile
20124 = cu
->per_cu
->dwarf2_per_objfile
;
20126 section
= get_debug_line_section (cu
);
20127 section
->read (dwarf2_per_objfile
->objfile
);
20128 if (section
->buffer
== NULL
)
20130 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20131 complaint (_("missing .debug_line.dwo section"));
20133 complaint (_("missing .debug_line section"));
20137 /* We can't do this until we know the section is non-empty.
20138 Only then do we know we have such a section. */
20139 abfd
= section
->get_bfd_owner ();
20141 /* Make sure that at least there's room for the total_length field.
20142 That could be 12 bytes long, but we're just going to fudge that. */
20143 if (to_underlying (sect_off
) + 4 >= section
->size
)
20145 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20149 line_header_up
lh (new line_header ());
20151 lh
->sect_off
= sect_off
;
20152 lh
->offset_in_dwz
= cu
->per_cu
->is_dwz
;
20154 line_ptr
= section
->buffer
+ to_underlying (sect_off
);
20156 /* Read in the header. */
20158 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
20159 &bytes_read
, &offset_size
);
20160 line_ptr
+= bytes_read
;
20162 const gdb_byte
*start_here
= line_ptr
;
20164 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
20166 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20169 lh
->statement_program_end
= start_here
+ lh
->total_length
;
20170 lh
->version
= read_2_bytes (abfd
, line_ptr
);
20172 if (lh
->version
> 5)
20174 /* This is a version we don't understand. The format could have
20175 changed in ways we don't handle properly so just punt. */
20176 complaint (_("unsupported version in .debug_line section"));
20179 if (lh
->version
>= 5)
20181 gdb_byte segment_selector_size
;
20183 /* Skip address size. */
20184 read_1_byte (abfd
, line_ptr
);
20187 segment_selector_size
= read_1_byte (abfd
, line_ptr
);
20189 if (segment_selector_size
!= 0)
20191 complaint (_("unsupported segment selector size %u "
20192 "in .debug_line section"),
20193 segment_selector_size
);
20197 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
20198 line_ptr
+= offset_size
;
20199 lh
->statement_program_start
= line_ptr
+ lh
->header_length
;
20200 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
20202 if (lh
->version
>= 4)
20204 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
20208 lh
->maximum_ops_per_instruction
= 1;
20210 if (lh
->maximum_ops_per_instruction
== 0)
20212 lh
->maximum_ops_per_instruction
= 1;
20213 complaint (_("invalid maximum_ops_per_instruction "
20214 "in `.debug_line' section"));
20217 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
20219 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
20221 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
20223 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
20225 lh
->standard_opcode_lengths
.reset (new unsigned char[lh
->opcode_base
]);
20227 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
20228 for (i
= 1; i
< lh
->opcode_base
; ++i
)
20230 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
20234 if (lh
->version
>= 5)
20236 /* Read directory table. */
20237 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20239 [] (struct line_header
*header
, const char *name
,
20240 dir_index d_index
, unsigned int mod_time
,
20241 unsigned int length
)
20243 header
->add_include_dir (name
);
20246 /* Read file name table. */
20247 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20249 [] (struct line_header
*header
, const char *name
,
20250 dir_index d_index
, unsigned int mod_time
,
20251 unsigned int length
)
20253 header
->add_file_name (name
, d_index
, mod_time
, length
);
20258 /* Read directory table. */
20259 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20261 line_ptr
+= bytes_read
;
20262 lh
->add_include_dir (cur_dir
);
20264 line_ptr
+= bytes_read
;
20266 /* Read file name table. */
20267 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20269 unsigned int mod_time
, length
;
20272 line_ptr
+= bytes_read
;
20273 d_index
= (dir_index
) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20274 line_ptr
+= bytes_read
;
20275 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20276 line_ptr
+= bytes_read
;
20277 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20278 line_ptr
+= bytes_read
;
20280 lh
->add_file_name (cur_file
, d_index
, mod_time
, length
);
20282 line_ptr
+= bytes_read
;
20285 if (line_ptr
> (section
->buffer
+ section
->size
))
20286 complaint (_("line number info header doesn't "
20287 "fit in `.debug_line' section"));
20292 /* Subroutine of dwarf_decode_lines to simplify it.
20293 Return the file name of the psymtab for the given file_entry.
20294 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20295 If space for the result is malloc'd, *NAME_HOLDER will be set.
20296 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
20298 static const char *
20299 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
20300 const dwarf2_psymtab
*pst
,
20301 const char *comp_dir
,
20302 gdb::unique_xmalloc_ptr
<char> *name_holder
)
20304 const char *include_name
= fe
.name
;
20305 const char *include_name_to_compare
= include_name
;
20306 const char *pst_filename
;
20309 const char *dir_name
= fe
.include_dir (lh
);
20311 gdb::unique_xmalloc_ptr
<char> hold_compare
;
20312 if (!IS_ABSOLUTE_PATH (include_name
)
20313 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
20315 /* Avoid creating a duplicate psymtab for PST.
20316 We do this by comparing INCLUDE_NAME and PST_FILENAME.
20317 Before we do the comparison, however, we need to account
20318 for DIR_NAME and COMP_DIR.
20319 First prepend dir_name (if non-NULL). If we still don't
20320 have an absolute path prepend comp_dir (if non-NULL).
20321 However, the directory we record in the include-file's
20322 psymtab does not contain COMP_DIR (to match the
20323 corresponding symtab(s)).
20328 bash$ gcc -g ./hello.c
20329 include_name = "hello.c"
20331 DW_AT_comp_dir = comp_dir = "/tmp"
20332 DW_AT_name = "./hello.c"
20336 if (dir_name
!= NULL
)
20338 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
20339 include_name
, (char *) NULL
));
20340 include_name
= name_holder
->get ();
20341 include_name_to_compare
= include_name
;
20343 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
20345 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
20346 include_name
, (char *) NULL
));
20347 include_name_to_compare
= hold_compare
.get ();
20351 pst_filename
= pst
->filename
;
20352 gdb::unique_xmalloc_ptr
<char> copied_name
;
20353 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
20355 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
20356 pst_filename
, (char *) NULL
));
20357 pst_filename
= copied_name
.get ();
20360 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
20364 return include_name
;
20367 /* State machine to track the state of the line number program. */
20369 class lnp_state_machine
20372 /* Initialize a machine state for the start of a line number
20374 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
20375 bool record_lines_p
);
20377 file_entry
*current_file ()
20379 /* lh->file_names is 0-based, but the file name numbers in the
20380 statement program are 1-based. */
20381 return m_line_header
->file_name_at (m_file
);
20384 /* Record the line in the state machine. END_SEQUENCE is true if
20385 we're processing the end of a sequence. */
20386 void record_line (bool end_sequence
);
20388 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
20389 nop-out rest of the lines in this sequence. */
20390 void check_line_address (struct dwarf2_cu
*cu
,
20391 const gdb_byte
*line_ptr
,
20392 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
20394 void handle_set_discriminator (unsigned int discriminator
)
20396 m_discriminator
= discriminator
;
20397 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
20400 /* Handle DW_LNE_set_address. */
20401 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
20404 address
+= baseaddr
;
20405 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
20408 /* Handle DW_LNS_advance_pc. */
20409 void handle_advance_pc (CORE_ADDR adjust
);
20411 /* Handle a special opcode. */
20412 void handle_special_opcode (unsigned char op_code
);
20414 /* Handle DW_LNS_advance_line. */
20415 void handle_advance_line (int line_delta
)
20417 advance_line (line_delta
);
20420 /* Handle DW_LNS_set_file. */
20421 void handle_set_file (file_name_index file
);
20423 /* Handle DW_LNS_negate_stmt. */
20424 void handle_negate_stmt ()
20426 m_is_stmt
= !m_is_stmt
;
20429 /* Handle DW_LNS_const_add_pc. */
20430 void handle_const_add_pc ();
20432 /* Handle DW_LNS_fixed_advance_pc. */
20433 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
20435 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20439 /* Handle DW_LNS_copy. */
20440 void handle_copy ()
20442 record_line (false);
20443 m_discriminator
= 0;
20446 /* Handle DW_LNE_end_sequence. */
20447 void handle_end_sequence ()
20449 m_currently_recording_lines
= true;
20453 /* Advance the line by LINE_DELTA. */
20454 void advance_line (int line_delta
)
20456 m_line
+= line_delta
;
20458 if (line_delta
!= 0)
20459 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20462 struct dwarf2_cu
*m_cu
;
20464 gdbarch
*m_gdbarch
;
20466 /* True if we're recording lines.
20467 Otherwise we're building partial symtabs and are just interested in
20468 finding include files mentioned by the line number program. */
20469 bool m_record_lines_p
;
20471 /* The line number header. */
20472 line_header
*m_line_header
;
20474 /* These are part of the standard DWARF line number state machine,
20475 and initialized according to the DWARF spec. */
20477 unsigned char m_op_index
= 0;
20478 /* The line table index of the current file. */
20479 file_name_index m_file
= 1;
20480 unsigned int m_line
= 1;
20482 /* These are initialized in the constructor. */
20484 CORE_ADDR m_address
;
20486 unsigned int m_discriminator
;
20488 /* Additional bits of state we need to track. */
20490 /* The last file that we called dwarf2_start_subfile for.
20491 This is only used for TLLs. */
20492 unsigned int m_last_file
= 0;
20493 /* The last file a line number was recorded for. */
20494 struct subfile
*m_last_subfile
= NULL
;
20496 /* When true, record the lines we decode. */
20497 bool m_currently_recording_lines
= false;
20499 /* The last line number that was recorded, used to coalesce
20500 consecutive entries for the same line. This can happen, for
20501 example, when discriminators are present. PR 17276. */
20502 unsigned int m_last_line
= 0;
20503 bool m_line_has_non_zero_discriminator
= false;
20507 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
20509 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
20510 / m_line_header
->maximum_ops_per_instruction
)
20511 * m_line_header
->minimum_instruction_length
);
20512 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20513 m_op_index
= ((m_op_index
+ adjust
)
20514 % m_line_header
->maximum_ops_per_instruction
);
20518 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
20520 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
20521 CORE_ADDR addr_adj
= (((m_op_index
20522 + (adj_opcode
/ m_line_header
->line_range
))
20523 / m_line_header
->maximum_ops_per_instruction
)
20524 * m_line_header
->minimum_instruction_length
);
20525 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20526 m_op_index
= ((m_op_index
+ (adj_opcode
/ m_line_header
->line_range
))
20527 % m_line_header
->maximum_ops_per_instruction
);
20529 int line_delta
= (m_line_header
->line_base
20530 + (adj_opcode
% m_line_header
->line_range
));
20531 advance_line (line_delta
);
20532 record_line (false);
20533 m_discriminator
= 0;
20537 lnp_state_machine::handle_set_file (file_name_index file
)
20541 const file_entry
*fe
= current_file ();
20543 dwarf2_debug_line_missing_file_complaint ();
20544 else if (m_record_lines_p
)
20546 const char *dir
= fe
->include_dir (m_line_header
);
20548 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20549 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20550 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
20555 lnp_state_machine::handle_const_add_pc ()
20558 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
20561 = (((m_op_index
+ adjust
)
20562 / m_line_header
->maximum_ops_per_instruction
)
20563 * m_line_header
->minimum_instruction_length
);
20565 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20566 m_op_index
= ((m_op_index
+ adjust
)
20567 % m_line_header
->maximum_ops_per_instruction
);
20570 /* Return non-zero if we should add LINE to the line number table.
20571 LINE is the line to add, LAST_LINE is the last line that was added,
20572 LAST_SUBFILE is the subfile for LAST_LINE.
20573 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
20574 had a non-zero discriminator.
20576 We have to be careful in the presence of discriminators.
20577 E.g., for this line:
20579 for (i = 0; i < 100000; i++);
20581 clang can emit four line number entries for that one line,
20582 each with a different discriminator.
20583 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
20585 However, we want gdb to coalesce all four entries into one.
20586 Otherwise the user could stepi into the middle of the line and
20587 gdb would get confused about whether the pc really was in the
20588 middle of the line.
20590 Things are further complicated by the fact that two consecutive
20591 line number entries for the same line is a heuristic used by gcc
20592 to denote the end of the prologue. So we can't just discard duplicate
20593 entries, we have to be selective about it. The heuristic we use is
20594 that we only collapse consecutive entries for the same line if at least
20595 one of those entries has a non-zero discriminator. PR 17276.
20597 Note: Addresses in the line number state machine can never go backwards
20598 within one sequence, thus this coalescing is ok. */
20601 dwarf_record_line_p (struct dwarf2_cu
*cu
,
20602 unsigned int line
, unsigned int last_line
,
20603 int line_has_non_zero_discriminator
,
20604 struct subfile
*last_subfile
)
20606 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
20608 if (line
!= last_line
)
20610 /* Same line for the same file that we've seen already.
20611 As a last check, for pr 17276, only record the line if the line
20612 has never had a non-zero discriminator. */
20613 if (!line_has_non_zero_discriminator
)
20618 /* Use the CU's builder to record line number LINE beginning at
20619 address ADDRESS in the line table of subfile SUBFILE. */
20622 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20623 unsigned int line
, CORE_ADDR address
,
20624 struct dwarf2_cu
*cu
)
20626 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
20628 if (dwarf_line_debug
)
20630 fprintf_unfiltered (gdb_stdlog
,
20631 "Recording line %u, file %s, address %s\n",
20632 line
, lbasename (subfile
->name
),
20633 paddress (gdbarch
, address
));
20637 cu
->get_builder ()->record_line (subfile
, line
, addr
);
20640 /* Subroutine of dwarf_decode_lines_1 to simplify it.
20641 Mark the end of a set of line number records.
20642 The arguments are the same as for dwarf_record_line_1.
20643 If SUBFILE is NULL the request is ignored. */
20646 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20647 CORE_ADDR address
, struct dwarf2_cu
*cu
)
20649 if (subfile
== NULL
)
20652 if (dwarf_line_debug
)
20654 fprintf_unfiltered (gdb_stdlog
,
20655 "Finishing current line, file %s, address %s\n",
20656 lbasename (subfile
->name
),
20657 paddress (gdbarch
, address
));
20660 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, cu
);
20664 lnp_state_machine::record_line (bool end_sequence
)
20666 if (dwarf_line_debug
)
20668 fprintf_unfiltered (gdb_stdlog
,
20669 "Processing actual line %u: file %u,"
20670 " address %s, is_stmt %u, discrim %u%s\n",
20672 paddress (m_gdbarch
, m_address
),
20673 m_is_stmt
, m_discriminator
,
20674 (end_sequence
? "\t(end sequence)" : ""));
20677 file_entry
*fe
= current_file ();
20680 dwarf2_debug_line_missing_file_complaint ();
20681 /* For now we ignore lines not starting on an instruction boundary.
20682 But not when processing end_sequence for compatibility with the
20683 previous version of the code. */
20684 else if (m_op_index
== 0 || end_sequence
)
20686 fe
->included_p
= 1;
20687 if (m_record_lines_p
20688 && (producer_is_codewarrior (m_cu
) || m_is_stmt
|| end_sequence
))
20690 if (m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ()
20693 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
20694 m_currently_recording_lines
? m_cu
: nullptr);
20699 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
20700 m_line_has_non_zero_discriminator
,
20703 buildsym_compunit
*builder
= m_cu
->get_builder ();
20704 dwarf_record_line_1 (m_gdbarch
,
20705 builder
->get_current_subfile (),
20707 m_currently_recording_lines
? m_cu
: nullptr);
20709 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20710 m_last_line
= m_line
;
20716 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
20717 line_header
*lh
, bool record_lines_p
)
20721 m_record_lines_p
= record_lines_p
;
20722 m_line_header
= lh
;
20724 m_currently_recording_lines
= true;
20726 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
20727 was a line entry for it so that the backend has a chance to adjust it
20728 and also record it in case it needs it. This is currently used by MIPS
20729 code, cf. `mips_adjust_dwarf2_line'. */
20730 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
20731 m_is_stmt
= lh
->default_is_stmt
;
20732 m_discriminator
= 0;
20736 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
20737 const gdb_byte
*line_ptr
,
20738 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
20740 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
20741 the pc range of the CU. However, we restrict the test to only ADDRESS
20742 values of zero to preserve GDB's previous behaviour which is to handle
20743 the specific case of a function being GC'd by the linker. */
20745 if (address
== 0 && address
< unrelocated_lowpc
)
20747 /* This line table is for a function which has been
20748 GCd by the linker. Ignore it. PR gdb/12528 */
20750 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20751 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
20753 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
20754 line_offset
, objfile_name (objfile
));
20755 m_currently_recording_lines
= false;
20756 /* Note: m_currently_recording_lines is left as false until we see
20757 DW_LNE_end_sequence. */
20761 /* Subroutine of dwarf_decode_lines to simplify it.
20762 Process the line number information in LH.
20763 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
20764 program in order to set included_p for every referenced header. */
20767 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
20768 const int decode_for_pst_p
, CORE_ADDR lowpc
)
20770 const gdb_byte
*line_ptr
, *extended_end
;
20771 const gdb_byte
*line_end
;
20772 unsigned int bytes_read
, extended_len
;
20773 unsigned char op_code
, extended_op
;
20774 CORE_ADDR baseaddr
;
20775 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20776 bfd
*abfd
= objfile
->obfd
;
20777 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
20778 /* True if we're recording line info (as opposed to building partial
20779 symtabs and just interested in finding include files mentioned by
20780 the line number program). */
20781 bool record_lines_p
= !decode_for_pst_p
;
20783 baseaddr
= objfile
->text_section_offset ();
20785 line_ptr
= lh
->statement_program_start
;
20786 line_end
= lh
->statement_program_end
;
20788 /* Read the statement sequences until there's nothing left. */
20789 while (line_ptr
< line_end
)
20791 /* The DWARF line number program state machine. Reset the state
20792 machine at the start of each sequence. */
20793 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
20794 bool end_sequence
= false;
20796 if (record_lines_p
)
20798 /* Start a subfile for the current file of the state
20800 const file_entry
*fe
= state_machine
.current_file ();
20803 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
20806 /* Decode the table. */
20807 while (line_ptr
< line_end
&& !end_sequence
)
20809 op_code
= read_1_byte (abfd
, line_ptr
);
20812 if (op_code
>= lh
->opcode_base
)
20814 /* Special opcode. */
20815 state_machine
.handle_special_opcode (op_code
);
20817 else switch (op_code
)
20819 case DW_LNS_extended_op
:
20820 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
20822 line_ptr
+= bytes_read
;
20823 extended_end
= line_ptr
+ extended_len
;
20824 extended_op
= read_1_byte (abfd
, line_ptr
);
20826 switch (extended_op
)
20828 case DW_LNE_end_sequence
:
20829 state_machine
.handle_end_sequence ();
20830 end_sequence
= true;
20832 case DW_LNE_set_address
:
20835 = read_address (abfd
, line_ptr
, cu
, &bytes_read
);
20836 line_ptr
+= bytes_read
;
20838 state_machine
.check_line_address (cu
, line_ptr
,
20839 lowpc
- baseaddr
, address
);
20840 state_machine
.handle_set_address (baseaddr
, address
);
20843 case DW_LNE_define_file
:
20845 const char *cur_file
;
20846 unsigned int mod_time
, length
;
20849 cur_file
= read_direct_string (abfd
, line_ptr
,
20851 line_ptr
+= bytes_read
;
20852 dindex
= (dir_index
)
20853 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20854 line_ptr
+= bytes_read
;
20856 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20857 line_ptr
+= bytes_read
;
20859 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20860 line_ptr
+= bytes_read
;
20861 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
20864 case DW_LNE_set_discriminator
:
20866 /* The discriminator is not interesting to the
20867 debugger; just ignore it. We still need to
20868 check its value though:
20869 if there are consecutive entries for the same
20870 (non-prologue) line we want to coalesce them.
20873 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20874 line_ptr
+= bytes_read
;
20876 state_machine
.handle_set_discriminator (discr
);
20880 complaint (_("mangled .debug_line section"));
20883 /* Make sure that we parsed the extended op correctly. If e.g.
20884 we expected a different address size than the producer used,
20885 we may have read the wrong number of bytes. */
20886 if (line_ptr
!= extended_end
)
20888 complaint (_("mangled .debug_line section"));
20893 state_machine
.handle_copy ();
20895 case DW_LNS_advance_pc
:
20898 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20899 line_ptr
+= bytes_read
;
20901 state_machine
.handle_advance_pc (adjust
);
20904 case DW_LNS_advance_line
:
20907 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
20908 line_ptr
+= bytes_read
;
20910 state_machine
.handle_advance_line (line_delta
);
20913 case DW_LNS_set_file
:
20915 file_name_index file
20916 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
20918 line_ptr
+= bytes_read
;
20920 state_machine
.handle_set_file (file
);
20923 case DW_LNS_set_column
:
20924 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20925 line_ptr
+= bytes_read
;
20927 case DW_LNS_negate_stmt
:
20928 state_machine
.handle_negate_stmt ();
20930 case DW_LNS_set_basic_block
:
20932 /* Add to the address register of the state machine the
20933 address increment value corresponding to special opcode
20934 255. I.e., this value is scaled by the minimum
20935 instruction length since special opcode 255 would have
20936 scaled the increment. */
20937 case DW_LNS_const_add_pc
:
20938 state_machine
.handle_const_add_pc ();
20940 case DW_LNS_fixed_advance_pc
:
20942 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
20945 state_machine
.handle_fixed_advance_pc (addr_adj
);
20950 /* Unknown standard opcode, ignore it. */
20953 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
20955 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20956 line_ptr
+= bytes_read
;
20963 dwarf2_debug_line_missing_end_sequence_complaint ();
20965 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
20966 in which case we still finish recording the last line). */
20967 state_machine
.record_line (true);
20971 /* Decode the Line Number Program (LNP) for the given line_header
20972 structure and CU. The actual information extracted and the type
20973 of structures created from the LNP depends on the value of PST.
20975 1. If PST is NULL, then this procedure uses the data from the program
20976 to create all necessary symbol tables, and their linetables.
20978 2. If PST is not NULL, this procedure reads the program to determine
20979 the list of files included by the unit represented by PST, and
20980 builds all the associated partial symbol tables.
20982 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20983 It is used for relative paths in the line table.
20984 NOTE: When processing partial symtabs (pst != NULL),
20985 comp_dir == pst->dirname.
20987 NOTE: It is important that psymtabs have the same file name (via strcmp)
20988 as the corresponding symtab. Since COMP_DIR is not used in the name of the
20989 symtab we don't use it in the name of the psymtabs we create.
20990 E.g. expand_line_sal requires this when finding psymtabs to expand.
20991 A good testcase for this is mb-inline.exp.
20993 LOWPC is the lowest address in CU (or 0 if not known).
20995 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
20996 for its PC<->lines mapping information. Otherwise only the filename
20997 table is read in. */
21000 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
21001 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
21002 CORE_ADDR lowpc
, int decode_mapping
)
21004 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21005 const int decode_for_pst_p
= (pst
!= NULL
);
21007 if (decode_mapping
)
21008 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
21010 if (decode_for_pst_p
)
21012 /* Now that we're done scanning the Line Header Program, we can
21013 create the psymtab of each included file. */
21014 for (auto &file_entry
: lh
->file_names ())
21015 if (file_entry
.included_p
== 1)
21017 gdb::unique_xmalloc_ptr
<char> name_holder
;
21018 const char *include_name
=
21019 psymtab_include_file_name (lh
, file_entry
, pst
,
21020 comp_dir
, &name_holder
);
21021 if (include_name
!= NULL
)
21022 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
21027 /* Make sure a symtab is created for every file, even files
21028 which contain only variables (i.e. no code with associated
21030 buildsym_compunit
*builder
= cu
->get_builder ();
21031 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
21033 for (auto &fe
: lh
->file_names ())
21035 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
21036 if (builder
->get_current_subfile ()->symtab
== NULL
)
21038 builder
->get_current_subfile ()->symtab
21039 = allocate_symtab (cust
,
21040 builder
->get_current_subfile ()->name
);
21042 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
21047 /* Start a subfile for DWARF. FILENAME is the name of the file and
21048 DIRNAME the name of the source directory which contains FILENAME
21049 or NULL if not known.
21050 This routine tries to keep line numbers from identical absolute and
21051 relative file names in a common subfile.
21053 Using the `list' example from the GDB testsuite, which resides in
21054 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
21055 of /srcdir/list0.c yields the following debugging information for list0.c:
21057 DW_AT_name: /srcdir/list0.c
21058 DW_AT_comp_dir: /compdir
21059 files.files[0].name: list0.h
21060 files.files[0].dir: /srcdir
21061 files.files[1].name: list0.c
21062 files.files[1].dir: /srcdir
21064 The line number information for list0.c has to end up in a single
21065 subfile, so that `break /srcdir/list0.c:1' works as expected.
21066 start_subfile will ensure that this happens provided that we pass the
21067 concatenation of files.files[1].dir and files.files[1].name as the
21071 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
21072 const char *dirname
)
21074 gdb::unique_xmalloc_ptr
<char> copy
;
21076 /* In order not to lose the line information directory,
21077 we concatenate it to the filename when it makes sense.
21078 Note that the Dwarf3 standard says (speaking of filenames in line
21079 information): ``The directory index is ignored for file names
21080 that represent full path names''. Thus ignoring dirname in the
21081 `else' branch below isn't an issue. */
21083 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
21085 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
21086 filename
= copy
.get ();
21089 cu
->get_builder ()->start_subfile (filename
);
21092 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
21093 buildsym_compunit constructor. */
21095 struct compunit_symtab
*
21096 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
21099 gdb_assert (m_builder
== nullptr);
21101 m_builder
.reset (new struct buildsym_compunit
21102 (per_cu
->dwarf2_per_objfile
->objfile
,
21103 name
, comp_dir
, language
, low_pc
));
21105 list_in_scope
= get_builder ()->get_file_symbols ();
21107 get_builder ()->record_debugformat ("DWARF 2");
21108 get_builder ()->record_producer (producer
);
21110 processing_has_namespace_info
= false;
21112 return get_builder ()->get_compunit_symtab ();
21116 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
21117 struct dwarf2_cu
*cu
)
21119 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21120 struct comp_unit_head
*cu_header
= &cu
->header
;
21122 /* NOTE drow/2003-01-30: There used to be a comment and some special
21123 code here to turn a symbol with DW_AT_external and a
21124 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
21125 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
21126 with some versions of binutils) where shared libraries could have
21127 relocations against symbols in their debug information - the
21128 minimal symbol would have the right address, but the debug info
21129 would not. It's no longer necessary, because we will explicitly
21130 apply relocations when we read in the debug information now. */
21132 /* A DW_AT_location attribute with no contents indicates that a
21133 variable has been optimized away. */
21134 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0)
21136 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21140 /* Handle one degenerate form of location expression specially, to
21141 preserve GDB's previous behavior when section offsets are
21142 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
21143 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
21145 if (attr
->form_is_block ()
21146 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
21147 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
21148 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
21149 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
21150 && (DW_BLOCK (attr
)->size
21151 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
21153 unsigned int dummy
;
21155 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
21156 SET_SYMBOL_VALUE_ADDRESS (sym
,
21157 read_address (objfile
->obfd
,
21158 DW_BLOCK (attr
)->data
+ 1,
21161 SET_SYMBOL_VALUE_ADDRESS
21162 (sym
, read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1,
21164 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
21165 fixup_symbol_section (sym
, objfile
);
21166 SET_SYMBOL_VALUE_ADDRESS
21168 SYMBOL_VALUE_ADDRESS (sym
)
21169 + objfile
->section_offsets
[SYMBOL_SECTION (sym
)]);
21173 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
21174 expression evaluator, and use LOC_COMPUTED only when necessary
21175 (i.e. when the value of a register or memory location is
21176 referenced, or a thread-local block, etc.). Then again, it might
21177 not be worthwhile. I'm assuming that it isn't unless performance
21178 or memory numbers show me otherwise. */
21180 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
21182 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
21183 cu
->has_loclist
= true;
21186 /* Given a pointer to a DWARF information entry, figure out if we need
21187 to make a symbol table entry for it, and if so, create a new entry
21188 and return a pointer to it.
21189 If TYPE is NULL, determine symbol type from the die, otherwise
21190 used the passed type.
21191 If SPACE is not NULL, use it to hold the new symbol. If it is
21192 NULL, allocate a new symbol on the objfile's obstack. */
21194 static struct symbol
*
21195 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
21196 struct symbol
*space
)
21198 struct dwarf2_per_objfile
*dwarf2_per_objfile
21199 = cu
->per_cu
->dwarf2_per_objfile
;
21200 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21201 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21202 struct symbol
*sym
= NULL
;
21204 struct attribute
*attr
= NULL
;
21205 struct attribute
*attr2
= NULL
;
21206 CORE_ADDR baseaddr
;
21207 struct pending
**list_to_add
= NULL
;
21209 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
21211 baseaddr
= objfile
->text_section_offset ();
21213 name
= dwarf2_name (die
, cu
);
21216 const char *linkagename
;
21217 int suppress_add
= 0;
21222 sym
= allocate_symbol (objfile
);
21223 OBJSTAT (objfile
, n_syms
++);
21225 /* Cache this symbol's name and the name's demangled form (if any). */
21226 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
21227 linkagename
= dwarf2_physname (name
, die
, cu
);
21228 sym
->compute_and_set_names (linkagename
, false, objfile
->per_bfd
);
21230 /* Fortran does not have mangling standard and the mangling does differ
21231 between gfortran, iFort etc. */
21232 if (cu
->language
== language_fortran
21233 && symbol_get_demangled_name (sym
) == NULL
)
21234 symbol_set_demangled_name (sym
,
21235 dwarf2_full_name (name
, die
, cu
),
21238 /* Default assumptions.
21239 Use the passed type or decode it from the die. */
21240 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21241 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21243 SYMBOL_TYPE (sym
) = type
;
21245 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
21246 attr
= dwarf2_attr (die
,
21247 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
21249 if (attr
!= nullptr)
21251 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
21254 attr
= dwarf2_attr (die
,
21255 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
21257 if (attr
!= nullptr)
21259 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
21260 struct file_entry
*fe
;
21262 if (cu
->line_header
!= NULL
)
21263 fe
= cu
->line_header
->file_name_at (file_index
);
21268 complaint (_("file index out of range"));
21270 symbol_set_symtab (sym
, fe
->symtab
);
21276 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
21277 if (attr
!= nullptr)
21281 addr
= attr
->value_as_address ();
21282 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
21283 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
21285 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
21286 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
21287 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
21288 add_symbol_to_list (sym
, cu
->list_in_scope
);
21290 case DW_TAG_subprogram
:
21291 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21293 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21294 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21295 if ((attr2
&& (DW_UNSND (attr2
) != 0))
21296 || cu
->language
== language_ada
21297 || cu
->language
== language_fortran
)
21299 /* Subprograms marked external are stored as a global symbol.
21300 Ada and Fortran subprograms, whether marked external or
21301 not, are always stored as a global symbol, because we want
21302 to be able to access them globally. For instance, we want
21303 to be able to break on a nested subprogram without having
21304 to specify the context. */
21305 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21309 list_to_add
= cu
->list_in_scope
;
21312 case DW_TAG_inlined_subroutine
:
21313 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21315 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21316 SYMBOL_INLINED (sym
) = 1;
21317 list_to_add
= cu
->list_in_scope
;
21319 case DW_TAG_template_value_param
:
21321 /* Fall through. */
21322 case DW_TAG_constant
:
21323 case DW_TAG_variable
:
21324 case DW_TAG_member
:
21325 /* Compilation with minimal debug info may result in
21326 variables with missing type entries. Change the
21327 misleading `void' type to something sensible. */
21328 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
21329 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
21331 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21332 /* In the case of DW_TAG_member, we should only be called for
21333 static const members. */
21334 if (die
->tag
== DW_TAG_member
)
21336 /* dwarf2_add_field uses die_is_declaration,
21337 so we do the same. */
21338 gdb_assert (die_is_declaration (die
, cu
));
21341 if (attr
!= nullptr)
21343 dwarf2_const_value (attr
, sym
, cu
);
21344 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21347 if (attr2
&& (DW_UNSND (attr2
) != 0))
21348 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21350 list_to_add
= cu
->list_in_scope
;
21354 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21355 if (attr
!= nullptr)
21357 var_decode_location (attr
, sym
, cu
);
21358 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21360 /* Fortran explicitly imports any global symbols to the local
21361 scope by DW_TAG_common_block. */
21362 if (cu
->language
== language_fortran
&& die
->parent
21363 && die
->parent
->tag
== DW_TAG_common_block
)
21366 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21367 && SYMBOL_VALUE_ADDRESS (sym
) == 0
21368 && !dwarf2_per_objfile
->has_section_at_zero
)
21370 /* When a static variable is eliminated by the linker,
21371 the corresponding debug information is not stripped
21372 out, but the variable address is set to null;
21373 do not add such variables into symbol table. */
21375 else if (attr2
&& (DW_UNSND (attr2
) != 0))
21377 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21378 && (objfile
->flags
& OBJF_MAINLINE
) == 0
21379 && dwarf2_per_objfile
->can_copy
)
21381 /* A global static variable might be subject to
21382 copy relocation. We first check for a local
21383 minsym, though, because maybe the symbol was
21384 marked hidden, in which case this would not
21386 bound_minimal_symbol found
21387 = (lookup_minimal_symbol_linkage
21388 (sym
->linkage_name (), objfile
));
21389 if (found
.minsym
!= nullptr)
21390 sym
->maybe_copied
= 1;
21393 /* A variable with DW_AT_external is never static,
21394 but it may be block-scoped. */
21396 = ((cu
->list_in_scope
21397 == cu
->get_builder ()->get_file_symbols ())
21398 ? cu
->get_builder ()->get_global_symbols ()
21399 : cu
->list_in_scope
);
21402 list_to_add
= cu
->list_in_scope
;
21406 /* We do not know the address of this symbol.
21407 If it is an external symbol and we have type information
21408 for it, enter the symbol as a LOC_UNRESOLVED symbol.
21409 The address of the variable will then be determined from
21410 the minimal symbol table whenever the variable is
21412 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21414 /* Fortran explicitly imports any global symbols to the local
21415 scope by DW_TAG_common_block. */
21416 if (cu
->language
== language_fortran
&& die
->parent
21417 && die
->parent
->tag
== DW_TAG_common_block
)
21419 /* SYMBOL_CLASS doesn't matter here because
21420 read_common_block is going to reset it. */
21422 list_to_add
= cu
->list_in_scope
;
21424 else if (attr2
&& (DW_UNSND (attr2
) != 0)
21425 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
21427 /* A variable with DW_AT_external is never static, but it
21428 may be block-scoped. */
21430 = ((cu
->list_in_scope
21431 == cu
->get_builder ()->get_file_symbols ())
21432 ? cu
->get_builder ()->get_global_symbols ()
21433 : cu
->list_in_scope
);
21435 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21437 else if (!die_is_declaration (die
, cu
))
21439 /* Use the default LOC_OPTIMIZED_OUT class. */
21440 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
21442 list_to_add
= cu
->list_in_scope
;
21446 case DW_TAG_formal_parameter
:
21448 /* If we are inside a function, mark this as an argument. If
21449 not, we might be looking at an argument to an inlined function
21450 when we do not have enough information to show inlined frames;
21451 pretend it's a local variable in that case so that the user can
21453 struct context_stack
*curr
21454 = cu
->get_builder ()->get_current_context_stack ();
21455 if (curr
!= nullptr && curr
->name
!= nullptr)
21456 SYMBOL_IS_ARGUMENT (sym
) = 1;
21457 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21458 if (attr
!= nullptr)
21460 var_decode_location (attr
, sym
, cu
);
21462 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21463 if (attr
!= nullptr)
21465 dwarf2_const_value (attr
, sym
, cu
);
21468 list_to_add
= cu
->list_in_scope
;
21471 case DW_TAG_unspecified_parameters
:
21472 /* From varargs functions; gdb doesn't seem to have any
21473 interest in this information, so just ignore it for now.
21476 case DW_TAG_template_type_param
:
21478 /* Fall through. */
21479 case DW_TAG_class_type
:
21480 case DW_TAG_interface_type
:
21481 case DW_TAG_structure_type
:
21482 case DW_TAG_union_type
:
21483 case DW_TAG_set_type
:
21484 case DW_TAG_enumeration_type
:
21485 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21486 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
21489 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
21490 really ever be static objects: otherwise, if you try
21491 to, say, break of a class's method and you're in a file
21492 which doesn't mention that class, it won't work unless
21493 the check for all static symbols in lookup_symbol_aux
21494 saves you. See the OtherFileClass tests in
21495 gdb.c++/namespace.exp. */
21499 buildsym_compunit
*builder
= cu
->get_builder ();
21501 = (cu
->list_in_scope
== builder
->get_file_symbols ()
21502 && cu
->language
== language_cplus
21503 ? builder
->get_global_symbols ()
21504 : cu
->list_in_scope
);
21506 /* The semantics of C++ state that "struct foo {
21507 ... }" also defines a typedef for "foo". */
21508 if (cu
->language
== language_cplus
21509 || cu
->language
== language_ada
21510 || cu
->language
== language_d
21511 || cu
->language
== language_rust
)
21513 /* The symbol's name is already allocated along
21514 with this objfile, so we don't need to
21515 duplicate it for the type. */
21516 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
21517 TYPE_NAME (SYMBOL_TYPE (sym
)) = sym
->search_name ();
21522 case DW_TAG_typedef
:
21523 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21524 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21525 list_to_add
= cu
->list_in_scope
;
21527 case DW_TAG_base_type
:
21528 case DW_TAG_subrange_type
:
21529 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21530 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21531 list_to_add
= cu
->list_in_scope
;
21533 case DW_TAG_enumerator
:
21534 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21535 if (attr
!= nullptr)
21537 dwarf2_const_value (attr
, sym
, cu
);
21540 /* NOTE: carlton/2003-11-10: See comment above in the
21541 DW_TAG_class_type, etc. block. */
21544 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
21545 && cu
->language
== language_cplus
21546 ? cu
->get_builder ()->get_global_symbols ()
21547 : cu
->list_in_scope
);
21550 case DW_TAG_imported_declaration
:
21551 case DW_TAG_namespace
:
21552 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21553 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21555 case DW_TAG_module
:
21556 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21557 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
21558 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21560 case DW_TAG_common_block
:
21561 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
21562 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
21563 add_symbol_to_list (sym
, cu
->list_in_scope
);
21566 /* Not a tag we recognize. Hopefully we aren't processing
21567 trash data, but since we must specifically ignore things
21568 we don't recognize, there is nothing else we should do at
21570 complaint (_("unsupported tag: '%s'"),
21571 dwarf_tag_name (die
->tag
));
21577 sym
->hash_next
= objfile
->template_symbols
;
21578 objfile
->template_symbols
= sym
;
21579 list_to_add
= NULL
;
21582 if (list_to_add
!= NULL
)
21583 add_symbol_to_list (sym
, list_to_add
);
21585 /* For the benefit of old versions of GCC, check for anonymous
21586 namespaces based on the demangled name. */
21587 if (!cu
->processing_has_namespace_info
21588 && cu
->language
== language_cplus
)
21589 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
21594 /* Given an attr with a DW_FORM_dataN value in host byte order,
21595 zero-extend it as appropriate for the symbol's type. The DWARF
21596 standard (v4) is not entirely clear about the meaning of using
21597 DW_FORM_dataN for a constant with a signed type, where the type is
21598 wider than the data. The conclusion of a discussion on the DWARF
21599 list was that this is unspecified. We choose to always zero-extend
21600 because that is the interpretation long in use by GCC. */
21603 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
21604 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
21606 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21607 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
21608 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
21609 LONGEST l
= DW_UNSND (attr
);
21611 if (bits
< sizeof (*value
) * 8)
21613 l
&= ((LONGEST
) 1 << bits
) - 1;
21616 else if (bits
== sizeof (*value
) * 8)
21620 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
21621 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
21628 /* Read a constant value from an attribute. Either set *VALUE, or if
21629 the value does not fit in *VALUE, set *BYTES - either already
21630 allocated on the objfile obstack, or newly allocated on OBSTACK,
21631 or, set *BATON, if we translated the constant to a location
21635 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
21636 const char *name
, struct obstack
*obstack
,
21637 struct dwarf2_cu
*cu
,
21638 LONGEST
*value
, const gdb_byte
**bytes
,
21639 struct dwarf2_locexpr_baton
**baton
)
21641 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21642 struct comp_unit_head
*cu_header
= &cu
->header
;
21643 struct dwarf_block
*blk
;
21644 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
21645 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
21651 switch (attr
->form
)
21654 case DW_FORM_addrx
:
21655 case DW_FORM_GNU_addr_index
:
21659 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
21660 dwarf2_const_value_length_mismatch_complaint (name
,
21661 cu_header
->addr_size
,
21662 TYPE_LENGTH (type
));
21663 /* Symbols of this form are reasonably rare, so we just
21664 piggyback on the existing location code rather than writing
21665 a new implementation of symbol_computed_ops. */
21666 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
21667 (*baton
)->per_cu
= cu
->per_cu
;
21668 gdb_assert ((*baton
)->per_cu
);
21670 (*baton
)->size
= 2 + cu_header
->addr_size
;
21671 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
21672 (*baton
)->data
= data
;
21674 data
[0] = DW_OP_addr
;
21675 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
21676 byte_order
, DW_ADDR (attr
));
21677 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
21680 case DW_FORM_string
:
21683 case DW_FORM_GNU_str_index
:
21684 case DW_FORM_GNU_strp_alt
:
21685 /* DW_STRING is already allocated on the objfile obstack, point
21687 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
21689 case DW_FORM_block1
:
21690 case DW_FORM_block2
:
21691 case DW_FORM_block4
:
21692 case DW_FORM_block
:
21693 case DW_FORM_exprloc
:
21694 case DW_FORM_data16
:
21695 blk
= DW_BLOCK (attr
);
21696 if (TYPE_LENGTH (type
) != blk
->size
)
21697 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
21698 TYPE_LENGTH (type
));
21699 *bytes
= blk
->data
;
21702 /* The DW_AT_const_value attributes are supposed to carry the
21703 symbol's value "represented as it would be on the target
21704 architecture." By the time we get here, it's already been
21705 converted to host endianness, so we just need to sign- or
21706 zero-extend it as appropriate. */
21707 case DW_FORM_data1
:
21708 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
21710 case DW_FORM_data2
:
21711 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
21713 case DW_FORM_data4
:
21714 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
21716 case DW_FORM_data8
:
21717 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
21720 case DW_FORM_sdata
:
21721 case DW_FORM_implicit_const
:
21722 *value
= DW_SND (attr
);
21725 case DW_FORM_udata
:
21726 *value
= DW_UNSND (attr
);
21730 complaint (_("unsupported const value attribute form: '%s'"),
21731 dwarf_form_name (attr
->form
));
21738 /* Copy constant value from an attribute to a symbol. */
21741 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
21742 struct dwarf2_cu
*cu
)
21744 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21746 const gdb_byte
*bytes
;
21747 struct dwarf2_locexpr_baton
*baton
;
21749 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
21750 sym
->print_name (),
21751 &objfile
->objfile_obstack
, cu
,
21752 &value
, &bytes
, &baton
);
21756 SYMBOL_LOCATION_BATON (sym
) = baton
;
21757 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
21759 else if (bytes
!= NULL
)
21761 SYMBOL_VALUE_BYTES (sym
) = bytes
;
21762 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
21766 SYMBOL_VALUE (sym
) = value
;
21767 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
21771 /* Return the type of the die in question using its DW_AT_type attribute. */
21773 static struct type
*
21774 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21776 struct attribute
*type_attr
;
21778 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
21781 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21782 /* A missing DW_AT_type represents a void type. */
21783 return objfile_type (objfile
)->builtin_void
;
21786 return lookup_die_type (die
, type_attr
, cu
);
21789 /* True iff CU's producer generates GNAT Ada auxiliary information
21790 that allows to find parallel types through that information instead
21791 of having to do expensive parallel lookups by type name. */
21794 need_gnat_info (struct dwarf2_cu
*cu
)
21796 /* Assume that the Ada compiler was GNAT, which always produces
21797 the auxiliary information. */
21798 return (cu
->language
== language_ada
);
21801 /* Return the auxiliary type of the die in question using its
21802 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
21803 attribute is not present. */
21805 static struct type
*
21806 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21808 struct attribute
*type_attr
;
21810 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
21814 return lookup_die_type (die
, type_attr
, cu
);
21817 /* If DIE has a descriptive_type attribute, then set the TYPE's
21818 descriptive type accordingly. */
21821 set_descriptive_type (struct type
*type
, struct die_info
*die
,
21822 struct dwarf2_cu
*cu
)
21824 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
21826 if (descriptive_type
)
21828 ALLOCATE_GNAT_AUX_TYPE (type
);
21829 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
21833 /* Return the containing type of the die in question using its
21834 DW_AT_containing_type attribute. */
21836 static struct type
*
21837 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21839 struct attribute
*type_attr
;
21840 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21842 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
21844 error (_("Dwarf Error: Problem turning containing type into gdb type "
21845 "[in module %s]"), objfile_name (objfile
));
21847 return lookup_die_type (die
, type_attr
, cu
);
21850 /* Return an error marker type to use for the ill formed type in DIE/CU. */
21852 static struct type
*
21853 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
21855 struct dwarf2_per_objfile
*dwarf2_per_objfile
21856 = cu
->per_cu
->dwarf2_per_objfile
;
21857 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21860 std::string message
21861 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
21862 objfile_name (objfile
),
21863 sect_offset_str (cu
->header
.sect_off
),
21864 sect_offset_str (die
->sect_off
));
21865 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
21867 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
21870 /* Look up the type of DIE in CU using its type attribute ATTR.
21871 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
21872 DW_AT_containing_type.
21873 If there is no type substitute an error marker. */
21875 static struct type
*
21876 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
21877 struct dwarf2_cu
*cu
)
21879 struct dwarf2_per_objfile
*dwarf2_per_objfile
21880 = cu
->per_cu
->dwarf2_per_objfile
;
21881 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21882 struct type
*this_type
;
21884 gdb_assert (attr
->name
== DW_AT_type
21885 || attr
->name
== DW_AT_GNAT_descriptive_type
21886 || attr
->name
== DW_AT_containing_type
);
21888 /* First see if we have it cached. */
21890 if (attr
->form
== DW_FORM_GNU_ref_alt
)
21892 struct dwarf2_per_cu_data
*per_cu
;
21893 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
21895 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
21896 dwarf2_per_objfile
);
21897 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
21899 else if (attr
->form_is_ref ())
21901 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
21903 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
21905 else if (attr
->form
== DW_FORM_ref_sig8
)
21907 ULONGEST signature
= DW_SIGNATURE (attr
);
21909 return get_signatured_type (die
, signature
, cu
);
21913 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
21914 " at %s [in module %s]"),
21915 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
21916 objfile_name (objfile
));
21917 return build_error_marker_type (cu
, die
);
21920 /* If not cached we need to read it in. */
21922 if (this_type
== NULL
)
21924 struct die_info
*type_die
= NULL
;
21925 struct dwarf2_cu
*type_cu
= cu
;
21927 if (attr
->form_is_ref ())
21928 type_die
= follow_die_ref (die
, attr
, &type_cu
);
21929 if (type_die
== NULL
)
21930 return build_error_marker_type (cu
, die
);
21931 /* If we find the type now, it's probably because the type came
21932 from an inter-CU reference and the type's CU got expanded before
21934 this_type
= read_type_die (type_die
, type_cu
);
21937 /* If we still don't have a type use an error marker. */
21939 if (this_type
== NULL
)
21940 return build_error_marker_type (cu
, die
);
21945 /* Return the type in DIE, CU.
21946 Returns NULL for invalid types.
21948 This first does a lookup in die_type_hash,
21949 and only reads the die in if necessary.
21951 NOTE: This can be called when reading in partial or full symbols. */
21953 static struct type
*
21954 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
21956 struct type
*this_type
;
21958 this_type
= get_die_type (die
, cu
);
21962 return read_type_die_1 (die
, cu
);
21965 /* Read the type in DIE, CU.
21966 Returns NULL for invalid types. */
21968 static struct type
*
21969 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
21971 struct type
*this_type
= NULL
;
21975 case DW_TAG_class_type
:
21976 case DW_TAG_interface_type
:
21977 case DW_TAG_structure_type
:
21978 case DW_TAG_union_type
:
21979 this_type
= read_structure_type (die
, cu
);
21981 case DW_TAG_enumeration_type
:
21982 this_type
= read_enumeration_type (die
, cu
);
21984 case DW_TAG_subprogram
:
21985 case DW_TAG_subroutine_type
:
21986 case DW_TAG_inlined_subroutine
:
21987 this_type
= read_subroutine_type (die
, cu
);
21989 case DW_TAG_array_type
:
21990 this_type
= read_array_type (die
, cu
);
21992 case DW_TAG_set_type
:
21993 this_type
= read_set_type (die
, cu
);
21995 case DW_TAG_pointer_type
:
21996 this_type
= read_tag_pointer_type (die
, cu
);
21998 case DW_TAG_ptr_to_member_type
:
21999 this_type
= read_tag_ptr_to_member_type (die
, cu
);
22001 case DW_TAG_reference_type
:
22002 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
22004 case DW_TAG_rvalue_reference_type
:
22005 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
22007 case DW_TAG_const_type
:
22008 this_type
= read_tag_const_type (die
, cu
);
22010 case DW_TAG_volatile_type
:
22011 this_type
= read_tag_volatile_type (die
, cu
);
22013 case DW_TAG_restrict_type
:
22014 this_type
= read_tag_restrict_type (die
, cu
);
22016 case DW_TAG_string_type
:
22017 this_type
= read_tag_string_type (die
, cu
);
22019 case DW_TAG_typedef
:
22020 this_type
= read_typedef (die
, cu
);
22022 case DW_TAG_subrange_type
:
22023 this_type
= read_subrange_type (die
, cu
);
22025 case DW_TAG_base_type
:
22026 this_type
= read_base_type (die
, cu
);
22028 case DW_TAG_unspecified_type
:
22029 this_type
= read_unspecified_type (die
, cu
);
22031 case DW_TAG_namespace
:
22032 this_type
= read_namespace_type (die
, cu
);
22034 case DW_TAG_module
:
22035 this_type
= read_module_type (die
, cu
);
22037 case DW_TAG_atomic_type
:
22038 this_type
= read_tag_atomic_type (die
, cu
);
22041 complaint (_("unexpected tag in read_type_die: '%s'"),
22042 dwarf_tag_name (die
->tag
));
22049 /* See if we can figure out if the class lives in a namespace. We do
22050 this by looking for a member function; its demangled name will
22051 contain namespace info, if there is any.
22052 Return the computed name or NULL.
22053 Space for the result is allocated on the objfile's obstack.
22054 This is the full-die version of guess_partial_die_structure_name.
22055 In this case we know DIE has no useful parent. */
22057 static const char *
22058 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22060 struct die_info
*spec_die
;
22061 struct dwarf2_cu
*spec_cu
;
22062 struct die_info
*child
;
22063 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22066 spec_die
= die_specification (die
, &spec_cu
);
22067 if (spec_die
!= NULL
)
22073 for (child
= die
->child
;
22075 child
= child
->sibling
)
22077 if (child
->tag
== DW_TAG_subprogram
)
22079 const char *linkage_name
= dw2_linkage_name (child
, cu
);
22081 if (linkage_name
!= NULL
)
22083 gdb::unique_xmalloc_ptr
<char> actual_name
22084 (language_class_name_from_physname (cu
->language_defn
,
22086 const char *name
= NULL
;
22088 if (actual_name
!= NULL
)
22090 const char *die_name
= dwarf2_name (die
, cu
);
22092 if (die_name
!= NULL
22093 && strcmp (die_name
, actual_name
.get ()) != 0)
22095 /* Strip off the class name from the full name.
22096 We want the prefix. */
22097 int die_name_len
= strlen (die_name
);
22098 int actual_name_len
= strlen (actual_name
.get ());
22099 const char *ptr
= actual_name
.get ();
22101 /* Test for '::' as a sanity check. */
22102 if (actual_name_len
> die_name_len
+ 2
22103 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
22104 name
= obstack_strndup (
22105 &objfile
->per_bfd
->storage_obstack
,
22106 ptr
, actual_name_len
- die_name_len
- 2);
22117 /* GCC might emit a nameless typedef that has a linkage name. Determine the
22118 prefix part in such case. See
22119 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22121 static const char *
22122 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22124 struct attribute
*attr
;
22127 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
22128 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
22131 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
22134 attr
= dw2_linkage_name_attr (die
, cu
);
22135 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22138 /* dwarf2_name had to be already called. */
22139 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
22141 /* Strip the base name, keep any leading namespaces/classes. */
22142 base
= strrchr (DW_STRING (attr
), ':');
22143 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
22146 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22147 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
22149 &base
[-1] - DW_STRING (attr
));
22152 /* Return the name of the namespace/class that DIE is defined within,
22153 or "" if we can't tell. The caller should not xfree the result.
22155 For example, if we're within the method foo() in the following
22165 then determine_prefix on foo's die will return "N::C". */
22167 static const char *
22168 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22170 struct dwarf2_per_objfile
*dwarf2_per_objfile
22171 = cu
->per_cu
->dwarf2_per_objfile
;
22172 struct die_info
*parent
, *spec_die
;
22173 struct dwarf2_cu
*spec_cu
;
22174 struct type
*parent_type
;
22175 const char *retval
;
22177 if (cu
->language
!= language_cplus
22178 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
22179 && cu
->language
!= language_rust
)
22182 retval
= anonymous_struct_prefix (die
, cu
);
22186 /* We have to be careful in the presence of DW_AT_specification.
22187 For example, with GCC 3.4, given the code
22191 // Definition of N::foo.
22195 then we'll have a tree of DIEs like this:
22197 1: DW_TAG_compile_unit
22198 2: DW_TAG_namespace // N
22199 3: DW_TAG_subprogram // declaration of N::foo
22200 4: DW_TAG_subprogram // definition of N::foo
22201 DW_AT_specification // refers to die #3
22203 Thus, when processing die #4, we have to pretend that we're in
22204 the context of its DW_AT_specification, namely the contex of die
22207 spec_die
= die_specification (die
, &spec_cu
);
22208 if (spec_die
== NULL
)
22209 parent
= die
->parent
;
22212 parent
= spec_die
->parent
;
22216 if (parent
== NULL
)
22218 else if (parent
->building_fullname
)
22221 const char *parent_name
;
22223 /* It has been seen on RealView 2.2 built binaries,
22224 DW_TAG_template_type_param types actually _defined_ as
22225 children of the parent class:
22228 template class <class Enum> Class{};
22229 Class<enum E> class_e;
22231 1: DW_TAG_class_type (Class)
22232 2: DW_TAG_enumeration_type (E)
22233 3: DW_TAG_enumerator (enum1:0)
22234 3: DW_TAG_enumerator (enum2:1)
22236 2: DW_TAG_template_type_param
22237 DW_AT_type DW_FORM_ref_udata (E)
22239 Besides being broken debug info, it can put GDB into an
22240 infinite loop. Consider:
22242 When we're building the full name for Class<E>, we'll start
22243 at Class, and go look over its template type parameters,
22244 finding E. We'll then try to build the full name of E, and
22245 reach here. We're now trying to build the full name of E,
22246 and look over the parent DIE for containing scope. In the
22247 broken case, if we followed the parent DIE of E, we'd again
22248 find Class, and once again go look at its template type
22249 arguments, etc., etc. Simply don't consider such parent die
22250 as source-level parent of this die (it can't be, the language
22251 doesn't allow it), and break the loop here. */
22252 name
= dwarf2_name (die
, cu
);
22253 parent_name
= dwarf2_name (parent
, cu
);
22254 complaint (_("template param type '%s' defined within parent '%s'"),
22255 name
? name
: "<unknown>",
22256 parent_name
? parent_name
: "<unknown>");
22260 switch (parent
->tag
)
22262 case DW_TAG_namespace
:
22263 parent_type
= read_type_die (parent
, cu
);
22264 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
22265 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
22266 Work around this problem here. */
22267 if (cu
->language
== language_cplus
22268 && strcmp (TYPE_NAME (parent_type
), "::") == 0)
22270 /* We give a name to even anonymous namespaces. */
22271 return TYPE_NAME (parent_type
);
22272 case DW_TAG_class_type
:
22273 case DW_TAG_interface_type
:
22274 case DW_TAG_structure_type
:
22275 case DW_TAG_union_type
:
22276 case DW_TAG_module
:
22277 parent_type
= read_type_die (parent
, cu
);
22278 if (TYPE_NAME (parent_type
) != NULL
)
22279 return TYPE_NAME (parent_type
);
22281 /* An anonymous structure is only allowed non-static data
22282 members; no typedefs, no member functions, et cetera.
22283 So it does not need a prefix. */
22285 case DW_TAG_compile_unit
:
22286 case DW_TAG_partial_unit
:
22287 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
22288 if (cu
->language
== language_cplus
22289 && !dwarf2_per_objfile
->types
.empty ()
22290 && die
->child
!= NULL
22291 && (die
->tag
== DW_TAG_class_type
22292 || die
->tag
== DW_TAG_structure_type
22293 || die
->tag
== DW_TAG_union_type
))
22295 const char *name
= guess_full_die_structure_name (die
, cu
);
22300 case DW_TAG_subprogram
:
22301 /* Nested subroutines in Fortran get a prefix with the name
22302 of the parent's subroutine. */
22303 if (cu
->language
== language_fortran
)
22305 if ((die
->tag
== DW_TAG_subprogram
)
22306 && (dwarf2_name (parent
, cu
) != NULL
))
22307 return dwarf2_name (parent
, cu
);
22309 return determine_prefix (parent
, cu
);
22310 case DW_TAG_enumeration_type
:
22311 parent_type
= read_type_die (parent
, cu
);
22312 if (TYPE_DECLARED_CLASS (parent_type
))
22314 if (TYPE_NAME (parent_type
) != NULL
)
22315 return TYPE_NAME (parent_type
);
22318 /* Fall through. */
22320 return determine_prefix (parent
, cu
);
22324 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
22325 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
22326 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
22327 an obconcat, otherwise allocate storage for the result. The CU argument is
22328 used to determine the language and hence, the appropriate separator. */
22330 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
22333 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
22334 int physname
, struct dwarf2_cu
*cu
)
22336 const char *lead
= "";
22339 if (suffix
== NULL
|| suffix
[0] == '\0'
22340 || prefix
== NULL
|| prefix
[0] == '\0')
22342 else if (cu
->language
== language_d
)
22344 /* For D, the 'main' function could be defined in any module, but it
22345 should never be prefixed. */
22346 if (strcmp (suffix
, "D main") == 0)
22354 else if (cu
->language
== language_fortran
&& physname
)
22356 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
22357 DW_AT_MIPS_linkage_name is preferred and used instead. */
22365 if (prefix
== NULL
)
22367 if (suffix
== NULL
)
22374 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
22376 strcpy (retval
, lead
);
22377 strcat (retval
, prefix
);
22378 strcat (retval
, sep
);
22379 strcat (retval
, suffix
);
22384 /* We have an obstack. */
22385 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
22389 /* Return sibling of die, NULL if no sibling. */
22391 static struct die_info
*
22392 sibling_die (struct die_info
*die
)
22394 return die
->sibling
;
22397 /* Get name of a die, return NULL if not found. */
22399 static const char *
22400 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
22401 struct obstack
*obstack
)
22403 if (name
&& cu
->language
== language_cplus
)
22405 std::string canon_name
= cp_canonicalize_string (name
);
22407 if (!canon_name
.empty ())
22409 if (canon_name
!= name
)
22410 name
= obstack_strdup (obstack
, canon_name
);
22417 /* Get name of a die, return NULL if not found.
22418 Anonymous namespaces are converted to their magic string. */
22420 static const char *
22421 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22423 struct attribute
*attr
;
22424 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22426 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
22427 if ((!attr
|| !DW_STRING (attr
))
22428 && die
->tag
!= DW_TAG_namespace
22429 && die
->tag
!= DW_TAG_class_type
22430 && die
->tag
!= DW_TAG_interface_type
22431 && die
->tag
!= DW_TAG_structure_type
22432 && die
->tag
!= DW_TAG_union_type
)
22437 case DW_TAG_compile_unit
:
22438 case DW_TAG_partial_unit
:
22439 /* Compilation units have a DW_AT_name that is a filename, not
22440 a source language identifier. */
22441 case DW_TAG_enumeration_type
:
22442 case DW_TAG_enumerator
:
22443 /* These tags always have simple identifiers already; no need
22444 to canonicalize them. */
22445 return DW_STRING (attr
);
22447 case DW_TAG_namespace
:
22448 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
22449 return DW_STRING (attr
);
22450 return CP_ANONYMOUS_NAMESPACE_STR
;
22452 case DW_TAG_class_type
:
22453 case DW_TAG_interface_type
:
22454 case DW_TAG_structure_type
:
22455 case DW_TAG_union_type
:
22456 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
22457 structures or unions. These were of the form "._%d" in GCC 4.1,
22458 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
22459 and GCC 4.4. We work around this problem by ignoring these. */
22460 if (attr
&& DW_STRING (attr
)
22461 && (startswith (DW_STRING (attr
), "._")
22462 || startswith (DW_STRING (attr
), "<anonymous")))
22465 /* GCC might emit a nameless typedef that has a linkage name. See
22466 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22467 if (!attr
|| DW_STRING (attr
) == NULL
)
22469 attr
= dw2_linkage_name_attr (die
, cu
);
22470 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22473 /* Avoid demangling DW_STRING (attr) the second time on a second
22474 call for the same DIE. */
22475 if (!DW_STRING_IS_CANONICAL (attr
))
22477 gdb::unique_xmalloc_ptr
<char> demangled
22478 (gdb_demangle (DW_STRING (attr
), DMGL_TYPES
));
22482 /* FIXME: we already did this for the partial symbol... */
22484 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
22486 DW_STRING_IS_CANONICAL (attr
) = 1;
22488 /* Strip any leading namespaces/classes, keep only the base name.
22489 DW_AT_name for named DIEs does not contain the prefixes. */
22490 base
= strrchr (DW_STRING (attr
), ':');
22491 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
22494 return DW_STRING (attr
);
22503 if (!DW_STRING_IS_CANONICAL (attr
))
22506 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
22507 &objfile
->per_bfd
->storage_obstack
);
22508 DW_STRING_IS_CANONICAL (attr
) = 1;
22510 return DW_STRING (attr
);
22513 /* Return the die that this die in an extension of, or NULL if there
22514 is none. *EXT_CU is the CU containing DIE on input, and the CU
22515 containing the return value on output. */
22517 static struct die_info
*
22518 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
22520 struct attribute
*attr
;
22522 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
22526 return follow_die_ref (die
, attr
, ext_cu
);
22529 /* A convenience function that returns an "unknown" DWARF name,
22530 including the value of V. STR is the name of the entity being
22531 printed, e.g., "TAG". */
22533 static const char *
22534 dwarf_unknown (const char *str
, unsigned v
)
22536 char *cell
= get_print_cell ();
22537 xsnprintf (cell
, PRINT_CELL_SIZE
, "DW_%s_<unknown: %u>", str
, v
);
22541 /* Convert a DIE tag into its string name. */
22543 static const char *
22544 dwarf_tag_name (unsigned tag
)
22546 const char *name
= get_DW_TAG_name (tag
);
22549 return dwarf_unknown ("TAG", tag
);
22554 /* Convert a DWARF attribute code into its string name. */
22556 static const char *
22557 dwarf_attr_name (unsigned attr
)
22561 #ifdef MIPS /* collides with DW_AT_HP_block_index */
22562 if (attr
== DW_AT_MIPS_fde
)
22563 return "DW_AT_MIPS_fde";
22565 if (attr
== DW_AT_HP_block_index
)
22566 return "DW_AT_HP_block_index";
22569 name
= get_DW_AT_name (attr
);
22572 return dwarf_unknown ("AT", attr
);
22577 /* Convert a unit type to corresponding DW_UT name. */
22579 static const char *
22580 dwarf_unit_type_name (int unit_type
) {
22584 return "DW_UT_compile (0x01)";
22586 return "DW_UT_type (0x02)";
22588 return "DW_UT_partial (0x03)";
22590 return "DW_UT_skeleton (0x04)";
22592 return "DW_UT_split_compile (0x05)";
22594 return "DW_UT_split_type (0x06)";
22596 return "DW_UT_lo_user (0x80)";
22598 return "DW_UT_hi_user (0xff)";
22604 /* Convert a DWARF value form code into its string name. */
22606 static const char *
22607 dwarf_form_name (unsigned form
)
22609 const char *name
= get_DW_FORM_name (form
);
22612 return dwarf_unknown ("FORM", form
);
22617 static const char *
22618 dwarf_bool_name (unsigned mybool
)
22626 /* Convert a DWARF type code into its string name. */
22628 static const char *
22629 dwarf_type_encoding_name (unsigned enc
)
22631 const char *name
= get_DW_ATE_name (enc
);
22634 return dwarf_unknown ("ATE", enc
);
22640 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
22644 print_spaces (indent
, f
);
22645 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
22646 dwarf_tag_name (die
->tag
), die
->abbrev
,
22647 sect_offset_str (die
->sect_off
));
22649 if (die
->parent
!= NULL
)
22651 print_spaces (indent
, f
);
22652 fprintf_unfiltered (f
, " parent at offset: %s\n",
22653 sect_offset_str (die
->parent
->sect_off
));
22656 print_spaces (indent
, f
);
22657 fprintf_unfiltered (f
, " has children: %s\n",
22658 dwarf_bool_name (die
->child
!= NULL
));
22660 print_spaces (indent
, f
);
22661 fprintf_unfiltered (f
, " attributes:\n");
22663 for (i
= 0; i
< die
->num_attrs
; ++i
)
22665 print_spaces (indent
, f
);
22666 fprintf_unfiltered (f
, " %s (%s) ",
22667 dwarf_attr_name (die
->attrs
[i
].name
),
22668 dwarf_form_name (die
->attrs
[i
].form
));
22670 switch (die
->attrs
[i
].form
)
22673 case DW_FORM_addrx
:
22674 case DW_FORM_GNU_addr_index
:
22675 fprintf_unfiltered (f
, "address: ");
22676 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
22678 case DW_FORM_block2
:
22679 case DW_FORM_block4
:
22680 case DW_FORM_block
:
22681 case DW_FORM_block1
:
22682 fprintf_unfiltered (f
, "block: size %s",
22683 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22685 case DW_FORM_exprloc
:
22686 fprintf_unfiltered (f
, "expression: size %s",
22687 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22689 case DW_FORM_data16
:
22690 fprintf_unfiltered (f
, "constant of 16 bytes");
22692 case DW_FORM_ref_addr
:
22693 fprintf_unfiltered (f
, "ref address: ");
22694 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22696 case DW_FORM_GNU_ref_alt
:
22697 fprintf_unfiltered (f
, "alt ref address: ");
22698 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22704 case DW_FORM_ref_udata
:
22705 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
22706 (long) (DW_UNSND (&die
->attrs
[i
])));
22708 case DW_FORM_data1
:
22709 case DW_FORM_data2
:
22710 case DW_FORM_data4
:
22711 case DW_FORM_data8
:
22712 case DW_FORM_udata
:
22713 case DW_FORM_sdata
:
22714 fprintf_unfiltered (f
, "constant: %s",
22715 pulongest (DW_UNSND (&die
->attrs
[i
])));
22717 case DW_FORM_sec_offset
:
22718 fprintf_unfiltered (f
, "section offset: %s",
22719 pulongest (DW_UNSND (&die
->attrs
[i
])));
22721 case DW_FORM_ref_sig8
:
22722 fprintf_unfiltered (f
, "signature: %s",
22723 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
22725 case DW_FORM_string
:
22727 case DW_FORM_line_strp
:
22729 case DW_FORM_GNU_str_index
:
22730 case DW_FORM_GNU_strp_alt
:
22731 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
22732 DW_STRING (&die
->attrs
[i
])
22733 ? DW_STRING (&die
->attrs
[i
]) : "",
22734 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
22737 if (DW_UNSND (&die
->attrs
[i
]))
22738 fprintf_unfiltered (f
, "flag: TRUE");
22740 fprintf_unfiltered (f
, "flag: FALSE");
22742 case DW_FORM_flag_present
:
22743 fprintf_unfiltered (f
, "flag: TRUE");
22745 case DW_FORM_indirect
:
22746 /* The reader will have reduced the indirect form to
22747 the "base form" so this form should not occur. */
22748 fprintf_unfiltered (f
,
22749 "unexpected attribute form: DW_FORM_indirect");
22751 case DW_FORM_implicit_const
:
22752 fprintf_unfiltered (f
, "constant: %s",
22753 plongest (DW_SND (&die
->attrs
[i
])));
22756 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
22757 die
->attrs
[i
].form
);
22760 fprintf_unfiltered (f
, "\n");
22765 dump_die_for_error (struct die_info
*die
)
22767 dump_die_shallow (gdb_stderr
, 0, die
);
22771 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
22773 int indent
= level
* 4;
22775 gdb_assert (die
!= NULL
);
22777 if (level
>= max_level
)
22780 dump_die_shallow (f
, indent
, die
);
22782 if (die
->child
!= NULL
)
22784 print_spaces (indent
, f
);
22785 fprintf_unfiltered (f
, " Children:");
22786 if (level
+ 1 < max_level
)
22788 fprintf_unfiltered (f
, "\n");
22789 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
22793 fprintf_unfiltered (f
,
22794 " [not printed, max nesting level reached]\n");
22798 if (die
->sibling
!= NULL
&& level
> 0)
22800 dump_die_1 (f
, level
, max_level
, die
->sibling
);
22804 /* This is called from the pdie macro in gdbinit.in.
22805 It's not static so gcc will keep a copy callable from gdb. */
22808 dump_die (struct die_info
*die
, int max_level
)
22810 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
22814 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
22818 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
22819 to_underlying (die
->sect_off
),
22825 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
22829 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
22831 if (attr
->form_is_ref ())
22832 return (sect_offset
) DW_UNSND (attr
);
22834 complaint (_("unsupported die ref attribute form: '%s'"),
22835 dwarf_form_name (attr
->form
));
22839 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
22840 * the value held by the attribute is not constant. */
22843 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
22845 if (attr
->form
== DW_FORM_sdata
|| attr
->form
== DW_FORM_implicit_const
)
22846 return DW_SND (attr
);
22847 else if (attr
->form
== DW_FORM_udata
22848 || attr
->form
== DW_FORM_data1
22849 || attr
->form
== DW_FORM_data2
22850 || attr
->form
== DW_FORM_data4
22851 || attr
->form
== DW_FORM_data8
)
22852 return DW_UNSND (attr
);
22855 /* For DW_FORM_data16 see attribute::form_is_constant. */
22856 complaint (_("Attribute value is not a constant (%s)"),
22857 dwarf_form_name (attr
->form
));
22858 return default_value
;
22862 /* Follow reference or signature attribute ATTR of SRC_DIE.
22863 On entry *REF_CU is the CU of SRC_DIE.
22864 On exit *REF_CU is the CU of the result. */
22866 static struct die_info
*
22867 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22868 struct dwarf2_cu
**ref_cu
)
22870 struct die_info
*die
;
22872 if (attr
->form_is_ref ())
22873 die
= follow_die_ref (src_die
, attr
, ref_cu
);
22874 else if (attr
->form
== DW_FORM_ref_sig8
)
22875 die
= follow_die_sig (src_die
, attr
, ref_cu
);
22878 dump_die_for_error (src_die
);
22879 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
22880 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22886 /* Follow reference OFFSET.
22887 On entry *REF_CU is the CU of the source die referencing OFFSET.
22888 On exit *REF_CU is the CU of the result.
22889 Returns NULL if OFFSET is invalid. */
22891 static struct die_info
*
22892 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
22893 struct dwarf2_cu
**ref_cu
)
22895 struct die_info temp_die
;
22896 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
22897 struct dwarf2_per_objfile
*dwarf2_per_objfile
22898 = cu
->per_cu
->dwarf2_per_objfile
;
22900 gdb_assert (cu
->per_cu
!= NULL
);
22904 if (cu
->per_cu
->is_debug_types
)
22906 /* .debug_types CUs cannot reference anything outside their CU.
22907 If they need to, they have to reference a signatured type via
22908 DW_FORM_ref_sig8. */
22909 if (!offset_in_cu_p (&cu
->header
, sect_off
))
22912 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
22913 || !offset_in_cu_p (&cu
->header
, sect_off
))
22915 struct dwarf2_per_cu_data
*per_cu
;
22917 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
22918 dwarf2_per_objfile
);
22920 /* If necessary, add it to the queue and load its DIEs. */
22921 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
22922 load_full_comp_unit (per_cu
, false, cu
->language
);
22924 target_cu
= per_cu
->cu
;
22926 else if (cu
->dies
== NULL
)
22928 /* We're loading full DIEs during partial symbol reading. */
22929 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
22930 load_full_comp_unit (cu
->per_cu
, false, language_minimal
);
22933 *ref_cu
= target_cu
;
22934 temp_die
.sect_off
= sect_off
;
22936 if (target_cu
!= cu
)
22937 target_cu
->ancestor
= cu
;
22939 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
22941 to_underlying (sect_off
));
22944 /* Follow reference attribute ATTR of SRC_DIE.
22945 On entry *REF_CU is the CU of SRC_DIE.
22946 On exit *REF_CU is the CU of the result. */
22948 static struct die_info
*
22949 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
22950 struct dwarf2_cu
**ref_cu
)
22952 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22953 struct dwarf2_cu
*cu
= *ref_cu
;
22954 struct die_info
*die
;
22956 die
= follow_die_offset (sect_off
,
22957 (attr
->form
== DW_FORM_GNU_ref_alt
22958 || cu
->per_cu
->is_dwz
),
22961 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
22962 "at %s [in module %s]"),
22963 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
22964 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
22969 /* Return DWARF block referenced by DW_AT_location of DIE at SECT_OFF at PER_CU.
22970 Returned value is intended for DW_OP_call*. Returned
22971 dwarf2_locexpr_baton->data has lifetime of
22972 PER_CU->DWARF2_PER_OBJFILE->OBJFILE. */
22974 struct dwarf2_locexpr_baton
22975 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
22976 struct dwarf2_per_cu_data
*per_cu
,
22977 CORE_ADDR (*get_frame_pc
) (void *baton
),
22978 void *baton
, bool resolve_abstract_p
)
22980 struct dwarf2_cu
*cu
;
22981 struct die_info
*die
;
22982 struct attribute
*attr
;
22983 struct dwarf2_locexpr_baton retval
;
22984 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
22985 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22987 if (per_cu
->cu
== NULL
)
22988 load_cu (per_cu
, false);
22992 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22993 Instead just throw an error, not much else we can do. */
22994 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22995 sect_offset_str (sect_off
), objfile_name (objfile
));
22998 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23000 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23001 sect_offset_str (sect_off
), objfile_name (objfile
));
23003 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23004 if (!attr
&& resolve_abstract_p
23005 && (dwarf2_per_objfile
->abstract_to_concrete
.find (die
->sect_off
)
23006 != dwarf2_per_objfile
->abstract_to_concrete
.end ()))
23008 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
23009 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
23010 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
23012 for (const auto &cand_off
23013 : dwarf2_per_objfile
->abstract_to_concrete
[die
->sect_off
])
23015 struct dwarf2_cu
*cand_cu
= cu
;
23016 struct die_info
*cand
23017 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
23020 || cand
->parent
->tag
!= DW_TAG_subprogram
)
23023 CORE_ADDR pc_low
, pc_high
;
23024 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
23025 if (pc_low
== ((CORE_ADDR
) -1))
23027 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
23028 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
23029 if (!(pc_low
<= pc
&& pc
< pc_high
))
23033 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23040 /* DWARF: "If there is no such attribute, then there is no effect.".
23041 DATA is ignored if SIZE is 0. */
23043 retval
.data
= NULL
;
23046 else if (attr
->form_is_section_offset ())
23048 struct dwarf2_loclist_baton loclist_baton
;
23049 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
23052 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
23054 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
23056 retval
.size
= size
;
23060 if (!attr
->form_is_block ())
23061 error (_("Dwarf Error: DIE at %s referenced in module %s "
23062 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
23063 sect_offset_str (sect_off
), objfile_name (objfile
));
23065 retval
.data
= DW_BLOCK (attr
)->data
;
23066 retval
.size
= DW_BLOCK (attr
)->size
;
23068 retval
.per_cu
= cu
->per_cu
;
23070 age_cached_comp_units (dwarf2_per_objfile
);
23075 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
23078 struct dwarf2_locexpr_baton
23079 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
23080 struct dwarf2_per_cu_data
*per_cu
,
23081 CORE_ADDR (*get_frame_pc
) (void *baton
),
23084 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
23086 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
23089 /* Write a constant of a given type as target-ordered bytes into
23092 static const gdb_byte
*
23093 write_constant_as_bytes (struct obstack
*obstack
,
23094 enum bfd_endian byte_order
,
23101 *len
= TYPE_LENGTH (type
);
23102 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23103 store_unsigned_integer (result
, *len
, byte_order
, value
);
23108 /* If the DIE at OFFSET in PER_CU has a DW_AT_const_value, return a
23109 pointer to the constant bytes and set LEN to the length of the
23110 data. If memory is needed, allocate it on OBSTACK. If the DIE
23111 does not have a DW_AT_const_value, return NULL. */
23114 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
23115 struct dwarf2_per_cu_data
*per_cu
,
23116 struct obstack
*obstack
,
23119 struct dwarf2_cu
*cu
;
23120 struct die_info
*die
;
23121 struct attribute
*attr
;
23122 const gdb_byte
*result
= NULL
;
23125 enum bfd_endian byte_order
;
23126 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
23128 if (per_cu
->cu
== NULL
)
23129 load_cu (per_cu
, false);
23133 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23134 Instead just throw an error, not much else we can do. */
23135 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23136 sect_offset_str (sect_off
), objfile_name (objfile
));
23139 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23141 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23142 sect_offset_str (sect_off
), objfile_name (objfile
));
23144 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23148 byte_order
= (bfd_big_endian (objfile
->obfd
)
23149 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
23151 switch (attr
->form
)
23154 case DW_FORM_addrx
:
23155 case DW_FORM_GNU_addr_index
:
23159 *len
= cu
->header
.addr_size
;
23160 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23161 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
23165 case DW_FORM_string
:
23168 case DW_FORM_GNU_str_index
:
23169 case DW_FORM_GNU_strp_alt
:
23170 /* DW_STRING is already allocated on the objfile obstack, point
23172 result
= (const gdb_byte
*) DW_STRING (attr
);
23173 *len
= strlen (DW_STRING (attr
));
23175 case DW_FORM_block1
:
23176 case DW_FORM_block2
:
23177 case DW_FORM_block4
:
23178 case DW_FORM_block
:
23179 case DW_FORM_exprloc
:
23180 case DW_FORM_data16
:
23181 result
= DW_BLOCK (attr
)->data
;
23182 *len
= DW_BLOCK (attr
)->size
;
23185 /* The DW_AT_const_value attributes are supposed to carry the
23186 symbol's value "represented as it would be on the target
23187 architecture." By the time we get here, it's already been
23188 converted to host endianness, so we just need to sign- or
23189 zero-extend it as appropriate. */
23190 case DW_FORM_data1
:
23191 type
= die_type (die
, cu
);
23192 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
23193 if (result
== NULL
)
23194 result
= write_constant_as_bytes (obstack
, byte_order
,
23197 case DW_FORM_data2
:
23198 type
= die_type (die
, cu
);
23199 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
23200 if (result
== NULL
)
23201 result
= write_constant_as_bytes (obstack
, byte_order
,
23204 case DW_FORM_data4
:
23205 type
= die_type (die
, cu
);
23206 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
23207 if (result
== NULL
)
23208 result
= write_constant_as_bytes (obstack
, byte_order
,
23211 case DW_FORM_data8
:
23212 type
= die_type (die
, cu
);
23213 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
23214 if (result
== NULL
)
23215 result
= write_constant_as_bytes (obstack
, byte_order
,
23219 case DW_FORM_sdata
:
23220 case DW_FORM_implicit_const
:
23221 type
= die_type (die
, cu
);
23222 result
= write_constant_as_bytes (obstack
, byte_order
,
23223 type
, DW_SND (attr
), len
);
23226 case DW_FORM_udata
:
23227 type
= die_type (die
, cu
);
23228 result
= write_constant_as_bytes (obstack
, byte_order
,
23229 type
, DW_UNSND (attr
), len
);
23233 complaint (_("unsupported const value attribute form: '%s'"),
23234 dwarf_form_name (attr
->form
));
23241 /* Return the type of the die at OFFSET in PER_CU. Return NULL if no
23242 valid type for this die is found. */
23245 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
23246 struct dwarf2_per_cu_data
*per_cu
)
23248 struct dwarf2_cu
*cu
;
23249 struct die_info
*die
;
23251 if (per_cu
->cu
== NULL
)
23252 load_cu (per_cu
, false);
23257 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23261 return die_type (die
, cu
);
23264 /* Return the type of the DIE at DIE_OFFSET in the CU named by
23268 dwarf2_get_die_type (cu_offset die_offset
,
23269 struct dwarf2_per_cu_data
*per_cu
)
23271 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
23272 return get_die_type_at_offset (die_offset_sect
, per_cu
);
23275 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
23276 On entry *REF_CU is the CU of SRC_DIE.
23277 On exit *REF_CU is the CU of the result.
23278 Returns NULL if the referenced DIE isn't found. */
23280 static struct die_info
*
23281 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
23282 struct dwarf2_cu
**ref_cu
)
23284 struct die_info temp_die
;
23285 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
23286 struct die_info
*die
;
23288 /* While it might be nice to assert sig_type->type == NULL here,
23289 we can get here for DW_AT_imported_declaration where we need
23290 the DIE not the type. */
23292 /* If necessary, add it to the queue and load its DIEs. */
23294 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
23295 read_signatured_type (sig_type
);
23297 sig_cu
= sig_type
->per_cu
.cu
;
23298 gdb_assert (sig_cu
!= NULL
);
23299 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
23300 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
23301 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
23302 to_underlying (temp_die
.sect_off
));
23305 struct dwarf2_per_objfile
*dwarf2_per_objfile
23306 = (*ref_cu
)->per_cu
->dwarf2_per_objfile
;
23308 /* For .gdb_index version 7 keep track of included TUs.
23309 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
23310 if (dwarf2_per_objfile
->index_table
!= NULL
23311 && dwarf2_per_objfile
->index_table
->version
<= 7)
23313 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
23318 sig_cu
->ancestor
= cu
;
23326 /* Follow signatured type referenced by ATTR in SRC_DIE.
23327 On entry *REF_CU is the CU of SRC_DIE.
23328 On exit *REF_CU is the CU of the result.
23329 The result is the DIE of the type.
23330 If the referenced type cannot be found an error is thrown. */
23332 static struct die_info
*
23333 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23334 struct dwarf2_cu
**ref_cu
)
23336 ULONGEST signature
= DW_SIGNATURE (attr
);
23337 struct signatured_type
*sig_type
;
23338 struct die_info
*die
;
23340 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
23342 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
23343 /* sig_type will be NULL if the signatured type is missing from
23345 if (sig_type
== NULL
)
23347 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23348 " from DIE at %s [in module %s]"),
23349 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23350 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23353 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
23356 dump_die_for_error (src_die
);
23357 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23358 " from DIE at %s [in module %s]"),
23359 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23360 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23366 /* Get the type specified by SIGNATURE referenced in DIE/CU,
23367 reading in and processing the type unit if necessary. */
23369 static struct type
*
23370 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
23371 struct dwarf2_cu
*cu
)
23373 struct dwarf2_per_objfile
*dwarf2_per_objfile
23374 = cu
->per_cu
->dwarf2_per_objfile
;
23375 struct signatured_type
*sig_type
;
23376 struct dwarf2_cu
*type_cu
;
23377 struct die_info
*type_die
;
23380 sig_type
= lookup_signatured_type (cu
, signature
);
23381 /* sig_type will be NULL if the signatured type is missing from
23383 if (sig_type
== NULL
)
23385 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23386 " from DIE at %s [in module %s]"),
23387 hex_string (signature
), sect_offset_str (die
->sect_off
),
23388 objfile_name (dwarf2_per_objfile
->objfile
));
23389 return build_error_marker_type (cu
, die
);
23392 /* If we already know the type we're done. */
23393 if (sig_type
->type
!= NULL
)
23394 return sig_type
->type
;
23397 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
23398 if (type_die
!= NULL
)
23400 /* N.B. We need to call get_die_type to ensure only one type for this DIE
23401 is created. This is important, for example, because for c++ classes
23402 we need TYPE_NAME set which is only done by new_symbol. Blech. */
23403 type
= read_type_die (type_die
, type_cu
);
23406 complaint (_("Dwarf Error: Cannot build signatured type %s"
23407 " referenced from DIE at %s [in module %s]"),
23408 hex_string (signature
), sect_offset_str (die
->sect_off
),
23409 objfile_name (dwarf2_per_objfile
->objfile
));
23410 type
= build_error_marker_type (cu
, die
);
23415 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23416 " from DIE at %s [in module %s]"),
23417 hex_string (signature
), sect_offset_str (die
->sect_off
),
23418 objfile_name (dwarf2_per_objfile
->objfile
));
23419 type
= build_error_marker_type (cu
, die
);
23421 sig_type
->type
= type
;
23426 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
23427 reading in and processing the type unit if necessary. */
23429 static struct type
*
23430 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
23431 struct dwarf2_cu
*cu
) /* ARI: editCase function */
23433 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
23434 if (attr
->form_is_ref ())
23436 struct dwarf2_cu
*type_cu
= cu
;
23437 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
23439 return read_type_die (type_die
, type_cu
);
23441 else if (attr
->form
== DW_FORM_ref_sig8
)
23443 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
23447 struct dwarf2_per_objfile
*dwarf2_per_objfile
23448 = cu
->per_cu
->dwarf2_per_objfile
;
23450 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
23451 " at %s [in module %s]"),
23452 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
23453 objfile_name (dwarf2_per_objfile
->objfile
));
23454 return build_error_marker_type (cu
, die
);
23458 /* Load the DIEs associated with type unit PER_CU into memory. */
23461 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
23463 struct signatured_type
*sig_type
;
23465 /* Caller is responsible for ensuring type_unit_groups don't get here. */
23466 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
23468 /* We have the per_cu, but we need the signatured_type.
23469 Fortunately this is an easy translation. */
23470 gdb_assert (per_cu
->is_debug_types
);
23471 sig_type
= (struct signatured_type
*) per_cu
;
23473 gdb_assert (per_cu
->cu
== NULL
);
23475 read_signatured_type (sig_type
);
23477 gdb_assert (per_cu
->cu
!= NULL
);
23480 /* Read in a signatured type and build its CU and DIEs.
23481 If the type is a stub for the real type in a DWO file,
23482 read in the real type from the DWO file as well. */
23485 read_signatured_type (struct signatured_type
*sig_type
)
23487 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
23489 gdb_assert (per_cu
->is_debug_types
);
23490 gdb_assert (per_cu
->cu
== NULL
);
23492 cutu_reader
reader (per_cu
, NULL
, 0, 1, false);
23494 if (!reader
.dummy_p
)
23496 struct dwarf2_cu
*cu
= reader
.cu
;
23497 const gdb_byte
*info_ptr
= reader
.info_ptr
;
23499 gdb_assert (cu
->die_hash
== NULL
);
23501 htab_create_alloc_ex (cu
->header
.length
/ 12,
23505 &cu
->comp_unit_obstack
,
23506 hashtab_obstack_allocate
,
23507 dummy_obstack_deallocate
);
23509 if (reader
.has_children
)
23510 reader
.comp_unit_die
->child
23511 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
23512 reader
.comp_unit_die
);
23513 cu
->dies
= reader
.comp_unit_die
;
23514 /* comp_unit_die is not stored in die_hash, no need. */
23516 /* We try not to read any attributes in this function, because
23517 not all CUs needed for references have been loaded yet, and
23518 symbol table processing isn't initialized. But we have to
23519 set the CU language, or we won't be able to build types
23520 correctly. Similarly, if we do not read the producer, we can
23521 not apply producer-specific interpretation. */
23522 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
23525 sig_type
->per_cu
.tu_read
= 1;
23528 /* Decode simple location descriptions.
23529 Given a pointer to a dwarf block that defines a location, compute
23530 the location and return the value.
23532 NOTE drow/2003-11-18: This function is called in two situations
23533 now: for the address of static or global variables (partial symbols
23534 only) and for offsets into structures which are expected to be
23535 (more or less) constant. The partial symbol case should go away,
23536 and only the constant case should remain. That will let this
23537 function complain more accurately. A few special modes are allowed
23538 without complaint for global variables (for instance, global
23539 register values and thread-local values).
23541 A location description containing no operations indicates that the
23542 object is optimized out. The return value is 0 for that case.
23543 FIXME drow/2003-11-16: No callers check for this case any more; soon all
23544 callers will only want a very basic result and this can become a
23547 Note that stack[0] is unused except as a default error return. */
23550 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
23552 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
23554 size_t size
= blk
->size
;
23555 const gdb_byte
*data
= blk
->data
;
23556 CORE_ADDR stack
[64];
23558 unsigned int bytes_read
, unsnd
;
23564 stack
[++stacki
] = 0;
23603 stack
[++stacki
] = op
- DW_OP_lit0
;
23638 stack
[++stacki
] = op
- DW_OP_reg0
;
23640 dwarf2_complex_location_expr_complaint ();
23644 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
23646 stack
[++stacki
] = unsnd
;
23648 dwarf2_complex_location_expr_complaint ();
23652 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
23657 case DW_OP_const1u
:
23658 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
23662 case DW_OP_const1s
:
23663 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
23667 case DW_OP_const2u
:
23668 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
23672 case DW_OP_const2s
:
23673 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
23677 case DW_OP_const4u
:
23678 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
23682 case DW_OP_const4s
:
23683 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
23687 case DW_OP_const8u
:
23688 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
23693 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
23699 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
23704 stack
[stacki
+ 1] = stack
[stacki
];
23709 stack
[stacki
- 1] += stack
[stacki
];
23713 case DW_OP_plus_uconst
:
23714 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
23720 stack
[stacki
- 1] -= stack
[stacki
];
23725 /* If we're not the last op, then we definitely can't encode
23726 this using GDB's address_class enum. This is valid for partial
23727 global symbols, although the variable's address will be bogus
23730 dwarf2_complex_location_expr_complaint ();
23733 case DW_OP_GNU_push_tls_address
:
23734 case DW_OP_form_tls_address
:
23735 /* The top of the stack has the offset from the beginning
23736 of the thread control block at which the variable is located. */
23737 /* Nothing should follow this operator, so the top of stack would
23739 /* This is valid for partial global symbols, but the variable's
23740 address will be bogus in the psymtab. Make it always at least
23741 non-zero to not look as a variable garbage collected by linker
23742 which have DW_OP_addr 0. */
23744 dwarf2_complex_location_expr_complaint ();
23748 case DW_OP_GNU_uninit
:
23752 case DW_OP_GNU_addr_index
:
23753 case DW_OP_GNU_const_index
:
23754 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
23761 const char *name
= get_DW_OP_name (op
);
23764 complaint (_("unsupported stack op: '%s'"),
23767 complaint (_("unsupported stack op: '%02x'"),
23771 return (stack
[stacki
]);
23774 /* Enforce maximum stack depth of SIZE-1 to avoid writing
23775 outside of the allocated space. Also enforce minimum>0. */
23776 if (stacki
>= ARRAY_SIZE (stack
) - 1)
23778 complaint (_("location description stack overflow"));
23784 complaint (_("location description stack underflow"));
23788 return (stack
[stacki
]);
23791 /* memory allocation interface */
23793 static struct dwarf_block
*
23794 dwarf_alloc_block (struct dwarf2_cu
*cu
)
23796 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
23799 static struct die_info
*
23800 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
23802 struct die_info
*die
;
23803 size_t size
= sizeof (struct die_info
);
23806 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
23808 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
23809 memset (die
, 0, sizeof (struct die_info
));
23814 /* Macro support. */
23816 /* Return file name relative to the compilation directory of file number I in
23817 *LH's file name table. The result is allocated using xmalloc; the caller is
23818 responsible for freeing it. */
23821 file_file_name (int file
, struct line_header
*lh
)
23823 /* Is the file number a valid index into the line header's file name
23824 table? Remember that file numbers start with one, not zero. */
23825 if (lh
->is_valid_file_index (file
))
23827 const file_entry
*fe
= lh
->file_name_at (file
);
23829 if (!IS_ABSOLUTE_PATH (fe
->name
))
23831 const char *dir
= fe
->include_dir (lh
);
23833 return concat (dir
, SLASH_STRING
, fe
->name
, (char *) NULL
);
23835 return xstrdup (fe
->name
);
23839 /* The compiler produced a bogus file number. We can at least
23840 record the macro definitions made in the file, even if we
23841 won't be able to find the file by name. */
23842 char fake_name
[80];
23844 xsnprintf (fake_name
, sizeof (fake_name
),
23845 "<bad macro file number %d>", file
);
23847 complaint (_("bad file number in macro information (%d)"),
23850 return xstrdup (fake_name
);
23854 /* Return the full name of file number I in *LH's file name table.
23855 Use COMP_DIR as the name of the current directory of the
23856 compilation. The result is allocated using xmalloc; the caller is
23857 responsible for freeing it. */
23859 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
23861 /* Is the file number a valid index into the line header's file name
23862 table? Remember that file numbers start with one, not zero. */
23863 if (lh
->is_valid_file_index (file
))
23865 char *relative
= file_file_name (file
, lh
);
23867 if (IS_ABSOLUTE_PATH (relative
) || comp_dir
== NULL
)
23869 return reconcat (relative
, comp_dir
, SLASH_STRING
,
23870 relative
, (char *) NULL
);
23873 return file_file_name (file
, lh
);
23877 static struct macro_source_file
*
23878 macro_start_file (struct dwarf2_cu
*cu
,
23879 int file
, int line
,
23880 struct macro_source_file
*current_file
,
23881 struct line_header
*lh
)
23883 /* File name relative to the compilation directory of this source file. */
23884 char *file_name
= file_file_name (file
, lh
);
23886 if (! current_file
)
23888 /* Note: We don't create a macro table for this compilation unit
23889 at all until we actually get a filename. */
23890 struct macro_table
*macro_table
= cu
->get_builder ()->get_macro_table ();
23892 /* If we have no current file, then this must be the start_file
23893 directive for the compilation unit's main source file. */
23894 current_file
= macro_set_main (macro_table
, file_name
);
23895 macro_define_special (macro_table
);
23898 current_file
= macro_include (current_file
, line
, file_name
);
23902 return current_file
;
23905 static const char *
23906 consume_improper_spaces (const char *p
, const char *body
)
23910 complaint (_("macro definition contains spaces "
23911 "in formal argument list:\n`%s'"),
23923 parse_macro_definition (struct macro_source_file
*file
, int line
,
23928 /* The body string takes one of two forms. For object-like macro
23929 definitions, it should be:
23931 <macro name> " " <definition>
23933 For function-like macro definitions, it should be:
23935 <macro name> "() " <definition>
23937 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
23939 Spaces may appear only where explicitly indicated, and in the
23942 The Dwarf 2 spec says that an object-like macro's name is always
23943 followed by a space, but versions of GCC around March 2002 omit
23944 the space when the macro's definition is the empty string.
23946 The Dwarf 2 spec says that there should be no spaces between the
23947 formal arguments in a function-like macro's formal argument list,
23948 but versions of GCC around March 2002 include spaces after the
23952 /* Find the extent of the macro name. The macro name is terminated
23953 by either a space or null character (for an object-like macro) or
23954 an opening paren (for a function-like macro). */
23955 for (p
= body
; *p
; p
++)
23956 if (*p
== ' ' || *p
== '(')
23959 if (*p
== ' ' || *p
== '\0')
23961 /* It's an object-like macro. */
23962 int name_len
= p
- body
;
23963 std::string
name (body
, name_len
);
23964 const char *replacement
;
23967 replacement
= body
+ name_len
+ 1;
23970 dwarf2_macro_malformed_definition_complaint (body
);
23971 replacement
= body
+ name_len
;
23974 macro_define_object (file
, line
, name
.c_str (), replacement
);
23976 else if (*p
== '(')
23978 /* It's a function-like macro. */
23979 std::string
name (body
, p
- body
);
23982 char **argv
= XNEWVEC (char *, argv_size
);
23986 p
= consume_improper_spaces (p
, body
);
23988 /* Parse the formal argument list. */
23989 while (*p
&& *p
!= ')')
23991 /* Find the extent of the current argument name. */
23992 const char *arg_start
= p
;
23994 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
23997 if (! *p
|| p
== arg_start
)
23998 dwarf2_macro_malformed_definition_complaint (body
);
24001 /* Make sure argv has room for the new argument. */
24002 if (argc
>= argv_size
)
24005 argv
= XRESIZEVEC (char *, argv
, argv_size
);
24008 argv
[argc
++] = savestring (arg_start
, p
- arg_start
);
24011 p
= consume_improper_spaces (p
, body
);
24013 /* Consume the comma, if present. */
24018 p
= consume_improper_spaces (p
, body
);
24027 /* Perfectly formed definition, no complaints. */
24028 macro_define_function (file
, line
, name
.c_str (),
24029 argc
, (const char **) argv
,
24031 else if (*p
== '\0')
24033 /* Complain, but do define it. */
24034 dwarf2_macro_malformed_definition_complaint (body
);
24035 macro_define_function (file
, line
, name
.c_str (),
24036 argc
, (const char **) argv
,
24040 /* Just complain. */
24041 dwarf2_macro_malformed_definition_complaint (body
);
24044 /* Just complain. */
24045 dwarf2_macro_malformed_definition_complaint (body
);
24050 for (i
= 0; i
< argc
; i
++)
24056 dwarf2_macro_malformed_definition_complaint (body
);
24059 /* Skip some bytes from BYTES according to the form given in FORM.
24060 Returns the new pointer. */
24062 static const gdb_byte
*
24063 skip_form_bytes (bfd
*abfd
, const gdb_byte
*bytes
, const gdb_byte
*buffer_end
,
24064 enum dwarf_form form
,
24065 unsigned int offset_size
,
24066 struct dwarf2_section_info
*section
)
24068 unsigned int bytes_read
;
24072 case DW_FORM_data1
:
24077 case DW_FORM_data2
:
24081 case DW_FORM_data4
:
24085 case DW_FORM_data8
:
24089 case DW_FORM_data16
:
24093 case DW_FORM_string
:
24094 read_direct_string (abfd
, bytes
, &bytes_read
);
24095 bytes
+= bytes_read
;
24098 case DW_FORM_sec_offset
:
24100 case DW_FORM_GNU_strp_alt
:
24101 bytes
+= offset_size
;
24104 case DW_FORM_block
:
24105 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
24106 bytes
+= bytes_read
;
24109 case DW_FORM_block1
:
24110 bytes
+= 1 + read_1_byte (abfd
, bytes
);
24112 case DW_FORM_block2
:
24113 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
24115 case DW_FORM_block4
:
24116 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
24119 case DW_FORM_addrx
:
24120 case DW_FORM_sdata
:
24122 case DW_FORM_udata
:
24123 case DW_FORM_GNU_addr_index
:
24124 case DW_FORM_GNU_str_index
:
24125 bytes
= gdb_skip_leb128 (bytes
, buffer_end
);
24128 dwarf2_section_buffer_overflow_complaint (section
);
24133 case DW_FORM_implicit_const
:
24138 complaint (_("invalid form 0x%x in `%s'"),
24139 form
, section
->get_name ());
24147 /* A helper for dwarf_decode_macros that handles skipping an unknown
24148 opcode. Returns an updated pointer to the macro data buffer; or,
24149 on error, issues a complaint and returns NULL. */
24151 static const gdb_byte
*
24152 skip_unknown_opcode (unsigned int opcode
,
24153 const gdb_byte
**opcode_definitions
,
24154 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24156 unsigned int offset_size
,
24157 struct dwarf2_section_info
*section
)
24159 unsigned int bytes_read
, i
;
24161 const gdb_byte
*defn
;
24163 if (opcode_definitions
[opcode
] == NULL
)
24165 complaint (_("unrecognized DW_MACFINO opcode 0x%x"),
24170 defn
= opcode_definitions
[opcode
];
24171 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
24172 defn
+= bytes_read
;
24174 for (i
= 0; i
< arg
; ++i
)
24176 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
,
24177 (enum dwarf_form
) defn
[i
], offset_size
,
24179 if (mac_ptr
== NULL
)
24181 /* skip_form_bytes already issued the complaint. */
24189 /* A helper function which parses the header of a macro section.
24190 If the macro section is the extended (for now called "GNU") type,
24191 then this updates *OFFSET_SIZE. Returns a pointer to just after
24192 the header, or issues a complaint and returns NULL on error. */
24194 static const gdb_byte
*
24195 dwarf_parse_macro_header (const gdb_byte
**opcode_definitions
,
24197 const gdb_byte
*mac_ptr
,
24198 unsigned int *offset_size
,
24199 int section_is_gnu
)
24201 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
24203 if (section_is_gnu
)
24205 unsigned int version
, flags
;
24207 version
= read_2_bytes (abfd
, mac_ptr
);
24208 if (version
!= 4 && version
!= 5)
24210 complaint (_("unrecognized version `%d' in .debug_macro section"),
24216 flags
= read_1_byte (abfd
, mac_ptr
);
24218 *offset_size
= (flags
& 1) ? 8 : 4;
24220 if ((flags
& 2) != 0)
24221 /* We don't need the line table offset. */
24222 mac_ptr
+= *offset_size
;
24224 /* Vendor opcode descriptions. */
24225 if ((flags
& 4) != 0)
24227 unsigned int i
, count
;
24229 count
= read_1_byte (abfd
, mac_ptr
);
24231 for (i
= 0; i
< count
; ++i
)
24233 unsigned int opcode
, bytes_read
;
24236 opcode
= read_1_byte (abfd
, mac_ptr
);
24238 opcode_definitions
[opcode
] = mac_ptr
;
24239 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24240 mac_ptr
+= bytes_read
;
24249 /* A helper for dwarf_decode_macros that handles the GNU extensions,
24250 including DW_MACRO_import. */
24253 dwarf_decode_macro_bytes (struct dwarf2_cu
*cu
,
24255 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24256 struct macro_source_file
*current_file
,
24257 struct line_header
*lh
,
24258 struct dwarf2_section_info
*section
,
24259 int section_is_gnu
, int section_is_dwz
,
24260 unsigned int offset_size
,
24261 htab_t include_hash
)
24263 struct dwarf2_per_objfile
*dwarf2_per_objfile
24264 = cu
->per_cu
->dwarf2_per_objfile
;
24265 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24266 enum dwarf_macro_record_type macinfo_type
;
24267 int at_commandline
;
24268 const gdb_byte
*opcode_definitions
[256];
24270 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
24271 &offset_size
, section_is_gnu
);
24272 if (mac_ptr
== NULL
)
24274 /* We already issued a complaint. */
24278 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
24279 GDB is still reading the definitions from command line. First
24280 DW_MACINFO_start_file will need to be ignored as it was already executed
24281 to create CURRENT_FILE for the main source holding also the command line
24282 definitions. On first met DW_MACINFO_start_file this flag is reset to
24283 normally execute all the remaining DW_MACINFO_start_file macinfos. */
24285 at_commandline
= 1;
24289 /* Do we at least have room for a macinfo type byte? */
24290 if (mac_ptr
>= mac_end
)
24292 dwarf2_section_buffer_overflow_complaint (section
);
24296 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
24299 /* Note that we rely on the fact that the corresponding GNU and
24300 DWARF constants are the same. */
24302 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
24303 switch (macinfo_type
)
24305 /* A zero macinfo type indicates the end of the macro
24310 case DW_MACRO_define
:
24311 case DW_MACRO_undef
:
24312 case DW_MACRO_define_strp
:
24313 case DW_MACRO_undef_strp
:
24314 case DW_MACRO_define_sup
:
24315 case DW_MACRO_undef_sup
:
24317 unsigned int bytes_read
;
24322 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24323 mac_ptr
+= bytes_read
;
24325 if (macinfo_type
== DW_MACRO_define
24326 || macinfo_type
== DW_MACRO_undef
)
24328 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24329 mac_ptr
+= bytes_read
;
24333 LONGEST str_offset
;
24335 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
24336 mac_ptr
+= offset_size
;
24338 if (macinfo_type
== DW_MACRO_define_sup
24339 || macinfo_type
== DW_MACRO_undef_sup
24342 struct dwz_file
*dwz
24343 = dwarf2_get_dwz_file (dwarf2_per_objfile
);
24345 body
= read_indirect_string_from_dwz (objfile
,
24349 body
= read_indirect_string_at_offset (dwarf2_per_objfile
,
24353 is_define
= (macinfo_type
== DW_MACRO_define
24354 || macinfo_type
== DW_MACRO_define_strp
24355 || macinfo_type
== DW_MACRO_define_sup
);
24356 if (! current_file
)
24358 /* DWARF violation as no main source is present. */
24359 complaint (_("debug info with no main source gives macro %s "
24361 is_define
? _("definition") : _("undefinition"),
24365 if ((line
== 0 && !at_commandline
)
24366 || (line
!= 0 && at_commandline
))
24367 complaint (_("debug info gives %s macro %s with %s line %d: %s"),
24368 at_commandline
? _("command-line") : _("in-file"),
24369 is_define
? _("definition") : _("undefinition"),
24370 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
24374 /* Fedora's rpm-build's "debugedit" binary
24375 corrupted .debug_macro sections.
24378 https://bugzilla.redhat.com/show_bug.cgi?id=1708786 */
24379 complaint (_("debug info gives %s invalid macro %s "
24380 "without body (corrupted?) at line %d "
24382 at_commandline
? _("command-line") : _("in-file"),
24383 is_define
? _("definition") : _("undefinition"),
24384 line
, current_file
->filename
);
24386 else if (is_define
)
24387 parse_macro_definition (current_file
, line
, body
);
24390 gdb_assert (macinfo_type
== DW_MACRO_undef
24391 || macinfo_type
== DW_MACRO_undef_strp
24392 || macinfo_type
== DW_MACRO_undef_sup
);
24393 macro_undef (current_file
, line
, body
);
24398 case DW_MACRO_start_file
:
24400 unsigned int bytes_read
;
24403 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24404 mac_ptr
+= bytes_read
;
24405 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24406 mac_ptr
+= bytes_read
;
24408 if ((line
== 0 && !at_commandline
)
24409 || (line
!= 0 && at_commandline
))
24410 complaint (_("debug info gives source %d included "
24411 "from %s at %s line %d"),
24412 file
, at_commandline
? _("command-line") : _("file"),
24413 line
== 0 ? _("zero") : _("non-zero"), line
);
24415 if (at_commandline
)
24417 /* This DW_MACRO_start_file was executed in the
24419 at_commandline
= 0;
24422 current_file
= macro_start_file (cu
, file
, line
, current_file
,
24427 case DW_MACRO_end_file
:
24428 if (! current_file
)
24429 complaint (_("macro debug info has an unmatched "
24430 "`close_file' directive"));
24433 current_file
= current_file
->included_by
;
24434 if (! current_file
)
24436 enum dwarf_macro_record_type next_type
;
24438 /* GCC circa March 2002 doesn't produce the zero
24439 type byte marking the end of the compilation
24440 unit. Complain if it's not there, but exit no
24443 /* Do we at least have room for a macinfo type byte? */
24444 if (mac_ptr
>= mac_end
)
24446 dwarf2_section_buffer_overflow_complaint (section
);
24450 /* We don't increment mac_ptr here, so this is just
24453 = (enum dwarf_macro_record_type
) read_1_byte (abfd
,
24455 if (next_type
!= 0)
24456 complaint (_("no terminating 0-type entry for "
24457 "macros in `.debug_macinfo' section"));
24464 case DW_MACRO_import
:
24465 case DW_MACRO_import_sup
:
24469 bfd
*include_bfd
= abfd
;
24470 struct dwarf2_section_info
*include_section
= section
;
24471 const gdb_byte
*include_mac_end
= mac_end
;
24472 int is_dwz
= section_is_dwz
;
24473 const gdb_byte
*new_mac_ptr
;
24475 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
24476 mac_ptr
+= offset_size
;
24478 if (macinfo_type
== DW_MACRO_import_sup
)
24480 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
24482 dwz
->macro
.read (objfile
);
24484 include_section
= &dwz
->macro
;
24485 include_bfd
= include_section
->get_bfd_owner ();
24486 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
24490 new_mac_ptr
= include_section
->buffer
+ offset
;
24491 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
24495 /* This has actually happened; see
24496 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
24497 complaint (_("recursive DW_MACRO_import in "
24498 ".debug_macro section"));
24502 *slot
= (void *) new_mac_ptr
;
24504 dwarf_decode_macro_bytes (cu
, include_bfd
, new_mac_ptr
,
24505 include_mac_end
, current_file
, lh
,
24506 section
, section_is_gnu
, is_dwz
,
24507 offset_size
, include_hash
);
24509 htab_remove_elt (include_hash
, (void *) new_mac_ptr
);
24514 case DW_MACINFO_vendor_ext
:
24515 if (!section_is_gnu
)
24517 unsigned int bytes_read
;
24519 /* This reads the constant, but since we don't recognize
24520 any vendor extensions, we ignore it. */
24521 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24522 mac_ptr
+= bytes_read
;
24523 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24524 mac_ptr
+= bytes_read
;
24526 /* We don't recognize any vendor extensions. */
24532 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
24533 mac_ptr
, mac_end
, abfd
, offset_size
,
24535 if (mac_ptr
== NULL
)
24540 } while (macinfo_type
!= 0);
24544 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
24545 int section_is_gnu
)
24547 struct dwarf2_per_objfile
*dwarf2_per_objfile
24548 = cu
->per_cu
->dwarf2_per_objfile
;
24549 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24550 struct line_header
*lh
= cu
->line_header
;
24552 const gdb_byte
*mac_ptr
, *mac_end
;
24553 struct macro_source_file
*current_file
= 0;
24554 enum dwarf_macro_record_type macinfo_type
;
24555 unsigned int offset_size
= cu
->header
.offset_size
;
24556 const gdb_byte
*opcode_definitions
[256];
24558 struct dwarf2_section_info
*section
;
24559 const char *section_name
;
24561 if (cu
->dwo_unit
!= NULL
)
24563 if (section_is_gnu
)
24565 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
24566 section_name
= ".debug_macro.dwo";
24570 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
24571 section_name
= ".debug_macinfo.dwo";
24576 if (section_is_gnu
)
24578 section
= &dwarf2_per_objfile
->macro
;
24579 section_name
= ".debug_macro";
24583 section
= &dwarf2_per_objfile
->macinfo
;
24584 section_name
= ".debug_macinfo";
24588 section
->read (objfile
);
24589 if (section
->buffer
== NULL
)
24591 complaint (_("missing %s section"), section_name
);
24594 abfd
= section
->get_bfd_owner ();
24596 /* First pass: Find the name of the base filename.
24597 This filename is needed in order to process all macros whose definition
24598 (or undefinition) comes from the command line. These macros are defined
24599 before the first DW_MACINFO_start_file entry, and yet still need to be
24600 associated to the base file.
24602 To determine the base file name, we scan the macro definitions until we
24603 reach the first DW_MACINFO_start_file entry. We then initialize
24604 CURRENT_FILE accordingly so that any macro definition found before the
24605 first DW_MACINFO_start_file can still be associated to the base file. */
24607 mac_ptr
= section
->buffer
+ offset
;
24608 mac_end
= section
->buffer
+ section
->size
;
24610 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
24611 &offset_size
, section_is_gnu
);
24612 if (mac_ptr
== NULL
)
24614 /* We already issued a complaint. */
24620 /* Do we at least have room for a macinfo type byte? */
24621 if (mac_ptr
>= mac_end
)
24623 /* Complaint is printed during the second pass as GDB will probably
24624 stop the first pass earlier upon finding
24625 DW_MACINFO_start_file. */
24629 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
24632 /* Note that we rely on the fact that the corresponding GNU and
24633 DWARF constants are the same. */
24635 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
24636 switch (macinfo_type
)
24638 /* A zero macinfo type indicates the end of the macro
24643 case DW_MACRO_define
:
24644 case DW_MACRO_undef
:
24645 /* Only skip the data by MAC_PTR. */
24647 unsigned int bytes_read
;
24649 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24650 mac_ptr
+= bytes_read
;
24651 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24652 mac_ptr
+= bytes_read
;
24656 case DW_MACRO_start_file
:
24658 unsigned int bytes_read
;
24661 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24662 mac_ptr
+= bytes_read
;
24663 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24664 mac_ptr
+= bytes_read
;
24666 current_file
= macro_start_file (cu
, file
, line
, current_file
, lh
);
24670 case DW_MACRO_end_file
:
24671 /* No data to skip by MAC_PTR. */
24674 case DW_MACRO_define_strp
:
24675 case DW_MACRO_undef_strp
:
24676 case DW_MACRO_define_sup
:
24677 case DW_MACRO_undef_sup
:
24679 unsigned int bytes_read
;
24681 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24682 mac_ptr
+= bytes_read
;
24683 mac_ptr
+= offset_size
;
24687 case DW_MACRO_import
:
24688 case DW_MACRO_import_sup
:
24689 /* Note that, according to the spec, a transparent include
24690 chain cannot call DW_MACRO_start_file. So, we can just
24691 skip this opcode. */
24692 mac_ptr
+= offset_size
;
24695 case DW_MACINFO_vendor_ext
:
24696 /* Only skip the data by MAC_PTR. */
24697 if (!section_is_gnu
)
24699 unsigned int bytes_read
;
24701 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24702 mac_ptr
+= bytes_read
;
24703 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24704 mac_ptr
+= bytes_read
;
24709 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
24710 mac_ptr
, mac_end
, abfd
, offset_size
,
24712 if (mac_ptr
== NULL
)
24717 } while (macinfo_type
!= 0 && current_file
== NULL
);
24719 /* Second pass: Process all entries.
24721 Use the AT_COMMAND_LINE flag to determine whether we are still processing
24722 command-line macro definitions/undefinitions. This flag is unset when we
24723 reach the first DW_MACINFO_start_file entry. */
24725 htab_up
include_hash (htab_create_alloc (1, htab_hash_pointer
,
24727 NULL
, xcalloc
, xfree
));
24728 mac_ptr
= section
->buffer
+ offset
;
24729 slot
= htab_find_slot (include_hash
.get (), mac_ptr
, INSERT
);
24730 *slot
= (void *) mac_ptr
;
24731 dwarf_decode_macro_bytes (cu
, abfd
, mac_ptr
, mac_end
,
24732 current_file
, lh
, section
,
24733 section_is_gnu
, 0, offset_size
,
24734 include_hash
.get ());
24737 /* Return the .debug_loc section to use for CU.
24738 For DWO files use .debug_loc.dwo. */
24740 static struct dwarf2_section_info
*
24741 cu_debug_loc_section (struct dwarf2_cu
*cu
)
24743 struct dwarf2_per_objfile
*dwarf2_per_objfile
24744 = cu
->per_cu
->dwarf2_per_objfile
;
24748 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24750 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
24752 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
24753 : &dwarf2_per_objfile
->loc
);
24756 /* A helper function that fills in a dwarf2_loclist_baton. */
24759 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
24760 struct dwarf2_loclist_baton
*baton
,
24761 const struct attribute
*attr
)
24763 struct dwarf2_per_objfile
*dwarf2_per_objfile
24764 = cu
->per_cu
->dwarf2_per_objfile
;
24765 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24767 section
->read (dwarf2_per_objfile
->objfile
);
24769 baton
->per_cu
= cu
->per_cu
;
24770 gdb_assert (baton
->per_cu
);
24771 /* We don't know how long the location list is, but make sure we
24772 don't run off the edge of the section. */
24773 baton
->size
= section
->size
- DW_UNSND (attr
);
24774 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
24775 baton
->base_address
= cu
->base_address
;
24776 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
24780 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
24781 struct dwarf2_cu
*cu
, int is_block
)
24783 struct dwarf2_per_objfile
*dwarf2_per_objfile
24784 = cu
->per_cu
->dwarf2_per_objfile
;
24785 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24786 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24788 if (attr
->form_is_section_offset ()
24789 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
24790 the section. If so, fall through to the complaint in the
24792 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
24794 struct dwarf2_loclist_baton
*baton
;
24796 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
24798 fill_in_loclist_baton (cu
, baton
, attr
);
24800 if (cu
->base_known
== 0)
24801 complaint (_("Location list used without "
24802 "specifying the CU base address."));
24804 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24805 ? dwarf2_loclist_block_index
24806 : dwarf2_loclist_index
);
24807 SYMBOL_LOCATION_BATON (sym
) = baton
;
24811 struct dwarf2_locexpr_baton
*baton
;
24813 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
24814 baton
->per_cu
= cu
->per_cu
;
24815 gdb_assert (baton
->per_cu
);
24817 if (attr
->form_is_block ())
24819 /* Note that we're just copying the block's data pointer
24820 here, not the actual data. We're still pointing into the
24821 info_buffer for SYM's objfile; right now we never release
24822 that buffer, but when we do clean up properly this may
24824 baton
->size
= DW_BLOCK (attr
)->size
;
24825 baton
->data
= DW_BLOCK (attr
)->data
;
24829 dwarf2_invalid_attrib_class_complaint ("location description",
24830 sym
->natural_name ());
24834 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24835 ? dwarf2_locexpr_block_index
24836 : dwarf2_locexpr_index
);
24837 SYMBOL_LOCATION_BATON (sym
) = baton
;
24841 /* Return the OBJFILE associated with the compilation unit CU. If CU
24842 came from a separate debuginfo file, then the master objfile is
24846 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
24848 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
24850 /* Return the master objfile, so that we can report and look up the
24851 correct file containing this variable. */
24852 if (objfile
->separate_debug_objfile_backlink
)
24853 objfile
= objfile
->separate_debug_objfile_backlink
;
24858 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
24859 (CU_HEADERP is unused in such case) or prepare a temporary copy at
24860 CU_HEADERP first. */
24862 static const struct comp_unit_head
*
24863 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
24864 struct dwarf2_per_cu_data
*per_cu
)
24866 const gdb_byte
*info_ptr
;
24869 return &per_cu
->cu
->header
;
24871 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
24873 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
24874 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
24875 rcuh_kind::COMPILE
);
24880 /* Return the address size given in the compilation unit header for CU. */
24883 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
24885 struct comp_unit_head cu_header_local
;
24886 const struct comp_unit_head
*cu_headerp
;
24888 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
24890 return cu_headerp
->addr_size
;
24893 /* Return the offset size given in the compilation unit header for CU. */
24896 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
24898 struct comp_unit_head cu_header_local
;
24899 const struct comp_unit_head
*cu_headerp
;
24901 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
24903 return cu_headerp
->offset_size
;
24906 /* See its dwarf2loc.h declaration. */
24909 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
24911 struct comp_unit_head cu_header_local
;
24912 const struct comp_unit_head
*cu_headerp
;
24914 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
24916 if (cu_headerp
->version
== 2)
24917 return cu_headerp
->addr_size
;
24919 return cu_headerp
->offset_size
;
24922 /* Return the text offset of the CU. The returned offset comes from
24923 this CU's objfile. If this objfile came from a separate debuginfo
24924 file, then the offset may be different from the corresponding
24925 offset in the parent objfile. */
24928 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
24930 return per_cu
->dwarf2_per_objfile
->objfile
->text_section_offset ();
24933 /* Return a type that is a generic pointer type, the size of which matches
24934 the address size given in the compilation unit header for PER_CU. */
24935 static struct type
*
24936 dwarf2_per_cu_addr_type (struct dwarf2_per_cu_data
*per_cu
)
24938 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
24939 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
24940 struct type
*addr_type
= lookup_pointer_type (void_type
);
24941 int addr_size
= dwarf2_per_cu_addr_size (per_cu
);
24943 if (TYPE_LENGTH (addr_type
) == addr_size
)
24947 = dwarf2_per_cu_addr_sized_int_type (per_cu
, TYPE_UNSIGNED (addr_type
));
24951 /* Return DWARF version number of PER_CU. */
24954 dwarf2_version (struct dwarf2_per_cu_data
*per_cu
)
24956 return per_cu
->dwarf_version
;
24959 /* Locate the .debug_info compilation unit from CU's objfile which contains
24960 the DIE at OFFSET. Raises an error on failure. */
24962 static struct dwarf2_per_cu_data
*
24963 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
24964 unsigned int offset_in_dwz
,
24965 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
24967 struct dwarf2_per_cu_data
*this_cu
;
24971 high
= dwarf2_per_objfile
->all_comp_units
.size () - 1;
24974 struct dwarf2_per_cu_data
*mid_cu
;
24975 int mid
= low
+ (high
- low
) / 2;
24977 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
24978 if (mid_cu
->is_dwz
> offset_in_dwz
24979 || (mid_cu
->is_dwz
== offset_in_dwz
24980 && mid_cu
->sect_off
+ mid_cu
->length
>= sect_off
))
24985 gdb_assert (low
== high
);
24986 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
24987 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
24989 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
24990 error (_("Dwarf Error: could not find partial DIE containing "
24991 "offset %s [in module %s]"),
24992 sect_offset_str (sect_off
),
24993 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
24995 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
24997 return dwarf2_per_objfile
->all_comp_units
[low
-1];
25001 if (low
== dwarf2_per_objfile
->all_comp_units
.size () - 1
25002 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
25003 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
25004 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
25009 /* Initialize dwarf2_cu CU, owned by PER_CU. */
25011 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data
*per_cu_
)
25012 : per_cu (per_cu_
),
25014 has_loclist (false),
25015 checked_producer (false),
25016 producer_is_gxx_lt_4_6 (false),
25017 producer_is_gcc_lt_4_3 (false),
25018 producer_is_icc (false),
25019 producer_is_icc_lt_14 (false),
25020 producer_is_codewarrior (false),
25021 processing_has_namespace_info (false)
25026 /* Destroy a dwarf2_cu. */
25028 dwarf2_cu::~dwarf2_cu ()
25033 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
25036 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
25037 enum language pretend_language
)
25039 struct attribute
*attr
;
25041 /* Set the language we're debugging. */
25042 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
25043 if (attr
!= nullptr)
25044 set_cu_language (DW_UNSND (attr
), cu
);
25047 cu
->language
= pretend_language
;
25048 cu
->language_defn
= language_def (cu
->language
);
25051 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
25054 /* Increase the age counter on each cached compilation unit, and free
25055 any that are too old. */
25058 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
25060 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25062 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
25063 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25064 while (per_cu
!= NULL
)
25066 per_cu
->cu
->last_used
++;
25067 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
25068 dwarf2_mark (per_cu
->cu
);
25069 per_cu
= per_cu
->cu
->read_in_chain
;
25072 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25073 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25074 while (per_cu
!= NULL
)
25076 struct dwarf2_per_cu_data
*next_cu
;
25078 next_cu
= per_cu
->cu
->read_in_chain
;
25080 if (!per_cu
->cu
->mark
)
25083 *last_chain
= next_cu
;
25086 last_chain
= &per_cu
->cu
->read_in_chain
;
25092 /* Remove a single compilation unit from the cache. */
25095 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
25097 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25098 struct dwarf2_per_objfile
*dwarf2_per_objfile
25099 = target_per_cu
->dwarf2_per_objfile
;
25101 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25102 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25103 while (per_cu
!= NULL
)
25105 struct dwarf2_per_cu_data
*next_cu
;
25107 next_cu
= per_cu
->cu
->read_in_chain
;
25109 if (per_cu
== target_per_cu
)
25113 *last_chain
= next_cu
;
25117 last_chain
= &per_cu
->cu
->read_in_chain
;
25123 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
25124 We store these in a hash table separate from the DIEs, and preserve them
25125 when the DIEs are flushed out of cache.
25127 The CU "per_cu" pointer is needed because offset alone is not enough to
25128 uniquely identify the type. A file may have multiple .debug_types sections,
25129 or the type may come from a DWO file. Furthermore, while it's more logical
25130 to use per_cu->section+offset, with Fission the section with the data is in
25131 the DWO file but we don't know that section at the point we need it.
25132 We have to use something in dwarf2_per_cu_data (or the pointer to it)
25133 because we can enter the lookup routine, get_die_type_at_offset, from
25134 outside this file, and thus won't necessarily have PER_CU->cu.
25135 Fortunately, PER_CU is stable for the life of the objfile. */
25137 struct dwarf2_per_cu_offset_and_type
25139 const struct dwarf2_per_cu_data
*per_cu
;
25140 sect_offset sect_off
;
25144 /* Hash function for a dwarf2_per_cu_offset_and_type. */
25147 per_cu_offset_and_type_hash (const void *item
)
25149 const struct dwarf2_per_cu_offset_and_type
*ofs
25150 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
25152 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
25155 /* Equality function for a dwarf2_per_cu_offset_and_type. */
25158 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
25160 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
25161 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
25162 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
25163 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
25165 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
25166 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
25169 /* Set the type associated with DIE to TYPE. Save it in CU's hash
25170 table if necessary. For convenience, return TYPE.
25172 The DIEs reading must have careful ordering to:
25173 * Not cause infinite loops trying to read in DIEs as a prerequisite for
25174 reading current DIE.
25175 * Not trying to dereference contents of still incompletely read in types
25176 while reading in other DIEs.
25177 * Enable referencing still incompletely read in types just by a pointer to
25178 the type without accessing its fields.
25180 Therefore caller should follow these rules:
25181 * Try to fetch any prerequisite types we may need to build this DIE type
25182 before building the type and calling set_die_type.
25183 * After building type call set_die_type for current DIE as soon as
25184 possible before fetching more types to complete the current type.
25185 * Make the type as complete as possible before fetching more types. */
25187 static struct type
*
25188 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
25190 struct dwarf2_per_objfile
*dwarf2_per_objfile
25191 = cu
->per_cu
->dwarf2_per_objfile
;
25192 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
25193 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25194 struct attribute
*attr
;
25195 struct dynamic_prop prop
;
25197 /* For Ada types, make sure that the gnat-specific data is always
25198 initialized (if not already set). There are a few types where
25199 we should not be doing so, because the type-specific area is
25200 already used to hold some other piece of info (eg: TYPE_CODE_FLT
25201 where the type-specific area is used to store the floatformat).
25202 But this is not a problem, because the gnat-specific information
25203 is actually not needed for these types. */
25204 if (need_gnat_info (cu
)
25205 && TYPE_CODE (type
) != TYPE_CODE_FUNC
25206 && TYPE_CODE (type
) != TYPE_CODE_FLT
25207 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
25208 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
25209 && TYPE_CODE (type
) != TYPE_CODE_METHOD
25210 && !HAVE_GNAT_AUX_INFO (type
))
25211 INIT_GNAT_SPECIFIC (type
);
25213 /* Read DW_AT_allocated and set in type. */
25214 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
25215 if (attr
!= NULL
&& attr
->form_is_block ())
25217 struct type
*prop_type
25218 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
25219 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
25220 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
);
25222 else if (attr
!= NULL
)
25224 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
25225 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25226 sect_offset_str (die
->sect_off
));
25229 /* Read DW_AT_associated and set in type. */
25230 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
25231 if (attr
!= NULL
&& attr
->form_is_block ())
25233 struct type
*prop_type
25234 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
25235 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
25236 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
);
25238 else if (attr
!= NULL
)
25240 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
25241 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25242 sect_offset_str (die
->sect_off
));
25245 /* Read DW_AT_data_location and set in type. */
25246 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
25247 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
,
25248 dwarf2_per_cu_addr_type (cu
->per_cu
)))
25249 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
);
25251 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25253 dwarf2_per_objfile
->die_type_hash
=
25254 htab_create_alloc_ex (127,
25255 per_cu_offset_and_type_hash
,
25256 per_cu_offset_and_type_eq
,
25258 &objfile
->objfile_obstack
,
25259 hashtab_obstack_allocate
,
25260 dummy_obstack_deallocate
);
25263 ofs
.per_cu
= cu
->per_cu
;
25264 ofs
.sect_off
= die
->sect_off
;
25266 slot
= (struct dwarf2_per_cu_offset_and_type
**)
25267 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
25269 complaint (_("A problem internal to GDB: DIE %s has type already set"),
25270 sect_offset_str (die
->sect_off
));
25271 *slot
= XOBNEW (&objfile
->objfile_obstack
,
25272 struct dwarf2_per_cu_offset_and_type
);
25277 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
25278 or return NULL if the die does not have a saved type. */
25280 static struct type
*
25281 get_die_type_at_offset (sect_offset sect_off
,
25282 struct dwarf2_per_cu_data
*per_cu
)
25284 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
25285 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
25287 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25290 ofs
.per_cu
= per_cu
;
25291 ofs
.sect_off
= sect_off
;
25292 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
25293 htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
));
25300 /* Look up the type for DIE in CU in die_type_hash,
25301 or return NULL if DIE does not have a saved type. */
25303 static struct type
*
25304 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
25306 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
25309 /* Add a dependence relationship from CU to REF_PER_CU. */
25312 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
25313 struct dwarf2_per_cu_data
*ref_per_cu
)
25317 if (cu
->dependencies
== NULL
)
25319 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
25320 NULL
, &cu
->comp_unit_obstack
,
25321 hashtab_obstack_allocate
,
25322 dummy_obstack_deallocate
);
25324 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
25326 *slot
= ref_per_cu
;
25329 /* Subroutine of dwarf2_mark to pass to htab_traverse.
25330 Set the mark field in every compilation unit in the
25331 cache that we must keep because we are keeping CU. */
25334 dwarf2_mark_helper (void **slot
, void *data
)
25336 struct dwarf2_per_cu_data
*per_cu
;
25338 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
25340 /* cu->dependencies references may not yet have been ever read if QUIT aborts
25341 reading of the chain. As such dependencies remain valid it is not much
25342 useful to track and undo them during QUIT cleanups. */
25343 if (per_cu
->cu
== NULL
)
25346 if (per_cu
->cu
->mark
)
25348 per_cu
->cu
->mark
= true;
25350 if (per_cu
->cu
->dependencies
!= NULL
)
25351 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
25356 /* Set the mark field in CU and in every other compilation unit in the
25357 cache that we must keep because we are keeping CU. */
25360 dwarf2_mark (struct dwarf2_cu
*cu
)
25365 if (cu
->dependencies
!= NULL
)
25366 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
25370 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
25374 per_cu
->cu
->mark
= false;
25375 per_cu
= per_cu
->cu
->read_in_chain
;
25379 /* Trivial hash function for partial_die_info: the hash value of a DIE
25380 is its offset in .debug_info for this objfile. */
25383 partial_die_hash (const void *item
)
25385 const struct partial_die_info
*part_die
25386 = (const struct partial_die_info
*) item
;
25388 return to_underlying (part_die
->sect_off
);
25391 /* Trivial comparison function for partial_die_info structures: two DIEs
25392 are equal if they have the same offset. */
25395 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
25397 const struct partial_die_info
*part_die_lhs
25398 = (const struct partial_die_info
*) item_lhs
;
25399 const struct partial_die_info
*part_die_rhs
25400 = (const struct partial_die_info
*) item_rhs
;
25402 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
25405 struct cmd_list_element
*set_dwarf_cmdlist
;
25406 struct cmd_list_element
*show_dwarf_cmdlist
;
25409 set_dwarf_cmd (const char *args
, int from_tty
)
25411 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
25416 show_dwarf_cmd (const char *args
, int from_tty
)
25418 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
25421 bool dwarf_always_disassemble
;
25424 show_dwarf_always_disassemble (struct ui_file
*file
, int from_tty
,
25425 struct cmd_list_element
*c
, const char *value
)
25427 fprintf_filtered (file
,
25428 _("Whether to always disassemble "
25429 "DWARF expressions is %s.\n"),
25434 show_check_physname (struct ui_file
*file
, int from_tty
,
25435 struct cmd_list_element
*c
, const char *value
)
25437 fprintf_filtered (file
,
25438 _("Whether to check \"physname\" is %s.\n"),
25442 void _initialize_dwarf2_read ();
25444 _initialize_dwarf2_read ()
25446 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
25447 Set DWARF specific variables.\n\
25448 Configure DWARF variables such as the cache size."),
25449 &set_dwarf_cmdlist
, "maintenance set dwarf ",
25450 0/*allow-unknown*/, &maintenance_set_cmdlist
);
25452 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
25453 Show DWARF specific variables.\n\
25454 Show DWARF variables such as the cache size."),
25455 &show_dwarf_cmdlist
, "maintenance show dwarf ",
25456 0/*allow-unknown*/, &maintenance_show_cmdlist
);
25458 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
25459 &dwarf_max_cache_age
, _("\
25460 Set the upper bound on the age of cached DWARF compilation units."), _("\
25461 Show the upper bound on the age of cached DWARF compilation units."), _("\
25462 A higher limit means that cached compilation units will be stored\n\
25463 in memory longer, and more total memory will be used. Zero disables\n\
25464 caching, which can slow down startup."),
25466 show_dwarf_max_cache_age
,
25467 &set_dwarf_cmdlist
,
25468 &show_dwarf_cmdlist
);
25470 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
25471 &dwarf_always_disassemble
, _("\
25472 Set whether `info address' always disassembles DWARF expressions."), _("\
25473 Show whether `info address' always disassembles DWARF expressions."), _("\
25474 When enabled, DWARF expressions are always printed in an assembly-like\n\
25475 syntax. When disabled, expressions will be printed in a more\n\
25476 conversational style, when possible."),
25478 show_dwarf_always_disassemble
,
25479 &set_dwarf_cmdlist
,
25480 &show_dwarf_cmdlist
);
25482 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
25483 Set debugging of the DWARF reader."), _("\
25484 Show debugging of the DWARF reader."), _("\
25485 When enabled (non-zero), debugging messages are printed during DWARF\n\
25486 reading and symtab expansion. A value of 1 (one) provides basic\n\
25487 information. A value greater than 1 provides more verbose information."),
25490 &setdebuglist
, &showdebuglist
);
25492 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
25493 Set debugging of the DWARF DIE reader."), _("\
25494 Show debugging of the DWARF DIE reader."), _("\
25495 When enabled (non-zero), DIEs are dumped after they are read in.\n\
25496 The value is the maximum depth to print."),
25499 &setdebuglist
, &showdebuglist
);
25501 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
25502 Set debugging of the dwarf line reader."), _("\
25503 Show debugging of the dwarf line reader."), _("\
25504 When enabled (non-zero), line number entries are dumped as they are read in.\n\
25505 A value of 1 (one) provides basic information.\n\
25506 A value greater than 1 provides more verbose information."),
25509 &setdebuglist
, &showdebuglist
);
25511 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
25512 Set cross-checking of \"physname\" code against demangler."), _("\
25513 Show cross-checking of \"physname\" code against demangler."), _("\
25514 When enabled, GDB's internal \"physname\" code is checked against\n\
25516 NULL
, show_check_physname
,
25517 &setdebuglist
, &showdebuglist
);
25519 add_setshow_boolean_cmd ("use-deprecated-index-sections",
25520 no_class
, &use_deprecated_index_sections
, _("\
25521 Set whether to use deprecated gdb_index sections."), _("\
25522 Show whether to use deprecated gdb_index sections."), _("\
25523 When enabled, deprecated .gdb_index sections are used anyway.\n\
25524 Normally they are ignored either because of a missing feature or\n\
25525 performance issue.\n\
25526 Warning: This option must be enabled before gdb reads the file."),
25529 &setlist
, &showlist
);
25531 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
25532 &dwarf2_locexpr_funcs
);
25533 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
25534 &dwarf2_loclist_funcs
);
25536 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
25537 &dwarf2_block_frame_base_locexpr_funcs
);
25538 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
25539 &dwarf2_block_frame_base_loclist_funcs
);
25542 selftests::register_test ("dw2_expand_symtabs_matching",
25543 selftests::dw2_expand_symtabs_matching::run_test
);