1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2019 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 "dwarf-index-cache.h"
34 #include "dwarf-index-common.h"
43 #include "gdb-demangle.h"
44 #include "expression.h"
45 #include "filenames.h" /* for DOSish file names */
48 #include "complaints.h"
49 #include "dwarf2expr.h"
50 #include "dwarf2loc.h"
51 #include "cp-support.h"
57 #include "typeprint.h"
60 #include "completer.h"
61 #include "gdbsupport/vec.h"
65 #include "gdbcore.h" /* for gnutarget */
66 #include "gdb/gdb-index.h"
71 #include "gdbsupport/filestuff.h"
73 #include "namespace.h"
74 #include "gdbsupport/gdb_unlinker.h"
75 #include "gdbsupport/function-view.h"
76 #include "gdbsupport/gdb_optional.h"
77 #include "gdbsupport/underlying.h"
78 #include "gdbsupport/byte-vector.h"
79 #include "gdbsupport/hash_enum.h"
80 #include "filename-seen-cache.h"
83 #include <sys/types.h>
85 #include <unordered_set>
86 #include <unordered_map>
87 #include "gdbsupport/selftest.h"
90 #include <forward_list>
91 #include "rust-lang.h"
92 #include "gdbsupport/pathstuff.h"
94 /* When == 1, print basic high level tracing messages.
95 When > 1, be more verbose.
96 This is in contrast to the low level DIE reading of dwarf_die_debug. */
97 static unsigned int dwarf_read_debug
= 0;
99 /* When non-zero, dump DIEs after they are read in. */
100 static unsigned int dwarf_die_debug
= 0;
102 /* When non-zero, dump line number entries as they are read in. */
103 static unsigned int dwarf_line_debug
= 0;
105 /* When true, cross-check physname against demangler. */
106 static bool check_physname
= false;
108 /* When true, do not reject deprecated .gdb_index sections. */
109 static bool use_deprecated_index_sections
= false;
111 static const struct objfile_key
<dwarf2_per_objfile
> dwarf2_objfile_data_key
;
113 /* The "aclass" indices for various kinds of computed DWARF symbols. */
115 static int dwarf2_locexpr_index
;
116 static int dwarf2_loclist_index
;
117 static int dwarf2_locexpr_block_index
;
118 static int dwarf2_loclist_block_index
;
120 /* An index into a (C++) symbol name component in a symbol name as
121 recorded in the mapped_index's symbol table. For each C++ symbol
122 in the symbol table, we record one entry for the start of each
123 component in the symbol in a table of name components, and then
124 sort the table, in order to be able to binary search symbol names,
125 ignoring leading namespaces, both completion and regular look up.
126 For example, for symbol "A::B::C", we'll have an entry that points
127 to "A::B::C", another that points to "B::C", and another for "C".
128 Note that function symbols in GDB index have no parameter
129 information, just the function/method names. You can convert a
130 name_component to a "const char *" using the
131 'mapped_index::symbol_name_at(offset_type)' method. */
133 struct name_component
135 /* Offset in the symbol name where the component starts. Stored as
136 a (32-bit) offset instead of a pointer to save memory and improve
137 locality on 64-bit architectures. */
138 offset_type name_offset
;
140 /* The symbol's index in the symbol and constant pool tables of a
145 /* Base class containing bits shared by both .gdb_index and
146 .debug_name indexes. */
148 struct mapped_index_base
150 mapped_index_base () = default;
151 DISABLE_COPY_AND_ASSIGN (mapped_index_base
);
153 /* The name_component table (a sorted vector). See name_component's
154 description above. */
155 std::vector
<name_component
> name_components
;
157 /* How NAME_COMPONENTS is sorted. */
158 enum case_sensitivity name_components_casing
;
160 /* Return the number of names in the symbol table. */
161 virtual size_t symbol_name_count () const = 0;
163 /* Get the name of the symbol at IDX in the symbol table. */
164 virtual const char *symbol_name_at (offset_type idx
) const = 0;
166 /* Return whether the name at IDX in the symbol table should be
168 virtual bool symbol_name_slot_invalid (offset_type idx
) const
173 /* Build the symbol name component sorted vector, if we haven't
175 void build_name_components ();
177 /* Returns the lower (inclusive) and upper (exclusive) bounds of the
178 possible matches for LN_NO_PARAMS in the name component
180 std::pair
<std::vector
<name_component
>::const_iterator
,
181 std::vector
<name_component
>::const_iterator
>
182 find_name_components_bounds (const lookup_name_info
&ln_no_params
,
183 enum language lang
) const;
185 /* Prevent deleting/destroying via a base class pointer. */
187 ~mapped_index_base() = default;
190 /* A description of the mapped index. The file format is described in
191 a comment by the code that writes the index. */
192 struct mapped_index final
: public mapped_index_base
194 /* A slot/bucket in the symbol table hash. */
195 struct symbol_table_slot
197 const offset_type name
;
198 const offset_type vec
;
201 /* Index data format version. */
204 /* The address table data. */
205 gdb::array_view
<const gdb_byte
> address_table
;
207 /* The symbol table, implemented as a hash table. */
208 gdb::array_view
<symbol_table_slot
> symbol_table
;
210 /* A pointer to the constant pool. */
211 const char *constant_pool
= nullptr;
213 bool symbol_name_slot_invalid (offset_type idx
) const override
215 const auto &bucket
= this->symbol_table
[idx
];
216 return bucket
.name
== 0 && bucket
.vec
== 0;
219 /* Convenience method to get at the name of the symbol at IDX in the
221 const char *symbol_name_at (offset_type idx
) const override
222 { return this->constant_pool
+ MAYBE_SWAP (this->symbol_table
[idx
].name
); }
224 size_t symbol_name_count () const override
225 { return this->symbol_table
.size (); }
228 /* A description of the mapped .debug_names.
229 Uninitialized map has CU_COUNT 0. */
230 struct mapped_debug_names final
: public mapped_index_base
232 mapped_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile_
)
233 : dwarf2_per_objfile (dwarf2_per_objfile_
)
236 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
237 bfd_endian dwarf5_byte_order
;
238 bool dwarf5_is_dwarf64
;
239 bool augmentation_is_gdb
;
241 uint32_t cu_count
= 0;
242 uint32_t tu_count
, bucket_count
, name_count
;
243 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
244 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
245 const gdb_byte
*name_table_string_offs_reordered
;
246 const gdb_byte
*name_table_entry_offs_reordered
;
247 const gdb_byte
*entry_pool
;
254 /* Attribute name DW_IDX_*. */
257 /* Attribute form DW_FORM_*. */
260 /* Value if FORM is DW_FORM_implicit_const. */
261 LONGEST implicit_const
;
263 std::vector
<attr
> attr_vec
;
266 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
268 const char *namei_to_name (uint32_t namei
) const;
270 /* Implementation of the mapped_index_base virtual interface, for
271 the name_components cache. */
273 const char *symbol_name_at (offset_type idx
) const override
274 { return namei_to_name (idx
); }
276 size_t symbol_name_count () const override
277 { return this->name_count
; }
280 /* See dwarf2read.h. */
283 get_dwarf2_per_objfile (struct objfile
*objfile
)
285 return dwarf2_objfile_data_key
.get (objfile
);
288 /* Default names of the debugging sections. */
290 /* Note that if the debugging section has been compressed, it might
291 have a name like .zdebug_info. */
293 static const struct dwarf2_debug_sections dwarf2_elf_names
=
295 { ".debug_info", ".zdebug_info" },
296 { ".debug_abbrev", ".zdebug_abbrev" },
297 { ".debug_line", ".zdebug_line" },
298 { ".debug_loc", ".zdebug_loc" },
299 { ".debug_loclists", ".zdebug_loclists" },
300 { ".debug_macinfo", ".zdebug_macinfo" },
301 { ".debug_macro", ".zdebug_macro" },
302 { ".debug_str", ".zdebug_str" },
303 { ".debug_line_str", ".zdebug_line_str" },
304 { ".debug_ranges", ".zdebug_ranges" },
305 { ".debug_rnglists", ".zdebug_rnglists" },
306 { ".debug_types", ".zdebug_types" },
307 { ".debug_addr", ".zdebug_addr" },
308 { ".debug_frame", ".zdebug_frame" },
309 { ".eh_frame", NULL
},
310 { ".gdb_index", ".zgdb_index" },
311 { ".debug_names", ".zdebug_names" },
312 { ".debug_aranges", ".zdebug_aranges" },
316 /* List of DWO/DWP sections. */
318 static const struct dwop_section_names
320 struct dwarf2_section_names abbrev_dwo
;
321 struct dwarf2_section_names info_dwo
;
322 struct dwarf2_section_names line_dwo
;
323 struct dwarf2_section_names loc_dwo
;
324 struct dwarf2_section_names loclists_dwo
;
325 struct dwarf2_section_names macinfo_dwo
;
326 struct dwarf2_section_names macro_dwo
;
327 struct dwarf2_section_names str_dwo
;
328 struct dwarf2_section_names str_offsets_dwo
;
329 struct dwarf2_section_names types_dwo
;
330 struct dwarf2_section_names cu_index
;
331 struct dwarf2_section_names tu_index
;
335 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
336 { ".debug_info.dwo", ".zdebug_info.dwo" },
337 { ".debug_line.dwo", ".zdebug_line.dwo" },
338 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
339 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
340 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
341 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
342 { ".debug_str.dwo", ".zdebug_str.dwo" },
343 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
344 { ".debug_types.dwo", ".zdebug_types.dwo" },
345 { ".debug_cu_index", ".zdebug_cu_index" },
346 { ".debug_tu_index", ".zdebug_tu_index" },
349 /* local data types */
351 /* The data in a compilation unit header, after target2host
352 translation, looks like this. */
353 struct comp_unit_head
357 unsigned char addr_size
;
358 unsigned char signed_addr_p
;
359 sect_offset abbrev_sect_off
;
361 /* Size of file offsets; either 4 or 8. */
362 unsigned int offset_size
;
364 /* Size of the length field; either 4 or 12. */
365 unsigned int initial_length_size
;
367 enum dwarf_unit_type unit_type
;
369 /* Offset to the first byte of this compilation unit header in the
370 .debug_info section, for resolving relative reference dies. */
371 sect_offset sect_off
;
373 /* Offset to first die in this cu from the start of the cu.
374 This will be the first byte following the compilation unit header. */
375 cu_offset first_die_cu_offset
;
378 /* 64-bit signature of this unit. For type units, it denotes the signature of
379 the type (DW_UT_type in DWARF 4, additionally DW_UT_split_type in DWARF 5).
380 Also used in DWARF 5, to denote the dwo id when the unit type is
381 DW_UT_skeleton or DW_UT_split_compile. */
384 /* For types, offset in the type's DIE of the type defined by this TU. */
385 cu_offset type_cu_offset_in_tu
;
388 /* Type used for delaying computation of method physnames.
389 See comments for compute_delayed_physnames. */
390 struct delayed_method_info
392 /* The type to which the method is attached, i.e., its parent class. */
395 /* The index of the method in the type's function fieldlists. */
398 /* The index of the method in the fieldlist. */
401 /* The name of the DIE. */
404 /* The DIE associated with this method. */
405 struct die_info
*die
;
408 /* Internal state when decoding a particular compilation unit. */
411 explicit dwarf2_cu (struct dwarf2_per_cu_data
*per_cu
);
414 DISABLE_COPY_AND_ASSIGN (dwarf2_cu
);
416 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
417 Create the set of symtabs used by this TU, or if this TU is sharing
418 symtabs with another TU and the symtabs have already been created
419 then restore those symtabs in the line header.
420 We don't need the pc/line-number mapping for type units. */
421 void setup_type_unit_groups (struct die_info
*die
);
423 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
424 buildsym_compunit constructor. */
425 struct compunit_symtab
*start_symtab (const char *name
,
426 const char *comp_dir
,
429 /* Reset the builder. */
430 void reset_builder () { m_builder
.reset (); }
432 /* The header of the compilation unit. */
433 struct comp_unit_head header
{};
435 /* Base address of this compilation unit. */
436 CORE_ADDR base_address
= 0;
438 /* Non-zero if base_address has been set. */
441 /* The language we are debugging. */
442 enum language language
= language_unknown
;
443 const struct language_defn
*language_defn
= nullptr;
445 const char *producer
= nullptr;
448 /* The symtab builder for this CU. This is only non-NULL when full
449 symbols are being read. */
450 std::unique_ptr
<buildsym_compunit
> m_builder
;
453 /* The generic symbol table building routines have separate lists for
454 file scope symbols and all all other scopes (local scopes). So
455 we need to select the right one to pass to add_symbol_to_list().
456 We do it by keeping a pointer to the correct list in list_in_scope.
458 FIXME: The original dwarf code just treated the file scope as the
459 first local scope, and all other local scopes as nested local
460 scopes, and worked fine. Check to see if we really need to
461 distinguish these in buildsym.c. */
462 struct pending
**list_in_scope
= nullptr;
464 /* Hash table holding all the loaded partial DIEs
465 with partial_die->offset.SECT_OFF as hash. */
466 htab_t partial_dies
= nullptr;
468 /* Storage for things with the same lifetime as this read-in compilation
469 unit, including partial DIEs. */
470 auto_obstack comp_unit_obstack
;
472 /* When multiple dwarf2_cu structures are living in memory, this field
473 chains them all together, so that they can be released efficiently.
474 We will probably also want a generation counter so that most-recently-used
475 compilation units are cached... */
476 struct dwarf2_per_cu_data
*read_in_chain
= nullptr;
478 /* Backlink to our per_cu entry. */
479 struct dwarf2_per_cu_data
*per_cu
;
481 /* How many compilation units ago was this CU last referenced? */
484 /* A hash table of DIE cu_offset for following references with
485 die_info->offset.sect_off as hash. */
486 htab_t die_hash
= nullptr;
488 /* Full DIEs if read in. */
489 struct die_info
*dies
= nullptr;
491 /* A set of pointers to dwarf2_per_cu_data objects for compilation
492 units referenced by this one. Only set during full symbol processing;
493 partial symbol tables do not have dependencies. */
494 htab_t dependencies
= nullptr;
496 /* Header data from the line table, during full symbol processing. */
497 struct line_header
*line_header
= nullptr;
498 /* Non-NULL if LINE_HEADER is owned by this DWARF_CU. Otherwise,
499 it's owned by dwarf2_per_objfile::line_header_hash. If non-NULL,
500 this is the DW_TAG_compile_unit die for this CU. We'll hold on
501 to the line header as long as this DIE is being processed. See
502 process_die_scope. */
503 die_info
*line_header_die_owner
= nullptr;
505 /* A list of methods which need to have physnames computed
506 after all type information has been read. */
507 std::vector
<delayed_method_info
> method_list
;
509 /* To be copied to symtab->call_site_htab. */
510 htab_t call_site_htab
= nullptr;
512 /* Non-NULL if this CU came from a DWO file.
513 There is an invariant here that is important to remember:
514 Except for attributes copied from the top level DIE in the "main"
515 (or "stub") file in preparation for reading the DWO file
516 (e.g., DW_AT_GNU_addr_base), we KISS: there is only *one* CU.
517 Either there isn't a DWO file (in which case this is NULL and the point
518 is moot), or there is and either we're not going to read it (in which
519 case this is NULL) or there is and we are reading it (in which case this
521 struct dwo_unit
*dwo_unit
= nullptr;
523 /* The DW_AT_addr_base attribute if present, zero otherwise
524 (zero is a valid value though).
525 Note this value comes from the Fission stub CU/TU's DIE. */
526 ULONGEST addr_base
= 0;
528 /* The DW_AT_ranges_base attribute if present, zero otherwise
529 (zero is a valid value though).
530 Note this value comes from the Fission stub CU/TU's DIE.
531 Also note that the value is zero in the non-DWO case so this value can
532 be used without needing to know whether DWO files are in use or not.
533 N.B. This does not apply to DW_AT_ranges appearing in
534 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
535 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
536 DW_AT_ranges_base *would* have to be applied, and we'd have to care
537 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
538 ULONGEST ranges_base
= 0;
540 /* When reading debug info generated by older versions of rustc, we
541 have to rewrite some union types to be struct types with a
542 variant part. This rewriting must be done after the CU is fully
543 read in, because otherwise at the point of rewriting some struct
544 type might not have been fully processed. So, we keep a list of
545 all such types here and process them after expansion. */
546 std::vector
<struct type
*> rust_unions
;
548 /* Mark used when releasing cached dies. */
551 /* This CU references .debug_loc. See the symtab->locations_valid field.
552 This test is imperfect as there may exist optimized debug code not using
553 any location list and still facing inlining issues if handled as
554 unoptimized code. For a future better test see GCC PR other/32998. */
555 bool has_loclist
: 1;
557 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is true
558 if all the producer_is_* fields are valid. This information is cached
559 because profiling CU expansion showed excessive time spent in
560 producer_is_gxx_lt_4_6. */
561 bool checked_producer
: 1;
562 bool producer_is_gxx_lt_4_6
: 1;
563 bool producer_is_gcc_lt_4_3
: 1;
564 bool producer_is_icc
: 1;
565 bool producer_is_icc_lt_14
: 1;
566 bool producer_is_codewarrior
: 1;
568 /* When true, the file that we're processing is known to have
569 debugging info for C++ namespaces. GCC 3.3.x did not produce
570 this information, but later versions do. */
572 bool processing_has_namespace_info
: 1;
574 struct partial_die_info
*find_partial_die (sect_offset sect_off
);
576 /* If this CU was inherited by another CU (via specification,
577 abstract_origin, etc), this is the ancestor CU. */
580 /* Get the buildsym_compunit for this CU. */
581 buildsym_compunit
*get_builder ()
583 /* If this CU has a builder associated with it, use that. */
584 if (m_builder
!= nullptr)
585 return m_builder
.get ();
587 /* Otherwise, search ancestors for a valid builder. */
588 if (ancestor
!= nullptr)
589 return ancestor
->get_builder ();
595 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
596 This includes type_unit_group and quick_file_names. */
598 struct stmt_list_hash
600 /* The DWO unit this table is from or NULL if there is none. */
601 struct dwo_unit
*dwo_unit
;
603 /* Offset in .debug_line or .debug_line.dwo. */
604 sect_offset line_sect_off
;
607 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
608 an object of this type. */
610 struct type_unit_group
612 /* dwarf2read.c's main "handle" on a TU symtab.
613 To simplify things we create an artificial CU that "includes" all the
614 type units using this stmt_list so that the rest of the code still has
615 a "per_cu" handle on the symtab.
616 This PER_CU is recognized by having no section. */
617 #define IS_TYPE_UNIT_GROUP(per_cu) ((per_cu)->section == NULL)
618 struct dwarf2_per_cu_data per_cu
;
620 /* The TUs that share this DW_AT_stmt_list entry.
621 This is added to while parsing type units to build partial symtabs,
622 and is deleted afterwards and not used again. */
623 VEC (sig_type_ptr
) *tus
;
625 /* The compunit symtab.
626 Type units in a group needn't all be defined in the same source file,
627 so we create an essentially anonymous symtab as the compunit symtab. */
628 struct compunit_symtab
*compunit_symtab
;
630 /* The data used to construct the hash key. */
631 struct stmt_list_hash hash
;
633 /* The number of symtabs from the line header.
634 The value here must match line_header.num_file_names. */
635 unsigned int num_symtabs
;
637 /* The symbol tables for this TU (obtained from the files listed in
639 WARNING: The order of entries here must match the order of entries
640 in the line header. After the first TU using this type_unit_group, the
641 line header for the subsequent TUs is recreated from this. This is done
642 because we need to use the same symtabs for each TU using the same
643 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
644 there's no guarantee the line header doesn't have duplicate entries. */
645 struct symtab
**symtabs
;
648 /* These sections are what may appear in a (real or virtual) DWO file. */
652 struct dwarf2_section_info abbrev
;
653 struct dwarf2_section_info line
;
654 struct dwarf2_section_info loc
;
655 struct dwarf2_section_info loclists
;
656 struct dwarf2_section_info macinfo
;
657 struct dwarf2_section_info macro
;
658 struct dwarf2_section_info str
;
659 struct dwarf2_section_info str_offsets
;
660 /* In the case of a virtual DWO file, these two are unused. */
661 struct dwarf2_section_info info
;
662 std::vector
<dwarf2_section_info
> types
;
665 /* CUs/TUs in DWP/DWO files. */
669 /* Backlink to the containing struct dwo_file. */
670 struct dwo_file
*dwo_file
;
672 /* The "id" that distinguishes this CU/TU.
673 .debug_info calls this "dwo_id", .debug_types calls this "signature".
674 Since signatures came first, we stick with it for consistency. */
677 /* The section this CU/TU lives in, in the DWO file. */
678 struct dwarf2_section_info
*section
;
680 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
681 sect_offset sect_off
;
684 /* For types, offset in the type's DIE of the type defined by this TU. */
685 cu_offset type_offset_in_tu
;
688 /* include/dwarf2.h defines the DWP section codes.
689 It defines a max value but it doesn't define a min value, which we
690 use for error checking, so provide one. */
692 enum dwp_v2_section_ids
697 /* Data for one DWO file.
699 This includes virtual DWO files (a virtual DWO file is a DWO file as it
700 appears in a DWP file). DWP files don't really have DWO files per se -
701 comdat folding of types "loses" the DWO file they came from, and from
702 a high level view DWP files appear to contain a mass of random types.
703 However, to maintain consistency with the non-DWP case we pretend DWP
704 files contain virtual DWO files, and we assign each TU with one virtual
705 DWO file (generally based on the line and abbrev section offsets -
706 a heuristic that seems to work in practice). */
710 dwo_file () = default;
711 DISABLE_COPY_AND_ASSIGN (dwo_file
);
713 /* The DW_AT_GNU_dwo_name attribute.
714 For virtual DWO files the name is constructed from the section offsets
715 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
716 from related CU+TUs. */
717 const char *dwo_name
= nullptr;
719 /* The DW_AT_comp_dir attribute. */
720 const char *comp_dir
= nullptr;
722 /* The bfd, when the file is open. Otherwise this is NULL.
723 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
724 gdb_bfd_ref_ptr dbfd
;
726 /* The sections that make up this DWO file.
727 Remember that for virtual DWO files in DWP V2, these are virtual
728 sections (for lack of a better name). */
729 struct dwo_sections sections
{};
731 /* The CUs in the file.
732 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
733 an extension to handle LLVM's Link Time Optimization output (where
734 multiple source files may be compiled into a single object/dwo pair). */
737 /* Table of TUs in the file.
738 Each element is a struct dwo_unit. */
742 /* These sections are what may appear in a DWP file. */
746 /* These are used by both DWP version 1 and 2. */
747 struct dwarf2_section_info str
;
748 struct dwarf2_section_info cu_index
;
749 struct dwarf2_section_info tu_index
;
751 /* These are only used by DWP version 2 files.
752 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
753 sections are referenced by section number, and are not recorded here.
754 In DWP version 2 there is at most one copy of all these sections, each
755 section being (effectively) comprised of the concatenation of all of the
756 individual sections that exist in the version 1 format.
757 To keep the code simple we treat each of these concatenated pieces as a
758 section itself (a virtual section?). */
759 struct dwarf2_section_info abbrev
;
760 struct dwarf2_section_info info
;
761 struct dwarf2_section_info line
;
762 struct dwarf2_section_info loc
;
763 struct dwarf2_section_info macinfo
;
764 struct dwarf2_section_info macro
;
765 struct dwarf2_section_info str_offsets
;
766 struct dwarf2_section_info types
;
769 /* These sections are what may appear in a virtual DWO file in DWP version 1.
770 A virtual DWO file is a DWO file as it appears in a DWP file. */
772 struct virtual_v1_dwo_sections
774 struct dwarf2_section_info abbrev
;
775 struct dwarf2_section_info line
;
776 struct dwarf2_section_info loc
;
777 struct dwarf2_section_info macinfo
;
778 struct dwarf2_section_info macro
;
779 struct dwarf2_section_info str_offsets
;
780 /* Each DWP hash table entry records one CU or one TU.
781 That is recorded here, and copied to dwo_unit.section. */
782 struct dwarf2_section_info info_or_types
;
785 /* Similar to virtual_v1_dwo_sections, but for DWP version 2.
786 In version 2, the sections of the DWO files are concatenated together
787 and stored in one section of that name. Thus each ELF section contains
788 several "virtual" sections. */
790 struct virtual_v2_dwo_sections
792 bfd_size_type abbrev_offset
;
793 bfd_size_type abbrev_size
;
795 bfd_size_type line_offset
;
796 bfd_size_type line_size
;
798 bfd_size_type loc_offset
;
799 bfd_size_type loc_size
;
801 bfd_size_type macinfo_offset
;
802 bfd_size_type macinfo_size
;
804 bfd_size_type macro_offset
;
805 bfd_size_type macro_size
;
807 bfd_size_type str_offsets_offset
;
808 bfd_size_type str_offsets_size
;
810 /* Each DWP hash table entry records one CU or one TU.
811 That is recorded here, and copied to dwo_unit.section. */
812 bfd_size_type info_or_types_offset
;
813 bfd_size_type info_or_types_size
;
816 /* Contents of DWP hash tables. */
818 struct dwp_hash_table
820 uint32_t version
, nr_columns
;
821 uint32_t nr_units
, nr_slots
;
822 const gdb_byte
*hash_table
, *unit_table
;
827 const gdb_byte
*indices
;
831 /* This is indexed by column number and gives the id of the section
833 #define MAX_NR_V2_DWO_SECTIONS \
834 (1 /* .debug_info or .debug_types */ \
835 + 1 /* .debug_abbrev */ \
836 + 1 /* .debug_line */ \
837 + 1 /* .debug_loc */ \
838 + 1 /* .debug_str_offsets */ \
839 + 1 /* .debug_macro or .debug_macinfo */)
840 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
841 const gdb_byte
*offsets
;
842 const gdb_byte
*sizes
;
847 /* Data for one DWP file. */
851 dwp_file (const char *name_
, gdb_bfd_ref_ptr
&&abfd
)
853 dbfd (std::move (abfd
))
857 /* Name of the file. */
860 /* File format version. */
864 gdb_bfd_ref_ptr dbfd
;
866 /* Section info for this file. */
867 struct dwp_sections sections
{};
869 /* Table of CUs in the file. */
870 const struct dwp_hash_table
*cus
= nullptr;
872 /* Table of TUs in the file. */
873 const struct dwp_hash_table
*tus
= nullptr;
875 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
876 htab_t loaded_cus
{};
877 htab_t loaded_tus
{};
879 /* Table to map ELF section numbers to their sections.
880 This is only needed for the DWP V1 file format. */
881 unsigned int num_sections
= 0;
882 asection
**elf_sections
= nullptr;
885 /* Struct used to pass misc. parameters to read_die_and_children, et
886 al. which are used for both .debug_info and .debug_types dies.
887 All parameters here are unchanging for the life of the call. This
888 struct exists to abstract away the constant parameters of die reading. */
890 struct die_reader_specs
892 /* The bfd of die_section. */
895 /* The CU of the DIE we are parsing. */
896 struct dwarf2_cu
*cu
;
898 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
899 struct dwo_file
*dwo_file
;
901 /* The section the die comes from.
902 This is either .debug_info or .debug_types, or the .dwo variants. */
903 struct dwarf2_section_info
*die_section
;
905 /* die_section->buffer. */
906 const gdb_byte
*buffer
;
908 /* The end of the buffer. */
909 const gdb_byte
*buffer_end
;
911 /* The value of the DW_AT_comp_dir attribute. */
912 const char *comp_dir
;
914 /* The abbreviation table to use when reading the DIEs. */
915 struct abbrev_table
*abbrev_table
;
918 /* Type of function passed to init_cutu_and_read_dies, et.al. */
919 typedef void (die_reader_func_ftype
) (const struct die_reader_specs
*reader
,
920 const gdb_byte
*info_ptr
,
921 struct die_info
*comp_unit_die
,
925 /* A 1-based directory index. This is a strong typedef to prevent
926 accidentally using a directory index as a 0-based index into an
928 enum class dir_index
: unsigned int {};
930 /* Likewise, a 1-based file name index. */
931 enum class file_name_index
: unsigned int {};
935 file_entry () = default;
937 file_entry (const char *name_
, dir_index d_index_
,
938 unsigned int mod_time_
, unsigned int length_
)
941 mod_time (mod_time_
),
945 /* Return the include directory at D_INDEX stored in LH. Returns
946 NULL if D_INDEX is out of bounds. */
947 const char *include_dir (const line_header
*lh
) const;
949 /* The file name. Note this is an observing pointer. The memory is
950 owned by debug_line_buffer. */
953 /* The directory index (1-based). */
954 dir_index d_index
{};
956 unsigned int mod_time
{};
958 unsigned int length
{};
960 /* True if referenced by the Line Number Program. */
963 /* The associated symbol table, if any. */
964 struct symtab
*symtab
{};
967 /* The line number information for a compilation unit (found in the
968 .debug_line section) begins with a "statement program header",
969 which contains the following information. */
976 /* Add an entry to the include directory table. */
977 void add_include_dir (const char *include_dir
);
979 /* Add an entry to the file name table. */
980 void add_file_name (const char *name
, dir_index d_index
,
981 unsigned int mod_time
, unsigned int length
);
983 /* Return the include dir at INDEX (1-based). Returns NULL if INDEX
985 const char *include_dir_at (dir_index index
) const
987 /* Convert directory index number (1-based) to vector index
989 size_t vec_index
= to_underlying (index
) - 1;
991 if (vec_index
>= include_dirs
.size ())
993 return include_dirs
[vec_index
];
996 /* Return the file name at INDEX (1-based). Returns NULL if INDEX
998 file_entry
*file_name_at (file_name_index index
)
1000 /* Convert file name index number (1-based) to vector index
1002 size_t vec_index
= to_underlying (index
) - 1;
1004 if (vec_index
>= file_names
.size ())
1006 return &file_names
[vec_index
];
1009 /* Offset of line number information in .debug_line section. */
1010 sect_offset sect_off
{};
1012 /* OFFSET is for struct dwz_file associated with dwarf2_per_objfile. */
1013 unsigned offset_in_dwz
: 1; /* Can't initialize bitfields in-class. */
1015 unsigned int total_length
{};
1016 unsigned short version
{};
1017 unsigned int header_length
{};
1018 unsigned char minimum_instruction_length
{};
1019 unsigned char maximum_ops_per_instruction
{};
1020 unsigned char default_is_stmt
{};
1022 unsigned char line_range
{};
1023 unsigned char opcode_base
{};
1025 /* standard_opcode_lengths[i] is the number of operands for the
1026 standard opcode whose value is i. This means that
1027 standard_opcode_lengths[0] is unused, and the last meaningful
1028 element is standard_opcode_lengths[opcode_base - 1]. */
1029 std::unique_ptr
<unsigned char[]> standard_opcode_lengths
;
1031 /* The include_directories table. Note these are observing
1032 pointers. The memory is owned by debug_line_buffer. */
1033 std::vector
<const char *> include_dirs
;
1035 /* The file_names table. */
1036 std::vector
<file_entry
> file_names
;
1038 /* The start and end of the statement program following this
1039 header. These point into dwarf2_per_objfile->line_buffer. */
1040 const gdb_byte
*statement_program_start
{}, *statement_program_end
{};
1043 typedef std::unique_ptr
<line_header
> line_header_up
;
1046 file_entry::include_dir (const line_header
*lh
) const
1048 return lh
->include_dir_at (d_index
);
1051 /* When we construct a partial symbol table entry we only
1052 need this much information. */
1053 struct partial_die_info
: public allocate_on_obstack
1055 partial_die_info (sect_offset sect_off
, struct abbrev_info
*abbrev
);
1057 /* Disable assign but still keep copy ctor, which is needed
1058 load_partial_dies. */
1059 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
1061 /* Adjust the partial die before generating a symbol for it. This
1062 function may set the is_external flag or change the DIE's
1064 void fixup (struct dwarf2_cu
*cu
);
1066 /* Read a minimal amount of information into the minimal die
1068 const gdb_byte
*read (const struct die_reader_specs
*reader
,
1069 const struct abbrev_info
&abbrev
,
1070 const gdb_byte
*info_ptr
);
1072 /* Offset of this DIE. */
1073 const sect_offset sect_off
;
1075 /* DWARF-2 tag for this DIE. */
1076 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1078 /* Assorted flags describing the data found in this DIE. */
1079 const unsigned int has_children
: 1;
1081 unsigned int is_external
: 1;
1082 unsigned int is_declaration
: 1;
1083 unsigned int has_type
: 1;
1084 unsigned int has_specification
: 1;
1085 unsigned int has_pc_info
: 1;
1086 unsigned int may_be_inlined
: 1;
1088 /* This DIE has been marked DW_AT_main_subprogram. */
1089 unsigned int main_subprogram
: 1;
1091 /* Flag set if the SCOPE field of this structure has been
1093 unsigned int scope_set
: 1;
1095 /* Flag set if the DIE has a byte_size attribute. */
1096 unsigned int has_byte_size
: 1;
1098 /* Flag set if the DIE has a DW_AT_const_value attribute. */
1099 unsigned int has_const_value
: 1;
1101 /* Flag set if any of the DIE's children are template arguments. */
1102 unsigned int has_template_arguments
: 1;
1104 /* Flag set if fixup has been called on this die. */
1105 unsigned int fixup_called
: 1;
1107 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1108 unsigned int is_dwz
: 1;
1110 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1111 unsigned int spec_is_dwz
: 1;
1113 /* The name of this DIE. Normally the value of DW_AT_name, but
1114 sometimes a default name for unnamed DIEs. */
1115 const char *name
= nullptr;
1117 /* The linkage name, if present. */
1118 const char *linkage_name
= nullptr;
1120 /* The scope to prepend to our children. This is generally
1121 allocated on the comp_unit_obstack, so will disappear
1122 when this compilation unit leaves the cache. */
1123 const char *scope
= nullptr;
1125 /* Some data associated with the partial DIE. The tag determines
1126 which field is live. */
1129 /* The location description associated with this DIE, if any. */
1130 struct dwarf_block
*locdesc
;
1131 /* The offset of an import, for DW_TAG_imported_unit. */
1132 sect_offset sect_off
;
1135 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1136 CORE_ADDR lowpc
= 0;
1137 CORE_ADDR highpc
= 0;
1139 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1140 DW_AT_sibling, if any. */
1141 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1142 could return DW_AT_sibling values to its caller load_partial_dies. */
1143 const gdb_byte
*sibling
= nullptr;
1145 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1146 DW_AT_specification (or DW_AT_abstract_origin or
1147 DW_AT_extension). */
1148 sect_offset spec_offset
{};
1150 /* Pointers to this DIE's parent, first child, and next sibling,
1152 struct partial_die_info
*die_parent
= nullptr;
1153 struct partial_die_info
*die_child
= nullptr;
1154 struct partial_die_info
*die_sibling
= nullptr;
1156 friend struct partial_die_info
*
1157 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1160 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1161 partial_die_info (sect_offset sect_off
)
1162 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1166 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1168 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1173 has_specification
= 0;
1176 main_subprogram
= 0;
1179 has_const_value
= 0;
1180 has_template_arguments
= 0;
1187 /* This data structure holds the information of an abbrev. */
1190 unsigned int number
; /* number identifying abbrev */
1191 enum dwarf_tag tag
; /* dwarf tag */
1192 unsigned short has_children
; /* boolean */
1193 unsigned short num_attrs
; /* number of attributes */
1194 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
1195 struct abbrev_info
*next
; /* next in chain */
1200 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1201 ENUM_BITFIELD(dwarf_form
) form
: 16;
1203 /* It is valid only if FORM is DW_FORM_implicit_const. */
1204 LONGEST implicit_const
;
1207 /* Size of abbrev_table.abbrev_hash_table. */
1208 #define ABBREV_HASH_SIZE 121
1210 /* Top level data structure to contain an abbreviation table. */
1214 explicit abbrev_table (sect_offset off
)
1218 XOBNEWVEC (&abbrev_obstack
, struct abbrev_info
*, ABBREV_HASH_SIZE
);
1219 memset (m_abbrevs
, 0, ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
1222 DISABLE_COPY_AND_ASSIGN (abbrev_table
);
1224 /* Allocate space for a struct abbrev_info object in
1226 struct abbrev_info
*alloc_abbrev ();
1228 /* Add an abbreviation to the table. */
1229 void add_abbrev (unsigned int abbrev_number
, struct abbrev_info
*abbrev
);
1231 /* Look up an abbrev in the table.
1232 Returns NULL if the abbrev is not found. */
1234 struct abbrev_info
*lookup_abbrev (unsigned int abbrev_number
);
1237 /* Where the abbrev table came from.
1238 This is used as a sanity check when the table is used. */
1239 const sect_offset sect_off
;
1241 /* Storage for the abbrev table. */
1242 auto_obstack abbrev_obstack
;
1246 /* Hash table of abbrevs.
1247 This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack.
1248 It could be statically allocated, but the previous code didn't so we
1250 struct abbrev_info
**m_abbrevs
;
1253 typedef std::unique_ptr
<struct abbrev_table
> abbrev_table_up
;
1255 /* Attributes have a name and a value. */
1258 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1259 ENUM_BITFIELD(dwarf_form
) form
: 15;
1261 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
1262 field should be in u.str (existing only for DW_STRING) but it is kept
1263 here for better struct attribute alignment. */
1264 unsigned int string_is_canonical
: 1;
1269 struct dwarf_block
*blk
;
1278 /* This data structure holds a complete die structure. */
1281 /* DWARF-2 tag for this DIE. */
1282 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1284 /* Number of attributes */
1285 unsigned char num_attrs
;
1287 /* True if we're presently building the full type name for the
1288 type derived from this DIE. */
1289 unsigned char building_fullname
: 1;
1291 /* True if this die is in process. PR 16581. */
1292 unsigned char in_process
: 1;
1295 unsigned int abbrev
;
1297 /* Offset in .debug_info or .debug_types section. */
1298 sect_offset sect_off
;
1300 /* The dies in a compilation unit form an n-ary tree. PARENT
1301 points to this die's parent; CHILD points to the first child of
1302 this node; and all the children of a given node are chained
1303 together via their SIBLING fields. */
1304 struct die_info
*child
; /* Its first child, if any. */
1305 struct die_info
*sibling
; /* Its next sibling, if any. */
1306 struct die_info
*parent
; /* Its parent, if any. */
1308 /* An array of attributes, with NUM_ATTRS elements. There may be
1309 zero, but it's not common and zero-sized arrays are not
1310 sufficiently portable C. */
1311 struct attribute attrs
[1];
1314 /* Get at parts of an attribute structure. */
1316 #define DW_STRING(attr) ((attr)->u.str)
1317 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
1318 #define DW_UNSND(attr) ((attr)->u.unsnd)
1319 #define DW_BLOCK(attr) ((attr)->u.blk)
1320 #define DW_SND(attr) ((attr)->u.snd)
1321 #define DW_ADDR(attr) ((attr)->u.addr)
1322 #define DW_SIGNATURE(attr) ((attr)->u.signature)
1324 /* Blocks are a bunch of untyped bytes. */
1329 /* Valid only if SIZE is not zero. */
1330 const gdb_byte
*data
;
1333 #ifndef ATTR_ALLOC_CHUNK
1334 #define ATTR_ALLOC_CHUNK 4
1337 /* Allocate fields for structs, unions and enums in this size. */
1338 #ifndef DW_FIELD_ALLOC_CHUNK
1339 #define DW_FIELD_ALLOC_CHUNK 4
1342 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1343 but this would require a corresponding change in unpack_field_as_long
1345 static int bits_per_byte
= 8;
1347 /* When reading a variant or variant part, we track a bit more
1348 information about the field, and store it in an object of this
1351 struct variant_field
1353 /* If we see a DW_TAG_variant, then this will be the discriminant
1355 ULONGEST discriminant_value
;
1356 /* If we see a DW_TAG_variant, then this will be set if this is the
1358 bool default_branch
;
1359 /* While reading a DW_TAG_variant_part, this will be set if this
1360 field is the discriminant. */
1361 bool is_discriminant
;
1366 int accessibility
= 0;
1368 /* Extra information to describe a variant or variant part. */
1369 struct variant_field variant
{};
1370 struct field field
{};
1375 const char *name
= nullptr;
1376 std::vector
<struct fn_field
> fnfields
;
1379 /* The routines that read and process dies for a C struct or C++ class
1380 pass lists of data member fields and lists of member function fields
1381 in an instance of a field_info structure, as defined below. */
1384 /* List of data member and baseclasses fields. */
1385 std::vector
<struct nextfield
> fields
;
1386 std::vector
<struct nextfield
> baseclasses
;
1388 /* Number of fields (including baseclasses). */
1391 /* Set if the accesibility of one of the fields is not public. */
1392 int non_public_fields
= 0;
1394 /* Member function fieldlist array, contains name of possibly overloaded
1395 member function, number of overloaded member functions and a pointer
1396 to the head of the member function field chain. */
1397 std::vector
<struct fnfieldlist
> fnfieldlists
;
1399 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1400 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1401 std::vector
<struct decl_field
> typedef_field_list
;
1403 /* Nested types defined by this class and the number of elements in this
1405 std::vector
<struct decl_field
> nested_types_list
;
1408 /* One item on the queue of compilation units to read in full symbols
1410 struct dwarf2_queue_item
1412 struct dwarf2_per_cu_data
*per_cu
;
1413 enum language pretend_language
;
1414 struct dwarf2_queue_item
*next
;
1417 /* The current queue. */
1418 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
1420 /* Loaded secondary compilation units are kept in memory until they
1421 have not been referenced for the processing of this many
1422 compilation units. Set this to zero to disable caching. Cache
1423 sizes of up to at least twenty will improve startup time for
1424 typical inter-CU-reference binaries, at an obvious memory cost. */
1425 static int dwarf_max_cache_age
= 5;
1427 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1428 struct cmd_list_element
*c
, const char *value
)
1430 fprintf_filtered (file
, _("The upper bound on the age of cached "
1431 "DWARF compilation units is %s.\n"),
1435 /* local function prototypes */
1437 static const char *get_section_name (const struct dwarf2_section_info
*);
1439 static const char *get_section_file_name (const struct dwarf2_section_info
*);
1441 static void dwarf2_find_base_address (struct die_info
*die
,
1442 struct dwarf2_cu
*cu
);
1444 static struct partial_symtab
*create_partial_symtab
1445 (struct dwarf2_per_cu_data
*per_cu
, const char *name
);
1447 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1448 const gdb_byte
*info_ptr
,
1449 struct die_info
*type_unit_die
,
1450 int has_children
, void *data
);
1452 static void dwarf2_build_psymtabs_hard
1453 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1455 static void scan_partial_symbols (struct partial_die_info
*,
1456 CORE_ADDR
*, CORE_ADDR
*,
1457 int, struct dwarf2_cu
*);
1459 static void add_partial_symbol (struct partial_die_info
*,
1460 struct dwarf2_cu
*);
1462 static void add_partial_namespace (struct partial_die_info
*pdi
,
1463 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1464 int set_addrmap
, struct dwarf2_cu
*cu
);
1466 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1467 CORE_ADDR
*highpc
, int set_addrmap
,
1468 struct dwarf2_cu
*cu
);
1470 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1471 struct dwarf2_cu
*cu
);
1473 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1474 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1475 int need_pc
, struct dwarf2_cu
*cu
);
1477 static void dwarf2_read_symtab (struct partial_symtab
*,
1480 static void psymtab_to_symtab_1 (struct partial_symtab
*);
1482 static abbrev_table_up abbrev_table_read_table
1483 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, struct dwarf2_section_info
*,
1486 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1488 static struct partial_die_info
*load_partial_dies
1489 (const struct die_reader_specs
*, const gdb_byte
*, int);
1491 /* A pair of partial_die_info and compilation unit. */
1492 struct cu_partial_die_info
1494 /* The compilation unit of the partial_die_info. */
1495 struct dwarf2_cu
*cu
;
1496 /* A partial_die_info. */
1497 struct partial_die_info
*pdi
;
1499 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1505 cu_partial_die_info () = delete;
1508 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1509 struct dwarf2_cu
*);
1511 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1512 struct attribute
*, struct attr_abbrev
*,
1515 static unsigned int read_1_byte (bfd
*, const gdb_byte
*);
1517 static int read_1_signed_byte (bfd
*, const gdb_byte
*);
1519 static unsigned int read_2_bytes (bfd
*, const gdb_byte
*);
1521 /* Read the next three bytes (little-endian order) as an unsigned integer. */
1522 static unsigned int read_3_bytes (bfd
*, const gdb_byte
*);
1524 static unsigned int read_4_bytes (bfd
*, const gdb_byte
*);
1526 static ULONGEST
read_8_bytes (bfd
*, const gdb_byte
*);
1528 static CORE_ADDR
read_address (bfd
*, const gdb_byte
*ptr
, struct dwarf2_cu
*,
1531 static LONGEST
read_initial_length (bfd
*, const gdb_byte
*, unsigned int *);
1533 static LONGEST read_checked_initial_length_and_offset
1534 (bfd
*, const gdb_byte
*, const struct comp_unit_head
*,
1535 unsigned int *, unsigned int *);
1537 static LONGEST
read_offset (bfd
*, const gdb_byte
*,
1538 const struct comp_unit_head
*,
1541 static LONGEST
read_offset_1 (bfd
*, const gdb_byte
*, unsigned int);
1543 static sect_offset read_abbrev_offset
1544 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1545 struct dwarf2_section_info
*, sect_offset
);
1547 static const gdb_byte
*read_n_bytes (bfd
*, const gdb_byte
*, unsigned int);
1549 static const char *read_direct_string (bfd
*, const gdb_byte
*, unsigned int *);
1551 static const char *read_indirect_string
1552 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1553 const struct comp_unit_head
*, unsigned int *);
1555 static const char *read_indirect_line_string
1556 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1557 const struct comp_unit_head
*, unsigned int *);
1559 static const char *read_indirect_string_at_offset
1560 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
1561 LONGEST str_offset
);
1563 static const char *read_indirect_string_from_dwz
1564 (struct objfile
*objfile
, struct dwz_file
*, LONGEST
);
1566 static LONGEST
read_signed_leb128 (bfd
*, const gdb_byte
*, unsigned int *);
1568 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1572 static const char *read_str_index (const struct die_reader_specs
*reader
,
1573 ULONGEST str_index
);
1575 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1577 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1578 struct dwarf2_cu
*);
1580 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1583 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1584 struct dwarf2_cu
*cu
);
1586 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1588 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1589 struct dwarf2_cu
*cu
);
1591 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1593 static struct die_info
*die_specification (struct die_info
*die
,
1594 struct dwarf2_cu
**);
1596 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1597 struct dwarf2_cu
*cu
);
1599 static void dwarf_decode_lines (struct line_header
*, const char *,
1600 struct dwarf2_cu
*, struct partial_symtab
*,
1601 CORE_ADDR
, int decode_mapping
);
1603 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1606 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1607 struct dwarf2_cu
*, struct symbol
* = NULL
);
1609 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1610 struct dwarf2_cu
*);
1612 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1615 struct obstack
*obstack
,
1616 struct dwarf2_cu
*cu
, LONGEST
*value
,
1617 const gdb_byte
**bytes
,
1618 struct dwarf2_locexpr_baton
**baton
);
1620 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1622 static int need_gnat_info (struct dwarf2_cu
*);
1624 static struct type
*die_descriptive_type (struct die_info
*,
1625 struct dwarf2_cu
*);
1627 static void set_descriptive_type (struct type
*, struct die_info
*,
1628 struct dwarf2_cu
*);
1630 static struct type
*die_containing_type (struct die_info
*,
1631 struct dwarf2_cu
*);
1633 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1634 struct dwarf2_cu
*);
1636 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1638 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1640 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1642 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1643 const char *suffix
, int physname
,
1644 struct dwarf2_cu
*cu
);
1646 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1648 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1650 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1652 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1654 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1656 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1658 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1659 struct dwarf2_cu
*, struct partial_symtab
*);
1661 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1662 values. Keep the items ordered with increasing constraints compliance. */
1665 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1666 PC_BOUNDS_NOT_PRESENT
,
1668 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1669 were present but they do not form a valid range of PC addresses. */
1672 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1675 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1679 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1680 CORE_ADDR
*, CORE_ADDR
*,
1682 struct partial_symtab
*);
1684 static void get_scope_pc_bounds (struct die_info
*,
1685 CORE_ADDR
*, CORE_ADDR
*,
1686 struct dwarf2_cu
*);
1688 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1689 CORE_ADDR
, struct dwarf2_cu
*);
1691 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1692 struct dwarf2_cu
*);
1694 static void dwarf2_attach_fields_to_type (struct field_info
*,
1695 struct type
*, struct dwarf2_cu
*);
1697 static void dwarf2_add_member_fn (struct field_info
*,
1698 struct die_info
*, struct type
*,
1699 struct dwarf2_cu
*);
1701 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1703 struct dwarf2_cu
*);
1705 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1707 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1709 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1711 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1713 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1715 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1717 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1719 static struct type
*read_module_type (struct die_info
*die
,
1720 struct dwarf2_cu
*cu
);
1722 static const char *namespace_name (struct die_info
*die
,
1723 int *is_anonymous
, struct dwarf2_cu
*);
1725 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1727 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1729 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1730 struct dwarf2_cu
*);
1732 static struct die_info
*read_die_and_siblings_1
1733 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1736 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1737 const gdb_byte
*info_ptr
,
1738 const gdb_byte
**new_info_ptr
,
1739 struct die_info
*parent
);
1741 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1742 struct die_info
**, const gdb_byte
*,
1745 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1746 struct die_info
**, const gdb_byte
*,
1749 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1751 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1754 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1756 static const char *dwarf2_full_name (const char *name
,
1757 struct die_info
*die
,
1758 struct dwarf2_cu
*cu
);
1760 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1761 struct dwarf2_cu
*cu
);
1763 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1764 struct dwarf2_cu
**);
1766 static const char *dwarf_tag_name (unsigned int);
1768 static const char *dwarf_attr_name (unsigned int);
1770 static const char *dwarf_unit_type_name (int unit_type
);
1772 static const char *dwarf_form_name (unsigned int);
1774 static const char *dwarf_bool_name (unsigned int);
1776 static const char *dwarf_type_encoding_name (unsigned int);
1778 static struct die_info
*sibling_die (struct die_info
*);
1780 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1782 static void dump_die_for_error (struct die_info
*);
1784 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1787 /*static*/ void dump_die (struct die_info
*, int max_level
);
1789 static void store_in_ref_table (struct die_info
*,
1790 struct dwarf2_cu
*);
1792 static sect_offset
dwarf2_get_ref_die_offset (const struct attribute
*);
1794 static LONGEST
dwarf2_get_attr_constant_value (const struct attribute
*, int);
1796 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1797 const struct attribute
*,
1798 struct dwarf2_cu
**);
1800 static struct die_info
*follow_die_ref (struct die_info
*,
1801 const struct attribute
*,
1802 struct dwarf2_cu
**);
1804 static struct die_info
*follow_die_sig (struct die_info
*,
1805 const struct attribute
*,
1806 struct dwarf2_cu
**);
1808 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1809 struct dwarf2_cu
*);
1811 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1812 const struct attribute
*,
1813 struct dwarf2_cu
*);
1815 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1817 static void read_signatured_type (struct signatured_type
*);
1819 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1820 struct die_info
*die
, struct dwarf2_cu
*cu
,
1821 struct dynamic_prop
*prop
, struct type
*type
);
1823 /* memory allocation interface */
1825 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1827 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1829 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1831 static int attr_form_is_block (const struct attribute
*);
1833 static int attr_form_is_section_offset (const struct attribute
*);
1835 static int attr_form_is_constant (const struct attribute
*);
1837 static int attr_form_is_ref (const struct attribute
*);
1839 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1840 struct dwarf2_loclist_baton
*baton
,
1841 const struct attribute
*attr
);
1843 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1845 struct dwarf2_cu
*cu
,
1848 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1849 const gdb_byte
*info_ptr
,
1850 struct abbrev_info
*abbrev
);
1852 static hashval_t
partial_die_hash (const void *item
);
1854 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1856 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1857 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1858 struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1860 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1861 struct die_info
*comp_unit_die
,
1862 enum language pretend_language
);
1864 static void age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1866 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1868 static struct type
*set_die_type (struct die_info
*, struct type
*,
1869 struct dwarf2_cu
*);
1871 static void create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1873 static int create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1875 static void load_full_comp_unit (struct dwarf2_per_cu_data
*, bool,
1878 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1881 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1884 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1885 struct dwarf2_per_cu_data
*);
1887 static void dwarf2_mark (struct dwarf2_cu
*);
1889 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1891 static struct type
*get_die_type_at_offset (sect_offset
,
1892 struct dwarf2_per_cu_data
*);
1894 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1896 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1897 enum language pretend_language
);
1899 static void process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1901 static struct type
*dwarf2_per_cu_addr_type (struct dwarf2_per_cu_data
*per_cu
);
1902 static struct type
*dwarf2_per_cu_addr_sized_int_type
1903 (struct dwarf2_per_cu_data
*per_cu
, bool unsigned_p
);
1905 /* Class, the destructor of which frees all allocated queue entries. This
1906 will only have work to do if an error was thrown while processing the
1907 dwarf. If no error was thrown then the queue entries should have all
1908 been processed, and freed, as we went along. */
1910 class dwarf2_queue_guard
1913 dwarf2_queue_guard () = default;
1915 /* Free any entries remaining on the queue. There should only be
1916 entries left if we hit an error while processing the dwarf. */
1917 ~dwarf2_queue_guard ()
1919 struct dwarf2_queue_item
*item
, *last
;
1921 item
= dwarf2_queue
;
1924 /* Anything still marked queued is likely to be in an
1925 inconsistent state, so discard it. */
1926 if (item
->per_cu
->queued
)
1928 if (item
->per_cu
->cu
!= NULL
)
1929 free_one_cached_comp_unit (item
->per_cu
);
1930 item
->per_cu
->queued
= 0;
1938 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
1942 /* The return type of find_file_and_directory. Note, the enclosed
1943 string pointers are only valid while this object is valid. */
1945 struct file_and_directory
1947 /* The filename. This is never NULL. */
1950 /* The compilation directory. NULL if not known. If we needed to
1951 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1952 points directly to the DW_AT_comp_dir string attribute owned by
1953 the obstack that owns the DIE. */
1954 const char *comp_dir
;
1956 /* If we needed to build a new string for comp_dir, this is what
1957 owns the storage. */
1958 std::string comp_dir_storage
;
1961 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1962 struct dwarf2_cu
*cu
);
1964 static char *file_full_name (int file
, struct line_header
*lh
,
1965 const char *comp_dir
);
1967 /* Expected enum dwarf_unit_type for read_comp_unit_head. */
1968 enum class rcuh_kind
{ COMPILE
, TYPE
};
1970 static const gdb_byte
*read_and_check_comp_unit_head
1971 (struct dwarf2_per_objfile
* dwarf2_per_objfile
,
1972 struct comp_unit_head
*header
,
1973 struct dwarf2_section_info
*section
,
1974 struct dwarf2_section_info
*abbrev_section
, const gdb_byte
*info_ptr
,
1975 rcuh_kind section_kind
);
1977 static void init_cutu_and_read_dies
1978 (struct dwarf2_per_cu_data
*this_cu
, struct abbrev_table
*abbrev_table
,
1979 int use_existing_cu
, int keep
, bool skip_partial
,
1980 die_reader_func_ftype
*die_reader_func
, void *data
);
1982 static void init_cutu_and_read_dies_simple
1983 (struct dwarf2_per_cu_data
*this_cu
,
1984 die_reader_func_ftype
*die_reader_func
, void *data
);
1986 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1988 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
1990 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1991 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1992 struct dwp_file
*dwp_file
, const char *comp_dir
,
1993 ULONGEST signature
, int is_debug_types
);
1995 static struct dwp_file
*get_dwp_file
1996 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1998 static struct dwo_unit
*lookup_dwo_comp_unit
1999 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
2001 static struct dwo_unit
*lookup_dwo_type_unit
2002 (struct signatured_type
*, const char *, const char *);
2004 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
2006 /* A unique pointer to a dwo_file. */
2008 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
2010 static void process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2012 static void check_producer (struct dwarf2_cu
*cu
);
2014 static void free_line_header_voidp (void *arg
);
2016 /* Various complaints about symbol reading that don't abort the process. */
2019 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
2021 complaint (_("statement list doesn't fit in .debug_line section"));
2025 dwarf2_debug_line_missing_file_complaint (void)
2027 complaint (_(".debug_line section has line data without a file"));
2031 dwarf2_debug_line_missing_end_sequence_complaint (void)
2033 complaint (_(".debug_line section has line "
2034 "program sequence without an end"));
2038 dwarf2_complex_location_expr_complaint (void)
2040 complaint (_("location expression too complex"));
2044 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
2047 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
2052 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
2054 complaint (_("debug info runs off end of %s section"
2056 get_section_name (section
),
2057 get_section_file_name (section
));
2061 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
2063 complaint (_("macro debug info contains a "
2064 "malformed macro definition:\n`%s'"),
2069 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
2071 complaint (_("invalid attribute class or form for '%s' in '%s'"),
2075 /* Hash function for line_header_hash. */
2078 line_header_hash (const struct line_header
*ofs
)
2080 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
2083 /* Hash function for htab_create_alloc_ex for line_header_hash. */
2086 line_header_hash_voidp (const void *item
)
2088 const struct line_header
*ofs
= (const struct line_header
*) item
;
2090 return line_header_hash (ofs
);
2093 /* Equality function for line_header_hash. */
2096 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
2098 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
2099 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
2101 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
2102 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
2107 /* Read the given attribute value as an address, taking the attribute's
2108 form into account. */
2111 attr_value_as_address (struct attribute
*attr
)
2115 if (attr
->form
!= DW_FORM_addr
&& attr
->form
!= DW_FORM_addrx
2116 && attr
->form
!= DW_FORM_GNU_addr_index
)
2118 /* Aside from a few clearly defined exceptions, attributes that
2119 contain an address must always be in DW_FORM_addr form.
2120 Unfortunately, some compilers happen to be violating this
2121 requirement by encoding addresses using other forms, such
2122 as DW_FORM_data4 for example. For those broken compilers,
2123 we try to do our best, without any guarantee of success,
2124 to interpret the address correctly. It would also be nice
2125 to generate a complaint, but that would require us to maintain
2126 a list of legitimate cases where a non-address form is allowed,
2127 as well as update callers to pass in at least the CU's DWARF
2128 version. This is more overhead than what we're willing to
2129 expand for a pretty rare case. */
2130 addr
= DW_UNSND (attr
);
2133 addr
= DW_ADDR (attr
);
2138 /* See declaration. */
2140 dwarf2_per_objfile::dwarf2_per_objfile (struct objfile
*objfile_
,
2141 const dwarf2_debug_sections
*names
)
2142 : objfile (objfile_
)
2145 names
= &dwarf2_elf_names
;
2147 bfd
*obfd
= objfile
->obfd
;
2149 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
2150 locate_sections (obfd
, sec
, *names
);
2153 dwarf2_per_objfile::~dwarf2_per_objfile ()
2155 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
2156 free_cached_comp_units ();
2158 if (quick_file_names_table
)
2159 htab_delete (quick_file_names_table
);
2161 if (line_header_hash
)
2162 htab_delete (line_header_hash
);
2164 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
2165 VEC_free (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
);
2167 for (signatured_type
*sig_type
: all_type_units
)
2168 VEC_free (dwarf2_per_cu_ptr
, sig_type
->per_cu
.imported_symtabs
);
2170 /* Everything else should be on the objfile obstack. */
2173 /* See declaration. */
2176 dwarf2_per_objfile::free_cached_comp_units ()
2178 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
2179 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
2180 while (per_cu
!= NULL
)
2182 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
2185 *last_chain
= next_cu
;
2190 /* A helper class that calls free_cached_comp_units on
2193 class free_cached_comp_units
2197 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
2198 : m_per_objfile (per_objfile
)
2202 ~free_cached_comp_units ()
2204 m_per_objfile
->free_cached_comp_units ();
2207 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
2211 dwarf2_per_objfile
*m_per_objfile
;
2214 /* Try to locate the sections we need for DWARF 2 debugging
2215 information and return true if we have enough to do something.
2216 NAMES points to the dwarf2 section names, or is NULL if the standard
2217 ELF names are used. */
2220 dwarf2_has_info (struct objfile
*objfile
,
2221 const struct dwarf2_debug_sections
*names
)
2223 if (objfile
->flags
& OBJF_READNEVER
)
2226 struct dwarf2_per_objfile
*dwarf2_per_objfile
2227 = get_dwarf2_per_objfile (objfile
);
2229 if (dwarf2_per_objfile
== NULL
)
2230 dwarf2_per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
,
2233 return (!dwarf2_per_objfile
->info
.is_virtual
2234 && dwarf2_per_objfile
->info
.s
.section
!= NULL
2235 && !dwarf2_per_objfile
->abbrev
.is_virtual
2236 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
2239 /* Return the containing section of virtual section SECTION. */
2241 static struct dwarf2_section_info
*
2242 get_containing_section (const struct dwarf2_section_info
*section
)
2244 gdb_assert (section
->is_virtual
);
2245 return section
->s
.containing_section
;
2248 /* Return the bfd owner of SECTION. */
2251 get_section_bfd_owner (const struct dwarf2_section_info
*section
)
2253 if (section
->is_virtual
)
2255 section
= get_containing_section (section
);
2256 gdb_assert (!section
->is_virtual
);
2258 return section
->s
.section
->owner
;
2261 /* Return the bfd section of SECTION.
2262 Returns NULL if the section is not present. */
2265 get_section_bfd_section (const struct dwarf2_section_info
*section
)
2267 if (section
->is_virtual
)
2269 section
= get_containing_section (section
);
2270 gdb_assert (!section
->is_virtual
);
2272 return section
->s
.section
;
2275 /* Return the name of SECTION. */
2278 get_section_name (const struct dwarf2_section_info
*section
)
2280 asection
*sectp
= get_section_bfd_section (section
);
2282 gdb_assert (sectp
!= NULL
);
2283 return bfd_section_name (sectp
);
2286 /* Return the name of the file SECTION is in. */
2289 get_section_file_name (const struct dwarf2_section_info
*section
)
2291 bfd
*abfd
= get_section_bfd_owner (section
);
2293 return bfd_get_filename (abfd
);
2296 /* Return the id of SECTION.
2297 Returns 0 if SECTION doesn't exist. */
2300 get_section_id (const struct dwarf2_section_info
*section
)
2302 asection
*sectp
= get_section_bfd_section (section
);
2309 /* Return the flags of SECTION.
2310 SECTION (or containing section if this is a virtual section) must exist. */
2313 get_section_flags (const struct dwarf2_section_info
*section
)
2315 asection
*sectp
= get_section_bfd_section (section
);
2317 gdb_assert (sectp
!= NULL
);
2318 return bfd_section_flags (sectp
);
2321 /* When loading sections, we look either for uncompressed section or for
2322 compressed section names. */
2325 section_is_p (const char *section_name
,
2326 const struct dwarf2_section_names
*names
)
2328 if (names
->normal
!= NULL
2329 && strcmp (section_name
, names
->normal
) == 0)
2331 if (names
->compressed
!= NULL
2332 && strcmp (section_name
, names
->compressed
) == 0)
2337 /* See declaration. */
2340 dwarf2_per_objfile::locate_sections (bfd
*abfd
, asection
*sectp
,
2341 const dwarf2_debug_sections
&names
)
2343 flagword aflag
= bfd_section_flags (sectp
);
2345 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
2348 else if (section_is_p (sectp
->name
, &names
.info
))
2350 this->info
.s
.section
= sectp
;
2351 this->info
.size
= bfd_section_size (sectp
);
2353 else if (section_is_p (sectp
->name
, &names
.abbrev
))
2355 this->abbrev
.s
.section
= sectp
;
2356 this->abbrev
.size
= bfd_section_size (sectp
);
2358 else if (section_is_p (sectp
->name
, &names
.line
))
2360 this->line
.s
.section
= sectp
;
2361 this->line
.size
= bfd_section_size (sectp
);
2363 else if (section_is_p (sectp
->name
, &names
.loc
))
2365 this->loc
.s
.section
= sectp
;
2366 this->loc
.size
= bfd_section_size (sectp
);
2368 else if (section_is_p (sectp
->name
, &names
.loclists
))
2370 this->loclists
.s
.section
= sectp
;
2371 this->loclists
.size
= bfd_section_size (sectp
);
2373 else if (section_is_p (sectp
->name
, &names
.macinfo
))
2375 this->macinfo
.s
.section
= sectp
;
2376 this->macinfo
.size
= bfd_section_size (sectp
);
2378 else if (section_is_p (sectp
->name
, &names
.macro
))
2380 this->macro
.s
.section
= sectp
;
2381 this->macro
.size
= bfd_section_size (sectp
);
2383 else if (section_is_p (sectp
->name
, &names
.str
))
2385 this->str
.s
.section
= sectp
;
2386 this->str
.size
= bfd_section_size (sectp
);
2388 else if (section_is_p (sectp
->name
, &names
.line_str
))
2390 this->line_str
.s
.section
= sectp
;
2391 this->line_str
.size
= bfd_section_size (sectp
);
2393 else if (section_is_p (sectp
->name
, &names
.addr
))
2395 this->addr
.s
.section
= sectp
;
2396 this->addr
.size
= bfd_section_size (sectp
);
2398 else if (section_is_p (sectp
->name
, &names
.frame
))
2400 this->frame
.s
.section
= sectp
;
2401 this->frame
.size
= bfd_section_size (sectp
);
2403 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
2405 this->eh_frame
.s
.section
= sectp
;
2406 this->eh_frame
.size
= bfd_section_size (sectp
);
2408 else if (section_is_p (sectp
->name
, &names
.ranges
))
2410 this->ranges
.s
.section
= sectp
;
2411 this->ranges
.size
= bfd_section_size (sectp
);
2413 else if (section_is_p (sectp
->name
, &names
.rnglists
))
2415 this->rnglists
.s
.section
= sectp
;
2416 this->rnglists
.size
= bfd_section_size (sectp
);
2418 else if (section_is_p (sectp
->name
, &names
.types
))
2420 struct dwarf2_section_info type_section
;
2422 memset (&type_section
, 0, sizeof (type_section
));
2423 type_section
.s
.section
= sectp
;
2424 type_section
.size
= bfd_section_size (sectp
);
2426 this->types
.push_back (type_section
);
2428 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
2430 this->gdb_index
.s
.section
= sectp
;
2431 this->gdb_index
.size
= bfd_section_size (sectp
);
2433 else if (section_is_p (sectp
->name
, &names
.debug_names
))
2435 this->debug_names
.s
.section
= sectp
;
2436 this->debug_names
.size
= bfd_section_size (sectp
);
2438 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
2440 this->debug_aranges
.s
.section
= sectp
;
2441 this->debug_aranges
.size
= bfd_section_size (sectp
);
2444 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2445 && bfd_section_vma (sectp
) == 0)
2446 this->has_section_at_zero
= true;
2449 /* A helper function that decides whether a section is empty,
2453 dwarf2_section_empty_p (const struct dwarf2_section_info
*section
)
2455 if (section
->is_virtual
)
2456 return section
->size
== 0;
2457 return section
->s
.section
== NULL
|| section
->size
== 0;
2460 /* See dwarf2read.h. */
2463 dwarf2_read_section (struct objfile
*objfile
, dwarf2_section_info
*info
)
2467 gdb_byte
*buf
, *retbuf
;
2471 info
->buffer
= NULL
;
2472 info
->readin
= true;
2474 if (dwarf2_section_empty_p (info
))
2477 sectp
= get_section_bfd_section (info
);
2479 /* If this is a virtual section we need to read in the real one first. */
2480 if (info
->is_virtual
)
2482 struct dwarf2_section_info
*containing_section
=
2483 get_containing_section (info
);
2485 gdb_assert (sectp
!= NULL
);
2486 if ((sectp
->flags
& SEC_RELOC
) != 0)
2488 error (_("Dwarf Error: DWP format V2 with relocations is not"
2489 " supported in section %s [in module %s]"),
2490 get_section_name (info
), get_section_file_name (info
));
2492 dwarf2_read_section (objfile
, containing_section
);
2493 /* Other code should have already caught virtual sections that don't
2495 gdb_assert (info
->virtual_offset
+ info
->size
2496 <= containing_section
->size
);
2497 /* If the real section is empty or there was a problem reading the
2498 section we shouldn't get here. */
2499 gdb_assert (containing_section
->buffer
!= NULL
);
2500 info
->buffer
= containing_section
->buffer
+ info
->virtual_offset
;
2504 /* If the section has relocations, we must read it ourselves.
2505 Otherwise we attach it to the BFD. */
2506 if ((sectp
->flags
& SEC_RELOC
) == 0)
2508 info
->buffer
= gdb_bfd_map_section (sectp
, &info
->size
);
2512 buf
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
2515 /* When debugging .o files, we may need to apply relocations; see
2516 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
2517 We never compress sections in .o files, so we only need to
2518 try this when the section is not compressed. */
2519 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
2522 info
->buffer
= retbuf
;
2526 abfd
= get_section_bfd_owner (info
);
2527 gdb_assert (abfd
!= NULL
);
2529 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
2530 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
2532 error (_("Dwarf Error: Can't read DWARF data"
2533 " in section %s [in module %s]"),
2534 bfd_section_name (sectp
), bfd_get_filename (abfd
));
2538 /* A helper function that returns the size of a section in a safe way.
2539 If you are positive that the section has been read before using the
2540 size, then it is safe to refer to the dwarf2_section_info object's
2541 "size" field directly. In other cases, you must call this
2542 function, because for compressed sections the size field is not set
2543 correctly until the section has been read. */
2545 static bfd_size_type
2546 dwarf2_section_size (struct objfile
*objfile
,
2547 struct dwarf2_section_info
*info
)
2550 dwarf2_read_section (objfile
, info
);
2554 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2558 dwarf2_get_section_info (struct objfile
*objfile
,
2559 enum dwarf2_section_enum sect
,
2560 asection
**sectp
, const gdb_byte
**bufp
,
2561 bfd_size_type
*sizep
)
2563 struct dwarf2_per_objfile
*data
= dwarf2_objfile_data_key
.get (objfile
);
2564 struct dwarf2_section_info
*info
;
2566 /* We may see an objfile without any DWARF, in which case we just
2577 case DWARF2_DEBUG_FRAME
:
2578 info
= &data
->frame
;
2580 case DWARF2_EH_FRAME
:
2581 info
= &data
->eh_frame
;
2584 gdb_assert_not_reached ("unexpected section");
2587 dwarf2_read_section (objfile
, info
);
2589 *sectp
= get_section_bfd_section (info
);
2590 *bufp
= info
->buffer
;
2591 *sizep
= info
->size
;
2594 /* A helper function to find the sections for a .dwz file. */
2597 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2599 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2601 /* Note that we only support the standard ELF names, because .dwz
2602 is ELF-only (at the time of writing). */
2603 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2605 dwz_file
->abbrev
.s
.section
= sectp
;
2606 dwz_file
->abbrev
.size
= bfd_section_size (sectp
);
2608 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2610 dwz_file
->info
.s
.section
= sectp
;
2611 dwz_file
->info
.size
= bfd_section_size (sectp
);
2613 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2615 dwz_file
->str
.s
.section
= sectp
;
2616 dwz_file
->str
.size
= bfd_section_size (sectp
);
2618 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2620 dwz_file
->line
.s
.section
= sectp
;
2621 dwz_file
->line
.size
= bfd_section_size (sectp
);
2623 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2625 dwz_file
->macro
.s
.section
= sectp
;
2626 dwz_file
->macro
.size
= bfd_section_size (sectp
);
2628 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2630 dwz_file
->gdb_index
.s
.section
= sectp
;
2631 dwz_file
->gdb_index
.size
= bfd_section_size (sectp
);
2633 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2635 dwz_file
->debug_names
.s
.section
= sectp
;
2636 dwz_file
->debug_names
.size
= bfd_section_size (sectp
);
2640 /* See dwarf2read.h. */
2643 dwarf2_get_dwz_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
2645 const char *filename
;
2646 bfd_size_type buildid_len_arg
;
2650 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2651 return dwarf2_per_objfile
->dwz_file
.get ();
2653 bfd_set_error (bfd_error_no_error
);
2654 gdb::unique_xmalloc_ptr
<char> data
2655 (bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2656 &buildid_len_arg
, &buildid
));
2659 if (bfd_get_error () == bfd_error_no_error
)
2661 error (_("could not read '.gnu_debugaltlink' section: %s"),
2662 bfd_errmsg (bfd_get_error ()));
2665 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2667 buildid_len
= (size_t) buildid_len_arg
;
2669 filename
= data
.get ();
2671 std::string abs_storage
;
2672 if (!IS_ABSOLUTE_PATH (filename
))
2674 gdb::unique_xmalloc_ptr
<char> abs
2675 = gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2677 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2678 filename
= abs_storage
.c_str ();
2681 /* First try the file name given in the section. If that doesn't
2682 work, try to use the build-id instead. */
2683 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
, -1));
2684 if (dwz_bfd
!= NULL
)
2686 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2687 dwz_bfd
.reset (nullptr);
2690 if (dwz_bfd
== NULL
)
2691 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2693 if (dwz_bfd
== NULL
)
2694 error (_("could not find '.gnu_debugaltlink' file for %s"),
2695 objfile_name (dwarf2_per_objfile
->objfile
));
2697 std::unique_ptr
<struct dwz_file
> result
2698 (new struct dwz_file (std::move (dwz_bfd
)));
2700 bfd_map_over_sections (result
->dwz_bfd
.get (), locate_dwz_sections
,
2703 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
,
2704 result
->dwz_bfd
.get ());
2705 dwarf2_per_objfile
->dwz_file
= std::move (result
);
2706 return dwarf2_per_objfile
->dwz_file
.get ();
2709 /* DWARF quick_symbols_functions support. */
2711 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2712 unique line tables, so we maintain a separate table of all .debug_line
2713 derived entries to support the sharing.
2714 All the quick functions need is the list of file names. We discard the
2715 line_header when we're done and don't need to record it here. */
2716 struct quick_file_names
2718 /* The data used to construct the hash key. */
2719 struct stmt_list_hash hash
;
2721 /* The number of entries in file_names, real_names. */
2722 unsigned int num_file_names
;
2724 /* The file names from the line table, after being run through
2726 const char **file_names
;
2728 /* The file names from the line table after being run through
2729 gdb_realpath. These are computed lazily. */
2730 const char **real_names
;
2733 /* When using the index (and thus not using psymtabs), each CU has an
2734 object of this type. This is used to hold information needed by
2735 the various "quick" methods. */
2736 struct dwarf2_per_cu_quick_data
2738 /* The file table. This can be NULL if there was no file table
2739 or it's currently not read in.
2740 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2741 struct quick_file_names
*file_names
;
2743 /* The corresponding symbol table. This is NULL if symbols for this
2744 CU have not yet been read. */
2745 struct compunit_symtab
*compunit_symtab
;
2747 /* A temporary mark bit used when iterating over all CUs in
2748 expand_symtabs_matching. */
2749 unsigned int mark
: 1;
2751 /* True if we've tried to read the file table and found there isn't one.
2752 There will be no point in trying to read it again next time. */
2753 unsigned int no_file_data
: 1;
2756 /* Utility hash function for a stmt_list_hash. */
2759 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2763 if (stmt_list_hash
->dwo_unit
!= NULL
)
2764 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2765 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2769 /* Utility equality function for a stmt_list_hash. */
2772 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2773 const struct stmt_list_hash
*rhs
)
2775 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2777 if (lhs
->dwo_unit
!= NULL
2778 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2781 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2784 /* Hash function for a quick_file_names. */
2787 hash_file_name_entry (const void *e
)
2789 const struct quick_file_names
*file_data
2790 = (const struct quick_file_names
*) e
;
2792 return hash_stmt_list_entry (&file_data
->hash
);
2795 /* Equality function for a quick_file_names. */
2798 eq_file_name_entry (const void *a
, const void *b
)
2800 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2801 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2803 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2806 /* Delete function for a quick_file_names. */
2809 delete_file_name_entry (void *e
)
2811 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2814 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2816 xfree ((void*) file_data
->file_names
[i
]);
2817 if (file_data
->real_names
)
2818 xfree ((void*) file_data
->real_names
[i
]);
2821 /* The space for the struct itself lives on objfile_obstack,
2822 so we don't free it here. */
2825 /* Create a quick_file_names hash table. */
2828 create_quick_file_names_table (unsigned int nr_initial_entries
)
2830 return htab_create_alloc (nr_initial_entries
,
2831 hash_file_name_entry
, eq_file_name_entry
,
2832 delete_file_name_entry
, xcalloc
, xfree
);
2835 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2836 have to be created afterwards. You should call age_cached_comp_units after
2837 processing PER_CU->CU. dw2_setup must have been already called. */
2840 load_cu (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2842 if (per_cu
->is_debug_types
)
2843 load_full_type_unit (per_cu
);
2845 load_full_comp_unit (per_cu
, skip_partial
, language_minimal
);
2847 if (per_cu
->cu
== NULL
)
2848 return; /* Dummy CU. */
2850 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2853 /* Read in the symbols for PER_CU. */
2856 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2858 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2860 /* Skip type_unit_groups, reading the type units they contain
2861 is handled elsewhere. */
2862 if (IS_TYPE_UNIT_GROUP (per_cu
))
2865 /* The destructor of dwarf2_queue_guard frees any entries left on
2866 the queue. After this point we're guaranteed to leave this function
2867 with the dwarf queue empty. */
2868 dwarf2_queue_guard q_guard
;
2870 if (dwarf2_per_objfile
->using_index
2871 ? per_cu
->v
.quick
->compunit_symtab
== NULL
2872 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2874 queue_comp_unit (per_cu
, language_minimal
);
2875 load_cu (per_cu
, skip_partial
);
2877 /* If we just loaded a CU from a DWO, and we're working with an index
2878 that may badly handle TUs, load all the TUs in that DWO as well.
2879 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2880 if (!per_cu
->is_debug_types
2881 && per_cu
->cu
!= NULL
2882 && per_cu
->cu
->dwo_unit
!= NULL
2883 && dwarf2_per_objfile
->index_table
!= NULL
2884 && dwarf2_per_objfile
->index_table
->version
<= 7
2885 /* DWP files aren't supported yet. */
2886 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
2887 queue_and_load_all_dwo_tus (per_cu
);
2890 process_queue (dwarf2_per_objfile
);
2892 /* Age the cache, releasing compilation units that have not
2893 been used recently. */
2894 age_cached_comp_units (dwarf2_per_objfile
);
2897 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2898 the objfile from which this CU came. Returns the resulting symbol
2901 static struct compunit_symtab
*
2902 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2904 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2906 gdb_assert (dwarf2_per_objfile
->using_index
);
2907 if (!per_cu
->v
.quick
->compunit_symtab
)
2909 free_cached_comp_units
freer (dwarf2_per_objfile
);
2910 scoped_restore decrementer
= increment_reading_symtab ();
2911 dw2_do_instantiate_symtab (per_cu
, skip_partial
);
2912 process_cu_includes (dwarf2_per_objfile
);
2915 return per_cu
->v
.quick
->compunit_symtab
;
2918 /* See declaration. */
2920 dwarf2_per_cu_data
*
2921 dwarf2_per_objfile::get_cutu (int index
)
2923 if (index
>= this->all_comp_units
.size ())
2925 index
-= this->all_comp_units
.size ();
2926 gdb_assert (index
< this->all_type_units
.size ());
2927 return &this->all_type_units
[index
]->per_cu
;
2930 return this->all_comp_units
[index
];
2933 /* See declaration. */
2935 dwarf2_per_cu_data
*
2936 dwarf2_per_objfile::get_cu (int index
)
2938 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2940 return this->all_comp_units
[index
];
2943 /* See declaration. */
2946 dwarf2_per_objfile::get_tu (int index
)
2948 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2950 return this->all_type_units
[index
];
2953 /* Return a new dwarf2_per_cu_data allocated on OBJFILE's
2954 objfile_obstack, and constructed with the specified field
2957 static dwarf2_per_cu_data
*
2958 create_cu_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2959 struct dwarf2_section_info
*section
,
2961 sect_offset sect_off
, ULONGEST length
)
2963 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2964 dwarf2_per_cu_data
*the_cu
2965 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2966 struct dwarf2_per_cu_data
);
2967 the_cu
->sect_off
= sect_off
;
2968 the_cu
->length
= length
;
2969 the_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
2970 the_cu
->section
= section
;
2971 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2972 struct dwarf2_per_cu_quick_data
);
2973 the_cu
->is_dwz
= is_dwz
;
2977 /* A helper for create_cus_from_index that handles a given list of
2981 create_cus_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2982 const gdb_byte
*cu_list
, offset_type n_elements
,
2983 struct dwarf2_section_info
*section
,
2986 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2988 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2990 sect_offset sect_off
2991 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2992 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2995 dwarf2_per_cu_data
*per_cu
2996 = create_cu_from_index_list (dwarf2_per_objfile
, section
, is_dwz
,
2998 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
3002 /* Read the CU list from the mapped index, and use it to create all
3003 the CU objects for this objfile. */
3006 create_cus_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3007 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
3008 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
3010 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
3011 dwarf2_per_objfile
->all_comp_units
.reserve
3012 ((cu_list_elements
+ dwz_elements
) / 2);
3014 create_cus_from_index_list (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3015 &dwarf2_per_objfile
->info
, 0);
3017 if (dwz_elements
== 0)
3020 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3021 create_cus_from_index_list (dwarf2_per_objfile
, dwz_list
, dwz_elements
,
3025 /* Create the signatured type hash table from the index. */
3028 create_signatured_type_table_from_index
3029 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3030 struct dwarf2_section_info
*section
,
3031 const gdb_byte
*bytes
,
3032 offset_type elements
)
3034 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3036 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
3037 dwarf2_per_objfile
->all_type_units
.reserve (elements
/ 3);
3039 htab_t sig_types_hash
= allocate_signatured_type_table (objfile
);
3041 for (offset_type i
= 0; i
< elements
; i
+= 3)
3043 struct signatured_type
*sig_type
;
3046 cu_offset type_offset_in_tu
;
3048 gdb_static_assert (sizeof (ULONGEST
) >= 8);
3049 sect_offset sect_off
3050 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
3052 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
3054 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
3057 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3058 struct signatured_type
);
3059 sig_type
->signature
= signature
;
3060 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
3061 sig_type
->per_cu
.is_debug_types
= 1;
3062 sig_type
->per_cu
.section
= section
;
3063 sig_type
->per_cu
.sect_off
= sect_off
;
3064 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
3065 sig_type
->per_cu
.v
.quick
3066 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3067 struct dwarf2_per_cu_quick_data
);
3069 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3072 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
3075 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3078 /* Create the signatured type hash table from .debug_names. */
3081 create_signatured_type_table_from_debug_names
3082 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3083 const mapped_debug_names
&map
,
3084 struct dwarf2_section_info
*section
,
3085 struct dwarf2_section_info
*abbrev_section
)
3087 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3089 dwarf2_read_section (objfile
, section
);
3090 dwarf2_read_section (objfile
, abbrev_section
);
3092 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
3093 dwarf2_per_objfile
->all_type_units
.reserve (map
.tu_count
);
3095 htab_t sig_types_hash
= allocate_signatured_type_table (objfile
);
3097 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
3099 struct signatured_type
*sig_type
;
3102 sect_offset sect_off
3103 = (sect_offset
) (extract_unsigned_integer
3104 (map
.tu_table_reordered
+ i
* map
.offset_size
,
3106 map
.dwarf5_byte_order
));
3108 comp_unit_head cu_header
;
3109 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
3111 section
->buffer
+ to_underlying (sect_off
),
3114 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3115 struct signatured_type
);
3116 sig_type
->signature
= cu_header
.signature
;
3117 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
3118 sig_type
->per_cu
.is_debug_types
= 1;
3119 sig_type
->per_cu
.section
= section
;
3120 sig_type
->per_cu
.sect_off
= sect_off
;
3121 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
3122 sig_type
->per_cu
.v
.quick
3123 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3124 struct dwarf2_per_cu_quick_data
);
3126 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3129 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
3132 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3135 /* Read the address map data from the mapped index, and use it to
3136 populate the objfile's psymtabs_addrmap. */
3139 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3140 struct mapped_index
*index
)
3142 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3143 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3144 const gdb_byte
*iter
, *end
;
3145 struct addrmap
*mutable_map
;
3148 auto_obstack temp_obstack
;
3150 mutable_map
= addrmap_create_mutable (&temp_obstack
);
3152 iter
= index
->address_table
.data ();
3153 end
= iter
+ index
->address_table
.size ();
3155 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3159 ULONGEST hi
, lo
, cu_index
;
3160 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3162 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3164 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
3169 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
3170 hex_string (lo
), hex_string (hi
));
3174 if (cu_index
>= dwarf2_per_objfile
->all_comp_units
.size ())
3176 complaint (_(".gdb_index address table has invalid CU number %u"),
3177 (unsigned) cu_index
);
3181 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
3182 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
3183 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
3184 dwarf2_per_objfile
->get_cu (cu_index
));
3187 objfile
->partial_symtabs
->psymtabs_addrmap
3188 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
3191 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
3192 populate the objfile's psymtabs_addrmap. */
3195 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3196 struct dwarf2_section_info
*section
)
3198 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3199 bfd
*abfd
= objfile
->obfd
;
3200 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3201 const CORE_ADDR baseaddr
= ANOFFSET (objfile
->section_offsets
,
3202 SECT_OFF_TEXT (objfile
));
3204 auto_obstack temp_obstack
;
3205 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
3207 std::unordered_map
<sect_offset
,
3208 dwarf2_per_cu_data
*,
3209 gdb::hash_enum
<sect_offset
>>
3210 debug_info_offset_to_per_cu
;
3211 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3213 const auto insertpair
3214 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
3215 if (!insertpair
.second
)
3217 warning (_("Section .debug_aranges in %s has duplicate "
3218 "debug_info_offset %s, ignoring .debug_aranges."),
3219 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
3224 dwarf2_read_section (objfile
, section
);
3226 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
3228 const gdb_byte
*addr
= section
->buffer
;
3230 while (addr
< section
->buffer
+ section
->size
)
3232 const gdb_byte
*const entry_addr
= addr
;
3233 unsigned int bytes_read
;
3235 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
3239 const gdb_byte
*const entry_end
= addr
+ entry_length
;
3240 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
3241 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
3242 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
3244 warning (_("Section .debug_aranges in %s entry at offset %s "
3245 "length %s exceeds section length %s, "
3246 "ignoring .debug_aranges."),
3247 objfile_name (objfile
),
3248 plongest (entry_addr
- section
->buffer
),
3249 plongest (bytes_read
+ entry_length
),
3250 pulongest (section
->size
));
3254 /* The version number. */
3255 const uint16_t version
= read_2_bytes (abfd
, addr
);
3259 warning (_("Section .debug_aranges in %s entry at offset %s "
3260 "has unsupported version %d, ignoring .debug_aranges."),
3261 objfile_name (objfile
),
3262 plongest (entry_addr
- section
->buffer
), version
);
3266 const uint64_t debug_info_offset
3267 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
3268 addr
+= offset_size
;
3269 const auto per_cu_it
3270 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
3271 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
3273 warning (_("Section .debug_aranges in %s entry at offset %s "
3274 "debug_info_offset %s does not exists, "
3275 "ignoring .debug_aranges."),
3276 objfile_name (objfile
),
3277 plongest (entry_addr
- section
->buffer
),
3278 pulongest (debug_info_offset
));
3281 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
3283 const uint8_t address_size
= *addr
++;
3284 if (address_size
< 1 || address_size
> 8)
3286 warning (_("Section .debug_aranges in %s entry at offset %s "
3287 "address_size %u is invalid, ignoring .debug_aranges."),
3288 objfile_name (objfile
),
3289 plongest (entry_addr
- section
->buffer
), address_size
);
3293 const uint8_t segment_selector_size
= *addr
++;
3294 if (segment_selector_size
!= 0)
3296 warning (_("Section .debug_aranges in %s entry at offset %s "
3297 "segment_selector_size %u is not supported, "
3298 "ignoring .debug_aranges."),
3299 objfile_name (objfile
),
3300 plongest (entry_addr
- section
->buffer
),
3301 segment_selector_size
);
3305 /* Must pad to an alignment boundary that is twice the address
3306 size. It is undocumented by the DWARF standard but GCC does
3308 for (size_t padding
= ((-(addr
- section
->buffer
))
3309 & (2 * address_size
- 1));
3310 padding
> 0; padding
--)
3313 warning (_("Section .debug_aranges in %s entry at offset %s "
3314 "padding is not zero, ignoring .debug_aranges."),
3315 objfile_name (objfile
),
3316 plongest (entry_addr
- section
->buffer
));
3322 if (addr
+ 2 * address_size
> entry_end
)
3324 warning (_("Section .debug_aranges in %s entry at offset %s "
3325 "address list is not properly terminated, "
3326 "ignoring .debug_aranges."),
3327 objfile_name (objfile
),
3328 plongest (entry_addr
- section
->buffer
));
3331 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
3333 addr
+= address_size
;
3334 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
3336 addr
+= address_size
;
3337 if (start
== 0 && length
== 0)
3339 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
3341 /* Symbol was eliminated due to a COMDAT group. */
3344 ULONGEST end
= start
+ length
;
3345 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
3347 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
3349 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
3353 objfile
->partial_symtabs
->psymtabs_addrmap
3354 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
3357 /* Find a slot in the mapped index INDEX for the object named NAME.
3358 If NAME is found, set *VEC_OUT to point to the CU vector in the
3359 constant pool and return true. If NAME cannot be found, return
3363 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
3364 offset_type
**vec_out
)
3367 offset_type slot
, step
;
3368 int (*cmp
) (const char *, const char *);
3370 gdb::unique_xmalloc_ptr
<char> without_params
;
3371 if (current_language
->la_language
== language_cplus
3372 || current_language
->la_language
== language_fortran
3373 || current_language
->la_language
== language_d
)
3375 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
3378 if (strchr (name
, '(') != NULL
)
3380 without_params
= cp_remove_params (name
);
3382 if (without_params
!= NULL
)
3383 name
= without_params
.get ();
3387 /* Index version 4 did not support case insensitive searches. But the
3388 indices for case insensitive languages are built in lowercase, therefore
3389 simulate our NAME being searched is also lowercased. */
3390 hash
= mapped_index_string_hash ((index
->version
== 4
3391 && case_sensitivity
== case_sensitive_off
3392 ? 5 : index
->version
),
3395 slot
= hash
& (index
->symbol_table
.size () - 1);
3396 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
3397 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
3403 const auto &bucket
= index
->symbol_table
[slot
];
3404 if (bucket
.name
== 0 && bucket
.vec
== 0)
3407 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
3408 if (!cmp (name
, str
))
3410 *vec_out
= (offset_type
*) (index
->constant_pool
3411 + MAYBE_SWAP (bucket
.vec
));
3415 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
3419 /* A helper function that reads the .gdb_index from BUFFER and fills
3420 in MAP. FILENAME is the name of the file containing the data;
3421 it is used for error reporting. DEPRECATED_OK is true if it is
3422 ok to use deprecated sections.
3424 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
3425 out parameters that are filled in with information about the CU and
3426 TU lists in the section.
3428 Returns true if all went well, false otherwise. */
3431 read_gdb_index_from_buffer (struct objfile
*objfile
,
3432 const char *filename
,
3434 gdb::array_view
<const gdb_byte
> buffer
,
3435 struct mapped_index
*map
,
3436 const gdb_byte
**cu_list
,
3437 offset_type
*cu_list_elements
,
3438 const gdb_byte
**types_list
,
3439 offset_type
*types_list_elements
)
3441 const gdb_byte
*addr
= &buffer
[0];
3443 /* Version check. */
3444 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
3445 /* Versions earlier than 3 emitted every copy of a psymbol. This
3446 causes the index to behave very poorly for certain requests. Version 3
3447 contained incomplete addrmap. So, it seems better to just ignore such
3451 static int warning_printed
= 0;
3452 if (!warning_printed
)
3454 warning (_("Skipping obsolete .gdb_index section in %s."),
3456 warning_printed
= 1;
3460 /* Index version 4 uses a different hash function than index version
3463 Versions earlier than 6 did not emit psymbols for inlined
3464 functions. Using these files will cause GDB not to be able to
3465 set breakpoints on inlined functions by name, so we ignore these
3466 indices unless the user has done
3467 "set use-deprecated-index-sections on". */
3468 if (version
< 6 && !deprecated_ok
)
3470 static int warning_printed
= 0;
3471 if (!warning_printed
)
3474 Skipping deprecated .gdb_index section in %s.\n\
3475 Do \"set use-deprecated-index-sections on\" before the file is read\n\
3476 to use the section anyway."),
3478 warning_printed
= 1;
3482 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3483 of the TU (for symbols coming from TUs),
3484 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3485 Plus gold-generated indices can have duplicate entries for global symbols,
3486 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3487 These are just performance bugs, and we can't distinguish gdb-generated
3488 indices from gold-generated ones, so issue no warning here. */
3490 /* Indexes with higher version than the one supported by GDB may be no
3491 longer backward compatible. */
3495 map
->version
= version
;
3497 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3500 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3501 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3505 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3506 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3507 - MAYBE_SWAP (metadata
[i
]))
3511 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3512 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3514 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
3517 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3518 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3520 = gdb::array_view
<mapped_index::symbol_table_slot
>
3521 ((mapped_index::symbol_table_slot
*) symbol_table
,
3522 (mapped_index::symbol_table_slot
*) symbol_table_end
);
3525 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3530 /* Callback types for dwarf2_read_gdb_index. */
3532 typedef gdb::function_view
3533 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_objfile
*)>
3534 get_gdb_index_contents_ftype
;
3535 typedef gdb::function_view
3536 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
3537 get_gdb_index_contents_dwz_ftype
;
3539 /* Read .gdb_index. If everything went ok, initialize the "quick"
3540 elements of all the CUs and return 1. Otherwise, return 0. */
3543 dwarf2_read_gdb_index
3544 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3545 get_gdb_index_contents_ftype get_gdb_index_contents
,
3546 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
3548 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3549 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3550 struct dwz_file
*dwz
;
3551 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3553 gdb::array_view
<const gdb_byte
> main_index_contents
3554 = get_gdb_index_contents (objfile
, dwarf2_per_objfile
);
3556 if (main_index_contents
.empty ())
3559 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3560 if (!read_gdb_index_from_buffer (objfile
, objfile_name (objfile
),
3561 use_deprecated_index_sections
,
3562 main_index_contents
, map
.get (), &cu_list
,
3563 &cu_list_elements
, &types_list
,
3564 &types_list_elements
))
3567 /* Don't use the index if it's empty. */
3568 if (map
->symbol_table
.empty ())
3571 /* If there is a .dwz file, read it so we can get its CU list as
3573 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3576 struct mapped_index dwz_map
;
3577 const gdb_byte
*dwz_types_ignore
;
3578 offset_type dwz_types_elements_ignore
;
3580 gdb::array_view
<const gdb_byte
> dwz_index_content
3581 = get_gdb_index_contents_dwz (objfile
, dwz
);
3583 if (dwz_index_content
.empty ())
3586 if (!read_gdb_index_from_buffer (objfile
,
3587 bfd_get_filename (dwz
->dwz_bfd
.get ()),
3588 1, dwz_index_content
, &dwz_map
,
3589 &dwz_list
, &dwz_list_elements
,
3591 &dwz_types_elements_ignore
))
3593 warning (_("could not read '.gdb_index' section from %s; skipping"),
3594 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3599 create_cus_from_index (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3600 dwz_list
, dwz_list_elements
);
3602 if (types_list_elements
)
3604 /* We can only handle a single .debug_types when we have an
3606 if (dwarf2_per_objfile
->types
.size () != 1)
3609 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
3611 create_signatured_type_table_from_index (dwarf2_per_objfile
, section
,
3612 types_list
, types_list_elements
);
3615 create_addrmap_from_index (dwarf2_per_objfile
, map
.get ());
3617 dwarf2_per_objfile
->index_table
= std::move (map
);
3618 dwarf2_per_objfile
->using_index
= 1;
3619 dwarf2_per_objfile
->quick_file_names_table
=
3620 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
3625 /* die_reader_func for dw2_get_file_names. */
3628 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3629 const gdb_byte
*info_ptr
,
3630 struct die_info
*comp_unit_die
,
3634 struct dwarf2_cu
*cu
= reader
->cu
;
3635 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3636 struct dwarf2_per_objfile
*dwarf2_per_objfile
3637 = cu
->per_cu
->dwarf2_per_objfile
;
3638 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3639 struct dwarf2_per_cu_data
*lh_cu
;
3640 struct attribute
*attr
;
3643 struct quick_file_names
*qfn
;
3645 gdb_assert (! this_cu
->is_debug_types
);
3647 /* Our callers never want to match partial units -- instead they
3648 will match the enclosing full CU. */
3649 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3651 this_cu
->v
.quick
->no_file_data
= 1;
3659 sect_offset line_offset
{};
3661 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3664 struct quick_file_names find_entry
;
3666 line_offset
= (sect_offset
) DW_UNSND (attr
);
3668 /* We may have already read in this line header (TU line header sharing).
3669 If we have we're done. */
3670 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3671 find_entry
.hash
.line_sect_off
= line_offset
;
3672 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
3673 &find_entry
, INSERT
);
3676 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3680 lh
= dwarf_decode_line_header (line_offset
, cu
);
3684 lh_cu
->v
.quick
->no_file_data
= 1;
3688 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
3689 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3690 qfn
->hash
.line_sect_off
= line_offset
;
3691 gdb_assert (slot
!= NULL
);
3694 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3697 if (strcmp (fnd
.name
, "<unknown>") != 0)
3700 qfn
->num_file_names
= offset
+ lh
->file_names
.size ();
3702 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, qfn
->num_file_names
);
3704 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3705 for (i
= 0; i
< lh
->file_names
.size (); ++i
)
3706 qfn
->file_names
[i
+ offset
] = file_full_name (i
+ 1, lh
.get (), fnd
.comp_dir
);
3707 qfn
->real_names
= NULL
;
3709 lh_cu
->v
.quick
->file_names
= qfn
;
3712 /* A helper for the "quick" functions which attempts to read the line
3713 table for THIS_CU. */
3715 static struct quick_file_names
*
3716 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3718 /* This should never be called for TUs. */
3719 gdb_assert (! this_cu
->is_debug_types
);
3720 /* Nor type unit groups. */
3721 gdb_assert (! IS_TYPE_UNIT_GROUP (this_cu
));
3723 if (this_cu
->v
.quick
->file_names
!= NULL
)
3724 return this_cu
->v
.quick
->file_names
;
3725 /* If we know there is no line data, no point in looking again. */
3726 if (this_cu
->v
.quick
->no_file_data
)
3729 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
3731 if (this_cu
->v
.quick
->no_file_data
)
3733 return this_cu
->v
.quick
->file_names
;
3736 /* A helper for the "quick" functions which computes and caches the
3737 real path for a given file name from the line table. */
3740 dw2_get_real_path (struct objfile
*objfile
,
3741 struct quick_file_names
*qfn
, int index
)
3743 if (qfn
->real_names
== NULL
)
3744 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3745 qfn
->num_file_names
, const char *);
3747 if (qfn
->real_names
[index
] == NULL
)
3748 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3750 return qfn
->real_names
[index
];
3753 static struct symtab
*
3754 dw2_find_last_source_symtab (struct objfile
*objfile
)
3756 struct dwarf2_per_objfile
*dwarf2_per_objfile
3757 = get_dwarf2_per_objfile (objfile
);
3758 dwarf2_per_cu_data
*dwarf_cu
= dwarf2_per_objfile
->all_comp_units
.back ();
3759 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, false);
3764 return compunit_primary_filetab (cust
);
3767 /* Traversal function for dw2_forget_cached_source_info. */
3770 dw2_free_cached_file_names (void **slot
, void *info
)
3772 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3774 if (file_data
->real_names
)
3778 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3780 xfree ((void*) file_data
->real_names
[i
]);
3781 file_data
->real_names
[i
] = NULL
;
3789 dw2_forget_cached_source_info (struct objfile
*objfile
)
3791 struct dwarf2_per_objfile
*dwarf2_per_objfile
3792 = get_dwarf2_per_objfile (objfile
);
3794 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
3795 dw2_free_cached_file_names
, NULL
);
3798 /* Helper function for dw2_map_symtabs_matching_filename that expands
3799 the symtabs and calls the iterator. */
3802 dw2_map_expand_apply (struct objfile
*objfile
,
3803 struct dwarf2_per_cu_data
*per_cu
,
3804 const char *name
, const char *real_path
,
3805 gdb::function_view
<bool (symtab
*)> callback
)
3807 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3809 /* Don't visit already-expanded CUs. */
3810 if (per_cu
->v
.quick
->compunit_symtab
)
3813 /* This may expand more than one symtab, and we want to iterate over
3815 dw2_instantiate_symtab (per_cu
, false);
3817 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3818 last_made
, callback
);
3821 /* Implementation of the map_symtabs_matching_filename method. */
3824 dw2_map_symtabs_matching_filename
3825 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3826 gdb::function_view
<bool (symtab
*)> callback
)
3828 const char *name_basename
= lbasename (name
);
3829 struct dwarf2_per_objfile
*dwarf2_per_objfile
3830 = get_dwarf2_per_objfile (objfile
);
3832 /* The rule is CUs specify all the files, including those used by
3833 any TU, so there's no need to scan TUs here. */
3835 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3837 /* We only need to look at symtabs not already expanded. */
3838 if (per_cu
->v
.quick
->compunit_symtab
)
3841 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3842 if (file_data
== NULL
)
3845 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3847 const char *this_name
= file_data
->file_names
[j
];
3848 const char *this_real_name
;
3850 if (compare_filenames_for_search (this_name
, name
))
3852 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3858 /* Before we invoke realpath, which can get expensive when many
3859 files are involved, do a quick comparison of the basenames. */
3860 if (! basenames_may_differ
3861 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3864 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3865 if (compare_filenames_for_search (this_real_name
, name
))
3867 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3873 if (real_path
!= NULL
)
3875 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3876 gdb_assert (IS_ABSOLUTE_PATH (name
));
3877 if (this_real_name
!= NULL
3878 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3880 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3892 /* Struct used to manage iterating over all CUs looking for a symbol. */
3894 struct dw2_symtab_iterator
3896 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3897 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
3898 /* If set, only look for symbols that match that block. Valid values are
3899 GLOBAL_BLOCK and STATIC_BLOCK. */
3900 gdb::optional
<block_enum
> block_index
;
3901 /* The kind of symbol we're looking for. */
3903 /* The list of CUs from the index entry of the symbol,
3904 or NULL if not found. */
3906 /* The next element in VEC to look at. */
3908 /* The number of elements in VEC, or zero if there is no match. */
3910 /* Have we seen a global version of the symbol?
3911 If so we can ignore all further global instances.
3912 This is to work around gold/15646, inefficient gold-generated
3917 /* Initialize the index symtab iterator ITER. */
3920 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3921 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3922 gdb::optional
<block_enum
> block_index
,
3926 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3927 iter
->block_index
= block_index
;
3928 iter
->domain
= domain
;
3930 iter
->global_seen
= 0;
3932 mapped_index
*index
= dwarf2_per_objfile
->index_table
.get ();
3934 /* index is NULL if OBJF_READNOW. */
3935 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3936 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3944 /* Return the next matching CU or NULL if there are no more. */
3946 static struct dwarf2_per_cu_data
*
3947 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3949 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
3951 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3953 offset_type cu_index_and_attrs
=
3954 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3955 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3956 gdb_index_symbol_kind symbol_kind
=
3957 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3958 /* Only check the symbol attributes if they're present.
3959 Indices prior to version 7 don't record them,
3960 and indices >= 7 may elide them for certain symbols
3961 (gold does this). */
3963 (dwarf2_per_objfile
->index_table
->version
>= 7
3964 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3966 /* Don't crash on bad data. */
3967 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
3968 + dwarf2_per_objfile
->all_type_units
.size ()))
3970 complaint (_(".gdb_index entry has bad CU index"
3972 objfile_name (dwarf2_per_objfile
->objfile
));
3976 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
3978 /* Skip if already read in. */
3979 if (per_cu
->v
.quick
->compunit_symtab
)
3982 /* Check static vs global. */
3985 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3987 if (iter
->block_index
.has_value ())
3989 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3991 if (is_static
!= want_static
)
3995 /* Work around gold/15646. */
3996 if (!is_static
&& iter
->global_seen
)
3999 iter
->global_seen
= 1;
4002 /* Only check the symbol's kind if it has one. */
4005 switch (iter
->domain
)
4008 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
4009 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
4010 /* Some types are also in VAR_DOMAIN. */
4011 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4015 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4019 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4034 static struct compunit_symtab
*
4035 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
4036 const char *name
, domain_enum domain
)
4038 struct compunit_symtab
*stab_best
= NULL
;
4039 struct dwarf2_per_objfile
*dwarf2_per_objfile
4040 = get_dwarf2_per_objfile (objfile
);
4042 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
4044 struct dw2_symtab_iterator iter
;
4045 struct dwarf2_per_cu_data
*per_cu
;
4047 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, block_index
, domain
, name
);
4049 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4051 struct symbol
*sym
, *with_opaque
= NULL
;
4052 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
4053 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
4054 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
4056 sym
= block_find_symbol (block
, name
, domain
,
4057 block_find_non_opaque_type_preferred
,
4060 /* Some caution must be observed with overloaded functions
4061 and methods, since the index will not contain any overload
4062 information (but NAME might contain it). */
4065 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
4067 if (with_opaque
!= NULL
4068 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
4071 /* Keep looking through other CUs. */
4078 dw2_print_stats (struct objfile
*objfile
)
4080 struct dwarf2_per_objfile
*dwarf2_per_objfile
4081 = get_dwarf2_per_objfile (objfile
);
4082 int total
= (dwarf2_per_objfile
->all_comp_units
.size ()
4083 + dwarf2_per_objfile
->all_type_units
.size ());
4086 for (int i
= 0; i
< total
; ++i
)
4088 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
4090 if (!per_cu
->v
.quick
->compunit_symtab
)
4093 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
4094 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
4097 /* This dumps minimal information about the index.
4098 It is called via "mt print objfiles".
4099 One use is to verify .gdb_index has been loaded by the
4100 gdb.dwarf2/gdb-index.exp testcase. */
4103 dw2_dump (struct objfile
*objfile
)
4105 struct dwarf2_per_objfile
*dwarf2_per_objfile
4106 = get_dwarf2_per_objfile (objfile
);
4108 gdb_assert (dwarf2_per_objfile
->using_index
);
4109 printf_filtered (".gdb_index:");
4110 if (dwarf2_per_objfile
->index_table
!= NULL
)
4112 printf_filtered (" version %d\n",
4113 dwarf2_per_objfile
->index_table
->version
);
4116 printf_filtered (" faked for \"readnow\"\n");
4117 printf_filtered ("\n");
4121 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
4122 const char *func_name
)
4124 struct dwarf2_per_objfile
*dwarf2_per_objfile
4125 = get_dwarf2_per_objfile (objfile
);
4127 struct dw2_symtab_iterator iter
;
4128 struct dwarf2_per_cu_data
*per_cu
;
4130 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, {}, VAR_DOMAIN
, func_name
);
4132 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4133 dw2_instantiate_symtab (per_cu
, false);
4138 dw2_expand_all_symtabs (struct objfile
*objfile
)
4140 struct dwarf2_per_objfile
*dwarf2_per_objfile
4141 = get_dwarf2_per_objfile (objfile
);
4142 int total_units
= (dwarf2_per_objfile
->all_comp_units
.size ()
4143 + dwarf2_per_objfile
->all_type_units
.size ());
4145 for (int i
= 0; i
< total_units
; ++i
)
4147 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
4149 /* We don't want to directly expand a partial CU, because if we
4150 read it with the wrong language, then assertion failures can
4151 be triggered later on. See PR symtab/23010. So, tell
4152 dw2_instantiate_symtab to skip partial CUs -- any important
4153 partial CU will be read via DW_TAG_imported_unit anyway. */
4154 dw2_instantiate_symtab (per_cu
, true);
4159 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
4160 const char *fullname
)
4162 struct dwarf2_per_objfile
*dwarf2_per_objfile
4163 = get_dwarf2_per_objfile (objfile
);
4165 /* We don't need to consider type units here.
4166 This is only called for examining code, e.g. expand_line_sal.
4167 There can be an order of magnitude (or more) more type units
4168 than comp units, and we avoid them if we can. */
4170 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4172 /* We only need to look at symtabs not already expanded. */
4173 if (per_cu
->v
.quick
->compunit_symtab
)
4176 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4177 if (file_data
== NULL
)
4180 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4182 const char *this_fullname
= file_data
->file_names
[j
];
4184 if (filename_cmp (this_fullname
, fullname
) == 0)
4186 dw2_instantiate_symtab (per_cu
, false);
4194 dw2_map_matching_symbols
4195 (struct objfile
*objfile
,
4196 const lookup_name_info
&name
, domain_enum domain
,
4198 gdb::function_view
<symbol_found_callback_ftype
> callback
,
4199 symbol_compare_ftype
*ordered_compare
)
4201 /* Currently unimplemented; used for Ada. The function can be called if the
4202 current language is Ada for a non-Ada objfile using GNU index. As Ada
4203 does not look for non-Ada symbols this function should just return. */
4206 /* Starting from a search name, return the string that finds the upper
4207 bound of all strings that start with SEARCH_NAME in a sorted name
4208 list. Returns the empty string to indicate that the upper bound is
4209 the end of the list. */
4212 make_sort_after_prefix_name (const char *search_name
)
4214 /* When looking to complete "func", we find the upper bound of all
4215 symbols that start with "func" by looking for where we'd insert
4216 the closest string that would follow "func" in lexicographical
4217 order. Usually, that's "func"-with-last-character-incremented,
4218 i.e. "fund". Mind non-ASCII characters, though. Usually those
4219 will be UTF-8 multi-byte sequences, but we can't be certain.
4220 Especially mind the 0xff character, which is a valid character in
4221 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
4222 rule out compilers allowing it in identifiers. Note that
4223 conveniently, strcmp/strcasecmp are specified to compare
4224 characters interpreted as unsigned char. So what we do is treat
4225 the whole string as a base 256 number composed of a sequence of
4226 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
4227 to 0, and carries 1 to the following more-significant position.
4228 If the very first character in SEARCH_NAME ends up incremented
4229 and carries/overflows, then the upper bound is the end of the
4230 list. The string after the empty string is also the empty
4233 Some examples of this operation:
4235 SEARCH_NAME => "+1" RESULT
4239 "\xff" "a" "\xff" => "\xff" "b"
4244 Then, with these symbols for example:
4250 completing "func" looks for symbols between "func" and
4251 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
4252 which finds "func" and "func1", but not "fund".
4256 funcÿ (Latin1 'ÿ' [0xff])
4260 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
4261 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
4265 ÿÿ (Latin1 'ÿ' [0xff])
4268 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
4269 the end of the list.
4271 std::string after
= search_name
;
4272 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
4274 if (!after
.empty ())
4275 after
.back () = (unsigned char) after
.back () + 1;
4279 /* See declaration. */
4281 std::pair
<std::vector
<name_component
>::const_iterator
,
4282 std::vector
<name_component
>::const_iterator
>
4283 mapped_index_base::find_name_components_bounds
4284 (const lookup_name_info
&lookup_name_without_params
, language lang
) const
4287 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4289 const char *lang_name
4290 = lookup_name_without_params
.language_lookup_name (lang
).c_str ();
4292 /* Comparison function object for lower_bound that matches against a
4293 given symbol name. */
4294 auto lookup_compare_lower
= [&] (const name_component
&elem
,
4297 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4298 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4299 return name_cmp (elem_name
, name
) < 0;
4302 /* Comparison function object for upper_bound that matches against a
4303 given symbol name. */
4304 auto lookup_compare_upper
= [&] (const char *name
,
4305 const name_component
&elem
)
4307 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4308 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4309 return name_cmp (name
, elem_name
) < 0;
4312 auto begin
= this->name_components
.begin ();
4313 auto end
= this->name_components
.end ();
4315 /* Find the lower bound. */
4318 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
4321 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
4324 /* Find the upper bound. */
4327 if (lookup_name_without_params
.completion_mode ())
4329 /* In completion mode, we want UPPER to point past all
4330 symbols names that have the same prefix. I.e., with
4331 these symbols, and completing "func":
4333 function << lower bound
4335 other_function << upper bound
4337 We find the upper bound by looking for the insertion
4338 point of "func"-with-last-character-incremented,
4340 std::string after
= make_sort_after_prefix_name (lang_name
);
4343 return std::lower_bound (lower
, end
, after
.c_str (),
4344 lookup_compare_lower
);
4347 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
4350 return {lower
, upper
};
4353 /* See declaration. */
4356 mapped_index_base::build_name_components ()
4358 if (!this->name_components
.empty ())
4361 this->name_components_casing
= case_sensitivity
;
4363 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4365 /* The code below only knows how to break apart components of C++
4366 symbol names (and other languages that use '::' as
4367 namespace/module separator) and Ada symbol names. */
4368 auto count
= this->symbol_name_count ();
4369 for (offset_type idx
= 0; idx
< count
; idx
++)
4371 if (this->symbol_name_slot_invalid (idx
))
4374 const char *name
= this->symbol_name_at (idx
);
4376 /* Add each name component to the name component table. */
4377 unsigned int previous_len
= 0;
4379 if (strstr (name
, "::") != nullptr)
4381 for (unsigned int current_len
= cp_find_first_component (name
);
4382 name
[current_len
] != '\0';
4383 current_len
+= cp_find_first_component (name
+ current_len
))
4385 gdb_assert (name
[current_len
] == ':');
4386 this->name_components
.push_back ({previous_len
, idx
});
4387 /* Skip the '::'. */
4389 previous_len
= current_len
;
4394 /* Handle the Ada encoded (aka mangled) form here. */
4395 for (const char *iter
= strstr (name
, "__");
4397 iter
= strstr (iter
, "__"))
4399 this->name_components
.push_back ({previous_len
, idx
});
4401 previous_len
= iter
- name
;
4405 this->name_components
.push_back ({previous_len
, idx
});
4408 /* Sort name_components elements by name. */
4409 auto name_comp_compare
= [&] (const name_component
&left
,
4410 const name_component
&right
)
4412 const char *left_qualified
= this->symbol_name_at (left
.idx
);
4413 const char *right_qualified
= this->symbol_name_at (right
.idx
);
4415 const char *left_name
= left_qualified
+ left
.name_offset
;
4416 const char *right_name
= right_qualified
+ right
.name_offset
;
4418 return name_cmp (left_name
, right_name
) < 0;
4421 std::sort (this->name_components
.begin (),
4422 this->name_components
.end (),
4426 /* Helper for dw2_expand_symtabs_matching that works with a
4427 mapped_index_base instead of the containing objfile. This is split
4428 to a separate function in order to be able to unit test the
4429 name_components matching using a mock mapped_index_base. For each
4430 symbol name that matches, calls MATCH_CALLBACK, passing it the
4431 symbol's index in the mapped_index_base symbol table. */
4434 dw2_expand_symtabs_matching_symbol
4435 (mapped_index_base
&index
,
4436 const lookup_name_info
&lookup_name_in
,
4437 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4438 enum search_domain kind
,
4439 gdb::function_view
<bool (offset_type
)> match_callback
)
4441 lookup_name_info lookup_name_without_params
4442 = lookup_name_in
.make_ignore_params ();
4444 /* Build the symbol name component sorted vector, if we haven't
4446 index
.build_name_components ();
4448 /* The same symbol may appear more than once in the range though.
4449 E.g., if we're looking for symbols that complete "w", and we have
4450 a symbol named "w1::w2", we'll find the two name components for
4451 that same symbol in the range. To be sure we only call the
4452 callback once per symbol, we first collect the symbol name
4453 indexes that matched in a temporary vector and ignore
4455 std::vector
<offset_type
> matches
;
4457 struct name_and_matcher
4459 symbol_name_matcher_ftype
*matcher
;
4460 const std::string
&name
;
4462 bool operator== (const name_and_matcher
&other
) const
4464 return matcher
== other
.matcher
&& name
== other
.name
;
4468 /* A vector holding all the different symbol name matchers, for all
4470 std::vector
<name_and_matcher
> matchers
;
4472 for (int i
= 0; i
< nr_languages
; i
++)
4474 enum language lang_e
= (enum language
) i
;
4476 const language_defn
*lang
= language_def (lang_e
);
4477 symbol_name_matcher_ftype
*name_matcher
4478 = get_symbol_name_matcher (lang
, lookup_name_without_params
);
4480 name_and_matcher key
{
4482 lookup_name_without_params
.language_lookup_name (lang_e
)
4485 /* Don't insert the same comparison routine more than once.
4486 Note that we do this linear walk. This is not a problem in
4487 practice because the number of supported languages is
4489 if (std::find (matchers
.begin (), matchers
.end (), key
)
4492 matchers
.push_back (std::move (key
));
4495 = index
.find_name_components_bounds (lookup_name_without_params
,
4498 /* Now for each symbol name in range, check to see if we have a name
4499 match, and if so, call the MATCH_CALLBACK callback. */
4501 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
4503 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
4505 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
4506 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4509 matches
.push_back (bounds
.first
->idx
);
4513 std::sort (matches
.begin (), matches
.end ());
4515 /* Finally call the callback, once per match. */
4517 for (offset_type idx
: matches
)
4521 if (!match_callback (idx
))
4527 /* Above we use a type wider than idx's for 'prev', since 0 and
4528 (offset_type)-1 are both possible values. */
4529 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4534 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4536 /* A mock .gdb_index/.debug_names-like name index table, enough to
4537 exercise dw2_expand_symtabs_matching_symbol, which works with the
4538 mapped_index_base interface. Builds an index from the symbol list
4539 passed as parameter to the constructor. */
4540 class mock_mapped_index
: public mapped_index_base
4543 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4544 : m_symbol_table (symbols
)
4547 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4549 /* Return the number of names in the symbol table. */
4550 size_t symbol_name_count () const override
4552 return m_symbol_table
.size ();
4555 /* Get the name of the symbol at IDX in the symbol table. */
4556 const char *symbol_name_at (offset_type idx
) const override
4558 return m_symbol_table
[idx
];
4562 gdb::array_view
<const char *> m_symbol_table
;
4565 /* Convenience function that converts a NULL pointer to a "<null>"
4566 string, to pass to print routines. */
4569 string_or_null (const char *str
)
4571 return str
!= NULL
? str
: "<null>";
4574 /* Check if a lookup_name_info built from
4575 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4576 index. EXPECTED_LIST is the list of expected matches, in expected
4577 matching order. If no match expected, then an empty list is
4578 specified. Returns true on success. On failure prints a warning
4579 indicating the file:line that failed, and returns false. */
4582 check_match (const char *file
, int line
,
4583 mock_mapped_index
&mock_index
,
4584 const char *name
, symbol_name_match_type match_type
,
4585 bool completion_mode
,
4586 std::initializer_list
<const char *> expected_list
)
4588 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4590 bool matched
= true;
4592 auto mismatch
= [&] (const char *expected_str
,
4595 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4596 "expected=\"%s\", got=\"%s\"\n"),
4598 (match_type
== symbol_name_match_type::FULL
4600 name
, string_or_null (expected_str
), string_or_null (got
));
4604 auto expected_it
= expected_list
.begin ();
4605 auto expected_end
= expected_list
.end ();
4607 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4609 [&] (offset_type idx
)
4611 const char *matched_name
= mock_index
.symbol_name_at (idx
);
4612 const char *expected_str
4613 = expected_it
== expected_end
? NULL
: *expected_it
++;
4615 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4616 mismatch (expected_str
, matched_name
);
4620 const char *expected_str
4621 = expected_it
== expected_end
? NULL
: *expected_it
++;
4622 if (expected_str
!= NULL
)
4623 mismatch (expected_str
, NULL
);
4628 /* The symbols added to the mock mapped_index for testing (in
4630 static const char *test_symbols
[] = {
4639 "ns2::tmpl<int>::foo2",
4640 "(anonymous namespace)::A::B::C",
4642 /* These are used to check that the increment-last-char in the
4643 matching algorithm for completion doesn't match "t1_fund" when
4644 completing "t1_func". */
4650 /* A UTF-8 name with multi-byte sequences to make sure that
4651 cp-name-parser understands this as a single identifier ("função"
4652 is "function" in PT). */
4655 /* \377 (0xff) is Latin1 'ÿ'. */
4658 /* \377 (0xff) is Latin1 'ÿ'. */
4662 /* A name with all sorts of complications. Starts with "z" to make
4663 it easier for the completion tests below. */
4664 #define Z_SYM_NAME \
4665 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4666 "::tuple<(anonymous namespace)::ui*, " \
4667 "std::default_delete<(anonymous namespace)::ui>, void>"
4672 /* Returns true if the mapped_index_base::find_name_component_bounds
4673 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4674 in completion mode. */
4677 check_find_bounds_finds (mapped_index_base
&index
,
4678 const char *search_name
,
4679 gdb::array_view
<const char *> expected_syms
)
4681 lookup_name_info
lookup_name (search_name
,
4682 symbol_name_match_type::FULL
, true);
4684 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4687 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4688 if (distance
!= expected_syms
.size ())
4691 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4693 auto nc_elem
= bounds
.first
+ exp_elem
;
4694 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
4695 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4702 /* Test the lower-level mapped_index::find_name_component_bounds
4706 test_mapped_index_find_name_component_bounds ()
4708 mock_mapped_index
mock_index (test_symbols
);
4710 mock_index
.build_name_components ();
4712 /* Test the lower-level mapped_index::find_name_component_bounds
4713 method in completion mode. */
4715 static const char *expected_syms
[] = {
4720 SELF_CHECK (check_find_bounds_finds (mock_index
,
4721 "t1_func", expected_syms
));
4724 /* Check that the increment-last-char in the name matching algorithm
4725 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4727 static const char *expected_syms1
[] = {
4731 SELF_CHECK (check_find_bounds_finds (mock_index
,
4732 "\377", expected_syms1
));
4734 static const char *expected_syms2
[] = {
4737 SELF_CHECK (check_find_bounds_finds (mock_index
,
4738 "\377\377", expected_syms2
));
4742 /* Test dw2_expand_symtabs_matching_symbol. */
4745 test_dw2_expand_symtabs_matching_symbol ()
4747 mock_mapped_index
mock_index (test_symbols
);
4749 /* We let all tests run until the end even if some fails, for debug
4751 bool any_mismatch
= false;
4753 /* Create the expected symbols list (an initializer_list). Needed
4754 because lists have commas, and we need to pass them to CHECK,
4755 which is a macro. */
4756 #define EXPECT(...) { __VA_ARGS__ }
4758 /* Wrapper for check_match that passes down the current
4759 __FILE__/__LINE__. */
4760 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4761 any_mismatch |= !check_match (__FILE__, __LINE__, \
4763 NAME, MATCH_TYPE, COMPLETION_MODE, \
4766 /* Identity checks. */
4767 for (const char *sym
: test_symbols
)
4769 /* Should be able to match all existing symbols. */
4770 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4773 /* Should be able to match all existing symbols with
4775 std::string with_params
= std::string (sym
) + "(int)";
4776 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4779 /* Should be able to match all existing symbols with
4780 parameters and qualifiers. */
4781 with_params
= std::string (sym
) + " ( int ) const";
4782 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4785 /* This should really find sym, but cp-name-parser.y doesn't
4786 know about lvalue/rvalue qualifiers yet. */
4787 with_params
= std::string (sym
) + " ( int ) &&";
4788 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4792 /* Check that the name matching algorithm for completion doesn't get
4793 confused with Latin1 'ÿ' / 0xff. */
4795 static const char str
[] = "\377";
4796 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4797 EXPECT ("\377", "\377\377123"));
4800 /* Check that the increment-last-char in the matching algorithm for
4801 completion doesn't match "t1_fund" when completing "t1_func". */
4803 static const char str
[] = "t1_func";
4804 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4805 EXPECT ("t1_func", "t1_func1"));
4808 /* Check that completion mode works at each prefix of the expected
4811 static const char str
[] = "function(int)";
4812 size_t len
= strlen (str
);
4815 for (size_t i
= 1; i
< len
; i
++)
4817 lookup
.assign (str
, i
);
4818 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4819 EXPECT ("function"));
4823 /* While "w" is a prefix of both components, the match function
4824 should still only be called once. */
4826 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4828 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4832 /* Same, with a "complicated" symbol. */
4834 static const char str
[] = Z_SYM_NAME
;
4835 size_t len
= strlen (str
);
4838 for (size_t i
= 1; i
< len
; i
++)
4840 lookup
.assign (str
, i
);
4841 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4842 EXPECT (Z_SYM_NAME
));
4846 /* In FULL mode, an incomplete symbol doesn't match. */
4848 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4852 /* A complete symbol with parameters matches any overload, since the
4853 index has no overload info. */
4855 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4856 EXPECT ("std::zfunction", "std::zfunction2"));
4857 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4858 EXPECT ("std::zfunction", "std::zfunction2"));
4859 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4860 EXPECT ("std::zfunction", "std::zfunction2"));
4863 /* Check that whitespace is ignored appropriately. A symbol with a
4864 template argument list. */
4866 static const char expected
[] = "ns::foo<int>";
4867 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4869 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4873 /* Check that whitespace is ignored appropriately. A symbol with a
4874 template argument list that includes a pointer. */
4876 static const char expected
[] = "ns::foo<char*>";
4877 /* Try both completion and non-completion modes. */
4878 static const bool completion_mode
[2] = {false, true};
4879 for (size_t i
= 0; i
< 2; i
++)
4881 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4882 completion_mode
[i
], EXPECT (expected
));
4883 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4884 completion_mode
[i
], EXPECT (expected
));
4886 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4887 completion_mode
[i
], EXPECT (expected
));
4888 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4889 completion_mode
[i
], EXPECT (expected
));
4894 /* Check method qualifiers are ignored. */
4895 static const char expected
[] = "ns::foo<char*>";
4896 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4897 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4898 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4899 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4900 CHECK_MATCH ("foo < char * > ( int ) const",
4901 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4902 CHECK_MATCH ("foo < char * > ( int ) &&",
4903 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4906 /* Test lookup names that don't match anything. */
4908 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4911 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4915 /* Some wild matching tests, exercising "(anonymous namespace)",
4916 which should not be confused with a parameter list. */
4918 static const char *syms
[] = {
4922 "A :: B :: C ( int )",
4927 for (const char *s
: syms
)
4929 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4930 EXPECT ("(anonymous namespace)::A::B::C"));
4935 static const char expected
[] = "ns2::tmpl<int>::foo2";
4936 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4938 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4942 SELF_CHECK (!any_mismatch
);
4951 test_mapped_index_find_name_component_bounds ();
4952 test_dw2_expand_symtabs_matching_symbol ();
4955 }} // namespace selftests::dw2_expand_symtabs_matching
4957 #endif /* GDB_SELF_TEST */
4959 /* If FILE_MATCHER is NULL or if PER_CU has
4960 dwarf2_per_cu_quick_data::MARK set (see
4961 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4962 EXPANSION_NOTIFY on it. */
4965 dw2_expand_symtabs_matching_one
4966 (struct dwarf2_per_cu_data
*per_cu
,
4967 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4968 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4970 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4972 bool symtab_was_null
4973 = (per_cu
->v
.quick
->compunit_symtab
== NULL
);
4975 dw2_instantiate_symtab (per_cu
, false);
4977 if (expansion_notify
!= NULL
4979 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
4980 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
4984 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4985 matched, to expand corresponding CUs that were marked. IDX is the
4986 index of the symbol name that matched. */
4989 dw2_expand_marked_cus
4990 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
4991 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4992 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4995 offset_type
*vec
, vec_len
, vec_idx
;
4996 bool global_seen
= false;
4997 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
4999 vec
= (offset_type
*) (index
.constant_pool
5000 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
5001 vec_len
= MAYBE_SWAP (vec
[0]);
5002 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
5004 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
5005 /* This value is only valid for index versions >= 7. */
5006 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
5007 gdb_index_symbol_kind symbol_kind
=
5008 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
5009 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
5010 /* Only check the symbol attributes if they're present.
5011 Indices prior to version 7 don't record them,
5012 and indices >= 7 may elide them for certain symbols
5013 (gold does this). */
5016 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
5018 /* Work around gold/15646. */
5021 if (!is_static
&& global_seen
)
5027 /* Only check the symbol's kind if it has one. */
5032 case VARIABLES_DOMAIN
:
5033 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
5036 case FUNCTIONS_DOMAIN
:
5037 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
5041 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
5049 /* Don't crash on bad data. */
5050 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
5051 + dwarf2_per_objfile
->all_type_units
.size ()))
5053 complaint (_(".gdb_index entry has bad CU index"
5055 objfile_name (dwarf2_per_objfile
->objfile
));
5059 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
5060 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5065 /* If FILE_MATCHER is non-NULL, set all the
5066 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
5067 that match FILE_MATCHER. */
5070 dw_expand_symtabs_matching_file_matcher
5071 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5072 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
5074 if (file_matcher
== NULL
)
5077 objfile
*const objfile
= dwarf2_per_objfile
->objfile
;
5079 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
5081 NULL
, xcalloc
, xfree
));
5082 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
5084 NULL
, xcalloc
, xfree
));
5086 /* The rule is CUs specify all the files, including those used by
5087 any TU, so there's no need to scan TUs here. */
5089 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5093 per_cu
->v
.quick
->mark
= 0;
5095 /* We only need to look at symtabs not already expanded. */
5096 if (per_cu
->v
.quick
->compunit_symtab
)
5099 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
5100 if (file_data
== NULL
)
5103 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
5105 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
5107 per_cu
->v
.quick
->mark
= 1;
5111 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
5113 const char *this_real_name
;
5115 if (file_matcher (file_data
->file_names
[j
], false))
5117 per_cu
->v
.quick
->mark
= 1;
5121 /* Before we invoke realpath, which can get expensive when many
5122 files are involved, do a quick comparison of the basenames. */
5123 if (!basenames_may_differ
5124 && !file_matcher (lbasename (file_data
->file_names
[j
]),
5128 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
5129 if (file_matcher (this_real_name
, false))
5131 per_cu
->v
.quick
->mark
= 1;
5136 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
5137 ? visited_found
.get ()
5138 : visited_not_found
.get (),
5145 dw2_expand_symtabs_matching
5146 (struct objfile
*objfile
,
5147 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5148 const lookup_name_info
&lookup_name
,
5149 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5150 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5151 enum search_domain kind
)
5153 struct dwarf2_per_objfile
*dwarf2_per_objfile
5154 = get_dwarf2_per_objfile (objfile
);
5156 /* index_table is NULL if OBJF_READNOW. */
5157 if (!dwarf2_per_objfile
->index_table
)
5160 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5162 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
5164 dw2_expand_symtabs_matching_symbol (index
, lookup_name
,
5166 kind
, [&] (offset_type idx
)
5168 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
5169 expansion_notify
, kind
);
5174 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
5177 static struct compunit_symtab
*
5178 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
5183 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
5184 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
5187 if (cust
->includes
== NULL
)
5190 for (i
= 0; cust
->includes
[i
]; ++i
)
5192 struct compunit_symtab
*s
= cust
->includes
[i
];
5194 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
5202 static struct compunit_symtab
*
5203 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
5204 struct bound_minimal_symbol msymbol
,
5206 struct obj_section
*section
,
5209 struct dwarf2_per_cu_data
*data
;
5210 struct compunit_symtab
*result
;
5212 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
5215 CORE_ADDR baseaddr
= ANOFFSET (objfile
->section_offsets
,
5216 SECT_OFF_TEXT (objfile
));
5217 data
= (struct dwarf2_per_cu_data
*) addrmap_find
5218 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
5222 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
5223 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
5224 paddress (get_objfile_arch (objfile
), pc
));
5227 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
,
5230 gdb_assert (result
!= NULL
);
5235 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
5236 void *data
, int need_fullname
)
5238 struct dwarf2_per_objfile
*dwarf2_per_objfile
5239 = get_dwarf2_per_objfile (objfile
);
5241 if (!dwarf2_per_objfile
->filenames_cache
)
5243 dwarf2_per_objfile
->filenames_cache
.emplace ();
5245 htab_up
visited (htab_create_alloc (10,
5246 htab_hash_pointer
, htab_eq_pointer
,
5247 NULL
, xcalloc
, xfree
));
5249 /* The rule is CUs specify all the files, including those used
5250 by any TU, so there's no need to scan TUs here. We can
5251 ignore file names coming from already-expanded CUs. */
5253 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5255 if (per_cu
->v
.quick
->compunit_symtab
)
5257 void **slot
= htab_find_slot (visited
.get (),
5258 per_cu
->v
.quick
->file_names
,
5261 *slot
= per_cu
->v
.quick
->file_names
;
5265 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5267 /* We only need to look at symtabs not already expanded. */
5268 if (per_cu
->v
.quick
->compunit_symtab
)
5271 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
5272 if (file_data
== NULL
)
5275 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
5278 /* Already visited. */
5283 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
5285 const char *filename
= file_data
->file_names
[j
];
5286 dwarf2_per_objfile
->filenames_cache
->seen (filename
);
5291 dwarf2_per_objfile
->filenames_cache
->traverse ([&] (const char *filename
)
5293 gdb::unique_xmalloc_ptr
<char> this_real_name
;
5296 this_real_name
= gdb_realpath (filename
);
5297 (*fun
) (filename
, this_real_name
.get (), data
);
5302 dw2_has_symbols (struct objfile
*objfile
)
5307 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
5310 dw2_find_last_source_symtab
,
5311 dw2_forget_cached_source_info
,
5312 dw2_map_symtabs_matching_filename
,
5316 dw2_expand_symtabs_for_function
,
5317 dw2_expand_all_symtabs
,
5318 dw2_expand_symtabs_with_fullname
,
5319 dw2_map_matching_symbols
,
5320 dw2_expand_symtabs_matching
,
5321 dw2_find_pc_sect_compunit_symtab
,
5323 dw2_map_symbol_filenames
5326 /* DWARF-5 debug_names reader. */
5328 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
5329 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
5331 /* A helper function that reads the .debug_names section in SECTION
5332 and fills in MAP. FILENAME is the name of the file containing the
5333 section; it is used for error reporting.
5335 Returns true if all went well, false otherwise. */
5338 read_debug_names_from_section (struct objfile
*objfile
,
5339 const char *filename
,
5340 struct dwarf2_section_info
*section
,
5341 mapped_debug_names
&map
)
5343 if (dwarf2_section_empty_p (section
))
5346 /* Older elfutils strip versions could keep the section in the main
5347 executable while splitting it for the separate debug info file. */
5348 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
5351 dwarf2_read_section (objfile
, section
);
5353 map
.dwarf5_byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
5355 const gdb_byte
*addr
= section
->buffer
;
5357 bfd
*const abfd
= get_section_bfd_owner (section
);
5359 unsigned int bytes_read
;
5360 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
5363 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
5364 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
5365 if (bytes_read
+ length
!= section
->size
)
5367 /* There may be multiple per-CU indices. */
5368 warning (_("Section .debug_names in %s length %s does not match "
5369 "section length %s, ignoring .debug_names."),
5370 filename
, plongest (bytes_read
+ length
),
5371 pulongest (section
->size
));
5375 /* The version number. */
5376 uint16_t version
= read_2_bytes (abfd
, addr
);
5380 warning (_("Section .debug_names in %s has unsupported version %d, "
5381 "ignoring .debug_names."),
5387 uint16_t padding
= read_2_bytes (abfd
, addr
);
5391 warning (_("Section .debug_names in %s has unsupported padding %d, "
5392 "ignoring .debug_names."),
5397 /* comp_unit_count - The number of CUs in the CU list. */
5398 map
.cu_count
= read_4_bytes (abfd
, addr
);
5401 /* local_type_unit_count - The number of TUs in the local TU
5403 map
.tu_count
= read_4_bytes (abfd
, addr
);
5406 /* foreign_type_unit_count - The number of TUs in the foreign TU
5408 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
5410 if (foreign_tu_count
!= 0)
5412 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
5413 "ignoring .debug_names."),
5414 filename
, static_cast<unsigned long> (foreign_tu_count
));
5418 /* bucket_count - The number of hash buckets in the hash lookup
5420 map
.bucket_count
= read_4_bytes (abfd
, addr
);
5423 /* name_count - The number of unique names in the index. */
5424 map
.name_count
= read_4_bytes (abfd
, addr
);
5427 /* abbrev_table_size - The size in bytes of the abbreviations
5429 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
5432 /* augmentation_string_size - The size in bytes of the augmentation
5433 string. This value is rounded up to a multiple of 4. */
5434 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
5436 map
.augmentation_is_gdb
= ((augmentation_string_size
5437 == sizeof (dwarf5_augmentation
))
5438 && memcmp (addr
, dwarf5_augmentation
,
5439 sizeof (dwarf5_augmentation
)) == 0);
5440 augmentation_string_size
+= (-augmentation_string_size
) & 3;
5441 addr
+= augmentation_string_size
;
5444 map
.cu_table_reordered
= addr
;
5445 addr
+= map
.cu_count
* map
.offset_size
;
5447 /* List of Local TUs */
5448 map
.tu_table_reordered
= addr
;
5449 addr
+= map
.tu_count
* map
.offset_size
;
5451 /* Hash Lookup Table */
5452 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5453 addr
+= map
.bucket_count
* 4;
5454 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5455 addr
+= map
.name_count
* 4;
5458 map
.name_table_string_offs_reordered
= addr
;
5459 addr
+= map
.name_count
* map
.offset_size
;
5460 map
.name_table_entry_offs_reordered
= addr
;
5461 addr
+= map
.name_count
* map
.offset_size
;
5463 const gdb_byte
*abbrev_table_start
= addr
;
5466 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5471 const auto insertpair
5472 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
5473 if (!insertpair
.second
)
5475 warning (_("Section .debug_names in %s has duplicate index %s, "
5476 "ignoring .debug_names."),
5477 filename
, pulongest (index_num
));
5480 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
5481 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5486 mapped_debug_names::index_val::attr attr
;
5487 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5489 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5491 if (attr
.form
== DW_FORM_implicit_const
)
5493 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
5497 if (attr
.dw_idx
== 0 && attr
.form
== 0)
5499 indexval
.attr_vec
.push_back (std::move (attr
));
5502 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
5504 warning (_("Section .debug_names in %s has abbreviation_table "
5505 "of size %s vs. written as %u, ignoring .debug_names."),
5506 filename
, plongest (addr
- abbrev_table_start
),
5510 map
.entry_pool
= addr
;
5515 /* A helper for create_cus_from_debug_names that handles the MAP's CU
5519 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5520 const mapped_debug_names
&map
,
5521 dwarf2_section_info
§ion
,
5524 sect_offset sect_off_prev
;
5525 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5527 sect_offset sect_off_next
;
5528 if (i
< map
.cu_count
)
5531 = (sect_offset
) (extract_unsigned_integer
5532 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5534 map
.dwarf5_byte_order
));
5537 sect_off_next
= (sect_offset
) section
.size
;
5540 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5541 dwarf2_per_cu_data
*per_cu
5542 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
5543 sect_off_prev
, length
);
5544 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
5546 sect_off_prev
= sect_off_next
;
5550 /* Read the CU list from the mapped index, and use it to create all
5551 the CU objects for this dwarf2_per_objfile. */
5554 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5555 const mapped_debug_names
&map
,
5556 const mapped_debug_names
&dwz_map
)
5558 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
5559 dwarf2_per_objfile
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5561 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
5562 dwarf2_per_objfile
->info
,
5563 false /* is_dwz */);
5565 if (dwz_map
.cu_count
== 0)
5568 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5569 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
5573 /* Read .debug_names. If everything went ok, initialize the "quick"
5574 elements of all the CUs and return true. Otherwise, return false. */
5577 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
5579 std::unique_ptr
<mapped_debug_names
> map
5580 (new mapped_debug_names (dwarf2_per_objfile
));
5581 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
5582 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5584 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5585 &dwarf2_per_objfile
->debug_names
,
5589 /* Don't use the index if it's empty. */
5590 if (map
->name_count
== 0)
5593 /* If there is a .dwz file, read it so we can get its CU list as
5595 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5598 if (!read_debug_names_from_section (objfile
,
5599 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5600 &dwz
->debug_names
, dwz_map
))
5602 warning (_("could not read '.debug_names' section from %s; skipping"),
5603 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5608 create_cus_from_debug_names (dwarf2_per_objfile
, *map
, dwz_map
);
5610 if (map
->tu_count
!= 0)
5612 /* We can only handle a single .debug_types when we have an
5614 if (dwarf2_per_objfile
->types
.size () != 1)
5617 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
5619 create_signatured_type_table_from_debug_names
5620 (dwarf2_per_objfile
, *map
, section
, &dwarf2_per_objfile
->abbrev
);
5623 create_addrmap_from_aranges (dwarf2_per_objfile
,
5624 &dwarf2_per_objfile
->debug_aranges
);
5626 dwarf2_per_objfile
->debug_names_table
= std::move (map
);
5627 dwarf2_per_objfile
->using_index
= 1;
5628 dwarf2_per_objfile
->quick_file_names_table
=
5629 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
5634 /* Type used to manage iterating over all CUs looking for a symbol for
5637 class dw2_debug_names_iterator
5640 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5641 gdb::optional
<block_enum
> block_index
,
5644 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5645 m_addr (find_vec_in_debug_names (map
, name
))
5648 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5649 search_domain search
, uint32_t namei
)
5652 m_addr (find_vec_in_debug_names (map
, namei
))
5655 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5656 block_enum block_index
, domain_enum domain
,
5658 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5659 m_addr (find_vec_in_debug_names (map
, namei
))
5662 /* Return the next matching CU or NULL if there are no more. */
5663 dwarf2_per_cu_data
*next ();
5666 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5668 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5671 /* The internalized form of .debug_names. */
5672 const mapped_debug_names
&m_map
;
5674 /* If set, only look for symbols that match that block. Valid values are
5675 GLOBAL_BLOCK and STATIC_BLOCK. */
5676 const gdb::optional
<block_enum
> m_block_index
;
5678 /* The kind of symbol we're looking for. */
5679 const domain_enum m_domain
= UNDEF_DOMAIN
;
5680 const search_domain m_search
= ALL_DOMAIN
;
5682 /* The list of CUs from the index entry of the symbol, or NULL if
5684 const gdb_byte
*m_addr
;
5688 mapped_debug_names::namei_to_name (uint32_t namei
) const
5690 const ULONGEST namei_string_offs
5691 = extract_unsigned_integer ((name_table_string_offs_reordered
5692 + namei
* offset_size
),
5695 return read_indirect_string_at_offset
5696 (dwarf2_per_objfile
, dwarf2_per_objfile
->objfile
->obfd
, namei_string_offs
);
5699 /* Find a slot in .debug_names for the object named NAME. If NAME is
5700 found, return pointer to its pool data. If NAME cannot be found,
5704 dw2_debug_names_iterator::find_vec_in_debug_names
5705 (const mapped_debug_names
&map
, const char *name
)
5707 int (*cmp
) (const char *, const char *);
5709 gdb::unique_xmalloc_ptr
<char> without_params
;
5710 if (current_language
->la_language
== language_cplus
5711 || current_language
->la_language
== language_fortran
5712 || current_language
->la_language
== language_d
)
5714 /* NAME is already canonical. Drop any qualifiers as
5715 .debug_names does not contain any. */
5717 if (strchr (name
, '(') != NULL
)
5719 without_params
= cp_remove_params (name
);
5720 if (without_params
!= NULL
)
5721 name
= without_params
.get ();
5725 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5727 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5729 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5730 (map
.bucket_table_reordered
5731 + (full_hash
% map
.bucket_count
)), 4,
5732 map
.dwarf5_byte_order
);
5736 if (namei
>= map
.name_count
)
5738 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5740 namei
, map
.name_count
,
5741 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5747 const uint32_t namei_full_hash
5748 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5749 (map
.hash_table_reordered
+ namei
), 4,
5750 map
.dwarf5_byte_order
);
5751 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5754 if (full_hash
== namei_full_hash
)
5756 const char *const namei_string
= map
.namei_to_name (namei
);
5758 #if 0 /* An expensive sanity check. */
5759 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5761 complaint (_("Wrong .debug_names hash for string at index %u "
5763 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5768 if (cmp (namei_string
, name
) == 0)
5770 const ULONGEST namei_entry_offs
5771 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5772 + namei
* map
.offset_size
),
5773 map
.offset_size
, map
.dwarf5_byte_order
);
5774 return map
.entry_pool
+ namei_entry_offs
;
5779 if (namei
>= map
.name_count
)
5785 dw2_debug_names_iterator::find_vec_in_debug_names
5786 (const mapped_debug_names
&map
, uint32_t namei
)
5788 if (namei
>= map
.name_count
)
5790 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5792 namei
, map
.name_count
,
5793 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5797 const ULONGEST namei_entry_offs
5798 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5799 + namei
* map
.offset_size
),
5800 map
.offset_size
, map
.dwarf5_byte_order
);
5801 return map
.entry_pool
+ namei_entry_offs
;
5804 /* See dw2_debug_names_iterator. */
5806 dwarf2_per_cu_data
*
5807 dw2_debug_names_iterator::next ()
5812 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
5813 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5814 bfd
*const abfd
= objfile
->obfd
;
5818 unsigned int bytes_read
;
5819 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5820 m_addr
+= bytes_read
;
5824 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5825 if (indexval_it
== m_map
.abbrev_map
.cend ())
5827 complaint (_("Wrong .debug_names undefined abbrev code %s "
5829 pulongest (abbrev
), objfile_name (objfile
));
5832 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5833 enum class symbol_linkage
{
5837 } symbol_linkage_
= symbol_linkage::unknown
;
5838 dwarf2_per_cu_data
*per_cu
= NULL
;
5839 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5844 case DW_FORM_implicit_const
:
5845 ull
= attr
.implicit_const
;
5847 case DW_FORM_flag_present
:
5851 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5852 m_addr
+= bytes_read
;
5855 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5856 dwarf_form_name (attr
.form
),
5857 objfile_name (objfile
));
5860 switch (attr
.dw_idx
)
5862 case DW_IDX_compile_unit
:
5863 /* Don't crash on bad data. */
5864 if (ull
>= dwarf2_per_objfile
->all_comp_units
.size ())
5866 complaint (_(".debug_names entry has bad CU index %s"
5869 objfile_name (dwarf2_per_objfile
->objfile
));
5872 per_cu
= dwarf2_per_objfile
->get_cutu (ull
);
5874 case DW_IDX_type_unit
:
5875 /* Don't crash on bad data. */
5876 if (ull
>= dwarf2_per_objfile
->all_type_units
.size ())
5878 complaint (_(".debug_names entry has bad TU index %s"
5881 objfile_name (dwarf2_per_objfile
->objfile
));
5884 per_cu
= &dwarf2_per_objfile
->get_tu (ull
)->per_cu
;
5886 case DW_IDX_GNU_internal
:
5887 if (!m_map
.augmentation_is_gdb
)
5889 symbol_linkage_
= symbol_linkage::static_
;
5891 case DW_IDX_GNU_external
:
5892 if (!m_map
.augmentation_is_gdb
)
5894 symbol_linkage_
= symbol_linkage::extern_
;
5899 /* Skip if already read in. */
5900 if (per_cu
->v
.quick
->compunit_symtab
)
5903 /* Check static vs global. */
5904 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5906 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5907 const bool symbol_is_static
=
5908 symbol_linkage_
== symbol_linkage::static_
;
5909 if (want_static
!= symbol_is_static
)
5913 /* Match dw2_symtab_iter_next, symbol_kind
5914 and debug_names::psymbol_tag. */
5918 switch (indexval
.dwarf_tag
)
5920 case DW_TAG_variable
:
5921 case DW_TAG_subprogram
:
5922 /* Some types are also in VAR_DOMAIN. */
5923 case DW_TAG_typedef
:
5924 case DW_TAG_structure_type
:
5931 switch (indexval
.dwarf_tag
)
5933 case DW_TAG_typedef
:
5934 case DW_TAG_structure_type
:
5941 switch (indexval
.dwarf_tag
)
5944 case DW_TAG_variable
:
5954 /* Match dw2_expand_symtabs_matching, symbol_kind and
5955 debug_names::psymbol_tag. */
5958 case VARIABLES_DOMAIN
:
5959 switch (indexval
.dwarf_tag
)
5961 case DW_TAG_variable
:
5967 case FUNCTIONS_DOMAIN
:
5968 switch (indexval
.dwarf_tag
)
5970 case DW_TAG_subprogram
:
5977 switch (indexval
.dwarf_tag
)
5979 case DW_TAG_typedef
:
5980 case DW_TAG_structure_type
:
5993 static struct compunit_symtab
*
5994 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
5995 const char *name
, domain_enum domain
)
5997 struct dwarf2_per_objfile
*dwarf2_per_objfile
5998 = get_dwarf2_per_objfile (objfile
);
6000 const auto &mapp
= dwarf2_per_objfile
->debug_names_table
;
6003 /* index is NULL if OBJF_READNOW. */
6006 const auto &map
= *mapp
;
6008 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
);
6010 struct compunit_symtab
*stab_best
= NULL
;
6011 struct dwarf2_per_cu_data
*per_cu
;
6012 while ((per_cu
= iter
.next ()) != NULL
)
6014 struct symbol
*sym
, *with_opaque
= NULL
;
6015 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
6016 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
6017 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
6019 sym
= block_find_symbol (block
, name
, domain
,
6020 block_find_non_opaque_type_preferred
,
6023 /* Some caution must be observed with overloaded functions and
6024 methods, since the index will not contain any overload
6025 information (but NAME might contain it). */
6028 && strcmp_iw (SYMBOL_SEARCH_NAME (sym
), name
) == 0)
6030 if (with_opaque
!= NULL
6031 && strcmp_iw (SYMBOL_SEARCH_NAME (with_opaque
), name
) == 0)
6034 /* Keep looking through other CUs. */
6040 /* This dumps minimal information about .debug_names. It is called
6041 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
6042 uses this to verify that .debug_names has been loaded. */
6045 dw2_debug_names_dump (struct objfile
*objfile
)
6047 struct dwarf2_per_objfile
*dwarf2_per_objfile
6048 = get_dwarf2_per_objfile (objfile
);
6050 gdb_assert (dwarf2_per_objfile
->using_index
);
6051 printf_filtered (".debug_names:");
6052 if (dwarf2_per_objfile
->debug_names_table
)
6053 printf_filtered (" exists\n");
6055 printf_filtered (" faked for \"readnow\"\n");
6056 printf_filtered ("\n");
6060 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
6061 const char *func_name
)
6063 struct dwarf2_per_objfile
*dwarf2_per_objfile
6064 = get_dwarf2_per_objfile (objfile
);
6066 /* dwarf2_per_objfile->debug_names_table is NULL if OBJF_READNOW. */
6067 if (dwarf2_per_objfile
->debug_names_table
)
6069 const mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6071 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
);
6073 struct dwarf2_per_cu_data
*per_cu
;
6074 while ((per_cu
= iter
.next ()) != NULL
)
6075 dw2_instantiate_symtab (per_cu
, false);
6080 dw2_debug_names_map_matching_symbols
6081 (struct objfile
*objfile
,
6082 const lookup_name_info
&name
, domain_enum domain
,
6084 gdb::function_view
<symbol_found_callback_ftype
> callback
,
6085 symbol_compare_ftype
*ordered_compare
)
6087 struct dwarf2_per_objfile
*dwarf2_per_objfile
6088 = get_dwarf2_per_objfile (objfile
);
6090 /* debug_names_table is NULL if OBJF_READNOW. */
6091 if (!dwarf2_per_objfile
->debug_names_table
)
6094 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6095 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
6097 const char *match_name
= name
.ada ().lookup_name ().c_str ();
6098 auto matcher
= [&] (const char *symname
)
6100 if (ordered_compare
== nullptr)
6102 return ordered_compare (symname
, match_name
) == 0;
6105 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
6106 [&] (offset_type namei
)
6108 /* The name was matched, now expand corresponding CUs that were
6110 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
);
6112 struct dwarf2_per_cu_data
*per_cu
;
6113 while ((per_cu
= iter
.next ()) != NULL
)
6114 dw2_expand_symtabs_matching_one (per_cu
, nullptr, nullptr);
6118 /* It's a shame we couldn't do this inside the
6119 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
6120 that have already been expanded. Instead, this loop matches what
6121 the psymtab code does. */
6122 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
6124 struct compunit_symtab
*cust
= per_cu
->v
.quick
->compunit_symtab
;
6125 if (cust
!= nullptr)
6127 const struct block
*block
6128 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
6129 if (!iterate_over_symbols_terminated (block
, name
,
6137 dw2_debug_names_expand_symtabs_matching
6138 (struct objfile
*objfile
,
6139 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
6140 const lookup_name_info
&lookup_name
,
6141 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
6142 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
6143 enum search_domain kind
)
6145 struct dwarf2_per_objfile
*dwarf2_per_objfile
6146 = get_dwarf2_per_objfile (objfile
);
6148 /* debug_names_table is NULL if OBJF_READNOW. */
6149 if (!dwarf2_per_objfile
->debug_names_table
)
6152 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
6154 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6156 dw2_expand_symtabs_matching_symbol (map
, lookup_name
,
6158 kind
, [&] (offset_type namei
)
6160 /* The name was matched, now expand corresponding CUs that were
6162 dw2_debug_names_iterator
iter (map
, kind
, namei
);
6164 struct dwarf2_per_cu_data
*per_cu
;
6165 while ((per_cu
= iter
.next ()) != NULL
)
6166 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
6172 const struct quick_symbol_functions dwarf2_debug_names_functions
=
6175 dw2_find_last_source_symtab
,
6176 dw2_forget_cached_source_info
,
6177 dw2_map_symtabs_matching_filename
,
6178 dw2_debug_names_lookup_symbol
,
6180 dw2_debug_names_dump
,
6181 dw2_debug_names_expand_symtabs_for_function
,
6182 dw2_expand_all_symtabs
,
6183 dw2_expand_symtabs_with_fullname
,
6184 dw2_debug_names_map_matching_symbols
,
6185 dw2_debug_names_expand_symtabs_matching
,
6186 dw2_find_pc_sect_compunit_symtab
,
6188 dw2_map_symbol_filenames
6191 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
6192 to either a dwarf2_per_objfile or dwz_file object. */
6194 template <typename T
>
6195 static gdb::array_view
<const gdb_byte
>
6196 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
6198 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
6200 if (dwarf2_section_empty_p (section
))
6203 /* Older elfutils strip versions could keep the section in the main
6204 executable while splitting it for the separate debug info file. */
6205 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
6208 dwarf2_read_section (obj
, section
);
6210 /* dwarf2_section_info::size is a bfd_size_type, while
6211 gdb::array_view works with size_t. On 32-bit hosts, with
6212 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
6213 is 32-bit. So we need an explicit narrowing conversion here.
6214 This is fine, because it's impossible to allocate or mmap an
6215 array/buffer larger than what size_t can represent. */
6216 return gdb::make_array_view (section
->buffer
, section
->size
);
6219 /* Lookup the index cache for the contents of the index associated to
6222 static gdb::array_view
<const gdb_byte
>
6223 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_objfile
*dwarf2_obj
)
6225 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
6226 if (build_id
== nullptr)
6229 return global_index_cache
.lookup_gdb_index (build_id
,
6230 &dwarf2_obj
->index_cache_res
);
6233 /* Same as the above, but for DWZ. */
6235 static gdb::array_view
<const gdb_byte
>
6236 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
6238 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
6239 if (build_id
== nullptr)
6242 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
6245 /* See symfile.h. */
6248 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
6250 struct dwarf2_per_objfile
*dwarf2_per_objfile
6251 = get_dwarf2_per_objfile (objfile
);
6253 /* If we're about to read full symbols, don't bother with the
6254 indices. In this case we also don't care if some other debug
6255 format is making psymtabs, because they are all about to be
6257 if ((objfile
->flags
& OBJF_READNOW
))
6259 dwarf2_per_objfile
->using_index
= 1;
6260 create_all_comp_units (dwarf2_per_objfile
);
6261 create_all_type_units (dwarf2_per_objfile
);
6262 dwarf2_per_objfile
->quick_file_names_table
6263 = create_quick_file_names_table
6264 (dwarf2_per_objfile
->all_comp_units
.size ());
6266 for (int i
= 0; i
< (dwarf2_per_objfile
->all_comp_units
.size ()
6267 + dwarf2_per_objfile
->all_type_units
.size ()); ++i
)
6269 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
6271 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6272 struct dwarf2_per_cu_quick_data
);
6275 /* Return 1 so that gdb sees the "quick" functions. However,
6276 these functions will be no-ops because we will have expanded
6278 *index_kind
= dw_index_kind::GDB_INDEX
;
6282 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
6284 *index_kind
= dw_index_kind::DEBUG_NAMES
;
6288 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
6289 get_gdb_index_contents_from_section
<struct dwarf2_per_objfile
>,
6290 get_gdb_index_contents_from_section
<dwz_file
>))
6292 *index_kind
= dw_index_kind::GDB_INDEX
;
6296 /* ... otherwise, try to find the index in the index cache. */
6297 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
6298 get_gdb_index_contents_from_cache
,
6299 get_gdb_index_contents_from_cache_dwz
))
6301 global_index_cache
.hit ();
6302 *index_kind
= dw_index_kind::GDB_INDEX
;
6306 global_index_cache
.miss ();
6312 /* Build a partial symbol table. */
6315 dwarf2_build_psymtabs (struct objfile
*objfile
)
6317 struct dwarf2_per_objfile
*dwarf2_per_objfile
6318 = get_dwarf2_per_objfile (objfile
);
6320 init_psymbol_list (objfile
, 1024);
6324 /* This isn't really ideal: all the data we allocate on the
6325 objfile's obstack is still uselessly kept around. However,
6326 freeing it seems unsafe. */
6327 psymtab_discarder
psymtabs (objfile
);
6328 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
6331 /* (maybe) store an index in the cache. */
6332 global_index_cache
.store (dwarf2_per_objfile
);
6334 catch (const gdb_exception_error
&except
)
6336 exception_print (gdb_stderr
, except
);
6340 /* Return the total length of the CU described by HEADER. */
6343 get_cu_length (const struct comp_unit_head
*header
)
6345 return header
->initial_length_size
+ header
->length
;
6348 /* Return TRUE if SECT_OFF is within CU_HEADER. */
6351 offset_in_cu_p (const comp_unit_head
*cu_header
, sect_offset sect_off
)
6353 sect_offset bottom
= cu_header
->sect_off
;
6354 sect_offset top
= cu_header
->sect_off
+ get_cu_length (cu_header
);
6356 return sect_off
>= bottom
&& sect_off
< top
;
6359 /* Find the base address of the compilation unit for range lists and
6360 location lists. It will normally be specified by DW_AT_low_pc.
6361 In DWARF-3 draft 4, the base address could be overridden by
6362 DW_AT_entry_pc. It's been removed, but GCC still uses this for
6363 compilation units with discontinuous ranges. */
6366 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
6368 struct attribute
*attr
;
6371 cu
->base_address
= 0;
6373 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
6376 cu
->base_address
= attr_value_as_address (attr
);
6381 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6384 cu
->base_address
= attr_value_as_address (attr
);
6390 /* Read in the comp unit header information from the debug_info at info_ptr.
6391 Use rcuh_kind::COMPILE as the default type if not known by the caller.
6392 NOTE: This leaves members offset, first_die_offset to be filled in
6395 static const gdb_byte
*
6396 read_comp_unit_head (struct comp_unit_head
*cu_header
,
6397 const gdb_byte
*info_ptr
,
6398 struct dwarf2_section_info
*section
,
6399 rcuh_kind section_kind
)
6402 unsigned int bytes_read
;
6403 const char *filename
= get_section_file_name (section
);
6404 bfd
*abfd
= get_section_bfd_owner (section
);
6406 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
6407 cu_header
->initial_length_size
= bytes_read
;
6408 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
6409 info_ptr
+= bytes_read
;
6410 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
6411 if (cu_header
->version
< 2 || cu_header
->version
> 5)
6412 error (_("Dwarf Error: wrong version in compilation unit header "
6413 "(is %d, should be 2, 3, 4 or 5) [in module %s]"),
6414 cu_header
->version
, filename
);
6416 if (cu_header
->version
< 5)
6417 switch (section_kind
)
6419 case rcuh_kind::COMPILE
:
6420 cu_header
->unit_type
= DW_UT_compile
;
6422 case rcuh_kind::TYPE
:
6423 cu_header
->unit_type
= DW_UT_type
;
6426 internal_error (__FILE__
, __LINE__
,
6427 _("read_comp_unit_head: invalid section_kind"));
6431 cu_header
->unit_type
= static_cast<enum dwarf_unit_type
>
6432 (read_1_byte (abfd
, info_ptr
));
6434 switch (cu_header
->unit_type
)
6438 case DW_UT_skeleton
:
6439 case DW_UT_split_compile
:
6440 if (section_kind
!= rcuh_kind::COMPILE
)
6441 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6442 "(is %s, should be %s) [in module %s]"),
6443 dwarf_unit_type_name (cu_header
->unit_type
),
6444 dwarf_unit_type_name (DW_UT_type
), filename
);
6447 case DW_UT_split_type
:
6448 section_kind
= rcuh_kind::TYPE
;
6451 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6452 "(is %#04x, should be one of: %s, %s, %s, %s or %s) "
6453 "[in module %s]"), cu_header
->unit_type
,
6454 dwarf_unit_type_name (DW_UT_compile
),
6455 dwarf_unit_type_name (DW_UT_skeleton
),
6456 dwarf_unit_type_name (DW_UT_split_compile
),
6457 dwarf_unit_type_name (DW_UT_type
),
6458 dwarf_unit_type_name (DW_UT_split_type
), filename
);
6461 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6464 cu_header
->abbrev_sect_off
= (sect_offset
) read_offset (abfd
, info_ptr
,
6467 info_ptr
+= bytes_read
;
6468 if (cu_header
->version
< 5)
6470 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6473 signed_addr
= bfd_get_sign_extend_vma (abfd
);
6474 if (signed_addr
< 0)
6475 internal_error (__FILE__
, __LINE__
,
6476 _("read_comp_unit_head: dwarf from non elf file"));
6477 cu_header
->signed_addr_p
= signed_addr
;
6479 bool header_has_signature
= section_kind
== rcuh_kind::TYPE
6480 || cu_header
->unit_type
== DW_UT_skeleton
6481 || cu_header
->unit_type
== DW_UT_split_compile
;
6483 if (header_has_signature
)
6485 cu_header
->signature
= read_8_bytes (abfd
, info_ptr
);
6489 if (section_kind
== rcuh_kind::TYPE
)
6491 LONGEST type_offset
;
6492 type_offset
= read_offset (abfd
, info_ptr
, cu_header
, &bytes_read
);
6493 info_ptr
+= bytes_read
;
6494 cu_header
->type_cu_offset_in_tu
= (cu_offset
) type_offset
;
6495 if (to_underlying (cu_header
->type_cu_offset_in_tu
) != type_offset
)
6496 error (_("Dwarf Error: Too big type_offset in compilation unit "
6497 "header (is %s) [in module %s]"), plongest (type_offset
),
6504 /* Helper function that returns the proper abbrev section for
6507 static struct dwarf2_section_info
*
6508 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
6510 struct dwarf2_section_info
*abbrev
;
6511 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6513 if (this_cu
->is_dwz
)
6514 abbrev
= &dwarf2_get_dwz_file (dwarf2_per_objfile
)->abbrev
;
6516 abbrev
= &dwarf2_per_objfile
->abbrev
;
6521 /* Subroutine of read_and_check_comp_unit_head and
6522 read_and_check_type_unit_head to simplify them.
6523 Perform various error checking on the header. */
6526 error_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6527 struct comp_unit_head
*header
,
6528 struct dwarf2_section_info
*section
,
6529 struct dwarf2_section_info
*abbrev_section
)
6531 const char *filename
= get_section_file_name (section
);
6533 if (to_underlying (header
->abbrev_sect_off
)
6534 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
, abbrev_section
))
6535 error (_("Dwarf Error: bad offset (%s) in compilation unit header "
6536 "(offset %s + 6) [in module %s]"),
6537 sect_offset_str (header
->abbrev_sect_off
),
6538 sect_offset_str (header
->sect_off
),
6541 /* Cast to ULONGEST to use 64-bit arithmetic when possible to
6542 avoid potential 32-bit overflow. */
6543 if (((ULONGEST
) header
->sect_off
+ get_cu_length (header
))
6545 error (_("Dwarf Error: bad length (0x%x) in compilation unit header "
6546 "(offset %s + 0) [in module %s]"),
6547 header
->length
, sect_offset_str (header
->sect_off
),
6551 /* Read in a CU/TU header and perform some basic error checking.
6552 The contents of the header are stored in HEADER.
6553 The result is a pointer to the start of the first DIE. */
6555 static const gdb_byte
*
6556 read_and_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6557 struct comp_unit_head
*header
,
6558 struct dwarf2_section_info
*section
,
6559 struct dwarf2_section_info
*abbrev_section
,
6560 const gdb_byte
*info_ptr
,
6561 rcuh_kind section_kind
)
6563 const gdb_byte
*beg_of_comp_unit
= info_ptr
;
6565 header
->sect_off
= (sect_offset
) (beg_of_comp_unit
- section
->buffer
);
6567 info_ptr
= read_comp_unit_head (header
, info_ptr
, section
, section_kind
);
6569 header
->first_die_cu_offset
= (cu_offset
) (info_ptr
- beg_of_comp_unit
);
6571 error_check_comp_unit_head (dwarf2_per_objfile
, header
, section
,
6577 /* Fetch the abbreviation table offset from a comp or type unit header. */
6580 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6581 struct dwarf2_section_info
*section
,
6582 sect_offset sect_off
)
6584 bfd
*abfd
= get_section_bfd_owner (section
);
6585 const gdb_byte
*info_ptr
;
6586 unsigned int initial_length_size
, offset_size
;
6589 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
6590 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
6591 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6592 offset_size
= initial_length_size
== 4 ? 4 : 8;
6593 info_ptr
+= initial_length_size
;
6595 version
= read_2_bytes (abfd
, info_ptr
);
6599 /* Skip unit type and address size. */
6603 return (sect_offset
) read_offset_1 (abfd
, info_ptr
, offset_size
);
6606 /* Allocate a new partial symtab for file named NAME and mark this new
6607 partial symtab as being an include of PST. */
6610 dwarf2_create_include_psymtab (const char *name
, struct partial_symtab
*pst
,
6611 struct objfile
*objfile
)
6613 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
6615 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6617 /* It shares objfile->objfile_obstack. */
6618 subpst
->dirname
= pst
->dirname
;
6621 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
6622 subpst
->dependencies
[0] = pst
;
6623 subpst
->number_of_dependencies
= 1;
6625 subpst
->read_symtab
= pst
->read_symtab
;
6627 /* No private part is necessary for include psymtabs. This property
6628 can be used to differentiate between such include psymtabs and
6629 the regular ones. */
6630 subpst
->read_symtab_private
= NULL
;
6633 /* Read the Line Number Program data and extract the list of files
6634 included by the source file represented by PST. Build an include
6635 partial symtab for each of these included files. */
6638 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
6639 struct die_info
*die
,
6640 struct partial_symtab
*pst
)
6643 struct attribute
*attr
;
6645 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6647 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
6649 return; /* No linetable, so no includes. */
6651 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
6652 that we pass in the raw text_low here; that is ok because we're
6653 only decoding the line table to make include partial symtabs, and
6654 so the addresses aren't really used. */
6655 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
6656 pst
->raw_text_low (), 1);
6660 hash_signatured_type (const void *item
)
6662 const struct signatured_type
*sig_type
6663 = (const struct signatured_type
*) item
;
6665 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6666 return sig_type
->signature
;
6670 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6672 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6673 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6675 return lhs
->signature
== rhs
->signature
;
6678 /* Allocate a hash table for signatured types. */
6681 allocate_signatured_type_table (struct objfile
*objfile
)
6683 return htab_create_alloc_ex (41,
6684 hash_signatured_type
,
6687 &objfile
->objfile_obstack
,
6688 hashtab_obstack_allocate
,
6689 dummy_obstack_deallocate
);
6692 /* A helper function to add a signatured type CU to a table. */
6695 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6697 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6698 std::vector
<signatured_type
*> *all_type_units
6699 = (std::vector
<signatured_type
*> *) datum
;
6701 all_type_units
->push_back (sigt
);
6706 /* A helper for create_debug_types_hash_table. Read types from SECTION
6707 and fill them into TYPES_HTAB. It will process only type units,
6708 therefore DW_UT_type. */
6711 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6712 struct dwo_file
*dwo_file
,
6713 dwarf2_section_info
*section
, htab_t
&types_htab
,
6714 rcuh_kind section_kind
)
6716 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6717 struct dwarf2_section_info
*abbrev_section
;
6719 const gdb_byte
*info_ptr
, *end_ptr
;
6721 abbrev_section
= (dwo_file
!= NULL
6722 ? &dwo_file
->sections
.abbrev
6723 : &dwarf2_per_objfile
->abbrev
);
6725 if (dwarf_read_debug
)
6726 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6727 get_section_name (section
),
6728 get_section_file_name (abbrev_section
));
6730 dwarf2_read_section (objfile
, section
);
6731 info_ptr
= section
->buffer
;
6733 if (info_ptr
== NULL
)
6736 /* We can't set abfd until now because the section may be empty or
6737 not present, in which case the bfd is unknown. */
6738 abfd
= get_section_bfd_owner (section
);
6740 /* We don't use init_cutu_and_read_dies_simple, or some such, here
6741 because we don't need to read any dies: the signature is in the
6744 end_ptr
= info_ptr
+ section
->size
;
6745 while (info_ptr
< end_ptr
)
6747 struct signatured_type
*sig_type
;
6748 struct dwo_unit
*dwo_tu
;
6750 const gdb_byte
*ptr
= info_ptr
;
6751 struct comp_unit_head header
;
6752 unsigned int length
;
6754 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6756 /* Initialize it due to a false compiler warning. */
6757 header
.signature
= -1;
6758 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6760 /* We need to read the type's signature in order to build the hash
6761 table, but we don't need anything else just yet. */
6763 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
6764 abbrev_section
, ptr
, section_kind
);
6766 length
= get_cu_length (&header
);
6768 /* Skip dummy type units. */
6769 if (ptr
>= info_ptr
+ length
6770 || peek_abbrev_code (abfd
, ptr
) == 0
6771 || header
.unit_type
!= DW_UT_type
)
6777 if (types_htab
== NULL
)
6780 types_htab
= allocate_dwo_unit_table (objfile
);
6782 types_htab
= allocate_signatured_type_table (objfile
);
6788 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6790 dwo_tu
->dwo_file
= dwo_file
;
6791 dwo_tu
->signature
= header
.signature
;
6792 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6793 dwo_tu
->section
= section
;
6794 dwo_tu
->sect_off
= sect_off
;
6795 dwo_tu
->length
= length
;
6799 /* N.B.: type_offset is not usable if this type uses a DWO file.
6800 The real type_offset is in the DWO file. */
6802 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6803 struct signatured_type
);
6804 sig_type
->signature
= header
.signature
;
6805 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6806 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6807 sig_type
->per_cu
.is_debug_types
= 1;
6808 sig_type
->per_cu
.section
= section
;
6809 sig_type
->per_cu
.sect_off
= sect_off
;
6810 sig_type
->per_cu
.length
= length
;
6813 slot
= htab_find_slot (types_htab
,
6814 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6816 gdb_assert (slot
!= NULL
);
6819 sect_offset dup_sect_off
;
6823 const struct dwo_unit
*dup_tu
6824 = (const struct dwo_unit
*) *slot
;
6826 dup_sect_off
= dup_tu
->sect_off
;
6830 const struct signatured_type
*dup_tu
6831 = (const struct signatured_type
*) *slot
;
6833 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6836 complaint (_("debug type entry at offset %s is duplicate to"
6837 " the entry at offset %s, signature %s"),
6838 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6839 hex_string (header
.signature
));
6841 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6843 if (dwarf_read_debug
> 1)
6844 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6845 sect_offset_str (sect_off
),
6846 hex_string (header
.signature
));
6852 /* Create the hash table of all entries in the .debug_types
6853 (or .debug_types.dwo) section(s).
6854 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6855 otherwise it is NULL.
6857 The result is a pointer to the hash table or NULL if there are no types.
6859 Note: This function processes DWO files only, not DWP files. */
6862 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6863 struct dwo_file
*dwo_file
,
6864 gdb::array_view
<dwarf2_section_info
> type_sections
,
6867 for (dwarf2_section_info
§ion
: type_sections
)
6868 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, §ion
,
6869 types_htab
, rcuh_kind::TYPE
);
6872 /* Create the hash table of all entries in the .debug_types section,
6873 and initialize all_type_units.
6874 The result is zero if there is an error (e.g. missing .debug_types section),
6875 otherwise non-zero. */
6878 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6880 htab_t types_htab
= NULL
;
6882 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
6883 &dwarf2_per_objfile
->info
, types_htab
,
6884 rcuh_kind::COMPILE
);
6885 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
6886 dwarf2_per_objfile
->types
, types_htab
);
6887 if (types_htab
== NULL
)
6889 dwarf2_per_objfile
->signatured_types
= NULL
;
6893 dwarf2_per_objfile
->signatured_types
= types_htab
;
6895 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
6896 dwarf2_per_objfile
->all_type_units
.reserve (htab_elements (types_htab
));
6898 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
,
6899 &dwarf2_per_objfile
->all_type_units
);
6904 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
6905 If SLOT is non-NULL, it is the entry to use in the hash table.
6906 Otherwise we find one. */
6908 static struct signatured_type
*
6909 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
6912 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6914 if (dwarf2_per_objfile
->all_type_units
.size ()
6915 == dwarf2_per_objfile
->all_type_units
.capacity ())
6916 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
6918 signatured_type
*sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6919 struct signatured_type
);
6921 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
6922 sig_type
->signature
= sig
;
6923 sig_type
->per_cu
.is_debug_types
= 1;
6924 if (dwarf2_per_objfile
->using_index
)
6926 sig_type
->per_cu
.v
.quick
=
6927 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6928 struct dwarf2_per_cu_quick_data
);
6933 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
6936 gdb_assert (*slot
== NULL
);
6938 /* The rest of sig_type must be filled in by the caller. */
6942 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6943 Fill in SIG_ENTRY with DWO_ENTRY. */
6946 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6947 struct signatured_type
*sig_entry
,
6948 struct dwo_unit
*dwo_entry
)
6950 /* Make sure we're not clobbering something we don't expect to. */
6951 gdb_assert (! sig_entry
->per_cu
.queued
);
6952 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
6953 if (dwarf2_per_objfile
->using_index
)
6955 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6956 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
6959 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6960 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6961 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6962 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6963 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6965 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6966 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6967 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6968 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6969 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6970 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6971 sig_entry
->dwo_unit
= dwo_entry
;
6974 /* Subroutine of lookup_signatured_type.
6975 If we haven't read the TU yet, create the signatured_type data structure
6976 for a TU to be read in directly from a DWO file, bypassing the stub.
6977 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6978 using .gdb_index, then when reading a CU we want to stay in the DWO file
6979 containing that CU. Otherwise we could end up reading several other DWO
6980 files (due to comdat folding) to process the transitive closure of all the
6981 mentioned TUs, and that can be slow. The current DWO file will have every
6982 type signature that it needs.
6983 We only do this for .gdb_index because in the psymtab case we already have
6984 to read all the DWOs to build the type unit groups. */
6986 static struct signatured_type
*
6987 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6989 struct dwarf2_per_objfile
*dwarf2_per_objfile
6990 = cu
->per_cu
->dwarf2_per_objfile
;
6991 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6992 struct dwo_file
*dwo_file
;
6993 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6994 struct signatured_type find_sig_entry
, *sig_entry
;
6997 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6999 /* If TU skeletons have been removed then we may not have read in any
7001 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7003 dwarf2_per_objfile
->signatured_types
7004 = allocate_signatured_type_table (objfile
);
7007 /* We only ever need to read in one copy of a signatured type.
7008 Use the global signatured_types array to do our own comdat-folding
7009 of types. If this is the first time we're reading this TU, and
7010 the TU has an entry in .gdb_index, replace the recorded data from
7011 .gdb_index with this TU. */
7013 find_sig_entry
.signature
= sig
;
7014 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
7015 &find_sig_entry
, INSERT
);
7016 sig_entry
= (struct signatured_type
*) *slot
;
7018 /* We can get here with the TU already read, *or* in the process of being
7019 read. Don't reassign the global entry to point to this DWO if that's
7020 the case. Also note that if the TU is already being read, it may not
7021 have come from a DWO, the program may be a mix of Fission-compiled
7022 code and non-Fission-compiled code. */
7024 /* Have we already tried to read this TU?
7025 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
7026 needn't exist in the global table yet). */
7027 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
7030 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
7031 dwo_unit of the TU itself. */
7032 dwo_file
= cu
->dwo_unit
->dwo_file
;
7034 /* Ok, this is the first time we're reading this TU. */
7035 if (dwo_file
->tus
== NULL
)
7037 find_dwo_entry
.signature
= sig
;
7038 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_entry
);
7039 if (dwo_entry
== NULL
)
7042 /* If the global table doesn't have an entry for this TU, add one. */
7043 if (sig_entry
== NULL
)
7044 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
7046 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
7047 sig_entry
->per_cu
.tu_read
= 1;
7051 /* Subroutine of lookup_signatured_type.
7052 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
7053 then try the DWP file. If the TU stub (skeleton) has been removed then
7054 it won't be in .gdb_index. */
7056 static struct signatured_type
*
7057 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7059 struct dwarf2_per_objfile
*dwarf2_per_objfile
7060 = cu
->per_cu
->dwarf2_per_objfile
;
7061 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7062 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
7063 struct dwo_unit
*dwo_entry
;
7064 struct signatured_type find_sig_entry
, *sig_entry
;
7067 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
7068 gdb_assert (dwp_file
!= NULL
);
7070 /* If TU skeletons have been removed then we may not have read in any
7072 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7074 dwarf2_per_objfile
->signatured_types
7075 = allocate_signatured_type_table (objfile
);
7078 find_sig_entry
.signature
= sig
;
7079 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
7080 &find_sig_entry
, INSERT
);
7081 sig_entry
= (struct signatured_type
*) *slot
;
7083 /* Have we already tried to read this TU?
7084 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
7085 needn't exist in the global table yet). */
7086 if (sig_entry
!= NULL
)
7089 if (dwp_file
->tus
== NULL
)
7091 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
7092 sig
, 1 /* is_debug_types */);
7093 if (dwo_entry
== NULL
)
7096 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
7097 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
7102 /* Lookup a signature based type for DW_FORM_ref_sig8.
7103 Returns NULL if signature SIG is not present in the table.
7104 It is up to the caller to complain about this. */
7106 static struct signatured_type
*
7107 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7109 struct dwarf2_per_objfile
*dwarf2_per_objfile
7110 = cu
->per_cu
->dwarf2_per_objfile
;
7113 && dwarf2_per_objfile
->using_index
)
7115 /* We're in a DWO/DWP file, and we're using .gdb_index.
7116 These cases require special processing. */
7117 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
7118 return lookup_dwo_signatured_type (cu
, sig
);
7120 return lookup_dwp_signatured_type (cu
, sig
);
7124 struct signatured_type find_entry
, *entry
;
7126 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7128 find_entry
.signature
= sig
;
7129 entry
= ((struct signatured_type
*)
7130 htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
));
7135 /* Low level DIE reading support. */
7137 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
7140 init_cu_die_reader (struct die_reader_specs
*reader
,
7141 struct dwarf2_cu
*cu
,
7142 struct dwarf2_section_info
*section
,
7143 struct dwo_file
*dwo_file
,
7144 struct abbrev_table
*abbrev_table
)
7146 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
7147 reader
->abfd
= get_section_bfd_owner (section
);
7149 reader
->dwo_file
= dwo_file
;
7150 reader
->die_section
= section
;
7151 reader
->buffer
= section
->buffer
;
7152 reader
->buffer_end
= section
->buffer
+ section
->size
;
7153 reader
->comp_dir
= NULL
;
7154 reader
->abbrev_table
= abbrev_table
;
7157 /* Subroutine of init_cutu_and_read_dies to simplify it.
7158 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
7159 There's just a lot of work to do, and init_cutu_and_read_dies is big enough
7162 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
7163 from it to the DIE in the DWO. If NULL we are skipping the stub.
7164 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
7165 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
7166 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
7167 STUB_COMP_DIR may be non-NULL.
7168 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE,*RESULT_HAS_CHILDREN
7169 are filled in with the info of the DIE from the DWO file.
7170 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
7171 from the dwo. Since *RESULT_READER references this abbrev table, it must be
7172 kept around for at least as long as *RESULT_READER.
7174 The result is non-zero if a valid (non-dummy) DIE was found. */
7177 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
7178 struct dwo_unit
*dwo_unit
,
7179 struct die_info
*stub_comp_unit_die
,
7180 const char *stub_comp_dir
,
7181 struct die_reader_specs
*result_reader
,
7182 const gdb_byte
**result_info_ptr
,
7183 struct die_info
**result_comp_unit_die
,
7184 int *result_has_children
,
7185 abbrev_table_up
*result_dwo_abbrev_table
)
7187 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7188 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7189 struct dwarf2_cu
*cu
= this_cu
->cu
;
7191 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7192 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
7193 int i
,num_extra_attrs
;
7194 struct dwarf2_section_info
*dwo_abbrev_section
;
7195 struct attribute
*attr
;
7196 struct die_info
*comp_unit_die
;
7198 /* At most one of these may be provided. */
7199 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
7201 /* These attributes aren't processed until later:
7202 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
7203 DW_AT_comp_dir is used now, to find the DWO file, but it is also
7204 referenced later. However, these attributes are found in the stub
7205 which we won't have later. In order to not impose this complication
7206 on the rest of the code, we read them here and copy them to the
7215 if (stub_comp_unit_die
!= NULL
)
7217 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
7219 if (! this_cu
->is_debug_types
)
7220 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
7221 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
7222 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
7223 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
7224 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
7226 /* There should be a DW_AT_addr_base attribute here (if needed).
7227 We need the value before we can process DW_FORM_GNU_addr_index
7228 or DW_FORM_addrx. */
7230 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
7232 cu
->addr_base
= DW_UNSND (attr
);
7234 /* There should be a DW_AT_ranges_base attribute here (if needed).
7235 We need the value before we can process DW_AT_ranges. */
7236 cu
->ranges_base
= 0;
7237 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_ranges_base
, cu
);
7239 cu
->ranges_base
= DW_UNSND (attr
);
7241 else if (stub_comp_dir
!= NULL
)
7243 /* Reconstruct the comp_dir attribute to simplify the code below. */
7244 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
7245 comp_dir
->name
= DW_AT_comp_dir
;
7246 comp_dir
->form
= DW_FORM_string
;
7247 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
7248 DW_STRING (comp_dir
) = stub_comp_dir
;
7251 /* Set up for reading the DWO CU/TU. */
7252 cu
->dwo_unit
= dwo_unit
;
7253 dwarf2_section_info
*section
= dwo_unit
->section
;
7254 dwarf2_read_section (objfile
, section
);
7255 abfd
= get_section_bfd_owner (section
);
7256 begin_info_ptr
= info_ptr
= (section
->buffer
7257 + to_underlying (dwo_unit
->sect_off
));
7258 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
7260 if (this_cu
->is_debug_types
)
7262 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
7264 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7265 &cu
->header
, section
,
7267 info_ptr
, rcuh_kind::TYPE
);
7268 /* This is not an assert because it can be caused by bad debug info. */
7269 if (sig_type
->signature
!= cu
->header
.signature
)
7271 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
7272 " TU at offset %s [in module %s]"),
7273 hex_string (sig_type
->signature
),
7274 hex_string (cu
->header
.signature
),
7275 sect_offset_str (dwo_unit
->sect_off
),
7276 bfd_get_filename (abfd
));
7278 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7279 /* For DWOs coming from DWP files, we don't know the CU length
7280 nor the type's offset in the TU until now. */
7281 dwo_unit
->length
= get_cu_length (&cu
->header
);
7282 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
7284 /* Establish the type offset that can be used to lookup the type.
7285 For DWO files, we don't know it until now. */
7286 sig_type
->type_offset_in_section
7287 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
7291 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7292 &cu
->header
, section
,
7294 info_ptr
, rcuh_kind::COMPILE
);
7295 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7296 /* For DWOs coming from DWP files, we don't know the CU length
7298 dwo_unit
->length
= get_cu_length (&cu
->header
);
7301 *result_dwo_abbrev_table
7302 = abbrev_table_read_table (dwarf2_per_objfile
, dwo_abbrev_section
,
7303 cu
->header
.abbrev_sect_off
);
7304 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
7305 result_dwo_abbrev_table
->get ());
7307 /* Read in the die, but leave space to copy over the attributes
7308 from the stub. This has the benefit of simplifying the rest of
7309 the code - all the work to maintain the illusion of a single
7310 DW_TAG_{compile,type}_unit DIE is done here. */
7311 num_extra_attrs
= ((stmt_list
!= NULL
)
7315 + (comp_dir
!= NULL
));
7316 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
7317 result_has_children
, num_extra_attrs
);
7319 /* Copy over the attributes from the stub to the DIE we just read in. */
7320 comp_unit_die
= *result_comp_unit_die
;
7321 i
= comp_unit_die
->num_attrs
;
7322 if (stmt_list
!= NULL
)
7323 comp_unit_die
->attrs
[i
++] = *stmt_list
;
7325 comp_unit_die
->attrs
[i
++] = *low_pc
;
7326 if (high_pc
!= NULL
)
7327 comp_unit_die
->attrs
[i
++] = *high_pc
;
7329 comp_unit_die
->attrs
[i
++] = *ranges
;
7330 if (comp_dir
!= NULL
)
7331 comp_unit_die
->attrs
[i
++] = *comp_dir
;
7332 comp_unit_die
->num_attrs
+= num_extra_attrs
;
7334 if (dwarf_die_debug
)
7336 fprintf_unfiltered (gdb_stdlog
,
7337 "Read die from %s@0x%x of %s:\n",
7338 get_section_name (section
),
7339 (unsigned) (begin_info_ptr
- section
->buffer
),
7340 bfd_get_filename (abfd
));
7341 dump_die (comp_unit_die
, dwarf_die_debug
);
7344 /* Save the comp_dir attribute. If there is no DWP file then we'll read
7345 TUs by skipping the stub and going directly to the entry in the DWO file.
7346 However, skipping the stub means we won't get DW_AT_comp_dir, so we have
7347 to get it via circuitous means. Blech. */
7348 if (comp_dir
!= NULL
)
7349 result_reader
->comp_dir
= DW_STRING (comp_dir
);
7351 /* Skip dummy compilation units. */
7352 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
7353 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7356 *result_info_ptr
= info_ptr
;
7360 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
7361 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
7362 signature is part of the header. */
7363 static gdb::optional
<ULONGEST
>
7364 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
7366 if (cu
->header
.version
>= 5)
7367 return cu
->header
.signature
;
7368 struct attribute
*attr
;
7369 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
7370 if (attr
== nullptr)
7371 return gdb::optional
<ULONGEST
> ();
7372 return DW_UNSND (attr
);
7375 /* Subroutine of init_cutu_and_read_dies to simplify it.
7376 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
7377 Returns NULL if the specified DWO unit cannot be found. */
7379 static struct dwo_unit
*
7380 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
7381 struct die_info
*comp_unit_die
)
7383 struct dwarf2_cu
*cu
= this_cu
->cu
;
7384 struct dwo_unit
*dwo_unit
;
7385 const char *comp_dir
, *dwo_name
;
7387 gdb_assert (cu
!= NULL
);
7389 /* Yeah, we look dwo_name up again, but it simplifies the code. */
7390 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7391 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7393 if (this_cu
->is_debug_types
)
7395 struct signatured_type
*sig_type
;
7397 /* Since this_cu is the first member of struct signatured_type,
7398 we can go from a pointer to one to a pointer to the other. */
7399 sig_type
= (struct signatured_type
*) this_cu
;
7400 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
7404 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
7405 if (!signature
.has_value ())
7406 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
7408 dwo_name
, objfile_name (this_cu
->dwarf2_per_objfile
->objfile
));
7409 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
7416 /* Subroutine of init_cutu_and_read_dies to simplify it.
7417 See it for a description of the parameters.
7418 Read a TU directly from a DWO file, bypassing the stub. */
7421 init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
7422 int use_existing_cu
, int keep
,
7423 die_reader_func_ftype
*die_reader_func
,
7426 std::unique_ptr
<dwarf2_cu
> new_cu
;
7427 struct signatured_type
*sig_type
;
7428 struct die_reader_specs reader
;
7429 const gdb_byte
*info_ptr
;
7430 struct die_info
*comp_unit_die
;
7432 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7434 /* Verify we can do the following downcast, and that we have the
7436 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
7437 sig_type
= (struct signatured_type
*) this_cu
;
7438 gdb_assert (sig_type
->dwo_unit
!= NULL
);
7440 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7442 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
7443 /* There's no need to do the rereading_dwo_cu handling that
7444 init_cutu_and_read_dies does since we don't read the stub. */
7448 /* If !use_existing_cu, this_cu->cu must be NULL. */
7449 gdb_assert (this_cu
->cu
== NULL
);
7450 new_cu
.reset (new dwarf2_cu (this_cu
));
7453 /* A future optimization, if needed, would be to use an existing
7454 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
7455 could share abbrev tables. */
7457 /* The abbreviation table used by READER, this must live at least as long as
7459 abbrev_table_up dwo_abbrev_table
;
7461 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
7462 NULL
/* stub_comp_unit_die */,
7463 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
7465 &comp_unit_die
, &has_children
,
7466 &dwo_abbrev_table
) == 0)
7472 /* All the "real" work is done here. */
7473 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7475 /* This duplicates the code in init_cutu_and_read_dies,
7476 but the alternative is making the latter more complex.
7477 This function is only for the special case of using DWO files directly:
7478 no point in overly complicating the general case just to handle this. */
7479 if (new_cu
!= NULL
&& keep
)
7481 /* Link this CU into read_in_chain. */
7482 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
7483 dwarf2_per_objfile
->read_in_chain
= this_cu
;
7484 /* The chain owns it now. */
7489 /* Initialize a CU (or TU) and read its DIEs.
7490 If the CU defers to a DWO file, read the DWO file as well.
7492 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
7493 Otherwise the table specified in the comp unit header is read in and used.
7494 This is an optimization for when we already have the abbrev table.
7496 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
7497 Otherwise, a new CU is allocated with xmalloc.
7499 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
7500 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
7502 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
7503 linker) then DIE_READER_FUNC will not get called. */
7506 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
7507 struct abbrev_table
*abbrev_table
,
7508 int use_existing_cu
, int keep
,
7510 die_reader_func_ftype
*die_reader_func
,
7513 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7514 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7515 struct dwarf2_section_info
*section
= this_cu
->section
;
7516 bfd
*abfd
= get_section_bfd_owner (section
);
7517 struct dwarf2_cu
*cu
;
7518 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7519 struct die_reader_specs reader
;
7520 struct die_info
*comp_unit_die
;
7522 struct signatured_type
*sig_type
= NULL
;
7523 struct dwarf2_section_info
*abbrev_section
;
7524 /* Non-zero if CU currently points to a DWO file and we need to
7525 reread it. When this happens we need to reread the skeleton die
7526 before we can reread the DWO file (this only applies to CUs, not TUs). */
7527 int rereading_dwo_cu
= 0;
7529 if (dwarf_die_debug
)
7530 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7531 this_cu
->is_debug_types
? "type" : "comp",
7532 sect_offset_str (this_cu
->sect_off
));
7534 if (use_existing_cu
)
7537 /* If we're reading a TU directly from a DWO file, including a virtual DWO
7538 file (instead of going through the stub), short-circuit all of this. */
7539 if (this_cu
->reading_dwo_directly
)
7541 /* Narrow down the scope of possibilities to have to understand. */
7542 gdb_assert (this_cu
->is_debug_types
);
7543 gdb_assert (abbrev_table
== NULL
);
7544 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
, keep
,
7545 die_reader_func
, data
);
7549 /* This is cheap if the section is already read in. */
7550 dwarf2_read_section (objfile
, section
);
7552 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7554 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
7556 std::unique_ptr
<dwarf2_cu
> new_cu
;
7557 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7560 /* If this CU is from a DWO file we need to start over, we need to
7561 refetch the attributes from the skeleton CU.
7562 This could be optimized by retrieving those attributes from when we
7563 were here the first time: the previous comp_unit_die was stored in
7564 comp_unit_obstack. But there's no data yet that we need this
7566 if (cu
->dwo_unit
!= NULL
)
7567 rereading_dwo_cu
= 1;
7571 /* If !use_existing_cu, this_cu->cu must be NULL. */
7572 gdb_assert (this_cu
->cu
== NULL
);
7573 new_cu
.reset (new dwarf2_cu (this_cu
));
7577 /* Get the header. */
7578 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
7580 /* We already have the header, there's no need to read it in again. */
7581 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
7585 if (this_cu
->is_debug_types
)
7587 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7588 &cu
->header
, section
,
7589 abbrev_section
, info_ptr
,
7592 /* Since per_cu is the first member of struct signatured_type,
7593 we can go from a pointer to one to a pointer to the other. */
7594 sig_type
= (struct signatured_type
*) this_cu
;
7595 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
7596 gdb_assert (sig_type
->type_offset_in_tu
7597 == cu
->header
.type_cu_offset_in_tu
);
7598 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7600 /* LENGTH has not been set yet for type units if we're
7601 using .gdb_index. */
7602 this_cu
->length
= get_cu_length (&cu
->header
);
7604 /* Establish the type offset that can be used to lookup the type. */
7605 sig_type
->type_offset_in_section
=
7606 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
7608 this_cu
->dwarf_version
= cu
->header
.version
;
7612 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7613 &cu
->header
, section
,
7616 rcuh_kind::COMPILE
);
7618 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7619 gdb_assert (this_cu
->length
== get_cu_length (&cu
->header
));
7620 this_cu
->dwarf_version
= cu
->header
.version
;
7624 /* Skip dummy compilation units. */
7625 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7626 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7629 /* If we don't have them yet, read the abbrevs for this compilation unit.
7630 And if we need to read them now, make sure they're freed when we're
7631 done (own the table through ABBREV_TABLE_HOLDER). */
7632 abbrev_table_up abbrev_table_holder
;
7633 if (abbrev_table
!= NULL
)
7634 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
7638 = abbrev_table_read_table (dwarf2_per_objfile
, abbrev_section
,
7639 cu
->header
.abbrev_sect_off
);
7640 abbrev_table
= abbrev_table_holder
.get ();
7643 /* Read the top level CU/TU die. */
7644 init_cu_die_reader (&reader
, cu
, section
, NULL
, abbrev_table
);
7645 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
7647 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
7650 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
7651 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
7652 table from the DWO file and pass the ownership over to us. It will be
7653 referenced from READER, so we must make sure to free it after we're done
7656 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
7657 DWO CU, that this test will fail (the attribute will not be present). */
7658 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7659 abbrev_table_up dwo_abbrev_table
;
7660 if (dwo_name
!= nullptr)
7662 struct dwo_unit
*dwo_unit
;
7663 struct die_info
*dwo_comp_unit_die
;
7667 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
7668 " has children (offset %s) [in module %s]"),
7669 sect_offset_str (this_cu
->sect_off
),
7670 bfd_get_filename (abfd
));
7672 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
);
7673 if (dwo_unit
!= NULL
)
7675 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
7676 comp_unit_die
, NULL
,
7678 &dwo_comp_unit_die
, &has_children
,
7679 &dwo_abbrev_table
) == 0)
7684 comp_unit_die
= dwo_comp_unit_die
;
7688 /* Yikes, we couldn't find the rest of the DIE, we only have
7689 the stub. A complaint has already been logged. There's
7690 not much more we can do except pass on the stub DIE to
7691 die_reader_func. We don't want to throw an error on bad
7696 /* All of the above is setup for this call. Yikes. */
7697 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7699 /* Done, clean up. */
7700 if (new_cu
!= NULL
&& keep
)
7702 /* Link this CU into read_in_chain. */
7703 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
7704 dwarf2_per_objfile
->read_in_chain
= this_cu
;
7705 /* The chain owns it now. */
7710 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name if present.
7711 DWO_FILE, if non-NULL, is the DWO file to read (the caller is assumed
7712 to have already done the lookup to find the DWO file).
7714 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7715 THIS_CU->is_debug_types, but nothing else.
7717 We fill in THIS_CU->length.
7719 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
7720 linker) then DIE_READER_FUNC will not get called.
7722 THIS_CU->cu is always freed when done.
7723 This is done in order to not leave THIS_CU->cu in a state where we have
7724 to care whether it refers to the "main" CU or the DWO CU. */
7727 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
7728 struct dwo_file
*dwo_file
,
7729 die_reader_func_ftype
*die_reader_func
,
7732 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7733 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7734 struct dwarf2_section_info
*section
= this_cu
->section
;
7735 bfd
*abfd
= get_section_bfd_owner (section
);
7736 struct dwarf2_section_info
*abbrev_section
;
7737 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7738 struct die_reader_specs reader
;
7739 struct die_info
*comp_unit_die
;
7742 if (dwarf_die_debug
)
7743 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7744 this_cu
->is_debug_types
? "type" : "comp",
7745 sect_offset_str (this_cu
->sect_off
));
7747 gdb_assert (this_cu
->cu
== NULL
);
7749 abbrev_section
= (dwo_file
!= NULL
7750 ? &dwo_file
->sections
.abbrev
7751 : get_abbrev_section_for_cu (this_cu
));
7753 /* This is cheap if the section is already read in. */
7754 dwarf2_read_section (objfile
, section
);
7756 struct dwarf2_cu
cu (this_cu
);
7758 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7759 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7760 &cu
.header
, section
,
7761 abbrev_section
, info_ptr
,
7762 (this_cu
->is_debug_types
7764 : rcuh_kind::COMPILE
));
7766 this_cu
->length
= get_cu_length (&cu
.header
);
7768 /* Skip dummy compilation units. */
7769 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7770 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7773 abbrev_table_up abbrev_table
7774 = abbrev_table_read_table (dwarf2_per_objfile
, abbrev_section
,
7775 cu
.header
.abbrev_sect_off
);
7777 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
, abbrev_table
.get ());
7778 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
7780 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7783 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
7784 does not lookup the specified DWO file.
7785 This cannot be used to read DWO files.
7787 THIS_CU->cu is always freed when done.
7788 This is done in order to not leave THIS_CU->cu in a state where we have
7789 to care whether it refers to the "main" CU or the DWO CU.
7790 We can revisit this if the data shows there's a performance issue. */
7793 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
7794 die_reader_func_ftype
*die_reader_func
,
7797 init_cutu_and_read_dies_no_follow (this_cu
, NULL
, die_reader_func
, data
);
7800 /* Type Unit Groups.
7802 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7803 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7804 so that all types coming from the same compilation (.o file) are grouped
7805 together. A future step could be to put the types in the same symtab as
7806 the CU the types ultimately came from. */
7809 hash_type_unit_group (const void *item
)
7811 const struct type_unit_group
*tu_group
7812 = (const struct type_unit_group
*) item
;
7814 return hash_stmt_list_entry (&tu_group
->hash
);
7818 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7820 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7821 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7823 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7826 /* Allocate a hash table for type unit groups. */
7829 allocate_type_unit_groups_table (struct objfile
*objfile
)
7831 return htab_create_alloc_ex (3,
7832 hash_type_unit_group
,
7835 &objfile
->objfile_obstack
,
7836 hashtab_obstack_allocate
,
7837 dummy_obstack_deallocate
);
7840 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7841 partial symtabs. We combine several TUs per psymtab to not let the size
7842 of any one psymtab grow too big. */
7843 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7844 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7846 /* Helper routine for get_type_unit_group.
7847 Create the type_unit_group object used to hold one or more TUs. */
7849 static struct type_unit_group
*
7850 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7852 struct dwarf2_per_objfile
*dwarf2_per_objfile
7853 = cu
->per_cu
->dwarf2_per_objfile
;
7854 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7855 struct dwarf2_per_cu_data
*per_cu
;
7856 struct type_unit_group
*tu_group
;
7858 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7859 struct type_unit_group
);
7860 per_cu
= &tu_group
->per_cu
;
7861 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7863 if (dwarf2_per_objfile
->using_index
)
7865 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7866 struct dwarf2_per_cu_quick_data
);
7870 unsigned int line_offset
= to_underlying (line_offset_struct
);
7871 struct partial_symtab
*pst
;
7874 /* Give the symtab a useful name for debug purposes. */
7875 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7876 name
= string_printf ("<type_units_%d>",
7877 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7879 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7881 pst
= create_partial_symtab (per_cu
, name
.c_str ());
7885 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7886 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7891 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7892 STMT_LIST is a DW_AT_stmt_list attribute. */
7894 static struct type_unit_group
*
7895 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7897 struct dwarf2_per_objfile
*dwarf2_per_objfile
7898 = cu
->per_cu
->dwarf2_per_objfile
;
7899 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7900 struct type_unit_group
*tu_group
;
7902 unsigned int line_offset
;
7903 struct type_unit_group type_unit_group_for_lookup
;
7905 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
7907 dwarf2_per_objfile
->type_unit_groups
=
7908 allocate_type_unit_groups_table (dwarf2_per_objfile
->objfile
);
7911 /* Do we need to create a new group, or can we use an existing one? */
7915 line_offset
= DW_UNSND (stmt_list
);
7916 ++tu_stats
->nr_symtab_sharers
;
7920 /* Ugh, no stmt_list. Rare, but we have to handle it.
7921 We can do various things here like create one group per TU or
7922 spread them over multiple groups to split up the expansion work.
7923 To avoid worst case scenarios (too many groups or too large groups)
7924 we, umm, group them in bunches. */
7925 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7926 | (tu_stats
->nr_stmt_less_type_units
7927 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7928 ++tu_stats
->nr_stmt_less_type_units
;
7931 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7932 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7933 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
,
7934 &type_unit_group_for_lookup
, INSERT
);
7937 tu_group
= (struct type_unit_group
*) *slot
;
7938 gdb_assert (tu_group
!= NULL
);
7942 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7943 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7945 ++tu_stats
->nr_symtabs
;
7951 /* Partial symbol tables. */
7953 /* Create a psymtab named NAME and assign it to PER_CU.
7955 The caller must fill in the following details:
7956 dirname, textlow, texthigh. */
7958 static struct partial_symtab
*
7959 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
7961 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
7962 struct partial_symtab
*pst
;
7964 pst
= start_psymtab_common (objfile
, name
, 0);
7966 pst
->psymtabs_addrmap_supported
= 1;
7968 /* This is the glue that links PST into GDB's symbol API. */
7969 pst
->read_symtab_private
= per_cu
;
7970 pst
->read_symtab
= dwarf2_read_symtab
;
7971 per_cu
->v
.psymtab
= pst
;
7976 /* The DATA object passed to process_psymtab_comp_unit_reader has this
7979 struct process_psymtab_comp_unit_data
7981 /* True if we are reading a DW_TAG_partial_unit. */
7983 int want_partial_unit
;
7985 /* The "pretend" language that is used if the CU doesn't declare a
7988 enum language pretend_language
;
7991 /* die_reader_func for process_psymtab_comp_unit. */
7994 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7995 const gdb_byte
*info_ptr
,
7996 struct die_info
*comp_unit_die
,
8000 struct dwarf2_cu
*cu
= reader
->cu
;
8001 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
8002 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8003 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
8005 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
8006 struct partial_symtab
*pst
;
8007 enum pc_bounds_kind cu_bounds_kind
;
8008 const char *filename
;
8009 struct process_psymtab_comp_unit_data
*info
8010 = (struct process_psymtab_comp_unit_data
*) data
;
8012 if (comp_unit_die
->tag
== DW_TAG_partial_unit
&& !info
->want_partial_unit
)
8015 gdb_assert (! per_cu
->is_debug_types
);
8017 prepare_one_comp_unit (cu
, comp_unit_die
, info
->pretend_language
);
8019 /* Allocate a new partial symbol table structure. */
8020 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
8021 if (filename
== NULL
)
8024 pst
= create_partial_symtab (per_cu
, filename
);
8026 /* This must be done before calling dwarf2_build_include_psymtabs. */
8027 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
8029 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8031 dwarf2_find_base_address (comp_unit_die
, cu
);
8033 /* Possibly set the default values of LOWPC and HIGHPC from
8035 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
8036 &best_highpc
, cu
, pst
);
8037 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
8040 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
8043 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
8045 /* Store the contiguous range if it is not empty; it can be
8046 empty for CUs with no code. */
8047 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8051 /* Check if comp unit has_children.
8052 If so, read the rest of the partial symbols from this comp unit.
8053 If not, there's no more debug_info for this comp unit. */
8056 struct partial_die_info
*first_die
;
8057 CORE_ADDR lowpc
, highpc
;
8059 lowpc
= ((CORE_ADDR
) -1);
8060 highpc
= ((CORE_ADDR
) 0);
8062 first_die
= load_partial_dies (reader
, info_ptr
, 1);
8064 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
8065 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
8067 /* If we didn't find a lowpc, set it to highpc to avoid
8068 complaints from `maint check'. */
8069 if (lowpc
== ((CORE_ADDR
) -1))
8072 /* If the compilation unit didn't have an explicit address range,
8073 then use the information extracted from its child dies. */
8074 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
8077 best_highpc
= highpc
;
8080 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
8081 best_lowpc
+ baseaddr
)
8083 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
8084 best_highpc
+ baseaddr
)
8087 end_psymtab_common (objfile
, pst
);
8089 if (!VEC_empty (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
))
8092 int len
= VEC_length (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
8093 struct dwarf2_per_cu_data
*iter
;
8095 /* Fill in 'dependencies' here; we fill in 'users' in a
8097 pst
->number_of_dependencies
= len
;
8099 = objfile
->partial_symtabs
->allocate_dependencies (len
);
8101 VEC_iterate (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
8104 pst
->dependencies
[i
] = iter
->v
.psymtab
;
8106 VEC_free (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
8109 /* Get the list of files included in the current compilation unit,
8110 and build a psymtab for each of them. */
8111 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
8113 if (dwarf_read_debug
)
8114 fprintf_unfiltered (gdb_stdlog
,
8115 "Psymtab for %s unit @%s: %s - %s"
8116 ", %d global, %d static syms\n",
8117 per_cu
->is_debug_types
? "type" : "comp",
8118 sect_offset_str (per_cu
->sect_off
),
8119 paddress (gdbarch
, pst
->text_low (objfile
)),
8120 paddress (gdbarch
, pst
->text_high (objfile
)),
8121 pst
->n_global_syms
, pst
->n_static_syms
);
8124 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8125 Process compilation unit THIS_CU for a psymtab. */
8128 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8129 int want_partial_unit
,
8130 enum language pretend_language
)
8132 /* If this compilation unit was already read in, free the
8133 cached copy in order to read it in again. This is
8134 necessary because we skipped some symbols when we first
8135 read in the compilation unit (see load_partial_dies).
8136 This problem could be avoided, but the benefit is unclear. */
8137 if (this_cu
->cu
!= NULL
)
8138 free_one_cached_comp_unit (this_cu
);
8140 if (this_cu
->is_debug_types
)
8141 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0, false,
8142 build_type_psymtabs_reader
, NULL
);
8145 process_psymtab_comp_unit_data info
;
8146 info
.want_partial_unit
= want_partial_unit
;
8147 info
.pretend_language
= pretend_language
;
8148 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0, false,
8149 process_psymtab_comp_unit_reader
, &info
);
8152 /* Age out any secondary CUs. */
8153 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
8156 /* Reader function for build_type_psymtabs. */
8159 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
8160 const gdb_byte
*info_ptr
,
8161 struct die_info
*type_unit_die
,
8165 struct dwarf2_per_objfile
*dwarf2_per_objfile
8166 = reader
->cu
->per_cu
->dwarf2_per_objfile
;
8167 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8168 struct dwarf2_cu
*cu
= reader
->cu
;
8169 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
8170 struct signatured_type
*sig_type
;
8171 struct type_unit_group
*tu_group
;
8172 struct attribute
*attr
;
8173 struct partial_die_info
*first_die
;
8174 CORE_ADDR lowpc
, highpc
;
8175 struct partial_symtab
*pst
;
8177 gdb_assert (data
== NULL
);
8178 gdb_assert (per_cu
->is_debug_types
);
8179 sig_type
= (struct signatured_type
*) per_cu
;
8184 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
8185 tu_group
= get_type_unit_group (cu
, attr
);
8187 VEC_safe_push (sig_type_ptr
, tu_group
->tus
, sig_type
);
8189 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
8190 pst
= create_partial_symtab (per_cu
, "");
8193 first_die
= load_partial_dies (reader
, info_ptr
, 1);
8195 lowpc
= (CORE_ADDR
) -1;
8196 highpc
= (CORE_ADDR
) 0;
8197 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
8199 end_psymtab_common (objfile
, pst
);
8202 /* Struct used to sort TUs by their abbreviation table offset. */
8204 struct tu_abbrev_offset
8206 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
8207 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
8210 signatured_type
*sig_type
;
8211 sect_offset abbrev_offset
;
8214 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
8217 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
8218 const struct tu_abbrev_offset
&b
)
8220 return a
.abbrev_offset
< b
.abbrev_offset
;
8223 /* Efficiently read all the type units.
8224 This does the bulk of the work for build_type_psymtabs.
8226 The efficiency is because we sort TUs by the abbrev table they use and
8227 only read each abbrev table once. In one program there are 200K TUs
8228 sharing 8K abbrev tables.
8230 The main purpose of this function is to support building the
8231 dwarf2_per_objfile->type_unit_groups table.
8232 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
8233 can collapse the search space by grouping them by stmt_list.
8234 The savings can be significant, in the same program from above the 200K TUs
8235 share 8K stmt_list tables.
8237 FUNC is expected to call get_type_unit_group, which will create the
8238 struct type_unit_group if necessary and add it to
8239 dwarf2_per_objfile->type_unit_groups. */
8242 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8244 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8245 abbrev_table_up abbrev_table
;
8246 sect_offset abbrev_offset
;
8248 /* It's up to the caller to not call us multiple times. */
8249 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
8251 if (dwarf2_per_objfile
->all_type_units
.empty ())
8254 /* TUs typically share abbrev tables, and there can be way more TUs than
8255 abbrev tables. Sort by abbrev table to reduce the number of times we
8256 read each abbrev table in.
8257 Alternatives are to punt or to maintain a cache of abbrev tables.
8258 This is simpler and efficient enough for now.
8260 Later we group TUs by their DW_AT_stmt_list value (as this defines the
8261 symtab to use). Typically TUs with the same abbrev offset have the same
8262 stmt_list value too so in practice this should work well.
8264 The basic algorithm here is:
8266 sort TUs by abbrev table
8267 for each TU with same abbrev table:
8268 read abbrev table if first user
8269 read TU top level DIE
8270 [IWBN if DWO skeletons had DW_AT_stmt_list]
8273 if (dwarf_read_debug
)
8274 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
8276 /* Sort in a separate table to maintain the order of all_type_units
8277 for .gdb_index: TU indices directly index all_type_units. */
8278 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
8279 sorted_by_abbrev
.reserve (dwarf2_per_objfile
->all_type_units
.size ());
8281 for (signatured_type
*sig_type
: dwarf2_per_objfile
->all_type_units
)
8282 sorted_by_abbrev
.emplace_back
8283 (sig_type
, read_abbrev_offset (dwarf2_per_objfile
,
8284 sig_type
->per_cu
.section
,
8285 sig_type
->per_cu
.sect_off
));
8287 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
8288 sort_tu_by_abbrev_offset
);
8290 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
8292 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
8294 /* Switch to the next abbrev table if necessary. */
8295 if (abbrev_table
== NULL
8296 || tu
.abbrev_offset
!= abbrev_offset
)
8298 abbrev_offset
= tu
.abbrev_offset
;
8300 abbrev_table_read_table (dwarf2_per_objfile
,
8301 &dwarf2_per_objfile
->abbrev
,
8303 ++tu_stats
->nr_uniq_abbrev_tables
;
8306 init_cutu_and_read_dies (&tu
.sig_type
->per_cu
, abbrev_table
.get (),
8307 0, 0, false, build_type_psymtabs_reader
, NULL
);
8311 /* Print collected type unit statistics. */
8314 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8316 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8318 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
8319 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
8320 dwarf2_per_objfile
->all_type_units
.size ());
8321 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
8322 tu_stats
->nr_uniq_abbrev_tables
);
8323 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
8324 tu_stats
->nr_symtabs
);
8325 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
8326 tu_stats
->nr_symtab_sharers
);
8327 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
8328 tu_stats
->nr_stmt_less_type_units
);
8329 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
8330 tu_stats
->nr_all_type_units_reallocs
);
8333 /* Traversal function for build_type_psymtabs. */
8336 build_type_psymtab_dependencies (void **slot
, void *info
)
8338 struct dwarf2_per_objfile
*dwarf2_per_objfile
8339 = (struct dwarf2_per_objfile
*) info
;
8340 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8341 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
8342 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
8343 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8344 int len
= VEC_length (sig_type_ptr
, tu_group
->tus
);
8345 struct signatured_type
*iter
;
8348 gdb_assert (len
> 0);
8349 gdb_assert (IS_TYPE_UNIT_GROUP (per_cu
));
8351 pst
->number_of_dependencies
= len
;
8352 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
8354 VEC_iterate (sig_type_ptr
, tu_group
->tus
, i
, iter
);
8357 gdb_assert (iter
->per_cu
.is_debug_types
);
8358 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
8359 iter
->type_unit_group
= tu_group
;
8362 VEC_free (sig_type_ptr
, tu_group
->tus
);
8367 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8368 Build partial symbol tables for the .debug_types comp-units. */
8371 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8373 if (! create_all_type_units (dwarf2_per_objfile
))
8376 build_type_psymtabs_1 (dwarf2_per_objfile
);
8379 /* Traversal function for process_skeletonless_type_unit.
8380 Read a TU in a DWO file and build partial symbols for it. */
8383 process_skeletonless_type_unit (void **slot
, void *info
)
8385 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
8386 struct dwarf2_per_objfile
*dwarf2_per_objfile
8387 = (struct dwarf2_per_objfile
*) info
;
8388 struct signatured_type find_entry
, *entry
;
8390 /* If this TU doesn't exist in the global table, add it and read it in. */
8392 if (dwarf2_per_objfile
->signatured_types
== NULL
)
8394 dwarf2_per_objfile
->signatured_types
8395 = allocate_signatured_type_table (dwarf2_per_objfile
->objfile
);
8398 find_entry
.signature
= dwo_unit
->signature
;
8399 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
, &find_entry
,
8401 /* If we've already seen this type there's nothing to do. What's happening
8402 is we're doing our own version of comdat-folding here. */
8406 /* This does the job that create_all_type_units would have done for
8408 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
8409 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
8412 /* This does the job that build_type_psymtabs_1 would have done. */
8413 init_cutu_and_read_dies (&entry
->per_cu
, NULL
, 0, 0, false,
8414 build_type_psymtabs_reader
, NULL
);
8419 /* Traversal function for process_skeletonless_type_units. */
8422 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
8424 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
8426 if (dwo_file
->tus
!= NULL
)
8428 htab_traverse_noresize (dwo_file
->tus
,
8429 process_skeletonless_type_unit
, info
);
8435 /* Scan all TUs of DWO files, verifying we've processed them.
8436 This is needed in case a TU was emitted without its skeleton.
8437 Note: This can't be done until we know what all the DWO files are. */
8440 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8442 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
8443 if (get_dwp_file (dwarf2_per_objfile
) == NULL
8444 && dwarf2_per_objfile
->dwo_files
!= NULL
)
8446 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
.get (),
8447 process_dwo_file_for_skeletonless_type_units
,
8448 dwarf2_per_objfile
);
8452 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
8455 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8457 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
8459 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8464 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
8466 /* Set the 'user' field only if it is not already set. */
8467 if (pst
->dependencies
[j
]->user
== NULL
)
8468 pst
->dependencies
[j
]->user
= pst
;
8473 /* Build the partial symbol table by doing a quick pass through the
8474 .debug_info and .debug_abbrev sections. */
8477 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8479 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8481 if (dwarf_read_debug
)
8483 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
8484 objfile_name (objfile
));
8487 dwarf2_per_objfile
->reading_partial_symbols
= 1;
8489 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
8491 /* Any cached compilation units will be linked by the per-objfile
8492 read_in_chain. Make sure to free them when we're done. */
8493 free_cached_comp_units
freer (dwarf2_per_objfile
);
8495 build_type_psymtabs (dwarf2_per_objfile
);
8497 create_all_comp_units (dwarf2_per_objfile
);
8499 /* Create a temporary address map on a temporary obstack. We later
8500 copy this to the final obstack. */
8501 auto_obstack temp_obstack
;
8503 scoped_restore save_psymtabs_addrmap
8504 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
8505 addrmap_create_mutable (&temp_obstack
));
8507 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
8508 process_psymtab_comp_unit (per_cu
, 0, language_minimal
);
8510 /* This has to wait until we read the CUs, we need the list of DWOs. */
8511 process_skeletonless_type_units (dwarf2_per_objfile
);
8513 /* Now that all TUs have been processed we can fill in the dependencies. */
8514 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
8516 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
8517 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
8520 if (dwarf_read_debug
)
8521 print_tu_stats (dwarf2_per_objfile
);
8523 set_partial_user (dwarf2_per_objfile
);
8525 objfile
->partial_symtabs
->psymtabs_addrmap
8526 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
8527 objfile
->partial_symtabs
->obstack ());
8528 /* At this point we want to keep the address map. */
8529 save_psymtabs_addrmap
.release ();
8531 if (dwarf_read_debug
)
8532 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
8533 objfile_name (objfile
));
8536 /* die_reader_func for load_partial_comp_unit. */
8539 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
8540 const gdb_byte
*info_ptr
,
8541 struct die_info
*comp_unit_die
,
8545 struct dwarf2_cu
*cu
= reader
->cu
;
8547 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
8549 /* Check if comp unit has_children.
8550 If so, read the rest of the partial symbols from this comp unit.
8551 If not, there's no more debug_info for this comp unit. */
8553 load_partial_dies (reader
, info_ptr
, 0);
8556 /* Load the partial DIEs for a secondary CU into memory.
8557 This is also used when rereading a primary CU with load_all_dies. */
8560 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
8562 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1, false,
8563 load_partial_comp_unit_reader
, NULL
);
8567 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
8568 struct dwarf2_section_info
*section
,
8569 struct dwarf2_section_info
*abbrev_section
,
8570 unsigned int is_dwz
)
8572 const gdb_byte
*info_ptr
;
8573 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8575 if (dwarf_read_debug
)
8576 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
8577 get_section_name (section
),
8578 get_section_file_name (section
));
8580 dwarf2_read_section (objfile
, section
);
8582 info_ptr
= section
->buffer
;
8584 while (info_ptr
< section
->buffer
+ section
->size
)
8586 struct dwarf2_per_cu_data
*this_cu
;
8588 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
8590 comp_unit_head cu_header
;
8591 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
8592 abbrev_section
, info_ptr
,
8593 rcuh_kind::COMPILE
);
8595 /* Save the compilation unit for later lookup. */
8596 if (cu_header
.unit_type
!= DW_UT_type
)
8598 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
8599 struct dwarf2_per_cu_data
);
8600 memset (this_cu
, 0, sizeof (*this_cu
));
8604 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
8605 struct signatured_type
);
8606 memset (sig_type
, 0, sizeof (*sig_type
));
8607 sig_type
->signature
= cu_header
.signature
;
8608 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
8609 this_cu
= &sig_type
->per_cu
;
8611 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
8612 this_cu
->sect_off
= sect_off
;
8613 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
8614 this_cu
->is_dwz
= is_dwz
;
8615 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
8616 this_cu
->section
= section
;
8618 dwarf2_per_objfile
->all_comp_units
.push_back (this_cu
);
8620 info_ptr
= info_ptr
+ this_cu
->length
;
8624 /* Create a list of all compilation units in OBJFILE.
8625 This is only done for -readnow and building partial symtabs. */
8628 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8630 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
8631 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->info
,
8632 &dwarf2_per_objfile
->abbrev
, 0);
8634 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
8636 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
8640 /* Process all loaded DIEs for compilation unit CU, starting at
8641 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
8642 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
8643 DW_AT_ranges). See the comments of add_partial_subprogram on how
8644 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
8647 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
8648 CORE_ADDR
*highpc
, int set_addrmap
,
8649 struct dwarf2_cu
*cu
)
8651 struct partial_die_info
*pdi
;
8653 /* Now, march along the PDI's, descending into ones which have
8654 interesting children but skipping the children of the other ones,
8655 until we reach the end of the compilation unit. */
8663 /* Anonymous namespaces or modules have no name but have interesting
8664 children, so we need to look at them. Ditto for anonymous
8667 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
8668 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
8669 || pdi
->tag
== DW_TAG_imported_unit
8670 || pdi
->tag
== DW_TAG_inlined_subroutine
)
8674 case DW_TAG_subprogram
:
8675 case DW_TAG_inlined_subroutine
:
8676 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8678 case DW_TAG_constant
:
8679 case DW_TAG_variable
:
8680 case DW_TAG_typedef
:
8681 case DW_TAG_union_type
:
8682 if (!pdi
->is_declaration
)
8684 add_partial_symbol (pdi
, cu
);
8687 case DW_TAG_class_type
:
8688 case DW_TAG_interface_type
:
8689 case DW_TAG_structure_type
:
8690 if (!pdi
->is_declaration
)
8692 add_partial_symbol (pdi
, cu
);
8694 if ((cu
->language
== language_rust
8695 || cu
->language
== language_cplus
) && pdi
->has_children
)
8696 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8699 case DW_TAG_enumeration_type
:
8700 if (!pdi
->is_declaration
)
8701 add_partial_enumeration (pdi
, cu
);
8703 case DW_TAG_base_type
:
8704 case DW_TAG_subrange_type
:
8705 /* File scope base type definitions are added to the partial
8707 add_partial_symbol (pdi
, cu
);
8709 case DW_TAG_namespace
:
8710 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8713 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8715 case DW_TAG_imported_unit
:
8717 struct dwarf2_per_cu_data
*per_cu
;
8719 /* For now we don't handle imported units in type units. */
8720 if (cu
->per_cu
->is_debug_types
)
8722 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8723 " supported in type units [in module %s]"),
8724 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
8727 per_cu
= dwarf2_find_containing_comp_unit
8728 (pdi
->d
.sect_off
, pdi
->is_dwz
,
8729 cu
->per_cu
->dwarf2_per_objfile
);
8731 /* Go read the partial unit, if needed. */
8732 if (per_cu
->v
.psymtab
== NULL
)
8733 process_psymtab_comp_unit (per_cu
, 1, cu
->language
);
8735 VEC_safe_push (dwarf2_per_cu_ptr
,
8736 cu
->per_cu
->imported_symtabs
, per_cu
);
8739 case DW_TAG_imported_declaration
:
8740 add_partial_symbol (pdi
, cu
);
8747 /* If the die has a sibling, skip to the sibling. */
8749 pdi
= pdi
->die_sibling
;
8753 /* Functions used to compute the fully scoped name of a partial DIE.
8755 Normally, this is simple. For C++, the parent DIE's fully scoped
8756 name is concatenated with "::" and the partial DIE's name.
8757 Enumerators are an exception; they use the scope of their parent
8758 enumeration type, i.e. the name of the enumeration type is not
8759 prepended to the enumerator.
8761 There are two complexities. One is DW_AT_specification; in this
8762 case "parent" means the parent of the target of the specification,
8763 instead of the direct parent of the DIE. The other is compilers
8764 which do not emit DW_TAG_namespace; in this case we try to guess
8765 the fully qualified name of structure types from their members'
8766 linkage names. This must be done using the DIE's children rather
8767 than the children of any DW_AT_specification target. We only need
8768 to do this for structures at the top level, i.e. if the target of
8769 any DW_AT_specification (if any; otherwise the DIE itself) does not
8772 /* Compute the scope prefix associated with PDI's parent, in
8773 compilation unit CU. The result will be allocated on CU's
8774 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8775 field. NULL is returned if no prefix is necessary. */
8777 partial_die_parent_scope (struct partial_die_info
*pdi
,
8778 struct dwarf2_cu
*cu
)
8780 const char *grandparent_scope
;
8781 struct partial_die_info
*parent
, *real_pdi
;
8783 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8784 then this means the parent of the specification DIE. */
8787 while (real_pdi
->has_specification
)
8789 auto res
= find_partial_die (real_pdi
->spec_offset
,
8790 real_pdi
->spec_is_dwz
, cu
);
8795 parent
= real_pdi
->die_parent
;
8799 if (parent
->scope_set
)
8800 return parent
->scope
;
8804 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8806 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8807 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8808 Work around this problem here. */
8809 if (cu
->language
== language_cplus
8810 && parent
->tag
== DW_TAG_namespace
8811 && strcmp (parent
->name
, "::") == 0
8812 && grandparent_scope
== NULL
)
8814 parent
->scope
= NULL
;
8815 parent
->scope_set
= 1;
8819 if (pdi
->tag
== DW_TAG_enumerator
)
8820 /* Enumerators should not get the name of the enumeration as a prefix. */
8821 parent
->scope
= grandparent_scope
;
8822 else if (parent
->tag
== DW_TAG_namespace
8823 || parent
->tag
== DW_TAG_module
8824 || parent
->tag
== DW_TAG_structure_type
8825 || parent
->tag
== DW_TAG_class_type
8826 || parent
->tag
== DW_TAG_interface_type
8827 || parent
->tag
== DW_TAG_union_type
8828 || parent
->tag
== DW_TAG_enumeration_type
)
8830 if (grandparent_scope
== NULL
)
8831 parent
->scope
= parent
->name
;
8833 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8835 parent
->name
, 0, cu
);
8839 /* FIXME drow/2004-04-01: What should we be doing with
8840 function-local names? For partial symbols, we should probably be
8842 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8843 dwarf_tag_name (parent
->tag
),
8844 sect_offset_str (pdi
->sect_off
));
8845 parent
->scope
= grandparent_scope
;
8848 parent
->scope_set
= 1;
8849 return parent
->scope
;
8852 /* Return the fully scoped name associated with PDI, from compilation unit
8853 CU. The result will be allocated with malloc. */
8856 partial_die_full_name (struct partial_die_info
*pdi
,
8857 struct dwarf2_cu
*cu
)
8859 const char *parent_scope
;
8861 /* If this is a template instantiation, we can not work out the
8862 template arguments from partial DIEs. So, unfortunately, we have
8863 to go through the full DIEs. At least any work we do building
8864 types here will be reused if full symbols are loaded later. */
8865 if (pdi
->has_template_arguments
)
8869 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
8871 struct die_info
*die
;
8872 struct attribute attr
;
8873 struct dwarf2_cu
*ref_cu
= cu
;
8875 /* DW_FORM_ref_addr is using section offset. */
8876 attr
.name
= (enum dwarf_attribute
) 0;
8877 attr
.form
= DW_FORM_ref_addr
;
8878 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8879 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8881 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8885 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8886 if (parent_scope
== NULL
)
8889 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
8893 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8895 struct dwarf2_per_objfile
*dwarf2_per_objfile
8896 = cu
->per_cu
->dwarf2_per_objfile
;
8897 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8898 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8900 const char *actual_name
= NULL
;
8902 char *built_actual_name
;
8904 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8906 built_actual_name
= partial_die_full_name (pdi
, cu
);
8907 if (built_actual_name
!= NULL
)
8908 actual_name
= built_actual_name
;
8910 if (actual_name
== NULL
)
8911 actual_name
= pdi
->name
;
8915 case DW_TAG_inlined_subroutine
:
8916 case DW_TAG_subprogram
:
8917 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8919 if (pdi
->is_external
|| cu
->language
== language_ada
)
8921 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
8922 of the global scope. But in Ada, we want to be able to access
8923 nested procedures globally. So all Ada subprograms are stored
8924 in the global scope. */
8925 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8926 built_actual_name
!= NULL
,
8927 VAR_DOMAIN
, LOC_BLOCK
,
8928 SECT_OFF_TEXT (objfile
),
8929 psymbol_placement::GLOBAL
,
8931 cu
->language
, objfile
);
8935 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8936 built_actual_name
!= NULL
,
8937 VAR_DOMAIN
, LOC_BLOCK
,
8938 SECT_OFF_TEXT (objfile
),
8939 psymbol_placement::STATIC
,
8940 addr
, cu
->language
, objfile
);
8943 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8944 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8946 case DW_TAG_constant
:
8947 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8948 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
8949 -1, (pdi
->is_external
8950 ? psymbol_placement::GLOBAL
8951 : psymbol_placement::STATIC
),
8952 0, cu
->language
, objfile
);
8954 case DW_TAG_variable
:
8956 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8960 && !dwarf2_per_objfile
->has_section_at_zero
)
8962 /* A global or static variable may also have been stripped
8963 out by the linker if unused, in which case its address
8964 will be nullified; do not add such variables into partial
8965 symbol table then. */
8967 else if (pdi
->is_external
)
8970 Don't enter into the minimal symbol tables as there is
8971 a minimal symbol table entry from the ELF symbols already.
8972 Enter into partial symbol table if it has a location
8973 descriptor or a type.
8974 If the location descriptor is missing, new_symbol will create
8975 a LOC_UNRESOLVED symbol, the address of the variable will then
8976 be determined from the minimal symbol table whenever the variable
8978 The address for the partial symbol table entry is not
8979 used by GDB, but it comes in handy for debugging partial symbol
8982 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8983 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8984 built_actual_name
!= NULL
,
8985 VAR_DOMAIN
, LOC_STATIC
,
8986 SECT_OFF_TEXT (objfile
),
8987 psymbol_placement::GLOBAL
,
8988 addr
, cu
->language
, objfile
);
8992 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8994 /* Static Variable. Skip symbols whose value we cannot know (those
8995 without location descriptors or constant values). */
8996 if (!has_loc
&& !pdi
->has_const_value
)
8998 xfree (built_actual_name
);
9002 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9003 built_actual_name
!= NULL
,
9004 VAR_DOMAIN
, LOC_STATIC
,
9005 SECT_OFF_TEXT (objfile
),
9006 psymbol_placement::STATIC
,
9008 cu
->language
, objfile
);
9011 case DW_TAG_typedef
:
9012 case DW_TAG_base_type
:
9013 case DW_TAG_subrange_type
:
9014 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9015 built_actual_name
!= NULL
,
9016 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
9017 psymbol_placement::STATIC
,
9018 0, cu
->language
, objfile
);
9020 case DW_TAG_imported_declaration
:
9021 case DW_TAG_namespace
:
9022 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9023 built_actual_name
!= NULL
,
9024 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
9025 psymbol_placement::GLOBAL
,
9026 0, cu
->language
, objfile
);
9029 /* With Fortran 77 there might be a "BLOCK DATA" module
9030 available without any name. If so, we skip the module as it
9031 doesn't bring any value. */
9032 if (actual_name
!= nullptr)
9033 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9034 built_actual_name
!= NULL
,
9035 MODULE_DOMAIN
, LOC_TYPEDEF
, -1,
9036 psymbol_placement::GLOBAL
,
9037 0, cu
->language
, objfile
);
9039 case DW_TAG_class_type
:
9040 case DW_TAG_interface_type
:
9041 case DW_TAG_structure_type
:
9042 case DW_TAG_union_type
:
9043 case DW_TAG_enumeration_type
:
9044 /* Skip external references. The DWARF standard says in the section
9045 about "Structure, Union, and Class Type Entries": "An incomplete
9046 structure, union or class type is represented by a structure,
9047 union or class entry that does not have a byte size attribute
9048 and that has a DW_AT_declaration attribute." */
9049 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
9051 xfree (built_actual_name
);
9055 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
9056 static vs. global. */
9057 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9058 built_actual_name
!= NULL
,
9059 STRUCT_DOMAIN
, LOC_TYPEDEF
, -1,
9060 cu
->language
== language_cplus
9061 ? psymbol_placement::GLOBAL
9062 : psymbol_placement::STATIC
,
9063 0, cu
->language
, objfile
);
9066 case DW_TAG_enumerator
:
9067 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9068 built_actual_name
!= NULL
,
9069 VAR_DOMAIN
, LOC_CONST
, -1,
9070 cu
->language
== language_cplus
9071 ? psymbol_placement::GLOBAL
9072 : psymbol_placement::STATIC
,
9073 0, cu
->language
, objfile
);
9079 xfree (built_actual_name
);
9082 /* Read a partial die corresponding to a namespace; also, add a symbol
9083 corresponding to that namespace to the symbol table. NAMESPACE is
9084 the name of the enclosing namespace. */
9087 add_partial_namespace (struct partial_die_info
*pdi
,
9088 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9089 int set_addrmap
, struct dwarf2_cu
*cu
)
9091 /* Add a symbol for the namespace. */
9093 add_partial_symbol (pdi
, cu
);
9095 /* Now scan partial symbols in that namespace. */
9097 if (pdi
->has_children
)
9098 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
9101 /* Read a partial die corresponding to a Fortran module. */
9104 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
9105 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
9107 /* Add a symbol for the namespace. */
9109 add_partial_symbol (pdi
, cu
);
9111 /* Now scan partial symbols in that module. */
9113 if (pdi
->has_children
)
9114 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
9117 /* Read a partial die corresponding to a subprogram or an inlined
9118 subprogram and create a partial symbol for that subprogram.
9119 When the CU language allows it, this routine also defines a partial
9120 symbol for each nested subprogram that this subprogram contains.
9121 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
9122 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
9124 PDI may also be a lexical block, in which case we simply search
9125 recursively for subprograms defined inside that lexical block.
9126 Again, this is only performed when the CU language allows this
9127 type of definitions. */
9130 add_partial_subprogram (struct partial_die_info
*pdi
,
9131 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9132 int set_addrmap
, struct dwarf2_cu
*cu
)
9134 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
9136 if (pdi
->has_pc_info
)
9138 if (pdi
->lowpc
< *lowpc
)
9139 *lowpc
= pdi
->lowpc
;
9140 if (pdi
->highpc
> *highpc
)
9141 *highpc
= pdi
->highpc
;
9144 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9145 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9147 CORE_ADDR this_highpc
;
9148 CORE_ADDR this_lowpc
;
9150 baseaddr
= ANOFFSET (objfile
->section_offsets
,
9151 SECT_OFF_TEXT (objfile
));
9153 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
9154 pdi
->lowpc
+ baseaddr
)
9157 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
9158 pdi
->highpc
+ baseaddr
)
9160 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
9161 this_lowpc
, this_highpc
- 1,
9162 cu
->per_cu
->v
.psymtab
);
9166 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
9168 if (!pdi
->is_declaration
)
9169 /* Ignore subprogram DIEs that do not have a name, they are
9170 illegal. Do not emit a complaint at this point, we will
9171 do so when we convert this psymtab into a symtab. */
9173 add_partial_symbol (pdi
, cu
);
9177 if (! pdi
->has_children
)
9180 if (cu
->language
== language_ada
)
9182 pdi
= pdi
->die_child
;
9186 if (pdi
->tag
== DW_TAG_subprogram
9187 || pdi
->tag
== DW_TAG_inlined_subroutine
9188 || pdi
->tag
== DW_TAG_lexical_block
)
9189 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
9190 pdi
= pdi
->die_sibling
;
9195 /* Read a partial die corresponding to an enumeration type. */
9198 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
9199 struct dwarf2_cu
*cu
)
9201 struct partial_die_info
*pdi
;
9203 if (enum_pdi
->name
!= NULL
)
9204 add_partial_symbol (enum_pdi
, cu
);
9206 pdi
= enum_pdi
->die_child
;
9209 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
9210 complaint (_("malformed enumerator DIE ignored"));
9212 add_partial_symbol (pdi
, cu
);
9213 pdi
= pdi
->die_sibling
;
9217 /* Return the initial uleb128 in the die at INFO_PTR. */
9220 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
9222 unsigned int bytes_read
;
9224 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9227 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
9228 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
9230 Return the corresponding abbrev, or NULL if the number is zero (indicating
9231 an empty DIE). In either case *BYTES_READ will be set to the length of
9232 the initial number. */
9234 static struct abbrev_info
*
9235 peek_die_abbrev (const die_reader_specs
&reader
,
9236 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
9238 dwarf2_cu
*cu
= reader
.cu
;
9239 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
9240 unsigned int abbrev_number
9241 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
9243 if (abbrev_number
== 0)
9246 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
9249 error (_("Dwarf Error: Could not find abbrev number %d in %s"
9250 " at offset %s [in module %s]"),
9251 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
9252 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
9258 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9259 Returns a pointer to the end of a series of DIEs, terminated by an empty
9260 DIE. Any children of the skipped DIEs will also be skipped. */
9262 static const gdb_byte
*
9263 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
9267 unsigned int bytes_read
;
9268 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
9271 return info_ptr
+ bytes_read
;
9273 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
9277 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9278 INFO_PTR should point just after the initial uleb128 of a DIE, and the
9279 abbrev corresponding to that skipped uleb128 should be passed in
9280 ABBREV. Returns a pointer to this DIE's sibling, skipping any
9283 static const gdb_byte
*
9284 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
9285 struct abbrev_info
*abbrev
)
9287 unsigned int bytes_read
;
9288 struct attribute attr
;
9289 bfd
*abfd
= reader
->abfd
;
9290 struct dwarf2_cu
*cu
= reader
->cu
;
9291 const gdb_byte
*buffer
= reader
->buffer
;
9292 const gdb_byte
*buffer_end
= reader
->buffer_end
;
9293 unsigned int form
, i
;
9295 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
9297 /* The only abbrev we care about is DW_AT_sibling. */
9298 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
9300 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
9301 if (attr
.form
== DW_FORM_ref_addr
)
9302 complaint (_("ignoring absolute DW_AT_sibling"));
9305 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
9306 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
9308 if (sibling_ptr
< info_ptr
)
9309 complaint (_("DW_AT_sibling points backwards"));
9310 else if (sibling_ptr
> reader
->buffer_end
)
9311 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
9317 /* If it isn't DW_AT_sibling, skip this attribute. */
9318 form
= abbrev
->attrs
[i
].form
;
9322 case DW_FORM_ref_addr
:
9323 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
9324 and later it is offset sized. */
9325 if (cu
->header
.version
== 2)
9326 info_ptr
+= cu
->header
.addr_size
;
9328 info_ptr
+= cu
->header
.offset_size
;
9330 case DW_FORM_GNU_ref_alt
:
9331 info_ptr
+= cu
->header
.offset_size
;
9334 info_ptr
+= cu
->header
.addr_size
;
9341 case DW_FORM_flag_present
:
9342 case DW_FORM_implicit_const
:
9354 case DW_FORM_ref_sig8
:
9357 case DW_FORM_data16
:
9360 case DW_FORM_string
:
9361 read_direct_string (abfd
, info_ptr
, &bytes_read
);
9362 info_ptr
+= bytes_read
;
9364 case DW_FORM_sec_offset
:
9366 case DW_FORM_GNU_strp_alt
:
9367 info_ptr
+= cu
->header
.offset_size
;
9369 case DW_FORM_exprloc
:
9371 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9372 info_ptr
+= bytes_read
;
9374 case DW_FORM_block1
:
9375 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
9377 case DW_FORM_block2
:
9378 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
9380 case DW_FORM_block4
:
9381 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
9387 case DW_FORM_ref_udata
:
9388 case DW_FORM_GNU_addr_index
:
9389 case DW_FORM_GNU_str_index
:
9390 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
9392 case DW_FORM_indirect
:
9393 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9394 info_ptr
+= bytes_read
;
9395 /* We need to continue parsing from here, so just go back to
9397 goto skip_attribute
;
9400 error (_("Dwarf Error: Cannot handle %s "
9401 "in DWARF reader [in module %s]"),
9402 dwarf_form_name (form
),
9403 bfd_get_filename (abfd
));
9407 if (abbrev
->has_children
)
9408 return skip_children (reader
, info_ptr
);
9413 /* Locate ORIG_PDI's sibling.
9414 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
9416 static const gdb_byte
*
9417 locate_pdi_sibling (const struct die_reader_specs
*reader
,
9418 struct partial_die_info
*orig_pdi
,
9419 const gdb_byte
*info_ptr
)
9421 /* Do we know the sibling already? */
9423 if (orig_pdi
->sibling
)
9424 return orig_pdi
->sibling
;
9426 /* Are there any children to deal with? */
9428 if (!orig_pdi
->has_children
)
9431 /* Skip the children the long way. */
9433 return skip_children (reader
, info_ptr
);
9436 /* Expand this partial symbol table into a full symbol table. SELF is
9440 dwarf2_read_symtab (struct partial_symtab
*self
,
9441 struct objfile
*objfile
)
9443 struct dwarf2_per_objfile
*dwarf2_per_objfile
9444 = get_dwarf2_per_objfile (objfile
);
9448 warning (_("bug: psymtab for %s is already read in."),
9455 printf_filtered (_("Reading in symbols for %s..."),
9457 gdb_flush (gdb_stdout
);
9460 /* If this psymtab is constructed from a debug-only objfile, the
9461 has_section_at_zero flag will not necessarily be correct. We
9462 can get the correct value for this flag by looking at the data
9463 associated with the (presumably stripped) associated objfile. */
9464 if (objfile
->separate_debug_objfile_backlink
)
9466 struct dwarf2_per_objfile
*dpo_backlink
9467 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
9469 dwarf2_per_objfile
->has_section_at_zero
9470 = dpo_backlink
->has_section_at_zero
;
9473 dwarf2_per_objfile
->reading_partial_symbols
= 0;
9475 psymtab_to_symtab_1 (self
);
9477 /* Finish up the debug error message. */
9479 printf_filtered (_("done.\n"));
9482 process_cu_includes (dwarf2_per_objfile
);
9485 /* Reading in full CUs. */
9487 /* Add PER_CU to the queue. */
9490 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9491 enum language pretend_language
)
9493 struct dwarf2_queue_item
*item
;
9496 item
= XNEW (struct dwarf2_queue_item
);
9497 item
->per_cu
= per_cu
;
9498 item
->pretend_language
= pretend_language
;
9501 if (dwarf2_queue
== NULL
)
9502 dwarf2_queue
= item
;
9504 dwarf2_queue_tail
->next
= item
;
9506 dwarf2_queue_tail
= item
;
9509 /* If PER_CU is not yet queued, add it to the queue.
9510 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
9512 The result is non-zero if PER_CU was queued, otherwise the result is zero
9513 meaning either PER_CU is already queued or it is already loaded.
9515 N.B. There is an invariant here that if a CU is queued then it is loaded.
9516 The caller is required to load PER_CU if we return non-zero. */
9519 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
9520 struct dwarf2_per_cu_data
*per_cu
,
9521 enum language pretend_language
)
9523 /* We may arrive here during partial symbol reading, if we need full
9524 DIEs to process an unusual case (e.g. template arguments). Do
9525 not queue PER_CU, just tell our caller to load its DIEs. */
9526 if (per_cu
->dwarf2_per_objfile
->reading_partial_symbols
)
9528 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
9533 /* Mark the dependence relation so that we don't flush PER_CU
9535 if (dependent_cu
!= NULL
)
9536 dwarf2_add_dependence (dependent_cu
, per_cu
);
9538 /* If it's already on the queue, we have nothing to do. */
9542 /* If the compilation unit is already loaded, just mark it as
9544 if (per_cu
->cu
!= NULL
)
9546 per_cu
->cu
->last_used
= 0;
9550 /* Add it to the queue. */
9551 queue_comp_unit (per_cu
, pretend_language
);
9556 /* Process the queue. */
9559 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9561 struct dwarf2_queue_item
*item
, *next_item
;
9563 if (dwarf_read_debug
)
9565 fprintf_unfiltered (gdb_stdlog
,
9566 "Expanding one or more symtabs of objfile %s ...\n",
9567 objfile_name (dwarf2_per_objfile
->objfile
));
9570 /* The queue starts out with one item, but following a DIE reference
9571 may load a new CU, adding it to the end of the queue. */
9572 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
9574 if ((dwarf2_per_objfile
->using_index
9575 ? !item
->per_cu
->v
.quick
->compunit_symtab
9576 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
9577 /* Skip dummy CUs. */
9578 && item
->per_cu
->cu
!= NULL
)
9580 struct dwarf2_per_cu_data
*per_cu
= item
->per_cu
;
9581 unsigned int debug_print_threshold
;
9584 if (per_cu
->is_debug_types
)
9586 struct signatured_type
*sig_type
=
9587 (struct signatured_type
*) per_cu
;
9589 sprintf (buf
, "TU %s at offset %s",
9590 hex_string (sig_type
->signature
),
9591 sect_offset_str (per_cu
->sect_off
));
9592 /* There can be 100s of TUs.
9593 Only print them in verbose mode. */
9594 debug_print_threshold
= 2;
9598 sprintf (buf
, "CU at offset %s",
9599 sect_offset_str (per_cu
->sect_off
));
9600 debug_print_threshold
= 1;
9603 if (dwarf_read_debug
>= debug_print_threshold
)
9604 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
9606 if (per_cu
->is_debug_types
)
9607 process_full_type_unit (per_cu
, item
->pretend_language
);
9609 process_full_comp_unit (per_cu
, item
->pretend_language
);
9611 if (dwarf_read_debug
>= debug_print_threshold
)
9612 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
9615 item
->per_cu
->queued
= 0;
9616 next_item
= item
->next
;
9620 dwarf2_queue_tail
= NULL
;
9622 if (dwarf_read_debug
)
9624 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
9625 objfile_name (dwarf2_per_objfile
->objfile
));
9629 /* Read in full symbols for PST, and anything it depends on. */
9632 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
9634 struct dwarf2_per_cu_data
*per_cu
;
9640 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
9641 if (!pst
->dependencies
[i
]->readin
9642 && pst
->dependencies
[i
]->user
== NULL
)
9644 /* Inform about additional files that need to be read in. */
9647 /* FIXME: i18n: Need to make this a single string. */
9648 fputs_filtered (" ", gdb_stdout
);
9650 fputs_filtered ("and ", gdb_stdout
);
9652 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
9653 wrap_here (""); /* Flush output. */
9654 gdb_flush (gdb_stdout
);
9656 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
9659 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
9663 /* It's an include file, no symbols to read for it.
9664 Everything is in the parent symtab. */
9669 dw2_do_instantiate_symtab (per_cu
, false);
9672 /* Trivial hash function for die_info: the hash value of a DIE
9673 is its offset in .debug_info for this objfile. */
9676 die_hash (const void *item
)
9678 const struct die_info
*die
= (const struct die_info
*) item
;
9680 return to_underlying (die
->sect_off
);
9683 /* Trivial comparison function for die_info structures: two DIEs
9684 are equal if they have the same offset. */
9687 die_eq (const void *item_lhs
, const void *item_rhs
)
9689 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
9690 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
9692 return die_lhs
->sect_off
== die_rhs
->sect_off
;
9695 /* die_reader_func for load_full_comp_unit.
9696 This is identical to read_signatured_type_reader,
9697 but is kept separate for now. */
9700 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
9701 const gdb_byte
*info_ptr
,
9702 struct die_info
*comp_unit_die
,
9706 struct dwarf2_cu
*cu
= reader
->cu
;
9707 enum language
*language_ptr
= (enum language
*) data
;
9709 gdb_assert (cu
->die_hash
== NULL
);
9711 htab_create_alloc_ex (cu
->header
.length
/ 12,
9715 &cu
->comp_unit_obstack
,
9716 hashtab_obstack_allocate
,
9717 dummy_obstack_deallocate
);
9720 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
9721 &info_ptr
, comp_unit_die
);
9722 cu
->dies
= comp_unit_die
;
9723 /* comp_unit_die is not stored in die_hash, no need. */
9725 /* We try not to read any attributes in this function, because not
9726 all CUs needed for references have been loaded yet, and symbol
9727 table processing isn't initialized. But we have to set the CU language,
9728 or we won't be able to build types correctly.
9729 Similarly, if we do not read the producer, we can not apply
9730 producer-specific interpretation. */
9731 prepare_one_comp_unit (cu
, cu
->dies
, *language_ptr
);
9734 /* Load the DIEs associated with PER_CU into memory. */
9737 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
9739 enum language pretend_language
)
9741 gdb_assert (! this_cu
->is_debug_types
);
9743 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1, skip_partial
,
9744 load_full_comp_unit_reader
, &pretend_language
);
9747 /* Add a DIE to the delayed physname list. */
9750 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
9751 const char *name
, struct die_info
*die
,
9752 struct dwarf2_cu
*cu
)
9754 struct delayed_method_info mi
;
9756 mi
.fnfield_index
= fnfield_index
;
9760 cu
->method_list
.push_back (mi
);
9763 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
9764 "const" / "volatile". If so, decrements LEN by the length of the
9765 modifier and return true. Otherwise return false. */
9769 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
9771 size_t mod_len
= sizeof (mod
) - 1;
9772 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
9780 /* Compute the physnames of any methods on the CU's method list.
9782 The computation of method physnames is delayed in order to avoid the
9783 (bad) condition that one of the method's formal parameters is of an as yet
9787 compute_delayed_physnames (struct dwarf2_cu
*cu
)
9789 /* Only C++ delays computing physnames. */
9790 if (cu
->method_list
.empty ())
9792 gdb_assert (cu
->language
== language_cplus
);
9794 for (const delayed_method_info
&mi
: cu
->method_list
)
9796 const char *physname
;
9797 struct fn_fieldlist
*fn_flp
9798 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9799 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9800 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9801 = physname
? physname
: "";
9803 /* Since there's no tag to indicate whether a method is a
9804 const/volatile overload, extract that information out of the
9806 if (physname
!= NULL
)
9808 size_t len
= strlen (physname
);
9812 if (physname
[len
] == ')') /* shortcut */
9814 else if (check_modifier (physname
, len
, " const"))
9815 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9816 else if (check_modifier (physname
, len
, " volatile"))
9817 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9824 /* The list is no longer needed. */
9825 cu
->method_list
.clear ();
9828 /* Go objects should be embedded in a DW_TAG_module DIE,
9829 and it's not clear if/how imported objects will appear.
9830 To keep Go support simple until that's worked out,
9831 go back through what we've read and create something usable.
9832 We could do this while processing each DIE, and feels kinda cleaner,
9833 but that way is more invasive.
9834 This is to, for example, allow the user to type "p var" or "b main"
9835 without having to specify the package name, and allow lookups
9836 of module.object to work in contexts that use the expression
9840 fixup_go_packaging (struct dwarf2_cu
*cu
)
9842 char *package_name
= NULL
;
9843 struct pending
*list
;
9846 for (list
= *cu
->get_builder ()->get_global_symbols ();
9850 for (i
= 0; i
< list
->nsyms
; ++i
)
9852 struct symbol
*sym
= list
->symbol
[i
];
9854 if (SYMBOL_LANGUAGE (sym
) == language_go
9855 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9857 char *this_package_name
= go_symbol_package_name (sym
);
9859 if (this_package_name
== NULL
)
9861 if (package_name
== NULL
)
9862 package_name
= this_package_name
;
9865 struct objfile
*objfile
9866 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9867 if (strcmp (package_name
, this_package_name
) != 0)
9868 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9869 (symbol_symtab (sym
) != NULL
9870 ? symtab_to_filename_for_display
9871 (symbol_symtab (sym
))
9872 : objfile_name (objfile
)),
9873 this_package_name
, package_name
);
9874 xfree (this_package_name
);
9880 if (package_name
!= NULL
)
9882 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9883 const char *saved_package_name
9884 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
, package_name
);
9885 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9886 saved_package_name
);
9889 sym
= allocate_symbol (objfile
);
9890 SYMBOL_SET_LANGUAGE (sym
, language_go
, &objfile
->objfile_obstack
);
9891 SYMBOL_SET_NAMES (sym
, saved_package_name
,
9892 strlen (saved_package_name
), 0, objfile
);
9893 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9894 e.g., "main" finds the "main" module and not C's main(). */
9895 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9896 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9897 SYMBOL_TYPE (sym
) = type
;
9899 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9901 xfree (package_name
);
9905 /* Allocate a fully-qualified name consisting of the two parts on the
9909 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9911 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9914 /* A helper that allocates a struct discriminant_info to attach to a
9917 static struct discriminant_info
*
9918 alloc_discriminant_info (struct type
*type
, int discriminant_index
,
9921 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9922 gdb_assert (discriminant_index
== -1
9923 || (discriminant_index
>= 0
9924 && discriminant_index
< TYPE_NFIELDS (type
)));
9925 gdb_assert (default_index
== -1
9926 || (default_index
>= 0 && default_index
< TYPE_NFIELDS (type
)));
9928 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
9930 struct discriminant_info
*disc
9931 = ((struct discriminant_info
*)
9933 offsetof (struct discriminant_info
, discriminants
)
9934 + TYPE_NFIELDS (type
) * sizeof (disc
->discriminants
[0])));
9935 disc
->default_index
= default_index
;
9936 disc
->discriminant_index
= discriminant_index
;
9938 struct dynamic_prop prop
;
9939 prop
.kind
= PROP_UNDEFINED
;
9940 prop
.data
.baton
= disc
;
9942 add_dyn_prop (DYN_PROP_DISCRIMINATED
, prop
, type
);
9947 /* Some versions of rustc emitted enums in an unusual way.
9949 Ordinary enums were emitted as unions. The first element of each
9950 structure in the union was named "RUST$ENUM$DISR". This element
9951 held the discriminant.
9953 These versions of Rust also implemented the "non-zero"
9954 optimization. When the enum had two values, and one is empty and
9955 the other holds a pointer that cannot be zero, the pointer is used
9956 as the discriminant, with a zero value meaning the empty variant.
9957 Here, the union's first member is of the form
9958 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9959 where the fieldnos are the indices of the fields that should be
9960 traversed in order to find the field (which may be several fields deep)
9961 and the variantname is the name of the variant of the case when the
9964 This function recognizes whether TYPE is of one of these forms,
9965 and, if so, smashes it to be a variant type. */
9968 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9970 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9972 /* We don't need to deal with empty enums. */
9973 if (TYPE_NFIELDS (type
) == 0)
9976 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9977 if (TYPE_NFIELDS (type
) == 1
9978 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9980 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9982 /* Decode the field name to find the offset of the
9984 ULONGEST bit_offset
= 0;
9985 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9986 while (name
[0] >= '0' && name
[0] <= '9')
9989 unsigned long index
= strtoul (name
, &tail
, 10);
9992 || index
>= TYPE_NFIELDS (field_type
)
9993 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9994 != FIELD_LOC_KIND_BITPOS
))
9996 complaint (_("Could not parse Rust enum encoding string \"%s\""
9998 TYPE_FIELD_NAME (type
, 0),
9999 objfile_name (objfile
));
10004 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
10005 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
10008 /* Make a union to hold the variants. */
10009 struct type
*union_type
= alloc_type (objfile
);
10010 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10011 TYPE_NFIELDS (union_type
) = 3;
10012 TYPE_FIELDS (union_type
)
10013 = (struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
));
10014 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10015 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
10017 /* Put the discriminant must at index 0. */
10018 TYPE_FIELD_TYPE (union_type
, 0) = field_type
;
10019 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
10020 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
10021 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 0), bit_offset
);
10023 /* The order of fields doesn't really matter, so put the real
10024 field at index 1 and the data-less field at index 2. */
10025 struct discriminant_info
*disc
10026 = alloc_discriminant_info (union_type
, 0, 1);
10027 TYPE_FIELD (union_type
, 1) = TYPE_FIELD (type
, 0);
10028 TYPE_FIELD_NAME (union_type
, 1)
10029 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1)));
10030 TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1))
10031 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
10032 TYPE_FIELD_NAME (union_type
, 1));
10034 const char *dataless_name
10035 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
10037 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
10039 TYPE_FIELD_TYPE (union_type
, 2) = dataless_type
;
10040 /* NAME points into the original discriminant name, which
10041 already has the correct lifetime. */
10042 TYPE_FIELD_NAME (union_type
, 2) = name
;
10043 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 2), 0);
10044 disc
->discriminants
[2] = 0;
10046 /* Smash this type to be a structure type. We have to do this
10047 because the type has already been recorded. */
10048 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10049 TYPE_NFIELDS (type
) = 1;
10051 = (struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
));
10053 /* Install the variant part. */
10054 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10055 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10056 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10058 else if (TYPE_NFIELDS (type
) == 1)
10060 /* We assume that a union with a single field is a univariant
10062 /* Smash this type to be a structure type. We have to do this
10063 because the type has already been recorded. */
10064 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10066 /* Make a union to hold the variants. */
10067 struct type
*union_type
= alloc_type (objfile
);
10068 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10069 TYPE_NFIELDS (union_type
) = TYPE_NFIELDS (type
);
10070 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10071 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
10072 TYPE_FIELDS (union_type
) = TYPE_FIELDS (type
);
10074 struct type
*field_type
= TYPE_FIELD_TYPE (union_type
, 0);
10075 const char *variant_name
10076 = rust_last_path_segment (TYPE_NAME (field_type
));
10077 TYPE_FIELD_NAME (union_type
, 0) = variant_name
;
10078 TYPE_NAME (field_type
)
10079 = rust_fully_qualify (&objfile
->objfile_obstack
,
10080 TYPE_NAME (type
), variant_name
);
10082 /* Install the union in the outer struct type. */
10083 TYPE_NFIELDS (type
) = 1;
10085 = (struct field
*) TYPE_ZALLOC (union_type
, sizeof (struct field
));
10086 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10087 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10088 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10090 alloc_discriminant_info (union_type
, -1, 0);
10094 struct type
*disr_type
= nullptr;
10095 for (int i
= 0; i
< TYPE_NFIELDS (type
); ++i
)
10097 disr_type
= TYPE_FIELD_TYPE (type
, i
);
10099 if (TYPE_CODE (disr_type
) != TYPE_CODE_STRUCT
)
10101 /* All fields of a true enum will be structs. */
10104 else if (TYPE_NFIELDS (disr_type
) == 0)
10106 /* Could be data-less variant, so keep going. */
10107 disr_type
= nullptr;
10109 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
10110 "RUST$ENUM$DISR") != 0)
10112 /* Not a Rust enum. */
10122 /* If we got here without a discriminant, then it's probably
10124 if (disr_type
== nullptr)
10127 /* Smash this type to be a structure type. We have to do this
10128 because the type has already been recorded. */
10129 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10131 /* Make a union to hold the variants. */
10132 struct field
*disr_field
= &TYPE_FIELD (disr_type
, 0);
10133 struct type
*union_type
= alloc_type (objfile
);
10134 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10135 TYPE_NFIELDS (union_type
) = 1 + TYPE_NFIELDS (type
);
10136 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10137 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
10138 TYPE_FIELDS (union_type
)
10139 = (struct field
*) TYPE_ZALLOC (union_type
,
10140 (TYPE_NFIELDS (union_type
)
10141 * sizeof (struct field
)));
10143 memcpy (TYPE_FIELDS (union_type
) + 1, TYPE_FIELDS (type
),
10144 TYPE_NFIELDS (type
) * sizeof (struct field
));
10146 /* Install the discriminant at index 0 in the union. */
10147 TYPE_FIELD (union_type
, 0) = *disr_field
;
10148 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
10149 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
10151 /* Install the union in the outer struct type. */
10152 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10153 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10154 TYPE_NFIELDS (type
) = 1;
10156 /* Set the size and offset of the union type. */
10157 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10159 /* We need a way to find the correct discriminant given a
10160 variant name. For convenience we build a map here. */
10161 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
10162 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
10163 for (int i
= 0; i
< TYPE_NFIELDS (enum_type
); ++i
)
10165 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
10168 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
10169 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
10173 int n_fields
= TYPE_NFIELDS (union_type
);
10174 struct discriminant_info
*disc
10175 = alloc_discriminant_info (union_type
, 0, -1);
10176 /* Skip the discriminant here. */
10177 for (int i
= 1; i
< n_fields
; ++i
)
10179 /* Find the final word in the name of this variant's type.
10180 That name can be used to look up the correct
10182 const char *variant_name
10183 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
,
10186 auto iter
= discriminant_map
.find (variant_name
);
10187 if (iter
!= discriminant_map
.end ())
10188 disc
->discriminants
[i
] = iter
->second
;
10190 /* Remove the discriminant field, if it exists. */
10191 struct type
*sub_type
= TYPE_FIELD_TYPE (union_type
, i
);
10192 if (TYPE_NFIELDS (sub_type
) > 0)
10194 --TYPE_NFIELDS (sub_type
);
10195 ++TYPE_FIELDS (sub_type
);
10197 TYPE_FIELD_NAME (union_type
, i
) = variant_name
;
10198 TYPE_NAME (sub_type
)
10199 = rust_fully_qualify (&objfile
->objfile_obstack
,
10200 TYPE_NAME (type
), variant_name
);
10205 /* Rewrite some Rust unions to be structures with variants parts. */
10208 rust_union_quirks (struct dwarf2_cu
*cu
)
10210 gdb_assert (cu
->language
== language_rust
);
10211 for (type
*type_
: cu
->rust_unions
)
10212 quirk_rust_enum (type_
, cu
->per_cu
->dwarf2_per_objfile
->objfile
);
10213 /* We don't need this any more. */
10214 cu
->rust_unions
.clear ();
10217 /* Return the symtab for PER_CU. This works properly regardless of
10218 whether we're using the index or psymtabs. */
10220 static struct compunit_symtab
*
10221 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
10223 return (per_cu
->dwarf2_per_objfile
->using_index
10224 ? per_cu
->v
.quick
->compunit_symtab
10225 : per_cu
->v
.psymtab
->compunit_symtab
);
10228 /* A helper function for computing the list of all symbol tables
10229 included by PER_CU. */
10232 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
10233 htab_t all_children
, htab_t all_type_symtabs
,
10234 struct dwarf2_per_cu_data
*per_cu
,
10235 struct compunit_symtab
*immediate_parent
)
10239 struct compunit_symtab
*cust
;
10240 struct dwarf2_per_cu_data
*iter
;
10242 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
10245 /* This inclusion and its children have been processed. */
10250 /* Only add a CU if it has a symbol table. */
10251 cust
= get_compunit_symtab (per_cu
);
10254 /* If this is a type unit only add its symbol table if we haven't
10255 seen it yet (type unit per_cu's can share symtabs). */
10256 if (per_cu
->is_debug_types
)
10258 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
10262 result
->push_back (cust
);
10263 if (cust
->user
== NULL
)
10264 cust
->user
= immediate_parent
;
10269 result
->push_back (cust
);
10270 if (cust
->user
== NULL
)
10271 cust
->user
= immediate_parent
;
10276 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, ix
, iter
);
10279 recursively_compute_inclusions (result
, all_children
,
10280 all_type_symtabs
, iter
, cust
);
10284 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
10288 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
10290 gdb_assert (! per_cu
->is_debug_types
);
10292 if (!VEC_empty (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
))
10295 struct dwarf2_per_cu_data
*per_cu_iter
;
10296 std::vector
<compunit_symtab
*> result_symtabs
;
10297 htab_t all_children
, all_type_symtabs
;
10298 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
10300 /* If we don't have a symtab, we can just skip this case. */
10304 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10305 NULL
, xcalloc
, xfree
);
10306 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10307 NULL
, xcalloc
, xfree
);
10310 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
,
10314 recursively_compute_inclusions (&result_symtabs
, all_children
,
10315 all_type_symtabs
, per_cu_iter
,
10319 /* Now we have a transitive closure of all the included symtabs. */
10320 len
= result_symtabs
.size ();
10322 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
10323 struct compunit_symtab
*, len
+ 1);
10324 memcpy (cust
->includes
, result_symtabs
.data (),
10325 len
* sizeof (compunit_symtab
*));
10326 cust
->includes
[len
] = NULL
;
10328 htab_delete (all_children
);
10329 htab_delete (all_type_symtabs
);
10333 /* Compute the 'includes' field for the symtabs of all the CUs we just
10337 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
10339 for (dwarf2_per_cu_data
*iter
: dwarf2_per_objfile
->just_read_cus
)
10341 if (! iter
->is_debug_types
)
10342 compute_compunit_symtab_includes (iter
);
10345 dwarf2_per_objfile
->just_read_cus
.clear ();
10348 /* Generate full symbol information for PER_CU, whose DIEs have
10349 already been loaded into memory. */
10352 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
10353 enum language pretend_language
)
10355 struct dwarf2_cu
*cu
= per_cu
->cu
;
10356 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10357 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10358 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10359 CORE_ADDR lowpc
, highpc
;
10360 struct compunit_symtab
*cust
;
10361 CORE_ADDR baseaddr
;
10362 struct block
*static_block
;
10365 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10367 /* Clear the list here in case something was left over. */
10368 cu
->method_list
.clear ();
10370 cu
->language
= pretend_language
;
10371 cu
->language_defn
= language_def (cu
->language
);
10373 /* Do line number decoding in read_file_scope () */
10374 process_die (cu
->dies
, cu
);
10376 /* For now fudge the Go package. */
10377 if (cu
->language
== language_go
)
10378 fixup_go_packaging (cu
);
10380 /* Now that we have processed all the DIEs in the CU, all the types
10381 should be complete, and it should now be safe to compute all of the
10383 compute_delayed_physnames (cu
);
10385 if (cu
->language
== language_rust
)
10386 rust_union_quirks (cu
);
10388 /* Some compilers don't define a DW_AT_high_pc attribute for the
10389 compilation unit. If the DW_AT_high_pc is missing, synthesize
10390 it, by scanning the DIE's below the compilation unit. */
10391 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
10393 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
10394 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
10396 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
10397 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
10398 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
10399 addrmap to help ensure it has an accurate map of pc values belonging to
10401 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
10403 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
10404 SECT_OFF_TEXT (objfile
),
10409 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
10411 /* Set symtab language to language from DW_AT_language. If the
10412 compilation is from a C file generated by language preprocessors, do
10413 not set the language if it was already deduced by start_subfile. */
10414 if (!(cu
->language
== language_c
10415 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
10416 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10418 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
10419 produce DW_AT_location with location lists but it can be possibly
10420 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
10421 there were bugs in prologue debug info, fixed later in GCC-4.5
10422 by "unwind info for epilogues" patch (which is not directly related).
10424 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
10425 needed, it would be wrong due to missing DW_AT_producer there.
10427 Still one can confuse GDB by using non-standard GCC compilation
10428 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
10430 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
10431 cust
->locations_valid
= 1;
10433 if (gcc_4_minor
>= 5)
10434 cust
->epilogue_unwind_valid
= 1;
10436 cust
->call_site_htab
= cu
->call_site_htab
;
10439 if (dwarf2_per_objfile
->using_index
)
10440 per_cu
->v
.quick
->compunit_symtab
= cust
;
10443 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
10444 pst
->compunit_symtab
= cust
;
10448 /* Push it for inclusion processing later. */
10449 dwarf2_per_objfile
->just_read_cus
.push_back (per_cu
);
10451 /* Not needed any more. */
10452 cu
->reset_builder ();
10455 /* Generate full symbol information for type unit PER_CU, whose DIEs have
10456 already been loaded into memory. */
10459 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
10460 enum language pretend_language
)
10462 struct dwarf2_cu
*cu
= per_cu
->cu
;
10463 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10464 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10465 struct compunit_symtab
*cust
;
10466 struct signatured_type
*sig_type
;
10468 gdb_assert (per_cu
->is_debug_types
);
10469 sig_type
= (struct signatured_type
*) per_cu
;
10471 /* Clear the list here in case something was left over. */
10472 cu
->method_list
.clear ();
10474 cu
->language
= pretend_language
;
10475 cu
->language_defn
= language_def (cu
->language
);
10477 /* The symbol tables are set up in read_type_unit_scope. */
10478 process_die (cu
->dies
, cu
);
10480 /* For now fudge the Go package. */
10481 if (cu
->language
== language_go
)
10482 fixup_go_packaging (cu
);
10484 /* Now that we have processed all the DIEs in the CU, all the types
10485 should be complete, and it should now be safe to compute all of the
10487 compute_delayed_physnames (cu
);
10489 if (cu
->language
== language_rust
)
10490 rust_union_quirks (cu
);
10492 /* TUs share symbol tables.
10493 If this is the first TU to use this symtab, complete the construction
10494 of it with end_expandable_symtab. Otherwise, complete the addition of
10495 this TU's symbols to the existing symtab. */
10496 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
10498 buildsym_compunit
*builder
= cu
->get_builder ();
10499 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
10500 sig_type
->type_unit_group
->compunit_symtab
= cust
;
10504 /* Set symtab language to language from DW_AT_language. If the
10505 compilation is from a C file generated by language preprocessors,
10506 do not set the language if it was already deduced by
10508 if (!(cu
->language
== language_c
10509 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
10510 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10515 cu
->get_builder ()->augment_type_symtab ();
10516 cust
= sig_type
->type_unit_group
->compunit_symtab
;
10519 if (dwarf2_per_objfile
->using_index
)
10520 per_cu
->v
.quick
->compunit_symtab
= cust
;
10523 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
10524 pst
->compunit_symtab
= cust
;
10528 /* Not needed any more. */
10529 cu
->reset_builder ();
10532 /* Process an imported unit DIE. */
10535 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10537 struct attribute
*attr
;
10539 /* For now we don't handle imported units in type units. */
10540 if (cu
->per_cu
->is_debug_types
)
10542 error (_("Dwarf Error: DW_TAG_imported_unit is not"
10543 " supported in type units [in module %s]"),
10544 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
10547 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10550 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
10551 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
10552 dwarf2_per_cu_data
*per_cu
10553 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
10554 cu
->per_cu
->dwarf2_per_objfile
);
10556 /* If necessary, add it to the queue and load its DIEs. */
10557 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
10558 load_full_comp_unit (per_cu
, false, cu
->language
);
10560 VEC_safe_push (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
10565 /* RAII object that represents a process_die scope: i.e.,
10566 starts/finishes processing a DIE. */
10567 class process_die_scope
10570 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
10571 : m_die (die
), m_cu (cu
)
10573 /* We should only be processing DIEs not already in process. */
10574 gdb_assert (!m_die
->in_process
);
10575 m_die
->in_process
= true;
10578 ~process_die_scope ()
10580 m_die
->in_process
= false;
10582 /* If we're done processing the DIE for the CU that owns the line
10583 header, we don't need the line header anymore. */
10584 if (m_cu
->line_header_die_owner
== m_die
)
10586 delete m_cu
->line_header
;
10587 m_cu
->line_header
= NULL
;
10588 m_cu
->line_header_die_owner
= NULL
;
10597 /* Process a die and its children. */
10600 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10602 process_die_scope
scope (die
, cu
);
10606 case DW_TAG_padding
:
10608 case DW_TAG_compile_unit
:
10609 case DW_TAG_partial_unit
:
10610 read_file_scope (die
, cu
);
10612 case DW_TAG_type_unit
:
10613 read_type_unit_scope (die
, cu
);
10615 case DW_TAG_subprogram
:
10616 case DW_TAG_inlined_subroutine
:
10617 read_func_scope (die
, cu
);
10619 case DW_TAG_lexical_block
:
10620 case DW_TAG_try_block
:
10621 case DW_TAG_catch_block
:
10622 read_lexical_block_scope (die
, cu
);
10624 case DW_TAG_call_site
:
10625 case DW_TAG_GNU_call_site
:
10626 read_call_site_scope (die
, cu
);
10628 case DW_TAG_class_type
:
10629 case DW_TAG_interface_type
:
10630 case DW_TAG_structure_type
:
10631 case DW_TAG_union_type
:
10632 process_structure_scope (die
, cu
);
10634 case DW_TAG_enumeration_type
:
10635 process_enumeration_scope (die
, cu
);
10638 /* These dies have a type, but processing them does not create
10639 a symbol or recurse to process the children. Therefore we can
10640 read them on-demand through read_type_die. */
10641 case DW_TAG_subroutine_type
:
10642 case DW_TAG_set_type
:
10643 case DW_TAG_array_type
:
10644 case DW_TAG_pointer_type
:
10645 case DW_TAG_ptr_to_member_type
:
10646 case DW_TAG_reference_type
:
10647 case DW_TAG_rvalue_reference_type
:
10648 case DW_TAG_string_type
:
10651 case DW_TAG_base_type
:
10652 case DW_TAG_subrange_type
:
10653 case DW_TAG_typedef
:
10654 /* Add a typedef symbol for the type definition, if it has a
10656 new_symbol (die
, read_type_die (die
, cu
), cu
);
10658 case DW_TAG_common_block
:
10659 read_common_block (die
, cu
);
10661 case DW_TAG_common_inclusion
:
10663 case DW_TAG_namespace
:
10664 cu
->processing_has_namespace_info
= true;
10665 read_namespace (die
, cu
);
10667 case DW_TAG_module
:
10668 cu
->processing_has_namespace_info
= true;
10669 read_module (die
, cu
);
10671 case DW_TAG_imported_declaration
:
10672 cu
->processing_has_namespace_info
= true;
10673 if (read_namespace_alias (die
, cu
))
10675 /* The declaration is not a global namespace alias. */
10676 /* Fall through. */
10677 case DW_TAG_imported_module
:
10678 cu
->processing_has_namespace_info
= true;
10679 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
10680 || cu
->language
!= language_fortran
))
10681 complaint (_("Tag '%s' has unexpected children"),
10682 dwarf_tag_name (die
->tag
));
10683 read_import_statement (die
, cu
);
10686 case DW_TAG_imported_unit
:
10687 process_imported_unit_die (die
, cu
);
10690 case DW_TAG_variable
:
10691 read_variable (die
, cu
);
10695 new_symbol (die
, NULL
, cu
);
10700 /* DWARF name computation. */
10702 /* A helper function for dwarf2_compute_name which determines whether DIE
10703 needs to have the name of the scope prepended to the name listed in the
10707 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10709 struct attribute
*attr
;
10713 case DW_TAG_namespace
:
10714 case DW_TAG_typedef
:
10715 case DW_TAG_class_type
:
10716 case DW_TAG_interface_type
:
10717 case DW_TAG_structure_type
:
10718 case DW_TAG_union_type
:
10719 case DW_TAG_enumeration_type
:
10720 case DW_TAG_enumerator
:
10721 case DW_TAG_subprogram
:
10722 case DW_TAG_inlined_subroutine
:
10723 case DW_TAG_member
:
10724 case DW_TAG_imported_declaration
:
10727 case DW_TAG_variable
:
10728 case DW_TAG_constant
:
10729 /* We only need to prefix "globally" visible variables. These include
10730 any variable marked with DW_AT_external or any variable that
10731 lives in a namespace. [Variables in anonymous namespaces
10732 require prefixing, but they are not DW_AT_external.] */
10734 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
10736 struct dwarf2_cu
*spec_cu
= cu
;
10738 return die_needs_namespace (die_specification (die
, &spec_cu
),
10742 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10743 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
10744 && die
->parent
->tag
!= DW_TAG_module
)
10746 /* A variable in a lexical block of some kind does not need a
10747 namespace, even though in C++ such variables may be external
10748 and have a mangled name. */
10749 if (die
->parent
->tag
== DW_TAG_lexical_block
10750 || die
->parent
->tag
== DW_TAG_try_block
10751 || die
->parent
->tag
== DW_TAG_catch_block
10752 || die
->parent
->tag
== DW_TAG_subprogram
)
10761 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
10762 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10763 defined for the given DIE. */
10765 static struct attribute
*
10766 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
10768 struct attribute
*attr
;
10770 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
10772 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10777 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10778 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10779 defined for the given DIE. */
10781 static const char *
10782 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10784 const char *linkage_name
;
10786 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10787 if (linkage_name
== NULL
)
10788 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10790 return linkage_name
;
10793 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10794 compute the physname for the object, which include a method's:
10795 - formal parameters (C++),
10796 - receiver type (Go),
10798 The term "physname" is a bit confusing.
10799 For C++, for example, it is the demangled name.
10800 For Go, for example, it's the mangled name.
10802 For Ada, return the DIE's linkage name rather than the fully qualified
10803 name. PHYSNAME is ignored..
10805 The result is allocated on the objfile_obstack and canonicalized. */
10807 static const char *
10808 dwarf2_compute_name (const char *name
,
10809 struct die_info
*die
, struct dwarf2_cu
*cu
,
10812 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10815 name
= dwarf2_name (die
, cu
);
10817 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10818 but otherwise compute it by typename_concat inside GDB.
10819 FIXME: Actually this is not really true, or at least not always true.
10820 It's all very confusing. SYMBOL_SET_NAMES doesn't try to demangle
10821 Fortran names because there is no mangling standard. So new_symbol
10822 will set the demangled name to the result of dwarf2_full_name, and it is
10823 the demangled name that GDB uses if it exists. */
10824 if (cu
->language
== language_ada
10825 || (cu
->language
== language_fortran
&& physname
))
10827 /* For Ada unit, we prefer the linkage name over the name, as
10828 the former contains the exported name, which the user expects
10829 to be able to reference. Ideally, we want the user to be able
10830 to reference this entity using either natural or linkage name,
10831 but we haven't started looking at this enhancement yet. */
10832 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10834 if (linkage_name
!= NULL
)
10835 return linkage_name
;
10838 /* These are the only languages we know how to qualify names in. */
10840 && (cu
->language
== language_cplus
10841 || cu
->language
== language_fortran
|| cu
->language
== language_d
10842 || cu
->language
== language_rust
))
10844 if (die_needs_namespace (die
, cu
))
10846 const char *prefix
;
10847 const char *canonical_name
= NULL
;
10851 prefix
= determine_prefix (die
, cu
);
10852 if (*prefix
!= '\0')
10854 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
10857 buf
.puts (prefixed_name
);
10858 xfree (prefixed_name
);
10863 /* Template parameters may be specified in the DIE's DW_AT_name, or
10864 as children with DW_TAG_template_type_param or
10865 DW_TAG_value_type_param. If the latter, add them to the name
10866 here. If the name already has template parameters, then
10867 skip this step; some versions of GCC emit both, and
10868 it is more efficient to use the pre-computed name.
10870 Something to keep in mind about this process: it is very
10871 unlikely, or in some cases downright impossible, to produce
10872 something that will match the mangled name of a function.
10873 If the definition of the function has the same debug info,
10874 we should be able to match up with it anyway. But fallbacks
10875 using the minimal symbol, for instance to find a method
10876 implemented in a stripped copy of libstdc++, will not work.
10877 If we do not have debug info for the definition, we will have to
10878 match them up some other way.
10880 When we do name matching there is a related problem with function
10881 templates; two instantiated function templates are allowed to
10882 differ only by their return types, which we do not add here. */
10884 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10886 struct attribute
*attr
;
10887 struct die_info
*child
;
10890 die
->building_fullname
= 1;
10892 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10896 const gdb_byte
*bytes
;
10897 struct dwarf2_locexpr_baton
*baton
;
10900 if (child
->tag
!= DW_TAG_template_type_param
10901 && child
->tag
!= DW_TAG_template_value_param
)
10912 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10915 complaint (_("template parameter missing DW_AT_type"));
10916 buf
.puts ("UNKNOWN_TYPE");
10919 type
= die_type (child
, cu
);
10921 if (child
->tag
== DW_TAG_template_type_param
)
10923 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10924 &type_print_raw_options
);
10928 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10931 complaint (_("template parameter missing "
10932 "DW_AT_const_value"));
10933 buf
.puts ("UNKNOWN_VALUE");
10937 dwarf2_const_value_attr (attr
, type
, name
,
10938 &cu
->comp_unit_obstack
, cu
,
10939 &value
, &bytes
, &baton
);
10941 if (TYPE_NOSIGN (type
))
10942 /* GDB prints characters as NUMBER 'CHAR'. If that's
10943 changed, this can use value_print instead. */
10944 c_printchar (value
, type
, &buf
);
10947 struct value_print_options opts
;
10950 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10954 else if (bytes
!= NULL
)
10956 v
= allocate_value (type
);
10957 memcpy (value_contents_writeable (v
), bytes
,
10958 TYPE_LENGTH (type
));
10961 v
= value_from_longest (type
, value
);
10963 /* Specify decimal so that we do not depend on
10965 get_formatted_print_options (&opts
, 'd');
10967 value_print (v
, &buf
, &opts
);
10972 die
->building_fullname
= 0;
10976 /* Close the argument list, with a space if necessary
10977 (nested templates). */
10978 if (!buf
.empty () && buf
.string ().back () == '>')
10985 /* For C++ methods, append formal parameter type
10986 information, if PHYSNAME. */
10988 if (physname
&& die
->tag
== DW_TAG_subprogram
10989 && cu
->language
== language_cplus
)
10991 struct type
*type
= read_type_die (die
, cu
);
10993 c_type_print_args (type
, &buf
, 1, cu
->language
,
10994 &type_print_raw_options
);
10996 if (cu
->language
== language_cplus
)
10998 /* Assume that an artificial first parameter is
10999 "this", but do not crash if it is not. RealView
11000 marks unnamed (and thus unused) parameters as
11001 artificial; there is no way to differentiate
11003 if (TYPE_NFIELDS (type
) > 0
11004 && TYPE_FIELD_ARTIFICIAL (type
, 0)
11005 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
11006 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
11008 buf
.puts (" const");
11012 const std::string
&intermediate_name
= buf
.string ();
11014 if (cu
->language
== language_cplus
)
11016 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
11017 &objfile
->per_bfd
->storage_obstack
);
11019 /* If we only computed INTERMEDIATE_NAME, or if
11020 INTERMEDIATE_NAME is already canonical, then we need to
11021 copy it to the appropriate obstack. */
11022 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
11023 name
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
11024 intermediate_name
);
11026 name
= canonical_name
;
11033 /* Return the fully qualified name of DIE, based on its DW_AT_name.
11034 If scope qualifiers are appropriate they will be added. The result
11035 will be allocated on the storage_obstack, or NULL if the DIE does
11036 not have a name. NAME may either be from a previous call to
11037 dwarf2_name or NULL.
11039 The output string will be canonicalized (if C++). */
11041 static const char *
11042 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
11044 return dwarf2_compute_name (name
, die
, cu
, 0);
11047 /* Construct a physname for the given DIE in CU. NAME may either be
11048 from a previous call to dwarf2_name or NULL. The result will be
11049 allocated on the objfile_objstack or NULL if the DIE does not have a
11052 The output string will be canonicalized (if C++). */
11054 static const char *
11055 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
11057 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
11058 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
11061 /* In this case dwarf2_compute_name is just a shortcut not building anything
11063 if (!die_needs_namespace (die
, cu
))
11064 return dwarf2_compute_name (name
, die
, cu
, 1);
11066 mangled
= dw2_linkage_name (die
, cu
);
11068 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
11069 See https://github.com/rust-lang/rust/issues/32925. */
11070 if (cu
->language
== language_rust
&& mangled
!= NULL
11071 && strchr (mangled
, '{') != NULL
)
11074 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
11076 gdb::unique_xmalloc_ptr
<char> demangled
;
11077 if (mangled
!= NULL
)
11080 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
11082 /* Do nothing (do not demangle the symbol name). */
11084 else if (cu
->language
== language_go
)
11086 /* This is a lie, but we already lie to the caller new_symbol.
11087 new_symbol assumes we return the mangled name.
11088 This just undoes that lie until things are cleaned up. */
11092 /* Use DMGL_RET_DROP for C++ template functions to suppress
11093 their return type. It is easier for GDB users to search
11094 for such functions as `name(params)' than `long name(params)'.
11095 In such case the minimal symbol names do not match the full
11096 symbol names but for template functions there is never a need
11097 to look up their definition from their declaration so
11098 the only disadvantage remains the minimal symbol variant
11099 `long name(params)' does not have the proper inferior type. */
11100 demangled
.reset (gdb_demangle (mangled
,
11101 (DMGL_PARAMS
| DMGL_ANSI
11102 | DMGL_RET_DROP
)));
11105 canon
= demangled
.get ();
11113 if (canon
== NULL
|| check_physname
)
11115 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
11117 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
11119 /* It may not mean a bug in GDB. The compiler could also
11120 compute DW_AT_linkage_name incorrectly. But in such case
11121 GDB would need to be bug-to-bug compatible. */
11123 complaint (_("Computed physname <%s> does not match demangled <%s> "
11124 "(from linkage <%s>) - DIE at %s [in module %s]"),
11125 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
11126 objfile_name (objfile
));
11128 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
11129 is available here - over computed PHYSNAME. It is safer
11130 against both buggy GDB and buggy compilers. */
11144 retval
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
, retval
);
11149 /* Inspect DIE in CU for a namespace alias. If one exists, record
11150 a new symbol for it.
11152 Returns 1 if a namespace alias was recorded, 0 otherwise. */
11155 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
11157 struct attribute
*attr
;
11159 /* If the die does not have a name, this is not a namespace
11161 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
11165 struct die_info
*d
= die
;
11166 struct dwarf2_cu
*imported_cu
= cu
;
11168 /* If the compiler has nested DW_AT_imported_declaration DIEs,
11169 keep inspecting DIEs until we hit the underlying import. */
11170 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
11171 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
11173 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
11177 d
= follow_die_ref (d
, attr
, &imported_cu
);
11178 if (d
->tag
!= DW_TAG_imported_declaration
)
11182 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
11184 complaint (_("DIE at %s has too many recursively imported "
11185 "declarations"), sect_offset_str (d
->sect_off
));
11192 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
11194 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
11195 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
11197 /* This declaration is a global namespace alias. Add
11198 a symbol for it whose type is the aliased namespace. */
11199 new_symbol (die
, type
, cu
);
11208 /* Return the using directives repository (global or local?) to use in the
11209 current context for CU.
11211 For Ada, imported declarations can materialize renamings, which *may* be
11212 global. However it is impossible (for now?) in DWARF to distinguish
11213 "external" imported declarations and "static" ones. As all imported
11214 declarations seem to be static in all other languages, make them all CU-wide
11215 global only in Ada. */
11217 static struct using_direct
**
11218 using_directives (struct dwarf2_cu
*cu
)
11220 if (cu
->language
== language_ada
11221 && cu
->get_builder ()->outermost_context_p ())
11222 return cu
->get_builder ()->get_global_using_directives ();
11224 return cu
->get_builder ()->get_local_using_directives ();
11227 /* Read the import statement specified by the given die and record it. */
11230 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
11232 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
11233 struct attribute
*import_attr
;
11234 struct die_info
*imported_die
, *child_die
;
11235 struct dwarf2_cu
*imported_cu
;
11236 const char *imported_name
;
11237 const char *imported_name_prefix
;
11238 const char *canonical_name
;
11239 const char *import_alias
;
11240 const char *imported_declaration
= NULL
;
11241 const char *import_prefix
;
11242 std::vector
<const char *> excludes
;
11244 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
11245 if (import_attr
== NULL
)
11247 complaint (_("Tag '%s' has no DW_AT_import"),
11248 dwarf_tag_name (die
->tag
));
11253 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
11254 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11255 if (imported_name
== NULL
)
11257 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
11259 The import in the following code:
11273 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
11274 <52> DW_AT_decl_file : 1
11275 <53> DW_AT_decl_line : 6
11276 <54> DW_AT_import : <0x75>
11277 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
11278 <59> DW_AT_name : B
11279 <5b> DW_AT_decl_file : 1
11280 <5c> DW_AT_decl_line : 2
11281 <5d> DW_AT_type : <0x6e>
11283 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
11284 <76> DW_AT_byte_size : 4
11285 <77> DW_AT_encoding : 5 (signed)
11287 imports the wrong die ( 0x75 instead of 0x58 ).
11288 This case will be ignored until the gcc bug is fixed. */
11292 /* Figure out the local name after import. */
11293 import_alias
= dwarf2_name (die
, cu
);
11295 /* Figure out where the statement is being imported to. */
11296 import_prefix
= determine_prefix (die
, cu
);
11298 /* Figure out what the scope of the imported die is and prepend it
11299 to the name of the imported die. */
11300 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
11302 if (imported_die
->tag
!= DW_TAG_namespace
11303 && imported_die
->tag
!= DW_TAG_module
)
11305 imported_declaration
= imported_name
;
11306 canonical_name
= imported_name_prefix
;
11308 else if (strlen (imported_name_prefix
) > 0)
11309 canonical_name
= obconcat (&objfile
->objfile_obstack
,
11310 imported_name_prefix
,
11311 (cu
->language
== language_d
? "." : "::"),
11312 imported_name
, (char *) NULL
);
11314 canonical_name
= imported_name
;
11316 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
11317 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
11318 child_die
= sibling_die (child_die
))
11320 /* DWARF-4: A Fortran use statement with a “rename list” may be
11321 represented by an imported module entry with an import attribute
11322 referring to the module and owned entries corresponding to those
11323 entities that are renamed as part of being imported. */
11325 if (child_die
->tag
!= DW_TAG_imported_declaration
)
11327 complaint (_("child DW_TAG_imported_declaration expected "
11328 "- DIE at %s [in module %s]"),
11329 sect_offset_str (child_die
->sect_off
),
11330 objfile_name (objfile
));
11334 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
11335 if (import_attr
== NULL
)
11337 complaint (_("Tag '%s' has no DW_AT_import"),
11338 dwarf_tag_name (child_die
->tag
));
11343 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
11345 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11346 if (imported_name
== NULL
)
11348 complaint (_("child DW_TAG_imported_declaration has unknown "
11349 "imported name - DIE at %s [in module %s]"),
11350 sect_offset_str (child_die
->sect_off
),
11351 objfile_name (objfile
));
11355 excludes
.push_back (imported_name
);
11357 process_die (child_die
, cu
);
11360 add_using_directive (using_directives (cu
),
11364 imported_declaration
,
11367 &objfile
->objfile_obstack
);
11370 /* ICC<14 does not output the required DW_AT_declaration on incomplete
11371 types, but gives them a size of zero. Starting with version 14,
11372 ICC is compatible with GCC. */
11375 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
11377 if (!cu
->checked_producer
)
11378 check_producer (cu
);
11380 return cu
->producer_is_icc_lt_14
;
11383 /* ICC generates a DW_AT_type for C void functions. This was observed on
11384 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
11385 which says that void functions should not have a DW_AT_type. */
11388 producer_is_icc (struct dwarf2_cu
*cu
)
11390 if (!cu
->checked_producer
)
11391 check_producer (cu
);
11393 return cu
->producer_is_icc
;
11396 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
11397 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
11398 this, it was first present in GCC release 4.3.0. */
11401 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
11403 if (!cu
->checked_producer
)
11404 check_producer (cu
);
11406 return cu
->producer_is_gcc_lt_4_3
;
11409 static file_and_directory
11410 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
11412 file_and_directory res
;
11414 /* Find the filename. Do not use dwarf2_name here, since the filename
11415 is not a source language identifier. */
11416 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
11417 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
11419 if (res
.comp_dir
== NULL
11420 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
11421 && IS_ABSOLUTE_PATH (res
.name
))
11423 res
.comp_dir_storage
= ldirname (res
.name
);
11424 if (!res
.comp_dir_storage
.empty ())
11425 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
11427 if (res
.comp_dir
!= NULL
)
11429 /* Irix 6.2 native cc prepends <machine>.: to the compilation
11430 directory, get rid of it. */
11431 const char *cp
= strchr (res
.comp_dir
, ':');
11433 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
11434 res
.comp_dir
= cp
+ 1;
11437 if (res
.name
== NULL
)
11438 res
.name
= "<unknown>";
11443 /* Handle DW_AT_stmt_list for a compilation unit.
11444 DIE is the DW_TAG_compile_unit die for CU.
11445 COMP_DIR is the compilation directory. LOWPC is passed to
11446 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
11449 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
11450 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
11452 struct dwarf2_per_objfile
*dwarf2_per_objfile
11453 = cu
->per_cu
->dwarf2_per_objfile
;
11454 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11455 struct attribute
*attr
;
11456 struct line_header line_header_local
;
11457 hashval_t line_header_local_hash
;
11459 int decode_mapping
;
11461 gdb_assert (! cu
->per_cu
->is_debug_types
);
11463 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
11467 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11469 /* The line header hash table is only created if needed (it exists to
11470 prevent redundant reading of the line table for partial_units).
11471 If we're given a partial_unit, we'll need it. If we're given a
11472 compile_unit, then use the line header hash table if it's already
11473 created, but don't create one just yet. */
11475 if (dwarf2_per_objfile
->line_header_hash
== NULL
11476 && die
->tag
== DW_TAG_partial_unit
)
11478 dwarf2_per_objfile
->line_header_hash
11479 = htab_create_alloc_ex (127, line_header_hash_voidp
,
11480 line_header_eq_voidp
,
11481 free_line_header_voidp
,
11482 &objfile
->objfile_obstack
,
11483 hashtab_obstack_allocate
,
11484 dummy_obstack_deallocate
);
11487 line_header_local
.sect_off
= line_offset
;
11488 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
11489 line_header_local_hash
= line_header_hash (&line_header_local
);
11490 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
11492 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11493 &line_header_local
,
11494 line_header_local_hash
, NO_INSERT
);
11496 /* For DW_TAG_compile_unit we need info like symtab::linetable which
11497 is not present in *SLOT (since if there is something in *SLOT then
11498 it will be for a partial_unit). */
11499 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
11501 gdb_assert (*slot
!= NULL
);
11502 cu
->line_header
= (struct line_header
*) *slot
;
11507 /* dwarf_decode_line_header does not yet provide sufficient information.
11508 We always have to call also dwarf_decode_lines for it. */
11509 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
11513 cu
->line_header
= lh
.release ();
11514 cu
->line_header_die_owner
= die
;
11516 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
11520 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11521 &line_header_local
,
11522 line_header_local_hash
, INSERT
);
11523 gdb_assert (slot
!= NULL
);
11525 if (slot
!= NULL
&& *slot
== NULL
)
11527 /* This newly decoded line number information unit will be owned
11528 by line_header_hash hash table. */
11529 *slot
= cu
->line_header
;
11530 cu
->line_header_die_owner
= NULL
;
11534 /* We cannot free any current entry in (*slot) as that struct line_header
11535 may be already used by multiple CUs. Create only temporary decoded
11536 line_header for this CU - it may happen at most once for each line
11537 number information unit. And if we're not using line_header_hash
11538 then this is what we want as well. */
11539 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
11541 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
11542 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
11547 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
11550 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11552 struct dwarf2_per_objfile
*dwarf2_per_objfile
11553 = cu
->per_cu
->dwarf2_per_objfile
;
11554 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11555 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11556 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
11557 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
11558 struct attribute
*attr
;
11559 struct die_info
*child_die
;
11560 CORE_ADDR baseaddr
;
11562 prepare_one_comp_unit (cu
, die
, cu
->language
);
11563 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11565 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
11567 /* If we didn't find a lowpc, set it to highpc to avoid complaints
11568 from finish_block. */
11569 if (lowpc
== ((CORE_ADDR
) -1))
11571 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11573 file_and_directory fnd
= find_file_and_directory (die
, cu
);
11575 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
11576 standardised yet. As a workaround for the language detection we fall
11577 back to the DW_AT_producer string. */
11578 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
11579 cu
->language
= language_opencl
;
11581 /* Similar hack for Go. */
11582 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
11583 set_cu_language (DW_LANG_Go
, cu
);
11585 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
11587 /* Decode line number information if present. We do this before
11588 processing child DIEs, so that the line header table is available
11589 for DW_AT_decl_file. */
11590 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
11592 /* Process all dies in compilation unit. */
11593 if (die
->child
!= NULL
)
11595 child_die
= die
->child
;
11596 while (child_die
&& child_die
->tag
)
11598 process_die (child_die
, cu
);
11599 child_die
= sibling_die (child_die
);
11603 /* Decode macro information, if present. Dwarf 2 macro information
11604 refers to information in the line number info statement program
11605 header, so we can only read it if we've read the header
11607 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
11609 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
11610 if (attr
&& cu
->line_header
)
11612 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
11613 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
11615 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
11619 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
11620 if (attr
&& cu
->line_header
)
11622 unsigned int macro_offset
= DW_UNSND (attr
);
11624 dwarf_decode_macros (cu
, macro_offset
, 0);
11630 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
11632 struct type_unit_group
*tu_group
;
11634 struct attribute
*attr
;
11636 struct signatured_type
*sig_type
;
11638 gdb_assert (per_cu
->is_debug_types
);
11639 sig_type
= (struct signatured_type
*) per_cu
;
11641 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
11643 /* If we're using .gdb_index (includes -readnow) then
11644 per_cu->type_unit_group may not have been set up yet. */
11645 if (sig_type
->type_unit_group
== NULL
)
11646 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
11647 tu_group
= sig_type
->type_unit_group
;
11649 /* If we've already processed this stmt_list there's no real need to
11650 do it again, we could fake it and just recreate the part we need
11651 (file name,index -> symtab mapping). If data shows this optimization
11652 is useful we can do it then. */
11653 first_time
= tu_group
->compunit_symtab
== NULL
;
11655 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
11660 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11661 lh
= dwarf_decode_line_header (line_offset
, this);
11666 start_symtab ("", NULL
, 0);
11669 gdb_assert (tu_group
->symtabs
== NULL
);
11670 gdb_assert (m_builder
== nullptr);
11671 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
11672 m_builder
.reset (new struct buildsym_compunit
11673 (COMPUNIT_OBJFILE (cust
), "",
11674 COMPUNIT_DIRNAME (cust
),
11675 compunit_language (cust
),
11681 line_header
= lh
.release ();
11682 line_header_die_owner
= die
;
11686 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
11688 /* Note: We don't assign tu_group->compunit_symtab yet because we're
11689 still initializing it, and our caller (a few levels up)
11690 process_full_type_unit still needs to know if this is the first
11693 tu_group
->num_symtabs
= line_header
->file_names
.size ();
11694 tu_group
->symtabs
= XNEWVEC (struct symtab
*,
11695 line_header
->file_names
.size ());
11697 for (i
= 0; i
< line_header
->file_names
.size (); ++i
)
11699 file_entry
&fe
= line_header
->file_names
[i
];
11701 dwarf2_start_subfile (this, fe
.name
,
11702 fe
.include_dir (line_header
));
11703 buildsym_compunit
*b
= get_builder ();
11704 if (b
->get_current_subfile ()->symtab
== NULL
)
11706 /* NOTE: start_subfile will recognize when it's been
11707 passed a file it has already seen. So we can't
11708 assume there's a simple mapping from
11709 cu->line_header->file_names to subfiles, plus
11710 cu->line_header->file_names may contain dups. */
11711 b
->get_current_subfile ()->symtab
11712 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
11715 fe
.symtab
= b
->get_current_subfile ()->symtab
;
11716 tu_group
->symtabs
[i
] = fe
.symtab
;
11721 gdb_assert (m_builder
== nullptr);
11722 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
11723 m_builder
.reset (new struct buildsym_compunit
11724 (COMPUNIT_OBJFILE (cust
), "",
11725 COMPUNIT_DIRNAME (cust
),
11726 compunit_language (cust
),
11729 for (i
= 0; i
< line_header
->file_names
.size (); ++i
)
11731 file_entry
&fe
= line_header
->file_names
[i
];
11733 fe
.symtab
= tu_group
->symtabs
[i
];
11737 /* The main symtab is allocated last. Type units don't have DW_AT_name
11738 so they don't have a "real" (so to speak) symtab anyway.
11739 There is later code that will assign the main symtab to all symbols
11740 that don't have one. We need to handle the case of a symbol with a
11741 missing symtab (DW_AT_decl_file) anyway. */
11744 /* Process DW_TAG_type_unit.
11745 For TUs we want to skip the first top level sibling if it's not the
11746 actual type being defined by this TU. In this case the first top
11747 level sibling is there to provide context only. */
11750 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11752 struct die_info
*child_die
;
11754 prepare_one_comp_unit (cu
, die
, language_minimal
);
11756 /* Initialize (or reinitialize) the machinery for building symtabs.
11757 We do this before processing child DIEs, so that the line header table
11758 is available for DW_AT_decl_file. */
11759 cu
->setup_type_unit_groups (die
);
11761 if (die
->child
!= NULL
)
11763 child_die
= die
->child
;
11764 while (child_die
&& child_die
->tag
)
11766 process_die (child_die
, cu
);
11767 child_die
= sibling_die (child_die
);
11774 http://gcc.gnu.org/wiki/DebugFission
11775 http://gcc.gnu.org/wiki/DebugFissionDWP
11777 To simplify handling of both DWO files ("object" files with the DWARF info)
11778 and DWP files (a file with the DWOs packaged up into one file), we treat
11779 DWP files as having a collection of virtual DWO files. */
11782 hash_dwo_file (const void *item
)
11784 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11787 hash
= htab_hash_string (dwo_file
->dwo_name
);
11788 if (dwo_file
->comp_dir
!= NULL
)
11789 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11794 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11796 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11797 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11799 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11801 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11802 return lhs
->comp_dir
== rhs
->comp_dir
;
11803 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11806 /* Allocate a hash table for DWO files. */
11809 allocate_dwo_file_hash_table (struct objfile
*objfile
)
11811 auto delete_dwo_file
= [] (void *item
)
11813 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
11818 return htab_up (htab_create_alloc_ex (41,
11822 &objfile
->objfile_obstack
,
11823 hashtab_obstack_allocate
,
11824 dummy_obstack_deallocate
));
11827 /* Lookup DWO file DWO_NAME. */
11830 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11831 const char *dwo_name
,
11832 const char *comp_dir
)
11834 struct dwo_file find_entry
;
11837 if (dwarf2_per_objfile
->dwo_files
== NULL
)
11838 dwarf2_per_objfile
->dwo_files
11839 = allocate_dwo_file_hash_table (dwarf2_per_objfile
->objfile
);
11841 find_entry
.dwo_name
= dwo_name
;
11842 find_entry
.comp_dir
= comp_dir
;
11843 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
.get (), &find_entry
,
11850 hash_dwo_unit (const void *item
)
11852 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11854 /* This drops the top 32 bits of the id, but is ok for a hash. */
11855 return dwo_unit
->signature
;
11859 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11861 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11862 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11864 /* The signature is assumed to be unique within the DWO file.
11865 So while object file CU dwo_id's always have the value zero,
11866 that's OK, assuming each object file DWO file has only one CU,
11867 and that's the rule for now. */
11868 return lhs
->signature
== rhs
->signature
;
11871 /* Allocate a hash table for DWO CUs,TUs.
11872 There is one of these tables for each of CUs,TUs for each DWO file. */
11875 allocate_dwo_unit_table (struct objfile
*objfile
)
11877 /* Start out with a pretty small number.
11878 Generally DWO files contain only one CU and maybe some TUs. */
11879 return htab_create_alloc_ex (3,
11883 &objfile
->objfile_obstack
,
11884 hashtab_obstack_allocate
,
11885 dummy_obstack_deallocate
);
11888 /* Structure used to pass data to create_dwo_debug_info_hash_table_reader. */
11890 struct create_dwo_cu_data
11892 struct dwo_file
*dwo_file
;
11893 struct dwo_unit dwo_unit
;
11896 /* die_reader_func for create_dwo_cu. */
11899 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11900 const gdb_byte
*info_ptr
,
11901 struct die_info
*comp_unit_die
,
11905 struct dwarf2_cu
*cu
= reader
->cu
;
11906 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11907 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11908 struct create_dwo_cu_data
*data
= (struct create_dwo_cu_data
*) datap
;
11909 struct dwo_file
*dwo_file
= data
->dwo_file
;
11910 struct dwo_unit
*dwo_unit
= &data
->dwo_unit
;
11912 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11913 if (!signature
.has_value ())
11915 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11916 " its dwo_id [in module %s]"),
11917 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11921 dwo_unit
->dwo_file
= dwo_file
;
11922 dwo_unit
->signature
= *signature
;
11923 dwo_unit
->section
= section
;
11924 dwo_unit
->sect_off
= sect_off
;
11925 dwo_unit
->length
= cu
->per_cu
->length
;
11927 if (dwarf_read_debug
)
11928 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11929 sect_offset_str (sect_off
),
11930 hex_string (dwo_unit
->signature
));
11933 /* Create the dwo_units for the CUs in a DWO_FILE.
11934 Note: This function processes DWO files only, not DWP files. */
11937 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11938 struct dwo_file
&dwo_file
, dwarf2_section_info
§ion
,
11941 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11942 const gdb_byte
*info_ptr
, *end_ptr
;
11944 dwarf2_read_section (objfile
, §ion
);
11945 info_ptr
= section
.buffer
;
11947 if (info_ptr
== NULL
)
11950 if (dwarf_read_debug
)
11952 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11953 get_section_name (§ion
),
11954 get_section_file_name (§ion
));
11957 end_ptr
= info_ptr
+ section
.size
;
11958 while (info_ptr
< end_ptr
)
11960 struct dwarf2_per_cu_data per_cu
;
11961 struct create_dwo_cu_data create_dwo_cu_data
;
11962 struct dwo_unit
*dwo_unit
;
11964 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11966 memset (&create_dwo_cu_data
.dwo_unit
, 0,
11967 sizeof (create_dwo_cu_data
.dwo_unit
));
11968 memset (&per_cu
, 0, sizeof (per_cu
));
11969 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
11970 per_cu
.is_debug_types
= 0;
11971 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11972 per_cu
.section
= §ion
;
11973 create_dwo_cu_data
.dwo_file
= &dwo_file
;
11975 init_cutu_and_read_dies_no_follow (
11976 &per_cu
, &dwo_file
, create_dwo_cu_reader
, &create_dwo_cu_data
);
11977 info_ptr
+= per_cu
.length
;
11979 // If the unit could not be parsed, skip it.
11980 if (create_dwo_cu_data
.dwo_unit
.dwo_file
== NULL
)
11983 if (cus_htab
== NULL
)
11984 cus_htab
= allocate_dwo_unit_table (objfile
);
11986 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11987 *dwo_unit
= create_dwo_cu_data
.dwo_unit
;
11988 slot
= htab_find_slot (cus_htab
, dwo_unit
, INSERT
);
11989 gdb_assert (slot
!= NULL
);
11992 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11993 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11995 complaint (_("debug cu entry at offset %s is duplicate to"
11996 " the entry at offset %s, signature %s"),
11997 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11998 hex_string (dwo_unit
->signature
));
12000 *slot
= (void *)dwo_unit
;
12004 /* DWP file .debug_{cu,tu}_index section format:
12005 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
12009 Both index sections have the same format, and serve to map a 64-bit
12010 signature to a set of section numbers. Each section begins with a header,
12011 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
12012 indexes, and a pool of 32-bit section numbers. The index sections will be
12013 aligned at 8-byte boundaries in the file.
12015 The index section header consists of:
12017 V, 32 bit version number
12019 N, 32 bit number of compilation units or type units in the index
12020 M, 32 bit number of slots in the hash table
12022 Numbers are recorded using the byte order of the application binary.
12024 The hash table begins at offset 16 in the section, and consists of an array
12025 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
12026 order of the application binary). Unused slots in the hash table are 0.
12027 (We rely on the extreme unlikeliness of a signature being exactly 0.)
12029 The parallel table begins immediately after the hash table
12030 (at offset 16 + 8 * M from the beginning of the section), and consists of an
12031 array of 32-bit indexes (using the byte order of the application binary),
12032 corresponding 1-1 with slots in the hash table. Each entry in the parallel
12033 table contains a 32-bit index into the pool of section numbers. For unused
12034 hash table slots, the corresponding entry in the parallel table will be 0.
12036 The pool of section numbers begins immediately following the hash table
12037 (at offset 16 + 12 * M from the beginning of the section). The pool of
12038 section numbers consists of an array of 32-bit words (using the byte order
12039 of the application binary). Each item in the array is indexed starting
12040 from 0. The hash table entry provides the index of the first section
12041 number in the set. Additional section numbers in the set follow, and the
12042 set is terminated by a 0 entry (section number 0 is not used in ELF).
12044 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
12045 section must be the first entry in the set, and the .debug_abbrev.dwo must
12046 be the second entry. Other members of the set may follow in any order.
12052 DWP Version 2 combines all the .debug_info, etc. sections into one,
12053 and the entries in the index tables are now offsets into these sections.
12054 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
12057 Index Section Contents:
12059 Hash Table of Signatures dwp_hash_table.hash_table
12060 Parallel Table of Indices dwp_hash_table.unit_table
12061 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
12062 Table of Section Sizes dwp_hash_table.v2.sizes
12064 The index section header consists of:
12066 V, 32 bit version number
12067 L, 32 bit number of columns in the table of section offsets
12068 N, 32 bit number of compilation units or type units in the index
12069 M, 32 bit number of slots in the hash table
12071 Numbers are recorded using the byte order of the application binary.
12073 The hash table has the same format as version 1.
12074 The parallel table of indices has the same format as version 1,
12075 except that the entries are origin-1 indices into the table of sections
12076 offsets and the table of section sizes.
12078 The table of offsets begins immediately following the parallel table
12079 (at offset 16 + 12 * M from the beginning of the section). The table is
12080 a two-dimensional array of 32-bit words (using the byte order of the
12081 application binary), with L columns and N+1 rows, in row-major order.
12082 Each row in the array is indexed starting from 0. The first row provides
12083 a key to the remaining rows: each column in this row provides an identifier
12084 for a debug section, and the offsets in the same column of subsequent rows
12085 refer to that section. The section identifiers are:
12087 DW_SECT_INFO 1 .debug_info.dwo
12088 DW_SECT_TYPES 2 .debug_types.dwo
12089 DW_SECT_ABBREV 3 .debug_abbrev.dwo
12090 DW_SECT_LINE 4 .debug_line.dwo
12091 DW_SECT_LOC 5 .debug_loc.dwo
12092 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
12093 DW_SECT_MACINFO 7 .debug_macinfo.dwo
12094 DW_SECT_MACRO 8 .debug_macro.dwo
12096 The offsets provided by the CU and TU index sections are the base offsets
12097 for the contributions made by each CU or TU to the corresponding section
12098 in the package file. Each CU and TU header contains an abbrev_offset
12099 field, used to find the abbreviations table for that CU or TU within the
12100 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
12101 be interpreted as relative to the base offset given in the index section.
12102 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
12103 should be interpreted as relative to the base offset for .debug_line.dwo,
12104 and offsets into other debug sections obtained from DWARF attributes should
12105 also be interpreted as relative to the corresponding base offset.
12107 The table of sizes begins immediately following the table of offsets.
12108 Like the table of offsets, it is a two-dimensional array of 32-bit words,
12109 with L columns and N rows, in row-major order. Each row in the array is
12110 indexed starting from 1 (row 0 is shared by the two tables).
12114 Hash table lookup is handled the same in version 1 and 2:
12116 We assume that N and M will not exceed 2^32 - 1.
12117 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
12119 Given a 64-bit compilation unit signature or a type signature S, an entry
12120 in the hash table is located as follows:
12122 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
12123 the low-order k bits all set to 1.
12125 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
12127 3) If the hash table entry at index H matches the signature, use that
12128 entry. If the hash table entry at index H is unused (all zeroes),
12129 terminate the search: the signature is not present in the table.
12131 4) Let H = (H + H') modulo M. Repeat at Step 3.
12133 Because M > N and H' and M are relatively prime, the search is guaranteed
12134 to stop at an unused slot or find the match. */
12136 /* Create a hash table to map DWO IDs to their CU/TU entry in
12137 .debug_{info,types}.dwo in DWP_FILE.
12138 Returns NULL if there isn't one.
12139 Note: This function processes DWP files only, not DWO files. */
12141 static struct dwp_hash_table
*
12142 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12143 struct dwp_file
*dwp_file
, int is_debug_types
)
12145 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12146 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12147 const gdb_byte
*index_ptr
, *index_end
;
12148 struct dwarf2_section_info
*index
;
12149 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
12150 struct dwp_hash_table
*htab
;
12152 if (is_debug_types
)
12153 index
= &dwp_file
->sections
.tu_index
;
12155 index
= &dwp_file
->sections
.cu_index
;
12157 if (dwarf2_section_empty_p (index
))
12159 dwarf2_read_section (objfile
, index
);
12161 index_ptr
= index
->buffer
;
12162 index_end
= index_ptr
+ index
->size
;
12164 version
= read_4_bytes (dbfd
, index_ptr
);
12167 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
12171 nr_units
= read_4_bytes (dbfd
, index_ptr
);
12173 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
12176 if (version
!= 1 && version
!= 2)
12178 error (_("Dwarf Error: unsupported DWP file version (%s)"
12179 " [in module %s]"),
12180 pulongest (version
), dwp_file
->name
);
12182 if (nr_slots
!= (nr_slots
& -nr_slots
))
12184 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
12185 " is not power of 2 [in module %s]"),
12186 pulongest (nr_slots
), dwp_file
->name
);
12189 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
12190 htab
->version
= version
;
12191 htab
->nr_columns
= nr_columns
;
12192 htab
->nr_units
= nr_units
;
12193 htab
->nr_slots
= nr_slots
;
12194 htab
->hash_table
= index_ptr
;
12195 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
12197 /* Exit early if the table is empty. */
12198 if (nr_slots
== 0 || nr_units
== 0
12199 || (version
== 2 && nr_columns
== 0))
12201 /* All must be zero. */
12202 if (nr_slots
!= 0 || nr_units
!= 0
12203 || (version
== 2 && nr_columns
!= 0))
12205 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
12206 " all zero [in modules %s]"),
12214 htab
->section_pool
.v1
.indices
=
12215 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12216 /* It's harder to decide whether the section is too small in v1.
12217 V1 is deprecated anyway so we punt. */
12221 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12222 int *ids
= htab
->section_pool
.v2
.section_ids
;
12223 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
12224 /* Reverse map for error checking. */
12225 int ids_seen
[DW_SECT_MAX
+ 1];
12228 if (nr_columns
< 2)
12230 error (_("Dwarf Error: bad DWP hash table, too few columns"
12231 " in section table [in module %s]"),
12234 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
12236 error (_("Dwarf Error: bad DWP hash table, too many columns"
12237 " in section table [in module %s]"),
12240 memset (ids
, 255, sizeof_ids
);
12241 memset (ids_seen
, 255, sizeof (ids_seen
));
12242 for (i
= 0; i
< nr_columns
; ++i
)
12244 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
12246 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
12248 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
12249 " in section table [in module %s]"),
12250 id
, dwp_file
->name
);
12252 if (ids_seen
[id
] != -1)
12254 error (_("Dwarf Error: bad DWP hash table, duplicate section"
12255 " id %d in section table [in module %s]"),
12256 id
, dwp_file
->name
);
12261 /* Must have exactly one info or types section. */
12262 if (((ids_seen
[DW_SECT_INFO
] != -1)
12263 + (ids_seen
[DW_SECT_TYPES
] != -1))
12266 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
12267 " DWO info/types section [in module %s]"),
12270 /* Must have an abbrev section. */
12271 if (ids_seen
[DW_SECT_ABBREV
] == -1)
12273 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
12274 " section [in module %s]"),
12277 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
12278 htab
->section_pool
.v2
.sizes
=
12279 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
12280 * nr_units
* nr_columns
);
12281 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
12282 * nr_units
* nr_columns
))
12285 error (_("Dwarf Error: DWP index section is corrupt (too small)"
12286 " [in module %s]"),
12294 /* Update SECTIONS with the data from SECTP.
12296 This function is like the other "locate" section routines that are
12297 passed to bfd_map_over_sections, but in this context the sections to
12298 read comes from the DWP V1 hash table, not the full ELF section table.
12300 The result is non-zero for success, or zero if an error was found. */
12303 locate_v1_virtual_dwo_sections (asection
*sectp
,
12304 struct virtual_v1_dwo_sections
*sections
)
12306 const struct dwop_section_names
*names
= &dwop_section_names
;
12308 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12310 /* There can be only one. */
12311 if (sections
->abbrev
.s
.section
!= NULL
)
12313 sections
->abbrev
.s
.section
= sectp
;
12314 sections
->abbrev
.size
= bfd_section_size (sectp
);
12316 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
12317 || section_is_p (sectp
->name
, &names
->types_dwo
))
12319 /* There can be only one. */
12320 if (sections
->info_or_types
.s
.section
!= NULL
)
12322 sections
->info_or_types
.s
.section
= sectp
;
12323 sections
->info_or_types
.size
= bfd_section_size (sectp
);
12325 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12327 /* There can be only one. */
12328 if (sections
->line
.s
.section
!= NULL
)
12330 sections
->line
.s
.section
= sectp
;
12331 sections
->line
.size
= bfd_section_size (sectp
);
12333 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12335 /* There can be only one. */
12336 if (sections
->loc
.s
.section
!= NULL
)
12338 sections
->loc
.s
.section
= sectp
;
12339 sections
->loc
.size
= bfd_section_size (sectp
);
12341 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12343 /* There can be only one. */
12344 if (sections
->macinfo
.s
.section
!= NULL
)
12346 sections
->macinfo
.s
.section
= sectp
;
12347 sections
->macinfo
.size
= bfd_section_size (sectp
);
12349 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12351 /* There can be only one. */
12352 if (sections
->macro
.s
.section
!= NULL
)
12354 sections
->macro
.s
.section
= sectp
;
12355 sections
->macro
.size
= bfd_section_size (sectp
);
12357 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12359 /* There can be only one. */
12360 if (sections
->str_offsets
.s
.section
!= NULL
)
12362 sections
->str_offsets
.s
.section
= sectp
;
12363 sections
->str_offsets
.size
= bfd_section_size (sectp
);
12367 /* No other kind of section is valid. */
12374 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12375 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12376 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12377 This is for DWP version 1 files. */
12379 static struct dwo_unit
*
12380 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12381 struct dwp_file
*dwp_file
,
12382 uint32_t unit_index
,
12383 const char *comp_dir
,
12384 ULONGEST signature
, int is_debug_types
)
12386 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12387 const struct dwp_hash_table
*dwp_htab
=
12388 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12389 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12390 const char *kind
= is_debug_types
? "TU" : "CU";
12391 struct dwo_file
*dwo_file
;
12392 struct dwo_unit
*dwo_unit
;
12393 struct virtual_v1_dwo_sections sections
;
12394 void **dwo_file_slot
;
12397 gdb_assert (dwp_file
->version
== 1);
12399 if (dwarf_read_debug
)
12401 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
12403 pulongest (unit_index
), hex_string (signature
),
12407 /* Fetch the sections of this DWO unit.
12408 Put a limit on the number of sections we look for so that bad data
12409 doesn't cause us to loop forever. */
12411 #define MAX_NR_V1_DWO_SECTIONS \
12412 (1 /* .debug_info or .debug_types */ \
12413 + 1 /* .debug_abbrev */ \
12414 + 1 /* .debug_line */ \
12415 + 1 /* .debug_loc */ \
12416 + 1 /* .debug_str_offsets */ \
12417 + 1 /* .debug_macro or .debug_macinfo */ \
12418 + 1 /* trailing zero */)
12420 memset (§ions
, 0, sizeof (sections
));
12422 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
12425 uint32_t section_nr
=
12426 read_4_bytes (dbfd
,
12427 dwp_htab
->section_pool
.v1
.indices
12428 + (unit_index
+ i
) * sizeof (uint32_t));
12430 if (section_nr
== 0)
12432 if (section_nr
>= dwp_file
->num_sections
)
12434 error (_("Dwarf Error: bad DWP hash table, section number too large"
12435 " [in module %s]"),
12439 sectp
= dwp_file
->elf_sections
[section_nr
];
12440 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
12442 error (_("Dwarf Error: bad DWP hash table, invalid section found"
12443 " [in module %s]"),
12449 || dwarf2_section_empty_p (§ions
.info_or_types
)
12450 || dwarf2_section_empty_p (§ions
.abbrev
))
12452 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
12453 " [in module %s]"),
12456 if (i
== MAX_NR_V1_DWO_SECTIONS
)
12458 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
12459 " [in module %s]"),
12463 /* It's easier for the rest of the code if we fake a struct dwo_file and
12464 have dwo_unit "live" in that. At least for now.
12466 The DWP file can be made up of a random collection of CUs and TUs.
12467 However, for each CU + set of TUs that came from the same original DWO
12468 file, we can combine them back into a virtual DWO file to save space
12469 (fewer struct dwo_file objects to allocate). Remember that for really
12470 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12472 std::string virtual_dwo_name
=
12473 string_printf ("virtual-dwo/%d-%d-%d-%d",
12474 get_section_id (§ions
.abbrev
),
12475 get_section_id (§ions
.line
),
12476 get_section_id (§ions
.loc
),
12477 get_section_id (§ions
.str_offsets
));
12478 /* Can we use an existing virtual DWO file? */
12479 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12480 virtual_dwo_name
.c_str (),
12482 /* Create one if necessary. */
12483 if (*dwo_file_slot
== NULL
)
12485 if (dwarf_read_debug
)
12487 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12488 virtual_dwo_name
.c_str ());
12490 dwo_file
= new struct dwo_file
;
12491 dwo_file
->dwo_name
= obstack_strdup (&objfile
->objfile_obstack
,
12493 dwo_file
->comp_dir
= comp_dir
;
12494 dwo_file
->sections
.abbrev
= sections
.abbrev
;
12495 dwo_file
->sections
.line
= sections
.line
;
12496 dwo_file
->sections
.loc
= sections
.loc
;
12497 dwo_file
->sections
.macinfo
= sections
.macinfo
;
12498 dwo_file
->sections
.macro
= sections
.macro
;
12499 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
12500 /* The "str" section is global to the entire DWP file. */
12501 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12502 /* The info or types section is assigned below to dwo_unit,
12503 there's no need to record it in dwo_file.
12504 Also, we can't simply record type sections in dwo_file because
12505 we record a pointer into the vector in dwo_unit. As we collect more
12506 types we'll grow the vector and eventually have to reallocate space
12507 for it, invalidating all copies of pointers into the previous
12509 *dwo_file_slot
= dwo_file
;
12513 if (dwarf_read_debug
)
12515 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12516 virtual_dwo_name
.c_str ());
12518 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12521 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12522 dwo_unit
->dwo_file
= dwo_file
;
12523 dwo_unit
->signature
= signature
;
12524 dwo_unit
->section
=
12525 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12526 *dwo_unit
->section
= sections
.info_or_types
;
12527 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12532 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
12533 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
12534 piece within that section used by a TU/CU, return a virtual section
12535 of just that piece. */
12537 static struct dwarf2_section_info
12538 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12539 struct dwarf2_section_info
*section
,
12540 bfd_size_type offset
, bfd_size_type size
)
12542 struct dwarf2_section_info result
;
12545 gdb_assert (section
!= NULL
);
12546 gdb_assert (!section
->is_virtual
);
12548 memset (&result
, 0, sizeof (result
));
12549 result
.s
.containing_section
= section
;
12550 result
.is_virtual
= true;
12555 sectp
= get_section_bfd_section (section
);
12557 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
12558 bounds of the real section. This is a pretty-rare event, so just
12559 flag an error (easier) instead of a warning and trying to cope. */
12561 || offset
+ size
> bfd_section_size (sectp
))
12563 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
12564 " in section %s [in module %s]"),
12565 sectp
? bfd_section_name (sectp
) : "<unknown>",
12566 objfile_name (dwarf2_per_objfile
->objfile
));
12569 result
.virtual_offset
= offset
;
12570 result
.size
= size
;
12574 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12575 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12576 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12577 This is for DWP version 2 files. */
12579 static struct dwo_unit
*
12580 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12581 struct dwp_file
*dwp_file
,
12582 uint32_t unit_index
,
12583 const char *comp_dir
,
12584 ULONGEST signature
, int is_debug_types
)
12586 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12587 const struct dwp_hash_table
*dwp_htab
=
12588 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12589 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12590 const char *kind
= is_debug_types
? "TU" : "CU";
12591 struct dwo_file
*dwo_file
;
12592 struct dwo_unit
*dwo_unit
;
12593 struct virtual_v2_dwo_sections sections
;
12594 void **dwo_file_slot
;
12597 gdb_assert (dwp_file
->version
== 2);
12599 if (dwarf_read_debug
)
12601 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
12603 pulongest (unit_index
), hex_string (signature
),
12607 /* Fetch the section offsets of this DWO unit. */
12609 memset (§ions
, 0, sizeof (sections
));
12611 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12613 uint32_t offset
= read_4_bytes (dbfd
,
12614 dwp_htab
->section_pool
.v2
.offsets
12615 + (((unit_index
- 1) * dwp_htab
->nr_columns
12617 * sizeof (uint32_t)));
12618 uint32_t size
= read_4_bytes (dbfd
,
12619 dwp_htab
->section_pool
.v2
.sizes
12620 + (((unit_index
- 1) * dwp_htab
->nr_columns
12622 * sizeof (uint32_t)));
12624 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
12627 case DW_SECT_TYPES
:
12628 sections
.info_or_types_offset
= offset
;
12629 sections
.info_or_types_size
= size
;
12631 case DW_SECT_ABBREV
:
12632 sections
.abbrev_offset
= offset
;
12633 sections
.abbrev_size
= size
;
12636 sections
.line_offset
= offset
;
12637 sections
.line_size
= size
;
12640 sections
.loc_offset
= offset
;
12641 sections
.loc_size
= size
;
12643 case DW_SECT_STR_OFFSETS
:
12644 sections
.str_offsets_offset
= offset
;
12645 sections
.str_offsets_size
= size
;
12647 case DW_SECT_MACINFO
:
12648 sections
.macinfo_offset
= offset
;
12649 sections
.macinfo_size
= size
;
12651 case DW_SECT_MACRO
:
12652 sections
.macro_offset
= offset
;
12653 sections
.macro_size
= size
;
12658 /* It's easier for the rest of the code if we fake a struct dwo_file and
12659 have dwo_unit "live" in that. At least for now.
12661 The DWP file can be made up of a random collection of CUs and TUs.
12662 However, for each CU + set of TUs that came from the same original DWO
12663 file, we can combine them back into a virtual DWO file to save space
12664 (fewer struct dwo_file objects to allocate). Remember that for really
12665 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12667 std::string virtual_dwo_name
=
12668 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
12669 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12670 (long) (sections
.line_size
? sections
.line_offset
: 0),
12671 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
12672 (long) (sections
.str_offsets_size
12673 ? sections
.str_offsets_offset
: 0));
12674 /* Can we use an existing virtual DWO file? */
12675 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12676 virtual_dwo_name
.c_str (),
12678 /* Create one if necessary. */
12679 if (*dwo_file_slot
== NULL
)
12681 if (dwarf_read_debug
)
12683 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12684 virtual_dwo_name
.c_str ());
12686 dwo_file
= new struct dwo_file
;
12687 dwo_file
->dwo_name
= obstack_strdup (&objfile
->objfile_obstack
,
12689 dwo_file
->comp_dir
= comp_dir
;
12690 dwo_file
->sections
.abbrev
=
12691 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
12692 sections
.abbrev_offset
, sections
.abbrev_size
);
12693 dwo_file
->sections
.line
=
12694 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
12695 sections
.line_offset
, sections
.line_size
);
12696 dwo_file
->sections
.loc
=
12697 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
12698 sections
.loc_offset
, sections
.loc_size
);
12699 dwo_file
->sections
.macinfo
=
12700 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
12701 sections
.macinfo_offset
, sections
.macinfo_size
);
12702 dwo_file
->sections
.macro
=
12703 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
12704 sections
.macro_offset
, sections
.macro_size
);
12705 dwo_file
->sections
.str_offsets
=
12706 create_dwp_v2_section (dwarf2_per_objfile
,
12707 &dwp_file
->sections
.str_offsets
,
12708 sections
.str_offsets_offset
,
12709 sections
.str_offsets_size
);
12710 /* The "str" section is global to the entire DWP file. */
12711 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12712 /* The info or types section is assigned below to dwo_unit,
12713 there's no need to record it in dwo_file.
12714 Also, we can't simply record type sections in dwo_file because
12715 we record a pointer into the vector in dwo_unit. As we collect more
12716 types we'll grow the vector and eventually have to reallocate space
12717 for it, invalidating all copies of pointers into the previous
12719 *dwo_file_slot
= dwo_file
;
12723 if (dwarf_read_debug
)
12725 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12726 virtual_dwo_name
.c_str ());
12728 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12731 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12732 dwo_unit
->dwo_file
= dwo_file
;
12733 dwo_unit
->signature
= signature
;
12734 dwo_unit
->section
=
12735 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12736 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
12738 ? &dwp_file
->sections
.types
12739 : &dwp_file
->sections
.info
,
12740 sections
.info_or_types_offset
,
12741 sections
.info_or_types_size
);
12742 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12747 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12748 Returns NULL if the signature isn't found. */
12750 static struct dwo_unit
*
12751 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12752 struct dwp_file
*dwp_file
, const char *comp_dir
,
12753 ULONGEST signature
, int is_debug_types
)
12755 const struct dwp_hash_table
*dwp_htab
=
12756 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12757 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12758 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12759 uint32_t hash
= signature
& mask
;
12760 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12763 struct dwo_unit find_dwo_cu
;
12765 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12766 find_dwo_cu
.signature
= signature
;
12767 slot
= htab_find_slot (is_debug_types
12768 ? dwp_file
->loaded_tus
12769 : dwp_file
->loaded_cus
,
12770 &find_dwo_cu
, INSERT
);
12773 return (struct dwo_unit
*) *slot
;
12775 /* Use a for loop so that we don't loop forever on bad debug info. */
12776 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12778 ULONGEST signature_in_table
;
12780 signature_in_table
=
12781 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12782 if (signature_in_table
== signature
)
12784 uint32_t unit_index
=
12785 read_4_bytes (dbfd
,
12786 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12788 if (dwp_file
->version
== 1)
12790 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
12791 dwp_file
, unit_index
,
12792 comp_dir
, signature
,
12797 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
12798 dwp_file
, unit_index
,
12799 comp_dir
, signature
,
12802 return (struct dwo_unit
*) *slot
;
12804 if (signature_in_table
== 0)
12806 hash
= (hash
+ hash2
) & mask
;
12809 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12810 " [in module %s]"),
12814 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12815 Open the file specified by FILE_NAME and hand it off to BFD for
12816 preliminary analysis. Return a newly initialized bfd *, which
12817 includes a canonicalized copy of FILE_NAME.
12818 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12819 SEARCH_CWD is true if the current directory is to be searched.
12820 It will be searched before debug-file-directory.
12821 If successful, the file is added to the bfd include table of the
12822 objfile's bfd (see gdb_bfd_record_inclusion).
12823 If unable to find/open the file, return NULL.
12824 NOTE: This function is derived from symfile_bfd_open. */
12826 static gdb_bfd_ref_ptr
12827 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12828 const char *file_name
, int is_dwp
, int search_cwd
)
12831 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12832 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12833 to debug_file_directory. */
12834 const char *search_path
;
12835 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12837 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12840 if (*debug_file_directory
!= '\0')
12842 search_path_holder
.reset (concat (".", dirname_separator_string
,
12843 debug_file_directory
,
12845 search_path
= search_path_holder
.get ();
12851 search_path
= debug_file_directory
;
12853 openp_flags flags
= OPF_RETURN_REALPATH
;
12855 flags
|= OPF_SEARCH_IN_PATH
;
12857 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12858 desc
= openp (search_path
, flags
, file_name
,
12859 O_RDONLY
| O_BINARY
, &absolute_name
);
12863 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12865 if (sym_bfd
== NULL
)
12867 bfd_set_cacheable (sym_bfd
.get (), 1);
12869 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12872 /* Success. Record the bfd as having been included by the objfile's bfd.
12873 This is important because things like demangled_names_hash lives in the
12874 objfile's per_bfd space and may have references to things like symbol
12875 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12876 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12881 /* Try to open DWO file FILE_NAME.
12882 COMP_DIR is the DW_AT_comp_dir attribute.
12883 The result is the bfd handle of the file.
12884 If there is a problem finding or opening the file, return NULL.
12885 Upon success, the canonicalized path of the file is stored in the bfd,
12886 same as symfile_bfd_open. */
12888 static gdb_bfd_ref_ptr
12889 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12890 const char *file_name
, const char *comp_dir
)
12892 if (IS_ABSOLUTE_PATH (file_name
))
12893 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12894 0 /*is_dwp*/, 0 /*search_cwd*/);
12896 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12898 if (comp_dir
!= NULL
)
12900 char *path_to_try
= concat (comp_dir
, SLASH_STRING
,
12901 file_name
, (char *) NULL
);
12903 /* NOTE: If comp_dir is a relative path, this will also try the
12904 search path, which seems useful. */
12905 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
12908 1 /*search_cwd*/));
12909 xfree (path_to_try
);
12914 /* That didn't work, try debug-file-directory, which, despite its name,
12915 is a list of paths. */
12917 if (*debug_file_directory
== '\0')
12920 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12921 0 /*is_dwp*/, 1 /*search_cwd*/);
12924 /* This function is mapped across the sections and remembers the offset and
12925 size of each of the DWO debugging sections we are interested in. */
12928 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12930 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12931 const struct dwop_section_names
*names
= &dwop_section_names
;
12933 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12935 dwo_sections
->abbrev
.s
.section
= sectp
;
12936 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12938 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12940 dwo_sections
->info
.s
.section
= sectp
;
12941 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12943 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12945 dwo_sections
->line
.s
.section
= sectp
;
12946 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12948 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12950 dwo_sections
->loc
.s
.section
= sectp
;
12951 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12953 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12955 dwo_sections
->macinfo
.s
.section
= sectp
;
12956 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12958 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12960 dwo_sections
->macro
.s
.section
= sectp
;
12961 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12963 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12965 dwo_sections
->str
.s
.section
= sectp
;
12966 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12968 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12970 dwo_sections
->str_offsets
.s
.section
= sectp
;
12971 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12973 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12975 struct dwarf2_section_info type_section
;
12977 memset (&type_section
, 0, sizeof (type_section
));
12978 type_section
.s
.section
= sectp
;
12979 type_section
.size
= bfd_section_size (sectp
);
12980 dwo_sections
->types
.push_back (type_section
);
12984 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12985 by PER_CU. This is for the non-DWP case.
12986 The result is NULL if DWO_NAME can't be found. */
12988 static struct dwo_file
*
12989 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
12990 const char *dwo_name
, const char *comp_dir
)
12992 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
12994 gdb_bfd_ref_ptr dbfd
= open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
);
12997 if (dwarf_read_debug
)
12998 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
13002 dwo_file_up
dwo_file (new struct dwo_file
);
13003 dwo_file
->dwo_name
= dwo_name
;
13004 dwo_file
->comp_dir
= comp_dir
;
13005 dwo_file
->dbfd
= std::move (dbfd
);
13007 bfd_map_over_sections (dwo_file
->dbfd
.get (), dwarf2_locate_dwo_sections
,
13008 &dwo_file
->sections
);
13010 create_cus_hash_table (dwarf2_per_objfile
, *dwo_file
, dwo_file
->sections
.info
,
13013 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
.get (),
13014 dwo_file
->sections
.types
, dwo_file
->tus
);
13016 if (dwarf_read_debug
)
13017 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
13019 return dwo_file
.release ();
13022 /* This function is mapped across the sections and remembers the offset and
13023 size of each of the DWP debugging sections common to version 1 and 2 that
13024 we are interested in. */
13027 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
13028 void *dwp_file_ptr
)
13030 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
13031 const struct dwop_section_names
*names
= &dwop_section_names
;
13032 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
13034 /* Record the ELF section number for later lookup: this is what the
13035 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
13036 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
13037 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
13039 /* Look for specific sections that we need. */
13040 if (section_is_p (sectp
->name
, &names
->str_dwo
))
13042 dwp_file
->sections
.str
.s
.section
= sectp
;
13043 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
13045 else if (section_is_p (sectp
->name
, &names
->cu_index
))
13047 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
13048 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
13050 else if (section_is_p (sectp
->name
, &names
->tu_index
))
13052 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
13053 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
13057 /* This function is mapped across the sections and remembers the offset and
13058 size of each of the DWP version 2 debugging sections that we are interested
13059 in. This is split into a separate function because we don't know if we
13060 have version 1 or 2 until we parse the cu_index/tu_index sections. */
13063 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
13065 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
13066 const struct dwop_section_names
*names
= &dwop_section_names
;
13067 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
13069 /* Record the ELF section number for later lookup: this is what the
13070 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
13071 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
13072 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
13074 /* Look for specific sections that we need. */
13075 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
13077 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
13078 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
13080 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
13082 dwp_file
->sections
.info
.s
.section
= sectp
;
13083 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
13085 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
13087 dwp_file
->sections
.line
.s
.section
= sectp
;
13088 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
13090 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
13092 dwp_file
->sections
.loc
.s
.section
= sectp
;
13093 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
13095 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
13097 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
13098 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
13100 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
13102 dwp_file
->sections
.macro
.s
.section
= sectp
;
13103 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
13105 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
13107 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
13108 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
13110 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
13112 dwp_file
->sections
.types
.s
.section
= sectp
;
13113 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
13117 /* Hash function for dwp_file loaded CUs/TUs. */
13120 hash_dwp_loaded_cutus (const void *item
)
13122 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
13124 /* This drops the top 32 bits of the signature, but is ok for a hash. */
13125 return dwo_unit
->signature
;
13128 /* Equality function for dwp_file loaded CUs/TUs. */
13131 eq_dwp_loaded_cutus (const void *a
, const void *b
)
13133 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
13134 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
13136 return dua
->signature
== dub
->signature
;
13139 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
13142 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
13144 return htab_create_alloc_ex (3,
13145 hash_dwp_loaded_cutus
,
13146 eq_dwp_loaded_cutus
,
13148 &objfile
->objfile_obstack
,
13149 hashtab_obstack_allocate
,
13150 dummy_obstack_deallocate
);
13153 /* Try to open DWP file FILE_NAME.
13154 The result is the bfd handle of the file.
13155 If there is a problem finding or opening the file, return NULL.
13156 Upon success, the canonicalized path of the file is stored in the bfd,
13157 same as symfile_bfd_open. */
13159 static gdb_bfd_ref_ptr
13160 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
13161 const char *file_name
)
13163 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
13165 1 /*search_cwd*/));
13169 /* Work around upstream bug 15652.
13170 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
13171 [Whether that's a "bug" is debatable, but it is getting in our way.]
13172 We have no real idea where the dwp file is, because gdb's realpath-ing
13173 of the executable's path may have discarded the needed info.
13174 [IWBN if the dwp file name was recorded in the executable, akin to
13175 .gnu_debuglink, but that doesn't exist yet.]
13176 Strip the directory from FILE_NAME and search again. */
13177 if (*debug_file_directory
!= '\0')
13179 /* Don't implicitly search the current directory here.
13180 If the user wants to search "." to handle this case,
13181 it must be added to debug-file-directory. */
13182 return try_open_dwop_file (dwarf2_per_objfile
,
13183 lbasename (file_name
), 1 /*is_dwp*/,
13190 /* Initialize the use of the DWP file for the current objfile.
13191 By convention the name of the DWP file is ${objfile}.dwp.
13192 The result is NULL if it can't be found. */
13194 static std::unique_ptr
<struct dwp_file
>
13195 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
13197 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13199 /* Try to find first .dwp for the binary file before any symbolic links
13202 /* If the objfile is a debug file, find the name of the real binary
13203 file and get the name of dwp file from there. */
13204 std::string dwp_name
;
13205 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
13207 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
13208 const char *backlink_basename
= lbasename (backlink
->original_name
);
13210 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
13213 dwp_name
= objfile
->original_name
;
13215 dwp_name
+= ".dwp";
13217 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
13219 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
13221 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
13222 dwp_name
= objfile_name (objfile
);
13223 dwp_name
+= ".dwp";
13224 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
13229 if (dwarf_read_debug
)
13230 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
13231 return std::unique_ptr
<dwp_file
> ();
13234 const char *name
= bfd_get_filename (dbfd
.get ());
13235 std::unique_ptr
<struct dwp_file
> dwp_file
13236 (new struct dwp_file (name
, std::move (dbfd
)));
13238 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
13239 dwp_file
->elf_sections
=
13240 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
13241 dwp_file
->num_sections
, asection
*);
13243 bfd_map_over_sections (dwp_file
->dbfd
.get (),
13244 dwarf2_locate_common_dwp_sections
,
13247 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
13250 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
13253 /* The DWP file version is stored in the hash table. Oh well. */
13254 if (dwp_file
->cus
&& dwp_file
->tus
13255 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
13257 /* Technically speaking, we should try to limp along, but this is
13258 pretty bizarre. We use pulongest here because that's the established
13259 portability solution (e.g, we cannot use %u for uint32_t). */
13260 error (_("Dwarf Error: DWP file CU version %s doesn't match"
13261 " TU version %s [in DWP file %s]"),
13262 pulongest (dwp_file
->cus
->version
),
13263 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
13267 dwp_file
->version
= dwp_file
->cus
->version
;
13268 else if (dwp_file
->tus
)
13269 dwp_file
->version
= dwp_file
->tus
->version
;
13271 dwp_file
->version
= 2;
13273 if (dwp_file
->version
== 2)
13274 bfd_map_over_sections (dwp_file
->dbfd
.get (),
13275 dwarf2_locate_v2_dwp_sections
,
13278 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table (objfile
);
13279 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table (objfile
);
13281 if (dwarf_read_debug
)
13283 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
13284 fprintf_unfiltered (gdb_stdlog
,
13285 " %s CUs, %s TUs\n",
13286 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
13287 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
13293 /* Wrapper around open_and_init_dwp_file, only open it once. */
13295 static struct dwp_file
*
13296 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
13298 if (! dwarf2_per_objfile
->dwp_checked
)
13300 dwarf2_per_objfile
->dwp_file
13301 = open_and_init_dwp_file (dwarf2_per_objfile
);
13302 dwarf2_per_objfile
->dwp_checked
= 1;
13304 return dwarf2_per_objfile
->dwp_file
.get ();
13307 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
13308 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
13309 or in the DWP file for the objfile, referenced by THIS_UNIT.
13310 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
13311 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
13313 This is called, for example, when wanting to read a variable with a
13314 complex location. Therefore we don't want to do file i/o for every call.
13315 Therefore we don't want to look for a DWO file on every call.
13316 Therefore we first see if we've already seen SIGNATURE in a DWP file,
13317 then we check if we've already seen DWO_NAME, and only THEN do we check
13320 The result is a pointer to the dwo_unit object or NULL if we didn't find it
13321 (dwo_id mismatch or couldn't find the DWO/DWP file). */
13323 static struct dwo_unit
*
13324 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
13325 const char *dwo_name
, const char *comp_dir
,
13326 ULONGEST signature
, int is_debug_types
)
13328 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_unit
->dwarf2_per_objfile
;
13329 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13330 const char *kind
= is_debug_types
? "TU" : "CU";
13331 void **dwo_file_slot
;
13332 struct dwo_file
*dwo_file
;
13333 struct dwp_file
*dwp_file
;
13335 /* First see if there's a DWP file.
13336 If we have a DWP file but didn't find the DWO inside it, don't
13337 look for the original DWO file. It makes gdb behave differently
13338 depending on whether one is debugging in the build tree. */
13340 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
13341 if (dwp_file
!= NULL
)
13343 const struct dwp_hash_table
*dwp_htab
=
13344 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
13346 if (dwp_htab
!= NULL
)
13348 struct dwo_unit
*dwo_cutu
=
13349 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
13350 signature
, is_debug_types
);
13352 if (dwo_cutu
!= NULL
)
13354 if (dwarf_read_debug
)
13356 fprintf_unfiltered (gdb_stdlog
,
13357 "Virtual DWO %s %s found: @%s\n",
13358 kind
, hex_string (signature
),
13359 host_address_to_string (dwo_cutu
));
13367 /* No DWP file, look for the DWO file. */
13369 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
13370 dwo_name
, comp_dir
);
13371 if (*dwo_file_slot
== NULL
)
13373 /* Read in the file and build a table of the CUs/TUs it contains. */
13374 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
13376 /* NOTE: This will be NULL if unable to open the file. */
13377 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
13379 if (dwo_file
!= NULL
)
13381 struct dwo_unit
*dwo_cutu
= NULL
;
13383 if (is_debug_types
&& dwo_file
->tus
)
13385 struct dwo_unit find_dwo_cutu
;
13387 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13388 find_dwo_cutu
.signature
= signature
;
13390 = (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_cutu
);
13392 else if (!is_debug_types
&& dwo_file
->cus
)
13394 struct dwo_unit find_dwo_cutu
;
13396 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13397 find_dwo_cutu
.signature
= signature
;
13398 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
,
13402 if (dwo_cutu
!= NULL
)
13404 if (dwarf_read_debug
)
13406 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
13407 kind
, dwo_name
, hex_string (signature
),
13408 host_address_to_string (dwo_cutu
));
13415 /* We didn't find it. This could mean a dwo_id mismatch, or
13416 someone deleted the DWO/DWP file, or the search path isn't set up
13417 correctly to find the file. */
13419 if (dwarf_read_debug
)
13421 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
13422 kind
, dwo_name
, hex_string (signature
));
13425 /* This is a warning and not a complaint because it can be caused by
13426 pilot error (e.g., user accidentally deleting the DWO). */
13428 /* Print the name of the DWP file if we looked there, helps the user
13429 better diagnose the problem. */
13430 std::string dwp_text
;
13432 if (dwp_file
!= NULL
)
13433 dwp_text
= string_printf (" [in DWP file %s]",
13434 lbasename (dwp_file
->name
));
13436 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
13437 " [in module %s]"),
13438 kind
, dwo_name
, hex_string (signature
),
13440 this_unit
->is_debug_types
? "TU" : "CU",
13441 sect_offset_str (this_unit
->sect_off
), objfile_name (objfile
));
13446 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
13447 See lookup_dwo_cutu_unit for details. */
13449 static struct dwo_unit
*
13450 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
13451 const char *dwo_name
, const char *comp_dir
,
13452 ULONGEST signature
)
13454 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
13457 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
13458 See lookup_dwo_cutu_unit for details. */
13460 static struct dwo_unit
*
13461 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
13462 const char *dwo_name
, const char *comp_dir
)
13464 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
13467 /* Traversal function for queue_and_load_all_dwo_tus. */
13470 queue_and_load_dwo_tu (void **slot
, void *info
)
13472 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
13473 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
13474 ULONGEST signature
= dwo_unit
->signature
;
13475 struct signatured_type
*sig_type
=
13476 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
13478 if (sig_type
!= NULL
)
13480 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
13482 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
13483 a real dependency of PER_CU on SIG_TYPE. That is detected later
13484 while processing PER_CU. */
13485 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
13486 load_full_type_unit (sig_cu
);
13487 VEC_safe_push (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, sig_cu
);
13493 /* Queue all TUs contained in the DWO of PER_CU to be read in.
13494 The DWO may have the only definition of the type, though it may not be
13495 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
13496 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
13499 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
13501 struct dwo_unit
*dwo_unit
;
13502 struct dwo_file
*dwo_file
;
13504 gdb_assert (!per_cu
->is_debug_types
);
13505 gdb_assert (get_dwp_file (per_cu
->dwarf2_per_objfile
) == NULL
);
13506 gdb_assert (per_cu
->cu
!= NULL
);
13508 dwo_unit
= per_cu
->cu
->dwo_unit
;
13509 gdb_assert (dwo_unit
!= NULL
);
13511 dwo_file
= dwo_unit
->dwo_file
;
13512 if (dwo_file
->tus
!= NULL
)
13513 htab_traverse_noresize (dwo_file
->tus
, queue_and_load_dwo_tu
, per_cu
);
13516 /* Read in various DIEs. */
13518 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
13519 Inherit only the children of the DW_AT_abstract_origin DIE not being
13520 already referenced by DW_AT_abstract_origin from the children of the
13524 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
13526 struct die_info
*child_die
;
13527 sect_offset
*offsetp
;
13528 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
13529 struct die_info
*origin_die
;
13530 /* Iterator of the ORIGIN_DIE children. */
13531 struct die_info
*origin_child_die
;
13532 struct attribute
*attr
;
13533 struct dwarf2_cu
*origin_cu
;
13534 struct pending
**origin_previous_list_in_scope
;
13536 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13540 /* Note that following die references may follow to a die in a
13544 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
13546 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
13548 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
13549 origin_cu
->list_in_scope
= cu
->list_in_scope
;
13551 if (die
->tag
!= origin_die
->tag
13552 && !(die
->tag
== DW_TAG_inlined_subroutine
13553 && origin_die
->tag
== DW_TAG_subprogram
))
13554 complaint (_("DIE %s and its abstract origin %s have different tags"),
13555 sect_offset_str (die
->sect_off
),
13556 sect_offset_str (origin_die
->sect_off
));
13558 std::vector
<sect_offset
> offsets
;
13560 for (child_die
= die
->child
;
13561 child_die
&& child_die
->tag
;
13562 child_die
= sibling_die (child_die
))
13564 struct die_info
*child_origin_die
;
13565 struct dwarf2_cu
*child_origin_cu
;
13567 /* We are trying to process concrete instance entries:
13568 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
13569 it's not relevant to our analysis here. i.e. detecting DIEs that are
13570 present in the abstract instance but not referenced in the concrete
13572 if (child_die
->tag
== DW_TAG_call_site
13573 || child_die
->tag
== DW_TAG_GNU_call_site
)
13576 /* For each CHILD_DIE, find the corresponding child of
13577 ORIGIN_DIE. If there is more than one layer of
13578 DW_AT_abstract_origin, follow them all; there shouldn't be,
13579 but GCC versions at least through 4.4 generate this (GCC PR
13581 child_origin_die
= child_die
;
13582 child_origin_cu
= cu
;
13585 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
13589 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
13593 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
13594 counterpart may exist. */
13595 if (child_origin_die
!= child_die
)
13597 if (child_die
->tag
!= child_origin_die
->tag
13598 && !(child_die
->tag
== DW_TAG_inlined_subroutine
13599 && child_origin_die
->tag
== DW_TAG_subprogram
))
13600 complaint (_("Child DIE %s and its abstract origin %s have "
13602 sect_offset_str (child_die
->sect_off
),
13603 sect_offset_str (child_origin_die
->sect_off
));
13604 if (child_origin_die
->parent
!= origin_die
)
13605 complaint (_("Child DIE %s and its abstract origin %s have "
13606 "different parents"),
13607 sect_offset_str (child_die
->sect_off
),
13608 sect_offset_str (child_origin_die
->sect_off
));
13610 offsets
.push_back (child_origin_die
->sect_off
);
13613 std::sort (offsets
.begin (), offsets
.end ());
13614 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
13615 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
13616 if (offsetp
[-1] == *offsetp
)
13617 complaint (_("Multiple children of DIE %s refer "
13618 "to DIE %s as their abstract origin"),
13619 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
13621 offsetp
= offsets
.data ();
13622 origin_child_die
= origin_die
->child
;
13623 while (origin_child_die
&& origin_child_die
->tag
)
13625 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13626 while (offsetp
< offsets_end
13627 && *offsetp
< origin_child_die
->sect_off
)
13629 if (offsetp
>= offsets_end
13630 || *offsetp
> origin_child_die
->sect_off
)
13632 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13633 Check whether we're already processing ORIGIN_CHILD_DIE.
13634 This can happen with mutually referenced abstract_origins.
13636 if (!origin_child_die
->in_process
)
13637 process_die (origin_child_die
, origin_cu
);
13639 origin_child_die
= sibling_die (origin_child_die
);
13641 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13645 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13647 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13648 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13649 struct context_stack
*newobj
;
13652 struct die_info
*child_die
;
13653 struct attribute
*attr
, *call_line
, *call_file
;
13655 CORE_ADDR baseaddr
;
13656 struct block
*block
;
13657 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13658 std::vector
<struct symbol
*> template_args
;
13659 struct template_symbol
*templ_func
= NULL
;
13663 /* If we do not have call site information, we can't show the
13664 caller of this inlined function. That's too confusing, so
13665 only use the scope for local variables. */
13666 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13667 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13668 if (call_line
== NULL
|| call_file
== NULL
)
13670 read_lexical_block_scope (die
, cu
);
13675 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13677 name
= dwarf2_name (die
, cu
);
13679 /* Ignore functions with missing or empty names. These are actually
13680 illegal according to the DWARF standard. */
13683 complaint (_("missing name for subprogram DIE at %s"),
13684 sect_offset_str (die
->sect_off
));
13688 /* Ignore functions with missing or invalid low and high pc attributes. */
13689 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13690 <= PC_BOUNDS_INVALID
)
13692 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13693 if (!attr
|| !DW_UNSND (attr
))
13694 complaint (_("cannot get low and high bounds "
13695 "for subprogram DIE at %s"),
13696 sect_offset_str (die
->sect_off
));
13700 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13701 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13703 /* If we have any template arguments, then we must allocate a
13704 different sort of symbol. */
13705 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
13707 if (child_die
->tag
== DW_TAG_template_type_param
13708 || child_die
->tag
== DW_TAG_template_value_param
)
13710 templ_func
= allocate_template_symbol (objfile
);
13711 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13716 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13717 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13718 (struct symbol
*) templ_func
);
13720 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13721 set_objfile_main_name (objfile
, SYMBOL_LINKAGE_NAME (newobj
->name
),
13724 /* If there is a location expression for DW_AT_frame_base, record
13726 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13728 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13730 /* If there is a location for the static link, record it. */
13731 newobj
->static_link
= NULL
;
13732 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13735 newobj
->static_link
13736 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13737 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13738 dwarf2_per_cu_addr_type (cu
->per_cu
));
13741 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13743 if (die
->child
!= NULL
)
13745 child_die
= die
->child
;
13746 while (child_die
&& child_die
->tag
)
13748 if (child_die
->tag
== DW_TAG_template_type_param
13749 || child_die
->tag
== DW_TAG_template_value_param
)
13751 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13754 template_args
.push_back (arg
);
13757 process_die (child_die
, cu
);
13758 child_die
= sibling_die (child_die
);
13762 inherit_abstract_dies (die
, cu
);
13764 /* If we have a DW_AT_specification, we might need to import using
13765 directives from the context of the specification DIE. See the
13766 comment in determine_prefix. */
13767 if (cu
->language
== language_cplus
13768 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13770 struct dwarf2_cu
*spec_cu
= cu
;
13771 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13775 child_die
= spec_die
->child
;
13776 while (child_die
&& child_die
->tag
)
13778 if (child_die
->tag
== DW_TAG_imported_module
)
13779 process_die (child_die
, spec_cu
);
13780 child_die
= sibling_die (child_die
);
13783 /* In some cases, GCC generates specification DIEs that
13784 themselves contain DW_AT_specification attributes. */
13785 spec_die
= die_specification (spec_die
, &spec_cu
);
13789 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13790 /* Make a block for the local symbols within. */
13791 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13792 cstk
.static_link
, lowpc
, highpc
);
13794 /* For C++, set the block's scope. */
13795 if ((cu
->language
== language_cplus
13796 || cu
->language
== language_fortran
13797 || cu
->language
== language_d
13798 || cu
->language
== language_rust
)
13799 && cu
->processing_has_namespace_info
)
13800 block_set_scope (block
, determine_prefix (die
, cu
),
13801 &objfile
->objfile_obstack
);
13803 /* If we have address ranges, record them. */
13804 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13806 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13808 /* Attach template arguments to function. */
13809 if (!template_args
.empty ())
13811 gdb_assert (templ_func
!= NULL
);
13813 templ_func
->n_template_arguments
= template_args
.size ();
13814 templ_func
->template_arguments
13815 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13816 templ_func
->n_template_arguments
);
13817 memcpy (templ_func
->template_arguments
,
13818 template_args
.data (),
13819 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13821 /* Make sure that the symtab is set on the new symbols. Even
13822 though they don't appear in this symtab directly, other parts
13823 of gdb assume that symbols do, and this is reasonably
13825 for (symbol
*sym
: template_args
)
13826 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13829 /* In C++, we can have functions nested inside functions (e.g., when
13830 a function declares a class that has methods). This means that
13831 when we finish processing a function scope, we may need to go
13832 back to building a containing block's symbol lists. */
13833 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13834 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13836 /* If we've finished processing a top-level function, subsequent
13837 symbols go in the file symbol list. */
13838 if (cu
->get_builder ()->outermost_context_p ())
13839 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13842 /* Process all the DIES contained within a lexical block scope. Start
13843 a new scope, process the dies, and then close the scope. */
13846 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13848 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13849 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13850 CORE_ADDR lowpc
, highpc
;
13851 struct die_info
*child_die
;
13852 CORE_ADDR baseaddr
;
13854 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13856 /* Ignore blocks with missing or invalid low and high pc attributes. */
13857 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13858 as multiple lexical blocks? Handling children in a sane way would
13859 be nasty. Might be easier to properly extend generic blocks to
13860 describe ranges. */
13861 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13863 case PC_BOUNDS_NOT_PRESENT
:
13864 /* DW_TAG_lexical_block has no attributes, process its children as if
13865 there was no wrapping by that DW_TAG_lexical_block.
13866 GCC does no longer produces such DWARF since GCC r224161. */
13867 for (child_die
= die
->child
;
13868 child_die
!= NULL
&& child_die
->tag
;
13869 child_die
= sibling_die (child_die
))
13870 process_die (child_die
, cu
);
13872 case PC_BOUNDS_INVALID
:
13875 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13876 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13878 cu
->get_builder ()->push_context (0, lowpc
);
13879 if (die
->child
!= NULL
)
13881 child_die
= die
->child
;
13882 while (child_die
&& child_die
->tag
)
13884 process_die (child_die
, cu
);
13885 child_die
= sibling_die (child_die
);
13888 inherit_abstract_dies (die
, cu
);
13889 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13891 if (*cu
->get_builder ()->get_local_symbols () != NULL
13892 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13894 struct block
*block
13895 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13896 cstk
.start_addr
, highpc
);
13898 /* Note that recording ranges after traversing children, as we
13899 do here, means that recording a parent's ranges entails
13900 walking across all its children's ranges as they appear in
13901 the address map, which is quadratic behavior.
13903 It would be nicer to record the parent's ranges before
13904 traversing its children, simply overriding whatever you find
13905 there. But since we don't even decide whether to create a
13906 block until after we've traversed its children, that's hard
13908 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13910 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13911 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13914 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13917 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13919 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13920 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13921 CORE_ADDR pc
, baseaddr
;
13922 struct attribute
*attr
;
13923 struct call_site
*call_site
, call_site_local
;
13926 struct die_info
*child_die
;
13928 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13930 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13933 /* This was a pre-DWARF-5 GNU extension alias
13934 for DW_AT_call_return_pc. */
13935 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13939 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13940 "DIE %s [in module %s]"),
13941 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13944 pc
= attr_value_as_address (attr
) + baseaddr
;
13945 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13947 if (cu
->call_site_htab
== NULL
)
13948 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13949 NULL
, &objfile
->objfile_obstack
,
13950 hashtab_obstack_allocate
, NULL
);
13951 call_site_local
.pc
= pc
;
13952 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13955 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13956 "DIE %s [in module %s]"),
13957 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13958 objfile_name (objfile
));
13962 /* Count parameters at the caller. */
13965 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13966 child_die
= sibling_die (child_die
))
13968 if (child_die
->tag
!= DW_TAG_call_site_parameter
13969 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13971 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13972 "DW_TAG_call_site child DIE %s [in module %s]"),
13973 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13974 objfile_name (objfile
));
13982 = ((struct call_site
*)
13983 obstack_alloc (&objfile
->objfile_obstack
,
13984 sizeof (*call_site
)
13985 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13987 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13988 call_site
->pc
= pc
;
13990 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13991 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13993 struct die_info
*func_die
;
13995 /* Skip also over DW_TAG_inlined_subroutine. */
13996 for (func_die
= die
->parent
;
13997 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13998 && func_die
->tag
!= DW_TAG_subroutine_type
;
13999 func_die
= func_die
->parent
);
14001 /* DW_AT_call_all_calls is a superset
14002 of DW_AT_call_all_tail_calls. */
14004 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
14005 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
14006 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
14007 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
14009 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
14010 not complete. But keep CALL_SITE for look ups via call_site_htab,
14011 both the initial caller containing the real return address PC and
14012 the final callee containing the current PC of a chain of tail
14013 calls do not need to have the tail call list complete. But any
14014 function candidate for a virtual tail call frame searched via
14015 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
14016 determined unambiguously. */
14020 struct type
*func_type
= NULL
;
14023 func_type
= get_die_type (func_die
, cu
);
14024 if (func_type
!= NULL
)
14026 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
14028 /* Enlist this call site to the function. */
14029 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
14030 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
14033 complaint (_("Cannot find function owning DW_TAG_call_site "
14034 "DIE %s [in module %s]"),
14035 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14039 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
14041 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
14043 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
14046 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
14047 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
14049 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
14050 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
14051 /* Keep NULL DWARF_BLOCK. */;
14052 else if (attr_form_is_block (attr
))
14054 struct dwarf2_locexpr_baton
*dlbaton
;
14056 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
14057 dlbaton
->data
= DW_BLOCK (attr
)->data
;
14058 dlbaton
->size
= DW_BLOCK (attr
)->size
;
14059 dlbaton
->per_cu
= cu
->per_cu
;
14061 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
14063 else if (attr_form_is_ref (attr
))
14065 struct dwarf2_cu
*target_cu
= cu
;
14066 struct die_info
*target_die
;
14068 target_die
= follow_die_ref (die
, attr
, &target_cu
);
14069 gdb_assert (target_cu
->per_cu
->dwarf2_per_objfile
->objfile
== objfile
);
14070 if (die_is_declaration (target_die
, target_cu
))
14072 const char *target_physname
;
14074 /* Prefer the mangled name; otherwise compute the demangled one. */
14075 target_physname
= dw2_linkage_name (target_die
, target_cu
);
14076 if (target_physname
== NULL
)
14077 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
14078 if (target_physname
== NULL
)
14079 complaint (_("DW_AT_call_target target DIE has invalid "
14080 "physname, for referencing DIE %s [in module %s]"),
14081 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14083 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
14089 /* DW_AT_entry_pc should be preferred. */
14090 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
14091 <= PC_BOUNDS_INVALID
)
14092 complaint (_("DW_AT_call_target target DIE has invalid "
14093 "low pc, for referencing DIE %s [in module %s]"),
14094 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14097 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
14098 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
14103 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
14104 "block nor reference, for DIE %s [in module %s]"),
14105 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14107 call_site
->per_cu
= cu
->per_cu
;
14109 for (child_die
= die
->child
;
14110 child_die
&& child_die
->tag
;
14111 child_die
= sibling_die (child_die
))
14113 struct call_site_parameter
*parameter
;
14114 struct attribute
*loc
, *origin
;
14116 if (child_die
->tag
!= DW_TAG_call_site_parameter
14117 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
14119 /* Already printed the complaint above. */
14123 gdb_assert (call_site
->parameter_count
< nparams
);
14124 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
14126 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
14127 specifies DW_TAG_formal_parameter. Value of the data assumed for the
14128 register is contained in DW_AT_call_value. */
14130 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
14131 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
14132 if (origin
== NULL
)
14134 /* This was a pre-DWARF-5 GNU extension alias
14135 for DW_AT_call_parameter. */
14136 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
14138 if (loc
== NULL
&& origin
!= NULL
&& attr_form_is_ref (origin
))
14140 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
14142 sect_offset sect_off
14143 = (sect_offset
) dwarf2_get_ref_die_offset (origin
);
14144 if (!offset_in_cu_p (&cu
->header
, sect_off
))
14146 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
14147 binding can be done only inside one CU. Such referenced DIE
14148 therefore cannot be even moved to DW_TAG_partial_unit. */
14149 complaint (_("DW_AT_call_parameter offset is not in CU for "
14150 "DW_TAG_call_site child DIE %s [in module %s]"),
14151 sect_offset_str (child_die
->sect_off
),
14152 objfile_name (objfile
));
14155 parameter
->u
.param_cu_off
14156 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
14158 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
14160 complaint (_("No DW_FORM_block* DW_AT_location for "
14161 "DW_TAG_call_site child DIE %s [in module %s]"),
14162 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
14167 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
14168 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
14169 if (parameter
->u
.dwarf_reg
!= -1)
14170 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
14171 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
14172 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
14173 ¶meter
->u
.fb_offset
))
14174 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
14177 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
14178 "for DW_FORM_block* DW_AT_location is supported for "
14179 "DW_TAG_call_site child DIE %s "
14181 sect_offset_str (child_die
->sect_off
),
14182 objfile_name (objfile
));
14187 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
14189 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
14190 if (!attr_form_is_block (attr
))
14192 complaint (_("No DW_FORM_block* DW_AT_call_value for "
14193 "DW_TAG_call_site child DIE %s [in module %s]"),
14194 sect_offset_str (child_die
->sect_off
),
14195 objfile_name (objfile
));
14198 parameter
->value
= DW_BLOCK (attr
)->data
;
14199 parameter
->value_size
= DW_BLOCK (attr
)->size
;
14201 /* Parameters are not pre-cleared by memset above. */
14202 parameter
->data_value
= NULL
;
14203 parameter
->data_value_size
= 0;
14204 call_site
->parameter_count
++;
14206 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
14208 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
14211 if (!attr_form_is_block (attr
))
14212 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
14213 "DW_TAG_call_site child DIE %s [in module %s]"),
14214 sect_offset_str (child_die
->sect_off
),
14215 objfile_name (objfile
));
14218 parameter
->data_value
= DW_BLOCK (attr
)->data
;
14219 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
14225 /* Helper function for read_variable. If DIE represents a virtual
14226 table, then return the type of the concrete object that is
14227 associated with the virtual table. Otherwise, return NULL. */
14229 static struct type
*
14230 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14232 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
14236 /* Find the type DIE. */
14237 struct die_info
*type_die
= NULL
;
14238 struct dwarf2_cu
*type_cu
= cu
;
14240 if (attr_form_is_ref (attr
))
14241 type_die
= follow_die_ref (die
, attr
, &type_cu
);
14242 if (type_die
== NULL
)
14245 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
14247 return die_containing_type (type_die
, type_cu
);
14250 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
14253 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
14255 struct rust_vtable_symbol
*storage
= NULL
;
14257 if (cu
->language
== language_rust
)
14259 struct type
*containing_type
= rust_containing_type (die
, cu
);
14261 if (containing_type
!= NULL
)
14263 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14265 storage
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
14266 struct rust_vtable_symbol
);
14267 initialize_objfile_symbol (storage
);
14268 storage
->concrete_type
= containing_type
;
14269 storage
->subclass
= SYMBOL_RUST_VTABLE
;
14273 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
14274 struct attribute
*abstract_origin
14275 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
14276 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
14277 if (res
== NULL
&& loc
&& abstract_origin
)
14279 /* We have a variable without a name, but with a location and an abstract
14280 origin. This may be a concrete instance of an abstract variable
14281 referenced from an DW_OP_GNU_variable_value, so save it to find it back
14283 struct dwarf2_cu
*origin_cu
= cu
;
14284 struct die_info
*origin_die
14285 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
14286 dwarf2_per_objfile
*dpo
= cu
->per_cu
->dwarf2_per_objfile
;
14287 dpo
->abstract_to_concrete
[origin_die
->sect_off
].push_back (die
->sect_off
);
14291 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
14292 reading .debug_rnglists.
14293 Callback's type should be:
14294 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14295 Return true if the attributes are present and valid, otherwise,
14298 template <typename Callback
>
14300 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
14301 Callback
&&callback
)
14303 struct dwarf2_per_objfile
*dwarf2_per_objfile
14304 = cu
->per_cu
->dwarf2_per_objfile
;
14305 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14306 bfd
*obfd
= objfile
->obfd
;
14307 /* Base address selection entry. */
14310 const gdb_byte
*buffer
;
14311 CORE_ADDR baseaddr
;
14312 bool overflow
= false;
14314 found_base
= cu
->base_known
;
14315 base
= cu
->base_address
;
14317 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->rnglists
);
14318 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
14320 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14324 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
14326 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14330 /* Initialize it due to a false compiler warning. */
14331 CORE_ADDR range_beginning
= 0, range_end
= 0;
14332 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
14333 + dwarf2_per_objfile
->rnglists
.size
);
14334 unsigned int bytes_read
;
14336 if (buffer
== buf_end
)
14341 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
14344 case DW_RLE_end_of_list
:
14346 case DW_RLE_base_address
:
14347 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14352 base
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14354 buffer
+= bytes_read
;
14356 case DW_RLE_start_length
:
14357 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14362 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14363 buffer
+= bytes_read
;
14364 range_end
= (range_beginning
14365 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
14366 buffer
+= bytes_read
;
14367 if (buffer
> buf_end
)
14373 case DW_RLE_offset_pair
:
14374 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14375 buffer
+= bytes_read
;
14376 if (buffer
> buf_end
)
14381 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14382 buffer
+= bytes_read
;
14383 if (buffer
> buf_end
)
14389 case DW_RLE_start_end
:
14390 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
14395 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14396 buffer
+= bytes_read
;
14397 range_end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14398 buffer
+= bytes_read
;
14401 complaint (_("Invalid .debug_rnglists data (no base address)"));
14404 if (rlet
== DW_RLE_end_of_list
|| overflow
)
14406 if (rlet
== DW_RLE_base_address
)
14411 /* We have no valid base address for the ranges
14413 complaint (_("Invalid .debug_rnglists data (no base address)"));
14417 if (range_beginning
> range_end
)
14419 /* Inverted range entries are invalid. */
14420 complaint (_("Invalid .debug_rnglists data (inverted range)"));
14424 /* Empty range entries have no effect. */
14425 if (range_beginning
== range_end
)
14428 range_beginning
+= base
;
14431 /* A not-uncommon case of bad debug info.
14432 Don't pollute the addrmap with bad data. */
14433 if (range_beginning
+ baseaddr
== 0
14434 && !dwarf2_per_objfile
->has_section_at_zero
)
14436 complaint (_(".debug_rnglists entry has start address of zero"
14437 " [in module %s]"), objfile_name (objfile
));
14441 callback (range_beginning
, range_end
);
14446 complaint (_("Offset %d is not terminated "
14447 "for DW_AT_ranges attribute"),
14455 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
14456 Callback's type should be:
14457 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14458 Return 1 if the attributes are present and valid, otherwise, return 0. */
14460 template <typename Callback
>
14462 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
14463 Callback
&&callback
)
14465 struct dwarf2_per_objfile
*dwarf2_per_objfile
14466 = cu
->per_cu
->dwarf2_per_objfile
;
14467 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14468 struct comp_unit_head
*cu_header
= &cu
->header
;
14469 bfd
*obfd
= objfile
->obfd
;
14470 unsigned int addr_size
= cu_header
->addr_size
;
14471 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
14472 /* Base address selection entry. */
14475 unsigned int dummy
;
14476 const gdb_byte
*buffer
;
14477 CORE_ADDR baseaddr
;
14479 if (cu_header
->version
>= 5)
14480 return dwarf2_rnglists_process (offset
, cu
, callback
);
14482 found_base
= cu
->base_known
;
14483 base
= cu
->base_address
;
14485 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
14486 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
14488 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14492 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
14494 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14498 CORE_ADDR range_beginning
, range_end
;
14500 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
14501 buffer
+= addr_size
;
14502 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
14503 buffer
+= addr_size
;
14504 offset
+= 2 * addr_size
;
14506 /* An end of list marker is a pair of zero addresses. */
14507 if (range_beginning
== 0 && range_end
== 0)
14508 /* Found the end of list entry. */
14511 /* Each base address selection entry is a pair of 2 values.
14512 The first is the largest possible address, the second is
14513 the base address. Check for a base address here. */
14514 if ((range_beginning
& mask
) == mask
)
14516 /* If we found the largest possible address, then we already
14517 have the base address in range_end. */
14525 /* We have no valid base address for the ranges
14527 complaint (_("Invalid .debug_ranges data (no base address)"));
14531 if (range_beginning
> range_end
)
14533 /* Inverted range entries are invalid. */
14534 complaint (_("Invalid .debug_ranges data (inverted range)"));
14538 /* Empty range entries have no effect. */
14539 if (range_beginning
== range_end
)
14542 range_beginning
+= base
;
14545 /* A not-uncommon case of bad debug info.
14546 Don't pollute the addrmap with bad data. */
14547 if (range_beginning
+ baseaddr
== 0
14548 && !dwarf2_per_objfile
->has_section_at_zero
)
14550 complaint (_(".debug_ranges entry has start address of zero"
14551 " [in module %s]"), objfile_name (objfile
));
14555 callback (range_beginning
, range_end
);
14561 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
14562 Return 1 if the attributes are present and valid, otherwise, return 0.
14563 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
14566 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
14567 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
14568 struct partial_symtab
*ranges_pst
)
14570 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14571 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14572 const CORE_ADDR baseaddr
= ANOFFSET (objfile
->section_offsets
,
14573 SECT_OFF_TEXT (objfile
));
14576 CORE_ADDR high
= 0;
14579 retval
= dwarf2_ranges_process (offset
, cu
,
14580 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
14582 if (ranges_pst
!= NULL
)
14587 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14588 range_beginning
+ baseaddr
)
14590 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14591 range_end
+ baseaddr
)
14593 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
14594 lowpc
, highpc
- 1, ranges_pst
);
14597 /* FIXME: This is recording everything as a low-high
14598 segment of consecutive addresses. We should have a
14599 data structure for discontiguous block ranges
14603 low
= range_beginning
;
14609 if (range_beginning
< low
)
14610 low
= range_beginning
;
14611 if (range_end
> high
)
14619 /* If the first entry is an end-of-list marker, the range
14620 describes an empty scope, i.e. no instructions. */
14626 *high_return
= high
;
14630 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14631 definition for the return value. *LOWPC and *HIGHPC are set iff
14632 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14634 static enum pc_bounds_kind
14635 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14636 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14637 struct partial_symtab
*pst
)
14639 struct dwarf2_per_objfile
*dwarf2_per_objfile
14640 = cu
->per_cu
->dwarf2_per_objfile
;
14641 struct attribute
*attr
;
14642 struct attribute
*attr_high
;
14644 CORE_ADDR high
= 0;
14645 enum pc_bounds_kind ret
;
14647 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14650 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14653 low
= attr_value_as_address (attr
);
14654 high
= attr_value_as_address (attr_high
);
14655 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
14659 /* Found high w/o low attribute. */
14660 return PC_BOUNDS_INVALID
;
14662 /* Found consecutive range of addresses. */
14663 ret
= PC_BOUNDS_HIGH_LOW
;
14667 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14670 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
14671 We take advantage of the fact that DW_AT_ranges does not appear
14672 in DW_TAG_compile_unit of DWO files. */
14673 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14674 unsigned int ranges_offset
= (DW_UNSND (attr
)
14675 + (need_ranges_base
14679 /* Value of the DW_AT_ranges attribute is the offset in the
14680 .debug_ranges section. */
14681 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
14682 return PC_BOUNDS_INVALID
;
14683 /* Found discontinuous range of addresses. */
14684 ret
= PC_BOUNDS_RANGES
;
14687 return PC_BOUNDS_NOT_PRESENT
;
14690 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14692 return PC_BOUNDS_INVALID
;
14694 /* When using the GNU linker, .gnu.linkonce. sections are used to
14695 eliminate duplicate copies of functions and vtables and such.
14696 The linker will arbitrarily choose one and discard the others.
14697 The AT_*_pc values for such functions refer to local labels in
14698 these sections. If the section from that file was discarded, the
14699 labels are not in the output, so the relocs get a value of 0.
14700 If this is a discarded function, mark the pc bounds as invalid,
14701 so that GDB will ignore it. */
14702 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
14703 return PC_BOUNDS_INVALID
;
14711 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14712 its low and high PC addresses. Do nothing if these addresses could not
14713 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14714 and HIGHPC to the high address if greater than HIGHPC. */
14717 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14718 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14719 struct dwarf2_cu
*cu
)
14721 CORE_ADDR low
, high
;
14722 struct die_info
*child
= die
->child
;
14724 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14726 *lowpc
= std::min (*lowpc
, low
);
14727 *highpc
= std::max (*highpc
, high
);
14730 /* If the language does not allow nested subprograms (either inside
14731 subprograms or lexical blocks), we're done. */
14732 if (cu
->language
!= language_ada
)
14735 /* Check all the children of the given DIE. If it contains nested
14736 subprograms, then check their pc bounds. Likewise, we need to
14737 check lexical blocks as well, as they may also contain subprogram
14739 while (child
&& child
->tag
)
14741 if (child
->tag
== DW_TAG_subprogram
14742 || child
->tag
== DW_TAG_lexical_block
)
14743 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14744 child
= sibling_die (child
);
14748 /* Get the low and high pc's represented by the scope DIE, and store
14749 them in *LOWPC and *HIGHPC. If the correct values can't be
14750 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14753 get_scope_pc_bounds (struct die_info
*die
,
14754 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14755 struct dwarf2_cu
*cu
)
14757 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14758 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14759 CORE_ADDR current_low
, current_high
;
14761 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14762 >= PC_BOUNDS_RANGES
)
14764 best_low
= current_low
;
14765 best_high
= current_high
;
14769 struct die_info
*child
= die
->child
;
14771 while (child
&& child
->tag
)
14773 switch (child
->tag
) {
14774 case DW_TAG_subprogram
:
14775 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14777 case DW_TAG_namespace
:
14778 case DW_TAG_module
:
14779 /* FIXME: carlton/2004-01-16: Should we do this for
14780 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14781 that current GCC's always emit the DIEs corresponding
14782 to definitions of methods of classes as children of a
14783 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14784 the DIEs giving the declarations, which could be
14785 anywhere). But I don't see any reason why the
14786 standards says that they have to be there. */
14787 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14789 if (current_low
!= ((CORE_ADDR
) -1))
14791 best_low
= std::min (best_low
, current_low
);
14792 best_high
= std::max (best_high
, current_high
);
14800 child
= sibling_die (child
);
14805 *highpc
= best_high
;
14808 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14812 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14813 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14815 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14816 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14817 struct attribute
*attr
;
14818 struct attribute
*attr_high
;
14820 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14823 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14826 CORE_ADDR low
= attr_value_as_address (attr
);
14827 CORE_ADDR high
= attr_value_as_address (attr_high
);
14829 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
14832 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14833 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14834 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14838 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14841 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
14842 We take advantage of the fact that DW_AT_ranges does not appear
14843 in DW_TAG_compile_unit of DWO files. */
14844 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14846 /* The value of the DW_AT_ranges attribute is the offset of the
14847 address range list in the .debug_ranges section. */
14848 unsigned long offset
= (DW_UNSND (attr
)
14849 + (need_ranges_base
? cu
->ranges_base
: 0));
14851 std::vector
<blockrange
> blockvec
;
14852 dwarf2_ranges_process (offset
, cu
,
14853 [&] (CORE_ADDR start
, CORE_ADDR end
)
14857 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14858 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14859 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14860 blockvec
.emplace_back (start
, end
);
14863 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14867 /* Check whether the producer field indicates either of GCC < 4.6, or the
14868 Intel C/C++ compiler, and cache the result in CU. */
14871 check_producer (struct dwarf2_cu
*cu
)
14875 if (cu
->producer
== NULL
)
14877 /* For unknown compilers expect their behavior is DWARF version
14880 GCC started to support .debug_types sections by -gdwarf-4 since
14881 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14882 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14883 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14884 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14886 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14888 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14889 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14891 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14893 cu
->producer_is_icc
= true;
14894 cu
->producer_is_icc_lt_14
= major
< 14;
14896 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14897 cu
->producer_is_codewarrior
= true;
14900 /* For other non-GCC compilers, expect their behavior is DWARF version
14904 cu
->checked_producer
= true;
14907 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14908 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14909 during 4.6.0 experimental. */
14912 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14914 if (!cu
->checked_producer
)
14915 check_producer (cu
);
14917 return cu
->producer_is_gxx_lt_4_6
;
14921 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14922 with incorrect is_stmt attributes. */
14925 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14927 if (!cu
->checked_producer
)
14928 check_producer (cu
);
14930 return cu
->producer_is_codewarrior
;
14933 /* Return the default accessibility type if it is not overriden by
14934 DW_AT_accessibility. */
14936 static enum dwarf_access_attribute
14937 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14939 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14941 /* The default DWARF 2 accessibility for members is public, the default
14942 accessibility for inheritance is private. */
14944 if (die
->tag
!= DW_TAG_inheritance
)
14945 return DW_ACCESS_public
;
14947 return DW_ACCESS_private
;
14951 /* DWARF 3+ defines the default accessibility a different way. The same
14952 rules apply now for DW_TAG_inheritance as for the members and it only
14953 depends on the container kind. */
14955 if (die
->parent
->tag
== DW_TAG_class_type
)
14956 return DW_ACCESS_private
;
14958 return DW_ACCESS_public
;
14962 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14963 offset. If the attribute was not found return 0, otherwise return
14964 1. If it was found but could not properly be handled, set *OFFSET
14968 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14971 struct attribute
*attr
;
14973 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14978 /* Note that we do not check for a section offset first here.
14979 This is because DW_AT_data_member_location is new in DWARF 4,
14980 so if we see it, we can assume that a constant form is really
14981 a constant and not a section offset. */
14982 if (attr_form_is_constant (attr
))
14983 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
14984 else if (attr_form_is_section_offset (attr
))
14985 dwarf2_complex_location_expr_complaint ();
14986 else if (attr_form_is_block (attr
))
14987 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14989 dwarf2_complex_location_expr_complaint ();
14997 /* Add an aggregate field to the field list. */
15000 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
15001 struct dwarf2_cu
*cu
)
15003 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15004 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15005 struct nextfield
*new_field
;
15006 struct attribute
*attr
;
15008 const char *fieldname
= "";
15010 if (die
->tag
== DW_TAG_inheritance
)
15012 fip
->baseclasses
.emplace_back ();
15013 new_field
= &fip
->baseclasses
.back ();
15017 fip
->fields
.emplace_back ();
15018 new_field
= &fip
->fields
.back ();
15023 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15025 new_field
->accessibility
= DW_UNSND (attr
);
15027 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
15028 if (new_field
->accessibility
!= DW_ACCESS_public
)
15029 fip
->non_public_fields
= 1;
15031 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15033 new_field
->virtuality
= DW_UNSND (attr
);
15035 new_field
->virtuality
= DW_VIRTUALITY_none
;
15037 fp
= &new_field
->field
;
15039 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
15043 /* Data member other than a C++ static data member. */
15045 /* Get type of field. */
15046 fp
->type
= die_type (die
, cu
);
15048 SET_FIELD_BITPOS (*fp
, 0);
15050 /* Get bit size of field (zero if none). */
15051 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
15054 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
15058 FIELD_BITSIZE (*fp
) = 0;
15061 /* Get bit offset of field. */
15062 if (handle_data_member_location (die
, cu
, &offset
))
15063 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
15064 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
15067 if (gdbarch_bits_big_endian (gdbarch
))
15069 /* For big endian bits, the DW_AT_bit_offset gives the
15070 additional bit offset from the MSB of the containing
15071 anonymous object to the MSB of the field. We don't
15072 have to do anything special since we don't need to
15073 know the size of the anonymous object. */
15074 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
15078 /* For little endian bits, compute the bit offset to the
15079 MSB of the anonymous object, subtract off the number of
15080 bits from the MSB of the field to the MSB of the
15081 object, and then subtract off the number of bits of
15082 the field itself. The result is the bit offset of
15083 the LSB of the field. */
15084 int anonymous_size
;
15085 int bit_offset
= DW_UNSND (attr
);
15087 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15090 /* The size of the anonymous object containing
15091 the bit field is explicit, so use the
15092 indicated size (in bytes). */
15093 anonymous_size
= DW_UNSND (attr
);
15097 /* The size of the anonymous object containing
15098 the bit field must be inferred from the type
15099 attribute of the data member containing the
15101 anonymous_size
= TYPE_LENGTH (fp
->type
);
15103 SET_FIELD_BITPOS (*fp
,
15104 (FIELD_BITPOS (*fp
)
15105 + anonymous_size
* bits_per_byte
15106 - bit_offset
- FIELD_BITSIZE (*fp
)));
15109 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
15111 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
15112 + dwarf2_get_attr_constant_value (attr
, 0)));
15114 /* Get name of field. */
15115 fieldname
= dwarf2_name (die
, cu
);
15116 if (fieldname
== NULL
)
15119 /* The name is already allocated along with this objfile, so we don't
15120 need to duplicate it for the type. */
15121 fp
->name
= fieldname
;
15123 /* Change accessibility for artificial fields (e.g. virtual table
15124 pointer or virtual base class pointer) to private. */
15125 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
15127 FIELD_ARTIFICIAL (*fp
) = 1;
15128 new_field
->accessibility
= DW_ACCESS_private
;
15129 fip
->non_public_fields
= 1;
15132 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
15134 /* C++ static member. */
15136 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
15137 is a declaration, but all versions of G++ as of this writing
15138 (so through at least 3.2.1) incorrectly generate
15139 DW_TAG_variable tags. */
15141 const char *physname
;
15143 /* Get name of field. */
15144 fieldname
= dwarf2_name (die
, cu
);
15145 if (fieldname
== NULL
)
15148 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15150 /* Only create a symbol if this is an external value.
15151 new_symbol checks this and puts the value in the global symbol
15152 table, which we want. If it is not external, new_symbol
15153 will try to put the value in cu->list_in_scope which is wrong. */
15154 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
15156 /* A static const member, not much different than an enum as far as
15157 we're concerned, except that we can support more types. */
15158 new_symbol (die
, NULL
, cu
);
15161 /* Get physical name. */
15162 physname
= dwarf2_physname (fieldname
, die
, cu
);
15164 /* The name is already allocated along with this objfile, so we don't
15165 need to duplicate it for the type. */
15166 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
15167 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15168 FIELD_NAME (*fp
) = fieldname
;
15170 else if (die
->tag
== DW_TAG_inheritance
)
15174 /* C++ base class field. */
15175 if (handle_data_member_location (die
, cu
, &offset
))
15176 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
15177 FIELD_BITSIZE (*fp
) = 0;
15178 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15179 FIELD_NAME (*fp
) = TYPE_NAME (fp
->type
);
15181 else if (die
->tag
== DW_TAG_variant_part
)
15183 /* process_structure_scope will treat this DIE as a union. */
15184 process_structure_scope (die
, cu
);
15186 /* The variant part is relative to the start of the enclosing
15188 SET_FIELD_BITPOS (*fp
, 0);
15189 fp
->type
= get_die_type (die
, cu
);
15190 fp
->artificial
= 1;
15191 fp
->name
= "<<variant>>";
15193 /* Normally a DW_TAG_variant_part won't have a size, but our
15194 representation requires one, so set it to the maximum of the
15196 if (TYPE_LENGTH (fp
->type
) == 0)
15199 for (int i
= 0; i
< TYPE_NFIELDS (fp
->type
); ++i
)
15200 if (TYPE_LENGTH (TYPE_FIELD_TYPE (fp
->type
, i
)) > max
)
15201 max
= TYPE_LENGTH (TYPE_FIELD_TYPE (fp
->type
, i
));
15202 TYPE_LENGTH (fp
->type
) = max
;
15206 gdb_assert_not_reached ("missing case in dwarf2_add_field");
15209 /* Can the type given by DIE define another type? */
15212 type_can_define_types (const struct die_info
*die
)
15216 case DW_TAG_typedef
:
15217 case DW_TAG_class_type
:
15218 case DW_TAG_structure_type
:
15219 case DW_TAG_union_type
:
15220 case DW_TAG_enumeration_type
:
15228 /* Add a type definition defined in the scope of the FIP's class. */
15231 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
15232 struct dwarf2_cu
*cu
)
15234 struct decl_field fp
;
15235 memset (&fp
, 0, sizeof (fp
));
15237 gdb_assert (type_can_define_types (die
));
15239 /* Get name of field. NULL is okay here, meaning an anonymous type. */
15240 fp
.name
= dwarf2_name (die
, cu
);
15241 fp
.type
= read_type_die (die
, cu
);
15243 /* Save accessibility. */
15244 enum dwarf_access_attribute accessibility
;
15245 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15247 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15249 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15250 switch (accessibility
)
15252 case DW_ACCESS_public
:
15253 /* The assumed value if neither private nor protected. */
15255 case DW_ACCESS_private
:
15258 case DW_ACCESS_protected
:
15259 fp
.is_protected
= 1;
15262 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
15265 if (die
->tag
== DW_TAG_typedef
)
15266 fip
->typedef_field_list
.push_back (fp
);
15268 fip
->nested_types_list
.push_back (fp
);
15271 /* Create the vector of fields, and attach it to the type. */
15274 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
15275 struct dwarf2_cu
*cu
)
15277 int nfields
= fip
->nfields
;
15279 /* Record the field count, allocate space for the array of fields,
15280 and create blank accessibility bitfields if necessary. */
15281 TYPE_NFIELDS (type
) = nfields
;
15282 TYPE_FIELDS (type
) = (struct field
*)
15283 TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
);
15285 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
15287 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15289 TYPE_FIELD_PRIVATE_BITS (type
) =
15290 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15291 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
15293 TYPE_FIELD_PROTECTED_BITS (type
) =
15294 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15295 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
15297 TYPE_FIELD_IGNORE_BITS (type
) =
15298 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15299 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
15302 /* If the type has baseclasses, allocate and clear a bit vector for
15303 TYPE_FIELD_VIRTUAL_BITS. */
15304 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
15306 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
15307 unsigned char *pointer
;
15309 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15310 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
15311 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
15312 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
15313 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
15316 if (TYPE_FLAG_DISCRIMINATED_UNION (type
))
15318 struct discriminant_info
*di
= alloc_discriminant_info (type
, -1, -1);
15320 for (int index
= 0; index
< nfields
; ++index
)
15322 struct nextfield
&field
= fip
->fields
[index
];
15324 if (field
.variant
.is_discriminant
)
15325 di
->discriminant_index
= index
;
15326 else if (field
.variant
.default_branch
)
15327 di
->default_index
= index
;
15329 di
->discriminants
[index
] = field
.variant
.discriminant_value
;
15333 /* Copy the saved-up fields into the field vector. */
15334 for (int i
= 0; i
< nfields
; ++i
)
15336 struct nextfield
&field
15337 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
15338 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
15340 TYPE_FIELD (type
, i
) = field
.field
;
15341 switch (field
.accessibility
)
15343 case DW_ACCESS_private
:
15344 if (cu
->language
!= language_ada
)
15345 SET_TYPE_FIELD_PRIVATE (type
, i
);
15348 case DW_ACCESS_protected
:
15349 if (cu
->language
!= language_ada
)
15350 SET_TYPE_FIELD_PROTECTED (type
, i
);
15353 case DW_ACCESS_public
:
15357 /* Unknown accessibility. Complain and treat it as public. */
15359 complaint (_("unsupported accessibility %d"),
15360 field
.accessibility
);
15364 if (i
< fip
->baseclasses
.size ())
15366 switch (field
.virtuality
)
15368 case DW_VIRTUALITY_virtual
:
15369 case DW_VIRTUALITY_pure_virtual
:
15370 if (cu
->language
== language_ada
)
15371 error (_("unexpected virtuality in component of Ada type"));
15372 SET_TYPE_FIELD_VIRTUAL (type
, i
);
15379 /* Return true if this member function is a constructor, false
15383 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15385 const char *fieldname
;
15386 const char *type_name
;
15389 if (die
->parent
== NULL
)
15392 if (die
->parent
->tag
!= DW_TAG_structure_type
15393 && die
->parent
->tag
!= DW_TAG_union_type
15394 && die
->parent
->tag
!= DW_TAG_class_type
)
15397 fieldname
= dwarf2_name (die
, cu
);
15398 type_name
= dwarf2_name (die
->parent
, cu
);
15399 if (fieldname
== NULL
|| type_name
== NULL
)
15402 len
= strlen (fieldname
);
15403 return (strncmp (fieldname
, type_name
, len
) == 0
15404 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15407 /* Add a member function to the proper fieldlist. */
15410 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15411 struct type
*type
, struct dwarf2_cu
*cu
)
15413 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15414 struct attribute
*attr
;
15416 struct fnfieldlist
*flp
= nullptr;
15417 struct fn_field
*fnp
;
15418 const char *fieldname
;
15419 struct type
*this_type
;
15420 enum dwarf_access_attribute accessibility
;
15422 if (cu
->language
== language_ada
)
15423 error (_("unexpected member function in Ada type"));
15425 /* Get name of member function. */
15426 fieldname
= dwarf2_name (die
, cu
);
15427 if (fieldname
== NULL
)
15430 /* Look up member function name in fieldlist. */
15431 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15433 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15435 flp
= &fip
->fnfieldlists
[i
];
15440 /* Create a new fnfieldlist if necessary. */
15441 if (flp
== nullptr)
15443 fip
->fnfieldlists
.emplace_back ();
15444 flp
= &fip
->fnfieldlists
.back ();
15445 flp
->name
= fieldname
;
15446 i
= fip
->fnfieldlists
.size () - 1;
15449 /* Create a new member function field and add it to the vector of
15451 flp
->fnfields
.emplace_back ();
15452 fnp
= &flp
->fnfields
.back ();
15454 /* Delay processing of the physname until later. */
15455 if (cu
->language
== language_cplus
)
15456 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15460 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15461 fnp
->physname
= physname
? physname
: "";
15464 fnp
->type
= alloc_type (objfile
);
15465 this_type
= read_type_die (die
, cu
);
15466 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
15468 int nparams
= TYPE_NFIELDS (this_type
);
15470 /* TYPE is the domain of this method, and THIS_TYPE is the type
15471 of the method itself (TYPE_CODE_METHOD). */
15472 smash_to_method_type (fnp
->type
, type
,
15473 TYPE_TARGET_TYPE (this_type
),
15474 TYPE_FIELDS (this_type
),
15475 TYPE_NFIELDS (this_type
),
15476 TYPE_VARARGS (this_type
));
15478 /* Handle static member functions.
15479 Dwarf2 has no clean way to discern C++ static and non-static
15480 member functions. G++ helps GDB by marking the first
15481 parameter for non-static member functions (which is the this
15482 pointer) as artificial. We obtain this information from
15483 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15484 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15485 fnp
->voffset
= VOFFSET_STATIC
;
15488 complaint (_("member function type missing for '%s'"),
15489 dwarf2_full_name (fieldname
, die
, cu
));
15491 /* Get fcontext from DW_AT_containing_type if present. */
15492 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15493 fnp
->fcontext
= die_containing_type (die
, cu
);
15495 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15496 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15498 /* Get accessibility. */
15499 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15501 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15503 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15504 switch (accessibility
)
15506 case DW_ACCESS_private
:
15507 fnp
->is_private
= 1;
15509 case DW_ACCESS_protected
:
15510 fnp
->is_protected
= 1;
15514 /* Check for artificial methods. */
15515 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15516 if (attr
&& DW_UNSND (attr
) != 0)
15517 fnp
->is_artificial
= 1;
15519 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15521 /* Get index in virtual function table if it is a virtual member
15522 function. For older versions of GCC, this is an offset in the
15523 appropriate virtual table, as specified by DW_AT_containing_type.
15524 For everyone else, it is an expression to be evaluated relative
15525 to the object address. */
15527 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15530 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
15532 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
15534 /* Old-style GCC. */
15535 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
15537 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
15538 || (DW_BLOCK (attr
)->size
> 1
15539 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
15540 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
15542 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15543 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15544 dwarf2_complex_location_expr_complaint ();
15546 fnp
->voffset
/= cu
->header
.addr_size
;
15550 dwarf2_complex_location_expr_complaint ();
15552 if (!fnp
->fcontext
)
15554 /* If there is no `this' field and no DW_AT_containing_type,
15555 we cannot actually find a base class context for the
15557 if (TYPE_NFIELDS (this_type
) == 0
15558 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15560 complaint (_("cannot determine context for virtual member "
15561 "function \"%s\" (offset %s)"),
15562 fieldname
, sect_offset_str (die
->sect_off
));
15567 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
15571 else if (attr_form_is_section_offset (attr
))
15573 dwarf2_complex_location_expr_complaint ();
15577 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15583 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15584 if (attr
&& DW_UNSND (attr
))
15586 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15587 complaint (_("Member function \"%s\" (offset %s) is virtual "
15588 "but the vtable offset is not specified"),
15589 fieldname
, sect_offset_str (die
->sect_off
));
15590 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15591 TYPE_CPLUS_DYNAMIC (type
) = 1;
15596 /* Create the vector of member function fields, and attach it to the type. */
15599 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15600 struct dwarf2_cu
*cu
)
15602 if (cu
->language
== language_ada
)
15603 error (_("unexpected member functions in Ada type"));
15605 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15606 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15608 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15610 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15612 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15613 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15615 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15616 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15617 fn_flp
->fn_fields
= (struct fn_field
*)
15618 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15620 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15621 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15624 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15627 /* Returns non-zero if NAME is the name of a vtable member in CU's
15628 language, zero otherwise. */
15630 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15632 static const char vptr
[] = "_vptr";
15634 /* Look for the C++ form of the vtable. */
15635 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15641 /* GCC outputs unnamed structures that are really pointers to member
15642 functions, with the ABI-specified layout. If TYPE describes
15643 such a structure, smash it into a member function type.
15645 GCC shouldn't do this; it should just output pointer to member DIEs.
15646 This is GCC PR debug/28767. */
15649 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15651 struct type
*pfn_type
, *self_type
, *new_type
;
15653 /* Check for a structure with no name and two children. */
15654 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
15657 /* Check for __pfn and __delta members. */
15658 if (TYPE_FIELD_NAME (type
, 0) == NULL
15659 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15660 || TYPE_FIELD_NAME (type
, 1) == NULL
15661 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15664 /* Find the type of the method. */
15665 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
15666 if (pfn_type
== NULL
15667 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
15668 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
15671 /* Look for the "this" argument. */
15672 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15673 if (TYPE_NFIELDS (pfn_type
) == 0
15674 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
15675 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
15678 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
15679 new_type
= alloc_type (objfile
);
15680 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15681 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
15682 TYPE_VARARGS (pfn_type
));
15683 smash_to_methodptr_type (type
, new_type
);
15686 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15687 appropriate error checking and issuing complaints if there is a
15691 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15693 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15695 if (attr
== nullptr)
15698 if (!attr_form_is_constant (attr
))
15700 complaint (_("DW_AT_alignment must have constant form"
15701 " - DIE at %s [in module %s]"),
15702 sect_offset_str (die
->sect_off
),
15703 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15708 if (attr
->form
== DW_FORM_sdata
)
15710 LONGEST val
= DW_SND (attr
);
15713 complaint (_("DW_AT_alignment value must not be negative"
15714 " - DIE at %s [in module %s]"),
15715 sect_offset_str (die
->sect_off
),
15716 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15722 align
= DW_UNSND (attr
);
15726 complaint (_("DW_AT_alignment value must not be zero"
15727 " - DIE at %s [in module %s]"),
15728 sect_offset_str (die
->sect_off
),
15729 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15732 if ((align
& (align
- 1)) != 0)
15734 complaint (_("DW_AT_alignment value must be a power of 2"
15735 " - DIE at %s [in module %s]"),
15736 sect_offset_str (die
->sect_off
),
15737 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15744 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15745 the alignment for TYPE. */
15748 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15751 if (!set_type_align (type
, get_alignment (cu
, die
)))
15752 complaint (_("DW_AT_alignment value too large"
15753 " - DIE at %s [in module %s]"),
15754 sect_offset_str (die
->sect_off
),
15755 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15758 /* Called when we find the DIE that starts a structure or union scope
15759 (definition) to create a type for the structure or union. Fill in
15760 the type's name and general properties; the members will not be
15761 processed until process_structure_scope. A symbol table entry for
15762 the type will also not be done until process_structure_scope (assuming
15763 the type has a name).
15765 NOTE: we need to call these functions regardless of whether or not the
15766 DIE has a DW_AT_name attribute, since it might be an anonymous
15767 structure or union. This gets the type entered into our set of
15768 user defined types. */
15770 static struct type
*
15771 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15773 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15775 struct attribute
*attr
;
15778 /* If the definition of this type lives in .debug_types, read that type.
15779 Don't follow DW_AT_specification though, that will take us back up
15780 the chain and we want to go down. */
15781 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
15784 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15786 /* The type's CU may not be the same as CU.
15787 Ensure TYPE is recorded with CU in die_type_hash. */
15788 return set_die_type (die
, type
, cu
);
15791 type
= alloc_type (objfile
);
15792 INIT_CPLUS_SPECIFIC (type
);
15794 name
= dwarf2_name (die
, cu
);
15797 if (cu
->language
== language_cplus
15798 || cu
->language
== language_d
15799 || cu
->language
== language_rust
)
15801 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15803 /* dwarf2_full_name might have already finished building the DIE's
15804 type. If so, there is no need to continue. */
15805 if (get_die_type (die
, cu
) != NULL
)
15806 return get_die_type (die
, cu
);
15808 TYPE_NAME (type
) = full_name
;
15812 /* The name is already allocated along with this objfile, so
15813 we don't need to duplicate it for the type. */
15814 TYPE_NAME (type
) = name
;
15818 if (die
->tag
== DW_TAG_structure_type
)
15820 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15822 else if (die
->tag
== DW_TAG_union_type
)
15824 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15826 else if (die
->tag
== DW_TAG_variant_part
)
15828 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15829 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
15833 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15836 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15837 TYPE_DECLARED_CLASS (type
) = 1;
15839 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15842 if (attr_form_is_constant (attr
))
15843 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15846 /* For the moment, dynamic type sizes are not supported
15847 by GDB's struct type. The actual size is determined
15848 on-demand when resolving the type of a given object,
15849 so set the type's length to zero for now. Otherwise,
15850 we record an expression as the length, and that expression
15851 could lead to a very large value, which could eventually
15852 lead to us trying to allocate that much memory when creating
15853 a value of that type. */
15854 TYPE_LENGTH (type
) = 0;
15859 TYPE_LENGTH (type
) = 0;
15862 maybe_set_alignment (cu
, die
, type
);
15864 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15866 /* ICC<14 does not output the required DW_AT_declaration on
15867 incomplete types, but gives them a size of zero. */
15868 TYPE_STUB (type
) = 1;
15871 TYPE_STUB_SUPPORTED (type
) = 1;
15873 if (die_is_declaration (die
, cu
))
15874 TYPE_STUB (type
) = 1;
15875 else if (attr
== NULL
&& die
->child
== NULL
15876 && producer_is_realview (cu
->producer
))
15877 /* RealView does not output the required DW_AT_declaration
15878 on incomplete types. */
15879 TYPE_STUB (type
) = 1;
15881 /* We need to add the type field to the die immediately so we don't
15882 infinitely recurse when dealing with pointers to the structure
15883 type within the structure itself. */
15884 set_die_type (die
, type
, cu
);
15886 /* set_die_type should be already done. */
15887 set_descriptive_type (type
, die
, cu
);
15892 /* A helper for process_structure_scope that handles a single member
15896 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15897 struct field_info
*fi
,
15898 std::vector
<struct symbol
*> *template_args
,
15899 struct dwarf2_cu
*cu
)
15901 if (child_die
->tag
== DW_TAG_member
15902 || child_die
->tag
== DW_TAG_variable
15903 || child_die
->tag
== DW_TAG_variant_part
)
15905 /* NOTE: carlton/2002-11-05: A C++ static data member
15906 should be a DW_TAG_member that is a declaration, but
15907 all versions of G++ as of this writing (so through at
15908 least 3.2.1) incorrectly generate DW_TAG_variable
15909 tags for them instead. */
15910 dwarf2_add_field (fi
, child_die
, cu
);
15912 else if (child_die
->tag
== DW_TAG_subprogram
)
15914 /* Rust doesn't have member functions in the C++ sense.
15915 However, it does emit ordinary functions as children
15916 of a struct DIE. */
15917 if (cu
->language
== language_rust
)
15918 read_func_scope (child_die
, cu
);
15921 /* C++ member function. */
15922 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15925 else if (child_die
->tag
== DW_TAG_inheritance
)
15927 /* C++ base class field. */
15928 dwarf2_add_field (fi
, child_die
, cu
);
15930 else if (type_can_define_types (child_die
))
15931 dwarf2_add_type_defn (fi
, child_die
, cu
);
15932 else if (child_die
->tag
== DW_TAG_template_type_param
15933 || child_die
->tag
== DW_TAG_template_value_param
)
15935 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15938 template_args
->push_back (arg
);
15940 else if (child_die
->tag
== DW_TAG_variant
)
15942 /* In a variant we want to get the discriminant and also add a
15943 field for our sole member child. */
15944 struct attribute
*discr
= dwarf2_attr (child_die
, DW_AT_discr_value
, cu
);
15946 for (die_info
*variant_child
= child_die
->child
;
15947 variant_child
!= NULL
;
15948 variant_child
= sibling_die (variant_child
))
15950 if (variant_child
->tag
== DW_TAG_member
)
15952 handle_struct_member_die (variant_child
, type
, fi
,
15953 template_args
, cu
);
15954 /* Only handle the one. */
15959 /* We don't handle this but we might as well report it if we see
15961 if (dwarf2_attr (child_die
, DW_AT_discr_list
, cu
) != nullptr)
15962 complaint (_("DW_AT_discr_list is not supported yet"
15963 " - DIE at %s [in module %s]"),
15964 sect_offset_str (child_die
->sect_off
),
15965 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15967 /* The first field was just added, so we can stash the
15968 discriminant there. */
15969 gdb_assert (!fi
->fields
.empty ());
15971 fi
->fields
.back ().variant
.default_branch
= true;
15973 fi
->fields
.back ().variant
.discriminant_value
= DW_UNSND (discr
);
15977 /* Finish creating a structure or union type, including filling in
15978 its members and creating a symbol for it. */
15981 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15983 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15984 struct die_info
*child_die
;
15987 type
= get_die_type (die
, cu
);
15989 type
= read_structure_type (die
, cu
);
15991 /* When reading a DW_TAG_variant_part, we need to notice when we
15992 read the discriminant member, so we can record it later in the
15993 discriminant_info. */
15994 bool is_variant_part
= TYPE_FLAG_DISCRIMINATED_UNION (type
);
15995 sect_offset discr_offset
;
15996 bool has_template_parameters
= false;
15998 if (is_variant_part
)
16000 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
16003 /* Maybe it's a univariant form, an extension we support.
16004 In this case arrange not to check the offset. */
16005 is_variant_part
= false;
16007 else if (attr_form_is_ref (discr
))
16009 struct dwarf2_cu
*target_cu
= cu
;
16010 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
16012 discr_offset
= target_die
->sect_off
;
16016 complaint (_("DW_AT_discr does not have DIE reference form"
16017 " - DIE at %s [in module %s]"),
16018 sect_offset_str (die
->sect_off
),
16019 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16020 is_variant_part
= false;
16024 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
16026 struct field_info fi
;
16027 std::vector
<struct symbol
*> template_args
;
16029 child_die
= die
->child
;
16031 while (child_die
&& child_die
->tag
)
16033 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
16035 if (is_variant_part
&& discr_offset
== child_die
->sect_off
)
16036 fi
.fields
.back ().variant
.is_discriminant
= true;
16038 child_die
= sibling_die (child_die
);
16041 /* Attach template arguments to type. */
16042 if (!template_args
.empty ())
16044 has_template_parameters
= true;
16045 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16046 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
16047 TYPE_TEMPLATE_ARGUMENTS (type
)
16048 = XOBNEWVEC (&objfile
->objfile_obstack
,
16050 TYPE_N_TEMPLATE_ARGUMENTS (type
));
16051 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
16052 template_args
.data (),
16053 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
16054 * sizeof (struct symbol
*)));
16057 /* Attach fields and member functions to the type. */
16059 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
16060 if (!fi
.fnfieldlists
.empty ())
16062 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
16064 /* Get the type which refers to the base class (possibly this
16065 class itself) which contains the vtable pointer for the current
16066 class from the DW_AT_containing_type attribute. This use of
16067 DW_AT_containing_type is a GNU extension. */
16069 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
16071 struct type
*t
= die_containing_type (die
, cu
);
16073 set_type_vptr_basetype (type
, t
);
16078 /* Our own class provides vtbl ptr. */
16079 for (i
= TYPE_NFIELDS (t
) - 1;
16080 i
>= TYPE_N_BASECLASSES (t
);
16083 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
16085 if (is_vtable_name (fieldname
, cu
))
16087 set_type_vptr_fieldno (type
, i
);
16092 /* Complain if virtual function table field not found. */
16093 if (i
< TYPE_N_BASECLASSES (t
))
16094 complaint (_("virtual function table pointer "
16095 "not found when defining class '%s'"),
16096 TYPE_NAME (type
) ? TYPE_NAME (type
) : "");
16100 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
16103 else if (cu
->producer
16104 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
16106 /* The IBM XLC compiler does not provide direct indication
16107 of the containing type, but the vtable pointer is
16108 always named __vfp. */
16112 for (i
= TYPE_NFIELDS (type
) - 1;
16113 i
>= TYPE_N_BASECLASSES (type
);
16116 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
16118 set_type_vptr_fieldno (type
, i
);
16119 set_type_vptr_basetype (type
, type
);
16126 /* Copy fi.typedef_field_list linked list elements content into the
16127 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
16128 if (!fi
.typedef_field_list
.empty ())
16130 int count
= fi
.typedef_field_list
.size ();
16132 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16133 TYPE_TYPEDEF_FIELD_ARRAY (type
)
16134 = ((struct decl_field
*)
16136 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
16137 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
16139 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
16140 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
16143 /* Copy fi.nested_types_list linked list elements content into the
16144 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
16145 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
16147 int count
= fi
.nested_types_list
.size ();
16149 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16150 TYPE_NESTED_TYPES_ARRAY (type
)
16151 = ((struct decl_field
*)
16152 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
16153 TYPE_NESTED_TYPES_COUNT (type
) = count
;
16155 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
16156 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
16160 quirk_gcc_member_function_pointer (type
, objfile
);
16161 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
16162 cu
->rust_unions
.push_back (type
);
16164 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
16165 snapshots) has been known to create a die giving a declaration
16166 for a class that has, as a child, a die giving a definition for a
16167 nested class. So we have to process our children even if the
16168 current die is a declaration. Normally, of course, a declaration
16169 won't have any children at all. */
16171 child_die
= die
->child
;
16173 while (child_die
!= NULL
&& child_die
->tag
)
16175 if (child_die
->tag
== DW_TAG_member
16176 || child_die
->tag
== DW_TAG_variable
16177 || child_die
->tag
== DW_TAG_inheritance
16178 || child_die
->tag
== DW_TAG_template_value_param
16179 || child_die
->tag
== DW_TAG_template_type_param
)
16184 process_die (child_die
, cu
);
16186 child_die
= sibling_die (child_die
);
16189 /* Do not consider external references. According to the DWARF standard,
16190 these DIEs are identified by the fact that they have no byte_size
16191 attribute, and a declaration attribute. */
16192 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
16193 || !die_is_declaration (die
, cu
))
16195 struct symbol
*sym
= new_symbol (die
, type
, cu
);
16197 if (has_template_parameters
)
16199 struct symtab
*symtab
;
16200 if (sym
!= nullptr)
16201 symtab
= symbol_symtab (sym
);
16202 else if (cu
->line_header
!= nullptr)
16204 /* Any related symtab will do. */
16206 = cu
->line_header
->file_name_at (file_name_index (1))->symtab
;
16211 complaint (_("could not find suitable "
16212 "symtab for template parameter"
16213 " - DIE at %s [in module %s]"),
16214 sect_offset_str (die
->sect_off
),
16215 objfile_name (objfile
));
16218 if (symtab
!= nullptr)
16220 /* Make sure that the symtab is set on the new symbols.
16221 Even though they don't appear in this symtab directly,
16222 other parts of gdb assume that symbols do, and this is
16223 reasonably true. */
16224 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
16225 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
16231 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
16232 update TYPE using some information only available in DIE's children. */
16235 update_enumeration_type_from_children (struct die_info
*die
,
16237 struct dwarf2_cu
*cu
)
16239 struct die_info
*child_die
;
16240 int unsigned_enum
= 1;
16244 auto_obstack obstack
;
16246 for (child_die
= die
->child
;
16247 child_die
!= NULL
&& child_die
->tag
;
16248 child_die
= sibling_die (child_die
))
16250 struct attribute
*attr
;
16252 const gdb_byte
*bytes
;
16253 struct dwarf2_locexpr_baton
*baton
;
16256 if (child_die
->tag
!= DW_TAG_enumerator
)
16259 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16263 name
= dwarf2_name (child_die
, cu
);
16265 name
= "<anonymous enumerator>";
16267 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16268 &value
, &bytes
, &baton
);
16274 else if ((mask
& value
) != 0)
16279 /* If we already know that the enum type is neither unsigned, nor
16280 a flag type, no need to look at the rest of the enumerates. */
16281 if (!unsigned_enum
&& !flag_enum
)
16286 TYPE_UNSIGNED (type
) = 1;
16288 TYPE_FLAG_ENUM (type
) = 1;
16291 /* Given a DW_AT_enumeration_type die, set its type. We do not
16292 complete the type's fields yet, or create any symbols. */
16294 static struct type
*
16295 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16297 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16299 struct attribute
*attr
;
16302 /* If the definition of this type lives in .debug_types, read that type.
16303 Don't follow DW_AT_specification though, that will take us back up
16304 the chain and we want to go down. */
16305 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
16308 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16310 /* The type's CU may not be the same as CU.
16311 Ensure TYPE is recorded with CU in die_type_hash. */
16312 return set_die_type (die
, type
, cu
);
16315 type
= alloc_type (objfile
);
16317 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
16318 name
= dwarf2_full_name (NULL
, die
, cu
);
16320 TYPE_NAME (type
) = name
;
16322 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16325 struct type
*underlying_type
= die_type (die
, cu
);
16327 TYPE_TARGET_TYPE (type
) = underlying_type
;
16330 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16333 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16337 TYPE_LENGTH (type
) = 0;
16340 maybe_set_alignment (cu
, die
, type
);
16342 /* The enumeration DIE can be incomplete. In Ada, any type can be
16343 declared as private in the package spec, and then defined only
16344 inside the package body. Such types are known as Taft Amendment
16345 Types. When another package uses such a type, an incomplete DIE
16346 may be generated by the compiler. */
16347 if (die_is_declaration (die
, cu
))
16348 TYPE_STUB (type
) = 1;
16350 /* Finish the creation of this type by using the enum's children.
16351 We must call this even when the underlying type has been provided
16352 so that we can determine if we're looking at a "flag" enum. */
16353 update_enumeration_type_from_children (die
, type
, cu
);
16355 /* If this type has an underlying type that is not a stub, then we
16356 may use its attributes. We always use the "unsigned" attribute
16357 in this situation, because ordinarily we guess whether the type
16358 is unsigned -- but the guess can be wrong and the underlying type
16359 can tell us the reality. However, we defer to a local size
16360 attribute if one exists, because this lets the compiler override
16361 the underlying type if needed. */
16362 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
16364 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
16365 if (TYPE_LENGTH (type
) == 0)
16366 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
16367 if (TYPE_RAW_ALIGN (type
) == 0
16368 && TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)) != 0)
16369 set_type_align (type
, TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)));
16372 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16374 return set_die_type (die
, type
, cu
);
16377 /* Given a pointer to a die which begins an enumeration, process all
16378 the dies that define the members of the enumeration, and create the
16379 symbol for the enumeration type.
16381 NOTE: We reverse the order of the element list. */
16384 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16386 struct type
*this_type
;
16388 this_type
= get_die_type (die
, cu
);
16389 if (this_type
== NULL
)
16390 this_type
= read_enumeration_type (die
, cu
);
16392 if (die
->child
!= NULL
)
16394 struct die_info
*child_die
;
16395 struct symbol
*sym
;
16396 struct field
*fields
= NULL
;
16397 int num_fields
= 0;
16400 child_die
= die
->child
;
16401 while (child_die
&& child_die
->tag
)
16403 if (child_die
->tag
!= DW_TAG_enumerator
)
16405 process_die (child_die
, cu
);
16409 name
= dwarf2_name (child_die
, cu
);
16412 sym
= new_symbol (child_die
, this_type
, cu
);
16414 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
16416 fields
= (struct field
*)
16418 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
16419 * sizeof (struct field
));
16422 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
16423 FIELD_TYPE (fields
[num_fields
]) = NULL
;
16424 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
16425 FIELD_BITSIZE (fields
[num_fields
]) = 0;
16431 child_die
= sibling_die (child_die
);
16436 TYPE_NFIELDS (this_type
) = num_fields
;
16437 TYPE_FIELDS (this_type
) = (struct field
*)
16438 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
16439 memcpy (TYPE_FIELDS (this_type
), fields
,
16440 sizeof (struct field
) * num_fields
);
16445 /* If we are reading an enum from a .debug_types unit, and the enum
16446 is a declaration, and the enum is not the signatured type in the
16447 unit, then we do not want to add a symbol for it. Adding a
16448 symbol would in some cases obscure the true definition of the
16449 enum, giving users an incomplete type when the definition is
16450 actually available. Note that we do not want to do this for all
16451 enums which are just declarations, because C++0x allows forward
16452 enum declarations. */
16453 if (cu
->per_cu
->is_debug_types
16454 && die_is_declaration (die
, cu
))
16456 struct signatured_type
*sig_type
;
16458 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16459 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16460 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16464 new_symbol (die
, this_type
, cu
);
16467 /* Extract all information from a DW_TAG_array_type DIE and put it in
16468 the DIE's type field. For now, this only handles one dimensional
16471 static struct type
*
16472 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16474 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16475 struct die_info
*child_die
;
16477 struct type
*element_type
, *range_type
, *index_type
;
16478 struct attribute
*attr
;
16480 struct dynamic_prop
*byte_stride_prop
= NULL
;
16481 unsigned int bit_stride
= 0;
16483 element_type
= die_type (die
, cu
);
16485 /* The die_type call above may have already set the type for this DIE. */
16486 type
= get_die_type (die
, cu
);
16490 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16494 struct type
*prop_type
16495 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
16498 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16499 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
16503 complaint (_("unable to read array DW_AT_byte_stride "
16504 " - DIE at %s [in module %s]"),
16505 sect_offset_str (die
->sect_off
),
16506 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16507 /* Ignore this attribute. We will likely not be able to print
16508 arrays of this type correctly, but there is little we can do
16509 to help if we cannot read the attribute's value. */
16510 byte_stride_prop
= NULL
;
16514 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16516 bit_stride
= DW_UNSND (attr
);
16518 /* Irix 6.2 native cc creates array types without children for
16519 arrays with unspecified length. */
16520 if (die
->child
== NULL
)
16522 index_type
= objfile_type (objfile
)->builtin_int
;
16523 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16524 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16525 byte_stride_prop
, bit_stride
);
16526 return set_die_type (die
, type
, cu
);
16529 std::vector
<struct type
*> range_types
;
16530 child_die
= die
->child
;
16531 while (child_die
&& child_die
->tag
)
16533 if (child_die
->tag
== DW_TAG_subrange_type
)
16535 struct type
*child_type
= read_type_die (child_die
, cu
);
16537 if (child_type
!= NULL
)
16539 /* The range type was succesfully read. Save it for the
16540 array type creation. */
16541 range_types
.push_back (child_type
);
16544 child_die
= sibling_die (child_die
);
16547 /* Dwarf2 dimensions are output from left to right, create the
16548 necessary array types in backwards order. */
16550 type
= element_type
;
16552 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16556 while (i
< range_types
.size ())
16557 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16558 byte_stride_prop
, bit_stride
);
16562 size_t ndim
= range_types
.size ();
16564 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16565 byte_stride_prop
, bit_stride
);
16568 /* Understand Dwarf2 support for vector types (like they occur on
16569 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16570 array type. This is not part of the Dwarf2/3 standard yet, but a
16571 custom vendor extension. The main difference between a regular
16572 array and the vector variant is that vectors are passed by value
16574 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16576 make_vector_type (type
);
16578 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16579 implementation may choose to implement triple vectors using this
16581 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16584 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
16585 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16587 complaint (_("DW_AT_byte_size for array type smaller "
16588 "than the total size of elements"));
16591 name
= dwarf2_name (die
, cu
);
16593 TYPE_NAME (type
) = name
;
16595 maybe_set_alignment (cu
, die
, type
);
16597 /* Install the type in the die. */
16598 set_die_type (die
, type
, cu
);
16600 /* set_die_type should be already done. */
16601 set_descriptive_type (type
, die
, cu
);
16606 static enum dwarf_array_dim_ordering
16607 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16609 struct attribute
*attr
;
16611 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16614 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
16616 /* GNU F77 is a special case, as at 08/2004 array type info is the
16617 opposite order to the dwarf2 specification, but data is still
16618 laid out as per normal fortran.
16620 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16621 version checking. */
16623 if (cu
->language
== language_fortran
16624 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16626 return DW_ORD_row_major
;
16629 switch (cu
->language_defn
->la_array_ordering
)
16631 case array_column_major
:
16632 return DW_ORD_col_major
;
16633 case array_row_major
:
16635 return DW_ORD_row_major
;
16639 /* Extract all information from a DW_TAG_set_type DIE and put it in
16640 the DIE's type field. */
16642 static struct type
*
16643 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16645 struct type
*domain_type
, *set_type
;
16646 struct attribute
*attr
;
16648 domain_type
= die_type (die
, cu
);
16650 /* The die_type call above may have already set the type for this DIE. */
16651 set_type
= get_die_type (die
, cu
);
16655 set_type
= create_set_type (NULL
, domain_type
);
16657 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16659 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
16661 maybe_set_alignment (cu
, die
, set_type
);
16663 return set_die_type (die
, set_type
, cu
);
16666 /* A helper for read_common_block that creates a locexpr baton.
16667 SYM is the symbol which we are marking as computed.
16668 COMMON_DIE is the DIE for the common block.
16669 COMMON_LOC is the location expression attribute for the common
16671 MEMBER_LOC is the location expression attribute for the particular
16672 member of the common block that we are processing.
16673 CU is the CU from which the above come. */
16676 mark_common_block_symbol_computed (struct symbol
*sym
,
16677 struct die_info
*common_die
,
16678 struct attribute
*common_loc
,
16679 struct attribute
*member_loc
,
16680 struct dwarf2_cu
*cu
)
16682 struct dwarf2_per_objfile
*dwarf2_per_objfile
16683 = cu
->per_cu
->dwarf2_per_objfile
;
16684 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16685 struct dwarf2_locexpr_baton
*baton
;
16687 unsigned int cu_off
;
16688 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
16689 LONGEST offset
= 0;
16691 gdb_assert (common_loc
&& member_loc
);
16692 gdb_assert (attr_form_is_block (common_loc
));
16693 gdb_assert (attr_form_is_block (member_loc
)
16694 || attr_form_is_constant (member_loc
));
16696 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16697 baton
->per_cu
= cu
->per_cu
;
16698 gdb_assert (baton
->per_cu
);
16700 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16702 if (attr_form_is_constant (member_loc
))
16704 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
16705 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16708 baton
->size
+= DW_BLOCK (member_loc
)->size
;
16710 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16713 *ptr
++ = DW_OP_call4
;
16714 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16715 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16718 if (attr_form_is_constant (member_loc
))
16720 *ptr
++ = DW_OP_addr
;
16721 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16722 ptr
+= cu
->header
.addr_size
;
16726 /* We have to copy the data here, because DW_OP_call4 will only
16727 use a DW_AT_location attribute. */
16728 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
16729 ptr
+= DW_BLOCK (member_loc
)->size
;
16732 *ptr
++ = DW_OP_plus
;
16733 gdb_assert (ptr
- baton
->data
== baton
->size
);
16735 SYMBOL_LOCATION_BATON (sym
) = baton
;
16736 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16739 /* Create appropriate locally-scoped variables for all the
16740 DW_TAG_common_block entries. Also create a struct common_block
16741 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16742 is used to sepate the common blocks name namespace from regular
16746 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16748 struct attribute
*attr
;
16750 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16753 /* Support the .debug_loc offsets. */
16754 if (attr_form_is_block (attr
))
16758 else if (attr_form_is_section_offset (attr
))
16760 dwarf2_complex_location_expr_complaint ();
16765 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16766 "common block member");
16771 if (die
->child
!= NULL
)
16773 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16774 struct die_info
*child_die
;
16775 size_t n_entries
= 0, size
;
16776 struct common_block
*common_block
;
16777 struct symbol
*sym
;
16779 for (child_die
= die
->child
;
16780 child_die
&& child_die
->tag
;
16781 child_die
= sibling_die (child_die
))
16784 size
= (sizeof (struct common_block
)
16785 + (n_entries
- 1) * sizeof (struct symbol
*));
16787 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16789 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16790 common_block
->n_entries
= 0;
16792 for (child_die
= die
->child
;
16793 child_die
&& child_die
->tag
;
16794 child_die
= sibling_die (child_die
))
16796 /* Create the symbol in the DW_TAG_common_block block in the current
16798 sym
= new_symbol (child_die
, NULL
, cu
);
16801 struct attribute
*member_loc
;
16803 common_block
->contents
[common_block
->n_entries
++] = sym
;
16805 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16809 /* GDB has handled this for a long time, but it is
16810 not specified by DWARF. It seems to have been
16811 emitted by gfortran at least as recently as:
16812 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16813 complaint (_("Variable in common block has "
16814 "DW_AT_data_member_location "
16815 "- DIE at %s [in module %s]"),
16816 sect_offset_str (child_die
->sect_off
),
16817 objfile_name (objfile
));
16819 if (attr_form_is_section_offset (member_loc
))
16820 dwarf2_complex_location_expr_complaint ();
16821 else if (attr_form_is_constant (member_loc
)
16822 || attr_form_is_block (member_loc
))
16825 mark_common_block_symbol_computed (sym
, die
, attr
,
16829 dwarf2_complex_location_expr_complaint ();
16834 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16835 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16839 /* Create a type for a C++ namespace. */
16841 static struct type
*
16842 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16844 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16845 const char *previous_prefix
, *name
;
16849 /* For extensions, reuse the type of the original namespace. */
16850 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16852 struct die_info
*ext_die
;
16853 struct dwarf2_cu
*ext_cu
= cu
;
16855 ext_die
= dwarf2_extension (die
, &ext_cu
);
16856 type
= read_type_die (ext_die
, ext_cu
);
16858 /* EXT_CU may not be the same as CU.
16859 Ensure TYPE is recorded with CU in die_type_hash. */
16860 return set_die_type (die
, type
, cu
);
16863 name
= namespace_name (die
, &is_anonymous
, cu
);
16865 /* Now build the name of the current namespace. */
16867 previous_prefix
= determine_prefix (die
, cu
);
16868 if (previous_prefix
[0] != '\0')
16869 name
= typename_concat (&objfile
->objfile_obstack
,
16870 previous_prefix
, name
, 0, cu
);
16872 /* Create the type. */
16873 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16875 return set_die_type (die
, type
, cu
);
16878 /* Read a namespace scope. */
16881 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16883 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16886 /* Add a symbol associated to this if we haven't seen the namespace
16887 before. Also, add a using directive if it's an anonymous
16890 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16894 type
= read_type_die (die
, cu
);
16895 new_symbol (die
, type
, cu
);
16897 namespace_name (die
, &is_anonymous
, cu
);
16900 const char *previous_prefix
= determine_prefix (die
, cu
);
16902 std::vector
<const char *> excludes
;
16903 add_using_directive (using_directives (cu
),
16904 previous_prefix
, TYPE_NAME (type
), NULL
,
16905 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16909 if (die
->child
!= NULL
)
16911 struct die_info
*child_die
= die
->child
;
16913 while (child_die
&& child_die
->tag
)
16915 process_die (child_die
, cu
);
16916 child_die
= sibling_die (child_die
);
16921 /* Read a Fortran module as type. This DIE can be only a declaration used for
16922 imported module. Still we need that type as local Fortran "use ... only"
16923 declaration imports depend on the created type in determine_prefix. */
16925 static struct type
*
16926 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16928 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16929 const char *module_name
;
16932 module_name
= dwarf2_name (die
, cu
);
16933 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16935 return set_die_type (die
, type
, cu
);
16938 /* Read a Fortran module. */
16941 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16943 struct die_info
*child_die
= die
->child
;
16946 type
= read_type_die (die
, cu
);
16947 new_symbol (die
, type
, cu
);
16949 while (child_die
&& child_die
->tag
)
16951 process_die (child_die
, cu
);
16952 child_die
= sibling_die (child_die
);
16956 /* Return the name of the namespace represented by DIE. Set
16957 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16960 static const char *
16961 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16963 struct die_info
*current_die
;
16964 const char *name
= NULL
;
16966 /* Loop through the extensions until we find a name. */
16968 for (current_die
= die
;
16969 current_die
!= NULL
;
16970 current_die
= dwarf2_extension (die
, &cu
))
16972 /* We don't use dwarf2_name here so that we can detect the absence
16973 of a name -> anonymous namespace. */
16974 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16980 /* Is it an anonymous namespace? */
16982 *is_anonymous
= (name
== NULL
);
16984 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16989 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16990 the user defined type vector. */
16992 static struct type
*
16993 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16995 struct gdbarch
*gdbarch
16996 = get_objfile_arch (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16997 struct comp_unit_head
*cu_header
= &cu
->header
;
16999 struct attribute
*attr_byte_size
;
17000 struct attribute
*attr_address_class
;
17001 int byte_size
, addr_class
;
17002 struct type
*target_type
;
17004 target_type
= die_type (die
, cu
);
17006 /* The die_type call above may have already set the type for this DIE. */
17007 type
= get_die_type (die
, cu
);
17011 type
= lookup_pointer_type (target_type
);
17013 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17014 if (attr_byte_size
)
17015 byte_size
= DW_UNSND (attr_byte_size
);
17017 byte_size
= cu_header
->addr_size
;
17019 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
17020 if (attr_address_class
)
17021 addr_class
= DW_UNSND (attr_address_class
);
17023 addr_class
= DW_ADDR_none
;
17025 ULONGEST alignment
= get_alignment (cu
, die
);
17027 /* If the pointer size, alignment, or address class is different
17028 than the default, create a type variant marked as such and set
17029 the length accordingly. */
17030 if (TYPE_LENGTH (type
) != byte_size
17031 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
17032 && alignment
!= TYPE_RAW_ALIGN (type
))
17033 || addr_class
!= DW_ADDR_none
)
17035 if (gdbarch_address_class_type_flags_p (gdbarch
))
17039 type_flags
= gdbarch_address_class_type_flags
17040 (gdbarch
, byte_size
, addr_class
);
17041 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
17043 type
= make_type_with_address_space (type
, type_flags
);
17045 else if (TYPE_LENGTH (type
) != byte_size
)
17047 complaint (_("invalid pointer size %d"), byte_size
);
17049 else if (TYPE_RAW_ALIGN (type
) != alignment
)
17051 complaint (_("Invalid DW_AT_alignment"
17052 " - DIE at %s [in module %s]"),
17053 sect_offset_str (die
->sect_off
),
17054 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17058 /* Should we also complain about unhandled address classes? */
17062 TYPE_LENGTH (type
) = byte_size
;
17063 set_type_align (type
, alignment
);
17064 return set_die_type (die
, type
, cu
);
17067 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
17068 the user defined type vector. */
17070 static struct type
*
17071 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17074 struct type
*to_type
;
17075 struct type
*domain
;
17077 to_type
= die_type (die
, cu
);
17078 domain
= die_containing_type (die
, cu
);
17080 /* The calls above may have already set the type for this DIE. */
17081 type
= get_die_type (die
, cu
);
17085 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
17086 type
= lookup_methodptr_type (to_type
);
17087 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
17089 struct type
*new_type
17090 = alloc_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
17092 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
17093 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
17094 TYPE_VARARGS (to_type
));
17095 type
= lookup_methodptr_type (new_type
);
17098 type
= lookup_memberptr_type (to_type
, domain
);
17100 return set_die_type (die
, type
, cu
);
17103 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
17104 the user defined type vector. */
17106 static struct type
*
17107 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17108 enum type_code refcode
)
17110 struct comp_unit_head
*cu_header
= &cu
->header
;
17111 struct type
*type
, *target_type
;
17112 struct attribute
*attr
;
17114 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
17116 target_type
= die_type (die
, cu
);
17118 /* The die_type call above may have already set the type for this DIE. */
17119 type
= get_die_type (die
, cu
);
17123 type
= lookup_reference_type (target_type
, refcode
);
17124 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17127 TYPE_LENGTH (type
) = DW_UNSND (attr
);
17131 TYPE_LENGTH (type
) = cu_header
->addr_size
;
17133 maybe_set_alignment (cu
, die
, type
);
17134 return set_die_type (die
, type
, cu
);
17137 /* Add the given cv-qualifiers to the element type of the array. GCC
17138 outputs DWARF type qualifiers that apply to an array, not the
17139 element type. But GDB relies on the array element type to carry
17140 the cv-qualifiers. This mimics section 6.7.3 of the C99
17143 static struct type
*
17144 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17145 struct type
*base_type
, int cnst
, int voltl
)
17147 struct type
*el_type
, *inner_array
;
17149 base_type
= copy_type (base_type
);
17150 inner_array
= base_type
;
17152 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
17154 TYPE_TARGET_TYPE (inner_array
) =
17155 copy_type (TYPE_TARGET_TYPE (inner_array
));
17156 inner_array
= TYPE_TARGET_TYPE (inner_array
);
17159 el_type
= TYPE_TARGET_TYPE (inner_array
);
17160 cnst
|= TYPE_CONST (el_type
);
17161 voltl
|= TYPE_VOLATILE (el_type
);
17162 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
17164 return set_die_type (die
, base_type
, cu
);
17167 static struct type
*
17168 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17170 struct type
*base_type
, *cv_type
;
17172 base_type
= die_type (die
, cu
);
17174 /* The die_type call above may have already set the type for this DIE. */
17175 cv_type
= get_die_type (die
, cu
);
17179 /* In case the const qualifier is applied to an array type, the element type
17180 is so qualified, not the array type (section 6.7.3 of C99). */
17181 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
17182 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
17184 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
17185 return set_die_type (die
, cv_type
, cu
);
17188 static struct type
*
17189 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17191 struct type
*base_type
, *cv_type
;
17193 base_type
= die_type (die
, cu
);
17195 /* The die_type call above may have already set the type for this DIE. */
17196 cv_type
= get_die_type (die
, cu
);
17200 /* In case the volatile qualifier is applied to an array type, the
17201 element type is so qualified, not the array type (section 6.7.3
17203 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
17204 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17206 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17207 return set_die_type (die
, cv_type
, cu
);
17210 /* Handle DW_TAG_restrict_type. */
17212 static struct type
*
17213 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17215 struct type
*base_type
, *cv_type
;
17217 base_type
= die_type (die
, cu
);
17219 /* The die_type call above may have already set the type for this DIE. */
17220 cv_type
= get_die_type (die
, cu
);
17224 cv_type
= make_restrict_type (base_type
);
17225 return set_die_type (die
, cv_type
, cu
);
17228 /* Handle DW_TAG_atomic_type. */
17230 static struct type
*
17231 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17233 struct type
*base_type
, *cv_type
;
17235 base_type
= die_type (die
, cu
);
17237 /* The die_type call above may have already set the type for this DIE. */
17238 cv_type
= get_die_type (die
, cu
);
17242 cv_type
= make_atomic_type (base_type
);
17243 return set_die_type (die
, cv_type
, cu
);
17246 /* Extract all information from a DW_TAG_string_type DIE and add to
17247 the user defined type vector. It isn't really a user defined type,
17248 but it behaves like one, with other DIE's using an AT_user_def_type
17249 attribute to reference it. */
17251 static struct type
*
17252 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17254 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17255 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17256 struct type
*type
, *range_type
, *index_type
, *char_type
;
17257 struct attribute
*attr
;
17258 unsigned int length
;
17260 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17263 length
= DW_UNSND (attr
);
17267 /* Check for the DW_AT_byte_size attribute. */
17268 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17271 length
= DW_UNSND (attr
);
17279 index_type
= objfile_type (objfile
)->builtin_int
;
17280 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17281 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17282 type
= create_string_type (NULL
, char_type
, range_type
);
17284 return set_die_type (die
, type
, cu
);
17287 /* Assuming that DIE corresponds to a function, returns nonzero
17288 if the function is prototyped. */
17291 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17293 struct attribute
*attr
;
17295 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17296 if (attr
&& (DW_UNSND (attr
) != 0))
17299 /* The DWARF standard implies that the DW_AT_prototyped attribute
17300 is only meaninful for C, but the concept also extends to other
17301 languages that allow unprototyped functions (Eg: Objective C).
17302 For all other languages, assume that functions are always
17304 if (cu
->language
!= language_c
17305 && cu
->language
!= language_objc
17306 && cu
->language
!= language_opencl
)
17309 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17310 prototyped and unprototyped functions; default to prototyped,
17311 since that is more common in modern code (and RealView warns
17312 about unprototyped functions). */
17313 if (producer_is_realview (cu
->producer
))
17319 /* Handle DIES due to C code like:
17323 int (*funcp)(int a, long l);
17327 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17329 static struct type
*
17330 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17332 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17333 struct type
*type
; /* Type that this function returns. */
17334 struct type
*ftype
; /* Function that returns above type. */
17335 struct attribute
*attr
;
17337 type
= die_type (die
, cu
);
17339 /* The die_type call above may have already set the type for this DIE. */
17340 ftype
= get_die_type (die
, cu
);
17344 ftype
= lookup_function_type (type
);
17346 if (prototyped_function_p (die
, cu
))
17347 TYPE_PROTOTYPED (ftype
) = 1;
17349 /* Store the calling convention in the type if it's available in
17350 the subroutine die. Otherwise set the calling convention to
17351 the default value DW_CC_normal. */
17352 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17354 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
17355 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17356 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17358 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17360 /* Record whether the function returns normally to its caller or not
17361 if the DWARF producer set that information. */
17362 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17363 if (attr
&& (DW_UNSND (attr
) != 0))
17364 TYPE_NO_RETURN (ftype
) = 1;
17366 /* We need to add the subroutine type to the die immediately so
17367 we don't infinitely recurse when dealing with parameters
17368 declared as the same subroutine type. */
17369 set_die_type (die
, ftype
, cu
);
17371 if (die
->child
!= NULL
)
17373 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17374 struct die_info
*child_die
;
17375 int nparams
, iparams
;
17377 /* Count the number of parameters.
17378 FIXME: GDB currently ignores vararg functions, but knows about
17379 vararg member functions. */
17381 child_die
= die
->child
;
17382 while (child_die
&& child_die
->tag
)
17384 if (child_die
->tag
== DW_TAG_formal_parameter
)
17386 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17387 TYPE_VARARGS (ftype
) = 1;
17388 child_die
= sibling_die (child_die
);
17391 /* Allocate storage for parameters and fill them in. */
17392 TYPE_NFIELDS (ftype
) = nparams
;
17393 TYPE_FIELDS (ftype
) = (struct field
*)
17394 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
17396 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17397 even if we error out during the parameters reading below. */
17398 for (iparams
= 0; iparams
< nparams
; iparams
++)
17399 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
17402 child_die
= die
->child
;
17403 while (child_die
&& child_die
->tag
)
17405 if (child_die
->tag
== DW_TAG_formal_parameter
)
17407 struct type
*arg_type
;
17409 /* DWARF version 2 has no clean way to discern C++
17410 static and non-static member functions. G++ helps
17411 GDB by marking the first parameter for non-static
17412 member functions (which is the this pointer) as
17413 artificial. We pass this information to
17414 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17416 DWARF version 3 added DW_AT_object_pointer, which GCC
17417 4.5 does not yet generate. */
17418 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17420 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
17422 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17423 arg_type
= die_type (child_die
, cu
);
17425 /* RealView does not mark THIS as const, which the testsuite
17426 expects. GCC marks THIS as const in method definitions,
17427 but not in the class specifications (GCC PR 43053). */
17428 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17429 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17432 struct dwarf2_cu
*arg_cu
= cu
;
17433 const char *name
= dwarf2_name (child_die
, cu
);
17435 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17438 /* If the compiler emits this, use it. */
17439 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17442 else if (name
&& strcmp (name
, "this") == 0)
17443 /* Function definitions will have the argument names. */
17445 else if (name
== NULL
&& iparams
== 0)
17446 /* Declarations may not have the names, so like
17447 elsewhere in GDB, assume an artificial first
17448 argument is "this". */
17452 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17456 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
17459 child_die
= sibling_die (child_die
);
17466 static struct type
*
17467 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17469 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17470 const char *name
= NULL
;
17471 struct type
*this_type
, *target_type
;
17473 name
= dwarf2_full_name (NULL
, die
, cu
);
17474 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17475 TYPE_TARGET_STUB (this_type
) = 1;
17476 set_die_type (die
, this_type
, cu
);
17477 target_type
= die_type (die
, cu
);
17478 if (target_type
!= this_type
)
17479 TYPE_TARGET_TYPE (this_type
) = target_type
;
17482 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17483 spec and cause infinite loops in GDB. */
17484 complaint (_("Self-referential DW_TAG_typedef "
17485 "- DIE at %s [in module %s]"),
17486 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17487 TYPE_TARGET_TYPE (this_type
) = NULL
;
17492 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17493 (which may be different from NAME) to the architecture back-end to allow
17494 it to guess the correct format if necessary. */
17496 static struct type
*
17497 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17498 const char *name_hint
)
17500 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17501 const struct floatformat
**format
;
17504 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17506 type
= init_float_type (objfile
, bits
, name
, format
);
17508 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17513 /* Allocate an integer type of size BITS and name NAME. */
17515 static struct type
*
17516 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
17517 int bits
, int unsigned_p
, const char *name
)
17521 /* Versions of Intel's C Compiler generate an integer type called "void"
17522 instead of using DW_TAG_unspecified_type. This has been seen on
17523 at least versions 14, 17, and 18. */
17524 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
17525 && strcmp (name
, "void") == 0)
17526 type
= objfile_type (objfile
)->builtin_void
;
17528 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
17533 /* Initialise and return a floating point type of size BITS suitable for
17534 use as a component of a complex number. The NAME_HINT is passed through
17535 when initialising the floating point type and is the name of the complex
17538 As DWARF doesn't currently provide an explicit name for the components
17539 of a complex number, but it can be helpful to have these components
17540 named, we try to select a suitable name based on the size of the
17542 static struct type
*
17543 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
17544 struct objfile
*objfile
,
17545 int bits
, const char *name_hint
)
17547 gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17548 struct type
*tt
= nullptr;
17550 /* Try to find a suitable floating point builtin type of size BITS.
17551 We're going to use the name of this type as the name for the complex
17552 target type that we are about to create. */
17553 switch (cu
->language
)
17555 case language_fortran
:
17559 tt
= builtin_f_type (gdbarch
)->builtin_real
;
17562 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
17564 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17566 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
17574 tt
= builtin_type (gdbarch
)->builtin_float
;
17577 tt
= builtin_type (gdbarch
)->builtin_double
;
17579 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17581 tt
= builtin_type (gdbarch
)->builtin_long_double
;
17587 /* If the type we found doesn't match the size we were looking for, then
17588 pretend we didn't find a type at all, the complex target type we
17589 create will then be nameless. */
17590 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
17593 const char *name
= (tt
== nullptr) ? nullptr : TYPE_NAME (tt
);
17594 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
);
17597 /* Find a representation of a given base type and install
17598 it in the TYPE field of the die. */
17600 static struct type
*
17601 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17603 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17605 struct attribute
*attr
;
17606 int encoding
= 0, bits
= 0;
17609 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17612 encoding
= DW_UNSND (attr
);
17614 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17617 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
17619 name
= dwarf2_name (die
, cu
);
17622 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
17627 case DW_ATE_address
:
17628 /* Turn DW_ATE_address into a void * pointer. */
17629 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
17630 type
= init_pointer_type (objfile
, bits
, name
, type
);
17632 case DW_ATE_boolean
:
17633 type
= init_boolean_type (objfile
, bits
, 1, name
);
17635 case DW_ATE_complex_float
:
17636 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
);
17637 type
= init_complex_type (objfile
, name
, type
);
17639 case DW_ATE_decimal_float
:
17640 type
= init_decfloat_type (objfile
, bits
, name
);
17643 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
);
17645 case DW_ATE_signed
:
17646 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17648 case DW_ATE_unsigned
:
17649 if (cu
->language
== language_fortran
17651 && startswith (name
, "character("))
17652 type
= init_character_type (objfile
, bits
, 1, name
);
17654 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17656 case DW_ATE_signed_char
:
17657 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17658 || cu
->language
== language_pascal
17659 || cu
->language
== language_fortran
)
17660 type
= init_character_type (objfile
, bits
, 0, name
);
17662 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17664 case DW_ATE_unsigned_char
:
17665 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17666 || cu
->language
== language_pascal
17667 || cu
->language
== language_fortran
17668 || cu
->language
== language_rust
)
17669 type
= init_character_type (objfile
, bits
, 1, name
);
17671 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17675 gdbarch
*arch
= get_objfile_arch (objfile
);
17678 type
= builtin_type (arch
)->builtin_char16
;
17679 else if (bits
== 32)
17680 type
= builtin_type (arch
)->builtin_char32
;
17683 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
17685 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17687 return set_die_type (die
, type
, cu
);
17692 complaint (_("unsupported DW_AT_encoding: '%s'"),
17693 dwarf_type_encoding_name (encoding
));
17694 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17698 if (name
&& strcmp (name
, "char") == 0)
17699 TYPE_NOSIGN (type
) = 1;
17701 maybe_set_alignment (cu
, die
, type
);
17703 return set_die_type (die
, type
, cu
);
17706 /* Parse dwarf attribute if it's a block, reference or constant and put the
17707 resulting value of the attribute into struct bound_prop.
17708 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17711 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17712 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
17713 struct type
*default_type
)
17715 struct dwarf2_property_baton
*baton
;
17716 struct obstack
*obstack
17717 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
17719 gdb_assert (default_type
!= NULL
);
17721 if (attr
== NULL
|| prop
== NULL
)
17724 if (attr_form_is_block (attr
))
17726 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17727 baton
->property_type
= default_type
;
17728 baton
->locexpr
.per_cu
= cu
->per_cu
;
17729 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17730 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17731 baton
->locexpr
.is_reference
= false;
17732 prop
->data
.baton
= baton
;
17733 prop
->kind
= PROP_LOCEXPR
;
17734 gdb_assert (prop
->data
.baton
!= NULL
);
17736 else if (attr_form_is_ref (attr
))
17738 struct dwarf2_cu
*target_cu
= cu
;
17739 struct die_info
*target_die
;
17740 struct attribute
*target_attr
;
17742 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17743 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17744 if (target_attr
== NULL
)
17745 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17747 if (target_attr
== NULL
)
17750 switch (target_attr
->name
)
17752 case DW_AT_location
:
17753 if (attr_form_is_section_offset (target_attr
))
17755 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17756 baton
->property_type
= die_type (target_die
, target_cu
);
17757 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17758 prop
->data
.baton
= baton
;
17759 prop
->kind
= PROP_LOCLIST
;
17760 gdb_assert (prop
->data
.baton
!= NULL
);
17762 else if (attr_form_is_block (target_attr
))
17764 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17765 baton
->property_type
= die_type (target_die
, target_cu
);
17766 baton
->locexpr
.per_cu
= cu
->per_cu
;
17767 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17768 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17769 baton
->locexpr
.is_reference
= true;
17770 prop
->data
.baton
= baton
;
17771 prop
->kind
= PROP_LOCEXPR
;
17772 gdb_assert (prop
->data
.baton
!= NULL
);
17776 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17777 "dynamic property");
17781 case DW_AT_data_member_location
:
17785 if (!handle_data_member_location (target_die
, target_cu
,
17789 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17790 baton
->property_type
= read_type_die (target_die
->parent
,
17792 baton
->offset_info
.offset
= offset
;
17793 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17794 prop
->data
.baton
= baton
;
17795 prop
->kind
= PROP_ADDR_OFFSET
;
17800 else if (attr_form_is_constant (attr
))
17802 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
17803 prop
->kind
= PROP_CONST
;
17807 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17808 dwarf2_name (die
, cu
));
17815 /* Find an integer type the same size as the address size given in the
17816 compilation unit header for PER_CU. UNSIGNED_P controls if the integer
17817 is unsigned or not. */
17819 static struct type
*
17820 dwarf2_per_cu_addr_sized_int_type (struct dwarf2_per_cu_data
*per_cu
,
17823 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
17824 int addr_size
= dwarf2_per_cu_addr_size (per_cu
);
17825 struct type
*int_type
;
17827 /* Helper macro to examine the various builtin types. */
17828 #define TRY_TYPE(F) \
17829 int_type = (unsigned_p \
17830 ? objfile_type (objfile)->builtin_unsigned_ ## F \
17831 : objfile_type (objfile)->builtin_ ## F); \
17832 if (int_type != NULL && TYPE_LENGTH (int_type) == addr_size) \
17839 TRY_TYPE (long_long
);
17843 gdb_assert_not_reached ("unable to find suitable integer type");
17846 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
17847 present (which is valid) then compute the default type based on the
17848 compilation units address size. */
17850 static struct type
*
17851 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17853 struct type
*index_type
= die_type (die
, cu
);
17855 /* Dwarf-2 specifications explicitly allows to create subrange types
17856 without specifying a base type.
17857 In that case, the base type must be set to the type of
17858 the lower bound, upper bound or count, in that order, if any of these
17859 three attributes references an object that has a type.
17860 If no base type is found, the Dwarf-2 specifications say that
17861 a signed integer type of size equal to the size of an address should
17863 For the following C code: `extern char gdb_int [];'
17864 GCC produces an empty range DIE.
17865 FIXME: muller/2010-05-28: Possible references to object for low bound,
17866 high bound or count are not yet handled by this code. */
17867 if (TYPE_CODE (index_type
) == TYPE_CODE_VOID
)
17868 index_type
= dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
17873 /* Read the given DW_AT_subrange DIE. */
17875 static struct type
*
17876 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17878 struct type
*base_type
, *orig_base_type
;
17879 struct type
*range_type
;
17880 struct attribute
*attr
;
17881 struct dynamic_prop low
, high
;
17882 int low_default_is_valid
;
17883 int high_bound_is_count
= 0;
17885 ULONGEST negative_mask
;
17887 orig_base_type
= read_subrange_index_type (die
, cu
);
17889 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17890 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17891 creating the range type, but we use the result of check_typedef
17892 when examining properties of the type. */
17893 base_type
= check_typedef (orig_base_type
);
17895 /* The die_type call above may have already set the type for this DIE. */
17896 range_type
= get_die_type (die
, cu
);
17900 low
.kind
= PROP_CONST
;
17901 high
.kind
= PROP_CONST
;
17902 high
.data
.const_val
= 0;
17904 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17905 omitting DW_AT_lower_bound. */
17906 switch (cu
->language
)
17909 case language_cplus
:
17910 low
.data
.const_val
= 0;
17911 low_default_is_valid
= 1;
17913 case language_fortran
:
17914 low
.data
.const_val
= 1;
17915 low_default_is_valid
= 1;
17918 case language_objc
:
17919 case language_rust
:
17920 low
.data
.const_val
= 0;
17921 low_default_is_valid
= (cu
->header
.version
>= 4);
17925 case language_pascal
:
17926 low
.data
.const_val
= 1;
17927 low_default_is_valid
= (cu
->header
.version
>= 4);
17930 low
.data
.const_val
= 0;
17931 low_default_is_valid
= 0;
17935 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
17937 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
17938 else if (!low_default_is_valid
)
17939 complaint (_("Missing DW_AT_lower_bound "
17940 "- DIE at %s [in module %s]"),
17941 sect_offset_str (die
->sect_off
),
17942 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17944 struct attribute
*attr_ub
, *attr_count
;
17945 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
17946 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17948 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
17949 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17951 /* If bounds are constant do the final calculation here. */
17952 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
17953 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
17955 high_bound_is_count
= 1;
17959 if (attr_ub
!= NULL
)
17960 complaint (_("Unresolved DW_AT_upper_bound "
17961 "- DIE at %s [in module %s]"),
17962 sect_offset_str (die
->sect_off
),
17963 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17964 if (attr_count
!= NULL
)
17965 complaint (_("Unresolved DW_AT_count "
17966 "- DIE at %s [in module %s]"),
17967 sect_offset_str (die
->sect_off
),
17968 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17973 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
17974 if (bias_attr
!= nullptr && attr_form_is_constant (bias_attr
))
17975 bias
= dwarf2_get_attr_constant_value (bias_attr
, 0);
17977 /* Normally, the DWARF producers are expected to use a signed
17978 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17979 But this is unfortunately not always the case, as witnessed
17980 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17981 is used instead. To work around that ambiguity, we treat
17982 the bounds as signed, and thus sign-extend their values, when
17983 the base type is signed. */
17985 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
17986 if (low
.kind
== PROP_CONST
17987 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
17988 low
.data
.const_val
|= negative_mask
;
17989 if (high
.kind
== PROP_CONST
17990 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
17991 high
.data
.const_val
|= negative_mask
;
17993 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
17995 if (high_bound_is_count
)
17996 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
17998 /* Ada expects an empty array on no boundary attributes. */
17999 if (attr
== NULL
&& cu
->language
!= language_ada
)
18000 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
18002 name
= dwarf2_name (die
, cu
);
18004 TYPE_NAME (range_type
) = name
;
18006 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18008 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
18010 maybe_set_alignment (cu
, die
, range_type
);
18012 set_die_type (die
, range_type
, cu
);
18014 /* set_die_type should be already done. */
18015 set_descriptive_type (range_type
, die
, cu
);
18020 static struct type
*
18021 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18025 type
= init_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
, TYPE_CODE_VOID
,0,
18027 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
18029 /* In Ada, an unspecified type is typically used when the description
18030 of the type is defered to a different unit. When encountering
18031 such a type, we treat it as a stub, and try to resolve it later on,
18033 if (cu
->language
== language_ada
)
18034 TYPE_STUB (type
) = 1;
18036 return set_die_type (die
, type
, cu
);
18039 /* Read a single die and all its descendents. Set the die's sibling
18040 field to NULL; set other fields in the die correctly, and set all
18041 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
18042 location of the info_ptr after reading all of those dies. PARENT
18043 is the parent of the die in question. */
18045 static struct die_info
*
18046 read_die_and_children (const struct die_reader_specs
*reader
,
18047 const gdb_byte
*info_ptr
,
18048 const gdb_byte
**new_info_ptr
,
18049 struct die_info
*parent
)
18051 struct die_info
*die
;
18052 const gdb_byte
*cur_ptr
;
18055 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, &has_children
, 0);
18058 *new_info_ptr
= cur_ptr
;
18061 store_in_ref_table (die
, reader
->cu
);
18064 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
18068 *new_info_ptr
= cur_ptr
;
18071 die
->sibling
= NULL
;
18072 die
->parent
= parent
;
18076 /* Read a die, all of its descendents, and all of its siblings; set
18077 all of the fields of all of the dies correctly. Arguments are as
18078 in read_die_and_children. */
18080 static struct die_info
*
18081 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
18082 const gdb_byte
*info_ptr
,
18083 const gdb_byte
**new_info_ptr
,
18084 struct die_info
*parent
)
18086 struct die_info
*first_die
, *last_sibling
;
18087 const gdb_byte
*cur_ptr
;
18089 cur_ptr
= info_ptr
;
18090 first_die
= last_sibling
= NULL
;
18094 struct die_info
*die
18095 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
18099 *new_info_ptr
= cur_ptr
;
18106 last_sibling
->sibling
= die
;
18108 last_sibling
= die
;
18112 /* Read a die, all of its descendents, and all of its siblings; set
18113 all of the fields of all of the dies correctly. Arguments are as
18114 in read_die_and_children.
18115 This the main entry point for reading a DIE and all its children. */
18117 static struct die_info
*
18118 read_die_and_siblings (const struct die_reader_specs
*reader
,
18119 const gdb_byte
*info_ptr
,
18120 const gdb_byte
**new_info_ptr
,
18121 struct die_info
*parent
)
18123 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
18124 new_info_ptr
, parent
);
18126 if (dwarf_die_debug
)
18128 fprintf_unfiltered (gdb_stdlog
,
18129 "Read die from %s@0x%x of %s:\n",
18130 get_section_name (reader
->die_section
),
18131 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18132 bfd_get_filename (reader
->abfd
));
18133 dump_die (die
, dwarf_die_debug
);
18139 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
18141 The caller is responsible for filling in the extra attributes
18142 and updating (*DIEP)->num_attrs.
18143 Set DIEP to point to a newly allocated die with its information,
18144 except for its child, sibling, and parent fields.
18145 Set HAS_CHILDREN to tell whether the die has children or not. */
18147 static const gdb_byte
*
18148 read_full_die_1 (const struct die_reader_specs
*reader
,
18149 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18150 int *has_children
, int num_extra_attrs
)
18152 unsigned int abbrev_number
, bytes_read
, i
;
18153 struct abbrev_info
*abbrev
;
18154 struct die_info
*die
;
18155 struct dwarf2_cu
*cu
= reader
->cu
;
18156 bfd
*abfd
= reader
->abfd
;
18158 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
18159 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18160 info_ptr
+= bytes_read
;
18161 if (!abbrev_number
)
18168 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
18170 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
18172 bfd_get_filename (abfd
));
18174 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
18175 die
->sect_off
= sect_off
;
18176 die
->tag
= abbrev
->tag
;
18177 die
->abbrev
= abbrev_number
;
18179 /* Make the result usable.
18180 The caller needs to update num_attrs after adding the extra
18182 die
->num_attrs
= abbrev
->num_attrs
;
18184 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18185 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
18189 *has_children
= abbrev
->has_children
;
18193 /* Read a die and all its attributes.
18194 Set DIEP to point to a newly allocated die with its information,
18195 except for its child, sibling, and parent fields.
18196 Set HAS_CHILDREN to tell whether the die has children or not. */
18198 static const gdb_byte
*
18199 read_full_die (const struct die_reader_specs
*reader
,
18200 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18203 const gdb_byte
*result
;
18205 result
= read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
18207 if (dwarf_die_debug
)
18209 fprintf_unfiltered (gdb_stdlog
,
18210 "Read die from %s@0x%x of %s:\n",
18211 get_section_name (reader
->die_section
),
18212 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18213 bfd_get_filename (reader
->abfd
));
18214 dump_die (*diep
, dwarf_die_debug
);
18220 /* Abbreviation tables.
18222 In DWARF version 2, the description of the debugging information is
18223 stored in a separate .debug_abbrev section. Before we read any
18224 dies from a section we read in all abbreviations and install them
18225 in a hash table. */
18227 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
18229 struct abbrev_info
*
18230 abbrev_table::alloc_abbrev ()
18232 struct abbrev_info
*abbrev
;
18234 abbrev
= XOBNEW (&abbrev_obstack
, struct abbrev_info
);
18235 memset (abbrev
, 0, sizeof (struct abbrev_info
));
18240 /* Add an abbreviation to the table. */
18243 abbrev_table::add_abbrev (unsigned int abbrev_number
,
18244 struct abbrev_info
*abbrev
)
18246 unsigned int hash_number
;
18248 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
18249 abbrev
->next
= m_abbrevs
[hash_number
];
18250 m_abbrevs
[hash_number
] = abbrev
;
18253 /* Look up an abbrev in the table.
18254 Returns NULL if the abbrev is not found. */
18256 struct abbrev_info
*
18257 abbrev_table::lookup_abbrev (unsigned int abbrev_number
)
18259 unsigned int hash_number
;
18260 struct abbrev_info
*abbrev
;
18262 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
18263 abbrev
= m_abbrevs
[hash_number
];
18267 if (abbrev
->number
== abbrev_number
)
18269 abbrev
= abbrev
->next
;
18274 /* Read in an abbrev table. */
18276 static abbrev_table_up
18277 abbrev_table_read_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18278 struct dwarf2_section_info
*section
,
18279 sect_offset sect_off
)
18281 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18282 bfd
*abfd
= get_section_bfd_owner (section
);
18283 const gdb_byte
*abbrev_ptr
;
18284 struct abbrev_info
*cur_abbrev
;
18285 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
18286 unsigned int abbrev_form
;
18287 struct attr_abbrev
*cur_attrs
;
18288 unsigned int allocated_attrs
;
18290 abbrev_table_up
abbrev_table (new struct abbrev_table (sect_off
));
18292 dwarf2_read_section (objfile
, section
);
18293 abbrev_ptr
= section
->buffer
+ to_underlying (sect_off
);
18294 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18295 abbrev_ptr
+= bytes_read
;
18297 allocated_attrs
= ATTR_ALLOC_CHUNK
;
18298 cur_attrs
= XNEWVEC (struct attr_abbrev
, allocated_attrs
);
18300 /* Loop until we reach an abbrev number of 0. */
18301 while (abbrev_number
)
18303 cur_abbrev
= abbrev_table
->alloc_abbrev ();
18305 /* read in abbrev header */
18306 cur_abbrev
->number
= abbrev_number
;
18308 = (enum dwarf_tag
) read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18309 abbrev_ptr
+= bytes_read
;
18310 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
18313 /* now read in declarations */
18316 LONGEST implicit_const
;
18318 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18319 abbrev_ptr
+= bytes_read
;
18320 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18321 abbrev_ptr
+= bytes_read
;
18322 if (abbrev_form
== DW_FORM_implicit_const
)
18324 implicit_const
= read_signed_leb128 (abfd
, abbrev_ptr
,
18326 abbrev_ptr
+= bytes_read
;
18330 /* Initialize it due to a false compiler warning. */
18331 implicit_const
= -1;
18334 if (abbrev_name
== 0)
18337 if (cur_abbrev
->num_attrs
== allocated_attrs
)
18339 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
18341 = XRESIZEVEC (struct attr_abbrev
, cur_attrs
, allocated_attrs
);
18344 cur_attrs
[cur_abbrev
->num_attrs
].name
18345 = (enum dwarf_attribute
) abbrev_name
;
18346 cur_attrs
[cur_abbrev
->num_attrs
].form
18347 = (enum dwarf_form
) abbrev_form
;
18348 cur_attrs
[cur_abbrev
->num_attrs
].implicit_const
= implicit_const
;
18349 ++cur_abbrev
->num_attrs
;
18352 cur_abbrev
->attrs
=
18353 XOBNEWVEC (&abbrev_table
->abbrev_obstack
, struct attr_abbrev
,
18354 cur_abbrev
->num_attrs
);
18355 memcpy (cur_abbrev
->attrs
, cur_attrs
,
18356 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
18358 abbrev_table
->add_abbrev (abbrev_number
, cur_abbrev
);
18360 /* Get next abbreviation.
18361 Under Irix6 the abbreviations for a compilation unit are not
18362 always properly terminated with an abbrev number of 0.
18363 Exit loop if we encounter an abbreviation which we have
18364 already read (which means we are about to read the abbreviations
18365 for the next compile unit) or if the end of the abbreviation
18366 table is reached. */
18367 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
18369 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18370 abbrev_ptr
+= bytes_read
;
18371 if (abbrev_table
->lookup_abbrev (abbrev_number
) != NULL
)
18376 return abbrev_table
;
18379 /* Returns nonzero if TAG represents a type that we might generate a partial
18383 is_type_tag_for_partial (int tag
)
18388 /* Some types that would be reasonable to generate partial symbols for,
18389 that we don't at present. */
18390 case DW_TAG_array_type
:
18391 case DW_TAG_file_type
:
18392 case DW_TAG_ptr_to_member_type
:
18393 case DW_TAG_set_type
:
18394 case DW_TAG_string_type
:
18395 case DW_TAG_subroutine_type
:
18397 case DW_TAG_base_type
:
18398 case DW_TAG_class_type
:
18399 case DW_TAG_interface_type
:
18400 case DW_TAG_enumeration_type
:
18401 case DW_TAG_structure_type
:
18402 case DW_TAG_subrange_type
:
18403 case DW_TAG_typedef
:
18404 case DW_TAG_union_type
:
18411 /* Load all DIEs that are interesting for partial symbols into memory. */
18413 static struct partial_die_info
*
18414 load_partial_dies (const struct die_reader_specs
*reader
,
18415 const gdb_byte
*info_ptr
, int building_psymtab
)
18417 struct dwarf2_cu
*cu
= reader
->cu
;
18418 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18419 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18420 unsigned int bytes_read
;
18421 unsigned int load_all
= 0;
18422 int nesting_level
= 1;
18427 gdb_assert (cu
->per_cu
!= NULL
);
18428 if (cu
->per_cu
->load_all_dies
)
18432 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18436 &cu
->comp_unit_obstack
,
18437 hashtab_obstack_allocate
,
18438 dummy_obstack_deallocate
);
18442 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
18444 /* A NULL abbrev means the end of a series of children. */
18445 if (abbrev
== NULL
)
18447 if (--nesting_level
== 0)
18450 info_ptr
+= bytes_read
;
18451 last_die
= parent_die
;
18452 parent_die
= parent_die
->die_parent
;
18456 /* Check for template arguments. We never save these; if
18457 they're seen, we just mark the parent, and go on our way. */
18458 if (parent_die
!= NULL
18459 && cu
->language
== language_cplus
18460 && (abbrev
->tag
== DW_TAG_template_type_param
18461 || abbrev
->tag
== DW_TAG_template_value_param
))
18463 parent_die
->has_template_arguments
= 1;
18467 /* We don't need a partial DIE for the template argument. */
18468 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18473 /* We only recurse into c++ subprograms looking for template arguments.
18474 Skip their other children. */
18476 && cu
->language
== language_cplus
18477 && parent_die
!= NULL
18478 && parent_die
->tag
== DW_TAG_subprogram
)
18480 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18484 /* Check whether this DIE is interesting enough to save. Normally
18485 we would not be interested in members here, but there may be
18486 later variables referencing them via DW_AT_specification (for
18487 static members). */
18489 && !is_type_tag_for_partial (abbrev
->tag
)
18490 && abbrev
->tag
!= DW_TAG_constant
18491 && abbrev
->tag
!= DW_TAG_enumerator
18492 && abbrev
->tag
!= DW_TAG_subprogram
18493 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18494 && abbrev
->tag
!= DW_TAG_lexical_block
18495 && abbrev
->tag
!= DW_TAG_variable
18496 && abbrev
->tag
!= DW_TAG_namespace
18497 && abbrev
->tag
!= DW_TAG_module
18498 && abbrev
->tag
!= DW_TAG_member
18499 && abbrev
->tag
!= DW_TAG_imported_unit
18500 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18502 /* Otherwise we skip to the next sibling, if any. */
18503 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18507 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
18510 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
18512 /* This two-pass algorithm for processing partial symbols has a
18513 high cost in cache pressure. Thus, handle some simple cases
18514 here which cover the majority of C partial symbols. DIEs
18515 which neither have specification tags in them, nor could have
18516 specification tags elsewhere pointing at them, can simply be
18517 processed and discarded.
18519 This segment is also optional; scan_partial_symbols and
18520 add_partial_symbol will handle these DIEs if we chain
18521 them in normally. When compilers which do not emit large
18522 quantities of duplicate debug information are more common,
18523 this code can probably be removed. */
18525 /* Any complete simple types at the top level (pretty much all
18526 of them, for a language without namespaces), can be processed
18528 if (parent_die
== NULL
18529 && pdi
.has_specification
== 0
18530 && pdi
.is_declaration
== 0
18531 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
18532 || pdi
.tag
== DW_TAG_base_type
18533 || pdi
.tag
== DW_TAG_subrange_type
))
18535 if (building_psymtab
&& pdi
.name
!= NULL
)
18536 add_psymbol_to_list (pdi
.name
, strlen (pdi
.name
), false,
18537 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
18538 psymbol_placement::STATIC
,
18539 0, cu
->language
, objfile
);
18540 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18544 /* The exception for DW_TAG_typedef with has_children above is
18545 a workaround of GCC PR debug/47510. In the case of this complaint
18546 type_name_or_error will error on such types later.
18548 GDB skipped children of DW_TAG_typedef by the shortcut above and then
18549 it could not find the child DIEs referenced later, this is checked
18550 above. In correct DWARF DW_TAG_typedef should have no children. */
18552 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
18553 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
18554 "- DIE at %s [in module %s]"),
18555 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
18557 /* If we're at the second level, and we're an enumerator, and
18558 our parent has no specification (meaning possibly lives in a
18559 namespace elsewhere), then we can add the partial symbol now
18560 instead of queueing it. */
18561 if (pdi
.tag
== DW_TAG_enumerator
18562 && parent_die
!= NULL
18563 && parent_die
->die_parent
== NULL
18564 && parent_die
->tag
== DW_TAG_enumeration_type
18565 && parent_die
->has_specification
== 0)
18567 if (pdi
.name
== NULL
)
18568 complaint (_("malformed enumerator DIE ignored"));
18569 else if (building_psymtab
)
18570 add_psymbol_to_list (pdi
.name
, strlen (pdi
.name
), false,
18571 VAR_DOMAIN
, LOC_CONST
, -1,
18572 cu
->language
== language_cplus
18573 ? psymbol_placement::GLOBAL
18574 : psymbol_placement::STATIC
,
18575 0, cu
->language
, objfile
);
18577 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18581 struct partial_die_info
*part_die
18582 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
18584 /* We'll save this DIE so link it in. */
18585 part_die
->die_parent
= parent_die
;
18586 part_die
->die_sibling
= NULL
;
18587 part_die
->die_child
= NULL
;
18589 if (last_die
&& last_die
== parent_die
)
18590 last_die
->die_child
= part_die
;
18592 last_die
->die_sibling
= part_die
;
18594 last_die
= part_die
;
18596 if (first_die
== NULL
)
18597 first_die
= part_die
;
18599 /* Maybe add the DIE to the hash table. Not all DIEs that we
18600 find interesting need to be in the hash table, because we
18601 also have the parent/sibling/child chains; only those that we
18602 might refer to by offset later during partial symbol reading.
18604 For now this means things that might have be the target of a
18605 DW_AT_specification, DW_AT_abstract_origin, or
18606 DW_AT_extension. DW_AT_extension will refer only to
18607 namespaces; DW_AT_abstract_origin refers to functions (and
18608 many things under the function DIE, but we do not recurse
18609 into function DIEs during partial symbol reading) and
18610 possibly variables as well; DW_AT_specification refers to
18611 declarations. Declarations ought to have the DW_AT_declaration
18612 flag. It happens that GCC forgets to put it in sometimes, but
18613 only for functions, not for types.
18615 Adding more things than necessary to the hash table is harmless
18616 except for the performance cost. Adding too few will result in
18617 wasted time in find_partial_die, when we reread the compilation
18618 unit with load_all_dies set. */
18621 || abbrev
->tag
== DW_TAG_constant
18622 || abbrev
->tag
== DW_TAG_subprogram
18623 || abbrev
->tag
== DW_TAG_variable
18624 || abbrev
->tag
== DW_TAG_namespace
18625 || part_die
->is_declaration
)
18629 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
18630 to_underlying (part_die
->sect_off
),
18635 /* For some DIEs we want to follow their children (if any). For C
18636 we have no reason to follow the children of structures; for other
18637 languages we have to, so that we can get at method physnames
18638 to infer fully qualified class names, for DW_AT_specification,
18639 and for C++ template arguments. For C++, we also look one level
18640 inside functions to find template arguments (if the name of the
18641 function does not already contain the template arguments).
18643 For Ada, we need to scan the children of subprograms and lexical
18644 blocks as well because Ada allows the definition of nested
18645 entities that could be interesting for the debugger, such as
18646 nested subprograms for instance. */
18647 if (last_die
->has_children
18649 || last_die
->tag
== DW_TAG_namespace
18650 || last_die
->tag
== DW_TAG_module
18651 || last_die
->tag
== DW_TAG_enumeration_type
18652 || (cu
->language
== language_cplus
18653 && last_die
->tag
== DW_TAG_subprogram
18654 && (last_die
->name
== NULL
18655 || strchr (last_die
->name
, '<') == NULL
))
18656 || (cu
->language
!= language_c
18657 && (last_die
->tag
== DW_TAG_class_type
18658 || last_die
->tag
== DW_TAG_interface_type
18659 || last_die
->tag
== DW_TAG_structure_type
18660 || last_die
->tag
== DW_TAG_union_type
))
18661 || (cu
->language
== language_ada
18662 && (last_die
->tag
== DW_TAG_subprogram
18663 || last_die
->tag
== DW_TAG_lexical_block
))))
18666 parent_die
= last_die
;
18670 /* Otherwise we skip to the next sibling, if any. */
18671 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
18673 /* Back to the top, do it again. */
18677 partial_die_info::partial_die_info (sect_offset sect_off_
,
18678 struct abbrev_info
*abbrev
)
18679 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
18683 /* Read a minimal amount of information into the minimal die structure.
18684 INFO_PTR should point just after the initial uleb128 of a DIE. */
18687 partial_die_info::read (const struct die_reader_specs
*reader
,
18688 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
18690 struct dwarf2_cu
*cu
= reader
->cu
;
18691 struct dwarf2_per_objfile
*dwarf2_per_objfile
18692 = cu
->per_cu
->dwarf2_per_objfile
;
18694 int has_low_pc_attr
= 0;
18695 int has_high_pc_attr
= 0;
18696 int high_pc_relative
= 0;
18698 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
18700 struct attribute attr
;
18702 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
], info_ptr
);
18704 /* Store the data if it is of an attribute we want to keep in a
18705 partial symbol table. */
18711 case DW_TAG_compile_unit
:
18712 case DW_TAG_partial_unit
:
18713 case DW_TAG_type_unit
:
18714 /* Compilation units have a DW_AT_name that is a filename, not
18715 a source language identifier. */
18716 case DW_TAG_enumeration_type
:
18717 case DW_TAG_enumerator
:
18718 /* These tags always have simple identifiers already; no need
18719 to canonicalize them. */
18720 name
= DW_STRING (&attr
);
18724 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18727 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
18728 &objfile
->per_bfd
->storage_obstack
);
18733 case DW_AT_linkage_name
:
18734 case DW_AT_MIPS_linkage_name
:
18735 /* Note that both forms of linkage name might appear. We
18736 assume they will be the same, and we only store the last
18738 linkage_name
= DW_STRING (&attr
);
18741 has_low_pc_attr
= 1;
18742 lowpc
= attr_value_as_address (&attr
);
18744 case DW_AT_high_pc
:
18745 has_high_pc_attr
= 1;
18746 highpc
= attr_value_as_address (&attr
);
18747 if (cu
->header
.version
>= 4 && attr_form_is_constant (&attr
))
18748 high_pc_relative
= 1;
18750 case DW_AT_location
:
18751 /* Support the .debug_loc offsets. */
18752 if (attr_form_is_block (&attr
))
18754 d
.locdesc
= DW_BLOCK (&attr
);
18756 else if (attr_form_is_section_offset (&attr
))
18758 dwarf2_complex_location_expr_complaint ();
18762 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18763 "partial symbol information");
18766 case DW_AT_external
:
18767 is_external
= DW_UNSND (&attr
);
18769 case DW_AT_declaration
:
18770 is_declaration
= DW_UNSND (&attr
);
18775 case DW_AT_abstract_origin
:
18776 case DW_AT_specification
:
18777 case DW_AT_extension
:
18778 has_specification
= 1;
18779 spec_offset
= dwarf2_get_ref_die_offset (&attr
);
18780 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18781 || cu
->per_cu
->is_dwz
);
18783 case DW_AT_sibling
:
18784 /* Ignore absolute siblings, they might point outside of
18785 the current compile unit. */
18786 if (attr
.form
== DW_FORM_ref_addr
)
18787 complaint (_("ignoring absolute DW_AT_sibling"));
18790 const gdb_byte
*buffer
= reader
->buffer
;
18791 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
18792 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
18794 if (sibling_ptr
< info_ptr
)
18795 complaint (_("DW_AT_sibling points backwards"));
18796 else if (sibling_ptr
> reader
->buffer_end
)
18797 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
18799 sibling
= sibling_ptr
;
18802 case DW_AT_byte_size
:
18805 case DW_AT_const_value
:
18806 has_const_value
= 1;
18808 case DW_AT_calling_convention
:
18809 /* DWARF doesn't provide a way to identify a program's source-level
18810 entry point. DW_AT_calling_convention attributes are only meant
18811 to describe functions' calling conventions.
18813 However, because it's a necessary piece of information in
18814 Fortran, and before DWARF 4 DW_CC_program was the only
18815 piece of debugging information whose definition refers to
18816 a 'main program' at all, several compilers marked Fortran
18817 main programs with DW_CC_program --- even when those
18818 functions use the standard calling conventions.
18820 Although DWARF now specifies a way to provide this
18821 information, we support this practice for backward
18823 if (DW_UNSND (&attr
) == DW_CC_program
18824 && cu
->language
== language_fortran
)
18825 main_subprogram
= 1;
18828 if (DW_UNSND (&attr
) == DW_INL_inlined
18829 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
18830 may_be_inlined
= 1;
18834 if (tag
== DW_TAG_imported_unit
)
18836 d
.sect_off
= dwarf2_get_ref_die_offset (&attr
);
18837 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18838 || cu
->per_cu
->is_dwz
);
18842 case DW_AT_main_subprogram
:
18843 main_subprogram
= DW_UNSND (&attr
);
18848 /* It would be nice to reuse dwarf2_get_pc_bounds here,
18849 but that requires a full DIE, so instead we just
18851 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
18852 unsigned int ranges_offset
= (DW_UNSND (&attr
)
18853 + (need_ranges_base
18857 /* Value of the DW_AT_ranges attribute is the offset in the
18858 .debug_ranges section. */
18859 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
18870 /* For Ada, if both the name and the linkage name appear, we prefer
18871 the latter. This lets "catch exception" work better, regardless
18872 of the order in which the name and linkage name were emitted.
18873 Really, though, this is just a workaround for the fact that gdb
18874 doesn't store both the name and the linkage name. */
18875 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
18876 name
= linkage_name
;
18878 if (high_pc_relative
)
18881 if (has_low_pc_attr
&& has_high_pc_attr
)
18883 /* When using the GNU linker, .gnu.linkonce. sections are used to
18884 eliminate duplicate copies of functions and vtables and such.
18885 The linker will arbitrarily choose one and discard the others.
18886 The AT_*_pc values for such functions refer to local labels in
18887 these sections. If the section from that file was discarded, the
18888 labels are not in the output, so the relocs get a value of 0.
18889 If this is a discarded function, mark the pc bounds as invalid,
18890 so that GDB will ignore it. */
18891 if (lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
18893 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18894 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18896 complaint (_("DW_AT_low_pc %s is zero "
18897 "for DIE at %s [in module %s]"),
18898 paddress (gdbarch
, lowpc
),
18899 sect_offset_str (sect_off
),
18900 objfile_name (objfile
));
18902 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
18903 else if (lowpc
>= highpc
)
18905 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18906 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18908 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
18909 "for DIE at %s [in module %s]"),
18910 paddress (gdbarch
, lowpc
),
18911 paddress (gdbarch
, highpc
),
18912 sect_offset_str (sect_off
),
18913 objfile_name (objfile
));
18922 /* Find a cached partial DIE at OFFSET in CU. */
18924 struct partial_die_info
*
18925 dwarf2_cu::find_partial_die (sect_offset sect_off
)
18927 struct partial_die_info
*lookup_die
= NULL
;
18928 struct partial_die_info
part_die (sect_off
);
18930 lookup_die
= ((struct partial_die_info
*)
18931 htab_find_with_hash (partial_dies
, &part_die
,
18932 to_underlying (sect_off
)));
18937 /* Find a partial DIE at OFFSET, which may or may not be in CU,
18938 except in the case of .debug_types DIEs which do not reference
18939 outside their CU (they do however referencing other types via
18940 DW_FORM_ref_sig8). */
18942 static const struct cu_partial_die_info
18943 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
18945 struct dwarf2_per_objfile
*dwarf2_per_objfile
18946 = cu
->per_cu
->dwarf2_per_objfile
;
18947 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18948 struct dwarf2_per_cu_data
*per_cu
= NULL
;
18949 struct partial_die_info
*pd
= NULL
;
18951 if (offset_in_dwz
== cu
->per_cu
->is_dwz
18952 && offset_in_cu_p (&cu
->header
, sect_off
))
18954 pd
= cu
->find_partial_die (sect_off
);
18957 /* We missed recording what we needed.
18958 Load all dies and try again. */
18959 per_cu
= cu
->per_cu
;
18963 /* TUs don't reference other CUs/TUs (except via type signatures). */
18964 if (cu
->per_cu
->is_debug_types
)
18966 error (_("Dwarf Error: Type Unit at offset %s contains"
18967 " external reference to offset %s [in module %s].\n"),
18968 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
18969 bfd_get_filename (objfile
->obfd
));
18971 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
18972 dwarf2_per_objfile
);
18974 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
18975 load_partial_comp_unit (per_cu
);
18977 per_cu
->cu
->last_used
= 0;
18978 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18981 /* If we didn't find it, and not all dies have been loaded,
18982 load them all and try again. */
18984 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
18986 per_cu
->load_all_dies
= 1;
18988 /* This is nasty. When we reread the DIEs, somewhere up the call chain
18989 THIS_CU->cu may already be in use. So we can't just free it and
18990 replace its DIEs with the ones we read in. Instead, we leave those
18991 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
18992 and clobber THIS_CU->cu->partial_dies with the hash table for the new
18994 load_partial_comp_unit (per_cu
);
18996 pd
= per_cu
->cu
->find_partial_die (sect_off
);
19000 internal_error (__FILE__
, __LINE__
,
19001 _("could not find partial DIE %s "
19002 "in cache [from module %s]\n"),
19003 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
19004 return { per_cu
->cu
, pd
};
19007 /* See if we can figure out if the class lives in a namespace. We do
19008 this by looking for a member function; its demangled name will
19009 contain namespace info, if there is any. */
19012 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
19013 struct dwarf2_cu
*cu
)
19015 /* NOTE: carlton/2003-10-07: Getting the info this way changes
19016 what template types look like, because the demangler
19017 frequently doesn't give the same name as the debug info. We
19018 could fix this by only using the demangled name to get the
19019 prefix (but see comment in read_structure_type). */
19021 struct partial_die_info
*real_pdi
;
19022 struct partial_die_info
*child_pdi
;
19024 /* If this DIE (this DIE's specification, if any) has a parent, then
19025 we should not do this. We'll prepend the parent's fully qualified
19026 name when we create the partial symbol. */
19028 real_pdi
= struct_pdi
;
19029 while (real_pdi
->has_specification
)
19031 auto res
= find_partial_die (real_pdi
->spec_offset
,
19032 real_pdi
->spec_is_dwz
, cu
);
19033 real_pdi
= res
.pdi
;
19037 if (real_pdi
->die_parent
!= NULL
)
19040 for (child_pdi
= struct_pdi
->die_child
;
19042 child_pdi
= child_pdi
->die_sibling
)
19044 if (child_pdi
->tag
== DW_TAG_subprogram
19045 && child_pdi
->linkage_name
!= NULL
)
19047 char *actual_class_name
19048 = language_class_name_from_physname (cu
->language_defn
,
19049 child_pdi
->linkage_name
);
19050 if (actual_class_name
!= NULL
)
19052 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19054 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
19055 actual_class_name
);
19056 xfree (actual_class_name
);
19064 partial_die_info::fixup (struct dwarf2_cu
*cu
)
19066 /* Once we've fixed up a die, there's no point in doing so again.
19067 This also avoids a memory leak if we were to call
19068 guess_partial_die_structure_name multiple times. */
19072 /* If we found a reference attribute and the DIE has no name, try
19073 to find a name in the referred to DIE. */
19075 if (name
== NULL
&& has_specification
)
19077 struct partial_die_info
*spec_die
;
19079 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19080 spec_die
= res
.pdi
;
19083 spec_die
->fixup (cu
);
19085 if (spec_die
->name
)
19087 name
= spec_die
->name
;
19089 /* Copy DW_AT_external attribute if it is set. */
19090 if (spec_die
->is_external
)
19091 is_external
= spec_die
->is_external
;
19095 /* Set default names for some unnamed DIEs. */
19097 if (name
== NULL
&& tag
== DW_TAG_namespace
)
19098 name
= CP_ANONYMOUS_NAMESPACE_STR
;
19100 /* If there is no parent die to provide a namespace, and there are
19101 children, see if we can determine the namespace from their linkage
19103 if (cu
->language
== language_cplus
19104 && !cu
->per_cu
->dwarf2_per_objfile
->types
.empty ()
19105 && die_parent
== NULL
19107 && (tag
== DW_TAG_class_type
19108 || tag
== DW_TAG_structure_type
19109 || tag
== DW_TAG_union_type
))
19110 guess_partial_die_structure_name (this, cu
);
19112 /* GCC might emit a nameless struct or union that has a linkage
19113 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
19115 && (tag
== DW_TAG_class_type
19116 || tag
== DW_TAG_interface_type
19117 || tag
== DW_TAG_structure_type
19118 || tag
== DW_TAG_union_type
)
19119 && linkage_name
!= NULL
)
19123 demangled
= gdb_demangle (linkage_name
, DMGL_TYPES
);
19128 /* Strip any leading namespaces/classes, keep only the base name.
19129 DW_AT_name for named DIEs does not contain the prefixes. */
19130 base
= strrchr (demangled
, ':');
19131 if (base
&& base
> demangled
&& base
[-1] == ':')
19136 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19137 name
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
, base
);
19145 /* Read an attribute value described by an attribute form. */
19147 static const gdb_byte
*
19148 read_attribute_value (const struct die_reader_specs
*reader
,
19149 struct attribute
*attr
, unsigned form
,
19150 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
19152 struct dwarf2_cu
*cu
= reader
->cu
;
19153 struct dwarf2_per_objfile
*dwarf2_per_objfile
19154 = cu
->per_cu
->dwarf2_per_objfile
;
19155 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19156 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19157 bfd
*abfd
= reader
->abfd
;
19158 struct comp_unit_head
*cu_header
= &cu
->header
;
19159 unsigned int bytes_read
;
19160 struct dwarf_block
*blk
;
19162 attr
->form
= (enum dwarf_form
) form
;
19165 case DW_FORM_ref_addr
:
19166 if (cu
->header
.version
== 2)
19167 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
19169 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
19170 &cu
->header
, &bytes_read
);
19171 info_ptr
+= bytes_read
;
19173 case DW_FORM_GNU_ref_alt
:
19174 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
19175 info_ptr
+= bytes_read
;
19178 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
19179 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
19180 info_ptr
+= bytes_read
;
19182 case DW_FORM_block2
:
19183 blk
= dwarf_alloc_block (cu
);
19184 blk
->size
= read_2_bytes (abfd
, info_ptr
);
19186 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19187 info_ptr
+= blk
->size
;
19188 DW_BLOCK (attr
) = blk
;
19190 case DW_FORM_block4
:
19191 blk
= dwarf_alloc_block (cu
);
19192 blk
->size
= read_4_bytes (abfd
, info_ptr
);
19194 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19195 info_ptr
+= blk
->size
;
19196 DW_BLOCK (attr
) = blk
;
19198 case DW_FORM_data2
:
19199 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
19202 case DW_FORM_data4
:
19203 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
19206 case DW_FORM_data8
:
19207 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
19210 case DW_FORM_data16
:
19211 blk
= dwarf_alloc_block (cu
);
19213 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
19215 DW_BLOCK (attr
) = blk
;
19217 case DW_FORM_sec_offset
:
19218 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
19219 info_ptr
+= bytes_read
;
19221 case DW_FORM_string
:
19222 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
19223 DW_STRING_IS_CANONICAL (attr
) = 0;
19224 info_ptr
+= bytes_read
;
19227 if (!cu
->per_cu
->is_dwz
)
19229 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
19230 abfd
, info_ptr
, cu_header
,
19232 DW_STRING_IS_CANONICAL (attr
) = 0;
19233 info_ptr
+= bytes_read
;
19237 case DW_FORM_line_strp
:
19238 if (!cu
->per_cu
->is_dwz
)
19240 DW_STRING (attr
) = read_indirect_line_string (dwarf2_per_objfile
,
19242 cu_header
, &bytes_read
);
19243 DW_STRING_IS_CANONICAL (attr
) = 0;
19244 info_ptr
+= bytes_read
;
19248 case DW_FORM_GNU_strp_alt
:
19250 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19251 LONGEST str_offset
= read_offset (abfd
, info_ptr
, cu_header
,
19254 DW_STRING (attr
) = read_indirect_string_from_dwz (objfile
,
19256 DW_STRING_IS_CANONICAL (attr
) = 0;
19257 info_ptr
+= bytes_read
;
19260 case DW_FORM_exprloc
:
19261 case DW_FORM_block
:
19262 blk
= dwarf_alloc_block (cu
);
19263 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19264 info_ptr
+= bytes_read
;
19265 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19266 info_ptr
+= blk
->size
;
19267 DW_BLOCK (attr
) = blk
;
19269 case DW_FORM_block1
:
19270 blk
= dwarf_alloc_block (cu
);
19271 blk
->size
= read_1_byte (abfd
, info_ptr
);
19273 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19274 info_ptr
+= blk
->size
;
19275 DW_BLOCK (attr
) = blk
;
19277 case DW_FORM_data1
:
19278 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19282 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19285 case DW_FORM_flag_present
:
19286 DW_UNSND (attr
) = 1;
19288 case DW_FORM_sdata
:
19289 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19290 info_ptr
+= bytes_read
;
19292 case DW_FORM_udata
:
19293 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19294 info_ptr
+= bytes_read
;
19297 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19298 + read_1_byte (abfd
, info_ptr
));
19302 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19303 + read_2_bytes (abfd
, info_ptr
));
19307 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19308 + read_4_bytes (abfd
, info_ptr
));
19312 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19313 + read_8_bytes (abfd
, info_ptr
));
19316 case DW_FORM_ref_sig8
:
19317 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
19320 case DW_FORM_ref_udata
:
19321 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19322 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
19323 info_ptr
+= bytes_read
;
19325 case DW_FORM_indirect
:
19326 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19327 info_ptr
+= bytes_read
;
19328 if (form
== DW_FORM_implicit_const
)
19330 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19331 info_ptr
+= bytes_read
;
19333 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
19336 case DW_FORM_implicit_const
:
19337 DW_SND (attr
) = implicit_const
;
19339 case DW_FORM_addrx
:
19340 case DW_FORM_GNU_addr_index
:
19341 if (reader
->dwo_file
== NULL
)
19343 /* For now flag a hard error.
19344 Later we can turn this into a complaint. */
19345 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
19346 dwarf_form_name (form
),
19347 bfd_get_filename (abfd
));
19349 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
19350 info_ptr
+= bytes_read
;
19353 case DW_FORM_strx1
:
19354 case DW_FORM_strx2
:
19355 case DW_FORM_strx3
:
19356 case DW_FORM_strx4
:
19357 case DW_FORM_GNU_str_index
:
19358 if (reader
->dwo_file
== NULL
)
19360 /* For now flag a hard error.
19361 Later we can turn this into a complaint if warranted. */
19362 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
19363 dwarf_form_name (form
),
19364 bfd_get_filename (abfd
));
19367 ULONGEST str_index
;
19368 if (form
== DW_FORM_strx1
)
19370 str_index
= read_1_byte (abfd
, info_ptr
);
19373 else if (form
== DW_FORM_strx2
)
19375 str_index
= read_2_bytes (abfd
, info_ptr
);
19378 else if (form
== DW_FORM_strx3
)
19380 str_index
= read_3_bytes (abfd
, info_ptr
);
19383 else if (form
== DW_FORM_strx4
)
19385 str_index
= read_4_bytes (abfd
, info_ptr
);
19390 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19391 info_ptr
+= bytes_read
;
19393 DW_STRING (attr
) = read_str_index (reader
, str_index
);
19394 DW_STRING_IS_CANONICAL (attr
) = 0;
19398 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
19399 dwarf_form_name (form
),
19400 bfd_get_filename (abfd
));
19404 if (cu
->per_cu
->is_dwz
&& attr_form_is_ref (attr
))
19405 attr
->form
= DW_FORM_GNU_ref_alt
;
19407 /* We have seen instances where the compiler tried to emit a byte
19408 size attribute of -1 which ended up being encoded as an unsigned
19409 0xffffffff. Although 0xffffffff is technically a valid size value,
19410 an object of this size seems pretty unlikely so we can relatively
19411 safely treat these cases as if the size attribute was invalid and
19412 treat them as zero by default. */
19413 if (attr
->name
== DW_AT_byte_size
19414 && form
== DW_FORM_data4
19415 && DW_UNSND (attr
) >= 0xffffffff)
19418 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
19419 hex_string (DW_UNSND (attr
)));
19420 DW_UNSND (attr
) = 0;
19426 /* Read an attribute described by an abbreviated attribute. */
19428 static const gdb_byte
*
19429 read_attribute (const struct die_reader_specs
*reader
,
19430 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
19431 const gdb_byte
*info_ptr
)
19433 attr
->name
= abbrev
->name
;
19434 return read_attribute_value (reader
, attr
, abbrev
->form
,
19435 abbrev
->implicit_const
, info_ptr
);
19438 /* Read dwarf information from a buffer. */
19440 static unsigned int
19441 read_1_byte (bfd
*abfd
, const gdb_byte
*buf
)
19443 return bfd_get_8 (abfd
, buf
);
19447 read_1_signed_byte (bfd
*abfd
, const gdb_byte
*buf
)
19449 return bfd_get_signed_8 (abfd
, buf
);
19452 static unsigned int
19453 read_2_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19455 return bfd_get_16 (abfd
, buf
);
19459 read_2_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19461 return bfd_get_signed_16 (abfd
, buf
);
19464 static unsigned int
19465 read_3_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19467 unsigned int result
= 0;
19468 for (int i
= 0; i
< 3; ++i
)
19470 unsigned char byte
= bfd_get_8 (abfd
, buf
);
19472 result
|= ((unsigned int) byte
<< (i
* 8));
19477 static unsigned int
19478 read_4_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19480 return bfd_get_32 (abfd
, buf
);
19484 read_4_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19486 return bfd_get_signed_32 (abfd
, buf
);
19490 read_8_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19492 return bfd_get_64 (abfd
, buf
);
19496 read_address (bfd
*abfd
, const gdb_byte
*buf
, struct dwarf2_cu
*cu
,
19497 unsigned int *bytes_read
)
19499 struct comp_unit_head
*cu_header
= &cu
->header
;
19500 CORE_ADDR retval
= 0;
19502 if (cu_header
->signed_addr_p
)
19504 switch (cu_header
->addr_size
)
19507 retval
= bfd_get_signed_16 (abfd
, buf
);
19510 retval
= bfd_get_signed_32 (abfd
, buf
);
19513 retval
= bfd_get_signed_64 (abfd
, buf
);
19516 internal_error (__FILE__
, __LINE__
,
19517 _("read_address: bad switch, signed [in module %s]"),
19518 bfd_get_filename (abfd
));
19523 switch (cu_header
->addr_size
)
19526 retval
= bfd_get_16 (abfd
, buf
);
19529 retval
= bfd_get_32 (abfd
, buf
);
19532 retval
= bfd_get_64 (abfd
, buf
);
19535 internal_error (__FILE__
, __LINE__
,
19536 _("read_address: bad switch, "
19537 "unsigned [in module %s]"),
19538 bfd_get_filename (abfd
));
19542 *bytes_read
= cu_header
->addr_size
;
19546 /* Read the initial length from a section. The (draft) DWARF 3
19547 specification allows the initial length to take up either 4 bytes
19548 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
19549 bytes describe the length and all offsets will be 8 bytes in length
19552 An older, non-standard 64-bit format is also handled by this
19553 function. The older format in question stores the initial length
19554 as an 8-byte quantity without an escape value. Lengths greater
19555 than 2^32 aren't very common which means that the initial 4 bytes
19556 is almost always zero. Since a length value of zero doesn't make
19557 sense for the 32-bit format, this initial zero can be considered to
19558 be an escape value which indicates the presence of the older 64-bit
19559 format. As written, the code can't detect (old format) lengths
19560 greater than 4GB. If it becomes necessary to handle lengths
19561 somewhat larger than 4GB, we could allow other small values (such
19562 as the non-sensical values of 1, 2, and 3) to also be used as
19563 escape values indicating the presence of the old format.
19565 The value returned via bytes_read should be used to increment the
19566 relevant pointer after calling read_initial_length().
19568 [ Note: read_initial_length() and read_offset() are based on the
19569 document entitled "DWARF Debugging Information Format", revision
19570 3, draft 8, dated November 19, 2001. This document was obtained
19573 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
19575 This document is only a draft and is subject to change. (So beware.)
19577 Details regarding the older, non-standard 64-bit format were
19578 determined empirically by examining 64-bit ELF files produced by
19579 the SGI toolchain on an IRIX 6.5 machine.
19581 - Kevin, July 16, 2002
19585 read_initial_length (bfd
*abfd
, const gdb_byte
*buf
, unsigned int *bytes_read
)
19587 LONGEST length
= bfd_get_32 (abfd
, buf
);
19589 if (length
== 0xffffffff)
19591 length
= bfd_get_64 (abfd
, buf
+ 4);
19594 else if (length
== 0)
19596 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
19597 length
= bfd_get_64 (abfd
, buf
);
19608 /* Cover function for read_initial_length.
19609 Returns the length of the object at BUF, and stores the size of the
19610 initial length in *BYTES_READ and stores the size that offsets will be in
19612 If the initial length size is not equivalent to that specified in
19613 CU_HEADER then issue a complaint.
19614 This is useful when reading non-comp-unit headers. */
19617 read_checked_initial_length_and_offset (bfd
*abfd
, const gdb_byte
*buf
,
19618 const struct comp_unit_head
*cu_header
,
19619 unsigned int *bytes_read
,
19620 unsigned int *offset_size
)
19622 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
19624 gdb_assert (cu_header
->initial_length_size
== 4
19625 || cu_header
->initial_length_size
== 8
19626 || cu_header
->initial_length_size
== 12);
19628 if (cu_header
->initial_length_size
!= *bytes_read
)
19629 complaint (_("intermixed 32-bit and 64-bit DWARF sections"));
19631 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
19635 /* Read an offset from the data stream. The size of the offset is
19636 given by cu_header->offset_size. */
19639 read_offset (bfd
*abfd
, const gdb_byte
*buf
,
19640 const struct comp_unit_head
*cu_header
,
19641 unsigned int *bytes_read
)
19643 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
19645 *bytes_read
= cu_header
->offset_size
;
19649 /* Read an offset from the data stream. */
19652 read_offset_1 (bfd
*abfd
, const gdb_byte
*buf
, unsigned int offset_size
)
19654 LONGEST retval
= 0;
19656 switch (offset_size
)
19659 retval
= bfd_get_32 (abfd
, buf
);
19662 retval
= bfd_get_64 (abfd
, buf
);
19665 internal_error (__FILE__
, __LINE__
,
19666 _("read_offset_1: bad switch [in module %s]"),
19667 bfd_get_filename (abfd
));
19673 static const gdb_byte
*
19674 read_n_bytes (bfd
*abfd
, const gdb_byte
*buf
, unsigned int size
)
19676 /* If the size of a host char is 8 bits, we can return a pointer
19677 to the buffer, otherwise we have to copy the data to a buffer
19678 allocated on the temporary obstack. */
19679 gdb_assert (HOST_CHAR_BIT
== 8);
19683 static const char *
19684 read_direct_string (bfd
*abfd
, const gdb_byte
*buf
,
19685 unsigned int *bytes_read_ptr
)
19687 /* If the size of a host char is 8 bits, we can return a pointer
19688 to the string, otherwise we have to copy the string to a buffer
19689 allocated on the temporary obstack. */
19690 gdb_assert (HOST_CHAR_BIT
== 8);
19693 *bytes_read_ptr
= 1;
19696 *bytes_read_ptr
= strlen ((const char *) buf
) + 1;
19697 return (const char *) buf
;
19700 /* Return pointer to string at section SECT offset STR_OFFSET with error
19701 reporting strings FORM_NAME and SECT_NAME. */
19703 static const char *
19704 read_indirect_string_at_offset_from (struct objfile
*objfile
,
19705 bfd
*abfd
, LONGEST str_offset
,
19706 struct dwarf2_section_info
*sect
,
19707 const char *form_name
,
19708 const char *sect_name
)
19710 dwarf2_read_section (objfile
, sect
);
19711 if (sect
->buffer
== NULL
)
19712 error (_("%s used without %s section [in module %s]"),
19713 form_name
, sect_name
, bfd_get_filename (abfd
));
19714 if (str_offset
>= sect
->size
)
19715 error (_("%s pointing outside of %s section [in module %s]"),
19716 form_name
, sect_name
, bfd_get_filename (abfd
));
19717 gdb_assert (HOST_CHAR_BIT
== 8);
19718 if (sect
->buffer
[str_offset
] == '\0')
19720 return (const char *) (sect
->buffer
+ str_offset
);
19723 /* Return pointer to string at .debug_str offset STR_OFFSET. */
19725 static const char *
19726 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19727 bfd
*abfd
, LONGEST str_offset
)
19729 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
19731 &dwarf2_per_objfile
->str
,
19732 "DW_FORM_strp", ".debug_str");
19735 /* Return pointer to string at .debug_line_str offset STR_OFFSET. */
19737 static const char *
19738 read_indirect_line_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19739 bfd
*abfd
, LONGEST str_offset
)
19741 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
19743 &dwarf2_per_objfile
->line_str
,
19744 "DW_FORM_line_strp",
19745 ".debug_line_str");
19748 /* Read a string at offset STR_OFFSET in the .debug_str section from
19749 the .dwz file DWZ. Throw an error if the offset is too large. If
19750 the string consists of a single NUL byte, return NULL; otherwise
19751 return a pointer to the string. */
19753 static const char *
19754 read_indirect_string_from_dwz (struct objfile
*objfile
, struct dwz_file
*dwz
,
19755 LONGEST str_offset
)
19757 dwarf2_read_section (objfile
, &dwz
->str
);
19759 if (dwz
->str
.buffer
== NULL
)
19760 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
19761 "section [in module %s]"),
19762 bfd_get_filename (dwz
->dwz_bfd
.get ()));
19763 if (str_offset
>= dwz
->str
.size
)
19764 error (_("DW_FORM_GNU_strp_alt pointing outside of "
19765 ".debug_str section [in module %s]"),
19766 bfd_get_filename (dwz
->dwz_bfd
.get ()));
19767 gdb_assert (HOST_CHAR_BIT
== 8);
19768 if (dwz
->str
.buffer
[str_offset
] == '\0')
19770 return (const char *) (dwz
->str
.buffer
+ str_offset
);
19773 /* Return pointer to string at .debug_str offset as read from BUF.
19774 BUF is assumed to be in a compilation unit described by CU_HEADER.
19775 Return *BYTES_READ_PTR count of bytes read from BUF. */
19777 static const char *
19778 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
19779 const gdb_byte
*buf
,
19780 const struct comp_unit_head
*cu_header
,
19781 unsigned int *bytes_read_ptr
)
19783 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
19785 return read_indirect_string_at_offset (dwarf2_per_objfile
, abfd
, str_offset
);
19788 /* Return pointer to string at .debug_line_str offset as read from BUF.
19789 BUF is assumed to be in a compilation unit described by CU_HEADER.
19790 Return *BYTES_READ_PTR count of bytes read from BUF. */
19792 static const char *
19793 read_indirect_line_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19794 bfd
*abfd
, const gdb_byte
*buf
,
19795 const struct comp_unit_head
*cu_header
,
19796 unsigned int *bytes_read_ptr
)
19798 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
19800 return read_indirect_line_string_at_offset (dwarf2_per_objfile
, abfd
,
19805 read_unsigned_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
19806 unsigned int *bytes_read_ptr
)
19809 unsigned int num_read
;
19811 unsigned char byte
;
19818 byte
= bfd_get_8 (abfd
, buf
);
19821 result
|= ((ULONGEST
) (byte
& 127) << shift
);
19822 if ((byte
& 128) == 0)
19828 *bytes_read_ptr
= num_read
;
19833 read_signed_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
19834 unsigned int *bytes_read_ptr
)
19837 int shift
, num_read
;
19838 unsigned char byte
;
19845 byte
= bfd_get_8 (abfd
, buf
);
19848 result
|= ((ULONGEST
) (byte
& 127) << shift
);
19850 if ((byte
& 128) == 0)
19855 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
19856 result
|= -(((ULONGEST
) 1) << shift
);
19857 *bytes_read_ptr
= num_read
;
19861 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
19862 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
19863 ADDR_SIZE is the size of addresses from the CU header. */
19866 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19867 unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
19869 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19870 bfd
*abfd
= objfile
->obfd
;
19871 const gdb_byte
*info_ptr
;
19873 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
19874 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
19875 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
19876 objfile_name (objfile
));
19877 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
19878 error (_("DW_FORM_addr_index pointing outside of "
19879 ".debug_addr section [in module %s]"),
19880 objfile_name (objfile
));
19881 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
19882 + addr_base
+ addr_index
* addr_size
);
19883 if (addr_size
== 4)
19884 return bfd_get_32 (abfd
, info_ptr
);
19886 return bfd_get_64 (abfd
, info_ptr
);
19889 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
19892 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
19894 return read_addr_index_1 (cu
->per_cu
->dwarf2_per_objfile
, addr_index
,
19895 cu
->addr_base
, cu
->header
.addr_size
);
19898 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
19901 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
19902 unsigned int *bytes_read
)
19904 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
19905 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
19907 return read_addr_index (cu
, addr_index
);
19910 /* Data structure to pass results from dwarf2_read_addr_index_reader
19911 back to dwarf2_read_addr_index. */
19913 struct dwarf2_read_addr_index_data
19915 ULONGEST addr_base
;
19919 /* die_reader_func for dwarf2_read_addr_index. */
19922 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
19923 const gdb_byte
*info_ptr
,
19924 struct die_info
*comp_unit_die
,
19928 struct dwarf2_cu
*cu
= reader
->cu
;
19929 struct dwarf2_read_addr_index_data
*aidata
=
19930 (struct dwarf2_read_addr_index_data
*) data
;
19932 aidata
->addr_base
= cu
->addr_base
;
19933 aidata
->addr_size
= cu
->header
.addr_size
;
19936 /* Given an index in .debug_addr, fetch the value.
19937 NOTE: This can be called during dwarf expression evaluation,
19938 long after the debug information has been read, and thus per_cu->cu
19939 may no longer exist. */
19942 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
19943 unsigned int addr_index
)
19945 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
19946 struct dwarf2_cu
*cu
= per_cu
->cu
;
19947 ULONGEST addr_base
;
19950 /* We need addr_base and addr_size.
19951 If we don't have PER_CU->cu, we have to get it.
19952 Nasty, but the alternative is storing the needed info in PER_CU,
19953 which at this point doesn't seem justified: it's not clear how frequently
19954 it would get used and it would increase the size of every PER_CU.
19955 Entry points like dwarf2_per_cu_addr_size do a similar thing
19956 so we're not in uncharted territory here.
19957 Alas we need to be a bit more complicated as addr_base is contained
19960 We don't need to read the entire CU(/TU).
19961 We just need the header and top level die.
19963 IWBN to use the aging mechanism to let us lazily later discard the CU.
19964 For now we skip this optimization. */
19968 addr_base
= cu
->addr_base
;
19969 addr_size
= cu
->header
.addr_size
;
19973 struct dwarf2_read_addr_index_data aidata
;
19975 /* Note: We can't use init_cutu_and_read_dies_simple here,
19976 we need addr_base. */
19977 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0, false,
19978 dwarf2_read_addr_index_reader
, &aidata
);
19979 addr_base
= aidata
.addr_base
;
19980 addr_size
= aidata
.addr_size
;
19983 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
19987 /* Given a DW_FORM_GNU_str_index or DW_FORM_strx, fetch the string.
19988 This is only used by the Fission support. */
19990 static const char *
19991 read_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
19993 struct dwarf2_cu
*cu
= reader
->cu
;
19994 struct dwarf2_per_objfile
*dwarf2_per_objfile
19995 = cu
->per_cu
->dwarf2_per_objfile
;
19996 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19997 const char *objf_name
= objfile_name (objfile
);
19998 bfd
*abfd
= objfile
->obfd
;
19999 struct dwarf2_section_info
*str_section
= &reader
->dwo_file
->sections
.str
;
20000 struct dwarf2_section_info
*str_offsets_section
=
20001 &reader
->dwo_file
->sections
.str_offsets
;
20002 const gdb_byte
*info_ptr
;
20003 ULONGEST str_offset
;
20004 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
20006 dwarf2_read_section (objfile
, str_section
);
20007 dwarf2_read_section (objfile
, str_offsets_section
);
20008 if (str_section
->buffer
== NULL
)
20009 error (_("%s used without .debug_str.dwo section"
20010 " in CU at offset %s [in module %s]"),
20011 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20012 if (str_offsets_section
->buffer
== NULL
)
20013 error (_("%s used without .debug_str_offsets.dwo section"
20014 " in CU at offset %s [in module %s]"),
20015 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20016 if (str_index
* cu
->header
.offset_size
>= str_offsets_section
->size
)
20017 error (_("%s pointing outside of .debug_str_offsets.dwo"
20018 " section in CU at offset %s [in module %s]"),
20019 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20020 info_ptr
= (str_offsets_section
->buffer
20021 + str_index
* cu
->header
.offset_size
);
20022 if (cu
->header
.offset_size
== 4)
20023 str_offset
= bfd_get_32 (abfd
, info_ptr
);
20025 str_offset
= bfd_get_64 (abfd
, info_ptr
);
20026 if (str_offset
>= str_section
->size
)
20027 error (_("Offset from %s pointing outside of"
20028 " .debug_str.dwo section in CU at offset %s [in module %s]"),
20029 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20030 return (const char *) (str_section
->buffer
+ str_offset
);
20033 /* Return the length of an LEB128 number in BUF. */
20036 leb128_size (const gdb_byte
*buf
)
20038 const gdb_byte
*begin
= buf
;
20044 if ((byte
& 128) == 0)
20045 return buf
- begin
;
20050 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
20059 cu
->language
= language_c
;
20062 case DW_LANG_C_plus_plus
:
20063 case DW_LANG_C_plus_plus_11
:
20064 case DW_LANG_C_plus_plus_14
:
20065 cu
->language
= language_cplus
;
20068 cu
->language
= language_d
;
20070 case DW_LANG_Fortran77
:
20071 case DW_LANG_Fortran90
:
20072 case DW_LANG_Fortran95
:
20073 case DW_LANG_Fortran03
:
20074 case DW_LANG_Fortran08
:
20075 cu
->language
= language_fortran
;
20078 cu
->language
= language_go
;
20080 case DW_LANG_Mips_Assembler
:
20081 cu
->language
= language_asm
;
20083 case DW_LANG_Ada83
:
20084 case DW_LANG_Ada95
:
20085 cu
->language
= language_ada
;
20087 case DW_LANG_Modula2
:
20088 cu
->language
= language_m2
;
20090 case DW_LANG_Pascal83
:
20091 cu
->language
= language_pascal
;
20094 cu
->language
= language_objc
;
20097 case DW_LANG_Rust_old
:
20098 cu
->language
= language_rust
;
20100 case DW_LANG_Cobol74
:
20101 case DW_LANG_Cobol85
:
20103 cu
->language
= language_minimal
;
20106 cu
->language_defn
= language_def (cu
->language
);
20109 /* Return the named attribute or NULL if not there. */
20111 static struct attribute
*
20112 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20117 struct attribute
*spec
= NULL
;
20119 for (i
= 0; i
< die
->num_attrs
; ++i
)
20121 if (die
->attrs
[i
].name
== name
)
20122 return &die
->attrs
[i
];
20123 if (die
->attrs
[i
].name
== DW_AT_specification
20124 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
20125 spec
= &die
->attrs
[i
];
20131 die
= follow_die_ref (die
, spec
, &cu
);
20137 /* Return the named attribute or NULL if not there,
20138 but do not follow DW_AT_specification, etc.
20139 This is for use in contexts where we're reading .debug_types dies.
20140 Following DW_AT_specification, DW_AT_abstract_origin will take us
20141 back up the chain, and we want to go down. */
20143 static struct attribute
*
20144 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
20148 for (i
= 0; i
< die
->num_attrs
; ++i
)
20149 if (die
->attrs
[i
].name
== name
)
20150 return &die
->attrs
[i
];
20155 /* Return the string associated with a string-typed attribute, or NULL if it
20156 is either not found or is of an incorrect type. */
20158 static const char *
20159 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20161 struct attribute
*attr
;
20162 const char *str
= NULL
;
20164 attr
= dwarf2_attr (die
, name
, cu
);
20168 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
20169 || attr
->form
== DW_FORM_string
20170 || attr
->form
== DW_FORM_strx
20171 || attr
->form
== DW_FORM_GNU_str_index
20172 || attr
->form
== DW_FORM_GNU_strp_alt
)
20173 str
= DW_STRING (attr
);
20175 complaint (_("string type expected for attribute %s for "
20176 "DIE at %s in module %s"),
20177 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
20178 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
20184 /* Return the dwo name or NULL if not present. If present, it is in either
20185 DW_AT_GNU_dwo_name or DW_AT_dwo_name atrribute. */
20186 static const char *
20187 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
20189 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
20190 if (dwo_name
== nullptr)
20191 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
20195 /* Return non-zero iff the attribute NAME is defined for the given DIE,
20196 and holds a non-zero value. This function should only be used for
20197 DW_FORM_flag or DW_FORM_flag_present attributes. */
20200 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
20202 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
20204 return (attr
&& DW_UNSND (attr
));
20208 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
20210 /* A DIE is a declaration if it has a DW_AT_declaration attribute
20211 which value is non-zero. However, we have to be careful with
20212 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
20213 (via dwarf2_flag_true_p) follows this attribute. So we may
20214 end up accidently finding a declaration attribute that belongs
20215 to a different DIE referenced by the specification attribute,
20216 even though the given DIE does not have a declaration attribute. */
20217 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
20218 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
20221 /* Return the die giving the specification for DIE, if there is
20222 one. *SPEC_CU is the CU containing DIE on input, and the CU
20223 containing the return value on output. If there is no
20224 specification, but there is an abstract origin, that is
20227 static struct die_info
*
20228 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
20230 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
20233 if (spec_attr
== NULL
)
20234 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
20236 if (spec_attr
== NULL
)
20239 return follow_die_ref (die
, spec_attr
, spec_cu
);
20242 /* Stub for free_line_header to match void * callback types. */
20245 free_line_header_voidp (void *arg
)
20247 struct line_header
*lh
= (struct line_header
*) arg
;
20253 line_header::add_include_dir (const char *include_dir
)
20255 if (dwarf_line_debug
>= 2)
20256 fprintf_unfiltered (gdb_stdlog
, "Adding dir %zu: %s\n",
20257 include_dirs
.size () + 1, include_dir
);
20259 include_dirs
.push_back (include_dir
);
20263 line_header::add_file_name (const char *name
,
20265 unsigned int mod_time
,
20266 unsigned int length
)
20268 if (dwarf_line_debug
>= 2)
20269 fprintf_unfiltered (gdb_stdlog
, "Adding file %u: %s\n",
20270 (unsigned) file_names
.size () + 1, name
);
20272 file_names
.emplace_back (name
, d_index
, mod_time
, length
);
20275 /* A convenience function to find the proper .debug_line section for a CU. */
20277 static struct dwarf2_section_info
*
20278 get_debug_line_section (struct dwarf2_cu
*cu
)
20280 struct dwarf2_section_info
*section
;
20281 struct dwarf2_per_objfile
*dwarf2_per_objfile
20282 = cu
->per_cu
->dwarf2_per_objfile
;
20284 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
20286 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20287 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
20288 else if (cu
->per_cu
->is_dwz
)
20290 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
20292 section
= &dwz
->line
;
20295 section
= &dwarf2_per_objfile
->line
;
20300 /* Read directory or file name entry format, starting with byte of
20301 format count entries, ULEB128 pairs of entry formats, ULEB128 of
20302 entries count and the entries themselves in the described entry
20306 read_formatted_entries (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20307 bfd
*abfd
, const gdb_byte
**bufp
,
20308 struct line_header
*lh
,
20309 const struct comp_unit_head
*cu_header
,
20310 void (*callback
) (struct line_header
*lh
,
20313 unsigned int mod_time
,
20314 unsigned int length
))
20316 gdb_byte format_count
, formati
;
20317 ULONGEST data_count
, datai
;
20318 const gdb_byte
*buf
= *bufp
;
20319 const gdb_byte
*format_header_data
;
20320 unsigned int bytes_read
;
20322 format_count
= read_1_byte (abfd
, buf
);
20324 format_header_data
= buf
;
20325 for (formati
= 0; formati
< format_count
; formati
++)
20327 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20329 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20333 data_count
= read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20335 for (datai
= 0; datai
< data_count
; datai
++)
20337 const gdb_byte
*format
= format_header_data
;
20338 struct file_entry fe
;
20340 for (formati
= 0; formati
< format_count
; formati
++)
20342 ULONGEST content_type
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20343 format
+= bytes_read
;
20345 ULONGEST form
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20346 format
+= bytes_read
;
20348 gdb::optional
<const char *> string
;
20349 gdb::optional
<unsigned int> uint
;
20353 case DW_FORM_string
:
20354 string
.emplace (read_direct_string (abfd
, buf
, &bytes_read
));
20358 case DW_FORM_line_strp
:
20359 string
.emplace (read_indirect_line_string (dwarf2_per_objfile
,
20366 case DW_FORM_data1
:
20367 uint
.emplace (read_1_byte (abfd
, buf
));
20371 case DW_FORM_data2
:
20372 uint
.emplace (read_2_bytes (abfd
, buf
));
20376 case DW_FORM_data4
:
20377 uint
.emplace (read_4_bytes (abfd
, buf
));
20381 case DW_FORM_data8
:
20382 uint
.emplace (read_8_bytes (abfd
, buf
));
20386 case DW_FORM_udata
:
20387 uint
.emplace (read_unsigned_leb128 (abfd
, buf
, &bytes_read
));
20391 case DW_FORM_block
:
20392 /* It is valid only for DW_LNCT_timestamp which is ignored by
20397 switch (content_type
)
20400 if (string
.has_value ())
20403 case DW_LNCT_directory_index
:
20404 if (uint
.has_value ())
20405 fe
.d_index
= (dir_index
) *uint
;
20407 case DW_LNCT_timestamp
:
20408 if (uint
.has_value ())
20409 fe
.mod_time
= *uint
;
20412 if (uint
.has_value ())
20418 complaint (_("Unknown format content type %s"),
20419 pulongest (content_type
));
20423 callback (lh
, fe
.name
, fe
.d_index
, fe
.mod_time
, fe
.length
);
20429 /* Read the statement program header starting at OFFSET in
20430 .debug_line, or .debug_line.dwo. Return a pointer
20431 to a struct line_header, allocated using xmalloc.
20432 Returns NULL if there is a problem reading the header, e.g., if it
20433 has a version we don't understand.
20435 NOTE: the strings in the include directory and file name tables of
20436 the returned object point into the dwarf line section buffer,
20437 and must not be freed. */
20439 static line_header_up
20440 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
20442 const gdb_byte
*line_ptr
;
20443 unsigned int bytes_read
, offset_size
;
20445 const char *cur_dir
, *cur_file
;
20446 struct dwarf2_section_info
*section
;
20448 struct dwarf2_per_objfile
*dwarf2_per_objfile
20449 = cu
->per_cu
->dwarf2_per_objfile
;
20451 section
= get_debug_line_section (cu
);
20452 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
20453 if (section
->buffer
== NULL
)
20455 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20456 complaint (_("missing .debug_line.dwo section"));
20458 complaint (_("missing .debug_line section"));
20462 /* We can't do this until we know the section is non-empty.
20463 Only then do we know we have such a section. */
20464 abfd
= get_section_bfd_owner (section
);
20466 /* Make sure that at least there's room for the total_length field.
20467 That could be 12 bytes long, but we're just going to fudge that. */
20468 if (to_underlying (sect_off
) + 4 >= section
->size
)
20470 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20474 line_header_up
lh (new line_header ());
20476 lh
->sect_off
= sect_off
;
20477 lh
->offset_in_dwz
= cu
->per_cu
->is_dwz
;
20479 line_ptr
= section
->buffer
+ to_underlying (sect_off
);
20481 /* Read in the header. */
20483 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
20484 &bytes_read
, &offset_size
);
20485 line_ptr
+= bytes_read
;
20486 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
20488 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20491 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
20492 lh
->version
= read_2_bytes (abfd
, line_ptr
);
20494 if (lh
->version
> 5)
20496 /* This is a version we don't understand. The format could have
20497 changed in ways we don't handle properly so just punt. */
20498 complaint (_("unsupported version in .debug_line section"));
20501 if (lh
->version
>= 5)
20503 gdb_byte segment_selector_size
;
20505 /* Skip address size. */
20506 read_1_byte (abfd
, line_ptr
);
20509 segment_selector_size
= read_1_byte (abfd
, line_ptr
);
20511 if (segment_selector_size
!= 0)
20513 complaint (_("unsupported segment selector size %u "
20514 "in .debug_line section"),
20515 segment_selector_size
);
20519 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
20520 line_ptr
+= offset_size
;
20521 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
20523 if (lh
->version
>= 4)
20525 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
20529 lh
->maximum_ops_per_instruction
= 1;
20531 if (lh
->maximum_ops_per_instruction
== 0)
20533 lh
->maximum_ops_per_instruction
= 1;
20534 complaint (_("invalid maximum_ops_per_instruction "
20535 "in `.debug_line' section"));
20538 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
20540 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
20542 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
20544 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
20546 lh
->standard_opcode_lengths
.reset (new unsigned char[lh
->opcode_base
]);
20548 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
20549 for (i
= 1; i
< lh
->opcode_base
; ++i
)
20551 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
20555 if (lh
->version
>= 5)
20557 /* Read directory table. */
20558 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20560 [] (struct line_header
*header
, const char *name
,
20561 dir_index d_index
, unsigned int mod_time
,
20562 unsigned int length
)
20564 header
->add_include_dir (name
);
20567 /* Read file name table. */
20568 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20570 [] (struct line_header
*header
, const char *name
,
20571 dir_index d_index
, unsigned int mod_time
,
20572 unsigned int length
)
20574 header
->add_file_name (name
, d_index
, mod_time
, length
);
20579 /* Read directory table. */
20580 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20582 line_ptr
+= bytes_read
;
20583 lh
->add_include_dir (cur_dir
);
20585 line_ptr
+= bytes_read
;
20587 /* Read file name table. */
20588 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20590 unsigned int mod_time
, length
;
20593 line_ptr
+= bytes_read
;
20594 d_index
= (dir_index
) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20595 line_ptr
+= bytes_read
;
20596 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20597 line_ptr
+= bytes_read
;
20598 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20599 line_ptr
+= bytes_read
;
20601 lh
->add_file_name (cur_file
, d_index
, mod_time
, length
);
20603 line_ptr
+= bytes_read
;
20605 lh
->statement_program_start
= line_ptr
;
20607 if (line_ptr
> (section
->buffer
+ section
->size
))
20608 complaint (_("line number info header doesn't "
20609 "fit in `.debug_line' section"));
20614 /* Subroutine of dwarf_decode_lines to simplify it.
20615 Return the file name of the psymtab for included file FILE_INDEX
20616 in line header LH of PST.
20617 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20618 If space for the result is malloc'd, *NAME_HOLDER will be set.
20619 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
20621 static const char *
20622 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
20623 const struct partial_symtab
*pst
,
20624 const char *comp_dir
,
20625 gdb::unique_xmalloc_ptr
<char> *name_holder
)
20627 const file_entry
&fe
= lh
->file_names
[file_index
];
20628 const char *include_name
= fe
.name
;
20629 const char *include_name_to_compare
= include_name
;
20630 const char *pst_filename
;
20633 const char *dir_name
= fe
.include_dir (lh
);
20635 gdb::unique_xmalloc_ptr
<char> hold_compare
;
20636 if (!IS_ABSOLUTE_PATH (include_name
)
20637 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
20639 /* Avoid creating a duplicate psymtab for PST.
20640 We do this by comparing INCLUDE_NAME and PST_FILENAME.
20641 Before we do the comparison, however, we need to account
20642 for DIR_NAME and COMP_DIR.
20643 First prepend dir_name (if non-NULL). If we still don't
20644 have an absolute path prepend comp_dir (if non-NULL).
20645 However, the directory we record in the include-file's
20646 psymtab does not contain COMP_DIR (to match the
20647 corresponding symtab(s)).
20652 bash$ gcc -g ./hello.c
20653 include_name = "hello.c"
20655 DW_AT_comp_dir = comp_dir = "/tmp"
20656 DW_AT_name = "./hello.c"
20660 if (dir_name
!= NULL
)
20662 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
20663 include_name
, (char *) NULL
));
20664 include_name
= name_holder
->get ();
20665 include_name_to_compare
= include_name
;
20667 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
20669 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
20670 include_name
, (char *) NULL
));
20671 include_name_to_compare
= hold_compare
.get ();
20675 pst_filename
= pst
->filename
;
20676 gdb::unique_xmalloc_ptr
<char> copied_name
;
20677 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
20679 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
20680 pst_filename
, (char *) NULL
));
20681 pst_filename
= copied_name
.get ();
20684 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
20688 return include_name
;
20691 /* State machine to track the state of the line number program. */
20693 class lnp_state_machine
20696 /* Initialize a machine state for the start of a line number
20698 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
20699 bool record_lines_p
);
20701 file_entry
*current_file ()
20703 /* lh->file_names is 0-based, but the file name numbers in the
20704 statement program are 1-based. */
20705 return m_line_header
->file_name_at (m_file
);
20708 /* Record the line in the state machine. END_SEQUENCE is true if
20709 we're processing the end of a sequence. */
20710 void record_line (bool end_sequence
);
20712 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
20713 nop-out rest of the lines in this sequence. */
20714 void check_line_address (struct dwarf2_cu
*cu
,
20715 const gdb_byte
*line_ptr
,
20716 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
20718 void handle_set_discriminator (unsigned int discriminator
)
20720 m_discriminator
= discriminator
;
20721 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
20724 /* Handle DW_LNE_set_address. */
20725 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
20728 address
+= baseaddr
;
20729 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
20732 /* Handle DW_LNS_advance_pc. */
20733 void handle_advance_pc (CORE_ADDR adjust
);
20735 /* Handle a special opcode. */
20736 void handle_special_opcode (unsigned char op_code
);
20738 /* Handle DW_LNS_advance_line. */
20739 void handle_advance_line (int line_delta
)
20741 advance_line (line_delta
);
20744 /* Handle DW_LNS_set_file. */
20745 void handle_set_file (file_name_index file
);
20747 /* Handle DW_LNS_negate_stmt. */
20748 void handle_negate_stmt ()
20750 m_is_stmt
= !m_is_stmt
;
20753 /* Handle DW_LNS_const_add_pc. */
20754 void handle_const_add_pc ();
20756 /* Handle DW_LNS_fixed_advance_pc. */
20757 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
20759 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20763 /* Handle DW_LNS_copy. */
20764 void handle_copy ()
20766 record_line (false);
20767 m_discriminator
= 0;
20770 /* Handle DW_LNE_end_sequence. */
20771 void handle_end_sequence ()
20773 m_currently_recording_lines
= true;
20777 /* Advance the line by LINE_DELTA. */
20778 void advance_line (int line_delta
)
20780 m_line
+= line_delta
;
20782 if (line_delta
!= 0)
20783 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20786 struct dwarf2_cu
*m_cu
;
20788 gdbarch
*m_gdbarch
;
20790 /* True if we're recording lines.
20791 Otherwise we're building partial symtabs and are just interested in
20792 finding include files mentioned by the line number program. */
20793 bool m_record_lines_p
;
20795 /* The line number header. */
20796 line_header
*m_line_header
;
20798 /* These are part of the standard DWARF line number state machine,
20799 and initialized according to the DWARF spec. */
20801 unsigned char m_op_index
= 0;
20802 /* The line table index (1-based) of the current file. */
20803 file_name_index m_file
= (file_name_index
) 1;
20804 unsigned int m_line
= 1;
20806 /* These are initialized in the constructor. */
20808 CORE_ADDR m_address
;
20810 unsigned int m_discriminator
;
20812 /* Additional bits of state we need to track. */
20814 /* The last file that we called dwarf2_start_subfile for.
20815 This is only used for TLLs. */
20816 unsigned int m_last_file
= 0;
20817 /* The last file a line number was recorded for. */
20818 struct subfile
*m_last_subfile
= NULL
;
20820 /* When true, record the lines we decode. */
20821 bool m_currently_recording_lines
= false;
20823 /* The last line number that was recorded, used to coalesce
20824 consecutive entries for the same line. This can happen, for
20825 example, when discriminators are present. PR 17276. */
20826 unsigned int m_last_line
= 0;
20827 bool m_line_has_non_zero_discriminator
= false;
20831 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
20833 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
20834 / m_line_header
->maximum_ops_per_instruction
)
20835 * m_line_header
->minimum_instruction_length
);
20836 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20837 m_op_index
= ((m_op_index
+ adjust
)
20838 % m_line_header
->maximum_ops_per_instruction
);
20842 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
20844 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
20845 CORE_ADDR addr_adj
= (((m_op_index
20846 + (adj_opcode
/ m_line_header
->line_range
))
20847 / m_line_header
->maximum_ops_per_instruction
)
20848 * m_line_header
->minimum_instruction_length
);
20849 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20850 m_op_index
= ((m_op_index
+ (adj_opcode
/ m_line_header
->line_range
))
20851 % m_line_header
->maximum_ops_per_instruction
);
20853 int line_delta
= (m_line_header
->line_base
20854 + (adj_opcode
% m_line_header
->line_range
));
20855 advance_line (line_delta
);
20856 record_line (false);
20857 m_discriminator
= 0;
20861 lnp_state_machine::handle_set_file (file_name_index file
)
20865 const file_entry
*fe
= current_file ();
20867 dwarf2_debug_line_missing_file_complaint ();
20868 else if (m_record_lines_p
)
20870 const char *dir
= fe
->include_dir (m_line_header
);
20872 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20873 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20874 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
20879 lnp_state_machine::handle_const_add_pc ()
20882 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
20885 = (((m_op_index
+ adjust
)
20886 / m_line_header
->maximum_ops_per_instruction
)
20887 * m_line_header
->minimum_instruction_length
);
20889 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20890 m_op_index
= ((m_op_index
+ adjust
)
20891 % m_line_header
->maximum_ops_per_instruction
);
20894 /* Return non-zero if we should add LINE to the line number table.
20895 LINE is the line to add, LAST_LINE is the last line that was added,
20896 LAST_SUBFILE is the subfile for LAST_LINE.
20897 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
20898 had a non-zero discriminator.
20900 We have to be careful in the presence of discriminators.
20901 E.g., for this line:
20903 for (i = 0; i < 100000; i++);
20905 clang can emit four line number entries for that one line,
20906 each with a different discriminator.
20907 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
20909 However, we want gdb to coalesce all four entries into one.
20910 Otherwise the user could stepi into the middle of the line and
20911 gdb would get confused about whether the pc really was in the
20912 middle of the line.
20914 Things are further complicated by the fact that two consecutive
20915 line number entries for the same line is a heuristic used by gcc
20916 to denote the end of the prologue. So we can't just discard duplicate
20917 entries, we have to be selective about it. The heuristic we use is
20918 that we only collapse consecutive entries for the same line if at least
20919 one of those entries has a non-zero discriminator. PR 17276.
20921 Note: Addresses in the line number state machine can never go backwards
20922 within one sequence, thus this coalescing is ok. */
20925 dwarf_record_line_p (struct dwarf2_cu
*cu
,
20926 unsigned int line
, unsigned int last_line
,
20927 int line_has_non_zero_discriminator
,
20928 struct subfile
*last_subfile
)
20930 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
20932 if (line
!= last_line
)
20934 /* Same line for the same file that we've seen already.
20935 As a last check, for pr 17276, only record the line if the line
20936 has never had a non-zero discriminator. */
20937 if (!line_has_non_zero_discriminator
)
20942 /* Use the CU's builder to record line number LINE beginning at
20943 address ADDRESS in the line table of subfile SUBFILE. */
20946 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20947 unsigned int line
, CORE_ADDR address
,
20948 struct dwarf2_cu
*cu
)
20950 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
20952 if (dwarf_line_debug
)
20954 fprintf_unfiltered (gdb_stdlog
,
20955 "Recording line %u, file %s, address %s\n",
20956 line
, lbasename (subfile
->name
),
20957 paddress (gdbarch
, address
));
20961 cu
->get_builder ()->record_line (subfile
, line
, addr
);
20964 /* Subroutine of dwarf_decode_lines_1 to simplify it.
20965 Mark the end of a set of line number records.
20966 The arguments are the same as for dwarf_record_line_1.
20967 If SUBFILE is NULL the request is ignored. */
20970 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20971 CORE_ADDR address
, struct dwarf2_cu
*cu
)
20973 if (subfile
== NULL
)
20976 if (dwarf_line_debug
)
20978 fprintf_unfiltered (gdb_stdlog
,
20979 "Finishing current line, file %s, address %s\n",
20980 lbasename (subfile
->name
),
20981 paddress (gdbarch
, address
));
20984 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, cu
);
20988 lnp_state_machine::record_line (bool end_sequence
)
20990 if (dwarf_line_debug
)
20992 fprintf_unfiltered (gdb_stdlog
,
20993 "Processing actual line %u: file %u,"
20994 " address %s, is_stmt %u, discrim %u\n",
20995 m_line
, to_underlying (m_file
),
20996 paddress (m_gdbarch
, m_address
),
20997 m_is_stmt
, m_discriminator
);
21000 file_entry
*fe
= current_file ();
21003 dwarf2_debug_line_missing_file_complaint ();
21004 /* For now we ignore lines not starting on an instruction boundary.
21005 But not when processing end_sequence for compatibility with the
21006 previous version of the code. */
21007 else if (m_op_index
== 0 || end_sequence
)
21009 fe
->included_p
= 1;
21010 if (m_record_lines_p
&& (producer_is_codewarrior (m_cu
) || m_is_stmt
))
21012 if (m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ()
21015 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
21016 m_currently_recording_lines
? m_cu
: nullptr);
21021 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
21022 m_line_has_non_zero_discriminator
,
21025 buildsym_compunit
*builder
= m_cu
->get_builder ();
21026 dwarf_record_line_1 (m_gdbarch
,
21027 builder
->get_current_subfile (),
21029 m_currently_recording_lines
? m_cu
: nullptr);
21031 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21032 m_last_line
= m_line
;
21038 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
21039 line_header
*lh
, bool record_lines_p
)
21043 m_record_lines_p
= record_lines_p
;
21044 m_line_header
= lh
;
21046 m_currently_recording_lines
= true;
21048 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
21049 was a line entry for it so that the backend has a chance to adjust it
21050 and also record it in case it needs it. This is currently used by MIPS
21051 code, cf. `mips_adjust_dwarf2_line'. */
21052 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
21053 m_is_stmt
= lh
->default_is_stmt
;
21054 m_discriminator
= 0;
21058 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
21059 const gdb_byte
*line_ptr
,
21060 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
21062 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
21063 the pc range of the CU. However, we restrict the test to only ADDRESS
21064 values of zero to preserve GDB's previous behaviour which is to handle
21065 the specific case of a function being GC'd by the linker. */
21067 if (address
== 0 && address
< unrelocated_lowpc
)
21069 /* This line table is for a function which has been
21070 GCd by the linker. Ignore it. PR gdb/12528 */
21072 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21073 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
21075 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
21076 line_offset
, objfile_name (objfile
));
21077 m_currently_recording_lines
= false;
21078 /* Note: m_currently_recording_lines is left as false until we see
21079 DW_LNE_end_sequence. */
21083 /* Subroutine of dwarf_decode_lines to simplify it.
21084 Process the line number information in LH.
21085 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
21086 program in order to set included_p for every referenced header. */
21089 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
21090 const int decode_for_pst_p
, CORE_ADDR lowpc
)
21092 const gdb_byte
*line_ptr
, *extended_end
;
21093 const gdb_byte
*line_end
;
21094 unsigned int bytes_read
, extended_len
;
21095 unsigned char op_code
, extended_op
;
21096 CORE_ADDR baseaddr
;
21097 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21098 bfd
*abfd
= objfile
->obfd
;
21099 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21100 /* True if we're recording line info (as opposed to building partial
21101 symtabs and just interested in finding include files mentioned by
21102 the line number program). */
21103 bool record_lines_p
= !decode_for_pst_p
;
21105 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
21107 line_ptr
= lh
->statement_program_start
;
21108 line_end
= lh
->statement_program_end
;
21110 /* Read the statement sequences until there's nothing left. */
21111 while (line_ptr
< line_end
)
21113 /* The DWARF line number program state machine. Reset the state
21114 machine at the start of each sequence. */
21115 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
21116 bool end_sequence
= false;
21118 if (record_lines_p
)
21120 /* Start a subfile for the current file of the state
21122 const file_entry
*fe
= state_machine
.current_file ();
21125 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
21128 /* Decode the table. */
21129 while (line_ptr
< line_end
&& !end_sequence
)
21131 op_code
= read_1_byte (abfd
, line_ptr
);
21134 if (op_code
>= lh
->opcode_base
)
21136 /* Special opcode. */
21137 state_machine
.handle_special_opcode (op_code
);
21139 else switch (op_code
)
21141 case DW_LNS_extended_op
:
21142 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
21144 line_ptr
+= bytes_read
;
21145 extended_end
= line_ptr
+ extended_len
;
21146 extended_op
= read_1_byte (abfd
, line_ptr
);
21148 switch (extended_op
)
21150 case DW_LNE_end_sequence
:
21151 state_machine
.handle_end_sequence ();
21152 end_sequence
= true;
21154 case DW_LNE_set_address
:
21157 = read_address (abfd
, line_ptr
, cu
, &bytes_read
);
21158 line_ptr
+= bytes_read
;
21160 state_machine
.check_line_address (cu
, line_ptr
,
21161 lowpc
- baseaddr
, address
);
21162 state_machine
.handle_set_address (baseaddr
, address
);
21165 case DW_LNE_define_file
:
21167 const char *cur_file
;
21168 unsigned int mod_time
, length
;
21171 cur_file
= read_direct_string (abfd
, line_ptr
,
21173 line_ptr
+= bytes_read
;
21174 dindex
= (dir_index
)
21175 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21176 line_ptr
+= bytes_read
;
21178 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21179 line_ptr
+= bytes_read
;
21181 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21182 line_ptr
+= bytes_read
;
21183 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
21186 case DW_LNE_set_discriminator
:
21188 /* The discriminator is not interesting to the
21189 debugger; just ignore it. We still need to
21190 check its value though:
21191 if there are consecutive entries for the same
21192 (non-prologue) line we want to coalesce them.
21195 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21196 line_ptr
+= bytes_read
;
21198 state_machine
.handle_set_discriminator (discr
);
21202 complaint (_("mangled .debug_line section"));
21205 /* Make sure that we parsed the extended op correctly. If e.g.
21206 we expected a different address size than the producer used,
21207 we may have read the wrong number of bytes. */
21208 if (line_ptr
!= extended_end
)
21210 complaint (_("mangled .debug_line section"));
21215 state_machine
.handle_copy ();
21217 case DW_LNS_advance_pc
:
21220 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21221 line_ptr
+= bytes_read
;
21223 state_machine
.handle_advance_pc (adjust
);
21226 case DW_LNS_advance_line
:
21229 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
21230 line_ptr
+= bytes_read
;
21232 state_machine
.handle_advance_line (line_delta
);
21235 case DW_LNS_set_file
:
21237 file_name_index file
21238 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
21240 line_ptr
+= bytes_read
;
21242 state_machine
.handle_set_file (file
);
21245 case DW_LNS_set_column
:
21246 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21247 line_ptr
+= bytes_read
;
21249 case DW_LNS_negate_stmt
:
21250 state_machine
.handle_negate_stmt ();
21252 case DW_LNS_set_basic_block
:
21254 /* Add to the address register of the state machine the
21255 address increment value corresponding to special opcode
21256 255. I.e., this value is scaled by the minimum
21257 instruction length since special opcode 255 would have
21258 scaled the increment. */
21259 case DW_LNS_const_add_pc
:
21260 state_machine
.handle_const_add_pc ();
21262 case DW_LNS_fixed_advance_pc
:
21264 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
21267 state_machine
.handle_fixed_advance_pc (addr_adj
);
21272 /* Unknown standard opcode, ignore it. */
21275 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
21277 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21278 line_ptr
+= bytes_read
;
21285 dwarf2_debug_line_missing_end_sequence_complaint ();
21287 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
21288 in which case we still finish recording the last line). */
21289 state_machine
.record_line (true);
21293 /* Decode the Line Number Program (LNP) for the given line_header
21294 structure and CU. The actual information extracted and the type
21295 of structures created from the LNP depends on the value of PST.
21297 1. If PST is NULL, then this procedure uses the data from the program
21298 to create all necessary symbol tables, and their linetables.
21300 2. If PST is not NULL, this procedure reads the program to determine
21301 the list of files included by the unit represented by PST, and
21302 builds all the associated partial symbol tables.
21304 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
21305 It is used for relative paths in the line table.
21306 NOTE: When processing partial symtabs (pst != NULL),
21307 comp_dir == pst->dirname.
21309 NOTE: It is important that psymtabs have the same file name (via strcmp)
21310 as the corresponding symtab. Since COMP_DIR is not used in the name of the
21311 symtab we don't use it in the name of the psymtabs we create.
21312 E.g. expand_line_sal requires this when finding psymtabs to expand.
21313 A good testcase for this is mb-inline.exp.
21315 LOWPC is the lowest address in CU (or 0 if not known).
21317 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
21318 for its PC<->lines mapping information. Otherwise only the filename
21319 table is read in. */
21322 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
21323 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
21324 CORE_ADDR lowpc
, int decode_mapping
)
21326 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21327 const int decode_for_pst_p
= (pst
!= NULL
);
21329 if (decode_mapping
)
21330 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
21332 if (decode_for_pst_p
)
21336 /* Now that we're done scanning the Line Header Program, we can
21337 create the psymtab of each included file. */
21338 for (file_index
= 0; file_index
< lh
->file_names
.size (); file_index
++)
21339 if (lh
->file_names
[file_index
].included_p
== 1)
21341 gdb::unique_xmalloc_ptr
<char> name_holder
;
21342 const char *include_name
=
21343 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
,
21345 if (include_name
!= NULL
)
21346 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
21351 /* Make sure a symtab is created for every file, even files
21352 which contain only variables (i.e. no code with associated
21354 buildsym_compunit
*builder
= cu
->get_builder ();
21355 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
21358 for (i
= 0; i
< lh
->file_names
.size (); i
++)
21360 file_entry
&fe
= lh
->file_names
[i
];
21362 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
21364 if (builder
->get_current_subfile ()->symtab
== NULL
)
21366 builder
->get_current_subfile ()->symtab
21367 = allocate_symtab (cust
,
21368 builder
->get_current_subfile ()->name
);
21370 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
21375 /* Start a subfile for DWARF. FILENAME is the name of the file and
21376 DIRNAME the name of the source directory which contains FILENAME
21377 or NULL if not known.
21378 This routine tries to keep line numbers from identical absolute and
21379 relative file names in a common subfile.
21381 Using the `list' example from the GDB testsuite, which resides in
21382 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
21383 of /srcdir/list0.c yields the following debugging information for list0.c:
21385 DW_AT_name: /srcdir/list0.c
21386 DW_AT_comp_dir: /compdir
21387 files.files[0].name: list0.h
21388 files.files[0].dir: /srcdir
21389 files.files[1].name: list0.c
21390 files.files[1].dir: /srcdir
21392 The line number information for list0.c has to end up in a single
21393 subfile, so that `break /srcdir/list0.c:1' works as expected.
21394 start_subfile will ensure that this happens provided that we pass the
21395 concatenation of files.files[1].dir and files.files[1].name as the
21399 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
21400 const char *dirname
)
21404 /* In order not to lose the line information directory,
21405 we concatenate it to the filename when it makes sense.
21406 Note that the Dwarf3 standard says (speaking of filenames in line
21407 information): ``The directory index is ignored for file names
21408 that represent full path names''. Thus ignoring dirname in the
21409 `else' branch below isn't an issue. */
21411 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
21413 copy
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
21417 cu
->get_builder ()->start_subfile (filename
);
21423 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
21424 buildsym_compunit constructor. */
21426 struct compunit_symtab
*
21427 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
21430 gdb_assert (m_builder
== nullptr);
21432 m_builder
.reset (new struct buildsym_compunit
21433 (per_cu
->dwarf2_per_objfile
->objfile
,
21434 name
, comp_dir
, language
, low_pc
));
21436 list_in_scope
= get_builder ()->get_file_symbols ();
21438 get_builder ()->record_debugformat ("DWARF 2");
21439 get_builder ()->record_producer (producer
);
21441 processing_has_namespace_info
= false;
21443 return get_builder ()->get_compunit_symtab ();
21447 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
21448 struct dwarf2_cu
*cu
)
21450 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21451 struct comp_unit_head
*cu_header
= &cu
->header
;
21453 /* NOTE drow/2003-01-30: There used to be a comment and some special
21454 code here to turn a symbol with DW_AT_external and a
21455 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
21456 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
21457 with some versions of binutils) where shared libraries could have
21458 relocations against symbols in their debug information - the
21459 minimal symbol would have the right address, but the debug info
21460 would not. It's no longer necessary, because we will explicitly
21461 apply relocations when we read in the debug information now. */
21463 /* A DW_AT_location attribute with no contents indicates that a
21464 variable has been optimized away. */
21465 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
21467 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21471 /* Handle one degenerate form of location expression specially, to
21472 preserve GDB's previous behavior when section offsets are
21473 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
21474 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
21476 if (attr_form_is_block (attr
)
21477 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
21478 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
21479 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
21480 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
21481 && (DW_BLOCK (attr
)->size
21482 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
21484 unsigned int dummy
;
21486 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
21487 SYMBOL_VALUE_ADDRESS (sym
) =
21488 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
21490 SYMBOL_VALUE_ADDRESS (sym
) =
21491 read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1, &dummy
);
21492 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
21493 fixup_symbol_section (sym
, objfile
);
21494 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
21495 SYMBOL_SECTION (sym
));
21499 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
21500 expression evaluator, and use LOC_COMPUTED only when necessary
21501 (i.e. when the value of a register or memory location is
21502 referenced, or a thread-local block, etc.). Then again, it might
21503 not be worthwhile. I'm assuming that it isn't unless performance
21504 or memory numbers show me otherwise. */
21506 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
21508 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
21509 cu
->has_loclist
= true;
21512 /* Given a pointer to a DWARF information entry, figure out if we need
21513 to make a symbol table entry for it, and if so, create a new entry
21514 and return a pointer to it.
21515 If TYPE is NULL, determine symbol type from the die, otherwise
21516 used the passed type.
21517 If SPACE is not NULL, use it to hold the new symbol. If it is
21518 NULL, allocate a new symbol on the objfile's obstack. */
21520 static struct symbol
*
21521 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
21522 struct symbol
*space
)
21524 struct dwarf2_per_objfile
*dwarf2_per_objfile
21525 = cu
->per_cu
->dwarf2_per_objfile
;
21526 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21527 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21528 struct symbol
*sym
= NULL
;
21530 struct attribute
*attr
= NULL
;
21531 struct attribute
*attr2
= NULL
;
21532 CORE_ADDR baseaddr
;
21533 struct pending
**list_to_add
= NULL
;
21535 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
21537 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
21539 name
= dwarf2_name (die
, cu
);
21542 const char *linkagename
;
21543 int suppress_add
= 0;
21548 sym
= allocate_symbol (objfile
);
21549 OBJSTAT (objfile
, n_syms
++);
21551 /* Cache this symbol's name and the name's demangled form (if any). */
21552 SYMBOL_SET_LANGUAGE (sym
, cu
->language
, &objfile
->objfile_obstack
);
21553 linkagename
= dwarf2_physname (name
, die
, cu
);
21554 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
21556 /* Fortran does not have mangling standard and the mangling does differ
21557 between gfortran, iFort etc. */
21558 if (cu
->language
== language_fortran
21559 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
21560 symbol_set_demangled_name (&(sym
->ginfo
),
21561 dwarf2_full_name (name
, die
, cu
),
21564 /* Default assumptions.
21565 Use the passed type or decode it from the die. */
21566 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21567 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21569 SYMBOL_TYPE (sym
) = type
;
21571 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
21572 attr
= dwarf2_attr (die
,
21573 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
21577 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
21580 attr
= dwarf2_attr (die
,
21581 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
21585 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
21586 struct file_entry
*fe
;
21588 if (cu
->line_header
!= NULL
)
21589 fe
= cu
->line_header
->file_name_at (file_index
);
21594 complaint (_("file index out of range"));
21596 symbol_set_symtab (sym
, fe
->symtab
);
21602 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
21607 addr
= attr_value_as_address (attr
);
21608 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
21609 SYMBOL_VALUE_ADDRESS (sym
) = addr
;
21611 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
21612 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
21613 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
21614 add_symbol_to_list (sym
, cu
->list_in_scope
);
21616 case DW_TAG_subprogram
:
21617 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21619 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21620 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21621 if ((attr2
&& (DW_UNSND (attr2
) != 0))
21622 || cu
->language
== language_ada
)
21624 /* Subprograms marked external are stored as a global symbol.
21625 Ada subprograms, whether marked external or not, are always
21626 stored as a global symbol, because we want to be able to
21627 access them globally. For instance, we want to be able
21628 to break on a nested subprogram without having to
21629 specify the context. */
21630 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21634 list_to_add
= cu
->list_in_scope
;
21637 case DW_TAG_inlined_subroutine
:
21638 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21640 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21641 SYMBOL_INLINED (sym
) = 1;
21642 list_to_add
= cu
->list_in_scope
;
21644 case DW_TAG_template_value_param
:
21646 /* Fall through. */
21647 case DW_TAG_constant
:
21648 case DW_TAG_variable
:
21649 case DW_TAG_member
:
21650 /* Compilation with minimal debug info may result in
21651 variables with missing type entries. Change the
21652 misleading `void' type to something sensible. */
21653 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
21654 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
21656 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21657 /* In the case of DW_TAG_member, we should only be called for
21658 static const members. */
21659 if (die
->tag
== DW_TAG_member
)
21661 /* dwarf2_add_field uses die_is_declaration,
21662 so we do the same. */
21663 gdb_assert (die_is_declaration (die
, cu
));
21668 dwarf2_const_value (attr
, sym
, cu
);
21669 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21672 if (attr2
&& (DW_UNSND (attr2
) != 0))
21673 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21675 list_to_add
= cu
->list_in_scope
;
21679 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21682 var_decode_location (attr
, sym
, cu
);
21683 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21685 /* Fortran explicitly imports any global symbols to the local
21686 scope by DW_TAG_common_block. */
21687 if (cu
->language
== language_fortran
&& die
->parent
21688 && die
->parent
->tag
== DW_TAG_common_block
)
21691 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21692 && SYMBOL_VALUE_ADDRESS (sym
) == 0
21693 && !dwarf2_per_objfile
->has_section_at_zero
)
21695 /* When a static variable is eliminated by the linker,
21696 the corresponding debug information is not stripped
21697 out, but the variable address is set to null;
21698 do not add such variables into symbol table. */
21700 else if (attr2
&& (DW_UNSND (attr2
) != 0))
21702 /* Workaround gfortran PR debug/40040 - it uses
21703 DW_AT_location for variables in -fPIC libraries which may
21704 get overriden by other libraries/executable and get
21705 a different address. Resolve it by the minimal symbol
21706 which may come from inferior's executable using copy
21707 relocation. Make this workaround only for gfortran as for
21708 other compilers GDB cannot guess the minimal symbol
21709 Fortran mangling kind. */
21710 if (cu
->language
== language_fortran
&& die
->parent
21711 && die
->parent
->tag
== DW_TAG_module
21713 && startswith (cu
->producer
, "GNU Fortran"))
21714 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21716 /* A variable with DW_AT_external is never static,
21717 but it may be block-scoped. */
21719 = ((cu
->list_in_scope
21720 == cu
->get_builder ()->get_file_symbols ())
21721 ? cu
->get_builder ()->get_global_symbols ()
21722 : cu
->list_in_scope
);
21725 list_to_add
= cu
->list_in_scope
;
21729 /* We do not know the address of this symbol.
21730 If it is an external symbol and we have type information
21731 for it, enter the symbol as a LOC_UNRESOLVED symbol.
21732 The address of the variable will then be determined from
21733 the minimal symbol table whenever the variable is
21735 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21737 /* Fortran explicitly imports any global symbols to the local
21738 scope by DW_TAG_common_block. */
21739 if (cu
->language
== language_fortran
&& die
->parent
21740 && die
->parent
->tag
== DW_TAG_common_block
)
21742 /* SYMBOL_CLASS doesn't matter here because
21743 read_common_block is going to reset it. */
21745 list_to_add
= cu
->list_in_scope
;
21747 else if (attr2
&& (DW_UNSND (attr2
) != 0)
21748 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
21750 /* A variable with DW_AT_external is never static, but it
21751 may be block-scoped. */
21753 = ((cu
->list_in_scope
21754 == cu
->get_builder ()->get_file_symbols ())
21755 ? cu
->get_builder ()->get_global_symbols ()
21756 : cu
->list_in_scope
);
21758 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21760 else if (!die_is_declaration (die
, cu
))
21762 /* Use the default LOC_OPTIMIZED_OUT class. */
21763 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
21765 list_to_add
= cu
->list_in_scope
;
21769 case DW_TAG_formal_parameter
:
21771 /* If we are inside a function, mark this as an argument. If
21772 not, we might be looking at an argument to an inlined function
21773 when we do not have enough information to show inlined frames;
21774 pretend it's a local variable in that case so that the user can
21776 struct context_stack
*curr
21777 = cu
->get_builder ()->get_current_context_stack ();
21778 if (curr
!= nullptr && curr
->name
!= nullptr)
21779 SYMBOL_IS_ARGUMENT (sym
) = 1;
21780 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21783 var_decode_location (attr
, sym
, cu
);
21785 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21788 dwarf2_const_value (attr
, sym
, cu
);
21791 list_to_add
= cu
->list_in_scope
;
21794 case DW_TAG_unspecified_parameters
:
21795 /* From varargs functions; gdb doesn't seem to have any
21796 interest in this information, so just ignore it for now.
21799 case DW_TAG_template_type_param
:
21801 /* Fall through. */
21802 case DW_TAG_class_type
:
21803 case DW_TAG_interface_type
:
21804 case DW_TAG_structure_type
:
21805 case DW_TAG_union_type
:
21806 case DW_TAG_set_type
:
21807 case DW_TAG_enumeration_type
:
21808 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21809 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
21812 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
21813 really ever be static objects: otherwise, if you try
21814 to, say, break of a class's method and you're in a file
21815 which doesn't mention that class, it won't work unless
21816 the check for all static symbols in lookup_symbol_aux
21817 saves you. See the OtherFileClass tests in
21818 gdb.c++/namespace.exp. */
21822 buildsym_compunit
*builder
= cu
->get_builder ();
21824 = (cu
->list_in_scope
== builder
->get_file_symbols ()
21825 && cu
->language
== language_cplus
21826 ? builder
->get_global_symbols ()
21827 : cu
->list_in_scope
);
21829 /* The semantics of C++ state that "struct foo {
21830 ... }" also defines a typedef for "foo". */
21831 if (cu
->language
== language_cplus
21832 || cu
->language
== language_ada
21833 || cu
->language
== language_d
21834 || cu
->language
== language_rust
)
21836 /* The symbol's name is already allocated along
21837 with this objfile, so we don't need to
21838 duplicate it for the type. */
21839 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
21840 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
21845 case DW_TAG_typedef
:
21846 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21847 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21848 list_to_add
= cu
->list_in_scope
;
21850 case DW_TAG_base_type
:
21851 case DW_TAG_subrange_type
:
21852 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21853 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21854 list_to_add
= cu
->list_in_scope
;
21856 case DW_TAG_enumerator
:
21857 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21860 dwarf2_const_value (attr
, sym
, cu
);
21863 /* NOTE: carlton/2003-11-10: See comment above in the
21864 DW_TAG_class_type, etc. block. */
21867 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
21868 && cu
->language
== language_cplus
21869 ? cu
->get_builder ()->get_global_symbols ()
21870 : cu
->list_in_scope
);
21873 case DW_TAG_imported_declaration
:
21874 case DW_TAG_namespace
:
21875 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21876 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21878 case DW_TAG_module
:
21879 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21880 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
21881 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21883 case DW_TAG_common_block
:
21884 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
21885 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
21886 add_symbol_to_list (sym
, cu
->list_in_scope
);
21889 /* Not a tag we recognize. Hopefully we aren't processing
21890 trash data, but since we must specifically ignore things
21891 we don't recognize, there is nothing else we should do at
21893 complaint (_("unsupported tag: '%s'"),
21894 dwarf_tag_name (die
->tag
));
21900 sym
->hash_next
= objfile
->template_symbols
;
21901 objfile
->template_symbols
= sym
;
21902 list_to_add
= NULL
;
21905 if (list_to_add
!= NULL
)
21906 add_symbol_to_list (sym
, list_to_add
);
21908 /* For the benefit of old versions of GCC, check for anonymous
21909 namespaces based on the demangled name. */
21910 if (!cu
->processing_has_namespace_info
21911 && cu
->language
== language_cplus
)
21912 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
21917 /* Given an attr with a DW_FORM_dataN value in host byte order,
21918 zero-extend it as appropriate for the symbol's type. The DWARF
21919 standard (v4) is not entirely clear about the meaning of using
21920 DW_FORM_dataN for a constant with a signed type, where the type is
21921 wider than the data. The conclusion of a discussion on the DWARF
21922 list was that this is unspecified. We choose to always zero-extend
21923 because that is the interpretation long in use by GCC. */
21926 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
21927 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
21929 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21930 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
21931 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
21932 LONGEST l
= DW_UNSND (attr
);
21934 if (bits
< sizeof (*value
) * 8)
21936 l
&= ((LONGEST
) 1 << bits
) - 1;
21939 else if (bits
== sizeof (*value
) * 8)
21943 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
21944 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
21951 /* Read a constant value from an attribute. Either set *VALUE, or if
21952 the value does not fit in *VALUE, set *BYTES - either already
21953 allocated on the objfile obstack, or newly allocated on OBSTACK,
21954 or, set *BATON, if we translated the constant to a location
21958 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
21959 const char *name
, struct obstack
*obstack
,
21960 struct dwarf2_cu
*cu
,
21961 LONGEST
*value
, const gdb_byte
**bytes
,
21962 struct dwarf2_locexpr_baton
**baton
)
21964 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21965 struct comp_unit_head
*cu_header
= &cu
->header
;
21966 struct dwarf_block
*blk
;
21967 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
21968 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
21974 switch (attr
->form
)
21977 case DW_FORM_addrx
:
21978 case DW_FORM_GNU_addr_index
:
21982 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
21983 dwarf2_const_value_length_mismatch_complaint (name
,
21984 cu_header
->addr_size
,
21985 TYPE_LENGTH (type
));
21986 /* Symbols of this form are reasonably rare, so we just
21987 piggyback on the existing location code rather than writing
21988 a new implementation of symbol_computed_ops. */
21989 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
21990 (*baton
)->per_cu
= cu
->per_cu
;
21991 gdb_assert ((*baton
)->per_cu
);
21993 (*baton
)->size
= 2 + cu_header
->addr_size
;
21994 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
21995 (*baton
)->data
= data
;
21997 data
[0] = DW_OP_addr
;
21998 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
21999 byte_order
, DW_ADDR (attr
));
22000 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
22003 case DW_FORM_string
:
22006 case DW_FORM_GNU_str_index
:
22007 case DW_FORM_GNU_strp_alt
:
22008 /* DW_STRING is already allocated on the objfile obstack, point
22010 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
22012 case DW_FORM_block1
:
22013 case DW_FORM_block2
:
22014 case DW_FORM_block4
:
22015 case DW_FORM_block
:
22016 case DW_FORM_exprloc
:
22017 case DW_FORM_data16
:
22018 blk
= DW_BLOCK (attr
);
22019 if (TYPE_LENGTH (type
) != blk
->size
)
22020 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
22021 TYPE_LENGTH (type
));
22022 *bytes
= blk
->data
;
22025 /* The DW_AT_const_value attributes are supposed to carry the
22026 symbol's value "represented as it would be on the target
22027 architecture." By the time we get here, it's already been
22028 converted to host endianness, so we just need to sign- or
22029 zero-extend it as appropriate. */
22030 case DW_FORM_data1
:
22031 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
22033 case DW_FORM_data2
:
22034 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
22036 case DW_FORM_data4
:
22037 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
22039 case DW_FORM_data8
:
22040 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
22043 case DW_FORM_sdata
:
22044 case DW_FORM_implicit_const
:
22045 *value
= DW_SND (attr
);
22048 case DW_FORM_udata
:
22049 *value
= DW_UNSND (attr
);
22053 complaint (_("unsupported const value attribute form: '%s'"),
22054 dwarf_form_name (attr
->form
));
22061 /* Copy constant value from an attribute to a symbol. */
22064 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
22065 struct dwarf2_cu
*cu
)
22067 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22069 const gdb_byte
*bytes
;
22070 struct dwarf2_locexpr_baton
*baton
;
22072 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
22073 SYMBOL_PRINT_NAME (sym
),
22074 &objfile
->objfile_obstack
, cu
,
22075 &value
, &bytes
, &baton
);
22079 SYMBOL_LOCATION_BATON (sym
) = baton
;
22080 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
22082 else if (bytes
!= NULL
)
22084 SYMBOL_VALUE_BYTES (sym
) = bytes
;
22085 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
22089 SYMBOL_VALUE (sym
) = value
;
22090 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
22094 /* Return the type of the die in question using its DW_AT_type attribute. */
22096 static struct type
*
22097 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22099 struct attribute
*type_attr
;
22101 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
22104 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22105 /* A missing DW_AT_type represents a void type. */
22106 return objfile_type (objfile
)->builtin_void
;
22109 return lookup_die_type (die
, type_attr
, cu
);
22112 /* True iff CU's producer generates GNAT Ada auxiliary information
22113 that allows to find parallel types through that information instead
22114 of having to do expensive parallel lookups by type name. */
22117 need_gnat_info (struct dwarf2_cu
*cu
)
22119 /* Assume that the Ada compiler was GNAT, which always produces
22120 the auxiliary information. */
22121 return (cu
->language
== language_ada
);
22124 /* Return the auxiliary type of the die in question using its
22125 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
22126 attribute is not present. */
22128 static struct type
*
22129 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22131 struct attribute
*type_attr
;
22133 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
22137 return lookup_die_type (die
, type_attr
, cu
);
22140 /* If DIE has a descriptive_type attribute, then set the TYPE's
22141 descriptive type accordingly. */
22144 set_descriptive_type (struct type
*type
, struct die_info
*die
,
22145 struct dwarf2_cu
*cu
)
22147 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
22149 if (descriptive_type
)
22151 ALLOCATE_GNAT_AUX_TYPE (type
);
22152 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
22156 /* Return the containing type of the die in question using its
22157 DW_AT_containing_type attribute. */
22159 static struct type
*
22160 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22162 struct attribute
*type_attr
;
22163 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22165 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
22167 error (_("Dwarf Error: Problem turning containing type into gdb type "
22168 "[in module %s]"), objfile_name (objfile
));
22170 return lookup_die_type (die
, type_attr
, cu
);
22173 /* Return an error marker type to use for the ill formed type in DIE/CU. */
22175 static struct type
*
22176 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
22178 struct dwarf2_per_objfile
*dwarf2_per_objfile
22179 = cu
->per_cu
->dwarf2_per_objfile
;
22180 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22183 std::string message
22184 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
22185 objfile_name (objfile
),
22186 sect_offset_str (cu
->header
.sect_off
),
22187 sect_offset_str (die
->sect_off
));
22188 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
22190 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
22193 /* Look up the type of DIE in CU using its type attribute ATTR.
22194 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
22195 DW_AT_containing_type.
22196 If there is no type substitute an error marker. */
22198 static struct type
*
22199 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
22200 struct dwarf2_cu
*cu
)
22202 struct dwarf2_per_objfile
*dwarf2_per_objfile
22203 = cu
->per_cu
->dwarf2_per_objfile
;
22204 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22205 struct type
*this_type
;
22207 gdb_assert (attr
->name
== DW_AT_type
22208 || attr
->name
== DW_AT_GNAT_descriptive_type
22209 || attr
->name
== DW_AT_containing_type
);
22211 /* First see if we have it cached. */
22213 if (attr
->form
== DW_FORM_GNU_ref_alt
)
22215 struct dwarf2_per_cu_data
*per_cu
;
22216 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22218 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
22219 dwarf2_per_objfile
);
22220 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
22222 else if (attr_form_is_ref (attr
))
22224 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22226 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
22228 else if (attr
->form
== DW_FORM_ref_sig8
)
22230 ULONGEST signature
= DW_SIGNATURE (attr
);
22232 return get_signatured_type (die
, signature
, cu
);
22236 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
22237 " at %s [in module %s]"),
22238 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
22239 objfile_name (objfile
));
22240 return build_error_marker_type (cu
, die
);
22243 /* If not cached we need to read it in. */
22245 if (this_type
== NULL
)
22247 struct die_info
*type_die
= NULL
;
22248 struct dwarf2_cu
*type_cu
= cu
;
22250 if (attr_form_is_ref (attr
))
22251 type_die
= follow_die_ref (die
, attr
, &type_cu
);
22252 if (type_die
== NULL
)
22253 return build_error_marker_type (cu
, die
);
22254 /* If we find the type now, it's probably because the type came
22255 from an inter-CU reference and the type's CU got expanded before
22257 this_type
= read_type_die (type_die
, type_cu
);
22260 /* If we still don't have a type use an error marker. */
22262 if (this_type
== NULL
)
22263 return build_error_marker_type (cu
, die
);
22268 /* Return the type in DIE, CU.
22269 Returns NULL for invalid types.
22271 This first does a lookup in die_type_hash,
22272 and only reads the die in if necessary.
22274 NOTE: This can be called when reading in partial or full symbols. */
22276 static struct type
*
22277 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
22279 struct type
*this_type
;
22281 this_type
= get_die_type (die
, cu
);
22285 return read_type_die_1 (die
, cu
);
22288 /* Read the type in DIE, CU.
22289 Returns NULL for invalid types. */
22291 static struct type
*
22292 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
22294 struct type
*this_type
= NULL
;
22298 case DW_TAG_class_type
:
22299 case DW_TAG_interface_type
:
22300 case DW_TAG_structure_type
:
22301 case DW_TAG_union_type
:
22302 this_type
= read_structure_type (die
, cu
);
22304 case DW_TAG_enumeration_type
:
22305 this_type
= read_enumeration_type (die
, cu
);
22307 case DW_TAG_subprogram
:
22308 case DW_TAG_subroutine_type
:
22309 case DW_TAG_inlined_subroutine
:
22310 this_type
= read_subroutine_type (die
, cu
);
22312 case DW_TAG_array_type
:
22313 this_type
= read_array_type (die
, cu
);
22315 case DW_TAG_set_type
:
22316 this_type
= read_set_type (die
, cu
);
22318 case DW_TAG_pointer_type
:
22319 this_type
= read_tag_pointer_type (die
, cu
);
22321 case DW_TAG_ptr_to_member_type
:
22322 this_type
= read_tag_ptr_to_member_type (die
, cu
);
22324 case DW_TAG_reference_type
:
22325 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
22327 case DW_TAG_rvalue_reference_type
:
22328 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
22330 case DW_TAG_const_type
:
22331 this_type
= read_tag_const_type (die
, cu
);
22333 case DW_TAG_volatile_type
:
22334 this_type
= read_tag_volatile_type (die
, cu
);
22336 case DW_TAG_restrict_type
:
22337 this_type
= read_tag_restrict_type (die
, cu
);
22339 case DW_TAG_string_type
:
22340 this_type
= read_tag_string_type (die
, cu
);
22342 case DW_TAG_typedef
:
22343 this_type
= read_typedef (die
, cu
);
22345 case DW_TAG_subrange_type
:
22346 this_type
= read_subrange_type (die
, cu
);
22348 case DW_TAG_base_type
:
22349 this_type
= read_base_type (die
, cu
);
22351 case DW_TAG_unspecified_type
:
22352 this_type
= read_unspecified_type (die
, cu
);
22354 case DW_TAG_namespace
:
22355 this_type
= read_namespace_type (die
, cu
);
22357 case DW_TAG_module
:
22358 this_type
= read_module_type (die
, cu
);
22360 case DW_TAG_atomic_type
:
22361 this_type
= read_tag_atomic_type (die
, cu
);
22364 complaint (_("unexpected tag in read_type_die: '%s'"),
22365 dwarf_tag_name (die
->tag
));
22372 /* See if we can figure out if the class lives in a namespace. We do
22373 this by looking for a member function; its demangled name will
22374 contain namespace info, if there is any.
22375 Return the computed name or NULL.
22376 Space for the result is allocated on the objfile's obstack.
22377 This is the full-die version of guess_partial_die_structure_name.
22378 In this case we know DIE has no useful parent. */
22381 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22383 struct die_info
*spec_die
;
22384 struct dwarf2_cu
*spec_cu
;
22385 struct die_info
*child
;
22386 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22389 spec_die
= die_specification (die
, &spec_cu
);
22390 if (spec_die
!= NULL
)
22396 for (child
= die
->child
;
22398 child
= child
->sibling
)
22400 if (child
->tag
== DW_TAG_subprogram
)
22402 const char *linkage_name
= dw2_linkage_name (child
, cu
);
22404 if (linkage_name
!= NULL
)
22407 = language_class_name_from_physname (cu
->language_defn
,
22411 if (actual_name
!= NULL
)
22413 const char *die_name
= dwarf2_name (die
, cu
);
22415 if (die_name
!= NULL
22416 && strcmp (die_name
, actual_name
) != 0)
22418 /* Strip off the class name from the full name.
22419 We want the prefix. */
22420 int die_name_len
= strlen (die_name
);
22421 int actual_name_len
= strlen (actual_name
);
22423 /* Test for '::' as a sanity check. */
22424 if (actual_name_len
> die_name_len
+ 2
22425 && actual_name
[actual_name_len
22426 - die_name_len
- 1] == ':')
22427 name
= obstack_strndup (
22428 &objfile
->per_bfd
->storage_obstack
,
22429 actual_name
, actual_name_len
- die_name_len
- 2);
22432 xfree (actual_name
);
22441 /* GCC might emit a nameless typedef that has a linkage name. Determine the
22442 prefix part in such case. See
22443 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22445 static const char *
22446 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22448 struct attribute
*attr
;
22451 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
22452 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
22455 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
22458 attr
= dw2_linkage_name_attr (die
, cu
);
22459 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22462 /* dwarf2_name had to be already called. */
22463 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
22465 /* Strip the base name, keep any leading namespaces/classes. */
22466 base
= strrchr (DW_STRING (attr
), ':');
22467 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
22470 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22471 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
22473 &base
[-1] - DW_STRING (attr
));
22476 /* Return the name of the namespace/class that DIE is defined within,
22477 or "" if we can't tell. The caller should not xfree the result.
22479 For example, if we're within the method foo() in the following
22489 then determine_prefix on foo's die will return "N::C". */
22491 static const char *
22492 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22494 struct dwarf2_per_objfile
*dwarf2_per_objfile
22495 = cu
->per_cu
->dwarf2_per_objfile
;
22496 struct die_info
*parent
, *spec_die
;
22497 struct dwarf2_cu
*spec_cu
;
22498 struct type
*parent_type
;
22499 const char *retval
;
22501 if (cu
->language
!= language_cplus
22502 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
22503 && cu
->language
!= language_rust
)
22506 retval
= anonymous_struct_prefix (die
, cu
);
22510 /* We have to be careful in the presence of DW_AT_specification.
22511 For example, with GCC 3.4, given the code
22515 // Definition of N::foo.
22519 then we'll have a tree of DIEs like this:
22521 1: DW_TAG_compile_unit
22522 2: DW_TAG_namespace // N
22523 3: DW_TAG_subprogram // declaration of N::foo
22524 4: DW_TAG_subprogram // definition of N::foo
22525 DW_AT_specification // refers to die #3
22527 Thus, when processing die #4, we have to pretend that we're in
22528 the context of its DW_AT_specification, namely the contex of die
22531 spec_die
= die_specification (die
, &spec_cu
);
22532 if (spec_die
== NULL
)
22533 parent
= die
->parent
;
22536 parent
= spec_die
->parent
;
22540 if (parent
== NULL
)
22542 else if (parent
->building_fullname
)
22545 const char *parent_name
;
22547 /* It has been seen on RealView 2.2 built binaries,
22548 DW_TAG_template_type_param types actually _defined_ as
22549 children of the parent class:
22552 template class <class Enum> Class{};
22553 Class<enum E> class_e;
22555 1: DW_TAG_class_type (Class)
22556 2: DW_TAG_enumeration_type (E)
22557 3: DW_TAG_enumerator (enum1:0)
22558 3: DW_TAG_enumerator (enum2:1)
22560 2: DW_TAG_template_type_param
22561 DW_AT_type DW_FORM_ref_udata (E)
22563 Besides being broken debug info, it can put GDB into an
22564 infinite loop. Consider:
22566 When we're building the full name for Class<E>, we'll start
22567 at Class, and go look over its template type parameters,
22568 finding E. We'll then try to build the full name of E, and
22569 reach here. We're now trying to build the full name of E,
22570 and look over the parent DIE for containing scope. In the
22571 broken case, if we followed the parent DIE of E, we'd again
22572 find Class, and once again go look at its template type
22573 arguments, etc., etc. Simply don't consider such parent die
22574 as source-level parent of this die (it can't be, the language
22575 doesn't allow it), and break the loop here. */
22576 name
= dwarf2_name (die
, cu
);
22577 parent_name
= dwarf2_name (parent
, cu
);
22578 complaint (_("template param type '%s' defined within parent '%s'"),
22579 name
? name
: "<unknown>",
22580 parent_name
? parent_name
: "<unknown>");
22584 switch (parent
->tag
)
22586 case DW_TAG_namespace
:
22587 parent_type
= read_type_die (parent
, cu
);
22588 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
22589 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
22590 Work around this problem here. */
22591 if (cu
->language
== language_cplus
22592 && strcmp (TYPE_NAME (parent_type
), "::") == 0)
22594 /* We give a name to even anonymous namespaces. */
22595 return TYPE_NAME (parent_type
);
22596 case DW_TAG_class_type
:
22597 case DW_TAG_interface_type
:
22598 case DW_TAG_structure_type
:
22599 case DW_TAG_union_type
:
22600 case DW_TAG_module
:
22601 parent_type
= read_type_die (parent
, cu
);
22602 if (TYPE_NAME (parent_type
) != NULL
)
22603 return TYPE_NAME (parent_type
);
22605 /* An anonymous structure is only allowed non-static data
22606 members; no typedefs, no member functions, et cetera.
22607 So it does not need a prefix. */
22609 case DW_TAG_compile_unit
:
22610 case DW_TAG_partial_unit
:
22611 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
22612 if (cu
->language
== language_cplus
22613 && !dwarf2_per_objfile
->types
.empty ()
22614 && die
->child
!= NULL
22615 && (die
->tag
== DW_TAG_class_type
22616 || die
->tag
== DW_TAG_structure_type
22617 || die
->tag
== DW_TAG_union_type
))
22619 char *name
= guess_full_die_structure_name (die
, cu
);
22624 case DW_TAG_enumeration_type
:
22625 parent_type
= read_type_die (parent
, cu
);
22626 if (TYPE_DECLARED_CLASS (parent_type
))
22628 if (TYPE_NAME (parent_type
) != NULL
)
22629 return TYPE_NAME (parent_type
);
22632 /* Fall through. */
22634 return determine_prefix (parent
, cu
);
22638 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
22639 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
22640 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
22641 an obconcat, otherwise allocate storage for the result. The CU argument is
22642 used to determine the language and hence, the appropriate separator. */
22644 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
22647 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
22648 int physname
, struct dwarf2_cu
*cu
)
22650 const char *lead
= "";
22653 if (suffix
== NULL
|| suffix
[0] == '\0'
22654 || prefix
== NULL
|| prefix
[0] == '\0')
22656 else if (cu
->language
== language_d
)
22658 /* For D, the 'main' function could be defined in any module, but it
22659 should never be prefixed. */
22660 if (strcmp (suffix
, "D main") == 0)
22668 else if (cu
->language
== language_fortran
&& physname
)
22670 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
22671 DW_AT_MIPS_linkage_name is preferred and used instead. */
22679 if (prefix
== NULL
)
22681 if (suffix
== NULL
)
22688 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
22690 strcpy (retval
, lead
);
22691 strcat (retval
, prefix
);
22692 strcat (retval
, sep
);
22693 strcat (retval
, suffix
);
22698 /* We have an obstack. */
22699 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
22703 /* Return sibling of die, NULL if no sibling. */
22705 static struct die_info
*
22706 sibling_die (struct die_info
*die
)
22708 return die
->sibling
;
22711 /* Get name of a die, return NULL if not found. */
22713 static const char *
22714 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
22715 struct obstack
*obstack
)
22717 if (name
&& cu
->language
== language_cplus
)
22719 std::string canon_name
= cp_canonicalize_string (name
);
22721 if (!canon_name
.empty ())
22723 if (canon_name
!= name
)
22724 name
= obstack_strdup (obstack
, canon_name
);
22731 /* Get name of a die, return NULL if not found.
22732 Anonymous namespaces are converted to their magic string. */
22734 static const char *
22735 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22737 struct attribute
*attr
;
22738 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22740 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
22741 if ((!attr
|| !DW_STRING (attr
))
22742 && die
->tag
!= DW_TAG_namespace
22743 && die
->tag
!= DW_TAG_class_type
22744 && die
->tag
!= DW_TAG_interface_type
22745 && die
->tag
!= DW_TAG_structure_type
22746 && die
->tag
!= DW_TAG_union_type
)
22751 case DW_TAG_compile_unit
:
22752 case DW_TAG_partial_unit
:
22753 /* Compilation units have a DW_AT_name that is a filename, not
22754 a source language identifier. */
22755 case DW_TAG_enumeration_type
:
22756 case DW_TAG_enumerator
:
22757 /* These tags always have simple identifiers already; no need
22758 to canonicalize them. */
22759 return DW_STRING (attr
);
22761 case DW_TAG_namespace
:
22762 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
22763 return DW_STRING (attr
);
22764 return CP_ANONYMOUS_NAMESPACE_STR
;
22766 case DW_TAG_class_type
:
22767 case DW_TAG_interface_type
:
22768 case DW_TAG_structure_type
:
22769 case DW_TAG_union_type
:
22770 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
22771 structures or unions. These were of the form "._%d" in GCC 4.1,
22772 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
22773 and GCC 4.4. We work around this problem by ignoring these. */
22774 if (attr
&& DW_STRING (attr
)
22775 && (startswith (DW_STRING (attr
), "._")
22776 || startswith (DW_STRING (attr
), "<anonymous")))
22779 /* GCC might emit a nameless typedef that has a linkage name. See
22780 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22781 if (!attr
|| DW_STRING (attr
) == NULL
)
22783 char *demangled
= NULL
;
22785 attr
= dw2_linkage_name_attr (die
, cu
);
22786 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22789 /* Avoid demangling DW_STRING (attr) the second time on a second
22790 call for the same DIE. */
22791 if (!DW_STRING_IS_CANONICAL (attr
))
22792 demangled
= gdb_demangle (DW_STRING (attr
), DMGL_TYPES
);
22798 /* FIXME: we already did this for the partial symbol... */
22800 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
22802 DW_STRING_IS_CANONICAL (attr
) = 1;
22805 /* Strip any leading namespaces/classes, keep only the base name.
22806 DW_AT_name for named DIEs does not contain the prefixes. */
22807 base
= strrchr (DW_STRING (attr
), ':');
22808 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
22811 return DW_STRING (attr
);
22820 if (!DW_STRING_IS_CANONICAL (attr
))
22823 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
22824 &objfile
->per_bfd
->storage_obstack
);
22825 DW_STRING_IS_CANONICAL (attr
) = 1;
22827 return DW_STRING (attr
);
22830 /* Return the die that this die in an extension of, or NULL if there
22831 is none. *EXT_CU is the CU containing DIE on input, and the CU
22832 containing the return value on output. */
22834 static struct die_info
*
22835 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
22837 struct attribute
*attr
;
22839 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
22843 return follow_die_ref (die
, attr
, ext_cu
);
22846 /* A convenience function that returns an "unknown" DWARF name,
22847 including the value of V. STR is the name of the entity being
22848 printed, e.g., "TAG". */
22850 static const char *
22851 dwarf_unknown (const char *str
, unsigned v
)
22853 char *cell
= get_print_cell ();
22854 xsnprintf (cell
, PRINT_CELL_SIZE
, "DW_%s_<unknown: %u>", str
, v
);
22858 /* Convert a DIE tag into its string name. */
22860 static const char *
22861 dwarf_tag_name (unsigned tag
)
22863 const char *name
= get_DW_TAG_name (tag
);
22866 return dwarf_unknown ("TAG", tag
);
22871 /* Convert a DWARF attribute code into its string name. */
22873 static const char *
22874 dwarf_attr_name (unsigned attr
)
22878 #ifdef MIPS /* collides with DW_AT_HP_block_index */
22879 if (attr
== DW_AT_MIPS_fde
)
22880 return "DW_AT_MIPS_fde";
22882 if (attr
== DW_AT_HP_block_index
)
22883 return "DW_AT_HP_block_index";
22886 name
= get_DW_AT_name (attr
);
22889 return dwarf_unknown ("AT", attr
);
22894 /* Convert a unit type to corresponding DW_UT name. */
22896 static const char *
22897 dwarf_unit_type_name (int unit_type
) {
22901 return "DW_UT_compile (0x01)";
22903 return "DW_UT_type (0x02)";
22905 return "DW_UT_partial (0x03)";
22907 return "DW_UT_skeleton (0x04)";
22909 return "DW_UT_split_compile (0x05)";
22911 return "DW_UT_split_type (0x06)";
22913 return "DW_UT_lo_user (0x80)";
22915 return "DW_UT_hi_user (0xff)";
22921 /* Convert a DWARF value form code into its string name. */
22923 static const char *
22924 dwarf_form_name (unsigned form
)
22926 const char *name
= get_DW_FORM_name (form
);
22929 return dwarf_unknown ("FORM", form
);
22934 static const char *
22935 dwarf_bool_name (unsigned mybool
)
22943 /* Convert a DWARF type code into its string name. */
22945 static const char *
22946 dwarf_type_encoding_name (unsigned enc
)
22948 const char *name
= get_DW_ATE_name (enc
);
22951 return dwarf_unknown ("ATE", enc
);
22957 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
22961 print_spaces (indent
, f
);
22962 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
22963 dwarf_tag_name (die
->tag
), die
->abbrev
,
22964 sect_offset_str (die
->sect_off
));
22966 if (die
->parent
!= NULL
)
22968 print_spaces (indent
, f
);
22969 fprintf_unfiltered (f
, " parent at offset: %s\n",
22970 sect_offset_str (die
->parent
->sect_off
));
22973 print_spaces (indent
, f
);
22974 fprintf_unfiltered (f
, " has children: %s\n",
22975 dwarf_bool_name (die
->child
!= NULL
));
22977 print_spaces (indent
, f
);
22978 fprintf_unfiltered (f
, " attributes:\n");
22980 for (i
= 0; i
< die
->num_attrs
; ++i
)
22982 print_spaces (indent
, f
);
22983 fprintf_unfiltered (f
, " %s (%s) ",
22984 dwarf_attr_name (die
->attrs
[i
].name
),
22985 dwarf_form_name (die
->attrs
[i
].form
));
22987 switch (die
->attrs
[i
].form
)
22990 case DW_FORM_addrx
:
22991 case DW_FORM_GNU_addr_index
:
22992 fprintf_unfiltered (f
, "address: ");
22993 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
22995 case DW_FORM_block2
:
22996 case DW_FORM_block4
:
22997 case DW_FORM_block
:
22998 case DW_FORM_block1
:
22999 fprintf_unfiltered (f
, "block: size %s",
23000 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
23002 case DW_FORM_exprloc
:
23003 fprintf_unfiltered (f
, "expression: size %s",
23004 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
23006 case DW_FORM_data16
:
23007 fprintf_unfiltered (f
, "constant of 16 bytes");
23009 case DW_FORM_ref_addr
:
23010 fprintf_unfiltered (f
, "ref address: ");
23011 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
23013 case DW_FORM_GNU_ref_alt
:
23014 fprintf_unfiltered (f
, "alt ref address: ");
23015 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
23021 case DW_FORM_ref_udata
:
23022 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
23023 (long) (DW_UNSND (&die
->attrs
[i
])));
23025 case DW_FORM_data1
:
23026 case DW_FORM_data2
:
23027 case DW_FORM_data4
:
23028 case DW_FORM_data8
:
23029 case DW_FORM_udata
:
23030 case DW_FORM_sdata
:
23031 fprintf_unfiltered (f
, "constant: %s",
23032 pulongest (DW_UNSND (&die
->attrs
[i
])));
23034 case DW_FORM_sec_offset
:
23035 fprintf_unfiltered (f
, "section offset: %s",
23036 pulongest (DW_UNSND (&die
->attrs
[i
])));
23038 case DW_FORM_ref_sig8
:
23039 fprintf_unfiltered (f
, "signature: %s",
23040 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
23042 case DW_FORM_string
:
23044 case DW_FORM_line_strp
:
23046 case DW_FORM_GNU_str_index
:
23047 case DW_FORM_GNU_strp_alt
:
23048 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
23049 DW_STRING (&die
->attrs
[i
])
23050 ? DW_STRING (&die
->attrs
[i
]) : "",
23051 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
23054 if (DW_UNSND (&die
->attrs
[i
]))
23055 fprintf_unfiltered (f
, "flag: TRUE");
23057 fprintf_unfiltered (f
, "flag: FALSE");
23059 case DW_FORM_flag_present
:
23060 fprintf_unfiltered (f
, "flag: TRUE");
23062 case DW_FORM_indirect
:
23063 /* The reader will have reduced the indirect form to
23064 the "base form" so this form should not occur. */
23065 fprintf_unfiltered (f
,
23066 "unexpected attribute form: DW_FORM_indirect");
23068 case DW_FORM_implicit_const
:
23069 fprintf_unfiltered (f
, "constant: %s",
23070 plongest (DW_SND (&die
->attrs
[i
])));
23073 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
23074 die
->attrs
[i
].form
);
23077 fprintf_unfiltered (f
, "\n");
23082 dump_die_for_error (struct die_info
*die
)
23084 dump_die_shallow (gdb_stderr
, 0, die
);
23088 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
23090 int indent
= level
* 4;
23092 gdb_assert (die
!= NULL
);
23094 if (level
>= max_level
)
23097 dump_die_shallow (f
, indent
, die
);
23099 if (die
->child
!= NULL
)
23101 print_spaces (indent
, f
);
23102 fprintf_unfiltered (f
, " Children:");
23103 if (level
+ 1 < max_level
)
23105 fprintf_unfiltered (f
, "\n");
23106 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
23110 fprintf_unfiltered (f
,
23111 " [not printed, max nesting level reached]\n");
23115 if (die
->sibling
!= NULL
&& level
> 0)
23117 dump_die_1 (f
, level
, max_level
, die
->sibling
);
23121 /* This is called from the pdie macro in gdbinit.in.
23122 It's not static so gcc will keep a copy callable from gdb. */
23125 dump_die (struct die_info
*die
, int max_level
)
23127 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
23131 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
23135 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
23136 to_underlying (die
->sect_off
),
23142 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
23146 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
23148 if (attr_form_is_ref (attr
))
23149 return (sect_offset
) DW_UNSND (attr
);
23151 complaint (_("unsupported die ref attribute form: '%s'"),
23152 dwarf_form_name (attr
->form
));
23156 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
23157 * the value held by the attribute is not constant. */
23160 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
23162 if (attr
->form
== DW_FORM_sdata
|| attr
->form
== DW_FORM_implicit_const
)
23163 return DW_SND (attr
);
23164 else if (attr
->form
== DW_FORM_udata
23165 || attr
->form
== DW_FORM_data1
23166 || attr
->form
== DW_FORM_data2
23167 || attr
->form
== DW_FORM_data4
23168 || attr
->form
== DW_FORM_data8
)
23169 return DW_UNSND (attr
);
23172 /* For DW_FORM_data16 see attr_form_is_constant. */
23173 complaint (_("Attribute value is not a constant (%s)"),
23174 dwarf_form_name (attr
->form
));
23175 return default_value
;
23179 /* Follow reference or signature attribute ATTR of SRC_DIE.
23180 On entry *REF_CU is the CU of SRC_DIE.
23181 On exit *REF_CU is the CU of the result. */
23183 static struct die_info
*
23184 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23185 struct dwarf2_cu
**ref_cu
)
23187 struct die_info
*die
;
23189 if (attr_form_is_ref (attr
))
23190 die
= follow_die_ref (src_die
, attr
, ref_cu
);
23191 else if (attr
->form
== DW_FORM_ref_sig8
)
23192 die
= follow_die_sig (src_die
, attr
, ref_cu
);
23195 dump_die_for_error (src_die
);
23196 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
23197 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23203 /* Follow reference OFFSET.
23204 On entry *REF_CU is the CU of the source die referencing OFFSET.
23205 On exit *REF_CU is the CU of the result.
23206 Returns NULL if OFFSET is invalid. */
23208 static struct die_info
*
23209 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
23210 struct dwarf2_cu
**ref_cu
)
23212 struct die_info temp_die
;
23213 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
23214 struct dwarf2_per_objfile
*dwarf2_per_objfile
23215 = cu
->per_cu
->dwarf2_per_objfile
;
23217 gdb_assert (cu
->per_cu
!= NULL
);
23221 if (cu
->per_cu
->is_debug_types
)
23223 /* .debug_types CUs cannot reference anything outside their CU.
23224 If they need to, they have to reference a signatured type via
23225 DW_FORM_ref_sig8. */
23226 if (!offset_in_cu_p (&cu
->header
, sect_off
))
23229 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
23230 || !offset_in_cu_p (&cu
->header
, sect_off
))
23232 struct dwarf2_per_cu_data
*per_cu
;
23234 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23235 dwarf2_per_objfile
);
23237 /* If necessary, add it to the queue and load its DIEs. */
23238 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
23239 load_full_comp_unit (per_cu
, false, cu
->language
);
23241 target_cu
= per_cu
->cu
;
23243 else if (cu
->dies
== NULL
)
23245 /* We're loading full DIEs during partial symbol reading. */
23246 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
23247 load_full_comp_unit (cu
->per_cu
, false, language_minimal
);
23250 *ref_cu
= target_cu
;
23251 temp_die
.sect_off
= sect_off
;
23253 if (target_cu
!= cu
)
23254 target_cu
->ancestor
= cu
;
23256 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
23258 to_underlying (sect_off
));
23261 /* Follow reference attribute ATTR of SRC_DIE.
23262 On entry *REF_CU is the CU of SRC_DIE.
23263 On exit *REF_CU is the CU of the result. */
23265 static struct die_info
*
23266 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
23267 struct dwarf2_cu
**ref_cu
)
23269 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
23270 struct dwarf2_cu
*cu
= *ref_cu
;
23271 struct die_info
*die
;
23273 die
= follow_die_offset (sect_off
,
23274 (attr
->form
== DW_FORM_GNU_ref_alt
23275 || cu
->per_cu
->is_dwz
),
23278 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
23279 "at %s [in module %s]"),
23280 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
23281 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
23286 /* Return DWARF block referenced by DW_AT_location of DIE at SECT_OFF at PER_CU.
23287 Returned value is intended for DW_OP_call*. Returned
23288 dwarf2_locexpr_baton->data has lifetime of
23289 PER_CU->DWARF2_PER_OBJFILE->OBJFILE. */
23291 struct dwarf2_locexpr_baton
23292 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
23293 struct dwarf2_per_cu_data
*per_cu
,
23294 CORE_ADDR (*get_frame_pc
) (void *baton
),
23295 void *baton
, bool resolve_abstract_p
)
23297 struct dwarf2_cu
*cu
;
23298 struct die_info
*die
;
23299 struct attribute
*attr
;
23300 struct dwarf2_locexpr_baton retval
;
23301 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
23302 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23304 if (per_cu
->cu
== NULL
)
23305 load_cu (per_cu
, false);
23309 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23310 Instead just throw an error, not much else we can do. */
23311 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23312 sect_offset_str (sect_off
), objfile_name (objfile
));
23315 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23317 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23318 sect_offset_str (sect_off
), objfile_name (objfile
));
23320 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23321 if (!attr
&& resolve_abstract_p
23322 && (dwarf2_per_objfile
->abstract_to_concrete
.find (die
->sect_off
)
23323 != dwarf2_per_objfile
->abstract_to_concrete
.end ()))
23325 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
23327 = ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
23328 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
23330 for (const auto &cand_off
23331 : dwarf2_per_objfile
->abstract_to_concrete
[die
->sect_off
])
23333 struct dwarf2_cu
*cand_cu
= cu
;
23334 struct die_info
*cand
23335 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
23338 || cand
->parent
->tag
!= DW_TAG_subprogram
)
23341 CORE_ADDR pc_low
, pc_high
;
23342 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
23343 if (pc_low
== ((CORE_ADDR
) -1))
23345 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
23346 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
23347 if (!(pc_low
<= pc
&& pc
< pc_high
))
23351 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23358 /* DWARF: "If there is no such attribute, then there is no effect.".
23359 DATA is ignored if SIZE is 0. */
23361 retval
.data
= NULL
;
23364 else if (attr_form_is_section_offset (attr
))
23366 struct dwarf2_loclist_baton loclist_baton
;
23367 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
23370 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
23372 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
23374 retval
.size
= size
;
23378 if (!attr_form_is_block (attr
))
23379 error (_("Dwarf Error: DIE at %s referenced in module %s "
23380 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
23381 sect_offset_str (sect_off
), objfile_name (objfile
));
23383 retval
.data
= DW_BLOCK (attr
)->data
;
23384 retval
.size
= DW_BLOCK (attr
)->size
;
23386 retval
.per_cu
= cu
->per_cu
;
23388 age_cached_comp_units (dwarf2_per_objfile
);
23393 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
23396 struct dwarf2_locexpr_baton
23397 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
23398 struct dwarf2_per_cu_data
*per_cu
,
23399 CORE_ADDR (*get_frame_pc
) (void *baton
),
23402 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
23404 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
23407 /* Write a constant of a given type as target-ordered bytes into
23410 static const gdb_byte
*
23411 write_constant_as_bytes (struct obstack
*obstack
,
23412 enum bfd_endian byte_order
,
23419 *len
= TYPE_LENGTH (type
);
23420 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23421 store_unsigned_integer (result
, *len
, byte_order
, value
);
23426 /* If the DIE at OFFSET in PER_CU has a DW_AT_const_value, return a
23427 pointer to the constant bytes and set LEN to the length of the
23428 data. If memory is needed, allocate it on OBSTACK. If the DIE
23429 does not have a DW_AT_const_value, return NULL. */
23432 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
23433 struct dwarf2_per_cu_data
*per_cu
,
23434 struct obstack
*obstack
,
23437 struct dwarf2_cu
*cu
;
23438 struct die_info
*die
;
23439 struct attribute
*attr
;
23440 const gdb_byte
*result
= NULL
;
23443 enum bfd_endian byte_order
;
23444 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
23446 if (per_cu
->cu
== NULL
)
23447 load_cu (per_cu
, false);
23451 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23452 Instead just throw an error, not much else we can do. */
23453 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23454 sect_offset_str (sect_off
), objfile_name (objfile
));
23457 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23459 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23460 sect_offset_str (sect_off
), objfile_name (objfile
));
23462 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23466 byte_order
= (bfd_big_endian (objfile
->obfd
)
23467 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
23469 switch (attr
->form
)
23472 case DW_FORM_addrx
:
23473 case DW_FORM_GNU_addr_index
:
23477 *len
= cu
->header
.addr_size
;
23478 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23479 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
23483 case DW_FORM_string
:
23486 case DW_FORM_GNU_str_index
:
23487 case DW_FORM_GNU_strp_alt
:
23488 /* DW_STRING is already allocated on the objfile obstack, point
23490 result
= (const gdb_byte
*) DW_STRING (attr
);
23491 *len
= strlen (DW_STRING (attr
));
23493 case DW_FORM_block1
:
23494 case DW_FORM_block2
:
23495 case DW_FORM_block4
:
23496 case DW_FORM_block
:
23497 case DW_FORM_exprloc
:
23498 case DW_FORM_data16
:
23499 result
= DW_BLOCK (attr
)->data
;
23500 *len
= DW_BLOCK (attr
)->size
;
23503 /* The DW_AT_const_value attributes are supposed to carry the
23504 symbol's value "represented as it would be on the target
23505 architecture." By the time we get here, it's already been
23506 converted to host endianness, so we just need to sign- or
23507 zero-extend it as appropriate. */
23508 case DW_FORM_data1
:
23509 type
= die_type (die
, cu
);
23510 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
23511 if (result
== NULL
)
23512 result
= write_constant_as_bytes (obstack
, byte_order
,
23515 case DW_FORM_data2
:
23516 type
= die_type (die
, cu
);
23517 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
23518 if (result
== NULL
)
23519 result
= write_constant_as_bytes (obstack
, byte_order
,
23522 case DW_FORM_data4
:
23523 type
= die_type (die
, cu
);
23524 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
23525 if (result
== NULL
)
23526 result
= write_constant_as_bytes (obstack
, byte_order
,
23529 case DW_FORM_data8
:
23530 type
= die_type (die
, cu
);
23531 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
23532 if (result
== NULL
)
23533 result
= write_constant_as_bytes (obstack
, byte_order
,
23537 case DW_FORM_sdata
:
23538 case DW_FORM_implicit_const
:
23539 type
= die_type (die
, cu
);
23540 result
= write_constant_as_bytes (obstack
, byte_order
,
23541 type
, DW_SND (attr
), len
);
23544 case DW_FORM_udata
:
23545 type
= die_type (die
, cu
);
23546 result
= write_constant_as_bytes (obstack
, byte_order
,
23547 type
, DW_UNSND (attr
), len
);
23551 complaint (_("unsupported const value attribute form: '%s'"),
23552 dwarf_form_name (attr
->form
));
23559 /* Return the type of the die at OFFSET in PER_CU. Return NULL if no
23560 valid type for this die is found. */
23563 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
23564 struct dwarf2_per_cu_data
*per_cu
)
23566 struct dwarf2_cu
*cu
;
23567 struct die_info
*die
;
23569 if (per_cu
->cu
== NULL
)
23570 load_cu (per_cu
, false);
23575 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23579 return die_type (die
, cu
);
23582 /* Return the type of the DIE at DIE_OFFSET in the CU named by
23586 dwarf2_get_die_type (cu_offset die_offset
,
23587 struct dwarf2_per_cu_data
*per_cu
)
23589 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
23590 return get_die_type_at_offset (die_offset_sect
, per_cu
);
23593 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
23594 On entry *REF_CU is the CU of SRC_DIE.
23595 On exit *REF_CU is the CU of the result.
23596 Returns NULL if the referenced DIE isn't found. */
23598 static struct die_info
*
23599 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
23600 struct dwarf2_cu
**ref_cu
)
23602 struct die_info temp_die
;
23603 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
23604 struct die_info
*die
;
23606 /* While it might be nice to assert sig_type->type == NULL here,
23607 we can get here for DW_AT_imported_declaration where we need
23608 the DIE not the type. */
23610 /* If necessary, add it to the queue and load its DIEs. */
23612 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
23613 read_signatured_type (sig_type
);
23615 sig_cu
= sig_type
->per_cu
.cu
;
23616 gdb_assert (sig_cu
!= NULL
);
23617 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
23618 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
23619 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
23620 to_underlying (temp_die
.sect_off
));
23623 struct dwarf2_per_objfile
*dwarf2_per_objfile
23624 = (*ref_cu
)->per_cu
->dwarf2_per_objfile
;
23626 /* For .gdb_index version 7 keep track of included TUs.
23627 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
23628 if (dwarf2_per_objfile
->index_table
!= NULL
23629 && dwarf2_per_objfile
->index_table
->version
<= 7)
23631 VEC_safe_push (dwarf2_per_cu_ptr
,
23632 (*ref_cu
)->per_cu
->imported_symtabs
,
23638 sig_cu
->ancestor
= cu
;
23646 /* Follow signatured type referenced by ATTR in SRC_DIE.
23647 On entry *REF_CU is the CU of SRC_DIE.
23648 On exit *REF_CU is the CU of the result.
23649 The result is the DIE of the type.
23650 If the referenced type cannot be found an error is thrown. */
23652 static struct die_info
*
23653 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23654 struct dwarf2_cu
**ref_cu
)
23656 ULONGEST signature
= DW_SIGNATURE (attr
);
23657 struct signatured_type
*sig_type
;
23658 struct die_info
*die
;
23660 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
23662 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
23663 /* sig_type will be NULL if the signatured type is missing from
23665 if (sig_type
== NULL
)
23667 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23668 " from DIE at %s [in module %s]"),
23669 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23670 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23673 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
23676 dump_die_for_error (src_die
);
23677 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23678 " from DIE at %s [in module %s]"),
23679 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23680 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23686 /* Get the type specified by SIGNATURE referenced in DIE/CU,
23687 reading in and processing the type unit if necessary. */
23689 static struct type
*
23690 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
23691 struct dwarf2_cu
*cu
)
23693 struct dwarf2_per_objfile
*dwarf2_per_objfile
23694 = cu
->per_cu
->dwarf2_per_objfile
;
23695 struct signatured_type
*sig_type
;
23696 struct dwarf2_cu
*type_cu
;
23697 struct die_info
*type_die
;
23700 sig_type
= lookup_signatured_type (cu
, signature
);
23701 /* sig_type will be NULL if the signatured type is missing from
23703 if (sig_type
== NULL
)
23705 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23706 " from DIE at %s [in module %s]"),
23707 hex_string (signature
), sect_offset_str (die
->sect_off
),
23708 objfile_name (dwarf2_per_objfile
->objfile
));
23709 return build_error_marker_type (cu
, die
);
23712 /* If we already know the type we're done. */
23713 if (sig_type
->type
!= NULL
)
23714 return sig_type
->type
;
23717 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
23718 if (type_die
!= NULL
)
23720 /* N.B. We need to call get_die_type to ensure only one type for this DIE
23721 is created. This is important, for example, because for c++ classes
23722 we need TYPE_NAME set which is only done by new_symbol. Blech. */
23723 type
= read_type_die (type_die
, type_cu
);
23726 complaint (_("Dwarf Error: Cannot build signatured type %s"
23727 " referenced from DIE at %s [in module %s]"),
23728 hex_string (signature
), sect_offset_str (die
->sect_off
),
23729 objfile_name (dwarf2_per_objfile
->objfile
));
23730 type
= build_error_marker_type (cu
, die
);
23735 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23736 " from DIE at %s [in module %s]"),
23737 hex_string (signature
), sect_offset_str (die
->sect_off
),
23738 objfile_name (dwarf2_per_objfile
->objfile
));
23739 type
= build_error_marker_type (cu
, die
);
23741 sig_type
->type
= type
;
23746 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
23747 reading in and processing the type unit if necessary. */
23749 static struct type
*
23750 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
23751 struct dwarf2_cu
*cu
) /* ARI: editCase function */
23753 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
23754 if (attr_form_is_ref (attr
))
23756 struct dwarf2_cu
*type_cu
= cu
;
23757 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
23759 return read_type_die (type_die
, type_cu
);
23761 else if (attr
->form
== DW_FORM_ref_sig8
)
23763 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
23767 struct dwarf2_per_objfile
*dwarf2_per_objfile
23768 = cu
->per_cu
->dwarf2_per_objfile
;
23770 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
23771 " at %s [in module %s]"),
23772 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
23773 objfile_name (dwarf2_per_objfile
->objfile
));
23774 return build_error_marker_type (cu
, die
);
23778 /* Load the DIEs associated with type unit PER_CU into memory. */
23781 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
23783 struct signatured_type
*sig_type
;
23785 /* Caller is responsible for ensuring type_unit_groups don't get here. */
23786 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
23788 /* We have the per_cu, but we need the signatured_type.
23789 Fortunately this is an easy translation. */
23790 gdb_assert (per_cu
->is_debug_types
);
23791 sig_type
= (struct signatured_type
*) per_cu
;
23793 gdb_assert (per_cu
->cu
== NULL
);
23795 read_signatured_type (sig_type
);
23797 gdb_assert (per_cu
->cu
!= NULL
);
23800 /* die_reader_func for read_signatured_type.
23801 This is identical to load_full_comp_unit_reader,
23802 but is kept separate for now. */
23805 read_signatured_type_reader (const struct die_reader_specs
*reader
,
23806 const gdb_byte
*info_ptr
,
23807 struct die_info
*comp_unit_die
,
23811 struct dwarf2_cu
*cu
= reader
->cu
;
23813 gdb_assert (cu
->die_hash
== NULL
);
23815 htab_create_alloc_ex (cu
->header
.length
/ 12,
23819 &cu
->comp_unit_obstack
,
23820 hashtab_obstack_allocate
,
23821 dummy_obstack_deallocate
);
23824 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
23825 &info_ptr
, comp_unit_die
);
23826 cu
->dies
= comp_unit_die
;
23827 /* comp_unit_die is not stored in die_hash, no need. */
23829 /* We try not to read any attributes in this function, because not
23830 all CUs needed for references have been loaded yet, and symbol
23831 table processing isn't initialized. But we have to set the CU language,
23832 or we won't be able to build types correctly.
23833 Similarly, if we do not read the producer, we can not apply
23834 producer-specific interpretation. */
23835 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
23838 /* Read in a signatured type and build its CU and DIEs.
23839 If the type is a stub for the real type in a DWO file,
23840 read in the real type from the DWO file as well. */
23843 read_signatured_type (struct signatured_type
*sig_type
)
23845 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
23847 gdb_assert (per_cu
->is_debug_types
);
23848 gdb_assert (per_cu
->cu
== NULL
);
23850 init_cutu_and_read_dies (per_cu
, NULL
, 0, 1, false,
23851 read_signatured_type_reader
, NULL
);
23852 sig_type
->per_cu
.tu_read
= 1;
23855 /* Decode simple location descriptions.
23856 Given a pointer to a dwarf block that defines a location, compute
23857 the location and return the value.
23859 NOTE drow/2003-11-18: This function is called in two situations
23860 now: for the address of static or global variables (partial symbols
23861 only) and for offsets into structures which are expected to be
23862 (more or less) constant. The partial symbol case should go away,
23863 and only the constant case should remain. That will let this
23864 function complain more accurately. A few special modes are allowed
23865 without complaint for global variables (for instance, global
23866 register values and thread-local values).
23868 A location description containing no operations indicates that the
23869 object is optimized out. The return value is 0 for that case.
23870 FIXME drow/2003-11-16: No callers check for this case any more; soon all
23871 callers will only want a very basic result and this can become a
23874 Note that stack[0] is unused except as a default error return. */
23877 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
23879 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
23881 size_t size
= blk
->size
;
23882 const gdb_byte
*data
= blk
->data
;
23883 CORE_ADDR stack
[64];
23885 unsigned int bytes_read
, unsnd
;
23891 stack
[++stacki
] = 0;
23930 stack
[++stacki
] = op
- DW_OP_lit0
;
23965 stack
[++stacki
] = op
- DW_OP_reg0
;
23967 dwarf2_complex_location_expr_complaint ();
23971 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
23973 stack
[++stacki
] = unsnd
;
23975 dwarf2_complex_location_expr_complaint ();
23979 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
23984 case DW_OP_const1u
:
23985 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
23989 case DW_OP_const1s
:
23990 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
23994 case DW_OP_const2u
:
23995 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
23999 case DW_OP_const2s
:
24000 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
24004 case DW_OP_const4u
:
24005 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
24009 case DW_OP_const4s
:
24010 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
24014 case DW_OP_const8u
:
24015 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
24020 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
24026 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
24031 stack
[stacki
+ 1] = stack
[stacki
];
24036 stack
[stacki
- 1] += stack
[stacki
];
24040 case DW_OP_plus_uconst
:
24041 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
24047 stack
[stacki
- 1] -= stack
[stacki
];
24052 /* If we're not the last op, then we definitely can't encode
24053 this using GDB's address_class enum. This is valid for partial
24054 global symbols, although the variable's address will be bogus
24057 dwarf2_complex_location_expr_complaint ();
24060 case DW_OP_GNU_push_tls_address
:
24061 case DW_OP_form_tls_address
:
24062 /* The top of the stack has the offset from the beginning
24063 of the thread control block at which the variable is located. */
24064 /* Nothing should follow this operator, so the top of stack would
24066 /* This is valid for partial global symbols, but the variable's
24067 address will be bogus in the psymtab. Make it always at least
24068 non-zero to not look as a variable garbage collected by linker
24069 which have DW_OP_addr 0. */
24071 dwarf2_complex_location_expr_complaint ();
24075 case DW_OP_GNU_uninit
:
24079 case DW_OP_GNU_addr_index
:
24080 case DW_OP_GNU_const_index
:
24081 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
24088 const char *name
= get_DW_OP_name (op
);
24091 complaint (_("unsupported stack op: '%s'"),
24094 complaint (_("unsupported stack op: '%02x'"),
24098 return (stack
[stacki
]);
24101 /* Enforce maximum stack depth of SIZE-1 to avoid writing
24102 outside of the allocated space. Also enforce minimum>0. */
24103 if (stacki
>= ARRAY_SIZE (stack
) - 1)
24105 complaint (_("location description stack overflow"));
24111 complaint (_("location description stack underflow"));
24115 return (stack
[stacki
]);
24118 /* memory allocation interface */
24120 static struct dwarf_block
*
24121 dwarf_alloc_block (struct dwarf2_cu
*cu
)
24123 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
24126 static struct die_info
*
24127 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
24129 struct die_info
*die
;
24130 size_t size
= sizeof (struct die_info
);
24133 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
24135 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
24136 memset (die
, 0, sizeof (struct die_info
));
24141 /* Macro support. */
24143 /* Return file name relative to the compilation directory of file number I in
24144 *LH's file name table. The result is allocated using xmalloc; the caller is
24145 responsible for freeing it. */
24148 file_file_name (int file
, struct line_header
*lh
)
24150 /* Is the file number a valid index into the line header's file name
24151 table? Remember that file numbers start with one, not zero. */
24152 if (1 <= file
&& file
<= lh
->file_names
.size ())
24154 const file_entry
&fe
= lh
->file_names
[file
- 1];
24156 if (!IS_ABSOLUTE_PATH (fe
.name
))
24158 const char *dir
= fe
.include_dir (lh
);
24160 return concat (dir
, SLASH_STRING
, fe
.name
, (char *) NULL
);
24162 return xstrdup (fe
.name
);
24166 /* The compiler produced a bogus file number. We can at least
24167 record the macro definitions made in the file, even if we
24168 won't be able to find the file by name. */
24169 char fake_name
[80];
24171 xsnprintf (fake_name
, sizeof (fake_name
),
24172 "<bad macro file number %d>", file
);
24174 complaint (_("bad file number in macro information (%d)"),
24177 return xstrdup (fake_name
);
24181 /* Return the full name of file number I in *LH's file name table.
24182 Use COMP_DIR as the name of the current directory of the
24183 compilation. The result is allocated using xmalloc; the caller is
24184 responsible for freeing it. */
24186 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
24188 /* Is the file number a valid index into the line header's file name
24189 table? Remember that file numbers start with one, not zero. */
24190 if (1 <= file
&& file
<= lh
->file_names
.size ())
24192 char *relative
= file_file_name (file
, lh
);
24194 if (IS_ABSOLUTE_PATH (relative
) || comp_dir
== NULL
)
24196 return reconcat (relative
, comp_dir
, SLASH_STRING
,
24197 relative
, (char *) NULL
);
24200 return file_file_name (file
, lh
);
24204 static struct macro_source_file
*
24205 macro_start_file (struct dwarf2_cu
*cu
,
24206 int file
, int line
,
24207 struct macro_source_file
*current_file
,
24208 struct line_header
*lh
)
24210 /* File name relative to the compilation directory of this source file. */
24211 char *file_name
= file_file_name (file
, lh
);
24213 if (! current_file
)
24215 /* Note: We don't create a macro table for this compilation unit
24216 at all until we actually get a filename. */
24217 struct macro_table
*macro_table
= cu
->get_builder ()->get_macro_table ();
24219 /* If we have no current file, then this must be the start_file
24220 directive for the compilation unit's main source file. */
24221 current_file
= macro_set_main (macro_table
, file_name
);
24222 macro_define_special (macro_table
);
24225 current_file
= macro_include (current_file
, line
, file_name
);
24229 return current_file
;
24232 static const char *
24233 consume_improper_spaces (const char *p
, const char *body
)
24237 complaint (_("macro definition contains spaces "
24238 "in formal argument list:\n`%s'"),
24250 parse_macro_definition (struct macro_source_file
*file
, int line
,
24255 /* The body string takes one of two forms. For object-like macro
24256 definitions, it should be:
24258 <macro name> " " <definition>
24260 For function-like macro definitions, it should be:
24262 <macro name> "() " <definition>
24264 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
24266 Spaces may appear only where explicitly indicated, and in the
24269 The Dwarf 2 spec says that an object-like macro's name is always
24270 followed by a space, but versions of GCC around March 2002 omit
24271 the space when the macro's definition is the empty string.
24273 The Dwarf 2 spec says that there should be no spaces between the
24274 formal arguments in a function-like macro's formal argument list,
24275 but versions of GCC around March 2002 include spaces after the
24279 /* Find the extent of the macro name. The macro name is terminated
24280 by either a space or null character (for an object-like macro) or
24281 an opening paren (for a function-like macro). */
24282 for (p
= body
; *p
; p
++)
24283 if (*p
== ' ' || *p
== '(')
24286 if (*p
== ' ' || *p
== '\0')
24288 /* It's an object-like macro. */
24289 int name_len
= p
- body
;
24290 char *name
= savestring (body
, name_len
);
24291 const char *replacement
;
24294 replacement
= body
+ name_len
+ 1;
24297 dwarf2_macro_malformed_definition_complaint (body
);
24298 replacement
= body
+ name_len
;
24301 macro_define_object (file
, line
, name
, replacement
);
24305 else if (*p
== '(')
24307 /* It's a function-like macro. */
24308 char *name
= savestring (body
, p
- body
);
24311 char **argv
= XNEWVEC (char *, argv_size
);
24315 p
= consume_improper_spaces (p
, body
);
24317 /* Parse the formal argument list. */
24318 while (*p
&& *p
!= ')')
24320 /* Find the extent of the current argument name. */
24321 const char *arg_start
= p
;
24323 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
24326 if (! *p
|| p
== arg_start
)
24327 dwarf2_macro_malformed_definition_complaint (body
);
24330 /* Make sure argv has room for the new argument. */
24331 if (argc
>= argv_size
)
24334 argv
= XRESIZEVEC (char *, argv
, argv_size
);
24337 argv
[argc
++] = savestring (arg_start
, p
- arg_start
);
24340 p
= consume_improper_spaces (p
, body
);
24342 /* Consume the comma, if present. */
24347 p
= consume_improper_spaces (p
, body
);
24356 /* Perfectly formed definition, no complaints. */
24357 macro_define_function (file
, line
, name
,
24358 argc
, (const char **) argv
,
24360 else if (*p
== '\0')
24362 /* Complain, but do define it. */
24363 dwarf2_macro_malformed_definition_complaint (body
);
24364 macro_define_function (file
, line
, name
,
24365 argc
, (const char **) argv
,
24369 /* Just complain. */
24370 dwarf2_macro_malformed_definition_complaint (body
);
24373 /* Just complain. */
24374 dwarf2_macro_malformed_definition_complaint (body
);
24380 for (i
= 0; i
< argc
; i
++)
24386 dwarf2_macro_malformed_definition_complaint (body
);
24389 /* Skip some bytes from BYTES according to the form given in FORM.
24390 Returns the new pointer. */
24392 static const gdb_byte
*
24393 skip_form_bytes (bfd
*abfd
, const gdb_byte
*bytes
, const gdb_byte
*buffer_end
,
24394 enum dwarf_form form
,
24395 unsigned int offset_size
,
24396 struct dwarf2_section_info
*section
)
24398 unsigned int bytes_read
;
24402 case DW_FORM_data1
:
24407 case DW_FORM_data2
:
24411 case DW_FORM_data4
:
24415 case DW_FORM_data8
:
24419 case DW_FORM_data16
:
24423 case DW_FORM_string
:
24424 read_direct_string (abfd
, bytes
, &bytes_read
);
24425 bytes
+= bytes_read
;
24428 case DW_FORM_sec_offset
:
24430 case DW_FORM_GNU_strp_alt
:
24431 bytes
+= offset_size
;
24434 case DW_FORM_block
:
24435 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
24436 bytes
+= bytes_read
;
24439 case DW_FORM_block1
:
24440 bytes
+= 1 + read_1_byte (abfd
, bytes
);
24442 case DW_FORM_block2
:
24443 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
24445 case DW_FORM_block4
:
24446 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
24449 case DW_FORM_addrx
:
24450 case DW_FORM_sdata
:
24452 case DW_FORM_udata
:
24453 case DW_FORM_GNU_addr_index
:
24454 case DW_FORM_GNU_str_index
:
24455 bytes
= gdb_skip_leb128 (bytes
, buffer_end
);
24458 dwarf2_section_buffer_overflow_complaint (section
);
24463 case DW_FORM_implicit_const
:
24468 complaint (_("invalid form 0x%x in `%s'"),
24469 form
, get_section_name (section
));
24477 /* A helper for dwarf_decode_macros that handles skipping an unknown
24478 opcode. Returns an updated pointer to the macro data buffer; or,
24479 on error, issues a complaint and returns NULL. */
24481 static const gdb_byte
*
24482 skip_unknown_opcode (unsigned int opcode
,
24483 const gdb_byte
**opcode_definitions
,
24484 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24486 unsigned int offset_size
,
24487 struct dwarf2_section_info
*section
)
24489 unsigned int bytes_read
, i
;
24491 const gdb_byte
*defn
;
24493 if (opcode_definitions
[opcode
] == NULL
)
24495 complaint (_("unrecognized DW_MACFINO opcode 0x%x"),
24500 defn
= opcode_definitions
[opcode
];
24501 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
24502 defn
+= bytes_read
;
24504 for (i
= 0; i
< arg
; ++i
)
24506 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
,
24507 (enum dwarf_form
) defn
[i
], offset_size
,
24509 if (mac_ptr
== NULL
)
24511 /* skip_form_bytes already issued the complaint. */
24519 /* A helper function which parses the header of a macro section.
24520 If the macro section is the extended (for now called "GNU") type,
24521 then this updates *OFFSET_SIZE. Returns a pointer to just after
24522 the header, or issues a complaint and returns NULL on error. */
24524 static const gdb_byte
*
24525 dwarf_parse_macro_header (const gdb_byte
**opcode_definitions
,
24527 const gdb_byte
*mac_ptr
,
24528 unsigned int *offset_size
,
24529 int section_is_gnu
)
24531 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
24533 if (section_is_gnu
)
24535 unsigned int version
, flags
;
24537 version
= read_2_bytes (abfd
, mac_ptr
);
24538 if (version
!= 4 && version
!= 5)
24540 complaint (_("unrecognized version `%d' in .debug_macro section"),
24546 flags
= read_1_byte (abfd
, mac_ptr
);
24548 *offset_size
= (flags
& 1) ? 8 : 4;
24550 if ((flags
& 2) != 0)
24551 /* We don't need the line table offset. */
24552 mac_ptr
+= *offset_size
;
24554 /* Vendor opcode descriptions. */
24555 if ((flags
& 4) != 0)
24557 unsigned int i
, count
;
24559 count
= read_1_byte (abfd
, mac_ptr
);
24561 for (i
= 0; i
< count
; ++i
)
24563 unsigned int opcode
, bytes_read
;
24566 opcode
= read_1_byte (abfd
, mac_ptr
);
24568 opcode_definitions
[opcode
] = mac_ptr
;
24569 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24570 mac_ptr
+= bytes_read
;
24579 /* A helper for dwarf_decode_macros that handles the GNU extensions,
24580 including DW_MACRO_import. */
24583 dwarf_decode_macro_bytes (struct dwarf2_cu
*cu
,
24585 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24586 struct macro_source_file
*current_file
,
24587 struct line_header
*lh
,
24588 struct dwarf2_section_info
*section
,
24589 int section_is_gnu
, int section_is_dwz
,
24590 unsigned int offset_size
,
24591 htab_t include_hash
)
24593 struct dwarf2_per_objfile
*dwarf2_per_objfile
24594 = cu
->per_cu
->dwarf2_per_objfile
;
24595 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24596 enum dwarf_macro_record_type macinfo_type
;
24597 int at_commandline
;
24598 const gdb_byte
*opcode_definitions
[256];
24600 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
24601 &offset_size
, section_is_gnu
);
24602 if (mac_ptr
== NULL
)
24604 /* We already issued a complaint. */
24608 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
24609 GDB is still reading the definitions from command line. First
24610 DW_MACINFO_start_file will need to be ignored as it was already executed
24611 to create CURRENT_FILE for the main source holding also the command line
24612 definitions. On first met DW_MACINFO_start_file this flag is reset to
24613 normally execute all the remaining DW_MACINFO_start_file macinfos. */
24615 at_commandline
= 1;
24619 /* Do we at least have room for a macinfo type byte? */
24620 if (mac_ptr
>= mac_end
)
24622 dwarf2_section_buffer_overflow_complaint (section
);
24626 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
24629 /* Note that we rely on the fact that the corresponding GNU and
24630 DWARF constants are the same. */
24632 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
24633 switch (macinfo_type
)
24635 /* A zero macinfo type indicates the end of the macro
24640 case DW_MACRO_define
:
24641 case DW_MACRO_undef
:
24642 case DW_MACRO_define_strp
:
24643 case DW_MACRO_undef_strp
:
24644 case DW_MACRO_define_sup
:
24645 case DW_MACRO_undef_sup
:
24647 unsigned int bytes_read
;
24652 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24653 mac_ptr
+= bytes_read
;
24655 if (macinfo_type
== DW_MACRO_define
24656 || macinfo_type
== DW_MACRO_undef
)
24658 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24659 mac_ptr
+= bytes_read
;
24663 LONGEST str_offset
;
24665 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
24666 mac_ptr
+= offset_size
;
24668 if (macinfo_type
== DW_MACRO_define_sup
24669 || macinfo_type
== DW_MACRO_undef_sup
24672 struct dwz_file
*dwz
24673 = dwarf2_get_dwz_file (dwarf2_per_objfile
);
24675 body
= read_indirect_string_from_dwz (objfile
,
24679 body
= read_indirect_string_at_offset (dwarf2_per_objfile
,
24683 is_define
= (macinfo_type
== DW_MACRO_define
24684 || macinfo_type
== DW_MACRO_define_strp
24685 || macinfo_type
== DW_MACRO_define_sup
);
24686 if (! current_file
)
24688 /* DWARF violation as no main source is present. */
24689 complaint (_("debug info with no main source gives macro %s "
24691 is_define
? _("definition") : _("undefinition"),
24695 if ((line
== 0 && !at_commandline
)
24696 || (line
!= 0 && at_commandline
))
24697 complaint (_("debug info gives %s macro %s with %s line %d: %s"),
24698 at_commandline
? _("command-line") : _("in-file"),
24699 is_define
? _("definition") : _("undefinition"),
24700 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
24704 /* Fedora's rpm-build's "debugedit" binary
24705 corrupted .debug_macro sections.
24708 https://bugzilla.redhat.com/show_bug.cgi?id=1708786 */
24709 complaint (_("debug info gives %s invalid macro %s "
24710 "without body (corrupted?) at line %d "
24712 at_commandline
? _("command-line") : _("in-file"),
24713 is_define
? _("definition") : _("undefinition"),
24714 line
, current_file
->filename
);
24716 else if (is_define
)
24717 parse_macro_definition (current_file
, line
, body
);
24720 gdb_assert (macinfo_type
== DW_MACRO_undef
24721 || macinfo_type
== DW_MACRO_undef_strp
24722 || macinfo_type
== DW_MACRO_undef_sup
);
24723 macro_undef (current_file
, line
, body
);
24728 case DW_MACRO_start_file
:
24730 unsigned int bytes_read
;
24733 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24734 mac_ptr
+= bytes_read
;
24735 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24736 mac_ptr
+= bytes_read
;
24738 if ((line
== 0 && !at_commandline
)
24739 || (line
!= 0 && at_commandline
))
24740 complaint (_("debug info gives source %d included "
24741 "from %s at %s line %d"),
24742 file
, at_commandline
? _("command-line") : _("file"),
24743 line
== 0 ? _("zero") : _("non-zero"), line
);
24745 if (at_commandline
)
24747 /* This DW_MACRO_start_file was executed in the
24749 at_commandline
= 0;
24752 current_file
= macro_start_file (cu
, file
, line
, current_file
,
24757 case DW_MACRO_end_file
:
24758 if (! current_file
)
24759 complaint (_("macro debug info has an unmatched "
24760 "`close_file' directive"));
24763 current_file
= current_file
->included_by
;
24764 if (! current_file
)
24766 enum dwarf_macro_record_type next_type
;
24768 /* GCC circa March 2002 doesn't produce the zero
24769 type byte marking the end of the compilation
24770 unit. Complain if it's not there, but exit no
24773 /* Do we at least have room for a macinfo type byte? */
24774 if (mac_ptr
>= mac_end
)
24776 dwarf2_section_buffer_overflow_complaint (section
);
24780 /* We don't increment mac_ptr here, so this is just
24783 = (enum dwarf_macro_record_type
) read_1_byte (abfd
,
24785 if (next_type
!= 0)
24786 complaint (_("no terminating 0-type entry for "
24787 "macros in `.debug_macinfo' section"));
24794 case DW_MACRO_import
:
24795 case DW_MACRO_import_sup
:
24799 bfd
*include_bfd
= abfd
;
24800 struct dwarf2_section_info
*include_section
= section
;
24801 const gdb_byte
*include_mac_end
= mac_end
;
24802 int is_dwz
= section_is_dwz
;
24803 const gdb_byte
*new_mac_ptr
;
24805 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
24806 mac_ptr
+= offset_size
;
24808 if (macinfo_type
== DW_MACRO_import_sup
)
24810 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
24812 dwarf2_read_section (objfile
, &dwz
->macro
);
24814 include_section
= &dwz
->macro
;
24815 include_bfd
= get_section_bfd_owner (include_section
);
24816 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
24820 new_mac_ptr
= include_section
->buffer
+ offset
;
24821 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
24825 /* This has actually happened; see
24826 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
24827 complaint (_("recursive DW_MACRO_import in "
24828 ".debug_macro section"));
24832 *slot
= (void *) new_mac_ptr
;
24834 dwarf_decode_macro_bytes (cu
, include_bfd
, new_mac_ptr
,
24835 include_mac_end
, current_file
, lh
,
24836 section
, section_is_gnu
, is_dwz
,
24837 offset_size
, include_hash
);
24839 htab_remove_elt (include_hash
, (void *) new_mac_ptr
);
24844 case DW_MACINFO_vendor_ext
:
24845 if (!section_is_gnu
)
24847 unsigned int bytes_read
;
24849 /* This reads the constant, but since we don't recognize
24850 any vendor extensions, we ignore it. */
24851 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24852 mac_ptr
+= bytes_read
;
24853 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24854 mac_ptr
+= bytes_read
;
24856 /* We don't recognize any vendor extensions. */
24862 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
24863 mac_ptr
, mac_end
, abfd
, offset_size
,
24865 if (mac_ptr
== NULL
)
24870 } while (macinfo_type
!= 0);
24874 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
24875 int section_is_gnu
)
24877 struct dwarf2_per_objfile
*dwarf2_per_objfile
24878 = cu
->per_cu
->dwarf2_per_objfile
;
24879 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24880 struct line_header
*lh
= cu
->line_header
;
24882 const gdb_byte
*mac_ptr
, *mac_end
;
24883 struct macro_source_file
*current_file
= 0;
24884 enum dwarf_macro_record_type macinfo_type
;
24885 unsigned int offset_size
= cu
->header
.offset_size
;
24886 const gdb_byte
*opcode_definitions
[256];
24888 struct dwarf2_section_info
*section
;
24889 const char *section_name
;
24891 if (cu
->dwo_unit
!= NULL
)
24893 if (section_is_gnu
)
24895 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
24896 section_name
= ".debug_macro.dwo";
24900 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
24901 section_name
= ".debug_macinfo.dwo";
24906 if (section_is_gnu
)
24908 section
= &dwarf2_per_objfile
->macro
;
24909 section_name
= ".debug_macro";
24913 section
= &dwarf2_per_objfile
->macinfo
;
24914 section_name
= ".debug_macinfo";
24918 dwarf2_read_section (objfile
, section
);
24919 if (section
->buffer
== NULL
)
24921 complaint (_("missing %s section"), section_name
);
24924 abfd
= get_section_bfd_owner (section
);
24926 /* First pass: Find the name of the base filename.
24927 This filename is needed in order to process all macros whose definition
24928 (or undefinition) comes from the command line. These macros are defined
24929 before the first DW_MACINFO_start_file entry, and yet still need to be
24930 associated to the base file.
24932 To determine the base file name, we scan the macro definitions until we
24933 reach the first DW_MACINFO_start_file entry. We then initialize
24934 CURRENT_FILE accordingly so that any macro definition found before the
24935 first DW_MACINFO_start_file can still be associated to the base file. */
24937 mac_ptr
= section
->buffer
+ offset
;
24938 mac_end
= section
->buffer
+ section
->size
;
24940 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
24941 &offset_size
, section_is_gnu
);
24942 if (mac_ptr
== NULL
)
24944 /* We already issued a complaint. */
24950 /* Do we at least have room for a macinfo type byte? */
24951 if (mac_ptr
>= mac_end
)
24953 /* Complaint is printed during the second pass as GDB will probably
24954 stop the first pass earlier upon finding
24955 DW_MACINFO_start_file. */
24959 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
24962 /* Note that we rely on the fact that the corresponding GNU and
24963 DWARF constants are the same. */
24965 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
24966 switch (macinfo_type
)
24968 /* A zero macinfo type indicates the end of the macro
24973 case DW_MACRO_define
:
24974 case DW_MACRO_undef
:
24975 /* Only skip the data by MAC_PTR. */
24977 unsigned int bytes_read
;
24979 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24980 mac_ptr
+= bytes_read
;
24981 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24982 mac_ptr
+= bytes_read
;
24986 case DW_MACRO_start_file
:
24988 unsigned int bytes_read
;
24991 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24992 mac_ptr
+= bytes_read
;
24993 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24994 mac_ptr
+= bytes_read
;
24996 current_file
= macro_start_file (cu
, file
, line
, current_file
, lh
);
25000 case DW_MACRO_end_file
:
25001 /* No data to skip by MAC_PTR. */
25004 case DW_MACRO_define_strp
:
25005 case DW_MACRO_undef_strp
:
25006 case DW_MACRO_define_sup
:
25007 case DW_MACRO_undef_sup
:
25009 unsigned int bytes_read
;
25011 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25012 mac_ptr
+= bytes_read
;
25013 mac_ptr
+= offset_size
;
25017 case DW_MACRO_import
:
25018 case DW_MACRO_import_sup
:
25019 /* Note that, according to the spec, a transparent include
25020 chain cannot call DW_MACRO_start_file. So, we can just
25021 skip this opcode. */
25022 mac_ptr
+= offset_size
;
25025 case DW_MACINFO_vendor_ext
:
25026 /* Only skip the data by MAC_PTR. */
25027 if (!section_is_gnu
)
25029 unsigned int bytes_read
;
25031 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25032 mac_ptr
+= bytes_read
;
25033 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
25034 mac_ptr
+= bytes_read
;
25039 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
25040 mac_ptr
, mac_end
, abfd
, offset_size
,
25042 if (mac_ptr
== NULL
)
25047 } while (macinfo_type
!= 0 && current_file
== NULL
);
25049 /* Second pass: Process all entries.
25051 Use the AT_COMMAND_LINE flag to determine whether we are still processing
25052 command-line macro definitions/undefinitions. This flag is unset when we
25053 reach the first DW_MACINFO_start_file entry. */
25055 htab_up
include_hash (htab_create_alloc (1, htab_hash_pointer
,
25057 NULL
, xcalloc
, xfree
));
25058 mac_ptr
= section
->buffer
+ offset
;
25059 slot
= htab_find_slot (include_hash
.get (), mac_ptr
, INSERT
);
25060 *slot
= (void *) mac_ptr
;
25061 dwarf_decode_macro_bytes (cu
, abfd
, mac_ptr
, mac_end
,
25062 current_file
, lh
, section
,
25063 section_is_gnu
, 0, offset_size
,
25064 include_hash
.get ());
25067 /* Check if the attribute's form is a DW_FORM_block*
25068 if so return true else false. */
25071 attr_form_is_block (const struct attribute
*attr
)
25073 return (attr
== NULL
? 0 :
25074 attr
->form
== DW_FORM_block1
25075 || attr
->form
== DW_FORM_block2
25076 || attr
->form
== DW_FORM_block4
25077 || attr
->form
== DW_FORM_block
25078 || attr
->form
== DW_FORM_exprloc
);
25081 /* Return non-zero if ATTR's value is a section offset --- classes
25082 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
25083 You may use DW_UNSND (attr) to retrieve such offsets.
25085 Section 7.5.4, "Attribute Encodings", explains that no attribute
25086 may have a value that belongs to more than one of these classes; it
25087 would be ambiguous if we did, because we use the same forms for all
25091 attr_form_is_section_offset (const struct attribute
*attr
)
25093 return (attr
->form
== DW_FORM_data4
25094 || attr
->form
== DW_FORM_data8
25095 || attr
->form
== DW_FORM_sec_offset
);
25098 /* Return non-zero if ATTR's value falls in the 'constant' class, or
25099 zero otherwise. When this function returns true, you can apply
25100 dwarf2_get_attr_constant_value to it.
25102 However, note that for some attributes you must check
25103 attr_form_is_section_offset before using this test. DW_FORM_data4
25104 and DW_FORM_data8 are members of both the constant class, and of
25105 the classes that contain offsets into other debug sections
25106 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
25107 that, if an attribute's can be either a constant or one of the
25108 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
25109 taken as section offsets, not constants.
25111 DW_FORM_data16 is not considered as dwarf2_get_attr_constant_value
25112 cannot handle that. */
25115 attr_form_is_constant (const struct attribute
*attr
)
25117 switch (attr
->form
)
25119 case DW_FORM_sdata
:
25120 case DW_FORM_udata
:
25121 case DW_FORM_data1
:
25122 case DW_FORM_data2
:
25123 case DW_FORM_data4
:
25124 case DW_FORM_data8
:
25125 case DW_FORM_implicit_const
:
25133 /* DW_ADDR is always stored already as sect_offset; despite for the forms
25134 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
25137 attr_form_is_ref (const struct attribute
*attr
)
25139 switch (attr
->form
)
25141 case DW_FORM_ref_addr
:
25146 case DW_FORM_ref_udata
:
25147 case DW_FORM_GNU_ref_alt
:
25154 /* Return the .debug_loc section to use for CU.
25155 For DWO files use .debug_loc.dwo. */
25157 static struct dwarf2_section_info
*
25158 cu_debug_loc_section (struct dwarf2_cu
*cu
)
25160 struct dwarf2_per_objfile
*dwarf2_per_objfile
25161 = cu
->per_cu
->dwarf2_per_objfile
;
25165 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
25167 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
25169 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
25170 : &dwarf2_per_objfile
->loc
);
25173 /* A helper function that fills in a dwarf2_loclist_baton. */
25176 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
25177 struct dwarf2_loclist_baton
*baton
,
25178 const struct attribute
*attr
)
25180 struct dwarf2_per_objfile
*dwarf2_per_objfile
25181 = cu
->per_cu
->dwarf2_per_objfile
;
25182 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
25184 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
25186 baton
->per_cu
= cu
->per_cu
;
25187 gdb_assert (baton
->per_cu
);
25188 /* We don't know how long the location list is, but make sure we
25189 don't run off the edge of the section. */
25190 baton
->size
= section
->size
- DW_UNSND (attr
);
25191 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
25192 baton
->base_address
= cu
->base_address
;
25193 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
25197 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
25198 struct dwarf2_cu
*cu
, int is_block
)
25200 struct dwarf2_per_objfile
*dwarf2_per_objfile
25201 = cu
->per_cu
->dwarf2_per_objfile
;
25202 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25203 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
25205 if (attr_form_is_section_offset (attr
)
25206 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
25207 the section. If so, fall through to the complaint in the
25209 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
25211 struct dwarf2_loclist_baton
*baton
;
25213 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
25215 fill_in_loclist_baton (cu
, baton
, attr
);
25217 if (cu
->base_known
== 0)
25218 complaint (_("Location list used without "
25219 "specifying the CU base address."));
25221 SYMBOL_ACLASS_INDEX (sym
) = (is_block
25222 ? dwarf2_loclist_block_index
25223 : dwarf2_loclist_index
);
25224 SYMBOL_LOCATION_BATON (sym
) = baton
;
25228 struct dwarf2_locexpr_baton
*baton
;
25230 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
25231 baton
->per_cu
= cu
->per_cu
;
25232 gdb_assert (baton
->per_cu
);
25234 if (attr_form_is_block (attr
))
25236 /* Note that we're just copying the block's data pointer
25237 here, not the actual data. We're still pointing into the
25238 info_buffer for SYM's objfile; right now we never release
25239 that buffer, but when we do clean up properly this may
25241 baton
->size
= DW_BLOCK (attr
)->size
;
25242 baton
->data
= DW_BLOCK (attr
)->data
;
25246 dwarf2_invalid_attrib_class_complaint ("location description",
25247 SYMBOL_NATURAL_NAME (sym
));
25251 SYMBOL_ACLASS_INDEX (sym
) = (is_block
25252 ? dwarf2_locexpr_block_index
25253 : dwarf2_locexpr_index
);
25254 SYMBOL_LOCATION_BATON (sym
) = baton
;
25258 /* Return the OBJFILE associated with the compilation unit CU. If CU
25259 came from a separate debuginfo file, then the master objfile is
25263 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
25265 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
25267 /* Return the master objfile, so that we can report and look up the
25268 correct file containing this variable. */
25269 if (objfile
->separate_debug_objfile_backlink
)
25270 objfile
= objfile
->separate_debug_objfile_backlink
;
25275 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
25276 (CU_HEADERP is unused in such case) or prepare a temporary copy at
25277 CU_HEADERP first. */
25279 static const struct comp_unit_head
*
25280 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
25281 struct dwarf2_per_cu_data
*per_cu
)
25283 const gdb_byte
*info_ptr
;
25286 return &per_cu
->cu
->header
;
25288 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
25290 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
25291 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
25292 rcuh_kind::COMPILE
);
25297 /* Return the address size given in the compilation unit header for CU. */
25300 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
25302 struct comp_unit_head cu_header_local
;
25303 const struct comp_unit_head
*cu_headerp
;
25305 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25307 return cu_headerp
->addr_size
;
25310 /* Return the offset size given in the compilation unit header for CU. */
25313 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
25315 struct comp_unit_head cu_header_local
;
25316 const struct comp_unit_head
*cu_headerp
;
25318 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25320 return cu_headerp
->offset_size
;
25323 /* See its dwarf2loc.h declaration. */
25326 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
25328 struct comp_unit_head cu_header_local
;
25329 const struct comp_unit_head
*cu_headerp
;
25331 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25333 if (cu_headerp
->version
== 2)
25334 return cu_headerp
->addr_size
;
25336 return cu_headerp
->offset_size
;
25339 /* Return the text offset of the CU. The returned offset comes from
25340 this CU's objfile. If this objfile came from a separate debuginfo
25341 file, then the offset may be different from the corresponding
25342 offset in the parent objfile. */
25345 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
25347 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
25349 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
25352 /* Return a type that is a generic pointer type, the size of which matches
25353 the address size given in the compilation unit header for PER_CU. */
25354 static struct type
*
25355 dwarf2_per_cu_addr_type (struct dwarf2_per_cu_data
*per_cu
)
25357 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
25358 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
25359 struct type
*addr_type
= lookup_pointer_type (void_type
);
25360 int addr_size
= dwarf2_per_cu_addr_size (per_cu
);
25362 if (TYPE_LENGTH (addr_type
) == addr_size
)
25366 = dwarf2_per_cu_addr_sized_int_type (per_cu
, TYPE_UNSIGNED (addr_type
));
25370 /* Return DWARF version number of PER_CU. */
25373 dwarf2_version (struct dwarf2_per_cu_data
*per_cu
)
25375 return per_cu
->dwarf_version
;
25378 /* Locate the .debug_info compilation unit from CU's objfile which contains
25379 the DIE at OFFSET. Raises an error on failure. */
25381 static struct dwarf2_per_cu_data
*
25382 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
25383 unsigned int offset_in_dwz
,
25384 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
25386 struct dwarf2_per_cu_data
*this_cu
;
25390 high
= dwarf2_per_objfile
->all_comp_units
.size () - 1;
25393 struct dwarf2_per_cu_data
*mid_cu
;
25394 int mid
= low
+ (high
- low
) / 2;
25396 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
25397 if (mid_cu
->is_dwz
> offset_in_dwz
25398 || (mid_cu
->is_dwz
== offset_in_dwz
25399 && mid_cu
->sect_off
+ mid_cu
->length
>= sect_off
))
25404 gdb_assert (low
== high
);
25405 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
25406 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
25408 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
25409 error (_("Dwarf Error: could not find partial DIE containing "
25410 "offset %s [in module %s]"),
25411 sect_offset_str (sect_off
),
25412 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
25414 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
25416 return dwarf2_per_objfile
->all_comp_units
[low
-1];
25420 if (low
== dwarf2_per_objfile
->all_comp_units
.size () - 1
25421 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
25422 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
25423 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
25428 /* Initialize dwarf2_cu CU, owned by PER_CU. */
25430 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data
*per_cu_
)
25431 : per_cu (per_cu_
),
25433 has_loclist (false),
25434 checked_producer (false),
25435 producer_is_gxx_lt_4_6 (false),
25436 producer_is_gcc_lt_4_3 (false),
25437 producer_is_icc (false),
25438 producer_is_icc_lt_14 (false),
25439 producer_is_codewarrior (false),
25440 processing_has_namespace_info (false)
25445 /* Destroy a dwarf2_cu. */
25447 dwarf2_cu::~dwarf2_cu ()
25452 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
25455 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
25456 enum language pretend_language
)
25458 struct attribute
*attr
;
25460 /* Set the language we're debugging. */
25461 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
25463 set_cu_language (DW_UNSND (attr
), cu
);
25466 cu
->language
= pretend_language
;
25467 cu
->language_defn
= language_def (cu
->language
);
25470 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
25473 /* Increase the age counter on each cached compilation unit, and free
25474 any that are too old. */
25477 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
25479 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25481 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
25482 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25483 while (per_cu
!= NULL
)
25485 per_cu
->cu
->last_used
++;
25486 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
25487 dwarf2_mark (per_cu
->cu
);
25488 per_cu
= per_cu
->cu
->read_in_chain
;
25491 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25492 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25493 while (per_cu
!= NULL
)
25495 struct dwarf2_per_cu_data
*next_cu
;
25497 next_cu
= per_cu
->cu
->read_in_chain
;
25499 if (!per_cu
->cu
->mark
)
25502 *last_chain
= next_cu
;
25505 last_chain
= &per_cu
->cu
->read_in_chain
;
25511 /* Remove a single compilation unit from the cache. */
25514 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
25516 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25517 struct dwarf2_per_objfile
*dwarf2_per_objfile
25518 = target_per_cu
->dwarf2_per_objfile
;
25520 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25521 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25522 while (per_cu
!= NULL
)
25524 struct dwarf2_per_cu_data
*next_cu
;
25526 next_cu
= per_cu
->cu
->read_in_chain
;
25528 if (per_cu
== target_per_cu
)
25532 *last_chain
= next_cu
;
25536 last_chain
= &per_cu
->cu
->read_in_chain
;
25542 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
25543 We store these in a hash table separate from the DIEs, and preserve them
25544 when the DIEs are flushed out of cache.
25546 The CU "per_cu" pointer is needed because offset alone is not enough to
25547 uniquely identify the type. A file may have multiple .debug_types sections,
25548 or the type may come from a DWO file. Furthermore, while it's more logical
25549 to use per_cu->section+offset, with Fission the section with the data is in
25550 the DWO file but we don't know that section at the point we need it.
25551 We have to use something in dwarf2_per_cu_data (or the pointer to it)
25552 because we can enter the lookup routine, get_die_type_at_offset, from
25553 outside this file, and thus won't necessarily have PER_CU->cu.
25554 Fortunately, PER_CU is stable for the life of the objfile. */
25556 struct dwarf2_per_cu_offset_and_type
25558 const struct dwarf2_per_cu_data
*per_cu
;
25559 sect_offset sect_off
;
25563 /* Hash function for a dwarf2_per_cu_offset_and_type. */
25566 per_cu_offset_and_type_hash (const void *item
)
25568 const struct dwarf2_per_cu_offset_and_type
*ofs
25569 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
25571 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
25574 /* Equality function for a dwarf2_per_cu_offset_and_type. */
25577 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
25579 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
25580 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
25581 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
25582 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
25584 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
25585 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
25588 /* Set the type associated with DIE to TYPE. Save it in CU's hash
25589 table if necessary. For convenience, return TYPE.
25591 The DIEs reading must have careful ordering to:
25592 * Not cause infite loops trying to read in DIEs as a prerequisite for
25593 reading current DIE.
25594 * Not trying to dereference contents of still incompletely read in types
25595 while reading in other DIEs.
25596 * Enable referencing still incompletely read in types just by a pointer to
25597 the type without accessing its fields.
25599 Therefore caller should follow these rules:
25600 * Try to fetch any prerequisite types we may need to build this DIE type
25601 before building the type and calling set_die_type.
25602 * After building type call set_die_type for current DIE as soon as
25603 possible before fetching more types to complete the current type.
25604 * Make the type as complete as possible before fetching more types. */
25606 static struct type
*
25607 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
25609 struct dwarf2_per_objfile
*dwarf2_per_objfile
25610 = cu
->per_cu
->dwarf2_per_objfile
;
25611 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
25612 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25613 struct attribute
*attr
;
25614 struct dynamic_prop prop
;
25616 /* For Ada types, make sure that the gnat-specific data is always
25617 initialized (if not already set). There are a few types where
25618 we should not be doing so, because the type-specific area is
25619 already used to hold some other piece of info (eg: TYPE_CODE_FLT
25620 where the type-specific area is used to store the floatformat).
25621 But this is not a problem, because the gnat-specific information
25622 is actually not needed for these types. */
25623 if (need_gnat_info (cu
)
25624 && TYPE_CODE (type
) != TYPE_CODE_FUNC
25625 && TYPE_CODE (type
) != TYPE_CODE_FLT
25626 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
25627 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
25628 && TYPE_CODE (type
) != TYPE_CODE_METHOD
25629 && !HAVE_GNAT_AUX_INFO (type
))
25630 INIT_GNAT_SPECIFIC (type
);
25632 /* Read DW_AT_allocated and set in type. */
25633 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
25634 if (attr_form_is_block (attr
))
25636 struct type
*prop_type
25637 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
25638 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
25639 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
);
25641 else if (attr
!= NULL
)
25643 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
25644 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25645 sect_offset_str (die
->sect_off
));
25648 /* Read DW_AT_associated and set in type. */
25649 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
25650 if (attr_form_is_block (attr
))
25652 struct type
*prop_type
25653 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
25654 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
25655 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
);
25657 else if (attr
!= NULL
)
25659 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
25660 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25661 sect_offset_str (die
->sect_off
));
25664 /* Read DW_AT_data_location and set in type. */
25665 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
25666 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
,
25667 dwarf2_per_cu_addr_type (cu
->per_cu
)))
25668 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
);
25670 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25672 dwarf2_per_objfile
->die_type_hash
=
25673 htab_create_alloc_ex (127,
25674 per_cu_offset_and_type_hash
,
25675 per_cu_offset_and_type_eq
,
25677 &objfile
->objfile_obstack
,
25678 hashtab_obstack_allocate
,
25679 dummy_obstack_deallocate
);
25682 ofs
.per_cu
= cu
->per_cu
;
25683 ofs
.sect_off
= die
->sect_off
;
25685 slot
= (struct dwarf2_per_cu_offset_and_type
**)
25686 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
25688 complaint (_("A problem internal to GDB: DIE %s has type already set"),
25689 sect_offset_str (die
->sect_off
));
25690 *slot
= XOBNEW (&objfile
->objfile_obstack
,
25691 struct dwarf2_per_cu_offset_and_type
);
25696 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
25697 or return NULL if the die does not have a saved type. */
25699 static struct type
*
25700 get_die_type_at_offset (sect_offset sect_off
,
25701 struct dwarf2_per_cu_data
*per_cu
)
25703 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
25704 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
25706 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25709 ofs
.per_cu
= per_cu
;
25710 ofs
.sect_off
= sect_off
;
25711 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
25712 htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
));
25719 /* Look up the type for DIE in CU in die_type_hash,
25720 or return NULL if DIE does not have a saved type. */
25722 static struct type
*
25723 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
25725 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
25728 /* Add a dependence relationship from CU to REF_PER_CU. */
25731 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
25732 struct dwarf2_per_cu_data
*ref_per_cu
)
25736 if (cu
->dependencies
== NULL
)
25738 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
25739 NULL
, &cu
->comp_unit_obstack
,
25740 hashtab_obstack_allocate
,
25741 dummy_obstack_deallocate
);
25743 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
25745 *slot
= ref_per_cu
;
25748 /* Subroutine of dwarf2_mark to pass to htab_traverse.
25749 Set the mark field in every compilation unit in the
25750 cache that we must keep because we are keeping CU. */
25753 dwarf2_mark_helper (void **slot
, void *data
)
25755 struct dwarf2_per_cu_data
*per_cu
;
25757 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
25759 /* cu->dependencies references may not yet have been ever read if QUIT aborts
25760 reading of the chain. As such dependencies remain valid it is not much
25761 useful to track and undo them during QUIT cleanups. */
25762 if (per_cu
->cu
== NULL
)
25765 if (per_cu
->cu
->mark
)
25767 per_cu
->cu
->mark
= true;
25769 if (per_cu
->cu
->dependencies
!= NULL
)
25770 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
25775 /* Set the mark field in CU and in every other compilation unit in the
25776 cache that we must keep because we are keeping CU. */
25779 dwarf2_mark (struct dwarf2_cu
*cu
)
25784 if (cu
->dependencies
!= NULL
)
25785 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
25789 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
25793 per_cu
->cu
->mark
= false;
25794 per_cu
= per_cu
->cu
->read_in_chain
;
25798 /* Trivial hash function for partial_die_info: the hash value of a DIE
25799 is its offset in .debug_info for this objfile. */
25802 partial_die_hash (const void *item
)
25804 const struct partial_die_info
*part_die
25805 = (const struct partial_die_info
*) item
;
25807 return to_underlying (part_die
->sect_off
);
25810 /* Trivial comparison function for partial_die_info structures: two DIEs
25811 are equal if they have the same offset. */
25814 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
25816 const struct partial_die_info
*part_die_lhs
25817 = (const struct partial_die_info
*) item_lhs
;
25818 const struct partial_die_info
*part_die_rhs
25819 = (const struct partial_die_info
*) item_rhs
;
25821 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
25824 struct cmd_list_element
*set_dwarf_cmdlist
;
25825 struct cmd_list_element
*show_dwarf_cmdlist
;
25828 set_dwarf_cmd (const char *args
, int from_tty
)
25830 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
25835 show_dwarf_cmd (const char *args
, int from_tty
)
25837 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
25840 bool dwarf_always_disassemble
;
25843 show_dwarf_always_disassemble (struct ui_file
*file
, int from_tty
,
25844 struct cmd_list_element
*c
, const char *value
)
25846 fprintf_filtered (file
,
25847 _("Whether to always disassemble "
25848 "DWARF expressions is %s.\n"),
25853 show_check_physname (struct ui_file
*file
, int from_tty
,
25854 struct cmd_list_element
*c
, const char *value
)
25856 fprintf_filtered (file
,
25857 _("Whether to check \"physname\" is %s.\n"),
25862 _initialize_dwarf2_read (void)
25864 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
25865 Set DWARF specific variables.\n\
25866 Configure DWARF variables such as the cache size."),
25867 &set_dwarf_cmdlist
, "maintenance set dwarf ",
25868 0/*allow-unknown*/, &maintenance_set_cmdlist
);
25870 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
25871 Show DWARF specific variables.\n\
25872 Show DWARF variables such as the cache size."),
25873 &show_dwarf_cmdlist
, "maintenance show dwarf ",
25874 0/*allow-unknown*/, &maintenance_show_cmdlist
);
25876 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
25877 &dwarf_max_cache_age
, _("\
25878 Set the upper bound on the age of cached DWARF compilation units."), _("\
25879 Show the upper bound on the age of cached DWARF compilation units."), _("\
25880 A higher limit means that cached compilation units will be stored\n\
25881 in memory longer, and more total memory will be used. Zero disables\n\
25882 caching, which can slow down startup."),
25884 show_dwarf_max_cache_age
,
25885 &set_dwarf_cmdlist
,
25886 &show_dwarf_cmdlist
);
25888 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
25889 &dwarf_always_disassemble
, _("\
25890 Set whether `info address' always disassembles DWARF expressions."), _("\
25891 Show whether `info address' always disassembles DWARF expressions."), _("\
25892 When enabled, DWARF expressions are always printed in an assembly-like\n\
25893 syntax. When disabled, expressions will be printed in a more\n\
25894 conversational style, when possible."),
25896 show_dwarf_always_disassemble
,
25897 &set_dwarf_cmdlist
,
25898 &show_dwarf_cmdlist
);
25900 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
25901 Set debugging of the DWARF reader."), _("\
25902 Show debugging of the DWARF reader."), _("\
25903 When enabled (non-zero), debugging messages are printed during DWARF\n\
25904 reading and symtab expansion. A value of 1 (one) provides basic\n\
25905 information. A value greater than 1 provides more verbose information."),
25908 &setdebuglist
, &showdebuglist
);
25910 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
25911 Set debugging of the DWARF DIE reader."), _("\
25912 Show debugging of the DWARF DIE reader."), _("\
25913 When enabled (non-zero), DIEs are dumped after they are read in.\n\
25914 The value is the maximum depth to print."),
25917 &setdebuglist
, &showdebuglist
);
25919 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
25920 Set debugging of the dwarf line reader."), _("\
25921 Show debugging of the dwarf line reader."), _("\
25922 When enabled (non-zero), line number entries are dumped as they are read in.\n\
25923 A value of 1 (one) provides basic information.\n\
25924 A value greater than 1 provides more verbose information."),
25927 &setdebuglist
, &showdebuglist
);
25929 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
25930 Set cross-checking of \"physname\" code against demangler."), _("\
25931 Show cross-checking of \"physname\" code against demangler."), _("\
25932 When enabled, GDB's internal \"physname\" code is checked against\n\
25934 NULL
, show_check_physname
,
25935 &setdebuglist
, &showdebuglist
);
25937 add_setshow_boolean_cmd ("use-deprecated-index-sections",
25938 no_class
, &use_deprecated_index_sections
, _("\
25939 Set whether to use deprecated gdb_index sections."), _("\
25940 Show whether to use deprecated gdb_index sections."), _("\
25941 When enabled, deprecated .gdb_index sections are used anyway.\n\
25942 Normally they are ignored either because of a missing feature or\n\
25943 performance issue.\n\
25944 Warning: This option must be enabled before gdb reads the file."),
25947 &setlist
, &showlist
);
25949 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
25950 &dwarf2_locexpr_funcs
);
25951 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
25952 &dwarf2_loclist_funcs
);
25954 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
25955 &dwarf2_block_frame_base_locexpr_funcs
);
25956 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
25957 &dwarf2_block_frame_base_loclist_funcs
);
25960 selftests::register_test ("dw2_expand_symtabs_matching",
25961 selftests::dw2_expand_symtabs_matching::run_test
);