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 "dwarf2/read.h"
33 #include "dwarf2/abbrev.h"
34 #include "dwarf2/attribute.h"
35 #include "dwarf2/comp-unit.h"
36 #include "dwarf2/index-cache.h"
37 #include "dwarf2/index-common.h"
38 #include "dwarf2/leb.h"
39 #include "dwarf2/line-header.h"
48 #include "gdb-demangle.h"
49 #include "filenames.h" /* for DOSish file names */
52 #include "complaints.h"
53 #include "dwarf2/expr.h"
54 #include "dwarf2/loc.h"
55 #include "cp-support.h"
61 #include "typeprint.h"
66 #include "gdbcore.h" /* for gnutarget */
67 #include "gdb/gdb-index.h"
72 #include "namespace.h"
73 #include "gdbsupport/function-view.h"
74 #include "gdbsupport/gdb_optional.h"
75 #include "gdbsupport/underlying.h"
76 #include "gdbsupport/hash_enum.h"
77 #include "filename-seen-cache.h"
81 #include <unordered_map>
82 #include "gdbsupport/selftest.h"
83 #include "rust-lang.h"
84 #include "gdbsupport/pathstuff.h"
86 /* When == 1, print basic high level tracing messages.
87 When > 1, be more verbose.
88 This is in contrast to the low level DIE reading of dwarf_die_debug. */
89 static unsigned int dwarf_read_debug
= 0;
91 /* When non-zero, dump DIEs after they are read in. */
92 static unsigned int dwarf_die_debug
= 0;
94 /* When non-zero, dump line number entries as they are read in. */
95 unsigned int dwarf_line_debug
= 0;
97 /* When true, cross-check physname against demangler. */
98 static bool check_physname
= false;
100 /* When true, do not reject deprecated .gdb_index sections. */
101 static bool use_deprecated_index_sections
= false;
103 static const struct objfile_key
<dwarf2_per_objfile
> dwarf2_objfile_data_key
;
105 /* The "aclass" indices for various kinds of computed DWARF symbols. */
107 static int dwarf2_locexpr_index
;
108 static int dwarf2_loclist_index
;
109 static int dwarf2_locexpr_block_index
;
110 static int dwarf2_loclist_block_index
;
112 /* An index into a (C++) symbol name component in a symbol name as
113 recorded in the mapped_index's symbol table. For each C++ symbol
114 in the symbol table, we record one entry for the start of each
115 component in the symbol in a table of name components, and then
116 sort the table, in order to be able to binary search symbol names,
117 ignoring leading namespaces, both completion and regular look up.
118 For example, for symbol "A::B::C", we'll have an entry that points
119 to "A::B::C", another that points to "B::C", and another for "C".
120 Note that function symbols in GDB index have no parameter
121 information, just the function/method names. You can convert a
122 name_component to a "const char *" using the
123 'mapped_index::symbol_name_at(offset_type)' method. */
125 struct name_component
127 /* Offset in the symbol name where the component starts. Stored as
128 a (32-bit) offset instead of a pointer to save memory and improve
129 locality on 64-bit architectures. */
130 offset_type name_offset
;
132 /* The symbol's index in the symbol and constant pool tables of a
137 /* Base class containing bits shared by both .gdb_index and
138 .debug_name indexes. */
140 struct mapped_index_base
142 mapped_index_base () = default;
143 DISABLE_COPY_AND_ASSIGN (mapped_index_base
);
145 /* The name_component table (a sorted vector). See name_component's
146 description above. */
147 std::vector
<name_component
> name_components
;
149 /* How NAME_COMPONENTS is sorted. */
150 enum case_sensitivity name_components_casing
;
152 /* Return the number of names in the symbol table. */
153 virtual size_t symbol_name_count () const = 0;
155 /* Get the name of the symbol at IDX in the symbol table. */
156 virtual const char *symbol_name_at (offset_type idx
) const = 0;
158 /* Return whether the name at IDX in the symbol table should be
160 virtual bool symbol_name_slot_invalid (offset_type idx
) const
165 /* Build the symbol name component sorted vector, if we haven't
167 void build_name_components ();
169 /* Returns the lower (inclusive) and upper (exclusive) bounds of the
170 possible matches for LN_NO_PARAMS in the name component
172 std::pair
<std::vector
<name_component
>::const_iterator
,
173 std::vector
<name_component
>::const_iterator
>
174 find_name_components_bounds (const lookup_name_info
&ln_no_params
,
175 enum language lang
) const;
177 /* Prevent deleting/destroying via a base class pointer. */
179 ~mapped_index_base() = default;
182 /* A description of the mapped index. The file format is described in
183 a comment by the code that writes the index. */
184 struct mapped_index final
: public mapped_index_base
186 /* A slot/bucket in the symbol table hash. */
187 struct symbol_table_slot
189 const offset_type name
;
190 const offset_type vec
;
193 /* Index data format version. */
196 /* The address table data. */
197 gdb::array_view
<const gdb_byte
> address_table
;
199 /* The symbol table, implemented as a hash table. */
200 gdb::array_view
<symbol_table_slot
> symbol_table
;
202 /* A pointer to the constant pool. */
203 const char *constant_pool
= nullptr;
205 bool symbol_name_slot_invalid (offset_type idx
) const override
207 const auto &bucket
= this->symbol_table
[idx
];
208 return bucket
.name
== 0 && bucket
.vec
== 0;
211 /* Convenience method to get at the name of the symbol at IDX in the
213 const char *symbol_name_at (offset_type idx
) const override
214 { return this->constant_pool
+ MAYBE_SWAP (this->symbol_table
[idx
].name
); }
216 size_t symbol_name_count () const override
217 { return this->symbol_table
.size (); }
220 /* A description of the mapped .debug_names.
221 Uninitialized map has CU_COUNT 0. */
222 struct mapped_debug_names final
: public mapped_index_base
224 mapped_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile_
)
225 : dwarf2_per_objfile (dwarf2_per_objfile_
)
228 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
229 bfd_endian dwarf5_byte_order
;
230 bool dwarf5_is_dwarf64
;
231 bool augmentation_is_gdb
;
233 uint32_t cu_count
= 0;
234 uint32_t tu_count
, bucket_count
, name_count
;
235 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
236 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
237 const gdb_byte
*name_table_string_offs_reordered
;
238 const gdb_byte
*name_table_entry_offs_reordered
;
239 const gdb_byte
*entry_pool
;
246 /* Attribute name DW_IDX_*. */
249 /* Attribute form DW_FORM_*. */
252 /* Value if FORM is DW_FORM_implicit_const. */
253 LONGEST implicit_const
;
255 std::vector
<attr
> attr_vec
;
258 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
260 const char *namei_to_name (uint32_t namei
) const;
262 /* Implementation of the mapped_index_base virtual interface, for
263 the name_components cache. */
265 const char *symbol_name_at (offset_type idx
) const override
266 { return namei_to_name (idx
); }
268 size_t symbol_name_count () const override
269 { return this->name_count
; }
272 /* See dwarf2read.h. */
275 get_dwarf2_per_objfile (struct objfile
*objfile
)
277 return dwarf2_objfile_data_key
.get (objfile
);
280 /* Default names of the debugging sections. */
282 /* Note that if the debugging section has been compressed, it might
283 have a name like .zdebug_info. */
285 static const struct dwarf2_debug_sections dwarf2_elf_names
=
287 { ".debug_info", ".zdebug_info" },
288 { ".debug_abbrev", ".zdebug_abbrev" },
289 { ".debug_line", ".zdebug_line" },
290 { ".debug_loc", ".zdebug_loc" },
291 { ".debug_loclists", ".zdebug_loclists" },
292 { ".debug_macinfo", ".zdebug_macinfo" },
293 { ".debug_macro", ".zdebug_macro" },
294 { ".debug_str", ".zdebug_str" },
295 { ".debug_str_offsets", ".zdebug_str_offsets" },
296 { ".debug_line_str", ".zdebug_line_str" },
297 { ".debug_ranges", ".zdebug_ranges" },
298 { ".debug_rnglists", ".zdebug_rnglists" },
299 { ".debug_types", ".zdebug_types" },
300 { ".debug_addr", ".zdebug_addr" },
301 { ".debug_frame", ".zdebug_frame" },
302 { ".eh_frame", NULL
},
303 { ".gdb_index", ".zgdb_index" },
304 { ".debug_names", ".zdebug_names" },
305 { ".debug_aranges", ".zdebug_aranges" },
309 /* List of DWO/DWP sections. */
311 static const struct dwop_section_names
313 struct dwarf2_section_names abbrev_dwo
;
314 struct dwarf2_section_names info_dwo
;
315 struct dwarf2_section_names line_dwo
;
316 struct dwarf2_section_names loc_dwo
;
317 struct dwarf2_section_names loclists_dwo
;
318 struct dwarf2_section_names macinfo_dwo
;
319 struct dwarf2_section_names macro_dwo
;
320 struct dwarf2_section_names str_dwo
;
321 struct dwarf2_section_names str_offsets_dwo
;
322 struct dwarf2_section_names types_dwo
;
323 struct dwarf2_section_names cu_index
;
324 struct dwarf2_section_names tu_index
;
328 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
329 { ".debug_info.dwo", ".zdebug_info.dwo" },
330 { ".debug_line.dwo", ".zdebug_line.dwo" },
331 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
332 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
333 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
334 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
335 { ".debug_str.dwo", ".zdebug_str.dwo" },
336 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
337 { ".debug_types.dwo", ".zdebug_types.dwo" },
338 { ".debug_cu_index", ".zdebug_cu_index" },
339 { ".debug_tu_index", ".zdebug_tu_index" },
342 /* local data types */
344 /* Type used for delaying computation of method physnames.
345 See comments for compute_delayed_physnames. */
346 struct delayed_method_info
348 /* The type to which the method is attached, i.e., its parent class. */
351 /* The index of the method in the type's function fieldlists. */
354 /* The index of the method in the fieldlist. */
357 /* The name of the DIE. */
360 /* The DIE associated with this method. */
361 struct die_info
*die
;
364 /* Internal state when decoding a particular compilation unit. */
367 explicit dwarf2_cu (struct dwarf2_per_cu_data
*per_cu
);
370 DISABLE_COPY_AND_ASSIGN (dwarf2_cu
);
372 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
373 Create the set of symtabs used by this TU, or if this TU is sharing
374 symtabs with another TU and the symtabs have already been created
375 then restore those symtabs in the line header.
376 We don't need the pc/line-number mapping for type units. */
377 void setup_type_unit_groups (struct die_info
*die
);
379 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
380 buildsym_compunit constructor. */
381 struct compunit_symtab
*start_symtab (const char *name
,
382 const char *comp_dir
,
385 /* Reset the builder. */
386 void reset_builder () { m_builder
.reset (); }
388 /* The header of the compilation unit. */
389 struct comp_unit_head header
{};
391 /* Base address of this compilation unit. */
392 CORE_ADDR base_address
= 0;
394 /* Non-zero if base_address has been set. */
397 /* The language we are debugging. */
398 enum language language
= language_unknown
;
399 const struct language_defn
*language_defn
= nullptr;
401 const char *producer
= nullptr;
404 /* The symtab builder for this CU. This is only non-NULL when full
405 symbols are being read. */
406 std::unique_ptr
<buildsym_compunit
> m_builder
;
409 /* The generic symbol table building routines have separate lists for
410 file scope symbols and all all other scopes (local scopes). So
411 we need to select the right one to pass to add_symbol_to_list().
412 We do it by keeping a pointer to the correct list in list_in_scope.
414 FIXME: The original dwarf code just treated the file scope as the
415 first local scope, and all other local scopes as nested local
416 scopes, and worked fine. Check to see if we really need to
417 distinguish these in buildsym.c. */
418 struct pending
**list_in_scope
= nullptr;
420 /* Hash table holding all the loaded partial DIEs
421 with partial_die->offset.SECT_OFF as hash. */
422 htab_t partial_dies
= nullptr;
424 /* Storage for things with the same lifetime as this read-in compilation
425 unit, including partial DIEs. */
426 auto_obstack comp_unit_obstack
;
428 /* When multiple dwarf2_cu structures are living in memory, this field
429 chains them all together, so that they can be released efficiently.
430 We will probably also want a generation counter so that most-recently-used
431 compilation units are cached... */
432 struct dwarf2_per_cu_data
*read_in_chain
= nullptr;
434 /* Backlink to our per_cu entry. */
435 struct dwarf2_per_cu_data
*per_cu
;
437 /* How many compilation units ago was this CU last referenced? */
440 /* A hash table of DIE cu_offset for following references with
441 die_info->offset.sect_off as hash. */
442 htab_t die_hash
= nullptr;
444 /* Full DIEs if read in. */
445 struct die_info
*dies
= nullptr;
447 /* A set of pointers to dwarf2_per_cu_data objects for compilation
448 units referenced by this one. Only set during full symbol processing;
449 partial symbol tables do not have dependencies. */
450 htab_t dependencies
= nullptr;
452 /* Header data from the line table, during full symbol processing. */
453 struct line_header
*line_header
= nullptr;
454 /* Non-NULL if LINE_HEADER is owned by this DWARF_CU. Otherwise,
455 it's owned by dwarf2_per_objfile::line_header_hash. If non-NULL,
456 this is the DW_TAG_compile_unit die for this CU. We'll hold on
457 to the line header as long as this DIE is being processed. See
458 process_die_scope. */
459 die_info
*line_header_die_owner
= nullptr;
461 /* A list of methods which need to have physnames computed
462 after all type information has been read. */
463 std::vector
<delayed_method_info
> method_list
;
465 /* To be copied to symtab->call_site_htab. */
466 htab_t call_site_htab
= nullptr;
468 /* Non-NULL if this CU came from a DWO file.
469 There is an invariant here that is important to remember:
470 Except for attributes copied from the top level DIE in the "main"
471 (or "stub") file in preparation for reading the DWO file
472 (e.g., DW_AT_addr_base), we KISS: there is only *one* CU.
473 Either there isn't a DWO file (in which case this is NULL and the point
474 is moot), or there is and either we're not going to read it (in which
475 case this is NULL) or there is and we are reading it (in which case this
477 struct dwo_unit
*dwo_unit
= nullptr;
479 /* The DW_AT_addr_base (DW_AT_GNU_addr_base) attribute if present.
480 Note this value comes from the Fission stub CU/TU's DIE. */
481 gdb::optional
<ULONGEST
> addr_base
;
483 /* The DW_AT_rnglists_base attribute if present.
484 Note this value comes from the Fission stub CU/TU's DIE.
485 Also note that the value is zero in the non-DWO case so this value can
486 be used without needing to know whether DWO files are in use or not.
487 N.B. This does not apply to DW_AT_ranges appearing in
488 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
489 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
490 DW_AT_rnglists_base *would* have to be applied, and we'd have to care
491 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
492 ULONGEST ranges_base
= 0;
494 /* When reading debug info generated by older versions of rustc, we
495 have to rewrite some union types to be struct types with a
496 variant part. This rewriting must be done after the CU is fully
497 read in, because otherwise at the point of rewriting some struct
498 type might not have been fully processed. So, we keep a list of
499 all such types here and process them after expansion. */
500 std::vector
<struct type
*> rust_unions
;
502 /* The DW_AT_str_offsets_base attribute if present. For DWARF 4 version DWO
503 files, the value is implicitly zero. For DWARF 5 version DWO files, the
504 value is often implicit and is the size of the header of
505 .debug_str_offsets section (8 or 4, depending on the address size). */
506 gdb::optional
<ULONGEST
> str_offsets_base
;
508 /* Mark used when releasing cached dies. */
511 /* This CU references .debug_loc. See the symtab->locations_valid field.
512 This test is imperfect as there may exist optimized debug code not using
513 any location list and still facing inlining issues if handled as
514 unoptimized code. For a future better test see GCC PR other/32998. */
515 bool has_loclist
: 1;
517 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is true
518 if all the producer_is_* fields are valid. This information is cached
519 because profiling CU expansion showed excessive time spent in
520 producer_is_gxx_lt_4_6. */
521 bool checked_producer
: 1;
522 bool producer_is_gxx_lt_4_6
: 1;
523 bool producer_is_gcc_lt_4_3
: 1;
524 bool producer_is_icc
: 1;
525 bool producer_is_icc_lt_14
: 1;
526 bool producer_is_codewarrior
: 1;
528 /* When true, the file that we're processing is known to have
529 debugging info for C++ namespaces. GCC 3.3.x did not produce
530 this information, but later versions do. */
532 bool processing_has_namespace_info
: 1;
534 struct partial_die_info
*find_partial_die (sect_offset sect_off
);
536 /* If this CU was inherited by another CU (via specification,
537 abstract_origin, etc), this is the ancestor CU. */
540 /* Get the buildsym_compunit for this CU. */
541 buildsym_compunit
*get_builder ()
543 /* If this CU has a builder associated with it, use that. */
544 if (m_builder
!= nullptr)
545 return m_builder
.get ();
547 /* Otherwise, search ancestors for a valid builder. */
548 if (ancestor
!= nullptr)
549 return ancestor
->get_builder ();
555 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
556 This includes type_unit_group and quick_file_names. */
558 struct stmt_list_hash
560 /* The DWO unit this table is from or NULL if there is none. */
561 struct dwo_unit
*dwo_unit
;
563 /* Offset in .debug_line or .debug_line.dwo. */
564 sect_offset line_sect_off
;
567 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
568 an object of this type. */
570 struct type_unit_group
572 /* dwarf2read.c's main "handle" on a TU symtab.
573 To simplify things we create an artificial CU that "includes" all the
574 type units using this stmt_list so that the rest of the code still has
575 a "per_cu" handle on the symtab.
576 This PER_CU is recognized by having no section. */
577 #define IS_TYPE_UNIT_GROUP(per_cu) ((per_cu)->section == NULL)
578 struct dwarf2_per_cu_data per_cu
;
580 /* The TUs that share this DW_AT_stmt_list entry.
581 This is added to while parsing type units to build partial symtabs,
582 and is deleted afterwards and not used again. */
583 std::vector
<signatured_type
*> *tus
;
585 /* The compunit symtab.
586 Type units in a group needn't all be defined in the same source file,
587 so we create an essentially anonymous symtab as the compunit symtab. */
588 struct compunit_symtab
*compunit_symtab
;
590 /* The data used to construct the hash key. */
591 struct stmt_list_hash hash
;
593 /* The number of symtabs from the line header.
594 The value here must match line_header.num_file_names. */
595 unsigned int num_symtabs
;
597 /* The symbol tables for this TU (obtained from the files listed in
599 WARNING: The order of entries here must match the order of entries
600 in the line header. After the first TU using this type_unit_group, the
601 line header for the subsequent TUs is recreated from this. This is done
602 because we need to use the same symtabs for each TU using the same
603 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
604 there's no guarantee the line header doesn't have duplicate entries. */
605 struct symtab
**symtabs
;
608 /* These sections are what may appear in a (real or virtual) DWO file. */
612 struct dwarf2_section_info abbrev
;
613 struct dwarf2_section_info line
;
614 struct dwarf2_section_info loc
;
615 struct dwarf2_section_info loclists
;
616 struct dwarf2_section_info macinfo
;
617 struct dwarf2_section_info macro
;
618 struct dwarf2_section_info str
;
619 struct dwarf2_section_info str_offsets
;
620 /* In the case of a virtual DWO file, these two are unused. */
621 struct dwarf2_section_info info
;
622 std::vector
<dwarf2_section_info
> types
;
625 /* CUs/TUs in DWP/DWO files. */
629 /* Backlink to the containing struct dwo_file. */
630 struct dwo_file
*dwo_file
;
632 /* The "id" that distinguishes this CU/TU.
633 .debug_info calls this "dwo_id", .debug_types calls this "signature".
634 Since signatures came first, we stick with it for consistency. */
637 /* The section this CU/TU lives in, in the DWO file. */
638 struct dwarf2_section_info
*section
;
640 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
641 sect_offset sect_off
;
644 /* For types, offset in the type's DIE of the type defined by this TU. */
645 cu_offset type_offset_in_tu
;
648 /* include/dwarf2.h defines the DWP section codes.
649 It defines a max value but it doesn't define a min value, which we
650 use for error checking, so provide one. */
652 enum dwp_v2_section_ids
657 /* Data for one DWO file.
659 This includes virtual DWO files (a virtual DWO file is a DWO file as it
660 appears in a DWP file). DWP files don't really have DWO files per se -
661 comdat folding of types "loses" the DWO file they came from, and from
662 a high level view DWP files appear to contain a mass of random types.
663 However, to maintain consistency with the non-DWP case we pretend DWP
664 files contain virtual DWO files, and we assign each TU with one virtual
665 DWO file (generally based on the line and abbrev section offsets -
666 a heuristic that seems to work in practice). */
670 dwo_file () = default;
671 DISABLE_COPY_AND_ASSIGN (dwo_file
);
673 /* The DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute.
674 For virtual DWO files the name is constructed from the section offsets
675 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
676 from related CU+TUs. */
677 const char *dwo_name
= nullptr;
679 /* The DW_AT_comp_dir attribute. */
680 const char *comp_dir
= nullptr;
682 /* The bfd, when the file is open. Otherwise this is NULL.
683 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
684 gdb_bfd_ref_ptr dbfd
;
686 /* The sections that make up this DWO file.
687 Remember that for virtual DWO files in DWP V2, these are virtual
688 sections (for lack of a better name). */
689 struct dwo_sections sections
{};
691 /* The CUs in the file.
692 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
693 an extension to handle LLVM's Link Time Optimization output (where
694 multiple source files may be compiled into a single object/dwo pair). */
697 /* Table of TUs in the file.
698 Each element is a struct dwo_unit. */
702 /* These sections are what may appear in a DWP file. */
706 /* These are used by both DWP version 1 and 2. */
707 struct dwarf2_section_info str
;
708 struct dwarf2_section_info cu_index
;
709 struct dwarf2_section_info tu_index
;
711 /* These are only used by DWP version 2 files.
712 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
713 sections are referenced by section number, and are not recorded here.
714 In DWP version 2 there is at most one copy of all these sections, each
715 section being (effectively) comprised of the concatenation of all of the
716 individual sections that exist in the version 1 format.
717 To keep the code simple we treat each of these concatenated pieces as a
718 section itself (a virtual section?). */
719 struct dwarf2_section_info abbrev
;
720 struct dwarf2_section_info info
;
721 struct dwarf2_section_info line
;
722 struct dwarf2_section_info loc
;
723 struct dwarf2_section_info macinfo
;
724 struct dwarf2_section_info macro
;
725 struct dwarf2_section_info str_offsets
;
726 struct dwarf2_section_info types
;
729 /* These sections are what may appear in a virtual DWO file in DWP version 1.
730 A virtual DWO file is a DWO file as it appears in a DWP file. */
732 struct virtual_v1_dwo_sections
734 struct dwarf2_section_info abbrev
;
735 struct dwarf2_section_info line
;
736 struct dwarf2_section_info loc
;
737 struct dwarf2_section_info macinfo
;
738 struct dwarf2_section_info macro
;
739 struct dwarf2_section_info str_offsets
;
740 /* Each DWP hash table entry records one CU or one TU.
741 That is recorded here, and copied to dwo_unit.section. */
742 struct dwarf2_section_info info_or_types
;
745 /* Similar to virtual_v1_dwo_sections, but for DWP version 2.
746 In version 2, the sections of the DWO files are concatenated together
747 and stored in one section of that name. Thus each ELF section contains
748 several "virtual" sections. */
750 struct virtual_v2_dwo_sections
752 bfd_size_type abbrev_offset
;
753 bfd_size_type abbrev_size
;
755 bfd_size_type line_offset
;
756 bfd_size_type line_size
;
758 bfd_size_type loc_offset
;
759 bfd_size_type loc_size
;
761 bfd_size_type macinfo_offset
;
762 bfd_size_type macinfo_size
;
764 bfd_size_type macro_offset
;
765 bfd_size_type macro_size
;
767 bfd_size_type str_offsets_offset
;
768 bfd_size_type str_offsets_size
;
770 /* Each DWP hash table entry records one CU or one TU.
771 That is recorded here, and copied to dwo_unit.section. */
772 bfd_size_type info_or_types_offset
;
773 bfd_size_type info_or_types_size
;
776 /* Contents of DWP hash tables. */
778 struct dwp_hash_table
780 uint32_t version
, nr_columns
;
781 uint32_t nr_units
, nr_slots
;
782 const gdb_byte
*hash_table
, *unit_table
;
787 const gdb_byte
*indices
;
791 /* This is indexed by column number and gives the id of the section
793 #define MAX_NR_V2_DWO_SECTIONS \
794 (1 /* .debug_info or .debug_types */ \
795 + 1 /* .debug_abbrev */ \
796 + 1 /* .debug_line */ \
797 + 1 /* .debug_loc */ \
798 + 1 /* .debug_str_offsets */ \
799 + 1 /* .debug_macro or .debug_macinfo */)
800 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
801 const gdb_byte
*offsets
;
802 const gdb_byte
*sizes
;
807 /* Data for one DWP file. */
811 dwp_file (const char *name_
, gdb_bfd_ref_ptr
&&abfd
)
813 dbfd (std::move (abfd
))
817 /* Name of the file. */
820 /* File format version. */
824 gdb_bfd_ref_ptr dbfd
;
826 /* Section info for this file. */
827 struct dwp_sections sections
{};
829 /* Table of CUs in the file. */
830 const struct dwp_hash_table
*cus
= nullptr;
832 /* Table of TUs in the file. */
833 const struct dwp_hash_table
*tus
= nullptr;
835 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
839 /* Table to map ELF section numbers to their sections.
840 This is only needed for the DWP V1 file format. */
841 unsigned int num_sections
= 0;
842 asection
**elf_sections
= nullptr;
845 /* Struct used to pass misc. parameters to read_die_and_children, et
846 al. which are used for both .debug_info and .debug_types dies.
847 All parameters here are unchanging for the life of the call. This
848 struct exists to abstract away the constant parameters of die reading. */
850 struct die_reader_specs
852 /* The bfd of die_section. */
855 /* The CU of the DIE we are parsing. */
856 struct dwarf2_cu
*cu
;
858 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
859 struct dwo_file
*dwo_file
;
861 /* The section the die comes from.
862 This is either .debug_info or .debug_types, or the .dwo variants. */
863 struct dwarf2_section_info
*die_section
;
865 /* die_section->buffer. */
866 const gdb_byte
*buffer
;
868 /* The end of the buffer. */
869 const gdb_byte
*buffer_end
;
871 /* The abbreviation table to use when reading the DIEs. */
872 struct abbrev_table
*abbrev_table
;
875 /* A subclass of die_reader_specs that holds storage and has complex
876 constructor and destructor behavior. */
878 class cutu_reader
: public die_reader_specs
882 cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
883 struct abbrev_table
*abbrev_table
,
887 explicit cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
888 struct dwarf2_cu
*parent_cu
= nullptr,
889 struct dwo_file
*dwo_file
= nullptr);
891 DISABLE_COPY_AND_ASSIGN (cutu_reader
);
893 const gdb_byte
*info_ptr
= nullptr;
894 struct die_info
*comp_unit_die
= nullptr;
895 bool dummy_p
= false;
897 /* Release the new CU, putting it on the chain. This cannot be done
902 void init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
903 int use_existing_cu
);
905 struct dwarf2_per_cu_data
*m_this_cu
;
906 std::unique_ptr
<dwarf2_cu
> m_new_cu
;
908 /* The ordinary abbreviation table. */
909 abbrev_table_up m_abbrev_table_holder
;
911 /* The DWO abbreviation table. */
912 abbrev_table_up m_dwo_abbrev_table
;
915 /* When we construct a partial symbol table entry we only
916 need this much information. */
917 struct partial_die_info
: public allocate_on_obstack
919 partial_die_info (sect_offset sect_off
, struct abbrev_info
*abbrev
);
921 /* Disable assign but still keep copy ctor, which is needed
922 load_partial_dies. */
923 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
925 /* Adjust the partial die before generating a symbol for it. This
926 function may set the is_external flag or change the DIE's
928 void fixup (struct dwarf2_cu
*cu
);
930 /* Read a minimal amount of information into the minimal die
932 const gdb_byte
*read (const struct die_reader_specs
*reader
,
933 const struct abbrev_info
&abbrev
,
934 const gdb_byte
*info_ptr
);
936 /* Offset of this DIE. */
937 const sect_offset sect_off
;
939 /* DWARF-2 tag for this DIE. */
940 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
942 /* Assorted flags describing the data found in this DIE. */
943 const unsigned int has_children
: 1;
945 unsigned int is_external
: 1;
946 unsigned int is_declaration
: 1;
947 unsigned int has_type
: 1;
948 unsigned int has_specification
: 1;
949 unsigned int has_pc_info
: 1;
950 unsigned int may_be_inlined
: 1;
952 /* This DIE has been marked DW_AT_main_subprogram. */
953 unsigned int main_subprogram
: 1;
955 /* Flag set if the SCOPE field of this structure has been
957 unsigned int scope_set
: 1;
959 /* Flag set if the DIE has a byte_size attribute. */
960 unsigned int has_byte_size
: 1;
962 /* Flag set if the DIE has a DW_AT_const_value attribute. */
963 unsigned int has_const_value
: 1;
965 /* Flag set if any of the DIE's children are template arguments. */
966 unsigned int has_template_arguments
: 1;
968 /* Flag set if fixup has been called on this die. */
969 unsigned int fixup_called
: 1;
971 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
972 unsigned int is_dwz
: 1;
974 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
975 unsigned int spec_is_dwz
: 1;
977 /* The name of this DIE. Normally the value of DW_AT_name, but
978 sometimes a default name for unnamed DIEs. */
979 const char *name
= nullptr;
981 /* The linkage name, if present. */
982 const char *linkage_name
= nullptr;
984 /* The scope to prepend to our children. This is generally
985 allocated on the comp_unit_obstack, so will disappear
986 when this compilation unit leaves the cache. */
987 const char *scope
= nullptr;
989 /* Some data associated with the partial DIE. The tag determines
990 which field is live. */
993 /* The location description associated with this DIE, if any. */
994 struct dwarf_block
*locdesc
;
995 /* The offset of an import, for DW_TAG_imported_unit. */
996 sect_offset sect_off
;
999 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1000 CORE_ADDR lowpc
= 0;
1001 CORE_ADDR highpc
= 0;
1003 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1004 DW_AT_sibling, if any. */
1005 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1006 could return DW_AT_sibling values to its caller load_partial_dies. */
1007 const gdb_byte
*sibling
= nullptr;
1009 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1010 DW_AT_specification (or DW_AT_abstract_origin or
1011 DW_AT_extension). */
1012 sect_offset spec_offset
{};
1014 /* Pointers to this DIE's parent, first child, and next sibling,
1016 struct partial_die_info
*die_parent
= nullptr;
1017 struct partial_die_info
*die_child
= nullptr;
1018 struct partial_die_info
*die_sibling
= nullptr;
1020 friend struct partial_die_info
*
1021 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1024 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1025 partial_die_info (sect_offset sect_off
)
1026 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1030 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1032 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1037 has_specification
= 0;
1040 main_subprogram
= 0;
1043 has_const_value
= 0;
1044 has_template_arguments
= 0;
1051 /* This data structure holds a complete die structure. */
1054 /* DWARF-2 tag for this DIE. */
1055 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1057 /* Number of attributes */
1058 unsigned char num_attrs
;
1060 /* True if we're presently building the full type name for the
1061 type derived from this DIE. */
1062 unsigned char building_fullname
: 1;
1064 /* True if this die is in process. PR 16581. */
1065 unsigned char in_process
: 1;
1067 /* True if this DIE has children. */
1068 unsigned char has_children
: 1;
1071 unsigned int abbrev
;
1073 /* Offset in .debug_info or .debug_types section. */
1074 sect_offset sect_off
;
1076 /* The dies in a compilation unit form an n-ary tree. PARENT
1077 points to this die's parent; CHILD points to the first child of
1078 this node; and all the children of a given node are chained
1079 together via their SIBLING fields. */
1080 struct die_info
*child
; /* Its first child, if any. */
1081 struct die_info
*sibling
; /* Its next sibling, if any. */
1082 struct die_info
*parent
; /* Its parent, if any. */
1084 /* An array of attributes, with NUM_ATTRS elements. There may be
1085 zero, but it's not common and zero-sized arrays are not
1086 sufficiently portable C. */
1087 struct attribute attrs
[1];
1090 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1091 but this would require a corresponding change in unpack_field_as_long
1093 static int bits_per_byte
= 8;
1095 /* When reading a variant or variant part, we track a bit more
1096 information about the field, and store it in an object of this
1099 struct variant_field
1101 /* If we see a DW_TAG_variant, then this will be the discriminant
1103 ULONGEST discriminant_value
;
1104 /* If we see a DW_TAG_variant, then this will be set if this is the
1106 bool default_branch
;
1107 /* While reading a DW_TAG_variant_part, this will be set if this
1108 field is the discriminant. */
1109 bool is_discriminant
;
1114 int accessibility
= 0;
1116 /* Extra information to describe a variant or variant part. */
1117 struct variant_field variant
{};
1118 struct field field
{};
1123 const char *name
= nullptr;
1124 std::vector
<struct fn_field
> fnfields
;
1127 /* The routines that read and process dies for a C struct or C++ class
1128 pass lists of data member fields and lists of member function fields
1129 in an instance of a field_info structure, as defined below. */
1132 /* List of data member and baseclasses fields. */
1133 std::vector
<struct nextfield
> fields
;
1134 std::vector
<struct nextfield
> baseclasses
;
1136 /* Number of fields (including baseclasses). */
1139 /* Set if the accessibility of one of the fields is not public. */
1140 int non_public_fields
= 0;
1142 /* Member function fieldlist array, contains name of possibly overloaded
1143 member function, number of overloaded member functions and a pointer
1144 to the head of the member function field chain. */
1145 std::vector
<struct fnfieldlist
> fnfieldlists
;
1147 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1148 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1149 std::vector
<struct decl_field
> typedef_field_list
;
1151 /* Nested types defined by this class and the number of elements in this
1153 std::vector
<struct decl_field
> nested_types_list
;
1156 /* Loaded secondary compilation units are kept in memory until they
1157 have not been referenced for the processing of this many
1158 compilation units. Set this to zero to disable caching. Cache
1159 sizes of up to at least twenty will improve startup time for
1160 typical inter-CU-reference binaries, at an obvious memory cost. */
1161 static int dwarf_max_cache_age
= 5;
1163 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1164 struct cmd_list_element
*c
, const char *value
)
1166 fprintf_filtered (file
, _("The upper bound on the age of cached "
1167 "DWARF compilation units is %s.\n"),
1171 /* local function prototypes */
1173 static void dwarf2_find_base_address (struct die_info
*die
,
1174 struct dwarf2_cu
*cu
);
1176 static dwarf2_psymtab
*create_partial_symtab
1177 (struct dwarf2_per_cu_data
*per_cu
, const char *name
);
1179 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1180 const gdb_byte
*info_ptr
,
1181 struct die_info
*type_unit_die
);
1183 static void dwarf2_build_psymtabs_hard
1184 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1186 static void scan_partial_symbols (struct partial_die_info
*,
1187 CORE_ADDR
*, CORE_ADDR
*,
1188 int, struct dwarf2_cu
*);
1190 static void add_partial_symbol (struct partial_die_info
*,
1191 struct dwarf2_cu
*);
1193 static void add_partial_namespace (struct partial_die_info
*pdi
,
1194 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1195 int set_addrmap
, struct dwarf2_cu
*cu
);
1197 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1198 CORE_ADDR
*highpc
, int set_addrmap
,
1199 struct dwarf2_cu
*cu
);
1201 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1202 struct dwarf2_cu
*cu
);
1204 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1205 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1206 int need_pc
, struct dwarf2_cu
*cu
);
1208 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1210 static struct partial_die_info
*load_partial_dies
1211 (const struct die_reader_specs
*, const gdb_byte
*, int);
1213 /* A pair of partial_die_info and compilation unit. */
1214 struct cu_partial_die_info
1216 /* The compilation unit of the partial_die_info. */
1217 struct dwarf2_cu
*cu
;
1218 /* A partial_die_info. */
1219 struct partial_die_info
*pdi
;
1221 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1227 cu_partial_die_info () = delete;
1230 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1231 struct dwarf2_cu
*);
1233 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1234 struct attribute
*, struct attr_abbrev
*,
1235 const gdb_byte
*, bool *need_reprocess
);
1237 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1238 struct attribute
*attr
);
1240 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1242 static LONGEST read_checked_initial_length_and_offset
1243 (bfd
*, const gdb_byte
*, const struct comp_unit_head
*,
1244 unsigned int *, unsigned int *);
1246 static sect_offset read_abbrev_offset
1247 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1248 struct dwarf2_section_info
*, sect_offset
);
1250 static const char *read_indirect_string
1251 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1252 const struct comp_unit_head
*, unsigned int *);
1254 static const char *read_indirect_line_string
1255 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1256 const struct comp_unit_head
*, unsigned int *);
1258 static const char *read_indirect_string_at_offset
1259 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
1260 LONGEST str_offset
);
1262 static const char *read_indirect_string_from_dwz
1263 (struct objfile
*objfile
, struct dwz_file
*, LONGEST
);
1265 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1269 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1270 ULONGEST str_index
);
1272 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1273 ULONGEST str_index
);
1275 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1277 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1278 struct dwarf2_cu
*);
1280 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1283 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1284 struct dwarf2_cu
*cu
);
1286 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1288 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1289 struct dwarf2_cu
*cu
);
1291 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1293 static struct die_info
*die_specification (struct die_info
*die
,
1294 struct dwarf2_cu
**);
1296 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1297 struct dwarf2_cu
*cu
);
1299 static void dwarf_decode_lines (struct line_header
*, const char *,
1300 struct dwarf2_cu
*, dwarf2_psymtab
*,
1301 CORE_ADDR
, int decode_mapping
);
1303 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1306 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1307 struct dwarf2_cu
*, struct symbol
* = NULL
);
1309 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1310 struct dwarf2_cu
*);
1312 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1315 struct obstack
*obstack
,
1316 struct dwarf2_cu
*cu
, LONGEST
*value
,
1317 const gdb_byte
**bytes
,
1318 struct dwarf2_locexpr_baton
**baton
);
1320 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1322 static int need_gnat_info (struct dwarf2_cu
*);
1324 static struct type
*die_descriptive_type (struct die_info
*,
1325 struct dwarf2_cu
*);
1327 static void set_descriptive_type (struct type
*, struct die_info
*,
1328 struct dwarf2_cu
*);
1330 static struct type
*die_containing_type (struct die_info
*,
1331 struct dwarf2_cu
*);
1333 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1334 struct dwarf2_cu
*);
1336 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1338 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1340 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1342 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1343 const char *suffix
, int physname
,
1344 struct dwarf2_cu
*cu
);
1346 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1348 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1350 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1352 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1354 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1356 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1358 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1359 struct dwarf2_cu
*, dwarf2_psymtab
*);
1361 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1362 values. Keep the items ordered with increasing constraints compliance. */
1365 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1366 PC_BOUNDS_NOT_PRESENT
,
1368 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1369 were present but they do not form a valid range of PC addresses. */
1372 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1375 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1379 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1380 CORE_ADDR
*, CORE_ADDR
*,
1384 static void get_scope_pc_bounds (struct die_info
*,
1385 CORE_ADDR
*, CORE_ADDR
*,
1386 struct dwarf2_cu
*);
1388 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1389 CORE_ADDR
, struct dwarf2_cu
*);
1391 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1392 struct dwarf2_cu
*);
1394 static void dwarf2_attach_fields_to_type (struct field_info
*,
1395 struct type
*, struct dwarf2_cu
*);
1397 static void dwarf2_add_member_fn (struct field_info
*,
1398 struct die_info
*, struct type
*,
1399 struct dwarf2_cu
*);
1401 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1403 struct dwarf2_cu
*);
1405 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1407 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1409 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1411 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1413 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1415 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1417 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1419 static struct type
*read_module_type (struct die_info
*die
,
1420 struct dwarf2_cu
*cu
);
1422 static const char *namespace_name (struct die_info
*die
,
1423 int *is_anonymous
, struct dwarf2_cu
*);
1425 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1427 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1429 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1430 struct dwarf2_cu
*);
1432 static struct die_info
*read_die_and_siblings_1
1433 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1436 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1437 const gdb_byte
*info_ptr
,
1438 const gdb_byte
**new_info_ptr
,
1439 struct die_info
*parent
);
1441 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1442 struct die_info
**, const gdb_byte
*,
1445 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1446 struct die_info
**, const gdb_byte
*);
1448 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1450 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1453 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1455 static const char *dwarf2_full_name (const char *name
,
1456 struct die_info
*die
,
1457 struct dwarf2_cu
*cu
);
1459 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1460 struct dwarf2_cu
*cu
);
1462 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1463 struct dwarf2_cu
**);
1465 static const char *dwarf_tag_name (unsigned int);
1467 static const char *dwarf_attr_name (unsigned int);
1469 static const char *dwarf_form_name (unsigned int);
1471 static const char *dwarf_bool_name (unsigned int);
1473 static const char *dwarf_type_encoding_name (unsigned int);
1475 static struct die_info
*sibling_die (struct die_info
*);
1477 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1479 static void dump_die_for_error (struct die_info
*);
1481 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1484 /*static*/ void dump_die (struct die_info
*, int max_level
);
1486 static void store_in_ref_table (struct die_info
*,
1487 struct dwarf2_cu
*);
1489 static sect_offset
dwarf2_get_ref_die_offset (const struct attribute
*);
1491 static LONGEST
dwarf2_get_attr_constant_value (const struct attribute
*, int);
1493 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1494 const struct attribute
*,
1495 struct dwarf2_cu
**);
1497 static struct die_info
*follow_die_ref (struct die_info
*,
1498 const struct attribute
*,
1499 struct dwarf2_cu
**);
1501 static struct die_info
*follow_die_sig (struct die_info
*,
1502 const struct attribute
*,
1503 struct dwarf2_cu
**);
1505 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1506 struct dwarf2_cu
*);
1508 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1509 const struct attribute
*,
1510 struct dwarf2_cu
*);
1512 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1514 static void read_signatured_type (struct signatured_type
*);
1516 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1517 struct die_info
*die
, struct dwarf2_cu
*cu
,
1518 struct dynamic_prop
*prop
, struct type
*type
);
1520 /* memory allocation interface */
1522 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1524 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1526 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1528 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1529 struct dwarf2_loclist_baton
*baton
,
1530 const struct attribute
*attr
);
1532 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1534 struct dwarf2_cu
*cu
,
1537 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1538 const gdb_byte
*info_ptr
,
1539 struct abbrev_info
*abbrev
);
1541 static hashval_t
partial_die_hash (const void *item
);
1543 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1545 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1546 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1547 struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1549 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1550 struct die_info
*comp_unit_die
,
1551 enum language pretend_language
);
1553 static void age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1555 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1557 static struct type
*set_die_type (struct die_info
*, struct type
*,
1558 struct dwarf2_cu
*);
1560 static void create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1562 static int create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1564 static void load_full_comp_unit (struct dwarf2_per_cu_data
*, bool,
1567 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1570 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1573 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1574 struct dwarf2_per_cu_data
*);
1576 static void dwarf2_mark (struct dwarf2_cu
*);
1578 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1580 static struct type
*get_die_type_at_offset (sect_offset
,
1581 struct dwarf2_per_cu_data
*);
1583 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1585 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1586 enum language pretend_language
);
1588 static void process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1590 /* Class, the destructor of which frees all allocated queue entries. This
1591 will only have work to do if an error was thrown while processing the
1592 dwarf. If no error was thrown then the queue entries should have all
1593 been processed, and freed, as we went along. */
1595 class dwarf2_queue_guard
1598 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1599 : m_per_objfile (per_objfile
)
1603 /* Free any entries remaining on the queue. There should only be
1604 entries left if we hit an error while processing the dwarf. */
1605 ~dwarf2_queue_guard ()
1607 /* Ensure that no memory is allocated by the queue. */
1608 std::queue
<dwarf2_queue_item
> empty
;
1609 std::swap (m_per_objfile
->queue
, empty
);
1612 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1615 dwarf2_per_objfile
*m_per_objfile
;
1618 dwarf2_queue_item::~dwarf2_queue_item ()
1620 /* Anything still marked queued is likely to be in an
1621 inconsistent state, so discard it. */
1624 if (per_cu
->cu
!= NULL
)
1625 free_one_cached_comp_unit (per_cu
);
1630 /* The return type of find_file_and_directory. Note, the enclosed
1631 string pointers are only valid while this object is valid. */
1633 struct file_and_directory
1635 /* The filename. This is never NULL. */
1638 /* The compilation directory. NULL if not known. If we needed to
1639 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1640 points directly to the DW_AT_comp_dir string attribute owned by
1641 the obstack that owns the DIE. */
1642 const char *comp_dir
;
1644 /* If we needed to build a new string for comp_dir, this is what
1645 owns the storage. */
1646 std::string comp_dir_storage
;
1649 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1650 struct dwarf2_cu
*cu
);
1652 static htab_up
allocate_signatured_type_table (struct objfile
*objfile
);
1654 static htab_up
allocate_dwo_unit_table (struct objfile
*objfile
);
1656 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1657 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1658 struct dwp_file
*dwp_file
, const char *comp_dir
,
1659 ULONGEST signature
, int is_debug_types
);
1661 static struct dwp_file
*get_dwp_file
1662 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1664 static struct dwo_unit
*lookup_dwo_comp_unit
1665 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
1667 static struct dwo_unit
*lookup_dwo_type_unit
1668 (struct signatured_type
*, const char *, const char *);
1670 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
1672 /* A unique pointer to a dwo_file. */
1674 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1676 static void process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1678 static void check_producer (struct dwarf2_cu
*cu
);
1680 static void free_line_header_voidp (void *arg
);
1682 /* Various complaints about symbol reading that don't abort the process. */
1685 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
1687 complaint (_("statement list doesn't fit in .debug_line section"));
1691 dwarf2_debug_line_missing_file_complaint (void)
1693 complaint (_(".debug_line section has line data without a file"));
1697 dwarf2_debug_line_missing_end_sequence_complaint (void)
1699 complaint (_(".debug_line section has line "
1700 "program sequence without an end"));
1704 dwarf2_complex_location_expr_complaint (void)
1706 complaint (_("location expression too complex"));
1710 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1713 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1718 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
1720 complaint (_("debug info runs off end of %s section"
1722 section
->get_name (),
1723 section
->get_file_name ());
1727 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
1729 complaint (_("macro debug info contains a "
1730 "malformed macro definition:\n`%s'"),
1735 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1737 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1741 /* Hash function for line_header_hash. */
1744 line_header_hash (const struct line_header
*ofs
)
1746 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1749 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1752 line_header_hash_voidp (const void *item
)
1754 const struct line_header
*ofs
= (const struct line_header
*) item
;
1756 return line_header_hash (ofs
);
1759 /* Equality function for line_header_hash. */
1762 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1764 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1765 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1767 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1768 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
1773 /* See declaration. */
1775 dwarf2_per_objfile::dwarf2_per_objfile (struct objfile
*objfile_
,
1776 const dwarf2_debug_sections
*names
,
1778 : objfile (objfile_
),
1779 can_copy (can_copy_
)
1782 names
= &dwarf2_elf_names
;
1784 bfd
*obfd
= objfile
->obfd
;
1786 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1787 locate_sections (obfd
, sec
, *names
);
1790 dwarf2_per_objfile::~dwarf2_per_objfile ()
1792 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
1793 free_cached_comp_units ();
1795 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
1796 per_cu
->imported_symtabs_free ();
1798 for (signatured_type
*sig_type
: all_type_units
)
1799 sig_type
->per_cu
.imported_symtabs_free ();
1801 /* Everything else should be on the objfile obstack. */
1804 /* See declaration. */
1807 dwarf2_per_objfile::free_cached_comp_units ()
1809 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
1810 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
1811 while (per_cu
!= NULL
)
1813 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
1816 *last_chain
= next_cu
;
1821 /* A helper class that calls free_cached_comp_units on
1824 class free_cached_comp_units
1828 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1829 : m_per_objfile (per_objfile
)
1833 ~free_cached_comp_units ()
1835 m_per_objfile
->free_cached_comp_units ();
1838 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1842 dwarf2_per_objfile
*m_per_objfile
;
1845 /* Try to locate the sections we need for DWARF 2 debugging
1846 information and return true if we have enough to do something.
1847 NAMES points to the dwarf2 section names, or is NULL if the standard
1848 ELF names are used. CAN_COPY is true for formats where symbol
1849 interposition is possible and so symbol values must follow copy
1850 relocation rules. */
1853 dwarf2_has_info (struct objfile
*objfile
,
1854 const struct dwarf2_debug_sections
*names
,
1857 if (objfile
->flags
& OBJF_READNEVER
)
1860 struct dwarf2_per_objfile
*dwarf2_per_objfile
1861 = get_dwarf2_per_objfile (objfile
);
1863 if (dwarf2_per_objfile
== NULL
)
1864 dwarf2_per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
,
1868 return (!dwarf2_per_objfile
->info
.is_virtual
1869 && dwarf2_per_objfile
->info
.s
.section
!= NULL
1870 && !dwarf2_per_objfile
->abbrev
.is_virtual
1871 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
1874 /* When loading sections, we look either for uncompressed section or for
1875 compressed section names. */
1878 section_is_p (const char *section_name
,
1879 const struct dwarf2_section_names
*names
)
1881 if (names
->normal
!= NULL
1882 && strcmp (section_name
, names
->normal
) == 0)
1884 if (names
->compressed
!= NULL
1885 && strcmp (section_name
, names
->compressed
) == 0)
1890 /* See declaration. */
1893 dwarf2_per_objfile::locate_sections (bfd
*abfd
, asection
*sectp
,
1894 const dwarf2_debug_sections
&names
)
1896 flagword aflag
= bfd_section_flags (sectp
);
1898 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1901 else if (elf_section_data (sectp
)->this_hdr
.sh_size
1902 > bfd_get_file_size (abfd
))
1904 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
1905 warning (_("Discarding section %s which has a section size (%s"
1906 ") larger than the file size [in module %s]"),
1907 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
1908 bfd_get_filename (abfd
));
1910 else if (section_is_p (sectp
->name
, &names
.info
))
1912 this->info
.s
.section
= sectp
;
1913 this->info
.size
= bfd_section_size (sectp
);
1915 else if (section_is_p (sectp
->name
, &names
.abbrev
))
1917 this->abbrev
.s
.section
= sectp
;
1918 this->abbrev
.size
= bfd_section_size (sectp
);
1920 else if (section_is_p (sectp
->name
, &names
.line
))
1922 this->line
.s
.section
= sectp
;
1923 this->line
.size
= bfd_section_size (sectp
);
1925 else if (section_is_p (sectp
->name
, &names
.loc
))
1927 this->loc
.s
.section
= sectp
;
1928 this->loc
.size
= bfd_section_size (sectp
);
1930 else if (section_is_p (sectp
->name
, &names
.loclists
))
1932 this->loclists
.s
.section
= sectp
;
1933 this->loclists
.size
= bfd_section_size (sectp
);
1935 else if (section_is_p (sectp
->name
, &names
.macinfo
))
1937 this->macinfo
.s
.section
= sectp
;
1938 this->macinfo
.size
= bfd_section_size (sectp
);
1940 else if (section_is_p (sectp
->name
, &names
.macro
))
1942 this->macro
.s
.section
= sectp
;
1943 this->macro
.size
= bfd_section_size (sectp
);
1945 else if (section_is_p (sectp
->name
, &names
.str
))
1947 this->str
.s
.section
= sectp
;
1948 this->str
.size
= bfd_section_size (sectp
);
1950 else if (section_is_p (sectp
->name
, &names
.str_offsets
))
1952 this->str_offsets
.s
.section
= sectp
;
1953 this->str_offsets
.size
= bfd_section_size (sectp
);
1955 else if (section_is_p (sectp
->name
, &names
.line_str
))
1957 this->line_str
.s
.section
= sectp
;
1958 this->line_str
.size
= bfd_section_size (sectp
);
1960 else if (section_is_p (sectp
->name
, &names
.addr
))
1962 this->addr
.s
.section
= sectp
;
1963 this->addr
.size
= bfd_section_size (sectp
);
1965 else if (section_is_p (sectp
->name
, &names
.frame
))
1967 this->frame
.s
.section
= sectp
;
1968 this->frame
.size
= bfd_section_size (sectp
);
1970 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
1972 this->eh_frame
.s
.section
= sectp
;
1973 this->eh_frame
.size
= bfd_section_size (sectp
);
1975 else if (section_is_p (sectp
->name
, &names
.ranges
))
1977 this->ranges
.s
.section
= sectp
;
1978 this->ranges
.size
= bfd_section_size (sectp
);
1980 else if (section_is_p (sectp
->name
, &names
.rnglists
))
1982 this->rnglists
.s
.section
= sectp
;
1983 this->rnglists
.size
= bfd_section_size (sectp
);
1985 else if (section_is_p (sectp
->name
, &names
.types
))
1987 struct dwarf2_section_info type_section
;
1989 memset (&type_section
, 0, sizeof (type_section
));
1990 type_section
.s
.section
= sectp
;
1991 type_section
.size
= bfd_section_size (sectp
);
1993 this->types
.push_back (type_section
);
1995 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
1997 this->gdb_index
.s
.section
= sectp
;
1998 this->gdb_index
.size
= bfd_section_size (sectp
);
2000 else if (section_is_p (sectp
->name
, &names
.debug_names
))
2002 this->debug_names
.s
.section
= sectp
;
2003 this->debug_names
.size
= bfd_section_size (sectp
);
2005 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
2007 this->debug_aranges
.s
.section
= sectp
;
2008 this->debug_aranges
.size
= bfd_section_size (sectp
);
2011 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2012 && bfd_section_vma (sectp
) == 0)
2013 this->has_section_at_zero
= true;
2016 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2020 dwarf2_get_section_info (struct objfile
*objfile
,
2021 enum dwarf2_section_enum sect
,
2022 asection
**sectp
, const gdb_byte
**bufp
,
2023 bfd_size_type
*sizep
)
2025 struct dwarf2_per_objfile
*data
= dwarf2_objfile_data_key
.get (objfile
);
2026 struct dwarf2_section_info
*info
;
2028 /* We may see an objfile without any DWARF, in which case we just
2039 case DWARF2_DEBUG_FRAME
:
2040 info
= &data
->frame
;
2042 case DWARF2_EH_FRAME
:
2043 info
= &data
->eh_frame
;
2046 gdb_assert_not_reached ("unexpected section");
2049 info
->read (objfile
);
2051 *sectp
= info
->get_bfd_section ();
2052 *bufp
= info
->buffer
;
2053 *sizep
= info
->size
;
2056 /* A helper function to find the sections for a .dwz file. */
2059 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2061 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2063 /* Note that we only support the standard ELF names, because .dwz
2064 is ELF-only (at the time of writing). */
2065 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2067 dwz_file
->abbrev
.s
.section
= sectp
;
2068 dwz_file
->abbrev
.size
= bfd_section_size (sectp
);
2070 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2072 dwz_file
->info
.s
.section
= sectp
;
2073 dwz_file
->info
.size
= bfd_section_size (sectp
);
2075 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2077 dwz_file
->str
.s
.section
= sectp
;
2078 dwz_file
->str
.size
= bfd_section_size (sectp
);
2080 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2082 dwz_file
->line
.s
.section
= sectp
;
2083 dwz_file
->line
.size
= bfd_section_size (sectp
);
2085 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2087 dwz_file
->macro
.s
.section
= sectp
;
2088 dwz_file
->macro
.size
= bfd_section_size (sectp
);
2090 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2092 dwz_file
->gdb_index
.s
.section
= sectp
;
2093 dwz_file
->gdb_index
.size
= bfd_section_size (sectp
);
2095 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2097 dwz_file
->debug_names
.s
.section
= sectp
;
2098 dwz_file
->debug_names
.size
= bfd_section_size (sectp
);
2102 /* See dwarf2read.h. */
2105 dwarf2_get_dwz_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
2107 const char *filename
;
2108 bfd_size_type buildid_len_arg
;
2112 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2113 return dwarf2_per_objfile
->dwz_file
.get ();
2115 bfd_set_error (bfd_error_no_error
);
2116 gdb::unique_xmalloc_ptr
<char> data
2117 (bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2118 &buildid_len_arg
, &buildid
));
2121 if (bfd_get_error () == bfd_error_no_error
)
2123 error (_("could not read '.gnu_debugaltlink' section: %s"),
2124 bfd_errmsg (bfd_get_error ()));
2127 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2129 buildid_len
= (size_t) buildid_len_arg
;
2131 filename
= data
.get ();
2133 std::string abs_storage
;
2134 if (!IS_ABSOLUTE_PATH (filename
))
2136 gdb::unique_xmalloc_ptr
<char> abs
2137 = gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2139 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2140 filename
= abs_storage
.c_str ();
2143 /* First try the file name given in the section. If that doesn't
2144 work, try to use the build-id instead. */
2145 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
, -1));
2146 if (dwz_bfd
!= NULL
)
2148 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2149 dwz_bfd
.reset (nullptr);
2152 if (dwz_bfd
== NULL
)
2153 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2155 if (dwz_bfd
== NULL
)
2156 error (_("could not find '.gnu_debugaltlink' file for %s"),
2157 objfile_name (dwarf2_per_objfile
->objfile
));
2159 std::unique_ptr
<struct dwz_file
> result
2160 (new struct dwz_file (std::move (dwz_bfd
)));
2162 bfd_map_over_sections (result
->dwz_bfd
.get (), locate_dwz_sections
,
2165 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
,
2166 result
->dwz_bfd
.get ());
2167 dwarf2_per_objfile
->dwz_file
= std::move (result
);
2168 return dwarf2_per_objfile
->dwz_file
.get ();
2171 /* DWARF quick_symbols_functions support. */
2173 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2174 unique line tables, so we maintain a separate table of all .debug_line
2175 derived entries to support the sharing.
2176 All the quick functions need is the list of file names. We discard the
2177 line_header when we're done and don't need to record it here. */
2178 struct quick_file_names
2180 /* The data used to construct the hash key. */
2181 struct stmt_list_hash hash
;
2183 /* The number of entries in file_names, real_names. */
2184 unsigned int num_file_names
;
2186 /* The file names from the line table, after being run through
2188 const char **file_names
;
2190 /* The file names from the line table after being run through
2191 gdb_realpath. These are computed lazily. */
2192 const char **real_names
;
2195 /* When using the index (and thus not using psymtabs), each CU has an
2196 object of this type. This is used to hold information needed by
2197 the various "quick" methods. */
2198 struct dwarf2_per_cu_quick_data
2200 /* The file table. This can be NULL if there was no file table
2201 or it's currently not read in.
2202 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2203 struct quick_file_names
*file_names
;
2205 /* The corresponding symbol table. This is NULL if symbols for this
2206 CU have not yet been read. */
2207 struct compunit_symtab
*compunit_symtab
;
2209 /* A temporary mark bit used when iterating over all CUs in
2210 expand_symtabs_matching. */
2211 unsigned int mark
: 1;
2213 /* True if we've tried to read the file table and found there isn't one.
2214 There will be no point in trying to read it again next time. */
2215 unsigned int no_file_data
: 1;
2218 /* Utility hash function for a stmt_list_hash. */
2221 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2225 if (stmt_list_hash
->dwo_unit
!= NULL
)
2226 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2227 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2231 /* Utility equality function for a stmt_list_hash. */
2234 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2235 const struct stmt_list_hash
*rhs
)
2237 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2239 if (lhs
->dwo_unit
!= NULL
2240 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2243 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2246 /* Hash function for a quick_file_names. */
2249 hash_file_name_entry (const void *e
)
2251 const struct quick_file_names
*file_data
2252 = (const struct quick_file_names
*) e
;
2254 return hash_stmt_list_entry (&file_data
->hash
);
2257 /* Equality function for a quick_file_names. */
2260 eq_file_name_entry (const void *a
, const void *b
)
2262 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2263 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2265 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2268 /* Delete function for a quick_file_names. */
2271 delete_file_name_entry (void *e
)
2273 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2276 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2278 xfree ((void*) file_data
->file_names
[i
]);
2279 if (file_data
->real_names
)
2280 xfree ((void*) file_data
->real_names
[i
]);
2283 /* The space for the struct itself lives on objfile_obstack,
2284 so we don't free it here. */
2287 /* Create a quick_file_names hash table. */
2290 create_quick_file_names_table (unsigned int nr_initial_entries
)
2292 return htab_up (htab_create_alloc (nr_initial_entries
,
2293 hash_file_name_entry
, eq_file_name_entry
,
2294 delete_file_name_entry
, xcalloc
, xfree
));
2297 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2298 have to be created afterwards. You should call age_cached_comp_units after
2299 processing PER_CU->CU. dw2_setup must have been already called. */
2302 load_cu (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2304 if (per_cu
->is_debug_types
)
2305 load_full_type_unit (per_cu
);
2307 load_full_comp_unit (per_cu
, skip_partial
, language_minimal
);
2309 if (per_cu
->cu
== NULL
)
2310 return; /* Dummy CU. */
2312 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2315 /* Read in the symbols for PER_CU. */
2318 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2320 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2322 /* Skip type_unit_groups, reading the type units they contain
2323 is handled elsewhere. */
2324 if (IS_TYPE_UNIT_GROUP (per_cu
))
2327 /* The destructor of dwarf2_queue_guard frees any entries left on
2328 the queue. After this point we're guaranteed to leave this function
2329 with the dwarf queue empty. */
2330 dwarf2_queue_guard
q_guard (dwarf2_per_objfile
);
2332 if (dwarf2_per_objfile
->using_index
2333 ? per_cu
->v
.quick
->compunit_symtab
== NULL
2334 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2336 queue_comp_unit (per_cu
, language_minimal
);
2337 load_cu (per_cu
, skip_partial
);
2339 /* If we just loaded a CU from a DWO, and we're working with an index
2340 that may badly handle TUs, load all the TUs in that DWO as well.
2341 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2342 if (!per_cu
->is_debug_types
2343 && per_cu
->cu
!= NULL
2344 && per_cu
->cu
->dwo_unit
!= NULL
2345 && dwarf2_per_objfile
->index_table
!= NULL
2346 && dwarf2_per_objfile
->index_table
->version
<= 7
2347 /* DWP files aren't supported yet. */
2348 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
2349 queue_and_load_all_dwo_tus (per_cu
);
2352 process_queue (dwarf2_per_objfile
);
2354 /* Age the cache, releasing compilation units that have not
2355 been used recently. */
2356 age_cached_comp_units (dwarf2_per_objfile
);
2359 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2360 the objfile from which this CU came. Returns the resulting symbol
2363 static struct compunit_symtab
*
2364 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2366 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2368 gdb_assert (dwarf2_per_objfile
->using_index
);
2369 if (!per_cu
->v
.quick
->compunit_symtab
)
2371 free_cached_comp_units
freer (dwarf2_per_objfile
);
2372 scoped_restore decrementer
= increment_reading_symtab ();
2373 dw2_do_instantiate_symtab (per_cu
, skip_partial
);
2374 process_cu_includes (dwarf2_per_objfile
);
2377 return per_cu
->v
.quick
->compunit_symtab
;
2380 /* See declaration. */
2382 dwarf2_per_cu_data
*
2383 dwarf2_per_objfile::get_cutu (int index
)
2385 if (index
>= this->all_comp_units
.size ())
2387 index
-= this->all_comp_units
.size ();
2388 gdb_assert (index
< this->all_type_units
.size ());
2389 return &this->all_type_units
[index
]->per_cu
;
2392 return this->all_comp_units
[index
];
2395 /* See declaration. */
2397 dwarf2_per_cu_data
*
2398 dwarf2_per_objfile::get_cu (int index
)
2400 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2402 return this->all_comp_units
[index
];
2405 /* See declaration. */
2408 dwarf2_per_objfile::get_tu (int index
)
2410 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2412 return this->all_type_units
[index
];
2415 /* Return a new dwarf2_per_cu_data allocated on OBJFILE's
2416 objfile_obstack, and constructed with the specified field
2419 static dwarf2_per_cu_data
*
2420 create_cu_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2421 struct dwarf2_section_info
*section
,
2423 sect_offset sect_off
, ULONGEST length
)
2425 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2426 dwarf2_per_cu_data
*the_cu
2427 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2428 struct dwarf2_per_cu_data
);
2429 the_cu
->sect_off
= sect_off
;
2430 the_cu
->length
= length
;
2431 the_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
2432 the_cu
->section
= section
;
2433 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2434 struct dwarf2_per_cu_quick_data
);
2435 the_cu
->is_dwz
= is_dwz
;
2439 /* A helper for create_cus_from_index that handles a given list of
2443 create_cus_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2444 const gdb_byte
*cu_list
, offset_type n_elements
,
2445 struct dwarf2_section_info
*section
,
2448 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2450 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2452 sect_offset sect_off
2453 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2454 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2457 dwarf2_per_cu_data
*per_cu
2458 = create_cu_from_index_list (dwarf2_per_objfile
, section
, is_dwz
,
2460 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
2464 /* Read the CU list from the mapped index, and use it to create all
2465 the CU objects for this objfile. */
2468 create_cus_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2469 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2470 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2472 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
2473 dwarf2_per_objfile
->all_comp_units
.reserve
2474 ((cu_list_elements
+ dwz_elements
) / 2);
2476 create_cus_from_index_list (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
2477 &dwarf2_per_objfile
->info
, 0);
2479 if (dwz_elements
== 0)
2482 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
2483 create_cus_from_index_list (dwarf2_per_objfile
, dwz_list
, dwz_elements
,
2487 /* Create the signatured type hash table from the index. */
2490 create_signatured_type_table_from_index
2491 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2492 struct dwarf2_section_info
*section
,
2493 const gdb_byte
*bytes
,
2494 offset_type elements
)
2496 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2498 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
2499 dwarf2_per_objfile
->all_type_units
.reserve (elements
/ 3);
2501 htab_up sig_types_hash
= allocate_signatured_type_table (objfile
);
2503 for (offset_type i
= 0; i
< elements
; i
+= 3)
2505 struct signatured_type
*sig_type
;
2508 cu_offset type_offset_in_tu
;
2510 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2511 sect_offset sect_off
2512 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2514 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2516 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2519 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2520 struct signatured_type
);
2521 sig_type
->signature
= signature
;
2522 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2523 sig_type
->per_cu
.is_debug_types
= 1;
2524 sig_type
->per_cu
.section
= section
;
2525 sig_type
->per_cu
.sect_off
= sect_off
;
2526 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
2527 sig_type
->per_cu
.v
.quick
2528 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2529 struct dwarf2_per_cu_quick_data
);
2531 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2534 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
2537 dwarf2_per_objfile
->signatured_types
= std::move (sig_types_hash
);
2540 /* Create the signatured type hash table from .debug_names. */
2543 create_signatured_type_table_from_debug_names
2544 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2545 const mapped_debug_names
&map
,
2546 struct dwarf2_section_info
*section
,
2547 struct dwarf2_section_info
*abbrev_section
)
2549 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2551 section
->read (objfile
);
2552 abbrev_section
->read (objfile
);
2554 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
2555 dwarf2_per_objfile
->all_type_units
.reserve (map
.tu_count
);
2557 htab_up sig_types_hash
= allocate_signatured_type_table (objfile
);
2559 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2561 struct signatured_type
*sig_type
;
2564 sect_offset sect_off
2565 = (sect_offset
) (extract_unsigned_integer
2566 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2568 map
.dwarf5_byte_order
));
2570 comp_unit_head cu_header
;
2571 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
2573 section
->buffer
+ to_underlying (sect_off
),
2576 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2577 struct signatured_type
);
2578 sig_type
->signature
= cu_header
.signature
;
2579 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2580 sig_type
->per_cu
.is_debug_types
= 1;
2581 sig_type
->per_cu
.section
= section
;
2582 sig_type
->per_cu
.sect_off
= sect_off
;
2583 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
2584 sig_type
->per_cu
.v
.quick
2585 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2586 struct dwarf2_per_cu_quick_data
);
2588 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2591 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
2594 dwarf2_per_objfile
->signatured_types
= std::move (sig_types_hash
);
2597 /* Read the address map data from the mapped index, and use it to
2598 populate the objfile's psymtabs_addrmap. */
2601 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2602 struct mapped_index
*index
)
2604 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2605 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2606 const gdb_byte
*iter
, *end
;
2607 struct addrmap
*mutable_map
;
2610 auto_obstack temp_obstack
;
2612 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2614 iter
= index
->address_table
.data ();
2615 end
= iter
+ index
->address_table
.size ();
2617 baseaddr
= objfile
->text_section_offset ();
2621 ULONGEST hi
, lo
, cu_index
;
2622 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2624 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2626 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2631 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2632 hex_string (lo
), hex_string (hi
));
2636 if (cu_index
>= dwarf2_per_objfile
->all_comp_units
.size ())
2638 complaint (_(".gdb_index address table has invalid CU number %u"),
2639 (unsigned) cu_index
);
2643 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2644 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2645 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2646 dwarf2_per_objfile
->get_cu (cu_index
));
2649 objfile
->partial_symtabs
->psymtabs_addrmap
2650 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2653 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2654 populate the objfile's psymtabs_addrmap. */
2657 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2658 struct dwarf2_section_info
*section
)
2660 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2661 bfd
*abfd
= objfile
->obfd
;
2662 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2663 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2665 auto_obstack temp_obstack
;
2666 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2668 std::unordered_map
<sect_offset
,
2669 dwarf2_per_cu_data
*,
2670 gdb::hash_enum
<sect_offset
>>
2671 debug_info_offset_to_per_cu
;
2672 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
2674 const auto insertpair
2675 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
2676 if (!insertpair
.second
)
2678 warning (_("Section .debug_aranges in %s has duplicate "
2679 "debug_info_offset %s, ignoring .debug_aranges."),
2680 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2685 section
->read (objfile
);
2687 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2689 const gdb_byte
*addr
= section
->buffer
;
2691 while (addr
< section
->buffer
+ section
->size
)
2693 const gdb_byte
*const entry_addr
= addr
;
2694 unsigned int bytes_read
;
2696 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2700 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2701 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2702 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2703 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2705 warning (_("Section .debug_aranges in %s entry at offset %s "
2706 "length %s exceeds section length %s, "
2707 "ignoring .debug_aranges."),
2708 objfile_name (objfile
),
2709 plongest (entry_addr
- section
->buffer
),
2710 plongest (bytes_read
+ entry_length
),
2711 pulongest (section
->size
));
2715 /* The version number. */
2716 const uint16_t version
= read_2_bytes (abfd
, addr
);
2720 warning (_("Section .debug_aranges in %s entry at offset %s "
2721 "has unsupported version %d, ignoring .debug_aranges."),
2722 objfile_name (objfile
),
2723 plongest (entry_addr
- section
->buffer
), version
);
2727 const uint64_t debug_info_offset
2728 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2729 addr
+= offset_size
;
2730 const auto per_cu_it
2731 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2732 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2734 warning (_("Section .debug_aranges in %s entry at offset %s "
2735 "debug_info_offset %s does not exists, "
2736 "ignoring .debug_aranges."),
2737 objfile_name (objfile
),
2738 plongest (entry_addr
- section
->buffer
),
2739 pulongest (debug_info_offset
));
2742 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2744 const uint8_t address_size
= *addr
++;
2745 if (address_size
< 1 || address_size
> 8)
2747 warning (_("Section .debug_aranges in %s entry at offset %s "
2748 "address_size %u is invalid, ignoring .debug_aranges."),
2749 objfile_name (objfile
),
2750 plongest (entry_addr
- section
->buffer
), address_size
);
2754 const uint8_t segment_selector_size
= *addr
++;
2755 if (segment_selector_size
!= 0)
2757 warning (_("Section .debug_aranges in %s entry at offset %s "
2758 "segment_selector_size %u is not supported, "
2759 "ignoring .debug_aranges."),
2760 objfile_name (objfile
),
2761 plongest (entry_addr
- section
->buffer
),
2762 segment_selector_size
);
2766 /* Must pad to an alignment boundary that is twice the address
2767 size. It is undocumented by the DWARF standard but GCC does
2769 for (size_t padding
= ((-(addr
- section
->buffer
))
2770 & (2 * address_size
- 1));
2771 padding
> 0; padding
--)
2774 warning (_("Section .debug_aranges in %s entry at offset %s "
2775 "padding is not zero, ignoring .debug_aranges."),
2776 objfile_name (objfile
),
2777 plongest (entry_addr
- section
->buffer
));
2783 if (addr
+ 2 * address_size
> entry_end
)
2785 warning (_("Section .debug_aranges in %s entry at offset %s "
2786 "address list is not properly terminated, "
2787 "ignoring .debug_aranges."),
2788 objfile_name (objfile
),
2789 plongest (entry_addr
- section
->buffer
));
2792 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
2794 addr
+= address_size
;
2795 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
2797 addr
+= address_size
;
2798 if (start
== 0 && length
== 0)
2800 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
2802 /* Symbol was eliminated due to a COMDAT group. */
2805 ULONGEST end
= start
+ length
;
2806 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
2808 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
2810 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
2814 objfile
->partial_symtabs
->psymtabs_addrmap
2815 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2818 /* Find a slot in the mapped index INDEX for the object named NAME.
2819 If NAME is found, set *VEC_OUT to point to the CU vector in the
2820 constant pool and return true. If NAME cannot be found, return
2824 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2825 offset_type
**vec_out
)
2828 offset_type slot
, step
;
2829 int (*cmp
) (const char *, const char *);
2831 gdb::unique_xmalloc_ptr
<char> without_params
;
2832 if (current_language
->la_language
== language_cplus
2833 || current_language
->la_language
== language_fortran
2834 || current_language
->la_language
== language_d
)
2836 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2839 if (strchr (name
, '(') != NULL
)
2841 without_params
= cp_remove_params (name
);
2843 if (without_params
!= NULL
)
2844 name
= without_params
.get ();
2848 /* Index version 4 did not support case insensitive searches. But the
2849 indices for case insensitive languages are built in lowercase, therefore
2850 simulate our NAME being searched is also lowercased. */
2851 hash
= mapped_index_string_hash ((index
->version
== 4
2852 && case_sensitivity
== case_sensitive_off
2853 ? 5 : index
->version
),
2856 slot
= hash
& (index
->symbol_table
.size () - 1);
2857 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
2858 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2864 const auto &bucket
= index
->symbol_table
[slot
];
2865 if (bucket
.name
== 0 && bucket
.vec
== 0)
2868 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
2869 if (!cmp (name
, str
))
2871 *vec_out
= (offset_type
*) (index
->constant_pool
2872 + MAYBE_SWAP (bucket
.vec
));
2876 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
2880 /* A helper function that reads the .gdb_index from BUFFER and fills
2881 in MAP. FILENAME is the name of the file containing the data;
2882 it is used for error reporting. DEPRECATED_OK is true if it is
2883 ok to use deprecated sections.
2885 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2886 out parameters that are filled in with information about the CU and
2887 TU lists in the section.
2889 Returns true if all went well, false otherwise. */
2892 read_gdb_index_from_buffer (struct objfile
*objfile
,
2893 const char *filename
,
2895 gdb::array_view
<const gdb_byte
> buffer
,
2896 struct mapped_index
*map
,
2897 const gdb_byte
**cu_list
,
2898 offset_type
*cu_list_elements
,
2899 const gdb_byte
**types_list
,
2900 offset_type
*types_list_elements
)
2902 const gdb_byte
*addr
= &buffer
[0];
2904 /* Version check. */
2905 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
2906 /* Versions earlier than 3 emitted every copy of a psymbol. This
2907 causes the index to behave very poorly for certain requests. Version 3
2908 contained incomplete addrmap. So, it seems better to just ignore such
2912 static int warning_printed
= 0;
2913 if (!warning_printed
)
2915 warning (_("Skipping obsolete .gdb_index section in %s."),
2917 warning_printed
= 1;
2921 /* Index version 4 uses a different hash function than index version
2924 Versions earlier than 6 did not emit psymbols for inlined
2925 functions. Using these files will cause GDB not to be able to
2926 set breakpoints on inlined functions by name, so we ignore these
2927 indices unless the user has done
2928 "set use-deprecated-index-sections on". */
2929 if (version
< 6 && !deprecated_ok
)
2931 static int warning_printed
= 0;
2932 if (!warning_printed
)
2935 Skipping deprecated .gdb_index section in %s.\n\
2936 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2937 to use the section anyway."),
2939 warning_printed
= 1;
2943 /* Version 7 indices generated by gold refer to the CU for a symbol instead
2944 of the TU (for symbols coming from TUs),
2945 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
2946 Plus gold-generated indices can have duplicate entries for global symbols,
2947 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
2948 These are just performance bugs, and we can't distinguish gdb-generated
2949 indices from gold-generated ones, so issue no warning here. */
2951 /* Indexes with higher version than the one supported by GDB may be no
2952 longer backward compatible. */
2956 map
->version
= version
;
2958 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2961 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2962 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2966 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2967 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2968 - MAYBE_SWAP (metadata
[i
]))
2972 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2973 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
2975 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
2978 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2979 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
2981 = gdb::array_view
<mapped_index::symbol_table_slot
>
2982 ((mapped_index::symbol_table_slot
*) symbol_table
,
2983 (mapped_index::symbol_table_slot
*) symbol_table_end
);
2986 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
2991 /* Callback types for dwarf2_read_gdb_index. */
2993 typedef gdb::function_view
2994 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_objfile
*)>
2995 get_gdb_index_contents_ftype
;
2996 typedef gdb::function_view
2997 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
2998 get_gdb_index_contents_dwz_ftype
;
3000 /* Read .gdb_index. If everything went ok, initialize the "quick"
3001 elements of all the CUs and return 1. Otherwise, return 0. */
3004 dwarf2_read_gdb_index
3005 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3006 get_gdb_index_contents_ftype get_gdb_index_contents
,
3007 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
3009 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3010 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3011 struct dwz_file
*dwz
;
3012 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3014 gdb::array_view
<const gdb_byte
> main_index_contents
3015 = get_gdb_index_contents (objfile
, dwarf2_per_objfile
);
3017 if (main_index_contents
.empty ())
3020 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3021 if (!read_gdb_index_from_buffer (objfile
, objfile_name (objfile
),
3022 use_deprecated_index_sections
,
3023 main_index_contents
, map
.get (), &cu_list
,
3024 &cu_list_elements
, &types_list
,
3025 &types_list_elements
))
3028 /* Don't use the index if it's empty. */
3029 if (map
->symbol_table
.empty ())
3032 /* If there is a .dwz file, read it so we can get its CU list as
3034 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3037 struct mapped_index dwz_map
;
3038 const gdb_byte
*dwz_types_ignore
;
3039 offset_type dwz_types_elements_ignore
;
3041 gdb::array_view
<const gdb_byte
> dwz_index_content
3042 = get_gdb_index_contents_dwz (objfile
, dwz
);
3044 if (dwz_index_content
.empty ())
3047 if (!read_gdb_index_from_buffer (objfile
,
3048 bfd_get_filename (dwz
->dwz_bfd
.get ()),
3049 1, dwz_index_content
, &dwz_map
,
3050 &dwz_list
, &dwz_list_elements
,
3052 &dwz_types_elements_ignore
))
3054 warning (_("could not read '.gdb_index' section from %s; skipping"),
3055 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3060 create_cus_from_index (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3061 dwz_list
, dwz_list_elements
);
3063 if (types_list_elements
)
3065 /* We can only handle a single .debug_types when we have an
3067 if (dwarf2_per_objfile
->types
.size () != 1)
3070 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
3072 create_signatured_type_table_from_index (dwarf2_per_objfile
, section
,
3073 types_list
, types_list_elements
);
3076 create_addrmap_from_index (dwarf2_per_objfile
, map
.get ());
3078 dwarf2_per_objfile
->index_table
= std::move (map
);
3079 dwarf2_per_objfile
->using_index
= 1;
3080 dwarf2_per_objfile
->quick_file_names_table
=
3081 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
3086 /* die_reader_func for dw2_get_file_names. */
3089 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3090 const gdb_byte
*info_ptr
,
3091 struct die_info
*comp_unit_die
)
3093 struct dwarf2_cu
*cu
= reader
->cu
;
3094 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3095 struct dwarf2_per_objfile
*dwarf2_per_objfile
3096 = cu
->per_cu
->dwarf2_per_objfile
;
3097 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3098 struct dwarf2_per_cu_data
*lh_cu
;
3099 struct attribute
*attr
;
3101 struct quick_file_names
*qfn
;
3103 gdb_assert (! this_cu
->is_debug_types
);
3105 /* Our callers never want to match partial units -- instead they
3106 will match the enclosing full CU. */
3107 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3109 this_cu
->v
.quick
->no_file_data
= 1;
3117 sect_offset line_offset
{};
3119 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3120 if (attr
!= nullptr)
3122 struct quick_file_names find_entry
;
3124 line_offset
= (sect_offset
) DW_UNSND (attr
);
3126 /* We may have already read in this line header (TU line header sharing).
3127 If we have we're done. */
3128 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3129 find_entry
.hash
.line_sect_off
= line_offset
;
3130 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
.get (),
3131 &find_entry
, INSERT
);
3134 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3138 lh
= dwarf_decode_line_header (line_offset
, cu
);
3142 lh_cu
->v
.quick
->no_file_data
= 1;
3146 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
3147 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3148 qfn
->hash
.line_sect_off
= line_offset
;
3149 gdb_assert (slot
!= NULL
);
3152 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3155 if (strcmp (fnd
.name
, "<unknown>") != 0)
3158 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3160 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, qfn
->num_file_names
);
3162 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3163 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3164 qfn
->file_names
[i
+ offset
] = lh
->file_full_name (i
+ 1,
3165 fnd
.comp_dir
).release ();
3166 qfn
->real_names
= NULL
;
3168 lh_cu
->v
.quick
->file_names
= qfn
;
3171 /* A helper for the "quick" functions which attempts to read the line
3172 table for THIS_CU. */
3174 static struct quick_file_names
*
3175 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3177 /* This should never be called for TUs. */
3178 gdb_assert (! this_cu
->is_debug_types
);
3179 /* Nor type unit groups. */
3180 gdb_assert (! IS_TYPE_UNIT_GROUP (this_cu
));
3182 if (this_cu
->v
.quick
->file_names
!= NULL
)
3183 return this_cu
->v
.quick
->file_names
;
3184 /* If we know there is no line data, no point in looking again. */
3185 if (this_cu
->v
.quick
->no_file_data
)
3188 cutu_reader
reader (this_cu
);
3189 if (!reader
.dummy_p
)
3190 dw2_get_file_names_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
);
3192 if (this_cu
->v
.quick
->no_file_data
)
3194 return this_cu
->v
.quick
->file_names
;
3197 /* A helper for the "quick" functions which computes and caches the
3198 real path for a given file name from the line table. */
3201 dw2_get_real_path (struct objfile
*objfile
,
3202 struct quick_file_names
*qfn
, int index
)
3204 if (qfn
->real_names
== NULL
)
3205 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3206 qfn
->num_file_names
, const char *);
3208 if (qfn
->real_names
[index
] == NULL
)
3209 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3211 return qfn
->real_names
[index
];
3214 static struct symtab
*
3215 dw2_find_last_source_symtab (struct objfile
*objfile
)
3217 struct dwarf2_per_objfile
*dwarf2_per_objfile
3218 = get_dwarf2_per_objfile (objfile
);
3219 dwarf2_per_cu_data
*dwarf_cu
= dwarf2_per_objfile
->all_comp_units
.back ();
3220 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, false);
3225 return compunit_primary_filetab (cust
);
3228 /* Traversal function for dw2_forget_cached_source_info. */
3231 dw2_free_cached_file_names (void **slot
, void *info
)
3233 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3235 if (file_data
->real_names
)
3239 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3241 xfree ((void*) file_data
->real_names
[i
]);
3242 file_data
->real_names
[i
] = NULL
;
3250 dw2_forget_cached_source_info (struct objfile
*objfile
)
3252 struct dwarf2_per_objfile
*dwarf2_per_objfile
3253 = get_dwarf2_per_objfile (objfile
);
3255 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
.get (),
3256 dw2_free_cached_file_names
, NULL
);
3259 /* Helper function for dw2_map_symtabs_matching_filename that expands
3260 the symtabs and calls the iterator. */
3263 dw2_map_expand_apply (struct objfile
*objfile
,
3264 struct dwarf2_per_cu_data
*per_cu
,
3265 const char *name
, const char *real_path
,
3266 gdb::function_view
<bool (symtab
*)> callback
)
3268 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3270 /* Don't visit already-expanded CUs. */
3271 if (per_cu
->v
.quick
->compunit_symtab
)
3274 /* This may expand more than one symtab, and we want to iterate over
3276 dw2_instantiate_symtab (per_cu
, false);
3278 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3279 last_made
, callback
);
3282 /* Implementation of the map_symtabs_matching_filename method. */
3285 dw2_map_symtabs_matching_filename
3286 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3287 gdb::function_view
<bool (symtab
*)> callback
)
3289 const char *name_basename
= lbasename (name
);
3290 struct dwarf2_per_objfile
*dwarf2_per_objfile
3291 = get_dwarf2_per_objfile (objfile
);
3293 /* The rule is CUs specify all the files, including those used by
3294 any TU, so there's no need to scan TUs here. */
3296 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3298 /* We only need to look at symtabs not already expanded. */
3299 if (per_cu
->v
.quick
->compunit_symtab
)
3302 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3303 if (file_data
== NULL
)
3306 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3308 const char *this_name
= file_data
->file_names
[j
];
3309 const char *this_real_name
;
3311 if (compare_filenames_for_search (this_name
, name
))
3313 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3319 /* Before we invoke realpath, which can get expensive when many
3320 files are involved, do a quick comparison of the basenames. */
3321 if (! basenames_may_differ
3322 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3325 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3326 if (compare_filenames_for_search (this_real_name
, name
))
3328 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3334 if (real_path
!= NULL
)
3336 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3337 gdb_assert (IS_ABSOLUTE_PATH (name
));
3338 if (this_real_name
!= NULL
3339 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3341 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3353 /* Struct used to manage iterating over all CUs looking for a symbol. */
3355 struct dw2_symtab_iterator
3357 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3358 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
3359 /* If set, only look for symbols that match that block. Valid values are
3360 GLOBAL_BLOCK and STATIC_BLOCK. */
3361 gdb::optional
<block_enum
> block_index
;
3362 /* The kind of symbol we're looking for. */
3364 /* The list of CUs from the index entry of the symbol,
3365 or NULL if not found. */
3367 /* The next element in VEC to look at. */
3369 /* The number of elements in VEC, or zero if there is no match. */
3371 /* Have we seen a global version of the symbol?
3372 If so we can ignore all further global instances.
3373 This is to work around gold/15646, inefficient gold-generated
3378 /* Initialize the index symtab iterator ITER. */
3381 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3382 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3383 gdb::optional
<block_enum
> block_index
,
3387 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3388 iter
->block_index
= block_index
;
3389 iter
->domain
= domain
;
3391 iter
->global_seen
= 0;
3393 mapped_index
*index
= dwarf2_per_objfile
->index_table
.get ();
3395 /* index is NULL if OBJF_READNOW. */
3396 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3397 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3405 /* Return the next matching CU or NULL if there are no more. */
3407 static struct dwarf2_per_cu_data
*
3408 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3410 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
3412 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3414 offset_type cu_index_and_attrs
=
3415 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3416 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3417 gdb_index_symbol_kind symbol_kind
=
3418 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3419 /* Only check the symbol attributes if they're present.
3420 Indices prior to version 7 don't record them,
3421 and indices >= 7 may elide them for certain symbols
3422 (gold does this). */
3424 (dwarf2_per_objfile
->index_table
->version
>= 7
3425 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3427 /* Don't crash on bad data. */
3428 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
3429 + dwarf2_per_objfile
->all_type_units
.size ()))
3431 complaint (_(".gdb_index entry has bad CU index"
3433 objfile_name (dwarf2_per_objfile
->objfile
));
3437 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
3439 /* Skip if already read in. */
3440 if (per_cu
->v
.quick
->compunit_symtab
)
3443 /* Check static vs global. */
3446 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3448 if (iter
->block_index
.has_value ())
3450 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3452 if (is_static
!= want_static
)
3456 /* Work around gold/15646. */
3457 if (!is_static
&& iter
->global_seen
)
3460 iter
->global_seen
= 1;
3463 /* Only check the symbol's kind if it has one. */
3466 switch (iter
->domain
)
3469 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3470 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3471 /* Some types are also in VAR_DOMAIN. */
3472 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3476 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3480 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3484 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3499 static struct compunit_symtab
*
3500 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
3501 const char *name
, domain_enum domain
)
3503 struct compunit_symtab
*stab_best
= NULL
;
3504 struct dwarf2_per_objfile
*dwarf2_per_objfile
3505 = get_dwarf2_per_objfile (objfile
);
3507 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
3509 struct dw2_symtab_iterator iter
;
3510 struct dwarf2_per_cu_data
*per_cu
;
3512 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, block_index
, domain
, name
);
3514 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3516 struct symbol
*sym
, *with_opaque
= NULL
;
3517 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
3518 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
3519 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3521 sym
= block_find_symbol (block
, name
, domain
,
3522 block_find_non_opaque_type_preferred
,
3525 /* Some caution must be observed with overloaded functions
3526 and methods, since the index will not contain any overload
3527 information (but NAME might contain it). */
3530 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
3532 if (with_opaque
!= NULL
3533 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
3536 /* Keep looking through other CUs. */
3543 dw2_print_stats (struct objfile
*objfile
)
3545 struct dwarf2_per_objfile
*dwarf2_per_objfile
3546 = get_dwarf2_per_objfile (objfile
);
3547 int total
= (dwarf2_per_objfile
->all_comp_units
.size ()
3548 + dwarf2_per_objfile
->all_type_units
.size ());
3551 for (int i
= 0; i
< total
; ++i
)
3553 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
3555 if (!per_cu
->v
.quick
->compunit_symtab
)
3558 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3559 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3562 /* This dumps minimal information about the index.
3563 It is called via "mt print objfiles".
3564 One use is to verify .gdb_index has been loaded by the
3565 gdb.dwarf2/gdb-index.exp testcase. */
3568 dw2_dump (struct objfile
*objfile
)
3570 struct dwarf2_per_objfile
*dwarf2_per_objfile
3571 = get_dwarf2_per_objfile (objfile
);
3573 gdb_assert (dwarf2_per_objfile
->using_index
);
3574 printf_filtered (".gdb_index:");
3575 if (dwarf2_per_objfile
->index_table
!= NULL
)
3577 printf_filtered (" version %d\n",
3578 dwarf2_per_objfile
->index_table
->version
);
3581 printf_filtered (" faked for \"readnow\"\n");
3582 printf_filtered ("\n");
3586 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3587 const char *func_name
)
3589 struct dwarf2_per_objfile
*dwarf2_per_objfile
3590 = get_dwarf2_per_objfile (objfile
);
3592 struct dw2_symtab_iterator iter
;
3593 struct dwarf2_per_cu_data
*per_cu
;
3595 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, {}, VAR_DOMAIN
, func_name
);
3597 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3598 dw2_instantiate_symtab (per_cu
, false);
3603 dw2_expand_all_symtabs (struct objfile
*objfile
)
3605 struct dwarf2_per_objfile
*dwarf2_per_objfile
3606 = get_dwarf2_per_objfile (objfile
);
3607 int total_units
= (dwarf2_per_objfile
->all_comp_units
.size ()
3608 + dwarf2_per_objfile
->all_type_units
.size ());
3610 for (int i
= 0; i
< total_units
; ++i
)
3612 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
3614 /* We don't want to directly expand a partial CU, because if we
3615 read it with the wrong language, then assertion failures can
3616 be triggered later on. See PR symtab/23010. So, tell
3617 dw2_instantiate_symtab to skip partial CUs -- any important
3618 partial CU will be read via DW_TAG_imported_unit anyway. */
3619 dw2_instantiate_symtab (per_cu
, true);
3624 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
3625 const char *fullname
)
3627 struct dwarf2_per_objfile
*dwarf2_per_objfile
3628 = get_dwarf2_per_objfile (objfile
);
3630 /* We don't need to consider type units here.
3631 This is only called for examining code, e.g. expand_line_sal.
3632 There can be an order of magnitude (or more) more type units
3633 than comp units, and we avoid them if we can. */
3635 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3637 /* We only need to look at symtabs not already expanded. */
3638 if (per_cu
->v
.quick
->compunit_symtab
)
3641 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3642 if (file_data
== NULL
)
3645 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3647 const char *this_fullname
= file_data
->file_names
[j
];
3649 if (filename_cmp (this_fullname
, fullname
) == 0)
3651 dw2_instantiate_symtab (per_cu
, false);
3659 dw2_map_matching_symbols
3660 (struct objfile
*objfile
,
3661 const lookup_name_info
&name
, domain_enum domain
,
3663 gdb::function_view
<symbol_found_callback_ftype
> callback
,
3664 symbol_compare_ftype
*ordered_compare
)
3666 /* Currently unimplemented; used for Ada. The function can be called if the
3667 current language is Ada for a non-Ada objfile using GNU index. As Ada
3668 does not look for non-Ada symbols this function should just return. */
3671 /* Starting from a search name, return the string that finds the upper
3672 bound of all strings that start with SEARCH_NAME in a sorted name
3673 list. Returns the empty string to indicate that the upper bound is
3674 the end of the list. */
3677 make_sort_after_prefix_name (const char *search_name
)
3679 /* When looking to complete "func", we find the upper bound of all
3680 symbols that start with "func" by looking for where we'd insert
3681 the closest string that would follow "func" in lexicographical
3682 order. Usually, that's "func"-with-last-character-incremented,
3683 i.e. "fund". Mind non-ASCII characters, though. Usually those
3684 will be UTF-8 multi-byte sequences, but we can't be certain.
3685 Especially mind the 0xff character, which is a valid character in
3686 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3687 rule out compilers allowing it in identifiers. Note that
3688 conveniently, strcmp/strcasecmp are specified to compare
3689 characters interpreted as unsigned char. So what we do is treat
3690 the whole string as a base 256 number composed of a sequence of
3691 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3692 to 0, and carries 1 to the following more-significant position.
3693 If the very first character in SEARCH_NAME ends up incremented
3694 and carries/overflows, then the upper bound is the end of the
3695 list. The string after the empty string is also the empty
3698 Some examples of this operation:
3700 SEARCH_NAME => "+1" RESULT
3704 "\xff" "a" "\xff" => "\xff" "b"
3709 Then, with these symbols for example:
3715 completing "func" looks for symbols between "func" and
3716 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3717 which finds "func" and "func1", but not "fund".
3721 funcÿ (Latin1 'ÿ' [0xff])
3725 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3726 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3730 ÿÿ (Latin1 'ÿ' [0xff])
3733 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3734 the end of the list.
3736 std::string after
= search_name
;
3737 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3739 if (!after
.empty ())
3740 after
.back () = (unsigned char) after
.back () + 1;
3744 /* See declaration. */
3746 std::pair
<std::vector
<name_component
>::const_iterator
,
3747 std::vector
<name_component
>::const_iterator
>
3748 mapped_index_base::find_name_components_bounds
3749 (const lookup_name_info
&lookup_name_without_params
, language lang
) const
3752 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3754 const char *lang_name
3755 = lookup_name_without_params
.language_lookup_name (lang
).c_str ();
3757 /* Comparison function object for lower_bound that matches against a
3758 given symbol name. */
3759 auto lookup_compare_lower
= [&] (const name_component
&elem
,
3762 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
3763 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3764 return name_cmp (elem_name
, name
) < 0;
3767 /* Comparison function object for upper_bound that matches against a
3768 given symbol name. */
3769 auto lookup_compare_upper
= [&] (const char *name
,
3770 const name_component
&elem
)
3772 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
3773 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3774 return name_cmp (name
, elem_name
) < 0;
3777 auto begin
= this->name_components
.begin ();
3778 auto end
= this->name_components
.end ();
3780 /* Find the lower bound. */
3783 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3786 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
3789 /* Find the upper bound. */
3792 if (lookup_name_without_params
.completion_mode ())
3794 /* In completion mode, we want UPPER to point past all
3795 symbols names that have the same prefix. I.e., with
3796 these symbols, and completing "func":
3798 function << lower bound
3800 other_function << upper bound
3802 We find the upper bound by looking for the insertion
3803 point of "func"-with-last-character-incremented,
3805 std::string after
= make_sort_after_prefix_name (lang_name
);
3808 return std::lower_bound (lower
, end
, after
.c_str (),
3809 lookup_compare_lower
);
3812 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
3815 return {lower
, upper
};
3818 /* See declaration. */
3821 mapped_index_base::build_name_components ()
3823 if (!this->name_components
.empty ())
3826 this->name_components_casing
= case_sensitivity
;
3828 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3830 /* The code below only knows how to break apart components of C++
3831 symbol names (and other languages that use '::' as
3832 namespace/module separator) and Ada symbol names. */
3833 auto count
= this->symbol_name_count ();
3834 for (offset_type idx
= 0; idx
< count
; idx
++)
3836 if (this->symbol_name_slot_invalid (idx
))
3839 const char *name
= this->symbol_name_at (idx
);
3841 /* Add each name component to the name component table. */
3842 unsigned int previous_len
= 0;
3844 if (strstr (name
, "::") != nullptr)
3846 for (unsigned int current_len
= cp_find_first_component (name
);
3847 name
[current_len
] != '\0';
3848 current_len
+= cp_find_first_component (name
+ current_len
))
3850 gdb_assert (name
[current_len
] == ':');
3851 this->name_components
.push_back ({previous_len
, idx
});
3852 /* Skip the '::'. */
3854 previous_len
= current_len
;
3859 /* Handle the Ada encoded (aka mangled) form here. */
3860 for (const char *iter
= strstr (name
, "__");
3862 iter
= strstr (iter
, "__"))
3864 this->name_components
.push_back ({previous_len
, idx
});
3866 previous_len
= iter
- name
;
3870 this->name_components
.push_back ({previous_len
, idx
});
3873 /* Sort name_components elements by name. */
3874 auto name_comp_compare
= [&] (const name_component
&left
,
3875 const name_component
&right
)
3877 const char *left_qualified
= this->symbol_name_at (left
.idx
);
3878 const char *right_qualified
= this->symbol_name_at (right
.idx
);
3880 const char *left_name
= left_qualified
+ left
.name_offset
;
3881 const char *right_name
= right_qualified
+ right
.name_offset
;
3883 return name_cmp (left_name
, right_name
) < 0;
3886 std::sort (this->name_components
.begin (),
3887 this->name_components
.end (),
3891 /* Helper for dw2_expand_symtabs_matching that works with a
3892 mapped_index_base instead of the containing objfile. This is split
3893 to a separate function in order to be able to unit test the
3894 name_components matching using a mock mapped_index_base. For each
3895 symbol name that matches, calls MATCH_CALLBACK, passing it the
3896 symbol's index in the mapped_index_base symbol table. */
3899 dw2_expand_symtabs_matching_symbol
3900 (mapped_index_base
&index
,
3901 const lookup_name_info
&lookup_name_in
,
3902 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3903 enum search_domain kind
,
3904 gdb::function_view
<bool (offset_type
)> match_callback
)
3906 lookup_name_info lookup_name_without_params
3907 = lookup_name_in
.make_ignore_params ();
3909 /* Build the symbol name component sorted vector, if we haven't
3911 index
.build_name_components ();
3913 /* The same symbol may appear more than once in the range though.
3914 E.g., if we're looking for symbols that complete "w", and we have
3915 a symbol named "w1::w2", we'll find the two name components for
3916 that same symbol in the range. To be sure we only call the
3917 callback once per symbol, we first collect the symbol name
3918 indexes that matched in a temporary vector and ignore
3920 std::vector
<offset_type
> matches
;
3922 struct name_and_matcher
3924 symbol_name_matcher_ftype
*matcher
;
3925 const std::string
&name
;
3927 bool operator== (const name_and_matcher
&other
) const
3929 return matcher
== other
.matcher
&& name
== other
.name
;
3933 /* A vector holding all the different symbol name matchers, for all
3935 std::vector
<name_and_matcher
> matchers
;
3937 for (int i
= 0; i
< nr_languages
; i
++)
3939 enum language lang_e
= (enum language
) i
;
3941 const language_defn
*lang
= language_def (lang_e
);
3942 symbol_name_matcher_ftype
*name_matcher
3943 = get_symbol_name_matcher (lang
, lookup_name_without_params
);
3945 name_and_matcher key
{
3947 lookup_name_without_params
.language_lookup_name (lang_e
)
3950 /* Don't insert the same comparison routine more than once.
3951 Note that we do this linear walk. This is not a problem in
3952 practice because the number of supported languages is
3954 if (std::find (matchers
.begin (), matchers
.end (), key
)
3957 matchers
.push_back (std::move (key
));
3960 = index
.find_name_components_bounds (lookup_name_without_params
,
3963 /* Now for each symbol name in range, check to see if we have a name
3964 match, and if so, call the MATCH_CALLBACK callback. */
3966 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
3968 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
3970 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
3971 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
3974 matches
.push_back (bounds
.first
->idx
);
3978 std::sort (matches
.begin (), matches
.end ());
3980 /* Finally call the callback, once per match. */
3982 for (offset_type idx
: matches
)
3986 if (!match_callback (idx
))
3992 /* Above we use a type wider than idx's for 'prev', since 0 and
3993 (offset_type)-1 are both possible values. */
3994 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
3999 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4001 /* A mock .gdb_index/.debug_names-like name index table, enough to
4002 exercise dw2_expand_symtabs_matching_symbol, which works with the
4003 mapped_index_base interface. Builds an index from the symbol list
4004 passed as parameter to the constructor. */
4005 class mock_mapped_index
: public mapped_index_base
4008 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4009 : m_symbol_table (symbols
)
4012 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4014 /* Return the number of names in the symbol table. */
4015 size_t symbol_name_count () const override
4017 return m_symbol_table
.size ();
4020 /* Get the name of the symbol at IDX in the symbol table. */
4021 const char *symbol_name_at (offset_type idx
) const override
4023 return m_symbol_table
[idx
];
4027 gdb::array_view
<const char *> m_symbol_table
;
4030 /* Convenience function that converts a NULL pointer to a "<null>"
4031 string, to pass to print routines. */
4034 string_or_null (const char *str
)
4036 return str
!= NULL
? str
: "<null>";
4039 /* Check if a lookup_name_info built from
4040 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4041 index. EXPECTED_LIST is the list of expected matches, in expected
4042 matching order. If no match expected, then an empty list is
4043 specified. Returns true on success. On failure prints a warning
4044 indicating the file:line that failed, and returns false. */
4047 check_match (const char *file
, int line
,
4048 mock_mapped_index
&mock_index
,
4049 const char *name
, symbol_name_match_type match_type
,
4050 bool completion_mode
,
4051 std::initializer_list
<const char *> expected_list
)
4053 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4055 bool matched
= true;
4057 auto mismatch
= [&] (const char *expected_str
,
4060 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4061 "expected=\"%s\", got=\"%s\"\n"),
4063 (match_type
== symbol_name_match_type::FULL
4065 name
, string_or_null (expected_str
), string_or_null (got
));
4069 auto expected_it
= expected_list
.begin ();
4070 auto expected_end
= expected_list
.end ();
4072 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4074 [&] (offset_type idx
)
4076 const char *matched_name
= mock_index
.symbol_name_at (idx
);
4077 const char *expected_str
4078 = expected_it
== expected_end
? NULL
: *expected_it
++;
4080 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4081 mismatch (expected_str
, matched_name
);
4085 const char *expected_str
4086 = expected_it
== expected_end
? NULL
: *expected_it
++;
4087 if (expected_str
!= NULL
)
4088 mismatch (expected_str
, NULL
);
4093 /* The symbols added to the mock mapped_index for testing (in
4095 static const char *test_symbols
[] = {
4104 "ns2::tmpl<int>::foo2",
4105 "(anonymous namespace)::A::B::C",
4107 /* These are used to check that the increment-last-char in the
4108 matching algorithm for completion doesn't match "t1_fund" when
4109 completing "t1_func". */
4115 /* A UTF-8 name with multi-byte sequences to make sure that
4116 cp-name-parser understands this as a single identifier ("função"
4117 is "function" in PT). */
4120 /* \377 (0xff) is Latin1 'ÿ'. */
4123 /* \377 (0xff) is Latin1 'ÿ'. */
4127 /* A name with all sorts of complications. Starts with "z" to make
4128 it easier for the completion tests below. */
4129 #define Z_SYM_NAME \
4130 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4131 "::tuple<(anonymous namespace)::ui*, " \
4132 "std::default_delete<(anonymous namespace)::ui>, void>"
4137 /* Returns true if the mapped_index_base::find_name_component_bounds
4138 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4139 in completion mode. */
4142 check_find_bounds_finds (mapped_index_base
&index
,
4143 const char *search_name
,
4144 gdb::array_view
<const char *> expected_syms
)
4146 lookup_name_info
lookup_name (search_name
,
4147 symbol_name_match_type::FULL
, true);
4149 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4152 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4153 if (distance
!= expected_syms
.size ())
4156 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4158 auto nc_elem
= bounds
.first
+ exp_elem
;
4159 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
4160 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4167 /* Test the lower-level mapped_index::find_name_component_bounds
4171 test_mapped_index_find_name_component_bounds ()
4173 mock_mapped_index
mock_index (test_symbols
);
4175 mock_index
.build_name_components ();
4177 /* Test the lower-level mapped_index::find_name_component_bounds
4178 method in completion mode. */
4180 static const char *expected_syms
[] = {
4185 SELF_CHECK (check_find_bounds_finds (mock_index
,
4186 "t1_func", expected_syms
));
4189 /* Check that the increment-last-char in the name matching algorithm
4190 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4192 static const char *expected_syms1
[] = {
4196 SELF_CHECK (check_find_bounds_finds (mock_index
,
4197 "\377", expected_syms1
));
4199 static const char *expected_syms2
[] = {
4202 SELF_CHECK (check_find_bounds_finds (mock_index
,
4203 "\377\377", expected_syms2
));
4207 /* Test dw2_expand_symtabs_matching_symbol. */
4210 test_dw2_expand_symtabs_matching_symbol ()
4212 mock_mapped_index
mock_index (test_symbols
);
4214 /* We let all tests run until the end even if some fails, for debug
4216 bool any_mismatch
= false;
4218 /* Create the expected symbols list (an initializer_list). Needed
4219 because lists have commas, and we need to pass them to CHECK,
4220 which is a macro. */
4221 #define EXPECT(...) { __VA_ARGS__ }
4223 /* Wrapper for check_match that passes down the current
4224 __FILE__/__LINE__. */
4225 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4226 any_mismatch |= !check_match (__FILE__, __LINE__, \
4228 NAME, MATCH_TYPE, COMPLETION_MODE, \
4231 /* Identity checks. */
4232 for (const char *sym
: test_symbols
)
4234 /* Should be able to match all existing symbols. */
4235 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4238 /* Should be able to match all existing symbols with
4240 std::string with_params
= std::string (sym
) + "(int)";
4241 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4244 /* Should be able to match all existing symbols with
4245 parameters and qualifiers. */
4246 with_params
= std::string (sym
) + " ( int ) const";
4247 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4250 /* This should really find sym, but cp-name-parser.y doesn't
4251 know about lvalue/rvalue qualifiers yet. */
4252 with_params
= std::string (sym
) + " ( int ) &&";
4253 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4257 /* Check that the name matching algorithm for completion doesn't get
4258 confused with Latin1 'ÿ' / 0xff. */
4260 static const char str
[] = "\377";
4261 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4262 EXPECT ("\377", "\377\377123"));
4265 /* Check that the increment-last-char in the matching algorithm for
4266 completion doesn't match "t1_fund" when completing "t1_func". */
4268 static const char str
[] = "t1_func";
4269 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4270 EXPECT ("t1_func", "t1_func1"));
4273 /* Check that completion mode works at each prefix of the expected
4276 static const char str
[] = "function(int)";
4277 size_t len
= strlen (str
);
4280 for (size_t i
= 1; i
< len
; i
++)
4282 lookup
.assign (str
, i
);
4283 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4284 EXPECT ("function"));
4288 /* While "w" is a prefix of both components, the match function
4289 should still only be called once. */
4291 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4293 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4297 /* Same, with a "complicated" symbol. */
4299 static const char str
[] = Z_SYM_NAME
;
4300 size_t len
= strlen (str
);
4303 for (size_t i
= 1; i
< len
; i
++)
4305 lookup
.assign (str
, i
);
4306 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4307 EXPECT (Z_SYM_NAME
));
4311 /* In FULL mode, an incomplete symbol doesn't match. */
4313 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4317 /* A complete symbol with parameters matches any overload, since the
4318 index has no overload info. */
4320 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4321 EXPECT ("std::zfunction", "std::zfunction2"));
4322 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4323 EXPECT ("std::zfunction", "std::zfunction2"));
4324 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4325 EXPECT ("std::zfunction", "std::zfunction2"));
4328 /* Check that whitespace is ignored appropriately. A symbol with a
4329 template argument list. */
4331 static const char expected
[] = "ns::foo<int>";
4332 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4334 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4338 /* Check that whitespace is ignored appropriately. A symbol with a
4339 template argument list that includes a pointer. */
4341 static const char expected
[] = "ns::foo<char*>";
4342 /* Try both completion and non-completion modes. */
4343 static const bool completion_mode
[2] = {false, true};
4344 for (size_t i
= 0; i
< 2; i
++)
4346 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4347 completion_mode
[i
], EXPECT (expected
));
4348 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4349 completion_mode
[i
], EXPECT (expected
));
4351 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4352 completion_mode
[i
], EXPECT (expected
));
4353 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4354 completion_mode
[i
], EXPECT (expected
));
4359 /* Check method qualifiers are ignored. */
4360 static const char expected
[] = "ns::foo<char*>";
4361 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4362 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4363 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4364 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4365 CHECK_MATCH ("foo < char * > ( int ) const",
4366 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4367 CHECK_MATCH ("foo < char * > ( int ) &&",
4368 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4371 /* Test lookup names that don't match anything. */
4373 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4376 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4380 /* Some wild matching tests, exercising "(anonymous namespace)",
4381 which should not be confused with a parameter list. */
4383 static const char *syms
[] = {
4387 "A :: B :: C ( int )",
4392 for (const char *s
: syms
)
4394 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4395 EXPECT ("(anonymous namespace)::A::B::C"));
4400 static const char expected
[] = "ns2::tmpl<int>::foo2";
4401 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4403 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4407 SELF_CHECK (!any_mismatch
);
4416 test_mapped_index_find_name_component_bounds ();
4417 test_dw2_expand_symtabs_matching_symbol ();
4420 }} // namespace selftests::dw2_expand_symtabs_matching
4422 #endif /* GDB_SELF_TEST */
4424 /* If FILE_MATCHER is NULL or if PER_CU has
4425 dwarf2_per_cu_quick_data::MARK set (see
4426 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4427 EXPANSION_NOTIFY on it. */
4430 dw2_expand_symtabs_matching_one
4431 (struct dwarf2_per_cu_data
*per_cu
,
4432 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4433 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4435 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4437 bool symtab_was_null
4438 = (per_cu
->v
.quick
->compunit_symtab
== NULL
);
4440 dw2_instantiate_symtab (per_cu
, false);
4442 if (expansion_notify
!= NULL
4444 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
4445 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
4449 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4450 matched, to expand corresponding CUs that were marked. IDX is the
4451 index of the symbol name that matched. */
4454 dw2_expand_marked_cus
4455 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
4456 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4457 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4460 offset_type
*vec
, vec_len
, vec_idx
;
4461 bool global_seen
= false;
4462 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
4464 vec
= (offset_type
*) (index
.constant_pool
4465 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
4466 vec_len
= MAYBE_SWAP (vec
[0]);
4467 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4469 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
4470 /* This value is only valid for index versions >= 7. */
4471 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4472 gdb_index_symbol_kind symbol_kind
=
4473 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4474 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4475 /* Only check the symbol attributes if they're present.
4476 Indices prior to version 7 don't record them,
4477 and indices >= 7 may elide them for certain symbols
4478 (gold does this). */
4481 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4483 /* Work around gold/15646. */
4486 if (!is_static
&& global_seen
)
4492 /* Only check the symbol's kind if it has one. */
4497 case VARIABLES_DOMAIN
:
4498 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4501 case FUNCTIONS_DOMAIN
:
4502 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4506 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4509 case MODULES_DOMAIN
:
4510 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4518 /* Don't crash on bad data. */
4519 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
4520 + dwarf2_per_objfile
->all_type_units
.size ()))
4522 complaint (_(".gdb_index entry has bad CU index"
4524 objfile_name (dwarf2_per_objfile
->objfile
));
4528 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
4529 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
4534 /* If FILE_MATCHER is non-NULL, set all the
4535 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4536 that match FILE_MATCHER. */
4539 dw_expand_symtabs_matching_file_matcher
4540 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4541 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4543 if (file_matcher
== NULL
)
4546 objfile
*const objfile
= dwarf2_per_objfile
->objfile
;
4548 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4550 NULL
, xcalloc
, xfree
));
4551 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4553 NULL
, xcalloc
, xfree
));
4555 /* The rule is CUs specify all the files, including those used by
4556 any TU, so there's no need to scan TUs here. */
4558 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4562 per_cu
->v
.quick
->mark
= 0;
4564 /* We only need to look at symtabs not already expanded. */
4565 if (per_cu
->v
.quick
->compunit_symtab
)
4568 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4569 if (file_data
== NULL
)
4572 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4574 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4576 per_cu
->v
.quick
->mark
= 1;
4580 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4582 const char *this_real_name
;
4584 if (file_matcher (file_data
->file_names
[j
], false))
4586 per_cu
->v
.quick
->mark
= 1;
4590 /* Before we invoke realpath, which can get expensive when many
4591 files are involved, do a quick comparison of the basenames. */
4592 if (!basenames_may_differ
4593 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4597 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
4598 if (file_matcher (this_real_name
, false))
4600 per_cu
->v
.quick
->mark
= 1;
4605 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4606 ? visited_found
.get ()
4607 : visited_not_found
.get (),
4614 dw2_expand_symtabs_matching
4615 (struct objfile
*objfile
,
4616 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4617 const lookup_name_info
&lookup_name
,
4618 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4619 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4620 enum search_domain kind
)
4622 struct dwarf2_per_objfile
*dwarf2_per_objfile
4623 = get_dwarf2_per_objfile (objfile
);
4625 /* index_table is NULL if OBJF_READNOW. */
4626 if (!dwarf2_per_objfile
->index_table
)
4629 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
4631 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
4633 dw2_expand_symtabs_matching_symbol (index
, lookup_name
,
4635 kind
, [&] (offset_type idx
)
4637 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
4638 expansion_notify
, kind
);
4643 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4646 static struct compunit_symtab
*
4647 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4652 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4653 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4656 if (cust
->includes
== NULL
)
4659 for (i
= 0; cust
->includes
[i
]; ++i
)
4661 struct compunit_symtab
*s
= cust
->includes
[i
];
4663 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4671 static struct compunit_symtab
*
4672 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
4673 struct bound_minimal_symbol msymbol
,
4675 struct obj_section
*section
,
4678 struct dwarf2_per_cu_data
*data
;
4679 struct compunit_symtab
*result
;
4681 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
4684 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4685 data
= (struct dwarf2_per_cu_data
*) addrmap_find
4686 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
4690 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
4691 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4692 paddress (get_objfile_arch (objfile
), pc
));
4695 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
,
4698 gdb_assert (result
!= NULL
);
4703 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
4704 void *data
, int need_fullname
)
4706 struct dwarf2_per_objfile
*dwarf2_per_objfile
4707 = get_dwarf2_per_objfile (objfile
);
4709 if (!dwarf2_per_objfile
->filenames_cache
)
4711 dwarf2_per_objfile
->filenames_cache
.emplace ();
4713 htab_up
visited (htab_create_alloc (10,
4714 htab_hash_pointer
, htab_eq_pointer
,
4715 NULL
, xcalloc
, xfree
));
4717 /* The rule is CUs specify all the files, including those used
4718 by any TU, so there's no need to scan TUs here. We can
4719 ignore file names coming from already-expanded CUs. */
4721 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4723 if (per_cu
->v
.quick
->compunit_symtab
)
4725 void **slot
= htab_find_slot (visited
.get (),
4726 per_cu
->v
.quick
->file_names
,
4729 *slot
= per_cu
->v
.quick
->file_names
;
4733 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4735 /* We only need to look at symtabs not already expanded. */
4736 if (per_cu
->v
.quick
->compunit_symtab
)
4739 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4740 if (file_data
== NULL
)
4743 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
4746 /* Already visited. */
4751 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4753 const char *filename
= file_data
->file_names
[j
];
4754 dwarf2_per_objfile
->filenames_cache
->seen (filename
);
4759 dwarf2_per_objfile
->filenames_cache
->traverse ([&] (const char *filename
)
4761 gdb::unique_xmalloc_ptr
<char> this_real_name
;
4764 this_real_name
= gdb_realpath (filename
);
4765 (*fun
) (filename
, this_real_name
.get (), data
);
4770 dw2_has_symbols (struct objfile
*objfile
)
4775 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
4778 dw2_find_last_source_symtab
,
4779 dw2_forget_cached_source_info
,
4780 dw2_map_symtabs_matching_filename
,
4784 dw2_expand_symtabs_for_function
,
4785 dw2_expand_all_symtabs
,
4786 dw2_expand_symtabs_with_fullname
,
4787 dw2_map_matching_symbols
,
4788 dw2_expand_symtabs_matching
,
4789 dw2_find_pc_sect_compunit_symtab
,
4791 dw2_map_symbol_filenames
4794 /* DWARF-5 debug_names reader. */
4796 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
4797 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
4799 /* A helper function that reads the .debug_names section in SECTION
4800 and fills in MAP. FILENAME is the name of the file containing the
4801 section; it is used for error reporting.
4803 Returns true if all went well, false otherwise. */
4806 read_debug_names_from_section (struct objfile
*objfile
,
4807 const char *filename
,
4808 struct dwarf2_section_info
*section
,
4809 mapped_debug_names
&map
)
4811 if (section
->empty ())
4814 /* Older elfutils strip versions could keep the section in the main
4815 executable while splitting it for the separate debug info file. */
4816 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
4819 section
->read (objfile
);
4821 map
.dwarf5_byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
4823 const gdb_byte
*addr
= section
->buffer
;
4825 bfd
*const abfd
= section
->get_bfd_owner ();
4827 unsigned int bytes_read
;
4828 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
4831 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
4832 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
4833 if (bytes_read
+ length
!= section
->size
)
4835 /* There may be multiple per-CU indices. */
4836 warning (_("Section .debug_names in %s length %s does not match "
4837 "section length %s, ignoring .debug_names."),
4838 filename
, plongest (bytes_read
+ length
),
4839 pulongest (section
->size
));
4843 /* The version number. */
4844 uint16_t version
= read_2_bytes (abfd
, addr
);
4848 warning (_("Section .debug_names in %s has unsupported version %d, "
4849 "ignoring .debug_names."),
4855 uint16_t padding
= read_2_bytes (abfd
, addr
);
4859 warning (_("Section .debug_names in %s has unsupported padding %d, "
4860 "ignoring .debug_names."),
4865 /* comp_unit_count - The number of CUs in the CU list. */
4866 map
.cu_count
= read_4_bytes (abfd
, addr
);
4869 /* local_type_unit_count - The number of TUs in the local TU
4871 map
.tu_count
= read_4_bytes (abfd
, addr
);
4874 /* foreign_type_unit_count - The number of TUs in the foreign TU
4876 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
4878 if (foreign_tu_count
!= 0)
4880 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
4881 "ignoring .debug_names."),
4882 filename
, static_cast<unsigned long> (foreign_tu_count
));
4886 /* bucket_count - The number of hash buckets in the hash lookup
4888 map
.bucket_count
= read_4_bytes (abfd
, addr
);
4891 /* name_count - The number of unique names in the index. */
4892 map
.name_count
= read_4_bytes (abfd
, addr
);
4895 /* abbrev_table_size - The size in bytes of the abbreviations
4897 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
4900 /* augmentation_string_size - The size in bytes of the augmentation
4901 string. This value is rounded up to a multiple of 4. */
4902 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
4904 map
.augmentation_is_gdb
= ((augmentation_string_size
4905 == sizeof (dwarf5_augmentation
))
4906 && memcmp (addr
, dwarf5_augmentation
,
4907 sizeof (dwarf5_augmentation
)) == 0);
4908 augmentation_string_size
+= (-augmentation_string_size
) & 3;
4909 addr
+= augmentation_string_size
;
4912 map
.cu_table_reordered
= addr
;
4913 addr
+= map
.cu_count
* map
.offset_size
;
4915 /* List of Local TUs */
4916 map
.tu_table_reordered
= addr
;
4917 addr
+= map
.tu_count
* map
.offset_size
;
4919 /* Hash Lookup Table */
4920 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4921 addr
+= map
.bucket_count
* 4;
4922 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4923 addr
+= map
.name_count
* 4;
4926 map
.name_table_string_offs_reordered
= addr
;
4927 addr
+= map
.name_count
* map
.offset_size
;
4928 map
.name_table_entry_offs_reordered
= addr
;
4929 addr
+= map
.name_count
* map
.offset_size
;
4931 const gdb_byte
*abbrev_table_start
= addr
;
4934 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4939 const auto insertpair
4940 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
4941 if (!insertpair
.second
)
4943 warning (_("Section .debug_names in %s has duplicate index %s, "
4944 "ignoring .debug_names."),
4945 filename
, pulongest (index_num
));
4948 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
4949 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4954 mapped_debug_names::index_val::attr attr
;
4955 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4957 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4959 if (attr
.form
== DW_FORM_implicit_const
)
4961 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
4965 if (attr
.dw_idx
== 0 && attr
.form
== 0)
4967 indexval
.attr_vec
.push_back (std::move (attr
));
4970 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
4972 warning (_("Section .debug_names in %s has abbreviation_table "
4973 "of size %s vs. written as %u, ignoring .debug_names."),
4974 filename
, plongest (addr
- abbrev_table_start
),
4978 map
.entry_pool
= addr
;
4983 /* A helper for create_cus_from_debug_names that handles the MAP's CU
4987 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4988 const mapped_debug_names
&map
,
4989 dwarf2_section_info
§ion
,
4992 sect_offset sect_off_prev
;
4993 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
4995 sect_offset sect_off_next
;
4996 if (i
< map
.cu_count
)
4999 = (sect_offset
) (extract_unsigned_integer
5000 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5002 map
.dwarf5_byte_order
));
5005 sect_off_next
= (sect_offset
) section
.size
;
5008 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5009 dwarf2_per_cu_data
*per_cu
5010 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
5011 sect_off_prev
, length
);
5012 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
5014 sect_off_prev
= sect_off_next
;
5018 /* Read the CU list from the mapped index, and use it to create all
5019 the CU objects for this dwarf2_per_objfile. */
5022 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5023 const mapped_debug_names
&map
,
5024 const mapped_debug_names
&dwz_map
)
5026 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
5027 dwarf2_per_objfile
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5029 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
5030 dwarf2_per_objfile
->info
,
5031 false /* is_dwz */);
5033 if (dwz_map
.cu_count
== 0)
5036 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5037 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
5041 /* Read .debug_names. If everything went ok, initialize the "quick"
5042 elements of all the CUs and return true. Otherwise, return false. */
5045 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
5047 std::unique_ptr
<mapped_debug_names
> map
5048 (new mapped_debug_names (dwarf2_per_objfile
));
5049 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
5050 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5052 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5053 &dwarf2_per_objfile
->debug_names
,
5057 /* Don't use the index if it's empty. */
5058 if (map
->name_count
== 0)
5061 /* If there is a .dwz file, read it so we can get its CU list as
5063 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5066 if (!read_debug_names_from_section (objfile
,
5067 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5068 &dwz
->debug_names
, dwz_map
))
5070 warning (_("could not read '.debug_names' section from %s; skipping"),
5071 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5076 create_cus_from_debug_names (dwarf2_per_objfile
, *map
, dwz_map
);
5078 if (map
->tu_count
!= 0)
5080 /* We can only handle a single .debug_types when we have an
5082 if (dwarf2_per_objfile
->types
.size () != 1)
5085 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
5087 create_signatured_type_table_from_debug_names
5088 (dwarf2_per_objfile
, *map
, section
, &dwarf2_per_objfile
->abbrev
);
5091 create_addrmap_from_aranges (dwarf2_per_objfile
,
5092 &dwarf2_per_objfile
->debug_aranges
);
5094 dwarf2_per_objfile
->debug_names_table
= std::move (map
);
5095 dwarf2_per_objfile
->using_index
= 1;
5096 dwarf2_per_objfile
->quick_file_names_table
=
5097 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
5102 /* Type used to manage iterating over all CUs looking for a symbol for
5105 class dw2_debug_names_iterator
5108 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5109 gdb::optional
<block_enum
> block_index
,
5112 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5113 m_addr (find_vec_in_debug_names (map
, name
))
5116 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5117 search_domain search
, uint32_t namei
)
5120 m_addr (find_vec_in_debug_names (map
, namei
))
5123 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5124 block_enum block_index
, domain_enum domain
,
5126 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5127 m_addr (find_vec_in_debug_names (map
, namei
))
5130 /* Return the next matching CU or NULL if there are no more. */
5131 dwarf2_per_cu_data
*next ();
5134 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5136 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5139 /* The internalized form of .debug_names. */
5140 const mapped_debug_names
&m_map
;
5142 /* If set, only look for symbols that match that block. Valid values are
5143 GLOBAL_BLOCK and STATIC_BLOCK. */
5144 const gdb::optional
<block_enum
> m_block_index
;
5146 /* The kind of symbol we're looking for. */
5147 const domain_enum m_domain
= UNDEF_DOMAIN
;
5148 const search_domain m_search
= ALL_DOMAIN
;
5150 /* The list of CUs from the index entry of the symbol, or NULL if
5152 const gdb_byte
*m_addr
;
5156 mapped_debug_names::namei_to_name (uint32_t namei
) const
5158 const ULONGEST namei_string_offs
5159 = extract_unsigned_integer ((name_table_string_offs_reordered
5160 + namei
* offset_size
),
5163 return read_indirect_string_at_offset
5164 (dwarf2_per_objfile
, dwarf2_per_objfile
->objfile
->obfd
, namei_string_offs
);
5167 /* Find a slot in .debug_names for the object named NAME. If NAME is
5168 found, return pointer to its pool data. If NAME cannot be found,
5172 dw2_debug_names_iterator::find_vec_in_debug_names
5173 (const mapped_debug_names
&map
, const char *name
)
5175 int (*cmp
) (const char *, const char *);
5177 gdb::unique_xmalloc_ptr
<char> without_params
;
5178 if (current_language
->la_language
== language_cplus
5179 || current_language
->la_language
== language_fortran
5180 || current_language
->la_language
== language_d
)
5182 /* NAME is already canonical. Drop any qualifiers as
5183 .debug_names does not contain any. */
5185 if (strchr (name
, '(') != NULL
)
5187 without_params
= cp_remove_params (name
);
5188 if (without_params
!= NULL
)
5189 name
= without_params
.get ();
5193 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5195 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5197 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5198 (map
.bucket_table_reordered
5199 + (full_hash
% map
.bucket_count
)), 4,
5200 map
.dwarf5_byte_order
);
5204 if (namei
>= map
.name_count
)
5206 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5208 namei
, map
.name_count
,
5209 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5215 const uint32_t namei_full_hash
5216 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5217 (map
.hash_table_reordered
+ namei
), 4,
5218 map
.dwarf5_byte_order
);
5219 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5222 if (full_hash
== namei_full_hash
)
5224 const char *const namei_string
= map
.namei_to_name (namei
);
5226 #if 0 /* An expensive sanity check. */
5227 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5229 complaint (_("Wrong .debug_names hash for string at index %u "
5231 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5236 if (cmp (namei_string
, name
) == 0)
5238 const ULONGEST namei_entry_offs
5239 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5240 + namei
* map
.offset_size
),
5241 map
.offset_size
, map
.dwarf5_byte_order
);
5242 return map
.entry_pool
+ namei_entry_offs
;
5247 if (namei
>= map
.name_count
)
5253 dw2_debug_names_iterator::find_vec_in_debug_names
5254 (const mapped_debug_names
&map
, uint32_t namei
)
5256 if (namei
>= map
.name_count
)
5258 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5260 namei
, map
.name_count
,
5261 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5265 const ULONGEST namei_entry_offs
5266 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5267 + namei
* map
.offset_size
),
5268 map
.offset_size
, map
.dwarf5_byte_order
);
5269 return map
.entry_pool
+ namei_entry_offs
;
5272 /* See dw2_debug_names_iterator. */
5274 dwarf2_per_cu_data
*
5275 dw2_debug_names_iterator::next ()
5280 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
5281 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5282 bfd
*const abfd
= objfile
->obfd
;
5286 unsigned int bytes_read
;
5287 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5288 m_addr
+= bytes_read
;
5292 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5293 if (indexval_it
== m_map
.abbrev_map
.cend ())
5295 complaint (_("Wrong .debug_names undefined abbrev code %s "
5297 pulongest (abbrev
), objfile_name (objfile
));
5300 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5301 enum class symbol_linkage
{
5305 } symbol_linkage_
= symbol_linkage::unknown
;
5306 dwarf2_per_cu_data
*per_cu
= NULL
;
5307 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5312 case DW_FORM_implicit_const
:
5313 ull
= attr
.implicit_const
;
5315 case DW_FORM_flag_present
:
5319 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5320 m_addr
+= bytes_read
;
5323 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5324 dwarf_form_name (attr
.form
),
5325 objfile_name (objfile
));
5328 switch (attr
.dw_idx
)
5330 case DW_IDX_compile_unit
:
5331 /* Don't crash on bad data. */
5332 if (ull
>= dwarf2_per_objfile
->all_comp_units
.size ())
5334 complaint (_(".debug_names entry has bad CU index %s"
5337 objfile_name (dwarf2_per_objfile
->objfile
));
5340 per_cu
= dwarf2_per_objfile
->get_cutu (ull
);
5342 case DW_IDX_type_unit
:
5343 /* Don't crash on bad data. */
5344 if (ull
>= dwarf2_per_objfile
->all_type_units
.size ())
5346 complaint (_(".debug_names entry has bad TU index %s"
5349 objfile_name (dwarf2_per_objfile
->objfile
));
5352 per_cu
= &dwarf2_per_objfile
->get_tu (ull
)->per_cu
;
5354 case DW_IDX_GNU_internal
:
5355 if (!m_map
.augmentation_is_gdb
)
5357 symbol_linkage_
= symbol_linkage::static_
;
5359 case DW_IDX_GNU_external
:
5360 if (!m_map
.augmentation_is_gdb
)
5362 symbol_linkage_
= symbol_linkage::extern_
;
5367 /* Skip if already read in. */
5368 if (per_cu
->v
.quick
->compunit_symtab
)
5371 /* Check static vs global. */
5372 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5374 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5375 const bool symbol_is_static
=
5376 symbol_linkage_
== symbol_linkage::static_
;
5377 if (want_static
!= symbol_is_static
)
5381 /* Match dw2_symtab_iter_next, symbol_kind
5382 and debug_names::psymbol_tag. */
5386 switch (indexval
.dwarf_tag
)
5388 case DW_TAG_variable
:
5389 case DW_TAG_subprogram
:
5390 /* Some types are also in VAR_DOMAIN. */
5391 case DW_TAG_typedef
:
5392 case DW_TAG_structure_type
:
5399 switch (indexval
.dwarf_tag
)
5401 case DW_TAG_typedef
:
5402 case DW_TAG_structure_type
:
5409 switch (indexval
.dwarf_tag
)
5412 case DW_TAG_variable
:
5419 switch (indexval
.dwarf_tag
)
5431 /* Match dw2_expand_symtabs_matching, symbol_kind and
5432 debug_names::psymbol_tag. */
5435 case VARIABLES_DOMAIN
:
5436 switch (indexval
.dwarf_tag
)
5438 case DW_TAG_variable
:
5444 case FUNCTIONS_DOMAIN
:
5445 switch (indexval
.dwarf_tag
)
5447 case DW_TAG_subprogram
:
5454 switch (indexval
.dwarf_tag
)
5456 case DW_TAG_typedef
:
5457 case DW_TAG_structure_type
:
5463 case MODULES_DOMAIN
:
5464 switch (indexval
.dwarf_tag
)
5478 static struct compunit_symtab
*
5479 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
5480 const char *name
, domain_enum domain
)
5482 struct dwarf2_per_objfile
*dwarf2_per_objfile
5483 = get_dwarf2_per_objfile (objfile
);
5485 const auto &mapp
= dwarf2_per_objfile
->debug_names_table
;
5488 /* index is NULL if OBJF_READNOW. */
5491 const auto &map
= *mapp
;
5493 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
);
5495 struct compunit_symtab
*stab_best
= NULL
;
5496 struct dwarf2_per_cu_data
*per_cu
;
5497 while ((per_cu
= iter
.next ()) != NULL
)
5499 struct symbol
*sym
, *with_opaque
= NULL
;
5500 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
5501 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
5502 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
5504 sym
= block_find_symbol (block
, name
, domain
,
5505 block_find_non_opaque_type_preferred
,
5508 /* Some caution must be observed with overloaded functions and
5509 methods, since the index will not contain any overload
5510 information (but NAME might contain it). */
5513 && strcmp_iw (sym
->search_name (), name
) == 0)
5515 if (with_opaque
!= NULL
5516 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
5519 /* Keep looking through other CUs. */
5525 /* This dumps minimal information about .debug_names. It is called
5526 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5527 uses this to verify that .debug_names has been loaded. */
5530 dw2_debug_names_dump (struct objfile
*objfile
)
5532 struct dwarf2_per_objfile
*dwarf2_per_objfile
5533 = get_dwarf2_per_objfile (objfile
);
5535 gdb_assert (dwarf2_per_objfile
->using_index
);
5536 printf_filtered (".debug_names:");
5537 if (dwarf2_per_objfile
->debug_names_table
)
5538 printf_filtered (" exists\n");
5540 printf_filtered (" faked for \"readnow\"\n");
5541 printf_filtered ("\n");
5545 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
5546 const char *func_name
)
5548 struct dwarf2_per_objfile
*dwarf2_per_objfile
5549 = get_dwarf2_per_objfile (objfile
);
5551 /* dwarf2_per_objfile->debug_names_table is NULL if OBJF_READNOW. */
5552 if (dwarf2_per_objfile
->debug_names_table
)
5554 const mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5556 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
);
5558 struct dwarf2_per_cu_data
*per_cu
;
5559 while ((per_cu
= iter
.next ()) != NULL
)
5560 dw2_instantiate_symtab (per_cu
, false);
5565 dw2_debug_names_map_matching_symbols
5566 (struct objfile
*objfile
,
5567 const lookup_name_info
&name
, domain_enum domain
,
5569 gdb::function_view
<symbol_found_callback_ftype
> callback
,
5570 symbol_compare_ftype
*ordered_compare
)
5572 struct dwarf2_per_objfile
*dwarf2_per_objfile
5573 = get_dwarf2_per_objfile (objfile
);
5575 /* debug_names_table is NULL if OBJF_READNOW. */
5576 if (!dwarf2_per_objfile
->debug_names_table
)
5579 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5580 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
5582 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5583 auto matcher
= [&] (const char *symname
)
5585 if (ordered_compare
== nullptr)
5587 return ordered_compare (symname
, match_name
) == 0;
5590 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
5591 [&] (offset_type namei
)
5593 /* The name was matched, now expand corresponding CUs that were
5595 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
);
5597 struct dwarf2_per_cu_data
*per_cu
;
5598 while ((per_cu
= iter
.next ()) != NULL
)
5599 dw2_expand_symtabs_matching_one (per_cu
, nullptr, nullptr);
5603 /* It's a shame we couldn't do this inside the
5604 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
5605 that have already been expanded. Instead, this loop matches what
5606 the psymtab code does. */
5607 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5609 struct compunit_symtab
*cust
= per_cu
->v
.quick
->compunit_symtab
;
5610 if (cust
!= nullptr)
5612 const struct block
*block
5613 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
5614 if (!iterate_over_symbols_terminated (block
, name
,
5622 dw2_debug_names_expand_symtabs_matching
5623 (struct objfile
*objfile
,
5624 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5625 const lookup_name_info
&lookup_name
,
5626 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5627 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5628 enum search_domain kind
)
5630 struct dwarf2_per_objfile
*dwarf2_per_objfile
5631 = get_dwarf2_per_objfile (objfile
);
5633 /* debug_names_table is NULL if OBJF_READNOW. */
5634 if (!dwarf2_per_objfile
->debug_names_table
)
5637 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5639 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5641 dw2_expand_symtabs_matching_symbol (map
, lookup_name
,
5643 kind
, [&] (offset_type namei
)
5645 /* The name was matched, now expand corresponding CUs that were
5647 dw2_debug_names_iterator
iter (map
, kind
, namei
);
5649 struct dwarf2_per_cu_data
*per_cu
;
5650 while ((per_cu
= iter
.next ()) != NULL
)
5651 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5657 const struct quick_symbol_functions dwarf2_debug_names_functions
=
5660 dw2_find_last_source_symtab
,
5661 dw2_forget_cached_source_info
,
5662 dw2_map_symtabs_matching_filename
,
5663 dw2_debug_names_lookup_symbol
,
5665 dw2_debug_names_dump
,
5666 dw2_debug_names_expand_symtabs_for_function
,
5667 dw2_expand_all_symtabs
,
5668 dw2_expand_symtabs_with_fullname
,
5669 dw2_debug_names_map_matching_symbols
,
5670 dw2_debug_names_expand_symtabs_matching
,
5671 dw2_find_pc_sect_compunit_symtab
,
5673 dw2_map_symbol_filenames
5676 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5677 to either a dwarf2_per_objfile or dwz_file object. */
5679 template <typename T
>
5680 static gdb::array_view
<const gdb_byte
>
5681 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5683 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5685 if (section
->empty ())
5688 /* Older elfutils strip versions could keep the section in the main
5689 executable while splitting it for the separate debug info file. */
5690 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5693 section
->read (obj
);
5695 /* dwarf2_section_info::size is a bfd_size_type, while
5696 gdb::array_view works with size_t. On 32-bit hosts, with
5697 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5698 is 32-bit. So we need an explicit narrowing conversion here.
5699 This is fine, because it's impossible to allocate or mmap an
5700 array/buffer larger than what size_t can represent. */
5701 return gdb::make_array_view (section
->buffer
, section
->size
);
5704 /* Lookup the index cache for the contents of the index associated to
5707 static gdb::array_view
<const gdb_byte
>
5708 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_objfile
*dwarf2_obj
)
5710 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5711 if (build_id
== nullptr)
5714 return global_index_cache
.lookup_gdb_index (build_id
,
5715 &dwarf2_obj
->index_cache_res
);
5718 /* Same as the above, but for DWZ. */
5720 static gdb::array_view
<const gdb_byte
>
5721 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5723 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5724 if (build_id
== nullptr)
5727 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5730 /* See symfile.h. */
5733 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
5735 struct dwarf2_per_objfile
*dwarf2_per_objfile
5736 = get_dwarf2_per_objfile (objfile
);
5738 /* If we're about to read full symbols, don't bother with the
5739 indices. In this case we also don't care if some other debug
5740 format is making psymtabs, because they are all about to be
5742 if ((objfile
->flags
& OBJF_READNOW
))
5744 dwarf2_per_objfile
->using_index
= 1;
5745 create_all_comp_units (dwarf2_per_objfile
);
5746 create_all_type_units (dwarf2_per_objfile
);
5747 dwarf2_per_objfile
->quick_file_names_table
5748 = create_quick_file_names_table
5749 (dwarf2_per_objfile
->all_comp_units
.size ());
5751 for (int i
= 0; i
< (dwarf2_per_objfile
->all_comp_units
.size ()
5752 + dwarf2_per_objfile
->all_type_units
.size ()); ++i
)
5754 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
5756 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5757 struct dwarf2_per_cu_quick_data
);
5760 /* Return 1 so that gdb sees the "quick" functions. However,
5761 these functions will be no-ops because we will have expanded
5763 *index_kind
= dw_index_kind::GDB_INDEX
;
5767 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
5769 *index_kind
= dw_index_kind::DEBUG_NAMES
;
5773 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5774 get_gdb_index_contents_from_section
<struct dwarf2_per_objfile
>,
5775 get_gdb_index_contents_from_section
<dwz_file
>))
5777 *index_kind
= dw_index_kind::GDB_INDEX
;
5781 /* ... otherwise, try to find the index in the index cache. */
5782 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5783 get_gdb_index_contents_from_cache
,
5784 get_gdb_index_contents_from_cache_dwz
))
5786 global_index_cache
.hit ();
5787 *index_kind
= dw_index_kind::GDB_INDEX
;
5791 global_index_cache
.miss ();
5797 /* Build a partial symbol table. */
5800 dwarf2_build_psymtabs (struct objfile
*objfile
)
5802 struct dwarf2_per_objfile
*dwarf2_per_objfile
5803 = get_dwarf2_per_objfile (objfile
);
5805 init_psymbol_list (objfile
, 1024);
5809 /* This isn't really ideal: all the data we allocate on the
5810 objfile's obstack is still uselessly kept around. However,
5811 freeing it seems unsafe. */
5812 psymtab_discarder
psymtabs (objfile
);
5813 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
5816 /* (maybe) store an index in the cache. */
5817 global_index_cache
.store (dwarf2_per_objfile
);
5819 catch (const gdb_exception_error
&except
)
5821 exception_print (gdb_stderr
, except
);
5825 /* Find the base address of the compilation unit for range lists and
5826 location lists. It will normally be specified by DW_AT_low_pc.
5827 In DWARF-3 draft 4, the base address could be overridden by
5828 DW_AT_entry_pc. It's been removed, but GCC still uses this for
5829 compilation units with discontinuous ranges. */
5832 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
5834 struct attribute
*attr
;
5837 cu
->base_address
= 0;
5839 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
5840 if (attr
!= nullptr)
5842 cu
->base_address
= attr
->value_as_address ();
5847 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5848 if (attr
!= nullptr)
5850 cu
->base_address
= attr
->value_as_address ();
5856 /* Helper function that returns the proper abbrev section for
5859 static struct dwarf2_section_info
*
5860 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
5862 struct dwarf2_section_info
*abbrev
;
5863 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
5865 if (this_cu
->is_dwz
)
5866 abbrev
= &dwarf2_get_dwz_file (dwarf2_per_objfile
)->abbrev
;
5868 abbrev
= &dwarf2_per_objfile
->abbrev
;
5873 /* Fetch the abbreviation table offset from a comp or type unit header. */
5876 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5877 struct dwarf2_section_info
*section
,
5878 sect_offset sect_off
)
5880 bfd
*abfd
= section
->get_bfd_owner ();
5881 const gdb_byte
*info_ptr
;
5882 unsigned int initial_length_size
, offset_size
;
5885 section
->read (dwarf2_per_objfile
->objfile
);
5886 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
5887 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
5888 offset_size
= initial_length_size
== 4 ? 4 : 8;
5889 info_ptr
+= initial_length_size
;
5891 version
= read_2_bytes (abfd
, info_ptr
);
5895 /* Skip unit type and address size. */
5899 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
5902 /* Allocate a new partial symtab for file named NAME and mark this new
5903 partial symtab as being an include of PST. */
5906 dwarf2_create_include_psymtab (const char *name
, dwarf2_psymtab
*pst
,
5907 struct objfile
*objfile
)
5909 dwarf2_psymtab
*subpst
= new dwarf2_psymtab (name
, objfile
);
5911 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
5913 /* It shares objfile->objfile_obstack. */
5914 subpst
->dirname
= pst
->dirname
;
5917 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
5918 subpst
->dependencies
[0] = pst
;
5919 subpst
->number_of_dependencies
= 1;
5921 /* No private part is necessary for include psymtabs. This property
5922 can be used to differentiate between such include psymtabs and
5923 the regular ones. */
5924 subpst
->per_cu_data
= nullptr;
5927 /* Read the Line Number Program data and extract the list of files
5928 included by the source file represented by PST. Build an include
5929 partial symtab for each of these included files. */
5932 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
5933 struct die_info
*die
,
5934 dwarf2_psymtab
*pst
)
5937 struct attribute
*attr
;
5939 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5940 if (attr
!= nullptr)
5941 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
5943 return; /* No linetable, so no includes. */
5945 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
5946 that we pass in the raw text_low here; that is ok because we're
5947 only decoding the line table to make include partial symtabs, and
5948 so the addresses aren't really used. */
5949 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
5950 pst
->raw_text_low (), 1);
5954 hash_signatured_type (const void *item
)
5956 const struct signatured_type
*sig_type
5957 = (const struct signatured_type
*) item
;
5959 /* This drops the top 32 bits of the signature, but is ok for a hash. */
5960 return sig_type
->signature
;
5964 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
5966 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
5967 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
5969 return lhs
->signature
== rhs
->signature
;
5972 /* Allocate a hash table for signatured types. */
5975 allocate_signatured_type_table (struct objfile
*objfile
)
5977 return htab_up (htab_create_alloc (41,
5978 hash_signatured_type
,
5980 NULL
, xcalloc
, xfree
));
5983 /* A helper function to add a signatured type CU to a table. */
5986 add_signatured_type_cu_to_table (void **slot
, void *datum
)
5988 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
5989 std::vector
<signatured_type
*> *all_type_units
5990 = (std::vector
<signatured_type
*> *) datum
;
5992 all_type_units
->push_back (sigt
);
5997 /* A helper for create_debug_types_hash_table. Read types from SECTION
5998 and fill them into TYPES_HTAB. It will process only type units,
5999 therefore DW_UT_type. */
6002 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6003 struct dwo_file
*dwo_file
,
6004 dwarf2_section_info
*section
, htab_up
&types_htab
,
6005 rcuh_kind section_kind
)
6007 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6008 struct dwarf2_section_info
*abbrev_section
;
6010 const gdb_byte
*info_ptr
, *end_ptr
;
6012 abbrev_section
= (dwo_file
!= NULL
6013 ? &dwo_file
->sections
.abbrev
6014 : &dwarf2_per_objfile
->abbrev
);
6016 if (dwarf_read_debug
)
6017 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6018 section
->get_name (),
6019 abbrev_section
->get_file_name ());
6021 section
->read (objfile
);
6022 info_ptr
= section
->buffer
;
6024 if (info_ptr
== NULL
)
6027 /* We can't set abfd until now because the section may be empty or
6028 not present, in which case the bfd is unknown. */
6029 abfd
= section
->get_bfd_owner ();
6031 /* We don't use cutu_reader here because we don't need to read
6032 any dies: the signature is in the header. */
6034 end_ptr
= info_ptr
+ section
->size
;
6035 while (info_ptr
< end_ptr
)
6037 struct signatured_type
*sig_type
;
6038 struct dwo_unit
*dwo_tu
;
6040 const gdb_byte
*ptr
= info_ptr
;
6041 struct comp_unit_head header
;
6042 unsigned int length
;
6044 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6046 /* Initialize it due to a false compiler warning. */
6047 header
.signature
= -1;
6048 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6050 /* We need to read the type's signature in order to build the hash
6051 table, but we don't need anything else just yet. */
6053 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
6054 abbrev_section
, ptr
, section_kind
);
6056 length
= header
.get_length ();
6058 /* Skip dummy type units. */
6059 if (ptr
>= info_ptr
+ length
6060 || peek_abbrev_code (abfd
, ptr
) == 0
6061 || header
.unit_type
!= DW_UT_type
)
6067 if (types_htab
== NULL
)
6070 types_htab
= allocate_dwo_unit_table (objfile
);
6072 types_htab
= allocate_signatured_type_table (objfile
);
6078 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6080 dwo_tu
->dwo_file
= dwo_file
;
6081 dwo_tu
->signature
= header
.signature
;
6082 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6083 dwo_tu
->section
= section
;
6084 dwo_tu
->sect_off
= sect_off
;
6085 dwo_tu
->length
= length
;
6089 /* N.B.: type_offset is not usable if this type uses a DWO file.
6090 The real type_offset is in the DWO file. */
6092 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6093 struct signatured_type
);
6094 sig_type
->signature
= header
.signature
;
6095 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6096 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6097 sig_type
->per_cu
.is_debug_types
= 1;
6098 sig_type
->per_cu
.section
= section
;
6099 sig_type
->per_cu
.sect_off
= sect_off
;
6100 sig_type
->per_cu
.length
= length
;
6103 slot
= htab_find_slot (types_htab
.get (),
6104 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6106 gdb_assert (slot
!= NULL
);
6109 sect_offset dup_sect_off
;
6113 const struct dwo_unit
*dup_tu
6114 = (const struct dwo_unit
*) *slot
;
6116 dup_sect_off
= dup_tu
->sect_off
;
6120 const struct signatured_type
*dup_tu
6121 = (const struct signatured_type
*) *slot
;
6123 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6126 complaint (_("debug type entry at offset %s is duplicate to"
6127 " the entry at offset %s, signature %s"),
6128 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6129 hex_string (header
.signature
));
6131 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6133 if (dwarf_read_debug
> 1)
6134 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6135 sect_offset_str (sect_off
),
6136 hex_string (header
.signature
));
6142 /* Create the hash table of all entries in the .debug_types
6143 (or .debug_types.dwo) section(s).
6144 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6145 otherwise it is NULL.
6147 The result is a pointer to the hash table or NULL if there are no types.
6149 Note: This function processes DWO files only, not DWP files. */
6152 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6153 struct dwo_file
*dwo_file
,
6154 gdb::array_view
<dwarf2_section_info
> type_sections
,
6155 htab_up
&types_htab
)
6157 for (dwarf2_section_info
§ion
: type_sections
)
6158 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, §ion
,
6159 types_htab
, rcuh_kind::TYPE
);
6162 /* Create the hash table of all entries in the .debug_types section,
6163 and initialize all_type_units.
6164 The result is zero if there is an error (e.g. missing .debug_types section),
6165 otherwise non-zero. */
6168 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6172 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
6173 &dwarf2_per_objfile
->info
, types_htab
,
6174 rcuh_kind::COMPILE
);
6175 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
6176 dwarf2_per_objfile
->types
, types_htab
);
6177 if (types_htab
== NULL
)
6179 dwarf2_per_objfile
->signatured_types
= NULL
;
6183 dwarf2_per_objfile
->signatured_types
= std::move (types_htab
);
6185 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
6186 dwarf2_per_objfile
->all_type_units
.reserve
6187 (htab_elements (dwarf2_per_objfile
->signatured_types
.get ()));
6189 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
.get (),
6190 add_signatured_type_cu_to_table
,
6191 &dwarf2_per_objfile
->all_type_units
);
6196 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
6197 If SLOT is non-NULL, it is the entry to use in the hash table.
6198 Otherwise we find one. */
6200 static struct signatured_type
*
6201 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
6204 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6206 if (dwarf2_per_objfile
->all_type_units
.size ()
6207 == dwarf2_per_objfile
->all_type_units
.capacity ())
6208 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
6210 signatured_type
*sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6211 struct signatured_type
);
6213 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
6214 sig_type
->signature
= sig
;
6215 sig_type
->per_cu
.is_debug_types
= 1;
6216 if (dwarf2_per_objfile
->using_index
)
6218 sig_type
->per_cu
.v
.quick
=
6219 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6220 struct dwarf2_per_cu_quick_data
);
6225 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6228 gdb_assert (*slot
== NULL
);
6230 /* The rest of sig_type must be filled in by the caller. */
6234 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6235 Fill in SIG_ENTRY with DWO_ENTRY. */
6238 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6239 struct signatured_type
*sig_entry
,
6240 struct dwo_unit
*dwo_entry
)
6242 /* Make sure we're not clobbering something we don't expect to. */
6243 gdb_assert (! sig_entry
->per_cu
.queued
);
6244 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
6245 if (dwarf2_per_objfile
->using_index
)
6247 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6248 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
6251 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6252 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6253 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6254 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6255 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6257 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6258 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6259 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6260 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6261 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6262 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6263 sig_entry
->dwo_unit
= dwo_entry
;
6266 /* Subroutine of lookup_signatured_type.
6267 If we haven't read the TU yet, create the signatured_type data structure
6268 for a TU to be read in directly from a DWO file, bypassing the stub.
6269 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6270 using .gdb_index, then when reading a CU we want to stay in the DWO file
6271 containing that CU. Otherwise we could end up reading several other DWO
6272 files (due to comdat folding) to process the transitive closure of all the
6273 mentioned TUs, and that can be slow. The current DWO file will have every
6274 type signature that it needs.
6275 We only do this for .gdb_index because in the psymtab case we already have
6276 to read all the DWOs to build the type unit groups. */
6278 static struct signatured_type
*
6279 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6281 struct dwarf2_per_objfile
*dwarf2_per_objfile
6282 = cu
->per_cu
->dwarf2_per_objfile
;
6283 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6284 struct dwo_file
*dwo_file
;
6285 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6286 struct signatured_type find_sig_entry
, *sig_entry
;
6289 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6291 /* If TU skeletons have been removed then we may not have read in any
6293 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6295 dwarf2_per_objfile
->signatured_types
6296 = allocate_signatured_type_table (objfile
);
6299 /* We only ever need to read in one copy of a signatured type.
6300 Use the global signatured_types array to do our own comdat-folding
6301 of types. If this is the first time we're reading this TU, and
6302 the TU has an entry in .gdb_index, replace the recorded data from
6303 .gdb_index with this TU. */
6305 find_sig_entry
.signature
= sig
;
6306 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6307 &find_sig_entry
, INSERT
);
6308 sig_entry
= (struct signatured_type
*) *slot
;
6310 /* We can get here with the TU already read, *or* in the process of being
6311 read. Don't reassign the global entry to point to this DWO if that's
6312 the case. Also note that if the TU is already being read, it may not
6313 have come from a DWO, the program may be a mix of Fission-compiled
6314 code and non-Fission-compiled code. */
6316 /* Have we already tried to read this TU?
6317 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6318 needn't exist in the global table yet). */
6319 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
6322 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6323 dwo_unit of the TU itself. */
6324 dwo_file
= cu
->dwo_unit
->dwo_file
;
6326 /* Ok, this is the first time we're reading this TU. */
6327 if (dwo_file
->tus
== NULL
)
6329 find_dwo_entry
.signature
= sig
;
6330 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6332 if (dwo_entry
== NULL
)
6335 /* If the global table doesn't have an entry for this TU, add one. */
6336 if (sig_entry
== NULL
)
6337 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6339 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6340 sig_entry
->per_cu
.tu_read
= 1;
6344 /* Subroutine of lookup_signatured_type.
6345 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6346 then try the DWP file. If the TU stub (skeleton) has been removed then
6347 it won't be in .gdb_index. */
6349 static struct signatured_type
*
6350 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6352 struct dwarf2_per_objfile
*dwarf2_per_objfile
6353 = cu
->per_cu
->dwarf2_per_objfile
;
6354 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6355 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
6356 struct dwo_unit
*dwo_entry
;
6357 struct signatured_type find_sig_entry
, *sig_entry
;
6360 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6361 gdb_assert (dwp_file
!= NULL
);
6363 /* If TU skeletons have been removed then we may not have read in any
6365 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6367 dwarf2_per_objfile
->signatured_types
6368 = allocate_signatured_type_table (objfile
);
6371 find_sig_entry
.signature
= sig
;
6372 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6373 &find_sig_entry
, INSERT
);
6374 sig_entry
= (struct signatured_type
*) *slot
;
6376 /* Have we already tried to read this TU?
6377 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6378 needn't exist in the global table yet). */
6379 if (sig_entry
!= NULL
)
6382 if (dwp_file
->tus
== NULL
)
6384 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
6385 sig
, 1 /* is_debug_types */);
6386 if (dwo_entry
== NULL
)
6389 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6390 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6395 /* Lookup a signature based type for DW_FORM_ref_sig8.
6396 Returns NULL if signature SIG is not present in the table.
6397 It is up to the caller to complain about this. */
6399 static struct signatured_type
*
6400 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6402 struct dwarf2_per_objfile
*dwarf2_per_objfile
6403 = cu
->per_cu
->dwarf2_per_objfile
;
6406 && dwarf2_per_objfile
->using_index
)
6408 /* We're in a DWO/DWP file, and we're using .gdb_index.
6409 These cases require special processing. */
6410 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
6411 return lookup_dwo_signatured_type (cu
, sig
);
6413 return lookup_dwp_signatured_type (cu
, sig
);
6417 struct signatured_type find_entry
, *entry
;
6419 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6421 find_entry
.signature
= sig
;
6422 entry
= ((struct signatured_type
*)
6423 htab_find (dwarf2_per_objfile
->signatured_types
.get (),
6429 /* Return the address base of the compile unit, which, if exists, is stored
6430 either at the attribute DW_AT_GNU_addr_base, or DW_AT_addr_base. */
6431 static gdb::optional
<ULONGEST
>
6432 lookup_addr_base (struct die_info
*comp_unit_die
)
6434 struct attribute
*attr
;
6435 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_addr_base
);
6436 if (attr
== nullptr)
6437 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_GNU_addr_base
);
6438 if (attr
== nullptr)
6439 return gdb::optional
<ULONGEST
> ();
6440 return DW_UNSND (attr
);
6443 /* Return range lists base of the compile unit, which, if exists, is stored
6444 either at the attribute DW_AT_rnglists_base or DW_AT_GNU_ranges_base. */
6446 lookup_ranges_base (struct die_info
*comp_unit_die
)
6448 struct attribute
*attr
;
6449 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_rnglists_base
);
6450 if (attr
== nullptr)
6451 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_GNU_ranges_base
);
6452 if (attr
== nullptr)
6454 return DW_UNSND (attr
);
6457 /* Low level DIE reading support. */
6459 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6462 init_cu_die_reader (struct die_reader_specs
*reader
,
6463 struct dwarf2_cu
*cu
,
6464 struct dwarf2_section_info
*section
,
6465 struct dwo_file
*dwo_file
,
6466 struct abbrev_table
*abbrev_table
)
6468 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6469 reader
->abfd
= section
->get_bfd_owner ();
6471 reader
->dwo_file
= dwo_file
;
6472 reader
->die_section
= section
;
6473 reader
->buffer
= section
->buffer
;
6474 reader
->buffer_end
= section
->buffer
+ section
->size
;
6475 reader
->abbrev_table
= abbrev_table
;
6478 /* Subroutine of cutu_reader to simplify it.
6479 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6480 There's just a lot of work to do, and cutu_reader is big enough
6483 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6484 from it to the DIE in the DWO. If NULL we are skipping the stub.
6485 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6486 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6487 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6488 STUB_COMP_DIR may be non-NULL.
6489 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6490 are filled in with the info of the DIE from the DWO file.
6491 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6492 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6493 kept around for at least as long as *RESULT_READER.
6495 The result is non-zero if a valid (non-dummy) DIE was found. */
6498 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
6499 struct dwo_unit
*dwo_unit
,
6500 struct die_info
*stub_comp_unit_die
,
6501 const char *stub_comp_dir
,
6502 struct die_reader_specs
*result_reader
,
6503 const gdb_byte
**result_info_ptr
,
6504 struct die_info
**result_comp_unit_die
,
6505 abbrev_table_up
*result_dwo_abbrev_table
)
6507 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6508 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6509 struct dwarf2_cu
*cu
= this_cu
->cu
;
6511 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6512 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6513 int i
,num_extra_attrs
;
6514 struct dwarf2_section_info
*dwo_abbrev_section
;
6515 struct die_info
*comp_unit_die
;
6517 /* At most one of these may be provided. */
6518 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6520 /* These attributes aren't processed until later:
6521 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6522 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6523 referenced later. However, these attributes are found in the stub
6524 which we won't have later. In order to not impose this complication
6525 on the rest of the code, we read them here and copy them to the
6534 if (stub_comp_unit_die
!= NULL
)
6536 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6538 if (! this_cu
->is_debug_types
)
6539 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6540 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6541 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6542 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6543 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6545 cu
->addr_base
= lookup_addr_base (stub_comp_unit_die
);
6547 /* There should be a DW_AT_rnglists_base (DW_AT_GNU_ranges_base) attribute
6548 here (if needed). We need the value before we can process
6550 cu
->ranges_base
= lookup_ranges_base (stub_comp_unit_die
);
6552 else if (stub_comp_dir
!= NULL
)
6554 /* Reconstruct the comp_dir attribute to simplify the code below. */
6555 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
6556 comp_dir
->name
= DW_AT_comp_dir
;
6557 comp_dir
->form
= DW_FORM_string
;
6558 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
6559 DW_STRING (comp_dir
) = stub_comp_dir
;
6562 /* Set up for reading the DWO CU/TU. */
6563 cu
->dwo_unit
= dwo_unit
;
6564 dwarf2_section_info
*section
= dwo_unit
->section
;
6565 section
->read (objfile
);
6566 abfd
= section
->get_bfd_owner ();
6567 begin_info_ptr
= info_ptr
= (section
->buffer
6568 + to_underlying (dwo_unit
->sect_off
));
6569 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6571 if (this_cu
->is_debug_types
)
6573 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
6575 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6576 &cu
->header
, section
,
6578 info_ptr
, rcuh_kind::TYPE
);
6579 /* This is not an assert because it can be caused by bad debug info. */
6580 if (sig_type
->signature
!= cu
->header
.signature
)
6582 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6583 " TU at offset %s [in module %s]"),
6584 hex_string (sig_type
->signature
),
6585 hex_string (cu
->header
.signature
),
6586 sect_offset_str (dwo_unit
->sect_off
),
6587 bfd_get_filename (abfd
));
6589 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6590 /* For DWOs coming from DWP files, we don't know the CU length
6591 nor the type's offset in the TU until now. */
6592 dwo_unit
->length
= cu
->header
.get_length ();
6593 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6595 /* Establish the type offset that can be used to lookup the type.
6596 For DWO files, we don't know it until now. */
6597 sig_type
->type_offset_in_section
6598 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6602 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6603 &cu
->header
, section
,
6605 info_ptr
, rcuh_kind::COMPILE
);
6606 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6607 /* For DWOs coming from DWP files, we don't know the CU length
6609 dwo_unit
->length
= cu
->header
.get_length ();
6612 *result_dwo_abbrev_table
6613 = abbrev_table::read (objfile
, dwo_abbrev_section
,
6614 cu
->header
.abbrev_sect_off
);
6615 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6616 result_dwo_abbrev_table
->get ());
6618 /* Read in the die, but leave space to copy over the attributes
6619 from the stub. This has the benefit of simplifying the rest of
6620 the code - all the work to maintain the illusion of a single
6621 DW_TAG_{compile,type}_unit DIE is done here. */
6622 num_extra_attrs
= ((stmt_list
!= NULL
)
6626 + (comp_dir
!= NULL
));
6627 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6630 /* Copy over the attributes from the stub to the DIE we just read in. */
6631 comp_unit_die
= *result_comp_unit_die
;
6632 i
= comp_unit_die
->num_attrs
;
6633 if (stmt_list
!= NULL
)
6634 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6636 comp_unit_die
->attrs
[i
++] = *low_pc
;
6637 if (high_pc
!= NULL
)
6638 comp_unit_die
->attrs
[i
++] = *high_pc
;
6640 comp_unit_die
->attrs
[i
++] = *ranges
;
6641 if (comp_dir
!= NULL
)
6642 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6643 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6645 if (dwarf_die_debug
)
6647 fprintf_unfiltered (gdb_stdlog
,
6648 "Read die from %s@0x%x of %s:\n",
6649 section
->get_name (),
6650 (unsigned) (begin_info_ptr
- section
->buffer
),
6651 bfd_get_filename (abfd
));
6652 dump_die (comp_unit_die
, dwarf_die_debug
);
6655 /* Skip dummy compilation units. */
6656 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6657 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6660 *result_info_ptr
= info_ptr
;
6664 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
6665 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
6666 signature is part of the header. */
6667 static gdb::optional
<ULONGEST
>
6668 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
6670 if (cu
->header
.version
>= 5)
6671 return cu
->header
.signature
;
6672 struct attribute
*attr
;
6673 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6674 if (attr
== nullptr)
6675 return gdb::optional
<ULONGEST
> ();
6676 return DW_UNSND (attr
);
6679 /* Subroutine of cutu_reader to simplify it.
6680 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6681 Returns NULL if the specified DWO unit cannot be found. */
6683 static struct dwo_unit
*
6684 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
6685 struct die_info
*comp_unit_die
,
6686 const char *dwo_name
)
6688 struct dwarf2_cu
*cu
= this_cu
->cu
;
6689 struct dwo_unit
*dwo_unit
;
6690 const char *comp_dir
;
6692 gdb_assert (cu
!= NULL
);
6694 /* Yeah, we look dwo_name up again, but it simplifies the code. */
6695 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6696 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6698 if (this_cu
->is_debug_types
)
6700 struct signatured_type
*sig_type
;
6702 /* Since this_cu is the first member of struct signatured_type,
6703 we can go from a pointer to one to a pointer to the other. */
6704 sig_type
= (struct signatured_type
*) this_cu
;
6705 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
6709 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
6710 if (!signature
.has_value ())
6711 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
6713 dwo_name
, objfile_name (this_cu
->dwarf2_per_objfile
->objfile
));
6714 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
6721 /* Subroutine of cutu_reader to simplify it.
6722 See it for a description of the parameters.
6723 Read a TU directly from a DWO file, bypassing the stub. */
6726 cutu_reader::init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
6727 int use_existing_cu
)
6729 struct signatured_type
*sig_type
;
6730 struct die_reader_specs reader
;
6732 /* Verify we can do the following downcast, and that we have the
6734 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
6735 sig_type
= (struct signatured_type
*) this_cu
;
6736 gdb_assert (sig_type
->dwo_unit
!= NULL
);
6738 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
6740 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
6741 /* There's no need to do the rereading_dwo_cu handling that
6742 cutu_reader does since we don't read the stub. */
6746 /* If !use_existing_cu, this_cu->cu must be NULL. */
6747 gdb_assert (this_cu
->cu
== NULL
);
6748 m_new_cu
.reset (new dwarf2_cu (this_cu
));
6751 /* A future optimization, if needed, would be to use an existing
6752 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
6753 could share abbrev tables. */
6755 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
6756 NULL
/* stub_comp_unit_die */,
6757 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
6760 &m_dwo_abbrev_table
) == 0)
6767 /* Initialize a CU (or TU) and read its DIEs.
6768 If the CU defers to a DWO file, read the DWO file as well.
6770 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
6771 Otherwise the table specified in the comp unit header is read in and used.
6772 This is an optimization for when we already have the abbrev table.
6774 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
6775 Otherwise, a new CU is allocated with xmalloc. */
6777 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
6778 struct abbrev_table
*abbrev_table
,
6779 int use_existing_cu
,
6781 : die_reader_specs
{},
6784 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6785 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6786 struct dwarf2_section_info
*section
= this_cu
->section
;
6787 bfd
*abfd
= section
->get_bfd_owner ();
6788 struct dwarf2_cu
*cu
;
6789 const gdb_byte
*begin_info_ptr
;
6790 struct signatured_type
*sig_type
= NULL
;
6791 struct dwarf2_section_info
*abbrev_section
;
6792 /* Non-zero if CU currently points to a DWO file and we need to
6793 reread it. When this happens we need to reread the skeleton die
6794 before we can reread the DWO file (this only applies to CUs, not TUs). */
6795 int rereading_dwo_cu
= 0;
6797 if (dwarf_die_debug
)
6798 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6799 this_cu
->is_debug_types
? "type" : "comp",
6800 sect_offset_str (this_cu
->sect_off
));
6802 /* If we're reading a TU directly from a DWO file, including a virtual DWO
6803 file (instead of going through the stub), short-circuit all of this. */
6804 if (this_cu
->reading_dwo_directly
)
6806 /* Narrow down the scope of possibilities to have to understand. */
6807 gdb_assert (this_cu
->is_debug_types
);
6808 gdb_assert (abbrev_table
== NULL
);
6809 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
);
6813 /* This is cheap if the section is already read in. */
6814 section
->read (objfile
);
6816 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6818 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
6820 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
6823 /* If this CU is from a DWO file we need to start over, we need to
6824 refetch the attributes from the skeleton CU.
6825 This could be optimized by retrieving those attributes from when we
6826 were here the first time: the previous comp_unit_die was stored in
6827 comp_unit_obstack. But there's no data yet that we need this
6829 if (cu
->dwo_unit
!= NULL
)
6830 rereading_dwo_cu
= 1;
6834 /* If !use_existing_cu, this_cu->cu must be NULL. */
6835 gdb_assert (this_cu
->cu
== NULL
);
6836 m_new_cu
.reset (new dwarf2_cu (this_cu
));
6837 cu
= m_new_cu
.get ();
6840 /* Get the header. */
6841 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
6843 /* We already have the header, there's no need to read it in again. */
6844 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
6848 if (this_cu
->is_debug_types
)
6850 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6851 &cu
->header
, section
,
6852 abbrev_section
, info_ptr
,
6855 /* Since per_cu is the first member of struct signatured_type,
6856 we can go from a pointer to one to a pointer to the other. */
6857 sig_type
= (struct signatured_type
*) this_cu
;
6858 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
6859 gdb_assert (sig_type
->type_offset_in_tu
6860 == cu
->header
.type_cu_offset_in_tu
);
6861 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6863 /* LENGTH has not been set yet for type units if we're
6864 using .gdb_index. */
6865 this_cu
->length
= cu
->header
.get_length ();
6867 /* Establish the type offset that can be used to lookup the type. */
6868 sig_type
->type_offset_in_section
=
6869 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
6871 this_cu
->dwarf_version
= cu
->header
.version
;
6875 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6876 &cu
->header
, section
,
6879 rcuh_kind::COMPILE
);
6881 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6882 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
6883 this_cu
->dwarf_version
= cu
->header
.version
;
6887 /* Skip dummy compilation units. */
6888 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6889 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6895 /* If we don't have them yet, read the abbrevs for this compilation unit.
6896 And if we need to read them now, make sure they're freed when we're
6898 if (abbrev_table
!= NULL
)
6899 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
6902 m_abbrev_table_holder
6903 = abbrev_table::read (objfile
, abbrev_section
,
6904 cu
->header
.abbrev_sect_off
);
6905 abbrev_table
= m_abbrev_table_holder
.get ();
6908 /* Read the top level CU/TU die. */
6909 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
6910 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
6912 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
6918 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
6919 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
6920 table from the DWO file and pass the ownership over to us. It will be
6921 referenced from READER, so we must make sure to free it after we're done
6924 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
6925 DWO CU, that this test will fail (the attribute will not be present). */
6926 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6927 if (dwo_name
!= nullptr)
6929 struct dwo_unit
*dwo_unit
;
6930 struct die_info
*dwo_comp_unit_die
;
6932 if (comp_unit_die
->has_children
)
6934 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
6935 " has children (offset %s) [in module %s]"),
6936 sect_offset_str (this_cu
->sect_off
),
6937 bfd_get_filename (abfd
));
6939 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
, dwo_name
);
6940 if (dwo_unit
!= NULL
)
6942 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
6943 comp_unit_die
, NULL
,
6946 &m_dwo_abbrev_table
) == 0)
6952 comp_unit_die
= dwo_comp_unit_die
;
6956 /* Yikes, we couldn't find the rest of the DIE, we only have
6957 the stub. A complaint has already been logged. There's
6958 not much more we can do except pass on the stub DIE to
6959 die_reader_func. We don't want to throw an error on bad
6966 cutu_reader::keep ()
6968 /* Done, clean up. */
6969 gdb_assert (!dummy_p
);
6970 if (m_new_cu
!= NULL
)
6972 struct dwarf2_per_objfile
*dwarf2_per_objfile
6973 = m_this_cu
->dwarf2_per_objfile
;
6974 /* Link this CU into read_in_chain. */
6975 m_this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
6976 dwarf2_per_objfile
->read_in_chain
= m_this_cu
;
6977 /* The chain owns it now. */
6978 m_new_cu
.release ();
6982 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
6983 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
6984 assumed to have already done the lookup to find the DWO file).
6986 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
6987 THIS_CU->is_debug_types, but nothing else.
6989 We fill in THIS_CU->length.
6991 THIS_CU->cu is always freed when done.
6992 This is done in order to not leave THIS_CU->cu in a state where we have
6993 to care whether it refers to the "main" CU or the DWO CU.
6995 When parent_cu is passed, it is used to provide a default value for
6996 str_offsets_base and addr_base from the parent. */
6998 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
6999 struct dwarf2_cu
*parent_cu
,
7000 struct dwo_file
*dwo_file
)
7001 : die_reader_specs
{},
7004 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7005 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7006 struct dwarf2_section_info
*section
= this_cu
->section
;
7007 bfd
*abfd
= section
->get_bfd_owner ();
7008 struct dwarf2_section_info
*abbrev_section
;
7009 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7011 if (dwarf_die_debug
)
7012 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7013 this_cu
->is_debug_types
? "type" : "comp",
7014 sect_offset_str (this_cu
->sect_off
));
7016 gdb_assert (this_cu
->cu
== NULL
);
7018 abbrev_section
= (dwo_file
!= NULL
7019 ? &dwo_file
->sections
.abbrev
7020 : get_abbrev_section_for_cu (this_cu
));
7022 /* This is cheap if the section is already read in. */
7023 section
->read (objfile
);
7025 m_new_cu
.reset (new dwarf2_cu (this_cu
));
7027 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7028 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7029 &m_new_cu
->header
, section
,
7030 abbrev_section
, info_ptr
,
7031 (this_cu
->is_debug_types
7033 : rcuh_kind::COMPILE
));
7035 if (parent_cu
!= nullptr)
7037 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
7038 m_new_cu
->addr_base
= parent_cu
->addr_base
;
7040 this_cu
->length
= m_new_cu
->header
.get_length ();
7042 /* Skip dummy compilation units. */
7043 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7044 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7050 m_abbrev_table_holder
7051 = abbrev_table::read (objfile
, abbrev_section
,
7052 m_new_cu
->header
.abbrev_sect_off
);
7054 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
7055 m_abbrev_table_holder
.get ());
7056 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7060 /* Type Unit Groups.
7062 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7063 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7064 so that all types coming from the same compilation (.o file) are grouped
7065 together. A future step could be to put the types in the same symtab as
7066 the CU the types ultimately came from. */
7069 hash_type_unit_group (const void *item
)
7071 const struct type_unit_group
*tu_group
7072 = (const struct type_unit_group
*) item
;
7074 return hash_stmt_list_entry (&tu_group
->hash
);
7078 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7080 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7081 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7083 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7086 /* Allocate a hash table for type unit groups. */
7089 allocate_type_unit_groups_table (struct objfile
*objfile
)
7091 return htab_up (htab_create_alloc (3,
7092 hash_type_unit_group
,
7094 NULL
, xcalloc
, xfree
));
7097 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7098 partial symtabs. We combine several TUs per psymtab to not let the size
7099 of any one psymtab grow too big. */
7100 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7101 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7103 /* Helper routine for get_type_unit_group.
7104 Create the type_unit_group object used to hold one or more TUs. */
7106 static struct type_unit_group
*
7107 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7109 struct dwarf2_per_objfile
*dwarf2_per_objfile
7110 = cu
->per_cu
->dwarf2_per_objfile
;
7111 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7112 struct dwarf2_per_cu_data
*per_cu
;
7113 struct type_unit_group
*tu_group
;
7115 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7116 struct type_unit_group
);
7117 per_cu
= &tu_group
->per_cu
;
7118 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7120 if (dwarf2_per_objfile
->using_index
)
7122 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7123 struct dwarf2_per_cu_quick_data
);
7127 unsigned int line_offset
= to_underlying (line_offset_struct
);
7128 dwarf2_psymtab
*pst
;
7131 /* Give the symtab a useful name for debug purposes. */
7132 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7133 name
= string_printf ("<type_units_%d>",
7134 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7136 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7138 pst
= create_partial_symtab (per_cu
, name
.c_str ());
7139 pst
->anonymous
= true;
7142 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7143 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7148 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7149 STMT_LIST is a DW_AT_stmt_list attribute. */
7151 static struct type_unit_group
*
7152 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7154 struct dwarf2_per_objfile
*dwarf2_per_objfile
7155 = cu
->per_cu
->dwarf2_per_objfile
;
7156 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7157 struct type_unit_group
*tu_group
;
7159 unsigned int line_offset
;
7160 struct type_unit_group type_unit_group_for_lookup
;
7162 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
7164 dwarf2_per_objfile
->type_unit_groups
=
7165 allocate_type_unit_groups_table (dwarf2_per_objfile
->objfile
);
7168 /* Do we need to create a new group, or can we use an existing one? */
7172 line_offset
= DW_UNSND (stmt_list
);
7173 ++tu_stats
->nr_symtab_sharers
;
7177 /* Ugh, no stmt_list. Rare, but we have to handle it.
7178 We can do various things here like create one group per TU or
7179 spread them over multiple groups to split up the expansion work.
7180 To avoid worst case scenarios (too many groups or too large groups)
7181 we, umm, group them in bunches. */
7182 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7183 | (tu_stats
->nr_stmt_less_type_units
7184 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7185 ++tu_stats
->nr_stmt_less_type_units
;
7188 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7189 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7190 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
.get (),
7191 &type_unit_group_for_lookup
, INSERT
);
7194 tu_group
= (struct type_unit_group
*) *slot
;
7195 gdb_assert (tu_group
!= NULL
);
7199 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7200 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7202 ++tu_stats
->nr_symtabs
;
7208 /* Partial symbol tables. */
7210 /* Create a psymtab named NAME and assign it to PER_CU.
7212 The caller must fill in the following details:
7213 dirname, textlow, texthigh. */
7215 static dwarf2_psymtab
*
7216 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
7218 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
7219 dwarf2_psymtab
*pst
;
7221 pst
= new dwarf2_psymtab (name
, objfile
, 0);
7223 pst
->psymtabs_addrmap_supported
= true;
7225 /* This is the glue that links PST into GDB's symbol API. */
7226 pst
->per_cu_data
= per_cu
;
7227 per_cu
->v
.psymtab
= pst
;
7232 /* DIE reader function for process_psymtab_comp_unit. */
7235 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7236 const gdb_byte
*info_ptr
,
7237 struct die_info
*comp_unit_die
,
7238 enum language pretend_language
)
7240 struct dwarf2_cu
*cu
= reader
->cu
;
7241 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
7242 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7243 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7245 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7246 dwarf2_psymtab
*pst
;
7247 enum pc_bounds_kind cu_bounds_kind
;
7248 const char *filename
;
7250 gdb_assert (! per_cu
->is_debug_types
);
7252 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
7254 /* Allocate a new partial symbol table structure. */
7255 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7256 if (filename
== NULL
)
7259 pst
= create_partial_symtab (per_cu
, filename
);
7261 /* This must be done before calling dwarf2_build_include_psymtabs. */
7262 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7264 baseaddr
= objfile
->text_section_offset ();
7266 dwarf2_find_base_address (comp_unit_die
, cu
);
7268 /* Possibly set the default values of LOWPC and HIGHPC from
7270 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7271 &best_highpc
, cu
, pst
);
7272 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7275 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7278 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7280 /* Store the contiguous range if it is not empty; it can be
7281 empty for CUs with no code. */
7282 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
7286 /* Check if comp unit has_children.
7287 If so, read the rest of the partial symbols from this comp unit.
7288 If not, there's no more debug_info for this comp unit. */
7289 if (comp_unit_die
->has_children
)
7291 struct partial_die_info
*first_die
;
7292 CORE_ADDR lowpc
, highpc
;
7294 lowpc
= ((CORE_ADDR
) -1);
7295 highpc
= ((CORE_ADDR
) 0);
7297 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7299 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7300 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7302 /* If we didn't find a lowpc, set it to highpc to avoid
7303 complaints from `maint check'. */
7304 if (lowpc
== ((CORE_ADDR
) -1))
7307 /* If the compilation unit didn't have an explicit address range,
7308 then use the information extracted from its child dies. */
7309 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7312 best_highpc
= highpc
;
7315 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7316 best_lowpc
+ baseaddr
)
7318 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7319 best_highpc
+ baseaddr
)
7322 end_psymtab_common (objfile
, pst
);
7324 if (!cu
->per_cu
->imported_symtabs_empty ())
7327 int len
= cu
->per_cu
->imported_symtabs_size ();
7329 /* Fill in 'dependencies' here; we fill in 'users' in a
7331 pst
->number_of_dependencies
= len
;
7333 = objfile
->partial_symtabs
->allocate_dependencies (len
);
7334 for (i
= 0; i
< len
; ++i
)
7336 pst
->dependencies
[i
]
7337 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7340 cu
->per_cu
->imported_symtabs_free ();
7343 /* Get the list of files included in the current compilation unit,
7344 and build a psymtab for each of them. */
7345 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
7347 if (dwarf_read_debug
)
7348 fprintf_unfiltered (gdb_stdlog
,
7349 "Psymtab for %s unit @%s: %s - %s"
7350 ", %d global, %d static syms\n",
7351 per_cu
->is_debug_types
? "type" : "comp",
7352 sect_offset_str (per_cu
->sect_off
),
7353 paddress (gdbarch
, pst
->text_low (objfile
)),
7354 paddress (gdbarch
, pst
->text_high (objfile
)),
7355 pst
->n_global_syms
, pst
->n_static_syms
);
7358 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7359 Process compilation unit THIS_CU for a psymtab. */
7362 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
7363 bool want_partial_unit
,
7364 enum language pretend_language
)
7366 /* If this compilation unit was already read in, free the
7367 cached copy in order to read it in again. This is
7368 necessary because we skipped some symbols when we first
7369 read in the compilation unit (see load_partial_dies).
7370 This problem could be avoided, but the benefit is unclear. */
7371 if (this_cu
->cu
!= NULL
)
7372 free_one_cached_comp_unit (this_cu
);
7374 cutu_reader
reader (this_cu
, NULL
, 0, false);
7380 else if (this_cu
->is_debug_types
)
7381 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7382 reader
.comp_unit_die
);
7383 else if (want_partial_unit
7384 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7385 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7386 reader
.comp_unit_die
,
7389 /* Age out any secondary CUs. */
7390 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
7393 /* Reader function for build_type_psymtabs. */
7396 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7397 const gdb_byte
*info_ptr
,
7398 struct die_info
*type_unit_die
)
7400 struct dwarf2_per_objfile
*dwarf2_per_objfile
7401 = reader
->cu
->per_cu
->dwarf2_per_objfile
;
7402 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7403 struct dwarf2_cu
*cu
= reader
->cu
;
7404 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7405 struct signatured_type
*sig_type
;
7406 struct type_unit_group
*tu_group
;
7407 struct attribute
*attr
;
7408 struct partial_die_info
*first_die
;
7409 CORE_ADDR lowpc
, highpc
;
7410 dwarf2_psymtab
*pst
;
7412 gdb_assert (per_cu
->is_debug_types
);
7413 sig_type
= (struct signatured_type
*) per_cu
;
7415 if (! type_unit_die
->has_children
)
7418 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
7419 tu_group
= get_type_unit_group (cu
, attr
);
7421 if (tu_group
->tus
== nullptr)
7422 tu_group
->tus
= new std::vector
<signatured_type
*>;
7423 tu_group
->tus
->push_back (sig_type
);
7425 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7426 pst
= create_partial_symtab (per_cu
, "");
7427 pst
->anonymous
= true;
7429 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7431 lowpc
= (CORE_ADDR
) -1;
7432 highpc
= (CORE_ADDR
) 0;
7433 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7435 end_psymtab_common (objfile
, pst
);
7438 /* Struct used to sort TUs by their abbreviation table offset. */
7440 struct tu_abbrev_offset
7442 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7443 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7446 signatured_type
*sig_type
;
7447 sect_offset abbrev_offset
;
7450 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
7453 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
7454 const struct tu_abbrev_offset
&b
)
7456 return a
.abbrev_offset
< b
.abbrev_offset
;
7459 /* Efficiently read all the type units.
7460 This does the bulk of the work for build_type_psymtabs.
7462 The efficiency is because we sort TUs by the abbrev table they use and
7463 only read each abbrev table once. In one program there are 200K TUs
7464 sharing 8K abbrev tables.
7466 The main purpose of this function is to support building the
7467 dwarf2_per_objfile->type_unit_groups table.
7468 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7469 can collapse the search space by grouping them by stmt_list.
7470 The savings can be significant, in the same program from above the 200K TUs
7471 share 8K stmt_list tables.
7473 FUNC is expected to call get_type_unit_group, which will create the
7474 struct type_unit_group if necessary and add it to
7475 dwarf2_per_objfile->type_unit_groups. */
7478 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7480 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7481 abbrev_table_up abbrev_table
;
7482 sect_offset abbrev_offset
;
7484 /* It's up to the caller to not call us multiple times. */
7485 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
7487 if (dwarf2_per_objfile
->all_type_units
.empty ())
7490 /* TUs typically share abbrev tables, and there can be way more TUs than
7491 abbrev tables. Sort by abbrev table to reduce the number of times we
7492 read each abbrev table in.
7493 Alternatives are to punt or to maintain a cache of abbrev tables.
7494 This is simpler and efficient enough for now.
7496 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7497 symtab to use). Typically TUs with the same abbrev offset have the same
7498 stmt_list value too so in practice this should work well.
7500 The basic algorithm here is:
7502 sort TUs by abbrev table
7503 for each TU with same abbrev table:
7504 read abbrev table if first user
7505 read TU top level DIE
7506 [IWBN if DWO skeletons had DW_AT_stmt_list]
7509 if (dwarf_read_debug
)
7510 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
7512 /* Sort in a separate table to maintain the order of all_type_units
7513 for .gdb_index: TU indices directly index all_type_units. */
7514 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7515 sorted_by_abbrev
.reserve (dwarf2_per_objfile
->all_type_units
.size ());
7517 for (signatured_type
*sig_type
: dwarf2_per_objfile
->all_type_units
)
7518 sorted_by_abbrev
.emplace_back
7519 (sig_type
, read_abbrev_offset (dwarf2_per_objfile
,
7520 sig_type
->per_cu
.section
,
7521 sig_type
->per_cu
.sect_off
));
7523 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
7524 sort_tu_by_abbrev_offset
);
7526 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7528 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7530 /* Switch to the next abbrev table if necessary. */
7531 if (abbrev_table
== NULL
7532 || tu
.abbrev_offset
!= abbrev_offset
)
7534 abbrev_offset
= tu
.abbrev_offset
;
7536 abbrev_table::read (dwarf2_per_objfile
->objfile
,
7537 &dwarf2_per_objfile
->abbrev
,
7539 ++tu_stats
->nr_uniq_abbrev_tables
;
7542 cutu_reader
reader (&tu
.sig_type
->per_cu
, abbrev_table
.get (),
7544 if (!reader
.dummy_p
)
7545 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7546 reader
.comp_unit_die
);
7550 /* Print collected type unit statistics. */
7553 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7555 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7557 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
7558 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
7559 dwarf2_per_objfile
->all_type_units
.size ());
7560 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
7561 tu_stats
->nr_uniq_abbrev_tables
);
7562 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
7563 tu_stats
->nr_symtabs
);
7564 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
7565 tu_stats
->nr_symtab_sharers
);
7566 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
7567 tu_stats
->nr_stmt_less_type_units
);
7568 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
7569 tu_stats
->nr_all_type_units_reallocs
);
7572 /* Traversal function for build_type_psymtabs. */
7575 build_type_psymtab_dependencies (void **slot
, void *info
)
7577 struct dwarf2_per_objfile
*dwarf2_per_objfile
7578 = (struct dwarf2_per_objfile
*) info
;
7579 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7580 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7581 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
7582 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7583 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7586 gdb_assert (len
> 0);
7587 gdb_assert (IS_TYPE_UNIT_GROUP (per_cu
));
7589 pst
->number_of_dependencies
= len
;
7590 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
7591 for (i
= 0; i
< len
; ++i
)
7593 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7594 gdb_assert (iter
->per_cu
.is_debug_types
);
7595 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
7596 iter
->type_unit_group
= tu_group
;
7599 delete tu_group
->tus
;
7600 tu_group
->tus
= nullptr;
7605 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7606 Build partial symbol tables for the .debug_types comp-units. */
7609 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7611 if (! create_all_type_units (dwarf2_per_objfile
))
7614 build_type_psymtabs_1 (dwarf2_per_objfile
);
7617 /* Traversal function for process_skeletonless_type_unit.
7618 Read a TU in a DWO file and build partial symbols for it. */
7621 process_skeletonless_type_unit (void **slot
, void *info
)
7623 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7624 struct dwarf2_per_objfile
*dwarf2_per_objfile
7625 = (struct dwarf2_per_objfile
*) info
;
7626 struct signatured_type find_entry
, *entry
;
7628 /* If this TU doesn't exist in the global table, add it and read it in. */
7630 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7632 dwarf2_per_objfile
->signatured_types
7633 = allocate_signatured_type_table (dwarf2_per_objfile
->objfile
);
7636 find_entry
.signature
= dwo_unit
->signature
;
7637 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
7638 &find_entry
, INSERT
);
7639 /* If we've already seen this type there's nothing to do. What's happening
7640 is we're doing our own version of comdat-folding here. */
7644 /* This does the job that create_all_type_units would have done for
7646 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
7647 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
7650 /* This does the job that build_type_psymtabs_1 would have done. */
7651 cutu_reader
reader (&entry
->per_cu
, NULL
, 0, false);
7652 if (!reader
.dummy_p
)
7653 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7654 reader
.comp_unit_die
);
7659 /* Traversal function for process_skeletonless_type_units. */
7662 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7664 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7666 if (dwo_file
->tus
!= NULL
)
7667 htab_traverse_noresize (dwo_file
->tus
.get (),
7668 process_skeletonless_type_unit
, info
);
7673 /* Scan all TUs of DWO files, verifying we've processed them.
7674 This is needed in case a TU was emitted without its skeleton.
7675 Note: This can't be done until we know what all the DWO files are. */
7678 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7680 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
7681 if (get_dwp_file (dwarf2_per_objfile
) == NULL
7682 && dwarf2_per_objfile
->dwo_files
!= NULL
)
7684 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
.get (),
7685 process_dwo_file_for_skeletonless_type_units
,
7686 dwarf2_per_objfile
);
7690 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
7693 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7695 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
7697 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7702 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
7704 /* Set the 'user' field only if it is not already set. */
7705 if (pst
->dependencies
[j
]->user
== NULL
)
7706 pst
->dependencies
[j
]->user
= pst
;
7711 /* Build the partial symbol table by doing a quick pass through the
7712 .debug_info and .debug_abbrev sections. */
7715 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7717 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7719 if (dwarf_read_debug
)
7721 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
7722 objfile_name (objfile
));
7725 dwarf2_per_objfile
->reading_partial_symbols
= 1;
7727 dwarf2_per_objfile
->info
.read (objfile
);
7729 /* Any cached compilation units will be linked by the per-objfile
7730 read_in_chain. Make sure to free them when we're done. */
7731 free_cached_comp_units
freer (dwarf2_per_objfile
);
7733 build_type_psymtabs (dwarf2_per_objfile
);
7735 create_all_comp_units (dwarf2_per_objfile
);
7737 /* Create a temporary address map on a temporary obstack. We later
7738 copy this to the final obstack. */
7739 auto_obstack temp_obstack
;
7741 scoped_restore save_psymtabs_addrmap
7742 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
7743 addrmap_create_mutable (&temp_obstack
));
7745 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
7746 process_psymtab_comp_unit (per_cu
, false, language_minimal
);
7748 /* This has to wait until we read the CUs, we need the list of DWOs. */
7749 process_skeletonless_type_units (dwarf2_per_objfile
);
7751 /* Now that all TUs have been processed we can fill in the dependencies. */
7752 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
7754 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
.get (),
7755 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
7758 if (dwarf_read_debug
)
7759 print_tu_stats (dwarf2_per_objfile
);
7761 set_partial_user (dwarf2_per_objfile
);
7763 objfile
->partial_symtabs
->psymtabs_addrmap
7764 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
7765 objfile
->partial_symtabs
->obstack ());
7766 /* At this point we want to keep the address map. */
7767 save_psymtabs_addrmap
.release ();
7769 if (dwarf_read_debug
)
7770 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
7771 objfile_name (objfile
));
7774 /* Load the partial DIEs for a secondary CU into memory.
7775 This is also used when rereading a primary CU with load_all_dies. */
7778 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
7780 cutu_reader
reader (this_cu
, NULL
, 1, false);
7782 if (!reader
.dummy_p
)
7784 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
7787 /* Check if comp unit has_children.
7788 If so, read the rest of the partial symbols from this comp unit.
7789 If not, there's no more debug_info for this comp unit. */
7790 if (reader
.comp_unit_die
->has_children
)
7791 load_partial_dies (&reader
, reader
.info_ptr
, 0);
7798 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
7799 struct dwarf2_section_info
*section
,
7800 struct dwarf2_section_info
*abbrev_section
,
7801 unsigned int is_dwz
)
7803 const gdb_byte
*info_ptr
;
7804 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7806 if (dwarf_read_debug
)
7807 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
7808 section
->get_name (),
7809 section
->get_file_name ());
7811 section
->read (objfile
);
7813 info_ptr
= section
->buffer
;
7815 while (info_ptr
< section
->buffer
+ section
->size
)
7817 struct dwarf2_per_cu_data
*this_cu
;
7819 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
7821 comp_unit_head cu_header
;
7822 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
7823 abbrev_section
, info_ptr
,
7824 rcuh_kind::COMPILE
);
7826 /* Save the compilation unit for later lookup. */
7827 if (cu_header
.unit_type
!= DW_UT_type
)
7829 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
7830 struct dwarf2_per_cu_data
);
7831 memset (this_cu
, 0, sizeof (*this_cu
));
7835 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
7836 struct signatured_type
);
7837 memset (sig_type
, 0, sizeof (*sig_type
));
7838 sig_type
->signature
= cu_header
.signature
;
7839 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
7840 this_cu
= &sig_type
->per_cu
;
7842 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
7843 this_cu
->sect_off
= sect_off
;
7844 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
7845 this_cu
->is_dwz
= is_dwz
;
7846 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7847 this_cu
->section
= section
;
7849 dwarf2_per_objfile
->all_comp_units
.push_back (this_cu
);
7851 info_ptr
= info_ptr
+ this_cu
->length
;
7855 /* Create a list of all compilation units in OBJFILE.
7856 This is only done for -readnow and building partial symtabs. */
7859 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7861 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
7862 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->info
,
7863 &dwarf2_per_objfile
->abbrev
, 0);
7865 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
7867 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
7871 /* Process all loaded DIEs for compilation unit CU, starting at
7872 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
7873 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
7874 DW_AT_ranges). See the comments of add_partial_subprogram on how
7875 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
7878 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
7879 CORE_ADDR
*highpc
, int set_addrmap
,
7880 struct dwarf2_cu
*cu
)
7882 struct partial_die_info
*pdi
;
7884 /* Now, march along the PDI's, descending into ones which have
7885 interesting children but skipping the children of the other ones,
7886 until we reach the end of the compilation unit. */
7894 /* Anonymous namespaces or modules have no name but have interesting
7895 children, so we need to look at them. Ditto for anonymous
7898 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
7899 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
7900 || pdi
->tag
== DW_TAG_imported_unit
7901 || pdi
->tag
== DW_TAG_inlined_subroutine
)
7905 case DW_TAG_subprogram
:
7906 case DW_TAG_inlined_subroutine
:
7907 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7909 case DW_TAG_constant
:
7910 case DW_TAG_variable
:
7911 case DW_TAG_typedef
:
7912 case DW_TAG_union_type
:
7913 if (!pdi
->is_declaration
)
7915 add_partial_symbol (pdi
, cu
);
7918 case DW_TAG_class_type
:
7919 case DW_TAG_interface_type
:
7920 case DW_TAG_structure_type
:
7921 if (!pdi
->is_declaration
)
7923 add_partial_symbol (pdi
, cu
);
7925 if ((cu
->language
== language_rust
7926 || cu
->language
== language_cplus
) && pdi
->has_children
)
7927 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
7930 case DW_TAG_enumeration_type
:
7931 if (!pdi
->is_declaration
)
7932 add_partial_enumeration (pdi
, cu
);
7934 case DW_TAG_base_type
:
7935 case DW_TAG_subrange_type
:
7936 /* File scope base type definitions are added to the partial
7938 add_partial_symbol (pdi
, cu
);
7940 case DW_TAG_namespace
:
7941 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7944 if (!pdi
->is_declaration
)
7945 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7947 case DW_TAG_imported_unit
:
7949 struct dwarf2_per_cu_data
*per_cu
;
7951 /* For now we don't handle imported units in type units. */
7952 if (cu
->per_cu
->is_debug_types
)
7954 error (_("Dwarf Error: DW_TAG_imported_unit is not"
7955 " supported in type units [in module %s]"),
7956 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
7959 per_cu
= dwarf2_find_containing_comp_unit
7960 (pdi
->d
.sect_off
, pdi
->is_dwz
,
7961 cu
->per_cu
->dwarf2_per_objfile
);
7963 /* Go read the partial unit, if needed. */
7964 if (per_cu
->v
.psymtab
== NULL
)
7965 process_psymtab_comp_unit (per_cu
, true, cu
->language
);
7967 cu
->per_cu
->imported_symtabs_push (per_cu
);
7970 case DW_TAG_imported_declaration
:
7971 add_partial_symbol (pdi
, cu
);
7978 /* If the die has a sibling, skip to the sibling. */
7980 pdi
= pdi
->die_sibling
;
7984 /* Functions used to compute the fully scoped name of a partial DIE.
7986 Normally, this is simple. For C++, the parent DIE's fully scoped
7987 name is concatenated with "::" and the partial DIE's name.
7988 Enumerators are an exception; they use the scope of their parent
7989 enumeration type, i.e. the name of the enumeration type is not
7990 prepended to the enumerator.
7992 There are two complexities. One is DW_AT_specification; in this
7993 case "parent" means the parent of the target of the specification,
7994 instead of the direct parent of the DIE. The other is compilers
7995 which do not emit DW_TAG_namespace; in this case we try to guess
7996 the fully qualified name of structure types from their members'
7997 linkage names. This must be done using the DIE's children rather
7998 than the children of any DW_AT_specification target. We only need
7999 to do this for structures at the top level, i.e. if the target of
8000 any DW_AT_specification (if any; otherwise the DIE itself) does not
8003 /* Compute the scope prefix associated with PDI's parent, in
8004 compilation unit CU. The result will be allocated on CU's
8005 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8006 field. NULL is returned if no prefix is necessary. */
8008 partial_die_parent_scope (struct partial_die_info
*pdi
,
8009 struct dwarf2_cu
*cu
)
8011 const char *grandparent_scope
;
8012 struct partial_die_info
*parent
, *real_pdi
;
8014 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8015 then this means the parent of the specification DIE. */
8018 while (real_pdi
->has_specification
)
8020 auto res
= find_partial_die (real_pdi
->spec_offset
,
8021 real_pdi
->spec_is_dwz
, cu
);
8026 parent
= real_pdi
->die_parent
;
8030 if (parent
->scope_set
)
8031 return parent
->scope
;
8035 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8037 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8038 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8039 Work around this problem here. */
8040 if (cu
->language
== language_cplus
8041 && parent
->tag
== DW_TAG_namespace
8042 && strcmp (parent
->name
, "::") == 0
8043 && grandparent_scope
== NULL
)
8045 parent
->scope
= NULL
;
8046 parent
->scope_set
= 1;
8050 /* Nested subroutines in Fortran get a prefix. */
8051 if (pdi
->tag
== DW_TAG_enumerator
)
8052 /* Enumerators should not get the name of the enumeration as a prefix. */
8053 parent
->scope
= grandparent_scope
;
8054 else if (parent
->tag
== DW_TAG_namespace
8055 || parent
->tag
== DW_TAG_module
8056 || parent
->tag
== DW_TAG_structure_type
8057 || parent
->tag
== DW_TAG_class_type
8058 || parent
->tag
== DW_TAG_interface_type
8059 || parent
->tag
== DW_TAG_union_type
8060 || parent
->tag
== DW_TAG_enumeration_type
8061 || (cu
->language
== language_fortran
8062 && parent
->tag
== DW_TAG_subprogram
8063 && pdi
->tag
== DW_TAG_subprogram
))
8065 if (grandparent_scope
== NULL
)
8066 parent
->scope
= parent
->name
;
8068 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8070 parent
->name
, 0, cu
);
8074 /* FIXME drow/2004-04-01: What should we be doing with
8075 function-local names? For partial symbols, we should probably be
8077 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8078 dwarf_tag_name (parent
->tag
),
8079 sect_offset_str (pdi
->sect_off
));
8080 parent
->scope
= grandparent_scope
;
8083 parent
->scope_set
= 1;
8084 return parent
->scope
;
8087 /* Return the fully scoped name associated with PDI, from compilation unit
8088 CU. The result will be allocated with malloc. */
8090 static gdb::unique_xmalloc_ptr
<char>
8091 partial_die_full_name (struct partial_die_info
*pdi
,
8092 struct dwarf2_cu
*cu
)
8094 const char *parent_scope
;
8096 /* If this is a template instantiation, we can not work out the
8097 template arguments from partial DIEs. So, unfortunately, we have
8098 to go through the full DIEs. At least any work we do building
8099 types here will be reused if full symbols are loaded later. */
8100 if (pdi
->has_template_arguments
)
8104 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
8106 struct die_info
*die
;
8107 struct attribute attr
;
8108 struct dwarf2_cu
*ref_cu
= cu
;
8110 /* DW_FORM_ref_addr is using section offset. */
8111 attr
.name
= (enum dwarf_attribute
) 0;
8112 attr
.form
= DW_FORM_ref_addr
;
8113 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8114 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8116 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8120 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8121 if (parent_scope
== NULL
)
8124 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8129 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8131 struct dwarf2_per_objfile
*dwarf2_per_objfile
8132 = cu
->per_cu
->dwarf2_per_objfile
;
8133 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8134 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8136 const char *actual_name
= NULL
;
8139 baseaddr
= objfile
->text_section_offset ();
8141 gdb::unique_xmalloc_ptr
<char> built_actual_name
8142 = partial_die_full_name (pdi
, cu
);
8143 if (built_actual_name
!= NULL
)
8144 actual_name
= built_actual_name
.get ();
8146 if (actual_name
== NULL
)
8147 actual_name
= pdi
->name
;
8151 case DW_TAG_inlined_subroutine
:
8152 case DW_TAG_subprogram
:
8153 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8155 if (pdi
->is_external
8156 || cu
->language
== language_ada
8157 || (cu
->language
== language_fortran
8158 && pdi
->die_parent
!= NULL
8159 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8161 /* Normally, only "external" DIEs are part of the global scope.
8162 But in Ada and Fortran, we want to be able to access nested
8163 procedures globally. So all Ada and Fortran subprograms are
8164 stored in the global scope. */
8165 add_psymbol_to_list (actual_name
,
8166 built_actual_name
!= NULL
,
8167 VAR_DOMAIN
, LOC_BLOCK
,
8168 SECT_OFF_TEXT (objfile
),
8169 psymbol_placement::GLOBAL
,
8171 cu
->language
, objfile
);
8175 add_psymbol_to_list (actual_name
,
8176 built_actual_name
!= NULL
,
8177 VAR_DOMAIN
, LOC_BLOCK
,
8178 SECT_OFF_TEXT (objfile
),
8179 psymbol_placement::STATIC
,
8180 addr
, cu
->language
, objfile
);
8183 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8184 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8186 case DW_TAG_constant
:
8187 add_psymbol_to_list (actual_name
,
8188 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
8189 -1, (pdi
->is_external
8190 ? psymbol_placement::GLOBAL
8191 : psymbol_placement::STATIC
),
8192 0, cu
->language
, objfile
);
8194 case DW_TAG_variable
:
8196 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8200 && !dwarf2_per_objfile
->has_section_at_zero
)
8202 /* A global or static variable may also have been stripped
8203 out by the linker if unused, in which case its address
8204 will be nullified; do not add such variables into partial
8205 symbol table then. */
8207 else if (pdi
->is_external
)
8210 Don't enter into the minimal symbol tables as there is
8211 a minimal symbol table entry from the ELF symbols already.
8212 Enter into partial symbol table if it has a location
8213 descriptor or a type.
8214 If the location descriptor is missing, new_symbol will create
8215 a LOC_UNRESOLVED symbol, the address of the variable will then
8216 be determined from the minimal symbol table whenever the variable
8218 The address for the partial symbol table entry is not
8219 used by GDB, but it comes in handy for debugging partial symbol
8222 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8223 add_psymbol_to_list (actual_name
,
8224 built_actual_name
!= NULL
,
8225 VAR_DOMAIN
, LOC_STATIC
,
8226 SECT_OFF_TEXT (objfile
),
8227 psymbol_placement::GLOBAL
,
8228 addr
, cu
->language
, objfile
);
8232 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8234 /* Static Variable. Skip symbols whose value we cannot know (those
8235 without location descriptors or constant values). */
8236 if (!has_loc
&& !pdi
->has_const_value
)
8239 add_psymbol_to_list (actual_name
,
8240 built_actual_name
!= NULL
,
8241 VAR_DOMAIN
, LOC_STATIC
,
8242 SECT_OFF_TEXT (objfile
),
8243 psymbol_placement::STATIC
,
8245 cu
->language
, objfile
);
8248 case DW_TAG_typedef
:
8249 case DW_TAG_base_type
:
8250 case DW_TAG_subrange_type
:
8251 add_psymbol_to_list (actual_name
,
8252 built_actual_name
!= NULL
,
8253 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
8254 psymbol_placement::STATIC
,
8255 0, cu
->language
, objfile
);
8257 case DW_TAG_imported_declaration
:
8258 case DW_TAG_namespace
:
8259 add_psymbol_to_list (actual_name
,
8260 built_actual_name
!= NULL
,
8261 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
8262 psymbol_placement::GLOBAL
,
8263 0, cu
->language
, objfile
);
8266 /* With Fortran 77 there might be a "BLOCK DATA" module
8267 available without any name. If so, we skip the module as it
8268 doesn't bring any value. */
8269 if (actual_name
!= nullptr)
8270 add_psymbol_to_list (actual_name
,
8271 built_actual_name
!= NULL
,
8272 MODULE_DOMAIN
, LOC_TYPEDEF
, -1,
8273 psymbol_placement::GLOBAL
,
8274 0, cu
->language
, objfile
);
8276 case DW_TAG_class_type
:
8277 case DW_TAG_interface_type
:
8278 case DW_TAG_structure_type
:
8279 case DW_TAG_union_type
:
8280 case DW_TAG_enumeration_type
:
8281 /* Skip external references. The DWARF standard says in the section
8282 about "Structure, Union, and Class Type Entries": "An incomplete
8283 structure, union or class type is represented by a structure,
8284 union or class entry that does not have a byte size attribute
8285 and that has a DW_AT_declaration attribute." */
8286 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8289 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8290 static vs. global. */
8291 add_psymbol_to_list (actual_name
,
8292 built_actual_name
!= NULL
,
8293 STRUCT_DOMAIN
, LOC_TYPEDEF
, -1,
8294 cu
->language
== language_cplus
8295 ? psymbol_placement::GLOBAL
8296 : psymbol_placement::STATIC
,
8297 0, cu
->language
, objfile
);
8300 case DW_TAG_enumerator
:
8301 add_psymbol_to_list (actual_name
,
8302 built_actual_name
!= NULL
,
8303 VAR_DOMAIN
, LOC_CONST
, -1,
8304 cu
->language
== language_cplus
8305 ? psymbol_placement::GLOBAL
8306 : psymbol_placement::STATIC
,
8307 0, cu
->language
, objfile
);
8314 /* Read a partial die corresponding to a namespace; also, add a symbol
8315 corresponding to that namespace to the symbol table. NAMESPACE is
8316 the name of the enclosing namespace. */
8319 add_partial_namespace (struct partial_die_info
*pdi
,
8320 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8321 int set_addrmap
, struct dwarf2_cu
*cu
)
8323 /* Add a symbol for the namespace. */
8325 add_partial_symbol (pdi
, cu
);
8327 /* Now scan partial symbols in that namespace. */
8329 if (pdi
->has_children
)
8330 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8333 /* Read a partial die corresponding to a Fortran module. */
8336 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8337 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8339 /* Add a symbol for the namespace. */
8341 add_partial_symbol (pdi
, cu
);
8343 /* Now scan partial symbols in that module. */
8345 if (pdi
->has_children
)
8346 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8349 /* Read a partial die corresponding to a subprogram or an inlined
8350 subprogram and create a partial symbol for that subprogram.
8351 When the CU language allows it, this routine also defines a partial
8352 symbol for each nested subprogram that this subprogram contains.
8353 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8354 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8356 PDI may also be a lexical block, in which case we simply search
8357 recursively for subprograms defined inside that lexical block.
8358 Again, this is only performed when the CU language allows this
8359 type of definitions. */
8362 add_partial_subprogram (struct partial_die_info
*pdi
,
8363 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8364 int set_addrmap
, struct dwarf2_cu
*cu
)
8366 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8368 if (pdi
->has_pc_info
)
8370 if (pdi
->lowpc
< *lowpc
)
8371 *lowpc
= pdi
->lowpc
;
8372 if (pdi
->highpc
> *highpc
)
8373 *highpc
= pdi
->highpc
;
8376 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
8377 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8379 CORE_ADDR this_highpc
;
8380 CORE_ADDR this_lowpc
;
8382 baseaddr
= objfile
->text_section_offset ();
8384 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8385 pdi
->lowpc
+ baseaddr
)
8388 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8389 pdi
->highpc
+ baseaddr
)
8391 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8392 this_lowpc
, this_highpc
- 1,
8393 cu
->per_cu
->v
.psymtab
);
8397 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8399 if (!pdi
->is_declaration
)
8400 /* Ignore subprogram DIEs that do not have a name, they are
8401 illegal. Do not emit a complaint at this point, we will
8402 do so when we convert this psymtab into a symtab. */
8404 add_partial_symbol (pdi
, cu
);
8408 if (! pdi
->has_children
)
8411 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
8413 pdi
= pdi
->die_child
;
8417 if (pdi
->tag
== DW_TAG_subprogram
8418 || pdi
->tag
== DW_TAG_inlined_subroutine
8419 || pdi
->tag
== DW_TAG_lexical_block
)
8420 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8421 pdi
= pdi
->die_sibling
;
8426 /* Read a partial die corresponding to an enumeration type. */
8429 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8430 struct dwarf2_cu
*cu
)
8432 struct partial_die_info
*pdi
;
8434 if (enum_pdi
->name
!= NULL
)
8435 add_partial_symbol (enum_pdi
, cu
);
8437 pdi
= enum_pdi
->die_child
;
8440 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
8441 complaint (_("malformed enumerator DIE ignored"));
8443 add_partial_symbol (pdi
, cu
);
8444 pdi
= pdi
->die_sibling
;
8448 /* Return the initial uleb128 in the die at INFO_PTR. */
8451 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8453 unsigned int bytes_read
;
8455 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8458 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8459 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8461 Return the corresponding abbrev, or NULL if the number is zero (indicating
8462 an empty DIE). In either case *BYTES_READ will be set to the length of
8463 the initial number. */
8465 static struct abbrev_info
*
8466 peek_die_abbrev (const die_reader_specs
&reader
,
8467 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8469 dwarf2_cu
*cu
= reader
.cu
;
8470 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
8471 unsigned int abbrev_number
8472 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8474 if (abbrev_number
== 0)
8477 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8480 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8481 " at offset %s [in module %s]"),
8482 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8483 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8489 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8490 Returns a pointer to the end of a series of DIEs, terminated by an empty
8491 DIE. Any children of the skipped DIEs will also be skipped. */
8493 static const gdb_byte
*
8494 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8498 unsigned int bytes_read
;
8499 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
8502 return info_ptr
+ bytes_read
;
8504 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8508 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8509 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8510 abbrev corresponding to that skipped uleb128 should be passed in
8511 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8514 static const gdb_byte
*
8515 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8516 struct abbrev_info
*abbrev
)
8518 unsigned int bytes_read
;
8519 struct attribute attr
;
8520 bfd
*abfd
= reader
->abfd
;
8521 struct dwarf2_cu
*cu
= reader
->cu
;
8522 const gdb_byte
*buffer
= reader
->buffer
;
8523 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8524 unsigned int form
, i
;
8526 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8528 /* The only abbrev we care about is DW_AT_sibling. */
8529 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8532 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
,
8534 if (attr
.form
== DW_FORM_ref_addr
)
8535 complaint (_("ignoring absolute DW_AT_sibling"));
8538 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
8539 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8541 if (sibling_ptr
< info_ptr
)
8542 complaint (_("DW_AT_sibling points backwards"));
8543 else if (sibling_ptr
> reader
->buffer_end
)
8544 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
8550 /* If it isn't DW_AT_sibling, skip this attribute. */
8551 form
= abbrev
->attrs
[i
].form
;
8555 case DW_FORM_ref_addr
:
8556 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8557 and later it is offset sized. */
8558 if (cu
->header
.version
== 2)
8559 info_ptr
+= cu
->header
.addr_size
;
8561 info_ptr
+= cu
->header
.offset_size
;
8563 case DW_FORM_GNU_ref_alt
:
8564 info_ptr
+= cu
->header
.offset_size
;
8567 info_ptr
+= cu
->header
.addr_size
;
8575 case DW_FORM_flag_present
:
8576 case DW_FORM_implicit_const
:
8593 case DW_FORM_ref_sig8
:
8596 case DW_FORM_data16
:
8599 case DW_FORM_string
:
8600 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8601 info_ptr
+= bytes_read
;
8603 case DW_FORM_sec_offset
:
8605 case DW_FORM_GNU_strp_alt
:
8606 info_ptr
+= cu
->header
.offset_size
;
8608 case DW_FORM_exprloc
:
8610 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8611 info_ptr
+= bytes_read
;
8613 case DW_FORM_block1
:
8614 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8616 case DW_FORM_block2
:
8617 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8619 case DW_FORM_block4
:
8620 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8626 case DW_FORM_ref_udata
:
8627 case DW_FORM_GNU_addr_index
:
8628 case DW_FORM_GNU_str_index
:
8629 case DW_FORM_rnglistx
:
8630 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8632 case DW_FORM_indirect
:
8633 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8634 info_ptr
+= bytes_read
;
8635 /* We need to continue parsing from here, so just go back to
8637 goto skip_attribute
;
8640 error (_("Dwarf Error: Cannot handle %s "
8641 "in DWARF reader [in module %s]"),
8642 dwarf_form_name (form
),
8643 bfd_get_filename (abfd
));
8647 if (abbrev
->has_children
)
8648 return skip_children (reader
, info_ptr
);
8653 /* Locate ORIG_PDI's sibling.
8654 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8656 static const gdb_byte
*
8657 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8658 struct partial_die_info
*orig_pdi
,
8659 const gdb_byte
*info_ptr
)
8661 /* Do we know the sibling already? */
8663 if (orig_pdi
->sibling
)
8664 return orig_pdi
->sibling
;
8666 /* Are there any children to deal with? */
8668 if (!orig_pdi
->has_children
)
8671 /* Skip the children the long way. */
8673 return skip_children (reader
, info_ptr
);
8676 /* Expand this partial symbol table into a full symbol table. SELF is
8680 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
8682 struct dwarf2_per_objfile
*dwarf2_per_objfile
8683 = get_dwarf2_per_objfile (objfile
);
8685 gdb_assert (!readin
);
8686 /* If this psymtab is constructed from a debug-only objfile, the
8687 has_section_at_zero flag will not necessarily be correct. We
8688 can get the correct value for this flag by looking at the data
8689 associated with the (presumably stripped) associated objfile. */
8690 if (objfile
->separate_debug_objfile_backlink
)
8692 struct dwarf2_per_objfile
*dpo_backlink
8693 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
8695 dwarf2_per_objfile
->has_section_at_zero
8696 = dpo_backlink
->has_section_at_zero
;
8699 dwarf2_per_objfile
->reading_partial_symbols
= 0;
8701 expand_psymtab (objfile
);
8703 process_cu_includes (dwarf2_per_objfile
);
8706 /* Reading in full CUs. */
8708 /* Add PER_CU to the queue. */
8711 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
8712 enum language pretend_language
)
8715 per_cu
->dwarf2_per_objfile
->queue
.emplace (per_cu
, pretend_language
);
8718 /* If PER_CU is not yet queued, add it to the queue.
8719 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
8721 The result is non-zero if PER_CU was queued, otherwise the result is zero
8722 meaning either PER_CU is already queued or it is already loaded.
8724 N.B. There is an invariant here that if a CU is queued then it is loaded.
8725 The caller is required to load PER_CU if we return non-zero. */
8728 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
8729 struct dwarf2_per_cu_data
*per_cu
,
8730 enum language pretend_language
)
8732 /* We may arrive here during partial symbol reading, if we need full
8733 DIEs to process an unusual case (e.g. template arguments). Do
8734 not queue PER_CU, just tell our caller to load its DIEs. */
8735 if (per_cu
->dwarf2_per_objfile
->reading_partial_symbols
)
8737 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
8742 /* Mark the dependence relation so that we don't flush PER_CU
8744 if (dependent_cu
!= NULL
)
8745 dwarf2_add_dependence (dependent_cu
, per_cu
);
8747 /* If it's already on the queue, we have nothing to do. */
8751 /* If the compilation unit is already loaded, just mark it as
8753 if (per_cu
->cu
!= NULL
)
8755 per_cu
->cu
->last_used
= 0;
8759 /* Add it to the queue. */
8760 queue_comp_unit (per_cu
, pretend_language
);
8765 /* Process the queue. */
8768 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8770 if (dwarf_read_debug
)
8772 fprintf_unfiltered (gdb_stdlog
,
8773 "Expanding one or more symtabs of objfile %s ...\n",
8774 objfile_name (dwarf2_per_objfile
->objfile
));
8777 /* The queue starts out with one item, but following a DIE reference
8778 may load a new CU, adding it to the end of the queue. */
8779 while (!dwarf2_per_objfile
->queue
.empty ())
8781 dwarf2_queue_item
&item
= dwarf2_per_objfile
->queue
.front ();
8783 if ((dwarf2_per_objfile
->using_index
8784 ? !item
.per_cu
->v
.quick
->compunit_symtab
8785 : (item
.per_cu
->v
.psymtab
&& !item
.per_cu
->v
.psymtab
->readin
))
8786 /* Skip dummy CUs. */
8787 && item
.per_cu
->cu
!= NULL
)
8789 struct dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
8790 unsigned int debug_print_threshold
;
8793 if (per_cu
->is_debug_types
)
8795 struct signatured_type
*sig_type
=
8796 (struct signatured_type
*) per_cu
;
8798 sprintf (buf
, "TU %s at offset %s",
8799 hex_string (sig_type
->signature
),
8800 sect_offset_str (per_cu
->sect_off
));
8801 /* There can be 100s of TUs.
8802 Only print them in verbose mode. */
8803 debug_print_threshold
= 2;
8807 sprintf (buf
, "CU at offset %s",
8808 sect_offset_str (per_cu
->sect_off
));
8809 debug_print_threshold
= 1;
8812 if (dwarf_read_debug
>= debug_print_threshold
)
8813 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
8815 if (per_cu
->is_debug_types
)
8816 process_full_type_unit (per_cu
, item
.pretend_language
);
8818 process_full_comp_unit (per_cu
, item
.pretend_language
);
8820 if (dwarf_read_debug
>= debug_print_threshold
)
8821 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
8824 item
.per_cu
->queued
= 0;
8825 dwarf2_per_objfile
->queue
.pop ();
8828 if (dwarf_read_debug
)
8830 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
8831 objfile_name (dwarf2_per_objfile
->objfile
));
8835 /* Read in full symbols for PST, and anything it depends on. */
8838 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
8840 struct dwarf2_per_cu_data
*per_cu
;
8845 read_dependencies (objfile
);
8847 per_cu
= per_cu_data
;
8851 /* It's an include file, no symbols to read for it.
8852 Everything is in the parent symtab. */
8857 dw2_do_instantiate_symtab (per_cu
, false);
8860 /* Trivial hash function for die_info: the hash value of a DIE
8861 is its offset in .debug_info for this objfile. */
8864 die_hash (const void *item
)
8866 const struct die_info
*die
= (const struct die_info
*) item
;
8868 return to_underlying (die
->sect_off
);
8871 /* Trivial comparison function for die_info structures: two DIEs
8872 are equal if they have the same offset. */
8875 die_eq (const void *item_lhs
, const void *item_rhs
)
8877 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
8878 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
8880 return die_lhs
->sect_off
== die_rhs
->sect_off
;
8883 /* Load the DIEs associated with PER_CU into memory. */
8886 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8888 enum language pretend_language
)
8890 gdb_assert (! this_cu
->is_debug_types
);
8892 cutu_reader
reader (this_cu
, NULL
, 1, skip_partial
);
8896 struct dwarf2_cu
*cu
= reader
.cu
;
8897 const gdb_byte
*info_ptr
= reader
.info_ptr
;
8899 gdb_assert (cu
->die_hash
== NULL
);
8901 htab_create_alloc_ex (cu
->header
.length
/ 12,
8905 &cu
->comp_unit_obstack
,
8906 hashtab_obstack_allocate
,
8907 dummy_obstack_deallocate
);
8909 if (reader
.comp_unit_die
->has_children
)
8910 reader
.comp_unit_die
->child
8911 = read_die_and_siblings (&reader
, reader
.info_ptr
,
8912 &info_ptr
, reader
.comp_unit_die
);
8913 cu
->dies
= reader
.comp_unit_die
;
8914 /* comp_unit_die is not stored in die_hash, no need. */
8916 /* We try not to read any attributes in this function, because not
8917 all CUs needed for references have been loaded yet, and symbol
8918 table processing isn't initialized. But we have to set the CU language,
8919 or we won't be able to build types correctly.
8920 Similarly, if we do not read the producer, we can not apply
8921 producer-specific interpretation. */
8922 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
8927 /* Add a DIE to the delayed physname list. */
8930 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
8931 const char *name
, struct die_info
*die
,
8932 struct dwarf2_cu
*cu
)
8934 struct delayed_method_info mi
;
8936 mi
.fnfield_index
= fnfield_index
;
8940 cu
->method_list
.push_back (mi
);
8943 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
8944 "const" / "volatile". If so, decrements LEN by the length of the
8945 modifier and return true. Otherwise return false. */
8949 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
8951 size_t mod_len
= sizeof (mod
) - 1;
8952 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
8960 /* Compute the physnames of any methods on the CU's method list.
8962 The computation of method physnames is delayed in order to avoid the
8963 (bad) condition that one of the method's formal parameters is of an as yet
8967 compute_delayed_physnames (struct dwarf2_cu
*cu
)
8969 /* Only C++ delays computing physnames. */
8970 if (cu
->method_list
.empty ())
8972 gdb_assert (cu
->language
== language_cplus
);
8974 for (const delayed_method_info
&mi
: cu
->method_list
)
8976 const char *physname
;
8977 struct fn_fieldlist
*fn_flp
8978 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
8979 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
8980 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
8981 = physname
? physname
: "";
8983 /* Since there's no tag to indicate whether a method is a
8984 const/volatile overload, extract that information out of the
8986 if (physname
!= NULL
)
8988 size_t len
= strlen (physname
);
8992 if (physname
[len
] == ')') /* shortcut */
8994 else if (check_modifier (physname
, len
, " const"))
8995 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
8996 else if (check_modifier (physname
, len
, " volatile"))
8997 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9004 /* The list is no longer needed. */
9005 cu
->method_list
.clear ();
9008 /* Go objects should be embedded in a DW_TAG_module DIE,
9009 and it's not clear if/how imported objects will appear.
9010 To keep Go support simple until that's worked out,
9011 go back through what we've read and create something usable.
9012 We could do this while processing each DIE, and feels kinda cleaner,
9013 but that way is more invasive.
9014 This is to, for example, allow the user to type "p var" or "b main"
9015 without having to specify the package name, and allow lookups
9016 of module.object to work in contexts that use the expression
9020 fixup_go_packaging (struct dwarf2_cu
*cu
)
9022 gdb::unique_xmalloc_ptr
<char> package_name
;
9023 struct pending
*list
;
9026 for (list
= *cu
->get_builder ()->get_global_symbols ();
9030 for (i
= 0; i
< list
->nsyms
; ++i
)
9032 struct symbol
*sym
= list
->symbol
[i
];
9034 if (sym
->language () == language_go
9035 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9037 gdb::unique_xmalloc_ptr
<char> this_package_name
9038 (go_symbol_package_name (sym
));
9040 if (this_package_name
== NULL
)
9042 if (package_name
== NULL
)
9043 package_name
= std::move (this_package_name
);
9046 struct objfile
*objfile
9047 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9048 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9049 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9050 (symbol_symtab (sym
) != NULL
9051 ? symtab_to_filename_for_display
9052 (symbol_symtab (sym
))
9053 : objfile_name (objfile
)),
9054 this_package_name
.get (), package_name
.get ());
9060 if (package_name
!= NULL
)
9062 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9063 const char *saved_package_name
9064 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
, package_name
.get ());
9065 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9066 saved_package_name
);
9069 sym
= allocate_symbol (objfile
);
9070 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9071 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9072 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9073 e.g., "main" finds the "main" module and not C's main(). */
9074 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9075 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9076 SYMBOL_TYPE (sym
) = type
;
9078 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9082 /* Allocate a fully-qualified name consisting of the two parts on the
9086 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9088 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9091 /* A helper that allocates a struct discriminant_info to attach to a
9094 static struct discriminant_info
*
9095 alloc_discriminant_info (struct type
*type
, int discriminant_index
,
9098 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9099 gdb_assert (discriminant_index
== -1
9100 || (discriminant_index
>= 0
9101 && discriminant_index
< TYPE_NFIELDS (type
)));
9102 gdb_assert (default_index
== -1
9103 || (default_index
>= 0 && default_index
< TYPE_NFIELDS (type
)));
9105 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
9107 struct discriminant_info
*disc
9108 = ((struct discriminant_info
*)
9110 offsetof (struct discriminant_info
, discriminants
)
9111 + TYPE_NFIELDS (type
) * sizeof (disc
->discriminants
[0])));
9112 disc
->default_index
= default_index
;
9113 disc
->discriminant_index
= discriminant_index
;
9115 struct dynamic_prop prop
;
9116 prop
.kind
= PROP_UNDEFINED
;
9117 prop
.data
.baton
= disc
;
9119 add_dyn_prop (DYN_PROP_DISCRIMINATED
, prop
, type
);
9124 /* Some versions of rustc emitted enums in an unusual way.
9126 Ordinary enums were emitted as unions. The first element of each
9127 structure in the union was named "RUST$ENUM$DISR". This element
9128 held the discriminant.
9130 These versions of Rust also implemented the "non-zero"
9131 optimization. When the enum had two values, and one is empty and
9132 the other holds a pointer that cannot be zero, the pointer is used
9133 as the discriminant, with a zero value meaning the empty variant.
9134 Here, the union's first member is of the form
9135 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9136 where the fieldnos are the indices of the fields that should be
9137 traversed in order to find the field (which may be several fields deep)
9138 and the variantname is the name of the variant of the case when the
9141 This function recognizes whether TYPE is of one of these forms,
9142 and, if so, smashes it to be a variant type. */
9145 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9147 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9149 /* We don't need to deal with empty enums. */
9150 if (TYPE_NFIELDS (type
) == 0)
9153 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9154 if (TYPE_NFIELDS (type
) == 1
9155 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9157 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9159 /* Decode the field name to find the offset of the
9161 ULONGEST bit_offset
= 0;
9162 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9163 while (name
[0] >= '0' && name
[0] <= '9')
9166 unsigned long index
= strtoul (name
, &tail
, 10);
9169 || index
>= TYPE_NFIELDS (field_type
)
9170 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9171 != FIELD_LOC_KIND_BITPOS
))
9173 complaint (_("Could not parse Rust enum encoding string \"%s\""
9175 TYPE_FIELD_NAME (type
, 0),
9176 objfile_name (objfile
));
9181 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9182 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
9185 /* Make a union to hold the variants. */
9186 struct type
*union_type
= alloc_type (objfile
);
9187 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9188 TYPE_NFIELDS (union_type
) = 3;
9189 TYPE_FIELDS (union_type
)
9190 = (struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
));
9191 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9192 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9194 /* Put the discriminant must at index 0. */
9195 TYPE_FIELD_TYPE (union_type
, 0) = field_type
;
9196 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
9197 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
9198 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 0), bit_offset
);
9200 /* The order of fields doesn't really matter, so put the real
9201 field at index 1 and the data-less field at index 2. */
9202 struct discriminant_info
*disc
9203 = alloc_discriminant_info (union_type
, 0, 1);
9204 TYPE_FIELD (union_type
, 1) = TYPE_FIELD (type
, 0);
9205 TYPE_FIELD_NAME (union_type
, 1)
9206 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1)));
9207 TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1))
9208 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9209 TYPE_FIELD_NAME (union_type
, 1));
9211 const char *dataless_name
9212 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9214 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9216 TYPE_FIELD_TYPE (union_type
, 2) = dataless_type
;
9217 /* NAME points into the original discriminant name, which
9218 already has the correct lifetime. */
9219 TYPE_FIELD_NAME (union_type
, 2) = name
;
9220 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 2), 0);
9221 disc
->discriminants
[2] = 0;
9223 /* Smash this type to be a structure type. We have to do this
9224 because the type has already been recorded. */
9225 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9226 TYPE_NFIELDS (type
) = 1;
9228 = (struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
));
9230 /* Install the variant part. */
9231 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9232 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9233 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9235 /* A union with a single anonymous field is probably an old-style
9237 else if (TYPE_NFIELDS (type
) == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
9239 /* Smash this type to be a structure type. We have to do this
9240 because the type has already been recorded. */
9241 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9243 /* Make a union to hold the variants. */
9244 struct type
*union_type
= alloc_type (objfile
);
9245 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9246 TYPE_NFIELDS (union_type
) = TYPE_NFIELDS (type
);
9247 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9248 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9249 TYPE_FIELDS (union_type
) = TYPE_FIELDS (type
);
9251 struct type
*field_type
= TYPE_FIELD_TYPE (union_type
, 0);
9252 const char *variant_name
9253 = rust_last_path_segment (TYPE_NAME (field_type
));
9254 TYPE_FIELD_NAME (union_type
, 0) = variant_name
;
9255 TYPE_NAME (field_type
)
9256 = rust_fully_qualify (&objfile
->objfile_obstack
,
9257 TYPE_NAME (type
), variant_name
);
9259 /* Install the union in the outer struct type. */
9260 TYPE_NFIELDS (type
) = 1;
9262 = (struct field
*) TYPE_ZALLOC (union_type
, sizeof (struct field
));
9263 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9264 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9265 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9267 alloc_discriminant_info (union_type
, -1, 0);
9271 struct type
*disr_type
= nullptr;
9272 for (int i
= 0; i
< TYPE_NFIELDS (type
); ++i
)
9274 disr_type
= TYPE_FIELD_TYPE (type
, i
);
9276 if (TYPE_CODE (disr_type
) != TYPE_CODE_STRUCT
)
9278 /* All fields of a true enum will be structs. */
9281 else if (TYPE_NFIELDS (disr_type
) == 0)
9283 /* Could be data-less variant, so keep going. */
9284 disr_type
= nullptr;
9286 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9287 "RUST$ENUM$DISR") != 0)
9289 /* Not a Rust enum. */
9299 /* If we got here without a discriminant, then it's probably
9301 if (disr_type
== nullptr)
9304 /* Smash this type to be a structure type. We have to do this
9305 because the type has already been recorded. */
9306 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9308 /* Make a union to hold the variants. */
9309 struct field
*disr_field
= &TYPE_FIELD (disr_type
, 0);
9310 struct type
*union_type
= alloc_type (objfile
);
9311 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9312 TYPE_NFIELDS (union_type
) = 1 + TYPE_NFIELDS (type
);
9313 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9314 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9315 TYPE_FIELDS (union_type
)
9316 = (struct field
*) TYPE_ZALLOC (union_type
,
9317 (TYPE_NFIELDS (union_type
)
9318 * sizeof (struct field
)));
9320 memcpy (TYPE_FIELDS (union_type
) + 1, TYPE_FIELDS (type
),
9321 TYPE_NFIELDS (type
) * sizeof (struct field
));
9323 /* Install the discriminant at index 0 in the union. */
9324 TYPE_FIELD (union_type
, 0) = *disr_field
;
9325 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
9326 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
9328 /* Install the union in the outer struct type. */
9329 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9330 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9331 TYPE_NFIELDS (type
) = 1;
9333 /* Set the size and offset of the union type. */
9334 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9336 /* We need a way to find the correct discriminant given a
9337 variant name. For convenience we build a map here. */
9338 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
9339 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9340 for (int i
= 0; i
< TYPE_NFIELDS (enum_type
); ++i
)
9342 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9345 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9346 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9350 int n_fields
= TYPE_NFIELDS (union_type
);
9351 struct discriminant_info
*disc
9352 = alloc_discriminant_info (union_type
, 0, -1);
9353 /* Skip the discriminant here. */
9354 for (int i
= 1; i
< n_fields
; ++i
)
9356 /* Find the final word in the name of this variant's type.
9357 That name can be used to look up the correct
9359 const char *variant_name
9360 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
,
9363 auto iter
= discriminant_map
.find (variant_name
);
9364 if (iter
!= discriminant_map
.end ())
9365 disc
->discriminants
[i
] = iter
->second
;
9367 /* Remove the discriminant field, if it exists. */
9368 struct type
*sub_type
= TYPE_FIELD_TYPE (union_type
, i
);
9369 if (TYPE_NFIELDS (sub_type
) > 0)
9371 --TYPE_NFIELDS (sub_type
);
9372 ++TYPE_FIELDS (sub_type
);
9374 TYPE_FIELD_NAME (union_type
, i
) = variant_name
;
9375 TYPE_NAME (sub_type
)
9376 = rust_fully_qualify (&objfile
->objfile_obstack
,
9377 TYPE_NAME (type
), variant_name
);
9382 /* Rewrite some Rust unions to be structures with variants parts. */
9385 rust_union_quirks (struct dwarf2_cu
*cu
)
9387 gdb_assert (cu
->language
== language_rust
);
9388 for (type
*type_
: cu
->rust_unions
)
9389 quirk_rust_enum (type_
, cu
->per_cu
->dwarf2_per_objfile
->objfile
);
9390 /* We don't need this any more. */
9391 cu
->rust_unions
.clear ();
9394 /* Return the symtab for PER_CU. This works properly regardless of
9395 whether we're using the index or psymtabs. */
9397 static struct compunit_symtab
*
9398 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
9400 return (per_cu
->dwarf2_per_objfile
->using_index
9401 ? per_cu
->v
.quick
->compunit_symtab
9402 : per_cu
->v
.psymtab
->compunit_symtab
);
9405 /* A helper function for computing the list of all symbol tables
9406 included by PER_CU. */
9409 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9410 htab_t all_children
, htab_t all_type_symtabs
,
9411 struct dwarf2_per_cu_data
*per_cu
,
9412 struct compunit_symtab
*immediate_parent
)
9415 struct compunit_symtab
*cust
;
9417 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9420 /* This inclusion and its children have been processed. */
9425 /* Only add a CU if it has a symbol table. */
9426 cust
= get_compunit_symtab (per_cu
);
9429 /* If this is a type unit only add its symbol table if we haven't
9430 seen it yet (type unit per_cu's can share symtabs). */
9431 if (per_cu
->is_debug_types
)
9433 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9437 result
->push_back (cust
);
9438 if (cust
->user
== NULL
)
9439 cust
->user
= immediate_parent
;
9444 result
->push_back (cust
);
9445 if (cust
->user
== NULL
)
9446 cust
->user
= immediate_parent
;
9450 if (!per_cu
->imported_symtabs_empty ())
9451 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9453 recursively_compute_inclusions (result
, all_children
,
9454 all_type_symtabs
, ptr
, cust
);
9458 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9462 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
9464 gdb_assert (! per_cu
->is_debug_types
);
9466 if (!per_cu
->imported_symtabs_empty ())
9469 std::vector
<compunit_symtab
*> result_symtabs
;
9470 htab_t all_children
, all_type_symtabs
;
9471 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
9473 /* If we don't have a symtab, we can just skip this case. */
9477 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9478 NULL
, xcalloc
, xfree
);
9479 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9480 NULL
, xcalloc
, xfree
);
9482 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9484 recursively_compute_inclusions (&result_symtabs
, all_children
,
9485 all_type_symtabs
, ptr
, cust
);
9488 /* Now we have a transitive closure of all the included symtabs. */
9489 len
= result_symtabs
.size ();
9491 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
9492 struct compunit_symtab
*, len
+ 1);
9493 memcpy (cust
->includes
, result_symtabs
.data (),
9494 len
* sizeof (compunit_symtab
*));
9495 cust
->includes
[len
] = NULL
;
9497 htab_delete (all_children
);
9498 htab_delete (all_type_symtabs
);
9502 /* Compute the 'includes' field for the symtabs of all the CUs we just
9506 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9508 for (dwarf2_per_cu_data
*iter
: dwarf2_per_objfile
->just_read_cus
)
9510 if (! iter
->is_debug_types
)
9511 compute_compunit_symtab_includes (iter
);
9514 dwarf2_per_objfile
->just_read_cus
.clear ();
9517 /* Generate full symbol information for PER_CU, whose DIEs have
9518 already been loaded into memory. */
9521 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9522 enum language pretend_language
)
9524 struct dwarf2_cu
*cu
= per_cu
->cu
;
9525 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
9526 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9527 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9528 CORE_ADDR lowpc
, highpc
;
9529 struct compunit_symtab
*cust
;
9531 struct block
*static_block
;
9534 baseaddr
= objfile
->text_section_offset ();
9536 /* Clear the list here in case something was left over. */
9537 cu
->method_list
.clear ();
9539 cu
->language
= pretend_language
;
9540 cu
->language_defn
= language_def (cu
->language
);
9542 /* Do line number decoding in read_file_scope () */
9543 process_die (cu
->dies
, cu
);
9545 /* For now fudge the Go package. */
9546 if (cu
->language
== language_go
)
9547 fixup_go_packaging (cu
);
9549 /* Now that we have processed all the DIEs in the CU, all the types
9550 should be complete, and it should now be safe to compute all of the
9552 compute_delayed_physnames (cu
);
9554 if (cu
->language
== language_rust
)
9555 rust_union_quirks (cu
);
9557 /* Some compilers don't define a DW_AT_high_pc attribute for the
9558 compilation unit. If the DW_AT_high_pc is missing, synthesize
9559 it, by scanning the DIE's below the compilation unit. */
9560 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9562 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9563 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
9565 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9566 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9567 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9568 addrmap to help ensure it has an accurate map of pc values belonging to
9570 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9572 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
9573 SECT_OFF_TEXT (objfile
),
9578 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9580 /* Set symtab language to language from DW_AT_language. If the
9581 compilation is from a C file generated by language preprocessors, do
9582 not set the language if it was already deduced by start_subfile. */
9583 if (!(cu
->language
== language_c
9584 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
9585 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9587 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9588 produce DW_AT_location with location lists but it can be possibly
9589 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9590 there were bugs in prologue debug info, fixed later in GCC-4.5
9591 by "unwind info for epilogues" patch (which is not directly related).
9593 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9594 needed, it would be wrong due to missing DW_AT_producer there.
9596 Still one can confuse GDB by using non-standard GCC compilation
9597 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9599 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9600 cust
->locations_valid
= 1;
9602 if (gcc_4_minor
>= 5)
9603 cust
->epilogue_unwind_valid
= 1;
9605 cust
->call_site_htab
= cu
->call_site_htab
;
9608 if (dwarf2_per_objfile
->using_index
)
9609 per_cu
->v
.quick
->compunit_symtab
= cust
;
9612 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
9613 pst
->compunit_symtab
= cust
;
9617 /* Push it for inclusion processing later. */
9618 dwarf2_per_objfile
->just_read_cus
.push_back (per_cu
);
9620 /* Not needed any more. */
9621 cu
->reset_builder ();
9624 /* Generate full symbol information for type unit PER_CU, whose DIEs have
9625 already been loaded into memory. */
9628 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
9629 enum language pretend_language
)
9631 struct dwarf2_cu
*cu
= per_cu
->cu
;
9632 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
9633 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9634 struct compunit_symtab
*cust
;
9635 struct signatured_type
*sig_type
;
9637 gdb_assert (per_cu
->is_debug_types
);
9638 sig_type
= (struct signatured_type
*) per_cu
;
9640 /* Clear the list here in case something was left over. */
9641 cu
->method_list
.clear ();
9643 cu
->language
= pretend_language
;
9644 cu
->language_defn
= language_def (cu
->language
);
9646 /* The symbol tables are set up in read_type_unit_scope. */
9647 process_die (cu
->dies
, cu
);
9649 /* For now fudge the Go package. */
9650 if (cu
->language
== language_go
)
9651 fixup_go_packaging (cu
);
9653 /* Now that we have processed all the DIEs in the CU, all the types
9654 should be complete, and it should now be safe to compute all of the
9656 compute_delayed_physnames (cu
);
9658 if (cu
->language
== language_rust
)
9659 rust_union_quirks (cu
);
9661 /* TUs share symbol tables.
9662 If this is the first TU to use this symtab, complete the construction
9663 of it with end_expandable_symtab. Otherwise, complete the addition of
9664 this TU's symbols to the existing symtab. */
9665 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
9667 buildsym_compunit
*builder
= cu
->get_builder ();
9668 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
9669 sig_type
->type_unit_group
->compunit_symtab
= cust
;
9673 /* Set symtab language to language from DW_AT_language. If the
9674 compilation is from a C file generated by language preprocessors,
9675 do not set the language if it was already deduced by
9677 if (!(cu
->language
== language_c
9678 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
9679 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9684 cu
->get_builder ()->augment_type_symtab ();
9685 cust
= sig_type
->type_unit_group
->compunit_symtab
;
9688 if (dwarf2_per_objfile
->using_index
)
9689 per_cu
->v
.quick
->compunit_symtab
= cust
;
9692 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
9693 pst
->compunit_symtab
= cust
;
9697 /* Not needed any more. */
9698 cu
->reset_builder ();
9701 /* Process an imported unit DIE. */
9704 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9706 struct attribute
*attr
;
9708 /* For now we don't handle imported units in type units. */
9709 if (cu
->per_cu
->is_debug_types
)
9711 error (_("Dwarf Error: DW_TAG_imported_unit is not"
9712 " supported in type units [in module %s]"),
9713 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
9716 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
9719 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
9720 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
9721 dwarf2_per_cu_data
*per_cu
9722 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
9723 cu
->per_cu
->dwarf2_per_objfile
);
9725 /* If necessary, add it to the queue and load its DIEs. */
9726 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
9727 load_full_comp_unit (per_cu
, false, cu
->language
);
9729 cu
->per_cu
->imported_symtabs_push (per_cu
);
9733 /* RAII object that represents a process_die scope: i.e.,
9734 starts/finishes processing a DIE. */
9735 class process_die_scope
9738 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
9739 : m_die (die
), m_cu (cu
)
9741 /* We should only be processing DIEs not already in process. */
9742 gdb_assert (!m_die
->in_process
);
9743 m_die
->in_process
= true;
9746 ~process_die_scope ()
9748 m_die
->in_process
= false;
9750 /* If we're done processing the DIE for the CU that owns the line
9751 header, we don't need the line header anymore. */
9752 if (m_cu
->line_header_die_owner
== m_die
)
9754 delete m_cu
->line_header
;
9755 m_cu
->line_header
= NULL
;
9756 m_cu
->line_header_die_owner
= NULL
;
9765 /* Process a die and its children. */
9768 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9770 process_die_scope
scope (die
, cu
);
9774 case DW_TAG_padding
:
9776 case DW_TAG_compile_unit
:
9777 case DW_TAG_partial_unit
:
9778 read_file_scope (die
, cu
);
9780 case DW_TAG_type_unit
:
9781 read_type_unit_scope (die
, cu
);
9783 case DW_TAG_subprogram
:
9784 /* Nested subprograms in Fortran get a prefix. */
9785 if (cu
->language
== language_fortran
9786 && die
->parent
!= NULL
9787 && die
->parent
->tag
== DW_TAG_subprogram
)
9788 cu
->processing_has_namespace_info
= true;
9790 case DW_TAG_inlined_subroutine
:
9791 read_func_scope (die
, cu
);
9793 case DW_TAG_lexical_block
:
9794 case DW_TAG_try_block
:
9795 case DW_TAG_catch_block
:
9796 read_lexical_block_scope (die
, cu
);
9798 case DW_TAG_call_site
:
9799 case DW_TAG_GNU_call_site
:
9800 read_call_site_scope (die
, cu
);
9802 case DW_TAG_class_type
:
9803 case DW_TAG_interface_type
:
9804 case DW_TAG_structure_type
:
9805 case DW_TAG_union_type
:
9806 process_structure_scope (die
, cu
);
9808 case DW_TAG_enumeration_type
:
9809 process_enumeration_scope (die
, cu
);
9812 /* These dies have a type, but processing them does not create
9813 a symbol or recurse to process the children. Therefore we can
9814 read them on-demand through read_type_die. */
9815 case DW_TAG_subroutine_type
:
9816 case DW_TAG_set_type
:
9817 case DW_TAG_array_type
:
9818 case DW_TAG_pointer_type
:
9819 case DW_TAG_ptr_to_member_type
:
9820 case DW_TAG_reference_type
:
9821 case DW_TAG_rvalue_reference_type
:
9822 case DW_TAG_string_type
:
9825 case DW_TAG_base_type
:
9826 case DW_TAG_subrange_type
:
9827 case DW_TAG_typedef
:
9828 /* Add a typedef symbol for the type definition, if it has a
9830 new_symbol (die
, read_type_die (die
, cu
), cu
);
9832 case DW_TAG_common_block
:
9833 read_common_block (die
, cu
);
9835 case DW_TAG_common_inclusion
:
9837 case DW_TAG_namespace
:
9838 cu
->processing_has_namespace_info
= true;
9839 read_namespace (die
, cu
);
9842 cu
->processing_has_namespace_info
= true;
9843 read_module (die
, cu
);
9845 case DW_TAG_imported_declaration
:
9846 cu
->processing_has_namespace_info
= true;
9847 if (read_namespace_alias (die
, cu
))
9849 /* The declaration is not a global namespace alias. */
9851 case DW_TAG_imported_module
:
9852 cu
->processing_has_namespace_info
= true;
9853 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
9854 || cu
->language
!= language_fortran
))
9855 complaint (_("Tag '%s' has unexpected children"),
9856 dwarf_tag_name (die
->tag
));
9857 read_import_statement (die
, cu
);
9860 case DW_TAG_imported_unit
:
9861 process_imported_unit_die (die
, cu
);
9864 case DW_TAG_variable
:
9865 read_variable (die
, cu
);
9869 new_symbol (die
, NULL
, cu
);
9874 /* DWARF name computation. */
9876 /* A helper function for dwarf2_compute_name which determines whether DIE
9877 needs to have the name of the scope prepended to the name listed in the
9881 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
9883 struct attribute
*attr
;
9887 case DW_TAG_namespace
:
9888 case DW_TAG_typedef
:
9889 case DW_TAG_class_type
:
9890 case DW_TAG_interface_type
:
9891 case DW_TAG_structure_type
:
9892 case DW_TAG_union_type
:
9893 case DW_TAG_enumeration_type
:
9894 case DW_TAG_enumerator
:
9895 case DW_TAG_subprogram
:
9896 case DW_TAG_inlined_subroutine
:
9898 case DW_TAG_imported_declaration
:
9901 case DW_TAG_variable
:
9902 case DW_TAG_constant
:
9903 /* We only need to prefix "globally" visible variables. These include
9904 any variable marked with DW_AT_external or any variable that
9905 lives in a namespace. [Variables in anonymous namespaces
9906 require prefixing, but they are not DW_AT_external.] */
9908 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
9910 struct dwarf2_cu
*spec_cu
= cu
;
9912 return die_needs_namespace (die_specification (die
, &spec_cu
),
9916 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
9917 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
9918 && die
->parent
->tag
!= DW_TAG_module
)
9920 /* A variable in a lexical block of some kind does not need a
9921 namespace, even though in C++ such variables may be external
9922 and have a mangled name. */
9923 if (die
->parent
->tag
== DW_TAG_lexical_block
9924 || die
->parent
->tag
== DW_TAG_try_block
9925 || die
->parent
->tag
== DW_TAG_catch_block
9926 || die
->parent
->tag
== DW_TAG_subprogram
)
9935 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
9936 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9937 defined for the given DIE. */
9939 static struct attribute
*
9940 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
9942 struct attribute
*attr
;
9944 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
9946 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9951 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
9952 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9953 defined for the given DIE. */
9956 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
9958 const char *linkage_name
;
9960 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
9961 if (linkage_name
== NULL
)
9962 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9964 return linkage_name
;
9967 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
9968 compute the physname for the object, which include a method's:
9969 - formal parameters (C++),
9970 - receiver type (Go),
9972 The term "physname" is a bit confusing.
9973 For C++, for example, it is the demangled name.
9974 For Go, for example, it's the mangled name.
9976 For Ada, return the DIE's linkage name rather than the fully qualified
9977 name. PHYSNAME is ignored..
9979 The result is allocated on the objfile_obstack and canonicalized. */
9982 dwarf2_compute_name (const char *name
,
9983 struct die_info
*die
, struct dwarf2_cu
*cu
,
9986 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9989 name
= dwarf2_name (die
, cu
);
9991 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
9992 but otherwise compute it by typename_concat inside GDB.
9993 FIXME: Actually this is not really true, or at least not always true.
9994 It's all very confusing. compute_and_set_names doesn't try to demangle
9995 Fortran names because there is no mangling standard. So new_symbol
9996 will set the demangled name to the result of dwarf2_full_name, and it is
9997 the demangled name that GDB uses if it exists. */
9998 if (cu
->language
== language_ada
9999 || (cu
->language
== language_fortran
&& physname
))
10001 /* For Ada unit, we prefer the linkage name over the name, as
10002 the former contains the exported name, which the user expects
10003 to be able to reference. Ideally, we want the user to be able
10004 to reference this entity using either natural or linkage name,
10005 but we haven't started looking at this enhancement yet. */
10006 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10008 if (linkage_name
!= NULL
)
10009 return linkage_name
;
10012 /* These are the only languages we know how to qualify names in. */
10014 && (cu
->language
== language_cplus
10015 || cu
->language
== language_fortran
|| cu
->language
== language_d
10016 || cu
->language
== language_rust
))
10018 if (die_needs_namespace (die
, cu
))
10020 const char *prefix
;
10021 const char *canonical_name
= NULL
;
10025 prefix
= determine_prefix (die
, cu
);
10026 if (*prefix
!= '\0')
10028 gdb::unique_xmalloc_ptr
<char> prefixed_name
10029 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10031 buf
.puts (prefixed_name
.get ());
10036 /* Template parameters may be specified in the DIE's DW_AT_name, or
10037 as children with DW_TAG_template_type_param or
10038 DW_TAG_value_type_param. If the latter, add them to the name
10039 here. If the name already has template parameters, then
10040 skip this step; some versions of GCC emit both, and
10041 it is more efficient to use the pre-computed name.
10043 Something to keep in mind about this process: it is very
10044 unlikely, or in some cases downright impossible, to produce
10045 something that will match the mangled name of a function.
10046 If the definition of the function has the same debug info,
10047 we should be able to match up with it anyway. But fallbacks
10048 using the minimal symbol, for instance to find a method
10049 implemented in a stripped copy of libstdc++, will not work.
10050 If we do not have debug info for the definition, we will have to
10051 match them up some other way.
10053 When we do name matching there is a related problem with function
10054 templates; two instantiated function templates are allowed to
10055 differ only by their return types, which we do not add here. */
10057 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10059 struct attribute
*attr
;
10060 struct die_info
*child
;
10063 die
->building_fullname
= 1;
10065 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10069 const gdb_byte
*bytes
;
10070 struct dwarf2_locexpr_baton
*baton
;
10073 if (child
->tag
!= DW_TAG_template_type_param
10074 && child
->tag
!= DW_TAG_template_value_param
)
10085 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10088 complaint (_("template parameter missing DW_AT_type"));
10089 buf
.puts ("UNKNOWN_TYPE");
10092 type
= die_type (child
, cu
);
10094 if (child
->tag
== DW_TAG_template_type_param
)
10096 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10097 &type_print_raw_options
);
10101 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10104 complaint (_("template parameter missing "
10105 "DW_AT_const_value"));
10106 buf
.puts ("UNKNOWN_VALUE");
10110 dwarf2_const_value_attr (attr
, type
, name
,
10111 &cu
->comp_unit_obstack
, cu
,
10112 &value
, &bytes
, &baton
);
10114 if (TYPE_NOSIGN (type
))
10115 /* GDB prints characters as NUMBER 'CHAR'. If that's
10116 changed, this can use value_print instead. */
10117 c_printchar (value
, type
, &buf
);
10120 struct value_print_options opts
;
10123 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10127 else if (bytes
!= NULL
)
10129 v
= allocate_value (type
);
10130 memcpy (value_contents_writeable (v
), bytes
,
10131 TYPE_LENGTH (type
));
10134 v
= value_from_longest (type
, value
);
10136 /* Specify decimal so that we do not depend on
10138 get_formatted_print_options (&opts
, 'd');
10140 value_print (v
, &buf
, &opts
);
10145 die
->building_fullname
= 0;
10149 /* Close the argument list, with a space if necessary
10150 (nested templates). */
10151 if (!buf
.empty () && buf
.string ().back () == '>')
10158 /* For C++ methods, append formal parameter type
10159 information, if PHYSNAME. */
10161 if (physname
&& die
->tag
== DW_TAG_subprogram
10162 && cu
->language
== language_cplus
)
10164 struct type
*type
= read_type_die (die
, cu
);
10166 c_type_print_args (type
, &buf
, 1, cu
->language
,
10167 &type_print_raw_options
);
10169 if (cu
->language
== language_cplus
)
10171 /* Assume that an artificial first parameter is
10172 "this", but do not crash if it is not. RealView
10173 marks unnamed (and thus unused) parameters as
10174 artificial; there is no way to differentiate
10176 if (TYPE_NFIELDS (type
) > 0
10177 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10178 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
10179 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
10181 buf
.puts (" const");
10185 const std::string
&intermediate_name
= buf
.string ();
10187 if (cu
->language
== language_cplus
)
10189 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10190 &objfile
->per_bfd
->storage_obstack
);
10192 /* If we only computed INTERMEDIATE_NAME, or if
10193 INTERMEDIATE_NAME is already canonical, then we need to
10194 copy it to the appropriate obstack. */
10195 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10196 name
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
10197 intermediate_name
);
10199 name
= canonical_name
;
10206 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10207 If scope qualifiers are appropriate they will be added. The result
10208 will be allocated on the storage_obstack, or NULL if the DIE does
10209 not have a name. NAME may either be from a previous call to
10210 dwarf2_name or NULL.
10212 The output string will be canonicalized (if C++). */
10214 static const char *
10215 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10217 return dwarf2_compute_name (name
, die
, cu
, 0);
10220 /* Construct a physname for the given DIE in CU. NAME may either be
10221 from a previous call to dwarf2_name or NULL. The result will be
10222 allocated on the objfile_objstack or NULL if the DIE does not have a
10225 The output string will be canonicalized (if C++). */
10227 static const char *
10228 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10230 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10231 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10234 /* In this case dwarf2_compute_name is just a shortcut not building anything
10236 if (!die_needs_namespace (die
, cu
))
10237 return dwarf2_compute_name (name
, die
, cu
, 1);
10239 mangled
= dw2_linkage_name (die
, cu
);
10241 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
10242 See https://github.com/rust-lang/rust/issues/32925. */
10243 if (cu
->language
== language_rust
&& mangled
!= NULL
10244 && strchr (mangled
, '{') != NULL
)
10247 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10249 gdb::unique_xmalloc_ptr
<char> demangled
;
10250 if (mangled
!= NULL
)
10253 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
10255 /* Do nothing (do not demangle the symbol name). */
10257 else if (cu
->language
== language_go
)
10259 /* This is a lie, but we already lie to the caller new_symbol.
10260 new_symbol assumes we return the mangled name.
10261 This just undoes that lie until things are cleaned up. */
10265 /* Use DMGL_RET_DROP for C++ template functions to suppress
10266 their return type. It is easier for GDB users to search
10267 for such functions as `name(params)' than `long name(params)'.
10268 In such case the minimal symbol names do not match the full
10269 symbol names but for template functions there is never a need
10270 to look up their definition from their declaration so
10271 the only disadvantage remains the minimal symbol variant
10272 `long name(params)' does not have the proper inferior type. */
10273 demangled
.reset (gdb_demangle (mangled
,
10274 (DMGL_PARAMS
| DMGL_ANSI
10275 | DMGL_RET_DROP
)));
10278 canon
= demangled
.get ();
10286 if (canon
== NULL
|| check_physname
)
10288 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10290 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10292 /* It may not mean a bug in GDB. The compiler could also
10293 compute DW_AT_linkage_name incorrectly. But in such case
10294 GDB would need to be bug-to-bug compatible. */
10296 complaint (_("Computed physname <%s> does not match demangled <%s> "
10297 "(from linkage <%s>) - DIE at %s [in module %s]"),
10298 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10299 objfile_name (objfile
));
10301 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10302 is available here - over computed PHYSNAME. It is safer
10303 against both buggy GDB and buggy compilers. */
10317 retval
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
, retval
);
10322 /* Inspect DIE in CU for a namespace alias. If one exists, record
10323 a new symbol for it.
10325 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10328 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10330 struct attribute
*attr
;
10332 /* If the die does not have a name, this is not a namespace
10334 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10338 struct die_info
*d
= die
;
10339 struct dwarf2_cu
*imported_cu
= cu
;
10341 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10342 keep inspecting DIEs until we hit the underlying import. */
10343 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10344 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10346 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10350 d
= follow_die_ref (d
, attr
, &imported_cu
);
10351 if (d
->tag
!= DW_TAG_imported_declaration
)
10355 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10357 complaint (_("DIE at %s has too many recursively imported "
10358 "declarations"), sect_offset_str (d
->sect_off
));
10365 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
10367 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
10368 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
10370 /* This declaration is a global namespace alias. Add
10371 a symbol for it whose type is the aliased namespace. */
10372 new_symbol (die
, type
, cu
);
10381 /* Return the using directives repository (global or local?) to use in the
10382 current context for CU.
10384 For Ada, imported declarations can materialize renamings, which *may* be
10385 global. However it is impossible (for now?) in DWARF to distinguish
10386 "external" imported declarations and "static" ones. As all imported
10387 declarations seem to be static in all other languages, make them all CU-wide
10388 global only in Ada. */
10390 static struct using_direct
**
10391 using_directives (struct dwarf2_cu
*cu
)
10393 if (cu
->language
== language_ada
10394 && cu
->get_builder ()->outermost_context_p ())
10395 return cu
->get_builder ()->get_global_using_directives ();
10397 return cu
->get_builder ()->get_local_using_directives ();
10400 /* Read the import statement specified by the given die and record it. */
10403 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10405 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10406 struct attribute
*import_attr
;
10407 struct die_info
*imported_die
, *child_die
;
10408 struct dwarf2_cu
*imported_cu
;
10409 const char *imported_name
;
10410 const char *imported_name_prefix
;
10411 const char *canonical_name
;
10412 const char *import_alias
;
10413 const char *imported_declaration
= NULL
;
10414 const char *import_prefix
;
10415 std::vector
<const char *> excludes
;
10417 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10418 if (import_attr
== NULL
)
10420 complaint (_("Tag '%s' has no DW_AT_import"),
10421 dwarf_tag_name (die
->tag
));
10426 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10427 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10428 if (imported_name
== NULL
)
10430 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10432 The import in the following code:
10446 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10447 <52> DW_AT_decl_file : 1
10448 <53> DW_AT_decl_line : 6
10449 <54> DW_AT_import : <0x75>
10450 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10451 <59> DW_AT_name : B
10452 <5b> DW_AT_decl_file : 1
10453 <5c> DW_AT_decl_line : 2
10454 <5d> DW_AT_type : <0x6e>
10456 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10457 <76> DW_AT_byte_size : 4
10458 <77> DW_AT_encoding : 5 (signed)
10460 imports the wrong die ( 0x75 instead of 0x58 ).
10461 This case will be ignored until the gcc bug is fixed. */
10465 /* Figure out the local name after import. */
10466 import_alias
= dwarf2_name (die
, cu
);
10468 /* Figure out where the statement is being imported to. */
10469 import_prefix
= determine_prefix (die
, cu
);
10471 /* Figure out what the scope of the imported die is and prepend it
10472 to the name of the imported die. */
10473 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10475 if (imported_die
->tag
!= DW_TAG_namespace
10476 && imported_die
->tag
!= DW_TAG_module
)
10478 imported_declaration
= imported_name
;
10479 canonical_name
= imported_name_prefix
;
10481 else if (strlen (imported_name_prefix
) > 0)
10482 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10483 imported_name_prefix
,
10484 (cu
->language
== language_d
? "." : "::"),
10485 imported_name
, (char *) NULL
);
10487 canonical_name
= imported_name
;
10489 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
10490 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10491 child_die
= sibling_die (child_die
))
10493 /* DWARF-4: A Fortran use statement with a “rename list” may be
10494 represented by an imported module entry with an import attribute
10495 referring to the module and owned entries corresponding to those
10496 entities that are renamed as part of being imported. */
10498 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10500 complaint (_("child DW_TAG_imported_declaration expected "
10501 "- DIE at %s [in module %s]"),
10502 sect_offset_str (child_die
->sect_off
),
10503 objfile_name (objfile
));
10507 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10508 if (import_attr
== NULL
)
10510 complaint (_("Tag '%s' has no DW_AT_import"),
10511 dwarf_tag_name (child_die
->tag
));
10516 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10518 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10519 if (imported_name
== NULL
)
10521 complaint (_("child DW_TAG_imported_declaration has unknown "
10522 "imported name - DIE at %s [in module %s]"),
10523 sect_offset_str (child_die
->sect_off
),
10524 objfile_name (objfile
));
10528 excludes
.push_back (imported_name
);
10530 process_die (child_die
, cu
);
10533 add_using_directive (using_directives (cu
),
10537 imported_declaration
,
10540 &objfile
->objfile_obstack
);
10543 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10544 types, but gives them a size of zero. Starting with version 14,
10545 ICC is compatible with GCC. */
10548 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10550 if (!cu
->checked_producer
)
10551 check_producer (cu
);
10553 return cu
->producer_is_icc_lt_14
;
10556 /* ICC generates a DW_AT_type for C void functions. This was observed on
10557 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10558 which says that void functions should not have a DW_AT_type. */
10561 producer_is_icc (struct dwarf2_cu
*cu
)
10563 if (!cu
->checked_producer
)
10564 check_producer (cu
);
10566 return cu
->producer_is_icc
;
10569 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10570 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10571 this, it was first present in GCC release 4.3.0. */
10574 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10576 if (!cu
->checked_producer
)
10577 check_producer (cu
);
10579 return cu
->producer_is_gcc_lt_4_3
;
10582 static file_and_directory
10583 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10585 file_and_directory res
;
10587 /* Find the filename. Do not use dwarf2_name here, since the filename
10588 is not a source language identifier. */
10589 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
10590 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
10592 if (res
.comp_dir
== NULL
10593 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
10594 && IS_ABSOLUTE_PATH (res
.name
))
10596 res
.comp_dir_storage
= ldirname (res
.name
);
10597 if (!res
.comp_dir_storage
.empty ())
10598 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
10600 if (res
.comp_dir
!= NULL
)
10602 /* Irix 6.2 native cc prepends <machine>.: to the compilation
10603 directory, get rid of it. */
10604 const char *cp
= strchr (res
.comp_dir
, ':');
10606 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
10607 res
.comp_dir
= cp
+ 1;
10610 if (res
.name
== NULL
)
10611 res
.name
= "<unknown>";
10616 /* Handle DW_AT_stmt_list for a compilation unit.
10617 DIE is the DW_TAG_compile_unit die for CU.
10618 COMP_DIR is the compilation directory. LOWPC is passed to
10619 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
10622 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
10623 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
10625 struct dwarf2_per_objfile
*dwarf2_per_objfile
10626 = cu
->per_cu
->dwarf2_per_objfile
;
10627 struct attribute
*attr
;
10628 struct line_header line_header_local
;
10629 hashval_t line_header_local_hash
;
10631 int decode_mapping
;
10633 gdb_assert (! cu
->per_cu
->is_debug_types
);
10635 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
10639 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10641 /* The line header hash table is only created if needed (it exists to
10642 prevent redundant reading of the line table for partial_units).
10643 If we're given a partial_unit, we'll need it. If we're given a
10644 compile_unit, then use the line header hash table if it's already
10645 created, but don't create one just yet. */
10647 if (dwarf2_per_objfile
->line_header_hash
== NULL
10648 && die
->tag
== DW_TAG_partial_unit
)
10650 dwarf2_per_objfile
->line_header_hash
10651 .reset (htab_create_alloc (127, line_header_hash_voidp
,
10652 line_header_eq_voidp
,
10653 free_line_header_voidp
,
10657 line_header_local
.sect_off
= line_offset
;
10658 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
10659 line_header_local_hash
= line_header_hash (&line_header_local
);
10660 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
10662 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
.get (),
10663 &line_header_local
,
10664 line_header_local_hash
, NO_INSERT
);
10666 /* For DW_TAG_compile_unit we need info like symtab::linetable which
10667 is not present in *SLOT (since if there is something in *SLOT then
10668 it will be for a partial_unit). */
10669 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
10671 gdb_assert (*slot
!= NULL
);
10672 cu
->line_header
= (struct line_header
*) *slot
;
10677 /* dwarf_decode_line_header does not yet provide sufficient information.
10678 We always have to call also dwarf_decode_lines for it. */
10679 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
10683 cu
->line_header
= lh
.release ();
10684 cu
->line_header_die_owner
= die
;
10686 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
10690 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
.get (),
10691 &line_header_local
,
10692 line_header_local_hash
, INSERT
);
10693 gdb_assert (slot
!= NULL
);
10695 if (slot
!= NULL
&& *slot
== NULL
)
10697 /* This newly decoded line number information unit will be owned
10698 by line_header_hash hash table. */
10699 *slot
= cu
->line_header
;
10700 cu
->line_header_die_owner
= NULL
;
10704 /* We cannot free any current entry in (*slot) as that struct line_header
10705 may be already used by multiple CUs. Create only temporary decoded
10706 line_header for this CU - it may happen at most once for each line
10707 number information unit. And if we're not using line_header_hash
10708 then this is what we want as well. */
10709 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
10711 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
10712 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
10717 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
10720 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10722 struct dwarf2_per_objfile
*dwarf2_per_objfile
10723 = cu
->per_cu
->dwarf2_per_objfile
;
10724 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10725 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10726 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
10727 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
10728 struct attribute
*attr
;
10729 struct die_info
*child_die
;
10730 CORE_ADDR baseaddr
;
10732 prepare_one_comp_unit (cu
, die
, cu
->language
);
10733 baseaddr
= objfile
->text_section_offset ();
10735 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
10737 /* If we didn't find a lowpc, set it to highpc to avoid complaints
10738 from finish_block. */
10739 if (lowpc
== ((CORE_ADDR
) -1))
10741 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
10743 file_and_directory fnd
= find_file_and_directory (die
, cu
);
10745 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
10746 standardised yet. As a workaround for the language detection we fall
10747 back to the DW_AT_producer string. */
10748 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
10749 cu
->language
= language_opencl
;
10751 /* Similar hack for Go. */
10752 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
10753 set_cu_language (DW_LANG_Go
, cu
);
10755 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
10757 /* Decode line number information if present. We do this before
10758 processing child DIEs, so that the line header table is available
10759 for DW_AT_decl_file. */
10760 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
10762 /* Process all dies in compilation unit. */
10763 if (die
->child
!= NULL
)
10765 child_die
= die
->child
;
10766 while (child_die
&& child_die
->tag
)
10768 process_die (child_die
, cu
);
10769 child_die
= sibling_die (child_die
);
10773 /* Decode macro information, if present. Dwarf 2 macro information
10774 refers to information in the line number info statement program
10775 header, so we can only read it if we've read the header
10777 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
10779 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
10780 if (attr
&& cu
->line_header
)
10782 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
10783 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
10785 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
10789 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
10790 if (attr
&& cu
->line_header
)
10792 unsigned int macro_offset
= DW_UNSND (attr
);
10794 dwarf_decode_macros (cu
, macro_offset
, 0);
10800 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
10802 struct type_unit_group
*tu_group
;
10804 struct attribute
*attr
;
10806 struct signatured_type
*sig_type
;
10808 gdb_assert (per_cu
->is_debug_types
);
10809 sig_type
= (struct signatured_type
*) per_cu
;
10811 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
10813 /* If we're using .gdb_index (includes -readnow) then
10814 per_cu->type_unit_group may not have been set up yet. */
10815 if (sig_type
->type_unit_group
== NULL
)
10816 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
10817 tu_group
= sig_type
->type_unit_group
;
10819 /* If we've already processed this stmt_list there's no real need to
10820 do it again, we could fake it and just recreate the part we need
10821 (file name,index -> symtab mapping). If data shows this optimization
10822 is useful we can do it then. */
10823 first_time
= tu_group
->compunit_symtab
== NULL
;
10825 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
10830 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10831 lh
= dwarf_decode_line_header (line_offset
, this);
10836 start_symtab ("", NULL
, 0);
10839 gdb_assert (tu_group
->symtabs
== NULL
);
10840 gdb_assert (m_builder
== nullptr);
10841 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
10842 m_builder
.reset (new struct buildsym_compunit
10843 (COMPUNIT_OBJFILE (cust
), "",
10844 COMPUNIT_DIRNAME (cust
),
10845 compunit_language (cust
),
10851 line_header
= lh
.release ();
10852 line_header_die_owner
= die
;
10856 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
10858 /* Note: We don't assign tu_group->compunit_symtab yet because we're
10859 still initializing it, and our caller (a few levels up)
10860 process_full_type_unit still needs to know if this is the first
10863 tu_group
->num_symtabs
= line_header
->file_names_size ();
10864 tu_group
->symtabs
= XNEWVEC (struct symtab
*,
10865 line_header
->file_names_size ());
10867 auto &file_names
= line_header
->file_names ();
10868 for (i
= 0; i
< file_names
.size (); ++i
)
10870 file_entry
&fe
= file_names
[i
];
10871 dwarf2_start_subfile (this, fe
.name
,
10872 fe
.include_dir (line_header
));
10873 buildsym_compunit
*b
= get_builder ();
10874 if (b
->get_current_subfile ()->symtab
== NULL
)
10876 /* NOTE: start_subfile will recognize when it's been
10877 passed a file it has already seen. So we can't
10878 assume there's a simple mapping from
10879 cu->line_header->file_names to subfiles, plus
10880 cu->line_header->file_names may contain dups. */
10881 b
->get_current_subfile ()->symtab
10882 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
10885 fe
.symtab
= b
->get_current_subfile ()->symtab
;
10886 tu_group
->symtabs
[i
] = fe
.symtab
;
10891 gdb_assert (m_builder
== nullptr);
10892 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
10893 m_builder
.reset (new struct buildsym_compunit
10894 (COMPUNIT_OBJFILE (cust
), "",
10895 COMPUNIT_DIRNAME (cust
),
10896 compunit_language (cust
),
10899 auto &file_names
= line_header
->file_names ();
10900 for (i
= 0; i
< file_names
.size (); ++i
)
10902 file_entry
&fe
= file_names
[i
];
10903 fe
.symtab
= tu_group
->symtabs
[i
];
10907 /* The main symtab is allocated last. Type units don't have DW_AT_name
10908 so they don't have a "real" (so to speak) symtab anyway.
10909 There is later code that will assign the main symtab to all symbols
10910 that don't have one. We need to handle the case of a symbol with a
10911 missing symtab (DW_AT_decl_file) anyway. */
10914 /* Process DW_TAG_type_unit.
10915 For TUs we want to skip the first top level sibling if it's not the
10916 actual type being defined by this TU. In this case the first top
10917 level sibling is there to provide context only. */
10920 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10922 struct die_info
*child_die
;
10924 prepare_one_comp_unit (cu
, die
, language_minimal
);
10926 /* Initialize (or reinitialize) the machinery for building symtabs.
10927 We do this before processing child DIEs, so that the line header table
10928 is available for DW_AT_decl_file. */
10929 cu
->setup_type_unit_groups (die
);
10931 if (die
->child
!= NULL
)
10933 child_die
= die
->child
;
10934 while (child_die
&& child_die
->tag
)
10936 process_die (child_die
, cu
);
10937 child_die
= sibling_die (child_die
);
10944 http://gcc.gnu.org/wiki/DebugFission
10945 http://gcc.gnu.org/wiki/DebugFissionDWP
10947 To simplify handling of both DWO files ("object" files with the DWARF info)
10948 and DWP files (a file with the DWOs packaged up into one file), we treat
10949 DWP files as having a collection of virtual DWO files. */
10952 hash_dwo_file (const void *item
)
10954 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
10957 hash
= htab_hash_string (dwo_file
->dwo_name
);
10958 if (dwo_file
->comp_dir
!= NULL
)
10959 hash
+= htab_hash_string (dwo_file
->comp_dir
);
10964 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
10966 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
10967 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
10969 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
10971 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
10972 return lhs
->comp_dir
== rhs
->comp_dir
;
10973 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
10976 /* Allocate a hash table for DWO files. */
10979 allocate_dwo_file_hash_table (struct objfile
*objfile
)
10981 auto delete_dwo_file
= [] (void *item
)
10983 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
10988 return htab_up (htab_create_alloc (41,
10995 /* Lookup DWO file DWO_NAME. */
10998 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
10999 const char *dwo_name
,
11000 const char *comp_dir
)
11002 struct dwo_file find_entry
;
11005 if (dwarf2_per_objfile
->dwo_files
== NULL
)
11006 dwarf2_per_objfile
->dwo_files
11007 = allocate_dwo_file_hash_table (dwarf2_per_objfile
->objfile
);
11009 find_entry
.dwo_name
= dwo_name
;
11010 find_entry
.comp_dir
= comp_dir
;
11011 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
.get (), &find_entry
,
11018 hash_dwo_unit (const void *item
)
11020 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11022 /* This drops the top 32 bits of the id, but is ok for a hash. */
11023 return dwo_unit
->signature
;
11027 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11029 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11030 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11032 /* The signature is assumed to be unique within the DWO file.
11033 So while object file CU dwo_id's always have the value zero,
11034 that's OK, assuming each object file DWO file has only one CU,
11035 and that's the rule for now. */
11036 return lhs
->signature
== rhs
->signature
;
11039 /* Allocate a hash table for DWO CUs,TUs.
11040 There is one of these tables for each of CUs,TUs for each DWO file. */
11043 allocate_dwo_unit_table (struct objfile
*objfile
)
11045 /* Start out with a pretty small number.
11046 Generally DWO files contain only one CU and maybe some TUs. */
11047 return htab_up (htab_create_alloc (3,
11050 NULL
, xcalloc
, xfree
));
11053 /* die_reader_func for create_dwo_cu. */
11056 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11057 const gdb_byte
*info_ptr
,
11058 struct die_info
*comp_unit_die
,
11059 struct dwo_file
*dwo_file
,
11060 struct dwo_unit
*dwo_unit
)
11062 struct dwarf2_cu
*cu
= reader
->cu
;
11063 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11064 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11066 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11067 if (!signature
.has_value ())
11069 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11070 " its dwo_id [in module %s]"),
11071 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11075 dwo_unit
->dwo_file
= dwo_file
;
11076 dwo_unit
->signature
= *signature
;
11077 dwo_unit
->section
= section
;
11078 dwo_unit
->sect_off
= sect_off
;
11079 dwo_unit
->length
= cu
->per_cu
->length
;
11081 if (dwarf_read_debug
)
11082 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11083 sect_offset_str (sect_off
),
11084 hex_string (dwo_unit
->signature
));
11087 /* Create the dwo_units for the CUs in a DWO_FILE.
11088 Note: This function processes DWO files only, not DWP files. */
11091 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11092 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11093 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
11095 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11096 const gdb_byte
*info_ptr
, *end_ptr
;
11098 section
.read (objfile
);
11099 info_ptr
= section
.buffer
;
11101 if (info_ptr
== NULL
)
11104 if (dwarf_read_debug
)
11106 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11107 section
.get_name (),
11108 section
.get_file_name ());
11111 end_ptr
= info_ptr
+ section
.size
;
11112 while (info_ptr
< end_ptr
)
11114 struct dwarf2_per_cu_data per_cu
;
11115 struct dwo_unit read_unit
{};
11116 struct dwo_unit
*dwo_unit
;
11118 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11120 memset (&per_cu
, 0, sizeof (per_cu
));
11121 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
11122 per_cu
.is_debug_types
= 0;
11123 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11124 per_cu
.section
= §ion
;
11126 cutu_reader
reader (&per_cu
, cu
, &dwo_file
);
11127 if (!reader
.dummy_p
)
11128 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11129 &dwo_file
, &read_unit
);
11130 info_ptr
+= per_cu
.length
;
11132 // If the unit could not be parsed, skip it.
11133 if (read_unit
.dwo_file
== NULL
)
11136 if (cus_htab
== NULL
)
11137 cus_htab
= allocate_dwo_unit_table (objfile
);
11139 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11140 *dwo_unit
= read_unit
;
11141 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11142 gdb_assert (slot
!= NULL
);
11145 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11146 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11148 complaint (_("debug cu entry at offset %s is duplicate to"
11149 " the entry at offset %s, signature %s"),
11150 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11151 hex_string (dwo_unit
->signature
));
11153 *slot
= (void *)dwo_unit
;
11157 /* DWP file .debug_{cu,tu}_index section format:
11158 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11162 Both index sections have the same format, and serve to map a 64-bit
11163 signature to a set of section numbers. Each section begins with a header,
11164 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11165 indexes, and a pool of 32-bit section numbers. The index sections will be
11166 aligned at 8-byte boundaries in the file.
11168 The index section header consists of:
11170 V, 32 bit version number
11172 N, 32 bit number of compilation units or type units in the index
11173 M, 32 bit number of slots in the hash table
11175 Numbers are recorded using the byte order of the application binary.
11177 The hash table begins at offset 16 in the section, and consists of an array
11178 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11179 order of the application binary). Unused slots in the hash table are 0.
11180 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11182 The parallel table begins immediately after the hash table
11183 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11184 array of 32-bit indexes (using the byte order of the application binary),
11185 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11186 table contains a 32-bit index into the pool of section numbers. For unused
11187 hash table slots, the corresponding entry in the parallel table will be 0.
11189 The pool of section numbers begins immediately following the hash table
11190 (at offset 16 + 12 * M from the beginning of the section). The pool of
11191 section numbers consists of an array of 32-bit words (using the byte order
11192 of the application binary). Each item in the array is indexed starting
11193 from 0. The hash table entry provides the index of the first section
11194 number in the set. Additional section numbers in the set follow, and the
11195 set is terminated by a 0 entry (section number 0 is not used in ELF).
11197 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11198 section must be the first entry in the set, and the .debug_abbrev.dwo must
11199 be the second entry. Other members of the set may follow in any order.
11205 DWP Version 2 combines all the .debug_info, etc. sections into one,
11206 and the entries in the index tables are now offsets into these sections.
11207 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11210 Index Section Contents:
11212 Hash Table of Signatures dwp_hash_table.hash_table
11213 Parallel Table of Indices dwp_hash_table.unit_table
11214 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
11215 Table of Section Sizes dwp_hash_table.v2.sizes
11217 The index section header consists of:
11219 V, 32 bit version number
11220 L, 32 bit number of columns in the table of section offsets
11221 N, 32 bit number of compilation units or type units in the index
11222 M, 32 bit number of slots in the hash table
11224 Numbers are recorded using the byte order of the application binary.
11226 The hash table has the same format as version 1.
11227 The parallel table of indices has the same format as version 1,
11228 except that the entries are origin-1 indices into the table of sections
11229 offsets and the table of section sizes.
11231 The table of offsets begins immediately following the parallel table
11232 (at offset 16 + 12 * M from the beginning of the section). The table is
11233 a two-dimensional array of 32-bit words (using the byte order of the
11234 application binary), with L columns and N+1 rows, in row-major order.
11235 Each row in the array is indexed starting from 0. The first row provides
11236 a key to the remaining rows: each column in this row provides an identifier
11237 for a debug section, and the offsets in the same column of subsequent rows
11238 refer to that section. The section identifiers are:
11240 DW_SECT_INFO 1 .debug_info.dwo
11241 DW_SECT_TYPES 2 .debug_types.dwo
11242 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11243 DW_SECT_LINE 4 .debug_line.dwo
11244 DW_SECT_LOC 5 .debug_loc.dwo
11245 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11246 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11247 DW_SECT_MACRO 8 .debug_macro.dwo
11249 The offsets provided by the CU and TU index sections are the base offsets
11250 for the contributions made by each CU or TU to the corresponding section
11251 in the package file. Each CU and TU header contains an abbrev_offset
11252 field, used to find the abbreviations table for that CU or TU within the
11253 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11254 be interpreted as relative to the base offset given in the index section.
11255 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11256 should be interpreted as relative to the base offset for .debug_line.dwo,
11257 and offsets into other debug sections obtained from DWARF attributes should
11258 also be interpreted as relative to the corresponding base offset.
11260 The table of sizes begins immediately following the table of offsets.
11261 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11262 with L columns and N rows, in row-major order. Each row in the array is
11263 indexed starting from 1 (row 0 is shared by the two tables).
11267 Hash table lookup is handled the same in version 1 and 2:
11269 We assume that N and M will not exceed 2^32 - 1.
11270 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11272 Given a 64-bit compilation unit signature or a type signature S, an entry
11273 in the hash table is located as follows:
11275 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11276 the low-order k bits all set to 1.
11278 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11280 3) If the hash table entry at index H matches the signature, use that
11281 entry. If the hash table entry at index H is unused (all zeroes),
11282 terminate the search: the signature is not present in the table.
11284 4) Let H = (H + H') modulo M. Repeat at Step 3.
11286 Because M > N and H' and M are relatively prime, the search is guaranteed
11287 to stop at an unused slot or find the match. */
11289 /* Create a hash table to map DWO IDs to their CU/TU entry in
11290 .debug_{info,types}.dwo in DWP_FILE.
11291 Returns NULL if there isn't one.
11292 Note: This function processes DWP files only, not DWO files. */
11294 static struct dwp_hash_table
*
11295 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11296 struct dwp_file
*dwp_file
, int is_debug_types
)
11298 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11299 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11300 const gdb_byte
*index_ptr
, *index_end
;
11301 struct dwarf2_section_info
*index
;
11302 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11303 struct dwp_hash_table
*htab
;
11305 if (is_debug_types
)
11306 index
= &dwp_file
->sections
.tu_index
;
11308 index
= &dwp_file
->sections
.cu_index
;
11310 if (index
->empty ())
11312 index
->read (objfile
);
11314 index_ptr
= index
->buffer
;
11315 index_end
= index_ptr
+ index
->size
;
11317 version
= read_4_bytes (dbfd
, index_ptr
);
11320 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11324 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11326 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11329 if (version
!= 1 && version
!= 2)
11331 error (_("Dwarf Error: unsupported DWP file version (%s)"
11332 " [in module %s]"),
11333 pulongest (version
), dwp_file
->name
);
11335 if (nr_slots
!= (nr_slots
& -nr_slots
))
11337 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11338 " is not power of 2 [in module %s]"),
11339 pulongest (nr_slots
), dwp_file
->name
);
11342 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
11343 htab
->version
= version
;
11344 htab
->nr_columns
= nr_columns
;
11345 htab
->nr_units
= nr_units
;
11346 htab
->nr_slots
= nr_slots
;
11347 htab
->hash_table
= index_ptr
;
11348 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11350 /* Exit early if the table is empty. */
11351 if (nr_slots
== 0 || nr_units
== 0
11352 || (version
== 2 && nr_columns
== 0))
11354 /* All must be zero. */
11355 if (nr_slots
!= 0 || nr_units
!= 0
11356 || (version
== 2 && nr_columns
!= 0))
11358 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11359 " all zero [in modules %s]"),
11367 htab
->section_pool
.v1
.indices
=
11368 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11369 /* It's harder to decide whether the section is too small in v1.
11370 V1 is deprecated anyway so we punt. */
11374 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11375 int *ids
= htab
->section_pool
.v2
.section_ids
;
11376 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11377 /* Reverse map for error checking. */
11378 int ids_seen
[DW_SECT_MAX
+ 1];
11381 if (nr_columns
< 2)
11383 error (_("Dwarf Error: bad DWP hash table, too few columns"
11384 " in section table [in module %s]"),
11387 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11389 error (_("Dwarf Error: bad DWP hash table, too many columns"
11390 " in section table [in module %s]"),
11393 memset (ids
, 255, sizeof_ids
);
11394 memset (ids_seen
, 255, sizeof (ids_seen
));
11395 for (i
= 0; i
< nr_columns
; ++i
)
11397 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11399 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11401 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11402 " in section table [in module %s]"),
11403 id
, dwp_file
->name
);
11405 if (ids_seen
[id
] != -1)
11407 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11408 " id %d in section table [in module %s]"),
11409 id
, dwp_file
->name
);
11414 /* Must have exactly one info or types section. */
11415 if (((ids_seen
[DW_SECT_INFO
] != -1)
11416 + (ids_seen
[DW_SECT_TYPES
] != -1))
11419 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11420 " DWO info/types section [in module %s]"),
11423 /* Must have an abbrev section. */
11424 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11426 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11427 " section [in module %s]"),
11430 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11431 htab
->section_pool
.v2
.sizes
=
11432 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11433 * nr_units
* nr_columns
);
11434 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11435 * nr_units
* nr_columns
))
11438 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11439 " [in module %s]"),
11447 /* Update SECTIONS with the data from SECTP.
11449 This function is like the other "locate" section routines that are
11450 passed to bfd_map_over_sections, but in this context the sections to
11451 read comes from the DWP V1 hash table, not the full ELF section table.
11453 The result is non-zero for success, or zero if an error was found. */
11456 locate_v1_virtual_dwo_sections (asection
*sectp
,
11457 struct virtual_v1_dwo_sections
*sections
)
11459 const struct dwop_section_names
*names
= &dwop_section_names
;
11461 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
11463 /* There can be only one. */
11464 if (sections
->abbrev
.s
.section
!= NULL
)
11466 sections
->abbrev
.s
.section
= sectp
;
11467 sections
->abbrev
.size
= bfd_section_size (sectp
);
11469 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
11470 || section_is_p (sectp
->name
, &names
->types_dwo
))
11472 /* There can be only one. */
11473 if (sections
->info_or_types
.s
.section
!= NULL
)
11475 sections
->info_or_types
.s
.section
= sectp
;
11476 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11478 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
11480 /* There can be only one. */
11481 if (sections
->line
.s
.section
!= NULL
)
11483 sections
->line
.s
.section
= sectp
;
11484 sections
->line
.size
= bfd_section_size (sectp
);
11486 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
11488 /* There can be only one. */
11489 if (sections
->loc
.s
.section
!= NULL
)
11491 sections
->loc
.s
.section
= sectp
;
11492 sections
->loc
.size
= bfd_section_size (sectp
);
11494 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
11496 /* There can be only one. */
11497 if (sections
->macinfo
.s
.section
!= NULL
)
11499 sections
->macinfo
.s
.section
= sectp
;
11500 sections
->macinfo
.size
= bfd_section_size (sectp
);
11502 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
11504 /* There can be only one. */
11505 if (sections
->macro
.s
.section
!= NULL
)
11507 sections
->macro
.s
.section
= sectp
;
11508 sections
->macro
.size
= bfd_section_size (sectp
);
11510 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
11512 /* There can be only one. */
11513 if (sections
->str_offsets
.s
.section
!= NULL
)
11515 sections
->str_offsets
.s
.section
= sectp
;
11516 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11520 /* No other kind of section is valid. */
11527 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11528 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11529 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11530 This is for DWP version 1 files. */
11532 static struct dwo_unit
*
11533 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11534 struct dwp_file
*dwp_file
,
11535 uint32_t unit_index
,
11536 const char *comp_dir
,
11537 ULONGEST signature
, int is_debug_types
)
11539 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11540 const struct dwp_hash_table
*dwp_htab
=
11541 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11542 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11543 const char *kind
= is_debug_types
? "TU" : "CU";
11544 struct dwo_file
*dwo_file
;
11545 struct dwo_unit
*dwo_unit
;
11546 struct virtual_v1_dwo_sections sections
;
11547 void **dwo_file_slot
;
11550 gdb_assert (dwp_file
->version
== 1);
11552 if (dwarf_read_debug
)
11554 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
11556 pulongest (unit_index
), hex_string (signature
),
11560 /* Fetch the sections of this DWO unit.
11561 Put a limit on the number of sections we look for so that bad data
11562 doesn't cause us to loop forever. */
11564 #define MAX_NR_V1_DWO_SECTIONS \
11565 (1 /* .debug_info or .debug_types */ \
11566 + 1 /* .debug_abbrev */ \
11567 + 1 /* .debug_line */ \
11568 + 1 /* .debug_loc */ \
11569 + 1 /* .debug_str_offsets */ \
11570 + 1 /* .debug_macro or .debug_macinfo */ \
11571 + 1 /* trailing zero */)
11573 memset (§ions
, 0, sizeof (sections
));
11575 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
11578 uint32_t section_nr
=
11579 read_4_bytes (dbfd
,
11580 dwp_htab
->section_pool
.v1
.indices
11581 + (unit_index
+ i
) * sizeof (uint32_t));
11583 if (section_nr
== 0)
11585 if (section_nr
>= dwp_file
->num_sections
)
11587 error (_("Dwarf Error: bad DWP hash table, section number too large"
11588 " [in module %s]"),
11592 sectp
= dwp_file
->elf_sections
[section_nr
];
11593 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
11595 error (_("Dwarf Error: bad DWP hash table, invalid section found"
11596 " [in module %s]"),
11602 || sections
.info_or_types
.empty ()
11603 || sections
.abbrev
.empty ())
11605 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
11606 " [in module %s]"),
11609 if (i
== MAX_NR_V1_DWO_SECTIONS
)
11611 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
11612 " [in module %s]"),
11616 /* It's easier for the rest of the code if we fake a struct dwo_file and
11617 have dwo_unit "live" in that. At least for now.
11619 The DWP file can be made up of a random collection of CUs and TUs.
11620 However, for each CU + set of TUs that came from the same original DWO
11621 file, we can combine them back into a virtual DWO file to save space
11622 (fewer struct dwo_file objects to allocate). Remember that for really
11623 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11625 std::string virtual_dwo_name
=
11626 string_printf ("virtual-dwo/%d-%d-%d-%d",
11627 sections
.abbrev
.get_id (),
11628 sections
.line
.get_id (),
11629 sections
.loc
.get_id (),
11630 sections
.str_offsets
.get_id ());
11631 /* Can we use an existing virtual DWO file? */
11632 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
11633 virtual_dwo_name
.c_str (),
11635 /* Create one if necessary. */
11636 if (*dwo_file_slot
== NULL
)
11638 if (dwarf_read_debug
)
11640 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11641 virtual_dwo_name
.c_str ());
11643 dwo_file
= new struct dwo_file
;
11644 dwo_file
->dwo_name
= obstack_strdup (&objfile
->objfile_obstack
,
11646 dwo_file
->comp_dir
= comp_dir
;
11647 dwo_file
->sections
.abbrev
= sections
.abbrev
;
11648 dwo_file
->sections
.line
= sections
.line
;
11649 dwo_file
->sections
.loc
= sections
.loc
;
11650 dwo_file
->sections
.macinfo
= sections
.macinfo
;
11651 dwo_file
->sections
.macro
= sections
.macro
;
11652 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
11653 /* The "str" section is global to the entire DWP file. */
11654 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11655 /* The info or types section is assigned below to dwo_unit,
11656 there's no need to record it in dwo_file.
11657 Also, we can't simply record type sections in dwo_file because
11658 we record a pointer into the vector in dwo_unit. As we collect more
11659 types we'll grow the vector and eventually have to reallocate space
11660 for it, invalidating all copies of pointers into the previous
11662 *dwo_file_slot
= dwo_file
;
11666 if (dwarf_read_debug
)
11668 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11669 virtual_dwo_name
.c_str ());
11671 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11674 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11675 dwo_unit
->dwo_file
= dwo_file
;
11676 dwo_unit
->signature
= signature
;
11677 dwo_unit
->section
=
11678 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
11679 *dwo_unit
->section
= sections
.info_or_types
;
11680 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11685 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
11686 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
11687 piece within that section used by a TU/CU, return a virtual section
11688 of just that piece. */
11690 static struct dwarf2_section_info
11691 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11692 struct dwarf2_section_info
*section
,
11693 bfd_size_type offset
, bfd_size_type size
)
11695 struct dwarf2_section_info result
;
11698 gdb_assert (section
!= NULL
);
11699 gdb_assert (!section
->is_virtual
);
11701 memset (&result
, 0, sizeof (result
));
11702 result
.s
.containing_section
= section
;
11703 result
.is_virtual
= true;
11708 sectp
= section
->get_bfd_section ();
11710 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
11711 bounds of the real section. This is a pretty-rare event, so just
11712 flag an error (easier) instead of a warning and trying to cope. */
11714 || offset
+ size
> bfd_section_size (sectp
))
11716 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
11717 " in section %s [in module %s]"),
11718 sectp
? bfd_section_name (sectp
) : "<unknown>",
11719 objfile_name (dwarf2_per_objfile
->objfile
));
11722 result
.virtual_offset
= offset
;
11723 result
.size
= size
;
11727 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11728 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11729 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11730 This is for DWP version 2 files. */
11732 static struct dwo_unit
*
11733 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11734 struct dwp_file
*dwp_file
,
11735 uint32_t unit_index
,
11736 const char *comp_dir
,
11737 ULONGEST signature
, int is_debug_types
)
11739 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11740 const struct dwp_hash_table
*dwp_htab
=
11741 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11742 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11743 const char *kind
= is_debug_types
? "TU" : "CU";
11744 struct dwo_file
*dwo_file
;
11745 struct dwo_unit
*dwo_unit
;
11746 struct virtual_v2_dwo_sections sections
;
11747 void **dwo_file_slot
;
11750 gdb_assert (dwp_file
->version
== 2);
11752 if (dwarf_read_debug
)
11754 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
11756 pulongest (unit_index
), hex_string (signature
),
11760 /* Fetch the section offsets of this DWO unit. */
11762 memset (§ions
, 0, sizeof (sections
));
11764 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11766 uint32_t offset
= read_4_bytes (dbfd
,
11767 dwp_htab
->section_pool
.v2
.offsets
11768 + (((unit_index
- 1) * dwp_htab
->nr_columns
11770 * sizeof (uint32_t)));
11771 uint32_t size
= read_4_bytes (dbfd
,
11772 dwp_htab
->section_pool
.v2
.sizes
11773 + (((unit_index
- 1) * dwp_htab
->nr_columns
11775 * sizeof (uint32_t)));
11777 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
11780 case DW_SECT_TYPES
:
11781 sections
.info_or_types_offset
= offset
;
11782 sections
.info_or_types_size
= size
;
11784 case DW_SECT_ABBREV
:
11785 sections
.abbrev_offset
= offset
;
11786 sections
.abbrev_size
= size
;
11789 sections
.line_offset
= offset
;
11790 sections
.line_size
= size
;
11793 sections
.loc_offset
= offset
;
11794 sections
.loc_size
= size
;
11796 case DW_SECT_STR_OFFSETS
:
11797 sections
.str_offsets_offset
= offset
;
11798 sections
.str_offsets_size
= size
;
11800 case DW_SECT_MACINFO
:
11801 sections
.macinfo_offset
= offset
;
11802 sections
.macinfo_size
= size
;
11804 case DW_SECT_MACRO
:
11805 sections
.macro_offset
= offset
;
11806 sections
.macro_size
= size
;
11811 /* It's easier for the rest of the code if we fake a struct dwo_file and
11812 have dwo_unit "live" in that. At least for now.
11814 The DWP file can be made up of a random collection of CUs and TUs.
11815 However, for each CU + set of TUs that came from the same original DWO
11816 file, we can combine them back into a virtual DWO file to save space
11817 (fewer struct dwo_file objects to allocate). Remember that for really
11818 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11820 std::string virtual_dwo_name
=
11821 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
11822 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
11823 (long) (sections
.line_size
? sections
.line_offset
: 0),
11824 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
11825 (long) (sections
.str_offsets_size
11826 ? sections
.str_offsets_offset
: 0));
11827 /* Can we use an existing virtual DWO file? */
11828 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
11829 virtual_dwo_name
.c_str (),
11831 /* Create one if necessary. */
11832 if (*dwo_file_slot
== NULL
)
11834 if (dwarf_read_debug
)
11836 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11837 virtual_dwo_name
.c_str ());
11839 dwo_file
= new struct dwo_file
;
11840 dwo_file
->dwo_name
= obstack_strdup (&objfile
->objfile_obstack
,
11842 dwo_file
->comp_dir
= comp_dir
;
11843 dwo_file
->sections
.abbrev
=
11844 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
11845 sections
.abbrev_offset
, sections
.abbrev_size
);
11846 dwo_file
->sections
.line
=
11847 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
11848 sections
.line_offset
, sections
.line_size
);
11849 dwo_file
->sections
.loc
=
11850 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
11851 sections
.loc_offset
, sections
.loc_size
);
11852 dwo_file
->sections
.macinfo
=
11853 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
11854 sections
.macinfo_offset
, sections
.macinfo_size
);
11855 dwo_file
->sections
.macro
=
11856 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
11857 sections
.macro_offset
, sections
.macro_size
);
11858 dwo_file
->sections
.str_offsets
=
11859 create_dwp_v2_section (dwarf2_per_objfile
,
11860 &dwp_file
->sections
.str_offsets
,
11861 sections
.str_offsets_offset
,
11862 sections
.str_offsets_size
);
11863 /* The "str" section is global to the entire DWP file. */
11864 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11865 /* The info or types section is assigned below to dwo_unit,
11866 there's no need to record it in dwo_file.
11867 Also, we can't simply record type sections in dwo_file because
11868 we record a pointer into the vector in dwo_unit. As we collect more
11869 types we'll grow the vector and eventually have to reallocate space
11870 for it, invalidating all copies of pointers into the previous
11872 *dwo_file_slot
= dwo_file
;
11876 if (dwarf_read_debug
)
11878 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11879 virtual_dwo_name
.c_str ());
11881 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11884 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11885 dwo_unit
->dwo_file
= dwo_file
;
11886 dwo_unit
->signature
= signature
;
11887 dwo_unit
->section
=
11888 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
11889 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
11891 ? &dwp_file
->sections
.types
11892 : &dwp_file
->sections
.info
,
11893 sections
.info_or_types_offset
,
11894 sections
.info_or_types_size
);
11895 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11900 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
11901 Returns NULL if the signature isn't found. */
11903 static struct dwo_unit
*
11904 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11905 struct dwp_file
*dwp_file
, const char *comp_dir
,
11906 ULONGEST signature
, int is_debug_types
)
11908 const struct dwp_hash_table
*dwp_htab
=
11909 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11910 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11911 uint32_t mask
= dwp_htab
->nr_slots
- 1;
11912 uint32_t hash
= signature
& mask
;
11913 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
11916 struct dwo_unit find_dwo_cu
;
11918 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
11919 find_dwo_cu
.signature
= signature
;
11920 slot
= htab_find_slot (is_debug_types
11921 ? dwp_file
->loaded_tus
.get ()
11922 : dwp_file
->loaded_cus
.get (),
11923 &find_dwo_cu
, INSERT
);
11926 return (struct dwo_unit
*) *slot
;
11928 /* Use a for loop so that we don't loop forever on bad debug info. */
11929 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
11931 ULONGEST signature_in_table
;
11933 signature_in_table
=
11934 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
11935 if (signature_in_table
== signature
)
11937 uint32_t unit_index
=
11938 read_4_bytes (dbfd
,
11939 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
11941 if (dwp_file
->version
== 1)
11943 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
11944 dwp_file
, unit_index
,
11945 comp_dir
, signature
,
11950 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
11951 dwp_file
, unit_index
,
11952 comp_dir
, signature
,
11955 return (struct dwo_unit
*) *slot
;
11957 if (signature_in_table
== 0)
11959 hash
= (hash
+ hash2
) & mask
;
11962 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
11963 " [in module %s]"),
11967 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
11968 Open the file specified by FILE_NAME and hand it off to BFD for
11969 preliminary analysis. Return a newly initialized bfd *, which
11970 includes a canonicalized copy of FILE_NAME.
11971 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
11972 SEARCH_CWD is true if the current directory is to be searched.
11973 It will be searched before debug-file-directory.
11974 If successful, the file is added to the bfd include table of the
11975 objfile's bfd (see gdb_bfd_record_inclusion).
11976 If unable to find/open the file, return NULL.
11977 NOTE: This function is derived from symfile_bfd_open. */
11979 static gdb_bfd_ref_ptr
11980 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11981 const char *file_name
, int is_dwp
, int search_cwd
)
11984 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
11985 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
11986 to debug_file_directory. */
11987 const char *search_path
;
11988 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
11990 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
11993 if (*debug_file_directory
!= '\0')
11995 search_path_holder
.reset (concat (".", dirname_separator_string
,
11996 debug_file_directory
,
11998 search_path
= search_path_holder
.get ();
12004 search_path
= debug_file_directory
;
12006 openp_flags flags
= OPF_RETURN_REALPATH
;
12008 flags
|= OPF_SEARCH_IN_PATH
;
12010 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12011 desc
= openp (search_path
, flags
, file_name
,
12012 O_RDONLY
| O_BINARY
, &absolute_name
);
12016 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12018 if (sym_bfd
== NULL
)
12020 bfd_set_cacheable (sym_bfd
.get (), 1);
12022 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12025 /* Success. Record the bfd as having been included by the objfile's bfd.
12026 This is important because things like demangled_names_hash lives in the
12027 objfile's per_bfd space and may have references to things like symbol
12028 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12029 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12034 /* Try to open DWO file FILE_NAME.
12035 COMP_DIR is the DW_AT_comp_dir attribute.
12036 The result is the bfd handle of the file.
12037 If there is a problem finding or opening the file, return NULL.
12038 Upon success, the canonicalized path of the file is stored in the bfd,
12039 same as symfile_bfd_open. */
12041 static gdb_bfd_ref_ptr
12042 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12043 const char *file_name
, const char *comp_dir
)
12045 if (IS_ABSOLUTE_PATH (file_name
))
12046 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12047 0 /*is_dwp*/, 0 /*search_cwd*/);
12049 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12051 if (comp_dir
!= NULL
)
12053 gdb::unique_xmalloc_ptr
<char> path_to_try
12054 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12056 /* NOTE: If comp_dir is a relative path, this will also try the
12057 search path, which seems useful. */
12058 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
12059 path_to_try
.get (),
12061 1 /*search_cwd*/));
12066 /* That didn't work, try debug-file-directory, which, despite its name,
12067 is a list of paths. */
12069 if (*debug_file_directory
== '\0')
12072 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12073 0 /*is_dwp*/, 1 /*search_cwd*/);
12076 /* This function is mapped across the sections and remembers the offset and
12077 size of each of the DWO debugging sections we are interested in. */
12080 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12082 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12083 const struct dwop_section_names
*names
= &dwop_section_names
;
12085 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12087 dwo_sections
->abbrev
.s
.section
= sectp
;
12088 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12090 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12092 dwo_sections
->info
.s
.section
= sectp
;
12093 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12095 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12097 dwo_sections
->line
.s
.section
= sectp
;
12098 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12100 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12102 dwo_sections
->loc
.s
.section
= sectp
;
12103 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12105 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12107 dwo_sections
->macinfo
.s
.section
= sectp
;
12108 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12110 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12112 dwo_sections
->macro
.s
.section
= sectp
;
12113 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12115 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12117 dwo_sections
->str
.s
.section
= sectp
;
12118 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12120 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12122 dwo_sections
->str_offsets
.s
.section
= sectp
;
12123 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12125 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12127 struct dwarf2_section_info type_section
;
12129 memset (&type_section
, 0, sizeof (type_section
));
12130 type_section
.s
.section
= sectp
;
12131 type_section
.size
= bfd_section_size (sectp
);
12132 dwo_sections
->types
.push_back (type_section
);
12136 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12137 by PER_CU. This is for the non-DWP case.
12138 The result is NULL if DWO_NAME can't be found. */
12140 static struct dwo_file
*
12141 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
12142 const char *dwo_name
, const char *comp_dir
)
12144 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
12146 gdb_bfd_ref_ptr dbfd
= open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
);
12149 if (dwarf_read_debug
)
12150 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
12154 dwo_file_up
dwo_file (new struct dwo_file
);
12155 dwo_file
->dwo_name
= dwo_name
;
12156 dwo_file
->comp_dir
= comp_dir
;
12157 dwo_file
->dbfd
= std::move (dbfd
);
12159 bfd_map_over_sections (dwo_file
->dbfd
.get (), dwarf2_locate_dwo_sections
,
12160 &dwo_file
->sections
);
12162 create_cus_hash_table (dwarf2_per_objfile
, per_cu
->cu
, *dwo_file
,
12163 dwo_file
->sections
.info
, dwo_file
->cus
);
12165 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
.get (),
12166 dwo_file
->sections
.types
, dwo_file
->tus
);
12168 if (dwarf_read_debug
)
12169 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
12171 return dwo_file
.release ();
12174 /* This function is mapped across the sections and remembers the offset and
12175 size of each of the DWP debugging sections common to version 1 and 2 that
12176 we are interested in. */
12179 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12180 void *dwp_file_ptr
)
12182 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12183 const struct dwop_section_names
*names
= &dwop_section_names
;
12184 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12186 /* Record the ELF section number for later lookup: this is what the
12187 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12188 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12189 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12191 /* Look for specific sections that we need. */
12192 if (section_is_p (sectp
->name
, &names
->str_dwo
))
12194 dwp_file
->sections
.str
.s
.section
= sectp
;
12195 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12197 else if (section_is_p (sectp
->name
, &names
->cu_index
))
12199 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12200 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12202 else if (section_is_p (sectp
->name
, &names
->tu_index
))
12204 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12205 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12209 /* This function is mapped across the sections and remembers the offset and
12210 size of each of the DWP version 2 debugging sections that we are interested
12211 in. This is split into a separate function because we don't know if we
12212 have version 1 or 2 until we parse the cu_index/tu_index sections. */
12215 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12217 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12218 const struct dwop_section_names
*names
= &dwop_section_names
;
12219 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12221 /* Record the ELF section number for later lookup: this is what the
12222 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12223 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12224 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12226 /* Look for specific sections that we need. */
12227 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12229 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12230 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12232 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12234 dwp_file
->sections
.info
.s
.section
= sectp
;
12235 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12237 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12239 dwp_file
->sections
.line
.s
.section
= sectp
;
12240 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12242 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12244 dwp_file
->sections
.loc
.s
.section
= sectp
;
12245 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12247 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12249 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12250 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12252 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12254 dwp_file
->sections
.macro
.s
.section
= sectp
;
12255 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12257 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12259 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12260 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12262 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12264 dwp_file
->sections
.types
.s
.section
= sectp
;
12265 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12269 /* Hash function for dwp_file loaded CUs/TUs. */
12272 hash_dwp_loaded_cutus (const void *item
)
12274 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12276 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12277 return dwo_unit
->signature
;
12280 /* Equality function for dwp_file loaded CUs/TUs. */
12283 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12285 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12286 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12288 return dua
->signature
== dub
->signature
;
12291 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12294 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
12296 return htab_up (htab_create_alloc (3,
12297 hash_dwp_loaded_cutus
,
12298 eq_dwp_loaded_cutus
,
12299 NULL
, xcalloc
, xfree
));
12302 /* Try to open DWP file FILE_NAME.
12303 The result is the bfd handle of the file.
12304 If there is a problem finding or opening the file, return NULL.
12305 Upon success, the canonicalized path of the file is stored in the bfd,
12306 same as symfile_bfd_open. */
12308 static gdb_bfd_ref_ptr
12309 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12310 const char *file_name
)
12312 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12314 1 /*search_cwd*/));
12318 /* Work around upstream bug 15652.
12319 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12320 [Whether that's a "bug" is debatable, but it is getting in our way.]
12321 We have no real idea where the dwp file is, because gdb's realpath-ing
12322 of the executable's path may have discarded the needed info.
12323 [IWBN if the dwp file name was recorded in the executable, akin to
12324 .gnu_debuglink, but that doesn't exist yet.]
12325 Strip the directory from FILE_NAME and search again. */
12326 if (*debug_file_directory
!= '\0')
12328 /* Don't implicitly search the current directory here.
12329 If the user wants to search "." to handle this case,
12330 it must be added to debug-file-directory. */
12331 return try_open_dwop_file (dwarf2_per_objfile
,
12332 lbasename (file_name
), 1 /*is_dwp*/,
12339 /* Initialize the use of the DWP file for the current objfile.
12340 By convention the name of the DWP file is ${objfile}.dwp.
12341 The result is NULL if it can't be found. */
12343 static std::unique_ptr
<struct dwp_file
>
12344 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12346 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12348 /* Try to find first .dwp for the binary file before any symbolic links
12351 /* If the objfile is a debug file, find the name of the real binary
12352 file and get the name of dwp file from there. */
12353 std::string dwp_name
;
12354 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
12356 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
12357 const char *backlink_basename
= lbasename (backlink
->original_name
);
12359 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
12362 dwp_name
= objfile
->original_name
;
12364 dwp_name
+= ".dwp";
12366 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
12368 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
12370 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
12371 dwp_name
= objfile_name (objfile
);
12372 dwp_name
+= ".dwp";
12373 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
12378 if (dwarf_read_debug
)
12379 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
12380 return std::unique_ptr
<dwp_file
> ();
12383 const char *name
= bfd_get_filename (dbfd
.get ());
12384 std::unique_ptr
<struct dwp_file
> dwp_file
12385 (new struct dwp_file (name
, std::move (dbfd
)));
12387 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
12388 dwp_file
->elf_sections
=
12389 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
12390 dwp_file
->num_sections
, asection
*);
12392 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12393 dwarf2_locate_common_dwp_sections
,
12396 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12399 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12402 /* The DWP file version is stored in the hash table. Oh well. */
12403 if (dwp_file
->cus
&& dwp_file
->tus
12404 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
12406 /* Technically speaking, we should try to limp along, but this is
12407 pretty bizarre. We use pulongest here because that's the established
12408 portability solution (e.g, we cannot use %u for uint32_t). */
12409 error (_("Dwarf Error: DWP file CU version %s doesn't match"
12410 " TU version %s [in DWP file %s]"),
12411 pulongest (dwp_file
->cus
->version
),
12412 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
12416 dwp_file
->version
= dwp_file
->cus
->version
;
12417 else if (dwp_file
->tus
)
12418 dwp_file
->version
= dwp_file
->tus
->version
;
12420 dwp_file
->version
= 2;
12422 if (dwp_file
->version
== 2)
12423 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12424 dwarf2_locate_v2_dwp_sections
,
12427 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table (objfile
);
12428 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table (objfile
);
12430 if (dwarf_read_debug
)
12432 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
12433 fprintf_unfiltered (gdb_stdlog
,
12434 " %s CUs, %s TUs\n",
12435 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
12436 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
12442 /* Wrapper around open_and_init_dwp_file, only open it once. */
12444 static struct dwp_file
*
12445 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12447 if (! dwarf2_per_objfile
->dwp_checked
)
12449 dwarf2_per_objfile
->dwp_file
12450 = open_and_init_dwp_file (dwarf2_per_objfile
);
12451 dwarf2_per_objfile
->dwp_checked
= 1;
12453 return dwarf2_per_objfile
->dwp_file
.get ();
12456 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
12457 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
12458 or in the DWP file for the objfile, referenced by THIS_UNIT.
12459 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
12460 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
12462 This is called, for example, when wanting to read a variable with a
12463 complex location. Therefore we don't want to do file i/o for every call.
12464 Therefore we don't want to look for a DWO file on every call.
12465 Therefore we first see if we've already seen SIGNATURE in a DWP file,
12466 then we check if we've already seen DWO_NAME, and only THEN do we check
12469 The result is a pointer to the dwo_unit object or NULL if we didn't find it
12470 (dwo_id mismatch or couldn't find the DWO/DWP file). */
12472 static struct dwo_unit
*
12473 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
12474 const char *dwo_name
, const char *comp_dir
,
12475 ULONGEST signature
, int is_debug_types
)
12477 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_unit
->dwarf2_per_objfile
;
12478 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12479 const char *kind
= is_debug_types
? "TU" : "CU";
12480 void **dwo_file_slot
;
12481 struct dwo_file
*dwo_file
;
12482 struct dwp_file
*dwp_file
;
12484 /* First see if there's a DWP file.
12485 If we have a DWP file but didn't find the DWO inside it, don't
12486 look for the original DWO file. It makes gdb behave differently
12487 depending on whether one is debugging in the build tree. */
12489 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
12490 if (dwp_file
!= NULL
)
12492 const struct dwp_hash_table
*dwp_htab
=
12493 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12495 if (dwp_htab
!= NULL
)
12497 struct dwo_unit
*dwo_cutu
=
12498 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
12499 signature
, is_debug_types
);
12501 if (dwo_cutu
!= NULL
)
12503 if (dwarf_read_debug
)
12505 fprintf_unfiltered (gdb_stdlog
,
12506 "Virtual DWO %s %s found: @%s\n",
12507 kind
, hex_string (signature
),
12508 host_address_to_string (dwo_cutu
));
12516 /* No DWP file, look for the DWO file. */
12518 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12519 dwo_name
, comp_dir
);
12520 if (*dwo_file_slot
== NULL
)
12522 /* Read in the file and build a table of the CUs/TUs it contains. */
12523 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
12525 /* NOTE: This will be NULL if unable to open the file. */
12526 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12528 if (dwo_file
!= NULL
)
12530 struct dwo_unit
*dwo_cutu
= NULL
;
12532 if (is_debug_types
&& dwo_file
->tus
)
12534 struct dwo_unit find_dwo_cutu
;
12536 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12537 find_dwo_cutu
.signature
= signature
;
12539 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
12542 else if (!is_debug_types
&& dwo_file
->cus
)
12544 struct dwo_unit find_dwo_cutu
;
12546 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12547 find_dwo_cutu
.signature
= signature
;
12548 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
12552 if (dwo_cutu
!= NULL
)
12554 if (dwarf_read_debug
)
12556 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
12557 kind
, dwo_name
, hex_string (signature
),
12558 host_address_to_string (dwo_cutu
));
12565 /* We didn't find it. This could mean a dwo_id mismatch, or
12566 someone deleted the DWO/DWP file, or the search path isn't set up
12567 correctly to find the file. */
12569 if (dwarf_read_debug
)
12571 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
12572 kind
, dwo_name
, hex_string (signature
));
12575 /* This is a warning and not a complaint because it can be caused by
12576 pilot error (e.g., user accidentally deleting the DWO). */
12578 /* Print the name of the DWP file if we looked there, helps the user
12579 better diagnose the problem. */
12580 std::string dwp_text
;
12582 if (dwp_file
!= NULL
)
12583 dwp_text
= string_printf (" [in DWP file %s]",
12584 lbasename (dwp_file
->name
));
12586 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
12587 " [in module %s]"),
12588 kind
, dwo_name
, hex_string (signature
),
12590 this_unit
->is_debug_types
? "TU" : "CU",
12591 sect_offset_str (this_unit
->sect_off
), objfile_name (objfile
));
12596 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
12597 See lookup_dwo_cutu_unit for details. */
12599 static struct dwo_unit
*
12600 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
12601 const char *dwo_name
, const char *comp_dir
,
12602 ULONGEST signature
)
12604 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
12607 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
12608 See lookup_dwo_cutu_unit for details. */
12610 static struct dwo_unit
*
12611 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
12612 const char *dwo_name
, const char *comp_dir
)
12614 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
12617 /* Traversal function for queue_and_load_all_dwo_tus. */
12620 queue_and_load_dwo_tu (void **slot
, void *info
)
12622 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
12623 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
12624 ULONGEST signature
= dwo_unit
->signature
;
12625 struct signatured_type
*sig_type
=
12626 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
12628 if (sig_type
!= NULL
)
12630 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
12632 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
12633 a real dependency of PER_CU on SIG_TYPE. That is detected later
12634 while processing PER_CU. */
12635 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
12636 load_full_type_unit (sig_cu
);
12637 per_cu
->imported_symtabs_push (sig_cu
);
12643 /* Queue all TUs contained in the DWO of PER_CU to be read in.
12644 The DWO may have the only definition of the type, though it may not be
12645 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
12646 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
12649 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
12651 struct dwo_unit
*dwo_unit
;
12652 struct dwo_file
*dwo_file
;
12654 gdb_assert (!per_cu
->is_debug_types
);
12655 gdb_assert (get_dwp_file (per_cu
->dwarf2_per_objfile
) == NULL
);
12656 gdb_assert (per_cu
->cu
!= NULL
);
12658 dwo_unit
= per_cu
->cu
->dwo_unit
;
12659 gdb_assert (dwo_unit
!= NULL
);
12661 dwo_file
= dwo_unit
->dwo_file
;
12662 if (dwo_file
->tus
!= NULL
)
12663 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
,
12667 /* Read in various DIEs. */
12669 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
12670 Inherit only the children of the DW_AT_abstract_origin DIE not being
12671 already referenced by DW_AT_abstract_origin from the children of the
12675 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
12677 struct die_info
*child_die
;
12678 sect_offset
*offsetp
;
12679 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
12680 struct die_info
*origin_die
;
12681 /* Iterator of the ORIGIN_DIE children. */
12682 struct die_info
*origin_child_die
;
12683 struct attribute
*attr
;
12684 struct dwarf2_cu
*origin_cu
;
12685 struct pending
**origin_previous_list_in_scope
;
12687 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
12691 /* Note that following die references may follow to a die in a
12695 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
12697 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
12699 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
12700 origin_cu
->list_in_scope
= cu
->list_in_scope
;
12702 if (die
->tag
!= origin_die
->tag
12703 && !(die
->tag
== DW_TAG_inlined_subroutine
12704 && origin_die
->tag
== DW_TAG_subprogram
))
12705 complaint (_("DIE %s and its abstract origin %s have different tags"),
12706 sect_offset_str (die
->sect_off
),
12707 sect_offset_str (origin_die
->sect_off
));
12709 std::vector
<sect_offset
> offsets
;
12711 for (child_die
= die
->child
;
12712 child_die
&& child_die
->tag
;
12713 child_die
= sibling_die (child_die
))
12715 struct die_info
*child_origin_die
;
12716 struct dwarf2_cu
*child_origin_cu
;
12718 /* We are trying to process concrete instance entries:
12719 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
12720 it's not relevant to our analysis here. i.e. detecting DIEs that are
12721 present in the abstract instance but not referenced in the concrete
12723 if (child_die
->tag
== DW_TAG_call_site
12724 || child_die
->tag
== DW_TAG_GNU_call_site
)
12727 /* For each CHILD_DIE, find the corresponding child of
12728 ORIGIN_DIE. If there is more than one layer of
12729 DW_AT_abstract_origin, follow them all; there shouldn't be,
12730 but GCC versions at least through 4.4 generate this (GCC PR
12732 child_origin_die
= child_die
;
12733 child_origin_cu
= cu
;
12736 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
12740 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
12744 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
12745 counterpart may exist. */
12746 if (child_origin_die
!= child_die
)
12748 if (child_die
->tag
!= child_origin_die
->tag
12749 && !(child_die
->tag
== DW_TAG_inlined_subroutine
12750 && child_origin_die
->tag
== DW_TAG_subprogram
))
12751 complaint (_("Child DIE %s and its abstract origin %s have "
12753 sect_offset_str (child_die
->sect_off
),
12754 sect_offset_str (child_origin_die
->sect_off
));
12755 if (child_origin_die
->parent
!= origin_die
)
12756 complaint (_("Child DIE %s and its abstract origin %s have "
12757 "different parents"),
12758 sect_offset_str (child_die
->sect_off
),
12759 sect_offset_str (child_origin_die
->sect_off
));
12761 offsets
.push_back (child_origin_die
->sect_off
);
12764 std::sort (offsets
.begin (), offsets
.end ());
12765 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
12766 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
12767 if (offsetp
[-1] == *offsetp
)
12768 complaint (_("Multiple children of DIE %s refer "
12769 "to DIE %s as their abstract origin"),
12770 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
12772 offsetp
= offsets
.data ();
12773 origin_child_die
= origin_die
->child
;
12774 while (origin_child_die
&& origin_child_die
->tag
)
12776 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
12777 while (offsetp
< offsets_end
12778 && *offsetp
< origin_child_die
->sect_off
)
12780 if (offsetp
>= offsets_end
12781 || *offsetp
> origin_child_die
->sect_off
)
12783 /* Found that ORIGIN_CHILD_DIE is really not referenced.
12784 Check whether we're already processing ORIGIN_CHILD_DIE.
12785 This can happen with mutually referenced abstract_origins.
12787 if (!origin_child_die
->in_process
)
12788 process_die (origin_child_die
, origin_cu
);
12790 origin_child_die
= sibling_die (origin_child_die
);
12792 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
12794 if (cu
!= origin_cu
)
12795 compute_delayed_physnames (origin_cu
);
12799 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12801 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
12802 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12803 struct context_stack
*newobj
;
12806 struct die_info
*child_die
;
12807 struct attribute
*attr
, *call_line
, *call_file
;
12809 CORE_ADDR baseaddr
;
12810 struct block
*block
;
12811 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
12812 std::vector
<struct symbol
*> template_args
;
12813 struct template_symbol
*templ_func
= NULL
;
12817 /* If we do not have call site information, we can't show the
12818 caller of this inlined function. That's too confusing, so
12819 only use the scope for local variables. */
12820 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
12821 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
12822 if (call_line
== NULL
|| call_file
== NULL
)
12824 read_lexical_block_scope (die
, cu
);
12829 baseaddr
= objfile
->text_section_offset ();
12831 name
= dwarf2_name (die
, cu
);
12833 /* Ignore functions with missing or empty names. These are actually
12834 illegal according to the DWARF standard. */
12837 complaint (_("missing name for subprogram DIE at %s"),
12838 sect_offset_str (die
->sect_off
));
12842 /* Ignore functions with missing or invalid low and high pc attributes. */
12843 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
12844 <= PC_BOUNDS_INVALID
)
12846 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
12847 if (!attr
|| !DW_UNSND (attr
))
12848 complaint (_("cannot get low and high bounds "
12849 "for subprogram DIE at %s"),
12850 sect_offset_str (die
->sect_off
));
12854 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
12855 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
12857 /* If we have any template arguments, then we must allocate a
12858 different sort of symbol. */
12859 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
12861 if (child_die
->tag
== DW_TAG_template_type_param
12862 || child_die
->tag
== DW_TAG_template_value_param
)
12864 templ_func
= allocate_template_symbol (objfile
);
12865 templ_func
->subclass
= SYMBOL_TEMPLATE
;
12870 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
12871 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
12872 (struct symbol
*) templ_func
);
12874 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
12875 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
12878 /* If there is a location expression for DW_AT_frame_base, record
12880 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
12881 if (attr
!= nullptr)
12882 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
12884 /* If there is a location for the static link, record it. */
12885 newobj
->static_link
= NULL
;
12886 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
12887 if (attr
!= nullptr)
12889 newobj
->static_link
12890 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
12891 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
12892 cu
->per_cu
->addr_type ());
12895 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
12897 if (die
->child
!= NULL
)
12899 child_die
= die
->child
;
12900 while (child_die
&& child_die
->tag
)
12902 if (child_die
->tag
== DW_TAG_template_type_param
12903 || child_die
->tag
== DW_TAG_template_value_param
)
12905 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
12908 template_args
.push_back (arg
);
12911 process_die (child_die
, cu
);
12912 child_die
= sibling_die (child_die
);
12916 inherit_abstract_dies (die
, cu
);
12918 /* If we have a DW_AT_specification, we might need to import using
12919 directives from the context of the specification DIE. See the
12920 comment in determine_prefix. */
12921 if (cu
->language
== language_cplus
12922 && dwarf2_attr (die
, DW_AT_specification
, cu
))
12924 struct dwarf2_cu
*spec_cu
= cu
;
12925 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
12929 child_die
= spec_die
->child
;
12930 while (child_die
&& child_die
->tag
)
12932 if (child_die
->tag
== DW_TAG_imported_module
)
12933 process_die (child_die
, spec_cu
);
12934 child_die
= sibling_die (child_die
);
12937 /* In some cases, GCC generates specification DIEs that
12938 themselves contain DW_AT_specification attributes. */
12939 spec_die
= die_specification (spec_die
, &spec_cu
);
12943 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
12944 /* Make a block for the local symbols within. */
12945 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
12946 cstk
.static_link
, lowpc
, highpc
);
12948 /* For C++, set the block's scope. */
12949 if ((cu
->language
== language_cplus
12950 || cu
->language
== language_fortran
12951 || cu
->language
== language_d
12952 || cu
->language
== language_rust
)
12953 && cu
->processing_has_namespace_info
)
12954 block_set_scope (block
, determine_prefix (die
, cu
),
12955 &objfile
->objfile_obstack
);
12957 /* If we have address ranges, record them. */
12958 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
12960 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
12962 /* Attach template arguments to function. */
12963 if (!template_args
.empty ())
12965 gdb_assert (templ_func
!= NULL
);
12967 templ_func
->n_template_arguments
= template_args
.size ();
12968 templ_func
->template_arguments
12969 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
12970 templ_func
->n_template_arguments
);
12971 memcpy (templ_func
->template_arguments
,
12972 template_args
.data (),
12973 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
12975 /* Make sure that the symtab is set on the new symbols. Even
12976 though they don't appear in this symtab directly, other parts
12977 of gdb assume that symbols do, and this is reasonably
12979 for (symbol
*sym
: template_args
)
12980 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
12983 /* In C++, we can have functions nested inside functions (e.g., when
12984 a function declares a class that has methods). This means that
12985 when we finish processing a function scope, we may need to go
12986 back to building a containing block's symbol lists. */
12987 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
12988 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
12990 /* If we've finished processing a top-level function, subsequent
12991 symbols go in the file symbol list. */
12992 if (cu
->get_builder ()->outermost_context_p ())
12993 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
12996 /* Process all the DIES contained within a lexical block scope. Start
12997 a new scope, process the dies, and then close the scope. */
13000 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13002 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13003 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13004 CORE_ADDR lowpc
, highpc
;
13005 struct die_info
*child_die
;
13006 CORE_ADDR baseaddr
;
13008 baseaddr
= objfile
->text_section_offset ();
13010 /* Ignore blocks with missing or invalid low and high pc attributes. */
13011 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13012 as multiple lexical blocks? Handling children in a sane way would
13013 be nasty. Might be easier to properly extend generic blocks to
13014 describe ranges. */
13015 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13017 case PC_BOUNDS_NOT_PRESENT
:
13018 /* DW_TAG_lexical_block has no attributes, process its children as if
13019 there was no wrapping by that DW_TAG_lexical_block.
13020 GCC does no longer produces such DWARF since GCC r224161. */
13021 for (child_die
= die
->child
;
13022 child_die
!= NULL
&& child_die
->tag
;
13023 child_die
= sibling_die (child_die
))
13024 process_die (child_die
, cu
);
13026 case PC_BOUNDS_INVALID
:
13029 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13030 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13032 cu
->get_builder ()->push_context (0, lowpc
);
13033 if (die
->child
!= NULL
)
13035 child_die
= die
->child
;
13036 while (child_die
&& child_die
->tag
)
13038 process_die (child_die
, cu
);
13039 child_die
= sibling_die (child_die
);
13042 inherit_abstract_dies (die
, cu
);
13043 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13045 if (*cu
->get_builder ()->get_local_symbols () != NULL
13046 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13048 struct block
*block
13049 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13050 cstk
.start_addr
, highpc
);
13052 /* Note that recording ranges after traversing children, as we
13053 do here, means that recording a parent's ranges entails
13054 walking across all its children's ranges as they appear in
13055 the address map, which is quadratic behavior.
13057 It would be nicer to record the parent's ranges before
13058 traversing its children, simply overriding whatever you find
13059 there. But since we don't even decide whether to create a
13060 block until after we've traversed its children, that's hard
13062 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13064 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13065 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13068 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13071 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13073 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13074 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13075 CORE_ADDR pc
, baseaddr
;
13076 struct attribute
*attr
;
13077 struct call_site
*call_site
, call_site_local
;
13080 struct die_info
*child_die
;
13082 baseaddr
= objfile
->text_section_offset ();
13084 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13087 /* This was a pre-DWARF-5 GNU extension alias
13088 for DW_AT_call_return_pc. */
13089 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13093 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13094 "DIE %s [in module %s]"),
13095 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13098 pc
= attr
->value_as_address () + baseaddr
;
13099 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13101 if (cu
->call_site_htab
== NULL
)
13102 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13103 NULL
, &objfile
->objfile_obstack
,
13104 hashtab_obstack_allocate
, NULL
);
13105 call_site_local
.pc
= pc
;
13106 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13109 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13110 "DIE %s [in module %s]"),
13111 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13112 objfile_name (objfile
));
13116 /* Count parameters at the caller. */
13119 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13120 child_die
= sibling_die (child_die
))
13122 if (child_die
->tag
!= DW_TAG_call_site_parameter
13123 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13125 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13126 "DW_TAG_call_site child DIE %s [in module %s]"),
13127 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13128 objfile_name (objfile
));
13136 = ((struct call_site
*)
13137 obstack_alloc (&objfile
->objfile_obstack
,
13138 sizeof (*call_site
)
13139 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13141 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13142 call_site
->pc
= pc
;
13144 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13145 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13147 struct die_info
*func_die
;
13149 /* Skip also over DW_TAG_inlined_subroutine. */
13150 for (func_die
= die
->parent
;
13151 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13152 && func_die
->tag
!= DW_TAG_subroutine_type
;
13153 func_die
= func_die
->parent
);
13155 /* DW_AT_call_all_calls is a superset
13156 of DW_AT_call_all_tail_calls. */
13158 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13159 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13160 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13161 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13163 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13164 not complete. But keep CALL_SITE for look ups via call_site_htab,
13165 both the initial caller containing the real return address PC and
13166 the final callee containing the current PC of a chain of tail
13167 calls do not need to have the tail call list complete. But any
13168 function candidate for a virtual tail call frame searched via
13169 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13170 determined unambiguously. */
13174 struct type
*func_type
= NULL
;
13177 func_type
= get_die_type (func_die
, cu
);
13178 if (func_type
!= NULL
)
13180 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
13182 /* Enlist this call site to the function. */
13183 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13184 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13187 complaint (_("Cannot find function owning DW_TAG_call_site "
13188 "DIE %s [in module %s]"),
13189 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13193 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13195 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13197 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13200 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13201 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13203 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13204 if (!attr
|| (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0))
13205 /* Keep NULL DWARF_BLOCK. */;
13206 else if (attr
->form_is_block ())
13208 struct dwarf2_locexpr_baton
*dlbaton
;
13210 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13211 dlbaton
->data
= DW_BLOCK (attr
)->data
;
13212 dlbaton
->size
= DW_BLOCK (attr
)->size
;
13213 dlbaton
->per_cu
= cu
->per_cu
;
13215 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13217 else if (attr
->form_is_ref ())
13219 struct dwarf2_cu
*target_cu
= cu
;
13220 struct die_info
*target_die
;
13222 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13223 gdb_assert (target_cu
->per_cu
->dwarf2_per_objfile
->objfile
== objfile
);
13224 if (die_is_declaration (target_die
, target_cu
))
13226 const char *target_physname
;
13228 /* Prefer the mangled name; otherwise compute the demangled one. */
13229 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13230 if (target_physname
== NULL
)
13231 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13232 if (target_physname
== NULL
)
13233 complaint (_("DW_AT_call_target target DIE has invalid "
13234 "physname, for referencing DIE %s [in module %s]"),
13235 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13237 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13243 /* DW_AT_entry_pc should be preferred. */
13244 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13245 <= PC_BOUNDS_INVALID
)
13246 complaint (_("DW_AT_call_target target DIE has invalid "
13247 "low pc, for referencing DIE %s [in module %s]"),
13248 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13251 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13252 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
13257 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13258 "block nor reference, for DIE %s [in module %s]"),
13259 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13261 call_site
->per_cu
= cu
->per_cu
;
13263 for (child_die
= die
->child
;
13264 child_die
&& child_die
->tag
;
13265 child_die
= sibling_die (child_die
))
13267 struct call_site_parameter
*parameter
;
13268 struct attribute
*loc
, *origin
;
13270 if (child_die
->tag
!= DW_TAG_call_site_parameter
13271 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13273 /* Already printed the complaint above. */
13277 gdb_assert (call_site
->parameter_count
< nparams
);
13278 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13280 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13281 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13282 register is contained in DW_AT_call_value. */
13284 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13285 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13286 if (origin
== NULL
)
13288 /* This was a pre-DWARF-5 GNU extension alias
13289 for DW_AT_call_parameter. */
13290 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13292 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
13294 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13296 sect_offset sect_off
13297 = (sect_offset
) dwarf2_get_ref_die_offset (origin
);
13298 if (!cu
->header
.offset_in_cu_p (sect_off
))
13300 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13301 binding can be done only inside one CU. Such referenced DIE
13302 therefore cannot be even moved to DW_TAG_partial_unit. */
13303 complaint (_("DW_AT_call_parameter offset is not in CU for "
13304 "DW_TAG_call_site child DIE %s [in module %s]"),
13305 sect_offset_str (child_die
->sect_off
),
13306 objfile_name (objfile
));
13309 parameter
->u
.param_cu_off
13310 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13312 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
13314 complaint (_("No DW_FORM_block* DW_AT_location for "
13315 "DW_TAG_call_site child DIE %s [in module %s]"),
13316 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13321 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13322 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
13323 if (parameter
->u
.dwarf_reg
!= -1)
13324 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13325 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
13326 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
13327 ¶meter
->u
.fb_offset
))
13328 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13331 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13332 "for DW_FORM_block* DW_AT_location is supported for "
13333 "DW_TAG_call_site child DIE %s "
13335 sect_offset_str (child_die
->sect_off
),
13336 objfile_name (objfile
));
13341 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13343 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13344 if (attr
== NULL
|| !attr
->form_is_block ())
13346 complaint (_("No DW_FORM_block* DW_AT_call_value for "
13347 "DW_TAG_call_site child DIE %s [in module %s]"),
13348 sect_offset_str (child_die
->sect_off
),
13349 objfile_name (objfile
));
13352 parameter
->value
= DW_BLOCK (attr
)->data
;
13353 parameter
->value_size
= DW_BLOCK (attr
)->size
;
13355 /* Parameters are not pre-cleared by memset above. */
13356 parameter
->data_value
= NULL
;
13357 parameter
->data_value_size
= 0;
13358 call_site
->parameter_count
++;
13360 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
13362 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
13363 if (attr
!= nullptr)
13365 if (!attr
->form_is_block ())
13366 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
13367 "DW_TAG_call_site child DIE %s [in module %s]"),
13368 sect_offset_str (child_die
->sect_off
),
13369 objfile_name (objfile
));
13372 parameter
->data_value
= DW_BLOCK (attr
)->data
;
13373 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
13379 /* Helper function for read_variable. If DIE represents a virtual
13380 table, then return the type of the concrete object that is
13381 associated with the virtual table. Otherwise, return NULL. */
13383 static struct type
*
13384 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13386 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13390 /* Find the type DIE. */
13391 struct die_info
*type_die
= NULL
;
13392 struct dwarf2_cu
*type_cu
= cu
;
13394 if (attr
->form_is_ref ())
13395 type_die
= follow_die_ref (die
, attr
, &type_cu
);
13396 if (type_die
== NULL
)
13399 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
13401 return die_containing_type (type_die
, type_cu
);
13404 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
13407 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
13409 struct rust_vtable_symbol
*storage
= NULL
;
13411 if (cu
->language
== language_rust
)
13413 struct type
*containing_type
= rust_containing_type (die
, cu
);
13415 if (containing_type
!= NULL
)
13417 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13419 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol ();
13420 initialize_objfile_symbol (storage
);
13421 storage
->concrete_type
= containing_type
;
13422 storage
->subclass
= SYMBOL_RUST_VTABLE
;
13426 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
13427 struct attribute
*abstract_origin
13428 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13429 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
13430 if (res
== NULL
&& loc
&& abstract_origin
)
13432 /* We have a variable without a name, but with a location and an abstract
13433 origin. This may be a concrete instance of an abstract variable
13434 referenced from an DW_OP_GNU_variable_value, so save it to find it back
13436 struct dwarf2_cu
*origin_cu
= cu
;
13437 struct die_info
*origin_die
13438 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
13439 dwarf2_per_objfile
*dpo
= cu
->per_cu
->dwarf2_per_objfile
;
13440 dpo
->abstract_to_concrete
[origin_die
->sect_off
].push_back (die
->sect_off
);
13444 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
13445 reading .debug_rnglists.
13446 Callback's type should be:
13447 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13448 Return true if the attributes are present and valid, otherwise,
13451 template <typename Callback
>
13453 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
13454 Callback
&&callback
)
13456 struct dwarf2_per_objfile
*dwarf2_per_objfile
13457 = cu
->per_cu
->dwarf2_per_objfile
;
13458 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13459 bfd
*obfd
= objfile
->obfd
;
13460 /* Base address selection entry. */
13463 const gdb_byte
*buffer
;
13464 CORE_ADDR baseaddr
;
13465 bool overflow
= false;
13467 found_base
= cu
->base_known
;
13468 base
= cu
->base_address
;
13470 dwarf2_per_objfile
->rnglists
.read (objfile
);
13471 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
13473 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13477 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
13479 baseaddr
= objfile
->text_section_offset ();
13483 /* Initialize it due to a false compiler warning. */
13484 CORE_ADDR range_beginning
= 0, range_end
= 0;
13485 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
13486 + dwarf2_per_objfile
->rnglists
.size
);
13487 unsigned int bytes_read
;
13489 if (buffer
== buf_end
)
13494 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
13497 case DW_RLE_end_of_list
:
13499 case DW_RLE_base_address
:
13500 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13505 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13507 buffer
+= bytes_read
;
13509 case DW_RLE_start_length
:
13510 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13515 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13517 buffer
+= bytes_read
;
13518 range_end
= (range_beginning
13519 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13520 buffer
+= bytes_read
;
13521 if (buffer
> buf_end
)
13527 case DW_RLE_offset_pair
:
13528 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13529 buffer
+= bytes_read
;
13530 if (buffer
> buf_end
)
13535 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13536 buffer
+= bytes_read
;
13537 if (buffer
> buf_end
)
13543 case DW_RLE_start_end
:
13544 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
13549 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13551 buffer
+= bytes_read
;
13552 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13553 buffer
+= bytes_read
;
13556 complaint (_("Invalid .debug_rnglists data (no base address)"));
13559 if (rlet
== DW_RLE_end_of_list
|| overflow
)
13561 if (rlet
== DW_RLE_base_address
)
13566 /* We have no valid base address for the ranges
13568 complaint (_("Invalid .debug_rnglists data (no base address)"));
13572 if (range_beginning
> range_end
)
13574 /* Inverted range entries are invalid. */
13575 complaint (_("Invalid .debug_rnglists data (inverted range)"));
13579 /* Empty range entries have no effect. */
13580 if (range_beginning
== range_end
)
13583 range_beginning
+= base
;
13586 /* A not-uncommon case of bad debug info.
13587 Don't pollute the addrmap with bad data. */
13588 if (range_beginning
+ baseaddr
== 0
13589 && !dwarf2_per_objfile
->has_section_at_zero
)
13591 complaint (_(".debug_rnglists entry has start address of zero"
13592 " [in module %s]"), objfile_name (objfile
));
13596 callback (range_beginning
, range_end
);
13601 complaint (_("Offset %d is not terminated "
13602 "for DW_AT_ranges attribute"),
13610 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
13611 Callback's type should be:
13612 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13613 Return 1 if the attributes are present and valid, otherwise, return 0. */
13615 template <typename Callback
>
13617 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
13618 Callback
&&callback
)
13620 struct dwarf2_per_objfile
*dwarf2_per_objfile
13621 = cu
->per_cu
->dwarf2_per_objfile
;
13622 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13623 struct comp_unit_head
*cu_header
= &cu
->header
;
13624 bfd
*obfd
= objfile
->obfd
;
13625 unsigned int addr_size
= cu_header
->addr_size
;
13626 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
13627 /* Base address selection entry. */
13630 unsigned int dummy
;
13631 const gdb_byte
*buffer
;
13632 CORE_ADDR baseaddr
;
13634 if (cu_header
->version
>= 5)
13635 return dwarf2_rnglists_process (offset
, cu
, callback
);
13637 found_base
= cu
->base_known
;
13638 base
= cu
->base_address
;
13640 dwarf2_per_objfile
->ranges
.read (objfile
);
13641 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
13643 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13647 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
13649 baseaddr
= objfile
->text_section_offset ();
13653 CORE_ADDR range_beginning
, range_end
;
13655 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13656 buffer
+= addr_size
;
13657 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13658 buffer
+= addr_size
;
13659 offset
+= 2 * addr_size
;
13661 /* An end of list marker is a pair of zero addresses. */
13662 if (range_beginning
== 0 && range_end
== 0)
13663 /* Found the end of list entry. */
13666 /* Each base address selection entry is a pair of 2 values.
13667 The first is the largest possible address, the second is
13668 the base address. Check for a base address here. */
13669 if ((range_beginning
& mask
) == mask
)
13671 /* If we found the largest possible address, then we already
13672 have the base address in range_end. */
13680 /* We have no valid base address for the ranges
13682 complaint (_("Invalid .debug_ranges data (no base address)"));
13686 if (range_beginning
> range_end
)
13688 /* Inverted range entries are invalid. */
13689 complaint (_("Invalid .debug_ranges data (inverted range)"));
13693 /* Empty range entries have no effect. */
13694 if (range_beginning
== range_end
)
13697 range_beginning
+= base
;
13700 /* A not-uncommon case of bad debug info.
13701 Don't pollute the addrmap with bad data. */
13702 if (range_beginning
+ baseaddr
== 0
13703 && !dwarf2_per_objfile
->has_section_at_zero
)
13705 complaint (_(".debug_ranges entry has start address of zero"
13706 " [in module %s]"), objfile_name (objfile
));
13710 callback (range_beginning
, range_end
);
13716 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
13717 Return 1 if the attributes are present and valid, otherwise, return 0.
13718 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
13721 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
13722 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
13723 dwarf2_psymtab
*ranges_pst
)
13725 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13726 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13727 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
13730 CORE_ADDR high
= 0;
13733 retval
= dwarf2_ranges_process (offset
, cu
,
13734 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
13736 if (ranges_pst
!= NULL
)
13741 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13742 range_beginning
+ baseaddr
)
13744 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13745 range_end
+ baseaddr
)
13747 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
13748 lowpc
, highpc
- 1, ranges_pst
);
13751 /* FIXME: This is recording everything as a low-high
13752 segment of consecutive addresses. We should have a
13753 data structure for discontiguous block ranges
13757 low
= range_beginning
;
13763 if (range_beginning
< low
)
13764 low
= range_beginning
;
13765 if (range_end
> high
)
13773 /* If the first entry is an end-of-list marker, the range
13774 describes an empty scope, i.e. no instructions. */
13780 *high_return
= high
;
13784 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
13785 definition for the return value. *LOWPC and *HIGHPC are set iff
13786 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
13788 static enum pc_bounds_kind
13789 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
13790 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
13791 dwarf2_psymtab
*pst
)
13793 struct dwarf2_per_objfile
*dwarf2_per_objfile
13794 = cu
->per_cu
->dwarf2_per_objfile
;
13795 struct attribute
*attr
;
13796 struct attribute
*attr_high
;
13798 CORE_ADDR high
= 0;
13799 enum pc_bounds_kind ret
;
13801 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
13804 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13805 if (attr
!= nullptr)
13807 low
= attr
->value_as_address ();
13808 high
= attr_high
->value_as_address ();
13809 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
13813 /* Found high w/o low attribute. */
13814 return PC_BOUNDS_INVALID
;
13816 /* Found consecutive range of addresses. */
13817 ret
= PC_BOUNDS_HIGH_LOW
;
13821 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
13824 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
13825 We take advantage of the fact that DW_AT_ranges does not appear
13826 in DW_TAG_compile_unit of DWO files. */
13827 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
13828 unsigned int ranges_offset
= (DW_UNSND (attr
)
13829 + (need_ranges_base
13833 /* Value of the DW_AT_ranges attribute is the offset in the
13834 .debug_ranges section. */
13835 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
13836 return PC_BOUNDS_INVALID
;
13837 /* Found discontinuous range of addresses. */
13838 ret
= PC_BOUNDS_RANGES
;
13841 return PC_BOUNDS_NOT_PRESENT
;
13844 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
13846 return PC_BOUNDS_INVALID
;
13848 /* When using the GNU linker, .gnu.linkonce. sections are used to
13849 eliminate duplicate copies of functions and vtables and such.
13850 The linker will arbitrarily choose one and discard the others.
13851 The AT_*_pc values for such functions refer to local labels in
13852 these sections. If the section from that file was discarded, the
13853 labels are not in the output, so the relocs get a value of 0.
13854 If this is a discarded function, mark the pc bounds as invalid,
13855 so that GDB will ignore it. */
13856 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
13857 return PC_BOUNDS_INVALID
;
13865 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
13866 its low and high PC addresses. Do nothing if these addresses could not
13867 be determined. Otherwise, set LOWPC to the low address if it is smaller,
13868 and HIGHPC to the high address if greater than HIGHPC. */
13871 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
13872 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
13873 struct dwarf2_cu
*cu
)
13875 CORE_ADDR low
, high
;
13876 struct die_info
*child
= die
->child
;
13878 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
13880 *lowpc
= std::min (*lowpc
, low
);
13881 *highpc
= std::max (*highpc
, high
);
13884 /* If the language does not allow nested subprograms (either inside
13885 subprograms or lexical blocks), we're done. */
13886 if (cu
->language
!= language_ada
)
13889 /* Check all the children of the given DIE. If it contains nested
13890 subprograms, then check their pc bounds. Likewise, we need to
13891 check lexical blocks as well, as they may also contain subprogram
13893 while (child
&& child
->tag
)
13895 if (child
->tag
== DW_TAG_subprogram
13896 || child
->tag
== DW_TAG_lexical_block
)
13897 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
13898 child
= sibling_die (child
);
13902 /* Get the low and high pc's represented by the scope DIE, and store
13903 them in *LOWPC and *HIGHPC. If the correct values can't be
13904 determined, set *LOWPC to -1 and *HIGHPC to 0. */
13907 get_scope_pc_bounds (struct die_info
*die
,
13908 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
13909 struct dwarf2_cu
*cu
)
13911 CORE_ADDR best_low
= (CORE_ADDR
) -1;
13912 CORE_ADDR best_high
= (CORE_ADDR
) 0;
13913 CORE_ADDR current_low
, current_high
;
13915 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
13916 >= PC_BOUNDS_RANGES
)
13918 best_low
= current_low
;
13919 best_high
= current_high
;
13923 struct die_info
*child
= die
->child
;
13925 while (child
&& child
->tag
)
13927 switch (child
->tag
) {
13928 case DW_TAG_subprogram
:
13929 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
13931 case DW_TAG_namespace
:
13932 case DW_TAG_module
:
13933 /* FIXME: carlton/2004-01-16: Should we do this for
13934 DW_TAG_class_type/DW_TAG_structure_type, too? I think
13935 that current GCC's always emit the DIEs corresponding
13936 to definitions of methods of classes as children of a
13937 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
13938 the DIEs giving the declarations, which could be
13939 anywhere). But I don't see any reason why the
13940 standards says that they have to be there. */
13941 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
13943 if (current_low
!= ((CORE_ADDR
) -1))
13945 best_low
= std::min (best_low
, current_low
);
13946 best_high
= std::max (best_high
, current_high
);
13954 child
= sibling_die (child
);
13959 *highpc
= best_high
;
13962 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
13966 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
13967 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
13969 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13970 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13971 struct attribute
*attr
;
13972 struct attribute
*attr_high
;
13974 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
13977 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13978 if (attr
!= nullptr)
13980 CORE_ADDR low
= attr
->value_as_address ();
13981 CORE_ADDR high
= attr_high
->value_as_address ();
13983 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
13986 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
13987 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
13988 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
13992 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
13993 if (attr
!= nullptr)
13995 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
13996 We take advantage of the fact that DW_AT_ranges does not appear
13997 in DW_TAG_compile_unit of DWO files. */
13998 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14000 /* The value of the DW_AT_ranges attribute is the offset of the
14001 address range list in the .debug_ranges section. */
14002 unsigned long offset
= (DW_UNSND (attr
)
14003 + (need_ranges_base
? cu
->ranges_base
: 0));
14005 std::vector
<blockrange
> blockvec
;
14006 dwarf2_ranges_process (offset
, cu
,
14007 [&] (CORE_ADDR start
, CORE_ADDR end
)
14011 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14012 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14013 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14014 blockvec
.emplace_back (start
, end
);
14017 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14021 /* Check whether the producer field indicates either of GCC < 4.6, or the
14022 Intel C/C++ compiler, and cache the result in CU. */
14025 check_producer (struct dwarf2_cu
*cu
)
14029 if (cu
->producer
== NULL
)
14031 /* For unknown compilers expect their behavior is DWARF version
14034 GCC started to support .debug_types sections by -gdwarf-4 since
14035 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14036 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14037 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14038 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14040 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14042 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14043 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14045 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14047 cu
->producer_is_icc
= true;
14048 cu
->producer_is_icc_lt_14
= major
< 14;
14050 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14051 cu
->producer_is_codewarrior
= true;
14054 /* For other non-GCC compilers, expect their behavior is DWARF version
14058 cu
->checked_producer
= true;
14061 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14062 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14063 during 4.6.0 experimental. */
14066 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14068 if (!cu
->checked_producer
)
14069 check_producer (cu
);
14071 return cu
->producer_is_gxx_lt_4_6
;
14075 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14076 with incorrect is_stmt attributes. */
14079 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14081 if (!cu
->checked_producer
)
14082 check_producer (cu
);
14084 return cu
->producer_is_codewarrior
;
14087 /* Return the default accessibility type if it is not overridden by
14088 DW_AT_accessibility. */
14090 static enum dwarf_access_attribute
14091 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14093 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14095 /* The default DWARF 2 accessibility for members is public, the default
14096 accessibility for inheritance is private. */
14098 if (die
->tag
!= DW_TAG_inheritance
)
14099 return DW_ACCESS_public
;
14101 return DW_ACCESS_private
;
14105 /* DWARF 3+ defines the default accessibility a different way. The same
14106 rules apply now for DW_TAG_inheritance as for the members and it only
14107 depends on the container kind. */
14109 if (die
->parent
->tag
== DW_TAG_class_type
)
14110 return DW_ACCESS_private
;
14112 return DW_ACCESS_public
;
14116 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14117 offset. If the attribute was not found return 0, otherwise return
14118 1. If it was found but could not properly be handled, set *OFFSET
14122 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14125 struct attribute
*attr
;
14127 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14132 /* Note that we do not check for a section offset first here.
14133 This is because DW_AT_data_member_location is new in DWARF 4,
14134 so if we see it, we can assume that a constant form is really
14135 a constant and not a section offset. */
14136 if (attr
->form_is_constant ())
14137 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
14138 else if (attr
->form_is_section_offset ())
14139 dwarf2_complex_location_expr_complaint ();
14140 else if (attr
->form_is_block ())
14141 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14143 dwarf2_complex_location_expr_complaint ();
14151 /* Add an aggregate field to the field list. */
14154 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14155 struct dwarf2_cu
*cu
)
14157 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14158 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14159 struct nextfield
*new_field
;
14160 struct attribute
*attr
;
14162 const char *fieldname
= "";
14164 if (die
->tag
== DW_TAG_inheritance
)
14166 fip
->baseclasses
.emplace_back ();
14167 new_field
= &fip
->baseclasses
.back ();
14171 fip
->fields
.emplace_back ();
14172 new_field
= &fip
->fields
.back ();
14177 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14178 if (attr
!= nullptr)
14179 new_field
->accessibility
= DW_UNSND (attr
);
14181 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
14182 if (new_field
->accessibility
!= DW_ACCESS_public
)
14183 fip
->non_public_fields
= 1;
14185 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14186 if (attr
!= nullptr)
14187 new_field
->virtuality
= DW_UNSND (attr
);
14189 new_field
->virtuality
= DW_VIRTUALITY_none
;
14191 fp
= &new_field
->field
;
14193 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14197 /* Data member other than a C++ static data member. */
14199 /* Get type of field. */
14200 fp
->type
= die_type (die
, cu
);
14202 SET_FIELD_BITPOS (*fp
, 0);
14204 /* Get bit size of field (zero if none). */
14205 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14206 if (attr
!= nullptr)
14208 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
14212 FIELD_BITSIZE (*fp
) = 0;
14215 /* Get bit offset of field. */
14216 if (handle_data_member_location (die
, cu
, &offset
))
14217 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
14218 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14219 if (attr
!= nullptr)
14221 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14223 /* For big endian bits, the DW_AT_bit_offset gives the
14224 additional bit offset from the MSB of the containing
14225 anonymous object to the MSB of the field. We don't
14226 have to do anything special since we don't need to
14227 know the size of the anonymous object. */
14228 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
14232 /* For little endian bits, compute the bit offset to the
14233 MSB of the anonymous object, subtract off the number of
14234 bits from the MSB of the field to the MSB of the
14235 object, and then subtract off the number of bits of
14236 the field itself. The result is the bit offset of
14237 the LSB of the field. */
14238 int anonymous_size
;
14239 int bit_offset
= DW_UNSND (attr
);
14241 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14242 if (attr
!= nullptr)
14244 /* The size of the anonymous object containing
14245 the bit field is explicit, so use the
14246 indicated size (in bytes). */
14247 anonymous_size
= DW_UNSND (attr
);
14251 /* The size of the anonymous object containing
14252 the bit field must be inferred from the type
14253 attribute of the data member containing the
14255 anonymous_size
= TYPE_LENGTH (fp
->type
);
14257 SET_FIELD_BITPOS (*fp
,
14258 (FIELD_BITPOS (*fp
)
14259 + anonymous_size
* bits_per_byte
14260 - bit_offset
- FIELD_BITSIZE (*fp
)));
14263 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14265 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14266 + dwarf2_get_attr_constant_value (attr
, 0)));
14268 /* Get name of field. */
14269 fieldname
= dwarf2_name (die
, cu
);
14270 if (fieldname
== NULL
)
14273 /* The name is already allocated along with this objfile, so we don't
14274 need to duplicate it for the type. */
14275 fp
->name
= fieldname
;
14277 /* Change accessibility for artificial fields (e.g. virtual table
14278 pointer or virtual base class pointer) to private. */
14279 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
14281 FIELD_ARTIFICIAL (*fp
) = 1;
14282 new_field
->accessibility
= DW_ACCESS_private
;
14283 fip
->non_public_fields
= 1;
14286 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
14288 /* C++ static member. */
14290 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
14291 is a declaration, but all versions of G++ as of this writing
14292 (so through at least 3.2.1) incorrectly generate
14293 DW_TAG_variable tags. */
14295 const char *physname
;
14297 /* Get name of field. */
14298 fieldname
= dwarf2_name (die
, cu
);
14299 if (fieldname
== NULL
)
14302 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14304 /* Only create a symbol if this is an external value.
14305 new_symbol checks this and puts the value in the global symbol
14306 table, which we want. If it is not external, new_symbol
14307 will try to put the value in cu->list_in_scope which is wrong. */
14308 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
14310 /* A static const member, not much different than an enum as far as
14311 we're concerned, except that we can support more types. */
14312 new_symbol (die
, NULL
, cu
);
14315 /* Get physical name. */
14316 physname
= dwarf2_physname (fieldname
, die
, cu
);
14318 /* The name is already allocated along with this objfile, so we don't
14319 need to duplicate it for the type. */
14320 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
14321 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14322 FIELD_NAME (*fp
) = fieldname
;
14324 else if (die
->tag
== DW_TAG_inheritance
)
14328 /* C++ base class field. */
14329 if (handle_data_member_location (die
, cu
, &offset
))
14330 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
14331 FIELD_BITSIZE (*fp
) = 0;
14332 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14333 FIELD_NAME (*fp
) = TYPE_NAME (fp
->type
);
14335 else if (die
->tag
== DW_TAG_variant_part
)
14337 /* process_structure_scope will treat this DIE as a union. */
14338 process_structure_scope (die
, cu
);
14340 /* The variant part is relative to the start of the enclosing
14342 SET_FIELD_BITPOS (*fp
, 0);
14343 fp
->type
= get_die_type (die
, cu
);
14344 fp
->artificial
= 1;
14345 fp
->name
= "<<variant>>";
14347 /* Normally a DW_TAG_variant_part won't have a size, but our
14348 representation requires one, so set it to the maximum of the
14349 child sizes, being sure to account for the offset at which
14350 each child is seen. */
14351 if (TYPE_LENGTH (fp
->type
) == 0)
14354 for (int i
= 0; i
< TYPE_NFIELDS (fp
->type
); ++i
)
14356 unsigned len
= ((TYPE_FIELD_BITPOS (fp
->type
, i
) + 7) / 8
14357 + TYPE_LENGTH (TYPE_FIELD_TYPE (fp
->type
, i
)));
14361 TYPE_LENGTH (fp
->type
) = max
;
14365 gdb_assert_not_reached ("missing case in dwarf2_add_field");
14368 /* Can the type given by DIE define another type? */
14371 type_can_define_types (const struct die_info
*die
)
14375 case DW_TAG_typedef
:
14376 case DW_TAG_class_type
:
14377 case DW_TAG_structure_type
:
14378 case DW_TAG_union_type
:
14379 case DW_TAG_enumeration_type
:
14387 /* Add a type definition defined in the scope of the FIP's class. */
14390 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
14391 struct dwarf2_cu
*cu
)
14393 struct decl_field fp
;
14394 memset (&fp
, 0, sizeof (fp
));
14396 gdb_assert (type_can_define_types (die
));
14398 /* Get name of field. NULL is okay here, meaning an anonymous type. */
14399 fp
.name
= dwarf2_name (die
, cu
);
14400 fp
.type
= read_type_die (die
, cu
);
14402 /* Save accessibility. */
14403 enum dwarf_access_attribute accessibility
;
14404 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14406 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14408 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14409 switch (accessibility
)
14411 case DW_ACCESS_public
:
14412 /* The assumed value if neither private nor protected. */
14414 case DW_ACCESS_private
:
14417 case DW_ACCESS_protected
:
14418 fp
.is_protected
= 1;
14421 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
14424 if (die
->tag
== DW_TAG_typedef
)
14425 fip
->typedef_field_list
.push_back (fp
);
14427 fip
->nested_types_list
.push_back (fp
);
14430 /* Create the vector of fields, and attach it to the type. */
14433 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
14434 struct dwarf2_cu
*cu
)
14436 int nfields
= fip
->nfields
;
14438 /* Record the field count, allocate space for the array of fields,
14439 and create blank accessibility bitfields if necessary. */
14440 TYPE_NFIELDS (type
) = nfields
;
14441 TYPE_FIELDS (type
) = (struct field
*)
14442 TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
);
14444 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
14446 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14448 TYPE_FIELD_PRIVATE_BITS (type
) =
14449 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14450 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
14452 TYPE_FIELD_PROTECTED_BITS (type
) =
14453 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14454 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
14456 TYPE_FIELD_IGNORE_BITS (type
) =
14457 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14458 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
14461 /* If the type has baseclasses, allocate and clear a bit vector for
14462 TYPE_FIELD_VIRTUAL_BITS. */
14463 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
14465 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
14466 unsigned char *pointer
;
14468 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14469 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
14470 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
14471 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
14472 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
14475 if (TYPE_FLAG_DISCRIMINATED_UNION (type
))
14477 struct discriminant_info
*di
= alloc_discriminant_info (type
, -1, -1);
14479 for (int index
= 0; index
< nfields
; ++index
)
14481 struct nextfield
&field
= fip
->fields
[index
];
14483 if (field
.variant
.is_discriminant
)
14484 di
->discriminant_index
= index
;
14485 else if (field
.variant
.default_branch
)
14486 di
->default_index
= index
;
14488 di
->discriminants
[index
] = field
.variant
.discriminant_value
;
14492 /* Copy the saved-up fields into the field vector. */
14493 for (int i
= 0; i
< nfields
; ++i
)
14495 struct nextfield
&field
14496 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
14497 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
14499 TYPE_FIELD (type
, i
) = field
.field
;
14500 switch (field
.accessibility
)
14502 case DW_ACCESS_private
:
14503 if (cu
->language
!= language_ada
)
14504 SET_TYPE_FIELD_PRIVATE (type
, i
);
14507 case DW_ACCESS_protected
:
14508 if (cu
->language
!= language_ada
)
14509 SET_TYPE_FIELD_PROTECTED (type
, i
);
14512 case DW_ACCESS_public
:
14516 /* Unknown accessibility. Complain and treat it as public. */
14518 complaint (_("unsupported accessibility %d"),
14519 field
.accessibility
);
14523 if (i
< fip
->baseclasses
.size ())
14525 switch (field
.virtuality
)
14527 case DW_VIRTUALITY_virtual
:
14528 case DW_VIRTUALITY_pure_virtual
:
14529 if (cu
->language
== language_ada
)
14530 error (_("unexpected virtuality in component of Ada type"));
14531 SET_TYPE_FIELD_VIRTUAL (type
, i
);
14538 /* Return true if this member function is a constructor, false
14542 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
14544 const char *fieldname
;
14545 const char *type_name
;
14548 if (die
->parent
== NULL
)
14551 if (die
->parent
->tag
!= DW_TAG_structure_type
14552 && die
->parent
->tag
!= DW_TAG_union_type
14553 && die
->parent
->tag
!= DW_TAG_class_type
)
14556 fieldname
= dwarf2_name (die
, cu
);
14557 type_name
= dwarf2_name (die
->parent
, cu
);
14558 if (fieldname
== NULL
|| type_name
== NULL
)
14561 len
= strlen (fieldname
);
14562 return (strncmp (fieldname
, type_name
, len
) == 0
14563 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
14566 /* Check if the given VALUE is a recognized enum
14567 dwarf_defaulted_attribute constant according to DWARF5 spec,
14571 is_valid_DW_AT_defaulted (ULONGEST value
)
14575 case DW_DEFAULTED_no
:
14576 case DW_DEFAULTED_in_class
:
14577 case DW_DEFAULTED_out_of_class
:
14581 complaint (_("unrecognized DW_AT_defaulted value (%s)"), pulongest (value
));
14585 /* Add a member function to the proper fieldlist. */
14588 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
14589 struct type
*type
, struct dwarf2_cu
*cu
)
14591 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14592 struct attribute
*attr
;
14594 struct fnfieldlist
*flp
= nullptr;
14595 struct fn_field
*fnp
;
14596 const char *fieldname
;
14597 struct type
*this_type
;
14598 enum dwarf_access_attribute accessibility
;
14600 if (cu
->language
== language_ada
)
14601 error (_("unexpected member function in Ada type"));
14603 /* Get name of member function. */
14604 fieldname
= dwarf2_name (die
, cu
);
14605 if (fieldname
== NULL
)
14608 /* Look up member function name in fieldlist. */
14609 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
14611 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
14613 flp
= &fip
->fnfieldlists
[i
];
14618 /* Create a new fnfieldlist if necessary. */
14619 if (flp
== nullptr)
14621 fip
->fnfieldlists
.emplace_back ();
14622 flp
= &fip
->fnfieldlists
.back ();
14623 flp
->name
= fieldname
;
14624 i
= fip
->fnfieldlists
.size () - 1;
14627 /* Create a new member function field and add it to the vector of
14629 flp
->fnfields
.emplace_back ();
14630 fnp
= &flp
->fnfields
.back ();
14632 /* Delay processing of the physname until later. */
14633 if (cu
->language
== language_cplus
)
14634 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
14638 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
14639 fnp
->physname
= physname
? physname
: "";
14642 fnp
->type
= alloc_type (objfile
);
14643 this_type
= read_type_die (die
, cu
);
14644 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
14646 int nparams
= TYPE_NFIELDS (this_type
);
14648 /* TYPE is the domain of this method, and THIS_TYPE is the type
14649 of the method itself (TYPE_CODE_METHOD). */
14650 smash_to_method_type (fnp
->type
, type
,
14651 TYPE_TARGET_TYPE (this_type
),
14652 TYPE_FIELDS (this_type
),
14653 TYPE_NFIELDS (this_type
),
14654 TYPE_VARARGS (this_type
));
14656 /* Handle static member functions.
14657 Dwarf2 has no clean way to discern C++ static and non-static
14658 member functions. G++ helps GDB by marking the first
14659 parameter for non-static member functions (which is the this
14660 pointer) as artificial. We obtain this information from
14661 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
14662 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
14663 fnp
->voffset
= VOFFSET_STATIC
;
14666 complaint (_("member function type missing for '%s'"),
14667 dwarf2_full_name (fieldname
, die
, cu
));
14669 /* Get fcontext from DW_AT_containing_type if present. */
14670 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
14671 fnp
->fcontext
= die_containing_type (die
, cu
);
14673 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
14674 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
14676 /* Get accessibility. */
14677 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14678 if (attr
!= nullptr)
14679 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14681 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14682 switch (accessibility
)
14684 case DW_ACCESS_private
:
14685 fnp
->is_private
= 1;
14687 case DW_ACCESS_protected
:
14688 fnp
->is_protected
= 1;
14692 /* Check for artificial methods. */
14693 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
14694 if (attr
&& DW_UNSND (attr
) != 0)
14695 fnp
->is_artificial
= 1;
14697 /* Check for defaulted methods. */
14698 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
14699 if (attr
!= nullptr && is_valid_DW_AT_defaulted (DW_UNSND (attr
)))
14700 fnp
->defaulted
= (enum dwarf_defaulted_attribute
) DW_UNSND (attr
);
14702 /* Check for deleted methods. */
14703 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
14704 if (attr
!= nullptr && DW_UNSND (attr
) != 0)
14705 fnp
->is_deleted
= 1;
14707 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
14709 /* Get index in virtual function table if it is a virtual member
14710 function. For older versions of GCC, this is an offset in the
14711 appropriate virtual table, as specified by DW_AT_containing_type.
14712 For everyone else, it is an expression to be evaluated relative
14713 to the object address. */
14715 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
14716 if (attr
!= nullptr)
14718 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
> 0)
14720 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
14722 /* Old-style GCC. */
14723 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
14725 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
14726 || (DW_BLOCK (attr
)->size
> 1
14727 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
14728 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
14730 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14731 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
14732 dwarf2_complex_location_expr_complaint ();
14734 fnp
->voffset
/= cu
->header
.addr_size
;
14738 dwarf2_complex_location_expr_complaint ();
14740 if (!fnp
->fcontext
)
14742 /* If there is no `this' field and no DW_AT_containing_type,
14743 we cannot actually find a base class context for the
14745 if (TYPE_NFIELDS (this_type
) == 0
14746 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
14748 complaint (_("cannot determine context for virtual member "
14749 "function \"%s\" (offset %s)"),
14750 fieldname
, sect_offset_str (die
->sect_off
));
14755 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
14759 else if (attr
->form_is_section_offset ())
14761 dwarf2_complex_location_expr_complaint ();
14765 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
14771 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14772 if (attr
&& DW_UNSND (attr
))
14774 /* GCC does this, as of 2008-08-25; PR debug/37237. */
14775 complaint (_("Member function \"%s\" (offset %s) is virtual "
14776 "but the vtable offset is not specified"),
14777 fieldname
, sect_offset_str (die
->sect_off
));
14778 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14779 TYPE_CPLUS_DYNAMIC (type
) = 1;
14784 /* Create the vector of member function fields, and attach it to the type. */
14787 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
14788 struct dwarf2_cu
*cu
)
14790 if (cu
->language
== language_ada
)
14791 error (_("unexpected member functions in Ada type"));
14793 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14794 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
14796 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
14798 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
14800 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
14801 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
14803 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
14804 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
14805 fn_flp
->fn_fields
= (struct fn_field
*)
14806 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
14808 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
14809 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
14812 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
14815 /* Returns non-zero if NAME is the name of a vtable member in CU's
14816 language, zero otherwise. */
14818 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
14820 static const char vptr
[] = "_vptr";
14822 /* Look for the C++ form of the vtable. */
14823 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
14829 /* GCC outputs unnamed structures that are really pointers to member
14830 functions, with the ABI-specified layout. If TYPE describes
14831 such a structure, smash it into a member function type.
14833 GCC shouldn't do this; it should just output pointer to member DIEs.
14834 This is GCC PR debug/28767. */
14837 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
14839 struct type
*pfn_type
, *self_type
, *new_type
;
14841 /* Check for a structure with no name and two children. */
14842 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
14845 /* Check for __pfn and __delta members. */
14846 if (TYPE_FIELD_NAME (type
, 0) == NULL
14847 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
14848 || TYPE_FIELD_NAME (type
, 1) == NULL
14849 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
14852 /* Find the type of the method. */
14853 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
14854 if (pfn_type
== NULL
14855 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
14856 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
14859 /* Look for the "this" argument. */
14860 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
14861 if (TYPE_NFIELDS (pfn_type
) == 0
14862 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
14863 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
14866 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
14867 new_type
= alloc_type (objfile
);
14868 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
14869 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
14870 TYPE_VARARGS (pfn_type
));
14871 smash_to_methodptr_type (type
, new_type
);
14874 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
14875 appropriate error checking and issuing complaints if there is a
14879 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
14881 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
14883 if (attr
== nullptr)
14886 if (!attr
->form_is_constant ())
14888 complaint (_("DW_AT_alignment must have constant form"
14889 " - DIE at %s [in module %s]"),
14890 sect_offset_str (die
->sect_off
),
14891 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14896 if (attr
->form
== DW_FORM_sdata
)
14898 LONGEST val
= DW_SND (attr
);
14901 complaint (_("DW_AT_alignment value must not be negative"
14902 " - DIE at %s [in module %s]"),
14903 sect_offset_str (die
->sect_off
),
14904 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14910 align
= DW_UNSND (attr
);
14914 complaint (_("DW_AT_alignment value must not be zero"
14915 " - DIE at %s [in module %s]"),
14916 sect_offset_str (die
->sect_off
),
14917 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14920 if ((align
& (align
- 1)) != 0)
14922 complaint (_("DW_AT_alignment value must be a power of 2"
14923 " - DIE at %s [in module %s]"),
14924 sect_offset_str (die
->sect_off
),
14925 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14932 /* If the DIE has a DW_AT_alignment attribute, use its value to set
14933 the alignment for TYPE. */
14936 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
14939 if (!set_type_align (type
, get_alignment (cu
, die
)))
14940 complaint (_("DW_AT_alignment value too large"
14941 " - DIE at %s [in module %s]"),
14942 sect_offset_str (die
->sect_off
),
14943 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14946 /* Check if the given VALUE is a valid enum dwarf_calling_convention
14947 constant for a type, according to DWARF5 spec, Table 5.5. */
14950 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
14955 case DW_CC_pass_by_reference
:
14956 case DW_CC_pass_by_value
:
14960 complaint (_("unrecognized DW_AT_calling_convention value "
14961 "(%s) for a type"), pulongest (value
));
14966 /* Check if the given VALUE is a valid enum dwarf_calling_convention
14967 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
14968 also according to GNU-specific values (see include/dwarf2.h). */
14971 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
14976 case DW_CC_program
:
14980 case DW_CC_GNU_renesas_sh
:
14981 case DW_CC_GNU_borland_fastcall_i386
:
14982 case DW_CC_GDB_IBM_OpenCL
:
14986 complaint (_("unrecognized DW_AT_calling_convention value "
14987 "(%s) for a subroutine"), pulongest (value
));
14992 /* Called when we find the DIE that starts a structure or union scope
14993 (definition) to create a type for the structure or union. Fill in
14994 the type's name and general properties; the members will not be
14995 processed until process_structure_scope. A symbol table entry for
14996 the type will also not be done until process_structure_scope (assuming
14997 the type has a name).
14999 NOTE: we need to call these functions regardless of whether or not the
15000 DIE has a DW_AT_name attribute, since it might be an anonymous
15001 structure or union. This gets the type entered into our set of
15002 user defined types. */
15004 static struct type
*
15005 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15007 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15009 struct attribute
*attr
;
15012 /* If the definition of this type lives in .debug_types, read that type.
15013 Don't follow DW_AT_specification though, that will take us back up
15014 the chain and we want to go down. */
15015 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
15016 if (attr
!= nullptr)
15018 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15020 /* The type's CU may not be the same as CU.
15021 Ensure TYPE is recorded with CU in die_type_hash. */
15022 return set_die_type (die
, type
, cu
);
15025 type
= alloc_type (objfile
);
15026 INIT_CPLUS_SPECIFIC (type
);
15028 name
= dwarf2_name (die
, cu
);
15031 if (cu
->language
== language_cplus
15032 || cu
->language
== language_d
15033 || cu
->language
== language_rust
)
15035 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15037 /* dwarf2_full_name might have already finished building the DIE's
15038 type. If so, there is no need to continue. */
15039 if (get_die_type (die
, cu
) != NULL
)
15040 return get_die_type (die
, cu
);
15042 TYPE_NAME (type
) = full_name
;
15046 /* The name is already allocated along with this objfile, so
15047 we don't need to duplicate it for the type. */
15048 TYPE_NAME (type
) = name
;
15052 if (die
->tag
== DW_TAG_structure_type
)
15054 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15056 else if (die
->tag
== DW_TAG_union_type
)
15058 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15060 else if (die
->tag
== DW_TAG_variant_part
)
15062 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15063 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
15067 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15070 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15071 TYPE_DECLARED_CLASS (type
) = 1;
15073 /* Store the calling convention in the type if it's available in
15074 the die. Otherwise the calling convention remains set to
15075 the default value DW_CC_normal. */
15076 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15077 if (attr
!= nullptr
15078 && is_valid_DW_AT_calling_convention_for_type (DW_UNSND (attr
)))
15080 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15081 TYPE_CPLUS_CALLING_CONVENTION (type
)
15082 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
15085 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15086 if (attr
!= nullptr)
15088 if (attr
->form_is_constant ())
15089 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15092 /* For the moment, dynamic type sizes are not supported
15093 by GDB's struct type. The actual size is determined
15094 on-demand when resolving the type of a given object,
15095 so set the type's length to zero for now. Otherwise,
15096 we record an expression as the length, and that expression
15097 could lead to a very large value, which could eventually
15098 lead to us trying to allocate that much memory when creating
15099 a value of that type. */
15100 TYPE_LENGTH (type
) = 0;
15105 TYPE_LENGTH (type
) = 0;
15108 maybe_set_alignment (cu
, die
, type
);
15110 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15112 /* ICC<14 does not output the required DW_AT_declaration on
15113 incomplete types, but gives them a size of zero. */
15114 TYPE_STUB (type
) = 1;
15117 TYPE_STUB_SUPPORTED (type
) = 1;
15119 if (die_is_declaration (die
, cu
))
15120 TYPE_STUB (type
) = 1;
15121 else if (attr
== NULL
&& die
->child
== NULL
15122 && producer_is_realview (cu
->producer
))
15123 /* RealView does not output the required DW_AT_declaration
15124 on incomplete types. */
15125 TYPE_STUB (type
) = 1;
15127 /* We need to add the type field to the die immediately so we don't
15128 infinitely recurse when dealing with pointers to the structure
15129 type within the structure itself. */
15130 set_die_type (die
, type
, cu
);
15132 /* set_die_type should be already done. */
15133 set_descriptive_type (type
, die
, cu
);
15138 /* A helper for process_structure_scope that handles a single member
15142 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15143 struct field_info
*fi
,
15144 std::vector
<struct symbol
*> *template_args
,
15145 struct dwarf2_cu
*cu
)
15147 if (child_die
->tag
== DW_TAG_member
15148 || child_die
->tag
== DW_TAG_variable
15149 || child_die
->tag
== DW_TAG_variant_part
)
15151 /* NOTE: carlton/2002-11-05: A C++ static data member
15152 should be a DW_TAG_member that is a declaration, but
15153 all versions of G++ as of this writing (so through at
15154 least 3.2.1) incorrectly generate DW_TAG_variable
15155 tags for them instead. */
15156 dwarf2_add_field (fi
, child_die
, cu
);
15158 else if (child_die
->tag
== DW_TAG_subprogram
)
15160 /* Rust doesn't have member functions in the C++ sense.
15161 However, it does emit ordinary functions as children
15162 of a struct DIE. */
15163 if (cu
->language
== language_rust
)
15164 read_func_scope (child_die
, cu
);
15167 /* C++ member function. */
15168 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15171 else if (child_die
->tag
== DW_TAG_inheritance
)
15173 /* C++ base class field. */
15174 dwarf2_add_field (fi
, child_die
, cu
);
15176 else if (type_can_define_types (child_die
))
15177 dwarf2_add_type_defn (fi
, child_die
, cu
);
15178 else if (child_die
->tag
== DW_TAG_template_type_param
15179 || child_die
->tag
== DW_TAG_template_value_param
)
15181 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15184 template_args
->push_back (arg
);
15186 else if (child_die
->tag
== DW_TAG_variant
)
15188 /* In a variant we want to get the discriminant and also add a
15189 field for our sole member child. */
15190 struct attribute
*discr
= dwarf2_attr (child_die
, DW_AT_discr_value
, cu
);
15192 for (die_info
*variant_child
= child_die
->child
;
15193 variant_child
!= NULL
;
15194 variant_child
= sibling_die (variant_child
))
15196 if (variant_child
->tag
== DW_TAG_member
)
15198 handle_struct_member_die (variant_child
, type
, fi
,
15199 template_args
, cu
);
15200 /* Only handle the one. */
15205 /* We don't handle this but we might as well report it if we see
15207 if (dwarf2_attr (child_die
, DW_AT_discr_list
, cu
) != nullptr)
15208 complaint (_("DW_AT_discr_list is not supported yet"
15209 " - DIE at %s [in module %s]"),
15210 sect_offset_str (child_die
->sect_off
),
15211 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15213 /* The first field was just added, so we can stash the
15214 discriminant there. */
15215 gdb_assert (!fi
->fields
.empty ());
15217 fi
->fields
.back ().variant
.default_branch
= true;
15219 fi
->fields
.back ().variant
.discriminant_value
= DW_UNSND (discr
);
15223 /* Finish creating a structure or union type, including filling in
15224 its members and creating a symbol for it. */
15227 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15229 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15230 struct die_info
*child_die
;
15233 type
= get_die_type (die
, cu
);
15235 type
= read_structure_type (die
, cu
);
15237 /* When reading a DW_TAG_variant_part, we need to notice when we
15238 read the discriminant member, so we can record it later in the
15239 discriminant_info. */
15240 bool is_variant_part
= TYPE_FLAG_DISCRIMINATED_UNION (type
);
15241 sect_offset discr_offset
{};
15242 bool has_template_parameters
= false;
15244 if (is_variant_part
)
15246 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15249 /* Maybe it's a univariant form, an extension we support.
15250 In this case arrange not to check the offset. */
15251 is_variant_part
= false;
15253 else if (discr
->form_is_ref ())
15255 struct dwarf2_cu
*target_cu
= cu
;
15256 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15258 discr_offset
= target_die
->sect_off
;
15262 complaint (_("DW_AT_discr does not have DIE reference form"
15263 " - DIE at %s [in module %s]"),
15264 sect_offset_str (die
->sect_off
),
15265 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15266 is_variant_part
= false;
15270 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15272 struct field_info fi
;
15273 std::vector
<struct symbol
*> template_args
;
15275 child_die
= die
->child
;
15277 while (child_die
&& child_die
->tag
)
15279 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15281 if (is_variant_part
&& discr_offset
== child_die
->sect_off
)
15282 fi
.fields
.back ().variant
.is_discriminant
= true;
15284 child_die
= sibling_die (child_die
);
15287 /* Attach template arguments to type. */
15288 if (!template_args
.empty ())
15290 has_template_parameters
= true;
15291 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15292 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15293 TYPE_TEMPLATE_ARGUMENTS (type
)
15294 = XOBNEWVEC (&objfile
->objfile_obstack
,
15296 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15297 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15298 template_args
.data (),
15299 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15300 * sizeof (struct symbol
*)));
15303 /* Attach fields and member functions to the type. */
15305 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15306 if (!fi
.fnfieldlists
.empty ())
15308 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15310 /* Get the type which refers to the base class (possibly this
15311 class itself) which contains the vtable pointer for the current
15312 class from the DW_AT_containing_type attribute. This use of
15313 DW_AT_containing_type is a GNU extension. */
15315 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15317 struct type
*t
= die_containing_type (die
, cu
);
15319 set_type_vptr_basetype (type
, t
);
15324 /* Our own class provides vtbl ptr. */
15325 for (i
= TYPE_NFIELDS (t
) - 1;
15326 i
>= TYPE_N_BASECLASSES (t
);
15329 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
15331 if (is_vtable_name (fieldname
, cu
))
15333 set_type_vptr_fieldno (type
, i
);
15338 /* Complain if virtual function table field not found. */
15339 if (i
< TYPE_N_BASECLASSES (t
))
15340 complaint (_("virtual function table pointer "
15341 "not found when defining class '%s'"),
15342 TYPE_NAME (type
) ? TYPE_NAME (type
) : "");
15346 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
15349 else if (cu
->producer
15350 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
15352 /* The IBM XLC compiler does not provide direct indication
15353 of the containing type, but the vtable pointer is
15354 always named __vfp. */
15358 for (i
= TYPE_NFIELDS (type
) - 1;
15359 i
>= TYPE_N_BASECLASSES (type
);
15362 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
15364 set_type_vptr_fieldno (type
, i
);
15365 set_type_vptr_basetype (type
, type
);
15372 /* Copy fi.typedef_field_list linked list elements content into the
15373 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
15374 if (!fi
.typedef_field_list
.empty ())
15376 int count
= fi
.typedef_field_list
.size ();
15378 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15379 TYPE_TYPEDEF_FIELD_ARRAY (type
)
15380 = ((struct decl_field
*)
15382 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
15383 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
15385 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
15386 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
15389 /* Copy fi.nested_types_list linked list elements content into the
15390 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
15391 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
15393 int count
= fi
.nested_types_list
.size ();
15395 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15396 TYPE_NESTED_TYPES_ARRAY (type
)
15397 = ((struct decl_field
*)
15398 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
15399 TYPE_NESTED_TYPES_COUNT (type
) = count
;
15401 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
15402 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
15406 quirk_gcc_member_function_pointer (type
, objfile
);
15407 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
15408 cu
->rust_unions
.push_back (type
);
15410 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
15411 snapshots) has been known to create a die giving a declaration
15412 for a class that has, as a child, a die giving a definition for a
15413 nested class. So we have to process our children even if the
15414 current die is a declaration. Normally, of course, a declaration
15415 won't have any children at all. */
15417 child_die
= die
->child
;
15419 while (child_die
!= NULL
&& child_die
->tag
)
15421 if (child_die
->tag
== DW_TAG_member
15422 || child_die
->tag
== DW_TAG_variable
15423 || child_die
->tag
== DW_TAG_inheritance
15424 || child_die
->tag
== DW_TAG_template_value_param
15425 || child_die
->tag
== DW_TAG_template_type_param
)
15430 process_die (child_die
, cu
);
15432 child_die
= sibling_die (child_die
);
15435 /* Do not consider external references. According to the DWARF standard,
15436 these DIEs are identified by the fact that they have no byte_size
15437 attribute, and a declaration attribute. */
15438 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
15439 || !die_is_declaration (die
, cu
))
15441 struct symbol
*sym
= new_symbol (die
, type
, cu
);
15443 if (has_template_parameters
)
15445 struct symtab
*symtab
;
15446 if (sym
!= nullptr)
15447 symtab
= symbol_symtab (sym
);
15448 else if (cu
->line_header
!= nullptr)
15450 /* Any related symtab will do. */
15452 = cu
->line_header
->file_names ()[0].symtab
;
15457 complaint (_("could not find suitable "
15458 "symtab for template parameter"
15459 " - DIE at %s [in module %s]"),
15460 sect_offset_str (die
->sect_off
),
15461 objfile_name (objfile
));
15464 if (symtab
!= nullptr)
15466 /* Make sure that the symtab is set on the new symbols.
15467 Even though they don't appear in this symtab directly,
15468 other parts of gdb assume that symbols do, and this is
15469 reasonably true. */
15470 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
15471 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
15477 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
15478 update TYPE using some information only available in DIE's children. */
15481 update_enumeration_type_from_children (struct die_info
*die
,
15483 struct dwarf2_cu
*cu
)
15485 struct die_info
*child_die
;
15486 int unsigned_enum
= 1;
15490 auto_obstack obstack
;
15492 for (child_die
= die
->child
;
15493 child_die
!= NULL
&& child_die
->tag
;
15494 child_die
= sibling_die (child_die
))
15496 struct attribute
*attr
;
15498 const gdb_byte
*bytes
;
15499 struct dwarf2_locexpr_baton
*baton
;
15502 if (child_die
->tag
!= DW_TAG_enumerator
)
15505 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
15509 name
= dwarf2_name (child_die
, cu
);
15511 name
= "<anonymous enumerator>";
15513 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
15514 &value
, &bytes
, &baton
);
15520 else if ((mask
& value
) != 0)
15525 /* If we already know that the enum type is neither unsigned, nor
15526 a flag type, no need to look at the rest of the enumerates. */
15527 if (!unsigned_enum
&& !flag_enum
)
15532 TYPE_UNSIGNED (type
) = 1;
15534 TYPE_FLAG_ENUM (type
) = 1;
15537 /* Given a DW_AT_enumeration_type die, set its type. We do not
15538 complete the type's fields yet, or create any symbols. */
15540 static struct type
*
15541 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15543 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15545 struct attribute
*attr
;
15548 /* If the definition of this type lives in .debug_types, read that type.
15549 Don't follow DW_AT_specification though, that will take us back up
15550 the chain and we want to go down. */
15551 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
15552 if (attr
!= nullptr)
15554 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15556 /* The type's CU may not be the same as CU.
15557 Ensure TYPE is recorded with CU in die_type_hash. */
15558 return set_die_type (die
, type
, cu
);
15561 type
= alloc_type (objfile
);
15563 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
15564 name
= dwarf2_full_name (NULL
, die
, cu
);
15566 TYPE_NAME (type
) = name
;
15568 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
15571 struct type
*underlying_type
= die_type (die
, cu
);
15573 TYPE_TARGET_TYPE (type
) = underlying_type
;
15576 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15577 if (attr
!= nullptr)
15579 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15583 TYPE_LENGTH (type
) = 0;
15586 maybe_set_alignment (cu
, die
, type
);
15588 /* The enumeration DIE can be incomplete. In Ada, any type can be
15589 declared as private in the package spec, and then defined only
15590 inside the package body. Such types are known as Taft Amendment
15591 Types. When another package uses such a type, an incomplete DIE
15592 may be generated by the compiler. */
15593 if (die_is_declaration (die
, cu
))
15594 TYPE_STUB (type
) = 1;
15596 /* Finish the creation of this type by using the enum's children.
15597 We must call this even when the underlying type has been provided
15598 so that we can determine if we're looking at a "flag" enum. */
15599 update_enumeration_type_from_children (die
, type
, cu
);
15601 /* If this type has an underlying type that is not a stub, then we
15602 may use its attributes. We always use the "unsigned" attribute
15603 in this situation, because ordinarily we guess whether the type
15604 is unsigned -- but the guess can be wrong and the underlying type
15605 can tell us the reality. However, we defer to a local size
15606 attribute if one exists, because this lets the compiler override
15607 the underlying type if needed. */
15608 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
15610 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
15611 if (TYPE_LENGTH (type
) == 0)
15612 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
15613 if (TYPE_RAW_ALIGN (type
) == 0
15614 && TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)) != 0)
15615 set_type_align (type
, TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)));
15618 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
15620 return set_die_type (die
, type
, cu
);
15623 /* Given a pointer to a die which begins an enumeration, process all
15624 the dies that define the members of the enumeration, and create the
15625 symbol for the enumeration type.
15627 NOTE: We reverse the order of the element list. */
15630 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15632 struct type
*this_type
;
15634 this_type
= get_die_type (die
, cu
);
15635 if (this_type
== NULL
)
15636 this_type
= read_enumeration_type (die
, cu
);
15638 if (die
->child
!= NULL
)
15640 struct die_info
*child_die
;
15641 struct symbol
*sym
;
15642 std::vector
<struct field
> fields
;
15645 child_die
= die
->child
;
15646 while (child_die
&& child_die
->tag
)
15648 if (child_die
->tag
!= DW_TAG_enumerator
)
15650 process_die (child_die
, cu
);
15654 name
= dwarf2_name (child_die
, cu
);
15657 sym
= new_symbol (child_die
, this_type
, cu
);
15659 fields
.emplace_back ();
15660 struct field
&field
= fields
.back ();
15662 FIELD_NAME (field
) = sym
->linkage_name ();
15663 FIELD_TYPE (field
) = NULL
;
15664 SET_FIELD_ENUMVAL (field
, SYMBOL_VALUE (sym
));
15665 FIELD_BITSIZE (field
) = 0;
15669 child_die
= sibling_die (child_die
);
15672 if (!fields
.empty ())
15674 TYPE_NFIELDS (this_type
) = fields
.size ();
15675 TYPE_FIELDS (this_type
) = (struct field
*)
15676 TYPE_ALLOC (this_type
, sizeof (struct field
) * fields
.size ());
15677 memcpy (TYPE_FIELDS (this_type
), fields
.data (),
15678 sizeof (struct field
) * fields
.size ());
15682 /* If we are reading an enum from a .debug_types unit, and the enum
15683 is a declaration, and the enum is not the signatured type in the
15684 unit, then we do not want to add a symbol for it. Adding a
15685 symbol would in some cases obscure the true definition of the
15686 enum, giving users an incomplete type when the definition is
15687 actually available. Note that we do not want to do this for all
15688 enums which are just declarations, because C++0x allows forward
15689 enum declarations. */
15690 if (cu
->per_cu
->is_debug_types
15691 && die_is_declaration (die
, cu
))
15693 struct signatured_type
*sig_type
;
15695 sig_type
= (struct signatured_type
*) cu
->per_cu
;
15696 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
15697 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
15701 new_symbol (die
, this_type
, cu
);
15704 /* Extract all information from a DW_TAG_array_type DIE and put it in
15705 the DIE's type field. For now, this only handles one dimensional
15708 static struct type
*
15709 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15711 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15712 struct die_info
*child_die
;
15714 struct type
*element_type
, *range_type
, *index_type
;
15715 struct attribute
*attr
;
15717 struct dynamic_prop
*byte_stride_prop
= NULL
;
15718 unsigned int bit_stride
= 0;
15720 element_type
= die_type (die
, cu
);
15722 /* The die_type call above may have already set the type for this DIE. */
15723 type
= get_die_type (die
, cu
);
15727 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
15731 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
15734 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
15735 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
15739 complaint (_("unable to read array DW_AT_byte_stride "
15740 " - DIE at %s [in module %s]"),
15741 sect_offset_str (die
->sect_off
),
15742 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15743 /* Ignore this attribute. We will likely not be able to print
15744 arrays of this type correctly, but there is little we can do
15745 to help if we cannot read the attribute's value. */
15746 byte_stride_prop
= NULL
;
15750 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
15752 bit_stride
= DW_UNSND (attr
);
15754 /* Irix 6.2 native cc creates array types without children for
15755 arrays with unspecified length. */
15756 if (die
->child
== NULL
)
15758 index_type
= objfile_type (objfile
)->builtin_int
;
15759 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
15760 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
15761 byte_stride_prop
, bit_stride
);
15762 return set_die_type (die
, type
, cu
);
15765 std::vector
<struct type
*> range_types
;
15766 child_die
= die
->child
;
15767 while (child_die
&& child_die
->tag
)
15769 if (child_die
->tag
== DW_TAG_subrange_type
)
15771 struct type
*child_type
= read_type_die (child_die
, cu
);
15773 if (child_type
!= NULL
)
15775 /* The range type was succesfully read. Save it for the
15776 array type creation. */
15777 range_types
.push_back (child_type
);
15780 child_die
= sibling_die (child_die
);
15783 /* Dwarf2 dimensions are output from left to right, create the
15784 necessary array types in backwards order. */
15786 type
= element_type
;
15788 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
15792 while (i
< range_types
.size ())
15793 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
15794 byte_stride_prop
, bit_stride
);
15798 size_t ndim
= range_types
.size ();
15800 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
15801 byte_stride_prop
, bit_stride
);
15804 /* Understand Dwarf2 support for vector types (like they occur on
15805 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
15806 array type. This is not part of the Dwarf2/3 standard yet, but a
15807 custom vendor extension. The main difference between a regular
15808 array and the vector variant is that vectors are passed by value
15810 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
15811 if (attr
!= nullptr)
15812 make_vector_type (type
);
15814 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
15815 implementation may choose to implement triple vectors using this
15817 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15818 if (attr
!= nullptr)
15820 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
15821 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15823 complaint (_("DW_AT_byte_size for array type smaller "
15824 "than the total size of elements"));
15827 name
= dwarf2_name (die
, cu
);
15829 TYPE_NAME (type
) = name
;
15831 maybe_set_alignment (cu
, die
, type
);
15833 /* Install the type in the die. */
15834 set_die_type (die
, type
, cu
);
15836 /* set_die_type should be already done. */
15837 set_descriptive_type (type
, die
, cu
);
15842 static enum dwarf_array_dim_ordering
15843 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
15845 struct attribute
*attr
;
15847 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
15849 if (attr
!= nullptr)
15850 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
15852 /* GNU F77 is a special case, as at 08/2004 array type info is the
15853 opposite order to the dwarf2 specification, but data is still
15854 laid out as per normal fortran.
15856 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
15857 version checking. */
15859 if (cu
->language
== language_fortran
15860 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
15862 return DW_ORD_row_major
;
15865 switch (cu
->language_defn
->la_array_ordering
)
15867 case array_column_major
:
15868 return DW_ORD_col_major
;
15869 case array_row_major
:
15871 return DW_ORD_row_major
;
15875 /* Extract all information from a DW_TAG_set_type DIE and put it in
15876 the DIE's type field. */
15878 static struct type
*
15879 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15881 struct type
*domain_type
, *set_type
;
15882 struct attribute
*attr
;
15884 domain_type
= die_type (die
, cu
);
15886 /* The die_type call above may have already set the type for this DIE. */
15887 set_type
= get_die_type (die
, cu
);
15891 set_type
= create_set_type (NULL
, domain_type
);
15893 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15894 if (attr
!= nullptr)
15895 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
15897 maybe_set_alignment (cu
, die
, set_type
);
15899 return set_die_type (die
, set_type
, cu
);
15902 /* A helper for read_common_block that creates a locexpr baton.
15903 SYM is the symbol which we are marking as computed.
15904 COMMON_DIE is the DIE for the common block.
15905 COMMON_LOC is the location expression attribute for the common
15907 MEMBER_LOC is the location expression attribute for the particular
15908 member of the common block that we are processing.
15909 CU is the CU from which the above come. */
15912 mark_common_block_symbol_computed (struct symbol
*sym
,
15913 struct die_info
*common_die
,
15914 struct attribute
*common_loc
,
15915 struct attribute
*member_loc
,
15916 struct dwarf2_cu
*cu
)
15918 struct dwarf2_per_objfile
*dwarf2_per_objfile
15919 = cu
->per_cu
->dwarf2_per_objfile
;
15920 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
15921 struct dwarf2_locexpr_baton
*baton
;
15923 unsigned int cu_off
;
15924 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
15925 LONGEST offset
= 0;
15927 gdb_assert (common_loc
&& member_loc
);
15928 gdb_assert (common_loc
->form_is_block ());
15929 gdb_assert (member_loc
->form_is_block ()
15930 || member_loc
->form_is_constant ());
15932 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
15933 baton
->per_cu
= cu
->per_cu
;
15934 gdb_assert (baton
->per_cu
);
15936 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
15938 if (member_loc
->form_is_constant ())
15940 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
15941 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
15944 baton
->size
+= DW_BLOCK (member_loc
)->size
;
15946 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
15949 *ptr
++ = DW_OP_call4
;
15950 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
15951 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
15954 if (member_loc
->form_is_constant ())
15956 *ptr
++ = DW_OP_addr
;
15957 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
15958 ptr
+= cu
->header
.addr_size
;
15962 /* We have to copy the data here, because DW_OP_call4 will only
15963 use a DW_AT_location attribute. */
15964 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
15965 ptr
+= DW_BLOCK (member_loc
)->size
;
15968 *ptr
++ = DW_OP_plus
;
15969 gdb_assert (ptr
- baton
->data
== baton
->size
);
15971 SYMBOL_LOCATION_BATON (sym
) = baton
;
15972 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
15975 /* Create appropriate locally-scoped variables for all the
15976 DW_TAG_common_block entries. Also create a struct common_block
15977 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
15978 is used to separate the common blocks name namespace from regular
15982 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
15984 struct attribute
*attr
;
15986 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
15987 if (attr
!= nullptr)
15989 /* Support the .debug_loc offsets. */
15990 if (attr
->form_is_block ())
15994 else if (attr
->form_is_section_offset ())
15996 dwarf2_complex_location_expr_complaint ();
16001 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16002 "common block member");
16007 if (die
->child
!= NULL
)
16009 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16010 struct die_info
*child_die
;
16011 size_t n_entries
= 0, size
;
16012 struct common_block
*common_block
;
16013 struct symbol
*sym
;
16015 for (child_die
= die
->child
;
16016 child_die
&& child_die
->tag
;
16017 child_die
= sibling_die (child_die
))
16020 size
= (sizeof (struct common_block
)
16021 + (n_entries
- 1) * sizeof (struct symbol
*));
16023 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16025 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16026 common_block
->n_entries
= 0;
16028 for (child_die
= die
->child
;
16029 child_die
&& child_die
->tag
;
16030 child_die
= sibling_die (child_die
))
16032 /* Create the symbol in the DW_TAG_common_block block in the current
16034 sym
= new_symbol (child_die
, NULL
, cu
);
16037 struct attribute
*member_loc
;
16039 common_block
->contents
[common_block
->n_entries
++] = sym
;
16041 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16045 /* GDB has handled this for a long time, but it is
16046 not specified by DWARF. It seems to have been
16047 emitted by gfortran at least as recently as:
16048 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16049 complaint (_("Variable in common block has "
16050 "DW_AT_data_member_location "
16051 "- DIE at %s [in module %s]"),
16052 sect_offset_str (child_die
->sect_off
),
16053 objfile_name (objfile
));
16055 if (member_loc
->form_is_section_offset ())
16056 dwarf2_complex_location_expr_complaint ();
16057 else if (member_loc
->form_is_constant ()
16058 || member_loc
->form_is_block ())
16060 if (attr
!= nullptr)
16061 mark_common_block_symbol_computed (sym
, die
, attr
,
16065 dwarf2_complex_location_expr_complaint ();
16070 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16071 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16075 /* Create a type for a C++ namespace. */
16077 static struct type
*
16078 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16080 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16081 const char *previous_prefix
, *name
;
16085 /* For extensions, reuse the type of the original namespace. */
16086 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16088 struct die_info
*ext_die
;
16089 struct dwarf2_cu
*ext_cu
= cu
;
16091 ext_die
= dwarf2_extension (die
, &ext_cu
);
16092 type
= read_type_die (ext_die
, ext_cu
);
16094 /* EXT_CU may not be the same as CU.
16095 Ensure TYPE is recorded with CU in die_type_hash. */
16096 return set_die_type (die
, type
, cu
);
16099 name
= namespace_name (die
, &is_anonymous
, cu
);
16101 /* Now build the name of the current namespace. */
16103 previous_prefix
= determine_prefix (die
, cu
);
16104 if (previous_prefix
[0] != '\0')
16105 name
= typename_concat (&objfile
->objfile_obstack
,
16106 previous_prefix
, name
, 0, cu
);
16108 /* Create the type. */
16109 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16111 return set_die_type (die
, type
, cu
);
16114 /* Read a namespace scope. */
16117 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16119 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16122 /* Add a symbol associated to this if we haven't seen the namespace
16123 before. Also, add a using directive if it's an anonymous
16126 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16130 type
= read_type_die (die
, cu
);
16131 new_symbol (die
, type
, cu
);
16133 namespace_name (die
, &is_anonymous
, cu
);
16136 const char *previous_prefix
= determine_prefix (die
, cu
);
16138 std::vector
<const char *> excludes
;
16139 add_using_directive (using_directives (cu
),
16140 previous_prefix
, TYPE_NAME (type
), NULL
,
16141 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16145 if (die
->child
!= NULL
)
16147 struct die_info
*child_die
= die
->child
;
16149 while (child_die
&& child_die
->tag
)
16151 process_die (child_die
, cu
);
16152 child_die
= sibling_die (child_die
);
16157 /* Read a Fortran module as type. This DIE can be only a declaration used for
16158 imported module. Still we need that type as local Fortran "use ... only"
16159 declaration imports depend on the created type in determine_prefix. */
16161 static struct type
*
16162 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16164 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16165 const char *module_name
;
16168 module_name
= dwarf2_name (die
, cu
);
16169 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16171 return set_die_type (die
, type
, cu
);
16174 /* Read a Fortran module. */
16177 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16179 struct die_info
*child_die
= die
->child
;
16182 type
= read_type_die (die
, cu
);
16183 new_symbol (die
, type
, cu
);
16185 while (child_die
&& child_die
->tag
)
16187 process_die (child_die
, cu
);
16188 child_die
= sibling_die (child_die
);
16192 /* Return the name of the namespace represented by DIE. Set
16193 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16196 static const char *
16197 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16199 struct die_info
*current_die
;
16200 const char *name
= NULL
;
16202 /* Loop through the extensions until we find a name. */
16204 for (current_die
= die
;
16205 current_die
!= NULL
;
16206 current_die
= dwarf2_extension (die
, &cu
))
16208 /* We don't use dwarf2_name here so that we can detect the absence
16209 of a name -> anonymous namespace. */
16210 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16216 /* Is it an anonymous namespace? */
16218 *is_anonymous
= (name
== NULL
);
16220 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16225 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16226 the user defined type vector. */
16228 static struct type
*
16229 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16231 struct gdbarch
*gdbarch
16232 = get_objfile_arch (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16233 struct comp_unit_head
*cu_header
= &cu
->header
;
16235 struct attribute
*attr_byte_size
;
16236 struct attribute
*attr_address_class
;
16237 int byte_size
, addr_class
;
16238 struct type
*target_type
;
16240 target_type
= die_type (die
, cu
);
16242 /* The die_type call above may have already set the type for this DIE. */
16243 type
= get_die_type (die
, cu
);
16247 type
= lookup_pointer_type (target_type
);
16249 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16250 if (attr_byte_size
)
16251 byte_size
= DW_UNSND (attr_byte_size
);
16253 byte_size
= cu_header
->addr_size
;
16255 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
16256 if (attr_address_class
)
16257 addr_class
= DW_UNSND (attr_address_class
);
16259 addr_class
= DW_ADDR_none
;
16261 ULONGEST alignment
= get_alignment (cu
, die
);
16263 /* If the pointer size, alignment, or address class is different
16264 than the default, create a type variant marked as such and set
16265 the length accordingly. */
16266 if (TYPE_LENGTH (type
) != byte_size
16267 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
16268 && alignment
!= TYPE_RAW_ALIGN (type
))
16269 || addr_class
!= DW_ADDR_none
)
16271 if (gdbarch_address_class_type_flags_p (gdbarch
))
16275 type_flags
= gdbarch_address_class_type_flags
16276 (gdbarch
, byte_size
, addr_class
);
16277 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
16279 type
= make_type_with_address_space (type
, type_flags
);
16281 else if (TYPE_LENGTH (type
) != byte_size
)
16283 complaint (_("invalid pointer size %d"), byte_size
);
16285 else if (TYPE_RAW_ALIGN (type
) != alignment
)
16287 complaint (_("Invalid DW_AT_alignment"
16288 " - DIE at %s [in module %s]"),
16289 sect_offset_str (die
->sect_off
),
16290 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16294 /* Should we also complain about unhandled address classes? */
16298 TYPE_LENGTH (type
) = byte_size
;
16299 set_type_align (type
, alignment
);
16300 return set_die_type (die
, type
, cu
);
16303 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
16304 the user defined type vector. */
16306 static struct type
*
16307 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16310 struct type
*to_type
;
16311 struct type
*domain
;
16313 to_type
= die_type (die
, cu
);
16314 domain
= die_containing_type (die
, cu
);
16316 /* The calls above may have already set the type for this DIE. */
16317 type
= get_die_type (die
, cu
);
16321 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
16322 type
= lookup_methodptr_type (to_type
);
16323 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
16325 struct type
*new_type
16326 = alloc_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16328 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
16329 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
16330 TYPE_VARARGS (to_type
));
16331 type
= lookup_methodptr_type (new_type
);
16334 type
= lookup_memberptr_type (to_type
, domain
);
16336 return set_die_type (die
, type
, cu
);
16339 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
16340 the user defined type vector. */
16342 static struct type
*
16343 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16344 enum type_code refcode
)
16346 struct comp_unit_head
*cu_header
= &cu
->header
;
16347 struct type
*type
, *target_type
;
16348 struct attribute
*attr
;
16350 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
16352 target_type
= die_type (die
, cu
);
16354 /* The die_type call above may have already set the type for this DIE. */
16355 type
= get_die_type (die
, cu
);
16359 type
= lookup_reference_type (target_type
, refcode
);
16360 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16361 if (attr
!= nullptr)
16363 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16367 TYPE_LENGTH (type
) = cu_header
->addr_size
;
16369 maybe_set_alignment (cu
, die
, type
);
16370 return set_die_type (die
, type
, cu
);
16373 /* Add the given cv-qualifiers to the element type of the array. GCC
16374 outputs DWARF type qualifiers that apply to an array, not the
16375 element type. But GDB relies on the array element type to carry
16376 the cv-qualifiers. This mimics section 6.7.3 of the C99
16379 static struct type
*
16380 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16381 struct type
*base_type
, int cnst
, int voltl
)
16383 struct type
*el_type
, *inner_array
;
16385 base_type
= copy_type (base_type
);
16386 inner_array
= base_type
;
16388 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
16390 TYPE_TARGET_TYPE (inner_array
) =
16391 copy_type (TYPE_TARGET_TYPE (inner_array
));
16392 inner_array
= TYPE_TARGET_TYPE (inner_array
);
16395 el_type
= TYPE_TARGET_TYPE (inner_array
);
16396 cnst
|= TYPE_CONST (el_type
);
16397 voltl
|= TYPE_VOLATILE (el_type
);
16398 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
16400 return set_die_type (die
, base_type
, cu
);
16403 static struct type
*
16404 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16406 struct type
*base_type
, *cv_type
;
16408 base_type
= die_type (die
, cu
);
16410 /* The die_type call above may have already set the type for this DIE. */
16411 cv_type
= get_die_type (die
, cu
);
16415 /* In case the const qualifier is applied to an array type, the element type
16416 is so qualified, not the array type (section 6.7.3 of C99). */
16417 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
16418 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
16420 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
16421 return set_die_type (die
, cv_type
, cu
);
16424 static struct type
*
16425 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16427 struct type
*base_type
, *cv_type
;
16429 base_type
= die_type (die
, cu
);
16431 /* The die_type call above may have already set the type for this DIE. */
16432 cv_type
= get_die_type (die
, cu
);
16436 /* In case the volatile qualifier is applied to an array type, the
16437 element type is so qualified, not the array type (section 6.7.3
16439 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
16440 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
16442 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
16443 return set_die_type (die
, cv_type
, cu
);
16446 /* Handle DW_TAG_restrict_type. */
16448 static struct type
*
16449 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16451 struct type
*base_type
, *cv_type
;
16453 base_type
= die_type (die
, cu
);
16455 /* The die_type call above may have already set the type for this DIE. */
16456 cv_type
= get_die_type (die
, cu
);
16460 cv_type
= make_restrict_type (base_type
);
16461 return set_die_type (die
, cv_type
, cu
);
16464 /* Handle DW_TAG_atomic_type. */
16466 static struct type
*
16467 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16469 struct type
*base_type
, *cv_type
;
16471 base_type
= die_type (die
, cu
);
16473 /* The die_type call above may have already set the type for this DIE. */
16474 cv_type
= get_die_type (die
, cu
);
16478 cv_type
= make_atomic_type (base_type
);
16479 return set_die_type (die
, cv_type
, cu
);
16482 /* Extract all information from a DW_TAG_string_type DIE and add to
16483 the user defined type vector. It isn't really a user defined type,
16484 but it behaves like one, with other DIE's using an AT_user_def_type
16485 attribute to reference it. */
16487 static struct type
*
16488 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16490 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16491 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16492 struct type
*type
, *range_type
, *index_type
, *char_type
;
16493 struct attribute
*attr
;
16494 struct dynamic_prop prop
;
16495 bool length_is_constant
= true;
16498 /* There are a couple of places where bit sizes might be made use of
16499 when parsing a DW_TAG_string_type, however, no producer that we know
16500 of make use of these. Handling bit sizes that are a multiple of the
16501 byte size is easy enough, but what about other bit sizes? Lets deal
16502 with that problem when we have to. Warn about these attributes being
16503 unsupported, then parse the type and ignore them like we always
16505 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
16506 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
16508 static bool warning_printed
= false;
16509 if (!warning_printed
)
16511 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
16512 "currently supported on DW_TAG_string_type."));
16513 warning_printed
= true;
16517 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
16518 if (attr
!= nullptr && !attr
->form_is_constant ())
16520 /* The string length describes the location at which the length of
16521 the string can be found. The size of the length field can be
16522 specified with one of the attributes below. */
16523 struct type
*prop_type
;
16524 struct attribute
*len
16525 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
16526 if (len
== nullptr)
16527 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16528 if (len
!= nullptr && len
->form_is_constant ())
16530 /* Pass 0 as the default as we know this attribute is constant
16531 and the default value will not be returned. */
16532 LONGEST sz
= dwarf2_get_attr_constant_value (len
, 0);
16533 prop_type
= cu
->per_cu
->int_type (sz
, true);
16537 /* If the size is not specified then we assume it is the size of
16538 an address on this target. */
16539 prop_type
= cu
->per_cu
->addr_sized_int_type (true);
16542 /* Convert the attribute into a dynamic property. */
16543 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
16546 length_is_constant
= false;
16548 else if (attr
!= nullptr)
16550 /* This DW_AT_string_length just contains the length with no
16551 indirection. There's no need to create a dynamic property in this
16552 case. Pass 0 for the default value as we know it will not be
16553 returned in this case. */
16554 length
= dwarf2_get_attr_constant_value (attr
, 0);
16556 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
16558 /* We don't currently support non-constant byte sizes for strings. */
16559 length
= dwarf2_get_attr_constant_value (attr
, 1);
16563 /* Use 1 as a fallback length if we have nothing else. */
16567 index_type
= objfile_type (objfile
)->builtin_int
;
16568 if (length_is_constant
)
16569 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
16572 struct dynamic_prop low_bound
;
16574 low_bound
.kind
= PROP_CONST
;
16575 low_bound
.data
.const_val
= 1;
16576 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
16578 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
16579 type
= create_string_type (NULL
, char_type
, range_type
);
16581 return set_die_type (die
, type
, cu
);
16584 /* Assuming that DIE corresponds to a function, returns nonzero
16585 if the function is prototyped. */
16588 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
16590 struct attribute
*attr
;
16592 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
16593 if (attr
&& (DW_UNSND (attr
) != 0))
16596 /* The DWARF standard implies that the DW_AT_prototyped attribute
16597 is only meaningful for C, but the concept also extends to other
16598 languages that allow unprototyped functions (Eg: Objective C).
16599 For all other languages, assume that functions are always
16601 if (cu
->language
!= language_c
16602 && cu
->language
!= language_objc
16603 && cu
->language
!= language_opencl
)
16606 /* RealView does not emit DW_AT_prototyped. We can not distinguish
16607 prototyped and unprototyped functions; default to prototyped,
16608 since that is more common in modern code (and RealView warns
16609 about unprototyped functions). */
16610 if (producer_is_realview (cu
->producer
))
16616 /* Handle DIES due to C code like:
16620 int (*funcp)(int a, long l);
16624 ('funcp' generates a DW_TAG_subroutine_type DIE). */
16626 static struct type
*
16627 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16629 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16630 struct type
*type
; /* Type that this function returns. */
16631 struct type
*ftype
; /* Function that returns above type. */
16632 struct attribute
*attr
;
16634 type
= die_type (die
, cu
);
16636 /* The die_type call above may have already set the type for this DIE. */
16637 ftype
= get_die_type (die
, cu
);
16641 ftype
= lookup_function_type (type
);
16643 if (prototyped_function_p (die
, cu
))
16644 TYPE_PROTOTYPED (ftype
) = 1;
16646 /* Store the calling convention in the type if it's available in
16647 the subroutine die. Otherwise set the calling convention to
16648 the default value DW_CC_normal. */
16649 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
16650 if (attr
!= nullptr
16651 && is_valid_DW_AT_calling_convention_for_subroutine (DW_UNSND (attr
)))
16652 TYPE_CALLING_CONVENTION (ftype
)
16653 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
16654 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
16655 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
16657 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
16659 /* Record whether the function returns normally to its caller or not
16660 if the DWARF producer set that information. */
16661 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
16662 if (attr
&& (DW_UNSND (attr
) != 0))
16663 TYPE_NO_RETURN (ftype
) = 1;
16665 /* We need to add the subroutine type to the die immediately so
16666 we don't infinitely recurse when dealing with parameters
16667 declared as the same subroutine type. */
16668 set_die_type (die
, ftype
, cu
);
16670 if (die
->child
!= NULL
)
16672 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
16673 struct die_info
*child_die
;
16674 int nparams
, iparams
;
16676 /* Count the number of parameters.
16677 FIXME: GDB currently ignores vararg functions, but knows about
16678 vararg member functions. */
16680 child_die
= die
->child
;
16681 while (child_die
&& child_die
->tag
)
16683 if (child_die
->tag
== DW_TAG_formal_parameter
)
16685 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
16686 TYPE_VARARGS (ftype
) = 1;
16687 child_die
= sibling_die (child_die
);
16690 /* Allocate storage for parameters and fill them in. */
16691 TYPE_NFIELDS (ftype
) = nparams
;
16692 TYPE_FIELDS (ftype
) = (struct field
*)
16693 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
16695 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
16696 even if we error out during the parameters reading below. */
16697 for (iparams
= 0; iparams
< nparams
; iparams
++)
16698 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
16701 child_die
= die
->child
;
16702 while (child_die
&& child_die
->tag
)
16704 if (child_die
->tag
== DW_TAG_formal_parameter
)
16706 struct type
*arg_type
;
16708 /* DWARF version 2 has no clean way to discern C++
16709 static and non-static member functions. G++ helps
16710 GDB by marking the first parameter for non-static
16711 member functions (which is the this pointer) as
16712 artificial. We pass this information to
16713 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
16715 DWARF version 3 added DW_AT_object_pointer, which GCC
16716 4.5 does not yet generate. */
16717 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
16718 if (attr
!= nullptr)
16719 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
16721 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
16722 arg_type
= die_type (child_die
, cu
);
16724 /* RealView does not mark THIS as const, which the testsuite
16725 expects. GCC marks THIS as const in method definitions,
16726 but not in the class specifications (GCC PR 43053). */
16727 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
16728 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
16731 struct dwarf2_cu
*arg_cu
= cu
;
16732 const char *name
= dwarf2_name (child_die
, cu
);
16734 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
16735 if (attr
!= nullptr)
16737 /* If the compiler emits this, use it. */
16738 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
16741 else if (name
&& strcmp (name
, "this") == 0)
16742 /* Function definitions will have the argument names. */
16744 else if (name
== NULL
&& iparams
== 0)
16745 /* Declarations may not have the names, so like
16746 elsewhere in GDB, assume an artificial first
16747 argument is "this". */
16751 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
16755 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
16758 child_die
= sibling_die (child_die
);
16765 static struct type
*
16766 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
16768 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16769 const char *name
= NULL
;
16770 struct type
*this_type
, *target_type
;
16772 name
= dwarf2_full_name (NULL
, die
, cu
);
16773 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
16774 TYPE_TARGET_STUB (this_type
) = 1;
16775 set_die_type (die
, this_type
, cu
);
16776 target_type
= die_type (die
, cu
);
16777 if (target_type
!= this_type
)
16778 TYPE_TARGET_TYPE (this_type
) = target_type
;
16781 /* Self-referential typedefs are, it seems, not allowed by the DWARF
16782 spec and cause infinite loops in GDB. */
16783 complaint (_("Self-referential DW_TAG_typedef "
16784 "- DIE at %s [in module %s]"),
16785 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
16786 TYPE_TARGET_TYPE (this_type
) = NULL
;
16791 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
16792 (which may be different from NAME) to the architecture back-end to allow
16793 it to guess the correct format if necessary. */
16795 static struct type
*
16796 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
16797 const char *name_hint
, enum bfd_endian byte_order
)
16799 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16800 const struct floatformat
**format
;
16803 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
16805 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
16807 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
16812 /* Allocate an integer type of size BITS and name NAME. */
16814 static struct type
*
16815 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
16816 int bits
, int unsigned_p
, const char *name
)
16820 /* Versions of Intel's C Compiler generate an integer type called "void"
16821 instead of using DW_TAG_unspecified_type. This has been seen on
16822 at least versions 14, 17, and 18. */
16823 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
16824 && strcmp (name
, "void") == 0)
16825 type
= objfile_type (objfile
)->builtin_void
;
16827 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
16832 /* Initialise and return a floating point type of size BITS suitable for
16833 use as a component of a complex number. The NAME_HINT is passed through
16834 when initialising the floating point type and is the name of the complex
16837 As DWARF doesn't currently provide an explicit name for the components
16838 of a complex number, but it can be helpful to have these components
16839 named, we try to select a suitable name based on the size of the
16841 static struct type
*
16842 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
16843 struct objfile
*objfile
,
16844 int bits
, const char *name_hint
,
16845 enum bfd_endian byte_order
)
16847 gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16848 struct type
*tt
= nullptr;
16850 /* Try to find a suitable floating point builtin type of size BITS.
16851 We're going to use the name of this type as the name for the complex
16852 target type that we are about to create. */
16853 switch (cu
->language
)
16855 case language_fortran
:
16859 tt
= builtin_f_type (gdbarch
)->builtin_real
;
16862 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
16864 case 96: /* The x86-32 ABI specifies 96-bit long double. */
16866 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
16874 tt
= builtin_type (gdbarch
)->builtin_float
;
16877 tt
= builtin_type (gdbarch
)->builtin_double
;
16879 case 96: /* The x86-32 ABI specifies 96-bit long double. */
16881 tt
= builtin_type (gdbarch
)->builtin_long_double
;
16887 /* If the type we found doesn't match the size we were looking for, then
16888 pretend we didn't find a type at all, the complex target type we
16889 create will then be nameless. */
16890 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
16893 const char *name
= (tt
== nullptr) ? nullptr : TYPE_NAME (tt
);
16894 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
16897 /* Find a representation of a given base type and install
16898 it in the TYPE field of the die. */
16900 static struct type
*
16901 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16903 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16905 struct attribute
*attr
;
16906 int encoding
= 0, bits
= 0;
16910 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
16911 if (attr
!= nullptr)
16912 encoding
= DW_UNSND (attr
);
16913 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16914 if (attr
!= nullptr)
16915 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
16916 name
= dwarf2_name (die
, cu
);
16918 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
16920 arch
= get_objfile_arch (objfile
);
16921 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
16923 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
16926 int endianity
= DW_UNSND (attr
);
16931 byte_order
= BFD_ENDIAN_BIG
;
16933 case DW_END_little
:
16934 byte_order
= BFD_ENDIAN_LITTLE
;
16937 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
16944 case DW_ATE_address
:
16945 /* Turn DW_ATE_address into a void * pointer. */
16946 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
16947 type
= init_pointer_type (objfile
, bits
, name
, type
);
16949 case DW_ATE_boolean
:
16950 type
= init_boolean_type (objfile
, bits
, 1, name
);
16952 case DW_ATE_complex_float
:
16953 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
16955 type
= init_complex_type (objfile
, name
, type
);
16957 case DW_ATE_decimal_float
:
16958 type
= init_decfloat_type (objfile
, bits
, name
);
16961 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
16963 case DW_ATE_signed
:
16964 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
16966 case DW_ATE_unsigned
:
16967 if (cu
->language
== language_fortran
16969 && startswith (name
, "character("))
16970 type
= init_character_type (objfile
, bits
, 1, name
);
16972 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
16974 case DW_ATE_signed_char
:
16975 if (cu
->language
== language_ada
|| cu
->language
== language_m2
16976 || cu
->language
== language_pascal
16977 || cu
->language
== language_fortran
)
16978 type
= init_character_type (objfile
, bits
, 0, name
);
16980 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
16982 case DW_ATE_unsigned_char
:
16983 if (cu
->language
== language_ada
|| cu
->language
== language_m2
16984 || cu
->language
== language_pascal
16985 || cu
->language
== language_fortran
16986 || cu
->language
== language_rust
)
16987 type
= init_character_type (objfile
, bits
, 1, name
);
16989 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
16994 type
= builtin_type (arch
)->builtin_char16
;
16995 else if (bits
== 32)
16996 type
= builtin_type (arch
)->builtin_char32
;
16999 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
17001 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17003 return set_die_type (die
, type
, cu
);
17008 complaint (_("unsupported DW_AT_encoding: '%s'"),
17009 dwarf_type_encoding_name (encoding
));
17010 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17014 if (name
&& strcmp (name
, "char") == 0)
17015 TYPE_NOSIGN (type
) = 1;
17017 maybe_set_alignment (cu
, die
, type
);
17019 TYPE_ENDIANITY_NOT_DEFAULT (type
) = gdbarch_byte_order (arch
) != byte_order
;
17021 return set_die_type (die
, type
, cu
);
17024 /* Parse dwarf attribute if it's a block, reference or constant and put the
17025 resulting value of the attribute into struct bound_prop.
17026 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17029 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17030 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
17031 struct type
*default_type
)
17033 struct dwarf2_property_baton
*baton
;
17034 struct obstack
*obstack
17035 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
17037 gdb_assert (default_type
!= NULL
);
17039 if (attr
== NULL
|| prop
== NULL
)
17042 if (attr
->form_is_block ())
17044 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17045 baton
->property_type
= default_type
;
17046 baton
->locexpr
.per_cu
= cu
->per_cu
;
17047 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17048 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17049 switch (attr
->name
)
17051 case DW_AT_string_length
:
17052 baton
->locexpr
.is_reference
= true;
17055 baton
->locexpr
.is_reference
= false;
17058 prop
->data
.baton
= baton
;
17059 prop
->kind
= PROP_LOCEXPR
;
17060 gdb_assert (prop
->data
.baton
!= NULL
);
17062 else if (attr
->form_is_ref ())
17064 struct dwarf2_cu
*target_cu
= cu
;
17065 struct die_info
*target_die
;
17066 struct attribute
*target_attr
;
17068 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17069 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17070 if (target_attr
== NULL
)
17071 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17073 if (target_attr
== NULL
)
17076 switch (target_attr
->name
)
17078 case DW_AT_location
:
17079 if (target_attr
->form_is_section_offset ())
17081 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17082 baton
->property_type
= die_type (target_die
, target_cu
);
17083 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17084 prop
->data
.baton
= baton
;
17085 prop
->kind
= PROP_LOCLIST
;
17086 gdb_assert (prop
->data
.baton
!= NULL
);
17088 else if (target_attr
->form_is_block ())
17090 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17091 baton
->property_type
= die_type (target_die
, target_cu
);
17092 baton
->locexpr
.per_cu
= cu
->per_cu
;
17093 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17094 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17095 baton
->locexpr
.is_reference
= true;
17096 prop
->data
.baton
= baton
;
17097 prop
->kind
= PROP_LOCEXPR
;
17098 gdb_assert (prop
->data
.baton
!= NULL
);
17102 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17103 "dynamic property");
17107 case DW_AT_data_member_location
:
17111 if (!handle_data_member_location (target_die
, target_cu
,
17115 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17116 baton
->property_type
= read_type_die (target_die
->parent
,
17118 baton
->offset_info
.offset
= offset
;
17119 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17120 prop
->data
.baton
= baton
;
17121 prop
->kind
= PROP_ADDR_OFFSET
;
17126 else if (attr
->form_is_constant ())
17128 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
17129 prop
->kind
= PROP_CONST
;
17133 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17134 dwarf2_name (die
, cu
));
17144 dwarf2_per_cu_data::int_type (int size_in_bytes
, bool unsigned_p
) const
17146 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17147 struct type
*int_type
;
17149 /* Helper macro to examine the various builtin types. */
17150 #define TRY_TYPE(F) \
17151 int_type = (unsigned_p \
17152 ? objfile_type (objfile)->builtin_unsigned_ ## F \
17153 : objfile_type (objfile)->builtin_ ## F); \
17154 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
17161 TRY_TYPE (long_long
);
17165 gdb_assert_not_reached ("unable to find suitable integer type");
17171 dwarf2_per_cu_data::addr_sized_int_type (bool unsigned_p
) const
17173 int addr_size
= this->addr_size ();
17174 return int_type (addr_size
, unsigned_p
);
17177 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
17178 present (which is valid) then compute the default type based on the
17179 compilation units address size. */
17181 static struct type
*
17182 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17184 struct type
*index_type
= die_type (die
, cu
);
17186 /* Dwarf-2 specifications explicitly allows to create subrange types
17187 without specifying a base type.
17188 In that case, the base type must be set to the type of
17189 the lower bound, upper bound or count, in that order, if any of these
17190 three attributes references an object that has a type.
17191 If no base type is found, the Dwarf-2 specifications say that
17192 a signed integer type of size equal to the size of an address should
17194 For the following C code: `extern char gdb_int [];'
17195 GCC produces an empty range DIE.
17196 FIXME: muller/2010-05-28: Possible references to object for low bound,
17197 high bound or count are not yet handled by this code. */
17198 if (TYPE_CODE (index_type
) == TYPE_CODE_VOID
)
17199 index_type
= cu
->per_cu
->addr_sized_int_type (false);
17204 /* Read the given DW_AT_subrange DIE. */
17206 static struct type
*
17207 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17209 struct type
*base_type
, *orig_base_type
;
17210 struct type
*range_type
;
17211 struct attribute
*attr
;
17212 struct dynamic_prop low
, high
;
17213 int low_default_is_valid
;
17214 int high_bound_is_count
= 0;
17216 ULONGEST negative_mask
;
17218 orig_base_type
= read_subrange_index_type (die
, cu
);
17220 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17221 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17222 creating the range type, but we use the result of check_typedef
17223 when examining properties of the type. */
17224 base_type
= check_typedef (orig_base_type
);
17226 /* The die_type call above may have already set the type for this DIE. */
17227 range_type
= get_die_type (die
, cu
);
17231 low
.kind
= PROP_CONST
;
17232 high
.kind
= PROP_CONST
;
17233 high
.data
.const_val
= 0;
17235 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17236 omitting DW_AT_lower_bound. */
17237 switch (cu
->language
)
17240 case language_cplus
:
17241 low
.data
.const_val
= 0;
17242 low_default_is_valid
= 1;
17244 case language_fortran
:
17245 low
.data
.const_val
= 1;
17246 low_default_is_valid
= 1;
17249 case language_objc
:
17250 case language_rust
:
17251 low
.data
.const_val
= 0;
17252 low_default_is_valid
= (cu
->header
.version
>= 4);
17256 case language_pascal
:
17257 low
.data
.const_val
= 1;
17258 low_default_is_valid
= (cu
->header
.version
>= 4);
17261 low
.data
.const_val
= 0;
17262 low_default_is_valid
= 0;
17266 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
17267 if (attr
!= nullptr)
17268 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
17269 else if (!low_default_is_valid
)
17270 complaint (_("Missing DW_AT_lower_bound "
17271 "- DIE at %s [in module %s]"),
17272 sect_offset_str (die
->sect_off
),
17273 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17275 struct attribute
*attr_ub
, *attr_count
;
17276 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
17277 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17279 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
17280 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17282 /* If bounds are constant do the final calculation here. */
17283 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
17284 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
17286 high_bound_is_count
= 1;
17290 if (attr_ub
!= NULL
)
17291 complaint (_("Unresolved DW_AT_upper_bound "
17292 "- DIE at %s [in module %s]"),
17293 sect_offset_str (die
->sect_off
),
17294 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17295 if (attr_count
!= NULL
)
17296 complaint (_("Unresolved DW_AT_count "
17297 "- DIE at %s [in module %s]"),
17298 sect_offset_str (die
->sect_off
),
17299 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17304 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
17305 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
17306 bias
= dwarf2_get_attr_constant_value (bias_attr
, 0);
17308 /* Normally, the DWARF producers are expected to use a signed
17309 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17310 But this is unfortunately not always the case, as witnessed
17311 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17312 is used instead. To work around that ambiguity, we treat
17313 the bounds as signed, and thus sign-extend their values, when
17314 the base type is signed. */
17316 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
17317 if (low
.kind
== PROP_CONST
17318 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
17319 low
.data
.const_val
|= negative_mask
;
17320 if (high
.kind
== PROP_CONST
17321 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
17322 high
.data
.const_val
|= negative_mask
;
17324 /* Check for bit and byte strides. */
17325 struct dynamic_prop byte_stride_prop
;
17326 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
17327 if (attr_byte_stride
!= nullptr)
17329 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
17330 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
17334 struct dynamic_prop bit_stride_prop
;
17335 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
17336 if (attr_bit_stride
!= nullptr)
17338 /* It only makes sense to have either a bit or byte stride. */
17339 if (attr_byte_stride
!= nullptr)
17341 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
17342 "- DIE at %s [in module %s]"),
17343 sect_offset_str (die
->sect_off
),
17344 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17345 attr_bit_stride
= nullptr;
17349 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
17350 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
17355 if (attr_byte_stride
!= nullptr
17356 || attr_bit_stride
!= nullptr)
17358 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
17359 struct dynamic_prop
*stride
17360 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
17363 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
17364 &high
, bias
, stride
, byte_stride_p
);
17367 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
17369 if (high_bound_is_count
)
17370 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
17372 /* Ada expects an empty array on no boundary attributes. */
17373 if (attr
== NULL
&& cu
->language
!= language_ada
)
17374 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
17376 name
= dwarf2_name (die
, cu
);
17378 TYPE_NAME (range_type
) = name
;
17380 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17381 if (attr
!= nullptr)
17382 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
17384 maybe_set_alignment (cu
, die
, range_type
);
17386 set_die_type (die
, range_type
, cu
);
17388 /* set_die_type should be already done. */
17389 set_descriptive_type (range_type
, die
, cu
);
17394 static struct type
*
17395 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17399 type
= init_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
, TYPE_CODE_VOID
,0,
17401 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
17403 /* In Ada, an unspecified type is typically used when the description
17404 of the type is deferred to a different unit. When encountering
17405 such a type, we treat it as a stub, and try to resolve it later on,
17407 if (cu
->language
== language_ada
)
17408 TYPE_STUB (type
) = 1;
17410 return set_die_type (die
, type
, cu
);
17413 /* Read a single die and all its descendents. Set the die's sibling
17414 field to NULL; set other fields in the die correctly, and set all
17415 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
17416 location of the info_ptr after reading all of those dies. PARENT
17417 is the parent of the die in question. */
17419 static struct die_info
*
17420 read_die_and_children (const struct die_reader_specs
*reader
,
17421 const gdb_byte
*info_ptr
,
17422 const gdb_byte
**new_info_ptr
,
17423 struct die_info
*parent
)
17425 struct die_info
*die
;
17426 const gdb_byte
*cur_ptr
;
17428 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
17431 *new_info_ptr
= cur_ptr
;
17434 store_in_ref_table (die
, reader
->cu
);
17436 if (die
->has_children
)
17437 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
17441 *new_info_ptr
= cur_ptr
;
17444 die
->sibling
= NULL
;
17445 die
->parent
= parent
;
17449 /* Read a die, all of its descendents, and all of its siblings; set
17450 all of the fields of all of the dies correctly. Arguments are as
17451 in read_die_and_children. */
17453 static struct die_info
*
17454 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
17455 const gdb_byte
*info_ptr
,
17456 const gdb_byte
**new_info_ptr
,
17457 struct die_info
*parent
)
17459 struct die_info
*first_die
, *last_sibling
;
17460 const gdb_byte
*cur_ptr
;
17462 cur_ptr
= info_ptr
;
17463 first_die
= last_sibling
= NULL
;
17467 struct die_info
*die
17468 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
17472 *new_info_ptr
= cur_ptr
;
17479 last_sibling
->sibling
= die
;
17481 last_sibling
= die
;
17485 /* Read a die, all of its descendents, and all of its siblings; set
17486 all of the fields of all of the dies correctly. Arguments are as
17487 in read_die_and_children.
17488 This the main entry point for reading a DIE and all its children. */
17490 static struct die_info
*
17491 read_die_and_siblings (const struct die_reader_specs
*reader
,
17492 const gdb_byte
*info_ptr
,
17493 const gdb_byte
**new_info_ptr
,
17494 struct die_info
*parent
)
17496 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
17497 new_info_ptr
, parent
);
17499 if (dwarf_die_debug
)
17501 fprintf_unfiltered (gdb_stdlog
,
17502 "Read die from %s@0x%x of %s:\n",
17503 reader
->die_section
->get_name (),
17504 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17505 bfd_get_filename (reader
->abfd
));
17506 dump_die (die
, dwarf_die_debug
);
17512 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
17514 The caller is responsible for filling in the extra attributes
17515 and updating (*DIEP)->num_attrs.
17516 Set DIEP to point to a newly allocated die with its information,
17517 except for its child, sibling, and parent fields. */
17519 static const gdb_byte
*
17520 read_full_die_1 (const struct die_reader_specs
*reader
,
17521 struct die_info
**diep
, const gdb_byte
*info_ptr
,
17522 int num_extra_attrs
)
17524 unsigned int abbrev_number
, bytes_read
, i
;
17525 struct abbrev_info
*abbrev
;
17526 struct die_info
*die
;
17527 struct dwarf2_cu
*cu
= reader
->cu
;
17528 bfd
*abfd
= reader
->abfd
;
17530 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
17531 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
17532 info_ptr
+= bytes_read
;
17533 if (!abbrev_number
)
17539 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
17541 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
17543 bfd_get_filename (abfd
));
17545 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
17546 die
->sect_off
= sect_off
;
17547 die
->tag
= abbrev
->tag
;
17548 die
->abbrev
= abbrev_number
;
17549 die
->has_children
= abbrev
->has_children
;
17551 /* Make the result usable.
17552 The caller needs to update num_attrs after adding the extra
17554 die
->num_attrs
= abbrev
->num_attrs
;
17556 std::vector
<int> indexes_that_need_reprocess
;
17557 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
17559 bool need_reprocess
;
17561 read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
17562 info_ptr
, &need_reprocess
);
17563 if (need_reprocess
)
17564 indexes_that_need_reprocess
.push_back (i
);
17567 struct attribute
*attr
= dwarf2_attr_no_follow (die
, DW_AT_str_offsets_base
);
17568 if (attr
!= nullptr)
17569 cu
->str_offsets_base
= DW_UNSND (attr
);
17571 auto maybe_addr_base
= lookup_addr_base(die
);
17572 if (maybe_addr_base
.has_value ())
17573 cu
->addr_base
= *maybe_addr_base
;
17574 for (int index
: indexes_that_need_reprocess
)
17575 read_attribute_reprocess (reader
, &die
->attrs
[index
]);
17580 /* Read a die and all its attributes.
17581 Set DIEP to point to a newly allocated die with its information,
17582 except for its child, sibling, and parent fields. */
17584 static const gdb_byte
*
17585 read_full_die (const struct die_reader_specs
*reader
,
17586 struct die_info
**diep
, const gdb_byte
*info_ptr
)
17588 const gdb_byte
*result
;
17590 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
17592 if (dwarf_die_debug
)
17594 fprintf_unfiltered (gdb_stdlog
,
17595 "Read die from %s@0x%x of %s:\n",
17596 reader
->die_section
->get_name (),
17597 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17598 bfd_get_filename (reader
->abfd
));
17599 dump_die (*diep
, dwarf_die_debug
);
17606 /* Returns nonzero if TAG represents a type that we might generate a partial
17610 is_type_tag_for_partial (int tag
)
17615 /* Some types that would be reasonable to generate partial symbols for,
17616 that we don't at present. */
17617 case DW_TAG_array_type
:
17618 case DW_TAG_file_type
:
17619 case DW_TAG_ptr_to_member_type
:
17620 case DW_TAG_set_type
:
17621 case DW_TAG_string_type
:
17622 case DW_TAG_subroutine_type
:
17624 case DW_TAG_base_type
:
17625 case DW_TAG_class_type
:
17626 case DW_TAG_interface_type
:
17627 case DW_TAG_enumeration_type
:
17628 case DW_TAG_structure_type
:
17629 case DW_TAG_subrange_type
:
17630 case DW_TAG_typedef
:
17631 case DW_TAG_union_type
:
17638 /* Load all DIEs that are interesting for partial symbols into memory. */
17640 static struct partial_die_info
*
17641 load_partial_dies (const struct die_reader_specs
*reader
,
17642 const gdb_byte
*info_ptr
, int building_psymtab
)
17644 struct dwarf2_cu
*cu
= reader
->cu
;
17645 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17646 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
17647 unsigned int bytes_read
;
17648 unsigned int load_all
= 0;
17649 int nesting_level
= 1;
17654 gdb_assert (cu
->per_cu
!= NULL
);
17655 if (cu
->per_cu
->load_all_dies
)
17659 = htab_create_alloc_ex (cu
->header
.length
/ 12,
17663 &cu
->comp_unit_obstack
,
17664 hashtab_obstack_allocate
,
17665 dummy_obstack_deallocate
);
17669 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
17671 /* A NULL abbrev means the end of a series of children. */
17672 if (abbrev
== NULL
)
17674 if (--nesting_level
== 0)
17677 info_ptr
+= bytes_read
;
17678 last_die
= parent_die
;
17679 parent_die
= parent_die
->die_parent
;
17683 /* Check for template arguments. We never save these; if
17684 they're seen, we just mark the parent, and go on our way. */
17685 if (parent_die
!= NULL
17686 && cu
->language
== language_cplus
17687 && (abbrev
->tag
== DW_TAG_template_type_param
17688 || abbrev
->tag
== DW_TAG_template_value_param
))
17690 parent_die
->has_template_arguments
= 1;
17694 /* We don't need a partial DIE for the template argument. */
17695 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17700 /* We only recurse into c++ subprograms looking for template arguments.
17701 Skip their other children. */
17703 && cu
->language
== language_cplus
17704 && parent_die
!= NULL
17705 && parent_die
->tag
== DW_TAG_subprogram
)
17707 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17711 /* Check whether this DIE is interesting enough to save. Normally
17712 we would not be interested in members here, but there may be
17713 later variables referencing them via DW_AT_specification (for
17714 static members). */
17716 && !is_type_tag_for_partial (abbrev
->tag
)
17717 && abbrev
->tag
!= DW_TAG_constant
17718 && abbrev
->tag
!= DW_TAG_enumerator
17719 && abbrev
->tag
!= DW_TAG_subprogram
17720 && abbrev
->tag
!= DW_TAG_inlined_subroutine
17721 && abbrev
->tag
!= DW_TAG_lexical_block
17722 && abbrev
->tag
!= DW_TAG_variable
17723 && abbrev
->tag
!= DW_TAG_namespace
17724 && abbrev
->tag
!= DW_TAG_module
17725 && abbrev
->tag
!= DW_TAG_member
17726 && abbrev
->tag
!= DW_TAG_imported_unit
17727 && abbrev
->tag
!= DW_TAG_imported_declaration
)
17729 /* Otherwise we skip to the next sibling, if any. */
17730 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17734 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
17737 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
17739 /* This two-pass algorithm for processing partial symbols has a
17740 high cost in cache pressure. Thus, handle some simple cases
17741 here which cover the majority of C partial symbols. DIEs
17742 which neither have specification tags in them, nor could have
17743 specification tags elsewhere pointing at them, can simply be
17744 processed and discarded.
17746 This segment is also optional; scan_partial_symbols and
17747 add_partial_symbol will handle these DIEs if we chain
17748 them in normally. When compilers which do not emit large
17749 quantities of duplicate debug information are more common,
17750 this code can probably be removed. */
17752 /* Any complete simple types at the top level (pretty much all
17753 of them, for a language without namespaces), can be processed
17755 if (parent_die
== NULL
17756 && pdi
.has_specification
== 0
17757 && pdi
.is_declaration
== 0
17758 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
17759 || pdi
.tag
== DW_TAG_base_type
17760 || pdi
.tag
== DW_TAG_subrange_type
))
17762 if (building_psymtab
&& pdi
.name
!= NULL
)
17763 add_psymbol_to_list (pdi
.name
, false,
17764 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
17765 psymbol_placement::STATIC
,
17766 0, cu
->language
, objfile
);
17767 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
17771 /* The exception for DW_TAG_typedef with has_children above is
17772 a workaround of GCC PR debug/47510. In the case of this complaint
17773 type_name_or_error will error on such types later.
17775 GDB skipped children of DW_TAG_typedef by the shortcut above and then
17776 it could not find the child DIEs referenced later, this is checked
17777 above. In correct DWARF DW_TAG_typedef should have no children. */
17779 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
17780 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
17781 "- DIE at %s [in module %s]"),
17782 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
17784 /* If we're at the second level, and we're an enumerator, and
17785 our parent has no specification (meaning possibly lives in a
17786 namespace elsewhere), then we can add the partial symbol now
17787 instead of queueing it. */
17788 if (pdi
.tag
== DW_TAG_enumerator
17789 && parent_die
!= NULL
17790 && parent_die
->die_parent
== NULL
17791 && parent_die
->tag
== DW_TAG_enumeration_type
17792 && parent_die
->has_specification
== 0)
17794 if (pdi
.name
== NULL
)
17795 complaint (_("malformed enumerator DIE ignored"));
17796 else if (building_psymtab
)
17797 add_psymbol_to_list (pdi
.name
, false,
17798 VAR_DOMAIN
, LOC_CONST
, -1,
17799 cu
->language
== language_cplus
17800 ? psymbol_placement::GLOBAL
17801 : psymbol_placement::STATIC
,
17802 0, cu
->language
, objfile
);
17804 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
17808 struct partial_die_info
*part_die
17809 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
17811 /* We'll save this DIE so link it in. */
17812 part_die
->die_parent
= parent_die
;
17813 part_die
->die_sibling
= NULL
;
17814 part_die
->die_child
= NULL
;
17816 if (last_die
&& last_die
== parent_die
)
17817 last_die
->die_child
= part_die
;
17819 last_die
->die_sibling
= part_die
;
17821 last_die
= part_die
;
17823 if (first_die
== NULL
)
17824 first_die
= part_die
;
17826 /* Maybe add the DIE to the hash table. Not all DIEs that we
17827 find interesting need to be in the hash table, because we
17828 also have the parent/sibling/child chains; only those that we
17829 might refer to by offset later during partial symbol reading.
17831 For now this means things that might have be the target of a
17832 DW_AT_specification, DW_AT_abstract_origin, or
17833 DW_AT_extension. DW_AT_extension will refer only to
17834 namespaces; DW_AT_abstract_origin refers to functions (and
17835 many things under the function DIE, but we do not recurse
17836 into function DIEs during partial symbol reading) and
17837 possibly variables as well; DW_AT_specification refers to
17838 declarations. Declarations ought to have the DW_AT_declaration
17839 flag. It happens that GCC forgets to put it in sometimes, but
17840 only for functions, not for types.
17842 Adding more things than necessary to the hash table is harmless
17843 except for the performance cost. Adding too few will result in
17844 wasted time in find_partial_die, when we reread the compilation
17845 unit with load_all_dies set. */
17848 || abbrev
->tag
== DW_TAG_constant
17849 || abbrev
->tag
== DW_TAG_subprogram
17850 || abbrev
->tag
== DW_TAG_variable
17851 || abbrev
->tag
== DW_TAG_namespace
17852 || part_die
->is_declaration
)
17856 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
17857 to_underlying (part_die
->sect_off
),
17862 /* For some DIEs we want to follow their children (if any). For C
17863 we have no reason to follow the children of structures; for other
17864 languages we have to, so that we can get at method physnames
17865 to infer fully qualified class names, for DW_AT_specification,
17866 and for C++ template arguments. For C++, we also look one level
17867 inside functions to find template arguments (if the name of the
17868 function does not already contain the template arguments).
17870 For Ada and Fortran, we need to scan the children of subprograms
17871 and lexical blocks as well because these languages allow the
17872 definition of nested entities that could be interesting for the
17873 debugger, such as nested subprograms for instance. */
17874 if (last_die
->has_children
17876 || last_die
->tag
== DW_TAG_namespace
17877 || last_die
->tag
== DW_TAG_module
17878 || last_die
->tag
== DW_TAG_enumeration_type
17879 || (cu
->language
== language_cplus
17880 && last_die
->tag
== DW_TAG_subprogram
17881 && (last_die
->name
== NULL
17882 || strchr (last_die
->name
, '<') == NULL
))
17883 || (cu
->language
!= language_c
17884 && (last_die
->tag
== DW_TAG_class_type
17885 || last_die
->tag
== DW_TAG_interface_type
17886 || last_die
->tag
== DW_TAG_structure_type
17887 || last_die
->tag
== DW_TAG_union_type
))
17888 || ((cu
->language
== language_ada
17889 || cu
->language
== language_fortran
)
17890 && (last_die
->tag
== DW_TAG_subprogram
17891 || last_die
->tag
== DW_TAG_lexical_block
))))
17894 parent_die
= last_die
;
17898 /* Otherwise we skip to the next sibling, if any. */
17899 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
17901 /* Back to the top, do it again. */
17905 partial_die_info::partial_die_info (sect_offset sect_off_
,
17906 struct abbrev_info
*abbrev
)
17907 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
17911 /* Read a minimal amount of information into the minimal die structure.
17912 INFO_PTR should point just after the initial uleb128 of a DIE. */
17915 partial_die_info::read (const struct die_reader_specs
*reader
,
17916 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
17918 struct dwarf2_cu
*cu
= reader
->cu
;
17919 struct dwarf2_per_objfile
*dwarf2_per_objfile
17920 = cu
->per_cu
->dwarf2_per_objfile
;
17922 int has_low_pc_attr
= 0;
17923 int has_high_pc_attr
= 0;
17924 int high_pc_relative
= 0;
17926 std::vector
<struct attribute
> attr_vec (abbrev
.num_attrs
);
17927 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
17929 bool need_reprocess
;
17930 info_ptr
= read_attribute (reader
, &attr_vec
[i
], &abbrev
.attrs
[i
],
17931 info_ptr
, &need_reprocess
);
17932 /* String and address offsets that need to do the reprocessing have
17933 already been read at this point, so there is no need to wait until
17934 the loop terminates to do the reprocessing. */
17935 if (need_reprocess
)
17936 read_attribute_reprocess (reader
, &attr_vec
[i
]);
17937 attribute
&attr
= attr_vec
[i
];
17938 /* Store the data if it is of an attribute we want to keep in a
17939 partial symbol table. */
17945 case DW_TAG_compile_unit
:
17946 case DW_TAG_partial_unit
:
17947 case DW_TAG_type_unit
:
17948 /* Compilation units have a DW_AT_name that is a filename, not
17949 a source language identifier. */
17950 case DW_TAG_enumeration_type
:
17951 case DW_TAG_enumerator
:
17952 /* These tags always have simple identifiers already; no need
17953 to canonicalize them. */
17954 name
= DW_STRING (&attr
);
17958 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17961 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
17962 &objfile
->per_bfd
->storage_obstack
);
17967 case DW_AT_linkage_name
:
17968 case DW_AT_MIPS_linkage_name
:
17969 /* Note that both forms of linkage name might appear. We
17970 assume they will be the same, and we only store the last
17972 linkage_name
= DW_STRING (&attr
);
17975 has_low_pc_attr
= 1;
17976 lowpc
= attr
.value_as_address ();
17978 case DW_AT_high_pc
:
17979 has_high_pc_attr
= 1;
17980 highpc
= attr
.value_as_address ();
17981 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
17982 high_pc_relative
= 1;
17984 case DW_AT_location
:
17985 /* Support the .debug_loc offsets. */
17986 if (attr
.form_is_block ())
17988 d
.locdesc
= DW_BLOCK (&attr
);
17990 else if (attr
.form_is_section_offset ())
17992 dwarf2_complex_location_expr_complaint ();
17996 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17997 "partial symbol information");
18000 case DW_AT_external
:
18001 is_external
= DW_UNSND (&attr
);
18003 case DW_AT_declaration
:
18004 is_declaration
= DW_UNSND (&attr
);
18009 case DW_AT_abstract_origin
:
18010 case DW_AT_specification
:
18011 case DW_AT_extension
:
18012 has_specification
= 1;
18013 spec_offset
= dwarf2_get_ref_die_offset (&attr
);
18014 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18015 || cu
->per_cu
->is_dwz
);
18017 case DW_AT_sibling
:
18018 /* Ignore absolute siblings, they might point outside of
18019 the current compile unit. */
18020 if (attr
.form
== DW_FORM_ref_addr
)
18021 complaint (_("ignoring absolute DW_AT_sibling"));
18024 const gdb_byte
*buffer
= reader
->buffer
;
18025 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
18026 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
18028 if (sibling_ptr
< info_ptr
)
18029 complaint (_("DW_AT_sibling points backwards"));
18030 else if (sibling_ptr
> reader
->buffer_end
)
18031 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
18033 sibling
= sibling_ptr
;
18036 case DW_AT_byte_size
:
18039 case DW_AT_const_value
:
18040 has_const_value
= 1;
18042 case DW_AT_calling_convention
:
18043 /* DWARF doesn't provide a way to identify a program's source-level
18044 entry point. DW_AT_calling_convention attributes are only meant
18045 to describe functions' calling conventions.
18047 However, because it's a necessary piece of information in
18048 Fortran, and before DWARF 4 DW_CC_program was the only
18049 piece of debugging information whose definition refers to
18050 a 'main program' at all, several compilers marked Fortran
18051 main programs with DW_CC_program --- even when those
18052 functions use the standard calling conventions.
18054 Although DWARF now specifies a way to provide this
18055 information, we support this practice for backward
18057 if (DW_UNSND (&attr
) == DW_CC_program
18058 && cu
->language
== language_fortran
)
18059 main_subprogram
= 1;
18062 if (DW_UNSND (&attr
) == DW_INL_inlined
18063 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
18064 may_be_inlined
= 1;
18068 if (tag
== DW_TAG_imported_unit
)
18070 d
.sect_off
= dwarf2_get_ref_die_offset (&attr
);
18071 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18072 || cu
->per_cu
->is_dwz
);
18076 case DW_AT_main_subprogram
:
18077 main_subprogram
= DW_UNSND (&attr
);
18082 /* It would be nice to reuse dwarf2_get_pc_bounds here,
18083 but that requires a full DIE, so instead we just
18085 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
18086 unsigned int ranges_offset
= (DW_UNSND (&attr
)
18087 + (need_ranges_base
18091 /* Value of the DW_AT_ranges attribute is the offset in the
18092 .debug_ranges section. */
18093 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
18104 /* For Ada, if both the name and the linkage name appear, we prefer
18105 the latter. This lets "catch exception" work better, regardless
18106 of the order in which the name and linkage name were emitted.
18107 Really, though, this is just a workaround for the fact that gdb
18108 doesn't store both the name and the linkage name. */
18109 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
18110 name
= linkage_name
;
18112 if (high_pc_relative
)
18115 if (has_low_pc_attr
&& has_high_pc_attr
)
18117 /* When using the GNU linker, .gnu.linkonce. sections are used to
18118 eliminate duplicate copies of functions and vtables and such.
18119 The linker will arbitrarily choose one and discard the others.
18120 The AT_*_pc values for such functions refer to local labels in
18121 these sections. If the section from that file was discarded, the
18122 labels are not in the output, so the relocs get a value of 0.
18123 If this is a discarded function, mark the pc bounds as invalid,
18124 so that GDB will ignore it. */
18125 if (lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
18127 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18128 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18130 complaint (_("DW_AT_low_pc %s is zero "
18131 "for DIE at %s [in module %s]"),
18132 paddress (gdbarch
, lowpc
),
18133 sect_offset_str (sect_off
),
18134 objfile_name (objfile
));
18136 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
18137 else if (lowpc
>= highpc
)
18139 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18140 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18142 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
18143 "for DIE at %s [in module %s]"),
18144 paddress (gdbarch
, lowpc
),
18145 paddress (gdbarch
, highpc
),
18146 sect_offset_str (sect_off
),
18147 objfile_name (objfile
));
18156 /* Find a cached partial DIE at OFFSET in CU. */
18158 struct partial_die_info
*
18159 dwarf2_cu::find_partial_die (sect_offset sect_off
)
18161 struct partial_die_info
*lookup_die
= NULL
;
18162 struct partial_die_info
part_die (sect_off
);
18164 lookup_die
= ((struct partial_die_info
*)
18165 htab_find_with_hash (partial_dies
, &part_die
,
18166 to_underlying (sect_off
)));
18171 /* Find a partial DIE at OFFSET, which may or may not be in CU,
18172 except in the case of .debug_types DIEs which do not reference
18173 outside their CU (they do however referencing other types via
18174 DW_FORM_ref_sig8). */
18176 static const struct cu_partial_die_info
18177 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
18179 struct dwarf2_per_objfile
*dwarf2_per_objfile
18180 = cu
->per_cu
->dwarf2_per_objfile
;
18181 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18182 struct dwarf2_per_cu_data
*per_cu
= NULL
;
18183 struct partial_die_info
*pd
= NULL
;
18185 if (offset_in_dwz
== cu
->per_cu
->is_dwz
18186 && cu
->header
.offset_in_cu_p (sect_off
))
18188 pd
= cu
->find_partial_die (sect_off
);
18191 /* We missed recording what we needed.
18192 Load all dies and try again. */
18193 per_cu
= cu
->per_cu
;
18197 /* TUs don't reference other CUs/TUs (except via type signatures). */
18198 if (cu
->per_cu
->is_debug_types
)
18200 error (_("Dwarf Error: Type Unit at offset %s contains"
18201 " external reference to offset %s [in module %s].\n"),
18202 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
18203 bfd_get_filename (objfile
->obfd
));
18205 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
18206 dwarf2_per_objfile
);
18208 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
18209 load_partial_comp_unit (per_cu
);
18211 per_cu
->cu
->last_used
= 0;
18212 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18215 /* If we didn't find it, and not all dies have been loaded,
18216 load them all and try again. */
18218 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
18220 per_cu
->load_all_dies
= 1;
18222 /* This is nasty. When we reread the DIEs, somewhere up the call chain
18223 THIS_CU->cu may already be in use. So we can't just free it and
18224 replace its DIEs with the ones we read in. Instead, we leave those
18225 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
18226 and clobber THIS_CU->cu->partial_dies with the hash table for the new
18228 load_partial_comp_unit (per_cu
);
18230 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18234 internal_error (__FILE__
, __LINE__
,
18235 _("could not find partial DIE %s "
18236 "in cache [from module %s]\n"),
18237 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
18238 return { per_cu
->cu
, pd
};
18241 /* See if we can figure out if the class lives in a namespace. We do
18242 this by looking for a member function; its demangled name will
18243 contain namespace info, if there is any. */
18246 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
18247 struct dwarf2_cu
*cu
)
18249 /* NOTE: carlton/2003-10-07: Getting the info this way changes
18250 what template types look like, because the demangler
18251 frequently doesn't give the same name as the debug info. We
18252 could fix this by only using the demangled name to get the
18253 prefix (but see comment in read_structure_type). */
18255 struct partial_die_info
*real_pdi
;
18256 struct partial_die_info
*child_pdi
;
18258 /* If this DIE (this DIE's specification, if any) has a parent, then
18259 we should not do this. We'll prepend the parent's fully qualified
18260 name when we create the partial symbol. */
18262 real_pdi
= struct_pdi
;
18263 while (real_pdi
->has_specification
)
18265 auto res
= find_partial_die (real_pdi
->spec_offset
,
18266 real_pdi
->spec_is_dwz
, cu
);
18267 real_pdi
= res
.pdi
;
18271 if (real_pdi
->die_parent
!= NULL
)
18274 for (child_pdi
= struct_pdi
->die_child
;
18276 child_pdi
= child_pdi
->die_sibling
)
18278 if (child_pdi
->tag
== DW_TAG_subprogram
18279 && child_pdi
->linkage_name
!= NULL
)
18281 gdb::unique_xmalloc_ptr
<char> actual_class_name
18282 (language_class_name_from_physname (cu
->language_defn
,
18283 child_pdi
->linkage_name
));
18284 if (actual_class_name
!= NULL
)
18286 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18288 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
18289 actual_class_name
.get ());
18297 partial_die_info::fixup (struct dwarf2_cu
*cu
)
18299 /* Once we've fixed up a die, there's no point in doing so again.
18300 This also avoids a memory leak if we were to call
18301 guess_partial_die_structure_name multiple times. */
18305 /* If we found a reference attribute and the DIE has no name, try
18306 to find a name in the referred to DIE. */
18308 if (name
== NULL
&& has_specification
)
18310 struct partial_die_info
*spec_die
;
18312 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18313 spec_die
= res
.pdi
;
18316 spec_die
->fixup (cu
);
18318 if (spec_die
->name
)
18320 name
= spec_die
->name
;
18322 /* Copy DW_AT_external attribute if it is set. */
18323 if (spec_die
->is_external
)
18324 is_external
= spec_die
->is_external
;
18328 /* Set default names for some unnamed DIEs. */
18330 if (name
== NULL
&& tag
== DW_TAG_namespace
)
18331 name
= CP_ANONYMOUS_NAMESPACE_STR
;
18333 /* If there is no parent die to provide a namespace, and there are
18334 children, see if we can determine the namespace from their linkage
18336 if (cu
->language
== language_cplus
18337 && !cu
->per_cu
->dwarf2_per_objfile
->types
.empty ()
18338 && die_parent
== NULL
18340 && (tag
== DW_TAG_class_type
18341 || tag
== DW_TAG_structure_type
18342 || tag
== DW_TAG_union_type
))
18343 guess_partial_die_structure_name (this, cu
);
18345 /* GCC might emit a nameless struct or union that has a linkage
18346 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
18348 && (tag
== DW_TAG_class_type
18349 || tag
== DW_TAG_interface_type
18350 || tag
== DW_TAG_structure_type
18351 || tag
== DW_TAG_union_type
)
18352 && linkage_name
!= NULL
)
18354 gdb::unique_xmalloc_ptr
<char> demangled
18355 (gdb_demangle (linkage_name
, DMGL_TYPES
));
18356 if (demangled
!= nullptr)
18360 /* Strip any leading namespaces/classes, keep only the base name.
18361 DW_AT_name for named DIEs does not contain the prefixes. */
18362 base
= strrchr (demangled
.get (), ':');
18363 if (base
&& base
> demangled
.get () && base
[-1] == ':')
18366 base
= demangled
.get ();
18368 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18369 name
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
, base
);
18376 /* Process the attributes that had to be skipped in the first round. These
18377 attributes are the ones that need str_offsets_base or addr_base attributes.
18378 They could not have been processed in the first round, because at the time
18379 the values of str_offsets_base or addr_base may not have been known. */
18380 void read_attribute_reprocess (const struct die_reader_specs
*reader
,
18381 struct attribute
*attr
)
18383 struct dwarf2_cu
*cu
= reader
->cu
;
18384 switch (attr
->form
)
18386 case DW_FORM_addrx
:
18387 case DW_FORM_GNU_addr_index
:
18388 DW_ADDR (attr
) = read_addr_index (cu
, DW_UNSND (attr
));
18391 case DW_FORM_strx1
:
18392 case DW_FORM_strx2
:
18393 case DW_FORM_strx3
:
18394 case DW_FORM_strx4
:
18395 case DW_FORM_GNU_str_index
:
18397 unsigned int str_index
= DW_UNSND (attr
);
18398 if (reader
->dwo_file
!= NULL
)
18400 DW_STRING (attr
) = read_dwo_str_index (reader
, str_index
);
18401 DW_STRING_IS_CANONICAL (attr
) = 0;
18405 DW_STRING (attr
) = read_stub_str_index (cu
, str_index
);
18406 DW_STRING_IS_CANONICAL (attr
) = 0;
18411 gdb_assert_not_reached (_("Unexpected DWARF form."));
18415 /* Read an attribute value described by an attribute form. */
18417 static const gdb_byte
*
18418 read_attribute_value (const struct die_reader_specs
*reader
,
18419 struct attribute
*attr
, unsigned form
,
18420 LONGEST implicit_const
, const gdb_byte
*info_ptr
,
18421 bool *need_reprocess
)
18423 struct dwarf2_cu
*cu
= reader
->cu
;
18424 struct dwarf2_per_objfile
*dwarf2_per_objfile
18425 = cu
->per_cu
->dwarf2_per_objfile
;
18426 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18427 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18428 bfd
*abfd
= reader
->abfd
;
18429 struct comp_unit_head
*cu_header
= &cu
->header
;
18430 unsigned int bytes_read
;
18431 struct dwarf_block
*blk
;
18432 *need_reprocess
= false;
18434 attr
->form
= (enum dwarf_form
) form
;
18437 case DW_FORM_ref_addr
:
18438 if (cu
->header
.version
== 2)
18439 DW_UNSND (attr
) = cu
->header
.read_address (abfd
, info_ptr
,
18442 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
,
18444 info_ptr
+= bytes_read
;
18446 case DW_FORM_GNU_ref_alt
:
18447 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
18448 info_ptr
+= bytes_read
;
18451 DW_ADDR (attr
) = cu
->header
.read_address (abfd
, info_ptr
, &bytes_read
);
18452 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
18453 info_ptr
+= bytes_read
;
18455 case DW_FORM_block2
:
18456 blk
= dwarf_alloc_block (cu
);
18457 blk
->size
= read_2_bytes (abfd
, info_ptr
);
18459 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18460 info_ptr
+= blk
->size
;
18461 DW_BLOCK (attr
) = blk
;
18463 case DW_FORM_block4
:
18464 blk
= dwarf_alloc_block (cu
);
18465 blk
->size
= read_4_bytes (abfd
, info_ptr
);
18467 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18468 info_ptr
+= blk
->size
;
18469 DW_BLOCK (attr
) = blk
;
18471 case DW_FORM_data2
:
18472 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
18475 case DW_FORM_data4
:
18476 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
18479 case DW_FORM_data8
:
18480 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
18483 case DW_FORM_data16
:
18484 blk
= dwarf_alloc_block (cu
);
18486 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
18488 DW_BLOCK (attr
) = blk
;
18490 case DW_FORM_sec_offset
:
18491 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
18492 info_ptr
+= bytes_read
;
18494 case DW_FORM_string
:
18495 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
18496 DW_STRING_IS_CANONICAL (attr
) = 0;
18497 info_ptr
+= bytes_read
;
18500 if (!cu
->per_cu
->is_dwz
)
18502 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
18503 abfd
, info_ptr
, cu_header
,
18505 DW_STRING_IS_CANONICAL (attr
) = 0;
18506 info_ptr
+= bytes_read
;
18510 case DW_FORM_line_strp
:
18511 if (!cu
->per_cu
->is_dwz
)
18513 DW_STRING (attr
) = read_indirect_line_string (dwarf2_per_objfile
,
18515 cu_header
, &bytes_read
);
18516 DW_STRING_IS_CANONICAL (attr
) = 0;
18517 info_ptr
+= bytes_read
;
18521 case DW_FORM_GNU_strp_alt
:
18523 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
18524 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
18527 DW_STRING (attr
) = read_indirect_string_from_dwz (objfile
,
18529 DW_STRING_IS_CANONICAL (attr
) = 0;
18530 info_ptr
+= bytes_read
;
18533 case DW_FORM_exprloc
:
18534 case DW_FORM_block
:
18535 blk
= dwarf_alloc_block (cu
);
18536 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18537 info_ptr
+= bytes_read
;
18538 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18539 info_ptr
+= blk
->size
;
18540 DW_BLOCK (attr
) = blk
;
18542 case DW_FORM_block1
:
18543 blk
= dwarf_alloc_block (cu
);
18544 blk
->size
= read_1_byte (abfd
, info_ptr
);
18546 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18547 info_ptr
+= blk
->size
;
18548 DW_BLOCK (attr
) = blk
;
18550 case DW_FORM_data1
:
18551 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
18555 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
18558 case DW_FORM_flag_present
:
18559 DW_UNSND (attr
) = 1;
18561 case DW_FORM_sdata
:
18562 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
18563 info_ptr
+= bytes_read
;
18565 case DW_FORM_udata
:
18566 case DW_FORM_rnglistx
:
18567 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18568 info_ptr
+= bytes_read
;
18571 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18572 + read_1_byte (abfd
, info_ptr
));
18576 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18577 + read_2_bytes (abfd
, info_ptr
));
18581 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18582 + read_4_bytes (abfd
, info_ptr
));
18586 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18587 + read_8_bytes (abfd
, info_ptr
));
18590 case DW_FORM_ref_sig8
:
18591 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
18594 case DW_FORM_ref_udata
:
18595 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18596 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
18597 info_ptr
+= bytes_read
;
18599 case DW_FORM_indirect
:
18600 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18601 info_ptr
+= bytes_read
;
18602 if (form
== DW_FORM_implicit_const
)
18604 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
18605 info_ptr
+= bytes_read
;
18607 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
18608 info_ptr
, need_reprocess
);
18610 case DW_FORM_implicit_const
:
18611 DW_SND (attr
) = implicit_const
;
18613 case DW_FORM_addrx
:
18614 case DW_FORM_GNU_addr_index
:
18615 *need_reprocess
= true;
18616 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18617 info_ptr
+= bytes_read
;
18620 case DW_FORM_strx1
:
18621 case DW_FORM_strx2
:
18622 case DW_FORM_strx3
:
18623 case DW_FORM_strx4
:
18624 case DW_FORM_GNU_str_index
:
18626 ULONGEST str_index
;
18627 if (form
== DW_FORM_strx1
)
18629 str_index
= read_1_byte (abfd
, info_ptr
);
18632 else if (form
== DW_FORM_strx2
)
18634 str_index
= read_2_bytes (abfd
, info_ptr
);
18637 else if (form
== DW_FORM_strx3
)
18639 str_index
= read_3_bytes (abfd
, info_ptr
);
18642 else if (form
== DW_FORM_strx4
)
18644 str_index
= read_4_bytes (abfd
, info_ptr
);
18649 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18650 info_ptr
+= bytes_read
;
18652 *need_reprocess
= true;
18653 DW_UNSND (attr
) = str_index
;
18657 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
18658 dwarf_form_name (form
),
18659 bfd_get_filename (abfd
));
18663 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
18664 attr
->form
= DW_FORM_GNU_ref_alt
;
18666 /* We have seen instances where the compiler tried to emit a byte
18667 size attribute of -1 which ended up being encoded as an unsigned
18668 0xffffffff. Although 0xffffffff is technically a valid size value,
18669 an object of this size seems pretty unlikely so we can relatively
18670 safely treat these cases as if the size attribute was invalid and
18671 treat them as zero by default. */
18672 if (attr
->name
== DW_AT_byte_size
18673 && form
== DW_FORM_data4
18674 && DW_UNSND (attr
) >= 0xffffffff)
18677 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
18678 hex_string (DW_UNSND (attr
)));
18679 DW_UNSND (attr
) = 0;
18685 /* Read an attribute described by an abbreviated attribute. */
18687 static const gdb_byte
*
18688 read_attribute (const struct die_reader_specs
*reader
,
18689 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
18690 const gdb_byte
*info_ptr
, bool *need_reprocess
)
18692 attr
->name
= abbrev
->name
;
18693 return read_attribute_value (reader
, attr
, abbrev
->form
,
18694 abbrev
->implicit_const
, info_ptr
,
18698 /* Cover function for read_initial_length.
18699 Returns the length of the object at BUF, and stores the size of the
18700 initial length in *BYTES_READ and stores the size that offsets will be in
18702 If the initial length size is not equivalent to that specified in
18703 CU_HEADER then issue a complaint.
18704 This is useful when reading non-comp-unit headers. */
18707 read_checked_initial_length_and_offset (bfd
*abfd
, const gdb_byte
*buf
,
18708 const struct comp_unit_head
*cu_header
,
18709 unsigned int *bytes_read
,
18710 unsigned int *offset_size
)
18712 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
18714 gdb_assert (cu_header
->initial_length_size
== 4
18715 || cu_header
->initial_length_size
== 8
18716 || cu_header
->initial_length_size
== 12);
18718 if (cu_header
->initial_length_size
!= *bytes_read
)
18719 complaint (_("intermixed 32-bit and 64-bit DWARF sections"));
18721 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
18725 /* Return pointer to string at section SECT offset STR_OFFSET with error
18726 reporting strings FORM_NAME and SECT_NAME. */
18728 static const char *
18729 read_indirect_string_at_offset_from (struct objfile
*objfile
,
18730 bfd
*abfd
, LONGEST str_offset
,
18731 struct dwarf2_section_info
*sect
,
18732 const char *form_name
,
18733 const char *sect_name
)
18735 sect
->read (objfile
);
18736 if (sect
->buffer
== NULL
)
18737 error (_("%s used without %s section [in module %s]"),
18738 form_name
, sect_name
, bfd_get_filename (abfd
));
18739 if (str_offset
>= sect
->size
)
18740 error (_("%s pointing outside of %s section [in module %s]"),
18741 form_name
, sect_name
, bfd_get_filename (abfd
));
18742 gdb_assert (HOST_CHAR_BIT
== 8);
18743 if (sect
->buffer
[str_offset
] == '\0')
18745 return (const char *) (sect
->buffer
+ str_offset
);
18748 /* Return pointer to string at .debug_str offset STR_OFFSET. */
18750 static const char *
18751 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18752 bfd
*abfd
, LONGEST str_offset
)
18754 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
18756 &dwarf2_per_objfile
->str
,
18757 "DW_FORM_strp", ".debug_str");
18760 /* Return pointer to string at .debug_line_str offset STR_OFFSET. */
18762 static const char *
18763 read_indirect_line_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18764 bfd
*abfd
, LONGEST str_offset
)
18766 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
18768 &dwarf2_per_objfile
->line_str
,
18769 "DW_FORM_line_strp",
18770 ".debug_line_str");
18773 /* Read a string at offset STR_OFFSET in the .debug_str section from
18774 the .dwz file DWZ. Throw an error if the offset is too large. If
18775 the string consists of a single NUL byte, return NULL; otherwise
18776 return a pointer to the string. */
18778 static const char *
18779 read_indirect_string_from_dwz (struct objfile
*objfile
, struct dwz_file
*dwz
,
18780 LONGEST str_offset
)
18782 dwz
->str
.read (objfile
);
18784 if (dwz
->str
.buffer
== NULL
)
18785 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
18786 "section [in module %s]"),
18787 bfd_get_filename (dwz
->dwz_bfd
.get ()));
18788 if (str_offset
>= dwz
->str
.size
)
18789 error (_("DW_FORM_GNU_strp_alt pointing outside of "
18790 ".debug_str section [in module %s]"),
18791 bfd_get_filename (dwz
->dwz_bfd
.get ()));
18792 gdb_assert (HOST_CHAR_BIT
== 8);
18793 if (dwz
->str
.buffer
[str_offset
] == '\0')
18795 return (const char *) (dwz
->str
.buffer
+ str_offset
);
18798 /* Return pointer to string at .debug_str offset as read from BUF.
18799 BUF is assumed to be in a compilation unit described by CU_HEADER.
18800 Return *BYTES_READ_PTR count of bytes read from BUF. */
18802 static const char *
18803 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
18804 const gdb_byte
*buf
,
18805 const struct comp_unit_head
*cu_header
,
18806 unsigned int *bytes_read_ptr
)
18808 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
18810 return read_indirect_string_at_offset (dwarf2_per_objfile
, abfd
, str_offset
);
18813 /* Return pointer to string at .debug_line_str offset as read from BUF.
18814 BUF is assumed to be in a compilation unit described by CU_HEADER.
18815 Return *BYTES_READ_PTR count of bytes read from BUF. */
18817 static const char *
18818 read_indirect_line_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18819 bfd
*abfd
, const gdb_byte
*buf
,
18820 const struct comp_unit_head
*cu_header
,
18821 unsigned int *bytes_read_ptr
)
18823 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
18825 return read_indirect_line_string_at_offset (dwarf2_per_objfile
, abfd
,
18829 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
18830 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
18831 ADDR_SIZE is the size of addresses from the CU header. */
18834 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18835 unsigned int addr_index
, gdb::optional
<ULONGEST
> addr_base
,
18838 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18839 bfd
*abfd
= objfile
->obfd
;
18840 const gdb_byte
*info_ptr
;
18841 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
18843 dwarf2_per_objfile
->addr
.read (objfile
);
18844 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
18845 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
18846 objfile_name (objfile
));
18847 if (addr_base_or_zero
+ addr_index
* addr_size
18848 >= dwarf2_per_objfile
->addr
.size
)
18849 error (_("DW_FORM_addr_index pointing outside of "
18850 ".debug_addr section [in module %s]"),
18851 objfile_name (objfile
));
18852 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
18853 + addr_base_or_zero
+ addr_index
* addr_size
);
18854 if (addr_size
== 4)
18855 return bfd_get_32 (abfd
, info_ptr
);
18857 return bfd_get_64 (abfd
, info_ptr
);
18860 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
18863 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
18865 return read_addr_index_1 (cu
->per_cu
->dwarf2_per_objfile
, addr_index
,
18866 cu
->addr_base
, cu
->header
.addr_size
);
18869 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
18872 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
18873 unsigned int *bytes_read
)
18875 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
18876 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
18878 return read_addr_index (cu
, addr_index
);
18881 /* Given an index in .debug_addr, fetch the value.
18882 NOTE: This can be called during dwarf expression evaluation,
18883 long after the debug information has been read, and thus per_cu->cu
18884 may no longer exist. */
18887 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
18888 unsigned int addr_index
)
18890 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
18891 struct dwarf2_cu
*cu
= per_cu
->cu
;
18892 gdb::optional
<ULONGEST
> addr_base
;
18895 /* We need addr_base and addr_size.
18896 If we don't have PER_CU->cu, we have to get it.
18897 Nasty, but the alternative is storing the needed info in PER_CU,
18898 which at this point doesn't seem justified: it's not clear how frequently
18899 it would get used and it would increase the size of every PER_CU.
18900 Entry points like dwarf2_per_cu_addr_size do a similar thing
18901 so we're not in uncharted territory here.
18902 Alas we need to be a bit more complicated as addr_base is contained
18905 We don't need to read the entire CU(/TU).
18906 We just need the header and top level die.
18908 IWBN to use the aging mechanism to let us lazily later discard the CU.
18909 For now we skip this optimization. */
18913 addr_base
= cu
->addr_base
;
18914 addr_size
= cu
->header
.addr_size
;
18918 cutu_reader
reader (per_cu
, NULL
, 0, false);
18919 addr_base
= reader
.cu
->addr_base
;
18920 addr_size
= reader
.cu
->header
.addr_size
;
18923 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
18927 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
18928 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
18931 static const char *
18932 read_str_index (struct dwarf2_cu
*cu
,
18933 struct dwarf2_section_info
*str_section
,
18934 struct dwarf2_section_info
*str_offsets_section
,
18935 ULONGEST str_offsets_base
, ULONGEST str_index
)
18937 struct dwarf2_per_objfile
*dwarf2_per_objfile
18938 = cu
->per_cu
->dwarf2_per_objfile
;
18939 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18940 const char *objf_name
= objfile_name (objfile
);
18941 bfd
*abfd
= objfile
->obfd
;
18942 const gdb_byte
*info_ptr
;
18943 ULONGEST str_offset
;
18944 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
18946 str_section
->read (objfile
);
18947 str_offsets_section
->read (objfile
);
18948 if (str_section
->buffer
== NULL
)
18949 error (_("%s used without %s section"
18950 " in CU at offset %s [in module %s]"),
18951 form_name
, str_section
->get_name (),
18952 sect_offset_str (cu
->header
.sect_off
), objf_name
);
18953 if (str_offsets_section
->buffer
== NULL
)
18954 error (_("%s used without %s section"
18955 " in CU at offset %s [in module %s]"),
18956 form_name
, str_section
->get_name (),
18957 sect_offset_str (cu
->header
.sect_off
), objf_name
);
18958 info_ptr
= (str_offsets_section
->buffer
18960 + str_index
* cu
->header
.offset_size
);
18961 if (cu
->header
.offset_size
== 4)
18962 str_offset
= bfd_get_32 (abfd
, info_ptr
);
18964 str_offset
= bfd_get_64 (abfd
, info_ptr
);
18965 if (str_offset
>= str_section
->size
)
18966 error (_("Offset from %s pointing outside of"
18967 " .debug_str.dwo section in CU at offset %s [in module %s]"),
18968 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
18969 return (const char *) (str_section
->buffer
+ str_offset
);
18972 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
18974 static const char *
18975 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
18977 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
18978 ? reader
->cu
->header
.addr_size
: 0;
18979 return read_str_index (reader
->cu
,
18980 &reader
->dwo_file
->sections
.str
,
18981 &reader
->dwo_file
->sections
.str_offsets
,
18982 str_offsets_base
, str_index
);
18985 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
18987 static const char *
18988 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
18990 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18991 const char *objf_name
= objfile_name (objfile
);
18992 static const char form_name
[] = "DW_FORM_GNU_str_index";
18993 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
18995 if (!cu
->str_offsets_base
.has_value ())
18996 error (_("%s used in Fission stub without %s"
18997 " in CU at offset 0x%lx [in module %s]"),
18998 form_name
, str_offsets_attr_name
,
18999 (long) cu
->header
.offset_size
, objf_name
);
19001 return read_str_index (cu
,
19002 &cu
->per_cu
->dwarf2_per_objfile
->str
,
19003 &cu
->per_cu
->dwarf2_per_objfile
->str_offsets
,
19004 *cu
->str_offsets_base
, str_index
);
19007 /* Return the length of an LEB128 number in BUF. */
19010 leb128_size (const gdb_byte
*buf
)
19012 const gdb_byte
*begin
= buf
;
19018 if ((byte
& 128) == 0)
19019 return buf
- begin
;
19024 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
19033 cu
->language
= language_c
;
19036 case DW_LANG_C_plus_plus
:
19037 case DW_LANG_C_plus_plus_11
:
19038 case DW_LANG_C_plus_plus_14
:
19039 cu
->language
= language_cplus
;
19042 cu
->language
= language_d
;
19044 case DW_LANG_Fortran77
:
19045 case DW_LANG_Fortran90
:
19046 case DW_LANG_Fortran95
:
19047 case DW_LANG_Fortran03
:
19048 case DW_LANG_Fortran08
:
19049 cu
->language
= language_fortran
;
19052 cu
->language
= language_go
;
19054 case DW_LANG_Mips_Assembler
:
19055 cu
->language
= language_asm
;
19057 case DW_LANG_Ada83
:
19058 case DW_LANG_Ada95
:
19059 cu
->language
= language_ada
;
19061 case DW_LANG_Modula2
:
19062 cu
->language
= language_m2
;
19064 case DW_LANG_Pascal83
:
19065 cu
->language
= language_pascal
;
19068 cu
->language
= language_objc
;
19071 case DW_LANG_Rust_old
:
19072 cu
->language
= language_rust
;
19074 case DW_LANG_Cobol74
:
19075 case DW_LANG_Cobol85
:
19077 cu
->language
= language_minimal
;
19080 cu
->language_defn
= language_def (cu
->language
);
19083 /* Return the named attribute or NULL if not there. */
19085 static struct attribute
*
19086 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19091 struct attribute
*spec
= NULL
;
19093 for (i
= 0; i
< die
->num_attrs
; ++i
)
19095 if (die
->attrs
[i
].name
== name
)
19096 return &die
->attrs
[i
];
19097 if (die
->attrs
[i
].name
== DW_AT_specification
19098 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
19099 spec
= &die
->attrs
[i
];
19105 die
= follow_die_ref (die
, spec
, &cu
);
19111 /* Return the named attribute or NULL if not there,
19112 but do not follow DW_AT_specification, etc.
19113 This is for use in contexts where we're reading .debug_types dies.
19114 Following DW_AT_specification, DW_AT_abstract_origin will take us
19115 back up the chain, and we want to go down. */
19117 static struct attribute
*
19118 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
19122 for (i
= 0; i
< die
->num_attrs
; ++i
)
19123 if (die
->attrs
[i
].name
== name
)
19124 return &die
->attrs
[i
];
19129 /* Return the string associated with a string-typed attribute, or NULL if it
19130 is either not found or is of an incorrect type. */
19132 static const char *
19133 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19135 struct attribute
*attr
;
19136 const char *str
= NULL
;
19138 attr
= dwarf2_attr (die
, name
, cu
);
19142 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
19143 || attr
->form
== DW_FORM_string
19144 || attr
->form
== DW_FORM_strx
19145 || attr
->form
== DW_FORM_strx1
19146 || attr
->form
== DW_FORM_strx2
19147 || attr
->form
== DW_FORM_strx3
19148 || attr
->form
== DW_FORM_strx4
19149 || attr
->form
== DW_FORM_GNU_str_index
19150 || attr
->form
== DW_FORM_GNU_strp_alt
)
19151 str
= DW_STRING (attr
);
19153 complaint (_("string type expected for attribute %s for "
19154 "DIE at %s in module %s"),
19155 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
19156 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
19162 /* Return the dwo name or NULL if not present. If present, it is in either
19163 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
19164 static const char *
19165 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
19167 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
19168 if (dwo_name
== nullptr)
19169 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
19173 /* Return non-zero iff the attribute NAME is defined for the given DIE,
19174 and holds a non-zero value. This function should only be used for
19175 DW_FORM_flag or DW_FORM_flag_present attributes. */
19178 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
19180 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
19182 return (attr
&& DW_UNSND (attr
));
19186 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
19188 /* A DIE is a declaration if it has a DW_AT_declaration attribute
19189 which value is non-zero. However, we have to be careful with
19190 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
19191 (via dwarf2_flag_true_p) follows this attribute. So we may
19192 end up accidently finding a declaration attribute that belongs
19193 to a different DIE referenced by the specification attribute,
19194 even though the given DIE does not have a declaration attribute. */
19195 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
19196 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
19199 /* Return the die giving the specification for DIE, if there is
19200 one. *SPEC_CU is the CU containing DIE on input, and the CU
19201 containing the return value on output. If there is no
19202 specification, but there is an abstract origin, that is
19205 static struct die_info
*
19206 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
19208 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
19211 if (spec_attr
== NULL
)
19212 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
19214 if (spec_attr
== NULL
)
19217 return follow_die_ref (die
, spec_attr
, spec_cu
);
19220 /* Stub for free_line_header to match void * callback types. */
19223 free_line_header_voidp (void *arg
)
19225 struct line_header
*lh
= (struct line_header
*) arg
;
19230 /* A convenience function to find the proper .debug_line section for a CU. */
19232 static struct dwarf2_section_info
*
19233 get_debug_line_section (struct dwarf2_cu
*cu
)
19235 struct dwarf2_section_info
*section
;
19236 struct dwarf2_per_objfile
*dwarf2_per_objfile
19237 = cu
->per_cu
->dwarf2_per_objfile
;
19239 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
19241 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19242 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
19243 else if (cu
->per_cu
->is_dwz
)
19245 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19247 section
= &dwz
->line
;
19250 section
= &dwarf2_per_objfile
->line
;
19255 /* Read directory or file name entry format, starting with byte of
19256 format count entries, ULEB128 pairs of entry formats, ULEB128 of
19257 entries count and the entries themselves in the described entry
19261 read_formatted_entries (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19262 bfd
*abfd
, const gdb_byte
**bufp
,
19263 struct line_header
*lh
,
19264 const struct comp_unit_head
*cu_header
,
19265 void (*callback
) (struct line_header
*lh
,
19268 unsigned int mod_time
,
19269 unsigned int length
))
19271 gdb_byte format_count
, formati
;
19272 ULONGEST data_count
, datai
;
19273 const gdb_byte
*buf
= *bufp
;
19274 const gdb_byte
*format_header_data
;
19275 unsigned int bytes_read
;
19277 format_count
= read_1_byte (abfd
, buf
);
19279 format_header_data
= buf
;
19280 for (formati
= 0; formati
< format_count
; formati
++)
19282 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
19284 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
19288 data_count
= read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
19290 for (datai
= 0; datai
< data_count
; datai
++)
19292 const gdb_byte
*format
= format_header_data
;
19293 struct file_entry fe
;
19295 for (formati
= 0; formati
< format_count
; formati
++)
19297 ULONGEST content_type
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
19298 format
+= bytes_read
;
19300 ULONGEST form
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
19301 format
+= bytes_read
;
19303 gdb::optional
<const char *> string
;
19304 gdb::optional
<unsigned int> uint
;
19308 case DW_FORM_string
:
19309 string
.emplace (read_direct_string (abfd
, buf
, &bytes_read
));
19313 case DW_FORM_line_strp
:
19314 string
.emplace (read_indirect_line_string (dwarf2_per_objfile
,
19321 case DW_FORM_data1
:
19322 uint
.emplace (read_1_byte (abfd
, buf
));
19326 case DW_FORM_data2
:
19327 uint
.emplace (read_2_bytes (abfd
, buf
));
19331 case DW_FORM_data4
:
19332 uint
.emplace (read_4_bytes (abfd
, buf
));
19336 case DW_FORM_data8
:
19337 uint
.emplace (read_8_bytes (abfd
, buf
));
19341 case DW_FORM_data16
:
19342 /* This is used for MD5, but file_entry does not record MD5s. */
19346 case DW_FORM_udata
:
19347 uint
.emplace (read_unsigned_leb128 (abfd
, buf
, &bytes_read
));
19351 case DW_FORM_block
:
19352 /* It is valid only for DW_LNCT_timestamp which is ignored by
19357 switch (content_type
)
19360 if (string
.has_value ())
19363 case DW_LNCT_directory_index
:
19364 if (uint
.has_value ())
19365 fe
.d_index
= (dir_index
) *uint
;
19367 case DW_LNCT_timestamp
:
19368 if (uint
.has_value ())
19369 fe
.mod_time
= *uint
;
19372 if (uint
.has_value ())
19378 complaint (_("Unknown format content type %s"),
19379 pulongest (content_type
));
19383 callback (lh
, fe
.name
, fe
.d_index
, fe
.mod_time
, fe
.length
);
19389 /* Read the statement program header starting at OFFSET in
19390 .debug_line, or .debug_line.dwo. Return a pointer
19391 to a struct line_header, allocated using xmalloc.
19392 Returns NULL if there is a problem reading the header, e.g., if it
19393 has a version we don't understand.
19395 NOTE: the strings in the include directory and file name tables of
19396 the returned object point into the dwarf line section buffer,
19397 and must not be freed. */
19399 static line_header_up
19400 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
19402 const gdb_byte
*line_ptr
;
19403 unsigned int bytes_read
, offset_size
;
19405 const char *cur_dir
, *cur_file
;
19406 struct dwarf2_section_info
*section
;
19408 struct dwarf2_per_objfile
*dwarf2_per_objfile
19409 = cu
->per_cu
->dwarf2_per_objfile
;
19411 section
= get_debug_line_section (cu
);
19412 section
->read (dwarf2_per_objfile
->objfile
);
19413 if (section
->buffer
== NULL
)
19415 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19416 complaint (_("missing .debug_line.dwo section"));
19418 complaint (_("missing .debug_line section"));
19422 /* We can't do this until we know the section is non-empty.
19423 Only then do we know we have such a section. */
19424 abfd
= section
->get_bfd_owner ();
19426 /* Make sure that at least there's room for the total_length field.
19427 That could be 12 bytes long, but we're just going to fudge that. */
19428 if (to_underlying (sect_off
) + 4 >= section
->size
)
19430 dwarf2_statement_list_fits_in_line_number_section_complaint ();
19434 line_header_up
lh (new line_header ());
19436 lh
->sect_off
= sect_off
;
19437 lh
->offset_in_dwz
= cu
->per_cu
->is_dwz
;
19439 line_ptr
= section
->buffer
+ to_underlying (sect_off
);
19441 /* Read in the header. */
19443 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
19444 &bytes_read
, &offset_size
);
19445 line_ptr
+= bytes_read
;
19447 const gdb_byte
*start_here
= line_ptr
;
19449 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
19451 dwarf2_statement_list_fits_in_line_number_section_complaint ();
19454 lh
->statement_program_end
= start_here
+ lh
->total_length
;
19455 lh
->version
= read_2_bytes (abfd
, line_ptr
);
19457 if (lh
->version
> 5)
19459 /* This is a version we don't understand. The format could have
19460 changed in ways we don't handle properly so just punt. */
19461 complaint (_("unsupported version in .debug_line section"));
19464 if (lh
->version
>= 5)
19466 gdb_byte segment_selector_size
;
19468 /* Skip address size. */
19469 read_1_byte (abfd
, line_ptr
);
19472 segment_selector_size
= read_1_byte (abfd
, line_ptr
);
19474 if (segment_selector_size
!= 0)
19476 complaint (_("unsupported segment selector size %u "
19477 "in .debug_line section"),
19478 segment_selector_size
);
19482 lh
->header_length
= read_offset (abfd
, line_ptr
, offset_size
);
19483 line_ptr
+= offset_size
;
19484 lh
->statement_program_start
= line_ptr
+ lh
->header_length
;
19485 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
19487 if (lh
->version
>= 4)
19489 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
19493 lh
->maximum_ops_per_instruction
= 1;
19495 if (lh
->maximum_ops_per_instruction
== 0)
19497 lh
->maximum_ops_per_instruction
= 1;
19498 complaint (_("invalid maximum_ops_per_instruction "
19499 "in `.debug_line' section"));
19502 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
19504 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
19506 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
19508 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
19510 lh
->standard_opcode_lengths
.reset (new unsigned char[lh
->opcode_base
]);
19512 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
19513 for (i
= 1; i
< lh
->opcode_base
; ++i
)
19515 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
19519 if (lh
->version
>= 5)
19521 /* Read directory table. */
19522 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
19524 [] (struct line_header
*header
, const char *name
,
19525 dir_index d_index
, unsigned int mod_time
,
19526 unsigned int length
)
19528 header
->add_include_dir (name
);
19531 /* Read file name table. */
19532 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
19534 [] (struct line_header
*header
, const char *name
,
19535 dir_index d_index
, unsigned int mod_time
,
19536 unsigned int length
)
19538 header
->add_file_name (name
, d_index
, mod_time
, length
);
19543 /* Read directory table. */
19544 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
19546 line_ptr
+= bytes_read
;
19547 lh
->add_include_dir (cur_dir
);
19549 line_ptr
+= bytes_read
;
19551 /* Read file name table. */
19552 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
19554 unsigned int mod_time
, length
;
19557 line_ptr
+= bytes_read
;
19558 d_index
= (dir_index
) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19559 line_ptr
+= bytes_read
;
19560 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19561 line_ptr
+= bytes_read
;
19562 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19563 line_ptr
+= bytes_read
;
19565 lh
->add_file_name (cur_file
, d_index
, mod_time
, length
);
19567 line_ptr
+= bytes_read
;
19570 if (line_ptr
> (section
->buffer
+ section
->size
))
19571 complaint (_("line number info header doesn't "
19572 "fit in `.debug_line' section"));
19577 /* Subroutine of dwarf_decode_lines to simplify it.
19578 Return the file name of the psymtab for the given file_entry.
19579 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
19580 If space for the result is malloc'd, *NAME_HOLDER will be set.
19581 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
19583 static const char *
19584 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
19585 const dwarf2_psymtab
*pst
,
19586 const char *comp_dir
,
19587 gdb::unique_xmalloc_ptr
<char> *name_holder
)
19589 const char *include_name
= fe
.name
;
19590 const char *include_name_to_compare
= include_name
;
19591 const char *pst_filename
;
19594 const char *dir_name
= fe
.include_dir (lh
);
19596 gdb::unique_xmalloc_ptr
<char> hold_compare
;
19597 if (!IS_ABSOLUTE_PATH (include_name
)
19598 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
19600 /* Avoid creating a duplicate psymtab for PST.
19601 We do this by comparing INCLUDE_NAME and PST_FILENAME.
19602 Before we do the comparison, however, we need to account
19603 for DIR_NAME and COMP_DIR.
19604 First prepend dir_name (if non-NULL). If we still don't
19605 have an absolute path prepend comp_dir (if non-NULL).
19606 However, the directory we record in the include-file's
19607 psymtab does not contain COMP_DIR (to match the
19608 corresponding symtab(s)).
19613 bash$ gcc -g ./hello.c
19614 include_name = "hello.c"
19616 DW_AT_comp_dir = comp_dir = "/tmp"
19617 DW_AT_name = "./hello.c"
19621 if (dir_name
!= NULL
)
19623 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
19624 include_name
, (char *) NULL
));
19625 include_name
= name_holder
->get ();
19626 include_name_to_compare
= include_name
;
19628 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
19630 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
19631 include_name
, (char *) NULL
));
19632 include_name_to_compare
= hold_compare
.get ();
19636 pst_filename
= pst
->filename
;
19637 gdb::unique_xmalloc_ptr
<char> copied_name
;
19638 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
19640 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
19641 pst_filename
, (char *) NULL
));
19642 pst_filename
= copied_name
.get ();
19645 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
19649 return include_name
;
19652 /* State machine to track the state of the line number program. */
19654 class lnp_state_machine
19657 /* Initialize a machine state for the start of a line number
19659 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
19660 bool record_lines_p
);
19662 file_entry
*current_file ()
19664 /* lh->file_names is 0-based, but the file name numbers in the
19665 statement program are 1-based. */
19666 return m_line_header
->file_name_at (m_file
);
19669 /* Record the line in the state machine. END_SEQUENCE is true if
19670 we're processing the end of a sequence. */
19671 void record_line (bool end_sequence
);
19673 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
19674 nop-out rest of the lines in this sequence. */
19675 void check_line_address (struct dwarf2_cu
*cu
,
19676 const gdb_byte
*line_ptr
,
19677 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
19679 void handle_set_discriminator (unsigned int discriminator
)
19681 m_discriminator
= discriminator
;
19682 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
19685 /* Handle DW_LNE_set_address. */
19686 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
19689 address
+= baseaddr
;
19690 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
19693 /* Handle DW_LNS_advance_pc. */
19694 void handle_advance_pc (CORE_ADDR adjust
);
19696 /* Handle a special opcode. */
19697 void handle_special_opcode (unsigned char op_code
);
19699 /* Handle DW_LNS_advance_line. */
19700 void handle_advance_line (int line_delta
)
19702 advance_line (line_delta
);
19705 /* Handle DW_LNS_set_file. */
19706 void handle_set_file (file_name_index file
);
19708 /* Handle DW_LNS_negate_stmt. */
19709 void handle_negate_stmt ()
19711 m_is_stmt
= !m_is_stmt
;
19714 /* Handle DW_LNS_const_add_pc. */
19715 void handle_const_add_pc ();
19717 /* Handle DW_LNS_fixed_advance_pc. */
19718 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
19720 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19724 /* Handle DW_LNS_copy. */
19725 void handle_copy ()
19727 record_line (false);
19728 m_discriminator
= 0;
19731 /* Handle DW_LNE_end_sequence. */
19732 void handle_end_sequence ()
19734 m_currently_recording_lines
= true;
19738 /* Advance the line by LINE_DELTA. */
19739 void advance_line (int line_delta
)
19741 m_line
+= line_delta
;
19743 if (line_delta
!= 0)
19744 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
19747 struct dwarf2_cu
*m_cu
;
19749 gdbarch
*m_gdbarch
;
19751 /* True if we're recording lines.
19752 Otherwise we're building partial symtabs and are just interested in
19753 finding include files mentioned by the line number program. */
19754 bool m_record_lines_p
;
19756 /* The line number header. */
19757 line_header
*m_line_header
;
19759 /* These are part of the standard DWARF line number state machine,
19760 and initialized according to the DWARF spec. */
19762 unsigned char m_op_index
= 0;
19763 /* The line table index of the current file. */
19764 file_name_index m_file
= 1;
19765 unsigned int m_line
= 1;
19767 /* These are initialized in the constructor. */
19769 CORE_ADDR m_address
;
19771 unsigned int m_discriminator
;
19773 /* Additional bits of state we need to track. */
19775 /* The last file that we called dwarf2_start_subfile for.
19776 This is only used for TLLs. */
19777 unsigned int m_last_file
= 0;
19778 /* The last file a line number was recorded for. */
19779 struct subfile
*m_last_subfile
= NULL
;
19781 /* When true, record the lines we decode. */
19782 bool m_currently_recording_lines
= false;
19784 /* The last line number that was recorded, used to coalesce
19785 consecutive entries for the same line. This can happen, for
19786 example, when discriminators are present. PR 17276. */
19787 unsigned int m_last_line
= 0;
19788 bool m_line_has_non_zero_discriminator
= false;
19792 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
19794 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
19795 / m_line_header
->maximum_ops_per_instruction
)
19796 * m_line_header
->minimum_instruction_length
);
19797 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19798 m_op_index
= ((m_op_index
+ adjust
)
19799 % m_line_header
->maximum_ops_per_instruction
);
19803 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
19805 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
19806 CORE_ADDR addr_adj
= (((m_op_index
19807 + (adj_opcode
/ m_line_header
->line_range
))
19808 / m_line_header
->maximum_ops_per_instruction
)
19809 * m_line_header
->minimum_instruction_length
);
19810 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19811 m_op_index
= ((m_op_index
+ (adj_opcode
/ m_line_header
->line_range
))
19812 % m_line_header
->maximum_ops_per_instruction
);
19814 int line_delta
= (m_line_header
->line_base
19815 + (adj_opcode
% m_line_header
->line_range
));
19816 advance_line (line_delta
);
19817 record_line (false);
19818 m_discriminator
= 0;
19822 lnp_state_machine::handle_set_file (file_name_index file
)
19826 const file_entry
*fe
= current_file ();
19828 dwarf2_debug_line_missing_file_complaint ();
19829 else if (m_record_lines_p
)
19831 const char *dir
= fe
->include_dir (m_line_header
);
19833 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
19834 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
19835 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
19840 lnp_state_machine::handle_const_add_pc ()
19843 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
19846 = (((m_op_index
+ adjust
)
19847 / m_line_header
->maximum_ops_per_instruction
)
19848 * m_line_header
->minimum_instruction_length
);
19850 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19851 m_op_index
= ((m_op_index
+ adjust
)
19852 % m_line_header
->maximum_ops_per_instruction
);
19855 /* Return non-zero if we should add LINE to the line number table.
19856 LINE is the line to add, LAST_LINE is the last line that was added,
19857 LAST_SUBFILE is the subfile for LAST_LINE.
19858 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
19859 had a non-zero discriminator.
19861 We have to be careful in the presence of discriminators.
19862 E.g., for this line:
19864 for (i = 0; i < 100000; i++);
19866 clang can emit four line number entries for that one line,
19867 each with a different discriminator.
19868 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
19870 However, we want gdb to coalesce all four entries into one.
19871 Otherwise the user could stepi into the middle of the line and
19872 gdb would get confused about whether the pc really was in the
19873 middle of the line.
19875 Things are further complicated by the fact that two consecutive
19876 line number entries for the same line is a heuristic used by gcc
19877 to denote the end of the prologue. So we can't just discard duplicate
19878 entries, we have to be selective about it. The heuristic we use is
19879 that we only collapse consecutive entries for the same line if at least
19880 one of those entries has a non-zero discriminator. PR 17276.
19882 Note: Addresses in the line number state machine can never go backwards
19883 within one sequence, thus this coalescing is ok. */
19886 dwarf_record_line_p (struct dwarf2_cu
*cu
,
19887 unsigned int line
, unsigned int last_line
,
19888 int line_has_non_zero_discriminator
,
19889 struct subfile
*last_subfile
)
19891 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
19893 if (line
!= last_line
)
19895 /* Same line for the same file that we've seen already.
19896 As a last check, for pr 17276, only record the line if the line
19897 has never had a non-zero discriminator. */
19898 if (!line_has_non_zero_discriminator
)
19903 /* Use the CU's builder to record line number LINE beginning at
19904 address ADDRESS in the line table of subfile SUBFILE. */
19907 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
19908 unsigned int line
, CORE_ADDR address
,
19909 struct dwarf2_cu
*cu
)
19911 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
19913 if (dwarf_line_debug
)
19915 fprintf_unfiltered (gdb_stdlog
,
19916 "Recording line %u, file %s, address %s\n",
19917 line
, lbasename (subfile
->name
),
19918 paddress (gdbarch
, address
));
19922 cu
->get_builder ()->record_line (subfile
, line
, addr
);
19925 /* Subroutine of dwarf_decode_lines_1 to simplify it.
19926 Mark the end of a set of line number records.
19927 The arguments are the same as for dwarf_record_line_1.
19928 If SUBFILE is NULL the request is ignored. */
19931 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
19932 CORE_ADDR address
, struct dwarf2_cu
*cu
)
19934 if (subfile
== NULL
)
19937 if (dwarf_line_debug
)
19939 fprintf_unfiltered (gdb_stdlog
,
19940 "Finishing current line, file %s, address %s\n",
19941 lbasename (subfile
->name
),
19942 paddress (gdbarch
, address
));
19945 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, cu
);
19949 lnp_state_machine::record_line (bool end_sequence
)
19951 if (dwarf_line_debug
)
19953 fprintf_unfiltered (gdb_stdlog
,
19954 "Processing actual line %u: file %u,"
19955 " address %s, is_stmt %u, discrim %u%s\n",
19957 paddress (m_gdbarch
, m_address
),
19958 m_is_stmt
, m_discriminator
,
19959 (end_sequence
? "\t(end sequence)" : ""));
19962 file_entry
*fe
= current_file ();
19965 dwarf2_debug_line_missing_file_complaint ();
19966 /* For now we ignore lines not starting on an instruction boundary.
19967 But not when processing end_sequence for compatibility with the
19968 previous version of the code. */
19969 else if (m_op_index
== 0 || end_sequence
)
19971 fe
->included_p
= 1;
19972 if (m_record_lines_p
19973 && (producer_is_codewarrior (m_cu
) || m_is_stmt
|| end_sequence
))
19975 if (m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ()
19978 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
19979 m_currently_recording_lines
? m_cu
: nullptr);
19984 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
19985 m_line_has_non_zero_discriminator
,
19988 buildsym_compunit
*builder
= m_cu
->get_builder ();
19989 dwarf_record_line_1 (m_gdbarch
,
19990 builder
->get_current_subfile (),
19992 m_currently_recording_lines
? m_cu
: nullptr);
19994 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
19995 m_last_line
= m_line
;
20001 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
20002 line_header
*lh
, bool record_lines_p
)
20006 m_record_lines_p
= record_lines_p
;
20007 m_line_header
= lh
;
20009 m_currently_recording_lines
= true;
20011 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
20012 was a line entry for it so that the backend has a chance to adjust it
20013 and also record it in case it needs it. This is currently used by MIPS
20014 code, cf. `mips_adjust_dwarf2_line'. */
20015 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
20016 m_is_stmt
= lh
->default_is_stmt
;
20017 m_discriminator
= 0;
20021 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
20022 const gdb_byte
*line_ptr
,
20023 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
20025 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
20026 the pc range of the CU. However, we restrict the test to only ADDRESS
20027 values of zero to preserve GDB's previous behaviour which is to handle
20028 the specific case of a function being GC'd by the linker. */
20030 if (address
== 0 && address
< unrelocated_lowpc
)
20032 /* This line table is for a function which has been
20033 GCd by the linker. Ignore it. PR gdb/12528 */
20035 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20036 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
20038 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
20039 line_offset
, objfile_name (objfile
));
20040 m_currently_recording_lines
= false;
20041 /* Note: m_currently_recording_lines is left as false until we see
20042 DW_LNE_end_sequence. */
20046 /* Subroutine of dwarf_decode_lines to simplify it.
20047 Process the line number information in LH.
20048 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
20049 program in order to set included_p for every referenced header. */
20052 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
20053 const int decode_for_pst_p
, CORE_ADDR lowpc
)
20055 const gdb_byte
*line_ptr
, *extended_end
;
20056 const gdb_byte
*line_end
;
20057 unsigned int bytes_read
, extended_len
;
20058 unsigned char op_code
, extended_op
;
20059 CORE_ADDR baseaddr
;
20060 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20061 bfd
*abfd
= objfile
->obfd
;
20062 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
20063 /* True if we're recording line info (as opposed to building partial
20064 symtabs and just interested in finding include files mentioned by
20065 the line number program). */
20066 bool record_lines_p
= !decode_for_pst_p
;
20068 baseaddr
= objfile
->text_section_offset ();
20070 line_ptr
= lh
->statement_program_start
;
20071 line_end
= lh
->statement_program_end
;
20073 /* Read the statement sequences until there's nothing left. */
20074 while (line_ptr
< line_end
)
20076 /* The DWARF line number program state machine. Reset the state
20077 machine at the start of each sequence. */
20078 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
20079 bool end_sequence
= false;
20081 if (record_lines_p
)
20083 /* Start a subfile for the current file of the state
20085 const file_entry
*fe
= state_machine
.current_file ();
20088 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
20091 /* Decode the table. */
20092 while (line_ptr
< line_end
&& !end_sequence
)
20094 op_code
= read_1_byte (abfd
, line_ptr
);
20097 if (op_code
>= lh
->opcode_base
)
20099 /* Special opcode. */
20100 state_machine
.handle_special_opcode (op_code
);
20102 else switch (op_code
)
20104 case DW_LNS_extended_op
:
20105 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
20107 line_ptr
+= bytes_read
;
20108 extended_end
= line_ptr
+ extended_len
;
20109 extended_op
= read_1_byte (abfd
, line_ptr
);
20111 switch (extended_op
)
20113 case DW_LNE_end_sequence
:
20114 state_machine
.handle_end_sequence ();
20115 end_sequence
= true;
20117 case DW_LNE_set_address
:
20120 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
20121 line_ptr
+= bytes_read
;
20123 state_machine
.check_line_address (cu
, line_ptr
,
20124 lowpc
- baseaddr
, address
);
20125 state_machine
.handle_set_address (baseaddr
, address
);
20128 case DW_LNE_define_file
:
20130 const char *cur_file
;
20131 unsigned int mod_time
, length
;
20134 cur_file
= read_direct_string (abfd
, line_ptr
,
20136 line_ptr
+= bytes_read
;
20137 dindex
= (dir_index
)
20138 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20139 line_ptr
+= bytes_read
;
20141 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20142 line_ptr
+= bytes_read
;
20144 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20145 line_ptr
+= bytes_read
;
20146 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
20149 case DW_LNE_set_discriminator
:
20151 /* The discriminator is not interesting to the
20152 debugger; just ignore it. We still need to
20153 check its value though:
20154 if there are consecutive entries for the same
20155 (non-prologue) line we want to coalesce them.
20158 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20159 line_ptr
+= bytes_read
;
20161 state_machine
.handle_set_discriminator (discr
);
20165 complaint (_("mangled .debug_line section"));
20168 /* Make sure that we parsed the extended op correctly. If e.g.
20169 we expected a different address size than the producer used,
20170 we may have read the wrong number of bytes. */
20171 if (line_ptr
!= extended_end
)
20173 complaint (_("mangled .debug_line section"));
20178 state_machine
.handle_copy ();
20180 case DW_LNS_advance_pc
:
20183 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20184 line_ptr
+= bytes_read
;
20186 state_machine
.handle_advance_pc (adjust
);
20189 case DW_LNS_advance_line
:
20192 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
20193 line_ptr
+= bytes_read
;
20195 state_machine
.handle_advance_line (line_delta
);
20198 case DW_LNS_set_file
:
20200 file_name_index file
20201 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
20203 line_ptr
+= bytes_read
;
20205 state_machine
.handle_set_file (file
);
20208 case DW_LNS_set_column
:
20209 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20210 line_ptr
+= bytes_read
;
20212 case DW_LNS_negate_stmt
:
20213 state_machine
.handle_negate_stmt ();
20215 case DW_LNS_set_basic_block
:
20217 /* Add to the address register of the state machine the
20218 address increment value corresponding to special opcode
20219 255. I.e., this value is scaled by the minimum
20220 instruction length since special opcode 255 would have
20221 scaled the increment. */
20222 case DW_LNS_const_add_pc
:
20223 state_machine
.handle_const_add_pc ();
20225 case DW_LNS_fixed_advance_pc
:
20227 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
20230 state_machine
.handle_fixed_advance_pc (addr_adj
);
20235 /* Unknown standard opcode, ignore it. */
20238 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
20240 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20241 line_ptr
+= bytes_read
;
20248 dwarf2_debug_line_missing_end_sequence_complaint ();
20250 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
20251 in which case we still finish recording the last line). */
20252 state_machine
.record_line (true);
20256 /* Decode the Line Number Program (LNP) for the given line_header
20257 structure and CU. The actual information extracted and the type
20258 of structures created from the LNP depends on the value of PST.
20260 1. If PST is NULL, then this procedure uses the data from the program
20261 to create all necessary symbol tables, and their linetables.
20263 2. If PST is not NULL, this procedure reads the program to determine
20264 the list of files included by the unit represented by PST, and
20265 builds all the associated partial symbol tables.
20267 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20268 It is used for relative paths in the line table.
20269 NOTE: When processing partial symtabs (pst != NULL),
20270 comp_dir == pst->dirname.
20272 NOTE: It is important that psymtabs have the same file name (via strcmp)
20273 as the corresponding symtab. Since COMP_DIR is not used in the name of the
20274 symtab we don't use it in the name of the psymtabs we create.
20275 E.g. expand_line_sal requires this when finding psymtabs to expand.
20276 A good testcase for this is mb-inline.exp.
20278 LOWPC is the lowest address in CU (or 0 if not known).
20280 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
20281 for its PC<->lines mapping information. Otherwise only the filename
20282 table is read in. */
20285 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
20286 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
20287 CORE_ADDR lowpc
, int decode_mapping
)
20289 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20290 const int decode_for_pst_p
= (pst
!= NULL
);
20292 if (decode_mapping
)
20293 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
20295 if (decode_for_pst_p
)
20297 /* Now that we're done scanning the Line Header Program, we can
20298 create the psymtab of each included file. */
20299 for (auto &file_entry
: lh
->file_names ())
20300 if (file_entry
.included_p
== 1)
20302 gdb::unique_xmalloc_ptr
<char> name_holder
;
20303 const char *include_name
=
20304 psymtab_include_file_name (lh
, file_entry
, pst
,
20305 comp_dir
, &name_holder
);
20306 if (include_name
!= NULL
)
20307 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
20312 /* Make sure a symtab is created for every file, even files
20313 which contain only variables (i.e. no code with associated
20315 buildsym_compunit
*builder
= cu
->get_builder ();
20316 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
20318 for (auto &fe
: lh
->file_names ())
20320 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
20321 if (builder
->get_current_subfile ()->symtab
== NULL
)
20323 builder
->get_current_subfile ()->symtab
20324 = allocate_symtab (cust
,
20325 builder
->get_current_subfile ()->name
);
20327 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
20332 /* Start a subfile for DWARF. FILENAME is the name of the file and
20333 DIRNAME the name of the source directory which contains FILENAME
20334 or NULL if not known.
20335 This routine tries to keep line numbers from identical absolute and
20336 relative file names in a common subfile.
20338 Using the `list' example from the GDB testsuite, which resides in
20339 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
20340 of /srcdir/list0.c yields the following debugging information for list0.c:
20342 DW_AT_name: /srcdir/list0.c
20343 DW_AT_comp_dir: /compdir
20344 files.files[0].name: list0.h
20345 files.files[0].dir: /srcdir
20346 files.files[1].name: list0.c
20347 files.files[1].dir: /srcdir
20349 The line number information for list0.c has to end up in a single
20350 subfile, so that `break /srcdir/list0.c:1' works as expected.
20351 start_subfile will ensure that this happens provided that we pass the
20352 concatenation of files.files[1].dir and files.files[1].name as the
20356 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
20357 const char *dirname
)
20359 gdb::unique_xmalloc_ptr
<char> copy
;
20361 /* In order not to lose the line information directory,
20362 we concatenate it to the filename when it makes sense.
20363 Note that the Dwarf3 standard says (speaking of filenames in line
20364 information): ``The directory index is ignored for file names
20365 that represent full path names''. Thus ignoring dirname in the
20366 `else' branch below isn't an issue. */
20368 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
20370 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
20371 filename
= copy
.get ();
20374 cu
->get_builder ()->start_subfile (filename
);
20377 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
20378 buildsym_compunit constructor. */
20380 struct compunit_symtab
*
20381 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
20384 gdb_assert (m_builder
== nullptr);
20386 m_builder
.reset (new struct buildsym_compunit
20387 (per_cu
->dwarf2_per_objfile
->objfile
,
20388 name
, comp_dir
, language
, low_pc
));
20390 list_in_scope
= get_builder ()->get_file_symbols ();
20392 get_builder ()->record_debugformat ("DWARF 2");
20393 get_builder ()->record_producer (producer
);
20395 processing_has_namespace_info
= false;
20397 return get_builder ()->get_compunit_symtab ();
20401 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
20402 struct dwarf2_cu
*cu
)
20404 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20405 struct comp_unit_head
*cu_header
= &cu
->header
;
20407 /* NOTE drow/2003-01-30: There used to be a comment and some special
20408 code here to turn a symbol with DW_AT_external and a
20409 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
20410 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
20411 with some versions of binutils) where shared libraries could have
20412 relocations against symbols in their debug information - the
20413 minimal symbol would have the right address, but the debug info
20414 would not. It's no longer necessary, because we will explicitly
20415 apply relocations when we read in the debug information now. */
20417 /* A DW_AT_location attribute with no contents indicates that a
20418 variable has been optimized away. */
20419 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0)
20421 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20425 /* Handle one degenerate form of location expression specially, to
20426 preserve GDB's previous behavior when section offsets are
20427 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
20428 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
20430 if (attr
->form_is_block ()
20431 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
20432 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
20433 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
20434 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
20435 && (DW_BLOCK (attr
)->size
20436 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
20438 unsigned int dummy
;
20440 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
20441 SET_SYMBOL_VALUE_ADDRESS
20442 (sym
, cu
->header
.read_address (objfile
->obfd
,
20443 DW_BLOCK (attr
)->data
+ 1,
20446 SET_SYMBOL_VALUE_ADDRESS
20447 (sym
, read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1,
20449 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
20450 fixup_symbol_section (sym
, objfile
);
20451 SET_SYMBOL_VALUE_ADDRESS
20453 SYMBOL_VALUE_ADDRESS (sym
)
20454 + objfile
->section_offsets
[SYMBOL_SECTION (sym
)]);
20458 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
20459 expression evaluator, and use LOC_COMPUTED only when necessary
20460 (i.e. when the value of a register or memory location is
20461 referenced, or a thread-local block, etc.). Then again, it might
20462 not be worthwhile. I'm assuming that it isn't unless performance
20463 or memory numbers show me otherwise. */
20465 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
20467 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
20468 cu
->has_loclist
= true;
20471 /* Given a pointer to a DWARF information entry, figure out if we need
20472 to make a symbol table entry for it, and if so, create a new entry
20473 and return a pointer to it.
20474 If TYPE is NULL, determine symbol type from the die, otherwise
20475 used the passed type.
20476 If SPACE is not NULL, use it to hold the new symbol. If it is
20477 NULL, allocate a new symbol on the objfile's obstack. */
20479 static struct symbol
*
20480 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
20481 struct symbol
*space
)
20483 struct dwarf2_per_objfile
*dwarf2_per_objfile
20484 = cu
->per_cu
->dwarf2_per_objfile
;
20485 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20486 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
20487 struct symbol
*sym
= NULL
;
20489 struct attribute
*attr
= NULL
;
20490 struct attribute
*attr2
= NULL
;
20491 CORE_ADDR baseaddr
;
20492 struct pending
**list_to_add
= NULL
;
20494 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
20496 baseaddr
= objfile
->text_section_offset ();
20498 name
= dwarf2_name (die
, cu
);
20501 const char *linkagename
;
20502 int suppress_add
= 0;
20507 sym
= allocate_symbol (objfile
);
20508 OBJSTAT (objfile
, n_syms
++);
20510 /* Cache this symbol's name and the name's demangled form (if any). */
20511 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
20512 linkagename
= dwarf2_physname (name
, die
, cu
);
20513 sym
->compute_and_set_names (linkagename
, false, objfile
->per_bfd
);
20515 /* Fortran does not have mangling standard and the mangling does differ
20516 between gfortran, iFort etc. */
20517 if (cu
->language
== language_fortran
20518 && symbol_get_demangled_name (sym
) == NULL
)
20519 symbol_set_demangled_name (sym
,
20520 dwarf2_full_name (name
, die
, cu
),
20523 /* Default assumptions.
20524 Use the passed type or decode it from the die. */
20525 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20526 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20528 SYMBOL_TYPE (sym
) = type
;
20530 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
20531 attr
= dwarf2_attr (die
,
20532 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
20534 if (attr
!= nullptr)
20536 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
20539 attr
= dwarf2_attr (die
,
20540 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
20542 if (attr
!= nullptr)
20544 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
20545 struct file_entry
*fe
;
20547 if (cu
->line_header
!= NULL
)
20548 fe
= cu
->line_header
->file_name_at (file_index
);
20553 complaint (_("file index out of range"));
20555 symbol_set_symtab (sym
, fe
->symtab
);
20561 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
20562 if (attr
!= nullptr)
20566 addr
= attr
->value_as_address ();
20567 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
20568 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
20570 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
20571 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
20572 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
20573 add_symbol_to_list (sym
, cu
->list_in_scope
);
20575 case DW_TAG_subprogram
:
20576 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20578 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20579 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20580 if ((attr2
&& (DW_UNSND (attr2
) != 0))
20581 || cu
->language
== language_ada
20582 || cu
->language
== language_fortran
)
20584 /* Subprograms marked external are stored as a global symbol.
20585 Ada and Fortran subprograms, whether marked external or
20586 not, are always stored as a global symbol, because we want
20587 to be able to access them globally. For instance, we want
20588 to be able to break on a nested subprogram without having
20589 to specify the context. */
20590 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20594 list_to_add
= cu
->list_in_scope
;
20597 case DW_TAG_inlined_subroutine
:
20598 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20600 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20601 SYMBOL_INLINED (sym
) = 1;
20602 list_to_add
= cu
->list_in_scope
;
20604 case DW_TAG_template_value_param
:
20606 /* Fall through. */
20607 case DW_TAG_constant
:
20608 case DW_TAG_variable
:
20609 case DW_TAG_member
:
20610 /* Compilation with minimal debug info may result in
20611 variables with missing type entries. Change the
20612 misleading `void' type to something sensible. */
20613 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
20614 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
20616 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20617 /* In the case of DW_TAG_member, we should only be called for
20618 static const members. */
20619 if (die
->tag
== DW_TAG_member
)
20621 /* dwarf2_add_field uses die_is_declaration,
20622 so we do the same. */
20623 gdb_assert (die_is_declaration (die
, cu
));
20626 if (attr
!= nullptr)
20628 dwarf2_const_value (attr
, sym
, cu
);
20629 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20632 if (attr2
&& (DW_UNSND (attr2
) != 0))
20633 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20635 list_to_add
= cu
->list_in_scope
;
20639 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20640 if (attr
!= nullptr)
20642 var_decode_location (attr
, sym
, cu
);
20643 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20645 /* Fortran explicitly imports any global symbols to the local
20646 scope by DW_TAG_common_block. */
20647 if (cu
->language
== language_fortran
&& die
->parent
20648 && die
->parent
->tag
== DW_TAG_common_block
)
20651 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20652 && SYMBOL_VALUE_ADDRESS (sym
) == 0
20653 && !dwarf2_per_objfile
->has_section_at_zero
)
20655 /* When a static variable is eliminated by the linker,
20656 the corresponding debug information is not stripped
20657 out, but the variable address is set to null;
20658 do not add such variables into symbol table. */
20660 else if (attr2
&& (DW_UNSND (attr2
) != 0))
20662 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20663 && (objfile
->flags
& OBJF_MAINLINE
) == 0
20664 && dwarf2_per_objfile
->can_copy
)
20666 /* A global static variable might be subject to
20667 copy relocation. We first check for a local
20668 minsym, though, because maybe the symbol was
20669 marked hidden, in which case this would not
20671 bound_minimal_symbol found
20672 = (lookup_minimal_symbol_linkage
20673 (sym
->linkage_name (), objfile
));
20674 if (found
.minsym
!= nullptr)
20675 sym
->maybe_copied
= 1;
20678 /* A variable with DW_AT_external is never static,
20679 but it may be block-scoped. */
20681 = ((cu
->list_in_scope
20682 == cu
->get_builder ()->get_file_symbols ())
20683 ? cu
->get_builder ()->get_global_symbols ()
20684 : cu
->list_in_scope
);
20687 list_to_add
= cu
->list_in_scope
;
20691 /* We do not know the address of this symbol.
20692 If it is an external symbol and we have type information
20693 for it, enter the symbol as a LOC_UNRESOLVED symbol.
20694 The address of the variable will then be determined from
20695 the minimal symbol table whenever the variable is
20697 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20699 /* Fortran explicitly imports any global symbols to the local
20700 scope by DW_TAG_common_block. */
20701 if (cu
->language
== language_fortran
&& die
->parent
20702 && die
->parent
->tag
== DW_TAG_common_block
)
20704 /* SYMBOL_CLASS doesn't matter here because
20705 read_common_block is going to reset it. */
20707 list_to_add
= cu
->list_in_scope
;
20709 else if (attr2
&& (DW_UNSND (attr2
) != 0)
20710 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
20712 /* A variable with DW_AT_external is never static, but it
20713 may be block-scoped. */
20715 = ((cu
->list_in_scope
20716 == cu
->get_builder ()->get_file_symbols ())
20717 ? cu
->get_builder ()->get_global_symbols ()
20718 : cu
->list_in_scope
);
20720 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
20722 else if (!die_is_declaration (die
, cu
))
20724 /* Use the default LOC_OPTIMIZED_OUT class. */
20725 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
20727 list_to_add
= cu
->list_in_scope
;
20731 case DW_TAG_formal_parameter
:
20733 /* If we are inside a function, mark this as an argument. If
20734 not, we might be looking at an argument to an inlined function
20735 when we do not have enough information to show inlined frames;
20736 pretend it's a local variable in that case so that the user can
20738 struct context_stack
*curr
20739 = cu
->get_builder ()->get_current_context_stack ();
20740 if (curr
!= nullptr && curr
->name
!= nullptr)
20741 SYMBOL_IS_ARGUMENT (sym
) = 1;
20742 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20743 if (attr
!= nullptr)
20745 var_decode_location (attr
, sym
, cu
);
20747 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20748 if (attr
!= nullptr)
20750 dwarf2_const_value (attr
, sym
, cu
);
20753 list_to_add
= cu
->list_in_scope
;
20756 case DW_TAG_unspecified_parameters
:
20757 /* From varargs functions; gdb doesn't seem to have any
20758 interest in this information, so just ignore it for now.
20761 case DW_TAG_template_type_param
:
20763 /* Fall through. */
20764 case DW_TAG_class_type
:
20765 case DW_TAG_interface_type
:
20766 case DW_TAG_structure_type
:
20767 case DW_TAG_union_type
:
20768 case DW_TAG_set_type
:
20769 case DW_TAG_enumeration_type
:
20770 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20771 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
20774 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
20775 really ever be static objects: otherwise, if you try
20776 to, say, break of a class's method and you're in a file
20777 which doesn't mention that class, it won't work unless
20778 the check for all static symbols in lookup_symbol_aux
20779 saves you. See the OtherFileClass tests in
20780 gdb.c++/namespace.exp. */
20784 buildsym_compunit
*builder
= cu
->get_builder ();
20786 = (cu
->list_in_scope
== builder
->get_file_symbols ()
20787 && cu
->language
== language_cplus
20788 ? builder
->get_global_symbols ()
20789 : cu
->list_in_scope
);
20791 /* The semantics of C++ state that "struct foo {
20792 ... }" also defines a typedef for "foo". */
20793 if (cu
->language
== language_cplus
20794 || cu
->language
== language_ada
20795 || cu
->language
== language_d
20796 || cu
->language
== language_rust
)
20798 /* The symbol's name is already allocated along
20799 with this objfile, so we don't need to
20800 duplicate it for the type. */
20801 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
20802 TYPE_NAME (SYMBOL_TYPE (sym
)) = sym
->search_name ();
20807 case DW_TAG_typedef
:
20808 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20809 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20810 list_to_add
= cu
->list_in_scope
;
20812 case DW_TAG_base_type
:
20813 case DW_TAG_subrange_type
:
20814 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20815 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20816 list_to_add
= cu
->list_in_scope
;
20818 case DW_TAG_enumerator
:
20819 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20820 if (attr
!= nullptr)
20822 dwarf2_const_value (attr
, sym
, cu
);
20825 /* NOTE: carlton/2003-11-10: See comment above in the
20826 DW_TAG_class_type, etc. block. */
20829 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
20830 && cu
->language
== language_cplus
20831 ? cu
->get_builder ()->get_global_symbols ()
20832 : cu
->list_in_scope
);
20835 case DW_TAG_imported_declaration
:
20836 case DW_TAG_namespace
:
20837 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20838 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20840 case DW_TAG_module
:
20841 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20842 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
20843 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20845 case DW_TAG_common_block
:
20846 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
20847 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
20848 add_symbol_to_list (sym
, cu
->list_in_scope
);
20851 /* Not a tag we recognize. Hopefully we aren't processing
20852 trash data, but since we must specifically ignore things
20853 we don't recognize, there is nothing else we should do at
20855 complaint (_("unsupported tag: '%s'"),
20856 dwarf_tag_name (die
->tag
));
20862 sym
->hash_next
= objfile
->template_symbols
;
20863 objfile
->template_symbols
= sym
;
20864 list_to_add
= NULL
;
20867 if (list_to_add
!= NULL
)
20868 add_symbol_to_list (sym
, list_to_add
);
20870 /* For the benefit of old versions of GCC, check for anonymous
20871 namespaces based on the demangled name. */
20872 if (!cu
->processing_has_namespace_info
20873 && cu
->language
== language_cplus
)
20874 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
20879 /* Given an attr with a DW_FORM_dataN value in host byte order,
20880 zero-extend it as appropriate for the symbol's type. The DWARF
20881 standard (v4) is not entirely clear about the meaning of using
20882 DW_FORM_dataN for a constant with a signed type, where the type is
20883 wider than the data. The conclusion of a discussion on the DWARF
20884 list was that this is unspecified. We choose to always zero-extend
20885 because that is the interpretation long in use by GCC. */
20888 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
20889 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
20891 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20892 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
20893 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
20894 LONGEST l
= DW_UNSND (attr
);
20896 if (bits
< sizeof (*value
) * 8)
20898 l
&= ((LONGEST
) 1 << bits
) - 1;
20901 else if (bits
== sizeof (*value
) * 8)
20905 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
20906 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
20913 /* Read a constant value from an attribute. Either set *VALUE, or if
20914 the value does not fit in *VALUE, set *BYTES - either already
20915 allocated on the objfile obstack, or newly allocated on OBSTACK,
20916 or, set *BATON, if we translated the constant to a location
20920 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
20921 const char *name
, struct obstack
*obstack
,
20922 struct dwarf2_cu
*cu
,
20923 LONGEST
*value
, const gdb_byte
**bytes
,
20924 struct dwarf2_locexpr_baton
**baton
)
20926 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20927 struct comp_unit_head
*cu_header
= &cu
->header
;
20928 struct dwarf_block
*blk
;
20929 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
20930 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
20936 switch (attr
->form
)
20939 case DW_FORM_addrx
:
20940 case DW_FORM_GNU_addr_index
:
20944 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
20945 dwarf2_const_value_length_mismatch_complaint (name
,
20946 cu_header
->addr_size
,
20947 TYPE_LENGTH (type
));
20948 /* Symbols of this form are reasonably rare, so we just
20949 piggyback on the existing location code rather than writing
20950 a new implementation of symbol_computed_ops. */
20951 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
20952 (*baton
)->per_cu
= cu
->per_cu
;
20953 gdb_assert ((*baton
)->per_cu
);
20955 (*baton
)->size
= 2 + cu_header
->addr_size
;
20956 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
20957 (*baton
)->data
= data
;
20959 data
[0] = DW_OP_addr
;
20960 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
20961 byte_order
, DW_ADDR (attr
));
20962 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
20965 case DW_FORM_string
:
20968 case DW_FORM_GNU_str_index
:
20969 case DW_FORM_GNU_strp_alt
:
20970 /* DW_STRING is already allocated on the objfile obstack, point
20972 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
20974 case DW_FORM_block1
:
20975 case DW_FORM_block2
:
20976 case DW_FORM_block4
:
20977 case DW_FORM_block
:
20978 case DW_FORM_exprloc
:
20979 case DW_FORM_data16
:
20980 blk
= DW_BLOCK (attr
);
20981 if (TYPE_LENGTH (type
) != blk
->size
)
20982 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
20983 TYPE_LENGTH (type
));
20984 *bytes
= blk
->data
;
20987 /* The DW_AT_const_value attributes are supposed to carry the
20988 symbol's value "represented as it would be on the target
20989 architecture." By the time we get here, it's already been
20990 converted to host endianness, so we just need to sign- or
20991 zero-extend it as appropriate. */
20992 case DW_FORM_data1
:
20993 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
20995 case DW_FORM_data2
:
20996 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
20998 case DW_FORM_data4
:
20999 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
21001 case DW_FORM_data8
:
21002 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
21005 case DW_FORM_sdata
:
21006 case DW_FORM_implicit_const
:
21007 *value
= DW_SND (attr
);
21010 case DW_FORM_udata
:
21011 *value
= DW_UNSND (attr
);
21015 complaint (_("unsupported const value attribute form: '%s'"),
21016 dwarf_form_name (attr
->form
));
21023 /* Copy constant value from an attribute to a symbol. */
21026 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
21027 struct dwarf2_cu
*cu
)
21029 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21031 const gdb_byte
*bytes
;
21032 struct dwarf2_locexpr_baton
*baton
;
21034 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
21035 sym
->print_name (),
21036 &objfile
->objfile_obstack
, cu
,
21037 &value
, &bytes
, &baton
);
21041 SYMBOL_LOCATION_BATON (sym
) = baton
;
21042 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
21044 else if (bytes
!= NULL
)
21046 SYMBOL_VALUE_BYTES (sym
) = bytes
;
21047 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
21051 SYMBOL_VALUE (sym
) = value
;
21052 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
21056 /* Return the type of the die in question using its DW_AT_type attribute. */
21058 static struct type
*
21059 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21061 struct attribute
*type_attr
;
21063 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
21066 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21067 /* A missing DW_AT_type represents a void type. */
21068 return objfile_type (objfile
)->builtin_void
;
21071 return lookup_die_type (die
, type_attr
, cu
);
21074 /* True iff CU's producer generates GNAT Ada auxiliary information
21075 that allows to find parallel types through that information instead
21076 of having to do expensive parallel lookups by type name. */
21079 need_gnat_info (struct dwarf2_cu
*cu
)
21081 /* Assume that the Ada compiler was GNAT, which always produces
21082 the auxiliary information. */
21083 return (cu
->language
== language_ada
);
21086 /* Return the auxiliary type of the die in question using its
21087 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
21088 attribute is not present. */
21090 static struct type
*
21091 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21093 struct attribute
*type_attr
;
21095 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
21099 return lookup_die_type (die
, type_attr
, cu
);
21102 /* If DIE has a descriptive_type attribute, then set the TYPE's
21103 descriptive type accordingly. */
21106 set_descriptive_type (struct type
*type
, struct die_info
*die
,
21107 struct dwarf2_cu
*cu
)
21109 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
21111 if (descriptive_type
)
21113 ALLOCATE_GNAT_AUX_TYPE (type
);
21114 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
21118 /* Return the containing type of the die in question using its
21119 DW_AT_containing_type attribute. */
21121 static struct type
*
21122 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21124 struct attribute
*type_attr
;
21125 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21127 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
21129 error (_("Dwarf Error: Problem turning containing type into gdb type "
21130 "[in module %s]"), objfile_name (objfile
));
21132 return lookup_die_type (die
, type_attr
, cu
);
21135 /* Return an error marker type to use for the ill formed type in DIE/CU. */
21137 static struct type
*
21138 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
21140 struct dwarf2_per_objfile
*dwarf2_per_objfile
21141 = cu
->per_cu
->dwarf2_per_objfile
;
21142 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21145 std::string message
21146 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
21147 objfile_name (objfile
),
21148 sect_offset_str (cu
->header
.sect_off
),
21149 sect_offset_str (die
->sect_off
));
21150 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
21152 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
21155 /* Look up the type of DIE in CU using its type attribute ATTR.
21156 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
21157 DW_AT_containing_type.
21158 If there is no type substitute an error marker. */
21160 static struct type
*
21161 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
21162 struct dwarf2_cu
*cu
)
21164 struct dwarf2_per_objfile
*dwarf2_per_objfile
21165 = cu
->per_cu
->dwarf2_per_objfile
;
21166 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21167 struct type
*this_type
;
21169 gdb_assert (attr
->name
== DW_AT_type
21170 || attr
->name
== DW_AT_GNAT_descriptive_type
21171 || attr
->name
== DW_AT_containing_type
);
21173 /* First see if we have it cached. */
21175 if (attr
->form
== DW_FORM_GNU_ref_alt
)
21177 struct dwarf2_per_cu_data
*per_cu
;
21178 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
21180 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
21181 dwarf2_per_objfile
);
21182 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
21184 else if (attr
->form_is_ref ())
21186 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
21188 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
21190 else if (attr
->form
== DW_FORM_ref_sig8
)
21192 ULONGEST signature
= DW_SIGNATURE (attr
);
21194 return get_signatured_type (die
, signature
, cu
);
21198 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
21199 " at %s [in module %s]"),
21200 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
21201 objfile_name (objfile
));
21202 return build_error_marker_type (cu
, die
);
21205 /* If not cached we need to read it in. */
21207 if (this_type
== NULL
)
21209 struct die_info
*type_die
= NULL
;
21210 struct dwarf2_cu
*type_cu
= cu
;
21212 if (attr
->form_is_ref ())
21213 type_die
= follow_die_ref (die
, attr
, &type_cu
);
21214 if (type_die
== NULL
)
21215 return build_error_marker_type (cu
, die
);
21216 /* If we find the type now, it's probably because the type came
21217 from an inter-CU reference and the type's CU got expanded before
21219 this_type
= read_type_die (type_die
, type_cu
);
21222 /* If we still don't have a type use an error marker. */
21224 if (this_type
== NULL
)
21225 return build_error_marker_type (cu
, die
);
21230 /* Return the type in DIE, CU.
21231 Returns NULL for invalid types.
21233 This first does a lookup in die_type_hash,
21234 and only reads the die in if necessary.
21236 NOTE: This can be called when reading in partial or full symbols. */
21238 static struct type
*
21239 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
21241 struct type
*this_type
;
21243 this_type
= get_die_type (die
, cu
);
21247 return read_type_die_1 (die
, cu
);
21250 /* Read the type in DIE, CU.
21251 Returns NULL for invalid types. */
21253 static struct type
*
21254 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
21256 struct type
*this_type
= NULL
;
21260 case DW_TAG_class_type
:
21261 case DW_TAG_interface_type
:
21262 case DW_TAG_structure_type
:
21263 case DW_TAG_union_type
:
21264 this_type
= read_structure_type (die
, cu
);
21266 case DW_TAG_enumeration_type
:
21267 this_type
= read_enumeration_type (die
, cu
);
21269 case DW_TAG_subprogram
:
21270 case DW_TAG_subroutine_type
:
21271 case DW_TAG_inlined_subroutine
:
21272 this_type
= read_subroutine_type (die
, cu
);
21274 case DW_TAG_array_type
:
21275 this_type
= read_array_type (die
, cu
);
21277 case DW_TAG_set_type
:
21278 this_type
= read_set_type (die
, cu
);
21280 case DW_TAG_pointer_type
:
21281 this_type
= read_tag_pointer_type (die
, cu
);
21283 case DW_TAG_ptr_to_member_type
:
21284 this_type
= read_tag_ptr_to_member_type (die
, cu
);
21286 case DW_TAG_reference_type
:
21287 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
21289 case DW_TAG_rvalue_reference_type
:
21290 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
21292 case DW_TAG_const_type
:
21293 this_type
= read_tag_const_type (die
, cu
);
21295 case DW_TAG_volatile_type
:
21296 this_type
= read_tag_volatile_type (die
, cu
);
21298 case DW_TAG_restrict_type
:
21299 this_type
= read_tag_restrict_type (die
, cu
);
21301 case DW_TAG_string_type
:
21302 this_type
= read_tag_string_type (die
, cu
);
21304 case DW_TAG_typedef
:
21305 this_type
= read_typedef (die
, cu
);
21307 case DW_TAG_subrange_type
:
21308 this_type
= read_subrange_type (die
, cu
);
21310 case DW_TAG_base_type
:
21311 this_type
= read_base_type (die
, cu
);
21313 case DW_TAG_unspecified_type
:
21314 this_type
= read_unspecified_type (die
, cu
);
21316 case DW_TAG_namespace
:
21317 this_type
= read_namespace_type (die
, cu
);
21319 case DW_TAG_module
:
21320 this_type
= read_module_type (die
, cu
);
21322 case DW_TAG_atomic_type
:
21323 this_type
= read_tag_atomic_type (die
, cu
);
21326 complaint (_("unexpected tag in read_type_die: '%s'"),
21327 dwarf_tag_name (die
->tag
));
21334 /* See if we can figure out if the class lives in a namespace. We do
21335 this by looking for a member function; its demangled name will
21336 contain namespace info, if there is any.
21337 Return the computed name or NULL.
21338 Space for the result is allocated on the objfile's obstack.
21339 This is the full-die version of guess_partial_die_structure_name.
21340 In this case we know DIE has no useful parent. */
21342 static const char *
21343 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21345 struct die_info
*spec_die
;
21346 struct dwarf2_cu
*spec_cu
;
21347 struct die_info
*child
;
21348 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21351 spec_die
= die_specification (die
, &spec_cu
);
21352 if (spec_die
!= NULL
)
21358 for (child
= die
->child
;
21360 child
= child
->sibling
)
21362 if (child
->tag
== DW_TAG_subprogram
)
21364 const char *linkage_name
= dw2_linkage_name (child
, cu
);
21366 if (linkage_name
!= NULL
)
21368 gdb::unique_xmalloc_ptr
<char> actual_name
21369 (language_class_name_from_physname (cu
->language_defn
,
21371 const char *name
= NULL
;
21373 if (actual_name
!= NULL
)
21375 const char *die_name
= dwarf2_name (die
, cu
);
21377 if (die_name
!= NULL
21378 && strcmp (die_name
, actual_name
.get ()) != 0)
21380 /* Strip off the class name from the full name.
21381 We want the prefix. */
21382 int die_name_len
= strlen (die_name
);
21383 int actual_name_len
= strlen (actual_name
.get ());
21384 const char *ptr
= actual_name
.get ();
21386 /* Test for '::' as a sanity check. */
21387 if (actual_name_len
> die_name_len
+ 2
21388 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
21389 name
= obstack_strndup (
21390 &objfile
->per_bfd
->storage_obstack
,
21391 ptr
, actual_name_len
- die_name_len
- 2);
21402 /* GCC might emit a nameless typedef that has a linkage name. Determine the
21403 prefix part in such case. See
21404 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21406 static const char *
21407 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21409 struct attribute
*attr
;
21412 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
21413 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
21416 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
21419 attr
= dw2_linkage_name_attr (die
, cu
);
21420 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21423 /* dwarf2_name had to be already called. */
21424 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
21426 /* Strip the base name, keep any leading namespaces/classes. */
21427 base
= strrchr (DW_STRING (attr
), ':');
21428 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
21431 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21432 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
21434 &base
[-1] - DW_STRING (attr
));
21437 /* Return the name of the namespace/class that DIE is defined within,
21438 or "" if we can't tell. The caller should not xfree the result.
21440 For example, if we're within the method foo() in the following
21450 then determine_prefix on foo's die will return "N::C". */
21452 static const char *
21453 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21455 struct dwarf2_per_objfile
*dwarf2_per_objfile
21456 = cu
->per_cu
->dwarf2_per_objfile
;
21457 struct die_info
*parent
, *spec_die
;
21458 struct dwarf2_cu
*spec_cu
;
21459 struct type
*parent_type
;
21460 const char *retval
;
21462 if (cu
->language
!= language_cplus
21463 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
21464 && cu
->language
!= language_rust
)
21467 retval
= anonymous_struct_prefix (die
, cu
);
21471 /* We have to be careful in the presence of DW_AT_specification.
21472 For example, with GCC 3.4, given the code
21476 // Definition of N::foo.
21480 then we'll have a tree of DIEs like this:
21482 1: DW_TAG_compile_unit
21483 2: DW_TAG_namespace // N
21484 3: DW_TAG_subprogram // declaration of N::foo
21485 4: DW_TAG_subprogram // definition of N::foo
21486 DW_AT_specification // refers to die #3
21488 Thus, when processing die #4, we have to pretend that we're in
21489 the context of its DW_AT_specification, namely the contex of die
21492 spec_die
= die_specification (die
, &spec_cu
);
21493 if (spec_die
== NULL
)
21494 parent
= die
->parent
;
21497 parent
= spec_die
->parent
;
21501 if (parent
== NULL
)
21503 else if (parent
->building_fullname
)
21506 const char *parent_name
;
21508 /* It has been seen on RealView 2.2 built binaries,
21509 DW_TAG_template_type_param types actually _defined_ as
21510 children of the parent class:
21513 template class <class Enum> Class{};
21514 Class<enum E> class_e;
21516 1: DW_TAG_class_type (Class)
21517 2: DW_TAG_enumeration_type (E)
21518 3: DW_TAG_enumerator (enum1:0)
21519 3: DW_TAG_enumerator (enum2:1)
21521 2: DW_TAG_template_type_param
21522 DW_AT_type DW_FORM_ref_udata (E)
21524 Besides being broken debug info, it can put GDB into an
21525 infinite loop. Consider:
21527 When we're building the full name for Class<E>, we'll start
21528 at Class, and go look over its template type parameters,
21529 finding E. We'll then try to build the full name of E, and
21530 reach here. We're now trying to build the full name of E,
21531 and look over the parent DIE for containing scope. In the
21532 broken case, if we followed the parent DIE of E, we'd again
21533 find Class, and once again go look at its template type
21534 arguments, etc., etc. Simply don't consider such parent die
21535 as source-level parent of this die (it can't be, the language
21536 doesn't allow it), and break the loop here. */
21537 name
= dwarf2_name (die
, cu
);
21538 parent_name
= dwarf2_name (parent
, cu
);
21539 complaint (_("template param type '%s' defined within parent '%s'"),
21540 name
? name
: "<unknown>",
21541 parent_name
? parent_name
: "<unknown>");
21545 switch (parent
->tag
)
21547 case DW_TAG_namespace
:
21548 parent_type
= read_type_die (parent
, cu
);
21549 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
21550 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
21551 Work around this problem here. */
21552 if (cu
->language
== language_cplus
21553 && strcmp (TYPE_NAME (parent_type
), "::") == 0)
21555 /* We give a name to even anonymous namespaces. */
21556 return TYPE_NAME (parent_type
);
21557 case DW_TAG_class_type
:
21558 case DW_TAG_interface_type
:
21559 case DW_TAG_structure_type
:
21560 case DW_TAG_union_type
:
21561 case DW_TAG_module
:
21562 parent_type
= read_type_die (parent
, cu
);
21563 if (TYPE_NAME (parent_type
) != NULL
)
21564 return TYPE_NAME (parent_type
);
21566 /* An anonymous structure is only allowed non-static data
21567 members; no typedefs, no member functions, et cetera.
21568 So it does not need a prefix. */
21570 case DW_TAG_compile_unit
:
21571 case DW_TAG_partial_unit
:
21572 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
21573 if (cu
->language
== language_cplus
21574 && !dwarf2_per_objfile
->types
.empty ()
21575 && die
->child
!= NULL
21576 && (die
->tag
== DW_TAG_class_type
21577 || die
->tag
== DW_TAG_structure_type
21578 || die
->tag
== DW_TAG_union_type
))
21580 const char *name
= guess_full_die_structure_name (die
, cu
);
21585 case DW_TAG_subprogram
:
21586 /* Nested subroutines in Fortran get a prefix with the name
21587 of the parent's subroutine. */
21588 if (cu
->language
== language_fortran
)
21590 if ((die
->tag
== DW_TAG_subprogram
)
21591 && (dwarf2_name (parent
, cu
) != NULL
))
21592 return dwarf2_name (parent
, cu
);
21594 return determine_prefix (parent
, cu
);
21595 case DW_TAG_enumeration_type
:
21596 parent_type
= read_type_die (parent
, cu
);
21597 if (TYPE_DECLARED_CLASS (parent_type
))
21599 if (TYPE_NAME (parent_type
) != NULL
)
21600 return TYPE_NAME (parent_type
);
21603 /* Fall through. */
21605 return determine_prefix (parent
, cu
);
21609 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
21610 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
21611 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
21612 an obconcat, otherwise allocate storage for the result. The CU argument is
21613 used to determine the language and hence, the appropriate separator. */
21615 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
21618 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
21619 int physname
, struct dwarf2_cu
*cu
)
21621 const char *lead
= "";
21624 if (suffix
== NULL
|| suffix
[0] == '\0'
21625 || prefix
== NULL
|| prefix
[0] == '\0')
21627 else if (cu
->language
== language_d
)
21629 /* For D, the 'main' function could be defined in any module, but it
21630 should never be prefixed. */
21631 if (strcmp (suffix
, "D main") == 0)
21639 else if (cu
->language
== language_fortran
&& physname
)
21641 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
21642 DW_AT_MIPS_linkage_name is preferred and used instead. */
21650 if (prefix
== NULL
)
21652 if (suffix
== NULL
)
21659 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
21661 strcpy (retval
, lead
);
21662 strcat (retval
, prefix
);
21663 strcat (retval
, sep
);
21664 strcat (retval
, suffix
);
21669 /* We have an obstack. */
21670 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
21674 /* Return sibling of die, NULL if no sibling. */
21676 static struct die_info
*
21677 sibling_die (struct die_info
*die
)
21679 return die
->sibling
;
21682 /* Get name of a die, return NULL if not found. */
21684 static const char *
21685 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
21686 struct obstack
*obstack
)
21688 if (name
&& cu
->language
== language_cplus
)
21690 std::string canon_name
= cp_canonicalize_string (name
);
21692 if (!canon_name
.empty ())
21694 if (canon_name
!= name
)
21695 name
= obstack_strdup (obstack
, canon_name
);
21702 /* Get name of a die, return NULL if not found.
21703 Anonymous namespaces are converted to their magic string. */
21705 static const char *
21706 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21708 struct attribute
*attr
;
21709 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21711 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
21712 if ((!attr
|| !DW_STRING (attr
))
21713 && die
->tag
!= DW_TAG_namespace
21714 && die
->tag
!= DW_TAG_class_type
21715 && die
->tag
!= DW_TAG_interface_type
21716 && die
->tag
!= DW_TAG_structure_type
21717 && die
->tag
!= DW_TAG_union_type
)
21722 case DW_TAG_compile_unit
:
21723 case DW_TAG_partial_unit
:
21724 /* Compilation units have a DW_AT_name that is a filename, not
21725 a source language identifier. */
21726 case DW_TAG_enumeration_type
:
21727 case DW_TAG_enumerator
:
21728 /* These tags always have simple identifiers already; no need
21729 to canonicalize them. */
21730 return DW_STRING (attr
);
21732 case DW_TAG_namespace
:
21733 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
21734 return DW_STRING (attr
);
21735 return CP_ANONYMOUS_NAMESPACE_STR
;
21737 case DW_TAG_class_type
:
21738 case DW_TAG_interface_type
:
21739 case DW_TAG_structure_type
:
21740 case DW_TAG_union_type
:
21741 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
21742 structures or unions. These were of the form "._%d" in GCC 4.1,
21743 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
21744 and GCC 4.4. We work around this problem by ignoring these. */
21745 if (attr
&& DW_STRING (attr
)
21746 && (startswith (DW_STRING (attr
), "._")
21747 || startswith (DW_STRING (attr
), "<anonymous")))
21750 /* GCC might emit a nameless typedef that has a linkage name. See
21751 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21752 if (!attr
|| DW_STRING (attr
) == NULL
)
21754 attr
= dw2_linkage_name_attr (die
, cu
);
21755 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21758 /* Avoid demangling DW_STRING (attr) the second time on a second
21759 call for the same DIE. */
21760 if (!DW_STRING_IS_CANONICAL (attr
))
21762 gdb::unique_xmalloc_ptr
<char> demangled
21763 (gdb_demangle (DW_STRING (attr
), DMGL_TYPES
));
21767 /* FIXME: we already did this for the partial symbol... */
21769 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
21771 DW_STRING_IS_CANONICAL (attr
) = 1;
21773 /* Strip any leading namespaces/classes, keep only the base name.
21774 DW_AT_name for named DIEs does not contain the prefixes. */
21775 base
= strrchr (DW_STRING (attr
), ':');
21776 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
21779 return DW_STRING (attr
);
21788 if (!DW_STRING_IS_CANONICAL (attr
))
21791 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
21792 &objfile
->per_bfd
->storage_obstack
);
21793 DW_STRING_IS_CANONICAL (attr
) = 1;
21795 return DW_STRING (attr
);
21798 /* Return the die that this die in an extension of, or NULL if there
21799 is none. *EXT_CU is the CU containing DIE on input, and the CU
21800 containing the return value on output. */
21802 static struct die_info
*
21803 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
21805 struct attribute
*attr
;
21807 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
21811 return follow_die_ref (die
, attr
, ext_cu
);
21814 /* A convenience function that returns an "unknown" DWARF name,
21815 including the value of V. STR is the name of the entity being
21816 printed, e.g., "TAG". */
21818 static const char *
21819 dwarf_unknown (const char *str
, unsigned v
)
21821 char *cell
= get_print_cell ();
21822 xsnprintf (cell
, PRINT_CELL_SIZE
, "DW_%s_<unknown: %u>", str
, v
);
21826 /* Convert a DIE tag into its string name. */
21828 static const char *
21829 dwarf_tag_name (unsigned tag
)
21831 const char *name
= get_DW_TAG_name (tag
);
21834 return dwarf_unknown ("TAG", tag
);
21839 /* Convert a DWARF attribute code into its string name. */
21841 static const char *
21842 dwarf_attr_name (unsigned attr
)
21846 #ifdef MIPS /* collides with DW_AT_HP_block_index */
21847 if (attr
== DW_AT_MIPS_fde
)
21848 return "DW_AT_MIPS_fde";
21850 if (attr
== DW_AT_HP_block_index
)
21851 return "DW_AT_HP_block_index";
21854 name
= get_DW_AT_name (attr
);
21857 return dwarf_unknown ("AT", attr
);
21862 /* Convert a DWARF value form code into its string name. */
21864 static const char *
21865 dwarf_form_name (unsigned form
)
21867 const char *name
= get_DW_FORM_name (form
);
21870 return dwarf_unknown ("FORM", form
);
21875 static const char *
21876 dwarf_bool_name (unsigned mybool
)
21884 /* Convert a DWARF type code into its string name. */
21886 static const char *
21887 dwarf_type_encoding_name (unsigned enc
)
21889 const char *name
= get_DW_ATE_name (enc
);
21892 return dwarf_unknown ("ATE", enc
);
21898 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
21902 print_spaces (indent
, f
);
21903 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
21904 dwarf_tag_name (die
->tag
), die
->abbrev
,
21905 sect_offset_str (die
->sect_off
));
21907 if (die
->parent
!= NULL
)
21909 print_spaces (indent
, f
);
21910 fprintf_unfiltered (f
, " parent at offset: %s\n",
21911 sect_offset_str (die
->parent
->sect_off
));
21914 print_spaces (indent
, f
);
21915 fprintf_unfiltered (f
, " has children: %s\n",
21916 dwarf_bool_name (die
->child
!= NULL
));
21918 print_spaces (indent
, f
);
21919 fprintf_unfiltered (f
, " attributes:\n");
21921 for (i
= 0; i
< die
->num_attrs
; ++i
)
21923 print_spaces (indent
, f
);
21924 fprintf_unfiltered (f
, " %s (%s) ",
21925 dwarf_attr_name (die
->attrs
[i
].name
),
21926 dwarf_form_name (die
->attrs
[i
].form
));
21928 switch (die
->attrs
[i
].form
)
21931 case DW_FORM_addrx
:
21932 case DW_FORM_GNU_addr_index
:
21933 fprintf_unfiltered (f
, "address: ");
21934 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
21936 case DW_FORM_block2
:
21937 case DW_FORM_block4
:
21938 case DW_FORM_block
:
21939 case DW_FORM_block1
:
21940 fprintf_unfiltered (f
, "block: size %s",
21941 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
21943 case DW_FORM_exprloc
:
21944 fprintf_unfiltered (f
, "expression: size %s",
21945 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
21947 case DW_FORM_data16
:
21948 fprintf_unfiltered (f
, "constant of 16 bytes");
21950 case DW_FORM_ref_addr
:
21951 fprintf_unfiltered (f
, "ref address: ");
21952 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
21954 case DW_FORM_GNU_ref_alt
:
21955 fprintf_unfiltered (f
, "alt ref address: ");
21956 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
21962 case DW_FORM_ref_udata
:
21963 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
21964 (long) (DW_UNSND (&die
->attrs
[i
])));
21966 case DW_FORM_data1
:
21967 case DW_FORM_data2
:
21968 case DW_FORM_data4
:
21969 case DW_FORM_data8
:
21970 case DW_FORM_udata
:
21971 case DW_FORM_sdata
:
21972 fprintf_unfiltered (f
, "constant: %s",
21973 pulongest (DW_UNSND (&die
->attrs
[i
])));
21975 case DW_FORM_sec_offset
:
21976 fprintf_unfiltered (f
, "section offset: %s",
21977 pulongest (DW_UNSND (&die
->attrs
[i
])));
21979 case DW_FORM_ref_sig8
:
21980 fprintf_unfiltered (f
, "signature: %s",
21981 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
21983 case DW_FORM_string
:
21985 case DW_FORM_line_strp
:
21987 case DW_FORM_GNU_str_index
:
21988 case DW_FORM_GNU_strp_alt
:
21989 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
21990 DW_STRING (&die
->attrs
[i
])
21991 ? DW_STRING (&die
->attrs
[i
]) : "",
21992 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
21995 if (DW_UNSND (&die
->attrs
[i
]))
21996 fprintf_unfiltered (f
, "flag: TRUE");
21998 fprintf_unfiltered (f
, "flag: FALSE");
22000 case DW_FORM_flag_present
:
22001 fprintf_unfiltered (f
, "flag: TRUE");
22003 case DW_FORM_indirect
:
22004 /* The reader will have reduced the indirect form to
22005 the "base form" so this form should not occur. */
22006 fprintf_unfiltered (f
,
22007 "unexpected attribute form: DW_FORM_indirect");
22009 case DW_FORM_implicit_const
:
22010 fprintf_unfiltered (f
, "constant: %s",
22011 plongest (DW_SND (&die
->attrs
[i
])));
22014 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
22015 die
->attrs
[i
].form
);
22018 fprintf_unfiltered (f
, "\n");
22023 dump_die_for_error (struct die_info
*die
)
22025 dump_die_shallow (gdb_stderr
, 0, die
);
22029 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
22031 int indent
= level
* 4;
22033 gdb_assert (die
!= NULL
);
22035 if (level
>= max_level
)
22038 dump_die_shallow (f
, indent
, die
);
22040 if (die
->child
!= NULL
)
22042 print_spaces (indent
, f
);
22043 fprintf_unfiltered (f
, " Children:");
22044 if (level
+ 1 < max_level
)
22046 fprintf_unfiltered (f
, "\n");
22047 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
22051 fprintf_unfiltered (f
,
22052 " [not printed, max nesting level reached]\n");
22056 if (die
->sibling
!= NULL
&& level
> 0)
22058 dump_die_1 (f
, level
, max_level
, die
->sibling
);
22062 /* This is called from the pdie macro in gdbinit.in.
22063 It's not static so gcc will keep a copy callable from gdb. */
22066 dump_die (struct die_info
*die
, int max_level
)
22068 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
22072 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
22076 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
22077 to_underlying (die
->sect_off
),
22083 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
22087 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
22089 if (attr
->form_is_ref ())
22090 return (sect_offset
) DW_UNSND (attr
);
22092 complaint (_("unsupported die ref attribute form: '%s'"),
22093 dwarf_form_name (attr
->form
));
22097 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
22098 * the value held by the attribute is not constant. */
22101 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
22103 if (attr
->form
== DW_FORM_sdata
|| attr
->form
== DW_FORM_implicit_const
)
22104 return DW_SND (attr
);
22105 else if (attr
->form
== DW_FORM_udata
22106 || attr
->form
== DW_FORM_data1
22107 || attr
->form
== DW_FORM_data2
22108 || attr
->form
== DW_FORM_data4
22109 || attr
->form
== DW_FORM_data8
)
22110 return DW_UNSND (attr
);
22113 /* For DW_FORM_data16 see attribute::form_is_constant. */
22114 complaint (_("Attribute value is not a constant (%s)"),
22115 dwarf_form_name (attr
->form
));
22116 return default_value
;
22120 /* Follow reference or signature attribute ATTR of SRC_DIE.
22121 On entry *REF_CU is the CU of SRC_DIE.
22122 On exit *REF_CU is the CU of the result. */
22124 static struct die_info
*
22125 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22126 struct dwarf2_cu
**ref_cu
)
22128 struct die_info
*die
;
22130 if (attr
->form_is_ref ())
22131 die
= follow_die_ref (src_die
, attr
, ref_cu
);
22132 else if (attr
->form
== DW_FORM_ref_sig8
)
22133 die
= follow_die_sig (src_die
, attr
, ref_cu
);
22136 dump_die_for_error (src_die
);
22137 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
22138 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22144 /* Follow reference OFFSET.
22145 On entry *REF_CU is the CU of the source die referencing OFFSET.
22146 On exit *REF_CU is the CU of the result.
22147 Returns NULL if OFFSET is invalid. */
22149 static struct die_info
*
22150 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
22151 struct dwarf2_cu
**ref_cu
)
22153 struct die_info temp_die
;
22154 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
22155 struct dwarf2_per_objfile
*dwarf2_per_objfile
22156 = cu
->per_cu
->dwarf2_per_objfile
;
22158 gdb_assert (cu
->per_cu
!= NULL
);
22162 if (cu
->per_cu
->is_debug_types
)
22164 /* .debug_types CUs cannot reference anything outside their CU.
22165 If they need to, they have to reference a signatured type via
22166 DW_FORM_ref_sig8. */
22167 if (!cu
->header
.offset_in_cu_p (sect_off
))
22170 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
22171 || !cu
->header
.offset_in_cu_p (sect_off
))
22173 struct dwarf2_per_cu_data
*per_cu
;
22175 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
22176 dwarf2_per_objfile
);
22178 /* If necessary, add it to the queue and load its DIEs. */
22179 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
22180 load_full_comp_unit (per_cu
, false, cu
->language
);
22182 target_cu
= per_cu
->cu
;
22184 else if (cu
->dies
== NULL
)
22186 /* We're loading full DIEs during partial symbol reading. */
22187 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
22188 load_full_comp_unit (cu
->per_cu
, false, language_minimal
);
22191 *ref_cu
= target_cu
;
22192 temp_die
.sect_off
= sect_off
;
22194 if (target_cu
!= cu
)
22195 target_cu
->ancestor
= cu
;
22197 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
22199 to_underlying (sect_off
));
22202 /* Follow reference attribute ATTR of SRC_DIE.
22203 On entry *REF_CU is the CU of SRC_DIE.
22204 On exit *REF_CU is the CU of the result. */
22206 static struct die_info
*
22207 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
22208 struct dwarf2_cu
**ref_cu
)
22210 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22211 struct dwarf2_cu
*cu
= *ref_cu
;
22212 struct die_info
*die
;
22214 die
= follow_die_offset (sect_off
,
22215 (attr
->form
== DW_FORM_GNU_ref_alt
22216 || cu
->per_cu
->is_dwz
),
22219 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
22220 "at %s [in module %s]"),
22221 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
22222 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
22227 /* Return DWARF block referenced by DW_AT_location of DIE at SECT_OFF at PER_CU.
22228 Returned value is intended for DW_OP_call*. Returned
22229 dwarf2_locexpr_baton->data has lifetime of
22230 PER_CU->DWARF2_PER_OBJFILE->OBJFILE. */
22232 struct dwarf2_locexpr_baton
22233 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
22234 struct dwarf2_per_cu_data
*per_cu
,
22235 CORE_ADDR (*get_frame_pc
) (void *baton
),
22236 void *baton
, bool resolve_abstract_p
)
22238 struct dwarf2_cu
*cu
;
22239 struct die_info
*die
;
22240 struct attribute
*attr
;
22241 struct dwarf2_locexpr_baton retval
;
22242 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
22243 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22245 if (per_cu
->cu
== NULL
)
22246 load_cu (per_cu
, false);
22250 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22251 Instead just throw an error, not much else we can do. */
22252 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22253 sect_offset_str (sect_off
), objfile_name (objfile
));
22256 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22258 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22259 sect_offset_str (sect_off
), objfile_name (objfile
));
22261 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22262 if (!attr
&& resolve_abstract_p
22263 && (dwarf2_per_objfile
->abstract_to_concrete
.find (die
->sect_off
)
22264 != dwarf2_per_objfile
->abstract_to_concrete
.end ()))
22266 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22267 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
22268 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
22270 for (const auto &cand_off
22271 : dwarf2_per_objfile
->abstract_to_concrete
[die
->sect_off
])
22273 struct dwarf2_cu
*cand_cu
= cu
;
22274 struct die_info
*cand
22275 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
22278 || cand
->parent
->tag
!= DW_TAG_subprogram
)
22281 CORE_ADDR pc_low
, pc_high
;
22282 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
22283 if (pc_low
== ((CORE_ADDR
) -1))
22285 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
22286 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
22287 if (!(pc_low
<= pc
&& pc
< pc_high
))
22291 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22298 /* DWARF: "If there is no such attribute, then there is no effect.".
22299 DATA is ignored if SIZE is 0. */
22301 retval
.data
= NULL
;
22304 else if (attr
->form_is_section_offset ())
22306 struct dwarf2_loclist_baton loclist_baton
;
22307 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22310 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
22312 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
22314 retval
.size
= size
;
22318 if (!attr
->form_is_block ())
22319 error (_("Dwarf Error: DIE at %s referenced in module %s "
22320 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
22321 sect_offset_str (sect_off
), objfile_name (objfile
));
22323 retval
.data
= DW_BLOCK (attr
)->data
;
22324 retval
.size
= DW_BLOCK (attr
)->size
;
22326 retval
.per_cu
= cu
->per_cu
;
22328 age_cached_comp_units (dwarf2_per_objfile
);
22333 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
22336 struct dwarf2_locexpr_baton
22337 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
22338 struct dwarf2_per_cu_data
*per_cu
,
22339 CORE_ADDR (*get_frame_pc
) (void *baton
),
22342 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
22344 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
22347 /* Write a constant of a given type as target-ordered bytes into
22350 static const gdb_byte
*
22351 write_constant_as_bytes (struct obstack
*obstack
,
22352 enum bfd_endian byte_order
,
22359 *len
= TYPE_LENGTH (type
);
22360 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22361 store_unsigned_integer (result
, *len
, byte_order
, value
);
22366 /* If the DIE at OFFSET in PER_CU has a DW_AT_const_value, return a
22367 pointer to the constant bytes and set LEN to the length of the
22368 data. If memory is needed, allocate it on OBSTACK. If the DIE
22369 does not have a DW_AT_const_value, return NULL. */
22372 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
22373 struct dwarf2_per_cu_data
*per_cu
,
22374 struct obstack
*obstack
,
22377 struct dwarf2_cu
*cu
;
22378 struct die_info
*die
;
22379 struct attribute
*attr
;
22380 const gdb_byte
*result
= NULL
;
22383 enum bfd_endian byte_order
;
22384 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
22386 if (per_cu
->cu
== NULL
)
22387 load_cu (per_cu
, false);
22391 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22392 Instead just throw an error, not much else we can do. */
22393 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22394 sect_offset_str (sect_off
), objfile_name (objfile
));
22397 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22399 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22400 sect_offset_str (sect_off
), objfile_name (objfile
));
22402 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22406 byte_order
= (bfd_big_endian (objfile
->obfd
)
22407 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22409 switch (attr
->form
)
22412 case DW_FORM_addrx
:
22413 case DW_FORM_GNU_addr_index
:
22417 *len
= cu
->header
.addr_size
;
22418 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22419 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
22423 case DW_FORM_string
:
22426 case DW_FORM_GNU_str_index
:
22427 case DW_FORM_GNU_strp_alt
:
22428 /* DW_STRING is already allocated on the objfile obstack, point
22430 result
= (const gdb_byte
*) DW_STRING (attr
);
22431 *len
= strlen (DW_STRING (attr
));
22433 case DW_FORM_block1
:
22434 case DW_FORM_block2
:
22435 case DW_FORM_block4
:
22436 case DW_FORM_block
:
22437 case DW_FORM_exprloc
:
22438 case DW_FORM_data16
:
22439 result
= DW_BLOCK (attr
)->data
;
22440 *len
= DW_BLOCK (attr
)->size
;
22443 /* The DW_AT_const_value attributes are supposed to carry the
22444 symbol's value "represented as it would be on the target
22445 architecture." By the time we get here, it's already been
22446 converted to host endianness, so we just need to sign- or
22447 zero-extend it as appropriate. */
22448 case DW_FORM_data1
:
22449 type
= die_type (die
, cu
);
22450 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
22451 if (result
== NULL
)
22452 result
= write_constant_as_bytes (obstack
, byte_order
,
22455 case DW_FORM_data2
:
22456 type
= die_type (die
, cu
);
22457 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
22458 if (result
== NULL
)
22459 result
= write_constant_as_bytes (obstack
, byte_order
,
22462 case DW_FORM_data4
:
22463 type
= die_type (die
, cu
);
22464 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
22465 if (result
== NULL
)
22466 result
= write_constant_as_bytes (obstack
, byte_order
,
22469 case DW_FORM_data8
:
22470 type
= die_type (die
, cu
);
22471 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
22472 if (result
== NULL
)
22473 result
= write_constant_as_bytes (obstack
, byte_order
,
22477 case DW_FORM_sdata
:
22478 case DW_FORM_implicit_const
:
22479 type
= die_type (die
, cu
);
22480 result
= write_constant_as_bytes (obstack
, byte_order
,
22481 type
, DW_SND (attr
), len
);
22484 case DW_FORM_udata
:
22485 type
= die_type (die
, cu
);
22486 result
= write_constant_as_bytes (obstack
, byte_order
,
22487 type
, DW_UNSND (attr
), len
);
22491 complaint (_("unsupported const value attribute form: '%s'"),
22492 dwarf_form_name (attr
->form
));
22499 /* Return the type of the die at OFFSET in PER_CU. Return NULL if no
22500 valid type for this die is found. */
22503 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
22504 struct dwarf2_per_cu_data
*per_cu
)
22506 struct dwarf2_cu
*cu
;
22507 struct die_info
*die
;
22509 if (per_cu
->cu
== NULL
)
22510 load_cu (per_cu
, false);
22515 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22519 return die_type (die
, cu
);
22522 /* Return the type of the DIE at DIE_OFFSET in the CU named by
22526 dwarf2_get_die_type (cu_offset die_offset
,
22527 struct dwarf2_per_cu_data
*per_cu
)
22529 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
22530 return get_die_type_at_offset (die_offset_sect
, per_cu
);
22533 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
22534 On entry *REF_CU is the CU of SRC_DIE.
22535 On exit *REF_CU is the CU of the result.
22536 Returns NULL if the referenced DIE isn't found. */
22538 static struct die_info
*
22539 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
22540 struct dwarf2_cu
**ref_cu
)
22542 struct die_info temp_die
;
22543 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
22544 struct die_info
*die
;
22546 /* While it might be nice to assert sig_type->type == NULL here,
22547 we can get here for DW_AT_imported_declaration where we need
22548 the DIE not the type. */
22550 /* If necessary, add it to the queue and load its DIEs. */
22552 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
22553 read_signatured_type (sig_type
);
22555 sig_cu
= sig_type
->per_cu
.cu
;
22556 gdb_assert (sig_cu
!= NULL
);
22557 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
22558 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
22559 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
22560 to_underlying (temp_die
.sect_off
));
22563 struct dwarf2_per_objfile
*dwarf2_per_objfile
22564 = (*ref_cu
)->per_cu
->dwarf2_per_objfile
;
22566 /* For .gdb_index version 7 keep track of included TUs.
22567 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
22568 if (dwarf2_per_objfile
->index_table
!= NULL
22569 && dwarf2_per_objfile
->index_table
->version
<= 7)
22571 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
22576 sig_cu
->ancestor
= cu
;
22584 /* Follow signatured type referenced by ATTR in SRC_DIE.
22585 On entry *REF_CU is the CU of SRC_DIE.
22586 On exit *REF_CU is the CU of the result.
22587 The result is the DIE of the type.
22588 If the referenced type cannot be found an error is thrown. */
22590 static struct die_info
*
22591 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22592 struct dwarf2_cu
**ref_cu
)
22594 ULONGEST signature
= DW_SIGNATURE (attr
);
22595 struct signatured_type
*sig_type
;
22596 struct die_info
*die
;
22598 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
22600 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
22601 /* sig_type will be NULL if the signatured type is missing from
22603 if (sig_type
== NULL
)
22605 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22606 " from DIE at %s [in module %s]"),
22607 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22608 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22611 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
22614 dump_die_for_error (src_die
);
22615 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22616 " from DIE at %s [in module %s]"),
22617 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22618 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22624 /* Get the type specified by SIGNATURE referenced in DIE/CU,
22625 reading in and processing the type unit if necessary. */
22627 static struct type
*
22628 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
22629 struct dwarf2_cu
*cu
)
22631 struct dwarf2_per_objfile
*dwarf2_per_objfile
22632 = cu
->per_cu
->dwarf2_per_objfile
;
22633 struct signatured_type
*sig_type
;
22634 struct dwarf2_cu
*type_cu
;
22635 struct die_info
*type_die
;
22638 sig_type
= lookup_signatured_type (cu
, signature
);
22639 /* sig_type will be NULL if the signatured type is missing from
22641 if (sig_type
== NULL
)
22643 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22644 " from DIE at %s [in module %s]"),
22645 hex_string (signature
), sect_offset_str (die
->sect_off
),
22646 objfile_name (dwarf2_per_objfile
->objfile
));
22647 return build_error_marker_type (cu
, die
);
22650 /* If we already know the type we're done. */
22651 if (sig_type
->type
!= NULL
)
22652 return sig_type
->type
;
22655 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
22656 if (type_die
!= NULL
)
22658 /* N.B. We need to call get_die_type to ensure only one type for this DIE
22659 is created. This is important, for example, because for c++ classes
22660 we need TYPE_NAME set which is only done by new_symbol. Blech. */
22661 type
= read_type_die (type_die
, type_cu
);
22664 complaint (_("Dwarf Error: Cannot build signatured type %s"
22665 " referenced from DIE at %s [in module %s]"),
22666 hex_string (signature
), sect_offset_str (die
->sect_off
),
22667 objfile_name (dwarf2_per_objfile
->objfile
));
22668 type
= build_error_marker_type (cu
, die
);
22673 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22674 " from DIE at %s [in module %s]"),
22675 hex_string (signature
), sect_offset_str (die
->sect_off
),
22676 objfile_name (dwarf2_per_objfile
->objfile
));
22677 type
= build_error_marker_type (cu
, die
);
22679 sig_type
->type
= type
;
22684 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
22685 reading in and processing the type unit if necessary. */
22687 static struct type
*
22688 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
22689 struct dwarf2_cu
*cu
) /* ARI: editCase function */
22691 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
22692 if (attr
->form_is_ref ())
22694 struct dwarf2_cu
*type_cu
= cu
;
22695 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
22697 return read_type_die (type_die
, type_cu
);
22699 else if (attr
->form
== DW_FORM_ref_sig8
)
22701 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
22705 struct dwarf2_per_objfile
*dwarf2_per_objfile
22706 = cu
->per_cu
->dwarf2_per_objfile
;
22708 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
22709 " at %s [in module %s]"),
22710 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
22711 objfile_name (dwarf2_per_objfile
->objfile
));
22712 return build_error_marker_type (cu
, die
);
22716 /* Load the DIEs associated with type unit PER_CU into memory. */
22719 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
22721 struct signatured_type
*sig_type
;
22723 /* Caller is responsible for ensuring type_unit_groups don't get here. */
22724 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
22726 /* We have the per_cu, but we need the signatured_type.
22727 Fortunately this is an easy translation. */
22728 gdb_assert (per_cu
->is_debug_types
);
22729 sig_type
= (struct signatured_type
*) per_cu
;
22731 gdb_assert (per_cu
->cu
== NULL
);
22733 read_signatured_type (sig_type
);
22735 gdb_assert (per_cu
->cu
!= NULL
);
22738 /* Read in a signatured type and build its CU and DIEs.
22739 If the type is a stub for the real type in a DWO file,
22740 read in the real type from the DWO file as well. */
22743 read_signatured_type (struct signatured_type
*sig_type
)
22745 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
22747 gdb_assert (per_cu
->is_debug_types
);
22748 gdb_assert (per_cu
->cu
== NULL
);
22750 cutu_reader
reader (per_cu
, NULL
, 0, false);
22752 if (!reader
.dummy_p
)
22754 struct dwarf2_cu
*cu
= reader
.cu
;
22755 const gdb_byte
*info_ptr
= reader
.info_ptr
;
22757 gdb_assert (cu
->die_hash
== NULL
);
22759 htab_create_alloc_ex (cu
->header
.length
/ 12,
22763 &cu
->comp_unit_obstack
,
22764 hashtab_obstack_allocate
,
22765 dummy_obstack_deallocate
);
22767 if (reader
.comp_unit_die
->has_children
)
22768 reader
.comp_unit_die
->child
22769 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
22770 reader
.comp_unit_die
);
22771 cu
->dies
= reader
.comp_unit_die
;
22772 /* comp_unit_die is not stored in die_hash, no need. */
22774 /* We try not to read any attributes in this function, because
22775 not all CUs needed for references have been loaded yet, and
22776 symbol table processing isn't initialized. But we have to
22777 set the CU language, or we won't be able to build types
22778 correctly. Similarly, if we do not read the producer, we can
22779 not apply producer-specific interpretation. */
22780 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
22785 sig_type
->per_cu
.tu_read
= 1;
22788 /* Decode simple location descriptions.
22789 Given a pointer to a dwarf block that defines a location, compute
22790 the location and return the value.
22792 NOTE drow/2003-11-18: This function is called in two situations
22793 now: for the address of static or global variables (partial symbols
22794 only) and for offsets into structures which are expected to be
22795 (more or less) constant. The partial symbol case should go away,
22796 and only the constant case should remain. That will let this
22797 function complain more accurately. A few special modes are allowed
22798 without complaint for global variables (for instance, global
22799 register values and thread-local values).
22801 A location description containing no operations indicates that the
22802 object is optimized out. The return value is 0 for that case.
22803 FIXME drow/2003-11-16: No callers check for this case any more; soon all
22804 callers will only want a very basic result and this can become a
22807 Note that stack[0] is unused except as a default error return. */
22810 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
22812 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22814 size_t size
= blk
->size
;
22815 const gdb_byte
*data
= blk
->data
;
22816 CORE_ADDR stack
[64];
22818 unsigned int bytes_read
, unsnd
;
22824 stack
[++stacki
] = 0;
22863 stack
[++stacki
] = op
- DW_OP_lit0
;
22898 stack
[++stacki
] = op
- DW_OP_reg0
;
22900 dwarf2_complex_location_expr_complaint ();
22904 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
22906 stack
[++stacki
] = unsnd
;
22908 dwarf2_complex_location_expr_complaint ();
22912 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
22917 case DW_OP_const1u
:
22918 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
22922 case DW_OP_const1s
:
22923 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
22927 case DW_OP_const2u
:
22928 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
22932 case DW_OP_const2s
:
22933 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
22937 case DW_OP_const4u
:
22938 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
22942 case DW_OP_const4s
:
22943 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
22947 case DW_OP_const8u
:
22948 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
22953 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
22959 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
22964 stack
[stacki
+ 1] = stack
[stacki
];
22969 stack
[stacki
- 1] += stack
[stacki
];
22973 case DW_OP_plus_uconst
:
22974 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
22980 stack
[stacki
- 1] -= stack
[stacki
];
22985 /* If we're not the last op, then we definitely can't encode
22986 this using GDB's address_class enum. This is valid for partial
22987 global symbols, although the variable's address will be bogus
22990 dwarf2_complex_location_expr_complaint ();
22993 case DW_OP_GNU_push_tls_address
:
22994 case DW_OP_form_tls_address
:
22995 /* The top of the stack has the offset from the beginning
22996 of the thread control block at which the variable is located. */
22997 /* Nothing should follow this operator, so the top of stack would
22999 /* This is valid for partial global symbols, but the variable's
23000 address will be bogus in the psymtab. Make it always at least
23001 non-zero to not look as a variable garbage collected by linker
23002 which have DW_OP_addr 0. */
23004 dwarf2_complex_location_expr_complaint ();
23008 case DW_OP_GNU_uninit
:
23012 case DW_OP_GNU_addr_index
:
23013 case DW_OP_GNU_const_index
:
23014 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
23021 const char *name
= get_DW_OP_name (op
);
23024 complaint (_("unsupported stack op: '%s'"),
23027 complaint (_("unsupported stack op: '%02x'"),
23031 return (stack
[stacki
]);
23034 /* Enforce maximum stack depth of SIZE-1 to avoid writing
23035 outside of the allocated space. Also enforce minimum>0. */
23036 if (stacki
>= ARRAY_SIZE (stack
) - 1)
23038 complaint (_("location description stack overflow"));
23044 complaint (_("location description stack underflow"));
23048 return (stack
[stacki
]);
23051 /* memory allocation interface */
23053 static struct dwarf_block
*
23054 dwarf_alloc_block (struct dwarf2_cu
*cu
)
23056 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
23059 static struct die_info
*
23060 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
23062 struct die_info
*die
;
23063 size_t size
= sizeof (struct die_info
);
23066 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
23068 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
23069 memset (die
, 0, sizeof (struct die_info
));
23074 /* Macro support. */
23076 static struct macro_source_file
*
23077 macro_start_file (struct dwarf2_cu
*cu
,
23078 int file
, int line
,
23079 struct macro_source_file
*current_file
,
23080 struct line_header
*lh
)
23082 /* File name relative to the compilation directory of this source file. */
23083 gdb::unique_xmalloc_ptr
<char> file_name
= lh
->file_file_name (file
);
23085 if (! current_file
)
23087 /* Note: We don't create a macro table for this compilation unit
23088 at all until we actually get a filename. */
23089 struct macro_table
*macro_table
= cu
->get_builder ()->get_macro_table ();
23091 /* If we have no current file, then this must be the start_file
23092 directive for the compilation unit's main source file. */
23093 current_file
= macro_set_main (macro_table
, file_name
.get ());
23094 macro_define_special (macro_table
);
23097 current_file
= macro_include (current_file
, line
, file_name
.get ());
23099 return current_file
;
23102 static const char *
23103 consume_improper_spaces (const char *p
, const char *body
)
23107 complaint (_("macro definition contains spaces "
23108 "in formal argument list:\n`%s'"),
23120 parse_macro_definition (struct macro_source_file
*file
, int line
,
23125 /* The body string takes one of two forms. For object-like macro
23126 definitions, it should be:
23128 <macro name> " " <definition>
23130 For function-like macro definitions, it should be:
23132 <macro name> "() " <definition>
23134 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
23136 Spaces may appear only where explicitly indicated, and in the
23139 The Dwarf 2 spec says that an object-like macro's name is always
23140 followed by a space, but versions of GCC around March 2002 omit
23141 the space when the macro's definition is the empty string.
23143 The Dwarf 2 spec says that there should be no spaces between the
23144 formal arguments in a function-like macro's formal argument list,
23145 but versions of GCC around March 2002 include spaces after the
23149 /* Find the extent of the macro name. The macro name is terminated
23150 by either a space or null character (for an object-like macro) or
23151 an opening paren (for a function-like macro). */
23152 for (p
= body
; *p
; p
++)
23153 if (*p
== ' ' || *p
== '(')
23156 if (*p
== ' ' || *p
== '\0')
23158 /* It's an object-like macro. */
23159 int name_len
= p
- body
;
23160 std::string
name (body
, name_len
);
23161 const char *replacement
;
23164 replacement
= body
+ name_len
+ 1;
23167 dwarf2_macro_malformed_definition_complaint (body
);
23168 replacement
= body
+ name_len
;
23171 macro_define_object (file
, line
, name
.c_str (), replacement
);
23173 else if (*p
== '(')
23175 /* It's a function-like macro. */
23176 std::string
name (body
, p
- body
);
23179 char **argv
= XNEWVEC (char *, argv_size
);
23183 p
= consume_improper_spaces (p
, body
);
23185 /* Parse the formal argument list. */
23186 while (*p
&& *p
!= ')')
23188 /* Find the extent of the current argument name. */
23189 const char *arg_start
= p
;
23191 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
23194 if (! *p
|| p
== arg_start
)
23195 dwarf2_macro_malformed_definition_complaint (body
);
23198 /* Make sure argv has room for the new argument. */
23199 if (argc
>= argv_size
)
23202 argv
= XRESIZEVEC (char *, argv
, argv_size
);
23205 argv
[argc
++] = savestring (arg_start
, p
- arg_start
);
23208 p
= consume_improper_spaces (p
, body
);
23210 /* Consume the comma, if present. */
23215 p
= consume_improper_spaces (p
, body
);
23224 /* Perfectly formed definition, no complaints. */
23225 macro_define_function (file
, line
, name
.c_str (),
23226 argc
, (const char **) argv
,
23228 else if (*p
== '\0')
23230 /* Complain, but do define it. */
23231 dwarf2_macro_malformed_definition_complaint (body
);
23232 macro_define_function (file
, line
, name
.c_str (),
23233 argc
, (const char **) argv
,
23237 /* Just complain. */
23238 dwarf2_macro_malformed_definition_complaint (body
);
23241 /* Just complain. */
23242 dwarf2_macro_malformed_definition_complaint (body
);
23247 for (i
= 0; i
< argc
; i
++)
23253 dwarf2_macro_malformed_definition_complaint (body
);
23256 /* Skip some bytes from BYTES according to the form given in FORM.
23257 Returns the new pointer. */
23259 static const gdb_byte
*
23260 skip_form_bytes (bfd
*abfd
, const gdb_byte
*bytes
, const gdb_byte
*buffer_end
,
23261 enum dwarf_form form
,
23262 unsigned int offset_size
,
23263 struct dwarf2_section_info
*section
)
23265 unsigned int bytes_read
;
23269 case DW_FORM_data1
:
23274 case DW_FORM_data2
:
23278 case DW_FORM_data4
:
23282 case DW_FORM_data8
:
23286 case DW_FORM_data16
:
23290 case DW_FORM_string
:
23291 read_direct_string (abfd
, bytes
, &bytes_read
);
23292 bytes
+= bytes_read
;
23295 case DW_FORM_sec_offset
:
23297 case DW_FORM_GNU_strp_alt
:
23298 bytes
+= offset_size
;
23301 case DW_FORM_block
:
23302 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
23303 bytes
+= bytes_read
;
23306 case DW_FORM_block1
:
23307 bytes
+= 1 + read_1_byte (abfd
, bytes
);
23309 case DW_FORM_block2
:
23310 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
23312 case DW_FORM_block4
:
23313 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
23316 case DW_FORM_addrx
:
23317 case DW_FORM_sdata
:
23319 case DW_FORM_udata
:
23320 case DW_FORM_GNU_addr_index
:
23321 case DW_FORM_GNU_str_index
:
23322 bytes
= gdb_skip_leb128 (bytes
, buffer_end
);
23325 dwarf2_section_buffer_overflow_complaint (section
);
23330 case DW_FORM_implicit_const
:
23335 complaint (_("invalid form 0x%x in `%s'"),
23336 form
, section
->get_name ());
23344 /* A helper for dwarf_decode_macros that handles skipping an unknown
23345 opcode. Returns an updated pointer to the macro data buffer; or,
23346 on error, issues a complaint and returns NULL. */
23348 static const gdb_byte
*
23349 skip_unknown_opcode (unsigned int opcode
,
23350 const gdb_byte
**opcode_definitions
,
23351 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
23353 unsigned int offset_size
,
23354 struct dwarf2_section_info
*section
)
23356 unsigned int bytes_read
, i
;
23358 const gdb_byte
*defn
;
23360 if (opcode_definitions
[opcode
] == NULL
)
23362 complaint (_("unrecognized DW_MACFINO opcode 0x%x"),
23367 defn
= opcode_definitions
[opcode
];
23368 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
23369 defn
+= bytes_read
;
23371 for (i
= 0; i
< arg
; ++i
)
23373 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
,
23374 (enum dwarf_form
) defn
[i
], offset_size
,
23376 if (mac_ptr
== NULL
)
23378 /* skip_form_bytes already issued the complaint. */
23386 /* A helper function which parses the header of a macro section.
23387 If the macro section is the extended (for now called "GNU") type,
23388 then this updates *OFFSET_SIZE. Returns a pointer to just after
23389 the header, or issues a complaint and returns NULL on error. */
23391 static const gdb_byte
*
23392 dwarf_parse_macro_header (const gdb_byte
**opcode_definitions
,
23394 const gdb_byte
*mac_ptr
,
23395 unsigned int *offset_size
,
23396 int section_is_gnu
)
23398 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
23400 if (section_is_gnu
)
23402 unsigned int version
, flags
;
23404 version
= read_2_bytes (abfd
, mac_ptr
);
23405 if (version
!= 4 && version
!= 5)
23407 complaint (_("unrecognized version `%d' in .debug_macro section"),
23413 flags
= read_1_byte (abfd
, mac_ptr
);
23415 *offset_size
= (flags
& 1) ? 8 : 4;
23417 if ((flags
& 2) != 0)
23418 /* We don't need the line table offset. */
23419 mac_ptr
+= *offset_size
;
23421 /* Vendor opcode descriptions. */
23422 if ((flags
& 4) != 0)
23424 unsigned int i
, count
;
23426 count
= read_1_byte (abfd
, mac_ptr
);
23428 for (i
= 0; i
< count
; ++i
)
23430 unsigned int opcode
, bytes_read
;
23433 opcode
= read_1_byte (abfd
, mac_ptr
);
23435 opcode_definitions
[opcode
] = mac_ptr
;
23436 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23437 mac_ptr
+= bytes_read
;
23446 /* A helper for dwarf_decode_macros that handles the GNU extensions,
23447 including DW_MACRO_import. */
23450 dwarf_decode_macro_bytes (struct dwarf2_cu
*cu
,
23452 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
23453 struct macro_source_file
*current_file
,
23454 struct line_header
*lh
,
23455 struct dwarf2_section_info
*section
,
23456 int section_is_gnu
, int section_is_dwz
,
23457 unsigned int offset_size
,
23458 htab_t include_hash
)
23460 struct dwarf2_per_objfile
*dwarf2_per_objfile
23461 = cu
->per_cu
->dwarf2_per_objfile
;
23462 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23463 enum dwarf_macro_record_type macinfo_type
;
23464 int at_commandline
;
23465 const gdb_byte
*opcode_definitions
[256];
23467 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
23468 &offset_size
, section_is_gnu
);
23469 if (mac_ptr
== NULL
)
23471 /* We already issued a complaint. */
23475 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
23476 GDB is still reading the definitions from command line. First
23477 DW_MACINFO_start_file will need to be ignored as it was already executed
23478 to create CURRENT_FILE for the main source holding also the command line
23479 definitions. On first met DW_MACINFO_start_file this flag is reset to
23480 normally execute all the remaining DW_MACINFO_start_file macinfos. */
23482 at_commandline
= 1;
23486 /* Do we at least have room for a macinfo type byte? */
23487 if (mac_ptr
>= mac_end
)
23489 dwarf2_section_buffer_overflow_complaint (section
);
23493 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
23496 /* Note that we rely on the fact that the corresponding GNU and
23497 DWARF constants are the same. */
23499 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
23500 switch (macinfo_type
)
23502 /* A zero macinfo type indicates the end of the macro
23507 case DW_MACRO_define
:
23508 case DW_MACRO_undef
:
23509 case DW_MACRO_define_strp
:
23510 case DW_MACRO_undef_strp
:
23511 case DW_MACRO_define_sup
:
23512 case DW_MACRO_undef_sup
:
23514 unsigned int bytes_read
;
23519 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23520 mac_ptr
+= bytes_read
;
23522 if (macinfo_type
== DW_MACRO_define
23523 || macinfo_type
== DW_MACRO_undef
)
23525 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
23526 mac_ptr
+= bytes_read
;
23530 LONGEST str_offset
;
23532 str_offset
= read_offset (abfd
, mac_ptr
, offset_size
);
23533 mac_ptr
+= offset_size
;
23535 if (macinfo_type
== DW_MACRO_define_sup
23536 || macinfo_type
== DW_MACRO_undef_sup
23539 struct dwz_file
*dwz
23540 = dwarf2_get_dwz_file (dwarf2_per_objfile
);
23542 body
= read_indirect_string_from_dwz (objfile
,
23546 body
= read_indirect_string_at_offset (dwarf2_per_objfile
,
23550 is_define
= (macinfo_type
== DW_MACRO_define
23551 || macinfo_type
== DW_MACRO_define_strp
23552 || macinfo_type
== DW_MACRO_define_sup
);
23553 if (! current_file
)
23555 /* DWARF violation as no main source is present. */
23556 complaint (_("debug info with no main source gives macro %s "
23558 is_define
? _("definition") : _("undefinition"),
23562 if ((line
== 0 && !at_commandline
)
23563 || (line
!= 0 && at_commandline
))
23564 complaint (_("debug info gives %s macro %s with %s line %d: %s"),
23565 at_commandline
? _("command-line") : _("in-file"),
23566 is_define
? _("definition") : _("undefinition"),
23567 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
23571 /* Fedora's rpm-build's "debugedit" binary
23572 corrupted .debug_macro sections.
23575 https://bugzilla.redhat.com/show_bug.cgi?id=1708786 */
23576 complaint (_("debug info gives %s invalid macro %s "
23577 "without body (corrupted?) at line %d "
23579 at_commandline
? _("command-line") : _("in-file"),
23580 is_define
? _("definition") : _("undefinition"),
23581 line
, current_file
->filename
);
23583 else if (is_define
)
23584 parse_macro_definition (current_file
, line
, body
);
23587 gdb_assert (macinfo_type
== DW_MACRO_undef
23588 || macinfo_type
== DW_MACRO_undef_strp
23589 || macinfo_type
== DW_MACRO_undef_sup
);
23590 macro_undef (current_file
, line
, body
);
23595 case DW_MACRO_start_file
:
23597 unsigned int bytes_read
;
23600 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23601 mac_ptr
+= bytes_read
;
23602 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23603 mac_ptr
+= bytes_read
;
23605 if ((line
== 0 && !at_commandline
)
23606 || (line
!= 0 && at_commandline
))
23607 complaint (_("debug info gives source %d included "
23608 "from %s at %s line %d"),
23609 file
, at_commandline
? _("command-line") : _("file"),
23610 line
== 0 ? _("zero") : _("non-zero"), line
);
23612 if (at_commandline
)
23614 /* This DW_MACRO_start_file was executed in the
23616 at_commandline
= 0;
23619 current_file
= macro_start_file (cu
, file
, line
, current_file
,
23624 case DW_MACRO_end_file
:
23625 if (! current_file
)
23626 complaint (_("macro debug info has an unmatched "
23627 "`close_file' directive"));
23630 current_file
= current_file
->included_by
;
23631 if (! current_file
)
23633 enum dwarf_macro_record_type next_type
;
23635 /* GCC circa March 2002 doesn't produce the zero
23636 type byte marking the end of the compilation
23637 unit. Complain if it's not there, but exit no
23640 /* Do we at least have room for a macinfo type byte? */
23641 if (mac_ptr
>= mac_end
)
23643 dwarf2_section_buffer_overflow_complaint (section
);
23647 /* We don't increment mac_ptr here, so this is just
23650 = (enum dwarf_macro_record_type
) read_1_byte (abfd
,
23652 if (next_type
!= 0)
23653 complaint (_("no terminating 0-type entry for "
23654 "macros in `.debug_macinfo' section"));
23661 case DW_MACRO_import
:
23662 case DW_MACRO_import_sup
:
23666 bfd
*include_bfd
= abfd
;
23667 struct dwarf2_section_info
*include_section
= section
;
23668 const gdb_byte
*include_mac_end
= mac_end
;
23669 int is_dwz
= section_is_dwz
;
23670 const gdb_byte
*new_mac_ptr
;
23672 offset
= read_offset (abfd
, mac_ptr
, offset_size
);
23673 mac_ptr
+= offset_size
;
23675 if (macinfo_type
== DW_MACRO_import_sup
)
23677 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
23679 dwz
->macro
.read (objfile
);
23681 include_section
= &dwz
->macro
;
23682 include_bfd
= include_section
->get_bfd_owner ();
23683 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
23687 new_mac_ptr
= include_section
->buffer
+ offset
;
23688 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
23692 /* This has actually happened; see
23693 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
23694 complaint (_("recursive DW_MACRO_import in "
23695 ".debug_macro section"));
23699 *slot
= (void *) new_mac_ptr
;
23701 dwarf_decode_macro_bytes (cu
, include_bfd
, new_mac_ptr
,
23702 include_mac_end
, current_file
, lh
,
23703 section
, section_is_gnu
, is_dwz
,
23704 offset_size
, include_hash
);
23706 htab_remove_elt (include_hash
, (void *) new_mac_ptr
);
23711 case DW_MACINFO_vendor_ext
:
23712 if (!section_is_gnu
)
23714 unsigned int bytes_read
;
23716 /* This reads the constant, but since we don't recognize
23717 any vendor extensions, we ignore it. */
23718 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23719 mac_ptr
+= bytes_read
;
23720 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
23721 mac_ptr
+= bytes_read
;
23723 /* We don't recognize any vendor extensions. */
23729 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
23730 mac_ptr
, mac_end
, abfd
, offset_size
,
23732 if (mac_ptr
== NULL
)
23737 } while (macinfo_type
!= 0);
23741 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
23742 int section_is_gnu
)
23744 struct dwarf2_per_objfile
*dwarf2_per_objfile
23745 = cu
->per_cu
->dwarf2_per_objfile
;
23746 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23747 struct line_header
*lh
= cu
->line_header
;
23749 const gdb_byte
*mac_ptr
, *mac_end
;
23750 struct macro_source_file
*current_file
= 0;
23751 enum dwarf_macro_record_type macinfo_type
;
23752 unsigned int offset_size
= cu
->header
.offset_size
;
23753 const gdb_byte
*opcode_definitions
[256];
23755 struct dwarf2_section_info
*section
;
23756 const char *section_name
;
23758 if (cu
->dwo_unit
!= NULL
)
23760 if (section_is_gnu
)
23762 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
23763 section_name
= ".debug_macro.dwo";
23767 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
23768 section_name
= ".debug_macinfo.dwo";
23773 if (section_is_gnu
)
23775 section
= &dwarf2_per_objfile
->macro
;
23776 section_name
= ".debug_macro";
23780 section
= &dwarf2_per_objfile
->macinfo
;
23781 section_name
= ".debug_macinfo";
23785 section
->read (objfile
);
23786 if (section
->buffer
== NULL
)
23788 complaint (_("missing %s section"), section_name
);
23791 abfd
= section
->get_bfd_owner ();
23793 /* First pass: Find the name of the base filename.
23794 This filename is needed in order to process all macros whose definition
23795 (or undefinition) comes from the command line. These macros are defined
23796 before the first DW_MACINFO_start_file entry, and yet still need to be
23797 associated to the base file.
23799 To determine the base file name, we scan the macro definitions until we
23800 reach the first DW_MACINFO_start_file entry. We then initialize
23801 CURRENT_FILE accordingly so that any macro definition found before the
23802 first DW_MACINFO_start_file can still be associated to the base file. */
23804 mac_ptr
= section
->buffer
+ offset
;
23805 mac_end
= section
->buffer
+ section
->size
;
23807 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
23808 &offset_size
, section_is_gnu
);
23809 if (mac_ptr
== NULL
)
23811 /* We already issued a complaint. */
23817 /* Do we at least have room for a macinfo type byte? */
23818 if (mac_ptr
>= mac_end
)
23820 /* Complaint is printed during the second pass as GDB will probably
23821 stop the first pass earlier upon finding
23822 DW_MACINFO_start_file. */
23826 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
23829 /* Note that we rely on the fact that the corresponding GNU and
23830 DWARF constants are the same. */
23832 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
23833 switch (macinfo_type
)
23835 /* A zero macinfo type indicates the end of the macro
23840 case DW_MACRO_define
:
23841 case DW_MACRO_undef
:
23842 /* Only skip the data by MAC_PTR. */
23844 unsigned int bytes_read
;
23846 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23847 mac_ptr
+= bytes_read
;
23848 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
23849 mac_ptr
+= bytes_read
;
23853 case DW_MACRO_start_file
:
23855 unsigned int bytes_read
;
23858 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23859 mac_ptr
+= bytes_read
;
23860 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23861 mac_ptr
+= bytes_read
;
23863 current_file
= macro_start_file (cu
, file
, line
, current_file
, lh
);
23867 case DW_MACRO_end_file
:
23868 /* No data to skip by MAC_PTR. */
23871 case DW_MACRO_define_strp
:
23872 case DW_MACRO_undef_strp
:
23873 case DW_MACRO_define_sup
:
23874 case DW_MACRO_undef_sup
:
23876 unsigned int bytes_read
;
23878 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23879 mac_ptr
+= bytes_read
;
23880 mac_ptr
+= offset_size
;
23884 case DW_MACRO_import
:
23885 case DW_MACRO_import_sup
:
23886 /* Note that, according to the spec, a transparent include
23887 chain cannot call DW_MACRO_start_file. So, we can just
23888 skip this opcode. */
23889 mac_ptr
+= offset_size
;
23892 case DW_MACINFO_vendor_ext
:
23893 /* Only skip the data by MAC_PTR. */
23894 if (!section_is_gnu
)
23896 unsigned int bytes_read
;
23898 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23899 mac_ptr
+= bytes_read
;
23900 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
23901 mac_ptr
+= bytes_read
;
23906 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
23907 mac_ptr
, mac_end
, abfd
, offset_size
,
23909 if (mac_ptr
== NULL
)
23914 } while (macinfo_type
!= 0 && current_file
== NULL
);
23916 /* Second pass: Process all entries.
23918 Use the AT_COMMAND_LINE flag to determine whether we are still processing
23919 command-line macro definitions/undefinitions. This flag is unset when we
23920 reach the first DW_MACINFO_start_file entry. */
23922 htab_up
include_hash (htab_create_alloc (1, htab_hash_pointer
,
23924 NULL
, xcalloc
, xfree
));
23925 mac_ptr
= section
->buffer
+ offset
;
23926 slot
= htab_find_slot (include_hash
.get (), mac_ptr
, INSERT
);
23927 *slot
= (void *) mac_ptr
;
23928 dwarf_decode_macro_bytes (cu
, abfd
, mac_ptr
, mac_end
,
23929 current_file
, lh
, section
,
23930 section_is_gnu
, 0, offset_size
,
23931 include_hash
.get ());
23934 /* Return the .debug_loc section to use for CU.
23935 For DWO files use .debug_loc.dwo. */
23937 static struct dwarf2_section_info
*
23938 cu_debug_loc_section (struct dwarf2_cu
*cu
)
23940 struct dwarf2_per_objfile
*dwarf2_per_objfile
23941 = cu
->per_cu
->dwarf2_per_objfile
;
23945 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
23947 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
23949 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
23950 : &dwarf2_per_objfile
->loc
);
23953 /* A helper function that fills in a dwarf2_loclist_baton. */
23956 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
23957 struct dwarf2_loclist_baton
*baton
,
23958 const struct attribute
*attr
)
23960 struct dwarf2_per_objfile
*dwarf2_per_objfile
23961 = cu
->per_cu
->dwarf2_per_objfile
;
23962 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
23964 section
->read (dwarf2_per_objfile
->objfile
);
23966 baton
->per_cu
= cu
->per_cu
;
23967 gdb_assert (baton
->per_cu
);
23968 /* We don't know how long the location list is, but make sure we
23969 don't run off the edge of the section. */
23970 baton
->size
= section
->size
- DW_UNSND (attr
);
23971 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
23972 baton
->base_address
= cu
->base_address
;
23973 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
23977 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
23978 struct dwarf2_cu
*cu
, int is_block
)
23980 struct dwarf2_per_objfile
*dwarf2_per_objfile
23981 = cu
->per_cu
->dwarf2_per_objfile
;
23982 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23983 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
23985 if (attr
->form_is_section_offset ()
23986 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
23987 the section. If so, fall through to the complaint in the
23989 && DW_UNSND (attr
) < section
->get_size (objfile
))
23991 struct dwarf2_loclist_baton
*baton
;
23993 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
23995 fill_in_loclist_baton (cu
, baton
, attr
);
23997 if (cu
->base_known
== 0)
23998 complaint (_("Location list used without "
23999 "specifying the CU base address."));
24001 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24002 ? dwarf2_loclist_block_index
24003 : dwarf2_loclist_index
);
24004 SYMBOL_LOCATION_BATON (sym
) = baton
;
24008 struct dwarf2_locexpr_baton
*baton
;
24010 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
24011 baton
->per_cu
= cu
->per_cu
;
24012 gdb_assert (baton
->per_cu
);
24014 if (attr
->form_is_block ())
24016 /* Note that we're just copying the block's data pointer
24017 here, not the actual data. We're still pointing into the
24018 info_buffer for SYM's objfile; right now we never release
24019 that buffer, but when we do clean up properly this may
24021 baton
->size
= DW_BLOCK (attr
)->size
;
24022 baton
->data
= DW_BLOCK (attr
)->data
;
24026 dwarf2_invalid_attrib_class_complaint ("location description",
24027 sym
->natural_name ());
24031 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24032 ? dwarf2_locexpr_block_index
24033 : dwarf2_locexpr_index
);
24034 SYMBOL_LOCATION_BATON (sym
) = baton
;
24041 dwarf2_per_cu_data::objfile () const
24043 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24045 /* Return the master objfile, so that we can report and look up the
24046 correct file containing this variable. */
24047 if (objfile
->separate_debug_objfile_backlink
)
24048 objfile
= objfile
->separate_debug_objfile_backlink
;
24053 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
24054 (CU_HEADERP is unused in such case) or prepare a temporary copy at
24055 CU_HEADERP first. */
24057 static const struct comp_unit_head
*
24058 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
24059 const struct dwarf2_per_cu_data
*per_cu
)
24061 const gdb_byte
*info_ptr
;
24064 return &per_cu
->cu
->header
;
24066 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
24068 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
24069 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
24070 rcuh_kind::COMPILE
);
24078 dwarf2_per_cu_data::addr_size () const
24080 struct comp_unit_head cu_header_local
;
24081 const struct comp_unit_head
*cu_headerp
;
24083 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
24085 return cu_headerp
->addr_size
;
24091 dwarf2_per_cu_data::offset_size () const
24093 struct comp_unit_head cu_header_local
;
24094 const struct comp_unit_head
*cu_headerp
;
24096 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
24098 return cu_headerp
->offset_size
;
24104 dwarf2_per_cu_data::ref_addr_size () const
24106 struct comp_unit_head cu_header_local
;
24107 const struct comp_unit_head
*cu_headerp
;
24109 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
24111 if (cu_headerp
->version
== 2)
24112 return cu_headerp
->addr_size
;
24114 return cu_headerp
->offset_size
;
24120 dwarf2_per_cu_data::text_offset () const
24122 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24124 return objfile
->text_section_offset ();
24130 dwarf2_per_cu_data::addr_type () const
24132 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24133 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
24134 struct type
*addr_type
= lookup_pointer_type (void_type
);
24135 int addr_size
= this->addr_size ();
24137 if (TYPE_LENGTH (addr_type
) == addr_size
)
24140 addr_type
= addr_sized_int_type (TYPE_UNSIGNED (addr_type
));
24144 /* Locate the .debug_info compilation unit from CU's objfile which contains
24145 the DIE at OFFSET. Raises an error on failure. */
24147 static struct dwarf2_per_cu_data
*
24148 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
24149 unsigned int offset_in_dwz
,
24150 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
24152 struct dwarf2_per_cu_data
*this_cu
;
24156 high
= dwarf2_per_objfile
->all_comp_units
.size () - 1;
24159 struct dwarf2_per_cu_data
*mid_cu
;
24160 int mid
= low
+ (high
- low
) / 2;
24162 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
24163 if (mid_cu
->is_dwz
> offset_in_dwz
24164 || (mid_cu
->is_dwz
== offset_in_dwz
24165 && mid_cu
->sect_off
+ mid_cu
->length
>= sect_off
))
24170 gdb_assert (low
== high
);
24171 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
24172 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
24174 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
24175 error (_("Dwarf Error: could not find partial DIE containing "
24176 "offset %s [in module %s]"),
24177 sect_offset_str (sect_off
),
24178 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
24180 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
24182 return dwarf2_per_objfile
->all_comp_units
[low
-1];
24186 if (low
== dwarf2_per_objfile
->all_comp_units
.size () - 1
24187 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
24188 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
24189 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
24194 /* Initialize dwarf2_cu CU, owned by PER_CU. */
24196 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data
*per_cu_
)
24197 : per_cu (per_cu_
),
24199 has_loclist (false),
24200 checked_producer (false),
24201 producer_is_gxx_lt_4_6 (false),
24202 producer_is_gcc_lt_4_3 (false),
24203 producer_is_icc (false),
24204 producer_is_icc_lt_14 (false),
24205 producer_is_codewarrior (false),
24206 processing_has_namespace_info (false)
24211 /* Destroy a dwarf2_cu. */
24213 dwarf2_cu::~dwarf2_cu ()
24218 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
24221 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
24222 enum language pretend_language
)
24224 struct attribute
*attr
;
24226 /* Set the language we're debugging. */
24227 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
24228 if (attr
!= nullptr)
24229 set_cu_language (DW_UNSND (attr
), cu
);
24232 cu
->language
= pretend_language
;
24233 cu
->language_defn
= language_def (cu
->language
);
24236 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
24239 /* Increase the age counter on each cached compilation unit, and free
24240 any that are too old. */
24243 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
24245 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
24247 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
24248 per_cu
= dwarf2_per_objfile
->read_in_chain
;
24249 while (per_cu
!= NULL
)
24251 per_cu
->cu
->last_used
++;
24252 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
24253 dwarf2_mark (per_cu
->cu
);
24254 per_cu
= per_cu
->cu
->read_in_chain
;
24257 per_cu
= dwarf2_per_objfile
->read_in_chain
;
24258 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
24259 while (per_cu
!= NULL
)
24261 struct dwarf2_per_cu_data
*next_cu
;
24263 next_cu
= per_cu
->cu
->read_in_chain
;
24265 if (!per_cu
->cu
->mark
)
24268 *last_chain
= next_cu
;
24271 last_chain
= &per_cu
->cu
->read_in_chain
;
24277 /* Remove a single compilation unit from the cache. */
24280 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
24282 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
24283 struct dwarf2_per_objfile
*dwarf2_per_objfile
24284 = target_per_cu
->dwarf2_per_objfile
;
24286 per_cu
= dwarf2_per_objfile
->read_in_chain
;
24287 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
24288 while (per_cu
!= NULL
)
24290 struct dwarf2_per_cu_data
*next_cu
;
24292 next_cu
= per_cu
->cu
->read_in_chain
;
24294 if (per_cu
== target_per_cu
)
24298 *last_chain
= next_cu
;
24302 last_chain
= &per_cu
->cu
->read_in_chain
;
24308 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
24309 We store these in a hash table separate from the DIEs, and preserve them
24310 when the DIEs are flushed out of cache.
24312 The CU "per_cu" pointer is needed because offset alone is not enough to
24313 uniquely identify the type. A file may have multiple .debug_types sections,
24314 or the type may come from a DWO file. Furthermore, while it's more logical
24315 to use per_cu->section+offset, with Fission the section with the data is in
24316 the DWO file but we don't know that section at the point we need it.
24317 We have to use something in dwarf2_per_cu_data (or the pointer to it)
24318 because we can enter the lookup routine, get_die_type_at_offset, from
24319 outside this file, and thus won't necessarily have PER_CU->cu.
24320 Fortunately, PER_CU is stable for the life of the objfile. */
24322 struct dwarf2_per_cu_offset_and_type
24324 const struct dwarf2_per_cu_data
*per_cu
;
24325 sect_offset sect_off
;
24329 /* Hash function for a dwarf2_per_cu_offset_and_type. */
24332 per_cu_offset_and_type_hash (const void *item
)
24334 const struct dwarf2_per_cu_offset_and_type
*ofs
24335 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
24337 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
24340 /* Equality function for a dwarf2_per_cu_offset_and_type. */
24343 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
24345 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
24346 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
24347 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
24348 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
24350 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
24351 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
24354 /* Set the type associated with DIE to TYPE. Save it in CU's hash
24355 table if necessary. For convenience, return TYPE.
24357 The DIEs reading must have careful ordering to:
24358 * Not cause infinite loops trying to read in DIEs as a prerequisite for
24359 reading current DIE.
24360 * Not trying to dereference contents of still incompletely read in types
24361 while reading in other DIEs.
24362 * Enable referencing still incompletely read in types just by a pointer to
24363 the type without accessing its fields.
24365 Therefore caller should follow these rules:
24366 * Try to fetch any prerequisite types we may need to build this DIE type
24367 before building the type and calling set_die_type.
24368 * After building type call set_die_type for current DIE as soon as
24369 possible before fetching more types to complete the current type.
24370 * Make the type as complete as possible before fetching more types. */
24372 static struct type
*
24373 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
24375 struct dwarf2_per_objfile
*dwarf2_per_objfile
24376 = cu
->per_cu
->dwarf2_per_objfile
;
24377 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
24378 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24379 struct attribute
*attr
;
24380 struct dynamic_prop prop
;
24382 /* For Ada types, make sure that the gnat-specific data is always
24383 initialized (if not already set). There are a few types where
24384 we should not be doing so, because the type-specific area is
24385 already used to hold some other piece of info (eg: TYPE_CODE_FLT
24386 where the type-specific area is used to store the floatformat).
24387 But this is not a problem, because the gnat-specific information
24388 is actually not needed for these types. */
24389 if (need_gnat_info (cu
)
24390 && TYPE_CODE (type
) != TYPE_CODE_FUNC
24391 && TYPE_CODE (type
) != TYPE_CODE_FLT
24392 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
24393 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
24394 && TYPE_CODE (type
) != TYPE_CODE_METHOD
24395 && !HAVE_GNAT_AUX_INFO (type
))
24396 INIT_GNAT_SPECIFIC (type
);
24398 /* Read DW_AT_allocated and set in type. */
24399 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
24400 if (attr
!= NULL
&& attr
->form_is_block ())
24402 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
24403 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
24404 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
);
24406 else if (attr
!= NULL
)
24408 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
24409 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
24410 sect_offset_str (die
->sect_off
));
24413 /* Read DW_AT_associated and set in type. */
24414 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
24415 if (attr
!= NULL
&& attr
->form_is_block ())
24417 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
24418 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
24419 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
);
24421 else if (attr
!= NULL
)
24423 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
24424 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
24425 sect_offset_str (die
->sect_off
));
24428 /* Read DW_AT_data_location and set in type. */
24429 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
24430 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
,
24431 cu
->per_cu
->addr_type ()))
24432 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
);
24434 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
24435 dwarf2_per_objfile
->die_type_hash
24436 = htab_up (htab_create_alloc (127,
24437 per_cu_offset_and_type_hash
,
24438 per_cu_offset_and_type_eq
,
24439 NULL
, xcalloc
, xfree
));
24441 ofs
.per_cu
= cu
->per_cu
;
24442 ofs
.sect_off
= die
->sect_off
;
24444 slot
= (struct dwarf2_per_cu_offset_and_type
**)
24445 htab_find_slot (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
24447 complaint (_("A problem internal to GDB: DIE %s has type already set"),
24448 sect_offset_str (die
->sect_off
));
24449 *slot
= XOBNEW (&objfile
->objfile_obstack
,
24450 struct dwarf2_per_cu_offset_and_type
);
24455 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
24456 or return NULL if the die does not have a saved type. */
24458 static struct type
*
24459 get_die_type_at_offset (sect_offset sect_off
,
24460 struct dwarf2_per_cu_data
*per_cu
)
24462 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
24463 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
24465 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
24468 ofs
.per_cu
= per_cu
;
24469 ofs
.sect_off
= sect_off
;
24470 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
24471 htab_find (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
));
24478 /* Look up the type for DIE in CU in die_type_hash,
24479 or return NULL if DIE does not have a saved type. */
24481 static struct type
*
24482 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
24484 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
24487 /* Add a dependence relationship from CU to REF_PER_CU. */
24490 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
24491 struct dwarf2_per_cu_data
*ref_per_cu
)
24495 if (cu
->dependencies
== NULL
)
24497 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
24498 NULL
, &cu
->comp_unit_obstack
,
24499 hashtab_obstack_allocate
,
24500 dummy_obstack_deallocate
);
24502 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
24504 *slot
= ref_per_cu
;
24507 /* Subroutine of dwarf2_mark to pass to htab_traverse.
24508 Set the mark field in every compilation unit in the
24509 cache that we must keep because we are keeping CU. */
24512 dwarf2_mark_helper (void **slot
, void *data
)
24514 struct dwarf2_per_cu_data
*per_cu
;
24516 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
24518 /* cu->dependencies references may not yet have been ever read if QUIT aborts
24519 reading of the chain. As such dependencies remain valid it is not much
24520 useful to track and undo them during QUIT cleanups. */
24521 if (per_cu
->cu
== NULL
)
24524 if (per_cu
->cu
->mark
)
24526 per_cu
->cu
->mark
= true;
24528 if (per_cu
->cu
->dependencies
!= NULL
)
24529 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
24534 /* Set the mark field in CU and in every other compilation unit in the
24535 cache that we must keep because we are keeping CU. */
24538 dwarf2_mark (struct dwarf2_cu
*cu
)
24543 if (cu
->dependencies
!= NULL
)
24544 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
24548 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
24552 per_cu
->cu
->mark
= false;
24553 per_cu
= per_cu
->cu
->read_in_chain
;
24557 /* Trivial hash function for partial_die_info: the hash value of a DIE
24558 is its offset in .debug_info for this objfile. */
24561 partial_die_hash (const void *item
)
24563 const struct partial_die_info
*part_die
24564 = (const struct partial_die_info
*) item
;
24566 return to_underlying (part_die
->sect_off
);
24569 /* Trivial comparison function for partial_die_info structures: two DIEs
24570 are equal if they have the same offset. */
24573 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
24575 const struct partial_die_info
*part_die_lhs
24576 = (const struct partial_die_info
*) item_lhs
;
24577 const struct partial_die_info
*part_die_rhs
24578 = (const struct partial_die_info
*) item_rhs
;
24580 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
24583 struct cmd_list_element
*set_dwarf_cmdlist
;
24584 struct cmd_list_element
*show_dwarf_cmdlist
;
24587 set_dwarf_cmd (const char *args
, int from_tty
)
24589 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
24594 show_dwarf_cmd (const char *args
, int from_tty
)
24596 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
24600 show_check_physname (struct ui_file
*file
, int from_tty
,
24601 struct cmd_list_element
*c
, const char *value
)
24603 fprintf_filtered (file
,
24604 _("Whether to check \"physname\" is %s.\n"),
24608 void _initialize_dwarf2_read ();
24610 _initialize_dwarf2_read ()
24612 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
24613 Set DWARF specific variables.\n\
24614 Configure DWARF variables such as the cache size."),
24615 &set_dwarf_cmdlist
, "maintenance set dwarf ",
24616 0/*allow-unknown*/, &maintenance_set_cmdlist
);
24618 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
24619 Show DWARF specific variables.\n\
24620 Show DWARF variables such as the cache size."),
24621 &show_dwarf_cmdlist
, "maintenance show dwarf ",
24622 0/*allow-unknown*/, &maintenance_show_cmdlist
);
24624 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
24625 &dwarf_max_cache_age
, _("\
24626 Set the upper bound on the age of cached DWARF compilation units."), _("\
24627 Show the upper bound on the age of cached DWARF compilation units."), _("\
24628 A higher limit means that cached compilation units will be stored\n\
24629 in memory longer, and more total memory will be used. Zero disables\n\
24630 caching, which can slow down startup."),
24632 show_dwarf_max_cache_age
,
24633 &set_dwarf_cmdlist
,
24634 &show_dwarf_cmdlist
);
24636 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
24637 Set debugging of the DWARF reader."), _("\
24638 Show debugging of the DWARF reader."), _("\
24639 When enabled (non-zero), debugging messages are printed during DWARF\n\
24640 reading and symtab expansion. A value of 1 (one) provides basic\n\
24641 information. A value greater than 1 provides more verbose information."),
24644 &setdebuglist
, &showdebuglist
);
24646 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
24647 Set debugging of the DWARF DIE reader."), _("\
24648 Show debugging of the DWARF DIE reader."), _("\
24649 When enabled (non-zero), DIEs are dumped after they are read in.\n\
24650 The value is the maximum depth to print."),
24653 &setdebuglist
, &showdebuglist
);
24655 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
24656 Set debugging of the dwarf line reader."), _("\
24657 Show debugging of the dwarf line reader."), _("\
24658 When enabled (non-zero), line number entries are dumped as they are read in.\n\
24659 A value of 1 (one) provides basic information.\n\
24660 A value greater than 1 provides more verbose information."),
24663 &setdebuglist
, &showdebuglist
);
24665 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
24666 Set cross-checking of \"physname\" code against demangler."), _("\
24667 Show cross-checking of \"physname\" code against demangler."), _("\
24668 When enabled, GDB's internal \"physname\" code is checked against\n\
24670 NULL
, show_check_physname
,
24671 &setdebuglist
, &showdebuglist
);
24673 add_setshow_boolean_cmd ("use-deprecated-index-sections",
24674 no_class
, &use_deprecated_index_sections
, _("\
24675 Set whether to use deprecated gdb_index sections."), _("\
24676 Show whether to use deprecated gdb_index sections."), _("\
24677 When enabled, deprecated .gdb_index sections are used anyway.\n\
24678 Normally they are ignored either because of a missing feature or\n\
24679 performance issue.\n\
24680 Warning: This option must be enabled before gdb reads the file."),
24683 &setlist
, &showlist
);
24685 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24686 &dwarf2_locexpr_funcs
);
24687 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24688 &dwarf2_loclist_funcs
);
24690 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24691 &dwarf2_block_frame_base_locexpr_funcs
);
24692 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24693 &dwarf2_block_frame_base_loclist_funcs
);
24696 selftests::register_test ("dw2_expand_symtabs_matching",
24697 selftests::dw2_expand_symtabs_matching::run_test
);