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 non-zero, cross-check physname against demangler. */
106 static int check_physname
= 0;
108 /* When non-zero, do not reject deprecated .gdb_index sections. */
109 static int use_deprecated_index_sections
= 0;
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
) const;
184 /* Prevent deleting/destroying via a base class pointer. */
186 ~mapped_index_base() = default;
189 /* A description of the mapped index. The file format is described in
190 a comment by the code that writes the index. */
191 struct mapped_index final
: public mapped_index_base
193 /* A slot/bucket in the symbol table hash. */
194 struct symbol_table_slot
196 const offset_type name
;
197 const offset_type vec
;
200 /* Index data format version. */
203 /* The address table data. */
204 gdb::array_view
<const gdb_byte
> address_table
;
206 /* The symbol table, implemented as a hash table. */
207 gdb::array_view
<symbol_table_slot
> symbol_table
;
209 /* A pointer to the constant pool. */
210 const char *constant_pool
= nullptr;
212 bool symbol_name_slot_invalid (offset_type idx
) const override
214 const auto &bucket
= this->symbol_table
[idx
];
215 return bucket
.name
== 0 && bucket
.vec
== 0;
218 /* Convenience method to get at the name of the symbol at IDX in the
220 const char *symbol_name_at (offset_type idx
) const override
221 { return this->constant_pool
+ MAYBE_SWAP (this->symbol_table
[idx
].name
); }
223 size_t symbol_name_count () const override
224 { return this->symbol_table
.size (); }
227 /* A description of the mapped .debug_names.
228 Uninitialized map has CU_COUNT 0. */
229 struct mapped_debug_names final
: public mapped_index_base
231 mapped_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile_
)
232 : dwarf2_per_objfile (dwarf2_per_objfile_
)
235 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
236 bfd_endian dwarf5_byte_order
;
237 bool dwarf5_is_dwarf64
;
238 bool augmentation_is_gdb
;
240 uint32_t cu_count
= 0;
241 uint32_t tu_count
, bucket_count
, name_count
;
242 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
243 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
244 const gdb_byte
*name_table_string_offs_reordered
;
245 const gdb_byte
*name_table_entry_offs_reordered
;
246 const gdb_byte
*entry_pool
;
253 /* Attribute name DW_IDX_*. */
256 /* Attribute form DW_FORM_*. */
259 /* Value if FORM is DW_FORM_implicit_const. */
260 LONGEST implicit_const
;
262 std::vector
<attr
> attr_vec
;
265 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
267 const char *namei_to_name (uint32_t namei
) const;
269 /* Implementation of the mapped_index_base virtual interface, for
270 the name_components cache. */
272 const char *symbol_name_at (offset_type idx
) const override
273 { return namei_to_name (idx
); }
275 size_t symbol_name_count () const override
276 { return this->name_count
; }
279 /* See dwarf2read.h. */
282 get_dwarf2_per_objfile (struct objfile
*objfile
)
284 return dwarf2_objfile_data_key
.get (objfile
);
287 /* Default names of the debugging sections. */
289 /* Note that if the debugging section has been compressed, it might
290 have a name like .zdebug_info. */
292 static const struct dwarf2_debug_sections dwarf2_elf_names
=
294 { ".debug_info", ".zdebug_info" },
295 { ".debug_abbrev", ".zdebug_abbrev" },
296 { ".debug_line", ".zdebug_line" },
297 { ".debug_loc", ".zdebug_loc" },
298 { ".debug_loclists", ".zdebug_loclists" },
299 { ".debug_macinfo", ".zdebug_macinfo" },
300 { ".debug_macro", ".zdebug_macro" },
301 { ".debug_str", ".zdebug_str" },
302 { ".debug_line_str", ".zdebug_line_str" },
303 { ".debug_ranges", ".zdebug_ranges" },
304 { ".debug_rnglists", ".zdebug_rnglists" },
305 { ".debug_types", ".zdebug_types" },
306 { ".debug_addr", ".zdebug_addr" },
307 { ".debug_frame", ".zdebug_frame" },
308 { ".eh_frame", NULL
},
309 { ".gdb_index", ".zgdb_index" },
310 { ".debug_names", ".zdebug_names" },
311 { ".debug_aranges", ".zdebug_aranges" },
315 /* List of DWO/DWP sections. */
317 static const struct dwop_section_names
319 struct dwarf2_section_names abbrev_dwo
;
320 struct dwarf2_section_names info_dwo
;
321 struct dwarf2_section_names line_dwo
;
322 struct dwarf2_section_names loc_dwo
;
323 struct dwarf2_section_names loclists_dwo
;
324 struct dwarf2_section_names macinfo_dwo
;
325 struct dwarf2_section_names macro_dwo
;
326 struct dwarf2_section_names str_dwo
;
327 struct dwarf2_section_names str_offsets_dwo
;
328 struct dwarf2_section_names types_dwo
;
329 struct dwarf2_section_names cu_index
;
330 struct dwarf2_section_names tu_index
;
334 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
335 { ".debug_info.dwo", ".zdebug_info.dwo" },
336 { ".debug_line.dwo", ".zdebug_line.dwo" },
337 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
338 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
339 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
340 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
341 { ".debug_str.dwo", ".zdebug_str.dwo" },
342 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
343 { ".debug_types.dwo", ".zdebug_types.dwo" },
344 { ".debug_cu_index", ".zdebug_cu_index" },
345 { ".debug_tu_index", ".zdebug_tu_index" },
348 /* local data types */
350 /* The data in a compilation unit header, after target2host
351 translation, looks like this. */
352 struct comp_unit_head
356 unsigned char addr_size
;
357 unsigned char signed_addr_p
;
358 sect_offset abbrev_sect_off
;
360 /* Size of file offsets; either 4 or 8. */
361 unsigned int offset_size
;
363 /* Size of the length field; either 4 or 12. */
364 unsigned int initial_length_size
;
366 enum dwarf_unit_type unit_type
;
368 /* Offset to the first byte of this compilation unit header in the
369 .debug_info section, for resolving relative reference dies. */
370 sect_offset sect_off
;
372 /* Offset to first die in this cu from the start of the cu.
373 This will be the first byte following the compilation unit header. */
374 cu_offset first_die_cu_offset
;
377 /* 64-bit signature of this unit. For type units, it denotes the signature of
378 the type (DW_UT_type in DWARF 4, additionally DW_UT_split_type in DWARF 5).
379 Also used in DWARF 5, to denote the dwo id when the unit type is
380 DW_UT_skeleton or DW_UT_split_compile. */
383 /* For types, offset in the type's DIE of the type defined by this TU. */
384 cu_offset type_cu_offset_in_tu
;
387 /* Type used for delaying computation of method physnames.
388 See comments for compute_delayed_physnames. */
389 struct delayed_method_info
391 /* The type to which the method is attached, i.e., its parent class. */
394 /* The index of the method in the type's function fieldlists. */
397 /* The index of the method in the fieldlist. */
400 /* The name of the DIE. */
403 /* The DIE associated with this method. */
404 struct die_info
*die
;
407 /* Internal state when decoding a particular compilation unit. */
410 explicit dwarf2_cu (struct dwarf2_per_cu_data
*per_cu
);
413 DISABLE_COPY_AND_ASSIGN (dwarf2_cu
);
415 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
416 Create the set of symtabs used by this TU, or if this TU is sharing
417 symtabs with another TU and the symtabs have already been created
418 then restore those symtabs in the line header.
419 We don't need the pc/line-number mapping for type units. */
420 void setup_type_unit_groups (struct die_info
*die
);
422 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
423 buildsym_compunit constructor. */
424 struct compunit_symtab
*start_symtab (const char *name
,
425 const char *comp_dir
,
428 /* Reset the builder. */
429 void reset_builder () { m_builder
.reset (); }
431 /* The header of the compilation unit. */
432 struct comp_unit_head header
{};
434 /* Base address of this compilation unit. */
435 CORE_ADDR base_address
= 0;
437 /* Non-zero if base_address has been set. */
440 /* The language we are debugging. */
441 enum language language
= language_unknown
;
442 const struct language_defn
*language_defn
= nullptr;
444 const char *producer
= nullptr;
447 /* The symtab builder for this CU. This is only non-NULL when full
448 symbols are being read. */
449 std::unique_ptr
<buildsym_compunit
> m_builder
;
452 /* The generic symbol table building routines have separate lists for
453 file scope symbols and all all other scopes (local scopes). So
454 we need to select the right one to pass to add_symbol_to_list().
455 We do it by keeping a pointer to the correct list in list_in_scope.
457 FIXME: The original dwarf code just treated the file scope as the
458 first local scope, and all other local scopes as nested local
459 scopes, and worked fine. Check to see if we really need to
460 distinguish these in buildsym.c. */
461 struct pending
**list_in_scope
= nullptr;
463 /* Hash table holding all the loaded partial DIEs
464 with partial_die->offset.SECT_OFF as hash. */
465 htab_t partial_dies
= nullptr;
467 /* Storage for things with the same lifetime as this read-in compilation
468 unit, including partial DIEs. */
469 auto_obstack comp_unit_obstack
;
471 /* When multiple dwarf2_cu structures are living in memory, this field
472 chains them all together, so that they can be released efficiently.
473 We will probably also want a generation counter so that most-recently-used
474 compilation units are cached... */
475 struct dwarf2_per_cu_data
*read_in_chain
= nullptr;
477 /* Backlink to our per_cu entry. */
478 struct dwarf2_per_cu_data
*per_cu
;
480 /* How many compilation units ago was this CU last referenced? */
483 /* A hash table of DIE cu_offset for following references with
484 die_info->offset.sect_off as hash. */
485 htab_t die_hash
= nullptr;
487 /* Full DIEs if read in. */
488 struct die_info
*dies
= nullptr;
490 /* A set of pointers to dwarf2_per_cu_data objects for compilation
491 units referenced by this one. Only set during full symbol processing;
492 partial symbol tables do not have dependencies. */
493 htab_t dependencies
= nullptr;
495 /* Header data from the line table, during full symbol processing. */
496 struct line_header
*line_header
= nullptr;
497 /* Non-NULL if LINE_HEADER is owned by this DWARF_CU. Otherwise,
498 it's owned by dwarf2_per_objfile::line_header_hash. If non-NULL,
499 this is the DW_TAG_compile_unit die for this CU. We'll hold on
500 to the line header as long as this DIE is being processed. See
501 process_die_scope. */
502 die_info
*line_header_die_owner
= nullptr;
504 /* A list of methods which need to have physnames computed
505 after all type information has been read. */
506 std::vector
<delayed_method_info
> method_list
;
508 /* To be copied to symtab->call_site_htab. */
509 htab_t call_site_htab
= nullptr;
511 /* Non-NULL if this CU came from a DWO file.
512 There is an invariant here that is important to remember:
513 Except for attributes copied from the top level DIE in the "main"
514 (or "stub") file in preparation for reading the DWO file
515 (e.g., DW_AT_GNU_addr_base), we KISS: there is only *one* CU.
516 Either there isn't a DWO file (in which case this is NULL and the point
517 is moot), or there is and either we're not going to read it (in which
518 case this is NULL) or there is and we are reading it (in which case this
520 struct dwo_unit
*dwo_unit
= nullptr;
522 /* The DW_AT_addr_base attribute if present, zero otherwise
523 (zero is a valid value though).
524 Note this value comes from the Fission stub CU/TU's DIE. */
525 ULONGEST addr_base
= 0;
527 /* The DW_AT_ranges_base attribute if present, zero otherwise
528 (zero is a valid value though).
529 Note this value comes from the Fission stub CU/TU's DIE.
530 Also note that the value is zero in the non-DWO case so this value can
531 be used without needing to know whether DWO files are in use or not.
532 N.B. This does not apply to DW_AT_ranges appearing in
533 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
534 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
535 DW_AT_ranges_base *would* have to be applied, and we'd have to care
536 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
537 ULONGEST ranges_base
= 0;
539 /* When reading debug info generated by older versions of rustc, we
540 have to rewrite some union types to be struct types with a
541 variant part. This rewriting must be done after the CU is fully
542 read in, because otherwise at the point of rewriting some struct
543 type might not have been fully processed. So, we keep a list of
544 all such types here and process them after expansion. */
545 std::vector
<struct type
*> rust_unions
;
547 /* Mark used when releasing cached dies. */
550 /* This CU references .debug_loc. See the symtab->locations_valid field.
551 This test is imperfect as there may exist optimized debug code not using
552 any location list and still facing inlining issues if handled as
553 unoptimized code. For a future better test see GCC PR other/32998. */
554 bool has_loclist
: 1;
556 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is true
557 if all the producer_is_* fields are valid. This information is cached
558 because profiling CU expansion showed excessive time spent in
559 producer_is_gxx_lt_4_6. */
560 bool checked_producer
: 1;
561 bool producer_is_gxx_lt_4_6
: 1;
562 bool producer_is_gcc_lt_4_3
: 1;
563 bool producer_is_icc
: 1;
564 bool producer_is_icc_lt_14
: 1;
565 bool producer_is_codewarrior
: 1;
567 /* When true, the file that we're processing is known to have
568 debugging info for C++ namespaces. GCC 3.3.x did not produce
569 this information, but later versions do. */
571 bool processing_has_namespace_info
: 1;
573 struct partial_die_info
*find_partial_die (sect_offset sect_off
);
575 /* If this CU was inherited by another CU (via specification,
576 abstract_origin, etc), this is the ancestor CU. */
579 /* Get the buildsym_compunit for this CU. */
580 buildsym_compunit
*get_builder ()
582 /* If this CU has a builder associated with it, use that. */
583 if (m_builder
!= nullptr)
584 return m_builder
.get ();
586 /* Otherwise, search ancestors for a valid builder. */
587 if (ancestor
!= nullptr)
588 return ancestor
->get_builder ();
594 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
595 This includes type_unit_group and quick_file_names. */
597 struct stmt_list_hash
599 /* The DWO unit this table is from or NULL if there is none. */
600 struct dwo_unit
*dwo_unit
;
602 /* Offset in .debug_line or .debug_line.dwo. */
603 sect_offset line_sect_off
;
606 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
607 an object of this type. */
609 struct type_unit_group
611 /* dwarf2read.c's main "handle" on a TU symtab.
612 To simplify things we create an artificial CU that "includes" all the
613 type units using this stmt_list so that the rest of the code still has
614 a "per_cu" handle on the symtab.
615 This PER_CU is recognized by having no section. */
616 #define IS_TYPE_UNIT_GROUP(per_cu) ((per_cu)->section == NULL)
617 struct dwarf2_per_cu_data per_cu
;
619 /* The TUs that share this DW_AT_stmt_list entry.
620 This is added to while parsing type units to build partial symtabs,
621 and is deleted afterwards and not used again. */
622 VEC (sig_type_ptr
) *tus
;
624 /* The compunit symtab.
625 Type units in a group needn't all be defined in the same source file,
626 so we create an essentially anonymous symtab as the compunit symtab. */
627 struct compunit_symtab
*compunit_symtab
;
629 /* The data used to construct the hash key. */
630 struct stmt_list_hash hash
;
632 /* The number of symtabs from the line header.
633 The value here must match line_header.num_file_names. */
634 unsigned int num_symtabs
;
636 /* The symbol tables for this TU (obtained from the files listed in
638 WARNING: The order of entries here must match the order of entries
639 in the line header. After the first TU using this type_unit_group, the
640 line header for the subsequent TUs is recreated from this. This is done
641 because we need to use the same symtabs for each TU using the same
642 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
643 there's no guarantee the line header doesn't have duplicate entries. */
644 struct symtab
**symtabs
;
647 /* These sections are what may appear in a (real or virtual) DWO file. */
651 struct dwarf2_section_info abbrev
;
652 struct dwarf2_section_info line
;
653 struct dwarf2_section_info loc
;
654 struct dwarf2_section_info loclists
;
655 struct dwarf2_section_info macinfo
;
656 struct dwarf2_section_info macro
;
657 struct dwarf2_section_info str
;
658 struct dwarf2_section_info str_offsets
;
659 /* In the case of a virtual DWO file, these two are unused. */
660 struct dwarf2_section_info info
;
661 std::vector
<dwarf2_section_info
> types
;
664 /* CUs/TUs in DWP/DWO files. */
668 /* Backlink to the containing struct dwo_file. */
669 struct dwo_file
*dwo_file
;
671 /* The "id" that distinguishes this CU/TU.
672 .debug_info calls this "dwo_id", .debug_types calls this "signature".
673 Since signatures came first, we stick with it for consistency. */
676 /* The section this CU/TU lives in, in the DWO file. */
677 struct dwarf2_section_info
*section
;
679 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
680 sect_offset sect_off
;
683 /* For types, offset in the type's DIE of the type defined by this TU. */
684 cu_offset type_offset_in_tu
;
687 /* include/dwarf2.h defines the DWP section codes.
688 It defines a max value but it doesn't define a min value, which we
689 use for error checking, so provide one. */
691 enum dwp_v2_section_ids
696 /* Data for one DWO file.
698 This includes virtual DWO files (a virtual DWO file is a DWO file as it
699 appears in a DWP file). DWP files don't really have DWO files per se -
700 comdat folding of types "loses" the DWO file they came from, and from
701 a high level view DWP files appear to contain a mass of random types.
702 However, to maintain consistency with the non-DWP case we pretend DWP
703 files contain virtual DWO files, and we assign each TU with one virtual
704 DWO file (generally based on the line and abbrev section offsets -
705 a heuristic that seems to work in practice). */
709 dwo_file () = default;
710 DISABLE_COPY_AND_ASSIGN (dwo_file
);
712 /* The DW_AT_GNU_dwo_name attribute.
713 For virtual DWO files the name is constructed from the section offsets
714 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
715 from related CU+TUs. */
716 const char *dwo_name
= nullptr;
718 /* The DW_AT_comp_dir attribute. */
719 const char *comp_dir
= nullptr;
721 /* The bfd, when the file is open. Otherwise this is NULL.
722 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
723 gdb_bfd_ref_ptr dbfd
;
725 /* The sections that make up this DWO file.
726 Remember that for virtual DWO files in DWP V2, these are virtual
727 sections (for lack of a better name). */
728 struct dwo_sections sections
{};
730 /* The CUs in the file.
731 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
732 an extension to handle LLVM's Link Time Optimization output (where
733 multiple source files may be compiled into a single object/dwo pair). */
736 /* Table of TUs in the file.
737 Each element is a struct dwo_unit. */
741 /* These sections are what may appear in a DWP file. */
745 /* These are used by both DWP version 1 and 2. */
746 struct dwarf2_section_info str
;
747 struct dwarf2_section_info cu_index
;
748 struct dwarf2_section_info tu_index
;
750 /* These are only used by DWP version 2 files.
751 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
752 sections are referenced by section number, and are not recorded here.
753 In DWP version 2 there is at most one copy of all these sections, each
754 section being (effectively) comprised of the concatenation of all of the
755 individual sections that exist in the version 1 format.
756 To keep the code simple we treat each of these concatenated pieces as a
757 section itself (a virtual section?). */
758 struct dwarf2_section_info abbrev
;
759 struct dwarf2_section_info info
;
760 struct dwarf2_section_info line
;
761 struct dwarf2_section_info loc
;
762 struct dwarf2_section_info macinfo
;
763 struct dwarf2_section_info macro
;
764 struct dwarf2_section_info str_offsets
;
765 struct dwarf2_section_info types
;
768 /* These sections are what may appear in a virtual DWO file in DWP version 1.
769 A virtual DWO file is a DWO file as it appears in a DWP file. */
771 struct virtual_v1_dwo_sections
773 struct dwarf2_section_info abbrev
;
774 struct dwarf2_section_info line
;
775 struct dwarf2_section_info loc
;
776 struct dwarf2_section_info macinfo
;
777 struct dwarf2_section_info macro
;
778 struct dwarf2_section_info str_offsets
;
779 /* Each DWP hash table entry records one CU or one TU.
780 That is recorded here, and copied to dwo_unit.section. */
781 struct dwarf2_section_info info_or_types
;
784 /* Similar to virtual_v1_dwo_sections, but for DWP version 2.
785 In version 2, the sections of the DWO files are concatenated together
786 and stored in one section of that name. Thus each ELF section contains
787 several "virtual" sections. */
789 struct virtual_v2_dwo_sections
791 bfd_size_type abbrev_offset
;
792 bfd_size_type abbrev_size
;
794 bfd_size_type line_offset
;
795 bfd_size_type line_size
;
797 bfd_size_type loc_offset
;
798 bfd_size_type loc_size
;
800 bfd_size_type macinfo_offset
;
801 bfd_size_type macinfo_size
;
803 bfd_size_type macro_offset
;
804 bfd_size_type macro_size
;
806 bfd_size_type str_offsets_offset
;
807 bfd_size_type str_offsets_size
;
809 /* Each DWP hash table entry records one CU or one TU.
810 That is recorded here, and copied to dwo_unit.section. */
811 bfd_size_type info_or_types_offset
;
812 bfd_size_type info_or_types_size
;
815 /* Contents of DWP hash tables. */
817 struct dwp_hash_table
819 uint32_t version
, nr_columns
;
820 uint32_t nr_units
, nr_slots
;
821 const gdb_byte
*hash_table
, *unit_table
;
826 const gdb_byte
*indices
;
830 /* This is indexed by column number and gives the id of the section
832 #define MAX_NR_V2_DWO_SECTIONS \
833 (1 /* .debug_info or .debug_types */ \
834 + 1 /* .debug_abbrev */ \
835 + 1 /* .debug_line */ \
836 + 1 /* .debug_loc */ \
837 + 1 /* .debug_str_offsets */ \
838 + 1 /* .debug_macro or .debug_macinfo */)
839 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
840 const gdb_byte
*offsets
;
841 const gdb_byte
*sizes
;
846 /* Data for one DWP file. */
850 dwp_file (const char *name_
, gdb_bfd_ref_ptr
&&abfd
)
852 dbfd (std::move (abfd
))
856 /* Name of the file. */
859 /* File format version. */
863 gdb_bfd_ref_ptr dbfd
;
865 /* Section info for this file. */
866 struct dwp_sections sections
{};
868 /* Table of CUs in the file. */
869 const struct dwp_hash_table
*cus
= nullptr;
871 /* Table of TUs in the file. */
872 const struct dwp_hash_table
*tus
= nullptr;
874 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
875 htab_t loaded_cus
{};
876 htab_t loaded_tus
{};
878 /* Table to map ELF section numbers to their sections.
879 This is only needed for the DWP V1 file format. */
880 unsigned int num_sections
= 0;
881 asection
**elf_sections
= nullptr;
884 /* Struct used to pass misc. parameters to read_die_and_children, et
885 al. which are used for both .debug_info and .debug_types dies.
886 All parameters here are unchanging for the life of the call. This
887 struct exists to abstract away the constant parameters of die reading. */
889 struct die_reader_specs
891 /* The bfd of die_section. */
894 /* The CU of the DIE we are parsing. */
895 struct dwarf2_cu
*cu
;
897 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
898 struct dwo_file
*dwo_file
;
900 /* The section the die comes from.
901 This is either .debug_info or .debug_types, or the .dwo variants. */
902 struct dwarf2_section_info
*die_section
;
904 /* die_section->buffer. */
905 const gdb_byte
*buffer
;
907 /* The end of the buffer. */
908 const gdb_byte
*buffer_end
;
910 /* The value of the DW_AT_comp_dir attribute. */
911 const char *comp_dir
;
913 /* The abbreviation table to use when reading the DIEs. */
914 struct abbrev_table
*abbrev_table
;
917 /* Type of function passed to init_cutu_and_read_dies, et.al. */
918 typedef void (die_reader_func_ftype
) (const struct die_reader_specs
*reader
,
919 const gdb_byte
*info_ptr
,
920 struct die_info
*comp_unit_die
,
924 /* A 1-based directory index. This is a strong typedef to prevent
925 accidentally using a directory index as a 0-based index into an
927 enum class dir_index
: unsigned int {};
929 /* Likewise, a 1-based file name index. */
930 enum class file_name_index
: unsigned int {};
934 file_entry () = default;
936 file_entry (const char *name_
, dir_index d_index_
,
937 unsigned int mod_time_
, unsigned int length_
)
940 mod_time (mod_time_
),
944 /* Return the include directory at D_INDEX stored in LH. Returns
945 NULL if D_INDEX is out of bounds. */
946 const char *include_dir (const line_header
*lh
) const;
948 /* The file name. Note this is an observing pointer. The memory is
949 owned by debug_line_buffer. */
952 /* The directory index (1-based). */
953 dir_index d_index
{};
955 unsigned int mod_time
{};
957 unsigned int length
{};
959 /* True if referenced by the Line Number Program. */
962 /* The associated symbol table, if any. */
963 struct symtab
*symtab
{};
966 /* The line number information for a compilation unit (found in the
967 .debug_line section) begins with a "statement program header",
968 which contains the following information. */
975 /* Add an entry to the include directory table. */
976 void add_include_dir (const char *include_dir
);
978 /* Add an entry to the file name table. */
979 void add_file_name (const char *name
, dir_index d_index
,
980 unsigned int mod_time
, unsigned int length
);
982 /* Return the include dir at INDEX (1-based). Returns NULL if INDEX
984 const char *include_dir_at (dir_index index
) const
986 /* Convert directory index number (1-based) to vector index
988 size_t vec_index
= to_underlying (index
) - 1;
990 if (vec_index
>= include_dirs
.size ())
992 return include_dirs
[vec_index
];
995 /* Return the file name at INDEX (1-based). Returns NULL if INDEX
997 file_entry
*file_name_at (file_name_index index
)
999 /* Convert file name index number (1-based) to vector index
1001 size_t vec_index
= to_underlying (index
) - 1;
1003 if (vec_index
>= file_names
.size ())
1005 return &file_names
[vec_index
];
1008 /* Offset of line number information in .debug_line section. */
1009 sect_offset sect_off
{};
1011 /* OFFSET is for struct dwz_file associated with dwarf2_per_objfile. */
1012 unsigned offset_in_dwz
: 1; /* Can't initialize bitfields in-class. */
1014 unsigned int total_length
{};
1015 unsigned short version
{};
1016 unsigned int header_length
{};
1017 unsigned char minimum_instruction_length
{};
1018 unsigned char maximum_ops_per_instruction
{};
1019 unsigned char default_is_stmt
{};
1021 unsigned char line_range
{};
1022 unsigned char opcode_base
{};
1024 /* standard_opcode_lengths[i] is the number of operands for the
1025 standard opcode whose value is i. This means that
1026 standard_opcode_lengths[0] is unused, and the last meaningful
1027 element is standard_opcode_lengths[opcode_base - 1]. */
1028 std::unique_ptr
<unsigned char[]> standard_opcode_lengths
;
1030 /* The include_directories table. Note these are observing
1031 pointers. The memory is owned by debug_line_buffer. */
1032 std::vector
<const char *> include_dirs
;
1034 /* The file_names table. */
1035 std::vector
<file_entry
> file_names
;
1037 /* The start and end of the statement program following this
1038 header. These point into dwarf2_per_objfile->line_buffer. */
1039 const gdb_byte
*statement_program_start
{}, *statement_program_end
{};
1042 typedef std::unique_ptr
<line_header
> line_header_up
;
1045 file_entry::include_dir (const line_header
*lh
) const
1047 return lh
->include_dir_at (d_index
);
1050 /* When we construct a partial symbol table entry we only
1051 need this much information. */
1052 struct partial_die_info
: public allocate_on_obstack
1054 partial_die_info (sect_offset sect_off
, struct abbrev_info
*abbrev
);
1056 /* Disable assign but still keep copy ctor, which is needed
1057 load_partial_dies. */
1058 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
1060 /* Adjust the partial die before generating a symbol for it. This
1061 function may set the is_external flag or change the DIE's
1063 void fixup (struct dwarf2_cu
*cu
);
1065 /* Read a minimal amount of information into the minimal die
1067 const gdb_byte
*read (const struct die_reader_specs
*reader
,
1068 const struct abbrev_info
&abbrev
,
1069 const gdb_byte
*info_ptr
);
1071 /* Offset of this DIE. */
1072 const sect_offset sect_off
;
1074 /* DWARF-2 tag for this DIE. */
1075 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1077 /* Assorted flags describing the data found in this DIE. */
1078 const unsigned int has_children
: 1;
1080 unsigned int is_external
: 1;
1081 unsigned int is_declaration
: 1;
1082 unsigned int has_type
: 1;
1083 unsigned int has_specification
: 1;
1084 unsigned int has_pc_info
: 1;
1085 unsigned int may_be_inlined
: 1;
1087 /* This DIE has been marked DW_AT_main_subprogram. */
1088 unsigned int main_subprogram
: 1;
1090 /* Flag set if the SCOPE field of this structure has been
1092 unsigned int scope_set
: 1;
1094 /* Flag set if the DIE has a byte_size attribute. */
1095 unsigned int has_byte_size
: 1;
1097 /* Flag set if the DIE has a DW_AT_const_value attribute. */
1098 unsigned int has_const_value
: 1;
1100 /* Flag set if any of the DIE's children are template arguments. */
1101 unsigned int has_template_arguments
: 1;
1103 /* Flag set if fixup has been called on this die. */
1104 unsigned int fixup_called
: 1;
1106 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1107 unsigned int is_dwz
: 1;
1109 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1110 unsigned int spec_is_dwz
: 1;
1112 /* The name of this DIE. Normally the value of DW_AT_name, but
1113 sometimes a default name for unnamed DIEs. */
1114 const char *name
= nullptr;
1116 /* The linkage name, if present. */
1117 const char *linkage_name
= nullptr;
1119 /* The scope to prepend to our children. This is generally
1120 allocated on the comp_unit_obstack, so will disappear
1121 when this compilation unit leaves the cache. */
1122 const char *scope
= nullptr;
1124 /* Some data associated with the partial DIE. The tag determines
1125 which field is live. */
1128 /* The location description associated with this DIE, if any. */
1129 struct dwarf_block
*locdesc
;
1130 /* The offset of an import, for DW_TAG_imported_unit. */
1131 sect_offset sect_off
;
1134 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1135 CORE_ADDR lowpc
= 0;
1136 CORE_ADDR highpc
= 0;
1138 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1139 DW_AT_sibling, if any. */
1140 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1141 could return DW_AT_sibling values to its caller load_partial_dies. */
1142 const gdb_byte
*sibling
= nullptr;
1144 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1145 DW_AT_specification (or DW_AT_abstract_origin or
1146 DW_AT_extension). */
1147 sect_offset spec_offset
{};
1149 /* Pointers to this DIE's parent, first child, and next sibling,
1151 struct partial_die_info
*die_parent
= nullptr;
1152 struct partial_die_info
*die_child
= nullptr;
1153 struct partial_die_info
*die_sibling
= nullptr;
1155 friend struct partial_die_info
*
1156 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1159 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1160 partial_die_info (sect_offset sect_off
)
1161 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1165 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1167 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1172 has_specification
= 0;
1175 main_subprogram
= 0;
1178 has_const_value
= 0;
1179 has_template_arguments
= 0;
1186 /* This data structure holds the information of an abbrev. */
1189 unsigned int number
; /* number identifying abbrev */
1190 enum dwarf_tag tag
; /* dwarf tag */
1191 unsigned short has_children
; /* boolean */
1192 unsigned short num_attrs
; /* number of attributes */
1193 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
1194 struct abbrev_info
*next
; /* next in chain */
1199 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1200 ENUM_BITFIELD(dwarf_form
) form
: 16;
1202 /* It is valid only if FORM is DW_FORM_implicit_const. */
1203 LONGEST implicit_const
;
1206 /* Size of abbrev_table.abbrev_hash_table. */
1207 #define ABBREV_HASH_SIZE 121
1209 /* Top level data structure to contain an abbreviation table. */
1213 explicit abbrev_table (sect_offset off
)
1217 XOBNEWVEC (&abbrev_obstack
, struct abbrev_info
*, ABBREV_HASH_SIZE
);
1218 memset (m_abbrevs
, 0, ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
1221 DISABLE_COPY_AND_ASSIGN (abbrev_table
);
1223 /* Allocate space for a struct abbrev_info object in
1225 struct abbrev_info
*alloc_abbrev ();
1227 /* Add an abbreviation to the table. */
1228 void add_abbrev (unsigned int abbrev_number
, struct abbrev_info
*abbrev
);
1230 /* Look up an abbrev in the table.
1231 Returns NULL if the abbrev is not found. */
1233 struct abbrev_info
*lookup_abbrev (unsigned int abbrev_number
);
1236 /* Where the abbrev table came from.
1237 This is used as a sanity check when the table is used. */
1238 const sect_offset sect_off
;
1240 /* Storage for the abbrev table. */
1241 auto_obstack abbrev_obstack
;
1245 /* Hash table of abbrevs.
1246 This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack.
1247 It could be statically allocated, but the previous code didn't so we
1249 struct abbrev_info
**m_abbrevs
;
1252 typedef std::unique_ptr
<struct abbrev_table
> abbrev_table_up
;
1254 /* Attributes have a name and a value. */
1257 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1258 ENUM_BITFIELD(dwarf_form
) form
: 15;
1260 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
1261 field should be in u.str (existing only for DW_STRING) but it is kept
1262 here for better struct attribute alignment. */
1263 unsigned int string_is_canonical
: 1;
1268 struct dwarf_block
*blk
;
1277 /* This data structure holds a complete die structure. */
1280 /* DWARF-2 tag for this DIE. */
1281 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1283 /* Number of attributes */
1284 unsigned char num_attrs
;
1286 /* True if we're presently building the full type name for the
1287 type derived from this DIE. */
1288 unsigned char building_fullname
: 1;
1290 /* True if this die is in process. PR 16581. */
1291 unsigned char in_process
: 1;
1294 unsigned int abbrev
;
1296 /* Offset in .debug_info or .debug_types section. */
1297 sect_offset sect_off
;
1299 /* The dies in a compilation unit form an n-ary tree. PARENT
1300 points to this die's parent; CHILD points to the first child of
1301 this node; and all the children of a given node are chained
1302 together via their SIBLING fields. */
1303 struct die_info
*child
; /* Its first child, if any. */
1304 struct die_info
*sibling
; /* Its next sibling, if any. */
1305 struct die_info
*parent
; /* Its parent, if any. */
1307 /* An array of attributes, with NUM_ATTRS elements. There may be
1308 zero, but it's not common and zero-sized arrays are not
1309 sufficiently portable C. */
1310 struct attribute attrs
[1];
1313 /* Get at parts of an attribute structure. */
1315 #define DW_STRING(attr) ((attr)->u.str)
1316 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
1317 #define DW_UNSND(attr) ((attr)->u.unsnd)
1318 #define DW_BLOCK(attr) ((attr)->u.blk)
1319 #define DW_SND(attr) ((attr)->u.snd)
1320 #define DW_ADDR(attr) ((attr)->u.addr)
1321 #define DW_SIGNATURE(attr) ((attr)->u.signature)
1323 /* Blocks are a bunch of untyped bytes. */
1328 /* Valid only if SIZE is not zero. */
1329 const gdb_byte
*data
;
1332 #ifndef ATTR_ALLOC_CHUNK
1333 #define ATTR_ALLOC_CHUNK 4
1336 /* Allocate fields for structs, unions and enums in this size. */
1337 #ifndef DW_FIELD_ALLOC_CHUNK
1338 #define DW_FIELD_ALLOC_CHUNK 4
1341 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1342 but this would require a corresponding change in unpack_field_as_long
1344 static int bits_per_byte
= 8;
1346 /* When reading a variant or variant part, we track a bit more
1347 information about the field, and store it in an object of this
1350 struct variant_field
1352 /* If we see a DW_TAG_variant, then this will be the discriminant
1354 ULONGEST discriminant_value
;
1355 /* If we see a DW_TAG_variant, then this will be set if this is the
1357 bool default_branch
;
1358 /* While reading a DW_TAG_variant_part, this will be set if this
1359 field is the discriminant. */
1360 bool is_discriminant
;
1365 int accessibility
= 0;
1367 /* Extra information to describe a variant or variant part. */
1368 struct variant_field variant
{};
1369 struct field field
{};
1374 const char *name
= nullptr;
1375 std::vector
<struct fn_field
> fnfields
;
1378 /* The routines that read and process dies for a C struct or C++ class
1379 pass lists of data member fields and lists of member function fields
1380 in an instance of a field_info structure, as defined below. */
1383 /* List of data member and baseclasses fields. */
1384 std::vector
<struct nextfield
> fields
;
1385 std::vector
<struct nextfield
> baseclasses
;
1387 /* Number of fields (including baseclasses). */
1390 /* Set if the accesibility of one of the fields is not public. */
1391 int non_public_fields
= 0;
1393 /* Member function fieldlist array, contains name of possibly overloaded
1394 member function, number of overloaded member functions and a pointer
1395 to the head of the member function field chain. */
1396 std::vector
<struct fnfieldlist
> fnfieldlists
;
1398 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1399 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1400 std::vector
<struct decl_field
> typedef_field_list
;
1402 /* Nested types defined by this class and the number of elements in this
1404 std::vector
<struct decl_field
> nested_types_list
;
1407 /* One item on the queue of compilation units to read in full symbols
1409 struct dwarf2_queue_item
1411 struct dwarf2_per_cu_data
*per_cu
;
1412 enum language pretend_language
;
1413 struct dwarf2_queue_item
*next
;
1416 /* The current queue. */
1417 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
1419 /* Loaded secondary compilation units are kept in memory until they
1420 have not been referenced for the processing of this many
1421 compilation units. Set this to zero to disable caching. Cache
1422 sizes of up to at least twenty will improve startup time for
1423 typical inter-CU-reference binaries, at an obvious memory cost. */
1424 static int dwarf_max_cache_age
= 5;
1426 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1427 struct cmd_list_element
*c
, const char *value
)
1429 fprintf_filtered (file
, _("The upper bound on the age of cached "
1430 "DWARF compilation units is %s.\n"),
1434 /* local function prototypes */
1436 static const char *get_section_name (const struct dwarf2_section_info
*);
1438 static const char *get_section_file_name (const struct dwarf2_section_info
*);
1440 static void dwarf2_find_base_address (struct die_info
*die
,
1441 struct dwarf2_cu
*cu
);
1443 static struct partial_symtab
*create_partial_symtab
1444 (struct dwarf2_per_cu_data
*per_cu
, const char *name
);
1446 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1447 const gdb_byte
*info_ptr
,
1448 struct die_info
*type_unit_die
,
1449 int has_children
, void *data
);
1451 static void dwarf2_build_psymtabs_hard
1452 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1454 static void scan_partial_symbols (struct partial_die_info
*,
1455 CORE_ADDR
*, CORE_ADDR
*,
1456 int, struct dwarf2_cu
*);
1458 static void add_partial_symbol (struct partial_die_info
*,
1459 struct dwarf2_cu
*);
1461 static void add_partial_namespace (struct partial_die_info
*pdi
,
1462 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1463 int set_addrmap
, struct dwarf2_cu
*cu
);
1465 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1466 CORE_ADDR
*highpc
, int set_addrmap
,
1467 struct dwarf2_cu
*cu
);
1469 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1470 struct dwarf2_cu
*cu
);
1472 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1473 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1474 int need_pc
, struct dwarf2_cu
*cu
);
1476 static void dwarf2_read_symtab (struct partial_symtab
*,
1479 static void psymtab_to_symtab_1 (struct partial_symtab
*);
1481 static abbrev_table_up abbrev_table_read_table
1482 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, struct dwarf2_section_info
*,
1485 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1487 static struct partial_die_info
*load_partial_dies
1488 (const struct die_reader_specs
*, const gdb_byte
*, int);
1490 /* A pair of partial_die_info and compilation unit. */
1491 struct cu_partial_die_info
1493 /* The compilation unit of the partial_die_info. */
1494 struct dwarf2_cu
*cu
;
1495 /* A partial_die_info. */
1496 struct partial_die_info
*pdi
;
1498 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1504 cu_partial_die_info () = delete;
1507 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1508 struct dwarf2_cu
*);
1510 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1511 struct attribute
*, struct attr_abbrev
*,
1514 static unsigned int read_1_byte (bfd
*, const gdb_byte
*);
1516 static int read_1_signed_byte (bfd
*, const gdb_byte
*);
1518 static unsigned int read_2_bytes (bfd
*, const gdb_byte
*);
1520 /* Read the next three bytes (little-endian order) as an unsigned integer. */
1521 static unsigned int read_3_bytes (bfd
*, const gdb_byte
*);
1523 static unsigned int read_4_bytes (bfd
*, const gdb_byte
*);
1525 static ULONGEST
read_8_bytes (bfd
*, const gdb_byte
*);
1527 static CORE_ADDR
read_address (bfd
*, const gdb_byte
*ptr
, struct dwarf2_cu
*,
1530 static LONGEST
read_initial_length (bfd
*, const gdb_byte
*, unsigned int *);
1532 static LONGEST read_checked_initial_length_and_offset
1533 (bfd
*, const gdb_byte
*, const struct comp_unit_head
*,
1534 unsigned int *, unsigned int *);
1536 static LONGEST
read_offset (bfd
*, const gdb_byte
*,
1537 const struct comp_unit_head
*,
1540 static LONGEST
read_offset_1 (bfd
*, const gdb_byte
*, unsigned int);
1542 static sect_offset read_abbrev_offset
1543 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1544 struct dwarf2_section_info
*, sect_offset
);
1546 static const gdb_byte
*read_n_bytes (bfd
*, const gdb_byte
*, unsigned int);
1548 static const char *read_direct_string (bfd
*, const gdb_byte
*, unsigned int *);
1550 static const char *read_indirect_string
1551 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1552 const struct comp_unit_head
*, unsigned int *);
1554 static const char *read_indirect_line_string
1555 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1556 const struct comp_unit_head
*, unsigned int *);
1558 static const char *read_indirect_string_at_offset
1559 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
1560 LONGEST str_offset
);
1562 static const char *read_indirect_string_from_dwz
1563 (struct objfile
*objfile
, struct dwz_file
*, LONGEST
);
1565 static LONGEST
read_signed_leb128 (bfd
*, const gdb_byte
*, unsigned int *);
1567 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1571 static const char *read_str_index (const struct die_reader_specs
*reader
,
1572 ULONGEST str_index
);
1574 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1576 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1577 struct dwarf2_cu
*);
1579 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1582 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1583 struct dwarf2_cu
*cu
);
1585 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1587 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1588 struct dwarf2_cu
*cu
);
1590 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1592 static struct die_info
*die_specification (struct die_info
*die
,
1593 struct dwarf2_cu
**);
1595 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1596 struct dwarf2_cu
*cu
);
1598 static void dwarf_decode_lines (struct line_header
*, const char *,
1599 struct dwarf2_cu
*, struct partial_symtab
*,
1600 CORE_ADDR
, int decode_mapping
);
1602 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1605 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1606 struct dwarf2_cu
*, struct symbol
* = NULL
);
1608 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1609 struct dwarf2_cu
*);
1611 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1614 struct obstack
*obstack
,
1615 struct dwarf2_cu
*cu
, LONGEST
*value
,
1616 const gdb_byte
**bytes
,
1617 struct dwarf2_locexpr_baton
**baton
);
1619 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1621 static int need_gnat_info (struct dwarf2_cu
*);
1623 static struct type
*die_descriptive_type (struct die_info
*,
1624 struct dwarf2_cu
*);
1626 static void set_descriptive_type (struct type
*, struct die_info
*,
1627 struct dwarf2_cu
*);
1629 static struct type
*die_containing_type (struct die_info
*,
1630 struct dwarf2_cu
*);
1632 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1633 struct dwarf2_cu
*);
1635 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1637 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1639 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1641 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1642 const char *suffix
, int physname
,
1643 struct dwarf2_cu
*cu
);
1645 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1647 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1649 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1651 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1653 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1655 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1657 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1658 struct dwarf2_cu
*, struct partial_symtab
*);
1660 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1661 values. Keep the items ordered with increasing constraints compliance. */
1664 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1665 PC_BOUNDS_NOT_PRESENT
,
1667 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1668 were present but they do not form a valid range of PC addresses. */
1671 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1674 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1678 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1679 CORE_ADDR
*, CORE_ADDR
*,
1681 struct partial_symtab
*);
1683 static void get_scope_pc_bounds (struct die_info
*,
1684 CORE_ADDR
*, CORE_ADDR
*,
1685 struct dwarf2_cu
*);
1687 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1688 CORE_ADDR
, struct dwarf2_cu
*);
1690 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1691 struct dwarf2_cu
*);
1693 static void dwarf2_attach_fields_to_type (struct field_info
*,
1694 struct type
*, struct dwarf2_cu
*);
1696 static void dwarf2_add_member_fn (struct field_info
*,
1697 struct die_info
*, struct type
*,
1698 struct dwarf2_cu
*);
1700 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1702 struct dwarf2_cu
*);
1704 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1706 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1708 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1710 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1712 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1714 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1716 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1718 static struct type
*read_module_type (struct die_info
*die
,
1719 struct dwarf2_cu
*cu
);
1721 static const char *namespace_name (struct die_info
*die
,
1722 int *is_anonymous
, struct dwarf2_cu
*);
1724 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1726 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1728 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1729 struct dwarf2_cu
*);
1731 static struct die_info
*read_die_and_siblings_1
1732 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1735 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1736 const gdb_byte
*info_ptr
,
1737 const gdb_byte
**new_info_ptr
,
1738 struct die_info
*parent
);
1740 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1741 struct die_info
**, const gdb_byte
*,
1744 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1745 struct die_info
**, const gdb_byte
*,
1748 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1750 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1753 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1755 static const char *dwarf2_full_name (const char *name
,
1756 struct die_info
*die
,
1757 struct dwarf2_cu
*cu
);
1759 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1760 struct dwarf2_cu
*cu
);
1762 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1763 struct dwarf2_cu
**);
1765 static const char *dwarf_tag_name (unsigned int);
1767 static const char *dwarf_attr_name (unsigned int);
1769 static const char *dwarf_unit_type_name (int unit_type
);
1771 static const char *dwarf_form_name (unsigned int);
1773 static const char *dwarf_bool_name (unsigned int);
1775 static const char *dwarf_type_encoding_name (unsigned int);
1777 static struct die_info
*sibling_die (struct die_info
*);
1779 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1781 static void dump_die_for_error (struct die_info
*);
1783 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1786 /*static*/ void dump_die (struct die_info
*, int max_level
);
1788 static void store_in_ref_table (struct die_info
*,
1789 struct dwarf2_cu
*);
1791 static sect_offset
dwarf2_get_ref_die_offset (const struct attribute
*);
1793 static LONGEST
dwarf2_get_attr_constant_value (const struct attribute
*, int);
1795 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1796 const struct attribute
*,
1797 struct dwarf2_cu
**);
1799 static struct die_info
*follow_die_ref (struct die_info
*,
1800 const struct attribute
*,
1801 struct dwarf2_cu
**);
1803 static struct die_info
*follow_die_sig (struct die_info
*,
1804 const struct attribute
*,
1805 struct dwarf2_cu
**);
1807 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1808 struct dwarf2_cu
*);
1810 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1811 const struct attribute
*,
1812 struct dwarf2_cu
*);
1814 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1816 static void read_signatured_type (struct signatured_type
*);
1818 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1819 struct die_info
*die
, struct dwarf2_cu
*cu
,
1820 struct dynamic_prop
*prop
, struct type
*type
);
1822 /* memory allocation interface */
1824 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1826 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1828 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1830 static int attr_form_is_block (const struct attribute
*);
1832 static int attr_form_is_section_offset (const struct attribute
*);
1834 static int attr_form_is_constant (const struct attribute
*);
1836 static int attr_form_is_ref (const struct attribute
*);
1838 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1839 struct dwarf2_loclist_baton
*baton
,
1840 const struct attribute
*attr
);
1842 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1844 struct dwarf2_cu
*cu
,
1847 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1848 const gdb_byte
*info_ptr
,
1849 struct abbrev_info
*abbrev
);
1851 static hashval_t
partial_die_hash (const void *item
);
1853 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1855 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1856 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1857 struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1859 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1860 struct die_info
*comp_unit_die
,
1861 enum language pretend_language
);
1863 static void age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1865 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1867 static struct type
*set_die_type (struct die_info
*, struct type
*,
1868 struct dwarf2_cu
*);
1870 static void create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1872 static int create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1874 static void load_full_comp_unit (struct dwarf2_per_cu_data
*, bool,
1877 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1880 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1883 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1884 struct dwarf2_per_cu_data
*);
1886 static void dwarf2_mark (struct dwarf2_cu
*);
1888 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1890 static struct type
*get_die_type_at_offset (sect_offset
,
1891 struct dwarf2_per_cu_data
*);
1893 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1895 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1896 enum language pretend_language
);
1898 static void process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1900 static struct type
*dwarf2_per_cu_addr_type (struct dwarf2_per_cu_data
*per_cu
);
1901 static struct type
*dwarf2_per_cu_addr_sized_int_type
1902 (struct dwarf2_per_cu_data
*per_cu
, bool unsigned_p
);
1904 /* Class, the destructor of which frees all allocated queue entries. This
1905 will only have work to do if an error was thrown while processing the
1906 dwarf. If no error was thrown then the queue entries should have all
1907 been processed, and freed, as we went along. */
1909 class dwarf2_queue_guard
1912 dwarf2_queue_guard () = default;
1914 /* Free any entries remaining on the queue. There should only be
1915 entries left if we hit an error while processing the dwarf. */
1916 ~dwarf2_queue_guard ()
1918 struct dwarf2_queue_item
*item
, *last
;
1920 item
= dwarf2_queue
;
1923 /* Anything still marked queued is likely to be in an
1924 inconsistent state, so discard it. */
1925 if (item
->per_cu
->queued
)
1927 if (item
->per_cu
->cu
!= NULL
)
1928 free_one_cached_comp_unit (item
->per_cu
);
1929 item
->per_cu
->queued
= 0;
1937 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
1941 /* The return type of find_file_and_directory. Note, the enclosed
1942 string pointers are only valid while this object is valid. */
1944 struct file_and_directory
1946 /* The filename. This is never NULL. */
1949 /* The compilation directory. NULL if not known. If we needed to
1950 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1951 points directly to the DW_AT_comp_dir string attribute owned by
1952 the obstack that owns the DIE. */
1953 const char *comp_dir
;
1955 /* If we needed to build a new string for comp_dir, this is what
1956 owns the storage. */
1957 std::string comp_dir_storage
;
1960 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1961 struct dwarf2_cu
*cu
);
1963 static char *file_full_name (int file
, struct line_header
*lh
,
1964 const char *comp_dir
);
1966 /* Expected enum dwarf_unit_type for read_comp_unit_head. */
1967 enum class rcuh_kind
{ COMPILE
, TYPE
};
1969 static const gdb_byte
*read_and_check_comp_unit_head
1970 (struct dwarf2_per_objfile
* dwarf2_per_objfile
,
1971 struct comp_unit_head
*header
,
1972 struct dwarf2_section_info
*section
,
1973 struct dwarf2_section_info
*abbrev_section
, const gdb_byte
*info_ptr
,
1974 rcuh_kind section_kind
);
1976 static void init_cutu_and_read_dies
1977 (struct dwarf2_per_cu_data
*this_cu
, struct abbrev_table
*abbrev_table
,
1978 int use_existing_cu
, int keep
, bool skip_partial
,
1979 die_reader_func_ftype
*die_reader_func
, void *data
);
1981 static void init_cutu_and_read_dies_simple
1982 (struct dwarf2_per_cu_data
*this_cu
,
1983 die_reader_func_ftype
*die_reader_func
, void *data
);
1985 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1987 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
1989 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1990 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1991 struct dwp_file
*dwp_file
, const char *comp_dir
,
1992 ULONGEST signature
, int is_debug_types
);
1994 static struct dwp_file
*get_dwp_file
1995 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1997 static struct dwo_unit
*lookup_dwo_comp_unit
1998 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
2000 static struct dwo_unit
*lookup_dwo_type_unit
2001 (struct signatured_type
*, const char *, const char *);
2003 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
2005 /* A unique pointer to a dwo_file. */
2007 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
2009 static void process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2011 static void check_producer (struct dwarf2_cu
*cu
);
2013 static void free_line_header_voidp (void *arg
);
2015 /* Various complaints about symbol reading that don't abort the process. */
2018 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
2020 complaint (_("statement list doesn't fit in .debug_line section"));
2024 dwarf2_debug_line_missing_file_complaint (void)
2026 complaint (_(".debug_line section has line data without a file"));
2030 dwarf2_debug_line_missing_end_sequence_complaint (void)
2032 complaint (_(".debug_line section has line "
2033 "program sequence without an end"));
2037 dwarf2_complex_location_expr_complaint (void)
2039 complaint (_("location expression too complex"));
2043 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
2046 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
2051 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
2053 complaint (_("debug info runs off end of %s section"
2055 get_section_name (section
),
2056 get_section_file_name (section
));
2060 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
2062 complaint (_("macro debug info contains a "
2063 "malformed macro definition:\n`%s'"),
2068 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
2070 complaint (_("invalid attribute class or form for '%s' in '%s'"),
2074 /* Hash function for line_header_hash. */
2077 line_header_hash (const struct line_header
*ofs
)
2079 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
2082 /* Hash function for htab_create_alloc_ex for line_header_hash. */
2085 line_header_hash_voidp (const void *item
)
2087 const struct line_header
*ofs
= (const struct line_header
*) item
;
2089 return line_header_hash (ofs
);
2092 /* Equality function for line_header_hash. */
2095 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
2097 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
2098 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
2100 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
2101 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
2106 /* Read the given attribute value as an address, taking the attribute's
2107 form into account. */
2110 attr_value_as_address (struct attribute
*attr
)
2114 if (attr
->form
!= DW_FORM_addr
&& attr
->form
!= DW_FORM_addrx
2115 && attr
->form
!= DW_FORM_GNU_addr_index
)
2117 /* Aside from a few clearly defined exceptions, attributes that
2118 contain an address must always be in DW_FORM_addr form.
2119 Unfortunately, some compilers happen to be violating this
2120 requirement by encoding addresses using other forms, such
2121 as DW_FORM_data4 for example. For those broken compilers,
2122 we try to do our best, without any guarantee of success,
2123 to interpret the address correctly. It would also be nice
2124 to generate a complaint, but that would require us to maintain
2125 a list of legitimate cases where a non-address form is allowed,
2126 as well as update callers to pass in at least the CU's DWARF
2127 version. This is more overhead than what we're willing to
2128 expand for a pretty rare case. */
2129 addr
= DW_UNSND (attr
);
2132 addr
= DW_ADDR (attr
);
2137 /* See declaration. */
2139 dwarf2_per_objfile::dwarf2_per_objfile (struct objfile
*objfile_
,
2140 const dwarf2_debug_sections
*names
)
2141 : objfile (objfile_
)
2144 names
= &dwarf2_elf_names
;
2146 bfd
*obfd
= objfile
->obfd
;
2148 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
2149 locate_sections (obfd
, sec
, *names
);
2152 dwarf2_per_objfile::~dwarf2_per_objfile ()
2154 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
2155 free_cached_comp_units ();
2157 if (quick_file_names_table
)
2158 htab_delete (quick_file_names_table
);
2160 if (line_header_hash
)
2161 htab_delete (line_header_hash
);
2163 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
2164 VEC_free (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
);
2166 for (signatured_type
*sig_type
: all_type_units
)
2167 VEC_free (dwarf2_per_cu_ptr
, sig_type
->per_cu
.imported_symtabs
);
2169 /* Everything else should be on the objfile obstack. */
2172 /* See declaration. */
2175 dwarf2_per_objfile::free_cached_comp_units ()
2177 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
2178 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
2179 while (per_cu
!= NULL
)
2181 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
2184 *last_chain
= next_cu
;
2189 /* A helper class that calls free_cached_comp_units on
2192 class free_cached_comp_units
2196 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
2197 : m_per_objfile (per_objfile
)
2201 ~free_cached_comp_units ()
2203 m_per_objfile
->free_cached_comp_units ();
2206 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
2210 dwarf2_per_objfile
*m_per_objfile
;
2213 /* Try to locate the sections we need for DWARF 2 debugging
2214 information and return true if we have enough to do something.
2215 NAMES points to the dwarf2 section names, or is NULL if the standard
2216 ELF names are used. */
2219 dwarf2_has_info (struct objfile
*objfile
,
2220 const struct dwarf2_debug_sections
*names
)
2222 if (objfile
->flags
& OBJF_READNEVER
)
2225 struct dwarf2_per_objfile
*dwarf2_per_objfile
2226 = get_dwarf2_per_objfile (objfile
);
2228 if (dwarf2_per_objfile
== NULL
)
2229 dwarf2_per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
,
2232 return (!dwarf2_per_objfile
->info
.is_virtual
2233 && dwarf2_per_objfile
->info
.s
.section
!= NULL
2234 && !dwarf2_per_objfile
->abbrev
.is_virtual
2235 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
2238 /* Return the containing section of virtual section SECTION. */
2240 static struct dwarf2_section_info
*
2241 get_containing_section (const struct dwarf2_section_info
*section
)
2243 gdb_assert (section
->is_virtual
);
2244 return section
->s
.containing_section
;
2247 /* Return the bfd owner of SECTION. */
2250 get_section_bfd_owner (const struct dwarf2_section_info
*section
)
2252 if (section
->is_virtual
)
2254 section
= get_containing_section (section
);
2255 gdb_assert (!section
->is_virtual
);
2257 return section
->s
.section
->owner
;
2260 /* Return the bfd section of SECTION.
2261 Returns NULL if the section is not present. */
2264 get_section_bfd_section (const struct dwarf2_section_info
*section
)
2266 if (section
->is_virtual
)
2268 section
= get_containing_section (section
);
2269 gdb_assert (!section
->is_virtual
);
2271 return section
->s
.section
;
2274 /* Return the name of SECTION. */
2277 get_section_name (const struct dwarf2_section_info
*section
)
2279 asection
*sectp
= get_section_bfd_section (section
);
2281 gdb_assert (sectp
!= NULL
);
2282 return bfd_section_name (get_section_bfd_owner (section
), sectp
);
2285 /* Return the name of the file SECTION is in. */
2288 get_section_file_name (const struct dwarf2_section_info
*section
)
2290 bfd
*abfd
= get_section_bfd_owner (section
);
2292 return bfd_get_filename (abfd
);
2295 /* Return the id of SECTION.
2296 Returns 0 if SECTION doesn't exist. */
2299 get_section_id (const struct dwarf2_section_info
*section
)
2301 asection
*sectp
= get_section_bfd_section (section
);
2308 /* Return the flags of SECTION.
2309 SECTION (or containing section if this is a virtual section) must exist. */
2312 get_section_flags (const struct dwarf2_section_info
*section
)
2314 asection
*sectp
= get_section_bfd_section (section
);
2316 gdb_assert (sectp
!= NULL
);
2317 return bfd_get_section_flags (sectp
->owner
, sectp
);
2320 /* When loading sections, we look either for uncompressed section or for
2321 compressed section names. */
2324 section_is_p (const char *section_name
,
2325 const struct dwarf2_section_names
*names
)
2327 if (names
->normal
!= NULL
2328 && strcmp (section_name
, names
->normal
) == 0)
2330 if (names
->compressed
!= NULL
2331 && strcmp (section_name
, names
->compressed
) == 0)
2336 /* See declaration. */
2339 dwarf2_per_objfile::locate_sections (bfd
*abfd
, asection
*sectp
,
2340 const dwarf2_debug_sections
&names
)
2342 flagword aflag
= bfd_get_section_flags (abfd
, sectp
);
2344 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
2347 else if (section_is_p (sectp
->name
, &names
.info
))
2349 this->info
.s
.section
= sectp
;
2350 this->info
.size
= bfd_get_section_size (sectp
);
2352 else if (section_is_p (sectp
->name
, &names
.abbrev
))
2354 this->abbrev
.s
.section
= sectp
;
2355 this->abbrev
.size
= bfd_get_section_size (sectp
);
2357 else if (section_is_p (sectp
->name
, &names
.line
))
2359 this->line
.s
.section
= sectp
;
2360 this->line
.size
= bfd_get_section_size (sectp
);
2362 else if (section_is_p (sectp
->name
, &names
.loc
))
2364 this->loc
.s
.section
= sectp
;
2365 this->loc
.size
= bfd_get_section_size (sectp
);
2367 else if (section_is_p (sectp
->name
, &names
.loclists
))
2369 this->loclists
.s
.section
= sectp
;
2370 this->loclists
.size
= bfd_get_section_size (sectp
);
2372 else if (section_is_p (sectp
->name
, &names
.macinfo
))
2374 this->macinfo
.s
.section
= sectp
;
2375 this->macinfo
.size
= bfd_get_section_size (sectp
);
2377 else if (section_is_p (sectp
->name
, &names
.macro
))
2379 this->macro
.s
.section
= sectp
;
2380 this->macro
.size
= bfd_get_section_size (sectp
);
2382 else if (section_is_p (sectp
->name
, &names
.str
))
2384 this->str
.s
.section
= sectp
;
2385 this->str
.size
= bfd_get_section_size (sectp
);
2387 else if (section_is_p (sectp
->name
, &names
.line_str
))
2389 this->line_str
.s
.section
= sectp
;
2390 this->line_str
.size
= bfd_get_section_size (sectp
);
2392 else if (section_is_p (sectp
->name
, &names
.addr
))
2394 this->addr
.s
.section
= sectp
;
2395 this->addr
.size
= bfd_get_section_size (sectp
);
2397 else if (section_is_p (sectp
->name
, &names
.frame
))
2399 this->frame
.s
.section
= sectp
;
2400 this->frame
.size
= bfd_get_section_size (sectp
);
2402 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
2404 this->eh_frame
.s
.section
= sectp
;
2405 this->eh_frame
.size
= bfd_get_section_size (sectp
);
2407 else if (section_is_p (sectp
->name
, &names
.ranges
))
2409 this->ranges
.s
.section
= sectp
;
2410 this->ranges
.size
= bfd_get_section_size (sectp
);
2412 else if (section_is_p (sectp
->name
, &names
.rnglists
))
2414 this->rnglists
.s
.section
= sectp
;
2415 this->rnglists
.size
= bfd_get_section_size (sectp
);
2417 else if (section_is_p (sectp
->name
, &names
.types
))
2419 struct dwarf2_section_info type_section
;
2421 memset (&type_section
, 0, sizeof (type_section
));
2422 type_section
.s
.section
= sectp
;
2423 type_section
.size
= bfd_get_section_size (sectp
);
2425 this->types
.push_back (type_section
);
2427 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
2429 this->gdb_index
.s
.section
= sectp
;
2430 this->gdb_index
.size
= bfd_get_section_size (sectp
);
2432 else if (section_is_p (sectp
->name
, &names
.debug_names
))
2434 this->debug_names
.s
.section
= sectp
;
2435 this->debug_names
.size
= bfd_get_section_size (sectp
);
2437 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
2439 this->debug_aranges
.s
.section
= sectp
;
2440 this->debug_aranges
.size
= bfd_get_section_size (sectp
);
2443 if ((bfd_get_section_flags (abfd
, sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2444 && bfd_section_vma (abfd
, sectp
) == 0)
2445 this->has_section_at_zero
= true;
2448 /* A helper function that decides whether a section is empty,
2452 dwarf2_section_empty_p (const struct dwarf2_section_info
*section
)
2454 if (section
->is_virtual
)
2455 return section
->size
== 0;
2456 return section
->s
.section
== NULL
|| section
->size
== 0;
2459 /* See dwarf2read.h. */
2462 dwarf2_read_section (struct objfile
*objfile
, dwarf2_section_info
*info
)
2466 gdb_byte
*buf
, *retbuf
;
2470 info
->buffer
= NULL
;
2471 info
->readin
= true;
2473 if (dwarf2_section_empty_p (info
))
2476 sectp
= get_section_bfd_section (info
);
2478 /* If this is a virtual section we need to read in the real one first. */
2479 if (info
->is_virtual
)
2481 struct dwarf2_section_info
*containing_section
=
2482 get_containing_section (info
);
2484 gdb_assert (sectp
!= NULL
);
2485 if ((sectp
->flags
& SEC_RELOC
) != 0)
2487 error (_("Dwarf Error: DWP format V2 with relocations is not"
2488 " supported in section %s [in module %s]"),
2489 get_section_name (info
), get_section_file_name (info
));
2491 dwarf2_read_section (objfile
, containing_section
);
2492 /* Other code should have already caught virtual sections that don't
2494 gdb_assert (info
->virtual_offset
+ info
->size
2495 <= containing_section
->size
);
2496 /* If the real section is empty or there was a problem reading the
2497 section we shouldn't get here. */
2498 gdb_assert (containing_section
->buffer
!= NULL
);
2499 info
->buffer
= containing_section
->buffer
+ info
->virtual_offset
;
2503 /* If the section has relocations, we must read it ourselves.
2504 Otherwise we attach it to the BFD. */
2505 if ((sectp
->flags
& SEC_RELOC
) == 0)
2507 info
->buffer
= gdb_bfd_map_section (sectp
, &info
->size
);
2511 buf
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
2514 /* When debugging .o files, we may need to apply relocations; see
2515 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
2516 We never compress sections in .o files, so we only need to
2517 try this when the section is not compressed. */
2518 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
2521 info
->buffer
= retbuf
;
2525 abfd
= get_section_bfd_owner (info
);
2526 gdb_assert (abfd
!= NULL
);
2528 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
2529 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
2531 error (_("Dwarf Error: Can't read DWARF data"
2532 " in section %s [in module %s]"),
2533 bfd_section_name (abfd
, sectp
), bfd_get_filename (abfd
));
2537 /* A helper function that returns the size of a section in a safe way.
2538 If you are positive that the section has been read before using the
2539 size, then it is safe to refer to the dwarf2_section_info object's
2540 "size" field directly. In other cases, you must call this
2541 function, because for compressed sections the size field is not set
2542 correctly until the section has been read. */
2544 static bfd_size_type
2545 dwarf2_section_size (struct objfile
*objfile
,
2546 struct dwarf2_section_info
*info
)
2549 dwarf2_read_section (objfile
, info
);
2553 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2557 dwarf2_get_section_info (struct objfile
*objfile
,
2558 enum dwarf2_section_enum sect
,
2559 asection
**sectp
, const gdb_byte
**bufp
,
2560 bfd_size_type
*sizep
)
2562 struct dwarf2_per_objfile
*data
= dwarf2_objfile_data_key
.get (objfile
);
2563 struct dwarf2_section_info
*info
;
2565 /* We may see an objfile without any DWARF, in which case we just
2576 case DWARF2_DEBUG_FRAME
:
2577 info
= &data
->frame
;
2579 case DWARF2_EH_FRAME
:
2580 info
= &data
->eh_frame
;
2583 gdb_assert_not_reached ("unexpected section");
2586 dwarf2_read_section (objfile
, info
);
2588 *sectp
= get_section_bfd_section (info
);
2589 *bufp
= info
->buffer
;
2590 *sizep
= info
->size
;
2593 /* A helper function to find the sections for a .dwz file. */
2596 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2598 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2600 /* Note that we only support the standard ELF names, because .dwz
2601 is ELF-only (at the time of writing). */
2602 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2604 dwz_file
->abbrev
.s
.section
= sectp
;
2605 dwz_file
->abbrev
.size
= bfd_get_section_size (sectp
);
2607 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2609 dwz_file
->info
.s
.section
= sectp
;
2610 dwz_file
->info
.size
= bfd_get_section_size (sectp
);
2612 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2614 dwz_file
->str
.s
.section
= sectp
;
2615 dwz_file
->str
.size
= bfd_get_section_size (sectp
);
2617 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2619 dwz_file
->line
.s
.section
= sectp
;
2620 dwz_file
->line
.size
= bfd_get_section_size (sectp
);
2622 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2624 dwz_file
->macro
.s
.section
= sectp
;
2625 dwz_file
->macro
.size
= bfd_get_section_size (sectp
);
2627 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2629 dwz_file
->gdb_index
.s
.section
= sectp
;
2630 dwz_file
->gdb_index
.size
= bfd_get_section_size (sectp
);
2632 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2634 dwz_file
->debug_names
.s
.section
= sectp
;
2635 dwz_file
->debug_names
.size
= bfd_get_section_size (sectp
);
2639 /* See dwarf2read.h. */
2642 dwarf2_get_dwz_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
2644 const char *filename
;
2645 bfd_size_type buildid_len_arg
;
2649 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2650 return dwarf2_per_objfile
->dwz_file
.get ();
2652 bfd_set_error (bfd_error_no_error
);
2653 gdb::unique_xmalloc_ptr
<char> data
2654 (bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2655 &buildid_len_arg
, &buildid
));
2658 if (bfd_get_error () == bfd_error_no_error
)
2660 error (_("could not read '.gnu_debugaltlink' section: %s"),
2661 bfd_errmsg (bfd_get_error ()));
2664 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2666 buildid_len
= (size_t) buildid_len_arg
;
2668 filename
= data
.get ();
2670 std::string abs_storage
;
2671 if (!IS_ABSOLUTE_PATH (filename
))
2673 gdb::unique_xmalloc_ptr
<char> abs
2674 = gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2676 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2677 filename
= abs_storage
.c_str ();
2680 /* First try the file name given in the section. If that doesn't
2681 work, try to use the build-id instead. */
2682 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
, -1));
2683 if (dwz_bfd
!= NULL
)
2685 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2686 dwz_bfd
.reset (nullptr);
2689 if (dwz_bfd
== NULL
)
2690 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2692 if (dwz_bfd
== NULL
)
2693 error (_("could not find '.gnu_debugaltlink' file for %s"),
2694 objfile_name (dwarf2_per_objfile
->objfile
));
2696 std::unique_ptr
<struct dwz_file
> result
2697 (new struct dwz_file (std::move (dwz_bfd
)));
2699 bfd_map_over_sections (result
->dwz_bfd
.get (), locate_dwz_sections
,
2702 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
,
2703 result
->dwz_bfd
.get ());
2704 dwarf2_per_objfile
->dwz_file
= std::move (result
);
2705 return dwarf2_per_objfile
->dwz_file
.get ();
2708 /* DWARF quick_symbols_functions support. */
2710 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2711 unique line tables, so we maintain a separate table of all .debug_line
2712 derived entries to support the sharing.
2713 All the quick functions need is the list of file names. We discard the
2714 line_header when we're done and don't need to record it here. */
2715 struct quick_file_names
2717 /* The data used to construct the hash key. */
2718 struct stmt_list_hash hash
;
2720 /* The number of entries in file_names, real_names. */
2721 unsigned int num_file_names
;
2723 /* The file names from the line table, after being run through
2725 const char **file_names
;
2727 /* The file names from the line table after being run through
2728 gdb_realpath. These are computed lazily. */
2729 const char **real_names
;
2732 /* When using the index (and thus not using psymtabs), each CU has an
2733 object of this type. This is used to hold information needed by
2734 the various "quick" methods. */
2735 struct dwarf2_per_cu_quick_data
2737 /* The file table. This can be NULL if there was no file table
2738 or it's currently not read in.
2739 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2740 struct quick_file_names
*file_names
;
2742 /* The corresponding symbol table. This is NULL if symbols for this
2743 CU have not yet been read. */
2744 struct compunit_symtab
*compunit_symtab
;
2746 /* A temporary mark bit used when iterating over all CUs in
2747 expand_symtabs_matching. */
2748 unsigned int mark
: 1;
2750 /* True if we've tried to read the file table and found there isn't one.
2751 There will be no point in trying to read it again next time. */
2752 unsigned int no_file_data
: 1;
2755 /* Utility hash function for a stmt_list_hash. */
2758 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2762 if (stmt_list_hash
->dwo_unit
!= NULL
)
2763 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2764 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2768 /* Utility equality function for a stmt_list_hash. */
2771 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2772 const struct stmt_list_hash
*rhs
)
2774 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2776 if (lhs
->dwo_unit
!= NULL
2777 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2780 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2783 /* Hash function for a quick_file_names. */
2786 hash_file_name_entry (const void *e
)
2788 const struct quick_file_names
*file_data
2789 = (const struct quick_file_names
*) e
;
2791 return hash_stmt_list_entry (&file_data
->hash
);
2794 /* Equality function for a quick_file_names. */
2797 eq_file_name_entry (const void *a
, const void *b
)
2799 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2800 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2802 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2805 /* Delete function for a quick_file_names. */
2808 delete_file_name_entry (void *e
)
2810 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2813 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2815 xfree ((void*) file_data
->file_names
[i
]);
2816 if (file_data
->real_names
)
2817 xfree ((void*) file_data
->real_names
[i
]);
2820 /* The space for the struct itself lives on objfile_obstack,
2821 so we don't free it here. */
2824 /* Create a quick_file_names hash table. */
2827 create_quick_file_names_table (unsigned int nr_initial_entries
)
2829 return htab_create_alloc (nr_initial_entries
,
2830 hash_file_name_entry
, eq_file_name_entry
,
2831 delete_file_name_entry
, xcalloc
, xfree
);
2834 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2835 have to be created afterwards. You should call age_cached_comp_units after
2836 processing PER_CU->CU. dw2_setup must have been already called. */
2839 load_cu (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2841 if (per_cu
->is_debug_types
)
2842 load_full_type_unit (per_cu
);
2844 load_full_comp_unit (per_cu
, skip_partial
, language_minimal
);
2846 if (per_cu
->cu
== NULL
)
2847 return; /* Dummy CU. */
2849 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2852 /* Read in the symbols for PER_CU. */
2855 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2857 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2859 /* Skip type_unit_groups, reading the type units they contain
2860 is handled elsewhere. */
2861 if (IS_TYPE_UNIT_GROUP (per_cu
))
2864 /* The destructor of dwarf2_queue_guard frees any entries left on
2865 the queue. After this point we're guaranteed to leave this function
2866 with the dwarf queue empty. */
2867 dwarf2_queue_guard q_guard
;
2869 if (dwarf2_per_objfile
->using_index
2870 ? per_cu
->v
.quick
->compunit_symtab
== NULL
2871 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2873 queue_comp_unit (per_cu
, language_minimal
);
2874 load_cu (per_cu
, skip_partial
);
2876 /* If we just loaded a CU from a DWO, and we're working with an index
2877 that may badly handle TUs, load all the TUs in that DWO as well.
2878 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2879 if (!per_cu
->is_debug_types
2880 && per_cu
->cu
!= NULL
2881 && per_cu
->cu
->dwo_unit
!= NULL
2882 && dwarf2_per_objfile
->index_table
!= NULL
2883 && dwarf2_per_objfile
->index_table
->version
<= 7
2884 /* DWP files aren't supported yet. */
2885 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
2886 queue_and_load_all_dwo_tus (per_cu
);
2889 process_queue (dwarf2_per_objfile
);
2891 /* Age the cache, releasing compilation units that have not
2892 been used recently. */
2893 age_cached_comp_units (dwarf2_per_objfile
);
2896 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2897 the objfile from which this CU came. Returns the resulting symbol
2900 static struct compunit_symtab
*
2901 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2903 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2905 gdb_assert (dwarf2_per_objfile
->using_index
);
2906 if (!per_cu
->v
.quick
->compunit_symtab
)
2908 free_cached_comp_units
freer (dwarf2_per_objfile
);
2909 scoped_restore decrementer
= increment_reading_symtab ();
2910 dw2_do_instantiate_symtab (per_cu
, skip_partial
);
2911 process_cu_includes (dwarf2_per_objfile
);
2914 return per_cu
->v
.quick
->compunit_symtab
;
2917 /* See declaration. */
2919 dwarf2_per_cu_data
*
2920 dwarf2_per_objfile::get_cutu (int index
)
2922 if (index
>= this->all_comp_units
.size ())
2924 index
-= this->all_comp_units
.size ();
2925 gdb_assert (index
< this->all_type_units
.size ());
2926 return &this->all_type_units
[index
]->per_cu
;
2929 return this->all_comp_units
[index
];
2932 /* See declaration. */
2934 dwarf2_per_cu_data
*
2935 dwarf2_per_objfile::get_cu (int index
)
2937 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2939 return this->all_comp_units
[index
];
2942 /* See declaration. */
2945 dwarf2_per_objfile::get_tu (int index
)
2947 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2949 return this->all_type_units
[index
];
2952 /* Return a new dwarf2_per_cu_data allocated on OBJFILE's
2953 objfile_obstack, and constructed with the specified field
2956 static dwarf2_per_cu_data
*
2957 create_cu_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2958 struct dwarf2_section_info
*section
,
2960 sect_offset sect_off
, ULONGEST length
)
2962 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2963 dwarf2_per_cu_data
*the_cu
2964 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2965 struct dwarf2_per_cu_data
);
2966 the_cu
->sect_off
= sect_off
;
2967 the_cu
->length
= length
;
2968 the_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
2969 the_cu
->section
= section
;
2970 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2971 struct dwarf2_per_cu_quick_data
);
2972 the_cu
->is_dwz
= is_dwz
;
2976 /* A helper for create_cus_from_index that handles a given list of
2980 create_cus_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2981 const gdb_byte
*cu_list
, offset_type n_elements
,
2982 struct dwarf2_section_info
*section
,
2985 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2987 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2989 sect_offset sect_off
2990 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2991 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2994 dwarf2_per_cu_data
*per_cu
2995 = create_cu_from_index_list (dwarf2_per_objfile
, section
, is_dwz
,
2997 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
3001 /* Read the CU list from the mapped index, and use it to create all
3002 the CU objects for this objfile. */
3005 create_cus_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3006 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
3007 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
3009 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
3010 dwarf2_per_objfile
->all_comp_units
.reserve
3011 ((cu_list_elements
+ dwz_elements
) / 2);
3013 create_cus_from_index_list (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3014 &dwarf2_per_objfile
->info
, 0);
3016 if (dwz_elements
== 0)
3019 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3020 create_cus_from_index_list (dwarf2_per_objfile
, dwz_list
, dwz_elements
,
3024 /* Create the signatured type hash table from the index. */
3027 create_signatured_type_table_from_index
3028 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3029 struct dwarf2_section_info
*section
,
3030 const gdb_byte
*bytes
,
3031 offset_type elements
)
3033 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3035 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
3036 dwarf2_per_objfile
->all_type_units
.reserve (elements
/ 3);
3038 htab_t sig_types_hash
= allocate_signatured_type_table (objfile
);
3040 for (offset_type i
= 0; i
< elements
; i
+= 3)
3042 struct signatured_type
*sig_type
;
3045 cu_offset type_offset_in_tu
;
3047 gdb_static_assert (sizeof (ULONGEST
) >= 8);
3048 sect_offset sect_off
3049 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
3051 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
3053 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
3056 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3057 struct signatured_type
);
3058 sig_type
->signature
= signature
;
3059 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
3060 sig_type
->per_cu
.is_debug_types
= 1;
3061 sig_type
->per_cu
.section
= section
;
3062 sig_type
->per_cu
.sect_off
= sect_off
;
3063 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
3064 sig_type
->per_cu
.v
.quick
3065 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3066 struct dwarf2_per_cu_quick_data
);
3068 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3071 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
3074 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3077 /* Create the signatured type hash table from .debug_names. */
3080 create_signatured_type_table_from_debug_names
3081 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3082 const mapped_debug_names
&map
,
3083 struct dwarf2_section_info
*section
,
3084 struct dwarf2_section_info
*abbrev_section
)
3086 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3088 dwarf2_read_section (objfile
, section
);
3089 dwarf2_read_section (objfile
, abbrev_section
);
3091 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
3092 dwarf2_per_objfile
->all_type_units
.reserve (map
.tu_count
);
3094 htab_t sig_types_hash
= allocate_signatured_type_table (objfile
);
3096 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
3098 struct signatured_type
*sig_type
;
3101 sect_offset sect_off
3102 = (sect_offset
) (extract_unsigned_integer
3103 (map
.tu_table_reordered
+ i
* map
.offset_size
,
3105 map
.dwarf5_byte_order
));
3107 comp_unit_head cu_header
;
3108 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
3110 section
->buffer
+ to_underlying (sect_off
),
3113 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3114 struct signatured_type
);
3115 sig_type
->signature
= cu_header
.signature
;
3116 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
3117 sig_type
->per_cu
.is_debug_types
= 1;
3118 sig_type
->per_cu
.section
= section
;
3119 sig_type
->per_cu
.sect_off
= sect_off
;
3120 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
3121 sig_type
->per_cu
.v
.quick
3122 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3123 struct dwarf2_per_cu_quick_data
);
3125 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3128 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
3131 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3134 /* Read the address map data from the mapped index, and use it to
3135 populate the objfile's psymtabs_addrmap. */
3138 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3139 struct mapped_index
*index
)
3141 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3142 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3143 const gdb_byte
*iter
, *end
;
3144 struct addrmap
*mutable_map
;
3147 auto_obstack temp_obstack
;
3149 mutable_map
= addrmap_create_mutable (&temp_obstack
);
3151 iter
= index
->address_table
.data ();
3152 end
= iter
+ index
->address_table
.size ();
3154 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3158 ULONGEST hi
, lo
, cu_index
;
3159 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3161 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3163 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
3168 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
3169 hex_string (lo
), hex_string (hi
));
3173 if (cu_index
>= dwarf2_per_objfile
->all_comp_units
.size ())
3175 complaint (_(".gdb_index address table has invalid CU number %u"),
3176 (unsigned) cu_index
);
3180 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
3181 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
3182 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
3183 dwarf2_per_objfile
->get_cu (cu_index
));
3186 objfile
->partial_symtabs
->psymtabs_addrmap
3187 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
3190 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
3191 populate the objfile's psymtabs_addrmap. */
3194 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3195 struct dwarf2_section_info
*section
)
3197 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3198 bfd
*abfd
= objfile
->obfd
;
3199 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3200 const CORE_ADDR baseaddr
= ANOFFSET (objfile
->section_offsets
,
3201 SECT_OFF_TEXT (objfile
));
3203 auto_obstack temp_obstack
;
3204 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
3206 std::unordered_map
<sect_offset
,
3207 dwarf2_per_cu_data
*,
3208 gdb::hash_enum
<sect_offset
>>
3209 debug_info_offset_to_per_cu
;
3210 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3212 const auto insertpair
3213 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
3214 if (!insertpair
.second
)
3216 warning (_("Section .debug_aranges in %s has duplicate "
3217 "debug_info_offset %s, ignoring .debug_aranges."),
3218 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
3223 dwarf2_read_section (objfile
, section
);
3225 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
3227 const gdb_byte
*addr
= section
->buffer
;
3229 while (addr
< section
->buffer
+ section
->size
)
3231 const gdb_byte
*const entry_addr
= addr
;
3232 unsigned int bytes_read
;
3234 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
3238 const gdb_byte
*const entry_end
= addr
+ entry_length
;
3239 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
3240 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
3241 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
3243 warning (_("Section .debug_aranges in %s entry at offset %s "
3244 "length %s exceeds section length %s, "
3245 "ignoring .debug_aranges."),
3246 objfile_name (objfile
),
3247 plongest (entry_addr
- section
->buffer
),
3248 plongest (bytes_read
+ entry_length
),
3249 pulongest (section
->size
));
3253 /* The version number. */
3254 const uint16_t version
= read_2_bytes (abfd
, addr
);
3258 warning (_("Section .debug_aranges in %s entry at offset %s "
3259 "has unsupported version %d, ignoring .debug_aranges."),
3260 objfile_name (objfile
),
3261 plongest (entry_addr
- section
->buffer
), version
);
3265 const uint64_t debug_info_offset
3266 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
3267 addr
+= offset_size
;
3268 const auto per_cu_it
3269 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
3270 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
3272 warning (_("Section .debug_aranges in %s entry at offset %s "
3273 "debug_info_offset %s does not exists, "
3274 "ignoring .debug_aranges."),
3275 objfile_name (objfile
),
3276 plongest (entry_addr
- section
->buffer
),
3277 pulongest (debug_info_offset
));
3280 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
3282 const uint8_t address_size
= *addr
++;
3283 if (address_size
< 1 || address_size
> 8)
3285 warning (_("Section .debug_aranges in %s entry at offset %s "
3286 "address_size %u is invalid, ignoring .debug_aranges."),
3287 objfile_name (objfile
),
3288 plongest (entry_addr
- section
->buffer
), address_size
);
3292 const uint8_t segment_selector_size
= *addr
++;
3293 if (segment_selector_size
!= 0)
3295 warning (_("Section .debug_aranges in %s entry at offset %s "
3296 "segment_selector_size %u is not supported, "
3297 "ignoring .debug_aranges."),
3298 objfile_name (objfile
),
3299 plongest (entry_addr
- section
->buffer
),
3300 segment_selector_size
);
3304 /* Must pad to an alignment boundary that is twice the address
3305 size. It is undocumented by the DWARF standard but GCC does
3307 for (size_t padding
= ((-(addr
- section
->buffer
))
3308 & (2 * address_size
- 1));
3309 padding
> 0; padding
--)
3312 warning (_("Section .debug_aranges in %s entry at offset %s "
3313 "padding is not zero, ignoring .debug_aranges."),
3314 objfile_name (objfile
),
3315 plongest (entry_addr
- section
->buffer
));
3321 if (addr
+ 2 * address_size
> entry_end
)
3323 warning (_("Section .debug_aranges in %s entry at offset %s "
3324 "address list is not properly terminated, "
3325 "ignoring .debug_aranges."),
3326 objfile_name (objfile
),
3327 plongest (entry_addr
- section
->buffer
));
3330 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
3332 addr
+= address_size
;
3333 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
3335 addr
+= address_size
;
3336 if (start
== 0 && length
== 0)
3338 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
3340 /* Symbol was eliminated due to a COMDAT group. */
3343 ULONGEST end
= start
+ length
;
3344 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
3346 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
3348 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
3352 objfile
->partial_symtabs
->psymtabs_addrmap
3353 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
3356 /* Find a slot in the mapped index INDEX for the object named NAME.
3357 If NAME is found, set *VEC_OUT to point to the CU vector in the
3358 constant pool and return true. If NAME cannot be found, return
3362 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
3363 offset_type
**vec_out
)
3366 offset_type slot
, step
;
3367 int (*cmp
) (const char *, const char *);
3369 gdb::unique_xmalloc_ptr
<char> without_params
;
3370 if (current_language
->la_language
== language_cplus
3371 || current_language
->la_language
== language_fortran
3372 || current_language
->la_language
== language_d
)
3374 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
3377 if (strchr (name
, '(') != NULL
)
3379 without_params
= cp_remove_params (name
);
3381 if (without_params
!= NULL
)
3382 name
= without_params
.get ();
3386 /* Index version 4 did not support case insensitive searches. But the
3387 indices for case insensitive languages are built in lowercase, therefore
3388 simulate our NAME being searched is also lowercased. */
3389 hash
= mapped_index_string_hash ((index
->version
== 4
3390 && case_sensitivity
== case_sensitive_off
3391 ? 5 : index
->version
),
3394 slot
= hash
& (index
->symbol_table
.size () - 1);
3395 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
3396 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
3402 const auto &bucket
= index
->symbol_table
[slot
];
3403 if (bucket
.name
== 0 && bucket
.vec
== 0)
3406 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
3407 if (!cmp (name
, str
))
3409 *vec_out
= (offset_type
*) (index
->constant_pool
3410 + MAYBE_SWAP (bucket
.vec
));
3414 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
3418 /* A helper function that reads the .gdb_index from BUFFER and fills
3419 in MAP. FILENAME is the name of the file containing the data;
3420 it is used for error reporting. DEPRECATED_OK is true if it is
3421 ok to use deprecated sections.
3423 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
3424 out parameters that are filled in with information about the CU and
3425 TU lists in the section.
3427 Returns true if all went well, false otherwise. */
3430 read_gdb_index_from_buffer (struct objfile
*objfile
,
3431 const char *filename
,
3433 gdb::array_view
<const gdb_byte
> buffer
,
3434 struct mapped_index
*map
,
3435 const gdb_byte
**cu_list
,
3436 offset_type
*cu_list_elements
,
3437 const gdb_byte
**types_list
,
3438 offset_type
*types_list_elements
)
3440 const gdb_byte
*addr
= &buffer
[0];
3442 /* Version check. */
3443 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
3444 /* Versions earlier than 3 emitted every copy of a psymbol. This
3445 causes the index to behave very poorly for certain requests. Version 3
3446 contained incomplete addrmap. So, it seems better to just ignore such
3450 static int warning_printed
= 0;
3451 if (!warning_printed
)
3453 warning (_("Skipping obsolete .gdb_index section in %s."),
3455 warning_printed
= 1;
3459 /* Index version 4 uses a different hash function than index version
3462 Versions earlier than 6 did not emit psymbols for inlined
3463 functions. Using these files will cause GDB not to be able to
3464 set breakpoints on inlined functions by name, so we ignore these
3465 indices unless the user has done
3466 "set use-deprecated-index-sections on". */
3467 if (version
< 6 && !deprecated_ok
)
3469 static int warning_printed
= 0;
3470 if (!warning_printed
)
3473 Skipping deprecated .gdb_index section in %s.\n\
3474 Do \"set use-deprecated-index-sections on\" before the file is read\n\
3475 to use the section anyway."),
3477 warning_printed
= 1;
3481 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3482 of the TU (for symbols coming from TUs),
3483 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3484 Plus gold-generated indices can have duplicate entries for global symbols,
3485 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3486 These are just performance bugs, and we can't distinguish gdb-generated
3487 indices from gold-generated ones, so issue no warning here. */
3489 /* Indexes with higher version than the one supported by GDB may be no
3490 longer backward compatible. */
3494 map
->version
= version
;
3496 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3499 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3500 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3504 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3505 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3506 - MAYBE_SWAP (metadata
[i
]))
3510 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3511 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3513 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
3516 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3517 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3519 = gdb::array_view
<mapped_index::symbol_table_slot
>
3520 ((mapped_index::symbol_table_slot
*) symbol_table
,
3521 (mapped_index::symbol_table_slot
*) symbol_table_end
);
3524 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3529 /* Callback types for dwarf2_read_gdb_index. */
3531 typedef gdb::function_view
3532 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_objfile
*)>
3533 get_gdb_index_contents_ftype
;
3534 typedef gdb::function_view
3535 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
3536 get_gdb_index_contents_dwz_ftype
;
3538 /* Read .gdb_index. If everything went ok, initialize the "quick"
3539 elements of all the CUs and return 1. Otherwise, return 0. */
3542 dwarf2_read_gdb_index
3543 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3544 get_gdb_index_contents_ftype get_gdb_index_contents
,
3545 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
3547 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3548 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3549 struct dwz_file
*dwz
;
3550 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3552 gdb::array_view
<const gdb_byte
> main_index_contents
3553 = get_gdb_index_contents (objfile
, dwarf2_per_objfile
);
3555 if (main_index_contents
.empty ())
3558 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3559 if (!read_gdb_index_from_buffer (objfile
, objfile_name (objfile
),
3560 use_deprecated_index_sections
,
3561 main_index_contents
, map
.get (), &cu_list
,
3562 &cu_list_elements
, &types_list
,
3563 &types_list_elements
))
3566 /* Don't use the index if it's empty. */
3567 if (map
->symbol_table
.empty ())
3570 /* If there is a .dwz file, read it so we can get its CU list as
3572 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3575 struct mapped_index dwz_map
;
3576 const gdb_byte
*dwz_types_ignore
;
3577 offset_type dwz_types_elements_ignore
;
3579 gdb::array_view
<const gdb_byte
> dwz_index_content
3580 = get_gdb_index_contents_dwz (objfile
, dwz
);
3582 if (dwz_index_content
.empty ())
3585 if (!read_gdb_index_from_buffer (objfile
,
3586 bfd_get_filename (dwz
->dwz_bfd
), 1,
3587 dwz_index_content
, &dwz_map
,
3588 &dwz_list
, &dwz_list_elements
,
3590 &dwz_types_elements_ignore
))
3592 warning (_("could not read '.gdb_index' section from %s; skipping"),
3593 bfd_get_filename (dwz
->dwz_bfd
));
3598 create_cus_from_index (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3599 dwz_list
, dwz_list_elements
);
3601 if (types_list_elements
)
3603 /* We can only handle a single .debug_types when we have an
3605 if (dwarf2_per_objfile
->types
.size () != 1)
3608 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
3610 create_signatured_type_table_from_index (dwarf2_per_objfile
, section
,
3611 types_list
, types_list_elements
);
3614 create_addrmap_from_index (dwarf2_per_objfile
, map
.get ());
3616 dwarf2_per_objfile
->index_table
= std::move (map
);
3617 dwarf2_per_objfile
->using_index
= 1;
3618 dwarf2_per_objfile
->quick_file_names_table
=
3619 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
3624 /* die_reader_func for dw2_get_file_names. */
3627 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3628 const gdb_byte
*info_ptr
,
3629 struct die_info
*comp_unit_die
,
3633 struct dwarf2_cu
*cu
= reader
->cu
;
3634 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3635 struct dwarf2_per_objfile
*dwarf2_per_objfile
3636 = cu
->per_cu
->dwarf2_per_objfile
;
3637 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3638 struct dwarf2_per_cu_data
*lh_cu
;
3639 struct attribute
*attr
;
3642 struct quick_file_names
*qfn
;
3644 gdb_assert (! this_cu
->is_debug_types
);
3646 /* Our callers never want to match partial units -- instead they
3647 will match the enclosing full CU. */
3648 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3650 this_cu
->v
.quick
->no_file_data
= 1;
3658 sect_offset line_offset
{};
3660 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3663 struct quick_file_names find_entry
;
3665 line_offset
= (sect_offset
) DW_UNSND (attr
);
3667 /* We may have already read in this line header (TU line header sharing).
3668 If we have we're done. */
3669 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3670 find_entry
.hash
.line_sect_off
= line_offset
;
3671 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
3672 &find_entry
, INSERT
);
3675 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3679 lh
= dwarf_decode_line_header (line_offset
, cu
);
3683 lh_cu
->v
.quick
->no_file_data
= 1;
3687 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
3688 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3689 qfn
->hash
.line_sect_off
= line_offset
;
3690 gdb_assert (slot
!= NULL
);
3693 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3695 qfn
->num_file_names
= lh
->file_names
.size ();
3697 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, lh
->file_names
.size ());
3698 for (i
= 0; i
< lh
->file_names
.size (); ++i
)
3699 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
.get (), fnd
.comp_dir
);
3700 qfn
->real_names
= NULL
;
3702 lh_cu
->v
.quick
->file_names
= qfn
;
3705 /* A helper for the "quick" functions which attempts to read the line
3706 table for THIS_CU. */
3708 static struct quick_file_names
*
3709 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3711 /* This should never be called for TUs. */
3712 gdb_assert (! this_cu
->is_debug_types
);
3713 /* Nor type unit groups. */
3714 gdb_assert (! IS_TYPE_UNIT_GROUP (this_cu
));
3716 if (this_cu
->v
.quick
->file_names
!= NULL
)
3717 return this_cu
->v
.quick
->file_names
;
3718 /* If we know there is no line data, no point in looking again. */
3719 if (this_cu
->v
.quick
->no_file_data
)
3722 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
3724 if (this_cu
->v
.quick
->no_file_data
)
3726 return this_cu
->v
.quick
->file_names
;
3729 /* A helper for the "quick" functions which computes and caches the
3730 real path for a given file name from the line table. */
3733 dw2_get_real_path (struct objfile
*objfile
,
3734 struct quick_file_names
*qfn
, int index
)
3736 if (qfn
->real_names
== NULL
)
3737 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3738 qfn
->num_file_names
, const char *);
3740 if (qfn
->real_names
[index
] == NULL
)
3741 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3743 return qfn
->real_names
[index
];
3746 static struct symtab
*
3747 dw2_find_last_source_symtab (struct objfile
*objfile
)
3749 struct dwarf2_per_objfile
*dwarf2_per_objfile
3750 = get_dwarf2_per_objfile (objfile
);
3751 dwarf2_per_cu_data
*dwarf_cu
= dwarf2_per_objfile
->all_comp_units
.back ();
3752 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, false);
3757 return compunit_primary_filetab (cust
);
3760 /* Traversal function for dw2_forget_cached_source_info. */
3763 dw2_free_cached_file_names (void **slot
, void *info
)
3765 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3767 if (file_data
->real_names
)
3771 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3773 xfree ((void*) file_data
->real_names
[i
]);
3774 file_data
->real_names
[i
] = NULL
;
3782 dw2_forget_cached_source_info (struct objfile
*objfile
)
3784 struct dwarf2_per_objfile
*dwarf2_per_objfile
3785 = get_dwarf2_per_objfile (objfile
);
3787 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
3788 dw2_free_cached_file_names
, NULL
);
3791 /* Helper function for dw2_map_symtabs_matching_filename that expands
3792 the symtabs and calls the iterator. */
3795 dw2_map_expand_apply (struct objfile
*objfile
,
3796 struct dwarf2_per_cu_data
*per_cu
,
3797 const char *name
, const char *real_path
,
3798 gdb::function_view
<bool (symtab
*)> callback
)
3800 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3802 /* Don't visit already-expanded CUs. */
3803 if (per_cu
->v
.quick
->compunit_symtab
)
3806 /* This may expand more than one symtab, and we want to iterate over
3808 dw2_instantiate_symtab (per_cu
, false);
3810 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3811 last_made
, callback
);
3814 /* Implementation of the map_symtabs_matching_filename method. */
3817 dw2_map_symtabs_matching_filename
3818 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3819 gdb::function_view
<bool (symtab
*)> callback
)
3821 const char *name_basename
= lbasename (name
);
3822 struct dwarf2_per_objfile
*dwarf2_per_objfile
3823 = get_dwarf2_per_objfile (objfile
);
3825 /* The rule is CUs specify all the files, including those used by
3826 any TU, so there's no need to scan TUs here. */
3828 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3830 /* We only need to look at symtabs not already expanded. */
3831 if (per_cu
->v
.quick
->compunit_symtab
)
3834 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3835 if (file_data
== NULL
)
3838 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3840 const char *this_name
= file_data
->file_names
[j
];
3841 const char *this_real_name
;
3843 if (compare_filenames_for_search (this_name
, name
))
3845 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3851 /* Before we invoke realpath, which can get expensive when many
3852 files are involved, do a quick comparison of the basenames. */
3853 if (! basenames_may_differ
3854 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3857 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3858 if (compare_filenames_for_search (this_real_name
, name
))
3860 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3866 if (real_path
!= NULL
)
3868 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3869 gdb_assert (IS_ABSOLUTE_PATH (name
));
3870 if (this_real_name
!= NULL
3871 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3873 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3885 /* Struct used to manage iterating over all CUs looking for a symbol. */
3887 struct dw2_symtab_iterator
3889 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3890 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
3891 /* If set, only look for symbols that match that block. Valid values are
3892 GLOBAL_BLOCK and STATIC_BLOCK. */
3893 gdb::optional
<block_enum
> block_index
;
3894 /* The kind of symbol we're looking for. */
3896 /* The list of CUs from the index entry of the symbol,
3897 or NULL if not found. */
3899 /* The next element in VEC to look at. */
3901 /* The number of elements in VEC, or zero if there is no match. */
3903 /* Have we seen a global version of the symbol?
3904 If so we can ignore all further global instances.
3905 This is to work around gold/15646, inefficient gold-generated
3910 /* Initialize the index symtab iterator ITER. */
3913 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3914 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3915 gdb::optional
<block_enum
> block_index
,
3919 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3920 iter
->block_index
= block_index
;
3921 iter
->domain
= domain
;
3923 iter
->global_seen
= 0;
3925 mapped_index
*index
= dwarf2_per_objfile
->index_table
.get ();
3927 /* index is NULL if OBJF_READNOW. */
3928 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3929 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3937 /* Return the next matching CU or NULL if there are no more. */
3939 static struct dwarf2_per_cu_data
*
3940 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3942 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
3944 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3946 offset_type cu_index_and_attrs
=
3947 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3948 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3949 gdb_index_symbol_kind symbol_kind
=
3950 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3951 /* Only check the symbol attributes if they're present.
3952 Indices prior to version 7 don't record them,
3953 and indices >= 7 may elide them for certain symbols
3954 (gold does this). */
3956 (dwarf2_per_objfile
->index_table
->version
>= 7
3957 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3959 /* Don't crash on bad data. */
3960 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
3961 + dwarf2_per_objfile
->all_type_units
.size ()))
3963 complaint (_(".gdb_index entry has bad CU index"
3965 objfile_name (dwarf2_per_objfile
->objfile
));
3969 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
3971 /* Skip if already read in. */
3972 if (per_cu
->v
.quick
->compunit_symtab
)
3975 /* Check static vs global. */
3978 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3980 if (iter
->block_index
.has_value ())
3982 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3984 if (is_static
!= want_static
)
3988 /* Work around gold/15646. */
3989 if (!is_static
&& iter
->global_seen
)
3992 iter
->global_seen
= 1;
3995 /* Only check the symbol's kind if it has one. */
3998 switch (iter
->domain
)
4001 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
4002 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
4003 /* Some types are also in VAR_DOMAIN. */
4004 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4008 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4012 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4027 static struct compunit_symtab
*
4028 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
4029 const char *name
, domain_enum domain
)
4031 struct compunit_symtab
*stab_best
= NULL
;
4032 struct dwarf2_per_objfile
*dwarf2_per_objfile
4033 = get_dwarf2_per_objfile (objfile
);
4035 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
4037 struct dw2_symtab_iterator iter
;
4038 struct dwarf2_per_cu_data
*per_cu
;
4040 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, block_index
, domain
, name
);
4042 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4044 struct symbol
*sym
, *with_opaque
= NULL
;
4045 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
4046 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
4047 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
4049 sym
= block_find_symbol (block
, name
, domain
,
4050 block_find_non_opaque_type_preferred
,
4053 /* Some caution must be observed with overloaded functions
4054 and methods, since the index will not contain any overload
4055 information (but NAME might contain it). */
4058 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
4060 if (with_opaque
!= NULL
4061 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
4064 /* Keep looking through other CUs. */
4071 dw2_print_stats (struct objfile
*objfile
)
4073 struct dwarf2_per_objfile
*dwarf2_per_objfile
4074 = get_dwarf2_per_objfile (objfile
);
4075 int total
= (dwarf2_per_objfile
->all_comp_units
.size ()
4076 + dwarf2_per_objfile
->all_type_units
.size ());
4079 for (int i
= 0; i
< total
; ++i
)
4081 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
4083 if (!per_cu
->v
.quick
->compunit_symtab
)
4086 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
4087 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
4090 /* This dumps minimal information about the index.
4091 It is called via "mt print objfiles".
4092 One use is to verify .gdb_index has been loaded by the
4093 gdb.dwarf2/gdb-index.exp testcase. */
4096 dw2_dump (struct objfile
*objfile
)
4098 struct dwarf2_per_objfile
*dwarf2_per_objfile
4099 = get_dwarf2_per_objfile (objfile
);
4101 gdb_assert (dwarf2_per_objfile
->using_index
);
4102 printf_filtered (".gdb_index:");
4103 if (dwarf2_per_objfile
->index_table
!= NULL
)
4105 printf_filtered (" version %d\n",
4106 dwarf2_per_objfile
->index_table
->version
);
4109 printf_filtered (" faked for \"readnow\"\n");
4110 printf_filtered ("\n");
4114 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
4115 const char *func_name
)
4117 struct dwarf2_per_objfile
*dwarf2_per_objfile
4118 = get_dwarf2_per_objfile (objfile
);
4120 struct dw2_symtab_iterator iter
;
4121 struct dwarf2_per_cu_data
*per_cu
;
4123 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, {}, VAR_DOMAIN
, func_name
);
4125 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4126 dw2_instantiate_symtab (per_cu
, false);
4131 dw2_expand_all_symtabs (struct objfile
*objfile
)
4133 struct dwarf2_per_objfile
*dwarf2_per_objfile
4134 = get_dwarf2_per_objfile (objfile
);
4135 int total_units
= (dwarf2_per_objfile
->all_comp_units
.size ()
4136 + dwarf2_per_objfile
->all_type_units
.size ());
4138 for (int i
= 0; i
< total_units
; ++i
)
4140 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
4142 /* We don't want to directly expand a partial CU, because if we
4143 read it with the wrong language, then assertion failures can
4144 be triggered later on. See PR symtab/23010. So, tell
4145 dw2_instantiate_symtab to skip partial CUs -- any important
4146 partial CU will be read via DW_TAG_imported_unit anyway. */
4147 dw2_instantiate_symtab (per_cu
, true);
4152 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
4153 const char *fullname
)
4155 struct dwarf2_per_objfile
*dwarf2_per_objfile
4156 = get_dwarf2_per_objfile (objfile
);
4158 /* We don't need to consider type units here.
4159 This is only called for examining code, e.g. expand_line_sal.
4160 There can be an order of magnitude (or more) more type units
4161 than comp units, and we avoid them if we can. */
4163 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4165 /* We only need to look at symtabs not already expanded. */
4166 if (per_cu
->v
.quick
->compunit_symtab
)
4169 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4170 if (file_data
== NULL
)
4173 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4175 const char *this_fullname
= file_data
->file_names
[j
];
4177 if (filename_cmp (this_fullname
, fullname
) == 0)
4179 dw2_instantiate_symtab (per_cu
, false);
4187 dw2_map_matching_symbols
4188 (struct objfile
*objfile
,
4189 const lookup_name_info
&name
, domain_enum domain
,
4191 gdb::function_view
<symbol_found_callback_ftype
> callback
,
4192 symbol_compare_ftype
*ordered_compare
)
4194 /* Currently unimplemented; used for Ada. The function can be called if the
4195 current language is Ada for a non-Ada objfile using GNU index. As Ada
4196 does not look for non-Ada symbols this function should just return. */
4199 /* Symbol name matcher for .gdb_index names.
4201 Symbol names in .gdb_index have a few particularities:
4203 - There's no indication of which is the language of each symbol.
4205 Since each language has its own symbol name matching algorithm,
4206 and we don't know which language is the right one, we must match
4207 each symbol against all languages. This would be a potential
4208 performance problem if it were not mitigated by the
4209 mapped_index::name_components lookup table, which significantly
4210 reduces the number of times we need to call into this matcher,
4211 making it a non-issue.
4213 - Symbol names in the index have no overload (parameter)
4214 information. I.e., in C++, "foo(int)" and "foo(long)" both
4215 appear as "foo" in the index, for example.
4217 This means that the lookup names passed to the symbol name
4218 matcher functions must have no parameter information either
4219 because (e.g.) symbol search name "foo" does not match
4220 lookup-name "foo(int)" [while swapping search name for lookup
4223 class gdb_index_symbol_name_matcher
4226 /* Prepares the vector of comparison functions for LOOKUP_NAME. */
4227 gdb_index_symbol_name_matcher (const lookup_name_info
&lookup_name
);
4229 /* Walk all the matcher routines and match SYMBOL_NAME against them.
4230 Returns true if any matcher matches. */
4231 bool matches (const char *symbol_name
);
4234 /* A reference to the lookup name we're matching against. */
4235 const lookup_name_info
&m_lookup_name
;
4237 /* A vector holding all the different symbol name matchers, for all
4239 std::vector
<symbol_name_matcher_ftype
*> m_symbol_name_matcher_funcs
;
4242 gdb_index_symbol_name_matcher::gdb_index_symbol_name_matcher
4243 (const lookup_name_info
&lookup_name
)
4244 : m_lookup_name (lookup_name
)
4246 /* Prepare the vector of comparison functions upfront, to avoid
4247 doing the same work for each symbol. Care is taken to avoid
4248 matching with the same matcher more than once if/when multiple
4249 languages use the same matcher function. */
4250 auto &matchers
= m_symbol_name_matcher_funcs
;
4251 matchers
.reserve (nr_languages
);
4253 matchers
.push_back (default_symbol_name_matcher
);
4255 for (int i
= 0; i
< nr_languages
; i
++)
4257 const language_defn
*lang
= language_def ((enum language
) i
);
4258 symbol_name_matcher_ftype
*name_matcher
4259 = get_symbol_name_matcher (lang
, m_lookup_name
);
4261 /* Don't insert the same comparison routine more than once.
4262 Note that we do this linear walk instead of a seemingly
4263 cheaper sorted insert, or use a std::set or something like
4264 that, because relative order of function addresses is not
4265 stable. This is not a problem in practice because the number
4266 of supported languages is low, and the cost here is tiny
4267 compared to the number of searches we'll do afterwards using
4269 if (name_matcher
!= default_symbol_name_matcher
4270 && (std::find (matchers
.begin (), matchers
.end (), name_matcher
)
4271 == matchers
.end ()))
4272 matchers
.push_back (name_matcher
);
4277 gdb_index_symbol_name_matcher::matches (const char *symbol_name
)
4279 for (auto matches_name
: m_symbol_name_matcher_funcs
)
4280 if (matches_name (symbol_name
, m_lookup_name
, NULL
))
4286 /* Starting from a search name, return the string that finds the upper
4287 bound of all strings that start with SEARCH_NAME in a sorted name
4288 list. Returns the empty string to indicate that the upper bound is
4289 the end of the list. */
4292 make_sort_after_prefix_name (const char *search_name
)
4294 /* When looking to complete "func", we find the upper bound of all
4295 symbols that start with "func" by looking for where we'd insert
4296 the closest string that would follow "func" in lexicographical
4297 order. Usually, that's "func"-with-last-character-incremented,
4298 i.e. "fund". Mind non-ASCII characters, though. Usually those
4299 will be UTF-8 multi-byte sequences, but we can't be certain.
4300 Especially mind the 0xff character, which is a valid character in
4301 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
4302 rule out compilers allowing it in identifiers. Note that
4303 conveniently, strcmp/strcasecmp are specified to compare
4304 characters interpreted as unsigned char. So what we do is treat
4305 the whole string as a base 256 number composed of a sequence of
4306 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
4307 to 0, and carries 1 to the following more-significant position.
4308 If the very first character in SEARCH_NAME ends up incremented
4309 and carries/overflows, then the upper bound is the end of the
4310 list. The string after the empty string is also the empty
4313 Some examples of this operation:
4315 SEARCH_NAME => "+1" RESULT
4319 "\xff" "a" "\xff" => "\xff" "b"
4324 Then, with these symbols for example:
4330 completing "func" looks for symbols between "func" and
4331 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
4332 which finds "func" and "func1", but not "fund".
4336 funcÿ (Latin1 'ÿ' [0xff])
4340 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
4341 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
4345 ÿÿ (Latin1 'ÿ' [0xff])
4348 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
4349 the end of the list.
4351 std::string after
= search_name
;
4352 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
4354 if (!after
.empty ())
4355 after
.back () = (unsigned char) after
.back () + 1;
4359 /* See declaration. */
4361 std::pair
<std::vector
<name_component
>::const_iterator
,
4362 std::vector
<name_component
>::const_iterator
>
4363 mapped_index_base::find_name_components_bounds
4364 (const lookup_name_info
&lookup_name_without_params
) const
4367 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4370 = lookup_name_without_params
.cplus ().lookup_name ().c_str ();
4372 /* Comparison function object for lower_bound that matches against a
4373 given symbol name. */
4374 auto lookup_compare_lower
= [&] (const name_component
&elem
,
4377 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4378 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4379 return name_cmp (elem_name
, name
) < 0;
4382 /* Comparison function object for upper_bound that matches against a
4383 given symbol name. */
4384 auto lookup_compare_upper
= [&] (const char *name
,
4385 const name_component
&elem
)
4387 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4388 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4389 return name_cmp (name
, elem_name
) < 0;
4392 auto begin
= this->name_components
.begin ();
4393 auto end
= this->name_components
.end ();
4395 /* Find the lower bound. */
4398 if (lookup_name_without_params
.completion_mode () && cplus
[0] == '\0')
4401 return std::lower_bound (begin
, end
, cplus
, lookup_compare_lower
);
4404 /* Find the upper bound. */
4407 if (lookup_name_without_params
.completion_mode ())
4409 /* In completion mode, we want UPPER to point past all
4410 symbols names that have the same prefix. I.e., with
4411 these symbols, and completing "func":
4413 function << lower bound
4415 other_function << upper bound
4417 We find the upper bound by looking for the insertion
4418 point of "func"-with-last-character-incremented,
4420 std::string after
= make_sort_after_prefix_name (cplus
);
4423 return std::lower_bound (lower
, end
, after
.c_str (),
4424 lookup_compare_lower
);
4427 return std::upper_bound (lower
, end
, cplus
, lookup_compare_upper
);
4430 return {lower
, upper
};
4433 /* See declaration. */
4436 mapped_index_base::build_name_components ()
4438 if (!this->name_components
.empty ())
4441 this->name_components_casing
= case_sensitivity
;
4443 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4445 /* The code below only knows how to break apart components of C++
4446 symbol names (and other languages that use '::' as
4447 namespace/module separator). If we add support for wild matching
4448 to some language that uses some other operator (E.g., Ada, Go and
4449 D use '.'), then we'll need to try splitting the symbol name
4450 according to that language too. Note that Ada does support wild
4451 matching, but doesn't currently support .gdb_index. */
4452 auto count
= this->symbol_name_count ();
4453 for (offset_type idx
= 0; idx
< count
; idx
++)
4455 if (this->symbol_name_slot_invalid (idx
))
4458 const char *name
= this->symbol_name_at (idx
);
4460 /* Add each name component to the name component table. */
4461 unsigned int previous_len
= 0;
4462 for (unsigned int current_len
= cp_find_first_component (name
);
4463 name
[current_len
] != '\0';
4464 current_len
+= cp_find_first_component (name
+ current_len
))
4466 gdb_assert (name
[current_len
] == ':');
4467 this->name_components
.push_back ({previous_len
, idx
});
4468 /* Skip the '::'. */
4470 previous_len
= current_len
;
4472 this->name_components
.push_back ({previous_len
, idx
});
4475 /* Sort name_components elements by name. */
4476 auto name_comp_compare
= [&] (const name_component
&left
,
4477 const name_component
&right
)
4479 const char *left_qualified
= this->symbol_name_at (left
.idx
);
4480 const char *right_qualified
= this->symbol_name_at (right
.idx
);
4482 const char *left_name
= left_qualified
+ left
.name_offset
;
4483 const char *right_name
= right_qualified
+ right
.name_offset
;
4485 return name_cmp (left_name
, right_name
) < 0;
4488 std::sort (this->name_components
.begin (),
4489 this->name_components
.end (),
4493 /* Helper for dw2_expand_symtabs_matching that works with a
4494 mapped_index_base instead of the containing objfile. This is split
4495 to a separate function in order to be able to unit test the
4496 name_components matching using a mock mapped_index_base. For each
4497 symbol name that matches, calls MATCH_CALLBACK, passing it the
4498 symbol's index in the mapped_index_base symbol table. */
4501 dw2_expand_symtabs_matching_symbol
4502 (mapped_index_base
&index
,
4503 const lookup_name_info
&lookup_name_in
,
4504 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4505 enum search_domain kind
,
4506 gdb::function_view
<void (offset_type
)> match_callback
)
4508 lookup_name_info lookup_name_without_params
4509 = lookup_name_in
.make_ignore_params ();
4510 gdb_index_symbol_name_matcher lookup_name_matcher
4511 (lookup_name_without_params
);
4513 /* Build the symbol name component sorted vector, if we haven't
4515 index
.build_name_components ();
4517 auto bounds
= index
.find_name_components_bounds (lookup_name_without_params
);
4519 /* Now for each symbol name in range, check to see if we have a name
4520 match, and if so, call the MATCH_CALLBACK callback. */
4522 /* The same symbol may appear more than once in the range though.
4523 E.g., if we're looking for symbols that complete "w", and we have
4524 a symbol named "w1::w2", we'll find the two name components for
4525 that same symbol in the range. To be sure we only call the
4526 callback once per symbol, we first collect the symbol name
4527 indexes that matched in a temporary vector and ignore
4529 std::vector
<offset_type
> matches
;
4530 matches
.reserve (std::distance (bounds
.first
, bounds
.second
));
4532 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
4534 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
4536 if (!lookup_name_matcher
.matches (qualified
)
4537 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4540 matches
.push_back (bounds
.first
->idx
);
4543 std::sort (matches
.begin (), matches
.end ());
4545 /* Finally call the callback, once per match. */
4547 for (offset_type idx
: matches
)
4551 match_callback (idx
);
4556 /* Above we use a type wider than idx's for 'prev', since 0 and
4557 (offset_type)-1 are both possible values. */
4558 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4563 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4565 /* A mock .gdb_index/.debug_names-like name index table, enough to
4566 exercise dw2_expand_symtabs_matching_symbol, which works with the
4567 mapped_index_base interface. Builds an index from the symbol list
4568 passed as parameter to the constructor. */
4569 class mock_mapped_index
: public mapped_index_base
4572 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4573 : m_symbol_table (symbols
)
4576 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4578 /* Return the number of names in the symbol table. */
4579 size_t symbol_name_count () const override
4581 return m_symbol_table
.size ();
4584 /* Get the name of the symbol at IDX in the symbol table. */
4585 const char *symbol_name_at (offset_type idx
) const override
4587 return m_symbol_table
[idx
];
4591 gdb::array_view
<const char *> m_symbol_table
;
4594 /* Convenience function that converts a NULL pointer to a "<null>"
4595 string, to pass to print routines. */
4598 string_or_null (const char *str
)
4600 return str
!= NULL
? str
: "<null>";
4603 /* Check if a lookup_name_info built from
4604 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4605 index. EXPECTED_LIST is the list of expected matches, in expected
4606 matching order. If no match expected, then an empty list is
4607 specified. Returns true on success. On failure prints a warning
4608 indicating the file:line that failed, and returns false. */
4611 check_match (const char *file
, int line
,
4612 mock_mapped_index
&mock_index
,
4613 const char *name
, symbol_name_match_type match_type
,
4614 bool completion_mode
,
4615 std::initializer_list
<const char *> expected_list
)
4617 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4619 bool matched
= true;
4621 auto mismatch
= [&] (const char *expected_str
,
4624 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4625 "expected=\"%s\", got=\"%s\"\n"),
4627 (match_type
== symbol_name_match_type::FULL
4629 name
, string_or_null (expected_str
), string_or_null (got
));
4633 auto expected_it
= expected_list
.begin ();
4634 auto expected_end
= expected_list
.end ();
4636 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4638 [&] (offset_type idx
)
4640 const char *matched_name
= mock_index
.symbol_name_at (idx
);
4641 const char *expected_str
4642 = expected_it
== expected_end
? NULL
: *expected_it
++;
4644 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4645 mismatch (expected_str
, matched_name
);
4648 const char *expected_str
4649 = expected_it
== expected_end
? NULL
: *expected_it
++;
4650 if (expected_str
!= NULL
)
4651 mismatch (expected_str
, NULL
);
4656 /* The symbols added to the mock mapped_index for testing (in
4658 static const char *test_symbols
[] = {
4667 "ns2::tmpl<int>::foo2",
4668 "(anonymous namespace)::A::B::C",
4670 /* These are used to check that the increment-last-char in the
4671 matching algorithm for completion doesn't match "t1_fund" when
4672 completing "t1_func". */
4678 /* A UTF-8 name with multi-byte sequences to make sure that
4679 cp-name-parser understands this as a single identifier ("função"
4680 is "function" in PT). */
4683 /* \377 (0xff) is Latin1 'ÿ'. */
4686 /* \377 (0xff) is Latin1 'ÿ'. */
4690 /* A name with all sorts of complications. Starts with "z" to make
4691 it easier for the completion tests below. */
4692 #define Z_SYM_NAME \
4693 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4694 "::tuple<(anonymous namespace)::ui*, " \
4695 "std::default_delete<(anonymous namespace)::ui>, void>"
4700 /* Returns true if the mapped_index_base::find_name_component_bounds
4701 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4702 in completion mode. */
4705 check_find_bounds_finds (mapped_index_base
&index
,
4706 const char *search_name
,
4707 gdb::array_view
<const char *> expected_syms
)
4709 lookup_name_info
lookup_name (search_name
,
4710 symbol_name_match_type::FULL
, true);
4712 auto bounds
= index
.find_name_components_bounds (lookup_name
);
4714 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4715 if (distance
!= expected_syms
.size ())
4718 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4720 auto nc_elem
= bounds
.first
+ exp_elem
;
4721 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
4722 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4729 /* Test the lower-level mapped_index::find_name_component_bounds
4733 test_mapped_index_find_name_component_bounds ()
4735 mock_mapped_index
mock_index (test_symbols
);
4737 mock_index
.build_name_components ();
4739 /* Test the lower-level mapped_index::find_name_component_bounds
4740 method in completion mode. */
4742 static const char *expected_syms
[] = {
4747 SELF_CHECK (check_find_bounds_finds (mock_index
,
4748 "t1_func", expected_syms
));
4751 /* Check that the increment-last-char in the name matching algorithm
4752 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4754 static const char *expected_syms1
[] = {
4758 SELF_CHECK (check_find_bounds_finds (mock_index
,
4759 "\377", expected_syms1
));
4761 static const char *expected_syms2
[] = {
4764 SELF_CHECK (check_find_bounds_finds (mock_index
,
4765 "\377\377", expected_syms2
));
4769 /* Test dw2_expand_symtabs_matching_symbol. */
4772 test_dw2_expand_symtabs_matching_symbol ()
4774 mock_mapped_index
mock_index (test_symbols
);
4776 /* We let all tests run until the end even if some fails, for debug
4778 bool any_mismatch
= false;
4780 /* Create the expected symbols list (an initializer_list). Needed
4781 because lists have commas, and we need to pass them to CHECK,
4782 which is a macro. */
4783 #define EXPECT(...) { __VA_ARGS__ }
4785 /* Wrapper for check_match that passes down the current
4786 __FILE__/__LINE__. */
4787 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4788 any_mismatch |= !check_match (__FILE__, __LINE__, \
4790 NAME, MATCH_TYPE, COMPLETION_MODE, \
4793 /* Identity checks. */
4794 for (const char *sym
: test_symbols
)
4796 /* Should be able to match all existing symbols. */
4797 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4800 /* Should be able to match all existing symbols with
4802 std::string with_params
= std::string (sym
) + "(int)";
4803 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4806 /* Should be able to match all existing symbols with
4807 parameters and qualifiers. */
4808 with_params
= std::string (sym
) + " ( int ) const";
4809 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4812 /* This should really find sym, but cp-name-parser.y doesn't
4813 know about lvalue/rvalue qualifiers yet. */
4814 with_params
= std::string (sym
) + " ( int ) &&";
4815 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4819 /* Check that the name matching algorithm for completion doesn't get
4820 confused with Latin1 'ÿ' / 0xff. */
4822 static const char str
[] = "\377";
4823 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4824 EXPECT ("\377", "\377\377123"));
4827 /* Check that the increment-last-char in the matching algorithm for
4828 completion doesn't match "t1_fund" when completing "t1_func". */
4830 static const char str
[] = "t1_func";
4831 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4832 EXPECT ("t1_func", "t1_func1"));
4835 /* Check that completion mode works at each prefix of the expected
4838 static const char str
[] = "function(int)";
4839 size_t len
= strlen (str
);
4842 for (size_t i
= 1; i
< len
; i
++)
4844 lookup
.assign (str
, i
);
4845 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4846 EXPECT ("function"));
4850 /* While "w" is a prefix of both components, the match function
4851 should still only be called once. */
4853 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4855 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4859 /* Same, with a "complicated" symbol. */
4861 static const char str
[] = Z_SYM_NAME
;
4862 size_t len
= strlen (str
);
4865 for (size_t i
= 1; i
< len
; i
++)
4867 lookup
.assign (str
, i
);
4868 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4869 EXPECT (Z_SYM_NAME
));
4873 /* In FULL mode, an incomplete symbol doesn't match. */
4875 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4879 /* A complete symbol with parameters matches any overload, since the
4880 index has no overload info. */
4882 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4883 EXPECT ("std::zfunction", "std::zfunction2"));
4884 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4885 EXPECT ("std::zfunction", "std::zfunction2"));
4886 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4887 EXPECT ("std::zfunction", "std::zfunction2"));
4890 /* Check that whitespace is ignored appropriately. A symbol with a
4891 template argument list. */
4893 static const char expected
[] = "ns::foo<int>";
4894 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4896 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4900 /* Check that whitespace is ignored appropriately. A symbol with a
4901 template argument list that includes a pointer. */
4903 static const char expected
[] = "ns::foo<char*>";
4904 /* Try both completion and non-completion modes. */
4905 static const bool completion_mode
[2] = {false, true};
4906 for (size_t i
= 0; i
< 2; i
++)
4908 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4909 completion_mode
[i
], EXPECT (expected
));
4910 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4911 completion_mode
[i
], EXPECT (expected
));
4913 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4914 completion_mode
[i
], EXPECT (expected
));
4915 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4916 completion_mode
[i
], EXPECT (expected
));
4921 /* Check method qualifiers are ignored. */
4922 static const char expected
[] = "ns::foo<char*>";
4923 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4924 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4925 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4926 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4927 CHECK_MATCH ("foo < char * > ( int ) const",
4928 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4929 CHECK_MATCH ("foo < char * > ( int ) &&",
4930 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4933 /* Test lookup names that don't match anything. */
4935 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4938 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4942 /* Some wild matching tests, exercising "(anonymous namespace)",
4943 which should not be confused with a parameter list. */
4945 static const char *syms
[] = {
4949 "A :: B :: C ( int )",
4954 for (const char *s
: syms
)
4956 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4957 EXPECT ("(anonymous namespace)::A::B::C"));
4962 static const char expected
[] = "ns2::tmpl<int>::foo2";
4963 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4965 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4969 SELF_CHECK (!any_mismatch
);
4978 test_mapped_index_find_name_component_bounds ();
4979 test_dw2_expand_symtabs_matching_symbol ();
4982 }} // namespace selftests::dw2_expand_symtabs_matching
4984 #endif /* GDB_SELF_TEST */
4986 /* If FILE_MATCHER is NULL or if PER_CU has
4987 dwarf2_per_cu_quick_data::MARK set (see
4988 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4989 EXPANSION_NOTIFY on it. */
4992 dw2_expand_symtabs_matching_one
4993 (struct dwarf2_per_cu_data
*per_cu
,
4994 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4995 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4997 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4999 bool symtab_was_null
5000 = (per_cu
->v
.quick
->compunit_symtab
== NULL
);
5002 dw2_instantiate_symtab (per_cu
, false);
5004 if (expansion_notify
!= NULL
5006 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
5007 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
5011 /* Helper for dw2_expand_matching symtabs. Called on each symbol
5012 matched, to expand corresponding CUs that were marked. IDX is the
5013 index of the symbol name that matched. */
5016 dw2_expand_marked_cus
5017 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
5018 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5019 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5022 offset_type
*vec
, vec_len
, vec_idx
;
5023 bool global_seen
= false;
5024 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
5026 vec
= (offset_type
*) (index
.constant_pool
5027 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
5028 vec_len
= MAYBE_SWAP (vec
[0]);
5029 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
5031 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
5032 /* This value is only valid for index versions >= 7. */
5033 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
5034 gdb_index_symbol_kind symbol_kind
=
5035 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
5036 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
5037 /* Only check the symbol attributes if they're present.
5038 Indices prior to version 7 don't record them,
5039 and indices >= 7 may elide them for certain symbols
5040 (gold does this). */
5043 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
5045 /* Work around gold/15646. */
5048 if (!is_static
&& global_seen
)
5054 /* Only check the symbol's kind if it has one. */
5059 case VARIABLES_DOMAIN
:
5060 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
5063 case FUNCTIONS_DOMAIN
:
5064 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
5068 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
5076 /* Don't crash on bad data. */
5077 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
5078 + dwarf2_per_objfile
->all_type_units
.size ()))
5080 complaint (_(".gdb_index entry has bad CU index"
5082 objfile_name (dwarf2_per_objfile
->objfile
));
5086 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
5087 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5092 /* If FILE_MATCHER is non-NULL, set all the
5093 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
5094 that match FILE_MATCHER. */
5097 dw_expand_symtabs_matching_file_matcher
5098 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5099 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
5101 if (file_matcher
== NULL
)
5104 objfile
*const objfile
= dwarf2_per_objfile
->objfile
;
5106 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
5108 NULL
, xcalloc
, xfree
));
5109 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
5111 NULL
, xcalloc
, xfree
));
5113 /* The rule is CUs specify all the files, including those used by
5114 any TU, so there's no need to scan TUs here. */
5116 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5120 per_cu
->v
.quick
->mark
= 0;
5122 /* We only need to look at symtabs not already expanded. */
5123 if (per_cu
->v
.quick
->compunit_symtab
)
5126 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
5127 if (file_data
== NULL
)
5130 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
5132 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
5134 per_cu
->v
.quick
->mark
= 1;
5138 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
5140 const char *this_real_name
;
5142 if (file_matcher (file_data
->file_names
[j
], false))
5144 per_cu
->v
.quick
->mark
= 1;
5148 /* Before we invoke realpath, which can get expensive when many
5149 files are involved, do a quick comparison of the basenames. */
5150 if (!basenames_may_differ
5151 && !file_matcher (lbasename (file_data
->file_names
[j
]),
5155 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
5156 if (file_matcher (this_real_name
, false))
5158 per_cu
->v
.quick
->mark
= 1;
5163 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
5164 ? visited_found
.get ()
5165 : visited_not_found
.get (),
5172 dw2_expand_symtabs_matching
5173 (struct objfile
*objfile
,
5174 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5175 const lookup_name_info
&lookup_name
,
5176 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5177 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5178 enum search_domain kind
)
5180 struct dwarf2_per_objfile
*dwarf2_per_objfile
5181 = get_dwarf2_per_objfile (objfile
);
5183 /* index_table is NULL if OBJF_READNOW. */
5184 if (!dwarf2_per_objfile
->index_table
)
5187 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5189 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
5191 dw2_expand_symtabs_matching_symbol (index
, lookup_name
,
5193 kind
, [&] (offset_type idx
)
5195 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
5196 expansion_notify
, kind
);
5200 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
5203 static struct compunit_symtab
*
5204 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
5209 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
5210 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
5213 if (cust
->includes
== NULL
)
5216 for (i
= 0; cust
->includes
[i
]; ++i
)
5218 struct compunit_symtab
*s
= cust
->includes
[i
];
5220 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
5228 static struct compunit_symtab
*
5229 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
5230 struct bound_minimal_symbol msymbol
,
5232 struct obj_section
*section
,
5235 struct dwarf2_per_cu_data
*data
;
5236 struct compunit_symtab
*result
;
5238 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
5241 CORE_ADDR baseaddr
= ANOFFSET (objfile
->section_offsets
,
5242 SECT_OFF_TEXT (objfile
));
5243 data
= (struct dwarf2_per_cu_data
*) addrmap_find
5244 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
5248 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
5249 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
5250 paddress (get_objfile_arch (objfile
), pc
));
5253 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
,
5256 gdb_assert (result
!= NULL
);
5261 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
5262 void *data
, int need_fullname
)
5264 struct dwarf2_per_objfile
*dwarf2_per_objfile
5265 = get_dwarf2_per_objfile (objfile
);
5267 if (!dwarf2_per_objfile
->filenames_cache
)
5269 dwarf2_per_objfile
->filenames_cache
.emplace ();
5271 htab_up
visited (htab_create_alloc (10,
5272 htab_hash_pointer
, htab_eq_pointer
,
5273 NULL
, xcalloc
, xfree
));
5275 /* The rule is CUs specify all the files, including those used
5276 by any TU, so there's no need to scan TUs here. We can
5277 ignore file names coming from already-expanded CUs. */
5279 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5281 if (per_cu
->v
.quick
->compunit_symtab
)
5283 void **slot
= htab_find_slot (visited
.get (),
5284 per_cu
->v
.quick
->file_names
,
5287 *slot
= per_cu
->v
.quick
->file_names
;
5291 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5293 /* We only need to look at symtabs not already expanded. */
5294 if (per_cu
->v
.quick
->compunit_symtab
)
5297 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
5298 if (file_data
== NULL
)
5301 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
5304 /* Already visited. */
5309 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
5311 const char *filename
= file_data
->file_names
[j
];
5312 dwarf2_per_objfile
->filenames_cache
->seen (filename
);
5317 dwarf2_per_objfile
->filenames_cache
->traverse ([&] (const char *filename
)
5319 gdb::unique_xmalloc_ptr
<char> this_real_name
;
5322 this_real_name
= gdb_realpath (filename
);
5323 (*fun
) (filename
, this_real_name
.get (), data
);
5328 dw2_has_symbols (struct objfile
*objfile
)
5333 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
5336 dw2_find_last_source_symtab
,
5337 dw2_forget_cached_source_info
,
5338 dw2_map_symtabs_matching_filename
,
5342 dw2_expand_symtabs_for_function
,
5343 dw2_expand_all_symtabs
,
5344 dw2_expand_symtabs_with_fullname
,
5345 dw2_map_matching_symbols
,
5346 dw2_expand_symtabs_matching
,
5347 dw2_find_pc_sect_compunit_symtab
,
5349 dw2_map_symbol_filenames
5352 /* DWARF-5 debug_names reader. */
5354 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
5355 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
5357 /* A helper function that reads the .debug_names section in SECTION
5358 and fills in MAP. FILENAME is the name of the file containing the
5359 section; it is used for error reporting.
5361 Returns true if all went well, false otherwise. */
5364 read_debug_names_from_section (struct objfile
*objfile
,
5365 const char *filename
,
5366 struct dwarf2_section_info
*section
,
5367 mapped_debug_names
&map
)
5369 if (dwarf2_section_empty_p (section
))
5372 /* Older elfutils strip versions could keep the section in the main
5373 executable while splitting it for the separate debug info file. */
5374 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
5377 dwarf2_read_section (objfile
, section
);
5379 map
.dwarf5_byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
5381 const gdb_byte
*addr
= section
->buffer
;
5383 bfd
*const abfd
= get_section_bfd_owner (section
);
5385 unsigned int bytes_read
;
5386 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
5389 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
5390 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
5391 if (bytes_read
+ length
!= section
->size
)
5393 /* There may be multiple per-CU indices. */
5394 warning (_("Section .debug_names in %s length %s does not match "
5395 "section length %s, ignoring .debug_names."),
5396 filename
, plongest (bytes_read
+ length
),
5397 pulongest (section
->size
));
5401 /* The version number. */
5402 uint16_t version
= read_2_bytes (abfd
, addr
);
5406 warning (_("Section .debug_names in %s has unsupported version %d, "
5407 "ignoring .debug_names."),
5413 uint16_t padding
= read_2_bytes (abfd
, addr
);
5417 warning (_("Section .debug_names in %s has unsupported padding %d, "
5418 "ignoring .debug_names."),
5423 /* comp_unit_count - The number of CUs in the CU list. */
5424 map
.cu_count
= read_4_bytes (abfd
, addr
);
5427 /* local_type_unit_count - The number of TUs in the local TU
5429 map
.tu_count
= read_4_bytes (abfd
, addr
);
5432 /* foreign_type_unit_count - The number of TUs in the foreign TU
5434 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
5436 if (foreign_tu_count
!= 0)
5438 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
5439 "ignoring .debug_names."),
5440 filename
, static_cast<unsigned long> (foreign_tu_count
));
5444 /* bucket_count - The number of hash buckets in the hash lookup
5446 map
.bucket_count
= read_4_bytes (abfd
, addr
);
5449 /* name_count - The number of unique names in the index. */
5450 map
.name_count
= read_4_bytes (abfd
, addr
);
5453 /* abbrev_table_size - The size in bytes of the abbreviations
5455 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
5458 /* augmentation_string_size - The size in bytes of the augmentation
5459 string. This value is rounded up to a multiple of 4. */
5460 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
5462 map
.augmentation_is_gdb
= ((augmentation_string_size
5463 == sizeof (dwarf5_augmentation
))
5464 && memcmp (addr
, dwarf5_augmentation
,
5465 sizeof (dwarf5_augmentation
)) == 0);
5466 augmentation_string_size
+= (-augmentation_string_size
) & 3;
5467 addr
+= augmentation_string_size
;
5470 map
.cu_table_reordered
= addr
;
5471 addr
+= map
.cu_count
* map
.offset_size
;
5473 /* List of Local TUs */
5474 map
.tu_table_reordered
= addr
;
5475 addr
+= map
.tu_count
* map
.offset_size
;
5477 /* Hash Lookup Table */
5478 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5479 addr
+= map
.bucket_count
* 4;
5480 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5481 addr
+= map
.name_count
* 4;
5484 map
.name_table_string_offs_reordered
= addr
;
5485 addr
+= map
.name_count
* map
.offset_size
;
5486 map
.name_table_entry_offs_reordered
= addr
;
5487 addr
+= map
.name_count
* map
.offset_size
;
5489 const gdb_byte
*abbrev_table_start
= addr
;
5492 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5497 const auto insertpair
5498 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
5499 if (!insertpair
.second
)
5501 warning (_("Section .debug_names in %s has duplicate index %s, "
5502 "ignoring .debug_names."),
5503 filename
, pulongest (index_num
));
5506 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
5507 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5512 mapped_debug_names::index_val::attr attr
;
5513 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5515 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5517 if (attr
.form
== DW_FORM_implicit_const
)
5519 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
5523 if (attr
.dw_idx
== 0 && attr
.form
== 0)
5525 indexval
.attr_vec
.push_back (std::move (attr
));
5528 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
5530 warning (_("Section .debug_names in %s has abbreviation_table "
5531 "of size %s vs. written as %u, ignoring .debug_names."),
5532 filename
, plongest (addr
- abbrev_table_start
),
5536 map
.entry_pool
= addr
;
5541 /* A helper for create_cus_from_debug_names that handles the MAP's CU
5545 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5546 const mapped_debug_names
&map
,
5547 dwarf2_section_info
§ion
,
5550 sect_offset sect_off_prev
;
5551 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5553 sect_offset sect_off_next
;
5554 if (i
< map
.cu_count
)
5557 = (sect_offset
) (extract_unsigned_integer
5558 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5560 map
.dwarf5_byte_order
));
5563 sect_off_next
= (sect_offset
) section
.size
;
5566 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5567 dwarf2_per_cu_data
*per_cu
5568 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
5569 sect_off_prev
, length
);
5570 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
5572 sect_off_prev
= sect_off_next
;
5576 /* Read the CU list from the mapped index, and use it to create all
5577 the CU objects for this dwarf2_per_objfile. */
5580 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5581 const mapped_debug_names
&map
,
5582 const mapped_debug_names
&dwz_map
)
5584 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
5585 dwarf2_per_objfile
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5587 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
5588 dwarf2_per_objfile
->info
,
5589 false /* is_dwz */);
5591 if (dwz_map
.cu_count
== 0)
5594 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5595 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
5599 /* Read .debug_names. If everything went ok, initialize the "quick"
5600 elements of all the CUs and return true. Otherwise, return false. */
5603 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
5605 std::unique_ptr
<mapped_debug_names
> map
5606 (new mapped_debug_names (dwarf2_per_objfile
));
5607 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
5608 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5610 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5611 &dwarf2_per_objfile
->debug_names
,
5615 /* Don't use the index if it's empty. */
5616 if (map
->name_count
== 0)
5619 /* If there is a .dwz file, read it so we can get its CU list as
5621 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5624 if (!read_debug_names_from_section (objfile
,
5625 bfd_get_filename (dwz
->dwz_bfd
),
5626 &dwz
->debug_names
, dwz_map
))
5628 warning (_("could not read '.debug_names' section from %s; skipping"),
5629 bfd_get_filename (dwz
->dwz_bfd
));
5634 create_cus_from_debug_names (dwarf2_per_objfile
, *map
, dwz_map
);
5636 if (map
->tu_count
!= 0)
5638 /* We can only handle a single .debug_types when we have an
5640 if (dwarf2_per_objfile
->types
.size () != 1)
5643 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
5645 create_signatured_type_table_from_debug_names
5646 (dwarf2_per_objfile
, *map
, section
, &dwarf2_per_objfile
->abbrev
);
5649 create_addrmap_from_aranges (dwarf2_per_objfile
,
5650 &dwarf2_per_objfile
->debug_aranges
);
5652 dwarf2_per_objfile
->debug_names_table
= std::move (map
);
5653 dwarf2_per_objfile
->using_index
= 1;
5654 dwarf2_per_objfile
->quick_file_names_table
=
5655 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
5660 /* Type used to manage iterating over all CUs looking for a symbol for
5663 class dw2_debug_names_iterator
5666 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5667 gdb::optional
<block_enum
> block_index
,
5670 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5671 m_addr (find_vec_in_debug_names (map
, name
))
5674 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5675 search_domain search
, uint32_t namei
)
5678 m_addr (find_vec_in_debug_names (map
, namei
))
5681 /* Return the next matching CU or NULL if there are no more. */
5682 dwarf2_per_cu_data
*next ();
5685 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5687 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5690 /* The internalized form of .debug_names. */
5691 const mapped_debug_names
&m_map
;
5693 /* If set, only look for symbols that match that block. Valid values are
5694 GLOBAL_BLOCK and STATIC_BLOCK. */
5695 const gdb::optional
<block_enum
> m_block_index
;
5697 /* The kind of symbol we're looking for. */
5698 const domain_enum m_domain
= UNDEF_DOMAIN
;
5699 const search_domain m_search
= ALL_DOMAIN
;
5701 /* The list of CUs from the index entry of the symbol, or NULL if
5703 const gdb_byte
*m_addr
;
5707 mapped_debug_names::namei_to_name (uint32_t namei
) const
5709 const ULONGEST namei_string_offs
5710 = extract_unsigned_integer ((name_table_string_offs_reordered
5711 + namei
* offset_size
),
5714 return read_indirect_string_at_offset
5715 (dwarf2_per_objfile
, dwarf2_per_objfile
->objfile
->obfd
, namei_string_offs
);
5718 /* Find a slot in .debug_names for the object named NAME. If NAME is
5719 found, return pointer to its pool data. If NAME cannot be found,
5723 dw2_debug_names_iterator::find_vec_in_debug_names
5724 (const mapped_debug_names
&map
, const char *name
)
5726 int (*cmp
) (const char *, const char *);
5728 gdb::unique_xmalloc_ptr
<char> without_params
;
5729 if (current_language
->la_language
== language_cplus
5730 || current_language
->la_language
== language_fortran
5731 || current_language
->la_language
== language_d
)
5733 /* NAME is already canonical. Drop any qualifiers as
5734 .debug_names does not contain any. */
5736 if (strchr (name
, '(') != NULL
)
5738 without_params
= cp_remove_params (name
);
5739 if (without_params
!= NULL
)
5740 name
= without_params
.get ();
5744 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5746 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5748 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5749 (map
.bucket_table_reordered
5750 + (full_hash
% map
.bucket_count
)), 4,
5751 map
.dwarf5_byte_order
);
5755 if (namei
>= map
.name_count
)
5757 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5759 namei
, map
.name_count
,
5760 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5766 const uint32_t namei_full_hash
5767 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5768 (map
.hash_table_reordered
+ namei
), 4,
5769 map
.dwarf5_byte_order
);
5770 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5773 if (full_hash
== namei_full_hash
)
5775 const char *const namei_string
= map
.namei_to_name (namei
);
5777 #if 0 /* An expensive sanity check. */
5778 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5780 complaint (_("Wrong .debug_names hash for string at index %u "
5782 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5787 if (cmp (namei_string
, name
) == 0)
5789 const ULONGEST namei_entry_offs
5790 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5791 + namei
* map
.offset_size
),
5792 map
.offset_size
, map
.dwarf5_byte_order
);
5793 return map
.entry_pool
+ namei_entry_offs
;
5798 if (namei
>= map
.name_count
)
5804 dw2_debug_names_iterator::find_vec_in_debug_names
5805 (const mapped_debug_names
&map
, uint32_t namei
)
5807 if (namei
>= map
.name_count
)
5809 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5811 namei
, map
.name_count
,
5812 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5816 const ULONGEST namei_entry_offs
5817 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5818 + namei
* map
.offset_size
),
5819 map
.offset_size
, map
.dwarf5_byte_order
);
5820 return map
.entry_pool
+ namei_entry_offs
;
5823 /* See dw2_debug_names_iterator. */
5825 dwarf2_per_cu_data
*
5826 dw2_debug_names_iterator::next ()
5831 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
5832 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5833 bfd
*const abfd
= objfile
->obfd
;
5837 unsigned int bytes_read
;
5838 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5839 m_addr
+= bytes_read
;
5843 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5844 if (indexval_it
== m_map
.abbrev_map
.cend ())
5846 complaint (_("Wrong .debug_names undefined abbrev code %s "
5848 pulongest (abbrev
), objfile_name (objfile
));
5851 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5852 enum class symbol_linkage
{
5856 } symbol_linkage_
= symbol_linkage::unknown
;
5857 dwarf2_per_cu_data
*per_cu
= NULL
;
5858 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5863 case DW_FORM_implicit_const
:
5864 ull
= attr
.implicit_const
;
5866 case DW_FORM_flag_present
:
5870 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5871 m_addr
+= bytes_read
;
5874 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5875 dwarf_form_name (attr
.form
),
5876 objfile_name (objfile
));
5879 switch (attr
.dw_idx
)
5881 case DW_IDX_compile_unit
:
5882 /* Don't crash on bad data. */
5883 if (ull
>= dwarf2_per_objfile
->all_comp_units
.size ())
5885 complaint (_(".debug_names entry has bad CU index %s"
5888 objfile_name (dwarf2_per_objfile
->objfile
));
5891 per_cu
= dwarf2_per_objfile
->get_cutu (ull
);
5893 case DW_IDX_type_unit
:
5894 /* Don't crash on bad data. */
5895 if (ull
>= dwarf2_per_objfile
->all_type_units
.size ())
5897 complaint (_(".debug_names entry has bad TU index %s"
5900 objfile_name (dwarf2_per_objfile
->objfile
));
5903 per_cu
= &dwarf2_per_objfile
->get_tu (ull
)->per_cu
;
5905 case DW_IDX_GNU_internal
:
5906 if (!m_map
.augmentation_is_gdb
)
5908 symbol_linkage_
= symbol_linkage::static_
;
5910 case DW_IDX_GNU_external
:
5911 if (!m_map
.augmentation_is_gdb
)
5913 symbol_linkage_
= symbol_linkage::extern_
;
5918 /* Skip if already read in. */
5919 if (per_cu
->v
.quick
->compunit_symtab
)
5922 /* Check static vs global. */
5923 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5925 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5926 const bool symbol_is_static
=
5927 symbol_linkage_
== symbol_linkage::static_
;
5928 if (want_static
!= symbol_is_static
)
5932 /* Match dw2_symtab_iter_next, symbol_kind
5933 and debug_names::psymbol_tag. */
5937 switch (indexval
.dwarf_tag
)
5939 case DW_TAG_variable
:
5940 case DW_TAG_subprogram
:
5941 /* Some types are also in VAR_DOMAIN. */
5942 case DW_TAG_typedef
:
5943 case DW_TAG_structure_type
:
5950 switch (indexval
.dwarf_tag
)
5952 case DW_TAG_typedef
:
5953 case DW_TAG_structure_type
:
5960 switch (indexval
.dwarf_tag
)
5963 case DW_TAG_variable
:
5973 /* Match dw2_expand_symtabs_matching, symbol_kind and
5974 debug_names::psymbol_tag. */
5977 case VARIABLES_DOMAIN
:
5978 switch (indexval
.dwarf_tag
)
5980 case DW_TAG_variable
:
5986 case FUNCTIONS_DOMAIN
:
5987 switch (indexval
.dwarf_tag
)
5989 case DW_TAG_subprogram
:
5996 switch (indexval
.dwarf_tag
)
5998 case DW_TAG_typedef
:
5999 case DW_TAG_structure_type
:
6012 static struct compunit_symtab
*
6013 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
6014 const char *name
, domain_enum domain
)
6016 struct dwarf2_per_objfile
*dwarf2_per_objfile
6017 = get_dwarf2_per_objfile (objfile
);
6019 const auto &mapp
= dwarf2_per_objfile
->debug_names_table
;
6022 /* index is NULL if OBJF_READNOW. */
6025 const auto &map
= *mapp
;
6027 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
);
6029 struct compunit_symtab
*stab_best
= NULL
;
6030 struct dwarf2_per_cu_data
*per_cu
;
6031 while ((per_cu
= iter
.next ()) != NULL
)
6033 struct symbol
*sym
, *with_opaque
= NULL
;
6034 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
6035 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
6036 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
6038 sym
= block_find_symbol (block
, name
, domain
,
6039 block_find_non_opaque_type_preferred
,
6042 /* Some caution must be observed with overloaded functions and
6043 methods, since the index will not contain any overload
6044 information (but NAME might contain it). */
6047 && strcmp_iw (SYMBOL_SEARCH_NAME (sym
), name
) == 0)
6049 if (with_opaque
!= NULL
6050 && strcmp_iw (SYMBOL_SEARCH_NAME (with_opaque
), name
) == 0)
6053 /* Keep looking through other CUs. */
6059 /* This dumps minimal information about .debug_names. It is called
6060 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
6061 uses this to verify that .debug_names has been loaded. */
6064 dw2_debug_names_dump (struct objfile
*objfile
)
6066 struct dwarf2_per_objfile
*dwarf2_per_objfile
6067 = get_dwarf2_per_objfile (objfile
);
6069 gdb_assert (dwarf2_per_objfile
->using_index
);
6070 printf_filtered (".debug_names:");
6071 if (dwarf2_per_objfile
->debug_names_table
)
6072 printf_filtered (" exists\n");
6074 printf_filtered (" faked for \"readnow\"\n");
6075 printf_filtered ("\n");
6079 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
6080 const char *func_name
)
6082 struct dwarf2_per_objfile
*dwarf2_per_objfile
6083 = get_dwarf2_per_objfile (objfile
);
6085 /* dwarf2_per_objfile->debug_names_table is NULL if OBJF_READNOW. */
6086 if (dwarf2_per_objfile
->debug_names_table
)
6088 const mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6090 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
);
6092 struct dwarf2_per_cu_data
*per_cu
;
6093 while ((per_cu
= iter
.next ()) != NULL
)
6094 dw2_instantiate_symtab (per_cu
, false);
6099 dw2_debug_names_expand_symtabs_matching
6100 (struct objfile
*objfile
,
6101 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
6102 const lookup_name_info
&lookup_name
,
6103 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
6104 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
6105 enum search_domain kind
)
6107 struct dwarf2_per_objfile
*dwarf2_per_objfile
6108 = get_dwarf2_per_objfile (objfile
);
6110 /* debug_names_table is NULL if OBJF_READNOW. */
6111 if (!dwarf2_per_objfile
->debug_names_table
)
6114 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
6116 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6118 dw2_expand_symtabs_matching_symbol (map
, lookup_name
,
6120 kind
, [&] (offset_type namei
)
6122 /* The name was matched, now expand corresponding CUs that were
6124 dw2_debug_names_iterator
iter (map
, kind
, namei
);
6126 struct dwarf2_per_cu_data
*per_cu
;
6127 while ((per_cu
= iter
.next ()) != NULL
)
6128 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
6133 const struct quick_symbol_functions dwarf2_debug_names_functions
=
6136 dw2_find_last_source_symtab
,
6137 dw2_forget_cached_source_info
,
6138 dw2_map_symtabs_matching_filename
,
6139 dw2_debug_names_lookup_symbol
,
6141 dw2_debug_names_dump
,
6142 dw2_debug_names_expand_symtabs_for_function
,
6143 dw2_expand_all_symtabs
,
6144 dw2_expand_symtabs_with_fullname
,
6145 dw2_map_matching_symbols
,
6146 dw2_debug_names_expand_symtabs_matching
,
6147 dw2_find_pc_sect_compunit_symtab
,
6149 dw2_map_symbol_filenames
6152 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
6153 to either a dwarf2_per_objfile or dwz_file object. */
6155 template <typename T
>
6156 static gdb::array_view
<const gdb_byte
>
6157 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
6159 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
6161 if (dwarf2_section_empty_p (section
))
6164 /* Older elfutils strip versions could keep the section in the main
6165 executable while splitting it for the separate debug info file. */
6166 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
6169 dwarf2_read_section (obj
, section
);
6171 /* dwarf2_section_info::size is a bfd_size_type, while
6172 gdb::array_view works with size_t. On 32-bit hosts, with
6173 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
6174 is 32-bit. So we need an explicit narrowing conversion here.
6175 This is fine, because it's impossible to allocate or mmap an
6176 array/buffer larger than what size_t can represent. */
6177 return gdb::make_array_view (section
->buffer
, section
->size
);
6180 /* Lookup the index cache for the contents of the index associated to
6183 static gdb::array_view
<const gdb_byte
>
6184 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_objfile
*dwarf2_obj
)
6186 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
6187 if (build_id
== nullptr)
6190 return global_index_cache
.lookup_gdb_index (build_id
,
6191 &dwarf2_obj
->index_cache_res
);
6194 /* Same as the above, but for DWZ. */
6196 static gdb::array_view
<const gdb_byte
>
6197 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
6199 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
6200 if (build_id
== nullptr)
6203 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
6206 /* See symfile.h. */
6209 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
6211 struct dwarf2_per_objfile
*dwarf2_per_objfile
6212 = get_dwarf2_per_objfile (objfile
);
6214 /* If we're about to read full symbols, don't bother with the
6215 indices. In this case we also don't care if some other debug
6216 format is making psymtabs, because they are all about to be
6218 if ((objfile
->flags
& OBJF_READNOW
))
6220 dwarf2_per_objfile
->using_index
= 1;
6221 create_all_comp_units (dwarf2_per_objfile
);
6222 create_all_type_units (dwarf2_per_objfile
);
6223 dwarf2_per_objfile
->quick_file_names_table
6224 = create_quick_file_names_table
6225 (dwarf2_per_objfile
->all_comp_units
.size ());
6227 for (int i
= 0; i
< (dwarf2_per_objfile
->all_comp_units
.size ()
6228 + dwarf2_per_objfile
->all_type_units
.size ()); ++i
)
6230 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
6232 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6233 struct dwarf2_per_cu_quick_data
);
6236 /* Return 1 so that gdb sees the "quick" functions. However,
6237 these functions will be no-ops because we will have expanded
6239 *index_kind
= dw_index_kind::GDB_INDEX
;
6243 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
6245 *index_kind
= dw_index_kind::DEBUG_NAMES
;
6249 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
6250 get_gdb_index_contents_from_section
<struct dwarf2_per_objfile
>,
6251 get_gdb_index_contents_from_section
<dwz_file
>))
6253 *index_kind
= dw_index_kind::GDB_INDEX
;
6257 /* ... otherwise, try to find the index in the index cache. */
6258 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
6259 get_gdb_index_contents_from_cache
,
6260 get_gdb_index_contents_from_cache_dwz
))
6262 global_index_cache
.hit ();
6263 *index_kind
= dw_index_kind::GDB_INDEX
;
6267 global_index_cache
.miss ();
6273 /* Build a partial symbol table. */
6276 dwarf2_build_psymtabs (struct objfile
*objfile
)
6278 struct dwarf2_per_objfile
*dwarf2_per_objfile
6279 = get_dwarf2_per_objfile (objfile
);
6281 init_psymbol_list (objfile
, 1024);
6285 /* This isn't really ideal: all the data we allocate on the
6286 objfile's obstack is still uselessly kept around. However,
6287 freeing it seems unsafe. */
6288 psymtab_discarder
psymtabs (objfile
);
6289 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
6292 /* (maybe) store an index in the cache. */
6293 global_index_cache
.store (dwarf2_per_objfile
);
6295 catch (const gdb_exception_error
&except
)
6297 exception_print (gdb_stderr
, except
);
6301 /* Return the total length of the CU described by HEADER. */
6304 get_cu_length (const struct comp_unit_head
*header
)
6306 return header
->initial_length_size
+ header
->length
;
6309 /* Return TRUE if SECT_OFF is within CU_HEADER. */
6312 offset_in_cu_p (const comp_unit_head
*cu_header
, sect_offset sect_off
)
6314 sect_offset bottom
= cu_header
->sect_off
;
6315 sect_offset top
= cu_header
->sect_off
+ get_cu_length (cu_header
);
6317 return sect_off
>= bottom
&& sect_off
< top
;
6320 /* Find the base address of the compilation unit for range lists and
6321 location lists. It will normally be specified by DW_AT_low_pc.
6322 In DWARF-3 draft 4, the base address could be overridden by
6323 DW_AT_entry_pc. It's been removed, but GCC still uses this for
6324 compilation units with discontinuous ranges. */
6327 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
6329 struct attribute
*attr
;
6332 cu
->base_address
= 0;
6334 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
6337 cu
->base_address
= attr_value_as_address (attr
);
6342 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6345 cu
->base_address
= attr_value_as_address (attr
);
6351 /* Read in the comp unit header information from the debug_info at info_ptr.
6352 Use rcuh_kind::COMPILE as the default type if not known by the caller.
6353 NOTE: This leaves members offset, first_die_offset to be filled in
6356 static const gdb_byte
*
6357 read_comp_unit_head (struct comp_unit_head
*cu_header
,
6358 const gdb_byte
*info_ptr
,
6359 struct dwarf2_section_info
*section
,
6360 rcuh_kind section_kind
)
6363 unsigned int bytes_read
;
6364 const char *filename
= get_section_file_name (section
);
6365 bfd
*abfd
= get_section_bfd_owner (section
);
6367 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
6368 cu_header
->initial_length_size
= bytes_read
;
6369 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
6370 info_ptr
+= bytes_read
;
6371 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
6372 if (cu_header
->version
< 2 || cu_header
->version
> 5)
6373 error (_("Dwarf Error: wrong version in compilation unit header "
6374 "(is %d, should be 2, 3, 4 or 5) [in module %s]"),
6375 cu_header
->version
, filename
);
6377 if (cu_header
->version
< 5)
6378 switch (section_kind
)
6380 case rcuh_kind::COMPILE
:
6381 cu_header
->unit_type
= DW_UT_compile
;
6383 case rcuh_kind::TYPE
:
6384 cu_header
->unit_type
= DW_UT_type
;
6387 internal_error (__FILE__
, __LINE__
,
6388 _("read_comp_unit_head: invalid section_kind"));
6392 cu_header
->unit_type
= static_cast<enum dwarf_unit_type
>
6393 (read_1_byte (abfd
, info_ptr
));
6395 switch (cu_header
->unit_type
)
6399 case DW_UT_skeleton
:
6400 case DW_UT_split_compile
:
6401 if (section_kind
!= rcuh_kind::COMPILE
)
6402 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6403 "(is %s, should be %s) [in module %s]"),
6404 dwarf_unit_type_name (cu_header
->unit_type
),
6405 dwarf_unit_type_name (DW_UT_type
), filename
);
6408 case DW_UT_split_type
:
6409 section_kind
= rcuh_kind::TYPE
;
6412 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6413 "(is %#04x, should be one of: %s, %s, %s, %s or %s) "
6414 "[in module %s]"), cu_header
->unit_type
,
6415 dwarf_unit_type_name (DW_UT_compile
),
6416 dwarf_unit_type_name (DW_UT_skeleton
),
6417 dwarf_unit_type_name (DW_UT_split_compile
),
6418 dwarf_unit_type_name (DW_UT_type
),
6419 dwarf_unit_type_name (DW_UT_split_type
), filename
);
6422 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6425 cu_header
->abbrev_sect_off
= (sect_offset
) read_offset (abfd
, info_ptr
,
6428 info_ptr
+= bytes_read
;
6429 if (cu_header
->version
< 5)
6431 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6434 signed_addr
= bfd_get_sign_extend_vma (abfd
);
6435 if (signed_addr
< 0)
6436 internal_error (__FILE__
, __LINE__
,
6437 _("read_comp_unit_head: dwarf from non elf file"));
6438 cu_header
->signed_addr_p
= signed_addr
;
6440 bool header_has_signature
= section_kind
== rcuh_kind::TYPE
6441 || cu_header
->unit_type
== DW_UT_skeleton
6442 || cu_header
->unit_type
== DW_UT_split_compile
;
6444 if (header_has_signature
)
6446 cu_header
->signature
= read_8_bytes (abfd
, info_ptr
);
6450 if (section_kind
== rcuh_kind::TYPE
)
6452 LONGEST type_offset
;
6453 type_offset
= read_offset (abfd
, info_ptr
, cu_header
, &bytes_read
);
6454 info_ptr
+= bytes_read
;
6455 cu_header
->type_cu_offset_in_tu
= (cu_offset
) type_offset
;
6456 if (to_underlying (cu_header
->type_cu_offset_in_tu
) != type_offset
)
6457 error (_("Dwarf Error: Too big type_offset in compilation unit "
6458 "header (is %s) [in module %s]"), plongest (type_offset
),
6465 /* Helper function that returns the proper abbrev section for
6468 static struct dwarf2_section_info
*
6469 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
6471 struct dwarf2_section_info
*abbrev
;
6472 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6474 if (this_cu
->is_dwz
)
6475 abbrev
= &dwarf2_get_dwz_file (dwarf2_per_objfile
)->abbrev
;
6477 abbrev
= &dwarf2_per_objfile
->abbrev
;
6482 /* Subroutine of read_and_check_comp_unit_head and
6483 read_and_check_type_unit_head to simplify them.
6484 Perform various error checking on the header. */
6487 error_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6488 struct comp_unit_head
*header
,
6489 struct dwarf2_section_info
*section
,
6490 struct dwarf2_section_info
*abbrev_section
)
6492 const char *filename
= get_section_file_name (section
);
6494 if (to_underlying (header
->abbrev_sect_off
)
6495 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
, abbrev_section
))
6496 error (_("Dwarf Error: bad offset (%s) in compilation unit header "
6497 "(offset %s + 6) [in module %s]"),
6498 sect_offset_str (header
->abbrev_sect_off
),
6499 sect_offset_str (header
->sect_off
),
6502 /* Cast to ULONGEST to use 64-bit arithmetic when possible to
6503 avoid potential 32-bit overflow. */
6504 if (((ULONGEST
) header
->sect_off
+ get_cu_length (header
))
6506 error (_("Dwarf Error: bad length (0x%x) in compilation unit header "
6507 "(offset %s + 0) [in module %s]"),
6508 header
->length
, sect_offset_str (header
->sect_off
),
6512 /* Read in a CU/TU header and perform some basic error checking.
6513 The contents of the header are stored in HEADER.
6514 The result is a pointer to the start of the first DIE. */
6516 static const gdb_byte
*
6517 read_and_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6518 struct comp_unit_head
*header
,
6519 struct dwarf2_section_info
*section
,
6520 struct dwarf2_section_info
*abbrev_section
,
6521 const gdb_byte
*info_ptr
,
6522 rcuh_kind section_kind
)
6524 const gdb_byte
*beg_of_comp_unit
= info_ptr
;
6526 header
->sect_off
= (sect_offset
) (beg_of_comp_unit
- section
->buffer
);
6528 info_ptr
= read_comp_unit_head (header
, info_ptr
, section
, section_kind
);
6530 header
->first_die_cu_offset
= (cu_offset
) (info_ptr
- beg_of_comp_unit
);
6532 error_check_comp_unit_head (dwarf2_per_objfile
, header
, section
,
6538 /* Fetch the abbreviation table offset from a comp or type unit header. */
6541 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6542 struct dwarf2_section_info
*section
,
6543 sect_offset sect_off
)
6545 bfd
*abfd
= get_section_bfd_owner (section
);
6546 const gdb_byte
*info_ptr
;
6547 unsigned int initial_length_size
, offset_size
;
6550 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
6551 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
6552 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6553 offset_size
= initial_length_size
== 4 ? 4 : 8;
6554 info_ptr
+= initial_length_size
;
6556 version
= read_2_bytes (abfd
, info_ptr
);
6560 /* Skip unit type and address size. */
6564 return (sect_offset
) read_offset_1 (abfd
, info_ptr
, offset_size
);
6567 /* Allocate a new partial symtab for file named NAME and mark this new
6568 partial symtab as being an include of PST. */
6571 dwarf2_create_include_psymtab (const char *name
, struct partial_symtab
*pst
,
6572 struct objfile
*objfile
)
6574 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
6576 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6578 /* It shares objfile->objfile_obstack. */
6579 subpst
->dirname
= pst
->dirname
;
6582 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
6583 subpst
->dependencies
[0] = pst
;
6584 subpst
->number_of_dependencies
= 1;
6586 subpst
->read_symtab
= pst
->read_symtab
;
6588 /* No private part is necessary for include psymtabs. This property
6589 can be used to differentiate between such include psymtabs and
6590 the regular ones. */
6591 subpst
->read_symtab_private
= NULL
;
6594 /* Read the Line Number Program data and extract the list of files
6595 included by the source file represented by PST. Build an include
6596 partial symtab for each of these included files. */
6599 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
6600 struct die_info
*die
,
6601 struct partial_symtab
*pst
)
6604 struct attribute
*attr
;
6606 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6608 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
6610 return; /* No linetable, so no includes. */
6612 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
6613 that we pass in the raw text_low here; that is ok because we're
6614 only decoding the line table to make include partial symtabs, and
6615 so the addresses aren't really used. */
6616 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
6617 pst
->raw_text_low (), 1);
6621 hash_signatured_type (const void *item
)
6623 const struct signatured_type
*sig_type
6624 = (const struct signatured_type
*) item
;
6626 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6627 return sig_type
->signature
;
6631 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6633 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6634 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6636 return lhs
->signature
== rhs
->signature
;
6639 /* Allocate a hash table for signatured types. */
6642 allocate_signatured_type_table (struct objfile
*objfile
)
6644 return htab_create_alloc_ex (41,
6645 hash_signatured_type
,
6648 &objfile
->objfile_obstack
,
6649 hashtab_obstack_allocate
,
6650 dummy_obstack_deallocate
);
6653 /* A helper function to add a signatured type CU to a table. */
6656 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6658 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6659 std::vector
<signatured_type
*> *all_type_units
6660 = (std::vector
<signatured_type
*> *) datum
;
6662 all_type_units
->push_back (sigt
);
6667 /* A helper for create_debug_types_hash_table. Read types from SECTION
6668 and fill them into TYPES_HTAB. It will process only type units,
6669 therefore DW_UT_type. */
6672 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6673 struct dwo_file
*dwo_file
,
6674 dwarf2_section_info
*section
, htab_t
&types_htab
,
6675 rcuh_kind section_kind
)
6677 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6678 struct dwarf2_section_info
*abbrev_section
;
6680 const gdb_byte
*info_ptr
, *end_ptr
;
6682 abbrev_section
= (dwo_file
!= NULL
6683 ? &dwo_file
->sections
.abbrev
6684 : &dwarf2_per_objfile
->abbrev
);
6686 if (dwarf_read_debug
)
6687 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6688 get_section_name (section
),
6689 get_section_file_name (abbrev_section
));
6691 dwarf2_read_section (objfile
, section
);
6692 info_ptr
= section
->buffer
;
6694 if (info_ptr
== NULL
)
6697 /* We can't set abfd until now because the section may be empty or
6698 not present, in which case the bfd is unknown. */
6699 abfd
= get_section_bfd_owner (section
);
6701 /* We don't use init_cutu_and_read_dies_simple, or some such, here
6702 because we don't need to read any dies: the signature is in the
6705 end_ptr
= info_ptr
+ section
->size
;
6706 while (info_ptr
< end_ptr
)
6708 struct signatured_type
*sig_type
;
6709 struct dwo_unit
*dwo_tu
;
6711 const gdb_byte
*ptr
= info_ptr
;
6712 struct comp_unit_head header
;
6713 unsigned int length
;
6715 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6717 /* Initialize it due to a false compiler warning. */
6718 header
.signature
= -1;
6719 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6721 /* We need to read the type's signature in order to build the hash
6722 table, but we don't need anything else just yet. */
6724 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
6725 abbrev_section
, ptr
, section_kind
);
6727 length
= get_cu_length (&header
);
6729 /* Skip dummy type units. */
6730 if (ptr
>= info_ptr
+ length
6731 || peek_abbrev_code (abfd
, ptr
) == 0
6732 || header
.unit_type
!= DW_UT_type
)
6738 if (types_htab
== NULL
)
6741 types_htab
= allocate_dwo_unit_table (objfile
);
6743 types_htab
= allocate_signatured_type_table (objfile
);
6749 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6751 dwo_tu
->dwo_file
= dwo_file
;
6752 dwo_tu
->signature
= header
.signature
;
6753 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6754 dwo_tu
->section
= section
;
6755 dwo_tu
->sect_off
= sect_off
;
6756 dwo_tu
->length
= length
;
6760 /* N.B.: type_offset is not usable if this type uses a DWO file.
6761 The real type_offset is in the DWO file. */
6763 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6764 struct signatured_type
);
6765 sig_type
->signature
= header
.signature
;
6766 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6767 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6768 sig_type
->per_cu
.is_debug_types
= 1;
6769 sig_type
->per_cu
.section
= section
;
6770 sig_type
->per_cu
.sect_off
= sect_off
;
6771 sig_type
->per_cu
.length
= length
;
6774 slot
= htab_find_slot (types_htab
,
6775 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6777 gdb_assert (slot
!= NULL
);
6780 sect_offset dup_sect_off
;
6784 const struct dwo_unit
*dup_tu
6785 = (const struct dwo_unit
*) *slot
;
6787 dup_sect_off
= dup_tu
->sect_off
;
6791 const struct signatured_type
*dup_tu
6792 = (const struct signatured_type
*) *slot
;
6794 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6797 complaint (_("debug type entry at offset %s is duplicate to"
6798 " the entry at offset %s, signature %s"),
6799 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6800 hex_string (header
.signature
));
6802 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6804 if (dwarf_read_debug
> 1)
6805 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6806 sect_offset_str (sect_off
),
6807 hex_string (header
.signature
));
6813 /* Create the hash table of all entries in the .debug_types
6814 (or .debug_types.dwo) section(s).
6815 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6816 otherwise it is NULL.
6818 The result is a pointer to the hash table or NULL if there are no types.
6820 Note: This function processes DWO files only, not DWP files. */
6823 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6824 struct dwo_file
*dwo_file
,
6825 gdb::array_view
<dwarf2_section_info
> type_sections
,
6828 for (dwarf2_section_info
§ion
: type_sections
)
6829 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, §ion
,
6830 types_htab
, rcuh_kind::TYPE
);
6833 /* Create the hash table of all entries in the .debug_types section,
6834 and initialize all_type_units.
6835 The result is zero if there is an error (e.g. missing .debug_types section),
6836 otherwise non-zero. */
6839 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6841 htab_t types_htab
= NULL
;
6843 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
6844 &dwarf2_per_objfile
->info
, types_htab
,
6845 rcuh_kind::COMPILE
);
6846 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
6847 dwarf2_per_objfile
->types
, types_htab
);
6848 if (types_htab
== NULL
)
6850 dwarf2_per_objfile
->signatured_types
= NULL
;
6854 dwarf2_per_objfile
->signatured_types
= types_htab
;
6856 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
6857 dwarf2_per_objfile
->all_type_units
.reserve (htab_elements (types_htab
));
6859 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
,
6860 &dwarf2_per_objfile
->all_type_units
);
6865 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
6866 If SLOT is non-NULL, it is the entry to use in the hash table.
6867 Otherwise we find one. */
6869 static struct signatured_type
*
6870 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
6873 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6875 if (dwarf2_per_objfile
->all_type_units
.size ()
6876 == dwarf2_per_objfile
->all_type_units
.capacity ())
6877 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
6879 signatured_type
*sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6880 struct signatured_type
);
6882 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
6883 sig_type
->signature
= sig
;
6884 sig_type
->per_cu
.is_debug_types
= 1;
6885 if (dwarf2_per_objfile
->using_index
)
6887 sig_type
->per_cu
.v
.quick
=
6888 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6889 struct dwarf2_per_cu_quick_data
);
6894 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
6897 gdb_assert (*slot
== NULL
);
6899 /* The rest of sig_type must be filled in by the caller. */
6903 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6904 Fill in SIG_ENTRY with DWO_ENTRY. */
6907 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6908 struct signatured_type
*sig_entry
,
6909 struct dwo_unit
*dwo_entry
)
6911 /* Make sure we're not clobbering something we don't expect to. */
6912 gdb_assert (! sig_entry
->per_cu
.queued
);
6913 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
6914 if (dwarf2_per_objfile
->using_index
)
6916 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6917 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
6920 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6921 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6922 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6923 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6924 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6926 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6927 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6928 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6929 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6930 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6931 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6932 sig_entry
->dwo_unit
= dwo_entry
;
6935 /* Subroutine of lookup_signatured_type.
6936 If we haven't read the TU yet, create the signatured_type data structure
6937 for a TU to be read in directly from a DWO file, bypassing the stub.
6938 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6939 using .gdb_index, then when reading a CU we want to stay in the DWO file
6940 containing that CU. Otherwise we could end up reading several other DWO
6941 files (due to comdat folding) to process the transitive closure of all the
6942 mentioned TUs, and that can be slow. The current DWO file will have every
6943 type signature that it needs.
6944 We only do this for .gdb_index because in the psymtab case we already have
6945 to read all the DWOs to build the type unit groups. */
6947 static struct signatured_type
*
6948 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6950 struct dwarf2_per_objfile
*dwarf2_per_objfile
6951 = cu
->per_cu
->dwarf2_per_objfile
;
6952 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6953 struct dwo_file
*dwo_file
;
6954 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6955 struct signatured_type find_sig_entry
, *sig_entry
;
6958 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6960 /* If TU skeletons have been removed then we may not have read in any
6962 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6964 dwarf2_per_objfile
->signatured_types
6965 = allocate_signatured_type_table (objfile
);
6968 /* We only ever need to read in one copy of a signatured type.
6969 Use the global signatured_types array to do our own comdat-folding
6970 of types. If this is the first time we're reading this TU, and
6971 the TU has an entry in .gdb_index, replace the recorded data from
6972 .gdb_index with this TU. */
6974 find_sig_entry
.signature
= sig
;
6975 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
6976 &find_sig_entry
, INSERT
);
6977 sig_entry
= (struct signatured_type
*) *slot
;
6979 /* We can get here with the TU already read, *or* in the process of being
6980 read. Don't reassign the global entry to point to this DWO if that's
6981 the case. Also note that if the TU is already being read, it may not
6982 have come from a DWO, the program may be a mix of Fission-compiled
6983 code and non-Fission-compiled code. */
6985 /* Have we already tried to read this TU?
6986 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6987 needn't exist in the global table yet). */
6988 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
6991 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6992 dwo_unit of the TU itself. */
6993 dwo_file
= cu
->dwo_unit
->dwo_file
;
6995 /* Ok, this is the first time we're reading this TU. */
6996 if (dwo_file
->tus
== NULL
)
6998 find_dwo_entry
.signature
= sig
;
6999 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_entry
);
7000 if (dwo_entry
== NULL
)
7003 /* If the global table doesn't have an entry for this TU, add one. */
7004 if (sig_entry
== NULL
)
7005 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
7007 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
7008 sig_entry
->per_cu
.tu_read
= 1;
7012 /* Subroutine of lookup_signatured_type.
7013 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
7014 then try the DWP file. If the TU stub (skeleton) has been removed then
7015 it won't be in .gdb_index. */
7017 static struct signatured_type
*
7018 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7020 struct dwarf2_per_objfile
*dwarf2_per_objfile
7021 = cu
->per_cu
->dwarf2_per_objfile
;
7022 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7023 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
7024 struct dwo_unit
*dwo_entry
;
7025 struct signatured_type find_sig_entry
, *sig_entry
;
7028 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
7029 gdb_assert (dwp_file
!= NULL
);
7031 /* If TU skeletons have been removed then we may not have read in any
7033 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7035 dwarf2_per_objfile
->signatured_types
7036 = allocate_signatured_type_table (objfile
);
7039 find_sig_entry
.signature
= sig
;
7040 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
7041 &find_sig_entry
, INSERT
);
7042 sig_entry
= (struct signatured_type
*) *slot
;
7044 /* Have we already tried to read this TU?
7045 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
7046 needn't exist in the global table yet). */
7047 if (sig_entry
!= NULL
)
7050 if (dwp_file
->tus
== NULL
)
7052 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
7053 sig
, 1 /* is_debug_types */);
7054 if (dwo_entry
== NULL
)
7057 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
7058 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
7063 /* Lookup a signature based type for DW_FORM_ref_sig8.
7064 Returns NULL if signature SIG is not present in the table.
7065 It is up to the caller to complain about this. */
7067 static struct signatured_type
*
7068 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7070 struct dwarf2_per_objfile
*dwarf2_per_objfile
7071 = cu
->per_cu
->dwarf2_per_objfile
;
7074 && dwarf2_per_objfile
->using_index
)
7076 /* We're in a DWO/DWP file, and we're using .gdb_index.
7077 These cases require special processing. */
7078 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
7079 return lookup_dwo_signatured_type (cu
, sig
);
7081 return lookup_dwp_signatured_type (cu
, sig
);
7085 struct signatured_type find_entry
, *entry
;
7087 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7089 find_entry
.signature
= sig
;
7090 entry
= ((struct signatured_type
*)
7091 htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
));
7096 /* Low level DIE reading support. */
7098 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
7101 init_cu_die_reader (struct die_reader_specs
*reader
,
7102 struct dwarf2_cu
*cu
,
7103 struct dwarf2_section_info
*section
,
7104 struct dwo_file
*dwo_file
,
7105 struct abbrev_table
*abbrev_table
)
7107 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
7108 reader
->abfd
= get_section_bfd_owner (section
);
7110 reader
->dwo_file
= dwo_file
;
7111 reader
->die_section
= section
;
7112 reader
->buffer
= section
->buffer
;
7113 reader
->buffer_end
= section
->buffer
+ section
->size
;
7114 reader
->comp_dir
= NULL
;
7115 reader
->abbrev_table
= abbrev_table
;
7118 /* Subroutine of init_cutu_and_read_dies to simplify it.
7119 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
7120 There's just a lot of work to do, and init_cutu_and_read_dies is big enough
7123 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
7124 from it to the DIE in the DWO. If NULL we are skipping the stub.
7125 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
7126 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
7127 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
7128 STUB_COMP_DIR may be non-NULL.
7129 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE,*RESULT_HAS_CHILDREN
7130 are filled in with the info of the DIE from the DWO file.
7131 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
7132 from the dwo. Since *RESULT_READER references this abbrev table, it must be
7133 kept around for at least as long as *RESULT_READER.
7135 The result is non-zero if a valid (non-dummy) DIE was found. */
7138 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
7139 struct dwo_unit
*dwo_unit
,
7140 struct die_info
*stub_comp_unit_die
,
7141 const char *stub_comp_dir
,
7142 struct die_reader_specs
*result_reader
,
7143 const gdb_byte
**result_info_ptr
,
7144 struct die_info
**result_comp_unit_die
,
7145 int *result_has_children
,
7146 abbrev_table_up
*result_dwo_abbrev_table
)
7148 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7149 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7150 struct dwarf2_cu
*cu
= this_cu
->cu
;
7152 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7153 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
7154 int i
,num_extra_attrs
;
7155 struct dwarf2_section_info
*dwo_abbrev_section
;
7156 struct attribute
*attr
;
7157 struct die_info
*comp_unit_die
;
7159 /* At most one of these may be provided. */
7160 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
7162 /* These attributes aren't processed until later:
7163 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
7164 DW_AT_comp_dir is used now, to find the DWO file, but it is also
7165 referenced later. However, these attributes are found in the stub
7166 which we won't have later. In order to not impose this complication
7167 on the rest of the code, we read them here and copy them to the
7176 if (stub_comp_unit_die
!= NULL
)
7178 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
7180 if (! this_cu
->is_debug_types
)
7181 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
7182 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
7183 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
7184 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
7185 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
7187 /* There should be a DW_AT_addr_base attribute here (if needed).
7188 We need the value before we can process DW_FORM_GNU_addr_index
7189 or DW_FORM_addrx. */
7191 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
7193 cu
->addr_base
= DW_UNSND (attr
);
7195 /* There should be a DW_AT_ranges_base attribute here (if needed).
7196 We need the value before we can process DW_AT_ranges. */
7197 cu
->ranges_base
= 0;
7198 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_ranges_base
, cu
);
7200 cu
->ranges_base
= DW_UNSND (attr
);
7202 else if (stub_comp_dir
!= NULL
)
7204 /* Reconstruct the comp_dir attribute to simplify the code below. */
7205 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
7206 comp_dir
->name
= DW_AT_comp_dir
;
7207 comp_dir
->form
= DW_FORM_string
;
7208 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
7209 DW_STRING (comp_dir
) = stub_comp_dir
;
7212 /* Set up for reading the DWO CU/TU. */
7213 cu
->dwo_unit
= dwo_unit
;
7214 dwarf2_section_info
*section
= dwo_unit
->section
;
7215 dwarf2_read_section (objfile
, section
);
7216 abfd
= get_section_bfd_owner (section
);
7217 begin_info_ptr
= info_ptr
= (section
->buffer
7218 + to_underlying (dwo_unit
->sect_off
));
7219 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
7221 if (this_cu
->is_debug_types
)
7223 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
7225 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7226 &cu
->header
, section
,
7228 info_ptr
, rcuh_kind::TYPE
);
7229 /* This is not an assert because it can be caused by bad debug info. */
7230 if (sig_type
->signature
!= cu
->header
.signature
)
7232 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
7233 " TU at offset %s [in module %s]"),
7234 hex_string (sig_type
->signature
),
7235 hex_string (cu
->header
.signature
),
7236 sect_offset_str (dwo_unit
->sect_off
),
7237 bfd_get_filename (abfd
));
7239 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7240 /* For DWOs coming from DWP files, we don't know the CU length
7241 nor the type's offset in the TU until now. */
7242 dwo_unit
->length
= get_cu_length (&cu
->header
);
7243 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
7245 /* Establish the type offset that can be used to lookup the type.
7246 For DWO files, we don't know it until now. */
7247 sig_type
->type_offset_in_section
7248 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
7252 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7253 &cu
->header
, section
,
7255 info_ptr
, rcuh_kind::COMPILE
);
7256 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7257 /* For DWOs coming from DWP files, we don't know the CU length
7259 dwo_unit
->length
= get_cu_length (&cu
->header
);
7262 *result_dwo_abbrev_table
7263 = abbrev_table_read_table (dwarf2_per_objfile
, dwo_abbrev_section
,
7264 cu
->header
.abbrev_sect_off
);
7265 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
7266 result_dwo_abbrev_table
->get ());
7268 /* Read in the die, but leave space to copy over the attributes
7269 from the stub. This has the benefit of simplifying the rest of
7270 the code - all the work to maintain the illusion of a single
7271 DW_TAG_{compile,type}_unit DIE is done here. */
7272 num_extra_attrs
= ((stmt_list
!= NULL
)
7276 + (comp_dir
!= NULL
));
7277 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
7278 result_has_children
, num_extra_attrs
);
7280 /* Copy over the attributes from the stub to the DIE we just read in. */
7281 comp_unit_die
= *result_comp_unit_die
;
7282 i
= comp_unit_die
->num_attrs
;
7283 if (stmt_list
!= NULL
)
7284 comp_unit_die
->attrs
[i
++] = *stmt_list
;
7286 comp_unit_die
->attrs
[i
++] = *low_pc
;
7287 if (high_pc
!= NULL
)
7288 comp_unit_die
->attrs
[i
++] = *high_pc
;
7290 comp_unit_die
->attrs
[i
++] = *ranges
;
7291 if (comp_dir
!= NULL
)
7292 comp_unit_die
->attrs
[i
++] = *comp_dir
;
7293 comp_unit_die
->num_attrs
+= num_extra_attrs
;
7295 if (dwarf_die_debug
)
7297 fprintf_unfiltered (gdb_stdlog
,
7298 "Read die from %s@0x%x of %s:\n",
7299 get_section_name (section
),
7300 (unsigned) (begin_info_ptr
- section
->buffer
),
7301 bfd_get_filename (abfd
));
7302 dump_die (comp_unit_die
, dwarf_die_debug
);
7305 /* Save the comp_dir attribute. If there is no DWP file then we'll read
7306 TUs by skipping the stub and going directly to the entry in the DWO file.
7307 However, skipping the stub means we won't get DW_AT_comp_dir, so we have
7308 to get it via circuitous means. Blech. */
7309 if (comp_dir
!= NULL
)
7310 result_reader
->comp_dir
= DW_STRING (comp_dir
);
7312 /* Skip dummy compilation units. */
7313 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
7314 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7317 *result_info_ptr
= info_ptr
;
7321 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
7322 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
7323 signature is part of the header. */
7324 static gdb::optional
<ULONGEST
>
7325 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
7327 if (cu
->header
.version
>= 5)
7328 return cu
->header
.signature
;
7329 struct attribute
*attr
;
7330 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
7331 if (attr
== nullptr)
7332 return gdb::optional
<ULONGEST
> ();
7333 return DW_UNSND (attr
);
7336 /* Subroutine of init_cutu_and_read_dies to simplify it.
7337 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
7338 Returns NULL if the specified DWO unit cannot be found. */
7340 static struct dwo_unit
*
7341 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
7342 struct die_info
*comp_unit_die
)
7344 struct dwarf2_cu
*cu
= this_cu
->cu
;
7345 struct dwo_unit
*dwo_unit
;
7346 const char *comp_dir
, *dwo_name
;
7348 gdb_assert (cu
!= NULL
);
7350 /* Yeah, we look dwo_name up again, but it simplifies the code. */
7351 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7352 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7354 if (this_cu
->is_debug_types
)
7356 struct signatured_type
*sig_type
;
7358 /* Since this_cu is the first member of struct signatured_type,
7359 we can go from a pointer to one to a pointer to the other. */
7360 sig_type
= (struct signatured_type
*) this_cu
;
7361 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
7365 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
7366 if (!signature
.has_value ())
7367 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
7369 dwo_name
, objfile_name (this_cu
->dwarf2_per_objfile
->objfile
));
7370 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
7377 /* Subroutine of init_cutu_and_read_dies to simplify it.
7378 See it for a description of the parameters.
7379 Read a TU directly from a DWO file, bypassing the stub. */
7382 init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
7383 int use_existing_cu
, int keep
,
7384 die_reader_func_ftype
*die_reader_func
,
7387 std::unique_ptr
<dwarf2_cu
> new_cu
;
7388 struct signatured_type
*sig_type
;
7389 struct die_reader_specs reader
;
7390 const gdb_byte
*info_ptr
;
7391 struct die_info
*comp_unit_die
;
7393 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7395 /* Verify we can do the following downcast, and that we have the
7397 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
7398 sig_type
= (struct signatured_type
*) this_cu
;
7399 gdb_assert (sig_type
->dwo_unit
!= NULL
);
7401 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7403 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
7404 /* There's no need to do the rereading_dwo_cu handling that
7405 init_cutu_and_read_dies does since we don't read the stub. */
7409 /* If !use_existing_cu, this_cu->cu must be NULL. */
7410 gdb_assert (this_cu
->cu
== NULL
);
7411 new_cu
.reset (new dwarf2_cu (this_cu
));
7414 /* A future optimization, if needed, would be to use an existing
7415 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
7416 could share abbrev tables. */
7418 /* The abbreviation table used by READER, this must live at least as long as
7420 abbrev_table_up dwo_abbrev_table
;
7422 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
7423 NULL
/* stub_comp_unit_die */,
7424 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
7426 &comp_unit_die
, &has_children
,
7427 &dwo_abbrev_table
) == 0)
7433 /* All the "real" work is done here. */
7434 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7436 /* This duplicates the code in init_cutu_and_read_dies,
7437 but the alternative is making the latter more complex.
7438 This function is only for the special case of using DWO files directly:
7439 no point in overly complicating the general case just to handle this. */
7440 if (new_cu
!= NULL
&& keep
)
7442 /* Link this CU into read_in_chain. */
7443 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
7444 dwarf2_per_objfile
->read_in_chain
= this_cu
;
7445 /* The chain owns it now. */
7450 /* Initialize a CU (or TU) and read its DIEs.
7451 If the CU defers to a DWO file, read the DWO file as well.
7453 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
7454 Otherwise the table specified in the comp unit header is read in and used.
7455 This is an optimization for when we already have the abbrev table.
7457 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
7458 Otherwise, a new CU is allocated with xmalloc.
7460 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
7461 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
7463 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
7464 linker) then DIE_READER_FUNC will not get called. */
7467 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
7468 struct abbrev_table
*abbrev_table
,
7469 int use_existing_cu
, int keep
,
7471 die_reader_func_ftype
*die_reader_func
,
7474 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7475 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7476 struct dwarf2_section_info
*section
= this_cu
->section
;
7477 bfd
*abfd
= get_section_bfd_owner (section
);
7478 struct dwarf2_cu
*cu
;
7479 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7480 struct die_reader_specs reader
;
7481 struct die_info
*comp_unit_die
;
7483 struct signatured_type
*sig_type
= NULL
;
7484 struct dwarf2_section_info
*abbrev_section
;
7485 /* Non-zero if CU currently points to a DWO file and we need to
7486 reread it. When this happens we need to reread the skeleton die
7487 before we can reread the DWO file (this only applies to CUs, not TUs). */
7488 int rereading_dwo_cu
= 0;
7490 if (dwarf_die_debug
)
7491 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7492 this_cu
->is_debug_types
? "type" : "comp",
7493 sect_offset_str (this_cu
->sect_off
));
7495 if (use_existing_cu
)
7498 /* If we're reading a TU directly from a DWO file, including a virtual DWO
7499 file (instead of going through the stub), short-circuit all of this. */
7500 if (this_cu
->reading_dwo_directly
)
7502 /* Narrow down the scope of possibilities to have to understand. */
7503 gdb_assert (this_cu
->is_debug_types
);
7504 gdb_assert (abbrev_table
== NULL
);
7505 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
, keep
,
7506 die_reader_func
, data
);
7510 /* This is cheap if the section is already read in. */
7511 dwarf2_read_section (objfile
, section
);
7513 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7515 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
7517 std::unique_ptr
<dwarf2_cu
> new_cu
;
7518 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7521 /* If this CU is from a DWO file we need to start over, we need to
7522 refetch the attributes from the skeleton CU.
7523 This could be optimized by retrieving those attributes from when we
7524 were here the first time: the previous comp_unit_die was stored in
7525 comp_unit_obstack. But there's no data yet that we need this
7527 if (cu
->dwo_unit
!= NULL
)
7528 rereading_dwo_cu
= 1;
7532 /* If !use_existing_cu, this_cu->cu must be NULL. */
7533 gdb_assert (this_cu
->cu
== NULL
);
7534 new_cu
.reset (new dwarf2_cu (this_cu
));
7538 /* Get the header. */
7539 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
7541 /* We already have the header, there's no need to read it in again. */
7542 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
7546 if (this_cu
->is_debug_types
)
7548 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7549 &cu
->header
, section
,
7550 abbrev_section
, info_ptr
,
7553 /* Since per_cu is the first member of struct signatured_type,
7554 we can go from a pointer to one to a pointer to the other. */
7555 sig_type
= (struct signatured_type
*) this_cu
;
7556 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
7557 gdb_assert (sig_type
->type_offset_in_tu
7558 == cu
->header
.type_cu_offset_in_tu
);
7559 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7561 /* LENGTH has not been set yet for type units if we're
7562 using .gdb_index. */
7563 this_cu
->length
= get_cu_length (&cu
->header
);
7565 /* Establish the type offset that can be used to lookup the type. */
7566 sig_type
->type_offset_in_section
=
7567 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
7569 this_cu
->dwarf_version
= cu
->header
.version
;
7573 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7574 &cu
->header
, section
,
7577 rcuh_kind::COMPILE
);
7579 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7580 gdb_assert (this_cu
->length
== get_cu_length (&cu
->header
));
7581 this_cu
->dwarf_version
= cu
->header
.version
;
7585 /* Skip dummy compilation units. */
7586 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7587 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7590 /* If we don't have them yet, read the abbrevs for this compilation unit.
7591 And if we need to read them now, make sure they're freed when we're
7592 done (own the table through ABBREV_TABLE_HOLDER). */
7593 abbrev_table_up abbrev_table_holder
;
7594 if (abbrev_table
!= NULL
)
7595 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
7599 = abbrev_table_read_table (dwarf2_per_objfile
, abbrev_section
,
7600 cu
->header
.abbrev_sect_off
);
7601 abbrev_table
= abbrev_table_holder
.get ();
7604 /* Read the top level CU/TU die. */
7605 init_cu_die_reader (&reader
, cu
, section
, NULL
, abbrev_table
);
7606 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
7608 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
7611 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
7612 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
7613 table from the DWO file and pass the ownership over to us. It will be
7614 referenced from READER, so we must make sure to free it after we're done
7617 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
7618 DWO CU, that this test will fail (the attribute will not be present). */
7619 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7620 abbrev_table_up dwo_abbrev_table
;
7621 if (dwo_name
!= nullptr)
7623 struct dwo_unit
*dwo_unit
;
7624 struct die_info
*dwo_comp_unit_die
;
7628 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
7629 " has children (offset %s) [in module %s]"),
7630 sect_offset_str (this_cu
->sect_off
),
7631 bfd_get_filename (abfd
));
7633 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
);
7634 if (dwo_unit
!= NULL
)
7636 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
7637 comp_unit_die
, NULL
,
7639 &dwo_comp_unit_die
, &has_children
,
7640 &dwo_abbrev_table
) == 0)
7645 comp_unit_die
= dwo_comp_unit_die
;
7649 /* Yikes, we couldn't find the rest of the DIE, we only have
7650 the stub. A complaint has already been logged. There's
7651 not much more we can do except pass on the stub DIE to
7652 die_reader_func. We don't want to throw an error on bad
7657 /* All of the above is setup for this call. Yikes. */
7658 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7660 /* Done, clean up. */
7661 if (new_cu
!= NULL
&& keep
)
7663 /* Link this CU into read_in_chain. */
7664 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
7665 dwarf2_per_objfile
->read_in_chain
= this_cu
;
7666 /* The chain owns it now. */
7671 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name if present.
7672 DWO_FILE, if non-NULL, is the DWO file to read (the caller is assumed
7673 to have already done the lookup to find the DWO file).
7675 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7676 THIS_CU->is_debug_types, but nothing else.
7678 We fill in THIS_CU->length.
7680 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
7681 linker) then DIE_READER_FUNC will not get called.
7683 THIS_CU->cu is always freed when done.
7684 This is done in order to not leave THIS_CU->cu in a state where we have
7685 to care whether it refers to the "main" CU or the DWO CU. */
7688 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
7689 struct dwo_file
*dwo_file
,
7690 die_reader_func_ftype
*die_reader_func
,
7693 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7694 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7695 struct dwarf2_section_info
*section
= this_cu
->section
;
7696 bfd
*abfd
= get_section_bfd_owner (section
);
7697 struct dwarf2_section_info
*abbrev_section
;
7698 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7699 struct die_reader_specs reader
;
7700 struct die_info
*comp_unit_die
;
7703 if (dwarf_die_debug
)
7704 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7705 this_cu
->is_debug_types
? "type" : "comp",
7706 sect_offset_str (this_cu
->sect_off
));
7708 gdb_assert (this_cu
->cu
== NULL
);
7710 abbrev_section
= (dwo_file
!= NULL
7711 ? &dwo_file
->sections
.abbrev
7712 : get_abbrev_section_for_cu (this_cu
));
7714 /* This is cheap if the section is already read in. */
7715 dwarf2_read_section (objfile
, section
);
7717 struct dwarf2_cu
cu (this_cu
);
7719 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7720 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7721 &cu
.header
, section
,
7722 abbrev_section
, info_ptr
,
7723 (this_cu
->is_debug_types
7725 : rcuh_kind::COMPILE
));
7727 this_cu
->length
= get_cu_length (&cu
.header
);
7729 /* Skip dummy compilation units. */
7730 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7731 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7734 abbrev_table_up abbrev_table
7735 = abbrev_table_read_table (dwarf2_per_objfile
, abbrev_section
,
7736 cu
.header
.abbrev_sect_off
);
7738 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
, abbrev_table
.get ());
7739 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
7741 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7744 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
7745 does not lookup the specified DWO file.
7746 This cannot be used to read DWO files.
7748 THIS_CU->cu is always freed when done.
7749 This is done in order to not leave THIS_CU->cu in a state where we have
7750 to care whether it refers to the "main" CU or the DWO CU.
7751 We can revisit this if the data shows there's a performance issue. */
7754 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
7755 die_reader_func_ftype
*die_reader_func
,
7758 init_cutu_and_read_dies_no_follow (this_cu
, NULL
, die_reader_func
, data
);
7761 /* Type Unit Groups.
7763 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7764 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7765 so that all types coming from the same compilation (.o file) are grouped
7766 together. A future step could be to put the types in the same symtab as
7767 the CU the types ultimately came from. */
7770 hash_type_unit_group (const void *item
)
7772 const struct type_unit_group
*tu_group
7773 = (const struct type_unit_group
*) item
;
7775 return hash_stmt_list_entry (&tu_group
->hash
);
7779 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7781 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7782 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7784 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7787 /* Allocate a hash table for type unit groups. */
7790 allocate_type_unit_groups_table (struct objfile
*objfile
)
7792 return htab_create_alloc_ex (3,
7793 hash_type_unit_group
,
7796 &objfile
->objfile_obstack
,
7797 hashtab_obstack_allocate
,
7798 dummy_obstack_deallocate
);
7801 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7802 partial symtabs. We combine several TUs per psymtab to not let the size
7803 of any one psymtab grow too big. */
7804 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7805 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7807 /* Helper routine for get_type_unit_group.
7808 Create the type_unit_group object used to hold one or more TUs. */
7810 static struct type_unit_group
*
7811 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7813 struct dwarf2_per_objfile
*dwarf2_per_objfile
7814 = cu
->per_cu
->dwarf2_per_objfile
;
7815 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7816 struct dwarf2_per_cu_data
*per_cu
;
7817 struct type_unit_group
*tu_group
;
7819 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7820 struct type_unit_group
);
7821 per_cu
= &tu_group
->per_cu
;
7822 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7824 if (dwarf2_per_objfile
->using_index
)
7826 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7827 struct dwarf2_per_cu_quick_data
);
7831 unsigned int line_offset
= to_underlying (line_offset_struct
);
7832 struct partial_symtab
*pst
;
7835 /* Give the symtab a useful name for debug purposes. */
7836 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7837 name
= string_printf ("<type_units_%d>",
7838 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7840 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7842 pst
= create_partial_symtab (per_cu
, name
.c_str ());
7846 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7847 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7852 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7853 STMT_LIST is a DW_AT_stmt_list attribute. */
7855 static struct type_unit_group
*
7856 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7858 struct dwarf2_per_objfile
*dwarf2_per_objfile
7859 = cu
->per_cu
->dwarf2_per_objfile
;
7860 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7861 struct type_unit_group
*tu_group
;
7863 unsigned int line_offset
;
7864 struct type_unit_group type_unit_group_for_lookup
;
7866 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
7868 dwarf2_per_objfile
->type_unit_groups
=
7869 allocate_type_unit_groups_table (dwarf2_per_objfile
->objfile
);
7872 /* Do we need to create a new group, or can we use an existing one? */
7876 line_offset
= DW_UNSND (stmt_list
);
7877 ++tu_stats
->nr_symtab_sharers
;
7881 /* Ugh, no stmt_list. Rare, but we have to handle it.
7882 We can do various things here like create one group per TU or
7883 spread them over multiple groups to split up the expansion work.
7884 To avoid worst case scenarios (too many groups or too large groups)
7885 we, umm, group them in bunches. */
7886 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7887 | (tu_stats
->nr_stmt_less_type_units
7888 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7889 ++tu_stats
->nr_stmt_less_type_units
;
7892 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7893 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7894 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
,
7895 &type_unit_group_for_lookup
, INSERT
);
7898 tu_group
= (struct type_unit_group
*) *slot
;
7899 gdb_assert (tu_group
!= NULL
);
7903 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7904 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7906 ++tu_stats
->nr_symtabs
;
7912 /* Partial symbol tables. */
7914 /* Create a psymtab named NAME and assign it to PER_CU.
7916 The caller must fill in the following details:
7917 dirname, textlow, texthigh. */
7919 static struct partial_symtab
*
7920 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
7922 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
7923 struct partial_symtab
*pst
;
7925 pst
= start_psymtab_common (objfile
, name
, 0);
7927 pst
->psymtabs_addrmap_supported
= 1;
7929 /* This is the glue that links PST into GDB's symbol API. */
7930 pst
->read_symtab_private
= per_cu
;
7931 pst
->read_symtab
= dwarf2_read_symtab
;
7932 per_cu
->v
.psymtab
= pst
;
7937 /* The DATA object passed to process_psymtab_comp_unit_reader has this
7940 struct process_psymtab_comp_unit_data
7942 /* True if we are reading a DW_TAG_partial_unit. */
7944 int want_partial_unit
;
7946 /* The "pretend" language that is used if the CU doesn't declare a
7949 enum language pretend_language
;
7952 /* die_reader_func for process_psymtab_comp_unit. */
7955 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7956 const gdb_byte
*info_ptr
,
7957 struct die_info
*comp_unit_die
,
7961 struct dwarf2_cu
*cu
= reader
->cu
;
7962 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
7963 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7964 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7966 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7967 struct partial_symtab
*pst
;
7968 enum pc_bounds_kind cu_bounds_kind
;
7969 const char *filename
;
7970 struct process_psymtab_comp_unit_data
*info
7971 = (struct process_psymtab_comp_unit_data
*) data
;
7973 if (comp_unit_die
->tag
== DW_TAG_partial_unit
&& !info
->want_partial_unit
)
7976 gdb_assert (! per_cu
->is_debug_types
);
7978 prepare_one_comp_unit (cu
, comp_unit_die
, info
->pretend_language
);
7980 /* Allocate a new partial symbol table structure. */
7981 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7982 if (filename
== NULL
)
7985 pst
= create_partial_symtab (per_cu
, filename
);
7987 /* This must be done before calling dwarf2_build_include_psymtabs. */
7988 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7990 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7992 dwarf2_find_base_address (comp_unit_die
, cu
);
7994 /* Possibly set the default values of LOWPC and HIGHPC from
7996 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7997 &best_highpc
, cu
, pst
);
7998 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
8001 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
8004 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
8006 /* Store the contiguous range if it is not empty; it can be
8007 empty for CUs with no code. */
8008 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8012 /* Check if comp unit has_children.
8013 If so, read the rest of the partial symbols from this comp unit.
8014 If not, there's no more debug_info for this comp unit. */
8017 struct partial_die_info
*first_die
;
8018 CORE_ADDR lowpc
, highpc
;
8020 lowpc
= ((CORE_ADDR
) -1);
8021 highpc
= ((CORE_ADDR
) 0);
8023 first_die
= load_partial_dies (reader
, info_ptr
, 1);
8025 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
8026 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
8028 /* If we didn't find a lowpc, set it to highpc to avoid
8029 complaints from `maint check'. */
8030 if (lowpc
== ((CORE_ADDR
) -1))
8033 /* If the compilation unit didn't have an explicit address range,
8034 then use the information extracted from its child dies. */
8035 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
8038 best_highpc
= highpc
;
8041 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
8042 best_lowpc
+ baseaddr
)
8044 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
8045 best_highpc
+ baseaddr
)
8048 end_psymtab_common (objfile
, pst
);
8050 if (!VEC_empty (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
))
8053 int len
= VEC_length (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
8054 struct dwarf2_per_cu_data
*iter
;
8056 /* Fill in 'dependencies' here; we fill in 'users' in a
8058 pst
->number_of_dependencies
= len
;
8060 = objfile
->partial_symtabs
->allocate_dependencies (len
);
8062 VEC_iterate (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
8065 pst
->dependencies
[i
] = iter
->v
.psymtab
;
8067 VEC_free (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
8070 /* Get the list of files included in the current compilation unit,
8071 and build a psymtab for each of them. */
8072 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
8074 if (dwarf_read_debug
)
8075 fprintf_unfiltered (gdb_stdlog
,
8076 "Psymtab for %s unit @%s: %s - %s"
8077 ", %d global, %d static syms\n",
8078 per_cu
->is_debug_types
? "type" : "comp",
8079 sect_offset_str (per_cu
->sect_off
),
8080 paddress (gdbarch
, pst
->text_low (objfile
)),
8081 paddress (gdbarch
, pst
->text_high (objfile
)),
8082 pst
->n_global_syms
, pst
->n_static_syms
);
8085 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8086 Process compilation unit THIS_CU for a psymtab. */
8089 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8090 int want_partial_unit
,
8091 enum language pretend_language
)
8093 /* If this compilation unit was already read in, free the
8094 cached copy in order to read it in again. This is
8095 necessary because we skipped some symbols when we first
8096 read in the compilation unit (see load_partial_dies).
8097 This problem could be avoided, but the benefit is unclear. */
8098 if (this_cu
->cu
!= NULL
)
8099 free_one_cached_comp_unit (this_cu
);
8101 if (this_cu
->is_debug_types
)
8102 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0, false,
8103 build_type_psymtabs_reader
, NULL
);
8106 process_psymtab_comp_unit_data info
;
8107 info
.want_partial_unit
= want_partial_unit
;
8108 info
.pretend_language
= pretend_language
;
8109 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0, false,
8110 process_psymtab_comp_unit_reader
, &info
);
8113 /* Age out any secondary CUs. */
8114 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
8117 /* Reader function for build_type_psymtabs. */
8120 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
8121 const gdb_byte
*info_ptr
,
8122 struct die_info
*type_unit_die
,
8126 struct dwarf2_per_objfile
*dwarf2_per_objfile
8127 = reader
->cu
->per_cu
->dwarf2_per_objfile
;
8128 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8129 struct dwarf2_cu
*cu
= reader
->cu
;
8130 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
8131 struct signatured_type
*sig_type
;
8132 struct type_unit_group
*tu_group
;
8133 struct attribute
*attr
;
8134 struct partial_die_info
*first_die
;
8135 CORE_ADDR lowpc
, highpc
;
8136 struct partial_symtab
*pst
;
8138 gdb_assert (data
== NULL
);
8139 gdb_assert (per_cu
->is_debug_types
);
8140 sig_type
= (struct signatured_type
*) per_cu
;
8145 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
8146 tu_group
= get_type_unit_group (cu
, attr
);
8148 VEC_safe_push (sig_type_ptr
, tu_group
->tus
, sig_type
);
8150 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
8151 pst
= create_partial_symtab (per_cu
, "");
8154 first_die
= load_partial_dies (reader
, info_ptr
, 1);
8156 lowpc
= (CORE_ADDR
) -1;
8157 highpc
= (CORE_ADDR
) 0;
8158 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
8160 end_psymtab_common (objfile
, pst
);
8163 /* Struct used to sort TUs by their abbreviation table offset. */
8165 struct tu_abbrev_offset
8167 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
8168 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
8171 signatured_type
*sig_type
;
8172 sect_offset abbrev_offset
;
8175 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
8178 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
8179 const struct tu_abbrev_offset
&b
)
8181 return a
.abbrev_offset
< b
.abbrev_offset
;
8184 /* Efficiently read all the type units.
8185 This does the bulk of the work for build_type_psymtabs.
8187 The efficiency is because we sort TUs by the abbrev table they use and
8188 only read each abbrev table once. In one program there are 200K TUs
8189 sharing 8K abbrev tables.
8191 The main purpose of this function is to support building the
8192 dwarf2_per_objfile->type_unit_groups table.
8193 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
8194 can collapse the search space by grouping them by stmt_list.
8195 The savings can be significant, in the same program from above the 200K TUs
8196 share 8K stmt_list tables.
8198 FUNC is expected to call get_type_unit_group, which will create the
8199 struct type_unit_group if necessary and add it to
8200 dwarf2_per_objfile->type_unit_groups. */
8203 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8205 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8206 abbrev_table_up abbrev_table
;
8207 sect_offset abbrev_offset
;
8209 /* It's up to the caller to not call us multiple times. */
8210 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
8212 if (dwarf2_per_objfile
->all_type_units
.empty ())
8215 /* TUs typically share abbrev tables, and there can be way more TUs than
8216 abbrev tables. Sort by abbrev table to reduce the number of times we
8217 read each abbrev table in.
8218 Alternatives are to punt or to maintain a cache of abbrev tables.
8219 This is simpler and efficient enough for now.
8221 Later we group TUs by their DW_AT_stmt_list value (as this defines the
8222 symtab to use). Typically TUs with the same abbrev offset have the same
8223 stmt_list value too so in practice this should work well.
8225 The basic algorithm here is:
8227 sort TUs by abbrev table
8228 for each TU with same abbrev table:
8229 read abbrev table if first user
8230 read TU top level DIE
8231 [IWBN if DWO skeletons had DW_AT_stmt_list]
8234 if (dwarf_read_debug
)
8235 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
8237 /* Sort in a separate table to maintain the order of all_type_units
8238 for .gdb_index: TU indices directly index all_type_units. */
8239 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
8240 sorted_by_abbrev
.reserve (dwarf2_per_objfile
->all_type_units
.size ());
8242 for (signatured_type
*sig_type
: dwarf2_per_objfile
->all_type_units
)
8243 sorted_by_abbrev
.emplace_back
8244 (sig_type
, read_abbrev_offset (dwarf2_per_objfile
,
8245 sig_type
->per_cu
.section
,
8246 sig_type
->per_cu
.sect_off
));
8248 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
8249 sort_tu_by_abbrev_offset
);
8251 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
8253 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
8255 /* Switch to the next abbrev table if necessary. */
8256 if (abbrev_table
== NULL
8257 || tu
.abbrev_offset
!= abbrev_offset
)
8259 abbrev_offset
= tu
.abbrev_offset
;
8261 abbrev_table_read_table (dwarf2_per_objfile
,
8262 &dwarf2_per_objfile
->abbrev
,
8264 ++tu_stats
->nr_uniq_abbrev_tables
;
8267 init_cutu_and_read_dies (&tu
.sig_type
->per_cu
, abbrev_table
.get (),
8268 0, 0, false, build_type_psymtabs_reader
, NULL
);
8272 /* Print collected type unit statistics. */
8275 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8277 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8279 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
8280 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
8281 dwarf2_per_objfile
->all_type_units
.size ());
8282 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
8283 tu_stats
->nr_uniq_abbrev_tables
);
8284 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
8285 tu_stats
->nr_symtabs
);
8286 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
8287 tu_stats
->nr_symtab_sharers
);
8288 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
8289 tu_stats
->nr_stmt_less_type_units
);
8290 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
8291 tu_stats
->nr_all_type_units_reallocs
);
8294 /* Traversal function for build_type_psymtabs. */
8297 build_type_psymtab_dependencies (void **slot
, void *info
)
8299 struct dwarf2_per_objfile
*dwarf2_per_objfile
8300 = (struct dwarf2_per_objfile
*) info
;
8301 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8302 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
8303 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
8304 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8305 int len
= VEC_length (sig_type_ptr
, tu_group
->tus
);
8306 struct signatured_type
*iter
;
8309 gdb_assert (len
> 0);
8310 gdb_assert (IS_TYPE_UNIT_GROUP (per_cu
));
8312 pst
->number_of_dependencies
= len
;
8313 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
8315 VEC_iterate (sig_type_ptr
, tu_group
->tus
, i
, iter
);
8318 gdb_assert (iter
->per_cu
.is_debug_types
);
8319 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
8320 iter
->type_unit_group
= tu_group
;
8323 VEC_free (sig_type_ptr
, tu_group
->tus
);
8328 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8329 Build partial symbol tables for the .debug_types comp-units. */
8332 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8334 if (! create_all_type_units (dwarf2_per_objfile
))
8337 build_type_psymtabs_1 (dwarf2_per_objfile
);
8340 /* Traversal function for process_skeletonless_type_unit.
8341 Read a TU in a DWO file and build partial symbols for it. */
8344 process_skeletonless_type_unit (void **slot
, void *info
)
8346 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
8347 struct dwarf2_per_objfile
*dwarf2_per_objfile
8348 = (struct dwarf2_per_objfile
*) info
;
8349 struct signatured_type find_entry
, *entry
;
8351 /* If this TU doesn't exist in the global table, add it and read it in. */
8353 if (dwarf2_per_objfile
->signatured_types
== NULL
)
8355 dwarf2_per_objfile
->signatured_types
8356 = allocate_signatured_type_table (dwarf2_per_objfile
->objfile
);
8359 find_entry
.signature
= dwo_unit
->signature
;
8360 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
, &find_entry
,
8362 /* If we've already seen this type there's nothing to do. What's happening
8363 is we're doing our own version of comdat-folding here. */
8367 /* This does the job that create_all_type_units would have done for
8369 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
8370 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
8373 /* This does the job that build_type_psymtabs_1 would have done. */
8374 init_cutu_and_read_dies (&entry
->per_cu
, NULL
, 0, 0, false,
8375 build_type_psymtabs_reader
, NULL
);
8380 /* Traversal function for process_skeletonless_type_units. */
8383 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
8385 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
8387 if (dwo_file
->tus
!= NULL
)
8389 htab_traverse_noresize (dwo_file
->tus
,
8390 process_skeletonless_type_unit
, info
);
8396 /* Scan all TUs of DWO files, verifying we've processed them.
8397 This is needed in case a TU was emitted without its skeleton.
8398 Note: This can't be done until we know what all the DWO files are. */
8401 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8403 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
8404 if (get_dwp_file (dwarf2_per_objfile
) == NULL
8405 && dwarf2_per_objfile
->dwo_files
!= NULL
)
8407 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
.get (),
8408 process_dwo_file_for_skeletonless_type_units
,
8409 dwarf2_per_objfile
);
8413 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
8416 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8418 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
8420 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8425 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
8427 /* Set the 'user' field only if it is not already set. */
8428 if (pst
->dependencies
[j
]->user
== NULL
)
8429 pst
->dependencies
[j
]->user
= pst
;
8434 /* Build the partial symbol table by doing a quick pass through the
8435 .debug_info and .debug_abbrev sections. */
8438 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8440 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8442 if (dwarf_read_debug
)
8444 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
8445 objfile_name (objfile
));
8448 dwarf2_per_objfile
->reading_partial_symbols
= 1;
8450 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
8452 /* Any cached compilation units will be linked by the per-objfile
8453 read_in_chain. Make sure to free them when we're done. */
8454 free_cached_comp_units
freer (dwarf2_per_objfile
);
8456 build_type_psymtabs (dwarf2_per_objfile
);
8458 create_all_comp_units (dwarf2_per_objfile
);
8460 /* Create a temporary address map on a temporary obstack. We later
8461 copy this to the final obstack. */
8462 auto_obstack temp_obstack
;
8464 scoped_restore save_psymtabs_addrmap
8465 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
8466 addrmap_create_mutable (&temp_obstack
));
8468 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
8469 process_psymtab_comp_unit (per_cu
, 0, language_minimal
);
8471 /* This has to wait until we read the CUs, we need the list of DWOs. */
8472 process_skeletonless_type_units (dwarf2_per_objfile
);
8474 /* Now that all TUs have been processed we can fill in the dependencies. */
8475 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
8477 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
8478 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
8481 if (dwarf_read_debug
)
8482 print_tu_stats (dwarf2_per_objfile
);
8484 set_partial_user (dwarf2_per_objfile
);
8486 objfile
->partial_symtabs
->psymtabs_addrmap
8487 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
8488 objfile
->partial_symtabs
->obstack ());
8489 /* At this point we want to keep the address map. */
8490 save_psymtabs_addrmap
.release ();
8492 if (dwarf_read_debug
)
8493 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
8494 objfile_name (objfile
));
8497 /* die_reader_func for load_partial_comp_unit. */
8500 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
8501 const gdb_byte
*info_ptr
,
8502 struct die_info
*comp_unit_die
,
8506 struct dwarf2_cu
*cu
= reader
->cu
;
8508 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
8510 /* Check if comp unit has_children.
8511 If so, read the rest of the partial symbols from this comp unit.
8512 If not, there's no more debug_info for this comp unit. */
8514 load_partial_dies (reader
, info_ptr
, 0);
8517 /* Load the partial DIEs for a secondary CU into memory.
8518 This is also used when rereading a primary CU with load_all_dies. */
8521 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
8523 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1, false,
8524 load_partial_comp_unit_reader
, NULL
);
8528 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
8529 struct dwarf2_section_info
*section
,
8530 struct dwarf2_section_info
*abbrev_section
,
8531 unsigned int is_dwz
)
8533 const gdb_byte
*info_ptr
;
8534 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8536 if (dwarf_read_debug
)
8537 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
8538 get_section_name (section
),
8539 get_section_file_name (section
));
8541 dwarf2_read_section (objfile
, section
);
8543 info_ptr
= section
->buffer
;
8545 while (info_ptr
< section
->buffer
+ section
->size
)
8547 struct dwarf2_per_cu_data
*this_cu
;
8549 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
8551 comp_unit_head cu_header
;
8552 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
8553 abbrev_section
, info_ptr
,
8554 rcuh_kind::COMPILE
);
8556 /* Save the compilation unit for later lookup. */
8557 if (cu_header
.unit_type
!= DW_UT_type
)
8559 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
8560 struct dwarf2_per_cu_data
);
8561 memset (this_cu
, 0, sizeof (*this_cu
));
8565 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
8566 struct signatured_type
);
8567 memset (sig_type
, 0, sizeof (*sig_type
));
8568 sig_type
->signature
= cu_header
.signature
;
8569 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
8570 this_cu
= &sig_type
->per_cu
;
8572 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
8573 this_cu
->sect_off
= sect_off
;
8574 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
8575 this_cu
->is_dwz
= is_dwz
;
8576 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
8577 this_cu
->section
= section
;
8579 dwarf2_per_objfile
->all_comp_units
.push_back (this_cu
);
8581 info_ptr
= info_ptr
+ this_cu
->length
;
8585 /* Create a list of all compilation units in OBJFILE.
8586 This is only done for -readnow and building partial symtabs. */
8589 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8591 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
8592 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->info
,
8593 &dwarf2_per_objfile
->abbrev
, 0);
8595 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
8597 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
8601 /* Process all loaded DIEs for compilation unit CU, starting at
8602 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
8603 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
8604 DW_AT_ranges). See the comments of add_partial_subprogram on how
8605 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
8608 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
8609 CORE_ADDR
*highpc
, int set_addrmap
,
8610 struct dwarf2_cu
*cu
)
8612 struct partial_die_info
*pdi
;
8614 /* Now, march along the PDI's, descending into ones which have
8615 interesting children but skipping the children of the other ones,
8616 until we reach the end of the compilation unit. */
8624 /* Anonymous namespaces or modules have no name but have interesting
8625 children, so we need to look at them. Ditto for anonymous
8628 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
8629 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
8630 || pdi
->tag
== DW_TAG_imported_unit
8631 || pdi
->tag
== DW_TAG_inlined_subroutine
)
8635 case DW_TAG_subprogram
:
8636 case DW_TAG_inlined_subroutine
:
8637 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8639 case DW_TAG_constant
:
8640 case DW_TAG_variable
:
8641 case DW_TAG_typedef
:
8642 case DW_TAG_union_type
:
8643 if (!pdi
->is_declaration
)
8645 add_partial_symbol (pdi
, cu
);
8648 case DW_TAG_class_type
:
8649 case DW_TAG_interface_type
:
8650 case DW_TAG_structure_type
:
8651 if (!pdi
->is_declaration
)
8653 add_partial_symbol (pdi
, cu
);
8655 if ((cu
->language
== language_rust
8656 || cu
->language
== language_cplus
) && pdi
->has_children
)
8657 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8660 case DW_TAG_enumeration_type
:
8661 if (!pdi
->is_declaration
)
8662 add_partial_enumeration (pdi
, cu
);
8664 case DW_TAG_base_type
:
8665 case DW_TAG_subrange_type
:
8666 /* File scope base type definitions are added to the partial
8668 add_partial_symbol (pdi
, cu
);
8670 case DW_TAG_namespace
:
8671 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8674 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8676 case DW_TAG_imported_unit
:
8678 struct dwarf2_per_cu_data
*per_cu
;
8680 /* For now we don't handle imported units in type units. */
8681 if (cu
->per_cu
->is_debug_types
)
8683 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8684 " supported in type units [in module %s]"),
8685 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
8688 per_cu
= dwarf2_find_containing_comp_unit
8689 (pdi
->d
.sect_off
, pdi
->is_dwz
,
8690 cu
->per_cu
->dwarf2_per_objfile
);
8692 /* Go read the partial unit, if needed. */
8693 if (per_cu
->v
.psymtab
== NULL
)
8694 process_psymtab_comp_unit (per_cu
, 1, cu
->language
);
8696 VEC_safe_push (dwarf2_per_cu_ptr
,
8697 cu
->per_cu
->imported_symtabs
, per_cu
);
8700 case DW_TAG_imported_declaration
:
8701 add_partial_symbol (pdi
, cu
);
8708 /* If the die has a sibling, skip to the sibling. */
8710 pdi
= pdi
->die_sibling
;
8714 /* Functions used to compute the fully scoped name of a partial DIE.
8716 Normally, this is simple. For C++, the parent DIE's fully scoped
8717 name is concatenated with "::" and the partial DIE's name.
8718 Enumerators are an exception; they use the scope of their parent
8719 enumeration type, i.e. the name of the enumeration type is not
8720 prepended to the enumerator.
8722 There are two complexities. One is DW_AT_specification; in this
8723 case "parent" means the parent of the target of the specification,
8724 instead of the direct parent of the DIE. The other is compilers
8725 which do not emit DW_TAG_namespace; in this case we try to guess
8726 the fully qualified name of structure types from their members'
8727 linkage names. This must be done using the DIE's children rather
8728 than the children of any DW_AT_specification target. We only need
8729 to do this for structures at the top level, i.e. if the target of
8730 any DW_AT_specification (if any; otherwise the DIE itself) does not
8733 /* Compute the scope prefix associated with PDI's parent, in
8734 compilation unit CU. The result will be allocated on CU's
8735 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8736 field. NULL is returned if no prefix is necessary. */
8738 partial_die_parent_scope (struct partial_die_info
*pdi
,
8739 struct dwarf2_cu
*cu
)
8741 const char *grandparent_scope
;
8742 struct partial_die_info
*parent
, *real_pdi
;
8744 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8745 then this means the parent of the specification DIE. */
8748 while (real_pdi
->has_specification
)
8750 auto res
= find_partial_die (real_pdi
->spec_offset
,
8751 real_pdi
->spec_is_dwz
, cu
);
8756 parent
= real_pdi
->die_parent
;
8760 if (parent
->scope_set
)
8761 return parent
->scope
;
8765 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8767 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8768 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8769 Work around this problem here. */
8770 if (cu
->language
== language_cplus
8771 && parent
->tag
== DW_TAG_namespace
8772 && strcmp (parent
->name
, "::") == 0
8773 && grandparent_scope
== NULL
)
8775 parent
->scope
= NULL
;
8776 parent
->scope_set
= 1;
8780 if (pdi
->tag
== DW_TAG_enumerator
)
8781 /* Enumerators should not get the name of the enumeration as a prefix. */
8782 parent
->scope
= grandparent_scope
;
8783 else if (parent
->tag
== DW_TAG_namespace
8784 || parent
->tag
== DW_TAG_module
8785 || parent
->tag
== DW_TAG_structure_type
8786 || parent
->tag
== DW_TAG_class_type
8787 || parent
->tag
== DW_TAG_interface_type
8788 || parent
->tag
== DW_TAG_union_type
8789 || parent
->tag
== DW_TAG_enumeration_type
)
8791 if (grandparent_scope
== NULL
)
8792 parent
->scope
= parent
->name
;
8794 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8796 parent
->name
, 0, cu
);
8800 /* FIXME drow/2004-04-01: What should we be doing with
8801 function-local names? For partial symbols, we should probably be
8803 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8804 dwarf_tag_name (parent
->tag
),
8805 sect_offset_str (pdi
->sect_off
));
8806 parent
->scope
= grandparent_scope
;
8809 parent
->scope_set
= 1;
8810 return parent
->scope
;
8813 /* Return the fully scoped name associated with PDI, from compilation unit
8814 CU. The result will be allocated with malloc. */
8817 partial_die_full_name (struct partial_die_info
*pdi
,
8818 struct dwarf2_cu
*cu
)
8820 const char *parent_scope
;
8822 /* If this is a template instantiation, we can not work out the
8823 template arguments from partial DIEs. So, unfortunately, we have
8824 to go through the full DIEs. At least any work we do building
8825 types here will be reused if full symbols are loaded later. */
8826 if (pdi
->has_template_arguments
)
8830 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
8832 struct die_info
*die
;
8833 struct attribute attr
;
8834 struct dwarf2_cu
*ref_cu
= cu
;
8836 /* DW_FORM_ref_addr is using section offset. */
8837 attr
.name
= (enum dwarf_attribute
) 0;
8838 attr
.form
= DW_FORM_ref_addr
;
8839 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8840 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8842 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8846 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8847 if (parent_scope
== NULL
)
8850 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
8854 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8856 struct dwarf2_per_objfile
*dwarf2_per_objfile
8857 = cu
->per_cu
->dwarf2_per_objfile
;
8858 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8859 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8861 const char *actual_name
= NULL
;
8863 char *built_actual_name
;
8865 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8867 built_actual_name
= partial_die_full_name (pdi
, cu
);
8868 if (built_actual_name
!= NULL
)
8869 actual_name
= built_actual_name
;
8871 if (actual_name
== NULL
)
8872 actual_name
= pdi
->name
;
8876 case DW_TAG_inlined_subroutine
:
8877 case DW_TAG_subprogram
:
8878 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8880 if (pdi
->is_external
|| cu
->language
== language_ada
)
8882 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
8883 of the global scope. But in Ada, we want to be able to access
8884 nested procedures globally. So all Ada subprograms are stored
8885 in the global scope. */
8886 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8887 built_actual_name
!= NULL
,
8888 VAR_DOMAIN
, LOC_BLOCK
,
8889 SECT_OFF_TEXT (objfile
),
8890 psymbol_placement::GLOBAL
,
8892 cu
->language
, objfile
);
8896 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8897 built_actual_name
!= NULL
,
8898 VAR_DOMAIN
, LOC_BLOCK
,
8899 SECT_OFF_TEXT (objfile
),
8900 psymbol_placement::STATIC
,
8901 addr
, cu
->language
, objfile
);
8904 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8905 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8907 case DW_TAG_constant
:
8908 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8909 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
8910 -1, (pdi
->is_external
8911 ? psymbol_placement::GLOBAL
8912 : psymbol_placement::STATIC
),
8913 0, cu
->language
, objfile
);
8915 case DW_TAG_variable
:
8917 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8921 && !dwarf2_per_objfile
->has_section_at_zero
)
8923 /* A global or static variable may also have been stripped
8924 out by the linker if unused, in which case its address
8925 will be nullified; do not add such variables into partial
8926 symbol table then. */
8928 else if (pdi
->is_external
)
8931 Don't enter into the minimal symbol tables as there is
8932 a minimal symbol table entry from the ELF symbols already.
8933 Enter into partial symbol table if it has a location
8934 descriptor or a type.
8935 If the location descriptor is missing, new_symbol will create
8936 a LOC_UNRESOLVED symbol, the address of the variable will then
8937 be determined from the minimal symbol table whenever the variable
8939 The address for the partial symbol table entry is not
8940 used by GDB, but it comes in handy for debugging partial symbol
8943 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8944 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8945 built_actual_name
!= NULL
,
8946 VAR_DOMAIN
, LOC_STATIC
,
8947 SECT_OFF_TEXT (objfile
),
8948 psymbol_placement::GLOBAL
,
8949 addr
, cu
->language
, objfile
);
8953 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8955 /* Static Variable. Skip symbols whose value we cannot know (those
8956 without location descriptors or constant values). */
8957 if (!has_loc
&& !pdi
->has_const_value
)
8959 xfree (built_actual_name
);
8963 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8964 built_actual_name
!= NULL
,
8965 VAR_DOMAIN
, LOC_STATIC
,
8966 SECT_OFF_TEXT (objfile
),
8967 psymbol_placement::STATIC
,
8969 cu
->language
, objfile
);
8972 case DW_TAG_typedef
:
8973 case DW_TAG_base_type
:
8974 case DW_TAG_subrange_type
:
8975 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8976 built_actual_name
!= NULL
,
8977 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
8978 psymbol_placement::STATIC
,
8979 0, cu
->language
, objfile
);
8981 case DW_TAG_imported_declaration
:
8982 case DW_TAG_namespace
:
8983 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8984 built_actual_name
!= NULL
,
8985 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
8986 psymbol_placement::GLOBAL
,
8987 0, cu
->language
, objfile
);
8990 /* With Fortran 77 there might be a "BLOCK DATA" module
8991 available without any name. If so, we skip the module as it
8992 doesn't bring any value. */
8993 if (actual_name
!= nullptr)
8994 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8995 built_actual_name
!= NULL
,
8996 MODULE_DOMAIN
, LOC_TYPEDEF
, -1,
8997 psymbol_placement::GLOBAL
,
8998 0, cu
->language
, objfile
);
9000 case DW_TAG_class_type
:
9001 case DW_TAG_interface_type
:
9002 case DW_TAG_structure_type
:
9003 case DW_TAG_union_type
:
9004 case DW_TAG_enumeration_type
:
9005 /* Skip external references. The DWARF standard says in the section
9006 about "Structure, Union, and Class Type Entries": "An incomplete
9007 structure, union or class type is represented by a structure,
9008 union or class entry that does not have a byte size attribute
9009 and that has a DW_AT_declaration attribute." */
9010 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
9012 xfree (built_actual_name
);
9016 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
9017 static vs. global. */
9018 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9019 built_actual_name
!= NULL
,
9020 STRUCT_DOMAIN
, LOC_TYPEDEF
, -1,
9021 cu
->language
== language_cplus
9022 ? psymbol_placement::GLOBAL
9023 : psymbol_placement::STATIC
,
9024 0, cu
->language
, objfile
);
9027 case DW_TAG_enumerator
:
9028 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9029 built_actual_name
!= NULL
,
9030 VAR_DOMAIN
, LOC_CONST
, -1,
9031 cu
->language
== language_cplus
9032 ? psymbol_placement::GLOBAL
9033 : psymbol_placement::STATIC
,
9034 0, cu
->language
, objfile
);
9040 xfree (built_actual_name
);
9043 /* Read a partial die corresponding to a namespace; also, add a symbol
9044 corresponding to that namespace to the symbol table. NAMESPACE is
9045 the name of the enclosing namespace. */
9048 add_partial_namespace (struct partial_die_info
*pdi
,
9049 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9050 int set_addrmap
, struct dwarf2_cu
*cu
)
9052 /* Add a symbol for the namespace. */
9054 add_partial_symbol (pdi
, cu
);
9056 /* Now scan partial symbols in that namespace. */
9058 if (pdi
->has_children
)
9059 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
9062 /* Read a partial die corresponding to a Fortran module. */
9065 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
9066 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
9068 /* Add a symbol for the namespace. */
9070 add_partial_symbol (pdi
, cu
);
9072 /* Now scan partial symbols in that module. */
9074 if (pdi
->has_children
)
9075 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
9078 /* Read a partial die corresponding to a subprogram or an inlined
9079 subprogram and create a partial symbol for that subprogram.
9080 When the CU language allows it, this routine also defines a partial
9081 symbol for each nested subprogram that this subprogram contains.
9082 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
9083 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
9085 PDI may also be a lexical block, in which case we simply search
9086 recursively for subprograms defined inside that lexical block.
9087 Again, this is only performed when the CU language allows this
9088 type of definitions. */
9091 add_partial_subprogram (struct partial_die_info
*pdi
,
9092 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9093 int set_addrmap
, struct dwarf2_cu
*cu
)
9095 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
9097 if (pdi
->has_pc_info
)
9099 if (pdi
->lowpc
< *lowpc
)
9100 *lowpc
= pdi
->lowpc
;
9101 if (pdi
->highpc
> *highpc
)
9102 *highpc
= pdi
->highpc
;
9105 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9106 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9108 CORE_ADDR this_highpc
;
9109 CORE_ADDR this_lowpc
;
9111 baseaddr
= ANOFFSET (objfile
->section_offsets
,
9112 SECT_OFF_TEXT (objfile
));
9114 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
9115 pdi
->lowpc
+ baseaddr
)
9118 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
9119 pdi
->highpc
+ baseaddr
)
9121 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
9122 this_lowpc
, this_highpc
- 1,
9123 cu
->per_cu
->v
.psymtab
);
9127 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
9129 if (!pdi
->is_declaration
)
9130 /* Ignore subprogram DIEs that do not have a name, they are
9131 illegal. Do not emit a complaint at this point, we will
9132 do so when we convert this psymtab into a symtab. */
9134 add_partial_symbol (pdi
, cu
);
9138 if (! pdi
->has_children
)
9141 if (cu
->language
== language_ada
)
9143 pdi
= pdi
->die_child
;
9147 if (pdi
->tag
== DW_TAG_subprogram
9148 || pdi
->tag
== DW_TAG_inlined_subroutine
9149 || pdi
->tag
== DW_TAG_lexical_block
)
9150 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
9151 pdi
= pdi
->die_sibling
;
9156 /* Read a partial die corresponding to an enumeration type. */
9159 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
9160 struct dwarf2_cu
*cu
)
9162 struct partial_die_info
*pdi
;
9164 if (enum_pdi
->name
!= NULL
)
9165 add_partial_symbol (enum_pdi
, cu
);
9167 pdi
= enum_pdi
->die_child
;
9170 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
9171 complaint (_("malformed enumerator DIE ignored"));
9173 add_partial_symbol (pdi
, cu
);
9174 pdi
= pdi
->die_sibling
;
9178 /* Return the initial uleb128 in the die at INFO_PTR. */
9181 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
9183 unsigned int bytes_read
;
9185 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9188 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
9189 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
9191 Return the corresponding abbrev, or NULL if the number is zero (indicating
9192 an empty DIE). In either case *BYTES_READ will be set to the length of
9193 the initial number. */
9195 static struct abbrev_info
*
9196 peek_die_abbrev (const die_reader_specs
&reader
,
9197 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
9199 dwarf2_cu
*cu
= reader
.cu
;
9200 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
9201 unsigned int abbrev_number
9202 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
9204 if (abbrev_number
== 0)
9207 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
9210 error (_("Dwarf Error: Could not find abbrev number %d in %s"
9211 " at offset %s [in module %s]"),
9212 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
9213 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
9219 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9220 Returns a pointer to the end of a series of DIEs, terminated by an empty
9221 DIE. Any children of the skipped DIEs will also be skipped. */
9223 static const gdb_byte
*
9224 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
9228 unsigned int bytes_read
;
9229 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
9232 return info_ptr
+ bytes_read
;
9234 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
9238 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9239 INFO_PTR should point just after the initial uleb128 of a DIE, and the
9240 abbrev corresponding to that skipped uleb128 should be passed in
9241 ABBREV. Returns a pointer to this DIE's sibling, skipping any
9244 static const gdb_byte
*
9245 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
9246 struct abbrev_info
*abbrev
)
9248 unsigned int bytes_read
;
9249 struct attribute attr
;
9250 bfd
*abfd
= reader
->abfd
;
9251 struct dwarf2_cu
*cu
= reader
->cu
;
9252 const gdb_byte
*buffer
= reader
->buffer
;
9253 const gdb_byte
*buffer_end
= reader
->buffer_end
;
9254 unsigned int form
, i
;
9256 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
9258 /* The only abbrev we care about is DW_AT_sibling. */
9259 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
9261 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
9262 if (attr
.form
== DW_FORM_ref_addr
)
9263 complaint (_("ignoring absolute DW_AT_sibling"));
9266 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
9267 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
9269 if (sibling_ptr
< info_ptr
)
9270 complaint (_("DW_AT_sibling points backwards"));
9271 else if (sibling_ptr
> reader
->buffer_end
)
9272 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
9278 /* If it isn't DW_AT_sibling, skip this attribute. */
9279 form
= abbrev
->attrs
[i
].form
;
9283 case DW_FORM_ref_addr
:
9284 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
9285 and later it is offset sized. */
9286 if (cu
->header
.version
== 2)
9287 info_ptr
+= cu
->header
.addr_size
;
9289 info_ptr
+= cu
->header
.offset_size
;
9291 case DW_FORM_GNU_ref_alt
:
9292 info_ptr
+= cu
->header
.offset_size
;
9295 info_ptr
+= cu
->header
.addr_size
;
9302 case DW_FORM_flag_present
:
9303 case DW_FORM_implicit_const
:
9315 case DW_FORM_ref_sig8
:
9318 case DW_FORM_data16
:
9321 case DW_FORM_string
:
9322 read_direct_string (abfd
, info_ptr
, &bytes_read
);
9323 info_ptr
+= bytes_read
;
9325 case DW_FORM_sec_offset
:
9327 case DW_FORM_GNU_strp_alt
:
9328 info_ptr
+= cu
->header
.offset_size
;
9330 case DW_FORM_exprloc
:
9332 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9333 info_ptr
+= bytes_read
;
9335 case DW_FORM_block1
:
9336 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
9338 case DW_FORM_block2
:
9339 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
9341 case DW_FORM_block4
:
9342 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
9348 case DW_FORM_ref_udata
:
9349 case DW_FORM_GNU_addr_index
:
9350 case DW_FORM_GNU_str_index
:
9351 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
9353 case DW_FORM_indirect
:
9354 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9355 info_ptr
+= bytes_read
;
9356 /* We need to continue parsing from here, so just go back to
9358 goto skip_attribute
;
9361 error (_("Dwarf Error: Cannot handle %s "
9362 "in DWARF reader [in module %s]"),
9363 dwarf_form_name (form
),
9364 bfd_get_filename (abfd
));
9368 if (abbrev
->has_children
)
9369 return skip_children (reader
, info_ptr
);
9374 /* Locate ORIG_PDI's sibling.
9375 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
9377 static const gdb_byte
*
9378 locate_pdi_sibling (const struct die_reader_specs
*reader
,
9379 struct partial_die_info
*orig_pdi
,
9380 const gdb_byte
*info_ptr
)
9382 /* Do we know the sibling already? */
9384 if (orig_pdi
->sibling
)
9385 return orig_pdi
->sibling
;
9387 /* Are there any children to deal with? */
9389 if (!orig_pdi
->has_children
)
9392 /* Skip the children the long way. */
9394 return skip_children (reader
, info_ptr
);
9397 /* Expand this partial symbol table into a full symbol table. SELF is
9401 dwarf2_read_symtab (struct partial_symtab
*self
,
9402 struct objfile
*objfile
)
9404 struct dwarf2_per_objfile
*dwarf2_per_objfile
9405 = get_dwarf2_per_objfile (objfile
);
9409 warning (_("bug: psymtab for %s is already read in."),
9416 printf_filtered (_("Reading in symbols for %s..."),
9418 gdb_flush (gdb_stdout
);
9421 /* If this psymtab is constructed from a debug-only objfile, the
9422 has_section_at_zero flag will not necessarily be correct. We
9423 can get the correct value for this flag by looking at the data
9424 associated with the (presumably stripped) associated objfile. */
9425 if (objfile
->separate_debug_objfile_backlink
)
9427 struct dwarf2_per_objfile
*dpo_backlink
9428 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
9430 dwarf2_per_objfile
->has_section_at_zero
9431 = dpo_backlink
->has_section_at_zero
;
9434 dwarf2_per_objfile
->reading_partial_symbols
= 0;
9436 psymtab_to_symtab_1 (self
);
9438 /* Finish up the debug error message. */
9440 printf_filtered (_("done.\n"));
9443 process_cu_includes (dwarf2_per_objfile
);
9446 /* Reading in full CUs. */
9448 /* Add PER_CU to the queue. */
9451 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9452 enum language pretend_language
)
9454 struct dwarf2_queue_item
*item
;
9457 item
= XNEW (struct dwarf2_queue_item
);
9458 item
->per_cu
= per_cu
;
9459 item
->pretend_language
= pretend_language
;
9462 if (dwarf2_queue
== NULL
)
9463 dwarf2_queue
= item
;
9465 dwarf2_queue_tail
->next
= item
;
9467 dwarf2_queue_tail
= item
;
9470 /* If PER_CU is not yet queued, add it to the queue.
9471 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
9473 The result is non-zero if PER_CU was queued, otherwise the result is zero
9474 meaning either PER_CU is already queued or it is already loaded.
9476 N.B. There is an invariant here that if a CU is queued then it is loaded.
9477 The caller is required to load PER_CU if we return non-zero. */
9480 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
9481 struct dwarf2_per_cu_data
*per_cu
,
9482 enum language pretend_language
)
9484 /* We may arrive here during partial symbol reading, if we need full
9485 DIEs to process an unusual case (e.g. template arguments). Do
9486 not queue PER_CU, just tell our caller to load its DIEs. */
9487 if (per_cu
->dwarf2_per_objfile
->reading_partial_symbols
)
9489 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
9494 /* Mark the dependence relation so that we don't flush PER_CU
9496 if (dependent_cu
!= NULL
)
9497 dwarf2_add_dependence (dependent_cu
, per_cu
);
9499 /* If it's already on the queue, we have nothing to do. */
9503 /* If the compilation unit is already loaded, just mark it as
9505 if (per_cu
->cu
!= NULL
)
9507 per_cu
->cu
->last_used
= 0;
9511 /* Add it to the queue. */
9512 queue_comp_unit (per_cu
, pretend_language
);
9517 /* Process the queue. */
9520 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9522 struct dwarf2_queue_item
*item
, *next_item
;
9524 if (dwarf_read_debug
)
9526 fprintf_unfiltered (gdb_stdlog
,
9527 "Expanding one or more symtabs of objfile %s ...\n",
9528 objfile_name (dwarf2_per_objfile
->objfile
));
9531 /* The queue starts out with one item, but following a DIE reference
9532 may load a new CU, adding it to the end of the queue. */
9533 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
9535 if ((dwarf2_per_objfile
->using_index
9536 ? !item
->per_cu
->v
.quick
->compunit_symtab
9537 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
9538 /* Skip dummy CUs. */
9539 && item
->per_cu
->cu
!= NULL
)
9541 struct dwarf2_per_cu_data
*per_cu
= item
->per_cu
;
9542 unsigned int debug_print_threshold
;
9545 if (per_cu
->is_debug_types
)
9547 struct signatured_type
*sig_type
=
9548 (struct signatured_type
*) per_cu
;
9550 sprintf (buf
, "TU %s at offset %s",
9551 hex_string (sig_type
->signature
),
9552 sect_offset_str (per_cu
->sect_off
));
9553 /* There can be 100s of TUs.
9554 Only print them in verbose mode. */
9555 debug_print_threshold
= 2;
9559 sprintf (buf
, "CU at offset %s",
9560 sect_offset_str (per_cu
->sect_off
));
9561 debug_print_threshold
= 1;
9564 if (dwarf_read_debug
>= debug_print_threshold
)
9565 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
9567 if (per_cu
->is_debug_types
)
9568 process_full_type_unit (per_cu
, item
->pretend_language
);
9570 process_full_comp_unit (per_cu
, item
->pretend_language
);
9572 if (dwarf_read_debug
>= debug_print_threshold
)
9573 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
9576 item
->per_cu
->queued
= 0;
9577 next_item
= item
->next
;
9581 dwarf2_queue_tail
= NULL
;
9583 if (dwarf_read_debug
)
9585 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
9586 objfile_name (dwarf2_per_objfile
->objfile
));
9590 /* Read in full symbols for PST, and anything it depends on. */
9593 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
9595 struct dwarf2_per_cu_data
*per_cu
;
9601 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
9602 if (!pst
->dependencies
[i
]->readin
9603 && pst
->dependencies
[i
]->user
== NULL
)
9605 /* Inform about additional files that need to be read in. */
9608 /* FIXME: i18n: Need to make this a single string. */
9609 fputs_filtered (" ", gdb_stdout
);
9611 fputs_filtered ("and ", gdb_stdout
);
9613 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
9614 wrap_here (""); /* Flush output. */
9615 gdb_flush (gdb_stdout
);
9617 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
9620 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
9624 /* It's an include file, no symbols to read for it.
9625 Everything is in the parent symtab. */
9630 dw2_do_instantiate_symtab (per_cu
, false);
9633 /* Trivial hash function for die_info: the hash value of a DIE
9634 is its offset in .debug_info for this objfile. */
9637 die_hash (const void *item
)
9639 const struct die_info
*die
= (const struct die_info
*) item
;
9641 return to_underlying (die
->sect_off
);
9644 /* Trivial comparison function for die_info structures: two DIEs
9645 are equal if they have the same offset. */
9648 die_eq (const void *item_lhs
, const void *item_rhs
)
9650 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
9651 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
9653 return die_lhs
->sect_off
== die_rhs
->sect_off
;
9656 /* die_reader_func for load_full_comp_unit.
9657 This is identical to read_signatured_type_reader,
9658 but is kept separate for now. */
9661 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
9662 const gdb_byte
*info_ptr
,
9663 struct die_info
*comp_unit_die
,
9667 struct dwarf2_cu
*cu
= reader
->cu
;
9668 enum language
*language_ptr
= (enum language
*) data
;
9670 gdb_assert (cu
->die_hash
== NULL
);
9672 htab_create_alloc_ex (cu
->header
.length
/ 12,
9676 &cu
->comp_unit_obstack
,
9677 hashtab_obstack_allocate
,
9678 dummy_obstack_deallocate
);
9681 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
9682 &info_ptr
, comp_unit_die
);
9683 cu
->dies
= comp_unit_die
;
9684 /* comp_unit_die is not stored in die_hash, no need. */
9686 /* We try not to read any attributes in this function, because not
9687 all CUs needed for references have been loaded yet, and symbol
9688 table processing isn't initialized. But we have to set the CU language,
9689 or we won't be able to build types correctly.
9690 Similarly, if we do not read the producer, we can not apply
9691 producer-specific interpretation. */
9692 prepare_one_comp_unit (cu
, cu
->dies
, *language_ptr
);
9695 /* Load the DIEs associated with PER_CU into memory. */
9698 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
9700 enum language pretend_language
)
9702 gdb_assert (! this_cu
->is_debug_types
);
9704 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1, skip_partial
,
9705 load_full_comp_unit_reader
, &pretend_language
);
9708 /* Add a DIE to the delayed physname list. */
9711 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
9712 const char *name
, struct die_info
*die
,
9713 struct dwarf2_cu
*cu
)
9715 struct delayed_method_info mi
;
9717 mi
.fnfield_index
= fnfield_index
;
9721 cu
->method_list
.push_back (mi
);
9724 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
9725 "const" / "volatile". If so, decrements LEN by the length of the
9726 modifier and return true. Otherwise return false. */
9730 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
9732 size_t mod_len
= sizeof (mod
) - 1;
9733 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
9741 /* Compute the physnames of any methods on the CU's method list.
9743 The computation of method physnames is delayed in order to avoid the
9744 (bad) condition that one of the method's formal parameters is of an as yet
9748 compute_delayed_physnames (struct dwarf2_cu
*cu
)
9750 /* Only C++ delays computing physnames. */
9751 if (cu
->method_list
.empty ())
9753 gdb_assert (cu
->language
== language_cplus
);
9755 for (const delayed_method_info
&mi
: cu
->method_list
)
9757 const char *physname
;
9758 struct fn_fieldlist
*fn_flp
9759 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9760 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9761 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9762 = physname
? physname
: "";
9764 /* Since there's no tag to indicate whether a method is a
9765 const/volatile overload, extract that information out of the
9767 if (physname
!= NULL
)
9769 size_t len
= strlen (physname
);
9773 if (physname
[len
] == ')') /* shortcut */
9775 else if (check_modifier (physname
, len
, " const"))
9776 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9777 else if (check_modifier (physname
, len
, " volatile"))
9778 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9785 /* The list is no longer needed. */
9786 cu
->method_list
.clear ();
9789 /* Go objects should be embedded in a DW_TAG_module DIE,
9790 and it's not clear if/how imported objects will appear.
9791 To keep Go support simple until that's worked out,
9792 go back through what we've read and create something usable.
9793 We could do this while processing each DIE, and feels kinda cleaner,
9794 but that way is more invasive.
9795 This is to, for example, allow the user to type "p var" or "b main"
9796 without having to specify the package name, and allow lookups
9797 of module.object to work in contexts that use the expression
9801 fixup_go_packaging (struct dwarf2_cu
*cu
)
9803 char *package_name
= NULL
;
9804 struct pending
*list
;
9807 for (list
= *cu
->get_builder ()->get_global_symbols ();
9811 for (i
= 0; i
< list
->nsyms
; ++i
)
9813 struct symbol
*sym
= list
->symbol
[i
];
9815 if (SYMBOL_LANGUAGE (sym
) == language_go
9816 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9818 char *this_package_name
= go_symbol_package_name (sym
);
9820 if (this_package_name
== NULL
)
9822 if (package_name
== NULL
)
9823 package_name
= this_package_name
;
9826 struct objfile
*objfile
9827 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9828 if (strcmp (package_name
, this_package_name
) != 0)
9829 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9830 (symbol_symtab (sym
) != NULL
9831 ? symtab_to_filename_for_display
9832 (symbol_symtab (sym
))
9833 : objfile_name (objfile
)),
9834 this_package_name
, package_name
);
9835 xfree (this_package_name
);
9841 if (package_name
!= NULL
)
9843 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9844 const char *saved_package_name
9845 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
, package_name
);
9846 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9847 saved_package_name
);
9850 sym
= allocate_symbol (objfile
);
9851 SYMBOL_SET_LANGUAGE (sym
, language_go
, &objfile
->objfile_obstack
);
9852 SYMBOL_SET_NAMES (sym
, saved_package_name
,
9853 strlen (saved_package_name
), 0, objfile
);
9854 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9855 e.g., "main" finds the "main" module and not C's main(). */
9856 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9857 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9858 SYMBOL_TYPE (sym
) = type
;
9860 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9862 xfree (package_name
);
9866 /* Allocate a fully-qualified name consisting of the two parts on the
9870 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9872 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9875 /* A helper that allocates a struct discriminant_info to attach to a
9878 static struct discriminant_info
*
9879 alloc_discriminant_info (struct type
*type
, int discriminant_index
,
9882 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9883 gdb_assert (discriminant_index
== -1
9884 || (discriminant_index
>= 0
9885 && discriminant_index
< TYPE_NFIELDS (type
)));
9886 gdb_assert (default_index
== -1
9887 || (default_index
>= 0 && default_index
< TYPE_NFIELDS (type
)));
9889 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
9891 struct discriminant_info
*disc
9892 = ((struct discriminant_info
*)
9894 offsetof (struct discriminant_info
, discriminants
)
9895 + TYPE_NFIELDS (type
) * sizeof (disc
->discriminants
[0])));
9896 disc
->default_index
= default_index
;
9897 disc
->discriminant_index
= discriminant_index
;
9899 struct dynamic_prop prop
;
9900 prop
.kind
= PROP_UNDEFINED
;
9901 prop
.data
.baton
= disc
;
9903 add_dyn_prop (DYN_PROP_DISCRIMINATED
, prop
, type
);
9908 /* Some versions of rustc emitted enums in an unusual way.
9910 Ordinary enums were emitted as unions. The first element of each
9911 structure in the union was named "RUST$ENUM$DISR". This element
9912 held the discriminant.
9914 These versions of Rust also implemented the "non-zero"
9915 optimization. When the enum had two values, and one is empty and
9916 the other holds a pointer that cannot be zero, the pointer is used
9917 as the discriminant, with a zero value meaning the empty variant.
9918 Here, the union's first member is of the form
9919 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9920 where the fieldnos are the indices of the fields that should be
9921 traversed in order to find the field (which may be several fields deep)
9922 and the variantname is the name of the variant of the case when the
9925 This function recognizes whether TYPE is of one of these forms,
9926 and, if so, smashes it to be a variant type. */
9929 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9931 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9933 /* We don't need to deal with empty enums. */
9934 if (TYPE_NFIELDS (type
) == 0)
9937 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9938 if (TYPE_NFIELDS (type
) == 1
9939 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9941 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9943 /* Decode the field name to find the offset of the
9945 ULONGEST bit_offset
= 0;
9946 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9947 while (name
[0] >= '0' && name
[0] <= '9')
9950 unsigned long index
= strtoul (name
, &tail
, 10);
9953 || index
>= TYPE_NFIELDS (field_type
)
9954 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9955 != FIELD_LOC_KIND_BITPOS
))
9957 complaint (_("Could not parse Rust enum encoding string \"%s\""
9959 TYPE_FIELD_NAME (type
, 0),
9960 objfile_name (objfile
));
9965 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9966 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
9969 /* Make a union to hold the variants. */
9970 struct type
*union_type
= alloc_type (objfile
);
9971 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9972 TYPE_NFIELDS (union_type
) = 3;
9973 TYPE_FIELDS (union_type
)
9974 = (struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
));
9975 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9976 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9978 /* Put the discriminant must at index 0. */
9979 TYPE_FIELD_TYPE (union_type
, 0) = field_type
;
9980 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
9981 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
9982 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 0), bit_offset
);
9984 /* The order of fields doesn't really matter, so put the real
9985 field at index 1 and the data-less field at index 2. */
9986 struct discriminant_info
*disc
9987 = alloc_discriminant_info (union_type
, 0, 1);
9988 TYPE_FIELD (union_type
, 1) = TYPE_FIELD (type
, 0);
9989 TYPE_FIELD_NAME (union_type
, 1)
9990 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1)));
9991 TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1))
9992 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9993 TYPE_FIELD_NAME (union_type
, 1));
9995 const char *dataless_name
9996 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9998 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
10000 TYPE_FIELD_TYPE (union_type
, 2) = dataless_type
;
10001 /* NAME points into the original discriminant name, which
10002 already has the correct lifetime. */
10003 TYPE_FIELD_NAME (union_type
, 2) = name
;
10004 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 2), 0);
10005 disc
->discriminants
[2] = 0;
10007 /* Smash this type to be a structure type. We have to do this
10008 because the type has already been recorded. */
10009 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10010 TYPE_NFIELDS (type
) = 1;
10012 = (struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
));
10014 /* Install the variant part. */
10015 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10016 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10017 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10019 else if (TYPE_NFIELDS (type
) == 1)
10021 /* We assume that a union with a single field is a univariant
10023 /* Smash this type to be a structure type. We have to do this
10024 because the type has already been recorded. */
10025 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10027 /* Make a union to hold the variants. */
10028 struct type
*union_type
= alloc_type (objfile
);
10029 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10030 TYPE_NFIELDS (union_type
) = TYPE_NFIELDS (type
);
10031 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10032 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
10033 TYPE_FIELDS (union_type
) = TYPE_FIELDS (type
);
10035 struct type
*field_type
= TYPE_FIELD_TYPE (union_type
, 0);
10036 const char *variant_name
10037 = rust_last_path_segment (TYPE_NAME (field_type
));
10038 TYPE_FIELD_NAME (union_type
, 0) = variant_name
;
10039 TYPE_NAME (field_type
)
10040 = rust_fully_qualify (&objfile
->objfile_obstack
,
10041 TYPE_NAME (type
), variant_name
);
10043 /* Install the union in the outer struct type. */
10044 TYPE_NFIELDS (type
) = 1;
10046 = (struct field
*) TYPE_ZALLOC (union_type
, sizeof (struct field
));
10047 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10048 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10049 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10051 alloc_discriminant_info (union_type
, -1, 0);
10055 struct type
*disr_type
= nullptr;
10056 for (int i
= 0; i
< TYPE_NFIELDS (type
); ++i
)
10058 disr_type
= TYPE_FIELD_TYPE (type
, i
);
10060 if (TYPE_CODE (disr_type
) != TYPE_CODE_STRUCT
)
10062 /* All fields of a true enum will be structs. */
10065 else if (TYPE_NFIELDS (disr_type
) == 0)
10067 /* Could be data-less variant, so keep going. */
10068 disr_type
= nullptr;
10070 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
10071 "RUST$ENUM$DISR") != 0)
10073 /* Not a Rust enum. */
10083 /* If we got here without a discriminant, then it's probably
10085 if (disr_type
== nullptr)
10088 /* Smash this type to be a structure type. We have to do this
10089 because the type has already been recorded. */
10090 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10092 /* Make a union to hold the variants. */
10093 struct field
*disr_field
= &TYPE_FIELD (disr_type
, 0);
10094 struct type
*union_type
= alloc_type (objfile
);
10095 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10096 TYPE_NFIELDS (union_type
) = 1 + TYPE_NFIELDS (type
);
10097 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10098 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
10099 TYPE_FIELDS (union_type
)
10100 = (struct field
*) TYPE_ZALLOC (union_type
,
10101 (TYPE_NFIELDS (union_type
)
10102 * sizeof (struct field
)));
10104 memcpy (TYPE_FIELDS (union_type
) + 1, TYPE_FIELDS (type
),
10105 TYPE_NFIELDS (type
) * sizeof (struct field
));
10107 /* Install the discriminant at index 0 in the union. */
10108 TYPE_FIELD (union_type
, 0) = *disr_field
;
10109 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
10110 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
10112 /* Install the union in the outer struct type. */
10113 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10114 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10115 TYPE_NFIELDS (type
) = 1;
10117 /* Set the size and offset of the union type. */
10118 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10120 /* We need a way to find the correct discriminant given a
10121 variant name. For convenience we build a map here. */
10122 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
10123 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
10124 for (int i
= 0; i
< TYPE_NFIELDS (enum_type
); ++i
)
10126 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
10129 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
10130 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
10134 int n_fields
= TYPE_NFIELDS (union_type
);
10135 struct discriminant_info
*disc
10136 = alloc_discriminant_info (union_type
, 0, -1);
10137 /* Skip the discriminant here. */
10138 for (int i
= 1; i
< n_fields
; ++i
)
10140 /* Find the final word in the name of this variant's type.
10141 That name can be used to look up the correct
10143 const char *variant_name
10144 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
,
10147 auto iter
= discriminant_map
.find (variant_name
);
10148 if (iter
!= discriminant_map
.end ())
10149 disc
->discriminants
[i
] = iter
->second
;
10151 /* Remove the discriminant field, if it exists. */
10152 struct type
*sub_type
= TYPE_FIELD_TYPE (union_type
, i
);
10153 if (TYPE_NFIELDS (sub_type
) > 0)
10155 --TYPE_NFIELDS (sub_type
);
10156 ++TYPE_FIELDS (sub_type
);
10158 TYPE_FIELD_NAME (union_type
, i
) = variant_name
;
10159 TYPE_NAME (sub_type
)
10160 = rust_fully_qualify (&objfile
->objfile_obstack
,
10161 TYPE_NAME (type
), variant_name
);
10166 /* Rewrite some Rust unions to be structures with variants parts. */
10169 rust_union_quirks (struct dwarf2_cu
*cu
)
10171 gdb_assert (cu
->language
== language_rust
);
10172 for (type
*type_
: cu
->rust_unions
)
10173 quirk_rust_enum (type_
, cu
->per_cu
->dwarf2_per_objfile
->objfile
);
10174 /* We don't need this any more. */
10175 cu
->rust_unions
.clear ();
10178 /* Return the symtab for PER_CU. This works properly regardless of
10179 whether we're using the index or psymtabs. */
10181 static struct compunit_symtab
*
10182 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
10184 return (per_cu
->dwarf2_per_objfile
->using_index
10185 ? per_cu
->v
.quick
->compunit_symtab
10186 : per_cu
->v
.psymtab
->compunit_symtab
);
10189 /* A helper function for computing the list of all symbol tables
10190 included by PER_CU. */
10193 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
10194 htab_t all_children
, htab_t all_type_symtabs
,
10195 struct dwarf2_per_cu_data
*per_cu
,
10196 struct compunit_symtab
*immediate_parent
)
10200 struct compunit_symtab
*cust
;
10201 struct dwarf2_per_cu_data
*iter
;
10203 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
10206 /* This inclusion and its children have been processed. */
10211 /* Only add a CU if it has a symbol table. */
10212 cust
= get_compunit_symtab (per_cu
);
10215 /* If this is a type unit only add its symbol table if we haven't
10216 seen it yet (type unit per_cu's can share symtabs). */
10217 if (per_cu
->is_debug_types
)
10219 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
10223 result
->push_back (cust
);
10224 if (cust
->user
== NULL
)
10225 cust
->user
= immediate_parent
;
10230 result
->push_back (cust
);
10231 if (cust
->user
== NULL
)
10232 cust
->user
= immediate_parent
;
10237 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, ix
, iter
);
10240 recursively_compute_inclusions (result
, all_children
,
10241 all_type_symtabs
, iter
, cust
);
10245 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
10249 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
10251 gdb_assert (! per_cu
->is_debug_types
);
10253 if (!VEC_empty (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
))
10256 struct dwarf2_per_cu_data
*per_cu_iter
;
10257 std::vector
<compunit_symtab
*> result_symtabs
;
10258 htab_t all_children
, all_type_symtabs
;
10259 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
10261 /* If we don't have a symtab, we can just skip this case. */
10265 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10266 NULL
, xcalloc
, xfree
);
10267 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10268 NULL
, xcalloc
, xfree
);
10271 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
,
10275 recursively_compute_inclusions (&result_symtabs
, all_children
,
10276 all_type_symtabs
, per_cu_iter
,
10280 /* Now we have a transitive closure of all the included symtabs. */
10281 len
= result_symtabs
.size ();
10283 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
10284 struct compunit_symtab
*, len
+ 1);
10285 memcpy (cust
->includes
, result_symtabs
.data (),
10286 len
* sizeof (compunit_symtab
*));
10287 cust
->includes
[len
] = NULL
;
10289 htab_delete (all_children
);
10290 htab_delete (all_type_symtabs
);
10294 /* Compute the 'includes' field for the symtabs of all the CUs we just
10298 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
10300 for (dwarf2_per_cu_data
*iter
: dwarf2_per_objfile
->just_read_cus
)
10302 if (! iter
->is_debug_types
)
10303 compute_compunit_symtab_includes (iter
);
10306 dwarf2_per_objfile
->just_read_cus
.clear ();
10309 /* Generate full symbol information for PER_CU, whose DIEs have
10310 already been loaded into memory. */
10313 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
10314 enum language pretend_language
)
10316 struct dwarf2_cu
*cu
= per_cu
->cu
;
10317 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10318 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10319 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10320 CORE_ADDR lowpc
, highpc
;
10321 struct compunit_symtab
*cust
;
10322 CORE_ADDR baseaddr
;
10323 struct block
*static_block
;
10326 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10328 /* Clear the list here in case something was left over. */
10329 cu
->method_list
.clear ();
10331 cu
->language
= pretend_language
;
10332 cu
->language_defn
= language_def (cu
->language
);
10334 /* Do line number decoding in read_file_scope () */
10335 process_die (cu
->dies
, cu
);
10337 /* For now fudge the Go package. */
10338 if (cu
->language
== language_go
)
10339 fixup_go_packaging (cu
);
10341 /* Now that we have processed all the DIEs in the CU, all the types
10342 should be complete, and it should now be safe to compute all of the
10344 compute_delayed_physnames (cu
);
10346 if (cu
->language
== language_rust
)
10347 rust_union_quirks (cu
);
10349 /* Some compilers don't define a DW_AT_high_pc attribute for the
10350 compilation unit. If the DW_AT_high_pc is missing, synthesize
10351 it, by scanning the DIE's below the compilation unit. */
10352 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
10354 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
10355 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
10357 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
10358 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
10359 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
10360 addrmap to help ensure it has an accurate map of pc values belonging to
10362 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
10364 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
10365 SECT_OFF_TEXT (objfile
),
10370 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
10372 /* Set symtab language to language from DW_AT_language. If the
10373 compilation is from a C file generated by language preprocessors, do
10374 not set the language if it was already deduced by start_subfile. */
10375 if (!(cu
->language
== language_c
10376 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
10377 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10379 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
10380 produce DW_AT_location with location lists but it can be possibly
10381 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
10382 there were bugs in prologue debug info, fixed later in GCC-4.5
10383 by "unwind info for epilogues" patch (which is not directly related).
10385 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
10386 needed, it would be wrong due to missing DW_AT_producer there.
10388 Still one can confuse GDB by using non-standard GCC compilation
10389 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
10391 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
10392 cust
->locations_valid
= 1;
10394 if (gcc_4_minor
>= 5)
10395 cust
->epilogue_unwind_valid
= 1;
10397 cust
->call_site_htab
= cu
->call_site_htab
;
10400 if (dwarf2_per_objfile
->using_index
)
10401 per_cu
->v
.quick
->compunit_symtab
= cust
;
10404 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
10405 pst
->compunit_symtab
= cust
;
10409 /* Push it for inclusion processing later. */
10410 dwarf2_per_objfile
->just_read_cus
.push_back (per_cu
);
10412 /* Not needed any more. */
10413 cu
->reset_builder ();
10416 /* Generate full symbol information for type unit PER_CU, whose DIEs have
10417 already been loaded into memory. */
10420 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
10421 enum language pretend_language
)
10423 struct dwarf2_cu
*cu
= per_cu
->cu
;
10424 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10425 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10426 struct compunit_symtab
*cust
;
10427 struct signatured_type
*sig_type
;
10429 gdb_assert (per_cu
->is_debug_types
);
10430 sig_type
= (struct signatured_type
*) per_cu
;
10432 /* Clear the list here in case something was left over. */
10433 cu
->method_list
.clear ();
10435 cu
->language
= pretend_language
;
10436 cu
->language_defn
= language_def (cu
->language
);
10438 /* The symbol tables are set up in read_type_unit_scope. */
10439 process_die (cu
->dies
, cu
);
10441 /* For now fudge the Go package. */
10442 if (cu
->language
== language_go
)
10443 fixup_go_packaging (cu
);
10445 /* Now that we have processed all the DIEs in the CU, all the types
10446 should be complete, and it should now be safe to compute all of the
10448 compute_delayed_physnames (cu
);
10450 if (cu
->language
== language_rust
)
10451 rust_union_quirks (cu
);
10453 /* TUs share symbol tables.
10454 If this is the first TU to use this symtab, complete the construction
10455 of it with end_expandable_symtab. Otherwise, complete the addition of
10456 this TU's symbols to the existing symtab. */
10457 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
10459 buildsym_compunit
*builder
= cu
->get_builder ();
10460 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
10461 sig_type
->type_unit_group
->compunit_symtab
= cust
;
10465 /* Set symtab language to language from DW_AT_language. If the
10466 compilation is from a C file generated by language preprocessors,
10467 do not set the language if it was already deduced by
10469 if (!(cu
->language
== language_c
10470 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
10471 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10476 cu
->get_builder ()->augment_type_symtab ();
10477 cust
= sig_type
->type_unit_group
->compunit_symtab
;
10480 if (dwarf2_per_objfile
->using_index
)
10481 per_cu
->v
.quick
->compunit_symtab
= cust
;
10484 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
10485 pst
->compunit_symtab
= cust
;
10489 /* Not needed any more. */
10490 cu
->reset_builder ();
10493 /* Process an imported unit DIE. */
10496 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10498 struct attribute
*attr
;
10500 /* For now we don't handle imported units in type units. */
10501 if (cu
->per_cu
->is_debug_types
)
10503 error (_("Dwarf Error: DW_TAG_imported_unit is not"
10504 " supported in type units [in module %s]"),
10505 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
10508 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10511 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
10512 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
10513 dwarf2_per_cu_data
*per_cu
10514 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
10515 cu
->per_cu
->dwarf2_per_objfile
);
10517 /* If necessary, add it to the queue and load its DIEs. */
10518 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
10519 load_full_comp_unit (per_cu
, false, cu
->language
);
10521 VEC_safe_push (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
10526 /* RAII object that represents a process_die scope: i.e.,
10527 starts/finishes processing a DIE. */
10528 class process_die_scope
10531 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
10532 : m_die (die
), m_cu (cu
)
10534 /* We should only be processing DIEs not already in process. */
10535 gdb_assert (!m_die
->in_process
);
10536 m_die
->in_process
= true;
10539 ~process_die_scope ()
10541 m_die
->in_process
= false;
10543 /* If we're done processing the DIE for the CU that owns the line
10544 header, we don't need the line header anymore. */
10545 if (m_cu
->line_header_die_owner
== m_die
)
10547 delete m_cu
->line_header
;
10548 m_cu
->line_header
= NULL
;
10549 m_cu
->line_header_die_owner
= NULL
;
10558 /* Process a die and its children. */
10561 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10563 process_die_scope
scope (die
, cu
);
10567 case DW_TAG_padding
:
10569 case DW_TAG_compile_unit
:
10570 case DW_TAG_partial_unit
:
10571 read_file_scope (die
, cu
);
10573 case DW_TAG_type_unit
:
10574 read_type_unit_scope (die
, cu
);
10576 case DW_TAG_subprogram
:
10577 case DW_TAG_inlined_subroutine
:
10578 read_func_scope (die
, cu
);
10580 case DW_TAG_lexical_block
:
10581 case DW_TAG_try_block
:
10582 case DW_TAG_catch_block
:
10583 read_lexical_block_scope (die
, cu
);
10585 case DW_TAG_call_site
:
10586 case DW_TAG_GNU_call_site
:
10587 read_call_site_scope (die
, cu
);
10589 case DW_TAG_class_type
:
10590 case DW_TAG_interface_type
:
10591 case DW_TAG_structure_type
:
10592 case DW_TAG_union_type
:
10593 process_structure_scope (die
, cu
);
10595 case DW_TAG_enumeration_type
:
10596 process_enumeration_scope (die
, cu
);
10599 /* These dies have a type, but processing them does not create
10600 a symbol or recurse to process the children. Therefore we can
10601 read them on-demand through read_type_die. */
10602 case DW_TAG_subroutine_type
:
10603 case DW_TAG_set_type
:
10604 case DW_TAG_array_type
:
10605 case DW_TAG_pointer_type
:
10606 case DW_TAG_ptr_to_member_type
:
10607 case DW_TAG_reference_type
:
10608 case DW_TAG_rvalue_reference_type
:
10609 case DW_TAG_string_type
:
10612 case DW_TAG_base_type
:
10613 case DW_TAG_subrange_type
:
10614 case DW_TAG_typedef
:
10615 /* Add a typedef symbol for the type definition, if it has a
10617 new_symbol (die
, read_type_die (die
, cu
), cu
);
10619 case DW_TAG_common_block
:
10620 read_common_block (die
, cu
);
10622 case DW_TAG_common_inclusion
:
10624 case DW_TAG_namespace
:
10625 cu
->processing_has_namespace_info
= true;
10626 read_namespace (die
, cu
);
10628 case DW_TAG_module
:
10629 cu
->processing_has_namespace_info
= true;
10630 read_module (die
, cu
);
10632 case DW_TAG_imported_declaration
:
10633 cu
->processing_has_namespace_info
= true;
10634 if (read_namespace_alias (die
, cu
))
10636 /* The declaration is not a global namespace alias. */
10637 /* Fall through. */
10638 case DW_TAG_imported_module
:
10639 cu
->processing_has_namespace_info
= true;
10640 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
10641 || cu
->language
!= language_fortran
))
10642 complaint (_("Tag '%s' has unexpected children"),
10643 dwarf_tag_name (die
->tag
));
10644 read_import_statement (die
, cu
);
10647 case DW_TAG_imported_unit
:
10648 process_imported_unit_die (die
, cu
);
10651 case DW_TAG_variable
:
10652 read_variable (die
, cu
);
10656 new_symbol (die
, NULL
, cu
);
10661 /* DWARF name computation. */
10663 /* A helper function for dwarf2_compute_name which determines whether DIE
10664 needs to have the name of the scope prepended to the name listed in the
10668 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10670 struct attribute
*attr
;
10674 case DW_TAG_namespace
:
10675 case DW_TAG_typedef
:
10676 case DW_TAG_class_type
:
10677 case DW_TAG_interface_type
:
10678 case DW_TAG_structure_type
:
10679 case DW_TAG_union_type
:
10680 case DW_TAG_enumeration_type
:
10681 case DW_TAG_enumerator
:
10682 case DW_TAG_subprogram
:
10683 case DW_TAG_inlined_subroutine
:
10684 case DW_TAG_member
:
10685 case DW_TAG_imported_declaration
:
10688 case DW_TAG_variable
:
10689 case DW_TAG_constant
:
10690 /* We only need to prefix "globally" visible variables. These include
10691 any variable marked with DW_AT_external or any variable that
10692 lives in a namespace. [Variables in anonymous namespaces
10693 require prefixing, but they are not DW_AT_external.] */
10695 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
10697 struct dwarf2_cu
*spec_cu
= cu
;
10699 return die_needs_namespace (die_specification (die
, &spec_cu
),
10703 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10704 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
10705 && die
->parent
->tag
!= DW_TAG_module
)
10707 /* A variable in a lexical block of some kind does not need a
10708 namespace, even though in C++ such variables may be external
10709 and have a mangled name. */
10710 if (die
->parent
->tag
== DW_TAG_lexical_block
10711 || die
->parent
->tag
== DW_TAG_try_block
10712 || die
->parent
->tag
== DW_TAG_catch_block
10713 || die
->parent
->tag
== DW_TAG_subprogram
)
10722 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
10723 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10724 defined for the given DIE. */
10726 static struct attribute
*
10727 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
10729 struct attribute
*attr
;
10731 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
10733 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10738 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10739 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10740 defined for the given DIE. */
10742 static const char *
10743 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10745 const char *linkage_name
;
10747 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10748 if (linkage_name
== NULL
)
10749 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10751 return linkage_name
;
10754 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10755 compute the physname for the object, which include a method's:
10756 - formal parameters (C++),
10757 - receiver type (Go),
10759 The term "physname" is a bit confusing.
10760 For C++, for example, it is the demangled name.
10761 For Go, for example, it's the mangled name.
10763 For Ada, return the DIE's linkage name rather than the fully qualified
10764 name. PHYSNAME is ignored..
10766 The result is allocated on the objfile_obstack and canonicalized. */
10768 static const char *
10769 dwarf2_compute_name (const char *name
,
10770 struct die_info
*die
, struct dwarf2_cu
*cu
,
10773 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10776 name
= dwarf2_name (die
, cu
);
10778 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10779 but otherwise compute it by typename_concat inside GDB.
10780 FIXME: Actually this is not really true, or at least not always true.
10781 It's all very confusing. SYMBOL_SET_NAMES doesn't try to demangle
10782 Fortran names because there is no mangling standard. So new_symbol
10783 will set the demangled name to the result of dwarf2_full_name, and it is
10784 the demangled name that GDB uses if it exists. */
10785 if (cu
->language
== language_ada
10786 || (cu
->language
== language_fortran
&& physname
))
10788 /* For Ada unit, we prefer the linkage name over the name, as
10789 the former contains the exported name, which the user expects
10790 to be able to reference. Ideally, we want the user to be able
10791 to reference this entity using either natural or linkage name,
10792 but we haven't started looking at this enhancement yet. */
10793 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10795 if (linkage_name
!= NULL
)
10796 return linkage_name
;
10799 /* These are the only languages we know how to qualify names in. */
10801 && (cu
->language
== language_cplus
10802 || cu
->language
== language_fortran
|| cu
->language
== language_d
10803 || cu
->language
== language_rust
))
10805 if (die_needs_namespace (die
, cu
))
10807 const char *prefix
;
10808 const char *canonical_name
= NULL
;
10812 prefix
= determine_prefix (die
, cu
);
10813 if (*prefix
!= '\0')
10815 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
10818 buf
.puts (prefixed_name
);
10819 xfree (prefixed_name
);
10824 /* Template parameters may be specified in the DIE's DW_AT_name, or
10825 as children with DW_TAG_template_type_param or
10826 DW_TAG_value_type_param. If the latter, add them to the name
10827 here. If the name already has template parameters, then
10828 skip this step; some versions of GCC emit both, and
10829 it is more efficient to use the pre-computed name.
10831 Something to keep in mind about this process: it is very
10832 unlikely, or in some cases downright impossible, to produce
10833 something that will match the mangled name of a function.
10834 If the definition of the function has the same debug info,
10835 we should be able to match up with it anyway. But fallbacks
10836 using the minimal symbol, for instance to find a method
10837 implemented in a stripped copy of libstdc++, will not work.
10838 If we do not have debug info for the definition, we will have to
10839 match them up some other way.
10841 When we do name matching there is a related problem with function
10842 templates; two instantiated function templates are allowed to
10843 differ only by their return types, which we do not add here. */
10845 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10847 struct attribute
*attr
;
10848 struct die_info
*child
;
10851 die
->building_fullname
= 1;
10853 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10857 const gdb_byte
*bytes
;
10858 struct dwarf2_locexpr_baton
*baton
;
10861 if (child
->tag
!= DW_TAG_template_type_param
10862 && child
->tag
!= DW_TAG_template_value_param
)
10873 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10876 complaint (_("template parameter missing DW_AT_type"));
10877 buf
.puts ("UNKNOWN_TYPE");
10880 type
= die_type (child
, cu
);
10882 if (child
->tag
== DW_TAG_template_type_param
)
10884 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10885 &type_print_raw_options
);
10889 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10892 complaint (_("template parameter missing "
10893 "DW_AT_const_value"));
10894 buf
.puts ("UNKNOWN_VALUE");
10898 dwarf2_const_value_attr (attr
, type
, name
,
10899 &cu
->comp_unit_obstack
, cu
,
10900 &value
, &bytes
, &baton
);
10902 if (TYPE_NOSIGN (type
))
10903 /* GDB prints characters as NUMBER 'CHAR'. If that's
10904 changed, this can use value_print instead. */
10905 c_printchar (value
, type
, &buf
);
10908 struct value_print_options opts
;
10911 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10915 else if (bytes
!= NULL
)
10917 v
= allocate_value (type
);
10918 memcpy (value_contents_writeable (v
), bytes
,
10919 TYPE_LENGTH (type
));
10922 v
= value_from_longest (type
, value
);
10924 /* Specify decimal so that we do not depend on
10926 get_formatted_print_options (&opts
, 'd');
10928 value_print (v
, &buf
, &opts
);
10933 die
->building_fullname
= 0;
10937 /* Close the argument list, with a space if necessary
10938 (nested templates). */
10939 if (!buf
.empty () && buf
.string ().back () == '>')
10946 /* For C++ methods, append formal parameter type
10947 information, if PHYSNAME. */
10949 if (physname
&& die
->tag
== DW_TAG_subprogram
10950 && cu
->language
== language_cplus
)
10952 struct type
*type
= read_type_die (die
, cu
);
10954 c_type_print_args (type
, &buf
, 1, cu
->language
,
10955 &type_print_raw_options
);
10957 if (cu
->language
== language_cplus
)
10959 /* Assume that an artificial first parameter is
10960 "this", but do not crash if it is not. RealView
10961 marks unnamed (and thus unused) parameters as
10962 artificial; there is no way to differentiate
10964 if (TYPE_NFIELDS (type
) > 0
10965 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10966 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
10967 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
10969 buf
.puts (" const");
10973 const std::string
&intermediate_name
= buf
.string ();
10975 if (cu
->language
== language_cplus
)
10977 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10978 &objfile
->per_bfd
->storage_obstack
);
10980 /* If we only computed INTERMEDIATE_NAME, or if
10981 INTERMEDIATE_NAME is already canonical, then we need to
10982 copy it to the appropriate obstack. */
10983 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10984 name
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
10985 intermediate_name
);
10987 name
= canonical_name
;
10994 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10995 If scope qualifiers are appropriate they will be added. The result
10996 will be allocated on the storage_obstack, or NULL if the DIE does
10997 not have a name. NAME may either be from a previous call to
10998 dwarf2_name or NULL.
11000 The output string will be canonicalized (if C++). */
11002 static const char *
11003 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
11005 return dwarf2_compute_name (name
, die
, cu
, 0);
11008 /* Construct a physname for the given DIE in CU. NAME may either be
11009 from a previous call to dwarf2_name or NULL. The result will be
11010 allocated on the objfile_objstack or NULL if the DIE does not have a
11013 The output string will be canonicalized (if C++). */
11015 static const char *
11016 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
11018 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
11019 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
11022 /* In this case dwarf2_compute_name is just a shortcut not building anything
11024 if (!die_needs_namespace (die
, cu
))
11025 return dwarf2_compute_name (name
, die
, cu
, 1);
11027 mangled
= dw2_linkage_name (die
, cu
);
11029 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
11030 See https://github.com/rust-lang/rust/issues/32925. */
11031 if (cu
->language
== language_rust
&& mangled
!= NULL
11032 && strchr (mangled
, '{') != NULL
)
11035 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
11037 gdb::unique_xmalloc_ptr
<char> demangled
;
11038 if (mangled
!= NULL
)
11041 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
11043 /* Do nothing (do not demangle the symbol name). */
11045 else if (cu
->language
== language_go
)
11047 /* This is a lie, but we already lie to the caller new_symbol.
11048 new_symbol assumes we return the mangled name.
11049 This just undoes that lie until things are cleaned up. */
11053 /* Use DMGL_RET_DROP for C++ template functions to suppress
11054 their return type. It is easier for GDB users to search
11055 for such functions as `name(params)' than `long name(params)'.
11056 In such case the minimal symbol names do not match the full
11057 symbol names but for template functions there is never a need
11058 to look up their definition from their declaration so
11059 the only disadvantage remains the minimal symbol variant
11060 `long name(params)' does not have the proper inferior type. */
11061 demangled
.reset (gdb_demangle (mangled
,
11062 (DMGL_PARAMS
| DMGL_ANSI
11063 | DMGL_RET_DROP
)));
11066 canon
= demangled
.get ();
11074 if (canon
== NULL
|| check_physname
)
11076 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
11078 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
11080 /* It may not mean a bug in GDB. The compiler could also
11081 compute DW_AT_linkage_name incorrectly. But in such case
11082 GDB would need to be bug-to-bug compatible. */
11084 complaint (_("Computed physname <%s> does not match demangled <%s> "
11085 "(from linkage <%s>) - DIE at %s [in module %s]"),
11086 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
11087 objfile_name (objfile
));
11089 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
11090 is available here - over computed PHYSNAME. It is safer
11091 against both buggy GDB and buggy compilers. */
11105 retval
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
, retval
);
11110 /* Inspect DIE in CU for a namespace alias. If one exists, record
11111 a new symbol for it.
11113 Returns 1 if a namespace alias was recorded, 0 otherwise. */
11116 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
11118 struct attribute
*attr
;
11120 /* If the die does not have a name, this is not a namespace
11122 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
11126 struct die_info
*d
= die
;
11127 struct dwarf2_cu
*imported_cu
= cu
;
11129 /* If the compiler has nested DW_AT_imported_declaration DIEs,
11130 keep inspecting DIEs until we hit the underlying import. */
11131 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
11132 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
11134 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
11138 d
= follow_die_ref (d
, attr
, &imported_cu
);
11139 if (d
->tag
!= DW_TAG_imported_declaration
)
11143 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
11145 complaint (_("DIE at %s has too many recursively imported "
11146 "declarations"), sect_offset_str (d
->sect_off
));
11153 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
11155 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
11156 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
11158 /* This declaration is a global namespace alias. Add
11159 a symbol for it whose type is the aliased namespace. */
11160 new_symbol (die
, type
, cu
);
11169 /* Return the using directives repository (global or local?) to use in the
11170 current context for CU.
11172 For Ada, imported declarations can materialize renamings, which *may* be
11173 global. However it is impossible (for now?) in DWARF to distinguish
11174 "external" imported declarations and "static" ones. As all imported
11175 declarations seem to be static in all other languages, make them all CU-wide
11176 global only in Ada. */
11178 static struct using_direct
**
11179 using_directives (struct dwarf2_cu
*cu
)
11181 if (cu
->language
== language_ada
11182 && cu
->get_builder ()->outermost_context_p ())
11183 return cu
->get_builder ()->get_global_using_directives ();
11185 return cu
->get_builder ()->get_local_using_directives ();
11188 /* Read the import statement specified by the given die and record it. */
11191 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
11193 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
11194 struct attribute
*import_attr
;
11195 struct die_info
*imported_die
, *child_die
;
11196 struct dwarf2_cu
*imported_cu
;
11197 const char *imported_name
;
11198 const char *imported_name_prefix
;
11199 const char *canonical_name
;
11200 const char *import_alias
;
11201 const char *imported_declaration
= NULL
;
11202 const char *import_prefix
;
11203 std::vector
<const char *> excludes
;
11205 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
11206 if (import_attr
== NULL
)
11208 complaint (_("Tag '%s' has no DW_AT_import"),
11209 dwarf_tag_name (die
->tag
));
11214 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
11215 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11216 if (imported_name
== NULL
)
11218 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
11220 The import in the following code:
11234 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
11235 <52> DW_AT_decl_file : 1
11236 <53> DW_AT_decl_line : 6
11237 <54> DW_AT_import : <0x75>
11238 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
11239 <59> DW_AT_name : B
11240 <5b> DW_AT_decl_file : 1
11241 <5c> DW_AT_decl_line : 2
11242 <5d> DW_AT_type : <0x6e>
11244 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
11245 <76> DW_AT_byte_size : 4
11246 <77> DW_AT_encoding : 5 (signed)
11248 imports the wrong die ( 0x75 instead of 0x58 ).
11249 This case will be ignored until the gcc bug is fixed. */
11253 /* Figure out the local name after import. */
11254 import_alias
= dwarf2_name (die
, cu
);
11256 /* Figure out where the statement is being imported to. */
11257 import_prefix
= determine_prefix (die
, cu
);
11259 /* Figure out what the scope of the imported die is and prepend it
11260 to the name of the imported die. */
11261 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
11263 if (imported_die
->tag
!= DW_TAG_namespace
11264 && imported_die
->tag
!= DW_TAG_module
)
11266 imported_declaration
= imported_name
;
11267 canonical_name
= imported_name_prefix
;
11269 else if (strlen (imported_name_prefix
) > 0)
11270 canonical_name
= obconcat (&objfile
->objfile_obstack
,
11271 imported_name_prefix
,
11272 (cu
->language
== language_d
? "." : "::"),
11273 imported_name
, (char *) NULL
);
11275 canonical_name
= imported_name
;
11277 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
11278 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
11279 child_die
= sibling_die (child_die
))
11281 /* DWARF-4: A Fortran use statement with a “rename list” may be
11282 represented by an imported module entry with an import attribute
11283 referring to the module and owned entries corresponding to those
11284 entities that are renamed as part of being imported. */
11286 if (child_die
->tag
!= DW_TAG_imported_declaration
)
11288 complaint (_("child DW_TAG_imported_declaration expected "
11289 "- DIE at %s [in module %s]"),
11290 sect_offset_str (child_die
->sect_off
),
11291 objfile_name (objfile
));
11295 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
11296 if (import_attr
== NULL
)
11298 complaint (_("Tag '%s' has no DW_AT_import"),
11299 dwarf_tag_name (child_die
->tag
));
11304 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
11306 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11307 if (imported_name
== NULL
)
11309 complaint (_("child DW_TAG_imported_declaration has unknown "
11310 "imported name - DIE at %s [in module %s]"),
11311 sect_offset_str (child_die
->sect_off
),
11312 objfile_name (objfile
));
11316 excludes
.push_back (imported_name
);
11318 process_die (child_die
, cu
);
11321 add_using_directive (using_directives (cu
),
11325 imported_declaration
,
11328 &objfile
->objfile_obstack
);
11331 /* ICC<14 does not output the required DW_AT_declaration on incomplete
11332 types, but gives them a size of zero. Starting with version 14,
11333 ICC is compatible with GCC. */
11336 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
11338 if (!cu
->checked_producer
)
11339 check_producer (cu
);
11341 return cu
->producer_is_icc_lt_14
;
11344 /* ICC generates a DW_AT_type for C void functions. This was observed on
11345 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
11346 which says that void functions should not have a DW_AT_type. */
11349 producer_is_icc (struct dwarf2_cu
*cu
)
11351 if (!cu
->checked_producer
)
11352 check_producer (cu
);
11354 return cu
->producer_is_icc
;
11357 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
11358 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
11359 this, it was first present in GCC release 4.3.0. */
11362 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
11364 if (!cu
->checked_producer
)
11365 check_producer (cu
);
11367 return cu
->producer_is_gcc_lt_4_3
;
11370 static file_and_directory
11371 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
11373 file_and_directory res
;
11375 /* Find the filename. Do not use dwarf2_name here, since the filename
11376 is not a source language identifier. */
11377 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
11378 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
11380 if (res
.comp_dir
== NULL
11381 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
11382 && IS_ABSOLUTE_PATH (res
.name
))
11384 res
.comp_dir_storage
= ldirname (res
.name
);
11385 if (!res
.comp_dir_storage
.empty ())
11386 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
11388 if (res
.comp_dir
!= NULL
)
11390 /* Irix 6.2 native cc prepends <machine>.: to the compilation
11391 directory, get rid of it. */
11392 const char *cp
= strchr (res
.comp_dir
, ':');
11394 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
11395 res
.comp_dir
= cp
+ 1;
11398 if (res
.name
== NULL
)
11399 res
.name
= "<unknown>";
11404 /* Handle DW_AT_stmt_list for a compilation unit.
11405 DIE is the DW_TAG_compile_unit die for CU.
11406 COMP_DIR is the compilation directory. LOWPC is passed to
11407 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
11410 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
11411 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
11413 struct dwarf2_per_objfile
*dwarf2_per_objfile
11414 = cu
->per_cu
->dwarf2_per_objfile
;
11415 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11416 struct attribute
*attr
;
11417 struct line_header line_header_local
;
11418 hashval_t line_header_local_hash
;
11420 int decode_mapping
;
11422 gdb_assert (! cu
->per_cu
->is_debug_types
);
11424 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
11428 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11430 /* The line header hash table is only created if needed (it exists to
11431 prevent redundant reading of the line table for partial_units).
11432 If we're given a partial_unit, we'll need it. If we're given a
11433 compile_unit, then use the line header hash table if it's already
11434 created, but don't create one just yet. */
11436 if (dwarf2_per_objfile
->line_header_hash
== NULL
11437 && die
->tag
== DW_TAG_partial_unit
)
11439 dwarf2_per_objfile
->line_header_hash
11440 = htab_create_alloc_ex (127, line_header_hash_voidp
,
11441 line_header_eq_voidp
,
11442 free_line_header_voidp
,
11443 &objfile
->objfile_obstack
,
11444 hashtab_obstack_allocate
,
11445 dummy_obstack_deallocate
);
11448 line_header_local
.sect_off
= line_offset
;
11449 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
11450 line_header_local_hash
= line_header_hash (&line_header_local
);
11451 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
11453 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11454 &line_header_local
,
11455 line_header_local_hash
, NO_INSERT
);
11457 /* For DW_TAG_compile_unit we need info like symtab::linetable which
11458 is not present in *SLOT (since if there is something in *SLOT then
11459 it will be for a partial_unit). */
11460 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
11462 gdb_assert (*slot
!= NULL
);
11463 cu
->line_header
= (struct line_header
*) *slot
;
11468 /* dwarf_decode_line_header does not yet provide sufficient information.
11469 We always have to call also dwarf_decode_lines for it. */
11470 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
11474 cu
->line_header
= lh
.release ();
11475 cu
->line_header_die_owner
= die
;
11477 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
11481 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11482 &line_header_local
,
11483 line_header_local_hash
, INSERT
);
11484 gdb_assert (slot
!= NULL
);
11486 if (slot
!= NULL
&& *slot
== NULL
)
11488 /* This newly decoded line number information unit will be owned
11489 by line_header_hash hash table. */
11490 *slot
= cu
->line_header
;
11491 cu
->line_header_die_owner
= NULL
;
11495 /* We cannot free any current entry in (*slot) as that struct line_header
11496 may be already used by multiple CUs. Create only temporary decoded
11497 line_header for this CU - it may happen at most once for each line
11498 number information unit. And if we're not using line_header_hash
11499 then this is what we want as well. */
11500 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
11502 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
11503 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
11508 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
11511 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11513 struct dwarf2_per_objfile
*dwarf2_per_objfile
11514 = cu
->per_cu
->dwarf2_per_objfile
;
11515 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11516 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11517 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
11518 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
11519 struct attribute
*attr
;
11520 struct die_info
*child_die
;
11521 CORE_ADDR baseaddr
;
11523 prepare_one_comp_unit (cu
, die
, cu
->language
);
11524 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11526 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
11528 /* If we didn't find a lowpc, set it to highpc to avoid complaints
11529 from finish_block. */
11530 if (lowpc
== ((CORE_ADDR
) -1))
11532 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11534 file_and_directory fnd
= find_file_and_directory (die
, cu
);
11536 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
11537 standardised yet. As a workaround for the language detection we fall
11538 back to the DW_AT_producer string. */
11539 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
11540 cu
->language
= language_opencl
;
11542 /* Similar hack for Go. */
11543 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
11544 set_cu_language (DW_LANG_Go
, cu
);
11546 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
11548 /* Decode line number information if present. We do this before
11549 processing child DIEs, so that the line header table is available
11550 for DW_AT_decl_file. */
11551 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
11553 /* Process all dies in compilation unit. */
11554 if (die
->child
!= NULL
)
11556 child_die
= die
->child
;
11557 while (child_die
&& child_die
->tag
)
11559 process_die (child_die
, cu
);
11560 child_die
= sibling_die (child_die
);
11564 /* Decode macro information, if present. Dwarf 2 macro information
11565 refers to information in the line number info statement program
11566 header, so we can only read it if we've read the header
11568 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
11570 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
11571 if (attr
&& cu
->line_header
)
11573 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
11574 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
11576 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
11580 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
11581 if (attr
&& cu
->line_header
)
11583 unsigned int macro_offset
= DW_UNSND (attr
);
11585 dwarf_decode_macros (cu
, macro_offset
, 0);
11591 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
11593 struct type_unit_group
*tu_group
;
11595 struct attribute
*attr
;
11597 struct signatured_type
*sig_type
;
11599 gdb_assert (per_cu
->is_debug_types
);
11600 sig_type
= (struct signatured_type
*) per_cu
;
11602 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
11604 /* If we're using .gdb_index (includes -readnow) then
11605 per_cu->type_unit_group may not have been set up yet. */
11606 if (sig_type
->type_unit_group
== NULL
)
11607 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
11608 tu_group
= sig_type
->type_unit_group
;
11610 /* If we've already processed this stmt_list there's no real need to
11611 do it again, we could fake it and just recreate the part we need
11612 (file name,index -> symtab mapping). If data shows this optimization
11613 is useful we can do it then. */
11614 first_time
= tu_group
->compunit_symtab
== NULL
;
11616 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
11621 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11622 lh
= dwarf_decode_line_header (line_offset
, this);
11627 start_symtab ("", NULL
, 0);
11630 gdb_assert (tu_group
->symtabs
== NULL
);
11631 gdb_assert (m_builder
== nullptr);
11632 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
11633 m_builder
.reset (new struct buildsym_compunit
11634 (COMPUNIT_OBJFILE (cust
), "",
11635 COMPUNIT_DIRNAME (cust
),
11636 compunit_language (cust
),
11642 line_header
= lh
.release ();
11643 line_header_die_owner
= die
;
11647 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
11649 /* Note: We don't assign tu_group->compunit_symtab yet because we're
11650 still initializing it, and our caller (a few levels up)
11651 process_full_type_unit still needs to know if this is the first
11654 tu_group
->num_symtabs
= line_header
->file_names
.size ();
11655 tu_group
->symtabs
= XNEWVEC (struct symtab
*,
11656 line_header
->file_names
.size ());
11658 for (i
= 0; i
< line_header
->file_names
.size (); ++i
)
11660 file_entry
&fe
= line_header
->file_names
[i
];
11662 dwarf2_start_subfile (this, fe
.name
,
11663 fe
.include_dir (line_header
));
11664 buildsym_compunit
*b
= get_builder ();
11665 if (b
->get_current_subfile ()->symtab
== NULL
)
11667 /* NOTE: start_subfile will recognize when it's been
11668 passed a file it has already seen. So we can't
11669 assume there's a simple mapping from
11670 cu->line_header->file_names to subfiles, plus
11671 cu->line_header->file_names may contain dups. */
11672 b
->get_current_subfile ()->symtab
11673 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
11676 fe
.symtab
= b
->get_current_subfile ()->symtab
;
11677 tu_group
->symtabs
[i
] = fe
.symtab
;
11682 gdb_assert (m_builder
== nullptr);
11683 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
11684 m_builder
.reset (new struct buildsym_compunit
11685 (COMPUNIT_OBJFILE (cust
), "",
11686 COMPUNIT_DIRNAME (cust
),
11687 compunit_language (cust
),
11690 for (i
= 0; i
< line_header
->file_names
.size (); ++i
)
11692 file_entry
&fe
= line_header
->file_names
[i
];
11694 fe
.symtab
= tu_group
->symtabs
[i
];
11698 /* The main symtab is allocated last. Type units don't have DW_AT_name
11699 so they don't have a "real" (so to speak) symtab anyway.
11700 There is later code that will assign the main symtab to all symbols
11701 that don't have one. We need to handle the case of a symbol with a
11702 missing symtab (DW_AT_decl_file) anyway. */
11705 /* Process DW_TAG_type_unit.
11706 For TUs we want to skip the first top level sibling if it's not the
11707 actual type being defined by this TU. In this case the first top
11708 level sibling is there to provide context only. */
11711 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11713 struct die_info
*child_die
;
11715 prepare_one_comp_unit (cu
, die
, language_minimal
);
11717 /* Initialize (or reinitialize) the machinery for building symtabs.
11718 We do this before processing child DIEs, so that the line header table
11719 is available for DW_AT_decl_file. */
11720 cu
->setup_type_unit_groups (die
);
11722 if (die
->child
!= NULL
)
11724 child_die
= die
->child
;
11725 while (child_die
&& child_die
->tag
)
11727 process_die (child_die
, cu
);
11728 child_die
= sibling_die (child_die
);
11735 http://gcc.gnu.org/wiki/DebugFission
11736 http://gcc.gnu.org/wiki/DebugFissionDWP
11738 To simplify handling of both DWO files ("object" files with the DWARF info)
11739 and DWP files (a file with the DWOs packaged up into one file), we treat
11740 DWP files as having a collection of virtual DWO files. */
11743 hash_dwo_file (const void *item
)
11745 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11748 hash
= htab_hash_string (dwo_file
->dwo_name
);
11749 if (dwo_file
->comp_dir
!= NULL
)
11750 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11755 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11757 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11758 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11760 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11762 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11763 return lhs
->comp_dir
== rhs
->comp_dir
;
11764 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11767 /* Allocate a hash table for DWO files. */
11770 allocate_dwo_file_hash_table (struct objfile
*objfile
)
11772 auto delete_dwo_file
= [] (void *item
)
11774 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
11779 return htab_up (htab_create_alloc_ex (41,
11783 &objfile
->objfile_obstack
,
11784 hashtab_obstack_allocate
,
11785 dummy_obstack_deallocate
));
11788 /* Lookup DWO file DWO_NAME. */
11791 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11792 const char *dwo_name
,
11793 const char *comp_dir
)
11795 struct dwo_file find_entry
;
11798 if (dwarf2_per_objfile
->dwo_files
== NULL
)
11799 dwarf2_per_objfile
->dwo_files
11800 = allocate_dwo_file_hash_table (dwarf2_per_objfile
->objfile
);
11802 find_entry
.dwo_name
= dwo_name
;
11803 find_entry
.comp_dir
= comp_dir
;
11804 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
.get (), &find_entry
,
11811 hash_dwo_unit (const void *item
)
11813 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11815 /* This drops the top 32 bits of the id, but is ok for a hash. */
11816 return dwo_unit
->signature
;
11820 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11822 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11823 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11825 /* The signature is assumed to be unique within the DWO file.
11826 So while object file CU dwo_id's always have the value zero,
11827 that's OK, assuming each object file DWO file has only one CU,
11828 and that's the rule for now. */
11829 return lhs
->signature
== rhs
->signature
;
11832 /* Allocate a hash table for DWO CUs,TUs.
11833 There is one of these tables for each of CUs,TUs for each DWO file. */
11836 allocate_dwo_unit_table (struct objfile
*objfile
)
11838 /* Start out with a pretty small number.
11839 Generally DWO files contain only one CU and maybe some TUs. */
11840 return htab_create_alloc_ex (3,
11844 &objfile
->objfile_obstack
,
11845 hashtab_obstack_allocate
,
11846 dummy_obstack_deallocate
);
11849 /* Structure used to pass data to create_dwo_debug_info_hash_table_reader. */
11851 struct create_dwo_cu_data
11853 struct dwo_file
*dwo_file
;
11854 struct dwo_unit dwo_unit
;
11857 /* die_reader_func for create_dwo_cu. */
11860 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11861 const gdb_byte
*info_ptr
,
11862 struct die_info
*comp_unit_die
,
11866 struct dwarf2_cu
*cu
= reader
->cu
;
11867 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11868 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11869 struct create_dwo_cu_data
*data
= (struct create_dwo_cu_data
*) datap
;
11870 struct dwo_file
*dwo_file
= data
->dwo_file
;
11871 struct dwo_unit
*dwo_unit
= &data
->dwo_unit
;
11873 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11874 if (!signature
.has_value ())
11876 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11877 " its dwo_id [in module %s]"),
11878 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11882 dwo_unit
->dwo_file
= dwo_file
;
11883 dwo_unit
->signature
= *signature
;
11884 dwo_unit
->section
= section
;
11885 dwo_unit
->sect_off
= sect_off
;
11886 dwo_unit
->length
= cu
->per_cu
->length
;
11888 if (dwarf_read_debug
)
11889 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11890 sect_offset_str (sect_off
),
11891 hex_string (dwo_unit
->signature
));
11894 /* Create the dwo_units for the CUs in a DWO_FILE.
11895 Note: This function processes DWO files only, not DWP files. */
11898 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11899 struct dwo_file
&dwo_file
, dwarf2_section_info
§ion
,
11902 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11903 const gdb_byte
*info_ptr
, *end_ptr
;
11905 dwarf2_read_section (objfile
, §ion
);
11906 info_ptr
= section
.buffer
;
11908 if (info_ptr
== NULL
)
11911 if (dwarf_read_debug
)
11913 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11914 get_section_name (§ion
),
11915 get_section_file_name (§ion
));
11918 end_ptr
= info_ptr
+ section
.size
;
11919 while (info_ptr
< end_ptr
)
11921 struct dwarf2_per_cu_data per_cu
;
11922 struct create_dwo_cu_data create_dwo_cu_data
;
11923 struct dwo_unit
*dwo_unit
;
11925 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11927 memset (&create_dwo_cu_data
.dwo_unit
, 0,
11928 sizeof (create_dwo_cu_data
.dwo_unit
));
11929 memset (&per_cu
, 0, sizeof (per_cu
));
11930 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
11931 per_cu
.is_debug_types
= 0;
11932 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11933 per_cu
.section
= §ion
;
11934 create_dwo_cu_data
.dwo_file
= &dwo_file
;
11936 init_cutu_and_read_dies_no_follow (
11937 &per_cu
, &dwo_file
, create_dwo_cu_reader
, &create_dwo_cu_data
);
11938 info_ptr
+= per_cu
.length
;
11940 // If the unit could not be parsed, skip it.
11941 if (create_dwo_cu_data
.dwo_unit
.dwo_file
== NULL
)
11944 if (cus_htab
== NULL
)
11945 cus_htab
= allocate_dwo_unit_table (objfile
);
11947 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11948 *dwo_unit
= create_dwo_cu_data
.dwo_unit
;
11949 slot
= htab_find_slot (cus_htab
, dwo_unit
, INSERT
);
11950 gdb_assert (slot
!= NULL
);
11953 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11954 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11956 complaint (_("debug cu entry at offset %s is duplicate to"
11957 " the entry at offset %s, signature %s"),
11958 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11959 hex_string (dwo_unit
->signature
));
11961 *slot
= (void *)dwo_unit
;
11965 /* DWP file .debug_{cu,tu}_index section format:
11966 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11970 Both index sections have the same format, and serve to map a 64-bit
11971 signature to a set of section numbers. Each section begins with a header,
11972 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11973 indexes, and a pool of 32-bit section numbers. The index sections will be
11974 aligned at 8-byte boundaries in the file.
11976 The index section header consists of:
11978 V, 32 bit version number
11980 N, 32 bit number of compilation units or type units in the index
11981 M, 32 bit number of slots in the hash table
11983 Numbers are recorded using the byte order of the application binary.
11985 The hash table begins at offset 16 in the section, and consists of an array
11986 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11987 order of the application binary). Unused slots in the hash table are 0.
11988 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11990 The parallel table begins immediately after the hash table
11991 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11992 array of 32-bit indexes (using the byte order of the application binary),
11993 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11994 table contains a 32-bit index into the pool of section numbers. For unused
11995 hash table slots, the corresponding entry in the parallel table will be 0.
11997 The pool of section numbers begins immediately following the hash table
11998 (at offset 16 + 12 * M from the beginning of the section). The pool of
11999 section numbers consists of an array of 32-bit words (using the byte order
12000 of the application binary). Each item in the array is indexed starting
12001 from 0. The hash table entry provides the index of the first section
12002 number in the set. Additional section numbers in the set follow, and the
12003 set is terminated by a 0 entry (section number 0 is not used in ELF).
12005 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
12006 section must be the first entry in the set, and the .debug_abbrev.dwo must
12007 be the second entry. Other members of the set may follow in any order.
12013 DWP Version 2 combines all the .debug_info, etc. sections into one,
12014 and the entries in the index tables are now offsets into these sections.
12015 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
12018 Index Section Contents:
12020 Hash Table of Signatures dwp_hash_table.hash_table
12021 Parallel Table of Indices dwp_hash_table.unit_table
12022 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
12023 Table of Section Sizes dwp_hash_table.v2.sizes
12025 The index section header consists of:
12027 V, 32 bit version number
12028 L, 32 bit number of columns in the table of section offsets
12029 N, 32 bit number of compilation units or type units in the index
12030 M, 32 bit number of slots in the hash table
12032 Numbers are recorded using the byte order of the application binary.
12034 The hash table has the same format as version 1.
12035 The parallel table of indices has the same format as version 1,
12036 except that the entries are origin-1 indices into the table of sections
12037 offsets and the table of section sizes.
12039 The table of offsets begins immediately following the parallel table
12040 (at offset 16 + 12 * M from the beginning of the section). The table is
12041 a two-dimensional array of 32-bit words (using the byte order of the
12042 application binary), with L columns and N+1 rows, in row-major order.
12043 Each row in the array is indexed starting from 0. The first row provides
12044 a key to the remaining rows: each column in this row provides an identifier
12045 for a debug section, and the offsets in the same column of subsequent rows
12046 refer to that section. The section identifiers are:
12048 DW_SECT_INFO 1 .debug_info.dwo
12049 DW_SECT_TYPES 2 .debug_types.dwo
12050 DW_SECT_ABBREV 3 .debug_abbrev.dwo
12051 DW_SECT_LINE 4 .debug_line.dwo
12052 DW_SECT_LOC 5 .debug_loc.dwo
12053 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
12054 DW_SECT_MACINFO 7 .debug_macinfo.dwo
12055 DW_SECT_MACRO 8 .debug_macro.dwo
12057 The offsets provided by the CU and TU index sections are the base offsets
12058 for the contributions made by each CU or TU to the corresponding section
12059 in the package file. Each CU and TU header contains an abbrev_offset
12060 field, used to find the abbreviations table for that CU or TU within the
12061 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
12062 be interpreted as relative to the base offset given in the index section.
12063 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
12064 should be interpreted as relative to the base offset for .debug_line.dwo,
12065 and offsets into other debug sections obtained from DWARF attributes should
12066 also be interpreted as relative to the corresponding base offset.
12068 The table of sizes begins immediately following the table of offsets.
12069 Like the table of offsets, it is a two-dimensional array of 32-bit words,
12070 with L columns and N rows, in row-major order. Each row in the array is
12071 indexed starting from 1 (row 0 is shared by the two tables).
12075 Hash table lookup is handled the same in version 1 and 2:
12077 We assume that N and M will not exceed 2^32 - 1.
12078 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
12080 Given a 64-bit compilation unit signature or a type signature S, an entry
12081 in the hash table is located as follows:
12083 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
12084 the low-order k bits all set to 1.
12086 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
12088 3) If the hash table entry at index H matches the signature, use that
12089 entry. If the hash table entry at index H is unused (all zeroes),
12090 terminate the search: the signature is not present in the table.
12092 4) Let H = (H + H') modulo M. Repeat at Step 3.
12094 Because M > N and H' and M are relatively prime, the search is guaranteed
12095 to stop at an unused slot or find the match. */
12097 /* Create a hash table to map DWO IDs to their CU/TU entry in
12098 .debug_{info,types}.dwo in DWP_FILE.
12099 Returns NULL if there isn't one.
12100 Note: This function processes DWP files only, not DWO files. */
12102 static struct dwp_hash_table
*
12103 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12104 struct dwp_file
*dwp_file
, int is_debug_types
)
12106 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12107 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12108 const gdb_byte
*index_ptr
, *index_end
;
12109 struct dwarf2_section_info
*index
;
12110 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
12111 struct dwp_hash_table
*htab
;
12113 if (is_debug_types
)
12114 index
= &dwp_file
->sections
.tu_index
;
12116 index
= &dwp_file
->sections
.cu_index
;
12118 if (dwarf2_section_empty_p (index
))
12120 dwarf2_read_section (objfile
, index
);
12122 index_ptr
= index
->buffer
;
12123 index_end
= index_ptr
+ index
->size
;
12125 version
= read_4_bytes (dbfd
, index_ptr
);
12128 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
12132 nr_units
= read_4_bytes (dbfd
, index_ptr
);
12134 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
12137 if (version
!= 1 && version
!= 2)
12139 error (_("Dwarf Error: unsupported DWP file version (%s)"
12140 " [in module %s]"),
12141 pulongest (version
), dwp_file
->name
);
12143 if (nr_slots
!= (nr_slots
& -nr_slots
))
12145 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
12146 " is not power of 2 [in module %s]"),
12147 pulongest (nr_slots
), dwp_file
->name
);
12150 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
12151 htab
->version
= version
;
12152 htab
->nr_columns
= nr_columns
;
12153 htab
->nr_units
= nr_units
;
12154 htab
->nr_slots
= nr_slots
;
12155 htab
->hash_table
= index_ptr
;
12156 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
12158 /* Exit early if the table is empty. */
12159 if (nr_slots
== 0 || nr_units
== 0
12160 || (version
== 2 && nr_columns
== 0))
12162 /* All must be zero. */
12163 if (nr_slots
!= 0 || nr_units
!= 0
12164 || (version
== 2 && nr_columns
!= 0))
12166 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
12167 " all zero [in modules %s]"),
12175 htab
->section_pool
.v1
.indices
=
12176 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12177 /* It's harder to decide whether the section is too small in v1.
12178 V1 is deprecated anyway so we punt. */
12182 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12183 int *ids
= htab
->section_pool
.v2
.section_ids
;
12184 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
12185 /* Reverse map for error checking. */
12186 int ids_seen
[DW_SECT_MAX
+ 1];
12189 if (nr_columns
< 2)
12191 error (_("Dwarf Error: bad DWP hash table, too few columns"
12192 " in section table [in module %s]"),
12195 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
12197 error (_("Dwarf Error: bad DWP hash table, too many columns"
12198 " in section table [in module %s]"),
12201 memset (ids
, 255, sizeof_ids
);
12202 memset (ids_seen
, 255, sizeof (ids_seen
));
12203 for (i
= 0; i
< nr_columns
; ++i
)
12205 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
12207 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
12209 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
12210 " in section table [in module %s]"),
12211 id
, dwp_file
->name
);
12213 if (ids_seen
[id
] != -1)
12215 error (_("Dwarf Error: bad DWP hash table, duplicate section"
12216 " id %d in section table [in module %s]"),
12217 id
, dwp_file
->name
);
12222 /* Must have exactly one info or types section. */
12223 if (((ids_seen
[DW_SECT_INFO
] != -1)
12224 + (ids_seen
[DW_SECT_TYPES
] != -1))
12227 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
12228 " DWO info/types section [in module %s]"),
12231 /* Must have an abbrev section. */
12232 if (ids_seen
[DW_SECT_ABBREV
] == -1)
12234 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
12235 " section [in module %s]"),
12238 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
12239 htab
->section_pool
.v2
.sizes
=
12240 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
12241 * nr_units
* nr_columns
);
12242 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
12243 * nr_units
* nr_columns
))
12246 error (_("Dwarf Error: DWP index section is corrupt (too small)"
12247 " [in module %s]"),
12255 /* Update SECTIONS with the data from SECTP.
12257 This function is like the other "locate" section routines that are
12258 passed to bfd_map_over_sections, but in this context the sections to
12259 read comes from the DWP V1 hash table, not the full ELF section table.
12261 The result is non-zero for success, or zero if an error was found. */
12264 locate_v1_virtual_dwo_sections (asection
*sectp
,
12265 struct virtual_v1_dwo_sections
*sections
)
12267 const struct dwop_section_names
*names
= &dwop_section_names
;
12269 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12271 /* There can be only one. */
12272 if (sections
->abbrev
.s
.section
!= NULL
)
12274 sections
->abbrev
.s
.section
= sectp
;
12275 sections
->abbrev
.size
= bfd_get_section_size (sectp
);
12277 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
12278 || section_is_p (sectp
->name
, &names
->types_dwo
))
12280 /* There can be only one. */
12281 if (sections
->info_or_types
.s
.section
!= NULL
)
12283 sections
->info_or_types
.s
.section
= sectp
;
12284 sections
->info_or_types
.size
= bfd_get_section_size (sectp
);
12286 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12288 /* There can be only one. */
12289 if (sections
->line
.s
.section
!= NULL
)
12291 sections
->line
.s
.section
= sectp
;
12292 sections
->line
.size
= bfd_get_section_size (sectp
);
12294 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12296 /* There can be only one. */
12297 if (sections
->loc
.s
.section
!= NULL
)
12299 sections
->loc
.s
.section
= sectp
;
12300 sections
->loc
.size
= bfd_get_section_size (sectp
);
12302 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12304 /* There can be only one. */
12305 if (sections
->macinfo
.s
.section
!= NULL
)
12307 sections
->macinfo
.s
.section
= sectp
;
12308 sections
->macinfo
.size
= bfd_get_section_size (sectp
);
12310 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12312 /* There can be only one. */
12313 if (sections
->macro
.s
.section
!= NULL
)
12315 sections
->macro
.s
.section
= sectp
;
12316 sections
->macro
.size
= bfd_get_section_size (sectp
);
12318 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12320 /* There can be only one. */
12321 if (sections
->str_offsets
.s
.section
!= NULL
)
12323 sections
->str_offsets
.s
.section
= sectp
;
12324 sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
12328 /* No other kind of section is valid. */
12335 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12336 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12337 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12338 This is for DWP version 1 files. */
12340 static struct dwo_unit
*
12341 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12342 struct dwp_file
*dwp_file
,
12343 uint32_t unit_index
,
12344 const char *comp_dir
,
12345 ULONGEST signature
, int is_debug_types
)
12347 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12348 const struct dwp_hash_table
*dwp_htab
=
12349 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12350 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12351 const char *kind
= is_debug_types
? "TU" : "CU";
12352 struct dwo_file
*dwo_file
;
12353 struct dwo_unit
*dwo_unit
;
12354 struct virtual_v1_dwo_sections sections
;
12355 void **dwo_file_slot
;
12358 gdb_assert (dwp_file
->version
== 1);
12360 if (dwarf_read_debug
)
12362 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
12364 pulongest (unit_index
), hex_string (signature
),
12368 /* Fetch the sections of this DWO unit.
12369 Put a limit on the number of sections we look for so that bad data
12370 doesn't cause us to loop forever. */
12372 #define MAX_NR_V1_DWO_SECTIONS \
12373 (1 /* .debug_info or .debug_types */ \
12374 + 1 /* .debug_abbrev */ \
12375 + 1 /* .debug_line */ \
12376 + 1 /* .debug_loc */ \
12377 + 1 /* .debug_str_offsets */ \
12378 + 1 /* .debug_macro or .debug_macinfo */ \
12379 + 1 /* trailing zero */)
12381 memset (§ions
, 0, sizeof (sections
));
12383 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
12386 uint32_t section_nr
=
12387 read_4_bytes (dbfd
,
12388 dwp_htab
->section_pool
.v1
.indices
12389 + (unit_index
+ i
) * sizeof (uint32_t));
12391 if (section_nr
== 0)
12393 if (section_nr
>= dwp_file
->num_sections
)
12395 error (_("Dwarf Error: bad DWP hash table, section number too large"
12396 " [in module %s]"),
12400 sectp
= dwp_file
->elf_sections
[section_nr
];
12401 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
12403 error (_("Dwarf Error: bad DWP hash table, invalid section found"
12404 " [in module %s]"),
12410 || dwarf2_section_empty_p (§ions
.info_or_types
)
12411 || dwarf2_section_empty_p (§ions
.abbrev
))
12413 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
12414 " [in module %s]"),
12417 if (i
== MAX_NR_V1_DWO_SECTIONS
)
12419 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
12420 " [in module %s]"),
12424 /* It's easier for the rest of the code if we fake a struct dwo_file and
12425 have dwo_unit "live" in that. At least for now.
12427 The DWP file can be made up of a random collection of CUs and TUs.
12428 However, for each CU + set of TUs that came from the same original DWO
12429 file, we can combine them back into a virtual DWO file to save space
12430 (fewer struct dwo_file objects to allocate). Remember that for really
12431 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12433 std::string virtual_dwo_name
=
12434 string_printf ("virtual-dwo/%d-%d-%d-%d",
12435 get_section_id (§ions
.abbrev
),
12436 get_section_id (§ions
.line
),
12437 get_section_id (§ions
.loc
),
12438 get_section_id (§ions
.str_offsets
));
12439 /* Can we use an existing virtual DWO file? */
12440 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12441 virtual_dwo_name
.c_str (),
12443 /* Create one if necessary. */
12444 if (*dwo_file_slot
== NULL
)
12446 if (dwarf_read_debug
)
12448 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12449 virtual_dwo_name
.c_str ());
12451 dwo_file
= new struct dwo_file
;
12452 dwo_file
->dwo_name
= obstack_strdup (&objfile
->objfile_obstack
,
12454 dwo_file
->comp_dir
= comp_dir
;
12455 dwo_file
->sections
.abbrev
= sections
.abbrev
;
12456 dwo_file
->sections
.line
= sections
.line
;
12457 dwo_file
->sections
.loc
= sections
.loc
;
12458 dwo_file
->sections
.macinfo
= sections
.macinfo
;
12459 dwo_file
->sections
.macro
= sections
.macro
;
12460 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
12461 /* The "str" section is global to the entire DWP file. */
12462 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12463 /* The info or types section is assigned below to dwo_unit,
12464 there's no need to record it in dwo_file.
12465 Also, we can't simply record type sections in dwo_file because
12466 we record a pointer into the vector in dwo_unit. As we collect more
12467 types we'll grow the vector and eventually have to reallocate space
12468 for it, invalidating all copies of pointers into the previous
12470 *dwo_file_slot
= dwo_file
;
12474 if (dwarf_read_debug
)
12476 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12477 virtual_dwo_name
.c_str ());
12479 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12482 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12483 dwo_unit
->dwo_file
= dwo_file
;
12484 dwo_unit
->signature
= signature
;
12485 dwo_unit
->section
=
12486 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12487 *dwo_unit
->section
= sections
.info_or_types
;
12488 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12493 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
12494 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
12495 piece within that section used by a TU/CU, return a virtual section
12496 of just that piece. */
12498 static struct dwarf2_section_info
12499 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12500 struct dwarf2_section_info
*section
,
12501 bfd_size_type offset
, bfd_size_type size
)
12503 struct dwarf2_section_info result
;
12506 gdb_assert (section
!= NULL
);
12507 gdb_assert (!section
->is_virtual
);
12509 memset (&result
, 0, sizeof (result
));
12510 result
.s
.containing_section
= section
;
12511 result
.is_virtual
= true;
12516 sectp
= get_section_bfd_section (section
);
12518 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
12519 bounds of the real section. This is a pretty-rare event, so just
12520 flag an error (easier) instead of a warning and trying to cope. */
12522 || offset
+ size
> bfd_get_section_size (sectp
))
12524 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
12525 " in section %s [in module %s]"),
12526 sectp
? bfd_section_name (abfd
, sectp
) : "<unknown>",
12527 objfile_name (dwarf2_per_objfile
->objfile
));
12530 result
.virtual_offset
= offset
;
12531 result
.size
= size
;
12535 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12536 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12537 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12538 This is for DWP version 2 files. */
12540 static struct dwo_unit
*
12541 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12542 struct dwp_file
*dwp_file
,
12543 uint32_t unit_index
,
12544 const char *comp_dir
,
12545 ULONGEST signature
, int is_debug_types
)
12547 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12548 const struct dwp_hash_table
*dwp_htab
=
12549 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12550 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12551 const char *kind
= is_debug_types
? "TU" : "CU";
12552 struct dwo_file
*dwo_file
;
12553 struct dwo_unit
*dwo_unit
;
12554 struct virtual_v2_dwo_sections sections
;
12555 void **dwo_file_slot
;
12558 gdb_assert (dwp_file
->version
== 2);
12560 if (dwarf_read_debug
)
12562 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
12564 pulongest (unit_index
), hex_string (signature
),
12568 /* Fetch the section offsets of this DWO unit. */
12570 memset (§ions
, 0, sizeof (sections
));
12572 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12574 uint32_t offset
= read_4_bytes (dbfd
,
12575 dwp_htab
->section_pool
.v2
.offsets
12576 + (((unit_index
- 1) * dwp_htab
->nr_columns
12578 * sizeof (uint32_t)));
12579 uint32_t size
= read_4_bytes (dbfd
,
12580 dwp_htab
->section_pool
.v2
.sizes
12581 + (((unit_index
- 1) * dwp_htab
->nr_columns
12583 * sizeof (uint32_t)));
12585 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
12588 case DW_SECT_TYPES
:
12589 sections
.info_or_types_offset
= offset
;
12590 sections
.info_or_types_size
= size
;
12592 case DW_SECT_ABBREV
:
12593 sections
.abbrev_offset
= offset
;
12594 sections
.abbrev_size
= size
;
12597 sections
.line_offset
= offset
;
12598 sections
.line_size
= size
;
12601 sections
.loc_offset
= offset
;
12602 sections
.loc_size
= size
;
12604 case DW_SECT_STR_OFFSETS
:
12605 sections
.str_offsets_offset
= offset
;
12606 sections
.str_offsets_size
= size
;
12608 case DW_SECT_MACINFO
:
12609 sections
.macinfo_offset
= offset
;
12610 sections
.macinfo_size
= size
;
12612 case DW_SECT_MACRO
:
12613 sections
.macro_offset
= offset
;
12614 sections
.macro_size
= size
;
12619 /* It's easier for the rest of the code if we fake a struct dwo_file and
12620 have dwo_unit "live" in that. At least for now.
12622 The DWP file can be made up of a random collection of CUs and TUs.
12623 However, for each CU + set of TUs that came from the same original DWO
12624 file, we can combine them back into a virtual DWO file to save space
12625 (fewer struct dwo_file objects to allocate). Remember that for really
12626 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12628 std::string virtual_dwo_name
=
12629 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
12630 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12631 (long) (sections
.line_size
? sections
.line_offset
: 0),
12632 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
12633 (long) (sections
.str_offsets_size
12634 ? sections
.str_offsets_offset
: 0));
12635 /* Can we use an existing virtual DWO file? */
12636 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12637 virtual_dwo_name
.c_str (),
12639 /* Create one if necessary. */
12640 if (*dwo_file_slot
== NULL
)
12642 if (dwarf_read_debug
)
12644 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12645 virtual_dwo_name
.c_str ());
12647 dwo_file
= new struct dwo_file
;
12648 dwo_file
->dwo_name
= obstack_strdup (&objfile
->objfile_obstack
,
12650 dwo_file
->comp_dir
= comp_dir
;
12651 dwo_file
->sections
.abbrev
=
12652 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
12653 sections
.abbrev_offset
, sections
.abbrev_size
);
12654 dwo_file
->sections
.line
=
12655 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
12656 sections
.line_offset
, sections
.line_size
);
12657 dwo_file
->sections
.loc
=
12658 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
12659 sections
.loc_offset
, sections
.loc_size
);
12660 dwo_file
->sections
.macinfo
=
12661 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
12662 sections
.macinfo_offset
, sections
.macinfo_size
);
12663 dwo_file
->sections
.macro
=
12664 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
12665 sections
.macro_offset
, sections
.macro_size
);
12666 dwo_file
->sections
.str_offsets
=
12667 create_dwp_v2_section (dwarf2_per_objfile
,
12668 &dwp_file
->sections
.str_offsets
,
12669 sections
.str_offsets_offset
,
12670 sections
.str_offsets_size
);
12671 /* The "str" section is global to the entire DWP file. */
12672 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12673 /* The info or types section is assigned below to dwo_unit,
12674 there's no need to record it in dwo_file.
12675 Also, we can't simply record type sections in dwo_file because
12676 we record a pointer into the vector in dwo_unit. As we collect more
12677 types we'll grow the vector and eventually have to reallocate space
12678 for it, invalidating all copies of pointers into the previous
12680 *dwo_file_slot
= dwo_file
;
12684 if (dwarf_read_debug
)
12686 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12687 virtual_dwo_name
.c_str ());
12689 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12692 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12693 dwo_unit
->dwo_file
= dwo_file
;
12694 dwo_unit
->signature
= signature
;
12695 dwo_unit
->section
=
12696 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12697 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
12699 ? &dwp_file
->sections
.types
12700 : &dwp_file
->sections
.info
,
12701 sections
.info_or_types_offset
,
12702 sections
.info_or_types_size
);
12703 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12708 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12709 Returns NULL if the signature isn't found. */
12711 static struct dwo_unit
*
12712 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12713 struct dwp_file
*dwp_file
, const char *comp_dir
,
12714 ULONGEST signature
, int is_debug_types
)
12716 const struct dwp_hash_table
*dwp_htab
=
12717 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12718 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12719 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12720 uint32_t hash
= signature
& mask
;
12721 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12724 struct dwo_unit find_dwo_cu
;
12726 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12727 find_dwo_cu
.signature
= signature
;
12728 slot
= htab_find_slot (is_debug_types
12729 ? dwp_file
->loaded_tus
12730 : dwp_file
->loaded_cus
,
12731 &find_dwo_cu
, INSERT
);
12734 return (struct dwo_unit
*) *slot
;
12736 /* Use a for loop so that we don't loop forever on bad debug info. */
12737 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12739 ULONGEST signature_in_table
;
12741 signature_in_table
=
12742 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12743 if (signature_in_table
== signature
)
12745 uint32_t unit_index
=
12746 read_4_bytes (dbfd
,
12747 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12749 if (dwp_file
->version
== 1)
12751 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
12752 dwp_file
, unit_index
,
12753 comp_dir
, signature
,
12758 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
12759 dwp_file
, unit_index
,
12760 comp_dir
, signature
,
12763 return (struct dwo_unit
*) *slot
;
12765 if (signature_in_table
== 0)
12767 hash
= (hash
+ hash2
) & mask
;
12770 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12771 " [in module %s]"),
12775 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12776 Open the file specified by FILE_NAME and hand it off to BFD for
12777 preliminary analysis. Return a newly initialized bfd *, which
12778 includes a canonicalized copy of FILE_NAME.
12779 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12780 SEARCH_CWD is true if the current directory is to be searched.
12781 It will be searched before debug-file-directory.
12782 If successful, the file is added to the bfd include table of the
12783 objfile's bfd (see gdb_bfd_record_inclusion).
12784 If unable to find/open the file, return NULL.
12785 NOTE: This function is derived from symfile_bfd_open. */
12787 static gdb_bfd_ref_ptr
12788 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12789 const char *file_name
, int is_dwp
, int search_cwd
)
12792 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12793 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12794 to debug_file_directory. */
12795 const char *search_path
;
12796 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12798 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12801 if (*debug_file_directory
!= '\0')
12803 search_path_holder
.reset (concat (".", dirname_separator_string
,
12804 debug_file_directory
,
12806 search_path
= search_path_holder
.get ();
12812 search_path
= debug_file_directory
;
12814 openp_flags flags
= OPF_RETURN_REALPATH
;
12816 flags
|= OPF_SEARCH_IN_PATH
;
12818 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12819 desc
= openp (search_path
, flags
, file_name
,
12820 O_RDONLY
| O_BINARY
, &absolute_name
);
12824 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12826 if (sym_bfd
== NULL
)
12828 bfd_set_cacheable (sym_bfd
.get (), 1);
12830 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12833 /* Success. Record the bfd as having been included by the objfile's bfd.
12834 This is important because things like demangled_names_hash lives in the
12835 objfile's per_bfd space and may have references to things like symbol
12836 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12837 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12842 /* Try to open DWO file FILE_NAME.
12843 COMP_DIR is the DW_AT_comp_dir attribute.
12844 The result is the bfd handle of the file.
12845 If there is a problem finding or opening the file, return NULL.
12846 Upon success, the canonicalized path of the file is stored in the bfd,
12847 same as symfile_bfd_open. */
12849 static gdb_bfd_ref_ptr
12850 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12851 const char *file_name
, const char *comp_dir
)
12853 if (IS_ABSOLUTE_PATH (file_name
))
12854 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12855 0 /*is_dwp*/, 0 /*search_cwd*/);
12857 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12859 if (comp_dir
!= NULL
)
12861 char *path_to_try
= concat (comp_dir
, SLASH_STRING
,
12862 file_name
, (char *) NULL
);
12864 /* NOTE: If comp_dir is a relative path, this will also try the
12865 search path, which seems useful. */
12866 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
12869 1 /*search_cwd*/));
12870 xfree (path_to_try
);
12875 /* That didn't work, try debug-file-directory, which, despite its name,
12876 is a list of paths. */
12878 if (*debug_file_directory
== '\0')
12881 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12882 0 /*is_dwp*/, 1 /*search_cwd*/);
12885 /* This function is mapped across the sections and remembers the offset and
12886 size of each of the DWO debugging sections we are interested in. */
12889 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12891 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12892 const struct dwop_section_names
*names
= &dwop_section_names
;
12894 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12896 dwo_sections
->abbrev
.s
.section
= sectp
;
12897 dwo_sections
->abbrev
.size
= bfd_get_section_size (sectp
);
12899 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12901 dwo_sections
->info
.s
.section
= sectp
;
12902 dwo_sections
->info
.size
= bfd_get_section_size (sectp
);
12904 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12906 dwo_sections
->line
.s
.section
= sectp
;
12907 dwo_sections
->line
.size
= bfd_get_section_size (sectp
);
12909 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12911 dwo_sections
->loc
.s
.section
= sectp
;
12912 dwo_sections
->loc
.size
= bfd_get_section_size (sectp
);
12914 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12916 dwo_sections
->macinfo
.s
.section
= sectp
;
12917 dwo_sections
->macinfo
.size
= bfd_get_section_size (sectp
);
12919 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12921 dwo_sections
->macro
.s
.section
= sectp
;
12922 dwo_sections
->macro
.size
= bfd_get_section_size (sectp
);
12924 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12926 dwo_sections
->str
.s
.section
= sectp
;
12927 dwo_sections
->str
.size
= bfd_get_section_size (sectp
);
12929 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12931 dwo_sections
->str_offsets
.s
.section
= sectp
;
12932 dwo_sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
12934 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12936 struct dwarf2_section_info type_section
;
12938 memset (&type_section
, 0, sizeof (type_section
));
12939 type_section
.s
.section
= sectp
;
12940 type_section
.size
= bfd_get_section_size (sectp
);
12941 dwo_sections
->types
.push_back (type_section
);
12945 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12946 by PER_CU. This is for the non-DWP case.
12947 The result is NULL if DWO_NAME can't be found. */
12949 static struct dwo_file
*
12950 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
12951 const char *dwo_name
, const char *comp_dir
)
12953 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
12955 gdb_bfd_ref_ptr dbfd
= open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
);
12958 if (dwarf_read_debug
)
12959 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
12963 dwo_file_up
dwo_file (new struct dwo_file
);
12964 dwo_file
->dwo_name
= dwo_name
;
12965 dwo_file
->comp_dir
= comp_dir
;
12966 dwo_file
->dbfd
= std::move (dbfd
);
12968 bfd_map_over_sections (dwo_file
->dbfd
.get (), dwarf2_locate_dwo_sections
,
12969 &dwo_file
->sections
);
12971 create_cus_hash_table (dwarf2_per_objfile
, *dwo_file
, dwo_file
->sections
.info
,
12974 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
.get (),
12975 dwo_file
->sections
.types
, dwo_file
->tus
);
12977 if (dwarf_read_debug
)
12978 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
12980 return dwo_file
.release ();
12983 /* This function is mapped across the sections and remembers the offset and
12984 size of each of the DWP debugging sections common to version 1 and 2 that
12985 we are interested in. */
12988 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12989 void *dwp_file_ptr
)
12991 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12992 const struct dwop_section_names
*names
= &dwop_section_names
;
12993 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12995 /* Record the ELF section number for later lookup: this is what the
12996 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12997 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12998 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
13000 /* Look for specific sections that we need. */
13001 if (section_is_p (sectp
->name
, &names
->str_dwo
))
13003 dwp_file
->sections
.str
.s
.section
= sectp
;
13004 dwp_file
->sections
.str
.size
= bfd_get_section_size (sectp
);
13006 else if (section_is_p (sectp
->name
, &names
->cu_index
))
13008 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
13009 dwp_file
->sections
.cu_index
.size
= bfd_get_section_size (sectp
);
13011 else if (section_is_p (sectp
->name
, &names
->tu_index
))
13013 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
13014 dwp_file
->sections
.tu_index
.size
= bfd_get_section_size (sectp
);
13018 /* This function is mapped across the sections and remembers the offset and
13019 size of each of the DWP version 2 debugging sections that we are interested
13020 in. This is split into a separate function because we don't know if we
13021 have version 1 or 2 until we parse the cu_index/tu_index sections. */
13024 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
13026 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
13027 const struct dwop_section_names
*names
= &dwop_section_names
;
13028 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
13030 /* Record the ELF section number for later lookup: this is what the
13031 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
13032 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
13033 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
13035 /* Look for specific sections that we need. */
13036 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
13038 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
13039 dwp_file
->sections
.abbrev
.size
= bfd_get_section_size (sectp
);
13041 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
13043 dwp_file
->sections
.info
.s
.section
= sectp
;
13044 dwp_file
->sections
.info
.size
= bfd_get_section_size (sectp
);
13046 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
13048 dwp_file
->sections
.line
.s
.section
= sectp
;
13049 dwp_file
->sections
.line
.size
= bfd_get_section_size (sectp
);
13051 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
13053 dwp_file
->sections
.loc
.s
.section
= sectp
;
13054 dwp_file
->sections
.loc
.size
= bfd_get_section_size (sectp
);
13056 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
13058 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
13059 dwp_file
->sections
.macinfo
.size
= bfd_get_section_size (sectp
);
13061 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
13063 dwp_file
->sections
.macro
.s
.section
= sectp
;
13064 dwp_file
->sections
.macro
.size
= bfd_get_section_size (sectp
);
13066 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
13068 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
13069 dwp_file
->sections
.str_offsets
.size
= bfd_get_section_size (sectp
);
13071 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
13073 dwp_file
->sections
.types
.s
.section
= sectp
;
13074 dwp_file
->sections
.types
.size
= bfd_get_section_size (sectp
);
13078 /* Hash function for dwp_file loaded CUs/TUs. */
13081 hash_dwp_loaded_cutus (const void *item
)
13083 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
13085 /* This drops the top 32 bits of the signature, but is ok for a hash. */
13086 return dwo_unit
->signature
;
13089 /* Equality function for dwp_file loaded CUs/TUs. */
13092 eq_dwp_loaded_cutus (const void *a
, const void *b
)
13094 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
13095 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
13097 return dua
->signature
== dub
->signature
;
13100 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
13103 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
13105 return htab_create_alloc_ex (3,
13106 hash_dwp_loaded_cutus
,
13107 eq_dwp_loaded_cutus
,
13109 &objfile
->objfile_obstack
,
13110 hashtab_obstack_allocate
,
13111 dummy_obstack_deallocate
);
13114 /* Try to open DWP file FILE_NAME.
13115 The result is the bfd handle of the file.
13116 If there is a problem finding or opening the file, return NULL.
13117 Upon success, the canonicalized path of the file is stored in the bfd,
13118 same as symfile_bfd_open. */
13120 static gdb_bfd_ref_ptr
13121 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
13122 const char *file_name
)
13124 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
13126 1 /*search_cwd*/));
13130 /* Work around upstream bug 15652.
13131 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
13132 [Whether that's a "bug" is debatable, but it is getting in our way.]
13133 We have no real idea where the dwp file is, because gdb's realpath-ing
13134 of the executable's path may have discarded the needed info.
13135 [IWBN if the dwp file name was recorded in the executable, akin to
13136 .gnu_debuglink, but that doesn't exist yet.]
13137 Strip the directory from FILE_NAME and search again. */
13138 if (*debug_file_directory
!= '\0')
13140 /* Don't implicitly search the current directory here.
13141 If the user wants to search "." to handle this case,
13142 it must be added to debug-file-directory. */
13143 return try_open_dwop_file (dwarf2_per_objfile
,
13144 lbasename (file_name
), 1 /*is_dwp*/,
13151 /* Initialize the use of the DWP file for the current objfile.
13152 By convention the name of the DWP file is ${objfile}.dwp.
13153 The result is NULL if it can't be found. */
13155 static std::unique_ptr
<struct dwp_file
>
13156 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
13158 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13160 /* Try to find first .dwp for the binary file before any symbolic links
13163 /* If the objfile is a debug file, find the name of the real binary
13164 file and get the name of dwp file from there. */
13165 std::string dwp_name
;
13166 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
13168 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
13169 const char *backlink_basename
= lbasename (backlink
->original_name
);
13171 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
13174 dwp_name
= objfile
->original_name
;
13176 dwp_name
+= ".dwp";
13178 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
13180 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
13182 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
13183 dwp_name
= objfile_name (objfile
);
13184 dwp_name
+= ".dwp";
13185 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
13190 if (dwarf_read_debug
)
13191 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
13192 return std::unique_ptr
<dwp_file
> ();
13195 const char *name
= bfd_get_filename (dbfd
.get ());
13196 std::unique_ptr
<struct dwp_file
> dwp_file
13197 (new struct dwp_file (name
, std::move (dbfd
)));
13199 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
13200 dwp_file
->elf_sections
=
13201 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
13202 dwp_file
->num_sections
, asection
*);
13204 bfd_map_over_sections (dwp_file
->dbfd
.get (),
13205 dwarf2_locate_common_dwp_sections
,
13208 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
13211 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
13214 /* The DWP file version is stored in the hash table. Oh well. */
13215 if (dwp_file
->cus
&& dwp_file
->tus
13216 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
13218 /* Technically speaking, we should try to limp along, but this is
13219 pretty bizarre. We use pulongest here because that's the established
13220 portability solution (e.g, we cannot use %u for uint32_t). */
13221 error (_("Dwarf Error: DWP file CU version %s doesn't match"
13222 " TU version %s [in DWP file %s]"),
13223 pulongest (dwp_file
->cus
->version
),
13224 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
13228 dwp_file
->version
= dwp_file
->cus
->version
;
13229 else if (dwp_file
->tus
)
13230 dwp_file
->version
= dwp_file
->tus
->version
;
13232 dwp_file
->version
= 2;
13234 if (dwp_file
->version
== 2)
13235 bfd_map_over_sections (dwp_file
->dbfd
.get (),
13236 dwarf2_locate_v2_dwp_sections
,
13239 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table (objfile
);
13240 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table (objfile
);
13242 if (dwarf_read_debug
)
13244 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
13245 fprintf_unfiltered (gdb_stdlog
,
13246 " %s CUs, %s TUs\n",
13247 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
13248 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
13254 /* Wrapper around open_and_init_dwp_file, only open it once. */
13256 static struct dwp_file
*
13257 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
13259 if (! dwarf2_per_objfile
->dwp_checked
)
13261 dwarf2_per_objfile
->dwp_file
13262 = open_and_init_dwp_file (dwarf2_per_objfile
);
13263 dwarf2_per_objfile
->dwp_checked
= 1;
13265 return dwarf2_per_objfile
->dwp_file
.get ();
13268 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
13269 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
13270 or in the DWP file for the objfile, referenced by THIS_UNIT.
13271 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
13272 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
13274 This is called, for example, when wanting to read a variable with a
13275 complex location. Therefore we don't want to do file i/o for every call.
13276 Therefore we don't want to look for a DWO file on every call.
13277 Therefore we first see if we've already seen SIGNATURE in a DWP file,
13278 then we check if we've already seen DWO_NAME, and only THEN do we check
13281 The result is a pointer to the dwo_unit object or NULL if we didn't find it
13282 (dwo_id mismatch or couldn't find the DWO/DWP file). */
13284 static struct dwo_unit
*
13285 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
13286 const char *dwo_name
, const char *comp_dir
,
13287 ULONGEST signature
, int is_debug_types
)
13289 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_unit
->dwarf2_per_objfile
;
13290 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13291 const char *kind
= is_debug_types
? "TU" : "CU";
13292 void **dwo_file_slot
;
13293 struct dwo_file
*dwo_file
;
13294 struct dwp_file
*dwp_file
;
13296 /* First see if there's a DWP file.
13297 If we have a DWP file but didn't find the DWO inside it, don't
13298 look for the original DWO file. It makes gdb behave differently
13299 depending on whether one is debugging in the build tree. */
13301 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
13302 if (dwp_file
!= NULL
)
13304 const struct dwp_hash_table
*dwp_htab
=
13305 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
13307 if (dwp_htab
!= NULL
)
13309 struct dwo_unit
*dwo_cutu
=
13310 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
13311 signature
, is_debug_types
);
13313 if (dwo_cutu
!= NULL
)
13315 if (dwarf_read_debug
)
13317 fprintf_unfiltered (gdb_stdlog
,
13318 "Virtual DWO %s %s found: @%s\n",
13319 kind
, hex_string (signature
),
13320 host_address_to_string (dwo_cutu
));
13328 /* No DWP file, look for the DWO file. */
13330 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
13331 dwo_name
, comp_dir
);
13332 if (*dwo_file_slot
== NULL
)
13334 /* Read in the file and build a table of the CUs/TUs it contains. */
13335 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
13337 /* NOTE: This will be NULL if unable to open the file. */
13338 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
13340 if (dwo_file
!= NULL
)
13342 struct dwo_unit
*dwo_cutu
= NULL
;
13344 if (is_debug_types
&& dwo_file
->tus
)
13346 struct dwo_unit find_dwo_cutu
;
13348 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13349 find_dwo_cutu
.signature
= signature
;
13351 = (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_cutu
);
13353 else if (!is_debug_types
&& dwo_file
->cus
)
13355 struct dwo_unit find_dwo_cutu
;
13357 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13358 find_dwo_cutu
.signature
= signature
;
13359 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
,
13363 if (dwo_cutu
!= NULL
)
13365 if (dwarf_read_debug
)
13367 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
13368 kind
, dwo_name
, hex_string (signature
),
13369 host_address_to_string (dwo_cutu
));
13376 /* We didn't find it. This could mean a dwo_id mismatch, or
13377 someone deleted the DWO/DWP file, or the search path isn't set up
13378 correctly to find the file. */
13380 if (dwarf_read_debug
)
13382 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
13383 kind
, dwo_name
, hex_string (signature
));
13386 /* This is a warning and not a complaint because it can be caused by
13387 pilot error (e.g., user accidentally deleting the DWO). */
13389 /* Print the name of the DWP file if we looked there, helps the user
13390 better diagnose the problem. */
13391 std::string dwp_text
;
13393 if (dwp_file
!= NULL
)
13394 dwp_text
= string_printf (" [in DWP file %s]",
13395 lbasename (dwp_file
->name
));
13397 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
13398 " [in module %s]"),
13399 kind
, dwo_name
, hex_string (signature
),
13401 this_unit
->is_debug_types
? "TU" : "CU",
13402 sect_offset_str (this_unit
->sect_off
), objfile_name (objfile
));
13407 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
13408 See lookup_dwo_cutu_unit for details. */
13410 static struct dwo_unit
*
13411 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
13412 const char *dwo_name
, const char *comp_dir
,
13413 ULONGEST signature
)
13415 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
13418 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
13419 See lookup_dwo_cutu_unit for details. */
13421 static struct dwo_unit
*
13422 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
13423 const char *dwo_name
, const char *comp_dir
)
13425 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
13428 /* Traversal function for queue_and_load_all_dwo_tus. */
13431 queue_and_load_dwo_tu (void **slot
, void *info
)
13433 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
13434 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
13435 ULONGEST signature
= dwo_unit
->signature
;
13436 struct signatured_type
*sig_type
=
13437 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
13439 if (sig_type
!= NULL
)
13441 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
13443 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
13444 a real dependency of PER_CU on SIG_TYPE. That is detected later
13445 while processing PER_CU. */
13446 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
13447 load_full_type_unit (sig_cu
);
13448 VEC_safe_push (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, sig_cu
);
13454 /* Queue all TUs contained in the DWO of PER_CU to be read in.
13455 The DWO may have the only definition of the type, though it may not be
13456 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
13457 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
13460 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
13462 struct dwo_unit
*dwo_unit
;
13463 struct dwo_file
*dwo_file
;
13465 gdb_assert (!per_cu
->is_debug_types
);
13466 gdb_assert (get_dwp_file (per_cu
->dwarf2_per_objfile
) == NULL
);
13467 gdb_assert (per_cu
->cu
!= NULL
);
13469 dwo_unit
= per_cu
->cu
->dwo_unit
;
13470 gdb_assert (dwo_unit
!= NULL
);
13472 dwo_file
= dwo_unit
->dwo_file
;
13473 if (dwo_file
->tus
!= NULL
)
13474 htab_traverse_noresize (dwo_file
->tus
, queue_and_load_dwo_tu
, per_cu
);
13477 /* Read in various DIEs. */
13479 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
13480 Inherit only the children of the DW_AT_abstract_origin DIE not being
13481 already referenced by DW_AT_abstract_origin from the children of the
13485 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
13487 struct die_info
*child_die
;
13488 sect_offset
*offsetp
;
13489 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
13490 struct die_info
*origin_die
;
13491 /* Iterator of the ORIGIN_DIE children. */
13492 struct die_info
*origin_child_die
;
13493 struct attribute
*attr
;
13494 struct dwarf2_cu
*origin_cu
;
13495 struct pending
**origin_previous_list_in_scope
;
13497 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13501 /* Note that following die references may follow to a die in a
13505 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
13507 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
13509 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
13510 origin_cu
->list_in_scope
= cu
->list_in_scope
;
13512 if (die
->tag
!= origin_die
->tag
13513 && !(die
->tag
== DW_TAG_inlined_subroutine
13514 && origin_die
->tag
== DW_TAG_subprogram
))
13515 complaint (_("DIE %s and its abstract origin %s have different tags"),
13516 sect_offset_str (die
->sect_off
),
13517 sect_offset_str (origin_die
->sect_off
));
13519 std::vector
<sect_offset
> offsets
;
13521 for (child_die
= die
->child
;
13522 child_die
&& child_die
->tag
;
13523 child_die
= sibling_die (child_die
))
13525 struct die_info
*child_origin_die
;
13526 struct dwarf2_cu
*child_origin_cu
;
13528 /* We are trying to process concrete instance entries:
13529 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
13530 it's not relevant to our analysis here. i.e. detecting DIEs that are
13531 present in the abstract instance but not referenced in the concrete
13533 if (child_die
->tag
== DW_TAG_call_site
13534 || child_die
->tag
== DW_TAG_GNU_call_site
)
13537 /* For each CHILD_DIE, find the corresponding child of
13538 ORIGIN_DIE. If there is more than one layer of
13539 DW_AT_abstract_origin, follow them all; there shouldn't be,
13540 but GCC versions at least through 4.4 generate this (GCC PR
13542 child_origin_die
= child_die
;
13543 child_origin_cu
= cu
;
13546 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
13550 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
13554 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
13555 counterpart may exist. */
13556 if (child_origin_die
!= child_die
)
13558 if (child_die
->tag
!= child_origin_die
->tag
13559 && !(child_die
->tag
== DW_TAG_inlined_subroutine
13560 && child_origin_die
->tag
== DW_TAG_subprogram
))
13561 complaint (_("Child DIE %s and its abstract origin %s have "
13563 sect_offset_str (child_die
->sect_off
),
13564 sect_offset_str (child_origin_die
->sect_off
));
13565 if (child_origin_die
->parent
!= origin_die
)
13566 complaint (_("Child DIE %s and its abstract origin %s have "
13567 "different parents"),
13568 sect_offset_str (child_die
->sect_off
),
13569 sect_offset_str (child_origin_die
->sect_off
));
13571 offsets
.push_back (child_origin_die
->sect_off
);
13574 std::sort (offsets
.begin (), offsets
.end ());
13575 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
13576 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
13577 if (offsetp
[-1] == *offsetp
)
13578 complaint (_("Multiple children of DIE %s refer "
13579 "to DIE %s as their abstract origin"),
13580 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
13582 offsetp
= offsets
.data ();
13583 origin_child_die
= origin_die
->child
;
13584 while (origin_child_die
&& origin_child_die
->tag
)
13586 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13587 while (offsetp
< offsets_end
13588 && *offsetp
< origin_child_die
->sect_off
)
13590 if (offsetp
>= offsets_end
13591 || *offsetp
> origin_child_die
->sect_off
)
13593 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13594 Check whether we're already processing ORIGIN_CHILD_DIE.
13595 This can happen with mutually referenced abstract_origins.
13597 if (!origin_child_die
->in_process
)
13598 process_die (origin_child_die
, origin_cu
);
13600 origin_child_die
= sibling_die (origin_child_die
);
13602 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13606 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13608 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13609 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13610 struct context_stack
*newobj
;
13613 struct die_info
*child_die
;
13614 struct attribute
*attr
, *call_line
, *call_file
;
13616 CORE_ADDR baseaddr
;
13617 struct block
*block
;
13618 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13619 std::vector
<struct symbol
*> template_args
;
13620 struct template_symbol
*templ_func
= NULL
;
13624 /* If we do not have call site information, we can't show the
13625 caller of this inlined function. That's too confusing, so
13626 only use the scope for local variables. */
13627 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13628 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13629 if (call_line
== NULL
|| call_file
== NULL
)
13631 read_lexical_block_scope (die
, cu
);
13636 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13638 name
= dwarf2_name (die
, cu
);
13640 /* Ignore functions with missing or empty names. These are actually
13641 illegal according to the DWARF standard. */
13644 complaint (_("missing name for subprogram DIE at %s"),
13645 sect_offset_str (die
->sect_off
));
13649 /* Ignore functions with missing or invalid low and high pc attributes. */
13650 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13651 <= PC_BOUNDS_INVALID
)
13653 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13654 if (!attr
|| !DW_UNSND (attr
))
13655 complaint (_("cannot get low and high bounds "
13656 "for subprogram DIE at %s"),
13657 sect_offset_str (die
->sect_off
));
13661 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13662 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13664 /* If we have any template arguments, then we must allocate a
13665 different sort of symbol. */
13666 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
13668 if (child_die
->tag
== DW_TAG_template_type_param
13669 || child_die
->tag
== DW_TAG_template_value_param
)
13671 templ_func
= allocate_template_symbol (objfile
);
13672 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13677 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13678 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13679 (struct symbol
*) templ_func
);
13681 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13682 set_objfile_main_name (objfile
, SYMBOL_LINKAGE_NAME (newobj
->name
),
13685 /* If there is a location expression for DW_AT_frame_base, record
13687 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13689 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13691 /* If there is a location for the static link, record it. */
13692 newobj
->static_link
= NULL
;
13693 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13696 newobj
->static_link
13697 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13698 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13699 dwarf2_per_cu_addr_type (cu
->per_cu
));
13702 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13704 if (die
->child
!= NULL
)
13706 child_die
= die
->child
;
13707 while (child_die
&& child_die
->tag
)
13709 if (child_die
->tag
== DW_TAG_template_type_param
13710 || child_die
->tag
== DW_TAG_template_value_param
)
13712 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13715 template_args
.push_back (arg
);
13718 process_die (child_die
, cu
);
13719 child_die
= sibling_die (child_die
);
13723 inherit_abstract_dies (die
, cu
);
13725 /* If we have a DW_AT_specification, we might need to import using
13726 directives from the context of the specification DIE. See the
13727 comment in determine_prefix. */
13728 if (cu
->language
== language_cplus
13729 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13731 struct dwarf2_cu
*spec_cu
= cu
;
13732 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13736 child_die
= spec_die
->child
;
13737 while (child_die
&& child_die
->tag
)
13739 if (child_die
->tag
== DW_TAG_imported_module
)
13740 process_die (child_die
, spec_cu
);
13741 child_die
= sibling_die (child_die
);
13744 /* In some cases, GCC generates specification DIEs that
13745 themselves contain DW_AT_specification attributes. */
13746 spec_die
= die_specification (spec_die
, &spec_cu
);
13750 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13751 /* Make a block for the local symbols within. */
13752 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13753 cstk
.static_link
, lowpc
, highpc
);
13755 /* For C++, set the block's scope. */
13756 if ((cu
->language
== language_cplus
13757 || cu
->language
== language_fortran
13758 || cu
->language
== language_d
13759 || cu
->language
== language_rust
)
13760 && cu
->processing_has_namespace_info
)
13761 block_set_scope (block
, determine_prefix (die
, cu
),
13762 &objfile
->objfile_obstack
);
13764 /* If we have address ranges, record them. */
13765 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13767 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13769 /* Attach template arguments to function. */
13770 if (!template_args
.empty ())
13772 gdb_assert (templ_func
!= NULL
);
13774 templ_func
->n_template_arguments
= template_args
.size ();
13775 templ_func
->template_arguments
13776 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13777 templ_func
->n_template_arguments
);
13778 memcpy (templ_func
->template_arguments
,
13779 template_args
.data (),
13780 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13782 /* Make sure that the symtab is set on the new symbols. Even
13783 though they don't appear in this symtab directly, other parts
13784 of gdb assume that symbols do, and this is reasonably
13786 for (symbol
*sym
: template_args
)
13787 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13790 /* In C++, we can have functions nested inside functions (e.g., when
13791 a function declares a class that has methods). This means that
13792 when we finish processing a function scope, we may need to go
13793 back to building a containing block's symbol lists. */
13794 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13795 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13797 /* If we've finished processing a top-level function, subsequent
13798 symbols go in the file symbol list. */
13799 if (cu
->get_builder ()->outermost_context_p ())
13800 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13803 /* Process all the DIES contained within a lexical block scope. Start
13804 a new scope, process the dies, and then close the scope. */
13807 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13809 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13810 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13811 CORE_ADDR lowpc
, highpc
;
13812 struct die_info
*child_die
;
13813 CORE_ADDR baseaddr
;
13815 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13817 /* Ignore blocks with missing or invalid low and high pc attributes. */
13818 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13819 as multiple lexical blocks? Handling children in a sane way would
13820 be nasty. Might be easier to properly extend generic blocks to
13821 describe ranges. */
13822 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13824 case PC_BOUNDS_NOT_PRESENT
:
13825 /* DW_TAG_lexical_block has no attributes, process its children as if
13826 there was no wrapping by that DW_TAG_lexical_block.
13827 GCC does no longer produces such DWARF since GCC r224161. */
13828 for (child_die
= die
->child
;
13829 child_die
!= NULL
&& child_die
->tag
;
13830 child_die
= sibling_die (child_die
))
13831 process_die (child_die
, cu
);
13833 case PC_BOUNDS_INVALID
:
13836 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13837 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13839 cu
->get_builder ()->push_context (0, lowpc
);
13840 if (die
->child
!= NULL
)
13842 child_die
= die
->child
;
13843 while (child_die
&& child_die
->tag
)
13845 process_die (child_die
, cu
);
13846 child_die
= sibling_die (child_die
);
13849 inherit_abstract_dies (die
, cu
);
13850 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13852 if (*cu
->get_builder ()->get_local_symbols () != NULL
13853 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13855 struct block
*block
13856 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13857 cstk
.start_addr
, highpc
);
13859 /* Note that recording ranges after traversing children, as we
13860 do here, means that recording a parent's ranges entails
13861 walking across all its children's ranges as they appear in
13862 the address map, which is quadratic behavior.
13864 It would be nicer to record the parent's ranges before
13865 traversing its children, simply overriding whatever you find
13866 there. But since we don't even decide whether to create a
13867 block until after we've traversed its children, that's hard
13869 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13871 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13872 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13875 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13878 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13880 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13881 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13882 CORE_ADDR pc
, baseaddr
;
13883 struct attribute
*attr
;
13884 struct call_site
*call_site
, call_site_local
;
13887 struct die_info
*child_die
;
13889 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13891 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13894 /* This was a pre-DWARF-5 GNU extension alias
13895 for DW_AT_call_return_pc. */
13896 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13900 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13901 "DIE %s [in module %s]"),
13902 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13905 pc
= attr_value_as_address (attr
) + baseaddr
;
13906 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13908 if (cu
->call_site_htab
== NULL
)
13909 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13910 NULL
, &objfile
->objfile_obstack
,
13911 hashtab_obstack_allocate
, NULL
);
13912 call_site_local
.pc
= pc
;
13913 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13916 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13917 "DIE %s [in module %s]"),
13918 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13919 objfile_name (objfile
));
13923 /* Count parameters at the caller. */
13926 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13927 child_die
= sibling_die (child_die
))
13929 if (child_die
->tag
!= DW_TAG_call_site_parameter
13930 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13932 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13933 "DW_TAG_call_site child DIE %s [in module %s]"),
13934 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13935 objfile_name (objfile
));
13943 = ((struct call_site
*)
13944 obstack_alloc (&objfile
->objfile_obstack
,
13945 sizeof (*call_site
)
13946 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13948 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13949 call_site
->pc
= pc
;
13951 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13952 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13954 struct die_info
*func_die
;
13956 /* Skip also over DW_TAG_inlined_subroutine. */
13957 for (func_die
= die
->parent
;
13958 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13959 && func_die
->tag
!= DW_TAG_subroutine_type
;
13960 func_die
= func_die
->parent
);
13962 /* DW_AT_call_all_calls is a superset
13963 of DW_AT_call_all_tail_calls. */
13965 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13966 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13967 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13968 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13970 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13971 not complete. But keep CALL_SITE for look ups via call_site_htab,
13972 both the initial caller containing the real return address PC and
13973 the final callee containing the current PC of a chain of tail
13974 calls do not need to have the tail call list complete. But any
13975 function candidate for a virtual tail call frame searched via
13976 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13977 determined unambiguously. */
13981 struct type
*func_type
= NULL
;
13984 func_type
= get_die_type (func_die
, cu
);
13985 if (func_type
!= NULL
)
13987 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
13989 /* Enlist this call site to the function. */
13990 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13991 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13994 complaint (_("Cannot find function owning DW_TAG_call_site "
13995 "DIE %s [in module %s]"),
13996 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14000 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
14002 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
14004 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
14007 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
14008 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
14010 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
14011 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
14012 /* Keep NULL DWARF_BLOCK. */;
14013 else if (attr_form_is_block (attr
))
14015 struct dwarf2_locexpr_baton
*dlbaton
;
14017 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
14018 dlbaton
->data
= DW_BLOCK (attr
)->data
;
14019 dlbaton
->size
= DW_BLOCK (attr
)->size
;
14020 dlbaton
->per_cu
= cu
->per_cu
;
14022 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
14024 else if (attr_form_is_ref (attr
))
14026 struct dwarf2_cu
*target_cu
= cu
;
14027 struct die_info
*target_die
;
14029 target_die
= follow_die_ref (die
, attr
, &target_cu
);
14030 gdb_assert (target_cu
->per_cu
->dwarf2_per_objfile
->objfile
== objfile
);
14031 if (die_is_declaration (target_die
, target_cu
))
14033 const char *target_physname
;
14035 /* Prefer the mangled name; otherwise compute the demangled one. */
14036 target_physname
= dw2_linkage_name (target_die
, target_cu
);
14037 if (target_physname
== NULL
)
14038 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
14039 if (target_physname
== NULL
)
14040 complaint (_("DW_AT_call_target target DIE has invalid "
14041 "physname, for referencing DIE %s [in module %s]"),
14042 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14044 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
14050 /* DW_AT_entry_pc should be preferred. */
14051 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
14052 <= PC_BOUNDS_INVALID
)
14053 complaint (_("DW_AT_call_target target DIE has invalid "
14054 "low pc, for referencing DIE %s [in module %s]"),
14055 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14058 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
14059 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
14064 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
14065 "block nor reference, for DIE %s [in module %s]"),
14066 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14068 call_site
->per_cu
= cu
->per_cu
;
14070 for (child_die
= die
->child
;
14071 child_die
&& child_die
->tag
;
14072 child_die
= sibling_die (child_die
))
14074 struct call_site_parameter
*parameter
;
14075 struct attribute
*loc
, *origin
;
14077 if (child_die
->tag
!= DW_TAG_call_site_parameter
14078 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
14080 /* Already printed the complaint above. */
14084 gdb_assert (call_site
->parameter_count
< nparams
);
14085 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
14087 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
14088 specifies DW_TAG_formal_parameter. Value of the data assumed for the
14089 register is contained in DW_AT_call_value. */
14091 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
14092 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
14093 if (origin
== NULL
)
14095 /* This was a pre-DWARF-5 GNU extension alias
14096 for DW_AT_call_parameter. */
14097 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
14099 if (loc
== NULL
&& origin
!= NULL
&& attr_form_is_ref (origin
))
14101 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
14103 sect_offset sect_off
14104 = (sect_offset
) dwarf2_get_ref_die_offset (origin
);
14105 if (!offset_in_cu_p (&cu
->header
, sect_off
))
14107 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
14108 binding can be done only inside one CU. Such referenced DIE
14109 therefore cannot be even moved to DW_TAG_partial_unit. */
14110 complaint (_("DW_AT_call_parameter offset is not in CU for "
14111 "DW_TAG_call_site child DIE %s [in module %s]"),
14112 sect_offset_str (child_die
->sect_off
),
14113 objfile_name (objfile
));
14116 parameter
->u
.param_cu_off
14117 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
14119 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
14121 complaint (_("No DW_FORM_block* DW_AT_location for "
14122 "DW_TAG_call_site child DIE %s [in module %s]"),
14123 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
14128 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
14129 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
14130 if (parameter
->u
.dwarf_reg
!= -1)
14131 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
14132 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
14133 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
14134 ¶meter
->u
.fb_offset
))
14135 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
14138 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
14139 "for DW_FORM_block* DW_AT_location is supported for "
14140 "DW_TAG_call_site child DIE %s "
14142 sect_offset_str (child_die
->sect_off
),
14143 objfile_name (objfile
));
14148 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
14150 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
14151 if (!attr_form_is_block (attr
))
14153 complaint (_("No DW_FORM_block* DW_AT_call_value for "
14154 "DW_TAG_call_site child DIE %s [in module %s]"),
14155 sect_offset_str (child_die
->sect_off
),
14156 objfile_name (objfile
));
14159 parameter
->value
= DW_BLOCK (attr
)->data
;
14160 parameter
->value_size
= DW_BLOCK (attr
)->size
;
14162 /* Parameters are not pre-cleared by memset above. */
14163 parameter
->data_value
= NULL
;
14164 parameter
->data_value_size
= 0;
14165 call_site
->parameter_count
++;
14167 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
14169 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
14172 if (!attr_form_is_block (attr
))
14173 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
14174 "DW_TAG_call_site child DIE %s [in module %s]"),
14175 sect_offset_str (child_die
->sect_off
),
14176 objfile_name (objfile
));
14179 parameter
->data_value
= DW_BLOCK (attr
)->data
;
14180 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
14186 /* Helper function for read_variable. If DIE represents a virtual
14187 table, then return the type of the concrete object that is
14188 associated with the virtual table. Otherwise, return NULL. */
14190 static struct type
*
14191 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14193 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
14197 /* Find the type DIE. */
14198 struct die_info
*type_die
= NULL
;
14199 struct dwarf2_cu
*type_cu
= cu
;
14201 if (attr_form_is_ref (attr
))
14202 type_die
= follow_die_ref (die
, attr
, &type_cu
);
14203 if (type_die
== NULL
)
14206 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
14208 return die_containing_type (type_die
, type_cu
);
14211 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
14214 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
14216 struct rust_vtable_symbol
*storage
= NULL
;
14218 if (cu
->language
== language_rust
)
14220 struct type
*containing_type
= rust_containing_type (die
, cu
);
14222 if (containing_type
!= NULL
)
14224 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14226 storage
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
14227 struct rust_vtable_symbol
);
14228 initialize_objfile_symbol (storage
);
14229 storage
->concrete_type
= containing_type
;
14230 storage
->subclass
= SYMBOL_RUST_VTABLE
;
14234 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
14235 struct attribute
*abstract_origin
14236 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
14237 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
14238 if (res
== NULL
&& loc
&& abstract_origin
)
14240 /* We have a variable without a name, but with a location and an abstract
14241 origin. This may be a concrete instance of an abstract variable
14242 referenced from an DW_OP_GNU_variable_value, so save it to find it back
14244 struct dwarf2_cu
*origin_cu
= cu
;
14245 struct die_info
*origin_die
14246 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
14247 dwarf2_per_objfile
*dpo
= cu
->per_cu
->dwarf2_per_objfile
;
14248 dpo
->abstract_to_concrete
[origin_die
->sect_off
].push_back (die
->sect_off
);
14252 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
14253 reading .debug_rnglists.
14254 Callback's type should be:
14255 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14256 Return true if the attributes are present and valid, otherwise,
14259 template <typename Callback
>
14261 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
14262 Callback
&&callback
)
14264 struct dwarf2_per_objfile
*dwarf2_per_objfile
14265 = cu
->per_cu
->dwarf2_per_objfile
;
14266 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14267 bfd
*obfd
= objfile
->obfd
;
14268 /* Base address selection entry. */
14271 const gdb_byte
*buffer
;
14272 CORE_ADDR baseaddr
;
14273 bool overflow
= false;
14275 found_base
= cu
->base_known
;
14276 base
= cu
->base_address
;
14278 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->rnglists
);
14279 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
14281 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14285 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
14287 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14291 /* Initialize it due to a false compiler warning. */
14292 CORE_ADDR range_beginning
= 0, range_end
= 0;
14293 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
14294 + dwarf2_per_objfile
->rnglists
.size
);
14295 unsigned int bytes_read
;
14297 if (buffer
== buf_end
)
14302 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
14305 case DW_RLE_end_of_list
:
14307 case DW_RLE_base_address
:
14308 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14313 base
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14315 buffer
+= bytes_read
;
14317 case DW_RLE_start_length
:
14318 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14323 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14324 buffer
+= bytes_read
;
14325 range_end
= (range_beginning
14326 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
14327 buffer
+= bytes_read
;
14328 if (buffer
> buf_end
)
14334 case DW_RLE_offset_pair
:
14335 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14336 buffer
+= bytes_read
;
14337 if (buffer
> buf_end
)
14342 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14343 buffer
+= bytes_read
;
14344 if (buffer
> buf_end
)
14350 case DW_RLE_start_end
:
14351 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
14356 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14357 buffer
+= bytes_read
;
14358 range_end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14359 buffer
+= bytes_read
;
14362 complaint (_("Invalid .debug_rnglists data (no base address)"));
14365 if (rlet
== DW_RLE_end_of_list
|| overflow
)
14367 if (rlet
== DW_RLE_base_address
)
14372 /* We have no valid base address for the ranges
14374 complaint (_("Invalid .debug_rnglists data (no base address)"));
14378 if (range_beginning
> range_end
)
14380 /* Inverted range entries are invalid. */
14381 complaint (_("Invalid .debug_rnglists data (inverted range)"));
14385 /* Empty range entries have no effect. */
14386 if (range_beginning
== range_end
)
14389 range_beginning
+= base
;
14392 /* A not-uncommon case of bad debug info.
14393 Don't pollute the addrmap with bad data. */
14394 if (range_beginning
+ baseaddr
== 0
14395 && !dwarf2_per_objfile
->has_section_at_zero
)
14397 complaint (_(".debug_rnglists entry has start address of zero"
14398 " [in module %s]"), objfile_name (objfile
));
14402 callback (range_beginning
, range_end
);
14407 complaint (_("Offset %d is not terminated "
14408 "for DW_AT_ranges attribute"),
14416 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
14417 Callback's type should be:
14418 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14419 Return 1 if the attributes are present and valid, otherwise, return 0. */
14421 template <typename Callback
>
14423 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
14424 Callback
&&callback
)
14426 struct dwarf2_per_objfile
*dwarf2_per_objfile
14427 = cu
->per_cu
->dwarf2_per_objfile
;
14428 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14429 struct comp_unit_head
*cu_header
= &cu
->header
;
14430 bfd
*obfd
= objfile
->obfd
;
14431 unsigned int addr_size
= cu_header
->addr_size
;
14432 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
14433 /* Base address selection entry. */
14436 unsigned int dummy
;
14437 const gdb_byte
*buffer
;
14438 CORE_ADDR baseaddr
;
14440 if (cu_header
->version
>= 5)
14441 return dwarf2_rnglists_process (offset
, cu
, callback
);
14443 found_base
= cu
->base_known
;
14444 base
= cu
->base_address
;
14446 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
14447 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
14449 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14453 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
14455 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14459 CORE_ADDR range_beginning
, range_end
;
14461 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
14462 buffer
+= addr_size
;
14463 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
14464 buffer
+= addr_size
;
14465 offset
+= 2 * addr_size
;
14467 /* An end of list marker is a pair of zero addresses. */
14468 if (range_beginning
== 0 && range_end
== 0)
14469 /* Found the end of list entry. */
14472 /* Each base address selection entry is a pair of 2 values.
14473 The first is the largest possible address, the second is
14474 the base address. Check for a base address here. */
14475 if ((range_beginning
& mask
) == mask
)
14477 /* If we found the largest possible address, then we already
14478 have the base address in range_end. */
14486 /* We have no valid base address for the ranges
14488 complaint (_("Invalid .debug_ranges data (no base address)"));
14492 if (range_beginning
> range_end
)
14494 /* Inverted range entries are invalid. */
14495 complaint (_("Invalid .debug_ranges data (inverted range)"));
14499 /* Empty range entries have no effect. */
14500 if (range_beginning
== range_end
)
14503 range_beginning
+= base
;
14506 /* A not-uncommon case of bad debug info.
14507 Don't pollute the addrmap with bad data. */
14508 if (range_beginning
+ baseaddr
== 0
14509 && !dwarf2_per_objfile
->has_section_at_zero
)
14511 complaint (_(".debug_ranges entry has start address of zero"
14512 " [in module %s]"), objfile_name (objfile
));
14516 callback (range_beginning
, range_end
);
14522 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
14523 Return 1 if the attributes are present and valid, otherwise, return 0.
14524 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
14527 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
14528 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
14529 struct partial_symtab
*ranges_pst
)
14531 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14532 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14533 const CORE_ADDR baseaddr
= ANOFFSET (objfile
->section_offsets
,
14534 SECT_OFF_TEXT (objfile
));
14537 CORE_ADDR high
= 0;
14540 retval
= dwarf2_ranges_process (offset
, cu
,
14541 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
14543 if (ranges_pst
!= NULL
)
14548 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14549 range_beginning
+ baseaddr
)
14551 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14552 range_end
+ baseaddr
)
14554 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
14555 lowpc
, highpc
- 1, ranges_pst
);
14558 /* FIXME: This is recording everything as a low-high
14559 segment of consecutive addresses. We should have a
14560 data structure for discontiguous block ranges
14564 low
= range_beginning
;
14570 if (range_beginning
< low
)
14571 low
= range_beginning
;
14572 if (range_end
> high
)
14580 /* If the first entry is an end-of-list marker, the range
14581 describes an empty scope, i.e. no instructions. */
14587 *high_return
= high
;
14591 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14592 definition for the return value. *LOWPC and *HIGHPC are set iff
14593 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14595 static enum pc_bounds_kind
14596 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14597 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14598 struct partial_symtab
*pst
)
14600 struct dwarf2_per_objfile
*dwarf2_per_objfile
14601 = cu
->per_cu
->dwarf2_per_objfile
;
14602 struct attribute
*attr
;
14603 struct attribute
*attr_high
;
14605 CORE_ADDR high
= 0;
14606 enum pc_bounds_kind ret
;
14608 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14611 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14614 low
= attr_value_as_address (attr
);
14615 high
= attr_value_as_address (attr_high
);
14616 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
14620 /* Found high w/o low attribute. */
14621 return PC_BOUNDS_INVALID
;
14623 /* Found consecutive range of addresses. */
14624 ret
= PC_BOUNDS_HIGH_LOW
;
14628 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14631 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
14632 We take advantage of the fact that DW_AT_ranges does not appear
14633 in DW_TAG_compile_unit of DWO files. */
14634 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14635 unsigned int ranges_offset
= (DW_UNSND (attr
)
14636 + (need_ranges_base
14640 /* Value of the DW_AT_ranges attribute is the offset in the
14641 .debug_ranges section. */
14642 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
14643 return PC_BOUNDS_INVALID
;
14644 /* Found discontinuous range of addresses. */
14645 ret
= PC_BOUNDS_RANGES
;
14648 return PC_BOUNDS_NOT_PRESENT
;
14651 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14653 return PC_BOUNDS_INVALID
;
14655 /* When using the GNU linker, .gnu.linkonce. sections are used to
14656 eliminate duplicate copies of functions and vtables and such.
14657 The linker will arbitrarily choose one and discard the others.
14658 The AT_*_pc values for such functions refer to local labels in
14659 these sections. If the section from that file was discarded, the
14660 labels are not in the output, so the relocs get a value of 0.
14661 If this is a discarded function, mark the pc bounds as invalid,
14662 so that GDB will ignore it. */
14663 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
14664 return PC_BOUNDS_INVALID
;
14672 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14673 its low and high PC addresses. Do nothing if these addresses could not
14674 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14675 and HIGHPC to the high address if greater than HIGHPC. */
14678 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14679 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14680 struct dwarf2_cu
*cu
)
14682 CORE_ADDR low
, high
;
14683 struct die_info
*child
= die
->child
;
14685 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14687 *lowpc
= std::min (*lowpc
, low
);
14688 *highpc
= std::max (*highpc
, high
);
14691 /* If the language does not allow nested subprograms (either inside
14692 subprograms or lexical blocks), we're done. */
14693 if (cu
->language
!= language_ada
)
14696 /* Check all the children of the given DIE. If it contains nested
14697 subprograms, then check their pc bounds. Likewise, we need to
14698 check lexical blocks as well, as they may also contain subprogram
14700 while (child
&& child
->tag
)
14702 if (child
->tag
== DW_TAG_subprogram
14703 || child
->tag
== DW_TAG_lexical_block
)
14704 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14705 child
= sibling_die (child
);
14709 /* Get the low and high pc's represented by the scope DIE, and store
14710 them in *LOWPC and *HIGHPC. If the correct values can't be
14711 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14714 get_scope_pc_bounds (struct die_info
*die
,
14715 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14716 struct dwarf2_cu
*cu
)
14718 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14719 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14720 CORE_ADDR current_low
, current_high
;
14722 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14723 >= PC_BOUNDS_RANGES
)
14725 best_low
= current_low
;
14726 best_high
= current_high
;
14730 struct die_info
*child
= die
->child
;
14732 while (child
&& child
->tag
)
14734 switch (child
->tag
) {
14735 case DW_TAG_subprogram
:
14736 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14738 case DW_TAG_namespace
:
14739 case DW_TAG_module
:
14740 /* FIXME: carlton/2004-01-16: Should we do this for
14741 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14742 that current GCC's always emit the DIEs corresponding
14743 to definitions of methods of classes as children of a
14744 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14745 the DIEs giving the declarations, which could be
14746 anywhere). But I don't see any reason why the
14747 standards says that they have to be there. */
14748 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14750 if (current_low
!= ((CORE_ADDR
) -1))
14752 best_low
= std::min (best_low
, current_low
);
14753 best_high
= std::max (best_high
, current_high
);
14761 child
= sibling_die (child
);
14766 *highpc
= best_high
;
14769 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14773 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14774 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14776 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14777 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14778 struct attribute
*attr
;
14779 struct attribute
*attr_high
;
14781 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14784 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14787 CORE_ADDR low
= attr_value_as_address (attr
);
14788 CORE_ADDR high
= attr_value_as_address (attr_high
);
14790 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
14793 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14794 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14795 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14799 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14802 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
14803 We take advantage of the fact that DW_AT_ranges does not appear
14804 in DW_TAG_compile_unit of DWO files. */
14805 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14807 /* The value of the DW_AT_ranges attribute is the offset of the
14808 address range list in the .debug_ranges section. */
14809 unsigned long offset
= (DW_UNSND (attr
)
14810 + (need_ranges_base
? cu
->ranges_base
: 0));
14812 std::vector
<blockrange
> blockvec
;
14813 dwarf2_ranges_process (offset
, cu
,
14814 [&] (CORE_ADDR start
, CORE_ADDR end
)
14818 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14819 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14820 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14821 blockvec
.emplace_back (start
, end
);
14824 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14828 /* Check whether the producer field indicates either of GCC < 4.6, or the
14829 Intel C/C++ compiler, and cache the result in CU. */
14832 check_producer (struct dwarf2_cu
*cu
)
14836 if (cu
->producer
== NULL
)
14838 /* For unknown compilers expect their behavior is DWARF version
14841 GCC started to support .debug_types sections by -gdwarf-4 since
14842 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14843 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14844 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14845 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14847 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14849 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14850 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14852 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14854 cu
->producer_is_icc
= true;
14855 cu
->producer_is_icc_lt_14
= major
< 14;
14857 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14858 cu
->producer_is_codewarrior
= true;
14861 /* For other non-GCC compilers, expect their behavior is DWARF version
14865 cu
->checked_producer
= true;
14868 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14869 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14870 during 4.6.0 experimental. */
14873 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14875 if (!cu
->checked_producer
)
14876 check_producer (cu
);
14878 return cu
->producer_is_gxx_lt_4_6
;
14882 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14883 with incorrect is_stmt attributes. */
14886 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14888 if (!cu
->checked_producer
)
14889 check_producer (cu
);
14891 return cu
->producer_is_codewarrior
;
14894 /* Return the default accessibility type if it is not overriden by
14895 DW_AT_accessibility. */
14897 static enum dwarf_access_attribute
14898 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14900 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14902 /* The default DWARF 2 accessibility for members is public, the default
14903 accessibility for inheritance is private. */
14905 if (die
->tag
!= DW_TAG_inheritance
)
14906 return DW_ACCESS_public
;
14908 return DW_ACCESS_private
;
14912 /* DWARF 3+ defines the default accessibility a different way. The same
14913 rules apply now for DW_TAG_inheritance as for the members and it only
14914 depends on the container kind. */
14916 if (die
->parent
->tag
== DW_TAG_class_type
)
14917 return DW_ACCESS_private
;
14919 return DW_ACCESS_public
;
14923 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14924 offset. If the attribute was not found return 0, otherwise return
14925 1. If it was found but could not properly be handled, set *OFFSET
14929 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14932 struct attribute
*attr
;
14934 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14939 /* Note that we do not check for a section offset first here.
14940 This is because DW_AT_data_member_location is new in DWARF 4,
14941 so if we see it, we can assume that a constant form is really
14942 a constant and not a section offset. */
14943 if (attr_form_is_constant (attr
))
14944 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
14945 else if (attr_form_is_section_offset (attr
))
14946 dwarf2_complex_location_expr_complaint ();
14947 else if (attr_form_is_block (attr
))
14948 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14950 dwarf2_complex_location_expr_complaint ();
14958 /* Add an aggregate field to the field list. */
14961 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14962 struct dwarf2_cu
*cu
)
14964 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14965 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14966 struct nextfield
*new_field
;
14967 struct attribute
*attr
;
14969 const char *fieldname
= "";
14971 if (die
->tag
== DW_TAG_inheritance
)
14973 fip
->baseclasses
.emplace_back ();
14974 new_field
= &fip
->baseclasses
.back ();
14978 fip
->fields
.emplace_back ();
14979 new_field
= &fip
->fields
.back ();
14984 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14986 new_field
->accessibility
= DW_UNSND (attr
);
14988 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
14989 if (new_field
->accessibility
!= DW_ACCESS_public
)
14990 fip
->non_public_fields
= 1;
14992 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14994 new_field
->virtuality
= DW_UNSND (attr
);
14996 new_field
->virtuality
= DW_VIRTUALITY_none
;
14998 fp
= &new_field
->field
;
15000 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
15004 /* Data member other than a C++ static data member. */
15006 /* Get type of field. */
15007 fp
->type
= die_type (die
, cu
);
15009 SET_FIELD_BITPOS (*fp
, 0);
15011 /* Get bit size of field (zero if none). */
15012 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
15015 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
15019 FIELD_BITSIZE (*fp
) = 0;
15022 /* Get bit offset of field. */
15023 if (handle_data_member_location (die
, cu
, &offset
))
15024 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
15025 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
15028 if (gdbarch_bits_big_endian (gdbarch
))
15030 /* For big endian bits, the DW_AT_bit_offset gives the
15031 additional bit offset from the MSB of the containing
15032 anonymous object to the MSB of the field. We don't
15033 have to do anything special since we don't need to
15034 know the size of the anonymous object. */
15035 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
15039 /* For little endian bits, compute the bit offset to the
15040 MSB of the anonymous object, subtract off the number of
15041 bits from the MSB of the field to the MSB of the
15042 object, and then subtract off the number of bits of
15043 the field itself. The result is the bit offset of
15044 the LSB of the field. */
15045 int anonymous_size
;
15046 int bit_offset
= DW_UNSND (attr
);
15048 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15051 /* The size of the anonymous object containing
15052 the bit field is explicit, so use the
15053 indicated size (in bytes). */
15054 anonymous_size
= DW_UNSND (attr
);
15058 /* The size of the anonymous object containing
15059 the bit field must be inferred from the type
15060 attribute of the data member containing the
15062 anonymous_size
= TYPE_LENGTH (fp
->type
);
15064 SET_FIELD_BITPOS (*fp
,
15065 (FIELD_BITPOS (*fp
)
15066 + anonymous_size
* bits_per_byte
15067 - bit_offset
- FIELD_BITSIZE (*fp
)));
15070 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
15072 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
15073 + dwarf2_get_attr_constant_value (attr
, 0)));
15075 /* Get name of field. */
15076 fieldname
= dwarf2_name (die
, cu
);
15077 if (fieldname
== NULL
)
15080 /* The name is already allocated along with this objfile, so we don't
15081 need to duplicate it for the type. */
15082 fp
->name
= fieldname
;
15084 /* Change accessibility for artificial fields (e.g. virtual table
15085 pointer or virtual base class pointer) to private. */
15086 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
15088 FIELD_ARTIFICIAL (*fp
) = 1;
15089 new_field
->accessibility
= DW_ACCESS_private
;
15090 fip
->non_public_fields
= 1;
15093 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
15095 /* C++ static member. */
15097 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
15098 is a declaration, but all versions of G++ as of this writing
15099 (so through at least 3.2.1) incorrectly generate
15100 DW_TAG_variable tags. */
15102 const char *physname
;
15104 /* Get name of field. */
15105 fieldname
= dwarf2_name (die
, cu
);
15106 if (fieldname
== NULL
)
15109 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15111 /* Only create a symbol if this is an external value.
15112 new_symbol checks this and puts the value in the global symbol
15113 table, which we want. If it is not external, new_symbol
15114 will try to put the value in cu->list_in_scope which is wrong. */
15115 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
15117 /* A static const member, not much different than an enum as far as
15118 we're concerned, except that we can support more types. */
15119 new_symbol (die
, NULL
, cu
);
15122 /* Get physical name. */
15123 physname
= dwarf2_physname (fieldname
, die
, cu
);
15125 /* The name is already allocated along with this objfile, so we don't
15126 need to duplicate it for the type. */
15127 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
15128 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15129 FIELD_NAME (*fp
) = fieldname
;
15131 else if (die
->tag
== DW_TAG_inheritance
)
15135 /* C++ base class field. */
15136 if (handle_data_member_location (die
, cu
, &offset
))
15137 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
15138 FIELD_BITSIZE (*fp
) = 0;
15139 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15140 FIELD_NAME (*fp
) = TYPE_NAME (fp
->type
);
15142 else if (die
->tag
== DW_TAG_variant_part
)
15144 /* process_structure_scope will treat this DIE as a union. */
15145 process_structure_scope (die
, cu
);
15147 /* The variant part is relative to the start of the enclosing
15149 SET_FIELD_BITPOS (*fp
, 0);
15150 fp
->type
= get_die_type (die
, cu
);
15151 fp
->artificial
= 1;
15152 fp
->name
= "<<variant>>";
15154 /* Normally a DW_TAG_variant_part won't have a size, but our
15155 representation requires one, so set it to the maximum of the
15157 if (TYPE_LENGTH (fp
->type
) == 0)
15160 for (int i
= 0; i
< TYPE_NFIELDS (fp
->type
); ++i
)
15161 if (TYPE_LENGTH (TYPE_FIELD_TYPE (fp
->type
, i
)) > max
)
15162 max
= TYPE_LENGTH (TYPE_FIELD_TYPE (fp
->type
, i
));
15163 TYPE_LENGTH (fp
->type
) = max
;
15167 gdb_assert_not_reached ("missing case in dwarf2_add_field");
15170 /* Can the type given by DIE define another type? */
15173 type_can_define_types (const struct die_info
*die
)
15177 case DW_TAG_typedef
:
15178 case DW_TAG_class_type
:
15179 case DW_TAG_structure_type
:
15180 case DW_TAG_union_type
:
15181 case DW_TAG_enumeration_type
:
15189 /* Add a type definition defined in the scope of the FIP's class. */
15192 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
15193 struct dwarf2_cu
*cu
)
15195 struct decl_field fp
;
15196 memset (&fp
, 0, sizeof (fp
));
15198 gdb_assert (type_can_define_types (die
));
15200 /* Get name of field. NULL is okay here, meaning an anonymous type. */
15201 fp
.name
= dwarf2_name (die
, cu
);
15202 fp
.type
= read_type_die (die
, cu
);
15204 /* Save accessibility. */
15205 enum dwarf_access_attribute accessibility
;
15206 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15208 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15210 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15211 switch (accessibility
)
15213 case DW_ACCESS_public
:
15214 /* The assumed value if neither private nor protected. */
15216 case DW_ACCESS_private
:
15219 case DW_ACCESS_protected
:
15220 fp
.is_protected
= 1;
15223 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
15226 if (die
->tag
== DW_TAG_typedef
)
15227 fip
->typedef_field_list
.push_back (fp
);
15229 fip
->nested_types_list
.push_back (fp
);
15232 /* Create the vector of fields, and attach it to the type. */
15235 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
15236 struct dwarf2_cu
*cu
)
15238 int nfields
= fip
->nfields
;
15240 /* Record the field count, allocate space for the array of fields,
15241 and create blank accessibility bitfields if necessary. */
15242 TYPE_NFIELDS (type
) = nfields
;
15243 TYPE_FIELDS (type
) = (struct field
*)
15244 TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
);
15246 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
15248 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15250 TYPE_FIELD_PRIVATE_BITS (type
) =
15251 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15252 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
15254 TYPE_FIELD_PROTECTED_BITS (type
) =
15255 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15256 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
15258 TYPE_FIELD_IGNORE_BITS (type
) =
15259 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15260 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
15263 /* If the type has baseclasses, allocate and clear a bit vector for
15264 TYPE_FIELD_VIRTUAL_BITS. */
15265 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
15267 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
15268 unsigned char *pointer
;
15270 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15271 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
15272 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
15273 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
15274 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
15277 if (TYPE_FLAG_DISCRIMINATED_UNION (type
))
15279 struct discriminant_info
*di
= alloc_discriminant_info (type
, -1, -1);
15281 for (int index
= 0; index
< nfields
; ++index
)
15283 struct nextfield
&field
= fip
->fields
[index
];
15285 if (field
.variant
.is_discriminant
)
15286 di
->discriminant_index
= index
;
15287 else if (field
.variant
.default_branch
)
15288 di
->default_index
= index
;
15290 di
->discriminants
[index
] = field
.variant
.discriminant_value
;
15294 /* Copy the saved-up fields into the field vector. */
15295 for (int i
= 0; i
< nfields
; ++i
)
15297 struct nextfield
&field
15298 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
15299 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
15301 TYPE_FIELD (type
, i
) = field
.field
;
15302 switch (field
.accessibility
)
15304 case DW_ACCESS_private
:
15305 if (cu
->language
!= language_ada
)
15306 SET_TYPE_FIELD_PRIVATE (type
, i
);
15309 case DW_ACCESS_protected
:
15310 if (cu
->language
!= language_ada
)
15311 SET_TYPE_FIELD_PROTECTED (type
, i
);
15314 case DW_ACCESS_public
:
15318 /* Unknown accessibility. Complain and treat it as public. */
15320 complaint (_("unsupported accessibility %d"),
15321 field
.accessibility
);
15325 if (i
< fip
->baseclasses
.size ())
15327 switch (field
.virtuality
)
15329 case DW_VIRTUALITY_virtual
:
15330 case DW_VIRTUALITY_pure_virtual
:
15331 if (cu
->language
== language_ada
)
15332 error (_("unexpected virtuality in component of Ada type"));
15333 SET_TYPE_FIELD_VIRTUAL (type
, i
);
15340 /* Return true if this member function is a constructor, false
15344 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15346 const char *fieldname
;
15347 const char *type_name
;
15350 if (die
->parent
== NULL
)
15353 if (die
->parent
->tag
!= DW_TAG_structure_type
15354 && die
->parent
->tag
!= DW_TAG_union_type
15355 && die
->parent
->tag
!= DW_TAG_class_type
)
15358 fieldname
= dwarf2_name (die
, cu
);
15359 type_name
= dwarf2_name (die
->parent
, cu
);
15360 if (fieldname
== NULL
|| type_name
== NULL
)
15363 len
= strlen (fieldname
);
15364 return (strncmp (fieldname
, type_name
, len
) == 0
15365 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15368 /* Add a member function to the proper fieldlist. */
15371 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15372 struct type
*type
, struct dwarf2_cu
*cu
)
15374 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15375 struct attribute
*attr
;
15377 struct fnfieldlist
*flp
= nullptr;
15378 struct fn_field
*fnp
;
15379 const char *fieldname
;
15380 struct type
*this_type
;
15381 enum dwarf_access_attribute accessibility
;
15383 if (cu
->language
== language_ada
)
15384 error (_("unexpected member function in Ada type"));
15386 /* Get name of member function. */
15387 fieldname
= dwarf2_name (die
, cu
);
15388 if (fieldname
== NULL
)
15391 /* Look up member function name in fieldlist. */
15392 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15394 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15396 flp
= &fip
->fnfieldlists
[i
];
15401 /* Create a new fnfieldlist if necessary. */
15402 if (flp
== nullptr)
15404 fip
->fnfieldlists
.emplace_back ();
15405 flp
= &fip
->fnfieldlists
.back ();
15406 flp
->name
= fieldname
;
15407 i
= fip
->fnfieldlists
.size () - 1;
15410 /* Create a new member function field and add it to the vector of
15412 flp
->fnfields
.emplace_back ();
15413 fnp
= &flp
->fnfields
.back ();
15415 /* Delay processing of the physname until later. */
15416 if (cu
->language
== language_cplus
)
15417 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15421 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15422 fnp
->physname
= physname
? physname
: "";
15425 fnp
->type
= alloc_type (objfile
);
15426 this_type
= read_type_die (die
, cu
);
15427 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
15429 int nparams
= TYPE_NFIELDS (this_type
);
15431 /* TYPE is the domain of this method, and THIS_TYPE is the type
15432 of the method itself (TYPE_CODE_METHOD). */
15433 smash_to_method_type (fnp
->type
, type
,
15434 TYPE_TARGET_TYPE (this_type
),
15435 TYPE_FIELDS (this_type
),
15436 TYPE_NFIELDS (this_type
),
15437 TYPE_VARARGS (this_type
));
15439 /* Handle static member functions.
15440 Dwarf2 has no clean way to discern C++ static and non-static
15441 member functions. G++ helps GDB by marking the first
15442 parameter for non-static member functions (which is the this
15443 pointer) as artificial. We obtain this information from
15444 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15445 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15446 fnp
->voffset
= VOFFSET_STATIC
;
15449 complaint (_("member function type missing for '%s'"),
15450 dwarf2_full_name (fieldname
, die
, cu
));
15452 /* Get fcontext from DW_AT_containing_type if present. */
15453 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15454 fnp
->fcontext
= die_containing_type (die
, cu
);
15456 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15457 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15459 /* Get accessibility. */
15460 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15462 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15464 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15465 switch (accessibility
)
15467 case DW_ACCESS_private
:
15468 fnp
->is_private
= 1;
15470 case DW_ACCESS_protected
:
15471 fnp
->is_protected
= 1;
15475 /* Check for artificial methods. */
15476 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15477 if (attr
&& DW_UNSND (attr
) != 0)
15478 fnp
->is_artificial
= 1;
15480 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15482 /* Get index in virtual function table if it is a virtual member
15483 function. For older versions of GCC, this is an offset in the
15484 appropriate virtual table, as specified by DW_AT_containing_type.
15485 For everyone else, it is an expression to be evaluated relative
15486 to the object address. */
15488 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15491 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
15493 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
15495 /* Old-style GCC. */
15496 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
15498 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
15499 || (DW_BLOCK (attr
)->size
> 1
15500 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
15501 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
15503 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15504 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15505 dwarf2_complex_location_expr_complaint ();
15507 fnp
->voffset
/= cu
->header
.addr_size
;
15511 dwarf2_complex_location_expr_complaint ();
15513 if (!fnp
->fcontext
)
15515 /* If there is no `this' field and no DW_AT_containing_type,
15516 we cannot actually find a base class context for the
15518 if (TYPE_NFIELDS (this_type
) == 0
15519 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15521 complaint (_("cannot determine context for virtual member "
15522 "function \"%s\" (offset %s)"),
15523 fieldname
, sect_offset_str (die
->sect_off
));
15528 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
15532 else if (attr_form_is_section_offset (attr
))
15534 dwarf2_complex_location_expr_complaint ();
15538 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15544 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15545 if (attr
&& DW_UNSND (attr
))
15547 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15548 complaint (_("Member function \"%s\" (offset %s) is virtual "
15549 "but the vtable offset is not specified"),
15550 fieldname
, sect_offset_str (die
->sect_off
));
15551 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15552 TYPE_CPLUS_DYNAMIC (type
) = 1;
15557 /* Create the vector of member function fields, and attach it to the type. */
15560 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15561 struct dwarf2_cu
*cu
)
15563 if (cu
->language
== language_ada
)
15564 error (_("unexpected member functions in Ada type"));
15566 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15567 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15569 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15571 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15573 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15574 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15576 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15577 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15578 fn_flp
->fn_fields
= (struct fn_field
*)
15579 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15581 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15582 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15585 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15588 /* Returns non-zero if NAME is the name of a vtable member in CU's
15589 language, zero otherwise. */
15591 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15593 static const char vptr
[] = "_vptr";
15595 /* Look for the C++ form of the vtable. */
15596 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15602 /* GCC outputs unnamed structures that are really pointers to member
15603 functions, with the ABI-specified layout. If TYPE describes
15604 such a structure, smash it into a member function type.
15606 GCC shouldn't do this; it should just output pointer to member DIEs.
15607 This is GCC PR debug/28767. */
15610 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15612 struct type
*pfn_type
, *self_type
, *new_type
;
15614 /* Check for a structure with no name and two children. */
15615 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
15618 /* Check for __pfn and __delta members. */
15619 if (TYPE_FIELD_NAME (type
, 0) == NULL
15620 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15621 || TYPE_FIELD_NAME (type
, 1) == NULL
15622 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15625 /* Find the type of the method. */
15626 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
15627 if (pfn_type
== NULL
15628 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
15629 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
15632 /* Look for the "this" argument. */
15633 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15634 if (TYPE_NFIELDS (pfn_type
) == 0
15635 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
15636 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
15639 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
15640 new_type
= alloc_type (objfile
);
15641 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15642 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
15643 TYPE_VARARGS (pfn_type
));
15644 smash_to_methodptr_type (type
, new_type
);
15647 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15648 appropriate error checking and issuing complaints if there is a
15652 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15654 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15656 if (attr
== nullptr)
15659 if (!attr_form_is_constant (attr
))
15661 complaint (_("DW_AT_alignment must have constant form"
15662 " - DIE at %s [in module %s]"),
15663 sect_offset_str (die
->sect_off
),
15664 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15669 if (attr
->form
== DW_FORM_sdata
)
15671 LONGEST val
= DW_SND (attr
);
15674 complaint (_("DW_AT_alignment value must not be negative"
15675 " - DIE at %s [in module %s]"),
15676 sect_offset_str (die
->sect_off
),
15677 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15683 align
= DW_UNSND (attr
);
15687 complaint (_("DW_AT_alignment value must not be zero"
15688 " - DIE at %s [in module %s]"),
15689 sect_offset_str (die
->sect_off
),
15690 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15693 if ((align
& (align
- 1)) != 0)
15695 complaint (_("DW_AT_alignment value must be a power of 2"
15696 " - DIE at %s [in module %s]"),
15697 sect_offset_str (die
->sect_off
),
15698 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15705 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15706 the alignment for TYPE. */
15709 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15712 if (!set_type_align (type
, get_alignment (cu
, die
)))
15713 complaint (_("DW_AT_alignment value too large"
15714 " - DIE at %s [in module %s]"),
15715 sect_offset_str (die
->sect_off
),
15716 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15719 /* Called when we find the DIE that starts a structure or union scope
15720 (definition) to create a type for the structure or union. Fill in
15721 the type's name and general properties; the members will not be
15722 processed until process_structure_scope. A symbol table entry for
15723 the type will also not be done until process_structure_scope (assuming
15724 the type has a name).
15726 NOTE: we need to call these functions regardless of whether or not the
15727 DIE has a DW_AT_name attribute, since it might be an anonymous
15728 structure or union. This gets the type entered into our set of
15729 user defined types. */
15731 static struct type
*
15732 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15734 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15736 struct attribute
*attr
;
15739 /* If the definition of this type lives in .debug_types, read that type.
15740 Don't follow DW_AT_specification though, that will take us back up
15741 the chain and we want to go down. */
15742 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
15745 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15747 /* The type's CU may not be the same as CU.
15748 Ensure TYPE is recorded with CU in die_type_hash. */
15749 return set_die_type (die
, type
, cu
);
15752 type
= alloc_type (objfile
);
15753 INIT_CPLUS_SPECIFIC (type
);
15755 name
= dwarf2_name (die
, cu
);
15758 if (cu
->language
== language_cplus
15759 || cu
->language
== language_d
15760 || cu
->language
== language_rust
)
15762 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15764 /* dwarf2_full_name might have already finished building the DIE's
15765 type. If so, there is no need to continue. */
15766 if (get_die_type (die
, cu
) != NULL
)
15767 return get_die_type (die
, cu
);
15769 TYPE_NAME (type
) = full_name
;
15773 /* The name is already allocated along with this objfile, so
15774 we don't need to duplicate it for the type. */
15775 TYPE_NAME (type
) = name
;
15779 if (die
->tag
== DW_TAG_structure_type
)
15781 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15783 else if (die
->tag
== DW_TAG_union_type
)
15785 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15787 else if (die
->tag
== DW_TAG_variant_part
)
15789 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15790 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
15794 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15797 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15798 TYPE_DECLARED_CLASS (type
) = 1;
15800 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15803 if (attr_form_is_constant (attr
))
15804 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15807 /* For the moment, dynamic type sizes are not supported
15808 by GDB's struct type. The actual size is determined
15809 on-demand when resolving the type of a given object,
15810 so set the type's length to zero for now. Otherwise,
15811 we record an expression as the length, and that expression
15812 could lead to a very large value, which could eventually
15813 lead to us trying to allocate that much memory when creating
15814 a value of that type. */
15815 TYPE_LENGTH (type
) = 0;
15820 TYPE_LENGTH (type
) = 0;
15823 maybe_set_alignment (cu
, die
, type
);
15825 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15827 /* ICC<14 does not output the required DW_AT_declaration on
15828 incomplete types, but gives them a size of zero. */
15829 TYPE_STUB (type
) = 1;
15832 TYPE_STUB_SUPPORTED (type
) = 1;
15834 if (die_is_declaration (die
, cu
))
15835 TYPE_STUB (type
) = 1;
15836 else if (attr
== NULL
&& die
->child
== NULL
15837 && producer_is_realview (cu
->producer
))
15838 /* RealView does not output the required DW_AT_declaration
15839 on incomplete types. */
15840 TYPE_STUB (type
) = 1;
15842 /* We need to add the type field to the die immediately so we don't
15843 infinitely recurse when dealing with pointers to the structure
15844 type within the structure itself. */
15845 set_die_type (die
, type
, cu
);
15847 /* set_die_type should be already done. */
15848 set_descriptive_type (type
, die
, cu
);
15853 /* A helper for process_structure_scope that handles a single member
15857 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15858 struct field_info
*fi
,
15859 std::vector
<struct symbol
*> *template_args
,
15860 struct dwarf2_cu
*cu
)
15862 if (child_die
->tag
== DW_TAG_member
15863 || child_die
->tag
== DW_TAG_variable
15864 || child_die
->tag
== DW_TAG_variant_part
)
15866 /* NOTE: carlton/2002-11-05: A C++ static data member
15867 should be a DW_TAG_member that is a declaration, but
15868 all versions of G++ as of this writing (so through at
15869 least 3.2.1) incorrectly generate DW_TAG_variable
15870 tags for them instead. */
15871 dwarf2_add_field (fi
, child_die
, cu
);
15873 else if (child_die
->tag
== DW_TAG_subprogram
)
15875 /* Rust doesn't have member functions in the C++ sense.
15876 However, it does emit ordinary functions as children
15877 of a struct DIE. */
15878 if (cu
->language
== language_rust
)
15879 read_func_scope (child_die
, cu
);
15882 /* C++ member function. */
15883 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15886 else if (child_die
->tag
== DW_TAG_inheritance
)
15888 /* C++ base class field. */
15889 dwarf2_add_field (fi
, child_die
, cu
);
15891 else if (type_can_define_types (child_die
))
15892 dwarf2_add_type_defn (fi
, child_die
, cu
);
15893 else if (child_die
->tag
== DW_TAG_template_type_param
15894 || child_die
->tag
== DW_TAG_template_value_param
)
15896 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15899 template_args
->push_back (arg
);
15901 else if (child_die
->tag
== DW_TAG_variant
)
15903 /* In a variant we want to get the discriminant and also add a
15904 field for our sole member child. */
15905 struct attribute
*discr
= dwarf2_attr (child_die
, DW_AT_discr_value
, cu
);
15907 for (die_info
*variant_child
= child_die
->child
;
15908 variant_child
!= NULL
;
15909 variant_child
= sibling_die (variant_child
))
15911 if (variant_child
->tag
== DW_TAG_member
)
15913 handle_struct_member_die (variant_child
, type
, fi
,
15914 template_args
, cu
);
15915 /* Only handle the one. */
15920 /* We don't handle this but we might as well report it if we see
15922 if (dwarf2_attr (child_die
, DW_AT_discr_list
, cu
) != nullptr)
15923 complaint (_("DW_AT_discr_list is not supported yet"
15924 " - DIE at %s [in module %s]"),
15925 sect_offset_str (child_die
->sect_off
),
15926 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15928 /* The first field was just added, so we can stash the
15929 discriminant there. */
15930 gdb_assert (!fi
->fields
.empty ());
15932 fi
->fields
.back ().variant
.default_branch
= true;
15934 fi
->fields
.back ().variant
.discriminant_value
= DW_UNSND (discr
);
15938 /* Finish creating a structure or union type, including filling in
15939 its members and creating a symbol for it. */
15942 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15944 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15945 struct die_info
*child_die
;
15948 type
= get_die_type (die
, cu
);
15950 type
= read_structure_type (die
, cu
);
15952 /* When reading a DW_TAG_variant_part, we need to notice when we
15953 read the discriminant member, so we can record it later in the
15954 discriminant_info. */
15955 bool is_variant_part
= TYPE_FLAG_DISCRIMINATED_UNION (type
);
15956 sect_offset discr_offset
;
15957 bool has_template_parameters
= false;
15959 if (is_variant_part
)
15961 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15964 /* Maybe it's a univariant form, an extension we support.
15965 In this case arrange not to check the offset. */
15966 is_variant_part
= false;
15968 else if (attr_form_is_ref (discr
))
15970 struct dwarf2_cu
*target_cu
= cu
;
15971 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15973 discr_offset
= target_die
->sect_off
;
15977 complaint (_("DW_AT_discr does not have DIE reference form"
15978 " - DIE at %s [in module %s]"),
15979 sect_offset_str (die
->sect_off
),
15980 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15981 is_variant_part
= false;
15985 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15987 struct field_info fi
;
15988 std::vector
<struct symbol
*> template_args
;
15990 child_die
= die
->child
;
15992 while (child_die
&& child_die
->tag
)
15994 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15996 if (is_variant_part
&& discr_offset
== child_die
->sect_off
)
15997 fi
.fields
.back ().variant
.is_discriminant
= true;
15999 child_die
= sibling_die (child_die
);
16002 /* Attach template arguments to type. */
16003 if (!template_args
.empty ())
16005 has_template_parameters
= true;
16006 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16007 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
16008 TYPE_TEMPLATE_ARGUMENTS (type
)
16009 = XOBNEWVEC (&objfile
->objfile_obstack
,
16011 TYPE_N_TEMPLATE_ARGUMENTS (type
));
16012 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
16013 template_args
.data (),
16014 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
16015 * sizeof (struct symbol
*)));
16018 /* Attach fields and member functions to the type. */
16020 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
16021 if (!fi
.fnfieldlists
.empty ())
16023 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
16025 /* Get the type which refers to the base class (possibly this
16026 class itself) which contains the vtable pointer for the current
16027 class from the DW_AT_containing_type attribute. This use of
16028 DW_AT_containing_type is a GNU extension. */
16030 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
16032 struct type
*t
= die_containing_type (die
, cu
);
16034 set_type_vptr_basetype (type
, t
);
16039 /* Our own class provides vtbl ptr. */
16040 for (i
= TYPE_NFIELDS (t
) - 1;
16041 i
>= TYPE_N_BASECLASSES (t
);
16044 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
16046 if (is_vtable_name (fieldname
, cu
))
16048 set_type_vptr_fieldno (type
, i
);
16053 /* Complain if virtual function table field not found. */
16054 if (i
< TYPE_N_BASECLASSES (t
))
16055 complaint (_("virtual function table pointer "
16056 "not found when defining class '%s'"),
16057 TYPE_NAME (type
) ? TYPE_NAME (type
) : "");
16061 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
16064 else if (cu
->producer
16065 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
16067 /* The IBM XLC compiler does not provide direct indication
16068 of the containing type, but the vtable pointer is
16069 always named __vfp. */
16073 for (i
= TYPE_NFIELDS (type
) - 1;
16074 i
>= TYPE_N_BASECLASSES (type
);
16077 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
16079 set_type_vptr_fieldno (type
, i
);
16080 set_type_vptr_basetype (type
, type
);
16087 /* Copy fi.typedef_field_list linked list elements content into the
16088 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
16089 if (!fi
.typedef_field_list
.empty ())
16091 int count
= fi
.typedef_field_list
.size ();
16093 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16094 TYPE_TYPEDEF_FIELD_ARRAY (type
)
16095 = ((struct decl_field
*)
16097 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
16098 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
16100 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
16101 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
16104 /* Copy fi.nested_types_list linked list elements content into the
16105 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
16106 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
16108 int count
= fi
.nested_types_list
.size ();
16110 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16111 TYPE_NESTED_TYPES_ARRAY (type
)
16112 = ((struct decl_field
*)
16113 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
16114 TYPE_NESTED_TYPES_COUNT (type
) = count
;
16116 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
16117 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
16121 quirk_gcc_member_function_pointer (type
, objfile
);
16122 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
16123 cu
->rust_unions
.push_back (type
);
16125 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
16126 snapshots) has been known to create a die giving a declaration
16127 for a class that has, as a child, a die giving a definition for a
16128 nested class. So we have to process our children even if the
16129 current die is a declaration. Normally, of course, a declaration
16130 won't have any children at all. */
16132 child_die
= die
->child
;
16134 while (child_die
!= NULL
&& child_die
->tag
)
16136 if (child_die
->tag
== DW_TAG_member
16137 || child_die
->tag
== DW_TAG_variable
16138 || child_die
->tag
== DW_TAG_inheritance
16139 || child_die
->tag
== DW_TAG_template_value_param
16140 || child_die
->tag
== DW_TAG_template_type_param
)
16145 process_die (child_die
, cu
);
16147 child_die
= sibling_die (child_die
);
16150 /* Do not consider external references. According to the DWARF standard,
16151 these DIEs are identified by the fact that they have no byte_size
16152 attribute, and a declaration attribute. */
16153 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
16154 || !die_is_declaration (die
, cu
))
16156 struct symbol
*sym
= new_symbol (die
, type
, cu
);
16158 if (has_template_parameters
)
16160 struct symtab
*symtab
;
16161 if (sym
!= nullptr)
16162 symtab
= symbol_symtab (sym
);
16163 else if (cu
->line_header
!= nullptr)
16165 /* Any related symtab will do. */
16167 = cu
->line_header
->file_name_at (file_name_index (1))->symtab
;
16172 complaint (_("could not find suitable "
16173 "symtab for template parameter"
16174 " - DIE at %s [in module %s]"),
16175 sect_offset_str (die
->sect_off
),
16176 objfile_name (objfile
));
16179 if (symtab
!= nullptr)
16181 /* Make sure that the symtab is set on the new symbols.
16182 Even though they don't appear in this symtab directly,
16183 other parts of gdb assume that symbols do, and this is
16184 reasonably true. */
16185 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
16186 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
16192 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
16193 update TYPE using some information only available in DIE's children. */
16196 update_enumeration_type_from_children (struct die_info
*die
,
16198 struct dwarf2_cu
*cu
)
16200 struct die_info
*child_die
;
16201 int unsigned_enum
= 1;
16205 auto_obstack obstack
;
16207 for (child_die
= die
->child
;
16208 child_die
!= NULL
&& child_die
->tag
;
16209 child_die
= sibling_die (child_die
))
16211 struct attribute
*attr
;
16213 const gdb_byte
*bytes
;
16214 struct dwarf2_locexpr_baton
*baton
;
16217 if (child_die
->tag
!= DW_TAG_enumerator
)
16220 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16224 name
= dwarf2_name (child_die
, cu
);
16226 name
= "<anonymous enumerator>";
16228 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16229 &value
, &bytes
, &baton
);
16235 else if ((mask
& value
) != 0)
16240 /* If we already know that the enum type is neither unsigned, nor
16241 a flag type, no need to look at the rest of the enumerates. */
16242 if (!unsigned_enum
&& !flag_enum
)
16247 TYPE_UNSIGNED (type
) = 1;
16249 TYPE_FLAG_ENUM (type
) = 1;
16252 /* Given a DW_AT_enumeration_type die, set its type. We do not
16253 complete the type's fields yet, or create any symbols. */
16255 static struct type
*
16256 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16258 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16260 struct attribute
*attr
;
16263 /* If the definition of this type lives in .debug_types, read that type.
16264 Don't follow DW_AT_specification though, that will take us back up
16265 the chain and we want to go down. */
16266 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
16269 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16271 /* The type's CU may not be the same as CU.
16272 Ensure TYPE is recorded with CU in die_type_hash. */
16273 return set_die_type (die
, type
, cu
);
16276 type
= alloc_type (objfile
);
16278 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
16279 name
= dwarf2_full_name (NULL
, die
, cu
);
16281 TYPE_NAME (type
) = name
;
16283 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16286 struct type
*underlying_type
= die_type (die
, cu
);
16288 TYPE_TARGET_TYPE (type
) = underlying_type
;
16291 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16294 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16298 TYPE_LENGTH (type
) = 0;
16301 maybe_set_alignment (cu
, die
, type
);
16303 /* The enumeration DIE can be incomplete. In Ada, any type can be
16304 declared as private in the package spec, and then defined only
16305 inside the package body. Such types are known as Taft Amendment
16306 Types. When another package uses such a type, an incomplete DIE
16307 may be generated by the compiler. */
16308 if (die_is_declaration (die
, cu
))
16309 TYPE_STUB (type
) = 1;
16311 /* Finish the creation of this type by using the enum's children.
16312 We must call this even when the underlying type has been provided
16313 so that we can determine if we're looking at a "flag" enum. */
16314 update_enumeration_type_from_children (die
, type
, cu
);
16316 /* If this type has an underlying type that is not a stub, then we
16317 may use its attributes. We always use the "unsigned" attribute
16318 in this situation, because ordinarily we guess whether the type
16319 is unsigned -- but the guess can be wrong and the underlying type
16320 can tell us the reality. However, we defer to a local size
16321 attribute if one exists, because this lets the compiler override
16322 the underlying type if needed. */
16323 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
16325 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
16326 if (TYPE_LENGTH (type
) == 0)
16327 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
16328 if (TYPE_RAW_ALIGN (type
) == 0
16329 && TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)) != 0)
16330 set_type_align (type
, TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)));
16333 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16335 return set_die_type (die
, type
, cu
);
16338 /* Given a pointer to a die which begins an enumeration, process all
16339 the dies that define the members of the enumeration, and create the
16340 symbol for the enumeration type.
16342 NOTE: We reverse the order of the element list. */
16345 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16347 struct type
*this_type
;
16349 this_type
= get_die_type (die
, cu
);
16350 if (this_type
== NULL
)
16351 this_type
= read_enumeration_type (die
, cu
);
16353 if (die
->child
!= NULL
)
16355 struct die_info
*child_die
;
16356 struct symbol
*sym
;
16357 struct field
*fields
= NULL
;
16358 int num_fields
= 0;
16361 child_die
= die
->child
;
16362 while (child_die
&& child_die
->tag
)
16364 if (child_die
->tag
!= DW_TAG_enumerator
)
16366 process_die (child_die
, cu
);
16370 name
= dwarf2_name (child_die
, cu
);
16373 sym
= new_symbol (child_die
, this_type
, cu
);
16375 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
16377 fields
= (struct field
*)
16379 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
16380 * sizeof (struct field
));
16383 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
16384 FIELD_TYPE (fields
[num_fields
]) = NULL
;
16385 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
16386 FIELD_BITSIZE (fields
[num_fields
]) = 0;
16392 child_die
= sibling_die (child_die
);
16397 TYPE_NFIELDS (this_type
) = num_fields
;
16398 TYPE_FIELDS (this_type
) = (struct field
*)
16399 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
16400 memcpy (TYPE_FIELDS (this_type
), fields
,
16401 sizeof (struct field
) * num_fields
);
16406 /* If we are reading an enum from a .debug_types unit, and the enum
16407 is a declaration, and the enum is not the signatured type in the
16408 unit, then we do not want to add a symbol for it. Adding a
16409 symbol would in some cases obscure the true definition of the
16410 enum, giving users an incomplete type when the definition is
16411 actually available. Note that we do not want to do this for all
16412 enums which are just declarations, because C++0x allows forward
16413 enum declarations. */
16414 if (cu
->per_cu
->is_debug_types
16415 && die_is_declaration (die
, cu
))
16417 struct signatured_type
*sig_type
;
16419 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16420 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16421 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16425 new_symbol (die
, this_type
, cu
);
16428 /* Extract all information from a DW_TAG_array_type DIE and put it in
16429 the DIE's type field. For now, this only handles one dimensional
16432 static struct type
*
16433 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16435 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16436 struct die_info
*child_die
;
16438 struct type
*element_type
, *range_type
, *index_type
;
16439 struct attribute
*attr
;
16441 struct dynamic_prop
*byte_stride_prop
= NULL
;
16442 unsigned int bit_stride
= 0;
16444 element_type
= die_type (die
, cu
);
16446 /* The die_type call above may have already set the type for this DIE. */
16447 type
= get_die_type (die
, cu
);
16451 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16455 struct type
*prop_type
16456 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
16459 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16460 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
16464 complaint (_("unable to read array DW_AT_byte_stride "
16465 " - DIE at %s [in module %s]"),
16466 sect_offset_str (die
->sect_off
),
16467 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16468 /* Ignore this attribute. We will likely not be able to print
16469 arrays of this type correctly, but there is little we can do
16470 to help if we cannot read the attribute's value. */
16471 byte_stride_prop
= NULL
;
16475 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16477 bit_stride
= DW_UNSND (attr
);
16479 /* Irix 6.2 native cc creates array types without children for
16480 arrays with unspecified length. */
16481 if (die
->child
== NULL
)
16483 index_type
= objfile_type (objfile
)->builtin_int
;
16484 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16485 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16486 byte_stride_prop
, bit_stride
);
16487 return set_die_type (die
, type
, cu
);
16490 std::vector
<struct type
*> range_types
;
16491 child_die
= die
->child
;
16492 while (child_die
&& child_die
->tag
)
16494 if (child_die
->tag
== DW_TAG_subrange_type
)
16496 struct type
*child_type
= read_type_die (child_die
, cu
);
16498 if (child_type
!= NULL
)
16500 /* The range type was succesfully read. Save it for the
16501 array type creation. */
16502 range_types
.push_back (child_type
);
16505 child_die
= sibling_die (child_die
);
16508 /* Dwarf2 dimensions are output from left to right, create the
16509 necessary array types in backwards order. */
16511 type
= element_type
;
16513 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16517 while (i
< range_types
.size ())
16518 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16519 byte_stride_prop
, bit_stride
);
16523 size_t ndim
= range_types
.size ();
16525 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16526 byte_stride_prop
, bit_stride
);
16529 /* Understand Dwarf2 support for vector types (like they occur on
16530 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16531 array type. This is not part of the Dwarf2/3 standard yet, but a
16532 custom vendor extension. The main difference between a regular
16533 array and the vector variant is that vectors are passed by value
16535 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16537 make_vector_type (type
);
16539 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16540 implementation may choose to implement triple vectors using this
16542 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16545 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
16546 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16548 complaint (_("DW_AT_byte_size for array type smaller "
16549 "than the total size of elements"));
16552 name
= dwarf2_name (die
, cu
);
16554 TYPE_NAME (type
) = name
;
16556 maybe_set_alignment (cu
, die
, type
);
16558 /* Install the type in the die. */
16559 set_die_type (die
, type
, cu
);
16561 /* set_die_type should be already done. */
16562 set_descriptive_type (type
, die
, cu
);
16567 static enum dwarf_array_dim_ordering
16568 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16570 struct attribute
*attr
;
16572 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16575 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
16577 /* GNU F77 is a special case, as at 08/2004 array type info is the
16578 opposite order to the dwarf2 specification, but data is still
16579 laid out as per normal fortran.
16581 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16582 version checking. */
16584 if (cu
->language
== language_fortran
16585 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16587 return DW_ORD_row_major
;
16590 switch (cu
->language_defn
->la_array_ordering
)
16592 case array_column_major
:
16593 return DW_ORD_col_major
;
16594 case array_row_major
:
16596 return DW_ORD_row_major
;
16600 /* Extract all information from a DW_TAG_set_type DIE and put it in
16601 the DIE's type field. */
16603 static struct type
*
16604 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16606 struct type
*domain_type
, *set_type
;
16607 struct attribute
*attr
;
16609 domain_type
= die_type (die
, cu
);
16611 /* The die_type call above may have already set the type for this DIE. */
16612 set_type
= get_die_type (die
, cu
);
16616 set_type
= create_set_type (NULL
, domain_type
);
16618 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16620 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
16622 maybe_set_alignment (cu
, die
, set_type
);
16624 return set_die_type (die
, set_type
, cu
);
16627 /* A helper for read_common_block that creates a locexpr baton.
16628 SYM is the symbol which we are marking as computed.
16629 COMMON_DIE is the DIE for the common block.
16630 COMMON_LOC is the location expression attribute for the common
16632 MEMBER_LOC is the location expression attribute for the particular
16633 member of the common block that we are processing.
16634 CU is the CU from which the above come. */
16637 mark_common_block_symbol_computed (struct symbol
*sym
,
16638 struct die_info
*common_die
,
16639 struct attribute
*common_loc
,
16640 struct attribute
*member_loc
,
16641 struct dwarf2_cu
*cu
)
16643 struct dwarf2_per_objfile
*dwarf2_per_objfile
16644 = cu
->per_cu
->dwarf2_per_objfile
;
16645 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16646 struct dwarf2_locexpr_baton
*baton
;
16648 unsigned int cu_off
;
16649 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
16650 LONGEST offset
= 0;
16652 gdb_assert (common_loc
&& member_loc
);
16653 gdb_assert (attr_form_is_block (common_loc
));
16654 gdb_assert (attr_form_is_block (member_loc
)
16655 || attr_form_is_constant (member_loc
));
16657 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16658 baton
->per_cu
= cu
->per_cu
;
16659 gdb_assert (baton
->per_cu
);
16661 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16663 if (attr_form_is_constant (member_loc
))
16665 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
16666 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16669 baton
->size
+= DW_BLOCK (member_loc
)->size
;
16671 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16674 *ptr
++ = DW_OP_call4
;
16675 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16676 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16679 if (attr_form_is_constant (member_loc
))
16681 *ptr
++ = DW_OP_addr
;
16682 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16683 ptr
+= cu
->header
.addr_size
;
16687 /* We have to copy the data here, because DW_OP_call4 will only
16688 use a DW_AT_location attribute. */
16689 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
16690 ptr
+= DW_BLOCK (member_loc
)->size
;
16693 *ptr
++ = DW_OP_plus
;
16694 gdb_assert (ptr
- baton
->data
== baton
->size
);
16696 SYMBOL_LOCATION_BATON (sym
) = baton
;
16697 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16700 /* Create appropriate locally-scoped variables for all the
16701 DW_TAG_common_block entries. Also create a struct common_block
16702 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16703 is used to sepate the common blocks name namespace from regular
16707 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16709 struct attribute
*attr
;
16711 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16714 /* Support the .debug_loc offsets. */
16715 if (attr_form_is_block (attr
))
16719 else if (attr_form_is_section_offset (attr
))
16721 dwarf2_complex_location_expr_complaint ();
16726 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16727 "common block member");
16732 if (die
->child
!= NULL
)
16734 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16735 struct die_info
*child_die
;
16736 size_t n_entries
= 0, size
;
16737 struct common_block
*common_block
;
16738 struct symbol
*sym
;
16740 for (child_die
= die
->child
;
16741 child_die
&& child_die
->tag
;
16742 child_die
= sibling_die (child_die
))
16745 size
= (sizeof (struct common_block
)
16746 + (n_entries
- 1) * sizeof (struct symbol
*));
16748 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16750 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16751 common_block
->n_entries
= 0;
16753 for (child_die
= die
->child
;
16754 child_die
&& child_die
->tag
;
16755 child_die
= sibling_die (child_die
))
16757 /* Create the symbol in the DW_TAG_common_block block in the current
16759 sym
= new_symbol (child_die
, NULL
, cu
);
16762 struct attribute
*member_loc
;
16764 common_block
->contents
[common_block
->n_entries
++] = sym
;
16766 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16770 /* GDB has handled this for a long time, but it is
16771 not specified by DWARF. It seems to have been
16772 emitted by gfortran at least as recently as:
16773 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16774 complaint (_("Variable in common block has "
16775 "DW_AT_data_member_location "
16776 "- DIE at %s [in module %s]"),
16777 sect_offset_str (child_die
->sect_off
),
16778 objfile_name (objfile
));
16780 if (attr_form_is_section_offset (member_loc
))
16781 dwarf2_complex_location_expr_complaint ();
16782 else if (attr_form_is_constant (member_loc
)
16783 || attr_form_is_block (member_loc
))
16786 mark_common_block_symbol_computed (sym
, die
, attr
,
16790 dwarf2_complex_location_expr_complaint ();
16795 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16796 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16800 /* Create a type for a C++ namespace. */
16802 static struct type
*
16803 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16805 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16806 const char *previous_prefix
, *name
;
16810 /* For extensions, reuse the type of the original namespace. */
16811 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16813 struct die_info
*ext_die
;
16814 struct dwarf2_cu
*ext_cu
= cu
;
16816 ext_die
= dwarf2_extension (die
, &ext_cu
);
16817 type
= read_type_die (ext_die
, ext_cu
);
16819 /* EXT_CU may not be the same as CU.
16820 Ensure TYPE is recorded with CU in die_type_hash. */
16821 return set_die_type (die
, type
, cu
);
16824 name
= namespace_name (die
, &is_anonymous
, cu
);
16826 /* Now build the name of the current namespace. */
16828 previous_prefix
= determine_prefix (die
, cu
);
16829 if (previous_prefix
[0] != '\0')
16830 name
= typename_concat (&objfile
->objfile_obstack
,
16831 previous_prefix
, name
, 0, cu
);
16833 /* Create the type. */
16834 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16836 return set_die_type (die
, type
, cu
);
16839 /* Read a namespace scope. */
16842 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16844 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16847 /* Add a symbol associated to this if we haven't seen the namespace
16848 before. Also, add a using directive if it's an anonymous
16851 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16855 type
= read_type_die (die
, cu
);
16856 new_symbol (die
, type
, cu
);
16858 namespace_name (die
, &is_anonymous
, cu
);
16861 const char *previous_prefix
= determine_prefix (die
, cu
);
16863 std::vector
<const char *> excludes
;
16864 add_using_directive (using_directives (cu
),
16865 previous_prefix
, TYPE_NAME (type
), NULL
,
16866 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16870 if (die
->child
!= NULL
)
16872 struct die_info
*child_die
= die
->child
;
16874 while (child_die
&& child_die
->tag
)
16876 process_die (child_die
, cu
);
16877 child_die
= sibling_die (child_die
);
16882 /* Read a Fortran module as type. This DIE can be only a declaration used for
16883 imported module. Still we need that type as local Fortran "use ... only"
16884 declaration imports depend on the created type in determine_prefix. */
16886 static struct type
*
16887 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16889 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16890 const char *module_name
;
16893 module_name
= dwarf2_name (die
, cu
);
16894 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16896 return set_die_type (die
, type
, cu
);
16899 /* Read a Fortran module. */
16902 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16904 struct die_info
*child_die
= die
->child
;
16907 type
= read_type_die (die
, cu
);
16908 new_symbol (die
, type
, cu
);
16910 while (child_die
&& child_die
->tag
)
16912 process_die (child_die
, cu
);
16913 child_die
= sibling_die (child_die
);
16917 /* Return the name of the namespace represented by DIE. Set
16918 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16921 static const char *
16922 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16924 struct die_info
*current_die
;
16925 const char *name
= NULL
;
16927 /* Loop through the extensions until we find a name. */
16929 for (current_die
= die
;
16930 current_die
!= NULL
;
16931 current_die
= dwarf2_extension (die
, &cu
))
16933 /* We don't use dwarf2_name here so that we can detect the absence
16934 of a name -> anonymous namespace. */
16935 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16941 /* Is it an anonymous namespace? */
16943 *is_anonymous
= (name
== NULL
);
16945 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16950 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16951 the user defined type vector. */
16953 static struct type
*
16954 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16956 struct gdbarch
*gdbarch
16957 = get_objfile_arch (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16958 struct comp_unit_head
*cu_header
= &cu
->header
;
16960 struct attribute
*attr_byte_size
;
16961 struct attribute
*attr_address_class
;
16962 int byte_size
, addr_class
;
16963 struct type
*target_type
;
16965 target_type
= die_type (die
, cu
);
16967 /* The die_type call above may have already set the type for this DIE. */
16968 type
= get_die_type (die
, cu
);
16972 type
= lookup_pointer_type (target_type
);
16974 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16975 if (attr_byte_size
)
16976 byte_size
= DW_UNSND (attr_byte_size
);
16978 byte_size
= cu_header
->addr_size
;
16980 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
16981 if (attr_address_class
)
16982 addr_class
= DW_UNSND (attr_address_class
);
16984 addr_class
= DW_ADDR_none
;
16986 ULONGEST alignment
= get_alignment (cu
, die
);
16988 /* If the pointer size, alignment, or address class is different
16989 than the default, create a type variant marked as such and set
16990 the length accordingly. */
16991 if (TYPE_LENGTH (type
) != byte_size
16992 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
16993 && alignment
!= TYPE_RAW_ALIGN (type
))
16994 || addr_class
!= DW_ADDR_none
)
16996 if (gdbarch_address_class_type_flags_p (gdbarch
))
17000 type_flags
= gdbarch_address_class_type_flags
17001 (gdbarch
, byte_size
, addr_class
);
17002 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
17004 type
= make_type_with_address_space (type
, type_flags
);
17006 else if (TYPE_LENGTH (type
) != byte_size
)
17008 complaint (_("invalid pointer size %d"), byte_size
);
17010 else if (TYPE_RAW_ALIGN (type
) != alignment
)
17012 complaint (_("Invalid DW_AT_alignment"
17013 " - DIE at %s [in module %s]"),
17014 sect_offset_str (die
->sect_off
),
17015 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17019 /* Should we also complain about unhandled address classes? */
17023 TYPE_LENGTH (type
) = byte_size
;
17024 set_type_align (type
, alignment
);
17025 return set_die_type (die
, type
, cu
);
17028 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
17029 the user defined type vector. */
17031 static struct type
*
17032 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17035 struct type
*to_type
;
17036 struct type
*domain
;
17038 to_type
= die_type (die
, cu
);
17039 domain
= die_containing_type (die
, cu
);
17041 /* The calls above may have already set the type for this DIE. */
17042 type
= get_die_type (die
, cu
);
17046 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
17047 type
= lookup_methodptr_type (to_type
);
17048 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
17050 struct type
*new_type
17051 = alloc_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
17053 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
17054 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
17055 TYPE_VARARGS (to_type
));
17056 type
= lookup_methodptr_type (new_type
);
17059 type
= lookup_memberptr_type (to_type
, domain
);
17061 return set_die_type (die
, type
, cu
);
17064 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
17065 the user defined type vector. */
17067 static struct type
*
17068 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17069 enum type_code refcode
)
17071 struct comp_unit_head
*cu_header
= &cu
->header
;
17072 struct type
*type
, *target_type
;
17073 struct attribute
*attr
;
17075 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
17077 target_type
= die_type (die
, cu
);
17079 /* The die_type call above may have already set the type for this DIE. */
17080 type
= get_die_type (die
, cu
);
17084 type
= lookup_reference_type (target_type
, refcode
);
17085 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17088 TYPE_LENGTH (type
) = DW_UNSND (attr
);
17092 TYPE_LENGTH (type
) = cu_header
->addr_size
;
17094 maybe_set_alignment (cu
, die
, type
);
17095 return set_die_type (die
, type
, cu
);
17098 /* Add the given cv-qualifiers to the element type of the array. GCC
17099 outputs DWARF type qualifiers that apply to an array, not the
17100 element type. But GDB relies on the array element type to carry
17101 the cv-qualifiers. This mimics section 6.7.3 of the C99
17104 static struct type
*
17105 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17106 struct type
*base_type
, int cnst
, int voltl
)
17108 struct type
*el_type
, *inner_array
;
17110 base_type
= copy_type (base_type
);
17111 inner_array
= base_type
;
17113 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
17115 TYPE_TARGET_TYPE (inner_array
) =
17116 copy_type (TYPE_TARGET_TYPE (inner_array
));
17117 inner_array
= TYPE_TARGET_TYPE (inner_array
);
17120 el_type
= TYPE_TARGET_TYPE (inner_array
);
17121 cnst
|= TYPE_CONST (el_type
);
17122 voltl
|= TYPE_VOLATILE (el_type
);
17123 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
17125 return set_die_type (die
, base_type
, cu
);
17128 static struct type
*
17129 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17131 struct type
*base_type
, *cv_type
;
17133 base_type
= die_type (die
, cu
);
17135 /* The die_type call above may have already set the type for this DIE. */
17136 cv_type
= get_die_type (die
, cu
);
17140 /* In case the const qualifier is applied to an array type, the element type
17141 is so qualified, not the array type (section 6.7.3 of C99). */
17142 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
17143 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
17145 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
17146 return set_die_type (die
, cv_type
, cu
);
17149 static struct type
*
17150 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17152 struct type
*base_type
, *cv_type
;
17154 base_type
= die_type (die
, cu
);
17156 /* The die_type call above may have already set the type for this DIE. */
17157 cv_type
= get_die_type (die
, cu
);
17161 /* In case the volatile qualifier is applied to an array type, the
17162 element type is so qualified, not the array type (section 6.7.3
17164 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
17165 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17167 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17168 return set_die_type (die
, cv_type
, cu
);
17171 /* Handle DW_TAG_restrict_type. */
17173 static struct type
*
17174 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17176 struct type
*base_type
, *cv_type
;
17178 base_type
= die_type (die
, cu
);
17180 /* The die_type call above may have already set the type for this DIE. */
17181 cv_type
= get_die_type (die
, cu
);
17185 cv_type
= make_restrict_type (base_type
);
17186 return set_die_type (die
, cv_type
, cu
);
17189 /* Handle DW_TAG_atomic_type. */
17191 static struct type
*
17192 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17194 struct type
*base_type
, *cv_type
;
17196 base_type
= die_type (die
, cu
);
17198 /* The die_type call above may have already set the type for this DIE. */
17199 cv_type
= get_die_type (die
, cu
);
17203 cv_type
= make_atomic_type (base_type
);
17204 return set_die_type (die
, cv_type
, cu
);
17207 /* Extract all information from a DW_TAG_string_type DIE and add to
17208 the user defined type vector. It isn't really a user defined type,
17209 but it behaves like one, with other DIE's using an AT_user_def_type
17210 attribute to reference it. */
17212 static struct type
*
17213 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17215 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17216 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17217 struct type
*type
, *range_type
, *index_type
, *char_type
;
17218 struct attribute
*attr
;
17219 unsigned int length
;
17221 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17224 length
= DW_UNSND (attr
);
17228 /* Check for the DW_AT_byte_size attribute. */
17229 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17232 length
= DW_UNSND (attr
);
17240 index_type
= objfile_type (objfile
)->builtin_int
;
17241 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17242 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17243 type
= create_string_type (NULL
, char_type
, range_type
);
17245 return set_die_type (die
, type
, cu
);
17248 /* Assuming that DIE corresponds to a function, returns nonzero
17249 if the function is prototyped. */
17252 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17254 struct attribute
*attr
;
17256 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17257 if (attr
&& (DW_UNSND (attr
) != 0))
17260 /* The DWARF standard implies that the DW_AT_prototyped attribute
17261 is only meaninful for C, but the concept also extends to other
17262 languages that allow unprototyped functions (Eg: Objective C).
17263 For all other languages, assume that functions are always
17265 if (cu
->language
!= language_c
17266 && cu
->language
!= language_objc
17267 && cu
->language
!= language_opencl
)
17270 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17271 prototyped and unprototyped functions; default to prototyped,
17272 since that is more common in modern code (and RealView warns
17273 about unprototyped functions). */
17274 if (producer_is_realview (cu
->producer
))
17280 /* Handle DIES due to C code like:
17284 int (*funcp)(int a, long l);
17288 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17290 static struct type
*
17291 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17293 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17294 struct type
*type
; /* Type that this function returns. */
17295 struct type
*ftype
; /* Function that returns above type. */
17296 struct attribute
*attr
;
17298 type
= die_type (die
, cu
);
17300 /* The die_type call above may have already set the type for this DIE. */
17301 ftype
= get_die_type (die
, cu
);
17305 ftype
= lookup_function_type (type
);
17307 if (prototyped_function_p (die
, cu
))
17308 TYPE_PROTOTYPED (ftype
) = 1;
17310 /* Store the calling convention in the type if it's available in
17311 the subroutine die. Otherwise set the calling convention to
17312 the default value DW_CC_normal. */
17313 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17315 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
17316 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17317 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17319 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17321 /* Record whether the function returns normally to its caller or not
17322 if the DWARF producer set that information. */
17323 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17324 if (attr
&& (DW_UNSND (attr
) != 0))
17325 TYPE_NO_RETURN (ftype
) = 1;
17327 /* We need to add the subroutine type to the die immediately so
17328 we don't infinitely recurse when dealing with parameters
17329 declared as the same subroutine type. */
17330 set_die_type (die
, ftype
, cu
);
17332 if (die
->child
!= NULL
)
17334 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17335 struct die_info
*child_die
;
17336 int nparams
, iparams
;
17338 /* Count the number of parameters.
17339 FIXME: GDB currently ignores vararg functions, but knows about
17340 vararg member functions. */
17342 child_die
= die
->child
;
17343 while (child_die
&& child_die
->tag
)
17345 if (child_die
->tag
== DW_TAG_formal_parameter
)
17347 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17348 TYPE_VARARGS (ftype
) = 1;
17349 child_die
= sibling_die (child_die
);
17352 /* Allocate storage for parameters and fill them in. */
17353 TYPE_NFIELDS (ftype
) = nparams
;
17354 TYPE_FIELDS (ftype
) = (struct field
*)
17355 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
17357 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17358 even if we error out during the parameters reading below. */
17359 for (iparams
= 0; iparams
< nparams
; iparams
++)
17360 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
17363 child_die
= die
->child
;
17364 while (child_die
&& child_die
->tag
)
17366 if (child_die
->tag
== DW_TAG_formal_parameter
)
17368 struct type
*arg_type
;
17370 /* DWARF version 2 has no clean way to discern C++
17371 static and non-static member functions. G++ helps
17372 GDB by marking the first parameter for non-static
17373 member functions (which is the this pointer) as
17374 artificial. We pass this information to
17375 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17377 DWARF version 3 added DW_AT_object_pointer, which GCC
17378 4.5 does not yet generate. */
17379 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17381 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
17383 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17384 arg_type
= die_type (child_die
, cu
);
17386 /* RealView does not mark THIS as const, which the testsuite
17387 expects. GCC marks THIS as const in method definitions,
17388 but not in the class specifications (GCC PR 43053). */
17389 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17390 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17393 struct dwarf2_cu
*arg_cu
= cu
;
17394 const char *name
= dwarf2_name (child_die
, cu
);
17396 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17399 /* If the compiler emits this, use it. */
17400 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17403 else if (name
&& strcmp (name
, "this") == 0)
17404 /* Function definitions will have the argument names. */
17406 else if (name
== NULL
&& iparams
== 0)
17407 /* Declarations may not have the names, so like
17408 elsewhere in GDB, assume an artificial first
17409 argument is "this". */
17413 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17417 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
17420 child_die
= sibling_die (child_die
);
17427 static struct type
*
17428 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17430 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17431 const char *name
= NULL
;
17432 struct type
*this_type
, *target_type
;
17434 name
= dwarf2_full_name (NULL
, die
, cu
);
17435 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17436 TYPE_TARGET_STUB (this_type
) = 1;
17437 set_die_type (die
, this_type
, cu
);
17438 target_type
= die_type (die
, cu
);
17439 if (target_type
!= this_type
)
17440 TYPE_TARGET_TYPE (this_type
) = target_type
;
17443 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17444 spec and cause infinite loops in GDB. */
17445 complaint (_("Self-referential DW_TAG_typedef "
17446 "- DIE at %s [in module %s]"),
17447 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17448 TYPE_TARGET_TYPE (this_type
) = NULL
;
17453 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17454 (which may be different from NAME) to the architecture back-end to allow
17455 it to guess the correct format if necessary. */
17457 static struct type
*
17458 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17459 const char *name_hint
)
17461 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17462 const struct floatformat
**format
;
17465 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17467 type
= init_float_type (objfile
, bits
, name
, format
);
17469 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17474 /* Allocate an integer type of size BITS and name NAME. */
17476 static struct type
*
17477 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
17478 int bits
, int unsigned_p
, const char *name
)
17482 /* Versions of Intel's C Compiler generate an integer type called "void"
17483 instead of using DW_TAG_unspecified_type. This has been seen on
17484 at least versions 14, 17, and 18. */
17485 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
17486 && strcmp (name
, "void") == 0)
17487 type
= objfile_type (objfile
)->builtin_void
;
17489 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
17494 /* Initialise and return a floating point type of size BITS suitable for
17495 use as a component of a complex number. The NAME_HINT is passed through
17496 when initialising the floating point type and is the name of the complex
17499 As DWARF doesn't currently provide an explicit name for the components
17500 of a complex number, but it can be helpful to have these components
17501 named, we try to select a suitable name based on the size of the
17503 static struct type
*
17504 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
17505 struct objfile
*objfile
,
17506 int bits
, const char *name_hint
)
17508 gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17509 struct type
*tt
= nullptr;
17511 /* Try to find a suitable floating point builtin type of size BITS.
17512 We're going to use the name of this type as the name for the complex
17513 target type that we are about to create. */
17514 switch (cu
->language
)
17516 case language_fortran
:
17520 tt
= builtin_f_type (gdbarch
)->builtin_real
;
17523 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
17525 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17527 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
17535 tt
= builtin_type (gdbarch
)->builtin_float
;
17538 tt
= builtin_type (gdbarch
)->builtin_double
;
17540 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17542 tt
= builtin_type (gdbarch
)->builtin_long_double
;
17548 /* If the type we found doesn't match the size we were looking for, then
17549 pretend we didn't find a type at all, the complex target type we
17550 create will then be nameless. */
17551 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
17554 const char *name
= (tt
== nullptr) ? nullptr : TYPE_NAME (tt
);
17555 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
);
17558 /* Find a representation of a given base type and install
17559 it in the TYPE field of the die. */
17561 static struct type
*
17562 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17564 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17566 struct attribute
*attr
;
17567 int encoding
= 0, bits
= 0;
17570 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17573 encoding
= DW_UNSND (attr
);
17575 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17578 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
17580 name
= dwarf2_name (die
, cu
);
17583 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
17588 case DW_ATE_address
:
17589 /* Turn DW_ATE_address into a void * pointer. */
17590 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
17591 type
= init_pointer_type (objfile
, bits
, name
, type
);
17593 case DW_ATE_boolean
:
17594 type
= init_boolean_type (objfile
, bits
, 1, name
);
17596 case DW_ATE_complex_float
:
17597 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
);
17598 type
= init_complex_type (objfile
, name
, type
);
17600 case DW_ATE_decimal_float
:
17601 type
= init_decfloat_type (objfile
, bits
, name
);
17604 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
);
17606 case DW_ATE_signed
:
17607 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17609 case DW_ATE_unsigned
:
17610 if (cu
->language
== language_fortran
17612 && startswith (name
, "character("))
17613 type
= init_character_type (objfile
, bits
, 1, name
);
17615 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17617 case DW_ATE_signed_char
:
17618 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17619 || cu
->language
== language_pascal
17620 || cu
->language
== language_fortran
)
17621 type
= init_character_type (objfile
, bits
, 0, name
);
17623 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17625 case DW_ATE_unsigned_char
:
17626 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17627 || cu
->language
== language_pascal
17628 || cu
->language
== language_fortran
17629 || cu
->language
== language_rust
)
17630 type
= init_character_type (objfile
, bits
, 1, name
);
17632 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17636 gdbarch
*arch
= get_objfile_arch (objfile
);
17639 type
= builtin_type (arch
)->builtin_char16
;
17640 else if (bits
== 32)
17641 type
= builtin_type (arch
)->builtin_char32
;
17644 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
17646 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17648 return set_die_type (die
, type
, cu
);
17653 complaint (_("unsupported DW_AT_encoding: '%s'"),
17654 dwarf_type_encoding_name (encoding
));
17655 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17659 if (name
&& strcmp (name
, "char") == 0)
17660 TYPE_NOSIGN (type
) = 1;
17662 maybe_set_alignment (cu
, die
, type
);
17664 return set_die_type (die
, type
, cu
);
17667 /* Parse dwarf attribute if it's a block, reference or constant and put the
17668 resulting value of the attribute into struct bound_prop.
17669 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17672 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17673 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
17674 struct type
*default_type
)
17676 struct dwarf2_property_baton
*baton
;
17677 struct obstack
*obstack
17678 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
17680 gdb_assert (default_type
!= NULL
);
17682 if (attr
== NULL
|| prop
== NULL
)
17685 if (attr_form_is_block (attr
))
17687 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17688 baton
->property_type
= default_type
;
17689 baton
->locexpr
.per_cu
= cu
->per_cu
;
17690 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17691 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17692 baton
->locexpr
.is_reference
= false;
17693 prop
->data
.baton
= baton
;
17694 prop
->kind
= PROP_LOCEXPR
;
17695 gdb_assert (prop
->data
.baton
!= NULL
);
17697 else if (attr_form_is_ref (attr
))
17699 struct dwarf2_cu
*target_cu
= cu
;
17700 struct die_info
*target_die
;
17701 struct attribute
*target_attr
;
17703 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17704 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17705 if (target_attr
== NULL
)
17706 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17708 if (target_attr
== NULL
)
17711 switch (target_attr
->name
)
17713 case DW_AT_location
:
17714 if (attr_form_is_section_offset (target_attr
))
17716 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17717 baton
->property_type
= die_type (target_die
, target_cu
);
17718 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17719 prop
->data
.baton
= baton
;
17720 prop
->kind
= PROP_LOCLIST
;
17721 gdb_assert (prop
->data
.baton
!= NULL
);
17723 else if (attr_form_is_block (target_attr
))
17725 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17726 baton
->property_type
= die_type (target_die
, target_cu
);
17727 baton
->locexpr
.per_cu
= cu
->per_cu
;
17728 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17729 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17730 baton
->locexpr
.is_reference
= true;
17731 prop
->data
.baton
= baton
;
17732 prop
->kind
= PROP_LOCEXPR
;
17733 gdb_assert (prop
->data
.baton
!= NULL
);
17737 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17738 "dynamic property");
17742 case DW_AT_data_member_location
:
17746 if (!handle_data_member_location (target_die
, target_cu
,
17750 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17751 baton
->property_type
= read_type_die (target_die
->parent
,
17753 baton
->offset_info
.offset
= offset
;
17754 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17755 prop
->data
.baton
= baton
;
17756 prop
->kind
= PROP_ADDR_OFFSET
;
17761 else if (attr_form_is_constant (attr
))
17763 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
17764 prop
->kind
= PROP_CONST
;
17768 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17769 dwarf2_name (die
, cu
));
17776 /* Find an integer type the same size as the address size given in the
17777 compilation unit header for PER_CU. UNSIGNED_P controls if the integer
17778 is unsigned or not. */
17780 static struct type
*
17781 dwarf2_per_cu_addr_sized_int_type (struct dwarf2_per_cu_data
*per_cu
,
17784 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
17785 int addr_size
= dwarf2_per_cu_addr_size (per_cu
);
17786 struct type
*int_type
;
17788 /* Helper macro to examine the various builtin types. */
17789 #define TRY_TYPE(F) \
17790 int_type = (unsigned_p \
17791 ? objfile_type (objfile)->builtin_unsigned_ ## F \
17792 : objfile_type (objfile)->builtin_ ## F); \
17793 if (int_type != NULL && TYPE_LENGTH (int_type) == addr_size) \
17800 TRY_TYPE (long_long
);
17804 gdb_assert_not_reached ("unable to find suitable integer type");
17807 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
17808 present (which is valid) then compute the default type based on the
17809 compilation units address size. */
17811 static struct type
*
17812 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17814 struct type
*index_type
= die_type (die
, cu
);
17816 /* Dwarf-2 specifications explicitly allows to create subrange types
17817 without specifying a base type.
17818 In that case, the base type must be set to the type of
17819 the lower bound, upper bound or count, in that order, if any of these
17820 three attributes references an object that has a type.
17821 If no base type is found, the Dwarf-2 specifications say that
17822 a signed integer type of size equal to the size of an address should
17824 For the following C code: `extern char gdb_int [];'
17825 GCC produces an empty range DIE.
17826 FIXME: muller/2010-05-28: Possible references to object for low bound,
17827 high bound or count are not yet handled by this code. */
17828 if (TYPE_CODE (index_type
) == TYPE_CODE_VOID
)
17829 index_type
= dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
17834 /* Read the given DW_AT_subrange DIE. */
17836 static struct type
*
17837 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17839 struct type
*base_type
, *orig_base_type
;
17840 struct type
*range_type
;
17841 struct attribute
*attr
;
17842 struct dynamic_prop low
, high
;
17843 int low_default_is_valid
;
17844 int high_bound_is_count
= 0;
17846 ULONGEST negative_mask
;
17848 orig_base_type
= read_subrange_index_type (die
, cu
);
17850 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17851 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17852 creating the range type, but we use the result of check_typedef
17853 when examining properties of the type. */
17854 base_type
= check_typedef (orig_base_type
);
17856 /* The die_type call above may have already set the type for this DIE. */
17857 range_type
= get_die_type (die
, cu
);
17861 low
.kind
= PROP_CONST
;
17862 high
.kind
= PROP_CONST
;
17863 high
.data
.const_val
= 0;
17865 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17866 omitting DW_AT_lower_bound. */
17867 switch (cu
->language
)
17870 case language_cplus
:
17871 low
.data
.const_val
= 0;
17872 low_default_is_valid
= 1;
17874 case language_fortran
:
17875 low
.data
.const_val
= 1;
17876 low_default_is_valid
= 1;
17879 case language_objc
:
17880 case language_rust
:
17881 low
.data
.const_val
= 0;
17882 low_default_is_valid
= (cu
->header
.version
>= 4);
17886 case language_pascal
:
17887 low
.data
.const_val
= 1;
17888 low_default_is_valid
= (cu
->header
.version
>= 4);
17891 low
.data
.const_val
= 0;
17892 low_default_is_valid
= 0;
17896 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
17898 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
17899 else if (!low_default_is_valid
)
17900 complaint (_("Missing DW_AT_lower_bound "
17901 "- DIE at %s [in module %s]"),
17902 sect_offset_str (die
->sect_off
),
17903 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17905 struct attribute
*attr_ub
, *attr_count
;
17906 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
17907 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17909 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
17910 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17912 /* If bounds are constant do the final calculation here. */
17913 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
17914 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
17916 high_bound_is_count
= 1;
17920 if (attr_ub
!= NULL
)
17921 complaint (_("Unresolved DW_AT_upper_bound "
17922 "- DIE at %s [in module %s]"),
17923 sect_offset_str (die
->sect_off
),
17924 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17925 if (attr_count
!= NULL
)
17926 complaint (_("Unresolved DW_AT_count "
17927 "- DIE at %s [in module %s]"),
17928 sect_offset_str (die
->sect_off
),
17929 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17934 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
17935 if (bias_attr
!= nullptr && attr_form_is_constant (bias_attr
))
17936 bias
= dwarf2_get_attr_constant_value (bias_attr
, 0);
17938 /* Normally, the DWARF producers are expected to use a signed
17939 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17940 But this is unfortunately not always the case, as witnessed
17941 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17942 is used instead. To work around that ambiguity, we treat
17943 the bounds as signed, and thus sign-extend their values, when
17944 the base type is signed. */
17946 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
17947 if (low
.kind
== PROP_CONST
17948 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
17949 low
.data
.const_val
|= negative_mask
;
17950 if (high
.kind
== PROP_CONST
17951 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
17952 high
.data
.const_val
|= negative_mask
;
17954 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
17956 if (high_bound_is_count
)
17957 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
17959 /* Ada expects an empty array on no boundary attributes. */
17960 if (attr
== NULL
&& cu
->language
!= language_ada
)
17961 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
17963 name
= dwarf2_name (die
, cu
);
17965 TYPE_NAME (range_type
) = name
;
17967 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17969 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
17971 maybe_set_alignment (cu
, die
, range_type
);
17973 set_die_type (die
, range_type
, cu
);
17975 /* set_die_type should be already done. */
17976 set_descriptive_type (range_type
, die
, cu
);
17981 static struct type
*
17982 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17986 type
= init_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
, TYPE_CODE_VOID
,0,
17988 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
17990 /* In Ada, an unspecified type is typically used when the description
17991 of the type is defered to a different unit. When encountering
17992 such a type, we treat it as a stub, and try to resolve it later on,
17994 if (cu
->language
== language_ada
)
17995 TYPE_STUB (type
) = 1;
17997 return set_die_type (die
, type
, cu
);
18000 /* Read a single die and all its descendents. Set the die's sibling
18001 field to NULL; set other fields in the die correctly, and set all
18002 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
18003 location of the info_ptr after reading all of those dies. PARENT
18004 is the parent of the die in question. */
18006 static struct die_info
*
18007 read_die_and_children (const struct die_reader_specs
*reader
,
18008 const gdb_byte
*info_ptr
,
18009 const gdb_byte
**new_info_ptr
,
18010 struct die_info
*parent
)
18012 struct die_info
*die
;
18013 const gdb_byte
*cur_ptr
;
18016 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, &has_children
, 0);
18019 *new_info_ptr
= cur_ptr
;
18022 store_in_ref_table (die
, reader
->cu
);
18025 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
18029 *new_info_ptr
= cur_ptr
;
18032 die
->sibling
= NULL
;
18033 die
->parent
= parent
;
18037 /* Read a die, all of its descendents, and all of its siblings; set
18038 all of the fields of all of the dies correctly. Arguments are as
18039 in read_die_and_children. */
18041 static struct die_info
*
18042 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
18043 const gdb_byte
*info_ptr
,
18044 const gdb_byte
**new_info_ptr
,
18045 struct die_info
*parent
)
18047 struct die_info
*first_die
, *last_sibling
;
18048 const gdb_byte
*cur_ptr
;
18050 cur_ptr
= info_ptr
;
18051 first_die
= last_sibling
= NULL
;
18055 struct die_info
*die
18056 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
18060 *new_info_ptr
= cur_ptr
;
18067 last_sibling
->sibling
= die
;
18069 last_sibling
= die
;
18073 /* Read a die, all of its descendents, and all of its siblings; set
18074 all of the fields of all of the dies correctly. Arguments are as
18075 in read_die_and_children.
18076 This the main entry point for reading a DIE and all its children. */
18078 static struct die_info
*
18079 read_die_and_siblings (const struct die_reader_specs
*reader
,
18080 const gdb_byte
*info_ptr
,
18081 const gdb_byte
**new_info_ptr
,
18082 struct die_info
*parent
)
18084 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
18085 new_info_ptr
, parent
);
18087 if (dwarf_die_debug
)
18089 fprintf_unfiltered (gdb_stdlog
,
18090 "Read die from %s@0x%x of %s:\n",
18091 get_section_name (reader
->die_section
),
18092 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18093 bfd_get_filename (reader
->abfd
));
18094 dump_die (die
, dwarf_die_debug
);
18100 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
18102 The caller is responsible for filling in the extra attributes
18103 and updating (*DIEP)->num_attrs.
18104 Set DIEP to point to a newly allocated die with its information,
18105 except for its child, sibling, and parent fields.
18106 Set HAS_CHILDREN to tell whether the die has children or not. */
18108 static const gdb_byte
*
18109 read_full_die_1 (const struct die_reader_specs
*reader
,
18110 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18111 int *has_children
, int num_extra_attrs
)
18113 unsigned int abbrev_number
, bytes_read
, i
;
18114 struct abbrev_info
*abbrev
;
18115 struct die_info
*die
;
18116 struct dwarf2_cu
*cu
= reader
->cu
;
18117 bfd
*abfd
= reader
->abfd
;
18119 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
18120 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18121 info_ptr
+= bytes_read
;
18122 if (!abbrev_number
)
18129 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
18131 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
18133 bfd_get_filename (abfd
));
18135 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
18136 die
->sect_off
= sect_off
;
18137 die
->tag
= abbrev
->tag
;
18138 die
->abbrev
= abbrev_number
;
18140 /* Make the result usable.
18141 The caller needs to update num_attrs after adding the extra
18143 die
->num_attrs
= abbrev
->num_attrs
;
18145 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18146 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
18150 *has_children
= abbrev
->has_children
;
18154 /* Read a die and all its attributes.
18155 Set DIEP to point to a newly allocated die with its information,
18156 except for its child, sibling, and parent fields.
18157 Set HAS_CHILDREN to tell whether the die has children or not. */
18159 static const gdb_byte
*
18160 read_full_die (const struct die_reader_specs
*reader
,
18161 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18164 const gdb_byte
*result
;
18166 result
= read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
18168 if (dwarf_die_debug
)
18170 fprintf_unfiltered (gdb_stdlog
,
18171 "Read die from %s@0x%x of %s:\n",
18172 get_section_name (reader
->die_section
),
18173 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18174 bfd_get_filename (reader
->abfd
));
18175 dump_die (*diep
, dwarf_die_debug
);
18181 /* Abbreviation tables.
18183 In DWARF version 2, the description of the debugging information is
18184 stored in a separate .debug_abbrev section. Before we read any
18185 dies from a section we read in all abbreviations and install them
18186 in a hash table. */
18188 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
18190 struct abbrev_info
*
18191 abbrev_table::alloc_abbrev ()
18193 struct abbrev_info
*abbrev
;
18195 abbrev
= XOBNEW (&abbrev_obstack
, struct abbrev_info
);
18196 memset (abbrev
, 0, sizeof (struct abbrev_info
));
18201 /* Add an abbreviation to the table. */
18204 abbrev_table::add_abbrev (unsigned int abbrev_number
,
18205 struct abbrev_info
*abbrev
)
18207 unsigned int hash_number
;
18209 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
18210 abbrev
->next
= m_abbrevs
[hash_number
];
18211 m_abbrevs
[hash_number
] = abbrev
;
18214 /* Look up an abbrev in the table.
18215 Returns NULL if the abbrev is not found. */
18217 struct abbrev_info
*
18218 abbrev_table::lookup_abbrev (unsigned int abbrev_number
)
18220 unsigned int hash_number
;
18221 struct abbrev_info
*abbrev
;
18223 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
18224 abbrev
= m_abbrevs
[hash_number
];
18228 if (abbrev
->number
== abbrev_number
)
18230 abbrev
= abbrev
->next
;
18235 /* Read in an abbrev table. */
18237 static abbrev_table_up
18238 abbrev_table_read_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18239 struct dwarf2_section_info
*section
,
18240 sect_offset sect_off
)
18242 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18243 bfd
*abfd
= get_section_bfd_owner (section
);
18244 const gdb_byte
*abbrev_ptr
;
18245 struct abbrev_info
*cur_abbrev
;
18246 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
18247 unsigned int abbrev_form
;
18248 struct attr_abbrev
*cur_attrs
;
18249 unsigned int allocated_attrs
;
18251 abbrev_table_up
abbrev_table (new struct abbrev_table (sect_off
));
18253 dwarf2_read_section (objfile
, section
);
18254 abbrev_ptr
= section
->buffer
+ to_underlying (sect_off
);
18255 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18256 abbrev_ptr
+= bytes_read
;
18258 allocated_attrs
= ATTR_ALLOC_CHUNK
;
18259 cur_attrs
= XNEWVEC (struct attr_abbrev
, allocated_attrs
);
18261 /* Loop until we reach an abbrev number of 0. */
18262 while (abbrev_number
)
18264 cur_abbrev
= abbrev_table
->alloc_abbrev ();
18266 /* read in abbrev header */
18267 cur_abbrev
->number
= abbrev_number
;
18269 = (enum dwarf_tag
) read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18270 abbrev_ptr
+= bytes_read
;
18271 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
18274 /* now read in declarations */
18277 LONGEST implicit_const
;
18279 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18280 abbrev_ptr
+= bytes_read
;
18281 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18282 abbrev_ptr
+= bytes_read
;
18283 if (abbrev_form
== DW_FORM_implicit_const
)
18285 implicit_const
= read_signed_leb128 (abfd
, abbrev_ptr
,
18287 abbrev_ptr
+= bytes_read
;
18291 /* Initialize it due to a false compiler warning. */
18292 implicit_const
= -1;
18295 if (abbrev_name
== 0)
18298 if (cur_abbrev
->num_attrs
== allocated_attrs
)
18300 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
18302 = XRESIZEVEC (struct attr_abbrev
, cur_attrs
, allocated_attrs
);
18305 cur_attrs
[cur_abbrev
->num_attrs
].name
18306 = (enum dwarf_attribute
) abbrev_name
;
18307 cur_attrs
[cur_abbrev
->num_attrs
].form
18308 = (enum dwarf_form
) abbrev_form
;
18309 cur_attrs
[cur_abbrev
->num_attrs
].implicit_const
= implicit_const
;
18310 ++cur_abbrev
->num_attrs
;
18313 cur_abbrev
->attrs
=
18314 XOBNEWVEC (&abbrev_table
->abbrev_obstack
, struct attr_abbrev
,
18315 cur_abbrev
->num_attrs
);
18316 memcpy (cur_abbrev
->attrs
, cur_attrs
,
18317 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
18319 abbrev_table
->add_abbrev (abbrev_number
, cur_abbrev
);
18321 /* Get next abbreviation.
18322 Under Irix6 the abbreviations for a compilation unit are not
18323 always properly terminated with an abbrev number of 0.
18324 Exit loop if we encounter an abbreviation which we have
18325 already read (which means we are about to read the abbreviations
18326 for the next compile unit) or if the end of the abbreviation
18327 table is reached. */
18328 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
18330 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18331 abbrev_ptr
+= bytes_read
;
18332 if (abbrev_table
->lookup_abbrev (abbrev_number
) != NULL
)
18337 return abbrev_table
;
18340 /* Returns nonzero if TAG represents a type that we might generate a partial
18344 is_type_tag_for_partial (int tag
)
18349 /* Some types that would be reasonable to generate partial symbols for,
18350 that we don't at present. */
18351 case DW_TAG_array_type
:
18352 case DW_TAG_file_type
:
18353 case DW_TAG_ptr_to_member_type
:
18354 case DW_TAG_set_type
:
18355 case DW_TAG_string_type
:
18356 case DW_TAG_subroutine_type
:
18358 case DW_TAG_base_type
:
18359 case DW_TAG_class_type
:
18360 case DW_TAG_interface_type
:
18361 case DW_TAG_enumeration_type
:
18362 case DW_TAG_structure_type
:
18363 case DW_TAG_subrange_type
:
18364 case DW_TAG_typedef
:
18365 case DW_TAG_union_type
:
18372 /* Load all DIEs that are interesting for partial symbols into memory. */
18374 static struct partial_die_info
*
18375 load_partial_dies (const struct die_reader_specs
*reader
,
18376 const gdb_byte
*info_ptr
, int building_psymtab
)
18378 struct dwarf2_cu
*cu
= reader
->cu
;
18379 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18380 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18381 unsigned int bytes_read
;
18382 unsigned int load_all
= 0;
18383 int nesting_level
= 1;
18388 gdb_assert (cu
->per_cu
!= NULL
);
18389 if (cu
->per_cu
->load_all_dies
)
18393 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18397 &cu
->comp_unit_obstack
,
18398 hashtab_obstack_allocate
,
18399 dummy_obstack_deallocate
);
18403 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
18405 /* A NULL abbrev means the end of a series of children. */
18406 if (abbrev
== NULL
)
18408 if (--nesting_level
== 0)
18411 info_ptr
+= bytes_read
;
18412 last_die
= parent_die
;
18413 parent_die
= parent_die
->die_parent
;
18417 /* Check for template arguments. We never save these; if
18418 they're seen, we just mark the parent, and go on our way. */
18419 if (parent_die
!= NULL
18420 && cu
->language
== language_cplus
18421 && (abbrev
->tag
== DW_TAG_template_type_param
18422 || abbrev
->tag
== DW_TAG_template_value_param
))
18424 parent_die
->has_template_arguments
= 1;
18428 /* We don't need a partial DIE for the template argument. */
18429 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18434 /* We only recurse into c++ subprograms looking for template arguments.
18435 Skip their other children. */
18437 && cu
->language
== language_cplus
18438 && parent_die
!= NULL
18439 && parent_die
->tag
== DW_TAG_subprogram
)
18441 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18445 /* Check whether this DIE is interesting enough to save. Normally
18446 we would not be interested in members here, but there may be
18447 later variables referencing them via DW_AT_specification (for
18448 static members). */
18450 && !is_type_tag_for_partial (abbrev
->tag
)
18451 && abbrev
->tag
!= DW_TAG_constant
18452 && abbrev
->tag
!= DW_TAG_enumerator
18453 && abbrev
->tag
!= DW_TAG_subprogram
18454 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18455 && abbrev
->tag
!= DW_TAG_lexical_block
18456 && abbrev
->tag
!= DW_TAG_variable
18457 && abbrev
->tag
!= DW_TAG_namespace
18458 && abbrev
->tag
!= DW_TAG_module
18459 && abbrev
->tag
!= DW_TAG_member
18460 && abbrev
->tag
!= DW_TAG_imported_unit
18461 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18463 /* Otherwise we skip to the next sibling, if any. */
18464 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18468 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
18471 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
18473 /* This two-pass algorithm for processing partial symbols has a
18474 high cost in cache pressure. Thus, handle some simple cases
18475 here which cover the majority of C partial symbols. DIEs
18476 which neither have specification tags in them, nor could have
18477 specification tags elsewhere pointing at them, can simply be
18478 processed and discarded.
18480 This segment is also optional; scan_partial_symbols and
18481 add_partial_symbol will handle these DIEs if we chain
18482 them in normally. When compilers which do not emit large
18483 quantities of duplicate debug information are more common,
18484 this code can probably be removed. */
18486 /* Any complete simple types at the top level (pretty much all
18487 of them, for a language without namespaces), can be processed
18489 if (parent_die
== NULL
18490 && pdi
.has_specification
== 0
18491 && pdi
.is_declaration
== 0
18492 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
18493 || pdi
.tag
== DW_TAG_base_type
18494 || pdi
.tag
== DW_TAG_subrange_type
))
18496 if (building_psymtab
&& pdi
.name
!= NULL
)
18497 add_psymbol_to_list (pdi
.name
, strlen (pdi
.name
), 0,
18498 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
18499 psymbol_placement::STATIC
,
18500 0, cu
->language
, objfile
);
18501 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18505 /* The exception for DW_TAG_typedef with has_children above is
18506 a workaround of GCC PR debug/47510. In the case of this complaint
18507 type_name_or_error will error on such types later.
18509 GDB skipped children of DW_TAG_typedef by the shortcut above and then
18510 it could not find the child DIEs referenced later, this is checked
18511 above. In correct DWARF DW_TAG_typedef should have no children. */
18513 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
18514 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
18515 "- DIE at %s [in module %s]"),
18516 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
18518 /* If we're at the second level, and we're an enumerator, and
18519 our parent has no specification (meaning possibly lives in a
18520 namespace elsewhere), then we can add the partial symbol now
18521 instead of queueing it. */
18522 if (pdi
.tag
== DW_TAG_enumerator
18523 && parent_die
!= NULL
18524 && parent_die
->die_parent
== NULL
18525 && parent_die
->tag
== DW_TAG_enumeration_type
18526 && parent_die
->has_specification
== 0)
18528 if (pdi
.name
== NULL
)
18529 complaint (_("malformed enumerator DIE ignored"));
18530 else if (building_psymtab
)
18531 add_psymbol_to_list (pdi
.name
, strlen (pdi
.name
), 0,
18532 VAR_DOMAIN
, LOC_CONST
, -1,
18533 cu
->language
== language_cplus
18534 ? psymbol_placement::GLOBAL
18535 : psymbol_placement::STATIC
,
18536 0, cu
->language
, objfile
);
18538 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18542 struct partial_die_info
*part_die
18543 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
18545 /* We'll save this DIE so link it in. */
18546 part_die
->die_parent
= parent_die
;
18547 part_die
->die_sibling
= NULL
;
18548 part_die
->die_child
= NULL
;
18550 if (last_die
&& last_die
== parent_die
)
18551 last_die
->die_child
= part_die
;
18553 last_die
->die_sibling
= part_die
;
18555 last_die
= part_die
;
18557 if (first_die
== NULL
)
18558 first_die
= part_die
;
18560 /* Maybe add the DIE to the hash table. Not all DIEs that we
18561 find interesting need to be in the hash table, because we
18562 also have the parent/sibling/child chains; only those that we
18563 might refer to by offset later during partial symbol reading.
18565 For now this means things that might have be the target of a
18566 DW_AT_specification, DW_AT_abstract_origin, or
18567 DW_AT_extension. DW_AT_extension will refer only to
18568 namespaces; DW_AT_abstract_origin refers to functions (and
18569 many things under the function DIE, but we do not recurse
18570 into function DIEs during partial symbol reading) and
18571 possibly variables as well; DW_AT_specification refers to
18572 declarations. Declarations ought to have the DW_AT_declaration
18573 flag. It happens that GCC forgets to put it in sometimes, but
18574 only for functions, not for types.
18576 Adding more things than necessary to the hash table is harmless
18577 except for the performance cost. Adding too few will result in
18578 wasted time in find_partial_die, when we reread the compilation
18579 unit with load_all_dies set. */
18582 || abbrev
->tag
== DW_TAG_constant
18583 || abbrev
->tag
== DW_TAG_subprogram
18584 || abbrev
->tag
== DW_TAG_variable
18585 || abbrev
->tag
== DW_TAG_namespace
18586 || part_die
->is_declaration
)
18590 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
18591 to_underlying (part_die
->sect_off
),
18596 /* For some DIEs we want to follow their children (if any). For C
18597 we have no reason to follow the children of structures; for other
18598 languages we have to, so that we can get at method physnames
18599 to infer fully qualified class names, for DW_AT_specification,
18600 and for C++ template arguments. For C++, we also look one level
18601 inside functions to find template arguments (if the name of the
18602 function does not already contain the template arguments).
18604 For Ada, we need to scan the children of subprograms and lexical
18605 blocks as well because Ada allows the definition of nested
18606 entities that could be interesting for the debugger, such as
18607 nested subprograms for instance. */
18608 if (last_die
->has_children
18610 || last_die
->tag
== DW_TAG_namespace
18611 || last_die
->tag
== DW_TAG_module
18612 || last_die
->tag
== DW_TAG_enumeration_type
18613 || (cu
->language
== language_cplus
18614 && last_die
->tag
== DW_TAG_subprogram
18615 && (last_die
->name
== NULL
18616 || strchr (last_die
->name
, '<') == NULL
))
18617 || (cu
->language
!= language_c
18618 && (last_die
->tag
== DW_TAG_class_type
18619 || last_die
->tag
== DW_TAG_interface_type
18620 || last_die
->tag
== DW_TAG_structure_type
18621 || last_die
->tag
== DW_TAG_union_type
))
18622 || (cu
->language
== language_ada
18623 && (last_die
->tag
== DW_TAG_subprogram
18624 || last_die
->tag
== DW_TAG_lexical_block
))))
18627 parent_die
= last_die
;
18631 /* Otherwise we skip to the next sibling, if any. */
18632 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
18634 /* Back to the top, do it again. */
18638 partial_die_info::partial_die_info (sect_offset sect_off_
,
18639 struct abbrev_info
*abbrev
)
18640 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
18644 /* Read a minimal amount of information into the minimal die structure.
18645 INFO_PTR should point just after the initial uleb128 of a DIE. */
18648 partial_die_info::read (const struct die_reader_specs
*reader
,
18649 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
18651 struct dwarf2_cu
*cu
= reader
->cu
;
18652 struct dwarf2_per_objfile
*dwarf2_per_objfile
18653 = cu
->per_cu
->dwarf2_per_objfile
;
18655 int has_low_pc_attr
= 0;
18656 int has_high_pc_attr
= 0;
18657 int high_pc_relative
= 0;
18659 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
18661 struct attribute attr
;
18663 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
], info_ptr
);
18665 /* Store the data if it is of an attribute we want to keep in a
18666 partial symbol table. */
18672 case DW_TAG_compile_unit
:
18673 case DW_TAG_partial_unit
:
18674 case DW_TAG_type_unit
:
18675 /* Compilation units have a DW_AT_name that is a filename, not
18676 a source language identifier. */
18677 case DW_TAG_enumeration_type
:
18678 case DW_TAG_enumerator
:
18679 /* These tags always have simple identifiers already; no need
18680 to canonicalize them. */
18681 name
= DW_STRING (&attr
);
18685 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18688 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
18689 &objfile
->per_bfd
->storage_obstack
);
18694 case DW_AT_linkage_name
:
18695 case DW_AT_MIPS_linkage_name
:
18696 /* Note that both forms of linkage name might appear. We
18697 assume they will be the same, and we only store the last
18699 linkage_name
= DW_STRING (&attr
);
18702 has_low_pc_attr
= 1;
18703 lowpc
= attr_value_as_address (&attr
);
18705 case DW_AT_high_pc
:
18706 has_high_pc_attr
= 1;
18707 highpc
= attr_value_as_address (&attr
);
18708 if (cu
->header
.version
>= 4 && attr_form_is_constant (&attr
))
18709 high_pc_relative
= 1;
18711 case DW_AT_location
:
18712 /* Support the .debug_loc offsets. */
18713 if (attr_form_is_block (&attr
))
18715 d
.locdesc
= DW_BLOCK (&attr
);
18717 else if (attr_form_is_section_offset (&attr
))
18719 dwarf2_complex_location_expr_complaint ();
18723 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18724 "partial symbol information");
18727 case DW_AT_external
:
18728 is_external
= DW_UNSND (&attr
);
18730 case DW_AT_declaration
:
18731 is_declaration
= DW_UNSND (&attr
);
18736 case DW_AT_abstract_origin
:
18737 case DW_AT_specification
:
18738 case DW_AT_extension
:
18739 has_specification
= 1;
18740 spec_offset
= dwarf2_get_ref_die_offset (&attr
);
18741 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18742 || cu
->per_cu
->is_dwz
);
18744 case DW_AT_sibling
:
18745 /* Ignore absolute siblings, they might point outside of
18746 the current compile unit. */
18747 if (attr
.form
== DW_FORM_ref_addr
)
18748 complaint (_("ignoring absolute DW_AT_sibling"));
18751 const gdb_byte
*buffer
= reader
->buffer
;
18752 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
18753 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
18755 if (sibling_ptr
< info_ptr
)
18756 complaint (_("DW_AT_sibling points backwards"));
18757 else if (sibling_ptr
> reader
->buffer_end
)
18758 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
18760 sibling
= sibling_ptr
;
18763 case DW_AT_byte_size
:
18766 case DW_AT_const_value
:
18767 has_const_value
= 1;
18769 case DW_AT_calling_convention
:
18770 /* DWARF doesn't provide a way to identify a program's source-level
18771 entry point. DW_AT_calling_convention attributes are only meant
18772 to describe functions' calling conventions.
18774 However, because it's a necessary piece of information in
18775 Fortran, and before DWARF 4 DW_CC_program was the only
18776 piece of debugging information whose definition refers to
18777 a 'main program' at all, several compilers marked Fortran
18778 main programs with DW_CC_program --- even when those
18779 functions use the standard calling conventions.
18781 Although DWARF now specifies a way to provide this
18782 information, we support this practice for backward
18784 if (DW_UNSND (&attr
) == DW_CC_program
18785 && cu
->language
== language_fortran
)
18786 main_subprogram
= 1;
18789 if (DW_UNSND (&attr
) == DW_INL_inlined
18790 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
18791 may_be_inlined
= 1;
18795 if (tag
== DW_TAG_imported_unit
)
18797 d
.sect_off
= dwarf2_get_ref_die_offset (&attr
);
18798 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18799 || cu
->per_cu
->is_dwz
);
18803 case DW_AT_main_subprogram
:
18804 main_subprogram
= DW_UNSND (&attr
);
18809 /* It would be nice to reuse dwarf2_get_pc_bounds here,
18810 but that requires a full DIE, so instead we just
18812 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
18813 unsigned int ranges_offset
= (DW_UNSND (&attr
)
18814 + (need_ranges_base
18818 /* Value of the DW_AT_ranges attribute is the offset in the
18819 .debug_ranges section. */
18820 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
18831 /* For Ada, if both the name and the linkage name appear, we prefer
18832 the latter. This lets "catch exception" work better, regardless
18833 of the order in which the name and linkage name were emitted.
18834 Really, though, this is just a workaround for the fact that gdb
18835 doesn't store both the name and the linkage name. */
18836 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
18837 name
= linkage_name
;
18839 if (high_pc_relative
)
18842 if (has_low_pc_attr
&& has_high_pc_attr
)
18844 /* When using the GNU linker, .gnu.linkonce. sections are used to
18845 eliminate duplicate copies of functions and vtables and such.
18846 The linker will arbitrarily choose one and discard the others.
18847 The AT_*_pc values for such functions refer to local labels in
18848 these sections. If the section from that file was discarded, the
18849 labels are not in the output, so the relocs get a value of 0.
18850 If this is a discarded function, mark the pc bounds as invalid,
18851 so that GDB will ignore it. */
18852 if (lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
18854 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18855 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18857 complaint (_("DW_AT_low_pc %s is zero "
18858 "for DIE at %s [in module %s]"),
18859 paddress (gdbarch
, lowpc
),
18860 sect_offset_str (sect_off
),
18861 objfile_name (objfile
));
18863 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
18864 else if (lowpc
>= highpc
)
18866 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18867 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18869 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
18870 "for DIE at %s [in module %s]"),
18871 paddress (gdbarch
, lowpc
),
18872 paddress (gdbarch
, highpc
),
18873 sect_offset_str (sect_off
),
18874 objfile_name (objfile
));
18883 /* Find a cached partial DIE at OFFSET in CU. */
18885 struct partial_die_info
*
18886 dwarf2_cu::find_partial_die (sect_offset sect_off
)
18888 struct partial_die_info
*lookup_die
= NULL
;
18889 struct partial_die_info
part_die (sect_off
);
18891 lookup_die
= ((struct partial_die_info
*)
18892 htab_find_with_hash (partial_dies
, &part_die
,
18893 to_underlying (sect_off
)));
18898 /* Find a partial DIE at OFFSET, which may or may not be in CU,
18899 except in the case of .debug_types DIEs which do not reference
18900 outside their CU (they do however referencing other types via
18901 DW_FORM_ref_sig8). */
18903 static const struct cu_partial_die_info
18904 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
18906 struct dwarf2_per_objfile
*dwarf2_per_objfile
18907 = cu
->per_cu
->dwarf2_per_objfile
;
18908 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18909 struct dwarf2_per_cu_data
*per_cu
= NULL
;
18910 struct partial_die_info
*pd
= NULL
;
18912 if (offset_in_dwz
== cu
->per_cu
->is_dwz
18913 && offset_in_cu_p (&cu
->header
, sect_off
))
18915 pd
= cu
->find_partial_die (sect_off
);
18918 /* We missed recording what we needed.
18919 Load all dies and try again. */
18920 per_cu
= cu
->per_cu
;
18924 /* TUs don't reference other CUs/TUs (except via type signatures). */
18925 if (cu
->per_cu
->is_debug_types
)
18927 error (_("Dwarf Error: Type Unit at offset %s contains"
18928 " external reference to offset %s [in module %s].\n"),
18929 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
18930 bfd_get_filename (objfile
->obfd
));
18932 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
18933 dwarf2_per_objfile
);
18935 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
18936 load_partial_comp_unit (per_cu
);
18938 per_cu
->cu
->last_used
= 0;
18939 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18942 /* If we didn't find it, and not all dies have been loaded,
18943 load them all and try again. */
18945 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
18947 per_cu
->load_all_dies
= 1;
18949 /* This is nasty. When we reread the DIEs, somewhere up the call chain
18950 THIS_CU->cu may already be in use. So we can't just free it and
18951 replace its DIEs with the ones we read in. Instead, we leave those
18952 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
18953 and clobber THIS_CU->cu->partial_dies with the hash table for the new
18955 load_partial_comp_unit (per_cu
);
18957 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18961 internal_error (__FILE__
, __LINE__
,
18962 _("could not find partial DIE %s "
18963 "in cache [from module %s]\n"),
18964 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
18965 return { per_cu
->cu
, pd
};
18968 /* See if we can figure out if the class lives in a namespace. We do
18969 this by looking for a member function; its demangled name will
18970 contain namespace info, if there is any. */
18973 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
18974 struct dwarf2_cu
*cu
)
18976 /* NOTE: carlton/2003-10-07: Getting the info this way changes
18977 what template types look like, because the demangler
18978 frequently doesn't give the same name as the debug info. We
18979 could fix this by only using the demangled name to get the
18980 prefix (but see comment in read_structure_type). */
18982 struct partial_die_info
*real_pdi
;
18983 struct partial_die_info
*child_pdi
;
18985 /* If this DIE (this DIE's specification, if any) has a parent, then
18986 we should not do this. We'll prepend the parent's fully qualified
18987 name when we create the partial symbol. */
18989 real_pdi
= struct_pdi
;
18990 while (real_pdi
->has_specification
)
18992 auto res
= find_partial_die (real_pdi
->spec_offset
,
18993 real_pdi
->spec_is_dwz
, cu
);
18994 real_pdi
= res
.pdi
;
18998 if (real_pdi
->die_parent
!= NULL
)
19001 for (child_pdi
= struct_pdi
->die_child
;
19003 child_pdi
= child_pdi
->die_sibling
)
19005 if (child_pdi
->tag
== DW_TAG_subprogram
19006 && child_pdi
->linkage_name
!= NULL
)
19008 char *actual_class_name
19009 = language_class_name_from_physname (cu
->language_defn
,
19010 child_pdi
->linkage_name
);
19011 if (actual_class_name
!= NULL
)
19013 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19015 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
19016 actual_class_name
);
19017 xfree (actual_class_name
);
19025 partial_die_info::fixup (struct dwarf2_cu
*cu
)
19027 /* Once we've fixed up a die, there's no point in doing so again.
19028 This also avoids a memory leak if we were to call
19029 guess_partial_die_structure_name multiple times. */
19033 /* If we found a reference attribute and the DIE has no name, try
19034 to find a name in the referred to DIE. */
19036 if (name
== NULL
&& has_specification
)
19038 struct partial_die_info
*spec_die
;
19040 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19041 spec_die
= res
.pdi
;
19044 spec_die
->fixup (cu
);
19046 if (spec_die
->name
)
19048 name
= spec_die
->name
;
19050 /* Copy DW_AT_external attribute if it is set. */
19051 if (spec_die
->is_external
)
19052 is_external
= spec_die
->is_external
;
19056 /* Set default names for some unnamed DIEs. */
19058 if (name
== NULL
&& tag
== DW_TAG_namespace
)
19059 name
= CP_ANONYMOUS_NAMESPACE_STR
;
19061 /* If there is no parent die to provide a namespace, and there are
19062 children, see if we can determine the namespace from their linkage
19064 if (cu
->language
== language_cplus
19065 && !cu
->per_cu
->dwarf2_per_objfile
->types
.empty ()
19066 && die_parent
== NULL
19068 && (tag
== DW_TAG_class_type
19069 || tag
== DW_TAG_structure_type
19070 || tag
== DW_TAG_union_type
))
19071 guess_partial_die_structure_name (this, cu
);
19073 /* GCC might emit a nameless struct or union that has a linkage
19074 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
19076 && (tag
== DW_TAG_class_type
19077 || tag
== DW_TAG_interface_type
19078 || tag
== DW_TAG_structure_type
19079 || tag
== DW_TAG_union_type
)
19080 && linkage_name
!= NULL
)
19084 demangled
= gdb_demangle (linkage_name
, DMGL_TYPES
);
19089 /* Strip any leading namespaces/classes, keep only the base name.
19090 DW_AT_name for named DIEs does not contain the prefixes. */
19091 base
= strrchr (demangled
, ':');
19092 if (base
&& base
> demangled
&& base
[-1] == ':')
19097 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19098 name
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
, base
);
19106 /* Read an attribute value described by an attribute form. */
19108 static const gdb_byte
*
19109 read_attribute_value (const struct die_reader_specs
*reader
,
19110 struct attribute
*attr
, unsigned form
,
19111 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
19113 struct dwarf2_cu
*cu
= reader
->cu
;
19114 struct dwarf2_per_objfile
*dwarf2_per_objfile
19115 = cu
->per_cu
->dwarf2_per_objfile
;
19116 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19117 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19118 bfd
*abfd
= reader
->abfd
;
19119 struct comp_unit_head
*cu_header
= &cu
->header
;
19120 unsigned int bytes_read
;
19121 struct dwarf_block
*blk
;
19123 attr
->form
= (enum dwarf_form
) form
;
19126 case DW_FORM_ref_addr
:
19127 if (cu
->header
.version
== 2)
19128 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
19130 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
19131 &cu
->header
, &bytes_read
);
19132 info_ptr
+= bytes_read
;
19134 case DW_FORM_GNU_ref_alt
:
19135 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
19136 info_ptr
+= bytes_read
;
19139 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
19140 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
19141 info_ptr
+= bytes_read
;
19143 case DW_FORM_block2
:
19144 blk
= dwarf_alloc_block (cu
);
19145 blk
->size
= read_2_bytes (abfd
, info_ptr
);
19147 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19148 info_ptr
+= blk
->size
;
19149 DW_BLOCK (attr
) = blk
;
19151 case DW_FORM_block4
:
19152 blk
= dwarf_alloc_block (cu
);
19153 blk
->size
= read_4_bytes (abfd
, info_ptr
);
19155 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19156 info_ptr
+= blk
->size
;
19157 DW_BLOCK (attr
) = blk
;
19159 case DW_FORM_data2
:
19160 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
19163 case DW_FORM_data4
:
19164 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
19167 case DW_FORM_data8
:
19168 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
19171 case DW_FORM_data16
:
19172 blk
= dwarf_alloc_block (cu
);
19174 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
19176 DW_BLOCK (attr
) = blk
;
19178 case DW_FORM_sec_offset
:
19179 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
19180 info_ptr
+= bytes_read
;
19182 case DW_FORM_string
:
19183 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
19184 DW_STRING_IS_CANONICAL (attr
) = 0;
19185 info_ptr
+= bytes_read
;
19188 if (!cu
->per_cu
->is_dwz
)
19190 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
19191 abfd
, info_ptr
, cu_header
,
19193 DW_STRING_IS_CANONICAL (attr
) = 0;
19194 info_ptr
+= bytes_read
;
19198 case DW_FORM_line_strp
:
19199 if (!cu
->per_cu
->is_dwz
)
19201 DW_STRING (attr
) = read_indirect_line_string (dwarf2_per_objfile
,
19203 cu_header
, &bytes_read
);
19204 DW_STRING_IS_CANONICAL (attr
) = 0;
19205 info_ptr
+= bytes_read
;
19209 case DW_FORM_GNU_strp_alt
:
19211 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19212 LONGEST str_offset
= read_offset (abfd
, info_ptr
, cu_header
,
19215 DW_STRING (attr
) = read_indirect_string_from_dwz (objfile
,
19217 DW_STRING_IS_CANONICAL (attr
) = 0;
19218 info_ptr
+= bytes_read
;
19221 case DW_FORM_exprloc
:
19222 case DW_FORM_block
:
19223 blk
= dwarf_alloc_block (cu
);
19224 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19225 info_ptr
+= bytes_read
;
19226 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19227 info_ptr
+= blk
->size
;
19228 DW_BLOCK (attr
) = blk
;
19230 case DW_FORM_block1
:
19231 blk
= dwarf_alloc_block (cu
);
19232 blk
->size
= read_1_byte (abfd
, info_ptr
);
19234 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19235 info_ptr
+= blk
->size
;
19236 DW_BLOCK (attr
) = blk
;
19238 case DW_FORM_data1
:
19239 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19243 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19246 case DW_FORM_flag_present
:
19247 DW_UNSND (attr
) = 1;
19249 case DW_FORM_sdata
:
19250 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19251 info_ptr
+= bytes_read
;
19253 case DW_FORM_udata
:
19254 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19255 info_ptr
+= bytes_read
;
19258 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19259 + read_1_byte (abfd
, info_ptr
));
19263 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19264 + read_2_bytes (abfd
, info_ptr
));
19268 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19269 + read_4_bytes (abfd
, info_ptr
));
19273 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19274 + read_8_bytes (abfd
, info_ptr
));
19277 case DW_FORM_ref_sig8
:
19278 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
19281 case DW_FORM_ref_udata
:
19282 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19283 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
19284 info_ptr
+= bytes_read
;
19286 case DW_FORM_indirect
:
19287 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19288 info_ptr
+= bytes_read
;
19289 if (form
== DW_FORM_implicit_const
)
19291 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19292 info_ptr
+= bytes_read
;
19294 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
19297 case DW_FORM_implicit_const
:
19298 DW_SND (attr
) = implicit_const
;
19300 case DW_FORM_addrx
:
19301 case DW_FORM_GNU_addr_index
:
19302 if (reader
->dwo_file
== NULL
)
19304 /* For now flag a hard error.
19305 Later we can turn this into a complaint. */
19306 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
19307 dwarf_form_name (form
),
19308 bfd_get_filename (abfd
));
19310 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
19311 info_ptr
+= bytes_read
;
19314 case DW_FORM_strx1
:
19315 case DW_FORM_strx2
:
19316 case DW_FORM_strx3
:
19317 case DW_FORM_strx4
:
19318 case DW_FORM_GNU_str_index
:
19319 if (reader
->dwo_file
== NULL
)
19321 /* For now flag a hard error.
19322 Later we can turn this into a complaint if warranted. */
19323 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
19324 dwarf_form_name (form
),
19325 bfd_get_filename (abfd
));
19328 ULONGEST str_index
;
19329 if (form
== DW_FORM_strx1
)
19331 str_index
= read_1_byte (abfd
, info_ptr
);
19334 else if (form
== DW_FORM_strx2
)
19336 str_index
= read_2_bytes (abfd
, info_ptr
);
19339 else if (form
== DW_FORM_strx3
)
19341 str_index
= read_3_bytes (abfd
, info_ptr
);
19344 else if (form
== DW_FORM_strx4
)
19346 str_index
= read_4_bytes (abfd
, info_ptr
);
19351 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19352 info_ptr
+= bytes_read
;
19354 DW_STRING (attr
) = read_str_index (reader
, str_index
);
19355 DW_STRING_IS_CANONICAL (attr
) = 0;
19359 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
19360 dwarf_form_name (form
),
19361 bfd_get_filename (abfd
));
19365 if (cu
->per_cu
->is_dwz
&& attr_form_is_ref (attr
))
19366 attr
->form
= DW_FORM_GNU_ref_alt
;
19368 /* We have seen instances where the compiler tried to emit a byte
19369 size attribute of -1 which ended up being encoded as an unsigned
19370 0xffffffff. Although 0xffffffff is technically a valid size value,
19371 an object of this size seems pretty unlikely so we can relatively
19372 safely treat these cases as if the size attribute was invalid and
19373 treat them as zero by default. */
19374 if (attr
->name
== DW_AT_byte_size
19375 && form
== DW_FORM_data4
19376 && DW_UNSND (attr
) >= 0xffffffff)
19379 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
19380 hex_string (DW_UNSND (attr
)));
19381 DW_UNSND (attr
) = 0;
19387 /* Read an attribute described by an abbreviated attribute. */
19389 static const gdb_byte
*
19390 read_attribute (const struct die_reader_specs
*reader
,
19391 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
19392 const gdb_byte
*info_ptr
)
19394 attr
->name
= abbrev
->name
;
19395 return read_attribute_value (reader
, attr
, abbrev
->form
,
19396 abbrev
->implicit_const
, info_ptr
);
19399 /* Read dwarf information from a buffer. */
19401 static unsigned int
19402 read_1_byte (bfd
*abfd
, const gdb_byte
*buf
)
19404 return bfd_get_8 (abfd
, buf
);
19408 read_1_signed_byte (bfd
*abfd
, const gdb_byte
*buf
)
19410 return bfd_get_signed_8 (abfd
, buf
);
19413 static unsigned int
19414 read_2_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19416 return bfd_get_16 (abfd
, buf
);
19420 read_2_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19422 return bfd_get_signed_16 (abfd
, buf
);
19425 static unsigned int
19426 read_3_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19428 unsigned int result
= 0;
19429 for (int i
= 0; i
< 3; ++i
)
19431 unsigned char byte
= bfd_get_8 (abfd
, buf
);
19433 result
|= ((unsigned int) byte
<< (i
* 8));
19438 static unsigned int
19439 read_4_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19441 return bfd_get_32 (abfd
, buf
);
19445 read_4_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19447 return bfd_get_signed_32 (abfd
, buf
);
19451 read_8_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19453 return bfd_get_64 (abfd
, buf
);
19457 read_address (bfd
*abfd
, const gdb_byte
*buf
, struct dwarf2_cu
*cu
,
19458 unsigned int *bytes_read
)
19460 struct comp_unit_head
*cu_header
= &cu
->header
;
19461 CORE_ADDR retval
= 0;
19463 if (cu_header
->signed_addr_p
)
19465 switch (cu_header
->addr_size
)
19468 retval
= bfd_get_signed_16 (abfd
, buf
);
19471 retval
= bfd_get_signed_32 (abfd
, buf
);
19474 retval
= bfd_get_signed_64 (abfd
, buf
);
19477 internal_error (__FILE__
, __LINE__
,
19478 _("read_address: bad switch, signed [in module %s]"),
19479 bfd_get_filename (abfd
));
19484 switch (cu_header
->addr_size
)
19487 retval
= bfd_get_16 (abfd
, buf
);
19490 retval
= bfd_get_32 (abfd
, buf
);
19493 retval
= bfd_get_64 (abfd
, buf
);
19496 internal_error (__FILE__
, __LINE__
,
19497 _("read_address: bad switch, "
19498 "unsigned [in module %s]"),
19499 bfd_get_filename (abfd
));
19503 *bytes_read
= cu_header
->addr_size
;
19507 /* Read the initial length from a section. The (draft) DWARF 3
19508 specification allows the initial length to take up either 4 bytes
19509 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
19510 bytes describe the length and all offsets will be 8 bytes in length
19513 An older, non-standard 64-bit format is also handled by this
19514 function. The older format in question stores the initial length
19515 as an 8-byte quantity without an escape value. Lengths greater
19516 than 2^32 aren't very common which means that the initial 4 bytes
19517 is almost always zero. Since a length value of zero doesn't make
19518 sense for the 32-bit format, this initial zero can be considered to
19519 be an escape value which indicates the presence of the older 64-bit
19520 format. As written, the code can't detect (old format) lengths
19521 greater than 4GB. If it becomes necessary to handle lengths
19522 somewhat larger than 4GB, we could allow other small values (such
19523 as the non-sensical values of 1, 2, and 3) to also be used as
19524 escape values indicating the presence of the old format.
19526 The value returned via bytes_read should be used to increment the
19527 relevant pointer after calling read_initial_length().
19529 [ Note: read_initial_length() and read_offset() are based on the
19530 document entitled "DWARF Debugging Information Format", revision
19531 3, draft 8, dated November 19, 2001. This document was obtained
19534 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
19536 This document is only a draft and is subject to change. (So beware.)
19538 Details regarding the older, non-standard 64-bit format were
19539 determined empirically by examining 64-bit ELF files produced by
19540 the SGI toolchain on an IRIX 6.5 machine.
19542 - Kevin, July 16, 2002
19546 read_initial_length (bfd
*abfd
, const gdb_byte
*buf
, unsigned int *bytes_read
)
19548 LONGEST length
= bfd_get_32 (abfd
, buf
);
19550 if (length
== 0xffffffff)
19552 length
= bfd_get_64 (abfd
, buf
+ 4);
19555 else if (length
== 0)
19557 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
19558 length
= bfd_get_64 (abfd
, buf
);
19569 /* Cover function for read_initial_length.
19570 Returns the length of the object at BUF, and stores the size of the
19571 initial length in *BYTES_READ and stores the size that offsets will be in
19573 If the initial length size is not equivalent to that specified in
19574 CU_HEADER then issue a complaint.
19575 This is useful when reading non-comp-unit headers. */
19578 read_checked_initial_length_and_offset (bfd
*abfd
, const gdb_byte
*buf
,
19579 const struct comp_unit_head
*cu_header
,
19580 unsigned int *bytes_read
,
19581 unsigned int *offset_size
)
19583 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
19585 gdb_assert (cu_header
->initial_length_size
== 4
19586 || cu_header
->initial_length_size
== 8
19587 || cu_header
->initial_length_size
== 12);
19589 if (cu_header
->initial_length_size
!= *bytes_read
)
19590 complaint (_("intermixed 32-bit and 64-bit DWARF sections"));
19592 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
19596 /* Read an offset from the data stream. The size of the offset is
19597 given by cu_header->offset_size. */
19600 read_offset (bfd
*abfd
, const gdb_byte
*buf
,
19601 const struct comp_unit_head
*cu_header
,
19602 unsigned int *bytes_read
)
19604 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
19606 *bytes_read
= cu_header
->offset_size
;
19610 /* Read an offset from the data stream. */
19613 read_offset_1 (bfd
*abfd
, const gdb_byte
*buf
, unsigned int offset_size
)
19615 LONGEST retval
= 0;
19617 switch (offset_size
)
19620 retval
= bfd_get_32 (abfd
, buf
);
19623 retval
= bfd_get_64 (abfd
, buf
);
19626 internal_error (__FILE__
, __LINE__
,
19627 _("read_offset_1: bad switch [in module %s]"),
19628 bfd_get_filename (abfd
));
19634 static const gdb_byte
*
19635 read_n_bytes (bfd
*abfd
, const gdb_byte
*buf
, unsigned int size
)
19637 /* If the size of a host char is 8 bits, we can return a pointer
19638 to the buffer, otherwise we have to copy the data to a buffer
19639 allocated on the temporary obstack. */
19640 gdb_assert (HOST_CHAR_BIT
== 8);
19644 static const char *
19645 read_direct_string (bfd
*abfd
, const gdb_byte
*buf
,
19646 unsigned int *bytes_read_ptr
)
19648 /* If the size of a host char is 8 bits, we can return a pointer
19649 to the string, otherwise we have to copy the string to a buffer
19650 allocated on the temporary obstack. */
19651 gdb_assert (HOST_CHAR_BIT
== 8);
19654 *bytes_read_ptr
= 1;
19657 *bytes_read_ptr
= strlen ((const char *) buf
) + 1;
19658 return (const char *) buf
;
19661 /* Return pointer to string at section SECT offset STR_OFFSET with error
19662 reporting strings FORM_NAME and SECT_NAME. */
19664 static const char *
19665 read_indirect_string_at_offset_from (struct objfile
*objfile
,
19666 bfd
*abfd
, LONGEST str_offset
,
19667 struct dwarf2_section_info
*sect
,
19668 const char *form_name
,
19669 const char *sect_name
)
19671 dwarf2_read_section (objfile
, sect
);
19672 if (sect
->buffer
== NULL
)
19673 error (_("%s used without %s section [in module %s]"),
19674 form_name
, sect_name
, bfd_get_filename (abfd
));
19675 if (str_offset
>= sect
->size
)
19676 error (_("%s pointing outside of %s section [in module %s]"),
19677 form_name
, sect_name
, bfd_get_filename (abfd
));
19678 gdb_assert (HOST_CHAR_BIT
== 8);
19679 if (sect
->buffer
[str_offset
] == '\0')
19681 return (const char *) (sect
->buffer
+ str_offset
);
19684 /* Return pointer to string at .debug_str offset STR_OFFSET. */
19686 static const char *
19687 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19688 bfd
*abfd
, LONGEST str_offset
)
19690 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
19692 &dwarf2_per_objfile
->str
,
19693 "DW_FORM_strp", ".debug_str");
19696 /* Return pointer to string at .debug_line_str offset STR_OFFSET. */
19698 static const char *
19699 read_indirect_line_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19700 bfd
*abfd
, LONGEST str_offset
)
19702 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
19704 &dwarf2_per_objfile
->line_str
,
19705 "DW_FORM_line_strp",
19706 ".debug_line_str");
19709 /* Read a string at offset STR_OFFSET in the .debug_str section from
19710 the .dwz file DWZ. Throw an error if the offset is too large. If
19711 the string consists of a single NUL byte, return NULL; otherwise
19712 return a pointer to the string. */
19714 static const char *
19715 read_indirect_string_from_dwz (struct objfile
*objfile
, struct dwz_file
*dwz
,
19716 LONGEST str_offset
)
19718 dwarf2_read_section (objfile
, &dwz
->str
);
19720 if (dwz
->str
.buffer
== NULL
)
19721 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
19722 "section [in module %s]"),
19723 bfd_get_filename (dwz
->dwz_bfd
));
19724 if (str_offset
>= dwz
->str
.size
)
19725 error (_("DW_FORM_GNU_strp_alt pointing outside of "
19726 ".debug_str section [in module %s]"),
19727 bfd_get_filename (dwz
->dwz_bfd
));
19728 gdb_assert (HOST_CHAR_BIT
== 8);
19729 if (dwz
->str
.buffer
[str_offset
] == '\0')
19731 return (const char *) (dwz
->str
.buffer
+ str_offset
);
19734 /* Return pointer to string at .debug_str offset as read from BUF.
19735 BUF is assumed to be in a compilation unit described by CU_HEADER.
19736 Return *BYTES_READ_PTR count of bytes read from BUF. */
19738 static const char *
19739 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
19740 const gdb_byte
*buf
,
19741 const struct comp_unit_head
*cu_header
,
19742 unsigned int *bytes_read_ptr
)
19744 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
19746 return read_indirect_string_at_offset (dwarf2_per_objfile
, abfd
, str_offset
);
19749 /* Return pointer to string at .debug_line_str offset as read from BUF.
19750 BUF is assumed to be in a compilation unit described by CU_HEADER.
19751 Return *BYTES_READ_PTR count of bytes read from BUF. */
19753 static const char *
19754 read_indirect_line_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19755 bfd
*abfd
, const gdb_byte
*buf
,
19756 const struct comp_unit_head
*cu_header
,
19757 unsigned int *bytes_read_ptr
)
19759 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
19761 return read_indirect_line_string_at_offset (dwarf2_per_objfile
, abfd
,
19766 read_unsigned_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
19767 unsigned int *bytes_read_ptr
)
19770 unsigned int num_read
;
19772 unsigned char byte
;
19779 byte
= bfd_get_8 (abfd
, buf
);
19782 result
|= ((ULONGEST
) (byte
& 127) << shift
);
19783 if ((byte
& 128) == 0)
19789 *bytes_read_ptr
= num_read
;
19794 read_signed_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
19795 unsigned int *bytes_read_ptr
)
19798 int shift
, num_read
;
19799 unsigned char byte
;
19806 byte
= bfd_get_8 (abfd
, buf
);
19809 result
|= ((ULONGEST
) (byte
& 127) << shift
);
19811 if ((byte
& 128) == 0)
19816 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
19817 result
|= -(((ULONGEST
) 1) << shift
);
19818 *bytes_read_ptr
= num_read
;
19822 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
19823 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
19824 ADDR_SIZE is the size of addresses from the CU header. */
19827 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19828 unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
19830 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19831 bfd
*abfd
= objfile
->obfd
;
19832 const gdb_byte
*info_ptr
;
19834 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
19835 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
19836 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
19837 objfile_name (objfile
));
19838 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
19839 error (_("DW_FORM_addr_index pointing outside of "
19840 ".debug_addr section [in module %s]"),
19841 objfile_name (objfile
));
19842 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
19843 + addr_base
+ addr_index
* addr_size
);
19844 if (addr_size
== 4)
19845 return bfd_get_32 (abfd
, info_ptr
);
19847 return bfd_get_64 (abfd
, info_ptr
);
19850 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
19853 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
19855 return read_addr_index_1 (cu
->per_cu
->dwarf2_per_objfile
, addr_index
,
19856 cu
->addr_base
, cu
->header
.addr_size
);
19859 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
19862 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
19863 unsigned int *bytes_read
)
19865 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
19866 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
19868 return read_addr_index (cu
, addr_index
);
19871 /* Data structure to pass results from dwarf2_read_addr_index_reader
19872 back to dwarf2_read_addr_index. */
19874 struct dwarf2_read_addr_index_data
19876 ULONGEST addr_base
;
19880 /* die_reader_func for dwarf2_read_addr_index. */
19883 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
19884 const gdb_byte
*info_ptr
,
19885 struct die_info
*comp_unit_die
,
19889 struct dwarf2_cu
*cu
= reader
->cu
;
19890 struct dwarf2_read_addr_index_data
*aidata
=
19891 (struct dwarf2_read_addr_index_data
*) data
;
19893 aidata
->addr_base
= cu
->addr_base
;
19894 aidata
->addr_size
= cu
->header
.addr_size
;
19897 /* Given an index in .debug_addr, fetch the value.
19898 NOTE: This can be called during dwarf expression evaluation,
19899 long after the debug information has been read, and thus per_cu->cu
19900 may no longer exist. */
19903 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
19904 unsigned int addr_index
)
19906 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
19907 struct dwarf2_cu
*cu
= per_cu
->cu
;
19908 ULONGEST addr_base
;
19911 /* We need addr_base and addr_size.
19912 If we don't have PER_CU->cu, we have to get it.
19913 Nasty, but the alternative is storing the needed info in PER_CU,
19914 which at this point doesn't seem justified: it's not clear how frequently
19915 it would get used and it would increase the size of every PER_CU.
19916 Entry points like dwarf2_per_cu_addr_size do a similar thing
19917 so we're not in uncharted territory here.
19918 Alas we need to be a bit more complicated as addr_base is contained
19921 We don't need to read the entire CU(/TU).
19922 We just need the header and top level die.
19924 IWBN to use the aging mechanism to let us lazily later discard the CU.
19925 For now we skip this optimization. */
19929 addr_base
= cu
->addr_base
;
19930 addr_size
= cu
->header
.addr_size
;
19934 struct dwarf2_read_addr_index_data aidata
;
19936 /* Note: We can't use init_cutu_and_read_dies_simple here,
19937 we need addr_base. */
19938 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0, false,
19939 dwarf2_read_addr_index_reader
, &aidata
);
19940 addr_base
= aidata
.addr_base
;
19941 addr_size
= aidata
.addr_size
;
19944 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
19948 /* Given a DW_FORM_GNU_str_index or DW_FORM_strx, fetch the string.
19949 This is only used by the Fission support. */
19951 static const char *
19952 read_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
19954 struct dwarf2_cu
*cu
= reader
->cu
;
19955 struct dwarf2_per_objfile
*dwarf2_per_objfile
19956 = cu
->per_cu
->dwarf2_per_objfile
;
19957 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19958 const char *objf_name
= objfile_name (objfile
);
19959 bfd
*abfd
= objfile
->obfd
;
19960 struct dwarf2_section_info
*str_section
= &reader
->dwo_file
->sections
.str
;
19961 struct dwarf2_section_info
*str_offsets_section
=
19962 &reader
->dwo_file
->sections
.str_offsets
;
19963 const gdb_byte
*info_ptr
;
19964 ULONGEST str_offset
;
19965 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
19967 dwarf2_read_section (objfile
, str_section
);
19968 dwarf2_read_section (objfile
, str_offsets_section
);
19969 if (str_section
->buffer
== NULL
)
19970 error (_("%s used without .debug_str.dwo section"
19971 " in CU at offset %s [in module %s]"),
19972 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19973 if (str_offsets_section
->buffer
== NULL
)
19974 error (_("%s used without .debug_str_offsets.dwo section"
19975 " in CU at offset %s [in module %s]"),
19976 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19977 if (str_index
* cu
->header
.offset_size
>= str_offsets_section
->size
)
19978 error (_("%s pointing outside of .debug_str_offsets.dwo"
19979 " section in CU at offset %s [in module %s]"),
19980 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19981 info_ptr
= (str_offsets_section
->buffer
19982 + str_index
* cu
->header
.offset_size
);
19983 if (cu
->header
.offset_size
== 4)
19984 str_offset
= bfd_get_32 (abfd
, info_ptr
);
19986 str_offset
= bfd_get_64 (abfd
, info_ptr
);
19987 if (str_offset
>= str_section
->size
)
19988 error (_("Offset from %s pointing outside of"
19989 " .debug_str.dwo section in CU at offset %s [in module %s]"),
19990 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19991 return (const char *) (str_section
->buffer
+ str_offset
);
19994 /* Return the length of an LEB128 number in BUF. */
19997 leb128_size (const gdb_byte
*buf
)
19999 const gdb_byte
*begin
= buf
;
20005 if ((byte
& 128) == 0)
20006 return buf
- begin
;
20011 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
20020 cu
->language
= language_c
;
20023 case DW_LANG_C_plus_plus
:
20024 case DW_LANG_C_plus_plus_11
:
20025 case DW_LANG_C_plus_plus_14
:
20026 cu
->language
= language_cplus
;
20029 cu
->language
= language_d
;
20031 case DW_LANG_Fortran77
:
20032 case DW_LANG_Fortran90
:
20033 case DW_LANG_Fortran95
:
20034 case DW_LANG_Fortran03
:
20035 case DW_LANG_Fortran08
:
20036 cu
->language
= language_fortran
;
20039 cu
->language
= language_go
;
20041 case DW_LANG_Mips_Assembler
:
20042 cu
->language
= language_asm
;
20044 case DW_LANG_Ada83
:
20045 case DW_LANG_Ada95
:
20046 cu
->language
= language_ada
;
20048 case DW_LANG_Modula2
:
20049 cu
->language
= language_m2
;
20051 case DW_LANG_Pascal83
:
20052 cu
->language
= language_pascal
;
20055 cu
->language
= language_objc
;
20058 case DW_LANG_Rust_old
:
20059 cu
->language
= language_rust
;
20061 case DW_LANG_Cobol74
:
20062 case DW_LANG_Cobol85
:
20064 cu
->language
= language_minimal
;
20067 cu
->language_defn
= language_def (cu
->language
);
20070 /* Return the named attribute or NULL if not there. */
20072 static struct attribute
*
20073 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20078 struct attribute
*spec
= NULL
;
20080 for (i
= 0; i
< die
->num_attrs
; ++i
)
20082 if (die
->attrs
[i
].name
== name
)
20083 return &die
->attrs
[i
];
20084 if (die
->attrs
[i
].name
== DW_AT_specification
20085 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
20086 spec
= &die
->attrs
[i
];
20092 die
= follow_die_ref (die
, spec
, &cu
);
20098 /* Return the named attribute or NULL if not there,
20099 but do not follow DW_AT_specification, etc.
20100 This is for use in contexts where we're reading .debug_types dies.
20101 Following DW_AT_specification, DW_AT_abstract_origin will take us
20102 back up the chain, and we want to go down. */
20104 static struct attribute
*
20105 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
20109 for (i
= 0; i
< die
->num_attrs
; ++i
)
20110 if (die
->attrs
[i
].name
== name
)
20111 return &die
->attrs
[i
];
20116 /* Return the string associated with a string-typed attribute, or NULL if it
20117 is either not found or is of an incorrect type. */
20119 static const char *
20120 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20122 struct attribute
*attr
;
20123 const char *str
= NULL
;
20125 attr
= dwarf2_attr (die
, name
, cu
);
20129 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
20130 || attr
->form
== DW_FORM_string
20131 || attr
->form
== DW_FORM_strx
20132 || attr
->form
== DW_FORM_GNU_str_index
20133 || attr
->form
== DW_FORM_GNU_strp_alt
)
20134 str
= DW_STRING (attr
);
20136 complaint (_("string type expected for attribute %s for "
20137 "DIE at %s in module %s"),
20138 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
20139 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
20145 /* Return the dwo name or NULL if not present. If present, it is in either
20146 DW_AT_GNU_dwo_name or DW_AT_dwo_name atrribute. */
20147 static const char *
20148 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
20150 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
20151 if (dwo_name
== nullptr)
20152 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
20156 /* Return non-zero iff the attribute NAME is defined for the given DIE,
20157 and holds a non-zero value. This function should only be used for
20158 DW_FORM_flag or DW_FORM_flag_present attributes. */
20161 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
20163 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
20165 return (attr
&& DW_UNSND (attr
));
20169 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
20171 /* A DIE is a declaration if it has a DW_AT_declaration attribute
20172 which value is non-zero. However, we have to be careful with
20173 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
20174 (via dwarf2_flag_true_p) follows this attribute. So we may
20175 end up accidently finding a declaration attribute that belongs
20176 to a different DIE referenced by the specification attribute,
20177 even though the given DIE does not have a declaration attribute. */
20178 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
20179 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
20182 /* Return the die giving the specification for DIE, if there is
20183 one. *SPEC_CU is the CU containing DIE on input, and the CU
20184 containing the return value on output. If there is no
20185 specification, but there is an abstract origin, that is
20188 static struct die_info
*
20189 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
20191 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
20194 if (spec_attr
== NULL
)
20195 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
20197 if (spec_attr
== NULL
)
20200 return follow_die_ref (die
, spec_attr
, spec_cu
);
20203 /* Stub for free_line_header to match void * callback types. */
20206 free_line_header_voidp (void *arg
)
20208 struct line_header
*lh
= (struct line_header
*) arg
;
20214 line_header::add_include_dir (const char *include_dir
)
20216 if (dwarf_line_debug
>= 2)
20217 fprintf_unfiltered (gdb_stdlog
, "Adding dir %zu: %s\n",
20218 include_dirs
.size () + 1, include_dir
);
20220 include_dirs
.push_back (include_dir
);
20224 line_header::add_file_name (const char *name
,
20226 unsigned int mod_time
,
20227 unsigned int length
)
20229 if (dwarf_line_debug
>= 2)
20230 fprintf_unfiltered (gdb_stdlog
, "Adding file %u: %s\n",
20231 (unsigned) file_names
.size () + 1, name
);
20233 file_names
.emplace_back (name
, d_index
, mod_time
, length
);
20236 /* A convenience function to find the proper .debug_line section for a CU. */
20238 static struct dwarf2_section_info
*
20239 get_debug_line_section (struct dwarf2_cu
*cu
)
20241 struct dwarf2_section_info
*section
;
20242 struct dwarf2_per_objfile
*dwarf2_per_objfile
20243 = cu
->per_cu
->dwarf2_per_objfile
;
20245 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
20247 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20248 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
20249 else if (cu
->per_cu
->is_dwz
)
20251 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
20253 section
= &dwz
->line
;
20256 section
= &dwarf2_per_objfile
->line
;
20261 /* Read directory or file name entry format, starting with byte of
20262 format count entries, ULEB128 pairs of entry formats, ULEB128 of
20263 entries count and the entries themselves in the described entry
20267 read_formatted_entries (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20268 bfd
*abfd
, const gdb_byte
**bufp
,
20269 struct line_header
*lh
,
20270 const struct comp_unit_head
*cu_header
,
20271 void (*callback
) (struct line_header
*lh
,
20274 unsigned int mod_time
,
20275 unsigned int length
))
20277 gdb_byte format_count
, formati
;
20278 ULONGEST data_count
, datai
;
20279 const gdb_byte
*buf
= *bufp
;
20280 const gdb_byte
*format_header_data
;
20281 unsigned int bytes_read
;
20283 format_count
= read_1_byte (abfd
, buf
);
20285 format_header_data
= buf
;
20286 for (formati
= 0; formati
< format_count
; formati
++)
20288 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20290 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20294 data_count
= read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20296 for (datai
= 0; datai
< data_count
; datai
++)
20298 const gdb_byte
*format
= format_header_data
;
20299 struct file_entry fe
;
20301 for (formati
= 0; formati
< format_count
; formati
++)
20303 ULONGEST content_type
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20304 format
+= bytes_read
;
20306 ULONGEST form
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20307 format
+= bytes_read
;
20309 gdb::optional
<const char *> string
;
20310 gdb::optional
<unsigned int> uint
;
20314 case DW_FORM_string
:
20315 string
.emplace (read_direct_string (abfd
, buf
, &bytes_read
));
20319 case DW_FORM_line_strp
:
20320 string
.emplace (read_indirect_line_string (dwarf2_per_objfile
,
20327 case DW_FORM_data1
:
20328 uint
.emplace (read_1_byte (abfd
, buf
));
20332 case DW_FORM_data2
:
20333 uint
.emplace (read_2_bytes (abfd
, buf
));
20337 case DW_FORM_data4
:
20338 uint
.emplace (read_4_bytes (abfd
, buf
));
20342 case DW_FORM_data8
:
20343 uint
.emplace (read_8_bytes (abfd
, buf
));
20347 case DW_FORM_udata
:
20348 uint
.emplace (read_unsigned_leb128 (abfd
, buf
, &bytes_read
));
20352 case DW_FORM_block
:
20353 /* It is valid only for DW_LNCT_timestamp which is ignored by
20358 switch (content_type
)
20361 if (string
.has_value ())
20364 case DW_LNCT_directory_index
:
20365 if (uint
.has_value ())
20366 fe
.d_index
= (dir_index
) *uint
;
20368 case DW_LNCT_timestamp
:
20369 if (uint
.has_value ())
20370 fe
.mod_time
= *uint
;
20373 if (uint
.has_value ())
20379 complaint (_("Unknown format content type %s"),
20380 pulongest (content_type
));
20384 callback (lh
, fe
.name
, fe
.d_index
, fe
.mod_time
, fe
.length
);
20390 /* Read the statement program header starting at OFFSET in
20391 .debug_line, or .debug_line.dwo. Return a pointer
20392 to a struct line_header, allocated using xmalloc.
20393 Returns NULL if there is a problem reading the header, e.g., if it
20394 has a version we don't understand.
20396 NOTE: the strings in the include directory and file name tables of
20397 the returned object point into the dwarf line section buffer,
20398 and must not be freed. */
20400 static line_header_up
20401 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
20403 const gdb_byte
*line_ptr
;
20404 unsigned int bytes_read
, offset_size
;
20406 const char *cur_dir
, *cur_file
;
20407 struct dwarf2_section_info
*section
;
20409 struct dwarf2_per_objfile
*dwarf2_per_objfile
20410 = cu
->per_cu
->dwarf2_per_objfile
;
20412 section
= get_debug_line_section (cu
);
20413 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
20414 if (section
->buffer
== NULL
)
20416 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20417 complaint (_("missing .debug_line.dwo section"));
20419 complaint (_("missing .debug_line section"));
20423 /* We can't do this until we know the section is non-empty.
20424 Only then do we know we have such a section. */
20425 abfd
= get_section_bfd_owner (section
);
20427 /* Make sure that at least there's room for the total_length field.
20428 That could be 12 bytes long, but we're just going to fudge that. */
20429 if (to_underlying (sect_off
) + 4 >= section
->size
)
20431 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20435 line_header_up
lh (new line_header ());
20437 lh
->sect_off
= sect_off
;
20438 lh
->offset_in_dwz
= cu
->per_cu
->is_dwz
;
20440 line_ptr
= section
->buffer
+ to_underlying (sect_off
);
20442 /* Read in the header. */
20444 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
20445 &bytes_read
, &offset_size
);
20446 line_ptr
+= bytes_read
;
20447 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
20449 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20452 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
20453 lh
->version
= read_2_bytes (abfd
, line_ptr
);
20455 if (lh
->version
> 5)
20457 /* This is a version we don't understand. The format could have
20458 changed in ways we don't handle properly so just punt. */
20459 complaint (_("unsupported version in .debug_line section"));
20462 if (lh
->version
>= 5)
20464 gdb_byte segment_selector_size
;
20466 /* Skip address size. */
20467 read_1_byte (abfd
, line_ptr
);
20470 segment_selector_size
= read_1_byte (abfd
, line_ptr
);
20472 if (segment_selector_size
!= 0)
20474 complaint (_("unsupported segment selector size %u "
20475 "in .debug_line section"),
20476 segment_selector_size
);
20480 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
20481 line_ptr
+= offset_size
;
20482 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
20484 if (lh
->version
>= 4)
20486 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
20490 lh
->maximum_ops_per_instruction
= 1;
20492 if (lh
->maximum_ops_per_instruction
== 0)
20494 lh
->maximum_ops_per_instruction
= 1;
20495 complaint (_("invalid maximum_ops_per_instruction "
20496 "in `.debug_line' section"));
20499 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
20501 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
20503 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
20505 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
20507 lh
->standard_opcode_lengths
.reset (new unsigned char[lh
->opcode_base
]);
20509 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
20510 for (i
= 1; i
< lh
->opcode_base
; ++i
)
20512 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
20516 if (lh
->version
>= 5)
20518 /* Read directory table. */
20519 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20521 [] (struct line_header
*header
, const char *name
,
20522 dir_index d_index
, unsigned int mod_time
,
20523 unsigned int length
)
20525 header
->add_include_dir (name
);
20528 /* Read file name table. */
20529 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20531 [] (struct line_header
*header
, const char *name
,
20532 dir_index d_index
, unsigned int mod_time
,
20533 unsigned int length
)
20535 header
->add_file_name (name
, d_index
, mod_time
, length
);
20540 /* Read directory table. */
20541 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20543 line_ptr
+= bytes_read
;
20544 lh
->add_include_dir (cur_dir
);
20546 line_ptr
+= bytes_read
;
20548 /* Read file name table. */
20549 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20551 unsigned int mod_time
, length
;
20554 line_ptr
+= bytes_read
;
20555 d_index
= (dir_index
) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20556 line_ptr
+= bytes_read
;
20557 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20558 line_ptr
+= bytes_read
;
20559 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20560 line_ptr
+= bytes_read
;
20562 lh
->add_file_name (cur_file
, d_index
, mod_time
, length
);
20564 line_ptr
+= bytes_read
;
20566 lh
->statement_program_start
= line_ptr
;
20568 if (line_ptr
> (section
->buffer
+ section
->size
))
20569 complaint (_("line number info header doesn't "
20570 "fit in `.debug_line' section"));
20575 /* Subroutine of dwarf_decode_lines to simplify it.
20576 Return the file name of the psymtab for included file FILE_INDEX
20577 in line header LH of PST.
20578 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20579 If space for the result is malloc'd, *NAME_HOLDER will be set.
20580 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
20582 static const char *
20583 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
20584 const struct partial_symtab
*pst
,
20585 const char *comp_dir
,
20586 gdb::unique_xmalloc_ptr
<char> *name_holder
)
20588 const file_entry
&fe
= lh
->file_names
[file_index
];
20589 const char *include_name
= fe
.name
;
20590 const char *include_name_to_compare
= include_name
;
20591 const char *pst_filename
;
20594 const char *dir_name
= fe
.include_dir (lh
);
20596 gdb::unique_xmalloc_ptr
<char> hold_compare
;
20597 if (!IS_ABSOLUTE_PATH (include_name
)
20598 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
20600 /* Avoid creating a duplicate psymtab for PST.
20601 We do this by comparing INCLUDE_NAME and PST_FILENAME.
20602 Before we do the comparison, however, we need to account
20603 for DIR_NAME and COMP_DIR.
20604 First prepend dir_name (if non-NULL). If we still don't
20605 have an absolute path prepend comp_dir (if non-NULL).
20606 However, the directory we record in the include-file's
20607 psymtab does not contain COMP_DIR (to match the
20608 corresponding symtab(s)).
20613 bash$ gcc -g ./hello.c
20614 include_name = "hello.c"
20616 DW_AT_comp_dir = comp_dir = "/tmp"
20617 DW_AT_name = "./hello.c"
20621 if (dir_name
!= NULL
)
20623 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
20624 include_name
, (char *) NULL
));
20625 include_name
= name_holder
->get ();
20626 include_name_to_compare
= include_name
;
20628 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
20630 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
20631 include_name
, (char *) NULL
));
20632 include_name_to_compare
= hold_compare
.get ();
20636 pst_filename
= pst
->filename
;
20637 gdb::unique_xmalloc_ptr
<char> copied_name
;
20638 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
20640 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
20641 pst_filename
, (char *) NULL
));
20642 pst_filename
= copied_name
.get ();
20645 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
20649 return include_name
;
20652 /* State machine to track the state of the line number program. */
20654 class lnp_state_machine
20657 /* Initialize a machine state for the start of a line number
20659 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
20660 bool record_lines_p
);
20662 file_entry
*current_file ()
20664 /* lh->file_names is 0-based, but the file name numbers in the
20665 statement program are 1-based. */
20666 return m_line_header
->file_name_at (m_file
);
20669 /* Record the line in the state machine. END_SEQUENCE is true if
20670 we're processing the end of a sequence. */
20671 void record_line (bool end_sequence
);
20673 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
20674 nop-out rest of the lines in this sequence. */
20675 void check_line_address (struct dwarf2_cu
*cu
,
20676 const gdb_byte
*line_ptr
,
20677 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
20679 void handle_set_discriminator (unsigned int discriminator
)
20681 m_discriminator
= discriminator
;
20682 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
20685 /* Handle DW_LNE_set_address. */
20686 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
20689 address
+= baseaddr
;
20690 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
20693 /* Handle DW_LNS_advance_pc. */
20694 void handle_advance_pc (CORE_ADDR adjust
);
20696 /* Handle a special opcode. */
20697 void handle_special_opcode (unsigned char op_code
);
20699 /* Handle DW_LNS_advance_line. */
20700 void handle_advance_line (int line_delta
)
20702 advance_line (line_delta
);
20705 /* Handle DW_LNS_set_file. */
20706 void handle_set_file (file_name_index file
);
20708 /* Handle DW_LNS_negate_stmt. */
20709 void handle_negate_stmt ()
20711 m_is_stmt
= !m_is_stmt
;
20714 /* Handle DW_LNS_const_add_pc. */
20715 void handle_const_add_pc ();
20717 /* Handle DW_LNS_fixed_advance_pc. */
20718 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
20720 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20724 /* Handle DW_LNS_copy. */
20725 void handle_copy ()
20727 record_line (false);
20728 m_discriminator
= 0;
20731 /* Handle DW_LNE_end_sequence. */
20732 void handle_end_sequence ()
20734 m_currently_recording_lines
= true;
20738 /* Advance the line by LINE_DELTA. */
20739 void advance_line (int line_delta
)
20741 m_line
+= line_delta
;
20743 if (line_delta
!= 0)
20744 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20747 struct dwarf2_cu
*m_cu
;
20749 gdbarch
*m_gdbarch
;
20751 /* True if we're recording lines.
20752 Otherwise we're building partial symtabs and are just interested in
20753 finding include files mentioned by the line number program. */
20754 bool m_record_lines_p
;
20756 /* The line number header. */
20757 line_header
*m_line_header
;
20759 /* These are part of the standard DWARF line number state machine,
20760 and initialized according to the DWARF spec. */
20762 unsigned char m_op_index
= 0;
20763 /* The line table index (1-based) of the current file. */
20764 file_name_index m_file
= (file_name_index
) 1;
20765 unsigned int m_line
= 1;
20767 /* These are initialized in the constructor. */
20769 CORE_ADDR m_address
;
20771 unsigned int m_discriminator
;
20773 /* Additional bits of state we need to track. */
20775 /* The last file that we called dwarf2_start_subfile for.
20776 This is only used for TLLs. */
20777 unsigned int m_last_file
= 0;
20778 /* The last file a line number was recorded for. */
20779 struct subfile
*m_last_subfile
= NULL
;
20781 /* When true, record the lines we decode. */
20782 bool m_currently_recording_lines
= false;
20784 /* The last line number that was recorded, used to coalesce
20785 consecutive entries for the same line. This can happen, for
20786 example, when discriminators are present. PR 17276. */
20787 unsigned int m_last_line
= 0;
20788 bool m_line_has_non_zero_discriminator
= false;
20792 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
20794 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
20795 / m_line_header
->maximum_ops_per_instruction
)
20796 * m_line_header
->minimum_instruction_length
);
20797 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20798 m_op_index
= ((m_op_index
+ adjust
)
20799 % m_line_header
->maximum_ops_per_instruction
);
20803 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
20805 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
20806 CORE_ADDR addr_adj
= (((m_op_index
20807 + (adj_opcode
/ m_line_header
->line_range
))
20808 / m_line_header
->maximum_ops_per_instruction
)
20809 * m_line_header
->minimum_instruction_length
);
20810 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20811 m_op_index
= ((m_op_index
+ (adj_opcode
/ m_line_header
->line_range
))
20812 % m_line_header
->maximum_ops_per_instruction
);
20814 int line_delta
= (m_line_header
->line_base
20815 + (adj_opcode
% m_line_header
->line_range
));
20816 advance_line (line_delta
);
20817 record_line (false);
20818 m_discriminator
= 0;
20822 lnp_state_machine::handle_set_file (file_name_index file
)
20826 const file_entry
*fe
= current_file ();
20828 dwarf2_debug_line_missing_file_complaint ();
20829 else if (m_record_lines_p
)
20831 const char *dir
= fe
->include_dir (m_line_header
);
20833 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20834 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20835 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
20840 lnp_state_machine::handle_const_add_pc ()
20843 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
20846 = (((m_op_index
+ adjust
)
20847 / m_line_header
->maximum_ops_per_instruction
)
20848 * m_line_header
->minimum_instruction_length
);
20850 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20851 m_op_index
= ((m_op_index
+ adjust
)
20852 % m_line_header
->maximum_ops_per_instruction
);
20855 /* Return non-zero if we should add LINE to the line number table.
20856 LINE is the line to add, LAST_LINE is the last line that was added,
20857 LAST_SUBFILE is the subfile for LAST_LINE.
20858 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
20859 had a non-zero discriminator.
20861 We have to be careful in the presence of discriminators.
20862 E.g., for this line:
20864 for (i = 0; i < 100000; i++);
20866 clang can emit four line number entries for that one line,
20867 each with a different discriminator.
20868 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
20870 However, we want gdb to coalesce all four entries into one.
20871 Otherwise the user could stepi into the middle of the line and
20872 gdb would get confused about whether the pc really was in the
20873 middle of the line.
20875 Things are further complicated by the fact that two consecutive
20876 line number entries for the same line is a heuristic used by gcc
20877 to denote the end of the prologue. So we can't just discard duplicate
20878 entries, we have to be selective about it. The heuristic we use is
20879 that we only collapse consecutive entries for the same line if at least
20880 one of those entries has a non-zero discriminator. PR 17276.
20882 Note: Addresses in the line number state machine can never go backwards
20883 within one sequence, thus this coalescing is ok. */
20886 dwarf_record_line_p (struct dwarf2_cu
*cu
,
20887 unsigned int line
, unsigned int last_line
,
20888 int line_has_non_zero_discriminator
,
20889 struct subfile
*last_subfile
)
20891 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
20893 if (line
!= last_line
)
20895 /* Same line for the same file that we've seen already.
20896 As a last check, for pr 17276, only record the line if the line
20897 has never had a non-zero discriminator. */
20898 if (!line_has_non_zero_discriminator
)
20903 /* Use the CU's builder to record line number LINE beginning at
20904 address ADDRESS in the line table of subfile SUBFILE. */
20907 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20908 unsigned int line
, CORE_ADDR address
,
20909 struct dwarf2_cu
*cu
)
20911 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
20913 if (dwarf_line_debug
)
20915 fprintf_unfiltered (gdb_stdlog
,
20916 "Recording line %u, file %s, address %s\n",
20917 line
, lbasename (subfile
->name
),
20918 paddress (gdbarch
, address
));
20922 cu
->get_builder ()->record_line (subfile
, line
, addr
);
20925 /* Subroutine of dwarf_decode_lines_1 to simplify it.
20926 Mark the end of a set of line number records.
20927 The arguments are the same as for dwarf_record_line_1.
20928 If SUBFILE is NULL the request is ignored. */
20931 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20932 CORE_ADDR address
, struct dwarf2_cu
*cu
)
20934 if (subfile
== NULL
)
20937 if (dwarf_line_debug
)
20939 fprintf_unfiltered (gdb_stdlog
,
20940 "Finishing current line, file %s, address %s\n",
20941 lbasename (subfile
->name
),
20942 paddress (gdbarch
, address
));
20945 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, cu
);
20949 lnp_state_machine::record_line (bool end_sequence
)
20951 if (dwarf_line_debug
)
20953 fprintf_unfiltered (gdb_stdlog
,
20954 "Processing actual line %u: file %u,"
20955 " address %s, is_stmt %u, discrim %u\n",
20956 m_line
, to_underlying (m_file
),
20957 paddress (m_gdbarch
, m_address
),
20958 m_is_stmt
, m_discriminator
);
20961 file_entry
*fe
= current_file ();
20964 dwarf2_debug_line_missing_file_complaint ();
20965 /* For now we ignore lines not starting on an instruction boundary.
20966 But not when processing end_sequence for compatibility with the
20967 previous version of the code. */
20968 else if (m_op_index
== 0 || end_sequence
)
20970 fe
->included_p
= 1;
20971 if (m_record_lines_p
&& (producer_is_codewarrior (m_cu
) || m_is_stmt
))
20973 if (m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ()
20976 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
20977 m_currently_recording_lines
? m_cu
: nullptr);
20982 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
20983 m_line_has_non_zero_discriminator
,
20986 buildsym_compunit
*builder
= m_cu
->get_builder ();
20987 dwarf_record_line_1 (m_gdbarch
,
20988 builder
->get_current_subfile (),
20990 m_currently_recording_lines
? m_cu
: nullptr);
20992 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20993 m_last_line
= m_line
;
20999 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
21000 line_header
*lh
, bool record_lines_p
)
21004 m_record_lines_p
= record_lines_p
;
21005 m_line_header
= lh
;
21007 m_currently_recording_lines
= true;
21009 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
21010 was a line entry for it so that the backend has a chance to adjust it
21011 and also record it in case it needs it. This is currently used by MIPS
21012 code, cf. `mips_adjust_dwarf2_line'. */
21013 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
21014 m_is_stmt
= lh
->default_is_stmt
;
21015 m_discriminator
= 0;
21019 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
21020 const gdb_byte
*line_ptr
,
21021 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
21023 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
21024 the pc range of the CU. However, we restrict the test to only ADDRESS
21025 values of zero to preserve GDB's previous behaviour which is to handle
21026 the specific case of a function being GC'd by the linker. */
21028 if (address
== 0 && address
< unrelocated_lowpc
)
21030 /* This line table is for a function which has been
21031 GCd by the linker. Ignore it. PR gdb/12528 */
21033 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21034 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
21036 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
21037 line_offset
, objfile_name (objfile
));
21038 m_currently_recording_lines
= false;
21039 /* Note: m_currently_recording_lines is left as false until we see
21040 DW_LNE_end_sequence. */
21044 /* Subroutine of dwarf_decode_lines to simplify it.
21045 Process the line number information in LH.
21046 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
21047 program in order to set included_p for every referenced header. */
21050 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
21051 const int decode_for_pst_p
, CORE_ADDR lowpc
)
21053 const gdb_byte
*line_ptr
, *extended_end
;
21054 const gdb_byte
*line_end
;
21055 unsigned int bytes_read
, extended_len
;
21056 unsigned char op_code
, extended_op
;
21057 CORE_ADDR baseaddr
;
21058 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21059 bfd
*abfd
= objfile
->obfd
;
21060 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21061 /* True if we're recording line info (as opposed to building partial
21062 symtabs and just interested in finding include files mentioned by
21063 the line number program). */
21064 bool record_lines_p
= !decode_for_pst_p
;
21066 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
21068 line_ptr
= lh
->statement_program_start
;
21069 line_end
= lh
->statement_program_end
;
21071 /* Read the statement sequences until there's nothing left. */
21072 while (line_ptr
< line_end
)
21074 /* The DWARF line number program state machine. Reset the state
21075 machine at the start of each sequence. */
21076 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
21077 bool end_sequence
= false;
21079 if (record_lines_p
)
21081 /* Start a subfile for the current file of the state
21083 const file_entry
*fe
= state_machine
.current_file ();
21086 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
21089 /* Decode the table. */
21090 while (line_ptr
< line_end
&& !end_sequence
)
21092 op_code
= read_1_byte (abfd
, line_ptr
);
21095 if (op_code
>= lh
->opcode_base
)
21097 /* Special opcode. */
21098 state_machine
.handle_special_opcode (op_code
);
21100 else switch (op_code
)
21102 case DW_LNS_extended_op
:
21103 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
21105 line_ptr
+= bytes_read
;
21106 extended_end
= line_ptr
+ extended_len
;
21107 extended_op
= read_1_byte (abfd
, line_ptr
);
21109 switch (extended_op
)
21111 case DW_LNE_end_sequence
:
21112 state_machine
.handle_end_sequence ();
21113 end_sequence
= true;
21115 case DW_LNE_set_address
:
21118 = read_address (abfd
, line_ptr
, cu
, &bytes_read
);
21119 line_ptr
+= bytes_read
;
21121 state_machine
.check_line_address (cu
, line_ptr
,
21122 lowpc
- baseaddr
, address
);
21123 state_machine
.handle_set_address (baseaddr
, address
);
21126 case DW_LNE_define_file
:
21128 const char *cur_file
;
21129 unsigned int mod_time
, length
;
21132 cur_file
= read_direct_string (abfd
, line_ptr
,
21134 line_ptr
+= bytes_read
;
21135 dindex
= (dir_index
)
21136 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21137 line_ptr
+= bytes_read
;
21139 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21140 line_ptr
+= bytes_read
;
21142 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21143 line_ptr
+= bytes_read
;
21144 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
21147 case DW_LNE_set_discriminator
:
21149 /* The discriminator is not interesting to the
21150 debugger; just ignore it. We still need to
21151 check its value though:
21152 if there are consecutive entries for the same
21153 (non-prologue) line we want to coalesce them.
21156 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21157 line_ptr
+= bytes_read
;
21159 state_machine
.handle_set_discriminator (discr
);
21163 complaint (_("mangled .debug_line section"));
21166 /* Make sure that we parsed the extended op correctly. If e.g.
21167 we expected a different address size than the producer used,
21168 we may have read the wrong number of bytes. */
21169 if (line_ptr
!= extended_end
)
21171 complaint (_("mangled .debug_line section"));
21176 state_machine
.handle_copy ();
21178 case DW_LNS_advance_pc
:
21181 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21182 line_ptr
+= bytes_read
;
21184 state_machine
.handle_advance_pc (adjust
);
21187 case DW_LNS_advance_line
:
21190 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
21191 line_ptr
+= bytes_read
;
21193 state_machine
.handle_advance_line (line_delta
);
21196 case DW_LNS_set_file
:
21198 file_name_index file
21199 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
21201 line_ptr
+= bytes_read
;
21203 state_machine
.handle_set_file (file
);
21206 case DW_LNS_set_column
:
21207 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21208 line_ptr
+= bytes_read
;
21210 case DW_LNS_negate_stmt
:
21211 state_machine
.handle_negate_stmt ();
21213 case DW_LNS_set_basic_block
:
21215 /* Add to the address register of the state machine the
21216 address increment value corresponding to special opcode
21217 255. I.e., this value is scaled by the minimum
21218 instruction length since special opcode 255 would have
21219 scaled the increment. */
21220 case DW_LNS_const_add_pc
:
21221 state_machine
.handle_const_add_pc ();
21223 case DW_LNS_fixed_advance_pc
:
21225 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
21228 state_machine
.handle_fixed_advance_pc (addr_adj
);
21233 /* Unknown standard opcode, ignore it. */
21236 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
21238 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21239 line_ptr
+= bytes_read
;
21246 dwarf2_debug_line_missing_end_sequence_complaint ();
21248 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
21249 in which case we still finish recording the last line). */
21250 state_machine
.record_line (true);
21254 /* Decode the Line Number Program (LNP) for the given line_header
21255 structure and CU. The actual information extracted and the type
21256 of structures created from the LNP depends on the value of PST.
21258 1. If PST is NULL, then this procedure uses the data from the program
21259 to create all necessary symbol tables, and their linetables.
21261 2. If PST is not NULL, this procedure reads the program to determine
21262 the list of files included by the unit represented by PST, and
21263 builds all the associated partial symbol tables.
21265 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
21266 It is used for relative paths in the line table.
21267 NOTE: When processing partial symtabs (pst != NULL),
21268 comp_dir == pst->dirname.
21270 NOTE: It is important that psymtabs have the same file name (via strcmp)
21271 as the corresponding symtab. Since COMP_DIR is not used in the name of the
21272 symtab we don't use it in the name of the psymtabs we create.
21273 E.g. expand_line_sal requires this when finding psymtabs to expand.
21274 A good testcase for this is mb-inline.exp.
21276 LOWPC is the lowest address in CU (or 0 if not known).
21278 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
21279 for its PC<->lines mapping information. Otherwise only the filename
21280 table is read in. */
21283 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
21284 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
21285 CORE_ADDR lowpc
, int decode_mapping
)
21287 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21288 const int decode_for_pst_p
= (pst
!= NULL
);
21290 if (decode_mapping
)
21291 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
21293 if (decode_for_pst_p
)
21297 /* Now that we're done scanning the Line Header Program, we can
21298 create the psymtab of each included file. */
21299 for (file_index
= 0; file_index
< lh
->file_names
.size (); file_index
++)
21300 if (lh
->file_names
[file_index
].included_p
== 1)
21302 gdb::unique_xmalloc_ptr
<char> name_holder
;
21303 const char *include_name
=
21304 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
,
21306 if (include_name
!= NULL
)
21307 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
21312 /* Make sure a symtab is created for every file, even files
21313 which contain only variables (i.e. no code with associated
21315 buildsym_compunit
*builder
= cu
->get_builder ();
21316 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
21319 for (i
= 0; i
< lh
->file_names
.size (); i
++)
21321 file_entry
&fe
= lh
->file_names
[i
];
21323 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
21325 if (builder
->get_current_subfile ()->symtab
== NULL
)
21327 builder
->get_current_subfile ()->symtab
21328 = allocate_symtab (cust
,
21329 builder
->get_current_subfile ()->name
);
21331 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
21336 /* Start a subfile for DWARF. FILENAME is the name of the file and
21337 DIRNAME the name of the source directory which contains FILENAME
21338 or NULL if not known.
21339 This routine tries to keep line numbers from identical absolute and
21340 relative file names in a common subfile.
21342 Using the `list' example from the GDB testsuite, which resides in
21343 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
21344 of /srcdir/list0.c yields the following debugging information for list0.c:
21346 DW_AT_name: /srcdir/list0.c
21347 DW_AT_comp_dir: /compdir
21348 files.files[0].name: list0.h
21349 files.files[0].dir: /srcdir
21350 files.files[1].name: list0.c
21351 files.files[1].dir: /srcdir
21353 The line number information for list0.c has to end up in a single
21354 subfile, so that `break /srcdir/list0.c:1' works as expected.
21355 start_subfile will ensure that this happens provided that we pass the
21356 concatenation of files.files[1].dir and files.files[1].name as the
21360 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
21361 const char *dirname
)
21365 /* In order not to lose the line information directory,
21366 we concatenate it to the filename when it makes sense.
21367 Note that the Dwarf3 standard says (speaking of filenames in line
21368 information): ``The directory index is ignored for file names
21369 that represent full path names''. Thus ignoring dirname in the
21370 `else' branch below isn't an issue. */
21372 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
21374 copy
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
21378 cu
->get_builder ()->start_subfile (filename
);
21384 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
21385 buildsym_compunit constructor. */
21387 struct compunit_symtab
*
21388 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
21391 gdb_assert (m_builder
== nullptr);
21393 m_builder
.reset (new struct buildsym_compunit
21394 (per_cu
->dwarf2_per_objfile
->objfile
,
21395 name
, comp_dir
, language
, low_pc
));
21397 list_in_scope
= get_builder ()->get_file_symbols ();
21399 get_builder ()->record_debugformat ("DWARF 2");
21400 get_builder ()->record_producer (producer
);
21402 processing_has_namespace_info
= false;
21404 return get_builder ()->get_compunit_symtab ();
21408 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
21409 struct dwarf2_cu
*cu
)
21411 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21412 struct comp_unit_head
*cu_header
= &cu
->header
;
21414 /* NOTE drow/2003-01-30: There used to be a comment and some special
21415 code here to turn a symbol with DW_AT_external and a
21416 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
21417 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
21418 with some versions of binutils) where shared libraries could have
21419 relocations against symbols in their debug information - the
21420 minimal symbol would have the right address, but the debug info
21421 would not. It's no longer necessary, because we will explicitly
21422 apply relocations when we read in the debug information now. */
21424 /* A DW_AT_location attribute with no contents indicates that a
21425 variable has been optimized away. */
21426 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
21428 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21432 /* Handle one degenerate form of location expression specially, to
21433 preserve GDB's previous behavior when section offsets are
21434 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
21435 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
21437 if (attr_form_is_block (attr
)
21438 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
21439 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
21440 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
21441 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
21442 && (DW_BLOCK (attr
)->size
21443 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
21445 unsigned int dummy
;
21447 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
21448 SYMBOL_VALUE_ADDRESS (sym
) =
21449 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
21451 SYMBOL_VALUE_ADDRESS (sym
) =
21452 read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1, &dummy
);
21453 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
21454 fixup_symbol_section (sym
, objfile
);
21455 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
21456 SYMBOL_SECTION (sym
));
21460 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
21461 expression evaluator, and use LOC_COMPUTED only when necessary
21462 (i.e. when the value of a register or memory location is
21463 referenced, or a thread-local block, etc.). Then again, it might
21464 not be worthwhile. I'm assuming that it isn't unless performance
21465 or memory numbers show me otherwise. */
21467 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
21469 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
21470 cu
->has_loclist
= true;
21473 /* Given a pointer to a DWARF information entry, figure out if we need
21474 to make a symbol table entry for it, and if so, create a new entry
21475 and return a pointer to it.
21476 If TYPE is NULL, determine symbol type from the die, otherwise
21477 used the passed type.
21478 If SPACE is not NULL, use it to hold the new symbol. If it is
21479 NULL, allocate a new symbol on the objfile's obstack. */
21481 static struct symbol
*
21482 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
21483 struct symbol
*space
)
21485 struct dwarf2_per_objfile
*dwarf2_per_objfile
21486 = cu
->per_cu
->dwarf2_per_objfile
;
21487 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21488 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21489 struct symbol
*sym
= NULL
;
21491 struct attribute
*attr
= NULL
;
21492 struct attribute
*attr2
= NULL
;
21493 CORE_ADDR baseaddr
;
21494 struct pending
**list_to_add
= NULL
;
21496 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
21498 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
21500 name
= dwarf2_name (die
, cu
);
21503 const char *linkagename
;
21504 int suppress_add
= 0;
21509 sym
= allocate_symbol (objfile
);
21510 OBJSTAT (objfile
, n_syms
++);
21512 /* Cache this symbol's name and the name's demangled form (if any). */
21513 SYMBOL_SET_LANGUAGE (sym
, cu
->language
, &objfile
->objfile_obstack
);
21514 linkagename
= dwarf2_physname (name
, die
, cu
);
21515 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
21517 /* Fortran does not have mangling standard and the mangling does differ
21518 between gfortran, iFort etc. */
21519 if (cu
->language
== language_fortran
21520 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
21521 symbol_set_demangled_name (&(sym
->ginfo
),
21522 dwarf2_full_name (name
, die
, cu
),
21525 /* Default assumptions.
21526 Use the passed type or decode it from the die. */
21527 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21528 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21530 SYMBOL_TYPE (sym
) = type
;
21532 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
21533 attr
= dwarf2_attr (die
,
21534 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
21538 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
21541 attr
= dwarf2_attr (die
,
21542 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
21546 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
21547 struct file_entry
*fe
;
21549 if (cu
->line_header
!= NULL
)
21550 fe
= cu
->line_header
->file_name_at (file_index
);
21555 complaint (_("file index out of range"));
21557 symbol_set_symtab (sym
, fe
->symtab
);
21563 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
21568 addr
= attr_value_as_address (attr
);
21569 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
21570 SYMBOL_VALUE_ADDRESS (sym
) = addr
;
21572 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
21573 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
21574 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
21575 add_symbol_to_list (sym
, cu
->list_in_scope
);
21577 case DW_TAG_subprogram
:
21578 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21580 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21581 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21582 if ((attr2
&& (DW_UNSND (attr2
) != 0))
21583 || cu
->language
== language_ada
)
21585 /* Subprograms marked external are stored as a global symbol.
21586 Ada subprograms, whether marked external or not, are always
21587 stored as a global symbol, because we want to be able to
21588 access them globally. For instance, we want to be able
21589 to break on a nested subprogram without having to
21590 specify the context. */
21591 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21595 list_to_add
= cu
->list_in_scope
;
21598 case DW_TAG_inlined_subroutine
:
21599 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21601 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21602 SYMBOL_INLINED (sym
) = 1;
21603 list_to_add
= cu
->list_in_scope
;
21605 case DW_TAG_template_value_param
:
21607 /* Fall through. */
21608 case DW_TAG_constant
:
21609 case DW_TAG_variable
:
21610 case DW_TAG_member
:
21611 /* Compilation with minimal debug info may result in
21612 variables with missing type entries. Change the
21613 misleading `void' type to something sensible. */
21614 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
21615 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
21617 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21618 /* In the case of DW_TAG_member, we should only be called for
21619 static const members. */
21620 if (die
->tag
== DW_TAG_member
)
21622 /* dwarf2_add_field uses die_is_declaration,
21623 so we do the same. */
21624 gdb_assert (die_is_declaration (die
, cu
));
21629 dwarf2_const_value (attr
, sym
, cu
);
21630 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21633 if (attr2
&& (DW_UNSND (attr2
) != 0))
21634 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21636 list_to_add
= cu
->list_in_scope
;
21640 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21643 var_decode_location (attr
, sym
, cu
);
21644 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21646 /* Fortran explicitly imports any global symbols to the local
21647 scope by DW_TAG_common_block. */
21648 if (cu
->language
== language_fortran
&& die
->parent
21649 && die
->parent
->tag
== DW_TAG_common_block
)
21652 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21653 && SYMBOL_VALUE_ADDRESS (sym
) == 0
21654 && !dwarf2_per_objfile
->has_section_at_zero
)
21656 /* When a static variable is eliminated by the linker,
21657 the corresponding debug information is not stripped
21658 out, but the variable address is set to null;
21659 do not add such variables into symbol table. */
21661 else if (attr2
&& (DW_UNSND (attr2
) != 0))
21663 /* Workaround gfortran PR debug/40040 - it uses
21664 DW_AT_location for variables in -fPIC libraries which may
21665 get overriden by other libraries/executable and get
21666 a different address. Resolve it by the minimal symbol
21667 which may come from inferior's executable using copy
21668 relocation. Make this workaround only for gfortran as for
21669 other compilers GDB cannot guess the minimal symbol
21670 Fortran mangling kind. */
21671 if (cu
->language
== language_fortran
&& die
->parent
21672 && die
->parent
->tag
== DW_TAG_module
21674 && startswith (cu
->producer
, "GNU Fortran"))
21675 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21677 /* A variable with DW_AT_external is never static,
21678 but it may be block-scoped. */
21680 = ((cu
->list_in_scope
21681 == cu
->get_builder ()->get_file_symbols ())
21682 ? cu
->get_builder ()->get_global_symbols ()
21683 : cu
->list_in_scope
);
21686 list_to_add
= cu
->list_in_scope
;
21690 /* We do not know the address of this symbol.
21691 If it is an external symbol and we have type information
21692 for it, enter the symbol as a LOC_UNRESOLVED symbol.
21693 The address of the variable will then be determined from
21694 the minimal symbol table whenever the variable is
21696 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21698 /* Fortran explicitly imports any global symbols to the local
21699 scope by DW_TAG_common_block. */
21700 if (cu
->language
== language_fortran
&& die
->parent
21701 && die
->parent
->tag
== DW_TAG_common_block
)
21703 /* SYMBOL_CLASS doesn't matter here because
21704 read_common_block is going to reset it. */
21706 list_to_add
= cu
->list_in_scope
;
21708 else if (attr2
&& (DW_UNSND (attr2
) != 0)
21709 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
21711 /* A variable with DW_AT_external is never static, but it
21712 may be block-scoped. */
21714 = ((cu
->list_in_scope
21715 == cu
->get_builder ()->get_file_symbols ())
21716 ? cu
->get_builder ()->get_global_symbols ()
21717 : cu
->list_in_scope
);
21719 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21721 else if (!die_is_declaration (die
, cu
))
21723 /* Use the default LOC_OPTIMIZED_OUT class. */
21724 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
21726 list_to_add
= cu
->list_in_scope
;
21730 case DW_TAG_formal_parameter
:
21732 /* If we are inside a function, mark this as an argument. If
21733 not, we might be looking at an argument to an inlined function
21734 when we do not have enough information to show inlined frames;
21735 pretend it's a local variable in that case so that the user can
21737 struct context_stack
*curr
21738 = cu
->get_builder ()->get_current_context_stack ();
21739 if (curr
!= nullptr && curr
->name
!= nullptr)
21740 SYMBOL_IS_ARGUMENT (sym
) = 1;
21741 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21744 var_decode_location (attr
, sym
, cu
);
21746 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21749 dwarf2_const_value (attr
, sym
, cu
);
21752 list_to_add
= cu
->list_in_scope
;
21755 case DW_TAG_unspecified_parameters
:
21756 /* From varargs functions; gdb doesn't seem to have any
21757 interest in this information, so just ignore it for now.
21760 case DW_TAG_template_type_param
:
21762 /* Fall through. */
21763 case DW_TAG_class_type
:
21764 case DW_TAG_interface_type
:
21765 case DW_TAG_structure_type
:
21766 case DW_TAG_union_type
:
21767 case DW_TAG_set_type
:
21768 case DW_TAG_enumeration_type
:
21769 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21770 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
21773 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
21774 really ever be static objects: otherwise, if you try
21775 to, say, break of a class's method and you're in a file
21776 which doesn't mention that class, it won't work unless
21777 the check for all static symbols in lookup_symbol_aux
21778 saves you. See the OtherFileClass tests in
21779 gdb.c++/namespace.exp. */
21783 buildsym_compunit
*builder
= cu
->get_builder ();
21785 = (cu
->list_in_scope
== builder
->get_file_symbols ()
21786 && cu
->language
== language_cplus
21787 ? builder
->get_global_symbols ()
21788 : cu
->list_in_scope
);
21790 /* The semantics of C++ state that "struct foo {
21791 ... }" also defines a typedef for "foo". */
21792 if (cu
->language
== language_cplus
21793 || cu
->language
== language_ada
21794 || cu
->language
== language_d
21795 || cu
->language
== language_rust
)
21797 /* The symbol's name is already allocated along
21798 with this objfile, so we don't need to
21799 duplicate it for the type. */
21800 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
21801 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
21806 case DW_TAG_typedef
:
21807 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21808 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21809 list_to_add
= cu
->list_in_scope
;
21811 case DW_TAG_base_type
:
21812 case DW_TAG_subrange_type
:
21813 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21814 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21815 list_to_add
= cu
->list_in_scope
;
21817 case DW_TAG_enumerator
:
21818 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21821 dwarf2_const_value (attr
, sym
, cu
);
21824 /* NOTE: carlton/2003-11-10: See comment above in the
21825 DW_TAG_class_type, etc. block. */
21828 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
21829 && cu
->language
== language_cplus
21830 ? cu
->get_builder ()->get_global_symbols ()
21831 : cu
->list_in_scope
);
21834 case DW_TAG_imported_declaration
:
21835 case DW_TAG_namespace
:
21836 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21837 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21839 case DW_TAG_module
:
21840 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21841 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
21842 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21844 case DW_TAG_common_block
:
21845 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
21846 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
21847 add_symbol_to_list (sym
, cu
->list_in_scope
);
21850 /* Not a tag we recognize. Hopefully we aren't processing
21851 trash data, but since we must specifically ignore things
21852 we don't recognize, there is nothing else we should do at
21854 complaint (_("unsupported tag: '%s'"),
21855 dwarf_tag_name (die
->tag
));
21861 sym
->hash_next
= objfile
->template_symbols
;
21862 objfile
->template_symbols
= sym
;
21863 list_to_add
= NULL
;
21866 if (list_to_add
!= NULL
)
21867 add_symbol_to_list (sym
, list_to_add
);
21869 /* For the benefit of old versions of GCC, check for anonymous
21870 namespaces based on the demangled name. */
21871 if (!cu
->processing_has_namespace_info
21872 && cu
->language
== language_cplus
)
21873 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
21878 /* Given an attr with a DW_FORM_dataN value in host byte order,
21879 zero-extend it as appropriate for the symbol's type. The DWARF
21880 standard (v4) is not entirely clear about the meaning of using
21881 DW_FORM_dataN for a constant with a signed type, where the type is
21882 wider than the data. The conclusion of a discussion on the DWARF
21883 list was that this is unspecified. We choose to always zero-extend
21884 because that is the interpretation long in use by GCC. */
21887 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
21888 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
21890 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21891 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
21892 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
21893 LONGEST l
= DW_UNSND (attr
);
21895 if (bits
< sizeof (*value
) * 8)
21897 l
&= ((LONGEST
) 1 << bits
) - 1;
21900 else if (bits
== sizeof (*value
) * 8)
21904 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
21905 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
21912 /* Read a constant value from an attribute. Either set *VALUE, or if
21913 the value does not fit in *VALUE, set *BYTES - either already
21914 allocated on the objfile obstack, or newly allocated on OBSTACK,
21915 or, set *BATON, if we translated the constant to a location
21919 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
21920 const char *name
, struct obstack
*obstack
,
21921 struct dwarf2_cu
*cu
,
21922 LONGEST
*value
, const gdb_byte
**bytes
,
21923 struct dwarf2_locexpr_baton
**baton
)
21925 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21926 struct comp_unit_head
*cu_header
= &cu
->header
;
21927 struct dwarf_block
*blk
;
21928 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
21929 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
21935 switch (attr
->form
)
21938 case DW_FORM_addrx
:
21939 case DW_FORM_GNU_addr_index
:
21943 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
21944 dwarf2_const_value_length_mismatch_complaint (name
,
21945 cu_header
->addr_size
,
21946 TYPE_LENGTH (type
));
21947 /* Symbols of this form are reasonably rare, so we just
21948 piggyback on the existing location code rather than writing
21949 a new implementation of symbol_computed_ops. */
21950 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
21951 (*baton
)->per_cu
= cu
->per_cu
;
21952 gdb_assert ((*baton
)->per_cu
);
21954 (*baton
)->size
= 2 + cu_header
->addr_size
;
21955 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
21956 (*baton
)->data
= data
;
21958 data
[0] = DW_OP_addr
;
21959 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
21960 byte_order
, DW_ADDR (attr
));
21961 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
21964 case DW_FORM_string
:
21967 case DW_FORM_GNU_str_index
:
21968 case DW_FORM_GNU_strp_alt
:
21969 /* DW_STRING is already allocated on the objfile obstack, point
21971 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
21973 case DW_FORM_block1
:
21974 case DW_FORM_block2
:
21975 case DW_FORM_block4
:
21976 case DW_FORM_block
:
21977 case DW_FORM_exprloc
:
21978 case DW_FORM_data16
:
21979 blk
= DW_BLOCK (attr
);
21980 if (TYPE_LENGTH (type
) != blk
->size
)
21981 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
21982 TYPE_LENGTH (type
));
21983 *bytes
= blk
->data
;
21986 /* The DW_AT_const_value attributes are supposed to carry the
21987 symbol's value "represented as it would be on the target
21988 architecture." By the time we get here, it's already been
21989 converted to host endianness, so we just need to sign- or
21990 zero-extend it as appropriate. */
21991 case DW_FORM_data1
:
21992 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
21994 case DW_FORM_data2
:
21995 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
21997 case DW_FORM_data4
:
21998 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
22000 case DW_FORM_data8
:
22001 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
22004 case DW_FORM_sdata
:
22005 case DW_FORM_implicit_const
:
22006 *value
= DW_SND (attr
);
22009 case DW_FORM_udata
:
22010 *value
= DW_UNSND (attr
);
22014 complaint (_("unsupported const value attribute form: '%s'"),
22015 dwarf_form_name (attr
->form
));
22022 /* Copy constant value from an attribute to a symbol. */
22025 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
22026 struct dwarf2_cu
*cu
)
22028 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22030 const gdb_byte
*bytes
;
22031 struct dwarf2_locexpr_baton
*baton
;
22033 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
22034 SYMBOL_PRINT_NAME (sym
),
22035 &objfile
->objfile_obstack
, cu
,
22036 &value
, &bytes
, &baton
);
22040 SYMBOL_LOCATION_BATON (sym
) = baton
;
22041 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
22043 else if (bytes
!= NULL
)
22045 SYMBOL_VALUE_BYTES (sym
) = bytes
;
22046 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
22050 SYMBOL_VALUE (sym
) = value
;
22051 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
22055 /* Return the type of the die in question using its DW_AT_type attribute. */
22057 static struct type
*
22058 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22060 struct attribute
*type_attr
;
22062 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
22065 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22066 /* A missing DW_AT_type represents a void type. */
22067 return objfile_type (objfile
)->builtin_void
;
22070 return lookup_die_type (die
, type_attr
, cu
);
22073 /* True iff CU's producer generates GNAT Ada auxiliary information
22074 that allows to find parallel types through that information instead
22075 of having to do expensive parallel lookups by type name. */
22078 need_gnat_info (struct dwarf2_cu
*cu
)
22080 /* Assume that the Ada compiler was GNAT, which always produces
22081 the auxiliary information. */
22082 return (cu
->language
== language_ada
);
22085 /* Return the auxiliary type of the die in question using its
22086 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
22087 attribute is not present. */
22089 static struct type
*
22090 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22092 struct attribute
*type_attr
;
22094 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
22098 return lookup_die_type (die
, type_attr
, cu
);
22101 /* If DIE has a descriptive_type attribute, then set the TYPE's
22102 descriptive type accordingly. */
22105 set_descriptive_type (struct type
*type
, struct die_info
*die
,
22106 struct dwarf2_cu
*cu
)
22108 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
22110 if (descriptive_type
)
22112 ALLOCATE_GNAT_AUX_TYPE (type
);
22113 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
22117 /* Return the containing type of the die in question using its
22118 DW_AT_containing_type attribute. */
22120 static struct type
*
22121 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22123 struct attribute
*type_attr
;
22124 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22126 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
22128 error (_("Dwarf Error: Problem turning containing type into gdb type "
22129 "[in module %s]"), objfile_name (objfile
));
22131 return lookup_die_type (die
, type_attr
, cu
);
22134 /* Return an error marker type to use for the ill formed type in DIE/CU. */
22136 static struct type
*
22137 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
22139 struct dwarf2_per_objfile
*dwarf2_per_objfile
22140 = cu
->per_cu
->dwarf2_per_objfile
;
22141 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22144 std::string message
22145 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
22146 objfile_name (objfile
),
22147 sect_offset_str (cu
->header
.sect_off
),
22148 sect_offset_str (die
->sect_off
));
22149 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
22151 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
22154 /* Look up the type of DIE in CU using its type attribute ATTR.
22155 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
22156 DW_AT_containing_type.
22157 If there is no type substitute an error marker. */
22159 static struct type
*
22160 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
22161 struct dwarf2_cu
*cu
)
22163 struct dwarf2_per_objfile
*dwarf2_per_objfile
22164 = cu
->per_cu
->dwarf2_per_objfile
;
22165 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22166 struct type
*this_type
;
22168 gdb_assert (attr
->name
== DW_AT_type
22169 || attr
->name
== DW_AT_GNAT_descriptive_type
22170 || attr
->name
== DW_AT_containing_type
);
22172 /* First see if we have it cached. */
22174 if (attr
->form
== DW_FORM_GNU_ref_alt
)
22176 struct dwarf2_per_cu_data
*per_cu
;
22177 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22179 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
22180 dwarf2_per_objfile
);
22181 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
22183 else if (attr_form_is_ref (attr
))
22185 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22187 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
22189 else if (attr
->form
== DW_FORM_ref_sig8
)
22191 ULONGEST signature
= DW_SIGNATURE (attr
);
22193 return get_signatured_type (die
, signature
, cu
);
22197 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
22198 " at %s [in module %s]"),
22199 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
22200 objfile_name (objfile
));
22201 return build_error_marker_type (cu
, die
);
22204 /* If not cached we need to read it in. */
22206 if (this_type
== NULL
)
22208 struct die_info
*type_die
= NULL
;
22209 struct dwarf2_cu
*type_cu
= cu
;
22211 if (attr_form_is_ref (attr
))
22212 type_die
= follow_die_ref (die
, attr
, &type_cu
);
22213 if (type_die
== NULL
)
22214 return build_error_marker_type (cu
, die
);
22215 /* If we find the type now, it's probably because the type came
22216 from an inter-CU reference and the type's CU got expanded before
22218 this_type
= read_type_die (type_die
, type_cu
);
22221 /* If we still don't have a type use an error marker. */
22223 if (this_type
== NULL
)
22224 return build_error_marker_type (cu
, die
);
22229 /* Return the type in DIE, CU.
22230 Returns NULL for invalid types.
22232 This first does a lookup in die_type_hash,
22233 and only reads the die in if necessary.
22235 NOTE: This can be called when reading in partial or full symbols. */
22237 static struct type
*
22238 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
22240 struct type
*this_type
;
22242 this_type
= get_die_type (die
, cu
);
22246 return read_type_die_1 (die
, cu
);
22249 /* Read the type in DIE, CU.
22250 Returns NULL for invalid types. */
22252 static struct type
*
22253 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
22255 struct type
*this_type
= NULL
;
22259 case DW_TAG_class_type
:
22260 case DW_TAG_interface_type
:
22261 case DW_TAG_structure_type
:
22262 case DW_TAG_union_type
:
22263 this_type
= read_structure_type (die
, cu
);
22265 case DW_TAG_enumeration_type
:
22266 this_type
= read_enumeration_type (die
, cu
);
22268 case DW_TAG_subprogram
:
22269 case DW_TAG_subroutine_type
:
22270 case DW_TAG_inlined_subroutine
:
22271 this_type
= read_subroutine_type (die
, cu
);
22273 case DW_TAG_array_type
:
22274 this_type
= read_array_type (die
, cu
);
22276 case DW_TAG_set_type
:
22277 this_type
= read_set_type (die
, cu
);
22279 case DW_TAG_pointer_type
:
22280 this_type
= read_tag_pointer_type (die
, cu
);
22282 case DW_TAG_ptr_to_member_type
:
22283 this_type
= read_tag_ptr_to_member_type (die
, cu
);
22285 case DW_TAG_reference_type
:
22286 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
22288 case DW_TAG_rvalue_reference_type
:
22289 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
22291 case DW_TAG_const_type
:
22292 this_type
= read_tag_const_type (die
, cu
);
22294 case DW_TAG_volatile_type
:
22295 this_type
= read_tag_volatile_type (die
, cu
);
22297 case DW_TAG_restrict_type
:
22298 this_type
= read_tag_restrict_type (die
, cu
);
22300 case DW_TAG_string_type
:
22301 this_type
= read_tag_string_type (die
, cu
);
22303 case DW_TAG_typedef
:
22304 this_type
= read_typedef (die
, cu
);
22306 case DW_TAG_subrange_type
:
22307 this_type
= read_subrange_type (die
, cu
);
22309 case DW_TAG_base_type
:
22310 this_type
= read_base_type (die
, cu
);
22312 case DW_TAG_unspecified_type
:
22313 this_type
= read_unspecified_type (die
, cu
);
22315 case DW_TAG_namespace
:
22316 this_type
= read_namespace_type (die
, cu
);
22318 case DW_TAG_module
:
22319 this_type
= read_module_type (die
, cu
);
22321 case DW_TAG_atomic_type
:
22322 this_type
= read_tag_atomic_type (die
, cu
);
22325 complaint (_("unexpected tag in read_type_die: '%s'"),
22326 dwarf_tag_name (die
->tag
));
22333 /* See if we can figure out if the class lives in a namespace. We do
22334 this by looking for a member function; its demangled name will
22335 contain namespace info, if there is any.
22336 Return the computed name or NULL.
22337 Space for the result is allocated on the objfile's obstack.
22338 This is the full-die version of guess_partial_die_structure_name.
22339 In this case we know DIE has no useful parent. */
22342 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22344 struct die_info
*spec_die
;
22345 struct dwarf2_cu
*spec_cu
;
22346 struct die_info
*child
;
22347 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22350 spec_die
= die_specification (die
, &spec_cu
);
22351 if (spec_die
!= NULL
)
22357 for (child
= die
->child
;
22359 child
= child
->sibling
)
22361 if (child
->tag
== DW_TAG_subprogram
)
22363 const char *linkage_name
= dw2_linkage_name (child
, cu
);
22365 if (linkage_name
!= NULL
)
22368 = language_class_name_from_physname (cu
->language_defn
,
22372 if (actual_name
!= NULL
)
22374 const char *die_name
= dwarf2_name (die
, cu
);
22376 if (die_name
!= NULL
22377 && strcmp (die_name
, actual_name
) != 0)
22379 /* Strip off the class name from the full name.
22380 We want the prefix. */
22381 int die_name_len
= strlen (die_name
);
22382 int actual_name_len
= strlen (actual_name
);
22384 /* Test for '::' as a sanity check. */
22385 if (actual_name_len
> die_name_len
+ 2
22386 && actual_name
[actual_name_len
22387 - die_name_len
- 1] == ':')
22388 name
= obstack_strndup (
22389 &objfile
->per_bfd
->storage_obstack
,
22390 actual_name
, actual_name_len
- die_name_len
- 2);
22393 xfree (actual_name
);
22402 /* GCC might emit a nameless typedef that has a linkage name. Determine the
22403 prefix part in such case. See
22404 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22406 static const char *
22407 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22409 struct attribute
*attr
;
22412 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
22413 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
22416 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
22419 attr
= dw2_linkage_name_attr (die
, cu
);
22420 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22423 /* dwarf2_name had to be already called. */
22424 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
22426 /* Strip the base name, keep any leading namespaces/classes. */
22427 base
= strrchr (DW_STRING (attr
), ':');
22428 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
22431 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22432 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
22434 &base
[-1] - DW_STRING (attr
));
22437 /* Return the name of the namespace/class that DIE is defined within,
22438 or "" if we can't tell. The caller should not xfree the result.
22440 For example, if we're within the method foo() in the following
22450 then determine_prefix on foo's die will return "N::C". */
22452 static const char *
22453 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22455 struct dwarf2_per_objfile
*dwarf2_per_objfile
22456 = cu
->per_cu
->dwarf2_per_objfile
;
22457 struct die_info
*parent
, *spec_die
;
22458 struct dwarf2_cu
*spec_cu
;
22459 struct type
*parent_type
;
22460 const char *retval
;
22462 if (cu
->language
!= language_cplus
22463 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
22464 && cu
->language
!= language_rust
)
22467 retval
= anonymous_struct_prefix (die
, cu
);
22471 /* We have to be careful in the presence of DW_AT_specification.
22472 For example, with GCC 3.4, given the code
22476 // Definition of N::foo.
22480 then we'll have a tree of DIEs like this:
22482 1: DW_TAG_compile_unit
22483 2: DW_TAG_namespace // N
22484 3: DW_TAG_subprogram // declaration of N::foo
22485 4: DW_TAG_subprogram // definition of N::foo
22486 DW_AT_specification // refers to die #3
22488 Thus, when processing die #4, we have to pretend that we're in
22489 the context of its DW_AT_specification, namely the contex of die
22492 spec_die
= die_specification (die
, &spec_cu
);
22493 if (spec_die
== NULL
)
22494 parent
= die
->parent
;
22497 parent
= spec_die
->parent
;
22501 if (parent
== NULL
)
22503 else if (parent
->building_fullname
)
22506 const char *parent_name
;
22508 /* It has been seen on RealView 2.2 built binaries,
22509 DW_TAG_template_type_param types actually _defined_ as
22510 children of the parent class:
22513 template class <class Enum> Class{};
22514 Class<enum E> class_e;
22516 1: DW_TAG_class_type (Class)
22517 2: DW_TAG_enumeration_type (E)
22518 3: DW_TAG_enumerator (enum1:0)
22519 3: DW_TAG_enumerator (enum2:1)
22521 2: DW_TAG_template_type_param
22522 DW_AT_type DW_FORM_ref_udata (E)
22524 Besides being broken debug info, it can put GDB into an
22525 infinite loop. Consider:
22527 When we're building the full name for Class<E>, we'll start
22528 at Class, and go look over its template type parameters,
22529 finding E. We'll then try to build the full name of E, and
22530 reach here. We're now trying to build the full name of E,
22531 and look over the parent DIE for containing scope. In the
22532 broken case, if we followed the parent DIE of E, we'd again
22533 find Class, and once again go look at its template type
22534 arguments, etc., etc. Simply don't consider such parent die
22535 as source-level parent of this die (it can't be, the language
22536 doesn't allow it), and break the loop here. */
22537 name
= dwarf2_name (die
, cu
);
22538 parent_name
= dwarf2_name (parent
, cu
);
22539 complaint (_("template param type '%s' defined within parent '%s'"),
22540 name
? name
: "<unknown>",
22541 parent_name
? parent_name
: "<unknown>");
22545 switch (parent
->tag
)
22547 case DW_TAG_namespace
:
22548 parent_type
= read_type_die (parent
, cu
);
22549 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
22550 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
22551 Work around this problem here. */
22552 if (cu
->language
== language_cplus
22553 && strcmp (TYPE_NAME (parent_type
), "::") == 0)
22555 /* We give a name to even anonymous namespaces. */
22556 return TYPE_NAME (parent_type
);
22557 case DW_TAG_class_type
:
22558 case DW_TAG_interface_type
:
22559 case DW_TAG_structure_type
:
22560 case DW_TAG_union_type
:
22561 case DW_TAG_module
:
22562 parent_type
= read_type_die (parent
, cu
);
22563 if (TYPE_NAME (parent_type
) != NULL
)
22564 return TYPE_NAME (parent_type
);
22566 /* An anonymous structure is only allowed non-static data
22567 members; no typedefs, no member functions, et cetera.
22568 So it does not need a prefix. */
22570 case DW_TAG_compile_unit
:
22571 case DW_TAG_partial_unit
:
22572 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
22573 if (cu
->language
== language_cplus
22574 && !dwarf2_per_objfile
->types
.empty ()
22575 && die
->child
!= NULL
22576 && (die
->tag
== DW_TAG_class_type
22577 || die
->tag
== DW_TAG_structure_type
22578 || die
->tag
== DW_TAG_union_type
))
22580 char *name
= guess_full_die_structure_name (die
, cu
);
22585 case DW_TAG_enumeration_type
:
22586 parent_type
= read_type_die (parent
, cu
);
22587 if (TYPE_DECLARED_CLASS (parent_type
))
22589 if (TYPE_NAME (parent_type
) != NULL
)
22590 return TYPE_NAME (parent_type
);
22593 /* Fall through. */
22595 return determine_prefix (parent
, cu
);
22599 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
22600 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
22601 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
22602 an obconcat, otherwise allocate storage for the result. The CU argument is
22603 used to determine the language and hence, the appropriate separator. */
22605 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
22608 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
22609 int physname
, struct dwarf2_cu
*cu
)
22611 const char *lead
= "";
22614 if (suffix
== NULL
|| suffix
[0] == '\0'
22615 || prefix
== NULL
|| prefix
[0] == '\0')
22617 else if (cu
->language
== language_d
)
22619 /* For D, the 'main' function could be defined in any module, but it
22620 should never be prefixed. */
22621 if (strcmp (suffix
, "D main") == 0)
22629 else if (cu
->language
== language_fortran
&& physname
)
22631 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
22632 DW_AT_MIPS_linkage_name is preferred and used instead. */
22640 if (prefix
== NULL
)
22642 if (suffix
== NULL
)
22649 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
22651 strcpy (retval
, lead
);
22652 strcat (retval
, prefix
);
22653 strcat (retval
, sep
);
22654 strcat (retval
, suffix
);
22659 /* We have an obstack. */
22660 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
22664 /* Return sibling of die, NULL if no sibling. */
22666 static struct die_info
*
22667 sibling_die (struct die_info
*die
)
22669 return die
->sibling
;
22672 /* Get name of a die, return NULL if not found. */
22674 static const char *
22675 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
22676 struct obstack
*obstack
)
22678 if (name
&& cu
->language
== language_cplus
)
22680 std::string canon_name
= cp_canonicalize_string (name
);
22682 if (!canon_name
.empty ())
22684 if (canon_name
!= name
)
22685 name
= obstack_strdup (obstack
, canon_name
);
22692 /* Get name of a die, return NULL if not found.
22693 Anonymous namespaces are converted to their magic string. */
22695 static const char *
22696 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22698 struct attribute
*attr
;
22699 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22701 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
22702 if ((!attr
|| !DW_STRING (attr
))
22703 && die
->tag
!= DW_TAG_namespace
22704 && die
->tag
!= DW_TAG_class_type
22705 && die
->tag
!= DW_TAG_interface_type
22706 && die
->tag
!= DW_TAG_structure_type
22707 && die
->tag
!= DW_TAG_union_type
)
22712 case DW_TAG_compile_unit
:
22713 case DW_TAG_partial_unit
:
22714 /* Compilation units have a DW_AT_name that is a filename, not
22715 a source language identifier. */
22716 case DW_TAG_enumeration_type
:
22717 case DW_TAG_enumerator
:
22718 /* These tags always have simple identifiers already; no need
22719 to canonicalize them. */
22720 return DW_STRING (attr
);
22722 case DW_TAG_namespace
:
22723 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
22724 return DW_STRING (attr
);
22725 return CP_ANONYMOUS_NAMESPACE_STR
;
22727 case DW_TAG_class_type
:
22728 case DW_TAG_interface_type
:
22729 case DW_TAG_structure_type
:
22730 case DW_TAG_union_type
:
22731 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
22732 structures or unions. These were of the form "._%d" in GCC 4.1,
22733 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
22734 and GCC 4.4. We work around this problem by ignoring these. */
22735 if (attr
&& DW_STRING (attr
)
22736 && (startswith (DW_STRING (attr
), "._")
22737 || startswith (DW_STRING (attr
), "<anonymous")))
22740 /* GCC might emit a nameless typedef that has a linkage name. See
22741 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22742 if (!attr
|| DW_STRING (attr
) == NULL
)
22744 char *demangled
= NULL
;
22746 attr
= dw2_linkage_name_attr (die
, cu
);
22747 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22750 /* Avoid demangling DW_STRING (attr) the second time on a second
22751 call for the same DIE. */
22752 if (!DW_STRING_IS_CANONICAL (attr
))
22753 demangled
= gdb_demangle (DW_STRING (attr
), DMGL_TYPES
);
22759 /* FIXME: we already did this for the partial symbol... */
22761 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
22763 DW_STRING_IS_CANONICAL (attr
) = 1;
22766 /* Strip any leading namespaces/classes, keep only the base name.
22767 DW_AT_name for named DIEs does not contain the prefixes. */
22768 base
= strrchr (DW_STRING (attr
), ':');
22769 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
22772 return DW_STRING (attr
);
22781 if (!DW_STRING_IS_CANONICAL (attr
))
22784 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
22785 &objfile
->per_bfd
->storage_obstack
);
22786 DW_STRING_IS_CANONICAL (attr
) = 1;
22788 return DW_STRING (attr
);
22791 /* Return the die that this die in an extension of, or NULL if there
22792 is none. *EXT_CU is the CU containing DIE on input, and the CU
22793 containing the return value on output. */
22795 static struct die_info
*
22796 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
22798 struct attribute
*attr
;
22800 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
22804 return follow_die_ref (die
, attr
, ext_cu
);
22807 /* A convenience function that returns an "unknown" DWARF name,
22808 including the value of V. STR is the name of the entity being
22809 printed, e.g., "TAG". */
22811 static const char *
22812 dwarf_unknown (const char *str
, unsigned v
)
22814 char *cell
= get_print_cell ();
22815 xsnprintf (cell
, PRINT_CELL_SIZE
, "DW_%s_<unknown: %u>", str
, v
);
22819 /* Convert a DIE tag into its string name. */
22821 static const char *
22822 dwarf_tag_name (unsigned tag
)
22824 const char *name
= get_DW_TAG_name (tag
);
22827 return dwarf_unknown ("TAG", tag
);
22832 /* Convert a DWARF attribute code into its string name. */
22834 static const char *
22835 dwarf_attr_name (unsigned attr
)
22839 #ifdef MIPS /* collides with DW_AT_HP_block_index */
22840 if (attr
== DW_AT_MIPS_fde
)
22841 return "DW_AT_MIPS_fde";
22843 if (attr
== DW_AT_HP_block_index
)
22844 return "DW_AT_HP_block_index";
22847 name
= get_DW_AT_name (attr
);
22850 return dwarf_unknown ("AT", attr
);
22855 /* Convert a unit type to corresponding DW_UT name. */
22857 static const char *
22858 dwarf_unit_type_name (int unit_type
) {
22862 return "DW_UT_compile (0x01)";
22864 return "DW_UT_type (0x02)";
22866 return "DW_UT_partial (0x03)";
22868 return "DW_UT_skeleton (0x04)";
22870 return "DW_UT_split_compile (0x05)";
22872 return "DW_UT_split_type (0x06)";
22874 return "DW_UT_lo_user (0x80)";
22876 return "DW_UT_hi_user (0xff)";
22882 /* Convert a DWARF value form code into its string name. */
22884 static const char *
22885 dwarf_form_name (unsigned form
)
22887 const char *name
= get_DW_FORM_name (form
);
22890 return dwarf_unknown ("FORM", form
);
22895 static const char *
22896 dwarf_bool_name (unsigned mybool
)
22904 /* Convert a DWARF type code into its string name. */
22906 static const char *
22907 dwarf_type_encoding_name (unsigned enc
)
22909 const char *name
= get_DW_ATE_name (enc
);
22912 return dwarf_unknown ("ATE", enc
);
22918 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
22922 print_spaces (indent
, f
);
22923 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
22924 dwarf_tag_name (die
->tag
), die
->abbrev
,
22925 sect_offset_str (die
->sect_off
));
22927 if (die
->parent
!= NULL
)
22929 print_spaces (indent
, f
);
22930 fprintf_unfiltered (f
, " parent at offset: %s\n",
22931 sect_offset_str (die
->parent
->sect_off
));
22934 print_spaces (indent
, f
);
22935 fprintf_unfiltered (f
, " has children: %s\n",
22936 dwarf_bool_name (die
->child
!= NULL
));
22938 print_spaces (indent
, f
);
22939 fprintf_unfiltered (f
, " attributes:\n");
22941 for (i
= 0; i
< die
->num_attrs
; ++i
)
22943 print_spaces (indent
, f
);
22944 fprintf_unfiltered (f
, " %s (%s) ",
22945 dwarf_attr_name (die
->attrs
[i
].name
),
22946 dwarf_form_name (die
->attrs
[i
].form
));
22948 switch (die
->attrs
[i
].form
)
22951 case DW_FORM_addrx
:
22952 case DW_FORM_GNU_addr_index
:
22953 fprintf_unfiltered (f
, "address: ");
22954 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
22956 case DW_FORM_block2
:
22957 case DW_FORM_block4
:
22958 case DW_FORM_block
:
22959 case DW_FORM_block1
:
22960 fprintf_unfiltered (f
, "block: size %s",
22961 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22963 case DW_FORM_exprloc
:
22964 fprintf_unfiltered (f
, "expression: size %s",
22965 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22967 case DW_FORM_data16
:
22968 fprintf_unfiltered (f
, "constant of 16 bytes");
22970 case DW_FORM_ref_addr
:
22971 fprintf_unfiltered (f
, "ref address: ");
22972 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22974 case DW_FORM_GNU_ref_alt
:
22975 fprintf_unfiltered (f
, "alt ref address: ");
22976 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22982 case DW_FORM_ref_udata
:
22983 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
22984 (long) (DW_UNSND (&die
->attrs
[i
])));
22986 case DW_FORM_data1
:
22987 case DW_FORM_data2
:
22988 case DW_FORM_data4
:
22989 case DW_FORM_data8
:
22990 case DW_FORM_udata
:
22991 case DW_FORM_sdata
:
22992 fprintf_unfiltered (f
, "constant: %s",
22993 pulongest (DW_UNSND (&die
->attrs
[i
])));
22995 case DW_FORM_sec_offset
:
22996 fprintf_unfiltered (f
, "section offset: %s",
22997 pulongest (DW_UNSND (&die
->attrs
[i
])));
22999 case DW_FORM_ref_sig8
:
23000 fprintf_unfiltered (f
, "signature: %s",
23001 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
23003 case DW_FORM_string
:
23005 case DW_FORM_line_strp
:
23007 case DW_FORM_GNU_str_index
:
23008 case DW_FORM_GNU_strp_alt
:
23009 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
23010 DW_STRING (&die
->attrs
[i
])
23011 ? DW_STRING (&die
->attrs
[i
]) : "",
23012 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
23015 if (DW_UNSND (&die
->attrs
[i
]))
23016 fprintf_unfiltered (f
, "flag: TRUE");
23018 fprintf_unfiltered (f
, "flag: FALSE");
23020 case DW_FORM_flag_present
:
23021 fprintf_unfiltered (f
, "flag: TRUE");
23023 case DW_FORM_indirect
:
23024 /* The reader will have reduced the indirect form to
23025 the "base form" so this form should not occur. */
23026 fprintf_unfiltered (f
,
23027 "unexpected attribute form: DW_FORM_indirect");
23029 case DW_FORM_implicit_const
:
23030 fprintf_unfiltered (f
, "constant: %s",
23031 plongest (DW_SND (&die
->attrs
[i
])));
23034 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
23035 die
->attrs
[i
].form
);
23038 fprintf_unfiltered (f
, "\n");
23043 dump_die_for_error (struct die_info
*die
)
23045 dump_die_shallow (gdb_stderr
, 0, die
);
23049 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
23051 int indent
= level
* 4;
23053 gdb_assert (die
!= NULL
);
23055 if (level
>= max_level
)
23058 dump_die_shallow (f
, indent
, die
);
23060 if (die
->child
!= NULL
)
23062 print_spaces (indent
, f
);
23063 fprintf_unfiltered (f
, " Children:");
23064 if (level
+ 1 < max_level
)
23066 fprintf_unfiltered (f
, "\n");
23067 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
23071 fprintf_unfiltered (f
,
23072 " [not printed, max nesting level reached]\n");
23076 if (die
->sibling
!= NULL
&& level
> 0)
23078 dump_die_1 (f
, level
, max_level
, die
->sibling
);
23082 /* This is called from the pdie macro in gdbinit.in.
23083 It's not static so gcc will keep a copy callable from gdb. */
23086 dump_die (struct die_info
*die
, int max_level
)
23088 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
23092 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
23096 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
23097 to_underlying (die
->sect_off
),
23103 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
23107 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
23109 if (attr_form_is_ref (attr
))
23110 return (sect_offset
) DW_UNSND (attr
);
23112 complaint (_("unsupported die ref attribute form: '%s'"),
23113 dwarf_form_name (attr
->form
));
23117 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
23118 * the value held by the attribute is not constant. */
23121 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
23123 if (attr
->form
== DW_FORM_sdata
|| attr
->form
== DW_FORM_implicit_const
)
23124 return DW_SND (attr
);
23125 else if (attr
->form
== DW_FORM_udata
23126 || attr
->form
== DW_FORM_data1
23127 || attr
->form
== DW_FORM_data2
23128 || attr
->form
== DW_FORM_data4
23129 || attr
->form
== DW_FORM_data8
)
23130 return DW_UNSND (attr
);
23133 /* For DW_FORM_data16 see attr_form_is_constant. */
23134 complaint (_("Attribute value is not a constant (%s)"),
23135 dwarf_form_name (attr
->form
));
23136 return default_value
;
23140 /* Follow reference or signature attribute ATTR of SRC_DIE.
23141 On entry *REF_CU is the CU of SRC_DIE.
23142 On exit *REF_CU is the CU of the result. */
23144 static struct die_info
*
23145 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23146 struct dwarf2_cu
**ref_cu
)
23148 struct die_info
*die
;
23150 if (attr_form_is_ref (attr
))
23151 die
= follow_die_ref (src_die
, attr
, ref_cu
);
23152 else if (attr
->form
== DW_FORM_ref_sig8
)
23153 die
= follow_die_sig (src_die
, attr
, ref_cu
);
23156 dump_die_for_error (src_die
);
23157 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
23158 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23164 /* Follow reference OFFSET.
23165 On entry *REF_CU is the CU of the source die referencing OFFSET.
23166 On exit *REF_CU is the CU of the result.
23167 Returns NULL if OFFSET is invalid. */
23169 static struct die_info
*
23170 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
23171 struct dwarf2_cu
**ref_cu
)
23173 struct die_info temp_die
;
23174 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
23175 struct dwarf2_per_objfile
*dwarf2_per_objfile
23176 = cu
->per_cu
->dwarf2_per_objfile
;
23178 gdb_assert (cu
->per_cu
!= NULL
);
23182 if (cu
->per_cu
->is_debug_types
)
23184 /* .debug_types CUs cannot reference anything outside their CU.
23185 If they need to, they have to reference a signatured type via
23186 DW_FORM_ref_sig8. */
23187 if (!offset_in_cu_p (&cu
->header
, sect_off
))
23190 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
23191 || !offset_in_cu_p (&cu
->header
, sect_off
))
23193 struct dwarf2_per_cu_data
*per_cu
;
23195 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23196 dwarf2_per_objfile
);
23198 /* If necessary, add it to the queue and load its DIEs. */
23199 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
23200 load_full_comp_unit (per_cu
, false, cu
->language
);
23202 target_cu
= per_cu
->cu
;
23204 else if (cu
->dies
== NULL
)
23206 /* We're loading full DIEs during partial symbol reading. */
23207 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
23208 load_full_comp_unit (cu
->per_cu
, false, language_minimal
);
23211 *ref_cu
= target_cu
;
23212 temp_die
.sect_off
= sect_off
;
23214 if (target_cu
!= cu
)
23215 target_cu
->ancestor
= cu
;
23217 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
23219 to_underlying (sect_off
));
23222 /* Follow reference attribute ATTR of SRC_DIE.
23223 On entry *REF_CU is the CU of SRC_DIE.
23224 On exit *REF_CU is the CU of the result. */
23226 static struct die_info
*
23227 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
23228 struct dwarf2_cu
**ref_cu
)
23230 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
23231 struct dwarf2_cu
*cu
= *ref_cu
;
23232 struct die_info
*die
;
23234 die
= follow_die_offset (sect_off
,
23235 (attr
->form
== DW_FORM_GNU_ref_alt
23236 || cu
->per_cu
->is_dwz
),
23239 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
23240 "at %s [in module %s]"),
23241 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
23242 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
23247 /* Return DWARF block referenced by DW_AT_location of DIE at SECT_OFF at PER_CU.
23248 Returned value is intended for DW_OP_call*. Returned
23249 dwarf2_locexpr_baton->data has lifetime of
23250 PER_CU->DWARF2_PER_OBJFILE->OBJFILE. */
23252 struct dwarf2_locexpr_baton
23253 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
23254 struct dwarf2_per_cu_data
*per_cu
,
23255 CORE_ADDR (*get_frame_pc
) (void *baton
),
23256 void *baton
, bool resolve_abstract_p
)
23258 struct dwarf2_cu
*cu
;
23259 struct die_info
*die
;
23260 struct attribute
*attr
;
23261 struct dwarf2_locexpr_baton retval
;
23262 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
23263 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23265 if (per_cu
->cu
== NULL
)
23266 load_cu (per_cu
, false);
23270 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23271 Instead just throw an error, not much else we can do. */
23272 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23273 sect_offset_str (sect_off
), objfile_name (objfile
));
23276 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23278 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23279 sect_offset_str (sect_off
), objfile_name (objfile
));
23281 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23282 if (!attr
&& resolve_abstract_p
23283 && (dwarf2_per_objfile
->abstract_to_concrete
.find (die
->sect_off
)
23284 != dwarf2_per_objfile
->abstract_to_concrete
.end ()))
23286 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
23288 = ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
23289 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
23291 for (const auto &cand_off
23292 : dwarf2_per_objfile
->abstract_to_concrete
[die
->sect_off
])
23294 struct dwarf2_cu
*cand_cu
= cu
;
23295 struct die_info
*cand
23296 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
23299 || cand
->parent
->tag
!= DW_TAG_subprogram
)
23302 CORE_ADDR pc_low
, pc_high
;
23303 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
23304 if (pc_low
== ((CORE_ADDR
) -1))
23306 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
23307 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
23308 if (!(pc_low
<= pc
&& pc
< pc_high
))
23312 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23319 /* DWARF: "If there is no such attribute, then there is no effect.".
23320 DATA is ignored if SIZE is 0. */
23322 retval
.data
= NULL
;
23325 else if (attr_form_is_section_offset (attr
))
23327 struct dwarf2_loclist_baton loclist_baton
;
23328 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
23331 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
23333 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
23335 retval
.size
= size
;
23339 if (!attr_form_is_block (attr
))
23340 error (_("Dwarf Error: DIE at %s referenced in module %s "
23341 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
23342 sect_offset_str (sect_off
), objfile_name (objfile
));
23344 retval
.data
= DW_BLOCK (attr
)->data
;
23345 retval
.size
= DW_BLOCK (attr
)->size
;
23347 retval
.per_cu
= cu
->per_cu
;
23349 age_cached_comp_units (dwarf2_per_objfile
);
23354 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
23357 struct dwarf2_locexpr_baton
23358 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
23359 struct dwarf2_per_cu_data
*per_cu
,
23360 CORE_ADDR (*get_frame_pc
) (void *baton
),
23363 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
23365 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
23368 /* Write a constant of a given type as target-ordered bytes into
23371 static const gdb_byte
*
23372 write_constant_as_bytes (struct obstack
*obstack
,
23373 enum bfd_endian byte_order
,
23380 *len
= TYPE_LENGTH (type
);
23381 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23382 store_unsigned_integer (result
, *len
, byte_order
, value
);
23387 /* If the DIE at OFFSET in PER_CU has a DW_AT_const_value, return a
23388 pointer to the constant bytes and set LEN to the length of the
23389 data. If memory is needed, allocate it on OBSTACK. If the DIE
23390 does not have a DW_AT_const_value, return NULL. */
23393 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
23394 struct dwarf2_per_cu_data
*per_cu
,
23395 struct obstack
*obstack
,
23398 struct dwarf2_cu
*cu
;
23399 struct die_info
*die
;
23400 struct attribute
*attr
;
23401 const gdb_byte
*result
= NULL
;
23404 enum bfd_endian byte_order
;
23405 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
23407 if (per_cu
->cu
== NULL
)
23408 load_cu (per_cu
, false);
23412 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23413 Instead just throw an error, not much else we can do. */
23414 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23415 sect_offset_str (sect_off
), objfile_name (objfile
));
23418 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23420 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23421 sect_offset_str (sect_off
), objfile_name (objfile
));
23423 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23427 byte_order
= (bfd_big_endian (objfile
->obfd
)
23428 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
23430 switch (attr
->form
)
23433 case DW_FORM_addrx
:
23434 case DW_FORM_GNU_addr_index
:
23438 *len
= cu
->header
.addr_size
;
23439 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23440 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
23444 case DW_FORM_string
:
23447 case DW_FORM_GNU_str_index
:
23448 case DW_FORM_GNU_strp_alt
:
23449 /* DW_STRING is already allocated on the objfile obstack, point
23451 result
= (const gdb_byte
*) DW_STRING (attr
);
23452 *len
= strlen (DW_STRING (attr
));
23454 case DW_FORM_block1
:
23455 case DW_FORM_block2
:
23456 case DW_FORM_block4
:
23457 case DW_FORM_block
:
23458 case DW_FORM_exprloc
:
23459 case DW_FORM_data16
:
23460 result
= DW_BLOCK (attr
)->data
;
23461 *len
= DW_BLOCK (attr
)->size
;
23464 /* The DW_AT_const_value attributes are supposed to carry the
23465 symbol's value "represented as it would be on the target
23466 architecture." By the time we get here, it's already been
23467 converted to host endianness, so we just need to sign- or
23468 zero-extend it as appropriate. */
23469 case DW_FORM_data1
:
23470 type
= die_type (die
, cu
);
23471 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
23472 if (result
== NULL
)
23473 result
= write_constant_as_bytes (obstack
, byte_order
,
23476 case DW_FORM_data2
:
23477 type
= die_type (die
, cu
);
23478 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
23479 if (result
== NULL
)
23480 result
= write_constant_as_bytes (obstack
, byte_order
,
23483 case DW_FORM_data4
:
23484 type
= die_type (die
, cu
);
23485 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
23486 if (result
== NULL
)
23487 result
= write_constant_as_bytes (obstack
, byte_order
,
23490 case DW_FORM_data8
:
23491 type
= die_type (die
, cu
);
23492 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
23493 if (result
== NULL
)
23494 result
= write_constant_as_bytes (obstack
, byte_order
,
23498 case DW_FORM_sdata
:
23499 case DW_FORM_implicit_const
:
23500 type
= die_type (die
, cu
);
23501 result
= write_constant_as_bytes (obstack
, byte_order
,
23502 type
, DW_SND (attr
), len
);
23505 case DW_FORM_udata
:
23506 type
= die_type (die
, cu
);
23507 result
= write_constant_as_bytes (obstack
, byte_order
,
23508 type
, DW_UNSND (attr
), len
);
23512 complaint (_("unsupported const value attribute form: '%s'"),
23513 dwarf_form_name (attr
->form
));
23520 /* Return the type of the die at OFFSET in PER_CU. Return NULL if no
23521 valid type for this die is found. */
23524 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
23525 struct dwarf2_per_cu_data
*per_cu
)
23527 struct dwarf2_cu
*cu
;
23528 struct die_info
*die
;
23530 if (per_cu
->cu
== NULL
)
23531 load_cu (per_cu
, false);
23536 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23540 return die_type (die
, cu
);
23543 /* Return the type of the DIE at DIE_OFFSET in the CU named by
23547 dwarf2_get_die_type (cu_offset die_offset
,
23548 struct dwarf2_per_cu_data
*per_cu
)
23550 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
23551 return get_die_type_at_offset (die_offset_sect
, per_cu
);
23554 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
23555 On entry *REF_CU is the CU of SRC_DIE.
23556 On exit *REF_CU is the CU of the result.
23557 Returns NULL if the referenced DIE isn't found. */
23559 static struct die_info
*
23560 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
23561 struct dwarf2_cu
**ref_cu
)
23563 struct die_info temp_die
;
23564 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
23565 struct die_info
*die
;
23567 /* While it might be nice to assert sig_type->type == NULL here,
23568 we can get here for DW_AT_imported_declaration where we need
23569 the DIE not the type. */
23571 /* If necessary, add it to the queue and load its DIEs. */
23573 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
23574 read_signatured_type (sig_type
);
23576 sig_cu
= sig_type
->per_cu
.cu
;
23577 gdb_assert (sig_cu
!= NULL
);
23578 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
23579 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
23580 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
23581 to_underlying (temp_die
.sect_off
));
23584 struct dwarf2_per_objfile
*dwarf2_per_objfile
23585 = (*ref_cu
)->per_cu
->dwarf2_per_objfile
;
23587 /* For .gdb_index version 7 keep track of included TUs.
23588 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
23589 if (dwarf2_per_objfile
->index_table
!= NULL
23590 && dwarf2_per_objfile
->index_table
->version
<= 7)
23592 VEC_safe_push (dwarf2_per_cu_ptr
,
23593 (*ref_cu
)->per_cu
->imported_symtabs
,
23599 sig_cu
->ancestor
= cu
;
23607 /* Follow signatured type referenced by ATTR in SRC_DIE.
23608 On entry *REF_CU is the CU of SRC_DIE.
23609 On exit *REF_CU is the CU of the result.
23610 The result is the DIE of the type.
23611 If the referenced type cannot be found an error is thrown. */
23613 static struct die_info
*
23614 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23615 struct dwarf2_cu
**ref_cu
)
23617 ULONGEST signature
= DW_SIGNATURE (attr
);
23618 struct signatured_type
*sig_type
;
23619 struct die_info
*die
;
23621 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
23623 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
23624 /* sig_type will be NULL if the signatured type is missing from
23626 if (sig_type
== NULL
)
23628 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23629 " from DIE at %s [in module %s]"),
23630 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23631 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23634 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
23637 dump_die_for_error (src_die
);
23638 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23639 " from DIE at %s [in module %s]"),
23640 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23641 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23647 /* Get the type specified by SIGNATURE referenced in DIE/CU,
23648 reading in and processing the type unit if necessary. */
23650 static struct type
*
23651 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
23652 struct dwarf2_cu
*cu
)
23654 struct dwarf2_per_objfile
*dwarf2_per_objfile
23655 = cu
->per_cu
->dwarf2_per_objfile
;
23656 struct signatured_type
*sig_type
;
23657 struct dwarf2_cu
*type_cu
;
23658 struct die_info
*type_die
;
23661 sig_type
= lookup_signatured_type (cu
, signature
);
23662 /* sig_type will be NULL if the signatured type is missing from
23664 if (sig_type
== NULL
)
23666 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23667 " from DIE at %s [in module %s]"),
23668 hex_string (signature
), sect_offset_str (die
->sect_off
),
23669 objfile_name (dwarf2_per_objfile
->objfile
));
23670 return build_error_marker_type (cu
, die
);
23673 /* If we already know the type we're done. */
23674 if (sig_type
->type
!= NULL
)
23675 return sig_type
->type
;
23678 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
23679 if (type_die
!= NULL
)
23681 /* N.B. We need to call get_die_type to ensure only one type for this DIE
23682 is created. This is important, for example, because for c++ classes
23683 we need TYPE_NAME set which is only done by new_symbol. Blech. */
23684 type
= read_type_die (type_die
, type_cu
);
23687 complaint (_("Dwarf Error: Cannot build signatured type %s"
23688 " referenced from DIE at %s [in module %s]"),
23689 hex_string (signature
), sect_offset_str (die
->sect_off
),
23690 objfile_name (dwarf2_per_objfile
->objfile
));
23691 type
= build_error_marker_type (cu
, die
);
23696 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23697 " from DIE at %s [in module %s]"),
23698 hex_string (signature
), sect_offset_str (die
->sect_off
),
23699 objfile_name (dwarf2_per_objfile
->objfile
));
23700 type
= build_error_marker_type (cu
, die
);
23702 sig_type
->type
= type
;
23707 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
23708 reading in and processing the type unit if necessary. */
23710 static struct type
*
23711 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
23712 struct dwarf2_cu
*cu
) /* ARI: editCase function */
23714 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
23715 if (attr_form_is_ref (attr
))
23717 struct dwarf2_cu
*type_cu
= cu
;
23718 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
23720 return read_type_die (type_die
, type_cu
);
23722 else if (attr
->form
== DW_FORM_ref_sig8
)
23724 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
23728 struct dwarf2_per_objfile
*dwarf2_per_objfile
23729 = cu
->per_cu
->dwarf2_per_objfile
;
23731 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
23732 " at %s [in module %s]"),
23733 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
23734 objfile_name (dwarf2_per_objfile
->objfile
));
23735 return build_error_marker_type (cu
, die
);
23739 /* Load the DIEs associated with type unit PER_CU into memory. */
23742 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
23744 struct signatured_type
*sig_type
;
23746 /* Caller is responsible for ensuring type_unit_groups don't get here. */
23747 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
23749 /* We have the per_cu, but we need the signatured_type.
23750 Fortunately this is an easy translation. */
23751 gdb_assert (per_cu
->is_debug_types
);
23752 sig_type
= (struct signatured_type
*) per_cu
;
23754 gdb_assert (per_cu
->cu
== NULL
);
23756 read_signatured_type (sig_type
);
23758 gdb_assert (per_cu
->cu
!= NULL
);
23761 /* die_reader_func for read_signatured_type.
23762 This is identical to load_full_comp_unit_reader,
23763 but is kept separate for now. */
23766 read_signatured_type_reader (const struct die_reader_specs
*reader
,
23767 const gdb_byte
*info_ptr
,
23768 struct die_info
*comp_unit_die
,
23772 struct dwarf2_cu
*cu
= reader
->cu
;
23774 gdb_assert (cu
->die_hash
== NULL
);
23776 htab_create_alloc_ex (cu
->header
.length
/ 12,
23780 &cu
->comp_unit_obstack
,
23781 hashtab_obstack_allocate
,
23782 dummy_obstack_deallocate
);
23785 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
23786 &info_ptr
, comp_unit_die
);
23787 cu
->dies
= comp_unit_die
;
23788 /* comp_unit_die is not stored in die_hash, no need. */
23790 /* We try not to read any attributes in this function, because not
23791 all CUs needed for references have been loaded yet, and symbol
23792 table processing isn't initialized. But we have to set the CU language,
23793 or we won't be able to build types correctly.
23794 Similarly, if we do not read the producer, we can not apply
23795 producer-specific interpretation. */
23796 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
23799 /* Read in a signatured type and build its CU and DIEs.
23800 If the type is a stub for the real type in a DWO file,
23801 read in the real type from the DWO file as well. */
23804 read_signatured_type (struct signatured_type
*sig_type
)
23806 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
23808 gdb_assert (per_cu
->is_debug_types
);
23809 gdb_assert (per_cu
->cu
== NULL
);
23811 init_cutu_and_read_dies (per_cu
, NULL
, 0, 1, false,
23812 read_signatured_type_reader
, NULL
);
23813 sig_type
->per_cu
.tu_read
= 1;
23816 /* Decode simple location descriptions.
23817 Given a pointer to a dwarf block that defines a location, compute
23818 the location and return the value.
23820 NOTE drow/2003-11-18: This function is called in two situations
23821 now: for the address of static or global variables (partial symbols
23822 only) and for offsets into structures which are expected to be
23823 (more or less) constant. The partial symbol case should go away,
23824 and only the constant case should remain. That will let this
23825 function complain more accurately. A few special modes are allowed
23826 without complaint for global variables (for instance, global
23827 register values and thread-local values).
23829 A location description containing no operations indicates that the
23830 object is optimized out. The return value is 0 for that case.
23831 FIXME drow/2003-11-16: No callers check for this case any more; soon all
23832 callers will only want a very basic result and this can become a
23835 Note that stack[0] is unused except as a default error return. */
23838 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
23840 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
23842 size_t size
= blk
->size
;
23843 const gdb_byte
*data
= blk
->data
;
23844 CORE_ADDR stack
[64];
23846 unsigned int bytes_read
, unsnd
;
23852 stack
[++stacki
] = 0;
23891 stack
[++stacki
] = op
- DW_OP_lit0
;
23926 stack
[++stacki
] = op
- DW_OP_reg0
;
23928 dwarf2_complex_location_expr_complaint ();
23932 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
23934 stack
[++stacki
] = unsnd
;
23936 dwarf2_complex_location_expr_complaint ();
23940 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
23945 case DW_OP_const1u
:
23946 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
23950 case DW_OP_const1s
:
23951 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
23955 case DW_OP_const2u
:
23956 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
23960 case DW_OP_const2s
:
23961 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
23965 case DW_OP_const4u
:
23966 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
23970 case DW_OP_const4s
:
23971 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
23975 case DW_OP_const8u
:
23976 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
23981 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
23987 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
23992 stack
[stacki
+ 1] = stack
[stacki
];
23997 stack
[stacki
- 1] += stack
[stacki
];
24001 case DW_OP_plus_uconst
:
24002 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
24008 stack
[stacki
- 1] -= stack
[stacki
];
24013 /* If we're not the last op, then we definitely can't encode
24014 this using GDB's address_class enum. This is valid for partial
24015 global symbols, although the variable's address will be bogus
24018 dwarf2_complex_location_expr_complaint ();
24021 case DW_OP_GNU_push_tls_address
:
24022 case DW_OP_form_tls_address
:
24023 /* The top of the stack has the offset from the beginning
24024 of the thread control block at which the variable is located. */
24025 /* Nothing should follow this operator, so the top of stack would
24027 /* This is valid for partial global symbols, but the variable's
24028 address will be bogus in the psymtab. Make it always at least
24029 non-zero to not look as a variable garbage collected by linker
24030 which have DW_OP_addr 0. */
24032 dwarf2_complex_location_expr_complaint ();
24036 case DW_OP_GNU_uninit
:
24040 case DW_OP_GNU_addr_index
:
24041 case DW_OP_GNU_const_index
:
24042 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
24049 const char *name
= get_DW_OP_name (op
);
24052 complaint (_("unsupported stack op: '%s'"),
24055 complaint (_("unsupported stack op: '%02x'"),
24059 return (stack
[stacki
]);
24062 /* Enforce maximum stack depth of SIZE-1 to avoid writing
24063 outside of the allocated space. Also enforce minimum>0. */
24064 if (stacki
>= ARRAY_SIZE (stack
) - 1)
24066 complaint (_("location description stack overflow"));
24072 complaint (_("location description stack underflow"));
24076 return (stack
[stacki
]);
24079 /* memory allocation interface */
24081 static struct dwarf_block
*
24082 dwarf_alloc_block (struct dwarf2_cu
*cu
)
24084 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
24087 static struct die_info
*
24088 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
24090 struct die_info
*die
;
24091 size_t size
= sizeof (struct die_info
);
24094 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
24096 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
24097 memset (die
, 0, sizeof (struct die_info
));
24102 /* Macro support. */
24104 /* Return file name relative to the compilation directory of file number I in
24105 *LH's file name table. The result is allocated using xmalloc; the caller is
24106 responsible for freeing it. */
24109 file_file_name (int file
, struct line_header
*lh
)
24111 /* Is the file number a valid index into the line header's file name
24112 table? Remember that file numbers start with one, not zero. */
24113 if (1 <= file
&& file
<= lh
->file_names
.size ())
24115 const file_entry
&fe
= lh
->file_names
[file
- 1];
24117 if (!IS_ABSOLUTE_PATH (fe
.name
))
24119 const char *dir
= fe
.include_dir (lh
);
24121 return concat (dir
, SLASH_STRING
, fe
.name
, (char *) NULL
);
24123 return xstrdup (fe
.name
);
24127 /* The compiler produced a bogus file number. We can at least
24128 record the macro definitions made in the file, even if we
24129 won't be able to find the file by name. */
24130 char fake_name
[80];
24132 xsnprintf (fake_name
, sizeof (fake_name
),
24133 "<bad macro file number %d>", file
);
24135 complaint (_("bad file number in macro information (%d)"),
24138 return xstrdup (fake_name
);
24142 /* Return the full name of file number I in *LH's file name table.
24143 Use COMP_DIR as the name of the current directory of the
24144 compilation. The result is allocated using xmalloc; the caller is
24145 responsible for freeing it. */
24147 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
24149 /* Is the file number a valid index into the line header's file name
24150 table? Remember that file numbers start with one, not zero. */
24151 if (1 <= file
&& file
<= lh
->file_names
.size ())
24153 char *relative
= file_file_name (file
, lh
);
24155 if (IS_ABSOLUTE_PATH (relative
) || comp_dir
== NULL
)
24157 return reconcat (relative
, comp_dir
, SLASH_STRING
,
24158 relative
, (char *) NULL
);
24161 return file_file_name (file
, lh
);
24165 static struct macro_source_file
*
24166 macro_start_file (struct dwarf2_cu
*cu
,
24167 int file
, int line
,
24168 struct macro_source_file
*current_file
,
24169 struct line_header
*lh
)
24171 /* File name relative to the compilation directory of this source file. */
24172 char *file_name
= file_file_name (file
, lh
);
24174 if (! current_file
)
24176 /* Note: We don't create a macro table for this compilation unit
24177 at all until we actually get a filename. */
24178 struct macro_table
*macro_table
= cu
->get_builder ()->get_macro_table ();
24180 /* If we have no current file, then this must be the start_file
24181 directive for the compilation unit's main source file. */
24182 current_file
= macro_set_main (macro_table
, file_name
);
24183 macro_define_special (macro_table
);
24186 current_file
= macro_include (current_file
, line
, file_name
);
24190 return current_file
;
24193 static const char *
24194 consume_improper_spaces (const char *p
, const char *body
)
24198 complaint (_("macro definition contains spaces "
24199 "in formal argument list:\n`%s'"),
24211 parse_macro_definition (struct macro_source_file
*file
, int line
,
24216 /* The body string takes one of two forms. For object-like macro
24217 definitions, it should be:
24219 <macro name> " " <definition>
24221 For function-like macro definitions, it should be:
24223 <macro name> "() " <definition>
24225 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
24227 Spaces may appear only where explicitly indicated, and in the
24230 The Dwarf 2 spec says that an object-like macro's name is always
24231 followed by a space, but versions of GCC around March 2002 omit
24232 the space when the macro's definition is the empty string.
24234 The Dwarf 2 spec says that there should be no spaces between the
24235 formal arguments in a function-like macro's formal argument list,
24236 but versions of GCC around March 2002 include spaces after the
24240 /* Find the extent of the macro name. The macro name is terminated
24241 by either a space or null character (for an object-like macro) or
24242 an opening paren (for a function-like macro). */
24243 for (p
= body
; *p
; p
++)
24244 if (*p
== ' ' || *p
== '(')
24247 if (*p
== ' ' || *p
== '\0')
24249 /* It's an object-like macro. */
24250 int name_len
= p
- body
;
24251 char *name
= savestring (body
, name_len
);
24252 const char *replacement
;
24255 replacement
= body
+ name_len
+ 1;
24258 dwarf2_macro_malformed_definition_complaint (body
);
24259 replacement
= body
+ name_len
;
24262 macro_define_object (file
, line
, name
, replacement
);
24266 else if (*p
== '(')
24268 /* It's a function-like macro. */
24269 char *name
= savestring (body
, p
- body
);
24272 char **argv
= XNEWVEC (char *, argv_size
);
24276 p
= consume_improper_spaces (p
, body
);
24278 /* Parse the formal argument list. */
24279 while (*p
&& *p
!= ')')
24281 /* Find the extent of the current argument name. */
24282 const char *arg_start
= p
;
24284 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
24287 if (! *p
|| p
== arg_start
)
24288 dwarf2_macro_malformed_definition_complaint (body
);
24291 /* Make sure argv has room for the new argument. */
24292 if (argc
>= argv_size
)
24295 argv
= XRESIZEVEC (char *, argv
, argv_size
);
24298 argv
[argc
++] = savestring (arg_start
, p
- arg_start
);
24301 p
= consume_improper_spaces (p
, body
);
24303 /* Consume the comma, if present. */
24308 p
= consume_improper_spaces (p
, body
);
24317 /* Perfectly formed definition, no complaints. */
24318 macro_define_function (file
, line
, name
,
24319 argc
, (const char **) argv
,
24321 else if (*p
== '\0')
24323 /* Complain, but do define it. */
24324 dwarf2_macro_malformed_definition_complaint (body
);
24325 macro_define_function (file
, line
, name
,
24326 argc
, (const char **) argv
,
24330 /* Just complain. */
24331 dwarf2_macro_malformed_definition_complaint (body
);
24334 /* Just complain. */
24335 dwarf2_macro_malformed_definition_complaint (body
);
24341 for (i
= 0; i
< argc
; i
++)
24347 dwarf2_macro_malformed_definition_complaint (body
);
24350 /* Skip some bytes from BYTES according to the form given in FORM.
24351 Returns the new pointer. */
24353 static const gdb_byte
*
24354 skip_form_bytes (bfd
*abfd
, const gdb_byte
*bytes
, const gdb_byte
*buffer_end
,
24355 enum dwarf_form form
,
24356 unsigned int offset_size
,
24357 struct dwarf2_section_info
*section
)
24359 unsigned int bytes_read
;
24363 case DW_FORM_data1
:
24368 case DW_FORM_data2
:
24372 case DW_FORM_data4
:
24376 case DW_FORM_data8
:
24380 case DW_FORM_data16
:
24384 case DW_FORM_string
:
24385 read_direct_string (abfd
, bytes
, &bytes_read
);
24386 bytes
+= bytes_read
;
24389 case DW_FORM_sec_offset
:
24391 case DW_FORM_GNU_strp_alt
:
24392 bytes
+= offset_size
;
24395 case DW_FORM_block
:
24396 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
24397 bytes
+= bytes_read
;
24400 case DW_FORM_block1
:
24401 bytes
+= 1 + read_1_byte (abfd
, bytes
);
24403 case DW_FORM_block2
:
24404 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
24406 case DW_FORM_block4
:
24407 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
24410 case DW_FORM_addrx
:
24411 case DW_FORM_sdata
:
24413 case DW_FORM_udata
:
24414 case DW_FORM_GNU_addr_index
:
24415 case DW_FORM_GNU_str_index
:
24416 bytes
= gdb_skip_leb128 (bytes
, buffer_end
);
24419 dwarf2_section_buffer_overflow_complaint (section
);
24424 case DW_FORM_implicit_const
:
24429 complaint (_("invalid form 0x%x in `%s'"),
24430 form
, get_section_name (section
));
24438 /* A helper for dwarf_decode_macros that handles skipping an unknown
24439 opcode. Returns an updated pointer to the macro data buffer; or,
24440 on error, issues a complaint and returns NULL. */
24442 static const gdb_byte
*
24443 skip_unknown_opcode (unsigned int opcode
,
24444 const gdb_byte
**opcode_definitions
,
24445 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24447 unsigned int offset_size
,
24448 struct dwarf2_section_info
*section
)
24450 unsigned int bytes_read
, i
;
24452 const gdb_byte
*defn
;
24454 if (opcode_definitions
[opcode
] == NULL
)
24456 complaint (_("unrecognized DW_MACFINO opcode 0x%x"),
24461 defn
= opcode_definitions
[opcode
];
24462 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
24463 defn
+= bytes_read
;
24465 for (i
= 0; i
< arg
; ++i
)
24467 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
,
24468 (enum dwarf_form
) defn
[i
], offset_size
,
24470 if (mac_ptr
== NULL
)
24472 /* skip_form_bytes already issued the complaint. */
24480 /* A helper function which parses the header of a macro section.
24481 If the macro section is the extended (for now called "GNU") type,
24482 then this updates *OFFSET_SIZE. Returns a pointer to just after
24483 the header, or issues a complaint and returns NULL on error. */
24485 static const gdb_byte
*
24486 dwarf_parse_macro_header (const gdb_byte
**opcode_definitions
,
24488 const gdb_byte
*mac_ptr
,
24489 unsigned int *offset_size
,
24490 int section_is_gnu
)
24492 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
24494 if (section_is_gnu
)
24496 unsigned int version
, flags
;
24498 version
= read_2_bytes (abfd
, mac_ptr
);
24499 if (version
!= 4 && version
!= 5)
24501 complaint (_("unrecognized version `%d' in .debug_macro section"),
24507 flags
= read_1_byte (abfd
, mac_ptr
);
24509 *offset_size
= (flags
& 1) ? 8 : 4;
24511 if ((flags
& 2) != 0)
24512 /* We don't need the line table offset. */
24513 mac_ptr
+= *offset_size
;
24515 /* Vendor opcode descriptions. */
24516 if ((flags
& 4) != 0)
24518 unsigned int i
, count
;
24520 count
= read_1_byte (abfd
, mac_ptr
);
24522 for (i
= 0; i
< count
; ++i
)
24524 unsigned int opcode
, bytes_read
;
24527 opcode
= read_1_byte (abfd
, mac_ptr
);
24529 opcode_definitions
[opcode
] = mac_ptr
;
24530 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24531 mac_ptr
+= bytes_read
;
24540 /* A helper for dwarf_decode_macros that handles the GNU extensions,
24541 including DW_MACRO_import. */
24544 dwarf_decode_macro_bytes (struct dwarf2_cu
*cu
,
24546 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24547 struct macro_source_file
*current_file
,
24548 struct line_header
*lh
,
24549 struct dwarf2_section_info
*section
,
24550 int section_is_gnu
, int section_is_dwz
,
24551 unsigned int offset_size
,
24552 htab_t include_hash
)
24554 struct dwarf2_per_objfile
*dwarf2_per_objfile
24555 = cu
->per_cu
->dwarf2_per_objfile
;
24556 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24557 enum dwarf_macro_record_type macinfo_type
;
24558 int at_commandline
;
24559 const gdb_byte
*opcode_definitions
[256];
24561 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
24562 &offset_size
, section_is_gnu
);
24563 if (mac_ptr
== NULL
)
24565 /* We already issued a complaint. */
24569 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
24570 GDB is still reading the definitions from command line. First
24571 DW_MACINFO_start_file will need to be ignored as it was already executed
24572 to create CURRENT_FILE for the main source holding also the command line
24573 definitions. On first met DW_MACINFO_start_file this flag is reset to
24574 normally execute all the remaining DW_MACINFO_start_file macinfos. */
24576 at_commandline
= 1;
24580 /* Do we at least have room for a macinfo type byte? */
24581 if (mac_ptr
>= mac_end
)
24583 dwarf2_section_buffer_overflow_complaint (section
);
24587 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
24590 /* Note that we rely on the fact that the corresponding GNU and
24591 DWARF constants are the same. */
24593 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
24594 switch (macinfo_type
)
24596 /* A zero macinfo type indicates the end of the macro
24601 case DW_MACRO_define
:
24602 case DW_MACRO_undef
:
24603 case DW_MACRO_define_strp
:
24604 case DW_MACRO_undef_strp
:
24605 case DW_MACRO_define_sup
:
24606 case DW_MACRO_undef_sup
:
24608 unsigned int bytes_read
;
24613 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24614 mac_ptr
+= bytes_read
;
24616 if (macinfo_type
== DW_MACRO_define
24617 || macinfo_type
== DW_MACRO_undef
)
24619 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24620 mac_ptr
+= bytes_read
;
24624 LONGEST str_offset
;
24626 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
24627 mac_ptr
+= offset_size
;
24629 if (macinfo_type
== DW_MACRO_define_sup
24630 || macinfo_type
== DW_MACRO_undef_sup
24633 struct dwz_file
*dwz
24634 = dwarf2_get_dwz_file (dwarf2_per_objfile
);
24636 body
= read_indirect_string_from_dwz (objfile
,
24640 body
= read_indirect_string_at_offset (dwarf2_per_objfile
,
24644 is_define
= (macinfo_type
== DW_MACRO_define
24645 || macinfo_type
== DW_MACRO_define_strp
24646 || macinfo_type
== DW_MACRO_define_sup
);
24647 if (! current_file
)
24649 /* DWARF violation as no main source is present. */
24650 complaint (_("debug info with no main source gives macro %s "
24652 is_define
? _("definition") : _("undefinition"),
24656 if ((line
== 0 && !at_commandline
)
24657 || (line
!= 0 && at_commandline
))
24658 complaint (_("debug info gives %s macro %s with %s line %d: %s"),
24659 at_commandline
? _("command-line") : _("in-file"),
24660 is_define
? _("definition") : _("undefinition"),
24661 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
24665 /* Fedora's rpm-build's "debugedit" binary
24666 corrupted .debug_macro sections.
24669 https://bugzilla.redhat.com/show_bug.cgi?id=1708786 */
24670 complaint (_("debug info gives %s invalid macro %s "
24671 "without body (corrupted?) at line %d "
24673 at_commandline
? _("command-line") : _("in-file"),
24674 is_define
? _("definition") : _("undefinition"),
24675 line
, current_file
->filename
);
24677 else if (is_define
)
24678 parse_macro_definition (current_file
, line
, body
);
24681 gdb_assert (macinfo_type
== DW_MACRO_undef
24682 || macinfo_type
== DW_MACRO_undef_strp
24683 || macinfo_type
== DW_MACRO_undef_sup
);
24684 macro_undef (current_file
, line
, body
);
24689 case DW_MACRO_start_file
:
24691 unsigned int bytes_read
;
24694 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24695 mac_ptr
+= bytes_read
;
24696 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24697 mac_ptr
+= bytes_read
;
24699 if ((line
== 0 && !at_commandline
)
24700 || (line
!= 0 && at_commandline
))
24701 complaint (_("debug info gives source %d included "
24702 "from %s at %s line %d"),
24703 file
, at_commandline
? _("command-line") : _("file"),
24704 line
== 0 ? _("zero") : _("non-zero"), line
);
24706 if (at_commandline
)
24708 /* This DW_MACRO_start_file was executed in the
24710 at_commandline
= 0;
24713 current_file
= macro_start_file (cu
, file
, line
, current_file
,
24718 case DW_MACRO_end_file
:
24719 if (! current_file
)
24720 complaint (_("macro debug info has an unmatched "
24721 "`close_file' directive"));
24724 current_file
= current_file
->included_by
;
24725 if (! current_file
)
24727 enum dwarf_macro_record_type next_type
;
24729 /* GCC circa March 2002 doesn't produce the zero
24730 type byte marking the end of the compilation
24731 unit. Complain if it's not there, but exit no
24734 /* Do we at least have room for a macinfo type byte? */
24735 if (mac_ptr
>= mac_end
)
24737 dwarf2_section_buffer_overflow_complaint (section
);
24741 /* We don't increment mac_ptr here, so this is just
24744 = (enum dwarf_macro_record_type
) read_1_byte (abfd
,
24746 if (next_type
!= 0)
24747 complaint (_("no terminating 0-type entry for "
24748 "macros in `.debug_macinfo' section"));
24755 case DW_MACRO_import
:
24756 case DW_MACRO_import_sup
:
24760 bfd
*include_bfd
= abfd
;
24761 struct dwarf2_section_info
*include_section
= section
;
24762 const gdb_byte
*include_mac_end
= mac_end
;
24763 int is_dwz
= section_is_dwz
;
24764 const gdb_byte
*new_mac_ptr
;
24766 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
24767 mac_ptr
+= offset_size
;
24769 if (macinfo_type
== DW_MACRO_import_sup
)
24771 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
24773 dwarf2_read_section (objfile
, &dwz
->macro
);
24775 include_section
= &dwz
->macro
;
24776 include_bfd
= get_section_bfd_owner (include_section
);
24777 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
24781 new_mac_ptr
= include_section
->buffer
+ offset
;
24782 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
24786 /* This has actually happened; see
24787 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
24788 complaint (_("recursive DW_MACRO_import in "
24789 ".debug_macro section"));
24793 *slot
= (void *) new_mac_ptr
;
24795 dwarf_decode_macro_bytes (cu
, include_bfd
, new_mac_ptr
,
24796 include_mac_end
, current_file
, lh
,
24797 section
, section_is_gnu
, is_dwz
,
24798 offset_size
, include_hash
);
24800 htab_remove_elt (include_hash
, (void *) new_mac_ptr
);
24805 case DW_MACINFO_vendor_ext
:
24806 if (!section_is_gnu
)
24808 unsigned int bytes_read
;
24810 /* This reads the constant, but since we don't recognize
24811 any vendor extensions, we ignore it. */
24812 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24813 mac_ptr
+= bytes_read
;
24814 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24815 mac_ptr
+= bytes_read
;
24817 /* We don't recognize any vendor extensions. */
24823 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
24824 mac_ptr
, mac_end
, abfd
, offset_size
,
24826 if (mac_ptr
== NULL
)
24831 } while (macinfo_type
!= 0);
24835 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
24836 int section_is_gnu
)
24838 struct dwarf2_per_objfile
*dwarf2_per_objfile
24839 = cu
->per_cu
->dwarf2_per_objfile
;
24840 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24841 struct line_header
*lh
= cu
->line_header
;
24843 const gdb_byte
*mac_ptr
, *mac_end
;
24844 struct macro_source_file
*current_file
= 0;
24845 enum dwarf_macro_record_type macinfo_type
;
24846 unsigned int offset_size
= cu
->header
.offset_size
;
24847 const gdb_byte
*opcode_definitions
[256];
24849 struct dwarf2_section_info
*section
;
24850 const char *section_name
;
24852 if (cu
->dwo_unit
!= NULL
)
24854 if (section_is_gnu
)
24856 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
24857 section_name
= ".debug_macro.dwo";
24861 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
24862 section_name
= ".debug_macinfo.dwo";
24867 if (section_is_gnu
)
24869 section
= &dwarf2_per_objfile
->macro
;
24870 section_name
= ".debug_macro";
24874 section
= &dwarf2_per_objfile
->macinfo
;
24875 section_name
= ".debug_macinfo";
24879 dwarf2_read_section (objfile
, section
);
24880 if (section
->buffer
== NULL
)
24882 complaint (_("missing %s section"), section_name
);
24885 abfd
= get_section_bfd_owner (section
);
24887 /* First pass: Find the name of the base filename.
24888 This filename is needed in order to process all macros whose definition
24889 (or undefinition) comes from the command line. These macros are defined
24890 before the first DW_MACINFO_start_file entry, and yet still need to be
24891 associated to the base file.
24893 To determine the base file name, we scan the macro definitions until we
24894 reach the first DW_MACINFO_start_file entry. We then initialize
24895 CURRENT_FILE accordingly so that any macro definition found before the
24896 first DW_MACINFO_start_file can still be associated to the base file. */
24898 mac_ptr
= section
->buffer
+ offset
;
24899 mac_end
= section
->buffer
+ section
->size
;
24901 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
24902 &offset_size
, section_is_gnu
);
24903 if (mac_ptr
== NULL
)
24905 /* We already issued a complaint. */
24911 /* Do we at least have room for a macinfo type byte? */
24912 if (mac_ptr
>= mac_end
)
24914 /* Complaint is printed during the second pass as GDB will probably
24915 stop the first pass earlier upon finding
24916 DW_MACINFO_start_file. */
24920 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
24923 /* Note that we rely on the fact that the corresponding GNU and
24924 DWARF constants are the same. */
24926 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
24927 switch (macinfo_type
)
24929 /* A zero macinfo type indicates the end of the macro
24934 case DW_MACRO_define
:
24935 case DW_MACRO_undef
:
24936 /* Only skip the data by MAC_PTR. */
24938 unsigned int bytes_read
;
24940 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24941 mac_ptr
+= bytes_read
;
24942 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24943 mac_ptr
+= bytes_read
;
24947 case DW_MACRO_start_file
:
24949 unsigned int bytes_read
;
24952 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24953 mac_ptr
+= bytes_read
;
24954 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24955 mac_ptr
+= bytes_read
;
24957 current_file
= macro_start_file (cu
, file
, line
, current_file
, lh
);
24961 case DW_MACRO_end_file
:
24962 /* No data to skip by MAC_PTR. */
24965 case DW_MACRO_define_strp
:
24966 case DW_MACRO_undef_strp
:
24967 case DW_MACRO_define_sup
:
24968 case DW_MACRO_undef_sup
:
24970 unsigned int bytes_read
;
24972 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24973 mac_ptr
+= bytes_read
;
24974 mac_ptr
+= offset_size
;
24978 case DW_MACRO_import
:
24979 case DW_MACRO_import_sup
:
24980 /* Note that, according to the spec, a transparent include
24981 chain cannot call DW_MACRO_start_file. So, we can just
24982 skip this opcode. */
24983 mac_ptr
+= offset_size
;
24986 case DW_MACINFO_vendor_ext
:
24987 /* Only skip the data by MAC_PTR. */
24988 if (!section_is_gnu
)
24990 unsigned int bytes_read
;
24992 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24993 mac_ptr
+= bytes_read
;
24994 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24995 mac_ptr
+= bytes_read
;
25000 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
25001 mac_ptr
, mac_end
, abfd
, offset_size
,
25003 if (mac_ptr
== NULL
)
25008 } while (macinfo_type
!= 0 && current_file
== NULL
);
25010 /* Second pass: Process all entries.
25012 Use the AT_COMMAND_LINE flag to determine whether we are still processing
25013 command-line macro definitions/undefinitions. This flag is unset when we
25014 reach the first DW_MACINFO_start_file entry. */
25016 htab_up
include_hash (htab_create_alloc (1, htab_hash_pointer
,
25018 NULL
, xcalloc
, xfree
));
25019 mac_ptr
= section
->buffer
+ offset
;
25020 slot
= htab_find_slot (include_hash
.get (), mac_ptr
, INSERT
);
25021 *slot
= (void *) mac_ptr
;
25022 dwarf_decode_macro_bytes (cu
, abfd
, mac_ptr
, mac_end
,
25023 current_file
, lh
, section
,
25024 section_is_gnu
, 0, offset_size
,
25025 include_hash
.get ());
25028 /* Check if the attribute's form is a DW_FORM_block*
25029 if so return true else false. */
25032 attr_form_is_block (const struct attribute
*attr
)
25034 return (attr
== NULL
? 0 :
25035 attr
->form
== DW_FORM_block1
25036 || attr
->form
== DW_FORM_block2
25037 || attr
->form
== DW_FORM_block4
25038 || attr
->form
== DW_FORM_block
25039 || attr
->form
== DW_FORM_exprloc
);
25042 /* Return non-zero if ATTR's value is a section offset --- classes
25043 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
25044 You may use DW_UNSND (attr) to retrieve such offsets.
25046 Section 7.5.4, "Attribute Encodings", explains that no attribute
25047 may have a value that belongs to more than one of these classes; it
25048 would be ambiguous if we did, because we use the same forms for all
25052 attr_form_is_section_offset (const struct attribute
*attr
)
25054 return (attr
->form
== DW_FORM_data4
25055 || attr
->form
== DW_FORM_data8
25056 || attr
->form
== DW_FORM_sec_offset
);
25059 /* Return non-zero if ATTR's value falls in the 'constant' class, or
25060 zero otherwise. When this function returns true, you can apply
25061 dwarf2_get_attr_constant_value to it.
25063 However, note that for some attributes you must check
25064 attr_form_is_section_offset before using this test. DW_FORM_data4
25065 and DW_FORM_data8 are members of both the constant class, and of
25066 the classes that contain offsets into other debug sections
25067 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
25068 that, if an attribute's can be either a constant or one of the
25069 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
25070 taken as section offsets, not constants.
25072 DW_FORM_data16 is not considered as dwarf2_get_attr_constant_value
25073 cannot handle that. */
25076 attr_form_is_constant (const struct attribute
*attr
)
25078 switch (attr
->form
)
25080 case DW_FORM_sdata
:
25081 case DW_FORM_udata
:
25082 case DW_FORM_data1
:
25083 case DW_FORM_data2
:
25084 case DW_FORM_data4
:
25085 case DW_FORM_data8
:
25086 case DW_FORM_implicit_const
:
25094 /* DW_ADDR is always stored already as sect_offset; despite for the forms
25095 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
25098 attr_form_is_ref (const struct attribute
*attr
)
25100 switch (attr
->form
)
25102 case DW_FORM_ref_addr
:
25107 case DW_FORM_ref_udata
:
25108 case DW_FORM_GNU_ref_alt
:
25115 /* Return the .debug_loc section to use for CU.
25116 For DWO files use .debug_loc.dwo. */
25118 static struct dwarf2_section_info
*
25119 cu_debug_loc_section (struct dwarf2_cu
*cu
)
25121 struct dwarf2_per_objfile
*dwarf2_per_objfile
25122 = cu
->per_cu
->dwarf2_per_objfile
;
25126 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
25128 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
25130 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
25131 : &dwarf2_per_objfile
->loc
);
25134 /* A helper function that fills in a dwarf2_loclist_baton. */
25137 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
25138 struct dwarf2_loclist_baton
*baton
,
25139 const struct attribute
*attr
)
25141 struct dwarf2_per_objfile
*dwarf2_per_objfile
25142 = cu
->per_cu
->dwarf2_per_objfile
;
25143 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
25145 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
25147 baton
->per_cu
= cu
->per_cu
;
25148 gdb_assert (baton
->per_cu
);
25149 /* We don't know how long the location list is, but make sure we
25150 don't run off the edge of the section. */
25151 baton
->size
= section
->size
- DW_UNSND (attr
);
25152 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
25153 baton
->base_address
= cu
->base_address
;
25154 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
25158 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
25159 struct dwarf2_cu
*cu
, int is_block
)
25161 struct dwarf2_per_objfile
*dwarf2_per_objfile
25162 = cu
->per_cu
->dwarf2_per_objfile
;
25163 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25164 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
25166 if (attr_form_is_section_offset (attr
)
25167 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
25168 the section. If so, fall through to the complaint in the
25170 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
25172 struct dwarf2_loclist_baton
*baton
;
25174 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
25176 fill_in_loclist_baton (cu
, baton
, attr
);
25178 if (cu
->base_known
== 0)
25179 complaint (_("Location list used without "
25180 "specifying the CU base address."));
25182 SYMBOL_ACLASS_INDEX (sym
) = (is_block
25183 ? dwarf2_loclist_block_index
25184 : dwarf2_loclist_index
);
25185 SYMBOL_LOCATION_BATON (sym
) = baton
;
25189 struct dwarf2_locexpr_baton
*baton
;
25191 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
25192 baton
->per_cu
= cu
->per_cu
;
25193 gdb_assert (baton
->per_cu
);
25195 if (attr_form_is_block (attr
))
25197 /* Note that we're just copying the block's data pointer
25198 here, not the actual data. We're still pointing into the
25199 info_buffer for SYM's objfile; right now we never release
25200 that buffer, but when we do clean up properly this may
25202 baton
->size
= DW_BLOCK (attr
)->size
;
25203 baton
->data
= DW_BLOCK (attr
)->data
;
25207 dwarf2_invalid_attrib_class_complaint ("location description",
25208 SYMBOL_NATURAL_NAME (sym
));
25212 SYMBOL_ACLASS_INDEX (sym
) = (is_block
25213 ? dwarf2_locexpr_block_index
25214 : dwarf2_locexpr_index
);
25215 SYMBOL_LOCATION_BATON (sym
) = baton
;
25219 /* Return the OBJFILE associated with the compilation unit CU. If CU
25220 came from a separate debuginfo file, then the master objfile is
25224 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
25226 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
25228 /* Return the master objfile, so that we can report and look up the
25229 correct file containing this variable. */
25230 if (objfile
->separate_debug_objfile_backlink
)
25231 objfile
= objfile
->separate_debug_objfile_backlink
;
25236 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
25237 (CU_HEADERP is unused in such case) or prepare a temporary copy at
25238 CU_HEADERP first. */
25240 static const struct comp_unit_head
*
25241 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
25242 struct dwarf2_per_cu_data
*per_cu
)
25244 const gdb_byte
*info_ptr
;
25247 return &per_cu
->cu
->header
;
25249 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
25251 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
25252 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
25253 rcuh_kind::COMPILE
);
25258 /* Return the address size given in the compilation unit header for CU. */
25261 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
25263 struct comp_unit_head cu_header_local
;
25264 const struct comp_unit_head
*cu_headerp
;
25266 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25268 return cu_headerp
->addr_size
;
25271 /* Return the offset size given in the compilation unit header for CU. */
25274 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
25276 struct comp_unit_head cu_header_local
;
25277 const struct comp_unit_head
*cu_headerp
;
25279 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25281 return cu_headerp
->offset_size
;
25284 /* See its dwarf2loc.h declaration. */
25287 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
25289 struct comp_unit_head cu_header_local
;
25290 const struct comp_unit_head
*cu_headerp
;
25292 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25294 if (cu_headerp
->version
== 2)
25295 return cu_headerp
->addr_size
;
25297 return cu_headerp
->offset_size
;
25300 /* Return the text offset of the CU. The returned offset comes from
25301 this CU's objfile. If this objfile came from a separate debuginfo
25302 file, then the offset may be different from the corresponding
25303 offset in the parent objfile. */
25306 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
25308 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
25310 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
25313 /* Return a type that is a generic pointer type, the size of which matches
25314 the address size given in the compilation unit header for PER_CU. */
25315 static struct type
*
25316 dwarf2_per_cu_addr_type (struct dwarf2_per_cu_data
*per_cu
)
25318 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
25319 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
25320 struct type
*addr_type
= lookup_pointer_type (void_type
);
25321 int addr_size
= dwarf2_per_cu_addr_size (per_cu
);
25323 if (TYPE_LENGTH (addr_type
) == addr_size
)
25327 = dwarf2_per_cu_addr_sized_int_type (per_cu
, TYPE_UNSIGNED (addr_type
));
25331 /* Return DWARF version number of PER_CU. */
25334 dwarf2_version (struct dwarf2_per_cu_data
*per_cu
)
25336 return per_cu
->dwarf_version
;
25339 /* Locate the .debug_info compilation unit from CU's objfile which contains
25340 the DIE at OFFSET. Raises an error on failure. */
25342 static struct dwarf2_per_cu_data
*
25343 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
25344 unsigned int offset_in_dwz
,
25345 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
25347 struct dwarf2_per_cu_data
*this_cu
;
25351 high
= dwarf2_per_objfile
->all_comp_units
.size () - 1;
25354 struct dwarf2_per_cu_data
*mid_cu
;
25355 int mid
= low
+ (high
- low
) / 2;
25357 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
25358 if (mid_cu
->is_dwz
> offset_in_dwz
25359 || (mid_cu
->is_dwz
== offset_in_dwz
25360 && mid_cu
->sect_off
+ mid_cu
->length
>= sect_off
))
25365 gdb_assert (low
== high
);
25366 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
25367 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
25369 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
25370 error (_("Dwarf Error: could not find partial DIE containing "
25371 "offset %s [in module %s]"),
25372 sect_offset_str (sect_off
),
25373 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
25375 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
25377 return dwarf2_per_objfile
->all_comp_units
[low
-1];
25381 if (low
== dwarf2_per_objfile
->all_comp_units
.size () - 1
25382 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
25383 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
25384 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
25389 /* Initialize dwarf2_cu CU, owned by PER_CU. */
25391 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data
*per_cu_
)
25392 : per_cu (per_cu_
),
25394 has_loclist (false),
25395 checked_producer (false),
25396 producer_is_gxx_lt_4_6 (false),
25397 producer_is_gcc_lt_4_3 (false),
25398 producer_is_icc (false),
25399 producer_is_icc_lt_14 (false),
25400 producer_is_codewarrior (false),
25401 processing_has_namespace_info (false)
25406 /* Destroy a dwarf2_cu. */
25408 dwarf2_cu::~dwarf2_cu ()
25413 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
25416 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
25417 enum language pretend_language
)
25419 struct attribute
*attr
;
25421 /* Set the language we're debugging. */
25422 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
25424 set_cu_language (DW_UNSND (attr
), cu
);
25427 cu
->language
= pretend_language
;
25428 cu
->language_defn
= language_def (cu
->language
);
25431 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
25434 /* Increase the age counter on each cached compilation unit, and free
25435 any that are too old. */
25438 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
25440 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25442 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
25443 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25444 while (per_cu
!= NULL
)
25446 per_cu
->cu
->last_used
++;
25447 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
25448 dwarf2_mark (per_cu
->cu
);
25449 per_cu
= per_cu
->cu
->read_in_chain
;
25452 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25453 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25454 while (per_cu
!= NULL
)
25456 struct dwarf2_per_cu_data
*next_cu
;
25458 next_cu
= per_cu
->cu
->read_in_chain
;
25460 if (!per_cu
->cu
->mark
)
25463 *last_chain
= next_cu
;
25466 last_chain
= &per_cu
->cu
->read_in_chain
;
25472 /* Remove a single compilation unit from the cache. */
25475 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
25477 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25478 struct dwarf2_per_objfile
*dwarf2_per_objfile
25479 = target_per_cu
->dwarf2_per_objfile
;
25481 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25482 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25483 while (per_cu
!= NULL
)
25485 struct dwarf2_per_cu_data
*next_cu
;
25487 next_cu
= per_cu
->cu
->read_in_chain
;
25489 if (per_cu
== target_per_cu
)
25493 *last_chain
= next_cu
;
25497 last_chain
= &per_cu
->cu
->read_in_chain
;
25503 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
25504 We store these in a hash table separate from the DIEs, and preserve them
25505 when the DIEs are flushed out of cache.
25507 The CU "per_cu" pointer is needed because offset alone is not enough to
25508 uniquely identify the type. A file may have multiple .debug_types sections,
25509 or the type may come from a DWO file. Furthermore, while it's more logical
25510 to use per_cu->section+offset, with Fission the section with the data is in
25511 the DWO file but we don't know that section at the point we need it.
25512 We have to use something in dwarf2_per_cu_data (or the pointer to it)
25513 because we can enter the lookup routine, get_die_type_at_offset, from
25514 outside this file, and thus won't necessarily have PER_CU->cu.
25515 Fortunately, PER_CU is stable for the life of the objfile. */
25517 struct dwarf2_per_cu_offset_and_type
25519 const struct dwarf2_per_cu_data
*per_cu
;
25520 sect_offset sect_off
;
25524 /* Hash function for a dwarf2_per_cu_offset_and_type. */
25527 per_cu_offset_and_type_hash (const void *item
)
25529 const struct dwarf2_per_cu_offset_and_type
*ofs
25530 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
25532 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
25535 /* Equality function for a dwarf2_per_cu_offset_and_type. */
25538 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
25540 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
25541 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
25542 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
25543 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
25545 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
25546 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
25549 /* Set the type associated with DIE to TYPE. Save it in CU's hash
25550 table if necessary. For convenience, return TYPE.
25552 The DIEs reading must have careful ordering to:
25553 * Not cause infite loops trying to read in DIEs as a prerequisite for
25554 reading current DIE.
25555 * Not trying to dereference contents of still incompletely read in types
25556 while reading in other DIEs.
25557 * Enable referencing still incompletely read in types just by a pointer to
25558 the type without accessing its fields.
25560 Therefore caller should follow these rules:
25561 * Try to fetch any prerequisite types we may need to build this DIE type
25562 before building the type and calling set_die_type.
25563 * After building type call set_die_type for current DIE as soon as
25564 possible before fetching more types to complete the current type.
25565 * Make the type as complete as possible before fetching more types. */
25567 static struct type
*
25568 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
25570 struct dwarf2_per_objfile
*dwarf2_per_objfile
25571 = cu
->per_cu
->dwarf2_per_objfile
;
25572 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
25573 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25574 struct attribute
*attr
;
25575 struct dynamic_prop prop
;
25577 /* For Ada types, make sure that the gnat-specific data is always
25578 initialized (if not already set). There are a few types where
25579 we should not be doing so, because the type-specific area is
25580 already used to hold some other piece of info (eg: TYPE_CODE_FLT
25581 where the type-specific area is used to store the floatformat).
25582 But this is not a problem, because the gnat-specific information
25583 is actually not needed for these types. */
25584 if (need_gnat_info (cu
)
25585 && TYPE_CODE (type
) != TYPE_CODE_FUNC
25586 && TYPE_CODE (type
) != TYPE_CODE_FLT
25587 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
25588 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
25589 && TYPE_CODE (type
) != TYPE_CODE_METHOD
25590 && !HAVE_GNAT_AUX_INFO (type
))
25591 INIT_GNAT_SPECIFIC (type
);
25593 /* Read DW_AT_allocated and set in type. */
25594 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
25595 if (attr_form_is_block (attr
))
25597 struct type
*prop_type
25598 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
25599 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
25600 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
);
25602 else if (attr
!= NULL
)
25604 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
25605 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25606 sect_offset_str (die
->sect_off
));
25609 /* Read DW_AT_associated and set in type. */
25610 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
25611 if (attr_form_is_block (attr
))
25613 struct type
*prop_type
25614 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
25615 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
25616 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
);
25618 else if (attr
!= NULL
)
25620 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
25621 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25622 sect_offset_str (die
->sect_off
));
25625 /* Read DW_AT_data_location and set in type. */
25626 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
25627 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
,
25628 dwarf2_per_cu_addr_type (cu
->per_cu
)))
25629 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
);
25631 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25633 dwarf2_per_objfile
->die_type_hash
=
25634 htab_create_alloc_ex (127,
25635 per_cu_offset_and_type_hash
,
25636 per_cu_offset_and_type_eq
,
25638 &objfile
->objfile_obstack
,
25639 hashtab_obstack_allocate
,
25640 dummy_obstack_deallocate
);
25643 ofs
.per_cu
= cu
->per_cu
;
25644 ofs
.sect_off
= die
->sect_off
;
25646 slot
= (struct dwarf2_per_cu_offset_and_type
**)
25647 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
25649 complaint (_("A problem internal to GDB: DIE %s has type already set"),
25650 sect_offset_str (die
->sect_off
));
25651 *slot
= XOBNEW (&objfile
->objfile_obstack
,
25652 struct dwarf2_per_cu_offset_and_type
);
25657 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
25658 or return NULL if the die does not have a saved type. */
25660 static struct type
*
25661 get_die_type_at_offset (sect_offset sect_off
,
25662 struct dwarf2_per_cu_data
*per_cu
)
25664 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
25665 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
25667 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25670 ofs
.per_cu
= per_cu
;
25671 ofs
.sect_off
= sect_off
;
25672 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
25673 htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
));
25680 /* Look up the type for DIE in CU in die_type_hash,
25681 or return NULL if DIE does not have a saved type. */
25683 static struct type
*
25684 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
25686 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
25689 /* Add a dependence relationship from CU to REF_PER_CU. */
25692 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
25693 struct dwarf2_per_cu_data
*ref_per_cu
)
25697 if (cu
->dependencies
== NULL
)
25699 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
25700 NULL
, &cu
->comp_unit_obstack
,
25701 hashtab_obstack_allocate
,
25702 dummy_obstack_deallocate
);
25704 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
25706 *slot
= ref_per_cu
;
25709 /* Subroutine of dwarf2_mark to pass to htab_traverse.
25710 Set the mark field in every compilation unit in the
25711 cache that we must keep because we are keeping CU. */
25714 dwarf2_mark_helper (void **slot
, void *data
)
25716 struct dwarf2_per_cu_data
*per_cu
;
25718 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
25720 /* cu->dependencies references may not yet have been ever read if QUIT aborts
25721 reading of the chain. As such dependencies remain valid it is not much
25722 useful to track and undo them during QUIT cleanups. */
25723 if (per_cu
->cu
== NULL
)
25726 if (per_cu
->cu
->mark
)
25728 per_cu
->cu
->mark
= true;
25730 if (per_cu
->cu
->dependencies
!= NULL
)
25731 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
25736 /* Set the mark field in CU and in every other compilation unit in the
25737 cache that we must keep because we are keeping CU. */
25740 dwarf2_mark (struct dwarf2_cu
*cu
)
25745 if (cu
->dependencies
!= NULL
)
25746 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
25750 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
25754 per_cu
->cu
->mark
= false;
25755 per_cu
= per_cu
->cu
->read_in_chain
;
25759 /* Trivial hash function for partial_die_info: the hash value of a DIE
25760 is its offset in .debug_info for this objfile. */
25763 partial_die_hash (const void *item
)
25765 const struct partial_die_info
*part_die
25766 = (const struct partial_die_info
*) item
;
25768 return to_underlying (part_die
->sect_off
);
25771 /* Trivial comparison function for partial_die_info structures: two DIEs
25772 are equal if they have the same offset. */
25775 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
25777 const struct partial_die_info
*part_die_lhs
25778 = (const struct partial_die_info
*) item_lhs
;
25779 const struct partial_die_info
*part_die_rhs
25780 = (const struct partial_die_info
*) item_rhs
;
25782 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
25785 struct cmd_list_element
*set_dwarf_cmdlist
;
25786 struct cmd_list_element
*show_dwarf_cmdlist
;
25789 set_dwarf_cmd (const char *args
, int from_tty
)
25791 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
25796 show_dwarf_cmd (const char *args
, int from_tty
)
25798 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
25801 int dwarf_always_disassemble
;
25804 show_dwarf_always_disassemble (struct ui_file
*file
, int from_tty
,
25805 struct cmd_list_element
*c
, const char *value
)
25807 fprintf_filtered (file
,
25808 _("Whether to always disassemble "
25809 "DWARF expressions is %s.\n"),
25814 show_check_physname (struct ui_file
*file
, int from_tty
,
25815 struct cmd_list_element
*c
, const char *value
)
25817 fprintf_filtered (file
,
25818 _("Whether to check \"physname\" is %s.\n"),
25823 _initialize_dwarf2_read (void)
25825 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
25826 Set DWARF specific variables.\n\
25827 Configure DWARF variables such as the cache size."),
25828 &set_dwarf_cmdlist
, "maintenance set dwarf ",
25829 0/*allow-unknown*/, &maintenance_set_cmdlist
);
25831 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
25832 Show DWARF specific variables.\n\
25833 Show DWARF variables such as the cache size."),
25834 &show_dwarf_cmdlist
, "maintenance show dwarf ",
25835 0/*allow-unknown*/, &maintenance_show_cmdlist
);
25837 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
25838 &dwarf_max_cache_age
, _("\
25839 Set the upper bound on the age of cached DWARF compilation units."), _("\
25840 Show the upper bound on the age of cached DWARF compilation units."), _("\
25841 A higher limit means that cached compilation units will be stored\n\
25842 in memory longer, and more total memory will be used. Zero disables\n\
25843 caching, which can slow down startup."),
25845 show_dwarf_max_cache_age
,
25846 &set_dwarf_cmdlist
,
25847 &show_dwarf_cmdlist
);
25849 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
25850 &dwarf_always_disassemble
, _("\
25851 Set whether `info address' always disassembles DWARF expressions."), _("\
25852 Show whether `info address' always disassembles DWARF expressions."), _("\
25853 When enabled, DWARF expressions are always printed in an assembly-like\n\
25854 syntax. When disabled, expressions will be printed in a more\n\
25855 conversational style, when possible."),
25857 show_dwarf_always_disassemble
,
25858 &set_dwarf_cmdlist
,
25859 &show_dwarf_cmdlist
);
25861 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
25862 Set debugging of the DWARF reader."), _("\
25863 Show debugging of the DWARF reader."), _("\
25864 When enabled (non-zero), debugging messages are printed during DWARF\n\
25865 reading and symtab expansion. A value of 1 (one) provides basic\n\
25866 information. A value greater than 1 provides more verbose information."),
25869 &setdebuglist
, &showdebuglist
);
25871 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
25872 Set debugging of the DWARF DIE reader."), _("\
25873 Show debugging of the DWARF DIE reader."), _("\
25874 When enabled (non-zero), DIEs are dumped after they are read in.\n\
25875 The value is the maximum depth to print."),
25878 &setdebuglist
, &showdebuglist
);
25880 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
25881 Set debugging of the dwarf line reader."), _("\
25882 Show debugging of the dwarf line reader."), _("\
25883 When enabled (non-zero), line number entries are dumped as they are read in.\n\
25884 A value of 1 (one) provides basic information.\n\
25885 A value greater than 1 provides more verbose information."),
25888 &setdebuglist
, &showdebuglist
);
25890 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
25891 Set cross-checking of \"physname\" code against demangler."), _("\
25892 Show cross-checking of \"physname\" code against demangler."), _("\
25893 When enabled, GDB's internal \"physname\" code is checked against\n\
25895 NULL
, show_check_physname
,
25896 &setdebuglist
, &showdebuglist
);
25898 add_setshow_boolean_cmd ("use-deprecated-index-sections",
25899 no_class
, &use_deprecated_index_sections
, _("\
25900 Set whether to use deprecated gdb_index sections."), _("\
25901 Show whether to use deprecated gdb_index sections."), _("\
25902 When enabled, deprecated .gdb_index sections are used anyway.\n\
25903 Normally they are ignored either because of a missing feature or\n\
25904 performance issue.\n\
25905 Warning: This option must be enabled before gdb reads the file."),
25908 &setlist
, &showlist
);
25910 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
25911 &dwarf2_locexpr_funcs
);
25912 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
25913 &dwarf2_loclist_funcs
);
25915 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
25916 &dwarf2_block_frame_base_locexpr_funcs
);
25917 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
25918 &dwarf2_block_frame_base_loclist_funcs
);
25921 selftests::register_test ("dw2_expand_symtabs_matching",
25922 selftests::dw2_expand_symtabs_matching::run_test
);