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 void psymtab_to_symtab_1 (dwarf2_psymtab
*);
1518 static abbrev_table_up abbrev_table_read_table
1519 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, struct dwarf2_section_info
*,
1522 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1524 static struct partial_die_info
*load_partial_dies
1525 (const struct die_reader_specs
*, const gdb_byte
*, int);
1527 /* A pair of partial_die_info and compilation unit. */
1528 struct cu_partial_die_info
1530 /* The compilation unit of the partial_die_info. */
1531 struct dwarf2_cu
*cu
;
1532 /* A partial_die_info. */
1533 struct partial_die_info
*pdi
;
1535 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1541 cu_partial_die_info () = delete;
1544 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1545 struct dwarf2_cu
*);
1547 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1548 struct attribute
*, struct attr_abbrev
*,
1549 const gdb_byte
*, bool *need_reprocess
);
1551 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1552 struct attribute
*attr
);
1554 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1556 static unsigned int read_1_byte (bfd
*, const gdb_byte
*);
1558 static int read_1_signed_byte (bfd
*, const gdb_byte
*);
1560 static unsigned int read_2_bytes (bfd
*, const gdb_byte
*);
1562 /* Read the next three bytes (little-endian order) as an unsigned integer. */
1563 static unsigned int read_3_bytes (bfd
*, const gdb_byte
*);
1565 static unsigned int read_4_bytes (bfd
*, const gdb_byte
*);
1567 static ULONGEST
read_8_bytes (bfd
*, const gdb_byte
*);
1569 static CORE_ADDR
read_address (bfd
*, const gdb_byte
*ptr
, struct dwarf2_cu
*,
1572 static LONGEST
read_initial_length (bfd
*, const gdb_byte
*, unsigned int *);
1574 static LONGEST read_checked_initial_length_and_offset
1575 (bfd
*, const gdb_byte
*, const struct comp_unit_head
*,
1576 unsigned int *, unsigned int *);
1578 static LONGEST
read_offset (bfd
*, const gdb_byte
*,
1579 const struct comp_unit_head
*,
1582 static LONGEST
read_offset_1 (bfd
*, const gdb_byte
*, unsigned int);
1584 static sect_offset read_abbrev_offset
1585 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1586 struct dwarf2_section_info
*, sect_offset
);
1588 static const gdb_byte
*read_n_bytes (bfd
*, const gdb_byte
*, unsigned int);
1590 static const char *read_direct_string (bfd
*, const gdb_byte
*, unsigned int *);
1592 static const char *read_indirect_string
1593 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1594 const struct comp_unit_head
*, unsigned int *);
1596 static const char *read_indirect_line_string
1597 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1598 const struct comp_unit_head
*, unsigned int *);
1600 static const char *read_indirect_string_at_offset
1601 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
1602 LONGEST str_offset
);
1604 static const char *read_indirect_string_from_dwz
1605 (struct objfile
*objfile
, struct dwz_file
*, LONGEST
);
1607 static LONGEST
read_signed_leb128 (bfd
*, const gdb_byte
*, unsigned int *);
1609 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1613 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1614 ULONGEST str_index
);
1616 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1617 ULONGEST str_index
);
1619 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1621 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1622 struct dwarf2_cu
*);
1624 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1627 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1628 struct dwarf2_cu
*cu
);
1630 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1632 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1633 struct dwarf2_cu
*cu
);
1635 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1637 static struct die_info
*die_specification (struct die_info
*die
,
1638 struct dwarf2_cu
**);
1640 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1641 struct dwarf2_cu
*cu
);
1643 static void dwarf_decode_lines (struct line_header
*, const char *,
1644 struct dwarf2_cu
*, dwarf2_psymtab
*,
1645 CORE_ADDR
, int decode_mapping
);
1647 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1650 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1651 struct dwarf2_cu
*, struct symbol
* = NULL
);
1653 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1654 struct dwarf2_cu
*);
1656 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1659 struct obstack
*obstack
,
1660 struct dwarf2_cu
*cu
, LONGEST
*value
,
1661 const gdb_byte
**bytes
,
1662 struct dwarf2_locexpr_baton
**baton
);
1664 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1666 static int need_gnat_info (struct dwarf2_cu
*);
1668 static struct type
*die_descriptive_type (struct die_info
*,
1669 struct dwarf2_cu
*);
1671 static void set_descriptive_type (struct type
*, struct die_info
*,
1672 struct dwarf2_cu
*);
1674 static struct type
*die_containing_type (struct die_info
*,
1675 struct dwarf2_cu
*);
1677 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1678 struct dwarf2_cu
*);
1680 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1682 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1684 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1686 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1687 const char *suffix
, int physname
,
1688 struct dwarf2_cu
*cu
);
1690 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1692 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1694 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1696 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1698 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1700 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1702 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1703 struct dwarf2_cu
*, dwarf2_psymtab
*);
1705 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1706 values. Keep the items ordered with increasing constraints compliance. */
1709 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1710 PC_BOUNDS_NOT_PRESENT
,
1712 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1713 were present but they do not form a valid range of PC addresses. */
1716 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1719 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1723 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1724 CORE_ADDR
*, CORE_ADDR
*,
1728 static void get_scope_pc_bounds (struct die_info
*,
1729 CORE_ADDR
*, CORE_ADDR
*,
1730 struct dwarf2_cu
*);
1732 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1733 CORE_ADDR
, struct dwarf2_cu
*);
1735 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1736 struct dwarf2_cu
*);
1738 static void dwarf2_attach_fields_to_type (struct field_info
*,
1739 struct type
*, struct dwarf2_cu
*);
1741 static void dwarf2_add_member_fn (struct field_info
*,
1742 struct die_info
*, struct type
*,
1743 struct dwarf2_cu
*);
1745 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1747 struct dwarf2_cu
*);
1749 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1751 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1753 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1755 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1757 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1759 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1761 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1763 static struct type
*read_module_type (struct die_info
*die
,
1764 struct dwarf2_cu
*cu
);
1766 static const char *namespace_name (struct die_info
*die
,
1767 int *is_anonymous
, struct dwarf2_cu
*);
1769 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1771 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1773 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1774 struct dwarf2_cu
*);
1776 static struct die_info
*read_die_and_siblings_1
1777 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1780 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1781 const gdb_byte
*info_ptr
,
1782 const gdb_byte
**new_info_ptr
,
1783 struct die_info
*parent
);
1785 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1786 struct die_info
**, const gdb_byte
*,
1789 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1790 struct die_info
**, const gdb_byte
*,
1793 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1795 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1798 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1800 static const char *dwarf2_full_name (const char *name
,
1801 struct die_info
*die
,
1802 struct dwarf2_cu
*cu
);
1804 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1805 struct dwarf2_cu
*cu
);
1807 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1808 struct dwarf2_cu
**);
1810 static const char *dwarf_tag_name (unsigned int);
1812 static const char *dwarf_attr_name (unsigned int);
1814 static const char *dwarf_unit_type_name (int unit_type
);
1816 static const char *dwarf_form_name (unsigned int);
1818 static const char *dwarf_bool_name (unsigned int);
1820 static const char *dwarf_type_encoding_name (unsigned int);
1822 static struct die_info
*sibling_die (struct die_info
*);
1824 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1826 static void dump_die_for_error (struct die_info
*);
1828 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1831 /*static*/ void dump_die (struct die_info
*, int max_level
);
1833 static void store_in_ref_table (struct die_info
*,
1834 struct dwarf2_cu
*);
1836 static sect_offset
dwarf2_get_ref_die_offset (const struct attribute
*);
1838 static LONGEST
dwarf2_get_attr_constant_value (const struct attribute
*, int);
1840 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1841 const struct attribute
*,
1842 struct dwarf2_cu
**);
1844 static struct die_info
*follow_die_ref (struct die_info
*,
1845 const struct attribute
*,
1846 struct dwarf2_cu
**);
1848 static struct die_info
*follow_die_sig (struct die_info
*,
1849 const struct attribute
*,
1850 struct dwarf2_cu
**);
1852 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1853 struct dwarf2_cu
*);
1855 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1856 const struct attribute
*,
1857 struct dwarf2_cu
*);
1859 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1861 static void read_signatured_type (struct signatured_type
*);
1863 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1864 struct die_info
*die
, struct dwarf2_cu
*cu
,
1865 struct dynamic_prop
*prop
, struct type
*type
);
1867 /* memory allocation interface */
1869 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1871 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1873 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1875 static int attr_form_is_block (const struct attribute
*);
1877 static int attr_form_is_section_offset (const struct attribute
*);
1879 static int attr_form_is_constant (const struct attribute
*);
1881 static int attr_form_is_ref (const struct attribute
*);
1883 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1884 struct dwarf2_loclist_baton
*baton
,
1885 const struct attribute
*attr
);
1887 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1889 struct dwarf2_cu
*cu
,
1892 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1893 const gdb_byte
*info_ptr
,
1894 struct abbrev_info
*abbrev
);
1896 static hashval_t
partial_die_hash (const void *item
);
1898 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1900 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1901 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1902 struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1904 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1905 struct die_info
*comp_unit_die
,
1906 enum language pretend_language
);
1908 static void age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1910 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1912 static struct type
*set_die_type (struct die_info
*, struct type
*,
1913 struct dwarf2_cu
*);
1915 static void create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1917 static int create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1919 static void load_full_comp_unit (struct dwarf2_per_cu_data
*, bool,
1922 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1925 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1928 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1929 struct dwarf2_per_cu_data
*);
1931 static void dwarf2_mark (struct dwarf2_cu
*);
1933 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1935 static struct type
*get_die_type_at_offset (sect_offset
,
1936 struct dwarf2_per_cu_data
*);
1938 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1940 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1941 enum language pretend_language
);
1943 static void process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1945 static struct type
*dwarf2_per_cu_addr_type (struct dwarf2_per_cu_data
*per_cu
);
1946 static struct type
*dwarf2_per_cu_addr_sized_int_type
1947 (struct dwarf2_per_cu_data
*per_cu
, bool unsigned_p
);
1948 static struct type
*dwarf2_per_cu_int_type
1949 (struct dwarf2_per_cu_data
*per_cu
, int size_in_bytes
,
1952 /* Class, the destructor of which frees all allocated queue entries. This
1953 will only have work to do if an error was thrown while processing the
1954 dwarf. If no error was thrown then the queue entries should have all
1955 been processed, and freed, as we went along. */
1957 class dwarf2_queue_guard
1960 dwarf2_queue_guard () = default;
1962 /* Free any entries remaining on the queue. There should only be
1963 entries left if we hit an error while processing the dwarf. */
1964 ~dwarf2_queue_guard ()
1966 struct dwarf2_queue_item
*item
, *last
;
1968 item
= dwarf2_queue
;
1971 /* Anything still marked queued is likely to be in an
1972 inconsistent state, so discard it. */
1973 if (item
->per_cu
->queued
)
1975 if (item
->per_cu
->cu
!= NULL
)
1976 free_one_cached_comp_unit (item
->per_cu
);
1977 item
->per_cu
->queued
= 0;
1985 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
1989 /* The return type of find_file_and_directory. Note, the enclosed
1990 string pointers are only valid while this object is valid. */
1992 struct file_and_directory
1994 /* The filename. This is never NULL. */
1997 /* The compilation directory. NULL if not known. If we needed to
1998 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1999 points directly to the DW_AT_comp_dir string attribute owned by
2000 the obstack that owns the DIE. */
2001 const char *comp_dir
;
2003 /* If we needed to build a new string for comp_dir, this is what
2004 owns the storage. */
2005 std::string comp_dir_storage
;
2008 static file_and_directory
find_file_and_directory (struct die_info
*die
,
2009 struct dwarf2_cu
*cu
);
2011 static char *file_full_name (int file
, struct line_header
*lh
,
2012 const char *comp_dir
);
2014 /* Expected enum dwarf_unit_type for read_comp_unit_head. */
2015 enum class rcuh_kind
{ COMPILE
, TYPE
};
2017 static const gdb_byte
*read_and_check_comp_unit_head
2018 (struct dwarf2_per_objfile
* dwarf2_per_objfile
,
2019 struct comp_unit_head
*header
,
2020 struct dwarf2_section_info
*section
,
2021 struct dwarf2_section_info
*abbrev_section
, const gdb_byte
*info_ptr
,
2022 rcuh_kind section_kind
);
2024 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
2026 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
2028 static struct dwo_unit
*lookup_dwo_unit_in_dwp
2029 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2030 struct dwp_file
*dwp_file
, const char *comp_dir
,
2031 ULONGEST signature
, int is_debug_types
);
2033 static struct dwp_file
*get_dwp_file
2034 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2036 static struct dwo_unit
*lookup_dwo_comp_unit
2037 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
2039 static struct dwo_unit
*lookup_dwo_type_unit
2040 (struct signatured_type
*, const char *, const char *);
2042 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
2044 /* A unique pointer to a dwo_file. */
2046 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
2048 static void process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2050 static void check_producer (struct dwarf2_cu
*cu
);
2052 static void free_line_header_voidp (void *arg
);
2054 /* Various complaints about symbol reading that don't abort the process. */
2057 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
2059 complaint (_("statement list doesn't fit in .debug_line section"));
2063 dwarf2_debug_line_missing_file_complaint (void)
2065 complaint (_(".debug_line section has line data without a file"));
2069 dwarf2_debug_line_missing_end_sequence_complaint (void)
2071 complaint (_(".debug_line section has line "
2072 "program sequence without an end"));
2076 dwarf2_complex_location_expr_complaint (void)
2078 complaint (_("location expression too complex"));
2082 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
2085 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
2090 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
2092 complaint (_("debug info runs off end of %s section"
2094 get_section_name (section
),
2095 get_section_file_name (section
));
2099 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
2101 complaint (_("macro debug info contains a "
2102 "malformed macro definition:\n`%s'"),
2107 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
2109 complaint (_("invalid attribute class or form for '%s' in '%s'"),
2113 /* Hash function for line_header_hash. */
2116 line_header_hash (const struct line_header
*ofs
)
2118 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
2121 /* Hash function for htab_create_alloc_ex for line_header_hash. */
2124 line_header_hash_voidp (const void *item
)
2126 const struct line_header
*ofs
= (const struct line_header
*) item
;
2128 return line_header_hash (ofs
);
2131 /* Equality function for line_header_hash. */
2134 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
2136 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
2137 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
2139 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
2140 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
2145 /* Read the given attribute value as an address, taking the attribute's
2146 form into account. */
2149 attr_value_as_address (struct attribute
*attr
)
2153 if (attr
->form
!= DW_FORM_addr
&& attr
->form
!= DW_FORM_addrx
2154 && attr
->form
!= DW_FORM_GNU_addr_index
)
2156 /* Aside from a few clearly defined exceptions, attributes that
2157 contain an address must always be in DW_FORM_addr form.
2158 Unfortunately, some compilers happen to be violating this
2159 requirement by encoding addresses using other forms, such
2160 as DW_FORM_data4 for example. For those broken compilers,
2161 we try to do our best, without any guarantee of success,
2162 to interpret the address correctly. It would also be nice
2163 to generate a complaint, but that would require us to maintain
2164 a list of legitimate cases where a non-address form is allowed,
2165 as well as update callers to pass in at least the CU's DWARF
2166 version. This is more overhead than what we're willing to
2167 expand for a pretty rare case. */
2168 addr
= DW_UNSND (attr
);
2171 addr
= DW_ADDR (attr
);
2176 /* See declaration. */
2178 dwarf2_per_objfile::dwarf2_per_objfile (struct objfile
*objfile_
,
2179 const dwarf2_debug_sections
*names
,
2181 : objfile (objfile_
),
2182 can_copy (can_copy_
)
2185 names
= &dwarf2_elf_names
;
2187 bfd
*obfd
= objfile
->obfd
;
2189 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
2190 locate_sections (obfd
, sec
, *names
);
2193 dwarf2_per_objfile::~dwarf2_per_objfile ()
2195 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
2196 free_cached_comp_units ();
2198 if (quick_file_names_table
)
2199 htab_delete (quick_file_names_table
);
2201 if (line_header_hash
)
2202 htab_delete (line_header_hash
);
2204 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
2205 per_cu
->imported_symtabs_free ();
2207 for (signatured_type
*sig_type
: all_type_units
)
2208 sig_type
->per_cu
.imported_symtabs_free ();
2210 /* Everything else should be on the objfile obstack. */
2213 /* See declaration. */
2216 dwarf2_per_objfile::free_cached_comp_units ()
2218 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
2219 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
2220 while (per_cu
!= NULL
)
2222 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
2225 *last_chain
= next_cu
;
2230 /* A helper class that calls free_cached_comp_units on
2233 class free_cached_comp_units
2237 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
2238 : m_per_objfile (per_objfile
)
2242 ~free_cached_comp_units ()
2244 m_per_objfile
->free_cached_comp_units ();
2247 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
2251 dwarf2_per_objfile
*m_per_objfile
;
2254 /* Try to locate the sections we need for DWARF 2 debugging
2255 information and return true if we have enough to do something.
2256 NAMES points to the dwarf2 section names, or is NULL if the standard
2257 ELF names are used. CAN_COPY is true for formats where symbol
2258 interposition is possible and so symbol values must follow copy
2259 relocation rules. */
2262 dwarf2_has_info (struct objfile
*objfile
,
2263 const struct dwarf2_debug_sections
*names
,
2266 if (objfile
->flags
& OBJF_READNEVER
)
2269 struct dwarf2_per_objfile
*dwarf2_per_objfile
2270 = get_dwarf2_per_objfile (objfile
);
2272 if (dwarf2_per_objfile
== NULL
)
2273 dwarf2_per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
,
2277 return (!dwarf2_per_objfile
->info
.is_virtual
2278 && dwarf2_per_objfile
->info
.s
.section
!= NULL
2279 && !dwarf2_per_objfile
->abbrev
.is_virtual
2280 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
2283 /* Return the containing section of virtual section SECTION. */
2285 static struct dwarf2_section_info
*
2286 get_containing_section (const struct dwarf2_section_info
*section
)
2288 gdb_assert (section
->is_virtual
);
2289 return section
->s
.containing_section
;
2292 /* Return the bfd owner of SECTION. */
2295 get_section_bfd_owner (const struct dwarf2_section_info
*section
)
2297 if (section
->is_virtual
)
2299 section
= get_containing_section (section
);
2300 gdb_assert (!section
->is_virtual
);
2302 return section
->s
.section
->owner
;
2305 /* Return the bfd section of SECTION.
2306 Returns NULL if the section is not present. */
2309 get_section_bfd_section (const struct dwarf2_section_info
*section
)
2311 if (section
->is_virtual
)
2313 section
= get_containing_section (section
);
2314 gdb_assert (!section
->is_virtual
);
2316 return section
->s
.section
;
2319 /* Return the name of SECTION. */
2322 get_section_name (const struct dwarf2_section_info
*section
)
2324 asection
*sectp
= get_section_bfd_section (section
);
2326 gdb_assert (sectp
!= NULL
);
2327 return bfd_section_name (sectp
);
2330 /* Return the name of the file SECTION is in. */
2333 get_section_file_name (const struct dwarf2_section_info
*section
)
2335 bfd
*abfd
= get_section_bfd_owner (section
);
2337 return bfd_get_filename (abfd
);
2340 /* Return the id of SECTION.
2341 Returns 0 if SECTION doesn't exist. */
2344 get_section_id (const struct dwarf2_section_info
*section
)
2346 asection
*sectp
= get_section_bfd_section (section
);
2353 /* Return the flags of SECTION.
2354 SECTION (or containing section if this is a virtual section) must exist. */
2357 get_section_flags (const struct dwarf2_section_info
*section
)
2359 asection
*sectp
= get_section_bfd_section (section
);
2361 gdb_assert (sectp
!= NULL
);
2362 return bfd_section_flags (sectp
);
2365 /* When loading sections, we look either for uncompressed section or for
2366 compressed section names. */
2369 section_is_p (const char *section_name
,
2370 const struct dwarf2_section_names
*names
)
2372 if (names
->normal
!= NULL
2373 && strcmp (section_name
, names
->normal
) == 0)
2375 if (names
->compressed
!= NULL
2376 && strcmp (section_name
, names
->compressed
) == 0)
2381 /* See declaration. */
2384 dwarf2_per_objfile::locate_sections (bfd
*abfd
, asection
*sectp
,
2385 const dwarf2_debug_sections
&names
)
2387 flagword aflag
= bfd_section_flags (sectp
);
2389 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
2392 else if (elf_section_data (sectp
)->this_hdr
.sh_size
2393 > bfd_get_file_size (abfd
))
2395 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
2396 warning (_("Discarding section %s which has a section size (%s"
2397 ") larger than the file size [in module %s]"),
2398 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
2399 bfd_get_filename (abfd
));
2401 else if (section_is_p (sectp
->name
, &names
.info
))
2403 this->info
.s
.section
= sectp
;
2404 this->info
.size
= bfd_section_size (sectp
);
2406 else if (section_is_p (sectp
->name
, &names
.abbrev
))
2408 this->abbrev
.s
.section
= sectp
;
2409 this->abbrev
.size
= bfd_section_size (sectp
);
2411 else if (section_is_p (sectp
->name
, &names
.line
))
2413 this->line
.s
.section
= sectp
;
2414 this->line
.size
= bfd_section_size (sectp
);
2416 else if (section_is_p (sectp
->name
, &names
.loc
))
2418 this->loc
.s
.section
= sectp
;
2419 this->loc
.size
= bfd_section_size (sectp
);
2421 else if (section_is_p (sectp
->name
, &names
.loclists
))
2423 this->loclists
.s
.section
= sectp
;
2424 this->loclists
.size
= bfd_section_size (sectp
);
2426 else if (section_is_p (sectp
->name
, &names
.macinfo
))
2428 this->macinfo
.s
.section
= sectp
;
2429 this->macinfo
.size
= bfd_section_size (sectp
);
2431 else if (section_is_p (sectp
->name
, &names
.macro
))
2433 this->macro
.s
.section
= sectp
;
2434 this->macro
.size
= bfd_section_size (sectp
);
2436 else if (section_is_p (sectp
->name
, &names
.str
))
2438 this->str
.s
.section
= sectp
;
2439 this->str
.size
= bfd_section_size (sectp
);
2441 else if (section_is_p (sectp
->name
, &names
.str_offsets
))
2443 this->str_offsets
.s
.section
= sectp
;
2444 this->str_offsets
.size
= bfd_section_size (sectp
);
2446 else if (section_is_p (sectp
->name
, &names
.line_str
))
2448 this->line_str
.s
.section
= sectp
;
2449 this->line_str
.size
= bfd_section_size (sectp
);
2451 else if (section_is_p (sectp
->name
, &names
.addr
))
2453 this->addr
.s
.section
= sectp
;
2454 this->addr
.size
= bfd_section_size (sectp
);
2456 else if (section_is_p (sectp
->name
, &names
.frame
))
2458 this->frame
.s
.section
= sectp
;
2459 this->frame
.size
= bfd_section_size (sectp
);
2461 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
2463 this->eh_frame
.s
.section
= sectp
;
2464 this->eh_frame
.size
= bfd_section_size (sectp
);
2466 else if (section_is_p (sectp
->name
, &names
.ranges
))
2468 this->ranges
.s
.section
= sectp
;
2469 this->ranges
.size
= bfd_section_size (sectp
);
2471 else if (section_is_p (sectp
->name
, &names
.rnglists
))
2473 this->rnglists
.s
.section
= sectp
;
2474 this->rnglists
.size
= bfd_section_size (sectp
);
2476 else if (section_is_p (sectp
->name
, &names
.types
))
2478 struct dwarf2_section_info type_section
;
2480 memset (&type_section
, 0, sizeof (type_section
));
2481 type_section
.s
.section
= sectp
;
2482 type_section
.size
= bfd_section_size (sectp
);
2484 this->types
.push_back (type_section
);
2486 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
2488 this->gdb_index
.s
.section
= sectp
;
2489 this->gdb_index
.size
= bfd_section_size (sectp
);
2491 else if (section_is_p (sectp
->name
, &names
.debug_names
))
2493 this->debug_names
.s
.section
= sectp
;
2494 this->debug_names
.size
= bfd_section_size (sectp
);
2496 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
2498 this->debug_aranges
.s
.section
= sectp
;
2499 this->debug_aranges
.size
= bfd_section_size (sectp
);
2502 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2503 && bfd_section_vma (sectp
) == 0)
2504 this->has_section_at_zero
= true;
2507 /* A helper function that decides whether a section is empty,
2511 dwarf2_section_empty_p (const struct dwarf2_section_info
*section
)
2513 if (section
->is_virtual
)
2514 return section
->size
== 0;
2515 return section
->s
.section
== NULL
|| section
->size
== 0;
2518 /* See dwarf2read.h. */
2521 dwarf2_read_section (struct objfile
*objfile
, dwarf2_section_info
*info
)
2525 gdb_byte
*buf
, *retbuf
;
2529 info
->buffer
= NULL
;
2530 info
->readin
= true;
2532 if (dwarf2_section_empty_p (info
))
2535 sectp
= get_section_bfd_section (info
);
2537 /* If this is a virtual section we need to read in the real one first. */
2538 if (info
->is_virtual
)
2540 struct dwarf2_section_info
*containing_section
=
2541 get_containing_section (info
);
2543 gdb_assert (sectp
!= NULL
);
2544 if ((sectp
->flags
& SEC_RELOC
) != 0)
2546 error (_("Dwarf Error: DWP format V2 with relocations is not"
2547 " supported in section %s [in module %s]"),
2548 get_section_name (info
), get_section_file_name (info
));
2550 dwarf2_read_section (objfile
, containing_section
);
2551 /* Other code should have already caught virtual sections that don't
2553 gdb_assert (info
->virtual_offset
+ info
->size
2554 <= containing_section
->size
);
2555 /* If the real section is empty or there was a problem reading the
2556 section we shouldn't get here. */
2557 gdb_assert (containing_section
->buffer
!= NULL
);
2558 info
->buffer
= containing_section
->buffer
+ info
->virtual_offset
;
2562 /* If the section has relocations, we must read it ourselves.
2563 Otherwise we attach it to the BFD. */
2564 if ((sectp
->flags
& SEC_RELOC
) == 0)
2566 info
->buffer
= gdb_bfd_map_section (sectp
, &info
->size
);
2570 buf
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
2573 /* When debugging .o files, we may need to apply relocations; see
2574 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
2575 We never compress sections in .o files, so we only need to
2576 try this when the section is not compressed. */
2577 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
2580 info
->buffer
= retbuf
;
2584 abfd
= get_section_bfd_owner (info
);
2585 gdb_assert (abfd
!= NULL
);
2587 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
2588 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
2590 error (_("Dwarf Error: Can't read DWARF data"
2591 " in section %s [in module %s]"),
2592 bfd_section_name (sectp
), bfd_get_filename (abfd
));
2596 /* A helper function that returns the size of a section in a safe way.
2597 If you are positive that the section has been read before using the
2598 size, then it is safe to refer to the dwarf2_section_info object's
2599 "size" field directly. In other cases, you must call this
2600 function, because for compressed sections the size field is not set
2601 correctly until the section has been read. */
2603 static bfd_size_type
2604 dwarf2_section_size (struct objfile
*objfile
,
2605 struct dwarf2_section_info
*info
)
2608 dwarf2_read_section (objfile
, info
);
2612 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2616 dwarf2_get_section_info (struct objfile
*objfile
,
2617 enum dwarf2_section_enum sect
,
2618 asection
**sectp
, const gdb_byte
**bufp
,
2619 bfd_size_type
*sizep
)
2621 struct dwarf2_per_objfile
*data
= dwarf2_objfile_data_key
.get (objfile
);
2622 struct dwarf2_section_info
*info
;
2624 /* We may see an objfile without any DWARF, in which case we just
2635 case DWARF2_DEBUG_FRAME
:
2636 info
= &data
->frame
;
2638 case DWARF2_EH_FRAME
:
2639 info
= &data
->eh_frame
;
2642 gdb_assert_not_reached ("unexpected section");
2645 dwarf2_read_section (objfile
, info
);
2647 *sectp
= get_section_bfd_section (info
);
2648 *bufp
= info
->buffer
;
2649 *sizep
= info
->size
;
2652 /* A helper function to find the sections for a .dwz file. */
2655 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2657 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2659 /* Note that we only support the standard ELF names, because .dwz
2660 is ELF-only (at the time of writing). */
2661 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2663 dwz_file
->abbrev
.s
.section
= sectp
;
2664 dwz_file
->abbrev
.size
= bfd_section_size (sectp
);
2666 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2668 dwz_file
->info
.s
.section
= sectp
;
2669 dwz_file
->info
.size
= bfd_section_size (sectp
);
2671 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2673 dwz_file
->str
.s
.section
= sectp
;
2674 dwz_file
->str
.size
= bfd_section_size (sectp
);
2676 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2678 dwz_file
->line
.s
.section
= sectp
;
2679 dwz_file
->line
.size
= bfd_section_size (sectp
);
2681 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2683 dwz_file
->macro
.s
.section
= sectp
;
2684 dwz_file
->macro
.size
= bfd_section_size (sectp
);
2686 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2688 dwz_file
->gdb_index
.s
.section
= sectp
;
2689 dwz_file
->gdb_index
.size
= bfd_section_size (sectp
);
2691 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2693 dwz_file
->debug_names
.s
.section
= sectp
;
2694 dwz_file
->debug_names
.size
= bfd_section_size (sectp
);
2698 /* See dwarf2read.h. */
2701 dwarf2_get_dwz_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
2703 const char *filename
;
2704 bfd_size_type buildid_len_arg
;
2708 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2709 return dwarf2_per_objfile
->dwz_file
.get ();
2711 bfd_set_error (bfd_error_no_error
);
2712 gdb::unique_xmalloc_ptr
<char> data
2713 (bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2714 &buildid_len_arg
, &buildid
));
2717 if (bfd_get_error () == bfd_error_no_error
)
2719 error (_("could not read '.gnu_debugaltlink' section: %s"),
2720 bfd_errmsg (bfd_get_error ()));
2723 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2725 buildid_len
= (size_t) buildid_len_arg
;
2727 filename
= data
.get ();
2729 std::string abs_storage
;
2730 if (!IS_ABSOLUTE_PATH (filename
))
2732 gdb::unique_xmalloc_ptr
<char> abs
2733 = gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2735 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2736 filename
= abs_storage
.c_str ();
2739 /* First try the file name given in the section. If that doesn't
2740 work, try to use the build-id instead. */
2741 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
, -1));
2742 if (dwz_bfd
!= NULL
)
2744 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2745 dwz_bfd
.reset (nullptr);
2748 if (dwz_bfd
== NULL
)
2749 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2751 if (dwz_bfd
== NULL
)
2752 error (_("could not find '.gnu_debugaltlink' file for %s"),
2753 objfile_name (dwarf2_per_objfile
->objfile
));
2755 std::unique_ptr
<struct dwz_file
> result
2756 (new struct dwz_file (std::move (dwz_bfd
)));
2758 bfd_map_over_sections (result
->dwz_bfd
.get (), locate_dwz_sections
,
2761 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
,
2762 result
->dwz_bfd
.get ());
2763 dwarf2_per_objfile
->dwz_file
= std::move (result
);
2764 return dwarf2_per_objfile
->dwz_file
.get ();
2767 /* DWARF quick_symbols_functions support. */
2769 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2770 unique line tables, so we maintain a separate table of all .debug_line
2771 derived entries to support the sharing.
2772 All the quick functions need is the list of file names. We discard the
2773 line_header when we're done and don't need to record it here. */
2774 struct quick_file_names
2776 /* The data used to construct the hash key. */
2777 struct stmt_list_hash hash
;
2779 /* The number of entries in file_names, real_names. */
2780 unsigned int num_file_names
;
2782 /* The file names from the line table, after being run through
2784 const char **file_names
;
2786 /* The file names from the line table after being run through
2787 gdb_realpath. These are computed lazily. */
2788 const char **real_names
;
2791 /* When using the index (and thus not using psymtabs), each CU has an
2792 object of this type. This is used to hold information needed by
2793 the various "quick" methods. */
2794 struct dwarf2_per_cu_quick_data
2796 /* The file table. This can be NULL if there was no file table
2797 or it's currently not read in.
2798 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2799 struct quick_file_names
*file_names
;
2801 /* The corresponding symbol table. This is NULL if symbols for this
2802 CU have not yet been read. */
2803 struct compunit_symtab
*compunit_symtab
;
2805 /* A temporary mark bit used when iterating over all CUs in
2806 expand_symtabs_matching. */
2807 unsigned int mark
: 1;
2809 /* True if we've tried to read the file table and found there isn't one.
2810 There will be no point in trying to read it again next time. */
2811 unsigned int no_file_data
: 1;
2814 /* Utility hash function for a stmt_list_hash. */
2817 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2821 if (stmt_list_hash
->dwo_unit
!= NULL
)
2822 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2823 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2827 /* Utility equality function for a stmt_list_hash. */
2830 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2831 const struct stmt_list_hash
*rhs
)
2833 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2835 if (lhs
->dwo_unit
!= NULL
2836 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2839 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2842 /* Hash function for a quick_file_names. */
2845 hash_file_name_entry (const void *e
)
2847 const struct quick_file_names
*file_data
2848 = (const struct quick_file_names
*) e
;
2850 return hash_stmt_list_entry (&file_data
->hash
);
2853 /* Equality function for a quick_file_names. */
2856 eq_file_name_entry (const void *a
, const void *b
)
2858 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2859 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2861 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2864 /* Delete function for a quick_file_names. */
2867 delete_file_name_entry (void *e
)
2869 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2872 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2874 xfree ((void*) file_data
->file_names
[i
]);
2875 if (file_data
->real_names
)
2876 xfree ((void*) file_data
->real_names
[i
]);
2879 /* The space for the struct itself lives on objfile_obstack,
2880 so we don't free it here. */
2883 /* Create a quick_file_names hash table. */
2886 create_quick_file_names_table (unsigned int nr_initial_entries
)
2888 return htab_create_alloc (nr_initial_entries
,
2889 hash_file_name_entry
, eq_file_name_entry
,
2890 delete_file_name_entry
, xcalloc
, xfree
);
2893 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2894 have to be created afterwards. You should call age_cached_comp_units after
2895 processing PER_CU->CU. dw2_setup must have been already called. */
2898 load_cu (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2900 if (per_cu
->is_debug_types
)
2901 load_full_type_unit (per_cu
);
2903 load_full_comp_unit (per_cu
, skip_partial
, language_minimal
);
2905 if (per_cu
->cu
== NULL
)
2906 return; /* Dummy CU. */
2908 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2911 /* Read in the symbols for PER_CU. */
2914 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2916 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2918 /* Skip type_unit_groups, reading the type units they contain
2919 is handled elsewhere. */
2920 if (IS_TYPE_UNIT_GROUP (per_cu
))
2923 /* The destructor of dwarf2_queue_guard frees any entries left on
2924 the queue. After this point we're guaranteed to leave this function
2925 with the dwarf queue empty. */
2926 dwarf2_queue_guard q_guard
;
2928 if (dwarf2_per_objfile
->using_index
2929 ? per_cu
->v
.quick
->compunit_symtab
== NULL
2930 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2932 queue_comp_unit (per_cu
, language_minimal
);
2933 load_cu (per_cu
, skip_partial
);
2935 /* If we just loaded a CU from a DWO, and we're working with an index
2936 that may badly handle TUs, load all the TUs in that DWO as well.
2937 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2938 if (!per_cu
->is_debug_types
2939 && per_cu
->cu
!= NULL
2940 && per_cu
->cu
->dwo_unit
!= NULL
2941 && dwarf2_per_objfile
->index_table
!= NULL
2942 && dwarf2_per_objfile
->index_table
->version
<= 7
2943 /* DWP files aren't supported yet. */
2944 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
2945 queue_and_load_all_dwo_tus (per_cu
);
2948 process_queue (dwarf2_per_objfile
);
2950 /* Age the cache, releasing compilation units that have not
2951 been used recently. */
2952 age_cached_comp_units (dwarf2_per_objfile
);
2955 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2956 the objfile from which this CU came. Returns the resulting symbol
2959 static struct compunit_symtab
*
2960 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2962 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2964 gdb_assert (dwarf2_per_objfile
->using_index
);
2965 if (!per_cu
->v
.quick
->compunit_symtab
)
2967 free_cached_comp_units
freer (dwarf2_per_objfile
);
2968 scoped_restore decrementer
= increment_reading_symtab ();
2969 dw2_do_instantiate_symtab (per_cu
, skip_partial
);
2970 process_cu_includes (dwarf2_per_objfile
);
2973 return per_cu
->v
.quick
->compunit_symtab
;
2976 /* See declaration. */
2978 dwarf2_per_cu_data
*
2979 dwarf2_per_objfile::get_cutu (int index
)
2981 if (index
>= this->all_comp_units
.size ())
2983 index
-= this->all_comp_units
.size ();
2984 gdb_assert (index
< this->all_type_units
.size ());
2985 return &this->all_type_units
[index
]->per_cu
;
2988 return this->all_comp_units
[index
];
2991 /* See declaration. */
2993 dwarf2_per_cu_data
*
2994 dwarf2_per_objfile::get_cu (int index
)
2996 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2998 return this->all_comp_units
[index
];
3001 /* See declaration. */
3004 dwarf2_per_objfile::get_tu (int index
)
3006 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
3008 return this->all_type_units
[index
];
3011 /* Return a new dwarf2_per_cu_data allocated on OBJFILE's
3012 objfile_obstack, and constructed with the specified field
3015 static dwarf2_per_cu_data
*
3016 create_cu_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3017 struct dwarf2_section_info
*section
,
3019 sect_offset sect_off
, ULONGEST length
)
3021 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3022 dwarf2_per_cu_data
*the_cu
3023 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3024 struct dwarf2_per_cu_data
);
3025 the_cu
->sect_off
= sect_off
;
3026 the_cu
->length
= length
;
3027 the_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3028 the_cu
->section
= section
;
3029 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3030 struct dwarf2_per_cu_quick_data
);
3031 the_cu
->is_dwz
= is_dwz
;
3035 /* A helper for create_cus_from_index that handles a given list of
3039 create_cus_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3040 const gdb_byte
*cu_list
, offset_type n_elements
,
3041 struct dwarf2_section_info
*section
,
3044 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
3046 gdb_static_assert (sizeof (ULONGEST
) >= 8);
3048 sect_offset sect_off
3049 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
3050 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
3053 dwarf2_per_cu_data
*per_cu
3054 = create_cu_from_index_list (dwarf2_per_objfile
, section
, is_dwz
,
3056 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
3060 /* Read the CU list from the mapped index, and use it to create all
3061 the CU objects for this objfile. */
3064 create_cus_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3065 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
3066 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
3068 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
3069 dwarf2_per_objfile
->all_comp_units
.reserve
3070 ((cu_list_elements
+ dwz_elements
) / 2);
3072 create_cus_from_index_list (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3073 &dwarf2_per_objfile
->info
, 0);
3075 if (dwz_elements
== 0)
3078 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3079 create_cus_from_index_list (dwarf2_per_objfile
, dwz_list
, dwz_elements
,
3083 /* Create the signatured type hash table from the index. */
3086 create_signatured_type_table_from_index
3087 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3088 struct dwarf2_section_info
*section
,
3089 const gdb_byte
*bytes
,
3090 offset_type elements
)
3092 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3094 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
3095 dwarf2_per_objfile
->all_type_units
.reserve (elements
/ 3);
3097 htab_t sig_types_hash
= allocate_signatured_type_table (objfile
);
3099 for (offset_type i
= 0; i
< elements
; i
+= 3)
3101 struct signatured_type
*sig_type
;
3104 cu_offset type_offset_in_tu
;
3106 gdb_static_assert (sizeof (ULONGEST
) >= 8);
3107 sect_offset sect_off
3108 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
3110 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
3112 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
3115 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3116 struct signatured_type
);
3117 sig_type
->signature
= signature
;
3118 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
3119 sig_type
->per_cu
.is_debug_types
= 1;
3120 sig_type
->per_cu
.section
= section
;
3121 sig_type
->per_cu
.sect_off
= sect_off
;
3122 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
3123 sig_type
->per_cu
.v
.quick
3124 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3125 struct dwarf2_per_cu_quick_data
);
3127 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3130 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
3133 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3136 /* Create the signatured type hash table from .debug_names. */
3139 create_signatured_type_table_from_debug_names
3140 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3141 const mapped_debug_names
&map
,
3142 struct dwarf2_section_info
*section
,
3143 struct dwarf2_section_info
*abbrev_section
)
3145 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3147 dwarf2_read_section (objfile
, section
);
3148 dwarf2_read_section (objfile
, abbrev_section
);
3150 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
3151 dwarf2_per_objfile
->all_type_units
.reserve (map
.tu_count
);
3153 htab_t sig_types_hash
= allocate_signatured_type_table (objfile
);
3155 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
3157 struct signatured_type
*sig_type
;
3160 sect_offset sect_off
3161 = (sect_offset
) (extract_unsigned_integer
3162 (map
.tu_table_reordered
+ i
* map
.offset_size
,
3164 map
.dwarf5_byte_order
));
3166 comp_unit_head cu_header
;
3167 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
3169 section
->buffer
+ to_underlying (sect_off
),
3172 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3173 struct signatured_type
);
3174 sig_type
->signature
= cu_header
.signature
;
3175 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
3176 sig_type
->per_cu
.is_debug_types
= 1;
3177 sig_type
->per_cu
.section
= section
;
3178 sig_type
->per_cu
.sect_off
= sect_off
;
3179 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
3180 sig_type
->per_cu
.v
.quick
3181 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3182 struct dwarf2_per_cu_quick_data
);
3184 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3187 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
3190 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3193 /* Read the address map data from the mapped index, and use it to
3194 populate the objfile's psymtabs_addrmap. */
3197 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3198 struct mapped_index
*index
)
3200 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3201 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3202 const gdb_byte
*iter
, *end
;
3203 struct addrmap
*mutable_map
;
3206 auto_obstack temp_obstack
;
3208 mutable_map
= addrmap_create_mutable (&temp_obstack
);
3210 iter
= index
->address_table
.data ();
3211 end
= iter
+ index
->address_table
.size ();
3213 baseaddr
= objfile
->text_section_offset ();
3217 ULONGEST hi
, lo
, cu_index
;
3218 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3220 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3222 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
3227 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
3228 hex_string (lo
), hex_string (hi
));
3232 if (cu_index
>= dwarf2_per_objfile
->all_comp_units
.size ())
3234 complaint (_(".gdb_index address table has invalid CU number %u"),
3235 (unsigned) cu_index
);
3239 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
3240 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
3241 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
3242 dwarf2_per_objfile
->get_cu (cu_index
));
3245 objfile
->partial_symtabs
->psymtabs_addrmap
3246 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
3249 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
3250 populate the objfile's psymtabs_addrmap. */
3253 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3254 struct dwarf2_section_info
*section
)
3256 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3257 bfd
*abfd
= objfile
->obfd
;
3258 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3259 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
3261 auto_obstack temp_obstack
;
3262 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
3264 std::unordered_map
<sect_offset
,
3265 dwarf2_per_cu_data
*,
3266 gdb::hash_enum
<sect_offset
>>
3267 debug_info_offset_to_per_cu
;
3268 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3270 const auto insertpair
3271 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
3272 if (!insertpair
.second
)
3274 warning (_("Section .debug_aranges in %s has duplicate "
3275 "debug_info_offset %s, ignoring .debug_aranges."),
3276 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
3281 dwarf2_read_section (objfile
, section
);
3283 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
3285 const gdb_byte
*addr
= section
->buffer
;
3287 while (addr
< section
->buffer
+ section
->size
)
3289 const gdb_byte
*const entry_addr
= addr
;
3290 unsigned int bytes_read
;
3292 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
3296 const gdb_byte
*const entry_end
= addr
+ entry_length
;
3297 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
3298 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
3299 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
3301 warning (_("Section .debug_aranges in %s entry at offset %s "
3302 "length %s exceeds section length %s, "
3303 "ignoring .debug_aranges."),
3304 objfile_name (objfile
),
3305 plongest (entry_addr
- section
->buffer
),
3306 plongest (bytes_read
+ entry_length
),
3307 pulongest (section
->size
));
3311 /* The version number. */
3312 const uint16_t version
= read_2_bytes (abfd
, addr
);
3316 warning (_("Section .debug_aranges in %s entry at offset %s "
3317 "has unsupported version %d, ignoring .debug_aranges."),
3318 objfile_name (objfile
),
3319 plongest (entry_addr
- section
->buffer
), version
);
3323 const uint64_t debug_info_offset
3324 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
3325 addr
+= offset_size
;
3326 const auto per_cu_it
3327 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
3328 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
3330 warning (_("Section .debug_aranges in %s entry at offset %s "
3331 "debug_info_offset %s does not exists, "
3332 "ignoring .debug_aranges."),
3333 objfile_name (objfile
),
3334 plongest (entry_addr
- section
->buffer
),
3335 pulongest (debug_info_offset
));
3338 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
3340 const uint8_t address_size
= *addr
++;
3341 if (address_size
< 1 || address_size
> 8)
3343 warning (_("Section .debug_aranges in %s entry at offset %s "
3344 "address_size %u is invalid, ignoring .debug_aranges."),
3345 objfile_name (objfile
),
3346 plongest (entry_addr
- section
->buffer
), address_size
);
3350 const uint8_t segment_selector_size
= *addr
++;
3351 if (segment_selector_size
!= 0)
3353 warning (_("Section .debug_aranges in %s entry at offset %s "
3354 "segment_selector_size %u is not supported, "
3355 "ignoring .debug_aranges."),
3356 objfile_name (objfile
),
3357 plongest (entry_addr
- section
->buffer
),
3358 segment_selector_size
);
3362 /* Must pad to an alignment boundary that is twice the address
3363 size. It is undocumented by the DWARF standard but GCC does
3365 for (size_t padding
= ((-(addr
- section
->buffer
))
3366 & (2 * address_size
- 1));
3367 padding
> 0; padding
--)
3370 warning (_("Section .debug_aranges in %s entry at offset %s "
3371 "padding is not zero, ignoring .debug_aranges."),
3372 objfile_name (objfile
),
3373 plongest (entry_addr
- section
->buffer
));
3379 if (addr
+ 2 * address_size
> entry_end
)
3381 warning (_("Section .debug_aranges in %s entry at offset %s "
3382 "address list is not properly terminated, "
3383 "ignoring .debug_aranges."),
3384 objfile_name (objfile
),
3385 plongest (entry_addr
- section
->buffer
));
3388 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
3390 addr
+= address_size
;
3391 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
3393 addr
+= address_size
;
3394 if (start
== 0 && length
== 0)
3396 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
3398 /* Symbol was eliminated due to a COMDAT group. */
3401 ULONGEST end
= start
+ length
;
3402 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
3404 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
3406 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
3410 objfile
->partial_symtabs
->psymtabs_addrmap
3411 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
3414 /* Find a slot in the mapped index INDEX for the object named NAME.
3415 If NAME is found, set *VEC_OUT to point to the CU vector in the
3416 constant pool and return true. If NAME cannot be found, return
3420 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
3421 offset_type
**vec_out
)
3424 offset_type slot
, step
;
3425 int (*cmp
) (const char *, const char *);
3427 gdb::unique_xmalloc_ptr
<char> without_params
;
3428 if (current_language
->la_language
== language_cplus
3429 || current_language
->la_language
== language_fortran
3430 || current_language
->la_language
== language_d
)
3432 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
3435 if (strchr (name
, '(') != NULL
)
3437 without_params
= cp_remove_params (name
);
3439 if (without_params
!= NULL
)
3440 name
= without_params
.get ();
3444 /* Index version 4 did not support case insensitive searches. But the
3445 indices for case insensitive languages are built in lowercase, therefore
3446 simulate our NAME being searched is also lowercased. */
3447 hash
= mapped_index_string_hash ((index
->version
== 4
3448 && case_sensitivity
== case_sensitive_off
3449 ? 5 : index
->version
),
3452 slot
= hash
& (index
->symbol_table
.size () - 1);
3453 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
3454 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
3460 const auto &bucket
= index
->symbol_table
[slot
];
3461 if (bucket
.name
== 0 && bucket
.vec
== 0)
3464 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
3465 if (!cmp (name
, str
))
3467 *vec_out
= (offset_type
*) (index
->constant_pool
3468 + MAYBE_SWAP (bucket
.vec
));
3472 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
3476 /* A helper function that reads the .gdb_index from BUFFER and fills
3477 in MAP. FILENAME is the name of the file containing the data;
3478 it is used for error reporting. DEPRECATED_OK is true if it is
3479 ok to use deprecated sections.
3481 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
3482 out parameters that are filled in with information about the CU and
3483 TU lists in the section.
3485 Returns true if all went well, false otherwise. */
3488 read_gdb_index_from_buffer (struct objfile
*objfile
,
3489 const char *filename
,
3491 gdb::array_view
<const gdb_byte
> buffer
,
3492 struct mapped_index
*map
,
3493 const gdb_byte
**cu_list
,
3494 offset_type
*cu_list_elements
,
3495 const gdb_byte
**types_list
,
3496 offset_type
*types_list_elements
)
3498 const gdb_byte
*addr
= &buffer
[0];
3500 /* Version check. */
3501 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
3502 /* Versions earlier than 3 emitted every copy of a psymbol. This
3503 causes the index to behave very poorly for certain requests. Version 3
3504 contained incomplete addrmap. So, it seems better to just ignore such
3508 static int warning_printed
= 0;
3509 if (!warning_printed
)
3511 warning (_("Skipping obsolete .gdb_index section in %s."),
3513 warning_printed
= 1;
3517 /* Index version 4 uses a different hash function than index version
3520 Versions earlier than 6 did not emit psymbols for inlined
3521 functions. Using these files will cause GDB not to be able to
3522 set breakpoints on inlined functions by name, so we ignore these
3523 indices unless the user has done
3524 "set use-deprecated-index-sections on". */
3525 if (version
< 6 && !deprecated_ok
)
3527 static int warning_printed
= 0;
3528 if (!warning_printed
)
3531 Skipping deprecated .gdb_index section in %s.\n\
3532 Do \"set use-deprecated-index-sections on\" before the file is read\n\
3533 to use the section anyway."),
3535 warning_printed
= 1;
3539 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3540 of the TU (for symbols coming from TUs),
3541 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3542 Plus gold-generated indices can have duplicate entries for global symbols,
3543 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3544 These are just performance bugs, and we can't distinguish gdb-generated
3545 indices from gold-generated ones, so issue no warning here. */
3547 /* Indexes with higher version than the one supported by GDB may be no
3548 longer backward compatible. */
3552 map
->version
= version
;
3554 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3557 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3558 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3562 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3563 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3564 - MAYBE_SWAP (metadata
[i
]))
3568 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3569 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3571 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
3574 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3575 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3577 = gdb::array_view
<mapped_index::symbol_table_slot
>
3578 ((mapped_index::symbol_table_slot
*) symbol_table
,
3579 (mapped_index::symbol_table_slot
*) symbol_table_end
);
3582 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3587 /* Callback types for dwarf2_read_gdb_index. */
3589 typedef gdb::function_view
3590 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_objfile
*)>
3591 get_gdb_index_contents_ftype
;
3592 typedef gdb::function_view
3593 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
3594 get_gdb_index_contents_dwz_ftype
;
3596 /* Read .gdb_index. If everything went ok, initialize the "quick"
3597 elements of all the CUs and return 1. Otherwise, return 0. */
3600 dwarf2_read_gdb_index
3601 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3602 get_gdb_index_contents_ftype get_gdb_index_contents
,
3603 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
3605 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3606 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3607 struct dwz_file
*dwz
;
3608 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3610 gdb::array_view
<const gdb_byte
> main_index_contents
3611 = get_gdb_index_contents (objfile
, dwarf2_per_objfile
);
3613 if (main_index_contents
.empty ())
3616 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3617 if (!read_gdb_index_from_buffer (objfile
, objfile_name (objfile
),
3618 use_deprecated_index_sections
,
3619 main_index_contents
, map
.get (), &cu_list
,
3620 &cu_list_elements
, &types_list
,
3621 &types_list_elements
))
3624 /* Don't use the index if it's empty. */
3625 if (map
->symbol_table
.empty ())
3628 /* If there is a .dwz file, read it so we can get its CU list as
3630 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3633 struct mapped_index dwz_map
;
3634 const gdb_byte
*dwz_types_ignore
;
3635 offset_type dwz_types_elements_ignore
;
3637 gdb::array_view
<const gdb_byte
> dwz_index_content
3638 = get_gdb_index_contents_dwz (objfile
, dwz
);
3640 if (dwz_index_content
.empty ())
3643 if (!read_gdb_index_from_buffer (objfile
,
3644 bfd_get_filename (dwz
->dwz_bfd
.get ()),
3645 1, dwz_index_content
, &dwz_map
,
3646 &dwz_list
, &dwz_list_elements
,
3648 &dwz_types_elements_ignore
))
3650 warning (_("could not read '.gdb_index' section from %s; skipping"),
3651 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3656 create_cus_from_index (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3657 dwz_list
, dwz_list_elements
);
3659 if (types_list_elements
)
3661 /* We can only handle a single .debug_types when we have an
3663 if (dwarf2_per_objfile
->types
.size () != 1)
3666 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
3668 create_signatured_type_table_from_index (dwarf2_per_objfile
, section
,
3669 types_list
, types_list_elements
);
3672 create_addrmap_from_index (dwarf2_per_objfile
, map
.get ());
3674 dwarf2_per_objfile
->index_table
= std::move (map
);
3675 dwarf2_per_objfile
->using_index
= 1;
3676 dwarf2_per_objfile
->quick_file_names_table
=
3677 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
3682 /* die_reader_func for dw2_get_file_names. */
3685 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3686 const gdb_byte
*info_ptr
,
3687 struct die_info
*comp_unit_die
,
3690 struct dwarf2_cu
*cu
= reader
->cu
;
3691 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3692 struct dwarf2_per_objfile
*dwarf2_per_objfile
3693 = cu
->per_cu
->dwarf2_per_objfile
;
3694 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3695 struct dwarf2_per_cu_data
*lh_cu
;
3696 struct attribute
*attr
;
3698 struct quick_file_names
*qfn
;
3700 gdb_assert (! this_cu
->is_debug_types
);
3702 /* Our callers never want to match partial units -- instead they
3703 will match the enclosing full CU. */
3704 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3706 this_cu
->v
.quick
->no_file_data
= 1;
3714 sect_offset line_offset
{};
3716 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3717 if (attr
!= nullptr)
3719 struct quick_file_names find_entry
;
3721 line_offset
= (sect_offset
) DW_UNSND (attr
);
3723 /* We may have already read in this line header (TU line header sharing).
3724 If we have we're done. */
3725 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3726 find_entry
.hash
.line_sect_off
= line_offset
;
3727 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
3728 &find_entry
, INSERT
);
3731 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3735 lh
= dwarf_decode_line_header (line_offset
, cu
);
3739 lh_cu
->v
.quick
->no_file_data
= 1;
3743 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
3744 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3745 qfn
->hash
.line_sect_off
= line_offset
;
3746 gdb_assert (slot
!= NULL
);
3749 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3752 if (strcmp (fnd
.name
, "<unknown>") != 0)
3755 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3757 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, qfn
->num_file_names
);
3759 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3760 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3761 qfn
->file_names
[i
+ offset
] = file_full_name (i
+ 1, lh
.get (), fnd
.comp_dir
);
3762 qfn
->real_names
= NULL
;
3764 lh_cu
->v
.quick
->file_names
= qfn
;
3767 /* A helper for the "quick" functions which attempts to read the line
3768 table for THIS_CU. */
3770 static struct quick_file_names
*
3771 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3773 /* This should never be called for TUs. */
3774 gdb_assert (! this_cu
->is_debug_types
);
3775 /* Nor type unit groups. */
3776 gdb_assert (! IS_TYPE_UNIT_GROUP (this_cu
));
3778 if (this_cu
->v
.quick
->file_names
!= NULL
)
3779 return this_cu
->v
.quick
->file_names
;
3780 /* If we know there is no line data, no point in looking again. */
3781 if (this_cu
->v
.quick
->no_file_data
)
3784 cutu_reader
reader (this_cu
);
3785 if (!reader
.dummy_p
)
3786 dw2_get_file_names_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
3787 reader
.has_children
);
3789 if (this_cu
->v
.quick
->no_file_data
)
3791 return this_cu
->v
.quick
->file_names
;
3794 /* A helper for the "quick" functions which computes and caches the
3795 real path for a given file name from the line table. */
3798 dw2_get_real_path (struct objfile
*objfile
,
3799 struct quick_file_names
*qfn
, int index
)
3801 if (qfn
->real_names
== NULL
)
3802 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3803 qfn
->num_file_names
, const char *);
3805 if (qfn
->real_names
[index
] == NULL
)
3806 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3808 return qfn
->real_names
[index
];
3811 static struct symtab
*
3812 dw2_find_last_source_symtab (struct objfile
*objfile
)
3814 struct dwarf2_per_objfile
*dwarf2_per_objfile
3815 = get_dwarf2_per_objfile (objfile
);
3816 dwarf2_per_cu_data
*dwarf_cu
= dwarf2_per_objfile
->all_comp_units
.back ();
3817 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, false);
3822 return compunit_primary_filetab (cust
);
3825 /* Traversal function for dw2_forget_cached_source_info. */
3828 dw2_free_cached_file_names (void **slot
, void *info
)
3830 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3832 if (file_data
->real_names
)
3836 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3838 xfree ((void*) file_data
->real_names
[i
]);
3839 file_data
->real_names
[i
] = NULL
;
3847 dw2_forget_cached_source_info (struct objfile
*objfile
)
3849 struct dwarf2_per_objfile
*dwarf2_per_objfile
3850 = get_dwarf2_per_objfile (objfile
);
3852 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
3853 dw2_free_cached_file_names
, NULL
);
3856 /* Helper function for dw2_map_symtabs_matching_filename that expands
3857 the symtabs and calls the iterator. */
3860 dw2_map_expand_apply (struct objfile
*objfile
,
3861 struct dwarf2_per_cu_data
*per_cu
,
3862 const char *name
, const char *real_path
,
3863 gdb::function_view
<bool (symtab
*)> callback
)
3865 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3867 /* Don't visit already-expanded CUs. */
3868 if (per_cu
->v
.quick
->compunit_symtab
)
3871 /* This may expand more than one symtab, and we want to iterate over
3873 dw2_instantiate_symtab (per_cu
, false);
3875 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3876 last_made
, callback
);
3879 /* Implementation of the map_symtabs_matching_filename method. */
3882 dw2_map_symtabs_matching_filename
3883 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3884 gdb::function_view
<bool (symtab
*)> callback
)
3886 const char *name_basename
= lbasename (name
);
3887 struct dwarf2_per_objfile
*dwarf2_per_objfile
3888 = get_dwarf2_per_objfile (objfile
);
3890 /* The rule is CUs specify all the files, including those used by
3891 any TU, so there's no need to scan TUs here. */
3893 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3895 /* We only need to look at symtabs not already expanded. */
3896 if (per_cu
->v
.quick
->compunit_symtab
)
3899 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3900 if (file_data
== NULL
)
3903 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3905 const char *this_name
= file_data
->file_names
[j
];
3906 const char *this_real_name
;
3908 if (compare_filenames_for_search (this_name
, name
))
3910 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3916 /* Before we invoke realpath, which can get expensive when many
3917 files are involved, do a quick comparison of the basenames. */
3918 if (! basenames_may_differ
3919 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3922 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3923 if (compare_filenames_for_search (this_real_name
, name
))
3925 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3931 if (real_path
!= NULL
)
3933 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3934 gdb_assert (IS_ABSOLUTE_PATH (name
));
3935 if (this_real_name
!= NULL
3936 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3938 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3950 /* Struct used to manage iterating over all CUs looking for a symbol. */
3952 struct dw2_symtab_iterator
3954 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3955 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
3956 /* If set, only look for symbols that match that block. Valid values are
3957 GLOBAL_BLOCK and STATIC_BLOCK. */
3958 gdb::optional
<block_enum
> block_index
;
3959 /* The kind of symbol we're looking for. */
3961 /* The list of CUs from the index entry of the symbol,
3962 or NULL if not found. */
3964 /* The next element in VEC to look at. */
3966 /* The number of elements in VEC, or zero if there is no match. */
3968 /* Have we seen a global version of the symbol?
3969 If so we can ignore all further global instances.
3970 This is to work around gold/15646, inefficient gold-generated
3975 /* Initialize the index symtab iterator ITER. */
3978 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3979 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3980 gdb::optional
<block_enum
> block_index
,
3984 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3985 iter
->block_index
= block_index
;
3986 iter
->domain
= domain
;
3988 iter
->global_seen
= 0;
3990 mapped_index
*index
= dwarf2_per_objfile
->index_table
.get ();
3992 /* index is NULL if OBJF_READNOW. */
3993 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3994 iter
->length
= MAYBE_SWAP (*iter
->vec
);
4002 /* Return the next matching CU or NULL if there are no more. */
4004 static struct dwarf2_per_cu_data
*
4005 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
4007 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
4009 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
4011 offset_type cu_index_and_attrs
=
4012 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
4013 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4014 gdb_index_symbol_kind symbol_kind
=
4015 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4016 /* Only check the symbol attributes if they're present.
4017 Indices prior to version 7 don't record them,
4018 and indices >= 7 may elide them for certain symbols
4019 (gold does this). */
4021 (dwarf2_per_objfile
->index_table
->version
>= 7
4022 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4024 /* Don't crash on bad data. */
4025 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
4026 + dwarf2_per_objfile
->all_type_units
.size ()))
4028 complaint (_(".gdb_index entry has bad CU index"
4030 objfile_name (dwarf2_per_objfile
->objfile
));
4034 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
4036 /* Skip if already read in. */
4037 if (per_cu
->v
.quick
->compunit_symtab
)
4040 /* Check static vs global. */
4043 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4045 if (iter
->block_index
.has_value ())
4047 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
4049 if (is_static
!= want_static
)
4053 /* Work around gold/15646. */
4054 if (!is_static
&& iter
->global_seen
)
4057 iter
->global_seen
= 1;
4060 /* Only check the symbol's kind if it has one. */
4063 switch (iter
->domain
)
4066 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
4067 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
4068 /* Some types are also in VAR_DOMAIN. */
4069 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4073 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4077 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4081 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4096 static struct compunit_symtab
*
4097 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
4098 const char *name
, domain_enum domain
)
4100 struct compunit_symtab
*stab_best
= NULL
;
4101 struct dwarf2_per_objfile
*dwarf2_per_objfile
4102 = get_dwarf2_per_objfile (objfile
);
4104 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
4106 struct dw2_symtab_iterator iter
;
4107 struct dwarf2_per_cu_data
*per_cu
;
4109 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, block_index
, domain
, name
);
4111 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4113 struct symbol
*sym
, *with_opaque
= NULL
;
4114 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
4115 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
4116 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
4118 sym
= block_find_symbol (block
, name
, domain
,
4119 block_find_non_opaque_type_preferred
,
4122 /* Some caution must be observed with overloaded functions
4123 and methods, since the index will not contain any overload
4124 information (but NAME might contain it). */
4127 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
4129 if (with_opaque
!= NULL
4130 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
4133 /* Keep looking through other CUs. */
4140 dw2_print_stats (struct objfile
*objfile
)
4142 struct dwarf2_per_objfile
*dwarf2_per_objfile
4143 = get_dwarf2_per_objfile (objfile
);
4144 int total
= (dwarf2_per_objfile
->all_comp_units
.size ()
4145 + dwarf2_per_objfile
->all_type_units
.size ());
4148 for (int i
= 0; i
< total
; ++i
)
4150 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
4152 if (!per_cu
->v
.quick
->compunit_symtab
)
4155 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
4156 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
4159 /* This dumps minimal information about the index.
4160 It is called via "mt print objfiles".
4161 One use is to verify .gdb_index has been loaded by the
4162 gdb.dwarf2/gdb-index.exp testcase. */
4165 dw2_dump (struct objfile
*objfile
)
4167 struct dwarf2_per_objfile
*dwarf2_per_objfile
4168 = get_dwarf2_per_objfile (objfile
);
4170 gdb_assert (dwarf2_per_objfile
->using_index
);
4171 printf_filtered (".gdb_index:");
4172 if (dwarf2_per_objfile
->index_table
!= NULL
)
4174 printf_filtered (" version %d\n",
4175 dwarf2_per_objfile
->index_table
->version
);
4178 printf_filtered (" faked for \"readnow\"\n");
4179 printf_filtered ("\n");
4183 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
4184 const char *func_name
)
4186 struct dwarf2_per_objfile
*dwarf2_per_objfile
4187 = get_dwarf2_per_objfile (objfile
);
4189 struct dw2_symtab_iterator iter
;
4190 struct dwarf2_per_cu_data
*per_cu
;
4192 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, {}, VAR_DOMAIN
, func_name
);
4194 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4195 dw2_instantiate_symtab (per_cu
, false);
4200 dw2_expand_all_symtabs (struct objfile
*objfile
)
4202 struct dwarf2_per_objfile
*dwarf2_per_objfile
4203 = get_dwarf2_per_objfile (objfile
);
4204 int total_units
= (dwarf2_per_objfile
->all_comp_units
.size ()
4205 + dwarf2_per_objfile
->all_type_units
.size ());
4207 for (int i
= 0; i
< total_units
; ++i
)
4209 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
4211 /* We don't want to directly expand a partial CU, because if we
4212 read it with the wrong language, then assertion failures can
4213 be triggered later on. See PR symtab/23010. So, tell
4214 dw2_instantiate_symtab to skip partial CUs -- any important
4215 partial CU will be read via DW_TAG_imported_unit anyway. */
4216 dw2_instantiate_symtab (per_cu
, true);
4221 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
4222 const char *fullname
)
4224 struct dwarf2_per_objfile
*dwarf2_per_objfile
4225 = get_dwarf2_per_objfile (objfile
);
4227 /* We don't need to consider type units here.
4228 This is only called for examining code, e.g. expand_line_sal.
4229 There can be an order of magnitude (or more) more type units
4230 than comp units, and we avoid them if we can. */
4232 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4234 /* We only need to look at symtabs not already expanded. */
4235 if (per_cu
->v
.quick
->compunit_symtab
)
4238 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4239 if (file_data
== NULL
)
4242 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4244 const char *this_fullname
= file_data
->file_names
[j
];
4246 if (filename_cmp (this_fullname
, fullname
) == 0)
4248 dw2_instantiate_symtab (per_cu
, false);
4256 dw2_map_matching_symbols
4257 (struct objfile
*objfile
,
4258 const lookup_name_info
&name
, domain_enum domain
,
4260 gdb::function_view
<symbol_found_callback_ftype
> callback
,
4261 symbol_compare_ftype
*ordered_compare
)
4263 /* Currently unimplemented; used for Ada. The function can be called if the
4264 current language is Ada for a non-Ada objfile using GNU index. As Ada
4265 does not look for non-Ada symbols this function should just return. */
4268 /* Starting from a search name, return the string that finds the upper
4269 bound of all strings that start with SEARCH_NAME in a sorted name
4270 list. Returns the empty string to indicate that the upper bound is
4271 the end of the list. */
4274 make_sort_after_prefix_name (const char *search_name
)
4276 /* When looking to complete "func", we find the upper bound of all
4277 symbols that start with "func" by looking for where we'd insert
4278 the closest string that would follow "func" in lexicographical
4279 order. Usually, that's "func"-with-last-character-incremented,
4280 i.e. "fund". Mind non-ASCII characters, though. Usually those
4281 will be UTF-8 multi-byte sequences, but we can't be certain.
4282 Especially mind the 0xff character, which is a valid character in
4283 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
4284 rule out compilers allowing it in identifiers. Note that
4285 conveniently, strcmp/strcasecmp are specified to compare
4286 characters interpreted as unsigned char. So what we do is treat
4287 the whole string as a base 256 number composed of a sequence of
4288 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
4289 to 0, and carries 1 to the following more-significant position.
4290 If the very first character in SEARCH_NAME ends up incremented
4291 and carries/overflows, then the upper bound is the end of the
4292 list. The string after the empty string is also the empty
4295 Some examples of this operation:
4297 SEARCH_NAME => "+1" RESULT
4301 "\xff" "a" "\xff" => "\xff" "b"
4306 Then, with these symbols for example:
4312 completing "func" looks for symbols between "func" and
4313 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
4314 which finds "func" and "func1", but not "fund".
4318 funcÿ (Latin1 'ÿ' [0xff])
4322 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
4323 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
4327 ÿÿ (Latin1 'ÿ' [0xff])
4330 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
4331 the end of the list.
4333 std::string after
= search_name
;
4334 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
4336 if (!after
.empty ())
4337 after
.back () = (unsigned char) after
.back () + 1;
4341 /* See declaration. */
4343 std::pair
<std::vector
<name_component
>::const_iterator
,
4344 std::vector
<name_component
>::const_iterator
>
4345 mapped_index_base::find_name_components_bounds
4346 (const lookup_name_info
&lookup_name_without_params
, language lang
) const
4349 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4351 const char *lang_name
4352 = lookup_name_without_params
.language_lookup_name (lang
).c_str ();
4354 /* Comparison function object for lower_bound that matches against a
4355 given symbol name. */
4356 auto lookup_compare_lower
= [&] (const name_component
&elem
,
4359 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4360 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4361 return name_cmp (elem_name
, name
) < 0;
4364 /* Comparison function object for upper_bound that matches against a
4365 given symbol name. */
4366 auto lookup_compare_upper
= [&] (const char *name
,
4367 const name_component
&elem
)
4369 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4370 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4371 return name_cmp (name
, elem_name
) < 0;
4374 auto begin
= this->name_components
.begin ();
4375 auto end
= this->name_components
.end ();
4377 /* Find the lower bound. */
4380 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
4383 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
4386 /* Find the upper bound. */
4389 if (lookup_name_without_params
.completion_mode ())
4391 /* In completion mode, we want UPPER to point past all
4392 symbols names that have the same prefix. I.e., with
4393 these symbols, and completing "func":
4395 function << lower bound
4397 other_function << upper bound
4399 We find the upper bound by looking for the insertion
4400 point of "func"-with-last-character-incremented,
4402 std::string after
= make_sort_after_prefix_name (lang_name
);
4405 return std::lower_bound (lower
, end
, after
.c_str (),
4406 lookup_compare_lower
);
4409 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
4412 return {lower
, upper
};
4415 /* See declaration. */
4418 mapped_index_base::build_name_components ()
4420 if (!this->name_components
.empty ())
4423 this->name_components_casing
= case_sensitivity
;
4425 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4427 /* The code below only knows how to break apart components of C++
4428 symbol names (and other languages that use '::' as
4429 namespace/module separator) and Ada symbol names. */
4430 auto count
= this->symbol_name_count ();
4431 for (offset_type idx
= 0; idx
< count
; idx
++)
4433 if (this->symbol_name_slot_invalid (idx
))
4436 const char *name
= this->symbol_name_at (idx
);
4438 /* Add each name component to the name component table. */
4439 unsigned int previous_len
= 0;
4441 if (strstr (name
, "::") != nullptr)
4443 for (unsigned int current_len
= cp_find_first_component (name
);
4444 name
[current_len
] != '\0';
4445 current_len
+= cp_find_first_component (name
+ current_len
))
4447 gdb_assert (name
[current_len
] == ':');
4448 this->name_components
.push_back ({previous_len
, idx
});
4449 /* Skip the '::'. */
4451 previous_len
= current_len
;
4456 /* Handle the Ada encoded (aka mangled) form here. */
4457 for (const char *iter
= strstr (name
, "__");
4459 iter
= strstr (iter
, "__"))
4461 this->name_components
.push_back ({previous_len
, idx
});
4463 previous_len
= iter
- name
;
4467 this->name_components
.push_back ({previous_len
, idx
});
4470 /* Sort name_components elements by name. */
4471 auto name_comp_compare
= [&] (const name_component
&left
,
4472 const name_component
&right
)
4474 const char *left_qualified
= this->symbol_name_at (left
.idx
);
4475 const char *right_qualified
= this->symbol_name_at (right
.idx
);
4477 const char *left_name
= left_qualified
+ left
.name_offset
;
4478 const char *right_name
= right_qualified
+ right
.name_offset
;
4480 return name_cmp (left_name
, right_name
) < 0;
4483 std::sort (this->name_components
.begin (),
4484 this->name_components
.end (),
4488 /* Helper for dw2_expand_symtabs_matching that works with a
4489 mapped_index_base instead of the containing objfile. This is split
4490 to a separate function in order to be able to unit test the
4491 name_components matching using a mock mapped_index_base. For each
4492 symbol name that matches, calls MATCH_CALLBACK, passing it the
4493 symbol's index in the mapped_index_base symbol table. */
4496 dw2_expand_symtabs_matching_symbol
4497 (mapped_index_base
&index
,
4498 const lookup_name_info
&lookup_name_in
,
4499 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4500 enum search_domain kind
,
4501 gdb::function_view
<bool (offset_type
)> match_callback
)
4503 lookup_name_info lookup_name_without_params
4504 = lookup_name_in
.make_ignore_params ();
4506 /* Build the symbol name component sorted vector, if we haven't
4508 index
.build_name_components ();
4510 /* The same symbol may appear more than once in the range though.
4511 E.g., if we're looking for symbols that complete "w", and we have
4512 a symbol named "w1::w2", we'll find the two name components for
4513 that same symbol in the range. To be sure we only call the
4514 callback once per symbol, we first collect the symbol name
4515 indexes that matched in a temporary vector and ignore
4517 std::vector
<offset_type
> matches
;
4519 struct name_and_matcher
4521 symbol_name_matcher_ftype
*matcher
;
4522 const std::string
&name
;
4524 bool operator== (const name_and_matcher
&other
) const
4526 return matcher
== other
.matcher
&& name
== other
.name
;
4530 /* A vector holding all the different symbol name matchers, for all
4532 std::vector
<name_and_matcher
> matchers
;
4534 for (int i
= 0; i
< nr_languages
; i
++)
4536 enum language lang_e
= (enum language
) i
;
4538 const language_defn
*lang
= language_def (lang_e
);
4539 symbol_name_matcher_ftype
*name_matcher
4540 = get_symbol_name_matcher (lang
, lookup_name_without_params
);
4542 name_and_matcher key
{
4544 lookup_name_without_params
.language_lookup_name (lang_e
)
4547 /* Don't insert the same comparison routine more than once.
4548 Note that we do this linear walk. This is not a problem in
4549 practice because the number of supported languages is
4551 if (std::find (matchers
.begin (), matchers
.end (), key
)
4554 matchers
.push_back (std::move (key
));
4557 = index
.find_name_components_bounds (lookup_name_without_params
,
4560 /* Now for each symbol name in range, check to see if we have a name
4561 match, and if so, call the MATCH_CALLBACK callback. */
4563 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
4565 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
4567 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
4568 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4571 matches
.push_back (bounds
.first
->idx
);
4575 std::sort (matches
.begin (), matches
.end ());
4577 /* Finally call the callback, once per match. */
4579 for (offset_type idx
: matches
)
4583 if (!match_callback (idx
))
4589 /* Above we use a type wider than idx's for 'prev', since 0 and
4590 (offset_type)-1 are both possible values. */
4591 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4596 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4598 /* A mock .gdb_index/.debug_names-like name index table, enough to
4599 exercise dw2_expand_symtabs_matching_symbol, which works with the
4600 mapped_index_base interface. Builds an index from the symbol list
4601 passed as parameter to the constructor. */
4602 class mock_mapped_index
: public mapped_index_base
4605 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4606 : m_symbol_table (symbols
)
4609 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4611 /* Return the number of names in the symbol table. */
4612 size_t symbol_name_count () const override
4614 return m_symbol_table
.size ();
4617 /* Get the name of the symbol at IDX in the symbol table. */
4618 const char *symbol_name_at (offset_type idx
) const override
4620 return m_symbol_table
[idx
];
4624 gdb::array_view
<const char *> m_symbol_table
;
4627 /* Convenience function that converts a NULL pointer to a "<null>"
4628 string, to pass to print routines. */
4631 string_or_null (const char *str
)
4633 return str
!= NULL
? str
: "<null>";
4636 /* Check if a lookup_name_info built from
4637 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4638 index. EXPECTED_LIST is the list of expected matches, in expected
4639 matching order. If no match expected, then an empty list is
4640 specified. Returns true on success. On failure prints a warning
4641 indicating the file:line that failed, and returns false. */
4644 check_match (const char *file
, int line
,
4645 mock_mapped_index
&mock_index
,
4646 const char *name
, symbol_name_match_type match_type
,
4647 bool completion_mode
,
4648 std::initializer_list
<const char *> expected_list
)
4650 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4652 bool matched
= true;
4654 auto mismatch
= [&] (const char *expected_str
,
4657 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4658 "expected=\"%s\", got=\"%s\"\n"),
4660 (match_type
== symbol_name_match_type::FULL
4662 name
, string_or_null (expected_str
), string_or_null (got
));
4666 auto expected_it
= expected_list
.begin ();
4667 auto expected_end
= expected_list
.end ();
4669 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4671 [&] (offset_type idx
)
4673 const char *matched_name
= mock_index
.symbol_name_at (idx
);
4674 const char *expected_str
4675 = expected_it
== expected_end
? NULL
: *expected_it
++;
4677 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4678 mismatch (expected_str
, matched_name
);
4682 const char *expected_str
4683 = expected_it
== expected_end
? NULL
: *expected_it
++;
4684 if (expected_str
!= NULL
)
4685 mismatch (expected_str
, NULL
);
4690 /* The symbols added to the mock mapped_index for testing (in
4692 static const char *test_symbols
[] = {
4701 "ns2::tmpl<int>::foo2",
4702 "(anonymous namespace)::A::B::C",
4704 /* These are used to check that the increment-last-char in the
4705 matching algorithm for completion doesn't match "t1_fund" when
4706 completing "t1_func". */
4712 /* A UTF-8 name with multi-byte sequences to make sure that
4713 cp-name-parser understands this as a single identifier ("função"
4714 is "function" in PT). */
4717 /* \377 (0xff) is Latin1 'ÿ'. */
4720 /* \377 (0xff) is Latin1 'ÿ'. */
4724 /* A name with all sorts of complications. Starts with "z" to make
4725 it easier for the completion tests below. */
4726 #define Z_SYM_NAME \
4727 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4728 "::tuple<(anonymous namespace)::ui*, " \
4729 "std::default_delete<(anonymous namespace)::ui>, void>"
4734 /* Returns true if the mapped_index_base::find_name_component_bounds
4735 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4736 in completion mode. */
4739 check_find_bounds_finds (mapped_index_base
&index
,
4740 const char *search_name
,
4741 gdb::array_view
<const char *> expected_syms
)
4743 lookup_name_info
lookup_name (search_name
,
4744 symbol_name_match_type::FULL
, true);
4746 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4749 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4750 if (distance
!= expected_syms
.size ())
4753 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4755 auto nc_elem
= bounds
.first
+ exp_elem
;
4756 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
4757 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4764 /* Test the lower-level mapped_index::find_name_component_bounds
4768 test_mapped_index_find_name_component_bounds ()
4770 mock_mapped_index
mock_index (test_symbols
);
4772 mock_index
.build_name_components ();
4774 /* Test the lower-level mapped_index::find_name_component_bounds
4775 method in completion mode. */
4777 static const char *expected_syms
[] = {
4782 SELF_CHECK (check_find_bounds_finds (mock_index
,
4783 "t1_func", expected_syms
));
4786 /* Check that the increment-last-char in the name matching algorithm
4787 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4789 static const char *expected_syms1
[] = {
4793 SELF_CHECK (check_find_bounds_finds (mock_index
,
4794 "\377", expected_syms1
));
4796 static const char *expected_syms2
[] = {
4799 SELF_CHECK (check_find_bounds_finds (mock_index
,
4800 "\377\377", expected_syms2
));
4804 /* Test dw2_expand_symtabs_matching_symbol. */
4807 test_dw2_expand_symtabs_matching_symbol ()
4809 mock_mapped_index
mock_index (test_symbols
);
4811 /* We let all tests run until the end even if some fails, for debug
4813 bool any_mismatch
= false;
4815 /* Create the expected symbols list (an initializer_list). Needed
4816 because lists have commas, and we need to pass them to CHECK,
4817 which is a macro. */
4818 #define EXPECT(...) { __VA_ARGS__ }
4820 /* Wrapper for check_match that passes down the current
4821 __FILE__/__LINE__. */
4822 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4823 any_mismatch |= !check_match (__FILE__, __LINE__, \
4825 NAME, MATCH_TYPE, COMPLETION_MODE, \
4828 /* Identity checks. */
4829 for (const char *sym
: test_symbols
)
4831 /* Should be able to match all existing symbols. */
4832 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4835 /* Should be able to match all existing symbols with
4837 std::string with_params
= std::string (sym
) + "(int)";
4838 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4841 /* Should be able to match all existing symbols with
4842 parameters and qualifiers. */
4843 with_params
= std::string (sym
) + " ( int ) const";
4844 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4847 /* This should really find sym, but cp-name-parser.y doesn't
4848 know about lvalue/rvalue qualifiers yet. */
4849 with_params
= std::string (sym
) + " ( int ) &&";
4850 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4854 /* Check that the name matching algorithm for completion doesn't get
4855 confused with Latin1 'ÿ' / 0xff. */
4857 static const char str
[] = "\377";
4858 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4859 EXPECT ("\377", "\377\377123"));
4862 /* Check that the increment-last-char in the matching algorithm for
4863 completion doesn't match "t1_fund" when completing "t1_func". */
4865 static const char str
[] = "t1_func";
4866 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4867 EXPECT ("t1_func", "t1_func1"));
4870 /* Check that completion mode works at each prefix of the expected
4873 static const char str
[] = "function(int)";
4874 size_t len
= strlen (str
);
4877 for (size_t i
= 1; i
< len
; i
++)
4879 lookup
.assign (str
, i
);
4880 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4881 EXPECT ("function"));
4885 /* While "w" is a prefix of both components, the match function
4886 should still only be called once. */
4888 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4890 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4894 /* Same, with a "complicated" symbol. */
4896 static const char str
[] = Z_SYM_NAME
;
4897 size_t len
= strlen (str
);
4900 for (size_t i
= 1; i
< len
; i
++)
4902 lookup
.assign (str
, i
);
4903 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4904 EXPECT (Z_SYM_NAME
));
4908 /* In FULL mode, an incomplete symbol doesn't match. */
4910 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4914 /* A complete symbol with parameters matches any overload, since the
4915 index has no overload info. */
4917 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4918 EXPECT ("std::zfunction", "std::zfunction2"));
4919 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4920 EXPECT ("std::zfunction", "std::zfunction2"));
4921 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4922 EXPECT ("std::zfunction", "std::zfunction2"));
4925 /* Check that whitespace is ignored appropriately. A symbol with a
4926 template argument list. */
4928 static const char expected
[] = "ns::foo<int>";
4929 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4931 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4935 /* Check that whitespace is ignored appropriately. A symbol with a
4936 template argument list that includes a pointer. */
4938 static const char expected
[] = "ns::foo<char*>";
4939 /* Try both completion and non-completion modes. */
4940 static const bool completion_mode
[2] = {false, true};
4941 for (size_t i
= 0; i
< 2; i
++)
4943 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4944 completion_mode
[i
], EXPECT (expected
));
4945 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4946 completion_mode
[i
], EXPECT (expected
));
4948 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4949 completion_mode
[i
], EXPECT (expected
));
4950 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4951 completion_mode
[i
], EXPECT (expected
));
4956 /* Check method qualifiers are ignored. */
4957 static const char expected
[] = "ns::foo<char*>";
4958 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4959 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4960 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4961 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4962 CHECK_MATCH ("foo < char * > ( int ) const",
4963 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4964 CHECK_MATCH ("foo < char * > ( int ) &&",
4965 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4968 /* Test lookup names that don't match anything. */
4970 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4973 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4977 /* Some wild matching tests, exercising "(anonymous namespace)",
4978 which should not be confused with a parameter list. */
4980 static const char *syms
[] = {
4984 "A :: B :: C ( int )",
4989 for (const char *s
: syms
)
4991 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4992 EXPECT ("(anonymous namespace)::A::B::C"));
4997 static const char expected
[] = "ns2::tmpl<int>::foo2";
4998 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
5000 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
5004 SELF_CHECK (!any_mismatch
);
5013 test_mapped_index_find_name_component_bounds ();
5014 test_dw2_expand_symtabs_matching_symbol ();
5017 }} // namespace selftests::dw2_expand_symtabs_matching
5019 #endif /* GDB_SELF_TEST */
5021 /* If FILE_MATCHER is NULL or if PER_CU has
5022 dwarf2_per_cu_quick_data::MARK set (see
5023 dw_expand_symtabs_matching_file_matcher), expand the CU and call
5024 EXPANSION_NOTIFY on it. */
5027 dw2_expand_symtabs_matching_one
5028 (struct dwarf2_per_cu_data
*per_cu
,
5029 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5030 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
5032 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
5034 bool symtab_was_null
5035 = (per_cu
->v
.quick
->compunit_symtab
== NULL
);
5037 dw2_instantiate_symtab (per_cu
, false);
5039 if (expansion_notify
!= NULL
5041 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
5042 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
5046 /* Helper for dw2_expand_matching symtabs. Called on each symbol
5047 matched, to expand corresponding CUs that were marked. IDX is the
5048 index of the symbol name that matched. */
5051 dw2_expand_marked_cus
5052 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
5053 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5054 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5057 offset_type
*vec
, vec_len
, vec_idx
;
5058 bool global_seen
= false;
5059 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
5061 vec
= (offset_type
*) (index
.constant_pool
5062 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
5063 vec_len
= MAYBE_SWAP (vec
[0]);
5064 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
5066 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
5067 /* This value is only valid for index versions >= 7. */
5068 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
5069 gdb_index_symbol_kind symbol_kind
=
5070 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
5071 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
5072 /* Only check the symbol attributes if they're present.
5073 Indices prior to version 7 don't record them,
5074 and indices >= 7 may elide them for certain symbols
5075 (gold does this). */
5078 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
5080 /* Work around gold/15646. */
5083 if (!is_static
&& global_seen
)
5089 /* Only check the symbol's kind if it has one. */
5094 case VARIABLES_DOMAIN
:
5095 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
5098 case FUNCTIONS_DOMAIN
:
5099 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
5103 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
5106 case MODULES_DOMAIN
:
5107 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
5115 /* Don't crash on bad data. */
5116 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
5117 + dwarf2_per_objfile
->all_type_units
.size ()))
5119 complaint (_(".gdb_index entry has bad CU index"
5121 objfile_name (dwarf2_per_objfile
->objfile
));
5125 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
5126 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5131 /* If FILE_MATCHER is non-NULL, set all the
5132 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
5133 that match FILE_MATCHER. */
5136 dw_expand_symtabs_matching_file_matcher
5137 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5138 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
5140 if (file_matcher
== NULL
)
5143 objfile
*const objfile
= dwarf2_per_objfile
->objfile
;
5145 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
5147 NULL
, xcalloc
, xfree
));
5148 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
5150 NULL
, xcalloc
, xfree
));
5152 /* The rule is CUs specify all the files, including those used by
5153 any TU, so there's no need to scan TUs here. */
5155 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5159 per_cu
->v
.quick
->mark
= 0;
5161 /* We only need to look at symtabs not already expanded. */
5162 if (per_cu
->v
.quick
->compunit_symtab
)
5165 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
5166 if (file_data
== NULL
)
5169 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
5171 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
5173 per_cu
->v
.quick
->mark
= 1;
5177 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
5179 const char *this_real_name
;
5181 if (file_matcher (file_data
->file_names
[j
], false))
5183 per_cu
->v
.quick
->mark
= 1;
5187 /* Before we invoke realpath, which can get expensive when many
5188 files are involved, do a quick comparison of the basenames. */
5189 if (!basenames_may_differ
5190 && !file_matcher (lbasename (file_data
->file_names
[j
]),
5194 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
5195 if (file_matcher (this_real_name
, false))
5197 per_cu
->v
.quick
->mark
= 1;
5202 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
5203 ? visited_found
.get ()
5204 : visited_not_found
.get (),
5211 dw2_expand_symtabs_matching
5212 (struct objfile
*objfile
,
5213 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5214 const lookup_name_info
&lookup_name
,
5215 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5216 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5217 enum search_domain kind
)
5219 struct dwarf2_per_objfile
*dwarf2_per_objfile
5220 = get_dwarf2_per_objfile (objfile
);
5222 /* index_table is NULL if OBJF_READNOW. */
5223 if (!dwarf2_per_objfile
->index_table
)
5226 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5228 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
5230 dw2_expand_symtabs_matching_symbol (index
, lookup_name
,
5232 kind
, [&] (offset_type idx
)
5234 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
5235 expansion_notify
, kind
);
5240 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
5243 static struct compunit_symtab
*
5244 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
5249 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
5250 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
5253 if (cust
->includes
== NULL
)
5256 for (i
= 0; cust
->includes
[i
]; ++i
)
5258 struct compunit_symtab
*s
= cust
->includes
[i
];
5260 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
5268 static struct compunit_symtab
*
5269 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
5270 struct bound_minimal_symbol msymbol
,
5272 struct obj_section
*section
,
5275 struct dwarf2_per_cu_data
*data
;
5276 struct compunit_symtab
*result
;
5278 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
5281 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
5282 data
= (struct dwarf2_per_cu_data
*) addrmap_find
5283 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
5287 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
5288 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
5289 paddress (get_objfile_arch (objfile
), pc
));
5292 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
,
5295 gdb_assert (result
!= NULL
);
5300 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
5301 void *data
, int need_fullname
)
5303 struct dwarf2_per_objfile
*dwarf2_per_objfile
5304 = get_dwarf2_per_objfile (objfile
);
5306 if (!dwarf2_per_objfile
->filenames_cache
)
5308 dwarf2_per_objfile
->filenames_cache
.emplace ();
5310 htab_up
visited (htab_create_alloc (10,
5311 htab_hash_pointer
, htab_eq_pointer
,
5312 NULL
, xcalloc
, xfree
));
5314 /* The rule is CUs specify all the files, including those used
5315 by any TU, so there's no need to scan TUs here. We can
5316 ignore file names coming from already-expanded CUs. */
5318 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5320 if (per_cu
->v
.quick
->compunit_symtab
)
5322 void **slot
= htab_find_slot (visited
.get (),
5323 per_cu
->v
.quick
->file_names
,
5326 *slot
= per_cu
->v
.quick
->file_names
;
5330 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5332 /* We only need to look at symtabs not already expanded. */
5333 if (per_cu
->v
.quick
->compunit_symtab
)
5336 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
5337 if (file_data
== NULL
)
5340 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
5343 /* Already visited. */
5348 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
5350 const char *filename
= file_data
->file_names
[j
];
5351 dwarf2_per_objfile
->filenames_cache
->seen (filename
);
5356 dwarf2_per_objfile
->filenames_cache
->traverse ([&] (const char *filename
)
5358 gdb::unique_xmalloc_ptr
<char> this_real_name
;
5361 this_real_name
= gdb_realpath (filename
);
5362 (*fun
) (filename
, this_real_name
.get (), data
);
5367 dw2_has_symbols (struct objfile
*objfile
)
5372 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
5375 dw2_find_last_source_symtab
,
5376 dw2_forget_cached_source_info
,
5377 dw2_map_symtabs_matching_filename
,
5381 dw2_expand_symtabs_for_function
,
5382 dw2_expand_all_symtabs
,
5383 dw2_expand_symtabs_with_fullname
,
5384 dw2_map_matching_symbols
,
5385 dw2_expand_symtabs_matching
,
5386 dw2_find_pc_sect_compunit_symtab
,
5388 dw2_map_symbol_filenames
5391 /* DWARF-5 debug_names reader. */
5393 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
5394 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
5396 /* A helper function that reads the .debug_names section in SECTION
5397 and fills in MAP. FILENAME is the name of the file containing the
5398 section; it is used for error reporting.
5400 Returns true if all went well, false otherwise. */
5403 read_debug_names_from_section (struct objfile
*objfile
,
5404 const char *filename
,
5405 struct dwarf2_section_info
*section
,
5406 mapped_debug_names
&map
)
5408 if (dwarf2_section_empty_p (section
))
5411 /* Older elfutils strip versions could keep the section in the main
5412 executable while splitting it for the separate debug info file. */
5413 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
5416 dwarf2_read_section (objfile
, section
);
5418 map
.dwarf5_byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
5420 const gdb_byte
*addr
= section
->buffer
;
5422 bfd
*const abfd
= get_section_bfd_owner (section
);
5424 unsigned int bytes_read
;
5425 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
5428 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
5429 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
5430 if (bytes_read
+ length
!= section
->size
)
5432 /* There may be multiple per-CU indices. */
5433 warning (_("Section .debug_names in %s length %s does not match "
5434 "section length %s, ignoring .debug_names."),
5435 filename
, plongest (bytes_read
+ length
),
5436 pulongest (section
->size
));
5440 /* The version number. */
5441 uint16_t version
= read_2_bytes (abfd
, addr
);
5445 warning (_("Section .debug_names in %s has unsupported version %d, "
5446 "ignoring .debug_names."),
5452 uint16_t padding
= read_2_bytes (abfd
, addr
);
5456 warning (_("Section .debug_names in %s has unsupported padding %d, "
5457 "ignoring .debug_names."),
5462 /* comp_unit_count - The number of CUs in the CU list. */
5463 map
.cu_count
= read_4_bytes (abfd
, addr
);
5466 /* local_type_unit_count - The number of TUs in the local TU
5468 map
.tu_count
= read_4_bytes (abfd
, addr
);
5471 /* foreign_type_unit_count - The number of TUs in the foreign TU
5473 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
5475 if (foreign_tu_count
!= 0)
5477 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
5478 "ignoring .debug_names."),
5479 filename
, static_cast<unsigned long> (foreign_tu_count
));
5483 /* bucket_count - The number of hash buckets in the hash lookup
5485 map
.bucket_count
= read_4_bytes (abfd
, addr
);
5488 /* name_count - The number of unique names in the index. */
5489 map
.name_count
= read_4_bytes (abfd
, addr
);
5492 /* abbrev_table_size - The size in bytes of the abbreviations
5494 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
5497 /* augmentation_string_size - The size in bytes of the augmentation
5498 string. This value is rounded up to a multiple of 4. */
5499 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
5501 map
.augmentation_is_gdb
= ((augmentation_string_size
5502 == sizeof (dwarf5_augmentation
))
5503 && memcmp (addr
, dwarf5_augmentation
,
5504 sizeof (dwarf5_augmentation
)) == 0);
5505 augmentation_string_size
+= (-augmentation_string_size
) & 3;
5506 addr
+= augmentation_string_size
;
5509 map
.cu_table_reordered
= addr
;
5510 addr
+= map
.cu_count
* map
.offset_size
;
5512 /* List of Local TUs */
5513 map
.tu_table_reordered
= addr
;
5514 addr
+= map
.tu_count
* map
.offset_size
;
5516 /* Hash Lookup Table */
5517 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5518 addr
+= map
.bucket_count
* 4;
5519 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5520 addr
+= map
.name_count
* 4;
5523 map
.name_table_string_offs_reordered
= addr
;
5524 addr
+= map
.name_count
* map
.offset_size
;
5525 map
.name_table_entry_offs_reordered
= addr
;
5526 addr
+= map
.name_count
* map
.offset_size
;
5528 const gdb_byte
*abbrev_table_start
= addr
;
5531 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5536 const auto insertpair
5537 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
5538 if (!insertpair
.second
)
5540 warning (_("Section .debug_names in %s has duplicate index %s, "
5541 "ignoring .debug_names."),
5542 filename
, pulongest (index_num
));
5545 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
5546 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5551 mapped_debug_names::index_val::attr attr
;
5552 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5554 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5556 if (attr
.form
== DW_FORM_implicit_const
)
5558 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
5562 if (attr
.dw_idx
== 0 && attr
.form
== 0)
5564 indexval
.attr_vec
.push_back (std::move (attr
));
5567 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
5569 warning (_("Section .debug_names in %s has abbreviation_table "
5570 "of size %s vs. written as %u, ignoring .debug_names."),
5571 filename
, plongest (addr
- abbrev_table_start
),
5575 map
.entry_pool
= addr
;
5580 /* A helper for create_cus_from_debug_names that handles the MAP's CU
5584 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5585 const mapped_debug_names
&map
,
5586 dwarf2_section_info
§ion
,
5589 sect_offset sect_off_prev
;
5590 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5592 sect_offset sect_off_next
;
5593 if (i
< map
.cu_count
)
5596 = (sect_offset
) (extract_unsigned_integer
5597 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5599 map
.dwarf5_byte_order
));
5602 sect_off_next
= (sect_offset
) section
.size
;
5605 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5606 dwarf2_per_cu_data
*per_cu
5607 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
5608 sect_off_prev
, length
);
5609 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
5611 sect_off_prev
= sect_off_next
;
5615 /* Read the CU list from the mapped index, and use it to create all
5616 the CU objects for this dwarf2_per_objfile. */
5619 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5620 const mapped_debug_names
&map
,
5621 const mapped_debug_names
&dwz_map
)
5623 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
5624 dwarf2_per_objfile
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5626 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
5627 dwarf2_per_objfile
->info
,
5628 false /* is_dwz */);
5630 if (dwz_map
.cu_count
== 0)
5633 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5634 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
5638 /* Read .debug_names. If everything went ok, initialize the "quick"
5639 elements of all the CUs and return true. Otherwise, return false. */
5642 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
5644 std::unique_ptr
<mapped_debug_names
> map
5645 (new mapped_debug_names (dwarf2_per_objfile
));
5646 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
5647 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5649 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5650 &dwarf2_per_objfile
->debug_names
,
5654 /* Don't use the index if it's empty. */
5655 if (map
->name_count
== 0)
5658 /* If there is a .dwz file, read it so we can get its CU list as
5660 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5663 if (!read_debug_names_from_section (objfile
,
5664 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5665 &dwz
->debug_names
, dwz_map
))
5667 warning (_("could not read '.debug_names' section from %s; skipping"),
5668 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5673 create_cus_from_debug_names (dwarf2_per_objfile
, *map
, dwz_map
);
5675 if (map
->tu_count
!= 0)
5677 /* We can only handle a single .debug_types when we have an
5679 if (dwarf2_per_objfile
->types
.size () != 1)
5682 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
5684 create_signatured_type_table_from_debug_names
5685 (dwarf2_per_objfile
, *map
, section
, &dwarf2_per_objfile
->abbrev
);
5688 create_addrmap_from_aranges (dwarf2_per_objfile
,
5689 &dwarf2_per_objfile
->debug_aranges
);
5691 dwarf2_per_objfile
->debug_names_table
= std::move (map
);
5692 dwarf2_per_objfile
->using_index
= 1;
5693 dwarf2_per_objfile
->quick_file_names_table
=
5694 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
5699 /* Type used to manage iterating over all CUs looking for a symbol for
5702 class dw2_debug_names_iterator
5705 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5706 gdb::optional
<block_enum
> block_index
,
5709 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5710 m_addr (find_vec_in_debug_names (map
, name
))
5713 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5714 search_domain search
, uint32_t namei
)
5717 m_addr (find_vec_in_debug_names (map
, namei
))
5720 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5721 block_enum block_index
, domain_enum domain
,
5723 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5724 m_addr (find_vec_in_debug_names (map
, namei
))
5727 /* Return the next matching CU or NULL if there are no more. */
5728 dwarf2_per_cu_data
*next ();
5731 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5733 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5736 /* The internalized form of .debug_names. */
5737 const mapped_debug_names
&m_map
;
5739 /* If set, only look for symbols that match that block. Valid values are
5740 GLOBAL_BLOCK and STATIC_BLOCK. */
5741 const gdb::optional
<block_enum
> m_block_index
;
5743 /* The kind of symbol we're looking for. */
5744 const domain_enum m_domain
= UNDEF_DOMAIN
;
5745 const search_domain m_search
= ALL_DOMAIN
;
5747 /* The list of CUs from the index entry of the symbol, or NULL if
5749 const gdb_byte
*m_addr
;
5753 mapped_debug_names::namei_to_name (uint32_t namei
) const
5755 const ULONGEST namei_string_offs
5756 = extract_unsigned_integer ((name_table_string_offs_reordered
5757 + namei
* offset_size
),
5760 return read_indirect_string_at_offset
5761 (dwarf2_per_objfile
, dwarf2_per_objfile
->objfile
->obfd
, namei_string_offs
);
5764 /* Find a slot in .debug_names for the object named NAME. If NAME is
5765 found, return pointer to its pool data. If NAME cannot be found,
5769 dw2_debug_names_iterator::find_vec_in_debug_names
5770 (const mapped_debug_names
&map
, const char *name
)
5772 int (*cmp
) (const char *, const char *);
5774 gdb::unique_xmalloc_ptr
<char> without_params
;
5775 if (current_language
->la_language
== language_cplus
5776 || current_language
->la_language
== language_fortran
5777 || current_language
->la_language
== language_d
)
5779 /* NAME is already canonical. Drop any qualifiers as
5780 .debug_names does not contain any. */
5782 if (strchr (name
, '(') != NULL
)
5784 without_params
= cp_remove_params (name
);
5785 if (without_params
!= NULL
)
5786 name
= without_params
.get ();
5790 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5792 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5794 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5795 (map
.bucket_table_reordered
5796 + (full_hash
% map
.bucket_count
)), 4,
5797 map
.dwarf5_byte_order
);
5801 if (namei
>= map
.name_count
)
5803 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5805 namei
, map
.name_count
,
5806 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5812 const uint32_t namei_full_hash
5813 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5814 (map
.hash_table_reordered
+ namei
), 4,
5815 map
.dwarf5_byte_order
);
5816 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5819 if (full_hash
== namei_full_hash
)
5821 const char *const namei_string
= map
.namei_to_name (namei
);
5823 #if 0 /* An expensive sanity check. */
5824 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5826 complaint (_("Wrong .debug_names hash for string at index %u "
5828 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5833 if (cmp (namei_string
, name
) == 0)
5835 const ULONGEST namei_entry_offs
5836 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5837 + namei
* map
.offset_size
),
5838 map
.offset_size
, map
.dwarf5_byte_order
);
5839 return map
.entry_pool
+ namei_entry_offs
;
5844 if (namei
>= map
.name_count
)
5850 dw2_debug_names_iterator::find_vec_in_debug_names
5851 (const mapped_debug_names
&map
, uint32_t namei
)
5853 if (namei
>= map
.name_count
)
5855 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5857 namei
, map
.name_count
,
5858 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5862 const ULONGEST namei_entry_offs
5863 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5864 + namei
* map
.offset_size
),
5865 map
.offset_size
, map
.dwarf5_byte_order
);
5866 return map
.entry_pool
+ namei_entry_offs
;
5869 /* See dw2_debug_names_iterator. */
5871 dwarf2_per_cu_data
*
5872 dw2_debug_names_iterator::next ()
5877 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
5878 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5879 bfd
*const abfd
= objfile
->obfd
;
5883 unsigned int bytes_read
;
5884 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5885 m_addr
+= bytes_read
;
5889 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5890 if (indexval_it
== m_map
.abbrev_map
.cend ())
5892 complaint (_("Wrong .debug_names undefined abbrev code %s "
5894 pulongest (abbrev
), objfile_name (objfile
));
5897 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5898 enum class symbol_linkage
{
5902 } symbol_linkage_
= symbol_linkage::unknown
;
5903 dwarf2_per_cu_data
*per_cu
= NULL
;
5904 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5909 case DW_FORM_implicit_const
:
5910 ull
= attr
.implicit_const
;
5912 case DW_FORM_flag_present
:
5916 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5917 m_addr
+= bytes_read
;
5920 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5921 dwarf_form_name (attr
.form
),
5922 objfile_name (objfile
));
5925 switch (attr
.dw_idx
)
5927 case DW_IDX_compile_unit
:
5928 /* Don't crash on bad data. */
5929 if (ull
>= dwarf2_per_objfile
->all_comp_units
.size ())
5931 complaint (_(".debug_names entry has bad CU index %s"
5934 objfile_name (dwarf2_per_objfile
->objfile
));
5937 per_cu
= dwarf2_per_objfile
->get_cutu (ull
);
5939 case DW_IDX_type_unit
:
5940 /* Don't crash on bad data. */
5941 if (ull
>= dwarf2_per_objfile
->all_type_units
.size ())
5943 complaint (_(".debug_names entry has bad TU index %s"
5946 objfile_name (dwarf2_per_objfile
->objfile
));
5949 per_cu
= &dwarf2_per_objfile
->get_tu (ull
)->per_cu
;
5951 case DW_IDX_GNU_internal
:
5952 if (!m_map
.augmentation_is_gdb
)
5954 symbol_linkage_
= symbol_linkage::static_
;
5956 case DW_IDX_GNU_external
:
5957 if (!m_map
.augmentation_is_gdb
)
5959 symbol_linkage_
= symbol_linkage::extern_
;
5964 /* Skip if already read in. */
5965 if (per_cu
->v
.quick
->compunit_symtab
)
5968 /* Check static vs global. */
5969 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5971 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5972 const bool symbol_is_static
=
5973 symbol_linkage_
== symbol_linkage::static_
;
5974 if (want_static
!= symbol_is_static
)
5978 /* Match dw2_symtab_iter_next, symbol_kind
5979 and debug_names::psymbol_tag. */
5983 switch (indexval
.dwarf_tag
)
5985 case DW_TAG_variable
:
5986 case DW_TAG_subprogram
:
5987 /* Some types are also in VAR_DOMAIN. */
5988 case DW_TAG_typedef
:
5989 case DW_TAG_structure_type
:
5996 switch (indexval
.dwarf_tag
)
5998 case DW_TAG_typedef
:
5999 case DW_TAG_structure_type
:
6006 switch (indexval
.dwarf_tag
)
6009 case DW_TAG_variable
:
6016 switch (indexval
.dwarf_tag
)
6028 /* Match dw2_expand_symtabs_matching, symbol_kind and
6029 debug_names::psymbol_tag. */
6032 case VARIABLES_DOMAIN
:
6033 switch (indexval
.dwarf_tag
)
6035 case DW_TAG_variable
:
6041 case FUNCTIONS_DOMAIN
:
6042 switch (indexval
.dwarf_tag
)
6044 case DW_TAG_subprogram
:
6051 switch (indexval
.dwarf_tag
)
6053 case DW_TAG_typedef
:
6054 case DW_TAG_structure_type
:
6060 case MODULES_DOMAIN
:
6061 switch (indexval
.dwarf_tag
)
6075 static struct compunit_symtab
*
6076 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
6077 const char *name
, domain_enum domain
)
6079 struct dwarf2_per_objfile
*dwarf2_per_objfile
6080 = get_dwarf2_per_objfile (objfile
);
6082 const auto &mapp
= dwarf2_per_objfile
->debug_names_table
;
6085 /* index is NULL if OBJF_READNOW. */
6088 const auto &map
= *mapp
;
6090 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
);
6092 struct compunit_symtab
*stab_best
= NULL
;
6093 struct dwarf2_per_cu_data
*per_cu
;
6094 while ((per_cu
= iter
.next ()) != NULL
)
6096 struct symbol
*sym
, *with_opaque
= NULL
;
6097 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
6098 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
6099 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
6101 sym
= block_find_symbol (block
, name
, domain
,
6102 block_find_non_opaque_type_preferred
,
6105 /* Some caution must be observed with overloaded functions and
6106 methods, since the index will not contain any overload
6107 information (but NAME might contain it). */
6110 && strcmp_iw (sym
->search_name (), name
) == 0)
6112 if (with_opaque
!= NULL
6113 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
6116 /* Keep looking through other CUs. */
6122 /* This dumps minimal information about .debug_names. It is called
6123 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
6124 uses this to verify that .debug_names has been loaded. */
6127 dw2_debug_names_dump (struct objfile
*objfile
)
6129 struct dwarf2_per_objfile
*dwarf2_per_objfile
6130 = get_dwarf2_per_objfile (objfile
);
6132 gdb_assert (dwarf2_per_objfile
->using_index
);
6133 printf_filtered (".debug_names:");
6134 if (dwarf2_per_objfile
->debug_names_table
)
6135 printf_filtered (" exists\n");
6137 printf_filtered (" faked for \"readnow\"\n");
6138 printf_filtered ("\n");
6142 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
6143 const char *func_name
)
6145 struct dwarf2_per_objfile
*dwarf2_per_objfile
6146 = get_dwarf2_per_objfile (objfile
);
6148 /* dwarf2_per_objfile->debug_names_table is NULL if OBJF_READNOW. */
6149 if (dwarf2_per_objfile
->debug_names_table
)
6151 const mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6153 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
);
6155 struct dwarf2_per_cu_data
*per_cu
;
6156 while ((per_cu
= iter
.next ()) != NULL
)
6157 dw2_instantiate_symtab (per_cu
, false);
6162 dw2_debug_names_map_matching_symbols
6163 (struct objfile
*objfile
,
6164 const lookup_name_info
&name
, domain_enum domain
,
6166 gdb::function_view
<symbol_found_callback_ftype
> callback
,
6167 symbol_compare_ftype
*ordered_compare
)
6169 struct dwarf2_per_objfile
*dwarf2_per_objfile
6170 = get_dwarf2_per_objfile (objfile
);
6172 /* debug_names_table is NULL if OBJF_READNOW. */
6173 if (!dwarf2_per_objfile
->debug_names_table
)
6176 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6177 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
6179 const char *match_name
= name
.ada ().lookup_name ().c_str ();
6180 auto matcher
= [&] (const char *symname
)
6182 if (ordered_compare
== nullptr)
6184 return ordered_compare (symname
, match_name
) == 0;
6187 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
6188 [&] (offset_type namei
)
6190 /* The name was matched, now expand corresponding CUs that were
6192 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
);
6194 struct dwarf2_per_cu_data
*per_cu
;
6195 while ((per_cu
= iter
.next ()) != NULL
)
6196 dw2_expand_symtabs_matching_one (per_cu
, nullptr, nullptr);
6200 /* It's a shame we couldn't do this inside the
6201 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
6202 that have already been expanded. Instead, this loop matches what
6203 the psymtab code does. */
6204 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
6206 struct compunit_symtab
*cust
= per_cu
->v
.quick
->compunit_symtab
;
6207 if (cust
!= nullptr)
6209 const struct block
*block
6210 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
6211 if (!iterate_over_symbols_terminated (block
, name
,
6219 dw2_debug_names_expand_symtabs_matching
6220 (struct objfile
*objfile
,
6221 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
6222 const lookup_name_info
&lookup_name
,
6223 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
6224 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
6225 enum search_domain kind
)
6227 struct dwarf2_per_objfile
*dwarf2_per_objfile
6228 = get_dwarf2_per_objfile (objfile
);
6230 /* debug_names_table is NULL if OBJF_READNOW. */
6231 if (!dwarf2_per_objfile
->debug_names_table
)
6234 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
6236 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6238 dw2_expand_symtabs_matching_symbol (map
, lookup_name
,
6240 kind
, [&] (offset_type namei
)
6242 /* The name was matched, now expand corresponding CUs that were
6244 dw2_debug_names_iterator
iter (map
, kind
, namei
);
6246 struct dwarf2_per_cu_data
*per_cu
;
6247 while ((per_cu
= iter
.next ()) != NULL
)
6248 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
6254 const struct quick_symbol_functions dwarf2_debug_names_functions
=
6257 dw2_find_last_source_symtab
,
6258 dw2_forget_cached_source_info
,
6259 dw2_map_symtabs_matching_filename
,
6260 dw2_debug_names_lookup_symbol
,
6262 dw2_debug_names_dump
,
6263 dw2_debug_names_expand_symtabs_for_function
,
6264 dw2_expand_all_symtabs
,
6265 dw2_expand_symtabs_with_fullname
,
6266 dw2_debug_names_map_matching_symbols
,
6267 dw2_debug_names_expand_symtabs_matching
,
6268 dw2_find_pc_sect_compunit_symtab
,
6270 dw2_map_symbol_filenames
6273 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
6274 to either a dwarf2_per_objfile or dwz_file object. */
6276 template <typename T
>
6277 static gdb::array_view
<const gdb_byte
>
6278 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
6280 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
6282 if (dwarf2_section_empty_p (section
))
6285 /* Older elfutils strip versions could keep the section in the main
6286 executable while splitting it for the separate debug info file. */
6287 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
6290 dwarf2_read_section (obj
, section
);
6292 /* dwarf2_section_info::size is a bfd_size_type, while
6293 gdb::array_view works with size_t. On 32-bit hosts, with
6294 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
6295 is 32-bit. So we need an explicit narrowing conversion here.
6296 This is fine, because it's impossible to allocate or mmap an
6297 array/buffer larger than what size_t can represent. */
6298 return gdb::make_array_view (section
->buffer
, section
->size
);
6301 /* Lookup the index cache for the contents of the index associated to
6304 static gdb::array_view
<const gdb_byte
>
6305 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_objfile
*dwarf2_obj
)
6307 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
6308 if (build_id
== nullptr)
6311 return global_index_cache
.lookup_gdb_index (build_id
,
6312 &dwarf2_obj
->index_cache_res
);
6315 /* Same as the above, but for DWZ. */
6317 static gdb::array_view
<const gdb_byte
>
6318 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
6320 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
6321 if (build_id
== nullptr)
6324 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
6327 /* See symfile.h. */
6330 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
6332 struct dwarf2_per_objfile
*dwarf2_per_objfile
6333 = get_dwarf2_per_objfile (objfile
);
6335 /* If we're about to read full symbols, don't bother with the
6336 indices. In this case we also don't care if some other debug
6337 format is making psymtabs, because they are all about to be
6339 if ((objfile
->flags
& OBJF_READNOW
))
6341 dwarf2_per_objfile
->using_index
= 1;
6342 create_all_comp_units (dwarf2_per_objfile
);
6343 create_all_type_units (dwarf2_per_objfile
);
6344 dwarf2_per_objfile
->quick_file_names_table
6345 = create_quick_file_names_table
6346 (dwarf2_per_objfile
->all_comp_units
.size ());
6348 for (int i
= 0; i
< (dwarf2_per_objfile
->all_comp_units
.size ()
6349 + dwarf2_per_objfile
->all_type_units
.size ()); ++i
)
6351 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
6353 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6354 struct dwarf2_per_cu_quick_data
);
6357 /* Return 1 so that gdb sees the "quick" functions. However,
6358 these functions will be no-ops because we will have expanded
6360 *index_kind
= dw_index_kind::GDB_INDEX
;
6364 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
6366 *index_kind
= dw_index_kind::DEBUG_NAMES
;
6370 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
6371 get_gdb_index_contents_from_section
<struct dwarf2_per_objfile
>,
6372 get_gdb_index_contents_from_section
<dwz_file
>))
6374 *index_kind
= dw_index_kind::GDB_INDEX
;
6378 /* ... otherwise, try to find the index in the index cache. */
6379 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
6380 get_gdb_index_contents_from_cache
,
6381 get_gdb_index_contents_from_cache_dwz
))
6383 global_index_cache
.hit ();
6384 *index_kind
= dw_index_kind::GDB_INDEX
;
6388 global_index_cache
.miss ();
6394 /* Build a partial symbol table. */
6397 dwarf2_build_psymtabs (struct objfile
*objfile
)
6399 struct dwarf2_per_objfile
*dwarf2_per_objfile
6400 = get_dwarf2_per_objfile (objfile
);
6402 init_psymbol_list (objfile
, 1024);
6406 /* This isn't really ideal: all the data we allocate on the
6407 objfile's obstack is still uselessly kept around. However,
6408 freeing it seems unsafe. */
6409 psymtab_discarder
psymtabs (objfile
);
6410 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
6413 /* (maybe) store an index in the cache. */
6414 global_index_cache
.store (dwarf2_per_objfile
);
6416 catch (const gdb_exception_error
&except
)
6418 exception_print (gdb_stderr
, except
);
6422 /* Return the total length of the CU described by HEADER. */
6425 get_cu_length (const struct comp_unit_head
*header
)
6427 return header
->initial_length_size
+ header
->length
;
6430 /* Return TRUE if SECT_OFF is within CU_HEADER. */
6433 offset_in_cu_p (const comp_unit_head
*cu_header
, sect_offset sect_off
)
6435 sect_offset bottom
= cu_header
->sect_off
;
6436 sect_offset top
= cu_header
->sect_off
+ get_cu_length (cu_header
);
6438 return sect_off
>= bottom
&& sect_off
< top
;
6441 /* Find the base address of the compilation unit for range lists and
6442 location lists. It will normally be specified by DW_AT_low_pc.
6443 In DWARF-3 draft 4, the base address could be overridden by
6444 DW_AT_entry_pc. It's been removed, but GCC still uses this for
6445 compilation units with discontinuous ranges. */
6448 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
6450 struct attribute
*attr
;
6453 cu
->base_address
= 0;
6455 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
6456 if (attr
!= nullptr)
6458 cu
->base_address
= attr_value_as_address (attr
);
6463 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6464 if (attr
!= nullptr)
6466 cu
->base_address
= attr_value_as_address (attr
);
6472 /* Read in the comp unit header information from the debug_info at info_ptr.
6473 Use rcuh_kind::COMPILE as the default type if not known by the caller.
6474 NOTE: This leaves members offset, first_die_offset to be filled in
6477 static const gdb_byte
*
6478 read_comp_unit_head (struct comp_unit_head
*cu_header
,
6479 const gdb_byte
*info_ptr
,
6480 struct dwarf2_section_info
*section
,
6481 rcuh_kind section_kind
)
6484 unsigned int bytes_read
;
6485 const char *filename
= get_section_file_name (section
);
6486 bfd
*abfd
= get_section_bfd_owner (section
);
6488 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
6489 cu_header
->initial_length_size
= bytes_read
;
6490 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
6491 info_ptr
+= bytes_read
;
6492 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
6493 if (cu_header
->version
< 2 || cu_header
->version
> 5)
6494 error (_("Dwarf Error: wrong version in compilation unit header "
6495 "(is %d, should be 2, 3, 4 or 5) [in module %s]"),
6496 cu_header
->version
, filename
);
6498 if (cu_header
->version
< 5)
6499 switch (section_kind
)
6501 case rcuh_kind::COMPILE
:
6502 cu_header
->unit_type
= DW_UT_compile
;
6504 case rcuh_kind::TYPE
:
6505 cu_header
->unit_type
= DW_UT_type
;
6508 internal_error (__FILE__
, __LINE__
,
6509 _("read_comp_unit_head: invalid section_kind"));
6513 cu_header
->unit_type
= static_cast<enum dwarf_unit_type
>
6514 (read_1_byte (abfd
, info_ptr
));
6516 switch (cu_header
->unit_type
)
6520 case DW_UT_skeleton
:
6521 case DW_UT_split_compile
:
6522 if (section_kind
!= rcuh_kind::COMPILE
)
6523 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6524 "(is %s, should be %s) [in module %s]"),
6525 dwarf_unit_type_name (cu_header
->unit_type
),
6526 dwarf_unit_type_name (DW_UT_type
), filename
);
6529 case DW_UT_split_type
:
6530 section_kind
= rcuh_kind::TYPE
;
6533 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6534 "(is %#04x, should be one of: %s, %s, %s, %s or %s) "
6535 "[in module %s]"), cu_header
->unit_type
,
6536 dwarf_unit_type_name (DW_UT_compile
),
6537 dwarf_unit_type_name (DW_UT_skeleton
),
6538 dwarf_unit_type_name (DW_UT_split_compile
),
6539 dwarf_unit_type_name (DW_UT_type
),
6540 dwarf_unit_type_name (DW_UT_split_type
), filename
);
6543 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6546 cu_header
->abbrev_sect_off
= (sect_offset
) read_offset (abfd
, info_ptr
,
6549 info_ptr
+= bytes_read
;
6550 if (cu_header
->version
< 5)
6552 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6555 signed_addr
= bfd_get_sign_extend_vma (abfd
);
6556 if (signed_addr
< 0)
6557 internal_error (__FILE__
, __LINE__
,
6558 _("read_comp_unit_head: dwarf from non elf file"));
6559 cu_header
->signed_addr_p
= signed_addr
;
6561 bool header_has_signature
= section_kind
== rcuh_kind::TYPE
6562 || cu_header
->unit_type
== DW_UT_skeleton
6563 || cu_header
->unit_type
== DW_UT_split_compile
;
6565 if (header_has_signature
)
6567 cu_header
->signature
= read_8_bytes (abfd
, info_ptr
);
6571 if (section_kind
== rcuh_kind::TYPE
)
6573 LONGEST type_offset
;
6574 type_offset
= read_offset (abfd
, info_ptr
, cu_header
, &bytes_read
);
6575 info_ptr
+= bytes_read
;
6576 cu_header
->type_cu_offset_in_tu
= (cu_offset
) type_offset
;
6577 if (to_underlying (cu_header
->type_cu_offset_in_tu
) != type_offset
)
6578 error (_("Dwarf Error: Too big type_offset in compilation unit "
6579 "header (is %s) [in module %s]"), plongest (type_offset
),
6586 /* Helper function that returns the proper abbrev section for
6589 static struct dwarf2_section_info
*
6590 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
6592 struct dwarf2_section_info
*abbrev
;
6593 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6595 if (this_cu
->is_dwz
)
6596 abbrev
= &dwarf2_get_dwz_file (dwarf2_per_objfile
)->abbrev
;
6598 abbrev
= &dwarf2_per_objfile
->abbrev
;
6603 /* Subroutine of read_and_check_comp_unit_head and
6604 read_and_check_type_unit_head to simplify them.
6605 Perform various error checking on the header. */
6608 error_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6609 struct comp_unit_head
*header
,
6610 struct dwarf2_section_info
*section
,
6611 struct dwarf2_section_info
*abbrev_section
)
6613 const char *filename
= get_section_file_name (section
);
6615 if (to_underlying (header
->abbrev_sect_off
)
6616 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
, abbrev_section
))
6617 error (_("Dwarf Error: bad offset (%s) in compilation unit header "
6618 "(offset %s + 6) [in module %s]"),
6619 sect_offset_str (header
->abbrev_sect_off
),
6620 sect_offset_str (header
->sect_off
),
6623 /* Cast to ULONGEST to use 64-bit arithmetic when possible to
6624 avoid potential 32-bit overflow. */
6625 if (((ULONGEST
) header
->sect_off
+ get_cu_length (header
))
6627 error (_("Dwarf Error: bad length (0x%x) in compilation unit header "
6628 "(offset %s + 0) [in module %s]"),
6629 header
->length
, sect_offset_str (header
->sect_off
),
6633 /* Read in a CU/TU header and perform some basic error checking.
6634 The contents of the header are stored in HEADER.
6635 The result is a pointer to the start of the first DIE. */
6637 static const gdb_byte
*
6638 read_and_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6639 struct comp_unit_head
*header
,
6640 struct dwarf2_section_info
*section
,
6641 struct dwarf2_section_info
*abbrev_section
,
6642 const gdb_byte
*info_ptr
,
6643 rcuh_kind section_kind
)
6645 const gdb_byte
*beg_of_comp_unit
= info_ptr
;
6647 header
->sect_off
= (sect_offset
) (beg_of_comp_unit
- section
->buffer
);
6649 info_ptr
= read_comp_unit_head (header
, info_ptr
, section
, section_kind
);
6651 header
->first_die_cu_offset
= (cu_offset
) (info_ptr
- beg_of_comp_unit
);
6653 error_check_comp_unit_head (dwarf2_per_objfile
, header
, section
,
6659 /* Fetch the abbreviation table offset from a comp or type unit header. */
6662 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6663 struct dwarf2_section_info
*section
,
6664 sect_offset sect_off
)
6666 bfd
*abfd
= get_section_bfd_owner (section
);
6667 const gdb_byte
*info_ptr
;
6668 unsigned int initial_length_size
, offset_size
;
6671 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
6672 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
6673 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6674 offset_size
= initial_length_size
== 4 ? 4 : 8;
6675 info_ptr
+= initial_length_size
;
6677 version
= read_2_bytes (abfd
, info_ptr
);
6681 /* Skip unit type and address size. */
6685 return (sect_offset
) read_offset_1 (abfd
, info_ptr
, offset_size
);
6688 /* Allocate a new partial symtab for file named NAME and mark this new
6689 partial symtab as being an include of PST. */
6692 dwarf2_create_include_psymtab (const char *name
, dwarf2_psymtab
*pst
,
6693 struct objfile
*objfile
)
6695 dwarf2_psymtab
*subpst
= new dwarf2_psymtab (name
, objfile
);
6697 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6699 /* It shares objfile->objfile_obstack. */
6700 subpst
->dirname
= pst
->dirname
;
6703 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
6704 subpst
->dependencies
[0] = pst
;
6705 subpst
->number_of_dependencies
= 1;
6707 /* No private part is necessary for include psymtabs. This property
6708 can be used to differentiate between such include psymtabs and
6709 the regular ones. */
6710 subpst
->per_cu_data
= nullptr;
6713 /* Read the Line Number Program data and extract the list of files
6714 included by the source file represented by PST. Build an include
6715 partial symtab for each of these included files. */
6718 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
6719 struct die_info
*die
,
6720 dwarf2_psymtab
*pst
)
6723 struct attribute
*attr
;
6725 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6726 if (attr
!= nullptr)
6727 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
6729 return; /* No linetable, so no includes. */
6731 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
6732 that we pass in the raw text_low here; that is ok because we're
6733 only decoding the line table to make include partial symtabs, and
6734 so the addresses aren't really used. */
6735 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
6736 pst
->raw_text_low (), 1);
6740 hash_signatured_type (const void *item
)
6742 const struct signatured_type
*sig_type
6743 = (const struct signatured_type
*) item
;
6745 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6746 return sig_type
->signature
;
6750 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6752 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6753 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6755 return lhs
->signature
== rhs
->signature
;
6758 /* Allocate a hash table for signatured types. */
6761 allocate_signatured_type_table (struct objfile
*objfile
)
6763 return htab_create_alloc_ex (41,
6764 hash_signatured_type
,
6767 &objfile
->objfile_obstack
,
6768 hashtab_obstack_allocate
,
6769 dummy_obstack_deallocate
);
6772 /* A helper function to add a signatured type CU to a table. */
6775 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6777 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6778 std::vector
<signatured_type
*> *all_type_units
6779 = (std::vector
<signatured_type
*> *) datum
;
6781 all_type_units
->push_back (sigt
);
6786 /* A helper for create_debug_types_hash_table. Read types from SECTION
6787 and fill them into TYPES_HTAB. It will process only type units,
6788 therefore DW_UT_type. */
6791 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6792 struct dwo_file
*dwo_file
,
6793 dwarf2_section_info
*section
, htab_t
&types_htab
,
6794 rcuh_kind section_kind
)
6796 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6797 struct dwarf2_section_info
*abbrev_section
;
6799 const gdb_byte
*info_ptr
, *end_ptr
;
6801 abbrev_section
= (dwo_file
!= NULL
6802 ? &dwo_file
->sections
.abbrev
6803 : &dwarf2_per_objfile
->abbrev
);
6805 if (dwarf_read_debug
)
6806 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6807 get_section_name (section
),
6808 get_section_file_name (abbrev_section
));
6810 dwarf2_read_section (objfile
, section
);
6811 info_ptr
= section
->buffer
;
6813 if (info_ptr
== NULL
)
6816 /* We can't set abfd until now because the section may be empty or
6817 not present, in which case the bfd is unknown. */
6818 abfd
= get_section_bfd_owner (section
);
6820 /* We don't use cutu_reader here because we don't need to read
6821 any dies: the signature is in the header. */
6823 end_ptr
= info_ptr
+ section
->size
;
6824 while (info_ptr
< end_ptr
)
6826 struct signatured_type
*sig_type
;
6827 struct dwo_unit
*dwo_tu
;
6829 const gdb_byte
*ptr
= info_ptr
;
6830 struct comp_unit_head header
;
6831 unsigned int length
;
6833 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6835 /* Initialize it due to a false compiler warning. */
6836 header
.signature
= -1;
6837 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6839 /* We need to read the type's signature in order to build the hash
6840 table, but we don't need anything else just yet. */
6842 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
6843 abbrev_section
, ptr
, section_kind
);
6845 length
= get_cu_length (&header
);
6847 /* Skip dummy type units. */
6848 if (ptr
>= info_ptr
+ length
6849 || peek_abbrev_code (abfd
, ptr
) == 0
6850 || header
.unit_type
!= DW_UT_type
)
6856 if (types_htab
== NULL
)
6859 types_htab
= allocate_dwo_unit_table (objfile
);
6861 types_htab
= allocate_signatured_type_table (objfile
);
6867 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6869 dwo_tu
->dwo_file
= dwo_file
;
6870 dwo_tu
->signature
= header
.signature
;
6871 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6872 dwo_tu
->section
= section
;
6873 dwo_tu
->sect_off
= sect_off
;
6874 dwo_tu
->length
= length
;
6878 /* N.B.: type_offset is not usable if this type uses a DWO file.
6879 The real type_offset is in the DWO file. */
6881 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6882 struct signatured_type
);
6883 sig_type
->signature
= header
.signature
;
6884 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6885 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6886 sig_type
->per_cu
.is_debug_types
= 1;
6887 sig_type
->per_cu
.section
= section
;
6888 sig_type
->per_cu
.sect_off
= sect_off
;
6889 sig_type
->per_cu
.length
= length
;
6892 slot
= htab_find_slot (types_htab
,
6893 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6895 gdb_assert (slot
!= NULL
);
6898 sect_offset dup_sect_off
;
6902 const struct dwo_unit
*dup_tu
6903 = (const struct dwo_unit
*) *slot
;
6905 dup_sect_off
= dup_tu
->sect_off
;
6909 const struct signatured_type
*dup_tu
6910 = (const struct signatured_type
*) *slot
;
6912 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6915 complaint (_("debug type entry at offset %s is duplicate to"
6916 " the entry at offset %s, signature %s"),
6917 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6918 hex_string (header
.signature
));
6920 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6922 if (dwarf_read_debug
> 1)
6923 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6924 sect_offset_str (sect_off
),
6925 hex_string (header
.signature
));
6931 /* Create the hash table of all entries in the .debug_types
6932 (or .debug_types.dwo) section(s).
6933 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6934 otherwise it is NULL.
6936 The result is a pointer to the hash table or NULL if there are no types.
6938 Note: This function processes DWO files only, not DWP files. */
6941 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6942 struct dwo_file
*dwo_file
,
6943 gdb::array_view
<dwarf2_section_info
> type_sections
,
6946 for (dwarf2_section_info
§ion
: type_sections
)
6947 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, §ion
,
6948 types_htab
, rcuh_kind::TYPE
);
6951 /* Create the hash table of all entries in the .debug_types section,
6952 and initialize all_type_units.
6953 The result is zero if there is an error (e.g. missing .debug_types section),
6954 otherwise non-zero. */
6957 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6959 htab_t types_htab
= NULL
;
6961 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
6962 &dwarf2_per_objfile
->info
, types_htab
,
6963 rcuh_kind::COMPILE
);
6964 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
6965 dwarf2_per_objfile
->types
, types_htab
);
6966 if (types_htab
== NULL
)
6968 dwarf2_per_objfile
->signatured_types
= NULL
;
6972 dwarf2_per_objfile
->signatured_types
= types_htab
;
6974 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
6975 dwarf2_per_objfile
->all_type_units
.reserve (htab_elements (types_htab
));
6977 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
,
6978 &dwarf2_per_objfile
->all_type_units
);
6983 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
6984 If SLOT is non-NULL, it is the entry to use in the hash table.
6985 Otherwise we find one. */
6987 static struct signatured_type
*
6988 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
6991 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6993 if (dwarf2_per_objfile
->all_type_units
.size ()
6994 == dwarf2_per_objfile
->all_type_units
.capacity ())
6995 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
6997 signatured_type
*sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6998 struct signatured_type
);
7000 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
7001 sig_type
->signature
= sig
;
7002 sig_type
->per_cu
.is_debug_types
= 1;
7003 if (dwarf2_per_objfile
->using_index
)
7005 sig_type
->per_cu
.v
.quick
=
7006 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7007 struct dwarf2_per_cu_quick_data
);
7012 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
7015 gdb_assert (*slot
== NULL
);
7017 /* The rest of sig_type must be filled in by the caller. */
7021 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
7022 Fill in SIG_ENTRY with DWO_ENTRY. */
7025 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
7026 struct signatured_type
*sig_entry
,
7027 struct dwo_unit
*dwo_entry
)
7029 /* Make sure we're not clobbering something we don't expect to. */
7030 gdb_assert (! sig_entry
->per_cu
.queued
);
7031 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
7032 if (dwarf2_per_objfile
->using_index
)
7034 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
7035 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
7038 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
7039 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
7040 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
7041 gdb_assert (sig_entry
->type_unit_group
== NULL
);
7042 gdb_assert (sig_entry
->dwo_unit
== NULL
);
7044 sig_entry
->per_cu
.section
= dwo_entry
->section
;
7045 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
7046 sig_entry
->per_cu
.length
= dwo_entry
->length
;
7047 sig_entry
->per_cu
.reading_dwo_directly
= 1;
7048 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
7049 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
7050 sig_entry
->dwo_unit
= dwo_entry
;
7053 /* Subroutine of lookup_signatured_type.
7054 If we haven't read the TU yet, create the signatured_type data structure
7055 for a TU to be read in directly from a DWO file, bypassing the stub.
7056 This is the "Stay in DWO Optimization": When there is no DWP file and we're
7057 using .gdb_index, then when reading a CU we want to stay in the DWO file
7058 containing that CU. Otherwise we could end up reading several other DWO
7059 files (due to comdat folding) to process the transitive closure of all the
7060 mentioned TUs, and that can be slow. The current DWO file will have every
7061 type signature that it needs.
7062 We only do this for .gdb_index because in the psymtab case we already have
7063 to read all the DWOs to build the type unit groups. */
7065 static struct signatured_type
*
7066 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7068 struct dwarf2_per_objfile
*dwarf2_per_objfile
7069 = cu
->per_cu
->dwarf2_per_objfile
;
7070 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7071 struct dwo_file
*dwo_file
;
7072 struct dwo_unit find_dwo_entry
, *dwo_entry
;
7073 struct signatured_type find_sig_entry
, *sig_entry
;
7076 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
7078 /* If TU skeletons have been removed then we may not have read in any
7080 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7082 dwarf2_per_objfile
->signatured_types
7083 = allocate_signatured_type_table (objfile
);
7086 /* We only ever need to read in one copy of a signatured type.
7087 Use the global signatured_types array to do our own comdat-folding
7088 of types. If this is the first time we're reading this TU, and
7089 the TU has an entry in .gdb_index, replace the recorded data from
7090 .gdb_index with this TU. */
7092 find_sig_entry
.signature
= sig
;
7093 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
7094 &find_sig_entry
, INSERT
);
7095 sig_entry
= (struct signatured_type
*) *slot
;
7097 /* We can get here with the TU already read, *or* in the process of being
7098 read. Don't reassign the global entry to point to this DWO if that's
7099 the case. Also note that if the TU is already being read, it may not
7100 have come from a DWO, the program may be a mix of Fission-compiled
7101 code and non-Fission-compiled code. */
7103 /* Have we already tried to read this TU?
7104 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
7105 needn't exist in the global table yet). */
7106 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
7109 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
7110 dwo_unit of the TU itself. */
7111 dwo_file
= cu
->dwo_unit
->dwo_file
;
7113 /* Ok, this is the first time we're reading this TU. */
7114 if (dwo_file
->tus
== NULL
)
7116 find_dwo_entry
.signature
= sig
;
7117 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_entry
);
7118 if (dwo_entry
== NULL
)
7121 /* If the global table doesn't have an entry for this TU, add one. */
7122 if (sig_entry
== NULL
)
7123 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
7125 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
7126 sig_entry
->per_cu
.tu_read
= 1;
7130 /* Subroutine of lookup_signatured_type.
7131 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
7132 then try the DWP file. If the TU stub (skeleton) has been removed then
7133 it won't be in .gdb_index. */
7135 static struct signatured_type
*
7136 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7138 struct dwarf2_per_objfile
*dwarf2_per_objfile
7139 = cu
->per_cu
->dwarf2_per_objfile
;
7140 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7141 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
7142 struct dwo_unit
*dwo_entry
;
7143 struct signatured_type find_sig_entry
, *sig_entry
;
7146 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
7147 gdb_assert (dwp_file
!= NULL
);
7149 /* If TU skeletons have been removed then we may not have read in any
7151 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7153 dwarf2_per_objfile
->signatured_types
7154 = allocate_signatured_type_table (objfile
);
7157 find_sig_entry
.signature
= sig
;
7158 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
7159 &find_sig_entry
, INSERT
);
7160 sig_entry
= (struct signatured_type
*) *slot
;
7162 /* Have we already tried to read this TU?
7163 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
7164 needn't exist in the global table yet). */
7165 if (sig_entry
!= NULL
)
7168 if (dwp_file
->tus
== NULL
)
7170 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
7171 sig
, 1 /* is_debug_types */);
7172 if (dwo_entry
== NULL
)
7175 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
7176 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
7181 /* Lookup a signature based type for DW_FORM_ref_sig8.
7182 Returns NULL if signature SIG is not present in the table.
7183 It is up to the caller to complain about this. */
7185 static struct signatured_type
*
7186 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7188 struct dwarf2_per_objfile
*dwarf2_per_objfile
7189 = cu
->per_cu
->dwarf2_per_objfile
;
7192 && dwarf2_per_objfile
->using_index
)
7194 /* We're in a DWO/DWP file, and we're using .gdb_index.
7195 These cases require special processing. */
7196 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
7197 return lookup_dwo_signatured_type (cu
, sig
);
7199 return lookup_dwp_signatured_type (cu
, sig
);
7203 struct signatured_type find_entry
, *entry
;
7205 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7207 find_entry
.signature
= sig
;
7208 entry
= ((struct signatured_type
*)
7209 htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
));
7214 /* Return the address base of the compile unit, which, if exists, is stored
7215 either at the attribute DW_AT_GNU_addr_base, or DW_AT_addr_base. */
7216 static gdb::optional
<ULONGEST
>
7217 lookup_addr_base (struct die_info
*comp_unit_die
)
7219 struct attribute
*attr
;
7220 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_addr_base
);
7221 if (attr
== nullptr)
7222 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_GNU_addr_base
);
7223 if (attr
== nullptr)
7224 return gdb::optional
<ULONGEST
> ();
7225 return DW_UNSND (attr
);
7228 /* Return range lists base of the compile unit, which, if exists, is stored
7229 either at the attribute DW_AT_rnglists_base or DW_AT_GNU_ranges_base. */
7231 lookup_ranges_base (struct die_info
*comp_unit_die
)
7233 struct attribute
*attr
;
7234 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_rnglists_base
);
7235 if (attr
== nullptr)
7236 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_GNU_ranges_base
);
7237 if (attr
== nullptr)
7239 return DW_UNSND (attr
);
7242 /* Low level DIE reading support. */
7244 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
7247 init_cu_die_reader (struct die_reader_specs
*reader
,
7248 struct dwarf2_cu
*cu
,
7249 struct dwarf2_section_info
*section
,
7250 struct dwo_file
*dwo_file
,
7251 struct abbrev_table
*abbrev_table
)
7253 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
7254 reader
->abfd
= get_section_bfd_owner (section
);
7256 reader
->dwo_file
= dwo_file
;
7257 reader
->die_section
= section
;
7258 reader
->buffer
= section
->buffer
;
7259 reader
->buffer_end
= section
->buffer
+ section
->size
;
7260 reader
->comp_dir
= NULL
;
7261 reader
->abbrev_table
= abbrev_table
;
7264 /* Subroutine of cutu_reader to simplify it.
7265 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
7266 There's just a lot of work to do, and cutu_reader is big enough
7269 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
7270 from it to the DIE in the DWO. If NULL we are skipping the stub.
7271 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
7272 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
7273 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
7274 STUB_COMP_DIR may be non-NULL.
7275 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE,*RESULT_HAS_CHILDREN
7276 are filled in with the info of the DIE from the DWO file.
7277 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
7278 from the dwo. Since *RESULT_READER references this abbrev table, it must be
7279 kept around for at least as long as *RESULT_READER.
7281 The result is non-zero if a valid (non-dummy) DIE was found. */
7284 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
7285 struct dwo_unit
*dwo_unit
,
7286 struct die_info
*stub_comp_unit_die
,
7287 const char *stub_comp_dir
,
7288 struct die_reader_specs
*result_reader
,
7289 const gdb_byte
**result_info_ptr
,
7290 struct die_info
**result_comp_unit_die
,
7291 int *result_has_children
,
7292 abbrev_table_up
*result_dwo_abbrev_table
)
7294 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7295 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7296 struct dwarf2_cu
*cu
= this_cu
->cu
;
7298 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7299 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
7300 int i
,num_extra_attrs
;
7301 struct dwarf2_section_info
*dwo_abbrev_section
;
7302 struct die_info
*comp_unit_die
;
7304 /* At most one of these may be provided. */
7305 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
7307 /* These attributes aren't processed until later:
7308 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
7309 DW_AT_comp_dir is used now, to find the DWO file, but it is also
7310 referenced later. However, these attributes are found in the stub
7311 which we won't have later. In order to not impose this complication
7312 on the rest of the code, we read them here and copy them to the
7321 if (stub_comp_unit_die
!= NULL
)
7323 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
7325 if (! this_cu
->is_debug_types
)
7326 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
7327 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
7328 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
7329 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
7330 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
7332 cu
->addr_base
= lookup_addr_base (stub_comp_unit_die
);
7334 /* There should be a DW_AT_rnglists_base (DW_AT_GNU_ranges_base) attribute
7335 here (if needed). We need the value before we can process
7337 cu
->ranges_base
= lookup_ranges_base (stub_comp_unit_die
);
7339 else if (stub_comp_dir
!= NULL
)
7341 /* Reconstruct the comp_dir attribute to simplify the code below. */
7342 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
7343 comp_dir
->name
= DW_AT_comp_dir
;
7344 comp_dir
->form
= DW_FORM_string
;
7345 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
7346 DW_STRING (comp_dir
) = stub_comp_dir
;
7349 /* Set up for reading the DWO CU/TU. */
7350 cu
->dwo_unit
= dwo_unit
;
7351 dwarf2_section_info
*section
= dwo_unit
->section
;
7352 dwarf2_read_section (objfile
, section
);
7353 abfd
= get_section_bfd_owner (section
);
7354 begin_info_ptr
= info_ptr
= (section
->buffer
7355 + to_underlying (dwo_unit
->sect_off
));
7356 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
7358 if (this_cu
->is_debug_types
)
7360 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
7362 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7363 &cu
->header
, section
,
7365 info_ptr
, rcuh_kind::TYPE
);
7366 /* This is not an assert because it can be caused by bad debug info. */
7367 if (sig_type
->signature
!= cu
->header
.signature
)
7369 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
7370 " TU at offset %s [in module %s]"),
7371 hex_string (sig_type
->signature
),
7372 hex_string (cu
->header
.signature
),
7373 sect_offset_str (dwo_unit
->sect_off
),
7374 bfd_get_filename (abfd
));
7376 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7377 /* For DWOs coming from DWP files, we don't know the CU length
7378 nor the type's offset in the TU until now. */
7379 dwo_unit
->length
= get_cu_length (&cu
->header
);
7380 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
7382 /* Establish the type offset that can be used to lookup the type.
7383 For DWO files, we don't know it until now. */
7384 sig_type
->type_offset_in_section
7385 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
7389 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7390 &cu
->header
, section
,
7392 info_ptr
, rcuh_kind::COMPILE
);
7393 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7394 /* For DWOs coming from DWP files, we don't know the CU length
7396 dwo_unit
->length
= get_cu_length (&cu
->header
);
7399 *result_dwo_abbrev_table
7400 = abbrev_table_read_table (dwarf2_per_objfile
, dwo_abbrev_section
,
7401 cu
->header
.abbrev_sect_off
);
7402 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
7403 result_dwo_abbrev_table
->get ());
7405 /* Read in the die, but leave space to copy over the attributes
7406 from the stub. This has the benefit of simplifying the rest of
7407 the code - all the work to maintain the illusion of a single
7408 DW_TAG_{compile,type}_unit DIE is done here. */
7409 num_extra_attrs
= ((stmt_list
!= NULL
)
7413 + (comp_dir
!= NULL
));
7414 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
7415 result_has_children
, num_extra_attrs
);
7417 /* Copy over the attributes from the stub to the DIE we just read in. */
7418 comp_unit_die
= *result_comp_unit_die
;
7419 i
= comp_unit_die
->num_attrs
;
7420 if (stmt_list
!= NULL
)
7421 comp_unit_die
->attrs
[i
++] = *stmt_list
;
7423 comp_unit_die
->attrs
[i
++] = *low_pc
;
7424 if (high_pc
!= NULL
)
7425 comp_unit_die
->attrs
[i
++] = *high_pc
;
7427 comp_unit_die
->attrs
[i
++] = *ranges
;
7428 if (comp_dir
!= NULL
)
7429 comp_unit_die
->attrs
[i
++] = *comp_dir
;
7430 comp_unit_die
->num_attrs
+= num_extra_attrs
;
7432 if (dwarf_die_debug
)
7434 fprintf_unfiltered (gdb_stdlog
,
7435 "Read die from %s@0x%x of %s:\n",
7436 get_section_name (section
),
7437 (unsigned) (begin_info_ptr
- section
->buffer
),
7438 bfd_get_filename (abfd
));
7439 dump_die (comp_unit_die
, dwarf_die_debug
);
7442 /* Save the comp_dir attribute. If there is no DWP file then we'll read
7443 TUs by skipping the stub and going directly to the entry in the DWO file.
7444 However, skipping the stub means we won't get DW_AT_comp_dir, so we have
7445 to get it via circuitous means. Blech. */
7446 if (comp_dir
!= NULL
)
7447 result_reader
->comp_dir
= DW_STRING (comp_dir
);
7449 /* Skip dummy compilation units. */
7450 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
7451 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7454 *result_info_ptr
= info_ptr
;
7458 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
7459 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
7460 signature is part of the header. */
7461 static gdb::optional
<ULONGEST
>
7462 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
7464 if (cu
->header
.version
>= 5)
7465 return cu
->header
.signature
;
7466 struct attribute
*attr
;
7467 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
7468 if (attr
== nullptr)
7469 return gdb::optional
<ULONGEST
> ();
7470 return DW_UNSND (attr
);
7473 /* Subroutine of cutu_reader to simplify it.
7474 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
7475 Returns NULL if the specified DWO unit cannot be found. */
7477 static struct dwo_unit
*
7478 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
7479 struct die_info
*comp_unit_die
,
7480 const char *dwo_name
)
7482 struct dwarf2_cu
*cu
= this_cu
->cu
;
7483 struct dwo_unit
*dwo_unit
;
7484 const char *comp_dir
;
7486 gdb_assert (cu
!= NULL
);
7488 /* Yeah, we look dwo_name up again, but it simplifies the code. */
7489 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7490 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7492 if (this_cu
->is_debug_types
)
7494 struct signatured_type
*sig_type
;
7496 /* Since this_cu is the first member of struct signatured_type,
7497 we can go from a pointer to one to a pointer to the other. */
7498 sig_type
= (struct signatured_type
*) this_cu
;
7499 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
7503 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
7504 if (!signature
.has_value ())
7505 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
7507 dwo_name
, objfile_name (this_cu
->dwarf2_per_objfile
->objfile
));
7508 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
7515 /* Subroutine of cutu_reader to simplify it.
7516 See it for a description of the parameters.
7517 Read a TU directly from a DWO file, bypassing the stub. */
7520 cutu_reader::init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
7521 int use_existing_cu
, int keep
)
7523 struct signatured_type
*sig_type
;
7524 struct die_reader_specs reader
;
7526 /* Verify we can do the following downcast, and that we have the
7528 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
7529 sig_type
= (struct signatured_type
*) this_cu
;
7530 gdb_assert (sig_type
->dwo_unit
!= NULL
);
7532 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7534 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
7535 /* There's no need to do the rereading_dwo_cu handling that
7536 cutu_reader does since we don't read the stub. */
7540 /* If !use_existing_cu, this_cu->cu must be NULL. */
7541 gdb_assert (this_cu
->cu
== NULL
);
7542 m_new_cu
.reset (new dwarf2_cu (this_cu
));
7545 /* A future optimization, if needed, would be to use an existing
7546 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
7547 could share abbrev tables. */
7549 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
7550 NULL
/* stub_comp_unit_die */,
7551 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
7553 &comp_unit_die
, &has_children
,
7554 &m_dwo_abbrev_table
) == 0)
7561 /* Initialize a CU (or TU) and read its DIEs.
7562 If the CU defers to a DWO file, read the DWO file as well.
7564 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
7565 Otherwise the table specified in the comp unit header is read in and used.
7566 This is an optimization for when we already have the abbrev table.
7568 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
7569 Otherwise, a new CU is allocated with xmalloc.
7571 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
7572 read_in_chain. Otherwise the dwarf2_cu data is freed at the
7575 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
7576 struct abbrev_table
*abbrev_table
,
7577 int use_existing_cu
, int keep
,
7579 : die_reader_specs
{},
7580 m_this_cu (this_cu
),
7583 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7584 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7585 struct dwarf2_section_info
*section
= this_cu
->section
;
7586 bfd
*abfd
= get_section_bfd_owner (section
);
7587 struct dwarf2_cu
*cu
;
7588 const gdb_byte
*begin_info_ptr
;
7589 struct signatured_type
*sig_type
= NULL
;
7590 struct dwarf2_section_info
*abbrev_section
;
7591 /* Non-zero if CU currently points to a DWO file and we need to
7592 reread it. When this happens we need to reread the skeleton die
7593 before we can reread the DWO file (this only applies to CUs, not TUs). */
7594 int rereading_dwo_cu
= 0;
7596 if (dwarf_die_debug
)
7597 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7598 this_cu
->is_debug_types
? "type" : "comp",
7599 sect_offset_str (this_cu
->sect_off
));
7601 if (use_existing_cu
)
7604 /* If we're reading a TU directly from a DWO file, including a virtual DWO
7605 file (instead of going through the stub), short-circuit all of this. */
7606 if (this_cu
->reading_dwo_directly
)
7608 /* Narrow down the scope of possibilities to have to understand. */
7609 gdb_assert (this_cu
->is_debug_types
);
7610 gdb_assert (abbrev_table
== NULL
);
7611 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
, keep
);
7615 /* This is cheap if the section is already read in. */
7616 dwarf2_read_section (objfile
, section
);
7618 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7620 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
7622 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7625 /* If this CU is from a DWO file we need to start over, we need to
7626 refetch the attributes from the skeleton CU.
7627 This could be optimized by retrieving those attributes from when we
7628 were here the first time: the previous comp_unit_die was stored in
7629 comp_unit_obstack. But there's no data yet that we need this
7631 if (cu
->dwo_unit
!= NULL
)
7632 rereading_dwo_cu
= 1;
7636 /* If !use_existing_cu, this_cu->cu must be NULL. */
7637 gdb_assert (this_cu
->cu
== NULL
);
7638 m_new_cu
.reset (new dwarf2_cu (this_cu
));
7639 cu
= m_new_cu
.get ();
7642 /* Get the header. */
7643 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
7645 /* We already have the header, there's no need to read it in again. */
7646 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
7650 if (this_cu
->is_debug_types
)
7652 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7653 &cu
->header
, section
,
7654 abbrev_section
, info_ptr
,
7657 /* Since per_cu is the first member of struct signatured_type,
7658 we can go from a pointer to one to a pointer to the other. */
7659 sig_type
= (struct signatured_type
*) this_cu
;
7660 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
7661 gdb_assert (sig_type
->type_offset_in_tu
7662 == cu
->header
.type_cu_offset_in_tu
);
7663 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7665 /* LENGTH has not been set yet for type units if we're
7666 using .gdb_index. */
7667 this_cu
->length
= get_cu_length (&cu
->header
);
7669 /* Establish the type offset that can be used to lookup the type. */
7670 sig_type
->type_offset_in_section
=
7671 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
7673 this_cu
->dwarf_version
= cu
->header
.version
;
7677 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7678 &cu
->header
, section
,
7681 rcuh_kind::COMPILE
);
7683 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7684 gdb_assert (this_cu
->length
== get_cu_length (&cu
->header
));
7685 this_cu
->dwarf_version
= cu
->header
.version
;
7689 /* Skip dummy compilation units. */
7690 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7691 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7697 /* If we don't have them yet, read the abbrevs for this compilation unit.
7698 And if we need to read them now, make sure they're freed when we're
7700 if (abbrev_table
!= NULL
)
7701 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
7704 m_abbrev_table_holder
7705 = abbrev_table_read_table (dwarf2_per_objfile
, abbrev_section
,
7706 cu
->header
.abbrev_sect_off
);
7707 abbrev_table
= m_abbrev_table_holder
.get ();
7710 /* Read the top level CU/TU die. */
7711 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
7712 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
, &has_children
);
7714 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
7720 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
7721 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
7722 table from the DWO file and pass the ownership over to us. It will be
7723 referenced from READER, so we must make sure to free it after we're done
7726 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
7727 DWO CU, that this test will fail (the attribute will not be present). */
7728 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7729 if (dwo_name
!= nullptr)
7731 struct dwo_unit
*dwo_unit
;
7732 struct die_info
*dwo_comp_unit_die
;
7736 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
7737 " has children (offset %s) [in module %s]"),
7738 sect_offset_str (this_cu
->sect_off
),
7739 bfd_get_filename (abfd
));
7741 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
, dwo_name
);
7742 if (dwo_unit
!= NULL
)
7744 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
7745 comp_unit_die
, NULL
,
7747 &dwo_comp_unit_die
, &has_children
,
7748 &m_dwo_abbrev_table
) == 0)
7754 comp_unit_die
= dwo_comp_unit_die
;
7758 /* Yikes, we couldn't find the rest of the DIE, we only have
7759 the stub. A complaint has already been logged. There's
7760 not much more we can do except pass on the stub DIE to
7761 die_reader_func. We don't want to throw an error on bad
7767 cutu_reader::~cutu_reader ()
7769 /* Done, clean up. */
7770 if (m_new_cu
!= NULL
&& m_keep
&& !dummy_p
)
7772 struct dwarf2_per_objfile
*dwarf2_per_objfile
7773 = m_this_cu
->dwarf2_per_objfile
;
7774 /* Link this CU into read_in_chain. */
7775 m_this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
7776 dwarf2_per_objfile
->read_in_chain
= m_this_cu
;
7777 /* The chain owns it now. */
7778 m_new_cu
.release ();
7782 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
7783 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
7784 assumed to have already done the lookup to find the DWO file).
7786 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7787 THIS_CU->is_debug_types, but nothing else.
7789 We fill in THIS_CU->length.
7791 THIS_CU->cu is always freed when done.
7792 This is done in order to not leave THIS_CU->cu in a state where we have
7793 to care whether it refers to the "main" CU or the DWO CU.
7795 When parent_cu is passed, it is used to provide a default value for
7796 str_offsets_base and addr_base from the parent. */
7798 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
7799 struct dwarf2_cu
*parent_cu
,
7800 struct dwo_file
*dwo_file
)
7801 : die_reader_specs
{},
7804 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7805 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7806 struct dwarf2_section_info
*section
= this_cu
->section
;
7807 bfd
*abfd
= get_section_bfd_owner (section
);
7808 struct dwarf2_section_info
*abbrev_section
;
7809 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7812 if (dwarf_die_debug
)
7813 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7814 this_cu
->is_debug_types
? "type" : "comp",
7815 sect_offset_str (this_cu
->sect_off
));
7817 gdb_assert (this_cu
->cu
== NULL
);
7819 abbrev_section
= (dwo_file
!= NULL
7820 ? &dwo_file
->sections
.abbrev
7821 : get_abbrev_section_for_cu (this_cu
));
7823 /* This is cheap if the section is already read in. */
7824 dwarf2_read_section (objfile
, section
);
7826 m_new_cu
.reset (new dwarf2_cu (this_cu
));
7828 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7829 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7830 &m_new_cu
->header
, section
,
7831 abbrev_section
, info_ptr
,
7832 (this_cu
->is_debug_types
7834 : rcuh_kind::COMPILE
));
7836 if (parent_cu
!= nullptr)
7838 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
7839 m_new_cu
->addr_base
= parent_cu
->addr_base
;
7841 this_cu
->length
= get_cu_length (&m_new_cu
->header
);
7843 /* Skip dummy compilation units. */
7844 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7845 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7851 m_abbrev_table_holder
7852 = abbrev_table_read_table (dwarf2_per_objfile
, abbrev_section
,
7853 m_new_cu
->header
.abbrev_sect_off
);
7855 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
7856 m_abbrev_table_holder
.get ());
7857 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
, &has_children
);
7861 /* Type Unit Groups.
7863 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7864 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7865 so that all types coming from the same compilation (.o file) are grouped
7866 together. A future step could be to put the types in the same symtab as
7867 the CU the types ultimately came from. */
7870 hash_type_unit_group (const void *item
)
7872 const struct type_unit_group
*tu_group
7873 = (const struct type_unit_group
*) item
;
7875 return hash_stmt_list_entry (&tu_group
->hash
);
7879 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7881 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7882 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7884 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7887 /* Allocate a hash table for type unit groups. */
7890 allocate_type_unit_groups_table (struct objfile
*objfile
)
7892 return htab_create_alloc_ex (3,
7893 hash_type_unit_group
,
7896 &objfile
->objfile_obstack
,
7897 hashtab_obstack_allocate
,
7898 dummy_obstack_deallocate
);
7901 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7902 partial symtabs. We combine several TUs per psymtab to not let the size
7903 of any one psymtab grow too big. */
7904 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7905 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7907 /* Helper routine for get_type_unit_group.
7908 Create the type_unit_group object used to hold one or more TUs. */
7910 static struct type_unit_group
*
7911 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7913 struct dwarf2_per_objfile
*dwarf2_per_objfile
7914 = cu
->per_cu
->dwarf2_per_objfile
;
7915 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7916 struct dwarf2_per_cu_data
*per_cu
;
7917 struct type_unit_group
*tu_group
;
7919 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7920 struct type_unit_group
);
7921 per_cu
= &tu_group
->per_cu
;
7922 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7924 if (dwarf2_per_objfile
->using_index
)
7926 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7927 struct dwarf2_per_cu_quick_data
);
7931 unsigned int line_offset
= to_underlying (line_offset_struct
);
7932 dwarf2_psymtab
*pst
;
7935 /* Give the symtab a useful name for debug purposes. */
7936 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7937 name
= string_printf ("<type_units_%d>",
7938 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7940 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7942 pst
= create_partial_symtab (per_cu
, name
.c_str ());
7943 pst
->anonymous
= true;
7946 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7947 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7952 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7953 STMT_LIST is a DW_AT_stmt_list attribute. */
7955 static struct type_unit_group
*
7956 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7958 struct dwarf2_per_objfile
*dwarf2_per_objfile
7959 = cu
->per_cu
->dwarf2_per_objfile
;
7960 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7961 struct type_unit_group
*tu_group
;
7963 unsigned int line_offset
;
7964 struct type_unit_group type_unit_group_for_lookup
;
7966 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
7968 dwarf2_per_objfile
->type_unit_groups
=
7969 allocate_type_unit_groups_table (dwarf2_per_objfile
->objfile
);
7972 /* Do we need to create a new group, or can we use an existing one? */
7976 line_offset
= DW_UNSND (stmt_list
);
7977 ++tu_stats
->nr_symtab_sharers
;
7981 /* Ugh, no stmt_list. Rare, but we have to handle it.
7982 We can do various things here like create one group per TU or
7983 spread them over multiple groups to split up the expansion work.
7984 To avoid worst case scenarios (too many groups or too large groups)
7985 we, umm, group them in bunches. */
7986 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7987 | (tu_stats
->nr_stmt_less_type_units
7988 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7989 ++tu_stats
->nr_stmt_less_type_units
;
7992 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7993 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7994 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
,
7995 &type_unit_group_for_lookup
, INSERT
);
7998 tu_group
= (struct type_unit_group
*) *slot
;
7999 gdb_assert (tu_group
!= NULL
);
8003 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
8004 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
8006 ++tu_stats
->nr_symtabs
;
8012 /* Partial symbol tables. */
8014 /* Create a psymtab named NAME and assign it to PER_CU.
8016 The caller must fill in the following details:
8017 dirname, textlow, texthigh. */
8019 static dwarf2_psymtab
*
8020 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
8022 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
8023 dwarf2_psymtab
*pst
;
8025 pst
= new dwarf2_psymtab (name
, objfile
, 0);
8027 pst
->psymtabs_addrmap_supported
= true;
8029 /* This is the glue that links PST into GDB's symbol API. */
8030 pst
->per_cu_data
= per_cu
;
8031 per_cu
->v
.psymtab
= pst
;
8036 /* DIE reader function for process_psymtab_comp_unit. */
8039 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
8040 const gdb_byte
*info_ptr
,
8041 struct die_info
*comp_unit_die
,
8043 int want_partial_unit
,
8044 enum language pretend_language
)
8046 struct dwarf2_cu
*cu
= reader
->cu
;
8047 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
8048 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8049 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
8051 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
8052 dwarf2_psymtab
*pst
;
8053 enum pc_bounds_kind cu_bounds_kind
;
8054 const char *filename
;
8056 if (comp_unit_die
->tag
== DW_TAG_partial_unit
&& !want_partial_unit
)
8059 gdb_assert (! per_cu
->is_debug_types
);
8061 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
8063 /* Allocate a new partial symbol table structure. */
8064 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
8065 if (filename
== NULL
)
8068 pst
= create_partial_symtab (per_cu
, filename
);
8070 /* This must be done before calling dwarf2_build_include_psymtabs. */
8071 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
8073 baseaddr
= objfile
->text_section_offset ();
8075 dwarf2_find_base_address (comp_unit_die
, cu
);
8077 /* Possibly set the default values of LOWPC and HIGHPC from
8079 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
8080 &best_highpc
, cu
, pst
);
8081 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
8084 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
8087 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
8089 /* Store the contiguous range if it is not empty; it can be
8090 empty for CUs with no code. */
8091 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8095 /* Check if comp unit has_children.
8096 If so, read the rest of the partial symbols from this comp unit.
8097 If not, there's no more debug_info for this comp unit. */
8100 struct partial_die_info
*first_die
;
8101 CORE_ADDR lowpc
, highpc
;
8103 lowpc
= ((CORE_ADDR
) -1);
8104 highpc
= ((CORE_ADDR
) 0);
8106 first_die
= load_partial_dies (reader
, info_ptr
, 1);
8108 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
8109 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
8111 /* If we didn't find a lowpc, set it to highpc to avoid
8112 complaints from `maint check'. */
8113 if (lowpc
== ((CORE_ADDR
) -1))
8116 /* If the compilation unit didn't have an explicit address range,
8117 then use the information extracted from its child dies. */
8118 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
8121 best_highpc
= highpc
;
8124 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
8125 best_lowpc
+ baseaddr
)
8127 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
8128 best_highpc
+ baseaddr
)
8131 end_psymtab_common (objfile
, pst
);
8133 if (!cu
->per_cu
->imported_symtabs_empty ())
8136 int len
= cu
->per_cu
->imported_symtabs_size ();
8138 /* Fill in 'dependencies' here; we fill in 'users' in a
8140 pst
->number_of_dependencies
= len
;
8142 = objfile
->partial_symtabs
->allocate_dependencies (len
);
8143 for (i
= 0; i
< len
; ++i
)
8145 pst
->dependencies
[i
]
8146 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
8149 cu
->per_cu
->imported_symtabs_free ();
8152 /* Get the list of files included in the current compilation unit,
8153 and build a psymtab for each of them. */
8154 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
8156 if (dwarf_read_debug
)
8157 fprintf_unfiltered (gdb_stdlog
,
8158 "Psymtab for %s unit @%s: %s - %s"
8159 ", %d global, %d static syms\n",
8160 per_cu
->is_debug_types
? "type" : "comp",
8161 sect_offset_str (per_cu
->sect_off
),
8162 paddress (gdbarch
, pst
->text_low (objfile
)),
8163 paddress (gdbarch
, pst
->text_high (objfile
)),
8164 pst
->n_global_syms
, pst
->n_static_syms
);
8167 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8168 Process compilation unit THIS_CU for a psymtab. */
8171 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8172 int want_partial_unit
,
8173 enum language pretend_language
)
8175 /* If this compilation unit was already read in, free the
8176 cached copy in order to read it in again. This is
8177 necessary because we skipped some symbols when we first
8178 read in the compilation unit (see load_partial_dies).
8179 This problem could be avoided, but the benefit is unclear. */
8180 if (this_cu
->cu
!= NULL
)
8181 free_one_cached_comp_unit (this_cu
);
8183 cutu_reader
reader (this_cu
, NULL
, 0, 0, false);
8189 else if (this_cu
->is_debug_types
)
8190 build_type_psymtabs_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
8191 reader
.has_children
);
8193 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
8194 reader
.comp_unit_die
,
8195 reader
.has_children
,
8199 /* Age out any secondary CUs. */
8200 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
8203 /* Reader function for build_type_psymtabs. */
8206 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
8207 const gdb_byte
*info_ptr
,
8208 struct die_info
*type_unit_die
,
8211 struct dwarf2_per_objfile
*dwarf2_per_objfile
8212 = reader
->cu
->per_cu
->dwarf2_per_objfile
;
8213 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8214 struct dwarf2_cu
*cu
= reader
->cu
;
8215 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
8216 struct signatured_type
*sig_type
;
8217 struct type_unit_group
*tu_group
;
8218 struct attribute
*attr
;
8219 struct partial_die_info
*first_die
;
8220 CORE_ADDR lowpc
, highpc
;
8221 dwarf2_psymtab
*pst
;
8223 gdb_assert (per_cu
->is_debug_types
);
8224 sig_type
= (struct signatured_type
*) per_cu
;
8229 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
8230 tu_group
= get_type_unit_group (cu
, attr
);
8232 if (tu_group
->tus
== nullptr)
8233 tu_group
->tus
= new std::vector
<signatured_type
*>;
8234 tu_group
->tus
->push_back (sig_type
);
8236 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
8237 pst
= create_partial_symtab (per_cu
, "");
8238 pst
->anonymous
= true;
8240 first_die
= load_partial_dies (reader
, info_ptr
, 1);
8242 lowpc
= (CORE_ADDR
) -1;
8243 highpc
= (CORE_ADDR
) 0;
8244 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
8246 end_psymtab_common (objfile
, pst
);
8249 /* Struct used to sort TUs by their abbreviation table offset. */
8251 struct tu_abbrev_offset
8253 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
8254 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
8257 signatured_type
*sig_type
;
8258 sect_offset abbrev_offset
;
8261 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
8264 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
8265 const struct tu_abbrev_offset
&b
)
8267 return a
.abbrev_offset
< b
.abbrev_offset
;
8270 /* Efficiently read all the type units.
8271 This does the bulk of the work for build_type_psymtabs.
8273 The efficiency is because we sort TUs by the abbrev table they use and
8274 only read each abbrev table once. In one program there are 200K TUs
8275 sharing 8K abbrev tables.
8277 The main purpose of this function is to support building the
8278 dwarf2_per_objfile->type_unit_groups table.
8279 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
8280 can collapse the search space by grouping them by stmt_list.
8281 The savings can be significant, in the same program from above the 200K TUs
8282 share 8K stmt_list tables.
8284 FUNC is expected to call get_type_unit_group, which will create the
8285 struct type_unit_group if necessary and add it to
8286 dwarf2_per_objfile->type_unit_groups. */
8289 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8291 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8292 abbrev_table_up abbrev_table
;
8293 sect_offset abbrev_offset
;
8295 /* It's up to the caller to not call us multiple times. */
8296 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
8298 if (dwarf2_per_objfile
->all_type_units
.empty ())
8301 /* TUs typically share abbrev tables, and there can be way more TUs than
8302 abbrev tables. Sort by abbrev table to reduce the number of times we
8303 read each abbrev table in.
8304 Alternatives are to punt or to maintain a cache of abbrev tables.
8305 This is simpler and efficient enough for now.
8307 Later we group TUs by their DW_AT_stmt_list value (as this defines the
8308 symtab to use). Typically TUs with the same abbrev offset have the same
8309 stmt_list value too so in practice this should work well.
8311 The basic algorithm here is:
8313 sort TUs by abbrev table
8314 for each TU with same abbrev table:
8315 read abbrev table if first user
8316 read TU top level DIE
8317 [IWBN if DWO skeletons had DW_AT_stmt_list]
8320 if (dwarf_read_debug
)
8321 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
8323 /* Sort in a separate table to maintain the order of all_type_units
8324 for .gdb_index: TU indices directly index all_type_units. */
8325 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
8326 sorted_by_abbrev
.reserve (dwarf2_per_objfile
->all_type_units
.size ());
8328 for (signatured_type
*sig_type
: dwarf2_per_objfile
->all_type_units
)
8329 sorted_by_abbrev
.emplace_back
8330 (sig_type
, read_abbrev_offset (dwarf2_per_objfile
,
8331 sig_type
->per_cu
.section
,
8332 sig_type
->per_cu
.sect_off
));
8334 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
8335 sort_tu_by_abbrev_offset
);
8337 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
8339 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
8341 /* Switch to the next abbrev table if necessary. */
8342 if (abbrev_table
== NULL
8343 || tu
.abbrev_offset
!= abbrev_offset
)
8345 abbrev_offset
= tu
.abbrev_offset
;
8347 abbrev_table_read_table (dwarf2_per_objfile
,
8348 &dwarf2_per_objfile
->abbrev
,
8350 ++tu_stats
->nr_uniq_abbrev_tables
;
8353 cutu_reader
reader (&tu
.sig_type
->per_cu
, abbrev_table
.get (),
8355 if (!reader
.dummy_p
)
8356 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
8357 reader
.comp_unit_die
,
8358 reader
.has_children
);
8362 /* Print collected type unit statistics. */
8365 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8367 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8369 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
8370 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
8371 dwarf2_per_objfile
->all_type_units
.size ());
8372 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
8373 tu_stats
->nr_uniq_abbrev_tables
);
8374 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
8375 tu_stats
->nr_symtabs
);
8376 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
8377 tu_stats
->nr_symtab_sharers
);
8378 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
8379 tu_stats
->nr_stmt_less_type_units
);
8380 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
8381 tu_stats
->nr_all_type_units_reallocs
);
8384 /* Traversal function for build_type_psymtabs. */
8387 build_type_psymtab_dependencies (void **slot
, void *info
)
8389 struct dwarf2_per_objfile
*dwarf2_per_objfile
8390 = (struct dwarf2_per_objfile
*) info
;
8391 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8392 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
8393 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
8394 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
8395 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
8398 gdb_assert (len
> 0);
8399 gdb_assert (IS_TYPE_UNIT_GROUP (per_cu
));
8401 pst
->number_of_dependencies
= len
;
8402 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
8403 for (i
= 0; i
< len
; ++i
)
8405 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
8406 gdb_assert (iter
->per_cu
.is_debug_types
);
8407 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
8408 iter
->type_unit_group
= tu_group
;
8411 delete tu_group
->tus
;
8412 tu_group
->tus
= nullptr;
8417 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8418 Build partial symbol tables for the .debug_types comp-units. */
8421 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8423 if (! create_all_type_units (dwarf2_per_objfile
))
8426 build_type_psymtabs_1 (dwarf2_per_objfile
);
8429 /* Traversal function for process_skeletonless_type_unit.
8430 Read a TU in a DWO file and build partial symbols for it. */
8433 process_skeletonless_type_unit (void **slot
, void *info
)
8435 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
8436 struct dwarf2_per_objfile
*dwarf2_per_objfile
8437 = (struct dwarf2_per_objfile
*) info
;
8438 struct signatured_type find_entry
, *entry
;
8440 /* If this TU doesn't exist in the global table, add it and read it in. */
8442 if (dwarf2_per_objfile
->signatured_types
== NULL
)
8444 dwarf2_per_objfile
->signatured_types
8445 = allocate_signatured_type_table (dwarf2_per_objfile
->objfile
);
8448 find_entry
.signature
= dwo_unit
->signature
;
8449 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
, &find_entry
,
8451 /* If we've already seen this type there's nothing to do. What's happening
8452 is we're doing our own version of comdat-folding here. */
8456 /* This does the job that create_all_type_units would have done for
8458 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
8459 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
8462 /* This does the job that build_type_psymtabs_1 would have done. */
8463 cutu_reader
reader (&entry
->per_cu
, NULL
, 0, 0, false);
8464 if (!reader
.dummy_p
)
8465 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
8466 reader
.comp_unit_die
, reader
.has_children
);
8471 /* Traversal function for process_skeletonless_type_units. */
8474 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
8476 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
8478 if (dwo_file
->tus
!= NULL
)
8480 htab_traverse_noresize (dwo_file
->tus
,
8481 process_skeletonless_type_unit
, info
);
8487 /* Scan all TUs of DWO files, verifying we've processed them.
8488 This is needed in case a TU was emitted without its skeleton.
8489 Note: This can't be done until we know what all the DWO files are. */
8492 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8494 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
8495 if (get_dwp_file (dwarf2_per_objfile
) == NULL
8496 && dwarf2_per_objfile
->dwo_files
!= NULL
)
8498 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
.get (),
8499 process_dwo_file_for_skeletonless_type_units
,
8500 dwarf2_per_objfile
);
8504 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
8507 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8509 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
8511 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
8516 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
8518 /* Set the 'user' field only if it is not already set. */
8519 if (pst
->dependencies
[j
]->user
== NULL
)
8520 pst
->dependencies
[j
]->user
= pst
;
8525 /* Build the partial symbol table by doing a quick pass through the
8526 .debug_info and .debug_abbrev sections. */
8529 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8531 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8533 if (dwarf_read_debug
)
8535 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
8536 objfile_name (objfile
));
8539 dwarf2_per_objfile
->reading_partial_symbols
= 1;
8541 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
8543 /* Any cached compilation units will be linked by the per-objfile
8544 read_in_chain. Make sure to free them when we're done. */
8545 free_cached_comp_units
freer (dwarf2_per_objfile
);
8547 build_type_psymtabs (dwarf2_per_objfile
);
8549 create_all_comp_units (dwarf2_per_objfile
);
8551 /* Create a temporary address map on a temporary obstack. We later
8552 copy this to the final obstack. */
8553 auto_obstack temp_obstack
;
8555 scoped_restore save_psymtabs_addrmap
8556 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
8557 addrmap_create_mutable (&temp_obstack
));
8559 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
8560 process_psymtab_comp_unit (per_cu
, 0, language_minimal
);
8562 /* This has to wait until we read the CUs, we need the list of DWOs. */
8563 process_skeletonless_type_units (dwarf2_per_objfile
);
8565 /* Now that all TUs have been processed we can fill in the dependencies. */
8566 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
8568 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
8569 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
8572 if (dwarf_read_debug
)
8573 print_tu_stats (dwarf2_per_objfile
);
8575 set_partial_user (dwarf2_per_objfile
);
8577 objfile
->partial_symtabs
->psymtabs_addrmap
8578 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
8579 objfile
->partial_symtabs
->obstack ());
8580 /* At this point we want to keep the address map. */
8581 save_psymtabs_addrmap
.release ();
8583 if (dwarf_read_debug
)
8584 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
8585 objfile_name (objfile
));
8588 /* Load the partial DIEs for a secondary CU into memory.
8589 This is also used when rereading a primary CU with load_all_dies. */
8592 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
8594 cutu_reader
reader (this_cu
, NULL
, 1, 1, false);
8596 if (!reader
.dummy_p
)
8598 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
8601 /* Check if comp unit has_children.
8602 If so, read the rest of the partial symbols from this comp unit.
8603 If not, there's no more debug_info for this comp unit. */
8604 if (reader
.has_children
)
8605 load_partial_dies (&reader
, reader
.info_ptr
, 0);
8610 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
8611 struct dwarf2_section_info
*section
,
8612 struct dwarf2_section_info
*abbrev_section
,
8613 unsigned int is_dwz
)
8615 const gdb_byte
*info_ptr
;
8616 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8618 if (dwarf_read_debug
)
8619 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
8620 get_section_name (section
),
8621 get_section_file_name (section
));
8623 dwarf2_read_section (objfile
, section
);
8625 info_ptr
= section
->buffer
;
8627 while (info_ptr
< section
->buffer
+ section
->size
)
8629 struct dwarf2_per_cu_data
*this_cu
;
8631 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
8633 comp_unit_head cu_header
;
8634 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
8635 abbrev_section
, info_ptr
,
8636 rcuh_kind::COMPILE
);
8638 /* Save the compilation unit for later lookup. */
8639 if (cu_header
.unit_type
!= DW_UT_type
)
8641 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
8642 struct dwarf2_per_cu_data
);
8643 memset (this_cu
, 0, sizeof (*this_cu
));
8647 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
8648 struct signatured_type
);
8649 memset (sig_type
, 0, sizeof (*sig_type
));
8650 sig_type
->signature
= cu_header
.signature
;
8651 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
8652 this_cu
= &sig_type
->per_cu
;
8654 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
8655 this_cu
->sect_off
= sect_off
;
8656 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
8657 this_cu
->is_dwz
= is_dwz
;
8658 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
8659 this_cu
->section
= section
;
8661 dwarf2_per_objfile
->all_comp_units
.push_back (this_cu
);
8663 info_ptr
= info_ptr
+ this_cu
->length
;
8667 /* Create a list of all compilation units in OBJFILE.
8668 This is only done for -readnow and building partial symtabs. */
8671 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8673 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
8674 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->info
,
8675 &dwarf2_per_objfile
->abbrev
, 0);
8677 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
8679 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
8683 /* Process all loaded DIEs for compilation unit CU, starting at
8684 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
8685 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
8686 DW_AT_ranges). See the comments of add_partial_subprogram on how
8687 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
8690 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
8691 CORE_ADDR
*highpc
, int set_addrmap
,
8692 struct dwarf2_cu
*cu
)
8694 struct partial_die_info
*pdi
;
8696 /* Now, march along the PDI's, descending into ones which have
8697 interesting children but skipping the children of the other ones,
8698 until we reach the end of the compilation unit. */
8706 /* Anonymous namespaces or modules have no name but have interesting
8707 children, so we need to look at them. Ditto for anonymous
8710 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
8711 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
8712 || pdi
->tag
== DW_TAG_imported_unit
8713 || pdi
->tag
== DW_TAG_inlined_subroutine
)
8717 case DW_TAG_subprogram
:
8718 case DW_TAG_inlined_subroutine
:
8719 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8721 case DW_TAG_constant
:
8722 case DW_TAG_variable
:
8723 case DW_TAG_typedef
:
8724 case DW_TAG_union_type
:
8725 if (!pdi
->is_declaration
)
8727 add_partial_symbol (pdi
, cu
);
8730 case DW_TAG_class_type
:
8731 case DW_TAG_interface_type
:
8732 case DW_TAG_structure_type
:
8733 if (!pdi
->is_declaration
)
8735 add_partial_symbol (pdi
, cu
);
8737 if ((cu
->language
== language_rust
8738 || cu
->language
== language_cplus
) && pdi
->has_children
)
8739 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8742 case DW_TAG_enumeration_type
:
8743 if (!pdi
->is_declaration
)
8744 add_partial_enumeration (pdi
, cu
);
8746 case DW_TAG_base_type
:
8747 case DW_TAG_subrange_type
:
8748 /* File scope base type definitions are added to the partial
8750 add_partial_symbol (pdi
, cu
);
8752 case DW_TAG_namespace
:
8753 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8756 if (!pdi
->is_declaration
)
8757 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8759 case DW_TAG_imported_unit
:
8761 struct dwarf2_per_cu_data
*per_cu
;
8763 /* For now we don't handle imported units in type units. */
8764 if (cu
->per_cu
->is_debug_types
)
8766 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8767 " supported in type units [in module %s]"),
8768 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
8771 per_cu
= dwarf2_find_containing_comp_unit
8772 (pdi
->d
.sect_off
, pdi
->is_dwz
,
8773 cu
->per_cu
->dwarf2_per_objfile
);
8775 /* Go read the partial unit, if needed. */
8776 if (per_cu
->v
.psymtab
== NULL
)
8777 process_psymtab_comp_unit (per_cu
, 1, cu
->language
);
8779 cu
->per_cu
->imported_symtabs_push (per_cu
);
8782 case DW_TAG_imported_declaration
:
8783 add_partial_symbol (pdi
, cu
);
8790 /* If the die has a sibling, skip to the sibling. */
8792 pdi
= pdi
->die_sibling
;
8796 /* Functions used to compute the fully scoped name of a partial DIE.
8798 Normally, this is simple. For C++, the parent DIE's fully scoped
8799 name is concatenated with "::" and the partial DIE's name.
8800 Enumerators are an exception; they use the scope of their parent
8801 enumeration type, i.e. the name of the enumeration type is not
8802 prepended to the enumerator.
8804 There are two complexities. One is DW_AT_specification; in this
8805 case "parent" means the parent of the target of the specification,
8806 instead of the direct parent of the DIE. The other is compilers
8807 which do not emit DW_TAG_namespace; in this case we try to guess
8808 the fully qualified name of structure types from their members'
8809 linkage names. This must be done using the DIE's children rather
8810 than the children of any DW_AT_specification target. We only need
8811 to do this for structures at the top level, i.e. if the target of
8812 any DW_AT_specification (if any; otherwise the DIE itself) does not
8815 /* Compute the scope prefix associated with PDI's parent, in
8816 compilation unit CU. The result will be allocated on CU's
8817 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8818 field. NULL is returned if no prefix is necessary. */
8820 partial_die_parent_scope (struct partial_die_info
*pdi
,
8821 struct dwarf2_cu
*cu
)
8823 const char *grandparent_scope
;
8824 struct partial_die_info
*parent
, *real_pdi
;
8826 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8827 then this means the parent of the specification DIE. */
8830 while (real_pdi
->has_specification
)
8832 auto res
= find_partial_die (real_pdi
->spec_offset
,
8833 real_pdi
->spec_is_dwz
, cu
);
8838 parent
= real_pdi
->die_parent
;
8842 if (parent
->scope_set
)
8843 return parent
->scope
;
8847 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8849 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8850 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8851 Work around this problem here. */
8852 if (cu
->language
== language_cplus
8853 && parent
->tag
== DW_TAG_namespace
8854 && strcmp (parent
->name
, "::") == 0
8855 && grandparent_scope
== NULL
)
8857 parent
->scope
= NULL
;
8858 parent
->scope_set
= 1;
8862 /* Nested subroutines in Fortran get a prefix. */
8863 if (pdi
->tag
== DW_TAG_enumerator
)
8864 /* Enumerators should not get the name of the enumeration as a prefix. */
8865 parent
->scope
= grandparent_scope
;
8866 else if (parent
->tag
== DW_TAG_namespace
8867 || parent
->tag
== DW_TAG_module
8868 || parent
->tag
== DW_TAG_structure_type
8869 || parent
->tag
== DW_TAG_class_type
8870 || parent
->tag
== DW_TAG_interface_type
8871 || parent
->tag
== DW_TAG_union_type
8872 || parent
->tag
== DW_TAG_enumeration_type
8873 || (cu
->language
== language_fortran
8874 && parent
->tag
== DW_TAG_subprogram
8875 && pdi
->tag
== DW_TAG_subprogram
))
8877 if (grandparent_scope
== NULL
)
8878 parent
->scope
= parent
->name
;
8880 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8882 parent
->name
, 0, cu
);
8886 /* FIXME drow/2004-04-01: What should we be doing with
8887 function-local names? For partial symbols, we should probably be
8889 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8890 dwarf_tag_name (parent
->tag
),
8891 sect_offset_str (pdi
->sect_off
));
8892 parent
->scope
= grandparent_scope
;
8895 parent
->scope_set
= 1;
8896 return parent
->scope
;
8899 /* Return the fully scoped name associated with PDI, from compilation unit
8900 CU. The result will be allocated with malloc. */
8902 static gdb::unique_xmalloc_ptr
<char>
8903 partial_die_full_name (struct partial_die_info
*pdi
,
8904 struct dwarf2_cu
*cu
)
8906 const char *parent_scope
;
8908 /* If this is a template instantiation, we can not work out the
8909 template arguments from partial DIEs. So, unfortunately, we have
8910 to go through the full DIEs. At least any work we do building
8911 types here will be reused if full symbols are loaded later. */
8912 if (pdi
->has_template_arguments
)
8916 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
8918 struct die_info
*die
;
8919 struct attribute attr
;
8920 struct dwarf2_cu
*ref_cu
= cu
;
8922 /* DW_FORM_ref_addr is using section offset. */
8923 attr
.name
= (enum dwarf_attribute
) 0;
8924 attr
.form
= DW_FORM_ref_addr
;
8925 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8926 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8928 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8932 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8933 if (parent_scope
== NULL
)
8936 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8941 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8943 struct dwarf2_per_objfile
*dwarf2_per_objfile
8944 = cu
->per_cu
->dwarf2_per_objfile
;
8945 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8946 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8948 const char *actual_name
= NULL
;
8951 baseaddr
= objfile
->text_section_offset ();
8953 gdb::unique_xmalloc_ptr
<char> built_actual_name
8954 = partial_die_full_name (pdi
, cu
);
8955 if (built_actual_name
!= NULL
)
8956 actual_name
= built_actual_name
.get ();
8958 if (actual_name
== NULL
)
8959 actual_name
= pdi
->name
;
8963 case DW_TAG_inlined_subroutine
:
8964 case DW_TAG_subprogram
:
8965 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8967 if (pdi
->is_external
8968 || cu
->language
== language_ada
8969 || (cu
->language
== language_fortran
8970 && pdi
->die_parent
!= NULL
8971 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8973 /* Normally, only "external" DIEs are part of the global scope.
8974 But in Ada and Fortran, we want to be able to access nested
8975 procedures globally. So all Ada and Fortran subprograms are
8976 stored in the global scope. */
8977 add_psymbol_to_list (actual_name
,
8978 built_actual_name
!= NULL
,
8979 VAR_DOMAIN
, LOC_BLOCK
,
8980 SECT_OFF_TEXT (objfile
),
8981 psymbol_placement::GLOBAL
,
8983 cu
->language
, objfile
);
8987 add_psymbol_to_list (actual_name
,
8988 built_actual_name
!= NULL
,
8989 VAR_DOMAIN
, LOC_BLOCK
,
8990 SECT_OFF_TEXT (objfile
),
8991 psymbol_placement::STATIC
,
8992 addr
, cu
->language
, objfile
);
8995 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8996 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8998 case DW_TAG_constant
:
8999 add_psymbol_to_list (actual_name
,
9000 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
9001 -1, (pdi
->is_external
9002 ? psymbol_placement::GLOBAL
9003 : psymbol_placement::STATIC
),
9004 0, cu
->language
, objfile
);
9006 case DW_TAG_variable
:
9008 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
9012 && !dwarf2_per_objfile
->has_section_at_zero
)
9014 /* A global or static variable may also have been stripped
9015 out by the linker if unused, in which case its address
9016 will be nullified; do not add such variables into partial
9017 symbol table then. */
9019 else if (pdi
->is_external
)
9022 Don't enter into the minimal symbol tables as there is
9023 a minimal symbol table entry from the ELF symbols already.
9024 Enter into partial symbol table if it has a location
9025 descriptor or a type.
9026 If the location descriptor is missing, new_symbol will create
9027 a LOC_UNRESOLVED symbol, the address of the variable will then
9028 be determined from the minimal symbol table whenever the variable
9030 The address for the partial symbol table entry is not
9031 used by GDB, but it comes in handy for debugging partial symbol
9034 if (pdi
->d
.locdesc
|| pdi
->has_type
)
9035 add_psymbol_to_list (actual_name
,
9036 built_actual_name
!= NULL
,
9037 VAR_DOMAIN
, LOC_STATIC
,
9038 SECT_OFF_TEXT (objfile
),
9039 psymbol_placement::GLOBAL
,
9040 addr
, cu
->language
, objfile
);
9044 int has_loc
= pdi
->d
.locdesc
!= NULL
;
9046 /* Static Variable. Skip symbols whose value we cannot know (those
9047 without location descriptors or constant values). */
9048 if (!has_loc
&& !pdi
->has_const_value
)
9051 add_psymbol_to_list (actual_name
,
9052 built_actual_name
!= NULL
,
9053 VAR_DOMAIN
, LOC_STATIC
,
9054 SECT_OFF_TEXT (objfile
),
9055 psymbol_placement::STATIC
,
9057 cu
->language
, objfile
);
9060 case DW_TAG_typedef
:
9061 case DW_TAG_base_type
:
9062 case DW_TAG_subrange_type
:
9063 add_psymbol_to_list (actual_name
,
9064 built_actual_name
!= NULL
,
9065 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
9066 psymbol_placement::STATIC
,
9067 0, cu
->language
, objfile
);
9069 case DW_TAG_imported_declaration
:
9070 case DW_TAG_namespace
:
9071 add_psymbol_to_list (actual_name
,
9072 built_actual_name
!= NULL
,
9073 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
9074 psymbol_placement::GLOBAL
,
9075 0, cu
->language
, objfile
);
9078 /* With Fortran 77 there might be a "BLOCK DATA" module
9079 available without any name. If so, we skip the module as it
9080 doesn't bring any value. */
9081 if (actual_name
!= nullptr)
9082 add_psymbol_to_list (actual_name
,
9083 built_actual_name
!= NULL
,
9084 MODULE_DOMAIN
, LOC_TYPEDEF
, -1,
9085 psymbol_placement::GLOBAL
,
9086 0, cu
->language
, objfile
);
9088 case DW_TAG_class_type
:
9089 case DW_TAG_interface_type
:
9090 case DW_TAG_structure_type
:
9091 case DW_TAG_union_type
:
9092 case DW_TAG_enumeration_type
:
9093 /* Skip external references. The DWARF standard says in the section
9094 about "Structure, Union, and Class Type Entries": "An incomplete
9095 structure, union or class type is represented by a structure,
9096 union or class entry that does not have a byte size attribute
9097 and that has a DW_AT_declaration attribute." */
9098 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
9101 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
9102 static vs. global. */
9103 add_psymbol_to_list (actual_name
,
9104 built_actual_name
!= NULL
,
9105 STRUCT_DOMAIN
, LOC_TYPEDEF
, -1,
9106 cu
->language
== language_cplus
9107 ? psymbol_placement::GLOBAL
9108 : psymbol_placement::STATIC
,
9109 0, cu
->language
, objfile
);
9112 case DW_TAG_enumerator
:
9113 add_psymbol_to_list (actual_name
,
9114 built_actual_name
!= NULL
,
9115 VAR_DOMAIN
, LOC_CONST
, -1,
9116 cu
->language
== language_cplus
9117 ? psymbol_placement::GLOBAL
9118 : psymbol_placement::STATIC
,
9119 0, cu
->language
, objfile
);
9126 /* Read a partial die corresponding to a namespace; also, add a symbol
9127 corresponding to that namespace to the symbol table. NAMESPACE is
9128 the name of the enclosing namespace. */
9131 add_partial_namespace (struct partial_die_info
*pdi
,
9132 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9133 int set_addrmap
, struct dwarf2_cu
*cu
)
9135 /* Add a symbol for the namespace. */
9137 add_partial_symbol (pdi
, cu
);
9139 /* Now scan partial symbols in that namespace. */
9141 if (pdi
->has_children
)
9142 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
9145 /* Read a partial die corresponding to a Fortran module. */
9148 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
9149 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
9151 /* Add a symbol for the namespace. */
9153 add_partial_symbol (pdi
, cu
);
9155 /* Now scan partial symbols in that module. */
9157 if (pdi
->has_children
)
9158 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
9161 /* Read a partial die corresponding to a subprogram or an inlined
9162 subprogram and create a partial symbol for that subprogram.
9163 When the CU language allows it, this routine also defines a partial
9164 symbol for each nested subprogram that this subprogram contains.
9165 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
9166 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
9168 PDI may also be a lexical block, in which case we simply search
9169 recursively for subprograms defined inside that lexical block.
9170 Again, this is only performed when the CU language allows this
9171 type of definitions. */
9174 add_partial_subprogram (struct partial_die_info
*pdi
,
9175 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9176 int set_addrmap
, struct dwarf2_cu
*cu
)
9178 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
9180 if (pdi
->has_pc_info
)
9182 if (pdi
->lowpc
< *lowpc
)
9183 *lowpc
= pdi
->lowpc
;
9184 if (pdi
->highpc
> *highpc
)
9185 *highpc
= pdi
->highpc
;
9188 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9189 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9191 CORE_ADDR this_highpc
;
9192 CORE_ADDR this_lowpc
;
9194 baseaddr
= objfile
->text_section_offset ();
9196 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
9197 pdi
->lowpc
+ baseaddr
)
9200 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
9201 pdi
->highpc
+ baseaddr
)
9203 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
9204 this_lowpc
, this_highpc
- 1,
9205 cu
->per_cu
->v
.psymtab
);
9209 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
9211 if (!pdi
->is_declaration
)
9212 /* Ignore subprogram DIEs that do not have a name, they are
9213 illegal. Do not emit a complaint at this point, we will
9214 do so when we convert this psymtab into a symtab. */
9216 add_partial_symbol (pdi
, cu
);
9220 if (! pdi
->has_children
)
9223 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
9225 pdi
= pdi
->die_child
;
9229 if (pdi
->tag
== DW_TAG_subprogram
9230 || pdi
->tag
== DW_TAG_inlined_subroutine
9231 || pdi
->tag
== DW_TAG_lexical_block
)
9232 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
9233 pdi
= pdi
->die_sibling
;
9238 /* Read a partial die corresponding to an enumeration type. */
9241 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
9242 struct dwarf2_cu
*cu
)
9244 struct partial_die_info
*pdi
;
9246 if (enum_pdi
->name
!= NULL
)
9247 add_partial_symbol (enum_pdi
, cu
);
9249 pdi
= enum_pdi
->die_child
;
9252 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
9253 complaint (_("malformed enumerator DIE ignored"));
9255 add_partial_symbol (pdi
, cu
);
9256 pdi
= pdi
->die_sibling
;
9260 /* Return the initial uleb128 in the die at INFO_PTR. */
9263 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
9265 unsigned int bytes_read
;
9267 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9270 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
9271 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
9273 Return the corresponding abbrev, or NULL if the number is zero (indicating
9274 an empty DIE). In either case *BYTES_READ will be set to the length of
9275 the initial number. */
9277 static struct abbrev_info
*
9278 peek_die_abbrev (const die_reader_specs
&reader
,
9279 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
9281 dwarf2_cu
*cu
= reader
.cu
;
9282 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
9283 unsigned int abbrev_number
9284 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
9286 if (abbrev_number
== 0)
9289 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
9292 error (_("Dwarf Error: Could not find abbrev number %d in %s"
9293 " at offset %s [in module %s]"),
9294 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
9295 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
9301 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9302 Returns a pointer to the end of a series of DIEs, terminated by an empty
9303 DIE. Any children of the skipped DIEs will also be skipped. */
9305 static const gdb_byte
*
9306 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
9310 unsigned int bytes_read
;
9311 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
9314 return info_ptr
+ bytes_read
;
9316 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
9320 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9321 INFO_PTR should point just after the initial uleb128 of a DIE, and the
9322 abbrev corresponding to that skipped uleb128 should be passed in
9323 ABBREV. Returns a pointer to this DIE's sibling, skipping any
9326 static const gdb_byte
*
9327 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
9328 struct abbrev_info
*abbrev
)
9330 unsigned int bytes_read
;
9331 struct attribute attr
;
9332 bfd
*abfd
= reader
->abfd
;
9333 struct dwarf2_cu
*cu
= reader
->cu
;
9334 const gdb_byte
*buffer
= reader
->buffer
;
9335 const gdb_byte
*buffer_end
= reader
->buffer_end
;
9336 unsigned int form
, i
;
9338 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
9340 /* The only abbrev we care about is DW_AT_sibling. */
9341 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
9344 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
,
9346 if (attr
.form
== DW_FORM_ref_addr
)
9347 complaint (_("ignoring absolute DW_AT_sibling"));
9350 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
9351 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
9353 if (sibling_ptr
< info_ptr
)
9354 complaint (_("DW_AT_sibling points backwards"));
9355 else if (sibling_ptr
> reader
->buffer_end
)
9356 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
9362 /* If it isn't DW_AT_sibling, skip this attribute. */
9363 form
= abbrev
->attrs
[i
].form
;
9367 case DW_FORM_ref_addr
:
9368 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
9369 and later it is offset sized. */
9370 if (cu
->header
.version
== 2)
9371 info_ptr
+= cu
->header
.addr_size
;
9373 info_ptr
+= cu
->header
.offset_size
;
9375 case DW_FORM_GNU_ref_alt
:
9376 info_ptr
+= cu
->header
.offset_size
;
9379 info_ptr
+= cu
->header
.addr_size
;
9387 case DW_FORM_flag_present
:
9388 case DW_FORM_implicit_const
:
9405 case DW_FORM_ref_sig8
:
9408 case DW_FORM_data16
:
9411 case DW_FORM_string
:
9412 read_direct_string (abfd
, info_ptr
, &bytes_read
);
9413 info_ptr
+= bytes_read
;
9415 case DW_FORM_sec_offset
:
9417 case DW_FORM_GNU_strp_alt
:
9418 info_ptr
+= cu
->header
.offset_size
;
9420 case DW_FORM_exprloc
:
9422 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9423 info_ptr
+= bytes_read
;
9425 case DW_FORM_block1
:
9426 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
9428 case DW_FORM_block2
:
9429 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
9431 case DW_FORM_block4
:
9432 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
9438 case DW_FORM_ref_udata
:
9439 case DW_FORM_GNU_addr_index
:
9440 case DW_FORM_GNU_str_index
:
9441 case DW_FORM_rnglistx
:
9442 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
9444 case DW_FORM_indirect
:
9445 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9446 info_ptr
+= bytes_read
;
9447 /* We need to continue parsing from here, so just go back to
9449 goto skip_attribute
;
9452 error (_("Dwarf Error: Cannot handle %s "
9453 "in DWARF reader [in module %s]"),
9454 dwarf_form_name (form
),
9455 bfd_get_filename (abfd
));
9459 if (abbrev
->has_children
)
9460 return skip_children (reader
, info_ptr
);
9465 /* Locate ORIG_PDI's sibling.
9466 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
9468 static const gdb_byte
*
9469 locate_pdi_sibling (const struct die_reader_specs
*reader
,
9470 struct partial_die_info
*orig_pdi
,
9471 const gdb_byte
*info_ptr
)
9473 /* Do we know the sibling already? */
9475 if (orig_pdi
->sibling
)
9476 return orig_pdi
->sibling
;
9478 /* Are there any children to deal with? */
9480 if (!orig_pdi
->has_children
)
9483 /* Skip the children the long way. */
9485 return skip_children (reader
, info_ptr
);
9488 /* Expand this partial symbol table into a full symbol table. SELF is
9492 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
9494 struct dwarf2_per_objfile
*dwarf2_per_objfile
9495 = get_dwarf2_per_objfile (objfile
);
9499 warning (_("bug: psymtab for %s is already read in."),
9506 printf_filtered (_("Reading in symbols for %s..."),
9508 gdb_flush (gdb_stdout
);
9511 /* If this psymtab is constructed from a debug-only objfile, the
9512 has_section_at_zero flag will not necessarily be correct. We
9513 can get the correct value for this flag by looking at the data
9514 associated with the (presumably stripped) associated objfile. */
9515 if (objfile
->separate_debug_objfile_backlink
)
9517 struct dwarf2_per_objfile
*dpo_backlink
9518 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
9520 dwarf2_per_objfile
->has_section_at_zero
9521 = dpo_backlink
->has_section_at_zero
;
9524 dwarf2_per_objfile
->reading_partial_symbols
= 0;
9526 psymtab_to_symtab_1 (this);
9528 /* Finish up the debug error message. */
9530 printf_filtered (_("done.\n"));
9533 process_cu_includes (dwarf2_per_objfile
);
9536 /* Reading in full CUs. */
9538 /* Add PER_CU to the queue. */
9541 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9542 enum language pretend_language
)
9544 struct dwarf2_queue_item
*item
;
9547 item
= XNEW (struct dwarf2_queue_item
);
9548 item
->per_cu
= per_cu
;
9549 item
->pretend_language
= pretend_language
;
9552 if (dwarf2_queue
== NULL
)
9553 dwarf2_queue
= item
;
9555 dwarf2_queue_tail
->next
= item
;
9557 dwarf2_queue_tail
= item
;
9560 /* If PER_CU is not yet queued, add it to the queue.
9561 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
9563 The result is non-zero if PER_CU was queued, otherwise the result is zero
9564 meaning either PER_CU is already queued or it is already loaded.
9566 N.B. There is an invariant here that if a CU is queued then it is loaded.
9567 The caller is required to load PER_CU if we return non-zero. */
9570 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
9571 struct dwarf2_per_cu_data
*per_cu
,
9572 enum language pretend_language
)
9574 /* We may arrive here during partial symbol reading, if we need full
9575 DIEs to process an unusual case (e.g. template arguments). Do
9576 not queue PER_CU, just tell our caller to load its DIEs. */
9577 if (per_cu
->dwarf2_per_objfile
->reading_partial_symbols
)
9579 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
9584 /* Mark the dependence relation so that we don't flush PER_CU
9586 if (dependent_cu
!= NULL
)
9587 dwarf2_add_dependence (dependent_cu
, per_cu
);
9589 /* If it's already on the queue, we have nothing to do. */
9593 /* If the compilation unit is already loaded, just mark it as
9595 if (per_cu
->cu
!= NULL
)
9597 per_cu
->cu
->last_used
= 0;
9601 /* Add it to the queue. */
9602 queue_comp_unit (per_cu
, pretend_language
);
9607 /* Process the queue. */
9610 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9612 struct dwarf2_queue_item
*item
, *next_item
;
9614 if (dwarf_read_debug
)
9616 fprintf_unfiltered (gdb_stdlog
,
9617 "Expanding one or more symtabs of objfile %s ...\n",
9618 objfile_name (dwarf2_per_objfile
->objfile
));
9621 /* The queue starts out with one item, but following a DIE reference
9622 may load a new CU, adding it to the end of the queue. */
9623 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
9625 if ((dwarf2_per_objfile
->using_index
9626 ? !item
->per_cu
->v
.quick
->compunit_symtab
9627 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
9628 /* Skip dummy CUs. */
9629 && item
->per_cu
->cu
!= NULL
)
9631 struct dwarf2_per_cu_data
*per_cu
= item
->per_cu
;
9632 unsigned int debug_print_threshold
;
9635 if (per_cu
->is_debug_types
)
9637 struct signatured_type
*sig_type
=
9638 (struct signatured_type
*) per_cu
;
9640 sprintf (buf
, "TU %s at offset %s",
9641 hex_string (sig_type
->signature
),
9642 sect_offset_str (per_cu
->sect_off
));
9643 /* There can be 100s of TUs.
9644 Only print them in verbose mode. */
9645 debug_print_threshold
= 2;
9649 sprintf (buf
, "CU at offset %s",
9650 sect_offset_str (per_cu
->sect_off
));
9651 debug_print_threshold
= 1;
9654 if (dwarf_read_debug
>= debug_print_threshold
)
9655 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
9657 if (per_cu
->is_debug_types
)
9658 process_full_type_unit (per_cu
, item
->pretend_language
);
9660 process_full_comp_unit (per_cu
, item
->pretend_language
);
9662 if (dwarf_read_debug
>= debug_print_threshold
)
9663 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
9666 item
->per_cu
->queued
= 0;
9667 next_item
= item
->next
;
9671 dwarf2_queue_tail
= NULL
;
9673 if (dwarf_read_debug
)
9675 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
9676 objfile_name (dwarf2_per_objfile
->objfile
));
9680 /* Read in full symbols for PST, and anything it depends on. */
9683 psymtab_to_symtab_1 (dwarf2_psymtab
*pst
)
9685 struct dwarf2_per_cu_data
*per_cu
;
9691 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
9692 if (!pst
->dependencies
[i
]->readin
9693 && pst
->dependencies
[i
]->user
== NULL
)
9695 /* Inform about additional files that need to be read in. */
9698 /* FIXME: i18n: Need to make this a single string. */
9699 fputs_filtered (" ", gdb_stdout
);
9701 fputs_filtered ("and ", gdb_stdout
);
9703 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
9704 wrap_here (""); /* Flush output. */
9705 gdb_flush (gdb_stdout
);
9707 psymtab_to_symtab_1 ((dwarf2_psymtab
*) pst
->dependencies
[i
]);
9710 per_cu
= pst
->per_cu_data
;
9714 /* It's an include file, no symbols to read for it.
9715 Everything is in the parent symtab. */
9720 dw2_do_instantiate_symtab (per_cu
, false);
9723 /* Trivial hash function for die_info: the hash value of a DIE
9724 is its offset in .debug_info for this objfile. */
9727 die_hash (const void *item
)
9729 const struct die_info
*die
= (const struct die_info
*) item
;
9731 return to_underlying (die
->sect_off
);
9734 /* Trivial comparison function for die_info structures: two DIEs
9735 are equal if they have the same offset. */
9738 die_eq (const void *item_lhs
, const void *item_rhs
)
9740 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
9741 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
9743 return die_lhs
->sect_off
== die_rhs
->sect_off
;
9746 /* Load the DIEs associated with PER_CU into memory. */
9749 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
9751 enum language pretend_language
)
9753 gdb_assert (! this_cu
->is_debug_types
);
9755 cutu_reader
reader (this_cu
, NULL
, 1, 1, skip_partial
);
9759 struct dwarf2_cu
*cu
= reader
.cu
;
9760 const gdb_byte
*info_ptr
= reader
.info_ptr
;
9762 gdb_assert (cu
->die_hash
== NULL
);
9764 htab_create_alloc_ex (cu
->header
.length
/ 12,
9768 &cu
->comp_unit_obstack
,
9769 hashtab_obstack_allocate
,
9770 dummy_obstack_deallocate
);
9772 if (reader
.has_children
)
9773 reader
.comp_unit_die
->child
9774 = read_die_and_siblings (&reader
, reader
.info_ptr
,
9775 &info_ptr
, reader
.comp_unit_die
);
9776 cu
->dies
= reader
.comp_unit_die
;
9777 /* comp_unit_die is not stored in die_hash, no need. */
9779 /* We try not to read any attributes in this function, because not
9780 all CUs needed for references have been loaded yet, and symbol
9781 table processing isn't initialized. But we have to set the CU language,
9782 or we won't be able to build types correctly.
9783 Similarly, if we do not read the producer, we can not apply
9784 producer-specific interpretation. */
9785 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
9788 /* Add a DIE to the delayed physname list. */
9791 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
9792 const char *name
, struct die_info
*die
,
9793 struct dwarf2_cu
*cu
)
9795 struct delayed_method_info mi
;
9797 mi
.fnfield_index
= fnfield_index
;
9801 cu
->method_list
.push_back (mi
);
9804 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
9805 "const" / "volatile". If so, decrements LEN by the length of the
9806 modifier and return true. Otherwise return false. */
9810 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
9812 size_t mod_len
= sizeof (mod
) - 1;
9813 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
9821 /* Compute the physnames of any methods on the CU's method list.
9823 The computation of method physnames is delayed in order to avoid the
9824 (bad) condition that one of the method's formal parameters is of an as yet
9828 compute_delayed_physnames (struct dwarf2_cu
*cu
)
9830 /* Only C++ delays computing physnames. */
9831 if (cu
->method_list
.empty ())
9833 gdb_assert (cu
->language
== language_cplus
);
9835 for (const delayed_method_info
&mi
: cu
->method_list
)
9837 const char *physname
;
9838 struct fn_fieldlist
*fn_flp
9839 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9840 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9841 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9842 = physname
? physname
: "";
9844 /* Since there's no tag to indicate whether a method is a
9845 const/volatile overload, extract that information out of the
9847 if (physname
!= NULL
)
9849 size_t len
= strlen (physname
);
9853 if (physname
[len
] == ')') /* shortcut */
9855 else if (check_modifier (physname
, len
, " const"))
9856 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9857 else if (check_modifier (physname
, len
, " volatile"))
9858 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9865 /* The list is no longer needed. */
9866 cu
->method_list
.clear ();
9869 /* Go objects should be embedded in a DW_TAG_module DIE,
9870 and it's not clear if/how imported objects will appear.
9871 To keep Go support simple until that's worked out,
9872 go back through what we've read and create something usable.
9873 We could do this while processing each DIE, and feels kinda cleaner,
9874 but that way is more invasive.
9875 This is to, for example, allow the user to type "p var" or "b main"
9876 without having to specify the package name, and allow lookups
9877 of module.object to work in contexts that use the expression
9881 fixup_go_packaging (struct dwarf2_cu
*cu
)
9883 gdb::unique_xmalloc_ptr
<char> package_name
;
9884 struct pending
*list
;
9887 for (list
= *cu
->get_builder ()->get_global_symbols ();
9891 for (i
= 0; i
< list
->nsyms
; ++i
)
9893 struct symbol
*sym
= list
->symbol
[i
];
9895 if (sym
->language () == language_go
9896 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9898 gdb::unique_xmalloc_ptr
<char> this_package_name
9899 (go_symbol_package_name (sym
));
9901 if (this_package_name
== NULL
)
9903 if (package_name
== NULL
)
9904 package_name
= std::move (this_package_name
);
9907 struct objfile
*objfile
9908 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9909 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9910 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9911 (symbol_symtab (sym
) != NULL
9912 ? symtab_to_filename_for_display
9913 (symbol_symtab (sym
))
9914 : objfile_name (objfile
)),
9915 this_package_name
.get (), package_name
.get ());
9921 if (package_name
!= NULL
)
9923 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9924 const char *saved_package_name
9925 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
, package_name
.get ());
9926 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9927 saved_package_name
);
9930 sym
= allocate_symbol (objfile
);
9931 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9932 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9933 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9934 e.g., "main" finds the "main" module and not C's main(). */
9935 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9936 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9937 SYMBOL_TYPE (sym
) = type
;
9939 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9943 /* Allocate a fully-qualified name consisting of the two parts on the
9947 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9949 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9952 /* A helper that allocates a struct discriminant_info to attach to a
9955 static struct discriminant_info
*
9956 alloc_discriminant_info (struct type
*type
, int discriminant_index
,
9959 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9960 gdb_assert (discriminant_index
== -1
9961 || (discriminant_index
>= 0
9962 && discriminant_index
< TYPE_NFIELDS (type
)));
9963 gdb_assert (default_index
== -1
9964 || (default_index
>= 0 && default_index
< TYPE_NFIELDS (type
)));
9966 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
9968 struct discriminant_info
*disc
9969 = ((struct discriminant_info
*)
9971 offsetof (struct discriminant_info
, discriminants
)
9972 + TYPE_NFIELDS (type
) * sizeof (disc
->discriminants
[0])));
9973 disc
->default_index
= default_index
;
9974 disc
->discriminant_index
= discriminant_index
;
9976 struct dynamic_prop prop
;
9977 prop
.kind
= PROP_UNDEFINED
;
9978 prop
.data
.baton
= disc
;
9980 add_dyn_prop (DYN_PROP_DISCRIMINATED
, prop
, type
);
9985 /* Some versions of rustc emitted enums in an unusual way.
9987 Ordinary enums were emitted as unions. The first element of each
9988 structure in the union was named "RUST$ENUM$DISR". This element
9989 held the discriminant.
9991 These versions of Rust also implemented the "non-zero"
9992 optimization. When the enum had two values, and one is empty and
9993 the other holds a pointer that cannot be zero, the pointer is used
9994 as the discriminant, with a zero value meaning the empty variant.
9995 Here, the union's first member is of the form
9996 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9997 where the fieldnos are the indices of the fields that should be
9998 traversed in order to find the field (which may be several fields deep)
9999 and the variantname is the name of the variant of the case when the
10002 This function recognizes whether TYPE is of one of these forms,
10003 and, if so, smashes it to be a variant type. */
10006 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
10008 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
10010 /* We don't need to deal with empty enums. */
10011 if (TYPE_NFIELDS (type
) == 0)
10014 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
10015 if (TYPE_NFIELDS (type
) == 1
10016 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
10018 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
10020 /* Decode the field name to find the offset of the
10022 ULONGEST bit_offset
= 0;
10023 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
10024 while (name
[0] >= '0' && name
[0] <= '9')
10027 unsigned long index
= strtoul (name
, &tail
, 10);
10030 || index
>= TYPE_NFIELDS (field_type
)
10031 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
10032 != FIELD_LOC_KIND_BITPOS
))
10034 complaint (_("Could not parse Rust enum encoding string \"%s\""
10036 TYPE_FIELD_NAME (type
, 0),
10037 objfile_name (objfile
));
10042 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
10043 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
10046 /* Make a union to hold the variants. */
10047 struct type
*union_type
= alloc_type (objfile
);
10048 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10049 TYPE_NFIELDS (union_type
) = 3;
10050 TYPE_FIELDS (union_type
)
10051 = (struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
));
10052 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10053 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
10055 /* Put the discriminant must at index 0. */
10056 TYPE_FIELD_TYPE (union_type
, 0) = field_type
;
10057 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
10058 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
10059 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 0), bit_offset
);
10061 /* The order of fields doesn't really matter, so put the real
10062 field at index 1 and the data-less field at index 2. */
10063 struct discriminant_info
*disc
10064 = alloc_discriminant_info (union_type
, 0, 1);
10065 TYPE_FIELD (union_type
, 1) = TYPE_FIELD (type
, 0);
10066 TYPE_FIELD_NAME (union_type
, 1)
10067 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1)));
10068 TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1))
10069 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
10070 TYPE_FIELD_NAME (union_type
, 1));
10072 const char *dataless_name
10073 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
10075 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
10077 TYPE_FIELD_TYPE (union_type
, 2) = dataless_type
;
10078 /* NAME points into the original discriminant name, which
10079 already has the correct lifetime. */
10080 TYPE_FIELD_NAME (union_type
, 2) = name
;
10081 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 2), 0);
10082 disc
->discriminants
[2] = 0;
10084 /* Smash this type to be a structure type. We have to do this
10085 because the type has already been recorded. */
10086 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10087 TYPE_NFIELDS (type
) = 1;
10089 = (struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
));
10091 /* Install the variant part. */
10092 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10093 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10094 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10096 /* A union with a single anonymous field is probably an old-style
10097 univariant enum. */
10098 else if (TYPE_NFIELDS (type
) == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
10100 /* Smash this type to be a structure type. We have to do this
10101 because the type has already been recorded. */
10102 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10104 /* Make a union to hold the variants. */
10105 struct type
*union_type
= alloc_type (objfile
);
10106 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10107 TYPE_NFIELDS (union_type
) = TYPE_NFIELDS (type
);
10108 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10109 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
10110 TYPE_FIELDS (union_type
) = TYPE_FIELDS (type
);
10112 struct type
*field_type
= TYPE_FIELD_TYPE (union_type
, 0);
10113 const char *variant_name
10114 = rust_last_path_segment (TYPE_NAME (field_type
));
10115 TYPE_FIELD_NAME (union_type
, 0) = variant_name
;
10116 TYPE_NAME (field_type
)
10117 = rust_fully_qualify (&objfile
->objfile_obstack
,
10118 TYPE_NAME (type
), variant_name
);
10120 /* Install the union in the outer struct type. */
10121 TYPE_NFIELDS (type
) = 1;
10123 = (struct field
*) TYPE_ZALLOC (union_type
, sizeof (struct field
));
10124 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10125 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10126 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10128 alloc_discriminant_info (union_type
, -1, 0);
10132 struct type
*disr_type
= nullptr;
10133 for (int i
= 0; i
< TYPE_NFIELDS (type
); ++i
)
10135 disr_type
= TYPE_FIELD_TYPE (type
, i
);
10137 if (TYPE_CODE (disr_type
) != TYPE_CODE_STRUCT
)
10139 /* All fields of a true enum will be structs. */
10142 else if (TYPE_NFIELDS (disr_type
) == 0)
10144 /* Could be data-less variant, so keep going. */
10145 disr_type
= nullptr;
10147 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
10148 "RUST$ENUM$DISR") != 0)
10150 /* Not a Rust enum. */
10160 /* If we got here without a discriminant, then it's probably
10162 if (disr_type
== nullptr)
10165 /* Smash this type to be a structure type. We have to do this
10166 because the type has already been recorded. */
10167 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10169 /* Make a union to hold the variants. */
10170 struct field
*disr_field
= &TYPE_FIELD (disr_type
, 0);
10171 struct type
*union_type
= alloc_type (objfile
);
10172 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10173 TYPE_NFIELDS (union_type
) = 1 + TYPE_NFIELDS (type
);
10174 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10175 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
10176 TYPE_FIELDS (union_type
)
10177 = (struct field
*) TYPE_ZALLOC (union_type
,
10178 (TYPE_NFIELDS (union_type
)
10179 * sizeof (struct field
)));
10181 memcpy (TYPE_FIELDS (union_type
) + 1, TYPE_FIELDS (type
),
10182 TYPE_NFIELDS (type
) * sizeof (struct field
));
10184 /* Install the discriminant at index 0 in the union. */
10185 TYPE_FIELD (union_type
, 0) = *disr_field
;
10186 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
10187 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
10189 /* Install the union in the outer struct type. */
10190 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10191 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10192 TYPE_NFIELDS (type
) = 1;
10194 /* Set the size and offset of the union type. */
10195 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10197 /* We need a way to find the correct discriminant given a
10198 variant name. For convenience we build a map here. */
10199 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
10200 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
10201 for (int i
= 0; i
< TYPE_NFIELDS (enum_type
); ++i
)
10203 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
10206 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
10207 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
10211 int n_fields
= TYPE_NFIELDS (union_type
);
10212 struct discriminant_info
*disc
10213 = alloc_discriminant_info (union_type
, 0, -1);
10214 /* Skip the discriminant here. */
10215 for (int i
= 1; i
< n_fields
; ++i
)
10217 /* Find the final word in the name of this variant's type.
10218 That name can be used to look up the correct
10220 const char *variant_name
10221 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
,
10224 auto iter
= discriminant_map
.find (variant_name
);
10225 if (iter
!= discriminant_map
.end ())
10226 disc
->discriminants
[i
] = iter
->second
;
10228 /* Remove the discriminant field, if it exists. */
10229 struct type
*sub_type
= TYPE_FIELD_TYPE (union_type
, i
);
10230 if (TYPE_NFIELDS (sub_type
) > 0)
10232 --TYPE_NFIELDS (sub_type
);
10233 ++TYPE_FIELDS (sub_type
);
10235 TYPE_FIELD_NAME (union_type
, i
) = variant_name
;
10236 TYPE_NAME (sub_type
)
10237 = rust_fully_qualify (&objfile
->objfile_obstack
,
10238 TYPE_NAME (type
), variant_name
);
10243 /* Rewrite some Rust unions to be structures with variants parts. */
10246 rust_union_quirks (struct dwarf2_cu
*cu
)
10248 gdb_assert (cu
->language
== language_rust
);
10249 for (type
*type_
: cu
->rust_unions
)
10250 quirk_rust_enum (type_
, cu
->per_cu
->dwarf2_per_objfile
->objfile
);
10251 /* We don't need this any more. */
10252 cu
->rust_unions
.clear ();
10255 /* Return the symtab for PER_CU. This works properly regardless of
10256 whether we're using the index or psymtabs. */
10258 static struct compunit_symtab
*
10259 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
10261 return (per_cu
->dwarf2_per_objfile
->using_index
10262 ? per_cu
->v
.quick
->compunit_symtab
10263 : per_cu
->v
.psymtab
->compunit_symtab
);
10266 /* A helper function for computing the list of all symbol tables
10267 included by PER_CU. */
10270 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
10271 htab_t all_children
, htab_t all_type_symtabs
,
10272 struct dwarf2_per_cu_data
*per_cu
,
10273 struct compunit_symtab
*immediate_parent
)
10276 struct compunit_symtab
*cust
;
10278 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
10281 /* This inclusion and its children have been processed. */
10286 /* Only add a CU if it has a symbol table. */
10287 cust
= get_compunit_symtab (per_cu
);
10290 /* If this is a type unit only add its symbol table if we haven't
10291 seen it yet (type unit per_cu's can share symtabs). */
10292 if (per_cu
->is_debug_types
)
10294 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
10298 result
->push_back (cust
);
10299 if (cust
->user
== NULL
)
10300 cust
->user
= immediate_parent
;
10305 result
->push_back (cust
);
10306 if (cust
->user
== NULL
)
10307 cust
->user
= immediate_parent
;
10311 if (!per_cu
->imported_symtabs_empty ())
10312 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
10314 recursively_compute_inclusions (result
, all_children
,
10315 all_type_symtabs
, ptr
, cust
);
10319 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
10323 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
10325 gdb_assert (! per_cu
->is_debug_types
);
10327 if (!per_cu
->imported_symtabs_empty ())
10330 std::vector
<compunit_symtab
*> result_symtabs
;
10331 htab_t all_children
, all_type_symtabs
;
10332 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
10334 /* If we don't have a symtab, we can just skip this case. */
10338 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10339 NULL
, xcalloc
, xfree
);
10340 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10341 NULL
, xcalloc
, xfree
);
10343 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
10345 recursively_compute_inclusions (&result_symtabs
, all_children
,
10346 all_type_symtabs
, ptr
, cust
);
10349 /* Now we have a transitive closure of all the included symtabs. */
10350 len
= result_symtabs
.size ();
10352 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
10353 struct compunit_symtab
*, len
+ 1);
10354 memcpy (cust
->includes
, result_symtabs
.data (),
10355 len
* sizeof (compunit_symtab
*));
10356 cust
->includes
[len
] = NULL
;
10358 htab_delete (all_children
);
10359 htab_delete (all_type_symtabs
);
10363 /* Compute the 'includes' field for the symtabs of all the CUs we just
10367 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
10369 for (dwarf2_per_cu_data
*iter
: dwarf2_per_objfile
->just_read_cus
)
10371 if (! iter
->is_debug_types
)
10372 compute_compunit_symtab_includes (iter
);
10375 dwarf2_per_objfile
->just_read_cus
.clear ();
10378 /* Generate full symbol information for PER_CU, whose DIEs have
10379 already been loaded into memory. */
10382 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
10383 enum language pretend_language
)
10385 struct dwarf2_cu
*cu
= per_cu
->cu
;
10386 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10387 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10388 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10389 CORE_ADDR lowpc
, highpc
;
10390 struct compunit_symtab
*cust
;
10391 CORE_ADDR baseaddr
;
10392 struct block
*static_block
;
10395 baseaddr
= objfile
->text_section_offset ();
10397 /* Clear the list here in case something was left over. */
10398 cu
->method_list
.clear ();
10400 cu
->language
= pretend_language
;
10401 cu
->language_defn
= language_def (cu
->language
);
10403 /* Do line number decoding in read_file_scope () */
10404 process_die (cu
->dies
, cu
);
10406 /* For now fudge the Go package. */
10407 if (cu
->language
== language_go
)
10408 fixup_go_packaging (cu
);
10410 /* Now that we have processed all the DIEs in the CU, all the types
10411 should be complete, and it should now be safe to compute all of the
10413 compute_delayed_physnames (cu
);
10415 if (cu
->language
== language_rust
)
10416 rust_union_quirks (cu
);
10418 /* Some compilers don't define a DW_AT_high_pc attribute for the
10419 compilation unit. If the DW_AT_high_pc is missing, synthesize
10420 it, by scanning the DIE's below the compilation unit. */
10421 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
10423 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
10424 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
10426 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
10427 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
10428 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
10429 addrmap to help ensure it has an accurate map of pc values belonging to
10431 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
10433 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
10434 SECT_OFF_TEXT (objfile
),
10439 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
10441 /* Set symtab language to language from DW_AT_language. If the
10442 compilation is from a C file generated by language preprocessors, do
10443 not set the language if it was already deduced by start_subfile. */
10444 if (!(cu
->language
== language_c
10445 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
10446 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10448 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
10449 produce DW_AT_location with location lists but it can be possibly
10450 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
10451 there were bugs in prologue debug info, fixed later in GCC-4.5
10452 by "unwind info for epilogues" patch (which is not directly related).
10454 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
10455 needed, it would be wrong due to missing DW_AT_producer there.
10457 Still one can confuse GDB by using non-standard GCC compilation
10458 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
10460 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
10461 cust
->locations_valid
= 1;
10463 if (gcc_4_minor
>= 5)
10464 cust
->epilogue_unwind_valid
= 1;
10466 cust
->call_site_htab
= cu
->call_site_htab
;
10469 if (dwarf2_per_objfile
->using_index
)
10470 per_cu
->v
.quick
->compunit_symtab
= cust
;
10473 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
10474 pst
->compunit_symtab
= cust
;
10475 pst
->readin
= true;
10478 /* Push it for inclusion processing later. */
10479 dwarf2_per_objfile
->just_read_cus
.push_back (per_cu
);
10481 /* Not needed any more. */
10482 cu
->reset_builder ();
10485 /* Generate full symbol information for type unit PER_CU, whose DIEs have
10486 already been loaded into memory. */
10489 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
10490 enum language pretend_language
)
10492 struct dwarf2_cu
*cu
= per_cu
->cu
;
10493 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10494 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10495 struct compunit_symtab
*cust
;
10496 struct signatured_type
*sig_type
;
10498 gdb_assert (per_cu
->is_debug_types
);
10499 sig_type
= (struct signatured_type
*) per_cu
;
10501 /* Clear the list here in case something was left over. */
10502 cu
->method_list
.clear ();
10504 cu
->language
= pretend_language
;
10505 cu
->language_defn
= language_def (cu
->language
);
10507 /* The symbol tables are set up in read_type_unit_scope. */
10508 process_die (cu
->dies
, cu
);
10510 /* For now fudge the Go package. */
10511 if (cu
->language
== language_go
)
10512 fixup_go_packaging (cu
);
10514 /* Now that we have processed all the DIEs in the CU, all the types
10515 should be complete, and it should now be safe to compute all of the
10517 compute_delayed_physnames (cu
);
10519 if (cu
->language
== language_rust
)
10520 rust_union_quirks (cu
);
10522 /* TUs share symbol tables.
10523 If this is the first TU to use this symtab, complete the construction
10524 of it with end_expandable_symtab. Otherwise, complete the addition of
10525 this TU's symbols to the existing symtab. */
10526 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
10528 buildsym_compunit
*builder
= cu
->get_builder ();
10529 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
10530 sig_type
->type_unit_group
->compunit_symtab
= cust
;
10534 /* Set symtab language to language from DW_AT_language. If the
10535 compilation is from a C file generated by language preprocessors,
10536 do not set the language if it was already deduced by
10538 if (!(cu
->language
== language_c
10539 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
10540 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10545 cu
->get_builder ()->augment_type_symtab ();
10546 cust
= sig_type
->type_unit_group
->compunit_symtab
;
10549 if (dwarf2_per_objfile
->using_index
)
10550 per_cu
->v
.quick
->compunit_symtab
= cust
;
10553 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
10554 pst
->compunit_symtab
= cust
;
10555 pst
->readin
= true;
10558 /* Not needed any more. */
10559 cu
->reset_builder ();
10562 /* Process an imported unit DIE. */
10565 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10567 struct attribute
*attr
;
10569 /* For now we don't handle imported units in type units. */
10570 if (cu
->per_cu
->is_debug_types
)
10572 error (_("Dwarf Error: DW_TAG_imported_unit is not"
10573 " supported in type units [in module %s]"),
10574 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
10577 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10580 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
10581 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
10582 dwarf2_per_cu_data
*per_cu
10583 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
10584 cu
->per_cu
->dwarf2_per_objfile
);
10586 /* If necessary, add it to the queue and load its DIEs. */
10587 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
10588 load_full_comp_unit (per_cu
, false, cu
->language
);
10590 cu
->per_cu
->imported_symtabs_push (per_cu
);
10594 /* RAII object that represents a process_die scope: i.e.,
10595 starts/finishes processing a DIE. */
10596 class process_die_scope
10599 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
10600 : m_die (die
), m_cu (cu
)
10602 /* We should only be processing DIEs not already in process. */
10603 gdb_assert (!m_die
->in_process
);
10604 m_die
->in_process
= true;
10607 ~process_die_scope ()
10609 m_die
->in_process
= false;
10611 /* If we're done processing the DIE for the CU that owns the line
10612 header, we don't need the line header anymore. */
10613 if (m_cu
->line_header_die_owner
== m_die
)
10615 delete m_cu
->line_header
;
10616 m_cu
->line_header
= NULL
;
10617 m_cu
->line_header_die_owner
= NULL
;
10626 /* Process a die and its children. */
10629 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10631 process_die_scope
scope (die
, cu
);
10635 case DW_TAG_padding
:
10637 case DW_TAG_compile_unit
:
10638 case DW_TAG_partial_unit
:
10639 read_file_scope (die
, cu
);
10641 case DW_TAG_type_unit
:
10642 read_type_unit_scope (die
, cu
);
10644 case DW_TAG_subprogram
:
10645 /* Nested subprograms in Fortran get a prefix. */
10646 if (cu
->language
== language_fortran
10647 && die
->parent
!= NULL
10648 && die
->parent
->tag
== DW_TAG_subprogram
)
10649 cu
->processing_has_namespace_info
= true;
10650 /* Fall through. */
10651 case DW_TAG_inlined_subroutine
:
10652 read_func_scope (die
, cu
);
10654 case DW_TAG_lexical_block
:
10655 case DW_TAG_try_block
:
10656 case DW_TAG_catch_block
:
10657 read_lexical_block_scope (die
, cu
);
10659 case DW_TAG_call_site
:
10660 case DW_TAG_GNU_call_site
:
10661 read_call_site_scope (die
, cu
);
10663 case DW_TAG_class_type
:
10664 case DW_TAG_interface_type
:
10665 case DW_TAG_structure_type
:
10666 case DW_TAG_union_type
:
10667 process_structure_scope (die
, cu
);
10669 case DW_TAG_enumeration_type
:
10670 process_enumeration_scope (die
, cu
);
10673 /* These dies have a type, but processing them does not create
10674 a symbol or recurse to process the children. Therefore we can
10675 read them on-demand through read_type_die. */
10676 case DW_TAG_subroutine_type
:
10677 case DW_TAG_set_type
:
10678 case DW_TAG_array_type
:
10679 case DW_TAG_pointer_type
:
10680 case DW_TAG_ptr_to_member_type
:
10681 case DW_TAG_reference_type
:
10682 case DW_TAG_rvalue_reference_type
:
10683 case DW_TAG_string_type
:
10686 case DW_TAG_base_type
:
10687 case DW_TAG_subrange_type
:
10688 case DW_TAG_typedef
:
10689 /* Add a typedef symbol for the type definition, if it has a
10691 new_symbol (die
, read_type_die (die
, cu
), cu
);
10693 case DW_TAG_common_block
:
10694 read_common_block (die
, cu
);
10696 case DW_TAG_common_inclusion
:
10698 case DW_TAG_namespace
:
10699 cu
->processing_has_namespace_info
= true;
10700 read_namespace (die
, cu
);
10702 case DW_TAG_module
:
10703 cu
->processing_has_namespace_info
= true;
10704 read_module (die
, cu
);
10706 case DW_TAG_imported_declaration
:
10707 cu
->processing_has_namespace_info
= true;
10708 if (read_namespace_alias (die
, cu
))
10710 /* The declaration is not a global namespace alias. */
10711 /* Fall through. */
10712 case DW_TAG_imported_module
:
10713 cu
->processing_has_namespace_info
= true;
10714 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
10715 || cu
->language
!= language_fortran
))
10716 complaint (_("Tag '%s' has unexpected children"),
10717 dwarf_tag_name (die
->tag
));
10718 read_import_statement (die
, cu
);
10721 case DW_TAG_imported_unit
:
10722 process_imported_unit_die (die
, cu
);
10725 case DW_TAG_variable
:
10726 read_variable (die
, cu
);
10730 new_symbol (die
, NULL
, cu
);
10735 /* DWARF name computation. */
10737 /* A helper function for dwarf2_compute_name which determines whether DIE
10738 needs to have the name of the scope prepended to the name listed in the
10742 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10744 struct attribute
*attr
;
10748 case DW_TAG_namespace
:
10749 case DW_TAG_typedef
:
10750 case DW_TAG_class_type
:
10751 case DW_TAG_interface_type
:
10752 case DW_TAG_structure_type
:
10753 case DW_TAG_union_type
:
10754 case DW_TAG_enumeration_type
:
10755 case DW_TAG_enumerator
:
10756 case DW_TAG_subprogram
:
10757 case DW_TAG_inlined_subroutine
:
10758 case DW_TAG_member
:
10759 case DW_TAG_imported_declaration
:
10762 case DW_TAG_variable
:
10763 case DW_TAG_constant
:
10764 /* We only need to prefix "globally" visible variables. These include
10765 any variable marked with DW_AT_external or any variable that
10766 lives in a namespace. [Variables in anonymous namespaces
10767 require prefixing, but they are not DW_AT_external.] */
10769 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
10771 struct dwarf2_cu
*spec_cu
= cu
;
10773 return die_needs_namespace (die_specification (die
, &spec_cu
),
10777 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10778 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
10779 && die
->parent
->tag
!= DW_TAG_module
)
10781 /* A variable in a lexical block of some kind does not need a
10782 namespace, even though in C++ such variables may be external
10783 and have a mangled name. */
10784 if (die
->parent
->tag
== DW_TAG_lexical_block
10785 || die
->parent
->tag
== DW_TAG_try_block
10786 || die
->parent
->tag
== DW_TAG_catch_block
10787 || die
->parent
->tag
== DW_TAG_subprogram
)
10796 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
10797 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10798 defined for the given DIE. */
10800 static struct attribute
*
10801 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
10803 struct attribute
*attr
;
10805 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
10807 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10812 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10813 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10814 defined for the given DIE. */
10816 static const char *
10817 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10819 const char *linkage_name
;
10821 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10822 if (linkage_name
== NULL
)
10823 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10825 return linkage_name
;
10828 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10829 compute the physname for the object, which include a method's:
10830 - formal parameters (C++),
10831 - receiver type (Go),
10833 The term "physname" is a bit confusing.
10834 For C++, for example, it is the demangled name.
10835 For Go, for example, it's the mangled name.
10837 For Ada, return the DIE's linkage name rather than the fully qualified
10838 name. PHYSNAME is ignored..
10840 The result is allocated on the objfile_obstack and canonicalized. */
10842 static const char *
10843 dwarf2_compute_name (const char *name
,
10844 struct die_info
*die
, struct dwarf2_cu
*cu
,
10847 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10850 name
= dwarf2_name (die
, cu
);
10852 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10853 but otherwise compute it by typename_concat inside GDB.
10854 FIXME: Actually this is not really true, or at least not always true.
10855 It's all very confusing. compute_and_set_names doesn't try to demangle
10856 Fortran names because there is no mangling standard. So new_symbol
10857 will set the demangled name to the result of dwarf2_full_name, and it is
10858 the demangled name that GDB uses if it exists. */
10859 if (cu
->language
== language_ada
10860 || (cu
->language
== language_fortran
&& physname
))
10862 /* For Ada unit, we prefer the linkage name over the name, as
10863 the former contains the exported name, which the user expects
10864 to be able to reference. Ideally, we want the user to be able
10865 to reference this entity using either natural or linkage name,
10866 but we haven't started looking at this enhancement yet. */
10867 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10869 if (linkage_name
!= NULL
)
10870 return linkage_name
;
10873 /* These are the only languages we know how to qualify names in. */
10875 && (cu
->language
== language_cplus
10876 || cu
->language
== language_fortran
|| cu
->language
== language_d
10877 || cu
->language
== language_rust
))
10879 if (die_needs_namespace (die
, cu
))
10881 const char *prefix
;
10882 const char *canonical_name
= NULL
;
10886 prefix
= determine_prefix (die
, cu
);
10887 if (*prefix
!= '\0')
10889 gdb::unique_xmalloc_ptr
<char> prefixed_name
10890 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10892 buf
.puts (prefixed_name
.get ());
10897 /* Template parameters may be specified in the DIE's DW_AT_name, or
10898 as children with DW_TAG_template_type_param or
10899 DW_TAG_value_type_param. If the latter, add them to the name
10900 here. If the name already has template parameters, then
10901 skip this step; some versions of GCC emit both, and
10902 it is more efficient to use the pre-computed name.
10904 Something to keep in mind about this process: it is very
10905 unlikely, or in some cases downright impossible, to produce
10906 something that will match the mangled name of a function.
10907 If the definition of the function has the same debug info,
10908 we should be able to match up with it anyway. But fallbacks
10909 using the minimal symbol, for instance to find a method
10910 implemented in a stripped copy of libstdc++, will not work.
10911 If we do not have debug info for the definition, we will have to
10912 match them up some other way.
10914 When we do name matching there is a related problem with function
10915 templates; two instantiated function templates are allowed to
10916 differ only by their return types, which we do not add here. */
10918 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10920 struct attribute
*attr
;
10921 struct die_info
*child
;
10924 die
->building_fullname
= 1;
10926 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10930 const gdb_byte
*bytes
;
10931 struct dwarf2_locexpr_baton
*baton
;
10934 if (child
->tag
!= DW_TAG_template_type_param
10935 && child
->tag
!= DW_TAG_template_value_param
)
10946 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10949 complaint (_("template parameter missing DW_AT_type"));
10950 buf
.puts ("UNKNOWN_TYPE");
10953 type
= die_type (child
, cu
);
10955 if (child
->tag
== DW_TAG_template_type_param
)
10957 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10958 &type_print_raw_options
);
10962 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10965 complaint (_("template parameter missing "
10966 "DW_AT_const_value"));
10967 buf
.puts ("UNKNOWN_VALUE");
10971 dwarf2_const_value_attr (attr
, type
, name
,
10972 &cu
->comp_unit_obstack
, cu
,
10973 &value
, &bytes
, &baton
);
10975 if (TYPE_NOSIGN (type
))
10976 /* GDB prints characters as NUMBER 'CHAR'. If that's
10977 changed, this can use value_print instead. */
10978 c_printchar (value
, type
, &buf
);
10981 struct value_print_options opts
;
10984 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10988 else if (bytes
!= NULL
)
10990 v
= allocate_value (type
);
10991 memcpy (value_contents_writeable (v
), bytes
,
10992 TYPE_LENGTH (type
));
10995 v
= value_from_longest (type
, value
);
10997 /* Specify decimal so that we do not depend on
10999 get_formatted_print_options (&opts
, 'd');
11001 value_print (v
, &buf
, &opts
);
11006 die
->building_fullname
= 0;
11010 /* Close the argument list, with a space if necessary
11011 (nested templates). */
11012 if (!buf
.empty () && buf
.string ().back () == '>')
11019 /* For C++ methods, append formal parameter type
11020 information, if PHYSNAME. */
11022 if (physname
&& die
->tag
== DW_TAG_subprogram
11023 && cu
->language
== language_cplus
)
11025 struct type
*type
= read_type_die (die
, cu
);
11027 c_type_print_args (type
, &buf
, 1, cu
->language
,
11028 &type_print_raw_options
);
11030 if (cu
->language
== language_cplus
)
11032 /* Assume that an artificial first parameter is
11033 "this", but do not crash if it is not. RealView
11034 marks unnamed (and thus unused) parameters as
11035 artificial; there is no way to differentiate
11037 if (TYPE_NFIELDS (type
) > 0
11038 && TYPE_FIELD_ARTIFICIAL (type
, 0)
11039 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
11040 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
11042 buf
.puts (" const");
11046 const std::string
&intermediate_name
= buf
.string ();
11048 if (cu
->language
== language_cplus
)
11050 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
11051 &objfile
->per_bfd
->storage_obstack
);
11053 /* If we only computed INTERMEDIATE_NAME, or if
11054 INTERMEDIATE_NAME is already canonical, then we need to
11055 copy it to the appropriate obstack. */
11056 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
11057 name
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
11058 intermediate_name
);
11060 name
= canonical_name
;
11067 /* Return the fully qualified name of DIE, based on its DW_AT_name.
11068 If scope qualifiers are appropriate they will be added. The result
11069 will be allocated on the storage_obstack, or NULL if the DIE does
11070 not have a name. NAME may either be from a previous call to
11071 dwarf2_name or NULL.
11073 The output string will be canonicalized (if C++). */
11075 static const char *
11076 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
11078 return dwarf2_compute_name (name
, die
, cu
, 0);
11081 /* Construct a physname for the given DIE in CU. NAME may either be
11082 from a previous call to dwarf2_name or NULL. The result will be
11083 allocated on the objfile_objstack or NULL if the DIE does not have a
11086 The output string will be canonicalized (if C++). */
11088 static const char *
11089 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
11091 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
11092 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
11095 /* In this case dwarf2_compute_name is just a shortcut not building anything
11097 if (!die_needs_namespace (die
, cu
))
11098 return dwarf2_compute_name (name
, die
, cu
, 1);
11100 mangled
= dw2_linkage_name (die
, cu
);
11102 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
11103 See https://github.com/rust-lang/rust/issues/32925. */
11104 if (cu
->language
== language_rust
&& mangled
!= NULL
11105 && strchr (mangled
, '{') != NULL
)
11108 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
11110 gdb::unique_xmalloc_ptr
<char> demangled
;
11111 if (mangled
!= NULL
)
11114 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
11116 /* Do nothing (do not demangle the symbol name). */
11118 else if (cu
->language
== language_go
)
11120 /* This is a lie, but we already lie to the caller new_symbol.
11121 new_symbol assumes we return the mangled name.
11122 This just undoes that lie until things are cleaned up. */
11126 /* Use DMGL_RET_DROP for C++ template functions to suppress
11127 their return type. It is easier for GDB users to search
11128 for such functions as `name(params)' than `long name(params)'.
11129 In such case the minimal symbol names do not match the full
11130 symbol names but for template functions there is never a need
11131 to look up their definition from their declaration so
11132 the only disadvantage remains the minimal symbol variant
11133 `long name(params)' does not have the proper inferior type. */
11134 demangled
.reset (gdb_demangle (mangled
,
11135 (DMGL_PARAMS
| DMGL_ANSI
11136 | DMGL_RET_DROP
)));
11139 canon
= demangled
.get ();
11147 if (canon
== NULL
|| check_physname
)
11149 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
11151 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
11153 /* It may not mean a bug in GDB. The compiler could also
11154 compute DW_AT_linkage_name incorrectly. But in such case
11155 GDB would need to be bug-to-bug compatible. */
11157 complaint (_("Computed physname <%s> does not match demangled <%s> "
11158 "(from linkage <%s>) - DIE at %s [in module %s]"),
11159 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
11160 objfile_name (objfile
));
11162 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
11163 is available here - over computed PHYSNAME. It is safer
11164 against both buggy GDB and buggy compilers. */
11178 retval
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
, retval
);
11183 /* Inspect DIE in CU for a namespace alias. If one exists, record
11184 a new symbol for it.
11186 Returns 1 if a namespace alias was recorded, 0 otherwise. */
11189 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
11191 struct attribute
*attr
;
11193 /* If the die does not have a name, this is not a namespace
11195 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
11199 struct die_info
*d
= die
;
11200 struct dwarf2_cu
*imported_cu
= cu
;
11202 /* If the compiler has nested DW_AT_imported_declaration DIEs,
11203 keep inspecting DIEs until we hit the underlying import. */
11204 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
11205 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
11207 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
11211 d
= follow_die_ref (d
, attr
, &imported_cu
);
11212 if (d
->tag
!= DW_TAG_imported_declaration
)
11216 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
11218 complaint (_("DIE at %s has too many recursively imported "
11219 "declarations"), sect_offset_str (d
->sect_off
));
11226 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
11228 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
11229 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
11231 /* This declaration is a global namespace alias. Add
11232 a symbol for it whose type is the aliased namespace. */
11233 new_symbol (die
, type
, cu
);
11242 /* Return the using directives repository (global or local?) to use in the
11243 current context for CU.
11245 For Ada, imported declarations can materialize renamings, which *may* be
11246 global. However it is impossible (for now?) in DWARF to distinguish
11247 "external" imported declarations and "static" ones. As all imported
11248 declarations seem to be static in all other languages, make them all CU-wide
11249 global only in Ada. */
11251 static struct using_direct
**
11252 using_directives (struct dwarf2_cu
*cu
)
11254 if (cu
->language
== language_ada
11255 && cu
->get_builder ()->outermost_context_p ())
11256 return cu
->get_builder ()->get_global_using_directives ();
11258 return cu
->get_builder ()->get_local_using_directives ();
11261 /* Read the import statement specified by the given die and record it. */
11264 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
11266 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
11267 struct attribute
*import_attr
;
11268 struct die_info
*imported_die
, *child_die
;
11269 struct dwarf2_cu
*imported_cu
;
11270 const char *imported_name
;
11271 const char *imported_name_prefix
;
11272 const char *canonical_name
;
11273 const char *import_alias
;
11274 const char *imported_declaration
= NULL
;
11275 const char *import_prefix
;
11276 std::vector
<const char *> excludes
;
11278 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
11279 if (import_attr
== NULL
)
11281 complaint (_("Tag '%s' has no DW_AT_import"),
11282 dwarf_tag_name (die
->tag
));
11287 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
11288 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11289 if (imported_name
== NULL
)
11291 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
11293 The import in the following code:
11307 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
11308 <52> DW_AT_decl_file : 1
11309 <53> DW_AT_decl_line : 6
11310 <54> DW_AT_import : <0x75>
11311 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
11312 <59> DW_AT_name : B
11313 <5b> DW_AT_decl_file : 1
11314 <5c> DW_AT_decl_line : 2
11315 <5d> DW_AT_type : <0x6e>
11317 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
11318 <76> DW_AT_byte_size : 4
11319 <77> DW_AT_encoding : 5 (signed)
11321 imports the wrong die ( 0x75 instead of 0x58 ).
11322 This case will be ignored until the gcc bug is fixed. */
11326 /* Figure out the local name after import. */
11327 import_alias
= dwarf2_name (die
, cu
);
11329 /* Figure out where the statement is being imported to. */
11330 import_prefix
= determine_prefix (die
, cu
);
11332 /* Figure out what the scope of the imported die is and prepend it
11333 to the name of the imported die. */
11334 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
11336 if (imported_die
->tag
!= DW_TAG_namespace
11337 && imported_die
->tag
!= DW_TAG_module
)
11339 imported_declaration
= imported_name
;
11340 canonical_name
= imported_name_prefix
;
11342 else if (strlen (imported_name_prefix
) > 0)
11343 canonical_name
= obconcat (&objfile
->objfile_obstack
,
11344 imported_name_prefix
,
11345 (cu
->language
== language_d
? "." : "::"),
11346 imported_name
, (char *) NULL
);
11348 canonical_name
= imported_name
;
11350 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
11351 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
11352 child_die
= sibling_die (child_die
))
11354 /* DWARF-4: A Fortran use statement with a “rename list” may be
11355 represented by an imported module entry with an import attribute
11356 referring to the module and owned entries corresponding to those
11357 entities that are renamed as part of being imported. */
11359 if (child_die
->tag
!= DW_TAG_imported_declaration
)
11361 complaint (_("child DW_TAG_imported_declaration expected "
11362 "- DIE at %s [in module %s]"),
11363 sect_offset_str (child_die
->sect_off
),
11364 objfile_name (objfile
));
11368 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
11369 if (import_attr
== NULL
)
11371 complaint (_("Tag '%s' has no DW_AT_import"),
11372 dwarf_tag_name (child_die
->tag
));
11377 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
11379 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11380 if (imported_name
== NULL
)
11382 complaint (_("child DW_TAG_imported_declaration has unknown "
11383 "imported name - DIE at %s [in module %s]"),
11384 sect_offset_str (child_die
->sect_off
),
11385 objfile_name (objfile
));
11389 excludes
.push_back (imported_name
);
11391 process_die (child_die
, cu
);
11394 add_using_directive (using_directives (cu
),
11398 imported_declaration
,
11401 &objfile
->objfile_obstack
);
11404 /* ICC<14 does not output the required DW_AT_declaration on incomplete
11405 types, but gives them a size of zero. Starting with version 14,
11406 ICC is compatible with GCC. */
11409 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
11411 if (!cu
->checked_producer
)
11412 check_producer (cu
);
11414 return cu
->producer_is_icc_lt_14
;
11417 /* ICC generates a DW_AT_type for C void functions. This was observed on
11418 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
11419 which says that void functions should not have a DW_AT_type. */
11422 producer_is_icc (struct dwarf2_cu
*cu
)
11424 if (!cu
->checked_producer
)
11425 check_producer (cu
);
11427 return cu
->producer_is_icc
;
11430 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
11431 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
11432 this, it was first present in GCC release 4.3.0. */
11435 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
11437 if (!cu
->checked_producer
)
11438 check_producer (cu
);
11440 return cu
->producer_is_gcc_lt_4_3
;
11443 static file_and_directory
11444 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
11446 file_and_directory res
;
11448 /* Find the filename. Do not use dwarf2_name here, since the filename
11449 is not a source language identifier. */
11450 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
11451 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
11453 if (res
.comp_dir
== NULL
11454 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
11455 && IS_ABSOLUTE_PATH (res
.name
))
11457 res
.comp_dir_storage
= ldirname (res
.name
);
11458 if (!res
.comp_dir_storage
.empty ())
11459 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
11461 if (res
.comp_dir
!= NULL
)
11463 /* Irix 6.2 native cc prepends <machine>.: to the compilation
11464 directory, get rid of it. */
11465 const char *cp
= strchr (res
.comp_dir
, ':');
11467 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
11468 res
.comp_dir
= cp
+ 1;
11471 if (res
.name
== NULL
)
11472 res
.name
= "<unknown>";
11477 /* Handle DW_AT_stmt_list for a compilation unit.
11478 DIE is the DW_TAG_compile_unit die for CU.
11479 COMP_DIR is the compilation directory. LOWPC is passed to
11480 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
11483 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
11484 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
11486 struct dwarf2_per_objfile
*dwarf2_per_objfile
11487 = cu
->per_cu
->dwarf2_per_objfile
;
11488 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11489 struct attribute
*attr
;
11490 struct line_header line_header_local
;
11491 hashval_t line_header_local_hash
;
11493 int decode_mapping
;
11495 gdb_assert (! cu
->per_cu
->is_debug_types
);
11497 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
11501 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11503 /* The line header hash table is only created if needed (it exists to
11504 prevent redundant reading of the line table for partial_units).
11505 If we're given a partial_unit, we'll need it. If we're given a
11506 compile_unit, then use the line header hash table if it's already
11507 created, but don't create one just yet. */
11509 if (dwarf2_per_objfile
->line_header_hash
== NULL
11510 && die
->tag
== DW_TAG_partial_unit
)
11512 dwarf2_per_objfile
->line_header_hash
11513 = htab_create_alloc_ex (127, line_header_hash_voidp
,
11514 line_header_eq_voidp
,
11515 free_line_header_voidp
,
11516 &objfile
->objfile_obstack
,
11517 hashtab_obstack_allocate
,
11518 dummy_obstack_deallocate
);
11521 line_header_local
.sect_off
= line_offset
;
11522 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
11523 line_header_local_hash
= line_header_hash (&line_header_local
);
11524 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
11526 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11527 &line_header_local
,
11528 line_header_local_hash
, NO_INSERT
);
11530 /* For DW_TAG_compile_unit we need info like symtab::linetable which
11531 is not present in *SLOT (since if there is something in *SLOT then
11532 it will be for a partial_unit). */
11533 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
11535 gdb_assert (*slot
!= NULL
);
11536 cu
->line_header
= (struct line_header
*) *slot
;
11541 /* dwarf_decode_line_header does not yet provide sufficient information.
11542 We always have to call also dwarf_decode_lines for it. */
11543 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
11547 cu
->line_header
= lh
.release ();
11548 cu
->line_header_die_owner
= die
;
11550 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
11554 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11555 &line_header_local
,
11556 line_header_local_hash
, INSERT
);
11557 gdb_assert (slot
!= NULL
);
11559 if (slot
!= NULL
&& *slot
== NULL
)
11561 /* This newly decoded line number information unit will be owned
11562 by line_header_hash hash table. */
11563 *slot
= cu
->line_header
;
11564 cu
->line_header_die_owner
= NULL
;
11568 /* We cannot free any current entry in (*slot) as that struct line_header
11569 may be already used by multiple CUs. Create only temporary decoded
11570 line_header for this CU - it may happen at most once for each line
11571 number information unit. And if we're not using line_header_hash
11572 then this is what we want as well. */
11573 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
11575 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
11576 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
11581 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
11584 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11586 struct dwarf2_per_objfile
*dwarf2_per_objfile
11587 = cu
->per_cu
->dwarf2_per_objfile
;
11588 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11589 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11590 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
11591 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
11592 struct attribute
*attr
;
11593 struct die_info
*child_die
;
11594 CORE_ADDR baseaddr
;
11596 prepare_one_comp_unit (cu
, die
, cu
->language
);
11597 baseaddr
= objfile
->text_section_offset ();
11599 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
11601 /* If we didn't find a lowpc, set it to highpc to avoid complaints
11602 from finish_block. */
11603 if (lowpc
== ((CORE_ADDR
) -1))
11605 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11607 file_and_directory fnd
= find_file_and_directory (die
, cu
);
11609 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
11610 standardised yet. As a workaround for the language detection we fall
11611 back to the DW_AT_producer string. */
11612 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
11613 cu
->language
= language_opencl
;
11615 /* Similar hack for Go. */
11616 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
11617 set_cu_language (DW_LANG_Go
, cu
);
11619 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
11621 /* Decode line number information if present. We do this before
11622 processing child DIEs, so that the line header table is available
11623 for DW_AT_decl_file. */
11624 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
11626 /* Process all dies in compilation unit. */
11627 if (die
->child
!= NULL
)
11629 child_die
= die
->child
;
11630 while (child_die
&& child_die
->tag
)
11632 process_die (child_die
, cu
);
11633 child_die
= sibling_die (child_die
);
11637 /* Decode macro information, if present. Dwarf 2 macro information
11638 refers to information in the line number info statement program
11639 header, so we can only read it if we've read the header
11641 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
11643 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
11644 if (attr
&& cu
->line_header
)
11646 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
11647 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
11649 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
11653 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
11654 if (attr
&& cu
->line_header
)
11656 unsigned int macro_offset
= DW_UNSND (attr
);
11658 dwarf_decode_macros (cu
, macro_offset
, 0);
11664 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
11666 struct type_unit_group
*tu_group
;
11668 struct attribute
*attr
;
11670 struct signatured_type
*sig_type
;
11672 gdb_assert (per_cu
->is_debug_types
);
11673 sig_type
= (struct signatured_type
*) per_cu
;
11675 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
11677 /* If we're using .gdb_index (includes -readnow) then
11678 per_cu->type_unit_group may not have been set up yet. */
11679 if (sig_type
->type_unit_group
== NULL
)
11680 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
11681 tu_group
= sig_type
->type_unit_group
;
11683 /* If we've already processed this stmt_list there's no real need to
11684 do it again, we could fake it and just recreate the part we need
11685 (file name,index -> symtab mapping). If data shows this optimization
11686 is useful we can do it then. */
11687 first_time
= tu_group
->compunit_symtab
== NULL
;
11689 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
11694 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11695 lh
= dwarf_decode_line_header (line_offset
, this);
11700 start_symtab ("", NULL
, 0);
11703 gdb_assert (tu_group
->symtabs
== NULL
);
11704 gdb_assert (m_builder
== nullptr);
11705 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
11706 m_builder
.reset (new struct buildsym_compunit
11707 (COMPUNIT_OBJFILE (cust
), "",
11708 COMPUNIT_DIRNAME (cust
),
11709 compunit_language (cust
),
11715 line_header
= lh
.release ();
11716 line_header_die_owner
= die
;
11720 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
11722 /* Note: We don't assign tu_group->compunit_symtab yet because we're
11723 still initializing it, and our caller (a few levels up)
11724 process_full_type_unit still needs to know if this is the first
11727 tu_group
->num_symtabs
= line_header
->file_names_size ();
11728 tu_group
->symtabs
= XNEWVEC (struct symtab
*,
11729 line_header
->file_names_size ());
11731 auto &file_names
= line_header
->file_names ();
11732 for (i
= 0; i
< file_names
.size (); ++i
)
11734 file_entry
&fe
= file_names
[i
];
11735 dwarf2_start_subfile (this, fe
.name
,
11736 fe
.include_dir (line_header
));
11737 buildsym_compunit
*b
= get_builder ();
11738 if (b
->get_current_subfile ()->symtab
== NULL
)
11740 /* NOTE: start_subfile will recognize when it's been
11741 passed a file it has already seen. So we can't
11742 assume there's a simple mapping from
11743 cu->line_header->file_names to subfiles, plus
11744 cu->line_header->file_names may contain dups. */
11745 b
->get_current_subfile ()->symtab
11746 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
11749 fe
.symtab
= b
->get_current_subfile ()->symtab
;
11750 tu_group
->symtabs
[i
] = fe
.symtab
;
11755 gdb_assert (m_builder
== nullptr);
11756 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
11757 m_builder
.reset (new struct buildsym_compunit
11758 (COMPUNIT_OBJFILE (cust
), "",
11759 COMPUNIT_DIRNAME (cust
),
11760 compunit_language (cust
),
11763 auto &file_names
= line_header
->file_names ();
11764 for (i
= 0; i
< file_names
.size (); ++i
)
11766 file_entry
&fe
= file_names
[i
];
11767 fe
.symtab
= tu_group
->symtabs
[i
];
11771 /* The main symtab is allocated last. Type units don't have DW_AT_name
11772 so they don't have a "real" (so to speak) symtab anyway.
11773 There is later code that will assign the main symtab to all symbols
11774 that don't have one. We need to handle the case of a symbol with a
11775 missing symtab (DW_AT_decl_file) anyway. */
11778 /* Process DW_TAG_type_unit.
11779 For TUs we want to skip the first top level sibling if it's not the
11780 actual type being defined by this TU. In this case the first top
11781 level sibling is there to provide context only. */
11784 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11786 struct die_info
*child_die
;
11788 prepare_one_comp_unit (cu
, die
, language_minimal
);
11790 /* Initialize (or reinitialize) the machinery for building symtabs.
11791 We do this before processing child DIEs, so that the line header table
11792 is available for DW_AT_decl_file. */
11793 cu
->setup_type_unit_groups (die
);
11795 if (die
->child
!= NULL
)
11797 child_die
= die
->child
;
11798 while (child_die
&& child_die
->tag
)
11800 process_die (child_die
, cu
);
11801 child_die
= sibling_die (child_die
);
11808 http://gcc.gnu.org/wiki/DebugFission
11809 http://gcc.gnu.org/wiki/DebugFissionDWP
11811 To simplify handling of both DWO files ("object" files with the DWARF info)
11812 and DWP files (a file with the DWOs packaged up into one file), we treat
11813 DWP files as having a collection of virtual DWO files. */
11816 hash_dwo_file (const void *item
)
11818 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11821 hash
= htab_hash_string (dwo_file
->dwo_name
);
11822 if (dwo_file
->comp_dir
!= NULL
)
11823 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11828 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11830 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11831 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11833 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11835 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11836 return lhs
->comp_dir
== rhs
->comp_dir
;
11837 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11840 /* Allocate a hash table for DWO files. */
11843 allocate_dwo_file_hash_table (struct objfile
*objfile
)
11845 auto delete_dwo_file
= [] (void *item
)
11847 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
11852 return htab_up (htab_create_alloc_ex (41,
11856 &objfile
->objfile_obstack
,
11857 hashtab_obstack_allocate
,
11858 dummy_obstack_deallocate
));
11861 /* Lookup DWO file DWO_NAME. */
11864 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11865 const char *dwo_name
,
11866 const char *comp_dir
)
11868 struct dwo_file find_entry
;
11871 if (dwarf2_per_objfile
->dwo_files
== NULL
)
11872 dwarf2_per_objfile
->dwo_files
11873 = allocate_dwo_file_hash_table (dwarf2_per_objfile
->objfile
);
11875 find_entry
.dwo_name
= dwo_name
;
11876 find_entry
.comp_dir
= comp_dir
;
11877 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
.get (), &find_entry
,
11884 hash_dwo_unit (const void *item
)
11886 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11888 /* This drops the top 32 bits of the id, but is ok for a hash. */
11889 return dwo_unit
->signature
;
11893 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11895 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11896 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11898 /* The signature is assumed to be unique within the DWO file.
11899 So while object file CU dwo_id's always have the value zero,
11900 that's OK, assuming each object file DWO file has only one CU,
11901 and that's the rule for now. */
11902 return lhs
->signature
== rhs
->signature
;
11905 /* Allocate a hash table for DWO CUs,TUs.
11906 There is one of these tables for each of CUs,TUs for each DWO file. */
11909 allocate_dwo_unit_table (struct objfile
*objfile
)
11911 /* Start out with a pretty small number.
11912 Generally DWO files contain only one CU and maybe some TUs. */
11913 return htab_create_alloc_ex (3,
11917 &objfile
->objfile_obstack
,
11918 hashtab_obstack_allocate
,
11919 dummy_obstack_deallocate
);
11922 /* die_reader_func for create_dwo_cu. */
11925 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11926 const gdb_byte
*info_ptr
,
11927 struct die_info
*comp_unit_die
,
11929 struct dwo_file
*dwo_file
,
11930 struct dwo_unit
*dwo_unit
)
11932 struct dwarf2_cu
*cu
= reader
->cu
;
11933 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11934 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11936 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11937 if (!signature
.has_value ())
11939 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11940 " its dwo_id [in module %s]"),
11941 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11945 dwo_unit
->dwo_file
= dwo_file
;
11946 dwo_unit
->signature
= *signature
;
11947 dwo_unit
->section
= section
;
11948 dwo_unit
->sect_off
= sect_off
;
11949 dwo_unit
->length
= cu
->per_cu
->length
;
11951 if (dwarf_read_debug
)
11952 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11953 sect_offset_str (sect_off
),
11954 hex_string (dwo_unit
->signature
));
11957 /* Create the dwo_units for the CUs in a DWO_FILE.
11958 Note: This function processes DWO files only, not DWP files. */
11961 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11962 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11963 dwarf2_section_info
§ion
, htab_t
&cus_htab
)
11965 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11966 const gdb_byte
*info_ptr
, *end_ptr
;
11968 dwarf2_read_section (objfile
, §ion
);
11969 info_ptr
= section
.buffer
;
11971 if (info_ptr
== NULL
)
11974 if (dwarf_read_debug
)
11976 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11977 get_section_name (§ion
),
11978 get_section_file_name (§ion
));
11981 end_ptr
= info_ptr
+ section
.size
;
11982 while (info_ptr
< end_ptr
)
11984 struct dwarf2_per_cu_data per_cu
;
11985 struct dwo_unit read_unit
{};
11986 struct dwo_unit
*dwo_unit
;
11988 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11990 memset (&per_cu
, 0, sizeof (per_cu
));
11991 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
11992 per_cu
.is_debug_types
= 0;
11993 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11994 per_cu
.section
= §ion
;
11996 cutu_reader
reader (&per_cu
, cu
, &dwo_file
);
11997 if (!reader
.dummy_p
)
11998 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11999 reader
.has_children
, &dwo_file
, &read_unit
);
12000 info_ptr
+= per_cu
.length
;
12002 // If the unit could not be parsed, skip it.
12003 if (read_unit
.dwo_file
== NULL
)
12006 if (cus_htab
== NULL
)
12007 cus_htab
= allocate_dwo_unit_table (objfile
);
12009 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12010 *dwo_unit
= read_unit
;
12011 slot
= htab_find_slot (cus_htab
, dwo_unit
, INSERT
);
12012 gdb_assert (slot
!= NULL
);
12015 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
12016 sect_offset dup_sect_off
= dup_cu
->sect_off
;
12018 complaint (_("debug cu entry at offset %s is duplicate to"
12019 " the entry at offset %s, signature %s"),
12020 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
12021 hex_string (dwo_unit
->signature
));
12023 *slot
= (void *)dwo_unit
;
12027 /* DWP file .debug_{cu,tu}_index section format:
12028 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
12032 Both index sections have the same format, and serve to map a 64-bit
12033 signature to a set of section numbers. Each section begins with a header,
12034 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
12035 indexes, and a pool of 32-bit section numbers. The index sections will be
12036 aligned at 8-byte boundaries in the file.
12038 The index section header consists of:
12040 V, 32 bit version number
12042 N, 32 bit number of compilation units or type units in the index
12043 M, 32 bit number of slots in the hash table
12045 Numbers are recorded using the byte order of the application binary.
12047 The hash table begins at offset 16 in the section, and consists of an array
12048 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
12049 order of the application binary). Unused slots in the hash table are 0.
12050 (We rely on the extreme unlikeliness of a signature being exactly 0.)
12052 The parallel table begins immediately after the hash table
12053 (at offset 16 + 8 * M from the beginning of the section), and consists of an
12054 array of 32-bit indexes (using the byte order of the application binary),
12055 corresponding 1-1 with slots in the hash table. Each entry in the parallel
12056 table contains a 32-bit index into the pool of section numbers. For unused
12057 hash table slots, the corresponding entry in the parallel table will be 0.
12059 The pool of section numbers begins immediately following the hash table
12060 (at offset 16 + 12 * M from the beginning of the section). The pool of
12061 section numbers consists of an array of 32-bit words (using the byte order
12062 of the application binary). Each item in the array is indexed starting
12063 from 0. The hash table entry provides the index of the first section
12064 number in the set. Additional section numbers in the set follow, and the
12065 set is terminated by a 0 entry (section number 0 is not used in ELF).
12067 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
12068 section must be the first entry in the set, and the .debug_abbrev.dwo must
12069 be the second entry. Other members of the set may follow in any order.
12075 DWP Version 2 combines all the .debug_info, etc. sections into one,
12076 and the entries in the index tables are now offsets into these sections.
12077 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
12080 Index Section Contents:
12082 Hash Table of Signatures dwp_hash_table.hash_table
12083 Parallel Table of Indices dwp_hash_table.unit_table
12084 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
12085 Table of Section Sizes dwp_hash_table.v2.sizes
12087 The index section header consists of:
12089 V, 32 bit version number
12090 L, 32 bit number of columns in the table of section offsets
12091 N, 32 bit number of compilation units or type units in the index
12092 M, 32 bit number of slots in the hash table
12094 Numbers are recorded using the byte order of the application binary.
12096 The hash table has the same format as version 1.
12097 The parallel table of indices has the same format as version 1,
12098 except that the entries are origin-1 indices into the table of sections
12099 offsets and the table of section sizes.
12101 The table of offsets begins immediately following the parallel table
12102 (at offset 16 + 12 * M from the beginning of the section). The table is
12103 a two-dimensional array of 32-bit words (using the byte order of the
12104 application binary), with L columns and N+1 rows, in row-major order.
12105 Each row in the array is indexed starting from 0. The first row provides
12106 a key to the remaining rows: each column in this row provides an identifier
12107 for a debug section, and the offsets in the same column of subsequent rows
12108 refer to that section. The section identifiers are:
12110 DW_SECT_INFO 1 .debug_info.dwo
12111 DW_SECT_TYPES 2 .debug_types.dwo
12112 DW_SECT_ABBREV 3 .debug_abbrev.dwo
12113 DW_SECT_LINE 4 .debug_line.dwo
12114 DW_SECT_LOC 5 .debug_loc.dwo
12115 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
12116 DW_SECT_MACINFO 7 .debug_macinfo.dwo
12117 DW_SECT_MACRO 8 .debug_macro.dwo
12119 The offsets provided by the CU and TU index sections are the base offsets
12120 for the contributions made by each CU or TU to the corresponding section
12121 in the package file. Each CU and TU header contains an abbrev_offset
12122 field, used to find the abbreviations table for that CU or TU within the
12123 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
12124 be interpreted as relative to the base offset given in the index section.
12125 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
12126 should be interpreted as relative to the base offset for .debug_line.dwo,
12127 and offsets into other debug sections obtained from DWARF attributes should
12128 also be interpreted as relative to the corresponding base offset.
12130 The table of sizes begins immediately following the table of offsets.
12131 Like the table of offsets, it is a two-dimensional array of 32-bit words,
12132 with L columns and N rows, in row-major order. Each row in the array is
12133 indexed starting from 1 (row 0 is shared by the two tables).
12137 Hash table lookup is handled the same in version 1 and 2:
12139 We assume that N and M will not exceed 2^32 - 1.
12140 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
12142 Given a 64-bit compilation unit signature or a type signature S, an entry
12143 in the hash table is located as follows:
12145 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
12146 the low-order k bits all set to 1.
12148 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
12150 3) If the hash table entry at index H matches the signature, use that
12151 entry. If the hash table entry at index H is unused (all zeroes),
12152 terminate the search: the signature is not present in the table.
12154 4) Let H = (H + H') modulo M. Repeat at Step 3.
12156 Because M > N and H' and M are relatively prime, the search is guaranteed
12157 to stop at an unused slot or find the match. */
12159 /* Create a hash table to map DWO IDs to their CU/TU entry in
12160 .debug_{info,types}.dwo in DWP_FILE.
12161 Returns NULL if there isn't one.
12162 Note: This function processes DWP files only, not DWO files. */
12164 static struct dwp_hash_table
*
12165 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12166 struct dwp_file
*dwp_file
, int is_debug_types
)
12168 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12169 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12170 const gdb_byte
*index_ptr
, *index_end
;
12171 struct dwarf2_section_info
*index
;
12172 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
12173 struct dwp_hash_table
*htab
;
12175 if (is_debug_types
)
12176 index
= &dwp_file
->sections
.tu_index
;
12178 index
= &dwp_file
->sections
.cu_index
;
12180 if (dwarf2_section_empty_p (index
))
12182 dwarf2_read_section (objfile
, index
);
12184 index_ptr
= index
->buffer
;
12185 index_end
= index_ptr
+ index
->size
;
12187 version
= read_4_bytes (dbfd
, index_ptr
);
12190 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
12194 nr_units
= read_4_bytes (dbfd
, index_ptr
);
12196 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
12199 if (version
!= 1 && version
!= 2)
12201 error (_("Dwarf Error: unsupported DWP file version (%s)"
12202 " [in module %s]"),
12203 pulongest (version
), dwp_file
->name
);
12205 if (nr_slots
!= (nr_slots
& -nr_slots
))
12207 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
12208 " is not power of 2 [in module %s]"),
12209 pulongest (nr_slots
), dwp_file
->name
);
12212 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
12213 htab
->version
= version
;
12214 htab
->nr_columns
= nr_columns
;
12215 htab
->nr_units
= nr_units
;
12216 htab
->nr_slots
= nr_slots
;
12217 htab
->hash_table
= index_ptr
;
12218 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
12220 /* Exit early if the table is empty. */
12221 if (nr_slots
== 0 || nr_units
== 0
12222 || (version
== 2 && nr_columns
== 0))
12224 /* All must be zero. */
12225 if (nr_slots
!= 0 || nr_units
!= 0
12226 || (version
== 2 && nr_columns
!= 0))
12228 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
12229 " all zero [in modules %s]"),
12237 htab
->section_pool
.v1
.indices
=
12238 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12239 /* It's harder to decide whether the section is too small in v1.
12240 V1 is deprecated anyway so we punt. */
12244 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12245 int *ids
= htab
->section_pool
.v2
.section_ids
;
12246 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
12247 /* Reverse map for error checking. */
12248 int ids_seen
[DW_SECT_MAX
+ 1];
12251 if (nr_columns
< 2)
12253 error (_("Dwarf Error: bad DWP hash table, too few columns"
12254 " in section table [in module %s]"),
12257 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
12259 error (_("Dwarf Error: bad DWP hash table, too many columns"
12260 " in section table [in module %s]"),
12263 memset (ids
, 255, sizeof_ids
);
12264 memset (ids_seen
, 255, sizeof (ids_seen
));
12265 for (i
= 0; i
< nr_columns
; ++i
)
12267 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
12269 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
12271 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
12272 " in section table [in module %s]"),
12273 id
, dwp_file
->name
);
12275 if (ids_seen
[id
] != -1)
12277 error (_("Dwarf Error: bad DWP hash table, duplicate section"
12278 " id %d in section table [in module %s]"),
12279 id
, dwp_file
->name
);
12284 /* Must have exactly one info or types section. */
12285 if (((ids_seen
[DW_SECT_INFO
] != -1)
12286 + (ids_seen
[DW_SECT_TYPES
] != -1))
12289 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
12290 " DWO info/types section [in module %s]"),
12293 /* Must have an abbrev section. */
12294 if (ids_seen
[DW_SECT_ABBREV
] == -1)
12296 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
12297 " section [in module %s]"),
12300 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
12301 htab
->section_pool
.v2
.sizes
=
12302 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
12303 * nr_units
* nr_columns
);
12304 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
12305 * nr_units
* nr_columns
))
12308 error (_("Dwarf Error: DWP index section is corrupt (too small)"
12309 " [in module %s]"),
12317 /* Update SECTIONS with the data from SECTP.
12319 This function is like the other "locate" section routines that are
12320 passed to bfd_map_over_sections, but in this context the sections to
12321 read comes from the DWP V1 hash table, not the full ELF section table.
12323 The result is non-zero for success, or zero if an error was found. */
12326 locate_v1_virtual_dwo_sections (asection
*sectp
,
12327 struct virtual_v1_dwo_sections
*sections
)
12329 const struct dwop_section_names
*names
= &dwop_section_names
;
12331 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12333 /* There can be only one. */
12334 if (sections
->abbrev
.s
.section
!= NULL
)
12336 sections
->abbrev
.s
.section
= sectp
;
12337 sections
->abbrev
.size
= bfd_section_size (sectp
);
12339 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
12340 || section_is_p (sectp
->name
, &names
->types_dwo
))
12342 /* There can be only one. */
12343 if (sections
->info_or_types
.s
.section
!= NULL
)
12345 sections
->info_or_types
.s
.section
= sectp
;
12346 sections
->info_or_types
.size
= bfd_section_size (sectp
);
12348 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12350 /* There can be only one. */
12351 if (sections
->line
.s
.section
!= NULL
)
12353 sections
->line
.s
.section
= sectp
;
12354 sections
->line
.size
= bfd_section_size (sectp
);
12356 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12358 /* There can be only one. */
12359 if (sections
->loc
.s
.section
!= NULL
)
12361 sections
->loc
.s
.section
= sectp
;
12362 sections
->loc
.size
= bfd_section_size (sectp
);
12364 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12366 /* There can be only one. */
12367 if (sections
->macinfo
.s
.section
!= NULL
)
12369 sections
->macinfo
.s
.section
= sectp
;
12370 sections
->macinfo
.size
= bfd_section_size (sectp
);
12372 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12374 /* There can be only one. */
12375 if (sections
->macro
.s
.section
!= NULL
)
12377 sections
->macro
.s
.section
= sectp
;
12378 sections
->macro
.size
= bfd_section_size (sectp
);
12380 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12382 /* There can be only one. */
12383 if (sections
->str_offsets
.s
.section
!= NULL
)
12385 sections
->str_offsets
.s
.section
= sectp
;
12386 sections
->str_offsets
.size
= bfd_section_size (sectp
);
12390 /* No other kind of section is valid. */
12397 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12398 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12399 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12400 This is for DWP version 1 files. */
12402 static struct dwo_unit
*
12403 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12404 struct dwp_file
*dwp_file
,
12405 uint32_t unit_index
,
12406 const char *comp_dir
,
12407 ULONGEST signature
, int is_debug_types
)
12409 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12410 const struct dwp_hash_table
*dwp_htab
=
12411 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12412 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12413 const char *kind
= is_debug_types
? "TU" : "CU";
12414 struct dwo_file
*dwo_file
;
12415 struct dwo_unit
*dwo_unit
;
12416 struct virtual_v1_dwo_sections sections
;
12417 void **dwo_file_slot
;
12420 gdb_assert (dwp_file
->version
== 1);
12422 if (dwarf_read_debug
)
12424 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
12426 pulongest (unit_index
), hex_string (signature
),
12430 /* Fetch the sections of this DWO unit.
12431 Put a limit on the number of sections we look for so that bad data
12432 doesn't cause us to loop forever. */
12434 #define MAX_NR_V1_DWO_SECTIONS \
12435 (1 /* .debug_info or .debug_types */ \
12436 + 1 /* .debug_abbrev */ \
12437 + 1 /* .debug_line */ \
12438 + 1 /* .debug_loc */ \
12439 + 1 /* .debug_str_offsets */ \
12440 + 1 /* .debug_macro or .debug_macinfo */ \
12441 + 1 /* trailing zero */)
12443 memset (§ions
, 0, sizeof (sections
));
12445 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
12448 uint32_t section_nr
=
12449 read_4_bytes (dbfd
,
12450 dwp_htab
->section_pool
.v1
.indices
12451 + (unit_index
+ i
) * sizeof (uint32_t));
12453 if (section_nr
== 0)
12455 if (section_nr
>= dwp_file
->num_sections
)
12457 error (_("Dwarf Error: bad DWP hash table, section number too large"
12458 " [in module %s]"),
12462 sectp
= dwp_file
->elf_sections
[section_nr
];
12463 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
12465 error (_("Dwarf Error: bad DWP hash table, invalid section found"
12466 " [in module %s]"),
12472 || dwarf2_section_empty_p (§ions
.info_or_types
)
12473 || dwarf2_section_empty_p (§ions
.abbrev
))
12475 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
12476 " [in module %s]"),
12479 if (i
== MAX_NR_V1_DWO_SECTIONS
)
12481 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
12482 " [in module %s]"),
12486 /* It's easier for the rest of the code if we fake a struct dwo_file and
12487 have dwo_unit "live" in that. At least for now.
12489 The DWP file can be made up of a random collection of CUs and TUs.
12490 However, for each CU + set of TUs that came from the same original DWO
12491 file, we can combine them back into a virtual DWO file to save space
12492 (fewer struct dwo_file objects to allocate). Remember that for really
12493 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12495 std::string virtual_dwo_name
=
12496 string_printf ("virtual-dwo/%d-%d-%d-%d",
12497 get_section_id (§ions
.abbrev
),
12498 get_section_id (§ions
.line
),
12499 get_section_id (§ions
.loc
),
12500 get_section_id (§ions
.str_offsets
));
12501 /* Can we use an existing virtual DWO file? */
12502 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12503 virtual_dwo_name
.c_str (),
12505 /* Create one if necessary. */
12506 if (*dwo_file_slot
== NULL
)
12508 if (dwarf_read_debug
)
12510 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12511 virtual_dwo_name
.c_str ());
12513 dwo_file
= new struct dwo_file
;
12514 dwo_file
->dwo_name
= obstack_strdup (&objfile
->objfile_obstack
,
12516 dwo_file
->comp_dir
= comp_dir
;
12517 dwo_file
->sections
.abbrev
= sections
.abbrev
;
12518 dwo_file
->sections
.line
= sections
.line
;
12519 dwo_file
->sections
.loc
= sections
.loc
;
12520 dwo_file
->sections
.macinfo
= sections
.macinfo
;
12521 dwo_file
->sections
.macro
= sections
.macro
;
12522 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
12523 /* The "str" section is global to the entire DWP file. */
12524 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12525 /* The info or types section is assigned below to dwo_unit,
12526 there's no need to record it in dwo_file.
12527 Also, we can't simply record type sections in dwo_file because
12528 we record a pointer into the vector in dwo_unit. As we collect more
12529 types we'll grow the vector and eventually have to reallocate space
12530 for it, invalidating all copies of pointers into the previous
12532 *dwo_file_slot
= dwo_file
;
12536 if (dwarf_read_debug
)
12538 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12539 virtual_dwo_name
.c_str ());
12541 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12544 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12545 dwo_unit
->dwo_file
= dwo_file
;
12546 dwo_unit
->signature
= signature
;
12547 dwo_unit
->section
=
12548 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12549 *dwo_unit
->section
= sections
.info_or_types
;
12550 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12555 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
12556 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
12557 piece within that section used by a TU/CU, return a virtual section
12558 of just that piece. */
12560 static struct dwarf2_section_info
12561 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12562 struct dwarf2_section_info
*section
,
12563 bfd_size_type offset
, bfd_size_type size
)
12565 struct dwarf2_section_info result
;
12568 gdb_assert (section
!= NULL
);
12569 gdb_assert (!section
->is_virtual
);
12571 memset (&result
, 0, sizeof (result
));
12572 result
.s
.containing_section
= section
;
12573 result
.is_virtual
= true;
12578 sectp
= get_section_bfd_section (section
);
12580 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
12581 bounds of the real section. This is a pretty-rare event, so just
12582 flag an error (easier) instead of a warning and trying to cope. */
12584 || offset
+ size
> bfd_section_size (sectp
))
12586 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
12587 " in section %s [in module %s]"),
12588 sectp
? bfd_section_name (sectp
) : "<unknown>",
12589 objfile_name (dwarf2_per_objfile
->objfile
));
12592 result
.virtual_offset
= offset
;
12593 result
.size
= size
;
12597 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12598 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12599 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12600 This is for DWP version 2 files. */
12602 static struct dwo_unit
*
12603 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12604 struct dwp_file
*dwp_file
,
12605 uint32_t unit_index
,
12606 const char *comp_dir
,
12607 ULONGEST signature
, int is_debug_types
)
12609 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12610 const struct dwp_hash_table
*dwp_htab
=
12611 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12612 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12613 const char *kind
= is_debug_types
? "TU" : "CU";
12614 struct dwo_file
*dwo_file
;
12615 struct dwo_unit
*dwo_unit
;
12616 struct virtual_v2_dwo_sections sections
;
12617 void **dwo_file_slot
;
12620 gdb_assert (dwp_file
->version
== 2);
12622 if (dwarf_read_debug
)
12624 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
12626 pulongest (unit_index
), hex_string (signature
),
12630 /* Fetch the section offsets of this DWO unit. */
12632 memset (§ions
, 0, sizeof (sections
));
12634 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12636 uint32_t offset
= read_4_bytes (dbfd
,
12637 dwp_htab
->section_pool
.v2
.offsets
12638 + (((unit_index
- 1) * dwp_htab
->nr_columns
12640 * sizeof (uint32_t)));
12641 uint32_t size
= read_4_bytes (dbfd
,
12642 dwp_htab
->section_pool
.v2
.sizes
12643 + (((unit_index
- 1) * dwp_htab
->nr_columns
12645 * sizeof (uint32_t)));
12647 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
12650 case DW_SECT_TYPES
:
12651 sections
.info_or_types_offset
= offset
;
12652 sections
.info_or_types_size
= size
;
12654 case DW_SECT_ABBREV
:
12655 sections
.abbrev_offset
= offset
;
12656 sections
.abbrev_size
= size
;
12659 sections
.line_offset
= offset
;
12660 sections
.line_size
= size
;
12663 sections
.loc_offset
= offset
;
12664 sections
.loc_size
= size
;
12666 case DW_SECT_STR_OFFSETS
:
12667 sections
.str_offsets_offset
= offset
;
12668 sections
.str_offsets_size
= size
;
12670 case DW_SECT_MACINFO
:
12671 sections
.macinfo_offset
= offset
;
12672 sections
.macinfo_size
= size
;
12674 case DW_SECT_MACRO
:
12675 sections
.macro_offset
= offset
;
12676 sections
.macro_size
= size
;
12681 /* It's easier for the rest of the code if we fake a struct dwo_file and
12682 have dwo_unit "live" in that. At least for now.
12684 The DWP file can be made up of a random collection of CUs and TUs.
12685 However, for each CU + set of TUs that came from the same original DWO
12686 file, we can combine them back into a virtual DWO file to save space
12687 (fewer struct dwo_file objects to allocate). Remember that for really
12688 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12690 std::string virtual_dwo_name
=
12691 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
12692 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12693 (long) (sections
.line_size
? sections
.line_offset
: 0),
12694 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
12695 (long) (sections
.str_offsets_size
12696 ? sections
.str_offsets_offset
: 0));
12697 /* Can we use an existing virtual DWO file? */
12698 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12699 virtual_dwo_name
.c_str (),
12701 /* Create one if necessary. */
12702 if (*dwo_file_slot
== NULL
)
12704 if (dwarf_read_debug
)
12706 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12707 virtual_dwo_name
.c_str ());
12709 dwo_file
= new struct dwo_file
;
12710 dwo_file
->dwo_name
= obstack_strdup (&objfile
->objfile_obstack
,
12712 dwo_file
->comp_dir
= comp_dir
;
12713 dwo_file
->sections
.abbrev
=
12714 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
12715 sections
.abbrev_offset
, sections
.abbrev_size
);
12716 dwo_file
->sections
.line
=
12717 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
12718 sections
.line_offset
, sections
.line_size
);
12719 dwo_file
->sections
.loc
=
12720 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
12721 sections
.loc_offset
, sections
.loc_size
);
12722 dwo_file
->sections
.macinfo
=
12723 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
12724 sections
.macinfo_offset
, sections
.macinfo_size
);
12725 dwo_file
->sections
.macro
=
12726 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
12727 sections
.macro_offset
, sections
.macro_size
);
12728 dwo_file
->sections
.str_offsets
=
12729 create_dwp_v2_section (dwarf2_per_objfile
,
12730 &dwp_file
->sections
.str_offsets
,
12731 sections
.str_offsets_offset
,
12732 sections
.str_offsets_size
);
12733 /* The "str" section is global to the entire DWP file. */
12734 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12735 /* The info or types section is assigned below to dwo_unit,
12736 there's no need to record it in dwo_file.
12737 Also, we can't simply record type sections in dwo_file because
12738 we record a pointer into the vector in dwo_unit. As we collect more
12739 types we'll grow the vector and eventually have to reallocate space
12740 for it, invalidating all copies of pointers into the previous
12742 *dwo_file_slot
= dwo_file
;
12746 if (dwarf_read_debug
)
12748 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12749 virtual_dwo_name
.c_str ());
12751 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12754 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12755 dwo_unit
->dwo_file
= dwo_file
;
12756 dwo_unit
->signature
= signature
;
12757 dwo_unit
->section
=
12758 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12759 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
12761 ? &dwp_file
->sections
.types
12762 : &dwp_file
->sections
.info
,
12763 sections
.info_or_types_offset
,
12764 sections
.info_or_types_size
);
12765 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12770 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12771 Returns NULL if the signature isn't found. */
12773 static struct dwo_unit
*
12774 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12775 struct dwp_file
*dwp_file
, const char *comp_dir
,
12776 ULONGEST signature
, int is_debug_types
)
12778 const struct dwp_hash_table
*dwp_htab
=
12779 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12780 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12781 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12782 uint32_t hash
= signature
& mask
;
12783 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12786 struct dwo_unit find_dwo_cu
;
12788 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12789 find_dwo_cu
.signature
= signature
;
12790 slot
= htab_find_slot (is_debug_types
12791 ? dwp_file
->loaded_tus
12792 : dwp_file
->loaded_cus
,
12793 &find_dwo_cu
, INSERT
);
12796 return (struct dwo_unit
*) *slot
;
12798 /* Use a for loop so that we don't loop forever on bad debug info. */
12799 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12801 ULONGEST signature_in_table
;
12803 signature_in_table
=
12804 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12805 if (signature_in_table
== signature
)
12807 uint32_t unit_index
=
12808 read_4_bytes (dbfd
,
12809 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12811 if (dwp_file
->version
== 1)
12813 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
12814 dwp_file
, unit_index
,
12815 comp_dir
, signature
,
12820 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
12821 dwp_file
, unit_index
,
12822 comp_dir
, signature
,
12825 return (struct dwo_unit
*) *slot
;
12827 if (signature_in_table
== 0)
12829 hash
= (hash
+ hash2
) & mask
;
12832 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12833 " [in module %s]"),
12837 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12838 Open the file specified by FILE_NAME and hand it off to BFD for
12839 preliminary analysis. Return a newly initialized bfd *, which
12840 includes a canonicalized copy of FILE_NAME.
12841 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12842 SEARCH_CWD is true if the current directory is to be searched.
12843 It will be searched before debug-file-directory.
12844 If successful, the file is added to the bfd include table of the
12845 objfile's bfd (see gdb_bfd_record_inclusion).
12846 If unable to find/open the file, return NULL.
12847 NOTE: This function is derived from symfile_bfd_open. */
12849 static gdb_bfd_ref_ptr
12850 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12851 const char *file_name
, int is_dwp
, int search_cwd
)
12854 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12855 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12856 to debug_file_directory. */
12857 const char *search_path
;
12858 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12860 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12863 if (*debug_file_directory
!= '\0')
12865 search_path_holder
.reset (concat (".", dirname_separator_string
,
12866 debug_file_directory
,
12868 search_path
= search_path_holder
.get ();
12874 search_path
= debug_file_directory
;
12876 openp_flags flags
= OPF_RETURN_REALPATH
;
12878 flags
|= OPF_SEARCH_IN_PATH
;
12880 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12881 desc
= openp (search_path
, flags
, file_name
,
12882 O_RDONLY
| O_BINARY
, &absolute_name
);
12886 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12888 if (sym_bfd
== NULL
)
12890 bfd_set_cacheable (sym_bfd
.get (), 1);
12892 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12895 /* Success. Record the bfd as having been included by the objfile's bfd.
12896 This is important because things like demangled_names_hash lives in the
12897 objfile's per_bfd space and may have references to things like symbol
12898 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12899 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12904 /* Try to open DWO file FILE_NAME.
12905 COMP_DIR is the DW_AT_comp_dir attribute.
12906 The result is the bfd handle of the file.
12907 If there is a problem finding or opening the file, return NULL.
12908 Upon success, the canonicalized path of the file is stored in the bfd,
12909 same as symfile_bfd_open. */
12911 static gdb_bfd_ref_ptr
12912 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12913 const char *file_name
, const char *comp_dir
)
12915 if (IS_ABSOLUTE_PATH (file_name
))
12916 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12917 0 /*is_dwp*/, 0 /*search_cwd*/);
12919 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12921 if (comp_dir
!= NULL
)
12923 gdb::unique_xmalloc_ptr
<char> path_to_try
12924 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12926 /* NOTE: If comp_dir is a relative path, this will also try the
12927 search path, which seems useful. */
12928 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
12929 path_to_try
.get (),
12931 1 /*search_cwd*/));
12936 /* That didn't work, try debug-file-directory, which, despite its name,
12937 is a list of paths. */
12939 if (*debug_file_directory
== '\0')
12942 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12943 0 /*is_dwp*/, 1 /*search_cwd*/);
12946 /* This function is mapped across the sections and remembers the offset and
12947 size of each of the DWO debugging sections we are interested in. */
12950 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12952 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12953 const struct dwop_section_names
*names
= &dwop_section_names
;
12955 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12957 dwo_sections
->abbrev
.s
.section
= sectp
;
12958 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12960 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12962 dwo_sections
->info
.s
.section
= sectp
;
12963 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12965 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12967 dwo_sections
->line
.s
.section
= sectp
;
12968 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12970 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12972 dwo_sections
->loc
.s
.section
= sectp
;
12973 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12975 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12977 dwo_sections
->macinfo
.s
.section
= sectp
;
12978 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12980 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12982 dwo_sections
->macro
.s
.section
= sectp
;
12983 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12985 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12987 dwo_sections
->str
.s
.section
= sectp
;
12988 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12990 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12992 dwo_sections
->str_offsets
.s
.section
= sectp
;
12993 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12995 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12997 struct dwarf2_section_info type_section
;
12999 memset (&type_section
, 0, sizeof (type_section
));
13000 type_section
.s
.section
= sectp
;
13001 type_section
.size
= bfd_section_size (sectp
);
13002 dwo_sections
->types
.push_back (type_section
);
13006 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
13007 by PER_CU. This is for the non-DWP case.
13008 The result is NULL if DWO_NAME can't be found. */
13010 static struct dwo_file
*
13011 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
13012 const char *dwo_name
, const char *comp_dir
)
13014 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
13016 gdb_bfd_ref_ptr dbfd
= open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
);
13019 if (dwarf_read_debug
)
13020 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
13024 dwo_file_up
dwo_file (new struct dwo_file
);
13025 dwo_file
->dwo_name
= dwo_name
;
13026 dwo_file
->comp_dir
= comp_dir
;
13027 dwo_file
->dbfd
= std::move (dbfd
);
13029 bfd_map_over_sections (dwo_file
->dbfd
.get (), dwarf2_locate_dwo_sections
,
13030 &dwo_file
->sections
);
13032 create_cus_hash_table (dwarf2_per_objfile
, per_cu
->cu
, *dwo_file
,
13033 dwo_file
->sections
.info
, dwo_file
->cus
);
13035 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
.get (),
13036 dwo_file
->sections
.types
, dwo_file
->tus
);
13038 if (dwarf_read_debug
)
13039 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
13041 return dwo_file
.release ();
13044 /* This function is mapped across the sections and remembers the offset and
13045 size of each of the DWP debugging sections common to version 1 and 2 that
13046 we are interested in. */
13049 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
13050 void *dwp_file_ptr
)
13052 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
13053 const struct dwop_section_names
*names
= &dwop_section_names
;
13054 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
13056 /* Record the ELF section number for later lookup: this is what the
13057 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
13058 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
13059 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
13061 /* Look for specific sections that we need. */
13062 if (section_is_p (sectp
->name
, &names
->str_dwo
))
13064 dwp_file
->sections
.str
.s
.section
= sectp
;
13065 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
13067 else if (section_is_p (sectp
->name
, &names
->cu_index
))
13069 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
13070 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
13072 else if (section_is_p (sectp
->name
, &names
->tu_index
))
13074 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
13075 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
13079 /* This function is mapped across the sections and remembers the offset and
13080 size of each of the DWP version 2 debugging sections that we are interested
13081 in. This is split into a separate function because we don't know if we
13082 have version 1 or 2 until we parse the cu_index/tu_index sections. */
13085 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
13087 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
13088 const struct dwop_section_names
*names
= &dwop_section_names
;
13089 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
13091 /* Record the ELF section number for later lookup: this is what the
13092 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
13093 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
13094 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
13096 /* Look for specific sections that we need. */
13097 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
13099 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
13100 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
13102 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
13104 dwp_file
->sections
.info
.s
.section
= sectp
;
13105 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
13107 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
13109 dwp_file
->sections
.line
.s
.section
= sectp
;
13110 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
13112 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
13114 dwp_file
->sections
.loc
.s
.section
= sectp
;
13115 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
13117 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
13119 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
13120 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
13122 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
13124 dwp_file
->sections
.macro
.s
.section
= sectp
;
13125 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
13127 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
13129 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
13130 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
13132 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
13134 dwp_file
->sections
.types
.s
.section
= sectp
;
13135 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
13139 /* Hash function for dwp_file loaded CUs/TUs. */
13142 hash_dwp_loaded_cutus (const void *item
)
13144 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
13146 /* This drops the top 32 bits of the signature, but is ok for a hash. */
13147 return dwo_unit
->signature
;
13150 /* Equality function for dwp_file loaded CUs/TUs. */
13153 eq_dwp_loaded_cutus (const void *a
, const void *b
)
13155 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
13156 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
13158 return dua
->signature
== dub
->signature
;
13161 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
13164 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
13166 return htab_create_alloc_ex (3,
13167 hash_dwp_loaded_cutus
,
13168 eq_dwp_loaded_cutus
,
13170 &objfile
->objfile_obstack
,
13171 hashtab_obstack_allocate
,
13172 dummy_obstack_deallocate
);
13175 /* Try to open DWP file FILE_NAME.
13176 The result is the bfd handle of the file.
13177 If there is a problem finding or opening the file, return NULL.
13178 Upon success, the canonicalized path of the file is stored in the bfd,
13179 same as symfile_bfd_open. */
13181 static gdb_bfd_ref_ptr
13182 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
13183 const char *file_name
)
13185 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
13187 1 /*search_cwd*/));
13191 /* Work around upstream bug 15652.
13192 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
13193 [Whether that's a "bug" is debatable, but it is getting in our way.]
13194 We have no real idea where the dwp file is, because gdb's realpath-ing
13195 of the executable's path may have discarded the needed info.
13196 [IWBN if the dwp file name was recorded in the executable, akin to
13197 .gnu_debuglink, but that doesn't exist yet.]
13198 Strip the directory from FILE_NAME and search again. */
13199 if (*debug_file_directory
!= '\0')
13201 /* Don't implicitly search the current directory here.
13202 If the user wants to search "." to handle this case,
13203 it must be added to debug-file-directory. */
13204 return try_open_dwop_file (dwarf2_per_objfile
,
13205 lbasename (file_name
), 1 /*is_dwp*/,
13212 /* Initialize the use of the DWP file for the current objfile.
13213 By convention the name of the DWP file is ${objfile}.dwp.
13214 The result is NULL if it can't be found. */
13216 static std::unique_ptr
<struct dwp_file
>
13217 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
13219 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13221 /* Try to find first .dwp for the binary file before any symbolic links
13224 /* If the objfile is a debug file, find the name of the real binary
13225 file and get the name of dwp file from there. */
13226 std::string dwp_name
;
13227 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
13229 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
13230 const char *backlink_basename
= lbasename (backlink
->original_name
);
13232 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
13235 dwp_name
= objfile
->original_name
;
13237 dwp_name
+= ".dwp";
13239 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
13241 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
13243 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
13244 dwp_name
= objfile_name (objfile
);
13245 dwp_name
+= ".dwp";
13246 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
13251 if (dwarf_read_debug
)
13252 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
13253 return std::unique_ptr
<dwp_file
> ();
13256 const char *name
= bfd_get_filename (dbfd
.get ());
13257 std::unique_ptr
<struct dwp_file
> dwp_file
13258 (new struct dwp_file (name
, std::move (dbfd
)));
13260 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
13261 dwp_file
->elf_sections
=
13262 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
13263 dwp_file
->num_sections
, asection
*);
13265 bfd_map_over_sections (dwp_file
->dbfd
.get (),
13266 dwarf2_locate_common_dwp_sections
,
13269 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
13272 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
13275 /* The DWP file version is stored in the hash table. Oh well. */
13276 if (dwp_file
->cus
&& dwp_file
->tus
13277 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
13279 /* Technically speaking, we should try to limp along, but this is
13280 pretty bizarre. We use pulongest here because that's the established
13281 portability solution (e.g, we cannot use %u for uint32_t). */
13282 error (_("Dwarf Error: DWP file CU version %s doesn't match"
13283 " TU version %s [in DWP file %s]"),
13284 pulongest (dwp_file
->cus
->version
),
13285 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
13289 dwp_file
->version
= dwp_file
->cus
->version
;
13290 else if (dwp_file
->tus
)
13291 dwp_file
->version
= dwp_file
->tus
->version
;
13293 dwp_file
->version
= 2;
13295 if (dwp_file
->version
== 2)
13296 bfd_map_over_sections (dwp_file
->dbfd
.get (),
13297 dwarf2_locate_v2_dwp_sections
,
13300 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table (objfile
);
13301 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table (objfile
);
13303 if (dwarf_read_debug
)
13305 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
13306 fprintf_unfiltered (gdb_stdlog
,
13307 " %s CUs, %s TUs\n",
13308 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
13309 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
13315 /* Wrapper around open_and_init_dwp_file, only open it once. */
13317 static struct dwp_file
*
13318 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
13320 if (! dwarf2_per_objfile
->dwp_checked
)
13322 dwarf2_per_objfile
->dwp_file
13323 = open_and_init_dwp_file (dwarf2_per_objfile
);
13324 dwarf2_per_objfile
->dwp_checked
= 1;
13326 return dwarf2_per_objfile
->dwp_file
.get ();
13329 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
13330 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
13331 or in the DWP file for the objfile, referenced by THIS_UNIT.
13332 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
13333 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
13335 This is called, for example, when wanting to read a variable with a
13336 complex location. Therefore we don't want to do file i/o for every call.
13337 Therefore we don't want to look for a DWO file on every call.
13338 Therefore we first see if we've already seen SIGNATURE in a DWP file,
13339 then we check if we've already seen DWO_NAME, and only THEN do we check
13342 The result is a pointer to the dwo_unit object or NULL if we didn't find it
13343 (dwo_id mismatch or couldn't find the DWO/DWP file). */
13345 static struct dwo_unit
*
13346 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
13347 const char *dwo_name
, const char *comp_dir
,
13348 ULONGEST signature
, int is_debug_types
)
13350 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_unit
->dwarf2_per_objfile
;
13351 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13352 const char *kind
= is_debug_types
? "TU" : "CU";
13353 void **dwo_file_slot
;
13354 struct dwo_file
*dwo_file
;
13355 struct dwp_file
*dwp_file
;
13357 /* First see if there's a DWP file.
13358 If we have a DWP file but didn't find the DWO inside it, don't
13359 look for the original DWO file. It makes gdb behave differently
13360 depending on whether one is debugging in the build tree. */
13362 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
13363 if (dwp_file
!= NULL
)
13365 const struct dwp_hash_table
*dwp_htab
=
13366 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
13368 if (dwp_htab
!= NULL
)
13370 struct dwo_unit
*dwo_cutu
=
13371 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
13372 signature
, is_debug_types
);
13374 if (dwo_cutu
!= NULL
)
13376 if (dwarf_read_debug
)
13378 fprintf_unfiltered (gdb_stdlog
,
13379 "Virtual DWO %s %s found: @%s\n",
13380 kind
, hex_string (signature
),
13381 host_address_to_string (dwo_cutu
));
13389 /* No DWP file, look for the DWO file. */
13391 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
13392 dwo_name
, comp_dir
);
13393 if (*dwo_file_slot
== NULL
)
13395 /* Read in the file and build a table of the CUs/TUs it contains. */
13396 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
13398 /* NOTE: This will be NULL if unable to open the file. */
13399 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
13401 if (dwo_file
!= NULL
)
13403 struct dwo_unit
*dwo_cutu
= NULL
;
13405 if (is_debug_types
&& dwo_file
->tus
)
13407 struct dwo_unit find_dwo_cutu
;
13409 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13410 find_dwo_cutu
.signature
= signature
;
13412 = (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_cutu
);
13414 else if (!is_debug_types
&& dwo_file
->cus
)
13416 struct dwo_unit find_dwo_cutu
;
13418 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13419 find_dwo_cutu
.signature
= signature
;
13420 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
,
13424 if (dwo_cutu
!= NULL
)
13426 if (dwarf_read_debug
)
13428 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
13429 kind
, dwo_name
, hex_string (signature
),
13430 host_address_to_string (dwo_cutu
));
13437 /* We didn't find it. This could mean a dwo_id mismatch, or
13438 someone deleted the DWO/DWP file, or the search path isn't set up
13439 correctly to find the file. */
13441 if (dwarf_read_debug
)
13443 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
13444 kind
, dwo_name
, hex_string (signature
));
13447 /* This is a warning and not a complaint because it can be caused by
13448 pilot error (e.g., user accidentally deleting the DWO). */
13450 /* Print the name of the DWP file if we looked there, helps the user
13451 better diagnose the problem. */
13452 std::string dwp_text
;
13454 if (dwp_file
!= NULL
)
13455 dwp_text
= string_printf (" [in DWP file %s]",
13456 lbasename (dwp_file
->name
));
13458 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
13459 " [in module %s]"),
13460 kind
, dwo_name
, hex_string (signature
),
13462 this_unit
->is_debug_types
? "TU" : "CU",
13463 sect_offset_str (this_unit
->sect_off
), objfile_name (objfile
));
13468 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
13469 See lookup_dwo_cutu_unit for details. */
13471 static struct dwo_unit
*
13472 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
13473 const char *dwo_name
, const char *comp_dir
,
13474 ULONGEST signature
)
13476 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
13479 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
13480 See lookup_dwo_cutu_unit for details. */
13482 static struct dwo_unit
*
13483 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
13484 const char *dwo_name
, const char *comp_dir
)
13486 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
13489 /* Traversal function for queue_and_load_all_dwo_tus. */
13492 queue_and_load_dwo_tu (void **slot
, void *info
)
13494 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
13495 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
13496 ULONGEST signature
= dwo_unit
->signature
;
13497 struct signatured_type
*sig_type
=
13498 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
13500 if (sig_type
!= NULL
)
13502 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
13504 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
13505 a real dependency of PER_CU on SIG_TYPE. That is detected later
13506 while processing PER_CU. */
13507 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
13508 load_full_type_unit (sig_cu
);
13509 per_cu
->imported_symtabs_push (sig_cu
);
13515 /* Queue all TUs contained in the DWO of PER_CU to be read in.
13516 The DWO may have the only definition of the type, though it may not be
13517 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
13518 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
13521 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
13523 struct dwo_unit
*dwo_unit
;
13524 struct dwo_file
*dwo_file
;
13526 gdb_assert (!per_cu
->is_debug_types
);
13527 gdb_assert (get_dwp_file (per_cu
->dwarf2_per_objfile
) == NULL
);
13528 gdb_assert (per_cu
->cu
!= NULL
);
13530 dwo_unit
= per_cu
->cu
->dwo_unit
;
13531 gdb_assert (dwo_unit
!= NULL
);
13533 dwo_file
= dwo_unit
->dwo_file
;
13534 if (dwo_file
->tus
!= NULL
)
13535 htab_traverse_noresize (dwo_file
->tus
, queue_and_load_dwo_tu
, per_cu
);
13538 /* Read in various DIEs. */
13540 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
13541 Inherit only the children of the DW_AT_abstract_origin DIE not being
13542 already referenced by DW_AT_abstract_origin from the children of the
13546 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
13548 struct die_info
*child_die
;
13549 sect_offset
*offsetp
;
13550 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
13551 struct die_info
*origin_die
;
13552 /* Iterator of the ORIGIN_DIE children. */
13553 struct die_info
*origin_child_die
;
13554 struct attribute
*attr
;
13555 struct dwarf2_cu
*origin_cu
;
13556 struct pending
**origin_previous_list_in_scope
;
13558 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13562 /* Note that following die references may follow to a die in a
13566 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
13568 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
13570 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
13571 origin_cu
->list_in_scope
= cu
->list_in_scope
;
13573 if (die
->tag
!= origin_die
->tag
13574 && !(die
->tag
== DW_TAG_inlined_subroutine
13575 && origin_die
->tag
== DW_TAG_subprogram
))
13576 complaint (_("DIE %s and its abstract origin %s have different tags"),
13577 sect_offset_str (die
->sect_off
),
13578 sect_offset_str (origin_die
->sect_off
));
13580 std::vector
<sect_offset
> offsets
;
13582 for (child_die
= die
->child
;
13583 child_die
&& child_die
->tag
;
13584 child_die
= sibling_die (child_die
))
13586 struct die_info
*child_origin_die
;
13587 struct dwarf2_cu
*child_origin_cu
;
13589 /* We are trying to process concrete instance entries:
13590 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
13591 it's not relevant to our analysis here. i.e. detecting DIEs that are
13592 present in the abstract instance but not referenced in the concrete
13594 if (child_die
->tag
== DW_TAG_call_site
13595 || child_die
->tag
== DW_TAG_GNU_call_site
)
13598 /* For each CHILD_DIE, find the corresponding child of
13599 ORIGIN_DIE. If there is more than one layer of
13600 DW_AT_abstract_origin, follow them all; there shouldn't be,
13601 but GCC versions at least through 4.4 generate this (GCC PR
13603 child_origin_die
= child_die
;
13604 child_origin_cu
= cu
;
13607 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
13611 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
13615 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
13616 counterpart may exist. */
13617 if (child_origin_die
!= child_die
)
13619 if (child_die
->tag
!= child_origin_die
->tag
13620 && !(child_die
->tag
== DW_TAG_inlined_subroutine
13621 && child_origin_die
->tag
== DW_TAG_subprogram
))
13622 complaint (_("Child DIE %s and its abstract origin %s have "
13624 sect_offset_str (child_die
->sect_off
),
13625 sect_offset_str (child_origin_die
->sect_off
));
13626 if (child_origin_die
->parent
!= origin_die
)
13627 complaint (_("Child DIE %s and its abstract origin %s have "
13628 "different parents"),
13629 sect_offset_str (child_die
->sect_off
),
13630 sect_offset_str (child_origin_die
->sect_off
));
13632 offsets
.push_back (child_origin_die
->sect_off
);
13635 std::sort (offsets
.begin (), offsets
.end ());
13636 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
13637 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
13638 if (offsetp
[-1] == *offsetp
)
13639 complaint (_("Multiple children of DIE %s refer "
13640 "to DIE %s as their abstract origin"),
13641 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
13643 offsetp
= offsets
.data ();
13644 origin_child_die
= origin_die
->child
;
13645 while (origin_child_die
&& origin_child_die
->tag
)
13647 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13648 while (offsetp
< offsets_end
13649 && *offsetp
< origin_child_die
->sect_off
)
13651 if (offsetp
>= offsets_end
13652 || *offsetp
> origin_child_die
->sect_off
)
13654 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13655 Check whether we're already processing ORIGIN_CHILD_DIE.
13656 This can happen with mutually referenced abstract_origins.
13658 if (!origin_child_die
->in_process
)
13659 process_die (origin_child_die
, origin_cu
);
13661 origin_child_die
= sibling_die (origin_child_die
);
13663 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13665 if (cu
!= origin_cu
)
13666 compute_delayed_physnames (origin_cu
);
13670 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13672 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13673 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13674 struct context_stack
*newobj
;
13677 struct die_info
*child_die
;
13678 struct attribute
*attr
, *call_line
, *call_file
;
13680 CORE_ADDR baseaddr
;
13681 struct block
*block
;
13682 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13683 std::vector
<struct symbol
*> template_args
;
13684 struct template_symbol
*templ_func
= NULL
;
13688 /* If we do not have call site information, we can't show the
13689 caller of this inlined function. That's too confusing, so
13690 only use the scope for local variables. */
13691 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13692 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13693 if (call_line
== NULL
|| call_file
== NULL
)
13695 read_lexical_block_scope (die
, cu
);
13700 baseaddr
= objfile
->text_section_offset ();
13702 name
= dwarf2_name (die
, cu
);
13704 /* Ignore functions with missing or empty names. These are actually
13705 illegal according to the DWARF standard. */
13708 complaint (_("missing name for subprogram DIE at %s"),
13709 sect_offset_str (die
->sect_off
));
13713 /* Ignore functions with missing or invalid low and high pc attributes. */
13714 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13715 <= PC_BOUNDS_INVALID
)
13717 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13718 if (!attr
|| !DW_UNSND (attr
))
13719 complaint (_("cannot get low and high bounds "
13720 "for subprogram DIE at %s"),
13721 sect_offset_str (die
->sect_off
));
13725 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13726 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13728 /* If we have any template arguments, then we must allocate a
13729 different sort of symbol. */
13730 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
13732 if (child_die
->tag
== DW_TAG_template_type_param
13733 || child_die
->tag
== DW_TAG_template_value_param
)
13735 templ_func
= allocate_template_symbol (objfile
);
13736 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13741 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13742 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13743 (struct symbol
*) templ_func
);
13745 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13746 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
13749 /* If there is a location expression for DW_AT_frame_base, record
13751 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13752 if (attr
!= nullptr)
13753 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13755 /* If there is a location for the static link, record it. */
13756 newobj
->static_link
= NULL
;
13757 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13758 if (attr
!= nullptr)
13760 newobj
->static_link
13761 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13762 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13763 dwarf2_per_cu_addr_type (cu
->per_cu
));
13766 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13768 if (die
->child
!= NULL
)
13770 child_die
= die
->child
;
13771 while (child_die
&& child_die
->tag
)
13773 if (child_die
->tag
== DW_TAG_template_type_param
13774 || child_die
->tag
== DW_TAG_template_value_param
)
13776 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13779 template_args
.push_back (arg
);
13782 process_die (child_die
, cu
);
13783 child_die
= sibling_die (child_die
);
13787 inherit_abstract_dies (die
, cu
);
13789 /* If we have a DW_AT_specification, we might need to import using
13790 directives from the context of the specification DIE. See the
13791 comment in determine_prefix. */
13792 if (cu
->language
== language_cplus
13793 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13795 struct dwarf2_cu
*spec_cu
= cu
;
13796 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13800 child_die
= spec_die
->child
;
13801 while (child_die
&& child_die
->tag
)
13803 if (child_die
->tag
== DW_TAG_imported_module
)
13804 process_die (child_die
, spec_cu
);
13805 child_die
= sibling_die (child_die
);
13808 /* In some cases, GCC generates specification DIEs that
13809 themselves contain DW_AT_specification attributes. */
13810 spec_die
= die_specification (spec_die
, &spec_cu
);
13814 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13815 /* Make a block for the local symbols within. */
13816 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13817 cstk
.static_link
, lowpc
, highpc
);
13819 /* For C++, set the block's scope. */
13820 if ((cu
->language
== language_cplus
13821 || cu
->language
== language_fortran
13822 || cu
->language
== language_d
13823 || cu
->language
== language_rust
)
13824 && cu
->processing_has_namespace_info
)
13825 block_set_scope (block
, determine_prefix (die
, cu
),
13826 &objfile
->objfile_obstack
);
13828 /* If we have address ranges, record them. */
13829 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13831 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13833 /* Attach template arguments to function. */
13834 if (!template_args
.empty ())
13836 gdb_assert (templ_func
!= NULL
);
13838 templ_func
->n_template_arguments
= template_args
.size ();
13839 templ_func
->template_arguments
13840 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13841 templ_func
->n_template_arguments
);
13842 memcpy (templ_func
->template_arguments
,
13843 template_args
.data (),
13844 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13846 /* Make sure that the symtab is set on the new symbols. Even
13847 though they don't appear in this symtab directly, other parts
13848 of gdb assume that symbols do, and this is reasonably
13850 for (symbol
*sym
: template_args
)
13851 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13854 /* In C++, we can have functions nested inside functions (e.g., when
13855 a function declares a class that has methods). This means that
13856 when we finish processing a function scope, we may need to go
13857 back to building a containing block's symbol lists. */
13858 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13859 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13861 /* If we've finished processing a top-level function, subsequent
13862 symbols go in the file symbol list. */
13863 if (cu
->get_builder ()->outermost_context_p ())
13864 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13867 /* Process all the DIES contained within a lexical block scope. Start
13868 a new scope, process the dies, and then close the scope. */
13871 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13873 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13874 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13875 CORE_ADDR lowpc
, highpc
;
13876 struct die_info
*child_die
;
13877 CORE_ADDR baseaddr
;
13879 baseaddr
= objfile
->text_section_offset ();
13881 /* Ignore blocks with missing or invalid low and high pc attributes. */
13882 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13883 as multiple lexical blocks? Handling children in a sane way would
13884 be nasty. Might be easier to properly extend generic blocks to
13885 describe ranges. */
13886 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13888 case PC_BOUNDS_NOT_PRESENT
:
13889 /* DW_TAG_lexical_block has no attributes, process its children as if
13890 there was no wrapping by that DW_TAG_lexical_block.
13891 GCC does no longer produces such DWARF since GCC r224161. */
13892 for (child_die
= die
->child
;
13893 child_die
!= NULL
&& child_die
->tag
;
13894 child_die
= sibling_die (child_die
))
13895 process_die (child_die
, cu
);
13897 case PC_BOUNDS_INVALID
:
13900 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13901 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13903 cu
->get_builder ()->push_context (0, lowpc
);
13904 if (die
->child
!= NULL
)
13906 child_die
= die
->child
;
13907 while (child_die
&& child_die
->tag
)
13909 process_die (child_die
, cu
);
13910 child_die
= sibling_die (child_die
);
13913 inherit_abstract_dies (die
, cu
);
13914 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13916 if (*cu
->get_builder ()->get_local_symbols () != NULL
13917 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13919 struct block
*block
13920 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13921 cstk
.start_addr
, highpc
);
13923 /* Note that recording ranges after traversing children, as we
13924 do here, means that recording a parent's ranges entails
13925 walking across all its children's ranges as they appear in
13926 the address map, which is quadratic behavior.
13928 It would be nicer to record the parent's ranges before
13929 traversing its children, simply overriding whatever you find
13930 there. But since we don't even decide whether to create a
13931 block until after we've traversed its children, that's hard
13933 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13935 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13936 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13939 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13942 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13944 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13945 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13946 CORE_ADDR pc
, baseaddr
;
13947 struct attribute
*attr
;
13948 struct call_site
*call_site
, call_site_local
;
13951 struct die_info
*child_die
;
13953 baseaddr
= objfile
->text_section_offset ();
13955 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13958 /* This was a pre-DWARF-5 GNU extension alias
13959 for DW_AT_call_return_pc. */
13960 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13964 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13965 "DIE %s [in module %s]"),
13966 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13969 pc
= attr_value_as_address (attr
) + baseaddr
;
13970 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13972 if (cu
->call_site_htab
== NULL
)
13973 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13974 NULL
, &objfile
->objfile_obstack
,
13975 hashtab_obstack_allocate
, NULL
);
13976 call_site_local
.pc
= pc
;
13977 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13980 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13981 "DIE %s [in module %s]"),
13982 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13983 objfile_name (objfile
));
13987 /* Count parameters at the caller. */
13990 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13991 child_die
= sibling_die (child_die
))
13993 if (child_die
->tag
!= DW_TAG_call_site_parameter
13994 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13996 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13997 "DW_TAG_call_site child DIE %s [in module %s]"),
13998 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13999 objfile_name (objfile
));
14007 = ((struct call_site
*)
14008 obstack_alloc (&objfile
->objfile_obstack
,
14009 sizeof (*call_site
)
14010 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
14012 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
14013 call_site
->pc
= pc
;
14015 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
14016 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
14018 struct die_info
*func_die
;
14020 /* Skip also over DW_TAG_inlined_subroutine. */
14021 for (func_die
= die
->parent
;
14022 func_die
&& func_die
->tag
!= DW_TAG_subprogram
14023 && func_die
->tag
!= DW_TAG_subroutine_type
;
14024 func_die
= func_die
->parent
);
14026 /* DW_AT_call_all_calls is a superset
14027 of DW_AT_call_all_tail_calls. */
14029 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
14030 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
14031 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
14032 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
14034 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
14035 not complete. But keep CALL_SITE for look ups via call_site_htab,
14036 both the initial caller containing the real return address PC and
14037 the final callee containing the current PC of a chain of tail
14038 calls do not need to have the tail call list complete. But any
14039 function candidate for a virtual tail call frame searched via
14040 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
14041 determined unambiguously. */
14045 struct type
*func_type
= NULL
;
14048 func_type
= get_die_type (func_die
, cu
);
14049 if (func_type
!= NULL
)
14051 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
14053 /* Enlist this call site to the function. */
14054 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
14055 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
14058 complaint (_("Cannot find function owning DW_TAG_call_site "
14059 "DIE %s [in module %s]"),
14060 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14064 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
14066 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
14068 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
14071 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
14072 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
14074 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
14075 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
14076 /* Keep NULL DWARF_BLOCK. */;
14077 else if (attr_form_is_block (attr
))
14079 struct dwarf2_locexpr_baton
*dlbaton
;
14081 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
14082 dlbaton
->data
= DW_BLOCK (attr
)->data
;
14083 dlbaton
->size
= DW_BLOCK (attr
)->size
;
14084 dlbaton
->per_cu
= cu
->per_cu
;
14086 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
14088 else if (attr_form_is_ref (attr
))
14090 struct dwarf2_cu
*target_cu
= cu
;
14091 struct die_info
*target_die
;
14093 target_die
= follow_die_ref (die
, attr
, &target_cu
);
14094 gdb_assert (target_cu
->per_cu
->dwarf2_per_objfile
->objfile
== objfile
);
14095 if (die_is_declaration (target_die
, target_cu
))
14097 const char *target_physname
;
14099 /* Prefer the mangled name; otherwise compute the demangled one. */
14100 target_physname
= dw2_linkage_name (target_die
, target_cu
);
14101 if (target_physname
== NULL
)
14102 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
14103 if (target_physname
== NULL
)
14104 complaint (_("DW_AT_call_target target DIE has invalid "
14105 "physname, for referencing DIE %s [in module %s]"),
14106 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14108 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
14114 /* DW_AT_entry_pc should be preferred. */
14115 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
14116 <= PC_BOUNDS_INVALID
)
14117 complaint (_("DW_AT_call_target target DIE has invalid "
14118 "low pc, for referencing DIE %s [in module %s]"),
14119 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14122 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
14123 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
14128 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
14129 "block nor reference, for DIE %s [in module %s]"),
14130 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14132 call_site
->per_cu
= cu
->per_cu
;
14134 for (child_die
= die
->child
;
14135 child_die
&& child_die
->tag
;
14136 child_die
= sibling_die (child_die
))
14138 struct call_site_parameter
*parameter
;
14139 struct attribute
*loc
, *origin
;
14141 if (child_die
->tag
!= DW_TAG_call_site_parameter
14142 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
14144 /* Already printed the complaint above. */
14148 gdb_assert (call_site
->parameter_count
< nparams
);
14149 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
14151 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
14152 specifies DW_TAG_formal_parameter. Value of the data assumed for the
14153 register is contained in DW_AT_call_value. */
14155 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
14156 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
14157 if (origin
== NULL
)
14159 /* This was a pre-DWARF-5 GNU extension alias
14160 for DW_AT_call_parameter. */
14161 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
14163 if (loc
== NULL
&& origin
!= NULL
&& attr_form_is_ref (origin
))
14165 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
14167 sect_offset sect_off
14168 = (sect_offset
) dwarf2_get_ref_die_offset (origin
);
14169 if (!offset_in_cu_p (&cu
->header
, sect_off
))
14171 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
14172 binding can be done only inside one CU. Such referenced DIE
14173 therefore cannot be even moved to DW_TAG_partial_unit. */
14174 complaint (_("DW_AT_call_parameter offset is not in CU for "
14175 "DW_TAG_call_site child DIE %s [in module %s]"),
14176 sect_offset_str (child_die
->sect_off
),
14177 objfile_name (objfile
));
14180 parameter
->u
.param_cu_off
14181 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
14183 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
14185 complaint (_("No DW_FORM_block* DW_AT_location for "
14186 "DW_TAG_call_site child DIE %s [in module %s]"),
14187 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
14192 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
14193 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
14194 if (parameter
->u
.dwarf_reg
!= -1)
14195 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
14196 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
14197 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
14198 ¶meter
->u
.fb_offset
))
14199 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
14202 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
14203 "for DW_FORM_block* DW_AT_location is supported for "
14204 "DW_TAG_call_site child DIE %s "
14206 sect_offset_str (child_die
->sect_off
),
14207 objfile_name (objfile
));
14212 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
14214 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
14215 if (!attr_form_is_block (attr
))
14217 complaint (_("No DW_FORM_block* DW_AT_call_value for "
14218 "DW_TAG_call_site child DIE %s [in module %s]"),
14219 sect_offset_str (child_die
->sect_off
),
14220 objfile_name (objfile
));
14223 parameter
->value
= DW_BLOCK (attr
)->data
;
14224 parameter
->value_size
= DW_BLOCK (attr
)->size
;
14226 /* Parameters are not pre-cleared by memset above. */
14227 parameter
->data_value
= NULL
;
14228 parameter
->data_value_size
= 0;
14229 call_site
->parameter_count
++;
14231 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
14233 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
14234 if (attr
!= nullptr)
14236 if (!attr_form_is_block (attr
))
14237 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
14238 "DW_TAG_call_site child DIE %s [in module %s]"),
14239 sect_offset_str (child_die
->sect_off
),
14240 objfile_name (objfile
));
14243 parameter
->data_value
= DW_BLOCK (attr
)->data
;
14244 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
14250 /* Helper function for read_variable. If DIE represents a virtual
14251 table, then return the type of the concrete object that is
14252 associated with the virtual table. Otherwise, return NULL. */
14254 static struct type
*
14255 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14257 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
14261 /* Find the type DIE. */
14262 struct die_info
*type_die
= NULL
;
14263 struct dwarf2_cu
*type_cu
= cu
;
14265 if (attr_form_is_ref (attr
))
14266 type_die
= follow_die_ref (die
, attr
, &type_cu
);
14267 if (type_die
== NULL
)
14270 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
14272 return die_containing_type (type_die
, type_cu
);
14275 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
14278 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
14280 struct rust_vtable_symbol
*storage
= NULL
;
14282 if (cu
->language
== language_rust
)
14284 struct type
*containing_type
= rust_containing_type (die
, cu
);
14286 if (containing_type
!= NULL
)
14288 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14290 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol ();
14291 initialize_objfile_symbol (storage
);
14292 storage
->concrete_type
= containing_type
;
14293 storage
->subclass
= SYMBOL_RUST_VTABLE
;
14297 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
14298 struct attribute
*abstract_origin
14299 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
14300 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
14301 if (res
== NULL
&& loc
&& abstract_origin
)
14303 /* We have a variable without a name, but with a location and an abstract
14304 origin. This may be a concrete instance of an abstract variable
14305 referenced from an DW_OP_GNU_variable_value, so save it to find it back
14307 struct dwarf2_cu
*origin_cu
= cu
;
14308 struct die_info
*origin_die
14309 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
14310 dwarf2_per_objfile
*dpo
= cu
->per_cu
->dwarf2_per_objfile
;
14311 dpo
->abstract_to_concrete
[origin_die
->sect_off
].push_back (die
->sect_off
);
14315 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
14316 reading .debug_rnglists.
14317 Callback's type should be:
14318 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14319 Return true if the attributes are present and valid, otherwise,
14322 template <typename Callback
>
14324 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
14325 Callback
&&callback
)
14327 struct dwarf2_per_objfile
*dwarf2_per_objfile
14328 = cu
->per_cu
->dwarf2_per_objfile
;
14329 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14330 bfd
*obfd
= objfile
->obfd
;
14331 /* Base address selection entry. */
14334 const gdb_byte
*buffer
;
14335 CORE_ADDR baseaddr
;
14336 bool overflow
= false;
14338 found_base
= cu
->base_known
;
14339 base
= cu
->base_address
;
14341 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->rnglists
);
14342 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
14344 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14348 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
14350 baseaddr
= objfile
->text_section_offset ();
14354 /* Initialize it due to a false compiler warning. */
14355 CORE_ADDR range_beginning
= 0, range_end
= 0;
14356 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
14357 + dwarf2_per_objfile
->rnglists
.size
);
14358 unsigned int bytes_read
;
14360 if (buffer
== buf_end
)
14365 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
14368 case DW_RLE_end_of_list
:
14370 case DW_RLE_base_address
:
14371 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14376 base
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14378 buffer
+= bytes_read
;
14380 case DW_RLE_start_length
:
14381 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14386 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14387 buffer
+= bytes_read
;
14388 range_end
= (range_beginning
14389 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
14390 buffer
+= bytes_read
;
14391 if (buffer
> buf_end
)
14397 case DW_RLE_offset_pair
:
14398 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14399 buffer
+= bytes_read
;
14400 if (buffer
> buf_end
)
14405 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14406 buffer
+= bytes_read
;
14407 if (buffer
> buf_end
)
14413 case DW_RLE_start_end
:
14414 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
14419 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14420 buffer
+= bytes_read
;
14421 range_end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14422 buffer
+= bytes_read
;
14425 complaint (_("Invalid .debug_rnglists data (no base address)"));
14428 if (rlet
== DW_RLE_end_of_list
|| overflow
)
14430 if (rlet
== DW_RLE_base_address
)
14435 /* We have no valid base address for the ranges
14437 complaint (_("Invalid .debug_rnglists data (no base address)"));
14441 if (range_beginning
> range_end
)
14443 /* Inverted range entries are invalid. */
14444 complaint (_("Invalid .debug_rnglists data (inverted range)"));
14448 /* Empty range entries have no effect. */
14449 if (range_beginning
== range_end
)
14452 range_beginning
+= base
;
14455 /* A not-uncommon case of bad debug info.
14456 Don't pollute the addrmap with bad data. */
14457 if (range_beginning
+ baseaddr
== 0
14458 && !dwarf2_per_objfile
->has_section_at_zero
)
14460 complaint (_(".debug_rnglists entry has start address of zero"
14461 " [in module %s]"), objfile_name (objfile
));
14465 callback (range_beginning
, range_end
);
14470 complaint (_("Offset %d is not terminated "
14471 "for DW_AT_ranges attribute"),
14479 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
14480 Callback's type should be:
14481 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14482 Return 1 if the attributes are present and valid, otherwise, return 0. */
14484 template <typename Callback
>
14486 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
14487 Callback
&&callback
)
14489 struct dwarf2_per_objfile
*dwarf2_per_objfile
14490 = cu
->per_cu
->dwarf2_per_objfile
;
14491 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14492 struct comp_unit_head
*cu_header
= &cu
->header
;
14493 bfd
*obfd
= objfile
->obfd
;
14494 unsigned int addr_size
= cu_header
->addr_size
;
14495 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
14496 /* Base address selection entry. */
14499 unsigned int dummy
;
14500 const gdb_byte
*buffer
;
14501 CORE_ADDR baseaddr
;
14503 if (cu_header
->version
>= 5)
14504 return dwarf2_rnglists_process (offset
, cu
, callback
);
14506 found_base
= cu
->base_known
;
14507 base
= cu
->base_address
;
14509 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
14510 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
14512 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14516 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
14518 baseaddr
= objfile
->text_section_offset ();
14522 CORE_ADDR range_beginning
, range_end
;
14524 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
14525 buffer
+= addr_size
;
14526 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
14527 buffer
+= addr_size
;
14528 offset
+= 2 * addr_size
;
14530 /* An end of list marker is a pair of zero addresses. */
14531 if (range_beginning
== 0 && range_end
== 0)
14532 /* Found the end of list entry. */
14535 /* Each base address selection entry is a pair of 2 values.
14536 The first is the largest possible address, the second is
14537 the base address. Check for a base address here. */
14538 if ((range_beginning
& mask
) == mask
)
14540 /* If we found the largest possible address, then we already
14541 have the base address in range_end. */
14549 /* We have no valid base address for the ranges
14551 complaint (_("Invalid .debug_ranges data (no base address)"));
14555 if (range_beginning
> range_end
)
14557 /* Inverted range entries are invalid. */
14558 complaint (_("Invalid .debug_ranges data (inverted range)"));
14562 /* Empty range entries have no effect. */
14563 if (range_beginning
== range_end
)
14566 range_beginning
+= base
;
14569 /* A not-uncommon case of bad debug info.
14570 Don't pollute the addrmap with bad data. */
14571 if (range_beginning
+ baseaddr
== 0
14572 && !dwarf2_per_objfile
->has_section_at_zero
)
14574 complaint (_(".debug_ranges entry has start address of zero"
14575 " [in module %s]"), objfile_name (objfile
));
14579 callback (range_beginning
, range_end
);
14585 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
14586 Return 1 if the attributes are present and valid, otherwise, return 0.
14587 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
14590 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
14591 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
14592 dwarf2_psymtab
*ranges_pst
)
14594 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14595 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14596 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
14599 CORE_ADDR high
= 0;
14602 retval
= dwarf2_ranges_process (offset
, cu
,
14603 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
14605 if (ranges_pst
!= NULL
)
14610 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14611 range_beginning
+ baseaddr
)
14613 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14614 range_end
+ baseaddr
)
14616 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
14617 lowpc
, highpc
- 1, ranges_pst
);
14620 /* FIXME: This is recording everything as a low-high
14621 segment of consecutive addresses. We should have a
14622 data structure for discontiguous block ranges
14626 low
= range_beginning
;
14632 if (range_beginning
< low
)
14633 low
= range_beginning
;
14634 if (range_end
> high
)
14642 /* If the first entry is an end-of-list marker, the range
14643 describes an empty scope, i.e. no instructions. */
14649 *high_return
= high
;
14653 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14654 definition for the return value. *LOWPC and *HIGHPC are set iff
14655 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14657 static enum pc_bounds_kind
14658 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14659 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14660 dwarf2_psymtab
*pst
)
14662 struct dwarf2_per_objfile
*dwarf2_per_objfile
14663 = cu
->per_cu
->dwarf2_per_objfile
;
14664 struct attribute
*attr
;
14665 struct attribute
*attr_high
;
14667 CORE_ADDR high
= 0;
14668 enum pc_bounds_kind ret
;
14670 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14673 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14674 if (attr
!= nullptr)
14676 low
= attr_value_as_address (attr
);
14677 high
= attr_value_as_address (attr_high
);
14678 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
14682 /* Found high w/o low attribute. */
14683 return PC_BOUNDS_INVALID
;
14685 /* Found consecutive range of addresses. */
14686 ret
= PC_BOUNDS_HIGH_LOW
;
14690 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14693 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14694 We take advantage of the fact that DW_AT_ranges does not appear
14695 in DW_TAG_compile_unit of DWO files. */
14696 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14697 unsigned int ranges_offset
= (DW_UNSND (attr
)
14698 + (need_ranges_base
14702 /* Value of the DW_AT_ranges attribute is the offset in the
14703 .debug_ranges section. */
14704 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
14705 return PC_BOUNDS_INVALID
;
14706 /* Found discontinuous range of addresses. */
14707 ret
= PC_BOUNDS_RANGES
;
14710 return PC_BOUNDS_NOT_PRESENT
;
14713 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14715 return PC_BOUNDS_INVALID
;
14717 /* When using the GNU linker, .gnu.linkonce. sections are used to
14718 eliminate duplicate copies of functions and vtables and such.
14719 The linker will arbitrarily choose one and discard the others.
14720 The AT_*_pc values for such functions refer to local labels in
14721 these sections. If the section from that file was discarded, the
14722 labels are not in the output, so the relocs get a value of 0.
14723 If this is a discarded function, mark the pc bounds as invalid,
14724 so that GDB will ignore it. */
14725 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
14726 return PC_BOUNDS_INVALID
;
14734 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14735 its low and high PC addresses. Do nothing if these addresses could not
14736 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14737 and HIGHPC to the high address if greater than HIGHPC. */
14740 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14741 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14742 struct dwarf2_cu
*cu
)
14744 CORE_ADDR low
, high
;
14745 struct die_info
*child
= die
->child
;
14747 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14749 *lowpc
= std::min (*lowpc
, low
);
14750 *highpc
= std::max (*highpc
, high
);
14753 /* If the language does not allow nested subprograms (either inside
14754 subprograms or lexical blocks), we're done. */
14755 if (cu
->language
!= language_ada
)
14758 /* Check all the children of the given DIE. If it contains nested
14759 subprograms, then check their pc bounds. Likewise, we need to
14760 check lexical blocks as well, as they may also contain subprogram
14762 while (child
&& child
->tag
)
14764 if (child
->tag
== DW_TAG_subprogram
14765 || child
->tag
== DW_TAG_lexical_block
)
14766 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14767 child
= sibling_die (child
);
14771 /* Get the low and high pc's represented by the scope DIE, and store
14772 them in *LOWPC and *HIGHPC. If the correct values can't be
14773 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14776 get_scope_pc_bounds (struct die_info
*die
,
14777 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14778 struct dwarf2_cu
*cu
)
14780 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14781 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14782 CORE_ADDR current_low
, current_high
;
14784 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14785 >= PC_BOUNDS_RANGES
)
14787 best_low
= current_low
;
14788 best_high
= current_high
;
14792 struct die_info
*child
= die
->child
;
14794 while (child
&& child
->tag
)
14796 switch (child
->tag
) {
14797 case DW_TAG_subprogram
:
14798 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14800 case DW_TAG_namespace
:
14801 case DW_TAG_module
:
14802 /* FIXME: carlton/2004-01-16: Should we do this for
14803 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14804 that current GCC's always emit the DIEs corresponding
14805 to definitions of methods of classes as children of a
14806 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14807 the DIEs giving the declarations, which could be
14808 anywhere). But I don't see any reason why the
14809 standards says that they have to be there. */
14810 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14812 if (current_low
!= ((CORE_ADDR
) -1))
14814 best_low
= std::min (best_low
, current_low
);
14815 best_high
= std::max (best_high
, current_high
);
14823 child
= sibling_die (child
);
14828 *highpc
= best_high
;
14831 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14835 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14836 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14838 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14839 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14840 struct attribute
*attr
;
14841 struct attribute
*attr_high
;
14843 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14846 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14847 if (attr
!= nullptr)
14849 CORE_ADDR low
= attr_value_as_address (attr
);
14850 CORE_ADDR high
= attr_value_as_address (attr_high
);
14852 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
14855 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14856 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14857 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14861 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14862 if (attr
!= nullptr)
14864 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14865 We take advantage of the fact that DW_AT_ranges does not appear
14866 in DW_TAG_compile_unit of DWO files. */
14867 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14869 /* The value of the DW_AT_ranges attribute is the offset of the
14870 address range list in the .debug_ranges section. */
14871 unsigned long offset
= (DW_UNSND (attr
)
14872 + (need_ranges_base
? cu
->ranges_base
: 0));
14874 std::vector
<blockrange
> blockvec
;
14875 dwarf2_ranges_process (offset
, cu
,
14876 [&] (CORE_ADDR start
, CORE_ADDR end
)
14880 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14881 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14882 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14883 blockvec
.emplace_back (start
, end
);
14886 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14890 /* Check whether the producer field indicates either of GCC < 4.6, or the
14891 Intel C/C++ compiler, and cache the result in CU. */
14894 check_producer (struct dwarf2_cu
*cu
)
14898 if (cu
->producer
== NULL
)
14900 /* For unknown compilers expect their behavior is DWARF version
14903 GCC started to support .debug_types sections by -gdwarf-4 since
14904 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14905 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14906 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14907 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14909 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14911 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14912 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14914 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14916 cu
->producer_is_icc
= true;
14917 cu
->producer_is_icc_lt_14
= major
< 14;
14919 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14920 cu
->producer_is_codewarrior
= true;
14923 /* For other non-GCC compilers, expect their behavior is DWARF version
14927 cu
->checked_producer
= true;
14930 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14931 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14932 during 4.6.0 experimental. */
14935 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14937 if (!cu
->checked_producer
)
14938 check_producer (cu
);
14940 return cu
->producer_is_gxx_lt_4_6
;
14944 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14945 with incorrect is_stmt attributes. */
14948 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14950 if (!cu
->checked_producer
)
14951 check_producer (cu
);
14953 return cu
->producer_is_codewarrior
;
14956 /* Return the default accessibility type if it is not overridden by
14957 DW_AT_accessibility. */
14959 static enum dwarf_access_attribute
14960 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14962 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14964 /* The default DWARF 2 accessibility for members is public, the default
14965 accessibility for inheritance is private. */
14967 if (die
->tag
!= DW_TAG_inheritance
)
14968 return DW_ACCESS_public
;
14970 return DW_ACCESS_private
;
14974 /* DWARF 3+ defines the default accessibility a different way. The same
14975 rules apply now for DW_TAG_inheritance as for the members and it only
14976 depends on the container kind. */
14978 if (die
->parent
->tag
== DW_TAG_class_type
)
14979 return DW_ACCESS_private
;
14981 return DW_ACCESS_public
;
14985 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14986 offset. If the attribute was not found return 0, otherwise return
14987 1. If it was found but could not properly be handled, set *OFFSET
14991 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14994 struct attribute
*attr
;
14996 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
15001 /* Note that we do not check for a section offset first here.
15002 This is because DW_AT_data_member_location is new in DWARF 4,
15003 so if we see it, we can assume that a constant form is really
15004 a constant and not a section offset. */
15005 if (attr_form_is_constant (attr
))
15006 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
15007 else if (attr_form_is_section_offset (attr
))
15008 dwarf2_complex_location_expr_complaint ();
15009 else if (attr_form_is_block (attr
))
15010 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15012 dwarf2_complex_location_expr_complaint ();
15020 /* Add an aggregate field to the field list. */
15023 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
15024 struct dwarf2_cu
*cu
)
15026 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15027 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15028 struct nextfield
*new_field
;
15029 struct attribute
*attr
;
15031 const char *fieldname
= "";
15033 if (die
->tag
== DW_TAG_inheritance
)
15035 fip
->baseclasses
.emplace_back ();
15036 new_field
= &fip
->baseclasses
.back ();
15040 fip
->fields
.emplace_back ();
15041 new_field
= &fip
->fields
.back ();
15046 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15047 if (attr
!= nullptr)
15048 new_field
->accessibility
= DW_UNSND (attr
);
15050 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
15051 if (new_field
->accessibility
!= DW_ACCESS_public
)
15052 fip
->non_public_fields
= 1;
15054 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15055 if (attr
!= nullptr)
15056 new_field
->virtuality
= DW_UNSND (attr
);
15058 new_field
->virtuality
= DW_VIRTUALITY_none
;
15060 fp
= &new_field
->field
;
15062 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
15066 /* Data member other than a C++ static data member. */
15068 /* Get type of field. */
15069 fp
->type
= die_type (die
, cu
);
15071 SET_FIELD_BITPOS (*fp
, 0);
15073 /* Get bit size of field (zero if none). */
15074 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
15075 if (attr
!= nullptr)
15077 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
15081 FIELD_BITSIZE (*fp
) = 0;
15084 /* Get bit offset of field. */
15085 if (handle_data_member_location (die
, cu
, &offset
))
15086 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
15087 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
15088 if (attr
!= nullptr)
15090 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
15092 /* For big endian bits, the DW_AT_bit_offset gives the
15093 additional bit offset from the MSB of the containing
15094 anonymous object to the MSB of the field. We don't
15095 have to do anything special since we don't need to
15096 know the size of the anonymous object. */
15097 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
15101 /* For little endian bits, compute the bit offset to the
15102 MSB of the anonymous object, subtract off the number of
15103 bits from the MSB of the field to the MSB of the
15104 object, and then subtract off the number of bits of
15105 the field itself. The result is the bit offset of
15106 the LSB of the field. */
15107 int anonymous_size
;
15108 int bit_offset
= DW_UNSND (attr
);
15110 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15111 if (attr
!= nullptr)
15113 /* The size of the anonymous object containing
15114 the bit field is explicit, so use the
15115 indicated size (in bytes). */
15116 anonymous_size
= DW_UNSND (attr
);
15120 /* The size of the anonymous object containing
15121 the bit field must be inferred from the type
15122 attribute of the data member containing the
15124 anonymous_size
= TYPE_LENGTH (fp
->type
);
15126 SET_FIELD_BITPOS (*fp
,
15127 (FIELD_BITPOS (*fp
)
15128 + anonymous_size
* bits_per_byte
15129 - bit_offset
- FIELD_BITSIZE (*fp
)));
15132 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
15134 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
15135 + dwarf2_get_attr_constant_value (attr
, 0)));
15137 /* Get name of field. */
15138 fieldname
= dwarf2_name (die
, cu
);
15139 if (fieldname
== NULL
)
15142 /* The name is already allocated along with this objfile, so we don't
15143 need to duplicate it for the type. */
15144 fp
->name
= fieldname
;
15146 /* Change accessibility for artificial fields (e.g. virtual table
15147 pointer or virtual base class pointer) to private. */
15148 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
15150 FIELD_ARTIFICIAL (*fp
) = 1;
15151 new_field
->accessibility
= DW_ACCESS_private
;
15152 fip
->non_public_fields
= 1;
15155 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
15157 /* C++ static member. */
15159 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
15160 is a declaration, but all versions of G++ as of this writing
15161 (so through at least 3.2.1) incorrectly generate
15162 DW_TAG_variable tags. */
15164 const char *physname
;
15166 /* Get name of field. */
15167 fieldname
= dwarf2_name (die
, cu
);
15168 if (fieldname
== NULL
)
15171 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15173 /* Only create a symbol if this is an external value.
15174 new_symbol checks this and puts the value in the global symbol
15175 table, which we want. If it is not external, new_symbol
15176 will try to put the value in cu->list_in_scope which is wrong. */
15177 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
15179 /* A static const member, not much different than an enum as far as
15180 we're concerned, except that we can support more types. */
15181 new_symbol (die
, NULL
, cu
);
15184 /* Get physical name. */
15185 physname
= dwarf2_physname (fieldname
, die
, cu
);
15187 /* The name is already allocated along with this objfile, so we don't
15188 need to duplicate it for the type. */
15189 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
15190 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15191 FIELD_NAME (*fp
) = fieldname
;
15193 else if (die
->tag
== DW_TAG_inheritance
)
15197 /* C++ base class field. */
15198 if (handle_data_member_location (die
, cu
, &offset
))
15199 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
15200 FIELD_BITSIZE (*fp
) = 0;
15201 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15202 FIELD_NAME (*fp
) = TYPE_NAME (fp
->type
);
15204 else if (die
->tag
== DW_TAG_variant_part
)
15206 /* process_structure_scope will treat this DIE as a union. */
15207 process_structure_scope (die
, cu
);
15209 /* The variant part is relative to the start of the enclosing
15211 SET_FIELD_BITPOS (*fp
, 0);
15212 fp
->type
= get_die_type (die
, cu
);
15213 fp
->artificial
= 1;
15214 fp
->name
= "<<variant>>";
15216 /* Normally a DW_TAG_variant_part won't have a size, but our
15217 representation requires one, so set it to the maximum of the
15218 child sizes, being sure to account for the offset at which
15219 each child is seen. */
15220 if (TYPE_LENGTH (fp
->type
) == 0)
15223 for (int i
= 0; i
< TYPE_NFIELDS (fp
->type
); ++i
)
15225 unsigned len
= ((TYPE_FIELD_BITPOS (fp
->type
, i
) + 7) / 8
15226 + TYPE_LENGTH (TYPE_FIELD_TYPE (fp
->type
, i
)));
15230 TYPE_LENGTH (fp
->type
) = max
;
15234 gdb_assert_not_reached ("missing case in dwarf2_add_field");
15237 /* Can the type given by DIE define another type? */
15240 type_can_define_types (const struct die_info
*die
)
15244 case DW_TAG_typedef
:
15245 case DW_TAG_class_type
:
15246 case DW_TAG_structure_type
:
15247 case DW_TAG_union_type
:
15248 case DW_TAG_enumeration_type
:
15256 /* Add a type definition defined in the scope of the FIP's class. */
15259 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
15260 struct dwarf2_cu
*cu
)
15262 struct decl_field fp
;
15263 memset (&fp
, 0, sizeof (fp
));
15265 gdb_assert (type_can_define_types (die
));
15267 /* Get name of field. NULL is okay here, meaning an anonymous type. */
15268 fp
.name
= dwarf2_name (die
, cu
);
15269 fp
.type
= read_type_die (die
, cu
);
15271 /* Save accessibility. */
15272 enum dwarf_access_attribute accessibility
;
15273 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15275 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15277 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15278 switch (accessibility
)
15280 case DW_ACCESS_public
:
15281 /* The assumed value if neither private nor protected. */
15283 case DW_ACCESS_private
:
15286 case DW_ACCESS_protected
:
15287 fp
.is_protected
= 1;
15290 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
15293 if (die
->tag
== DW_TAG_typedef
)
15294 fip
->typedef_field_list
.push_back (fp
);
15296 fip
->nested_types_list
.push_back (fp
);
15299 /* Create the vector of fields, and attach it to the type. */
15302 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
15303 struct dwarf2_cu
*cu
)
15305 int nfields
= fip
->nfields
;
15307 /* Record the field count, allocate space for the array of fields,
15308 and create blank accessibility bitfields if necessary. */
15309 TYPE_NFIELDS (type
) = nfields
;
15310 TYPE_FIELDS (type
) = (struct field
*)
15311 TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
);
15313 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
15315 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15317 TYPE_FIELD_PRIVATE_BITS (type
) =
15318 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15319 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
15321 TYPE_FIELD_PROTECTED_BITS (type
) =
15322 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15323 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
15325 TYPE_FIELD_IGNORE_BITS (type
) =
15326 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15327 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
15330 /* If the type has baseclasses, allocate and clear a bit vector for
15331 TYPE_FIELD_VIRTUAL_BITS. */
15332 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
15334 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
15335 unsigned char *pointer
;
15337 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15338 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
15339 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
15340 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
15341 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
15344 if (TYPE_FLAG_DISCRIMINATED_UNION (type
))
15346 struct discriminant_info
*di
= alloc_discriminant_info (type
, -1, -1);
15348 for (int index
= 0; index
< nfields
; ++index
)
15350 struct nextfield
&field
= fip
->fields
[index
];
15352 if (field
.variant
.is_discriminant
)
15353 di
->discriminant_index
= index
;
15354 else if (field
.variant
.default_branch
)
15355 di
->default_index
= index
;
15357 di
->discriminants
[index
] = field
.variant
.discriminant_value
;
15361 /* Copy the saved-up fields into the field vector. */
15362 for (int i
= 0; i
< nfields
; ++i
)
15364 struct nextfield
&field
15365 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
15366 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
15368 TYPE_FIELD (type
, i
) = field
.field
;
15369 switch (field
.accessibility
)
15371 case DW_ACCESS_private
:
15372 if (cu
->language
!= language_ada
)
15373 SET_TYPE_FIELD_PRIVATE (type
, i
);
15376 case DW_ACCESS_protected
:
15377 if (cu
->language
!= language_ada
)
15378 SET_TYPE_FIELD_PROTECTED (type
, i
);
15381 case DW_ACCESS_public
:
15385 /* Unknown accessibility. Complain and treat it as public. */
15387 complaint (_("unsupported accessibility %d"),
15388 field
.accessibility
);
15392 if (i
< fip
->baseclasses
.size ())
15394 switch (field
.virtuality
)
15396 case DW_VIRTUALITY_virtual
:
15397 case DW_VIRTUALITY_pure_virtual
:
15398 if (cu
->language
== language_ada
)
15399 error (_("unexpected virtuality in component of Ada type"));
15400 SET_TYPE_FIELD_VIRTUAL (type
, i
);
15407 /* Return true if this member function is a constructor, false
15411 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15413 const char *fieldname
;
15414 const char *type_name
;
15417 if (die
->parent
== NULL
)
15420 if (die
->parent
->tag
!= DW_TAG_structure_type
15421 && die
->parent
->tag
!= DW_TAG_union_type
15422 && die
->parent
->tag
!= DW_TAG_class_type
)
15425 fieldname
= dwarf2_name (die
, cu
);
15426 type_name
= dwarf2_name (die
->parent
, cu
);
15427 if (fieldname
== NULL
|| type_name
== NULL
)
15430 len
= strlen (fieldname
);
15431 return (strncmp (fieldname
, type_name
, len
) == 0
15432 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15435 /* Check if the given VALUE is a recognized enum
15436 dwarf_defaulted_attribute constant according to DWARF5 spec,
15440 is_valid_DW_AT_defaulted (ULONGEST value
)
15444 case DW_DEFAULTED_no
:
15445 case DW_DEFAULTED_in_class
:
15446 case DW_DEFAULTED_out_of_class
:
15450 complaint (_("unrecognized DW_AT_defaulted value (%s)"), pulongest (value
));
15454 /* Add a member function to the proper fieldlist. */
15457 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15458 struct type
*type
, struct dwarf2_cu
*cu
)
15460 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15461 struct attribute
*attr
;
15463 struct fnfieldlist
*flp
= nullptr;
15464 struct fn_field
*fnp
;
15465 const char *fieldname
;
15466 struct type
*this_type
;
15467 enum dwarf_access_attribute accessibility
;
15469 if (cu
->language
== language_ada
)
15470 error (_("unexpected member function in Ada type"));
15472 /* Get name of member function. */
15473 fieldname
= dwarf2_name (die
, cu
);
15474 if (fieldname
== NULL
)
15477 /* Look up member function name in fieldlist. */
15478 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15480 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15482 flp
= &fip
->fnfieldlists
[i
];
15487 /* Create a new fnfieldlist if necessary. */
15488 if (flp
== nullptr)
15490 fip
->fnfieldlists
.emplace_back ();
15491 flp
= &fip
->fnfieldlists
.back ();
15492 flp
->name
= fieldname
;
15493 i
= fip
->fnfieldlists
.size () - 1;
15496 /* Create a new member function field and add it to the vector of
15498 flp
->fnfields
.emplace_back ();
15499 fnp
= &flp
->fnfields
.back ();
15501 /* Delay processing of the physname until later. */
15502 if (cu
->language
== language_cplus
)
15503 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15507 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15508 fnp
->physname
= physname
? physname
: "";
15511 fnp
->type
= alloc_type (objfile
);
15512 this_type
= read_type_die (die
, cu
);
15513 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
15515 int nparams
= TYPE_NFIELDS (this_type
);
15517 /* TYPE is the domain of this method, and THIS_TYPE is the type
15518 of the method itself (TYPE_CODE_METHOD). */
15519 smash_to_method_type (fnp
->type
, type
,
15520 TYPE_TARGET_TYPE (this_type
),
15521 TYPE_FIELDS (this_type
),
15522 TYPE_NFIELDS (this_type
),
15523 TYPE_VARARGS (this_type
));
15525 /* Handle static member functions.
15526 Dwarf2 has no clean way to discern C++ static and non-static
15527 member functions. G++ helps GDB by marking the first
15528 parameter for non-static member functions (which is the this
15529 pointer) as artificial. We obtain this information from
15530 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15531 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15532 fnp
->voffset
= VOFFSET_STATIC
;
15535 complaint (_("member function type missing for '%s'"),
15536 dwarf2_full_name (fieldname
, die
, cu
));
15538 /* Get fcontext from DW_AT_containing_type if present. */
15539 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15540 fnp
->fcontext
= die_containing_type (die
, cu
);
15542 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15543 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15545 /* Get accessibility. */
15546 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15547 if (attr
!= nullptr)
15548 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15550 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15551 switch (accessibility
)
15553 case DW_ACCESS_private
:
15554 fnp
->is_private
= 1;
15556 case DW_ACCESS_protected
:
15557 fnp
->is_protected
= 1;
15561 /* Check for artificial methods. */
15562 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15563 if (attr
&& DW_UNSND (attr
) != 0)
15564 fnp
->is_artificial
= 1;
15566 /* Check for defaulted methods. */
15567 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
15568 if (attr
!= nullptr && is_valid_DW_AT_defaulted (DW_UNSND (attr
)))
15569 fnp
->defaulted
= (enum dwarf_defaulted_attribute
) DW_UNSND (attr
);
15571 /* Check for deleted methods. */
15572 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
15573 if (attr
!= nullptr && DW_UNSND (attr
) != 0)
15574 fnp
->is_deleted
= 1;
15576 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15578 /* Get index in virtual function table if it is a virtual member
15579 function. For older versions of GCC, this is an offset in the
15580 appropriate virtual table, as specified by DW_AT_containing_type.
15581 For everyone else, it is an expression to be evaluated relative
15582 to the object address. */
15584 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15585 if (attr
!= nullptr)
15587 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
15589 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
15591 /* Old-style GCC. */
15592 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
15594 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
15595 || (DW_BLOCK (attr
)->size
> 1
15596 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
15597 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
15599 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15600 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15601 dwarf2_complex_location_expr_complaint ();
15603 fnp
->voffset
/= cu
->header
.addr_size
;
15607 dwarf2_complex_location_expr_complaint ();
15609 if (!fnp
->fcontext
)
15611 /* If there is no `this' field and no DW_AT_containing_type,
15612 we cannot actually find a base class context for the
15614 if (TYPE_NFIELDS (this_type
) == 0
15615 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15617 complaint (_("cannot determine context for virtual member "
15618 "function \"%s\" (offset %s)"),
15619 fieldname
, sect_offset_str (die
->sect_off
));
15624 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
15628 else if (attr_form_is_section_offset (attr
))
15630 dwarf2_complex_location_expr_complaint ();
15634 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15640 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15641 if (attr
&& DW_UNSND (attr
))
15643 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15644 complaint (_("Member function \"%s\" (offset %s) is virtual "
15645 "but the vtable offset is not specified"),
15646 fieldname
, sect_offset_str (die
->sect_off
));
15647 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15648 TYPE_CPLUS_DYNAMIC (type
) = 1;
15653 /* Create the vector of member function fields, and attach it to the type. */
15656 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15657 struct dwarf2_cu
*cu
)
15659 if (cu
->language
== language_ada
)
15660 error (_("unexpected member functions in Ada type"));
15662 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15663 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15665 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15667 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15669 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15670 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15672 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15673 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15674 fn_flp
->fn_fields
= (struct fn_field
*)
15675 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15677 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15678 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15681 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15684 /* Returns non-zero if NAME is the name of a vtable member in CU's
15685 language, zero otherwise. */
15687 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15689 static const char vptr
[] = "_vptr";
15691 /* Look for the C++ form of the vtable. */
15692 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15698 /* GCC outputs unnamed structures that are really pointers to member
15699 functions, with the ABI-specified layout. If TYPE describes
15700 such a structure, smash it into a member function type.
15702 GCC shouldn't do this; it should just output pointer to member DIEs.
15703 This is GCC PR debug/28767. */
15706 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15708 struct type
*pfn_type
, *self_type
, *new_type
;
15710 /* Check for a structure with no name and two children. */
15711 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
15714 /* Check for __pfn and __delta members. */
15715 if (TYPE_FIELD_NAME (type
, 0) == NULL
15716 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15717 || TYPE_FIELD_NAME (type
, 1) == NULL
15718 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15721 /* Find the type of the method. */
15722 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
15723 if (pfn_type
== NULL
15724 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
15725 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
15728 /* Look for the "this" argument. */
15729 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15730 if (TYPE_NFIELDS (pfn_type
) == 0
15731 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
15732 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
15735 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
15736 new_type
= alloc_type (objfile
);
15737 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15738 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
15739 TYPE_VARARGS (pfn_type
));
15740 smash_to_methodptr_type (type
, new_type
);
15743 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15744 appropriate error checking and issuing complaints if there is a
15748 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15750 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15752 if (attr
== nullptr)
15755 if (!attr_form_is_constant (attr
))
15757 complaint (_("DW_AT_alignment must have constant form"
15758 " - DIE at %s [in module %s]"),
15759 sect_offset_str (die
->sect_off
),
15760 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15765 if (attr
->form
== DW_FORM_sdata
)
15767 LONGEST val
= DW_SND (attr
);
15770 complaint (_("DW_AT_alignment value must not be negative"
15771 " - DIE at %s [in module %s]"),
15772 sect_offset_str (die
->sect_off
),
15773 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15779 align
= DW_UNSND (attr
);
15783 complaint (_("DW_AT_alignment value must not be zero"
15784 " - DIE at %s [in module %s]"),
15785 sect_offset_str (die
->sect_off
),
15786 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15789 if ((align
& (align
- 1)) != 0)
15791 complaint (_("DW_AT_alignment value must be a power of 2"
15792 " - DIE at %s [in module %s]"),
15793 sect_offset_str (die
->sect_off
),
15794 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15801 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15802 the alignment for TYPE. */
15805 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15808 if (!set_type_align (type
, get_alignment (cu
, die
)))
15809 complaint (_("DW_AT_alignment value too large"
15810 " - DIE at %s [in module %s]"),
15811 sect_offset_str (die
->sect_off
),
15812 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15815 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15816 constant for a type, according to DWARF5 spec, Table 5.5. */
15819 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
15824 case DW_CC_pass_by_reference
:
15825 case DW_CC_pass_by_value
:
15829 complaint (_("unrecognized DW_AT_calling_convention value "
15830 "(%s) for a type"), pulongest (value
));
15835 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15836 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
15837 also according to GNU-specific values (see include/dwarf2.h). */
15840 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
15845 case DW_CC_program
:
15849 case DW_CC_GNU_renesas_sh
:
15850 case DW_CC_GNU_borland_fastcall_i386
:
15851 case DW_CC_GDB_IBM_OpenCL
:
15855 complaint (_("unrecognized DW_AT_calling_convention value "
15856 "(%s) for a subroutine"), pulongest (value
));
15861 /* Called when we find the DIE that starts a structure or union scope
15862 (definition) to create a type for the structure or union. Fill in
15863 the type's name and general properties; the members will not be
15864 processed until process_structure_scope. A symbol table entry for
15865 the type will also not be done until process_structure_scope (assuming
15866 the type has a name).
15868 NOTE: we need to call these functions regardless of whether or not the
15869 DIE has a DW_AT_name attribute, since it might be an anonymous
15870 structure or union. This gets the type entered into our set of
15871 user defined types. */
15873 static struct type
*
15874 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15876 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15878 struct attribute
*attr
;
15881 /* If the definition of this type lives in .debug_types, read that type.
15882 Don't follow DW_AT_specification though, that will take us back up
15883 the chain and we want to go down. */
15884 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
15885 if (attr
!= nullptr)
15887 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15889 /* The type's CU may not be the same as CU.
15890 Ensure TYPE is recorded with CU in die_type_hash. */
15891 return set_die_type (die
, type
, cu
);
15894 type
= alloc_type (objfile
);
15895 INIT_CPLUS_SPECIFIC (type
);
15897 name
= dwarf2_name (die
, cu
);
15900 if (cu
->language
== language_cplus
15901 || cu
->language
== language_d
15902 || cu
->language
== language_rust
)
15904 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15906 /* dwarf2_full_name might have already finished building the DIE's
15907 type. If so, there is no need to continue. */
15908 if (get_die_type (die
, cu
) != NULL
)
15909 return get_die_type (die
, cu
);
15911 TYPE_NAME (type
) = full_name
;
15915 /* The name is already allocated along with this objfile, so
15916 we don't need to duplicate it for the type. */
15917 TYPE_NAME (type
) = name
;
15921 if (die
->tag
== DW_TAG_structure_type
)
15923 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15925 else if (die
->tag
== DW_TAG_union_type
)
15927 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15929 else if (die
->tag
== DW_TAG_variant_part
)
15931 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15932 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
15936 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15939 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15940 TYPE_DECLARED_CLASS (type
) = 1;
15942 /* Store the calling convention in the type if it's available in
15943 the die. Otherwise the calling convention remains set to
15944 the default value DW_CC_normal. */
15945 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15946 if (attr
!= nullptr
15947 && is_valid_DW_AT_calling_convention_for_type (DW_UNSND (attr
)))
15949 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15950 TYPE_CPLUS_CALLING_CONVENTION (type
)
15951 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
15954 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15955 if (attr
!= nullptr)
15957 if (attr_form_is_constant (attr
))
15958 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15961 /* For the moment, dynamic type sizes are not supported
15962 by GDB's struct type. The actual size is determined
15963 on-demand when resolving the type of a given object,
15964 so set the type's length to zero for now. Otherwise,
15965 we record an expression as the length, and that expression
15966 could lead to a very large value, which could eventually
15967 lead to us trying to allocate that much memory when creating
15968 a value of that type. */
15969 TYPE_LENGTH (type
) = 0;
15974 TYPE_LENGTH (type
) = 0;
15977 maybe_set_alignment (cu
, die
, type
);
15979 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15981 /* ICC<14 does not output the required DW_AT_declaration on
15982 incomplete types, but gives them a size of zero. */
15983 TYPE_STUB (type
) = 1;
15986 TYPE_STUB_SUPPORTED (type
) = 1;
15988 if (die_is_declaration (die
, cu
))
15989 TYPE_STUB (type
) = 1;
15990 else if (attr
== NULL
&& die
->child
== NULL
15991 && producer_is_realview (cu
->producer
))
15992 /* RealView does not output the required DW_AT_declaration
15993 on incomplete types. */
15994 TYPE_STUB (type
) = 1;
15996 /* We need to add the type field to the die immediately so we don't
15997 infinitely recurse when dealing with pointers to the structure
15998 type within the structure itself. */
15999 set_die_type (die
, type
, cu
);
16001 /* set_die_type should be already done. */
16002 set_descriptive_type (type
, die
, cu
);
16007 /* A helper for process_structure_scope that handles a single member
16011 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
16012 struct field_info
*fi
,
16013 std::vector
<struct symbol
*> *template_args
,
16014 struct dwarf2_cu
*cu
)
16016 if (child_die
->tag
== DW_TAG_member
16017 || child_die
->tag
== DW_TAG_variable
16018 || child_die
->tag
== DW_TAG_variant_part
)
16020 /* NOTE: carlton/2002-11-05: A C++ static data member
16021 should be a DW_TAG_member that is a declaration, but
16022 all versions of G++ as of this writing (so through at
16023 least 3.2.1) incorrectly generate DW_TAG_variable
16024 tags for them instead. */
16025 dwarf2_add_field (fi
, child_die
, cu
);
16027 else if (child_die
->tag
== DW_TAG_subprogram
)
16029 /* Rust doesn't have member functions in the C++ sense.
16030 However, it does emit ordinary functions as children
16031 of a struct DIE. */
16032 if (cu
->language
== language_rust
)
16033 read_func_scope (child_die
, cu
);
16036 /* C++ member function. */
16037 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
16040 else if (child_die
->tag
== DW_TAG_inheritance
)
16042 /* C++ base class field. */
16043 dwarf2_add_field (fi
, child_die
, cu
);
16045 else if (type_can_define_types (child_die
))
16046 dwarf2_add_type_defn (fi
, child_die
, cu
);
16047 else if (child_die
->tag
== DW_TAG_template_type_param
16048 || child_die
->tag
== DW_TAG_template_value_param
)
16050 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
16053 template_args
->push_back (arg
);
16055 else if (child_die
->tag
== DW_TAG_variant
)
16057 /* In a variant we want to get the discriminant and also add a
16058 field for our sole member child. */
16059 struct attribute
*discr
= dwarf2_attr (child_die
, DW_AT_discr_value
, cu
);
16061 for (die_info
*variant_child
= child_die
->child
;
16062 variant_child
!= NULL
;
16063 variant_child
= sibling_die (variant_child
))
16065 if (variant_child
->tag
== DW_TAG_member
)
16067 handle_struct_member_die (variant_child
, type
, fi
,
16068 template_args
, cu
);
16069 /* Only handle the one. */
16074 /* We don't handle this but we might as well report it if we see
16076 if (dwarf2_attr (child_die
, DW_AT_discr_list
, cu
) != nullptr)
16077 complaint (_("DW_AT_discr_list is not supported yet"
16078 " - DIE at %s [in module %s]"),
16079 sect_offset_str (child_die
->sect_off
),
16080 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16082 /* The first field was just added, so we can stash the
16083 discriminant there. */
16084 gdb_assert (!fi
->fields
.empty ());
16086 fi
->fields
.back ().variant
.default_branch
= true;
16088 fi
->fields
.back ().variant
.discriminant_value
= DW_UNSND (discr
);
16092 /* Finish creating a structure or union type, including filling in
16093 its members and creating a symbol for it. */
16096 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16098 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16099 struct die_info
*child_die
;
16102 type
= get_die_type (die
, cu
);
16104 type
= read_structure_type (die
, cu
);
16106 /* When reading a DW_TAG_variant_part, we need to notice when we
16107 read the discriminant member, so we can record it later in the
16108 discriminant_info. */
16109 bool is_variant_part
= TYPE_FLAG_DISCRIMINATED_UNION (type
);
16110 sect_offset discr_offset
{};
16111 bool has_template_parameters
= false;
16113 if (is_variant_part
)
16115 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
16118 /* Maybe it's a univariant form, an extension we support.
16119 In this case arrange not to check the offset. */
16120 is_variant_part
= false;
16122 else if (attr_form_is_ref (discr
))
16124 struct dwarf2_cu
*target_cu
= cu
;
16125 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
16127 discr_offset
= target_die
->sect_off
;
16131 complaint (_("DW_AT_discr does not have DIE reference form"
16132 " - DIE at %s [in module %s]"),
16133 sect_offset_str (die
->sect_off
),
16134 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16135 is_variant_part
= false;
16139 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
16141 struct field_info fi
;
16142 std::vector
<struct symbol
*> template_args
;
16144 child_die
= die
->child
;
16146 while (child_die
&& child_die
->tag
)
16148 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
16150 if (is_variant_part
&& discr_offset
== child_die
->sect_off
)
16151 fi
.fields
.back ().variant
.is_discriminant
= true;
16153 child_die
= sibling_die (child_die
);
16156 /* Attach template arguments to type. */
16157 if (!template_args
.empty ())
16159 has_template_parameters
= true;
16160 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16161 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
16162 TYPE_TEMPLATE_ARGUMENTS (type
)
16163 = XOBNEWVEC (&objfile
->objfile_obstack
,
16165 TYPE_N_TEMPLATE_ARGUMENTS (type
));
16166 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
16167 template_args
.data (),
16168 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
16169 * sizeof (struct symbol
*)));
16172 /* Attach fields and member functions to the type. */
16174 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
16175 if (!fi
.fnfieldlists
.empty ())
16177 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
16179 /* Get the type which refers to the base class (possibly this
16180 class itself) which contains the vtable pointer for the current
16181 class from the DW_AT_containing_type attribute. This use of
16182 DW_AT_containing_type is a GNU extension. */
16184 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
16186 struct type
*t
= die_containing_type (die
, cu
);
16188 set_type_vptr_basetype (type
, t
);
16193 /* Our own class provides vtbl ptr. */
16194 for (i
= TYPE_NFIELDS (t
) - 1;
16195 i
>= TYPE_N_BASECLASSES (t
);
16198 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
16200 if (is_vtable_name (fieldname
, cu
))
16202 set_type_vptr_fieldno (type
, i
);
16207 /* Complain if virtual function table field not found. */
16208 if (i
< TYPE_N_BASECLASSES (t
))
16209 complaint (_("virtual function table pointer "
16210 "not found when defining class '%s'"),
16211 TYPE_NAME (type
) ? TYPE_NAME (type
) : "");
16215 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
16218 else if (cu
->producer
16219 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
16221 /* The IBM XLC compiler does not provide direct indication
16222 of the containing type, but the vtable pointer is
16223 always named __vfp. */
16227 for (i
= TYPE_NFIELDS (type
) - 1;
16228 i
>= TYPE_N_BASECLASSES (type
);
16231 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
16233 set_type_vptr_fieldno (type
, i
);
16234 set_type_vptr_basetype (type
, type
);
16241 /* Copy fi.typedef_field_list linked list elements content into the
16242 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
16243 if (!fi
.typedef_field_list
.empty ())
16245 int count
= fi
.typedef_field_list
.size ();
16247 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16248 TYPE_TYPEDEF_FIELD_ARRAY (type
)
16249 = ((struct decl_field
*)
16251 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
16252 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
16254 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
16255 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
16258 /* Copy fi.nested_types_list linked list elements content into the
16259 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
16260 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
16262 int count
= fi
.nested_types_list
.size ();
16264 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16265 TYPE_NESTED_TYPES_ARRAY (type
)
16266 = ((struct decl_field
*)
16267 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
16268 TYPE_NESTED_TYPES_COUNT (type
) = count
;
16270 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
16271 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
16275 quirk_gcc_member_function_pointer (type
, objfile
);
16276 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
16277 cu
->rust_unions
.push_back (type
);
16279 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
16280 snapshots) has been known to create a die giving a declaration
16281 for a class that has, as a child, a die giving a definition for a
16282 nested class. So we have to process our children even if the
16283 current die is a declaration. Normally, of course, a declaration
16284 won't have any children at all. */
16286 child_die
= die
->child
;
16288 while (child_die
!= NULL
&& child_die
->tag
)
16290 if (child_die
->tag
== DW_TAG_member
16291 || child_die
->tag
== DW_TAG_variable
16292 || child_die
->tag
== DW_TAG_inheritance
16293 || child_die
->tag
== DW_TAG_template_value_param
16294 || child_die
->tag
== DW_TAG_template_type_param
)
16299 process_die (child_die
, cu
);
16301 child_die
= sibling_die (child_die
);
16304 /* Do not consider external references. According to the DWARF standard,
16305 these DIEs are identified by the fact that they have no byte_size
16306 attribute, and a declaration attribute. */
16307 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
16308 || !die_is_declaration (die
, cu
))
16310 struct symbol
*sym
= new_symbol (die
, type
, cu
);
16312 if (has_template_parameters
)
16314 struct symtab
*symtab
;
16315 if (sym
!= nullptr)
16316 symtab
= symbol_symtab (sym
);
16317 else if (cu
->line_header
!= nullptr)
16319 /* Any related symtab will do. */
16321 = cu
->line_header
->file_names ()[0].symtab
;
16326 complaint (_("could not find suitable "
16327 "symtab for template parameter"
16328 " - DIE at %s [in module %s]"),
16329 sect_offset_str (die
->sect_off
),
16330 objfile_name (objfile
));
16333 if (symtab
!= nullptr)
16335 /* Make sure that the symtab is set on the new symbols.
16336 Even though they don't appear in this symtab directly,
16337 other parts of gdb assume that symbols do, and this is
16338 reasonably true. */
16339 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
16340 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
16346 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
16347 update TYPE using some information only available in DIE's children. */
16350 update_enumeration_type_from_children (struct die_info
*die
,
16352 struct dwarf2_cu
*cu
)
16354 struct die_info
*child_die
;
16355 int unsigned_enum
= 1;
16359 auto_obstack obstack
;
16361 for (child_die
= die
->child
;
16362 child_die
!= NULL
&& child_die
->tag
;
16363 child_die
= sibling_die (child_die
))
16365 struct attribute
*attr
;
16367 const gdb_byte
*bytes
;
16368 struct dwarf2_locexpr_baton
*baton
;
16371 if (child_die
->tag
!= DW_TAG_enumerator
)
16374 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16378 name
= dwarf2_name (child_die
, cu
);
16380 name
= "<anonymous enumerator>";
16382 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16383 &value
, &bytes
, &baton
);
16389 else if ((mask
& value
) != 0)
16394 /* If we already know that the enum type is neither unsigned, nor
16395 a flag type, no need to look at the rest of the enumerates. */
16396 if (!unsigned_enum
&& !flag_enum
)
16401 TYPE_UNSIGNED (type
) = 1;
16403 TYPE_FLAG_ENUM (type
) = 1;
16406 /* Given a DW_AT_enumeration_type die, set its type. We do not
16407 complete the type's fields yet, or create any symbols. */
16409 static struct type
*
16410 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16412 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16414 struct attribute
*attr
;
16417 /* If the definition of this type lives in .debug_types, read that type.
16418 Don't follow DW_AT_specification though, that will take us back up
16419 the chain and we want to go down. */
16420 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
16421 if (attr
!= nullptr)
16423 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16425 /* The type's CU may not be the same as CU.
16426 Ensure TYPE is recorded with CU in die_type_hash. */
16427 return set_die_type (die
, type
, cu
);
16430 type
= alloc_type (objfile
);
16432 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
16433 name
= dwarf2_full_name (NULL
, die
, cu
);
16435 TYPE_NAME (type
) = name
;
16437 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16440 struct type
*underlying_type
= die_type (die
, cu
);
16442 TYPE_TARGET_TYPE (type
) = underlying_type
;
16445 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16446 if (attr
!= nullptr)
16448 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16452 TYPE_LENGTH (type
) = 0;
16455 maybe_set_alignment (cu
, die
, type
);
16457 /* The enumeration DIE can be incomplete. In Ada, any type can be
16458 declared as private in the package spec, and then defined only
16459 inside the package body. Such types are known as Taft Amendment
16460 Types. When another package uses such a type, an incomplete DIE
16461 may be generated by the compiler. */
16462 if (die_is_declaration (die
, cu
))
16463 TYPE_STUB (type
) = 1;
16465 /* Finish the creation of this type by using the enum's children.
16466 We must call this even when the underlying type has been provided
16467 so that we can determine if we're looking at a "flag" enum. */
16468 update_enumeration_type_from_children (die
, type
, cu
);
16470 /* If this type has an underlying type that is not a stub, then we
16471 may use its attributes. We always use the "unsigned" attribute
16472 in this situation, because ordinarily we guess whether the type
16473 is unsigned -- but the guess can be wrong and the underlying type
16474 can tell us the reality. However, we defer to a local size
16475 attribute if one exists, because this lets the compiler override
16476 the underlying type if needed. */
16477 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
16479 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
16480 if (TYPE_LENGTH (type
) == 0)
16481 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
16482 if (TYPE_RAW_ALIGN (type
) == 0
16483 && TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)) != 0)
16484 set_type_align (type
, TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)));
16487 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16489 return set_die_type (die
, type
, cu
);
16492 /* Given a pointer to a die which begins an enumeration, process all
16493 the dies that define the members of the enumeration, and create the
16494 symbol for the enumeration type.
16496 NOTE: We reverse the order of the element list. */
16499 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16501 struct type
*this_type
;
16503 this_type
= get_die_type (die
, cu
);
16504 if (this_type
== NULL
)
16505 this_type
= read_enumeration_type (die
, cu
);
16507 if (die
->child
!= NULL
)
16509 struct die_info
*child_die
;
16510 struct symbol
*sym
;
16511 std::vector
<struct field
> fields
;
16514 child_die
= die
->child
;
16515 while (child_die
&& child_die
->tag
)
16517 if (child_die
->tag
!= DW_TAG_enumerator
)
16519 process_die (child_die
, cu
);
16523 name
= dwarf2_name (child_die
, cu
);
16526 sym
= new_symbol (child_die
, this_type
, cu
);
16528 fields
.emplace_back ();
16529 struct field
&field
= fields
.back ();
16531 FIELD_NAME (field
) = sym
->linkage_name ();
16532 FIELD_TYPE (field
) = NULL
;
16533 SET_FIELD_ENUMVAL (field
, SYMBOL_VALUE (sym
));
16534 FIELD_BITSIZE (field
) = 0;
16538 child_die
= sibling_die (child_die
);
16541 if (!fields
.empty ())
16543 TYPE_NFIELDS (this_type
) = fields
.size ();
16544 TYPE_FIELDS (this_type
) = (struct field
*)
16545 TYPE_ALLOC (this_type
, sizeof (struct field
) * fields
.size ());
16546 memcpy (TYPE_FIELDS (this_type
), fields
.data (),
16547 sizeof (struct field
) * fields
.size ());
16551 /* If we are reading an enum from a .debug_types unit, and the enum
16552 is a declaration, and the enum is not the signatured type in the
16553 unit, then we do not want to add a symbol for it. Adding a
16554 symbol would in some cases obscure the true definition of the
16555 enum, giving users an incomplete type when the definition is
16556 actually available. Note that we do not want to do this for all
16557 enums which are just declarations, because C++0x allows forward
16558 enum declarations. */
16559 if (cu
->per_cu
->is_debug_types
16560 && die_is_declaration (die
, cu
))
16562 struct signatured_type
*sig_type
;
16564 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16565 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16566 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16570 new_symbol (die
, this_type
, cu
);
16573 /* Extract all information from a DW_TAG_array_type DIE and put it in
16574 the DIE's type field. For now, this only handles one dimensional
16577 static struct type
*
16578 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16580 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16581 struct die_info
*child_die
;
16583 struct type
*element_type
, *range_type
, *index_type
;
16584 struct attribute
*attr
;
16586 struct dynamic_prop
*byte_stride_prop
= NULL
;
16587 unsigned int bit_stride
= 0;
16589 element_type
= die_type (die
, cu
);
16591 /* The die_type call above may have already set the type for this DIE. */
16592 type
= get_die_type (die
, cu
);
16596 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16600 struct type
*prop_type
16601 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
16604 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16605 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
16609 complaint (_("unable to read array DW_AT_byte_stride "
16610 " - DIE at %s [in module %s]"),
16611 sect_offset_str (die
->sect_off
),
16612 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16613 /* Ignore this attribute. We will likely not be able to print
16614 arrays of this type correctly, but there is little we can do
16615 to help if we cannot read the attribute's value. */
16616 byte_stride_prop
= NULL
;
16620 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16622 bit_stride
= DW_UNSND (attr
);
16624 /* Irix 6.2 native cc creates array types without children for
16625 arrays with unspecified length. */
16626 if (die
->child
== NULL
)
16628 index_type
= objfile_type (objfile
)->builtin_int
;
16629 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16630 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16631 byte_stride_prop
, bit_stride
);
16632 return set_die_type (die
, type
, cu
);
16635 std::vector
<struct type
*> range_types
;
16636 child_die
= die
->child
;
16637 while (child_die
&& child_die
->tag
)
16639 if (child_die
->tag
== DW_TAG_subrange_type
)
16641 struct type
*child_type
= read_type_die (child_die
, cu
);
16643 if (child_type
!= NULL
)
16645 /* The range type was succesfully read. Save it for the
16646 array type creation. */
16647 range_types
.push_back (child_type
);
16650 child_die
= sibling_die (child_die
);
16653 /* Dwarf2 dimensions are output from left to right, create the
16654 necessary array types in backwards order. */
16656 type
= element_type
;
16658 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16662 while (i
< range_types
.size ())
16663 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16664 byte_stride_prop
, bit_stride
);
16668 size_t ndim
= range_types
.size ();
16670 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16671 byte_stride_prop
, bit_stride
);
16674 /* Understand Dwarf2 support for vector types (like they occur on
16675 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16676 array type. This is not part of the Dwarf2/3 standard yet, but a
16677 custom vendor extension. The main difference between a regular
16678 array and the vector variant is that vectors are passed by value
16680 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16681 if (attr
!= nullptr)
16682 make_vector_type (type
);
16684 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16685 implementation may choose to implement triple vectors using this
16687 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16688 if (attr
!= nullptr)
16690 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
16691 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16693 complaint (_("DW_AT_byte_size for array type smaller "
16694 "than the total size of elements"));
16697 name
= dwarf2_name (die
, cu
);
16699 TYPE_NAME (type
) = name
;
16701 maybe_set_alignment (cu
, die
, type
);
16703 /* Install the type in the die. */
16704 set_die_type (die
, type
, cu
);
16706 /* set_die_type should be already done. */
16707 set_descriptive_type (type
, die
, cu
);
16712 static enum dwarf_array_dim_ordering
16713 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16715 struct attribute
*attr
;
16717 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16719 if (attr
!= nullptr)
16720 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
16722 /* GNU F77 is a special case, as at 08/2004 array type info is the
16723 opposite order to the dwarf2 specification, but data is still
16724 laid out as per normal fortran.
16726 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16727 version checking. */
16729 if (cu
->language
== language_fortran
16730 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16732 return DW_ORD_row_major
;
16735 switch (cu
->language_defn
->la_array_ordering
)
16737 case array_column_major
:
16738 return DW_ORD_col_major
;
16739 case array_row_major
:
16741 return DW_ORD_row_major
;
16745 /* Extract all information from a DW_TAG_set_type DIE and put it in
16746 the DIE's type field. */
16748 static struct type
*
16749 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16751 struct type
*domain_type
, *set_type
;
16752 struct attribute
*attr
;
16754 domain_type
= die_type (die
, cu
);
16756 /* The die_type call above may have already set the type for this DIE. */
16757 set_type
= get_die_type (die
, cu
);
16761 set_type
= create_set_type (NULL
, domain_type
);
16763 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16764 if (attr
!= nullptr)
16765 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
16767 maybe_set_alignment (cu
, die
, set_type
);
16769 return set_die_type (die
, set_type
, cu
);
16772 /* A helper for read_common_block that creates a locexpr baton.
16773 SYM is the symbol which we are marking as computed.
16774 COMMON_DIE is the DIE for the common block.
16775 COMMON_LOC is the location expression attribute for the common
16777 MEMBER_LOC is the location expression attribute for the particular
16778 member of the common block that we are processing.
16779 CU is the CU from which the above come. */
16782 mark_common_block_symbol_computed (struct symbol
*sym
,
16783 struct die_info
*common_die
,
16784 struct attribute
*common_loc
,
16785 struct attribute
*member_loc
,
16786 struct dwarf2_cu
*cu
)
16788 struct dwarf2_per_objfile
*dwarf2_per_objfile
16789 = cu
->per_cu
->dwarf2_per_objfile
;
16790 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16791 struct dwarf2_locexpr_baton
*baton
;
16793 unsigned int cu_off
;
16794 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
16795 LONGEST offset
= 0;
16797 gdb_assert (common_loc
&& member_loc
);
16798 gdb_assert (attr_form_is_block (common_loc
));
16799 gdb_assert (attr_form_is_block (member_loc
)
16800 || attr_form_is_constant (member_loc
));
16802 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16803 baton
->per_cu
= cu
->per_cu
;
16804 gdb_assert (baton
->per_cu
);
16806 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16808 if (attr_form_is_constant (member_loc
))
16810 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
16811 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16814 baton
->size
+= DW_BLOCK (member_loc
)->size
;
16816 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16819 *ptr
++ = DW_OP_call4
;
16820 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16821 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16824 if (attr_form_is_constant (member_loc
))
16826 *ptr
++ = DW_OP_addr
;
16827 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16828 ptr
+= cu
->header
.addr_size
;
16832 /* We have to copy the data here, because DW_OP_call4 will only
16833 use a DW_AT_location attribute. */
16834 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
16835 ptr
+= DW_BLOCK (member_loc
)->size
;
16838 *ptr
++ = DW_OP_plus
;
16839 gdb_assert (ptr
- baton
->data
== baton
->size
);
16841 SYMBOL_LOCATION_BATON (sym
) = baton
;
16842 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16845 /* Create appropriate locally-scoped variables for all the
16846 DW_TAG_common_block entries. Also create a struct common_block
16847 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16848 is used to separate the common blocks name namespace from regular
16852 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16854 struct attribute
*attr
;
16856 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16857 if (attr
!= nullptr)
16859 /* Support the .debug_loc offsets. */
16860 if (attr_form_is_block (attr
))
16864 else if (attr_form_is_section_offset (attr
))
16866 dwarf2_complex_location_expr_complaint ();
16871 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16872 "common block member");
16877 if (die
->child
!= NULL
)
16879 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16880 struct die_info
*child_die
;
16881 size_t n_entries
= 0, size
;
16882 struct common_block
*common_block
;
16883 struct symbol
*sym
;
16885 for (child_die
= die
->child
;
16886 child_die
&& child_die
->tag
;
16887 child_die
= sibling_die (child_die
))
16890 size
= (sizeof (struct common_block
)
16891 + (n_entries
- 1) * sizeof (struct symbol
*));
16893 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16895 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16896 common_block
->n_entries
= 0;
16898 for (child_die
= die
->child
;
16899 child_die
&& child_die
->tag
;
16900 child_die
= sibling_die (child_die
))
16902 /* Create the symbol in the DW_TAG_common_block block in the current
16904 sym
= new_symbol (child_die
, NULL
, cu
);
16907 struct attribute
*member_loc
;
16909 common_block
->contents
[common_block
->n_entries
++] = sym
;
16911 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16915 /* GDB has handled this for a long time, but it is
16916 not specified by DWARF. It seems to have been
16917 emitted by gfortran at least as recently as:
16918 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16919 complaint (_("Variable in common block has "
16920 "DW_AT_data_member_location "
16921 "- DIE at %s [in module %s]"),
16922 sect_offset_str (child_die
->sect_off
),
16923 objfile_name (objfile
));
16925 if (attr_form_is_section_offset (member_loc
))
16926 dwarf2_complex_location_expr_complaint ();
16927 else if (attr_form_is_constant (member_loc
)
16928 || attr_form_is_block (member_loc
))
16930 if (attr
!= nullptr)
16931 mark_common_block_symbol_computed (sym
, die
, attr
,
16935 dwarf2_complex_location_expr_complaint ();
16940 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16941 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16945 /* Create a type for a C++ namespace. */
16947 static struct type
*
16948 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16950 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16951 const char *previous_prefix
, *name
;
16955 /* For extensions, reuse the type of the original namespace. */
16956 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16958 struct die_info
*ext_die
;
16959 struct dwarf2_cu
*ext_cu
= cu
;
16961 ext_die
= dwarf2_extension (die
, &ext_cu
);
16962 type
= read_type_die (ext_die
, ext_cu
);
16964 /* EXT_CU may not be the same as CU.
16965 Ensure TYPE is recorded with CU in die_type_hash. */
16966 return set_die_type (die
, type
, cu
);
16969 name
= namespace_name (die
, &is_anonymous
, cu
);
16971 /* Now build the name of the current namespace. */
16973 previous_prefix
= determine_prefix (die
, cu
);
16974 if (previous_prefix
[0] != '\0')
16975 name
= typename_concat (&objfile
->objfile_obstack
,
16976 previous_prefix
, name
, 0, cu
);
16978 /* Create the type. */
16979 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16981 return set_die_type (die
, type
, cu
);
16984 /* Read a namespace scope. */
16987 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16989 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16992 /* Add a symbol associated to this if we haven't seen the namespace
16993 before. Also, add a using directive if it's an anonymous
16996 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
17000 type
= read_type_die (die
, cu
);
17001 new_symbol (die
, type
, cu
);
17003 namespace_name (die
, &is_anonymous
, cu
);
17006 const char *previous_prefix
= determine_prefix (die
, cu
);
17008 std::vector
<const char *> excludes
;
17009 add_using_directive (using_directives (cu
),
17010 previous_prefix
, TYPE_NAME (type
), NULL
,
17011 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
17015 if (die
->child
!= NULL
)
17017 struct die_info
*child_die
= die
->child
;
17019 while (child_die
&& child_die
->tag
)
17021 process_die (child_die
, cu
);
17022 child_die
= sibling_die (child_die
);
17027 /* Read a Fortran module as type. This DIE can be only a declaration used for
17028 imported module. Still we need that type as local Fortran "use ... only"
17029 declaration imports depend on the created type in determine_prefix. */
17031 static struct type
*
17032 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17034 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17035 const char *module_name
;
17038 module_name
= dwarf2_name (die
, cu
);
17039 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
17041 return set_die_type (die
, type
, cu
);
17044 /* Read a Fortran module. */
17047 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
17049 struct die_info
*child_die
= die
->child
;
17052 type
= read_type_die (die
, cu
);
17053 new_symbol (die
, type
, cu
);
17055 while (child_die
&& child_die
->tag
)
17057 process_die (child_die
, cu
);
17058 child_die
= sibling_die (child_die
);
17062 /* Return the name of the namespace represented by DIE. Set
17063 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
17066 static const char *
17067 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
17069 struct die_info
*current_die
;
17070 const char *name
= NULL
;
17072 /* Loop through the extensions until we find a name. */
17074 for (current_die
= die
;
17075 current_die
!= NULL
;
17076 current_die
= dwarf2_extension (die
, &cu
))
17078 /* We don't use dwarf2_name here so that we can detect the absence
17079 of a name -> anonymous namespace. */
17080 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
17086 /* Is it an anonymous namespace? */
17088 *is_anonymous
= (name
== NULL
);
17090 name
= CP_ANONYMOUS_NAMESPACE_STR
;
17095 /* Extract all information from a DW_TAG_pointer_type DIE and add to
17096 the user defined type vector. */
17098 static struct type
*
17099 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17101 struct gdbarch
*gdbarch
17102 = get_objfile_arch (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
17103 struct comp_unit_head
*cu_header
= &cu
->header
;
17105 struct attribute
*attr_byte_size
;
17106 struct attribute
*attr_address_class
;
17107 int byte_size
, addr_class
;
17108 struct type
*target_type
;
17110 target_type
= die_type (die
, cu
);
17112 /* The die_type call above may have already set the type for this DIE. */
17113 type
= get_die_type (die
, cu
);
17117 type
= lookup_pointer_type (target_type
);
17119 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17120 if (attr_byte_size
)
17121 byte_size
= DW_UNSND (attr_byte_size
);
17123 byte_size
= cu_header
->addr_size
;
17125 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
17126 if (attr_address_class
)
17127 addr_class
= DW_UNSND (attr_address_class
);
17129 addr_class
= DW_ADDR_none
;
17131 ULONGEST alignment
= get_alignment (cu
, die
);
17133 /* If the pointer size, alignment, or address class is different
17134 than the default, create a type variant marked as such and set
17135 the length accordingly. */
17136 if (TYPE_LENGTH (type
) != byte_size
17137 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
17138 && alignment
!= TYPE_RAW_ALIGN (type
))
17139 || addr_class
!= DW_ADDR_none
)
17141 if (gdbarch_address_class_type_flags_p (gdbarch
))
17145 type_flags
= gdbarch_address_class_type_flags
17146 (gdbarch
, byte_size
, addr_class
);
17147 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
17149 type
= make_type_with_address_space (type
, type_flags
);
17151 else if (TYPE_LENGTH (type
) != byte_size
)
17153 complaint (_("invalid pointer size %d"), byte_size
);
17155 else if (TYPE_RAW_ALIGN (type
) != alignment
)
17157 complaint (_("Invalid DW_AT_alignment"
17158 " - DIE at %s [in module %s]"),
17159 sect_offset_str (die
->sect_off
),
17160 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17164 /* Should we also complain about unhandled address classes? */
17168 TYPE_LENGTH (type
) = byte_size
;
17169 set_type_align (type
, alignment
);
17170 return set_die_type (die
, type
, cu
);
17173 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
17174 the user defined type vector. */
17176 static struct type
*
17177 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17180 struct type
*to_type
;
17181 struct type
*domain
;
17183 to_type
= die_type (die
, cu
);
17184 domain
= die_containing_type (die
, cu
);
17186 /* The calls above may have already set the type for this DIE. */
17187 type
= get_die_type (die
, cu
);
17191 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
17192 type
= lookup_methodptr_type (to_type
);
17193 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
17195 struct type
*new_type
17196 = alloc_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
17198 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
17199 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
17200 TYPE_VARARGS (to_type
));
17201 type
= lookup_methodptr_type (new_type
);
17204 type
= lookup_memberptr_type (to_type
, domain
);
17206 return set_die_type (die
, type
, cu
);
17209 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
17210 the user defined type vector. */
17212 static struct type
*
17213 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17214 enum type_code refcode
)
17216 struct comp_unit_head
*cu_header
= &cu
->header
;
17217 struct type
*type
, *target_type
;
17218 struct attribute
*attr
;
17220 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
17222 target_type
= die_type (die
, cu
);
17224 /* The die_type call above may have already set the type for this DIE. */
17225 type
= get_die_type (die
, cu
);
17229 type
= lookup_reference_type (target_type
, refcode
);
17230 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17231 if (attr
!= nullptr)
17233 TYPE_LENGTH (type
) = DW_UNSND (attr
);
17237 TYPE_LENGTH (type
) = cu_header
->addr_size
;
17239 maybe_set_alignment (cu
, die
, type
);
17240 return set_die_type (die
, type
, cu
);
17243 /* Add the given cv-qualifiers to the element type of the array. GCC
17244 outputs DWARF type qualifiers that apply to an array, not the
17245 element type. But GDB relies on the array element type to carry
17246 the cv-qualifiers. This mimics section 6.7.3 of the C99
17249 static struct type
*
17250 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17251 struct type
*base_type
, int cnst
, int voltl
)
17253 struct type
*el_type
, *inner_array
;
17255 base_type
= copy_type (base_type
);
17256 inner_array
= base_type
;
17258 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
17260 TYPE_TARGET_TYPE (inner_array
) =
17261 copy_type (TYPE_TARGET_TYPE (inner_array
));
17262 inner_array
= TYPE_TARGET_TYPE (inner_array
);
17265 el_type
= TYPE_TARGET_TYPE (inner_array
);
17266 cnst
|= TYPE_CONST (el_type
);
17267 voltl
|= TYPE_VOLATILE (el_type
);
17268 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
17270 return set_die_type (die
, base_type
, cu
);
17273 static struct type
*
17274 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17276 struct type
*base_type
, *cv_type
;
17278 base_type
= die_type (die
, cu
);
17280 /* The die_type call above may have already set the type for this DIE. */
17281 cv_type
= get_die_type (die
, cu
);
17285 /* In case the const qualifier is applied to an array type, the element type
17286 is so qualified, not the array type (section 6.7.3 of C99). */
17287 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
17288 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
17290 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
17291 return set_die_type (die
, cv_type
, cu
);
17294 static struct type
*
17295 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17297 struct type
*base_type
, *cv_type
;
17299 base_type
= die_type (die
, cu
);
17301 /* The die_type call above may have already set the type for this DIE. */
17302 cv_type
= get_die_type (die
, cu
);
17306 /* In case the volatile qualifier is applied to an array type, the
17307 element type is so qualified, not the array type (section 6.7.3
17309 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
17310 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17312 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17313 return set_die_type (die
, cv_type
, cu
);
17316 /* Handle DW_TAG_restrict_type. */
17318 static struct type
*
17319 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17321 struct type
*base_type
, *cv_type
;
17323 base_type
= die_type (die
, cu
);
17325 /* The die_type call above may have already set the type for this DIE. */
17326 cv_type
= get_die_type (die
, cu
);
17330 cv_type
= make_restrict_type (base_type
);
17331 return set_die_type (die
, cv_type
, cu
);
17334 /* Handle DW_TAG_atomic_type. */
17336 static struct type
*
17337 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17339 struct type
*base_type
, *cv_type
;
17341 base_type
= die_type (die
, cu
);
17343 /* The die_type call above may have already set the type for this DIE. */
17344 cv_type
= get_die_type (die
, cu
);
17348 cv_type
= make_atomic_type (base_type
);
17349 return set_die_type (die
, cv_type
, cu
);
17352 /* Extract all information from a DW_TAG_string_type DIE and add to
17353 the user defined type vector. It isn't really a user defined type,
17354 but it behaves like one, with other DIE's using an AT_user_def_type
17355 attribute to reference it. */
17357 static struct type
*
17358 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17360 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17361 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17362 struct type
*type
, *range_type
, *index_type
, *char_type
;
17363 struct attribute
*attr
;
17364 struct dynamic_prop prop
;
17365 bool length_is_constant
= true;
17368 /* There are a couple of places where bit sizes might be made use of
17369 when parsing a DW_TAG_string_type, however, no producer that we know
17370 of make use of these. Handling bit sizes that are a multiple of the
17371 byte size is easy enough, but what about other bit sizes? Lets deal
17372 with that problem when we have to. Warn about these attributes being
17373 unsupported, then parse the type and ignore them like we always
17375 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
17376 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
17378 static bool warning_printed
= false;
17379 if (!warning_printed
)
17381 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
17382 "currently supported on DW_TAG_string_type."));
17383 warning_printed
= true;
17387 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17388 if (attr
!= nullptr && !attr_form_is_constant (attr
))
17390 /* The string length describes the location at which the length of
17391 the string can be found. The size of the length field can be
17392 specified with one of the attributes below. */
17393 struct type
*prop_type
;
17394 struct attribute
*len
17395 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
17396 if (len
== nullptr)
17397 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17398 if (len
!= nullptr && attr_form_is_constant (len
))
17400 /* Pass 0 as the default as we know this attribute is constant
17401 and the default value will not be returned. */
17402 LONGEST sz
= dwarf2_get_attr_constant_value (len
, 0);
17403 prop_type
= dwarf2_per_cu_int_type (cu
->per_cu
, sz
, true);
17407 /* If the size is not specified then we assume it is the size of
17408 an address on this target. */
17409 prop_type
= dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, true);
17412 /* Convert the attribute into a dynamic property. */
17413 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
17416 length_is_constant
= false;
17418 else if (attr
!= nullptr)
17420 /* This DW_AT_string_length just contains the length with no
17421 indirection. There's no need to create a dynamic property in this
17422 case. Pass 0 for the default value as we know it will not be
17423 returned in this case. */
17424 length
= dwarf2_get_attr_constant_value (attr
, 0);
17426 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
17428 /* We don't currently support non-constant byte sizes for strings. */
17429 length
= dwarf2_get_attr_constant_value (attr
, 1);
17433 /* Use 1 as a fallback length if we have nothing else. */
17437 index_type
= objfile_type (objfile
)->builtin_int
;
17438 if (length_is_constant
)
17439 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17442 struct dynamic_prop low_bound
;
17444 low_bound
.kind
= PROP_CONST
;
17445 low_bound
.data
.const_val
= 1;
17446 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
17448 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17449 type
= create_string_type (NULL
, char_type
, range_type
);
17451 return set_die_type (die
, type
, cu
);
17454 /* Assuming that DIE corresponds to a function, returns nonzero
17455 if the function is prototyped. */
17458 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17460 struct attribute
*attr
;
17462 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17463 if (attr
&& (DW_UNSND (attr
) != 0))
17466 /* The DWARF standard implies that the DW_AT_prototyped attribute
17467 is only meaningful for C, but the concept also extends to other
17468 languages that allow unprototyped functions (Eg: Objective C).
17469 For all other languages, assume that functions are always
17471 if (cu
->language
!= language_c
17472 && cu
->language
!= language_objc
17473 && cu
->language
!= language_opencl
)
17476 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17477 prototyped and unprototyped functions; default to prototyped,
17478 since that is more common in modern code (and RealView warns
17479 about unprototyped functions). */
17480 if (producer_is_realview (cu
->producer
))
17486 /* Handle DIES due to C code like:
17490 int (*funcp)(int a, long l);
17494 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17496 static struct type
*
17497 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17499 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17500 struct type
*type
; /* Type that this function returns. */
17501 struct type
*ftype
; /* Function that returns above type. */
17502 struct attribute
*attr
;
17504 type
= die_type (die
, cu
);
17506 /* The die_type call above may have already set the type for this DIE. */
17507 ftype
= get_die_type (die
, cu
);
17511 ftype
= lookup_function_type (type
);
17513 if (prototyped_function_p (die
, cu
))
17514 TYPE_PROTOTYPED (ftype
) = 1;
17516 /* Store the calling convention in the type if it's available in
17517 the subroutine die. Otherwise set the calling convention to
17518 the default value DW_CC_normal. */
17519 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17520 if (attr
!= nullptr
17521 && is_valid_DW_AT_calling_convention_for_subroutine (DW_UNSND (attr
)))
17522 TYPE_CALLING_CONVENTION (ftype
)
17523 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
17524 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17525 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17527 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17529 /* Record whether the function returns normally to its caller or not
17530 if the DWARF producer set that information. */
17531 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17532 if (attr
&& (DW_UNSND (attr
) != 0))
17533 TYPE_NO_RETURN (ftype
) = 1;
17535 /* We need to add the subroutine type to the die immediately so
17536 we don't infinitely recurse when dealing with parameters
17537 declared as the same subroutine type. */
17538 set_die_type (die
, ftype
, cu
);
17540 if (die
->child
!= NULL
)
17542 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17543 struct die_info
*child_die
;
17544 int nparams
, iparams
;
17546 /* Count the number of parameters.
17547 FIXME: GDB currently ignores vararg functions, but knows about
17548 vararg member functions. */
17550 child_die
= die
->child
;
17551 while (child_die
&& child_die
->tag
)
17553 if (child_die
->tag
== DW_TAG_formal_parameter
)
17555 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17556 TYPE_VARARGS (ftype
) = 1;
17557 child_die
= sibling_die (child_die
);
17560 /* Allocate storage for parameters and fill them in. */
17561 TYPE_NFIELDS (ftype
) = nparams
;
17562 TYPE_FIELDS (ftype
) = (struct field
*)
17563 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
17565 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17566 even if we error out during the parameters reading below. */
17567 for (iparams
= 0; iparams
< nparams
; iparams
++)
17568 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
17571 child_die
= die
->child
;
17572 while (child_die
&& child_die
->tag
)
17574 if (child_die
->tag
== DW_TAG_formal_parameter
)
17576 struct type
*arg_type
;
17578 /* DWARF version 2 has no clean way to discern C++
17579 static and non-static member functions. G++ helps
17580 GDB by marking the first parameter for non-static
17581 member functions (which is the this pointer) as
17582 artificial. We pass this information to
17583 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17585 DWARF version 3 added DW_AT_object_pointer, which GCC
17586 4.5 does not yet generate. */
17587 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17588 if (attr
!= nullptr)
17589 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
17591 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17592 arg_type
= die_type (child_die
, cu
);
17594 /* RealView does not mark THIS as const, which the testsuite
17595 expects. GCC marks THIS as const in method definitions,
17596 but not in the class specifications (GCC PR 43053). */
17597 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17598 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17601 struct dwarf2_cu
*arg_cu
= cu
;
17602 const char *name
= dwarf2_name (child_die
, cu
);
17604 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17605 if (attr
!= nullptr)
17607 /* If the compiler emits this, use it. */
17608 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17611 else if (name
&& strcmp (name
, "this") == 0)
17612 /* Function definitions will have the argument names. */
17614 else if (name
== NULL
&& iparams
== 0)
17615 /* Declarations may not have the names, so like
17616 elsewhere in GDB, assume an artificial first
17617 argument is "this". */
17621 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17625 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
17628 child_die
= sibling_die (child_die
);
17635 static struct type
*
17636 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17638 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17639 const char *name
= NULL
;
17640 struct type
*this_type
, *target_type
;
17642 name
= dwarf2_full_name (NULL
, die
, cu
);
17643 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17644 TYPE_TARGET_STUB (this_type
) = 1;
17645 set_die_type (die
, this_type
, cu
);
17646 target_type
= die_type (die
, cu
);
17647 if (target_type
!= this_type
)
17648 TYPE_TARGET_TYPE (this_type
) = target_type
;
17651 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17652 spec and cause infinite loops in GDB. */
17653 complaint (_("Self-referential DW_TAG_typedef "
17654 "- DIE at %s [in module %s]"),
17655 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17656 TYPE_TARGET_TYPE (this_type
) = NULL
;
17661 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17662 (which may be different from NAME) to the architecture back-end to allow
17663 it to guess the correct format if necessary. */
17665 static struct type
*
17666 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17667 const char *name_hint
, enum bfd_endian byte_order
)
17669 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17670 const struct floatformat
**format
;
17673 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17675 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
17677 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17682 /* Allocate an integer type of size BITS and name NAME. */
17684 static struct type
*
17685 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
17686 int bits
, int unsigned_p
, const char *name
)
17690 /* Versions of Intel's C Compiler generate an integer type called "void"
17691 instead of using DW_TAG_unspecified_type. This has been seen on
17692 at least versions 14, 17, and 18. */
17693 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
17694 && strcmp (name
, "void") == 0)
17695 type
= objfile_type (objfile
)->builtin_void
;
17697 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
17702 /* Initialise and return a floating point type of size BITS suitable for
17703 use as a component of a complex number. The NAME_HINT is passed through
17704 when initialising the floating point type and is the name of the complex
17707 As DWARF doesn't currently provide an explicit name for the components
17708 of a complex number, but it can be helpful to have these components
17709 named, we try to select a suitable name based on the size of the
17711 static struct type
*
17712 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
17713 struct objfile
*objfile
,
17714 int bits
, const char *name_hint
,
17715 enum bfd_endian byte_order
)
17717 gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17718 struct type
*tt
= nullptr;
17720 /* Try to find a suitable floating point builtin type of size BITS.
17721 We're going to use the name of this type as the name for the complex
17722 target type that we are about to create. */
17723 switch (cu
->language
)
17725 case language_fortran
:
17729 tt
= builtin_f_type (gdbarch
)->builtin_real
;
17732 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
17734 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17736 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
17744 tt
= builtin_type (gdbarch
)->builtin_float
;
17747 tt
= builtin_type (gdbarch
)->builtin_double
;
17749 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17751 tt
= builtin_type (gdbarch
)->builtin_long_double
;
17757 /* If the type we found doesn't match the size we were looking for, then
17758 pretend we didn't find a type at all, the complex target type we
17759 create will then be nameless. */
17760 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
17763 const char *name
= (tt
== nullptr) ? nullptr : TYPE_NAME (tt
);
17764 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
17767 /* Find a representation of a given base type and install
17768 it in the TYPE field of the die. */
17770 static struct type
*
17771 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17773 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17775 struct attribute
*attr
;
17776 int encoding
= 0, bits
= 0;
17780 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17781 if (attr
!= nullptr)
17782 encoding
= DW_UNSND (attr
);
17783 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17784 if (attr
!= nullptr)
17785 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
17786 name
= dwarf2_name (die
, cu
);
17788 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
17790 arch
= get_objfile_arch (objfile
);
17791 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
17793 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
17796 int endianity
= DW_UNSND (attr
);
17801 byte_order
= BFD_ENDIAN_BIG
;
17803 case DW_END_little
:
17804 byte_order
= BFD_ENDIAN_LITTLE
;
17807 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
17814 case DW_ATE_address
:
17815 /* Turn DW_ATE_address into a void * pointer. */
17816 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
17817 type
= init_pointer_type (objfile
, bits
, name
, type
);
17819 case DW_ATE_boolean
:
17820 type
= init_boolean_type (objfile
, bits
, 1, name
);
17822 case DW_ATE_complex_float
:
17823 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
17825 type
= init_complex_type (objfile
, name
, type
);
17827 case DW_ATE_decimal_float
:
17828 type
= init_decfloat_type (objfile
, bits
, name
);
17831 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
17833 case DW_ATE_signed
:
17834 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17836 case DW_ATE_unsigned
:
17837 if (cu
->language
== language_fortran
17839 && startswith (name
, "character("))
17840 type
= init_character_type (objfile
, bits
, 1, name
);
17842 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17844 case DW_ATE_signed_char
:
17845 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17846 || cu
->language
== language_pascal
17847 || cu
->language
== language_fortran
)
17848 type
= init_character_type (objfile
, bits
, 0, name
);
17850 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17852 case DW_ATE_unsigned_char
:
17853 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17854 || cu
->language
== language_pascal
17855 || cu
->language
== language_fortran
17856 || cu
->language
== language_rust
)
17857 type
= init_character_type (objfile
, bits
, 1, name
);
17859 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17864 type
= builtin_type (arch
)->builtin_char16
;
17865 else if (bits
== 32)
17866 type
= builtin_type (arch
)->builtin_char32
;
17869 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
17871 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17873 return set_die_type (die
, type
, cu
);
17878 complaint (_("unsupported DW_AT_encoding: '%s'"),
17879 dwarf_type_encoding_name (encoding
));
17880 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17884 if (name
&& strcmp (name
, "char") == 0)
17885 TYPE_NOSIGN (type
) = 1;
17887 maybe_set_alignment (cu
, die
, type
);
17889 TYPE_ENDIANITY_NOT_DEFAULT (type
) = gdbarch_byte_order (arch
) != byte_order
;
17891 return set_die_type (die
, type
, cu
);
17894 /* Parse dwarf attribute if it's a block, reference or constant and put the
17895 resulting value of the attribute into struct bound_prop.
17896 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17899 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17900 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
17901 struct type
*default_type
)
17903 struct dwarf2_property_baton
*baton
;
17904 struct obstack
*obstack
17905 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
17907 gdb_assert (default_type
!= NULL
);
17909 if (attr
== NULL
|| prop
== NULL
)
17912 if (attr_form_is_block (attr
))
17914 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17915 baton
->property_type
= default_type
;
17916 baton
->locexpr
.per_cu
= cu
->per_cu
;
17917 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17918 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17919 switch (attr
->name
)
17921 case DW_AT_string_length
:
17922 baton
->locexpr
.is_reference
= true;
17925 baton
->locexpr
.is_reference
= false;
17928 prop
->data
.baton
= baton
;
17929 prop
->kind
= PROP_LOCEXPR
;
17930 gdb_assert (prop
->data
.baton
!= NULL
);
17932 else if (attr_form_is_ref (attr
))
17934 struct dwarf2_cu
*target_cu
= cu
;
17935 struct die_info
*target_die
;
17936 struct attribute
*target_attr
;
17938 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17939 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17940 if (target_attr
== NULL
)
17941 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17943 if (target_attr
== NULL
)
17946 switch (target_attr
->name
)
17948 case DW_AT_location
:
17949 if (attr_form_is_section_offset (target_attr
))
17951 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17952 baton
->property_type
= die_type (target_die
, target_cu
);
17953 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17954 prop
->data
.baton
= baton
;
17955 prop
->kind
= PROP_LOCLIST
;
17956 gdb_assert (prop
->data
.baton
!= NULL
);
17958 else if (attr_form_is_block (target_attr
))
17960 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17961 baton
->property_type
= die_type (target_die
, target_cu
);
17962 baton
->locexpr
.per_cu
= cu
->per_cu
;
17963 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17964 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17965 baton
->locexpr
.is_reference
= true;
17966 prop
->data
.baton
= baton
;
17967 prop
->kind
= PROP_LOCEXPR
;
17968 gdb_assert (prop
->data
.baton
!= NULL
);
17972 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17973 "dynamic property");
17977 case DW_AT_data_member_location
:
17981 if (!handle_data_member_location (target_die
, target_cu
,
17985 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17986 baton
->property_type
= read_type_die (target_die
->parent
,
17988 baton
->offset_info
.offset
= offset
;
17989 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17990 prop
->data
.baton
= baton
;
17991 prop
->kind
= PROP_ADDR_OFFSET
;
17996 else if (attr_form_is_constant (attr
))
17998 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
17999 prop
->kind
= PROP_CONST
;
18003 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
18004 dwarf2_name (die
, cu
));
18011 /* Find an integer type SIZE_IN_BYTES bytes in size and return it.
18012 UNSIGNED_P controls if the integer is unsigned or not. */
18014 static struct type
*
18015 dwarf2_per_cu_int_type (struct dwarf2_per_cu_data
*per_cu
,
18016 int size_in_bytes
, bool unsigned_p
)
18018 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
18019 struct type
*int_type
;
18021 /* Helper macro to examine the various builtin types. */
18022 #define TRY_TYPE(F) \
18023 int_type = (unsigned_p \
18024 ? objfile_type (objfile)->builtin_unsigned_ ## F \
18025 : objfile_type (objfile)->builtin_ ## F); \
18026 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
18033 TRY_TYPE (long_long
);
18037 gdb_assert_not_reached ("unable to find suitable integer type");
18040 /* Find an integer type the same size as the address size given in the
18041 compilation unit header for PER_CU. UNSIGNED_P controls if the integer
18042 is unsigned or not. */
18044 static struct type
*
18045 dwarf2_per_cu_addr_sized_int_type (struct dwarf2_per_cu_data
*per_cu
,
18048 int addr_size
= dwarf2_per_cu_addr_size (per_cu
);
18049 return dwarf2_per_cu_int_type (per_cu
, addr_size
, unsigned_p
);
18052 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
18053 present (which is valid) then compute the default type based on the
18054 compilation units address size. */
18056 static struct type
*
18057 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18059 struct type
*index_type
= die_type (die
, cu
);
18061 /* Dwarf-2 specifications explicitly allows to create subrange types
18062 without specifying a base type.
18063 In that case, the base type must be set to the type of
18064 the lower bound, upper bound or count, in that order, if any of these
18065 three attributes references an object that has a type.
18066 If no base type is found, the Dwarf-2 specifications say that
18067 a signed integer type of size equal to the size of an address should
18069 For the following C code: `extern char gdb_int [];'
18070 GCC produces an empty range DIE.
18071 FIXME: muller/2010-05-28: Possible references to object for low bound,
18072 high bound or count are not yet handled by this code. */
18073 if (TYPE_CODE (index_type
) == TYPE_CODE_VOID
)
18074 index_type
= dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
18079 /* Read the given DW_AT_subrange DIE. */
18081 static struct type
*
18082 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18084 struct type
*base_type
, *orig_base_type
;
18085 struct type
*range_type
;
18086 struct attribute
*attr
;
18087 struct dynamic_prop low
, high
;
18088 int low_default_is_valid
;
18089 int high_bound_is_count
= 0;
18091 ULONGEST negative_mask
;
18093 orig_base_type
= read_subrange_index_type (die
, cu
);
18095 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
18096 whereas the real type might be. So, we use ORIG_BASE_TYPE when
18097 creating the range type, but we use the result of check_typedef
18098 when examining properties of the type. */
18099 base_type
= check_typedef (orig_base_type
);
18101 /* The die_type call above may have already set the type for this DIE. */
18102 range_type
= get_die_type (die
, cu
);
18106 low
.kind
= PROP_CONST
;
18107 high
.kind
= PROP_CONST
;
18108 high
.data
.const_val
= 0;
18110 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
18111 omitting DW_AT_lower_bound. */
18112 switch (cu
->language
)
18115 case language_cplus
:
18116 low
.data
.const_val
= 0;
18117 low_default_is_valid
= 1;
18119 case language_fortran
:
18120 low
.data
.const_val
= 1;
18121 low_default_is_valid
= 1;
18124 case language_objc
:
18125 case language_rust
:
18126 low
.data
.const_val
= 0;
18127 low_default_is_valid
= (cu
->header
.version
>= 4);
18131 case language_pascal
:
18132 low
.data
.const_val
= 1;
18133 low_default_is_valid
= (cu
->header
.version
>= 4);
18136 low
.data
.const_val
= 0;
18137 low_default_is_valid
= 0;
18141 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
18142 if (attr
!= nullptr)
18143 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
18144 else if (!low_default_is_valid
)
18145 complaint (_("Missing DW_AT_lower_bound "
18146 "- DIE at %s [in module %s]"),
18147 sect_offset_str (die
->sect_off
),
18148 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
18150 struct attribute
*attr_ub
, *attr_count
;
18151 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
18152 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18154 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
18155 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18157 /* If bounds are constant do the final calculation here. */
18158 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
18159 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
18161 high_bound_is_count
= 1;
18165 if (attr_ub
!= NULL
)
18166 complaint (_("Unresolved DW_AT_upper_bound "
18167 "- DIE at %s [in module %s]"),
18168 sect_offset_str (die
->sect_off
),
18169 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
18170 if (attr_count
!= NULL
)
18171 complaint (_("Unresolved DW_AT_count "
18172 "- DIE at %s [in module %s]"),
18173 sect_offset_str (die
->sect_off
),
18174 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
18179 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
18180 if (bias_attr
!= nullptr && attr_form_is_constant (bias_attr
))
18181 bias
= dwarf2_get_attr_constant_value (bias_attr
, 0);
18183 /* Normally, the DWARF producers are expected to use a signed
18184 constant form (Eg. DW_FORM_sdata) to express negative bounds.
18185 But this is unfortunately not always the case, as witnessed
18186 with GCC, for instance, where the ambiguous DW_FORM_dataN form
18187 is used instead. To work around that ambiguity, we treat
18188 the bounds as signed, and thus sign-extend their values, when
18189 the base type is signed. */
18191 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
18192 if (low
.kind
== PROP_CONST
18193 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
18194 low
.data
.const_val
|= negative_mask
;
18195 if (high
.kind
== PROP_CONST
18196 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
18197 high
.data
.const_val
|= negative_mask
;
18199 /* Check for bit and byte strides. */
18200 struct dynamic_prop byte_stride_prop
;
18201 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
18202 if (attr_byte_stride
!= nullptr)
18204 struct type
*prop_type
18205 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
18206 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
18210 struct dynamic_prop bit_stride_prop
;
18211 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
18212 if (attr_bit_stride
!= nullptr)
18214 /* It only makes sense to have either a bit or byte stride. */
18215 if (attr_byte_stride
!= nullptr)
18217 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
18218 "- DIE at %s [in module %s]"),
18219 sect_offset_str (die
->sect_off
),
18220 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
18221 attr_bit_stride
= nullptr;
18225 struct type
*prop_type
18226 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
18227 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
18232 if (attr_byte_stride
!= nullptr
18233 || attr_bit_stride
!= nullptr)
18235 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
18236 struct dynamic_prop
*stride
18237 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
18240 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
18241 &high
, bias
, stride
, byte_stride_p
);
18244 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
18246 if (high_bound_is_count
)
18247 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
18249 /* Ada expects an empty array on no boundary attributes. */
18250 if (attr
== NULL
&& cu
->language
!= language_ada
)
18251 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
18253 name
= dwarf2_name (die
, cu
);
18255 TYPE_NAME (range_type
) = name
;
18257 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18258 if (attr
!= nullptr)
18259 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
18261 maybe_set_alignment (cu
, die
, range_type
);
18263 set_die_type (die
, range_type
, cu
);
18265 /* set_die_type should be already done. */
18266 set_descriptive_type (range_type
, die
, cu
);
18271 static struct type
*
18272 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18276 type
= init_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
, TYPE_CODE_VOID
,0,
18278 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
18280 /* In Ada, an unspecified type is typically used when the description
18281 of the type is deferred to a different unit. When encountering
18282 such a type, we treat it as a stub, and try to resolve it later on,
18284 if (cu
->language
== language_ada
)
18285 TYPE_STUB (type
) = 1;
18287 return set_die_type (die
, type
, cu
);
18290 /* Read a single die and all its descendents. Set the die's sibling
18291 field to NULL; set other fields in the die correctly, and set all
18292 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
18293 location of the info_ptr after reading all of those dies. PARENT
18294 is the parent of the die in question. */
18296 static struct die_info
*
18297 read_die_and_children (const struct die_reader_specs
*reader
,
18298 const gdb_byte
*info_ptr
,
18299 const gdb_byte
**new_info_ptr
,
18300 struct die_info
*parent
)
18302 struct die_info
*die
;
18303 const gdb_byte
*cur_ptr
;
18306 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, &has_children
, 0);
18309 *new_info_ptr
= cur_ptr
;
18312 store_in_ref_table (die
, reader
->cu
);
18315 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
18319 *new_info_ptr
= cur_ptr
;
18322 die
->sibling
= NULL
;
18323 die
->parent
= parent
;
18327 /* Read a die, all of its descendents, and all of its siblings; set
18328 all of the fields of all of the dies correctly. Arguments are as
18329 in read_die_and_children. */
18331 static struct die_info
*
18332 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
18333 const gdb_byte
*info_ptr
,
18334 const gdb_byte
**new_info_ptr
,
18335 struct die_info
*parent
)
18337 struct die_info
*first_die
, *last_sibling
;
18338 const gdb_byte
*cur_ptr
;
18340 cur_ptr
= info_ptr
;
18341 first_die
= last_sibling
= NULL
;
18345 struct die_info
*die
18346 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
18350 *new_info_ptr
= cur_ptr
;
18357 last_sibling
->sibling
= die
;
18359 last_sibling
= die
;
18363 /* Read a die, all of its descendents, and all of its siblings; set
18364 all of the fields of all of the dies correctly. Arguments are as
18365 in read_die_and_children.
18366 This the main entry point for reading a DIE and all its children. */
18368 static struct die_info
*
18369 read_die_and_siblings (const struct die_reader_specs
*reader
,
18370 const gdb_byte
*info_ptr
,
18371 const gdb_byte
**new_info_ptr
,
18372 struct die_info
*parent
)
18374 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
18375 new_info_ptr
, parent
);
18377 if (dwarf_die_debug
)
18379 fprintf_unfiltered (gdb_stdlog
,
18380 "Read die from %s@0x%x of %s:\n",
18381 get_section_name (reader
->die_section
),
18382 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18383 bfd_get_filename (reader
->abfd
));
18384 dump_die (die
, dwarf_die_debug
);
18390 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
18392 The caller is responsible for filling in the extra attributes
18393 and updating (*DIEP)->num_attrs.
18394 Set DIEP to point to a newly allocated die with its information,
18395 except for its child, sibling, and parent fields.
18396 Set HAS_CHILDREN to tell whether the die has children or not. */
18398 static const gdb_byte
*
18399 read_full_die_1 (const struct die_reader_specs
*reader
,
18400 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18401 int *has_children
, int num_extra_attrs
)
18403 unsigned int abbrev_number
, bytes_read
, i
;
18404 struct abbrev_info
*abbrev
;
18405 struct die_info
*die
;
18406 struct dwarf2_cu
*cu
= reader
->cu
;
18407 bfd
*abfd
= reader
->abfd
;
18409 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
18410 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18411 info_ptr
+= bytes_read
;
18412 if (!abbrev_number
)
18419 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
18421 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
18423 bfd_get_filename (abfd
));
18425 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
18426 die
->sect_off
= sect_off
;
18427 die
->tag
= abbrev
->tag
;
18428 die
->abbrev
= abbrev_number
;
18430 /* Make the result usable.
18431 The caller needs to update num_attrs after adding the extra
18433 die
->num_attrs
= abbrev
->num_attrs
;
18435 std::vector
<int> indexes_that_need_reprocess
;
18436 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18438 bool need_reprocess
;
18440 read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
18441 info_ptr
, &need_reprocess
);
18442 if (need_reprocess
)
18443 indexes_that_need_reprocess
.push_back (i
);
18446 struct attribute
*attr
= dwarf2_attr_no_follow (die
, DW_AT_str_offsets_base
);
18447 if (attr
!= nullptr)
18448 cu
->str_offsets_base
= DW_UNSND (attr
);
18450 auto maybe_addr_base
= lookup_addr_base(die
);
18451 if (maybe_addr_base
.has_value ())
18452 cu
->addr_base
= *maybe_addr_base
;
18453 for (int index
: indexes_that_need_reprocess
)
18454 read_attribute_reprocess (reader
, &die
->attrs
[index
]);
18456 *has_children
= abbrev
->has_children
;
18460 /* Read a die and all its attributes.
18461 Set DIEP to point to a newly allocated die with its information,
18462 except for its child, sibling, and parent fields.
18463 Set HAS_CHILDREN to tell whether the die has children or not. */
18465 static const gdb_byte
*
18466 read_full_die (const struct die_reader_specs
*reader
,
18467 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18470 const gdb_byte
*result
;
18472 result
= read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
18474 if (dwarf_die_debug
)
18476 fprintf_unfiltered (gdb_stdlog
,
18477 "Read die from %s@0x%x of %s:\n",
18478 get_section_name (reader
->die_section
),
18479 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18480 bfd_get_filename (reader
->abfd
));
18481 dump_die (*diep
, dwarf_die_debug
);
18487 /* Abbreviation tables.
18489 In DWARF version 2, the description of the debugging information is
18490 stored in a separate .debug_abbrev section. Before we read any
18491 dies from a section we read in all abbreviations and install them
18492 in a hash table. */
18494 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
18496 struct abbrev_info
*
18497 abbrev_table::alloc_abbrev ()
18499 struct abbrev_info
*abbrev
;
18501 abbrev
= XOBNEW (&abbrev_obstack
, struct abbrev_info
);
18502 memset (abbrev
, 0, sizeof (struct abbrev_info
));
18507 /* Add an abbreviation to the table. */
18510 abbrev_table::add_abbrev (unsigned int abbrev_number
,
18511 struct abbrev_info
*abbrev
)
18513 unsigned int hash_number
;
18515 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
18516 abbrev
->next
= m_abbrevs
[hash_number
];
18517 m_abbrevs
[hash_number
] = abbrev
;
18520 /* Look up an abbrev in the table.
18521 Returns NULL if the abbrev is not found. */
18523 struct abbrev_info
*
18524 abbrev_table::lookup_abbrev (unsigned int abbrev_number
)
18526 unsigned int hash_number
;
18527 struct abbrev_info
*abbrev
;
18529 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
18530 abbrev
= m_abbrevs
[hash_number
];
18534 if (abbrev
->number
== abbrev_number
)
18536 abbrev
= abbrev
->next
;
18541 /* Read in an abbrev table. */
18543 static abbrev_table_up
18544 abbrev_table_read_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18545 struct dwarf2_section_info
*section
,
18546 sect_offset sect_off
)
18548 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18549 bfd
*abfd
= get_section_bfd_owner (section
);
18550 const gdb_byte
*abbrev_ptr
;
18551 struct abbrev_info
*cur_abbrev
;
18552 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
18553 unsigned int abbrev_form
;
18554 std::vector
<struct attr_abbrev
> cur_attrs
;
18556 abbrev_table_up
abbrev_table (new struct abbrev_table (sect_off
));
18558 dwarf2_read_section (objfile
, section
);
18559 abbrev_ptr
= section
->buffer
+ to_underlying (sect_off
);
18560 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18561 abbrev_ptr
+= bytes_read
;
18563 /* Loop until we reach an abbrev number of 0. */
18564 while (abbrev_number
)
18566 cur_attrs
.clear ();
18567 cur_abbrev
= abbrev_table
->alloc_abbrev ();
18569 /* read in abbrev header */
18570 cur_abbrev
->number
= abbrev_number
;
18572 = (enum dwarf_tag
) read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18573 abbrev_ptr
+= bytes_read
;
18574 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
18577 /* now read in declarations */
18580 LONGEST implicit_const
;
18582 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18583 abbrev_ptr
+= bytes_read
;
18584 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18585 abbrev_ptr
+= bytes_read
;
18586 if (abbrev_form
== DW_FORM_implicit_const
)
18588 implicit_const
= read_signed_leb128 (abfd
, abbrev_ptr
,
18590 abbrev_ptr
+= bytes_read
;
18594 /* Initialize it due to a false compiler warning. */
18595 implicit_const
= -1;
18598 if (abbrev_name
== 0)
18601 cur_attrs
.emplace_back ();
18602 struct attr_abbrev
&cur_attr
= cur_attrs
.back ();
18603 cur_attr
.name
= (enum dwarf_attribute
) abbrev_name
;
18604 cur_attr
.form
= (enum dwarf_form
) abbrev_form
;
18605 cur_attr
.implicit_const
= implicit_const
;
18606 ++cur_abbrev
->num_attrs
;
18609 cur_abbrev
->attrs
=
18610 XOBNEWVEC (&abbrev_table
->abbrev_obstack
, struct attr_abbrev
,
18611 cur_abbrev
->num_attrs
);
18612 memcpy (cur_abbrev
->attrs
, cur_attrs
.data (),
18613 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
18615 abbrev_table
->add_abbrev (abbrev_number
, cur_abbrev
);
18617 /* Get next abbreviation.
18618 Under Irix6 the abbreviations for a compilation unit are not
18619 always properly terminated with an abbrev number of 0.
18620 Exit loop if we encounter an abbreviation which we have
18621 already read (which means we are about to read the abbreviations
18622 for the next compile unit) or if the end of the abbreviation
18623 table is reached. */
18624 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
18626 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18627 abbrev_ptr
+= bytes_read
;
18628 if (abbrev_table
->lookup_abbrev (abbrev_number
) != NULL
)
18632 return abbrev_table
;
18635 /* Returns nonzero if TAG represents a type that we might generate a partial
18639 is_type_tag_for_partial (int tag
)
18644 /* Some types that would be reasonable to generate partial symbols for,
18645 that we don't at present. */
18646 case DW_TAG_array_type
:
18647 case DW_TAG_file_type
:
18648 case DW_TAG_ptr_to_member_type
:
18649 case DW_TAG_set_type
:
18650 case DW_TAG_string_type
:
18651 case DW_TAG_subroutine_type
:
18653 case DW_TAG_base_type
:
18654 case DW_TAG_class_type
:
18655 case DW_TAG_interface_type
:
18656 case DW_TAG_enumeration_type
:
18657 case DW_TAG_structure_type
:
18658 case DW_TAG_subrange_type
:
18659 case DW_TAG_typedef
:
18660 case DW_TAG_union_type
:
18667 /* Load all DIEs that are interesting for partial symbols into memory. */
18669 static struct partial_die_info
*
18670 load_partial_dies (const struct die_reader_specs
*reader
,
18671 const gdb_byte
*info_ptr
, int building_psymtab
)
18673 struct dwarf2_cu
*cu
= reader
->cu
;
18674 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18675 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18676 unsigned int bytes_read
;
18677 unsigned int load_all
= 0;
18678 int nesting_level
= 1;
18683 gdb_assert (cu
->per_cu
!= NULL
);
18684 if (cu
->per_cu
->load_all_dies
)
18688 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18692 &cu
->comp_unit_obstack
,
18693 hashtab_obstack_allocate
,
18694 dummy_obstack_deallocate
);
18698 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
18700 /* A NULL abbrev means the end of a series of children. */
18701 if (abbrev
== NULL
)
18703 if (--nesting_level
== 0)
18706 info_ptr
+= bytes_read
;
18707 last_die
= parent_die
;
18708 parent_die
= parent_die
->die_parent
;
18712 /* Check for template arguments. We never save these; if
18713 they're seen, we just mark the parent, and go on our way. */
18714 if (parent_die
!= NULL
18715 && cu
->language
== language_cplus
18716 && (abbrev
->tag
== DW_TAG_template_type_param
18717 || abbrev
->tag
== DW_TAG_template_value_param
))
18719 parent_die
->has_template_arguments
= 1;
18723 /* We don't need a partial DIE for the template argument. */
18724 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18729 /* We only recurse into c++ subprograms looking for template arguments.
18730 Skip their other children. */
18732 && cu
->language
== language_cplus
18733 && parent_die
!= NULL
18734 && parent_die
->tag
== DW_TAG_subprogram
)
18736 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18740 /* Check whether this DIE is interesting enough to save. Normally
18741 we would not be interested in members here, but there may be
18742 later variables referencing them via DW_AT_specification (for
18743 static members). */
18745 && !is_type_tag_for_partial (abbrev
->tag
)
18746 && abbrev
->tag
!= DW_TAG_constant
18747 && abbrev
->tag
!= DW_TAG_enumerator
18748 && abbrev
->tag
!= DW_TAG_subprogram
18749 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18750 && abbrev
->tag
!= DW_TAG_lexical_block
18751 && abbrev
->tag
!= DW_TAG_variable
18752 && abbrev
->tag
!= DW_TAG_namespace
18753 && abbrev
->tag
!= DW_TAG_module
18754 && abbrev
->tag
!= DW_TAG_member
18755 && abbrev
->tag
!= DW_TAG_imported_unit
18756 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18758 /* Otherwise we skip to the next sibling, if any. */
18759 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18763 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
18766 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
18768 /* This two-pass algorithm for processing partial symbols has a
18769 high cost in cache pressure. Thus, handle some simple cases
18770 here which cover the majority of C partial symbols. DIEs
18771 which neither have specification tags in them, nor could have
18772 specification tags elsewhere pointing at them, can simply be
18773 processed and discarded.
18775 This segment is also optional; scan_partial_symbols and
18776 add_partial_symbol will handle these DIEs if we chain
18777 them in normally. When compilers which do not emit large
18778 quantities of duplicate debug information are more common,
18779 this code can probably be removed. */
18781 /* Any complete simple types at the top level (pretty much all
18782 of them, for a language without namespaces), can be processed
18784 if (parent_die
== NULL
18785 && pdi
.has_specification
== 0
18786 && pdi
.is_declaration
== 0
18787 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
18788 || pdi
.tag
== DW_TAG_base_type
18789 || pdi
.tag
== DW_TAG_subrange_type
))
18791 if (building_psymtab
&& pdi
.name
!= NULL
)
18792 add_psymbol_to_list (pdi
.name
, false,
18793 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
18794 psymbol_placement::STATIC
,
18795 0, cu
->language
, objfile
);
18796 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18800 /* The exception for DW_TAG_typedef with has_children above is
18801 a workaround of GCC PR debug/47510. In the case of this complaint
18802 type_name_or_error will error on such types later.
18804 GDB skipped children of DW_TAG_typedef by the shortcut above and then
18805 it could not find the child DIEs referenced later, this is checked
18806 above. In correct DWARF DW_TAG_typedef should have no children. */
18808 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
18809 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
18810 "- DIE at %s [in module %s]"),
18811 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
18813 /* If we're at the second level, and we're an enumerator, and
18814 our parent has no specification (meaning possibly lives in a
18815 namespace elsewhere), then we can add the partial symbol now
18816 instead of queueing it. */
18817 if (pdi
.tag
== DW_TAG_enumerator
18818 && parent_die
!= NULL
18819 && parent_die
->die_parent
== NULL
18820 && parent_die
->tag
== DW_TAG_enumeration_type
18821 && parent_die
->has_specification
== 0)
18823 if (pdi
.name
== NULL
)
18824 complaint (_("malformed enumerator DIE ignored"));
18825 else if (building_psymtab
)
18826 add_psymbol_to_list (pdi
.name
, false,
18827 VAR_DOMAIN
, LOC_CONST
, -1,
18828 cu
->language
== language_cplus
18829 ? psymbol_placement::GLOBAL
18830 : psymbol_placement::STATIC
,
18831 0, cu
->language
, objfile
);
18833 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18837 struct partial_die_info
*part_die
18838 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
18840 /* We'll save this DIE so link it in. */
18841 part_die
->die_parent
= parent_die
;
18842 part_die
->die_sibling
= NULL
;
18843 part_die
->die_child
= NULL
;
18845 if (last_die
&& last_die
== parent_die
)
18846 last_die
->die_child
= part_die
;
18848 last_die
->die_sibling
= part_die
;
18850 last_die
= part_die
;
18852 if (first_die
== NULL
)
18853 first_die
= part_die
;
18855 /* Maybe add the DIE to the hash table. Not all DIEs that we
18856 find interesting need to be in the hash table, because we
18857 also have the parent/sibling/child chains; only those that we
18858 might refer to by offset later during partial symbol reading.
18860 For now this means things that might have be the target of a
18861 DW_AT_specification, DW_AT_abstract_origin, or
18862 DW_AT_extension. DW_AT_extension will refer only to
18863 namespaces; DW_AT_abstract_origin refers to functions (and
18864 many things under the function DIE, but we do not recurse
18865 into function DIEs during partial symbol reading) and
18866 possibly variables as well; DW_AT_specification refers to
18867 declarations. Declarations ought to have the DW_AT_declaration
18868 flag. It happens that GCC forgets to put it in sometimes, but
18869 only for functions, not for types.
18871 Adding more things than necessary to the hash table is harmless
18872 except for the performance cost. Adding too few will result in
18873 wasted time in find_partial_die, when we reread the compilation
18874 unit with load_all_dies set. */
18877 || abbrev
->tag
== DW_TAG_constant
18878 || abbrev
->tag
== DW_TAG_subprogram
18879 || abbrev
->tag
== DW_TAG_variable
18880 || abbrev
->tag
== DW_TAG_namespace
18881 || part_die
->is_declaration
)
18885 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
18886 to_underlying (part_die
->sect_off
),
18891 /* For some DIEs we want to follow their children (if any). For C
18892 we have no reason to follow the children of structures; for other
18893 languages we have to, so that we can get at method physnames
18894 to infer fully qualified class names, for DW_AT_specification,
18895 and for C++ template arguments. For C++, we also look one level
18896 inside functions to find template arguments (if the name of the
18897 function does not already contain the template arguments).
18899 For Ada and Fortran, we need to scan the children of subprograms
18900 and lexical blocks as well because these languages allow the
18901 definition of nested entities that could be interesting for the
18902 debugger, such as nested subprograms for instance. */
18903 if (last_die
->has_children
18905 || last_die
->tag
== DW_TAG_namespace
18906 || last_die
->tag
== DW_TAG_module
18907 || last_die
->tag
== DW_TAG_enumeration_type
18908 || (cu
->language
== language_cplus
18909 && last_die
->tag
== DW_TAG_subprogram
18910 && (last_die
->name
== NULL
18911 || strchr (last_die
->name
, '<') == NULL
))
18912 || (cu
->language
!= language_c
18913 && (last_die
->tag
== DW_TAG_class_type
18914 || last_die
->tag
== DW_TAG_interface_type
18915 || last_die
->tag
== DW_TAG_structure_type
18916 || last_die
->tag
== DW_TAG_union_type
))
18917 || ((cu
->language
== language_ada
18918 || cu
->language
== language_fortran
)
18919 && (last_die
->tag
== DW_TAG_subprogram
18920 || last_die
->tag
== DW_TAG_lexical_block
))))
18923 parent_die
= last_die
;
18927 /* Otherwise we skip to the next sibling, if any. */
18928 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
18930 /* Back to the top, do it again. */
18934 partial_die_info::partial_die_info (sect_offset sect_off_
,
18935 struct abbrev_info
*abbrev
)
18936 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
18940 /* Read a minimal amount of information into the minimal die structure.
18941 INFO_PTR should point just after the initial uleb128 of a DIE. */
18944 partial_die_info::read (const struct die_reader_specs
*reader
,
18945 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
18947 struct dwarf2_cu
*cu
= reader
->cu
;
18948 struct dwarf2_per_objfile
*dwarf2_per_objfile
18949 = cu
->per_cu
->dwarf2_per_objfile
;
18951 int has_low_pc_attr
= 0;
18952 int has_high_pc_attr
= 0;
18953 int high_pc_relative
= 0;
18955 std::vector
<struct attribute
> attr_vec (abbrev
.num_attrs
);
18956 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
18958 bool need_reprocess
;
18959 info_ptr
= read_attribute (reader
, &attr_vec
[i
], &abbrev
.attrs
[i
],
18960 info_ptr
, &need_reprocess
);
18961 /* String and address offsets that need to do the reprocessing have
18962 already been read at this point, so there is no need to wait until
18963 the loop terminates to do the reprocessing. */
18964 if (need_reprocess
)
18965 read_attribute_reprocess (reader
, &attr_vec
[i
]);
18966 attribute
&attr
= attr_vec
[i
];
18967 /* Store the data if it is of an attribute we want to keep in a
18968 partial symbol table. */
18974 case DW_TAG_compile_unit
:
18975 case DW_TAG_partial_unit
:
18976 case DW_TAG_type_unit
:
18977 /* Compilation units have a DW_AT_name that is a filename, not
18978 a source language identifier. */
18979 case DW_TAG_enumeration_type
:
18980 case DW_TAG_enumerator
:
18981 /* These tags always have simple identifiers already; no need
18982 to canonicalize them. */
18983 name
= DW_STRING (&attr
);
18987 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18990 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
18991 &objfile
->per_bfd
->storage_obstack
);
18996 case DW_AT_linkage_name
:
18997 case DW_AT_MIPS_linkage_name
:
18998 /* Note that both forms of linkage name might appear. We
18999 assume they will be the same, and we only store the last
19001 linkage_name
= DW_STRING (&attr
);
19004 has_low_pc_attr
= 1;
19005 lowpc
= attr_value_as_address (&attr
);
19007 case DW_AT_high_pc
:
19008 has_high_pc_attr
= 1;
19009 highpc
= attr_value_as_address (&attr
);
19010 if (cu
->header
.version
>= 4 && attr_form_is_constant (&attr
))
19011 high_pc_relative
= 1;
19013 case DW_AT_location
:
19014 /* Support the .debug_loc offsets. */
19015 if (attr_form_is_block (&attr
))
19017 d
.locdesc
= DW_BLOCK (&attr
);
19019 else if (attr_form_is_section_offset (&attr
))
19021 dwarf2_complex_location_expr_complaint ();
19025 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
19026 "partial symbol information");
19029 case DW_AT_external
:
19030 is_external
= DW_UNSND (&attr
);
19032 case DW_AT_declaration
:
19033 is_declaration
= DW_UNSND (&attr
);
19038 case DW_AT_abstract_origin
:
19039 case DW_AT_specification
:
19040 case DW_AT_extension
:
19041 has_specification
= 1;
19042 spec_offset
= dwarf2_get_ref_die_offset (&attr
);
19043 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19044 || cu
->per_cu
->is_dwz
);
19046 case DW_AT_sibling
:
19047 /* Ignore absolute siblings, they might point outside of
19048 the current compile unit. */
19049 if (attr
.form
== DW_FORM_ref_addr
)
19050 complaint (_("ignoring absolute DW_AT_sibling"));
19053 const gdb_byte
*buffer
= reader
->buffer
;
19054 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
19055 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
19057 if (sibling_ptr
< info_ptr
)
19058 complaint (_("DW_AT_sibling points backwards"));
19059 else if (sibling_ptr
> reader
->buffer_end
)
19060 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
19062 sibling
= sibling_ptr
;
19065 case DW_AT_byte_size
:
19068 case DW_AT_const_value
:
19069 has_const_value
= 1;
19071 case DW_AT_calling_convention
:
19072 /* DWARF doesn't provide a way to identify a program's source-level
19073 entry point. DW_AT_calling_convention attributes are only meant
19074 to describe functions' calling conventions.
19076 However, because it's a necessary piece of information in
19077 Fortran, and before DWARF 4 DW_CC_program was the only
19078 piece of debugging information whose definition refers to
19079 a 'main program' at all, several compilers marked Fortran
19080 main programs with DW_CC_program --- even when those
19081 functions use the standard calling conventions.
19083 Although DWARF now specifies a way to provide this
19084 information, we support this practice for backward
19086 if (DW_UNSND (&attr
) == DW_CC_program
19087 && cu
->language
== language_fortran
)
19088 main_subprogram
= 1;
19091 if (DW_UNSND (&attr
) == DW_INL_inlined
19092 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
19093 may_be_inlined
= 1;
19097 if (tag
== DW_TAG_imported_unit
)
19099 d
.sect_off
= dwarf2_get_ref_die_offset (&attr
);
19100 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19101 || cu
->per_cu
->is_dwz
);
19105 case DW_AT_main_subprogram
:
19106 main_subprogram
= DW_UNSND (&attr
);
19111 /* It would be nice to reuse dwarf2_get_pc_bounds here,
19112 but that requires a full DIE, so instead we just
19114 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
19115 unsigned int ranges_offset
= (DW_UNSND (&attr
)
19116 + (need_ranges_base
19120 /* Value of the DW_AT_ranges attribute is the offset in the
19121 .debug_ranges section. */
19122 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
19133 /* For Ada, if both the name and the linkage name appear, we prefer
19134 the latter. This lets "catch exception" work better, regardless
19135 of the order in which the name and linkage name were emitted.
19136 Really, though, this is just a workaround for the fact that gdb
19137 doesn't store both the name and the linkage name. */
19138 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
19139 name
= linkage_name
;
19141 if (high_pc_relative
)
19144 if (has_low_pc_attr
&& has_high_pc_attr
)
19146 /* When using the GNU linker, .gnu.linkonce. sections are used to
19147 eliminate duplicate copies of functions and vtables and such.
19148 The linker will arbitrarily choose one and discard the others.
19149 The AT_*_pc values for such functions refer to local labels in
19150 these sections. If the section from that file was discarded, the
19151 labels are not in the output, so the relocs get a value of 0.
19152 If this is a discarded function, mark the pc bounds as invalid,
19153 so that GDB will ignore it. */
19154 if (lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
19156 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19157 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19159 complaint (_("DW_AT_low_pc %s is zero "
19160 "for DIE at %s [in module %s]"),
19161 paddress (gdbarch
, lowpc
),
19162 sect_offset_str (sect_off
),
19163 objfile_name (objfile
));
19165 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
19166 else if (lowpc
>= highpc
)
19168 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19169 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19171 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
19172 "for DIE at %s [in module %s]"),
19173 paddress (gdbarch
, lowpc
),
19174 paddress (gdbarch
, highpc
),
19175 sect_offset_str (sect_off
),
19176 objfile_name (objfile
));
19185 /* Find a cached partial DIE at OFFSET in CU. */
19187 struct partial_die_info
*
19188 dwarf2_cu::find_partial_die (sect_offset sect_off
)
19190 struct partial_die_info
*lookup_die
= NULL
;
19191 struct partial_die_info
part_die (sect_off
);
19193 lookup_die
= ((struct partial_die_info
*)
19194 htab_find_with_hash (partial_dies
, &part_die
,
19195 to_underlying (sect_off
)));
19200 /* Find a partial DIE at OFFSET, which may or may not be in CU,
19201 except in the case of .debug_types DIEs which do not reference
19202 outside their CU (they do however referencing other types via
19203 DW_FORM_ref_sig8). */
19205 static const struct cu_partial_die_info
19206 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
19208 struct dwarf2_per_objfile
*dwarf2_per_objfile
19209 = cu
->per_cu
->dwarf2_per_objfile
;
19210 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19211 struct dwarf2_per_cu_data
*per_cu
= NULL
;
19212 struct partial_die_info
*pd
= NULL
;
19214 if (offset_in_dwz
== cu
->per_cu
->is_dwz
19215 && offset_in_cu_p (&cu
->header
, sect_off
))
19217 pd
= cu
->find_partial_die (sect_off
);
19220 /* We missed recording what we needed.
19221 Load all dies and try again. */
19222 per_cu
= cu
->per_cu
;
19226 /* TUs don't reference other CUs/TUs (except via type signatures). */
19227 if (cu
->per_cu
->is_debug_types
)
19229 error (_("Dwarf Error: Type Unit at offset %s contains"
19230 " external reference to offset %s [in module %s].\n"),
19231 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
19232 bfd_get_filename (objfile
->obfd
));
19234 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
19235 dwarf2_per_objfile
);
19237 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
19238 load_partial_comp_unit (per_cu
);
19240 per_cu
->cu
->last_used
= 0;
19241 pd
= per_cu
->cu
->find_partial_die (sect_off
);
19244 /* If we didn't find it, and not all dies have been loaded,
19245 load them all and try again. */
19247 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
19249 per_cu
->load_all_dies
= 1;
19251 /* This is nasty. When we reread the DIEs, somewhere up the call chain
19252 THIS_CU->cu may already be in use. So we can't just free it and
19253 replace its DIEs with the ones we read in. Instead, we leave those
19254 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
19255 and clobber THIS_CU->cu->partial_dies with the hash table for the new
19257 load_partial_comp_unit (per_cu
);
19259 pd
= per_cu
->cu
->find_partial_die (sect_off
);
19263 internal_error (__FILE__
, __LINE__
,
19264 _("could not find partial DIE %s "
19265 "in cache [from module %s]\n"),
19266 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
19267 return { per_cu
->cu
, pd
};
19270 /* See if we can figure out if the class lives in a namespace. We do
19271 this by looking for a member function; its demangled name will
19272 contain namespace info, if there is any. */
19275 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
19276 struct dwarf2_cu
*cu
)
19278 /* NOTE: carlton/2003-10-07: Getting the info this way changes
19279 what template types look like, because the demangler
19280 frequently doesn't give the same name as the debug info. We
19281 could fix this by only using the demangled name to get the
19282 prefix (but see comment in read_structure_type). */
19284 struct partial_die_info
*real_pdi
;
19285 struct partial_die_info
*child_pdi
;
19287 /* If this DIE (this DIE's specification, if any) has a parent, then
19288 we should not do this. We'll prepend the parent's fully qualified
19289 name when we create the partial symbol. */
19291 real_pdi
= struct_pdi
;
19292 while (real_pdi
->has_specification
)
19294 auto res
= find_partial_die (real_pdi
->spec_offset
,
19295 real_pdi
->spec_is_dwz
, cu
);
19296 real_pdi
= res
.pdi
;
19300 if (real_pdi
->die_parent
!= NULL
)
19303 for (child_pdi
= struct_pdi
->die_child
;
19305 child_pdi
= child_pdi
->die_sibling
)
19307 if (child_pdi
->tag
== DW_TAG_subprogram
19308 && child_pdi
->linkage_name
!= NULL
)
19310 gdb::unique_xmalloc_ptr
<char> actual_class_name
19311 (language_class_name_from_physname (cu
->language_defn
,
19312 child_pdi
->linkage_name
));
19313 if (actual_class_name
!= NULL
)
19315 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19317 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
19318 actual_class_name
.get ());
19326 partial_die_info::fixup (struct dwarf2_cu
*cu
)
19328 /* Once we've fixed up a die, there's no point in doing so again.
19329 This also avoids a memory leak if we were to call
19330 guess_partial_die_structure_name multiple times. */
19334 /* If we found a reference attribute and the DIE has no name, try
19335 to find a name in the referred to DIE. */
19337 if (name
== NULL
&& has_specification
)
19339 struct partial_die_info
*spec_die
;
19341 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19342 spec_die
= res
.pdi
;
19345 spec_die
->fixup (cu
);
19347 if (spec_die
->name
)
19349 name
= spec_die
->name
;
19351 /* Copy DW_AT_external attribute if it is set. */
19352 if (spec_die
->is_external
)
19353 is_external
= spec_die
->is_external
;
19357 /* Set default names for some unnamed DIEs. */
19359 if (name
== NULL
&& tag
== DW_TAG_namespace
)
19360 name
= CP_ANONYMOUS_NAMESPACE_STR
;
19362 /* If there is no parent die to provide a namespace, and there are
19363 children, see if we can determine the namespace from their linkage
19365 if (cu
->language
== language_cplus
19366 && !cu
->per_cu
->dwarf2_per_objfile
->types
.empty ()
19367 && die_parent
== NULL
19369 && (tag
== DW_TAG_class_type
19370 || tag
== DW_TAG_structure_type
19371 || tag
== DW_TAG_union_type
))
19372 guess_partial_die_structure_name (this, cu
);
19374 /* GCC might emit a nameless struct or union that has a linkage
19375 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
19377 && (tag
== DW_TAG_class_type
19378 || tag
== DW_TAG_interface_type
19379 || tag
== DW_TAG_structure_type
19380 || tag
== DW_TAG_union_type
)
19381 && linkage_name
!= NULL
)
19383 gdb::unique_xmalloc_ptr
<char> demangled
19384 (gdb_demangle (linkage_name
, DMGL_TYPES
));
19385 if (demangled
!= nullptr)
19389 /* Strip any leading namespaces/classes, keep only the base name.
19390 DW_AT_name for named DIEs does not contain the prefixes. */
19391 base
= strrchr (demangled
.get (), ':');
19392 if (base
&& base
> demangled
.get () && base
[-1] == ':')
19395 base
= demangled
.get ();
19397 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19398 name
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
, base
);
19405 /* Process the attributes that had to be skipped in the first round. These
19406 attributes are the ones that need str_offsets_base or addr_base attributes.
19407 They could not have been processed in the first round, because at the time
19408 the values of str_offsets_base or addr_base may not have been known. */
19409 void read_attribute_reprocess (const struct die_reader_specs
*reader
,
19410 struct attribute
*attr
)
19412 struct dwarf2_cu
*cu
= reader
->cu
;
19413 switch (attr
->form
)
19415 case DW_FORM_addrx
:
19416 case DW_FORM_GNU_addr_index
:
19417 DW_ADDR (attr
) = read_addr_index (cu
, DW_UNSND (attr
));
19420 case DW_FORM_strx1
:
19421 case DW_FORM_strx2
:
19422 case DW_FORM_strx3
:
19423 case DW_FORM_strx4
:
19424 case DW_FORM_GNU_str_index
:
19426 unsigned int str_index
= DW_UNSND (attr
);
19427 if (reader
->dwo_file
!= NULL
)
19429 DW_STRING (attr
) = read_dwo_str_index (reader
, str_index
);
19430 DW_STRING_IS_CANONICAL (attr
) = 0;
19434 DW_STRING (attr
) = read_stub_str_index (cu
, str_index
);
19435 DW_STRING_IS_CANONICAL (attr
) = 0;
19440 gdb_assert_not_reached (_("Unexpected DWARF form."));
19444 /* Read an attribute value described by an attribute form. */
19446 static const gdb_byte
*
19447 read_attribute_value (const struct die_reader_specs
*reader
,
19448 struct attribute
*attr
, unsigned form
,
19449 LONGEST implicit_const
, const gdb_byte
*info_ptr
,
19450 bool *need_reprocess
)
19452 struct dwarf2_cu
*cu
= reader
->cu
;
19453 struct dwarf2_per_objfile
*dwarf2_per_objfile
19454 = cu
->per_cu
->dwarf2_per_objfile
;
19455 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19456 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19457 bfd
*abfd
= reader
->abfd
;
19458 struct comp_unit_head
*cu_header
= &cu
->header
;
19459 unsigned int bytes_read
;
19460 struct dwarf_block
*blk
;
19461 *need_reprocess
= false;
19463 attr
->form
= (enum dwarf_form
) form
;
19466 case DW_FORM_ref_addr
:
19467 if (cu
->header
.version
== 2)
19468 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
19470 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
19471 &cu
->header
, &bytes_read
);
19472 info_ptr
+= bytes_read
;
19474 case DW_FORM_GNU_ref_alt
:
19475 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
19476 info_ptr
+= bytes_read
;
19479 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
19480 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
19481 info_ptr
+= bytes_read
;
19483 case DW_FORM_block2
:
19484 blk
= dwarf_alloc_block (cu
);
19485 blk
->size
= read_2_bytes (abfd
, info_ptr
);
19487 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19488 info_ptr
+= blk
->size
;
19489 DW_BLOCK (attr
) = blk
;
19491 case DW_FORM_block4
:
19492 blk
= dwarf_alloc_block (cu
);
19493 blk
->size
= read_4_bytes (abfd
, info_ptr
);
19495 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19496 info_ptr
+= blk
->size
;
19497 DW_BLOCK (attr
) = blk
;
19499 case DW_FORM_data2
:
19500 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
19503 case DW_FORM_data4
:
19504 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
19507 case DW_FORM_data8
:
19508 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
19511 case DW_FORM_data16
:
19512 blk
= dwarf_alloc_block (cu
);
19514 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
19516 DW_BLOCK (attr
) = blk
;
19518 case DW_FORM_sec_offset
:
19519 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
19520 info_ptr
+= bytes_read
;
19522 case DW_FORM_string
:
19523 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
19524 DW_STRING_IS_CANONICAL (attr
) = 0;
19525 info_ptr
+= bytes_read
;
19528 if (!cu
->per_cu
->is_dwz
)
19530 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
19531 abfd
, info_ptr
, cu_header
,
19533 DW_STRING_IS_CANONICAL (attr
) = 0;
19534 info_ptr
+= bytes_read
;
19538 case DW_FORM_line_strp
:
19539 if (!cu
->per_cu
->is_dwz
)
19541 DW_STRING (attr
) = read_indirect_line_string (dwarf2_per_objfile
,
19543 cu_header
, &bytes_read
);
19544 DW_STRING_IS_CANONICAL (attr
) = 0;
19545 info_ptr
+= bytes_read
;
19549 case DW_FORM_GNU_strp_alt
:
19551 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19552 LONGEST str_offset
= read_offset (abfd
, info_ptr
, cu_header
,
19555 DW_STRING (attr
) = read_indirect_string_from_dwz (objfile
,
19557 DW_STRING_IS_CANONICAL (attr
) = 0;
19558 info_ptr
+= bytes_read
;
19561 case DW_FORM_exprloc
:
19562 case DW_FORM_block
:
19563 blk
= dwarf_alloc_block (cu
);
19564 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19565 info_ptr
+= bytes_read
;
19566 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19567 info_ptr
+= blk
->size
;
19568 DW_BLOCK (attr
) = blk
;
19570 case DW_FORM_block1
:
19571 blk
= dwarf_alloc_block (cu
);
19572 blk
->size
= read_1_byte (abfd
, info_ptr
);
19574 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19575 info_ptr
+= blk
->size
;
19576 DW_BLOCK (attr
) = blk
;
19578 case DW_FORM_data1
:
19579 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19583 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19586 case DW_FORM_flag_present
:
19587 DW_UNSND (attr
) = 1;
19589 case DW_FORM_sdata
:
19590 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19591 info_ptr
+= bytes_read
;
19593 case DW_FORM_udata
:
19594 case DW_FORM_rnglistx
:
19595 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19596 info_ptr
+= bytes_read
;
19599 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19600 + read_1_byte (abfd
, info_ptr
));
19604 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19605 + read_2_bytes (abfd
, info_ptr
));
19609 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19610 + read_4_bytes (abfd
, info_ptr
));
19614 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19615 + read_8_bytes (abfd
, info_ptr
));
19618 case DW_FORM_ref_sig8
:
19619 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
19622 case DW_FORM_ref_udata
:
19623 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19624 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
19625 info_ptr
+= bytes_read
;
19627 case DW_FORM_indirect
:
19628 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19629 info_ptr
+= bytes_read
;
19630 if (form
== DW_FORM_implicit_const
)
19632 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19633 info_ptr
+= bytes_read
;
19635 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
19636 info_ptr
, need_reprocess
);
19638 case DW_FORM_implicit_const
:
19639 DW_SND (attr
) = implicit_const
;
19641 case DW_FORM_addrx
:
19642 case DW_FORM_GNU_addr_index
:
19643 *need_reprocess
= true;
19644 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19645 info_ptr
+= bytes_read
;
19648 case DW_FORM_strx1
:
19649 case DW_FORM_strx2
:
19650 case DW_FORM_strx3
:
19651 case DW_FORM_strx4
:
19652 case DW_FORM_GNU_str_index
:
19654 ULONGEST str_index
;
19655 if (form
== DW_FORM_strx1
)
19657 str_index
= read_1_byte (abfd
, info_ptr
);
19660 else if (form
== DW_FORM_strx2
)
19662 str_index
= read_2_bytes (abfd
, info_ptr
);
19665 else if (form
== DW_FORM_strx3
)
19667 str_index
= read_3_bytes (abfd
, info_ptr
);
19670 else if (form
== DW_FORM_strx4
)
19672 str_index
= read_4_bytes (abfd
, info_ptr
);
19677 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19678 info_ptr
+= bytes_read
;
19680 *need_reprocess
= true;
19681 DW_UNSND (attr
) = str_index
;
19685 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
19686 dwarf_form_name (form
),
19687 bfd_get_filename (abfd
));
19691 if (cu
->per_cu
->is_dwz
&& attr_form_is_ref (attr
))
19692 attr
->form
= DW_FORM_GNU_ref_alt
;
19694 /* We have seen instances where the compiler tried to emit a byte
19695 size attribute of -1 which ended up being encoded as an unsigned
19696 0xffffffff. Although 0xffffffff is technically a valid size value,
19697 an object of this size seems pretty unlikely so we can relatively
19698 safely treat these cases as if the size attribute was invalid and
19699 treat them as zero by default. */
19700 if (attr
->name
== DW_AT_byte_size
19701 && form
== DW_FORM_data4
19702 && DW_UNSND (attr
) >= 0xffffffff)
19705 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
19706 hex_string (DW_UNSND (attr
)));
19707 DW_UNSND (attr
) = 0;
19713 /* Read an attribute described by an abbreviated attribute. */
19715 static const gdb_byte
*
19716 read_attribute (const struct die_reader_specs
*reader
,
19717 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
19718 const gdb_byte
*info_ptr
, bool *need_reprocess
)
19720 attr
->name
= abbrev
->name
;
19721 return read_attribute_value (reader
, attr
, abbrev
->form
,
19722 abbrev
->implicit_const
, info_ptr
,
19726 /* Read dwarf information from a buffer. */
19728 static unsigned int
19729 read_1_byte (bfd
*abfd
, const gdb_byte
*buf
)
19731 return bfd_get_8 (abfd
, buf
);
19735 read_1_signed_byte (bfd
*abfd
, const gdb_byte
*buf
)
19737 return bfd_get_signed_8 (abfd
, buf
);
19740 static unsigned int
19741 read_2_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19743 return bfd_get_16 (abfd
, buf
);
19747 read_2_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19749 return bfd_get_signed_16 (abfd
, buf
);
19752 static unsigned int
19753 read_3_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19755 unsigned int result
= 0;
19756 for (int i
= 0; i
< 3; ++i
)
19758 unsigned char byte
= bfd_get_8 (abfd
, buf
);
19760 result
|= ((unsigned int) byte
<< (i
* 8));
19765 static unsigned int
19766 read_4_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19768 return bfd_get_32 (abfd
, buf
);
19772 read_4_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19774 return bfd_get_signed_32 (abfd
, buf
);
19778 read_8_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19780 return bfd_get_64 (abfd
, buf
);
19784 read_address (bfd
*abfd
, const gdb_byte
*buf
, struct dwarf2_cu
*cu
,
19785 unsigned int *bytes_read
)
19787 struct comp_unit_head
*cu_header
= &cu
->header
;
19788 CORE_ADDR retval
= 0;
19790 if (cu_header
->signed_addr_p
)
19792 switch (cu_header
->addr_size
)
19795 retval
= bfd_get_signed_16 (abfd
, buf
);
19798 retval
= bfd_get_signed_32 (abfd
, buf
);
19801 retval
= bfd_get_signed_64 (abfd
, buf
);
19804 internal_error (__FILE__
, __LINE__
,
19805 _("read_address: bad switch, signed [in module %s]"),
19806 bfd_get_filename (abfd
));
19811 switch (cu_header
->addr_size
)
19814 retval
= bfd_get_16 (abfd
, buf
);
19817 retval
= bfd_get_32 (abfd
, buf
);
19820 retval
= bfd_get_64 (abfd
, buf
);
19823 internal_error (__FILE__
, __LINE__
,
19824 _("read_address: bad switch, "
19825 "unsigned [in module %s]"),
19826 bfd_get_filename (abfd
));
19830 *bytes_read
= cu_header
->addr_size
;
19834 /* Read the initial length from a section. The (draft) DWARF 3
19835 specification allows the initial length to take up either 4 bytes
19836 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
19837 bytes describe the length and all offsets will be 8 bytes in length
19840 An older, non-standard 64-bit format is also handled by this
19841 function. The older format in question stores the initial length
19842 as an 8-byte quantity without an escape value. Lengths greater
19843 than 2^32 aren't very common which means that the initial 4 bytes
19844 is almost always zero. Since a length value of zero doesn't make
19845 sense for the 32-bit format, this initial zero can be considered to
19846 be an escape value which indicates the presence of the older 64-bit
19847 format. As written, the code can't detect (old format) lengths
19848 greater than 4GB. If it becomes necessary to handle lengths
19849 somewhat larger than 4GB, we could allow other small values (such
19850 as the non-sensical values of 1, 2, and 3) to also be used as
19851 escape values indicating the presence of the old format.
19853 The value returned via bytes_read should be used to increment the
19854 relevant pointer after calling read_initial_length().
19856 [ Note: read_initial_length() and read_offset() are based on the
19857 document entitled "DWARF Debugging Information Format", revision
19858 3, draft 8, dated November 19, 2001. This document was obtained
19861 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
19863 This document is only a draft and is subject to change. (So beware.)
19865 Details regarding the older, non-standard 64-bit format were
19866 determined empirically by examining 64-bit ELF files produced by
19867 the SGI toolchain on an IRIX 6.5 machine.
19869 - Kevin, July 16, 2002
19873 read_initial_length (bfd
*abfd
, const gdb_byte
*buf
, unsigned int *bytes_read
)
19875 LONGEST length
= bfd_get_32 (abfd
, buf
);
19877 if (length
== 0xffffffff)
19879 length
= bfd_get_64 (abfd
, buf
+ 4);
19882 else if (length
== 0)
19884 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
19885 length
= bfd_get_64 (abfd
, buf
);
19896 /* Cover function for read_initial_length.
19897 Returns the length of the object at BUF, and stores the size of the
19898 initial length in *BYTES_READ and stores the size that offsets will be in
19900 If the initial length size is not equivalent to that specified in
19901 CU_HEADER then issue a complaint.
19902 This is useful when reading non-comp-unit headers. */
19905 read_checked_initial_length_and_offset (bfd
*abfd
, const gdb_byte
*buf
,
19906 const struct comp_unit_head
*cu_header
,
19907 unsigned int *bytes_read
,
19908 unsigned int *offset_size
)
19910 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
19912 gdb_assert (cu_header
->initial_length_size
== 4
19913 || cu_header
->initial_length_size
== 8
19914 || cu_header
->initial_length_size
== 12);
19916 if (cu_header
->initial_length_size
!= *bytes_read
)
19917 complaint (_("intermixed 32-bit and 64-bit DWARF sections"));
19919 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
19923 /* Read an offset from the data stream. The size of the offset is
19924 given by cu_header->offset_size. */
19927 read_offset (bfd
*abfd
, const gdb_byte
*buf
,
19928 const struct comp_unit_head
*cu_header
,
19929 unsigned int *bytes_read
)
19931 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
19933 *bytes_read
= cu_header
->offset_size
;
19937 /* Read an offset from the data stream. */
19940 read_offset_1 (bfd
*abfd
, const gdb_byte
*buf
, unsigned int offset_size
)
19942 LONGEST retval
= 0;
19944 switch (offset_size
)
19947 retval
= bfd_get_32 (abfd
, buf
);
19950 retval
= bfd_get_64 (abfd
, buf
);
19953 internal_error (__FILE__
, __LINE__
,
19954 _("read_offset_1: bad switch [in module %s]"),
19955 bfd_get_filename (abfd
));
19961 static const gdb_byte
*
19962 read_n_bytes (bfd
*abfd
, const gdb_byte
*buf
, unsigned int size
)
19964 /* If the size of a host char is 8 bits, we can return a pointer
19965 to the buffer, otherwise we have to copy the data to a buffer
19966 allocated on the temporary obstack. */
19967 gdb_assert (HOST_CHAR_BIT
== 8);
19971 static const char *
19972 read_direct_string (bfd
*abfd
, const gdb_byte
*buf
,
19973 unsigned int *bytes_read_ptr
)
19975 /* If the size of a host char is 8 bits, we can return a pointer
19976 to the string, otherwise we have to copy the string to a buffer
19977 allocated on the temporary obstack. */
19978 gdb_assert (HOST_CHAR_BIT
== 8);
19981 *bytes_read_ptr
= 1;
19984 *bytes_read_ptr
= strlen ((const char *) buf
) + 1;
19985 return (const char *) buf
;
19988 /* Return pointer to string at section SECT offset STR_OFFSET with error
19989 reporting strings FORM_NAME and SECT_NAME. */
19991 static const char *
19992 read_indirect_string_at_offset_from (struct objfile
*objfile
,
19993 bfd
*abfd
, LONGEST str_offset
,
19994 struct dwarf2_section_info
*sect
,
19995 const char *form_name
,
19996 const char *sect_name
)
19998 dwarf2_read_section (objfile
, sect
);
19999 if (sect
->buffer
== NULL
)
20000 error (_("%s used without %s section [in module %s]"),
20001 form_name
, sect_name
, bfd_get_filename (abfd
));
20002 if (str_offset
>= sect
->size
)
20003 error (_("%s pointing outside of %s section [in module %s]"),
20004 form_name
, sect_name
, bfd_get_filename (abfd
));
20005 gdb_assert (HOST_CHAR_BIT
== 8);
20006 if (sect
->buffer
[str_offset
] == '\0')
20008 return (const char *) (sect
->buffer
+ str_offset
);
20011 /* Return pointer to string at .debug_str offset STR_OFFSET. */
20013 static const char *
20014 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20015 bfd
*abfd
, LONGEST str_offset
)
20017 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
20019 &dwarf2_per_objfile
->str
,
20020 "DW_FORM_strp", ".debug_str");
20023 /* Return pointer to string at .debug_line_str offset STR_OFFSET. */
20025 static const char *
20026 read_indirect_line_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20027 bfd
*abfd
, LONGEST str_offset
)
20029 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
20031 &dwarf2_per_objfile
->line_str
,
20032 "DW_FORM_line_strp",
20033 ".debug_line_str");
20036 /* Read a string at offset STR_OFFSET in the .debug_str section from
20037 the .dwz file DWZ. Throw an error if the offset is too large. If
20038 the string consists of a single NUL byte, return NULL; otherwise
20039 return a pointer to the string. */
20041 static const char *
20042 read_indirect_string_from_dwz (struct objfile
*objfile
, struct dwz_file
*dwz
,
20043 LONGEST str_offset
)
20045 dwarf2_read_section (objfile
, &dwz
->str
);
20047 if (dwz
->str
.buffer
== NULL
)
20048 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
20049 "section [in module %s]"),
20050 bfd_get_filename (dwz
->dwz_bfd
.get ()));
20051 if (str_offset
>= dwz
->str
.size
)
20052 error (_("DW_FORM_GNU_strp_alt pointing outside of "
20053 ".debug_str section [in module %s]"),
20054 bfd_get_filename (dwz
->dwz_bfd
.get ()));
20055 gdb_assert (HOST_CHAR_BIT
== 8);
20056 if (dwz
->str
.buffer
[str_offset
] == '\0')
20058 return (const char *) (dwz
->str
.buffer
+ str_offset
);
20061 /* Return pointer to string at .debug_str offset as read from BUF.
20062 BUF is assumed to be in a compilation unit described by CU_HEADER.
20063 Return *BYTES_READ_PTR count of bytes read from BUF. */
20065 static const char *
20066 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
20067 const gdb_byte
*buf
,
20068 const struct comp_unit_head
*cu_header
,
20069 unsigned int *bytes_read_ptr
)
20071 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
20073 return read_indirect_string_at_offset (dwarf2_per_objfile
, abfd
, str_offset
);
20076 /* Return pointer to string at .debug_line_str offset as read from BUF.
20077 BUF is assumed to be in a compilation unit described by CU_HEADER.
20078 Return *BYTES_READ_PTR count of bytes read from BUF. */
20080 static const char *
20081 read_indirect_line_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20082 bfd
*abfd
, const gdb_byte
*buf
,
20083 const struct comp_unit_head
*cu_header
,
20084 unsigned int *bytes_read_ptr
)
20086 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
20088 return read_indirect_line_string_at_offset (dwarf2_per_objfile
, abfd
,
20093 read_unsigned_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
20094 unsigned int *bytes_read_ptr
)
20097 unsigned int num_read
;
20099 unsigned char byte
;
20106 byte
= bfd_get_8 (abfd
, buf
);
20109 result
|= ((ULONGEST
) (byte
& 127) << shift
);
20110 if ((byte
& 128) == 0)
20116 *bytes_read_ptr
= num_read
;
20121 read_signed_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
20122 unsigned int *bytes_read_ptr
)
20125 int shift
, num_read
;
20126 unsigned char byte
;
20133 byte
= bfd_get_8 (abfd
, buf
);
20136 result
|= ((ULONGEST
) (byte
& 127) << shift
);
20138 if ((byte
& 128) == 0)
20143 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
20144 result
|= -(((ULONGEST
) 1) << shift
);
20145 *bytes_read_ptr
= num_read
;
20149 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
20150 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
20151 ADDR_SIZE is the size of addresses from the CU header. */
20154 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20155 unsigned int addr_index
, gdb::optional
<ULONGEST
> addr_base
,
20158 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20159 bfd
*abfd
= objfile
->obfd
;
20160 const gdb_byte
*info_ptr
;
20161 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
20163 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
20164 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
20165 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
20166 objfile_name (objfile
));
20167 if (addr_base_or_zero
+ addr_index
* addr_size
20168 >= dwarf2_per_objfile
->addr
.size
)
20169 error (_("DW_FORM_addr_index pointing outside of "
20170 ".debug_addr section [in module %s]"),
20171 objfile_name (objfile
));
20172 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
20173 + addr_base_or_zero
+ addr_index
* addr_size
);
20174 if (addr_size
== 4)
20175 return bfd_get_32 (abfd
, info_ptr
);
20177 return bfd_get_64 (abfd
, info_ptr
);
20180 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
20183 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
20185 return read_addr_index_1 (cu
->per_cu
->dwarf2_per_objfile
, addr_index
,
20186 cu
->addr_base
, cu
->header
.addr_size
);
20189 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
20192 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
20193 unsigned int *bytes_read
)
20195 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
20196 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
20198 return read_addr_index (cu
, addr_index
);
20201 /* Given an index in .debug_addr, fetch the value.
20202 NOTE: This can be called during dwarf expression evaluation,
20203 long after the debug information has been read, and thus per_cu->cu
20204 may no longer exist. */
20207 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
20208 unsigned int addr_index
)
20210 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
20211 struct dwarf2_cu
*cu
= per_cu
->cu
;
20212 gdb::optional
<ULONGEST
> addr_base
;
20215 /* We need addr_base and addr_size.
20216 If we don't have PER_CU->cu, we have to get it.
20217 Nasty, but the alternative is storing the needed info in PER_CU,
20218 which at this point doesn't seem justified: it's not clear how frequently
20219 it would get used and it would increase the size of every PER_CU.
20220 Entry points like dwarf2_per_cu_addr_size do a similar thing
20221 so we're not in uncharted territory here.
20222 Alas we need to be a bit more complicated as addr_base is contained
20225 We don't need to read the entire CU(/TU).
20226 We just need the header and top level die.
20228 IWBN to use the aging mechanism to let us lazily later discard the CU.
20229 For now we skip this optimization. */
20233 addr_base
= cu
->addr_base
;
20234 addr_size
= cu
->header
.addr_size
;
20238 cutu_reader
reader (per_cu
, NULL
, 0, 0, false);
20239 addr_base
= reader
.cu
->addr_base
;
20240 addr_size
= reader
.cu
->header
.addr_size
;
20243 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
20247 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
20248 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
20251 static const char *
20252 read_str_index (struct dwarf2_cu
*cu
,
20253 struct dwarf2_section_info
*str_section
,
20254 struct dwarf2_section_info
*str_offsets_section
,
20255 ULONGEST str_offsets_base
, ULONGEST str_index
)
20257 struct dwarf2_per_objfile
*dwarf2_per_objfile
20258 = cu
->per_cu
->dwarf2_per_objfile
;
20259 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20260 const char *objf_name
= objfile_name (objfile
);
20261 bfd
*abfd
= objfile
->obfd
;
20262 const gdb_byte
*info_ptr
;
20263 ULONGEST str_offset
;
20264 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
20266 dwarf2_read_section (objfile
, str_section
);
20267 dwarf2_read_section (objfile
, str_offsets_section
);
20268 if (str_section
->buffer
== NULL
)
20269 error (_("%s used without %s section"
20270 " in CU at offset %s [in module %s]"),
20271 form_name
, get_section_name (str_section
),
20272 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20273 if (str_offsets_section
->buffer
== NULL
)
20274 error (_("%s used without %s section"
20275 " in CU at offset %s [in module %s]"),
20276 form_name
, get_section_name (str_section
),
20277 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20278 info_ptr
= (str_offsets_section
->buffer
20280 + str_index
* cu
->header
.offset_size
);
20281 if (cu
->header
.offset_size
== 4)
20282 str_offset
= bfd_get_32 (abfd
, info_ptr
);
20284 str_offset
= bfd_get_64 (abfd
, info_ptr
);
20285 if (str_offset
>= str_section
->size
)
20286 error (_("Offset from %s pointing outside of"
20287 " .debug_str.dwo section in CU at offset %s [in module %s]"),
20288 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20289 return (const char *) (str_section
->buffer
+ str_offset
);
20292 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
20294 static const char *
20295 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
20297 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
20298 ? reader
->cu
->header
.addr_size
: 0;
20299 return read_str_index (reader
->cu
,
20300 &reader
->dwo_file
->sections
.str
,
20301 &reader
->dwo_file
->sections
.str_offsets
,
20302 str_offsets_base
, str_index
);
20305 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
20307 static const char *
20308 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
20310 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20311 const char *objf_name
= objfile_name (objfile
);
20312 static const char form_name
[] = "DW_FORM_GNU_str_index";
20313 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
20315 if (!cu
->str_offsets_base
.has_value ())
20316 error (_("%s used in Fission stub without %s"
20317 " in CU at offset 0x%lx [in module %s]"),
20318 form_name
, str_offsets_attr_name
,
20319 (long) cu
->header
.offset_size
, objf_name
);
20321 return read_str_index (cu
,
20322 &cu
->per_cu
->dwarf2_per_objfile
->str
,
20323 &cu
->per_cu
->dwarf2_per_objfile
->str_offsets
,
20324 *cu
->str_offsets_base
, str_index
);
20327 /* Return the length of an LEB128 number in BUF. */
20330 leb128_size (const gdb_byte
*buf
)
20332 const gdb_byte
*begin
= buf
;
20338 if ((byte
& 128) == 0)
20339 return buf
- begin
;
20344 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
20353 cu
->language
= language_c
;
20356 case DW_LANG_C_plus_plus
:
20357 case DW_LANG_C_plus_plus_11
:
20358 case DW_LANG_C_plus_plus_14
:
20359 cu
->language
= language_cplus
;
20362 cu
->language
= language_d
;
20364 case DW_LANG_Fortran77
:
20365 case DW_LANG_Fortran90
:
20366 case DW_LANG_Fortran95
:
20367 case DW_LANG_Fortran03
:
20368 case DW_LANG_Fortran08
:
20369 cu
->language
= language_fortran
;
20372 cu
->language
= language_go
;
20374 case DW_LANG_Mips_Assembler
:
20375 cu
->language
= language_asm
;
20377 case DW_LANG_Ada83
:
20378 case DW_LANG_Ada95
:
20379 cu
->language
= language_ada
;
20381 case DW_LANG_Modula2
:
20382 cu
->language
= language_m2
;
20384 case DW_LANG_Pascal83
:
20385 cu
->language
= language_pascal
;
20388 cu
->language
= language_objc
;
20391 case DW_LANG_Rust_old
:
20392 cu
->language
= language_rust
;
20394 case DW_LANG_Cobol74
:
20395 case DW_LANG_Cobol85
:
20397 cu
->language
= language_minimal
;
20400 cu
->language_defn
= language_def (cu
->language
);
20403 /* Return the named attribute or NULL if not there. */
20405 static struct attribute
*
20406 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20411 struct attribute
*spec
= NULL
;
20413 for (i
= 0; i
< die
->num_attrs
; ++i
)
20415 if (die
->attrs
[i
].name
== name
)
20416 return &die
->attrs
[i
];
20417 if (die
->attrs
[i
].name
== DW_AT_specification
20418 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
20419 spec
= &die
->attrs
[i
];
20425 die
= follow_die_ref (die
, spec
, &cu
);
20431 /* Return the named attribute or NULL if not there,
20432 but do not follow DW_AT_specification, etc.
20433 This is for use in contexts where we're reading .debug_types dies.
20434 Following DW_AT_specification, DW_AT_abstract_origin will take us
20435 back up the chain, and we want to go down. */
20437 static struct attribute
*
20438 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
20442 for (i
= 0; i
< die
->num_attrs
; ++i
)
20443 if (die
->attrs
[i
].name
== name
)
20444 return &die
->attrs
[i
];
20449 /* Return the string associated with a string-typed attribute, or NULL if it
20450 is either not found or is of an incorrect type. */
20452 static const char *
20453 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20455 struct attribute
*attr
;
20456 const char *str
= NULL
;
20458 attr
= dwarf2_attr (die
, name
, cu
);
20462 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
20463 || attr
->form
== DW_FORM_string
20464 || attr
->form
== DW_FORM_strx
20465 || attr
->form
== DW_FORM_strx1
20466 || attr
->form
== DW_FORM_strx2
20467 || attr
->form
== DW_FORM_strx3
20468 || attr
->form
== DW_FORM_strx4
20469 || attr
->form
== DW_FORM_GNU_str_index
20470 || attr
->form
== DW_FORM_GNU_strp_alt
)
20471 str
= DW_STRING (attr
);
20473 complaint (_("string type expected for attribute %s for "
20474 "DIE at %s in module %s"),
20475 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
20476 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
20482 /* Return the dwo name or NULL if not present. If present, it is in either
20483 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
20484 static const char *
20485 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
20487 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
20488 if (dwo_name
== nullptr)
20489 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
20493 /* Return non-zero iff the attribute NAME is defined for the given DIE,
20494 and holds a non-zero value. This function should only be used for
20495 DW_FORM_flag or DW_FORM_flag_present attributes. */
20498 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
20500 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
20502 return (attr
&& DW_UNSND (attr
));
20506 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
20508 /* A DIE is a declaration if it has a DW_AT_declaration attribute
20509 which value is non-zero. However, we have to be careful with
20510 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
20511 (via dwarf2_flag_true_p) follows this attribute. So we may
20512 end up accidently finding a declaration attribute that belongs
20513 to a different DIE referenced by the specification attribute,
20514 even though the given DIE does not have a declaration attribute. */
20515 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
20516 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
20519 /* Return the die giving the specification for DIE, if there is
20520 one. *SPEC_CU is the CU containing DIE on input, and the CU
20521 containing the return value on output. If there is no
20522 specification, but there is an abstract origin, that is
20525 static struct die_info
*
20526 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
20528 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
20531 if (spec_attr
== NULL
)
20532 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
20534 if (spec_attr
== NULL
)
20537 return follow_die_ref (die
, spec_attr
, spec_cu
);
20540 /* Stub for free_line_header to match void * callback types. */
20543 free_line_header_voidp (void *arg
)
20545 struct line_header
*lh
= (struct line_header
*) arg
;
20551 line_header::add_include_dir (const char *include_dir
)
20553 if (dwarf_line_debug
>= 2)
20557 new_size
= m_include_dirs
.size ();
20559 new_size
= m_include_dirs
.size () + 1;
20560 fprintf_unfiltered (gdb_stdlog
, "Adding dir %zu: %s\n",
20561 new_size
, include_dir
);
20563 m_include_dirs
.push_back (include_dir
);
20567 line_header::add_file_name (const char *name
,
20569 unsigned int mod_time
,
20570 unsigned int length
)
20572 if (dwarf_line_debug
>= 2)
20576 new_size
= file_names_size ();
20578 new_size
= file_names_size () + 1;
20579 fprintf_unfiltered (gdb_stdlog
, "Adding file %zu: %s\n",
20582 m_file_names
.emplace_back (name
, d_index
, mod_time
, length
);
20585 /* A convenience function to find the proper .debug_line section for a CU. */
20587 static struct dwarf2_section_info
*
20588 get_debug_line_section (struct dwarf2_cu
*cu
)
20590 struct dwarf2_section_info
*section
;
20591 struct dwarf2_per_objfile
*dwarf2_per_objfile
20592 = cu
->per_cu
->dwarf2_per_objfile
;
20594 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
20596 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20597 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
20598 else if (cu
->per_cu
->is_dwz
)
20600 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
20602 section
= &dwz
->line
;
20605 section
= &dwarf2_per_objfile
->line
;
20610 /* Read directory or file name entry format, starting with byte of
20611 format count entries, ULEB128 pairs of entry formats, ULEB128 of
20612 entries count and the entries themselves in the described entry
20616 read_formatted_entries (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20617 bfd
*abfd
, const gdb_byte
**bufp
,
20618 struct line_header
*lh
,
20619 const struct comp_unit_head
*cu_header
,
20620 void (*callback
) (struct line_header
*lh
,
20623 unsigned int mod_time
,
20624 unsigned int length
))
20626 gdb_byte format_count
, formati
;
20627 ULONGEST data_count
, datai
;
20628 const gdb_byte
*buf
= *bufp
;
20629 const gdb_byte
*format_header_data
;
20630 unsigned int bytes_read
;
20632 format_count
= read_1_byte (abfd
, buf
);
20634 format_header_data
= buf
;
20635 for (formati
= 0; formati
< format_count
; formati
++)
20637 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20639 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20643 data_count
= read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20645 for (datai
= 0; datai
< data_count
; datai
++)
20647 const gdb_byte
*format
= format_header_data
;
20648 struct file_entry fe
;
20650 for (formati
= 0; formati
< format_count
; formati
++)
20652 ULONGEST content_type
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20653 format
+= bytes_read
;
20655 ULONGEST form
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20656 format
+= bytes_read
;
20658 gdb::optional
<const char *> string
;
20659 gdb::optional
<unsigned int> uint
;
20663 case DW_FORM_string
:
20664 string
.emplace (read_direct_string (abfd
, buf
, &bytes_read
));
20668 case DW_FORM_line_strp
:
20669 string
.emplace (read_indirect_line_string (dwarf2_per_objfile
,
20676 case DW_FORM_data1
:
20677 uint
.emplace (read_1_byte (abfd
, buf
));
20681 case DW_FORM_data2
:
20682 uint
.emplace (read_2_bytes (abfd
, buf
));
20686 case DW_FORM_data4
:
20687 uint
.emplace (read_4_bytes (abfd
, buf
));
20691 case DW_FORM_data8
:
20692 uint
.emplace (read_8_bytes (abfd
, buf
));
20696 case DW_FORM_data16
:
20697 /* This is used for MD5, but file_entry does not record MD5s. */
20701 case DW_FORM_udata
:
20702 uint
.emplace (read_unsigned_leb128 (abfd
, buf
, &bytes_read
));
20706 case DW_FORM_block
:
20707 /* It is valid only for DW_LNCT_timestamp which is ignored by
20712 switch (content_type
)
20715 if (string
.has_value ())
20718 case DW_LNCT_directory_index
:
20719 if (uint
.has_value ())
20720 fe
.d_index
= (dir_index
) *uint
;
20722 case DW_LNCT_timestamp
:
20723 if (uint
.has_value ())
20724 fe
.mod_time
= *uint
;
20727 if (uint
.has_value ())
20733 complaint (_("Unknown format content type %s"),
20734 pulongest (content_type
));
20738 callback (lh
, fe
.name
, fe
.d_index
, fe
.mod_time
, fe
.length
);
20744 /* Read the statement program header starting at OFFSET in
20745 .debug_line, or .debug_line.dwo. Return a pointer
20746 to a struct line_header, allocated using xmalloc.
20747 Returns NULL if there is a problem reading the header, e.g., if it
20748 has a version we don't understand.
20750 NOTE: the strings in the include directory and file name tables of
20751 the returned object point into the dwarf line section buffer,
20752 and must not be freed. */
20754 static line_header_up
20755 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
20757 const gdb_byte
*line_ptr
;
20758 unsigned int bytes_read
, offset_size
;
20760 const char *cur_dir
, *cur_file
;
20761 struct dwarf2_section_info
*section
;
20763 struct dwarf2_per_objfile
*dwarf2_per_objfile
20764 = cu
->per_cu
->dwarf2_per_objfile
;
20766 section
= get_debug_line_section (cu
);
20767 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
20768 if (section
->buffer
== NULL
)
20770 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20771 complaint (_("missing .debug_line.dwo section"));
20773 complaint (_("missing .debug_line section"));
20777 /* We can't do this until we know the section is non-empty.
20778 Only then do we know we have such a section. */
20779 abfd
= get_section_bfd_owner (section
);
20781 /* Make sure that at least there's room for the total_length field.
20782 That could be 12 bytes long, but we're just going to fudge that. */
20783 if (to_underlying (sect_off
) + 4 >= section
->size
)
20785 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20789 line_header_up
lh (new line_header ());
20791 lh
->sect_off
= sect_off
;
20792 lh
->offset_in_dwz
= cu
->per_cu
->is_dwz
;
20794 line_ptr
= section
->buffer
+ to_underlying (sect_off
);
20796 /* Read in the header. */
20798 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
20799 &bytes_read
, &offset_size
);
20800 line_ptr
+= bytes_read
;
20802 const gdb_byte
*start_here
= line_ptr
;
20804 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
20806 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20809 lh
->statement_program_end
= start_here
+ lh
->total_length
;
20810 lh
->version
= read_2_bytes (abfd
, line_ptr
);
20812 if (lh
->version
> 5)
20814 /* This is a version we don't understand. The format could have
20815 changed in ways we don't handle properly so just punt. */
20816 complaint (_("unsupported version in .debug_line section"));
20819 if (lh
->version
>= 5)
20821 gdb_byte segment_selector_size
;
20823 /* Skip address size. */
20824 read_1_byte (abfd
, line_ptr
);
20827 segment_selector_size
= read_1_byte (abfd
, line_ptr
);
20829 if (segment_selector_size
!= 0)
20831 complaint (_("unsupported segment selector size %u "
20832 "in .debug_line section"),
20833 segment_selector_size
);
20837 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
20838 line_ptr
+= offset_size
;
20839 lh
->statement_program_start
= line_ptr
+ lh
->header_length
;
20840 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
20842 if (lh
->version
>= 4)
20844 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
20848 lh
->maximum_ops_per_instruction
= 1;
20850 if (lh
->maximum_ops_per_instruction
== 0)
20852 lh
->maximum_ops_per_instruction
= 1;
20853 complaint (_("invalid maximum_ops_per_instruction "
20854 "in `.debug_line' section"));
20857 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
20859 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
20861 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
20863 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
20865 lh
->standard_opcode_lengths
.reset (new unsigned char[lh
->opcode_base
]);
20867 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
20868 for (i
= 1; i
< lh
->opcode_base
; ++i
)
20870 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
20874 if (lh
->version
>= 5)
20876 /* Read directory table. */
20877 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20879 [] (struct line_header
*header
, const char *name
,
20880 dir_index d_index
, unsigned int mod_time
,
20881 unsigned int length
)
20883 header
->add_include_dir (name
);
20886 /* Read file name table. */
20887 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20889 [] (struct line_header
*header
, const char *name
,
20890 dir_index d_index
, unsigned int mod_time
,
20891 unsigned int length
)
20893 header
->add_file_name (name
, d_index
, mod_time
, length
);
20898 /* Read directory table. */
20899 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20901 line_ptr
+= bytes_read
;
20902 lh
->add_include_dir (cur_dir
);
20904 line_ptr
+= bytes_read
;
20906 /* Read file name table. */
20907 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20909 unsigned int mod_time
, length
;
20912 line_ptr
+= bytes_read
;
20913 d_index
= (dir_index
) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20914 line_ptr
+= bytes_read
;
20915 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20916 line_ptr
+= bytes_read
;
20917 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20918 line_ptr
+= bytes_read
;
20920 lh
->add_file_name (cur_file
, d_index
, mod_time
, length
);
20922 line_ptr
+= bytes_read
;
20925 if (line_ptr
> (section
->buffer
+ section
->size
))
20926 complaint (_("line number info header doesn't "
20927 "fit in `.debug_line' section"));
20932 /* Subroutine of dwarf_decode_lines to simplify it.
20933 Return the file name of the psymtab for the given file_entry.
20934 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20935 If space for the result is malloc'd, *NAME_HOLDER will be set.
20936 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
20938 static const char *
20939 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
20940 const dwarf2_psymtab
*pst
,
20941 const char *comp_dir
,
20942 gdb::unique_xmalloc_ptr
<char> *name_holder
)
20944 const char *include_name
= fe
.name
;
20945 const char *include_name_to_compare
= include_name
;
20946 const char *pst_filename
;
20949 const char *dir_name
= fe
.include_dir (lh
);
20951 gdb::unique_xmalloc_ptr
<char> hold_compare
;
20952 if (!IS_ABSOLUTE_PATH (include_name
)
20953 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
20955 /* Avoid creating a duplicate psymtab for PST.
20956 We do this by comparing INCLUDE_NAME and PST_FILENAME.
20957 Before we do the comparison, however, we need to account
20958 for DIR_NAME and COMP_DIR.
20959 First prepend dir_name (if non-NULL). If we still don't
20960 have an absolute path prepend comp_dir (if non-NULL).
20961 However, the directory we record in the include-file's
20962 psymtab does not contain COMP_DIR (to match the
20963 corresponding symtab(s)).
20968 bash$ gcc -g ./hello.c
20969 include_name = "hello.c"
20971 DW_AT_comp_dir = comp_dir = "/tmp"
20972 DW_AT_name = "./hello.c"
20976 if (dir_name
!= NULL
)
20978 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
20979 include_name
, (char *) NULL
));
20980 include_name
= name_holder
->get ();
20981 include_name_to_compare
= include_name
;
20983 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
20985 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
20986 include_name
, (char *) NULL
));
20987 include_name_to_compare
= hold_compare
.get ();
20991 pst_filename
= pst
->filename
;
20992 gdb::unique_xmalloc_ptr
<char> copied_name
;
20993 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
20995 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
20996 pst_filename
, (char *) NULL
));
20997 pst_filename
= copied_name
.get ();
21000 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
21004 return include_name
;
21007 /* State machine to track the state of the line number program. */
21009 class lnp_state_machine
21012 /* Initialize a machine state for the start of a line number
21014 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
21015 bool record_lines_p
);
21017 file_entry
*current_file ()
21019 /* lh->file_names is 0-based, but the file name numbers in the
21020 statement program are 1-based. */
21021 return m_line_header
->file_name_at (m_file
);
21024 /* Record the line in the state machine. END_SEQUENCE is true if
21025 we're processing the end of a sequence. */
21026 void record_line (bool end_sequence
);
21028 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
21029 nop-out rest of the lines in this sequence. */
21030 void check_line_address (struct dwarf2_cu
*cu
,
21031 const gdb_byte
*line_ptr
,
21032 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
21034 void handle_set_discriminator (unsigned int discriminator
)
21036 m_discriminator
= discriminator
;
21037 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
21040 /* Handle DW_LNE_set_address. */
21041 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
21044 address
+= baseaddr
;
21045 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
21048 /* Handle DW_LNS_advance_pc. */
21049 void handle_advance_pc (CORE_ADDR adjust
);
21051 /* Handle a special opcode. */
21052 void handle_special_opcode (unsigned char op_code
);
21054 /* Handle DW_LNS_advance_line. */
21055 void handle_advance_line (int line_delta
)
21057 advance_line (line_delta
);
21060 /* Handle DW_LNS_set_file. */
21061 void handle_set_file (file_name_index file
);
21063 /* Handle DW_LNS_negate_stmt. */
21064 void handle_negate_stmt ()
21066 m_is_stmt
= !m_is_stmt
;
21069 /* Handle DW_LNS_const_add_pc. */
21070 void handle_const_add_pc ();
21072 /* Handle DW_LNS_fixed_advance_pc. */
21073 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
21075 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21079 /* Handle DW_LNS_copy. */
21080 void handle_copy ()
21082 record_line (false);
21083 m_discriminator
= 0;
21086 /* Handle DW_LNE_end_sequence. */
21087 void handle_end_sequence ()
21089 m_currently_recording_lines
= true;
21093 /* Advance the line by LINE_DELTA. */
21094 void advance_line (int line_delta
)
21096 m_line
+= line_delta
;
21098 if (line_delta
!= 0)
21099 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
21102 struct dwarf2_cu
*m_cu
;
21104 gdbarch
*m_gdbarch
;
21106 /* True if we're recording lines.
21107 Otherwise we're building partial symtabs and are just interested in
21108 finding include files mentioned by the line number program. */
21109 bool m_record_lines_p
;
21111 /* The line number header. */
21112 line_header
*m_line_header
;
21114 /* These are part of the standard DWARF line number state machine,
21115 and initialized according to the DWARF spec. */
21117 unsigned char m_op_index
= 0;
21118 /* The line table index of the current file. */
21119 file_name_index m_file
= 1;
21120 unsigned int m_line
= 1;
21122 /* These are initialized in the constructor. */
21124 CORE_ADDR m_address
;
21126 unsigned int m_discriminator
;
21128 /* Additional bits of state we need to track. */
21130 /* The last file that we called dwarf2_start_subfile for.
21131 This is only used for TLLs. */
21132 unsigned int m_last_file
= 0;
21133 /* The last file a line number was recorded for. */
21134 struct subfile
*m_last_subfile
= NULL
;
21136 /* When true, record the lines we decode. */
21137 bool m_currently_recording_lines
= false;
21139 /* The last line number that was recorded, used to coalesce
21140 consecutive entries for the same line. This can happen, for
21141 example, when discriminators are present. PR 17276. */
21142 unsigned int m_last_line
= 0;
21143 bool m_line_has_non_zero_discriminator
= false;
21147 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
21149 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
21150 / m_line_header
->maximum_ops_per_instruction
)
21151 * m_line_header
->minimum_instruction_length
);
21152 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21153 m_op_index
= ((m_op_index
+ adjust
)
21154 % m_line_header
->maximum_ops_per_instruction
);
21158 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
21160 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
21161 CORE_ADDR addr_adj
= (((m_op_index
21162 + (adj_opcode
/ m_line_header
->line_range
))
21163 / m_line_header
->maximum_ops_per_instruction
)
21164 * m_line_header
->minimum_instruction_length
);
21165 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21166 m_op_index
= ((m_op_index
+ (adj_opcode
/ m_line_header
->line_range
))
21167 % m_line_header
->maximum_ops_per_instruction
);
21169 int line_delta
= (m_line_header
->line_base
21170 + (adj_opcode
% m_line_header
->line_range
));
21171 advance_line (line_delta
);
21172 record_line (false);
21173 m_discriminator
= 0;
21177 lnp_state_machine::handle_set_file (file_name_index file
)
21181 const file_entry
*fe
= current_file ();
21183 dwarf2_debug_line_missing_file_complaint ();
21184 else if (m_record_lines_p
)
21186 const char *dir
= fe
->include_dir (m_line_header
);
21188 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21189 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
21190 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
21195 lnp_state_machine::handle_const_add_pc ()
21198 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
21201 = (((m_op_index
+ adjust
)
21202 / m_line_header
->maximum_ops_per_instruction
)
21203 * m_line_header
->minimum_instruction_length
);
21205 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21206 m_op_index
= ((m_op_index
+ adjust
)
21207 % m_line_header
->maximum_ops_per_instruction
);
21210 /* Return non-zero if we should add LINE to the line number table.
21211 LINE is the line to add, LAST_LINE is the last line that was added,
21212 LAST_SUBFILE is the subfile for LAST_LINE.
21213 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
21214 had a non-zero discriminator.
21216 We have to be careful in the presence of discriminators.
21217 E.g., for this line:
21219 for (i = 0; i < 100000; i++);
21221 clang can emit four line number entries for that one line,
21222 each with a different discriminator.
21223 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
21225 However, we want gdb to coalesce all four entries into one.
21226 Otherwise the user could stepi into the middle of the line and
21227 gdb would get confused about whether the pc really was in the
21228 middle of the line.
21230 Things are further complicated by the fact that two consecutive
21231 line number entries for the same line is a heuristic used by gcc
21232 to denote the end of the prologue. So we can't just discard duplicate
21233 entries, we have to be selective about it. The heuristic we use is
21234 that we only collapse consecutive entries for the same line if at least
21235 one of those entries has a non-zero discriminator. PR 17276.
21237 Note: Addresses in the line number state machine can never go backwards
21238 within one sequence, thus this coalescing is ok. */
21241 dwarf_record_line_p (struct dwarf2_cu
*cu
,
21242 unsigned int line
, unsigned int last_line
,
21243 int line_has_non_zero_discriminator
,
21244 struct subfile
*last_subfile
)
21246 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
21248 if (line
!= last_line
)
21250 /* Same line for the same file that we've seen already.
21251 As a last check, for pr 17276, only record the line if the line
21252 has never had a non-zero discriminator. */
21253 if (!line_has_non_zero_discriminator
)
21258 /* Use the CU's builder to record line number LINE beginning at
21259 address ADDRESS in the line table of subfile SUBFILE. */
21262 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21263 unsigned int line
, CORE_ADDR address
,
21264 struct dwarf2_cu
*cu
)
21266 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
21268 if (dwarf_line_debug
)
21270 fprintf_unfiltered (gdb_stdlog
,
21271 "Recording line %u, file %s, address %s\n",
21272 line
, lbasename (subfile
->name
),
21273 paddress (gdbarch
, address
));
21277 cu
->get_builder ()->record_line (subfile
, line
, addr
);
21280 /* Subroutine of dwarf_decode_lines_1 to simplify it.
21281 Mark the end of a set of line number records.
21282 The arguments are the same as for dwarf_record_line_1.
21283 If SUBFILE is NULL the request is ignored. */
21286 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21287 CORE_ADDR address
, struct dwarf2_cu
*cu
)
21289 if (subfile
== NULL
)
21292 if (dwarf_line_debug
)
21294 fprintf_unfiltered (gdb_stdlog
,
21295 "Finishing current line, file %s, address %s\n",
21296 lbasename (subfile
->name
),
21297 paddress (gdbarch
, address
));
21300 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, cu
);
21304 lnp_state_machine::record_line (bool end_sequence
)
21306 if (dwarf_line_debug
)
21308 fprintf_unfiltered (gdb_stdlog
,
21309 "Processing actual line %u: file %u,"
21310 " address %s, is_stmt %u, discrim %u%s\n",
21312 paddress (m_gdbarch
, m_address
),
21313 m_is_stmt
, m_discriminator
,
21314 (end_sequence
? "\t(end sequence)" : ""));
21317 file_entry
*fe
= current_file ();
21320 dwarf2_debug_line_missing_file_complaint ();
21321 /* For now we ignore lines not starting on an instruction boundary.
21322 But not when processing end_sequence for compatibility with the
21323 previous version of the code. */
21324 else if (m_op_index
== 0 || end_sequence
)
21326 fe
->included_p
= 1;
21327 if (m_record_lines_p
21328 && (producer_is_codewarrior (m_cu
) || m_is_stmt
|| end_sequence
))
21330 if (m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ()
21333 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
21334 m_currently_recording_lines
? m_cu
: nullptr);
21339 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
21340 m_line_has_non_zero_discriminator
,
21343 buildsym_compunit
*builder
= m_cu
->get_builder ();
21344 dwarf_record_line_1 (m_gdbarch
,
21345 builder
->get_current_subfile (),
21347 m_currently_recording_lines
? m_cu
: nullptr);
21349 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21350 m_last_line
= m_line
;
21356 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
21357 line_header
*lh
, bool record_lines_p
)
21361 m_record_lines_p
= record_lines_p
;
21362 m_line_header
= lh
;
21364 m_currently_recording_lines
= true;
21366 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
21367 was a line entry for it so that the backend has a chance to adjust it
21368 and also record it in case it needs it. This is currently used by MIPS
21369 code, cf. `mips_adjust_dwarf2_line'. */
21370 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
21371 m_is_stmt
= lh
->default_is_stmt
;
21372 m_discriminator
= 0;
21376 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
21377 const gdb_byte
*line_ptr
,
21378 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
21380 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
21381 the pc range of the CU. However, we restrict the test to only ADDRESS
21382 values of zero to preserve GDB's previous behaviour which is to handle
21383 the specific case of a function being GC'd by the linker. */
21385 if (address
== 0 && address
< unrelocated_lowpc
)
21387 /* This line table is for a function which has been
21388 GCd by the linker. Ignore it. PR gdb/12528 */
21390 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21391 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
21393 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
21394 line_offset
, objfile_name (objfile
));
21395 m_currently_recording_lines
= false;
21396 /* Note: m_currently_recording_lines is left as false until we see
21397 DW_LNE_end_sequence. */
21401 /* Subroutine of dwarf_decode_lines to simplify it.
21402 Process the line number information in LH.
21403 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
21404 program in order to set included_p for every referenced header. */
21407 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
21408 const int decode_for_pst_p
, CORE_ADDR lowpc
)
21410 const gdb_byte
*line_ptr
, *extended_end
;
21411 const gdb_byte
*line_end
;
21412 unsigned int bytes_read
, extended_len
;
21413 unsigned char op_code
, extended_op
;
21414 CORE_ADDR baseaddr
;
21415 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21416 bfd
*abfd
= objfile
->obfd
;
21417 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21418 /* True if we're recording line info (as opposed to building partial
21419 symtabs and just interested in finding include files mentioned by
21420 the line number program). */
21421 bool record_lines_p
= !decode_for_pst_p
;
21423 baseaddr
= objfile
->text_section_offset ();
21425 line_ptr
= lh
->statement_program_start
;
21426 line_end
= lh
->statement_program_end
;
21428 /* Read the statement sequences until there's nothing left. */
21429 while (line_ptr
< line_end
)
21431 /* The DWARF line number program state machine. Reset the state
21432 machine at the start of each sequence. */
21433 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
21434 bool end_sequence
= false;
21436 if (record_lines_p
)
21438 /* Start a subfile for the current file of the state
21440 const file_entry
*fe
= state_machine
.current_file ();
21443 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
21446 /* Decode the table. */
21447 while (line_ptr
< line_end
&& !end_sequence
)
21449 op_code
= read_1_byte (abfd
, line_ptr
);
21452 if (op_code
>= lh
->opcode_base
)
21454 /* Special opcode. */
21455 state_machine
.handle_special_opcode (op_code
);
21457 else switch (op_code
)
21459 case DW_LNS_extended_op
:
21460 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
21462 line_ptr
+= bytes_read
;
21463 extended_end
= line_ptr
+ extended_len
;
21464 extended_op
= read_1_byte (abfd
, line_ptr
);
21466 switch (extended_op
)
21468 case DW_LNE_end_sequence
:
21469 state_machine
.handle_end_sequence ();
21470 end_sequence
= true;
21472 case DW_LNE_set_address
:
21475 = read_address (abfd
, line_ptr
, cu
, &bytes_read
);
21476 line_ptr
+= bytes_read
;
21478 state_machine
.check_line_address (cu
, line_ptr
,
21479 lowpc
- baseaddr
, address
);
21480 state_machine
.handle_set_address (baseaddr
, address
);
21483 case DW_LNE_define_file
:
21485 const char *cur_file
;
21486 unsigned int mod_time
, length
;
21489 cur_file
= read_direct_string (abfd
, line_ptr
,
21491 line_ptr
+= bytes_read
;
21492 dindex
= (dir_index
)
21493 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21494 line_ptr
+= bytes_read
;
21496 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21497 line_ptr
+= bytes_read
;
21499 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21500 line_ptr
+= bytes_read
;
21501 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
21504 case DW_LNE_set_discriminator
:
21506 /* The discriminator is not interesting to the
21507 debugger; just ignore it. We still need to
21508 check its value though:
21509 if there are consecutive entries for the same
21510 (non-prologue) line we want to coalesce them.
21513 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21514 line_ptr
+= bytes_read
;
21516 state_machine
.handle_set_discriminator (discr
);
21520 complaint (_("mangled .debug_line section"));
21523 /* Make sure that we parsed the extended op correctly. If e.g.
21524 we expected a different address size than the producer used,
21525 we may have read the wrong number of bytes. */
21526 if (line_ptr
!= extended_end
)
21528 complaint (_("mangled .debug_line section"));
21533 state_machine
.handle_copy ();
21535 case DW_LNS_advance_pc
:
21538 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21539 line_ptr
+= bytes_read
;
21541 state_machine
.handle_advance_pc (adjust
);
21544 case DW_LNS_advance_line
:
21547 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
21548 line_ptr
+= bytes_read
;
21550 state_machine
.handle_advance_line (line_delta
);
21553 case DW_LNS_set_file
:
21555 file_name_index file
21556 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
21558 line_ptr
+= bytes_read
;
21560 state_machine
.handle_set_file (file
);
21563 case DW_LNS_set_column
:
21564 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21565 line_ptr
+= bytes_read
;
21567 case DW_LNS_negate_stmt
:
21568 state_machine
.handle_negate_stmt ();
21570 case DW_LNS_set_basic_block
:
21572 /* Add to the address register of the state machine the
21573 address increment value corresponding to special opcode
21574 255. I.e., this value is scaled by the minimum
21575 instruction length since special opcode 255 would have
21576 scaled the increment. */
21577 case DW_LNS_const_add_pc
:
21578 state_machine
.handle_const_add_pc ();
21580 case DW_LNS_fixed_advance_pc
:
21582 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
21585 state_machine
.handle_fixed_advance_pc (addr_adj
);
21590 /* Unknown standard opcode, ignore it. */
21593 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
21595 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21596 line_ptr
+= bytes_read
;
21603 dwarf2_debug_line_missing_end_sequence_complaint ();
21605 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
21606 in which case we still finish recording the last line). */
21607 state_machine
.record_line (true);
21611 /* Decode the Line Number Program (LNP) for the given line_header
21612 structure and CU. The actual information extracted and the type
21613 of structures created from the LNP depends on the value of PST.
21615 1. If PST is NULL, then this procedure uses the data from the program
21616 to create all necessary symbol tables, and their linetables.
21618 2. If PST is not NULL, this procedure reads the program to determine
21619 the list of files included by the unit represented by PST, and
21620 builds all the associated partial symbol tables.
21622 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
21623 It is used for relative paths in the line table.
21624 NOTE: When processing partial symtabs (pst != NULL),
21625 comp_dir == pst->dirname.
21627 NOTE: It is important that psymtabs have the same file name (via strcmp)
21628 as the corresponding symtab. Since COMP_DIR is not used in the name of the
21629 symtab we don't use it in the name of the psymtabs we create.
21630 E.g. expand_line_sal requires this when finding psymtabs to expand.
21631 A good testcase for this is mb-inline.exp.
21633 LOWPC is the lowest address in CU (or 0 if not known).
21635 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
21636 for its PC<->lines mapping information. Otherwise only the filename
21637 table is read in. */
21640 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
21641 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
21642 CORE_ADDR lowpc
, int decode_mapping
)
21644 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21645 const int decode_for_pst_p
= (pst
!= NULL
);
21647 if (decode_mapping
)
21648 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
21650 if (decode_for_pst_p
)
21652 /* Now that we're done scanning the Line Header Program, we can
21653 create the psymtab of each included file. */
21654 for (auto &file_entry
: lh
->file_names ())
21655 if (file_entry
.included_p
== 1)
21657 gdb::unique_xmalloc_ptr
<char> name_holder
;
21658 const char *include_name
=
21659 psymtab_include_file_name (lh
, file_entry
, pst
,
21660 comp_dir
, &name_holder
);
21661 if (include_name
!= NULL
)
21662 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
21667 /* Make sure a symtab is created for every file, even files
21668 which contain only variables (i.e. no code with associated
21670 buildsym_compunit
*builder
= cu
->get_builder ();
21671 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
21673 for (auto &fe
: lh
->file_names ())
21675 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
21676 if (builder
->get_current_subfile ()->symtab
== NULL
)
21678 builder
->get_current_subfile ()->symtab
21679 = allocate_symtab (cust
,
21680 builder
->get_current_subfile ()->name
);
21682 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
21687 /* Start a subfile for DWARF. FILENAME is the name of the file and
21688 DIRNAME the name of the source directory which contains FILENAME
21689 or NULL if not known.
21690 This routine tries to keep line numbers from identical absolute and
21691 relative file names in a common subfile.
21693 Using the `list' example from the GDB testsuite, which resides in
21694 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
21695 of /srcdir/list0.c yields the following debugging information for list0.c:
21697 DW_AT_name: /srcdir/list0.c
21698 DW_AT_comp_dir: /compdir
21699 files.files[0].name: list0.h
21700 files.files[0].dir: /srcdir
21701 files.files[1].name: list0.c
21702 files.files[1].dir: /srcdir
21704 The line number information for list0.c has to end up in a single
21705 subfile, so that `break /srcdir/list0.c:1' works as expected.
21706 start_subfile will ensure that this happens provided that we pass the
21707 concatenation of files.files[1].dir and files.files[1].name as the
21711 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
21712 const char *dirname
)
21714 gdb::unique_xmalloc_ptr
<char> copy
;
21716 /* In order not to lose the line information directory,
21717 we concatenate it to the filename when it makes sense.
21718 Note that the Dwarf3 standard says (speaking of filenames in line
21719 information): ``The directory index is ignored for file names
21720 that represent full path names''. Thus ignoring dirname in the
21721 `else' branch below isn't an issue. */
21723 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
21725 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
21726 filename
= copy
.get ();
21729 cu
->get_builder ()->start_subfile (filename
);
21732 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
21733 buildsym_compunit constructor. */
21735 struct compunit_symtab
*
21736 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
21739 gdb_assert (m_builder
== nullptr);
21741 m_builder
.reset (new struct buildsym_compunit
21742 (per_cu
->dwarf2_per_objfile
->objfile
,
21743 name
, comp_dir
, language
, low_pc
));
21745 list_in_scope
= get_builder ()->get_file_symbols ();
21747 get_builder ()->record_debugformat ("DWARF 2");
21748 get_builder ()->record_producer (producer
);
21750 processing_has_namespace_info
= false;
21752 return get_builder ()->get_compunit_symtab ();
21756 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
21757 struct dwarf2_cu
*cu
)
21759 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21760 struct comp_unit_head
*cu_header
= &cu
->header
;
21762 /* NOTE drow/2003-01-30: There used to be a comment and some special
21763 code here to turn a symbol with DW_AT_external and a
21764 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
21765 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
21766 with some versions of binutils) where shared libraries could have
21767 relocations against symbols in their debug information - the
21768 minimal symbol would have the right address, but the debug info
21769 would not. It's no longer necessary, because we will explicitly
21770 apply relocations when we read in the debug information now. */
21772 /* A DW_AT_location attribute with no contents indicates that a
21773 variable has been optimized away. */
21774 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
21776 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21780 /* Handle one degenerate form of location expression specially, to
21781 preserve GDB's previous behavior when section offsets are
21782 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
21783 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
21785 if (attr_form_is_block (attr
)
21786 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
21787 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
21788 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
21789 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
21790 && (DW_BLOCK (attr
)->size
21791 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
21793 unsigned int dummy
;
21795 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
21796 SET_SYMBOL_VALUE_ADDRESS (sym
,
21797 read_address (objfile
->obfd
,
21798 DW_BLOCK (attr
)->data
+ 1,
21801 SET_SYMBOL_VALUE_ADDRESS
21802 (sym
, read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1,
21804 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
21805 fixup_symbol_section (sym
, objfile
);
21806 SET_SYMBOL_VALUE_ADDRESS
21808 SYMBOL_VALUE_ADDRESS (sym
)
21809 + objfile
->section_offsets
[SYMBOL_SECTION (sym
)]);
21813 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
21814 expression evaluator, and use LOC_COMPUTED only when necessary
21815 (i.e. when the value of a register or memory location is
21816 referenced, or a thread-local block, etc.). Then again, it might
21817 not be worthwhile. I'm assuming that it isn't unless performance
21818 or memory numbers show me otherwise. */
21820 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
21822 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
21823 cu
->has_loclist
= true;
21826 /* Given a pointer to a DWARF information entry, figure out if we need
21827 to make a symbol table entry for it, and if so, create a new entry
21828 and return a pointer to it.
21829 If TYPE is NULL, determine symbol type from the die, otherwise
21830 used the passed type.
21831 If SPACE is not NULL, use it to hold the new symbol. If it is
21832 NULL, allocate a new symbol on the objfile's obstack. */
21834 static struct symbol
*
21835 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
21836 struct symbol
*space
)
21838 struct dwarf2_per_objfile
*dwarf2_per_objfile
21839 = cu
->per_cu
->dwarf2_per_objfile
;
21840 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21841 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21842 struct symbol
*sym
= NULL
;
21844 struct attribute
*attr
= NULL
;
21845 struct attribute
*attr2
= NULL
;
21846 CORE_ADDR baseaddr
;
21847 struct pending
**list_to_add
= NULL
;
21849 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
21851 baseaddr
= objfile
->text_section_offset ();
21853 name
= dwarf2_name (die
, cu
);
21856 const char *linkagename
;
21857 int suppress_add
= 0;
21862 sym
= allocate_symbol (objfile
);
21863 OBJSTAT (objfile
, n_syms
++);
21865 /* Cache this symbol's name and the name's demangled form (if any). */
21866 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
21867 linkagename
= dwarf2_physname (name
, die
, cu
);
21868 sym
->compute_and_set_names (linkagename
, false, objfile
->per_bfd
);
21870 /* Fortran does not have mangling standard and the mangling does differ
21871 between gfortran, iFort etc. */
21872 if (cu
->language
== language_fortran
21873 && symbol_get_demangled_name (sym
) == NULL
)
21874 symbol_set_demangled_name (sym
,
21875 dwarf2_full_name (name
, die
, cu
),
21878 /* Default assumptions.
21879 Use the passed type or decode it from the die. */
21880 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21881 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21883 SYMBOL_TYPE (sym
) = type
;
21885 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
21886 attr
= dwarf2_attr (die
,
21887 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
21889 if (attr
!= nullptr)
21891 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
21894 attr
= dwarf2_attr (die
,
21895 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
21897 if (attr
!= nullptr)
21899 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
21900 struct file_entry
*fe
;
21902 if (cu
->line_header
!= NULL
)
21903 fe
= cu
->line_header
->file_name_at (file_index
);
21908 complaint (_("file index out of range"));
21910 symbol_set_symtab (sym
, fe
->symtab
);
21916 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
21917 if (attr
!= nullptr)
21921 addr
= attr_value_as_address (attr
);
21922 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
21923 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
21925 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
21926 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
21927 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
21928 add_symbol_to_list (sym
, cu
->list_in_scope
);
21930 case DW_TAG_subprogram
:
21931 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21933 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21934 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21935 if ((attr2
&& (DW_UNSND (attr2
) != 0))
21936 || cu
->language
== language_ada
21937 || cu
->language
== language_fortran
)
21939 /* Subprograms marked external are stored as a global symbol.
21940 Ada and Fortran subprograms, whether marked external or
21941 not, are always stored as a global symbol, because we want
21942 to be able to access them globally. For instance, we want
21943 to be able to break on a nested subprogram without having
21944 to specify the context. */
21945 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21949 list_to_add
= cu
->list_in_scope
;
21952 case DW_TAG_inlined_subroutine
:
21953 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21955 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21956 SYMBOL_INLINED (sym
) = 1;
21957 list_to_add
= cu
->list_in_scope
;
21959 case DW_TAG_template_value_param
:
21961 /* Fall through. */
21962 case DW_TAG_constant
:
21963 case DW_TAG_variable
:
21964 case DW_TAG_member
:
21965 /* Compilation with minimal debug info may result in
21966 variables with missing type entries. Change the
21967 misleading `void' type to something sensible. */
21968 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
21969 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
21971 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21972 /* In the case of DW_TAG_member, we should only be called for
21973 static const members. */
21974 if (die
->tag
== DW_TAG_member
)
21976 /* dwarf2_add_field uses die_is_declaration,
21977 so we do the same. */
21978 gdb_assert (die_is_declaration (die
, cu
));
21981 if (attr
!= nullptr)
21983 dwarf2_const_value (attr
, sym
, cu
);
21984 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21987 if (attr2
&& (DW_UNSND (attr2
) != 0))
21988 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21990 list_to_add
= cu
->list_in_scope
;
21994 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21995 if (attr
!= nullptr)
21997 var_decode_location (attr
, sym
, cu
);
21998 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
22000 /* Fortran explicitly imports any global symbols to the local
22001 scope by DW_TAG_common_block. */
22002 if (cu
->language
== language_fortran
&& die
->parent
22003 && die
->parent
->tag
== DW_TAG_common_block
)
22006 if (SYMBOL_CLASS (sym
) == LOC_STATIC
22007 && SYMBOL_VALUE_ADDRESS (sym
) == 0
22008 && !dwarf2_per_objfile
->has_section_at_zero
)
22010 /* When a static variable is eliminated by the linker,
22011 the corresponding debug information is not stripped
22012 out, but the variable address is set to null;
22013 do not add such variables into symbol table. */
22015 else if (attr2
&& (DW_UNSND (attr2
) != 0))
22017 if (SYMBOL_CLASS (sym
) == LOC_STATIC
22018 && (objfile
->flags
& OBJF_MAINLINE
) == 0
22019 && dwarf2_per_objfile
->can_copy
)
22021 /* A global static variable might be subject to
22022 copy relocation. We first check for a local
22023 minsym, though, because maybe the symbol was
22024 marked hidden, in which case this would not
22026 bound_minimal_symbol found
22027 = (lookup_minimal_symbol_linkage
22028 (sym
->linkage_name (), objfile
));
22029 if (found
.minsym
!= nullptr)
22030 sym
->maybe_copied
= 1;
22033 /* A variable with DW_AT_external is never static,
22034 but it may be block-scoped. */
22036 = ((cu
->list_in_scope
22037 == cu
->get_builder ()->get_file_symbols ())
22038 ? cu
->get_builder ()->get_global_symbols ()
22039 : cu
->list_in_scope
);
22042 list_to_add
= cu
->list_in_scope
;
22046 /* We do not know the address of this symbol.
22047 If it is an external symbol and we have type information
22048 for it, enter the symbol as a LOC_UNRESOLVED symbol.
22049 The address of the variable will then be determined from
22050 the minimal symbol table whenever the variable is
22052 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
22054 /* Fortran explicitly imports any global symbols to the local
22055 scope by DW_TAG_common_block. */
22056 if (cu
->language
== language_fortran
&& die
->parent
22057 && die
->parent
->tag
== DW_TAG_common_block
)
22059 /* SYMBOL_CLASS doesn't matter here because
22060 read_common_block is going to reset it. */
22062 list_to_add
= cu
->list_in_scope
;
22064 else if (attr2
&& (DW_UNSND (attr2
) != 0)
22065 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
22067 /* A variable with DW_AT_external is never static, but it
22068 may be block-scoped. */
22070 = ((cu
->list_in_scope
22071 == cu
->get_builder ()->get_file_symbols ())
22072 ? cu
->get_builder ()->get_global_symbols ()
22073 : cu
->list_in_scope
);
22075 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
22077 else if (!die_is_declaration (die
, cu
))
22079 /* Use the default LOC_OPTIMIZED_OUT class. */
22080 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
22082 list_to_add
= cu
->list_in_scope
;
22086 case DW_TAG_formal_parameter
:
22088 /* If we are inside a function, mark this as an argument. If
22089 not, we might be looking at an argument to an inlined function
22090 when we do not have enough information to show inlined frames;
22091 pretend it's a local variable in that case so that the user can
22093 struct context_stack
*curr
22094 = cu
->get_builder ()->get_current_context_stack ();
22095 if (curr
!= nullptr && curr
->name
!= nullptr)
22096 SYMBOL_IS_ARGUMENT (sym
) = 1;
22097 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22098 if (attr
!= nullptr)
22100 var_decode_location (attr
, sym
, cu
);
22102 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22103 if (attr
!= nullptr)
22105 dwarf2_const_value (attr
, sym
, cu
);
22108 list_to_add
= cu
->list_in_scope
;
22111 case DW_TAG_unspecified_parameters
:
22112 /* From varargs functions; gdb doesn't seem to have any
22113 interest in this information, so just ignore it for now.
22116 case DW_TAG_template_type_param
:
22118 /* Fall through. */
22119 case DW_TAG_class_type
:
22120 case DW_TAG_interface_type
:
22121 case DW_TAG_structure_type
:
22122 case DW_TAG_union_type
:
22123 case DW_TAG_set_type
:
22124 case DW_TAG_enumeration_type
:
22125 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22126 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
22129 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
22130 really ever be static objects: otherwise, if you try
22131 to, say, break of a class's method and you're in a file
22132 which doesn't mention that class, it won't work unless
22133 the check for all static symbols in lookup_symbol_aux
22134 saves you. See the OtherFileClass tests in
22135 gdb.c++/namespace.exp. */
22139 buildsym_compunit
*builder
= cu
->get_builder ();
22141 = (cu
->list_in_scope
== builder
->get_file_symbols ()
22142 && cu
->language
== language_cplus
22143 ? builder
->get_global_symbols ()
22144 : cu
->list_in_scope
);
22146 /* The semantics of C++ state that "struct foo {
22147 ... }" also defines a typedef for "foo". */
22148 if (cu
->language
== language_cplus
22149 || cu
->language
== language_ada
22150 || cu
->language
== language_d
22151 || cu
->language
== language_rust
)
22153 /* The symbol's name is already allocated along
22154 with this objfile, so we don't need to
22155 duplicate it for the type. */
22156 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
22157 TYPE_NAME (SYMBOL_TYPE (sym
)) = sym
->search_name ();
22162 case DW_TAG_typedef
:
22163 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22164 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
22165 list_to_add
= cu
->list_in_scope
;
22167 case DW_TAG_base_type
:
22168 case DW_TAG_subrange_type
:
22169 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22170 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
22171 list_to_add
= cu
->list_in_scope
;
22173 case DW_TAG_enumerator
:
22174 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22175 if (attr
!= nullptr)
22177 dwarf2_const_value (attr
, sym
, cu
);
22180 /* NOTE: carlton/2003-11-10: See comment above in the
22181 DW_TAG_class_type, etc. block. */
22184 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
22185 && cu
->language
== language_cplus
22186 ? cu
->get_builder ()->get_global_symbols ()
22187 : cu
->list_in_scope
);
22190 case DW_TAG_imported_declaration
:
22191 case DW_TAG_namespace
:
22192 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22193 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22195 case DW_TAG_module
:
22196 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22197 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
22198 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22200 case DW_TAG_common_block
:
22201 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
22202 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
22203 add_symbol_to_list (sym
, cu
->list_in_scope
);
22206 /* Not a tag we recognize. Hopefully we aren't processing
22207 trash data, but since we must specifically ignore things
22208 we don't recognize, there is nothing else we should do at
22210 complaint (_("unsupported tag: '%s'"),
22211 dwarf_tag_name (die
->tag
));
22217 sym
->hash_next
= objfile
->template_symbols
;
22218 objfile
->template_symbols
= sym
;
22219 list_to_add
= NULL
;
22222 if (list_to_add
!= NULL
)
22223 add_symbol_to_list (sym
, list_to_add
);
22225 /* For the benefit of old versions of GCC, check for anonymous
22226 namespaces based on the demangled name. */
22227 if (!cu
->processing_has_namespace_info
22228 && cu
->language
== language_cplus
)
22229 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
22234 /* Given an attr with a DW_FORM_dataN value in host byte order,
22235 zero-extend it as appropriate for the symbol's type. The DWARF
22236 standard (v4) is not entirely clear about the meaning of using
22237 DW_FORM_dataN for a constant with a signed type, where the type is
22238 wider than the data. The conclusion of a discussion on the DWARF
22239 list was that this is unspecified. We choose to always zero-extend
22240 because that is the interpretation long in use by GCC. */
22243 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
22244 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
22246 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22247 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
22248 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
22249 LONGEST l
= DW_UNSND (attr
);
22251 if (bits
< sizeof (*value
) * 8)
22253 l
&= ((LONGEST
) 1 << bits
) - 1;
22256 else if (bits
== sizeof (*value
) * 8)
22260 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
22261 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
22268 /* Read a constant value from an attribute. Either set *VALUE, or if
22269 the value does not fit in *VALUE, set *BYTES - either already
22270 allocated on the objfile obstack, or newly allocated on OBSTACK,
22271 or, set *BATON, if we translated the constant to a location
22275 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
22276 const char *name
, struct obstack
*obstack
,
22277 struct dwarf2_cu
*cu
,
22278 LONGEST
*value
, const gdb_byte
**bytes
,
22279 struct dwarf2_locexpr_baton
**baton
)
22281 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22282 struct comp_unit_head
*cu_header
= &cu
->header
;
22283 struct dwarf_block
*blk
;
22284 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
22285 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22291 switch (attr
->form
)
22294 case DW_FORM_addrx
:
22295 case DW_FORM_GNU_addr_index
:
22299 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
22300 dwarf2_const_value_length_mismatch_complaint (name
,
22301 cu_header
->addr_size
,
22302 TYPE_LENGTH (type
));
22303 /* Symbols of this form are reasonably rare, so we just
22304 piggyback on the existing location code rather than writing
22305 a new implementation of symbol_computed_ops. */
22306 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
22307 (*baton
)->per_cu
= cu
->per_cu
;
22308 gdb_assert ((*baton
)->per_cu
);
22310 (*baton
)->size
= 2 + cu_header
->addr_size
;
22311 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
22312 (*baton
)->data
= data
;
22314 data
[0] = DW_OP_addr
;
22315 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
22316 byte_order
, DW_ADDR (attr
));
22317 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
22320 case DW_FORM_string
:
22323 case DW_FORM_GNU_str_index
:
22324 case DW_FORM_GNU_strp_alt
:
22325 /* DW_STRING is already allocated on the objfile obstack, point
22327 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
22329 case DW_FORM_block1
:
22330 case DW_FORM_block2
:
22331 case DW_FORM_block4
:
22332 case DW_FORM_block
:
22333 case DW_FORM_exprloc
:
22334 case DW_FORM_data16
:
22335 blk
= DW_BLOCK (attr
);
22336 if (TYPE_LENGTH (type
) != blk
->size
)
22337 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
22338 TYPE_LENGTH (type
));
22339 *bytes
= blk
->data
;
22342 /* The DW_AT_const_value attributes are supposed to carry the
22343 symbol's value "represented as it would be on the target
22344 architecture." By the time we get here, it's already been
22345 converted to host endianness, so we just need to sign- or
22346 zero-extend it as appropriate. */
22347 case DW_FORM_data1
:
22348 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
22350 case DW_FORM_data2
:
22351 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
22353 case DW_FORM_data4
:
22354 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
22356 case DW_FORM_data8
:
22357 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
22360 case DW_FORM_sdata
:
22361 case DW_FORM_implicit_const
:
22362 *value
= DW_SND (attr
);
22365 case DW_FORM_udata
:
22366 *value
= DW_UNSND (attr
);
22370 complaint (_("unsupported const value attribute form: '%s'"),
22371 dwarf_form_name (attr
->form
));
22378 /* Copy constant value from an attribute to a symbol. */
22381 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
22382 struct dwarf2_cu
*cu
)
22384 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22386 const gdb_byte
*bytes
;
22387 struct dwarf2_locexpr_baton
*baton
;
22389 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
22390 sym
->print_name (),
22391 &objfile
->objfile_obstack
, cu
,
22392 &value
, &bytes
, &baton
);
22396 SYMBOL_LOCATION_BATON (sym
) = baton
;
22397 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
22399 else if (bytes
!= NULL
)
22401 SYMBOL_VALUE_BYTES (sym
) = bytes
;
22402 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
22406 SYMBOL_VALUE (sym
) = value
;
22407 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
22411 /* Return the type of the die in question using its DW_AT_type attribute. */
22413 static struct type
*
22414 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22416 struct attribute
*type_attr
;
22418 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
22421 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22422 /* A missing DW_AT_type represents a void type. */
22423 return objfile_type (objfile
)->builtin_void
;
22426 return lookup_die_type (die
, type_attr
, cu
);
22429 /* True iff CU's producer generates GNAT Ada auxiliary information
22430 that allows to find parallel types through that information instead
22431 of having to do expensive parallel lookups by type name. */
22434 need_gnat_info (struct dwarf2_cu
*cu
)
22436 /* Assume that the Ada compiler was GNAT, which always produces
22437 the auxiliary information. */
22438 return (cu
->language
== language_ada
);
22441 /* Return the auxiliary type of the die in question using its
22442 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
22443 attribute is not present. */
22445 static struct type
*
22446 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22448 struct attribute
*type_attr
;
22450 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
22454 return lookup_die_type (die
, type_attr
, cu
);
22457 /* If DIE has a descriptive_type attribute, then set the TYPE's
22458 descriptive type accordingly. */
22461 set_descriptive_type (struct type
*type
, struct die_info
*die
,
22462 struct dwarf2_cu
*cu
)
22464 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
22466 if (descriptive_type
)
22468 ALLOCATE_GNAT_AUX_TYPE (type
);
22469 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
22473 /* Return the containing type of the die in question using its
22474 DW_AT_containing_type attribute. */
22476 static struct type
*
22477 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22479 struct attribute
*type_attr
;
22480 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22482 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
22484 error (_("Dwarf Error: Problem turning containing type into gdb type "
22485 "[in module %s]"), objfile_name (objfile
));
22487 return lookup_die_type (die
, type_attr
, cu
);
22490 /* Return an error marker type to use for the ill formed type in DIE/CU. */
22492 static struct type
*
22493 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
22495 struct dwarf2_per_objfile
*dwarf2_per_objfile
22496 = cu
->per_cu
->dwarf2_per_objfile
;
22497 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22500 std::string message
22501 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
22502 objfile_name (objfile
),
22503 sect_offset_str (cu
->header
.sect_off
),
22504 sect_offset_str (die
->sect_off
));
22505 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
22507 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
22510 /* Look up the type of DIE in CU using its type attribute ATTR.
22511 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
22512 DW_AT_containing_type.
22513 If there is no type substitute an error marker. */
22515 static struct type
*
22516 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
22517 struct dwarf2_cu
*cu
)
22519 struct dwarf2_per_objfile
*dwarf2_per_objfile
22520 = cu
->per_cu
->dwarf2_per_objfile
;
22521 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22522 struct type
*this_type
;
22524 gdb_assert (attr
->name
== DW_AT_type
22525 || attr
->name
== DW_AT_GNAT_descriptive_type
22526 || attr
->name
== DW_AT_containing_type
);
22528 /* First see if we have it cached. */
22530 if (attr
->form
== DW_FORM_GNU_ref_alt
)
22532 struct dwarf2_per_cu_data
*per_cu
;
22533 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22535 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
22536 dwarf2_per_objfile
);
22537 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
22539 else if (attr_form_is_ref (attr
))
22541 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22543 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
22545 else if (attr
->form
== DW_FORM_ref_sig8
)
22547 ULONGEST signature
= DW_SIGNATURE (attr
);
22549 return get_signatured_type (die
, signature
, cu
);
22553 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
22554 " at %s [in module %s]"),
22555 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
22556 objfile_name (objfile
));
22557 return build_error_marker_type (cu
, die
);
22560 /* If not cached we need to read it in. */
22562 if (this_type
== NULL
)
22564 struct die_info
*type_die
= NULL
;
22565 struct dwarf2_cu
*type_cu
= cu
;
22567 if (attr_form_is_ref (attr
))
22568 type_die
= follow_die_ref (die
, attr
, &type_cu
);
22569 if (type_die
== NULL
)
22570 return build_error_marker_type (cu
, die
);
22571 /* If we find the type now, it's probably because the type came
22572 from an inter-CU reference and the type's CU got expanded before
22574 this_type
= read_type_die (type_die
, type_cu
);
22577 /* If we still don't have a type use an error marker. */
22579 if (this_type
== NULL
)
22580 return build_error_marker_type (cu
, die
);
22585 /* Return the type in DIE, CU.
22586 Returns NULL for invalid types.
22588 This first does a lookup in die_type_hash,
22589 and only reads the die in if necessary.
22591 NOTE: This can be called when reading in partial or full symbols. */
22593 static struct type
*
22594 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
22596 struct type
*this_type
;
22598 this_type
= get_die_type (die
, cu
);
22602 return read_type_die_1 (die
, cu
);
22605 /* Read the type in DIE, CU.
22606 Returns NULL for invalid types. */
22608 static struct type
*
22609 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
22611 struct type
*this_type
= NULL
;
22615 case DW_TAG_class_type
:
22616 case DW_TAG_interface_type
:
22617 case DW_TAG_structure_type
:
22618 case DW_TAG_union_type
:
22619 this_type
= read_structure_type (die
, cu
);
22621 case DW_TAG_enumeration_type
:
22622 this_type
= read_enumeration_type (die
, cu
);
22624 case DW_TAG_subprogram
:
22625 case DW_TAG_subroutine_type
:
22626 case DW_TAG_inlined_subroutine
:
22627 this_type
= read_subroutine_type (die
, cu
);
22629 case DW_TAG_array_type
:
22630 this_type
= read_array_type (die
, cu
);
22632 case DW_TAG_set_type
:
22633 this_type
= read_set_type (die
, cu
);
22635 case DW_TAG_pointer_type
:
22636 this_type
= read_tag_pointer_type (die
, cu
);
22638 case DW_TAG_ptr_to_member_type
:
22639 this_type
= read_tag_ptr_to_member_type (die
, cu
);
22641 case DW_TAG_reference_type
:
22642 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
22644 case DW_TAG_rvalue_reference_type
:
22645 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
22647 case DW_TAG_const_type
:
22648 this_type
= read_tag_const_type (die
, cu
);
22650 case DW_TAG_volatile_type
:
22651 this_type
= read_tag_volatile_type (die
, cu
);
22653 case DW_TAG_restrict_type
:
22654 this_type
= read_tag_restrict_type (die
, cu
);
22656 case DW_TAG_string_type
:
22657 this_type
= read_tag_string_type (die
, cu
);
22659 case DW_TAG_typedef
:
22660 this_type
= read_typedef (die
, cu
);
22662 case DW_TAG_subrange_type
:
22663 this_type
= read_subrange_type (die
, cu
);
22665 case DW_TAG_base_type
:
22666 this_type
= read_base_type (die
, cu
);
22668 case DW_TAG_unspecified_type
:
22669 this_type
= read_unspecified_type (die
, cu
);
22671 case DW_TAG_namespace
:
22672 this_type
= read_namespace_type (die
, cu
);
22674 case DW_TAG_module
:
22675 this_type
= read_module_type (die
, cu
);
22677 case DW_TAG_atomic_type
:
22678 this_type
= read_tag_atomic_type (die
, cu
);
22681 complaint (_("unexpected tag in read_type_die: '%s'"),
22682 dwarf_tag_name (die
->tag
));
22689 /* See if we can figure out if the class lives in a namespace. We do
22690 this by looking for a member function; its demangled name will
22691 contain namespace info, if there is any.
22692 Return the computed name or NULL.
22693 Space for the result is allocated on the objfile's obstack.
22694 This is the full-die version of guess_partial_die_structure_name.
22695 In this case we know DIE has no useful parent. */
22697 static const char *
22698 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22700 struct die_info
*spec_die
;
22701 struct dwarf2_cu
*spec_cu
;
22702 struct die_info
*child
;
22703 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22706 spec_die
= die_specification (die
, &spec_cu
);
22707 if (spec_die
!= NULL
)
22713 for (child
= die
->child
;
22715 child
= child
->sibling
)
22717 if (child
->tag
== DW_TAG_subprogram
)
22719 const char *linkage_name
= dw2_linkage_name (child
, cu
);
22721 if (linkage_name
!= NULL
)
22723 gdb::unique_xmalloc_ptr
<char> actual_name
22724 (language_class_name_from_physname (cu
->language_defn
,
22726 const char *name
= NULL
;
22728 if (actual_name
!= NULL
)
22730 const char *die_name
= dwarf2_name (die
, cu
);
22732 if (die_name
!= NULL
22733 && strcmp (die_name
, actual_name
.get ()) != 0)
22735 /* Strip off the class name from the full name.
22736 We want the prefix. */
22737 int die_name_len
= strlen (die_name
);
22738 int actual_name_len
= strlen (actual_name
.get ());
22739 const char *ptr
= actual_name
.get ();
22741 /* Test for '::' as a sanity check. */
22742 if (actual_name_len
> die_name_len
+ 2
22743 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
22744 name
= obstack_strndup (
22745 &objfile
->per_bfd
->storage_obstack
,
22746 ptr
, actual_name_len
- die_name_len
- 2);
22757 /* GCC might emit a nameless typedef that has a linkage name. Determine the
22758 prefix part in such case. See
22759 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22761 static const char *
22762 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22764 struct attribute
*attr
;
22767 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
22768 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
22771 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
22774 attr
= dw2_linkage_name_attr (die
, cu
);
22775 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22778 /* dwarf2_name had to be already called. */
22779 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
22781 /* Strip the base name, keep any leading namespaces/classes. */
22782 base
= strrchr (DW_STRING (attr
), ':');
22783 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
22786 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22787 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
22789 &base
[-1] - DW_STRING (attr
));
22792 /* Return the name of the namespace/class that DIE is defined within,
22793 or "" if we can't tell. The caller should not xfree the result.
22795 For example, if we're within the method foo() in the following
22805 then determine_prefix on foo's die will return "N::C". */
22807 static const char *
22808 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22810 struct dwarf2_per_objfile
*dwarf2_per_objfile
22811 = cu
->per_cu
->dwarf2_per_objfile
;
22812 struct die_info
*parent
, *spec_die
;
22813 struct dwarf2_cu
*spec_cu
;
22814 struct type
*parent_type
;
22815 const char *retval
;
22817 if (cu
->language
!= language_cplus
22818 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
22819 && cu
->language
!= language_rust
)
22822 retval
= anonymous_struct_prefix (die
, cu
);
22826 /* We have to be careful in the presence of DW_AT_specification.
22827 For example, with GCC 3.4, given the code
22831 // Definition of N::foo.
22835 then we'll have a tree of DIEs like this:
22837 1: DW_TAG_compile_unit
22838 2: DW_TAG_namespace // N
22839 3: DW_TAG_subprogram // declaration of N::foo
22840 4: DW_TAG_subprogram // definition of N::foo
22841 DW_AT_specification // refers to die #3
22843 Thus, when processing die #4, we have to pretend that we're in
22844 the context of its DW_AT_specification, namely the contex of die
22847 spec_die
= die_specification (die
, &spec_cu
);
22848 if (spec_die
== NULL
)
22849 parent
= die
->parent
;
22852 parent
= spec_die
->parent
;
22856 if (parent
== NULL
)
22858 else if (parent
->building_fullname
)
22861 const char *parent_name
;
22863 /* It has been seen on RealView 2.2 built binaries,
22864 DW_TAG_template_type_param types actually _defined_ as
22865 children of the parent class:
22868 template class <class Enum> Class{};
22869 Class<enum E> class_e;
22871 1: DW_TAG_class_type (Class)
22872 2: DW_TAG_enumeration_type (E)
22873 3: DW_TAG_enumerator (enum1:0)
22874 3: DW_TAG_enumerator (enum2:1)
22876 2: DW_TAG_template_type_param
22877 DW_AT_type DW_FORM_ref_udata (E)
22879 Besides being broken debug info, it can put GDB into an
22880 infinite loop. Consider:
22882 When we're building the full name for Class<E>, we'll start
22883 at Class, and go look over its template type parameters,
22884 finding E. We'll then try to build the full name of E, and
22885 reach here. We're now trying to build the full name of E,
22886 and look over the parent DIE for containing scope. In the
22887 broken case, if we followed the parent DIE of E, we'd again
22888 find Class, and once again go look at its template type
22889 arguments, etc., etc. Simply don't consider such parent die
22890 as source-level parent of this die (it can't be, the language
22891 doesn't allow it), and break the loop here. */
22892 name
= dwarf2_name (die
, cu
);
22893 parent_name
= dwarf2_name (parent
, cu
);
22894 complaint (_("template param type '%s' defined within parent '%s'"),
22895 name
? name
: "<unknown>",
22896 parent_name
? parent_name
: "<unknown>");
22900 switch (parent
->tag
)
22902 case DW_TAG_namespace
:
22903 parent_type
= read_type_die (parent
, cu
);
22904 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
22905 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
22906 Work around this problem here. */
22907 if (cu
->language
== language_cplus
22908 && strcmp (TYPE_NAME (parent_type
), "::") == 0)
22910 /* We give a name to even anonymous namespaces. */
22911 return TYPE_NAME (parent_type
);
22912 case DW_TAG_class_type
:
22913 case DW_TAG_interface_type
:
22914 case DW_TAG_structure_type
:
22915 case DW_TAG_union_type
:
22916 case DW_TAG_module
:
22917 parent_type
= read_type_die (parent
, cu
);
22918 if (TYPE_NAME (parent_type
) != NULL
)
22919 return TYPE_NAME (parent_type
);
22921 /* An anonymous structure is only allowed non-static data
22922 members; no typedefs, no member functions, et cetera.
22923 So it does not need a prefix. */
22925 case DW_TAG_compile_unit
:
22926 case DW_TAG_partial_unit
:
22927 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
22928 if (cu
->language
== language_cplus
22929 && !dwarf2_per_objfile
->types
.empty ()
22930 && die
->child
!= NULL
22931 && (die
->tag
== DW_TAG_class_type
22932 || die
->tag
== DW_TAG_structure_type
22933 || die
->tag
== DW_TAG_union_type
))
22935 const char *name
= guess_full_die_structure_name (die
, cu
);
22940 case DW_TAG_subprogram
:
22941 /* Nested subroutines in Fortran get a prefix with the name
22942 of the parent's subroutine. */
22943 if (cu
->language
== language_fortran
)
22945 if ((die
->tag
== DW_TAG_subprogram
)
22946 && (dwarf2_name (parent
, cu
) != NULL
))
22947 return dwarf2_name (parent
, cu
);
22949 return determine_prefix (parent
, cu
);
22950 case DW_TAG_enumeration_type
:
22951 parent_type
= read_type_die (parent
, cu
);
22952 if (TYPE_DECLARED_CLASS (parent_type
))
22954 if (TYPE_NAME (parent_type
) != NULL
)
22955 return TYPE_NAME (parent_type
);
22958 /* Fall through. */
22960 return determine_prefix (parent
, cu
);
22964 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
22965 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
22966 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
22967 an obconcat, otherwise allocate storage for the result. The CU argument is
22968 used to determine the language and hence, the appropriate separator. */
22970 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
22973 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
22974 int physname
, struct dwarf2_cu
*cu
)
22976 const char *lead
= "";
22979 if (suffix
== NULL
|| suffix
[0] == '\0'
22980 || prefix
== NULL
|| prefix
[0] == '\0')
22982 else if (cu
->language
== language_d
)
22984 /* For D, the 'main' function could be defined in any module, but it
22985 should never be prefixed. */
22986 if (strcmp (suffix
, "D main") == 0)
22994 else if (cu
->language
== language_fortran
&& physname
)
22996 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
22997 DW_AT_MIPS_linkage_name is preferred and used instead. */
23005 if (prefix
== NULL
)
23007 if (suffix
== NULL
)
23014 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
23016 strcpy (retval
, lead
);
23017 strcat (retval
, prefix
);
23018 strcat (retval
, sep
);
23019 strcat (retval
, suffix
);
23024 /* We have an obstack. */
23025 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
23029 /* Return sibling of die, NULL if no sibling. */
23031 static struct die_info
*
23032 sibling_die (struct die_info
*die
)
23034 return die
->sibling
;
23037 /* Get name of a die, return NULL if not found. */
23039 static const char *
23040 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
23041 struct obstack
*obstack
)
23043 if (name
&& cu
->language
== language_cplus
)
23045 std::string canon_name
= cp_canonicalize_string (name
);
23047 if (!canon_name
.empty ())
23049 if (canon_name
!= name
)
23050 name
= obstack_strdup (obstack
, canon_name
);
23057 /* Get name of a die, return NULL if not found.
23058 Anonymous namespaces are converted to their magic string. */
23060 static const char *
23061 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
23063 struct attribute
*attr
;
23064 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
23066 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
23067 if ((!attr
|| !DW_STRING (attr
))
23068 && die
->tag
!= DW_TAG_namespace
23069 && die
->tag
!= DW_TAG_class_type
23070 && die
->tag
!= DW_TAG_interface_type
23071 && die
->tag
!= DW_TAG_structure_type
23072 && die
->tag
!= DW_TAG_union_type
)
23077 case DW_TAG_compile_unit
:
23078 case DW_TAG_partial_unit
:
23079 /* Compilation units have a DW_AT_name that is a filename, not
23080 a source language identifier. */
23081 case DW_TAG_enumeration_type
:
23082 case DW_TAG_enumerator
:
23083 /* These tags always have simple identifiers already; no need
23084 to canonicalize them. */
23085 return DW_STRING (attr
);
23087 case DW_TAG_namespace
:
23088 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
23089 return DW_STRING (attr
);
23090 return CP_ANONYMOUS_NAMESPACE_STR
;
23092 case DW_TAG_class_type
:
23093 case DW_TAG_interface_type
:
23094 case DW_TAG_structure_type
:
23095 case DW_TAG_union_type
:
23096 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
23097 structures or unions. These were of the form "._%d" in GCC 4.1,
23098 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
23099 and GCC 4.4. We work around this problem by ignoring these. */
23100 if (attr
&& DW_STRING (attr
)
23101 && (startswith (DW_STRING (attr
), "._")
23102 || startswith (DW_STRING (attr
), "<anonymous")))
23105 /* GCC might emit a nameless typedef that has a linkage name. See
23106 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
23107 if (!attr
|| DW_STRING (attr
) == NULL
)
23109 attr
= dw2_linkage_name_attr (die
, cu
);
23110 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
23113 /* Avoid demangling DW_STRING (attr) the second time on a second
23114 call for the same DIE. */
23115 if (!DW_STRING_IS_CANONICAL (attr
))
23117 gdb::unique_xmalloc_ptr
<char> demangled
23118 (gdb_demangle (DW_STRING (attr
), DMGL_TYPES
));
23122 /* FIXME: we already did this for the partial symbol... */
23124 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
23126 DW_STRING_IS_CANONICAL (attr
) = 1;
23128 /* Strip any leading namespaces/classes, keep only the base name.
23129 DW_AT_name for named DIEs does not contain the prefixes. */
23130 base
= strrchr (DW_STRING (attr
), ':');
23131 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
23134 return DW_STRING (attr
);
23143 if (!DW_STRING_IS_CANONICAL (attr
))
23146 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
23147 &objfile
->per_bfd
->storage_obstack
);
23148 DW_STRING_IS_CANONICAL (attr
) = 1;
23150 return DW_STRING (attr
);
23153 /* Return the die that this die in an extension of, or NULL if there
23154 is none. *EXT_CU is the CU containing DIE on input, and the CU
23155 containing the return value on output. */
23157 static struct die_info
*
23158 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
23160 struct attribute
*attr
;
23162 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
23166 return follow_die_ref (die
, attr
, ext_cu
);
23169 /* A convenience function that returns an "unknown" DWARF name,
23170 including the value of V. STR is the name of the entity being
23171 printed, e.g., "TAG". */
23173 static const char *
23174 dwarf_unknown (const char *str
, unsigned v
)
23176 char *cell
= get_print_cell ();
23177 xsnprintf (cell
, PRINT_CELL_SIZE
, "DW_%s_<unknown: %u>", str
, v
);
23181 /* Convert a DIE tag into its string name. */
23183 static const char *
23184 dwarf_tag_name (unsigned tag
)
23186 const char *name
= get_DW_TAG_name (tag
);
23189 return dwarf_unknown ("TAG", tag
);
23194 /* Convert a DWARF attribute code into its string name. */
23196 static const char *
23197 dwarf_attr_name (unsigned attr
)
23201 #ifdef MIPS /* collides with DW_AT_HP_block_index */
23202 if (attr
== DW_AT_MIPS_fde
)
23203 return "DW_AT_MIPS_fde";
23205 if (attr
== DW_AT_HP_block_index
)
23206 return "DW_AT_HP_block_index";
23209 name
= get_DW_AT_name (attr
);
23212 return dwarf_unknown ("AT", attr
);
23217 /* Convert a unit type to corresponding DW_UT name. */
23219 static const char *
23220 dwarf_unit_type_name (int unit_type
) {
23224 return "DW_UT_compile (0x01)";
23226 return "DW_UT_type (0x02)";
23228 return "DW_UT_partial (0x03)";
23230 return "DW_UT_skeleton (0x04)";
23232 return "DW_UT_split_compile (0x05)";
23234 return "DW_UT_split_type (0x06)";
23236 return "DW_UT_lo_user (0x80)";
23238 return "DW_UT_hi_user (0xff)";
23244 /* Convert a DWARF value form code into its string name. */
23246 static const char *
23247 dwarf_form_name (unsigned form
)
23249 const char *name
= get_DW_FORM_name (form
);
23252 return dwarf_unknown ("FORM", form
);
23257 static const char *
23258 dwarf_bool_name (unsigned mybool
)
23266 /* Convert a DWARF type code into its string name. */
23268 static const char *
23269 dwarf_type_encoding_name (unsigned enc
)
23271 const char *name
= get_DW_ATE_name (enc
);
23274 return dwarf_unknown ("ATE", enc
);
23280 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
23284 print_spaces (indent
, f
);
23285 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
23286 dwarf_tag_name (die
->tag
), die
->abbrev
,
23287 sect_offset_str (die
->sect_off
));
23289 if (die
->parent
!= NULL
)
23291 print_spaces (indent
, f
);
23292 fprintf_unfiltered (f
, " parent at offset: %s\n",
23293 sect_offset_str (die
->parent
->sect_off
));
23296 print_spaces (indent
, f
);
23297 fprintf_unfiltered (f
, " has children: %s\n",
23298 dwarf_bool_name (die
->child
!= NULL
));
23300 print_spaces (indent
, f
);
23301 fprintf_unfiltered (f
, " attributes:\n");
23303 for (i
= 0; i
< die
->num_attrs
; ++i
)
23305 print_spaces (indent
, f
);
23306 fprintf_unfiltered (f
, " %s (%s) ",
23307 dwarf_attr_name (die
->attrs
[i
].name
),
23308 dwarf_form_name (die
->attrs
[i
].form
));
23310 switch (die
->attrs
[i
].form
)
23313 case DW_FORM_addrx
:
23314 case DW_FORM_GNU_addr_index
:
23315 fprintf_unfiltered (f
, "address: ");
23316 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
23318 case DW_FORM_block2
:
23319 case DW_FORM_block4
:
23320 case DW_FORM_block
:
23321 case DW_FORM_block1
:
23322 fprintf_unfiltered (f
, "block: size %s",
23323 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
23325 case DW_FORM_exprloc
:
23326 fprintf_unfiltered (f
, "expression: size %s",
23327 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
23329 case DW_FORM_data16
:
23330 fprintf_unfiltered (f
, "constant of 16 bytes");
23332 case DW_FORM_ref_addr
:
23333 fprintf_unfiltered (f
, "ref address: ");
23334 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
23336 case DW_FORM_GNU_ref_alt
:
23337 fprintf_unfiltered (f
, "alt ref address: ");
23338 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
23344 case DW_FORM_ref_udata
:
23345 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
23346 (long) (DW_UNSND (&die
->attrs
[i
])));
23348 case DW_FORM_data1
:
23349 case DW_FORM_data2
:
23350 case DW_FORM_data4
:
23351 case DW_FORM_data8
:
23352 case DW_FORM_udata
:
23353 case DW_FORM_sdata
:
23354 fprintf_unfiltered (f
, "constant: %s",
23355 pulongest (DW_UNSND (&die
->attrs
[i
])));
23357 case DW_FORM_sec_offset
:
23358 fprintf_unfiltered (f
, "section offset: %s",
23359 pulongest (DW_UNSND (&die
->attrs
[i
])));
23361 case DW_FORM_ref_sig8
:
23362 fprintf_unfiltered (f
, "signature: %s",
23363 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
23365 case DW_FORM_string
:
23367 case DW_FORM_line_strp
:
23369 case DW_FORM_GNU_str_index
:
23370 case DW_FORM_GNU_strp_alt
:
23371 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
23372 DW_STRING (&die
->attrs
[i
])
23373 ? DW_STRING (&die
->attrs
[i
]) : "",
23374 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
23377 if (DW_UNSND (&die
->attrs
[i
]))
23378 fprintf_unfiltered (f
, "flag: TRUE");
23380 fprintf_unfiltered (f
, "flag: FALSE");
23382 case DW_FORM_flag_present
:
23383 fprintf_unfiltered (f
, "flag: TRUE");
23385 case DW_FORM_indirect
:
23386 /* The reader will have reduced the indirect form to
23387 the "base form" so this form should not occur. */
23388 fprintf_unfiltered (f
,
23389 "unexpected attribute form: DW_FORM_indirect");
23391 case DW_FORM_implicit_const
:
23392 fprintf_unfiltered (f
, "constant: %s",
23393 plongest (DW_SND (&die
->attrs
[i
])));
23396 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
23397 die
->attrs
[i
].form
);
23400 fprintf_unfiltered (f
, "\n");
23405 dump_die_for_error (struct die_info
*die
)
23407 dump_die_shallow (gdb_stderr
, 0, die
);
23411 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
23413 int indent
= level
* 4;
23415 gdb_assert (die
!= NULL
);
23417 if (level
>= max_level
)
23420 dump_die_shallow (f
, indent
, die
);
23422 if (die
->child
!= NULL
)
23424 print_spaces (indent
, f
);
23425 fprintf_unfiltered (f
, " Children:");
23426 if (level
+ 1 < max_level
)
23428 fprintf_unfiltered (f
, "\n");
23429 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
23433 fprintf_unfiltered (f
,
23434 " [not printed, max nesting level reached]\n");
23438 if (die
->sibling
!= NULL
&& level
> 0)
23440 dump_die_1 (f
, level
, max_level
, die
->sibling
);
23444 /* This is called from the pdie macro in gdbinit.in.
23445 It's not static so gcc will keep a copy callable from gdb. */
23448 dump_die (struct die_info
*die
, int max_level
)
23450 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
23454 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
23458 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
23459 to_underlying (die
->sect_off
),
23465 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
23469 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
23471 if (attr_form_is_ref (attr
))
23472 return (sect_offset
) DW_UNSND (attr
);
23474 complaint (_("unsupported die ref attribute form: '%s'"),
23475 dwarf_form_name (attr
->form
));
23479 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
23480 * the value held by the attribute is not constant. */
23483 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
23485 if (attr
->form
== DW_FORM_sdata
|| attr
->form
== DW_FORM_implicit_const
)
23486 return DW_SND (attr
);
23487 else if (attr
->form
== DW_FORM_udata
23488 || attr
->form
== DW_FORM_data1
23489 || attr
->form
== DW_FORM_data2
23490 || attr
->form
== DW_FORM_data4
23491 || attr
->form
== DW_FORM_data8
)
23492 return DW_UNSND (attr
);
23495 /* For DW_FORM_data16 see attr_form_is_constant. */
23496 complaint (_("Attribute value is not a constant (%s)"),
23497 dwarf_form_name (attr
->form
));
23498 return default_value
;
23502 /* Follow reference or signature attribute ATTR of SRC_DIE.
23503 On entry *REF_CU is the CU of SRC_DIE.
23504 On exit *REF_CU is the CU of the result. */
23506 static struct die_info
*
23507 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23508 struct dwarf2_cu
**ref_cu
)
23510 struct die_info
*die
;
23512 if (attr_form_is_ref (attr
))
23513 die
= follow_die_ref (src_die
, attr
, ref_cu
);
23514 else if (attr
->form
== DW_FORM_ref_sig8
)
23515 die
= follow_die_sig (src_die
, attr
, ref_cu
);
23518 dump_die_for_error (src_die
);
23519 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
23520 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23526 /* Follow reference OFFSET.
23527 On entry *REF_CU is the CU of the source die referencing OFFSET.
23528 On exit *REF_CU is the CU of the result.
23529 Returns NULL if OFFSET is invalid. */
23531 static struct die_info
*
23532 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
23533 struct dwarf2_cu
**ref_cu
)
23535 struct die_info temp_die
;
23536 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
23537 struct dwarf2_per_objfile
*dwarf2_per_objfile
23538 = cu
->per_cu
->dwarf2_per_objfile
;
23540 gdb_assert (cu
->per_cu
!= NULL
);
23544 if (cu
->per_cu
->is_debug_types
)
23546 /* .debug_types CUs cannot reference anything outside their CU.
23547 If they need to, they have to reference a signatured type via
23548 DW_FORM_ref_sig8. */
23549 if (!offset_in_cu_p (&cu
->header
, sect_off
))
23552 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
23553 || !offset_in_cu_p (&cu
->header
, sect_off
))
23555 struct dwarf2_per_cu_data
*per_cu
;
23557 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23558 dwarf2_per_objfile
);
23560 /* If necessary, add it to the queue and load its DIEs. */
23561 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
23562 load_full_comp_unit (per_cu
, false, cu
->language
);
23564 target_cu
= per_cu
->cu
;
23566 else if (cu
->dies
== NULL
)
23568 /* We're loading full DIEs during partial symbol reading. */
23569 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
23570 load_full_comp_unit (cu
->per_cu
, false, language_minimal
);
23573 *ref_cu
= target_cu
;
23574 temp_die
.sect_off
= sect_off
;
23576 if (target_cu
!= cu
)
23577 target_cu
->ancestor
= cu
;
23579 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
23581 to_underlying (sect_off
));
23584 /* Follow reference attribute ATTR of SRC_DIE.
23585 On entry *REF_CU is the CU of SRC_DIE.
23586 On exit *REF_CU is the CU of the result. */
23588 static struct die_info
*
23589 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
23590 struct dwarf2_cu
**ref_cu
)
23592 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
23593 struct dwarf2_cu
*cu
= *ref_cu
;
23594 struct die_info
*die
;
23596 die
= follow_die_offset (sect_off
,
23597 (attr
->form
== DW_FORM_GNU_ref_alt
23598 || cu
->per_cu
->is_dwz
),
23601 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
23602 "at %s [in module %s]"),
23603 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
23604 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
23609 /* Return DWARF block referenced by DW_AT_location of DIE at SECT_OFF at PER_CU.
23610 Returned value is intended for DW_OP_call*. Returned
23611 dwarf2_locexpr_baton->data has lifetime of
23612 PER_CU->DWARF2_PER_OBJFILE->OBJFILE. */
23614 struct dwarf2_locexpr_baton
23615 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
23616 struct dwarf2_per_cu_data
*per_cu
,
23617 CORE_ADDR (*get_frame_pc
) (void *baton
),
23618 void *baton
, bool resolve_abstract_p
)
23620 struct dwarf2_cu
*cu
;
23621 struct die_info
*die
;
23622 struct attribute
*attr
;
23623 struct dwarf2_locexpr_baton retval
;
23624 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
23625 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23627 if (per_cu
->cu
== NULL
)
23628 load_cu (per_cu
, false);
23632 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23633 Instead just throw an error, not much else we can do. */
23634 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23635 sect_offset_str (sect_off
), objfile_name (objfile
));
23638 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23640 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23641 sect_offset_str (sect_off
), objfile_name (objfile
));
23643 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23644 if (!attr
&& resolve_abstract_p
23645 && (dwarf2_per_objfile
->abstract_to_concrete
.find (die
->sect_off
)
23646 != dwarf2_per_objfile
->abstract_to_concrete
.end ()))
23648 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
23649 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
23650 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
23652 for (const auto &cand_off
23653 : dwarf2_per_objfile
->abstract_to_concrete
[die
->sect_off
])
23655 struct dwarf2_cu
*cand_cu
= cu
;
23656 struct die_info
*cand
23657 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
23660 || cand
->parent
->tag
!= DW_TAG_subprogram
)
23663 CORE_ADDR pc_low
, pc_high
;
23664 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
23665 if (pc_low
== ((CORE_ADDR
) -1))
23667 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
23668 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
23669 if (!(pc_low
<= pc
&& pc
< pc_high
))
23673 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23680 /* DWARF: "If there is no such attribute, then there is no effect.".
23681 DATA is ignored if SIZE is 0. */
23683 retval
.data
= NULL
;
23686 else if (attr_form_is_section_offset (attr
))
23688 struct dwarf2_loclist_baton loclist_baton
;
23689 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
23692 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
23694 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
23696 retval
.size
= size
;
23700 if (!attr_form_is_block (attr
))
23701 error (_("Dwarf Error: DIE at %s referenced in module %s "
23702 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
23703 sect_offset_str (sect_off
), objfile_name (objfile
));
23705 retval
.data
= DW_BLOCK (attr
)->data
;
23706 retval
.size
= DW_BLOCK (attr
)->size
;
23708 retval
.per_cu
= cu
->per_cu
;
23710 age_cached_comp_units (dwarf2_per_objfile
);
23715 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
23718 struct dwarf2_locexpr_baton
23719 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
23720 struct dwarf2_per_cu_data
*per_cu
,
23721 CORE_ADDR (*get_frame_pc
) (void *baton
),
23724 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
23726 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
23729 /* Write a constant of a given type as target-ordered bytes into
23732 static const gdb_byte
*
23733 write_constant_as_bytes (struct obstack
*obstack
,
23734 enum bfd_endian byte_order
,
23741 *len
= TYPE_LENGTH (type
);
23742 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23743 store_unsigned_integer (result
, *len
, byte_order
, value
);
23748 /* If the DIE at OFFSET in PER_CU has a DW_AT_const_value, return a
23749 pointer to the constant bytes and set LEN to the length of the
23750 data. If memory is needed, allocate it on OBSTACK. If the DIE
23751 does not have a DW_AT_const_value, return NULL. */
23754 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
23755 struct dwarf2_per_cu_data
*per_cu
,
23756 struct obstack
*obstack
,
23759 struct dwarf2_cu
*cu
;
23760 struct die_info
*die
;
23761 struct attribute
*attr
;
23762 const gdb_byte
*result
= NULL
;
23765 enum bfd_endian byte_order
;
23766 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
23768 if (per_cu
->cu
== NULL
)
23769 load_cu (per_cu
, false);
23773 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23774 Instead just throw an error, not much else we can do. */
23775 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23776 sect_offset_str (sect_off
), objfile_name (objfile
));
23779 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23781 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23782 sect_offset_str (sect_off
), objfile_name (objfile
));
23784 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23788 byte_order
= (bfd_big_endian (objfile
->obfd
)
23789 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
23791 switch (attr
->form
)
23794 case DW_FORM_addrx
:
23795 case DW_FORM_GNU_addr_index
:
23799 *len
= cu
->header
.addr_size
;
23800 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23801 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
23805 case DW_FORM_string
:
23808 case DW_FORM_GNU_str_index
:
23809 case DW_FORM_GNU_strp_alt
:
23810 /* DW_STRING is already allocated on the objfile obstack, point
23812 result
= (const gdb_byte
*) DW_STRING (attr
);
23813 *len
= strlen (DW_STRING (attr
));
23815 case DW_FORM_block1
:
23816 case DW_FORM_block2
:
23817 case DW_FORM_block4
:
23818 case DW_FORM_block
:
23819 case DW_FORM_exprloc
:
23820 case DW_FORM_data16
:
23821 result
= DW_BLOCK (attr
)->data
;
23822 *len
= DW_BLOCK (attr
)->size
;
23825 /* The DW_AT_const_value attributes are supposed to carry the
23826 symbol's value "represented as it would be on the target
23827 architecture." By the time we get here, it's already been
23828 converted to host endianness, so we just need to sign- or
23829 zero-extend it as appropriate. */
23830 case DW_FORM_data1
:
23831 type
= die_type (die
, cu
);
23832 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
23833 if (result
== NULL
)
23834 result
= write_constant_as_bytes (obstack
, byte_order
,
23837 case DW_FORM_data2
:
23838 type
= die_type (die
, cu
);
23839 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
23840 if (result
== NULL
)
23841 result
= write_constant_as_bytes (obstack
, byte_order
,
23844 case DW_FORM_data4
:
23845 type
= die_type (die
, cu
);
23846 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
23847 if (result
== NULL
)
23848 result
= write_constant_as_bytes (obstack
, byte_order
,
23851 case DW_FORM_data8
:
23852 type
= die_type (die
, cu
);
23853 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
23854 if (result
== NULL
)
23855 result
= write_constant_as_bytes (obstack
, byte_order
,
23859 case DW_FORM_sdata
:
23860 case DW_FORM_implicit_const
:
23861 type
= die_type (die
, cu
);
23862 result
= write_constant_as_bytes (obstack
, byte_order
,
23863 type
, DW_SND (attr
), len
);
23866 case DW_FORM_udata
:
23867 type
= die_type (die
, cu
);
23868 result
= write_constant_as_bytes (obstack
, byte_order
,
23869 type
, DW_UNSND (attr
), len
);
23873 complaint (_("unsupported const value attribute form: '%s'"),
23874 dwarf_form_name (attr
->form
));
23881 /* Return the type of the die at OFFSET in PER_CU. Return NULL if no
23882 valid type for this die is found. */
23885 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
23886 struct dwarf2_per_cu_data
*per_cu
)
23888 struct dwarf2_cu
*cu
;
23889 struct die_info
*die
;
23891 if (per_cu
->cu
== NULL
)
23892 load_cu (per_cu
, false);
23897 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23901 return die_type (die
, cu
);
23904 /* Return the type of the DIE at DIE_OFFSET in the CU named by
23908 dwarf2_get_die_type (cu_offset die_offset
,
23909 struct dwarf2_per_cu_data
*per_cu
)
23911 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
23912 return get_die_type_at_offset (die_offset_sect
, per_cu
);
23915 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
23916 On entry *REF_CU is the CU of SRC_DIE.
23917 On exit *REF_CU is the CU of the result.
23918 Returns NULL if the referenced DIE isn't found. */
23920 static struct die_info
*
23921 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
23922 struct dwarf2_cu
**ref_cu
)
23924 struct die_info temp_die
;
23925 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
23926 struct die_info
*die
;
23928 /* While it might be nice to assert sig_type->type == NULL here,
23929 we can get here for DW_AT_imported_declaration where we need
23930 the DIE not the type. */
23932 /* If necessary, add it to the queue and load its DIEs. */
23934 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
23935 read_signatured_type (sig_type
);
23937 sig_cu
= sig_type
->per_cu
.cu
;
23938 gdb_assert (sig_cu
!= NULL
);
23939 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
23940 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
23941 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
23942 to_underlying (temp_die
.sect_off
));
23945 struct dwarf2_per_objfile
*dwarf2_per_objfile
23946 = (*ref_cu
)->per_cu
->dwarf2_per_objfile
;
23948 /* For .gdb_index version 7 keep track of included TUs.
23949 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
23950 if (dwarf2_per_objfile
->index_table
!= NULL
23951 && dwarf2_per_objfile
->index_table
->version
<= 7)
23953 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
23958 sig_cu
->ancestor
= cu
;
23966 /* Follow signatured type referenced by ATTR in SRC_DIE.
23967 On entry *REF_CU is the CU of SRC_DIE.
23968 On exit *REF_CU is the CU of the result.
23969 The result is the DIE of the type.
23970 If the referenced type cannot be found an error is thrown. */
23972 static struct die_info
*
23973 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23974 struct dwarf2_cu
**ref_cu
)
23976 ULONGEST signature
= DW_SIGNATURE (attr
);
23977 struct signatured_type
*sig_type
;
23978 struct die_info
*die
;
23980 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
23982 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
23983 /* sig_type will be NULL if the signatured type is missing from
23985 if (sig_type
== NULL
)
23987 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23988 " from DIE at %s [in module %s]"),
23989 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23990 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23993 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
23996 dump_die_for_error (src_die
);
23997 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23998 " from DIE at %s [in module %s]"),
23999 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
24000 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
24006 /* Get the type specified by SIGNATURE referenced in DIE/CU,
24007 reading in and processing the type unit if necessary. */
24009 static struct type
*
24010 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
24011 struct dwarf2_cu
*cu
)
24013 struct dwarf2_per_objfile
*dwarf2_per_objfile
24014 = cu
->per_cu
->dwarf2_per_objfile
;
24015 struct signatured_type
*sig_type
;
24016 struct dwarf2_cu
*type_cu
;
24017 struct die_info
*type_die
;
24020 sig_type
= lookup_signatured_type (cu
, signature
);
24021 /* sig_type will be NULL if the signatured type is missing from
24023 if (sig_type
== NULL
)
24025 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
24026 " from DIE at %s [in module %s]"),
24027 hex_string (signature
), sect_offset_str (die
->sect_off
),
24028 objfile_name (dwarf2_per_objfile
->objfile
));
24029 return build_error_marker_type (cu
, die
);
24032 /* If we already know the type we're done. */
24033 if (sig_type
->type
!= NULL
)
24034 return sig_type
->type
;
24037 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
24038 if (type_die
!= NULL
)
24040 /* N.B. We need to call get_die_type to ensure only one type for this DIE
24041 is created. This is important, for example, because for c++ classes
24042 we need TYPE_NAME set which is only done by new_symbol. Blech. */
24043 type
= read_type_die (type_die
, type_cu
);
24046 complaint (_("Dwarf Error: Cannot build signatured type %s"
24047 " referenced from DIE at %s [in module %s]"),
24048 hex_string (signature
), sect_offset_str (die
->sect_off
),
24049 objfile_name (dwarf2_per_objfile
->objfile
));
24050 type
= build_error_marker_type (cu
, die
);
24055 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
24056 " from DIE at %s [in module %s]"),
24057 hex_string (signature
), sect_offset_str (die
->sect_off
),
24058 objfile_name (dwarf2_per_objfile
->objfile
));
24059 type
= build_error_marker_type (cu
, die
);
24061 sig_type
->type
= type
;
24066 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
24067 reading in and processing the type unit if necessary. */
24069 static struct type
*
24070 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
24071 struct dwarf2_cu
*cu
) /* ARI: editCase function */
24073 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
24074 if (attr_form_is_ref (attr
))
24076 struct dwarf2_cu
*type_cu
= cu
;
24077 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
24079 return read_type_die (type_die
, type_cu
);
24081 else if (attr
->form
== DW_FORM_ref_sig8
)
24083 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
24087 struct dwarf2_per_objfile
*dwarf2_per_objfile
24088 = cu
->per_cu
->dwarf2_per_objfile
;
24090 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
24091 " at %s [in module %s]"),
24092 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
24093 objfile_name (dwarf2_per_objfile
->objfile
));
24094 return build_error_marker_type (cu
, die
);
24098 /* Load the DIEs associated with type unit PER_CU into memory. */
24101 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
24103 struct signatured_type
*sig_type
;
24105 /* Caller is responsible for ensuring type_unit_groups don't get here. */
24106 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
24108 /* We have the per_cu, but we need the signatured_type.
24109 Fortunately this is an easy translation. */
24110 gdb_assert (per_cu
->is_debug_types
);
24111 sig_type
= (struct signatured_type
*) per_cu
;
24113 gdb_assert (per_cu
->cu
== NULL
);
24115 read_signatured_type (sig_type
);
24117 gdb_assert (per_cu
->cu
!= NULL
);
24120 /* Read in a signatured type and build its CU and DIEs.
24121 If the type is a stub for the real type in a DWO file,
24122 read in the real type from the DWO file as well. */
24125 read_signatured_type (struct signatured_type
*sig_type
)
24127 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
24129 gdb_assert (per_cu
->is_debug_types
);
24130 gdb_assert (per_cu
->cu
== NULL
);
24132 cutu_reader
reader (per_cu
, NULL
, 0, 1, false);
24134 if (!reader
.dummy_p
)
24136 struct dwarf2_cu
*cu
= reader
.cu
;
24137 const gdb_byte
*info_ptr
= reader
.info_ptr
;
24139 gdb_assert (cu
->die_hash
== NULL
);
24141 htab_create_alloc_ex (cu
->header
.length
/ 12,
24145 &cu
->comp_unit_obstack
,
24146 hashtab_obstack_allocate
,
24147 dummy_obstack_deallocate
);
24149 if (reader
.has_children
)
24150 reader
.comp_unit_die
->child
24151 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
24152 reader
.comp_unit_die
);
24153 cu
->dies
= reader
.comp_unit_die
;
24154 /* comp_unit_die is not stored in die_hash, no need. */
24156 /* We try not to read any attributes in this function, because
24157 not all CUs needed for references have been loaded yet, and
24158 symbol table processing isn't initialized. But we have to
24159 set the CU language, or we won't be able to build types
24160 correctly. Similarly, if we do not read the producer, we can
24161 not apply producer-specific interpretation. */
24162 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
24165 sig_type
->per_cu
.tu_read
= 1;
24168 /* Decode simple location descriptions.
24169 Given a pointer to a dwarf block that defines a location, compute
24170 the location and return the value.
24172 NOTE drow/2003-11-18: This function is called in two situations
24173 now: for the address of static or global variables (partial symbols
24174 only) and for offsets into structures which are expected to be
24175 (more or less) constant. The partial symbol case should go away,
24176 and only the constant case should remain. That will let this
24177 function complain more accurately. A few special modes are allowed
24178 without complaint for global variables (for instance, global
24179 register values and thread-local values).
24181 A location description containing no operations indicates that the
24182 object is optimized out. The return value is 0 for that case.
24183 FIXME drow/2003-11-16: No callers check for this case any more; soon all
24184 callers will only want a very basic result and this can become a
24187 Note that stack[0] is unused except as a default error return. */
24190 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
24192 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
24194 size_t size
= blk
->size
;
24195 const gdb_byte
*data
= blk
->data
;
24196 CORE_ADDR stack
[64];
24198 unsigned int bytes_read
, unsnd
;
24204 stack
[++stacki
] = 0;
24243 stack
[++stacki
] = op
- DW_OP_lit0
;
24278 stack
[++stacki
] = op
- DW_OP_reg0
;
24280 dwarf2_complex_location_expr_complaint ();
24284 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
24286 stack
[++stacki
] = unsnd
;
24288 dwarf2_complex_location_expr_complaint ();
24292 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
24297 case DW_OP_const1u
:
24298 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
24302 case DW_OP_const1s
:
24303 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
24307 case DW_OP_const2u
:
24308 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
24312 case DW_OP_const2s
:
24313 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
24317 case DW_OP_const4u
:
24318 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
24322 case DW_OP_const4s
:
24323 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
24327 case DW_OP_const8u
:
24328 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
24333 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
24339 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
24344 stack
[stacki
+ 1] = stack
[stacki
];
24349 stack
[stacki
- 1] += stack
[stacki
];
24353 case DW_OP_plus_uconst
:
24354 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
24360 stack
[stacki
- 1] -= stack
[stacki
];
24365 /* If we're not the last op, then we definitely can't encode
24366 this using GDB's address_class enum. This is valid for partial
24367 global symbols, although the variable's address will be bogus
24370 dwarf2_complex_location_expr_complaint ();
24373 case DW_OP_GNU_push_tls_address
:
24374 case DW_OP_form_tls_address
:
24375 /* The top of the stack has the offset from the beginning
24376 of the thread control block at which the variable is located. */
24377 /* Nothing should follow this operator, so the top of stack would
24379 /* This is valid for partial global symbols, but the variable's
24380 address will be bogus in the psymtab. Make it always at least
24381 non-zero to not look as a variable garbage collected by linker
24382 which have DW_OP_addr 0. */
24384 dwarf2_complex_location_expr_complaint ();
24388 case DW_OP_GNU_uninit
:
24392 case DW_OP_GNU_addr_index
:
24393 case DW_OP_GNU_const_index
:
24394 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
24401 const char *name
= get_DW_OP_name (op
);
24404 complaint (_("unsupported stack op: '%s'"),
24407 complaint (_("unsupported stack op: '%02x'"),
24411 return (stack
[stacki
]);
24414 /* Enforce maximum stack depth of SIZE-1 to avoid writing
24415 outside of the allocated space. Also enforce minimum>0. */
24416 if (stacki
>= ARRAY_SIZE (stack
) - 1)
24418 complaint (_("location description stack overflow"));
24424 complaint (_("location description stack underflow"));
24428 return (stack
[stacki
]);
24431 /* memory allocation interface */
24433 static struct dwarf_block
*
24434 dwarf_alloc_block (struct dwarf2_cu
*cu
)
24436 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
24439 static struct die_info
*
24440 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
24442 struct die_info
*die
;
24443 size_t size
= sizeof (struct die_info
);
24446 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
24448 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
24449 memset (die
, 0, sizeof (struct die_info
));
24454 /* Macro support. */
24456 /* Return file name relative to the compilation directory of file number I in
24457 *LH's file name table. The result is allocated using xmalloc; the caller is
24458 responsible for freeing it. */
24461 file_file_name (int file
, struct line_header
*lh
)
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 const file_entry
*fe
= lh
->file_name_at (file
);
24469 if (!IS_ABSOLUTE_PATH (fe
->name
))
24471 const char *dir
= fe
->include_dir (lh
);
24473 return concat (dir
, SLASH_STRING
, fe
->name
, (char *) NULL
);
24475 return xstrdup (fe
->name
);
24479 /* The compiler produced a bogus file number. We can at least
24480 record the macro definitions made in the file, even if we
24481 won't be able to find the file by name. */
24482 char fake_name
[80];
24484 xsnprintf (fake_name
, sizeof (fake_name
),
24485 "<bad macro file number %d>", file
);
24487 complaint (_("bad file number in macro information (%d)"),
24490 return xstrdup (fake_name
);
24494 /* Return the full name of file number I in *LH's file name table.
24495 Use COMP_DIR as the name of the current directory of the
24496 compilation. The result is allocated using xmalloc; the caller is
24497 responsible for freeing it. */
24499 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
24501 /* Is the file number a valid index into the line header's file name
24502 table? Remember that file numbers start with one, not zero. */
24503 if (lh
->is_valid_file_index (file
))
24505 char *relative
= file_file_name (file
, lh
);
24507 if (IS_ABSOLUTE_PATH (relative
) || comp_dir
== NULL
)
24509 return reconcat (relative
, comp_dir
, SLASH_STRING
,
24510 relative
, (char *) NULL
);
24513 return file_file_name (file
, lh
);
24517 static struct macro_source_file
*
24518 macro_start_file (struct dwarf2_cu
*cu
,
24519 int file
, int line
,
24520 struct macro_source_file
*current_file
,
24521 struct line_header
*lh
)
24523 /* File name relative to the compilation directory of this source file. */
24524 char *file_name
= file_file_name (file
, lh
);
24526 if (! current_file
)
24528 /* Note: We don't create a macro table for this compilation unit
24529 at all until we actually get a filename. */
24530 struct macro_table
*macro_table
= cu
->get_builder ()->get_macro_table ();
24532 /* If we have no current file, then this must be the start_file
24533 directive for the compilation unit's main source file. */
24534 current_file
= macro_set_main (macro_table
, file_name
);
24535 macro_define_special (macro_table
);
24538 current_file
= macro_include (current_file
, line
, file_name
);
24542 return current_file
;
24545 static const char *
24546 consume_improper_spaces (const char *p
, const char *body
)
24550 complaint (_("macro definition contains spaces "
24551 "in formal argument list:\n`%s'"),
24563 parse_macro_definition (struct macro_source_file
*file
, int line
,
24568 /* The body string takes one of two forms. For object-like macro
24569 definitions, it should be:
24571 <macro name> " " <definition>
24573 For function-like macro definitions, it should be:
24575 <macro name> "() " <definition>
24577 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
24579 Spaces may appear only where explicitly indicated, and in the
24582 The Dwarf 2 spec says that an object-like macro's name is always
24583 followed by a space, but versions of GCC around March 2002 omit
24584 the space when the macro's definition is the empty string.
24586 The Dwarf 2 spec says that there should be no spaces between the
24587 formal arguments in a function-like macro's formal argument list,
24588 but versions of GCC around March 2002 include spaces after the
24592 /* Find the extent of the macro name. The macro name is terminated
24593 by either a space or null character (for an object-like macro) or
24594 an opening paren (for a function-like macro). */
24595 for (p
= body
; *p
; p
++)
24596 if (*p
== ' ' || *p
== '(')
24599 if (*p
== ' ' || *p
== '\0')
24601 /* It's an object-like macro. */
24602 int name_len
= p
- body
;
24603 std::string
name (body
, name_len
);
24604 const char *replacement
;
24607 replacement
= body
+ name_len
+ 1;
24610 dwarf2_macro_malformed_definition_complaint (body
);
24611 replacement
= body
+ name_len
;
24614 macro_define_object (file
, line
, name
.c_str (), replacement
);
24616 else if (*p
== '(')
24618 /* It's a function-like macro. */
24619 std::string
name (body
, p
- body
);
24622 char **argv
= XNEWVEC (char *, argv_size
);
24626 p
= consume_improper_spaces (p
, body
);
24628 /* Parse the formal argument list. */
24629 while (*p
&& *p
!= ')')
24631 /* Find the extent of the current argument name. */
24632 const char *arg_start
= p
;
24634 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
24637 if (! *p
|| p
== arg_start
)
24638 dwarf2_macro_malformed_definition_complaint (body
);
24641 /* Make sure argv has room for the new argument. */
24642 if (argc
>= argv_size
)
24645 argv
= XRESIZEVEC (char *, argv
, argv_size
);
24648 argv
[argc
++] = savestring (arg_start
, p
- arg_start
);
24651 p
= consume_improper_spaces (p
, body
);
24653 /* Consume the comma, if present. */
24658 p
= consume_improper_spaces (p
, body
);
24667 /* Perfectly formed definition, no complaints. */
24668 macro_define_function (file
, line
, name
.c_str (),
24669 argc
, (const char **) argv
,
24671 else if (*p
== '\0')
24673 /* Complain, but do define it. */
24674 dwarf2_macro_malformed_definition_complaint (body
);
24675 macro_define_function (file
, line
, name
.c_str (),
24676 argc
, (const char **) argv
,
24680 /* Just complain. */
24681 dwarf2_macro_malformed_definition_complaint (body
);
24684 /* Just complain. */
24685 dwarf2_macro_malformed_definition_complaint (body
);
24690 for (i
= 0; i
< argc
; i
++)
24696 dwarf2_macro_malformed_definition_complaint (body
);
24699 /* Skip some bytes from BYTES according to the form given in FORM.
24700 Returns the new pointer. */
24702 static const gdb_byte
*
24703 skip_form_bytes (bfd
*abfd
, const gdb_byte
*bytes
, const gdb_byte
*buffer_end
,
24704 enum dwarf_form form
,
24705 unsigned int offset_size
,
24706 struct dwarf2_section_info
*section
)
24708 unsigned int bytes_read
;
24712 case DW_FORM_data1
:
24717 case DW_FORM_data2
:
24721 case DW_FORM_data4
:
24725 case DW_FORM_data8
:
24729 case DW_FORM_data16
:
24733 case DW_FORM_string
:
24734 read_direct_string (abfd
, bytes
, &bytes_read
);
24735 bytes
+= bytes_read
;
24738 case DW_FORM_sec_offset
:
24740 case DW_FORM_GNU_strp_alt
:
24741 bytes
+= offset_size
;
24744 case DW_FORM_block
:
24745 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
24746 bytes
+= bytes_read
;
24749 case DW_FORM_block1
:
24750 bytes
+= 1 + read_1_byte (abfd
, bytes
);
24752 case DW_FORM_block2
:
24753 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
24755 case DW_FORM_block4
:
24756 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
24759 case DW_FORM_addrx
:
24760 case DW_FORM_sdata
:
24762 case DW_FORM_udata
:
24763 case DW_FORM_GNU_addr_index
:
24764 case DW_FORM_GNU_str_index
:
24765 bytes
= gdb_skip_leb128 (bytes
, buffer_end
);
24768 dwarf2_section_buffer_overflow_complaint (section
);
24773 case DW_FORM_implicit_const
:
24778 complaint (_("invalid form 0x%x in `%s'"),
24779 form
, get_section_name (section
));
24787 /* A helper for dwarf_decode_macros that handles skipping an unknown
24788 opcode. Returns an updated pointer to the macro data buffer; or,
24789 on error, issues a complaint and returns NULL. */
24791 static const gdb_byte
*
24792 skip_unknown_opcode (unsigned int opcode
,
24793 const gdb_byte
**opcode_definitions
,
24794 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24796 unsigned int offset_size
,
24797 struct dwarf2_section_info
*section
)
24799 unsigned int bytes_read
, i
;
24801 const gdb_byte
*defn
;
24803 if (opcode_definitions
[opcode
] == NULL
)
24805 complaint (_("unrecognized DW_MACFINO opcode 0x%x"),
24810 defn
= opcode_definitions
[opcode
];
24811 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
24812 defn
+= bytes_read
;
24814 for (i
= 0; i
< arg
; ++i
)
24816 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
,
24817 (enum dwarf_form
) defn
[i
], offset_size
,
24819 if (mac_ptr
== NULL
)
24821 /* skip_form_bytes already issued the complaint. */
24829 /* A helper function which parses the header of a macro section.
24830 If the macro section is the extended (for now called "GNU") type,
24831 then this updates *OFFSET_SIZE. Returns a pointer to just after
24832 the header, or issues a complaint and returns NULL on error. */
24834 static const gdb_byte
*
24835 dwarf_parse_macro_header (const gdb_byte
**opcode_definitions
,
24837 const gdb_byte
*mac_ptr
,
24838 unsigned int *offset_size
,
24839 int section_is_gnu
)
24841 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
24843 if (section_is_gnu
)
24845 unsigned int version
, flags
;
24847 version
= read_2_bytes (abfd
, mac_ptr
);
24848 if (version
!= 4 && version
!= 5)
24850 complaint (_("unrecognized version `%d' in .debug_macro section"),
24856 flags
= read_1_byte (abfd
, mac_ptr
);
24858 *offset_size
= (flags
& 1) ? 8 : 4;
24860 if ((flags
& 2) != 0)
24861 /* We don't need the line table offset. */
24862 mac_ptr
+= *offset_size
;
24864 /* Vendor opcode descriptions. */
24865 if ((flags
& 4) != 0)
24867 unsigned int i
, count
;
24869 count
= read_1_byte (abfd
, mac_ptr
);
24871 for (i
= 0; i
< count
; ++i
)
24873 unsigned int opcode
, bytes_read
;
24876 opcode
= read_1_byte (abfd
, mac_ptr
);
24878 opcode_definitions
[opcode
] = mac_ptr
;
24879 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24880 mac_ptr
+= bytes_read
;
24889 /* A helper for dwarf_decode_macros that handles the GNU extensions,
24890 including DW_MACRO_import. */
24893 dwarf_decode_macro_bytes (struct dwarf2_cu
*cu
,
24895 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24896 struct macro_source_file
*current_file
,
24897 struct line_header
*lh
,
24898 struct dwarf2_section_info
*section
,
24899 int section_is_gnu
, int section_is_dwz
,
24900 unsigned int offset_size
,
24901 htab_t include_hash
)
24903 struct dwarf2_per_objfile
*dwarf2_per_objfile
24904 = cu
->per_cu
->dwarf2_per_objfile
;
24905 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24906 enum dwarf_macro_record_type macinfo_type
;
24907 int at_commandline
;
24908 const gdb_byte
*opcode_definitions
[256];
24910 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
24911 &offset_size
, section_is_gnu
);
24912 if (mac_ptr
== NULL
)
24914 /* We already issued a complaint. */
24918 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
24919 GDB is still reading the definitions from command line. First
24920 DW_MACINFO_start_file will need to be ignored as it was already executed
24921 to create CURRENT_FILE for the main source holding also the command line
24922 definitions. On first met DW_MACINFO_start_file this flag is reset to
24923 normally execute all the remaining DW_MACINFO_start_file macinfos. */
24925 at_commandline
= 1;
24929 /* Do we at least have room for a macinfo type byte? */
24930 if (mac_ptr
>= mac_end
)
24932 dwarf2_section_buffer_overflow_complaint (section
);
24936 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
24939 /* Note that we rely on the fact that the corresponding GNU and
24940 DWARF constants are the same. */
24942 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
24943 switch (macinfo_type
)
24945 /* A zero macinfo type indicates the end of the macro
24950 case DW_MACRO_define
:
24951 case DW_MACRO_undef
:
24952 case DW_MACRO_define_strp
:
24953 case DW_MACRO_undef_strp
:
24954 case DW_MACRO_define_sup
:
24955 case DW_MACRO_undef_sup
:
24957 unsigned int bytes_read
;
24962 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24963 mac_ptr
+= bytes_read
;
24965 if (macinfo_type
== DW_MACRO_define
24966 || macinfo_type
== DW_MACRO_undef
)
24968 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24969 mac_ptr
+= bytes_read
;
24973 LONGEST str_offset
;
24975 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
24976 mac_ptr
+= offset_size
;
24978 if (macinfo_type
== DW_MACRO_define_sup
24979 || macinfo_type
== DW_MACRO_undef_sup
24982 struct dwz_file
*dwz
24983 = dwarf2_get_dwz_file (dwarf2_per_objfile
);
24985 body
= read_indirect_string_from_dwz (objfile
,
24989 body
= read_indirect_string_at_offset (dwarf2_per_objfile
,
24993 is_define
= (macinfo_type
== DW_MACRO_define
24994 || macinfo_type
== DW_MACRO_define_strp
24995 || macinfo_type
== DW_MACRO_define_sup
);
24996 if (! current_file
)
24998 /* DWARF violation as no main source is present. */
24999 complaint (_("debug info with no main source gives macro %s "
25001 is_define
? _("definition") : _("undefinition"),
25005 if ((line
== 0 && !at_commandline
)
25006 || (line
!= 0 && at_commandline
))
25007 complaint (_("debug info gives %s macro %s with %s line %d: %s"),
25008 at_commandline
? _("command-line") : _("in-file"),
25009 is_define
? _("definition") : _("undefinition"),
25010 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
25014 /* Fedora's rpm-build's "debugedit" binary
25015 corrupted .debug_macro sections.
25018 https://bugzilla.redhat.com/show_bug.cgi?id=1708786 */
25019 complaint (_("debug info gives %s invalid macro %s "
25020 "without body (corrupted?) at line %d "
25022 at_commandline
? _("command-line") : _("in-file"),
25023 is_define
? _("definition") : _("undefinition"),
25024 line
, current_file
->filename
);
25026 else if (is_define
)
25027 parse_macro_definition (current_file
, line
, body
);
25030 gdb_assert (macinfo_type
== DW_MACRO_undef
25031 || macinfo_type
== DW_MACRO_undef_strp
25032 || macinfo_type
== DW_MACRO_undef_sup
);
25033 macro_undef (current_file
, line
, body
);
25038 case DW_MACRO_start_file
:
25040 unsigned int bytes_read
;
25043 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25044 mac_ptr
+= bytes_read
;
25045 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25046 mac_ptr
+= bytes_read
;
25048 if ((line
== 0 && !at_commandline
)
25049 || (line
!= 0 && at_commandline
))
25050 complaint (_("debug info gives source %d included "
25051 "from %s at %s line %d"),
25052 file
, at_commandline
? _("command-line") : _("file"),
25053 line
== 0 ? _("zero") : _("non-zero"), line
);
25055 if (at_commandline
)
25057 /* This DW_MACRO_start_file was executed in the
25059 at_commandline
= 0;
25062 current_file
= macro_start_file (cu
, file
, line
, current_file
,
25067 case DW_MACRO_end_file
:
25068 if (! current_file
)
25069 complaint (_("macro debug info has an unmatched "
25070 "`close_file' directive"));
25073 current_file
= current_file
->included_by
;
25074 if (! current_file
)
25076 enum dwarf_macro_record_type next_type
;
25078 /* GCC circa March 2002 doesn't produce the zero
25079 type byte marking the end of the compilation
25080 unit. Complain if it's not there, but exit no
25083 /* Do we at least have room for a macinfo type byte? */
25084 if (mac_ptr
>= mac_end
)
25086 dwarf2_section_buffer_overflow_complaint (section
);
25090 /* We don't increment mac_ptr here, so this is just
25093 = (enum dwarf_macro_record_type
) read_1_byte (abfd
,
25095 if (next_type
!= 0)
25096 complaint (_("no terminating 0-type entry for "
25097 "macros in `.debug_macinfo' section"));
25104 case DW_MACRO_import
:
25105 case DW_MACRO_import_sup
:
25109 bfd
*include_bfd
= abfd
;
25110 struct dwarf2_section_info
*include_section
= section
;
25111 const gdb_byte
*include_mac_end
= mac_end
;
25112 int is_dwz
= section_is_dwz
;
25113 const gdb_byte
*new_mac_ptr
;
25115 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
25116 mac_ptr
+= offset_size
;
25118 if (macinfo_type
== DW_MACRO_import_sup
)
25120 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
25122 dwarf2_read_section (objfile
, &dwz
->macro
);
25124 include_section
= &dwz
->macro
;
25125 include_bfd
= get_section_bfd_owner (include_section
);
25126 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
25130 new_mac_ptr
= include_section
->buffer
+ offset
;
25131 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
25135 /* This has actually happened; see
25136 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
25137 complaint (_("recursive DW_MACRO_import in "
25138 ".debug_macro section"));
25142 *slot
= (void *) new_mac_ptr
;
25144 dwarf_decode_macro_bytes (cu
, include_bfd
, new_mac_ptr
,
25145 include_mac_end
, current_file
, lh
,
25146 section
, section_is_gnu
, is_dwz
,
25147 offset_size
, include_hash
);
25149 htab_remove_elt (include_hash
, (void *) new_mac_ptr
);
25154 case DW_MACINFO_vendor_ext
:
25155 if (!section_is_gnu
)
25157 unsigned int bytes_read
;
25159 /* This reads the constant, but since we don't recognize
25160 any vendor extensions, we ignore it. */
25161 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25162 mac_ptr
+= bytes_read
;
25163 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
25164 mac_ptr
+= bytes_read
;
25166 /* We don't recognize any vendor extensions. */
25172 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
25173 mac_ptr
, mac_end
, abfd
, offset_size
,
25175 if (mac_ptr
== NULL
)
25180 } while (macinfo_type
!= 0);
25184 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
25185 int section_is_gnu
)
25187 struct dwarf2_per_objfile
*dwarf2_per_objfile
25188 = cu
->per_cu
->dwarf2_per_objfile
;
25189 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25190 struct line_header
*lh
= cu
->line_header
;
25192 const gdb_byte
*mac_ptr
, *mac_end
;
25193 struct macro_source_file
*current_file
= 0;
25194 enum dwarf_macro_record_type macinfo_type
;
25195 unsigned int offset_size
= cu
->header
.offset_size
;
25196 const gdb_byte
*opcode_definitions
[256];
25198 struct dwarf2_section_info
*section
;
25199 const char *section_name
;
25201 if (cu
->dwo_unit
!= NULL
)
25203 if (section_is_gnu
)
25205 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
25206 section_name
= ".debug_macro.dwo";
25210 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
25211 section_name
= ".debug_macinfo.dwo";
25216 if (section_is_gnu
)
25218 section
= &dwarf2_per_objfile
->macro
;
25219 section_name
= ".debug_macro";
25223 section
= &dwarf2_per_objfile
->macinfo
;
25224 section_name
= ".debug_macinfo";
25228 dwarf2_read_section (objfile
, section
);
25229 if (section
->buffer
== NULL
)
25231 complaint (_("missing %s section"), section_name
);
25234 abfd
= get_section_bfd_owner (section
);
25236 /* First pass: Find the name of the base filename.
25237 This filename is needed in order to process all macros whose definition
25238 (or undefinition) comes from the command line. These macros are defined
25239 before the first DW_MACINFO_start_file entry, and yet still need to be
25240 associated to the base file.
25242 To determine the base file name, we scan the macro definitions until we
25243 reach the first DW_MACINFO_start_file entry. We then initialize
25244 CURRENT_FILE accordingly so that any macro definition found before the
25245 first DW_MACINFO_start_file can still be associated to the base file. */
25247 mac_ptr
= section
->buffer
+ offset
;
25248 mac_end
= section
->buffer
+ section
->size
;
25250 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
25251 &offset_size
, section_is_gnu
);
25252 if (mac_ptr
== NULL
)
25254 /* We already issued a complaint. */
25260 /* Do we at least have room for a macinfo type byte? */
25261 if (mac_ptr
>= mac_end
)
25263 /* Complaint is printed during the second pass as GDB will probably
25264 stop the first pass earlier upon finding
25265 DW_MACINFO_start_file. */
25269 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
25272 /* Note that we rely on the fact that the corresponding GNU and
25273 DWARF constants are the same. */
25275 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
25276 switch (macinfo_type
)
25278 /* A zero macinfo type indicates the end of the macro
25283 case DW_MACRO_define
:
25284 case DW_MACRO_undef
:
25285 /* Only skip the data by MAC_PTR. */
25287 unsigned int bytes_read
;
25289 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25290 mac_ptr
+= bytes_read
;
25291 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
25292 mac_ptr
+= bytes_read
;
25296 case DW_MACRO_start_file
:
25298 unsigned int bytes_read
;
25301 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25302 mac_ptr
+= bytes_read
;
25303 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25304 mac_ptr
+= bytes_read
;
25306 current_file
= macro_start_file (cu
, file
, line
, current_file
, lh
);
25310 case DW_MACRO_end_file
:
25311 /* No data to skip by MAC_PTR. */
25314 case DW_MACRO_define_strp
:
25315 case DW_MACRO_undef_strp
:
25316 case DW_MACRO_define_sup
:
25317 case DW_MACRO_undef_sup
:
25319 unsigned int bytes_read
;
25321 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25322 mac_ptr
+= bytes_read
;
25323 mac_ptr
+= offset_size
;
25327 case DW_MACRO_import
:
25328 case DW_MACRO_import_sup
:
25329 /* Note that, according to the spec, a transparent include
25330 chain cannot call DW_MACRO_start_file. So, we can just
25331 skip this opcode. */
25332 mac_ptr
+= offset_size
;
25335 case DW_MACINFO_vendor_ext
:
25336 /* Only skip the data by MAC_PTR. */
25337 if (!section_is_gnu
)
25339 unsigned int bytes_read
;
25341 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25342 mac_ptr
+= bytes_read
;
25343 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
25344 mac_ptr
+= bytes_read
;
25349 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
25350 mac_ptr
, mac_end
, abfd
, offset_size
,
25352 if (mac_ptr
== NULL
)
25357 } while (macinfo_type
!= 0 && current_file
== NULL
);
25359 /* Second pass: Process all entries.
25361 Use the AT_COMMAND_LINE flag to determine whether we are still processing
25362 command-line macro definitions/undefinitions. This flag is unset when we
25363 reach the first DW_MACINFO_start_file entry. */
25365 htab_up
include_hash (htab_create_alloc (1, htab_hash_pointer
,
25367 NULL
, xcalloc
, xfree
));
25368 mac_ptr
= section
->buffer
+ offset
;
25369 slot
= htab_find_slot (include_hash
.get (), mac_ptr
, INSERT
);
25370 *slot
= (void *) mac_ptr
;
25371 dwarf_decode_macro_bytes (cu
, abfd
, mac_ptr
, mac_end
,
25372 current_file
, lh
, section
,
25373 section_is_gnu
, 0, offset_size
,
25374 include_hash
.get ());
25377 /* Check if the attribute's form is a DW_FORM_block*
25378 if so return true else false. */
25381 attr_form_is_block (const struct attribute
*attr
)
25383 return (attr
== NULL
? 0 :
25384 attr
->form
== DW_FORM_block1
25385 || attr
->form
== DW_FORM_block2
25386 || attr
->form
== DW_FORM_block4
25387 || attr
->form
== DW_FORM_block
25388 || attr
->form
== DW_FORM_exprloc
);
25391 /* Return non-zero if ATTR's value is a section offset --- classes
25392 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
25393 You may use DW_UNSND (attr) to retrieve such offsets.
25395 Section 7.5.4, "Attribute Encodings", explains that no attribute
25396 may have a value that belongs to more than one of these classes; it
25397 would be ambiguous if we did, because we use the same forms for all
25401 attr_form_is_section_offset (const struct attribute
*attr
)
25403 return (attr
->form
== DW_FORM_data4
25404 || attr
->form
== DW_FORM_data8
25405 || attr
->form
== DW_FORM_sec_offset
);
25408 /* Return non-zero if ATTR's value falls in the 'constant' class, or
25409 zero otherwise. When this function returns true, you can apply
25410 dwarf2_get_attr_constant_value to it.
25412 However, note that for some attributes you must check
25413 attr_form_is_section_offset before using this test. DW_FORM_data4
25414 and DW_FORM_data8 are members of both the constant class, and of
25415 the classes that contain offsets into other debug sections
25416 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
25417 that, if an attribute's can be either a constant or one of the
25418 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
25419 taken as section offsets, not constants.
25421 DW_FORM_data16 is not considered as dwarf2_get_attr_constant_value
25422 cannot handle that. */
25425 attr_form_is_constant (const struct attribute
*attr
)
25427 switch (attr
->form
)
25429 case DW_FORM_sdata
:
25430 case DW_FORM_udata
:
25431 case DW_FORM_data1
:
25432 case DW_FORM_data2
:
25433 case DW_FORM_data4
:
25434 case DW_FORM_data8
:
25435 case DW_FORM_implicit_const
:
25443 /* DW_ADDR is always stored already as sect_offset; despite for the forms
25444 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
25447 attr_form_is_ref (const struct attribute
*attr
)
25449 switch (attr
->form
)
25451 case DW_FORM_ref_addr
:
25456 case DW_FORM_ref_udata
:
25457 case DW_FORM_GNU_ref_alt
:
25464 /* Return the .debug_loc section to use for CU.
25465 For DWO files use .debug_loc.dwo. */
25467 static struct dwarf2_section_info
*
25468 cu_debug_loc_section (struct dwarf2_cu
*cu
)
25470 struct dwarf2_per_objfile
*dwarf2_per_objfile
25471 = cu
->per_cu
->dwarf2_per_objfile
;
25475 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
25477 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
25479 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
25480 : &dwarf2_per_objfile
->loc
);
25483 /* A helper function that fills in a dwarf2_loclist_baton. */
25486 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
25487 struct dwarf2_loclist_baton
*baton
,
25488 const struct attribute
*attr
)
25490 struct dwarf2_per_objfile
*dwarf2_per_objfile
25491 = cu
->per_cu
->dwarf2_per_objfile
;
25492 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
25494 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
25496 baton
->per_cu
= cu
->per_cu
;
25497 gdb_assert (baton
->per_cu
);
25498 /* We don't know how long the location list is, but make sure we
25499 don't run off the edge of the section. */
25500 baton
->size
= section
->size
- DW_UNSND (attr
);
25501 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
25502 baton
->base_address
= cu
->base_address
;
25503 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
25507 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
25508 struct dwarf2_cu
*cu
, int is_block
)
25510 struct dwarf2_per_objfile
*dwarf2_per_objfile
25511 = cu
->per_cu
->dwarf2_per_objfile
;
25512 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25513 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
25515 if (attr_form_is_section_offset (attr
)
25516 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
25517 the section. If so, fall through to the complaint in the
25519 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
25521 struct dwarf2_loclist_baton
*baton
;
25523 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
25525 fill_in_loclist_baton (cu
, baton
, attr
);
25527 if (cu
->base_known
== 0)
25528 complaint (_("Location list used without "
25529 "specifying the CU base address."));
25531 SYMBOL_ACLASS_INDEX (sym
) = (is_block
25532 ? dwarf2_loclist_block_index
25533 : dwarf2_loclist_index
);
25534 SYMBOL_LOCATION_BATON (sym
) = baton
;
25538 struct dwarf2_locexpr_baton
*baton
;
25540 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
25541 baton
->per_cu
= cu
->per_cu
;
25542 gdb_assert (baton
->per_cu
);
25544 if (attr_form_is_block (attr
))
25546 /* Note that we're just copying the block's data pointer
25547 here, not the actual data. We're still pointing into the
25548 info_buffer for SYM's objfile; right now we never release
25549 that buffer, but when we do clean up properly this may
25551 baton
->size
= DW_BLOCK (attr
)->size
;
25552 baton
->data
= DW_BLOCK (attr
)->data
;
25556 dwarf2_invalid_attrib_class_complaint ("location description",
25557 sym
->natural_name ());
25561 SYMBOL_ACLASS_INDEX (sym
) = (is_block
25562 ? dwarf2_locexpr_block_index
25563 : dwarf2_locexpr_index
);
25564 SYMBOL_LOCATION_BATON (sym
) = baton
;
25568 /* Return the OBJFILE associated with the compilation unit CU. If CU
25569 came from a separate debuginfo file, then the master objfile is
25573 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
25575 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
25577 /* Return the master objfile, so that we can report and look up the
25578 correct file containing this variable. */
25579 if (objfile
->separate_debug_objfile_backlink
)
25580 objfile
= objfile
->separate_debug_objfile_backlink
;
25585 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
25586 (CU_HEADERP is unused in such case) or prepare a temporary copy at
25587 CU_HEADERP first. */
25589 static const struct comp_unit_head
*
25590 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
25591 struct dwarf2_per_cu_data
*per_cu
)
25593 const gdb_byte
*info_ptr
;
25596 return &per_cu
->cu
->header
;
25598 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
25600 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
25601 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
25602 rcuh_kind::COMPILE
);
25607 /* Return the address size given in the compilation unit header for CU. */
25610 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
25612 struct comp_unit_head cu_header_local
;
25613 const struct comp_unit_head
*cu_headerp
;
25615 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25617 return cu_headerp
->addr_size
;
25620 /* Return the offset size given in the compilation unit header for CU. */
25623 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
25625 struct comp_unit_head cu_header_local
;
25626 const struct comp_unit_head
*cu_headerp
;
25628 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25630 return cu_headerp
->offset_size
;
25633 /* See its dwarf2loc.h declaration. */
25636 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
25638 struct comp_unit_head cu_header_local
;
25639 const struct comp_unit_head
*cu_headerp
;
25641 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25643 if (cu_headerp
->version
== 2)
25644 return cu_headerp
->addr_size
;
25646 return cu_headerp
->offset_size
;
25649 /* Return the text offset of the CU. The returned offset comes from
25650 this CU's objfile. If this objfile came from a separate debuginfo
25651 file, then the offset may be different from the corresponding
25652 offset in the parent objfile. */
25655 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
25657 return per_cu
->dwarf2_per_objfile
->objfile
->text_section_offset ();
25660 /* Return a type that is a generic pointer type, the size of which matches
25661 the address size given in the compilation unit header for PER_CU. */
25662 static struct type
*
25663 dwarf2_per_cu_addr_type (struct dwarf2_per_cu_data
*per_cu
)
25665 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
25666 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
25667 struct type
*addr_type
= lookup_pointer_type (void_type
);
25668 int addr_size
= dwarf2_per_cu_addr_size (per_cu
);
25670 if (TYPE_LENGTH (addr_type
) == addr_size
)
25674 = dwarf2_per_cu_addr_sized_int_type (per_cu
, TYPE_UNSIGNED (addr_type
));
25678 /* Return DWARF version number of PER_CU. */
25681 dwarf2_version (struct dwarf2_per_cu_data
*per_cu
)
25683 return per_cu
->dwarf_version
;
25686 /* Locate the .debug_info compilation unit from CU's objfile which contains
25687 the DIE at OFFSET. Raises an error on failure. */
25689 static struct dwarf2_per_cu_data
*
25690 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
25691 unsigned int offset_in_dwz
,
25692 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
25694 struct dwarf2_per_cu_data
*this_cu
;
25698 high
= dwarf2_per_objfile
->all_comp_units
.size () - 1;
25701 struct dwarf2_per_cu_data
*mid_cu
;
25702 int mid
= low
+ (high
- low
) / 2;
25704 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
25705 if (mid_cu
->is_dwz
> offset_in_dwz
25706 || (mid_cu
->is_dwz
== offset_in_dwz
25707 && mid_cu
->sect_off
+ mid_cu
->length
>= sect_off
))
25712 gdb_assert (low
== high
);
25713 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
25714 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
25716 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
25717 error (_("Dwarf Error: could not find partial DIE containing "
25718 "offset %s [in module %s]"),
25719 sect_offset_str (sect_off
),
25720 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
25722 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
25724 return dwarf2_per_objfile
->all_comp_units
[low
-1];
25728 if (low
== dwarf2_per_objfile
->all_comp_units
.size () - 1
25729 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
25730 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
25731 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
25736 /* Initialize dwarf2_cu CU, owned by PER_CU. */
25738 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data
*per_cu_
)
25739 : per_cu (per_cu_
),
25741 has_loclist (false),
25742 checked_producer (false),
25743 producer_is_gxx_lt_4_6 (false),
25744 producer_is_gcc_lt_4_3 (false),
25745 producer_is_icc (false),
25746 producer_is_icc_lt_14 (false),
25747 producer_is_codewarrior (false),
25748 processing_has_namespace_info (false)
25753 /* Destroy a dwarf2_cu. */
25755 dwarf2_cu::~dwarf2_cu ()
25760 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
25763 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
25764 enum language pretend_language
)
25766 struct attribute
*attr
;
25768 /* Set the language we're debugging. */
25769 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
25770 if (attr
!= nullptr)
25771 set_cu_language (DW_UNSND (attr
), cu
);
25774 cu
->language
= pretend_language
;
25775 cu
->language_defn
= language_def (cu
->language
);
25778 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
25781 /* Increase the age counter on each cached compilation unit, and free
25782 any that are too old. */
25785 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
25787 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25789 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
25790 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25791 while (per_cu
!= NULL
)
25793 per_cu
->cu
->last_used
++;
25794 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
25795 dwarf2_mark (per_cu
->cu
);
25796 per_cu
= per_cu
->cu
->read_in_chain
;
25799 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25800 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25801 while (per_cu
!= NULL
)
25803 struct dwarf2_per_cu_data
*next_cu
;
25805 next_cu
= per_cu
->cu
->read_in_chain
;
25807 if (!per_cu
->cu
->mark
)
25810 *last_chain
= next_cu
;
25813 last_chain
= &per_cu
->cu
->read_in_chain
;
25819 /* Remove a single compilation unit from the cache. */
25822 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
25824 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25825 struct dwarf2_per_objfile
*dwarf2_per_objfile
25826 = target_per_cu
->dwarf2_per_objfile
;
25828 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25829 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25830 while (per_cu
!= NULL
)
25832 struct dwarf2_per_cu_data
*next_cu
;
25834 next_cu
= per_cu
->cu
->read_in_chain
;
25836 if (per_cu
== target_per_cu
)
25840 *last_chain
= next_cu
;
25844 last_chain
= &per_cu
->cu
->read_in_chain
;
25850 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
25851 We store these in a hash table separate from the DIEs, and preserve them
25852 when the DIEs are flushed out of cache.
25854 The CU "per_cu" pointer is needed because offset alone is not enough to
25855 uniquely identify the type. A file may have multiple .debug_types sections,
25856 or the type may come from a DWO file. Furthermore, while it's more logical
25857 to use per_cu->section+offset, with Fission the section with the data is in
25858 the DWO file but we don't know that section at the point we need it.
25859 We have to use something in dwarf2_per_cu_data (or the pointer to it)
25860 because we can enter the lookup routine, get_die_type_at_offset, from
25861 outside this file, and thus won't necessarily have PER_CU->cu.
25862 Fortunately, PER_CU is stable for the life of the objfile. */
25864 struct dwarf2_per_cu_offset_and_type
25866 const struct dwarf2_per_cu_data
*per_cu
;
25867 sect_offset sect_off
;
25871 /* Hash function for a dwarf2_per_cu_offset_and_type. */
25874 per_cu_offset_and_type_hash (const void *item
)
25876 const struct dwarf2_per_cu_offset_and_type
*ofs
25877 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
25879 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
25882 /* Equality function for a dwarf2_per_cu_offset_and_type. */
25885 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
25887 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
25888 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
25889 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
25890 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
25892 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
25893 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
25896 /* Set the type associated with DIE to TYPE. Save it in CU's hash
25897 table if necessary. For convenience, return TYPE.
25899 The DIEs reading must have careful ordering to:
25900 * Not cause infinite loops trying to read in DIEs as a prerequisite for
25901 reading current DIE.
25902 * Not trying to dereference contents of still incompletely read in types
25903 while reading in other DIEs.
25904 * Enable referencing still incompletely read in types just by a pointer to
25905 the type without accessing its fields.
25907 Therefore caller should follow these rules:
25908 * Try to fetch any prerequisite types we may need to build this DIE type
25909 before building the type and calling set_die_type.
25910 * After building type call set_die_type for current DIE as soon as
25911 possible before fetching more types to complete the current type.
25912 * Make the type as complete as possible before fetching more types. */
25914 static struct type
*
25915 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
25917 struct dwarf2_per_objfile
*dwarf2_per_objfile
25918 = cu
->per_cu
->dwarf2_per_objfile
;
25919 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
25920 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25921 struct attribute
*attr
;
25922 struct dynamic_prop prop
;
25924 /* For Ada types, make sure that the gnat-specific data is always
25925 initialized (if not already set). There are a few types where
25926 we should not be doing so, because the type-specific area is
25927 already used to hold some other piece of info (eg: TYPE_CODE_FLT
25928 where the type-specific area is used to store the floatformat).
25929 But this is not a problem, because the gnat-specific information
25930 is actually not needed for these types. */
25931 if (need_gnat_info (cu
)
25932 && TYPE_CODE (type
) != TYPE_CODE_FUNC
25933 && TYPE_CODE (type
) != TYPE_CODE_FLT
25934 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
25935 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
25936 && TYPE_CODE (type
) != TYPE_CODE_METHOD
25937 && !HAVE_GNAT_AUX_INFO (type
))
25938 INIT_GNAT_SPECIFIC (type
);
25940 /* Read DW_AT_allocated and set in type. */
25941 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
25942 if (attr_form_is_block (attr
))
25944 struct type
*prop_type
25945 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
25946 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
25947 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
);
25949 else if (attr
!= NULL
)
25951 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
25952 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25953 sect_offset_str (die
->sect_off
));
25956 /* Read DW_AT_associated and set in type. */
25957 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
25958 if (attr_form_is_block (attr
))
25960 struct type
*prop_type
25961 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
25962 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
25963 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
);
25965 else if (attr
!= NULL
)
25967 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
25968 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25969 sect_offset_str (die
->sect_off
));
25972 /* Read DW_AT_data_location and set in type. */
25973 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
25974 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
,
25975 dwarf2_per_cu_addr_type (cu
->per_cu
)))
25976 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
);
25978 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25980 dwarf2_per_objfile
->die_type_hash
=
25981 htab_create_alloc_ex (127,
25982 per_cu_offset_and_type_hash
,
25983 per_cu_offset_and_type_eq
,
25985 &objfile
->objfile_obstack
,
25986 hashtab_obstack_allocate
,
25987 dummy_obstack_deallocate
);
25990 ofs
.per_cu
= cu
->per_cu
;
25991 ofs
.sect_off
= die
->sect_off
;
25993 slot
= (struct dwarf2_per_cu_offset_and_type
**)
25994 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
25996 complaint (_("A problem internal to GDB: DIE %s has type already set"),
25997 sect_offset_str (die
->sect_off
));
25998 *slot
= XOBNEW (&objfile
->objfile_obstack
,
25999 struct dwarf2_per_cu_offset_and_type
);
26004 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
26005 or return NULL if the die does not have a saved type. */
26007 static struct type
*
26008 get_die_type_at_offset (sect_offset sect_off
,
26009 struct dwarf2_per_cu_data
*per_cu
)
26011 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
26012 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
26014 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
26017 ofs
.per_cu
= per_cu
;
26018 ofs
.sect_off
= sect_off
;
26019 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
26020 htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
));
26027 /* Look up the type for DIE in CU in die_type_hash,
26028 or return NULL if DIE does not have a saved type. */
26030 static struct type
*
26031 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
26033 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
26036 /* Add a dependence relationship from CU to REF_PER_CU. */
26039 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
26040 struct dwarf2_per_cu_data
*ref_per_cu
)
26044 if (cu
->dependencies
== NULL
)
26046 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
26047 NULL
, &cu
->comp_unit_obstack
,
26048 hashtab_obstack_allocate
,
26049 dummy_obstack_deallocate
);
26051 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
26053 *slot
= ref_per_cu
;
26056 /* Subroutine of dwarf2_mark to pass to htab_traverse.
26057 Set the mark field in every compilation unit in the
26058 cache that we must keep because we are keeping CU. */
26061 dwarf2_mark_helper (void **slot
, void *data
)
26063 struct dwarf2_per_cu_data
*per_cu
;
26065 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
26067 /* cu->dependencies references may not yet have been ever read if QUIT aborts
26068 reading of the chain. As such dependencies remain valid it is not much
26069 useful to track and undo them during QUIT cleanups. */
26070 if (per_cu
->cu
== NULL
)
26073 if (per_cu
->cu
->mark
)
26075 per_cu
->cu
->mark
= true;
26077 if (per_cu
->cu
->dependencies
!= NULL
)
26078 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
26083 /* Set the mark field in CU and in every other compilation unit in the
26084 cache that we must keep because we are keeping CU. */
26087 dwarf2_mark (struct dwarf2_cu
*cu
)
26092 if (cu
->dependencies
!= NULL
)
26093 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
26097 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
26101 per_cu
->cu
->mark
= false;
26102 per_cu
= per_cu
->cu
->read_in_chain
;
26106 /* Trivial hash function for partial_die_info: the hash value of a DIE
26107 is its offset in .debug_info for this objfile. */
26110 partial_die_hash (const void *item
)
26112 const struct partial_die_info
*part_die
26113 = (const struct partial_die_info
*) item
;
26115 return to_underlying (part_die
->sect_off
);
26118 /* Trivial comparison function for partial_die_info structures: two DIEs
26119 are equal if they have the same offset. */
26122 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
26124 const struct partial_die_info
*part_die_lhs
26125 = (const struct partial_die_info
*) item_lhs
;
26126 const struct partial_die_info
*part_die_rhs
26127 = (const struct partial_die_info
*) item_rhs
;
26129 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
26132 struct cmd_list_element
*set_dwarf_cmdlist
;
26133 struct cmd_list_element
*show_dwarf_cmdlist
;
26136 set_dwarf_cmd (const char *args
, int from_tty
)
26138 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
26143 show_dwarf_cmd (const char *args
, int from_tty
)
26145 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
26148 bool dwarf_always_disassemble
;
26151 show_dwarf_always_disassemble (struct ui_file
*file
, int from_tty
,
26152 struct cmd_list_element
*c
, const char *value
)
26154 fprintf_filtered (file
,
26155 _("Whether to always disassemble "
26156 "DWARF expressions is %s.\n"),
26161 show_check_physname (struct ui_file
*file
, int from_tty
,
26162 struct cmd_list_element
*c
, const char *value
)
26164 fprintf_filtered (file
,
26165 _("Whether to check \"physname\" is %s.\n"),
26169 void _initialize_dwarf2_read ();
26171 _initialize_dwarf2_read ()
26173 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
26174 Set DWARF specific variables.\n\
26175 Configure DWARF variables such as the cache size."),
26176 &set_dwarf_cmdlist
, "maintenance set dwarf ",
26177 0/*allow-unknown*/, &maintenance_set_cmdlist
);
26179 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
26180 Show DWARF specific variables.\n\
26181 Show DWARF variables such as the cache size."),
26182 &show_dwarf_cmdlist
, "maintenance show dwarf ",
26183 0/*allow-unknown*/, &maintenance_show_cmdlist
);
26185 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
26186 &dwarf_max_cache_age
, _("\
26187 Set the upper bound on the age of cached DWARF compilation units."), _("\
26188 Show the upper bound on the age of cached DWARF compilation units."), _("\
26189 A higher limit means that cached compilation units will be stored\n\
26190 in memory longer, and more total memory will be used. Zero disables\n\
26191 caching, which can slow down startup."),
26193 show_dwarf_max_cache_age
,
26194 &set_dwarf_cmdlist
,
26195 &show_dwarf_cmdlist
);
26197 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
26198 &dwarf_always_disassemble
, _("\
26199 Set whether `info address' always disassembles DWARF expressions."), _("\
26200 Show whether `info address' always disassembles DWARF expressions."), _("\
26201 When enabled, DWARF expressions are always printed in an assembly-like\n\
26202 syntax. When disabled, expressions will be printed in a more\n\
26203 conversational style, when possible."),
26205 show_dwarf_always_disassemble
,
26206 &set_dwarf_cmdlist
,
26207 &show_dwarf_cmdlist
);
26209 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
26210 Set debugging of the DWARF reader."), _("\
26211 Show debugging of the DWARF reader."), _("\
26212 When enabled (non-zero), debugging messages are printed during DWARF\n\
26213 reading and symtab expansion. A value of 1 (one) provides basic\n\
26214 information. A value greater than 1 provides more verbose information."),
26217 &setdebuglist
, &showdebuglist
);
26219 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
26220 Set debugging of the DWARF DIE reader."), _("\
26221 Show debugging of the DWARF DIE reader."), _("\
26222 When enabled (non-zero), DIEs are dumped after they are read in.\n\
26223 The value is the maximum depth to print."),
26226 &setdebuglist
, &showdebuglist
);
26228 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
26229 Set debugging of the dwarf line reader."), _("\
26230 Show debugging of the dwarf line reader."), _("\
26231 When enabled (non-zero), line number entries are dumped as they are read in.\n\
26232 A value of 1 (one) provides basic information.\n\
26233 A value greater than 1 provides more verbose information."),
26236 &setdebuglist
, &showdebuglist
);
26238 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
26239 Set cross-checking of \"physname\" code against demangler."), _("\
26240 Show cross-checking of \"physname\" code against demangler."), _("\
26241 When enabled, GDB's internal \"physname\" code is checked against\n\
26243 NULL
, show_check_physname
,
26244 &setdebuglist
, &showdebuglist
);
26246 add_setshow_boolean_cmd ("use-deprecated-index-sections",
26247 no_class
, &use_deprecated_index_sections
, _("\
26248 Set whether to use deprecated gdb_index sections."), _("\
26249 Show whether to use deprecated gdb_index sections."), _("\
26250 When enabled, deprecated .gdb_index sections are used anyway.\n\
26251 Normally they are ignored either because of a missing feature or\n\
26252 performance issue.\n\
26253 Warning: This option must be enabled before gdb reads the file."),
26256 &setlist
, &showlist
);
26258 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
26259 &dwarf2_locexpr_funcs
);
26260 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
26261 &dwarf2_loclist_funcs
);
26263 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
26264 &dwarf2_block_frame_base_locexpr_funcs
);
26265 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
26266 &dwarf2_block_frame_base_loclist_funcs
);
26269 selftests::register_test ("dw2_expand_symtabs_matching",
26270 selftests::dw2_expand_symtabs_matching::run_test
);