1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2020 Free Software Foundation, Inc.
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
12 This file is part of GDB.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 /* FIXME: Various die-reading functions need to be more careful with
28 reading off the end of the section.
29 E.g., load_partial_dies, read_partial_die. */
32 #include "dwarf2read.h"
33 #include "dwarf-index-cache.h"
34 #include "dwarf-index-common.h"
43 #include "gdb-demangle.h"
44 #include "filenames.h" /* for DOSish file names */
47 #include "complaints.h"
48 #include "dwarf2expr.h"
49 #include "dwarf2loc.h"
50 #include "cp-support.h"
56 #include "typeprint.h"
61 #include "gdbcore.h" /* for gnutarget */
62 #include "gdb/gdb-index.h"
67 #include "namespace.h"
68 #include "gdbsupport/function-view.h"
69 #include "gdbsupport/gdb_optional.h"
70 #include "gdbsupport/underlying.h"
71 #include "gdbsupport/hash_enum.h"
72 #include "filename-seen-cache.h"
76 #include <unordered_map>
77 #include "gdbsupport/selftest.h"
78 #include "rust-lang.h"
79 #include "gdbsupport/pathstuff.h"
81 /* When == 1, print basic high level tracing messages.
82 When > 1, be more verbose.
83 This is in contrast to the low level DIE reading of dwarf_die_debug. */
84 static unsigned int dwarf_read_debug
= 0;
86 /* When non-zero, dump DIEs after they are read in. */
87 static unsigned int dwarf_die_debug
= 0;
89 /* When non-zero, dump line number entries as they are read in. */
90 static unsigned int dwarf_line_debug
= 0;
92 /* When true, cross-check physname against demangler. */
93 static bool check_physname
= false;
95 /* When true, do not reject deprecated .gdb_index sections. */
96 static bool use_deprecated_index_sections
= false;
98 static const struct objfile_key
<dwarf2_per_objfile
> dwarf2_objfile_data_key
;
100 /* The "aclass" indices for various kinds of computed DWARF symbols. */
102 static int dwarf2_locexpr_index
;
103 static int dwarf2_loclist_index
;
104 static int dwarf2_locexpr_block_index
;
105 static int dwarf2_loclist_block_index
;
107 /* An index into a (C++) symbol name component in a symbol name as
108 recorded in the mapped_index's symbol table. For each C++ symbol
109 in the symbol table, we record one entry for the start of each
110 component in the symbol in a table of name components, and then
111 sort the table, in order to be able to binary search symbol names,
112 ignoring leading namespaces, both completion and regular look up.
113 For example, for symbol "A::B::C", we'll have an entry that points
114 to "A::B::C", another that points to "B::C", and another for "C".
115 Note that function symbols in GDB index have no parameter
116 information, just the function/method names. You can convert a
117 name_component to a "const char *" using the
118 'mapped_index::symbol_name_at(offset_type)' method. */
120 struct name_component
122 /* Offset in the symbol name where the component starts. Stored as
123 a (32-bit) offset instead of a pointer to save memory and improve
124 locality on 64-bit architectures. */
125 offset_type name_offset
;
127 /* The symbol's index in the symbol and constant pool tables of a
132 /* Base class containing bits shared by both .gdb_index and
133 .debug_name indexes. */
135 struct mapped_index_base
137 mapped_index_base () = default;
138 DISABLE_COPY_AND_ASSIGN (mapped_index_base
);
140 /* The name_component table (a sorted vector). See name_component's
141 description above. */
142 std::vector
<name_component
> name_components
;
144 /* How NAME_COMPONENTS is sorted. */
145 enum case_sensitivity name_components_casing
;
147 /* Return the number of names in the symbol table. */
148 virtual size_t symbol_name_count () const = 0;
150 /* Get the name of the symbol at IDX in the symbol table. */
151 virtual const char *symbol_name_at (offset_type idx
) const = 0;
153 /* Return whether the name at IDX in the symbol table should be
155 virtual bool symbol_name_slot_invalid (offset_type idx
) const
160 /* Build the symbol name component sorted vector, if we haven't
162 void build_name_components ();
164 /* Returns the lower (inclusive) and upper (exclusive) bounds of the
165 possible matches for LN_NO_PARAMS in the name component
167 std::pair
<std::vector
<name_component
>::const_iterator
,
168 std::vector
<name_component
>::const_iterator
>
169 find_name_components_bounds (const lookup_name_info
&ln_no_params
,
170 enum language lang
) const;
172 /* Prevent deleting/destroying via a base class pointer. */
174 ~mapped_index_base() = default;
177 /* A description of the mapped index. The file format is described in
178 a comment by the code that writes the index. */
179 struct mapped_index final
: public mapped_index_base
181 /* A slot/bucket in the symbol table hash. */
182 struct symbol_table_slot
184 const offset_type name
;
185 const offset_type vec
;
188 /* Index data format version. */
191 /* The address table data. */
192 gdb::array_view
<const gdb_byte
> address_table
;
194 /* The symbol table, implemented as a hash table. */
195 gdb::array_view
<symbol_table_slot
> symbol_table
;
197 /* A pointer to the constant pool. */
198 const char *constant_pool
= nullptr;
200 bool symbol_name_slot_invalid (offset_type idx
) const override
202 const auto &bucket
= this->symbol_table
[idx
];
203 return bucket
.name
== 0 && bucket
.vec
== 0;
206 /* Convenience method to get at the name of the symbol at IDX in the
208 const char *symbol_name_at (offset_type idx
) const override
209 { return this->constant_pool
+ MAYBE_SWAP (this->symbol_table
[idx
].name
); }
211 size_t symbol_name_count () const override
212 { return this->symbol_table
.size (); }
215 /* A description of the mapped .debug_names.
216 Uninitialized map has CU_COUNT 0. */
217 struct mapped_debug_names final
: public mapped_index_base
219 mapped_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile_
)
220 : dwarf2_per_objfile (dwarf2_per_objfile_
)
223 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
224 bfd_endian dwarf5_byte_order
;
225 bool dwarf5_is_dwarf64
;
226 bool augmentation_is_gdb
;
228 uint32_t cu_count
= 0;
229 uint32_t tu_count
, bucket_count
, name_count
;
230 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
231 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
232 const gdb_byte
*name_table_string_offs_reordered
;
233 const gdb_byte
*name_table_entry_offs_reordered
;
234 const gdb_byte
*entry_pool
;
241 /* Attribute name DW_IDX_*. */
244 /* Attribute form DW_FORM_*. */
247 /* Value if FORM is DW_FORM_implicit_const. */
248 LONGEST implicit_const
;
250 std::vector
<attr
> attr_vec
;
253 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
255 const char *namei_to_name (uint32_t namei
) const;
257 /* Implementation of the mapped_index_base virtual interface, for
258 the name_components cache. */
260 const char *symbol_name_at (offset_type idx
) const override
261 { return namei_to_name (idx
); }
263 size_t symbol_name_count () const override
264 { return this->name_count
; }
267 /* See dwarf2read.h. */
270 get_dwarf2_per_objfile (struct objfile
*objfile
)
272 return dwarf2_objfile_data_key
.get (objfile
);
275 /* Default names of the debugging sections. */
277 /* Note that if the debugging section has been compressed, it might
278 have a name like .zdebug_info. */
280 static const struct dwarf2_debug_sections dwarf2_elf_names
=
282 { ".debug_info", ".zdebug_info" },
283 { ".debug_abbrev", ".zdebug_abbrev" },
284 { ".debug_line", ".zdebug_line" },
285 { ".debug_loc", ".zdebug_loc" },
286 { ".debug_loclists", ".zdebug_loclists" },
287 { ".debug_macinfo", ".zdebug_macinfo" },
288 { ".debug_macro", ".zdebug_macro" },
289 { ".debug_str", ".zdebug_str" },
290 { ".debug_str_offsets", ".zdebug_str_offsets" },
291 { ".debug_line_str", ".zdebug_line_str" },
292 { ".debug_ranges", ".zdebug_ranges" },
293 { ".debug_rnglists", ".zdebug_rnglists" },
294 { ".debug_types", ".zdebug_types" },
295 { ".debug_addr", ".zdebug_addr" },
296 { ".debug_frame", ".zdebug_frame" },
297 { ".eh_frame", NULL
},
298 { ".gdb_index", ".zgdb_index" },
299 { ".debug_names", ".zdebug_names" },
300 { ".debug_aranges", ".zdebug_aranges" },
304 /* List of DWO/DWP sections. */
306 static const struct dwop_section_names
308 struct dwarf2_section_names abbrev_dwo
;
309 struct dwarf2_section_names info_dwo
;
310 struct dwarf2_section_names line_dwo
;
311 struct dwarf2_section_names loc_dwo
;
312 struct dwarf2_section_names loclists_dwo
;
313 struct dwarf2_section_names macinfo_dwo
;
314 struct dwarf2_section_names macro_dwo
;
315 struct dwarf2_section_names str_dwo
;
316 struct dwarf2_section_names str_offsets_dwo
;
317 struct dwarf2_section_names types_dwo
;
318 struct dwarf2_section_names cu_index
;
319 struct dwarf2_section_names tu_index
;
323 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
324 { ".debug_info.dwo", ".zdebug_info.dwo" },
325 { ".debug_line.dwo", ".zdebug_line.dwo" },
326 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
327 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
328 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
329 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
330 { ".debug_str.dwo", ".zdebug_str.dwo" },
331 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
332 { ".debug_types.dwo", ".zdebug_types.dwo" },
333 { ".debug_cu_index", ".zdebug_cu_index" },
334 { ".debug_tu_index", ".zdebug_tu_index" },
337 /* local data types */
339 /* The data in a compilation unit header, after target2host
340 translation, looks like this. */
341 struct comp_unit_head
345 unsigned char addr_size
;
346 unsigned char signed_addr_p
;
347 sect_offset abbrev_sect_off
;
349 /* Size of file offsets; either 4 or 8. */
350 unsigned int offset_size
;
352 /* Size of the length field; either 4 or 12. */
353 unsigned int initial_length_size
;
355 enum dwarf_unit_type unit_type
;
357 /* Offset to the first byte of this compilation unit header in the
358 .debug_info section, for resolving relative reference dies. */
359 sect_offset sect_off
;
361 /* Offset to first die in this cu from the start of the cu.
362 This will be the first byte following the compilation unit header. */
363 cu_offset first_die_cu_offset
;
366 /* 64-bit signature of this unit. For type units, it denotes the signature of
367 the type (DW_UT_type in DWARF 4, additionally DW_UT_split_type in DWARF 5).
368 Also used in DWARF 5, to denote the dwo id when the unit type is
369 DW_UT_skeleton or DW_UT_split_compile. */
372 /* For types, offset in the type's DIE of the type defined by this TU. */
373 cu_offset type_cu_offset_in_tu
;
376 /* Type used for delaying computation of method physnames.
377 See comments for compute_delayed_physnames. */
378 struct delayed_method_info
380 /* The type to which the method is attached, i.e., its parent class. */
383 /* The index of the method in the type's function fieldlists. */
386 /* The index of the method in the fieldlist. */
389 /* The name of the DIE. */
392 /* The DIE associated with this method. */
393 struct die_info
*die
;
396 /* Internal state when decoding a particular compilation unit. */
399 explicit dwarf2_cu (struct dwarf2_per_cu_data
*per_cu
);
402 DISABLE_COPY_AND_ASSIGN (dwarf2_cu
);
404 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
405 Create the set of symtabs used by this TU, or if this TU is sharing
406 symtabs with another TU and the symtabs have already been created
407 then restore those symtabs in the line header.
408 We don't need the pc/line-number mapping for type units. */
409 void setup_type_unit_groups (struct die_info
*die
);
411 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
412 buildsym_compunit constructor. */
413 struct compunit_symtab
*start_symtab (const char *name
,
414 const char *comp_dir
,
417 /* Reset the builder. */
418 void reset_builder () { m_builder
.reset (); }
420 /* The header of the compilation unit. */
421 struct comp_unit_head header
{};
423 /* Base address of this compilation unit. */
424 CORE_ADDR base_address
= 0;
426 /* Non-zero if base_address has been set. */
429 /* The language we are debugging. */
430 enum language language
= language_unknown
;
431 const struct language_defn
*language_defn
= nullptr;
433 const char *producer
= nullptr;
436 /* The symtab builder for this CU. This is only non-NULL when full
437 symbols are being read. */
438 std::unique_ptr
<buildsym_compunit
> m_builder
;
441 /* The generic symbol table building routines have separate lists for
442 file scope symbols and all all other scopes (local scopes). So
443 we need to select the right one to pass to add_symbol_to_list().
444 We do it by keeping a pointer to the correct list in list_in_scope.
446 FIXME: The original dwarf code just treated the file scope as the
447 first local scope, and all other local scopes as nested local
448 scopes, and worked fine. Check to see if we really need to
449 distinguish these in buildsym.c. */
450 struct pending
**list_in_scope
= nullptr;
452 /* Hash table holding all the loaded partial DIEs
453 with partial_die->offset.SECT_OFF as hash. */
454 htab_t partial_dies
= nullptr;
456 /* Storage for things with the same lifetime as this read-in compilation
457 unit, including partial DIEs. */
458 auto_obstack comp_unit_obstack
;
460 /* When multiple dwarf2_cu structures are living in memory, this field
461 chains them all together, so that they can be released efficiently.
462 We will probably also want a generation counter so that most-recently-used
463 compilation units are cached... */
464 struct dwarf2_per_cu_data
*read_in_chain
= nullptr;
466 /* Backlink to our per_cu entry. */
467 struct dwarf2_per_cu_data
*per_cu
;
469 /* How many compilation units ago was this CU last referenced? */
472 /* A hash table of DIE cu_offset for following references with
473 die_info->offset.sect_off as hash. */
474 htab_t die_hash
= nullptr;
476 /* Full DIEs if read in. */
477 struct die_info
*dies
= nullptr;
479 /* A set of pointers to dwarf2_per_cu_data objects for compilation
480 units referenced by this one. Only set during full symbol processing;
481 partial symbol tables do not have dependencies. */
482 htab_t dependencies
= nullptr;
484 /* Header data from the line table, during full symbol processing. */
485 struct line_header
*line_header
= nullptr;
486 /* Non-NULL if LINE_HEADER is owned by this DWARF_CU. Otherwise,
487 it's owned by dwarf2_per_objfile::line_header_hash. If non-NULL,
488 this is the DW_TAG_compile_unit die for this CU. We'll hold on
489 to the line header as long as this DIE is being processed. See
490 process_die_scope. */
491 die_info
*line_header_die_owner
= nullptr;
493 /* A list of methods which need to have physnames computed
494 after all type information has been read. */
495 std::vector
<delayed_method_info
> method_list
;
497 /* To be copied to symtab->call_site_htab. */
498 htab_t call_site_htab
= nullptr;
500 /* Non-NULL if this CU came from a DWO file.
501 There is an invariant here that is important to remember:
502 Except for attributes copied from the top level DIE in the "main"
503 (or "stub") file in preparation for reading the DWO file
504 (e.g., DW_AT_addr_base), we KISS: there is only *one* CU.
505 Either there isn't a DWO file (in which case this is NULL and the point
506 is moot), or there is and either we're not going to read it (in which
507 case this is NULL) or there is and we are reading it (in which case this
509 struct dwo_unit
*dwo_unit
= nullptr;
511 /* The DW_AT_addr_base (DW_AT_GNU_addr_base) attribute if present.
512 Note this value comes from the Fission stub CU/TU's DIE. */
513 gdb::optional
<ULONGEST
> addr_base
;
515 /* The DW_AT_rnglists_base attribute if present.
516 Note this value comes from the Fission stub CU/TU's DIE.
517 Also note that the value is zero in the non-DWO case so this value can
518 be used without needing to know whether DWO files are in use or not.
519 N.B. This does not apply to DW_AT_ranges appearing in
520 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
521 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
522 DW_AT_rnglists_base *would* have to be applied, and we'd have to care
523 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
524 ULONGEST ranges_base
= 0;
526 /* When reading debug info generated by older versions of rustc, we
527 have to rewrite some union types to be struct types with a
528 variant part. This rewriting must be done after the CU is fully
529 read in, because otherwise at the point of rewriting some struct
530 type might not have been fully processed. So, we keep a list of
531 all such types here and process them after expansion. */
532 std::vector
<struct type
*> rust_unions
;
534 /* The DW_AT_str_offsets_base attribute if present. For DWARF 4 version DWO
535 files, the value is implicitly zero. For DWARF 5 version DWO files, the
536 value is often implicit and is the size of the header of
537 .debug_str_offsets section (8 or 4, depending on the address size). */
538 gdb::optional
<ULONGEST
> str_offsets_base
;
540 /* Mark used when releasing cached dies. */
543 /* This CU references .debug_loc. See the symtab->locations_valid field.
544 This test is imperfect as there may exist optimized debug code not using
545 any location list and still facing inlining issues if handled as
546 unoptimized code. For a future better test see GCC PR other/32998. */
547 bool has_loclist
: 1;
549 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is true
550 if all the producer_is_* fields are valid. This information is cached
551 because profiling CU expansion showed excessive time spent in
552 producer_is_gxx_lt_4_6. */
553 bool checked_producer
: 1;
554 bool producer_is_gxx_lt_4_6
: 1;
555 bool producer_is_gcc_lt_4_3
: 1;
556 bool producer_is_icc
: 1;
557 bool producer_is_icc_lt_14
: 1;
558 bool producer_is_codewarrior
: 1;
560 /* When true, the file that we're processing is known to have
561 debugging info for C++ namespaces. GCC 3.3.x did not produce
562 this information, but later versions do. */
564 bool processing_has_namespace_info
: 1;
566 struct partial_die_info
*find_partial_die (sect_offset sect_off
);
568 /* If this CU was inherited by another CU (via specification,
569 abstract_origin, etc), this is the ancestor CU. */
572 /* Get the buildsym_compunit for this CU. */
573 buildsym_compunit
*get_builder ()
575 /* If this CU has a builder associated with it, use that. */
576 if (m_builder
!= nullptr)
577 return m_builder
.get ();
579 /* Otherwise, search ancestors for a valid builder. */
580 if (ancestor
!= nullptr)
581 return ancestor
->get_builder ();
587 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
588 This includes type_unit_group and quick_file_names. */
590 struct stmt_list_hash
592 /* The DWO unit this table is from or NULL if there is none. */
593 struct dwo_unit
*dwo_unit
;
595 /* Offset in .debug_line or .debug_line.dwo. */
596 sect_offset line_sect_off
;
599 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
600 an object of this type. */
602 struct type_unit_group
604 /* dwarf2read.c's main "handle" on a TU symtab.
605 To simplify things we create an artificial CU that "includes" all the
606 type units using this stmt_list so that the rest of the code still has
607 a "per_cu" handle on the symtab.
608 This PER_CU is recognized by having no section. */
609 #define IS_TYPE_UNIT_GROUP(per_cu) ((per_cu)->section == NULL)
610 struct dwarf2_per_cu_data per_cu
;
612 /* The TUs that share this DW_AT_stmt_list entry.
613 This is added to while parsing type units to build partial symtabs,
614 and is deleted afterwards and not used again. */
615 std::vector
<signatured_type
*> *tus
;
617 /* The compunit symtab.
618 Type units in a group needn't all be defined in the same source file,
619 so we create an essentially anonymous symtab as the compunit symtab. */
620 struct compunit_symtab
*compunit_symtab
;
622 /* The data used to construct the hash key. */
623 struct stmt_list_hash hash
;
625 /* The number of symtabs from the line header.
626 The value here must match line_header.num_file_names. */
627 unsigned int num_symtabs
;
629 /* The symbol tables for this TU (obtained from the files listed in
631 WARNING: The order of entries here must match the order of entries
632 in the line header. After the first TU using this type_unit_group, the
633 line header for the subsequent TUs is recreated from this. This is done
634 because we need to use the same symtabs for each TU using the same
635 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
636 there's no guarantee the line header doesn't have duplicate entries. */
637 struct symtab
**symtabs
;
640 /* These sections are what may appear in a (real or virtual) DWO file. */
644 struct dwarf2_section_info abbrev
;
645 struct dwarf2_section_info line
;
646 struct dwarf2_section_info loc
;
647 struct dwarf2_section_info loclists
;
648 struct dwarf2_section_info macinfo
;
649 struct dwarf2_section_info macro
;
650 struct dwarf2_section_info str
;
651 struct dwarf2_section_info str_offsets
;
652 /* In the case of a virtual DWO file, these two are unused. */
653 struct dwarf2_section_info info
;
654 std::vector
<dwarf2_section_info
> types
;
657 /* CUs/TUs in DWP/DWO files. */
661 /* Backlink to the containing struct dwo_file. */
662 struct dwo_file
*dwo_file
;
664 /* The "id" that distinguishes this CU/TU.
665 .debug_info calls this "dwo_id", .debug_types calls this "signature".
666 Since signatures came first, we stick with it for consistency. */
669 /* The section this CU/TU lives in, in the DWO file. */
670 struct dwarf2_section_info
*section
;
672 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
673 sect_offset sect_off
;
676 /* For types, offset in the type's DIE of the type defined by this TU. */
677 cu_offset type_offset_in_tu
;
680 /* include/dwarf2.h defines the DWP section codes.
681 It defines a max value but it doesn't define a min value, which we
682 use for error checking, so provide one. */
684 enum dwp_v2_section_ids
689 /* Data for one DWO file.
691 This includes virtual DWO files (a virtual DWO file is a DWO file as it
692 appears in a DWP file). DWP files don't really have DWO files per se -
693 comdat folding of types "loses" the DWO file they came from, and from
694 a high level view DWP files appear to contain a mass of random types.
695 However, to maintain consistency with the non-DWP case we pretend DWP
696 files contain virtual DWO files, and we assign each TU with one virtual
697 DWO file (generally based on the line and abbrev section offsets -
698 a heuristic that seems to work in practice). */
702 dwo_file () = default;
703 DISABLE_COPY_AND_ASSIGN (dwo_file
);
705 /* The DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute.
706 For virtual DWO files the name is constructed from the section offsets
707 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
708 from related CU+TUs. */
709 const char *dwo_name
= nullptr;
711 /* The DW_AT_comp_dir attribute. */
712 const char *comp_dir
= nullptr;
714 /* The bfd, when the file is open. Otherwise this is NULL.
715 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
716 gdb_bfd_ref_ptr dbfd
;
718 /* The sections that make up this DWO file.
719 Remember that for virtual DWO files in DWP V2, these are virtual
720 sections (for lack of a better name). */
721 struct dwo_sections sections
{};
723 /* The CUs in the file.
724 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
725 an extension to handle LLVM's Link Time Optimization output (where
726 multiple source files may be compiled into a single object/dwo pair). */
729 /* Table of TUs in the file.
730 Each element is a struct dwo_unit. */
734 /* These sections are what may appear in a DWP file. */
738 /* These are used by both DWP version 1 and 2. */
739 struct dwarf2_section_info str
;
740 struct dwarf2_section_info cu_index
;
741 struct dwarf2_section_info tu_index
;
743 /* These are only used by DWP version 2 files.
744 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
745 sections are referenced by section number, and are not recorded here.
746 In DWP version 2 there is at most one copy of all these sections, each
747 section being (effectively) comprised of the concatenation of all of the
748 individual sections that exist in the version 1 format.
749 To keep the code simple we treat each of these concatenated pieces as a
750 section itself (a virtual section?). */
751 struct dwarf2_section_info abbrev
;
752 struct dwarf2_section_info info
;
753 struct dwarf2_section_info line
;
754 struct dwarf2_section_info loc
;
755 struct dwarf2_section_info macinfo
;
756 struct dwarf2_section_info macro
;
757 struct dwarf2_section_info str_offsets
;
758 struct dwarf2_section_info types
;
761 /* These sections are what may appear in a virtual DWO file in DWP version 1.
762 A virtual DWO file is a DWO file as it appears in a DWP file. */
764 struct virtual_v1_dwo_sections
766 struct dwarf2_section_info abbrev
;
767 struct dwarf2_section_info line
;
768 struct dwarf2_section_info loc
;
769 struct dwarf2_section_info macinfo
;
770 struct dwarf2_section_info macro
;
771 struct dwarf2_section_info str_offsets
;
772 /* Each DWP hash table entry records one CU or one TU.
773 That is recorded here, and copied to dwo_unit.section. */
774 struct dwarf2_section_info info_or_types
;
777 /* Similar to virtual_v1_dwo_sections, but for DWP version 2.
778 In version 2, the sections of the DWO files are concatenated together
779 and stored in one section of that name. Thus each ELF section contains
780 several "virtual" sections. */
782 struct virtual_v2_dwo_sections
784 bfd_size_type abbrev_offset
;
785 bfd_size_type abbrev_size
;
787 bfd_size_type line_offset
;
788 bfd_size_type line_size
;
790 bfd_size_type loc_offset
;
791 bfd_size_type loc_size
;
793 bfd_size_type macinfo_offset
;
794 bfd_size_type macinfo_size
;
796 bfd_size_type macro_offset
;
797 bfd_size_type macro_size
;
799 bfd_size_type str_offsets_offset
;
800 bfd_size_type str_offsets_size
;
802 /* Each DWP hash table entry records one CU or one TU.
803 That is recorded here, and copied to dwo_unit.section. */
804 bfd_size_type info_or_types_offset
;
805 bfd_size_type info_or_types_size
;
808 /* Contents of DWP hash tables. */
810 struct dwp_hash_table
812 uint32_t version
, nr_columns
;
813 uint32_t nr_units
, nr_slots
;
814 const gdb_byte
*hash_table
, *unit_table
;
819 const gdb_byte
*indices
;
823 /* This is indexed by column number and gives the id of the section
825 #define MAX_NR_V2_DWO_SECTIONS \
826 (1 /* .debug_info or .debug_types */ \
827 + 1 /* .debug_abbrev */ \
828 + 1 /* .debug_line */ \
829 + 1 /* .debug_loc */ \
830 + 1 /* .debug_str_offsets */ \
831 + 1 /* .debug_macro or .debug_macinfo */)
832 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
833 const gdb_byte
*offsets
;
834 const gdb_byte
*sizes
;
839 /* Data for one DWP file. */
843 dwp_file (const char *name_
, gdb_bfd_ref_ptr
&&abfd
)
845 dbfd (std::move (abfd
))
849 /* Name of the file. */
852 /* File format version. */
856 gdb_bfd_ref_ptr dbfd
;
858 /* Section info for this file. */
859 struct dwp_sections sections
{};
861 /* Table of CUs in the file. */
862 const struct dwp_hash_table
*cus
= nullptr;
864 /* Table of TUs in the file. */
865 const struct dwp_hash_table
*tus
= nullptr;
867 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
868 htab_t loaded_cus
{};
869 htab_t loaded_tus
{};
871 /* Table to map ELF section numbers to their sections.
872 This is only needed for the DWP V1 file format. */
873 unsigned int num_sections
= 0;
874 asection
**elf_sections
= nullptr;
878 typedef std::unique_ptr
<struct abbrev_table
> abbrev_table_up
;
880 /* Struct used to pass misc. parameters to read_die_and_children, et
881 al. which are used for both .debug_info and .debug_types dies.
882 All parameters here are unchanging for the life of the call. This
883 struct exists to abstract away the constant parameters of die reading. */
885 struct die_reader_specs
887 /* The bfd of die_section. */
890 /* The CU of the DIE we are parsing. */
891 struct dwarf2_cu
*cu
;
893 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
894 struct dwo_file
*dwo_file
;
896 /* The section the die comes from.
897 This is either .debug_info or .debug_types, or the .dwo variants. */
898 struct dwarf2_section_info
*die_section
;
900 /* die_section->buffer. */
901 const gdb_byte
*buffer
;
903 /* The end of the buffer. */
904 const gdb_byte
*buffer_end
;
906 /* The value of the DW_AT_comp_dir attribute. */
907 const char *comp_dir
;
909 /* The abbreviation table to use when reading the DIEs. */
910 struct abbrev_table
*abbrev_table
;
913 /* A subclass of die_reader_specs that holds storage and has complex
914 constructor and destructor behavior. */
916 class cutu_reader
: public die_reader_specs
920 cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
921 struct abbrev_table
*abbrev_table
,
922 int use_existing_cu
, int keep
,
925 explicit cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
926 struct dwarf2_cu
*parent_cu
= nullptr,
927 struct dwo_file
*dwo_file
= nullptr);
931 DISABLE_COPY_AND_ASSIGN (cutu_reader
);
933 const gdb_byte
*info_ptr
= nullptr;
934 struct die_info
*comp_unit_die
= nullptr;
935 int has_children
= 0;
936 bool dummy_p
= false;
939 void init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
940 int use_existing_cu
, int keep
);
942 struct dwarf2_per_cu_data
*m_this_cu
;
944 std::unique_ptr
<dwarf2_cu
> m_new_cu
;
946 /* The ordinary abbreviation table. */
947 abbrev_table_up m_abbrev_table_holder
;
949 /* The DWO abbreviation table. */
950 abbrev_table_up m_dwo_abbrev_table
;
953 /* dir_index is 1-based in DWARF 4 and before, and is 0-based in DWARF 5 and
955 typedef int dir_index
;
957 /* file_name_index is 1-based in DWARF 4 and before, and is 0-based in DWARF 5
959 typedef int file_name_index
;
963 file_entry () = default;
965 file_entry (const char *name_
, dir_index d_index_
,
966 unsigned int mod_time_
, unsigned int length_
)
969 mod_time (mod_time_
),
973 /* Return the include directory at D_INDEX stored in LH. Returns
974 NULL if D_INDEX is out of bounds. */
975 const char *include_dir (const line_header
*lh
) const;
977 /* The file name. Note this is an observing pointer. The memory is
978 owned by debug_line_buffer. */
981 /* The directory index (1-based). */
982 dir_index d_index
{};
984 unsigned int mod_time
{};
986 unsigned int length
{};
988 /* True if referenced by the Line Number Program. */
991 /* The associated symbol table, if any. */
992 struct symtab
*symtab
{};
995 /* The line number information for a compilation unit (found in the
996 .debug_line section) begins with a "statement program header",
997 which contains the following information. */
1004 /* Add an entry to the include directory table. */
1005 void add_include_dir (const char *include_dir
);
1007 /* Add an entry to the file name table. */
1008 void add_file_name (const char *name
, dir_index d_index
,
1009 unsigned int mod_time
, unsigned int length
);
1011 /* Return the include dir at INDEX (0-based in DWARF 5 and 1-based before).
1012 Returns NULL if INDEX is out of bounds. */
1013 const char *include_dir_at (dir_index index
) const
1019 vec_index
= index
- 1;
1020 if (vec_index
< 0 || vec_index
>= m_include_dirs
.size ())
1022 return m_include_dirs
[vec_index
];
1025 bool is_valid_file_index (int file_index
)
1028 return 0 <= file_index
&& file_index
< file_names_size ();
1029 return 1 <= file_index
&& file_index
<= file_names_size ();
1032 /* Return the file name at INDEX (0-based in DWARF 5 and 1-based before).
1033 Returns NULL if INDEX is out of bounds. */
1034 file_entry
*file_name_at (file_name_index index
)
1040 vec_index
= index
- 1;
1041 if (vec_index
< 0 || vec_index
>= m_file_names
.size ())
1043 return &m_file_names
[vec_index
];
1046 /* The indexes are 0-based in DWARF 5 and 1-based in DWARF 4. Therefore,
1047 this method should only be used to iterate through all file entries in an
1048 index-agnostic manner. */
1049 std::vector
<file_entry
> &file_names ()
1050 { return m_file_names
; }
1052 /* Offset of line number information in .debug_line section. */
1053 sect_offset sect_off
{};
1055 /* OFFSET is for struct dwz_file associated with dwarf2_per_objfile. */
1056 unsigned offset_in_dwz
: 1; /* Can't initialize bitfields in-class. */
1058 unsigned int total_length
{};
1059 unsigned short version
{};
1060 unsigned int header_length
{};
1061 unsigned char minimum_instruction_length
{};
1062 unsigned char maximum_ops_per_instruction
{};
1063 unsigned char default_is_stmt
{};
1065 unsigned char line_range
{};
1066 unsigned char opcode_base
{};
1068 /* standard_opcode_lengths[i] is the number of operands for the
1069 standard opcode whose value is i. This means that
1070 standard_opcode_lengths[0] is unused, and the last meaningful
1071 element is standard_opcode_lengths[opcode_base - 1]. */
1072 std::unique_ptr
<unsigned char[]> standard_opcode_lengths
;
1074 int file_names_size ()
1075 { return m_file_names
.size(); }
1077 /* The start and end of the statement program following this
1078 header. These point into dwarf2_per_objfile->line_buffer. */
1079 const gdb_byte
*statement_program_start
{}, *statement_program_end
{};
1082 /* The include_directories table. Note these are observing
1083 pointers. The memory is owned by debug_line_buffer. */
1084 std::vector
<const char *> m_include_dirs
;
1086 /* The file_names table. This is private because the meaning of indexes
1087 differs among DWARF versions (The first valid index is 1 in DWARF 4 and
1088 before, and is 0 in DWARF 5 and later). So the client should use
1089 file_name_at method for access. */
1090 std::vector
<file_entry
> m_file_names
;
1093 typedef std::unique_ptr
<line_header
> line_header_up
;
1096 file_entry::include_dir (const line_header
*lh
) const
1098 return lh
->include_dir_at (d_index
);
1101 /* When we construct a partial symbol table entry we only
1102 need this much information. */
1103 struct partial_die_info
: public allocate_on_obstack
1105 partial_die_info (sect_offset sect_off
, struct abbrev_info
*abbrev
);
1107 /* Disable assign but still keep copy ctor, which is needed
1108 load_partial_dies. */
1109 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
1111 /* Adjust the partial die before generating a symbol for it. This
1112 function may set the is_external flag or change the DIE's
1114 void fixup (struct dwarf2_cu
*cu
);
1116 /* Read a minimal amount of information into the minimal die
1118 const gdb_byte
*read (const struct die_reader_specs
*reader
,
1119 const struct abbrev_info
&abbrev
,
1120 const gdb_byte
*info_ptr
);
1122 /* Offset of this DIE. */
1123 const sect_offset sect_off
;
1125 /* DWARF-2 tag for this DIE. */
1126 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1128 /* Assorted flags describing the data found in this DIE. */
1129 const unsigned int has_children
: 1;
1131 unsigned int is_external
: 1;
1132 unsigned int is_declaration
: 1;
1133 unsigned int has_type
: 1;
1134 unsigned int has_specification
: 1;
1135 unsigned int has_pc_info
: 1;
1136 unsigned int may_be_inlined
: 1;
1138 /* This DIE has been marked DW_AT_main_subprogram. */
1139 unsigned int main_subprogram
: 1;
1141 /* Flag set if the SCOPE field of this structure has been
1143 unsigned int scope_set
: 1;
1145 /* Flag set if the DIE has a byte_size attribute. */
1146 unsigned int has_byte_size
: 1;
1148 /* Flag set if the DIE has a DW_AT_const_value attribute. */
1149 unsigned int has_const_value
: 1;
1151 /* Flag set if any of the DIE's children are template arguments. */
1152 unsigned int has_template_arguments
: 1;
1154 /* Flag set if fixup has been called on this die. */
1155 unsigned int fixup_called
: 1;
1157 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1158 unsigned int is_dwz
: 1;
1160 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1161 unsigned int spec_is_dwz
: 1;
1163 /* The name of this DIE. Normally the value of DW_AT_name, but
1164 sometimes a default name for unnamed DIEs. */
1165 const char *name
= nullptr;
1167 /* The linkage name, if present. */
1168 const char *linkage_name
= nullptr;
1170 /* The scope to prepend to our children. This is generally
1171 allocated on the comp_unit_obstack, so will disappear
1172 when this compilation unit leaves the cache. */
1173 const char *scope
= nullptr;
1175 /* Some data associated with the partial DIE. The tag determines
1176 which field is live. */
1179 /* The location description associated with this DIE, if any. */
1180 struct dwarf_block
*locdesc
;
1181 /* The offset of an import, for DW_TAG_imported_unit. */
1182 sect_offset sect_off
;
1185 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1186 CORE_ADDR lowpc
= 0;
1187 CORE_ADDR highpc
= 0;
1189 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1190 DW_AT_sibling, if any. */
1191 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1192 could return DW_AT_sibling values to its caller load_partial_dies. */
1193 const gdb_byte
*sibling
= nullptr;
1195 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1196 DW_AT_specification (or DW_AT_abstract_origin or
1197 DW_AT_extension). */
1198 sect_offset spec_offset
{};
1200 /* Pointers to this DIE's parent, first child, and next sibling,
1202 struct partial_die_info
*die_parent
= nullptr;
1203 struct partial_die_info
*die_child
= nullptr;
1204 struct partial_die_info
*die_sibling
= nullptr;
1206 friend struct partial_die_info
*
1207 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1210 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1211 partial_die_info (sect_offset sect_off
)
1212 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1216 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1218 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1223 has_specification
= 0;
1226 main_subprogram
= 0;
1229 has_const_value
= 0;
1230 has_template_arguments
= 0;
1237 /* This data structure holds the information of an abbrev. */
1240 unsigned int number
; /* number identifying abbrev */
1241 enum dwarf_tag tag
; /* dwarf tag */
1242 unsigned short has_children
; /* boolean */
1243 unsigned short num_attrs
; /* number of attributes */
1244 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
1245 struct abbrev_info
*next
; /* next in chain */
1250 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1251 ENUM_BITFIELD(dwarf_form
) form
: 16;
1253 /* It is valid only if FORM is DW_FORM_implicit_const. */
1254 LONGEST implicit_const
;
1257 /* Size of abbrev_table.abbrev_hash_table. */
1258 #define ABBREV_HASH_SIZE 121
1260 /* Top level data structure to contain an abbreviation table. */
1264 explicit abbrev_table (sect_offset off
)
1268 XOBNEWVEC (&abbrev_obstack
, struct abbrev_info
*, ABBREV_HASH_SIZE
);
1269 memset (m_abbrevs
, 0, ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
1272 DISABLE_COPY_AND_ASSIGN (abbrev_table
);
1274 /* Allocate space for a struct abbrev_info object in
1276 struct abbrev_info
*alloc_abbrev ();
1278 /* Add an abbreviation to the table. */
1279 void add_abbrev (unsigned int abbrev_number
, struct abbrev_info
*abbrev
);
1281 /* Look up an abbrev in the table.
1282 Returns NULL if the abbrev is not found. */
1284 struct abbrev_info
*lookup_abbrev (unsigned int abbrev_number
);
1287 /* Where the abbrev table came from.
1288 This is used as a sanity check when the table is used. */
1289 const sect_offset sect_off
;
1291 /* Storage for the abbrev table. */
1292 auto_obstack abbrev_obstack
;
1296 /* Hash table of abbrevs.
1297 This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack.
1298 It could be statically allocated, but the previous code didn't so we
1300 struct abbrev_info
**m_abbrevs
;
1303 /* Attributes have a name and a value. */
1306 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1307 ENUM_BITFIELD(dwarf_form
) form
: 15;
1309 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
1310 field should be in u.str (existing only for DW_STRING) but it is kept
1311 here for better struct attribute alignment. */
1312 unsigned int string_is_canonical
: 1;
1317 struct dwarf_block
*blk
;
1326 /* This data structure holds a complete die structure. */
1329 /* DWARF-2 tag for this DIE. */
1330 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1332 /* Number of attributes */
1333 unsigned char num_attrs
;
1335 /* True if we're presently building the full type name for the
1336 type derived from this DIE. */
1337 unsigned char building_fullname
: 1;
1339 /* True if this die is in process. PR 16581. */
1340 unsigned char in_process
: 1;
1343 unsigned int abbrev
;
1345 /* Offset in .debug_info or .debug_types section. */
1346 sect_offset sect_off
;
1348 /* The dies in a compilation unit form an n-ary tree. PARENT
1349 points to this die's parent; CHILD points to the first child of
1350 this node; and all the children of a given node are chained
1351 together via their SIBLING fields. */
1352 struct die_info
*child
; /* Its first child, if any. */
1353 struct die_info
*sibling
; /* Its next sibling, if any. */
1354 struct die_info
*parent
; /* Its parent, if any. */
1356 /* An array of attributes, with NUM_ATTRS elements. There may be
1357 zero, but it's not common and zero-sized arrays are not
1358 sufficiently portable C. */
1359 struct attribute attrs
[1];
1362 /* Get at parts of an attribute structure. */
1364 #define DW_STRING(attr) ((attr)->u.str)
1365 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
1366 #define DW_UNSND(attr) ((attr)->u.unsnd)
1367 #define DW_BLOCK(attr) ((attr)->u.blk)
1368 #define DW_SND(attr) ((attr)->u.snd)
1369 #define DW_ADDR(attr) ((attr)->u.addr)
1370 #define DW_SIGNATURE(attr) ((attr)->u.signature)
1372 /* Blocks are a bunch of untyped bytes. */
1377 /* Valid only if SIZE is not zero. */
1378 const gdb_byte
*data
;
1381 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1382 but this would require a corresponding change in unpack_field_as_long
1384 static int bits_per_byte
= 8;
1386 /* When reading a variant or variant part, we track a bit more
1387 information about the field, and store it in an object of this
1390 struct variant_field
1392 /* If we see a DW_TAG_variant, then this will be the discriminant
1394 ULONGEST discriminant_value
;
1395 /* If we see a DW_TAG_variant, then this will be set if this is the
1397 bool default_branch
;
1398 /* While reading a DW_TAG_variant_part, this will be set if this
1399 field is the discriminant. */
1400 bool is_discriminant
;
1405 int accessibility
= 0;
1407 /* Extra information to describe a variant or variant part. */
1408 struct variant_field variant
{};
1409 struct field field
{};
1414 const char *name
= nullptr;
1415 std::vector
<struct fn_field
> fnfields
;
1418 /* The routines that read and process dies for a C struct or C++ class
1419 pass lists of data member fields and lists of member function fields
1420 in an instance of a field_info structure, as defined below. */
1423 /* List of data member and baseclasses fields. */
1424 std::vector
<struct nextfield
> fields
;
1425 std::vector
<struct nextfield
> baseclasses
;
1427 /* Number of fields (including baseclasses). */
1430 /* Set if the accessibility of one of the fields is not public. */
1431 int non_public_fields
= 0;
1433 /* Member function fieldlist array, contains name of possibly overloaded
1434 member function, number of overloaded member functions and a pointer
1435 to the head of the member function field chain. */
1436 std::vector
<struct fnfieldlist
> fnfieldlists
;
1438 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1439 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1440 std::vector
<struct decl_field
> typedef_field_list
;
1442 /* Nested types defined by this class and the number of elements in this
1444 std::vector
<struct decl_field
> nested_types_list
;
1447 /* One item on the queue of compilation units to read in full symbols
1449 struct dwarf2_queue_item
1451 struct dwarf2_per_cu_data
*per_cu
;
1452 enum language pretend_language
;
1453 struct dwarf2_queue_item
*next
;
1456 /* The current queue. */
1457 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
1459 /* Loaded secondary compilation units are kept in memory until they
1460 have not been referenced for the processing of this many
1461 compilation units. Set this to zero to disable caching. Cache
1462 sizes of up to at least twenty will improve startup time for
1463 typical inter-CU-reference binaries, at an obvious memory cost. */
1464 static int dwarf_max_cache_age
= 5;
1466 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1467 struct cmd_list_element
*c
, const char *value
)
1469 fprintf_filtered (file
, _("The upper bound on the age of cached "
1470 "DWARF compilation units is %s.\n"),
1474 /* local function prototypes */
1476 static const char *get_section_name (const struct dwarf2_section_info
*);
1478 static const char *get_section_file_name (const struct dwarf2_section_info
*);
1480 static void dwarf2_find_base_address (struct die_info
*die
,
1481 struct dwarf2_cu
*cu
);
1483 static dwarf2_psymtab
*create_partial_symtab
1484 (struct dwarf2_per_cu_data
*per_cu
, const char *name
);
1486 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1487 const gdb_byte
*info_ptr
,
1488 struct die_info
*type_unit_die
,
1491 static void dwarf2_build_psymtabs_hard
1492 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1494 static void scan_partial_symbols (struct partial_die_info
*,
1495 CORE_ADDR
*, CORE_ADDR
*,
1496 int, struct dwarf2_cu
*);
1498 static void add_partial_symbol (struct partial_die_info
*,
1499 struct dwarf2_cu
*);
1501 static void add_partial_namespace (struct partial_die_info
*pdi
,
1502 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1503 int set_addrmap
, struct dwarf2_cu
*cu
);
1505 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1506 CORE_ADDR
*highpc
, int set_addrmap
,
1507 struct dwarf2_cu
*cu
);
1509 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1510 struct dwarf2_cu
*cu
);
1512 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1513 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1514 int need_pc
, struct dwarf2_cu
*cu
);
1516 static abbrev_table_up abbrev_table_read_table
1517 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, struct dwarf2_section_info
*,
1520 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1522 static struct partial_die_info
*load_partial_dies
1523 (const struct die_reader_specs
*, const gdb_byte
*, int);
1525 /* A pair of partial_die_info and compilation unit. */
1526 struct cu_partial_die_info
1528 /* The compilation unit of the partial_die_info. */
1529 struct dwarf2_cu
*cu
;
1530 /* A partial_die_info. */
1531 struct partial_die_info
*pdi
;
1533 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1539 cu_partial_die_info () = delete;
1542 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1543 struct dwarf2_cu
*);
1545 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1546 struct attribute
*, struct attr_abbrev
*,
1547 const gdb_byte
*, bool *need_reprocess
);
1549 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1550 struct attribute
*attr
);
1552 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1554 static unsigned int read_1_byte (bfd
*, const gdb_byte
*);
1556 static int read_1_signed_byte (bfd
*, const gdb_byte
*);
1558 static unsigned int read_2_bytes (bfd
*, const gdb_byte
*);
1560 /* Read the next three bytes (little-endian order) as an unsigned integer. */
1561 static unsigned int read_3_bytes (bfd
*, const gdb_byte
*);
1563 static unsigned int read_4_bytes (bfd
*, const gdb_byte
*);
1565 static ULONGEST
read_8_bytes (bfd
*, const gdb_byte
*);
1567 static CORE_ADDR
read_address (bfd
*, const gdb_byte
*ptr
, struct dwarf2_cu
*,
1570 static LONGEST
read_initial_length (bfd
*, const gdb_byte
*, unsigned int *);
1572 static LONGEST read_checked_initial_length_and_offset
1573 (bfd
*, const gdb_byte
*, const struct comp_unit_head
*,
1574 unsigned int *, unsigned int *);
1576 static LONGEST
read_offset (bfd
*, const gdb_byte
*,
1577 const struct comp_unit_head
*,
1580 static LONGEST
read_offset_1 (bfd
*, const gdb_byte
*, unsigned int);
1582 static sect_offset read_abbrev_offset
1583 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1584 struct dwarf2_section_info
*, sect_offset
);
1586 static const gdb_byte
*read_n_bytes (bfd
*, const gdb_byte
*, unsigned int);
1588 static const char *read_direct_string (bfd
*, const gdb_byte
*, unsigned int *);
1590 static const char *read_indirect_string
1591 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1592 const struct comp_unit_head
*, unsigned int *);
1594 static const char *read_indirect_line_string
1595 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1596 const struct comp_unit_head
*, unsigned int *);
1598 static const char *read_indirect_string_at_offset
1599 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
1600 LONGEST str_offset
);
1602 static const char *read_indirect_string_from_dwz
1603 (struct objfile
*objfile
, struct dwz_file
*, LONGEST
);
1605 static LONGEST
read_signed_leb128 (bfd
*, const gdb_byte
*, unsigned int *);
1607 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1611 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1612 ULONGEST str_index
);
1614 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1615 ULONGEST str_index
);
1617 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1619 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1620 struct dwarf2_cu
*);
1622 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1625 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1626 struct dwarf2_cu
*cu
);
1628 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1630 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1631 struct dwarf2_cu
*cu
);
1633 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1635 static struct die_info
*die_specification (struct die_info
*die
,
1636 struct dwarf2_cu
**);
1638 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1639 struct dwarf2_cu
*cu
);
1641 static void dwarf_decode_lines (struct line_header
*, const char *,
1642 struct dwarf2_cu
*, dwarf2_psymtab
*,
1643 CORE_ADDR
, int decode_mapping
);
1645 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1648 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1649 struct dwarf2_cu
*, struct symbol
* = NULL
);
1651 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1652 struct dwarf2_cu
*);
1654 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1657 struct obstack
*obstack
,
1658 struct dwarf2_cu
*cu
, LONGEST
*value
,
1659 const gdb_byte
**bytes
,
1660 struct dwarf2_locexpr_baton
**baton
);
1662 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1664 static int need_gnat_info (struct dwarf2_cu
*);
1666 static struct type
*die_descriptive_type (struct die_info
*,
1667 struct dwarf2_cu
*);
1669 static void set_descriptive_type (struct type
*, struct die_info
*,
1670 struct dwarf2_cu
*);
1672 static struct type
*die_containing_type (struct die_info
*,
1673 struct dwarf2_cu
*);
1675 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1676 struct dwarf2_cu
*);
1678 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1680 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1682 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1684 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1685 const char *suffix
, int physname
,
1686 struct dwarf2_cu
*cu
);
1688 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1690 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1692 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1694 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1696 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1698 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1700 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1701 struct dwarf2_cu
*, dwarf2_psymtab
*);
1703 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1704 values. Keep the items ordered with increasing constraints compliance. */
1707 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1708 PC_BOUNDS_NOT_PRESENT
,
1710 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1711 were present but they do not form a valid range of PC addresses. */
1714 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1717 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1721 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1722 CORE_ADDR
*, CORE_ADDR
*,
1726 static void get_scope_pc_bounds (struct die_info
*,
1727 CORE_ADDR
*, CORE_ADDR
*,
1728 struct dwarf2_cu
*);
1730 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1731 CORE_ADDR
, struct dwarf2_cu
*);
1733 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1734 struct dwarf2_cu
*);
1736 static void dwarf2_attach_fields_to_type (struct field_info
*,
1737 struct type
*, struct dwarf2_cu
*);
1739 static void dwarf2_add_member_fn (struct field_info
*,
1740 struct die_info
*, struct type
*,
1741 struct dwarf2_cu
*);
1743 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1745 struct dwarf2_cu
*);
1747 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1749 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1751 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1753 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1755 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1757 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1759 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1761 static struct type
*read_module_type (struct die_info
*die
,
1762 struct dwarf2_cu
*cu
);
1764 static const char *namespace_name (struct die_info
*die
,
1765 int *is_anonymous
, struct dwarf2_cu
*);
1767 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1769 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1771 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1772 struct dwarf2_cu
*);
1774 static struct die_info
*read_die_and_siblings_1
1775 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1778 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1779 const gdb_byte
*info_ptr
,
1780 const gdb_byte
**new_info_ptr
,
1781 struct die_info
*parent
);
1783 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1784 struct die_info
**, const gdb_byte
*,
1787 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1788 struct die_info
**, const gdb_byte
*,
1791 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1793 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1796 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1798 static const char *dwarf2_full_name (const char *name
,
1799 struct die_info
*die
,
1800 struct dwarf2_cu
*cu
);
1802 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1803 struct dwarf2_cu
*cu
);
1805 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1806 struct dwarf2_cu
**);
1808 static const char *dwarf_tag_name (unsigned int);
1810 static const char *dwarf_attr_name (unsigned int);
1812 static const char *dwarf_unit_type_name (int unit_type
);
1814 static const char *dwarf_form_name (unsigned int);
1816 static const char *dwarf_bool_name (unsigned int);
1818 static const char *dwarf_type_encoding_name (unsigned int);
1820 static struct die_info
*sibling_die (struct die_info
*);
1822 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1824 static void dump_die_for_error (struct die_info
*);
1826 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1829 /*static*/ void dump_die (struct die_info
*, int max_level
);
1831 static void store_in_ref_table (struct die_info
*,
1832 struct dwarf2_cu
*);
1834 static sect_offset
dwarf2_get_ref_die_offset (const struct attribute
*);
1836 static LONGEST
dwarf2_get_attr_constant_value (const struct attribute
*, int);
1838 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1839 const struct attribute
*,
1840 struct dwarf2_cu
**);
1842 static struct die_info
*follow_die_ref (struct die_info
*,
1843 const struct attribute
*,
1844 struct dwarf2_cu
**);
1846 static struct die_info
*follow_die_sig (struct die_info
*,
1847 const struct attribute
*,
1848 struct dwarf2_cu
**);
1850 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1851 struct dwarf2_cu
*);
1853 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1854 const struct attribute
*,
1855 struct dwarf2_cu
*);
1857 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1859 static void read_signatured_type (struct signatured_type
*);
1861 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1862 struct die_info
*die
, struct dwarf2_cu
*cu
,
1863 struct dynamic_prop
*prop
, struct type
*type
);
1865 /* memory allocation interface */
1867 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1869 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1871 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1873 static int attr_form_is_block (const struct attribute
*);
1875 static int attr_form_is_section_offset (const struct attribute
*);
1877 static int attr_form_is_constant (const struct attribute
*);
1879 static int attr_form_is_ref (const struct attribute
*);
1881 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1882 struct dwarf2_loclist_baton
*baton
,
1883 const struct attribute
*attr
);
1885 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1887 struct dwarf2_cu
*cu
,
1890 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1891 const gdb_byte
*info_ptr
,
1892 struct abbrev_info
*abbrev
);
1894 static hashval_t
partial_die_hash (const void *item
);
1896 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1898 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1899 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1900 struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1902 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1903 struct die_info
*comp_unit_die
,
1904 enum language pretend_language
);
1906 static void age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1908 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1910 static struct type
*set_die_type (struct die_info
*, struct type
*,
1911 struct dwarf2_cu
*);
1913 static void create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1915 static int create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1917 static void load_full_comp_unit (struct dwarf2_per_cu_data
*, bool,
1920 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1923 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1926 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1927 struct dwarf2_per_cu_data
*);
1929 static void dwarf2_mark (struct dwarf2_cu
*);
1931 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1933 static struct type
*get_die_type_at_offset (sect_offset
,
1934 struct dwarf2_per_cu_data
*);
1936 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1938 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1939 enum language pretend_language
);
1941 static void process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1943 static struct type
*dwarf2_per_cu_addr_type (struct dwarf2_per_cu_data
*per_cu
);
1944 static struct type
*dwarf2_per_cu_addr_sized_int_type
1945 (struct dwarf2_per_cu_data
*per_cu
, bool unsigned_p
);
1946 static struct type
*dwarf2_per_cu_int_type
1947 (struct dwarf2_per_cu_data
*per_cu
, int size_in_bytes
,
1950 /* Class, the destructor of which frees all allocated queue entries. This
1951 will only have work to do if an error was thrown while processing the
1952 dwarf. If no error was thrown then the queue entries should have all
1953 been processed, and freed, as we went along. */
1955 class dwarf2_queue_guard
1958 dwarf2_queue_guard () = default;
1960 /* Free any entries remaining on the queue. There should only be
1961 entries left if we hit an error while processing the dwarf. */
1962 ~dwarf2_queue_guard ()
1964 struct dwarf2_queue_item
*item
, *last
;
1966 item
= dwarf2_queue
;
1969 /* Anything still marked queued is likely to be in an
1970 inconsistent state, so discard it. */
1971 if (item
->per_cu
->queued
)
1973 if (item
->per_cu
->cu
!= NULL
)
1974 free_one_cached_comp_unit (item
->per_cu
);
1975 item
->per_cu
->queued
= 0;
1983 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
1987 /* The return type of find_file_and_directory. Note, the enclosed
1988 string pointers are only valid while this object is valid. */
1990 struct file_and_directory
1992 /* The filename. This is never NULL. */
1995 /* The compilation directory. NULL if not known. If we needed to
1996 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1997 points directly to the DW_AT_comp_dir string attribute owned by
1998 the obstack that owns the DIE. */
1999 const char *comp_dir
;
2001 /* If we needed to build a new string for comp_dir, this is what
2002 owns the storage. */
2003 std::string comp_dir_storage
;
2006 static file_and_directory
find_file_and_directory (struct die_info
*die
,
2007 struct dwarf2_cu
*cu
);
2009 static char *file_full_name (int file
, struct line_header
*lh
,
2010 const char *comp_dir
);
2012 /* Expected enum dwarf_unit_type for read_comp_unit_head. */
2013 enum class rcuh_kind
{ COMPILE
, TYPE
};
2015 static const gdb_byte
*read_and_check_comp_unit_head
2016 (struct dwarf2_per_objfile
* dwarf2_per_objfile
,
2017 struct comp_unit_head
*header
,
2018 struct dwarf2_section_info
*section
,
2019 struct dwarf2_section_info
*abbrev_section
, const gdb_byte
*info_ptr
,
2020 rcuh_kind section_kind
);
2022 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
2024 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
2026 static struct dwo_unit
*lookup_dwo_unit_in_dwp
2027 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2028 struct dwp_file
*dwp_file
, const char *comp_dir
,
2029 ULONGEST signature
, int is_debug_types
);
2031 static struct dwp_file
*get_dwp_file
2032 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2034 static struct dwo_unit
*lookup_dwo_comp_unit
2035 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
2037 static struct dwo_unit
*lookup_dwo_type_unit
2038 (struct signatured_type
*, const char *, const char *);
2040 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
2042 /* A unique pointer to a dwo_file. */
2044 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
2046 static void process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2048 static void check_producer (struct dwarf2_cu
*cu
);
2050 static void free_line_header_voidp (void *arg
);
2052 /* Various complaints about symbol reading that don't abort the process. */
2055 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
2057 complaint (_("statement list doesn't fit in .debug_line section"));
2061 dwarf2_debug_line_missing_file_complaint (void)
2063 complaint (_(".debug_line section has line data without a file"));
2067 dwarf2_debug_line_missing_end_sequence_complaint (void)
2069 complaint (_(".debug_line section has line "
2070 "program sequence without an end"));
2074 dwarf2_complex_location_expr_complaint (void)
2076 complaint (_("location expression too complex"));
2080 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
2083 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
2088 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
2090 complaint (_("debug info runs off end of %s section"
2092 get_section_name (section
),
2093 get_section_file_name (section
));
2097 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
2099 complaint (_("macro debug info contains a "
2100 "malformed macro definition:\n`%s'"),
2105 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
2107 complaint (_("invalid attribute class or form for '%s' in '%s'"),
2111 /* Hash function for line_header_hash. */
2114 line_header_hash (const struct line_header
*ofs
)
2116 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
2119 /* Hash function for htab_create_alloc_ex for line_header_hash. */
2122 line_header_hash_voidp (const void *item
)
2124 const struct line_header
*ofs
= (const struct line_header
*) item
;
2126 return line_header_hash (ofs
);
2129 /* Equality function for line_header_hash. */
2132 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
2134 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
2135 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
2137 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
2138 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
2143 /* Read the given attribute value as an address, taking the attribute's
2144 form into account. */
2147 attr_value_as_address (struct attribute
*attr
)
2151 if (attr
->form
!= DW_FORM_addr
&& attr
->form
!= DW_FORM_addrx
2152 && attr
->form
!= DW_FORM_GNU_addr_index
)
2154 /* Aside from a few clearly defined exceptions, attributes that
2155 contain an address must always be in DW_FORM_addr form.
2156 Unfortunately, some compilers happen to be violating this
2157 requirement by encoding addresses using other forms, such
2158 as DW_FORM_data4 for example. For those broken compilers,
2159 we try to do our best, without any guarantee of success,
2160 to interpret the address correctly. It would also be nice
2161 to generate a complaint, but that would require us to maintain
2162 a list of legitimate cases where a non-address form is allowed,
2163 as well as update callers to pass in at least the CU's DWARF
2164 version. This is more overhead than what we're willing to
2165 expand for a pretty rare case. */
2166 addr
= DW_UNSND (attr
);
2169 addr
= DW_ADDR (attr
);
2174 /* See declaration. */
2176 dwarf2_per_objfile::dwarf2_per_objfile (struct objfile
*objfile_
,
2177 const dwarf2_debug_sections
*names
,
2179 : objfile (objfile_
),
2180 can_copy (can_copy_
)
2183 names
= &dwarf2_elf_names
;
2185 bfd
*obfd
= objfile
->obfd
;
2187 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
2188 locate_sections (obfd
, sec
, *names
);
2191 dwarf2_per_objfile::~dwarf2_per_objfile ()
2193 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
2194 free_cached_comp_units ();
2196 if (quick_file_names_table
)
2197 htab_delete (quick_file_names_table
);
2199 if (line_header_hash
)
2200 htab_delete (line_header_hash
);
2202 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
2203 per_cu
->imported_symtabs_free ();
2205 for (signatured_type
*sig_type
: all_type_units
)
2206 sig_type
->per_cu
.imported_symtabs_free ();
2208 /* Everything else should be on the objfile obstack. */
2211 /* See declaration. */
2214 dwarf2_per_objfile::free_cached_comp_units ()
2216 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
2217 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
2218 while (per_cu
!= NULL
)
2220 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
2223 *last_chain
= next_cu
;
2228 /* A helper class that calls free_cached_comp_units on
2231 class free_cached_comp_units
2235 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
2236 : m_per_objfile (per_objfile
)
2240 ~free_cached_comp_units ()
2242 m_per_objfile
->free_cached_comp_units ();
2245 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
2249 dwarf2_per_objfile
*m_per_objfile
;
2252 /* Try to locate the sections we need for DWARF 2 debugging
2253 information and return true if we have enough to do something.
2254 NAMES points to the dwarf2 section names, or is NULL if the standard
2255 ELF names are used. CAN_COPY is true for formats where symbol
2256 interposition is possible and so symbol values must follow copy
2257 relocation rules. */
2260 dwarf2_has_info (struct objfile
*objfile
,
2261 const struct dwarf2_debug_sections
*names
,
2264 if (objfile
->flags
& OBJF_READNEVER
)
2267 struct dwarf2_per_objfile
*dwarf2_per_objfile
2268 = get_dwarf2_per_objfile (objfile
);
2270 if (dwarf2_per_objfile
== NULL
)
2271 dwarf2_per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
,
2275 return (!dwarf2_per_objfile
->info
.is_virtual
2276 && dwarf2_per_objfile
->info
.s
.section
!= NULL
2277 && !dwarf2_per_objfile
->abbrev
.is_virtual
2278 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
2281 /* Return the containing section of virtual section SECTION. */
2283 static struct dwarf2_section_info
*
2284 get_containing_section (const struct dwarf2_section_info
*section
)
2286 gdb_assert (section
->is_virtual
);
2287 return section
->s
.containing_section
;
2290 /* Return the bfd owner of SECTION. */
2293 get_section_bfd_owner (const struct dwarf2_section_info
*section
)
2295 if (section
->is_virtual
)
2297 section
= get_containing_section (section
);
2298 gdb_assert (!section
->is_virtual
);
2300 return section
->s
.section
->owner
;
2303 /* Return the bfd section of SECTION.
2304 Returns NULL if the section is not present. */
2307 get_section_bfd_section (const struct dwarf2_section_info
*section
)
2309 if (section
->is_virtual
)
2311 section
= get_containing_section (section
);
2312 gdb_assert (!section
->is_virtual
);
2314 return section
->s
.section
;
2317 /* Return the name of SECTION. */
2320 get_section_name (const struct dwarf2_section_info
*section
)
2322 asection
*sectp
= get_section_bfd_section (section
);
2324 gdb_assert (sectp
!= NULL
);
2325 return bfd_section_name (sectp
);
2328 /* Return the name of the file SECTION is in. */
2331 get_section_file_name (const struct dwarf2_section_info
*section
)
2333 bfd
*abfd
= get_section_bfd_owner (section
);
2335 return bfd_get_filename (abfd
);
2338 /* Return the id of SECTION.
2339 Returns 0 if SECTION doesn't exist. */
2342 get_section_id (const struct dwarf2_section_info
*section
)
2344 asection
*sectp
= get_section_bfd_section (section
);
2351 /* Return the flags of SECTION.
2352 SECTION (or containing section if this is a virtual section) must exist. */
2355 get_section_flags (const struct dwarf2_section_info
*section
)
2357 asection
*sectp
= get_section_bfd_section (section
);
2359 gdb_assert (sectp
!= NULL
);
2360 return bfd_section_flags (sectp
);
2363 /* When loading sections, we look either for uncompressed section or for
2364 compressed section names. */
2367 section_is_p (const char *section_name
,
2368 const struct dwarf2_section_names
*names
)
2370 if (names
->normal
!= NULL
2371 && strcmp (section_name
, names
->normal
) == 0)
2373 if (names
->compressed
!= NULL
2374 && strcmp (section_name
, names
->compressed
) == 0)
2379 /* See declaration. */
2382 dwarf2_per_objfile::locate_sections (bfd
*abfd
, asection
*sectp
,
2383 const dwarf2_debug_sections
&names
)
2385 flagword aflag
= bfd_section_flags (sectp
);
2387 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
2390 else if (elf_section_data (sectp
)->this_hdr
.sh_size
2391 > bfd_get_file_size (abfd
))
2393 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
2394 warning (_("Discarding section %s which has a section size (%s"
2395 ") larger than the file size [in module %s]"),
2396 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
2397 bfd_get_filename (abfd
));
2399 else if (section_is_p (sectp
->name
, &names
.info
))
2401 this->info
.s
.section
= sectp
;
2402 this->info
.size
= bfd_section_size (sectp
);
2404 else if (section_is_p (sectp
->name
, &names
.abbrev
))
2406 this->abbrev
.s
.section
= sectp
;
2407 this->abbrev
.size
= bfd_section_size (sectp
);
2409 else if (section_is_p (sectp
->name
, &names
.line
))
2411 this->line
.s
.section
= sectp
;
2412 this->line
.size
= bfd_section_size (sectp
);
2414 else if (section_is_p (sectp
->name
, &names
.loc
))
2416 this->loc
.s
.section
= sectp
;
2417 this->loc
.size
= bfd_section_size (sectp
);
2419 else if (section_is_p (sectp
->name
, &names
.loclists
))
2421 this->loclists
.s
.section
= sectp
;
2422 this->loclists
.size
= bfd_section_size (sectp
);
2424 else if (section_is_p (sectp
->name
, &names
.macinfo
))
2426 this->macinfo
.s
.section
= sectp
;
2427 this->macinfo
.size
= bfd_section_size (sectp
);
2429 else if (section_is_p (sectp
->name
, &names
.macro
))
2431 this->macro
.s
.section
= sectp
;
2432 this->macro
.size
= bfd_section_size (sectp
);
2434 else if (section_is_p (sectp
->name
, &names
.str
))
2436 this->str
.s
.section
= sectp
;
2437 this->str
.size
= bfd_section_size (sectp
);
2439 else if (section_is_p (sectp
->name
, &names
.str_offsets
))
2441 this->str_offsets
.s
.section
= sectp
;
2442 this->str_offsets
.size
= bfd_section_size (sectp
);
2444 else if (section_is_p (sectp
->name
, &names
.line_str
))
2446 this->line_str
.s
.section
= sectp
;
2447 this->line_str
.size
= bfd_section_size (sectp
);
2449 else if (section_is_p (sectp
->name
, &names
.addr
))
2451 this->addr
.s
.section
= sectp
;
2452 this->addr
.size
= bfd_section_size (sectp
);
2454 else if (section_is_p (sectp
->name
, &names
.frame
))
2456 this->frame
.s
.section
= sectp
;
2457 this->frame
.size
= bfd_section_size (sectp
);
2459 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
2461 this->eh_frame
.s
.section
= sectp
;
2462 this->eh_frame
.size
= bfd_section_size (sectp
);
2464 else if (section_is_p (sectp
->name
, &names
.ranges
))
2466 this->ranges
.s
.section
= sectp
;
2467 this->ranges
.size
= bfd_section_size (sectp
);
2469 else if (section_is_p (sectp
->name
, &names
.rnglists
))
2471 this->rnglists
.s
.section
= sectp
;
2472 this->rnglists
.size
= bfd_section_size (sectp
);
2474 else if (section_is_p (sectp
->name
, &names
.types
))
2476 struct dwarf2_section_info type_section
;
2478 memset (&type_section
, 0, sizeof (type_section
));
2479 type_section
.s
.section
= sectp
;
2480 type_section
.size
= bfd_section_size (sectp
);
2482 this->types
.push_back (type_section
);
2484 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
2486 this->gdb_index
.s
.section
= sectp
;
2487 this->gdb_index
.size
= bfd_section_size (sectp
);
2489 else if (section_is_p (sectp
->name
, &names
.debug_names
))
2491 this->debug_names
.s
.section
= sectp
;
2492 this->debug_names
.size
= bfd_section_size (sectp
);
2494 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
2496 this->debug_aranges
.s
.section
= sectp
;
2497 this->debug_aranges
.size
= bfd_section_size (sectp
);
2500 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2501 && bfd_section_vma (sectp
) == 0)
2502 this->has_section_at_zero
= true;
2505 /* A helper function that decides whether a section is empty,
2509 dwarf2_section_empty_p (const struct dwarf2_section_info
*section
)
2511 if (section
->is_virtual
)
2512 return section
->size
== 0;
2513 return section
->s
.section
== NULL
|| section
->size
== 0;
2516 /* See dwarf2read.h. */
2519 dwarf2_read_section (struct objfile
*objfile
, dwarf2_section_info
*info
)
2523 gdb_byte
*buf
, *retbuf
;
2527 info
->buffer
= NULL
;
2528 info
->readin
= true;
2530 if (dwarf2_section_empty_p (info
))
2533 sectp
= get_section_bfd_section (info
);
2535 /* If this is a virtual section we need to read in the real one first. */
2536 if (info
->is_virtual
)
2538 struct dwarf2_section_info
*containing_section
=
2539 get_containing_section (info
);
2541 gdb_assert (sectp
!= NULL
);
2542 if ((sectp
->flags
& SEC_RELOC
) != 0)
2544 error (_("Dwarf Error: DWP format V2 with relocations is not"
2545 " supported in section %s [in module %s]"),
2546 get_section_name (info
), get_section_file_name (info
));
2548 dwarf2_read_section (objfile
, containing_section
);
2549 /* Other code should have already caught virtual sections that don't
2551 gdb_assert (info
->virtual_offset
+ info
->size
2552 <= containing_section
->size
);
2553 /* If the real section is empty or there was a problem reading the
2554 section we shouldn't get here. */
2555 gdb_assert (containing_section
->buffer
!= NULL
);
2556 info
->buffer
= containing_section
->buffer
+ info
->virtual_offset
;
2560 /* If the section has relocations, we must read it ourselves.
2561 Otherwise we attach it to the BFD. */
2562 if ((sectp
->flags
& SEC_RELOC
) == 0)
2564 info
->buffer
= gdb_bfd_map_section (sectp
, &info
->size
);
2568 buf
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
2571 /* When debugging .o files, we may need to apply relocations; see
2572 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
2573 We never compress sections in .o files, so we only need to
2574 try this when the section is not compressed. */
2575 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
2578 info
->buffer
= retbuf
;
2582 abfd
= get_section_bfd_owner (info
);
2583 gdb_assert (abfd
!= NULL
);
2585 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
2586 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
2588 error (_("Dwarf Error: Can't read DWARF data"
2589 " in section %s [in module %s]"),
2590 bfd_section_name (sectp
), bfd_get_filename (abfd
));
2594 /* A helper function that returns the size of a section in a safe way.
2595 If you are positive that the section has been read before using the
2596 size, then it is safe to refer to the dwarf2_section_info object's
2597 "size" field directly. In other cases, you must call this
2598 function, because for compressed sections the size field is not set
2599 correctly until the section has been read. */
2601 static bfd_size_type
2602 dwarf2_section_size (struct objfile
*objfile
,
2603 struct dwarf2_section_info
*info
)
2606 dwarf2_read_section (objfile
, info
);
2610 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2614 dwarf2_get_section_info (struct objfile
*objfile
,
2615 enum dwarf2_section_enum sect
,
2616 asection
**sectp
, const gdb_byte
**bufp
,
2617 bfd_size_type
*sizep
)
2619 struct dwarf2_per_objfile
*data
= dwarf2_objfile_data_key
.get (objfile
);
2620 struct dwarf2_section_info
*info
;
2622 /* We may see an objfile without any DWARF, in which case we just
2633 case DWARF2_DEBUG_FRAME
:
2634 info
= &data
->frame
;
2636 case DWARF2_EH_FRAME
:
2637 info
= &data
->eh_frame
;
2640 gdb_assert_not_reached ("unexpected section");
2643 dwarf2_read_section (objfile
, info
);
2645 *sectp
= get_section_bfd_section (info
);
2646 *bufp
= info
->buffer
;
2647 *sizep
= info
->size
;
2650 /* A helper function to find the sections for a .dwz file. */
2653 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2655 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2657 /* Note that we only support the standard ELF names, because .dwz
2658 is ELF-only (at the time of writing). */
2659 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2661 dwz_file
->abbrev
.s
.section
= sectp
;
2662 dwz_file
->abbrev
.size
= bfd_section_size (sectp
);
2664 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2666 dwz_file
->info
.s
.section
= sectp
;
2667 dwz_file
->info
.size
= bfd_section_size (sectp
);
2669 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2671 dwz_file
->str
.s
.section
= sectp
;
2672 dwz_file
->str
.size
= bfd_section_size (sectp
);
2674 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2676 dwz_file
->line
.s
.section
= sectp
;
2677 dwz_file
->line
.size
= bfd_section_size (sectp
);
2679 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2681 dwz_file
->macro
.s
.section
= sectp
;
2682 dwz_file
->macro
.size
= bfd_section_size (sectp
);
2684 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2686 dwz_file
->gdb_index
.s
.section
= sectp
;
2687 dwz_file
->gdb_index
.size
= bfd_section_size (sectp
);
2689 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2691 dwz_file
->debug_names
.s
.section
= sectp
;
2692 dwz_file
->debug_names
.size
= bfd_section_size (sectp
);
2696 /* See dwarf2read.h. */
2699 dwarf2_get_dwz_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
2701 const char *filename
;
2702 bfd_size_type buildid_len_arg
;
2706 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2707 return dwarf2_per_objfile
->dwz_file
.get ();
2709 bfd_set_error (bfd_error_no_error
);
2710 gdb::unique_xmalloc_ptr
<char> data
2711 (bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2712 &buildid_len_arg
, &buildid
));
2715 if (bfd_get_error () == bfd_error_no_error
)
2717 error (_("could not read '.gnu_debugaltlink' section: %s"),
2718 bfd_errmsg (bfd_get_error ()));
2721 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2723 buildid_len
= (size_t) buildid_len_arg
;
2725 filename
= data
.get ();
2727 std::string abs_storage
;
2728 if (!IS_ABSOLUTE_PATH (filename
))
2730 gdb::unique_xmalloc_ptr
<char> abs
2731 = gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2733 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2734 filename
= abs_storage
.c_str ();
2737 /* First try the file name given in the section. If that doesn't
2738 work, try to use the build-id instead. */
2739 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
, -1));
2740 if (dwz_bfd
!= NULL
)
2742 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2743 dwz_bfd
.reset (nullptr);
2746 if (dwz_bfd
== NULL
)
2747 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2749 if (dwz_bfd
== NULL
)
2750 error (_("could not find '.gnu_debugaltlink' file for %s"),
2751 objfile_name (dwarf2_per_objfile
->objfile
));
2753 std::unique_ptr
<struct dwz_file
> result
2754 (new struct dwz_file (std::move (dwz_bfd
)));
2756 bfd_map_over_sections (result
->dwz_bfd
.get (), locate_dwz_sections
,
2759 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
,
2760 result
->dwz_bfd
.get ());
2761 dwarf2_per_objfile
->dwz_file
= std::move (result
);
2762 return dwarf2_per_objfile
->dwz_file
.get ();
2765 /* DWARF quick_symbols_functions support. */
2767 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2768 unique line tables, so we maintain a separate table of all .debug_line
2769 derived entries to support the sharing.
2770 All the quick functions need is the list of file names. We discard the
2771 line_header when we're done and don't need to record it here. */
2772 struct quick_file_names
2774 /* The data used to construct the hash key. */
2775 struct stmt_list_hash hash
;
2777 /* The number of entries in file_names, real_names. */
2778 unsigned int num_file_names
;
2780 /* The file names from the line table, after being run through
2782 const char **file_names
;
2784 /* The file names from the line table after being run through
2785 gdb_realpath. These are computed lazily. */
2786 const char **real_names
;
2789 /* When using the index (and thus not using psymtabs), each CU has an
2790 object of this type. This is used to hold information needed by
2791 the various "quick" methods. */
2792 struct dwarf2_per_cu_quick_data
2794 /* The file table. This can be NULL if there was no file table
2795 or it's currently not read in.
2796 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2797 struct quick_file_names
*file_names
;
2799 /* The corresponding symbol table. This is NULL if symbols for this
2800 CU have not yet been read. */
2801 struct compunit_symtab
*compunit_symtab
;
2803 /* A temporary mark bit used when iterating over all CUs in
2804 expand_symtabs_matching. */
2805 unsigned int mark
: 1;
2807 /* True if we've tried to read the file table and found there isn't one.
2808 There will be no point in trying to read it again next time. */
2809 unsigned int no_file_data
: 1;
2812 /* Utility hash function for a stmt_list_hash. */
2815 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2819 if (stmt_list_hash
->dwo_unit
!= NULL
)
2820 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2821 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2825 /* Utility equality function for a stmt_list_hash. */
2828 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2829 const struct stmt_list_hash
*rhs
)
2831 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2833 if (lhs
->dwo_unit
!= NULL
2834 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2837 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2840 /* Hash function for a quick_file_names. */
2843 hash_file_name_entry (const void *e
)
2845 const struct quick_file_names
*file_data
2846 = (const struct quick_file_names
*) e
;
2848 return hash_stmt_list_entry (&file_data
->hash
);
2851 /* Equality function for a quick_file_names. */
2854 eq_file_name_entry (const void *a
, const void *b
)
2856 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2857 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2859 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2862 /* Delete function for a quick_file_names. */
2865 delete_file_name_entry (void *e
)
2867 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2870 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2872 xfree ((void*) file_data
->file_names
[i
]);
2873 if (file_data
->real_names
)
2874 xfree ((void*) file_data
->real_names
[i
]);
2877 /* The space for the struct itself lives on objfile_obstack,
2878 so we don't free it here. */
2881 /* Create a quick_file_names hash table. */
2884 create_quick_file_names_table (unsigned int nr_initial_entries
)
2886 return htab_create_alloc (nr_initial_entries
,
2887 hash_file_name_entry
, eq_file_name_entry
,
2888 delete_file_name_entry
, xcalloc
, xfree
);
2891 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2892 have to be created afterwards. You should call age_cached_comp_units after
2893 processing PER_CU->CU. dw2_setup must have been already called. */
2896 load_cu (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2898 if (per_cu
->is_debug_types
)
2899 load_full_type_unit (per_cu
);
2901 load_full_comp_unit (per_cu
, skip_partial
, language_minimal
);
2903 if (per_cu
->cu
== NULL
)
2904 return; /* Dummy CU. */
2906 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2909 /* Read in the symbols for PER_CU. */
2912 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2914 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2916 /* Skip type_unit_groups, reading the type units they contain
2917 is handled elsewhere. */
2918 if (IS_TYPE_UNIT_GROUP (per_cu
))
2921 /* The destructor of dwarf2_queue_guard frees any entries left on
2922 the queue. After this point we're guaranteed to leave this function
2923 with the dwarf queue empty. */
2924 dwarf2_queue_guard q_guard
;
2926 if (dwarf2_per_objfile
->using_index
2927 ? per_cu
->v
.quick
->compunit_symtab
== NULL
2928 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2930 queue_comp_unit (per_cu
, language_minimal
);
2931 load_cu (per_cu
, skip_partial
);
2933 /* If we just loaded a CU from a DWO, and we're working with an index
2934 that may badly handle TUs, load all the TUs in that DWO as well.
2935 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2936 if (!per_cu
->is_debug_types
2937 && per_cu
->cu
!= NULL
2938 && per_cu
->cu
->dwo_unit
!= NULL
2939 && dwarf2_per_objfile
->index_table
!= NULL
2940 && dwarf2_per_objfile
->index_table
->version
<= 7
2941 /* DWP files aren't supported yet. */
2942 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
2943 queue_and_load_all_dwo_tus (per_cu
);
2946 process_queue (dwarf2_per_objfile
);
2948 /* Age the cache, releasing compilation units that have not
2949 been used recently. */
2950 age_cached_comp_units (dwarf2_per_objfile
);
2953 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2954 the objfile from which this CU came. Returns the resulting symbol
2957 static struct compunit_symtab
*
2958 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2960 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2962 gdb_assert (dwarf2_per_objfile
->using_index
);
2963 if (!per_cu
->v
.quick
->compunit_symtab
)
2965 free_cached_comp_units
freer (dwarf2_per_objfile
);
2966 scoped_restore decrementer
= increment_reading_symtab ();
2967 dw2_do_instantiate_symtab (per_cu
, skip_partial
);
2968 process_cu_includes (dwarf2_per_objfile
);
2971 return per_cu
->v
.quick
->compunit_symtab
;
2974 /* See declaration. */
2976 dwarf2_per_cu_data
*
2977 dwarf2_per_objfile::get_cutu (int index
)
2979 if (index
>= this->all_comp_units
.size ())
2981 index
-= this->all_comp_units
.size ();
2982 gdb_assert (index
< this->all_type_units
.size ());
2983 return &this->all_type_units
[index
]->per_cu
;
2986 return this->all_comp_units
[index
];
2989 /* See declaration. */
2991 dwarf2_per_cu_data
*
2992 dwarf2_per_objfile::get_cu (int index
)
2994 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2996 return this->all_comp_units
[index
];
2999 /* See declaration. */
3002 dwarf2_per_objfile::get_tu (int index
)
3004 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
3006 return this->all_type_units
[index
];
3009 /* Return a new dwarf2_per_cu_data allocated on OBJFILE's
3010 objfile_obstack, and constructed with the specified field
3013 static dwarf2_per_cu_data
*
3014 create_cu_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3015 struct dwarf2_section_info
*section
,
3017 sect_offset sect_off
, ULONGEST length
)
3019 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3020 dwarf2_per_cu_data
*the_cu
3021 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3022 struct dwarf2_per_cu_data
);
3023 the_cu
->sect_off
= sect_off
;
3024 the_cu
->length
= length
;
3025 the_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3026 the_cu
->section
= section
;
3027 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3028 struct dwarf2_per_cu_quick_data
);
3029 the_cu
->is_dwz
= is_dwz
;
3033 /* A helper for create_cus_from_index that handles a given list of
3037 create_cus_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3038 const gdb_byte
*cu_list
, offset_type n_elements
,
3039 struct dwarf2_section_info
*section
,
3042 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
3044 gdb_static_assert (sizeof (ULONGEST
) >= 8);
3046 sect_offset sect_off
3047 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
3048 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
3051 dwarf2_per_cu_data
*per_cu
3052 = create_cu_from_index_list (dwarf2_per_objfile
, section
, is_dwz
,
3054 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
3058 /* Read the CU list from the mapped index, and use it to create all
3059 the CU objects for this objfile. */
3062 create_cus_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3063 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
3064 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
3066 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
3067 dwarf2_per_objfile
->all_comp_units
.reserve
3068 ((cu_list_elements
+ dwz_elements
) / 2);
3070 create_cus_from_index_list (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3071 &dwarf2_per_objfile
->info
, 0);
3073 if (dwz_elements
== 0)
3076 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3077 create_cus_from_index_list (dwarf2_per_objfile
, dwz_list
, dwz_elements
,
3081 /* Create the signatured type hash table from the index. */
3084 create_signatured_type_table_from_index
3085 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3086 struct dwarf2_section_info
*section
,
3087 const gdb_byte
*bytes
,
3088 offset_type elements
)
3090 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3092 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
3093 dwarf2_per_objfile
->all_type_units
.reserve (elements
/ 3);
3095 htab_t sig_types_hash
= allocate_signatured_type_table (objfile
);
3097 for (offset_type i
= 0; i
< elements
; i
+= 3)
3099 struct signatured_type
*sig_type
;
3102 cu_offset type_offset_in_tu
;
3104 gdb_static_assert (sizeof (ULONGEST
) >= 8);
3105 sect_offset sect_off
3106 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
3108 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
3110 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
3113 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3114 struct signatured_type
);
3115 sig_type
->signature
= signature
;
3116 sig_type
->type_offset_in_tu
= type_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 /* Create the signatured type hash table from .debug_names. */
3137 create_signatured_type_table_from_debug_names
3138 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3139 const mapped_debug_names
&map
,
3140 struct dwarf2_section_info
*section
,
3141 struct dwarf2_section_info
*abbrev_section
)
3143 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3145 dwarf2_read_section (objfile
, section
);
3146 dwarf2_read_section (objfile
, abbrev_section
);
3148 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
3149 dwarf2_per_objfile
->all_type_units
.reserve (map
.tu_count
);
3151 htab_t sig_types_hash
= allocate_signatured_type_table (objfile
);
3153 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
3155 struct signatured_type
*sig_type
;
3158 sect_offset sect_off
3159 = (sect_offset
) (extract_unsigned_integer
3160 (map
.tu_table_reordered
+ i
* map
.offset_size
,
3162 map
.dwarf5_byte_order
));
3164 comp_unit_head cu_header
;
3165 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
3167 section
->buffer
+ to_underlying (sect_off
),
3170 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3171 struct signatured_type
);
3172 sig_type
->signature
= cu_header
.signature
;
3173 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
3174 sig_type
->per_cu
.is_debug_types
= 1;
3175 sig_type
->per_cu
.section
= section
;
3176 sig_type
->per_cu
.sect_off
= sect_off
;
3177 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
3178 sig_type
->per_cu
.v
.quick
3179 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3180 struct dwarf2_per_cu_quick_data
);
3182 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3185 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
3188 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3191 /* Read the address map data from the mapped index, and use it to
3192 populate the objfile's psymtabs_addrmap. */
3195 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3196 struct mapped_index
*index
)
3198 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3199 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3200 const gdb_byte
*iter
, *end
;
3201 struct addrmap
*mutable_map
;
3204 auto_obstack temp_obstack
;
3206 mutable_map
= addrmap_create_mutable (&temp_obstack
);
3208 iter
= index
->address_table
.data ();
3209 end
= iter
+ index
->address_table
.size ();
3211 baseaddr
= objfile
->text_section_offset ();
3215 ULONGEST hi
, lo
, cu_index
;
3216 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3218 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3220 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
3225 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
3226 hex_string (lo
), hex_string (hi
));
3230 if (cu_index
>= dwarf2_per_objfile
->all_comp_units
.size ())
3232 complaint (_(".gdb_index address table has invalid CU number %u"),
3233 (unsigned) cu_index
);
3237 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
3238 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
3239 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
3240 dwarf2_per_objfile
->get_cu (cu_index
));
3243 objfile
->partial_symtabs
->psymtabs_addrmap
3244 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
3247 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
3248 populate the objfile's psymtabs_addrmap. */
3251 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3252 struct dwarf2_section_info
*section
)
3254 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3255 bfd
*abfd
= objfile
->obfd
;
3256 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3257 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
3259 auto_obstack temp_obstack
;
3260 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
3262 std::unordered_map
<sect_offset
,
3263 dwarf2_per_cu_data
*,
3264 gdb::hash_enum
<sect_offset
>>
3265 debug_info_offset_to_per_cu
;
3266 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3268 const auto insertpair
3269 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
3270 if (!insertpair
.second
)
3272 warning (_("Section .debug_aranges in %s has duplicate "
3273 "debug_info_offset %s, ignoring .debug_aranges."),
3274 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
3279 dwarf2_read_section (objfile
, section
);
3281 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
3283 const gdb_byte
*addr
= section
->buffer
;
3285 while (addr
< section
->buffer
+ section
->size
)
3287 const gdb_byte
*const entry_addr
= addr
;
3288 unsigned int bytes_read
;
3290 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
3294 const gdb_byte
*const entry_end
= addr
+ entry_length
;
3295 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
3296 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
3297 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
3299 warning (_("Section .debug_aranges in %s entry at offset %s "
3300 "length %s exceeds section length %s, "
3301 "ignoring .debug_aranges."),
3302 objfile_name (objfile
),
3303 plongest (entry_addr
- section
->buffer
),
3304 plongest (bytes_read
+ entry_length
),
3305 pulongest (section
->size
));
3309 /* The version number. */
3310 const uint16_t version
= read_2_bytes (abfd
, addr
);
3314 warning (_("Section .debug_aranges in %s entry at offset %s "
3315 "has unsupported version %d, ignoring .debug_aranges."),
3316 objfile_name (objfile
),
3317 plongest (entry_addr
- section
->buffer
), version
);
3321 const uint64_t debug_info_offset
3322 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
3323 addr
+= offset_size
;
3324 const auto per_cu_it
3325 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
3326 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
3328 warning (_("Section .debug_aranges in %s entry at offset %s "
3329 "debug_info_offset %s does not exists, "
3330 "ignoring .debug_aranges."),
3331 objfile_name (objfile
),
3332 plongest (entry_addr
- section
->buffer
),
3333 pulongest (debug_info_offset
));
3336 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
3338 const uint8_t address_size
= *addr
++;
3339 if (address_size
< 1 || address_size
> 8)
3341 warning (_("Section .debug_aranges in %s entry at offset %s "
3342 "address_size %u is invalid, ignoring .debug_aranges."),
3343 objfile_name (objfile
),
3344 plongest (entry_addr
- section
->buffer
), address_size
);
3348 const uint8_t segment_selector_size
= *addr
++;
3349 if (segment_selector_size
!= 0)
3351 warning (_("Section .debug_aranges in %s entry at offset %s "
3352 "segment_selector_size %u is not supported, "
3353 "ignoring .debug_aranges."),
3354 objfile_name (objfile
),
3355 plongest (entry_addr
- section
->buffer
),
3356 segment_selector_size
);
3360 /* Must pad to an alignment boundary that is twice the address
3361 size. It is undocumented by the DWARF standard but GCC does
3363 for (size_t padding
= ((-(addr
- section
->buffer
))
3364 & (2 * address_size
- 1));
3365 padding
> 0; padding
--)
3368 warning (_("Section .debug_aranges in %s entry at offset %s "
3369 "padding is not zero, ignoring .debug_aranges."),
3370 objfile_name (objfile
),
3371 plongest (entry_addr
- section
->buffer
));
3377 if (addr
+ 2 * address_size
> entry_end
)
3379 warning (_("Section .debug_aranges in %s entry at offset %s "
3380 "address list is not properly terminated, "
3381 "ignoring .debug_aranges."),
3382 objfile_name (objfile
),
3383 plongest (entry_addr
- section
->buffer
));
3386 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
3388 addr
+= address_size
;
3389 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
3391 addr
+= address_size
;
3392 if (start
== 0 && length
== 0)
3394 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
3396 /* Symbol was eliminated due to a COMDAT group. */
3399 ULONGEST end
= start
+ length
;
3400 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
3402 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
3404 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
3408 objfile
->partial_symtabs
->psymtabs_addrmap
3409 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
3412 /* Find a slot in the mapped index INDEX for the object named NAME.
3413 If NAME is found, set *VEC_OUT to point to the CU vector in the
3414 constant pool and return true. If NAME cannot be found, return
3418 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
3419 offset_type
**vec_out
)
3422 offset_type slot
, step
;
3423 int (*cmp
) (const char *, const char *);
3425 gdb::unique_xmalloc_ptr
<char> without_params
;
3426 if (current_language
->la_language
== language_cplus
3427 || current_language
->la_language
== language_fortran
3428 || current_language
->la_language
== language_d
)
3430 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
3433 if (strchr (name
, '(') != NULL
)
3435 without_params
= cp_remove_params (name
);
3437 if (without_params
!= NULL
)
3438 name
= without_params
.get ();
3442 /* Index version 4 did not support case insensitive searches. But the
3443 indices for case insensitive languages are built in lowercase, therefore
3444 simulate our NAME being searched is also lowercased. */
3445 hash
= mapped_index_string_hash ((index
->version
== 4
3446 && case_sensitivity
== case_sensitive_off
3447 ? 5 : index
->version
),
3450 slot
= hash
& (index
->symbol_table
.size () - 1);
3451 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
3452 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
3458 const auto &bucket
= index
->symbol_table
[slot
];
3459 if (bucket
.name
== 0 && bucket
.vec
== 0)
3462 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
3463 if (!cmp (name
, str
))
3465 *vec_out
= (offset_type
*) (index
->constant_pool
3466 + MAYBE_SWAP (bucket
.vec
));
3470 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
3474 /* A helper function that reads the .gdb_index from BUFFER and fills
3475 in MAP. FILENAME is the name of the file containing the data;
3476 it is used for error reporting. DEPRECATED_OK is true if it is
3477 ok to use deprecated sections.
3479 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
3480 out parameters that are filled in with information about the CU and
3481 TU lists in the section.
3483 Returns true if all went well, false otherwise. */
3486 read_gdb_index_from_buffer (struct objfile
*objfile
,
3487 const char *filename
,
3489 gdb::array_view
<const gdb_byte
> buffer
,
3490 struct mapped_index
*map
,
3491 const gdb_byte
**cu_list
,
3492 offset_type
*cu_list_elements
,
3493 const gdb_byte
**types_list
,
3494 offset_type
*types_list_elements
)
3496 const gdb_byte
*addr
= &buffer
[0];
3498 /* Version check. */
3499 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
3500 /* Versions earlier than 3 emitted every copy of a psymbol. This
3501 causes the index to behave very poorly for certain requests. Version 3
3502 contained incomplete addrmap. So, it seems better to just ignore such
3506 static int warning_printed
= 0;
3507 if (!warning_printed
)
3509 warning (_("Skipping obsolete .gdb_index section in %s."),
3511 warning_printed
= 1;
3515 /* Index version 4 uses a different hash function than index version
3518 Versions earlier than 6 did not emit psymbols for inlined
3519 functions. Using these files will cause GDB not to be able to
3520 set breakpoints on inlined functions by name, so we ignore these
3521 indices unless the user has done
3522 "set use-deprecated-index-sections on". */
3523 if (version
< 6 && !deprecated_ok
)
3525 static int warning_printed
= 0;
3526 if (!warning_printed
)
3529 Skipping deprecated .gdb_index section in %s.\n\
3530 Do \"set use-deprecated-index-sections on\" before the file is read\n\
3531 to use the section anyway."),
3533 warning_printed
= 1;
3537 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3538 of the TU (for symbols coming from TUs),
3539 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3540 Plus gold-generated indices can have duplicate entries for global symbols,
3541 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3542 These are just performance bugs, and we can't distinguish gdb-generated
3543 indices from gold-generated ones, so issue no warning here. */
3545 /* Indexes with higher version than the one supported by GDB may be no
3546 longer backward compatible. */
3550 map
->version
= version
;
3552 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3555 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3556 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3560 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3561 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3562 - MAYBE_SWAP (metadata
[i
]))
3566 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3567 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3569 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
3572 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3573 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3575 = gdb::array_view
<mapped_index::symbol_table_slot
>
3576 ((mapped_index::symbol_table_slot
*) symbol_table
,
3577 (mapped_index::symbol_table_slot
*) symbol_table_end
);
3580 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3585 /* Callback types for dwarf2_read_gdb_index. */
3587 typedef gdb::function_view
3588 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_objfile
*)>
3589 get_gdb_index_contents_ftype
;
3590 typedef gdb::function_view
3591 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
3592 get_gdb_index_contents_dwz_ftype
;
3594 /* Read .gdb_index. If everything went ok, initialize the "quick"
3595 elements of all the CUs and return 1. Otherwise, return 0. */
3598 dwarf2_read_gdb_index
3599 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3600 get_gdb_index_contents_ftype get_gdb_index_contents
,
3601 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
3603 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3604 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3605 struct dwz_file
*dwz
;
3606 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3608 gdb::array_view
<const gdb_byte
> main_index_contents
3609 = get_gdb_index_contents (objfile
, dwarf2_per_objfile
);
3611 if (main_index_contents
.empty ())
3614 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3615 if (!read_gdb_index_from_buffer (objfile
, objfile_name (objfile
),
3616 use_deprecated_index_sections
,
3617 main_index_contents
, map
.get (), &cu_list
,
3618 &cu_list_elements
, &types_list
,
3619 &types_list_elements
))
3622 /* Don't use the index if it's empty. */
3623 if (map
->symbol_table
.empty ())
3626 /* If there is a .dwz file, read it so we can get its CU list as
3628 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3631 struct mapped_index dwz_map
;
3632 const gdb_byte
*dwz_types_ignore
;
3633 offset_type dwz_types_elements_ignore
;
3635 gdb::array_view
<const gdb_byte
> dwz_index_content
3636 = get_gdb_index_contents_dwz (objfile
, dwz
);
3638 if (dwz_index_content
.empty ())
3641 if (!read_gdb_index_from_buffer (objfile
,
3642 bfd_get_filename (dwz
->dwz_bfd
.get ()),
3643 1, dwz_index_content
, &dwz_map
,
3644 &dwz_list
, &dwz_list_elements
,
3646 &dwz_types_elements_ignore
))
3648 warning (_("could not read '.gdb_index' section from %s; skipping"),
3649 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3654 create_cus_from_index (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3655 dwz_list
, dwz_list_elements
);
3657 if (types_list_elements
)
3659 /* We can only handle a single .debug_types when we have an
3661 if (dwarf2_per_objfile
->types
.size () != 1)
3664 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
3666 create_signatured_type_table_from_index (dwarf2_per_objfile
, section
,
3667 types_list
, types_list_elements
);
3670 create_addrmap_from_index (dwarf2_per_objfile
, map
.get ());
3672 dwarf2_per_objfile
->index_table
= std::move (map
);
3673 dwarf2_per_objfile
->using_index
= 1;
3674 dwarf2_per_objfile
->quick_file_names_table
=
3675 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
3680 /* die_reader_func for dw2_get_file_names. */
3683 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3684 const gdb_byte
*info_ptr
,
3685 struct die_info
*comp_unit_die
,
3688 struct dwarf2_cu
*cu
= reader
->cu
;
3689 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3690 struct dwarf2_per_objfile
*dwarf2_per_objfile
3691 = cu
->per_cu
->dwarf2_per_objfile
;
3692 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3693 struct dwarf2_per_cu_data
*lh_cu
;
3694 struct attribute
*attr
;
3696 struct quick_file_names
*qfn
;
3698 gdb_assert (! this_cu
->is_debug_types
);
3700 /* Our callers never want to match partial units -- instead they
3701 will match the enclosing full CU. */
3702 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3704 this_cu
->v
.quick
->no_file_data
= 1;
3712 sect_offset line_offset
{};
3714 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3715 if (attr
!= nullptr)
3717 struct quick_file_names find_entry
;
3719 line_offset
= (sect_offset
) DW_UNSND (attr
);
3721 /* We may have already read in this line header (TU line header sharing).
3722 If we have we're done. */
3723 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3724 find_entry
.hash
.line_sect_off
= line_offset
;
3725 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
3726 &find_entry
, INSERT
);
3729 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3733 lh
= dwarf_decode_line_header (line_offset
, cu
);
3737 lh_cu
->v
.quick
->no_file_data
= 1;
3741 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
3742 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3743 qfn
->hash
.line_sect_off
= line_offset
;
3744 gdb_assert (slot
!= NULL
);
3747 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3750 if (strcmp (fnd
.name
, "<unknown>") != 0)
3753 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3755 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, qfn
->num_file_names
);
3757 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3758 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3759 qfn
->file_names
[i
+ offset
] = file_full_name (i
+ 1, lh
.get (), fnd
.comp_dir
);
3760 qfn
->real_names
= NULL
;
3762 lh_cu
->v
.quick
->file_names
= qfn
;
3765 /* A helper for the "quick" functions which attempts to read the line
3766 table for THIS_CU. */
3768 static struct quick_file_names
*
3769 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3771 /* This should never be called for TUs. */
3772 gdb_assert (! this_cu
->is_debug_types
);
3773 /* Nor type unit groups. */
3774 gdb_assert (! IS_TYPE_UNIT_GROUP (this_cu
));
3776 if (this_cu
->v
.quick
->file_names
!= NULL
)
3777 return this_cu
->v
.quick
->file_names
;
3778 /* If we know there is no line data, no point in looking again. */
3779 if (this_cu
->v
.quick
->no_file_data
)
3782 cutu_reader
reader (this_cu
);
3783 if (!reader
.dummy_p
)
3784 dw2_get_file_names_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
3785 reader
.has_children
);
3787 if (this_cu
->v
.quick
->no_file_data
)
3789 return this_cu
->v
.quick
->file_names
;
3792 /* A helper for the "quick" functions which computes and caches the
3793 real path for a given file name from the line table. */
3796 dw2_get_real_path (struct objfile
*objfile
,
3797 struct quick_file_names
*qfn
, int index
)
3799 if (qfn
->real_names
== NULL
)
3800 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3801 qfn
->num_file_names
, const char *);
3803 if (qfn
->real_names
[index
] == NULL
)
3804 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3806 return qfn
->real_names
[index
];
3809 static struct symtab
*
3810 dw2_find_last_source_symtab (struct objfile
*objfile
)
3812 struct dwarf2_per_objfile
*dwarf2_per_objfile
3813 = get_dwarf2_per_objfile (objfile
);
3814 dwarf2_per_cu_data
*dwarf_cu
= dwarf2_per_objfile
->all_comp_units
.back ();
3815 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, false);
3820 return compunit_primary_filetab (cust
);
3823 /* Traversal function for dw2_forget_cached_source_info. */
3826 dw2_free_cached_file_names (void **slot
, void *info
)
3828 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3830 if (file_data
->real_names
)
3834 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3836 xfree ((void*) file_data
->real_names
[i
]);
3837 file_data
->real_names
[i
] = NULL
;
3845 dw2_forget_cached_source_info (struct objfile
*objfile
)
3847 struct dwarf2_per_objfile
*dwarf2_per_objfile
3848 = get_dwarf2_per_objfile (objfile
);
3850 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
3851 dw2_free_cached_file_names
, NULL
);
3854 /* Helper function for dw2_map_symtabs_matching_filename that expands
3855 the symtabs and calls the iterator. */
3858 dw2_map_expand_apply (struct objfile
*objfile
,
3859 struct dwarf2_per_cu_data
*per_cu
,
3860 const char *name
, const char *real_path
,
3861 gdb::function_view
<bool (symtab
*)> callback
)
3863 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3865 /* Don't visit already-expanded CUs. */
3866 if (per_cu
->v
.quick
->compunit_symtab
)
3869 /* This may expand more than one symtab, and we want to iterate over
3871 dw2_instantiate_symtab (per_cu
, false);
3873 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3874 last_made
, callback
);
3877 /* Implementation of the map_symtabs_matching_filename method. */
3880 dw2_map_symtabs_matching_filename
3881 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3882 gdb::function_view
<bool (symtab
*)> callback
)
3884 const char *name_basename
= lbasename (name
);
3885 struct dwarf2_per_objfile
*dwarf2_per_objfile
3886 = get_dwarf2_per_objfile (objfile
);
3888 /* The rule is CUs specify all the files, including those used by
3889 any TU, so there's no need to scan TUs here. */
3891 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3893 /* We only need to look at symtabs not already expanded. */
3894 if (per_cu
->v
.quick
->compunit_symtab
)
3897 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3898 if (file_data
== NULL
)
3901 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3903 const char *this_name
= file_data
->file_names
[j
];
3904 const char *this_real_name
;
3906 if (compare_filenames_for_search (this_name
, name
))
3908 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3914 /* Before we invoke realpath, which can get expensive when many
3915 files are involved, do a quick comparison of the basenames. */
3916 if (! basenames_may_differ
3917 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3920 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3921 if (compare_filenames_for_search (this_real_name
, name
))
3923 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3929 if (real_path
!= NULL
)
3931 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3932 gdb_assert (IS_ABSOLUTE_PATH (name
));
3933 if (this_real_name
!= NULL
3934 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3936 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3948 /* Struct used to manage iterating over all CUs looking for a symbol. */
3950 struct dw2_symtab_iterator
3952 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3953 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
3954 /* If set, only look for symbols that match that block. Valid values are
3955 GLOBAL_BLOCK and STATIC_BLOCK. */
3956 gdb::optional
<block_enum
> block_index
;
3957 /* The kind of symbol we're looking for. */
3959 /* The list of CUs from the index entry of the symbol,
3960 or NULL if not found. */
3962 /* The next element in VEC to look at. */
3964 /* The number of elements in VEC, or zero if there is no match. */
3966 /* Have we seen a global version of the symbol?
3967 If so we can ignore all further global instances.
3968 This is to work around gold/15646, inefficient gold-generated
3973 /* Initialize the index symtab iterator ITER. */
3976 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3977 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3978 gdb::optional
<block_enum
> block_index
,
3982 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3983 iter
->block_index
= block_index
;
3984 iter
->domain
= domain
;
3986 iter
->global_seen
= 0;
3988 mapped_index
*index
= dwarf2_per_objfile
->index_table
.get ();
3990 /* index is NULL if OBJF_READNOW. */
3991 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3992 iter
->length
= MAYBE_SWAP (*iter
->vec
);
4000 /* Return the next matching CU or NULL if there are no more. */
4002 static struct dwarf2_per_cu_data
*
4003 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
4005 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
4007 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
4009 offset_type cu_index_and_attrs
=
4010 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
4011 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4012 gdb_index_symbol_kind symbol_kind
=
4013 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4014 /* Only check the symbol attributes if they're present.
4015 Indices prior to version 7 don't record them,
4016 and indices >= 7 may elide them for certain symbols
4017 (gold does this). */
4019 (dwarf2_per_objfile
->index_table
->version
>= 7
4020 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4022 /* Don't crash on bad data. */
4023 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
4024 + dwarf2_per_objfile
->all_type_units
.size ()))
4026 complaint (_(".gdb_index entry has bad CU index"
4028 objfile_name (dwarf2_per_objfile
->objfile
));
4032 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
4034 /* Skip if already read in. */
4035 if (per_cu
->v
.quick
->compunit_symtab
)
4038 /* Check static vs global. */
4041 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4043 if (iter
->block_index
.has_value ())
4045 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
4047 if (is_static
!= want_static
)
4051 /* Work around gold/15646. */
4052 if (!is_static
&& iter
->global_seen
)
4055 iter
->global_seen
= 1;
4058 /* Only check the symbol's kind if it has one. */
4061 switch (iter
->domain
)
4064 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
4065 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
4066 /* Some types are also in VAR_DOMAIN. */
4067 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4071 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4075 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4079 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4094 static struct compunit_symtab
*
4095 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
4096 const char *name
, domain_enum domain
)
4098 struct compunit_symtab
*stab_best
= NULL
;
4099 struct dwarf2_per_objfile
*dwarf2_per_objfile
4100 = get_dwarf2_per_objfile (objfile
);
4102 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
4104 struct dw2_symtab_iterator iter
;
4105 struct dwarf2_per_cu_data
*per_cu
;
4107 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, block_index
, domain
, name
);
4109 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4111 struct symbol
*sym
, *with_opaque
= NULL
;
4112 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
4113 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
4114 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
4116 sym
= block_find_symbol (block
, name
, domain
,
4117 block_find_non_opaque_type_preferred
,
4120 /* Some caution must be observed with overloaded functions
4121 and methods, since the index will not contain any overload
4122 information (but NAME might contain it). */
4125 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
4127 if (with_opaque
!= NULL
4128 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
4131 /* Keep looking through other CUs. */
4138 dw2_print_stats (struct objfile
*objfile
)
4140 struct dwarf2_per_objfile
*dwarf2_per_objfile
4141 = get_dwarf2_per_objfile (objfile
);
4142 int total
= (dwarf2_per_objfile
->all_comp_units
.size ()
4143 + dwarf2_per_objfile
->all_type_units
.size ());
4146 for (int i
= 0; i
< total
; ++i
)
4148 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
4150 if (!per_cu
->v
.quick
->compunit_symtab
)
4153 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
4154 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
4157 /* This dumps minimal information about the index.
4158 It is called via "mt print objfiles".
4159 One use is to verify .gdb_index has been loaded by the
4160 gdb.dwarf2/gdb-index.exp testcase. */
4163 dw2_dump (struct objfile
*objfile
)
4165 struct dwarf2_per_objfile
*dwarf2_per_objfile
4166 = get_dwarf2_per_objfile (objfile
);
4168 gdb_assert (dwarf2_per_objfile
->using_index
);
4169 printf_filtered (".gdb_index:");
4170 if (dwarf2_per_objfile
->index_table
!= NULL
)
4172 printf_filtered (" version %d\n",
4173 dwarf2_per_objfile
->index_table
->version
);
4176 printf_filtered (" faked for \"readnow\"\n");
4177 printf_filtered ("\n");
4181 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
4182 const char *func_name
)
4184 struct dwarf2_per_objfile
*dwarf2_per_objfile
4185 = get_dwarf2_per_objfile (objfile
);
4187 struct dw2_symtab_iterator iter
;
4188 struct dwarf2_per_cu_data
*per_cu
;
4190 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, {}, VAR_DOMAIN
, func_name
);
4192 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4193 dw2_instantiate_symtab (per_cu
, false);
4198 dw2_expand_all_symtabs (struct objfile
*objfile
)
4200 struct dwarf2_per_objfile
*dwarf2_per_objfile
4201 = get_dwarf2_per_objfile (objfile
);
4202 int total_units
= (dwarf2_per_objfile
->all_comp_units
.size ()
4203 + dwarf2_per_objfile
->all_type_units
.size ());
4205 for (int i
= 0; i
< total_units
; ++i
)
4207 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
4209 /* We don't want to directly expand a partial CU, because if we
4210 read it with the wrong language, then assertion failures can
4211 be triggered later on. See PR symtab/23010. So, tell
4212 dw2_instantiate_symtab to skip partial CUs -- any important
4213 partial CU will be read via DW_TAG_imported_unit anyway. */
4214 dw2_instantiate_symtab (per_cu
, true);
4219 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
4220 const char *fullname
)
4222 struct dwarf2_per_objfile
*dwarf2_per_objfile
4223 = get_dwarf2_per_objfile (objfile
);
4225 /* We don't need to consider type units here.
4226 This is only called for examining code, e.g. expand_line_sal.
4227 There can be an order of magnitude (or more) more type units
4228 than comp units, and we avoid them if we can. */
4230 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4232 /* We only need to look at symtabs not already expanded. */
4233 if (per_cu
->v
.quick
->compunit_symtab
)
4236 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4237 if (file_data
== NULL
)
4240 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4242 const char *this_fullname
= file_data
->file_names
[j
];
4244 if (filename_cmp (this_fullname
, fullname
) == 0)
4246 dw2_instantiate_symtab (per_cu
, false);
4254 dw2_map_matching_symbols
4255 (struct objfile
*objfile
,
4256 const lookup_name_info
&name
, domain_enum domain
,
4258 gdb::function_view
<symbol_found_callback_ftype
> callback
,
4259 symbol_compare_ftype
*ordered_compare
)
4261 /* Currently unimplemented; used for Ada. The function can be called if the
4262 current language is Ada for a non-Ada objfile using GNU index. As Ada
4263 does not look for non-Ada symbols this function should just return. */
4266 /* Starting from a search name, return the string that finds the upper
4267 bound of all strings that start with SEARCH_NAME in a sorted name
4268 list. Returns the empty string to indicate that the upper bound is
4269 the end of the list. */
4272 make_sort_after_prefix_name (const char *search_name
)
4274 /* When looking to complete "func", we find the upper bound of all
4275 symbols that start with "func" by looking for where we'd insert
4276 the closest string that would follow "func" in lexicographical
4277 order. Usually, that's "func"-with-last-character-incremented,
4278 i.e. "fund". Mind non-ASCII characters, though. Usually those
4279 will be UTF-8 multi-byte sequences, but we can't be certain.
4280 Especially mind the 0xff character, which is a valid character in
4281 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
4282 rule out compilers allowing it in identifiers. Note that
4283 conveniently, strcmp/strcasecmp are specified to compare
4284 characters interpreted as unsigned char. So what we do is treat
4285 the whole string as a base 256 number composed of a sequence of
4286 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
4287 to 0, and carries 1 to the following more-significant position.
4288 If the very first character in SEARCH_NAME ends up incremented
4289 and carries/overflows, then the upper bound is the end of the
4290 list. The string after the empty string is also the empty
4293 Some examples of this operation:
4295 SEARCH_NAME => "+1" RESULT
4299 "\xff" "a" "\xff" => "\xff" "b"
4304 Then, with these symbols for example:
4310 completing "func" looks for symbols between "func" and
4311 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
4312 which finds "func" and "func1", but not "fund".
4316 funcÿ (Latin1 'ÿ' [0xff])
4320 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
4321 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
4325 ÿÿ (Latin1 'ÿ' [0xff])
4328 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
4329 the end of the list.
4331 std::string after
= search_name
;
4332 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
4334 if (!after
.empty ())
4335 after
.back () = (unsigned char) after
.back () + 1;
4339 /* See declaration. */
4341 std::pair
<std::vector
<name_component
>::const_iterator
,
4342 std::vector
<name_component
>::const_iterator
>
4343 mapped_index_base::find_name_components_bounds
4344 (const lookup_name_info
&lookup_name_without_params
, language lang
) const
4347 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4349 const char *lang_name
4350 = lookup_name_without_params
.language_lookup_name (lang
).c_str ();
4352 /* Comparison function object for lower_bound that matches against a
4353 given symbol name. */
4354 auto lookup_compare_lower
= [&] (const name_component
&elem
,
4357 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4358 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4359 return name_cmp (elem_name
, name
) < 0;
4362 /* Comparison function object for upper_bound that matches against a
4363 given symbol name. */
4364 auto lookup_compare_upper
= [&] (const char *name
,
4365 const name_component
&elem
)
4367 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4368 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4369 return name_cmp (name
, elem_name
) < 0;
4372 auto begin
= this->name_components
.begin ();
4373 auto end
= this->name_components
.end ();
4375 /* Find the lower bound. */
4378 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
4381 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
4384 /* Find the upper bound. */
4387 if (lookup_name_without_params
.completion_mode ())
4389 /* In completion mode, we want UPPER to point past all
4390 symbols names that have the same prefix. I.e., with
4391 these symbols, and completing "func":
4393 function << lower bound
4395 other_function << upper bound
4397 We find the upper bound by looking for the insertion
4398 point of "func"-with-last-character-incremented,
4400 std::string after
= make_sort_after_prefix_name (lang_name
);
4403 return std::lower_bound (lower
, end
, after
.c_str (),
4404 lookup_compare_lower
);
4407 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
4410 return {lower
, upper
};
4413 /* See declaration. */
4416 mapped_index_base::build_name_components ()
4418 if (!this->name_components
.empty ())
4421 this->name_components_casing
= case_sensitivity
;
4423 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4425 /* The code below only knows how to break apart components of C++
4426 symbol names (and other languages that use '::' as
4427 namespace/module separator) and Ada symbol names. */
4428 auto count
= this->symbol_name_count ();
4429 for (offset_type idx
= 0; idx
< count
; idx
++)
4431 if (this->symbol_name_slot_invalid (idx
))
4434 const char *name
= this->symbol_name_at (idx
);
4436 /* Add each name component to the name component table. */
4437 unsigned int previous_len
= 0;
4439 if (strstr (name
, "::") != nullptr)
4441 for (unsigned int current_len
= cp_find_first_component (name
);
4442 name
[current_len
] != '\0';
4443 current_len
+= cp_find_first_component (name
+ current_len
))
4445 gdb_assert (name
[current_len
] == ':');
4446 this->name_components
.push_back ({previous_len
, idx
});
4447 /* Skip the '::'. */
4449 previous_len
= current_len
;
4454 /* Handle the Ada encoded (aka mangled) form here. */
4455 for (const char *iter
= strstr (name
, "__");
4457 iter
= strstr (iter
, "__"))
4459 this->name_components
.push_back ({previous_len
, idx
});
4461 previous_len
= iter
- name
;
4465 this->name_components
.push_back ({previous_len
, idx
});
4468 /* Sort name_components elements by name. */
4469 auto name_comp_compare
= [&] (const name_component
&left
,
4470 const name_component
&right
)
4472 const char *left_qualified
= this->symbol_name_at (left
.idx
);
4473 const char *right_qualified
= this->symbol_name_at (right
.idx
);
4475 const char *left_name
= left_qualified
+ left
.name_offset
;
4476 const char *right_name
= right_qualified
+ right
.name_offset
;
4478 return name_cmp (left_name
, right_name
) < 0;
4481 std::sort (this->name_components
.begin (),
4482 this->name_components
.end (),
4486 /* Helper for dw2_expand_symtabs_matching that works with a
4487 mapped_index_base instead of the containing objfile. This is split
4488 to a separate function in order to be able to unit test the
4489 name_components matching using a mock mapped_index_base. For each
4490 symbol name that matches, calls MATCH_CALLBACK, passing it the
4491 symbol's index in the mapped_index_base symbol table. */
4494 dw2_expand_symtabs_matching_symbol
4495 (mapped_index_base
&index
,
4496 const lookup_name_info
&lookup_name_in
,
4497 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4498 enum search_domain kind
,
4499 gdb::function_view
<bool (offset_type
)> match_callback
)
4501 lookup_name_info lookup_name_without_params
4502 = lookup_name_in
.make_ignore_params ();
4504 /* Build the symbol name component sorted vector, if we haven't
4506 index
.build_name_components ();
4508 /* The same symbol may appear more than once in the range though.
4509 E.g., if we're looking for symbols that complete "w", and we have
4510 a symbol named "w1::w2", we'll find the two name components for
4511 that same symbol in the range. To be sure we only call the
4512 callback once per symbol, we first collect the symbol name
4513 indexes that matched in a temporary vector and ignore
4515 std::vector
<offset_type
> matches
;
4517 struct name_and_matcher
4519 symbol_name_matcher_ftype
*matcher
;
4520 const std::string
&name
;
4522 bool operator== (const name_and_matcher
&other
) const
4524 return matcher
== other
.matcher
&& name
== other
.name
;
4528 /* A vector holding all the different symbol name matchers, for all
4530 std::vector
<name_and_matcher
> matchers
;
4532 for (int i
= 0; i
< nr_languages
; i
++)
4534 enum language lang_e
= (enum language
) i
;
4536 const language_defn
*lang
= language_def (lang_e
);
4537 symbol_name_matcher_ftype
*name_matcher
4538 = get_symbol_name_matcher (lang
, lookup_name_without_params
);
4540 name_and_matcher key
{
4542 lookup_name_without_params
.language_lookup_name (lang_e
)
4545 /* Don't insert the same comparison routine more than once.
4546 Note that we do this linear walk. This is not a problem in
4547 practice because the number of supported languages is
4549 if (std::find (matchers
.begin (), matchers
.end (), key
)
4552 matchers
.push_back (std::move (key
));
4555 = index
.find_name_components_bounds (lookup_name_without_params
,
4558 /* Now for each symbol name in range, check to see if we have a name
4559 match, and if so, call the MATCH_CALLBACK callback. */
4561 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
4563 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
4565 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
4566 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4569 matches
.push_back (bounds
.first
->idx
);
4573 std::sort (matches
.begin (), matches
.end ());
4575 /* Finally call the callback, once per match. */
4577 for (offset_type idx
: matches
)
4581 if (!match_callback (idx
))
4587 /* Above we use a type wider than idx's for 'prev', since 0 and
4588 (offset_type)-1 are both possible values. */
4589 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4594 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4596 /* A mock .gdb_index/.debug_names-like name index table, enough to
4597 exercise dw2_expand_symtabs_matching_symbol, which works with the
4598 mapped_index_base interface. Builds an index from the symbol list
4599 passed as parameter to the constructor. */
4600 class mock_mapped_index
: public mapped_index_base
4603 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4604 : m_symbol_table (symbols
)
4607 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4609 /* Return the number of names in the symbol table. */
4610 size_t symbol_name_count () const override
4612 return m_symbol_table
.size ();
4615 /* Get the name of the symbol at IDX in the symbol table. */
4616 const char *symbol_name_at (offset_type idx
) const override
4618 return m_symbol_table
[idx
];
4622 gdb::array_view
<const char *> m_symbol_table
;
4625 /* Convenience function that converts a NULL pointer to a "<null>"
4626 string, to pass to print routines. */
4629 string_or_null (const char *str
)
4631 return str
!= NULL
? str
: "<null>";
4634 /* Check if a lookup_name_info built from
4635 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4636 index. EXPECTED_LIST is the list of expected matches, in expected
4637 matching order. If no match expected, then an empty list is
4638 specified. Returns true on success. On failure prints a warning
4639 indicating the file:line that failed, and returns false. */
4642 check_match (const char *file
, int line
,
4643 mock_mapped_index
&mock_index
,
4644 const char *name
, symbol_name_match_type match_type
,
4645 bool completion_mode
,
4646 std::initializer_list
<const char *> expected_list
)
4648 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4650 bool matched
= true;
4652 auto mismatch
= [&] (const char *expected_str
,
4655 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4656 "expected=\"%s\", got=\"%s\"\n"),
4658 (match_type
== symbol_name_match_type::FULL
4660 name
, string_or_null (expected_str
), string_or_null (got
));
4664 auto expected_it
= expected_list
.begin ();
4665 auto expected_end
= expected_list
.end ();
4667 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4669 [&] (offset_type idx
)
4671 const char *matched_name
= mock_index
.symbol_name_at (idx
);
4672 const char *expected_str
4673 = expected_it
== expected_end
? NULL
: *expected_it
++;
4675 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4676 mismatch (expected_str
, matched_name
);
4680 const char *expected_str
4681 = expected_it
== expected_end
? NULL
: *expected_it
++;
4682 if (expected_str
!= NULL
)
4683 mismatch (expected_str
, NULL
);
4688 /* The symbols added to the mock mapped_index for testing (in
4690 static const char *test_symbols
[] = {
4699 "ns2::tmpl<int>::foo2",
4700 "(anonymous namespace)::A::B::C",
4702 /* These are used to check that the increment-last-char in the
4703 matching algorithm for completion doesn't match "t1_fund" when
4704 completing "t1_func". */
4710 /* A UTF-8 name with multi-byte sequences to make sure that
4711 cp-name-parser understands this as a single identifier ("função"
4712 is "function" in PT). */
4715 /* \377 (0xff) is Latin1 'ÿ'. */
4718 /* \377 (0xff) is Latin1 'ÿ'. */
4722 /* A name with all sorts of complications. Starts with "z" to make
4723 it easier for the completion tests below. */
4724 #define Z_SYM_NAME \
4725 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4726 "::tuple<(anonymous namespace)::ui*, " \
4727 "std::default_delete<(anonymous namespace)::ui>, void>"
4732 /* Returns true if the mapped_index_base::find_name_component_bounds
4733 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4734 in completion mode. */
4737 check_find_bounds_finds (mapped_index_base
&index
,
4738 const char *search_name
,
4739 gdb::array_view
<const char *> expected_syms
)
4741 lookup_name_info
lookup_name (search_name
,
4742 symbol_name_match_type::FULL
, true);
4744 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4747 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4748 if (distance
!= expected_syms
.size ())
4751 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4753 auto nc_elem
= bounds
.first
+ exp_elem
;
4754 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
4755 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4762 /* Test the lower-level mapped_index::find_name_component_bounds
4766 test_mapped_index_find_name_component_bounds ()
4768 mock_mapped_index
mock_index (test_symbols
);
4770 mock_index
.build_name_components ();
4772 /* Test the lower-level mapped_index::find_name_component_bounds
4773 method in completion mode. */
4775 static const char *expected_syms
[] = {
4780 SELF_CHECK (check_find_bounds_finds (mock_index
,
4781 "t1_func", expected_syms
));
4784 /* Check that the increment-last-char in the name matching algorithm
4785 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4787 static const char *expected_syms1
[] = {
4791 SELF_CHECK (check_find_bounds_finds (mock_index
,
4792 "\377", expected_syms1
));
4794 static const char *expected_syms2
[] = {
4797 SELF_CHECK (check_find_bounds_finds (mock_index
,
4798 "\377\377", expected_syms2
));
4802 /* Test dw2_expand_symtabs_matching_symbol. */
4805 test_dw2_expand_symtabs_matching_symbol ()
4807 mock_mapped_index
mock_index (test_symbols
);
4809 /* We let all tests run until the end even if some fails, for debug
4811 bool any_mismatch
= false;
4813 /* Create the expected symbols list (an initializer_list). Needed
4814 because lists have commas, and we need to pass them to CHECK,
4815 which is a macro. */
4816 #define EXPECT(...) { __VA_ARGS__ }
4818 /* Wrapper for check_match that passes down the current
4819 __FILE__/__LINE__. */
4820 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4821 any_mismatch |= !check_match (__FILE__, __LINE__, \
4823 NAME, MATCH_TYPE, COMPLETION_MODE, \
4826 /* Identity checks. */
4827 for (const char *sym
: test_symbols
)
4829 /* Should be able to match all existing symbols. */
4830 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4833 /* Should be able to match all existing symbols with
4835 std::string with_params
= std::string (sym
) + "(int)";
4836 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4839 /* Should be able to match all existing symbols with
4840 parameters and qualifiers. */
4841 with_params
= std::string (sym
) + " ( int ) const";
4842 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4845 /* This should really find sym, but cp-name-parser.y doesn't
4846 know about lvalue/rvalue qualifiers yet. */
4847 with_params
= std::string (sym
) + " ( int ) &&";
4848 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4852 /* Check that the name matching algorithm for completion doesn't get
4853 confused with Latin1 'ÿ' / 0xff. */
4855 static const char str
[] = "\377";
4856 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4857 EXPECT ("\377", "\377\377123"));
4860 /* Check that the increment-last-char in the matching algorithm for
4861 completion doesn't match "t1_fund" when completing "t1_func". */
4863 static const char str
[] = "t1_func";
4864 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4865 EXPECT ("t1_func", "t1_func1"));
4868 /* Check that completion mode works at each prefix of the expected
4871 static const char str
[] = "function(int)";
4872 size_t len
= strlen (str
);
4875 for (size_t i
= 1; i
< len
; i
++)
4877 lookup
.assign (str
, i
);
4878 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4879 EXPECT ("function"));
4883 /* While "w" is a prefix of both components, the match function
4884 should still only be called once. */
4886 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4888 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4892 /* Same, with a "complicated" symbol. */
4894 static const char str
[] = Z_SYM_NAME
;
4895 size_t len
= strlen (str
);
4898 for (size_t i
= 1; i
< len
; i
++)
4900 lookup
.assign (str
, i
);
4901 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4902 EXPECT (Z_SYM_NAME
));
4906 /* In FULL mode, an incomplete symbol doesn't match. */
4908 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4912 /* A complete symbol with parameters matches any overload, since the
4913 index has no overload info. */
4915 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4916 EXPECT ("std::zfunction", "std::zfunction2"));
4917 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4918 EXPECT ("std::zfunction", "std::zfunction2"));
4919 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4920 EXPECT ("std::zfunction", "std::zfunction2"));
4923 /* Check that whitespace is ignored appropriately. A symbol with a
4924 template argument list. */
4926 static const char expected
[] = "ns::foo<int>";
4927 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4929 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4933 /* Check that whitespace is ignored appropriately. A symbol with a
4934 template argument list that includes a pointer. */
4936 static const char expected
[] = "ns::foo<char*>";
4937 /* Try both completion and non-completion modes. */
4938 static const bool completion_mode
[2] = {false, true};
4939 for (size_t i
= 0; i
< 2; i
++)
4941 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4942 completion_mode
[i
], EXPECT (expected
));
4943 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4944 completion_mode
[i
], EXPECT (expected
));
4946 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4947 completion_mode
[i
], EXPECT (expected
));
4948 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4949 completion_mode
[i
], EXPECT (expected
));
4954 /* Check method qualifiers are ignored. */
4955 static const char expected
[] = "ns::foo<char*>";
4956 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4957 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4958 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4959 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4960 CHECK_MATCH ("foo < char * > ( int ) const",
4961 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4962 CHECK_MATCH ("foo < char * > ( int ) &&",
4963 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4966 /* Test lookup names that don't match anything. */
4968 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4971 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4975 /* Some wild matching tests, exercising "(anonymous namespace)",
4976 which should not be confused with a parameter list. */
4978 static const char *syms
[] = {
4982 "A :: B :: C ( int )",
4987 for (const char *s
: syms
)
4989 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4990 EXPECT ("(anonymous namespace)::A::B::C"));
4995 static const char expected
[] = "ns2::tmpl<int>::foo2";
4996 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4998 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
5002 SELF_CHECK (!any_mismatch
);
5011 test_mapped_index_find_name_component_bounds ();
5012 test_dw2_expand_symtabs_matching_symbol ();
5015 }} // namespace selftests::dw2_expand_symtabs_matching
5017 #endif /* GDB_SELF_TEST */
5019 /* If FILE_MATCHER is NULL or if PER_CU has
5020 dwarf2_per_cu_quick_data::MARK set (see
5021 dw_expand_symtabs_matching_file_matcher), expand the CU and call
5022 EXPANSION_NOTIFY on it. */
5025 dw2_expand_symtabs_matching_one
5026 (struct dwarf2_per_cu_data
*per_cu
,
5027 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5028 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
5030 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
5032 bool symtab_was_null
5033 = (per_cu
->v
.quick
->compunit_symtab
== NULL
);
5035 dw2_instantiate_symtab (per_cu
, false);
5037 if (expansion_notify
!= NULL
5039 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
5040 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
5044 /* Helper for dw2_expand_matching symtabs. Called on each symbol
5045 matched, to expand corresponding CUs that were marked. IDX is the
5046 index of the symbol name that matched. */
5049 dw2_expand_marked_cus
5050 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
5051 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5052 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5055 offset_type
*vec
, vec_len
, vec_idx
;
5056 bool global_seen
= false;
5057 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
5059 vec
= (offset_type
*) (index
.constant_pool
5060 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
5061 vec_len
= MAYBE_SWAP (vec
[0]);
5062 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
5064 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
5065 /* This value is only valid for index versions >= 7. */
5066 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
5067 gdb_index_symbol_kind symbol_kind
=
5068 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
5069 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
5070 /* Only check the symbol attributes if they're present.
5071 Indices prior to version 7 don't record them,
5072 and indices >= 7 may elide them for certain symbols
5073 (gold does this). */
5076 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
5078 /* Work around gold/15646. */
5081 if (!is_static
&& global_seen
)
5087 /* Only check the symbol's kind if it has one. */
5092 case VARIABLES_DOMAIN
:
5093 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
5096 case FUNCTIONS_DOMAIN
:
5097 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
5101 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
5104 case MODULES_DOMAIN
:
5105 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
5113 /* Don't crash on bad data. */
5114 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
5115 + dwarf2_per_objfile
->all_type_units
.size ()))
5117 complaint (_(".gdb_index entry has bad CU index"
5119 objfile_name (dwarf2_per_objfile
->objfile
));
5123 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
5124 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5129 /* If FILE_MATCHER is non-NULL, set all the
5130 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
5131 that match FILE_MATCHER. */
5134 dw_expand_symtabs_matching_file_matcher
5135 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5136 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
5138 if (file_matcher
== NULL
)
5141 objfile
*const objfile
= dwarf2_per_objfile
->objfile
;
5143 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
5145 NULL
, xcalloc
, xfree
));
5146 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
5148 NULL
, xcalloc
, xfree
));
5150 /* The rule is CUs specify all the files, including those used by
5151 any TU, so there's no need to scan TUs here. */
5153 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5157 per_cu
->v
.quick
->mark
= 0;
5159 /* We only need to look at symtabs not already expanded. */
5160 if (per_cu
->v
.quick
->compunit_symtab
)
5163 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
5164 if (file_data
== NULL
)
5167 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
5169 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
5171 per_cu
->v
.quick
->mark
= 1;
5175 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
5177 const char *this_real_name
;
5179 if (file_matcher (file_data
->file_names
[j
], false))
5181 per_cu
->v
.quick
->mark
= 1;
5185 /* Before we invoke realpath, which can get expensive when many
5186 files are involved, do a quick comparison of the basenames. */
5187 if (!basenames_may_differ
5188 && !file_matcher (lbasename (file_data
->file_names
[j
]),
5192 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
5193 if (file_matcher (this_real_name
, false))
5195 per_cu
->v
.quick
->mark
= 1;
5200 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
5201 ? visited_found
.get ()
5202 : visited_not_found
.get (),
5209 dw2_expand_symtabs_matching
5210 (struct objfile
*objfile
,
5211 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5212 const lookup_name_info
&lookup_name
,
5213 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5214 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5215 enum search_domain kind
)
5217 struct dwarf2_per_objfile
*dwarf2_per_objfile
5218 = get_dwarf2_per_objfile (objfile
);
5220 /* index_table is NULL if OBJF_READNOW. */
5221 if (!dwarf2_per_objfile
->index_table
)
5224 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5226 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
5228 dw2_expand_symtabs_matching_symbol (index
, lookup_name
,
5230 kind
, [&] (offset_type idx
)
5232 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
5233 expansion_notify
, kind
);
5238 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
5241 static struct compunit_symtab
*
5242 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
5247 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
5248 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
5251 if (cust
->includes
== NULL
)
5254 for (i
= 0; cust
->includes
[i
]; ++i
)
5256 struct compunit_symtab
*s
= cust
->includes
[i
];
5258 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
5266 static struct compunit_symtab
*
5267 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
5268 struct bound_minimal_symbol msymbol
,
5270 struct obj_section
*section
,
5273 struct dwarf2_per_cu_data
*data
;
5274 struct compunit_symtab
*result
;
5276 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
5279 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
5280 data
= (struct dwarf2_per_cu_data
*) addrmap_find
5281 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
5285 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
5286 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
5287 paddress (get_objfile_arch (objfile
), pc
));
5290 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
,
5293 gdb_assert (result
!= NULL
);
5298 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
5299 void *data
, int need_fullname
)
5301 struct dwarf2_per_objfile
*dwarf2_per_objfile
5302 = get_dwarf2_per_objfile (objfile
);
5304 if (!dwarf2_per_objfile
->filenames_cache
)
5306 dwarf2_per_objfile
->filenames_cache
.emplace ();
5308 htab_up
visited (htab_create_alloc (10,
5309 htab_hash_pointer
, htab_eq_pointer
,
5310 NULL
, xcalloc
, xfree
));
5312 /* The rule is CUs specify all the files, including those used
5313 by any TU, so there's no need to scan TUs here. We can
5314 ignore file names coming from already-expanded CUs. */
5316 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5318 if (per_cu
->v
.quick
->compunit_symtab
)
5320 void **slot
= htab_find_slot (visited
.get (),
5321 per_cu
->v
.quick
->file_names
,
5324 *slot
= per_cu
->v
.quick
->file_names
;
5328 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5330 /* We only need to look at symtabs not already expanded. */
5331 if (per_cu
->v
.quick
->compunit_symtab
)
5334 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
5335 if (file_data
== NULL
)
5338 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
5341 /* Already visited. */
5346 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
5348 const char *filename
= file_data
->file_names
[j
];
5349 dwarf2_per_objfile
->filenames_cache
->seen (filename
);
5354 dwarf2_per_objfile
->filenames_cache
->traverse ([&] (const char *filename
)
5356 gdb::unique_xmalloc_ptr
<char> this_real_name
;
5359 this_real_name
= gdb_realpath (filename
);
5360 (*fun
) (filename
, this_real_name
.get (), data
);
5365 dw2_has_symbols (struct objfile
*objfile
)
5370 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
5373 dw2_find_last_source_symtab
,
5374 dw2_forget_cached_source_info
,
5375 dw2_map_symtabs_matching_filename
,
5379 dw2_expand_symtabs_for_function
,
5380 dw2_expand_all_symtabs
,
5381 dw2_expand_symtabs_with_fullname
,
5382 dw2_map_matching_symbols
,
5383 dw2_expand_symtabs_matching
,
5384 dw2_find_pc_sect_compunit_symtab
,
5386 dw2_map_symbol_filenames
5389 /* DWARF-5 debug_names reader. */
5391 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
5392 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
5394 /* A helper function that reads the .debug_names section in SECTION
5395 and fills in MAP. FILENAME is the name of the file containing the
5396 section; it is used for error reporting.
5398 Returns true if all went well, false otherwise. */
5401 read_debug_names_from_section (struct objfile
*objfile
,
5402 const char *filename
,
5403 struct dwarf2_section_info
*section
,
5404 mapped_debug_names
&map
)
5406 if (dwarf2_section_empty_p (section
))
5409 /* Older elfutils strip versions could keep the section in the main
5410 executable while splitting it for the separate debug info file. */
5411 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
5414 dwarf2_read_section (objfile
, section
);
5416 map
.dwarf5_byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
5418 const gdb_byte
*addr
= section
->buffer
;
5420 bfd
*const abfd
= get_section_bfd_owner (section
);
5422 unsigned int bytes_read
;
5423 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
5426 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
5427 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
5428 if (bytes_read
+ length
!= section
->size
)
5430 /* There may be multiple per-CU indices. */
5431 warning (_("Section .debug_names in %s length %s does not match "
5432 "section length %s, ignoring .debug_names."),
5433 filename
, plongest (bytes_read
+ length
),
5434 pulongest (section
->size
));
5438 /* The version number. */
5439 uint16_t version
= read_2_bytes (abfd
, addr
);
5443 warning (_("Section .debug_names in %s has unsupported version %d, "
5444 "ignoring .debug_names."),
5450 uint16_t padding
= read_2_bytes (abfd
, addr
);
5454 warning (_("Section .debug_names in %s has unsupported padding %d, "
5455 "ignoring .debug_names."),
5460 /* comp_unit_count - The number of CUs in the CU list. */
5461 map
.cu_count
= read_4_bytes (abfd
, addr
);
5464 /* local_type_unit_count - The number of TUs in the local TU
5466 map
.tu_count
= read_4_bytes (abfd
, addr
);
5469 /* foreign_type_unit_count - The number of TUs in the foreign TU
5471 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
5473 if (foreign_tu_count
!= 0)
5475 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
5476 "ignoring .debug_names."),
5477 filename
, static_cast<unsigned long> (foreign_tu_count
));
5481 /* bucket_count - The number of hash buckets in the hash lookup
5483 map
.bucket_count
= read_4_bytes (abfd
, addr
);
5486 /* name_count - The number of unique names in the index. */
5487 map
.name_count
= read_4_bytes (abfd
, addr
);
5490 /* abbrev_table_size - The size in bytes of the abbreviations
5492 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
5495 /* augmentation_string_size - The size in bytes of the augmentation
5496 string. This value is rounded up to a multiple of 4. */
5497 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
5499 map
.augmentation_is_gdb
= ((augmentation_string_size
5500 == sizeof (dwarf5_augmentation
))
5501 && memcmp (addr
, dwarf5_augmentation
,
5502 sizeof (dwarf5_augmentation
)) == 0);
5503 augmentation_string_size
+= (-augmentation_string_size
) & 3;
5504 addr
+= augmentation_string_size
;
5507 map
.cu_table_reordered
= addr
;
5508 addr
+= map
.cu_count
* map
.offset_size
;
5510 /* List of Local TUs */
5511 map
.tu_table_reordered
= addr
;
5512 addr
+= map
.tu_count
* map
.offset_size
;
5514 /* Hash Lookup Table */
5515 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5516 addr
+= map
.bucket_count
* 4;
5517 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5518 addr
+= map
.name_count
* 4;
5521 map
.name_table_string_offs_reordered
= addr
;
5522 addr
+= map
.name_count
* map
.offset_size
;
5523 map
.name_table_entry_offs_reordered
= addr
;
5524 addr
+= map
.name_count
* map
.offset_size
;
5526 const gdb_byte
*abbrev_table_start
= addr
;
5529 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5534 const auto insertpair
5535 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
5536 if (!insertpair
.second
)
5538 warning (_("Section .debug_names in %s has duplicate index %s, "
5539 "ignoring .debug_names."),
5540 filename
, pulongest (index_num
));
5543 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
5544 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5549 mapped_debug_names::index_val::attr attr
;
5550 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5552 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5554 if (attr
.form
== DW_FORM_implicit_const
)
5556 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
5560 if (attr
.dw_idx
== 0 && attr
.form
== 0)
5562 indexval
.attr_vec
.push_back (std::move (attr
));
5565 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
5567 warning (_("Section .debug_names in %s has abbreviation_table "
5568 "of size %s vs. written as %u, ignoring .debug_names."),
5569 filename
, plongest (addr
- abbrev_table_start
),
5573 map
.entry_pool
= addr
;
5578 /* A helper for create_cus_from_debug_names that handles the MAP's CU
5582 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5583 const mapped_debug_names
&map
,
5584 dwarf2_section_info
§ion
,
5587 sect_offset sect_off_prev
;
5588 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5590 sect_offset sect_off_next
;
5591 if (i
< map
.cu_count
)
5594 = (sect_offset
) (extract_unsigned_integer
5595 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5597 map
.dwarf5_byte_order
));
5600 sect_off_next
= (sect_offset
) section
.size
;
5603 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5604 dwarf2_per_cu_data
*per_cu
5605 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
5606 sect_off_prev
, length
);
5607 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
5609 sect_off_prev
= sect_off_next
;
5613 /* Read the CU list from the mapped index, and use it to create all
5614 the CU objects for this dwarf2_per_objfile. */
5617 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5618 const mapped_debug_names
&map
,
5619 const mapped_debug_names
&dwz_map
)
5621 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
5622 dwarf2_per_objfile
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5624 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
5625 dwarf2_per_objfile
->info
,
5626 false /* is_dwz */);
5628 if (dwz_map
.cu_count
== 0)
5631 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5632 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
5636 /* Read .debug_names. If everything went ok, initialize the "quick"
5637 elements of all the CUs and return true. Otherwise, return false. */
5640 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
5642 std::unique_ptr
<mapped_debug_names
> map
5643 (new mapped_debug_names (dwarf2_per_objfile
));
5644 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
5645 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5647 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5648 &dwarf2_per_objfile
->debug_names
,
5652 /* Don't use the index if it's empty. */
5653 if (map
->name_count
== 0)
5656 /* If there is a .dwz file, read it so we can get its CU list as
5658 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5661 if (!read_debug_names_from_section (objfile
,
5662 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5663 &dwz
->debug_names
, dwz_map
))
5665 warning (_("could not read '.debug_names' section from %s; skipping"),
5666 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5671 create_cus_from_debug_names (dwarf2_per_objfile
, *map
, dwz_map
);
5673 if (map
->tu_count
!= 0)
5675 /* We can only handle a single .debug_types when we have an
5677 if (dwarf2_per_objfile
->types
.size () != 1)
5680 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
5682 create_signatured_type_table_from_debug_names
5683 (dwarf2_per_objfile
, *map
, section
, &dwarf2_per_objfile
->abbrev
);
5686 create_addrmap_from_aranges (dwarf2_per_objfile
,
5687 &dwarf2_per_objfile
->debug_aranges
);
5689 dwarf2_per_objfile
->debug_names_table
= std::move (map
);
5690 dwarf2_per_objfile
->using_index
= 1;
5691 dwarf2_per_objfile
->quick_file_names_table
=
5692 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
5697 /* Type used to manage iterating over all CUs looking for a symbol for
5700 class dw2_debug_names_iterator
5703 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5704 gdb::optional
<block_enum
> block_index
,
5707 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5708 m_addr (find_vec_in_debug_names (map
, name
))
5711 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5712 search_domain search
, uint32_t namei
)
5715 m_addr (find_vec_in_debug_names (map
, namei
))
5718 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5719 block_enum block_index
, domain_enum domain
,
5721 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5722 m_addr (find_vec_in_debug_names (map
, namei
))
5725 /* Return the next matching CU or NULL if there are no more. */
5726 dwarf2_per_cu_data
*next ();
5729 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5731 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5734 /* The internalized form of .debug_names. */
5735 const mapped_debug_names
&m_map
;
5737 /* If set, only look for symbols that match that block. Valid values are
5738 GLOBAL_BLOCK and STATIC_BLOCK. */
5739 const gdb::optional
<block_enum
> m_block_index
;
5741 /* The kind of symbol we're looking for. */
5742 const domain_enum m_domain
= UNDEF_DOMAIN
;
5743 const search_domain m_search
= ALL_DOMAIN
;
5745 /* The list of CUs from the index entry of the symbol, or NULL if
5747 const gdb_byte
*m_addr
;
5751 mapped_debug_names::namei_to_name (uint32_t namei
) const
5753 const ULONGEST namei_string_offs
5754 = extract_unsigned_integer ((name_table_string_offs_reordered
5755 + namei
* offset_size
),
5758 return read_indirect_string_at_offset
5759 (dwarf2_per_objfile
, dwarf2_per_objfile
->objfile
->obfd
, namei_string_offs
);
5762 /* Find a slot in .debug_names for the object named NAME. If NAME is
5763 found, return pointer to its pool data. If NAME cannot be found,
5767 dw2_debug_names_iterator::find_vec_in_debug_names
5768 (const mapped_debug_names
&map
, const char *name
)
5770 int (*cmp
) (const char *, const char *);
5772 gdb::unique_xmalloc_ptr
<char> without_params
;
5773 if (current_language
->la_language
== language_cplus
5774 || current_language
->la_language
== language_fortran
5775 || current_language
->la_language
== language_d
)
5777 /* NAME is already canonical. Drop any qualifiers as
5778 .debug_names does not contain any. */
5780 if (strchr (name
, '(') != NULL
)
5782 without_params
= cp_remove_params (name
);
5783 if (without_params
!= NULL
)
5784 name
= without_params
.get ();
5788 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5790 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5792 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5793 (map
.bucket_table_reordered
5794 + (full_hash
% map
.bucket_count
)), 4,
5795 map
.dwarf5_byte_order
);
5799 if (namei
>= map
.name_count
)
5801 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5803 namei
, map
.name_count
,
5804 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5810 const uint32_t namei_full_hash
5811 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5812 (map
.hash_table_reordered
+ namei
), 4,
5813 map
.dwarf5_byte_order
);
5814 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5817 if (full_hash
== namei_full_hash
)
5819 const char *const namei_string
= map
.namei_to_name (namei
);
5821 #if 0 /* An expensive sanity check. */
5822 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5824 complaint (_("Wrong .debug_names hash for string at index %u "
5826 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5831 if (cmp (namei_string
, name
) == 0)
5833 const ULONGEST namei_entry_offs
5834 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5835 + namei
* map
.offset_size
),
5836 map
.offset_size
, map
.dwarf5_byte_order
);
5837 return map
.entry_pool
+ namei_entry_offs
;
5842 if (namei
>= map
.name_count
)
5848 dw2_debug_names_iterator::find_vec_in_debug_names
5849 (const mapped_debug_names
&map
, uint32_t namei
)
5851 if (namei
>= map
.name_count
)
5853 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5855 namei
, map
.name_count
,
5856 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5860 const ULONGEST namei_entry_offs
5861 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5862 + namei
* map
.offset_size
),
5863 map
.offset_size
, map
.dwarf5_byte_order
);
5864 return map
.entry_pool
+ namei_entry_offs
;
5867 /* See dw2_debug_names_iterator. */
5869 dwarf2_per_cu_data
*
5870 dw2_debug_names_iterator::next ()
5875 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
5876 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5877 bfd
*const abfd
= objfile
->obfd
;
5881 unsigned int bytes_read
;
5882 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5883 m_addr
+= bytes_read
;
5887 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5888 if (indexval_it
== m_map
.abbrev_map
.cend ())
5890 complaint (_("Wrong .debug_names undefined abbrev code %s "
5892 pulongest (abbrev
), objfile_name (objfile
));
5895 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5896 enum class symbol_linkage
{
5900 } symbol_linkage_
= symbol_linkage::unknown
;
5901 dwarf2_per_cu_data
*per_cu
= NULL
;
5902 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5907 case DW_FORM_implicit_const
:
5908 ull
= attr
.implicit_const
;
5910 case DW_FORM_flag_present
:
5914 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5915 m_addr
+= bytes_read
;
5918 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5919 dwarf_form_name (attr
.form
),
5920 objfile_name (objfile
));
5923 switch (attr
.dw_idx
)
5925 case DW_IDX_compile_unit
:
5926 /* Don't crash on bad data. */
5927 if (ull
>= dwarf2_per_objfile
->all_comp_units
.size ())
5929 complaint (_(".debug_names entry has bad CU index %s"
5932 objfile_name (dwarf2_per_objfile
->objfile
));
5935 per_cu
= dwarf2_per_objfile
->get_cutu (ull
);
5937 case DW_IDX_type_unit
:
5938 /* Don't crash on bad data. */
5939 if (ull
>= dwarf2_per_objfile
->all_type_units
.size ())
5941 complaint (_(".debug_names entry has bad TU index %s"
5944 objfile_name (dwarf2_per_objfile
->objfile
));
5947 per_cu
= &dwarf2_per_objfile
->get_tu (ull
)->per_cu
;
5949 case DW_IDX_GNU_internal
:
5950 if (!m_map
.augmentation_is_gdb
)
5952 symbol_linkage_
= symbol_linkage::static_
;
5954 case DW_IDX_GNU_external
:
5955 if (!m_map
.augmentation_is_gdb
)
5957 symbol_linkage_
= symbol_linkage::extern_
;
5962 /* Skip if already read in. */
5963 if (per_cu
->v
.quick
->compunit_symtab
)
5966 /* Check static vs global. */
5967 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5969 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5970 const bool symbol_is_static
=
5971 symbol_linkage_
== symbol_linkage::static_
;
5972 if (want_static
!= symbol_is_static
)
5976 /* Match dw2_symtab_iter_next, symbol_kind
5977 and debug_names::psymbol_tag. */
5981 switch (indexval
.dwarf_tag
)
5983 case DW_TAG_variable
:
5984 case DW_TAG_subprogram
:
5985 /* Some types are also in VAR_DOMAIN. */
5986 case DW_TAG_typedef
:
5987 case DW_TAG_structure_type
:
5994 switch (indexval
.dwarf_tag
)
5996 case DW_TAG_typedef
:
5997 case DW_TAG_structure_type
:
6004 switch (indexval
.dwarf_tag
)
6007 case DW_TAG_variable
:
6014 switch (indexval
.dwarf_tag
)
6026 /* Match dw2_expand_symtabs_matching, symbol_kind and
6027 debug_names::psymbol_tag. */
6030 case VARIABLES_DOMAIN
:
6031 switch (indexval
.dwarf_tag
)
6033 case DW_TAG_variable
:
6039 case FUNCTIONS_DOMAIN
:
6040 switch (indexval
.dwarf_tag
)
6042 case DW_TAG_subprogram
:
6049 switch (indexval
.dwarf_tag
)
6051 case DW_TAG_typedef
:
6052 case DW_TAG_structure_type
:
6058 case MODULES_DOMAIN
:
6059 switch (indexval
.dwarf_tag
)
6073 static struct compunit_symtab
*
6074 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
6075 const char *name
, domain_enum domain
)
6077 struct dwarf2_per_objfile
*dwarf2_per_objfile
6078 = get_dwarf2_per_objfile (objfile
);
6080 const auto &mapp
= dwarf2_per_objfile
->debug_names_table
;
6083 /* index is NULL if OBJF_READNOW. */
6086 const auto &map
= *mapp
;
6088 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
);
6090 struct compunit_symtab
*stab_best
= NULL
;
6091 struct dwarf2_per_cu_data
*per_cu
;
6092 while ((per_cu
= iter
.next ()) != NULL
)
6094 struct symbol
*sym
, *with_opaque
= NULL
;
6095 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
6096 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
6097 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
6099 sym
= block_find_symbol (block
, name
, domain
,
6100 block_find_non_opaque_type_preferred
,
6103 /* Some caution must be observed with overloaded functions and
6104 methods, since the index will not contain any overload
6105 information (but NAME might contain it). */
6108 && strcmp_iw (sym
->search_name (), name
) == 0)
6110 if (with_opaque
!= NULL
6111 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
6114 /* Keep looking through other CUs. */
6120 /* This dumps minimal information about .debug_names. It is called
6121 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
6122 uses this to verify that .debug_names has been loaded. */
6125 dw2_debug_names_dump (struct objfile
*objfile
)
6127 struct dwarf2_per_objfile
*dwarf2_per_objfile
6128 = get_dwarf2_per_objfile (objfile
);
6130 gdb_assert (dwarf2_per_objfile
->using_index
);
6131 printf_filtered (".debug_names:");
6132 if (dwarf2_per_objfile
->debug_names_table
)
6133 printf_filtered (" exists\n");
6135 printf_filtered (" faked for \"readnow\"\n");
6136 printf_filtered ("\n");
6140 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
6141 const char *func_name
)
6143 struct dwarf2_per_objfile
*dwarf2_per_objfile
6144 = get_dwarf2_per_objfile (objfile
);
6146 /* dwarf2_per_objfile->debug_names_table is NULL if OBJF_READNOW. */
6147 if (dwarf2_per_objfile
->debug_names_table
)
6149 const mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6151 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
);
6153 struct dwarf2_per_cu_data
*per_cu
;
6154 while ((per_cu
= iter
.next ()) != NULL
)
6155 dw2_instantiate_symtab (per_cu
, false);
6160 dw2_debug_names_map_matching_symbols
6161 (struct objfile
*objfile
,
6162 const lookup_name_info
&name
, domain_enum domain
,
6164 gdb::function_view
<symbol_found_callback_ftype
> callback
,
6165 symbol_compare_ftype
*ordered_compare
)
6167 struct dwarf2_per_objfile
*dwarf2_per_objfile
6168 = get_dwarf2_per_objfile (objfile
);
6170 /* debug_names_table is NULL if OBJF_READNOW. */
6171 if (!dwarf2_per_objfile
->debug_names_table
)
6174 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6175 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
6177 const char *match_name
= name
.ada ().lookup_name ().c_str ();
6178 auto matcher
= [&] (const char *symname
)
6180 if (ordered_compare
== nullptr)
6182 return ordered_compare (symname
, match_name
) == 0;
6185 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
6186 [&] (offset_type namei
)
6188 /* The name was matched, now expand corresponding CUs that were
6190 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
);
6192 struct dwarf2_per_cu_data
*per_cu
;
6193 while ((per_cu
= iter
.next ()) != NULL
)
6194 dw2_expand_symtabs_matching_one (per_cu
, nullptr, nullptr);
6198 /* It's a shame we couldn't do this inside the
6199 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
6200 that have already been expanded. Instead, this loop matches what
6201 the psymtab code does. */
6202 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
6204 struct compunit_symtab
*cust
= per_cu
->v
.quick
->compunit_symtab
;
6205 if (cust
!= nullptr)
6207 const struct block
*block
6208 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
6209 if (!iterate_over_symbols_terminated (block
, name
,
6217 dw2_debug_names_expand_symtabs_matching
6218 (struct objfile
*objfile
,
6219 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
6220 const lookup_name_info
&lookup_name
,
6221 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
6222 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
6223 enum search_domain kind
)
6225 struct dwarf2_per_objfile
*dwarf2_per_objfile
6226 = get_dwarf2_per_objfile (objfile
);
6228 /* debug_names_table is NULL if OBJF_READNOW. */
6229 if (!dwarf2_per_objfile
->debug_names_table
)
6232 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
6234 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6236 dw2_expand_symtabs_matching_symbol (map
, lookup_name
,
6238 kind
, [&] (offset_type namei
)
6240 /* The name was matched, now expand corresponding CUs that were
6242 dw2_debug_names_iterator
iter (map
, kind
, namei
);
6244 struct dwarf2_per_cu_data
*per_cu
;
6245 while ((per_cu
= iter
.next ()) != NULL
)
6246 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
6252 const struct quick_symbol_functions dwarf2_debug_names_functions
=
6255 dw2_find_last_source_symtab
,
6256 dw2_forget_cached_source_info
,
6257 dw2_map_symtabs_matching_filename
,
6258 dw2_debug_names_lookup_symbol
,
6260 dw2_debug_names_dump
,
6261 dw2_debug_names_expand_symtabs_for_function
,
6262 dw2_expand_all_symtabs
,
6263 dw2_expand_symtabs_with_fullname
,
6264 dw2_debug_names_map_matching_symbols
,
6265 dw2_debug_names_expand_symtabs_matching
,
6266 dw2_find_pc_sect_compunit_symtab
,
6268 dw2_map_symbol_filenames
6271 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
6272 to either a dwarf2_per_objfile or dwz_file object. */
6274 template <typename T
>
6275 static gdb::array_view
<const gdb_byte
>
6276 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
6278 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
6280 if (dwarf2_section_empty_p (section
))
6283 /* Older elfutils strip versions could keep the section in the main
6284 executable while splitting it for the separate debug info file. */
6285 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
6288 dwarf2_read_section (obj
, section
);
6290 /* dwarf2_section_info::size is a bfd_size_type, while
6291 gdb::array_view works with size_t. On 32-bit hosts, with
6292 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
6293 is 32-bit. So we need an explicit narrowing conversion here.
6294 This is fine, because it's impossible to allocate or mmap an
6295 array/buffer larger than what size_t can represent. */
6296 return gdb::make_array_view (section
->buffer
, section
->size
);
6299 /* Lookup the index cache for the contents of the index associated to
6302 static gdb::array_view
<const gdb_byte
>
6303 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_objfile
*dwarf2_obj
)
6305 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
6306 if (build_id
== nullptr)
6309 return global_index_cache
.lookup_gdb_index (build_id
,
6310 &dwarf2_obj
->index_cache_res
);
6313 /* Same as the above, but for DWZ. */
6315 static gdb::array_view
<const gdb_byte
>
6316 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
6318 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
6319 if (build_id
== nullptr)
6322 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
6325 /* See symfile.h. */
6328 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
6330 struct dwarf2_per_objfile
*dwarf2_per_objfile
6331 = get_dwarf2_per_objfile (objfile
);
6333 /* If we're about to read full symbols, don't bother with the
6334 indices. In this case we also don't care if some other debug
6335 format is making psymtabs, because they are all about to be
6337 if ((objfile
->flags
& OBJF_READNOW
))
6339 dwarf2_per_objfile
->using_index
= 1;
6340 create_all_comp_units (dwarf2_per_objfile
);
6341 create_all_type_units (dwarf2_per_objfile
);
6342 dwarf2_per_objfile
->quick_file_names_table
6343 = create_quick_file_names_table
6344 (dwarf2_per_objfile
->all_comp_units
.size ());
6346 for (int i
= 0; i
< (dwarf2_per_objfile
->all_comp_units
.size ()
6347 + dwarf2_per_objfile
->all_type_units
.size ()); ++i
)
6349 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
6351 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6352 struct dwarf2_per_cu_quick_data
);
6355 /* Return 1 so that gdb sees the "quick" functions. However,
6356 these functions will be no-ops because we will have expanded
6358 *index_kind
= dw_index_kind::GDB_INDEX
;
6362 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
6364 *index_kind
= dw_index_kind::DEBUG_NAMES
;
6368 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
6369 get_gdb_index_contents_from_section
<struct dwarf2_per_objfile
>,
6370 get_gdb_index_contents_from_section
<dwz_file
>))
6372 *index_kind
= dw_index_kind::GDB_INDEX
;
6376 /* ... otherwise, try to find the index in the index cache. */
6377 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
6378 get_gdb_index_contents_from_cache
,
6379 get_gdb_index_contents_from_cache_dwz
))
6381 global_index_cache
.hit ();
6382 *index_kind
= dw_index_kind::GDB_INDEX
;
6386 global_index_cache
.miss ();
6392 /* Build a partial symbol table. */
6395 dwarf2_build_psymtabs (struct objfile
*objfile
)
6397 struct dwarf2_per_objfile
*dwarf2_per_objfile
6398 = get_dwarf2_per_objfile (objfile
);
6400 init_psymbol_list (objfile
, 1024);
6404 /* This isn't really ideal: all the data we allocate on the
6405 objfile's obstack is still uselessly kept around. However,
6406 freeing it seems unsafe. */
6407 psymtab_discarder
psymtabs (objfile
);
6408 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
6411 /* (maybe) store an index in the cache. */
6412 global_index_cache
.store (dwarf2_per_objfile
);
6414 catch (const gdb_exception_error
&except
)
6416 exception_print (gdb_stderr
, except
);
6420 /* Return the total length of the CU described by HEADER. */
6423 get_cu_length (const struct comp_unit_head
*header
)
6425 return header
->initial_length_size
+ header
->length
;
6428 /* Return TRUE if SECT_OFF is within CU_HEADER. */
6431 offset_in_cu_p (const comp_unit_head
*cu_header
, sect_offset sect_off
)
6433 sect_offset bottom
= cu_header
->sect_off
;
6434 sect_offset top
= cu_header
->sect_off
+ get_cu_length (cu_header
);
6436 return sect_off
>= bottom
&& sect_off
< top
;
6439 /* Find the base address of the compilation unit for range lists and
6440 location lists. It will normally be specified by DW_AT_low_pc.
6441 In DWARF-3 draft 4, the base address could be overridden by
6442 DW_AT_entry_pc. It's been removed, but GCC still uses this for
6443 compilation units with discontinuous ranges. */
6446 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
6448 struct attribute
*attr
;
6451 cu
->base_address
= 0;
6453 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
6454 if (attr
!= nullptr)
6456 cu
->base_address
= attr_value_as_address (attr
);
6461 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6462 if (attr
!= nullptr)
6464 cu
->base_address
= attr_value_as_address (attr
);
6470 /* Read in the comp unit header information from the debug_info at info_ptr.
6471 Use rcuh_kind::COMPILE as the default type if not known by the caller.
6472 NOTE: This leaves members offset, first_die_offset to be filled in
6475 static const gdb_byte
*
6476 read_comp_unit_head (struct comp_unit_head
*cu_header
,
6477 const gdb_byte
*info_ptr
,
6478 struct dwarf2_section_info
*section
,
6479 rcuh_kind section_kind
)
6482 unsigned int bytes_read
;
6483 const char *filename
= get_section_file_name (section
);
6484 bfd
*abfd
= get_section_bfd_owner (section
);
6486 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
6487 cu_header
->initial_length_size
= bytes_read
;
6488 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
6489 info_ptr
+= bytes_read
;
6490 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
6491 if (cu_header
->version
< 2 || cu_header
->version
> 5)
6492 error (_("Dwarf Error: wrong version in compilation unit header "
6493 "(is %d, should be 2, 3, 4 or 5) [in module %s]"),
6494 cu_header
->version
, filename
);
6496 if (cu_header
->version
< 5)
6497 switch (section_kind
)
6499 case rcuh_kind::COMPILE
:
6500 cu_header
->unit_type
= DW_UT_compile
;
6502 case rcuh_kind::TYPE
:
6503 cu_header
->unit_type
= DW_UT_type
;
6506 internal_error (__FILE__
, __LINE__
,
6507 _("read_comp_unit_head: invalid section_kind"));
6511 cu_header
->unit_type
= static_cast<enum dwarf_unit_type
>
6512 (read_1_byte (abfd
, info_ptr
));
6514 switch (cu_header
->unit_type
)
6518 case DW_UT_skeleton
:
6519 case DW_UT_split_compile
:
6520 if (section_kind
!= rcuh_kind::COMPILE
)
6521 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6522 "(is %s, should be %s) [in module %s]"),
6523 dwarf_unit_type_name (cu_header
->unit_type
),
6524 dwarf_unit_type_name (DW_UT_type
), filename
);
6527 case DW_UT_split_type
:
6528 section_kind
= rcuh_kind::TYPE
;
6531 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6532 "(is %#04x, should be one of: %s, %s, %s, %s or %s) "
6533 "[in module %s]"), cu_header
->unit_type
,
6534 dwarf_unit_type_name (DW_UT_compile
),
6535 dwarf_unit_type_name (DW_UT_skeleton
),
6536 dwarf_unit_type_name (DW_UT_split_compile
),
6537 dwarf_unit_type_name (DW_UT_type
),
6538 dwarf_unit_type_name (DW_UT_split_type
), filename
);
6541 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6544 cu_header
->abbrev_sect_off
= (sect_offset
) read_offset (abfd
, info_ptr
,
6547 info_ptr
+= bytes_read
;
6548 if (cu_header
->version
< 5)
6550 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6553 signed_addr
= bfd_get_sign_extend_vma (abfd
);
6554 if (signed_addr
< 0)
6555 internal_error (__FILE__
, __LINE__
,
6556 _("read_comp_unit_head: dwarf from non elf file"));
6557 cu_header
->signed_addr_p
= signed_addr
;
6559 bool header_has_signature
= section_kind
== rcuh_kind::TYPE
6560 || cu_header
->unit_type
== DW_UT_skeleton
6561 || cu_header
->unit_type
== DW_UT_split_compile
;
6563 if (header_has_signature
)
6565 cu_header
->signature
= read_8_bytes (abfd
, info_ptr
);
6569 if (section_kind
== rcuh_kind::TYPE
)
6571 LONGEST type_offset
;
6572 type_offset
= read_offset (abfd
, info_ptr
, cu_header
, &bytes_read
);
6573 info_ptr
+= bytes_read
;
6574 cu_header
->type_cu_offset_in_tu
= (cu_offset
) type_offset
;
6575 if (to_underlying (cu_header
->type_cu_offset_in_tu
) != type_offset
)
6576 error (_("Dwarf Error: Too big type_offset in compilation unit "
6577 "header (is %s) [in module %s]"), plongest (type_offset
),
6584 /* Helper function that returns the proper abbrev section for
6587 static struct dwarf2_section_info
*
6588 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
6590 struct dwarf2_section_info
*abbrev
;
6591 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6593 if (this_cu
->is_dwz
)
6594 abbrev
= &dwarf2_get_dwz_file (dwarf2_per_objfile
)->abbrev
;
6596 abbrev
= &dwarf2_per_objfile
->abbrev
;
6601 /* Subroutine of read_and_check_comp_unit_head and
6602 read_and_check_type_unit_head to simplify them.
6603 Perform various error checking on the header. */
6606 error_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6607 struct comp_unit_head
*header
,
6608 struct dwarf2_section_info
*section
,
6609 struct dwarf2_section_info
*abbrev_section
)
6611 const char *filename
= get_section_file_name (section
);
6613 if (to_underlying (header
->abbrev_sect_off
)
6614 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
, abbrev_section
))
6615 error (_("Dwarf Error: bad offset (%s) in compilation unit header "
6616 "(offset %s + 6) [in module %s]"),
6617 sect_offset_str (header
->abbrev_sect_off
),
6618 sect_offset_str (header
->sect_off
),
6621 /* Cast to ULONGEST to use 64-bit arithmetic when possible to
6622 avoid potential 32-bit overflow. */
6623 if (((ULONGEST
) header
->sect_off
+ get_cu_length (header
))
6625 error (_("Dwarf Error: bad length (0x%x) in compilation unit header "
6626 "(offset %s + 0) [in module %s]"),
6627 header
->length
, sect_offset_str (header
->sect_off
),
6631 /* Read in a CU/TU header and perform some basic error checking.
6632 The contents of the header are stored in HEADER.
6633 The result is a pointer to the start of the first DIE. */
6635 static const gdb_byte
*
6636 read_and_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6637 struct comp_unit_head
*header
,
6638 struct dwarf2_section_info
*section
,
6639 struct dwarf2_section_info
*abbrev_section
,
6640 const gdb_byte
*info_ptr
,
6641 rcuh_kind section_kind
)
6643 const gdb_byte
*beg_of_comp_unit
= info_ptr
;
6645 header
->sect_off
= (sect_offset
) (beg_of_comp_unit
- section
->buffer
);
6647 info_ptr
= read_comp_unit_head (header
, info_ptr
, section
, section_kind
);
6649 header
->first_die_cu_offset
= (cu_offset
) (info_ptr
- beg_of_comp_unit
);
6651 error_check_comp_unit_head (dwarf2_per_objfile
, header
, section
,
6657 /* Fetch the abbreviation table offset from a comp or type unit header. */
6660 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6661 struct dwarf2_section_info
*section
,
6662 sect_offset sect_off
)
6664 bfd
*abfd
= get_section_bfd_owner (section
);
6665 const gdb_byte
*info_ptr
;
6666 unsigned int initial_length_size
, offset_size
;
6669 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
6670 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
6671 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6672 offset_size
= initial_length_size
== 4 ? 4 : 8;
6673 info_ptr
+= initial_length_size
;
6675 version
= read_2_bytes (abfd
, info_ptr
);
6679 /* Skip unit type and address size. */
6683 return (sect_offset
) read_offset_1 (abfd
, info_ptr
, offset_size
);
6686 /* Allocate a new partial symtab for file named NAME and mark this new
6687 partial symtab as being an include of PST. */
6690 dwarf2_create_include_psymtab (const char *name
, dwarf2_psymtab
*pst
,
6691 struct objfile
*objfile
)
6693 dwarf2_psymtab
*subpst
= new dwarf2_psymtab (name
, objfile
);
6695 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6697 /* It shares objfile->objfile_obstack. */
6698 subpst
->dirname
= pst
->dirname
;
6701 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
6702 subpst
->dependencies
[0] = pst
;
6703 subpst
->number_of_dependencies
= 1;
6705 /* No private part is necessary for include psymtabs. This property
6706 can be used to differentiate between such include psymtabs and
6707 the regular ones. */
6708 subpst
->per_cu_data
= nullptr;
6711 /* Read the Line Number Program data and extract the list of files
6712 included by the source file represented by PST. Build an include
6713 partial symtab for each of these included files. */
6716 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
6717 struct die_info
*die
,
6718 dwarf2_psymtab
*pst
)
6721 struct attribute
*attr
;
6723 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6724 if (attr
!= nullptr)
6725 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
6727 return; /* No linetable, so no includes. */
6729 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
6730 that we pass in the raw text_low here; that is ok because we're
6731 only decoding the line table to make include partial symtabs, and
6732 so the addresses aren't really used. */
6733 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
6734 pst
->raw_text_low (), 1);
6738 hash_signatured_type (const void *item
)
6740 const struct signatured_type
*sig_type
6741 = (const struct signatured_type
*) item
;
6743 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6744 return sig_type
->signature
;
6748 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6750 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6751 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6753 return lhs
->signature
== rhs
->signature
;
6756 /* Allocate a hash table for signatured types. */
6759 allocate_signatured_type_table (struct objfile
*objfile
)
6761 return htab_create_alloc_ex (41,
6762 hash_signatured_type
,
6765 &objfile
->objfile_obstack
,
6766 hashtab_obstack_allocate
,
6767 dummy_obstack_deallocate
);
6770 /* A helper function to add a signatured type CU to a table. */
6773 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6775 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6776 std::vector
<signatured_type
*> *all_type_units
6777 = (std::vector
<signatured_type
*> *) datum
;
6779 all_type_units
->push_back (sigt
);
6784 /* A helper for create_debug_types_hash_table. Read types from SECTION
6785 and fill them into TYPES_HTAB. It will process only type units,
6786 therefore DW_UT_type. */
6789 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6790 struct dwo_file
*dwo_file
,
6791 dwarf2_section_info
*section
, htab_t
&types_htab
,
6792 rcuh_kind section_kind
)
6794 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6795 struct dwarf2_section_info
*abbrev_section
;
6797 const gdb_byte
*info_ptr
, *end_ptr
;
6799 abbrev_section
= (dwo_file
!= NULL
6800 ? &dwo_file
->sections
.abbrev
6801 : &dwarf2_per_objfile
->abbrev
);
6803 if (dwarf_read_debug
)
6804 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6805 get_section_name (section
),
6806 get_section_file_name (abbrev_section
));
6808 dwarf2_read_section (objfile
, section
);
6809 info_ptr
= section
->buffer
;
6811 if (info_ptr
== NULL
)
6814 /* We can't set abfd until now because the section may be empty or
6815 not present, in which case the bfd is unknown. */
6816 abfd
= get_section_bfd_owner (section
);
6818 /* We don't use cutu_reader here because we don't need to read
6819 any dies: the signature is in the header. */
6821 end_ptr
= info_ptr
+ section
->size
;
6822 while (info_ptr
< end_ptr
)
6824 struct signatured_type
*sig_type
;
6825 struct dwo_unit
*dwo_tu
;
6827 const gdb_byte
*ptr
= info_ptr
;
6828 struct comp_unit_head header
;
6829 unsigned int length
;
6831 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6833 /* Initialize it due to a false compiler warning. */
6834 header
.signature
= -1;
6835 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6837 /* We need to read the type's signature in order to build the hash
6838 table, but we don't need anything else just yet. */
6840 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
6841 abbrev_section
, ptr
, section_kind
);
6843 length
= get_cu_length (&header
);
6845 /* Skip dummy type units. */
6846 if (ptr
>= info_ptr
+ length
6847 || peek_abbrev_code (abfd
, ptr
) == 0
6848 || header
.unit_type
!= DW_UT_type
)
6854 if (types_htab
== NULL
)
6857 types_htab
= allocate_dwo_unit_table (objfile
);
6859 types_htab
= allocate_signatured_type_table (objfile
);
6865 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6867 dwo_tu
->dwo_file
= dwo_file
;
6868 dwo_tu
->signature
= header
.signature
;
6869 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6870 dwo_tu
->section
= section
;
6871 dwo_tu
->sect_off
= sect_off
;
6872 dwo_tu
->length
= length
;
6876 /* N.B.: type_offset is not usable if this type uses a DWO file.
6877 The real type_offset is in the DWO file. */
6879 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6880 struct signatured_type
);
6881 sig_type
->signature
= header
.signature
;
6882 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6883 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6884 sig_type
->per_cu
.is_debug_types
= 1;
6885 sig_type
->per_cu
.section
= section
;
6886 sig_type
->per_cu
.sect_off
= sect_off
;
6887 sig_type
->per_cu
.length
= length
;
6890 slot
= htab_find_slot (types_htab
,
6891 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6893 gdb_assert (slot
!= NULL
);
6896 sect_offset dup_sect_off
;
6900 const struct dwo_unit
*dup_tu
6901 = (const struct dwo_unit
*) *slot
;
6903 dup_sect_off
= dup_tu
->sect_off
;
6907 const struct signatured_type
*dup_tu
6908 = (const struct signatured_type
*) *slot
;
6910 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6913 complaint (_("debug type entry at offset %s is duplicate to"
6914 " the entry at offset %s, signature %s"),
6915 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6916 hex_string (header
.signature
));
6918 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6920 if (dwarf_read_debug
> 1)
6921 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6922 sect_offset_str (sect_off
),
6923 hex_string (header
.signature
));
6929 /* Create the hash table of all entries in the .debug_types
6930 (or .debug_types.dwo) section(s).
6931 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6932 otherwise it is NULL.
6934 The result is a pointer to the hash table or NULL if there are no types.
6936 Note: This function processes DWO files only, not DWP files. */
6939 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6940 struct dwo_file
*dwo_file
,
6941 gdb::array_view
<dwarf2_section_info
> type_sections
,
6944 for (dwarf2_section_info
§ion
: type_sections
)
6945 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, §ion
,
6946 types_htab
, rcuh_kind::TYPE
);
6949 /* Create the hash table of all entries in the .debug_types section,
6950 and initialize all_type_units.
6951 The result is zero if there is an error (e.g. missing .debug_types section),
6952 otherwise non-zero. */
6955 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6957 htab_t types_htab
= NULL
;
6959 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
6960 &dwarf2_per_objfile
->info
, types_htab
,
6961 rcuh_kind::COMPILE
);
6962 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
6963 dwarf2_per_objfile
->types
, types_htab
);
6964 if (types_htab
== NULL
)
6966 dwarf2_per_objfile
->signatured_types
= NULL
;
6970 dwarf2_per_objfile
->signatured_types
= types_htab
;
6972 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
6973 dwarf2_per_objfile
->all_type_units
.reserve (htab_elements (types_htab
));
6975 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
,
6976 &dwarf2_per_objfile
->all_type_units
);
6981 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
6982 If SLOT is non-NULL, it is the entry to use in the hash table.
6983 Otherwise we find one. */
6985 static struct signatured_type
*
6986 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
6989 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6991 if (dwarf2_per_objfile
->all_type_units
.size ()
6992 == dwarf2_per_objfile
->all_type_units
.capacity ())
6993 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
6995 signatured_type
*sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6996 struct signatured_type
);
6998 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
6999 sig_type
->signature
= sig
;
7000 sig_type
->per_cu
.is_debug_types
= 1;
7001 if (dwarf2_per_objfile
->using_index
)
7003 sig_type
->per_cu
.v
.quick
=
7004 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7005 struct dwarf2_per_cu_quick_data
);
7010 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
7013 gdb_assert (*slot
== NULL
);
7015 /* The rest of sig_type must be filled in by the caller. */
7019 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
7020 Fill in SIG_ENTRY with DWO_ENTRY. */
7023 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
7024 struct signatured_type
*sig_entry
,
7025 struct dwo_unit
*dwo_entry
)
7027 /* Make sure we're not clobbering something we don't expect to. */
7028 gdb_assert (! sig_entry
->per_cu
.queued
);
7029 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
7030 if (dwarf2_per_objfile
->using_index
)
7032 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
7033 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
7036 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
7037 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
7038 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
7039 gdb_assert (sig_entry
->type_unit_group
== NULL
);
7040 gdb_assert (sig_entry
->dwo_unit
== NULL
);
7042 sig_entry
->per_cu
.section
= dwo_entry
->section
;
7043 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
7044 sig_entry
->per_cu
.length
= dwo_entry
->length
;
7045 sig_entry
->per_cu
.reading_dwo_directly
= 1;
7046 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
7047 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
7048 sig_entry
->dwo_unit
= dwo_entry
;
7051 /* Subroutine of lookup_signatured_type.
7052 If we haven't read the TU yet, create the signatured_type data structure
7053 for a TU to be read in directly from a DWO file, bypassing the stub.
7054 This is the "Stay in DWO Optimization": When there is no DWP file and we're
7055 using .gdb_index, then when reading a CU we want to stay in the DWO file
7056 containing that CU. Otherwise we could end up reading several other DWO
7057 files (due to comdat folding) to process the transitive closure of all the
7058 mentioned TUs, and that can be slow. The current DWO file will have every
7059 type signature that it needs.
7060 We only do this for .gdb_index because in the psymtab case we already have
7061 to read all the DWOs to build the type unit groups. */
7063 static struct signatured_type
*
7064 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7066 struct dwarf2_per_objfile
*dwarf2_per_objfile
7067 = cu
->per_cu
->dwarf2_per_objfile
;
7068 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7069 struct dwo_file
*dwo_file
;
7070 struct dwo_unit find_dwo_entry
, *dwo_entry
;
7071 struct signatured_type find_sig_entry
, *sig_entry
;
7074 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
7076 /* If TU skeletons have been removed then we may not have read in any
7078 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7080 dwarf2_per_objfile
->signatured_types
7081 = allocate_signatured_type_table (objfile
);
7084 /* We only ever need to read in one copy of a signatured type.
7085 Use the global signatured_types array to do our own comdat-folding
7086 of types. If this is the first time we're reading this TU, and
7087 the TU has an entry in .gdb_index, replace the recorded data from
7088 .gdb_index with this TU. */
7090 find_sig_entry
.signature
= sig
;
7091 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
7092 &find_sig_entry
, INSERT
);
7093 sig_entry
= (struct signatured_type
*) *slot
;
7095 /* We can get here with the TU already read, *or* in the process of being
7096 read. Don't reassign the global entry to point to this DWO if that's
7097 the case. Also note that if the TU is already being read, it may not
7098 have come from a DWO, the program may be a mix of Fission-compiled
7099 code and non-Fission-compiled code. */
7101 /* Have we already tried to read this TU?
7102 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
7103 needn't exist in the global table yet). */
7104 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
7107 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
7108 dwo_unit of the TU itself. */
7109 dwo_file
= cu
->dwo_unit
->dwo_file
;
7111 /* Ok, this is the first time we're reading this TU. */
7112 if (dwo_file
->tus
== NULL
)
7114 find_dwo_entry
.signature
= sig
;
7115 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_entry
);
7116 if (dwo_entry
== NULL
)
7119 /* If the global table doesn't have an entry for this TU, add one. */
7120 if (sig_entry
== NULL
)
7121 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
7123 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
7124 sig_entry
->per_cu
.tu_read
= 1;
7128 /* Subroutine of lookup_signatured_type.
7129 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
7130 then try the DWP file. If the TU stub (skeleton) has been removed then
7131 it won't be in .gdb_index. */
7133 static struct signatured_type
*
7134 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7136 struct dwarf2_per_objfile
*dwarf2_per_objfile
7137 = cu
->per_cu
->dwarf2_per_objfile
;
7138 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7139 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
7140 struct dwo_unit
*dwo_entry
;
7141 struct signatured_type find_sig_entry
, *sig_entry
;
7144 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
7145 gdb_assert (dwp_file
!= NULL
);
7147 /* If TU skeletons have been removed then we may not have read in any
7149 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7151 dwarf2_per_objfile
->signatured_types
7152 = allocate_signatured_type_table (objfile
);
7155 find_sig_entry
.signature
= sig
;
7156 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
7157 &find_sig_entry
, INSERT
);
7158 sig_entry
= (struct signatured_type
*) *slot
;
7160 /* Have we already tried to read this TU?
7161 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
7162 needn't exist in the global table yet). */
7163 if (sig_entry
!= NULL
)
7166 if (dwp_file
->tus
== NULL
)
7168 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
7169 sig
, 1 /* is_debug_types */);
7170 if (dwo_entry
== NULL
)
7173 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
7174 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
7179 /* Lookup a signature based type for DW_FORM_ref_sig8.
7180 Returns NULL if signature SIG is not present in the table.
7181 It is up to the caller to complain about this. */
7183 static struct signatured_type
*
7184 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7186 struct dwarf2_per_objfile
*dwarf2_per_objfile
7187 = cu
->per_cu
->dwarf2_per_objfile
;
7190 && dwarf2_per_objfile
->using_index
)
7192 /* We're in a DWO/DWP file, and we're using .gdb_index.
7193 These cases require special processing. */
7194 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
7195 return lookup_dwo_signatured_type (cu
, sig
);
7197 return lookup_dwp_signatured_type (cu
, sig
);
7201 struct signatured_type find_entry
, *entry
;
7203 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7205 find_entry
.signature
= sig
;
7206 entry
= ((struct signatured_type
*)
7207 htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
));
7212 /* Return the address base of the compile unit, which, if exists, is stored
7213 either at the attribute DW_AT_GNU_addr_base, or DW_AT_addr_base. */
7214 static gdb::optional
<ULONGEST
>
7215 lookup_addr_base (struct die_info
*comp_unit_die
)
7217 struct attribute
*attr
;
7218 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_addr_base
);
7219 if (attr
== nullptr)
7220 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_GNU_addr_base
);
7221 if (attr
== nullptr)
7222 return gdb::optional
<ULONGEST
> ();
7223 return DW_UNSND (attr
);
7226 /* Return range lists base of the compile unit, which, if exists, is stored
7227 either at the attribute DW_AT_rnglists_base or DW_AT_GNU_ranges_base. */
7229 lookup_ranges_base (struct die_info
*comp_unit_die
)
7231 struct attribute
*attr
;
7232 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_rnglists_base
);
7233 if (attr
== nullptr)
7234 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_GNU_ranges_base
);
7235 if (attr
== nullptr)
7237 return DW_UNSND (attr
);
7240 /* Low level DIE reading support. */
7242 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
7245 init_cu_die_reader (struct die_reader_specs
*reader
,
7246 struct dwarf2_cu
*cu
,
7247 struct dwarf2_section_info
*section
,
7248 struct dwo_file
*dwo_file
,
7249 struct abbrev_table
*abbrev_table
)
7251 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
7252 reader
->abfd
= get_section_bfd_owner (section
);
7254 reader
->dwo_file
= dwo_file
;
7255 reader
->die_section
= section
;
7256 reader
->buffer
= section
->buffer
;
7257 reader
->buffer_end
= section
->buffer
+ section
->size
;
7258 reader
->comp_dir
= NULL
;
7259 reader
->abbrev_table
= abbrev_table
;
7262 /* Subroutine of cutu_reader to simplify it.
7263 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
7264 There's just a lot of work to do, and cutu_reader is big enough
7267 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
7268 from it to the DIE in the DWO. If NULL we are skipping the stub.
7269 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
7270 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
7271 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
7272 STUB_COMP_DIR may be non-NULL.
7273 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE,*RESULT_HAS_CHILDREN
7274 are filled in with the info of the DIE from the DWO file.
7275 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
7276 from the dwo. Since *RESULT_READER references this abbrev table, it must be
7277 kept around for at least as long as *RESULT_READER.
7279 The result is non-zero if a valid (non-dummy) DIE was found. */
7282 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
7283 struct dwo_unit
*dwo_unit
,
7284 struct die_info
*stub_comp_unit_die
,
7285 const char *stub_comp_dir
,
7286 struct die_reader_specs
*result_reader
,
7287 const gdb_byte
**result_info_ptr
,
7288 struct die_info
**result_comp_unit_die
,
7289 int *result_has_children
,
7290 abbrev_table_up
*result_dwo_abbrev_table
)
7292 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7293 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7294 struct dwarf2_cu
*cu
= this_cu
->cu
;
7296 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7297 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
7298 int i
,num_extra_attrs
;
7299 struct dwarf2_section_info
*dwo_abbrev_section
;
7300 struct die_info
*comp_unit_die
;
7302 /* At most one of these may be provided. */
7303 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
7305 /* These attributes aren't processed until later:
7306 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
7307 DW_AT_comp_dir is used now, to find the DWO file, but it is also
7308 referenced later. However, these attributes are found in the stub
7309 which we won't have later. In order to not impose this complication
7310 on the rest of the code, we read them here and copy them to the
7319 if (stub_comp_unit_die
!= NULL
)
7321 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
7323 if (! this_cu
->is_debug_types
)
7324 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
7325 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
7326 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
7327 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
7328 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
7330 cu
->addr_base
= lookup_addr_base (stub_comp_unit_die
);
7332 /* There should be a DW_AT_rnglists_base (DW_AT_GNU_ranges_base) attribute
7333 here (if needed). We need the value before we can process
7335 cu
->ranges_base
= lookup_ranges_base (stub_comp_unit_die
);
7337 else if (stub_comp_dir
!= NULL
)
7339 /* Reconstruct the comp_dir attribute to simplify the code below. */
7340 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
7341 comp_dir
->name
= DW_AT_comp_dir
;
7342 comp_dir
->form
= DW_FORM_string
;
7343 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
7344 DW_STRING (comp_dir
) = stub_comp_dir
;
7347 /* Set up for reading the DWO CU/TU. */
7348 cu
->dwo_unit
= dwo_unit
;
7349 dwarf2_section_info
*section
= dwo_unit
->section
;
7350 dwarf2_read_section (objfile
, section
);
7351 abfd
= get_section_bfd_owner (section
);
7352 begin_info_ptr
= info_ptr
= (section
->buffer
7353 + to_underlying (dwo_unit
->sect_off
));
7354 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
7356 if (this_cu
->is_debug_types
)
7358 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
7360 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7361 &cu
->header
, section
,
7363 info_ptr
, rcuh_kind::TYPE
);
7364 /* This is not an assert because it can be caused by bad debug info. */
7365 if (sig_type
->signature
!= cu
->header
.signature
)
7367 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
7368 " TU at offset %s [in module %s]"),
7369 hex_string (sig_type
->signature
),
7370 hex_string (cu
->header
.signature
),
7371 sect_offset_str (dwo_unit
->sect_off
),
7372 bfd_get_filename (abfd
));
7374 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7375 /* For DWOs coming from DWP files, we don't know the CU length
7376 nor the type's offset in the TU until now. */
7377 dwo_unit
->length
= get_cu_length (&cu
->header
);
7378 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
7380 /* Establish the type offset that can be used to lookup the type.
7381 For DWO files, we don't know it until now. */
7382 sig_type
->type_offset_in_section
7383 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
7387 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7388 &cu
->header
, section
,
7390 info_ptr
, rcuh_kind::COMPILE
);
7391 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7392 /* For DWOs coming from DWP files, we don't know the CU length
7394 dwo_unit
->length
= get_cu_length (&cu
->header
);
7397 *result_dwo_abbrev_table
7398 = abbrev_table_read_table (dwarf2_per_objfile
, dwo_abbrev_section
,
7399 cu
->header
.abbrev_sect_off
);
7400 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
7401 result_dwo_abbrev_table
->get ());
7403 /* Read in the die, but leave space to copy over the attributes
7404 from the stub. This has the benefit of simplifying the rest of
7405 the code - all the work to maintain the illusion of a single
7406 DW_TAG_{compile,type}_unit DIE is done here. */
7407 num_extra_attrs
= ((stmt_list
!= NULL
)
7411 + (comp_dir
!= NULL
));
7412 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
7413 result_has_children
, num_extra_attrs
);
7415 /* Copy over the attributes from the stub to the DIE we just read in. */
7416 comp_unit_die
= *result_comp_unit_die
;
7417 i
= comp_unit_die
->num_attrs
;
7418 if (stmt_list
!= NULL
)
7419 comp_unit_die
->attrs
[i
++] = *stmt_list
;
7421 comp_unit_die
->attrs
[i
++] = *low_pc
;
7422 if (high_pc
!= NULL
)
7423 comp_unit_die
->attrs
[i
++] = *high_pc
;
7425 comp_unit_die
->attrs
[i
++] = *ranges
;
7426 if (comp_dir
!= NULL
)
7427 comp_unit_die
->attrs
[i
++] = *comp_dir
;
7428 comp_unit_die
->num_attrs
+= num_extra_attrs
;
7430 if (dwarf_die_debug
)
7432 fprintf_unfiltered (gdb_stdlog
,
7433 "Read die from %s@0x%x of %s:\n",
7434 get_section_name (section
),
7435 (unsigned) (begin_info_ptr
- section
->buffer
),
7436 bfd_get_filename (abfd
));
7437 dump_die (comp_unit_die
, dwarf_die_debug
);
7440 /* Save the comp_dir attribute. If there is no DWP file then we'll read
7441 TUs by skipping the stub and going directly to the entry in the DWO file.
7442 However, skipping the stub means we won't get DW_AT_comp_dir, so we have
7443 to get it via circuitous means. Blech. */
7444 if (comp_dir
!= NULL
)
7445 result_reader
->comp_dir
= DW_STRING (comp_dir
);
7447 /* Skip dummy compilation units. */
7448 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
7449 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7452 *result_info_ptr
= info_ptr
;
7456 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
7457 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
7458 signature is part of the header. */
7459 static gdb::optional
<ULONGEST
>
7460 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
7462 if (cu
->header
.version
>= 5)
7463 return cu
->header
.signature
;
7464 struct attribute
*attr
;
7465 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
7466 if (attr
== nullptr)
7467 return gdb::optional
<ULONGEST
> ();
7468 return DW_UNSND (attr
);
7471 /* Subroutine of cutu_reader to simplify it.
7472 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
7473 Returns NULL if the specified DWO unit cannot be found. */
7475 static struct dwo_unit
*
7476 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
7477 struct die_info
*comp_unit_die
,
7478 const char *dwo_name
)
7480 struct dwarf2_cu
*cu
= this_cu
->cu
;
7481 struct dwo_unit
*dwo_unit
;
7482 const char *comp_dir
;
7484 gdb_assert (cu
!= NULL
);
7486 /* Yeah, we look dwo_name up again, but it simplifies the code. */
7487 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7488 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7490 if (this_cu
->is_debug_types
)
7492 struct signatured_type
*sig_type
;
7494 /* Since this_cu is the first member of struct signatured_type,
7495 we can go from a pointer to one to a pointer to the other. */
7496 sig_type
= (struct signatured_type
*) this_cu
;
7497 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
7501 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
7502 if (!signature
.has_value ())
7503 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
7505 dwo_name
, objfile_name (this_cu
->dwarf2_per_objfile
->objfile
));
7506 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
7513 /* Subroutine of cutu_reader to simplify it.
7514 See it for a description of the parameters.
7515 Read a TU directly from a DWO file, bypassing the stub. */
7518 cutu_reader::init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
7519 int use_existing_cu
, int keep
)
7521 struct signatured_type
*sig_type
;
7522 struct die_reader_specs reader
;
7524 /* Verify we can do the following downcast, and that we have the
7526 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
7527 sig_type
= (struct signatured_type
*) this_cu
;
7528 gdb_assert (sig_type
->dwo_unit
!= NULL
);
7530 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7532 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
7533 /* There's no need to do the rereading_dwo_cu handling that
7534 cutu_reader does since we don't read the stub. */
7538 /* If !use_existing_cu, this_cu->cu must be NULL. */
7539 gdb_assert (this_cu
->cu
== NULL
);
7540 m_new_cu
.reset (new dwarf2_cu (this_cu
));
7543 /* A future optimization, if needed, would be to use an existing
7544 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
7545 could share abbrev tables. */
7547 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
7548 NULL
/* stub_comp_unit_die */,
7549 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
7551 &comp_unit_die
, &has_children
,
7552 &m_dwo_abbrev_table
) == 0)
7559 /* Initialize a CU (or TU) and read its DIEs.
7560 If the CU defers to a DWO file, read the DWO file as well.
7562 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
7563 Otherwise the table specified in the comp unit header is read in and used.
7564 This is an optimization for when we already have the abbrev table.
7566 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
7567 Otherwise, a new CU is allocated with xmalloc.
7569 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
7570 read_in_chain. Otherwise the dwarf2_cu data is freed at the
7573 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
7574 struct abbrev_table
*abbrev_table
,
7575 int use_existing_cu
, int keep
,
7577 : die_reader_specs
{},
7578 m_this_cu (this_cu
),
7581 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7582 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7583 struct dwarf2_section_info
*section
= this_cu
->section
;
7584 bfd
*abfd
= get_section_bfd_owner (section
);
7585 struct dwarf2_cu
*cu
;
7586 const gdb_byte
*begin_info_ptr
;
7587 struct signatured_type
*sig_type
= NULL
;
7588 struct dwarf2_section_info
*abbrev_section
;
7589 /* Non-zero if CU currently points to a DWO file and we need to
7590 reread it. When this happens we need to reread the skeleton die
7591 before we can reread the DWO file (this only applies to CUs, not TUs). */
7592 int rereading_dwo_cu
= 0;
7594 if (dwarf_die_debug
)
7595 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7596 this_cu
->is_debug_types
? "type" : "comp",
7597 sect_offset_str (this_cu
->sect_off
));
7599 if (use_existing_cu
)
7602 /* If we're reading a TU directly from a DWO file, including a virtual DWO
7603 file (instead of going through the stub), short-circuit all of this. */
7604 if (this_cu
->reading_dwo_directly
)
7606 /* Narrow down the scope of possibilities to have to understand. */
7607 gdb_assert (this_cu
->is_debug_types
);
7608 gdb_assert (abbrev_table
== NULL
);
7609 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
, keep
);
7613 /* This is cheap if the section is already read in. */
7614 dwarf2_read_section (objfile
, section
);
7616 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7618 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
7620 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7623 /* If this CU is from a DWO file we need to start over, we need to
7624 refetch the attributes from the skeleton CU.
7625 This could be optimized by retrieving those attributes from when we
7626 were here the first time: the previous comp_unit_die was stored in
7627 comp_unit_obstack. But there's no data yet that we need this
7629 if (cu
->dwo_unit
!= NULL
)
7630 rereading_dwo_cu
= 1;
7634 /* If !use_existing_cu, this_cu->cu must be NULL. */
7635 gdb_assert (this_cu
->cu
== NULL
);
7636 m_new_cu
.reset (new dwarf2_cu (this_cu
));
7637 cu
= m_new_cu
.get ();
7640 /* Get the header. */
7641 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
7643 /* We already have the header, there's no need to read it in again. */
7644 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
7648 if (this_cu
->is_debug_types
)
7650 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7651 &cu
->header
, section
,
7652 abbrev_section
, info_ptr
,
7655 /* Since per_cu is the first member of struct signatured_type,
7656 we can go from a pointer to one to a pointer to the other. */
7657 sig_type
= (struct signatured_type
*) this_cu
;
7658 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
7659 gdb_assert (sig_type
->type_offset_in_tu
7660 == cu
->header
.type_cu_offset_in_tu
);
7661 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7663 /* LENGTH has not been set yet for type units if we're
7664 using .gdb_index. */
7665 this_cu
->length
= get_cu_length (&cu
->header
);
7667 /* Establish the type offset that can be used to lookup the type. */
7668 sig_type
->type_offset_in_section
=
7669 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
7671 this_cu
->dwarf_version
= cu
->header
.version
;
7675 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7676 &cu
->header
, section
,
7679 rcuh_kind::COMPILE
);
7681 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7682 gdb_assert (this_cu
->length
== get_cu_length (&cu
->header
));
7683 this_cu
->dwarf_version
= cu
->header
.version
;
7687 /* Skip dummy compilation units. */
7688 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7689 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7695 /* If we don't have them yet, read the abbrevs for this compilation unit.
7696 And if we need to read them now, make sure they're freed when we're
7698 if (abbrev_table
!= NULL
)
7699 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
7702 m_abbrev_table_holder
7703 = abbrev_table_read_table (dwarf2_per_objfile
, abbrev_section
,
7704 cu
->header
.abbrev_sect_off
);
7705 abbrev_table
= m_abbrev_table_holder
.get ();
7708 /* Read the top level CU/TU die. */
7709 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
7710 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
, &has_children
);
7712 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
7718 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
7719 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
7720 table from the DWO file and pass the ownership over to us. It will be
7721 referenced from READER, so we must make sure to free it after we're done
7724 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
7725 DWO CU, that this test will fail (the attribute will not be present). */
7726 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7727 if (dwo_name
!= nullptr)
7729 struct dwo_unit
*dwo_unit
;
7730 struct die_info
*dwo_comp_unit_die
;
7734 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
7735 " has children (offset %s) [in module %s]"),
7736 sect_offset_str (this_cu
->sect_off
),
7737 bfd_get_filename (abfd
));
7739 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
, dwo_name
);
7740 if (dwo_unit
!= NULL
)
7742 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
7743 comp_unit_die
, NULL
,
7745 &dwo_comp_unit_die
, &has_children
,
7746 &m_dwo_abbrev_table
) == 0)
7752 comp_unit_die
= dwo_comp_unit_die
;
7756 /* Yikes, we couldn't find the rest of the DIE, we only have
7757 the stub. A complaint has already been logged. There's
7758 not much more we can do except pass on the stub DIE to
7759 die_reader_func. We don't want to throw an error on bad
7765 cutu_reader::~cutu_reader ()
7767 /* Done, clean up. */
7768 if (m_new_cu
!= NULL
&& m_keep
&& !dummy_p
)
7770 struct dwarf2_per_objfile
*dwarf2_per_objfile
7771 = m_this_cu
->dwarf2_per_objfile
;
7772 /* Link this CU into read_in_chain. */
7773 m_this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
7774 dwarf2_per_objfile
->read_in_chain
= m_this_cu
;
7775 /* The chain owns it now. */
7776 m_new_cu
.release ();
7780 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
7781 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
7782 assumed to have already done the lookup to find the DWO file).
7784 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7785 THIS_CU->is_debug_types, but nothing else.
7787 We fill in THIS_CU->length.
7789 THIS_CU->cu is always freed when done.
7790 This is done in order to not leave THIS_CU->cu in a state where we have
7791 to care whether it refers to the "main" CU or the DWO CU.
7793 When parent_cu is passed, it is used to provide a default value for
7794 str_offsets_base and addr_base from the parent. */
7796 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
7797 struct dwarf2_cu
*parent_cu
,
7798 struct dwo_file
*dwo_file
)
7799 : die_reader_specs
{},
7802 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7803 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7804 struct dwarf2_section_info
*section
= this_cu
->section
;
7805 bfd
*abfd
= get_section_bfd_owner (section
);
7806 struct dwarf2_section_info
*abbrev_section
;
7807 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7810 if (dwarf_die_debug
)
7811 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7812 this_cu
->is_debug_types
? "type" : "comp",
7813 sect_offset_str (this_cu
->sect_off
));
7815 gdb_assert (this_cu
->cu
== NULL
);
7817 abbrev_section
= (dwo_file
!= NULL
7818 ? &dwo_file
->sections
.abbrev
7819 : get_abbrev_section_for_cu (this_cu
));
7821 /* This is cheap if the section is already read in. */
7822 dwarf2_read_section (objfile
, section
);
7824 m_new_cu
.reset (new dwarf2_cu (this_cu
));
7826 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7827 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7828 &m_new_cu
->header
, section
,
7829 abbrev_section
, info_ptr
,
7830 (this_cu
->is_debug_types
7832 : rcuh_kind::COMPILE
));
7834 if (parent_cu
!= nullptr)
7836 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
7837 m_new_cu
->addr_base
= parent_cu
->addr_base
;
7839 this_cu
->length
= get_cu_length (&m_new_cu
->header
);
7841 /* Skip dummy compilation units. */
7842 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7843 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7849 m_abbrev_table_holder
7850 = abbrev_table_read_table (dwarf2_per_objfile
, abbrev_section
,
7851 m_new_cu
->header
.abbrev_sect_off
);
7853 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
7854 m_abbrev_table_holder
.get ());
7855 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
, &has_children
);
7859 /* Type Unit Groups.
7861 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7862 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7863 so that all types coming from the same compilation (.o file) are grouped
7864 together. A future step could be to put the types in the same symtab as
7865 the CU the types ultimately came from. */
7868 hash_type_unit_group (const void *item
)
7870 const struct type_unit_group
*tu_group
7871 = (const struct type_unit_group
*) item
;
7873 return hash_stmt_list_entry (&tu_group
->hash
);
7877 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7879 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7880 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7882 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7885 /* Allocate a hash table for type unit groups. */
7888 allocate_type_unit_groups_table (struct objfile
*objfile
)
7890 return htab_create_alloc_ex (3,
7891 hash_type_unit_group
,
7894 &objfile
->objfile_obstack
,
7895 hashtab_obstack_allocate
,
7896 dummy_obstack_deallocate
);
7899 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7900 partial symtabs. We combine several TUs per psymtab to not let the size
7901 of any one psymtab grow too big. */
7902 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7903 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7905 /* Helper routine for get_type_unit_group.
7906 Create the type_unit_group object used to hold one or more TUs. */
7908 static struct type_unit_group
*
7909 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7911 struct dwarf2_per_objfile
*dwarf2_per_objfile
7912 = cu
->per_cu
->dwarf2_per_objfile
;
7913 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7914 struct dwarf2_per_cu_data
*per_cu
;
7915 struct type_unit_group
*tu_group
;
7917 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7918 struct type_unit_group
);
7919 per_cu
= &tu_group
->per_cu
;
7920 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7922 if (dwarf2_per_objfile
->using_index
)
7924 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7925 struct dwarf2_per_cu_quick_data
);
7929 unsigned int line_offset
= to_underlying (line_offset_struct
);
7930 dwarf2_psymtab
*pst
;
7933 /* Give the symtab a useful name for debug purposes. */
7934 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7935 name
= string_printf ("<type_units_%d>",
7936 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7938 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7940 pst
= create_partial_symtab (per_cu
, name
.c_str ());
7941 pst
->anonymous
= true;
7944 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7945 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7950 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7951 STMT_LIST is a DW_AT_stmt_list attribute. */
7953 static struct type_unit_group
*
7954 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7956 struct dwarf2_per_objfile
*dwarf2_per_objfile
7957 = cu
->per_cu
->dwarf2_per_objfile
;
7958 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7959 struct type_unit_group
*tu_group
;
7961 unsigned int line_offset
;
7962 struct type_unit_group type_unit_group_for_lookup
;
7964 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
7966 dwarf2_per_objfile
->type_unit_groups
=
7967 allocate_type_unit_groups_table (dwarf2_per_objfile
->objfile
);
7970 /* Do we need to create a new group, or can we use an existing one? */
7974 line_offset
= DW_UNSND (stmt_list
);
7975 ++tu_stats
->nr_symtab_sharers
;
7979 /* Ugh, no stmt_list. Rare, but we have to handle it.
7980 We can do various things here like create one group per TU or
7981 spread them over multiple groups to split up the expansion work.
7982 To avoid worst case scenarios (too many groups or too large groups)
7983 we, umm, group them in bunches. */
7984 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7985 | (tu_stats
->nr_stmt_less_type_units
7986 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7987 ++tu_stats
->nr_stmt_less_type_units
;
7990 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7991 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7992 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
,
7993 &type_unit_group_for_lookup
, INSERT
);
7996 tu_group
= (struct type_unit_group
*) *slot
;
7997 gdb_assert (tu_group
!= NULL
);
8001 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
8002 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
8004 ++tu_stats
->nr_symtabs
;
8010 /* Partial symbol tables. */
8012 /* Create a psymtab named NAME and assign it to PER_CU.
8014 The caller must fill in the following details:
8015 dirname, textlow, texthigh. */
8017 static dwarf2_psymtab
*
8018 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
8020 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
8021 dwarf2_psymtab
*pst
;
8023 pst
= new dwarf2_psymtab (name
, objfile
, 0);
8025 pst
->psymtabs_addrmap_supported
= true;
8027 /* This is the glue that links PST into GDB's symbol API. */
8028 pst
->per_cu_data
= per_cu
;
8029 per_cu
->v
.psymtab
= pst
;
8034 /* DIE reader function for process_psymtab_comp_unit. */
8037 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
8038 const gdb_byte
*info_ptr
,
8039 struct die_info
*comp_unit_die
,
8041 int want_partial_unit
,
8042 enum language pretend_language
)
8044 struct dwarf2_cu
*cu
= reader
->cu
;
8045 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
8046 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8047 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
8049 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
8050 dwarf2_psymtab
*pst
;
8051 enum pc_bounds_kind cu_bounds_kind
;
8052 const char *filename
;
8054 if (comp_unit_die
->tag
== DW_TAG_partial_unit
&& !want_partial_unit
)
8057 gdb_assert (! per_cu
->is_debug_types
);
8059 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
8061 /* Allocate a new partial symbol table structure. */
8062 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
8063 if (filename
== NULL
)
8066 pst
= create_partial_symtab (per_cu
, filename
);
8068 /* This must be done before calling dwarf2_build_include_psymtabs. */
8069 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
8071 baseaddr
= objfile
->text_section_offset ();
8073 dwarf2_find_base_address (comp_unit_die
, cu
);
8075 /* Possibly set the default values of LOWPC and HIGHPC from
8077 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
8078 &best_highpc
, cu
, pst
);
8079 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
8082 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
8085 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
8087 /* Store the contiguous range if it is not empty; it can be
8088 empty for CUs with no code. */
8089 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8093 /* Check if comp unit has_children.
8094 If so, read the rest of the partial symbols from this comp unit.
8095 If not, there's no more debug_info for this comp unit. */
8098 struct partial_die_info
*first_die
;
8099 CORE_ADDR lowpc
, highpc
;
8101 lowpc
= ((CORE_ADDR
) -1);
8102 highpc
= ((CORE_ADDR
) 0);
8104 first_die
= load_partial_dies (reader
, info_ptr
, 1);
8106 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
8107 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
8109 /* If we didn't find a lowpc, set it to highpc to avoid
8110 complaints from `maint check'. */
8111 if (lowpc
== ((CORE_ADDR
) -1))
8114 /* If the compilation unit didn't have an explicit address range,
8115 then use the information extracted from its child dies. */
8116 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
8119 best_highpc
= highpc
;
8122 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
8123 best_lowpc
+ baseaddr
)
8125 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
8126 best_highpc
+ baseaddr
)
8129 end_psymtab_common (objfile
, pst
);
8131 if (!cu
->per_cu
->imported_symtabs_empty ())
8134 int len
= cu
->per_cu
->imported_symtabs_size ();
8136 /* Fill in 'dependencies' here; we fill in 'users' in a
8138 pst
->number_of_dependencies
= len
;
8140 = objfile
->partial_symtabs
->allocate_dependencies (len
);
8141 for (i
= 0; i
< len
; ++i
)
8143 pst
->dependencies
[i
]
8144 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
8147 cu
->per_cu
->imported_symtabs_free ();
8150 /* Get the list of files included in the current compilation unit,
8151 and build a psymtab for each of them. */
8152 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
8154 if (dwarf_read_debug
)
8155 fprintf_unfiltered (gdb_stdlog
,
8156 "Psymtab for %s unit @%s: %s - %s"
8157 ", %d global, %d static syms\n",
8158 per_cu
->is_debug_types
? "type" : "comp",
8159 sect_offset_str (per_cu
->sect_off
),
8160 paddress (gdbarch
, pst
->text_low (objfile
)),
8161 paddress (gdbarch
, pst
->text_high (objfile
)),
8162 pst
->n_global_syms
, pst
->n_static_syms
);
8165 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8166 Process compilation unit THIS_CU for a psymtab. */
8169 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8170 int want_partial_unit
,
8171 enum language pretend_language
)
8173 /* If this compilation unit was already read in, free the
8174 cached copy in order to read it in again. This is
8175 necessary because we skipped some symbols when we first
8176 read in the compilation unit (see load_partial_dies).
8177 This problem could be avoided, but the benefit is unclear. */
8178 if (this_cu
->cu
!= NULL
)
8179 free_one_cached_comp_unit (this_cu
);
8181 cutu_reader
reader (this_cu
, NULL
, 0, 0, false);
8187 else if (this_cu
->is_debug_types
)
8188 build_type_psymtabs_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
8189 reader
.has_children
);
8191 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
8192 reader
.comp_unit_die
,
8193 reader
.has_children
,
8197 /* Age out any secondary CUs. */
8198 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
8201 /* Reader function for build_type_psymtabs. */
8204 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
8205 const gdb_byte
*info_ptr
,
8206 struct die_info
*type_unit_die
,
8209 struct dwarf2_per_objfile
*dwarf2_per_objfile
8210 = reader
->cu
->per_cu
->dwarf2_per_objfile
;
8211 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8212 struct dwarf2_cu
*cu
= reader
->cu
;
8213 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
8214 struct signatured_type
*sig_type
;
8215 struct type_unit_group
*tu_group
;
8216 struct attribute
*attr
;
8217 struct partial_die_info
*first_die
;
8218 CORE_ADDR lowpc
, highpc
;
8219 dwarf2_psymtab
*pst
;
8221 gdb_assert (per_cu
->is_debug_types
);
8222 sig_type
= (struct signatured_type
*) per_cu
;
8227 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
8228 tu_group
= get_type_unit_group (cu
, attr
);
8230 if (tu_group
->tus
== nullptr)
8231 tu_group
->tus
= new std::vector
<signatured_type
*>;
8232 tu_group
->tus
->push_back (sig_type
);
8234 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
8235 pst
= create_partial_symtab (per_cu
, "");
8236 pst
->anonymous
= true;
8238 first_die
= load_partial_dies (reader
, info_ptr
, 1);
8240 lowpc
= (CORE_ADDR
) -1;
8241 highpc
= (CORE_ADDR
) 0;
8242 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
8244 end_psymtab_common (objfile
, pst
);
8247 /* Struct used to sort TUs by their abbreviation table offset. */
8249 struct tu_abbrev_offset
8251 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
8252 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
8255 signatured_type
*sig_type
;
8256 sect_offset abbrev_offset
;
8259 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
8262 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
8263 const struct tu_abbrev_offset
&b
)
8265 return a
.abbrev_offset
< b
.abbrev_offset
;
8268 /* Efficiently read all the type units.
8269 This does the bulk of the work for build_type_psymtabs.
8271 The efficiency is because we sort TUs by the abbrev table they use and
8272 only read each abbrev table once. In one program there are 200K TUs
8273 sharing 8K abbrev tables.
8275 The main purpose of this function is to support building the
8276 dwarf2_per_objfile->type_unit_groups table.
8277 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
8278 can collapse the search space by grouping them by stmt_list.
8279 The savings can be significant, in the same program from above the 200K TUs
8280 share 8K stmt_list tables.
8282 FUNC is expected to call get_type_unit_group, which will create the
8283 struct type_unit_group if necessary and add it to
8284 dwarf2_per_objfile->type_unit_groups. */
8287 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8289 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8290 abbrev_table_up abbrev_table
;
8291 sect_offset abbrev_offset
;
8293 /* It's up to the caller to not call us multiple times. */
8294 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
8296 if (dwarf2_per_objfile
->all_type_units
.empty ())
8299 /* TUs typically share abbrev tables, and there can be way more TUs than
8300 abbrev tables. Sort by abbrev table to reduce the number of times we
8301 read each abbrev table in.
8302 Alternatives are to punt or to maintain a cache of abbrev tables.
8303 This is simpler and efficient enough for now.
8305 Later we group TUs by their DW_AT_stmt_list value (as this defines the
8306 symtab to use). Typically TUs with the same abbrev offset have the same
8307 stmt_list value too so in practice this should work well.
8309 The basic algorithm here is:
8311 sort TUs by abbrev table
8312 for each TU with same abbrev table:
8313 read abbrev table if first user
8314 read TU top level DIE
8315 [IWBN if DWO skeletons had DW_AT_stmt_list]
8318 if (dwarf_read_debug
)
8319 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
8321 /* Sort in a separate table to maintain the order of all_type_units
8322 for .gdb_index: TU indices directly index all_type_units. */
8323 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
8324 sorted_by_abbrev
.reserve (dwarf2_per_objfile
->all_type_units
.size ());
8326 for (signatured_type
*sig_type
: dwarf2_per_objfile
->all_type_units
)
8327 sorted_by_abbrev
.emplace_back
8328 (sig_type
, read_abbrev_offset (dwarf2_per_objfile
,
8329 sig_type
->per_cu
.section
,
8330 sig_type
->per_cu
.sect_off
));
8332 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
8333 sort_tu_by_abbrev_offset
);
8335 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
8337 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
8339 /* Switch to the next abbrev table if necessary. */
8340 if (abbrev_table
== NULL
8341 || tu
.abbrev_offset
!= abbrev_offset
)
8343 abbrev_offset
= tu
.abbrev_offset
;
8345 abbrev_table_read_table (dwarf2_per_objfile
,
8346 &dwarf2_per_objfile
->abbrev
,
8348 ++tu_stats
->nr_uniq_abbrev_tables
;
8351 cutu_reader
reader (&tu
.sig_type
->per_cu
, abbrev_table
.get (),
8353 if (!reader
.dummy_p
)
8354 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
8355 reader
.comp_unit_die
,
8356 reader
.has_children
);
8360 /* Print collected type unit statistics. */
8363 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8365 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8367 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
8368 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
8369 dwarf2_per_objfile
->all_type_units
.size ());
8370 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
8371 tu_stats
->nr_uniq_abbrev_tables
);
8372 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
8373 tu_stats
->nr_symtabs
);
8374 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
8375 tu_stats
->nr_symtab_sharers
);
8376 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
8377 tu_stats
->nr_stmt_less_type_units
);
8378 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
8379 tu_stats
->nr_all_type_units_reallocs
);
8382 /* Traversal function for build_type_psymtabs. */
8385 build_type_psymtab_dependencies (void **slot
, void *info
)
8387 struct dwarf2_per_objfile
*dwarf2_per_objfile
8388 = (struct dwarf2_per_objfile
*) info
;
8389 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8390 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
8391 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
8392 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
8393 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
8396 gdb_assert (len
> 0);
8397 gdb_assert (IS_TYPE_UNIT_GROUP (per_cu
));
8399 pst
->number_of_dependencies
= len
;
8400 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
8401 for (i
= 0; i
< len
; ++i
)
8403 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
8404 gdb_assert (iter
->per_cu
.is_debug_types
);
8405 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
8406 iter
->type_unit_group
= tu_group
;
8409 delete tu_group
->tus
;
8410 tu_group
->tus
= nullptr;
8415 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8416 Build partial symbol tables for the .debug_types comp-units. */
8419 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8421 if (! create_all_type_units (dwarf2_per_objfile
))
8424 build_type_psymtabs_1 (dwarf2_per_objfile
);
8427 /* Traversal function for process_skeletonless_type_unit.
8428 Read a TU in a DWO file and build partial symbols for it. */
8431 process_skeletonless_type_unit (void **slot
, void *info
)
8433 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
8434 struct dwarf2_per_objfile
*dwarf2_per_objfile
8435 = (struct dwarf2_per_objfile
*) info
;
8436 struct signatured_type find_entry
, *entry
;
8438 /* If this TU doesn't exist in the global table, add it and read it in. */
8440 if (dwarf2_per_objfile
->signatured_types
== NULL
)
8442 dwarf2_per_objfile
->signatured_types
8443 = allocate_signatured_type_table (dwarf2_per_objfile
->objfile
);
8446 find_entry
.signature
= dwo_unit
->signature
;
8447 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
, &find_entry
,
8449 /* If we've already seen this type there's nothing to do. What's happening
8450 is we're doing our own version of comdat-folding here. */
8454 /* This does the job that create_all_type_units would have done for
8456 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
8457 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
8460 /* This does the job that build_type_psymtabs_1 would have done. */
8461 cutu_reader
reader (&entry
->per_cu
, NULL
, 0, 0, false);
8462 if (!reader
.dummy_p
)
8463 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
8464 reader
.comp_unit_die
, reader
.has_children
);
8469 /* Traversal function for process_skeletonless_type_units. */
8472 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
8474 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
8476 if (dwo_file
->tus
!= NULL
)
8478 htab_traverse_noresize (dwo_file
->tus
,
8479 process_skeletonless_type_unit
, info
);
8485 /* Scan all TUs of DWO files, verifying we've processed them.
8486 This is needed in case a TU was emitted without its skeleton.
8487 Note: This can't be done until we know what all the DWO files are. */
8490 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8492 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
8493 if (get_dwp_file (dwarf2_per_objfile
) == NULL
8494 && dwarf2_per_objfile
->dwo_files
!= NULL
)
8496 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
.get (),
8497 process_dwo_file_for_skeletonless_type_units
,
8498 dwarf2_per_objfile
);
8502 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
8505 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8507 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
8509 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
8514 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
8516 /* Set the 'user' field only if it is not already set. */
8517 if (pst
->dependencies
[j
]->user
== NULL
)
8518 pst
->dependencies
[j
]->user
= pst
;
8523 /* Build the partial symbol table by doing a quick pass through the
8524 .debug_info and .debug_abbrev sections. */
8527 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8529 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8531 if (dwarf_read_debug
)
8533 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
8534 objfile_name (objfile
));
8537 dwarf2_per_objfile
->reading_partial_symbols
= 1;
8539 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
8541 /* Any cached compilation units will be linked by the per-objfile
8542 read_in_chain. Make sure to free them when we're done. */
8543 free_cached_comp_units
freer (dwarf2_per_objfile
);
8545 build_type_psymtabs (dwarf2_per_objfile
);
8547 create_all_comp_units (dwarf2_per_objfile
);
8549 /* Create a temporary address map on a temporary obstack. We later
8550 copy this to the final obstack. */
8551 auto_obstack temp_obstack
;
8553 scoped_restore save_psymtabs_addrmap
8554 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
8555 addrmap_create_mutable (&temp_obstack
));
8557 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
8558 process_psymtab_comp_unit (per_cu
, 0, language_minimal
);
8560 /* This has to wait until we read the CUs, we need the list of DWOs. */
8561 process_skeletonless_type_units (dwarf2_per_objfile
);
8563 /* Now that all TUs have been processed we can fill in the dependencies. */
8564 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
8566 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
8567 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
8570 if (dwarf_read_debug
)
8571 print_tu_stats (dwarf2_per_objfile
);
8573 set_partial_user (dwarf2_per_objfile
);
8575 objfile
->partial_symtabs
->psymtabs_addrmap
8576 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
8577 objfile
->partial_symtabs
->obstack ());
8578 /* At this point we want to keep the address map. */
8579 save_psymtabs_addrmap
.release ();
8581 if (dwarf_read_debug
)
8582 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
8583 objfile_name (objfile
));
8586 /* Load the partial DIEs for a secondary CU into memory.
8587 This is also used when rereading a primary CU with load_all_dies. */
8590 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
8592 cutu_reader
reader (this_cu
, NULL
, 1, 1, false);
8594 if (!reader
.dummy_p
)
8596 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
8599 /* Check if comp unit has_children.
8600 If so, read the rest of the partial symbols from this comp unit.
8601 If not, there's no more debug_info for this comp unit. */
8602 if (reader
.has_children
)
8603 load_partial_dies (&reader
, reader
.info_ptr
, 0);
8608 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
8609 struct dwarf2_section_info
*section
,
8610 struct dwarf2_section_info
*abbrev_section
,
8611 unsigned int is_dwz
)
8613 const gdb_byte
*info_ptr
;
8614 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8616 if (dwarf_read_debug
)
8617 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
8618 get_section_name (section
),
8619 get_section_file_name (section
));
8621 dwarf2_read_section (objfile
, section
);
8623 info_ptr
= section
->buffer
;
8625 while (info_ptr
< section
->buffer
+ section
->size
)
8627 struct dwarf2_per_cu_data
*this_cu
;
8629 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
8631 comp_unit_head cu_header
;
8632 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
8633 abbrev_section
, info_ptr
,
8634 rcuh_kind::COMPILE
);
8636 /* Save the compilation unit for later lookup. */
8637 if (cu_header
.unit_type
!= DW_UT_type
)
8639 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
8640 struct dwarf2_per_cu_data
);
8641 memset (this_cu
, 0, sizeof (*this_cu
));
8645 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
8646 struct signatured_type
);
8647 memset (sig_type
, 0, sizeof (*sig_type
));
8648 sig_type
->signature
= cu_header
.signature
;
8649 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
8650 this_cu
= &sig_type
->per_cu
;
8652 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
8653 this_cu
->sect_off
= sect_off
;
8654 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
8655 this_cu
->is_dwz
= is_dwz
;
8656 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
8657 this_cu
->section
= section
;
8659 dwarf2_per_objfile
->all_comp_units
.push_back (this_cu
);
8661 info_ptr
= info_ptr
+ this_cu
->length
;
8665 /* Create a list of all compilation units in OBJFILE.
8666 This is only done for -readnow and building partial symtabs. */
8669 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8671 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
8672 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->info
,
8673 &dwarf2_per_objfile
->abbrev
, 0);
8675 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
8677 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
8681 /* Process all loaded DIEs for compilation unit CU, starting at
8682 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
8683 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
8684 DW_AT_ranges). See the comments of add_partial_subprogram on how
8685 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
8688 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
8689 CORE_ADDR
*highpc
, int set_addrmap
,
8690 struct dwarf2_cu
*cu
)
8692 struct partial_die_info
*pdi
;
8694 /* Now, march along the PDI's, descending into ones which have
8695 interesting children but skipping the children of the other ones,
8696 until we reach the end of the compilation unit. */
8704 /* Anonymous namespaces or modules have no name but have interesting
8705 children, so we need to look at them. Ditto for anonymous
8708 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
8709 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
8710 || pdi
->tag
== DW_TAG_imported_unit
8711 || pdi
->tag
== DW_TAG_inlined_subroutine
)
8715 case DW_TAG_subprogram
:
8716 case DW_TAG_inlined_subroutine
:
8717 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8719 case DW_TAG_constant
:
8720 case DW_TAG_variable
:
8721 case DW_TAG_typedef
:
8722 case DW_TAG_union_type
:
8723 if (!pdi
->is_declaration
)
8725 add_partial_symbol (pdi
, cu
);
8728 case DW_TAG_class_type
:
8729 case DW_TAG_interface_type
:
8730 case DW_TAG_structure_type
:
8731 if (!pdi
->is_declaration
)
8733 add_partial_symbol (pdi
, cu
);
8735 if ((cu
->language
== language_rust
8736 || cu
->language
== language_cplus
) && pdi
->has_children
)
8737 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8740 case DW_TAG_enumeration_type
:
8741 if (!pdi
->is_declaration
)
8742 add_partial_enumeration (pdi
, cu
);
8744 case DW_TAG_base_type
:
8745 case DW_TAG_subrange_type
:
8746 /* File scope base type definitions are added to the partial
8748 add_partial_symbol (pdi
, cu
);
8750 case DW_TAG_namespace
:
8751 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8754 if (!pdi
->is_declaration
)
8755 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8757 case DW_TAG_imported_unit
:
8759 struct dwarf2_per_cu_data
*per_cu
;
8761 /* For now we don't handle imported units in type units. */
8762 if (cu
->per_cu
->is_debug_types
)
8764 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8765 " supported in type units [in module %s]"),
8766 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
8769 per_cu
= dwarf2_find_containing_comp_unit
8770 (pdi
->d
.sect_off
, pdi
->is_dwz
,
8771 cu
->per_cu
->dwarf2_per_objfile
);
8773 /* Go read the partial unit, if needed. */
8774 if (per_cu
->v
.psymtab
== NULL
)
8775 process_psymtab_comp_unit (per_cu
, 1, cu
->language
);
8777 cu
->per_cu
->imported_symtabs_push (per_cu
);
8780 case DW_TAG_imported_declaration
:
8781 add_partial_symbol (pdi
, cu
);
8788 /* If the die has a sibling, skip to the sibling. */
8790 pdi
= pdi
->die_sibling
;
8794 /* Functions used to compute the fully scoped name of a partial DIE.
8796 Normally, this is simple. For C++, the parent DIE's fully scoped
8797 name is concatenated with "::" and the partial DIE's name.
8798 Enumerators are an exception; they use the scope of their parent
8799 enumeration type, i.e. the name of the enumeration type is not
8800 prepended to the enumerator.
8802 There are two complexities. One is DW_AT_specification; in this
8803 case "parent" means the parent of the target of the specification,
8804 instead of the direct parent of the DIE. The other is compilers
8805 which do not emit DW_TAG_namespace; in this case we try to guess
8806 the fully qualified name of structure types from their members'
8807 linkage names. This must be done using the DIE's children rather
8808 than the children of any DW_AT_specification target. We only need
8809 to do this for structures at the top level, i.e. if the target of
8810 any DW_AT_specification (if any; otherwise the DIE itself) does not
8813 /* Compute the scope prefix associated with PDI's parent, in
8814 compilation unit CU. The result will be allocated on CU's
8815 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8816 field. NULL is returned if no prefix is necessary. */
8818 partial_die_parent_scope (struct partial_die_info
*pdi
,
8819 struct dwarf2_cu
*cu
)
8821 const char *grandparent_scope
;
8822 struct partial_die_info
*parent
, *real_pdi
;
8824 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8825 then this means the parent of the specification DIE. */
8828 while (real_pdi
->has_specification
)
8830 auto res
= find_partial_die (real_pdi
->spec_offset
,
8831 real_pdi
->spec_is_dwz
, cu
);
8836 parent
= real_pdi
->die_parent
;
8840 if (parent
->scope_set
)
8841 return parent
->scope
;
8845 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8847 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8848 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8849 Work around this problem here. */
8850 if (cu
->language
== language_cplus
8851 && parent
->tag
== DW_TAG_namespace
8852 && strcmp (parent
->name
, "::") == 0
8853 && grandparent_scope
== NULL
)
8855 parent
->scope
= NULL
;
8856 parent
->scope_set
= 1;
8860 /* Nested subroutines in Fortran get a prefix. */
8861 if (pdi
->tag
== DW_TAG_enumerator
)
8862 /* Enumerators should not get the name of the enumeration as a prefix. */
8863 parent
->scope
= grandparent_scope
;
8864 else if (parent
->tag
== DW_TAG_namespace
8865 || parent
->tag
== DW_TAG_module
8866 || parent
->tag
== DW_TAG_structure_type
8867 || parent
->tag
== DW_TAG_class_type
8868 || parent
->tag
== DW_TAG_interface_type
8869 || parent
->tag
== DW_TAG_union_type
8870 || parent
->tag
== DW_TAG_enumeration_type
8871 || (cu
->language
== language_fortran
8872 && parent
->tag
== DW_TAG_subprogram
8873 && pdi
->tag
== DW_TAG_subprogram
))
8875 if (grandparent_scope
== NULL
)
8876 parent
->scope
= parent
->name
;
8878 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8880 parent
->name
, 0, cu
);
8884 /* FIXME drow/2004-04-01: What should we be doing with
8885 function-local names? For partial symbols, we should probably be
8887 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8888 dwarf_tag_name (parent
->tag
),
8889 sect_offset_str (pdi
->sect_off
));
8890 parent
->scope
= grandparent_scope
;
8893 parent
->scope_set
= 1;
8894 return parent
->scope
;
8897 /* Return the fully scoped name associated with PDI, from compilation unit
8898 CU. The result will be allocated with malloc. */
8900 static gdb::unique_xmalloc_ptr
<char>
8901 partial_die_full_name (struct partial_die_info
*pdi
,
8902 struct dwarf2_cu
*cu
)
8904 const char *parent_scope
;
8906 /* If this is a template instantiation, we can not work out the
8907 template arguments from partial DIEs. So, unfortunately, we have
8908 to go through the full DIEs. At least any work we do building
8909 types here will be reused if full symbols are loaded later. */
8910 if (pdi
->has_template_arguments
)
8914 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
8916 struct die_info
*die
;
8917 struct attribute attr
;
8918 struct dwarf2_cu
*ref_cu
= cu
;
8920 /* DW_FORM_ref_addr is using section offset. */
8921 attr
.name
= (enum dwarf_attribute
) 0;
8922 attr
.form
= DW_FORM_ref_addr
;
8923 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8924 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8926 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8930 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8931 if (parent_scope
== NULL
)
8934 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8939 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8941 struct dwarf2_per_objfile
*dwarf2_per_objfile
8942 = cu
->per_cu
->dwarf2_per_objfile
;
8943 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8944 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8946 const char *actual_name
= NULL
;
8949 baseaddr
= objfile
->text_section_offset ();
8951 gdb::unique_xmalloc_ptr
<char> built_actual_name
8952 = partial_die_full_name (pdi
, cu
);
8953 if (built_actual_name
!= NULL
)
8954 actual_name
= built_actual_name
.get ();
8956 if (actual_name
== NULL
)
8957 actual_name
= pdi
->name
;
8961 case DW_TAG_inlined_subroutine
:
8962 case DW_TAG_subprogram
:
8963 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8965 if (pdi
->is_external
8966 || cu
->language
== language_ada
8967 || (cu
->language
== language_fortran
8968 && pdi
->die_parent
!= NULL
8969 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8971 /* Normally, only "external" DIEs are part of the global scope.
8972 But in Ada and Fortran, we want to be able to access nested
8973 procedures globally. So all Ada and Fortran subprograms are
8974 stored in the global scope. */
8975 add_psymbol_to_list (actual_name
,
8976 built_actual_name
!= NULL
,
8977 VAR_DOMAIN
, LOC_BLOCK
,
8978 SECT_OFF_TEXT (objfile
),
8979 psymbol_placement::GLOBAL
,
8981 cu
->language
, objfile
);
8985 add_psymbol_to_list (actual_name
,
8986 built_actual_name
!= NULL
,
8987 VAR_DOMAIN
, LOC_BLOCK
,
8988 SECT_OFF_TEXT (objfile
),
8989 psymbol_placement::STATIC
,
8990 addr
, cu
->language
, objfile
);
8993 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8994 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8996 case DW_TAG_constant
:
8997 add_psymbol_to_list (actual_name
,
8998 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
8999 -1, (pdi
->is_external
9000 ? psymbol_placement::GLOBAL
9001 : psymbol_placement::STATIC
),
9002 0, cu
->language
, objfile
);
9004 case DW_TAG_variable
:
9006 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
9010 && !dwarf2_per_objfile
->has_section_at_zero
)
9012 /* A global or static variable may also have been stripped
9013 out by the linker if unused, in which case its address
9014 will be nullified; do not add such variables into partial
9015 symbol table then. */
9017 else if (pdi
->is_external
)
9020 Don't enter into the minimal symbol tables as there is
9021 a minimal symbol table entry from the ELF symbols already.
9022 Enter into partial symbol table if it has a location
9023 descriptor or a type.
9024 If the location descriptor is missing, new_symbol will create
9025 a LOC_UNRESOLVED symbol, the address of the variable will then
9026 be determined from the minimal symbol table whenever the variable
9028 The address for the partial symbol table entry is not
9029 used by GDB, but it comes in handy for debugging partial symbol
9032 if (pdi
->d
.locdesc
|| pdi
->has_type
)
9033 add_psymbol_to_list (actual_name
,
9034 built_actual_name
!= NULL
,
9035 VAR_DOMAIN
, LOC_STATIC
,
9036 SECT_OFF_TEXT (objfile
),
9037 psymbol_placement::GLOBAL
,
9038 addr
, cu
->language
, objfile
);
9042 int has_loc
= pdi
->d
.locdesc
!= NULL
;
9044 /* Static Variable. Skip symbols whose value we cannot know (those
9045 without location descriptors or constant values). */
9046 if (!has_loc
&& !pdi
->has_const_value
)
9049 add_psymbol_to_list (actual_name
,
9050 built_actual_name
!= NULL
,
9051 VAR_DOMAIN
, LOC_STATIC
,
9052 SECT_OFF_TEXT (objfile
),
9053 psymbol_placement::STATIC
,
9055 cu
->language
, objfile
);
9058 case DW_TAG_typedef
:
9059 case DW_TAG_base_type
:
9060 case DW_TAG_subrange_type
:
9061 add_psymbol_to_list (actual_name
,
9062 built_actual_name
!= NULL
,
9063 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
9064 psymbol_placement::STATIC
,
9065 0, cu
->language
, objfile
);
9067 case DW_TAG_imported_declaration
:
9068 case DW_TAG_namespace
:
9069 add_psymbol_to_list (actual_name
,
9070 built_actual_name
!= NULL
,
9071 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
9072 psymbol_placement::GLOBAL
,
9073 0, cu
->language
, objfile
);
9076 /* With Fortran 77 there might be a "BLOCK DATA" module
9077 available without any name. If so, we skip the module as it
9078 doesn't bring any value. */
9079 if (actual_name
!= nullptr)
9080 add_psymbol_to_list (actual_name
,
9081 built_actual_name
!= NULL
,
9082 MODULE_DOMAIN
, LOC_TYPEDEF
, -1,
9083 psymbol_placement::GLOBAL
,
9084 0, cu
->language
, objfile
);
9086 case DW_TAG_class_type
:
9087 case DW_TAG_interface_type
:
9088 case DW_TAG_structure_type
:
9089 case DW_TAG_union_type
:
9090 case DW_TAG_enumeration_type
:
9091 /* Skip external references. The DWARF standard says in the section
9092 about "Structure, Union, and Class Type Entries": "An incomplete
9093 structure, union or class type is represented by a structure,
9094 union or class entry that does not have a byte size attribute
9095 and that has a DW_AT_declaration attribute." */
9096 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
9099 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
9100 static vs. global. */
9101 add_psymbol_to_list (actual_name
,
9102 built_actual_name
!= NULL
,
9103 STRUCT_DOMAIN
, LOC_TYPEDEF
, -1,
9104 cu
->language
== language_cplus
9105 ? psymbol_placement::GLOBAL
9106 : psymbol_placement::STATIC
,
9107 0, cu
->language
, objfile
);
9110 case DW_TAG_enumerator
:
9111 add_psymbol_to_list (actual_name
,
9112 built_actual_name
!= NULL
,
9113 VAR_DOMAIN
, LOC_CONST
, -1,
9114 cu
->language
== language_cplus
9115 ? psymbol_placement::GLOBAL
9116 : psymbol_placement::STATIC
,
9117 0, cu
->language
, objfile
);
9124 /* Read a partial die corresponding to a namespace; also, add a symbol
9125 corresponding to that namespace to the symbol table. NAMESPACE is
9126 the name of the enclosing namespace. */
9129 add_partial_namespace (struct partial_die_info
*pdi
,
9130 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9131 int set_addrmap
, struct dwarf2_cu
*cu
)
9133 /* Add a symbol for the namespace. */
9135 add_partial_symbol (pdi
, cu
);
9137 /* Now scan partial symbols in that namespace. */
9139 if (pdi
->has_children
)
9140 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
9143 /* Read a partial die corresponding to a Fortran module. */
9146 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
9147 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
9149 /* Add a symbol for the namespace. */
9151 add_partial_symbol (pdi
, cu
);
9153 /* Now scan partial symbols in that module. */
9155 if (pdi
->has_children
)
9156 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
9159 /* Read a partial die corresponding to a subprogram or an inlined
9160 subprogram and create a partial symbol for that subprogram.
9161 When the CU language allows it, this routine also defines a partial
9162 symbol for each nested subprogram that this subprogram contains.
9163 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
9164 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
9166 PDI may also be a lexical block, in which case we simply search
9167 recursively for subprograms defined inside that lexical block.
9168 Again, this is only performed when the CU language allows this
9169 type of definitions. */
9172 add_partial_subprogram (struct partial_die_info
*pdi
,
9173 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9174 int set_addrmap
, struct dwarf2_cu
*cu
)
9176 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
9178 if (pdi
->has_pc_info
)
9180 if (pdi
->lowpc
< *lowpc
)
9181 *lowpc
= pdi
->lowpc
;
9182 if (pdi
->highpc
> *highpc
)
9183 *highpc
= pdi
->highpc
;
9186 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9187 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9189 CORE_ADDR this_highpc
;
9190 CORE_ADDR this_lowpc
;
9192 baseaddr
= objfile
->text_section_offset ();
9194 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
9195 pdi
->lowpc
+ baseaddr
)
9198 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
9199 pdi
->highpc
+ baseaddr
)
9201 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
9202 this_lowpc
, this_highpc
- 1,
9203 cu
->per_cu
->v
.psymtab
);
9207 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
9209 if (!pdi
->is_declaration
)
9210 /* Ignore subprogram DIEs that do not have a name, they are
9211 illegal. Do not emit a complaint at this point, we will
9212 do so when we convert this psymtab into a symtab. */
9214 add_partial_symbol (pdi
, cu
);
9218 if (! pdi
->has_children
)
9221 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
9223 pdi
= pdi
->die_child
;
9227 if (pdi
->tag
== DW_TAG_subprogram
9228 || pdi
->tag
== DW_TAG_inlined_subroutine
9229 || pdi
->tag
== DW_TAG_lexical_block
)
9230 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
9231 pdi
= pdi
->die_sibling
;
9236 /* Read a partial die corresponding to an enumeration type. */
9239 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
9240 struct dwarf2_cu
*cu
)
9242 struct partial_die_info
*pdi
;
9244 if (enum_pdi
->name
!= NULL
)
9245 add_partial_symbol (enum_pdi
, cu
);
9247 pdi
= enum_pdi
->die_child
;
9250 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
9251 complaint (_("malformed enumerator DIE ignored"));
9253 add_partial_symbol (pdi
, cu
);
9254 pdi
= pdi
->die_sibling
;
9258 /* Return the initial uleb128 in the die at INFO_PTR. */
9261 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
9263 unsigned int bytes_read
;
9265 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9268 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
9269 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
9271 Return the corresponding abbrev, or NULL if the number is zero (indicating
9272 an empty DIE). In either case *BYTES_READ will be set to the length of
9273 the initial number. */
9275 static struct abbrev_info
*
9276 peek_die_abbrev (const die_reader_specs
&reader
,
9277 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
9279 dwarf2_cu
*cu
= reader
.cu
;
9280 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
9281 unsigned int abbrev_number
9282 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
9284 if (abbrev_number
== 0)
9287 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
9290 error (_("Dwarf Error: Could not find abbrev number %d in %s"
9291 " at offset %s [in module %s]"),
9292 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
9293 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
9299 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9300 Returns a pointer to the end of a series of DIEs, terminated by an empty
9301 DIE. Any children of the skipped DIEs will also be skipped. */
9303 static const gdb_byte
*
9304 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
9308 unsigned int bytes_read
;
9309 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
9312 return info_ptr
+ bytes_read
;
9314 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
9318 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9319 INFO_PTR should point just after the initial uleb128 of a DIE, and the
9320 abbrev corresponding to that skipped uleb128 should be passed in
9321 ABBREV. Returns a pointer to this DIE's sibling, skipping any
9324 static const gdb_byte
*
9325 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
9326 struct abbrev_info
*abbrev
)
9328 unsigned int bytes_read
;
9329 struct attribute attr
;
9330 bfd
*abfd
= reader
->abfd
;
9331 struct dwarf2_cu
*cu
= reader
->cu
;
9332 const gdb_byte
*buffer
= reader
->buffer
;
9333 const gdb_byte
*buffer_end
= reader
->buffer_end
;
9334 unsigned int form
, i
;
9336 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
9338 /* The only abbrev we care about is DW_AT_sibling. */
9339 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
9342 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
,
9344 if (attr
.form
== DW_FORM_ref_addr
)
9345 complaint (_("ignoring absolute DW_AT_sibling"));
9348 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
9349 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
9351 if (sibling_ptr
< info_ptr
)
9352 complaint (_("DW_AT_sibling points backwards"));
9353 else if (sibling_ptr
> reader
->buffer_end
)
9354 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
9360 /* If it isn't DW_AT_sibling, skip this attribute. */
9361 form
= abbrev
->attrs
[i
].form
;
9365 case DW_FORM_ref_addr
:
9366 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
9367 and later it is offset sized. */
9368 if (cu
->header
.version
== 2)
9369 info_ptr
+= cu
->header
.addr_size
;
9371 info_ptr
+= cu
->header
.offset_size
;
9373 case DW_FORM_GNU_ref_alt
:
9374 info_ptr
+= cu
->header
.offset_size
;
9377 info_ptr
+= cu
->header
.addr_size
;
9385 case DW_FORM_flag_present
:
9386 case DW_FORM_implicit_const
:
9403 case DW_FORM_ref_sig8
:
9406 case DW_FORM_data16
:
9409 case DW_FORM_string
:
9410 read_direct_string (abfd
, info_ptr
, &bytes_read
);
9411 info_ptr
+= bytes_read
;
9413 case DW_FORM_sec_offset
:
9415 case DW_FORM_GNU_strp_alt
:
9416 info_ptr
+= cu
->header
.offset_size
;
9418 case DW_FORM_exprloc
:
9420 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9421 info_ptr
+= bytes_read
;
9423 case DW_FORM_block1
:
9424 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
9426 case DW_FORM_block2
:
9427 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
9429 case DW_FORM_block4
:
9430 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
9436 case DW_FORM_ref_udata
:
9437 case DW_FORM_GNU_addr_index
:
9438 case DW_FORM_GNU_str_index
:
9439 case DW_FORM_rnglistx
:
9440 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
9442 case DW_FORM_indirect
:
9443 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9444 info_ptr
+= bytes_read
;
9445 /* We need to continue parsing from here, so just go back to
9447 goto skip_attribute
;
9450 error (_("Dwarf Error: Cannot handle %s "
9451 "in DWARF reader [in module %s]"),
9452 dwarf_form_name (form
),
9453 bfd_get_filename (abfd
));
9457 if (abbrev
->has_children
)
9458 return skip_children (reader
, info_ptr
);
9463 /* Locate ORIG_PDI's sibling.
9464 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
9466 static const gdb_byte
*
9467 locate_pdi_sibling (const struct die_reader_specs
*reader
,
9468 struct partial_die_info
*orig_pdi
,
9469 const gdb_byte
*info_ptr
)
9471 /* Do we know the sibling already? */
9473 if (orig_pdi
->sibling
)
9474 return orig_pdi
->sibling
;
9476 /* Are there any children to deal with? */
9478 if (!orig_pdi
->has_children
)
9481 /* Skip the children the long way. */
9483 return skip_children (reader
, info_ptr
);
9486 /* Expand this partial symbol table into a full symbol table. SELF is
9490 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
9492 struct dwarf2_per_objfile
*dwarf2_per_objfile
9493 = get_dwarf2_per_objfile (objfile
);
9495 gdb_assert (!readin
);
9496 /* If this psymtab is constructed from a debug-only objfile, the
9497 has_section_at_zero flag will not necessarily be correct. We
9498 can get the correct value for this flag by looking at the data
9499 associated with the (presumably stripped) associated objfile. */
9500 if (objfile
->separate_debug_objfile_backlink
)
9502 struct dwarf2_per_objfile
*dpo_backlink
9503 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
9505 dwarf2_per_objfile
->has_section_at_zero
9506 = dpo_backlink
->has_section_at_zero
;
9509 dwarf2_per_objfile
->reading_partial_symbols
= 0;
9511 expand_psymtab (objfile
);
9513 process_cu_includes (dwarf2_per_objfile
);
9516 /* Reading in full CUs. */
9518 /* Add PER_CU to the queue. */
9521 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9522 enum language pretend_language
)
9524 struct dwarf2_queue_item
*item
;
9527 item
= XNEW (struct dwarf2_queue_item
);
9528 item
->per_cu
= per_cu
;
9529 item
->pretend_language
= pretend_language
;
9532 if (dwarf2_queue
== NULL
)
9533 dwarf2_queue
= item
;
9535 dwarf2_queue_tail
->next
= item
;
9537 dwarf2_queue_tail
= item
;
9540 /* If PER_CU is not yet queued, add it to the queue.
9541 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
9543 The result is non-zero if PER_CU was queued, otherwise the result is zero
9544 meaning either PER_CU is already queued or it is already loaded.
9546 N.B. There is an invariant here that if a CU is queued then it is loaded.
9547 The caller is required to load PER_CU if we return non-zero. */
9550 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
9551 struct dwarf2_per_cu_data
*per_cu
,
9552 enum language pretend_language
)
9554 /* We may arrive here during partial symbol reading, if we need full
9555 DIEs to process an unusual case (e.g. template arguments). Do
9556 not queue PER_CU, just tell our caller to load its DIEs. */
9557 if (per_cu
->dwarf2_per_objfile
->reading_partial_symbols
)
9559 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
9564 /* Mark the dependence relation so that we don't flush PER_CU
9566 if (dependent_cu
!= NULL
)
9567 dwarf2_add_dependence (dependent_cu
, per_cu
);
9569 /* If it's already on the queue, we have nothing to do. */
9573 /* If the compilation unit is already loaded, just mark it as
9575 if (per_cu
->cu
!= NULL
)
9577 per_cu
->cu
->last_used
= 0;
9581 /* Add it to the queue. */
9582 queue_comp_unit (per_cu
, pretend_language
);
9587 /* Process the queue. */
9590 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9592 struct dwarf2_queue_item
*item
, *next_item
;
9594 if (dwarf_read_debug
)
9596 fprintf_unfiltered (gdb_stdlog
,
9597 "Expanding one or more symtabs of objfile %s ...\n",
9598 objfile_name (dwarf2_per_objfile
->objfile
));
9601 /* The queue starts out with one item, but following a DIE reference
9602 may load a new CU, adding it to the end of the queue. */
9603 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
9605 if ((dwarf2_per_objfile
->using_index
9606 ? !item
->per_cu
->v
.quick
->compunit_symtab
9607 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
9608 /* Skip dummy CUs. */
9609 && item
->per_cu
->cu
!= NULL
)
9611 struct dwarf2_per_cu_data
*per_cu
= item
->per_cu
;
9612 unsigned int debug_print_threshold
;
9615 if (per_cu
->is_debug_types
)
9617 struct signatured_type
*sig_type
=
9618 (struct signatured_type
*) per_cu
;
9620 sprintf (buf
, "TU %s at offset %s",
9621 hex_string (sig_type
->signature
),
9622 sect_offset_str (per_cu
->sect_off
));
9623 /* There can be 100s of TUs.
9624 Only print them in verbose mode. */
9625 debug_print_threshold
= 2;
9629 sprintf (buf
, "CU at offset %s",
9630 sect_offset_str (per_cu
->sect_off
));
9631 debug_print_threshold
= 1;
9634 if (dwarf_read_debug
>= debug_print_threshold
)
9635 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
9637 if (per_cu
->is_debug_types
)
9638 process_full_type_unit (per_cu
, item
->pretend_language
);
9640 process_full_comp_unit (per_cu
, item
->pretend_language
);
9642 if (dwarf_read_debug
>= debug_print_threshold
)
9643 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
9646 item
->per_cu
->queued
= 0;
9647 next_item
= item
->next
;
9651 dwarf2_queue_tail
= NULL
;
9653 if (dwarf_read_debug
)
9655 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
9656 objfile_name (dwarf2_per_objfile
->objfile
));
9660 /* Read in full symbols for PST, and anything it depends on. */
9663 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
9665 struct dwarf2_per_cu_data
*per_cu
;
9670 read_dependencies (objfile
);
9672 per_cu
= per_cu_data
;
9676 /* It's an include file, no symbols to read for it.
9677 Everything is in the parent symtab. */
9682 dw2_do_instantiate_symtab (per_cu
, false);
9685 /* Trivial hash function for die_info: the hash value of a DIE
9686 is its offset in .debug_info for this objfile. */
9689 die_hash (const void *item
)
9691 const struct die_info
*die
= (const struct die_info
*) item
;
9693 return to_underlying (die
->sect_off
);
9696 /* Trivial comparison function for die_info structures: two DIEs
9697 are equal if they have the same offset. */
9700 die_eq (const void *item_lhs
, const void *item_rhs
)
9702 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
9703 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
9705 return die_lhs
->sect_off
== die_rhs
->sect_off
;
9708 /* Load the DIEs associated with PER_CU into memory. */
9711 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
9713 enum language pretend_language
)
9715 gdb_assert (! this_cu
->is_debug_types
);
9717 cutu_reader
reader (this_cu
, NULL
, 1, 1, skip_partial
);
9721 struct dwarf2_cu
*cu
= reader
.cu
;
9722 const gdb_byte
*info_ptr
= reader
.info_ptr
;
9724 gdb_assert (cu
->die_hash
== NULL
);
9726 htab_create_alloc_ex (cu
->header
.length
/ 12,
9730 &cu
->comp_unit_obstack
,
9731 hashtab_obstack_allocate
,
9732 dummy_obstack_deallocate
);
9734 if (reader
.has_children
)
9735 reader
.comp_unit_die
->child
9736 = read_die_and_siblings (&reader
, reader
.info_ptr
,
9737 &info_ptr
, reader
.comp_unit_die
);
9738 cu
->dies
= reader
.comp_unit_die
;
9739 /* comp_unit_die is not stored in die_hash, no need. */
9741 /* We try not to read any attributes in this function, because not
9742 all CUs needed for references have been loaded yet, and symbol
9743 table processing isn't initialized. But we have to set the CU language,
9744 or we won't be able to build types correctly.
9745 Similarly, if we do not read the producer, we can not apply
9746 producer-specific interpretation. */
9747 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
9750 /* Add a DIE to the delayed physname list. */
9753 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
9754 const char *name
, struct die_info
*die
,
9755 struct dwarf2_cu
*cu
)
9757 struct delayed_method_info mi
;
9759 mi
.fnfield_index
= fnfield_index
;
9763 cu
->method_list
.push_back (mi
);
9766 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
9767 "const" / "volatile". If so, decrements LEN by the length of the
9768 modifier and return true. Otherwise return false. */
9772 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
9774 size_t mod_len
= sizeof (mod
) - 1;
9775 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
9783 /* Compute the physnames of any methods on the CU's method list.
9785 The computation of method physnames is delayed in order to avoid the
9786 (bad) condition that one of the method's formal parameters is of an as yet
9790 compute_delayed_physnames (struct dwarf2_cu
*cu
)
9792 /* Only C++ delays computing physnames. */
9793 if (cu
->method_list
.empty ())
9795 gdb_assert (cu
->language
== language_cplus
);
9797 for (const delayed_method_info
&mi
: cu
->method_list
)
9799 const char *physname
;
9800 struct fn_fieldlist
*fn_flp
9801 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9802 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9803 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9804 = physname
? physname
: "";
9806 /* Since there's no tag to indicate whether a method is a
9807 const/volatile overload, extract that information out of the
9809 if (physname
!= NULL
)
9811 size_t len
= strlen (physname
);
9815 if (physname
[len
] == ')') /* shortcut */
9817 else if (check_modifier (physname
, len
, " const"))
9818 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9819 else if (check_modifier (physname
, len
, " volatile"))
9820 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9827 /* The list is no longer needed. */
9828 cu
->method_list
.clear ();
9831 /* Go objects should be embedded in a DW_TAG_module DIE,
9832 and it's not clear if/how imported objects will appear.
9833 To keep Go support simple until that's worked out,
9834 go back through what we've read and create something usable.
9835 We could do this while processing each DIE, and feels kinda cleaner,
9836 but that way is more invasive.
9837 This is to, for example, allow the user to type "p var" or "b main"
9838 without having to specify the package name, and allow lookups
9839 of module.object to work in contexts that use the expression
9843 fixup_go_packaging (struct dwarf2_cu
*cu
)
9845 gdb::unique_xmalloc_ptr
<char> package_name
;
9846 struct pending
*list
;
9849 for (list
= *cu
->get_builder ()->get_global_symbols ();
9853 for (i
= 0; i
< list
->nsyms
; ++i
)
9855 struct symbol
*sym
= list
->symbol
[i
];
9857 if (sym
->language () == language_go
9858 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9860 gdb::unique_xmalloc_ptr
<char> this_package_name
9861 (go_symbol_package_name (sym
));
9863 if (this_package_name
== NULL
)
9865 if (package_name
== NULL
)
9866 package_name
= std::move (this_package_name
);
9869 struct objfile
*objfile
9870 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9871 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9872 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9873 (symbol_symtab (sym
) != NULL
9874 ? symtab_to_filename_for_display
9875 (symbol_symtab (sym
))
9876 : objfile_name (objfile
)),
9877 this_package_name
.get (), package_name
.get ());
9883 if (package_name
!= NULL
)
9885 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9886 const char *saved_package_name
9887 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
, package_name
.get ());
9888 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9889 saved_package_name
);
9892 sym
= allocate_symbol (objfile
);
9893 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9894 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9895 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9896 e.g., "main" finds the "main" module and not C's main(). */
9897 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9898 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9899 SYMBOL_TYPE (sym
) = type
;
9901 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9905 /* Allocate a fully-qualified name consisting of the two parts on the
9909 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9911 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9914 /* A helper that allocates a struct discriminant_info to attach to a
9917 static struct discriminant_info
*
9918 alloc_discriminant_info (struct type
*type
, int discriminant_index
,
9921 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9922 gdb_assert (discriminant_index
== -1
9923 || (discriminant_index
>= 0
9924 && discriminant_index
< TYPE_NFIELDS (type
)));
9925 gdb_assert (default_index
== -1
9926 || (default_index
>= 0 && default_index
< TYPE_NFIELDS (type
)));
9928 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
9930 struct discriminant_info
*disc
9931 = ((struct discriminant_info
*)
9933 offsetof (struct discriminant_info
, discriminants
)
9934 + TYPE_NFIELDS (type
) * sizeof (disc
->discriminants
[0])));
9935 disc
->default_index
= default_index
;
9936 disc
->discriminant_index
= discriminant_index
;
9938 struct dynamic_prop prop
;
9939 prop
.kind
= PROP_UNDEFINED
;
9940 prop
.data
.baton
= disc
;
9942 add_dyn_prop (DYN_PROP_DISCRIMINATED
, prop
, type
);
9947 /* Some versions of rustc emitted enums in an unusual way.
9949 Ordinary enums were emitted as unions. The first element of each
9950 structure in the union was named "RUST$ENUM$DISR". This element
9951 held the discriminant.
9953 These versions of Rust also implemented the "non-zero"
9954 optimization. When the enum had two values, and one is empty and
9955 the other holds a pointer that cannot be zero, the pointer is used
9956 as the discriminant, with a zero value meaning the empty variant.
9957 Here, the union's first member is of the form
9958 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9959 where the fieldnos are the indices of the fields that should be
9960 traversed in order to find the field (which may be several fields deep)
9961 and the variantname is the name of the variant of the case when the
9964 This function recognizes whether TYPE is of one of these forms,
9965 and, if so, smashes it to be a variant type. */
9968 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9970 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9972 /* We don't need to deal with empty enums. */
9973 if (TYPE_NFIELDS (type
) == 0)
9976 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9977 if (TYPE_NFIELDS (type
) == 1
9978 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9980 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9982 /* Decode the field name to find the offset of the
9984 ULONGEST bit_offset
= 0;
9985 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9986 while (name
[0] >= '0' && name
[0] <= '9')
9989 unsigned long index
= strtoul (name
, &tail
, 10);
9992 || index
>= TYPE_NFIELDS (field_type
)
9993 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9994 != FIELD_LOC_KIND_BITPOS
))
9996 complaint (_("Could not parse Rust enum encoding string \"%s\""
9998 TYPE_FIELD_NAME (type
, 0),
9999 objfile_name (objfile
));
10004 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
10005 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
10008 /* Make a union to hold the variants. */
10009 struct type
*union_type
= alloc_type (objfile
);
10010 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10011 TYPE_NFIELDS (union_type
) = 3;
10012 TYPE_FIELDS (union_type
)
10013 = (struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
));
10014 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10015 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
10017 /* Put the discriminant must at index 0. */
10018 TYPE_FIELD_TYPE (union_type
, 0) = field_type
;
10019 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
10020 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
10021 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 0), bit_offset
);
10023 /* The order of fields doesn't really matter, so put the real
10024 field at index 1 and the data-less field at index 2. */
10025 struct discriminant_info
*disc
10026 = alloc_discriminant_info (union_type
, 0, 1);
10027 TYPE_FIELD (union_type
, 1) = TYPE_FIELD (type
, 0);
10028 TYPE_FIELD_NAME (union_type
, 1)
10029 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1)));
10030 TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1))
10031 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
10032 TYPE_FIELD_NAME (union_type
, 1));
10034 const char *dataless_name
10035 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
10037 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
10039 TYPE_FIELD_TYPE (union_type
, 2) = dataless_type
;
10040 /* NAME points into the original discriminant name, which
10041 already has the correct lifetime. */
10042 TYPE_FIELD_NAME (union_type
, 2) = name
;
10043 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 2), 0);
10044 disc
->discriminants
[2] = 0;
10046 /* Smash this type to be a structure type. We have to do this
10047 because the type has already been recorded. */
10048 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10049 TYPE_NFIELDS (type
) = 1;
10051 = (struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
));
10053 /* Install the variant part. */
10054 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10055 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10056 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10058 /* A union with a single anonymous field is probably an old-style
10059 univariant enum. */
10060 else if (TYPE_NFIELDS (type
) == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
10062 /* Smash this type to be a structure type. We have to do this
10063 because the type has already been recorded. */
10064 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10066 /* Make a union to hold the variants. */
10067 struct type
*union_type
= alloc_type (objfile
);
10068 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10069 TYPE_NFIELDS (union_type
) = TYPE_NFIELDS (type
);
10070 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10071 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
10072 TYPE_FIELDS (union_type
) = TYPE_FIELDS (type
);
10074 struct type
*field_type
= TYPE_FIELD_TYPE (union_type
, 0);
10075 const char *variant_name
10076 = rust_last_path_segment (TYPE_NAME (field_type
));
10077 TYPE_FIELD_NAME (union_type
, 0) = variant_name
;
10078 TYPE_NAME (field_type
)
10079 = rust_fully_qualify (&objfile
->objfile_obstack
,
10080 TYPE_NAME (type
), variant_name
);
10082 /* Install the union in the outer struct type. */
10083 TYPE_NFIELDS (type
) = 1;
10085 = (struct field
*) TYPE_ZALLOC (union_type
, sizeof (struct field
));
10086 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10087 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10088 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10090 alloc_discriminant_info (union_type
, -1, 0);
10094 struct type
*disr_type
= nullptr;
10095 for (int i
= 0; i
< TYPE_NFIELDS (type
); ++i
)
10097 disr_type
= TYPE_FIELD_TYPE (type
, i
);
10099 if (TYPE_CODE (disr_type
) != TYPE_CODE_STRUCT
)
10101 /* All fields of a true enum will be structs. */
10104 else if (TYPE_NFIELDS (disr_type
) == 0)
10106 /* Could be data-less variant, so keep going. */
10107 disr_type
= nullptr;
10109 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
10110 "RUST$ENUM$DISR") != 0)
10112 /* Not a Rust enum. */
10122 /* If we got here without a discriminant, then it's probably
10124 if (disr_type
== nullptr)
10127 /* Smash this type to be a structure type. We have to do this
10128 because the type has already been recorded. */
10129 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10131 /* Make a union to hold the variants. */
10132 struct field
*disr_field
= &TYPE_FIELD (disr_type
, 0);
10133 struct type
*union_type
= alloc_type (objfile
);
10134 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10135 TYPE_NFIELDS (union_type
) = 1 + TYPE_NFIELDS (type
);
10136 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10137 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
10138 TYPE_FIELDS (union_type
)
10139 = (struct field
*) TYPE_ZALLOC (union_type
,
10140 (TYPE_NFIELDS (union_type
)
10141 * sizeof (struct field
)));
10143 memcpy (TYPE_FIELDS (union_type
) + 1, TYPE_FIELDS (type
),
10144 TYPE_NFIELDS (type
) * sizeof (struct field
));
10146 /* Install the discriminant at index 0 in the union. */
10147 TYPE_FIELD (union_type
, 0) = *disr_field
;
10148 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
10149 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
10151 /* Install the union in the outer struct type. */
10152 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10153 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10154 TYPE_NFIELDS (type
) = 1;
10156 /* Set the size and offset of the union type. */
10157 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10159 /* We need a way to find the correct discriminant given a
10160 variant name. For convenience we build a map here. */
10161 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
10162 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
10163 for (int i
= 0; i
< TYPE_NFIELDS (enum_type
); ++i
)
10165 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
10168 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
10169 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
10173 int n_fields
= TYPE_NFIELDS (union_type
);
10174 struct discriminant_info
*disc
10175 = alloc_discriminant_info (union_type
, 0, -1);
10176 /* Skip the discriminant here. */
10177 for (int i
= 1; i
< n_fields
; ++i
)
10179 /* Find the final word in the name of this variant's type.
10180 That name can be used to look up the correct
10182 const char *variant_name
10183 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
,
10186 auto iter
= discriminant_map
.find (variant_name
);
10187 if (iter
!= discriminant_map
.end ())
10188 disc
->discriminants
[i
] = iter
->second
;
10190 /* Remove the discriminant field, if it exists. */
10191 struct type
*sub_type
= TYPE_FIELD_TYPE (union_type
, i
);
10192 if (TYPE_NFIELDS (sub_type
) > 0)
10194 --TYPE_NFIELDS (sub_type
);
10195 ++TYPE_FIELDS (sub_type
);
10197 TYPE_FIELD_NAME (union_type
, i
) = variant_name
;
10198 TYPE_NAME (sub_type
)
10199 = rust_fully_qualify (&objfile
->objfile_obstack
,
10200 TYPE_NAME (type
), variant_name
);
10205 /* Rewrite some Rust unions to be structures with variants parts. */
10208 rust_union_quirks (struct dwarf2_cu
*cu
)
10210 gdb_assert (cu
->language
== language_rust
);
10211 for (type
*type_
: cu
->rust_unions
)
10212 quirk_rust_enum (type_
, cu
->per_cu
->dwarf2_per_objfile
->objfile
);
10213 /* We don't need this any more. */
10214 cu
->rust_unions
.clear ();
10217 /* Return the symtab for PER_CU. This works properly regardless of
10218 whether we're using the index or psymtabs. */
10220 static struct compunit_symtab
*
10221 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
10223 return (per_cu
->dwarf2_per_objfile
->using_index
10224 ? per_cu
->v
.quick
->compunit_symtab
10225 : per_cu
->v
.psymtab
->compunit_symtab
);
10228 /* A helper function for computing the list of all symbol tables
10229 included by PER_CU. */
10232 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
10233 htab_t all_children
, htab_t all_type_symtabs
,
10234 struct dwarf2_per_cu_data
*per_cu
,
10235 struct compunit_symtab
*immediate_parent
)
10238 struct compunit_symtab
*cust
;
10240 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
10243 /* This inclusion and its children have been processed. */
10248 /* Only add a CU if it has a symbol table. */
10249 cust
= get_compunit_symtab (per_cu
);
10252 /* If this is a type unit only add its symbol table if we haven't
10253 seen it yet (type unit per_cu's can share symtabs). */
10254 if (per_cu
->is_debug_types
)
10256 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
10260 result
->push_back (cust
);
10261 if (cust
->user
== NULL
)
10262 cust
->user
= immediate_parent
;
10267 result
->push_back (cust
);
10268 if (cust
->user
== NULL
)
10269 cust
->user
= immediate_parent
;
10273 if (!per_cu
->imported_symtabs_empty ())
10274 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
10276 recursively_compute_inclusions (result
, all_children
,
10277 all_type_symtabs
, ptr
, cust
);
10281 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
10285 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
10287 gdb_assert (! per_cu
->is_debug_types
);
10289 if (!per_cu
->imported_symtabs_empty ())
10292 std::vector
<compunit_symtab
*> result_symtabs
;
10293 htab_t all_children
, all_type_symtabs
;
10294 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
10296 /* If we don't have a symtab, we can just skip this case. */
10300 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10301 NULL
, xcalloc
, xfree
);
10302 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10303 NULL
, xcalloc
, xfree
);
10305 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
10307 recursively_compute_inclusions (&result_symtabs
, all_children
,
10308 all_type_symtabs
, ptr
, cust
);
10311 /* Now we have a transitive closure of all the included symtabs. */
10312 len
= result_symtabs
.size ();
10314 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
10315 struct compunit_symtab
*, len
+ 1);
10316 memcpy (cust
->includes
, result_symtabs
.data (),
10317 len
* sizeof (compunit_symtab
*));
10318 cust
->includes
[len
] = NULL
;
10320 htab_delete (all_children
);
10321 htab_delete (all_type_symtabs
);
10325 /* Compute the 'includes' field for the symtabs of all the CUs we just
10329 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
10331 for (dwarf2_per_cu_data
*iter
: dwarf2_per_objfile
->just_read_cus
)
10333 if (! iter
->is_debug_types
)
10334 compute_compunit_symtab_includes (iter
);
10337 dwarf2_per_objfile
->just_read_cus
.clear ();
10340 /* Generate full symbol information for PER_CU, whose DIEs have
10341 already been loaded into memory. */
10344 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
10345 enum language pretend_language
)
10347 struct dwarf2_cu
*cu
= per_cu
->cu
;
10348 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10349 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10350 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10351 CORE_ADDR lowpc
, highpc
;
10352 struct compunit_symtab
*cust
;
10353 CORE_ADDR baseaddr
;
10354 struct block
*static_block
;
10357 baseaddr
= objfile
->text_section_offset ();
10359 /* Clear the list here in case something was left over. */
10360 cu
->method_list
.clear ();
10362 cu
->language
= pretend_language
;
10363 cu
->language_defn
= language_def (cu
->language
);
10365 /* Do line number decoding in read_file_scope () */
10366 process_die (cu
->dies
, cu
);
10368 /* For now fudge the Go package. */
10369 if (cu
->language
== language_go
)
10370 fixup_go_packaging (cu
);
10372 /* Now that we have processed all the DIEs in the CU, all the types
10373 should be complete, and it should now be safe to compute all of the
10375 compute_delayed_physnames (cu
);
10377 if (cu
->language
== language_rust
)
10378 rust_union_quirks (cu
);
10380 /* Some compilers don't define a DW_AT_high_pc attribute for the
10381 compilation unit. If the DW_AT_high_pc is missing, synthesize
10382 it, by scanning the DIE's below the compilation unit. */
10383 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
10385 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
10386 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
10388 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
10389 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
10390 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
10391 addrmap to help ensure it has an accurate map of pc values belonging to
10393 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
10395 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
10396 SECT_OFF_TEXT (objfile
),
10401 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
10403 /* Set symtab language to language from DW_AT_language. If the
10404 compilation is from a C file generated by language preprocessors, do
10405 not set the language if it was already deduced by start_subfile. */
10406 if (!(cu
->language
== language_c
10407 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
10408 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10410 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
10411 produce DW_AT_location with location lists but it can be possibly
10412 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
10413 there were bugs in prologue debug info, fixed later in GCC-4.5
10414 by "unwind info for epilogues" patch (which is not directly related).
10416 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
10417 needed, it would be wrong due to missing DW_AT_producer there.
10419 Still one can confuse GDB by using non-standard GCC compilation
10420 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
10422 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
10423 cust
->locations_valid
= 1;
10425 if (gcc_4_minor
>= 5)
10426 cust
->epilogue_unwind_valid
= 1;
10428 cust
->call_site_htab
= cu
->call_site_htab
;
10431 if (dwarf2_per_objfile
->using_index
)
10432 per_cu
->v
.quick
->compunit_symtab
= cust
;
10435 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
10436 pst
->compunit_symtab
= cust
;
10437 pst
->readin
= true;
10440 /* Push it for inclusion processing later. */
10441 dwarf2_per_objfile
->just_read_cus
.push_back (per_cu
);
10443 /* Not needed any more. */
10444 cu
->reset_builder ();
10447 /* Generate full symbol information for type unit PER_CU, whose DIEs have
10448 already been loaded into memory. */
10451 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
10452 enum language pretend_language
)
10454 struct dwarf2_cu
*cu
= per_cu
->cu
;
10455 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10456 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10457 struct compunit_symtab
*cust
;
10458 struct signatured_type
*sig_type
;
10460 gdb_assert (per_cu
->is_debug_types
);
10461 sig_type
= (struct signatured_type
*) per_cu
;
10463 /* Clear the list here in case something was left over. */
10464 cu
->method_list
.clear ();
10466 cu
->language
= pretend_language
;
10467 cu
->language_defn
= language_def (cu
->language
);
10469 /* The symbol tables are set up in read_type_unit_scope. */
10470 process_die (cu
->dies
, cu
);
10472 /* For now fudge the Go package. */
10473 if (cu
->language
== language_go
)
10474 fixup_go_packaging (cu
);
10476 /* Now that we have processed all the DIEs in the CU, all the types
10477 should be complete, and it should now be safe to compute all of the
10479 compute_delayed_physnames (cu
);
10481 if (cu
->language
== language_rust
)
10482 rust_union_quirks (cu
);
10484 /* TUs share symbol tables.
10485 If this is the first TU to use this symtab, complete the construction
10486 of it with end_expandable_symtab. Otherwise, complete the addition of
10487 this TU's symbols to the existing symtab. */
10488 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
10490 buildsym_compunit
*builder
= cu
->get_builder ();
10491 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
10492 sig_type
->type_unit_group
->compunit_symtab
= cust
;
10496 /* Set symtab language to language from DW_AT_language. If the
10497 compilation is from a C file generated by language preprocessors,
10498 do not set the language if it was already deduced by
10500 if (!(cu
->language
== language_c
10501 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
10502 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10507 cu
->get_builder ()->augment_type_symtab ();
10508 cust
= sig_type
->type_unit_group
->compunit_symtab
;
10511 if (dwarf2_per_objfile
->using_index
)
10512 per_cu
->v
.quick
->compunit_symtab
= cust
;
10515 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
10516 pst
->compunit_symtab
= cust
;
10517 pst
->readin
= true;
10520 /* Not needed any more. */
10521 cu
->reset_builder ();
10524 /* Process an imported unit DIE. */
10527 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10529 struct attribute
*attr
;
10531 /* For now we don't handle imported units in type units. */
10532 if (cu
->per_cu
->is_debug_types
)
10534 error (_("Dwarf Error: DW_TAG_imported_unit is not"
10535 " supported in type units [in module %s]"),
10536 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
10539 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10542 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
10543 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
10544 dwarf2_per_cu_data
*per_cu
10545 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
10546 cu
->per_cu
->dwarf2_per_objfile
);
10548 /* If necessary, add it to the queue and load its DIEs. */
10549 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
10550 load_full_comp_unit (per_cu
, false, cu
->language
);
10552 cu
->per_cu
->imported_symtabs_push (per_cu
);
10556 /* RAII object that represents a process_die scope: i.e.,
10557 starts/finishes processing a DIE. */
10558 class process_die_scope
10561 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
10562 : m_die (die
), m_cu (cu
)
10564 /* We should only be processing DIEs not already in process. */
10565 gdb_assert (!m_die
->in_process
);
10566 m_die
->in_process
= true;
10569 ~process_die_scope ()
10571 m_die
->in_process
= false;
10573 /* If we're done processing the DIE for the CU that owns the line
10574 header, we don't need the line header anymore. */
10575 if (m_cu
->line_header_die_owner
== m_die
)
10577 delete m_cu
->line_header
;
10578 m_cu
->line_header
= NULL
;
10579 m_cu
->line_header_die_owner
= NULL
;
10588 /* Process a die and its children. */
10591 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10593 process_die_scope
scope (die
, cu
);
10597 case DW_TAG_padding
:
10599 case DW_TAG_compile_unit
:
10600 case DW_TAG_partial_unit
:
10601 read_file_scope (die
, cu
);
10603 case DW_TAG_type_unit
:
10604 read_type_unit_scope (die
, cu
);
10606 case DW_TAG_subprogram
:
10607 /* Nested subprograms in Fortran get a prefix. */
10608 if (cu
->language
== language_fortran
10609 && die
->parent
!= NULL
10610 && die
->parent
->tag
== DW_TAG_subprogram
)
10611 cu
->processing_has_namespace_info
= true;
10612 /* Fall through. */
10613 case DW_TAG_inlined_subroutine
:
10614 read_func_scope (die
, cu
);
10616 case DW_TAG_lexical_block
:
10617 case DW_TAG_try_block
:
10618 case DW_TAG_catch_block
:
10619 read_lexical_block_scope (die
, cu
);
10621 case DW_TAG_call_site
:
10622 case DW_TAG_GNU_call_site
:
10623 read_call_site_scope (die
, cu
);
10625 case DW_TAG_class_type
:
10626 case DW_TAG_interface_type
:
10627 case DW_TAG_structure_type
:
10628 case DW_TAG_union_type
:
10629 process_structure_scope (die
, cu
);
10631 case DW_TAG_enumeration_type
:
10632 process_enumeration_scope (die
, cu
);
10635 /* These dies have a type, but processing them does not create
10636 a symbol or recurse to process the children. Therefore we can
10637 read them on-demand through read_type_die. */
10638 case DW_TAG_subroutine_type
:
10639 case DW_TAG_set_type
:
10640 case DW_TAG_array_type
:
10641 case DW_TAG_pointer_type
:
10642 case DW_TAG_ptr_to_member_type
:
10643 case DW_TAG_reference_type
:
10644 case DW_TAG_rvalue_reference_type
:
10645 case DW_TAG_string_type
:
10648 case DW_TAG_base_type
:
10649 case DW_TAG_subrange_type
:
10650 case DW_TAG_typedef
:
10651 /* Add a typedef symbol for the type definition, if it has a
10653 new_symbol (die
, read_type_die (die
, cu
), cu
);
10655 case DW_TAG_common_block
:
10656 read_common_block (die
, cu
);
10658 case DW_TAG_common_inclusion
:
10660 case DW_TAG_namespace
:
10661 cu
->processing_has_namespace_info
= true;
10662 read_namespace (die
, cu
);
10664 case DW_TAG_module
:
10665 cu
->processing_has_namespace_info
= true;
10666 read_module (die
, cu
);
10668 case DW_TAG_imported_declaration
:
10669 cu
->processing_has_namespace_info
= true;
10670 if (read_namespace_alias (die
, cu
))
10672 /* The declaration is not a global namespace alias. */
10673 /* Fall through. */
10674 case DW_TAG_imported_module
:
10675 cu
->processing_has_namespace_info
= true;
10676 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
10677 || cu
->language
!= language_fortran
))
10678 complaint (_("Tag '%s' has unexpected children"),
10679 dwarf_tag_name (die
->tag
));
10680 read_import_statement (die
, cu
);
10683 case DW_TAG_imported_unit
:
10684 process_imported_unit_die (die
, cu
);
10687 case DW_TAG_variable
:
10688 read_variable (die
, cu
);
10692 new_symbol (die
, NULL
, cu
);
10697 /* DWARF name computation. */
10699 /* A helper function for dwarf2_compute_name which determines whether DIE
10700 needs to have the name of the scope prepended to the name listed in the
10704 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10706 struct attribute
*attr
;
10710 case DW_TAG_namespace
:
10711 case DW_TAG_typedef
:
10712 case DW_TAG_class_type
:
10713 case DW_TAG_interface_type
:
10714 case DW_TAG_structure_type
:
10715 case DW_TAG_union_type
:
10716 case DW_TAG_enumeration_type
:
10717 case DW_TAG_enumerator
:
10718 case DW_TAG_subprogram
:
10719 case DW_TAG_inlined_subroutine
:
10720 case DW_TAG_member
:
10721 case DW_TAG_imported_declaration
:
10724 case DW_TAG_variable
:
10725 case DW_TAG_constant
:
10726 /* We only need to prefix "globally" visible variables. These include
10727 any variable marked with DW_AT_external or any variable that
10728 lives in a namespace. [Variables in anonymous namespaces
10729 require prefixing, but they are not DW_AT_external.] */
10731 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
10733 struct dwarf2_cu
*spec_cu
= cu
;
10735 return die_needs_namespace (die_specification (die
, &spec_cu
),
10739 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10740 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
10741 && die
->parent
->tag
!= DW_TAG_module
)
10743 /* A variable in a lexical block of some kind does not need a
10744 namespace, even though in C++ such variables may be external
10745 and have a mangled name. */
10746 if (die
->parent
->tag
== DW_TAG_lexical_block
10747 || die
->parent
->tag
== DW_TAG_try_block
10748 || die
->parent
->tag
== DW_TAG_catch_block
10749 || die
->parent
->tag
== DW_TAG_subprogram
)
10758 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
10759 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10760 defined for the given DIE. */
10762 static struct attribute
*
10763 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
10765 struct attribute
*attr
;
10767 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
10769 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10774 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10775 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10776 defined for the given DIE. */
10778 static const char *
10779 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10781 const char *linkage_name
;
10783 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10784 if (linkage_name
== NULL
)
10785 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10787 return linkage_name
;
10790 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10791 compute the physname for the object, which include a method's:
10792 - formal parameters (C++),
10793 - receiver type (Go),
10795 The term "physname" is a bit confusing.
10796 For C++, for example, it is the demangled name.
10797 For Go, for example, it's the mangled name.
10799 For Ada, return the DIE's linkage name rather than the fully qualified
10800 name. PHYSNAME is ignored..
10802 The result is allocated on the objfile_obstack and canonicalized. */
10804 static const char *
10805 dwarf2_compute_name (const char *name
,
10806 struct die_info
*die
, struct dwarf2_cu
*cu
,
10809 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10812 name
= dwarf2_name (die
, cu
);
10814 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10815 but otherwise compute it by typename_concat inside GDB.
10816 FIXME: Actually this is not really true, or at least not always true.
10817 It's all very confusing. compute_and_set_names doesn't try to demangle
10818 Fortran names because there is no mangling standard. So new_symbol
10819 will set the demangled name to the result of dwarf2_full_name, and it is
10820 the demangled name that GDB uses if it exists. */
10821 if (cu
->language
== language_ada
10822 || (cu
->language
== language_fortran
&& physname
))
10824 /* For Ada unit, we prefer the linkage name over the name, as
10825 the former contains the exported name, which the user expects
10826 to be able to reference. Ideally, we want the user to be able
10827 to reference this entity using either natural or linkage name,
10828 but we haven't started looking at this enhancement yet. */
10829 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10831 if (linkage_name
!= NULL
)
10832 return linkage_name
;
10835 /* These are the only languages we know how to qualify names in. */
10837 && (cu
->language
== language_cplus
10838 || cu
->language
== language_fortran
|| cu
->language
== language_d
10839 || cu
->language
== language_rust
))
10841 if (die_needs_namespace (die
, cu
))
10843 const char *prefix
;
10844 const char *canonical_name
= NULL
;
10848 prefix
= determine_prefix (die
, cu
);
10849 if (*prefix
!= '\0')
10851 gdb::unique_xmalloc_ptr
<char> prefixed_name
10852 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10854 buf
.puts (prefixed_name
.get ());
10859 /* Template parameters may be specified in the DIE's DW_AT_name, or
10860 as children with DW_TAG_template_type_param or
10861 DW_TAG_value_type_param. If the latter, add them to the name
10862 here. If the name already has template parameters, then
10863 skip this step; some versions of GCC emit both, and
10864 it is more efficient to use the pre-computed name.
10866 Something to keep in mind about this process: it is very
10867 unlikely, or in some cases downright impossible, to produce
10868 something that will match the mangled name of a function.
10869 If the definition of the function has the same debug info,
10870 we should be able to match up with it anyway. But fallbacks
10871 using the minimal symbol, for instance to find a method
10872 implemented in a stripped copy of libstdc++, will not work.
10873 If we do not have debug info for the definition, we will have to
10874 match them up some other way.
10876 When we do name matching there is a related problem with function
10877 templates; two instantiated function templates are allowed to
10878 differ only by their return types, which we do not add here. */
10880 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10882 struct attribute
*attr
;
10883 struct die_info
*child
;
10886 die
->building_fullname
= 1;
10888 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10892 const gdb_byte
*bytes
;
10893 struct dwarf2_locexpr_baton
*baton
;
10896 if (child
->tag
!= DW_TAG_template_type_param
10897 && child
->tag
!= DW_TAG_template_value_param
)
10908 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10911 complaint (_("template parameter missing DW_AT_type"));
10912 buf
.puts ("UNKNOWN_TYPE");
10915 type
= die_type (child
, cu
);
10917 if (child
->tag
== DW_TAG_template_type_param
)
10919 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10920 &type_print_raw_options
);
10924 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10927 complaint (_("template parameter missing "
10928 "DW_AT_const_value"));
10929 buf
.puts ("UNKNOWN_VALUE");
10933 dwarf2_const_value_attr (attr
, type
, name
,
10934 &cu
->comp_unit_obstack
, cu
,
10935 &value
, &bytes
, &baton
);
10937 if (TYPE_NOSIGN (type
))
10938 /* GDB prints characters as NUMBER 'CHAR'. If that's
10939 changed, this can use value_print instead. */
10940 c_printchar (value
, type
, &buf
);
10943 struct value_print_options opts
;
10946 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10950 else if (bytes
!= NULL
)
10952 v
= allocate_value (type
);
10953 memcpy (value_contents_writeable (v
), bytes
,
10954 TYPE_LENGTH (type
));
10957 v
= value_from_longest (type
, value
);
10959 /* Specify decimal so that we do not depend on
10961 get_formatted_print_options (&opts
, 'd');
10963 value_print (v
, &buf
, &opts
);
10968 die
->building_fullname
= 0;
10972 /* Close the argument list, with a space if necessary
10973 (nested templates). */
10974 if (!buf
.empty () && buf
.string ().back () == '>')
10981 /* For C++ methods, append formal parameter type
10982 information, if PHYSNAME. */
10984 if (physname
&& die
->tag
== DW_TAG_subprogram
10985 && cu
->language
== language_cplus
)
10987 struct type
*type
= read_type_die (die
, cu
);
10989 c_type_print_args (type
, &buf
, 1, cu
->language
,
10990 &type_print_raw_options
);
10992 if (cu
->language
== language_cplus
)
10994 /* Assume that an artificial first parameter is
10995 "this", but do not crash if it is not. RealView
10996 marks unnamed (and thus unused) parameters as
10997 artificial; there is no way to differentiate
10999 if (TYPE_NFIELDS (type
) > 0
11000 && TYPE_FIELD_ARTIFICIAL (type
, 0)
11001 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
11002 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
11004 buf
.puts (" const");
11008 const std::string
&intermediate_name
= buf
.string ();
11010 if (cu
->language
== language_cplus
)
11012 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
11013 &objfile
->per_bfd
->storage_obstack
);
11015 /* If we only computed INTERMEDIATE_NAME, or if
11016 INTERMEDIATE_NAME is already canonical, then we need to
11017 copy it to the appropriate obstack. */
11018 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
11019 name
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
11020 intermediate_name
);
11022 name
= canonical_name
;
11029 /* Return the fully qualified name of DIE, based on its DW_AT_name.
11030 If scope qualifiers are appropriate they will be added. The result
11031 will be allocated on the storage_obstack, or NULL if the DIE does
11032 not have a name. NAME may either be from a previous call to
11033 dwarf2_name or NULL.
11035 The output string will be canonicalized (if C++). */
11037 static const char *
11038 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
11040 return dwarf2_compute_name (name
, die
, cu
, 0);
11043 /* Construct a physname for the given DIE in CU. NAME may either be
11044 from a previous call to dwarf2_name or NULL. The result will be
11045 allocated on the objfile_objstack or NULL if the DIE does not have a
11048 The output string will be canonicalized (if C++). */
11050 static const char *
11051 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
11053 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
11054 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
11057 /* In this case dwarf2_compute_name is just a shortcut not building anything
11059 if (!die_needs_namespace (die
, cu
))
11060 return dwarf2_compute_name (name
, die
, cu
, 1);
11062 mangled
= dw2_linkage_name (die
, cu
);
11064 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
11065 See https://github.com/rust-lang/rust/issues/32925. */
11066 if (cu
->language
== language_rust
&& mangled
!= NULL
11067 && strchr (mangled
, '{') != NULL
)
11070 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
11072 gdb::unique_xmalloc_ptr
<char> demangled
;
11073 if (mangled
!= NULL
)
11076 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
11078 /* Do nothing (do not demangle the symbol name). */
11080 else if (cu
->language
== language_go
)
11082 /* This is a lie, but we already lie to the caller new_symbol.
11083 new_symbol assumes we return the mangled name.
11084 This just undoes that lie until things are cleaned up. */
11088 /* Use DMGL_RET_DROP for C++ template functions to suppress
11089 their return type. It is easier for GDB users to search
11090 for such functions as `name(params)' than `long name(params)'.
11091 In such case the minimal symbol names do not match the full
11092 symbol names but for template functions there is never a need
11093 to look up their definition from their declaration so
11094 the only disadvantage remains the minimal symbol variant
11095 `long name(params)' does not have the proper inferior type. */
11096 demangled
.reset (gdb_demangle (mangled
,
11097 (DMGL_PARAMS
| DMGL_ANSI
11098 | DMGL_RET_DROP
)));
11101 canon
= demangled
.get ();
11109 if (canon
== NULL
|| check_physname
)
11111 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
11113 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
11115 /* It may not mean a bug in GDB. The compiler could also
11116 compute DW_AT_linkage_name incorrectly. But in such case
11117 GDB would need to be bug-to-bug compatible. */
11119 complaint (_("Computed physname <%s> does not match demangled <%s> "
11120 "(from linkage <%s>) - DIE at %s [in module %s]"),
11121 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
11122 objfile_name (objfile
));
11124 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
11125 is available here - over computed PHYSNAME. It is safer
11126 against both buggy GDB and buggy compilers. */
11140 retval
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
, retval
);
11145 /* Inspect DIE in CU for a namespace alias. If one exists, record
11146 a new symbol for it.
11148 Returns 1 if a namespace alias was recorded, 0 otherwise. */
11151 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
11153 struct attribute
*attr
;
11155 /* If the die does not have a name, this is not a namespace
11157 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
11161 struct die_info
*d
= die
;
11162 struct dwarf2_cu
*imported_cu
= cu
;
11164 /* If the compiler has nested DW_AT_imported_declaration DIEs,
11165 keep inspecting DIEs until we hit the underlying import. */
11166 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
11167 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
11169 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
11173 d
= follow_die_ref (d
, attr
, &imported_cu
);
11174 if (d
->tag
!= DW_TAG_imported_declaration
)
11178 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
11180 complaint (_("DIE at %s has too many recursively imported "
11181 "declarations"), sect_offset_str (d
->sect_off
));
11188 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
11190 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
11191 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
11193 /* This declaration is a global namespace alias. Add
11194 a symbol for it whose type is the aliased namespace. */
11195 new_symbol (die
, type
, cu
);
11204 /* Return the using directives repository (global or local?) to use in the
11205 current context for CU.
11207 For Ada, imported declarations can materialize renamings, which *may* be
11208 global. However it is impossible (for now?) in DWARF to distinguish
11209 "external" imported declarations and "static" ones. As all imported
11210 declarations seem to be static in all other languages, make them all CU-wide
11211 global only in Ada. */
11213 static struct using_direct
**
11214 using_directives (struct dwarf2_cu
*cu
)
11216 if (cu
->language
== language_ada
11217 && cu
->get_builder ()->outermost_context_p ())
11218 return cu
->get_builder ()->get_global_using_directives ();
11220 return cu
->get_builder ()->get_local_using_directives ();
11223 /* Read the import statement specified by the given die and record it. */
11226 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
11228 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
11229 struct attribute
*import_attr
;
11230 struct die_info
*imported_die
, *child_die
;
11231 struct dwarf2_cu
*imported_cu
;
11232 const char *imported_name
;
11233 const char *imported_name_prefix
;
11234 const char *canonical_name
;
11235 const char *import_alias
;
11236 const char *imported_declaration
= NULL
;
11237 const char *import_prefix
;
11238 std::vector
<const char *> excludes
;
11240 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
11241 if (import_attr
== NULL
)
11243 complaint (_("Tag '%s' has no DW_AT_import"),
11244 dwarf_tag_name (die
->tag
));
11249 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
11250 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11251 if (imported_name
== NULL
)
11253 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
11255 The import in the following code:
11269 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
11270 <52> DW_AT_decl_file : 1
11271 <53> DW_AT_decl_line : 6
11272 <54> DW_AT_import : <0x75>
11273 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
11274 <59> DW_AT_name : B
11275 <5b> DW_AT_decl_file : 1
11276 <5c> DW_AT_decl_line : 2
11277 <5d> DW_AT_type : <0x6e>
11279 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
11280 <76> DW_AT_byte_size : 4
11281 <77> DW_AT_encoding : 5 (signed)
11283 imports the wrong die ( 0x75 instead of 0x58 ).
11284 This case will be ignored until the gcc bug is fixed. */
11288 /* Figure out the local name after import. */
11289 import_alias
= dwarf2_name (die
, cu
);
11291 /* Figure out where the statement is being imported to. */
11292 import_prefix
= determine_prefix (die
, cu
);
11294 /* Figure out what the scope of the imported die is and prepend it
11295 to the name of the imported die. */
11296 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
11298 if (imported_die
->tag
!= DW_TAG_namespace
11299 && imported_die
->tag
!= DW_TAG_module
)
11301 imported_declaration
= imported_name
;
11302 canonical_name
= imported_name_prefix
;
11304 else if (strlen (imported_name_prefix
) > 0)
11305 canonical_name
= obconcat (&objfile
->objfile_obstack
,
11306 imported_name_prefix
,
11307 (cu
->language
== language_d
? "." : "::"),
11308 imported_name
, (char *) NULL
);
11310 canonical_name
= imported_name
;
11312 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
11313 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
11314 child_die
= sibling_die (child_die
))
11316 /* DWARF-4: A Fortran use statement with a “rename list” may be
11317 represented by an imported module entry with an import attribute
11318 referring to the module and owned entries corresponding to those
11319 entities that are renamed as part of being imported. */
11321 if (child_die
->tag
!= DW_TAG_imported_declaration
)
11323 complaint (_("child DW_TAG_imported_declaration expected "
11324 "- DIE at %s [in module %s]"),
11325 sect_offset_str (child_die
->sect_off
),
11326 objfile_name (objfile
));
11330 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
11331 if (import_attr
== NULL
)
11333 complaint (_("Tag '%s' has no DW_AT_import"),
11334 dwarf_tag_name (child_die
->tag
));
11339 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
11341 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11342 if (imported_name
== NULL
)
11344 complaint (_("child DW_TAG_imported_declaration has unknown "
11345 "imported name - DIE at %s [in module %s]"),
11346 sect_offset_str (child_die
->sect_off
),
11347 objfile_name (objfile
));
11351 excludes
.push_back (imported_name
);
11353 process_die (child_die
, cu
);
11356 add_using_directive (using_directives (cu
),
11360 imported_declaration
,
11363 &objfile
->objfile_obstack
);
11366 /* ICC<14 does not output the required DW_AT_declaration on incomplete
11367 types, but gives them a size of zero. Starting with version 14,
11368 ICC is compatible with GCC. */
11371 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
11373 if (!cu
->checked_producer
)
11374 check_producer (cu
);
11376 return cu
->producer_is_icc_lt_14
;
11379 /* ICC generates a DW_AT_type for C void functions. This was observed on
11380 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
11381 which says that void functions should not have a DW_AT_type. */
11384 producer_is_icc (struct dwarf2_cu
*cu
)
11386 if (!cu
->checked_producer
)
11387 check_producer (cu
);
11389 return cu
->producer_is_icc
;
11392 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
11393 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
11394 this, it was first present in GCC release 4.3.0. */
11397 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
11399 if (!cu
->checked_producer
)
11400 check_producer (cu
);
11402 return cu
->producer_is_gcc_lt_4_3
;
11405 static file_and_directory
11406 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
11408 file_and_directory res
;
11410 /* Find the filename. Do not use dwarf2_name here, since the filename
11411 is not a source language identifier. */
11412 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
11413 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
11415 if (res
.comp_dir
== NULL
11416 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
11417 && IS_ABSOLUTE_PATH (res
.name
))
11419 res
.comp_dir_storage
= ldirname (res
.name
);
11420 if (!res
.comp_dir_storage
.empty ())
11421 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
11423 if (res
.comp_dir
!= NULL
)
11425 /* Irix 6.2 native cc prepends <machine>.: to the compilation
11426 directory, get rid of it. */
11427 const char *cp
= strchr (res
.comp_dir
, ':');
11429 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
11430 res
.comp_dir
= cp
+ 1;
11433 if (res
.name
== NULL
)
11434 res
.name
= "<unknown>";
11439 /* Handle DW_AT_stmt_list for a compilation unit.
11440 DIE is the DW_TAG_compile_unit die for CU.
11441 COMP_DIR is the compilation directory. LOWPC is passed to
11442 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
11445 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
11446 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
11448 struct dwarf2_per_objfile
*dwarf2_per_objfile
11449 = cu
->per_cu
->dwarf2_per_objfile
;
11450 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11451 struct attribute
*attr
;
11452 struct line_header line_header_local
;
11453 hashval_t line_header_local_hash
;
11455 int decode_mapping
;
11457 gdb_assert (! cu
->per_cu
->is_debug_types
);
11459 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
11463 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11465 /* The line header hash table is only created if needed (it exists to
11466 prevent redundant reading of the line table for partial_units).
11467 If we're given a partial_unit, we'll need it. If we're given a
11468 compile_unit, then use the line header hash table if it's already
11469 created, but don't create one just yet. */
11471 if (dwarf2_per_objfile
->line_header_hash
== NULL
11472 && die
->tag
== DW_TAG_partial_unit
)
11474 dwarf2_per_objfile
->line_header_hash
11475 = htab_create_alloc_ex (127, line_header_hash_voidp
,
11476 line_header_eq_voidp
,
11477 free_line_header_voidp
,
11478 &objfile
->objfile_obstack
,
11479 hashtab_obstack_allocate
,
11480 dummy_obstack_deallocate
);
11483 line_header_local
.sect_off
= line_offset
;
11484 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
11485 line_header_local_hash
= line_header_hash (&line_header_local
);
11486 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
11488 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11489 &line_header_local
,
11490 line_header_local_hash
, NO_INSERT
);
11492 /* For DW_TAG_compile_unit we need info like symtab::linetable which
11493 is not present in *SLOT (since if there is something in *SLOT then
11494 it will be for a partial_unit). */
11495 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
11497 gdb_assert (*slot
!= NULL
);
11498 cu
->line_header
= (struct line_header
*) *slot
;
11503 /* dwarf_decode_line_header does not yet provide sufficient information.
11504 We always have to call also dwarf_decode_lines for it. */
11505 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
11509 cu
->line_header
= lh
.release ();
11510 cu
->line_header_die_owner
= die
;
11512 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
11516 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11517 &line_header_local
,
11518 line_header_local_hash
, INSERT
);
11519 gdb_assert (slot
!= NULL
);
11521 if (slot
!= NULL
&& *slot
== NULL
)
11523 /* This newly decoded line number information unit will be owned
11524 by line_header_hash hash table. */
11525 *slot
= cu
->line_header
;
11526 cu
->line_header_die_owner
= NULL
;
11530 /* We cannot free any current entry in (*slot) as that struct line_header
11531 may be already used by multiple CUs. Create only temporary decoded
11532 line_header for this CU - it may happen at most once for each line
11533 number information unit. And if we're not using line_header_hash
11534 then this is what we want as well. */
11535 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
11537 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
11538 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
11543 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
11546 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11548 struct dwarf2_per_objfile
*dwarf2_per_objfile
11549 = cu
->per_cu
->dwarf2_per_objfile
;
11550 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11551 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11552 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
11553 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
11554 struct attribute
*attr
;
11555 struct die_info
*child_die
;
11556 CORE_ADDR baseaddr
;
11558 prepare_one_comp_unit (cu
, die
, cu
->language
);
11559 baseaddr
= objfile
->text_section_offset ();
11561 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
11563 /* If we didn't find a lowpc, set it to highpc to avoid complaints
11564 from finish_block. */
11565 if (lowpc
== ((CORE_ADDR
) -1))
11567 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11569 file_and_directory fnd
= find_file_and_directory (die
, cu
);
11571 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
11572 standardised yet. As a workaround for the language detection we fall
11573 back to the DW_AT_producer string. */
11574 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
11575 cu
->language
= language_opencl
;
11577 /* Similar hack for Go. */
11578 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
11579 set_cu_language (DW_LANG_Go
, cu
);
11581 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
11583 /* Decode line number information if present. We do this before
11584 processing child DIEs, so that the line header table is available
11585 for DW_AT_decl_file. */
11586 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
11588 /* Process all dies in compilation unit. */
11589 if (die
->child
!= NULL
)
11591 child_die
= die
->child
;
11592 while (child_die
&& child_die
->tag
)
11594 process_die (child_die
, cu
);
11595 child_die
= sibling_die (child_die
);
11599 /* Decode macro information, if present. Dwarf 2 macro information
11600 refers to information in the line number info statement program
11601 header, so we can only read it if we've read the header
11603 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
11605 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
11606 if (attr
&& cu
->line_header
)
11608 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
11609 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
11611 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
11615 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
11616 if (attr
&& cu
->line_header
)
11618 unsigned int macro_offset
= DW_UNSND (attr
);
11620 dwarf_decode_macros (cu
, macro_offset
, 0);
11626 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
11628 struct type_unit_group
*tu_group
;
11630 struct attribute
*attr
;
11632 struct signatured_type
*sig_type
;
11634 gdb_assert (per_cu
->is_debug_types
);
11635 sig_type
= (struct signatured_type
*) per_cu
;
11637 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
11639 /* If we're using .gdb_index (includes -readnow) then
11640 per_cu->type_unit_group may not have been set up yet. */
11641 if (sig_type
->type_unit_group
== NULL
)
11642 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
11643 tu_group
= sig_type
->type_unit_group
;
11645 /* If we've already processed this stmt_list there's no real need to
11646 do it again, we could fake it and just recreate the part we need
11647 (file name,index -> symtab mapping). If data shows this optimization
11648 is useful we can do it then. */
11649 first_time
= tu_group
->compunit_symtab
== NULL
;
11651 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
11656 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11657 lh
= dwarf_decode_line_header (line_offset
, this);
11662 start_symtab ("", NULL
, 0);
11665 gdb_assert (tu_group
->symtabs
== NULL
);
11666 gdb_assert (m_builder
== nullptr);
11667 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
11668 m_builder
.reset (new struct buildsym_compunit
11669 (COMPUNIT_OBJFILE (cust
), "",
11670 COMPUNIT_DIRNAME (cust
),
11671 compunit_language (cust
),
11677 line_header
= lh
.release ();
11678 line_header_die_owner
= die
;
11682 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
11684 /* Note: We don't assign tu_group->compunit_symtab yet because we're
11685 still initializing it, and our caller (a few levels up)
11686 process_full_type_unit still needs to know if this is the first
11689 tu_group
->num_symtabs
= line_header
->file_names_size ();
11690 tu_group
->symtabs
= XNEWVEC (struct symtab
*,
11691 line_header
->file_names_size ());
11693 auto &file_names
= line_header
->file_names ();
11694 for (i
= 0; i
< file_names
.size (); ++i
)
11696 file_entry
&fe
= file_names
[i
];
11697 dwarf2_start_subfile (this, fe
.name
,
11698 fe
.include_dir (line_header
));
11699 buildsym_compunit
*b
= get_builder ();
11700 if (b
->get_current_subfile ()->symtab
== NULL
)
11702 /* NOTE: start_subfile will recognize when it's been
11703 passed a file it has already seen. So we can't
11704 assume there's a simple mapping from
11705 cu->line_header->file_names to subfiles, plus
11706 cu->line_header->file_names may contain dups. */
11707 b
->get_current_subfile ()->symtab
11708 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
11711 fe
.symtab
= b
->get_current_subfile ()->symtab
;
11712 tu_group
->symtabs
[i
] = fe
.symtab
;
11717 gdb_assert (m_builder
== nullptr);
11718 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
11719 m_builder
.reset (new struct buildsym_compunit
11720 (COMPUNIT_OBJFILE (cust
), "",
11721 COMPUNIT_DIRNAME (cust
),
11722 compunit_language (cust
),
11725 auto &file_names
= line_header
->file_names ();
11726 for (i
= 0; i
< file_names
.size (); ++i
)
11728 file_entry
&fe
= file_names
[i
];
11729 fe
.symtab
= tu_group
->symtabs
[i
];
11733 /* The main symtab is allocated last. Type units don't have DW_AT_name
11734 so they don't have a "real" (so to speak) symtab anyway.
11735 There is later code that will assign the main symtab to all symbols
11736 that don't have one. We need to handle the case of a symbol with a
11737 missing symtab (DW_AT_decl_file) anyway. */
11740 /* Process DW_TAG_type_unit.
11741 For TUs we want to skip the first top level sibling if it's not the
11742 actual type being defined by this TU. In this case the first top
11743 level sibling is there to provide context only. */
11746 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11748 struct die_info
*child_die
;
11750 prepare_one_comp_unit (cu
, die
, language_minimal
);
11752 /* Initialize (or reinitialize) the machinery for building symtabs.
11753 We do this before processing child DIEs, so that the line header table
11754 is available for DW_AT_decl_file. */
11755 cu
->setup_type_unit_groups (die
);
11757 if (die
->child
!= NULL
)
11759 child_die
= die
->child
;
11760 while (child_die
&& child_die
->tag
)
11762 process_die (child_die
, cu
);
11763 child_die
= sibling_die (child_die
);
11770 http://gcc.gnu.org/wiki/DebugFission
11771 http://gcc.gnu.org/wiki/DebugFissionDWP
11773 To simplify handling of both DWO files ("object" files with the DWARF info)
11774 and DWP files (a file with the DWOs packaged up into one file), we treat
11775 DWP files as having a collection of virtual DWO files. */
11778 hash_dwo_file (const void *item
)
11780 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11783 hash
= htab_hash_string (dwo_file
->dwo_name
);
11784 if (dwo_file
->comp_dir
!= NULL
)
11785 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11790 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11792 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11793 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11795 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11797 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11798 return lhs
->comp_dir
== rhs
->comp_dir
;
11799 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11802 /* Allocate a hash table for DWO files. */
11805 allocate_dwo_file_hash_table (struct objfile
*objfile
)
11807 auto delete_dwo_file
= [] (void *item
)
11809 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
11814 return htab_up (htab_create_alloc_ex (41,
11818 &objfile
->objfile_obstack
,
11819 hashtab_obstack_allocate
,
11820 dummy_obstack_deallocate
));
11823 /* Lookup DWO file DWO_NAME. */
11826 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11827 const char *dwo_name
,
11828 const char *comp_dir
)
11830 struct dwo_file find_entry
;
11833 if (dwarf2_per_objfile
->dwo_files
== NULL
)
11834 dwarf2_per_objfile
->dwo_files
11835 = allocate_dwo_file_hash_table (dwarf2_per_objfile
->objfile
);
11837 find_entry
.dwo_name
= dwo_name
;
11838 find_entry
.comp_dir
= comp_dir
;
11839 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
.get (), &find_entry
,
11846 hash_dwo_unit (const void *item
)
11848 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11850 /* This drops the top 32 bits of the id, but is ok for a hash. */
11851 return dwo_unit
->signature
;
11855 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11857 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11858 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11860 /* The signature is assumed to be unique within the DWO file.
11861 So while object file CU dwo_id's always have the value zero,
11862 that's OK, assuming each object file DWO file has only one CU,
11863 and that's the rule for now. */
11864 return lhs
->signature
== rhs
->signature
;
11867 /* Allocate a hash table for DWO CUs,TUs.
11868 There is one of these tables for each of CUs,TUs for each DWO file. */
11871 allocate_dwo_unit_table (struct objfile
*objfile
)
11873 /* Start out with a pretty small number.
11874 Generally DWO files contain only one CU and maybe some TUs. */
11875 return htab_create_alloc_ex (3,
11879 &objfile
->objfile_obstack
,
11880 hashtab_obstack_allocate
,
11881 dummy_obstack_deallocate
);
11884 /* die_reader_func for create_dwo_cu. */
11887 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11888 const gdb_byte
*info_ptr
,
11889 struct die_info
*comp_unit_die
,
11891 struct dwo_file
*dwo_file
,
11892 struct dwo_unit
*dwo_unit
)
11894 struct dwarf2_cu
*cu
= reader
->cu
;
11895 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11896 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11898 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11899 if (!signature
.has_value ())
11901 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11902 " its dwo_id [in module %s]"),
11903 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11907 dwo_unit
->dwo_file
= dwo_file
;
11908 dwo_unit
->signature
= *signature
;
11909 dwo_unit
->section
= section
;
11910 dwo_unit
->sect_off
= sect_off
;
11911 dwo_unit
->length
= cu
->per_cu
->length
;
11913 if (dwarf_read_debug
)
11914 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11915 sect_offset_str (sect_off
),
11916 hex_string (dwo_unit
->signature
));
11919 /* Create the dwo_units for the CUs in a DWO_FILE.
11920 Note: This function processes DWO files only, not DWP files. */
11923 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11924 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11925 dwarf2_section_info
§ion
, htab_t
&cus_htab
)
11927 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11928 const gdb_byte
*info_ptr
, *end_ptr
;
11930 dwarf2_read_section (objfile
, §ion
);
11931 info_ptr
= section
.buffer
;
11933 if (info_ptr
== NULL
)
11936 if (dwarf_read_debug
)
11938 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11939 get_section_name (§ion
),
11940 get_section_file_name (§ion
));
11943 end_ptr
= info_ptr
+ section
.size
;
11944 while (info_ptr
< end_ptr
)
11946 struct dwarf2_per_cu_data per_cu
;
11947 struct dwo_unit read_unit
{};
11948 struct dwo_unit
*dwo_unit
;
11950 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11952 memset (&per_cu
, 0, sizeof (per_cu
));
11953 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
11954 per_cu
.is_debug_types
= 0;
11955 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11956 per_cu
.section
= §ion
;
11958 cutu_reader
reader (&per_cu
, cu
, &dwo_file
);
11959 if (!reader
.dummy_p
)
11960 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11961 reader
.has_children
, &dwo_file
, &read_unit
);
11962 info_ptr
+= per_cu
.length
;
11964 // If the unit could not be parsed, skip it.
11965 if (read_unit
.dwo_file
== NULL
)
11968 if (cus_htab
== NULL
)
11969 cus_htab
= allocate_dwo_unit_table (objfile
);
11971 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11972 *dwo_unit
= read_unit
;
11973 slot
= htab_find_slot (cus_htab
, dwo_unit
, INSERT
);
11974 gdb_assert (slot
!= NULL
);
11977 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11978 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11980 complaint (_("debug cu entry at offset %s is duplicate to"
11981 " the entry at offset %s, signature %s"),
11982 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11983 hex_string (dwo_unit
->signature
));
11985 *slot
= (void *)dwo_unit
;
11989 /* DWP file .debug_{cu,tu}_index section format:
11990 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11994 Both index sections have the same format, and serve to map a 64-bit
11995 signature to a set of section numbers. Each section begins with a header,
11996 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11997 indexes, and a pool of 32-bit section numbers. The index sections will be
11998 aligned at 8-byte boundaries in the file.
12000 The index section header consists of:
12002 V, 32 bit version number
12004 N, 32 bit number of compilation units or type units in the index
12005 M, 32 bit number of slots in the hash table
12007 Numbers are recorded using the byte order of the application binary.
12009 The hash table begins at offset 16 in the section, and consists of an array
12010 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
12011 order of the application binary). Unused slots in the hash table are 0.
12012 (We rely on the extreme unlikeliness of a signature being exactly 0.)
12014 The parallel table begins immediately after the hash table
12015 (at offset 16 + 8 * M from the beginning of the section), and consists of an
12016 array of 32-bit indexes (using the byte order of the application binary),
12017 corresponding 1-1 with slots in the hash table. Each entry in the parallel
12018 table contains a 32-bit index into the pool of section numbers. For unused
12019 hash table slots, the corresponding entry in the parallel table will be 0.
12021 The pool of section numbers begins immediately following the hash table
12022 (at offset 16 + 12 * M from the beginning of the section). The pool of
12023 section numbers consists of an array of 32-bit words (using the byte order
12024 of the application binary). Each item in the array is indexed starting
12025 from 0. The hash table entry provides the index of the first section
12026 number in the set. Additional section numbers in the set follow, and the
12027 set is terminated by a 0 entry (section number 0 is not used in ELF).
12029 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
12030 section must be the first entry in the set, and the .debug_abbrev.dwo must
12031 be the second entry. Other members of the set may follow in any order.
12037 DWP Version 2 combines all the .debug_info, etc. sections into one,
12038 and the entries in the index tables are now offsets into these sections.
12039 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
12042 Index Section Contents:
12044 Hash Table of Signatures dwp_hash_table.hash_table
12045 Parallel Table of Indices dwp_hash_table.unit_table
12046 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
12047 Table of Section Sizes dwp_hash_table.v2.sizes
12049 The index section header consists of:
12051 V, 32 bit version number
12052 L, 32 bit number of columns in the table of section offsets
12053 N, 32 bit number of compilation units or type units in the index
12054 M, 32 bit number of slots in the hash table
12056 Numbers are recorded using the byte order of the application binary.
12058 The hash table has the same format as version 1.
12059 The parallel table of indices has the same format as version 1,
12060 except that the entries are origin-1 indices into the table of sections
12061 offsets and the table of section sizes.
12063 The table of offsets begins immediately following the parallel table
12064 (at offset 16 + 12 * M from the beginning of the section). The table is
12065 a two-dimensional array of 32-bit words (using the byte order of the
12066 application binary), with L columns and N+1 rows, in row-major order.
12067 Each row in the array is indexed starting from 0. The first row provides
12068 a key to the remaining rows: each column in this row provides an identifier
12069 for a debug section, and the offsets in the same column of subsequent rows
12070 refer to that section. The section identifiers are:
12072 DW_SECT_INFO 1 .debug_info.dwo
12073 DW_SECT_TYPES 2 .debug_types.dwo
12074 DW_SECT_ABBREV 3 .debug_abbrev.dwo
12075 DW_SECT_LINE 4 .debug_line.dwo
12076 DW_SECT_LOC 5 .debug_loc.dwo
12077 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
12078 DW_SECT_MACINFO 7 .debug_macinfo.dwo
12079 DW_SECT_MACRO 8 .debug_macro.dwo
12081 The offsets provided by the CU and TU index sections are the base offsets
12082 for the contributions made by each CU or TU to the corresponding section
12083 in the package file. Each CU and TU header contains an abbrev_offset
12084 field, used to find the abbreviations table for that CU or TU within the
12085 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
12086 be interpreted as relative to the base offset given in the index section.
12087 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
12088 should be interpreted as relative to the base offset for .debug_line.dwo,
12089 and offsets into other debug sections obtained from DWARF attributes should
12090 also be interpreted as relative to the corresponding base offset.
12092 The table of sizes begins immediately following the table of offsets.
12093 Like the table of offsets, it is a two-dimensional array of 32-bit words,
12094 with L columns and N rows, in row-major order. Each row in the array is
12095 indexed starting from 1 (row 0 is shared by the two tables).
12099 Hash table lookup is handled the same in version 1 and 2:
12101 We assume that N and M will not exceed 2^32 - 1.
12102 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
12104 Given a 64-bit compilation unit signature or a type signature S, an entry
12105 in the hash table is located as follows:
12107 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
12108 the low-order k bits all set to 1.
12110 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
12112 3) If the hash table entry at index H matches the signature, use that
12113 entry. If the hash table entry at index H is unused (all zeroes),
12114 terminate the search: the signature is not present in the table.
12116 4) Let H = (H + H') modulo M. Repeat at Step 3.
12118 Because M > N and H' and M are relatively prime, the search is guaranteed
12119 to stop at an unused slot or find the match. */
12121 /* Create a hash table to map DWO IDs to their CU/TU entry in
12122 .debug_{info,types}.dwo in DWP_FILE.
12123 Returns NULL if there isn't one.
12124 Note: This function processes DWP files only, not DWO files. */
12126 static struct dwp_hash_table
*
12127 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12128 struct dwp_file
*dwp_file
, int is_debug_types
)
12130 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12131 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12132 const gdb_byte
*index_ptr
, *index_end
;
12133 struct dwarf2_section_info
*index
;
12134 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
12135 struct dwp_hash_table
*htab
;
12137 if (is_debug_types
)
12138 index
= &dwp_file
->sections
.tu_index
;
12140 index
= &dwp_file
->sections
.cu_index
;
12142 if (dwarf2_section_empty_p (index
))
12144 dwarf2_read_section (objfile
, index
);
12146 index_ptr
= index
->buffer
;
12147 index_end
= index_ptr
+ index
->size
;
12149 version
= read_4_bytes (dbfd
, index_ptr
);
12152 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
12156 nr_units
= read_4_bytes (dbfd
, index_ptr
);
12158 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
12161 if (version
!= 1 && version
!= 2)
12163 error (_("Dwarf Error: unsupported DWP file version (%s)"
12164 " [in module %s]"),
12165 pulongest (version
), dwp_file
->name
);
12167 if (nr_slots
!= (nr_slots
& -nr_slots
))
12169 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
12170 " is not power of 2 [in module %s]"),
12171 pulongest (nr_slots
), dwp_file
->name
);
12174 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
12175 htab
->version
= version
;
12176 htab
->nr_columns
= nr_columns
;
12177 htab
->nr_units
= nr_units
;
12178 htab
->nr_slots
= nr_slots
;
12179 htab
->hash_table
= index_ptr
;
12180 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
12182 /* Exit early if the table is empty. */
12183 if (nr_slots
== 0 || nr_units
== 0
12184 || (version
== 2 && nr_columns
== 0))
12186 /* All must be zero. */
12187 if (nr_slots
!= 0 || nr_units
!= 0
12188 || (version
== 2 && nr_columns
!= 0))
12190 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
12191 " all zero [in modules %s]"),
12199 htab
->section_pool
.v1
.indices
=
12200 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12201 /* It's harder to decide whether the section is too small in v1.
12202 V1 is deprecated anyway so we punt. */
12206 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12207 int *ids
= htab
->section_pool
.v2
.section_ids
;
12208 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
12209 /* Reverse map for error checking. */
12210 int ids_seen
[DW_SECT_MAX
+ 1];
12213 if (nr_columns
< 2)
12215 error (_("Dwarf Error: bad DWP hash table, too few columns"
12216 " in section table [in module %s]"),
12219 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
12221 error (_("Dwarf Error: bad DWP hash table, too many columns"
12222 " in section table [in module %s]"),
12225 memset (ids
, 255, sizeof_ids
);
12226 memset (ids_seen
, 255, sizeof (ids_seen
));
12227 for (i
= 0; i
< nr_columns
; ++i
)
12229 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
12231 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
12233 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
12234 " in section table [in module %s]"),
12235 id
, dwp_file
->name
);
12237 if (ids_seen
[id
] != -1)
12239 error (_("Dwarf Error: bad DWP hash table, duplicate section"
12240 " id %d in section table [in module %s]"),
12241 id
, dwp_file
->name
);
12246 /* Must have exactly one info or types section. */
12247 if (((ids_seen
[DW_SECT_INFO
] != -1)
12248 + (ids_seen
[DW_SECT_TYPES
] != -1))
12251 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
12252 " DWO info/types section [in module %s]"),
12255 /* Must have an abbrev section. */
12256 if (ids_seen
[DW_SECT_ABBREV
] == -1)
12258 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
12259 " section [in module %s]"),
12262 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
12263 htab
->section_pool
.v2
.sizes
=
12264 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
12265 * nr_units
* nr_columns
);
12266 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
12267 * nr_units
* nr_columns
))
12270 error (_("Dwarf Error: DWP index section is corrupt (too small)"
12271 " [in module %s]"),
12279 /* Update SECTIONS with the data from SECTP.
12281 This function is like the other "locate" section routines that are
12282 passed to bfd_map_over_sections, but in this context the sections to
12283 read comes from the DWP V1 hash table, not the full ELF section table.
12285 The result is non-zero for success, or zero if an error was found. */
12288 locate_v1_virtual_dwo_sections (asection
*sectp
,
12289 struct virtual_v1_dwo_sections
*sections
)
12291 const struct dwop_section_names
*names
= &dwop_section_names
;
12293 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12295 /* There can be only one. */
12296 if (sections
->abbrev
.s
.section
!= NULL
)
12298 sections
->abbrev
.s
.section
= sectp
;
12299 sections
->abbrev
.size
= bfd_section_size (sectp
);
12301 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
12302 || section_is_p (sectp
->name
, &names
->types_dwo
))
12304 /* There can be only one. */
12305 if (sections
->info_or_types
.s
.section
!= NULL
)
12307 sections
->info_or_types
.s
.section
= sectp
;
12308 sections
->info_or_types
.size
= bfd_section_size (sectp
);
12310 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12312 /* There can be only one. */
12313 if (sections
->line
.s
.section
!= NULL
)
12315 sections
->line
.s
.section
= sectp
;
12316 sections
->line
.size
= bfd_section_size (sectp
);
12318 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12320 /* There can be only one. */
12321 if (sections
->loc
.s
.section
!= NULL
)
12323 sections
->loc
.s
.section
= sectp
;
12324 sections
->loc
.size
= bfd_section_size (sectp
);
12326 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12328 /* There can be only one. */
12329 if (sections
->macinfo
.s
.section
!= NULL
)
12331 sections
->macinfo
.s
.section
= sectp
;
12332 sections
->macinfo
.size
= bfd_section_size (sectp
);
12334 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12336 /* There can be only one. */
12337 if (sections
->macro
.s
.section
!= NULL
)
12339 sections
->macro
.s
.section
= sectp
;
12340 sections
->macro
.size
= bfd_section_size (sectp
);
12342 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12344 /* There can be only one. */
12345 if (sections
->str_offsets
.s
.section
!= NULL
)
12347 sections
->str_offsets
.s
.section
= sectp
;
12348 sections
->str_offsets
.size
= bfd_section_size (sectp
);
12352 /* No other kind of section is valid. */
12359 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12360 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12361 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12362 This is for DWP version 1 files. */
12364 static struct dwo_unit
*
12365 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12366 struct dwp_file
*dwp_file
,
12367 uint32_t unit_index
,
12368 const char *comp_dir
,
12369 ULONGEST signature
, int is_debug_types
)
12371 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12372 const struct dwp_hash_table
*dwp_htab
=
12373 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12374 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12375 const char *kind
= is_debug_types
? "TU" : "CU";
12376 struct dwo_file
*dwo_file
;
12377 struct dwo_unit
*dwo_unit
;
12378 struct virtual_v1_dwo_sections sections
;
12379 void **dwo_file_slot
;
12382 gdb_assert (dwp_file
->version
== 1);
12384 if (dwarf_read_debug
)
12386 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
12388 pulongest (unit_index
), hex_string (signature
),
12392 /* Fetch the sections of this DWO unit.
12393 Put a limit on the number of sections we look for so that bad data
12394 doesn't cause us to loop forever. */
12396 #define MAX_NR_V1_DWO_SECTIONS \
12397 (1 /* .debug_info or .debug_types */ \
12398 + 1 /* .debug_abbrev */ \
12399 + 1 /* .debug_line */ \
12400 + 1 /* .debug_loc */ \
12401 + 1 /* .debug_str_offsets */ \
12402 + 1 /* .debug_macro or .debug_macinfo */ \
12403 + 1 /* trailing zero */)
12405 memset (§ions
, 0, sizeof (sections
));
12407 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
12410 uint32_t section_nr
=
12411 read_4_bytes (dbfd
,
12412 dwp_htab
->section_pool
.v1
.indices
12413 + (unit_index
+ i
) * sizeof (uint32_t));
12415 if (section_nr
== 0)
12417 if (section_nr
>= dwp_file
->num_sections
)
12419 error (_("Dwarf Error: bad DWP hash table, section number too large"
12420 " [in module %s]"),
12424 sectp
= dwp_file
->elf_sections
[section_nr
];
12425 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
12427 error (_("Dwarf Error: bad DWP hash table, invalid section found"
12428 " [in module %s]"),
12434 || dwarf2_section_empty_p (§ions
.info_or_types
)
12435 || dwarf2_section_empty_p (§ions
.abbrev
))
12437 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
12438 " [in module %s]"),
12441 if (i
== MAX_NR_V1_DWO_SECTIONS
)
12443 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
12444 " [in module %s]"),
12448 /* It's easier for the rest of the code if we fake a struct dwo_file and
12449 have dwo_unit "live" in that. At least for now.
12451 The DWP file can be made up of a random collection of CUs and TUs.
12452 However, for each CU + set of TUs that came from the same original DWO
12453 file, we can combine them back into a virtual DWO file to save space
12454 (fewer struct dwo_file objects to allocate). Remember that for really
12455 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12457 std::string virtual_dwo_name
=
12458 string_printf ("virtual-dwo/%d-%d-%d-%d",
12459 get_section_id (§ions
.abbrev
),
12460 get_section_id (§ions
.line
),
12461 get_section_id (§ions
.loc
),
12462 get_section_id (§ions
.str_offsets
));
12463 /* Can we use an existing virtual DWO file? */
12464 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12465 virtual_dwo_name
.c_str (),
12467 /* Create one if necessary. */
12468 if (*dwo_file_slot
== NULL
)
12470 if (dwarf_read_debug
)
12472 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12473 virtual_dwo_name
.c_str ());
12475 dwo_file
= new struct dwo_file
;
12476 dwo_file
->dwo_name
= obstack_strdup (&objfile
->objfile_obstack
,
12478 dwo_file
->comp_dir
= comp_dir
;
12479 dwo_file
->sections
.abbrev
= sections
.abbrev
;
12480 dwo_file
->sections
.line
= sections
.line
;
12481 dwo_file
->sections
.loc
= sections
.loc
;
12482 dwo_file
->sections
.macinfo
= sections
.macinfo
;
12483 dwo_file
->sections
.macro
= sections
.macro
;
12484 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
12485 /* The "str" section is global to the entire DWP file. */
12486 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12487 /* The info or types section is assigned below to dwo_unit,
12488 there's no need to record it in dwo_file.
12489 Also, we can't simply record type sections in dwo_file because
12490 we record a pointer into the vector in dwo_unit. As we collect more
12491 types we'll grow the vector and eventually have to reallocate space
12492 for it, invalidating all copies of pointers into the previous
12494 *dwo_file_slot
= dwo_file
;
12498 if (dwarf_read_debug
)
12500 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12501 virtual_dwo_name
.c_str ());
12503 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12506 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12507 dwo_unit
->dwo_file
= dwo_file
;
12508 dwo_unit
->signature
= signature
;
12509 dwo_unit
->section
=
12510 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12511 *dwo_unit
->section
= sections
.info_or_types
;
12512 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12517 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
12518 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
12519 piece within that section used by a TU/CU, return a virtual section
12520 of just that piece. */
12522 static struct dwarf2_section_info
12523 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12524 struct dwarf2_section_info
*section
,
12525 bfd_size_type offset
, bfd_size_type size
)
12527 struct dwarf2_section_info result
;
12530 gdb_assert (section
!= NULL
);
12531 gdb_assert (!section
->is_virtual
);
12533 memset (&result
, 0, sizeof (result
));
12534 result
.s
.containing_section
= section
;
12535 result
.is_virtual
= true;
12540 sectp
= get_section_bfd_section (section
);
12542 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
12543 bounds of the real section. This is a pretty-rare event, so just
12544 flag an error (easier) instead of a warning and trying to cope. */
12546 || offset
+ size
> bfd_section_size (sectp
))
12548 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
12549 " in section %s [in module %s]"),
12550 sectp
? bfd_section_name (sectp
) : "<unknown>",
12551 objfile_name (dwarf2_per_objfile
->objfile
));
12554 result
.virtual_offset
= offset
;
12555 result
.size
= size
;
12559 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12560 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12561 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12562 This is for DWP version 2 files. */
12564 static struct dwo_unit
*
12565 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12566 struct dwp_file
*dwp_file
,
12567 uint32_t unit_index
,
12568 const char *comp_dir
,
12569 ULONGEST signature
, int is_debug_types
)
12571 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12572 const struct dwp_hash_table
*dwp_htab
=
12573 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12574 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12575 const char *kind
= is_debug_types
? "TU" : "CU";
12576 struct dwo_file
*dwo_file
;
12577 struct dwo_unit
*dwo_unit
;
12578 struct virtual_v2_dwo_sections sections
;
12579 void **dwo_file_slot
;
12582 gdb_assert (dwp_file
->version
== 2);
12584 if (dwarf_read_debug
)
12586 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
12588 pulongest (unit_index
), hex_string (signature
),
12592 /* Fetch the section offsets of this DWO unit. */
12594 memset (§ions
, 0, sizeof (sections
));
12596 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12598 uint32_t offset
= read_4_bytes (dbfd
,
12599 dwp_htab
->section_pool
.v2
.offsets
12600 + (((unit_index
- 1) * dwp_htab
->nr_columns
12602 * sizeof (uint32_t)));
12603 uint32_t size
= read_4_bytes (dbfd
,
12604 dwp_htab
->section_pool
.v2
.sizes
12605 + (((unit_index
- 1) * dwp_htab
->nr_columns
12607 * sizeof (uint32_t)));
12609 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
12612 case DW_SECT_TYPES
:
12613 sections
.info_or_types_offset
= offset
;
12614 sections
.info_or_types_size
= size
;
12616 case DW_SECT_ABBREV
:
12617 sections
.abbrev_offset
= offset
;
12618 sections
.abbrev_size
= size
;
12621 sections
.line_offset
= offset
;
12622 sections
.line_size
= size
;
12625 sections
.loc_offset
= offset
;
12626 sections
.loc_size
= size
;
12628 case DW_SECT_STR_OFFSETS
:
12629 sections
.str_offsets_offset
= offset
;
12630 sections
.str_offsets_size
= size
;
12632 case DW_SECT_MACINFO
:
12633 sections
.macinfo_offset
= offset
;
12634 sections
.macinfo_size
= size
;
12636 case DW_SECT_MACRO
:
12637 sections
.macro_offset
= offset
;
12638 sections
.macro_size
= size
;
12643 /* It's easier for the rest of the code if we fake a struct dwo_file and
12644 have dwo_unit "live" in that. At least for now.
12646 The DWP file can be made up of a random collection of CUs and TUs.
12647 However, for each CU + set of TUs that came from the same original DWO
12648 file, we can combine them back into a virtual DWO file to save space
12649 (fewer struct dwo_file objects to allocate). Remember that for really
12650 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12652 std::string virtual_dwo_name
=
12653 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
12654 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12655 (long) (sections
.line_size
? sections
.line_offset
: 0),
12656 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
12657 (long) (sections
.str_offsets_size
12658 ? sections
.str_offsets_offset
: 0));
12659 /* Can we use an existing virtual DWO file? */
12660 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12661 virtual_dwo_name
.c_str (),
12663 /* Create one if necessary. */
12664 if (*dwo_file_slot
== NULL
)
12666 if (dwarf_read_debug
)
12668 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12669 virtual_dwo_name
.c_str ());
12671 dwo_file
= new struct dwo_file
;
12672 dwo_file
->dwo_name
= obstack_strdup (&objfile
->objfile_obstack
,
12674 dwo_file
->comp_dir
= comp_dir
;
12675 dwo_file
->sections
.abbrev
=
12676 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
12677 sections
.abbrev_offset
, sections
.abbrev_size
);
12678 dwo_file
->sections
.line
=
12679 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
12680 sections
.line_offset
, sections
.line_size
);
12681 dwo_file
->sections
.loc
=
12682 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
12683 sections
.loc_offset
, sections
.loc_size
);
12684 dwo_file
->sections
.macinfo
=
12685 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
12686 sections
.macinfo_offset
, sections
.macinfo_size
);
12687 dwo_file
->sections
.macro
=
12688 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
12689 sections
.macro_offset
, sections
.macro_size
);
12690 dwo_file
->sections
.str_offsets
=
12691 create_dwp_v2_section (dwarf2_per_objfile
,
12692 &dwp_file
->sections
.str_offsets
,
12693 sections
.str_offsets_offset
,
12694 sections
.str_offsets_size
);
12695 /* The "str" section is global to the entire DWP file. */
12696 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12697 /* The info or types section is assigned below to dwo_unit,
12698 there's no need to record it in dwo_file.
12699 Also, we can't simply record type sections in dwo_file because
12700 we record a pointer into the vector in dwo_unit. As we collect more
12701 types we'll grow the vector and eventually have to reallocate space
12702 for it, invalidating all copies of pointers into the previous
12704 *dwo_file_slot
= dwo_file
;
12708 if (dwarf_read_debug
)
12710 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12711 virtual_dwo_name
.c_str ());
12713 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12716 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12717 dwo_unit
->dwo_file
= dwo_file
;
12718 dwo_unit
->signature
= signature
;
12719 dwo_unit
->section
=
12720 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12721 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
12723 ? &dwp_file
->sections
.types
12724 : &dwp_file
->sections
.info
,
12725 sections
.info_or_types_offset
,
12726 sections
.info_or_types_size
);
12727 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12732 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12733 Returns NULL if the signature isn't found. */
12735 static struct dwo_unit
*
12736 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12737 struct dwp_file
*dwp_file
, const char *comp_dir
,
12738 ULONGEST signature
, int is_debug_types
)
12740 const struct dwp_hash_table
*dwp_htab
=
12741 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12742 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12743 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12744 uint32_t hash
= signature
& mask
;
12745 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12748 struct dwo_unit find_dwo_cu
;
12750 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12751 find_dwo_cu
.signature
= signature
;
12752 slot
= htab_find_slot (is_debug_types
12753 ? dwp_file
->loaded_tus
12754 : dwp_file
->loaded_cus
,
12755 &find_dwo_cu
, INSERT
);
12758 return (struct dwo_unit
*) *slot
;
12760 /* Use a for loop so that we don't loop forever on bad debug info. */
12761 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12763 ULONGEST signature_in_table
;
12765 signature_in_table
=
12766 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12767 if (signature_in_table
== signature
)
12769 uint32_t unit_index
=
12770 read_4_bytes (dbfd
,
12771 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12773 if (dwp_file
->version
== 1)
12775 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
12776 dwp_file
, unit_index
,
12777 comp_dir
, signature
,
12782 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
12783 dwp_file
, unit_index
,
12784 comp_dir
, signature
,
12787 return (struct dwo_unit
*) *slot
;
12789 if (signature_in_table
== 0)
12791 hash
= (hash
+ hash2
) & mask
;
12794 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12795 " [in module %s]"),
12799 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12800 Open the file specified by FILE_NAME and hand it off to BFD for
12801 preliminary analysis. Return a newly initialized bfd *, which
12802 includes a canonicalized copy of FILE_NAME.
12803 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12804 SEARCH_CWD is true if the current directory is to be searched.
12805 It will be searched before debug-file-directory.
12806 If successful, the file is added to the bfd include table of the
12807 objfile's bfd (see gdb_bfd_record_inclusion).
12808 If unable to find/open the file, return NULL.
12809 NOTE: This function is derived from symfile_bfd_open. */
12811 static gdb_bfd_ref_ptr
12812 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12813 const char *file_name
, int is_dwp
, int search_cwd
)
12816 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12817 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12818 to debug_file_directory. */
12819 const char *search_path
;
12820 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12822 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12825 if (*debug_file_directory
!= '\0')
12827 search_path_holder
.reset (concat (".", dirname_separator_string
,
12828 debug_file_directory
,
12830 search_path
= search_path_holder
.get ();
12836 search_path
= debug_file_directory
;
12838 openp_flags flags
= OPF_RETURN_REALPATH
;
12840 flags
|= OPF_SEARCH_IN_PATH
;
12842 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12843 desc
= openp (search_path
, flags
, file_name
,
12844 O_RDONLY
| O_BINARY
, &absolute_name
);
12848 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12850 if (sym_bfd
== NULL
)
12852 bfd_set_cacheable (sym_bfd
.get (), 1);
12854 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12857 /* Success. Record the bfd as having been included by the objfile's bfd.
12858 This is important because things like demangled_names_hash lives in the
12859 objfile's per_bfd space and may have references to things like symbol
12860 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12861 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12866 /* Try to open DWO file FILE_NAME.
12867 COMP_DIR is the DW_AT_comp_dir attribute.
12868 The result is the bfd handle of the file.
12869 If there is a problem finding or opening the file, return NULL.
12870 Upon success, the canonicalized path of the file is stored in the bfd,
12871 same as symfile_bfd_open. */
12873 static gdb_bfd_ref_ptr
12874 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12875 const char *file_name
, const char *comp_dir
)
12877 if (IS_ABSOLUTE_PATH (file_name
))
12878 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12879 0 /*is_dwp*/, 0 /*search_cwd*/);
12881 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12883 if (comp_dir
!= NULL
)
12885 gdb::unique_xmalloc_ptr
<char> path_to_try
12886 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12888 /* NOTE: If comp_dir is a relative path, this will also try the
12889 search path, which seems useful. */
12890 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
12891 path_to_try
.get (),
12893 1 /*search_cwd*/));
12898 /* That didn't work, try debug-file-directory, which, despite its name,
12899 is a list of paths. */
12901 if (*debug_file_directory
== '\0')
12904 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12905 0 /*is_dwp*/, 1 /*search_cwd*/);
12908 /* This function is mapped across the sections and remembers the offset and
12909 size of each of the DWO debugging sections we are interested in. */
12912 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12914 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12915 const struct dwop_section_names
*names
= &dwop_section_names
;
12917 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12919 dwo_sections
->abbrev
.s
.section
= sectp
;
12920 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12922 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12924 dwo_sections
->info
.s
.section
= sectp
;
12925 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12927 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12929 dwo_sections
->line
.s
.section
= sectp
;
12930 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12932 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12934 dwo_sections
->loc
.s
.section
= sectp
;
12935 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12937 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12939 dwo_sections
->macinfo
.s
.section
= sectp
;
12940 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12942 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12944 dwo_sections
->macro
.s
.section
= sectp
;
12945 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12947 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12949 dwo_sections
->str
.s
.section
= sectp
;
12950 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12952 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12954 dwo_sections
->str_offsets
.s
.section
= sectp
;
12955 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12957 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12959 struct dwarf2_section_info type_section
;
12961 memset (&type_section
, 0, sizeof (type_section
));
12962 type_section
.s
.section
= sectp
;
12963 type_section
.size
= bfd_section_size (sectp
);
12964 dwo_sections
->types
.push_back (type_section
);
12968 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12969 by PER_CU. This is for the non-DWP case.
12970 The result is NULL if DWO_NAME can't be found. */
12972 static struct dwo_file
*
12973 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
12974 const char *dwo_name
, const char *comp_dir
)
12976 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
12978 gdb_bfd_ref_ptr dbfd
= open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
);
12981 if (dwarf_read_debug
)
12982 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
12986 dwo_file_up
dwo_file (new struct dwo_file
);
12987 dwo_file
->dwo_name
= dwo_name
;
12988 dwo_file
->comp_dir
= comp_dir
;
12989 dwo_file
->dbfd
= std::move (dbfd
);
12991 bfd_map_over_sections (dwo_file
->dbfd
.get (), dwarf2_locate_dwo_sections
,
12992 &dwo_file
->sections
);
12994 create_cus_hash_table (dwarf2_per_objfile
, per_cu
->cu
, *dwo_file
,
12995 dwo_file
->sections
.info
, dwo_file
->cus
);
12997 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
.get (),
12998 dwo_file
->sections
.types
, dwo_file
->tus
);
13000 if (dwarf_read_debug
)
13001 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
13003 return dwo_file
.release ();
13006 /* This function is mapped across the sections and remembers the offset and
13007 size of each of the DWP debugging sections common to version 1 and 2 that
13008 we are interested in. */
13011 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
13012 void *dwp_file_ptr
)
13014 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
13015 const struct dwop_section_names
*names
= &dwop_section_names
;
13016 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
13018 /* Record the ELF section number for later lookup: this is what the
13019 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
13020 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
13021 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
13023 /* Look for specific sections that we need. */
13024 if (section_is_p (sectp
->name
, &names
->str_dwo
))
13026 dwp_file
->sections
.str
.s
.section
= sectp
;
13027 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
13029 else if (section_is_p (sectp
->name
, &names
->cu_index
))
13031 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
13032 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
13034 else if (section_is_p (sectp
->name
, &names
->tu_index
))
13036 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
13037 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
13041 /* This function is mapped across the sections and remembers the offset and
13042 size of each of the DWP version 2 debugging sections that we are interested
13043 in. This is split into a separate function because we don't know if we
13044 have version 1 or 2 until we parse the cu_index/tu_index sections. */
13047 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
13049 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
13050 const struct dwop_section_names
*names
= &dwop_section_names
;
13051 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
13053 /* Record the ELF section number for later lookup: this is what the
13054 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
13055 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
13056 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
13058 /* Look for specific sections that we need. */
13059 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
13061 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
13062 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
13064 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
13066 dwp_file
->sections
.info
.s
.section
= sectp
;
13067 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
13069 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
13071 dwp_file
->sections
.line
.s
.section
= sectp
;
13072 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
13074 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
13076 dwp_file
->sections
.loc
.s
.section
= sectp
;
13077 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
13079 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
13081 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
13082 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
13084 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
13086 dwp_file
->sections
.macro
.s
.section
= sectp
;
13087 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
13089 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
13091 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
13092 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
13094 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
13096 dwp_file
->sections
.types
.s
.section
= sectp
;
13097 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
13101 /* Hash function for dwp_file loaded CUs/TUs. */
13104 hash_dwp_loaded_cutus (const void *item
)
13106 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
13108 /* This drops the top 32 bits of the signature, but is ok for a hash. */
13109 return dwo_unit
->signature
;
13112 /* Equality function for dwp_file loaded CUs/TUs. */
13115 eq_dwp_loaded_cutus (const void *a
, const void *b
)
13117 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
13118 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
13120 return dua
->signature
== dub
->signature
;
13123 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
13126 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
13128 return htab_create_alloc_ex (3,
13129 hash_dwp_loaded_cutus
,
13130 eq_dwp_loaded_cutus
,
13132 &objfile
->objfile_obstack
,
13133 hashtab_obstack_allocate
,
13134 dummy_obstack_deallocate
);
13137 /* Try to open DWP file FILE_NAME.
13138 The result is the bfd handle of the file.
13139 If there is a problem finding or opening the file, return NULL.
13140 Upon success, the canonicalized path of the file is stored in the bfd,
13141 same as symfile_bfd_open. */
13143 static gdb_bfd_ref_ptr
13144 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
13145 const char *file_name
)
13147 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
13149 1 /*search_cwd*/));
13153 /* Work around upstream bug 15652.
13154 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
13155 [Whether that's a "bug" is debatable, but it is getting in our way.]
13156 We have no real idea where the dwp file is, because gdb's realpath-ing
13157 of the executable's path may have discarded the needed info.
13158 [IWBN if the dwp file name was recorded in the executable, akin to
13159 .gnu_debuglink, but that doesn't exist yet.]
13160 Strip the directory from FILE_NAME and search again. */
13161 if (*debug_file_directory
!= '\0')
13163 /* Don't implicitly search the current directory here.
13164 If the user wants to search "." to handle this case,
13165 it must be added to debug-file-directory. */
13166 return try_open_dwop_file (dwarf2_per_objfile
,
13167 lbasename (file_name
), 1 /*is_dwp*/,
13174 /* Initialize the use of the DWP file for the current objfile.
13175 By convention the name of the DWP file is ${objfile}.dwp.
13176 The result is NULL if it can't be found. */
13178 static std::unique_ptr
<struct dwp_file
>
13179 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
13181 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13183 /* Try to find first .dwp for the binary file before any symbolic links
13186 /* If the objfile is a debug file, find the name of the real binary
13187 file and get the name of dwp file from there. */
13188 std::string dwp_name
;
13189 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
13191 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
13192 const char *backlink_basename
= lbasename (backlink
->original_name
);
13194 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
13197 dwp_name
= objfile
->original_name
;
13199 dwp_name
+= ".dwp";
13201 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
13203 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
13205 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
13206 dwp_name
= objfile_name (objfile
);
13207 dwp_name
+= ".dwp";
13208 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
13213 if (dwarf_read_debug
)
13214 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
13215 return std::unique_ptr
<dwp_file
> ();
13218 const char *name
= bfd_get_filename (dbfd
.get ());
13219 std::unique_ptr
<struct dwp_file
> dwp_file
13220 (new struct dwp_file (name
, std::move (dbfd
)));
13222 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
13223 dwp_file
->elf_sections
=
13224 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
13225 dwp_file
->num_sections
, asection
*);
13227 bfd_map_over_sections (dwp_file
->dbfd
.get (),
13228 dwarf2_locate_common_dwp_sections
,
13231 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
13234 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
13237 /* The DWP file version is stored in the hash table. Oh well. */
13238 if (dwp_file
->cus
&& dwp_file
->tus
13239 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
13241 /* Technically speaking, we should try to limp along, but this is
13242 pretty bizarre. We use pulongest here because that's the established
13243 portability solution (e.g, we cannot use %u for uint32_t). */
13244 error (_("Dwarf Error: DWP file CU version %s doesn't match"
13245 " TU version %s [in DWP file %s]"),
13246 pulongest (dwp_file
->cus
->version
),
13247 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
13251 dwp_file
->version
= dwp_file
->cus
->version
;
13252 else if (dwp_file
->tus
)
13253 dwp_file
->version
= dwp_file
->tus
->version
;
13255 dwp_file
->version
= 2;
13257 if (dwp_file
->version
== 2)
13258 bfd_map_over_sections (dwp_file
->dbfd
.get (),
13259 dwarf2_locate_v2_dwp_sections
,
13262 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table (objfile
);
13263 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table (objfile
);
13265 if (dwarf_read_debug
)
13267 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
13268 fprintf_unfiltered (gdb_stdlog
,
13269 " %s CUs, %s TUs\n",
13270 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
13271 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
13277 /* Wrapper around open_and_init_dwp_file, only open it once. */
13279 static struct dwp_file
*
13280 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
13282 if (! dwarf2_per_objfile
->dwp_checked
)
13284 dwarf2_per_objfile
->dwp_file
13285 = open_and_init_dwp_file (dwarf2_per_objfile
);
13286 dwarf2_per_objfile
->dwp_checked
= 1;
13288 return dwarf2_per_objfile
->dwp_file
.get ();
13291 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
13292 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
13293 or in the DWP file for the objfile, referenced by THIS_UNIT.
13294 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
13295 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
13297 This is called, for example, when wanting to read a variable with a
13298 complex location. Therefore we don't want to do file i/o for every call.
13299 Therefore we don't want to look for a DWO file on every call.
13300 Therefore we first see if we've already seen SIGNATURE in a DWP file,
13301 then we check if we've already seen DWO_NAME, and only THEN do we check
13304 The result is a pointer to the dwo_unit object or NULL if we didn't find it
13305 (dwo_id mismatch or couldn't find the DWO/DWP file). */
13307 static struct dwo_unit
*
13308 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
13309 const char *dwo_name
, const char *comp_dir
,
13310 ULONGEST signature
, int is_debug_types
)
13312 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_unit
->dwarf2_per_objfile
;
13313 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13314 const char *kind
= is_debug_types
? "TU" : "CU";
13315 void **dwo_file_slot
;
13316 struct dwo_file
*dwo_file
;
13317 struct dwp_file
*dwp_file
;
13319 /* First see if there's a DWP file.
13320 If we have a DWP file but didn't find the DWO inside it, don't
13321 look for the original DWO file. It makes gdb behave differently
13322 depending on whether one is debugging in the build tree. */
13324 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
13325 if (dwp_file
!= NULL
)
13327 const struct dwp_hash_table
*dwp_htab
=
13328 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
13330 if (dwp_htab
!= NULL
)
13332 struct dwo_unit
*dwo_cutu
=
13333 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
13334 signature
, is_debug_types
);
13336 if (dwo_cutu
!= NULL
)
13338 if (dwarf_read_debug
)
13340 fprintf_unfiltered (gdb_stdlog
,
13341 "Virtual DWO %s %s found: @%s\n",
13342 kind
, hex_string (signature
),
13343 host_address_to_string (dwo_cutu
));
13351 /* No DWP file, look for the DWO file. */
13353 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
13354 dwo_name
, comp_dir
);
13355 if (*dwo_file_slot
== NULL
)
13357 /* Read in the file and build a table of the CUs/TUs it contains. */
13358 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
13360 /* NOTE: This will be NULL if unable to open the file. */
13361 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
13363 if (dwo_file
!= NULL
)
13365 struct dwo_unit
*dwo_cutu
= NULL
;
13367 if (is_debug_types
&& dwo_file
->tus
)
13369 struct dwo_unit find_dwo_cutu
;
13371 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13372 find_dwo_cutu
.signature
= signature
;
13374 = (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_cutu
);
13376 else if (!is_debug_types
&& dwo_file
->cus
)
13378 struct dwo_unit find_dwo_cutu
;
13380 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13381 find_dwo_cutu
.signature
= signature
;
13382 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
,
13386 if (dwo_cutu
!= NULL
)
13388 if (dwarf_read_debug
)
13390 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
13391 kind
, dwo_name
, hex_string (signature
),
13392 host_address_to_string (dwo_cutu
));
13399 /* We didn't find it. This could mean a dwo_id mismatch, or
13400 someone deleted the DWO/DWP file, or the search path isn't set up
13401 correctly to find the file. */
13403 if (dwarf_read_debug
)
13405 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
13406 kind
, dwo_name
, hex_string (signature
));
13409 /* This is a warning and not a complaint because it can be caused by
13410 pilot error (e.g., user accidentally deleting the DWO). */
13412 /* Print the name of the DWP file if we looked there, helps the user
13413 better diagnose the problem. */
13414 std::string dwp_text
;
13416 if (dwp_file
!= NULL
)
13417 dwp_text
= string_printf (" [in DWP file %s]",
13418 lbasename (dwp_file
->name
));
13420 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
13421 " [in module %s]"),
13422 kind
, dwo_name
, hex_string (signature
),
13424 this_unit
->is_debug_types
? "TU" : "CU",
13425 sect_offset_str (this_unit
->sect_off
), objfile_name (objfile
));
13430 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
13431 See lookup_dwo_cutu_unit for details. */
13433 static struct dwo_unit
*
13434 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
13435 const char *dwo_name
, const char *comp_dir
,
13436 ULONGEST signature
)
13438 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
13441 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
13442 See lookup_dwo_cutu_unit for details. */
13444 static struct dwo_unit
*
13445 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
13446 const char *dwo_name
, const char *comp_dir
)
13448 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
13451 /* Traversal function for queue_and_load_all_dwo_tus. */
13454 queue_and_load_dwo_tu (void **slot
, void *info
)
13456 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
13457 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
13458 ULONGEST signature
= dwo_unit
->signature
;
13459 struct signatured_type
*sig_type
=
13460 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
13462 if (sig_type
!= NULL
)
13464 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
13466 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
13467 a real dependency of PER_CU on SIG_TYPE. That is detected later
13468 while processing PER_CU. */
13469 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
13470 load_full_type_unit (sig_cu
);
13471 per_cu
->imported_symtabs_push (sig_cu
);
13477 /* Queue all TUs contained in the DWO of PER_CU to be read in.
13478 The DWO may have the only definition of the type, though it may not be
13479 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
13480 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
13483 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
13485 struct dwo_unit
*dwo_unit
;
13486 struct dwo_file
*dwo_file
;
13488 gdb_assert (!per_cu
->is_debug_types
);
13489 gdb_assert (get_dwp_file (per_cu
->dwarf2_per_objfile
) == NULL
);
13490 gdb_assert (per_cu
->cu
!= NULL
);
13492 dwo_unit
= per_cu
->cu
->dwo_unit
;
13493 gdb_assert (dwo_unit
!= NULL
);
13495 dwo_file
= dwo_unit
->dwo_file
;
13496 if (dwo_file
->tus
!= NULL
)
13497 htab_traverse_noresize (dwo_file
->tus
, queue_and_load_dwo_tu
, per_cu
);
13500 /* Read in various DIEs. */
13502 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
13503 Inherit only the children of the DW_AT_abstract_origin DIE not being
13504 already referenced by DW_AT_abstract_origin from the children of the
13508 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
13510 struct die_info
*child_die
;
13511 sect_offset
*offsetp
;
13512 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
13513 struct die_info
*origin_die
;
13514 /* Iterator of the ORIGIN_DIE children. */
13515 struct die_info
*origin_child_die
;
13516 struct attribute
*attr
;
13517 struct dwarf2_cu
*origin_cu
;
13518 struct pending
**origin_previous_list_in_scope
;
13520 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13524 /* Note that following die references may follow to a die in a
13528 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
13530 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
13532 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
13533 origin_cu
->list_in_scope
= cu
->list_in_scope
;
13535 if (die
->tag
!= origin_die
->tag
13536 && !(die
->tag
== DW_TAG_inlined_subroutine
13537 && origin_die
->tag
== DW_TAG_subprogram
))
13538 complaint (_("DIE %s and its abstract origin %s have different tags"),
13539 sect_offset_str (die
->sect_off
),
13540 sect_offset_str (origin_die
->sect_off
));
13542 std::vector
<sect_offset
> offsets
;
13544 for (child_die
= die
->child
;
13545 child_die
&& child_die
->tag
;
13546 child_die
= sibling_die (child_die
))
13548 struct die_info
*child_origin_die
;
13549 struct dwarf2_cu
*child_origin_cu
;
13551 /* We are trying to process concrete instance entries:
13552 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
13553 it's not relevant to our analysis here. i.e. detecting DIEs that are
13554 present in the abstract instance but not referenced in the concrete
13556 if (child_die
->tag
== DW_TAG_call_site
13557 || child_die
->tag
== DW_TAG_GNU_call_site
)
13560 /* For each CHILD_DIE, find the corresponding child of
13561 ORIGIN_DIE. If there is more than one layer of
13562 DW_AT_abstract_origin, follow them all; there shouldn't be,
13563 but GCC versions at least through 4.4 generate this (GCC PR
13565 child_origin_die
= child_die
;
13566 child_origin_cu
= cu
;
13569 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
13573 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
13577 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
13578 counterpart may exist. */
13579 if (child_origin_die
!= child_die
)
13581 if (child_die
->tag
!= child_origin_die
->tag
13582 && !(child_die
->tag
== DW_TAG_inlined_subroutine
13583 && child_origin_die
->tag
== DW_TAG_subprogram
))
13584 complaint (_("Child DIE %s and its abstract origin %s have "
13586 sect_offset_str (child_die
->sect_off
),
13587 sect_offset_str (child_origin_die
->sect_off
));
13588 if (child_origin_die
->parent
!= origin_die
)
13589 complaint (_("Child DIE %s and its abstract origin %s have "
13590 "different parents"),
13591 sect_offset_str (child_die
->sect_off
),
13592 sect_offset_str (child_origin_die
->sect_off
));
13594 offsets
.push_back (child_origin_die
->sect_off
);
13597 std::sort (offsets
.begin (), offsets
.end ());
13598 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
13599 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
13600 if (offsetp
[-1] == *offsetp
)
13601 complaint (_("Multiple children of DIE %s refer "
13602 "to DIE %s as their abstract origin"),
13603 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
13605 offsetp
= offsets
.data ();
13606 origin_child_die
= origin_die
->child
;
13607 while (origin_child_die
&& origin_child_die
->tag
)
13609 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13610 while (offsetp
< offsets_end
13611 && *offsetp
< origin_child_die
->sect_off
)
13613 if (offsetp
>= offsets_end
13614 || *offsetp
> origin_child_die
->sect_off
)
13616 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13617 Check whether we're already processing ORIGIN_CHILD_DIE.
13618 This can happen with mutually referenced abstract_origins.
13620 if (!origin_child_die
->in_process
)
13621 process_die (origin_child_die
, origin_cu
);
13623 origin_child_die
= sibling_die (origin_child_die
);
13625 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13627 if (cu
!= origin_cu
)
13628 compute_delayed_physnames (origin_cu
);
13632 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13634 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13635 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13636 struct context_stack
*newobj
;
13639 struct die_info
*child_die
;
13640 struct attribute
*attr
, *call_line
, *call_file
;
13642 CORE_ADDR baseaddr
;
13643 struct block
*block
;
13644 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13645 std::vector
<struct symbol
*> template_args
;
13646 struct template_symbol
*templ_func
= NULL
;
13650 /* If we do not have call site information, we can't show the
13651 caller of this inlined function. That's too confusing, so
13652 only use the scope for local variables. */
13653 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13654 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13655 if (call_line
== NULL
|| call_file
== NULL
)
13657 read_lexical_block_scope (die
, cu
);
13662 baseaddr
= objfile
->text_section_offset ();
13664 name
= dwarf2_name (die
, cu
);
13666 /* Ignore functions with missing or empty names. These are actually
13667 illegal according to the DWARF standard. */
13670 complaint (_("missing name for subprogram DIE at %s"),
13671 sect_offset_str (die
->sect_off
));
13675 /* Ignore functions with missing or invalid low and high pc attributes. */
13676 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13677 <= PC_BOUNDS_INVALID
)
13679 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13680 if (!attr
|| !DW_UNSND (attr
))
13681 complaint (_("cannot get low and high bounds "
13682 "for subprogram DIE at %s"),
13683 sect_offset_str (die
->sect_off
));
13687 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13688 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13690 /* If we have any template arguments, then we must allocate a
13691 different sort of symbol. */
13692 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
13694 if (child_die
->tag
== DW_TAG_template_type_param
13695 || child_die
->tag
== DW_TAG_template_value_param
)
13697 templ_func
= allocate_template_symbol (objfile
);
13698 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13703 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13704 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13705 (struct symbol
*) templ_func
);
13707 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13708 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
13711 /* If there is a location expression for DW_AT_frame_base, record
13713 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13714 if (attr
!= nullptr)
13715 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13717 /* If there is a location for the static link, record it. */
13718 newobj
->static_link
= NULL
;
13719 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13720 if (attr
!= nullptr)
13722 newobj
->static_link
13723 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13724 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13725 dwarf2_per_cu_addr_type (cu
->per_cu
));
13728 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13730 if (die
->child
!= NULL
)
13732 child_die
= die
->child
;
13733 while (child_die
&& child_die
->tag
)
13735 if (child_die
->tag
== DW_TAG_template_type_param
13736 || child_die
->tag
== DW_TAG_template_value_param
)
13738 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13741 template_args
.push_back (arg
);
13744 process_die (child_die
, cu
);
13745 child_die
= sibling_die (child_die
);
13749 inherit_abstract_dies (die
, cu
);
13751 /* If we have a DW_AT_specification, we might need to import using
13752 directives from the context of the specification DIE. See the
13753 comment in determine_prefix. */
13754 if (cu
->language
== language_cplus
13755 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13757 struct dwarf2_cu
*spec_cu
= cu
;
13758 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13762 child_die
= spec_die
->child
;
13763 while (child_die
&& child_die
->tag
)
13765 if (child_die
->tag
== DW_TAG_imported_module
)
13766 process_die (child_die
, spec_cu
);
13767 child_die
= sibling_die (child_die
);
13770 /* In some cases, GCC generates specification DIEs that
13771 themselves contain DW_AT_specification attributes. */
13772 spec_die
= die_specification (spec_die
, &spec_cu
);
13776 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13777 /* Make a block for the local symbols within. */
13778 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13779 cstk
.static_link
, lowpc
, highpc
);
13781 /* For C++, set the block's scope. */
13782 if ((cu
->language
== language_cplus
13783 || cu
->language
== language_fortran
13784 || cu
->language
== language_d
13785 || cu
->language
== language_rust
)
13786 && cu
->processing_has_namespace_info
)
13787 block_set_scope (block
, determine_prefix (die
, cu
),
13788 &objfile
->objfile_obstack
);
13790 /* If we have address ranges, record them. */
13791 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13793 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13795 /* Attach template arguments to function. */
13796 if (!template_args
.empty ())
13798 gdb_assert (templ_func
!= NULL
);
13800 templ_func
->n_template_arguments
= template_args
.size ();
13801 templ_func
->template_arguments
13802 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13803 templ_func
->n_template_arguments
);
13804 memcpy (templ_func
->template_arguments
,
13805 template_args
.data (),
13806 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13808 /* Make sure that the symtab is set on the new symbols. Even
13809 though they don't appear in this symtab directly, other parts
13810 of gdb assume that symbols do, and this is reasonably
13812 for (symbol
*sym
: template_args
)
13813 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13816 /* In C++, we can have functions nested inside functions (e.g., when
13817 a function declares a class that has methods). This means that
13818 when we finish processing a function scope, we may need to go
13819 back to building a containing block's symbol lists. */
13820 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13821 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13823 /* If we've finished processing a top-level function, subsequent
13824 symbols go in the file symbol list. */
13825 if (cu
->get_builder ()->outermost_context_p ())
13826 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13829 /* Process all the DIES contained within a lexical block scope. Start
13830 a new scope, process the dies, and then close the scope. */
13833 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13835 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13836 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13837 CORE_ADDR lowpc
, highpc
;
13838 struct die_info
*child_die
;
13839 CORE_ADDR baseaddr
;
13841 baseaddr
= objfile
->text_section_offset ();
13843 /* Ignore blocks with missing or invalid low and high pc attributes. */
13844 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13845 as multiple lexical blocks? Handling children in a sane way would
13846 be nasty. Might be easier to properly extend generic blocks to
13847 describe ranges. */
13848 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13850 case PC_BOUNDS_NOT_PRESENT
:
13851 /* DW_TAG_lexical_block has no attributes, process its children as if
13852 there was no wrapping by that DW_TAG_lexical_block.
13853 GCC does no longer produces such DWARF since GCC r224161. */
13854 for (child_die
= die
->child
;
13855 child_die
!= NULL
&& child_die
->tag
;
13856 child_die
= sibling_die (child_die
))
13857 process_die (child_die
, cu
);
13859 case PC_BOUNDS_INVALID
:
13862 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13863 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13865 cu
->get_builder ()->push_context (0, lowpc
);
13866 if (die
->child
!= NULL
)
13868 child_die
= die
->child
;
13869 while (child_die
&& child_die
->tag
)
13871 process_die (child_die
, cu
);
13872 child_die
= sibling_die (child_die
);
13875 inherit_abstract_dies (die
, cu
);
13876 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13878 if (*cu
->get_builder ()->get_local_symbols () != NULL
13879 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13881 struct block
*block
13882 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13883 cstk
.start_addr
, highpc
);
13885 /* Note that recording ranges after traversing children, as we
13886 do here, means that recording a parent's ranges entails
13887 walking across all its children's ranges as they appear in
13888 the address map, which is quadratic behavior.
13890 It would be nicer to record the parent's ranges before
13891 traversing its children, simply overriding whatever you find
13892 there. But since we don't even decide whether to create a
13893 block until after we've traversed its children, that's hard
13895 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13897 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13898 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13901 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13904 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13906 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13907 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13908 CORE_ADDR pc
, baseaddr
;
13909 struct attribute
*attr
;
13910 struct call_site
*call_site
, call_site_local
;
13913 struct die_info
*child_die
;
13915 baseaddr
= objfile
->text_section_offset ();
13917 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13920 /* This was a pre-DWARF-5 GNU extension alias
13921 for DW_AT_call_return_pc. */
13922 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13926 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13927 "DIE %s [in module %s]"),
13928 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13931 pc
= attr_value_as_address (attr
) + baseaddr
;
13932 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13934 if (cu
->call_site_htab
== NULL
)
13935 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13936 NULL
, &objfile
->objfile_obstack
,
13937 hashtab_obstack_allocate
, NULL
);
13938 call_site_local
.pc
= pc
;
13939 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13942 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13943 "DIE %s [in module %s]"),
13944 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13945 objfile_name (objfile
));
13949 /* Count parameters at the caller. */
13952 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13953 child_die
= sibling_die (child_die
))
13955 if (child_die
->tag
!= DW_TAG_call_site_parameter
13956 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13958 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13959 "DW_TAG_call_site child DIE %s [in module %s]"),
13960 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13961 objfile_name (objfile
));
13969 = ((struct call_site
*)
13970 obstack_alloc (&objfile
->objfile_obstack
,
13971 sizeof (*call_site
)
13972 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13974 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13975 call_site
->pc
= pc
;
13977 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13978 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13980 struct die_info
*func_die
;
13982 /* Skip also over DW_TAG_inlined_subroutine. */
13983 for (func_die
= die
->parent
;
13984 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13985 && func_die
->tag
!= DW_TAG_subroutine_type
;
13986 func_die
= func_die
->parent
);
13988 /* DW_AT_call_all_calls is a superset
13989 of DW_AT_call_all_tail_calls. */
13991 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13992 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13993 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13994 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13996 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13997 not complete. But keep CALL_SITE for look ups via call_site_htab,
13998 both the initial caller containing the real return address PC and
13999 the final callee containing the current PC of a chain of tail
14000 calls do not need to have the tail call list complete. But any
14001 function candidate for a virtual tail call frame searched via
14002 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
14003 determined unambiguously. */
14007 struct type
*func_type
= NULL
;
14010 func_type
= get_die_type (func_die
, cu
);
14011 if (func_type
!= NULL
)
14013 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
14015 /* Enlist this call site to the function. */
14016 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
14017 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
14020 complaint (_("Cannot find function owning DW_TAG_call_site "
14021 "DIE %s [in module %s]"),
14022 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14026 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
14028 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
14030 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
14033 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
14034 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
14036 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
14037 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
14038 /* Keep NULL DWARF_BLOCK. */;
14039 else if (attr_form_is_block (attr
))
14041 struct dwarf2_locexpr_baton
*dlbaton
;
14043 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
14044 dlbaton
->data
= DW_BLOCK (attr
)->data
;
14045 dlbaton
->size
= DW_BLOCK (attr
)->size
;
14046 dlbaton
->per_cu
= cu
->per_cu
;
14048 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
14050 else if (attr_form_is_ref (attr
))
14052 struct dwarf2_cu
*target_cu
= cu
;
14053 struct die_info
*target_die
;
14055 target_die
= follow_die_ref (die
, attr
, &target_cu
);
14056 gdb_assert (target_cu
->per_cu
->dwarf2_per_objfile
->objfile
== objfile
);
14057 if (die_is_declaration (target_die
, target_cu
))
14059 const char *target_physname
;
14061 /* Prefer the mangled name; otherwise compute the demangled one. */
14062 target_physname
= dw2_linkage_name (target_die
, target_cu
);
14063 if (target_physname
== NULL
)
14064 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
14065 if (target_physname
== NULL
)
14066 complaint (_("DW_AT_call_target target DIE has invalid "
14067 "physname, for referencing DIE %s [in module %s]"),
14068 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14070 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
14076 /* DW_AT_entry_pc should be preferred. */
14077 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
14078 <= PC_BOUNDS_INVALID
)
14079 complaint (_("DW_AT_call_target target DIE has invalid "
14080 "low pc, for referencing DIE %s [in module %s]"),
14081 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14084 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
14085 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
14090 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
14091 "block nor reference, for DIE %s [in module %s]"),
14092 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14094 call_site
->per_cu
= cu
->per_cu
;
14096 for (child_die
= die
->child
;
14097 child_die
&& child_die
->tag
;
14098 child_die
= sibling_die (child_die
))
14100 struct call_site_parameter
*parameter
;
14101 struct attribute
*loc
, *origin
;
14103 if (child_die
->tag
!= DW_TAG_call_site_parameter
14104 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
14106 /* Already printed the complaint above. */
14110 gdb_assert (call_site
->parameter_count
< nparams
);
14111 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
14113 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
14114 specifies DW_TAG_formal_parameter. Value of the data assumed for the
14115 register is contained in DW_AT_call_value. */
14117 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
14118 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
14119 if (origin
== NULL
)
14121 /* This was a pre-DWARF-5 GNU extension alias
14122 for DW_AT_call_parameter. */
14123 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
14125 if (loc
== NULL
&& origin
!= NULL
&& attr_form_is_ref (origin
))
14127 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
14129 sect_offset sect_off
14130 = (sect_offset
) dwarf2_get_ref_die_offset (origin
);
14131 if (!offset_in_cu_p (&cu
->header
, sect_off
))
14133 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
14134 binding can be done only inside one CU. Such referenced DIE
14135 therefore cannot be even moved to DW_TAG_partial_unit. */
14136 complaint (_("DW_AT_call_parameter offset is not in CU for "
14137 "DW_TAG_call_site child DIE %s [in module %s]"),
14138 sect_offset_str (child_die
->sect_off
),
14139 objfile_name (objfile
));
14142 parameter
->u
.param_cu_off
14143 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
14145 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
14147 complaint (_("No DW_FORM_block* DW_AT_location for "
14148 "DW_TAG_call_site child DIE %s [in module %s]"),
14149 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
14154 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
14155 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
14156 if (parameter
->u
.dwarf_reg
!= -1)
14157 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
14158 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
14159 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
14160 ¶meter
->u
.fb_offset
))
14161 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
14164 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
14165 "for DW_FORM_block* DW_AT_location is supported for "
14166 "DW_TAG_call_site child DIE %s "
14168 sect_offset_str (child_die
->sect_off
),
14169 objfile_name (objfile
));
14174 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
14176 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
14177 if (!attr_form_is_block (attr
))
14179 complaint (_("No DW_FORM_block* DW_AT_call_value for "
14180 "DW_TAG_call_site child DIE %s [in module %s]"),
14181 sect_offset_str (child_die
->sect_off
),
14182 objfile_name (objfile
));
14185 parameter
->value
= DW_BLOCK (attr
)->data
;
14186 parameter
->value_size
= DW_BLOCK (attr
)->size
;
14188 /* Parameters are not pre-cleared by memset above. */
14189 parameter
->data_value
= NULL
;
14190 parameter
->data_value_size
= 0;
14191 call_site
->parameter_count
++;
14193 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
14195 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
14196 if (attr
!= nullptr)
14198 if (!attr_form_is_block (attr
))
14199 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
14200 "DW_TAG_call_site child DIE %s [in module %s]"),
14201 sect_offset_str (child_die
->sect_off
),
14202 objfile_name (objfile
));
14205 parameter
->data_value
= DW_BLOCK (attr
)->data
;
14206 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
14212 /* Helper function for read_variable. If DIE represents a virtual
14213 table, then return the type of the concrete object that is
14214 associated with the virtual table. Otherwise, return NULL. */
14216 static struct type
*
14217 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14219 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
14223 /* Find the type DIE. */
14224 struct die_info
*type_die
= NULL
;
14225 struct dwarf2_cu
*type_cu
= cu
;
14227 if (attr_form_is_ref (attr
))
14228 type_die
= follow_die_ref (die
, attr
, &type_cu
);
14229 if (type_die
== NULL
)
14232 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
14234 return die_containing_type (type_die
, type_cu
);
14237 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
14240 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
14242 struct rust_vtable_symbol
*storage
= NULL
;
14244 if (cu
->language
== language_rust
)
14246 struct type
*containing_type
= rust_containing_type (die
, cu
);
14248 if (containing_type
!= NULL
)
14250 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14252 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol ();
14253 initialize_objfile_symbol (storage
);
14254 storage
->concrete_type
= containing_type
;
14255 storage
->subclass
= SYMBOL_RUST_VTABLE
;
14259 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
14260 struct attribute
*abstract_origin
14261 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
14262 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
14263 if (res
== NULL
&& loc
&& abstract_origin
)
14265 /* We have a variable without a name, but with a location and an abstract
14266 origin. This may be a concrete instance of an abstract variable
14267 referenced from an DW_OP_GNU_variable_value, so save it to find it back
14269 struct dwarf2_cu
*origin_cu
= cu
;
14270 struct die_info
*origin_die
14271 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
14272 dwarf2_per_objfile
*dpo
= cu
->per_cu
->dwarf2_per_objfile
;
14273 dpo
->abstract_to_concrete
[origin_die
->sect_off
].push_back (die
->sect_off
);
14277 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
14278 reading .debug_rnglists.
14279 Callback's type should be:
14280 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14281 Return true if the attributes are present and valid, otherwise,
14284 template <typename Callback
>
14286 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
14287 Callback
&&callback
)
14289 struct dwarf2_per_objfile
*dwarf2_per_objfile
14290 = cu
->per_cu
->dwarf2_per_objfile
;
14291 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14292 bfd
*obfd
= objfile
->obfd
;
14293 /* Base address selection entry. */
14296 const gdb_byte
*buffer
;
14297 CORE_ADDR baseaddr
;
14298 bool overflow
= false;
14300 found_base
= cu
->base_known
;
14301 base
= cu
->base_address
;
14303 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->rnglists
);
14304 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
14306 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14310 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
14312 baseaddr
= objfile
->text_section_offset ();
14316 /* Initialize it due to a false compiler warning. */
14317 CORE_ADDR range_beginning
= 0, range_end
= 0;
14318 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
14319 + dwarf2_per_objfile
->rnglists
.size
);
14320 unsigned int bytes_read
;
14322 if (buffer
== buf_end
)
14327 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
14330 case DW_RLE_end_of_list
:
14332 case DW_RLE_base_address
:
14333 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14338 base
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14340 buffer
+= bytes_read
;
14342 case DW_RLE_start_length
:
14343 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14348 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14349 buffer
+= bytes_read
;
14350 range_end
= (range_beginning
14351 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
14352 buffer
+= bytes_read
;
14353 if (buffer
> buf_end
)
14359 case DW_RLE_offset_pair
:
14360 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14361 buffer
+= bytes_read
;
14362 if (buffer
> buf_end
)
14367 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14368 buffer
+= bytes_read
;
14369 if (buffer
> buf_end
)
14375 case DW_RLE_start_end
:
14376 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
14381 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14382 buffer
+= bytes_read
;
14383 range_end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14384 buffer
+= bytes_read
;
14387 complaint (_("Invalid .debug_rnglists data (no base address)"));
14390 if (rlet
== DW_RLE_end_of_list
|| overflow
)
14392 if (rlet
== DW_RLE_base_address
)
14397 /* We have no valid base address for the ranges
14399 complaint (_("Invalid .debug_rnglists data (no base address)"));
14403 if (range_beginning
> range_end
)
14405 /* Inverted range entries are invalid. */
14406 complaint (_("Invalid .debug_rnglists data (inverted range)"));
14410 /* Empty range entries have no effect. */
14411 if (range_beginning
== range_end
)
14414 range_beginning
+= base
;
14417 /* A not-uncommon case of bad debug info.
14418 Don't pollute the addrmap with bad data. */
14419 if (range_beginning
+ baseaddr
== 0
14420 && !dwarf2_per_objfile
->has_section_at_zero
)
14422 complaint (_(".debug_rnglists entry has start address of zero"
14423 " [in module %s]"), objfile_name (objfile
));
14427 callback (range_beginning
, range_end
);
14432 complaint (_("Offset %d is not terminated "
14433 "for DW_AT_ranges attribute"),
14441 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
14442 Callback's type should be:
14443 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14444 Return 1 if the attributes are present and valid, otherwise, return 0. */
14446 template <typename Callback
>
14448 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
14449 Callback
&&callback
)
14451 struct dwarf2_per_objfile
*dwarf2_per_objfile
14452 = cu
->per_cu
->dwarf2_per_objfile
;
14453 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14454 struct comp_unit_head
*cu_header
= &cu
->header
;
14455 bfd
*obfd
= objfile
->obfd
;
14456 unsigned int addr_size
= cu_header
->addr_size
;
14457 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
14458 /* Base address selection entry. */
14461 unsigned int dummy
;
14462 const gdb_byte
*buffer
;
14463 CORE_ADDR baseaddr
;
14465 if (cu_header
->version
>= 5)
14466 return dwarf2_rnglists_process (offset
, cu
, callback
);
14468 found_base
= cu
->base_known
;
14469 base
= cu
->base_address
;
14471 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
14472 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
14474 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14478 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
14480 baseaddr
= objfile
->text_section_offset ();
14484 CORE_ADDR range_beginning
, range_end
;
14486 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
14487 buffer
+= addr_size
;
14488 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
14489 buffer
+= addr_size
;
14490 offset
+= 2 * addr_size
;
14492 /* An end of list marker is a pair of zero addresses. */
14493 if (range_beginning
== 0 && range_end
== 0)
14494 /* Found the end of list entry. */
14497 /* Each base address selection entry is a pair of 2 values.
14498 The first is the largest possible address, the second is
14499 the base address. Check for a base address here. */
14500 if ((range_beginning
& mask
) == mask
)
14502 /* If we found the largest possible address, then we already
14503 have the base address in range_end. */
14511 /* We have no valid base address for the ranges
14513 complaint (_("Invalid .debug_ranges data (no base address)"));
14517 if (range_beginning
> range_end
)
14519 /* Inverted range entries are invalid. */
14520 complaint (_("Invalid .debug_ranges data (inverted range)"));
14524 /* Empty range entries have no effect. */
14525 if (range_beginning
== range_end
)
14528 range_beginning
+= base
;
14531 /* A not-uncommon case of bad debug info.
14532 Don't pollute the addrmap with bad data. */
14533 if (range_beginning
+ baseaddr
== 0
14534 && !dwarf2_per_objfile
->has_section_at_zero
)
14536 complaint (_(".debug_ranges entry has start address of zero"
14537 " [in module %s]"), objfile_name (objfile
));
14541 callback (range_beginning
, range_end
);
14547 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
14548 Return 1 if the attributes are present and valid, otherwise, return 0.
14549 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
14552 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
14553 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
14554 dwarf2_psymtab
*ranges_pst
)
14556 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14557 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14558 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
14561 CORE_ADDR high
= 0;
14564 retval
= dwarf2_ranges_process (offset
, cu
,
14565 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
14567 if (ranges_pst
!= NULL
)
14572 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14573 range_beginning
+ baseaddr
)
14575 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14576 range_end
+ baseaddr
)
14578 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
14579 lowpc
, highpc
- 1, ranges_pst
);
14582 /* FIXME: This is recording everything as a low-high
14583 segment of consecutive addresses. We should have a
14584 data structure for discontiguous block ranges
14588 low
= range_beginning
;
14594 if (range_beginning
< low
)
14595 low
= range_beginning
;
14596 if (range_end
> high
)
14604 /* If the first entry is an end-of-list marker, the range
14605 describes an empty scope, i.e. no instructions. */
14611 *high_return
= high
;
14615 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14616 definition for the return value. *LOWPC and *HIGHPC are set iff
14617 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14619 static enum pc_bounds_kind
14620 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14621 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14622 dwarf2_psymtab
*pst
)
14624 struct dwarf2_per_objfile
*dwarf2_per_objfile
14625 = cu
->per_cu
->dwarf2_per_objfile
;
14626 struct attribute
*attr
;
14627 struct attribute
*attr_high
;
14629 CORE_ADDR high
= 0;
14630 enum pc_bounds_kind ret
;
14632 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14635 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14636 if (attr
!= nullptr)
14638 low
= attr_value_as_address (attr
);
14639 high
= attr_value_as_address (attr_high
);
14640 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
14644 /* Found high w/o low attribute. */
14645 return PC_BOUNDS_INVALID
;
14647 /* Found consecutive range of addresses. */
14648 ret
= PC_BOUNDS_HIGH_LOW
;
14652 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14655 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14656 We take advantage of the fact that DW_AT_ranges does not appear
14657 in DW_TAG_compile_unit of DWO files. */
14658 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14659 unsigned int ranges_offset
= (DW_UNSND (attr
)
14660 + (need_ranges_base
14664 /* Value of the DW_AT_ranges attribute is the offset in the
14665 .debug_ranges section. */
14666 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
14667 return PC_BOUNDS_INVALID
;
14668 /* Found discontinuous range of addresses. */
14669 ret
= PC_BOUNDS_RANGES
;
14672 return PC_BOUNDS_NOT_PRESENT
;
14675 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14677 return PC_BOUNDS_INVALID
;
14679 /* When using the GNU linker, .gnu.linkonce. sections are used to
14680 eliminate duplicate copies of functions and vtables and such.
14681 The linker will arbitrarily choose one and discard the others.
14682 The AT_*_pc values for such functions refer to local labels in
14683 these sections. If the section from that file was discarded, the
14684 labels are not in the output, so the relocs get a value of 0.
14685 If this is a discarded function, mark the pc bounds as invalid,
14686 so that GDB will ignore it. */
14687 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
14688 return PC_BOUNDS_INVALID
;
14696 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14697 its low and high PC addresses. Do nothing if these addresses could not
14698 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14699 and HIGHPC to the high address if greater than HIGHPC. */
14702 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14703 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14704 struct dwarf2_cu
*cu
)
14706 CORE_ADDR low
, high
;
14707 struct die_info
*child
= die
->child
;
14709 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14711 *lowpc
= std::min (*lowpc
, low
);
14712 *highpc
= std::max (*highpc
, high
);
14715 /* If the language does not allow nested subprograms (either inside
14716 subprograms or lexical blocks), we're done. */
14717 if (cu
->language
!= language_ada
)
14720 /* Check all the children of the given DIE. If it contains nested
14721 subprograms, then check their pc bounds. Likewise, we need to
14722 check lexical blocks as well, as they may also contain subprogram
14724 while (child
&& child
->tag
)
14726 if (child
->tag
== DW_TAG_subprogram
14727 || child
->tag
== DW_TAG_lexical_block
)
14728 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14729 child
= sibling_die (child
);
14733 /* Get the low and high pc's represented by the scope DIE, and store
14734 them in *LOWPC and *HIGHPC. If the correct values can't be
14735 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14738 get_scope_pc_bounds (struct die_info
*die
,
14739 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14740 struct dwarf2_cu
*cu
)
14742 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14743 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14744 CORE_ADDR current_low
, current_high
;
14746 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14747 >= PC_BOUNDS_RANGES
)
14749 best_low
= current_low
;
14750 best_high
= current_high
;
14754 struct die_info
*child
= die
->child
;
14756 while (child
&& child
->tag
)
14758 switch (child
->tag
) {
14759 case DW_TAG_subprogram
:
14760 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14762 case DW_TAG_namespace
:
14763 case DW_TAG_module
:
14764 /* FIXME: carlton/2004-01-16: Should we do this for
14765 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14766 that current GCC's always emit the DIEs corresponding
14767 to definitions of methods of classes as children of a
14768 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14769 the DIEs giving the declarations, which could be
14770 anywhere). But I don't see any reason why the
14771 standards says that they have to be there. */
14772 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14774 if (current_low
!= ((CORE_ADDR
) -1))
14776 best_low
= std::min (best_low
, current_low
);
14777 best_high
= std::max (best_high
, current_high
);
14785 child
= sibling_die (child
);
14790 *highpc
= best_high
;
14793 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14797 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14798 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14800 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14801 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14802 struct attribute
*attr
;
14803 struct attribute
*attr_high
;
14805 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14808 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14809 if (attr
!= nullptr)
14811 CORE_ADDR low
= attr_value_as_address (attr
);
14812 CORE_ADDR high
= attr_value_as_address (attr_high
);
14814 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
14817 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14818 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14819 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14823 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14824 if (attr
!= nullptr)
14826 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14827 We take advantage of the fact that DW_AT_ranges does not appear
14828 in DW_TAG_compile_unit of DWO files. */
14829 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14831 /* The value of the DW_AT_ranges attribute is the offset of the
14832 address range list in the .debug_ranges section. */
14833 unsigned long offset
= (DW_UNSND (attr
)
14834 + (need_ranges_base
? cu
->ranges_base
: 0));
14836 std::vector
<blockrange
> blockvec
;
14837 dwarf2_ranges_process (offset
, cu
,
14838 [&] (CORE_ADDR start
, CORE_ADDR end
)
14842 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14843 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14844 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14845 blockvec
.emplace_back (start
, end
);
14848 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14852 /* Check whether the producer field indicates either of GCC < 4.6, or the
14853 Intel C/C++ compiler, and cache the result in CU. */
14856 check_producer (struct dwarf2_cu
*cu
)
14860 if (cu
->producer
== NULL
)
14862 /* For unknown compilers expect their behavior is DWARF version
14865 GCC started to support .debug_types sections by -gdwarf-4 since
14866 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14867 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14868 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14869 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14871 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14873 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14874 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14876 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14878 cu
->producer_is_icc
= true;
14879 cu
->producer_is_icc_lt_14
= major
< 14;
14881 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14882 cu
->producer_is_codewarrior
= true;
14885 /* For other non-GCC compilers, expect their behavior is DWARF version
14889 cu
->checked_producer
= true;
14892 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14893 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14894 during 4.6.0 experimental. */
14897 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14899 if (!cu
->checked_producer
)
14900 check_producer (cu
);
14902 return cu
->producer_is_gxx_lt_4_6
;
14906 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14907 with incorrect is_stmt attributes. */
14910 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14912 if (!cu
->checked_producer
)
14913 check_producer (cu
);
14915 return cu
->producer_is_codewarrior
;
14918 /* Return the default accessibility type if it is not overridden by
14919 DW_AT_accessibility. */
14921 static enum dwarf_access_attribute
14922 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14924 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14926 /* The default DWARF 2 accessibility for members is public, the default
14927 accessibility for inheritance is private. */
14929 if (die
->tag
!= DW_TAG_inheritance
)
14930 return DW_ACCESS_public
;
14932 return DW_ACCESS_private
;
14936 /* DWARF 3+ defines the default accessibility a different way. The same
14937 rules apply now for DW_TAG_inheritance as for the members and it only
14938 depends on the container kind. */
14940 if (die
->parent
->tag
== DW_TAG_class_type
)
14941 return DW_ACCESS_private
;
14943 return DW_ACCESS_public
;
14947 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14948 offset. If the attribute was not found return 0, otherwise return
14949 1. If it was found but could not properly be handled, set *OFFSET
14953 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14956 struct attribute
*attr
;
14958 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14963 /* Note that we do not check for a section offset first here.
14964 This is because DW_AT_data_member_location is new in DWARF 4,
14965 so if we see it, we can assume that a constant form is really
14966 a constant and not a section offset. */
14967 if (attr_form_is_constant (attr
))
14968 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
14969 else if (attr_form_is_section_offset (attr
))
14970 dwarf2_complex_location_expr_complaint ();
14971 else if (attr_form_is_block (attr
))
14972 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14974 dwarf2_complex_location_expr_complaint ();
14982 /* Add an aggregate field to the field list. */
14985 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14986 struct dwarf2_cu
*cu
)
14988 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14989 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14990 struct nextfield
*new_field
;
14991 struct attribute
*attr
;
14993 const char *fieldname
= "";
14995 if (die
->tag
== DW_TAG_inheritance
)
14997 fip
->baseclasses
.emplace_back ();
14998 new_field
= &fip
->baseclasses
.back ();
15002 fip
->fields
.emplace_back ();
15003 new_field
= &fip
->fields
.back ();
15008 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15009 if (attr
!= nullptr)
15010 new_field
->accessibility
= DW_UNSND (attr
);
15012 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
15013 if (new_field
->accessibility
!= DW_ACCESS_public
)
15014 fip
->non_public_fields
= 1;
15016 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15017 if (attr
!= nullptr)
15018 new_field
->virtuality
= DW_UNSND (attr
);
15020 new_field
->virtuality
= DW_VIRTUALITY_none
;
15022 fp
= &new_field
->field
;
15024 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
15028 /* Data member other than a C++ static data member. */
15030 /* Get type of field. */
15031 fp
->type
= die_type (die
, cu
);
15033 SET_FIELD_BITPOS (*fp
, 0);
15035 /* Get bit size of field (zero if none). */
15036 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
15037 if (attr
!= nullptr)
15039 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
15043 FIELD_BITSIZE (*fp
) = 0;
15046 /* Get bit offset of field. */
15047 if (handle_data_member_location (die
, cu
, &offset
))
15048 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
15049 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
15050 if (attr
!= nullptr)
15052 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
15054 /* For big endian bits, the DW_AT_bit_offset gives the
15055 additional bit offset from the MSB of the containing
15056 anonymous object to the MSB of the field. We don't
15057 have to do anything special since we don't need to
15058 know the size of the anonymous object. */
15059 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
15063 /* For little endian bits, compute the bit offset to the
15064 MSB of the anonymous object, subtract off the number of
15065 bits from the MSB of the field to the MSB of the
15066 object, and then subtract off the number of bits of
15067 the field itself. The result is the bit offset of
15068 the LSB of the field. */
15069 int anonymous_size
;
15070 int bit_offset
= DW_UNSND (attr
);
15072 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15073 if (attr
!= nullptr)
15075 /* The size of the anonymous object containing
15076 the bit field is explicit, so use the
15077 indicated size (in bytes). */
15078 anonymous_size
= DW_UNSND (attr
);
15082 /* The size of the anonymous object containing
15083 the bit field must be inferred from the type
15084 attribute of the data member containing the
15086 anonymous_size
= TYPE_LENGTH (fp
->type
);
15088 SET_FIELD_BITPOS (*fp
,
15089 (FIELD_BITPOS (*fp
)
15090 + anonymous_size
* bits_per_byte
15091 - bit_offset
- FIELD_BITSIZE (*fp
)));
15094 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
15096 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
15097 + dwarf2_get_attr_constant_value (attr
, 0)));
15099 /* Get name of field. */
15100 fieldname
= dwarf2_name (die
, cu
);
15101 if (fieldname
== NULL
)
15104 /* The name is already allocated along with this objfile, so we don't
15105 need to duplicate it for the type. */
15106 fp
->name
= fieldname
;
15108 /* Change accessibility for artificial fields (e.g. virtual table
15109 pointer or virtual base class pointer) to private. */
15110 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
15112 FIELD_ARTIFICIAL (*fp
) = 1;
15113 new_field
->accessibility
= DW_ACCESS_private
;
15114 fip
->non_public_fields
= 1;
15117 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
15119 /* C++ static member. */
15121 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
15122 is a declaration, but all versions of G++ as of this writing
15123 (so through at least 3.2.1) incorrectly generate
15124 DW_TAG_variable tags. */
15126 const char *physname
;
15128 /* Get name of field. */
15129 fieldname
= dwarf2_name (die
, cu
);
15130 if (fieldname
== NULL
)
15133 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15135 /* Only create a symbol if this is an external value.
15136 new_symbol checks this and puts the value in the global symbol
15137 table, which we want. If it is not external, new_symbol
15138 will try to put the value in cu->list_in_scope which is wrong. */
15139 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
15141 /* A static const member, not much different than an enum as far as
15142 we're concerned, except that we can support more types. */
15143 new_symbol (die
, NULL
, cu
);
15146 /* Get physical name. */
15147 physname
= dwarf2_physname (fieldname
, die
, cu
);
15149 /* The name is already allocated along with this objfile, so we don't
15150 need to duplicate it for the type. */
15151 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
15152 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15153 FIELD_NAME (*fp
) = fieldname
;
15155 else if (die
->tag
== DW_TAG_inheritance
)
15159 /* C++ base class field. */
15160 if (handle_data_member_location (die
, cu
, &offset
))
15161 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
15162 FIELD_BITSIZE (*fp
) = 0;
15163 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15164 FIELD_NAME (*fp
) = TYPE_NAME (fp
->type
);
15166 else if (die
->tag
== DW_TAG_variant_part
)
15168 /* process_structure_scope will treat this DIE as a union. */
15169 process_structure_scope (die
, cu
);
15171 /* The variant part is relative to the start of the enclosing
15173 SET_FIELD_BITPOS (*fp
, 0);
15174 fp
->type
= get_die_type (die
, cu
);
15175 fp
->artificial
= 1;
15176 fp
->name
= "<<variant>>";
15178 /* Normally a DW_TAG_variant_part won't have a size, but our
15179 representation requires one, so set it to the maximum of the
15180 child sizes, being sure to account for the offset at which
15181 each child is seen. */
15182 if (TYPE_LENGTH (fp
->type
) == 0)
15185 for (int i
= 0; i
< TYPE_NFIELDS (fp
->type
); ++i
)
15187 unsigned len
= ((TYPE_FIELD_BITPOS (fp
->type
, i
) + 7) / 8
15188 + TYPE_LENGTH (TYPE_FIELD_TYPE (fp
->type
, i
)));
15192 TYPE_LENGTH (fp
->type
) = max
;
15196 gdb_assert_not_reached ("missing case in dwarf2_add_field");
15199 /* Can the type given by DIE define another type? */
15202 type_can_define_types (const struct die_info
*die
)
15206 case DW_TAG_typedef
:
15207 case DW_TAG_class_type
:
15208 case DW_TAG_structure_type
:
15209 case DW_TAG_union_type
:
15210 case DW_TAG_enumeration_type
:
15218 /* Add a type definition defined in the scope of the FIP's class. */
15221 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
15222 struct dwarf2_cu
*cu
)
15224 struct decl_field fp
;
15225 memset (&fp
, 0, sizeof (fp
));
15227 gdb_assert (type_can_define_types (die
));
15229 /* Get name of field. NULL is okay here, meaning an anonymous type. */
15230 fp
.name
= dwarf2_name (die
, cu
);
15231 fp
.type
= read_type_die (die
, cu
);
15233 /* Save accessibility. */
15234 enum dwarf_access_attribute accessibility
;
15235 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15237 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15239 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15240 switch (accessibility
)
15242 case DW_ACCESS_public
:
15243 /* The assumed value if neither private nor protected. */
15245 case DW_ACCESS_private
:
15248 case DW_ACCESS_protected
:
15249 fp
.is_protected
= 1;
15252 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
15255 if (die
->tag
== DW_TAG_typedef
)
15256 fip
->typedef_field_list
.push_back (fp
);
15258 fip
->nested_types_list
.push_back (fp
);
15261 /* Create the vector of fields, and attach it to the type. */
15264 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
15265 struct dwarf2_cu
*cu
)
15267 int nfields
= fip
->nfields
;
15269 /* Record the field count, allocate space for the array of fields,
15270 and create blank accessibility bitfields if necessary. */
15271 TYPE_NFIELDS (type
) = nfields
;
15272 TYPE_FIELDS (type
) = (struct field
*)
15273 TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
);
15275 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
15277 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15279 TYPE_FIELD_PRIVATE_BITS (type
) =
15280 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15281 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
15283 TYPE_FIELD_PROTECTED_BITS (type
) =
15284 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15285 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
15287 TYPE_FIELD_IGNORE_BITS (type
) =
15288 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15289 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
15292 /* If the type has baseclasses, allocate and clear a bit vector for
15293 TYPE_FIELD_VIRTUAL_BITS. */
15294 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
15296 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
15297 unsigned char *pointer
;
15299 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15300 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
15301 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
15302 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
15303 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
15306 if (TYPE_FLAG_DISCRIMINATED_UNION (type
))
15308 struct discriminant_info
*di
= alloc_discriminant_info (type
, -1, -1);
15310 for (int index
= 0; index
< nfields
; ++index
)
15312 struct nextfield
&field
= fip
->fields
[index
];
15314 if (field
.variant
.is_discriminant
)
15315 di
->discriminant_index
= index
;
15316 else if (field
.variant
.default_branch
)
15317 di
->default_index
= index
;
15319 di
->discriminants
[index
] = field
.variant
.discriminant_value
;
15323 /* Copy the saved-up fields into the field vector. */
15324 for (int i
= 0; i
< nfields
; ++i
)
15326 struct nextfield
&field
15327 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
15328 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
15330 TYPE_FIELD (type
, i
) = field
.field
;
15331 switch (field
.accessibility
)
15333 case DW_ACCESS_private
:
15334 if (cu
->language
!= language_ada
)
15335 SET_TYPE_FIELD_PRIVATE (type
, i
);
15338 case DW_ACCESS_protected
:
15339 if (cu
->language
!= language_ada
)
15340 SET_TYPE_FIELD_PROTECTED (type
, i
);
15343 case DW_ACCESS_public
:
15347 /* Unknown accessibility. Complain and treat it as public. */
15349 complaint (_("unsupported accessibility %d"),
15350 field
.accessibility
);
15354 if (i
< fip
->baseclasses
.size ())
15356 switch (field
.virtuality
)
15358 case DW_VIRTUALITY_virtual
:
15359 case DW_VIRTUALITY_pure_virtual
:
15360 if (cu
->language
== language_ada
)
15361 error (_("unexpected virtuality in component of Ada type"));
15362 SET_TYPE_FIELD_VIRTUAL (type
, i
);
15369 /* Return true if this member function is a constructor, false
15373 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15375 const char *fieldname
;
15376 const char *type_name
;
15379 if (die
->parent
== NULL
)
15382 if (die
->parent
->tag
!= DW_TAG_structure_type
15383 && die
->parent
->tag
!= DW_TAG_union_type
15384 && die
->parent
->tag
!= DW_TAG_class_type
)
15387 fieldname
= dwarf2_name (die
, cu
);
15388 type_name
= dwarf2_name (die
->parent
, cu
);
15389 if (fieldname
== NULL
|| type_name
== NULL
)
15392 len
= strlen (fieldname
);
15393 return (strncmp (fieldname
, type_name
, len
) == 0
15394 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15397 /* Check if the given VALUE is a recognized enum
15398 dwarf_defaulted_attribute constant according to DWARF5 spec,
15402 is_valid_DW_AT_defaulted (ULONGEST value
)
15406 case DW_DEFAULTED_no
:
15407 case DW_DEFAULTED_in_class
:
15408 case DW_DEFAULTED_out_of_class
:
15412 complaint (_("unrecognized DW_AT_defaulted value (%s)"), pulongest (value
));
15416 /* Add a member function to the proper fieldlist. */
15419 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15420 struct type
*type
, struct dwarf2_cu
*cu
)
15422 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15423 struct attribute
*attr
;
15425 struct fnfieldlist
*flp
= nullptr;
15426 struct fn_field
*fnp
;
15427 const char *fieldname
;
15428 struct type
*this_type
;
15429 enum dwarf_access_attribute accessibility
;
15431 if (cu
->language
== language_ada
)
15432 error (_("unexpected member function in Ada type"));
15434 /* Get name of member function. */
15435 fieldname
= dwarf2_name (die
, cu
);
15436 if (fieldname
== NULL
)
15439 /* Look up member function name in fieldlist. */
15440 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15442 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15444 flp
= &fip
->fnfieldlists
[i
];
15449 /* Create a new fnfieldlist if necessary. */
15450 if (flp
== nullptr)
15452 fip
->fnfieldlists
.emplace_back ();
15453 flp
= &fip
->fnfieldlists
.back ();
15454 flp
->name
= fieldname
;
15455 i
= fip
->fnfieldlists
.size () - 1;
15458 /* Create a new member function field and add it to the vector of
15460 flp
->fnfields
.emplace_back ();
15461 fnp
= &flp
->fnfields
.back ();
15463 /* Delay processing of the physname until later. */
15464 if (cu
->language
== language_cplus
)
15465 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15469 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15470 fnp
->physname
= physname
? physname
: "";
15473 fnp
->type
= alloc_type (objfile
);
15474 this_type
= read_type_die (die
, cu
);
15475 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
15477 int nparams
= TYPE_NFIELDS (this_type
);
15479 /* TYPE is the domain of this method, and THIS_TYPE is the type
15480 of the method itself (TYPE_CODE_METHOD). */
15481 smash_to_method_type (fnp
->type
, type
,
15482 TYPE_TARGET_TYPE (this_type
),
15483 TYPE_FIELDS (this_type
),
15484 TYPE_NFIELDS (this_type
),
15485 TYPE_VARARGS (this_type
));
15487 /* Handle static member functions.
15488 Dwarf2 has no clean way to discern C++ static and non-static
15489 member functions. G++ helps GDB by marking the first
15490 parameter for non-static member functions (which is the this
15491 pointer) as artificial. We obtain this information from
15492 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15493 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15494 fnp
->voffset
= VOFFSET_STATIC
;
15497 complaint (_("member function type missing for '%s'"),
15498 dwarf2_full_name (fieldname
, die
, cu
));
15500 /* Get fcontext from DW_AT_containing_type if present. */
15501 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15502 fnp
->fcontext
= die_containing_type (die
, cu
);
15504 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15505 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15507 /* Get accessibility. */
15508 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15509 if (attr
!= nullptr)
15510 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15512 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15513 switch (accessibility
)
15515 case DW_ACCESS_private
:
15516 fnp
->is_private
= 1;
15518 case DW_ACCESS_protected
:
15519 fnp
->is_protected
= 1;
15523 /* Check for artificial methods. */
15524 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15525 if (attr
&& DW_UNSND (attr
) != 0)
15526 fnp
->is_artificial
= 1;
15528 /* Check for defaulted methods. */
15529 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
15530 if (attr
!= nullptr && is_valid_DW_AT_defaulted (DW_UNSND (attr
)))
15531 fnp
->defaulted
= (enum dwarf_defaulted_attribute
) DW_UNSND (attr
);
15533 /* Check for deleted methods. */
15534 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
15535 if (attr
!= nullptr && DW_UNSND (attr
) != 0)
15536 fnp
->is_deleted
= 1;
15538 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15540 /* Get index in virtual function table if it is a virtual member
15541 function. For older versions of GCC, this is an offset in the
15542 appropriate virtual table, as specified by DW_AT_containing_type.
15543 For everyone else, it is an expression to be evaluated relative
15544 to the object address. */
15546 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15547 if (attr
!= nullptr)
15549 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
15551 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
15553 /* Old-style GCC. */
15554 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
15556 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
15557 || (DW_BLOCK (attr
)->size
> 1
15558 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
15559 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
15561 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15562 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15563 dwarf2_complex_location_expr_complaint ();
15565 fnp
->voffset
/= cu
->header
.addr_size
;
15569 dwarf2_complex_location_expr_complaint ();
15571 if (!fnp
->fcontext
)
15573 /* If there is no `this' field and no DW_AT_containing_type,
15574 we cannot actually find a base class context for the
15576 if (TYPE_NFIELDS (this_type
) == 0
15577 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15579 complaint (_("cannot determine context for virtual member "
15580 "function \"%s\" (offset %s)"),
15581 fieldname
, sect_offset_str (die
->sect_off
));
15586 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
15590 else if (attr_form_is_section_offset (attr
))
15592 dwarf2_complex_location_expr_complaint ();
15596 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15602 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15603 if (attr
&& DW_UNSND (attr
))
15605 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15606 complaint (_("Member function \"%s\" (offset %s) is virtual "
15607 "but the vtable offset is not specified"),
15608 fieldname
, sect_offset_str (die
->sect_off
));
15609 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15610 TYPE_CPLUS_DYNAMIC (type
) = 1;
15615 /* Create the vector of member function fields, and attach it to the type. */
15618 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15619 struct dwarf2_cu
*cu
)
15621 if (cu
->language
== language_ada
)
15622 error (_("unexpected member functions in Ada type"));
15624 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15625 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15627 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15629 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15631 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15632 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15634 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15635 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15636 fn_flp
->fn_fields
= (struct fn_field
*)
15637 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15639 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15640 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15643 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15646 /* Returns non-zero if NAME is the name of a vtable member in CU's
15647 language, zero otherwise. */
15649 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15651 static const char vptr
[] = "_vptr";
15653 /* Look for the C++ form of the vtable. */
15654 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15660 /* GCC outputs unnamed structures that are really pointers to member
15661 functions, with the ABI-specified layout. If TYPE describes
15662 such a structure, smash it into a member function type.
15664 GCC shouldn't do this; it should just output pointer to member DIEs.
15665 This is GCC PR debug/28767. */
15668 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15670 struct type
*pfn_type
, *self_type
, *new_type
;
15672 /* Check for a structure with no name and two children. */
15673 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
15676 /* Check for __pfn and __delta members. */
15677 if (TYPE_FIELD_NAME (type
, 0) == NULL
15678 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15679 || TYPE_FIELD_NAME (type
, 1) == NULL
15680 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15683 /* Find the type of the method. */
15684 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
15685 if (pfn_type
== NULL
15686 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
15687 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
15690 /* Look for the "this" argument. */
15691 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15692 if (TYPE_NFIELDS (pfn_type
) == 0
15693 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
15694 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
15697 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
15698 new_type
= alloc_type (objfile
);
15699 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15700 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
15701 TYPE_VARARGS (pfn_type
));
15702 smash_to_methodptr_type (type
, new_type
);
15705 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15706 appropriate error checking and issuing complaints if there is a
15710 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15712 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15714 if (attr
== nullptr)
15717 if (!attr_form_is_constant (attr
))
15719 complaint (_("DW_AT_alignment must have constant form"
15720 " - DIE at %s [in module %s]"),
15721 sect_offset_str (die
->sect_off
),
15722 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15727 if (attr
->form
== DW_FORM_sdata
)
15729 LONGEST val
= DW_SND (attr
);
15732 complaint (_("DW_AT_alignment value must not be negative"
15733 " - DIE at %s [in module %s]"),
15734 sect_offset_str (die
->sect_off
),
15735 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15741 align
= DW_UNSND (attr
);
15745 complaint (_("DW_AT_alignment value must not be zero"
15746 " - DIE at %s [in module %s]"),
15747 sect_offset_str (die
->sect_off
),
15748 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15751 if ((align
& (align
- 1)) != 0)
15753 complaint (_("DW_AT_alignment value must be a power of 2"
15754 " - DIE at %s [in module %s]"),
15755 sect_offset_str (die
->sect_off
),
15756 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15763 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15764 the alignment for TYPE. */
15767 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15770 if (!set_type_align (type
, get_alignment (cu
, die
)))
15771 complaint (_("DW_AT_alignment value too large"
15772 " - DIE at %s [in module %s]"),
15773 sect_offset_str (die
->sect_off
),
15774 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15777 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15778 constant for a type, according to DWARF5 spec, Table 5.5. */
15781 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
15786 case DW_CC_pass_by_reference
:
15787 case DW_CC_pass_by_value
:
15791 complaint (_("unrecognized DW_AT_calling_convention value "
15792 "(%s) for a type"), pulongest (value
));
15797 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15798 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
15799 also according to GNU-specific values (see include/dwarf2.h). */
15802 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
15807 case DW_CC_program
:
15811 case DW_CC_GNU_renesas_sh
:
15812 case DW_CC_GNU_borland_fastcall_i386
:
15813 case DW_CC_GDB_IBM_OpenCL
:
15817 complaint (_("unrecognized DW_AT_calling_convention value "
15818 "(%s) for a subroutine"), pulongest (value
));
15823 /* Called when we find the DIE that starts a structure or union scope
15824 (definition) to create a type for the structure or union. Fill in
15825 the type's name and general properties; the members will not be
15826 processed until process_structure_scope. A symbol table entry for
15827 the type will also not be done until process_structure_scope (assuming
15828 the type has a name).
15830 NOTE: we need to call these functions regardless of whether or not the
15831 DIE has a DW_AT_name attribute, since it might be an anonymous
15832 structure or union. This gets the type entered into our set of
15833 user defined types. */
15835 static struct type
*
15836 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15838 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15840 struct attribute
*attr
;
15843 /* If the definition of this type lives in .debug_types, read that type.
15844 Don't follow DW_AT_specification though, that will take us back up
15845 the chain and we want to go down. */
15846 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
15847 if (attr
!= nullptr)
15849 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15851 /* The type's CU may not be the same as CU.
15852 Ensure TYPE is recorded with CU in die_type_hash. */
15853 return set_die_type (die
, type
, cu
);
15856 type
= alloc_type (objfile
);
15857 INIT_CPLUS_SPECIFIC (type
);
15859 name
= dwarf2_name (die
, cu
);
15862 if (cu
->language
== language_cplus
15863 || cu
->language
== language_d
15864 || cu
->language
== language_rust
)
15866 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15868 /* dwarf2_full_name might have already finished building the DIE's
15869 type. If so, there is no need to continue. */
15870 if (get_die_type (die
, cu
) != NULL
)
15871 return get_die_type (die
, cu
);
15873 TYPE_NAME (type
) = full_name
;
15877 /* The name is already allocated along with this objfile, so
15878 we don't need to duplicate it for the type. */
15879 TYPE_NAME (type
) = name
;
15883 if (die
->tag
== DW_TAG_structure_type
)
15885 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15887 else if (die
->tag
== DW_TAG_union_type
)
15889 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15891 else if (die
->tag
== DW_TAG_variant_part
)
15893 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15894 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
15898 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15901 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15902 TYPE_DECLARED_CLASS (type
) = 1;
15904 /* Store the calling convention in the type if it's available in
15905 the die. Otherwise the calling convention remains set to
15906 the default value DW_CC_normal. */
15907 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15908 if (attr
!= nullptr
15909 && is_valid_DW_AT_calling_convention_for_type (DW_UNSND (attr
)))
15911 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15912 TYPE_CPLUS_CALLING_CONVENTION (type
)
15913 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
15916 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15917 if (attr
!= nullptr)
15919 if (attr_form_is_constant (attr
))
15920 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15923 /* For the moment, dynamic type sizes are not supported
15924 by GDB's struct type. The actual size is determined
15925 on-demand when resolving the type of a given object,
15926 so set the type's length to zero for now. Otherwise,
15927 we record an expression as the length, and that expression
15928 could lead to a very large value, which could eventually
15929 lead to us trying to allocate that much memory when creating
15930 a value of that type. */
15931 TYPE_LENGTH (type
) = 0;
15936 TYPE_LENGTH (type
) = 0;
15939 maybe_set_alignment (cu
, die
, type
);
15941 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15943 /* ICC<14 does not output the required DW_AT_declaration on
15944 incomplete types, but gives them a size of zero. */
15945 TYPE_STUB (type
) = 1;
15948 TYPE_STUB_SUPPORTED (type
) = 1;
15950 if (die_is_declaration (die
, cu
))
15951 TYPE_STUB (type
) = 1;
15952 else if (attr
== NULL
&& die
->child
== NULL
15953 && producer_is_realview (cu
->producer
))
15954 /* RealView does not output the required DW_AT_declaration
15955 on incomplete types. */
15956 TYPE_STUB (type
) = 1;
15958 /* We need to add the type field to the die immediately so we don't
15959 infinitely recurse when dealing with pointers to the structure
15960 type within the structure itself. */
15961 set_die_type (die
, type
, cu
);
15963 /* set_die_type should be already done. */
15964 set_descriptive_type (type
, die
, cu
);
15969 /* A helper for process_structure_scope that handles a single member
15973 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15974 struct field_info
*fi
,
15975 std::vector
<struct symbol
*> *template_args
,
15976 struct dwarf2_cu
*cu
)
15978 if (child_die
->tag
== DW_TAG_member
15979 || child_die
->tag
== DW_TAG_variable
15980 || child_die
->tag
== DW_TAG_variant_part
)
15982 /* NOTE: carlton/2002-11-05: A C++ static data member
15983 should be a DW_TAG_member that is a declaration, but
15984 all versions of G++ as of this writing (so through at
15985 least 3.2.1) incorrectly generate DW_TAG_variable
15986 tags for them instead. */
15987 dwarf2_add_field (fi
, child_die
, cu
);
15989 else if (child_die
->tag
== DW_TAG_subprogram
)
15991 /* Rust doesn't have member functions in the C++ sense.
15992 However, it does emit ordinary functions as children
15993 of a struct DIE. */
15994 if (cu
->language
== language_rust
)
15995 read_func_scope (child_die
, cu
);
15998 /* C++ member function. */
15999 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
16002 else if (child_die
->tag
== DW_TAG_inheritance
)
16004 /* C++ base class field. */
16005 dwarf2_add_field (fi
, child_die
, cu
);
16007 else if (type_can_define_types (child_die
))
16008 dwarf2_add_type_defn (fi
, child_die
, cu
);
16009 else if (child_die
->tag
== DW_TAG_template_type_param
16010 || child_die
->tag
== DW_TAG_template_value_param
)
16012 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
16015 template_args
->push_back (arg
);
16017 else if (child_die
->tag
== DW_TAG_variant
)
16019 /* In a variant we want to get the discriminant and also add a
16020 field for our sole member child. */
16021 struct attribute
*discr
= dwarf2_attr (child_die
, DW_AT_discr_value
, cu
);
16023 for (die_info
*variant_child
= child_die
->child
;
16024 variant_child
!= NULL
;
16025 variant_child
= sibling_die (variant_child
))
16027 if (variant_child
->tag
== DW_TAG_member
)
16029 handle_struct_member_die (variant_child
, type
, fi
,
16030 template_args
, cu
);
16031 /* Only handle the one. */
16036 /* We don't handle this but we might as well report it if we see
16038 if (dwarf2_attr (child_die
, DW_AT_discr_list
, cu
) != nullptr)
16039 complaint (_("DW_AT_discr_list is not supported yet"
16040 " - DIE at %s [in module %s]"),
16041 sect_offset_str (child_die
->sect_off
),
16042 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16044 /* The first field was just added, so we can stash the
16045 discriminant there. */
16046 gdb_assert (!fi
->fields
.empty ());
16048 fi
->fields
.back ().variant
.default_branch
= true;
16050 fi
->fields
.back ().variant
.discriminant_value
= DW_UNSND (discr
);
16054 /* Finish creating a structure or union type, including filling in
16055 its members and creating a symbol for it. */
16058 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16060 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16061 struct die_info
*child_die
;
16064 type
= get_die_type (die
, cu
);
16066 type
= read_structure_type (die
, cu
);
16068 /* When reading a DW_TAG_variant_part, we need to notice when we
16069 read the discriminant member, so we can record it later in the
16070 discriminant_info. */
16071 bool is_variant_part
= TYPE_FLAG_DISCRIMINATED_UNION (type
);
16072 sect_offset discr_offset
{};
16073 bool has_template_parameters
= false;
16075 if (is_variant_part
)
16077 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
16080 /* Maybe it's a univariant form, an extension we support.
16081 In this case arrange not to check the offset. */
16082 is_variant_part
= false;
16084 else if (attr_form_is_ref (discr
))
16086 struct dwarf2_cu
*target_cu
= cu
;
16087 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
16089 discr_offset
= target_die
->sect_off
;
16093 complaint (_("DW_AT_discr does not have DIE reference form"
16094 " - DIE at %s [in module %s]"),
16095 sect_offset_str (die
->sect_off
),
16096 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16097 is_variant_part
= false;
16101 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
16103 struct field_info fi
;
16104 std::vector
<struct symbol
*> template_args
;
16106 child_die
= die
->child
;
16108 while (child_die
&& child_die
->tag
)
16110 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
16112 if (is_variant_part
&& discr_offset
== child_die
->sect_off
)
16113 fi
.fields
.back ().variant
.is_discriminant
= true;
16115 child_die
= sibling_die (child_die
);
16118 /* Attach template arguments to type. */
16119 if (!template_args
.empty ())
16121 has_template_parameters
= true;
16122 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16123 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
16124 TYPE_TEMPLATE_ARGUMENTS (type
)
16125 = XOBNEWVEC (&objfile
->objfile_obstack
,
16127 TYPE_N_TEMPLATE_ARGUMENTS (type
));
16128 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
16129 template_args
.data (),
16130 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
16131 * sizeof (struct symbol
*)));
16134 /* Attach fields and member functions to the type. */
16136 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
16137 if (!fi
.fnfieldlists
.empty ())
16139 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
16141 /* Get the type which refers to the base class (possibly this
16142 class itself) which contains the vtable pointer for the current
16143 class from the DW_AT_containing_type attribute. This use of
16144 DW_AT_containing_type is a GNU extension. */
16146 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
16148 struct type
*t
= die_containing_type (die
, cu
);
16150 set_type_vptr_basetype (type
, t
);
16155 /* Our own class provides vtbl ptr. */
16156 for (i
= TYPE_NFIELDS (t
) - 1;
16157 i
>= TYPE_N_BASECLASSES (t
);
16160 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
16162 if (is_vtable_name (fieldname
, cu
))
16164 set_type_vptr_fieldno (type
, i
);
16169 /* Complain if virtual function table field not found. */
16170 if (i
< TYPE_N_BASECLASSES (t
))
16171 complaint (_("virtual function table pointer "
16172 "not found when defining class '%s'"),
16173 TYPE_NAME (type
) ? TYPE_NAME (type
) : "");
16177 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
16180 else if (cu
->producer
16181 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
16183 /* The IBM XLC compiler does not provide direct indication
16184 of the containing type, but the vtable pointer is
16185 always named __vfp. */
16189 for (i
= TYPE_NFIELDS (type
) - 1;
16190 i
>= TYPE_N_BASECLASSES (type
);
16193 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
16195 set_type_vptr_fieldno (type
, i
);
16196 set_type_vptr_basetype (type
, type
);
16203 /* Copy fi.typedef_field_list linked list elements content into the
16204 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
16205 if (!fi
.typedef_field_list
.empty ())
16207 int count
= fi
.typedef_field_list
.size ();
16209 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16210 TYPE_TYPEDEF_FIELD_ARRAY (type
)
16211 = ((struct decl_field
*)
16213 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
16214 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
16216 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
16217 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
16220 /* Copy fi.nested_types_list linked list elements content into the
16221 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
16222 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
16224 int count
= fi
.nested_types_list
.size ();
16226 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16227 TYPE_NESTED_TYPES_ARRAY (type
)
16228 = ((struct decl_field
*)
16229 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
16230 TYPE_NESTED_TYPES_COUNT (type
) = count
;
16232 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
16233 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
16237 quirk_gcc_member_function_pointer (type
, objfile
);
16238 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
16239 cu
->rust_unions
.push_back (type
);
16241 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
16242 snapshots) has been known to create a die giving a declaration
16243 for a class that has, as a child, a die giving a definition for a
16244 nested class. So we have to process our children even if the
16245 current die is a declaration. Normally, of course, a declaration
16246 won't have any children at all. */
16248 child_die
= die
->child
;
16250 while (child_die
!= NULL
&& child_die
->tag
)
16252 if (child_die
->tag
== DW_TAG_member
16253 || child_die
->tag
== DW_TAG_variable
16254 || child_die
->tag
== DW_TAG_inheritance
16255 || child_die
->tag
== DW_TAG_template_value_param
16256 || child_die
->tag
== DW_TAG_template_type_param
)
16261 process_die (child_die
, cu
);
16263 child_die
= sibling_die (child_die
);
16266 /* Do not consider external references. According to the DWARF standard,
16267 these DIEs are identified by the fact that they have no byte_size
16268 attribute, and a declaration attribute. */
16269 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
16270 || !die_is_declaration (die
, cu
))
16272 struct symbol
*sym
= new_symbol (die
, type
, cu
);
16274 if (has_template_parameters
)
16276 struct symtab
*symtab
;
16277 if (sym
!= nullptr)
16278 symtab
= symbol_symtab (sym
);
16279 else if (cu
->line_header
!= nullptr)
16281 /* Any related symtab will do. */
16283 = cu
->line_header
->file_names ()[0].symtab
;
16288 complaint (_("could not find suitable "
16289 "symtab for template parameter"
16290 " - DIE at %s [in module %s]"),
16291 sect_offset_str (die
->sect_off
),
16292 objfile_name (objfile
));
16295 if (symtab
!= nullptr)
16297 /* Make sure that the symtab is set on the new symbols.
16298 Even though they don't appear in this symtab directly,
16299 other parts of gdb assume that symbols do, and this is
16300 reasonably true. */
16301 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
16302 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
16308 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
16309 update TYPE using some information only available in DIE's children. */
16312 update_enumeration_type_from_children (struct die_info
*die
,
16314 struct dwarf2_cu
*cu
)
16316 struct die_info
*child_die
;
16317 int unsigned_enum
= 1;
16321 auto_obstack obstack
;
16323 for (child_die
= die
->child
;
16324 child_die
!= NULL
&& child_die
->tag
;
16325 child_die
= sibling_die (child_die
))
16327 struct attribute
*attr
;
16329 const gdb_byte
*bytes
;
16330 struct dwarf2_locexpr_baton
*baton
;
16333 if (child_die
->tag
!= DW_TAG_enumerator
)
16336 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16340 name
= dwarf2_name (child_die
, cu
);
16342 name
= "<anonymous enumerator>";
16344 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16345 &value
, &bytes
, &baton
);
16351 else if ((mask
& value
) != 0)
16356 /* If we already know that the enum type is neither unsigned, nor
16357 a flag type, no need to look at the rest of the enumerates. */
16358 if (!unsigned_enum
&& !flag_enum
)
16363 TYPE_UNSIGNED (type
) = 1;
16365 TYPE_FLAG_ENUM (type
) = 1;
16368 /* Given a DW_AT_enumeration_type die, set its type. We do not
16369 complete the type's fields yet, or create any symbols. */
16371 static struct type
*
16372 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16374 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16376 struct attribute
*attr
;
16379 /* If the definition of this type lives in .debug_types, read that type.
16380 Don't follow DW_AT_specification though, that will take us back up
16381 the chain and we want to go down. */
16382 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
16383 if (attr
!= nullptr)
16385 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16387 /* The type's CU may not be the same as CU.
16388 Ensure TYPE is recorded with CU in die_type_hash. */
16389 return set_die_type (die
, type
, cu
);
16392 type
= alloc_type (objfile
);
16394 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
16395 name
= dwarf2_full_name (NULL
, die
, cu
);
16397 TYPE_NAME (type
) = name
;
16399 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16402 struct type
*underlying_type
= die_type (die
, cu
);
16404 TYPE_TARGET_TYPE (type
) = underlying_type
;
16407 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16408 if (attr
!= nullptr)
16410 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16414 TYPE_LENGTH (type
) = 0;
16417 maybe_set_alignment (cu
, die
, type
);
16419 /* The enumeration DIE can be incomplete. In Ada, any type can be
16420 declared as private in the package spec, and then defined only
16421 inside the package body. Such types are known as Taft Amendment
16422 Types. When another package uses such a type, an incomplete DIE
16423 may be generated by the compiler. */
16424 if (die_is_declaration (die
, cu
))
16425 TYPE_STUB (type
) = 1;
16427 /* Finish the creation of this type by using the enum's children.
16428 We must call this even when the underlying type has been provided
16429 so that we can determine if we're looking at a "flag" enum. */
16430 update_enumeration_type_from_children (die
, type
, cu
);
16432 /* If this type has an underlying type that is not a stub, then we
16433 may use its attributes. We always use the "unsigned" attribute
16434 in this situation, because ordinarily we guess whether the type
16435 is unsigned -- but the guess can be wrong and the underlying type
16436 can tell us the reality. However, we defer to a local size
16437 attribute if one exists, because this lets the compiler override
16438 the underlying type if needed. */
16439 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
16441 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
16442 if (TYPE_LENGTH (type
) == 0)
16443 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
16444 if (TYPE_RAW_ALIGN (type
) == 0
16445 && TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)) != 0)
16446 set_type_align (type
, TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)));
16449 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16451 return set_die_type (die
, type
, cu
);
16454 /* Given a pointer to a die which begins an enumeration, process all
16455 the dies that define the members of the enumeration, and create the
16456 symbol for the enumeration type.
16458 NOTE: We reverse the order of the element list. */
16461 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16463 struct type
*this_type
;
16465 this_type
= get_die_type (die
, cu
);
16466 if (this_type
== NULL
)
16467 this_type
= read_enumeration_type (die
, cu
);
16469 if (die
->child
!= NULL
)
16471 struct die_info
*child_die
;
16472 struct symbol
*sym
;
16473 std::vector
<struct field
> fields
;
16476 child_die
= die
->child
;
16477 while (child_die
&& child_die
->tag
)
16479 if (child_die
->tag
!= DW_TAG_enumerator
)
16481 process_die (child_die
, cu
);
16485 name
= dwarf2_name (child_die
, cu
);
16488 sym
= new_symbol (child_die
, this_type
, cu
);
16490 fields
.emplace_back ();
16491 struct field
&field
= fields
.back ();
16493 FIELD_NAME (field
) = sym
->linkage_name ();
16494 FIELD_TYPE (field
) = NULL
;
16495 SET_FIELD_ENUMVAL (field
, SYMBOL_VALUE (sym
));
16496 FIELD_BITSIZE (field
) = 0;
16500 child_die
= sibling_die (child_die
);
16503 if (!fields
.empty ())
16505 TYPE_NFIELDS (this_type
) = fields
.size ();
16506 TYPE_FIELDS (this_type
) = (struct field
*)
16507 TYPE_ALLOC (this_type
, sizeof (struct field
) * fields
.size ());
16508 memcpy (TYPE_FIELDS (this_type
), fields
.data (),
16509 sizeof (struct field
) * fields
.size ());
16513 /* If we are reading an enum from a .debug_types unit, and the enum
16514 is a declaration, and the enum is not the signatured type in the
16515 unit, then we do not want to add a symbol for it. Adding a
16516 symbol would in some cases obscure the true definition of the
16517 enum, giving users an incomplete type when the definition is
16518 actually available. Note that we do not want to do this for all
16519 enums which are just declarations, because C++0x allows forward
16520 enum declarations. */
16521 if (cu
->per_cu
->is_debug_types
16522 && die_is_declaration (die
, cu
))
16524 struct signatured_type
*sig_type
;
16526 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16527 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16528 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16532 new_symbol (die
, this_type
, cu
);
16535 /* Extract all information from a DW_TAG_array_type DIE and put it in
16536 the DIE's type field. For now, this only handles one dimensional
16539 static struct type
*
16540 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16542 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16543 struct die_info
*child_die
;
16545 struct type
*element_type
, *range_type
, *index_type
;
16546 struct attribute
*attr
;
16548 struct dynamic_prop
*byte_stride_prop
= NULL
;
16549 unsigned int bit_stride
= 0;
16551 element_type
= die_type (die
, cu
);
16553 /* The die_type call above may have already set the type for this DIE. */
16554 type
= get_die_type (die
, cu
);
16558 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16562 struct type
*prop_type
16563 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
16566 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16567 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
16571 complaint (_("unable to read array DW_AT_byte_stride "
16572 " - DIE at %s [in module %s]"),
16573 sect_offset_str (die
->sect_off
),
16574 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16575 /* Ignore this attribute. We will likely not be able to print
16576 arrays of this type correctly, but there is little we can do
16577 to help if we cannot read the attribute's value. */
16578 byte_stride_prop
= NULL
;
16582 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16584 bit_stride
= DW_UNSND (attr
);
16586 /* Irix 6.2 native cc creates array types without children for
16587 arrays with unspecified length. */
16588 if (die
->child
== NULL
)
16590 index_type
= objfile_type (objfile
)->builtin_int
;
16591 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16592 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16593 byte_stride_prop
, bit_stride
);
16594 return set_die_type (die
, type
, cu
);
16597 std::vector
<struct type
*> range_types
;
16598 child_die
= die
->child
;
16599 while (child_die
&& child_die
->tag
)
16601 if (child_die
->tag
== DW_TAG_subrange_type
)
16603 struct type
*child_type
= read_type_die (child_die
, cu
);
16605 if (child_type
!= NULL
)
16607 /* The range type was succesfully read. Save it for the
16608 array type creation. */
16609 range_types
.push_back (child_type
);
16612 child_die
= sibling_die (child_die
);
16615 /* Dwarf2 dimensions are output from left to right, create the
16616 necessary array types in backwards order. */
16618 type
= element_type
;
16620 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16624 while (i
< range_types
.size ())
16625 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16626 byte_stride_prop
, bit_stride
);
16630 size_t ndim
= range_types
.size ();
16632 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16633 byte_stride_prop
, bit_stride
);
16636 /* Understand Dwarf2 support for vector types (like they occur on
16637 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16638 array type. This is not part of the Dwarf2/3 standard yet, but a
16639 custom vendor extension. The main difference between a regular
16640 array and the vector variant is that vectors are passed by value
16642 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16643 if (attr
!= nullptr)
16644 make_vector_type (type
);
16646 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16647 implementation may choose to implement triple vectors using this
16649 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16650 if (attr
!= nullptr)
16652 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
16653 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16655 complaint (_("DW_AT_byte_size for array type smaller "
16656 "than the total size of elements"));
16659 name
= dwarf2_name (die
, cu
);
16661 TYPE_NAME (type
) = name
;
16663 maybe_set_alignment (cu
, die
, type
);
16665 /* Install the type in the die. */
16666 set_die_type (die
, type
, cu
);
16668 /* set_die_type should be already done. */
16669 set_descriptive_type (type
, die
, cu
);
16674 static enum dwarf_array_dim_ordering
16675 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16677 struct attribute
*attr
;
16679 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16681 if (attr
!= nullptr)
16682 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
16684 /* GNU F77 is a special case, as at 08/2004 array type info is the
16685 opposite order to the dwarf2 specification, but data is still
16686 laid out as per normal fortran.
16688 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16689 version checking. */
16691 if (cu
->language
== language_fortran
16692 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16694 return DW_ORD_row_major
;
16697 switch (cu
->language_defn
->la_array_ordering
)
16699 case array_column_major
:
16700 return DW_ORD_col_major
;
16701 case array_row_major
:
16703 return DW_ORD_row_major
;
16707 /* Extract all information from a DW_TAG_set_type DIE and put it in
16708 the DIE's type field. */
16710 static struct type
*
16711 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16713 struct type
*domain_type
, *set_type
;
16714 struct attribute
*attr
;
16716 domain_type
= die_type (die
, cu
);
16718 /* The die_type call above may have already set the type for this DIE. */
16719 set_type
= get_die_type (die
, cu
);
16723 set_type
= create_set_type (NULL
, domain_type
);
16725 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16726 if (attr
!= nullptr)
16727 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
16729 maybe_set_alignment (cu
, die
, set_type
);
16731 return set_die_type (die
, set_type
, cu
);
16734 /* A helper for read_common_block that creates a locexpr baton.
16735 SYM is the symbol which we are marking as computed.
16736 COMMON_DIE is the DIE for the common block.
16737 COMMON_LOC is the location expression attribute for the common
16739 MEMBER_LOC is the location expression attribute for the particular
16740 member of the common block that we are processing.
16741 CU is the CU from which the above come. */
16744 mark_common_block_symbol_computed (struct symbol
*sym
,
16745 struct die_info
*common_die
,
16746 struct attribute
*common_loc
,
16747 struct attribute
*member_loc
,
16748 struct dwarf2_cu
*cu
)
16750 struct dwarf2_per_objfile
*dwarf2_per_objfile
16751 = cu
->per_cu
->dwarf2_per_objfile
;
16752 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16753 struct dwarf2_locexpr_baton
*baton
;
16755 unsigned int cu_off
;
16756 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
16757 LONGEST offset
= 0;
16759 gdb_assert (common_loc
&& member_loc
);
16760 gdb_assert (attr_form_is_block (common_loc
));
16761 gdb_assert (attr_form_is_block (member_loc
)
16762 || attr_form_is_constant (member_loc
));
16764 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16765 baton
->per_cu
= cu
->per_cu
;
16766 gdb_assert (baton
->per_cu
);
16768 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16770 if (attr_form_is_constant (member_loc
))
16772 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
16773 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16776 baton
->size
+= DW_BLOCK (member_loc
)->size
;
16778 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16781 *ptr
++ = DW_OP_call4
;
16782 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16783 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16786 if (attr_form_is_constant (member_loc
))
16788 *ptr
++ = DW_OP_addr
;
16789 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16790 ptr
+= cu
->header
.addr_size
;
16794 /* We have to copy the data here, because DW_OP_call4 will only
16795 use a DW_AT_location attribute. */
16796 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
16797 ptr
+= DW_BLOCK (member_loc
)->size
;
16800 *ptr
++ = DW_OP_plus
;
16801 gdb_assert (ptr
- baton
->data
== baton
->size
);
16803 SYMBOL_LOCATION_BATON (sym
) = baton
;
16804 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16807 /* Create appropriate locally-scoped variables for all the
16808 DW_TAG_common_block entries. Also create a struct common_block
16809 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16810 is used to separate the common blocks name namespace from regular
16814 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16816 struct attribute
*attr
;
16818 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16819 if (attr
!= nullptr)
16821 /* Support the .debug_loc offsets. */
16822 if (attr_form_is_block (attr
))
16826 else if (attr_form_is_section_offset (attr
))
16828 dwarf2_complex_location_expr_complaint ();
16833 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16834 "common block member");
16839 if (die
->child
!= NULL
)
16841 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16842 struct die_info
*child_die
;
16843 size_t n_entries
= 0, size
;
16844 struct common_block
*common_block
;
16845 struct symbol
*sym
;
16847 for (child_die
= die
->child
;
16848 child_die
&& child_die
->tag
;
16849 child_die
= sibling_die (child_die
))
16852 size
= (sizeof (struct common_block
)
16853 + (n_entries
- 1) * sizeof (struct symbol
*));
16855 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16857 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16858 common_block
->n_entries
= 0;
16860 for (child_die
= die
->child
;
16861 child_die
&& child_die
->tag
;
16862 child_die
= sibling_die (child_die
))
16864 /* Create the symbol in the DW_TAG_common_block block in the current
16866 sym
= new_symbol (child_die
, NULL
, cu
);
16869 struct attribute
*member_loc
;
16871 common_block
->contents
[common_block
->n_entries
++] = sym
;
16873 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16877 /* GDB has handled this for a long time, but it is
16878 not specified by DWARF. It seems to have been
16879 emitted by gfortran at least as recently as:
16880 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16881 complaint (_("Variable in common block has "
16882 "DW_AT_data_member_location "
16883 "- DIE at %s [in module %s]"),
16884 sect_offset_str (child_die
->sect_off
),
16885 objfile_name (objfile
));
16887 if (attr_form_is_section_offset (member_loc
))
16888 dwarf2_complex_location_expr_complaint ();
16889 else if (attr_form_is_constant (member_loc
)
16890 || attr_form_is_block (member_loc
))
16892 if (attr
!= nullptr)
16893 mark_common_block_symbol_computed (sym
, die
, attr
,
16897 dwarf2_complex_location_expr_complaint ();
16902 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16903 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16907 /* Create a type for a C++ namespace. */
16909 static struct type
*
16910 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16912 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16913 const char *previous_prefix
, *name
;
16917 /* For extensions, reuse the type of the original namespace. */
16918 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16920 struct die_info
*ext_die
;
16921 struct dwarf2_cu
*ext_cu
= cu
;
16923 ext_die
= dwarf2_extension (die
, &ext_cu
);
16924 type
= read_type_die (ext_die
, ext_cu
);
16926 /* EXT_CU may not be the same as CU.
16927 Ensure TYPE is recorded with CU in die_type_hash. */
16928 return set_die_type (die
, type
, cu
);
16931 name
= namespace_name (die
, &is_anonymous
, cu
);
16933 /* Now build the name of the current namespace. */
16935 previous_prefix
= determine_prefix (die
, cu
);
16936 if (previous_prefix
[0] != '\0')
16937 name
= typename_concat (&objfile
->objfile_obstack
,
16938 previous_prefix
, name
, 0, cu
);
16940 /* Create the type. */
16941 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16943 return set_die_type (die
, type
, cu
);
16946 /* Read a namespace scope. */
16949 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16951 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16954 /* Add a symbol associated to this if we haven't seen the namespace
16955 before. Also, add a using directive if it's an anonymous
16958 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16962 type
= read_type_die (die
, cu
);
16963 new_symbol (die
, type
, cu
);
16965 namespace_name (die
, &is_anonymous
, cu
);
16968 const char *previous_prefix
= determine_prefix (die
, cu
);
16970 std::vector
<const char *> excludes
;
16971 add_using_directive (using_directives (cu
),
16972 previous_prefix
, TYPE_NAME (type
), NULL
,
16973 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16977 if (die
->child
!= NULL
)
16979 struct die_info
*child_die
= die
->child
;
16981 while (child_die
&& child_die
->tag
)
16983 process_die (child_die
, cu
);
16984 child_die
= sibling_die (child_die
);
16989 /* Read a Fortran module as type. This DIE can be only a declaration used for
16990 imported module. Still we need that type as local Fortran "use ... only"
16991 declaration imports depend on the created type in determine_prefix. */
16993 static struct type
*
16994 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16996 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16997 const char *module_name
;
17000 module_name
= dwarf2_name (die
, cu
);
17001 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
17003 return set_die_type (die
, type
, cu
);
17006 /* Read a Fortran module. */
17009 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
17011 struct die_info
*child_die
= die
->child
;
17014 type
= read_type_die (die
, cu
);
17015 new_symbol (die
, type
, cu
);
17017 while (child_die
&& child_die
->tag
)
17019 process_die (child_die
, cu
);
17020 child_die
= sibling_die (child_die
);
17024 /* Return the name of the namespace represented by DIE. Set
17025 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
17028 static const char *
17029 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
17031 struct die_info
*current_die
;
17032 const char *name
= NULL
;
17034 /* Loop through the extensions until we find a name. */
17036 for (current_die
= die
;
17037 current_die
!= NULL
;
17038 current_die
= dwarf2_extension (die
, &cu
))
17040 /* We don't use dwarf2_name here so that we can detect the absence
17041 of a name -> anonymous namespace. */
17042 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
17048 /* Is it an anonymous namespace? */
17050 *is_anonymous
= (name
== NULL
);
17052 name
= CP_ANONYMOUS_NAMESPACE_STR
;
17057 /* Extract all information from a DW_TAG_pointer_type DIE and add to
17058 the user defined type vector. */
17060 static struct type
*
17061 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17063 struct gdbarch
*gdbarch
17064 = get_objfile_arch (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
17065 struct comp_unit_head
*cu_header
= &cu
->header
;
17067 struct attribute
*attr_byte_size
;
17068 struct attribute
*attr_address_class
;
17069 int byte_size
, addr_class
;
17070 struct type
*target_type
;
17072 target_type
= die_type (die
, cu
);
17074 /* The die_type call above may have already set the type for this DIE. */
17075 type
= get_die_type (die
, cu
);
17079 type
= lookup_pointer_type (target_type
);
17081 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17082 if (attr_byte_size
)
17083 byte_size
= DW_UNSND (attr_byte_size
);
17085 byte_size
= cu_header
->addr_size
;
17087 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
17088 if (attr_address_class
)
17089 addr_class
= DW_UNSND (attr_address_class
);
17091 addr_class
= DW_ADDR_none
;
17093 ULONGEST alignment
= get_alignment (cu
, die
);
17095 /* If the pointer size, alignment, or address class is different
17096 than the default, create a type variant marked as such and set
17097 the length accordingly. */
17098 if (TYPE_LENGTH (type
) != byte_size
17099 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
17100 && alignment
!= TYPE_RAW_ALIGN (type
))
17101 || addr_class
!= DW_ADDR_none
)
17103 if (gdbarch_address_class_type_flags_p (gdbarch
))
17107 type_flags
= gdbarch_address_class_type_flags
17108 (gdbarch
, byte_size
, addr_class
);
17109 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
17111 type
= make_type_with_address_space (type
, type_flags
);
17113 else if (TYPE_LENGTH (type
) != byte_size
)
17115 complaint (_("invalid pointer size %d"), byte_size
);
17117 else if (TYPE_RAW_ALIGN (type
) != alignment
)
17119 complaint (_("Invalid DW_AT_alignment"
17120 " - DIE at %s [in module %s]"),
17121 sect_offset_str (die
->sect_off
),
17122 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17126 /* Should we also complain about unhandled address classes? */
17130 TYPE_LENGTH (type
) = byte_size
;
17131 set_type_align (type
, alignment
);
17132 return set_die_type (die
, type
, cu
);
17135 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
17136 the user defined type vector. */
17138 static struct type
*
17139 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17142 struct type
*to_type
;
17143 struct type
*domain
;
17145 to_type
= die_type (die
, cu
);
17146 domain
= die_containing_type (die
, cu
);
17148 /* The calls above may have already set the type for this DIE. */
17149 type
= get_die_type (die
, cu
);
17153 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
17154 type
= lookup_methodptr_type (to_type
);
17155 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
17157 struct type
*new_type
17158 = alloc_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
17160 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
17161 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
17162 TYPE_VARARGS (to_type
));
17163 type
= lookup_methodptr_type (new_type
);
17166 type
= lookup_memberptr_type (to_type
, domain
);
17168 return set_die_type (die
, type
, cu
);
17171 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
17172 the user defined type vector. */
17174 static struct type
*
17175 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17176 enum type_code refcode
)
17178 struct comp_unit_head
*cu_header
= &cu
->header
;
17179 struct type
*type
, *target_type
;
17180 struct attribute
*attr
;
17182 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
17184 target_type
= die_type (die
, cu
);
17186 /* The die_type call above may have already set the type for this DIE. */
17187 type
= get_die_type (die
, cu
);
17191 type
= lookup_reference_type (target_type
, refcode
);
17192 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17193 if (attr
!= nullptr)
17195 TYPE_LENGTH (type
) = DW_UNSND (attr
);
17199 TYPE_LENGTH (type
) = cu_header
->addr_size
;
17201 maybe_set_alignment (cu
, die
, type
);
17202 return set_die_type (die
, type
, cu
);
17205 /* Add the given cv-qualifiers to the element type of the array. GCC
17206 outputs DWARF type qualifiers that apply to an array, not the
17207 element type. But GDB relies on the array element type to carry
17208 the cv-qualifiers. This mimics section 6.7.3 of the C99
17211 static struct type
*
17212 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17213 struct type
*base_type
, int cnst
, int voltl
)
17215 struct type
*el_type
, *inner_array
;
17217 base_type
= copy_type (base_type
);
17218 inner_array
= base_type
;
17220 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
17222 TYPE_TARGET_TYPE (inner_array
) =
17223 copy_type (TYPE_TARGET_TYPE (inner_array
));
17224 inner_array
= TYPE_TARGET_TYPE (inner_array
);
17227 el_type
= TYPE_TARGET_TYPE (inner_array
);
17228 cnst
|= TYPE_CONST (el_type
);
17229 voltl
|= TYPE_VOLATILE (el_type
);
17230 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
17232 return set_die_type (die
, base_type
, cu
);
17235 static struct type
*
17236 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17238 struct type
*base_type
, *cv_type
;
17240 base_type
= die_type (die
, cu
);
17242 /* The die_type call above may have already set the type for this DIE. */
17243 cv_type
= get_die_type (die
, cu
);
17247 /* In case the const qualifier is applied to an array type, the element type
17248 is so qualified, not the array type (section 6.7.3 of C99). */
17249 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
17250 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
17252 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
17253 return set_die_type (die
, cv_type
, cu
);
17256 static struct type
*
17257 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17259 struct type
*base_type
, *cv_type
;
17261 base_type
= die_type (die
, cu
);
17263 /* The die_type call above may have already set the type for this DIE. */
17264 cv_type
= get_die_type (die
, cu
);
17268 /* In case the volatile qualifier is applied to an array type, the
17269 element type is so qualified, not the array type (section 6.7.3
17271 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
17272 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17274 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17275 return set_die_type (die
, cv_type
, cu
);
17278 /* Handle DW_TAG_restrict_type. */
17280 static struct type
*
17281 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17283 struct type
*base_type
, *cv_type
;
17285 base_type
= die_type (die
, cu
);
17287 /* The die_type call above may have already set the type for this DIE. */
17288 cv_type
= get_die_type (die
, cu
);
17292 cv_type
= make_restrict_type (base_type
);
17293 return set_die_type (die
, cv_type
, cu
);
17296 /* Handle DW_TAG_atomic_type. */
17298 static struct type
*
17299 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17301 struct type
*base_type
, *cv_type
;
17303 base_type
= die_type (die
, cu
);
17305 /* The die_type call above may have already set the type for this DIE. */
17306 cv_type
= get_die_type (die
, cu
);
17310 cv_type
= make_atomic_type (base_type
);
17311 return set_die_type (die
, cv_type
, cu
);
17314 /* Extract all information from a DW_TAG_string_type DIE and add to
17315 the user defined type vector. It isn't really a user defined type,
17316 but it behaves like one, with other DIE's using an AT_user_def_type
17317 attribute to reference it. */
17319 static struct type
*
17320 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17322 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17323 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17324 struct type
*type
, *range_type
, *index_type
, *char_type
;
17325 struct attribute
*attr
;
17326 struct dynamic_prop prop
;
17327 bool length_is_constant
= true;
17330 /* There are a couple of places where bit sizes might be made use of
17331 when parsing a DW_TAG_string_type, however, no producer that we know
17332 of make use of these. Handling bit sizes that are a multiple of the
17333 byte size is easy enough, but what about other bit sizes? Lets deal
17334 with that problem when we have to. Warn about these attributes being
17335 unsupported, then parse the type and ignore them like we always
17337 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
17338 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
17340 static bool warning_printed
= false;
17341 if (!warning_printed
)
17343 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
17344 "currently supported on DW_TAG_string_type."));
17345 warning_printed
= true;
17349 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17350 if (attr
!= nullptr && !attr_form_is_constant (attr
))
17352 /* The string length describes the location at which the length of
17353 the string can be found. The size of the length field can be
17354 specified with one of the attributes below. */
17355 struct type
*prop_type
;
17356 struct attribute
*len
17357 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
17358 if (len
== nullptr)
17359 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17360 if (len
!= nullptr && attr_form_is_constant (len
))
17362 /* Pass 0 as the default as we know this attribute is constant
17363 and the default value will not be returned. */
17364 LONGEST sz
= dwarf2_get_attr_constant_value (len
, 0);
17365 prop_type
= dwarf2_per_cu_int_type (cu
->per_cu
, sz
, true);
17369 /* If the size is not specified then we assume it is the size of
17370 an address on this target. */
17371 prop_type
= dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, true);
17374 /* Convert the attribute into a dynamic property. */
17375 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
17378 length_is_constant
= false;
17380 else if (attr
!= nullptr)
17382 /* This DW_AT_string_length just contains the length with no
17383 indirection. There's no need to create a dynamic property in this
17384 case. Pass 0 for the default value as we know it will not be
17385 returned in this case. */
17386 length
= dwarf2_get_attr_constant_value (attr
, 0);
17388 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
17390 /* We don't currently support non-constant byte sizes for strings. */
17391 length
= dwarf2_get_attr_constant_value (attr
, 1);
17395 /* Use 1 as a fallback length if we have nothing else. */
17399 index_type
= objfile_type (objfile
)->builtin_int
;
17400 if (length_is_constant
)
17401 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17404 struct dynamic_prop low_bound
;
17406 low_bound
.kind
= PROP_CONST
;
17407 low_bound
.data
.const_val
= 1;
17408 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
17410 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17411 type
= create_string_type (NULL
, char_type
, range_type
);
17413 return set_die_type (die
, type
, cu
);
17416 /* Assuming that DIE corresponds to a function, returns nonzero
17417 if the function is prototyped. */
17420 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17422 struct attribute
*attr
;
17424 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17425 if (attr
&& (DW_UNSND (attr
) != 0))
17428 /* The DWARF standard implies that the DW_AT_prototyped attribute
17429 is only meaningful for C, but the concept also extends to other
17430 languages that allow unprototyped functions (Eg: Objective C).
17431 For all other languages, assume that functions are always
17433 if (cu
->language
!= language_c
17434 && cu
->language
!= language_objc
17435 && cu
->language
!= language_opencl
)
17438 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17439 prototyped and unprototyped functions; default to prototyped,
17440 since that is more common in modern code (and RealView warns
17441 about unprototyped functions). */
17442 if (producer_is_realview (cu
->producer
))
17448 /* Handle DIES due to C code like:
17452 int (*funcp)(int a, long l);
17456 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17458 static struct type
*
17459 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17461 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17462 struct type
*type
; /* Type that this function returns. */
17463 struct type
*ftype
; /* Function that returns above type. */
17464 struct attribute
*attr
;
17466 type
= die_type (die
, cu
);
17468 /* The die_type call above may have already set the type for this DIE. */
17469 ftype
= get_die_type (die
, cu
);
17473 ftype
= lookup_function_type (type
);
17475 if (prototyped_function_p (die
, cu
))
17476 TYPE_PROTOTYPED (ftype
) = 1;
17478 /* Store the calling convention in the type if it's available in
17479 the subroutine die. Otherwise set the calling convention to
17480 the default value DW_CC_normal. */
17481 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17482 if (attr
!= nullptr
17483 && is_valid_DW_AT_calling_convention_for_subroutine (DW_UNSND (attr
)))
17484 TYPE_CALLING_CONVENTION (ftype
)
17485 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
17486 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17487 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17489 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17491 /* Record whether the function returns normally to its caller or not
17492 if the DWARF producer set that information. */
17493 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17494 if (attr
&& (DW_UNSND (attr
) != 0))
17495 TYPE_NO_RETURN (ftype
) = 1;
17497 /* We need to add the subroutine type to the die immediately so
17498 we don't infinitely recurse when dealing with parameters
17499 declared as the same subroutine type. */
17500 set_die_type (die
, ftype
, cu
);
17502 if (die
->child
!= NULL
)
17504 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17505 struct die_info
*child_die
;
17506 int nparams
, iparams
;
17508 /* Count the number of parameters.
17509 FIXME: GDB currently ignores vararg functions, but knows about
17510 vararg member functions. */
17512 child_die
= die
->child
;
17513 while (child_die
&& child_die
->tag
)
17515 if (child_die
->tag
== DW_TAG_formal_parameter
)
17517 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17518 TYPE_VARARGS (ftype
) = 1;
17519 child_die
= sibling_die (child_die
);
17522 /* Allocate storage for parameters and fill them in. */
17523 TYPE_NFIELDS (ftype
) = nparams
;
17524 TYPE_FIELDS (ftype
) = (struct field
*)
17525 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
17527 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17528 even if we error out during the parameters reading below. */
17529 for (iparams
= 0; iparams
< nparams
; iparams
++)
17530 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
17533 child_die
= die
->child
;
17534 while (child_die
&& child_die
->tag
)
17536 if (child_die
->tag
== DW_TAG_formal_parameter
)
17538 struct type
*arg_type
;
17540 /* DWARF version 2 has no clean way to discern C++
17541 static and non-static member functions. G++ helps
17542 GDB by marking the first parameter for non-static
17543 member functions (which is the this pointer) as
17544 artificial. We pass this information to
17545 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17547 DWARF version 3 added DW_AT_object_pointer, which GCC
17548 4.5 does not yet generate. */
17549 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17550 if (attr
!= nullptr)
17551 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
17553 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17554 arg_type
= die_type (child_die
, cu
);
17556 /* RealView does not mark THIS as const, which the testsuite
17557 expects. GCC marks THIS as const in method definitions,
17558 but not in the class specifications (GCC PR 43053). */
17559 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17560 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17563 struct dwarf2_cu
*arg_cu
= cu
;
17564 const char *name
= dwarf2_name (child_die
, cu
);
17566 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17567 if (attr
!= nullptr)
17569 /* If the compiler emits this, use it. */
17570 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17573 else if (name
&& strcmp (name
, "this") == 0)
17574 /* Function definitions will have the argument names. */
17576 else if (name
== NULL
&& iparams
== 0)
17577 /* Declarations may not have the names, so like
17578 elsewhere in GDB, assume an artificial first
17579 argument is "this". */
17583 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17587 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
17590 child_die
= sibling_die (child_die
);
17597 static struct type
*
17598 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17600 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17601 const char *name
= NULL
;
17602 struct type
*this_type
, *target_type
;
17604 name
= dwarf2_full_name (NULL
, die
, cu
);
17605 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17606 TYPE_TARGET_STUB (this_type
) = 1;
17607 set_die_type (die
, this_type
, cu
);
17608 target_type
= die_type (die
, cu
);
17609 if (target_type
!= this_type
)
17610 TYPE_TARGET_TYPE (this_type
) = target_type
;
17613 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17614 spec and cause infinite loops in GDB. */
17615 complaint (_("Self-referential DW_TAG_typedef "
17616 "- DIE at %s [in module %s]"),
17617 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17618 TYPE_TARGET_TYPE (this_type
) = NULL
;
17623 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17624 (which may be different from NAME) to the architecture back-end to allow
17625 it to guess the correct format if necessary. */
17627 static struct type
*
17628 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17629 const char *name_hint
, enum bfd_endian byte_order
)
17631 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17632 const struct floatformat
**format
;
17635 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17637 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
17639 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17644 /* Allocate an integer type of size BITS and name NAME. */
17646 static struct type
*
17647 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
17648 int bits
, int unsigned_p
, const char *name
)
17652 /* Versions of Intel's C Compiler generate an integer type called "void"
17653 instead of using DW_TAG_unspecified_type. This has been seen on
17654 at least versions 14, 17, and 18. */
17655 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
17656 && strcmp (name
, "void") == 0)
17657 type
= objfile_type (objfile
)->builtin_void
;
17659 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
17664 /* Initialise and return a floating point type of size BITS suitable for
17665 use as a component of a complex number. The NAME_HINT is passed through
17666 when initialising the floating point type and is the name of the complex
17669 As DWARF doesn't currently provide an explicit name for the components
17670 of a complex number, but it can be helpful to have these components
17671 named, we try to select a suitable name based on the size of the
17673 static struct type
*
17674 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
17675 struct objfile
*objfile
,
17676 int bits
, const char *name_hint
,
17677 enum bfd_endian byte_order
)
17679 gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17680 struct type
*tt
= nullptr;
17682 /* Try to find a suitable floating point builtin type of size BITS.
17683 We're going to use the name of this type as the name for the complex
17684 target type that we are about to create. */
17685 switch (cu
->language
)
17687 case language_fortran
:
17691 tt
= builtin_f_type (gdbarch
)->builtin_real
;
17694 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
17696 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17698 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
17706 tt
= builtin_type (gdbarch
)->builtin_float
;
17709 tt
= builtin_type (gdbarch
)->builtin_double
;
17711 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17713 tt
= builtin_type (gdbarch
)->builtin_long_double
;
17719 /* If the type we found doesn't match the size we were looking for, then
17720 pretend we didn't find a type at all, the complex target type we
17721 create will then be nameless. */
17722 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
17725 const char *name
= (tt
== nullptr) ? nullptr : TYPE_NAME (tt
);
17726 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
17729 /* Find a representation of a given base type and install
17730 it in the TYPE field of the die. */
17732 static struct type
*
17733 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17735 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17737 struct attribute
*attr
;
17738 int encoding
= 0, bits
= 0;
17742 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17743 if (attr
!= nullptr)
17744 encoding
= DW_UNSND (attr
);
17745 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17746 if (attr
!= nullptr)
17747 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
17748 name
= dwarf2_name (die
, cu
);
17750 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
17752 arch
= get_objfile_arch (objfile
);
17753 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
17755 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
17758 int endianity
= DW_UNSND (attr
);
17763 byte_order
= BFD_ENDIAN_BIG
;
17765 case DW_END_little
:
17766 byte_order
= BFD_ENDIAN_LITTLE
;
17769 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
17776 case DW_ATE_address
:
17777 /* Turn DW_ATE_address into a void * pointer. */
17778 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
17779 type
= init_pointer_type (objfile
, bits
, name
, type
);
17781 case DW_ATE_boolean
:
17782 type
= init_boolean_type (objfile
, bits
, 1, name
);
17784 case DW_ATE_complex_float
:
17785 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
17787 type
= init_complex_type (objfile
, name
, type
);
17789 case DW_ATE_decimal_float
:
17790 type
= init_decfloat_type (objfile
, bits
, name
);
17793 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
17795 case DW_ATE_signed
:
17796 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17798 case DW_ATE_unsigned
:
17799 if (cu
->language
== language_fortran
17801 && startswith (name
, "character("))
17802 type
= init_character_type (objfile
, bits
, 1, name
);
17804 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17806 case DW_ATE_signed_char
:
17807 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17808 || cu
->language
== language_pascal
17809 || cu
->language
== language_fortran
)
17810 type
= init_character_type (objfile
, bits
, 0, name
);
17812 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17814 case DW_ATE_unsigned_char
:
17815 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17816 || cu
->language
== language_pascal
17817 || cu
->language
== language_fortran
17818 || cu
->language
== language_rust
)
17819 type
= init_character_type (objfile
, bits
, 1, name
);
17821 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17826 type
= builtin_type (arch
)->builtin_char16
;
17827 else if (bits
== 32)
17828 type
= builtin_type (arch
)->builtin_char32
;
17831 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
17833 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17835 return set_die_type (die
, type
, cu
);
17840 complaint (_("unsupported DW_AT_encoding: '%s'"),
17841 dwarf_type_encoding_name (encoding
));
17842 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17846 if (name
&& strcmp (name
, "char") == 0)
17847 TYPE_NOSIGN (type
) = 1;
17849 maybe_set_alignment (cu
, die
, type
);
17851 TYPE_ENDIANITY_NOT_DEFAULT (type
) = gdbarch_byte_order (arch
) != byte_order
;
17853 return set_die_type (die
, type
, cu
);
17856 /* Parse dwarf attribute if it's a block, reference or constant and put the
17857 resulting value of the attribute into struct bound_prop.
17858 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17861 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17862 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
17863 struct type
*default_type
)
17865 struct dwarf2_property_baton
*baton
;
17866 struct obstack
*obstack
17867 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
17869 gdb_assert (default_type
!= NULL
);
17871 if (attr
== NULL
|| prop
== NULL
)
17874 if (attr_form_is_block (attr
))
17876 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17877 baton
->property_type
= default_type
;
17878 baton
->locexpr
.per_cu
= cu
->per_cu
;
17879 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17880 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17881 switch (attr
->name
)
17883 case DW_AT_string_length
:
17884 baton
->locexpr
.is_reference
= true;
17887 baton
->locexpr
.is_reference
= false;
17890 prop
->data
.baton
= baton
;
17891 prop
->kind
= PROP_LOCEXPR
;
17892 gdb_assert (prop
->data
.baton
!= NULL
);
17894 else if (attr_form_is_ref (attr
))
17896 struct dwarf2_cu
*target_cu
= cu
;
17897 struct die_info
*target_die
;
17898 struct attribute
*target_attr
;
17900 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17901 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17902 if (target_attr
== NULL
)
17903 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17905 if (target_attr
== NULL
)
17908 switch (target_attr
->name
)
17910 case DW_AT_location
:
17911 if (attr_form_is_section_offset (target_attr
))
17913 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17914 baton
->property_type
= die_type (target_die
, target_cu
);
17915 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17916 prop
->data
.baton
= baton
;
17917 prop
->kind
= PROP_LOCLIST
;
17918 gdb_assert (prop
->data
.baton
!= NULL
);
17920 else if (attr_form_is_block (target_attr
))
17922 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17923 baton
->property_type
= die_type (target_die
, target_cu
);
17924 baton
->locexpr
.per_cu
= cu
->per_cu
;
17925 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17926 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17927 baton
->locexpr
.is_reference
= true;
17928 prop
->data
.baton
= baton
;
17929 prop
->kind
= PROP_LOCEXPR
;
17930 gdb_assert (prop
->data
.baton
!= NULL
);
17934 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17935 "dynamic property");
17939 case DW_AT_data_member_location
:
17943 if (!handle_data_member_location (target_die
, target_cu
,
17947 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17948 baton
->property_type
= read_type_die (target_die
->parent
,
17950 baton
->offset_info
.offset
= offset
;
17951 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17952 prop
->data
.baton
= baton
;
17953 prop
->kind
= PROP_ADDR_OFFSET
;
17958 else if (attr_form_is_constant (attr
))
17960 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
17961 prop
->kind
= PROP_CONST
;
17965 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17966 dwarf2_name (die
, cu
));
17973 /* Find an integer type SIZE_IN_BYTES bytes in size and return it.
17974 UNSIGNED_P controls if the integer is unsigned or not. */
17976 static struct type
*
17977 dwarf2_per_cu_int_type (struct dwarf2_per_cu_data
*per_cu
,
17978 int size_in_bytes
, bool unsigned_p
)
17980 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
17981 struct type
*int_type
;
17983 /* Helper macro to examine the various builtin types. */
17984 #define TRY_TYPE(F) \
17985 int_type = (unsigned_p \
17986 ? objfile_type (objfile)->builtin_unsigned_ ## F \
17987 : objfile_type (objfile)->builtin_ ## F); \
17988 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
17995 TRY_TYPE (long_long
);
17999 gdb_assert_not_reached ("unable to find suitable integer type");
18002 /* Find an integer type the same size as the address size given in the
18003 compilation unit header for PER_CU. UNSIGNED_P controls if the integer
18004 is unsigned or not. */
18006 static struct type
*
18007 dwarf2_per_cu_addr_sized_int_type (struct dwarf2_per_cu_data
*per_cu
,
18010 int addr_size
= dwarf2_per_cu_addr_size (per_cu
);
18011 return dwarf2_per_cu_int_type (per_cu
, addr_size
, unsigned_p
);
18014 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
18015 present (which is valid) then compute the default type based on the
18016 compilation units address size. */
18018 static struct type
*
18019 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18021 struct type
*index_type
= die_type (die
, cu
);
18023 /* Dwarf-2 specifications explicitly allows to create subrange types
18024 without specifying a base type.
18025 In that case, the base type must be set to the type of
18026 the lower bound, upper bound or count, in that order, if any of these
18027 three attributes references an object that has a type.
18028 If no base type is found, the Dwarf-2 specifications say that
18029 a signed integer type of size equal to the size of an address should
18031 For the following C code: `extern char gdb_int [];'
18032 GCC produces an empty range DIE.
18033 FIXME: muller/2010-05-28: Possible references to object for low bound,
18034 high bound or count are not yet handled by this code. */
18035 if (TYPE_CODE (index_type
) == TYPE_CODE_VOID
)
18036 index_type
= dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
18041 /* Read the given DW_AT_subrange DIE. */
18043 static struct type
*
18044 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18046 struct type
*base_type
, *orig_base_type
;
18047 struct type
*range_type
;
18048 struct attribute
*attr
;
18049 struct dynamic_prop low
, high
;
18050 int low_default_is_valid
;
18051 int high_bound_is_count
= 0;
18053 ULONGEST negative_mask
;
18055 orig_base_type
= read_subrange_index_type (die
, cu
);
18057 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
18058 whereas the real type might be. So, we use ORIG_BASE_TYPE when
18059 creating the range type, but we use the result of check_typedef
18060 when examining properties of the type. */
18061 base_type
= check_typedef (orig_base_type
);
18063 /* The die_type call above may have already set the type for this DIE. */
18064 range_type
= get_die_type (die
, cu
);
18068 low
.kind
= PROP_CONST
;
18069 high
.kind
= PROP_CONST
;
18070 high
.data
.const_val
= 0;
18072 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
18073 omitting DW_AT_lower_bound. */
18074 switch (cu
->language
)
18077 case language_cplus
:
18078 low
.data
.const_val
= 0;
18079 low_default_is_valid
= 1;
18081 case language_fortran
:
18082 low
.data
.const_val
= 1;
18083 low_default_is_valid
= 1;
18086 case language_objc
:
18087 case language_rust
:
18088 low
.data
.const_val
= 0;
18089 low_default_is_valid
= (cu
->header
.version
>= 4);
18093 case language_pascal
:
18094 low
.data
.const_val
= 1;
18095 low_default_is_valid
= (cu
->header
.version
>= 4);
18098 low
.data
.const_val
= 0;
18099 low_default_is_valid
= 0;
18103 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
18104 if (attr
!= nullptr)
18105 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
18106 else if (!low_default_is_valid
)
18107 complaint (_("Missing DW_AT_lower_bound "
18108 "- DIE at %s [in module %s]"),
18109 sect_offset_str (die
->sect_off
),
18110 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
18112 struct attribute
*attr_ub
, *attr_count
;
18113 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
18114 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18116 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
18117 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18119 /* If bounds are constant do the final calculation here. */
18120 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
18121 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
18123 high_bound_is_count
= 1;
18127 if (attr_ub
!= NULL
)
18128 complaint (_("Unresolved DW_AT_upper_bound "
18129 "- DIE at %s [in module %s]"),
18130 sect_offset_str (die
->sect_off
),
18131 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
18132 if (attr_count
!= NULL
)
18133 complaint (_("Unresolved DW_AT_count "
18134 "- DIE at %s [in module %s]"),
18135 sect_offset_str (die
->sect_off
),
18136 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
18141 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
18142 if (bias_attr
!= nullptr && attr_form_is_constant (bias_attr
))
18143 bias
= dwarf2_get_attr_constant_value (bias_attr
, 0);
18145 /* Normally, the DWARF producers are expected to use a signed
18146 constant form (Eg. DW_FORM_sdata) to express negative bounds.
18147 But this is unfortunately not always the case, as witnessed
18148 with GCC, for instance, where the ambiguous DW_FORM_dataN form
18149 is used instead. To work around that ambiguity, we treat
18150 the bounds as signed, and thus sign-extend their values, when
18151 the base type is signed. */
18153 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
18154 if (low
.kind
== PROP_CONST
18155 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
18156 low
.data
.const_val
|= negative_mask
;
18157 if (high
.kind
== PROP_CONST
18158 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
18159 high
.data
.const_val
|= negative_mask
;
18161 /* Check for bit and byte strides. */
18162 struct dynamic_prop byte_stride_prop
;
18163 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
18164 if (attr_byte_stride
!= nullptr)
18166 struct type
*prop_type
18167 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
18168 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
18172 struct dynamic_prop bit_stride_prop
;
18173 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
18174 if (attr_bit_stride
!= nullptr)
18176 /* It only makes sense to have either a bit or byte stride. */
18177 if (attr_byte_stride
!= nullptr)
18179 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
18180 "- DIE at %s [in module %s]"),
18181 sect_offset_str (die
->sect_off
),
18182 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
18183 attr_bit_stride
= nullptr;
18187 struct type
*prop_type
18188 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
18189 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
18194 if (attr_byte_stride
!= nullptr
18195 || attr_bit_stride
!= nullptr)
18197 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
18198 struct dynamic_prop
*stride
18199 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
18202 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
18203 &high
, bias
, stride
, byte_stride_p
);
18206 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
18208 if (high_bound_is_count
)
18209 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
18211 /* Ada expects an empty array on no boundary attributes. */
18212 if (attr
== NULL
&& cu
->language
!= language_ada
)
18213 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
18215 name
= dwarf2_name (die
, cu
);
18217 TYPE_NAME (range_type
) = name
;
18219 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18220 if (attr
!= nullptr)
18221 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
18223 maybe_set_alignment (cu
, die
, range_type
);
18225 set_die_type (die
, range_type
, cu
);
18227 /* set_die_type should be already done. */
18228 set_descriptive_type (range_type
, die
, cu
);
18233 static struct type
*
18234 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18238 type
= init_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
, TYPE_CODE_VOID
,0,
18240 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
18242 /* In Ada, an unspecified type is typically used when the description
18243 of the type is deferred to a different unit. When encountering
18244 such a type, we treat it as a stub, and try to resolve it later on,
18246 if (cu
->language
== language_ada
)
18247 TYPE_STUB (type
) = 1;
18249 return set_die_type (die
, type
, cu
);
18252 /* Read a single die and all its descendents. Set the die's sibling
18253 field to NULL; set other fields in the die correctly, and set all
18254 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
18255 location of the info_ptr after reading all of those dies. PARENT
18256 is the parent of the die in question. */
18258 static struct die_info
*
18259 read_die_and_children (const struct die_reader_specs
*reader
,
18260 const gdb_byte
*info_ptr
,
18261 const gdb_byte
**new_info_ptr
,
18262 struct die_info
*parent
)
18264 struct die_info
*die
;
18265 const gdb_byte
*cur_ptr
;
18268 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, &has_children
, 0);
18271 *new_info_ptr
= cur_ptr
;
18274 store_in_ref_table (die
, reader
->cu
);
18277 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
18281 *new_info_ptr
= cur_ptr
;
18284 die
->sibling
= NULL
;
18285 die
->parent
= parent
;
18289 /* Read a die, all of its descendents, and all of its siblings; set
18290 all of the fields of all of the dies correctly. Arguments are as
18291 in read_die_and_children. */
18293 static struct die_info
*
18294 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
18295 const gdb_byte
*info_ptr
,
18296 const gdb_byte
**new_info_ptr
,
18297 struct die_info
*parent
)
18299 struct die_info
*first_die
, *last_sibling
;
18300 const gdb_byte
*cur_ptr
;
18302 cur_ptr
= info_ptr
;
18303 first_die
= last_sibling
= NULL
;
18307 struct die_info
*die
18308 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
18312 *new_info_ptr
= cur_ptr
;
18319 last_sibling
->sibling
= die
;
18321 last_sibling
= die
;
18325 /* Read a die, all of its descendents, and all of its siblings; set
18326 all of the fields of all of the dies correctly. Arguments are as
18327 in read_die_and_children.
18328 This the main entry point for reading a DIE and all its children. */
18330 static struct die_info
*
18331 read_die_and_siblings (const struct die_reader_specs
*reader
,
18332 const gdb_byte
*info_ptr
,
18333 const gdb_byte
**new_info_ptr
,
18334 struct die_info
*parent
)
18336 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
18337 new_info_ptr
, parent
);
18339 if (dwarf_die_debug
)
18341 fprintf_unfiltered (gdb_stdlog
,
18342 "Read die from %s@0x%x of %s:\n",
18343 get_section_name (reader
->die_section
),
18344 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18345 bfd_get_filename (reader
->abfd
));
18346 dump_die (die
, dwarf_die_debug
);
18352 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
18354 The caller is responsible for filling in the extra attributes
18355 and updating (*DIEP)->num_attrs.
18356 Set DIEP to point to a newly allocated die with its information,
18357 except for its child, sibling, and parent fields.
18358 Set HAS_CHILDREN to tell whether the die has children or not. */
18360 static const gdb_byte
*
18361 read_full_die_1 (const struct die_reader_specs
*reader
,
18362 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18363 int *has_children
, int num_extra_attrs
)
18365 unsigned int abbrev_number
, bytes_read
, i
;
18366 struct abbrev_info
*abbrev
;
18367 struct die_info
*die
;
18368 struct dwarf2_cu
*cu
= reader
->cu
;
18369 bfd
*abfd
= reader
->abfd
;
18371 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
18372 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18373 info_ptr
+= bytes_read
;
18374 if (!abbrev_number
)
18381 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
18383 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
18385 bfd_get_filename (abfd
));
18387 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
18388 die
->sect_off
= sect_off
;
18389 die
->tag
= abbrev
->tag
;
18390 die
->abbrev
= abbrev_number
;
18392 /* Make the result usable.
18393 The caller needs to update num_attrs after adding the extra
18395 die
->num_attrs
= abbrev
->num_attrs
;
18397 std::vector
<int> indexes_that_need_reprocess
;
18398 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18400 bool need_reprocess
;
18402 read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
18403 info_ptr
, &need_reprocess
);
18404 if (need_reprocess
)
18405 indexes_that_need_reprocess
.push_back (i
);
18408 struct attribute
*attr
= dwarf2_attr_no_follow (die
, DW_AT_str_offsets_base
);
18409 if (attr
!= nullptr)
18410 cu
->str_offsets_base
= DW_UNSND (attr
);
18412 auto maybe_addr_base
= lookup_addr_base(die
);
18413 if (maybe_addr_base
.has_value ())
18414 cu
->addr_base
= *maybe_addr_base
;
18415 for (int index
: indexes_that_need_reprocess
)
18416 read_attribute_reprocess (reader
, &die
->attrs
[index
]);
18418 *has_children
= abbrev
->has_children
;
18422 /* Read a die and all its attributes.
18423 Set DIEP to point to a newly allocated die with its information,
18424 except for its child, sibling, and parent fields.
18425 Set HAS_CHILDREN to tell whether the die has children or not. */
18427 static const gdb_byte
*
18428 read_full_die (const struct die_reader_specs
*reader
,
18429 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18432 const gdb_byte
*result
;
18434 result
= read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
18436 if (dwarf_die_debug
)
18438 fprintf_unfiltered (gdb_stdlog
,
18439 "Read die from %s@0x%x of %s:\n",
18440 get_section_name (reader
->die_section
),
18441 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18442 bfd_get_filename (reader
->abfd
));
18443 dump_die (*diep
, dwarf_die_debug
);
18449 /* Abbreviation tables.
18451 In DWARF version 2, the description of the debugging information is
18452 stored in a separate .debug_abbrev section. Before we read any
18453 dies from a section we read in all abbreviations and install them
18454 in a hash table. */
18456 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
18458 struct abbrev_info
*
18459 abbrev_table::alloc_abbrev ()
18461 struct abbrev_info
*abbrev
;
18463 abbrev
= XOBNEW (&abbrev_obstack
, struct abbrev_info
);
18464 memset (abbrev
, 0, sizeof (struct abbrev_info
));
18469 /* Add an abbreviation to the table. */
18472 abbrev_table::add_abbrev (unsigned int abbrev_number
,
18473 struct abbrev_info
*abbrev
)
18475 unsigned int hash_number
;
18477 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
18478 abbrev
->next
= m_abbrevs
[hash_number
];
18479 m_abbrevs
[hash_number
] = abbrev
;
18482 /* Look up an abbrev in the table.
18483 Returns NULL if the abbrev is not found. */
18485 struct abbrev_info
*
18486 abbrev_table::lookup_abbrev (unsigned int abbrev_number
)
18488 unsigned int hash_number
;
18489 struct abbrev_info
*abbrev
;
18491 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
18492 abbrev
= m_abbrevs
[hash_number
];
18496 if (abbrev
->number
== abbrev_number
)
18498 abbrev
= abbrev
->next
;
18503 /* Read in an abbrev table. */
18505 static abbrev_table_up
18506 abbrev_table_read_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18507 struct dwarf2_section_info
*section
,
18508 sect_offset sect_off
)
18510 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18511 bfd
*abfd
= get_section_bfd_owner (section
);
18512 const gdb_byte
*abbrev_ptr
;
18513 struct abbrev_info
*cur_abbrev
;
18514 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
18515 unsigned int abbrev_form
;
18516 std::vector
<struct attr_abbrev
> cur_attrs
;
18518 abbrev_table_up
abbrev_table (new struct abbrev_table (sect_off
));
18520 dwarf2_read_section (objfile
, section
);
18521 abbrev_ptr
= section
->buffer
+ to_underlying (sect_off
);
18522 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18523 abbrev_ptr
+= bytes_read
;
18525 /* Loop until we reach an abbrev number of 0. */
18526 while (abbrev_number
)
18528 cur_attrs
.clear ();
18529 cur_abbrev
= abbrev_table
->alloc_abbrev ();
18531 /* read in abbrev header */
18532 cur_abbrev
->number
= abbrev_number
;
18534 = (enum dwarf_tag
) read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18535 abbrev_ptr
+= bytes_read
;
18536 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
18539 /* now read in declarations */
18542 LONGEST implicit_const
;
18544 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18545 abbrev_ptr
+= bytes_read
;
18546 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18547 abbrev_ptr
+= bytes_read
;
18548 if (abbrev_form
== DW_FORM_implicit_const
)
18550 implicit_const
= read_signed_leb128 (abfd
, abbrev_ptr
,
18552 abbrev_ptr
+= bytes_read
;
18556 /* Initialize it due to a false compiler warning. */
18557 implicit_const
= -1;
18560 if (abbrev_name
== 0)
18563 cur_attrs
.emplace_back ();
18564 struct attr_abbrev
&cur_attr
= cur_attrs
.back ();
18565 cur_attr
.name
= (enum dwarf_attribute
) abbrev_name
;
18566 cur_attr
.form
= (enum dwarf_form
) abbrev_form
;
18567 cur_attr
.implicit_const
= implicit_const
;
18568 ++cur_abbrev
->num_attrs
;
18571 cur_abbrev
->attrs
=
18572 XOBNEWVEC (&abbrev_table
->abbrev_obstack
, struct attr_abbrev
,
18573 cur_abbrev
->num_attrs
);
18574 memcpy (cur_abbrev
->attrs
, cur_attrs
.data (),
18575 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
18577 abbrev_table
->add_abbrev (abbrev_number
, cur_abbrev
);
18579 /* Get next abbreviation.
18580 Under Irix6 the abbreviations for a compilation unit are not
18581 always properly terminated with an abbrev number of 0.
18582 Exit loop if we encounter an abbreviation which we have
18583 already read (which means we are about to read the abbreviations
18584 for the next compile unit) or if the end of the abbreviation
18585 table is reached. */
18586 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
18588 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18589 abbrev_ptr
+= bytes_read
;
18590 if (abbrev_table
->lookup_abbrev (abbrev_number
) != NULL
)
18594 return abbrev_table
;
18597 /* Returns nonzero if TAG represents a type that we might generate a partial
18601 is_type_tag_for_partial (int tag
)
18606 /* Some types that would be reasonable to generate partial symbols for,
18607 that we don't at present. */
18608 case DW_TAG_array_type
:
18609 case DW_TAG_file_type
:
18610 case DW_TAG_ptr_to_member_type
:
18611 case DW_TAG_set_type
:
18612 case DW_TAG_string_type
:
18613 case DW_TAG_subroutine_type
:
18615 case DW_TAG_base_type
:
18616 case DW_TAG_class_type
:
18617 case DW_TAG_interface_type
:
18618 case DW_TAG_enumeration_type
:
18619 case DW_TAG_structure_type
:
18620 case DW_TAG_subrange_type
:
18621 case DW_TAG_typedef
:
18622 case DW_TAG_union_type
:
18629 /* Load all DIEs that are interesting for partial symbols into memory. */
18631 static struct partial_die_info
*
18632 load_partial_dies (const struct die_reader_specs
*reader
,
18633 const gdb_byte
*info_ptr
, int building_psymtab
)
18635 struct dwarf2_cu
*cu
= reader
->cu
;
18636 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18637 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18638 unsigned int bytes_read
;
18639 unsigned int load_all
= 0;
18640 int nesting_level
= 1;
18645 gdb_assert (cu
->per_cu
!= NULL
);
18646 if (cu
->per_cu
->load_all_dies
)
18650 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18654 &cu
->comp_unit_obstack
,
18655 hashtab_obstack_allocate
,
18656 dummy_obstack_deallocate
);
18660 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
18662 /* A NULL abbrev means the end of a series of children. */
18663 if (abbrev
== NULL
)
18665 if (--nesting_level
== 0)
18668 info_ptr
+= bytes_read
;
18669 last_die
= parent_die
;
18670 parent_die
= parent_die
->die_parent
;
18674 /* Check for template arguments. We never save these; if
18675 they're seen, we just mark the parent, and go on our way. */
18676 if (parent_die
!= NULL
18677 && cu
->language
== language_cplus
18678 && (abbrev
->tag
== DW_TAG_template_type_param
18679 || abbrev
->tag
== DW_TAG_template_value_param
))
18681 parent_die
->has_template_arguments
= 1;
18685 /* We don't need a partial DIE for the template argument. */
18686 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18691 /* We only recurse into c++ subprograms looking for template arguments.
18692 Skip their other children. */
18694 && cu
->language
== language_cplus
18695 && parent_die
!= NULL
18696 && parent_die
->tag
== DW_TAG_subprogram
)
18698 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18702 /* Check whether this DIE is interesting enough to save. Normally
18703 we would not be interested in members here, but there may be
18704 later variables referencing them via DW_AT_specification (for
18705 static members). */
18707 && !is_type_tag_for_partial (abbrev
->tag
)
18708 && abbrev
->tag
!= DW_TAG_constant
18709 && abbrev
->tag
!= DW_TAG_enumerator
18710 && abbrev
->tag
!= DW_TAG_subprogram
18711 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18712 && abbrev
->tag
!= DW_TAG_lexical_block
18713 && abbrev
->tag
!= DW_TAG_variable
18714 && abbrev
->tag
!= DW_TAG_namespace
18715 && abbrev
->tag
!= DW_TAG_module
18716 && abbrev
->tag
!= DW_TAG_member
18717 && abbrev
->tag
!= DW_TAG_imported_unit
18718 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18720 /* Otherwise we skip to the next sibling, if any. */
18721 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18725 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
18728 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
18730 /* This two-pass algorithm for processing partial symbols has a
18731 high cost in cache pressure. Thus, handle some simple cases
18732 here which cover the majority of C partial symbols. DIEs
18733 which neither have specification tags in them, nor could have
18734 specification tags elsewhere pointing at them, can simply be
18735 processed and discarded.
18737 This segment is also optional; scan_partial_symbols and
18738 add_partial_symbol will handle these DIEs if we chain
18739 them in normally. When compilers which do not emit large
18740 quantities of duplicate debug information are more common,
18741 this code can probably be removed. */
18743 /* Any complete simple types at the top level (pretty much all
18744 of them, for a language without namespaces), can be processed
18746 if (parent_die
== NULL
18747 && pdi
.has_specification
== 0
18748 && pdi
.is_declaration
== 0
18749 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
18750 || pdi
.tag
== DW_TAG_base_type
18751 || pdi
.tag
== DW_TAG_subrange_type
))
18753 if (building_psymtab
&& pdi
.name
!= NULL
)
18754 add_psymbol_to_list (pdi
.name
, false,
18755 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
18756 psymbol_placement::STATIC
,
18757 0, cu
->language
, objfile
);
18758 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18762 /* The exception for DW_TAG_typedef with has_children above is
18763 a workaround of GCC PR debug/47510. In the case of this complaint
18764 type_name_or_error will error on such types later.
18766 GDB skipped children of DW_TAG_typedef by the shortcut above and then
18767 it could not find the child DIEs referenced later, this is checked
18768 above. In correct DWARF DW_TAG_typedef should have no children. */
18770 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
18771 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
18772 "- DIE at %s [in module %s]"),
18773 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
18775 /* If we're at the second level, and we're an enumerator, and
18776 our parent has no specification (meaning possibly lives in a
18777 namespace elsewhere), then we can add the partial symbol now
18778 instead of queueing it. */
18779 if (pdi
.tag
== DW_TAG_enumerator
18780 && parent_die
!= NULL
18781 && parent_die
->die_parent
== NULL
18782 && parent_die
->tag
== DW_TAG_enumeration_type
18783 && parent_die
->has_specification
== 0)
18785 if (pdi
.name
== NULL
)
18786 complaint (_("malformed enumerator DIE ignored"));
18787 else if (building_psymtab
)
18788 add_psymbol_to_list (pdi
.name
, false,
18789 VAR_DOMAIN
, LOC_CONST
, -1,
18790 cu
->language
== language_cplus
18791 ? psymbol_placement::GLOBAL
18792 : psymbol_placement::STATIC
,
18793 0, cu
->language
, objfile
);
18795 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18799 struct partial_die_info
*part_die
18800 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
18802 /* We'll save this DIE so link it in. */
18803 part_die
->die_parent
= parent_die
;
18804 part_die
->die_sibling
= NULL
;
18805 part_die
->die_child
= NULL
;
18807 if (last_die
&& last_die
== parent_die
)
18808 last_die
->die_child
= part_die
;
18810 last_die
->die_sibling
= part_die
;
18812 last_die
= part_die
;
18814 if (first_die
== NULL
)
18815 first_die
= part_die
;
18817 /* Maybe add the DIE to the hash table. Not all DIEs that we
18818 find interesting need to be in the hash table, because we
18819 also have the parent/sibling/child chains; only those that we
18820 might refer to by offset later during partial symbol reading.
18822 For now this means things that might have be the target of a
18823 DW_AT_specification, DW_AT_abstract_origin, or
18824 DW_AT_extension. DW_AT_extension will refer only to
18825 namespaces; DW_AT_abstract_origin refers to functions (and
18826 many things under the function DIE, but we do not recurse
18827 into function DIEs during partial symbol reading) and
18828 possibly variables as well; DW_AT_specification refers to
18829 declarations. Declarations ought to have the DW_AT_declaration
18830 flag. It happens that GCC forgets to put it in sometimes, but
18831 only for functions, not for types.
18833 Adding more things than necessary to the hash table is harmless
18834 except for the performance cost. Adding too few will result in
18835 wasted time in find_partial_die, when we reread the compilation
18836 unit with load_all_dies set. */
18839 || abbrev
->tag
== DW_TAG_constant
18840 || abbrev
->tag
== DW_TAG_subprogram
18841 || abbrev
->tag
== DW_TAG_variable
18842 || abbrev
->tag
== DW_TAG_namespace
18843 || part_die
->is_declaration
)
18847 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
18848 to_underlying (part_die
->sect_off
),
18853 /* For some DIEs we want to follow their children (if any). For C
18854 we have no reason to follow the children of structures; for other
18855 languages we have to, so that we can get at method physnames
18856 to infer fully qualified class names, for DW_AT_specification,
18857 and for C++ template arguments. For C++, we also look one level
18858 inside functions to find template arguments (if the name of the
18859 function does not already contain the template arguments).
18861 For Ada and Fortran, we need to scan the children of subprograms
18862 and lexical blocks as well because these languages allow the
18863 definition of nested entities that could be interesting for the
18864 debugger, such as nested subprograms for instance. */
18865 if (last_die
->has_children
18867 || last_die
->tag
== DW_TAG_namespace
18868 || last_die
->tag
== DW_TAG_module
18869 || last_die
->tag
== DW_TAG_enumeration_type
18870 || (cu
->language
== language_cplus
18871 && last_die
->tag
== DW_TAG_subprogram
18872 && (last_die
->name
== NULL
18873 || strchr (last_die
->name
, '<') == NULL
))
18874 || (cu
->language
!= language_c
18875 && (last_die
->tag
== DW_TAG_class_type
18876 || last_die
->tag
== DW_TAG_interface_type
18877 || last_die
->tag
== DW_TAG_structure_type
18878 || last_die
->tag
== DW_TAG_union_type
))
18879 || ((cu
->language
== language_ada
18880 || cu
->language
== language_fortran
)
18881 && (last_die
->tag
== DW_TAG_subprogram
18882 || last_die
->tag
== DW_TAG_lexical_block
))))
18885 parent_die
= last_die
;
18889 /* Otherwise we skip to the next sibling, if any. */
18890 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
18892 /* Back to the top, do it again. */
18896 partial_die_info::partial_die_info (sect_offset sect_off_
,
18897 struct abbrev_info
*abbrev
)
18898 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
18902 /* Read a minimal amount of information into the minimal die structure.
18903 INFO_PTR should point just after the initial uleb128 of a DIE. */
18906 partial_die_info::read (const struct die_reader_specs
*reader
,
18907 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
18909 struct dwarf2_cu
*cu
= reader
->cu
;
18910 struct dwarf2_per_objfile
*dwarf2_per_objfile
18911 = cu
->per_cu
->dwarf2_per_objfile
;
18913 int has_low_pc_attr
= 0;
18914 int has_high_pc_attr
= 0;
18915 int high_pc_relative
= 0;
18917 std::vector
<struct attribute
> attr_vec (abbrev
.num_attrs
);
18918 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
18920 bool need_reprocess
;
18921 info_ptr
= read_attribute (reader
, &attr_vec
[i
], &abbrev
.attrs
[i
],
18922 info_ptr
, &need_reprocess
);
18923 /* String and address offsets that need to do the reprocessing have
18924 already been read at this point, so there is no need to wait until
18925 the loop terminates to do the reprocessing. */
18926 if (need_reprocess
)
18927 read_attribute_reprocess (reader
, &attr_vec
[i
]);
18928 attribute
&attr
= attr_vec
[i
];
18929 /* Store the data if it is of an attribute we want to keep in a
18930 partial symbol table. */
18936 case DW_TAG_compile_unit
:
18937 case DW_TAG_partial_unit
:
18938 case DW_TAG_type_unit
:
18939 /* Compilation units have a DW_AT_name that is a filename, not
18940 a source language identifier. */
18941 case DW_TAG_enumeration_type
:
18942 case DW_TAG_enumerator
:
18943 /* These tags always have simple identifiers already; no need
18944 to canonicalize them. */
18945 name
= DW_STRING (&attr
);
18949 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18952 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
18953 &objfile
->per_bfd
->storage_obstack
);
18958 case DW_AT_linkage_name
:
18959 case DW_AT_MIPS_linkage_name
:
18960 /* Note that both forms of linkage name might appear. We
18961 assume they will be the same, and we only store the last
18963 linkage_name
= DW_STRING (&attr
);
18966 has_low_pc_attr
= 1;
18967 lowpc
= attr_value_as_address (&attr
);
18969 case DW_AT_high_pc
:
18970 has_high_pc_attr
= 1;
18971 highpc
= attr_value_as_address (&attr
);
18972 if (cu
->header
.version
>= 4 && attr_form_is_constant (&attr
))
18973 high_pc_relative
= 1;
18975 case DW_AT_location
:
18976 /* Support the .debug_loc offsets. */
18977 if (attr_form_is_block (&attr
))
18979 d
.locdesc
= DW_BLOCK (&attr
);
18981 else if (attr_form_is_section_offset (&attr
))
18983 dwarf2_complex_location_expr_complaint ();
18987 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18988 "partial symbol information");
18991 case DW_AT_external
:
18992 is_external
= DW_UNSND (&attr
);
18994 case DW_AT_declaration
:
18995 is_declaration
= DW_UNSND (&attr
);
19000 case DW_AT_abstract_origin
:
19001 case DW_AT_specification
:
19002 case DW_AT_extension
:
19003 has_specification
= 1;
19004 spec_offset
= dwarf2_get_ref_die_offset (&attr
);
19005 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19006 || cu
->per_cu
->is_dwz
);
19008 case DW_AT_sibling
:
19009 /* Ignore absolute siblings, they might point outside of
19010 the current compile unit. */
19011 if (attr
.form
== DW_FORM_ref_addr
)
19012 complaint (_("ignoring absolute DW_AT_sibling"));
19015 const gdb_byte
*buffer
= reader
->buffer
;
19016 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
19017 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
19019 if (sibling_ptr
< info_ptr
)
19020 complaint (_("DW_AT_sibling points backwards"));
19021 else if (sibling_ptr
> reader
->buffer_end
)
19022 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
19024 sibling
= sibling_ptr
;
19027 case DW_AT_byte_size
:
19030 case DW_AT_const_value
:
19031 has_const_value
= 1;
19033 case DW_AT_calling_convention
:
19034 /* DWARF doesn't provide a way to identify a program's source-level
19035 entry point. DW_AT_calling_convention attributes are only meant
19036 to describe functions' calling conventions.
19038 However, because it's a necessary piece of information in
19039 Fortran, and before DWARF 4 DW_CC_program was the only
19040 piece of debugging information whose definition refers to
19041 a 'main program' at all, several compilers marked Fortran
19042 main programs with DW_CC_program --- even when those
19043 functions use the standard calling conventions.
19045 Although DWARF now specifies a way to provide this
19046 information, we support this practice for backward
19048 if (DW_UNSND (&attr
) == DW_CC_program
19049 && cu
->language
== language_fortran
)
19050 main_subprogram
= 1;
19053 if (DW_UNSND (&attr
) == DW_INL_inlined
19054 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
19055 may_be_inlined
= 1;
19059 if (tag
== DW_TAG_imported_unit
)
19061 d
.sect_off
= dwarf2_get_ref_die_offset (&attr
);
19062 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19063 || cu
->per_cu
->is_dwz
);
19067 case DW_AT_main_subprogram
:
19068 main_subprogram
= DW_UNSND (&attr
);
19073 /* It would be nice to reuse dwarf2_get_pc_bounds here,
19074 but that requires a full DIE, so instead we just
19076 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
19077 unsigned int ranges_offset
= (DW_UNSND (&attr
)
19078 + (need_ranges_base
19082 /* Value of the DW_AT_ranges attribute is the offset in the
19083 .debug_ranges section. */
19084 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
19095 /* For Ada, if both the name and the linkage name appear, we prefer
19096 the latter. This lets "catch exception" work better, regardless
19097 of the order in which the name and linkage name were emitted.
19098 Really, though, this is just a workaround for the fact that gdb
19099 doesn't store both the name and the linkage name. */
19100 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
19101 name
= linkage_name
;
19103 if (high_pc_relative
)
19106 if (has_low_pc_attr
&& has_high_pc_attr
)
19108 /* When using the GNU linker, .gnu.linkonce. sections are used to
19109 eliminate duplicate copies of functions and vtables and such.
19110 The linker will arbitrarily choose one and discard the others.
19111 The AT_*_pc values for such functions refer to local labels in
19112 these sections. If the section from that file was discarded, the
19113 labels are not in the output, so the relocs get a value of 0.
19114 If this is a discarded function, mark the pc bounds as invalid,
19115 so that GDB will ignore it. */
19116 if (lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
19118 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19119 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19121 complaint (_("DW_AT_low_pc %s is zero "
19122 "for DIE at %s [in module %s]"),
19123 paddress (gdbarch
, lowpc
),
19124 sect_offset_str (sect_off
),
19125 objfile_name (objfile
));
19127 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
19128 else if (lowpc
>= highpc
)
19130 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19131 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19133 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
19134 "for DIE at %s [in module %s]"),
19135 paddress (gdbarch
, lowpc
),
19136 paddress (gdbarch
, highpc
),
19137 sect_offset_str (sect_off
),
19138 objfile_name (objfile
));
19147 /* Find a cached partial DIE at OFFSET in CU. */
19149 struct partial_die_info
*
19150 dwarf2_cu::find_partial_die (sect_offset sect_off
)
19152 struct partial_die_info
*lookup_die
= NULL
;
19153 struct partial_die_info
part_die (sect_off
);
19155 lookup_die
= ((struct partial_die_info
*)
19156 htab_find_with_hash (partial_dies
, &part_die
,
19157 to_underlying (sect_off
)));
19162 /* Find a partial DIE at OFFSET, which may or may not be in CU,
19163 except in the case of .debug_types DIEs which do not reference
19164 outside their CU (they do however referencing other types via
19165 DW_FORM_ref_sig8). */
19167 static const struct cu_partial_die_info
19168 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
19170 struct dwarf2_per_objfile
*dwarf2_per_objfile
19171 = cu
->per_cu
->dwarf2_per_objfile
;
19172 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19173 struct dwarf2_per_cu_data
*per_cu
= NULL
;
19174 struct partial_die_info
*pd
= NULL
;
19176 if (offset_in_dwz
== cu
->per_cu
->is_dwz
19177 && offset_in_cu_p (&cu
->header
, sect_off
))
19179 pd
= cu
->find_partial_die (sect_off
);
19182 /* We missed recording what we needed.
19183 Load all dies and try again. */
19184 per_cu
= cu
->per_cu
;
19188 /* TUs don't reference other CUs/TUs (except via type signatures). */
19189 if (cu
->per_cu
->is_debug_types
)
19191 error (_("Dwarf Error: Type Unit at offset %s contains"
19192 " external reference to offset %s [in module %s].\n"),
19193 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
19194 bfd_get_filename (objfile
->obfd
));
19196 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
19197 dwarf2_per_objfile
);
19199 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
19200 load_partial_comp_unit (per_cu
);
19202 per_cu
->cu
->last_used
= 0;
19203 pd
= per_cu
->cu
->find_partial_die (sect_off
);
19206 /* If we didn't find it, and not all dies have been loaded,
19207 load them all and try again. */
19209 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
19211 per_cu
->load_all_dies
= 1;
19213 /* This is nasty. When we reread the DIEs, somewhere up the call chain
19214 THIS_CU->cu may already be in use. So we can't just free it and
19215 replace its DIEs with the ones we read in. Instead, we leave those
19216 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
19217 and clobber THIS_CU->cu->partial_dies with the hash table for the new
19219 load_partial_comp_unit (per_cu
);
19221 pd
= per_cu
->cu
->find_partial_die (sect_off
);
19225 internal_error (__FILE__
, __LINE__
,
19226 _("could not find partial DIE %s "
19227 "in cache [from module %s]\n"),
19228 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
19229 return { per_cu
->cu
, pd
};
19232 /* See if we can figure out if the class lives in a namespace. We do
19233 this by looking for a member function; its demangled name will
19234 contain namespace info, if there is any. */
19237 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
19238 struct dwarf2_cu
*cu
)
19240 /* NOTE: carlton/2003-10-07: Getting the info this way changes
19241 what template types look like, because the demangler
19242 frequently doesn't give the same name as the debug info. We
19243 could fix this by only using the demangled name to get the
19244 prefix (but see comment in read_structure_type). */
19246 struct partial_die_info
*real_pdi
;
19247 struct partial_die_info
*child_pdi
;
19249 /* If this DIE (this DIE's specification, if any) has a parent, then
19250 we should not do this. We'll prepend the parent's fully qualified
19251 name when we create the partial symbol. */
19253 real_pdi
= struct_pdi
;
19254 while (real_pdi
->has_specification
)
19256 auto res
= find_partial_die (real_pdi
->spec_offset
,
19257 real_pdi
->spec_is_dwz
, cu
);
19258 real_pdi
= res
.pdi
;
19262 if (real_pdi
->die_parent
!= NULL
)
19265 for (child_pdi
= struct_pdi
->die_child
;
19267 child_pdi
= child_pdi
->die_sibling
)
19269 if (child_pdi
->tag
== DW_TAG_subprogram
19270 && child_pdi
->linkage_name
!= NULL
)
19272 gdb::unique_xmalloc_ptr
<char> actual_class_name
19273 (language_class_name_from_physname (cu
->language_defn
,
19274 child_pdi
->linkage_name
));
19275 if (actual_class_name
!= NULL
)
19277 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19279 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
19280 actual_class_name
.get ());
19288 partial_die_info::fixup (struct dwarf2_cu
*cu
)
19290 /* Once we've fixed up a die, there's no point in doing so again.
19291 This also avoids a memory leak if we were to call
19292 guess_partial_die_structure_name multiple times. */
19296 /* If we found a reference attribute and the DIE has no name, try
19297 to find a name in the referred to DIE. */
19299 if (name
== NULL
&& has_specification
)
19301 struct partial_die_info
*spec_die
;
19303 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19304 spec_die
= res
.pdi
;
19307 spec_die
->fixup (cu
);
19309 if (spec_die
->name
)
19311 name
= spec_die
->name
;
19313 /* Copy DW_AT_external attribute if it is set. */
19314 if (spec_die
->is_external
)
19315 is_external
= spec_die
->is_external
;
19319 /* Set default names for some unnamed DIEs. */
19321 if (name
== NULL
&& tag
== DW_TAG_namespace
)
19322 name
= CP_ANONYMOUS_NAMESPACE_STR
;
19324 /* If there is no parent die to provide a namespace, and there are
19325 children, see if we can determine the namespace from their linkage
19327 if (cu
->language
== language_cplus
19328 && !cu
->per_cu
->dwarf2_per_objfile
->types
.empty ()
19329 && die_parent
== NULL
19331 && (tag
== DW_TAG_class_type
19332 || tag
== DW_TAG_structure_type
19333 || tag
== DW_TAG_union_type
))
19334 guess_partial_die_structure_name (this, cu
);
19336 /* GCC might emit a nameless struct or union that has a linkage
19337 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
19339 && (tag
== DW_TAG_class_type
19340 || tag
== DW_TAG_interface_type
19341 || tag
== DW_TAG_structure_type
19342 || tag
== DW_TAG_union_type
)
19343 && linkage_name
!= NULL
)
19345 gdb::unique_xmalloc_ptr
<char> demangled
19346 (gdb_demangle (linkage_name
, DMGL_TYPES
));
19347 if (demangled
!= nullptr)
19351 /* Strip any leading namespaces/classes, keep only the base name.
19352 DW_AT_name for named DIEs does not contain the prefixes. */
19353 base
= strrchr (demangled
.get (), ':');
19354 if (base
&& base
> demangled
.get () && base
[-1] == ':')
19357 base
= demangled
.get ();
19359 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19360 name
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
, base
);
19367 /* Process the attributes that had to be skipped in the first round. These
19368 attributes are the ones that need str_offsets_base or addr_base attributes.
19369 They could not have been processed in the first round, because at the time
19370 the values of str_offsets_base or addr_base may not have been known. */
19371 void read_attribute_reprocess (const struct die_reader_specs
*reader
,
19372 struct attribute
*attr
)
19374 struct dwarf2_cu
*cu
= reader
->cu
;
19375 switch (attr
->form
)
19377 case DW_FORM_addrx
:
19378 case DW_FORM_GNU_addr_index
:
19379 DW_ADDR (attr
) = read_addr_index (cu
, DW_UNSND (attr
));
19382 case DW_FORM_strx1
:
19383 case DW_FORM_strx2
:
19384 case DW_FORM_strx3
:
19385 case DW_FORM_strx4
:
19386 case DW_FORM_GNU_str_index
:
19388 unsigned int str_index
= DW_UNSND (attr
);
19389 if (reader
->dwo_file
!= NULL
)
19391 DW_STRING (attr
) = read_dwo_str_index (reader
, str_index
);
19392 DW_STRING_IS_CANONICAL (attr
) = 0;
19396 DW_STRING (attr
) = read_stub_str_index (cu
, str_index
);
19397 DW_STRING_IS_CANONICAL (attr
) = 0;
19402 gdb_assert_not_reached (_("Unexpected DWARF form."));
19406 /* Read an attribute value described by an attribute form. */
19408 static const gdb_byte
*
19409 read_attribute_value (const struct die_reader_specs
*reader
,
19410 struct attribute
*attr
, unsigned form
,
19411 LONGEST implicit_const
, const gdb_byte
*info_ptr
,
19412 bool *need_reprocess
)
19414 struct dwarf2_cu
*cu
= reader
->cu
;
19415 struct dwarf2_per_objfile
*dwarf2_per_objfile
19416 = cu
->per_cu
->dwarf2_per_objfile
;
19417 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19418 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19419 bfd
*abfd
= reader
->abfd
;
19420 struct comp_unit_head
*cu_header
= &cu
->header
;
19421 unsigned int bytes_read
;
19422 struct dwarf_block
*blk
;
19423 *need_reprocess
= false;
19425 attr
->form
= (enum dwarf_form
) form
;
19428 case DW_FORM_ref_addr
:
19429 if (cu
->header
.version
== 2)
19430 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
19432 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
19433 &cu
->header
, &bytes_read
);
19434 info_ptr
+= bytes_read
;
19436 case DW_FORM_GNU_ref_alt
:
19437 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
19438 info_ptr
+= bytes_read
;
19441 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
19442 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
19443 info_ptr
+= bytes_read
;
19445 case DW_FORM_block2
:
19446 blk
= dwarf_alloc_block (cu
);
19447 blk
->size
= read_2_bytes (abfd
, info_ptr
);
19449 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19450 info_ptr
+= blk
->size
;
19451 DW_BLOCK (attr
) = blk
;
19453 case DW_FORM_block4
:
19454 blk
= dwarf_alloc_block (cu
);
19455 blk
->size
= read_4_bytes (abfd
, info_ptr
);
19457 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19458 info_ptr
+= blk
->size
;
19459 DW_BLOCK (attr
) = blk
;
19461 case DW_FORM_data2
:
19462 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
19465 case DW_FORM_data4
:
19466 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
19469 case DW_FORM_data8
:
19470 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
19473 case DW_FORM_data16
:
19474 blk
= dwarf_alloc_block (cu
);
19476 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
19478 DW_BLOCK (attr
) = blk
;
19480 case DW_FORM_sec_offset
:
19481 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
19482 info_ptr
+= bytes_read
;
19484 case DW_FORM_string
:
19485 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
19486 DW_STRING_IS_CANONICAL (attr
) = 0;
19487 info_ptr
+= bytes_read
;
19490 if (!cu
->per_cu
->is_dwz
)
19492 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
19493 abfd
, info_ptr
, cu_header
,
19495 DW_STRING_IS_CANONICAL (attr
) = 0;
19496 info_ptr
+= bytes_read
;
19500 case DW_FORM_line_strp
:
19501 if (!cu
->per_cu
->is_dwz
)
19503 DW_STRING (attr
) = read_indirect_line_string (dwarf2_per_objfile
,
19505 cu_header
, &bytes_read
);
19506 DW_STRING_IS_CANONICAL (attr
) = 0;
19507 info_ptr
+= bytes_read
;
19511 case DW_FORM_GNU_strp_alt
:
19513 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19514 LONGEST str_offset
= read_offset (abfd
, info_ptr
, cu_header
,
19517 DW_STRING (attr
) = read_indirect_string_from_dwz (objfile
,
19519 DW_STRING_IS_CANONICAL (attr
) = 0;
19520 info_ptr
+= bytes_read
;
19523 case DW_FORM_exprloc
:
19524 case DW_FORM_block
:
19525 blk
= dwarf_alloc_block (cu
);
19526 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19527 info_ptr
+= bytes_read
;
19528 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19529 info_ptr
+= blk
->size
;
19530 DW_BLOCK (attr
) = blk
;
19532 case DW_FORM_block1
:
19533 blk
= dwarf_alloc_block (cu
);
19534 blk
->size
= read_1_byte (abfd
, info_ptr
);
19536 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19537 info_ptr
+= blk
->size
;
19538 DW_BLOCK (attr
) = blk
;
19540 case DW_FORM_data1
:
19541 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19545 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19548 case DW_FORM_flag_present
:
19549 DW_UNSND (attr
) = 1;
19551 case DW_FORM_sdata
:
19552 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19553 info_ptr
+= bytes_read
;
19555 case DW_FORM_udata
:
19556 case DW_FORM_rnglistx
:
19557 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19558 info_ptr
+= bytes_read
;
19561 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19562 + read_1_byte (abfd
, info_ptr
));
19566 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19567 + read_2_bytes (abfd
, info_ptr
));
19571 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19572 + read_4_bytes (abfd
, info_ptr
));
19576 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19577 + read_8_bytes (abfd
, info_ptr
));
19580 case DW_FORM_ref_sig8
:
19581 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
19584 case DW_FORM_ref_udata
:
19585 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19586 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
19587 info_ptr
+= bytes_read
;
19589 case DW_FORM_indirect
:
19590 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19591 info_ptr
+= bytes_read
;
19592 if (form
== DW_FORM_implicit_const
)
19594 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19595 info_ptr
+= bytes_read
;
19597 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
19598 info_ptr
, need_reprocess
);
19600 case DW_FORM_implicit_const
:
19601 DW_SND (attr
) = implicit_const
;
19603 case DW_FORM_addrx
:
19604 case DW_FORM_GNU_addr_index
:
19605 *need_reprocess
= true;
19606 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19607 info_ptr
+= bytes_read
;
19610 case DW_FORM_strx1
:
19611 case DW_FORM_strx2
:
19612 case DW_FORM_strx3
:
19613 case DW_FORM_strx4
:
19614 case DW_FORM_GNU_str_index
:
19616 ULONGEST str_index
;
19617 if (form
== DW_FORM_strx1
)
19619 str_index
= read_1_byte (abfd
, info_ptr
);
19622 else if (form
== DW_FORM_strx2
)
19624 str_index
= read_2_bytes (abfd
, info_ptr
);
19627 else if (form
== DW_FORM_strx3
)
19629 str_index
= read_3_bytes (abfd
, info_ptr
);
19632 else if (form
== DW_FORM_strx4
)
19634 str_index
= read_4_bytes (abfd
, info_ptr
);
19639 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19640 info_ptr
+= bytes_read
;
19642 *need_reprocess
= true;
19643 DW_UNSND (attr
) = str_index
;
19647 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
19648 dwarf_form_name (form
),
19649 bfd_get_filename (abfd
));
19653 if (cu
->per_cu
->is_dwz
&& attr_form_is_ref (attr
))
19654 attr
->form
= DW_FORM_GNU_ref_alt
;
19656 /* We have seen instances where the compiler tried to emit a byte
19657 size attribute of -1 which ended up being encoded as an unsigned
19658 0xffffffff. Although 0xffffffff is technically a valid size value,
19659 an object of this size seems pretty unlikely so we can relatively
19660 safely treat these cases as if the size attribute was invalid and
19661 treat them as zero by default. */
19662 if (attr
->name
== DW_AT_byte_size
19663 && form
== DW_FORM_data4
19664 && DW_UNSND (attr
) >= 0xffffffff)
19667 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
19668 hex_string (DW_UNSND (attr
)));
19669 DW_UNSND (attr
) = 0;
19675 /* Read an attribute described by an abbreviated attribute. */
19677 static const gdb_byte
*
19678 read_attribute (const struct die_reader_specs
*reader
,
19679 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
19680 const gdb_byte
*info_ptr
, bool *need_reprocess
)
19682 attr
->name
= abbrev
->name
;
19683 return read_attribute_value (reader
, attr
, abbrev
->form
,
19684 abbrev
->implicit_const
, info_ptr
,
19688 /* Read dwarf information from a buffer. */
19690 static unsigned int
19691 read_1_byte (bfd
*abfd
, const gdb_byte
*buf
)
19693 return bfd_get_8 (abfd
, buf
);
19697 read_1_signed_byte (bfd
*abfd
, const gdb_byte
*buf
)
19699 return bfd_get_signed_8 (abfd
, buf
);
19702 static unsigned int
19703 read_2_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19705 return bfd_get_16 (abfd
, buf
);
19709 read_2_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19711 return bfd_get_signed_16 (abfd
, buf
);
19714 static unsigned int
19715 read_3_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19717 unsigned int result
= 0;
19718 for (int i
= 0; i
< 3; ++i
)
19720 unsigned char byte
= bfd_get_8 (abfd
, buf
);
19722 result
|= ((unsigned int) byte
<< (i
* 8));
19727 static unsigned int
19728 read_4_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19730 return bfd_get_32 (abfd
, buf
);
19734 read_4_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19736 return bfd_get_signed_32 (abfd
, buf
);
19740 read_8_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19742 return bfd_get_64 (abfd
, buf
);
19746 read_address (bfd
*abfd
, const gdb_byte
*buf
, struct dwarf2_cu
*cu
,
19747 unsigned int *bytes_read
)
19749 struct comp_unit_head
*cu_header
= &cu
->header
;
19750 CORE_ADDR retval
= 0;
19752 if (cu_header
->signed_addr_p
)
19754 switch (cu_header
->addr_size
)
19757 retval
= bfd_get_signed_16 (abfd
, buf
);
19760 retval
= bfd_get_signed_32 (abfd
, buf
);
19763 retval
= bfd_get_signed_64 (abfd
, buf
);
19766 internal_error (__FILE__
, __LINE__
,
19767 _("read_address: bad switch, signed [in module %s]"),
19768 bfd_get_filename (abfd
));
19773 switch (cu_header
->addr_size
)
19776 retval
= bfd_get_16 (abfd
, buf
);
19779 retval
= bfd_get_32 (abfd
, buf
);
19782 retval
= bfd_get_64 (abfd
, buf
);
19785 internal_error (__FILE__
, __LINE__
,
19786 _("read_address: bad switch, "
19787 "unsigned [in module %s]"),
19788 bfd_get_filename (abfd
));
19792 *bytes_read
= cu_header
->addr_size
;
19796 /* Read the initial length from a section. The (draft) DWARF 3
19797 specification allows the initial length to take up either 4 bytes
19798 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
19799 bytes describe the length and all offsets will be 8 bytes in length
19802 An older, non-standard 64-bit format is also handled by this
19803 function. The older format in question stores the initial length
19804 as an 8-byte quantity without an escape value. Lengths greater
19805 than 2^32 aren't very common which means that the initial 4 bytes
19806 is almost always zero. Since a length value of zero doesn't make
19807 sense for the 32-bit format, this initial zero can be considered to
19808 be an escape value which indicates the presence of the older 64-bit
19809 format. As written, the code can't detect (old format) lengths
19810 greater than 4GB. If it becomes necessary to handle lengths
19811 somewhat larger than 4GB, we could allow other small values (such
19812 as the non-sensical values of 1, 2, and 3) to also be used as
19813 escape values indicating the presence of the old format.
19815 The value returned via bytes_read should be used to increment the
19816 relevant pointer after calling read_initial_length().
19818 [ Note: read_initial_length() and read_offset() are based on the
19819 document entitled "DWARF Debugging Information Format", revision
19820 3, draft 8, dated November 19, 2001. This document was obtained
19823 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
19825 This document is only a draft and is subject to change. (So beware.)
19827 Details regarding the older, non-standard 64-bit format were
19828 determined empirically by examining 64-bit ELF files produced by
19829 the SGI toolchain on an IRIX 6.5 machine.
19831 - Kevin, July 16, 2002
19835 read_initial_length (bfd
*abfd
, const gdb_byte
*buf
, unsigned int *bytes_read
)
19837 LONGEST length
= bfd_get_32 (abfd
, buf
);
19839 if (length
== 0xffffffff)
19841 length
= bfd_get_64 (abfd
, buf
+ 4);
19844 else if (length
== 0)
19846 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
19847 length
= bfd_get_64 (abfd
, buf
);
19858 /* Cover function for read_initial_length.
19859 Returns the length of the object at BUF, and stores the size of the
19860 initial length in *BYTES_READ and stores the size that offsets will be in
19862 If the initial length size is not equivalent to that specified in
19863 CU_HEADER then issue a complaint.
19864 This is useful when reading non-comp-unit headers. */
19867 read_checked_initial_length_and_offset (bfd
*abfd
, const gdb_byte
*buf
,
19868 const struct comp_unit_head
*cu_header
,
19869 unsigned int *bytes_read
,
19870 unsigned int *offset_size
)
19872 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
19874 gdb_assert (cu_header
->initial_length_size
== 4
19875 || cu_header
->initial_length_size
== 8
19876 || cu_header
->initial_length_size
== 12);
19878 if (cu_header
->initial_length_size
!= *bytes_read
)
19879 complaint (_("intermixed 32-bit and 64-bit DWARF sections"));
19881 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
19885 /* Read an offset from the data stream. The size of the offset is
19886 given by cu_header->offset_size. */
19889 read_offset (bfd
*abfd
, const gdb_byte
*buf
,
19890 const struct comp_unit_head
*cu_header
,
19891 unsigned int *bytes_read
)
19893 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
19895 *bytes_read
= cu_header
->offset_size
;
19899 /* Read an offset from the data stream. */
19902 read_offset_1 (bfd
*abfd
, const gdb_byte
*buf
, unsigned int offset_size
)
19904 LONGEST retval
= 0;
19906 switch (offset_size
)
19909 retval
= bfd_get_32 (abfd
, buf
);
19912 retval
= bfd_get_64 (abfd
, buf
);
19915 internal_error (__FILE__
, __LINE__
,
19916 _("read_offset_1: bad switch [in module %s]"),
19917 bfd_get_filename (abfd
));
19923 static const gdb_byte
*
19924 read_n_bytes (bfd
*abfd
, const gdb_byte
*buf
, unsigned int size
)
19926 /* If the size of a host char is 8 bits, we can return a pointer
19927 to the buffer, otherwise we have to copy the data to a buffer
19928 allocated on the temporary obstack. */
19929 gdb_assert (HOST_CHAR_BIT
== 8);
19933 static const char *
19934 read_direct_string (bfd
*abfd
, const gdb_byte
*buf
,
19935 unsigned int *bytes_read_ptr
)
19937 /* If the size of a host char is 8 bits, we can return a pointer
19938 to the string, otherwise we have to copy the string to a buffer
19939 allocated on the temporary obstack. */
19940 gdb_assert (HOST_CHAR_BIT
== 8);
19943 *bytes_read_ptr
= 1;
19946 *bytes_read_ptr
= strlen ((const char *) buf
) + 1;
19947 return (const char *) buf
;
19950 /* Return pointer to string at section SECT offset STR_OFFSET with error
19951 reporting strings FORM_NAME and SECT_NAME. */
19953 static const char *
19954 read_indirect_string_at_offset_from (struct objfile
*objfile
,
19955 bfd
*abfd
, LONGEST str_offset
,
19956 struct dwarf2_section_info
*sect
,
19957 const char *form_name
,
19958 const char *sect_name
)
19960 dwarf2_read_section (objfile
, sect
);
19961 if (sect
->buffer
== NULL
)
19962 error (_("%s used without %s section [in module %s]"),
19963 form_name
, sect_name
, bfd_get_filename (abfd
));
19964 if (str_offset
>= sect
->size
)
19965 error (_("%s pointing outside of %s section [in module %s]"),
19966 form_name
, sect_name
, bfd_get_filename (abfd
));
19967 gdb_assert (HOST_CHAR_BIT
== 8);
19968 if (sect
->buffer
[str_offset
] == '\0')
19970 return (const char *) (sect
->buffer
+ str_offset
);
19973 /* Return pointer to string at .debug_str offset STR_OFFSET. */
19975 static const char *
19976 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19977 bfd
*abfd
, LONGEST str_offset
)
19979 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
19981 &dwarf2_per_objfile
->str
,
19982 "DW_FORM_strp", ".debug_str");
19985 /* Return pointer to string at .debug_line_str offset STR_OFFSET. */
19987 static const char *
19988 read_indirect_line_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19989 bfd
*abfd
, LONGEST str_offset
)
19991 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
19993 &dwarf2_per_objfile
->line_str
,
19994 "DW_FORM_line_strp",
19995 ".debug_line_str");
19998 /* Read a string at offset STR_OFFSET in the .debug_str section from
19999 the .dwz file DWZ. Throw an error if the offset is too large. If
20000 the string consists of a single NUL byte, return NULL; otherwise
20001 return a pointer to the string. */
20003 static const char *
20004 read_indirect_string_from_dwz (struct objfile
*objfile
, struct dwz_file
*dwz
,
20005 LONGEST str_offset
)
20007 dwarf2_read_section (objfile
, &dwz
->str
);
20009 if (dwz
->str
.buffer
== NULL
)
20010 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
20011 "section [in module %s]"),
20012 bfd_get_filename (dwz
->dwz_bfd
.get ()));
20013 if (str_offset
>= dwz
->str
.size
)
20014 error (_("DW_FORM_GNU_strp_alt pointing outside of "
20015 ".debug_str section [in module %s]"),
20016 bfd_get_filename (dwz
->dwz_bfd
.get ()));
20017 gdb_assert (HOST_CHAR_BIT
== 8);
20018 if (dwz
->str
.buffer
[str_offset
] == '\0')
20020 return (const char *) (dwz
->str
.buffer
+ str_offset
);
20023 /* Return pointer to string at .debug_str offset as read from BUF.
20024 BUF is assumed to be in a compilation unit described by CU_HEADER.
20025 Return *BYTES_READ_PTR count of bytes read from BUF. */
20027 static const char *
20028 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
20029 const gdb_byte
*buf
,
20030 const struct comp_unit_head
*cu_header
,
20031 unsigned int *bytes_read_ptr
)
20033 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
20035 return read_indirect_string_at_offset (dwarf2_per_objfile
, abfd
, str_offset
);
20038 /* Return pointer to string at .debug_line_str offset as read from BUF.
20039 BUF is assumed to be in a compilation unit described by CU_HEADER.
20040 Return *BYTES_READ_PTR count of bytes read from BUF. */
20042 static const char *
20043 read_indirect_line_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20044 bfd
*abfd
, const gdb_byte
*buf
,
20045 const struct comp_unit_head
*cu_header
,
20046 unsigned int *bytes_read_ptr
)
20048 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
20050 return read_indirect_line_string_at_offset (dwarf2_per_objfile
, abfd
,
20055 read_unsigned_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
20056 unsigned int *bytes_read_ptr
)
20059 unsigned int num_read
;
20061 unsigned char byte
;
20068 byte
= bfd_get_8 (abfd
, buf
);
20071 result
|= ((ULONGEST
) (byte
& 127) << shift
);
20072 if ((byte
& 128) == 0)
20078 *bytes_read_ptr
= num_read
;
20083 read_signed_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
20084 unsigned int *bytes_read_ptr
)
20087 int shift
, num_read
;
20088 unsigned char byte
;
20095 byte
= bfd_get_8 (abfd
, buf
);
20098 result
|= ((ULONGEST
) (byte
& 127) << shift
);
20100 if ((byte
& 128) == 0)
20105 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
20106 result
|= -(((ULONGEST
) 1) << shift
);
20107 *bytes_read_ptr
= num_read
;
20111 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
20112 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
20113 ADDR_SIZE is the size of addresses from the CU header. */
20116 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20117 unsigned int addr_index
, gdb::optional
<ULONGEST
> addr_base
,
20120 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20121 bfd
*abfd
= objfile
->obfd
;
20122 const gdb_byte
*info_ptr
;
20123 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
20125 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
20126 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
20127 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
20128 objfile_name (objfile
));
20129 if (addr_base_or_zero
+ addr_index
* addr_size
20130 >= dwarf2_per_objfile
->addr
.size
)
20131 error (_("DW_FORM_addr_index pointing outside of "
20132 ".debug_addr section [in module %s]"),
20133 objfile_name (objfile
));
20134 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
20135 + addr_base_or_zero
+ addr_index
* addr_size
);
20136 if (addr_size
== 4)
20137 return bfd_get_32 (abfd
, info_ptr
);
20139 return bfd_get_64 (abfd
, info_ptr
);
20142 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
20145 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
20147 return read_addr_index_1 (cu
->per_cu
->dwarf2_per_objfile
, addr_index
,
20148 cu
->addr_base
, cu
->header
.addr_size
);
20151 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
20154 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
20155 unsigned int *bytes_read
)
20157 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
20158 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
20160 return read_addr_index (cu
, addr_index
);
20163 /* Given an index in .debug_addr, fetch the value.
20164 NOTE: This can be called during dwarf expression evaluation,
20165 long after the debug information has been read, and thus per_cu->cu
20166 may no longer exist. */
20169 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
20170 unsigned int addr_index
)
20172 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
20173 struct dwarf2_cu
*cu
= per_cu
->cu
;
20174 gdb::optional
<ULONGEST
> addr_base
;
20177 /* We need addr_base and addr_size.
20178 If we don't have PER_CU->cu, we have to get it.
20179 Nasty, but the alternative is storing the needed info in PER_CU,
20180 which at this point doesn't seem justified: it's not clear how frequently
20181 it would get used and it would increase the size of every PER_CU.
20182 Entry points like dwarf2_per_cu_addr_size do a similar thing
20183 so we're not in uncharted territory here.
20184 Alas we need to be a bit more complicated as addr_base is contained
20187 We don't need to read the entire CU(/TU).
20188 We just need the header and top level die.
20190 IWBN to use the aging mechanism to let us lazily later discard the CU.
20191 For now we skip this optimization. */
20195 addr_base
= cu
->addr_base
;
20196 addr_size
= cu
->header
.addr_size
;
20200 cutu_reader
reader (per_cu
, NULL
, 0, 0, false);
20201 addr_base
= reader
.cu
->addr_base
;
20202 addr_size
= reader
.cu
->header
.addr_size
;
20205 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
20209 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
20210 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
20213 static const char *
20214 read_str_index (struct dwarf2_cu
*cu
,
20215 struct dwarf2_section_info
*str_section
,
20216 struct dwarf2_section_info
*str_offsets_section
,
20217 ULONGEST str_offsets_base
, ULONGEST str_index
)
20219 struct dwarf2_per_objfile
*dwarf2_per_objfile
20220 = cu
->per_cu
->dwarf2_per_objfile
;
20221 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20222 const char *objf_name
= objfile_name (objfile
);
20223 bfd
*abfd
= objfile
->obfd
;
20224 const gdb_byte
*info_ptr
;
20225 ULONGEST str_offset
;
20226 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
20228 dwarf2_read_section (objfile
, str_section
);
20229 dwarf2_read_section (objfile
, str_offsets_section
);
20230 if (str_section
->buffer
== NULL
)
20231 error (_("%s used without %s section"
20232 " in CU at offset %s [in module %s]"),
20233 form_name
, get_section_name (str_section
),
20234 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20235 if (str_offsets_section
->buffer
== NULL
)
20236 error (_("%s used without %s section"
20237 " in CU at offset %s [in module %s]"),
20238 form_name
, get_section_name (str_section
),
20239 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20240 info_ptr
= (str_offsets_section
->buffer
20242 + str_index
* cu
->header
.offset_size
);
20243 if (cu
->header
.offset_size
== 4)
20244 str_offset
= bfd_get_32 (abfd
, info_ptr
);
20246 str_offset
= bfd_get_64 (abfd
, info_ptr
);
20247 if (str_offset
>= str_section
->size
)
20248 error (_("Offset from %s pointing outside of"
20249 " .debug_str.dwo section in CU at offset %s [in module %s]"),
20250 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20251 return (const char *) (str_section
->buffer
+ str_offset
);
20254 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
20256 static const char *
20257 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
20259 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
20260 ? reader
->cu
->header
.addr_size
: 0;
20261 return read_str_index (reader
->cu
,
20262 &reader
->dwo_file
->sections
.str
,
20263 &reader
->dwo_file
->sections
.str_offsets
,
20264 str_offsets_base
, str_index
);
20267 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
20269 static const char *
20270 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
20272 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20273 const char *objf_name
= objfile_name (objfile
);
20274 static const char form_name
[] = "DW_FORM_GNU_str_index";
20275 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
20277 if (!cu
->str_offsets_base
.has_value ())
20278 error (_("%s used in Fission stub without %s"
20279 " in CU at offset 0x%lx [in module %s]"),
20280 form_name
, str_offsets_attr_name
,
20281 (long) cu
->header
.offset_size
, objf_name
);
20283 return read_str_index (cu
,
20284 &cu
->per_cu
->dwarf2_per_objfile
->str
,
20285 &cu
->per_cu
->dwarf2_per_objfile
->str_offsets
,
20286 *cu
->str_offsets_base
, str_index
);
20289 /* Return the length of an LEB128 number in BUF. */
20292 leb128_size (const gdb_byte
*buf
)
20294 const gdb_byte
*begin
= buf
;
20300 if ((byte
& 128) == 0)
20301 return buf
- begin
;
20306 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
20315 cu
->language
= language_c
;
20318 case DW_LANG_C_plus_plus
:
20319 case DW_LANG_C_plus_plus_11
:
20320 case DW_LANG_C_plus_plus_14
:
20321 cu
->language
= language_cplus
;
20324 cu
->language
= language_d
;
20326 case DW_LANG_Fortran77
:
20327 case DW_LANG_Fortran90
:
20328 case DW_LANG_Fortran95
:
20329 case DW_LANG_Fortran03
:
20330 case DW_LANG_Fortran08
:
20331 cu
->language
= language_fortran
;
20334 cu
->language
= language_go
;
20336 case DW_LANG_Mips_Assembler
:
20337 cu
->language
= language_asm
;
20339 case DW_LANG_Ada83
:
20340 case DW_LANG_Ada95
:
20341 cu
->language
= language_ada
;
20343 case DW_LANG_Modula2
:
20344 cu
->language
= language_m2
;
20346 case DW_LANG_Pascal83
:
20347 cu
->language
= language_pascal
;
20350 cu
->language
= language_objc
;
20353 case DW_LANG_Rust_old
:
20354 cu
->language
= language_rust
;
20356 case DW_LANG_Cobol74
:
20357 case DW_LANG_Cobol85
:
20359 cu
->language
= language_minimal
;
20362 cu
->language_defn
= language_def (cu
->language
);
20365 /* Return the named attribute or NULL if not there. */
20367 static struct attribute
*
20368 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20373 struct attribute
*spec
= NULL
;
20375 for (i
= 0; i
< die
->num_attrs
; ++i
)
20377 if (die
->attrs
[i
].name
== name
)
20378 return &die
->attrs
[i
];
20379 if (die
->attrs
[i
].name
== DW_AT_specification
20380 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
20381 spec
= &die
->attrs
[i
];
20387 die
= follow_die_ref (die
, spec
, &cu
);
20393 /* Return the named attribute or NULL if not there,
20394 but do not follow DW_AT_specification, etc.
20395 This is for use in contexts where we're reading .debug_types dies.
20396 Following DW_AT_specification, DW_AT_abstract_origin will take us
20397 back up the chain, and we want to go down. */
20399 static struct attribute
*
20400 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
20404 for (i
= 0; i
< die
->num_attrs
; ++i
)
20405 if (die
->attrs
[i
].name
== name
)
20406 return &die
->attrs
[i
];
20411 /* Return the string associated with a string-typed attribute, or NULL if it
20412 is either not found or is of an incorrect type. */
20414 static const char *
20415 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20417 struct attribute
*attr
;
20418 const char *str
= NULL
;
20420 attr
= dwarf2_attr (die
, name
, cu
);
20424 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
20425 || attr
->form
== DW_FORM_string
20426 || attr
->form
== DW_FORM_strx
20427 || attr
->form
== DW_FORM_strx1
20428 || attr
->form
== DW_FORM_strx2
20429 || attr
->form
== DW_FORM_strx3
20430 || attr
->form
== DW_FORM_strx4
20431 || attr
->form
== DW_FORM_GNU_str_index
20432 || attr
->form
== DW_FORM_GNU_strp_alt
)
20433 str
= DW_STRING (attr
);
20435 complaint (_("string type expected for attribute %s for "
20436 "DIE at %s in module %s"),
20437 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
20438 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
20444 /* Return the dwo name or NULL if not present. If present, it is in either
20445 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
20446 static const char *
20447 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
20449 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
20450 if (dwo_name
== nullptr)
20451 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
20455 /* Return non-zero iff the attribute NAME is defined for the given DIE,
20456 and holds a non-zero value. This function should only be used for
20457 DW_FORM_flag or DW_FORM_flag_present attributes. */
20460 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
20462 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
20464 return (attr
&& DW_UNSND (attr
));
20468 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
20470 /* A DIE is a declaration if it has a DW_AT_declaration attribute
20471 which value is non-zero. However, we have to be careful with
20472 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
20473 (via dwarf2_flag_true_p) follows this attribute. So we may
20474 end up accidently finding a declaration attribute that belongs
20475 to a different DIE referenced by the specification attribute,
20476 even though the given DIE does not have a declaration attribute. */
20477 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
20478 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
20481 /* Return the die giving the specification for DIE, if there is
20482 one. *SPEC_CU is the CU containing DIE on input, and the CU
20483 containing the return value on output. If there is no
20484 specification, but there is an abstract origin, that is
20487 static struct die_info
*
20488 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
20490 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
20493 if (spec_attr
== NULL
)
20494 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
20496 if (spec_attr
== NULL
)
20499 return follow_die_ref (die
, spec_attr
, spec_cu
);
20502 /* Stub for free_line_header to match void * callback types. */
20505 free_line_header_voidp (void *arg
)
20507 struct line_header
*lh
= (struct line_header
*) arg
;
20513 line_header::add_include_dir (const char *include_dir
)
20515 if (dwarf_line_debug
>= 2)
20519 new_size
= m_include_dirs
.size ();
20521 new_size
= m_include_dirs
.size () + 1;
20522 fprintf_unfiltered (gdb_stdlog
, "Adding dir %zu: %s\n",
20523 new_size
, include_dir
);
20525 m_include_dirs
.push_back (include_dir
);
20529 line_header::add_file_name (const char *name
,
20531 unsigned int mod_time
,
20532 unsigned int length
)
20534 if (dwarf_line_debug
>= 2)
20538 new_size
= file_names_size ();
20540 new_size
= file_names_size () + 1;
20541 fprintf_unfiltered (gdb_stdlog
, "Adding file %zu: %s\n",
20544 m_file_names
.emplace_back (name
, d_index
, mod_time
, length
);
20547 /* A convenience function to find the proper .debug_line section for a CU. */
20549 static struct dwarf2_section_info
*
20550 get_debug_line_section (struct dwarf2_cu
*cu
)
20552 struct dwarf2_section_info
*section
;
20553 struct dwarf2_per_objfile
*dwarf2_per_objfile
20554 = cu
->per_cu
->dwarf2_per_objfile
;
20556 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
20558 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20559 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
20560 else if (cu
->per_cu
->is_dwz
)
20562 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
20564 section
= &dwz
->line
;
20567 section
= &dwarf2_per_objfile
->line
;
20572 /* Read directory or file name entry format, starting with byte of
20573 format count entries, ULEB128 pairs of entry formats, ULEB128 of
20574 entries count and the entries themselves in the described entry
20578 read_formatted_entries (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20579 bfd
*abfd
, const gdb_byte
**bufp
,
20580 struct line_header
*lh
,
20581 const struct comp_unit_head
*cu_header
,
20582 void (*callback
) (struct line_header
*lh
,
20585 unsigned int mod_time
,
20586 unsigned int length
))
20588 gdb_byte format_count
, formati
;
20589 ULONGEST data_count
, datai
;
20590 const gdb_byte
*buf
= *bufp
;
20591 const gdb_byte
*format_header_data
;
20592 unsigned int bytes_read
;
20594 format_count
= read_1_byte (abfd
, buf
);
20596 format_header_data
= buf
;
20597 for (formati
= 0; formati
< format_count
; formati
++)
20599 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20601 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20605 data_count
= read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20607 for (datai
= 0; datai
< data_count
; datai
++)
20609 const gdb_byte
*format
= format_header_data
;
20610 struct file_entry fe
;
20612 for (formati
= 0; formati
< format_count
; formati
++)
20614 ULONGEST content_type
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20615 format
+= bytes_read
;
20617 ULONGEST form
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20618 format
+= bytes_read
;
20620 gdb::optional
<const char *> string
;
20621 gdb::optional
<unsigned int> uint
;
20625 case DW_FORM_string
:
20626 string
.emplace (read_direct_string (abfd
, buf
, &bytes_read
));
20630 case DW_FORM_line_strp
:
20631 string
.emplace (read_indirect_line_string (dwarf2_per_objfile
,
20638 case DW_FORM_data1
:
20639 uint
.emplace (read_1_byte (abfd
, buf
));
20643 case DW_FORM_data2
:
20644 uint
.emplace (read_2_bytes (abfd
, buf
));
20648 case DW_FORM_data4
:
20649 uint
.emplace (read_4_bytes (abfd
, buf
));
20653 case DW_FORM_data8
:
20654 uint
.emplace (read_8_bytes (abfd
, buf
));
20658 case DW_FORM_data16
:
20659 /* This is used for MD5, but file_entry does not record MD5s. */
20663 case DW_FORM_udata
:
20664 uint
.emplace (read_unsigned_leb128 (abfd
, buf
, &bytes_read
));
20668 case DW_FORM_block
:
20669 /* It is valid only for DW_LNCT_timestamp which is ignored by
20674 switch (content_type
)
20677 if (string
.has_value ())
20680 case DW_LNCT_directory_index
:
20681 if (uint
.has_value ())
20682 fe
.d_index
= (dir_index
) *uint
;
20684 case DW_LNCT_timestamp
:
20685 if (uint
.has_value ())
20686 fe
.mod_time
= *uint
;
20689 if (uint
.has_value ())
20695 complaint (_("Unknown format content type %s"),
20696 pulongest (content_type
));
20700 callback (lh
, fe
.name
, fe
.d_index
, fe
.mod_time
, fe
.length
);
20706 /* Read the statement program header starting at OFFSET in
20707 .debug_line, or .debug_line.dwo. Return a pointer
20708 to a struct line_header, allocated using xmalloc.
20709 Returns NULL if there is a problem reading the header, e.g., if it
20710 has a version we don't understand.
20712 NOTE: the strings in the include directory and file name tables of
20713 the returned object point into the dwarf line section buffer,
20714 and must not be freed. */
20716 static line_header_up
20717 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
20719 const gdb_byte
*line_ptr
;
20720 unsigned int bytes_read
, offset_size
;
20722 const char *cur_dir
, *cur_file
;
20723 struct dwarf2_section_info
*section
;
20725 struct dwarf2_per_objfile
*dwarf2_per_objfile
20726 = cu
->per_cu
->dwarf2_per_objfile
;
20728 section
= get_debug_line_section (cu
);
20729 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
20730 if (section
->buffer
== NULL
)
20732 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20733 complaint (_("missing .debug_line.dwo section"));
20735 complaint (_("missing .debug_line section"));
20739 /* We can't do this until we know the section is non-empty.
20740 Only then do we know we have such a section. */
20741 abfd
= get_section_bfd_owner (section
);
20743 /* Make sure that at least there's room for the total_length field.
20744 That could be 12 bytes long, but we're just going to fudge that. */
20745 if (to_underlying (sect_off
) + 4 >= section
->size
)
20747 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20751 line_header_up
lh (new line_header ());
20753 lh
->sect_off
= sect_off
;
20754 lh
->offset_in_dwz
= cu
->per_cu
->is_dwz
;
20756 line_ptr
= section
->buffer
+ to_underlying (sect_off
);
20758 /* Read in the header. */
20760 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
20761 &bytes_read
, &offset_size
);
20762 line_ptr
+= bytes_read
;
20764 const gdb_byte
*start_here
= line_ptr
;
20766 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
20768 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20771 lh
->statement_program_end
= start_here
+ lh
->total_length
;
20772 lh
->version
= read_2_bytes (abfd
, line_ptr
);
20774 if (lh
->version
> 5)
20776 /* This is a version we don't understand. The format could have
20777 changed in ways we don't handle properly so just punt. */
20778 complaint (_("unsupported version in .debug_line section"));
20781 if (lh
->version
>= 5)
20783 gdb_byte segment_selector_size
;
20785 /* Skip address size. */
20786 read_1_byte (abfd
, line_ptr
);
20789 segment_selector_size
= read_1_byte (abfd
, line_ptr
);
20791 if (segment_selector_size
!= 0)
20793 complaint (_("unsupported segment selector size %u "
20794 "in .debug_line section"),
20795 segment_selector_size
);
20799 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
20800 line_ptr
+= offset_size
;
20801 lh
->statement_program_start
= line_ptr
+ lh
->header_length
;
20802 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
20804 if (lh
->version
>= 4)
20806 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
20810 lh
->maximum_ops_per_instruction
= 1;
20812 if (lh
->maximum_ops_per_instruction
== 0)
20814 lh
->maximum_ops_per_instruction
= 1;
20815 complaint (_("invalid maximum_ops_per_instruction "
20816 "in `.debug_line' section"));
20819 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
20821 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
20823 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
20825 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
20827 lh
->standard_opcode_lengths
.reset (new unsigned char[lh
->opcode_base
]);
20829 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
20830 for (i
= 1; i
< lh
->opcode_base
; ++i
)
20832 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
20836 if (lh
->version
>= 5)
20838 /* Read directory table. */
20839 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20841 [] (struct line_header
*header
, const char *name
,
20842 dir_index d_index
, unsigned int mod_time
,
20843 unsigned int length
)
20845 header
->add_include_dir (name
);
20848 /* Read file name table. */
20849 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20851 [] (struct line_header
*header
, const char *name
,
20852 dir_index d_index
, unsigned int mod_time
,
20853 unsigned int length
)
20855 header
->add_file_name (name
, d_index
, mod_time
, length
);
20860 /* Read directory table. */
20861 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20863 line_ptr
+= bytes_read
;
20864 lh
->add_include_dir (cur_dir
);
20866 line_ptr
+= bytes_read
;
20868 /* Read file name table. */
20869 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20871 unsigned int mod_time
, length
;
20874 line_ptr
+= bytes_read
;
20875 d_index
= (dir_index
) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20876 line_ptr
+= bytes_read
;
20877 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20878 line_ptr
+= bytes_read
;
20879 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20880 line_ptr
+= bytes_read
;
20882 lh
->add_file_name (cur_file
, d_index
, mod_time
, length
);
20884 line_ptr
+= bytes_read
;
20887 if (line_ptr
> (section
->buffer
+ section
->size
))
20888 complaint (_("line number info header doesn't "
20889 "fit in `.debug_line' section"));
20894 /* Subroutine of dwarf_decode_lines to simplify it.
20895 Return the file name of the psymtab for the given file_entry.
20896 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20897 If space for the result is malloc'd, *NAME_HOLDER will be set.
20898 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
20900 static const char *
20901 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
20902 const dwarf2_psymtab
*pst
,
20903 const char *comp_dir
,
20904 gdb::unique_xmalloc_ptr
<char> *name_holder
)
20906 const char *include_name
= fe
.name
;
20907 const char *include_name_to_compare
= include_name
;
20908 const char *pst_filename
;
20911 const char *dir_name
= fe
.include_dir (lh
);
20913 gdb::unique_xmalloc_ptr
<char> hold_compare
;
20914 if (!IS_ABSOLUTE_PATH (include_name
)
20915 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
20917 /* Avoid creating a duplicate psymtab for PST.
20918 We do this by comparing INCLUDE_NAME and PST_FILENAME.
20919 Before we do the comparison, however, we need to account
20920 for DIR_NAME and COMP_DIR.
20921 First prepend dir_name (if non-NULL). If we still don't
20922 have an absolute path prepend comp_dir (if non-NULL).
20923 However, the directory we record in the include-file's
20924 psymtab does not contain COMP_DIR (to match the
20925 corresponding symtab(s)).
20930 bash$ gcc -g ./hello.c
20931 include_name = "hello.c"
20933 DW_AT_comp_dir = comp_dir = "/tmp"
20934 DW_AT_name = "./hello.c"
20938 if (dir_name
!= NULL
)
20940 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
20941 include_name
, (char *) NULL
));
20942 include_name
= name_holder
->get ();
20943 include_name_to_compare
= include_name
;
20945 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
20947 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
20948 include_name
, (char *) NULL
));
20949 include_name_to_compare
= hold_compare
.get ();
20953 pst_filename
= pst
->filename
;
20954 gdb::unique_xmalloc_ptr
<char> copied_name
;
20955 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
20957 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
20958 pst_filename
, (char *) NULL
));
20959 pst_filename
= copied_name
.get ();
20962 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
20966 return include_name
;
20969 /* State machine to track the state of the line number program. */
20971 class lnp_state_machine
20974 /* Initialize a machine state for the start of a line number
20976 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
20977 bool record_lines_p
);
20979 file_entry
*current_file ()
20981 /* lh->file_names is 0-based, but the file name numbers in the
20982 statement program are 1-based. */
20983 return m_line_header
->file_name_at (m_file
);
20986 /* Record the line in the state machine. END_SEQUENCE is true if
20987 we're processing the end of a sequence. */
20988 void record_line (bool end_sequence
);
20990 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
20991 nop-out rest of the lines in this sequence. */
20992 void check_line_address (struct dwarf2_cu
*cu
,
20993 const gdb_byte
*line_ptr
,
20994 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
20996 void handle_set_discriminator (unsigned int discriminator
)
20998 m_discriminator
= discriminator
;
20999 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
21002 /* Handle DW_LNE_set_address. */
21003 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
21006 address
+= baseaddr
;
21007 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
21010 /* Handle DW_LNS_advance_pc. */
21011 void handle_advance_pc (CORE_ADDR adjust
);
21013 /* Handle a special opcode. */
21014 void handle_special_opcode (unsigned char op_code
);
21016 /* Handle DW_LNS_advance_line. */
21017 void handle_advance_line (int line_delta
)
21019 advance_line (line_delta
);
21022 /* Handle DW_LNS_set_file. */
21023 void handle_set_file (file_name_index file
);
21025 /* Handle DW_LNS_negate_stmt. */
21026 void handle_negate_stmt ()
21028 m_is_stmt
= !m_is_stmt
;
21031 /* Handle DW_LNS_const_add_pc. */
21032 void handle_const_add_pc ();
21034 /* Handle DW_LNS_fixed_advance_pc. */
21035 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
21037 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21041 /* Handle DW_LNS_copy. */
21042 void handle_copy ()
21044 record_line (false);
21045 m_discriminator
= 0;
21048 /* Handle DW_LNE_end_sequence. */
21049 void handle_end_sequence ()
21051 m_currently_recording_lines
= true;
21055 /* Advance the line by LINE_DELTA. */
21056 void advance_line (int line_delta
)
21058 m_line
+= line_delta
;
21060 if (line_delta
!= 0)
21061 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
21064 struct dwarf2_cu
*m_cu
;
21066 gdbarch
*m_gdbarch
;
21068 /* True if we're recording lines.
21069 Otherwise we're building partial symtabs and are just interested in
21070 finding include files mentioned by the line number program. */
21071 bool m_record_lines_p
;
21073 /* The line number header. */
21074 line_header
*m_line_header
;
21076 /* These are part of the standard DWARF line number state machine,
21077 and initialized according to the DWARF spec. */
21079 unsigned char m_op_index
= 0;
21080 /* The line table index of the current file. */
21081 file_name_index m_file
= 1;
21082 unsigned int m_line
= 1;
21084 /* These are initialized in the constructor. */
21086 CORE_ADDR m_address
;
21088 unsigned int m_discriminator
;
21090 /* Additional bits of state we need to track. */
21092 /* The last file that we called dwarf2_start_subfile for.
21093 This is only used for TLLs. */
21094 unsigned int m_last_file
= 0;
21095 /* The last file a line number was recorded for. */
21096 struct subfile
*m_last_subfile
= NULL
;
21098 /* When true, record the lines we decode. */
21099 bool m_currently_recording_lines
= false;
21101 /* The last line number that was recorded, used to coalesce
21102 consecutive entries for the same line. This can happen, for
21103 example, when discriminators are present. PR 17276. */
21104 unsigned int m_last_line
= 0;
21105 bool m_line_has_non_zero_discriminator
= false;
21109 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
21111 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
21112 / m_line_header
->maximum_ops_per_instruction
)
21113 * m_line_header
->minimum_instruction_length
);
21114 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21115 m_op_index
= ((m_op_index
+ adjust
)
21116 % m_line_header
->maximum_ops_per_instruction
);
21120 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
21122 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
21123 CORE_ADDR addr_adj
= (((m_op_index
21124 + (adj_opcode
/ m_line_header
->line_range
))
21125 / m_line_header
->maximum_ops_per_instruction
)
21126 * m_line_header
->minimum_instruction_length
);
21127 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21128 m_op_index
= ((m_op_index
+ (adj_opcode
/ m_line_header
->line_range
))
21129 % m_line_header
->maximum_ops_per_instruction
);
21131 int line_delta
= (m_line_header
->line_base
21132 + (adj_opcode
% m_line_header
->line_range
));
21133 advance_line (line_delta
);
21134 record_line (false);
21135 m_discriminator
= 0;
21139 lnp_state_machine::handle_set_file (file_name_index file
)
21143 const file_entry
*fe
= current_file ();
21145 dwarf2_debug_line_missing_file_complaint ();
21146 else if (m_record_lines_p
)
21148 const char *dir
= fe
->include_dir (m_line_header
);
21150 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21151 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
21152 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
21157 lnp_state_machine::handle_const_add_pc ()
21160 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
21163 = (((m_op_index
+ adjust
)
21164 / m_line_header
->maximum_ops_per_instruction
)
21165 * m_line_header
->minimum_instruction_length
);
21167 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21168 m_op_index
= ((m_op_index
+ adjust
)
21169 % m_line_header
->maximum_ops_per_instruction
);
21172 /* Return non-zero if we should add LINE to the line number table.
21173 LINE is the line to add, LAST_LINE is the last line that was added,
21174 LAST_SUBFILE is the subfile for LAST_LINE.
21175 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
21176 had a non-zero discriminator.
21178 We have to be careful in the presence of discriminators.
21179 E.g., for this line:
21181 for (i = 0; i < 100000; i++);
21183 clang can emit four line number entries for that one line,
21184 each with a different discriminator.
21185 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
21187 However, we want gdb to coalesce all four entries into one.
21188 Otherwise the user could stepi into the middle of the line and
21189 gdb would get confused about whether the pc really was in the
21190 middle of the line.
21192 Things are further complicated by the fact that two consecutive
21193 line number entries for the same line is a heuristic used by gcc
21194 to denote the end of the prologue. So we can't just discard duplicate
21195 entries, we have to be selective about it. The heuristic we use is
21196 that we only collapse consecutive entries for the same line if at least
21197 one of those entries has a non-zero discriminator. PR 17276.
21199 Note: Addresses in the line number state machine can never go backwards
21200 within one sequence, thus this coalescing is ok. */
21203 dwarf_record_line_p (struct dwarf2_cu
*cu
,
21204 unsigned int line
, unsigned int last_line
,
21205 int line_has_non_zero_discriminator
,
21206 struct subfile
*last_subfile
)
21208 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
21210 if (line
!= last_line
)
21212 /* Same line for the same file that we've seen already.
21213 As a last check, for pr 17276, only record the line if the line
21214 has never had a non-zero discriminator. */
21215 if (!line_has_non_zero_discriminator
)
21220 /* Use the CU's builder to record line number LINE beginning at
21221 address ADDRESS in the line table of subfile SUBFILE. */
21224 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21225 unsigned int line
, CORE_ADDR address
,
21226 struct dwarf2_cu
*cu
)
21228 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
21230 if (dwarf_line_debug
)
21232 fprintf_unfiltered (gdb_stdlog
,
21233 "Recording line %u, file %s, address %s\n",
21234 line
, lbasename (subfile
->name
),
21235 paddress (gdbarch
, address
));
21239 cu
->get_builder ()->record_line (subfile
, line
, addr
);
21242 /* Subroutine of dwarf_decode_lines_1 to simplify it.
21243 Mark the end of a set of line number records.
21244 The arguments are the same as for dwarf_record_line_1.
21245 If SUBFILE is NULL the request is ignored. */
21248 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21249 CORE_ADDR address
, struct dwarf2_cu
*cu
)
21251 if (subfile
== NULL
)
21254 if (dwarf_line_debug
)
21256 fprintf_unfiltered (gdb_stdlog
,
21257 "Finishing current line, file %s, address %s\n",
21258 lbasename (subfile
->name
),
21259 paddress (gdbarch
, address
));
21262 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, cu
);
21266 lnp_state_machine::record_line (bool end_sequence
)
21268 if (dwarf_line_debug
)
21270 fprintf_unfiltered (gdb_stdlog
,
21271 "Processing actual line %u: file %u,"
21272 " address %s, is_stmt %u, discrim %u%s\n",
21274 paddress (m_gdbarch
, m_address
),
21275 m_is_stmt
, m_discriminator
,
21276 (end_sequence
? "\t(end sequence)" : ""));
21279 file_entry
*fe
= current_file ();
21282 dwarf2_debug_line_missing_file_complaint ();
21283 /* For now we ignore lines not starting on an instruction boundary.
21284 But not when processing end_sequence for compatibility with the
21285 previous version of the code. */
21286 else if (m_op_index
== 0 || end_sequence
)
21288 fe
->included_p
= 1;
21289 if (m_record_lines_p
21290 && (producer_is_codewarrior (m_cu
) || m_is_stmt
|| end_sequence
))
21292 if (m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ()
21295 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
21296 m_currently_recording_lines
? m_cu
: nullptr);
21301 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
21302 m_line_has_non_zero_discriminator
,
21305 buildsym_compunit
*builder
= m_cu
->get_builder ();
21306 dwarf_record_line_1 (m_gdbarch
,
21307 builder
->get_current_subfile (),
21309 m_currently_recording_lines
? m_cu
: nullptr);
21311 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21312 m_last_line
= m_line
;
21318 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
21319 line_header
*lh
, bool record_lines_p
)
21323 m_record_lines_p
= record_lines_p
;
21324 m_line_header
= lh
;
21326 m_currently_recording_lines
= true;
21328 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
21329 was a line entry for it so that the backend has a chance to adjust it
21330 and also record it in case it needs it. This is currently used by MIPS
21331 code, cf. `mips_adjust_dwarf2_line'. */
21332 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
21333 m_is_stmt
= lh
->default_is_stmt
;
21334 m_discriminator
= 0;
21338 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
21339 const gdb_byte
*line_ptr
,
21340 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
21342 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
21343 the pc range of the CU. However, we restrict the test to only ADDRESS
21344 values of zero to preserve GDB's previous behaviour which is to handle
21345 the specific case of a function being GC'd by the linker. */
21347 if (address
== 0 && address
< unrelocated_lowpc
)
21349 /* This line table is for a function which has been
21350 GCd by the linker. Ignore it. PR gdb/12528 */
21352 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21353 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
21355 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
21356 line_offset
, objfile_name (objfile
));
21357 m_currently_recording_lines
= false;
21358 /* Note: m_currently_recording_lines is left as false until we see
21359 DW_LNE_end_sequence. */
21363 /* Subroutine of dwarf_decode_lines to simplify it.
21364 Process the line number information in LH.
21365 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
21366 program in order to set included_p for every referenced header. */
21369 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
21370 const int decode_for_pst_p
, CORE_ADDR lowpc
)
21372 const gdb_byte
*line_ptr
, *extended_end
;
21373 const gdb_byte
*line_end
;
21374 unsigned int bytes_read
, extended_len
;
21375 unsigned char op_code
, extended_op
;
21376 CORE_ADDR baseaddr
;
21377 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21378 bfd
*abfd
= objfile
->obfd
;
21379 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21380 /* True if we're recording line info (as opposed to building partial
21381 symtabs and just interested in finding include files mentioned by
21382 the line number program). */
21383 bool record_lines_p
= !decode_for_pst_p
;
21385 baseaddr
= objfile
->text_section_offset ();
21387 line_ptr
= lh
->statement_program_start
;
21388 line_end
= lh
->statement_program_end
;
21390 /* Read the statement sequences until there's nothing left. */
21391 while (line_ptr
< line_end
)
21393 /* The DWARF line number program state machine. Reset the state
21394 machine at the start of each sequence. */
21395 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
21396 bool end_sequence
= false;
21398 if (record_lines_p
)
21400 /* Start a subfile for the current file of the state
21402 const file_entry
*fe
= state_machine
.current_file ();
21405 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
21408 /* Decode the table. */
21409 while (line_ptr
< line_end
&& !end_sequence
)
21411 op_code
= read_1_byte (abfd
, line_ptr
);
21414 if (op_code
>= lh
->opcode_base
)
21416 /* Special opcode. */
21417 state_machine
.handle_special_opcode (op_code
);
21419 else switch (op_code
)
21421 case DW_LNS_extended_op
:
21422 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
21424 line_ptr
+= bytes_read
;
21425 extended_end
= line_ptr
+ extended_len
;
21426 extended_op
= read_1_byte (abfd
, line_ptr
);
21428 switch (extended_op
)
21430 case DW_LNE_end_sequence
:
21431 state_machine
.handle_end_sequence ();
21432 end_sequence
= true;
21434 case DW_LNE_set_address
:
21437 = read_address (abfd
, line_ptr
, cu
, &bytes_read
);
21438 line_ptr
+= bytes_read
;
21440 state_machine
.check_line_address (cu
, line_ptr
,
21441 lowpc
- baseaddr
, address
);
21442 state_machine
.handle_set_address (baseaddr
, address
);
21445 case DW_LNE_define_file
:
21447 const char *cur_file
;
21448 unsigned int mod_time
, length
;
21451 cur_file
= read_direct_string (abfd
, line_ptr
,
21453 line_ptr
+= bytes_read
;
21454 dindex
= (dir_index
)
21455 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21456 line_ptr
+= bytes_read
;
21458 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21459 line_ptr
+= bytes_read
;
21461 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21462 line_ptr
+= bytes_read
;
21463 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
21466 case DW_LNE_set_discriminator
:
21468 /* The discriminator is not interesting to the
21469 debugger; just ignore it. We still need to
21470 check its value though:
21471 if there are consecutive entries for the same
21472 (non-prologue) line we want to coalesce them.
21475 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21476 line_ptr
+= bytes_read
;
21478 state_machine
.handle_set_discriminator (discr
);
21482 complaint (_("mangled .debug_line section"));
21485 /* Make sure that we parsed the extended op correctly. If e.g.
21486 we expected a different address size than the producer used,
21487 we may have read the wrong number of bytes. */
21488 if (line_ptr
!= extended_end
)
21490 complaint (_("mangled .debug_line section"));
21495 state_machine
.handle_copy ();
21497 case DW_LNS_advance_pc
:
21500 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21501 line_ptr
+= bytes_read
;
21503 state_machine
.handle_advance_pc (adjust
);
21506 case DW_LNS_advance_line
:
21509 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
21510 line_ptr
+= bytes_read
;
21512 state_machine
.handle_advance_line (line_delta
);
21515 case DW_LNS_set_file
:
21517 file_name_index file
21518 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
21520 line_ptr
+= bytes_read
;
21522 state_machine
.handle_set_file (file
);
21525 case DW_LNS_set_column
:
21526 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21527 line_ptr
+= bytes_read
;
21529 case DW_LNS_negate_stmt
:
21530 state_machine
.handle_negate_stmt ();
21532 case DW_LNS_set_basic_block
:
21534 /* Add to the address register of the state machine the
21535 address increment value corresponding to special opcode
21536 255. I.e., this value is scaled by the minimum
21537 instruction length since special opcode 255 would have
21538 scaled the increment. */
21539 case DW_LNS_const_add_pc
:
21540 state_machine
.handle_const_add_pc ();
21542 case DW_LNS_fixed_advance_pc
:
21544 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
21547 state_machine
.handle_fixed_advance_pc (addr_adj
);
21552 /* Unknown standard opcode, ignore it. */
21555 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
21557 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21558 line_ptr
+= bytes_read
;
21565 dwarf2_debug_line_missing_end_sequence_complaint ();
21567 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
21568 in which case we still finish recording the last line). */
21569 state_machine
.record_line (true);
21573 /* Decode the Line Number Program (LNP) for the given line_header
21574 structure and CU. The actual information extracted and the type
21575 of structures created from the LNP depends on the value of PST.
21577 1. If PST is NULL, then this procedure uses the data from the program
21578 to create all necessary symbol tables, and their linetables.
21580 2. If PST is not NULL, this procedure reads the program to determine
21581 the list of files included by the unit represented by PST, and
21582 builds all the associated partial symbol tables.
21584 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
21585 It is used for relative paths in the line table.
21586 NOTE: When processing partial symtabs (pst != NULL),
21587 comp_dir == pst->dirname.
21589 NOTE: It is important that psymtabs have the same file name (via strcmp)
21590 as the corresponding symtab. Since COMP_DIR is not used in the name of the
21591 symtab we don't use it in the name of the psymtabs we create.
21592 E.g. expand_line_sal requires this when finding psymtabs to expand.
21593 A good testcase for this is mb-inline.exp.
21595 LOWPC is the lowest address in CU (or 0 if not known).
21597 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
21598 for its PC<->lines mapping information. Otherwise only the filename
21599 table is read in. */
21602 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
21603 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
21604 CORE_ADDR lowpc
, int decode_mapping
)
21606 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21607 const int decode_for_pst_p
= (pst
!= NULL
);
21609 if (decode_mapping
)
21610 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
21612 if (decode_for_pst_p
)
21614 /* Now that we're done scanning the Line Header Program, we can
21615 create the psymtab of each included file. */
21616 for (auto &file_entry
: lh
->file_names ())
21617 if (file_entry
.included_p
== 1)
21619 gdb::unique_xmalloc_ptr
<char> name_holder
;
21620 const char *include_name
=
21621 psymtab_include_file_name (lh
, file_entry
, pst
,
21622 comp_dir
, &name_holder
);
21623 if (include_name
!= NULL
)
21624 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
21629 /* Make sure a symtab is created for every file, even files
21630 which contain only variables (i.e. no code with associated
21632 buildsym_compunit
*builder
= cu
->get_builder ();
21633 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
21635 for (auto &fe
: lh
->file_names ())
21637 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
21638 if (builder
->get_current_subfile ()->symtab
== NULL
)
21640 builder
->get_current_subfile ()->symtab
21641 = allocate_symtab (cust
,
21642 builder
->get_current_subfile ()->name
);
21644 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
21649 /* Start a subfile for DWARF. FILENAME is the name of the file and
21650 DIRNAME the name of the source directory which contains FILENAME
21651 or NULL if not known.
21652 This routine tries to keep line numbers from identical absolute and
21653 relative file names in a common subfile.
21655 Using the `list' example from the GDB testsuite, which resides in
21656 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
21657 of /srcdir/list0.c yields the following debugging information for list0.c:
21659 DW_AT_name: /srcdir/list0.c
21660 DW_AT_comp_dir: /compdir
21661 files.files[0].name: list0.h
21662 files.files[0].dir: /srcdir
21663 files.files[1].name: list0.c
21664 files.files[1].dir: /srcdir
21666 The line number information for list0.c has to end up in a single
21667 subfile, so that `break /srcdir/list0.c:1' works as expected.
21668 start_subfile will ensure that this happens provided that we pass the
21669 concatenation of files.files[1].dir and files.files[1].name as the
21673 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
21674 const char *dirname
)
21676 gdb::unique_xmalloc_ptr
<char> copy
;
21678 /* In order not to lose the line information directory,
21679 we concatenate it to the filename when it makes sense.
21680 Note that the Dwarf3 standard says (speaking of filenames in line
21681 information): ``The directory index is ignored for file names
21682 that represent full path names''. Thus ignoring dirname in the
21683 `else' branch below isn't an issue. */
21685 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
21687 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
21688 filename
= copy
.get ();
21691 cu
->get_builder ()->start_subfile (filename
);
21694 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
21695 buildsym_compunit constructor. */
21697 struct compunit_symtab
*
21698 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
21701 gdb_assert (m_builder
== nullptr);
21703 m_builder
.reset (new struct buildsym_compunit
21704 (per_cu
->dwarf2_per_objfile
->objfile
,
21705 name
, comp_dir
, language
, low_pc
));
21707 list_in_scope
= get_builder ()->get_file_symbols ();
21709 get_builder ()->record_debugformat ("DWARF 2");
21710 get_builder ()->record_producer (producer
);
21712 processing_has_namespace_info
= false;
21714 return get_builder ()->get_compunit_symtab ();
21718 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
21719 struct dwarf2_cu
*cu
)
21721 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21722 struct comp_unit_head
*cu_header
= &cu
->header
;
21724 /* NOTE drow/2003-01-30: There used to be a comment and some special
21725 code here to turn a symbol with DW_AT_external and a
21726 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
21727 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
21728 with some versions of binutils) where shared libraries could have
21729 relocations against symbols in their debug information - the
21730 minimal symbol would have the right address, but the debug info
21731 would not. It's no longer necessary, because we will explicitly
21732 apply relocations when we read in the debug information now. */
21734 /* A DW_AT_location attribute with no contents indicates that a
21735 variable has been optimized away. */
21736 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
21738 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21742 /* Handle one degenerate form of location expression specially, to
21743 preserve GDB's previous behavior when section offsets are
21744 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
21745 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
21747 if (attr_form_is_block (attr
)
21748 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
21749 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
21750 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
21751 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
21752 && (DW_BLOCK (attr
)->size
21753 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
21755 unsigned int dummy
;
21757 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
21758 SET_SYMBOL_VALUE_ADDRESS (sym
,
21759 read_address (objfile
->obfd
,
21760 DW_BLOCK (attr
)->data
+ 1,
21763 SET_SYMBOL_VALUE_ADDRESS
21764 (sym
, read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1,
21766 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
21767 fixup_symbol_section (sym
, objfile
);
21768 SET_SYMBOL_VALUE_ADDRESS
21770 SYMBOL_VALUE_ADDRESS (sym
)
21771 + objfile
->section_offsets
[SYMBOL_SECTION (sym
)]);
21775 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
21776 expression evaluator, and use LOC_COMPUTED only when necessary
21777 (i.e. when the value of a register or memory location is
21778 referenced, or a thread-local block, etc.). Then again, it might
21779 not be worthwhile. I'm assuming that it isn't unless performance
21780 or memory numbers show me otherwise. */
21782 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
21784 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
21785 cu
->has_loclist
= true;
21788 /* Given a pointer to a DWARF information entry, figure out if we need
21789 to make a symbol table entry for it, and if so, create a new entry
21790 and return a pointer to it.
21791 If TYPE is NULL, determine symbol type from the die, otherwise
21792 used the passed type.
21793 If SPACE is not NULL, use it to hold the new symbol. If it is
21794 NULL, allocate a new symbol on the objfile's obstack. */
21796 static struct symbol
*
21797 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
21798 struct symbol
*space
)
21800 struct dwarf2_per_objfile
*dwarf2_per_objfile
21801 = cu
->per_cu
->dwarf2_per_objfile
;
21802 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21803 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21804 struct symbol
*sym
= NULL
;
21806 struct attribute
*attr
= NULL
;
21807 struct attribute
*attr2
= NULL
;
21808 CORE_ADDR baseaddr
;
21809 struct pending
**list_to_add
= NULL
;
21811 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
21813 baseaddr
= objfile
->text_section_offset ();
21815 name
= dwarf2_name (die
, cu
);
21818 const char *linkagename
;
21819 int suppress_add
= 0;
21824 sym
= allocate_symbol (objfile
);
21825 OBJSTAT (objfile
, n_syms
++);
21827 /* Cache this symbol's name and the name's demangled form (if any). */
21828 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
21829 linkagename
= dwarf2_physname (name
, die
, cu
);
21830 sym
->compute_and_set_names (linkagename
, false, objfile
->per_bfd
);
21832 /* Fortran does not have mangling standard and the mangling does differ
21833 between gfortran, iFort etc. */
21834 if (cu
->language
== language_fortran
21835 && symbol_get_demangled_name (sym
) == NULL
)
21836 symbol_set_demangled_name (sym
,
21837 dwarf2_full_name (name
, die
, cu
),
21840 /* Default assumptions.
21841 Use the passed type or decode it from the die. */
21842 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21843 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21845 SYMBOL_TYPE (sym
) = type
;
21847 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
21848 attr
= dwarf2_attr (die
,
21849 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
21851 if (attr
!= nullptr)
21853 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
21856 attr
= dwarf2_attr (die
,
21857 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
21859 if (attr
!= nullptr)
21861 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
21862 struct file_entry
*fe
;
21864 if (cu
->line_header
!= NULL
)
21865 fe
= cu
->line_header
->file_name_at (file_index
);
21870 complaint (_("file index out of range"));
21872 symbol_set_symtab (sym
, fe
->symtab
);
21878 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
21879 if (attr
!= nullptr)
21883 addr
= attr_value_as_address (attr
);
21884 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
21885 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
21887 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
21888 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
21889 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
21890 add_symbol_to_list (sym
, cu
->list_in_scope
);
21892 case DW_TAG_subprogram
:
21893 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21895 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21896 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21897 if ((attr2
&& (DW_UNSND (attr2
) != 0))
21898 || cu
->language
== language_ada
21899 || cu
->language
== language_fortran
)
21901 /* Subprograms marked external are stored as a global symbol.
21902 Ada and Fortran subprograms, whether marked external or
21903 not, are always stored as a global symbol, because we want
21904 to be able to access them globally. For instance, we want
21905 to be able to break on a nested subprogram without having
21906 to specify the context. */
21907 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21911 list_to_add
= cu
->list_in_scope
;
21914 case DW_TAG_inlined_subroutine
:
21915 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21917 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21918 SYMBOL_INLINED (sym
) = 1;
21919 list_to_add
= cu
->list_in_scope
;
21921 case DW_TAG_template_value_param
:
21923 /* Fall through. */
21924 case DW_TAG_constant
:
21925 case DW_TAG_variable
:
21926 case DW_TAG_member
:
21927 /* Compilation with minimal debug info may result in
21928 variables with missing type entries. Change the
21929 misleading `void' type to something sensible. */
21930 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
21931 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
21933 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21934 /* In the case of DW_TAG_member, we should only be called for
21935 static const members. */
21936 if (die
->tag
== DW_TAG_member
)
21938 /* dwarf2_add_field uses die_is_declaration,
21939 so we do the same. */
21940 gdb_assert (die_is_declaration (die
, cu
));
21943 if (attr
!= nullptr)
21945 dwarf2_const_value (attr
, sym
, cu
);
21946 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21949 if (attr2
&& (DW_UNSND (attr2
) != 0))
21950 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21952 list_to_add
= cu
->list_in_scope
;
21956 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21957 if (attr
!= nullptr)
21959 var_decode_location (attr
, sym
, cu
);
21960 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21962 /* Fortran explicitly imports any global symbols to the local
21963 scope by DW_TAG_common_block. */
21964 if (cu
->language
== language_fortran
&& die
->parent
21965 && die
->parent
->tag
== DW_TAG_common_block
)
21968 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21969 && SYMBOL_VALUE_ADDRESS (sym
) == 0
21970 && !dwarf2_per_objfile
->has_section_at_zero
)
21972 /* When a static variable is eliminated by the linker,
21973 the corresponding debug information is not stripped
21974 out, but the variable address is set to null;
21975 do not add such variables into symbol table. */
21977 else if (attr2
&& (DW_UNSND (attr2
) != 0))
21979 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21980 && (objfile
->flags
& OBJF_MAINLINE
) == 0
21981 && dwarf2_per_objfile
->can_copy
)
21983 /* A global static variable might be subject to
21984 copy relocation. We first check for a local
21985 minsym, though, because maybe the symbol was
21986 marked hidden, in which case this would not
21988 bound_minimal_symbol found
21989 = (lookup_minimal_symbol_linkage
21990 (sym
->linkage_name (), objfile
));
21991 if (found
.minsym
!= nullptr)
21992 sym
->maybe_copied
= 1;
21995 /* A variable with DW_AT_external is never static,
21996 but it may be block-scoped. */
21998 = ((cu
->list_in_scope
21999 == cu
->get_builder ()->get_file_symbols ())
22000 ? cu
->get_builder ()->get_global_symbols ()
22001 : cu
->list_in_scope
);
22004 list_to_add
= cu
->list_in_scope
;
22008 /* We do not know the address of this symbol.
22009 If it is an external symbol and we have type information
22010 for it, enter the symbol as a LOC_UNRESOLVED symbol.
22011 The address of the variable will then be determined from
22012 the minimal symbol table whenever the variable is
22014 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
22016 /* Fortran explicitly imports any global symbols to the local
22017 scope by DW_TAG_common_block. */
22018 if (cu
->language
== language_fortran
&& die
->parent
22019 && die
->parent
->tag
== DW_TAG_common_block
)
22021 /* SYMBOL_CLASS doesn't matter here because
22022 read_common_block is going to reset it. */
22024 list_to_add
= cu
->list_in_scope
;
22026 else if (attr2
&& (DW_UNSND (attr2
) != 0)
22027 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
22029 /* A variable with DW_AT_external is never static, but it
22030 may be block-scoped. */
22032 = ((cu
->list_in_scope
22033 == cu
->get_builder ()->get_file_symbols ())
22034 ? cu
->get_builder ()->get_global_symbols ()
22035 : cu
->list_in_scope
);
22037 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
22039 else if (!die_is_declaration (die
, cu
))
22041 /* Use the default LOC_OPTIMIZED_OUT class. */
22042 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
22044 list_to_add
= cu
->list_in_scope
;
22048 case DW_TAG_formal_parameter
:
22050 /* If we are inside a function, mark this as an argument. If
22051 not, we might be looking at an argument to an inlined function
22052 when we do not have enough information to show inlined frames;
22053 pretend it's a local variable in that case so that the user can
22055 struct context_stack
*curr
22056 = cu
->get_builder ()->get_current_context_stack ();
22057 if (curr
!= nullptr && curr
->name
!= nullptr)
22058 SYMBOL_IS_ARGUMENT (sym
) = 1;
22059 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22060 if (attr
!= nullptr)
22062 var_decode_location (attr
, sym
, cu
);
22064 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22065 if (attr
!= nullptr)
22067 dwarf2_const_value (attr
, sym
, cu
);
22070 list_to_add
= cu
->list_in_scope
;
22073 case DW_TAG_unspecified_parameters
:
22074 /* From varargs functions; gdb doesn't seem to have any
22075 interest in this information, so just ignore it for now.
22078 case DW_TAG_template_type_param
:
22080 /* Fall through. */
22081 case DW_TAG_class_type
:
22082 case DW_TAG_interface_type
:
22083 case DW_TAG_structure_type
:
22084 case DW_TAG_union_type
:
22085 case DW_TAG_set_type
:
22086 case DW_TAG_enumeration_type
:
22087 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22088 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
22091 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
22092 really ever be static objects: otherwise, if you try
22093 to, say, break of a class's method and you're in a file
22094 which doesn't mention that class, it won't work unless
22095 the check for all static symbols in lookup_symbol_aux
22096 saves you. See the OtherFileClass tests in
22097 gdb.c++/namespace.exp. */
22101 buildsym_compunit
*builder
= cu
->get_builder ();
22103 = (cu
->list_in_scope
== builder
->get_file_symbols ()
22104 && cu
->language
== language_cplus
22105 ? builder
->get_global_symbols ()
22106 : cu
->list_in_scope
);
22108 /* The semantics of C++ state that "struct foo {
22109 ... }" also defines a typedef for "foo". */
22110 if (cu
->language
== language_cplus
22111 || cu
->language
== language_ada
22112 || cu
->language
== language_d
22113 || cu
->language
== language_rust
)
22115 /* The symbol's name is already allocated along
22116 with this objfile, so we don't need to
22117 duplicate it for the type. */
22118 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
22119 TYPE_NAME (SYMBOL_TYPE (sym
)) = sym
->search_name ();
22124 case DW_TAG_typedef
:
22125 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22126 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
22127 list_to_add
= cu
->list_in_scope
;
22129 case DW_TAG_base_type
:
22130 case DW_TAG_subrange_type
:
22131 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22132 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
22133 list_to_add
= cu
->list_in_scope
;
22135 case DW_TAG_enumerator
:
22136 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22137 if (attr
!= nullptr)
22139 dwarf2_const_value (attr
, sym
, cu
);
22142 /* NOTE: carlton/2003-11-10: See comment above in the
22143 DW_TAG_class_type, etc. block. */
22146 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
22147 && cu
->language
== language_cplus
22148 ? cu
->get_builder ()->get_global_symbols ()
22149 : cu
->list_in_scope
);
22152 case DW_TAG_imported_declaration
:
22153 case DW_TAG_namespace
:
22154 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22155 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22157 case DW_TAG_module
:
22158 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22159 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
22160 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22162 case DW_TAG_common_block
:
22163 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
22164 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
22165 add_symbol_to_list (sym
, cu
->list_in_scope
);
22168 /* Not a tag we recognize. Hopefully we aren't processing
22169 trash data, but since we must specifically ignore things
22170 we don't recognize, there is nothing else we should do at
22172 complaint (_("unsupported tag: '%s'"),
22173 dwarf_tag_name (die
->tag
));
22179 sym
->hash_next
= objfile
->template_symbols
;
22180 objfile
->template_symbols
= sym
;
22181 list_to_add
= NULL
;
22184 if (list_to_add
!= NULL
)
22185 add_symbol_to_list (sym
, list_to_add
);
22187 /* For the benefit of old versions of GCC, check for anonymous
22188 namespaces based on the demangled name. */
22189 if (!cu
->processing_has_namespace_info
22190 && cu
->language
== language_cplus
)
22191 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
22196 /* Given an attr with a DW_FORM_dataN value in host byte order,
22197 zero-extend it as appropriate for the symbol's type. The DWARF
22198 standard (v4) is not entirely clear about the meaning of using
22199 DW_FORM_dataN for a constant with a signed type, where the type is
22200 wider than the data. The conclusion of a discussion on the DWARF
22201 list was that this is unspecified. We choose to always zero-extend
22202 because that is the interpretation long in use by GCC. */
22205 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
22206 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
22208 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22209 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
22210 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
22211 LONGEST l
= DW_UNSND (attr
);
22213 if (bits
< sizeof (*value
) * 8)
22215 l
&= ((LONGEST
) 1 << bits
) - 1;
22218 else if (bits
== sizeof (*value
) * 8)
22222 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
22223 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
22230 /* Read a constant value from an attribute. Either set *VALUE, or if
22231 the value does not fit in *VALUE, set *BYTES - either already
22232 allocated on the objfile obstack, or newly allocated on OBSTACK,
22233 or, set *BATON, if we translated the constant to a location
22237 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
22238 const char *name
, struct obstack
*obstack
,
22239 struct dwarf2_cu
*cu
,
22240 LONGEST
*value
, const gdb_byte
**bytes
,
22241 struct dwarf2_locexpr_baton
**baton
)
22243 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22244 struct comp_unit_head
*cu_header
= &cu
->header
;
22245 struct dwarf_block
*blk
;
22246 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
22247 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22253 switch (attr
->form
)
22256 case DW_FORM_addrx
:
22257 case DW_FORM_GNU_addr_index
:
22261 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
22262 dwarf2_const_value_length_mismatch_complaint (name
,
22263 cu_header
->addr_size
,
22264 TYPE_LENGTH (type
));
22265 /* Symbols of this form are reasonably rare, so we just
22266 piggyback on the existing location code rather than writing
22267 a new implementation of symbol_computed_ops. */
22268 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
22269 (*baton
)->per_cu
= cu
->per_cu
;
22270 gdb_assert ((*baton
)->per_cu
);
22272 (*baton
)->size
= 2 + cu_header
->addr_size
;
22273 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
22274 (*baton
)->data
= data
;
22276 data
[0] = DW_OP_addr
;
22277 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
22278 byte_order
, DW_ADDR (attr
));
22279 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
22282 case DW_FORM_string
:
22285 case DW_FORM_GNU_str_index
:
22286 case DW_FORM_GNU_strp_alt
:
22287 /* DW_STRING is already allocated on the objfile obstack, point
22289 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
22291 case DW_FORM_block1
:
22292 case DW_FORM_block2
:
22293 case DW_FORM_block4
:
22294 case DW_FORM_block
:
22295 case DW_FORM_exprloc
:
22296 case DW_FORM_data16
:
22297 blk
= DW_BLOCK (attr
);
22298 if (TYPE_LENGTH (type
) != blk
->size
)
22299 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
22300 TYPE_LENGTH (type
));
22301 *bytes
= blk
->data
;
22304 /* The DW_AT_const_value attributes are supposed to carry the
22305 symbol's value "represented as it would be on the target
22306 architecture." By the time we get here, it's already been
22307 converted to host endianness, so we just need to sign- or
22308 zero-extend it as appropriate. */
22309 case DW_FORM_data1
:
22310 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
22312 case DW_FORM_data2
:
22313 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
22315 case DW_FORM_data4
:
22316 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
22318 case DW_FORM_data8
:
22319 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
22322 case DW_FORM_sdata
:
22323 case DW_FORM_implicit_const
:
22324 *value
= DW_SND (attr
);
22327 case DW_FORM_udata
:
22328 *value
= DW_UNSND (attr
);
22332 complaint (_("unsupported const value attribute form: '%s'"),
22333 dwarf_form_name (attr
->form
));
22340 /* Copy constant value from an attribute to a symbol. */
22343 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
22344 struct dwarf2_cu
*cu
)
22346 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22348 const gdb_byte
*bytes
;
22349 struct dwarf2_locexpr_baton
*baton
;
22351 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
22352 sym
->print_name (),
22353 &objfile
->objfile_obstack
, cu
,
22354 &value
, &bytes
, &baton
);
22358 SYMBOL_LOCATION_BATON (sym
) = baton
;
22359 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
22361 else if (bytes
!= NULL
)
22363 SYMBOL_VALUE_BYTES (sym
) = bytes
;
22364 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
22368 SYMBOL_VALUE (sym
) = value
;
22369 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
22373 /* Return the type of the die in question using its DW_AT_type attribute. */
22375 static struct type
*
22376 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22378 struct attribute
*type_attr
;
22380 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
22383 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22384 /* A missing DW_AT_type represents a void type. */
22385 return objfile_type (objfile
)->builtin_void
;
22388 return lookup_die_type (die
, type_attr
, cu
);
22391 /* True iff CU's producer generates GNAT Ada auxiliary information
22392 that allows to find parallel types through that information instead
22393 of having to do expensive parallel lookups by type name. */
22396 need_gnat_info (struct dwarf2_cu
*cu
)
22398 /* Assume that the Ada compiler was GNAT, which always produces
22399 the auxiliary information. */
22400 return (cu
->language
== language_ada
);
22403 /* Return the auxiliary type of the die in question using its
22404 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
22405 attribute is not present. */
22407 static struct type
*
22408 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22410 struct attribute
*type_attr
;
22412 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
22416 return lookup_die_type (die
, type_attr
, cu
);
22419 /* If DIE has a descriptive_type attribute, then set the TYPE's
22420 descriptive type accordingly. */
22423 set_descriptive_type (struct type
*type
, struct die_info
*die
,
22424 struct dwarf2_cu
*cu
)
22426 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
22428 if (descriptive_type
)
22430 ALLOCATE_GNAT_AUX_TYPE (type
);
22431 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
22435 /* Return the containing type of the die in question using its
22436 DW_AT_containing_type attribute. */
22438 static struct type
*
22439 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22441 struct attribute
*type_attr
;
22442 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22444 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
22446 error (_("Dwarf Error: Problem turning containing type into gdb type "
22447 "[in module %s]"), objfile_name (objfile
));
22449 return lookup_die_type (die
, type_attr
, cu
);
22452 /* Return an error marker type to use for the ill formed type in DIE/CU. */
22454 static struct type
*
22455 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
22457 struct dwarf2_per_objfile
*dwarf2_per_objfile
22458 = cu
->per_cu
->dwarf2_per_objfile
;
22459 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22462 std::string message
22463 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
22464 objfile_name (objfile
),
22465 sect_offset_str (cu
->header
.sect_off
),
22466 sect_offset_str (die
->sect_off
));
22467 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
22469 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
22472 /* Look up the type of DIE in CU using its type attribute ATTR.
22473 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
22474 DW_AT_containing_type.
22475 If there is no type substitute an error marker. */
22477 static struct type
*
22478 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
22479 struct dwarf2_cu
*cu
)
22481 struct dwarf2_per_objfile
*dwarf2_per_objfile
22482 = cu
->per_cu
->dwarf2_per_objfile
;
22483 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22484 struct type
*this_type
;
22486 gdb_assert (attr
->name
== DW_AT_type
22487 || attr
->name
== DW_AT_GNAT_descriptive_type
22488 || attr
->name
== DW_AT_containing_type
);
22490 /* First see if we have it cached. */
22492 if (attr
->form
== DW_FORM_GNU_ref_alt
)
22494 struct dwarf2_per_cu_data
*per_cu
;
22495 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22497 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
22498 dwarf2_per_objfile
);
22499 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
22501 else if (attr_form_is_ref (attr
))
22503 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22505 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
22507 else if (attr
->form
== DW_FORM_ref_sig8
)
22509 ULONGEST signature
= DW_SIGNATURE (attr
);
22511 return get_signatured_type (die
, signature
, cu
);
22515 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
22516 " at %s [in module %s]"),
22517 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
22518 objfile_name (objfile
));
22519 return build_error_marker_type (cu
, die
);
22522 /* If not cached we need to read it in. */
22524 if (this_type
== NULL
)
22526 struct die_info
*type_die
= NULL
;
22527 struct dwarf2_cu
*type_cu
= cu
;
22529 if (attr_form_is_ref (attr
))
22530 type_die
= follow_die_ref (die
, attr
, &type_cu
);
22531 if (type_die
== NULL
)
22532 return build_error_marker_type (cu
, die
);
22533 /* If we find the type now, it's probably because the type came
22534 from an inter-CU reference and the type's CU got expanded before
22536 this_type
= read_type_die (type_die
, type_cu
);
22539 /* If we still don't have a type use an error marker. */
22541 if (this_type
== NULL
)
22542 return build_error_marker_type (cu
, die
);
22547 /* Return the type in DIE, CU.
22548 Returns NULL for invalid types.
22550 This first does a lookup in die_type_hash,
22551 and only reads the die in if necessary.
22553 NOTE: This can be called when reading in partial or full symbols. */
22555 static struct type
*
22556 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
22558 struct type
*this_type
;
22560 this_type
= get_die_type (die
, cu
);
22564 return read_type_die_1 (die
, cu
);
22567 /* Read the type in DIE, CU.
22568 Returns NULL for invalid types. */
22570 static struct type
*
22571 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
22573 struct type
*this_type
= NULL
;
22577 case DW_TAG_class_type
:
22578 case DW_TAG_interface_type
:
22579 case DW_TAG_structure_type
:
22580 case DW_TAG_union_type
:
22581 this_type
= read_structure_type (die
, cu
);
22583 case DW_TAG_enumeration_type
:
22584 this_type
= read_enumeration_type (die
, cu
);
22586 case DW_TAG_subprogram
:
22587 case DW_TAG_subroutine_type
:
22588 case DW_TAG_inlined_subroutine
:
22589 this_type
= read_subroutine_type (die
, cu
);
22591 case DW_TAG_array_type
:
22592 this_type
= read_array_type (die
, cu
);
22594 case DW_TAG_set_type
:
22595 this_type
= read_set_type (die
, cu
);
22597 case DW_TAG_pointer_type
:
22598 this_type
= read_tag_pointer_type (die
, cu
);
22600 case DW_TAG_ptr_to_member_type
:
22601 this_type
= read_tag_ptr_to_member_type (die
, cu
);
22603 case DW_TAG_reference_type
:
22604 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
22606 case DW_TAG_rvalue_reference_type
:
22607 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
22609 case DW_TAG_const_type
:
22610 this_type
= read_tag_const_type (die
, cu
);
22612 case DW_TAG_volatile_type
:
22613 this_type
= read_tag_volatile_type (die
, cu
);
22615 case DW_TAG_restrict_type
:
22616 this_type
= read_tag_restrict_type (die
, cu
);
22618 case DW_TAG_string_type
:
22619 this_type
= read_tag_string_type (die
, cu
);
22621 case DW_TAG_typedef
:
22622 this_type
= read_typedef (die
, cu
);
22624 case DW_TAG_subrange_type
:
22625 this_type
= read_subrange_type (die
, cu
);
22627 case DW_TAG_base_type
:
22628 this_type
= read_base_type (die
, cu
);
22630 case DW_TAG_unspecified_type
:
22631 this_type
= read_unspecified_type (die
, cu
);
22633 case DW_TAG_namespace
:
22634 this_type
= read_namespace_type (die
, cu
);
22636 case DW_TAG_module
:
22637 this_type
= read_module_type (die
, cu
);
22639 case DW_TAG_atomic_type
:
22640 this_type
= read_tag_atomic_type (die
, cu
);
22643 complaint (_("unexpected tag in read_type_die: '%s'"),
22644 dwarf_tag_name (die
->tag
));
22651 /* See if we can figure out if the class lives in a namespace. We do
22652 this by looking for a member function; its demangled name will
22653 contain namespace info, if there is any.
22654 Return the computed name or NULL.
22655 Space for the result is allocated on the objfile's obstack.
22656 This is the full-die version of guess_partial_die_structure_name.
22657 In this case we know DIE has no useful parent. */
22659 static const char *
22660 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22662 struct die_info
*spec_die
;
22663 struct dwarf2_cu
*spec_cu
;
22664 struct die_info
*child
;
22665 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22668 spec_die
= die_specification (die
, &spec_cu
);
22669 if (spec_die
!= NULL
)
22675 for (child
= die
->child
;
22677 child
= child
->sibling
)
22679 if (child
->tag
== DW_TAG_subprogram
)
22681 const char *linkage_name
= dw2_linkage_name (child
, cu
);
22683 if (linkage_name
!= NULL
)
22685 gdb::unique_xmalloc_ptr
<char> actual_name
22686 (language_class_name_from_physname (cu
->language_defn
,
22688 const char *name
= NULL
;
22690 if (actual_name
!= NULL
)
22692 const char *die_name
= dwarf2_name (die
, cu
);
22694 if (die_name
!= NULL
22695 && strcmp (die_name
, actual_name
.get ()) != 0)
22697 /* Strip off the class name from the full name.
22698 We want the prefix. */
22699 int die_name_len
= strlen (die_name
);
22700 int actual_name_len
= strlen (actual_name
.get ());
22701 const char *ptr
= actual_name
.get ();
22703 /* Test for '::' as a sanity check. */
22704 if (actual_name_len
> die_name_len
+ 2
22705 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
22706 name
= obstack_strndup (
22707 &objfile
->per_bfd
->storage_obstack
,
22708 ptr
, actual_name_len
- die_name_len
- 2);
22719 /* GCC might emit a nameless typedef that has a linkage name. Determine the
22720 prefix part in such case. See
22721 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22723 static const char *
22724 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22726 struct attribute
*attr
;
22729 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
22730 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
22733 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
22736 attr
= dw2_linkage_name_attr (die
, cu
);
22737 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22740 /* dwarf2_name had to be already called. */
22741 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
22743 /* Strip the base name, keep any leading namespaces/classes. */
22744 base
= strrchr (DW_STRING (attr
), ':');
22745 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
22748 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22749 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
22751 &base
[-1] - DW_STRING (attr
));
22754 /* Return the name of the namespace/class that DIE is defined within,
22755 or "" if we can't tell. The caller should not xfree the result.
22757 For example, if we're within the method foo() in the following
22767 then determine_prefix on foo's die will return "N::C". */
22769 static const char *
22770 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22772 struct dwarf2_per_objfile
*dwarf2_per_objfile
22773 = cu
->per_cu
->dwarf2_per_objfile
;
22774 struct die_info
*parent
, *spec_die
;
22775 struct dwarf2_cu
*spec_cu
;
22776 struct type
*parent_type
;
22777 const char *retval
;
22779 if (cu
->language
!= language_cplus
22780 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
22781 && cu
->language
!= language_rust
)
22784 retval
= anonymous_struct_prefix (die
, cu
);
22788 /* We have to be careful in the presence of DW_AT_specification.
22789 For example, with GCC 3.4, given the code
22793 // Definition of N::foo.
22797 then we'll have a tree of DIEs like this:
22799 1: DW_TAG_compile_unit
22800 2: DW_TAG_namespace // N
22801 3: DW_TAG_subprogram // declaration of N::foo
22802 4: DW_TAG_subprogram // definition of N::foo
22803 DW_AT_specification // refers to die #3
22805 Thus, when processing die #4, we have to pretend that we're in
22806 the context of its DW_AT_specification, namely the contex of die
22809 spec_die
= die_specification (die
, &spec_cu
);
22810 if (spec_die
== NULL
)
22811 parent
= die
->parent
;
22814 parent
= spec_die
->parent
;
22818 if (parent
== NULL
)
22820 else if (parent
->building_fullname
)
22823 const char *parent_name
;
22825 /* It has been seen on RealView 2.2 built binaries,
22826 DW_TAG_template_type_param types actually _defined_ as
22827 children of the parent class:
22830 template class <class Enum> Class{};
22831 Class<enum E> class_e;
22833 1: DW_TAG_class_type (Class)
22834 2: DW_TAG_enumeration_type (E)
22835 3: DW_TAG_enumerator (enum1:0)
22836 3: DW_TAG_enumerator (enum2:1)
22838 2: DW_TAG_template_type_param
22839 DW_AT_type DW_FORM_ref_udata (E)
22841 Besides being broken debug info, it can put GDB into an
22842 infinite loop. Consider:
22844 When we're building the full name for Class<E>, we'll start
22845 at Class, and go look over its template type parameters,
22846 finding E. We'll then try to build the full name of E, and
22847 reach here. We're now trying to build the full name of E,
22848 and look over the parent DIE for containing scope. In the
22849 broken case, if we followed the parent DIE of E, we'd again
22850 find Class, and once again go look at its template type
22851 arguments, etc., etc. Simply don't consider such parent die
22852 as source-level parent of this die (it can't be, the language
22853 doesn't allow it), and break the loop here. */
22854 name
= dwarf2_name (die
, cu
);
22855 parent_name
= dwarf2_name (parent
, cu
);
22856 complaint (_("template param type '%s' defined within parent '%s'"),
22857 name
? name
: "<unknown>",
22858 parent_name
? parent_name
: "<unknown>");
22862 switch (parent
->tag
)
22864 case DW_TAG_namespace
:
22865 parent_type
= read_type_die (parent
, cu
);
22866 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
22867 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
22868 Work around this problem here. */
22869 if (cu
->language
== language_cplus
22870 && strcmp (TYPE_NAME (parent_type
), "::") == 0)
22872 /* We give a name to even anonymous namespaces. */
22873 return TYPE_NAME (parent_type
);
22874 case DW_TAG_class_type
:
22875 case DW_TAG_interface_type
:
22876 case DW_TAG_structure_type
:
22877 case DW_TAG_union_type
:
22878 case DW_TAG_module
:
22879 parent_type
= read_type_die (parent
, cu
);
22880 if (TYPE_NAME (parent_type
) != NULL
)
22881 return TYPE_NAME (parent_type
);
22883 /* An anonymous structure is only allowed non-static data
22884 members; no typedefs, no member functions, et cetera.
22885 So it does not need a prefix. */
22887 case DW_TAG_compile_unit
:
22888 case DW_TAG_partial_unit
:
22889 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
22890 if (cu
->language
== language_cplus
22891 && !dwarf2_per_objfile
->types
.empty ()
22892 && die
->child
!= NULL
22893 && (die
->tag
== DW_TAG_class_type
22894 || die
->tag
== DW_TAG_structure_type
22895 || die
->tag
== DW_TAG_union_type
))
22897 const char *name
= guess_full_die_structure_name (die
, cu
);
22902 case DW_TAG_subprogram
:
22903 /* Nested subroutines in Fortran get a prefix with the name
22904 of the parent's subroutine. */
22905 if (cu
->language
== language_fortran
)
22907 if ((die
->tag
== DW_TAG_subprogram
)
22908 && (dwarf2_name (parent
, cu
) != NULL
))
22909 return dwarf2_name (parent
, cu
);
22911 return determine_prefix (parent
, cu
);
22912 case DW_TAG_enumeration_type
:
22913 parent_type
= read_type_die (parent
, cu
);
22914 if (TYPE_DECLARED_CLASS (parent_type
))
22916 if (TYPE_NAME (parent_type
) != NULL
)
22917 return TYPE_NAME (parent_type
);
22920 /* Fall through. */
22922 return determine_prefix (parent
, cu
);
22926 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
22927 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
22928 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
22929 an obconcat, otherwise allocate storage for the result. The CU argument is
22930 used to determine the language and hence, the appropriate separator. */
22932 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
22935 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
22936 int physname
, struct dwarf2_cu
*cu
)
22938 const char *lead
= "";
22941 if (suffix
== NULL
|| suffix
[0] == '\0'
22942 || prefix
== NULL
|| prefix
[0] == '\0')
22944 else if (cu
->language
== language_d
)
22946 /* For D, the 'main' function could be defined in any module, but it
22947 should never be prefixed. */
22948 if (strcmp (suffix
, "D main") == 0)
22956 else if (cu
->language
== language_fortran
&& physname
)
22958 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
22959 DW_AT_MIPS_linkage_name is preferred and used instead. */
22967 if (prefix
== NULL
)
22969 if (suffix
== NULL
)
22976 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
22978 strcpy (retval
, lead
);
22979 strcat (retval
, prefix
);
22980 strcat (retval
, sep
);
22981 strcat (retval
, suffix
);
22986 /* We have an obstack. */
22987 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
22991 /* Return sibling of die, NULL if no sibling. */
22993 static struct die_info
*
22994 sibling_die (struct die_info
*die
)
22996 return die
->sibling
;
22999 /* Get name of a die, return NULL if not found. */
23001 static const char *
23002 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
23003 struct obstack
*obstack
)
23005 if (name
&& cu
->language
== language_cplus
)
23007 std::string canon_name
= cp_canonicalize_string (name
);
23009 if (!canon_name
.empty ())
23011 if (canon_name
!= name
)
23012 name
= obstack_strdup (obstack
, canon_name
);
23019 /* Get name of a die, return NULL if not found.
23020 Anonymous namespaces are converted to their magic string. */
23022 static const char *
23023 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
23025 struct attribute
*attr
;
23026 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
23028 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
23029 if ((!attr
|| !DW_STRING (attr
))
23030 && die
->tag
!= DW_TAG_namespace
23031 && die
->tag
!= DW_TAG_class_type
23032 && die
->tag
!= DW_TAG_interface_type
23033 && die
->tag
!= DW_TAG_structure_type
23034 && die
->tag
!= DW_TAG_union_type
)
23039 case DW_TAG_compile_unit
:
23040 case DW_TAG_partial_unit
:
23041 /* Compilation units have a DW_AT_name that is a filename, not
23042 a source language identifier. */
23043 case DW_TAG_enumeration_type
:
23044 case DW_TAG_enumerator
:
23045 /* These tags always have simple identifiers already; no need
23046 to canonicalize them. */
23047 return DW_STRING (attr
);
23049 case DW_TAG_namespace
:
23050 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
23051 return DW_STRING (attr
);
23052 return CP_ANONYMOUS_NAMESPACE_STR
;
23054 case DW_TAG_class_type
:
23055 case DW_TAG_interface_type
:
23056 case DW_TAG_structure_type
:
23057 case DW_TAG_union_type
:
23058 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
23059 structures or unions. These were of the form "._%d" in GCC 4.1,
23060 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
23061 and GCC 4.4. We work around this problem by ignoring these. */
23062 if (attr
&& DW_STRING (attr
)
23063 && (startswith (DW_STRING (attr
), "._")
23064 || startswith (DW_STRING (attr
), "<anonymous")))
23067 /* GCC might emit a nameless typedef that has a linkage name. See
23068 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
23069 if (!attr
|| DW_STRING (attr
) == NULL
)
23071 attr
= dw2_linkage_name_attr (die
, cu
);
23072 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
23075 /* Avoid demangling DW_STRING (attr) the second time on a second
23076 call for the same DIE. */
23077 if (!DW_STRING_IS_CANONICAL (attr
))
23079 gdb::unique_xmalloc_ptr
<char> demangled
23080 (gdb_demangle (DW_STRING (attr
), DMGL_TYPES
));
23084 /* FIXME: we already did this for the partial symbol... */
23086 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
23088 DW_STRING_IS_CANONICAL (attr
) = 1;
23090 /* Strip any leading namespaces/classes, keep only the base name.
23091 DW_AT_name for named DIEs does not contain the prefixes. */
23092 base
= strrchr (DW_STRING (attr
), ':');
23093 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
23096 return DW_STRING (attr
);
23105 if (!DW_STRING_IS_CANONICAL (attr
))
23108 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
23109 &objfile
->per_bfd
->storage_obstack
);
23110 DW_STRING_IS_CANONICAL (attr
) = 1;
23112 return DW_STRING (attr
);
23115 /* Return the die that this die in an extension of, or NULL if there
23116 is none. *EXT_CU is the CU containing DIE on input, and the CU
23117 containing the return value on output. */
23119 static struct die_info
*
23120 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
23122 struct attribute
*attr
;
23124 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
23128 return follow_die_ref (die
, attr
, ext_cu
);
23131 /* A convenience function that returns an "unknown" DWARF name,
23132 including the value of V. STR is the name of the entity being
23133 printed, e.g., "TAG". */
23135 static const char *
23136 dwarf_unknown (const char *str
, unsigned v
)
23138 char *cell
= get_print_cell ();
23139 xsnprintf (cell
, PRINT_CELL_SIZE
, "DW_%s_<unknown: %u>", str
, v
);
23143 /* Convert a DIE tag into its string name. */
23145 static const char *
23146 dwarf_tag_name (unsigned tag
)
23148 const char *name
= get_DW_TAG_name (tag
);
23151 return dwarf_unknown ("TAG", tag
);
23156 /* Convert a DWARF attribute code into its string name. */
23158 static const char *
23159 dwarf_attr_name (unsigned attr
)
23163 #ifdef MIPS /* collides with DW_AT_HP_block_index */
23164 if (attr
== DW_AT_MIPS_fde
)
23165 return "DW_AT_MIPS_fde";
23167 if (attr
== DW_AT_HP_block_index
)
23168 return "DW_AT_HP_block_index";
23171 name
= get_DW_AT_name (attr
);
23174 return dwarf_unknown ("AT", attr
);
23179 /* Convert a unit type to corresponding DW_UT name. */
23181 static const char *
23182 dwarf_unit_type_name (int unit_type
) {
23186 return "DW_UT_compile (0x01)";
23188 return "DW_UT_type (0x02)";
23190 return "DW_UT_partial (0x03)";
23192 return "DW_UT_skeleton (0x04)";
23194 return "DW_UT_split_compile (0x05)";
23196 return "DW_UT_split_type (0x06)";
23198 return "DW_UT_lo_user (0x80)";
23200 return "DW_UT_hi_user (0xff)";
23206 /* Convert a DWARF value form code into its string name. */
23208 static const char *
23209 dwarf_form_name (unsigned form
)
23211 const char *name
= get_DW_FORM_name (form
);
23214 return dwarf_unknown ("FORM", form
);
23219 static const char *
23220 dwarf_bool_name (unsigned mybool
)
23228 /* Convert a DWARF type code into its string name. */
23230 static const char *
23231 dwarf_type_encoding_name (unsigned enc
)
23233 const char *name
= get_DW_ATE_name (enc
);
23236 return dwarf_unknown ("ATE", enc
);
23242 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
23246 print_spaces (indent
, f
);
23247 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
23248 dwarf_tag_name (die
->tag
), die
->abbrev
,
23249 sect_offset_str (die
->sect_off
));
23251 if (die
->parent
!= NULL
)
23253 print_spaces (indent
, f
);
23254 fprintf_unfiltered (f
, " parent at offset: %s\n",
23255 sect_offset_str (die
->parent
->sect_off
));
23258 print_spaces (indent
, f
);
23259 fprintf_unfiltered (f
, " has children: %s\n",
23260 dwarf_bool_name (die
->child
!= NULL
));
23262 print_spaces (indent
, f
);
23263 fprintf_unfiltered (f
, " attributes:\n");
23265 for (i
= 0; i
< die
->num_attrs
; ++i
)
23267 print_spaces (indent
, f
);
23268 fprintf_unfiltered (f
, " %s (%s) ",
23269 dwarf_attr_name (die
->attrs
[i
].name
),
23270 dwarf_form_name (die
->attrs
[i
].form
));
23272 switch (die
->attrs
[i
].form
)
23275 case DW_FORM_addrx
:
23276 case DW_FORM_GNU_addr_index
:
23277 fprintf_unfiltered (f
, "address: ");
23278 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
23280 case DW_FORM_block2
:
23281 case DW_FORM_block4
:
23282 case DW_FORM_block
:
23283 case DW_FORM_block1
:
23284 fprintf_unfiltered (f
, "block: size %s",
23285 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
23287 case DW_FORM_exprloc
:
23288 fprintf_unfiltered (f
, "expression: size %s",
23289 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
23291 case DW_FORM_data16
:
23292 fprintf_unfiltered (f
, "constant of 16 bytes");
23294 case DW_FORM_ref_addr
:
23295 fprintf_unfiltered (f
, "ref address: ");
23296 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
23298 case DW_FORM_GNU_ref_alt
:
23299 fprintf_unfiltered (f
, "alt ref address: ");
23300 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
23306 case DW_FORM_ref_udata
:
23307 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
23308 (long) (DW_UNSND (&die
->attrs
[i
])));
23310 case DW_FORM_data1
:
23311 case DW_FORM_data2
:
23312 case DW_FORM_data4
:
23313 case DW_FORM_data8
:
23314 case DW_FORM_udata
:
23315 case DW_FORM_sdata
:
23316 fprintf_unfiltered (f
, "constant: %s",
23317 pulongest (DW_UNSND (&die
->attrs
[i
])));
23319 case DW_FORM_sec_offset
:
23320 fprintf_unfiltered (f
, "section offset: %s",
23321 pulongest (DW_UNSND (&die
->attrs
[i
])));
23323 case DW_FORM_ref_sig8
:
23324 fprintf_unfiltered (f
, "signature: %s",
23325 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
23327 case DW_FORM_string
:
23329 case DW_FORM_line_strp
:
23331 case DW_FORM_GNU_str_index
:
23332 case DW_FORM_GNU_strp_alt
:
23333 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
23334 DW_STRING (&die
->attrs
[i
])
23335 ? DW_STRING (&die
->attrs
[i
]) : "",
23336 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
23339 if (DW_UNSND (&die
->attrs
[i
]))
23340 fprintf_unfiltered (f
, "flag: TRUE");
23342 fprintf_unfiltered (f
, "flag: FALSE");
23344 case DW_FORM_flag_present
:
23345 fprintf_unfiltered (f
, "flag: TRUE");
23347 case DW_FORM_indirect
:
23348 /* The reader will have reduced the indirect form to
23349 the "base form" so this form should not occur. */
23350 fprintf_unfiltered (f
,
23351 "unexpected attribute form: DW_FORM_indirect");
23353 case DW_FORM_implicit_const
:
23354 fprintf_unfiltered (f
, "constant: %s",
23355 plongest (DW_SND (&die
->attrs
[i
])));
23358 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
23359 die
->attrs
[i
].form
);
23362 fprintf_unfiltered (f
, "\n");
23367 dump_die_for_error (struct die_info
*die
)
23369 dump_die_shallow (gdb_stderr
, 0, die
);
23373 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
23375 int indent
= level
* 4;
23377 gdb_assert (die
!= NULL
);
23379 if (level
>= max_level
)
23382 dump_die_shallow (f
, indent
, die
);
23384 if (die
->child
!= NULL
)
23386 print_spaces (indent
, f
);
23387 fprintf_unfiltered (f
, " Children:");
23388 if (level
+ 1 < max_level
)
23390 fprintf_unfiltered (f
, "\n");
23391 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
23395 fprintf_unfiltered (f
,
23396 " [not printed, max nesting level reached]\n");
23400 if (die
->sibling
!= NULL
&& level
> 0)
23402 dump_die_1 (f
, level
, max_level
, die
->sibling
);
23406 /* This is called from the pdie macro in gdbinit.in.
23407 It's not static so gcc will keep a copy callable from gdb. */
23410 dump_die (struct die_info
*die
, int max_level
)
23412 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
23416 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
23420 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
23421 to_underlying (die
->sect_off
),
23427 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
23431 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
23433 if (attr_form_is_ref (attr
))
23434 return (sect_offset
) DW_UNSND (attr
);
23436 complaint (_("unsupported die ref attribute form: '%s'"),
23437 dwarf_form_name (attr
->form
));
23441 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
23442 * the value held by the attribute is not constant. */
23445 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
23447 if (attr
->form
== DW_FORM_sdata
|| attr
->form
== DW_FORM_implicit_const
)
23448 return DW_SND (attr
);
23449 else if (attr
->form
== DW_FORM_udata
23450 || attr
->form
== DW_FORM_data1
23451 || attr
->form
== DW_FORM_data2
23452 || attr
->form
== DW_FORM_data4
23453 || attr
->form
== DW_FORM_data8
)
23454 return DW_UNSND (attr
);
23457 /* For DW_FORM_data16 see attr_form_is_constant. */
23458 complaint (_("Attribute value is not a constant (%s)"),
23459 dwarf_form_name (attr
->form
));
23460 return default_value
;
23464 /* Follow reference or signature attribute ATTR of SRC_DIE.
23465 On entry *REF_CU is the CU of SRC_DIE.
23466 On exit *REF_CU is the CU of the result. */
23468 static struct die_info
*
23469 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23470 struct dwarf2_cu
**ref_cu
)
23472 struct die_info
*die
;
23474 if (attr_form_is_ref (attr
))
23475 die
= follow_die_ref (src_die
, attr
, ref_cu
);
23476 else if (attr
->form
== DW_FORM_ref_sig8
)
23477 die
= follow_die_sig (src_die
, attr
, ref_cu
);
23480 dump_die_for_error (src_die
);
23481 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
23482 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23488 /* Follow reference OFFSET.
23489 On entry *REF_CU is the CU of the source die referencing OFFSET.
23490 On exit *REF_CU is the CU of the result.
23491 Returns NULL if OFFSET is invalid. */
23493 static struct die_info
*
23494 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
23495 struct dwarf2_cu
**ref_cu
)
23497 struct die_info temp_die
;
23498 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
23499 struct dwarf2_per_objfile
*dwarf2_per_objfile
23500 = cu
->per_cu
->dwarf2_per_objfile
;
23502 gdb_assert (cu
->per_cu
!= NULL
);
23506 if (cu
->per_cu
->is_debug_types
)
23508 /* .debug_types CUs cannot reference anything outside their CU.
23509 If they need to, they have to reference a signatured type via
23510 DW_FORM_ref_sig8. */
23511 if (!offset_in_cu_p (&cu
->header
, sect_off
))
23514 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
23515 || !offset_in_cu_p (&cu
->header
, sect_off
))
23517 struct dwarf2_per_cu_data
*per_cu
;
23519 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23520 dwarf2_per_objfile
);
23522 /* If necessary, add it to the queue and load its DIEs. */
23523 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
23524 load_full_comp_unit (per_cu
, false, cu
->language
);
23526 target_cu
= per_cu
->cu
;
23528 else if (cu
->dies
== NULL
)
23530 /* We're loading full DIEs during partial symbol reading. */
23531 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
23532 load_full_comp_unit (cu
->per_cu
, false, language_minimal
);
23535 *ref_cu
= target_cu
;
23536 temp_die
.sect_off
= sect_off
;
23538 if (target_cu
!= cu
)
23539 target_cu
->ancestor
= cu
;
23541 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
23543 to_underlying (sect_off
));
23546 /* Follow reference attribute ATTR of SRC_DIE.
23547 On entry *REF_CU is the CU of SRC_DIE.
23548 On exit *REF_CU is the CU of the result. */
23550 static struct die_info
*
23551 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
23552 struct dwarf2_cu
**ref_cu
)
23554 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
23555 struct dwarf2_cu
*cu
= *ref_cu
;
23556 struct die_info
*die
;
23558 die
= follow_die_offset (sect_off
,
23559 (attr
->form
== DW_FORM_GNU_ref_alt
23560 || cu
->per_cu
->is_dwz
),
23563 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
23564 "at %s [in module %s]"),
23565 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
23566 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
23571 /* Return DWARF block referenced by DW_AT_location of DIE at SECT_OFF at PER_CU.
23572 Returned value is intended for DW_OP_call*. Returned
23573 dwarf2_locexpr_baton->data has lifetime of
23574 PER_CU->DWARF2_PER_OBJFILE->OBJFILE. */
23576 struct dwarf2_locexpr_baton
23577 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
23578 struct dwarf2_per_cu_data
*per_cu
,
23579 CORE_ADDR (*get_frame_pc
) (void *baton
),
23580 void *baton
, bool resolve_abstract_p
)
23582 struct dwarf2_cu
*cu
;
23583 struct die_info
*die
;
23584 struct attribute
*attr
;
23585 struct dwarf2_locexpr_baton retval
;
23586 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
23587 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23589 if (per_cu
->cu
== NULL
)
23590 load_cu (per_cu
, false);
23594 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23595 Instead just throw an error, not much else we can do. */
23596 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23597 sect_offset_str (sect_off
), objfile_name (objfile
));
23600 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23602 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23603 sect_offset_str (sect_off
), objfile_name (objfile
));
23605 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23606 if (!attr
&& resolve_abstract_p
23607 && (dwarf2_per_objfile
->abstract_to_concrete
.find (die
->sect_off
)
23608 != dwarf2_per_objfile
->abstract_to_concrete
.end ()))
23610 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
23611 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
23612 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
23614 for (const auto &cand_off
23615 : dwarf2_per_objfile
->abstract_to_concrete
[die
->sect_off
])
23617 struct dwarf2_cu
*cand_cu
= cu
;
23618 struct die_info
*cand
23619 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
23622 || cand
->parent
->tag
!= DW_TAG_subprogram
)
23625 CORE_ADDR pc_low
, pc_high
;
23626 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
23627 if (pc_low
== ((CORE_ADDR
) -1))
23629 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
23630 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
23631 if (!(pc_low
<= pc
&& pc
< pc_high
))
23635 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23642 /* DWARF: "If there is no such attribute, then there is no effect.".
23643 DATA is ignored if SIZE is 0. */
23645 retval
.data
= NULL
;
23648 else if (attr_form_is_section_offset (attr
))
23650 struct dwarf2_loclist_baton loclist_baton
;
23651 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
23654 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
23656 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
23658 retval
.size
= size
;
23662 if (!attr_form_is_block (attr
))
23663 error (_("Dwarf Error: DIE at %s referenced in module %s "
23664 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
23665 sect_offset_str (sect_off
), objfile_name (objfile
));
23667 retval
.data
= DW_BLOCK (attr
)->data
;
23668 retval
.size
= DW_BLOCK (attr
)->size
;
23670 retval
.per_cu
= cu
->per_cu
;
23672 age_cached_comp_units (dwarf2_per_objfile
);
23677 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
23680 struct dwarf2_locexpr_baton
23681 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
23682 struct dwarf2_per_cu_data
*per_cu
,
23683 CORE_ADDR (*get_frame_pc
) (void *baton
),
23686 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
23688 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
23691 /* Write a constant of a given type as target-ordered bytes into
23694 static const gdb_byte
*
23695 write_constant_as_bytes (struct obstack
*obstack
,
23696 enum bfd_endian byte_order
,
23703 *len
= TYPE_LENGTH (type
);
23704 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23705 store_unsigned_integer (result
, *len
, byte_order
, value
);
23710 /* If the DIE at OFFSET in PER_CU has a DW_AT_const_value, return a
23711 pointer to the constant bytes and set LEN to the length of the
23712 data. If memory is needed, allocate it on OBSTACK. If the DIE
23713 does not have a DW_AT_const_value, return NULL. */
23716 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
23717 struct dwarf2_per_cu_data
*per_cu
,
23718 struct obstack
*obstack
,
23721 struct dwarf2_cu
*cu
;
23722 struct die_info
*die
;
23723 struct attribute
*attr
;
23724 const gdb_byte
*result
= NULL
;
23727 enum bfd_endian byte_order
;
23728 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
23730 if (per_cu
->cu
== NULL
)
23731 load_cu (per_cu
, false);
23735 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23736 Instead just throw an error, not much else we can do. */
23737 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23738 sect_offset_str (sect_off
), objfile_name (objfile
));
23741 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23743 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23744 sect_offset_str (sect_off
), objfile_name (objfile
));
23746 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23750 byte_order
= (bfd_big_endian (objfile
->obfd
)
23751 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
23753 switch (attr
->form
)
23756 case DW_FORM_addrx
:
23757 case DW_FORM_GNU_addr_index
:
23761 *len
= cu
->header
.addr_size
;
23762 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23763 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
23767 case DW_FORM_string
:
23770 case DW_FORM_GNU_str_index
:
23771 case DW_FORM_GNU_strp_alt
:
23772 /* DW_STRING is already allocated on the objfile obstack, point
23774 result
= (const gdb_byte
*) DW_STRING (attr
);
23775 *len
= strlen (DW_STRING (attr
));
23777 case DW_FORM_block1
:
23778 case DW_FORM_block2
:
23779 case DW_FORM_block4
:
23780 case DW_FORM_block
:
23781 case DW_FORM_exprloc
:
23782 case DW_FORM_data16
:
23783 result
= DW_BLOCK (attr
)->data
;
23784 *len
= DW_BLOCK (attr
)->size
;
23787 /* The DW_AT_const_value attributes are supposed to carry the
23788 symbol's value "represented as it would be on the target
23789 architecture." By the time we get here, it's already been
23790 converted to host endianness, so we just need to sign- or
23791 zero-extend it as appropriate. */
23792 case DW_FORM_data1
:
23793 type
= die_type (die
, cu
);
23794 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
23795 if (result
== NULL
)
23796 result
= write_constant_as_bytes (obstack
, byte_order
,
23799 case DW_FORM_data2
:
23800 type
= die_type (die
, cu
);
23801 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
23802 if (result
== NULL
)
23803 result
= write_constant_as_bytes (obstack
, byte_order
,
23806 case DW_FORM_data4
:
23807 type
= die_type (die
, cu
);
23808 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
23809 if (result
== NULL
)
23810 result
= write_constant_as_bytes (obstack
, byte_order
,
23813 case DW_FORM_data8
:
23814 type
= die_type (die
, cu
);
23815 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
23816 if (result
== NULL
)
23817 result
= write_constant_as_bytes (obstack
, byte_order
,
23821 case DW_FORM_sdata
:
23822 case DW_FORM_implicit_const
:
23823 type
= die_type (die
, cu
);
23824 result
= write_constant_as_bytes (obstack
, byte_order
,
23825 type
, DW_SND (attr
), len
);
23828 case DW_FORM_udata
:
23829 type
= die_type (die
, cu
);
23830 result
= write_constant_as_bytes (obstack
, byte_order
,
23831 type
, DW_UNSND (attr
), len
);
23835 complaint (_("unsupported const value attribute form: '%s'"),
23836 dwarf_form_name (attr
->form
));
23843 /* Return the type of the die at OFFSET in PER_CU. Return NULL if no
23844 valid type for this die is found. */
23847 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
23848 struct dwarf2_per_cu_data
*per_cu
)
23850 struct dwarf2_cu
*cu
;
23851 struct die_info
*die
;
23853 if (per_cu
->cu
== NULL
)
23854 load_cu (per_cu
, false);
23859 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23863 return die_type (die
, cu
);
23866 /* Return the type of the DIE at DIE_OFFSET in the CU named by
23870 dwarf2_get_die_type (cu_offset die_offset
,
23871 struct dwarf2_per_cu_data
*per_cu
)
23873 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
23874 return get_die_type_at_offset (die_offset_sect
, per_cu
);
23877 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
23878 On entry *REF_CU is the CU of SRC_DIE.
23879 On exit *REF_CU is the CU of the result.
23880 Returns NULL if the referenced DIE isn't found. */
23882 static struct die_info
*
23883 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
23884 struct dwarf2_cu
**ref_cu
)
23886 struct die_info temp_die
;
23887 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
23888 struct die_info
*die
;
23890 /* While it might be nice to assert sig_type->type == NULL here,
23891 we can get here for DW_AT_imported_declaration where we need
23892 the DIE not the type. */
23894 /* If necessary, add it to the queue and load its DIEs. */
23896 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
23897 read_signatured_type (sig_type
);
23899 sig_cu
= sig_type
->per_cu
.cu
;
23900 gdb_assert (sig_cu
!= NULL
);
23901 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
23902 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
23903 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
23904 to_underlying (temp_die
.sect_off
));
23907 struct dwarf2_per_objfile
*dwarf2_per_objfile
23908 = (*ref_cu
)->per_cu
->dwarf2_per_objfile
;
23910 /* For .gdb_index version 7 keep track of included TUs.
23911 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
23912 if (dwarf2_per_objfile
->index_table
!= NULL
23913 && dwarf2_per_objfile
->index_table
->version
<= 7)
23915 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
23920 sig_cu
->ancestor
= cu
;
23928 /* Follow signatured type referenced by ATTR in SRC_DIE.
23929 On entry *REF_CU is the CU of SRC_DIE.
23930 On exit *REF_CU is the CU of the result.
23931 The result is the DIE of the type.
23932 If the referenced type cannot be found an error is thrown. */
23934 static struct die_info
*
23935 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23936 struct dwarf2_cu
**ref_cu
)
23938 ULONGEST signature
= DW_SIGNATURE (attr
);
23939 struct signatured_type
*sig_type
;
23940 struct die_info
*die
;
23942 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
23944 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
23945 /* sig_type will be NULL if the signatured type is missing from
23947 if (sig_type
== NULL
)
23949 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23950 " from DIE at %s [in module %s]"),
23951 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23952 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23955 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
23958 dump_die_for_error (src_die
);
23959 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23960 " from DIE at %s [in module %s]"),
23961 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23962 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23968 /* Get the type specified by SIGNATURE referenced in DIE/CU,
23969 reading in and processing the type unit if necessary. */
23971 static struct type
*
23972 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
23973 struct dwarf2_cu
*cu
)
23975 struct dwarf2_per_objfile
*dwarf2_per_objfile
23976 = cu
->per_cu
->dwarf2_per_objfile
;
23977 struct signatured_type
*sig_type
;
23978 struct dwarf2_cu
*type_cu
;
23979 struct die_info
*type_die
;
23982 sig_type
= lookup_signatured_type (cu
, signature
);
23983 /* sig_type will be NULL if the signatured type is missing from
23985 if (sig_type
== NULL
)
23987 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23988 " from DIE at %s [in module %s]"),
23989 hex_string (signature
), sect_offset_str (die
->sect_off
),
23990 objfile_name (dwarf2_per_objfile
->objfile
));
23991 return build_error_marker_type (cu
, die
);
23994 /* If we already know the type we're done. */
23995 if (sig_type
->type
!= NULL
)
23996 return sig_type
->type
;
23999 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
24000 if (type_die
!= NULL
)
24002 /* N.B. We need to call get_die_type to ensure only one type for this DIE
24003 is created. This is important, for example, because for c++ classes
24004 we need TYPE_NAME set which is only done by new_symbol. Blech. */
24005 type
= read_type_die (type_die
, type_cu
);
24008 complaint (_("Dwarf Error: Cannot build signatured type %s"
24009 " referenced from DIE at %s [in module %s]"),
24010 hex_string (signature
), sect_offset_str (die
->sect_off
),
24011 objfile_name (dwarf2_per_objfile
->objfile
));
24012 type
= build_error_marker_type (cu
, die
);
24017 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
24018 " from DIE at %s [in module %s]"),
24019 hex_string (signature
), sect_offset_str (die
->sect_off
),
24020 objfile_name (dwarf2_per_objfile
->objfile
));
24021 type
= build_error_marker_type (cu
, die
);
24023 sig_type
->type
= type
;
24028 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
24029 reading in and processing the type unit if necessary. */
24031 static struct type
*
24032 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
24033 struct dwarf2_cu
*cu
) /* ARI: editCase function */
24035 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
24036 if (attr_form_is_ref (attr
))
24038 struct dwarf2_cu
*type_cu
= cu
;
24039 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
24041 return read_type_die (type_die
, type_cu
);
24043 else if (attr
->form
== DW_FORM_ref_sig8
)
24045 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
24049 struct dwarf2_per_objfile
*dwarf2_per_objfile
24050 = cu
->per_cu
->dwarf2_per_objfile
;
24052 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
24053 " at %s [in module %s]"),
24054 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
24055 objfile_name (dwarf2_per_objfile
->objfile
));
24056 return build_error_marker_type (cu
, die
);
24060 /* Load the DIEs associated with type unit PER_CU into memory. */
24063 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
24065 struct signatured_type
*sig_type
;
24067 /* Caller is responsible for ensuring type_unit_groups don't get here. */
24068 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
24070 /* We have the per_cu, but we need the signatured_type.
24071 Fortunately this is an easy translation. */
24072 gdb_assert (per_cu
->is_debug_types
);
24073 sig_type
= (struct signatured_type
*) per_cu
;
24075 gdb_assert (per_cu
->cu
== NULL
);
24077 read_signatured_type (sig_type
);
24079 gdb_assert (per_cu
->cu
!= NULL
);
24082 /* Read in a signatured type and build its CU and DIEs.
24083 If the type is a stub for the real type in a DWO file,
24084 read in the real type from the DWO file as well. */
24087 read_signatured_type (struct signatured_type
*sig_type
)
24089 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
24091 gdb_assert (per_cu
->is_debug_types
);
24092 gdb_assert (per_cu
->cu
== NULL
);
24094 cutu_reader
reader (per_cu
, NULL
, 0, 1, false);
24096 if (!reader
.dummy_p
)
24098 struct dwarf2_cu
*cu
= reader
.cu
;
24099 const gdb_byte
*info_ptr
= reader
.info_ptr
;
24101 gdb_assert (cu
->die_hash
== NULL
);
24103 htab_create_alloc_ex (cu
->header
.length
/ 12,
24107 &cu
->comp_unit_obstack
,
24108 hashtab_obstack_allocate
,
24109 dummy_obstack_deallocate
);
24111 if (reader
.has_children
)
24112 reader
.comp_unit_die
->child
24113 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
24114 reader
.comp_unit_die
);
24115 cu
->dies
= reader
.comp_unit_die
;
24116 /* comp_unit_die is not stored in die_hash, no need. */
24118 /* We try not to read any attributes in this function, because
24119 not all CUs needed for references have been loaded yet, and
24120 symbol table processing isn't initialized. But we have to
24121 set the CU language, or we won't be able to build types
24122 correctly. Similarly, if we do not read the producer, we can
24123 not apply producer-specific interpretation. */
24124 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
24127 sig_type
->per_cu
.tu_read
= 1;
24130 /* Decode simple location descriptions.
24131 Given a pointer to a dwarf block that defines a location, compute
24132 the location and return the value.
24134 NOTE drow/2003-11-18: This function is called in two situations
24135 now: for the address of static or global variables (partial symbols
24136 only) and for offsets into structures which are expected to be
24137 (more or less) constant. The partial symbol case should go away,
24138 and only the constant case should remain. That will let this
24139 function complain more accurately. A few special modes are allowed
24140 without complaint for global variables (for instance, global
24141 register values and thread-local values).
24143 A location description containing no operations indicates that the
24144 object is optimized out. The return value is 0 for that case.
24145 FIXME drow/2003-11-16: No callers check for this case any more; soon all
24146 callers will only want a very basic result and this can become a
24149 Note that stack[0] is unused except as a default error return. */
24152 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
24154 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
24156 size_t size
= blk
->size
;
24157 const gdb_byte
*data
= blk
->data
;
24158 CORE_ADDR stack
[64];
24160 unsigned int bytes_read
, unsnd
;
24166 stack
[++stacki
] = 0;
24205 stack
[++stacki
] = op
- DW_OP_lit0
;
24240 stack
[++stacki
] = op
- DW_OP_reg0
;
24242 dwarf2_complex_location_expr_complaint ();
24246 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
24248 stack
[++stacki
] = unsnd
;
24250 dwarf2_complex_location_expr_complaint ();
24254 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
24259 case DW_OP_const1u
:
24260 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
24264 case DW_OP_const1s
:
24265 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
24269 case DW_OP_const2u
:
24270 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
24274 case DW_OP_const2s
:
24275 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
24279 case DW_OP_const4u
:
24280 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
24284 case DW_OP_const4s
:
24285 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
24289 case DW_OP_const8u
:
24290 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
24295 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
24301 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
24306 stack
[stacki
+ 1] = stack
[stacki
];
24311 stack
[stacki
- 1] += stack
[stacki
];
24315 case DW_OP_plus_uconst
:
24316 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
24322 stack
[stacki
- 1] -= stack
[stacki
];
24327 /* If we're not the last op, then we definitely can't encode
24328 this using GDB's address_class enum. This is valid for partial
24329 global symbols, although the variable's address will be bogus
24332 dwarf2_complex_location_expr_complaint ();
24335 case DW_OP_GNU_push_tls_address
:
24336 case DW_OP_form_tls_address
:
24337 /* The top of the stack has the offset from the beginning
24338 of the thread control block at which the variable is located. */
24339 /* Nothing should follow this operator, so the top of stack would
24341 /* This is valid for partial global symbols, but the variable's
24342 address will be bogus in the psymtab. Make it always at least
24343 non-zero to not look as a variable garbage collected by linker
24344 which have DW_OP_addr 0. */
24346 dwarf2_complex_location_expr_complaint ();
24350 case DW_OP_GNU_uninit
:
24354 case DW_OP_GNU_addr_index
:
24355 case DW_OP_GNU_const_index
:
24356 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
24363 const char *name
= get_DW_OP_name (op
);
24366 complaint (_("unsupported stack op: '%s'"),
24369 complaint (_("unsupported stack op: '%02x'"),
24373 return (stack
[stacki
]);
24376 /* Enforce maximum stack depth of SIZE-1 to avoid writing
24377 outside of the allocated space. Also enforce minimum>0. */
24378 if (stacki
>= ARRAY_SIZE (stack
) - 1)
24380 complaint (_("location description stack overflow"));
24386 complaint (_("location description stack underflow"));
24390 return (stack
[stacki
]);
24393 /* memory allocation interface */
24395 static struct dwarf_block
*
24396 dwarf_alloc_block (struct dwarf2_cu
*cu
)
24398 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
24401 static struct die_info
*
24402 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
24404 struct die_info
*die
;
24405 size_t size
= sizeof (struct die_info
);
24408 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
24410 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
24411 memset (die
, 0, sizeof (struct die_info
));
24416 /* Macro support. */
24418 /* Return file name relative to the compilation directory of file number I in
24419 *LH's file name table. The result is allocated using xmalloc; the caller is
24420 responsible for freeing it. */
24423 file_file_name (int file
, struct line_header
*lh
)
24425 /* Is the file number a valid index into the line header's file name
24426 table? Remember that file numbers start with one, not zero. */
24427 if (lh
->is_valid_file_index (file
))
24429 const file_entry
*fe
= lh
->file_name_at (file
);
24431 if (!IS_ABSOLUTE_PATH (fe
->name
))
24433 const char *dir
= fe
->include_dir (lh
);
24435 return concat (dir
, SLASH_STRING
, fe
->name
, (char *) NULL
);
24437 return xstrdup (fe
->name
);
24441 /* The compiler produced a bogus file number. We can at least
24442 record the macro definitions made in the file, even if we
24443 won't be able to find the file by name. */
24444 char fake_name
[80];
24446 xsnprintf (fake_name
, sizeof (fake_name
),
24447 "<bad macro file number %d>", file
);
24449 complaint (_("bad file number in macro information (%d)"),
24452 return xstrdup (fake_name
);
24456 /* Return the full name of file number I in *LH's file name table.
24457 Use COMP_DIR as the name of the current directory of the
24458 compilation. The result is allocated using xmalloc; the caller is
24459 responsible for freeing it. */
24461 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
24463 /* Is the file number a valid index into the line header's file name
24464 table? Remember that file numbers start with one, not zero. */
24465 if (lh
->is_valid_file_index (file
))
24467 char *relative
= file_file_name (file
, lh
);
24469 if (IS_ABSOLUTE_PATH (relative
) || comp_dir
== NULL
)
24471 return reconcat (relative
, comp_dir
, SLASH_STRING
,
24472 relative
, (char *) NULL
);
24475 return file_file_name (file
, lh
);
24479 static struct macro_source_file
*
24480 macro_start_file (struct dwarf2_cu
*cu
,
24481 int file
, int line
,
24482 struct macro_source_file
*current_file
,
24483 struct line_header
*lh
)
24485 /* File name relative to the compilation directory of this source file. */
24486 char *file_name
= file_file_name (file
, lh
);
24488 if (! current_file
)
24490 /* Note: We don't create a macro table for this compilation unit
24491 at all until we actually get a filename. */
24492 struct macro_table
*macro_table
= cu
->get_builder ()->get_macro_table ();
24494 /* If we have no current file, then this must be the start_file
24495 directive for the compilation unit's main source file. */
24496 current_file
= macro_set_main (macro_table
, file_name
);
24497 macro_define_special (macro_table
);
24500 current_file
= macro_include (current_file
, line
, file_name
);
24504 return current_file
;
24507 static const char *
24508 consume_improper_spaces (const char *p
, const char *body
)
24512 complaint (_("macro definition contains spaces "
24513 "in formal argument list:\n`%s'"),
24525 parse_macro_definition (struct macro_source_file
*file
, int line
,
24530 /* The body string takes one of two forms. For object-like macro
24531 definitions, it should be:
24533 <macro name> " " <definition>
24535 For function-like macro definitions, it should be:
24537 <macro name> "() " <definition>
24539 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
24541 Spaces may appear only where explicitly indicated, and in the
24544 The Dwarf 2 spec says that an object-like macro's name is always
24545 followed by a space, but versions of GCC around March 2002 omit
24546 the space when the macro's definition is the empty string.
24548 The Dwarf 2 spec says that there should be no spaces between the
24549 formal arguments in a function-like macro's formal argument list,
24550 but versions of GCC around March 2002 include spaces after the
24554 /* Find the extent of the macro name. The macro name is terminated
24555 by either a space or null character (for an object-like macro) or
24556 an opening paren (for a function-like macro). */
24557 for (p
= body
; *p
; p
++)
24558 if (*p
== ' ' || *p
== '(')
24561 if (*p
== ' ' || *p
== '\0')
24563 /* It's an object-like macro. */
24564 int name_len
= p
- body
;
24565 std::string
name (body
, name_len
);
24566 const char *replacement
;
24569 replacement
= body
+ name_len
+ 1;
24572 dwarf2_macro_malformed_definition_complaint (body
);
24573 replacement
= body
+ name_len
;
24576 macro_define_object (file
, line
, name
.c_str (), replacement
);
24578 else if (*p
== '(')
24580 /* It's a function-like macro. */
24581 std::string
name (body
, p
- body
);
24584 char **argv
= XNEWVEC (char *, argv_size
);
24588 p
= consume_improper_spaces (p
, body
);
24590 /* Parse the formal argument list. */
24591 while (*p
&& *p
!= ')')
24593 /* Find the extent of the current argument name. */
24594 const char *arg_start
= p
;
24596 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
24599 if (! *p
|| p
== arg_start
)
24600 dwarf2_macro_malformed_definition_complaint (body
);
24603 /* Make sure argv has room for the new argument. */
24604 if (argc
>= argv_size
)
24607 argv
= XRESIZEVEC (char *, argv
, argv_size
);
24610 argv
[argc
++] = savestring (arg_start
, p
- arg_start
);
24613 p
= consume_improper_spaces (p
, body
);
24615 /* Consume the comma, if present. */
24620 p
= consume_improper_spaces (p
, body
);
24629 /* Perfectly formed definition, no complaints. */
24630 macro_define_function (file
, line
, name
.c_str (),
24631 argc
, (const char **) argv
,
24633 else if (*p
== '\0')
24635 /* Complain, but do define it. */
24636 dwarf2_macro_malformed_definition_complaint (body
);
24637 macro_define_function (file
, line
, name
.c_str (),
24638 argc
, (const char **) argv
,
24642 /* Just complain. */
24643 dwarf2_macro_malformed_definition_complaint (body
);
24646 /* Just complain. */
24647 dwarf2_macro_malformed_definition_complaint (body
);
24652 for (i
= 0; i
< argc
; i
++)
24658 dwarf2_macro_malformed_definition_complaint (body
);
24661 /* Skip some bytes from BYTES according to the form given in FORM.
24662 Returns the new pointer. */
24664 static const gdb_byte
*
24665 skip_form_bytes (bfd
*abfd
, const gdb_byte
*bytes
, const gdb_byte
*buffer_end
,
24666 enum dwarf_form form
,
24667 unsigned int offset_size
,
24668 struct dwarf2_section_info
*section
)
24670 unsigned int bytes_read
;
24674 case DW_FORM_data1
:
24679 case DW_FORM_data2
:
24683 case DW_FORM_data4
:
24687 case DW_FORM_data8
:
24691 case DW_FORM_data16
:
24695 case DW_FORM_string
:
24696 read_direct_string (abfd
, bytes
, &bytes_read
);
24697 bytes
+= bytes_read
;
24700 case DW_FORM_sec_offset
:
24702 case DW_FORM_GNU_strp_alt
:
24703 bytes
+= offset_size
;
24706 case DW_FORM_block
:
24707 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
24708 bytes
+= bytes_read
;
24711 case DW_FORM_block1
:
24712 bytes
+= 1 + read_1_byte (abfd
, bytes
);
24714 case DW_FORM_block2
:
24715 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
24717 case DW_FORM_block4
:
24718 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
24721 case DW_FORM_addrx
:
24722 case DW_FORM_sdata
:
24724 case DW_FORM_udata
:
24725 case DW_FORM_GNU_addr_index
:
24726 case DW_FORM_GNU_str_index
:
24727 bytes
= gdb_skip_leb128 (bytes
, buffer_end
);
24730 dwarf2_section_buffer_overflow_complaint (section
);
24735 case DW_FORM_implicit_const
:
24740 complaint (_("invalid form 0x%x in `%s'"),
24741 form
, get_section_name (section
));
24749 /* A helper for dwarf_decode_macros that handles skipping an unknown
24750 opcode. Returns an updated pointer to the macro data buffer; or,
24751 on error, issues a complaint and returns NULL. */
24753 static const gdb_byte
*
24754 skip_unknown_opcode (unsigned int opcode
,
24755 const gdb_byte
**opcode_definitions
,
24756 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24758 unsigned int offset_size
,
24759 struct dwarf2_section_info
*section
)
24761 unsigned int bytes_read
, i
;
24763 const gdb_byte
*defn
;
24765 if (opcode_definitions
[opcode
] == NULL
)
24767 complaint (_("unrecognized DW_MACFINO opcode 0x%x"),
24772 defn
= opcode_definitions
[opcode
];
24773 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
24774 defn
+= bytes_read
;
24776 for (i
= 0; i
< arg
; ++i
)
24778 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
,
24779 (enum dwarf_form
) defn
[i
], offset_size
,
24781 if (mac_ptr
== NULL
)
24783 /* skip_form_bytes already issued the complaint. */
24791 /* A helper function which parses the header of a macro section.
24792 If the macro section is the extended (for now called "GNU") type,
24793 then this updates *OFFSET_SIZE. Returns a pointer to just after
24794 the header, or issues a complaint and returns NULL on error. */
24796 static const gdb_byte
*
24797 dwarf_parse_macro_header (const gdb_byte
**opcode_definitions
,
24799 const gdb_byte
*mac_ptr
,
24800 unsigned int *offset_size
,
24801 int section_is_gnu
)
24803 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
24805 if (section_is_gnu
)
24807 unsigned int version
, flags
;
24809 version
= read_2_bytes (abfd
, mac_ptr
);
24810 if (version
!= 4 && version
!= 5)
24812 complaint (_("unrecognized version `%d' in .debug_macro section"),
24818 flags
= read_1_byte (abfd
, mac_ptr
);
24820 *offset_size
= (flags
& 1) ? 8 : 4;
24822 if ((flags
& 2) != 0)
24823 /* We don't need the line table offset. */
24824 mac_ptr
+= *offset_size
;
24826 /* Vendor opcode descriptions. */
24827 if ((flags
& 4) != 0)
24829 unsigned int i
, count
;
24831 count
= read_1_byte (abfd
, mac_ptr
);
24833 for (i
= 0; i
< count
; ++i
)
24835 unsigned int opcode
, bytes_read
;
24838 opcode
= read_1_byte (abfd
, mac_ptr
);
24840 opcode_definitions
[opcode
] = mac_ptr
;
24841 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24842 mac_ptr
+= bytes_read
;
24851 /* A helper for dwarf_decode_macros that handles the GNU extensions,
24852 including DW_MACRO_import. */
24855 dwarf_decode_macro_bytes (struct dwarf2_cu
*cu
,
24857 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24858 struct macro_source_file
*current_file
,
24859 struct line_header
*lh
,
24860 struct dwarf2_section_info
*section
,
24861 int section_is_gnu
, int section_is_dwz
,
24862 unsigned int offset_size
,
24863 htab_t include_hash
)
24865 struct dwarf2_per_objfile
*dwarf2_per_objfile
24866 = cu
->per_cu
->dwarf2_per_objfile
;
24867 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24868 enum dwarf_macro_record_type macinfo_type
;
24869 int at_commandline
;
24870 const gdb_byte
*opcode_definitions
[256];
24872 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
24873 &offset_size
, section_is_gnu
);
24874 if (mac_ptr
== NULL
)
24876 /* We already issued a complaint. */
24880 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
24881 GDB is still reading the definitions from command line. First
24882 DW_MACINFO_start_file will need to be ignored as it was already executed
24883 to create CURRENT_FILE for the main source holding also the command line
24884 definitions. On first met DW_MACINFO_start_file this flag is reset to
24885 normally execute all the remaining DW_MACINFO_start_file macinfos. */
24887 at_commandline
= 1;
24891 /* Do we at least have room for a macinfo type byte? */
24892 if (mac_ptr
>= mac_end
)
24894 dwarf2_section_buffer_overflow_complaint (section
);
24898 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
24901 /* Note that we rely on the fact that the corresponding GNU and
24902 DWARF constants are the same. */
24904 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
24905 switch (macinfo_type
)
24907 /* A zero macinfo type indicates the end of the macro
24912 case DW_MACRO_define
:
24913 case DW_MACRO_undef
:
24914 case DW_MACRO_define_strp
:
24915 case DW_MACRO_undef_strp
:
24916 case DW_MACRO_define_sup
:
24917 case DW_MACRO_undef_sup
:
24919 unsigned int bytes_read
;
24924 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24925 mac_ptr
+= bytes_read
;
24927 if (macinfo_type
== DW_MACRO_define
24928 || macinfo_type
== DW_MACRO_undef
)
24930 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24931 mac_ptr
+= bytes_read
;
24935 LONGEST str_offset
;
24937 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
24938 mac_ptr
+= offset_size
;
24940 if (macinfo_type
== DW_MACRO_define_sup
24941 || macinfo_type
== DW_MACRO_undef_sup
24944 struct dwz_file
*dwz
24945 = dwarf2_get_dwz_file (dwarf2_per_objfile
);
24947 body
= read_indirect_string_from_dwz (objfile
,
24951 body
= read_indirect_string_at_offset (dwarf2_per_objfile
,
24955 is_define
= (macinfo_type
== DW_MACRO_define
24956 || macinfo_type
== DW_MACRO_define_strp
24957 || macinfo_type
== DW_MACRO_define_sup
);
24958 if (! current_file
)
24960 /* DWARF violation as no main source is present. */
24961 complaint (_("debug info with no main source gives macro %s "
24963 is_define
? _("definition") : _("undefinition"),
24967 if ((line
== 0 && !at_commandline
)
24968 || (line
!= 0 && at_commandline
))
24969 complaint (_("debug info gives %s macro %s with %s line %d: %s"),
24970 at_commandline
? _("command-line") : _("in-file"),
24971 is_define
? _("definition") : _("undefinition"),
24972 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
24976 /* Fedora's rpm-build's "debugedit" binary
24977 corrupted .debug_macro sections.
24980 https://bugzilla.redhat.com/show_bug.cgi?id=1708786 */
24981 complaint (_("debug info gives %s invalid macro %s "
24982 "without body (corrupted?) at line %d "
24984 at_commandline
? _("command-line") : _("in-file"),
24985 is_define
? _("definition") : _("undefinition"),
24986 line
, current_file
->filename
);
24988 else if (is_define
)
24989 parse_macro_definition (current_file
, line
, body
);
24992 gdb_assert (macinfo_type
== DW_MACRO_undef
24993 || macinfo_type
== DW_MACRO_undef_strp
24994 || macinfo_type
== DW_MACRO_undef_sup
);
24995 macro_undef (current_file
, line
, body
);
25000 case DW_MACRO_start_file
:
25002 unsigned int bytes_read
;
25005 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25006 mac_ptr
+= bytes_read
;
25007 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25008 mac_ptr
+= bytes_read
;
25010 if ((line
== 0 && !at_commandline
)
25011 || (line
!= 0 && at_commandline
))
25012 complaint (_("debug info gives source %d included "
25013 "from %s at %s line %d"),
25014 file
, at_commandline
? _("command-line") : _("file"),
25015 line
== 0 ? _("zero") : _("non-zero"), line
);
25017 if (at_commandline
)
25019 /* This DW_MACRO_start_file was executed in the
25021 at_commandline
= 0;
25024 current_file
= macro_start_file (cu
, file
, line
, current_file
,
25029 case DW_MACRO_end_file
:
25030 if (! current_file
)
25031 complaint (_("macro debug info has an unmatched "
25032 "`close_file' directive"));
25035 current_file
= current_file
->included_by
;
25036 if (! current_file
)
25038 enum dwarf_macro_record_type next_type
;
25040 /* GCC circa March 2002 doesn't produce the zero
25041 type byte marking the end of the compilation
25042 unit. Complain if it's not there, but exit no
25045 /* Do we at least have room for a macinfo type byte? */
25046 if (mac_ptr
>= mac_end
)
25048 dwarf2_section_buffer_overflow_complaint (section
);
25052 /* We don't increment mac_ptr here, so this is just
25055 = (enum dwarf_macro_record_type
) read_1_byte (abfd
,
25057 if (next_type
!= 0)
25058 complaint (_("no terminating 0-type entry for "
25059 "macros in `.debug_macinfo' section"));
25066 case DW_MACRO_import
:
25067 case DW_MACRO_import_sup
:
25071 bfd
*include_bfd
= abfd
;
25072 struct dwarf2_section_info
*include_section
= section
;
25073 const gdb_byte
*include_mac_end
= mac_end
;
25074 int is_dwz
= section_is_dwz
;
25075 const gdb_byte
*new_mac_ptr
;
25077 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
25078 mac_ptr
+= offset_size
;
25080 if (macinfo_type
== DW_MACRO_import_sup
)
25082 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
25084 dwarf2_read_section (objfile
, &dwz
->macro
);
25086 include_section
= &dwz
->macro
;
25087 include_bfd
= get_section_bfd_owner (include_section
);
25088 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
25092 new_mac_ptr
= include_section
->buffer
+ offset
;
25093 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
25097 /* This has actually happened; see
25098 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
25099 complaint (_("recursive DW_MACRO_import in "
25100 ".debug_macro section"));
25104 *slot
= (void *) new_mac_ptr
;
25106 dwarf_decode_macro_bytes (cu
, include_bfd
, new_mac_ptr
,
25107 include_mac_end
, current_file
, lh
,
25108 section
, section_is_gnu
, is_dwz
,
25109 offset_size
, include_hash
);
25111 htab_remove_elt (include_hash
, (void *) new_mac_ptr
);
25116 case DW_MACINFO_vendor_ext
:
25117 if (!section_is_gnu
)
25119 unsigned int bytes_read
;
25121 /* This reads the constant, but since we don't recognize
25122 any vendor extensions, we ignore it. */
25123 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25124 mac_ptr
+= bytes_read
;
25125 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
25126 mac_ptr
+= bytes_read
;
25128 /* We don't recognize any vendor extensions. */
25134 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
25135 mac_ptr
, mac_end
, abfd
, offset_size
,
25137 if (mac_ptr
== NULL
)
25142 } while (macinfo_type
!= 0);
25146 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
25147 int section_is_gnu
)
25149 struct dwarf2_per_objfile
*dwarf2_per_objfile
25150 = cu
->per_cu
->dwarf2_per_objfile
;
25151 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25152 struct line_header
*lh
= cu
->line_header
;
25154 const gdb_byte
*mac_ptr
, *mac_end
;
25155 struct macro_source_file
*current_file
= 0;
25156 enum dwarf_macro_record_type macinfo_type
;
25157 unsigned int offset_size
= cu
->header
.offset_size
;
25158 const gdb_byte
*opcode_definitions
[256];
25160 struct dwarf2_section_info
*section
;
25161 const char *section_name
;
25163 if (cu
->dwo_unit
!= NULL
)
25165 if (section_is_gnu
)
25167 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
25168 section_name
= ".debug_macro.dwo";
25172 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
25173 section_name
= ".debug_macinfo.dwo";
25178 if (section_is_gnu
)
25180 section
= &dwarf2_per_objfile
->macro
;
25181 section_name
= ".debug_macro";
25185 section
= &dwarf2_per_objfile
->macinfo
;
25186 section_name
= ".debug_macinfo";
25190 dwarf2_read_section (objfile
, section
);
25191 if (section
->buffer
== NULL
)
25193 complaint (_("missing %s section"), section_name
);
25196 abfd
= get_section_bfd_owner (section
);
25198 /* First pass: Find the name of the base filename.
25199 This filename is needed in order to process all macros whose definition
25200 (or undefinition) comes from the command line. These macros are defined
25201 before the first DW_MACINFO_start_file entry, and yet still need to be
25202 associated to the base file.
25204 To determine the base file name, we scan the macro definitions until we
25205 reach the first DW_MACINFO_start_file entry. We then initialize
25206 CURRENT_FILE accordingly so that any macro definition found before the
25207 first DW_MACINFO_start_file can still be associated to the base file. */
25209 mac_ptr
= section
->buffer
+ offset
;
25210 mac_end
= section
->buffer
+ section
->size
;
25212 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
25213 &offset_size
, section_is_gnu
);
25214 if (mac_ptr
== NULL
)
25216 /* We already issued a complaint. */
25222 /* Do we at least have room for a macinfo type byte? */
25223 if (mac_ptr
>= mac_end
)
25225 /* Complaint is printed during the second pass as GDB will probably
25226 stop the first pass earlier upon finding
25227 DW_MACINFO_start_file. */
25231 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
25234 /* Note that we rely on the fact that the corresponding GNU and
25235 DWARF constants are the same. */
25237 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
25238 switch (macinfo_type
)
25240 /* A zero macinfo type indicates the end of the macro
25245 case DW_MACRO_define
:
25246 case DW_MACRO_undef
:
25247 /* Only skip the data by MAC_PTR. */
25249 unsigned int bytes_read
;
25251 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25252 mac_ptr
+= bytes_read
;
25253 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
25254 mac_ptr
+= bytes_read
;
25258 case DW_MACRO_start_file
:
25260 unsigned int bytes_read
;
25263 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25264 mac_ptr
+= bytes_read
;
25265 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25266 mac_ptr
+= bytes_read
;
25268 current_file
= macro_start_file (cu
, file
, line
, current_file
, lh
);
25272 case DW_MACRO_end_file
:
25273 /* No data to skip by MAC_PTR. */
25276 case DW_MACRO_define_strp
:
25277 case DW_MACRO_undef_strp
:
25278 case DW_MACRO_define_sup
:
25279 case DW_MACRO_undef_sup
:
25281 unsigned int bytes_read
;
25283 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25284 mac_ptr
+= bytes_read
;
25285 mac_ptr
+= offset_size
;
25289 case DW_MACRO_import
:
25290 case DW_MACRO_import_sup
:
25291 /* Note that, according to the spec, a transparent include
25292 chain cannot call DW_MACRO_start_file. So, we can just
25293 skip this opcode. */
25294 mac_ptr
+= offset_size
;
25297 case DW_MACINFO_vendor_ext
:
25298 /* Only skip the data by MAC_PTR. */
25299 if (!section_is_gnu
)
25301 unsigned int bytes_read
;
25303 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25304 mac_ptr
+= bytes_read
;
25305 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
25306 mac_ptr
+= bytes_read
;
25311 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
25312 mac_ptr
, mac_end
, abfd
, offset_size
,
25314 if (mac_ptr
== NULL
)
25319 } while (macinfo_type
!= 0 && current_file
== NULL
);
25321 /* Second pass: Process all entries.
25323 Use the AT_COMMAND_LINE flag to determine whether we are still processing
25324 command-line macro definitions/undefinitions. This flag is unset when we
25325 reach the first DW_MACINFO_start_file entry. */
25327 htab_up
include_hash (htab_create_alloc (1, htab_hash_pointer
,
25329 NULL
, xcalloc
, xfree
));
25330 mac_ptr
= section
->buffer
+ offset
;
25331 slot
= htab_find_slot (include_hash
.get (), mac_ptr
, INSERT
);
25332 *slot
= (void *) mac_ptr
;
25333 dwarf_decode_macro_bytes (cu
, abfd
, mac_ptr
, mac_end
,
25334 current_file
, lh
, section
,
25335 section_is_gnu
, 0, offset_size
,
25336 include_hash
.get ());
25339 /* Check if the attribute's form is a DW_FORM_block*
25340 if so return true else false. */
25343 attr_form_is_block (const struct attribute
*attr
)
25345 return (attr
== NULL
? 0 :
25346 attr
->form
== DW_FORM_block1
25347 || attr
->form
== DW_FORM_block2
25348 || attr
->form
== DW_FORM_block4
25349 || attr
->form
== DW_FORM_block
25350 || attr
->form
== DW_FORM_exprloc
);
25353 /* Return non-zero if ATTR's value is a section offset --- classes
25354 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
25355 You may use DW_UNSND (attr) to retrieve such offsets.
25357 Section 7.5.4, "Attribute Encodings", explains that no attribute
25358 may have a value that belongs to more than one of these classes; it
25359 would be ambiguous if we did, because we use the same forms for all
25363 attr_form_is_section_offset (const struct attribute
*attr
)
25365 return (attr
->form
== DW_FORM_data4
25366 || attr
->form
== DW_FORM_data8
25367 || attr
->form
== DW_FORM_sec_offset
);
25370 /* Return non-zero if ATTR's value falls in the 'constant' class, or
25371 zero otherwise. When this function returns true, you can apply
25372 dwarf2_get_attr_constant_value to it.
25374 However, note that for some attributes you must check
25375 attr_form_is_section_offset before using this test. DW_FORM_data4
25376 and DW_FORM_data8 are members of both the constant class, and of
25377 the classes that contain offsets into other debug sections
25378 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
25379 that, if an attribute's can be either a constant or one of the
25380 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
25381 taken as section offsets, not constants.
25383 DW_FORM_data16 is not considered as dwarf2_get_attr_constant_value
25384 cannot handle that. */
25387 attr_form_is_constant (const struct attribute
*attr
)
25389 switch (attr
->form
)
25391 case DW_FORM_sdata
:
25392 case DW_FORM_udata
:
25393 case DW_FORM_data1
:
25394 case DW_FORM_data2
:
25395 case DW_FORM_data4
:
25396 case DW_FORM_data8
:
25397 case DW_FORM_implicit_const
:
25405 /* DW_ADDR is always stored already as sect_offset; despite for the forms
25406 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
25409 attr_form_is_ref (const struct attribute
*attr
)
25411 switch (attr
->form
)
25413 case DW_FORM_ref_addr
:
25418 case DW_FORM_ref_udata
:
25419 case DW_FORM_GNU_ref_alt
:
25426 /* Return the .debug_loc section to use for CU.
25427 For DWO files use .debug_loc.dwo. */
25429 static struct dwarf2_section_info
*
25430 cu_debug_loc_section (struct dwarf2_cu
*cu
)
25432 struct dwarf2_per_objfile
*dwarf2_per_objfile
25433 = cu
->per_cu
->dwarf2_per_objfile
;
25437 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
25439 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
25441 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
25442 : &dwarf2_per_objfile
->loc
);
25445 /* A helper function that fills in a dwarf2_loclist_baton. */
25448 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
25449 struct dwarf2_loclist_baton
*baton
,
25450 const struct attribute
*attr
)
25452 struct dwarf2_per_objfile
*dwarf2_per_objfile
25453 = cu
->per_cu
->dwarf2_per_objfile
;
25454 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
25456 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
25458 baton
->per_cu
= cu
->per_cu
;
25459 gdb_assert (baton
->per_cu
);
25460 /* We don't know how long the location list is, but make sure we
25461 don't run off the edge of the section. */
25462 baton
->size
= section
->size
- DW_UNSND (attr
);
25463 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
25464 baton
->base_address
= cu
->base_address
;
25465 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
25469 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
25470 struct dwarf2_cu
*cu
, int is_block
)
25472 struct dwarf2_per_objfile
*dwarf2_per_objfile
25473 = cu
->per_cu
->dwarf2_per_objfile
;
25474 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25475 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
25477 if (attr_form_is_section_offset (attr
)
25478 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
25479 the section. If so, fall through to the complaint in the
25481 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
25483 struct dwarf2_loclist_baton
*baton
;
25485 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
25487 fill_in_loclist_baton (cu
, baton
, attr
);
25489 if (cu
->base_known
== 0)
25490 complaint (_("Location list used without "
25491 "specifying the CU base address."));
25493 SYMBOL_ACLASS_INDEX (sym
) = (is_block
25494 ? dwarf2_loclist_block_index
25495 : dwarf2_loclist_index
);
25496 SYMBOL_LOCATION_BATON (sym
) = baton
;
25500 struct dwarf2_locexpr_baton
*baton
;
25502 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
25503 baton
->per_cu
= cu
->per_cu
;
25504 gdb_assert (baton
->per_cu
);
25506 if (attr_form_is_block (attr
))
25508 /* Note that we're just copying the block's data pointer
25509 here, not the actual data. We're still pointing into the
25510 info_buffer for SYM's objfile; right now we never release
25511 that buffer, but when we do clean up properly this may
25513 baton
->size
= DW_BLOCK (attr
)->size
;
25514 baton
->data
= DW_BLOCK (attr
)->data
;
25518 dwarf2_invalid_attrib_class_complaint ("location description",
25519 sym
->natural_name ());
25523 SYMBOL_ACLASS_INDEX (sym
) = (is_block
25524 ? dwarf2_locexpr_block_index
25525 : dwarf2_locexpr_index
);
25526 SYMBOL_LOCATION_BATON (sym
) = baton
;
25530 /* Return the OBJFILE associated with the compilation unit CU. If CU
25531 came from a separate debuginfo file, then the master objfile is
25535 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
25537 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
25539 /* Return the master objfile, so that we can report and look up the
25540 correct file containing this variable. */
25541 if (objfile
->separate_debug_objfile_backlink
)
25542 objfile
= objfile
->separate_debug_objfile_backlink
;
25547 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
25548 (CU_HEADERP is unused in such case) or prepare a temporary copy at
25549 CU_HEADERP first. */
25551 static const struct comp_unit_head
*
25552 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
25553 struct dwarf2_per_cu_data
*per_cu
)
25555 const gdb_byte
*info_ptr
;
25558 return &per_cu
->cu
->header
;
25560 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
25562 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
25563 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
25564 rcuh_kind::COMPILE
);
25569 /* Return the address size given in the compilation unit header for CU. */
25572 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
25574 struct comp_unit_head cu_header_local
;
25575 const struct comp_unit_head
*cu_headerp
;
25577 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25579 return cu_headerp
->addr_size
;
25582 /* Return the offset size given in the compilation unit header for CU. */
25585 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
25587 struct comp_unit_head cu_header_local
;
25588 const struct comp_unit_head
*cu_headerp
;
25590 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25592 return cu_headerp
->offset_size
;
25595 /* See its dwarf2loc.h declaration. */
25598 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
25600 struct comp_unit_head cu_header_local
;
25601 const struct comp_unit_head
*cu_headerp
;
25603 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25605 if (cu_headerp
->version
== 2)
25606 return cu_headerp
->addr_size
;
25608 return cu_headerp
->offset_size
;
25611 /* Return the text offset of the CU. The returned offset comes from
25612 this CU's objfile. If this objfile came from a separate debuginfo
25613 file, then the offset may be different from the corresponding
25614 offset in the parent objfile. */
25617 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
25619 return per_cu
->dwarf2_per_objfile
->objfile
->text_section_offset ();
25622 /* Return a type that is a generic pointer type, the size of which matches
25623 the address size given in the compilation unit header for PER_CU. */
25624 static struct type
*
25625 dwarf2_per_cu_addr_type (struct dwarf2_per_cu_data
*per_cu
)
25627 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
25628 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
25629 struct type
*addr_type
= lookup_pointer_type (void_type
);
25630 int addr_size
= dwarf2_per_cu_addr_size (per_cu
);
25632 if (TYPE_LENGTH (addr_type
) == addr_size
)
25636 = dwarf2_per_cu_addr_sized_int_type (per_cu
, TYPE_UNSIGNED (addr_type
));
25640 /* Return DWARF version number of PER_CU. */
25643 dwarf2_version (struct dwarf2_per_cu_data
*per_cu
)
25645 return per_cu
->dwarf_version
;
25648 /* Locate the .debug_info compilation unit from CU's objfile which contains
25649 the DIE at OFFSET. Raises an error on failure. */
25651 static struct dwarf2_per_cu_data
*
25652 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
25653 unsigned int offset_in_dwz
,
25654 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
25656 struct dwarf2_per_cu_data
*this_cu
;
25660 high
= dwarf2_per_objfile
->all_comp_units
.size () - 1;
25663 struct dwarf2_per_cu_data
*mid_cu
;
25664 int mid
= low
+ (high
- low
) / 2;
25666 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
25667 if (mid_cu
->is_dwz
> offset_in_dwz
25668 || (mid_cu
->is_dwz
== offset_in_dwz
25669 && mid_cu
->sect_off
+ mid_cu
->length
>= sect_off
))
25674 gdb_assert (low
== high
);
25675 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
25676 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
25678 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
25679 error (_("Dwarf Error: could not find partial DIE containing "
25680 "offset %s [in module %s]"),
25681 sect_offset_str (sect_off
),
25682 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
25684 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
25686 return dwarf2_per_objfile
->all_comp_units
[low
-1];
25690 if (low
== dwarf2_per_objfile
->all_comp_units
.size () - 1
25691 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
25692 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
25693 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
25698 /* Initialize dwarf2_cu CU, owned by PER_CU. */
25700 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data
*per_cu_
)
25701 : per_cu (per_cu_
),
25703 has_loclist (false),
25704 checked_producer (false),
25705 producer_is_gxx_lt_4_6 (false),
25706 producer_is_gcc_lt_4_3 (false),
25707 producer_is_icc (false),
25708 producer_is_icc_lt_14 (false),
25709 producer_is_codewarrior (false),
25710 processing_has_namespace_info (false)
25715 /* Destroy a dwarf2_cu. */
25717 dwarf2_cu::~dwarf2_cu ()
25722 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
25725 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
25726 enum language pretend_language
)
25728 struct attribute
*attr
;
25730 /* Set the language we're debugging. */
25731 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
25732 if (attr
!= nullptr)
25733 set_cu_language (DW_UNSND (attr
), cu
);
25736 cu
->language
= pretend_language
;
25737 cu
->language_defn
= language_def (cu
->language
);
25740 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
25743 /* Increase the age counter on each cached compilation unit, and free
25744 any that are too old. */
25747 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
25749 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25751 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
25752 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25753 while (per_cu
!= NULL
)
25755 per_cu
->cu
->last_used
++;
25756 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
25757 dwarf2_mark (per_cu
->cu
);
25758 per_cu
= per_cu
->cu
->read_in_chain
;
25761 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25762 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25763 while (per_cu
!= NULL
)
25765 struct dwarf2_per_cu_data
*next_cu
;
25767 next_cu
= per_cu
->cu
->read_in_chain
;
25769 if (!per_cu
->cu
->mark
)
25772 *last_chain
= next_cu
;
25775 last_chain
= &per_cu
->cu
->read_in_chain
;
25781 /* Remove a single compilation unit from the cache. */
25784 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
25786 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25787 struct dwarf2_per_objfile
*dwarf2_per_objfile
25788 = target_per_cu
->dwarf2_per_objfile
;
25790 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25791 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25792 while (per_cu
!= NULL
)
25794 struct dwarf2_per_cu_data
*next_cu
;
25796 next_cu
= per_cu
->cu
->read_in_chain
;
25798 if (per_cu
== target_per_cu
)
25802 *last_chain
= next_cu
;
25806 last_chain
= &per_cu
->cu
->read_in_chain
;
25812 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
25813 We store these in a hash table separate from the DIEs, and preserve them
25814 when the DIEs are flushed out of cache.
25816 The CU "per_cu" pointer is needed because offset alone is not enough to
25817 uniquely identify the type. A file may have multiple .debug_types sections,
25818 or the type may come from a DWO file. Furthermore, while it's more logical
25819 to use per_cu->section+offset, with Fission the section with the data is in
25820 the DWO file but we don't know that section at the point we need it.
25821 We have to use something in dwarf2_per_cu_data (or the pointer to it)
25822 because we can enter the lookup routine, get_die_type_at_offset, from
25823 outside this file, and thus won't necessarily have PER_CU->cu.
25824 Fortunately, PER_CU is stable for the life of the objfile. */
25826 struct dwarf2_per_cu_offset_and_type
25828 const struct dwarf2_per_cu_data
*per_cu
;
25829 sect_offset sect_off
;
25833 /* Hash function for a dwarf2_per_cu_offset_and_type. */
25836 per_cu_offset_and_type_hash (const void *item
)
25838 const struct dwarf2_per_cu_offset_and_type
*ofs
25839 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
25841 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
25844 /* Equality function for a dwarf2_per_cu_offset_and_type. */
25847 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
25849 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
25850 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
25851 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
25852 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
25854 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
25855 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
25858 /* Set the type associated with DIE to TYPE. Save it in CU's hash
25859 table if necessary. For convenience, return TYPE.
25861 The DIEs reading must have careful ordering to:
25862 * Not cause infinite loops trying to read in DIEs as a prerequisite for
25863 reading current DIE.
25864 * Not trying to dereference contents of still incompletely read in types
25865 while reading in other DIEs.
25866 * Enable referencing still incompletely read in types just by a pointer to
25867 the type without accessing its fields.
25869 Therefore caller should follow these rules:
25870 * Try to fetch any prerequisite types we may need to build this DIE type
25871 before building the type and calling set_die_type.
25872 * After building type call set_die_type for current DIE as soon as
25873 possible before fetching more types to complete the current type.
25874 * Make the type as complete as possible before fetching more types. */
25876 static struct type
*
25877 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
25879 struct dwarf2_per_objfile
*dwarf2_per_objfile
25880 = cu
->per_cu
->dwarf2_per_objfile
;
25881 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
25882 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25883 struct attribute
*attr
;
25884 struct dynamic_prop prop
;
25886 /* For Ada types, make sure that the gnat-specific data is always
25887 initialized (if not already set). There are a few types where
25888 we should not be doing so, because the type-specific area is
25889 already used to hold some other piece of info (eg: TYPE_CODE_FLT
25890 where the type-specific area is used to store the floatformat).
25891 But this is not a problem, because the gnat-specific information
25892 is actually not needed for these types. */
25893 if (need_gnat_info (cu
)
25894 && TYPE_CODE (type
) != TYPE_CODE_FUNC
25895 && TYPE_CODE (type
) != TYPE_CODE_FLT
25896 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
25897 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
25898 && TYPE_CODE (type
) != TYPE_CODE_METHOD
25899 && !HAVE_GNAT_AUX_INFO (type
))
25900 INIT_GNAT_SPECIFIC (type
);
25902 /* Read DW_AT_allocated and set in type. */
25903 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
25904 if (attr_form_is_block (attr
))
25906 struct type
*prop_type
25907 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
25908 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
25909 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
);
25911 else if (attr
!= NULL
)
25913 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
25914 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25915 sect_offset_str (die
->sect_off
));
25918 /* Read DW_AT_associated and set in type. */
25919 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
25920 if (attr_form_is_block (attr
))
25922 struct type
*prop_type
25923 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
25924 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
25925 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
);
25927 else if (attr
!= NULL
)
25929 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
25930 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25931 sect_offset_str (die
->sect_off
));
25934 /* Read DW_AT_data_location and set in type. */
25935 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
25936 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
,
25937 dwarf2_per_cu_addr_type (cu
->per_cu
)))
25938 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
);
25940 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25942 dwarf2_per_objfile
->die_type_hash
=
25943 htab_create_alloc_ex (127,
25944 per_cu_offset_and_type_hash
,
25945 per_cu_offset_and_type_eq
,
25947 &objfile
->objfile_obstack
,
25948 hashtab_obstack_allocate
,
25949 dummy_obstack_deallocate
);
25952 ofs
.per_cu
= cu
->per_cu
;
25953 ofs
.sect_off
= die
->sect_off
;
25955 slot
= (struct dwarf2_per_cu_offset_and_type
**)
25956 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
25958 complaint (_("A problem internal to GDB: DIE %s has type already set"),
25959 sect_offset_str (die
->sect_off
));
25960 *slot
= XOBNEW (&objfile
->objfile_obstack
,
25961 struct dwarf2_per_cu_offset_and_type
);
25966 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
25967 or return NULL if the die does not have a saved type. */
25969 static struct type
*
25970 get_die_type_at_offset (sect_offset sect_off
,
25971 struct dwarf2_per_cu_data
*per_cu
)
25973 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
25974 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
25976 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25979 ofs
.per_cu
= per_cu
;
25980 ofs
.sect_off
= sect_off
;
25981 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
25982 htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
));
25989 /* Look up the type for DIE in CU in die_type_hash,
25990 or return NULL if DIE does not have a saved type. */
25992 static struct type
*
25993 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
25995 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
25998 /* Add a dependence relationship from CU to REF_PER_CU. */
26001 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
26002 struct dwarf2_per_cu_data
*ref_per_cu
)
26006 if (cu
->dependencies
== NULL
)
26008 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
26009 NULL
, &cu
->comp_unit_obstack
,
26010 hashtab_obstack_allocate
,
26011 dummy_obstack_deallocate
);
26013 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
26015 *slot
= ref_per_cu
;
26018 /* Subroutine of dwarf2_mark to pass to htab_traverse.
26019 Set the mark field in every compilation unit in the
26020 cache that we must keep because we are keeping CU. */
26023 dwarf2_mark_helper (void **slot
, void *data
)
26025 struct dwarf2_per_cu_data
*per_cu
;
26027 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
26029 /* cu->dependencies references may not yet have been ever read if QUIT aborts
26030 reading of the chain. As such dependencies remain valid it is not much
26031 useful to track and undo them during QUIT cleanups. */
26032 if (per_cu
->cu
== NULL
)
26035 if (per_cu
->cu
->mark
)
26037 per_cu
->cu
->mark
= true;
26039 if (per_cu
->cu
->dependencies
!= NULL
)
26040 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
26045 /* Set the mark field in CU and in every other compilation unit in the
26046 cache that we must keep because we are keeping CU. */
26049 dwarf2_mark (struct dwarf2_cu
*cu
)
26054 if (cu
->dependencies
!= NULL
)
26055 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
26059 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
26063 per_cu
->cu
->mark
= false;
26064 per_cu
= per_cu
->cu
->read_in_chain
;
26068 /* Trivial hash function for partial_die_info: the hash value of a DIE
26069 is its offset in .debug_info for this objfile. */
26072 partial_die_hash (const void *item
)
26074 const struct partial_die_info
*part_die
26075 = (const struct partial_die_info
*) item
;
26077 return to_underlying (part_die
->sect_off
);
26080 /* Trivial comparison function for partial_die_info structures: two DIEs
26081 are equal if they have the same offset. */
26084 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
26086 const struct partial_die_info
*part_die_lhs
26087 = (const struct partial_die_info
*) item_lhs
;
26088 const struct partial_die_info
*part_die_rhs
26089 = (const struct partial_die_info
*) item_rhs
;
26091 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
26094 struct cmd_list_element
*set_dwarf_cmdlist
;
26095 struct cmd_list_element
*show_dwarf_cmdlist
;
26098 set_dwarf_cmd (const char *args
, int from_tty
)
26100 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
26105 show_dwarf_cmd (const char *args
, int from_tty
)
26107 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
26110 bool dwarf_always_disassemble
;
26113 show_dwarf_always_disassemble (struct ui_file
*file
, int from_tty
,
26114 struct cmd_list_element
*c
, const char *value
)
26116 fprintf_filtered (file
,
26117 _("Whether to always disassemble "
26118 "DWARF expressions is %s.\n"),
26123 show_check_physname (struct ui_file
*file
, int from_tty
,
26124 struct cmd_list_element
*c
, const char *value
)
26126 fprintf_filtered (file
,
26127 _("Whether to check \"physname\" is %s.\n"),
26131 void _initialize_dwarf2_read ();
26133 _initialize_dwarf2_read ()
26135 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
26136 Set DWARF specific variables.\n\
26137 Configure DWARF variables such as the cache size."),
26138 &set_dwarf_cmdlist
, "maintenance set dwarf ",
26139 0/*allow-unknown*/, &maintenance_set_cmdlist
);
26141 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
26142 Show DWARF specific variables.\n\
26143 Show DWARF variables such as the cache size."),
26144 &show_dwarf_cmdlist
, "maintenance show dwarf ",
26145 0/*allow-unknown*/, &maintenance_show_cmdlist
);
26147 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
26148 &dwarf_max_cache_age
, _("\
26149 Set the upper bound on the age of cached DWARF compilation units."), _("\
26150 Show the upper bound on the age of cached DWARF compilation units."), _("\
26151 A higher limit means that cached compilation units will be stored\n\
26152 in memory longer, and more total memory will be used. Zero disables\n\
26153 caching, which can slow down startup."),
26155 show_dwarf_max_cache_age
,
26156 &set_dwarf_cmdlist
,
26157 &show_dwarf_cmdlist
);
26159 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
26160 &dwarf_always_disassemble
, _("\
26161 Set whether `info address' always disassembles DWARF expressions."), _("\
26162 Show whether `info address' always disassembles DWARF expressions."), _("\
26163 When enabled, DWARF expressions are always printed in an assembly-like\n\
26164 syntax. When disabled, expressions will be printed in a more\n\
26165 conversational style, when possible."),
26167 show_dwarf_always_disassemble
,
26168 &set_dwarf_cmdlist
,
26169 &show_dwarf_cmdlist
);
26171 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
26172 Set debugging of the DWARF reader."), _("\
26173 Show debugging of the DWARF reader."), _("\
26174 When enabled (non-zero), debugging messages are printed during DWARF\n\
26175 reading and symtab expansion. A value of 1 (one) provides basic\n\
26176 information. A value greater than 1 provides more verbose information."),
26179 &setdebuglist
, &showdebuglist
);
26181 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
26182 Set debugging of the DWARF DIE reader."), _("\
26183 Show debugging of the DWARF DIE reader."), _("\
26184 When enabled (non-zero), DIEs are dumped after they are read in.\n\
26185 The value is the maximum depth to print."),
26188 &setdebuglist
, &showdebuglist
);
26190 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
26191 Set debugging of the dwarf line reader."), _("\
26192 Show debugging of the dwarf line reader."), _("\
26193 When enabled (non-zero), line number entries are dumped as they are read in.\n\
26194 A value of 1 (one) provides basic information.\n\
26195 A value greater than 1 provides more verbose information."),
26198 &setdebuglist
, &showdebuglist
);
26200 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
26201 Set cross-checking of \"physname\" code against demangler."), _("\
26202 Show cross-checking of \"physname\" code against demangler."), _("\
26203 When enabled, GDB's internal \"physname\" code is checked against\n\
26205 NULL
, show_check_physname
,
26206 &setdebuglist
, &showdebuglist
);
26208 add_setshow_boolean_cmd ("use-deprecated-index-sections",
26209 no_class
, &use_deprecated_index_sections
, _("\
26210 Set whether to use deprecated gdb_index sections."), _("\
26211 Show whether to use deprecated gdb_index sections."), _("\
26212 When enabled, deprecated .gdb_index sections are used anyway.\n\
26213 Normally they are ignored either because of a missing feature or\n\
26214 performance issue.\n\
26215 Warning: This option must be enabled before gdb reads the file."),
26218 &setlist
, &showlist
);
26220 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
26221 &dwarf2_locexpr_funcs
);
26222 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
26223 &dwarf2_loclist_funcs
);
26225 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
26226 &dwarf2_block_frame_base_locexpr_funcs
);
26227 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
26228 &dwarf2_block_frame_base_loclist_funcs
);
26231 selftests::register_test ("dw2_expand_symtabs_matching",
26232 selftests::dw2_expand_symtabs_matching::run_test
);