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
,
884 int use_existing_cu
, int keep
,
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);
893 DISABLE_COPY_AND_ASSIGN (cutu_reader
);
895 const gdb_byte
*info_ptr
= nullptr;
896 struct die_info
*comp_unit_die
= nullptr;
897 bool dummy_p
= false;
900 void init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
901 int use_existing_cu
, int keep
);
903 struct dwarf2_per_cu_data
*m_this_cu
;
905 std::unique_ptr
<dwarf2_cu
> m_new_cu
;
907 /* The ordinary abbreviation table. */
908 abbrev_table_up m_abbrev_table_holder
;
910 /* The DWO abbreviation table. */
911 abbrev_table_up m_dwo_abbrev_table
;
914 /* When we construct a partial symbol table entry we only
915 need this much information. */
916 struct partial_die_info
: public allocate_on_obstack
918 partial_die_info (sect_offset sect_off
, struct abbrev_info
*abbrev
);
920 /* Disable assign but still keep copy ctor, which is needed
921 load_partial_dies. */
922 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
924 /* Adjust the partial die before generating a symbol for it. This
925 function may set the is_external flag or change the DIE's
927 void fixup (struct dwarf2_cu
*cu
);
929 /* Read a minimal amount of information into the minimal die
931 const gdb_byte
*read (const struct die_reader_specs
*reader
,
932 const struct abbrev_info
&abbrev
,
933 const gdb_byte
*info_ptr
);
935 /* Offset of this DIE. */
936 const sect_offset sect_off
;
938 /* DWARF-2 tag for this DIE. */
939 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
941 /* Assorted flags describing the data found in this DIE. */
942 const unsigned int has_children
: 1;
944 unsigned int is_external
: 1;
945 unsigned int is_declaration
: 1;
946 unsigned int has_type
: 1;
947 unsigned int has_specification
: 1;
948 unsigned int has_pc_info
: 1;
949 unsigned int may_be_inlined
: 1;
951 /* This DIE has been marked DW_AT_main_subprogram. */
952 unsigned int main_subprogram
: 1;
954 /* Flag set if the SCOPE field of this structure has been
956 unsigned int scope_set
: 1;
958 /* Flag set if the DIE has a byte_size attribute. */
959 unsigned int has_byte_size
: 1;
961 /* Flag set if the DIE has a DW_AT_const_value attribute. */
962 unsigned int has_const_value
: 1;
964 /* Flag set if any of the DIE's children are template arguments. */
965 unsigned int has_template_arguments
: 1;
967 /* Flag set if fixup has been called on this die. */
968 unsigned int fixup_called
: 1;
970 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
971 unsigned int is_dwz
: 1;
973 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
974 unsigned int spec_is_dwz
: 1;
976 /* The name of this DIE. Normally the value of DW_AT_name, but
977 sometimes a default name for unnamed DIEs. */
978 const char *name
= nullptr;
980 /* The linkage name, if present. */
981 const char *linkage_name
= nullptr;
983 /* The scope to prepend to our children. This is generally
984 allocated on the comp_unit_obstack, so will disappear
985 when this compilation unit leaves the cache. */
986 const char *scope
= nullptr;
988 /* Some data associated with the partial DIE. The tag determines
989 which field is live. */
992 /* The location description associated with this DIE, if any. */
993 struct dwarf_block
*locdesc
;
994 /* The offset of an import, for DW_TAG_imported_unit. */
995 sect_offset sect_off
;
998 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1000 CORE_ADDR highpc
= 0;
1002 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1003 DW_AT_sibling, if any. */
1004 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1005 could return DW_AT_sibling values to its caller load_partial_dies. */
1006 const gdb_byte
*sibling
= nullptr;
1008 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1009 DW_AT_specification (or DW_AT_abstract_origin or
1010 DW_AT_extension). */
1011 sect_offset spec_offset
{};
1013 /* Pointers to this DIE's parent, first child, and next sibling,
1015 struct partial_die_info
*die_parent
= nullptr;
1016 struct partial_die_info
*die_child
= nullptr;
1017 struct partial_die_info
*die_sibling
= nullptr;
1019 friend struct partial_die_info
*
1020 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1023 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1024 partial_die_info (sect_offset sect_off
)
1025 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1029 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1031 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1036 has_specification
= 0;
1039 main_subprogram
= 0;
1042 has_const_value
= 0;
1043 has_template_arguments
= 0;
1050 /* This data structure holds a complete die structure. */
1053 /* DWARF-2 tag for this DIE. */
1054 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1056 /* Number of attributes */
1057 unsigned char num_attrs
;
1059 /* True if we're presently building the full type name for the
1060 type derived from this DIE. */
1061 unsigned char building_fullname
: 1;
1063 /* True if this die is in process. PR 16581. */
1064 unsigned char in_process
: 1;
1066 /* True if this DIE has children. */
1067 unsigned char has_children
: 1;
1070 unsigned int abbrev
;
1072 /* Offset in .debug_info or .debug_types section. */
1073 sect_offset sect_off
;
1075 /* The dies in a compilation unit form an n-ary tree. PARENT
1076 points to this die's parent; CHILD points to the first child of
1077 this node; and all the children of a given node are chained
1078 together via their SIBLING fields. */
1079 struct die_info
*child
; /* Its first child, if any. */
1080 struct die_info
*sibling
; /* Its next sibling, if any. */
1081 struct die_info
*parent
; /* Its parent, if any. */
1083 /* An array of attributes, with NUM_ATTRS elements. There may be
1084 zero, but it's not common and zero-sized arrays are not
1085 sufficiently portable C. */
1086 struct attribute attrs
[1];
1089 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1090 but this would require a corresponding change in unpack_field_as_long
1092 static int bits_per_byte
= 8;
1094 /* When reading a variant or variant part, we track a bit more
1095 information about the field, and store it in an object of this
1098 struct variant_field
1100 /* If we see a DW_TAG_variant, then this will be the discriminant
1102 ULONGEST discriminant_value
;
1103 /* If we see a DW_TAG_variant, then this will be set if this is the
1105 bool default_branch
;
1106 /* While reading a DW_TAG_variant_part, this will be set if this
1107 field is the discriminant. */
1108 bool is_discriminant
;
1113 int accessibility
= 0;
1115 /* Extra information to describe a variant or variant part. */
1116 struct variant_field variant
{};
1117 struct field field
{};
1122 const char *name
= nullptr;
1123 std::vector
<struct fn_field
> fnfields
;
1126 /* The routines that read and process dies for a C struct or C++ class
1127 pass lists of data member fields and lists of member function fields
1128 in an instance of a field_info structure, as defined below. */
1131 /* List of data member and baseclasses fields. */
1132 std::vector
<struct nextfield
> fields
;
1133 std::vector
<struct nextfield
> baseclasses
;
1135 /* Number of fields (including baseclasses). */
1138 /* Set if the accessibility of one of the fields is not public. */
1139 int non_public_fields
= 0;
1141 /* Member function fieldlist array, contains name of possibly overloaded
1142 member function, number of overloaded member functions and a pointer
1143 to the head of the member function field chain. */
1144 std::vector
<struct fnfieldlist
> fnfieldlists
;
1146 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1147 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1148 std::vector
<struct decl_field
> typedef_field_list
;
1150 /* Nested types defined by this class and the number of elements in this
1152 std::vector
<struct decl_field
> nested_types_list
;
1155 /* Loaded secondary compilation units are kept in memory until they
1156 have not been referenced for the processing of this many
1157 compilation units. Set this to zero to disable caching. Cache
1158 sizes of up to at least twenty will improve startup time for
1159 typical inter-CU-reference binaries, at an obvious memory cost. */
1160 static int dwarf_max_cache_age
= 5;
1162 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1163 struct cmd_list_element
*c
, const char *value
)
1165 fprintf_filtered (file
, _("The upper bound on the age of cached "
1166 "DWARF compilation units is %s.\n"),
1170 /* local function prototypes */
1172 static void dwarf2_find_base_address (struct die_info
*die
,
1173 struct dwarf2_cu
*cu
);
1175 static dwarf2_psymtab
*create_partial_symtab
1176 (struct dwarf2_per_cu_data
*per_cu
, const char *name
);
1178 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1179 const gdb_byte
*info_ptr
,
1180 struct die_info
*type_unit_die
);
1182 static void dwarf2_build_psymtabs_hard
1183 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1185 static void scan_partial_symbols (struct partial_die_info
*,
1186 CORE_ADDR
*, CORE_ADDR
*,
1187 int, struct dwarf2_cu
*);
1189 static void add_partial_symbol (struct partial_die_info
*,
1190 struct dwarf2_cu
*);
1192 static void add_partial_namespace (struct partial_die_info
*pdi
,
1193 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1194 int set_addrmap
, struct dwarf2_cu
*cu
);
1196 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1197 CORE_ADDR
*highpc
, int set_addrmap
,
1198 struct dwarf2_cu
*cu
);
1200 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1201 struct dwarf2_cu
*cu
);
1203 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1204 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1205 int need_pc
, struct dwarf2_cu
*cu
);
1207 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1209 static struct partial_die_info
*load_partial_dies
1210 (const struct die_reader_specs
*, const gdb_byte
*, int);
1212 /* A pair of partial_die_info and compilation unit. */
1213 struct cu_partial_die_info
1215 /* The compilation unit of the partial_die_info. */
1216 struct dwarf2_cu
*cu
;
1217 /* A partial_die_info. */
1218 struct partial_die_info
*pdi
;
1220 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1226 cu_partial_die_info () = delete;
1229 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1230 struct dwarf2_cu
*);
1232 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1233 struct attribute
*, struct attr_abbrev
*,
1234 const gdb_byte
*, bool *need_reprocess
);
1236 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1237 struct attribute
*attr
);
1239 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1241 static LONGEST read_checked_initial_length_and_offset
1242 (bfd
*, const gdb_byte
*, const struct comp_unit_head
*,
1243 unsigned int *, unsigned int *);
1245 static sect_offset read_abbrev_offset
1246 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1247 struct dwarf2_section_info
*, sect_offset
);
1249 static const char *read_indirect_string
1250 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1251 const struct comp_unit_head
*, unsigned int *);
1253 static const char *read_indirect_line_string
1254 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1255 const struct comp_unit_head
*, unsigned int *);
1257 static const char *read_indirect_string_at_offset
1258 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
1259 LONGEST str_offset
);
1261 static const char *read_indirect_string_from_dwz
1262 (struct objfile
*objfile
, struct dwz_file
*, LONGEST
);
1264 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1268 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1269 ULONGEST str_index
);
1271 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1272 ULONGEST str_index
);
1274 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1276 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1277 struct dwarf2_cu
*);
1279 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1282 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1283 struct dwarf2_cu
*cu
);
1285 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1287 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1288 struct dwarf2_cu
*cu
);
1290 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1292 static struct die_info
*die_specification (struct die_info
*die
,
1293 struct dwarf2_cu
**);
1295 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1296 struct dwarf2_cu
*cu
);
1298 static void dwarf_decode_lines (struct line_header
*, const char *,
1299 struct dwarf2_cu
*, dwarf2_psymtab
*,
1300 CORE_ADDR
, int decode_mapping
);
1302 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1305 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1306 struct dwarf2_cu
*, struct symbol
* = NULL
);
1308 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1309 struct dwarf2_cu
*);
1311 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1314 struct obstack
*obstack
,
1315 struct dwarf2_cu
*cu
, LONGEST
*value
,
1316 const gdb_byte
**bytes
,
1317 struct dwarf2_locexpr_baton
**baton
);
1319 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1321 static int need_gnat_info (struct dwarf2_cu
*);
1323 static struct type
*die_descriptive_type (struct die_info
*,
1324 struct dwarf2_cu
*);
1326 static void set_descriptive_type (struct type
*, struct die_info
*,
1327 struct dwarf2_cu
*);
1329 static struct type
*die_containing_type (struct die_info
*,
1330 struct dwarf2_cu
*);
1332 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1333 struct dwarf2_cu
*);
1335 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1337 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1339 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1341 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1342 const char *suffix
, int physname
,
1343 struct dwarf2_cu
*cu
);
1345 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1347 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1349 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1351 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1353 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1355 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1357 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1358 struct dwarf2_cu
*, dwarf2_psymtab
*);
1360 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1361 values. Keep the items ordered with increasing constraints compliance. */
1364 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1365 PC_BOUNDS_NOT_PRESENT
,
1367 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1368 were present but they do not form a valid range of PC addresses. */
1371 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1374 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1378 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1379 CORE_ADDR
*, CORE_ADDR
*,
1383 static void get_scope_pc_bounds (struct die_info
*,
1384 CORE_ADDR
*, CORE_ADDR
*,
1385 struct dwarf2_cu
*);
1387 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1388 CORE_ADDR
, struct dwarf2_cu
*);
1390 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1391 struct dwarf2_cu
*);
1393 static void dwarf2_attach_fields_to_type (struct field_info
*,
1394 struct type
*, struct dwarf2_cu
*);
1396 static void dwarf2_add_member_fn (struct field_info
*,
1397 struct die_info
*, struct type
*,
1398 struct dwarf2_cu
*);
1400 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1402 struct dwarf2_cu
*);
1404 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1406 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1408 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1410 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1412 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1414 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1416 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1418 static struct type
*read_module_type (struct die_info
*die
,
1419 struct dwarf2_cu
*cu
);
1421 static const char *namespace_name (struct die_info
*die
,
1422 int *is_anonymous
, struct dwarf2_cu
*);
1424 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1426 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1428 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1429 struct dwarf2_cu
*);
1431 static struct die_info
*read_die_and_siblings_1
1432 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1435 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1436 const gdb_byte
*info_ptr
,
1437 const gdb_byte
**new_info_ptr
,
1438 struct die_info
*parent
);
1440 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1441 struct die_info
**, const gdb_byte
*,
1444 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1445 struct die_info
**, const gdb_byte
*);
1447 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1449 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1452 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1454 static const char *dwarf2_full_name (const char *name
,
1455 struct die_info
*die
,
1456 struct dwarf2_cu
*cu
);
1458 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1459 struct dwarf2_cu
*cu
);
1461 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1462 struct dwarf2_cu
**);
1464 static const char *dwarf_tag_name (unsigned int);
1466 static const char *dwarf_attr_name (unsigned int);
1468 static const char *dwarf_form_name (unsigned int);
1470 static const char *dwarf_bool_name (unsigned int);
1472 static const char *dwarf_type_encoding_name (unsigned int);
1474 static struct die_info
*sibling_die (struct die_info
*);
1476 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1478 static void dump_die_for_error (struct die_info
*);
1480 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1483 /*static*/ void dump_die (struct die_info
*, int max_level
);
1485 static void store_in_ref_table (struct die_info
*,
1486 struct dwarf2_cu
*);
1488 static sect_offset
dwarf2_get_ref_die_offset (const struct attribute
*);
1490 static LONGEST
dwarf2_get_attr_constant_value (const struct attribute
*, int);
1492 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1493 const struct attribute
*,
1494 struct dwarf2_cu
**);
1496 static struct die_info
*follow_die_ref (struct die_info
*,
1497 const struct attribute
*,
1498 struct dwarf2_cu
**);
1500 static struct die_info
*follow_die_sig (struct die_info
*,
1501 const struct attribute
*,
1502 struct dwarf2_cu
**);
1504 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1505 struct dwarf2_cu
*);
1507 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1508 const struct attribute
*,
1509 struct dwarf2_cu
*);
1511 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1513 static void read_signatured_type (struct signatured_type
*);
1515 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1516 struct die_info
*die
, struct dwarf2_cu
*cu
,
1517 struct dynamic_prop
*prop
, struct type
*type
);
1519 /* memory allocation interface */
1521 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1523 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1525 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1527 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1528 struct dwarf2_loclist_baton
*baton
,
1529 const struct attribute
*attr
);
1531 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1533 struct dwarf2_cu
*cu
,
1536 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1537 const gdb_byte
*info_ptr
,
1538 struct abbrev_info
*abbrev
);
1540 static hashval_t
partial_die_hash (const void *item
);
1542 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1544 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1545 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1546 struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1548 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1549 struct die_info
*comp_unit_die
,
1550 enum language pretend_language
);
1552 static void age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1554 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1556 static struct type
*set_die_type (struct die_info
*, struct type
*,
1557 struct dwarf2_cu
*);
1559 static void create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1561 static int create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1563 static void load_full_comp_unit (struct dwarf2_per_cu_data
*, bool,
1566 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1569 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1572 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1573 struct dwarf2_per_cu_data
*);
1575 static void dwarf2_mark (struct dwarf2_cu
*);
1577 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1579 static struct type
*get_die_type_at_offset (sect_offset
,
1580 struct dwarf2_per_cu_data
*);
1582 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1584 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1585 enum language pretend_language
);
1587 static void process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1589 /* Class, the destructor of which frees all allocated queue entries. This
1590 will only have work to do if an error was thrown while processing the
1591 dwarf. If no error was thrown then the queue entries should have all
1592 been processed, and freed, as we went along. */
1594 class dwarf2_queue_guard
1597 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1598 : m_per_objfile (per_objfile
)
1602 /* Free any entries remaining on the queue. There should only be
1603 entries left if we hit an error while processing the dwarf. */
1604 ~dwarf2_queue_guard ()
1606 /* Ensure that no memory is allocated by the queue. */
1607 std::queue
<dwarf2_queue_item
> empty
;
1608 std::swap (m_per_objfile
->queue
, empty
);
1611 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1614 dwarf2_per_objfile
*m_per_objfile
;
1617 dwarf2_queue_item::~dwarf2_queue_item ()
1619 /* Anything still marked queued is likely to be in an
1620 inconsistent state, so discard it. */
1623 if (per_cu
->cu
!= NULL
)
1624 free_one_cached_comp_unit (per_cu
);
1629 /* The return type of find_file_and_directory. Note, the enclosed
1630 string pointers are only valid while this object is valid. */
1632 struct file_and_directory
1634 /* The filename. This is never NULL. */
1637 /* The compilation directory. NULL if not known. If we needed to
1638 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1639 points directly to the DW_AT_comp_dir string attribute owned by
1640 the obstack that owns the DIE. */
1641 const char *comp_dir
;
1643 /* If we needed to build a new string for comp_dir, this is what
1644 owns the storage. */
1645 std::string comp_dir_storage
;
1648 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1649 struct dwarf2_cu
*cu
);
1651 static htab_up
allocate_signatured_type_table (struct objfile
*objfile
);
1653 static htab_up
allocate_dwo_unit_table (struct objfile
*objfile
);
1655 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1656 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1657 struct dwp_file
*dwp_file
, const char *comp_dir
,
1658 ULONGEST signature
, int is_debug_types
);
1660 static struct dwp_file
*get_dwp_file
1661 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1663 static struct dwo_unit
*lookup_dwo_comp_unit
1664 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
1666 static struct dwo_unit
*lookup_dwo_type_unit
1667 (struct signatured_type
*, const char *, const char *);
1669 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
1671 /* A unique pointer to a dwo_file. */
1673 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1675 static void process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1677 static void check_producer (struct dwarf2_cu
*cu
);
1679 static void free_line_header_voidp (void *arg
);
1681 /* Various complaints about symbol reading that don't abort the process. */
1684 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
1686 complaint (_("statement list doesn't fit in .debug_line section"));
1690 dwarf2_debug_line_missing_file_complaint (void)
1692 complaint (_(".debug_line section has line data without a file"));
1696 dwarf2_debug_line_missing_end_sequence_complaint (void)
1698 complaint (_(".debug_line section has line "
1699 "program sequence without an end"));
1703 dwarf2_complex_location_expr_complaint (void)
1705 complaint (_("location expression too complex"));
1709 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1712 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1717 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
1719 complaint (_("debug info runs off end of %s section"
1721 section
->get_name (),
1722 section
->get_file_name ());
1726 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
1728 complaint (_("macro debug info contains a "
1729 "malformed macro definition:\n`%s'"),
1734 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1736 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1740 /* Hash function for line_header_hash. */
1743 line_header_hash (const struct line_header
*ofs
)
1745 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1748 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1751 line_header_hash_voidp (const void *item
)
1753 const struct line_header
*ofs
= (const struct line_header
*) item
;
1755 return line_header_hash (ofs
);
1758 /* Equality function for line_header_hash. */
1761 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1763 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1764 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1766 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1767 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
1772 /* See declaration. */
1774 dwarf2_per_objfile::dwarf2_per_objfile (struct objfile
*objfile_
,
1775 const dwarf2_debug_sections
*names
,
1777 : objfile (objfile_
),
1778 can_copy (can_copy_
)
1781 names
= &dwarf2_elf_names
;
1783 bfd
*obfd
= objfile
->obfd
;
1785 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1786 locate_sections (obfd
, sec
, *names
);
1789 dwarf2_per_objfile::~dwarf2_per_objfile ()
1791 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
1792 free_cached_comp_units ();
1794 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
1795 per_cu
->imported_symtabs_free ();
1797 for (signatured_type
*sig_type
: all_type_units
)
1798 sig_type
->per_cu
.imported_symtabs_free ();
1800 /* Everything else should be on the objfile obstack. */
1803 /* See declaration. */
1806 dwarf2_per_objfile::free_cached_comp_units ()
1808 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
1809 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
1810 while (per_cu
!= NULL
)
1812 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
1815 *last_chain
= next_cu
;
1820 /* A helper class that calls free_cached_comp_units on
1823 class free_cached_comp_units
1827 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1828 : m_per_objfile (per_objfile
)
1832 ~free_cached_comp_units ()
1834 m_per_objfile
->free_cached_comp_units ();
1837 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1841 dwarf2_per_objfile
*m_per_objfile
;
1844 /* Try to locate the sections we need for DWARF 2 debugging
1845 information and return true if we have enough to do something.
1846 NAMES points to the dwarf2 section names, or is NULL if the standard
1847 ELF names are used. CAN_COPY is true for formats where symbol
1848 interposition is possible and so symbol values must follow copy
1849 relocation rules. */
1852 dwarf2_has_info (struct objfile
*objfile
,
1853 const struct dwarf2_debug_sections
*names
,
1856 if (objfile
->flags
& OBJF_READNEVER
)
1859 struct dwarf2_per_objfile
*dwarf2_per_objfile
1860 = get_dwarf2_per_objfile (objfile
);
1862 if (dwarf2_per_objfile
== NULL
)
1863 dwarf2_per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
,
1867 return (!dwarf2_per_objfile
->info
.is_virtual
1868 && dwarf2_per_objfile
->info
.s
.section
!= NULL
1869 && !dwarf2_per_objfile
->abbrev
.is_virtual
1870 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
1873 /* When loading sections, we look either for uncompressed section or for
1874 compressed section names. */
1877 section_is_p (const char *section_name
,
1878 const struct dwarf2_section_names
*names
)
1880 if (names
->normal
!= NULL
1881 && strcmp (section_name
, names
->normal
) == 0)
1883 if (names
->compressed
!= NULL
1884 && strcmp (section_name
, names
->compressed
) == 0)
1889 /* See declaration. */
1892 dwarf2_per_objfile::locate_sections (bfd
*abfd
, asection
*sectp
,
1893 const dwarf2_debug_sections
&names
)
1895 flagword aflag
= bfd_section_flags (sectp
);
1897 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1900 else if (elf_section_data (sectp
)->this_hdr
.sh_size
1901 > bfd_get_file_size (abfd
))
1903 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
1904 warning (_("Discarding section %s which has a section size (%s"
1905 ") larger than the file size [in module %s]"),
1906 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
1907 bfd_get_filename (abfd
));
1909 else if (section_is_p (sectp
->name
, &names
.info
))
1911 this->info
.s
.section
= sectp
;
1912 this->info
.size
= bfd_section_size (sectp
);
1914 else if (section_is_p (sectp
->name
, &names
.abbrev
))
1916 this->abbrev
.s
.section
= sectp
;
1917 this->abbrev
.size
= bfd_section_size (sectp
);
1919 else if (section_is_p (sectp
->name
, &names
.line
))
1921 this->line
.s
.section
= sectp
;
1922 this->line
.size
= bfd_section_size (sectp
);
1924 else if (section_is_p (sectp
->name
, &names
.loc
))
1926 this->loc
.s
.section
= sectp
;
1927 this->loc
.size
= bfd_section_size (sectp
);
1929 else if (section_is_p (sectp
->name
, &names
.loclists
))
1931 this->loclists
.s
.section
= sectp
;
1932 this->loclists
.size
= bfd_section_size (sectp
);
1934 else if (section_is_p (sectp
->name
, &names
.macinfo
))
1936 this->macinfo
.s
.section
= sectp
;
1937 this->macinfo
.size
= bfd_section_size (sectp
);
1939 else if (section_is_p (sectp
->name
, &names
.macro
))
1941 this->macro
.s
.section
= sectp
;
1942 this->macro
.size
= bfd_section_size (sectp
);
1944 else if (section_is_p (sectp
->name
, &names
.str
))
1946 this->str
.s
.section
= sectp
;
1947 this->str
.size
= bfd_section_size (sectp
);
1949 else if (section_is_p (sectp
->name
, &names
.str_offsets
))
1951 this->str_offsets
.s
.section
= sectp
;
1952 this->str_offsets
.size
= bfd_section_size (sectp
);
1954 else if (section_is_p (sectp
->name
, &names
.line_str
))
1956 this->line_str
.s
.section
= sectp
;
1957 this->line_str
.size
= bfd_section_size (sectp
);
1959 else if (section_is_p (sectp
->name
, &names
.addr
))
1961 this->addr
.s
.section
= sectp
;
1962 this->addr
.size
= bfd_section_size (sectp
);
1964 else if (section_is_p (sectp
->name
, &names
.frame
))
1966 this->frame
.s
.section
= sectp
;
1967 this->frame
.size
= bfd_section_size (sectp
);
1969 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
1971 this->eh_frame
.s
.section
= sectp
;
1972 this->eh_frame
.size
= bfd_section_size (sectp
);
1974 else if (section_is_p (sectp
->name
, &names
.ranges
))
1976 this->ranges
.s
.section
= sectp
;
1977 this->ranges
.size
= bfd_section_size (sectp
);
1979 else if (section_is_p (sectp
->name
, &names
.rnglists
))
1981 this->rnglists
.s
.section
= sectp
;
1982 this->rnglists
.size
= bfd_section_size (sectp
);
1984 else if (section_is_p (sectp
->name
, &names
.types
))
1986 struct dwarf2_section_info type_section
;
1988 memset (&type_section
, 0, sizeof (type_section
));
1989 type_section
.s
.section
= sectp
;
1990 type_section
.size
= bfd_section_size (sectp
);
1992 this->types
.push_back (type_section
);
1994 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
1996 this->gdb_index
.s
.section
= sectp
;
1997 this->gdb_index
.size
= bfd_section_size (sectp
);
1999 else if (section_is_p (sectp
->name
, &names
.debug_names
))
2001 this->debug_names
.s
.section
= sectp
;
2002 this->debug_names
.size
= bfd_section_size (sectp
);
2004 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
2006 this->debug_aranges
.s
.section
= sectp
;
2007 this->debug_aranges
.size
= bfd_section_size (sectp
);
2010 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2011 && bfd_section_vma (sectp
) == 0)
2012 this->has_section_at_zero
= true;
2015 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2019 dwarf2_get_section_info (struct objfile
*objfile
,
2020 enum dwarf2_section_enum sect
,
2021 asection
**sectp
, const gdb_byte
**bufp
,
2022 bfd_size_type
*sizep
)
2024 struct dwarf2_per_objfile
*data
= dwarf2_objfile_data_key
.get (objfile
);
2025 struct dwarf2_section_info
*info
;
2027 /* We may see an objfile without any DWARF, in which case we just
2038 case DWARF2_DEBUG_FRAME
:
2039 info
= &data
->frame
;
2041 case DWARF2_EH_FRAME
:
2042 info
= &data
->eh_frame
;
2045 gdb_assert_not_reached ("unexpected section");
2048 info
->read (objfile
);
2050 *sectp
= info
->get_bfd_section ();
2051 *bufp
= info
->buffer
;
2052 *sizep
= info
->size
;
2055 /* A helper function to find the sections for a .dwz file. */
2058 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2060 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2062 /* Note that we only support the standard ELF names, because .dwz
2063 is ELF-only (at the time of writing). */
2064 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2066 dwz_file
->abbrev
.s
.section
= sectp
;
2067 dwz_file
->abbrev
.size
= bfd_section_size (sectp
);
2069 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2071 dwz_file
->info
.s
.section
= sectp
;
2072 dwz_file
->info
.size
= bfd_section_size (sectp
);
2074 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2076 dwz_file
->str
.s
.section
= sectp
;
2077 dwz_file
->str
.size
= bfd_section_size (sectp
);
2079 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2081 dwz_file
->line
.s
.section
= sectp
;
2082 dwz_file
->line
.size
= bfd_section_size (sectp
);
2084 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2086 dwz_file
->macro
.s
.section
= sectp
;
2087 dwz_file
->macro
.size
= bfd_section_size (sectp
);
2089 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2091 dwz_file
->gdb_index
.s
.section
= sectp
;
2092 dwz_file
->gdb_index
.size
= bfd_section_size (sectp
);
2094 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2096 dwz_file
->debug_names
.s
.section
= sectp
;
2097 dwz_file
->debug_names
.size
= bfd_section_size (sectp
);
2101 /* See dwarf2read.h. */
2104 dwarf2_get_dwz_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
2106 const char *filename
;
2107 bfd_size_type buildid_len_arg
;
2111 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2112 return dwarf2_per_objfile
->dwz_file
.get ();
2114 bfd_set_error (bfd_error_no_error
);
2115 gdb::unique_xmalloc_ptr
<char> data
2116 (bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2117 &buildid_len_arg
, &buildid
));
2120 if (bfd_get_error () == bfd_error_no_error
)
2122 error (_("could not read '.gnu_debugaltlink' section: %s"),
2123 bfd_errmsg (bfd_get_error ()));
2126 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2128 buildid_len
= (size_t) buildid_len_arg
;
2130 filename
= data
.get ();
2132 std::string abs_storage
;
2133 if (!IS_ABSOLUTE_PATH (filename
))
2135 gdb::unique_xmalloc_ptr
<char> abs
2136 = gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2138 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2139 filename
= abs_storage
.c_str ();
2142 /* First try the file name given in the section. If that doesn't
2143 work, try to use the build-id instead. */
2144 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
, -1));
2145 if (dwz_bfd
!= NULL
)
2147 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2148 dwz_bfd
.reset (nullptr);
2151 if (dwz_bfd
== NULL
)
2152 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2154 if (dwz_bfd
== NULL
)
2155 error (_("could not find '.gnu_debugaltlink' file for %s"),
2156 objfile_name (dwarf2_per_objfile
->objfile
));
2158 std::unique_ptr
<struct dwz_file
> result
2159 (new struct dwz_file (std::move (dwz_bfd
)));
2161 bfd_map_over_sections (result
->dwz_bfd
.get (), locate_dwz_sections
,
2164 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
,
2165 result
->dwz_bfd
.get ());
2166 dwarf2_per_objfile
->dwz_file
= std::move (result
);
2167 return dwarf2_per_objfile
->dwz_file
.get ();
2170 /* DWARF quick_symbols_functions support. */
2172 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2173 unique line tables, so we maintain a separate table of all .debug_line
2174 derived entries to support the sharing.
2175 All the quick functions need is the list of file names. We discard the
2176 line_header when we're done and don't need to record it here. */
2177 struct quick_file_names
2179 /* The data used to construct the hash key. */
2180 struct stmt_list_hash hash
;
2182 /* The number of entries in file_names, real_names. */
2183 unsigned int num_file_names
;
2185 /* The file names from the line table, after being run through
2187 const char **file_names
;
2189 /* The file names from the line table after being run through
2190 gdb_realpath. These are computed lazily. */
2191 const char **real_names
;
2194 /* When using the index (and thus not using psymtabs), each CU has an
2195 object of this type. This is used to hold information needed by
2196 the various "quick" methods. */
2197 struct dwarf2_per_cu_quick_data
2199 /* The file table. This can be NULL if there was no file table
2200 or it's currently not read in.
2201 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2202 struct quick_file_names
*file_names
;
2204 /* The corresponding symbol table. This is NULL if symbols for this
2205 CU have not yet been read. */
2206 struct compunit_symtab
*compunit_symtab
;
2208 /* A temporary mark bit used when iterating over all CUs in
2209 expand_symtabs_matching. */
2210 unsigned int mark
: 1;
2212 /* True if we've tried to read the file table and found there isn't one.
2213 There will be no point in trying to read it again next time. */
2214 unsigned int no_file_data
: 1;
2217 /* Utility hash function for a stmt_list_hash. */
2220 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2224 if (stmt_list_hash
->dwo_unit
!= NULL
)
2225 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2226 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2230 /* Utility equality function for a stmt_list_hash. */
2233 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2234 const struct stmt_list_hash
*rhs
)
2236 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2238 if (lhs
->dwo_unit
!= NULL
2239 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2242 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2245 /* Hash function for a quick_file_names. */
2248 hash_file_name_entry (const void *e
)
2250 const struct quick_file_names
*file_data
2251 = (const struct quick_file_names
*) e
;
2253 return hash_stmt_list_entry (&file_data
->hash
);
2256 /* Equality function for a quick_file_names. */
2259 eq_file_name_entry (const void *a
, const void *b
)
2261 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2262 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2264 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2267 /* Delete function for a quick_file_names. */
2270 delete_file_name_entry (void *e
)
2272 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2275 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2277 xfree ((void*) file_data
->file_names
[i
]);
2278 if (file_data
->real_names
)
2279 xfree ((void*) file_data
->real_names
[i
]);
2282 /* The space for the struct itself lives on objfile_obstack,
2283 so we don't free it here. */
2286 /* Create a quick_file_names hash table. */
2289 create_quick_file_names_table (unsigned int nr_initial_entries
)
2291 return htab_up (htab_create_alloc (nr_initial_entries
,
2292 hash_file_name_entry
, eq_file_name_entry
,
2293 delete_file_name_entry
, xcalloc
, xfree
));
2296 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2297 have to be created afterwards. You should call age_cached_comp_units after
2298 processing PER_CU->CU. dw2_setup must have been already called. */
2301 load_cu (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2303 if (per_cu
->is_debug_types
)
2304 load_full_type_unit (per_cu
);
2306 load_full_comp_unit (per_cu
, skip_partial
, language_minimal
);
2308 if (per_cu
->cu
== NULL
)
2309 return; /* Dummy CU. */
2311 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2314 /* Read in the symbols for PER_CU. */
2317 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2319 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2321 /* Skip type_unit_groups, reading the type units they contain
2322 is handled elsewhere. */
2323 if (IS_TYPE_UNIT_GROUP (per_cu
))
2326 /* The destructor of dwarf2_queue_guard frees any entries left on
2327 the queue. After this point we're guaranteed to leave this function
2328 with the dwarf queue empty. */
2329 dwarf2_queue_guard
q_guard (dwarf2_per_objfile
);
2331 if (dwarf2_per_objfile
->using_index
2332 ? per_cu
->v
.quick
->compunit_symtab
== NULL
2333 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2335 queue_comp_unit (per_cu
, language_minimal
);
2336 load_cu (per_cu
, skip_partial
);
2338 /* If we just loaded a CU from a DWO, and we're working with an index
2339 that may badly handle TUs, load all the TUs in that DWO as well.
2340 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2341 if (!per_cu
->is_debug_types
2342 && per_cu
->cu
!= NULL
2343 && per_cu
->cu
->dwo_unit
!= NULL
2344 && dwarf2_per_objfile
->index_table
!= NULL
2345 && dwarf2_per_objfile
->index_table
->version
<= 7
2346 /* DWP files aren't supported yet. */
2347 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
2348 queue_and_load_all_dwo_tus (per_cu
);
2351 process_queue (dwarf2_per_objfile
);
2353 /* Age the cache, releasing compilation units that have not
2354 been used recently. */
2355 age_cached_comp_units (dwarf2_per_objfile
);
2358 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2359 the objfile from which this CU came. Returns the resulting symbol
2362 static struct compunit_symtab
*
2363 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2365 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2367 gdb_assert (dwarf2_per_objfile
->using_index
);
2368 if (!per_cu
->v
.quick
->compunit_symtab
)
2370 free_cached_comp_units
freer (dwarf2_per_objfile
);
2371 scoped_restore decrementer
= increment_reading_symtab ();
2372 dw2_do_instantiate_symtab (per_cu
, skip_partial
);
2373 process_cu_includes (dwarf2_per_objfile
);
2376 return per_cu
->v
.quick
->compunit_symtab
;
2379 /* See declaration. */
2381 dwarf2_per_cu_data
*
2382 dwarf2_per_objfile::get_cutu (int index
)
2384 if (index
>= this->all_comp_units
.size ())
2386 index
-= this->all_comp_units
.size ();
2387 gdb_assert (index
< this->all_type_units
.size ());
2388 return &this->all_type_units
[index
]->per_cu
;
2391 return this->all_comp_units
[index
];
2394 /* See declaration. */
2396 dwarf2_per_cu_data
*
2397 dwarf2_per_objfile::get_cu (int index
)
2399 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2401 return this->all_comp_units
[index
];
2404 /* See declaration. */
2407 dwarf2_per_objfile::get_tu (int index
)
2409 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2411 return this->all_type_units
[index
];
2414 /* Return a new dwarf2_per_cu_data allocated on OBJFILE's
2415 objfile_obstack, and constructed with the specified field
2418 static dwarf2_per_cu_data
*
2419 create_cu_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2420 struct dwarf2_section_info
*section
,
2422 sect_offset sect_off
, ULONGEST length
)
2424 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2425 dwarf2_per_cu_data
*the_cu
2426 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2427 struct dwarf2_per_cu_data
);
2428 the_cu
->sect_off
= sect_off
;
2429 the_cu
->length
= length
;
2430 the_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
2431 the_cu
->section
= section
;
2432 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2433 struct dwarf2_per_cu_quick_data
);
2434 the_cu
->is_dwz
= is_dwz
;
2438 /* A helper for create_cus_from_index that handles a given list of
2442 create_cus_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2443 const gdb_byte
*cu_list
, offset_type n_elements
,
2444 struct dwarf2_section_info
*section
,
2447 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2449 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2451 sect_offset sect_off
2452 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2453 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2456 dwarf2_per_cu_data
*per_cu
2457 = create_cu_from_index_list (dwarf2_per_objfile
, section
, is_dwz
,
2459 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
2463 /* Read the CU list from the mapped index, and use it to create all
2464 the CU objects for this objfile. */
2467 create_cus_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2468 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2469 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2471 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
2472 dwarf2_per_objfile
->all_comp_units
.reserve
2473 ((cu_list_elements
+ dwz_elements
) / 2);
2475 create_cus_from_index_list (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
2476 &dwarf2_per_objfile
->info
, 0);
2478 if (dwz_elements
== 0)
2481 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
2482 create_cus_from_index_list (dwarf2_per_objfile
, dwz_list
, dwz_elements
,
2486 /* Create the signatured type hash table from the index. */
2489 create_signatured_type_table_from_index
2490 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2491 struct dwarf2_section_info
*section
,
2492 const gdb_byte
*bytes
,
2493 offset_type elements
)
2495 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2497 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
2498 dwarf2_per_objfile
->all_type_units
.reserve (elements
/ 3);
2500 htab_up sig_types_hash
= allocate_signatured_type_table (objfile
);
2502 for (offset_type i
= 0; i
< elements
; i
+= 3)
2504 struct signatured_type
*sig_type
;
2507 cu_offset type_offset_in_tu
;
2509 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2510 sect_offset sect_off
2511 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2513 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2515 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2518 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2519 struct signatured_type
);
2520 sig_type
->signature
= signature
;
2521 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2522 sig_type
->per_cu
.is_debug_types
= 1;
2523 sig_type
->per_cu
.section
= section
;
2524 sig_type
->per_cu
.sect_off
= sect_off
;
2525 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
2526 sig_type
->per_cu
.v
.quick
2527 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2528 struct dwarf2_per_cu_quick_data
);
2530 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2533 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
2536 dwarf2_per_objfile
->signatured_types
= std::move (sig_types_hash
);
2539 /* Create the signatured type hash table from .debug_names. */
2542 create_signatured_type_table_from_debug_names
2543 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2544 const mapped_debug_names
&map
,
2545 struct dwarf2_section_info
*section
,
2546 struct dwarf2_section_info
*abbrev_section
)
2548 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2550 section
->read (objfile
);
2551 abbrev_section
->read (objfile
);
2553 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
2554 dwarf2_per_objfile
->all_type_units
.reserve (map
.tu_count
);
2556 htab_up sig_types_hash
= allocate_signatured_type_table (objfile
);
2558 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2560 struct signatured_type
*sig_type
;
2563 sect_offset sect_off
2564 = (sect_offset
) (extract_unsigned_integer
2565 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2567 map
.dwarf5_byte_order
));
2569 comp_unit_head cu_header
;
2570 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
2572 section
->buffer
+ to_underlying (sect_off
),
2575 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2576 struct signatured_type
);
2577 sig_type
->signature
= cu_header
.signature
;
2578 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2579 sig_type
->per_cu
.is_debug_types
= 1;
2580 sig_type
->per_cu
.section
= section
;
2581 sig_type
->per_cu
.sect_off
= sect_off
;
2582 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
2583 sig_type
->per_cu
.v
.quick
2584 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2585 struct dwarf2_per_cu_quick_data
);
2587 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2590 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
2593 dwarf2_per_objfile
->signatured_types
= std::move (sig_types_hash
);
2596 /* Read the address map data from the mapped index, and use it to
2597 populate the objfile's psymtabs_addrmap. */
2600 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2601 struct mapped_index
*index
)
2603 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2604 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2605 const gdb_byte
*iter
, *end
;
2606 struct addrmap
*mutable_map
;
2609 auto_obstack temp_obstack
;
2611 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2613 iter
= index
->address_table
.data ();
2614 end
= iter
+ index
->address_table
.size ();
2616 baseaddr
= objfile
->text_section_offset ();
2620 ULONGEST hi
, lo
, cu_index
;
2621 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2623 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2625 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2630 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2631 hex_string (lo
), hex_string (hi
));
2635 if (cu_index
>= dwarf2_per_objfile
->all_comp_units
.size ())
2637 complaint (_(".gdb_index address table has invalid CU number %u"),
2638 (unsigned) cu_index
);
2642 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2643 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2644 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2645 dwarf2_per_objfile
->get_cu (cu_index
));
2648 objfile
->partial_symtabs
->psymtabs_addrmap
2649 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2652 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2653 populate the objfile's psymtabs_addrmap. */
2656 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2657 struct dwarf2_section_info
*section
)
2659 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2660 bfd
*abfd
= objfile
->obfd
;
2661 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2662 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2664 auto_obstack temp_obstack
;
2665 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2667 std::unordered_map
<sect_offset
,
2668 dwarf2_per_cu_data
*,
2669 gdb::hash_enum
<sect_offset
>>
2670 debug_info_offset_to_per_cu
;
2671 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
2673 const auto insertpair
2674 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
2675 if (!insertpair
.second
)
2677 warning (_("Section .debug_aranges in %s has duplicate "
2678 "debug_info_offset %s, ignoring .debug_aranges."),
2679 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2684 section
->read (objfile
);
2686 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2688 const gdb_byte
*addr
= section
->buffer
;
2690 while (addr
< section
->buffer
+ section
->size
)
2692 const gdb_byte
*const entry_addr
= addr
;
2693 unsigned int bytes_read
;
2695 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2699 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2700 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2701 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2702 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2704 warning (_("Section .debug_aranges in %s entry at offset %s "
2705 "length %s exceeds section length %s, "
2706 "ignoring .debug_aranges."),
2707 objfile_name (objfile
),
2708 plongest (entry_addr
- section
->buffer
),
2709 plongest (bytes_read
+ entry_length
),
2710 pulongest (section
->size
));
2714 /* The version number. */
2715 const uint16_t version
= read_2_bytes (abfd
, addr
);
2719 warning (_("Section .debug_aranges in %s entry at offset %s "
2720 "has unsupported version %d, ignoring .debug_aranges."),
2721 objfile_name (objfile
),
2722 plongest (entry_addr
- section
->buffer
), version
);
2726 const uint64_t debug_info_offset
2727 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2728 addr
+= offset_size
;
2729 const auto per_cu_it
2730 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2731 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2733 warning (_("Section .debug_aranges in %s entry at offset %s "
2734 "debug_info_offset %s does not exists, "
2735 "ignoring .debug_aranges."),
2736 objfile_name (objfile
),
2737 plongest (entry_addr
- section
->buffer
),
2738 pulongest (debug_info_offset
));
2741 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2743 const uint8_t address_size
= *addr
++;
2744 if (address_size
< 1 || address_size
> 8)
2746 warning (_("Section .debug_aranges in %s entry at offset %s "
2747 "address_size %u is invalid, ignoring .debug_aranges."),
2748 objfile_name (objfile
),
2749 plongest (entry_addr
- section
->buffer
), address_size
);
2753 const uint8_t segment_selector_size
= *addr
++;
2754 if (segment_selector_size
!= 0)
2756 warning (_("Section .debug_aranges in %s entry at offset %s "
2757 "segment_selector_size %u is not supported, "
2758 "ignoring .debug_aranges."),
2759 objfile_name (objfile
),
2760 plongest (entry_addr
- section
->buffer
),
2761 segment_selector_size
);
2765 /* Must pad to an alignment boundary that is twice the address
2766 size. It is undocumented by the DWARF standard but GCC does
2768 for (size_t padding
= ((-(addr
- section
->buffer
))
2769 & (2 * address_size
- 1));
2770 padding
> 0; padding
--)
2773 warning (_("Section .debug_aranges in %s entry at offset %s "
2774 "padding is not zero, ignoring .debug_aranges."),
2775 objfile_name (objfile
),
2776 plongest (entry_addr
- section
->buffer
));
2782 if (addr
+ 2 * address_size
> entry_end
)
2784 warning (_("Section .debug_aranges in %s entry at offset %s "
2785 "address list is not properly terminated, "
2786 "ignoring .debug_aranges."),
2787 objfile_name (objfile
),
2788 plongest (entry_addr
- section
->buffer
));
2791 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
2793 addr
+= address_size
;
2794 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
2796 addr
+= address_size
;
2797 if (start
== 0 && length
== 0)
2799 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
2801 /* Symbol was eliminated due to a COMDAT group. */
2804 ULONGEST end
= start
+ length
;
2805 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
2807 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
2809 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
2813 objfile
->partial_symtabs
->psymtabs_addrmap
2814 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2817 /* Find a slot in the mapped index INDEX for the object named NAME.
2818 If NAME is found, set *VEC_OUT to point to the CU vector in the
2819 constant pool and return true. If NAME cannot be found, return
2823 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2824 offset_type
**vec_out
)
2827 offset_type slot
, step
;
2828 int (*cmp
) (const char *, const char *);
2830 gdb::unique_xmalloc_ptr
<char> without_params
;
2831 if (current_language
->la_language
== language_cplus
2832 || current_language
->la_language
== language_fortran
2833 || current_language
->la_language
== language_d
)
2835 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2838 if (strchr (name
, '(') != NULL
)
2840 without_params
= cp_remove_params (name
);
2842 if (without_params
!= NULL
)
2843 name
= without_params
.get ();
2847 /* Index version 4 did not support case insensitive searches. But the
2848 indices for case insensitive languages are built in lowercase, therefore
2849 simulate our NAME being searched is also lowercased. */
2850 hash
= mapped_index_string_hash ((index
->version
== 4
2851 && case_sensitivity
== case_sensitive_off
2852 ? 5 : index
->version
),
2855 slot
= hash
& (index
->symbol_table
.size () - 1);
2856 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
2857 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2863 const auto &bucket
= index
->symbol_table
[slot
];
2864 if (bucket
.name
== 0 && bucket
.vec
== 0)
2867 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
2868 if (!cmp (name
, str
))
2870 *vec_out
= (offset_type
*) (index
->constant_pool
2871 + MAYBE_SWAP (bucket
.vec
));
2875 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
2879 /* A helper function that reads the .gdb_index from BUFFER and fills
2880 in MAP. FILENAME is the name of the file containing the data;
2881 it is used for error reporting. DEPRECATED_OK is true if it is
2882 ok to use deprecated sections.
2884 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2885 out parameters that are filled in with information about the CU and
2886 TU lists in the section.
2888 Returns true if all went well, false otherwise. */
2891 read_gdb_index_from_buffer (struct objfile
*objfile
,
2892 const char *filename
,
2894 gdb::array_view
<const gdb_byte
> buffer
,
2895 struct mapped_index
*map
,
2896 const gdb_byte
**cu_list
,
2897 offset_type
*cu_list_elements
,
2898 const gdb_byte
**types_list
,
2899 offset_type
*types_list_elements
)
2901 const gdb_byte
*addr
= &buffer
[0];
2903 /* Version check. */
2904 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
2905 /* Versions earlier than 3 emitted every copy of a psymbol. This
2906 causes the index to behave very poorly for certain requests. Version 3
2907 contained incomplete addrmap. So, it seems better to just ignore such
2911 static int warning_printed
= 0;
2912 if (!warning_printed
)
2914 warning (_("Skipping obsolete .gdb_index section in %s."),
2916 warning_printed
= 1;
2920 /* Index version 4 uses a different hash function than index version
2923 Versions earlier than 6 did not emit psymbols for inlined
2924 functions. Using these files will cause GDB not to be able to
2925 set breakpoints on inlined functions by name, so we ignore these
2926 indices unless the user has done
2927 "set use-deprecated-index-sections on". */
2928 if (version
< 6 && !deprecated_ok
)
2930 static int warning_printed
= 0;
2931 if (!warning_printed
)
2934 Skipping deprecated .gdb_index section in %s.\n\
2935 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2936 to use the section anyway."),
2938 warning_printed
= 1;
2942 /* Version 7 indices generated by gold refer to the CU for a symbol instead
2943 of the TU (for symbols coming from TUs),
2944 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
2945 Plus gold-generated indices can have duplicate entries for global symbols,
2946 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
2947 These are just performance bugs, and we can't distinguish gdb-generated
2948 indices from gold-generated ones, so issue no warning here. */
2950 /* Indexes with higher version than the one supported by GDB may be no
2951 longer backward compatible. */
2955 map
->version
= version
;
2957 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2960 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2961 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2965 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2966 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2967 - MAYBE_SWAP (metadata
[i
]))
2971 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2972 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
2974 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
2977 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2978 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
2980 = gdb::array_view
<mapped_index::symbol_table_slot
>
2981 ((mapped_index::symbol_table_slot
*) symbol_table
,
2982 (mapped_index::symbol_table_slot
*) symbol_table_end
);
2985 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
2990 /* Callback types for dwarf2_read_gdb_index. */
2992 typedef gdb::function_view
2993 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_objfile
*)>
2994 get_gdb_index_contents_ftype
;
2995 typedef gdb::function_view
2996 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
2997 get_gdb_index_contents_dwz_ftype
;
2999 /* Read .gdb_index. If everything went ok, initialize the "quick"
3000 elements of all the CUs and return 1. Otherwise, return 0. */
3003 dwarf2_read_gdb_index
3004 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3005 get_gdb_index_contents_ftype get_gdb_index_contents
,
3006 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
3008 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3009 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3010 struct dwz_file
*dwz
;
3011 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3013 gdb::array_view
<const gdb_byte
> main_index_contents
3014 = get_gdb_index_contents (objfile
, dwarf2_per_objfile
);
3016 if (main_index_contents
.empty ())
3019 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3020 if (!read_gdb_index_from_buffer (objfile
, objfile_name (objfile
),
3021 use_deprecated_index_sections
,
3022 main_index_contents
, map
.get (), &cu_list
,
3023 &cu_list_elements
, &types_list
,
3024 &types_list_elements
))
3027 /* Don't use the index if it's empty. */
3028 if (map
->symbol_table
.empty ())
3031 /* If there is a .dwz file, read it so we can get its CU list as
3033 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3036 struct mapped_index dwz_map
;
3037 const gdb_byte
*dwz_types_ignore
;
3038 offset_type dwz_types_elements_ignore
;
3040 gdb::array_view
<const gdb_byte
> dwz_index_content
3041 = get_gdb_index_contents_dwz (objfile
, dwz
);
3043 if (dwz_index_content
.empty ())
3046 if (!read_gdb_index_from_buffer (objfile
,
3047 bfd_get_filename (dwz
->dwz_bfd
.get ()),
3048 1, dwz_index_content
, &dwz_map
,
3049 &dwz_list
, &dwz_list_elements
,
3051 &dwz_types_elements_ignore
))
3053 warning (_("could not read '.gdb_index' section from %s; skipping"),
3054 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3059 create_cus_from_index (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3060 dwz_list
, dwz_list_elements
);
3062 if (types_list_elements
)
3064 /* We can only handle a single .debug_types when we have an
3066 if (dwarf2_per_objfile
->types
.size () != 1)
3069 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
3071 create_signatured_type_table_from_index (dwarf2_per_objfile
, section
,
3072 types_list
, types_list_elements
);
3075 create_addrmap_from_index (dwarf2_per_objfile
, map
.get ());
3077 dwarf2_per_objfile
->index_table
= std::move (map
);
3078 dwarf2_per_objfile
->using_index
= 1;
3079 dwarf2_per_objfile
->quick_file_names_table
=
3080 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
3085 /* die_reader_func for dw2_get_file_names. */
3088 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3089 const gdb_byte
*info_ptr
,
3090 struct die_info
*comp_unit_die
)
3092 struct dwarf2_cu
*cu
= reader
->cu
;
3093 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3094 struct dwarf2_per_objfile
*dwarf2_per_objfile
3095 = cu
->per_cu
->dwarf2_per_objfile
;
3096 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3097 struct dwarf2_per_cu_data
*lh_cu
;
3098 struct attribute
*attr
;
3100 struct quick_file_names
*qfn
;
3102 gdb_assert (! this_cu
->is_debug_types
);
3104 /* Our callers never want to match partial units -- instead they
3105 will match the enclosing full CU. */
3106 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3108 this_cu
->v
.quick
->no_file_data
= 1;
3116 sect_offset line_offset
{};
3118 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3119 if (attr
!= nullptr)
3121 struct quick_file_names find_entry
;
3123 line_offset
= (sect_offset
) DW_UNSND (attr
);
3125 /* We may have already read in this line header (TU line header sharing).
3126 If we have we're done. */
3127 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3128 find_entry
.hash
.line_sect_off
= line_offset
;
3129 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
.get (),
3130 &find_entry
, INSERT
);
3133 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3137 lh
= dwarf_decode_line_header (line_offset
, cu
);
3141 lh_cu
->v
.quick
->no_file_data
= 1;
3145 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
3146 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3147 qfn
->hash
.line_sect_off
= line_offset
;
3148 gdb_assert (slot
!= NULL
);
3151 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3154 if (strcmp (fnd
.name
, "<unknown>") != 0)
3157 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3159 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, qfn
->num_file_names
);
3161 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3162 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3163 qfn
->file_names
[i
+ offset
] = lh
->file_full_name (i
+ 1,
3164 fnd
.comp_dir
).release ();
3165 qfn
->real_names
= NULL
;
3167 lh_cu
->v
.quick
->file_names
= qfn
;
3170 /* A helper for the "quick" functions which attempts to read the line
3171 table for THIS_CU. */
3173 static struct quick_file_names
*
3174 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3176 /* This should never be called for TUs. */
3177 gdb_assert (! this_cu
->is_debug_types
);
3178 /* Nor type unit groups. */
3179 gdb_assert (! IS_TYPE_UNIT_GROUP (this_cu
));
3181 if (this_cu
->v
.quick
->file_names
!= NULL
)
3182 return this_cu
->v
.quick
->file_names
;
3183 /* If we know there is no line data, no point in looking again. */
3184 if (this_cu
->v
.quick
->no_file_data
)
3187 cutu_reader
reader (this_cu
);
3188 if (!reader
.dummy_p
)
3189 dw2_get_file_names_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
);
3191 if (this_cu
->v
.quick
->no_file_data
)
3193 return this_cu
->v
.quick
->file_names
;
3196 /* A helper for the "quick" functions which computes and caches the
3197 real path for a given file name from the line table. */
3200 dw2_get_real_path (struct objfile
*objfile
,
3201 struct quick_file_names
*qfn
, int index
)
3203 if (qfn
->real_names
== NULL
)
3204 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3205 qfn
->num_file_names
, const char *);
3207 if (qfn
->real_names
[index
] == NULL
)
3208 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3210 return qfn
->real_names
[index
];
3213 static struct symtab
*
3214 dw2_find_last_source_symtab (struct objfile
*objfile
)
3216 struct dwarf2_per_objfile
*dwarf2_per_objfile
3217 = get_dwarf2_per_objfile (objfile
);
3218 dwarf2_per_cu_data
*dwarf_cu
= dwarf2_per_objfile
->all_comp_units
.back ();
3219 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, false);
3224 return compunit_primary_filetab (cust
);
3227 /* Traversal function for dw2_forget_cached_source_info. */
3230 dw2_free_cached_file_names (void **slot
, void *info
)
3232 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3234 if (file_data
->real_names
)
3238 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3240 xfree ((void*) file_data
->real_names
[i
]);
3241 file_data
->real_names
[i
] = NULL
;
3249 dw2_forget_cached_source_info (struct objfile
*objfile
)
3251 struct dwarf2_per_objfile
*dwarf2_per_objfile
3252 = get_dwarf2_per_objfile (objfile
);
3254 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
.get (),
3255 dw2_free_cached_file_names
, NULL
);
3258 /* Helper function for dw2_map_symtabs_matching_filename that expands
3259 the symtabs and calls the iterator. */
3262 dw2_map_expand_apply (struct objfile
*objfile
,
3263 struct dwarf2_per_cu_data
*per_cu
,
3264 const char *name
, const char *real_path
,
3265 gdb::function_view
<bool (symtab
*)> callback
)
3267 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3269 /* Don't visit already-expanded CUs. */
3270 if (per_cu
->v
.quick
->compunit_symtab
)
3273 /* This may expand more than one symtab, and we want to iterate over
3275 dw2_instantiate_symtab (per_cu
, false);
3277 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3278 last_made
, callback
);
3281 /* Implementation of the map_symtabs_matching_filename method. */
3284 dw2_map_symtabs_matching_filename
3285 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3286 gdb::function_view
<bool (symtab
*)> callback
)
3288 const char *name_basename
= lbasename (name
);
3289 struct dwarf2_per_objfile
*dwarf2_per_objfile
3290 = get_dwarf2_per_objfile (objfile
);
3292 /* The rule is CUs specify all the files, including those used by
3293 any TU, so there's no need to scan TUs here. */
3295 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3297 /* We only need to look at symtabs not already expanded. */
3298 if (per_cu
->v
.quick
->compunit_symtab
)
3301 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3302 if (file_data
== NULL
)
3305 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3307 const char *this_name
= file_data
->file_names
[j
];
3308 const char *this_real_name
;
3310 if (compare_filenames_for_search (this_name
, name
))
3312 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3318 /* Before we invoke realpath, which can get expensive when many
3319 files are involved, do a quick comparison of the basenames. */
3320 if (! basenames_may_differ
3321 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3324 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3325 if (compare_filenames_for_search (this_real_name
, name
))
3327 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3333 if (real_path
!= NULL
)
3335 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3336 gdb_assert (IS_ABSOLUTE_PATH (name
));
3337 if (this_real_name
!= NULL
3338 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3340 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3352 /* Struct used to manage iterating over all CUs looking for a symbol. */
3354 struct dw2_symtab_iterator
3356 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3357 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
3358 /* If set, only look for symbols that match that block. Valid values are
3359 GLOBAL_BLOCK and STATIC_BLOCK. */
3360 gdb::optional
<block_enum
> block_index
;
3361 /* The kind of symbol we're looking for. */
3363 /* The list of CUs from the index entry of the symbol,
3364 or NULL if not found. */
3366 /* The next element in VEC to look at. */
3368 /* The number of elements in VEC, or zero if there is no match. */
3370 /* Have we seen a global version of the symbol?
3371 If so we can ignore all further global instances.
3372 This is to work around gold/15646, inefficient gold-generated
3377 /* Initialize the index symtab iterator ITER. */
3380 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3381 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3382 gdb::optional
<block_enum
> block_index
,
3386 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3387 iter
->block_index
= block_index
;
3388 iter
->domain
= domain
;
3390 iter
->global_seen
= 0;
3392 mapped_index
*index
= dwarf2_per_objfile
->index_table
.get ();
3394 /* index is NULL if OBJF_READNOW. */
3395 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3396 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3404 /* Return the next matching CU or NULL if there are no more. */
3406 static struct dwarf2_per_cu_data
*
3407 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3409 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
3411 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3413 offset_type cu_index_and_attrs
=
3414 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3415 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3416 gdb_index_symbol_kind symbol_kind
=
3417 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3418 /* Only check the symbol attributes if they're present.
3419 Indices prior to version 7 don't record them,
3420 and indices >= 7 may elide them for certain symbols
3421 (gold does this). */
3423 (dwarf2_per_objfile
->index_table
->version
>= 7
3424 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3426 /* Don't crash on bad data. */
3427 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
3428 + dwarf2_per_objfile
->all_type_units
.size ()))
3430 complaint (_(".gdb_index entry has bad CU index"
3432 objfile_name (dwarf2_per_objfile
->objfile
));
3436 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
3438 /* Skip if already read in. */
3439 if (per_cu
->v
.quick
->compunit_symtab
)
3442 /* Check static vs global. */
3445 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3447 if (iter
->block_index
.has_value ())
3449 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3451 if (is_static
!= want_static
)
3455 /* Work around gold/15646. */
3456 if (!is_static
&& iter
->global_seen
)
3459 iter
->global_seen
= 1;
3462 /* Only check the symbol's kind if it has one. */
3465 switch (iter
->domain
)
3468 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3469 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3470 /* Some types are also in VAR_DOMAIN. */
3471 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3475 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3479 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3483 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3498 static struct compunit_symtab
*
3499 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
3500 const char *name
, domain_enum domain
)
3502 struct compunit_symtab
*stab_best
= NULL
;
3503 struct dwarf2_per_objfile
*dwarf2_per_objfile
3504 = get_dwarf2_per_objfile (objfile
);
3506 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
3508 struct dw2_symtab_iterator iter
;
3509 struct dwarf2_per_cu_data
*per_cu
;
3511 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, block_index
, domain
, name
);
3513 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3515 struct symbol
*sym
, *with_opaque
= NULL
;
3516 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
3517 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
3518 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3520 sym
= block_find_symbol (block
, name
, domain
,
3521 block_find_non_opaque_type_preferred
,
3524 /* Some caution must be observed with overloaded functions
3525 and methods, since the index will not contain any overload
3526 information (but NAME might contain it). */
3529 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
3531 if (with_opaque
!= NULL
3532 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
3535 /* Keep looking through other CUs. */
3542 dw2_print_stats (struct objfile
*objfile
)
3544 struct dwarf2_per_objfile
*dwarf2_per_objfile
3545 = get_dwarf2_per_objfile (objfile
);
3546 int total
= (dwarf2_per_objfile
->all_comp_units
.size ()
3547 + dwarf2_per_objfile
->all_type_units
.size ());
3550 for (int i
= 0; i
< total
; ++i
)
3552 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
3554 if (!per_cu
->v
.quick
->compunit_symtab
)
3557 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3558 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3561 /* This dumps minimal information about the index.
3562 It is called via "mt print objfiles".
3563 One use is to verify .gdb_index has been loaded by the
3564 gdb.dwarf2/gdb-index.exp testcase. */
3567 dw2_dump (struct objfile
*objfile
)
3569 struct dwarf2_per_objfile
*dwarf2_per_objfile
3570 = get_dwarf2_per_objfile (objfile
);
3572 gdb_assert (dwarf2_per_objfile
->using_index
);
3573 printf_filtered (".gdb_index:");
3574 if (dwarf2_per_objfile
->index_table
!= NULL
)
3576 printf_filtered (" version %d\n",
3577 dwarf2_per_objfile
->index_table
->version
);
3580 printf_filtered (" faked for \"readnow\"\n");
3581 printf_filtered ("\n");
3585 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3586 const char *func_name
)
3588 struct dwarf2_per_objfile
*dwarf2_per_objfile
3589 = get_dwarf2_per_objfile (objfile
);
3591 struct dw2_symtab_iterator iter
;
3592 struct dwarf2_per_cu_data
*per_cu
;
3594 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, {}, VAR_DOMAIN
, func_name
);
3596 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3597 dw2_instantiate_symtab (per_cu
, false);
3602 dw2_expand_all_symtabs (struct objfile
*objfile
)
3604 struct dwarf2_per_objfile
*dwarf2_per_objfile
3605 = get_dwarf2_per_objfile (objfile
);
3606 int total_units
= (dwarf2_per_objfile
->all_comp_units
.size ()
3607 + dwarf2_per_objfile
->all_type_units
.size ());
3609 for (int i
= 0; i
< total_units
; ++i
)
3611 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
3613 /* We don't want to directly expand a partial CU, because if we
3614 read it with the wrong language, then assertion failures can
3615 be triggered later on. See PR symtab/23010. So, tell
3616 dw2_instantiate_symtab to skip partial CUs -- any important
3617 partial CU will be read via DW_TAG_imported_unit anyway. */
3618 dw2_instantiate_symtab (per_cu
, true);
3623 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
3624 const char *fullname
)
3626 struct dwarf2_per_objfile
*dwarf2_per_objfile
3627 = get_dwarf2_per_objfile (objfile
);
3629 /* We don't need to consider type units here.
3630 This is only called for examining code, e.g. expand_line_sal.
3631 There can be an order of magnitude (or more) more type units
3632 than comp units, and we avoid them if we can. */
3634 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3636 /* We only need to look at symtabs not already expanded. */
3637 if (per_cu
->v
.quick
->compunit_symtab
)
3640 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3641 if (file_data
== NULL
)
3644 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3646 const char *this_fullname
= file_data
->file_names
[j
];
3648 if (filename_cmp (this_fullname
, fullname
) == 0)
3650 dw2_instantiate_symtab (per_cu
, false);
3658 dw2_map_matching_symbols
3659 (struct objfile
*objfile
,
3660 const lookup_name_info
&name
, domain_enum domain
,
3662 gdb::function_view
<symbol_found_callback_ftype
> callback
,
3663 symbol_compare_ftype
*ordered_compare
)
3665 /* Currently unimplemented; used for Ada. The function can be called if the
3666 current language is Ada for a non-Ada objfile using GNU index. As Ada
3667 does not look for non-Ada symbols this function should just return. */
3670 /* Starting from a search name, return the string that finds the upper
3671 bound of all strings that start with SEARCH_NAME in a sorted name
3672 list. Returns the empty string to indicate that the upper bound is
3673 the end of the list. */
3676 make_sort_after_prefix_name (const char *search_name
)
3678 /* When looking to complete "func", we find the upper bound of all
3679 symbols that start with "func" by looking for where we'd insert
3680 the closest string that would follow "func" in lexicographical
3681 order. Usually, that's "func"-with-last-character-incremented,
3682 i.e. "fund". Mind non-ASCII characters, though. Usually those
3683 will be UTF-8 multi-byte sequences, but we can't be certain.
3684 Especially mind the 0xff character, which is a valid character in
3685 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3686 rule out compilers allowing it in identifiers. Note that
3687 conveniently, strcmp/strcasecmp are specified to compare
3688 characters interpreted as unsigned char. So what we do is treat
3689 the whole string as a base 256 number composed of a sequence of
3690 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3691 to 0, and carries 1 to the following more-significant position.
3692 If the very first character in SEARCH_NAME ends up incremented
3693 and carries/overflows, then the upper bound is the end of the
3694 list. The string after the empty string is also the empty
3697 Some examples of this operation:
3699 SEARCH_NAME => "+1" RESULT
3703 "\xff" "a" "\xff" => "\xff" "b"
3708 Then, with these symbols for example:
3714 completing "func" looks for symbols between "func" and
3715 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3716 which finds "func" and "func1", but not "fund".
3720 funcÿ (Latin1 'ÿ' [0xff])
3724 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3725 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3729 ÿÿ (Latin1 'ÿ' [0xff])
3732 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3733 the end of the list.
3735 std::string after
= search_name
;
3736 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3738 if (!after
.empty ())
3739 after
.back () = (unsigned char) after
.back () + 1;
3743 /* See declaration. */
3745 std::pair
<std::vector
<name_component
>::const_iterator
,
3746 std::vector
<name_component
>::const_iterator
>
3747 mapped_index_base::find_name_components_bounds
3748 (const lookup_name_info
&lookup_name_without_params
, language lang
) const
3751 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3753 const char *lang_name
3754 = lookup_name_without_params
.language_lookup_name (lang
).c_str ();
3756 /* Comparison function object for lower_bound that matches against a
3757 given symbol name. */
3758 auto lookup_compare_lower
= [&] (const name_component
&elem
,
3761 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
3762 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3763 return name_cmp (elem_name
, name
) < 0;
3766 /* Comparison function object for upper_bound that matches against a
3767 given symbol name. */
3768 auto lookup_compare_upper
= [&] (const char *name
,
3769 const name_component
&elem
)
3771 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
3772 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3773 return name_cmp (name
, elem_name
) < 0;
3776 auto begin
= this->name_components
.begin ();
3777 auto end
= this->name_components
.end ();
3779 /* Find the lower bound. */
3782 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3785 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
3788 /* Find the upper bound. */
3791 if (lookup_name_without_params
.completion_mode ())
3793 /* In completion mode, we want UPPER to point past all
3794 symbols names that have the same prefix. I.e., with
3795 these symbols, and completing "func":
3797 function << lower bound
3799 other_function << upper bound
3801 We find the upper bound by looking for the insertion
3802 point of "func"-with-last-character-incremented,
3804 std::string after
= make_sort_after_prefix_name (lang_name
);
3807 return std::lower_bound (lower
, end
, after
.c_str (),
3808 lookup_compare_lower
);
3811 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
3814 return {lower
, upper
};
3817 /* See declaration. */
3820 mapped_index_base::build_name_components ()
3822 if (!this->name_components
.empty ())
3825 this->name_components_casing
= case_sensitivity
;
3827 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3829 /* The code below only knows how to break apart components of C++
3830 symbol names (and other languages that use '::' as
3831 namespace/module separator) and Ada symbol names. */
3832 auto count
= this->symbol_name_count ();
3833 for (offset_type idx
= 0; idx
< count
; idx
++)
3835 if (this->symbol_name_slot_invalid (idx
))
3838 const char *name
= this->symbol_name_at (idx
);
3840 /* Add each name component to the name component table. */
3841 unsigned int previous_len
= 0;
3843 if (strstr (name
, "::") != nullptr)
3845 for (unsigned int current_len
= cp_find_first_component (name
);
3846 name
[current_len
] != '\0';
3847 current_len
+= cp_find_first_component (name
+ current_len
))
3849 gdb_assert (name
[current_len
] == ':');
3850 this->name_components
.push_back ({previous_len
, idx
});
3851 /* Skip the '::'. */
3853 previous_len
= current_len
;
3858 /* Handle the Ada encoded (aka mangled) form here. */
3859 for (const char *iter
= strstr (name
, "__");
3861 iter
= strstr (iter
, "__"))
3863 this->name_components
.push_back ({previous_len
, idx
});
3865 previous_len
= iter
- name
;
3869 this->name_components
.push_back ({previous_len
, idx
});
3872 /* Sort name_components elements by name. */
3873 auto name_comp_compare
= [&] (const name_component
&left
,
3874 const name_component
&right
)
3876 const char *left_qualified
= this->symbol_name_at (left
.idx
);
3877 const char *right_qualified
= this->symbol_name_at (right
.idx
);
3879 const char *left_name
= left_qualified
+ left
.name_offset
;
3880 const char *right_name
= right_qualified
+ right
.name_offset
;
3882 return name_cmp (left_name
, right_name
) < 0;
3885 std::sort (this->name_components
.begin (),
3886 this->name_components
.end (),
3890 /* Helper for dw2_expand_symtabs_matching that works with a
3891 mapped_index_base instead of the containing objfile. This is split
3892 to a separate function in order to be able to unit test the
3893 name_components matching using a mock mapped_index_base. For each
3894 symbol name that matches, calls MATCH_CALLBACK, passing it the
3895 symbol's index in the mapped_index_base symbol table. */
3898 dw2_expand_symtabs_matching_symbol
3899 (mapped_index_base
&index
,
3900 const lookup_name_info
&lookup_name_in
,
3901 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3902 enum search_domain kind
,
3903 gdb::function_view
<bool (offset_type
)> match_callback
)
3905 lookup_name_info lookup_name_without_params
3906 = lookup_name_in
.make_ignore_params ();
3908 /* Build the symbol name component sorted vector, if we haven't
3910 index
.build_name_components ();
3912 /* The same symbol may appear more than once in the range though.
3913 E.g., if we're looking for symbols that complete "w", and we have
3914 a symbol named "w1::w2", we'll find the two name components for
3915 that same symbol in the range. To be sure we only call the
3916 callback once per symbol, we first collect the symbol name
3917 indexes that matched in a temporary vector and ignore
3919 std::vector
<offset_type
> matches
;
3921 struct name_and_matcher
3923 symbol_name_matcher_ftype
*matcher
;
3924 const std::string
&name
;
3926 bool operator== (const name_and_matcher
&other
) const
3928 return matcher
== other
.matcher
&& name
== other
.name
;
3932 /* A vector holding all the different symbol name matchers, for all
3934 std::vector
<name_and_matcher
> matchers
;
3936 for (int i
= 0; i
< nr_languages
; i
++)
3938 enum language lang_e
= (enum language
) i
;
3940 const language_defn
*lang
= language_def (lang_e
);
3941 symbol_name_matcher_ftype
*name_matcher
3942 = get_symbol_name_matcher (lang
, lookup_name_without_params
);
3944 name_and_matcher key
{
3946 lookup_name_without_params
.language_lookup_name (lang_e
)
3949 /* Don't insert the same comparison routine more than once.
3950 Note that we do this linear walk. This is not a problem in
3951 practice because the number of supported languages is
3953 if (std::find (matchers
.begin (), matchers
.end (), key
)
3956 matchers
.push_back (std::move (key
));
3959 = index
.find_name_components_bounds (lookup_name_without_params
,
3962 /* Now for each symbol name in range, check to see if we have a name
3963 match, and if so, call the MATCH_CALLBACK callback. */
3965 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
3967 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
3969 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
3970 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
3973 matches
.push_back (bounds
.first
->idx
);
3977 std::sort (matches
.begin (), matches
.end ());
3979 /* Finally call the callback, once per match. */
3981 for (offset_type idx
: matches
)
3985 if (!match_callback (idx
))
3991 /* Above we use a type wider than idx's for 'prev', since 0 and
3992 (offset_type)-1 are both possible values. */
3993 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
3998 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4000 /* A mock .gdb_index/.debug_names-like name index table, enough to
4001 exercise dw2_expand_symtabs_matching_symbol, which works with the
4002 mapped_index_base interface. Builds an index from the symbol list
4003 passed as parameter to the constructor. */
4004 class mock_mapped_index
: public mapped_index_base
4007 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4008 : m_symbol_table (symbols
)
4011 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4013 /* Return the number of names in the symbol table. */
4014 size_t symbol_name_count () const override
4016 return m_symbol_table
.size ();
4019 /* Get the name of the symbol at IDX in the symbol table. */
4020 const char *symbol_name_at (offset_type idx
) const override
4022 return m_symbol_table
[idx
];
4026 gdb::array_view
<const char *> m_symbol_table
;
4029 /* Convenience function that converts a NULL pointer to a "<null>"
4030 string, to pass to print routines. */
4033 string_or_null (const char *str
)
4035 return str
!= NULL
? str
: "<null>";
4038 /* Check if a lookup_name_info built from
4039 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4040 index. EXPECTED_LIST is the list of expected matches, in expected
4041 matching order. If no match expected, then an empty list is
4042 specified. Returns true on success. On failure prints a warning
4043 indicating the file:line that failed, and returns false. */
4046 check_match (const char *file
, int line
,
4047 mock_mapped_index
&mock_index
,
4048 const char *name
, symbol_name_match_type match_type
,
4049 bool completion_mode
,
4050 std::initializer_list
<const char *> expected_list
)
4052 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4054 bool matched
= true;
4056 auto mismatch
= [&] (const char *expected_str
,
4059 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4060 "expected=\"%s\", got=\"%s\"\n"),
4062 (match_type
== symbol_name_match_type::FULL
4064 name
, string_or_null (expected_str
), string_or_null (got
));
4068 auto expected_it
= expected_list
.begin ();
4069 auto expected_end
= expected_list
.end ();
4071 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4073 [&] (offset_type idx
)
4075 const char *matched_name
= mock_index
.symbol_name_at (idx
);
4076 const char *expected_str
4077 = expected_it
== expected_end
? NULL
: *expected_it
++;
4079 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4080 mismatch (expected_str
, matched_name
);
4084 const char *expected_str
4085 = expected_it
== expected_end
? NULL
: *expected_it
++;
4086 if (expected_str
!= NULL
)
4087 mismatch (expected_str
, NULL
);
4092 /* The symbols added to the mock mapped_index for testing (in
4094 static const char *test_symbols
[] = {
4103 "ns2::tmpl<int>::foo2",
4104 "(anonymous namespace)::A::B::C",
4106 /* These are used to check that the increment-last-char in the
4107 matching algorithm for completion doesn't match "t1_fund" when
4108 completing "t1_func". */
4114 /* A UTF-8 name with multi-byte sequences to make sure that
4115 cp-name-parser understands this as a single identifier ("função"
4116 is "function" in PT). */
4119 /* \377 (0xff) is Latin1 'ÿ'. */
4122 /* \377 (0xff) is Latin1 'ÿ'. */
4126 /* A name with all sorts of complications. Starts with "z" to make
4127 it easier for the completion tests below. */
4128 #define Z_SYM_NAME \
4129 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4130 "::tuple<(anonymous namespace)::ui*, " \
4131 "std::default_delete<(anonymous namespace)::ui>, void>"
4136 /* Returns true if the mapped_index_base::find_name_component_bounds
4137 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4138 in completion mode. */
4141 check_find_bounds_finds (mapped_index_base
&index
,
4142 const char *search_name
,
4143 gdb::array_view
<const char *> expected_syms
)
4145 lookup_name_info
lookup_name (search_name
,
4146 symbol_name_match_type::FULL
, true);
4148 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4151 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4152 if (distance
!= expected_syms
.size ())
4155 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4157 auto nc_elem
= bounds
.first
+ exp_elem
;
4158 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
4159 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4166 /* Test the lower-level mapped_index::find_name_component_bounds
4170 test_mapped_index_find_name_component_bounds ()
4172 mock_mapped_index
mock_index (test_symbols
);
4174 mock_index
.build_name_components ();
4176 /* Test the lower-level mapped_index::find_name_component_bounds
4177 method in completion mode. */
4179 static const char *expected_syms
[] = {
4184 SELF_CHECK (check_find_bounds_finds (mock_index
,
4185 "t1_func", expected_syms
));
4188 /* Check that the increment-last-char in the name matching algorithm
4189 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4191 static const char *expected_syms1
[] = {
4195 SELF_CHECK (check_find_bounds_finds (mock_index
,
4196 "\377", expected_syms1
));
4198 static const char *expected_syms2
[] = {
4201 SELF_CHECK (check_find_bounds_finds (mock_index
,
4202 "\377\377", expected_syms2
));
4206 /* Test dw2_expand_symtabs_matching_symbol. */
4209 test_dw2_expand_symtabs_matching_symbol ()
4211 mock_mapped_index
mock_index (test_symbols
);
4213 /* We let all tests run until the end even if some fails, for debug
4215 bool any_mismatch
= false;
4217 /* Create the expected symbols list (an initializer_list). Needed
4218 because lists have commas, and we need to pass them to CHECK,
4219 which is a macro. */
4220 #define EXPECT(...) { __VA_ARGS__ }
4222 /* Wrapper for check_match that passes down the current
4223 __FILE__/__LINE__. */
4224 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4225 any_mismatch |= !check_match (__FILE__, __LINE__, \
4227 NAME, MATCH_TYPE, COMPLETION_MODE, \
4230 /* Identity checks. */
4231 for (const char *sym
: test_symbols
)
4233 /* Should be able to match all existing symbols. */
4234 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4237 /* Should be able to match all existing symbols with
4239 std::string with_params
= std::string (sym
) + "(int)";
4240 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4243 /* Should be able to match all existing symbols with
4244 parameters and qualifiers. */
4245 with_params
= std::string (sym
) + " ( int ) const";
4246 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4249 /* This should really find sym, but cp-name-parser.y doesn't
4250 know about lvalue/rvalue qualifiers yet. */
4251 with_params
= std::string (sym
) + " ( int ) &&";
4252 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4256 /* Check that the name matching algorithm for completion doesn't get
4257 confused with Latin1 'ÿ' / 0xff. */
4259 static const char str
[] = "\377";
4260 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4261 EXPECT ("\377", "\377\377123"));
4264 /* Check that the increment-last-char in the matching algorithm for
4265 completion doesn't match "t1_fund" when completing "t1_func". */
4267 static const char str
[] = "t1_func";
4268 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4269 EXPECT ("t1_func", "t1_func1"));
4272 /* Check that completion mode works at each prefix of the expected
4275 static const char str
[] = "function(int)";
4276 size_t len
= strlen (str
);
4279 for (size_t i
= 1; i
< len
; i
++)
4281 lookup
.assign (str
, i
);
4282 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4283 EXPECT ("function"));
4287 /* While "w" is a prefix of both components, the match function
4288 should still only be called once. */
4290 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4292 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4296 /* Same, with a "complicated" symbol. */
4298 static const char str
[] = Z_SYM_NAME
;
4299 size_t len
= strlen (str
);
4302 for (size_t i
= 1; i
< len
; i
++)
4304 lookup
.assign (str
, i
);
4305 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4306 EXPECT (Z_SYM_NAME
));
4310 /* In FULL mode, an incomplete symbol doesn't match. */
4312 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4316 /* A complete symbol with parameters matches any overload, since the
4317 index has no overload info. */
4319 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4320 EXPECT ("std::zfunction", "std::zfunction2"));
4321 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4322 EXPECT ("std::zfunction", "std::zfunction2"));
4323 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4324 EXPECT ("std::zfunction", "std::zfunction2"));
4327 /* Check that whitespace is ignored appropriately. A symbol with a
4328 template argument list. */
4330 static const char expected
[] = "ns::foo<int>";
4331 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4333 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4337 /* Check that whitespace is ignored appropriately. A symbol with a
4338 template argument list that includes a pointer. */
4340 static const char expected
[] = "ns::foo<char*>";
4341 /* Try both completion and non-completion modes. */
4342 static const bool completion_mode
[2] = {false, true};
4343 for (size_t i
= 0; i
< 2; i
++)
4345 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4346 completion_mode
[i
], EXPECT (expected
));
4347 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4348 completion_mode
[i
], EXPECT (expected
));
4350 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4351 completion_mode
[i
], EXPECT (expected
));
4352 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4353 completion_mode
[i
], EXPECT (expected
));
4358 /* Check method qualifiers are ignored. */
4359 static const char expected
[] = "ns::foo<char*>";
4360 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4361 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4362 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4363 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4364 CHECK_MATCH ("foo < char * > ( int ) const",
4365 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4366 CHECK_MATCH ("foo < char * > ( int ) &&",
4367 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4370 /* Test lookup names that don't match anything. */
4372 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4375 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4379 /* Some wild matching tests, exercising "(anonymous namespace)",
4380 which should not be confused with a parameter list. */
4382 static const char *syms
[] = {
4386 "A :: B :: C ( int )",
4391 for (const char *s
: syms
)
4393 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4394 EXPECT ("(anonymous namespace)::A::B::C"));
4399 static const char expected
[] = "ns2::tmpl<int>::foo2";
4400 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4402 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4406 SELF_CHECK (!any_mismatch
);
4415 test_mapped_index_find_name_component_bounds ();
4416 test_dw2_expand_symtabs_matching_symbol ();
4419 }} // namespace selftests::dw2_expand_symtabs_matching
4421 #endif /* GDB_SELF_TEST */
4423 /* If FILE_MATCHER is NULL or if PER_CU has
4424 dwarf2_per_cu_quick_data::MARK set (see
4425 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4426 EXPANSION_NOTIFY on it. */
4429 dw2_expand_symtabs_matching_one
4430 (struct dwarf2_per_cu_data
*per_cu
,
4431 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4432 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4434 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4436 bool symtab_was_null
4437 = (per_cu
->v
.quick
->compunit_symtab
== NULL
);
4439 dw2_instantiate_symtab (per_cu
, false);
4441 if (expansion_notify
!= NULL
4443 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
4444 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
4448 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4449 matched, to expand corresponding CUs that were marked. IDX is the
4450 index of the symbol name that matched. */
4453 dw2_expand_marked_cus
4454 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
4455 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4456 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4459 offset_type
*vec
, vec_len
, vec_idx
;
4460 bool global_seen
= false;
4461 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
4463 vec
= (offset_type
*) (index
.constant_pool
4464 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
4465 vec_len
= MAYBE_SWAP (vec
[0]);
4466 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4468 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
4469 /* This value is only valid for index versions >= 7. */
4470 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4471 gdb_index_symbol_kind symbol_kind
=
4472 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4473 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4474 /* Only check the symbol attributes if they're present.
4475 Indices prior to version 7 don't record them,
4476 and indices >= 7 may elide them for certain symbols
4477 (gold does this). */
4480 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4482 /* Work around gold/15646. */
4485 if (!is_static
&& global_seen
)
4491 /* Only check the symbol's kind if it has one. */
4496 case VARIABLES_DOMAIN
:
4497 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4500 case FUNCTIONS_DOMAIN
:
4501 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4505 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4508 case MODULES_DOMAIN
:
4509 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4517 /* Don't crash on bad data. */
4518 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
4519 + dwarf2_per_objfile
->all_type_units
.size ()))
4521 complaint (_(".gdb_index entry has bad CU index"
4523 objfile_name (dwarf2_per_objfile
->objfile
));
4527 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
4528 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
4533 /* If FILE_MATCHER is non-NULL, set all the
4534 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4535 that match FILE_MATCHER. */
4538 dw_expand_symtabs_matching_file_matcher
4539 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4540 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4542 if (file_matcher
== NULL
)
4545 objfile
*const objfile
= dwarf2_per_objfile
->objfile
;
4547 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4549 NULL
, xcalloc
, xfree
));
4550 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4552 NULL
, xcalloc
, xfree
));
4554 /* The rule is CUs specify all the files, including those used by
4555 any TU, so there's no need to scan TUs here. */
4557 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4561 per_cu
->v
.quick
->mark
= 0;
4563 /* We only need to look at symtabs not already expanded. */
4564 if (per_cu
->v
.quick
->compunit_symtab
)
4567 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4568 if (file_data
== NULL
)
4571 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4573 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4575 per_cu
->v
.quick
->mark
= 1;
4579 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4581 const char *this_real_name
;
4583 if (file_matcher (file_data
->file_names
[j
], false))
4585 per_cu
->v
.quick
->mark
= 1;
4589 /* Before we invoke realpath, which can get expensive when many
4590 files are involved, do a quick comparison of the basenames. */
4591 if (!basenames_may_differ
4592 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4596 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
4597 if (file_matcher (this_real_name
, false))
4599 per_cu
->v
.quick
->mark
= 1;
4604 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4605 ? visited_found
.get ()
4606 : visited_not_found
.get (),
4613 dw2_expand_symtabs_matching
4614 (struct objfile
*objfile
,
4615 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4616 const lookup_name_info
&lookup_name
,
4617 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4618 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4619 enum search_domain kind
)
4621 struct dwarf2_per_objfile
*dwarf2_per_objfile
4622 = get_dwarf2_per_objfile (objfile
);
4624 /* index_table is NULL if OBJF_READNOW. */
4625 if (!dwarf2_per_objfile
->index_table
)
4628 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
4630 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
4632 dw2_expand_symtabs_matching_symbol (index
, lookup_name
,
4634 kind
, [&] (offset_type idx
)
4636 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
4637 expansion_notify
, kind
);
4642 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4645 static struct compunit_symtab
*
4646 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4651 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4652 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4655 if (cust
->includes
== NULL
)
4658 for (i
= 0; cust
->includes
[i
]; ++i
)
4660 struct compunit_symtab
*s
= cust
->includes
[i
];
4662 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4670 static struct compunit_symtab
*
4671 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
4672 struct bound_minimal_symbol msymbol
,
4674 struct obj_section
*section
,
4677 struct dwarf2_per_cu_data
*data
;
4678 struct compunit_symtab
*result
;
4680 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
4683 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4684 data
= (struct dwarf2_per_cu_data
*) addrmap_find
4685 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
4689 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
4690 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4691 paddress (get_objfile_arch (objfile
), pc
));
4694 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
,
4697 gdb_assert (result
!= NULL
);
4702 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
4703 void *data
, int need_fullname
)
4705 struct dwarf2_per_objfile
*dwarf2_per_objfile
4706 = get_dwarf2_per_objfile (objfile
);
4708 if (!dwarf2_per_objfile
->filenames_cache
)
4710 dwarf2_per_objfile
->filenames_cache
.emplace ();
4712 htab_up
visited (htab_create_alloc (10,
4713 htab_hash_pointer
, htab_eq_pointer
,
4714 NULL
, xcalloc
, xfree
));
4716 /* The rule is CUs specify all the files, including those used
4717 by any TU, so there's no need to scan TUs here. We can
4718 ignore file names coming from already-expanded CUs. */
4720 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4722 if (per_cu
->v
.quick
->compunit_symtab
)
4724 void **slot
= htab_find_slot (visited
.get (),
4725 per_cu
->v
.quick
->file_names
,
4728 *slot
= per_cu
->v
.quick
->file_names
;
4732 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4734 /* We only need to look at symtabs not already expanded. */
4735 if (per_cu
->v
.quick
->compunit_symtab
)
4738 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4739 if (file_data
== NULL
)
4742 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
4745 /* Already visited. */
4750 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4752 const char *filename
= file_data
->file_names
[j
];
4753 dwarf2_per_objfile
->filenames_cache
->seen (filename
);
4758 dwarf2_per_objfile
->filenames_cache
->traverse ([&] (const char *filename
)
4760 gdb::unique_xmalloc_ptr
<char> this_real_name
;
4763 this_real_name
= gdb_realpath (filename
);
4764 (*fun
) (filename
, this_real_name
.get (), data
);
4769 dw2_has_symbols (struct objfile
*objfile
)
4774 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
4777 dw2_find_last_source_symtab
,
4778 dw2_forget_cached_source_info
,
4779 dw2_map_symtabs_matching_filename
,
4783 dw2_expand_symtabs_for_function
,
4784 dw2_expand_all_symtabs
,
4785 dw2_expand_symtabs_with_fullname
,
4786 dw2_map_matching_symbols
,
4787 dw2_expand_symtabs_matching
,
4788 dw2_find_pc_sect_compunit_symtab
,
4790 dw2_map_symbol_filenames
4793 /* DWARF-5 debug_names reader. */
4795 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
4796 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
4798 /* A helper function that reads the .debug_names section in SECTION
4799 and fills in MAP. FILENAME is the name of the file containing the
4800 section; it is used for error reporting.
4802 Returns true if all went well, false otherwise. */
4805 read_debug_names_from_section (struct objfile
*objfile
,
4806 const char *filename
,
4807 struct dwarf2_section_info
*section
,
4808 mapped_debug_names
&map
)
4810 if (section
->empty ())
4813 /* Older elfutils strip versions could keep the section in the main
4814 executable while splitting it for the separate debug info file. */
4815 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
4818 section
->read (objfile
);
4820 map
.dwarf5_byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
4822 const gdb_byte
*addr
= section
->buffer
;
4824 bfd
*const abfd
= section
->get_bfd_owner ();
4826 unsigned int bytes_read
;
4827 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
4830 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
4831 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
4832 if (bytes_read
+ length
!= section
->size
)
4834 /* There may be multiple per-CU indices. */
4835 warning (_("Section .debug_names in %s length %s does not match "
4836 "section length %s, ignoring .debug_names."),
4837 filename
, plongest (bytes_read
+ length
),
4838 pulongest (section
->size
));
4842 /* The version number. */
4843 uint16_t version
= read_2_bytes (abfd
, addr
);
4847 warning (_("Section .debug_names in %s has unsupported version %d, "
4848 "ignoring .debug_names."),
4854 uint16_t padding
= read_2_bytes (abfd
, addr
);
4858 warning (_("Section .debug_names in %s has unsupported padding %d, "
4859 "ignoring .debug_names."),
4864 /* comp_unit_count - The number of CUs in the CU list. */
4865 map
.cu_count
= read_4_bytes (abfd
, addr
);
4868 /* local_type_unit_count - The number of TUs in the local TU
4870 map
.tu_count
= read_4_bytes (abfd
, addr
);
4873 /* foreign_type_unit_count - The number of TUs in the foreign TU
4875 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
4877 if (foreign_tu_count
!= 0)
4879 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
4880 "ignoring .debug_names."),
4881 filename
, static_cast<unsigned long> (foreign_tu_count
));
4885 /* bucket_count - The number of hash buckets in the hash lookup
4887 map
.bucket_count
= read_4_bytes (abfd
, addr
);
4890 /* name_count - The number of unique names in the index. */
4891 map
.name_count
= read_4_bytes (abfd
, addr
);
4894 /* abbrev_table_size - The size in bytes of the abbreviations
4896 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
4899 /* augmentation_string_size - The size in bytes of the augmentation
4900 string. This value is rounded up to a multiple of 4. */
4901 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
4903 map
.augmentation_is_gdb
= ((augmentation_string_size
4904 == sizeof (dwarf5_augmentation
))
4905 && memcmp (addr
, dwarf5_augmentation
,
4906 sizeof (dwarf5_augmentation
)) == 0);
4907 augmentation_string_size
+= (-augmentation_string_size
) & 3;
4908 addr
+= augmentation_string_size
;
4911 map
.cu_table_reordered
= addr
;
4912 addr
+= map
.cu_count
* map
.offset_size
;
4914 /* List of Local TUs */
4915 map
.tu_table_reordered
= addr
;
4916 addr
+= map
.tu_count
* map
.offset_size
;
4918 /* Hash Lookup Table */
4919 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4920 addr
+= map
.bucket_count
* 4;
4921 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4922 addr
+= map
.name_count
* 4;
4925 map
.name_table_string_offs_reordered
= addr
;
4926 addr
+= map
.name_count
* map
.offset_size
;
4927 map
.name_table_entry_offs_reordered
= addr
;
4928 addr
+= map
.name_count
* map
.offset_size
;
4930 const gdb_byte
*abbrev_table_start
= addr
;
4933 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4938 const auto insertpair
4939 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
4940 if (!insertpair
.second
)
4942 warning (_("Section .debug_names in %s has duplicate index %s, "
4943 "ignoring .debug_names."),
4944 filename
, pulongest (index_num
));
4947 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
4948 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4953 mapped_debug_names::index_val::attr attr
;
4954 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4956 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4958 if (attr
.form
== DW_FORM_implicit_const
)
4960 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
4964 if (attr
.dw_idx
== 0 && attr
.form
== 0)
4966 indexval
.attr_vec
.push_back (std::move (attr
));
4969 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
4971 warning (_("Section .debug_names in %s has abbreviation_table "
4972 "of size %s vs. written as %u, ignoring .debug_names."),
4973 filename
, plongest (addr
- abbrev_table_start
),
4977 map
.entry_pool
= addr
;
4982 /* A helper for create_cus_from_debug_names that handles the MAP's CU
4986 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4987 const mapped_debug_names
&map
,
4988 dwarf2_section_info
§ion
,
4991 sect_offset sect_off_prev
;
4992 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
4994 sect_offset sect_off_next
;
4995 if (i
< map
.cu_count
)
4998 = (sect_offset
) (extract_unsigned_integer
4999 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5001 map
.dwarf5_byte_order
));
5004 sect_off_next
= (sect_offset
) section
.size
;
5007 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5008 dwarf2_per_cu_data
*per_cu
5009 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
5010 sect_off_prev
, length
);
5011 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
5013 sect_off_prev
= sect_off_next
;
5017 /* Read the CU list from the mapped index, and use it to create all
5018 the CU objects for this dwarf2_per_objfile. */
5021 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5022 const mapped_debug_names
&map
,
5023 const mapped_debug_names
&dwz_map
)
5025 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
5026 dwarf2_per_objfile
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5028 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
5029 dwarf2_per_objfile
->info
,
5030 false /* is_dwz */);
5032 if (dwz_map
.cu_count
== 0)
5035 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5036 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
5040 /* Read .debug_names. If everything went ok, initialize the "quick"
5041 elements of all the CUs and return true. Otherwise, return false. */
5044 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
5046 std::unique_ptr
<mapped_debug_names
> map
5047 (new mapped_debug_names (dwarf2_per_objfile
));
5048 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
5049 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5051 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5052 &dwarf2_per_objfile
->debug_names
,
5056 /* Don't use the index if it's empty. */
5057 if (map
->name_count
== 0)
5060 /* If there is a .dwz file, read it so we can get its CU list as
5062 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5065 if (!read_debug_names_from_section (objfile
,
5066 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5067 &dwz
->debug_names
, dwz_map
))
5069 warning (_("could not read '.debug_names' section from %s; skipping"),
5070 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5075 create_cus_from_debug_names (dwarf2_per_objfile
, *map
, dwz_map
);
5077 if (map
->tu_count
!= 0)
5079 /* We can only handle a single .debug_types when we have an
5081 if (dwarf2_per_objfile
->types
.size () != 1)
5084 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
5086 create_signatured_type_table_from_debug_names
5087 (dwarf2_per_objfile
, *map
, section
, &dwarf2_per_objfile
->abbrev
);
5090 create_addrmap_from_aranges (dwarf2_per_objfile
,
5091 &dwarf2_per_objfile
->debug_aranges
);
5093 dwarf2_per_objfile
->debug_names_table
= std::move (map
);
5094 dwarf2_per_objfile
->using_index
= 1;
5095 dwarf2_per_objfile
->quick_file_names_table
=
5096 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
5101 /* Type used to manage iterating over all CUs looking for a symbol for
5104 class dw2_debug_names_iterator
5107 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5108 gdb::optional
<block_enum
> block_index
,
5111 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5112 m_addr (find_vec_in_debug_names (map
, name
))
5115 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5116 search_domain search
, uint32_t namei
)
5119 m_addr (find_vec_in_debug_names (map
, namei
))
5122 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5123 block_enum block_index
, domain_enum domain
,
5125 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5126 m_addr (find_vec_in_debug_names (map
, namei
))
5129 /* Return the next matching CU or NULL if there are no more. */
5130 dwarf2_per_cu_data
*next ();
5133 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5135 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5138 /* The internalized form of .debug_names. */
5139 const mapped_debug_names
&m_map
;
5141 /* If set, only look for symbols that match that block. Valid values are
5142 GLOBAL_BLOCK and STATIC_BLOCK. */
5143 const gdb::optional
<block_enum
> m_block_index
;
5145 /* The kind of symbol we're looking for. */
5146 const domain_enum m_domain
= UNDEF_DOMAIN
;
5147 const search_domain m_search
= ALL_DOMAIN
;
5149 /* The list of CUs from the index entry of the symbol, or NULL if
5151 const gdb_byte
*m_addr
;
5155 mapped_debug_names::namei_to_name (uint32_t namei
) const
5157 const ULONGEST namei_string_offs
5158 = extract_unsigned_integer ((name_table_string_offs_reordered
5159 + namei
* offset_size
),
5162 return read_indirect_string_at_offset
5163 (dwarf2_per_objfile
, dwarf2_per_objfile
->objfile
->obfd
, namei_string_offs
);
5166 /* Find a slot in .debug_names for the object named NAME. If NAME is
5167 found, return pointer to its pool data. If NAME cannot be found,
5171 dw2_debug_names_iterator::find_vec_in_debug_names
5172 (const mapped_debug_names
&map
, const char *name
)
5174 int (*cmp
) (const char *, const char *);
5176 gdb::unique_xmalloc_ptr
<char> without_params
;
5177 if (current_language
->la_language
== language_cplus
5178 || current_language
->la_language
== language_fortran
5179 || current_language
->la_language
== language_d
)
5181 /* NAME is already canonical. Drop any qualifiers as
5182 .debug_names does not contain any. */
5184 if (strchr (name
, '(') != NULL
)
5186 without_params
= cp_remove_params (name
);
5187 if (without_params
!= NULL
)
5188 name
= without_params
.get ();
5192 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5194 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5196 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5197 (map
.bucket_table_reordered
5198 + (full_hash
% map
.bucket_count
)), 4,
5199 map
.dwarf5_byte_order
);
5203 if (namei
>= map
.name_count
)
5205 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5207 namei
, map
.name_count
,
5208 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5214 const uint32_t namei_full_hash
5215 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5216 (map
.hash_table_reordered
+ namei
), 4,
5217 map
.dwarf5_byte_order
);
5218 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5221 if (full_hash
== namei_full_hash
)
5223 const char *const namei_string
= map
.namei_to_name (namei
);
5225 #if 0 /* An expensive sanity check. */
5226 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5228 complaint (_("Wrong .debug_names hash for string at index %u "
5230 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5235 if (cmp (namei_string
, name
) == 0)
5237 const ULONGEST namei_entry_offs
5238 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5239 + namei
* map
.offset_size
),
5240 map
.offset_size
, map
.dwarf5_byte_order
);
5241 return map
.entry_pool
+ namei_entry_offs
;
5246 if (namei
>= map
.name_count
)
5252 dw2_debug_names_iterator::find_vec_in_debug_names
5253 (const mapped_debug_names
&map
, uint32_t namei
)
5255 if (namei
>= map
.name_count
)
5257 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5259 namei
, map
.name_count
,
5260 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5264 const ULONGEST namei_entry_offs
5265 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5266 + namei
* map
.offset_size
),
5267 map
.offset_size
, map
.dwarf5_byte_order
);
5268 return map
.entry_pool
+ namei_entry_offs
;
5271 /* See dw2_debug_names_iterator. */
5273 dwarf2_per_cu_data
*
5274 dw2_debug_names_iterator::next ()
5279 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
5280 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5281 bfd
*const abfd
= objfile
->obfd
;
5285 unsigned int bytes_read
;
5286 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5287 m_addr
+= bytes_read
;
5291 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5292 if (indexval_it
== m_map
.abbrev_map
.cend ())
5294 complaint (_("Wrong .debug_names undefined abbrev code %s "
5296 pulongest (abbrev
), objfile_name (objfile
));
5299 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5300 enum class symbol_linkage
{
5304 } symbol_linkage_
= symbol_linkage::unknown
;
5305 dwarf2_per_cu_data
*per_cu
= NULL
;
5306 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5311 case DW_FORM_implicit_const
:
5312 ull
= attr
.implicit_const
;
5314 case DW_FORM_flag_present
:
5318 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5319 m_addr
+= bytes_read
;
5322 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5323 dwarf_form_name (attr
.form
),
5324 objfile_name (objfile
));
5327 switch (attr
.dw_idx
)
5329 case DW_IDX_compile_unit
:
5330 /* Don't crash on bad data. */
5331 if (ull
>= dwarf2_per_objfile
->all_comp_units
.size ())
5333 complaint (_(".debug_names entry has bad CU index %s"
5336 objfile_name (dwarf2_per_objfile
->objfile
));
5339 per_cu
= dwarf2_per_objfile
->get_cutu (ull
);
5341 case DW_IDX_type_unit
:
5342 /* Don't crash on bad data. */
5343 if (ull
>= dwarf2_per_objfile
->all_type_units
.size ())
5345 complaint (_(".debug_names entry has bad TU index %s"
5348 objfile_name (dwarf2_per_objfile
->objfile
));
5351 per_cu
= &dwarf2_per_objfile
->get_tu (ull
)->per_cu
;
5353 case DW_IDX_GNU_internal
:
5354 if (!m_map
.augmentation_is_gdb
)
5356 symbol_linkage_
= symbol_linkage::static_
;
5358 case DW_IDX_GNU_external
:
5359 if (!m_map
.augmentation_is_gdb
)
5361 symbol_linkage_
= symbol_linkage::extern_
;
5366 /* Skip if already read in. */
5367 if (per_cu
->v
.quick
->compunit_symtab
)
5370 /* Check static vs global. */
5371 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5373 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5374 const bool symbol_is_static
=
5375 symbol_linkage_
== symbol_linkage::static_
;
5376 if (want_static
!= symbol_is_static
)
5380 /* Match dw2_symtab_iter_next, symbol_kind
5381 and debug_names::psymbol_tag. */
5385 switch (indexval
.dwarf_tag
)
5387 case DW_TAG_variable
:
5388 case DW_TAG_subprogram
:
5389 /* Some types are also in VAR_DOMAIN. */
5390 case DW_TAG_typedef
:
5391 case DW_TAG_structure_type
:
5398 switch (indexval
.dwarf_tag
)
5400 case DW_TAG_typedef
:
5401 case DW_TAG_structure_type
:
5408 switch (indexval
.dwarf_tag
)
5411 case DW_TAG_variable
:
5418 switch (indexval
.dwarf_tag
)
5430 /* Match dw2_expand_symtabs_matching, symbol_kind and
5431 debug_names::psymbol_tag. */
5434 case VARIABLES_DOMAIN
:
5435 switch (indexval
.dwarf_tag
)
5437 case DW_TAG_variable
:
5443 case FUNCTIONS_DOMAIN
:
5444 switch (indexval
.dwarf_tag
)
5446 case DW_TAG_subprogram
:
5453 switch (indexval
.dwarf_tag
)
5455 case DW_TAG_typedef
:
5456 case DW_TAG_structure_type
:
5462 case MODULES_DOMAIN
:
5463 switch (indexval
.dwarf_tag
)
5477 static struct compunit_symtab
*
5478 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
5479 const char *name
, domain_enum domain
)
5481 struct dwarf2_per_objfile
*dwarf2_per_objfile
5482 = get_dwarf2_per_objfile (objfile
);
5484 const auto &mapp
= dwarf2_per_objfile
->debug_names_table
;
5487 /* index is NULL if OBJF_READNOW. */
5490 const auto &map
= *mapp
;
5492 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
);
5494 struct compunit_symtab
*stab_best
= NULL
;
5495 struct dwarf2_per_cu_data
*per_cu
;
5496 while ((per_cu
= iter
.next ()) != NULL
)
5498 struct symbol
*sym
, *with_opaque
= NULL
;
5499 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
5500 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
5501 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
5503 sym
= block_find_symbol (block
, name
, domain
,
5504 block_find_non_opaque_type_preferred
,
5507 /* Some caution must be observed with overloaded functions and
5508 methods, since the index will not contain any overload
5509 information (but NAME might contain it). */
5512 && strcmp_iw (sym
->search_name (), name
) == 0)
5514 if (with_opaque
!= NULL
5515 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
5518 /* Keep looking through other CUs. */
5524 /* This dumps minimal information about .debug_names. It is called
5525 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5526 uses this to verify that .debug_names has been loaded. */
5529 dw2_debug_names_dump (struct objfile
*objfile
)
5531 struct dwarf2_per_objfile
*dwarf2_per_objfile
5532 = get_dwarf2_per_objfile (objfile
);
5534 gdb_assert (dwarf2_per_objfile
->using_index
);
5535 printf_filtered (".debug_names:");
5536 if (dwarf2_per_objfile
->debug_names_table
)
5537 printf_filtered (" exists\n");
5539 printf_filtered (" faked for \"readnow\"\n");
5540 printf_filtered ("\n");
5544 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
5545 const char *func_name
)
5547 struct dwarf2_per_objfile
*dwarf2_per_objfile
5548 = get_dwarf2_per_objfile (objfile
);
5550 /* dwarf2_per_objfile->debug_names_table is NULL if OBJF_READNOW. */
5551 if (dwarf2_per_objfile
->debug_names_table
)
5553 const mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5555 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
);
5557 struct dwarf2_per_cu_data
*per_cu
;
5558 while ((per_cu
= iter
.next ()) != NULL
)
5559 dw2_instantiate_symtab (per_cu
, false);
5564 dw2_debug_names_map_matching_symbols
5565 (struct objfile
*objfile
,
5566 const lookup_name_info
&name
, domain_enum domain
,
5568 gdb::function_view
<symbol_found_callback_ftype
> callback
,
5569 symbol_compare_ftype
*ordered_compare
)
5571 struct dwarf2_per_objfile
*dwarf2_per_objfile
5572 = get_dwarf2_per_objfile (objfile
);
5574 /* debug_names_table is NULL if OBJF_READNOW. */
5575 if (!dwarf2_per_objfile
->debug_names_table
)
5578 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5579 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
5581 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5582 auto matcher
= [&] (const char *symname
)
5584 if (ordered_compare
== nullptr)
5586 return ordered_compare (symname
, match_name
) == 0;
5589 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
5590 [&] (offset_type namei
)
5592 /* The name was matched, now expand corresponding CUs that were
5594 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
);
5596 struct dwarf2_per_cu_data
*per_cu
;
5597 while ((per_cu
= iter
.next ()) != NULL
)
5598 dw2_expand_symtabs_matching_one (per_cu
, nullptr, nullptr);
5602 /* It's a shame we couldn't do this inside the
5603 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
5604 that have already been expanded. Instead, this loop matches what
5605 the psymtab code does. */
5606 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5608 struct compunit_symtab
*cust
= per_cu
->v
.quick
->compunit_symtab
;
5609 if (cust
!= nullptr)
5611 const struct block
*block
5612 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
5613 if (!iterate_over_symbols_terminated (block
, name
,
5621 dw2_debug_names_expand_symtabs_matching
5622 (struct objfile
*objfile
,
5623 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5624 const lookup_name_info
&lookup_name
,
5625 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5626 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5627 enum search_domain kind
)
5629 struct dwarf2_per_objfile
*dwarf2_per_objfile
5630 = get_dwarf2_per_objfile (objfile
);
5632 /* debug_names_table is NULL if OBJF_READNOW. */
5633 if (!dwarf2_per_objfile
->debug_names_table
)
5636 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5638 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5640 dw2_expand_symtabs_matching_symbol (map
, lookup_name
,
5642 kind
, [&] (offset_type namei
)
5644 /* The name was matched, now expand corresponding CUs that were
5646 dw2_debug_names_iterator
iter (map
, kind
, namei
);
5648 struct dwarf2_per_cu_data
*per_cu
;
5649 while ((per_cu
= iter
.next ()) != NULL
)
5650 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5656 const struct quick_symbol_functions dwarf2_debug_names_functions
=
5659 dw2_find_last_source_symtab
,
5660 dw2_forget_cached_source_info
,
5661 dw2_map_symtabs_matching_filename
,
5662 dw2_debug_names_lookup_symbol
,
5664 dw2_debug_names_dump
,
5665 dw2_debug_names_expand_symtabs_for_function
,
5666 dw2_expand_all_symtabs
,
5667 dw2_expand_symtabs_with_fullname
,
5668 dw2_debug_names_map_matching_symbols
,
5669 dw2_debug_names_expand_symtabs_matching
,
5670 dw2_find_pc_sect_compunit_symtab
,
5672 dw2_map_symbol_filenames
5675 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5676 to either a dwarf2_per_objfile or dwz_file object. */
5678 template <typename T
>
5679 static gdb::array_view
<const gdb_byte
>
5680 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5682 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5684 if (section
->empty ())
5687 /* Older elfutils strip versions could keep the section in the main
5688 executable while splitting it for the separate debug info file. */
5689 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5692 section
->read (obj
);
5694 /* dwarf2_section_info::size is a bfd_size_type, while
5695 gdb::array_view works with size_t. On 32-bit hosts, with
5696 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5697 is 32-bit. So we need an explicit narrowing conversion here.
5698 This is fine, because it's impossible to allocate or mmap an
5699 array/buffer larger than what size_t can represent. */
5700 return gdb::make_array_view (section
->buffer
, section
->size
);
5703 /* Lookup the index cache for the contents of the index associated to
5706 static gdb::array_view
<const gdb_byte
>
5707 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_objfile
*dwarf2_obj
)
5709 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5710 if (build_id
== nullptr)
5713 return global_index_cache
.lookup_gdb_index (build_id
,
5714 &dwarf2_obj
->index_cache_res
);
5717 /* Same as the above, but for DWZ. */
5719 static gdb::array_view
<const gdb_byte
>
5720 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5722 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5723 if (build_id
== nullptr)
5726 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5729 /* See symfile.h. */
5732 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
5734 struct dwarf2_per_objfile
*dwarf2_per_objfile
5735 = get_dwarf2_per_objfile (objfile
);
5737 /* If we're about to read full symbols, don't bother with the
5738 indices. In this case we also don't care if some other debug
5739 format is making psymtabs, because they are all about to be
5741 if ((objfile
->flags
& OBJF_READNOW
))
5743 dwarf2_per_objfile
->using_index
= 1;
5744 create_all_comp_units (dwarf2_per_objfile
);
5745 create_all_type_units (dwarf2_per_objfile
);
5746 dwarf2_per_objfile
->quick_file_names_table
5747 = create_quick_file_names_table
5748 (dwarf2_per_objfile
->all_comp_units
.size ());
5750 for (int i
= 0; i
< (dwarf2_per_objfile
->all_comp_units
.size ()
5751 + dwarf2_per_objfile
->all_type_units
.size ()); ++i
)
5753 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
5755 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5756 struct dwarf2_per_cu_quick_data
);
5759 /* Return 1 so that gdb sees the "quick" functions. However,
5760 these functions will be no-ops because we will have expanded
5762 *index_kind
= dw_index_kind::GDB_INDEX
;
5766 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
5768 *index_kind
= dw_index_kind::DEBUG_NAMES
;
5772 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5773 get_gdb_index_contents_from_section
<struct dwarf2_per_objfile
>,
5774 get_gdb_index_contents_from_section
<dwz_file
>))
5776 *index_kind
= dw_index_kind::GDB_INDEX
;
5780 /* ... otherwise, try to find the index in the index cache. */
5781 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5782 get_gdb_index_contents_from_cache
,
5783 get_gdb_index_contents_from_cache_dwz
))
5785 global_index_cache
.hit ();
5786 *index_kind
= dw_index_kind::GDB_INDEX
;
5790 global_index_cache
.miss ();
5796 /* Build a partial symbol table. */
5799 dwarf2_build_psymtabs (struct objfile
*objfile
)
5801 struct dwarf2_per_objfile
*dwarf2_per_objfile
5802 = get_dwarf2_per_objfile (objfile
);
5804 init_psymbol_list (objfile
, 1024);
5808 /* This isn't really ideal: all the data we allocate on the
5809 objfile's obstack is still uselessly kept around. However,
5810 freeing it seems unsafe. */
5811 psymtab_discarder
psymtabs (objfile
);
5812 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
5815 /* (maybe) store an index in the cache. */
5816 global_index_cache
.store (dwarf2_per_objfile
);
5818 catch (const gdb_exception_error
&except
)
5820 exception_print (gdb_stderr
, except
);
5824 /* Find the base address of the compilation unit for range lists and
5825 location lists. It will normally be specified by DW_AT_low_pc.
5826 In DWARF-3 draft 4, the base address could be overridden by
5827 DW_AT_entry_pc. It's been removed, but GCC still uses this for
5828 compilation units with discontinuous ranges. */
5831 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
5833 struct attribute
*attr
;
5836 cu
->base_address
= 0;
5838 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
5839 if (attr
!= nullptr)
5841 cu
->base_address
= attr
->value_as_address ();
5846 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5847 if (attr
!= nullptr)
5849 cu
->base_address
= attr
->value_as_address ();
5855 /* Helper function that returns the proper abbrev section for
5858 static struct dwarf2_section_info
*
5859 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
5861 struct dwarf2_section_info
*abbrev
;
5862 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
5864 if (this_cu
->is_dwz
)
5865 abbrev
= &dwarf2_get_dwz_file (dwarf2_per_objfile
)->abbrev
;
5867 abbrev
= &dwarf2_per_objfile
->abbrev
;
5872 /* Fetch the abbreviation table offset from a comp or type unit header. */
5875 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5876 struct dwarf2_section_info
*section
,
5877 sect_offset sect_off
)
5879 bfd
*abfd
= section
->get_bfd_owner ();
5880 const gdb_byte
*info_ptr
;
5881 unsigned int initial_length_size
, offset_size
;
5884 section
->read (dwarf2_per_objfile
->objfile
);
5885 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
5886 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
5887 offset_size
= initial_length_size
== 4 ? 4 : 8;
5888 info_ptr
+= initial_length_size
;
5890 version
= read_2_bytes (abfd
, info_ptr
);
5894 /* Skip unit type and address size. */
5898 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
5901 /* Allocate a new partial symtab for file named NAME and mark this new
5902 partial symtab as being an include of PST. */
5905 dwarf2_create_include_psymtab (const char *name
, dwarf2_psymtab
*pst
,
5906 struct objfile
*objfile
)
5908 dwarf2_psymtab
*subpst
= new dwarf2_psymtab (name
, objfile
);
5910 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
5912 /* It shares objfile->objfile_obstack. */
5913 subpst
->dirname
= pst
->dirname
;
5916 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
5917 subpst
->dependencies
[0] = pst
;
5918 subpst
->number_of_dependencies
= 1;
5920 /* No private part is necessary for include psymtabs. This property
5921 can be used to differentiate between such include psymtabs and
5922 the regular ones. */
5923 subpst
->per_cu_data
= nullptr;
5926 /* Read the Line Number Program data and extract the list of files
5927 included by the source file represented by PST. Build an include
5928 partial symtab for each of these included files. */
5931 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
5932 struct die_info
*die
,
5933 dwarf2_psymtab
*pst
)
5936 struct attribute
*attr
;
5938 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5939 if (attr
!= nullptr)
5940 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
5942 return; /* No linetable, so no includes. */
5944 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
5945 that we pass in the raw text_low here; that is ok because we're
5946 only decoding the line table to make include partial symtabs, and
5947 so the addresses aren't really used. */
5948 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
5949 pst
->raw_text_low (), 1);
5953 hash_signatured_type (const void *item
)
5955 const struct signatured_type
*sig_type
5956 = (const struct signatured_type
*) item
;
5958 /* This drops the top 32 bits of the signature, but is ok for a hash. */
5959 return sig_type
->signature
;
5963 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
5965 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
5966 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
5968 return lhs
->signature
== rhs
->signature
;
5971 /* Allocate a hash table for signatured types. */
5974 allocate_signatured_type_table (struct objfile
*objfile
)
5976 return htab_up (htab_create_alloc (41,
5977 hash_signatured_type
,
5979 NULL
, xcalloc
, xfree
));
5982 /* A helper function to add a signatured type CU to a table. */
5985 add_signatured_type_cu_to_table (void **slot
, void *datum
)
5987 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
5988 std::vector
<signatured_type
*> *all_type_units
5989 = (std::vector
<signatured_type
*> *) datum
;
5991 all_type_units
->push_back (sigt
);
5996 /* A helper for create_debug_types_hash_table. Read types from SECTION
5997 and fill them into TYPES_HTAB. It will process only type units,
5998 therefore DW_UT_type. */
6001 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6002 struct dwo_file
*dwo_file
,
6003 dwarf2_section_info
*section
, htab_up
&types_htab
,
6004 rcuh_kind section_kind
)
6006 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6007 struct dwarf2_section_info
*abbrev_section
;
6009 const gdb_byte
*info_ptr
, *end_ptr
;
6011 abbrev_section
= (dwo_file
!= NULL
6012 ? &dwo_file
->sections
.abbrev
6013 : &dwarf2_per_objfile
->abbrev
);
6015 if (dwarf_read_debug
)
6016 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6017 section
->get_name (),
6018 abbrev_section
->get_file_name ());
6020 section
->read (objfile
);
6021 info_ptr
= section
->buffer
;
6023 if (info_ptr
== NULL
)
6026 /* We can't set abfd until now because the section may be empty or
6027 not present, in which case the bfd is unknown. */
6028 abfd
= section
->get_bfd_owner ();
6030 /* We don't use cutu_reader here because we don't need to read
6031 any dies: the signature is in the header. */
6033 end_ptr
= info_ptr
+ section
->size
;
6034 while (info_ptr
< end_ptr
)
6036 struct signatured_type
*sig_type
;
6037 struct dwo_unit
*dwo_tu
;
6039 const gdb_byte
*ptr
= info_ptr
;
6040 struct comp_unit_head header
;
6041 unsigned int length
;
6043 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6045 /* Initialize it due to a false compiler warning. */
6046 header
.signature
= -1;
6047 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6049 /* We need to read the type's signature in order to build the hash
6050 table, but we don't need anything else just yet. */
6052 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
6053 abbrev_section
, ptr
, section_kind
);
6055 length
= header
.get_length ();
6057 /* Skip dummy type units. */
6058 if (ptr
>= info_ptr
+ length
6059 || peek_abbrev_code (abfd
, ptr
) == 0
6060 || header
.unit_type
!= DW_UT_type
)
6066 if (types_htab
== NULL
)
6069 types_htab
= allocate_dwo_unit_table (objfile
);
6071 types_htab
= allocate_signatured_type_table (objfile
);
6077 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6079 dwo_tu
->dwo_file
= dwo_file
;
6080 dwo_tu
->signature
= header
.signature
;
6081 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6082 dwo_tu
->section
= section
;
6083 dwo_tu
->sect_off
= sect_off
;
6084 dwo_tu
->length
= length
;
6088 /* N.B.: type_offset is not usable if this type uses a DWO file.
6089 The real type_offset is in the DWO file. */
6091 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6092 struct signatured_type
);
6093 sig_type
->signature
= header
.signature
;
6094 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6095 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6096 sig_type
->per_cu
.is_debug_types
= 1;
6097 sig_type
->per_cu
.section
= section
;
6098 sig_type
->per_cu
.sect_off
= sect_off
;
6099 sig_type
->per_cu
.length
= length
;
6102 slot
= htab_find_slot (types_htab
.get (),
6103 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6105 gdb_assert (slot
!= NULL
);
6108 sect_offset dup_sect_off
;
6112 const struct dwo_unit
*dup_tu
6113 = (const struct dwo_unit
*) *slot
;
6115 dup_sect_off
= dup_tu
->sect_off
;
6119 const struct signatured_type
*dup_tu
6120 = (const struct signatured_type
*) *slot
;
6122 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6125 complaint (_("debug type entry at offset %s is duplicate to"
6126 " the entry at offset %s, signature %s"),
6127 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6128 hex_string (header
.signature
));
6130 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6132 if (dwarf_read_debug
> 1)
6133 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6134 sect_offset_str (sect_off
),
6135 hex_string (header
.signature
));
6141 /* Create the hash table of all entries in the .debug_types
6142 (or .debug_types.dwo) section(s).
6143 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6144 otherwise it is NULL.
6146 The result is a pointer to the hash table or NULL if there are no types.
6148 Note: This function processes DWO files only, not DWP files. */
6151 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6152 struct dwo_file
*dwo_file
,
6153 gdb::array_view
<dwarf2_section_info
> type_sections
,
6154 htab_up
&types_htab
)
6156 for (dwarf2_section_info
§ion
: type_sections
)
6157 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, §ion
,
6158 types_htab
, rcuh_kind::TYPE
);
6161 /* Create the hash table of all entries in the .debug_types section,
6162 and initialize all_type_units.
6163 The result is zero if there is an error (e.g. missing .debug_types section),
6164 otherwise non-zero. */
6167 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6171 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
6172 &dwarf2_per_objfile
->info
, types_htab
,
6173 rcuh_kind::COMPILE
);
6174 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
6175 dwarf2_per_objfile
->types
, types_htab
);
6176 if (types_htab
== NULL
)
6178 dwarf2_per_objfile
->signatured_types
= NULL
;
6182 dwarf2_per_objfile
->signatured_types
= std::move (types_htab
);
6184 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
6185 dwarf2_per_objfile
->all_type_units
.reserve
6186 (htab_elements (dwarf2_per_objfile
->signatured_types
.get ()));
6188 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
.get (),
6189 add_signatured_type_cu_to_table
,
6190 &dwarf2_per_objfile
->all_type_units
);
6195 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
6196 If SLOT is non-NULL, it is the entry to use in the hash table.
6197 Otherwise we find one. */
6199 static struct signatured_type
*
6200 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
6203 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6205 if (dwarf2_per_objfile
->all_type_units
.size ()
6206 == dwarf2_per_objfile
->all_type_units
.capacity ())
6207 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
6209 signatured_type
*sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6210 struct signatured_type
);
6212 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
6213 sig_type
->signature
= sig
;
6214 sig_type
->per_cu
.is_debug_types
= 1;
6215 if (dwarf2_per_objfile
->using_index
)
6217 sig_type
->per_cu
.v
.quick
=
6218 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6219 struct dwarf2_per_cu_quick_data
);
6224 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6227 gdb_assert (*slot
== NULL
);
6229 /* The rest of sig_type must be filled in by the caller. */
6233 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6234 Fill in SIG_ENTRY with DWO_ENTRY. */
6237 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6238 struct signatured_type
*sig_entry
,
6239 struct dwo_unit
*dwo_entry
)
6241 /* Make sure we're not clobbering something we don't expect to. */
6242 gdb_assert (! sig_entry
->per_cu
.queued
);
6243 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
6244 if (dwarf2_per_objfile
->using_index
)
6246 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6247 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
6250 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6251 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6252 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6253 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6254 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6256 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6257 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6258 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6259 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6260 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6261 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6262 sig_entry
->dwo_unit
= dwo_entry
;
6265 /* Subroutine of lookup_signatured_type.
6266 If we haven't read the TU yet, create the signatured_type data structure
6267 for a TU to be read in directly from a DWO file, bypassing the stub.
6268 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6269 using .gdb_index, then when reading a CU we want to stay in the DWO file
6270 containing that CU. Otherwise we could end up reading several other DWO
6271 files (due to comdat folding) to process the transitive closure of all the
6272 mentioned TUs, and that can be slow. The current DWO file will have every
6273 type signature that it needs.
6274 We only do this for .gdb_index because in the psymtab case we already have
6275 to read all the DWOs to build the type unit groups. */
6277 static struct signatured_type
*
6278 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6280 struct dwarf2_per_objfile
*dwarf2_per_objfile
6281 = cu
->per_cu
->dwarf2_per_objfile
;
6282 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6283 struct dwo_file
*dwo_file
;
6284 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6285 struct signatured_type find_sig_entry
, *sig_entry
;
6288 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6290 /* If TU skeletons have been removed then we may not have read in any
6292 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6294 dwarf2_per_objfile
->signatured_types
6295 = allocate_signatured_type_table (objfile
);
6298 /* We only ever need to read in one copy of a signatured type.
6299 Use the global signatured_types array to do our own comdat-folding
6300 of types. If this is the first time we're reading this TU, and
6301 the TU has an entry in .gdb_index, replace the recorded data from
6302 .gdb_index with this TU. */
6304 find_sig_entry
.signature
= sig
;
6305 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6306 &find_sig_entry
, INSERT
);
6307 sig_entry
= (struct signatured_type
*) *slot
;
6309 /* We can get here with the TU already read, *or* in the process of being
6310 read. Don't reassign the global entry to point to this DWO if that's
6311 the case. Also note that if the TU is already being read, it may not
6312 have come from a DWO, the program may be a mix of Fission-compiled
6313 code and non-Fission-compiled code. */
6315 /* Have we already tried to read this TU?
6316 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6317 needn't exist in the global table yet). */
6318 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
6321 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6322 dwo_unit of the TU itself. */
6323 dwo_file
= cu
->dwo_unit
->dwo_file
;
6325 /* Ok, this is the first time we're reading this TU. */
6326 if (dwo_file
->tus
== NULL
)
6328 find_dwo_entry
.signature
= sig
;
6329 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6331 if (dwo_entry
== NULL
)
6334 /* If the global table doesn't have an entry for this TU, add one. */
6335 if (sig_entry
== NULL
)
6336 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6338 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6339 sig_entry
->per_cu
.tu_read
= 1;
6343 /* Subroutine of lookup_signatured_type.
6344 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6345 then try the DWP file. If the TU stub (skeleton) has been removed then
6346 it won't be in .gdb_index. */
6348 static struct signatured_type
*
6349 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6351 struct dwarf2_per_objfile
*dwarf2_per_objfile
6352 = cu
->per_cu
->dwarf2_per_objfile
;
6353 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6354 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
6355 struct dwo_unit
*dwo_entry
;
6356 struct signatured_type find_sig_entry
, *sig_entry
;
6359 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6360 gdb_assert (dwp_file
!= NULL
);
6362 /* If TU skeletons have been removed then we may not have read in any
6364 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6366 dwarf2_per_objfile
->signatured_types
6367 = allocate_signatured_type_table (objfile
);
6370 find_sig_entry
.signature
= sig
;
6371 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6372 &find_sig_entry
, INSERT
);
6373 sig_entry
= (struct signatured_type
*) *slot
;
6375 /* Have we already tried to read this TU?
6376 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6377 needn't exist in the global table yet). */
6378 if (sig_entry
!= NULL
)
6381 if (dwp_file
->tus
== NULL
)
6383 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
6384 sig
, 1 /* is_debug_types */);
6385 if (dwo_entry
== NULL
)
6388 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6389 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6394 /* Lookup a signature based type for DW_FORM_ref_sig8.
6395 Returns NULL if signature SIG is not present in the table.
6396 It is up to the caller to complain about this. */
6398 static struct signatured_type
*
6399 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6401 struct dwarf2_per_objfile
*dwarf2_per_objfile
6402 = cu
->per_cu
->dwarf2_per_objfile
;
6405 && dwarf2_per_objfile
->using_index
)
6407 /* We're in a DWO/DWP file, and we're using .gdb_index.
6408 These cases require special processing. */
6409 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
6410 return lookup_dwo_signatured_type (cu
, sig
);
6412 return lookup_dwp_signatured_type (cu
, sig
);
6416 struct signatured_type find_entry
, *entry
;
6418 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6420 find_entry
.signature
= sig
;
6421 entry
= ((struct signatured_type
*)
6422 htab_find (dwarf2_per_objfile
->signatured_types
.get (),
6428 /* Return the address base of the compile unit, which, if exists, is stored
6429 either at the attribute DW_AT_GNU_addr_base, or DW_AT_addr_base. */
6430 static gdb::optional
<ULONGEST
>
6431 lookup_addr_base (struct die_info
*comp_unit_die
)
6433 struct attribute
*attr
;
6434 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_addr_base
);
6435 if (attr
== nullptr)
6436 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_GNU_addr_base
);
6437 if (attr
== nullptr)
6438 return gdb::optional
<ULONGEST
> ();
6439 return DW_UNSND (attr
);
6442 /* Return range lists base of the compile unit, which, if exists, is stored
6443 either at the attribute DW_AT_rnglists_base or DW_AT_GNU_ranges_base. */
6445 lookup_ranges_base (struct die_info
*comp_unit_die
)
6447 struct attribute
*attr
;
6448 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_rnglists_base
);
6449 if (attr
== nullptr)
6450 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_GNU_ranges_base
);
6451 if (attr
== nullptr)
6453 return DW_UNSND (attr
);
6456 /* Low level DIE reading support. */
6458 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6461 init_cu_die_reader (struct die_reader_specs
*reader
,
6462 struct dwarf2_cu
*cu
,
6463 struct dwarf2_section_info
*section
,
6464 struct dwo_file
*dwo_file
,
6465 struct abbrev_table
*abbrev_table
)
6467 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6468 reader
->abfd
= section
->get_bfd_owner ();
6470 reader
->dwo_file
= dwo_file
;
6471 reader
->die_section
= section
;
6472 reader
->buffer
= section
->buffer
;
6473 reader
->buffer_end
= section
->buffer
+ section
->size
;
6474 reader
->abbrev_table
= abbrev_table
;
6477 /* Subroutine of cutu_reader to simplify it.
6478 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6479 There's just a lot of work to do, and cutu_reader is big enough
6482 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6483 from it to the DIE in the DWO. If NULL we are skipping the stub.
6484 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6485 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6486 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6487 STUB_COMP_DIR may be non-NULL.
6488 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6489 are filled in with the info of the DIE from the DWO file.
6490 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6491 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6492 kept around for at least as long as *RESULT_READER.
6494 The result is non-zero if a valid (non-dummy) DIE was found. */
6497 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
6498 struct dwo_unit
*dwo_unit
,
6499 struct die_info
*stub_comp_unit_die
,
6500 const char *stub_comp_dir
,
6501 struct die_reader_specs
*result_reader
,
6502 const gdb_byte
**result_info_ptr
,
6503 struct die_info
**result_comp_unit_die
,
6504 abbrev_table_up
*result_dwo_abbrev_table
)
6506 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6507 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6508 struct dwarf2_cu
*cu
= this_cu
->cu
;
6510 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6511 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6512 int i
,num_extra_attrs
;
6513 struct dwarf2_section_info
*dwo_abbrev_section
;
6514 struct die_info
*comp_unit_die
;
6516 /* At most one of these may be provided. */
6517 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6519 /* These attributes aren't processed until later:
6520 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6521 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6522 referenced later. However, these attributes are found in the stub
6523 which we won't have later. In order to not impose this complication
6524 on the rest of the code, we read them here and copy them to the
6533 if (stub_comp_unit_die
!= NULL
)
6535 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6537 if (! this_cu
->is_debug_types
)
6538 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6539 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6540 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6541 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6542 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6544 cu
->addr_base
= lookup_addr_base (stub_comp_unit_die
);
6546 /* There should be a DW_AT_rnglists_base (DW_AT_GNU_ranges_base) attribute
6547 here (if needed). We need the value before we can process
6549 cu
->ranges_base
= lookup_ranges_base (stub_comp_unit_die
);
6551 else if (stub_comp_dir
!= NULL
)
6553 /* Reconstruct the comp_dir attribute to simplify the code below. */
6554 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
6555 comp_dir
->name
= DW_AT_comp_dir
;
6556 comp_dir
->form
= DW_FORM_string
;
6557 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
6558 DW_STRING (comp_dir
) = stub_comp_dir
;
6561 /* Set up for reading the DWO CU/TU. */
6562 cu
->dwo_unit
= dwo_unit
;
6563 dwarf2_section_info
*section
= dwo_unit
->section
;
6564 section
->read (objfile
);
6565 abfd
= section
->get_bfd_owner ();
6566 begin_info_ptr
= info_ptr
= (section
->buffer
6567 + to_underlying (dwo_unit
->sect_off
));
6568 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6570 if (this_cu
->is_debug_types
)
6572 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
6574 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6575 &cu
->header
, section
,
6577 info_ptr
, rcuh_kind::TYPE
);
6578 /* This is not an assert because it can be caused by bad debug info. */
6579 if (sig_type
->signature
!= cu
->header
.signature
)
6581 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6582 " TU at offset %s [in module %s]"),
6583 hex_string (sig_type
->signature
),
6584 hex_string (cu
->header
.signature
),
6585 sect_offset_str (dwo_unit
->sect_off
),
6586 bfd_get_filename (abfd
));
6588 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6589 /* For DWOs coming from DWP files, we don't know the CU length
6590 nor the type's offset in the TU until now. */
6591 dwo_unit
->length
= cu
->header
.get_length ();
6592 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6594 /* Establish the type offset that can be used to lookup the type.
6595 For DWO files, we don't know it until now. */
6596 sig_type
->type_offset_in_section
6597 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6601 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6602 &cu
->header
, section
,
6604 info_ptr
, rcuh_kind::COMPILE
);
6605 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6606 /* For DWOs coming from DWP files, we don't know the CU length
6608 dwo_unit
->length
= cu
->header
.get_length ();
6611 *result_dwo_abbrev_table
6612 = abbrev_table::read (objfile
, dwo_abbrev_section
,
6613 cu
->header
.abbrev_sect_off
);
6614 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6615 result_dwo_abbrev_table
->get ());
6617 /* Read in the die, but leave space to copy over the attributes
6618 from the stub. This has the benefit of simplifying the rest of
6619 the code - all the work to maintain the illusion of a single
6620 DW_TAG_{compile,type}_unit DIE is done here. */
6621 num_extra_attrs
= ((stmt_list
!= NULL
)
6625 + (comp_dir
!= NULL
));
6626 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6629 /* Copy over the attributes from the stub to the DIE we just read in. */
6630 comp_unit_die
= *result_comp_unit_die
;
6631 i
= comp_unit_die
->num_attrs
;
6632 if (stmt_list
!= NULL
)
6633 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6635 comp_unit_die
->attrs
[i
++] = *low_pc
;
6636 if (high_pc
!= NULL
)
6637 comp_unit_die
->attrs
[i
++] = *high_pc
;
6639 comp_unit_die
->attrs
[i
++] = *ranges
;
6640 if (comp_dir
!= NULL
)
6641 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6642 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6644 if (dwarf_die_debug
)
6646 fprintf_unfiltered (gdb_stdlog
,
6647 "Read die from %s@0x%x of %s:\n",
6648 section
->get_name (),
6649 (unsigned) (begin_info_ptr
- section
->buffer
),
6650 bfd_get_filename (abfd
));
6651 dump_die (comp_unit_die
, dwarf_die_debug
);
6654 /* Skip dummy compilation units. */
6655 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6656 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6659 *result_info_ptr
= info_ptr
;
6663 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
6664 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
6665 signature is part of the header. */
6666 static gdb::optional
<ULONGEST
>
6667 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
6669 if (cu
->header
.version
>= 5)
6670 return cu
->header
.signature
;
6671 struct attribute
*attr
;
6672 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6673 if (attr
== nullptr)
6674 return gdb::optional
<ULONGEST
> ();
6675 return DW_UNSND (attr
);
6678 /* Subroutine of cutu_reader to simplify it.
6679 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6680 Returns NULL if the specified DWO unit cannot be found. */
6682 static struct dwo_unit
*
6683 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
6684 struct die_info
*comp_unit_die
,
6685 const char *dwo_name
)
6687 struct dwarf2_cu
*cu
= this_cu
->cu
;
6688 struct dwo_unit
*dwo_unit
;
6689 const char *comp_dir
;
6691 gdb_assert (cu
!= NULL
);
6693 /* Yeah, we look dwo_name up again, but it simplifies the code. */
6694 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6695 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6697 if (this_cu
->is_debug_types
)
6699 struct signatured_type
*sig_type
;
6701 /* Since this_cu is the first member of struct signatured_type,
6702 we can go from a pointer to one to a pointer to the other. */
6703 sig_type
= (struct signatured_type
*) this_cu
;
6704 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
6708 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
6709 if (!signature
.has_value ())
6710 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
6712 dwo_name
, objfile_name (this_cu
->dwarf2_per_objfile
->objfile
));
6713 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
6720 /* Subroutine of cutu_reader to simplify it.
6721 See it for a description of the parameters.
6722 Read a TU directly from a DWO file, bypassing the stub. */
6725 cutu_reader::init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
6726 int use_existing_cu
, int keep
)
6728 struct signatured_type
*sig_type
;
6729 struct die_reader_specs reader
;
6731 /* Verify we can do the following downcast, and that we have the
6733 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
6734 sig_type
= (struct signatured_type
*) this_cu
;
6735 gdb_assert (sig_type
->dwo_unit
!= NULL
);
6737 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
6739 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
6740 /* There's no need to do the rereading_dwo_cu handling that
6741 cutu_reader does since we don't read the stub. */
6745 /* If !use_existing_cu, this_cu->cu must be NULL. */
6746 gdb_assert (this_cu
->cu
== NULL
);
6747 m_new_cu
.reset (new dwarf2_cu (this_cu
));
6750 /* A future optimization, if needed, would be to use an existing
6751 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
6752 could share abbrev tables. */
6754 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
6755 NULL
/* stub_comp_unit_die */,
6756 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
6759 &m_dwo_abbrev_table
) == 0)
6766 /* Initialize a CU (or TU) and read its DIEs.
6767 If the CU defers to a DWO file, read the DWO file as well.
6769 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
6770 Otherwise the table specified in the comp unit header is read in and used.
6771 This is an optimization for when we already have the abbrev table.
6773 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
6774 Otherwise, a new CU is allocated with xmalloc.
6776 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
6777 read_in_chain. Otherwise the dwarf2_cu data is freed at the
6780 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
6781 struct abbrev_table
*abbrev_table
,
6782 int use_existing_cu
, int keep
,
6784 : die_reader_specs
{},
6785 m_this_cu (this_cu
),
6788 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6789 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6790 struct dwarf2_section_info
*section
= this_cu
->section
;
6791 bfd
*abfd
= section
->get_bfd_owner ();
6792 struct dwarf2_cu
*cu
;
6793 const gdb_byte
*begin_info_ptr
;
6794 struct signatured_type
*sig_type
= NULL
;
6795 struct dwarf2_section_info
*abbrev_section
;
6796 /* Non-zero if CU currently points to a DWO file and we need to
6797 reread it. When this happens we need to reread the skeleton die
6798 before we can reread the DWO file (this only applies to CUs, not TUs). */
6799 int rereading_dwo_cu
= 0;
6801 if (dwarf_die_debug
)
6802 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6803 this_cu
->is_debug_types
? "type" : "comp",
6804 sect_offset_str (this_cu
->sect_off
));
6806 if (use_existing_cu
)
6809 /* If we're reading a TU directly from a DWO file, including a virtual DWO
6810 file (instead of going through the stub), short-circuit all of this. */
6811 if (this_cu
->reading_dwo_directly
)
6813 /* Narrow down the scope of possibilities to have to understand. */
6814 gdb_assert (this_cu
->is_debug_types
);
6815 gdb_assert (abbrev_table
== NULL
);
6816 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
, keep
);
6820 /* This is cheap if the section is already read in. */
6821 section
->read (objfile
);
6823 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6825 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
6827 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
6830 /* If this CU is from a DWO file we need to start over, we need to
6831 refetch the attributes from the skeleton CU.
6832 This could be optimized by retrieving those attributes from when we
6833 were here the first time: the previous comp_unit_die was stored in
6834 comp_unit_obstack. But there's no data yet that we need this
6836 if (cu
->dwo_unit
!= NULL
)
6837 rereading_dwo_cu
= 1;
6841 /* If !use_existing_cu, this_cu->cu must be NULL. */
6842 gdb_assert (this_cu
->cu
== NULL
);
6843 m_new_cu
.reset (new dwarf2_cu (this_cu
));
6844 cu
= m_new_cu
.get ();
6847 /* Get the header. */
6848 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
6850 /* We already have the header, there's no need to read it in again. */
6851 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
6855 if (this_cu
->is_debug_types
)
6857 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6858 &cu
->header
, section
,
6859 abbrev_section
, info_ptr
,
6862 /* Since per_cu is the first member of struct signatured_type,
6863 we can go from a pointer to one to a pointer to the other. */
6864 sig_type
= (struct signatured_type
*) this_cu
;
6865 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
6866 gdb_assert (sig_type
->type_offset_in_tu
6867 == cu
->header
.type_cu_offset_in_tu
);
6868 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6870 /* LENGTH has not been set yet for type units if we're
6871 using .gdb_index. */
6872 this_cu
->length
= cu
->header
.get_length ();
6874 /* Establish the type offset that can be used to lookup the type. */
6875 sig_type
->type_offset_in_section
=
6876 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
6878 this_cu
->dwarf_version
= cu
->header
.version
;
6882 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6883 &cu
->header
, section
,
6886 rcuh_kind::COMPILE
);
6888 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6889 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
6890 this_cu
->dwarf_version
= cu
->header
.version
;
6894 /* Skip dummy compilation units. */
6895 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6896 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6902 /* If we don't have them yet, read the abbrevs for this compilation unit.
6903 And if we need to read them now, make sure they're freed when we're
6905 if (abbrev_table
!= NULL
)
6906 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
6909 m_abbrev_table_holder
6910 = abbrev_table::read (objfile
, abbrev_section
,
6911 cu
->header
.abbrev_sect_off
);
6912 abbrev_table
= m_abbrev_table_holder
.get ();
6915 /* Read the top level CU/TU die. */
6916 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
6917 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
6919 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
6925 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
6926 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
6927 table from the DWO file and pass the ownership over to us. It will be
6928 referenced from READER, so we must make sure to free it after we're done
6931 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
6932 DWO CU, that this test will fail (the attribute will not be present). */
6933 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6934 if (dwo_name
!= nullptr)
6936 struct dwo_unit
*dwo_unit
;
6937 struct die_info
*dwo_comp_unit_die
;
6939 if (comp_unit_die
->has_children
)
6941 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
6942 " has children (offset %s) [in module %s]"),
6943 sect_offset_str (this_cu
->sect_off
),
6944 bfd_get_filename (abfd
));
6946 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
, dwo_name
);
6947 if (dwo_unit
!= NULL
)
6949 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
6950 comp_unit_die
, NULL
,
6953 &m_dwo_abbrev_table
) == 0)
6959 comp_unit_die
= dwo_comp_unit_die
;
6963 /* Yikes, we couldn't find the rest of the DIE, we only have
6964 the stub. A complaint has already been logged. There's
6965 not much more we can do except pass on the stub DIE to
6966 die_reader_func. We don't want to throw an error on bad
6972 cutu_reader::~cutu_reader ()
6974 /* Done, clean up. */
6975 if (m_new_cu
!= NULL
&& m_keep
&& !dummy_p
)
6977 struct dwarf2_per_objfile
*dwarf2_per_objfile
6978 = m_this_cu
->dwarf2_per_objfile
;
6979 /* Link this CU into read_in_chain. */
6980 m_this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
6981 dwarf2_per_objfile
->read_in_chain
= m_this_cu
;
6982 /* The chain owns it now. */
6983 m_new_cu
.release ();
6987 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
6988 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
6989 assumed to have already done the lookup to find the DWO file).
6991 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
6992 THIS_CU->is_debug_types, but nothing else.
6994 We fill in THIS_CU->length.
6996 THIS_CU->cu is always freed when done.
6997 This is done in order to not leave THIS_CU->cu in a state where we have
6998 to care whether it refers to the "main" CU or the DWO CU.
7000 When parent_cu is passed, it is used to provide a default value for
7001 str_offsets_base and addr_base from the parent. */
7003 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
7004 struct dwarf2_cu
*parent_cu
,
7005 struct dwo_file
*dwo_file
)
7006 : die_reader_specs
{},
7009 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7010 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7011 struct dwarf2_section_info
*section
= this_cu
->section
;
7012 bfd
*abfd
= section
->get_bfd_owner ();
7013 struct dwarf2_section_info
*abbrev_section
;
7014 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7016 if (dwarf_die_debug
)
7017 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7018 this_cu
->is_debug_types
? "type" : "comp",
7019 sect_offset_str (this_cu
->sect_off
));
7021 gdb_assert (this_cu
->cu
== NULL
);
7023 abbrev_section
= (dwo_file
!= NULL
7024 ? &dwo_file
->sections
.abbrev
7025 : get_abbrev_section_for_cu (this_cu
));
7027 /* This is cheap if the section is already read in. */
7028 section
->read (objfile
);
7030 m_new_cu
.reset (new dwarf2_cu (this_cu
));
7032 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7033 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7034 &m_new_cu
->header
, section
,
7035 abbrev_section
, info_ptr
,
7036 (this_cu
->is_debug_types
7038 : rcuh_kind::COMPILE
));
7040 if (parent_cu
!= nullptr)
7042 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
7043 m_new_cu
->addr_base
= parent_cu
->addr_base
;
7045 this_cu
->length
= m_new_cu
->header
.get_length ();
7047 /* Skip dummy compilation units. */
7048 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7049 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7055 m_abbrev_table_holder
7056 = abbrev_table::read (objfile
, abbrev_section
,
7057 m_new_cu
->header
.abbrev_sect_off
);
7059 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
7060 m_abbrev_table_holder
.get ());
7061 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7065 /* Type Unit Groups.
7067 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7068 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7069 so that all types coming from the same compilation (.o file) are grouped
7070 together. A future step could be to put the types in the same symtab as
7071 the CU the types ultimately came from. */
7074 hash_type_unit_group (const void *item
)
7076 const struct type_unit_group
*tu_group
7077 = (const struct type_unit_group
*) item
;
7079 return hash_stmt_list_entry (&tu_group
->hash
);
7083 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7085 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7086 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7088 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7091 /* Allocate a hash table for type unit groups. */
7094 allocate_type_unit_groups_table (struct objfile
*objfile
)
7096 return htab_up (htab_create_alloc (3,
7097 hash_type_unit_group
,
7099 NULL
, xcalloc
, xfree
));
7102 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7103 partial symtabs. We combine several TUs per psymtab to not let the size
7104 of any one psymtab grow too big. */
7105 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7106 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7108 /* Helper routine for get_type_unit_group.
7109 Create the type_unit_group object used to hold one or more TUs. */
7111 static struct type_unit_group
*
7112 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7114 struct dwarf2_per_objfile
*dwarf2_per_objfile
7115 = cu
->per_cu
->dwarf2_per_objfile
;
7116 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7117 struct dwarf2_per_cu_data
*per_cu
;
7118 struct type_unit_group
*tu_group
;
7120 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7121 struct type_unit_group
);
7122 per_cu
= &tu_group
->per_cu
;
7123 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7125 if (dwarf2_per_objfile
->using_index
)
7127 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7128 struct dwarf2_per_cu_quick_data
);
7132 unsigned int line_offset
= to_underlying (line_offset_struct
);
7133 dwarf2_psymtab
*pst
;
7136 /* Give the symtab a useful name for debug purposes. */
7137 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7138 name
= string_printf ("<type_units_%d>",
7139 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7141 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7143 pst
= create_partial_symtab (per_cu
, name
.c_str ());
7144 pst
->anonymous
= true;
7147 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7148 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7153 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7154 STMT_LIST is a DW_AT_stmt_list attribute. */
7156 static struct type_unit_group
*
7157 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7159 struct dwarf2_per_objfile
*dwarf2_per_objfile
7160 = cu
->per_cu
->dwarf2_per_objfile
;
7161 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7162 struct type_unit_group
*tu_group
;
7164 unsigned int line_offset
;
7165 struct type_unit_group type_unit_group_for_lookup
;
7167 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
7169 dwarf2_per_objfile
->type_unit_groups
=
7170 allocate_type_unit_groups_table (dwarf2_per_objfile
->objfile
);
7173 /* Do we need to create a new group, or can we use an existing one? */
7177 line_offset
= DW_UNSND (stmt_list
);
7178 ++tu_stats
->nr_symtab_sharers
;
7182 /* Ugh, no stmt_list. Rare, but we have to handle it.
7183 We can do various things here like create one group per TU or
7184 spread them over multiple groups to split up the expansion work.
7185 To avoid worst case scenarios (too many groups or too large groups)
7186 we, umm, group them in bunches. */
7187 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7188 | (tu_stats
->nr_stmt_less_type_units
7189 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7190 ++tu_stats
->nr_stmt_less_type_units
;
7193 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7194 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7195 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
.get (),
7196 &type_unit_group_for_lookup
, INSERT
);
7199 tu_group
= (struct type_unit_group
*) *slot
;
7200 gdb_assert (tu_group
!= NULL
);
7204 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7205 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7207 ++tu_stats
->nr_symtabs
;
7213 /* Partial symbol tables. */
7215 /* Create a psymtab named NAME and assign it to PER_CU.
7217 The caller must fill in the following details:
7218 dirname, textlow, texthigh. */
7220 static dwarf2_psymtab
*
7221 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
7223 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
7224 dwarf2_psymtab
*pst
;
7226 pst
= new dwarf2_psymtab (name
, objfile
, 0);
7228 pst
->psymtabs_addrmap_supported
= true;
7230 /* This is the glue that links PST into GDB's symbol API. */
7231 pst
->per_cu_data
= per_cu
;
7232 per_cu
->v
.psymtab
= pst
;
7237 /* DIE reader function for process_psymtab_comp_unit. */
7240 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7241 const gdb_byte
*info_ptr
,
7242 struct die_info
*comp_unit_die
,
7243 enum language pretend_language
)
7245 struct dwarf2_cu
*cu
= reader
->cu
;
7246 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
7247 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7248 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7250 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7251 dwarf2_psymtab
*pst
;
7252 enum pc_bounds_kind cu_bounds_kind
;
7253 const char *filename
;
7255 gdb_assert (! per_cu
->is_debug_types
);
7257 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
7259 /* Allocate a new partial symbol table structure. */
7260 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7261 if (filename
== NULL
)
7264 pst
= create_partial_symtab (per_cu
, filename
);
7266 /* This must be done before calling dwarf2_build_include_psymtabs. */
7267 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7269 baseaddr
= objfile
->text_section_offset ();
7271 dwarf2_find_base_address (comp_unit_die
, cu
);
7273 /* Possibly set the default values of LOWPC and HIGHPC from
7275 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7276 &best_highpc
, cu
, pst
);
7277 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7280 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7283 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7285 /* Store the contiguous range if it is not empty; it can be
7286 empty for CUs with no code. */
7287 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
7291 /* Check if comp unit has_children.
7292 If so, read the rest of the partial symbols from this comp unit.
7293 If not, there's no more debug_info for this comp unit. */
7294 if (comp_unit_die
->has_children
)
7296 struct partial_die_info
*first_die
;
7297 CORE_ADDR lowpc
, highpc
;
7299 lowpc
= ((CORE_ADDR
) -1);
7300 highpc
= ((CORE_ADDR
) 0);
7302 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7304 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7305 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7307 /* If we didn't find a lowpc, set it to highpc to avoid
7308 complaints from `maint check'. */
7309 if (lowpc
== ((CORE_ADDR
) -1))
7312 /* If the compilation unit didn't have an explicit address range,
7313 then use the information extracted from its child dies. */
7314 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7317 best_highpc
= highpc
;
7320 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7321 best_lowpc
+ baseaddr
)
7323 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7324 best_highpc
+ baseaddr
)
7327 end_psymtab_common (objfile
, pst
);
7329 if (!cu
->per_cu
->imported_symtabs_empty ())
7332 int len
= cu
->per_cu
->imported_symtabs_size ();
7334 /* Fill in 'dependencies' here; we fill in 'users' in a
7336 pst
->number_of_dependencies
= len
;
7338 = objfile
->partial_symtabs
->allocate_dependencies (len
);
7339 for (i
= 0; i
< len
; ++i
)
7341 pst
->dependencies
[i
]
7342 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7345 cu
->per_cu
->imported_symtabs_free ();
7348 /* Get the list of files included in the current compilation unit,
7349 and build a psymtab for each of them. */
7350 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
7352 if (dwarf_read_debug
)
7353 fprintf_unfiltered (gdb_stdlog
,
7354 "Psymtab for %s unit @%s: %s - %s"
7355 ", %d global, %d static syms\n",
7356 per_cu
->is_debug_types
? "type" : "comp",
7357 sect_offset_str (per_cu
->sect_off
),
7358 paddress (gdbarch
, pst
->text_low (objfile
)),
7359 paddress (gdbarch
, pst
->text_high (objfile
)),
7360 pst
->n_global_syms
, pst
->n_static_syms
);
7363 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7364 Process compilation unit THIS_CU for a psymtab. */
7367 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
7368 bool want_partial_unit
,
7369 enum language pretend_language
)
7371 /* If this compilation unit was already read in, free the
7372 cached copy in order to read it in again. This is
7373 necessary because we skipped some symbols when we first
7374 read in the compilation unit (see load_partial_dies).
7375 This problem could be avoided, but the benefit is unclear. */
7376 if (this_cu
->cu
!= NULL
)
7377 free_one_cached_comp_unit (this_cu
);
7379 cutu_reader
reader (this_cu
, NULL
, 0, 0, false);
7385 else if (this_cu
->is_debug_types
)
7386 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7387 reader
.comp_unit_die
);
7388 else if (want_partial_unit
7389 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7390 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7391 reader
.comp_unit_die
,
7394 /* Age out any secondary CUs. */
7395 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
7398 /* Reader function for build_type_psymtabs. */
7401 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7402 const gdb_byte
*info_ptr
,
7403 struct die_info
*type_unit_die
)
7405 struct dwarf2_per_objfile
*dwarf2_per_objfile
7406 = reader
->cu
->per_cu
->dwarf2_per_objfile
;
7407 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7408 struct dwarf2_cu
*cu
= reader
->cu
;
7409 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7410 struct signatured_type
*sig_type
;
7411 struct type_unit_group
*tu_group
;
7412 struct attribute
*attr
;
7413 struct partial_die_info
*first_die
;
7414 CORE_ADDR lowpc
, highpc
;
7415 dwarf2_psymtab
*pst
;
7417 gdb_assert (per_cu
->is_debug_types
);
7418 sig_type
= (struct signatured_type
*) per_cu
;
7420 if (! type_unit_die
->has_children
)
7423 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
7424 tu_group
= get_type_unit_group (cu
, attr
);
7426 if (tu_group
->tus
== nullptr)
7427 tu_group
->tus
= new std::vector
<signatured_type
*>;
7428 tu_group
->tus
->push_back (sig_type
);
7430 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7431 pst
= create_partial_symtab (per_cu
, "");
7432 pst
->anonymous
= true;
7434 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7436 lowpc
= (CORE_ADDR
) -1;
7437 highpc
= (CORE_ADDR
) 0;
7438 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7440 end_psymtab_common (objfile
, pst
);
7443 /* Struct used to sort TUs by their abbreviation table offset. */
7445 struct tu_abbrev_offset
7447 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7448 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7451 signatured_type
*sig_type
;
7452 sect_offset abbrev_offset
;
7455 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
7458 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
7459 const struct tu_abbrev_offset
&b
)
7461 return a
.abbrev_offset
< b
.abbrev_offset
;
7464 /* Efficiently read all the type units.
7465 This does the bulk of the work for build_type_psymtabs.
7467 The efficiency is because we sort TUs by the abbrev table they use and
7468 only read each abbrev table once. In one program there are 200K TUs
7469 sharing 8K abbrev tables.
7471 The main purpose of this function is to support building the
7472 dwarf2_per_objfile->type_unit_groups table.
7473 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7474 can collapse the search space by grouping them by stmt_list.
7475 The savings can be significant, in the same program from above the 200K TUs
7476 share 8K stmt_list tables.
7478 FUNC is expected to call get_type_unit_group, which will create the
7479 struct type_unit_group if necessary and add it to
7480 dwarf2_per_objfile->type_unit_groups. */
7483 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7485 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7486 abbrev_table_up abbrev_table
;
7487 sect_offset abbrev_offset
;
7489 /* It's up to the caller to not call us multiple times. */
7490 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
7492 if (dwarf2_per_objfile
->all_type_units
.empty ())
7495 /* TUs typically share abbrev tables, and there can be way more TUs than
7496 abbrev tables. Sort by abbrev table to reduce the number of times we
7497 read each abbrev table in.
7498 Alternatives are to punt or to maintain a cache of abbrev tables.
7499 This is simpler and efficient enough for now.
7501 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7502 symtab to use). Typically TUs with the same abbrev offset have the same
7503 stmt_list value too so in practice this should work well.
7505 The basic algorithm here is:
7507 sort TUs by abbrev table
7508 for each TU with same abbrev table:
7509 read abbrev table if first user
7510 read TU top level DIE
7511 [IWBN if DWO skeletons had DW_AT_stmt_list]
7514 if (dwarf_read_debug
)
7515 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
7517 /* Sort in a separate table to maintain the order of all_type_units
7518 for .gdb_index: TU indices directly index all_type_units. */
7519 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7520 sorted_by_abbrev
.reserve (dwarf2_per_objfile
->all_type_units
.size ());
7522 for (signatured_type
*sig_type
: dwarf2_per_objfile
->all_type_units
)
7523 sorted_by_abbrev
.emplace_back
7524 (sig_type
, read_abbrev_offset (dwarf2_per_objfile
,
7525 sig_type
->per_cu
.section
,
7526 sig_type
->per_cu
.sect_off
));
7528 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
7529 sort_tu_by_abbrev_offset
);
7531 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7533 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7535 /* Switch to the next abbrev table if necessary. */
7536 if (abbrev_table
== NULL
7537 || tu
.abbrev_offset
!= abbrev_offset
)
7539 abbrev_offset
= tu
.abbrev_offset
;
7541 abbrev_table::read (dwarf2_per_objfile
->objfile
,
7542 &dwarf2_per_objfile
->abbrev
,
7544 ++tu_stats
->nr_uniq_abbrev_tables
;
7547 cutu_reader
reader (&tu
.sig_type
->per_cu
, abbrev_table
.get (),
7549 if (!reader
.dummy_p
)
7550 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7551 reader
.comp_unit_die
);
7555 /* Print collected type unit statistics. */
7558 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7560 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7562 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
7563 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
7564 dwarf2_per_objfile
->all_type_units
.size ());
7565 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
7566 tu_stats
->nr_uniq_abbrev_tables
);
7567 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
7568 tu_stats
->nr_symtabs
);
7569 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
7570 tu_stats
->nr_symtab_sharers
);
7571 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
7572 tu_stats
->nr_stmt_less_type_units
);
7573 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
7574 tu_stats
->nr_all_type_units_reallocs
);
7577 /* Traversal function for build_type_psymtabs. */
7580 build_type_psymtab_dependencies (void **slot
, void *info
)
7582 struct dwarf2_per_objfile
*dwarf2_per_objfile
7583 = (struct dwarf2_per_objfile
*) info
;
7584 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7585 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7586 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
7587 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7588 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7591 gdb_assert (len
> 0);
7592 gdb_assert (IS_TYPE_UNIT_GROUP (per_cu
));
7594 pst
->number_of_dependencies
= len
;
7595 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
7596 for (i
= 0; i
< len
; ++i
)
7598 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7599 gdb_assert (iter
->per_cu
.is_debug_types
);
7600 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
7601 iter
->type_unit_group
= tu_group
;
7604 delete tu_group
->tus
;
7605 tu_group
->tus
= nullptr;
7610 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7611 Build partial symbol tables for the .debug_types comp-units. */
7614 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7616 if (! create_all_type_units (dwarf2_per_objfile
))
7619 build_type_psymtabs_1 (dwarf2_per_objfile
);
7622 /* Traversal function for process_skeletonless_type_unit.
7623 Read a TU in a DWO file and build partial symbols for it. */
7626 process_skeletonless_type_unit (void **slot
, void *info
)
7628 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7629 struct dwarf2_per_objfile
*dwarf2_per_objfile
7630 = (struct dwarf2_per_objfile
*) info
;
7631 struct signatured_type find_entry
, *entry
;
7633 /* If this TU doesn't exist in the global table, add it and read it in. */
7635 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7637 dwarf2_per_objfile
->signatured_types
7638 = allocate_signatured_type_table (dwarf2_per_objfile
->objfile
);
7641 find_entry
.signature
= dwo_unit
->signature
;
7642 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
7643 &find_entry
, INSERT
);
7644 /* If we've already seen this type there's nothing to do. What's happening
7645 is we're doing our own version of comdat-folding here. */
7649 /* This does the job that create_all_type_units would have done for
7651 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
7652 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
7655 /* This does the job that build_type_psymtabs_1 would have done. */
7656 cutu_reader
reader (&entry
->per_cu
, NULL
, 0, 0, false);
7657 if (!reader
.dummy_p
)
7658 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7659 reader
.comp_unit_die
);
7664 /* Traversal function for process_skeletonless_type_units. */
7667 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7669 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7671 if (dwo_file
->tus
!= NULL
)
7672 htab_traverse_noresize (dwo_file
->tus
.get (),
7673 process_skeletonless_type_unit
, info
);
7678 /* Scan all TUs of DWO files, verifying we've processed them.
7679 This is needed in case a TU was emitted without its skeleton.
7680 Note: This can't be done until we know what all the DWO files are. */
7683 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7685 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
7686 if (get_dwp_file (dwarf2_per_objfile
) == NULL
7687 && dwarf2_per_objfile
->dwo_files
!= NULL
)
7689 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
.get (),
7690 process_dwo_file_for_skeletonless_type_units
,
7691 dwarf2_per_objfile
);
7695 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
7698 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7700 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
7702 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7707 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
7709 /* Set the 'user' field only if it is not already set. */
7710 if (pst
->dependencies
[j
]->user
== NULL
)
7711 pst
->dependencies
[j
]->user
= pst
;
7716 /* Build the partial symbol table by doing a quick pass through the
7717 .debug_info and .debug_abbrev sections. */
7720 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7722 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7724 if (dwarf_read_debug
)
7726 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
7727 objfile_name (objfile
));
7730 dwarf2_per_objfile
->reading_partial_symbols
= 1;
7732 dwarf2_per_objfile
->info
.read (objfile
);
7734 /* Any cached compilation units will be linked by the per-objfile
7735 read_in_chain. Make sure to free them when we're done. */
7736 free_cached_comp_units
freer (dwarf2_per_objfile
);
7738 build_type_psymtabs (dwarf2_per_objfile
);
7740 create_all_comp_units (dwarf2_per_objfile
);
7742 /* Create a temporary address map on a temporary obstack. We later
7743 copy this to the final obstack. */
7744 auto_obstack temp_obstack
;
7746 scoped_restore save_psymtabs_addrmap
7747 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
7748 addrmap_create_mutable (&temp_obstack
));
7750 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
7751 process_psymtab_comp_unit (per_cu
, false, language_minimal
);
7753 /* This has to wait until we read the CUs, we need the list of DWOs. */
7754 process_skeletonless_type_units (dwarf2_per_objfile
);
7756 /* Now that all TUs have been processed we can fill in the dependencies. */
7757 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
7759 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
.get (),
7760 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
7763 if (dwarf_read_debug
)
7764 print_tu_stats (dwarf2_per_objfile
);
7766 set_partial_user (dwarf2_per_objfile
);
7768 objfile
->partial_symtabs
->psymtabs_addrmap
7769 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
7770 objfile
->partial_symtabs
->obstack ());
7771 /* At this point we want to keep the address map. */
7772 save_psymtabs_addrmap
.release ();
7774 if (dwarf_read_debug
)
7775 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
7776 objfile_name (objfile
));
7779 /* Load the partial DIEs for a secondary CU into memory.
7780 This is also used when rereading a primary CU with load_all_dies. */
7783 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
7785 cutu_reader
reader (this_cu
, NULL
, 1, 1, false);
7787 if (!reader
.dummy_p
)
7789 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
7792 /* Check if comp unit has_children.
7793 If so, read the rest of the partial symbols from this comp unit.
7794 If not, there's no more debug_info for this comp unit. */
7795 if (reader
.comp_unit_die
->has_children
)
7796 load_partial_dies (&reader
, reader
.info_ptr
, 0);
7801 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
7802 struct dwarf2_section_info
*section
,
7803 struct dwarf2_section_info
*abbrev_section
,
7804 unsigned int is_dwz
)
7806 const gdb_byte
*info_ptr
;
7807 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7809 if (dwarf_read_debug
)
7810 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
7811 section
->get_name (),
7812 section
->get_file_name ());
7814 section
->read (objfile
);
7816 info_ptr
= section
->buffer
;
7818 while (info_ptr
< section
->buffer
+ section
->size
)
7820 struct dwarf2_per_cu_data
*this_cu
;
7822 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
7824 comp_unit_head cu_header
;
7825 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
7826 abbrev_section
, info_ptr
,
7827 rcuh_kind::COMPILE
);
7829 /* Save the compilation unit for later lookup. */
7830 if (cu_header
.unit_type
!= DW_UT_type
)
7832 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
7833 struct dwarf2_per_cu_data
);
7834 memset (this_cu
, 0, sizeof (*this_cu
));
7838 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
7839 struct signatured_type
);
7840 memset (sig_type
, 0, sizeof (*sig_type
));
7841 sig_type
->signature
= cu_header
.signature
;
7842 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
7843 this_cu
= &sig_type
->per_cu
;
7845 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
7846 this_cu
->sect_off
= sect_off
;
7847 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
7848 this_cu
->is_dwz
= is_dwz
;
7849 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7850 this_cu
->section
= section
;
7852 dwarf2_per_objfile
->all_comp_units
.push_back (this_cu
);
7854 info_ptr
= info_ptr
+ this_cu
->length
;
7858 /* Create a list of all compilation units in OBJFILE.
7859 This is only done for -readnow and building partial symtabs. */
7862 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7864 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
7865 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->info
,
7866 &dwarf2_per_objfile
->abbrev
, 0);
7868 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
7870 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
7874 /* Process all loaded DIEs for compilation unit CU, starting at
7875 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
7876 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
7877 DW_AT_ranges). See the comments of add_partial_subprogram on how
7878 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
7881 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
7882 CORE_ADDR
*highpc
, int set_addrmap
,
7883 struct dwarf2_cu
*cu
)
7885 struct partial_die_info
*pdi
;
7887 /* Now, march along the PDI's, descending into ones which have
7888 interesting children but skipping the children of the other ones,
7889 until we reach the end of the compilation unit. */
7897 /* Anonymous namespaces or modules have no name but have interesting
7898 children, so we need to look at them. Ditto for anonymous
7901 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
7902 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
7903 || pdi
->tag
== DW_TAG_imported_unit
7904 || pdi
->tag
== DW_TAG_inlined_subroutine
)
7908 case DW_TAG_subprogram
:
7909 case DW_TAG_inlined_subroutine
:
7910 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7912 case DW_TAG_constant
:
7913 case DW_TAG_variable
:
7914 case DW_TAG_typedef
:
7915 case DW_TAG_union_type
:
7916 if (!pdi
->is_declaration
)
7918 add_partial_symbol (pdi
, cu
);
7921 case DW_TAG_class_type
:
7922 case DW_TAG_interface_type
:
7923 case DW_TAG_structure_type
:
7924 if (!pdi
->is_declaration
)
7926 add_partial_symbol (pdi
, cu
);
7928 if ((cu
->language
== language_rust
7929 || cu
->language
== language_cplus
) && pdi
->has_children
)
7930 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
7933 case DW_TAG_enumeration_type
:
7934 if (!pdi
->is_declaration
)
7935 add_partial_enumeration (pdi
, cu
);
7937 case DW_TAG_base_type
:
7938 case DW_TAG_subrange_type
:
7939 /* File scope base type definitions are added to the partial
7941 add_partial_symbol (pdi
, cu
);
7943 case DW_TAG_namespace
:
7944 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7947 if (!pdi
->is_declaration
)
7948 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7950 case DW_TAG_imported_unit
:
7952 struct dwarf2_per_cu_data
*per_cu
;
7954 /* For now we don't handle imported units in type units. */
7955 if (cu
->per_cu
->is_debug_types
)
7957 error (_("Dwarf Error: DW_TAG_imported_unit is not"
7958 " supported in type units [in module %s]"),
7959 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
7962 per_cu
= dwarf2_find_containing_comp_unit
7963 (pdi
->d
.sect_off
, pdi
->is_dwz
,
7964 cu
->per_cu
->dwarf2_per_objfile
);
7966 /* Go read the partial unit, if needed. */
7967 if (per_cu
->v
.psymtab
== NULL
)
7968 process_psymtab_comp_unit (per_cu
, true, cu
->language
);
7970 cu
->per_cu
->imported_symtabs_push (per_cu
);
7973 case DW_TAG_imported_declaration
:
7974 add_partial_symbol (pdi
, cu
);
7981 /* If the die has a sibling, skip to the sibling. */
7983 pdi
= pdi
->die_sibling
;
7987 /* Functions used to compute the fully scoped name of a partial DIE.
7989 Normally, this is simple. For C++, the parent DIE's fully scoped
7990 name is concatenated with "::" and the partial DIE's name.
7991 Enumerators are an exception; they use the scope of their parent
7992 enumeration type, i.e. the name of the enumeration type is not
7993 prepended to the enumerator.
7995 There are two complexities. One is DW_AT_specification; in this
7996 case "parent" means the parent of the target of the specification,
7997 instead of the direct parent of the DIE. The other is compilers
7998 which do not emit DW_TAG_namespace; in this case we try to guess
7999 the fully qualified name of structure types from their members'
8000 linkage names. This must be done using the DIE's children rather
8001 than the children of any DW_AT_specification target. We only need
8002 to do this for structures at the top level, i.e. if the target of
8003 any DW_AT_specification (if any; otherwise the DIE itself) does not
8006 /* Compute the scope prefix associated with PDI's parent, in
8007 compilation unit CU. The result will be allocated on CU's
8008 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8009 field. NULL is returned if no prefix is necessary. */
8011 partial_die_parent_scope (struct partial_die_info
*pdi
,
8012 struct dwarf2_cu
*cu
)
8014 const char *grandparent_scope
;
8015 struct partial_die_info
*parent
, *real_pdi
;
8017 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8018 then this means the parent of the specification DIE. */
8021 while (real_pdi
->has_specification
)
8023 auto res
= find_partial_die (real_pdi
->spec_offset
,
8024 real_pdi
->spec_is_dwz
, cu
);
8029 parent
= real_pdi
->die_parent
;
8033 if (parent
->scope_set
)
8034 return parent
->scope
;
8038 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8040 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8041 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8042 Work around this problem here. */
8043 if (cu
->language
== language_cplus
8044 && parent
->tag
== DW_TAG_namespace
8045 && strcmp (parent
->name
, "::") == 0
8046 && grandparent_scope
== NULL
)
8048 parent
->scope
= NULL
;
8049 parent
->scope_set
= 1;
8053 /* Nested subroutines in Fortran get a prefix. */
8054 if (pdi
->tag
== DW_TAG_enumerator
)
8055 /* Enumerators should not get the name of the enumeration as a prefix. */
8056 parent
->scope
= grandparent_scope
;
8057 else if (parent
->tag
== DW_TAG_namespace
8058 || parent
->tag
== DW_TAG_module
8059 || parent
->tag
== DW_TAG_structure_type
8060 || parent
->tag
== DW_TAG_class_type
8061 || parent
->tag
== DW_TAG_interface_type
8062 || parent
->tag
== DW_TAG_union_type
8063 || parent
->tag
== DW_TAG_enumeration_type
8064 || (cu
->language
== language_fortran
8065 && parent
->tag
== DW_TAG_subprogram
8066 && pdi
->tag
== DW_TAG_subprogram
))
8068 if (grandparent_scope
== NULL
)
8069 parent
->scope
= parent
->name
;
8071 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8073 parent
->name
, 0, cu
);
8077 /* FIXME drow/2004-04-01: What should we be doing with
8078 function-local names? For partial symbols, we should probably be
8080 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8081 dwarf_tag_name (parent
->tag
),
8082 sect_offset_str (pdi
->sect_off
));
8083 parent
->scope
= grandparent_scope
;
8086 parent
->scope_set
= 1;
8087 return parent
->scope
;
8090 /* Return the fully scoped name associated with PDI, from compilation unit
8091 CU. The result will be allocated with malloc. */
8093 static gdb::unique_xmalloc_ptr
<char>
8094 partial_die_full_name (struct partial_die_info
*pdi
,
8095 struct dwarf2_cu
*cu
)
8097 const char *parent_scope
;
8099 /* If this is a template instantiation, we can not work out the
8100 template arguments from partial DIEs. So, unfortunately, we have
8101 to go through the full DIEs. At least any work we do building
8102 types here will be reused if full symbols are loaded later. */
8103 if (pdi
->has_template_arguments
)
8107 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
8109 struct die_info
*die
;
8110 struct attribute attr
;
8111 struct dwarf2_cu
*ref_cu
= cu
;
8113 /* DW_FORM_ref_addr is using section offset. */
8114 attr
.name
= (enum dwarf_attribute
) 0;
8115 attr
.form
= DW_FORM_ref_addr
;
8116 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8117 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8119 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8123 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8124 if (parent_scope
== NULL
)
8127 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8132 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8134 struct dwarf2_per_objfile
*dwarf2_per_objfile
8135 = cu
->per_cu
->dwarf2_per_objfile
;
8136 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8137 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8139 const char *actual_name
= NULL
;
8142 baseaddr
= objfile
->text_section_offset ();
8144 gdb::unique_xmalloc_ptr
<char> built_actual_name
8145 = partial_die_full_name (pdi
, cu
);
8146 if (built_actual_name
!= NULL
)
8147 actual_name
= built_actual_name
.get ();
8149 if (actual_name
== NULL
)
8150 actual_name
= pdi
->name
;
8154 case DW_TAG_inlined_subroutine
:
8155 case DW_TAG_subprogram
:
8156 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8158 if (pdi
->is_external
8159 || cu
->language
== language_ada
8160 || (cu
->language
== language_fortran
8161 && pdi
->die_parent
!= NULL
8162 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8164 /* Normally, only "external" DIEs are part of the global scope.
8165 But in Ada and Fortran, we want to be able to access nested
8166 procedures globally. So all Ada and Fortran subprograms are
8167 stored in the global scope. */
8168 add_psymbol_to_list (actual_name
,
8169 built_actual_name
!= NULL
,
8170 VAR_DOMAIN
, LOC_BLOCK
,
8171 SECT_OFF_TEXT (objfile
),
8172 psymbol_placement::GLOBAL
,
8174 cu
->language
, objfile
);
8178 add_psymbol_to_list (actual_name
,
8179 built_actual_name
!= NULL
,
8180 VAR_DOMAIN
, LOC_BLOCK
,
8181 SECT_OFF_TEXT (objfile
),
8182 psymbol_placement::STATIC
,
8183 addr
, cu
->language
, objfile
);
8186 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8187 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8189 case DW_TAG_constant
:
8190 add_psymbol_to_list (actual_name
,
8191 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
8192 -1, (pdi
->is_external
8193 ? psymbol_placement::GLOBAL
8194 : psymbol_placement::STATIC
),
8195 0, cu
->language
, objfile
);
8197 case DW_TAG_variable
:
8199 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8203 && !dwarf2_per_objfile
->has_section_at_zero
)
8205 /* A global or static variable may also have been stripped
8206 out by the linker if unused, in which case its address
8207 will be nullified; do not add such variables into partial
8208 symbol table then. */
8210 else if (pdi
->is_external
)
8213 Don't enter into the minimal symbol tables as there is
8214 a minimal symbol table entry from the ELF symbols already.
8215 Enter into partial symbol table if it has a location
8216 descriptor or a type.
8217 If the location descriptor is missing, new_symbol will create
8218 a LOC_UNRESOLVED symbol, the address of the variable will then
8219 be determined from the minimal symbol table whenever the variable
8221 The address for the partial symbol table entry is not
8222 used by GDB, but it comes in handy for debugging partial symbol
8225 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8226 add_psymbol_to_list (actual_name
,
8227 built_actual_name
!= NULL
,
8228 VAR_DOMAIN
, LOC_STATIC
,
8229 SECT_OFF_TEXT (objfile
),
8230 psymbol_placement::GLOBAL
,
8231 addr
, cu
->language
, objfile
);
8235 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8237 /* Static Variable. Skip symbols whose value we cannot know (those
8238 without location descriptors or constant values). */
8239 if (!has_loc
&& !pdi
->has_const_value
)
8242 add_psymbol_to_list (actual_name
,
8243 built_actual_name
!= NULL
,
8244 VAR_DOMAIN
, LOC_STATIC
,
8245 SECT_OFF_TEXT (objfile
),
8246 psymbol_placement::STATIC
,
8248 cu
->language
, objfile
);
8251 case DW_TAG_typedef
:
8252 case DW_TAG_base_type
:
8253 case DW_TAG_subrange_type
:
8254 add_psymbol_to_list (actual_name
,
8255 built_actual_name
!= NULL
,
8256 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
8257 psymbol_placement::STATIC
,
8258 0, cu
->language
, objfile
);
8260 case DW_TAG_imported_declaration
:
8261 case DW_TAG_namespace
:
8262 add_psymbol_to_list (actual_name
,
8263 built_actual_name
!= NULL
,
8264 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
8265 psymbol_placement::GLOBAL
,
8266 0, cu
->language
, objfile
);
8269 /* With Fortran 77 there might be a "BLOCK DATA" module
8270 available without any name. If so, we skip the module as it
8271 doesn't bring any value. */
8272 if (actual_name
!= nullptr)
8273 add_psymbol_to_list (actual_name
,
8274 built_actual_name
!= NULL
,
8275 MODULE_DOMAIN
, LOC_TYPEDEF
, -1,
8276 psymbol_placement::GLOBAL
,
8277 0, cu
->language
, objfile
);
8279 case DW_TAG_class_type
:
8280 case DW_TAG_interface_type
:
8281 case DW_TAG_structure_type
:
8282 case DW_TAG_union_type
:
8283 case DW_TAG_enumeration_type
:
8284 /* Skip external references. The DWARF standard says in the section
8285 about "Structure, Union, and Class Type Entries": "An incomplete
8286 structure, union or class type is represented by a structure,
8287 union or class entry that does not have a byte size attribute
8288 and that has a DW_AT_declaration attribute." */
8289 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8292 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8293 static vs. global. */
8294 add_psymbol_to_list (actual_name
,
8295 built_actual_name
!= NULL
,
8296 STRUCT_DOMAIN
, LOC_TYPEDEF
, -1,
8297 cu
->language
== language_cplus
8298 ? psymbol_placement::GLOBAL
8299 : psymbol_placement::STATIC
,
8300 0, cu
->language
, objfile
);
8303 case DW_TAG_enumerator
:
8304 add_psymbol_to_list (actual_name
,
8305 built_actual_name
!= NULL
,
8306 VAR_DOMAIN
, LOC_CONST
, -1,
8307 cu
->language
== language_cplus
8308 ? psymbol_placement::GLOBAL
8309 : psymbol_placement::STATIC
,
8310 0, cu
->language
, objfile
);
8317 /* Read a partial die corresponding to a namespace; also, add a symbol
8318 corresponding to that namespace to the symbol table. NAMESPACE is
8319 the name of the enclosing namespace. */
8322 add_partial_namespace (struct partial_die_info
*pdi
,
8323 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8324 int set_addrmap
, struct dwarf2_cu
*cu
)
8326 /* Add a symbol for the namespace. */
8328 add_partial_symbol (pdi
, cu
);
8330 /* Now scan partial symbols in that namespace. */
8332 if (pdi
->has_children
)
8333 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8336 /* Read a partial die corresponding to a Fortran module. */
8339 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8340 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8342 /* Add a symbol for the namespace. */
8344 add_partial_symbol (pdi
, cu
);
8346 /* Now scan partial symbols in that module. */
8348 if (pdi
->has_children
)
8349 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8352 /* Read a partial die corresponding to a subprogram or an inlined
8353 subprogram and create a partial symbol for that subprogram.
8354 When the CU language allows it, this routine also defines a partial
8355 symbol for each nested subprogram that this subprogram contains.
8356 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8357 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8359 PDI may also be a lexical block, in which case we simply search
8360 recursively for subprograms defined inside that lexical block.
8361 Again, this is only performed when the CU language allows this
8362 type of definitions. */
8365 add_partial_subprogram (struct partial_die_info
*pdi
,
8366 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8367 int set_addrmap
, struct dwarf2_cu
*cu
)
8369 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8371 if (pdi
->has_pc_info
)
8373 if (pdi
->lowpc
< *lowpc
)
8374 *lowpc
= pdi
->lowpc
;
8375 if (pdi
->highpc
> *highpc
)
8376 *highpc
= pdi
->highpc
;
8379 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
8380 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8382 CORE_ADDR this_highpc
;
8383 CORE_ADDR this_lowpc
;
8385 baseaddr
= objfile
->text_section_offset ();
8387 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8388 pdi
->lowpc
+ baseaddr
)
8391 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8392 pdi
->highpc
+ baseaddr
)
8394 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8395 this_lowpc
, this_highpc
- 1,
8396 cu
->per_cu
->v
.psymtab
);
8400 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8402 if (!pdi
->is_declaration
)
8403 /* Ignore subprogram DIEs that do not have a name, they are
8404 illegal. Do not emit a complaint at this point, we will
8405 do so when we convert this psymtab into a symtab. */
8407 add_partial_symbol (pdi
, cu
);
8411 if (! pdi
->has_children
)
8414 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
8416 pdi
= pdi
->die_child
;
8420 if (pdi
->tag
== DW_TAG_subprogram
8421 || pdi
->tag
== DW_TAG_inlined_subroutine
8422 || pdi
->tag
== DW_TAG_lexical_block
)
8423 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8424 pdi
= pdi
->die_sibling
;
8429 /* Read a partial die corresponding to an enumeration type. */
8432 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8433 struct dwarf2_cu
*cu
)
8435 struct partial_die_info
*pdi
;
8437 if (enum_pdi
->name
!= NULL
)
8438 add_partial_symbol (enum_pdi
, cu
);
8440 pdi
= enum_pdi
->die_child
;
8443 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
8444 complaint (_("malformed enumerator DIE ignored"));
8446 add_partial_symbol (pdi
, cu
);
8447 pdi
= pdi
->die_sibling
;
8451 /* Return the initial uleb128 in the die at INFO_PTR. */
8454 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8456 unsigned int bytes_read
;
8458 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8461 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8462 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8464 Return the corresponding abbrev, or NULL if the number is zero (indicating
8465 an empty DIE). In either case *BYTES_READ will be set to the length of
8466 the initial number. */
8468 static struct abbrev_info
*
8469 peek_die_abbrev (const die_reader_specs
&reader
,
8470 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8472 dwarf2_cu
*cu
= reader
.cu
;
8473 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
8474 unsigned int abbrev_number
8475 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8477 if (abbrev_number
== 0)
8480 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8483 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8484 " at offset %s [in module %s]"),
8485 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8486 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8492 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8493 Returns a pointer to the end of a series of DIEs, terminated by an empty
8494 DIE. Any children of the skipped DIEs will also be skipped. */
8496 static const gdb_byte
*
8497 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8501 unsigned int bytes_read
;
8502 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
8505 return info_ptr
+ bytes_read
;
8507 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8511 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8512 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8513 abbrev corresponding to that skipped uleb128 should be passed in
8514 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8517 static const gdb_byte
*
8518 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8519 struct abbrev_info
*abbrev
)
8521 unsigned int bytes_read
;
8522 struct attribute attr
;
8523 bfd
*abfd
= reader
->abfd
;
8524 struct dwarf2_cu
*cu
= reader
->cu
;
8525 const gdb_byte
*buffer
= reader
->buffer
;
8526 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8527 unsigned int form
, i
;
8529 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8531 /* The only abbrev we care about is DW_AT_sibling. */
8532 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8535 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
,
8537 if (attr
.form
== DW_FORM_ref_addr
)
8538 complaint (_("ignoring absolute DW_AT_sibling"));
8541 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
8542 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8544 if (sibling_ptr
< info_ptr
)
8545 complaint (_("DW_AT_sibling points backwards"));
8546 else if (sibling_ptr
> reader
->buffer_end
)
8547 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
8553 /* If it isn't DW_AT_sibling, skip this attribute. */
8554 form
= abbrev
->attrs
[i
].form
;
8558 case DW_FORM_ref_addr
:
8559 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8560 and later it is offset sized. */
8561 if (cu
->header
.version
== 2)
8562 info_ptr
+= cu
->header
.addr_size
;
8564 info_ptr
+= cu
->header
.offset_size
;
8566 case DW_FORM_GNU_ref_alt
:
8567 info_ptr
+= cu
->header
.offset_size
;
8570 info_ptr
+= cu
->header
.addr_size
;
8578 case DW_FORM_flag_present
:
8579 case DW_FORM_implicit_const
:
8596 case DW_FORM_ref_sig8
:
8599 case DW_FORM_data16
:
8602 case DW_FORM_string
:
8603 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8604 info_ptr
+= bytes_read
;
8606 case DW_FORM_sec_offset
:
8608 case DW_FORM_GNU_strp_alt
:
8609 info_ptr
+= cu
->header
.offset_size
;
8611 case DW_FORM_exprloc
:
8613 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8614 info_ptr
+= bytes_read
;
8616 case DW_FORM_block1
:
8617 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8619 case DW_FORM_block2
:
8620 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8622 case DW_FORM_block4
:
8623 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8629 case DW_FORM_ref_udata
:
8630 case DW_FORM_GNU_addr_index
:
8631 case DW_FORM_GNU_str_index
:
8632 case DW_FORM_rnglistx
:
8633 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8635 case DW_FORM_indirect
:
8636 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8637 info_ptr
+= bytes_read
;
8638 /* We need to continue parsing from here, so just go back to
8640 goto skip_attribute
;
8643 error (_("Dwarf Error: Cannot handle %s "
8644 "in DWARF reader [in module %s]"),
8645 dwarf_form_name (form
),
8646 bfd_get_filename (abfd
));
8650 if (abbrev
->has_children
)
8651 return skip_children (reader
, info_ptr
);
8656 /* Locate ORIG_PDI's sibling.
8657 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8659 static const gdb_byte
*
8660 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8661 struct partial_die_info
*orig_pdi
,
8662 const gdb_byte
*info_ptr
)
8664 /* Do we know the sibling already? */
8666 if (orig_pdi
->sibling
)
8667 return orig_pdi
->sibling
;
8669 /* Are there any children to deal with? */
8671 if (!orig_pdi
->has_children
)
8674 /* Skip the children the long way. */
8676 return skip_children (reader
, info_ptr
);
8679 /* Expand this partial symbol table into a full symbol table. SELF is
8683 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
8685 struct dwarf2_per_objfile
*dwarf2_per_objfile
8686 = get_dwarf2_per_objfile (objfile
);
8688 gdb_assert (!readin
);
8689 /* If this psymtab is constructed from a debug-only objfile, the
8690 has_section_at_zero flag will not necessarily be correct. We
8691 can get the correct value for this flag by looking at the data
8692 associated with the (presumably stripped) associated objfile. */
8693 if (objfile
->separate_debug_objfile_backlink
)
8695 struct dwarf2_per_objfile
*dpo_backlink
8696 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
8698 dwarf2_per_objfile
->has_section_at_zero
8699 = dpo_backlink
->has_section_at_zero
;
8702 dwarf2_per_objfile
->reading_partial_symbols
= 0;
8704 expand_psymtab (objfile
);
8706 process_cu_includes (dwarf2_per_objfile
);
8709 /* Reading in full CUs. */
8711 /* Add PER_CU to the queue. */
8714 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
8715 enum language pretend_language
)
8718 per_cu
->dwarf2_per_objfile
->queue
.emplace (per_cu
, pretend_language
);
8721 /* If PER_CU is not yet queued, add it to the queue.
8722 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
8724 The result is non-zero if PER_CU was queued, otherwise the result is zero
8725 meaning either PER_CU is already queued or it is already loaded.
8727 N.B. There is an invariant here that if a CU is queued then it is loaded.
8728 The caller is required to load PER_CU if we return non-zero. */
8731 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
8732 struct dwarf2_per_cu_data
*per_cu
,
8733 enum language pretend_language
)
8735 /* We may arrive here during partial symbol reading, if we need full
8736 DIEs to process an unusual case (e.g. template arguments). Do
8737 not queue PER_CU, just tell our caller to load its DIEs. */
8738 if (per_cu
->dwarf2_per_objfile
->reading_partial_symbols
)
8740 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
8745 /* Mark the dependence relation so that we don't flush PER_CU
8747 if (dependent_cu
!= NULL
)
8748 dwarf2_add_dependence (dependent_cu
, per_cu
);
8750 /* If it's already on the queue, we have nothing to do. */
8754 /* If the compilation unit is already loaded, just mark it as
8756 if (per_cu
->cu
!= NULL
)
8758 per_cu
->cu
->last_used
= 0;
8762 /* Add it to the queue. */
8763 queue_comp_unit (per_cu
, pretend_language
);
8768 /* Process the queue. */
8771 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8773 if (dwarf_read_debug
)
8775 fprintf_unfiltered (gdb_stdlog
,
8776 "Expanding one or more symtabs of objfile %s ...\n",
8777 objfile_name (dwarf2_per_objfile
->objfile
));
8780 /* The queue starts out with one item, but following a DIE reference
8781 may load a new CU, adding it to the end of the queue. */
8782 while (!dwarf2_per_objfile
->queue
.empty ())
8784 dwarf2_queue_item
&item
= dwarf2_per_objfile
->queue
.front ();
8786 if ((dwarf2_per_objfile
->using_index
8787 ? !item
.per_cu
->v
.quick
->compunit_symtab
8788 : (item
.per_cu
->v
.psymtab
&& !item
.per_cu
->v
.psymtab
->readin
))
8789 /* Skip dummy CUs. */
8790 && item
.per_cu
->cu
!= NULL
)
8792 struct dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
8793 unsigned int debug_print_threshold
;
8796 if (per_cu
->is_debug_types
)
8798 struct signatured_type
*sig_type
=
8799 (struct signatured_type
*) per_cu
;
8801 sprintf (buf
, "TU %s at offset %s",
8802 hex_string (sig_type
->signature
),
8803 sect_offset_str (per_cu
->sect_off
));
8804 /* There can be 100s of TUs.
8805 Only print them in verbose mode. */
8806 debug_print_threshold
= 2;
8810 sprintf (buf
, "CU at offset %s",
8811 sect_offset_str (per_cu
->sect_off
));
8812 debug_print_threshold
= 1;
8815 if (dwarf_read_debug
>= debug_print_threshold
)
8816 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
8818 if (per_cu
->is_debug_types
)
8819 process_full_type_unit (per_cu
, item
.pretend_language
);
8821 process_full_comp_unit (per_cu
, item
.pretend_language
);
8823 if (dwarf_read_debug
>= debug_print_threshold
)
8824 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
8827 item
.per_cu
->queued
= 0;
8828 dwarf2_per_objfile
->queue
.pop ();
8831 if (dwarf_read_debug
)
8833 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
8834 objfile_name (dwarf2_per_objfile
->objfile
));
8838 /* Read in full symbols for PST, and anything it depends on. */
8841 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
8843 struct dwarf2_per_cu_data
*per_cu
;
8848 read_dependencies (objfile
);
8850 per_cu
= per_cu_data
;
8854 /* It's an include file, no symbols to read for it.
8855 Everything is in the parent symtab. */
8860 dw2_do_instantiate_symtab (per_cu
, false);
8863 /* Trivial hash function for die_info: the hash value of a DIE
8864 is its offset in .debug_info for this objfile. */
8867 die_hash (const void *item
)
8869 const struct die_info
*die
= (const struct die_info
*) item
;
8871 return to_underlying (die
->sect_off
);
8874 /* Trivial comparison function for die_info structures: two DIEs
8875 are equal if they have the same offset. */
8878 die_eq (const void *item_lhs
, const void *item_rhs
)
8880 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
8881 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
8883 return die_lhs
->sect_off
== die_rhs
->sect_off
;
8886 /* Load the DIEs associated with PER_CU into memory. */
8889 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8891 enum language pretend_language
)
8893 gdb_assert (! this_cu
->is_debug_types
);
8895 cutu_reader
reader (this_cu
, NULL
, 1, 1, skip_partial
);
8899 struct dwarf2_cu
*cu
= reader
.cu
;
8900 const gdb_byte
*info_ptr
= reader
.info_ptr
;
8902 gdb_assert (cu
->die_hash
== NULL
);
8904 htab_create_alloc_ex (cu
->header
.length
/ 12,
8908 &cu
->comp_unit_obstack
,
8909 hashtab_obstack_allocate
,
8910 dummy_obstack_deallocate
);
8912 if (reader
.comp_unit_die
->has_children
)
8913 reader
.comp_unit_die
->child
8914 = read_die_and_siblings (&reader
, reader
.info_ptr
,
8915 &info_ptr
, reader
.comp_unit_die
);
8916 cu
->dies
= reader
.comp_unit_die
;
8917 /* comp_unit_die is not stored in die_hash, no need. */
8919 /* We try not to read any attributes in this function, because not
8920 all CUs needed for references have been loaded yet, and symbol
8921 table processing isn't initialized. But we have to set the CU language,
8922 or we won't be able to build types correctly.
8923 Similarly, if we do not read the producer, we can not apply
8924 producer-specific interpretation. */
8925 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
8928 /* Add a DIE to the delayed physname list. */
8931 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
8932 const char *name
, struct die_info
*die
,
8933 struct dwarf2_cu
*cu
)
8935 struct delayed_method_info mi
;
8937 mi
.fnfield_index
= fnfield_index
;
8941 cu
->method_list
.push_back (mi
);
8944 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
8945 "const" / "volatile". If so, decrements LEN by the length of the
8946 modifier and return true. Otherwise return false. */
8950 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
8952 size_t mod_len
= sizeof (mod
) - 1;
8953 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
8961 /* Compute the physnames of any methods on the CU's method list.
8963 The computation of method physnames is delayed in order to avoid the
8964 (bad) condition that one of the method's formal parameters is of an as yet
8968 compute_delayed_physnames (struct dwarf2_cu
*cu
)
8970 /* Only C++ delays computing physnames. */
8971 if (cu
->method_list
.empty ())
8973 gdb_assert (cu
->language
== language_cplus
);
8975 for (const delayed_method_info
&mi
: cu
->method_list
)
8977 const char *physname
;
8978 struct fn_fieldlist
*fn_flp
8979 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
8980 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
8981 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
8982 = physname
? physname
: "";
8984 /* Since there's no tag to indicate whether a method is a
8985 const/volatile overload, extract that information out of the
8987 if (physname
!= NULL
)
8989 size_t len
= strlen (physname
);
8993 if (physname
[len
] == ')') /* shortcut */
8995 else if (check_modifier (physname
, len
, " const"))
8996 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
8997 else if (check_modifier (physname
, len
, " volatile"))
8998 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9005 /* The list is no longer needed. */
9006 cu
->method_list
.clear ();
9009 /* Go objects should be embedded in a DW_TAG_module DIE,
9010 and it's not clear if/how imported objects will appear.
9011 To keep Go support simple until that's worked out,
9012 go back through what we've read and create something usable.
9013 We could do this while processing each DIE, and feels kinda cleaner,
9014 but that way is more invasive.
9015 This is to, for example, allow the user to type "p var" or "b main"
9016 without having to specify the package name, and allow lookups
9017 of module.object to work in contexts that use the expression
9021 fixup_go_packaging (struct dwarf2_cu
*cu
)
9023 gdb::unique_xmalloc_ptr
<char> package_name
;
9024 struct pending
*list
;
9027 for (list
= *cu
->get_builder ()->get_global_symbols ();
9031 for (i
= 0; i
< list
->nsyms
; ++i
)
9033 struct symbol
*sym
= list
->symbol
[i
];
9035 if (sym
->language () == language_go
9036 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9038 gdb::unique_xmalloc_ptr
<char> this_package_name
9039 (go_symbol_package_name (sym
));
9041 if (this_package_name
== NULL
)
9043 if (package_name
== NULL
)
9044 package_name
= std::move (this_package_name
);
9047 struct objfile
*objfile
9048 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9049 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9050 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9051 (symbol_symtab (sym
) != NULL
9052 ? symtab_to_filename_for_display
9053 (symbol_symtab (sym
))
9054 : objfile_name (objfile
)),
9055 this_package_name
.get (), package_name
.get ());
9061 if (package_name
!= NULL
)
9063 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9064 const char *saved_package_name
9065 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
, package_name
.get ());
9066 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9067 saved_package_name
);
9070 sym
= allocate_symbol (objfile
);
9071 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9072 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9073 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9074 e.g., "main" finds the "main" module and not C's main(). */
9075 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9076 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9077 SYMBOL_TYPE (sym
) = type
;
9079 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9083 /* Allocate a fully-qualified name consisting of the two parts on the
9087 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9089 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9092 /* A helper that allocates a struct discriminant_info to attach to a
9095 static struct discriminant_info
*
9096 alloc_discriminant_info (struct type
*type
, int discriminant_index
,
9099 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9100 gdb_assert (discriminant_index
== -1
9101 || (discriminant_index
>= 0
9102 && discriminant_index
< TYPE_NFIELDS (type
)));
9103 gdb_assert (default_index
== -1
9104 || (default_index
>= 0 && default_index
< TYPE_NFIELDS (type
)));
9106 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
9108 struct discriminant_info
*disc
9109 = ((struct discriminant_info
*)
9111 offsetof (struct discriminant_info
, discriminants
)
9112 + TYPE_NFIELDS (type
) * sizeof (disc
->discriminants
[0])));
9113 disc
->default_index
= default_index
;
9114 disc
->discriminant_index
= discriminant_index
;
9116 struct dynamic_prop prop
;
9117 prop
.kind
= PROP_UNDEFINED
;
9118 prop
.data
.baton
= disc
;
9120 add_dyn_prop (DYN_PROP_DISCRIMINATED
, prop
, type
);
9125 /* Some versions of rustc emitted enums in an unusual way.
9127 Ordinary enums were emitted as unions. The first element of each
9128 structure in the union was named "RUST$ENUM$DISR". This element
9129 held the discriminant.
9131 These versions of Rust also implemented the "non-zero"
9132 optimization. When the enum had two values, and one is empty and
9133 the other holds a pointer that cannot be zero, the pointer is used
9134 as the discriminant, with a zero value meaning the empty variant.
9135 Here, the union's first member is of the form
9136 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9137 where the fieldnos are the indices of the fields that should be
9138 traversed in order to find the field (which may be several fields deep)
9139 and the variantname is the name of the variant of the case when the
9142 This function recognizes whether TYPE is of one of these forms,
9143 and, if so, smashes it to be a variant type. */
9146 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9148 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9150 /* We don't need to deal with empty enums. */
9151 if (TYPE_NFIELDS (type
) == 0)
9154 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9155 if (TYPE_NFIELDS (type
) == 1
9156 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9158 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9160 /* Decode the field name to find the offset of the
9162 ULONGEST bit_offset
= 0;
9163 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9164 while (name
[0] >= '0' && name
[0] <= '9')
9167 unsigned long index
= strtoul (name
, &tail
, 10);
9170 || index
>= TYPE_NFIELDS (field_type
)
9171 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9172 != FIELD_LOC_KIND_BITPOS
))
9174 complaint (_("Could not parse Rust enum encoding string \"%s\""
9176 TYPE_FIELD_NAME (type
, 0),
9177 objfile_name (objfile
));
9182 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9183 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
9186 /* Make a union to hold the variants. */
9187 struct type
*union_type
= alloc_type (objfile
);
9188 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9189 TYPE_NFIELDS (union_type
) = 3;
9190 TYPE_FIELDS (union_type
)
9191 = (struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
));
9192 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9193 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9195 /* Put the discriminant must at index 0. */
9196 TYPE_FIELD_TYPE (union_type
, 0) = field_type
;
9197 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
9198 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
9199 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 0), bit_offset
);
9201 /* The order of fields doesn't really matter, so put the real
9202 field at index 1 and the data-less field at index 2. */
9203 struct discriminant_info
*disc
9204 = alloc_discriminant_info (union_type
, 0, 1);
9205 TYPE_FIELD (union_type
, 1) = TYPE_FIELD (type
, 0);
9206 TYPE_FIELD_NAME (union_type
, 1)
9207 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1)));
9208 TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1))
9209 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9210 TYPE_FIELD_NAME (union_type
, 1));
9212 const char *dataless_name
9213 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9215 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9217 TYPE_FIELD_TYPE (union_type
, 2) = dataless_type
;
9218 /* NAME points into the original discriminant name, which
9219 already has the correct lifetime. */
9220 TYPE_FIELD_NAME (union_type
, 2) = name
;
9221 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 2), 0);
9222 disc
->discriminants
[2] = 0;
9224 /* Smash this type to be a structure type. We have to do this
9225 because the type has already been recorded. */
9226 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9227 TYPE_NFIELDS (type
) = 1;
9229 = (struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
));
9231 /* Install the variant part. */
9232 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9233 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9234 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9236 /* A union with a single anonymous field is probably an old-style
9238 else if (TYPE_NFIELDS (type
) == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
9240 /* Smash this type to be a structure type. We have to do this
9241 because the type has already been recorded. */
9242 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9244 /* Make a union to hold the variants. */
9245 struct type
*union_type
= alloc_type (objfile
);
9246 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9247 TYPE_NFIELDS (union_type
) = TYPE_NFIELDS (type
);
9248 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9249 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9250 TYPE_FIELDS (union_type
) = TYPE_FIELDS (type
);
9252 struct type
*field_type
= TYPE_FIELD_TYPE (union_type
, 0);
9253 const char *variant_name
9254 = rust_last_path_segment (TYPE_NAME (field_type
));
9255 TYPE_FIELD_NAME (union_type
, 0) = variant_name
;
9256 TYPE_NAME (field_type
)
9257 = rust_fully_qualify (&objfile
->objfile_obstack
,
9258 TYPE_NAME (type
), variant_name
);
9260 /* Install the union in the outer struct type. */
9261 TYPE_NFIELDS (type
) = 1;
9263 = (struct field
*) TYPE_ZALLOC (union_type
, sizeof (struct field
));
9264 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9265 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9266 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9268 alloc_discriminant_info (union_type
, -1, 0);
9272 struct type
*disr_type
= nullptr;
9273 for (int i
= 0; i
< TYPE_NFIELDS (type
); ++i
)
9275 disr_type
= TYPE_FIELD_TYPE (type
, i
);
9277 if (TYPE_CODE (disr_type
) != TYPE_CODE_STRUCT
)
9279 /* All fields of a true enum will be structs. */
9282 else if (TYPE_NFIELDS (disr_type
) == 0)
9284 /* Could be data-less variant, so keep going. */
9285 disr_type
= nullptr;
9287 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9288 "RUST$ENUM$DISR") != 0)
9290 /* Not a Rust enum. */
9300 /* If we got here without a discriminant, then it's probably
9302 if (disr_type
== nullptr)
9305 /* Smash this type to be a structure type. We have to do this
9306 because the type has already been recorded. */
9307 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9309 /* Make a union to hold the variants. */
9310 struct field
*disr_field
= &TYPE_FIELD (disr_type
, 0);
9311 struct type
*union_type
= alloc_type (objfile
);
9312 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9313 TYPE_NFIELDS (union_type
) = 1 + TYPE_NFIELDS (type
);
9314 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9315 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9316 TYPE_FIELDS (union_type
)
9317 = (struct field
*) TYPE_ZALLOC (union_type
,
9318 (TYPE_NFIELDS (union_type
)
9319 * sizeof (struct field
)));
9321 memcpy (TYPE_FIELDS (union_type
) + 1, TYPE_FIELDS (type
),
9322 TYPE_NFIELDS (type
) * sizeof (struct field
));
9324 /* Install the discriminant at index 0 in the union. */
9325 TYPE_FIELD (union_type
, 0) = *disr_field
;
9326 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
9327 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
9329 /* Install the union in the outer struct type. */
9330 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9331 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9332 TYPE_NFIELDS (type
) = 1;
9334 /* Set the size and offset of the union type. */
9335 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9337 /* We need a way to find the correct discriminant given a
9338 variant name. For convenience we build a map here. */
9339 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
9340 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9341 for (int i
= 0; i
< TYPE_NFIELDS (enum_type
); ++i
)
9343 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9346 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9347 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9351 int n_fields
= TYPE_NFIELDS (union_type
);
9352 struct discriminant_info
*disc
9353 = alloc_discriminant_info (union_type
, 0, -1);
9354 /* Skip the discriminant here. */
9355 for (int i
= 1; i
< n_fields
; ++i
)
9357 /* Find the final word in the name of this variant's type.
9358 That name can be used to look up the correct
9360 const char *variant_name
9361 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
,
9364 auto iter
= discriminant_map
.find (variant_name
);
9365 if (iter
!= discriminant_map
.end ())
9366 disc
->discriminants
[i
] = iter
->second
;
9368 /* Remove the discriminant field, if it exists. */
9369 struct type
*sub_type
= TYPE_FIELD_TYPE (union_type
, i
);
9370 if (TYPE_NFIELDS (sub_type
) > 0)
9372 --TYPE_NFIELDS (sub_type
);
9373 ++TYPE_FIELDS (sub_type
);
9375 TYPE_FIELD_NAME (union_type
, i
) = variant_name
;
9376 TYPE_NAME (sub_type
)
9377 = rust_fully_qualify (&objfile
->objfile_obstack
,
9378 TYPE_NAME (type
), variant_name
);
9383 /* Rewrite some Rust unions to be structures with variants parts. */
9386 rust_union_quirks (struct dwarf2_cu
*cu
)
9388 gdb_assert (cu
->language
== language_rust
);
9389 for (type
*type_
: cu
->rust_unions
)
9390 quirk_rust_enum (type_
, cu
->per_cu
->dwarf2_per_objfile
->objfile
);
9391 /* We don't need this any more. */
9392 cu
->rust_unions
.clear ();
9395 /* Return the symtab for PER_CU. This works properly regardless of
9396 whether we're using the index or psymtabs. */
9398 static struct compunit_symtab
*
9399 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
9401 return (per_cu
->dwarf2_per_objfile
->using_index
9402 ? per_cu
->v
.quick
->compunit_symtab
9403 : per_cu
->v
.psymtab
->compunit_symtab
);
9406 /* A helper function for computing the list of all symbol tables
9407 included by PER_CU. */
9410 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9411 htab_t all_children
, htab_t all_type_symtabs
,
9412 struct dwarf2_per_cu_data
*per_cu
,
9413 struct compunit_symtab
*immediate_parent
)
9416 struct compunit_symtab
*cust
;
9418 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9421 /* This inclusion and its children have been processed. */
9426 /* Only add a CU if it has a symbol table. */
9427 cust
= get_compunit_symtab (per_cu
);
9430 /* If this is a type unit only add its symbol table if we haven't
9431 seen it yet (type unit per_cu's can share symtabs). */
9432 if (per_cu
->is_debug_types
)
9434 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9438 result
->push_back (cust
);
9439 if (cust
->user
== NULL
)
9440 cust
->user
= immediate_parent
;
9445 result
->push_back (cust
);
9446 if (cust
->user
== NULL
)
9447 cust
->user
= immediate_parent
;
9451 if (!per_cu
->imported_symtabs_empty ())
9452 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9454 recursively_compute_inclusions (result
, all_children
,
9455 all_type_symtabs
, ptr
, cust
);
9459 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9463 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
9465 gdb_assert (! per_cu
->is_debug_types
);
9467 if (!per_cu
->imported_symtabs_empty ())
9470 std::vector
<compunit_symtab
*> result_symtabs
;
9471 htab_t all_children
, all_type_symtabs
;
9472 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
9474 /* If we don't have a symtab, we can just skip this case. */
9478 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9479 NULL
, xcalloc
, xfree
);
9480 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9481 NULL
, xcalloc
, xfree
);
9483 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9485 recursively_compute_inclusions (&result_symtabs
, all_children
,
9486 all_type_symtabs
, ptr
, cust
);
9489 /* Now we have a transitive closure of all the included symtabs. */
9490 len
= result_symtabs
.size ();
9492 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
9493 struct compunit_symtab
*, len
+ 1);
9494 memcpy (cust
->includes
, result_symtabs
.data (),
9495 len
* sizeof (compunit_symtab
*));
9496 cust
->includes
[len
] = NULL
;
9498 htab_delete (all_children
);
9499 htab_delete (all_type_symtabs
);
9503 /* Compute the 'includes' field for the symtabs of all the CUs we just
9507 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9509 for (dwarf2_per_cu_data
*iter
: dwarf2_per_objfile
->just_read_cus
)
9511 if (! iter
->is_debug_types
)
9512 compute_compunit_symtab_includes (iter
);
9515 dwarf2_per_objfile
->just_read_cus
.clear ();
9518 /* Generate full symbol information for PER_CU, whose DIEs have
9519 already been loaded into memory. */
9522 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9523 enum language pretend_language
)
9525 struct dwarf2_cu
*cu
= per_cu
->cu
;
9526 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
9527 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9528 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9529 CORE_ADDR lowpc
, highpc
;
9530 struct compunit_symtab
*cust
;
9532 struct block
*static_block
;
9535 baseaddr
= objfile
->text_section_offset ();
9537 /* Clear the list here in case something was left over. */
9538 cu
->method_list
.clear ();
9540 cu
->language
= pretend_language
;
9541 cu
->language_defn
= language_def (cu
->language
);
9543 /* Do line number decoding in read_file_scope () */
9544 process_die (cu
->dies
, cu
);
9546 /* For now fudge the Go package. */
9547 if (cu
->language
== language_go
)
9548 fixup_go_packaging (cu
);
9550 /* Now that we have processed all the DIEs in the CU, all the types
9551 should be complete, and it should now be safe to compute all of the
9553 compute_delayed_physnames (cu
);
9555 if (cu
->language
== language_rust
)
9556 rust_union_quirks (cu
);
9558 /* Some compilers don't define a DW_AT_high_pc attribute for the
9559 compilation unit. If the DW_AT_high_pc is missing, synthesize
9560 it, by scanning the DIE's below the compilation unit. */
9561 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9563 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9564 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
9566 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9567 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9568 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9569 addrmap to help ensure it has an accurate map of pc values belonging to
9571 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9573 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
9574 SECT_OFF_TEXT (objfile
),
9579 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9581 /* Set symtab language to language from DW_AT_language. If the
9582 compilation is from a C file generated by language preprocessors, do
9583 not set the language if it was already deduced by start_subfile. */
9584 if (!(cu
->language
== language_c
9585 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
9586 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9588 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9589 produce DW_AT_location with location lists but it can be possibly
9590 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9591 there were bugs in prologue debug info, fixed later in GCC-4.5
9592 by "unwind info for epilogues" patch (which is not directly related).
9594 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9595 needed, it would be wrong due to missing DW_AT_producer there.
9597 Still one can confuse GDB by using non-standard GCC compilation
9598 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9600 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9601 cust
->locations_valid
= 1;
9603 if (gcc_4_minor
>= 5)
9604 cust
->epilogue_unwind_valid
= 1;
9606 cust
->call_site_htab
= cu
->call_site_htab
;
9609 if (dwarf2_per_objfile
->using_index
)
9610 per_cu
->v
.quick
->compunit_symtab
= cust
;
9613 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
9614 pst
->compunit_symtab
= cust
;
9618 /* Push it for inclusion processing later. */
9619 dwarf2_per_objfile
->just_read_cus
.push_back (per_cu
);
9621 /* Not needed any more. */
9622 cu
->reset_builder ();
9625 /* Generate full symbol information for type unit PER_CU, whose DIEs have
9626 already been loaded into memory. */
9629 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
9630 enum language pretend_language
)
9632 struct dwarf2_cu
*cu
= per_cu
->cu
;
9633 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
9634 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9635 struct compunit_symtab
*cust
;
9636 struct signatured_type
*sig_type
;
9638 gdb_assert (per_cu
->is_debug_types
);
9639 sig_type
= (struct signatured_type
*) per_cu
;
9641 /* Clear the list here in case something was left over. */
9642 cu
->method_list
.clear ();
9644 cu
->language
= pretend_language
;
9645 cu
->language_defn
= language_def (cu
->language
);
9647 /* The symbol tables are set up in read_type_unit_scope. */
9648 process_die (cu
->dies
, cu
);
9650 /* For now fudge the Go package. */
9651 if (cu
->language
== language_go
)
9652 fixup_go_packaging (cu
);
9654 /* Now that we have processed all the DIEs in the CU, all the types
9655 should be complete, and it should now be safe to compute all of the
9657 compute_delayed_physnames (cu
);
9659 if (cu
->language
== language_rust
)
9660 rust_union_quirks (cu
);
9662 /* TUs share symbol tables.
9663 If this is the first TU to use this symtab, complete the construction
9664 of it with end_expandable_symtab. Otherwise, complete the addition of
9665 this TU's symbols to the existing symtab. */
9666 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
9668 buildsym_compunit
*builder
= cu
->get_builder ();
9669 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
9670 sig_type
->type_unit_group
->compunit_symtab
= cust
;
9674 /* Set symtab language to language from DW_AT_language. If the
9675 compilation is from a C file generated by language preprocessors,
9676 do not set the language if it was already deduced by
9678 if (!(cu
->language
== language_c
9679 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
9680 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9685 cu
->get_builder ()->augment_type_symtab ();
9686 cust
= sig_type
->type_unit_group
->compunit_symtab
;
9689 if (dwarf2_per_objfile
->using_index
)
9690 per_cu
->v
.quick
->compunit_symtab
= cust
;
9693 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
9694 pst
->compunit_symtab
= cust
;
9698 /* Not needed any more. */
9699 cu
->reset_builder ();
9702 /* Process an imported unit DIE. */
9705 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9707 struct attribute
*attr
;
9709 /* For now we don't handle imported units in type units. */
9710 if (cu
->per_cu
->is_debug_types
)
9712 error (_("Dwarf Error: DW_TAG_imported_unit is not"
9713 " supported in type units [in module %s]"),
9714 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
9717 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
9720 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
9721 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
9722 dwarf2_per_cu_data
*per_cu
9723 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
9724 cu
->per_cu
->dwarf2_per_objfile
);
9726 /* If necessary, add it to the queue and load its DIEs. */
9727 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
9728 load_full_comp_unit (per_cu
, false, cu
->language
);
9730 cu
->per_cu
->imported_symtabs_push (per_cu
);
9734 /* RAII object that represents a process_die scope: i.e.,
9735 starts/finishes processing a DIE. */
9736 class process_die_scope
9739 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
9740 : m_die (die
), m_cu (cu
)
9742 /* We should only be processing DIEs not already in process. */
9743 gdb_assert (!m_die
->in_process
);
9744 m_die
->in_process
= true;
9747 ~process_die_scope ()
9749 m_die
->in_process
= false;
9751 /* If we're done processing the DIE for the CU that owns the line
9752 header, we don't need the line header anymore. */
9753 if (m_cu
->line_header_die_owner
== m_die
)
9755 delete m_cu
->line_header
;
9756 m_cu
->line_header
= NULL
;
9757 m_cu
->line_header_die_owner
= NULL
;
9766 /* Process a die and its children. */
9769 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9771 process_die_scope
scope (die
, cu
);
9775 case DW_TAG_padding
:
9777 case DW_TAG_compile_unit
:
9778 case DW_TAG_partial_unit
:
9779 read_file_scope (die
, cu
);
9781 case DW_TAG_type_unit
:
9782 read_type_unit_scope (die
, cu
);
9784 case DW_TAG_subprogram
:
9785 /* Nested subprograms in Fortran get a prefix. */
9786 if (cu
->language
== language_fortran
9787 && die
->parent
!= NULL
9788 && die
->parent
->tag
== DW_TAG_subprogram
)
9789 cu
->processing_has_namespace_info
= true;
9791 case DW_TAG_inlined_subroutine
:
9792 read_func_scope (die
, cu
);
9794 case DW_TAG_lexical_block
:
9795 case DW_TAG_try_block
:
9796 case DW_TAG_catch_block
:
9797 read_lexical_block_scope (die
, cu
);
9799 case DW_TAG_call_site
:
9800 case DW_TAG_GNU_call_site
:
9801 read_call_site_scope (die
, cu
);
9803 case DW_TAG_class_type
:
9804 case DW_TAG_interface_type
:
9805 case DW_TAG_structure_type
:
9806 case DW_TAG_union_type
:
9807 process_structure_scope (die
, cu
);
9809 case DW_TAG_enumeration_type
:
9810 process_enumeration_scope (die
, cu
);
9813 /* These dies have a type, but processing them does not create
9814 a symbol or recurse to process the children. Therefore we can
9815 read them on-demand through read_type_die. */
9816 case DW_TAG_subroutine_type
:
9817 case DW_TAG_set_type
:
9818 case DW_TAG_array_type
:
9819 case DW_TAG_pointer_type
:
9820 case DW_TAG_ptr_to_member_type
:
9821 case DW_TAG_reference_type
:
9822 case DW_TAG_rvalue_reference_type
:
9823 case DW_TAG_string_type
:
9826 case DW_TAG_base_type
:
9827 case DW_TAG_subrange_type
:
9828 case DW_TAG_typedef
:
9829 /* Add a typedef symbol for the type definition, if it has a
9831 new_symbol (die
, read_type_die (die
, cu
), cu
);
9833 case DW_TAG_common_block
:
9834 read_common_block (die
, cu
);
9836 case DW_TAG_common_inclusion
:
9838 case DW_TAG_namespace
:
9839 cu
->processing_has_namespace_info
= true;
9840 read_namespace (die
, cu
);
9843 cu
->processing_has_namespace_info
= true;
9844 read_module (die
, cu
);
9846 case DW_TAG_imported_declaration
:
9847 cu
->processing_has_namespace_info
= true;
9848 if (read_namespace_alias (die
, cu
))
9850 /* The declaration is not a global namespace alias. */
9852 case DW_TAG_imported_module
:
9853 cu
->processing_has_namespace_info
= true;
9854 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
9855 || cu
->language
!= language_fortran
))
9856 complaint (_("Tag '%s' has unexpected children"),
9857 dwarf_tag_name (die
->tag
));
9858 read_import_statement (die
, cu
);
9861 case DW_TAG_imported_unit
:
9862 process_imported_unit_die (die
, cu
);
9865 case DW_TAG_variable
:
9866 read_variable (die
, cu
);
9870 new_symbol (die
, NULL
, cu
);
9875 /* DWARF name computation. */
9877 /* A helper function for dwarf2_compute_name which determines whether DIE
9878 needs to have the name of the scope prepended to the name listed in the
9882 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
9884 struct attribute
*attr
;
9888 case DW_TAG_namespace
:
9889 case DW_TAG_typedef
:
9890 case DW_TAG_class_type
:
9891 case DW_TAG_interface_type
:
9892 case DW_TAG_structure_type
:
9893 case DW_TAG_union_type
:
9894 case DW_TAG_enumeration_type
:
9895 case DW_TAG_enumerator
:
9896 case DW_TAG_subprogram
:
9897 case DW_TAG_inlined_subroutine
:
9899 case DW_TAG_imported_declaration
:
9902 case DW_TAG_variable
:
9903 case DW_TAG_constant
:
9904 /* We only need to prefix "globally" visible variables. These include
9905 any variable marked with DW_AT_external or any variable that
9906 lives in a namespace. [Variables in anonymous namespaces
9907 require prefixing, but they are not DW_AT_external.] */
9909 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
9911 struct dwarf2_cu
*spec_cu
= cu
;
9913 return die_needs_namespace (die_specification (die
, &spec_cu
),
9917 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
9918 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
9919 && die
->parent
->tag
!= DW_TAG_module
)
9921 /* A variable in a lexical block of some kind does not need a
9922 namespace, even though in C++ such variables may be external
9923 and have a mangled name. */
9924 if (die
->parent
->tag
== DW_TAG_lexical_block
9925 || die
->parent
->tag
== DW_TAG_try_block
9926 || die
->parent
->tag
== DW_TAG_catch_block
9927 || die
->parent
->tag
== DW_TAG_subprogram
)
9936 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
9937 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9938 defined for the given DIE. */
9940 static struct attribute
*
9941 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
9943 struct attribute
*attr
;
9945 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
9947 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9952 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
9953 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9954 defined for the given DIE. */
9957 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
9959 const char *linkage_name
;
9961 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
9962 if (linkage_name
== NULL
)
9963 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9965 return linkage_name
;
9968 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
9969 compute the physname for the object, which include a method's:
9970 - formal parameters (C++),
9971 - receiver type (Go),
9973 The term "physname" is a bit confusing.
9974 For C++, for example, it is the demangled name.
9975 For Go, for example, it's the mangled name.
9977 For Ada, return the DIE's linkage name rather than the fully qualified
9978 name. PHYSNAME is ignored..
9980 The result is allocated on the objfile_obstack and canonicalized. */
9983 dwarf2_compute_name (const char *name
,
9984 struct die_info
*die
, struct dwarf2_cu
*cu
,
9987 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9990 name
= dwarf2_name (die
, cu
);
9992 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
9993 but otherwise compute it by typename_concat inside GDB.
9994 FIXME: Actually this is not really true, or at least not always true.
9995 It's all very confusing. compute_and_set_names doesn't try to demangle
9996 Fortran names because there is no mangling standard. So new_symbol
9997 will set the demangled name to the result of dwarf2_full_name, and it is
9998 the demangled name that GDB uses if it exists. */
9999 if (cu
->language
== language_ada
10000 || (cu
->language
== language_fortran
&& physname
))
10002 /* For Ada unit, we prefer the linkage name over the name, as
10003 the former contains the exported name, which the user expects
10004 to be able to reference. Ideally, we want the user to be able
10005 to reference this entity using either natural or linkage name,
10006 but we haven't started looking at this enhancement yet. */
10007 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10009 if (linkage_name
!= NULL
)
10010 return linkage_name
;
10013 /* These are the only languages we know how to qualify names in. */
10015 && (cu
->language
== language_cplus
10016 || cu
->language
== language_fortran
|| cu
->language
== language_d
10017 || cu
->language
== language_rust
))
10019 if (die_needs_namespace (die
, cu
))
10021 const char *prefix
;
10022 const char *canonical_name
= NULL
;
10026 prefix
= determine_prefix (die
, cu
);
10027 if (*prefix
!= '\0')
10029 gdb::unique_xmalloc_ptr
<char> prefixed_name
10030 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10032 buf
.puts (prefixed_name
.get ());
10037 /* Template parameters may be specified in the DIE's DW_AT_name, or
10038 as children with DW_TAG_template_type_param or
10039 DW_TAG_value_type_param. If the latter, add them to the name
10040 here. If the name already has template parameters, then
10041 skip this step; some versions of GCC emit both, and
10042 it is more efficient to use the pre-computed name.
10044 Something to keep in mind about this process: it is very
10045 unlikely, or in some cases downright impossible, to produce
10046 something that will match the mangled name of a function.
10047 If the definition of the function has the same debug info,
10048 we should be able to match up with it anyway. But fallbacks
10049 using the minimal symbol, for instance to find a method
10050 implemented in a stripped copy of libstdc++, will not work.
10051 If we do not have debug info for the definition, we will have to
10052 match them up some other way.
10054 When we do name matching there is a related problem with function
10055 templates; two instantiated function templates are allowed to
10056 differ only by their return types, which we do not add here. */
10058 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10060 struct attribute
*attr
;
10061 struct die_info
*child
;
10064 die
->building_fullname
= 1;
10066 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10070 const gdb_byte
*bytes
;
10071 struct dwarf2_locexpr_baton
*baton
;
10074 if (child
->tag
!= DW_TAG_template_type_param
10075 && child
->tag
!= DW_TAG_template_value_param
)
10086 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10089 complaint (_("template parameter missing DW_AT_type"));
10090 buf
.puts ("UNKNOWN_TYPE");
10093 type
= die_type (child
, cu
);
10095 if (child
->tag
== DW_TAG_template_type_param
)
10097 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10098 &type_print_raw_options
);
10102 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10105 complaint (_("template parameter missing "
10106 "DW_AT_const_value"));
10107 buf
.puts ("UNKNOWN_VALUE");
10111 dwarf2_const_value_attr (attr
, type
, name
,
10112 &cu
->comp_unit_obstack
, cu
,
10113 &value
, &bytes
, &baton
);
10115 if (TYPE_NOSIGN (type
))
10116 /* GDB prints characters as NUMBER 'CHAR'. If that's
10117 changed, this can use value_print instead. */
10118 c_printchar (value
, type
, &buf
);
10121 struct value_print_options opts
;
10124 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10128 else if (bytes
!= NULL
)
10130 v
= allocate_value (type
);
10131 memcpy (value_contents_writeable (v
), bytes
,
10132 TYPE_LENGTH (type
));
10135 v
= value_from_longest (type
, value
);
10137 /* Specify decimal so that we do not depend on
10139 get_formatted_print_options (&opts
, 'd');
10141 value_print (v
, &buf
, &opts
);
10146 die
->building_fullname
= 0;
10150 /* Close the argument list, with a space if necessary
10151 (nested templates). */
10152 if (!buf
.empty () && buf
.string ().back () == '>')
10159 /* For C++ methods, append formal parameter type
10160 information, if PHYSNAME. */
10162 if (physname
&& die
->tag
== DW_TAG_subprogram
10163 && cu
->language
== language_cplus
)
10165 struct type
*type
= read_type_die (die
, cu
);
10167 c_type_print_args (type
, &buf
, 1, cu
->language
,
10168 &type_print_raw_options
);
10170 if (cu
->language
== language_cplus
)
10172 /* Assume that an artificial first parameter is
10173 "this", but do not crash if it is not. RealView
10174 marks unnamed (and thus unused) parameters as
10175 artificial; there is no way to differentiate
10177 if (TYPE_NFIELDS (type
) > 0
10178 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10179 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
10180 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
10182 buf
.puts (" const");
10186 const std::string
&intermediate_name
= buf
.string ();
10188 if (cu
->language
== language_cplus
)
10190 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10191 &objfile
->per_bfd
->storage_obstack
);
10193 /* If we only computed INTERMEDIATE_NAME, or if
10194 INTERMEDIATE_NAME is already canonical, then we need to
10195 copy it to the appropriate obstack. */
10196 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10197 name
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
10198 intermediate_name
);
10200 name
= canonical_name
;
10207 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10208 If scope qualifiers are appropriate they will be added. The result
10209 will be allocated on the storage_obstack, or NULL if the DIE does
10210 not have a name. NAME may either be from a previous call to
10211 dwarf2_name or NULL.
10213 The output string will be canonicalized (if C++). */
10215 static const char *
10216 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10218 return dwarf2_compute_name (name
, die
, cu
, 0);
10221 /* Construct a physname for the given DIE in CU. NAME may either be
10222 from a previous call to dwarf2_name or NULL. The result will be
10223 allocated on the objfile_objstack or NULL if the DIE does not have a
10226 The output string will be canonicalized (if C++). */
10228 static const char *
10229 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10231 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10232 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10235 /* In this case dwarf2_compute_name is just a shortcut not building anything
10237 if (!die_needs_namespace (die
, cu
))
10238 return dwarf2_compute_name (name
, die
, cu
, 1);
10240 mangled
= dw2_linkage_name (die
, cu
);
10242 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
10243 See https://github.com/rust-lang/rust/issues/32925. */
10244 if (cu
->language
== language_rust
&& mangled
!= NULL
10245 && strchr (mangled
, '{') != NULL
)
10248 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10250 gdb::unique_xmalloc_ptr
<char> demangled
;
10251 if (mangled
!= NULL
)
10254 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
10256 /* Do nothing (do not demangle the symbol name). */
10258 else if (cu
->language
== language_go
)
10260 /* This is a lie, but we already lie to the caller new_symbol.
10261 new_symbol assumes we return the mangled name.
10262 This just undoes that lie until things are cleaned up. */
10266 /* Use DMGL_RET_DROP for C++ template functions to suppress
10267 their return type. It is easier for GDB users to search
10268 for such functions as `name(params)' than `long name(params)'.
10269 In such case the minimal symbol names do not match the full
10270 symbol names but for template functions there is never a need
10271 to look up their definition from their declaration so
10272 the only disadvantage remains the minimal symbol variant
10273 `long name(params)' does not have the proper inferior type. */
10274 demangled
.reset (gdb_demangle (mangled
,
10275 (DMGL_PARAMS
| DMGL_ANSI
10276 | DMGL_RET_DROP
)));
10279 canon
= demangled
.get ();
10287 if (canon
== NULL
|| check_physname
)
10289 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10291 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10293 /* It may not mean a bug in GDB. The compiler could also
10294 compute DW_AT_linkage_name incorrectly. But in such case
10295 GDB would need to be bug-to-bug compatible. */
10297 complaint (_("Computed physname <%s> does not match demangled <%s> "
10298 "(from linkage <%s>) - DIE at %s [in module %s]"),
10299 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10300 objfile_name (objfile
));
10302 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10303 is available here - over computed PHYSNAME. It is safer
10304 against both buggy GDB and buggy compilers. */
10318 retval
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
, retval
);
10323 /* Inspect DIE in CU for a namespace alias. If one exists, record
10324 a new symbol for it.
10326 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10329 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10331 struct attribute
*attr
;
10333 /* If the die does not have a name, this is not a namespace
10335 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10339 struct die_info
*d
= die
;
10340 struct dwarf2_cu
*imported_cu
= cu
;
10342 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10343 keep inspecting DIEs until we hit the underlying import. */
10344 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10345 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10347 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10351 d
= follow_die_ref (d
, attr
, &imported_cu
);
10352 if (d
->tag
!= DW_TAG_imported_declaration
)
10356 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10358 complaint (_("DIE at %s has too many recursively imported "
10359 "declarations"), sect_offset_str (d
->sect_off
));
10366 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
10368 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
10369 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
10371 /* This declaration is a global namespace alias. Add
10372 a symbol for it whose type is the aliased namespace. */
10373 new_symbol (die
, type
, cu
);
10382 /* Return the using directives repository (global or local?) to use in the
10383 current context for CU.
10385 For Ada, imported declarations can materialize renamings, which *may* be
10386 global. However it is impossible (for now?) in DWARF to distinguish
10387 "external" imported declarations and "static" ones. As all imported
10388 declarations seem to be static in all other languages, make them all CU-wide
10389 global only in Ada. */
10391 static struct using_direct
**
10392 using_directives (struct dwarf2_cu
*cu
)
10394 if (cu
->language
== language_ada
10395 && cu
->get_builder ()->outermost_context_p ())
10396 return cu
->get_builder ()->get_global_using_directives ();
10398 return cu
->get_builder ()->get_local_using_directives ();
10401 /* Read the import statement specified by the given die and record it. */
10404 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10406 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10407 struct attribute
*import_attr
;
10408 struct die_info
*imported_die
, *child_die
;
10409 struct dwarf2_cu
*imported_cu
;
10410 const char *imported_name
;
10411 const char *imported_name_prefix
;
10412 const char *canonical_name
;
10413 const char *import_alias
;
10414 const char *imported_declaration
= NULL
;
10415 const char *import_prefix
;
10416 std::vector
<const char *> excludes
;
10418 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10419 if (import_attr
== NULL
)
10421 complaint (_("Tag '%s' has no DW_AT_import"),
10422 dwarf_tag_name (die
->tag
));
10427 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10428 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10429 if (imported_name
== NULL
)
10431 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10433 The import in the following code:
10447 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10448 <52> DW_AT_decl_file : 1
10449 <53> DW_AT_decl_line : 6
10450 <54> DW_AT_import : <0x75>
10451 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10452 <59> DW_AT_name : B
10453 <5b> DW_AT_decl_file : 1
10454 <5c> DW_AT_decl_line : 2
10455 <5d> DW_AT_type : <0x6e>
10457 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10458 <76> DW_AT_byte_size : 4
10459 <77> DW_AT_encoding : 5 (signed)
10461 imports the wrong die ( 0x75 instead of 0x58 ).
10462 This case will be ignored until the gcc bug is fixed. */
10466 /* Figure out the local name after import. */
10467 import_alias
= dwarf2_name (die
, cu
);
10469 /* Figure out where the statement is being imported to. */
10470 import_prefix
= determine_prefix (die
, cu
);
10472 /* Figure out what the scope of the imported die is and prepend it
10473 to the name of the imported die. */
10474 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10476 if (imported_die
->tag
!= DW_TAG_namespace
10477 && imported_die
->tag
!= DW_TAG_module
)
10479 imported_declaration
= imported_name
;
10480 canonical_name
= imported_name_prefix
;
10482 else if (strlen (imported_name_prefix
) > 0)
10483 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10484 imported_name_prefix
,
10485 (cu
->language
== language_d
? "." : "::"),
10486 imported_name
, (char *) NULL
);
10488 canonical_name
= imported_name
;
10490 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
10491 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10492 child_die
= sibling_die (child_die
))
10494 /* DWARF-4: A Fortran use statement with a “rename list” may be
10495 represented by an imported module entry with an import attribute
10496 referring to the module and owned entries corresponding to those
10497 entities that are renamed as part of being imported. */
10499 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10501 complaint (_("child DW_TAG_imported_declaration expected "
10502 "- DIE at %s [in module %s]"),
10503 sect_offset_str (child_die
->sect_off
),
10504 objfile_name (objfile
));
10508 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10509 if (import_attr
== NULL
)
10511 complaint (_("Tag '%s' has no DW_AT_import"),
10512 dwarf_tag_name (child_die
->tag
));
10517 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10519 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10520 if (imported_name
== NULL
)
10522 complaint (_("child DW_TAG_imported_declaration has unknown "
10523 "imported name - DIE at %s [in module %s]"),
10524 sect_offset_str (child_die
->sect_off
),
10525 objfile_name (objfile
));
10529 excludes
.push_back (imported_name
);
10531 process_die (child_die
, cu
);
10534 add_using_directive (using_directives (cu
),
10538 imported_declaration
,
10541 &objfile
->objfile_obstack
);
10544 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10545 types, but gives them a size of zero. Starting with version 14,
10546 ICC is compatible with GCC. */
10549 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10551 if (!cu
->checked_producer
)
10552 check_producer (cu
);
10554 return cu
->producer_is_icc_lt_14
;
10557 /* ICC generates a DW_AT_type for C void functions. This was observed on
10558 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10559 which says that void functions should not have a DW_AT_type. */
10562 producer_is_icc (struct dwarf2_cu
*cu
)
10564 if (!cu
->checked_producer
)
10565 check_producer (cu
);
10567 return cu
->producer_is_icc
;
10570 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10571 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10572 this, it was first present in GCC release 4.3.0. */
10575 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10577 if (!cu
->checked_producer
)
10578 check_producer (cu
);
10580 return cu
->producer_is_gcc_lt_4_3
;
10583 static file_and_directory
10584 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10586 file_and_directory res
;
10588 /* Find the filename. Do not use dwarf2_name here, since the filename
10589 is not a source language identifier. */
10590 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
10591 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
10593 if (res
.comp_dir
== NULL
10594 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
10595 && IS_ABSOLUTE_PATH (res
.name
))
10597 res
.comp_dir_storage
= ldirname (res
.name
);
10598 if (!res
.comp_dir_storage
.empty ())
10599 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
10601 if (res
.comp_dir
!= NULL
)
10603 /* Irix 6.2 native cc prepends <machine>.: to the compilation
10604 directory, get rid of it. */
10605 const char *cp
= strchr (res
.comp_dir
, ':');
10607 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
10608 res
.comp_dir
= cp
+ 1;
10611 if (res
.name
== NULL
)
10612 res
.name
= "<unknown>";
10617 /* Handle DW_AT_stmt_list for a compilation unit.
10618 DIE is the DW_TAG_compile_unit die for CU.
10619 COMP_DIR is the compilation directory. LOWPC is passed to
10620 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
10623 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
10624 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
10626 struct dwarf2_per_objfile
*dwarf2_per_objfile
10627 = cu
->per_cu
->dwarf2_per_objfile
;
10628 struct attribute
*attr
;
10629 struct line_header line_header_local
;
10630 hashval_t line_header_local_hash
;
10632 int decode_mapping
;
10634 gdb_assert (! cu
->per_cu
->is_debug_types
);
10636 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
10640 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10642 /* The line header hash table is only created if needed (it exists to
10643 prevent redundant reading of the line table for partial_units).
10644 If we're given a partial_unit, we'll need it. If we're given a
10645 compile_unit, then use the line header hash table if it's already
10646 created, but don't create one just yet. */
10648 if (dwarf2_per_objfile
->line_header_hash
== NULL
10649 && die
->tag
== DW_TAG_partial_unit
)
10651 dwarf2_per_objfile
->line_header_hash
10652 .reset (htab_create_alloc (127, line_header_hash_voidp
,
10653 line_header_eq_voidp
,
10654 free_line_header_voidp
,
10658 line_header_local
.sect_off
= line_offset
;
10659 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
10660 line_header_local_hash
= line_header_hash (&line_header_local
);
10661 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
10663 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
.get (),
10664 &line_header_local
,
10665 line_header_local_hash
, NO_INSERT
);
10667 /* For DW_TAG_compile_unit we need info like symtab::linetable which
10668 is not present in *SLOT (since if there is something in *SLOT then
10669 it will be for a partial_unit). */
10670 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
10672 gdb_assert (*slot
!= NULL
);
10673 cu
->line_header
= (struct line_header
*) *slot
;
10678 /* dwarf_decode_line_header does not yet provide sufficient information.
10679 We always have to call also dwarf_decode_lines for it. */
10680 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
10684 cu
->line_header
= lh
.release ();
10685 cu
->line_header_die_owner
= die
;
10687 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
10691 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
.get (),
10692 &line_header_local
,
10693 line_header_local_hash
, INSERT
);
10694 gdb_assert (slot
!= NULL
);
10696 if (slot
!= NULL
&& *slot
== NULL
)
10698 /* This newly decoded line number information unit will be owned
10699 by line_header_hash hash table. */
10700 *slot
= cu
->line_header
;
10701 cu
->line_header_die_owner
= NULL
;
10705 /* We cannot free any current entry in (*slot) as that struct line_header
10706 may be already used by multiple CUs. Create only temporary decoded
10707 line_header for this CU - it may happen at most once for each line
10708 number information unit. And if we're not using line_header_hash
10709 then this is what we want as well. */
10710 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
10712 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
10713 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
10718 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
10721 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10723 struct dwarf2_per_objfile
*dwarf2_per_objfile
10724 = cu
->per_cu
->dwarf2_per_objfile
;
10725 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10726 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10727 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
10728 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
10729 struct attribute
*attr
;
10730 struct die_info
*child_die
;
10731 CORE_ADDR baseaddr
;
10733 prepare_one_comp_unit (cu
, die
, cu
->language
);
10734 baseaddr
= objfile
->text_section_offset ();
10736 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
10738 /* If we didn't find a lowpc, set it to highpc to avoid complaints
10739 from finish_block. */
10740 if (lowpc
== ((CORE_ADDR
) -1))
10742 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
10744 file_and_directory fnd
= find_file_and_directory (die
, cu
);
10746 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
10747 standardised yet. As a workaround for the language detection we fall
10748 back to the DW_AT_producer string. */
10749 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
10750 cu
->language
= language_opencl
;
10752 /* Similar hack for Go. */
10753 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
10754 set_cu_language (DW_LANG_Go
, cu
);
10756 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
10758 /* Decode line number information if present. We do this before
10759 processing child DIEs, so that the line header table is available
10760 for DW_AT_decl_file. */
10761 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
10763 /* Process all dies in compilation unit. */
10764 if (die
->child
!= NULL
)
10766 child_die
= die
->child
;
10767 while (child_die
&& child_die
->tag
)
10769 process_die (child_die
, cu
);
10770 child_die
= sibling_die (child_die
);
10774 /* Decode macro information, if present. Dwarf 2 macro information
10775 refers to information in the line number info statement program
10776 header, so we can only read it if we've read the header
10778 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
10780 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
10781 if (attr
&& cu
->line_header
)
10783 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
10784 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
10786 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
10790 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
10791 if (attr
&& cu
->line_header
)
10793 unsigned int macro_offset
= DW_UNSND (attr
);
10795 dwarf_decode_macros (cu
, macro_offset
, 0);
10801 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
10803 struct type_unit_group
*tu_group
;
10805 struct attribute
*attr
;
10807 struct signatured_type
*sig_type
;
10809 gdb_assert (per_cu
->is_debug_types
);
10810 sig_type
= (struct signatured_type
*) per_cu
;
10812 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
10814 /* If we're using .gdb_index (includes -readnow) then
10815 per_cu->type_unit_group may not have been set up yet. */
10816 if (sig_type
->type_unit_group
== NULL
)
10817 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
10818 tu_group
= sig_type
->type_unit_group
;
10820 /* If we've already processed this stmt_list there's no real need to
10821 do it again, we could fake it and just recreate the part we need
10822 (file name,index -> symtab mapping). If data shows this optimization
10823 is useful we can do it then. */
10824 first_time
= tu_group
->compunit_symtab
== NULL
;
10826 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
10831 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10832 lh
= dwarf_decode_line_header (line_offset
, this);
10837 start_symtab ("", NULL
, 0);
10840 gdb_assert (tu_group
->symtabs
== NULL
);
10841 gdb_assert (m_builder
== nullptr);
10842 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
10843 m_builder
.reset (new struct buildsym_compunit
10844 (COMPUNIT_OBJFILE (cust
), "",
10845 COMPUNIT_DIRNAME (cust
),
10846 compunit_language (cust
),
10852 line_header
= lh
.release ();
10853 line_header_die_owner
= die
;
10857 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
10859 /* Note: We don't assign tu_group->compunit_symtab yet because we're
10860 still initializing it, and our caller (a few levels up)
10861 process_full_type_unit still needs to know if this is the first
10864 tu_group
->num_symtabs
= line_header
->file_names_size ();
10865 tu_group
->symtabs
= XNEWVEC (struct symtab
*,
10866 line_header
->file_names_size ());
10868 auto &file_names
= line_header
->file_names ();
10869 for (i
= 0; i
< file_names
.size (); ++i
)
10871 file_entry
&fe
= file_names
[i
];
10872 dwarf2_start_subfile (this, fe
.name
,
10873 fe
.include_dir (line_header
));
10874 buildsym_compunit
*b
= get_builder ();
10875 if (b
->get_current_subfile ()->symtab
== NULL
)
10877 /* NOTE: start_subfile will recognize when it's been
10878 passed a file it has already seen. So we can't
10879 assume there's a simple mapping from
10880 cu->line_header->file_names to subfiles, plus
10881 cu->line_header->file_names may contain dups. */
10882 b
->get_current_subfile ()->symtab
10883 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
10886 fe
.symtab
= b
->get_current_subfile ()->symtab
;
10887 tu_group
->symtabs
[i
] = fe
.symtab
;
10892 gdb_assert (m_builder
== nullptr);
10893 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
10894 m_builder
.reset (new struct buildsym_compunit
10895 (COMPUNIT_OBJFILE (cust
), "",
10896 COMPUNIT_DIRNAME (cust
),
10897 compunit_language (cust
),
10900 auto &file_names
= line_header
->file_names ();
10901 for (i
= 0; i
< file_names
.size (); ++i
)
10903 file_entry
&fe
= file_names
[i
];
10904 fe
.symtab
= tu_group
->symtabs
[i
];
10908 /* The main symtab is allocated last. Type units don't have DW_AT_name
10909 so they don't have a "real" (so to speak) symtab anyway.
10910 There is later code that will assign the main symtab to all symbols
10911 that don't have one. We need to handle the case of a symbol with a
10912 missing symtab (DW_AT_decl_file) anyway. */
10915 /* Process DW_TAG_type_unit.
10916 For TUs we want to skip the first top level sibling if it's not the
10917 actual type being defined by this TU. In this case the first top
10918 level sibling is there to provide context only. */
10921 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10923 struct die_info
*child_die
;
10925 prepare_one_comp_unit (cu
, die
, language_minimal
);
10927 /* Initialize (or reinitialize) the machinery for building symtabs.
10928 We do this before processing child DIEs, so that the line header table
10929 is available for DW_AT_decl_file. */
10930 cu
->setup_type_unit_groups (die
);
10932 if (die
->child
!= NULL
)
10934 child_die
= die
->child
;
10935 while (child_die
&& child_die
->tag
)
10937 process_die (child_die
, cu
);
10938 child_die
= sibling_die (child_die
);
10945 http://gcc.gnu.org/wiki/DebugFission
10946 http://gcc.gnu.org/wiki/DebugFissionDWP
10948 To simplify handling of both DWO files ("object" files with the DWARF info)
10949 and DWP files (a file with the DWOs packaged up into one file), we treat
10950 DWP files as having a collection of virtual DWO files. */
10953 hash_dwo_file (const void *item
)
10955 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
10958 hash
= htab_hash_string (dwo_file
->dwo_name
);
10959 if (dwo_file
->comp_dir
!= NULL
)
10960 hash
+= htab_hash_string (dwo_file
->comp_dir
);
10965 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
10967 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
10968 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
10970 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
10972 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
10973 return lhs
->comp_dir
== rhs
->comp_dir
;
10974 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
10977 /* Allocate a hash table for DWO files. */
10980 allocate_dwo_file_hash_table (struct objfile
*objfile
)
10982 auto delete_dwo_file
= [] (void *item
)
10984 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
10989 return htab_up (htab_create_alloc (41,
10996 /* Lookup DWO file DWO_NAME. */
10999 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11000 const char *dwo_name
,
11001 const char *comp_dir
)
11003 struct dwo_file find_entry
;
11006 if (dwarf2_per_objfile
->dwo_files
== NULL
)
11007 dwarf2_per_objfile
->dwo_files
11008 = allocate_dwo_file_hash_table (dwarf2_per_objfile
->objfile
);
11010 find_entry
.dwo_name
= dwo_name
;
11011 find_entry
.comp_dir
= comp_dir
;
11012 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
.get (), &find_entry
,
11019 hash_dwo_unit (const void *item
)
11021 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11023 /* This drops the top 32 bits of the id, but is ok for a hash. */
11024 return dwo_unit
->signature
;
11028 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11030 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11031 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11033 /* The signature is assumed to be unique within the DWO file.
11034 So while object file CU dwo_id's always have the value zero,
11035 that's OK, assuming each object file DWO file has only one CU,
11036 and that's the rule for now. */
11037 return lhs
->signature
== rhs
->signature
;
11040 /* Allocate a hash table for DWO CUs,TUs.
11041 There is one of these tables for each of CUs,TUs for each DWO file. */
11044 allocate_dwo_unit_table (struct objfile
*objfile
)
11046 /* Start out with a pretty small number.
11047 Generally DWO files contain only one CU and maybe some TUs. */
11048 return htab_up (htab_create_alloc (3,
11051 NULL
, xcalloc
, xfree
));
11054 /* die_reader_func for create_dwo_cu. */
11057 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11058 const gdb_byte
*info_ptr
,
11059 struct die_info
*comp_unit_die
,
11060 struct dwo_file
*dwo_file
,
11061 struct dwo_unit
*dwo_unit
)
11063 struct dwarf2_cu
*cu
= reader
->cu
;
11064 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11065 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11067 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11068 if (!signature
.has_value ())
11070 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11071 " its dwo_id [in module %s]"),
11072 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11076 dwo_unit
->dwo_file
= dwo_file
;
11077 dwo_unit
->signature
= *signature
;
11078 dwo_unit
->section
= section
;
11079 dwo_unit
->sect_off
= sect_off
;
11080 dwo_unit
->length
= cu
->per_cu
->length
;
11082 if (dwarf_read_debug
)
11083 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11084 sect_offset_str (sect_off
),
11085 hex_string (dwo_unit
->signature
));
11088 /* Create the dwo_units for the CUs in a DWO_FILE.
11089 Note: This function processes DWO files only, not DWP files. */
11092 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11093 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11094 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
11096 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11097 const gdb_byte
*info_ptr
, *end_ptr
;
11099 section
.read (objfile
);
11100 info_ptr
= section
.buffer
;
11102 if (info_ptr
== NULL
)
11105 if (dwarf_read_debug
)
11107 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11108 section
.get_name (),
11109 section
.get_file_name ());
11112 end_ptr
= info_ptr
+ section
.size
;
11113 while (info_ptr
< end_ptr
)
11115 struct dwarf2_per_cu_data per_cu
;
11116 struct dwo_unit read_unit
{};
11117 struct dwo_unit
*dwo_unit
;
11119 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11121 memset (&per_cu
, 0, sizeof (per_cu
));
11122 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
11123 per_cu
.is_debug_types
= 0;
11124 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11125 per_cu
.section
= §ion
;
11127 cutu_reader
reader (&per_cu
, cu
, &dwo_file
);
11128 if (!reader
.dummy_p
)
11129 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11130 &dwo_file
, &read_unit
);
11131 info_ptr
+= per_cu
.length
;
11133 // If the unit could not be parsed, skip it.
11134 if (read_unit
.dwo_file
== NULL
)
11137 if (cus_htab
== NULL
)
11138 cus_htab
= allocate_dwo_unit_table (objfile
);
11140 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11141 *dwo_unit
= read_unit
;
11142 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11143 gdb_assert (slot
!= NULL
);
11146 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11147 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11149 complaint (_("debug cu entry at offset %s is duplicate to"
11150 " the entry at offset %s, signature %s"),
11151 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11152 hex_string (dwo_unit
->signature
));
11154 *slot
= (void *)dwo_unit
;
11158 /* DWP file .debug_{cu,tu}_index section format:
11159 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11163 Both index sections have the same format, and serve to map a 64-bit
11164 signature to a set of section numbers. Each section begins with a header,
11165 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11166 indexes, and a pool of 32-bit section numbers. The index sections will be
11167 aligned at 8-byte boundaries in the file.
11169 The index section header consists of:
11171 V, 32 bit version number
11173 N, 32 bit number of compilation units or type units in the index
11174 M, 32 bit number of slots in the hash table
11176 Numbers are recorded using the byte order of the application binary.
11178 The hash table begins at offset 16 in the section, and consists of an array
11179 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11180 order of the application binary). Unused slots in the hash table are 0.
11181 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11183 The parallel table begins immediately after the hash table
11184 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11185 array of 32-bit indexes (using the byte order of the application binary),
11186 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11187 table contains a 32-bit index into the pool of section numbers. For unused
11188 hash table slots, the corresponding entry in the parallel table will be 0.
11190 The pool of section numbers begins immediately following the hash table
11191 (at offset 16 + 12 * M from the beginning of the section). The pool of
11192 section numbers consists of an array of 32-bit words (using the byte order
11193 of the application binary). Each item in the array is indexed starting
11194 from 0. The hash table entry provides the index of the first section
11195 number in the set. Additional section numbers in the set follow, and the
11196 set is terminated by a 0 entry (section number 0 is not used in ELF).
11198 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11199 section must be the first entry in the set, and the .debug_abbrev.dwo must
11200 be the second entry. Other members of the set may follow in any order.
11206 DWP Version 2 combines all the .debug_info, etc. sections into one,
11207 and the entries in the index tables are now offsets into these sections.
11208 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11211 Index Section Contents:
11213 Hash Table of Signatures dwp_hash_table.hash_table
11214 Parallel Table of Indices dwp_hash_table.unit_table
11215 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
11216 Table of Section Sizes dwp_hash_table.v2.sizes
11218 The index section header consists of:
11220 V, 32 bit version number
11221 L, 32 bit number of columns in the table of section offsets
11222 N, 32 bit number of compilation units or type units in the index
11223 M, 32 bit number of slots in the hash table
11225 Numbers are recorded using the byte order of the application binary.
11227 The hash table has the same format as version 1.
11228 The parallel table of indices has the same format as version 1,
11229 except that the entries are origin-1 indices into the table of sections
11230 offsets and the table of section sizes.
11232 The table of offsets begins immediately following the parallel table
11233 (at offset 16 + 12 * M from the beginning of the section). The table is
11234 a two-dimensional array of 32-bit words (using the byte order of the
11235 application binary), with L columns and N+1 rows, in row-major order.
11236 Each row in the array is indexed starting from 0. The first row provides
11237 a key to the remaining rows: each column in this row provides an identifier
11238 for a debug section, and the offsets in the same column of subsequent rows
11239 refer to that section. The section identifiers are:
11241 DW_SECT_INFO 1 .debug_info.dwo
11242 DW_SECT_TYPES 2 .debug_types.dwo
11243 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11244 DW_SECT_LINE 4 .debug_line.dwo
11245 DW_SECT_LOC 5 .debug_loc.dwo
11246 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11247 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11248 DW_SECT_MACRO 8 .debug_macro.dwo
11250 The offsets provided by the CU and TU index sections are the base offsets
11251 for the contributions made by each CU or TU to the corresponding section
11252 in the package file. Each CU and TU header contains an abbrev_offset
11253 field, used to find the abbreviations table for that CU or TU within the
11254 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11255 be interpreted as relative to the base offset given in the index section.
11256 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11257 should be interpreted as relative to the base offset for .debug_line.dwo,
11258 and offsets into other debug sections obtained from DWARF attributes should
11259 also be interpreted as relative to the corresponding base offset.
11261 The table of sizes begins immediately following the table of offsets.
11262 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11263 with L columns and N rows, in row-major order. Each row in the array is
11264 indexed starting from 1 (row 0 is shared by the two tables).
11268 Hash table lookup is handled the same in version 1 and 2:
11270 We assume that N and M will not exceed 2^32 - 1.
11271 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11273 Given a 64-bit compilation unit signature or a type signature S, an entry
11274 in the hash table is located as follows:
11276 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11277 the low-order k bits all set to 1.
11279 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11281 3) If the hash table entry at index H matches the signature, use that
11282 entry. If the hash table entry at index H is unused (all zeroes),
11283 terminate the search: the signature is not present in the table.
11285 4) Let H = (H + H') modulo M. Repeat at Step 3.
11287 Because M > N and H' and M are relatively prime, the search is guaranteed
11288 to stop at an unused slot or find the match. */
11290 /* Create a hash table to map DWO IDs to their CU/TU entry in
11291 .debug_{info,types}.dwo in DWP_FILE.
11292 Returns NULL if there isn't one.
11293 Note: This function processes DWP files only, not DWO files. */
11295 static struct dwp_hash_table
*
11296 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11297 struct dwp_file
*dwp_file
, int is_debug_types
)
11299 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11300 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11301 const gdb_byte
*index_ptr
, *index_end
;
11302 struct dwarf2_section_info
*index
;
11303 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11304 struct dwp_hash_table
*htab
;
11306 if (is_debug_types
)
11307 index
= &dwp_file
->sections
.tu_index
;
11309 index
= &dwp_file
->sections
.cu_index
;
11311 if (index
->empty ())
11313 index
->read (objfile
);
11315 index_ptr
= index
->buffer
;
11316 index_end
= index_ptr
+ index
->size
;
11318 version
= read_4_bytes (dbfd
, index_ptr
);
11321 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11325 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11327 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11330 if (version
!= 1 && version
!= 2)
11332 error (_("Dwarf Error: unsupported DWP file version (%s)"
11333 " [in module %s]"),
11334 pulongest (version
), dwp_file
->name
);
11336 if (nr_slots
!= (nr_slots
& -nr_slots
))
11338 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11339 " is not power of 2 [in module %s]"),
11340 pulongest (nr_slots
), dwp_file
->name
);
11343 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
11344 htab
->version
= version
;
11345 htab
->nr_columns
= nr_columns
;
11346 htab
->nr_units
= nr_units
;
11347 htab
->nr_slots
= nr_slots
;
11348 htab
->hash_table
= index_ptr
;
11349 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11351 /* Exit early if the table is empty. */
11352 if (nr_slots
== 0 || nr_units
== 0
11353 || (version
== 2 && nr_columns
== 0))
11355 /* All must be zero. */
11356 if (nr_slots
!= 0 || nr_units
!= 0
11357 || (version
== 2 && nr_columns
!= 0))
11359 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11360 " all zero [in modules %s]"),
11368 htab
->section_pool
.v1
.indices
=
11369 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11370 /* It's harder to decide whether the section is too small in v1.
11371 V1 is deprecated anyway so we punt. */
11375 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11376 int *ids
= htab
->section_pool
.v2
.section_ids
;
11377 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11378 /* Reverse map for error checking. */
11379 int ids_seen
[DW_SECT_MAX
+ 1];
11382 if (nr_columns
< 2)
11384 error (_("Dwarf Error: bad DWP hash table, too few columns"
11385 " in section table [in module %s]"),
11388 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11390 error (_("Dwarf Error: bad DWP hash table, too many columns"
11391 " in section table [in module %s]"),
11394 memset (ids
, 255, sizeof_ids
);
11395 memset (ids_seen
, 255, sizeof (ids_seen
));
11396 for (i
= 0; i
< nr_columns
; ++i
)
11398 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11400 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11402 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11403 " in section table [in module %s]"),
11404 id
, dwp_file
->name
);
11406 if (ids_seen
[id
] != -1)
11408 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11409 " id %d in section table [in module %s]"),
11410 id
, dwp_file
->name
);
11415 /* Must have exactly one info or types section. */
11416 if (((ids_seen
[DW_SECT_INFO
] != -1)
11417 + (ids_seen
[DW_SECT_TYPES
] != -1))
11420 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11421 " DWO info/types section [in module %s]"),
11424 /* Must have an abbrev section. */
11425 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11427 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11428 " section [in module %s]"),
11431 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11432 htab
->section_pool
.v2
.sizes
=
11433 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11434 * nr_units
* nr_columns
);
11435 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11436 * nr_units
* nr_columns
))
11439 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11440 " [in module %s]"),
11448 /* Update SECTIONS with the data from SECTP.
11450 This function is like the other "locate" section routines that are
11451 passed to bfd_map_over_sections, but in this context the sections to
11452 read comes from the DWP V1 hash table, not the full ELF section table.
11454 The result is non-zero for success, or zero if an error was found. */
11457 locate_v1_virtual_dwo_sections (asection
*sectp
,
11458 struct virtual_v1_dwo_sections
*sections
)
11460 const struct dwop_section_names
*names
= &dwop_section_names
;
11462 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
11464 /* There can be only one. */
11465 if (sections
->abbrev
.s
.section
!= NULL
)
11467 sections
->abbrev
.s
.section
= sectp
;
11468 sections
->abbrev
.size
= bfd_section_size (sectp
);
11470 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
11471 || section_is_p (sectp
->name
, &names
->types_dwo
))
11473 /* There can be only one. */
11474 if (sections
->info_or_types
.s
.section
!= NULL
)
11476 sections
->info_or_types
.s
.section
= sectp
;
11477 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11479 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
11481 /* There can be only one. */
11482 if (sections
->line
.s
.section
!= NULL
)
11484 sections
->line
.s
.section
= sectp
;
11485 sections
->line
.size
= bfd_section_size (sectp
);
11487 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
11489 /* There can be only one. */
11490 if (sections
->loc
.s
.section
!= NULL
)
11492 sections
->loc
.s
.section
= sectp
;
11493 sections
->loc
.size
= bfd_section_size (sectp
);
11495 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
11497 /* There can be only one. */
11498 if (sections
->macinfo
.s
.section
!= NULL
)
11500 sections
->macinfo
.s
.section
= sectp
;
11501 sections
->macinfo
.size
= bfd_section_size (sectp
);
11503 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
11505 /* There can be only one. */
11506 if (sections
->macro
.s
.section
!= NULL
)
11508 sections
->macro
.s
.section
= sectp
;
11509 sections
->macro
.size
= bfd_section_size (sectp
);
11511 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
11513 /* There can be only one. */
11514 if (sections
->str_offsets
.s
.section
!= NULL
)
11516 sections
->str_offsets
.s
.section
= sectp
;
11517 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11521 /* No other kind of section is valid. */
11528 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11529 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11530 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11531 This is for DWP version 1 files. */
11533 static struct dwo_unit
*
11534 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11535 struct dwp_file
*dwp_file
,
11536 uint32_t unit_index
,
11537 const char *comp_dir
,
11538 ULONGEST signature
, int is_debug_types
)
11540 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11541 const struct dwp_hash_table
*dwp_htab
=
11542 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11543 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11544 const char *kind
= is_debug_types
? "TU" : "CU";
11545 struct dwo_file
*dwo_file
;
11546 struct dwo_unit
*dwo_unit
;
11547 struct virtual_v1_dwo_sections sections
;
11548 void **dwo_file_slot
;
11551 gdb_assert (dwp_file
->version
== 1);
11553 if (dwarf_read_debug
)
11555 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
11557 pulongest (unit_index
), hex_string (signature
),
11561 /* Fetch the sections of this DWO unit.
11562 Put a limit on the number of sections we look for so that bad data
11563 doesn't cause us to loop forever. */
11565 #define MAX_NR_V1_DWO_SECTIONS \
11566 (1 /* .debug_info or .debug_types */ \
11567 + 1 /* .debug_abbrev */ \
11568 + 1 /* .debug_line */ \
11569 + 1 /* .debug_loc */ \
11570 + 1 /* .debug_str_offsets */ \
11571 + 1 /* .debug_macro or .debug_macinfo */ \
11572 + 1 /* trailing zero */)
11574 memset (§ions
, 0, sizeof (sections
));
11576 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
11579 uint32_t section_nr
=
11580 read_4_bytes (dbfd
,
11581 dwp_htab
->section_pool
.v1
.indices
11582 + (unit_index
+ i
) * sizeof (uint32_t));
11584 if (section_nr
== 0)
11586 if (section_nr
>= dwp_file
->num_sections
)
11588 error (_("Dwarf Error: bad DWP hash table, section number too large"
11589 " [in module %s]"),
11593 sectp
= dwp_file
->elf_sections
[section_nr
];
11594 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
11596 error (_("Dwarf Error: bad DWP hash table, invalid section found"
11597 " [in module %s]"),
11603 || sections
.info_or_types
.empty ()
11604 || sections
.abbrev
.empty ())
11606 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
11607 " [in module %s]"),
11610 if (i
== MAX_NR_V1_DWO_SECTIONS
)
11612 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
11613 " [in module %s]"),
11617 /* It's easier for the rest of the code if we fake a struct dwo_file and
11618 have dwo_unit "live" in that. At least for now.
11620 The DWP file can be made up of a random collection of CUs and TUs.
11621 However, for each CU + set of TUs that came from the same original DWO
11622 file, we can combine them back into a virtual DWO file to save space
11623 (fewer struct dwo_file objects to allocate). Remember that for really
11624 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11626 std::string virtual_dwo_name
=
11627 string_printf ("virtual-dwo/%d-%d-%d-%d",
11628 sections
.abbrev
.get_id (),
11629 sections
.line
.get_id (),
11630 sections
.loc
.get_id (),
11631 sections
.str_offsets
.get_id ());
11632 /* Can we use an existing virtual DWO file? */
11633 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
11634 virtual_dwo_name
.c_str (),
11636 /* Create one if necessary. */
11637 if (*dwo_file_slot
== NULL
)
11639 if (dwarf_read_debug
)
11641 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11642 virtual_dwo_name
.c_str ());
11644 dwo_file
= new struct dwo_file
;
11645 dwo_file
->dwo_name
= obstack_strdup (&objfile
->objfile_obstack
,
11647 dwo_file
->comp_dir
= comp_dir
;
11648 dwo_file
->sections
.abbrev
= sections
.abbrev
;
11649 dwo_file
->sections
.line
= sections
.line
;
11650 dwo_file
->sections
.loc
= sections
.loc
;
11651 dwo_file
->sections
.macinfo
= sections
.macinfo
;
11652 dwo_file
->sections
.macro
= sections
.macro
;
11653 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
11654 /* The "str" section is global to the entire DWP file. */
11655 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11656 /* The info or types section is assigned below to dwo_unit,
11657 there's no need to record it in dwo_file.
11658 Also, we can't simply record type sections in dwo_file because
11659 we record a pointer into the vector in dwo_unit. As we collect more
11660 types we'll grow the vector and eventually have to reallocate space
11661 for it, invalidating all copies of pointers into the previous
11663 *dwo_file_slot
= dwo_file
;
11667 if (dwarf_read_debug
)
11669 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11670 virtual_dwo_name
.c_str ());
11672 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11675 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11676 dwo_unit
->dwo_file
= dwo_file
;
11677 dwo_unit
->signature
= signature
;
11678 dwo_unit
->section
=
11679 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
11680 *dwo_unit
->section
= sections
.info_or_types
;
11681 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11686 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
11687 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
11688 piece within that section used by a TU/CU, return a virtual section
11689 of just that piece. */
11691 static struct dwarf2_section_info
11692 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11693 struct dwarf2_section_info
*section
,
11694 bfd_size_type offset
, bfd_size_type size
)
11696 struct dwarf2_section_info result
;
11699 gdb_assert (section
!= NULL
);
11700 gdb_assert (!section
->is_virtual
);
11702 memset (&result
, 0, sizeof (result
));
11703 result
.s
.containing_section
= section
;
11704 result
.is_virtual
= true;
11709 sectp
= section
->get_bfd_section ();
11711 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
11712 bounds of the real section. This is a pretty-rare event, so just
11713 flag an error (easier) instead of a warning and trying to cope. */
11715 || offset
+ size
> bfd_section_size (sectp
))
11717 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
11718 " in section %s [in module %s]"),
11719 sectp
? bfd_section_name (sectp
) : "<unknown>",
11720 objfile_name (dwarf2_per_objfile
->objfile
));
11723 result
.virtual_offset
= offset
;
11724 result
.size
= size
;
11728 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11729 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11730 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11731 This is for DWP version 2 files. */
11733 static struct dwo_unit
*
11734 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11735 struct dwp_file
*dwp_file
,
11736 uint32_t unit_index
,
11737 const char *comp_dir
,
11738 ULONGEST signature
, int is_debug_types
)
11740 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11741 const struct dwp_hash_table
*dwp_htab
=
11742 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11743 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11744 const char *kind
= is_debug_types
? "TU" : "CU";
11745 struct dwo_file
*dwo_file
;
11746 struct dwo_unit
*dwo_unit
;
11747 struct virtual_v2_dwo_sections sections
;
11748 void **dwo_file_slot
;
11751 gdb_assert (dwp_file
->version
== 2);
11753 if (dwarf_read_debug
)
11755 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
11757 pulongest (unit_index
), hex_string (signature
),
11761 /* Fetch the section offsets of this DWO unit. */
11763 memset (§ions
, 0, sizeof (sections
));
11765 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11767 uint32_t offset
= read_4_bytes (dbfd
,
11768 dwp_htab
->section_pool
.v2
.offsets
11769 + (((unit_index
- 1) * dwp_htab
->nr_columns
11771 * sizeof (uint32_t)));
11772 uint32_t size
= read_4_bytes (dbfd
,
11773 dwp_htab
->section_pool
.v2
.sizes
11774 + (((unit_index
- 1) * dwp_htab
->nr_columns
11776 * sizeof (uint32_t)));
11778 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
11781 case DW_SECT_TYPES
:
11782 sections
.info_or_types_offset
= offset
;
11783 sections
.info_or_types_size
= size
;
11785 case DW_SECT_ABBREV
:
11786 sections
.abbrev_offset
= offset
;
11787 sections
.abbrev_size
= size
;
11790 sections
.line_offset
= offset
;
11791 sections
.line_size
= size
;
11794 sections
.loc_offset
= offset
;
11795 sections
.loc_size
= size
;
11797 case DW_SECT_STR_OFFSETS
:
11798 sections
.str_offsets_offset
= offset
;
11799 sections
.str_offsets_size
= size
;
11801 case DW_SECT_MACINFO
:
11802 sections
.macinfo_offset
= offset
;
11803 sections
.macinfo_size
= size
;
11805 case DW_SECT_MACRO
:
11806 sections
.macro_offset
= offset
;
11807 sections
.macro_size
= size
;
11812 /* It's easier for the rest of the code if we fake a struct dwo_file and
11813 have dwo_unit "live" in that. At least for now.
11815 The DWP file can be made up of a random collection of CUs and TUs.
11816 However, for each CU + set of TUs that came from the same original DWO
11817 file, we can combine them back into a virtual DWO file to save space
11818 (fewer struct dwo_file objects to allocate). Remember that for really
11819 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11821 std::string virtual_dwo_name
=
11822 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
11823 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
11824 (long) (sections
.line_size
? sections
.line_offset
: 0),
11825 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
11826 (long) (sections
.str_offsets_size
11827 ? sections
.str_offsets_offset
: 0));
11828 /* Can we use an existing virtual DWO file? */
11829 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
11830 virtual_dwo_name
.c_str (),
11832 /* Create one if necessary. */
11833 if (*dwo_file_slot
== NULL
)
11835 if (dwarf_read_debug
)
11837 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11838 virtual_dwo_name
.c_str ());
11840 dwo_file
= new struct dwo_file
;
11841 dwo_file
->dwo_name
= obstack_strdup (&objfile
->objfile_obstack
,
11843 dwo_file
->comp_dir
= comp_dir
;
11844 dwo_file
->sections
.abbrev
=
11845 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
11846 sections
.abbrev_offset
, sections
.abbrev_size
);
11847 dwo_file
->sections
.line
=
11848 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
11849 sections
.line_offset
, sections
.line_size
);
11850 dwo_file
->sections
.loc
=
11851 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
11852 sections
.loc_offset
, sections
.loc_size
);
11853 dwo_file
->sections
.macinfo
=
11854 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
11855 sections
.macinfo_offset
, sections
.macinfo_size
);
11856 dwo_file
->sections
.macro
=
11857 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
11858 sections
.macro_offset
, sections
.macro_size
);
11859 dwo_file
->sections
.str_offsets
=
11860 create_dwp_v2_section (dwarf2_per_objfile
,
11861 &dwp_file
->sections
.str_offsets
,
11862 sections
.str_offsets_offset
,
11863 sections
.str_offsets_size
);
11864 /* The "str" section is global to the entire DWP file. */
11865 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11866 /* The info or types section is assigned below to dwo_unit,
11867 there's no need to record it in dwo_file.
11868 Also, we can't simply record type sections in dwo_file because
11869 we record a pointer into the vector in dwo_unit. As we collect more
11870 types we'll grow the vector and eventually have to reallocate space
11871 for it, invalidating all copies of pointers into the previous
11873 *dwo_file_slot
= dwo_file
;
11877 if (dwarf_read_debug
)
11879 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11880 virtual_dwo_name
.c_str ());
11882 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11885 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11886 dwo_unit
->dwo_file
= dwo_file
;
11887 dwo_unit
->signature
= signature
;
11888 dwo_unit
->section
=
11889 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
11890 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
11892 ? &dwp_file
->sections
.types
11893 : &dwp_file
->sections
.info
,
11894 sections
.info_or_types_offset
,
11895 sections
.info_or_types_size
);
11896 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11901 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
11902 Returns NULL if the signature isn't found. */
11904 static struct dwo_unit
*
11905 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11906 struct dwp_file
*dwp_file
, const char *comp_dir
,
11907 ULONGEST signature
, int is_debug_types
)
11909 const struct dwp_hash_table
*dwp_htab
=
11910 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11911 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11912 uint32_t mask
= dwp_htab
->nr_slots
- 1;
11913 uint32_t hash
= signature
& mask
;
11914 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
11917 struct dwo_unit find_dwo_cu
;
11919 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
11920 find_dwo_cu
.signature
= signature
;
11921 slot
= htab_find_slot (is_debug_types
11922 ? dwp_file
->loaded_tus
.get ()
11923 : dwp_file
->loaded_cus
.get (),
11924 &find_dwo_cu
, INSERT
);
11927 return (struct dwo_unit
*) *slot
;
11929 /* Use a for loop so that we don't loop forever on bad debug info. */
11930 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
11932 ULONGEST signature_in_table
;
11934 signature_in_table
=
11935 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
11936 if (signature_in_table
== signature
)
11938 uint32_t unit_index
=
11939 read_4_bytes (dbfd
,
11940 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
11942 if (dwp_file
->version
== 1)
11944 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
11945 dwp_file
, unit_index
,
11946 comp_dir
, signature
,
11951 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
11952 dwp_file
, unit_index
,
11953 comp_dir
, signature
,
11956 return (struct dwo_unit
*) *slot
;
11958 if (signature_in_table
== 0)
11960 hash
= (hash
+ hash2
) & mask
;
11963 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
11964 " [in module %s]"),
11968 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
11969 Open the file specified by FILE_NAME and hand it off to BFD for
11970 preliminary analysis. Return a newly initialized bfd *, which
11971 includes a canonicalized copy of FILE_NAME.
11972 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
11973 SEARCH_CWD is true if the current directory is to be searched.
11974 It will be searched before debug-file-directory.
11975 If successful, the file is added to the bfd include table of the
11976 objfile's bfd (see gdb_bfd_record_inclusion).
11977 If unable to find/open the file, return NULL.
11978 NOTE: This function is derived from symfile_bfd_open. */
11980 static gdb_bfd_ref_ptr
11981 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11982 const char *file_name
, int is_dwp
, int search_cwd
)
11985 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
11986 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
11987 to debug_file_directory. */
11988 const char *search_path
;
11989 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
11991 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
11994 if (*debug_file_directory
!= '\0')
11996 search_path_holder
.reset (concat (".", dirname_separator_string
,
11997 debug_file_directory
,
11999 search_path
= search_path_holder
.get ();
12005 search_path
= debug_file_directory
;
12007 openp_flags flags
= OPF_RETURN_REALPATH
;
12009 flags
|= OPF_SEARCH_IN_PATH
;
12011 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12012 desc
= openp (search_path
, flags
, file_name
,
12013 O_RDONLY
| O_BINARY
, &absolute_name
);
12017 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12019 if (sym_bfd
== NULL
)
12021 bfd_set_cacheable (sym_bfd
.get (), 1);
12023 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12026 /* Success. Record the bfd as having been included by the objfile's bfd.
12027 This is important because things like demangled_names_hash lives in the
12028 objfile's per_bfd space and may have references to things like symbol
12029 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12030 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12035 /* Try to open DWO file FILE_NAME.
12036 COMP_DIR is the DW_AT_comp_dir attribute.
12037 The result is the bfd handle of the file.
12038 If there is a problem finding or opening the file, return NULL.
12039 Upon success, the canonicalized path of the file is stored in the bfd,
12040 same as symfile_bfd_open. */
12042 static gdb_bfd_ref_ptr
12043 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12044 const char *file_name
, const char *comp_dir
)
12046 if (IS_ABSOLUTE_PATH (file_name
))
12047 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12048 0 /*is_dwp*/, 0 /*search_cwd*/);
12050 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12052 if (comp_dir
!= NULL
)
12054 gdb::unique_xmalloc_ptr
<char> path_to_try
12055 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12057 /* NOTE: If comp_dir is a relative path, this will also try the
12058 search path, which seems useful. */
12059 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
12060 path_to_try
.get (),
12062 1 /*search_cwd*/));
12067 /* That didn't work, try debug-file-directory, which, despite its name,
12068 is a list of paths. */
12070 if (*debug_file_directory
== '\0')
12073 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12074 0 /*is_dwp*/, 1 /*search_cwd*/);
12077 /* This function is mapped across the sections and remembers the offset and
12078 size of each of the DWO debugging sections we are interested in. */
12081 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12083 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12084 const struct dwop_section_names
*names
= &dwop_section_names
;
12086 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12088 dwo_sections
->abbrev
.s
.section
= sectp
;
12089 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12091 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12093 dwo_sections
->info
.s
.section
= sectp
;
12094 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12096 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12098 dwo_sections
->line
.s
.section
= sectp
;
12099 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12101 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12103 dwo_sections
->loc
.s
.section
= sectp
;
12104 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12106 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12108 dwo_sections
->macinfo
.s
.section
= sectp
;
12109 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12111 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12113 dwo_sections
->macro
.s
.section
= sectp
;
12114 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12116 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12118 dwo_sections
->str
.s
.section
= sectp
;
12119 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12121 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12123 dwo_sections
->str_offsets
.s
.section
= sectp
;
12124 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12126 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12128 struct dwarf2_section_info type_section
;
12130 memset (&type_section
, 0, sizeof (type_section
));
12131 type_section
.s
.section
= sectp
;
12132 type_section
.size
= bfd_section_size (sectp
);
12133 dwo_sections
->types
.push_back (type_section
);
12137 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12138 by PER_CU. This is for the non-DWP case.
12139 The result is NULL if DWO_NAME can't be found. */
12141 static struct dwo_file
*
12142 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
12143 const char *dwo_name
, const char *comp_dir
)
12145 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
12147 gdb_bfd_ref_ptr dbfd
= open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
);
12150 if (dwarf_read_debug
)
12151 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
12155 dwo_file_up
dwo_file (new struct dwo_file
);
12156 dwo_file
->dwo_name
= dwo_name
;
12157 dwo_file
->comp_dir
= comp_dir
;
12158 dwo_file
->dbfd
= std::move (dbfd
);
12160 bfd_map_over_sections (dwo_file
->dbfd
.get (), dwarf2_locate_dwo_sections
,
12161 &dwo_file
->sections
);
12163 create_cus_hash_table (dwarf2_per_objfile
, per_cu
->cu
, *dwo_file
,
12164 dwo_file
->sections
.info
, dwo_file
->cus
);
12166 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
.get (),
12167 dwo_file
->sections
.types
, dwo_file
->tus
);
12169 if (dwarf_read_debug
)
12170 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
12172 return dwo_file
.release ();
12175 /* This function is mapped across the sections and remembers the offset and
12176 size of each of the DWP debugging sections common to version 1 and 2 that
12177 we are interested in. */
12180 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12181 void *dwp_file_ptr
)
12183 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12184 const struct dwop_section_names
*names
= &dwop_section_names
;
12185 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12187 /* Record the ELF section number for later lookup: this is what the
12188 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12189 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12190 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12192 /* Look for specific sections that we need. */
12193 if (section_is_p (sectp
->name
, &names
->str_dwo
))
12195 dwp_file
->sections
.str
.s
.section
= sectp
;
12196 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12198 else if (section_is_p (sectp
->name
, &names
->cu_index
))
12200 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12201 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12203 else if (section_is_p (sectp
->name
, &names
->tu_index
))
12205 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12206 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12210 /* This function is mapped across the sections and remembers the offset and
12211 size of each of the DWP version 2 debugging sections that we are interested
12212 in. This is split into a separate function because we don't know if we
12213 have version 1 or 2 until we parse the cu_index/tu_index sections. */
12216 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12218 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12219 const struct dwop_section_names
*names
= &dwop_section_names
;
12220 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12222 /* Record the ELF section number for later lookup: this is what the
12223 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12224 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12225 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12227 /* Look for specific sections that we need. */
12228 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12230 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12231 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12233 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12235 dwp_file
->sections
.info
.s
.section
= sectp
;
12236 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12238 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12240 dwp_file
->sections
.line
.s
.section
= sectp
;
12241 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12243 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12245 dwp_file
->sections
.loc
.s
.section
= sectp
;
12246 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12248 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12250 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12251 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12253 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12255 dwp_file
->sections
.macro
.s
.section
= sectp
;
12256 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12258 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12260 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12261 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12263 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12265 dwp_file
->sections
.types
.s
.section
= sectp
;
12266 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12270 /* Hash function for dwp_file loaded CUs/TUs. */
12273 hash_dwp_loaded_cutus (const void *item
)
12275 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12277 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12278 return dwo_unit
->signature
;
12281 /* Equality function for dwp_file loaded CUs/TUs. */
12284 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12286 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12287 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12289 return dua
->signature
== dub
->signature
;
12292 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12295 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
12297 return htab_up (htab_create_alloc (3,
12298 hash_dwp_loaded_cutus
,
12299 eq_dwp_loaded_cutus
,
12300 NULL
, xcalloc
, xfree
));
12303 /* Try to open DWP file FILE_NAME.
12304 The result is the bfd handle of the file.
12305 If there is a problem finding or opening the file, return NULL.
12306 Upon success, the canonicalized path of the file is stored in the bfd,
12307 same as symfile_bfd_open. */
12309 static gdb_bfd_ref_ptr
12310 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12311 const char *file_name
)
12313 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12315 1 /*search_cwd*/));
12319 /* Work around upstream bug 15652.
12320 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12321 [Whether that's a "bug" is debatable, but it is getting in our way.]
12322 We have no real idea where the dwp file is, because gdb's realpath-ing
12323 of the executable's path may have discarded the needed info.
12324 [IWBN if the dwp file name was recorded in the executable, akin to
12325 .gnu_debuglink, but that doesn't exist yet.]
12326 Strip the directory from FILE_NAME and search again. */
12327 if (*debug_file_directory
!= '\0')
12329 /* Don't implicitly search the current directory here.
12330 If the user wants to search "." to handle this case,
12331 it must be added to debug-file-directory. */
12332 return try_open_dwop_file (dwarf2_per_objfile
,
12333 lbasename (file_name
), 1 /*is_dwp*/,
12340 /* Initialize the use of the DWP file for the current objfile.
12341 By convention the name of the DWP file is ${objfile}.dwp.
12342 The result is NULL if it can't be found. */
12344 static std::unique_ptr
<struct dwp_file
>
12345 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12347 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12349 /* Try to find first .dwp for the binary file before any symbolic links
12352 /* If the objfile is a debug file, find the name of the real binary
12353 file and get the name of dwp file from there. */
12354 std::string dwp_name
;
12355 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
12357 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
12358 const char *backlink_basename
= lbasename (backlink
->original_name
);
12360 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
12363 dwp_name
= objfile
->original_name
;
12365 dwp_name
+= ".dwp";
12367 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
12369 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
12371 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
12372 dwp_name
= objfile_name (objfile
);
12373 dwp_name
+= ".dwp";
12374 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
12379 if (dwarf_read_debug
)
12380 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
12381 return std::unique_ptr
<dwp_file
> ();
12384 const char *name
= bfd_get_filename (dbfd
.get ());
12385 std::unique_ptr
<struct dwp_file
> dwp_file
12386 (new struct dwp_file (name
, std::move (dbfd
)));
12388 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
12389 dwp_file
->elf_sections
=
12390 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
12391 dwp_file
->num_sections
, asection
*);
12393 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12394 dwarf2_locate_common_dwp_sections
,
12397 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12400 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12403 /* The DWP file version is stored in the hash table. Oh well. */
12404 if (dwp_file
->cus
&& dwp_file
->tus
12405 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
12407 /* Technically speaking, we should try to limp along, but this is
12408 pretty bizarre. We use pulongest here because that's the established
12409 portability solution (e.g, we cannot use %u for uint32_t). */
12410 error (_("Dwarf Error: DWP file CU version %s doesn't match"
12411 " TU version %s [in DWP file %s]"),
12412 pulongest (dwp_file
->cus
->version
),
12413 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
12417 dwp_file
->version
= dwp_file
->cus
->version
;
12418 else if (dwp_file
->tus
)
12419 dwp_file
->version
= dwp_file
->tus
->version
;
12421 dwp_file
->version
= 2;
12423 if (dwp_file
->version
== 2)
12424 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12425 dwarf2_locate_v2_dwp_sections
,
12428 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table (objfile
);
12429 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table (objfile
);
12431 if (dwarf_read_debug
)
12433 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
12434 fprintf_unfiltered (gdb_stdlog
,
12435 " %s CUs, %s TUs\n",
12436 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
12437 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
12443 /* Wrapper around open_and_init_dwp_file, only open it once. */
12445 static struct dwp_file
*
12446 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12448 if (! dwarf2_per_objfile
->dwp_checked
)
12450 dwarf2_per_objfile
->dwp_file
12451 = open_and_init_dwp_file (dwarf2_per_objfile
);
12452 dwarf2_per_objfile
->dwp_checked
= 1;
12454 return dwarf2_per_objfile
->dwp_file
.get ();
12457 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
12458 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
12459 or in the DWP file for the objfile, referenced by THIS_UNIT.
12460 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
12461 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
12463 This is called, for example, when wanting to read a variable with a
12464 complex location. Therefore we don't want to do file i/o for every call.
12465 Therefore we don't want to look for a DWO file on every call.
12466 Therefore we first see if we've already seen SIGNATURE in a DWP file,
12467 then we check if we've already seen DWO_NAME, and only THEN do we check
12470 The result is a pointer to the dwo_unit object or NULL if we didn't find it
12471 (dwo_id mismatch or couldn't find the DWO/DWP file). */
12473 static struct dwo_unit
*
12474 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
12475 const char *dwo_name
, const char *comp_dir
,
12476 ULONGEST signature
, int is_debug_types
)
12478 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_unit
->dwarf2_per_objfile
;
12479 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12480 const char *kind
= is_debug_types
? "TU" : "CU";
12481 void **dwo_file_slot
;
12482 struct dwo_file
*dwo_file
;
12483 struct dwp_file
*dwp_file
;
12485 /* First see if there's a DWP file.
12486 If we have a DWP file but didn't find the DWO inside it, don't
12487 look for the original DWO file. It makes gdb behave differently
12488 depending on whether one is debugging in the build tree. */
12490 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
12491 if (dwp_file
!= NULL
)
12493 const struct dwp_hash_table
*dwp_htab
=
12494 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12496 if (dwp_htab
!= NULL
)
12498 struct dwo_unit
*dwo_cutu
=
12499 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
12500 signature
, is_debug_types
);
12502 if (dwo_cutu
!= NULL
)
12504 if (dwarf_read_debug
)
12506 fprintf_unfiltered (gdb_stdlog
,
12507 "Virtual DWO %s %s found: @%s\n",
12508 kind
, hex_string (signature
),
12509 host_address_to_string (dwo_cutu
));
12517 /* No DWP file, look for the DWO file. */
12519 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12520 dwo_name
, comp_dir
);
12521 if (*dwo_file_slot
== NULL
)
12523 /* Read in the file and build a table of the CUs/TUs it contains. */
12524 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
12526 /* NOTE: This will be NULL if unable to open the file. */
12527 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12529 if (dwo_file
!= NULL
)
12531 struct dwo_unit
*dwo_cutu
= NULL
;
12533 if (is_debug_types
&& dwo_file
->tus
)
12535 struct dwo_unit find_dwo_cutu
;
12537 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12538 find_dwo_cutu
.signature
= signature
;
12540 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
12543 else if (!is_debug_types
&& dwo_file
->cus
)
12545 struct dwo_unit find_dwo_cutu
;
12547 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12548 find_dwo_cutu
.signature
= signature
;
12549 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
12553 if (dwo_cutu
!= NULL
)
12555 if (dwarf_read_debug
)
12557 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
12558 kind
, dwo_name
, hex_string (signature
),
12559 host_address_to_string (dwo_cutu
));
12566 /* We didn't find it. This could mean a dwo_id mismatch, or
12567 someone deleted the DWO/DWP file, or the search path isn't set up
12568 correctly to find the file. */
12570 if (dwarf_read_debug
)
12572 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
12573 kind
, dwo_name
, hex_string (signature
));
12576 /* This is a warning and not a complaint because it can be caused by
12577 pilot error (e.g., user accidentally deleting the DWO). */
12579 /* Print the name of the DWP file if we looked there, helps the user
12580 better diagnose the problem. */
12581 std::string dwp_text
;
12583 if (dwp_file
!= NULL
)
12584 dwp_text
= string_printf (" [in DWP file %s]",
12585 lbasename (dwp_file
->name
));
12587 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
12588 " [in module %s]"),
12589 kind
, dwo_name
, hex_string (signature
),
12591 this_unit
->is_debug_types
? "TU" : "CU",
12592 sect_offset_str (this_unit
->sect_off
), objfile_name (objfile
));
12597 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
12598 See lookup_dwo_cutu_unit for details. */
12600 static struct dwo_unit
*
12601 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
12602 const char *dwo_name
, const char *comp_dir
,
12603 ULONGEST signature
)
12605 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
12608 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
12609 See lookup_dwo_cutu_unit for details. */
12611 static struct dwo_unit
*
12612 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
12613 const char *dwo_name
, const char *comp_dir
)
12615 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
12618 /* Traversal function for queue_and_load_all_dwo_tus. */
12621 queue_and_load_dwo_tu (void **slot
, void *info
)
12623 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
12624 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
12625 ULONGEST signature
= dwo_unit
->signature
;
12626 struct signatured_type
*sig_type
=
12627 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
12629 if (sig_type
!= NULL
)
12631 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
12633 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
12634 a real dependency of PER_CU on SIG_TYPE. That is detected later
12635 while processing PER_CU. */
12636 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
12637 load_full_type_unit (sig_cu
);
12638 per_cu
->imported_symtabs_push (sig_cu
);
12644 /* Queue all TUs contained in the DWO of PER_CU to be read in.
12645 The DWO may have the only definition of the type, though it may not be
12646 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
12647 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
12650 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
12652 struct dwo_unit
*dwo_unit
;
12653 struct dwo_file
*dwo_file
;
12655 gdb_assert (!per_cu
->is_debug_types
);
12656 gdb_assert (get_dwp_file (per_cu
->dwarf2_per_objfile
) == NULL
);
12657 gdb_assert (per_cu
->cu
!= NULL
);
12659 dwo_unit
= per_cu
->cu
->dwo_unit
;
12660 gdb_assert (dwo_unit
!= NULL
);
12662 dwo_file
= dwo_unit
->dwo_file
;
12663 if (dwo_file
->tus
!= NULL
)
12664 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
,
12668 /* Read in various DIEs. */
12670 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
12671 Inherit only the children of the DW_AT_abstract_origin DIE not being
12672 already referenced by DW_AT_abstract_origin from the children of the
12676 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
12678 struct die_info
*child_die
;
12679 sect_offset
*offsetp
;
12680 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
12681 struct die_info
*origin_die
;
12682 /* Iterator of the ORIGIN_DIE children. */
12683 struct die_info
*origin_child_die
;
12684 struct attribute
*attr
;
12685 struct dwarf2_cu
*origin_cu
;
12686 struct pending
**origin_previous_list_in_scope
;
12688 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
12692 /* Note that following die references may follow to a die in a
12696 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
12698 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
12700 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
12701 origin_cu
->list_in_scope
= cu
->list_in_scope
;
12703 if (die
->tag
!= origin_die
->tag
12704 && !(die
->tag
== DW_TAG_inlined_subroutine
12705 && origin_die
->tag
== DW_TAG_subprogram
))
12706 complaint (_("DIE %s and its abstract origin %s have different tags"),
12707 sect_offset_str (die
->sect_off
),
12708 sect_offset_str (origin_die
->sect_off
));
12710 std::vector
<sect_offset
> offsets
;
12712 for (child_die
= die
->child
;
12713 child_die
&& child_die
->tag
;
12714 child_die
= sibling_die (child_die
))
12716 struct die_info
*child_origin_die
;
12717 struct dwarf2_cu
*child_origin_cu
;
12719 /* We are trying to process concrete instance entries:
12720 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
12721 it's not relevant to our analysis here. i.e. detecting DIEs that are
12722 present in the abstract instance but not referenced in the concrete
12724 if (child_die
->tag
== DW_TAG_call_site
12725 || child_die
->tag
== DW_TAG_GNU_call_site
)
12728 /* For each CHILD_DIE, find the corresponding child of
12729 ORIGIN_DIE. If there is more than one layer of
12730 DW_AT_abstract_origin, follow them all; there shouldn't be,
12731 but GCC versions at least through 4.4 generate this (GCC PR
12733 child_origin_die
= child_die
;
12734 child_origin_cu
= cu
;
12737 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
12741 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
12745 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
12746 counterpart may exist. */
12747 if (child_origin_die
!= child_die
)
12749 if (child_die
->tag
!= child_origin_die
->tag
12750 && !(child_die
->tag
== DW_TAG_inlined_subroutine
12751 && child_origin_die
->tag
== DW_TAG_subprogram
))
12752 complaint (_("Child DIE %s and its abstract origin %s have "
12754 sect_offset_str (child_die
->sect_off
),
12755 sect_offset_str (child_origin_die
->sect_off
));
12756 if (child_origin_die
->parent
!= origin_die
)
12757 complaint (_("Child DIE %s and its abstract origin %s have "
12758 "different parents"),
12759 sect_offset_str (child_die
->sect_off
),
12760 sect_offset_str (child_origin_die
->sect_off
));
12762 offsets
.push_back (child_origin_die
->sect_off
);
12765 std::sort (offsets
.begin (), offsets
.end ());
12766 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
12767 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
12768 if (offsetp
[-1] == *offsetp
)
12769 complaint (_("Multiple children of DIE %s refer "
12770 "to DIE %s as their abstract origin"),
12771 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
12773 offsetp
= offsets
.data ();
12774 origin_child_die
= origin_die
->child
;
12775 while (origin_child_die
&& origin_child_die
->tag
)
12777 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
12778 while (offsetp
< offsets_end
12779 && *offsetp
< origin_child_die
->sect_off
)
12781 if (offsetp
>= offsets_end
12782 || *offsetp
> origin_child_die
->sect_off
)
12784 /* Found that ORIGIN_CHILD_DIE is really not referenced.
12785 Check whether we're already processing ORIGIN_CHILD_DIE.
12786 This can happen with mutually referenced abstract_origins.
12788 if (!origin_child_die
->in_process
)
12789 process_die (origin_child_die
, origin_cu
);
12791 origin_child_die
= sibling_die (origin_child_die
);
12793 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
12795 if (cu
!= origin_cu
)
12796 compute_delayed_physnames (origin_cu
);
12800 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12802 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
12803 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12804 struct context_stack
*newobj
;
12807 struct die_info
*child_die
;
12808 struct attribute
*attr
, *call_line
, *call_file
;
12810 CORE_ADDR baseaddr
;
12811 struct block
*block
;
12812 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
12813 std::vector
<struct symbol
*> template_args
;
12814 struct template_symbol
*templ_func
= NULL
;
12818 /* If we do not have call site information, we can't show the
12819 caller of this inlined function. That's too confusing, so
12820 only use the scope for local variables. */
12821 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
12822 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
12823 if (call_line
== NULL
|| call_file
== NULL
)
12825 read_lexical_block_scope (die
, cu
);
12830 baseaddr
= objfile
->text_section_offset ();
12832 name
= dwarf2_name (die
, cu
);
12834 /* Ignore functions with missing or empty names. These are actually
12835 illegal according to the DWARF standard. */
12838 complaint (_("missing name for subprogram DIE at %s"),
12839 sect_offset_str (die
->sect_off
));
12843 /* Ignore functions with missing or invalid low and high pc attributes. */
12844 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
12845 <= PC_BOUNDS_INVALID
)
12847 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
12848 if (!attr
|| !DW_UNSND (attr
))
12849 complaint (_("cannot get low and high bounds "
12850 "for subprogram DIE at %s"),
12851 sect_offset_str (die
->sect_off
));
12855 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
12856 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
12858 /* If we have any template arguments, then we must allocate a
12859 different sort of symbol. */
12860 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
12862 if (child_die
->tag
== DW_TAG_template_type_param
12863 || child_die
->tag
== DW_TAG_template_value_param
)
12865 templ_func
= allocate_template_symbol (objfile
);
12866 templ_func
->subclass
= SYMBOL_TEMPLATE
;
12871 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
12872 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
12873 (struct symbol
*) templ_func
);
12875 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
12876 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
12879 /* If there is a location expression for DW_AT_frame_base, record
12881 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
12882 if (attr
!= nullptr)
12883 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
12885 /* If there is a location for the static link, record it. */
12886 newobj
->static_link
= NULL
;
12887 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
12888 if (attr
!= nullptr)
12890 newobj
->static_link
12891 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
12892 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
12893 cu
->per_cu
->addr_type ());
12896 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
12898 if (die
->child
!= NULL
)
12900 child_die
= die
->child
;
12901 while (child_die
&& child_die
->tag
)
12903 if (child_die
->tag
== DW_TAG_template_type_param
12904 || child_die
->tag
== DW_TAG_template_value_param
)
12906 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
12909 template_args
.push_back (arg
);
12912 process_die (child_die
, cu
);
12913 child_die
= sibling_die (child_die
);
12917 inherit_abstract_dies (die
, cu
);
12919 /* If we have a DW_AT_specification, we might need to import using
12920 directives from the context of the specification DIE. See the
12921 comment in determine_prefix. */
12922 if (cu
->language
== language_cplus
12923 && dwarf2_attr (die
, DW_AT_specification
, cu
))
12925 struct dwarf2_cu
*spec_cu
= cu
;
12926 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
12930 child_die
= spec_die
->child
;
12931 while (child_die
&& child_die
->tag
)
12933 if (child_die
->tag
== DW_TAG_imported_module
)
12934 process_die (child_die
, spec_cu
);
12935 child_die
= sibling_die (child_die
);
12938 /* In some cases, GCC generates specification DIEs that
12939 themselves contain DW_AT_specification attributes. */
12940 spec_die
= die_specification (spec_die
, &spec_cu
);
12944 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
12945 /* Make a block for the local symbols within. */
12946 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
12947 cstk
.static_link
, lowpc
, highpc
);
12949 /* For C++, set the block's scope. */
12950 if ((cu
->language
== language_cplus
12951 || cu
->language
== language_fortran
12952 || cu
->language
== language_d
12953 || cu
->language
== language_rust
)
12954 && cu
->processing_has_namespace_info
)
12955 block_set_scope (block
, determine_prefix (die
, cu
),
12956 &objfile
->objfile_obstack
);
12958 /* If we have address ranges, record them. */
12959 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
12961 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
12963 /* Attach template arguments to function. */
12964 if (!template_args
.empty ())
12966 gdb_assert (templ_func
!= NULL
);
12968 templ_func
->n_template_arguments
= template_args
.size ();
12969 templ_func
->template_arguments
12970 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
12971 templ_func
->n_template_arguments
);
12972 memcpy (templ_func
->template_arguments
,
12973 template_args
.data (),
12974 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
12976 /* Make sure that the symtab is set on the new symbols. Even
12977 though they don't appear in this symtab directly, other parts
12978 of gdb assume that symbols do, and this is reasonably
12980 for (symbol
*sym
: template_args
)
12981 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
12984 /* In C++, we can have functions nested inside functions (e.g., when
12985 a function declares a class that has methods). This means that
12986 when we finish processing a function scope, we may need to go
12987 back to building a containing block's symbol lists. */
12988 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
12989 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
12991 /* If we've finished processing a top-level function, subsequent
12992 symbols go in the file symbol list. */
12993 if (cu
->get_builder ()->outermost_context_p ())
12994 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
12997 /* Process all the DIES contained within a lexical block scope. Start
12998 a new scope, process the dies, and then close the scope. */
13001 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13003 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13004 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13005 CORE_ADDR lowpc
, highpc
;
13006 struct die_info
*child_die
;
13007 CORE_ADDR baseaddr
;
13009 baseaddr
= objfile
->text_section_offset ();
13011 /* Ignore blocks with missing or invalid low and high pc attributes. */
13012 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13013 as multiple lexical blocks? Handling children in a sane way would
13014 be nasty. Might be easier to properly extend generic blocks to
13015 describe ranges. */
13016 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13018 case PC_BOUNDS_NOT_PRESENT
:
13019 /* DW_TAG_lexical_block has no attributes, process its children as if
13020 there was no wrapping by that DW_TAG_lexical_block.
13021 GCC does no longer produces such DWARF since GCC r224161. */
13022 for (child_die
= die
->child
;
13023 child_die
!= NULL
&& child_die
->tag
;
13024 child_die
= sibling_die (child_die
))
13025 process_die (child_die
, cu
);
13027 case PC_BOUNDS_INVALID
:
13030 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13031 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13033 cu
->get_builder ()->push_context (0, lowpc
);
13034 if (die
->child
!= NULL
)
13036 child_die
= die
->child
;
13037 while (child_die
&& child_die
->tag
)
13039 process_die (child_die
, cu
);
13040 child_die
= sibling_die (child_die
);
13043 inherit_abstract_dies (die
, cu
);
13044 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13046 if (*cu
->get_builder ()->get_local_symbols () != NULL
13047 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13049 struct block
*block
13050 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13051 cstk
.start_addr
, highpc
);
13053 /* Note that recording ranges after traversing children, as we
13054 do here, means that recording a parent's ranges entails
13055 walking across all its children's ranges as they appear in
13056 the address map, which is quadratic behavior.
13058 It would be nicer to record the parent's ranges before
13059 traversing its children, simply overriding whatever you find
13060 there. But since we don't even decide whether to create a
13061 block until after we've traversed its children, that's hard
13063 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13065 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13066 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13069 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13072 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13074 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13075 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13076 CORE_ADDR pc
, baseaddr
;
13077 struct attribute
*attr
;
13078 struct call_site
*call_site
, call_site_local
;
13081 struct die_info
*child_die
;
13083 baseaddr
= objfile
->text_section_offset ();
13085 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13088 /* This was a pre-DWARF-5 GNU extension alias
13089 for DW_AT_call_return_pc. */
13090 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13094 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13095 "DIE %s [in module %s]"),
13096 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13099 pc
= attr
->value_as_address () + baseaddr
;
13100 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13102 if (cu
->call_site_htab
== NULL
)
13103 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13104 NULL
, &objfile
->objfile_obstack
,
13105 hashtab_obstack_allocate
, NULL
);
13106 call_site_local
.pc
= pc
;
13107 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13110 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13111 "DIE %s [in module %s]"),
13112 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13113 objfile_name (objfile
));
13117 /* Count parameters at the caller. */
13120 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13121 child_die
= sibling_die (child_die
))
13123 if (child_die
->tag
!= DW_TAG_call_site_parameter
13124 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13126 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13127 "DW_TAG_call_site child DIE %s [in module %s]"),
13128 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13129 objfile_name (objfile
));
13137 = ((struct call_site
*)
13138 obstack_alloc (&objfile
->objfile_obstack
,
13139 sizeof (*call_site
)
13140 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13142 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13143 call_site
->pc
= pc
;
13145 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13146 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13148 struct die_info
*func_die
;
13150 /* Skip also over DW_TAG_inlined_subroutine. */
13151 for (func_die
= die
->parent
;
13152 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13153 && func_die
->tag
!= DW_TAG_subroutine_type
;
13154 func_die
= func_die
->parent
);
13156 /* DW_AT_call_all_calls is a superset
13157 of DW_AT_call_all_tail_calls. */
13159 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13160 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13161 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13162 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13164 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13165 not complete. But keep CALL_SITE for look ups via call_site_htab,
13166 both the initial caller containing the real return address PC and
13167 the final callee containing the current PC of a chain of tail
13168 calls do not need to have the tail call list complete. But any
13169 function candidate for a virtual tail call frame searched via
13170 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13171 determined unambiguously. */
13175 struct type
*func_type
= NULL
;
13178 func_type
= get_die_type (func_die
, cu
);
13179 if (func_type
!= NULL
)
13181 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
13183 /* Enlist this call site to the function. */
13184 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13185 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13188 complaint (_("Cannot find function owning DW_TAG_call_site "
13189 "DIE %s [in module %s]"),
13190 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13194 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13196 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13198 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13201 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13202 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13204 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13205 if (!attr
|| (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0))
13206 /* Keep NULL DWARF_BLOCK. */;
13207 else if (attr
->form_is_block ())
13209 struct dwarf2_locexpr_baton
*dlbaton
;
13211 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13212 dlbaton
->data
= DW_BLOCK (attr
)->data
;
13213 dlbaton
->size
= DW_BLOCK (attr
)->size
;
13214 dlbaton
->per_cu
= cu
->per_cu
;
13216 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13218 else if (attr
->form_is_ref ())
13220 struct dwarf2_cu
*target_cu
= cu
;
13221 struct die_info
*target_die
;
13223 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13224 gdb_assert (target_cu
->per_cu
->dwarf2_per_objfile
->objfile
== objfile
);
13225 if (die_is_declaration (target_die
, target_cu
))
13227 const char *target_physname
;
13229 /* Prefer the mangled name; otherwise compute the demangled one. */
13230 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13231 if (target_physname
== NULL
)
13232 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13233 if (target_physname
== NULL
)
13234 complaint (_("DW_AT_call_target target DIE has invalid "
13235 "physname, for referencing DIE %s [in module %s]"),
13236 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13238 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13244 /* DW_AT_entry_pc should be preferred. */
13245 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13246 <= PC_BOUNDS_INVALID
)
13247 complaint (_("DW_AT_call_target target DIE has invalid "
13248 "low pc, for referencing DIE %s [in module %s]"),
13249 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13252 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13253 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
13258 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13259 "block nor reference, for DIE %s [in module %s]"),
13260 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13262 call_site
->per_cu
= cu
->per_cu
;
13264 for (child_die
= die
->child
;
13265 child_die
&& child_die
->tag
;
13266 child_die
= sibling_die (child_die
))
13268 struct call_site_parameter
*parameter
;
13269 struct attribute
*loc
, *origin
;
13271 if (child_die
->tag
!= DW_TAG_call_site_parameter
13272 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13274 /* Already printed the complaint above. */
13278 gdb_assert (call_site
->parameter_count
< nparams
);
13279 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13281 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13282 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13283 register is contained in DW_AT_call_value. */
13285 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13286 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13287 if (origin
== NULL
)
13289 /* This was a pre-DWARF-5 GNU extension alias
13290 for DW_AT_call_parameter. */
13291 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13293 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
13295 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13297 sect_offset sect_off
13298 = (sect_offset
) dwarf2_get_ref_die_offset (origin
);
13299 if (!cu
->header
.offset_in_cu_p (sect_off
))
13301 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13302 binding can be done only inside one CU. Such referenced DIE
13303 therefore cannot be even moved to DW_TAG_partial_unit. */
13304 complaint (_("DW_AT_call_parameter offset is not in CU for "
13305 "DW_TAG_call_site child DIE %s [in module %s]"),
13306 sect_offset_str (child_die
->sect_off
),
13307 objfile_name (objfile
));
13310 parameter
->u
.param_cu_off
13311 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13313 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
13315 complaint (_("No DW_FORM_block* DW_AT_location for "
13316 "DW_TAG_call_site child DIE %s [in module %s]"),
13317 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13322 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13323 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
13324 if (parameter
->u
.dwarf_reg
!= -1)
13325 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13326 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
13327 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
13328 ¶meter
->u
.fb_offset
))
13329 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13332 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13333 "for DW_FORM_block* DW_AT_location is supported for "
13334 "DW_TAG_call_site child DIE %s "
13336 sect_offset_str (child_die
->sect_off
),
13337 objfile_name (objfile
));
13342 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13344 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13345 if (attr
== NULL
|| !attr
->form_is_block ())
13347 complaint (_("No DW_FORM_block* DW_AT_call_value for "
13348 "DW_TAG_call_site child DIE %s [in module %s]"),
13349 sect_offset_str (child_die
->sect_off
),
13350 objfile_name (objfile
));
13353 parameter
->value
= DW_BLOCK (attr
)->data
;
13354 parameter
->value_size
= DW_BLOCK (attr
)->size
;
13356 /* Parameters are not pre-cleared by memset above. */
13357 parameter
->data_value
= NULL
;
13358 parameter
->data_value_size
= 0;
13359 call_site
->parameter_count
++;
13361 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
13363 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
13364 if (attr
!= nullptr)
13366 if (!attr
->form_is_block ())
13367 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
13368 "DW_TAG_call_site child DIE %s [in module %s]"),
13369 sect_offset_str (child_die
->sect_off
),
13370 objfile_name (objfile
));
13373 parameter
->data_value
= DW_BLOCK (attr
)->data
;
13374 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
13380 /* Helper function for read_variable. If DIE represents a virtual
13381 table, then return the type of the concrete object that is
13382 associated with the virtual table. Otherwise, return NULL. */
13384 static struct type
*
13385 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13387 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13391 /* Find the type DIE. */
13392 struct die_info
*type_die
= NULL
;
13393 struct dwarf2_cu
*type_cu
= cu
;
13395 if (attr
->form_is_ref ())
13396 type_die
= follow_die_ref (die
, attr
, &type_cu
);
13397 if (type_die
== NULL
)
13400 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
13402 return die_containing_type (type_die
, type_cu
);
13405 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
13408 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
13410 struct rust_vtable_symbol
*storage
= NULL
;
13412 if (cu
->language
== language_rust
)
13414 struct type
*containing_type
= rust_containing_type (die
, cu
);
13416 if (containing_type
!= NULL
)
13418 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13420 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol ();
13421 initialize_objfile_symbol (storage
);
13422 storage
->concrete_type
= containing_type
;
13423 storage
->subclass
= SYMBOL_RUST_VTABLE
;
13427 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
13428 struct attribute
*abstract_origin
13429 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13430 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
13431 if (res
== NULL
&& loc
&& abstract_origin
)
13433 /* We have a variable without a name, but with a location and an abstract
13434 origin. This may be a concrete instance of an abstract variable
13435 referenced from an DW_OP_GNU_variable_value, so save it to find it back
13437 struct dwarf2_cu
*origin_cu
= cu
;
13438 struct die_info
*origin_die
13439 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
13440 dwarf2_per_objfile
*dpo
= cu
->per_cu
->dwarf2_per_objfile
;
13441 dpo
->abstract_to_concrete
[origin_die
->sect_off
].push_back (die
->sect_off
);
13445 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
13446 reading .debug_rnglists.
13447 Callback's type should be:
13448 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13449 Return true if the attributes are present and valid, otherwise,
13452 template <typename Callback
>
13454 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
13455 Callback
&&callback
)
13457 struct dwarf2_per_objfile
*dwarf2_per_objfile
13458 = cu
->per_cu
->dwarf2_per_objfile
;
13459 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13460 bfd
*obfd
= objfile
->obfd
;
13461 /* Base address selection entry. */
13464 const gdb_byte
*buffer
;
13465 CORE_ADDR baseaddr
;
13466 bool overflow
= false;
13468 found_base
= cu
->base_known
;
13469 base
= cu
->base_address
;
13471 dwarf2_per_objfile
->rnglists
.read (objfile
);
13472 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
13474 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13478 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
13480 baseaddr
= objfile
->text_section_offset ();
13484 /* Initialize it due to a false compiler warning. */
13485 CORE_ADDR range_beginning
= 0, range_end
= 0;
13486 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
13487 + dwarf2_per_objfile
->rnglists
.size
);
13488 unsigned int bytes_read
;
13490 if (buffer
== buf_end
)
13495 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
13498 case DW_RLE_end_of_list
:
13500 case DW_RLE_base_address
:
13501 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13506 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13508 buffer
+= bytes_read
;
13510 case DW_RLE_start_length
:
13511 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13516 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13518 buffer
+= bytes_read
;
13519 range_end
= (range_beginning
13520 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13521 buffer
+= bytes_read
;
13522 if (buffer
> buf_end
)
13528 case DW_RLE_offset_pair
:
13529 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13530 buffer
+= bytes_read
;
13531 if (buffer
> buf_end
)
13536 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13537 buffer
+= bytes_read
;
13538 if (buffer
> buf_end
)
13544 case DW_RLE_start_end
:
13545 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
13550 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13552 buffer
+= bytes_read
;
13553 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13554 buffer
+= bytes_read
;
13557 complaint (_("Invalid .debug_rnglists data (no base address)"));
13560 if (rlet
== DW_RLE_end_of_list
|| overflow
)
13562 if (rlet
== DW_RLE_base_address
)
13567 /* We have no valid base address for the ranges
13569 complaint (_("Invalid .debug_rnglists data (no base address)"));
13573 if (range_beginning
> range_end
)
13575 /* Inverted range entries are invalid. */
13576 complaint (_("Invalid .debug_rnglists data (inverted range)"));
13580 /* Empty range entries have no effect. */
13581 if (range_beginning
== range_end
)
13584 range_beginning
+= base
;
13587 /* A not-uncommon case of bad debug info.
13588 Don't pollute the addrmap with bad data. */
13589 if (range_beginning
+ baseaddr
== 0
13590 && !dwarf2_per_objfile
->has_section_at_zero
)
13592 complaint (_(".debug_rnglists entry has start address of zero"
13593 " [in module %s]"), objfile_name (objfile
));
13597 callback (range_beginning
, range_end
);
13602 complaint (_("Offset %d is not terminated "
13603 "for DW_AT_ranges attribute"),
13611 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
13612 Callback's type should be:
13613 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13614 Return 1 if the attributes are present and valid, otherwise, return 0. */
13616 template <typename Callback
>
13618 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
13619 Callback
&&callback
)
13621 struct dwarf2_per_objfile
*dwarf2_per_objfile
13622 = cu
->per_cu
->dwarf2_per_objfile
;
13623 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13624 struct comp_unit_head
*cu_header
= &cu
->header
;
13625 bfd
*obfd
= objfile
->obfd
;
13626 unsigned int addr_size
= cu_header
->addr_size
;
13627 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
13628 /* Base address selection entry. */
13631 unsigned int dummy
;
13632 const gdb_byte
*buffer
;
13633 CORE_ADDR baseaddr
;
13635 if (cu_header
->version
>= 5)
13636 return dwarf2_rnglists_process (offset
, cu
, callback
);
13638 found_base
= cu
->base_known
;
13639 base
= cu
->base_address
;
13641 dwarf2_per_objfile
->ranges
.read (objfile
);
13642 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
13644 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13648 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
13650 baseaddr
= objfile
->text_section_offset ();
13654 CORE_ADDR range_beginning
, range_end
;
13656 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13657 buffer
+= addr_size
;
13658 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13659 buffer
+= addr_size
;
13660 offset
+= 2 * addr_size
;
13662 /* An end of list marker is a pair of zero addresses. */
13663 if (range_beginning
== 0 && range_end
== 0)
13664 /* Found the end of list entry. */
13667 /* Each base address selection entry is a pair of 2 values.
13668 The first is the largest possible address, the second is
13669 the base address. Check for a base address here. */
13670 if ((range_beginning
& mask
) == mask
)
13672 /* If we found the largest possible address, then we already
13673 have the base address in range_end. */
13681 /* We have no valid base address for the ranges
13683 complaint (_("Invalid .debug_ranges data (no base address)"));
13687 if (range_beginning
> range_end
)
13689 /* Inverted range entries are invalid. */
13690 complaint (_("Invalid .debug_ranges data (inverted range)"));
13694 /* Empty range entries have no effect. */
13695 if (range_beginning
== range_end
)
13698 range_beginning
+= base
;
13701 /* A not-uncommon case of bad debug info.
13702 Don't pollute the addrmap with bad data. */
13703 if (range_beginning
+ baseaddr
== 0
13704 && !dwarf2_per_objfile
->has_section_at_zero
)
13706 complaint (_(".debug_ranges entry has start address of zero"
13707 " [in module %s]"), objfile_name (objfile
));
13711 callback (range_beginning
, range_end
);
13717 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
13718 Return 1 if the attributes are present and valid, otherwise, return 0.
13719 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
13722 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
13723 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
13724 dwarf2_psymtab
*ranges_pst
)
13726 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13727 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13728 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
13731 CORE_ADDR high
= 0;
13734 retval
= dwarf2_ranges_process (offset
, cu
,
13735 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
13737 if (ranges_pst
!= NULL
)
13742 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13743 range_beginning
+ baseaddr
)
13745 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13746 range_end
+ baseaddr
)
13748 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
13749 lowpc
, highpc
- 1, ranges_pst
);
13752 /* FIXME: This is recording everything as a low-high
13753 segment of consecutive addresses. We should have a
13754 data structure for discontiguous block ranges
13758 low
= range_beginning
;
13764 if (range_beginning
< low
)
13765 low
= range_beginning
;
13766 if (range_end
> high
)
13774 /* If the first entry is an end-of-list marker, the range
13775 describes an empty scope, i.e. no instructions. */
13781 *high_return
= high
;
13785 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
13786 definition for the return value. *LOWPC and *HIGHPC are set iff
13787 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
13789 static enum pc_bounds_kind
13790 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
13791 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
13792 dwarf2_psymtab
*pst
)
13794 struct dwarf2_per_objfile
*dwarf2_per_objfile
13795 = cu
->per_cu
->dwarf2_per_objfile
;
13796 struct attribute
*attr
;
13797 struct attribute
*attr_high
;
13799 CORE_ADDR high
= 0;
13800 enum pc_bounds_kind ret
;
13802 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
13805 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13806 if (attr
!= nullptr)
13808 low
= attr
->value_as_address ();
13809 high
= attr_high
->value_as_address ();
13810 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
13814 /* Found high w/o low attribute. */
13815 return PC_BOUNDS_INVALID
;
13817 /* Found consecutive range of addresses. */
13818 ret
= PC_BOUNDS_HIGH_LOW
;
13822 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
13825 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
13826 We take advantage of the fact that DW_AT_ranges does not appear
13827 in DW_TAG_compile_unit of DWO files. */
13828 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
13829 unsigned int ranges_offset
= (DW_UNSND (attr
)
13830 + (need_ranges_base
13834 /* Value of the DW_AT_ranges attribute is the offset in the
13835 .debug_ranges section. */
13836 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
13837 return PC_BOUNDS_INVALID
;
13838 /* Found discontinuous range of addresses. */
13839 ret
= PC_BOUNDS_RANGES
;
13842 return PC_BOUNDS_NOT_PRESENT
;
13845 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
13847 return PC_BOUNDS_INVALID
;
13849 /* When using the GNU linker, .gnu.linkonce. sections are used to
13850 eliminate duplicate copies of functions and vtables and such.
13851 The linker will arbitrarily choose one and discard the others.
13852 The AT_*_pc values for such functions refer to local labels in
13853 these sections. If the section from that file was discarded, the
13854 labels are not in the output, so the relocs get a value of 0.
13855 If this is a discarded function, mark the pc bounds as invalid,
13856 so that GDB will ignore it. */
13857 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
13858 return PC_BOUNDS_INVALID
;
13866 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
13867 its low and high PC addresses. Do nothing if these addresses could not
13868 be determined. Otherwise, set LOWPC to the low address if it is smaller,
13869 and HIGHPC to the high address if greater than HIGHPC. */
13872 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
13873 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
13874 struct dwarf2_cu
*cu
)
13876 CORE_ADDR low
, high
;
13877 struct die_info
*child
= die
->child
;
13879 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
13881 *lowpc
= std::min (*lowpc
, low
);
13882 *highpc
= std::max (*highpc
, high
);
13885 /* If the language does not allow nested subprograms (either inside
13886 subprograms or lexical blocks), we're done. */
13887 if (cu
->language
!= language_ada
)
13890 /* Check all the children of the given DIE. If it contains nested
13891 subprograms, then check their pc bounds. Likewise, we need to
13892 check lexical blocks as well, as they may also contain subprogram
13894 while (child
&& child
->tag
)
13896 if (child
->tag
== DW_TAG_subprogram
13897 || child
->tag
== DW_TAG_lexical_block
)
13898 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
13899 child
= sibling_die (child
);
13903 /* Get the low and high pc's represented by the scope DIE, and store
13904 them in *LOWPC and *HIGHPC. If the correct values can't be
13905 determined, set *LOWPC to -1 and *HIGHPC to 0. */
13908 get_scope_pc_bounds (struct die_info
*die
,
13909 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
13910 struct dwarf2_cu
*cu
)
13912 CORE_ADDR best_low
= (CORE_ADDR
) -1;
13913 CORE_ADDR best_high
= (CORE_ADDR
) 0;
13914 CORE_ADDR current_low
, current_high
;
13916 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
13917 >= PC_BOUNDS_RANGES
)
13919 best_low
= current_low
;
13920 best_high
= current_high
;
13924 struct die_info
*child
= die
->child
;
13926 while (child
&& child
->tag
)
13928 switch (child
->tag
) {
13929 case DW_TAG_subprogram
:
13930 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
13932 case DW_TAG_namespace
:
13933 case DW_TAG_module
:
13934 /* FIXME: carlton/2004-01-16: Should we do this for
13935 DW_TAG_class_type/DW_TAG_structure_type, too? I think
13936 that current GCC's always emit the DIEs corresponding
13937 to definitions of methods of classes as children of a
13938 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
13939 the DIEs giving the declarations, which could be
13940 anywhere). But I don't see any reason why the
13941 standards says that they have to be there. */
13942 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
13944 if (current_low
!= ((CORE_ADDR
) -1))
13946 best_low
= std::min (best_low
, current_low
);
13947 best_high
= std::max (best_high
, current_high
);
13955 child
= sibling_die (child
);
13960 *highpc
= best_high
;
13963 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
13967 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
13968 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
13970 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13971 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13972 struct attribute
*attr
;
13973 struct attribute
*attr_high
;
13975 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
13978 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13979 if (attr
!= nullptr)
13981 CORE_ADDR low
= attr
->value_as_address ();
13982 CORE_ADDR high
= attr_high
->value_as_address ();
13984 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
13987 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
13988 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
13989 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
13993 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
13994 if (attr
!= nullptr)
13996 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
13997 We take advantage of the fact that DW_AT_ranges does not appear
13998 in DW_TAG_compile_unit of DWO files. */
13999 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14001 /* The value of the DW_AT_ranges attribute is the offset of the
14002 address range list in the .debug_ranges section. */
14003 unsigned long offset
= (DW_UNSND (attr
)
14004 + (need_ranges_base
? cu
->ranges_base
: 0));
14006 std::vector
<blockrange
> blockvec
;
14007 dwarf2_ranges_process (offset
, cu
,
14008 [&] (CORE_ADDR start
, CORE_ADDR end
)
14012 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14013 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14014 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14015 blockvec
.emplace_back (start
, end
);
14018 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14022 /* Check whether the producer field indicates either of GCC < 4.6, or the
14023 Intel C/C++ compiler, and cache the result in CU. */
14026 check_producer (struct dwarf2_cu
*cu
)
14030 if (cu
->producer
== NULL
)
14032 /* For unknown compilers expect their behavior is DWARF version
14035 GCC started to support .debug_types sections by -gdwarf-4 since
14036 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14037 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14038 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14039 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14041 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14043 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14044 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14046 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14048 cu
->producer_is_icc
= true;
14049 cu
->producer_is_icc_lt_14
= major
< 14;
14051 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14052 cu
->producer_is_codewarrior
= true;
14055 /* For other non-GCC compilers, expect their behavior is DWARF version
14059 cu
->checked_producer
= true;
14062 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14063 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14064 during 4.6.0 experimental. */
14067 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14069 if (!cu
->checked_producer
)
14070 check_producer (cu
);
14072 return cu
->producer_is_gxx_lt_4_6
;
14076 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14077 with incorrect is_stmt attributes. */
14080 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14082 if (!cu
->checked_producer
)
14083 check_producer (cu
);
14085 return cu
->producer_is_codewarrior
;
14088 /* Return the default accessibility type if it is not overridden by
14089 DW_AT_accessibility. */
14091 static enum dwarf_access_attribute
14092 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14094 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14096 /* The default DWARF 2 accessibility for members is public, the default
14097 accessibility for inheritance is private. */
14099 if (die
->tag
!= DW_TAG_inheritance
)
14100 return DW_ACCESS_public
;
14102 return DW_ACCESS_private
;
14106 /* DWARF 3+ defines the default accessibility a different way. The same
14107 rules apply now for DW_TAG_inheritance as for the members and it only
14108 depends on the container kind. */
14110 if (die
->parent
->tag
== DW_TAG_class_type
)
14111 return DW_ACCESS_private
;
14113 return DW_ACCESS_public
;
14117 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14118 offset. If the attribute was not found return 0, otherwise return
14119 1. If it was found but could not properly be handled, set *OFFSET
14123 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14126 struct attribute
*attr
;
14128 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14133 /* Note that we do not check for a section offset first here.
14134 This is because DW_AT_data_member_location is new in DWARF 4,
14135 so if we see it, we can assume that a constant form is really
14136 a constant and not a section offset. */
14137 if (attr
->form_is_constant ())
14138 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
14139 else if (attr
->form_is_section_offset ())
14140 dwarf2_complex_location_expr_complaint ();
14141 else if (attr
->form_is_block ())
14142 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14144 dwarf2_complex_location_expr_complaint ();
14152 /* Add an aggregate field to the field list. */
14155 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14156 struct dwarf2_cu
*cu
)
14158 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14159 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14160 struct nextfield
*new_field
;
14161 struct attribute
*attr
;
14163 const char *fieldname
= "";
14165 if (die
->tag
== DW_TAG_inheritance
)
14167 fip
->baseclasses
.emplace_back ();
14168 new_field
= &fip
->baseclasses
.back ();
14172 fip
->fields
.emplace_back ();
14173 new_field
= &fip
->fields
.back ();
14178 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14179 if (attr
!= nullptr)
14180 new_field
->accessibility
= DW_UNSND (attr
);
14182 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
14183 if (new_field
->accessibility
!= DW_ACCESS_public
)
14184 fip
->non_public_fields
= 1;
14186 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14187 if (attr
!= nullptr)
14188 new_field
->virtuality
= DW_UNSND (attr
);
14190 new_field
->virtuality
= DW_VIRTUALITY_none
;
14192 fp
= &new_field
->field
;
14194 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14198 /* Data member other than a C++ static data member. */
14200 /* Get type of field. */
14201 fp
->type
= die_type (die
, cu
);
14203 SET_FIELD_BITPOS (*fp
, 0);
14205 /* Get bit size of field (zero if none). */
14206 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14207 if (attr
!= nullptr)
14209 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
14213 FIELD_BITSIZE (*fp
) = 0;
14216 /* Get bit offset of field. */
14217 if (handle_data_member_location (die
, cu
, &offset
))
14218 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
14219 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14220 if (attr
!= nullptr)
14222 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14224 /* For big endian bits, the DW_AT_bit_offset gives the
14225 additional bit offset from the MSB of the containing
14226 anonymous object to the MSB of the field. We don't
14227 have to do anything special since we don't need to
14228 know the size of the anonymous object. */
14229 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
14233 /* For little endian bits, compute the bit offset to the
14234 MSB of the anonymous object, subtract off the number of
14235 bits from the MSB of the field to the MSB of the
14236 object, and then subtract off the number of bits of
14237 the field itself. The result is the bit offset of
14238 the LSB of the field. */
14239 int anonymous_size
;
14240 int bit_offset
= DW_UNSND (attr
);
14242 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14243 if (attr
!= nullptr)
14245 /* The size of the anonymous object containing
14246 the bit field is explicit, so use the
14247 indicated size (in bytes). */
14248 anonymous_size
= DW_UNSND (attr
);
14252 /* The size of the anonymous object containing
14253 the bit field must be inferred from the type
14254 attribute of the data member containing the
14256 anonymous_size
= TYPE_LENGTH (fp
->type
);
14258 SET_FIELD_BITPOS (*fp
,
14259 (FIELD_BITPOS (*fp
)
14260 + anonymous_size
* bits_per_byte
14261 - bit_offset
- FIELD_BITSIZE (*fp
)));
14264 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14266 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14267 + dwarf2_get_attr_constant_value (attr
, 0)));
14269 /* Get name of field. */
14270 fieldname
= dwarf2_name (die
, cu
);
14271 if (fieldname
== NULL
)
14274 /* The name is already allocated along with this objfile, so we don't
14275 need to duplicate it for the type. */
14276 fp
->name
= fieldname
;
14278 /* Change accessibility for artificial fields (e.g. virtual table
14279 pointer or virtual base class pointer) to private. */
14280 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
14282 FIELD_ARTIFICIAL (*fp
) = 1;
14283 new_field
->accessibility
= DW_ACCESS_private
;
14284 fip
->non_public_fields
= 1;
14287 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
14289 /* C++ static member. */
14291 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
14292 is a declaration, but all versions of G++ as of this writing
14293 (so through at least 3.2.1) incorrectly generate
14294 DW_TAG_variable tags. */
14296 const char *physname
;
14298 /* Get name of field. */
14299 fieldname
= dwarf2_name (die
, cu
);
14300 if (fieldname
== NULL
)
14303 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14305 /* Only create a symbol if this is an external value.
14306 new_symbol checks this and puts the value in the global symbol
14307 table, which we want. If it is not external, new_symbol
14308 will try to put the value in cu->list_in_scope which is wrong. */
14309 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
14311 /* A static const member, not much different than an enum as far as
14312 we're concerned, except that we can support more types. */
14313 new_symbol (die
, NULL
, cu
);
14316 /* Get physical name. */
14317 physname
= dwarf2_physname (fieldname
, die
, cu
);
14319 /* The name is already allocated along with this objfile, so we don't
14320 need to duplicate it for the type. */
14321 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
14322 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14323 FIELD_NAME (*fp
) = fieldname
;
14325 else if (die
->tag
== DW_TAG_inheritance
)
14329 /* C++ base class field. */
14330 if (handle_data_member_location (die
, cu
, &offset
))
14331 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
14332 FIELD_BITSIZE (*fp
) = 0;
14333 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14334 FIELD_NAME (*fp
) = TYPE_NAME (fp
->type
);
14336 else if (die
->tag
== DW_TAG_variant_part
)
14338 /* process_structure_scope will treat this DIE as a union. */
14339 process_structure_scope (die
, cu
);
14341 /* The variant part is relative to the start of the enclosing
14343 SET_FIELD_BITPOS (*fp
, 0);
14344 fp
->type
= get_die_type (die
, cu
);
14345 fp
->artificial
= 1;
14346 fp
->name
= "<<variant>>";
14348 /* Normally a DW_TAG_variant_part won't have a size, but our
14349 representation requires one, so set it to the maximum of the
14350 child sizes, being sure to account for the offset at which
14351 each child is seen. */
14352 if (TYPE_LENGTH (fp
->type
) == 0)
14355 for (int i
= 0; i
< TYPE_NFIELDS (fp
->type
); ++i
)
14357 unsigned len
= ((TYPE_FIELD_BITPOS (fp
->type
, i
) + 7) / 8
14358 + TYPE_LENGTH (TYPE_FIELD_TYPE (fp
->type
, i
)));
14362 TYPE_LENGTH (fp
->type
) = max
;
14366 gdb_assert_not_reached ("missing case in dwarf2_add_field");
14369 /* Can the type given by DIE define another type? */
14372 type_can_define_types (const struct die_info
*die
)
14376 case DW_TAG_typedef
:
14377 case DW_TAG_class_type
:
14378 case DW_TAG_structure_type
:
14379 case DW_TAG_union_type
:
14380 case DW_TAG_enumeration_type
:
14388 /* Add a type definition defined in the scope of the FIP's class. */
14391 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
14392 struct dwarf2_cu
*cu
)
14394 struct decl_field fp
;
14395 memset (&fp
, 0, sizeof (fp
));
14397 gdb_assert (type_can_define_types (die
));
14399 /* Get name of field. NULL is okay here, meaning an anonymous type. */
14400 fp
.name
= dwarf2_name (die
, cu
);
14401 fp
.type
= read_type_die (die
, cu
);
14403 /* Save accessibility. */
14404 enum dwarf_access_attribute accessibility
;
14405 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14407 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14409 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14410 switch (accessibility
)
14412 case DW_ACCESS_public
:
14413 /* The assumed value if neither private nor protected. */
14415 case DW_ACCESS_private
:
14418 case DW_ACCESS_protected
:
14419 fp
.is_protected
= 1;
14422 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
14425 if (die
->tag
== DW_TAG_typedef
)
14426 fip
->typedef_field_list
.push_back (fp
);
14428 fip
->nested_types_list
.push_back (fp
);
14431 /* Create the vector of fields, and attach it to the type. */
14434 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
14435 struct dwarf2_cu
*cu
)
14437 int nfields
= fip
->nfields
;
14439 /* Record the field count, allocate space for the array of fields,
14440 and create blank accessibility bitfields if necessary. */
14441 TYPE_NFIELDS (type
) = nfields
;
14442 TYPE_FIELDS (type
) = (struct field
*)
14443 TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
);
14445 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
14447 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14449 TYPE_FIELD_PRIVATE_BITS (type
) =
14450 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14451 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
14453 TYPE_FIELD_PROTECTED_BITS (type
) =
14454 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14455 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
14457 TYPE_FIELD_IGNORE_BITS (type
) =
14458 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14459 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
14462 /* If the type has baseclasses, allocate and clear a bit vector for
14463 TYPE_FIELD_VIRTUAL_BITS. */
14464 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
14466 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
14467 unsigned char *pointer
;
14469 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14470 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
14471 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
14472 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
14473 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
14476 if (TYPE_FLAG_DISCRIMINATED_UNION (type
))
14478 struct discriminant_info
*di
= alloc_discriminant_info (type
, -1, -1);
14480 for (int index
= 0; index
< nfields
; ++index
)
14482 struct nextfield
&field
= fip
->fields
[index
];
14484 if (field
.variant
.is_discriminant
)
14485 di
->discriminant_index
= index
;
14486 else if (field
.variant
.default_branch
)
14487 di
->default_index
= index
;
14489 di
->discriminants
[index
] = field
.variant
.discriminant_value
;
14493 /* Copy the saved-up fields into the field vector. */
14494 for (int i
= 0; i
< nfields
; ++i
)
14496 struct nextfield
&field
14497 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
14498 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
14500 TYPE_FIELD (type
, i
) = field
.field
;
14501 switch (field
.accessibility
)
14503 case DW_ACCESS_private
:
14504 if (cu
->language
!= language_ada
)
14505 SET_TYPE_FIELD_PRIVATE (type
, i
);
14508 case DW_ACCESS_protected
:
14509 if (cu
->language
!= language_ada
)
14510 SET_TYPE_FIELD_PROTECTED (type
, i
);
14513 case DW_ACCESS_public
:
14517 /* Unknown accessibility. Complain and treat it as public. */
14519 complaint (_("unsupported accessibility %d"),
14520 field
.accessibility
);
14524 if (i
< fip
->baseclasses
.size ())
14526 switch (field
.virtuality
)
14528 case DW_VIRTUALITY_virtual
:
14529 case DW_VIRTUALITY_pure_virtual
:
14530 if (cu
->language
== language_ada
)
14531 error (_("unexpected virtuality in component of Ada type"));
14532 SET_TYPE_FIELD_VIRTUAL (type
, i
);
14539 /* Return true if this member function is a constructor, false
14543 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
14545 const char *fieldname
;
14546 const char *type_name
;
14549 if (die
->parent
== NULL
)
14552 if (die
->parent
->tag
!= DW_TAG_structure_type
14553 && die
->parent
->tag
!= DW_TAG_union_type
14554 && die
->parent
->tag
!= DW_TAG_class_type
)
14557 fieldname
= dwarf2_name (die
, cu
);
14558 type_name
= dwarf2_name (die
->parent
, cu
);
14559 if (fieldname
== NULL
|| type_name
== NULL
)
14562 len
= strlen (fieldname
);
14563 return (strncmp (fieldname
, type_name
, len
) == 0
14564 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
14567 /* Check if the given VALUE is a recognized enum
14568 dwarf_defaulted_attribute constant according to DWARF5 spec,
14572 is_valid_DW_AT_defaulted (ULONGEST value
)
14576 case DW_DEFAULTED_no
:
14577 case DW_DEFAULTED_in_class
:
14578 case DW_DEFAULTED_out_of_class
:
14582 complaint (_("unrecognized DW_AT_defaulted value (%s)"), pulongest (value
));
14586 /* Add a member function to the proper fieldlist. */
14589 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
14590 struct type
*type
, struct dwarf2_cu
*cu
)
14592 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14593 struct attribute
*attr
;
14595 struct fnfieldlist
*flp
= nullptr;
14596 struct fn_field
*fnp
;
14597 const char *fieldname
;
14598 struct type
*this_type
;
14599 enum dwarf_access_attribute accessibility
;
14601 if (cu
->language
== language_ada
)
14602 error (_("unexpected member function in Ada type"));
14604 /* Get name of member function. */
14605 fieldname
= dwarf2_name (die
, cu
);
14606 if (fieldname
== NULL
)
14609 /* Look up member function name in fieldlist. */
14610 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
14612 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
14614 flp
= &fip
->fnfieldlists
[i
];
14619 /* Create a new fnfieldlist if necessary. */
14620 if (flp
== nullptr)
14622 fip
->fnfieldlists
.emplace_back ();
14623 flp
= &fip
->fnfieldlists
.back ();
14624 flp
->name
= fieldname
;
14625 i
= fip
->fnfieldlists
.size () - 1;
14628 /* Create a new member function field and add it to the vector of
14630 flp
->fnfields
.emplace_back ();
14631 fnp
= &flp
->fnfields
.back ();
14633 /* Delay processing of the physname until later. */
14634 if (cu
->language
== language_cplus
)
14635 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
14639 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
14640 fnp
->physname
= physname
? physname
: "";
14643 fnp
->type
= alloc_type (objfile
);
14644 this_type
= read_type_die (die
, cu
);
14645 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
14647 int nparams
= TYPE_NFIELDS (this_type
);
14649 /* TYPE is the domain of this method, and THIS_TYPE is the type
14650 of the method itself (TYPE_CODE_METHOD). */
14651 smash_to_method_type (fnp
->type
, type
,
14652 TYPE_TARGET_TYPE (this_type
),
14653 TYPE_FIELDS (this_type
),
14654 TYPE_NFIELDS (this_type
),
14655 TYPE_VARARGS (this_type
));
14657 /* Handle static member functions.
14658 Dwarf2 has no clean way to discern C++ static and non-static
14659 member functions. G++ helps GDB by marking the first
14660 parameter for non-static member functions (which is the this
14661 pointer) as artificial. We obtain this information from
14662 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
14663 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
14664 fnp
->voffset
= VOFFSET_STATIC
;
14667 complaint (_("member function type missing for '%s'"),
14668 dwarf2_full_name (fieldname
, die
, cu
));
14670 /* Get fcontext from DW_AT_containing_type if present. */
14671 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
14672 fnp
->fcontext
= die_containing_type (die
, cu
);
14674 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
14675 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
14677 /* Get accessibility. */
14678 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14679 if (attr
!= nullptr)
14680 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14682 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14683 switch (accessibility
)
14685 case DW_ACCESS_private
:
14686 fnp
->is_private
= 1;
14688 case DW_ACCESS_protected
:
14689 fnp
->is_protected
= 1;
14693 /* Check for artificial methods. */
14694 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
14695 if (attr
&& DW_UNSND (attr
) != 0)
14696 fnp
->is_artificial
= 1;
14698 /* Check for defaulted methods. */
14699 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
14700 if (attr
!= nullptr && is_valid_DW_AT_defaulted (DW_UNSND (attr
)))
14701 fnp
->defaulted
= (enum dwarf_defaulted_attribute
) DW_UNSND (attr
);
14703 /* Check for deleted methods. */
14704 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
14705 if (attr
!= nullptr && DW_UNSND (attr
) != 0)
14706 fnp
->is_deleted
= 1;
14708 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
14710 /* Get index in virtual function table if it is a virtual member
14711 function. For older versions of GCC, this is an offset in the
14712 appropriate virtual table, as specified by DW_AT_containing_type.
14713 For everyone else, it is an expression to be evaluated relative
14714 to the object address. */
14716 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
14717 if (attr
!= nullptr)
14719 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
> 0)
14721 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
14723 /* Old-style GCC. */
14724 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
14726 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
14727 || (DW_BLOCK (attr
)->size
> 1
14728 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
14729 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
14731 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14732 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
14733 dwarf2_complex_location_expr_complaint ();
14735 fnp
->voffset
/= cu
->header
.addr_size
;
14739 dwarf2_complex_location_expr_complaint ();
14741 if (!fnp
->fcontext
)
14743 /* If there is no `this' field and no DW_AT_containing_type,
14744 we cannot actually find a base class context for the
14746 if (TYPE_NFIELDS (this_type
) == 0
14747 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
14749 complaint (_("cannot determine context for virtual member "
14750 "function \"%s\" (offset %s)"),
14751 fieldname
, sect_offset_str (die
->sect_off
));
14756 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
14760 else if (attr
->form_is_section_offset ())
14762 dwarf2_complex_location_expr_complaint ();
14766 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
14772 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14773 if (attr
&& DW_UNSND (attr
))
14775 /* GCC does this, as of 2008-08-25; PR debug/37237. */
14776 complaint (_("Member function \"%s\" (offset %s) is virtual "
14777 "but the vtable offset is not specified"),
14778 fieldname
, sect_offset_str (die
->sect_off
));
14779 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14780 TYPE_CPLUS_DYNAMIC (type
) = 1;
14785 /* Create the vector of member function fields, and attach it to the type. */
14788 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
14789 struct dwarf2_cu
*cu
)
14791 if (cu
->language
== language_ada
)
14792 error (_("unexpected member functions in Ada type"));
14794 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14795 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
14797 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
14799 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
14801 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
14802 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
14804 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
14805 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
14806 fn_flp
->fn_fields
= (struct fn_field
*)
14807 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
14809 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
14810 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
14813 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
14816 /* Returns non-zero if NAME is the name of a vtable member in CU's
14817 language, zero otherwise. */
14819 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
14821 static const char vptr
[] = "_vptr";
14823 /* Look for the C++ form of the vtable. */
14824 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
14830 /* GCC outputs unnamed structures that are really pointers to member
14831 functions, with the ABI-specified layout. If TYPE describes
14832 such a structure, smash it into a member function type.
14834 GCC shouldn't do this; it should just output pointer to member DIEs.
14835 This is GCC PR debug/28767. */
14838 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
14840 struct type
*pfn_type
, *self_type
, *new_type
;
14842 /* Check for a structure with no name and two children. */
14843 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
14846 /* Check for __pfn and __delta members. */
14847 if (TYPE_FIELD_NAME (type
, 0) == NULL
14848 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
14849 || TYPE_FIELD_NAME (type
, 1) == NULL
14850 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
14853 /* Find the type of the method. */
14854 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
14855 if (pfn_type
== NULL
14856 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
14857 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
14860 /* Look for the "this" argument. */
14861 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
14862 if (TYPE_NFIELDS (pfn_type
) == 0
14863 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
14864 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
14867 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
14868 new_type
= alloc_type (objfile
);
14869 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
14870 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
14871 TYPE_VARARGS (pfn_type
));
14872 smash_to_methodptr_type (type
, new_type
);
14875 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
14876 appropriate error checking and issuing complaints if there is a
14880 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
14882 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
14884 if (attr
== nullptr)
14887 if (!attr
->form_is_constant ())
14889 complaint (_("DW_AT_alignment must have constant form"
14890 " - DIE at %s [in module %s]"),
14891 sect_offset_str (die
->sect_off
),
14892 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14897 if (attr
->form
== DW_FORM_sdata
)
14899 LONGEST val
= DW_SND (attr
);
14902 complaint (_("DW_AT_alignment value must not be negative"
14903 " - DIE at %s [in module %s]"),
14904 sect_offset_str (die
->sect_off
),
14905 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14911 align
= DW_UNSND (attr
);
14915 complaint (_("DW_AT_alignment value must not be zero"
14916 " - DIE at %s [in module %s]"),
14917 sect_offset_str (die
->sect_off
),
14918 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14921 if ((align
& (align
- 1)) != 0)
14923 complaint (_("DW_AT_alignment value must be a power of 2"
14924 " - DIE at %s [in module %s]"),
14925 sect_offset_str (die
->sect_off
),
14926 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14933 /* If the DIE has a DW_AT_alignment attribute, use its value to set
14934 the alignment for TYPE. */
14937 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
14940 if (!set_type_align (type
, get_alignment (cu
, die
)))
14941 complaint (_("DW_AT_alignment value too large"
14942 " - DIE at %s [in module %s]"),
14943 sect_offset_str (die
->sect_off
),
14944 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14947 /* Check if the given VALUE is a valid enum dwarf_calling_convention
14948 constant for a type, according to DWARF5 spec, Table 5.5. */
14951 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
14956 case DW_CC_pass_by_reference
:
14957 case DW_CC_pass_by_value
:
14961 complaint (_("unrecognized DW_AT_calling_convention value "
14962 "(%s) for a type"), pulongest (value
));
14967 /* Check if the given VALUE is a valid enum dwarf_calling_convention
14968 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
14969 also according to GNU-specific values (see include/dwarf2.h). */
14972 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
14977 case DW_CC_program
:
14981 case DW_CC_GNU_renesas_sh
:
14982 case DW_CC_GNU_borland_fastcall_i386
:
14983 case DW_CC_GDB_IBM_OpenCL
:
14987 complaint (_("unrecognized DW_AT_calling_convention value "
14988 "(%s) for a subroutine"), pulongest (value
));
14993 /* Called when we find the DIE that starts a structure or union scope
14994 (definition) to create a type for the structure or union. Fill in
14995 the type's name and general properties; the members will not be
14996 processed until process_structure_scope. A symbol table entry for
14997 the type will also not be done until process_structure_scope (assuming
14998 the type has a name).
15000 NOTE: we need to call these functions regardless of whether or not the
15001 DIE has a DW_AT_name attribute, since it might be an anonymous
15002 structure or union. This gets the type entered into our set of
15003 user defined types. */
15005 static struct type
*
15006 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15008 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15010 struct attribute
*attr
;
15013 /* If the definition of this type lives in .debug_types, read that type.
15014 Don't follow DW_AT_specification though, that will take us back up
15015 the chain and we want to go down. */
15016 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
15017 if (attr
!= nullptr)
15019 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15021 /* The type's CU may not be the same as CU.
15022 Ensure TYPE is recorded with CU in die_type_hash. */
15023 return set_die_type (die
, type
, cu
);
15026 type
= alloc_type (objfile
);
15027 INIT_CPLUS_SPECIFIC (type
);
15029 name
= dwarf2_name (die
, cu
);
15032 if (cu
->language
== language_cplus
15033 || cu
->language
== language_d
15034 || cu
->language
== language_rust
)
15036 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15038 /* dwarf2_full_name might have already finished building the DIE's
15039 type. If so, there is no need to continue. */
15040 if (get_die_type (die
, cu
) != NULL
)
15041 return get_die_type (die
, cu
);
15043 TYPE_NAME (type
) = full_name
;
15047 /* The name is already allocated along with this objfile, so
15048 we don't need to duplicate it for the type. */
15049 TYPE_NAME (type
) = name
;
15053 if (die
->tag
== DW_TAG_structure_type
)
15055 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15057 else if (die
->tag
== DW_TAG_union_type
)
15059 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15061 else if (die
->tag
== DW_TAG_variant_part
)
15063 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15064 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
15068 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15071 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15072 TYPE_DECLARED_CLASS (type
) = 1;
15074 /* Store the calling convention in the type if it's available in
15075 the die. Otherwise the calling convention remains set to
15076 the default value DW_CC_normal. */
15077 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15078 if (attr
!= nullptr
15079 && is_valid_DW_AT_calling_convention_for_type (DW_UNSND (attr
)))
15081 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15082 TYPE_CPLUS_CALLING_CONVENTION (type
)
15083 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
15086 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15087 if (attr
!= nullptr)
15089 if (attr
->form_is_constant ())
15090 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15093 /* For the moment, dynamic type sizes are not supported
15094 by GDB's struct type. The actual size is determined
15095 on-demand when resolving the type of a given object,
15096 so set the type's length to zero for now. Otherwise,
15097 we record an expression as the length, and that expression
15098 could lead to a very large value, which could eventually
15099 lead to us trying to allocate that much memory when creating
15100 a value of that type. */
15101 TYPE_LENGTH (type
) = 0;
15106 TYPE_LENGTH (type
) = 0;
15109 maybe_set_alignment (cu
, die
, type
);
15111 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15113 /* ICC<14 does not output the required DW_AT_declaration on
15114 incomplete types, but gives them a size of zero. */
15115 TYPE_STUB (type
) = 1;
15118 TYPE_STUB_SUPPORTED (type
) = 1;
15120 if (die_is_declaration (die
, cu
))
15121 TYPE_STUB (type
) = 1;
15122 else if (attr
== NULL
&& die
->child
== NULL
15123 && producer_is_realview (cu
->producer
))
15124 /* RealView does not output the required DW_AT_declaration
15125 on incomplete types. */
15126 TYPE_STUB (type
) = 1;
15128 /* We need to add the type field to the die immediately so we don't
15129 infinitely recurse when dealing with pointers to the structure
15130 type within the structure itself. */
15131 set_die_type (die
, type
, cu
);
15133 /* set_die_type should be already done. */
15134 set_descriptive_type (type
, die
, cu
);
15139 /* A helper for process_structure_scope that handles a single member
15143 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15144 struct field_info
*fi
,
15145 std::vector
<struct symbol
*> *template_args
,
15146 struct dwarf2_cu
*cu
)
15148 if (child_die
->tag
== DW_TAG_member
15149 || child_die
->tag
== DW_TAG_variable
15150 || child_die
->tag
== DW_TAG_variant_part
)
15152 /* NOTE: carlton/2002-11-05: A C++ static data member
15153 should be a DW_TAG_member that is a declaration, but
15154 all versions of G++ as of this writing (so through at
15155 least 3.2.1) incorrectly generate DW_TAG_variable
15156 tags for them instead. */
15157 dwarf2_add_field (fi
, child_die
, cu
);
15159 else if (child_die
->tag
== DW_TAG_subprogram
)
15161 /* Rust doesn't have member functions in the C++ sense.
15162 However, it does emit ordinary functions as children
15163 of a struct DIE. */
15164 if (cu
->language
== language_rust
)
15165 read_func_scope (child_die
, cu
);
15168 /* C++ member function. */
15169 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15172 else if (child_die
->tag
== DW_TAG_inheritance
)
15174 /* C++ base class field. */
15175 dwarf2_add_field (fi
, child_die
, cu
);
15177 else if (type_can_define_types (child_die
))
15178 dwarf2_add_type_defn (fi
, child_die
, cu
);
15179 else if (child_die
->tag
== DW_TAG_template_type_param
15180 || child_die
->tag
== DW_TAG_template_value_param
)
15182 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15185 template_args
->push_back (arg
);
15187 else if (child_die
->tag
== DW_TAG_variant
)
15189 /* In a variant we want to get the discriminant and also add a
15190 field for our sole member child. */
15191 struct attribute
*discr
= dwarf2_attr (child_die
, DW_AT_discr_value
, cu
);
15193 for (die_info
*variant_child
= child_die
->child
;
15194 variant_child
!= NULL
;
15195 variant_child
= sibling_die (variant_child
))
15197 if (variant_child
->tag
== DW_TAG_member
)
15199 handle_struct_member_die (variant_child
, type
, fi
,
15200 template_args
, cu
);
15201 /* Only handle the one. */
15206 /* We don't handle this but we might as well report it if we see
15208 if (dwarf2_attr (child_die
, DW_AT_discr_list
, cu
) != nullptr)
15209 complaint (_("DW_AT_discr_list is not supported yet"
15210 " - DIE at %s [in module %s]"),
15211 sect_offset_str (child_die
->sect_off
),
15212 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15214 /* The first field was just added, so we can stash the
15215 discriminant there. */
15216 gdb_assert (!fi
->fields
.empty ());
15218 fi
->fields
.back ().variant
.default_branch
= true;
15220 fi
->fields
.back ().variant
.discriminant_value
= DW_UNSND (discr
);
15224 /* Finish creating a structure or union type, including filling in
15225 its members and creating a symbol for it. */
15228 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15230 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15231 struct die_info
*child_die
;
15234 type
= get_die_type (die
, cu
);
15236 type
= read_structure_type (die
, cu
);
15238 /* When reading a DW_TAG_variant_part, we need to notice when we
15239 read the discriminant member, so we can record it later in the
15240 discriminant_info. */
15241 bool is_variant_part
= TYPE_FLAG_DISCRIMINATED_UNION (type
);
15242 sect_offset discr_offset
{};
15243 bool has_template_parameters
= false;
15245 if (is_variant_part
)
15247 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15250 /* Maybe it's a univariant form, an extension we support.
15251 In this case arrange not to check the offset. */
15252 is_variant_part
= false;
15254 else if (discr
->form_is_ref ())
15256 struct dwarf2_cu
*target_cu
= cu
;
15257 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15259 discr_offset
= target_die
->sect_off
;
15263 complaint (_("DW_AT_discr does not have DIE reference form"
15264 " - DIE at %s [in module %s]"),
15265 sect_offset_str (die
->sect_off
),
15266 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15267 is_variant_part
= false;
15271 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15273 struct field_info fi
;
15274 std::vector
<struct symbol
*> template_args
;
15276 child_die
= die
->child
;
15278 while (child_die
&& child_die
->tag
)
15280 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15282 if (is_variant_part
&& discr_offset
== child_die
->sect_off
)
15283 fi
.fields
.back ().variant
.is_discriminant
= true;
15285 child_die
= sibling_die (child_die
);
15288 /* Attach template arguments to type. */
15289 if (!template_args
.empty ())
15291 has_template_parameters
= true;
15292 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15293 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15294 TYPE_TEMPLATE_ARGUMENTS (type
)
15295 = XOBNEWVEC (&objfile
->objfile_obstack
,
15297 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15298 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15299 template_args
.data (),
15300 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15301 * sizeof (struct symbol
*)));
15304 /* Attach fields and member functions to the type. */
15306 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15307 if (!fi
.fnfieldlists
.empty ())
15309 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15311 /* Get the type which refers to the base class (possibly this
15312 class itself) which contains the vtable pointer for the current
15313 class from the DW_AT_containing_type attribute. This use of
15314 DW_AT_containing_type is a GNU extension. */
15316 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15318 struct type
*t
= die_containing_type (die
, cu
);
15320 set_type_vptr_basetype (type
, t
);
15325 /* Our own class provides vtbl ptr. */
15326 for (i
= TYPE_NFIELDS (t
) - 1;
15327 i
>= TYPE_N_BASECLASSES (t
);
15330 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
15332 if (is_vtable_name (fieldname
, cu
))
15334 set_type_vptr_fieldno (type
, i
);
15339 /* Complain if virtual function table field not found. */
15340 if (i
< TYPE_N_BASECLASSES (t
))
15341 complaint (_("virtual function table pointer "
15342 "not found when defining class '%s'"),
15343 TYPE_NAME (type
) ? TYPE_NAME (type
) : "");
15347 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
15350 else if (cu
->producer
15351 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
15353 /* The IBM XLC compiler does not provide direct indication
15354 of the containing type, but the vtable pointer is
15355 always named __vfp. */
15359 for (i
= TYPE_NFIELDS (type
) - 1;
15360 i
>= TYPE_N_BASECLASSES (type
);
15363 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
15365 set_type_vptr_fieldno (type
, i
);
15366 set_type_vptr_basetype (type
, type
);
15373 /* Copy fi.typedef_field_list linked list elements content into the
15374 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
15375 if (!fi
.typedef_field_list
.empty ())
15377 int count
= fi
.typedef_field_list
.size ();
15379 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15380 TYPE_TYPEDEF_FIELD_ARRAY (type
)
15381 = ((struct decl_field
*)
15383 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
15384 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
15386 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
15387 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
15390 /* Copy fi.nested_types_list linked list elements content into the
15391 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
15392 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
15394 int count
= fi
.nested_types_list
.size ();
15396 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15397 TYPE_NESTED_TYPES_ARRAY (type
)
15398 = ((struct decl_field
*)
15399 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
15400 TYPE_NESTED_TYPES_COUNT (type
) = count
;
15402 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
15403 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
15407 quirk_gcc_member_function_pointer (type
, objfile
);
15408 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
15409 cu
->rust_unions
.push_back (type
);
15411 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
15412 snapshots) has been known to create a die giving a declaration
15413 for a class that has, as a child, a die giving a definition for a
15414 nested class. So we have to process our children even if the
15415 current die is a declaration. Normally, of course, a declaration
15416 won't have any children at all. */
15418 child_die
= die
->child
;
15420 while (child_die
!= NULL
&& child_die
->tag
)
15422 if (child_die
->tag
== DW_TAG_member
15423 || child_die
->tag
== DW_TAG_variable
15424 || child_die
->tag
== DW_TAG_inheritance
15425 || child_die
->tag
== DW_TAG_template_value_param
15426 || child_die
->tag
== DW_TAG_template_type_param
)
15431 process_die (child_die
, cu
);
15433 child_die
= sibling_die (child_die
);
15436 /* Do not consider external references. According to the DWARF standard,
15437 these DIEs are identified by the fact that they have no byte_size
15438 attribute, and a declaration attribute. */
15439 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
15440 || !die_is_declaration (die
, cu
))
15442 struct symbol
*sym
= new_symbol (die
, type
, cu
);
15444 if (has_template_parameters
)
15446 struct symtab
*symtab
;
15447 if (sym
!= nullptr)
15448 symtab
= symbol_symtab (sym
);
15449 else if (cu
->line_header
!= nullptr)
15451 /* Any related symtab will do. */
15453 = cu
->line_header
->file_names ()[0].symtab
;
15458 complaint (_("could not find suitable "
15459 "symtab for template parameter"
15460 " - DIE at %s [in module %s]"),
15461 sect_offset_str (die
->sect_off
),
15462 objfile_name (objfile
));
15465 if (symtab
!= nullptr)
15467 /* Make sure that the symtab is set on the new symbols.
15468 Even though they don't appear in this symtab directly,
15469 other parts of gdb assume that symbols do, and this is
15470 reasonably true. */
15471 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
15472 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
15478 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
15479 update TYPE using some information only available in DIE's children. */
15482 update_enumeration_type_from_children (struct die_info
*die
,
15484 struct dwarf2_cu
*cu
)
15486 struct die_info
*child_die
;
15487 int unsigned_enum
= 1;
15491 auto_obstack obstack
;
15493 for (child_die
= die
->child
;
15494 child_die
!= NULL
&& child_die
->tag
;
15495 child_die
= sibling_die (child_die
))
15497 struct attribute
*attr
;
15499 const gdb_byte
*bytes
;
15500 struct dwarf2_locexpr_baton
*baton
;
15503 if (child_die
->tag
!= DW_TAG_enumerator
)
15506 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
15510 name
= dwarf2_name (child_die
, cu
);
15512 name
= "<anonymous enumerator>";
15514 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
15515 &value
, &bytes
, &baton
);
15521 else if ((mask
& value
) != 0)
15526 /* If we already know that the enum type is neither unsigned, nor
15527 a flag type, no need to look at the rest of the enumerates. */
15528 if (!unsigned_enum
&& !flag_enum
)
15533 TYPE_UNSIGNED (type
) = 1;
15535 TYPE_FLAG_ENUM (type
) = 1;
15538 /* Given a DW_AT_enumeration_type die, set its type. We do not
15539 complete the type's fields yet, or create any symbols. */
15541 static struct type
*
15542 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15544 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15546 struct attribute
*attr
;
15549 /* If the definition of this type lives in .debug_types, read that type.
15550 Don't follow DW_AT_specification though, that will take us back up
15551 the chain and we want to go down. */
15552 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
15553 if (attr
!= nullptr)
15555 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15557 /* The type's CU may not be the same as CU.
15558 Ensure TYPE is recorded with CU in die_type_hash. */
15559 return set_die_type (die
, type
, cu
);
15562 type
= alloc_type (objfile
);
15564 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
15565 name
= dwarf2_full_name (NULL
, die
, cu
);
15567 TYPE_NAME (type
) = name
;
15569 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
15572 struct type
*underlying_type
= die_type (die
, cu
);
15574 TYPE_TARGET_TYPE (type
) = underlying_type
;
15577 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15578 if (attr
!= nullptr)
15580 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15584 TYPE_LENGTH (type
) = 0;
15587 maybe_set_alignment (cu
, die
, type
);
15589 /* The enumeration DIE can be incomplete. In Ada, any type can be
15590 declared as private in the package spec, and then defined only
15591 inside the package body. Such types are known as Taft Amendment
15592 Types. When another package uses such a type, an incomplete DIE
15593 may be generated by the compiler. */
15594 if (die_is_declaration (die
, cu
))
15595 TYPE_STUB (type
) = 1;
15597 /* Finish the creation of this type by using the enum's children.
15598 We must call this even when the underlying type has been provided
15599 so that we can determine if we're looking at a "flag" enum. */
15600 update_enumeration_type_from_children (die
, type
, cu
);
15602 /* If this type has an underlying type that is not a stub, then we
15603 may use its attributes. We always use the "unsigned" attribute
15604 in this situation, because ordinarily we guess whether the type
15605 is unsigned -- but the guess can be wrong and the underlying type
15606 can tell us the reality. However, we defer to a local size
15607 attribute if one exists, because this lets the compiler override
15608 the underlying type if needed. */
15609 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
15611 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
15612 if (TYPE_LENGTH (type
) == 0)
15613 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
15614 if (TYPE_RAW_ALIGN (type
) == 0
15615 && TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)) != 0)
15616 set_type_align (type
, TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)));
15619 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
15621 return set_die_type (die
, type
, cu
);
15624 /* Given a pointer to a die which begins an enumeration, process all
15625 the dies that define the members of the enumeration, and create the
15626 symbol for the enumeration type.
15628 NOTE: We reverse the order of the element list. */
15631 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15633 struct type
*this_type
;
15635 this_type
= get_die_type (die
, cu
);
15636 if (this_type
== NULL
)
15637 this_type
= read_enumeration_type (die
, cu
);
15639 if (die
->child
!= NULL
)
15641 struct die_info
*child_die
;
15642 struct symbol
*sym
;
15643 std::vector
<struct field
> fields
;
15646 child_die
= die
->child
;
15647 while (child_die
&& child_die
->tag
)
15649 if (child_die
->tag
!= DW_TAG_enumerator
)
15651 process_die (child_die
, cu
);
15655 name
= dwarf2_name (child_die
, cu
);
15658 sym
= new_symbol (child_die
, this_type
, cu
);
15660 fields
.emplace_back ();
15661 struct field
&field
= fields
.back ();
15663 FIELD_NAME (field
) = sym
->linkage_name ();
15664 FIELD_TYPE (field
) = NULL
;
15665 SET_FIELD_ENUMVAL (field
, SYMBOL_VALUE (sym
));
15666 FIELD_BITSIZE (field
) = 0;
15670 child_die
= sibling_die (child_die
);
15673 if (!fields
.empty ())
15675 TYPE_NFIELDS (this_type
) = fields
.size ();
15676 TYPE_FIELDS (this_type
) = (struct field
*)
15677 TYPE_ALLOC (this_type
, sizeof (struct field
) * fields
.size ());
15678 memcpy (TYPE_FIELDS (this_type
), fields
.data (),
15679 sizeof (struct field
) * fields
.size ());
15683 /* If we are reading an enum from a .debug_types unit, and the enum
15684 is a declaration, and the enum is not the signatured type in the
15685 unit, then we do not want to add a symbol for it. Adding a
15686 symbol would in some cases obscure the true definition of the
15687 enum, giving users an incomplete type when the definition is
15688 actually available. Note that we do not want to do this for all
15689 enums which are just declarations, because C++0x allows forward
15690 enum declarations. */
15691 if (cu
->per_cu
->is_debug_types
15692 && die_is_declaration (die
, cu
))
15694 struct signatured_type
*sig_type
;
15696 sig_type
= (struct signatured_type
*) cu
->per_cu
;
15697 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
15698 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
15702 new_symbol (die
, this_type
, cu
);
15705 /* Extract all information from a DW_TAG_array_type DIE and put it in
15706 the DIE's type field. For now, this only handles one dimensional
15709 static struct type
*
15710 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15712 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15713 struct die_info
*child_die
;
15715 struct type
*element_type
, *range_type
, *index_type
;
15716 struct attribute
*attr
;
15718 struct dynamic_prop
*byte_stride_prop
= NULL
;
15719 unsigned int bit_stride
= 0;
15721 element_type
= die_type (die
, cu
);
15723 /* The die_type call above may have already set the type for this DIE. */
15724 type
= get_die_type (die
, cu
);
15728 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
15732 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
15735 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
15736 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
15740 complaint (_("unable to read array DW_AT_byte_stride "
15741 " - DIE at %s [in module %s]"),
15742 sect_offset_str (die
->sect_off
),
15743 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15744 /* Ignore this attribute. We will likely not be able to print
15745 arrays of this type correctly, but there is little we can do
15746 to help if we cannot read the attribute's value. */
15747 byte_stride_prop
= NULL
;
15751 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
15753 bit_stride
= DW_UNSND (attr
);
15755 /* Irix 6.2 native cc creates array types without children for
15756 arrays with unspecified length. */
15757 if (die
->child
== NULL
)
15759 index_type
= objfile_type (objfile
)->builtin_int
;
15760 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
15761 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
15762 byte_stride_prop
, bit_stride
);
15763 return set_die_type (die
, type
, cu
);
15766 std::vector
<struct type
*> range_types
;
15767 child_die
= die
->child
;
15768 while (child_die
&& child_die
->tag
)
15770 if (child_die
->tag
== DW_TAG_subrange_type
)
15772 struct type
*child_type
= read_type_die (child_die
, cu
);
15774 if (child_type
!= NULL
)
15776 /* The range type was succesfully read. Save it for the
15777 array type creation. */
15778 range_types
.push_back (child_type
);
15781 child_die
= sibling_die (child_die
);
15784 /* Dwarf2 dimensions are output from left to right, create the
15785 necessary array types in backwards order. */
15787 type
= element_type
;
15789 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
15793 while (i
< range_types
.size ())
15794 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
15795 byte_stride_prop
, bit_stride
);
15799 size_t ndim
= range_types
.size ();
15801 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
15802 byte_stride_prop
, bit_stride
);
15805 /* Understand Dwarf2 support for vector types (like they occur on
15806 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
15807 array type. This is not part of the Dwarf2/3 standard yet, but a
15808 custom vendor extension. The main difference between a regular
15809 array and the vector variant is that vectors are passed by value
15811 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
15812 if (attr
!= nullptr)
15813 make_vector_type (type
);
15815 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
15816 implementation may choose to implement triple vectors using this
15818 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15819 if (attr
!= nullptr)
15821 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
15822 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15824 complaint (_("DW_AT_byte_size for array type smaller "
15825 "than the total size of elements"));
15828 name
= dwarf2_name (die
, cu
);
15830 TYPE_NAME (type
) = name
;
15832 maybe_set_alignment (cu
, die
, type
);
15834 /* Install the type in the die. */
15835 set_die_type (die
, type
, cu
);
15837 /* set_die_type should be already done. */
15838 set_descriptive_type (type
, die
, cu
);
15843 static enum dwarf_array_dim_ordering
15844 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
15846 struct attribute
*attr
;
15848 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
15850 if (attr
!= nullptr)
15851 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
15853 /* GNU F77 is a special case, as at 08/2004 array type info is the
15854 opposite order to the dwarf2 specification, but data is still
15855 laid out as per normal fortran.
15857 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
15858 version checking. */
15860 if (cu
->language
== language_fortran
15861 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
15863 return DW_ORD_row_major
;
15866 switch (cu
->language_defn
->la_array_ordering
)
15868 case array_column_major
:
15869 return DW_ORD_col_major
;
15870 case array_row_major
:
15872 return DW_ORD_row_major
;
15876 /* Extract all information from a DW_TAG_set_type DIE and put it in
15877 the DIE's type field. */
15879 static struct type
*
15880 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15882 struct type
*domain_type
, *set_type
;
15883 struct attribute
*attr
;
15885 domain_type
= die_type (die
, cu
);
15887 /* The die_type call above may have already set the type for this DIE. */
15888 set_type
= get_die_type (die
, cu
);
15892 set_type
= create_set_type (NULL
, domain_type
);
15894 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15895 if (attr
!= nullptr)
15896 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
15898 maybe_set_alignment (cu
, die
, set_type
);
15900 return set_die_type (die
, set_type
, cu
);
15903 /* A helper for read_common_block that creates a locexpr baton.
15904 SYM is the symbol which we are marking as computed.
15905 COMMON_DIE is the DIE for the common block.
15906 COMMON_LOC is the location expression attribute for the common
15908 MEMBER_LOC is the location expression attribute for the particular
15909 member of the common block that we are processing.
15910 CU is the CU from which the above come. */
15913 mark_common_block_symbol_computed (struct symbol
*sym
,
15914 struct die_info
*common_die
,
15915 struct attribute
*common_loc
,
15916 struct attribute
*member_loc
,
15917 struct dwarf2_cu
*cu
)
15919 struct dwarf2_per_objfile
*dwarf2_per_objfile
15920 = cu
->per_cu
->dwarf2_per_objfile
;
15921 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
15922 struct dwarf2_locexpr_baton
*baton
;
15924 unsigned int cu_off
;
15925 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
15926 LONGEST offset
= 0;
15928 gdb_assert (common_loc
&& member_loc
);
15929 gdb_assert (common_loc
->form_is_block ());
15930 gdb_assert (member_loc
->form_is_block ()
15931 || member_loc
->form_is_constant ());
15933 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
15934 baton
->per_cu
= cu
->per_cu
;
15935 gdb_assert (baton
->per_cu
);
15937 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
15939 if (member_loc
->form_is_constant ())
15941 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
15942 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
15945 baton
->size
+= DW_BLOCK (member_loc
)->size
;
15947 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
15950 *ptr
++ = DW_OP_call4
;
15951 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
15952 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
15955 if (member_loc
->form_is_constant ())
15957 *ptr
++ = DW_OP_addr
;
15958 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
15959 ptr
+= cu
->header
.addr_size
;
15963 /* We have to copy the data here, because DW_OP_call4 will only
15964 use a DW_AT_location attribute. */
15965 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
15966 ptr
+= DW_BLOCK (member_loc
)->size
;
15969 *ptr
++ = DW_OP_plus
;
15970 gdb_assert (ptr
- baton
->data
== baton
->size
);
15972 SYMBOL_LOCATION_BATON (sym
) = baton
;
15973 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
15976 /* Create appropriate locally-scoped variables for all the
15977 DW_TAG_common_block entries. Also create a struct common_block
15978 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
15979 is used to separate the common blocks name namespace from regular
15983 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
15985 struct attribute
*attr
;
15987 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
15988 if (attr
!= nullptr)
15990 /* Support the .debug_loc offsets. */
15991 if (attr
->form_is_block ())
15995 else if (attr
->form_is_section_offset ())
15997 dwarf2_complex_location_expr_complaint ();
16002 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16003 "common block member");
16008 if (die
->child
!= NULL
)
16010 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16011 struct die_info
*child_die
;
16012 size_t n_entries
= 0, size
;
16013 struct common_block
*common_block
;
16014 struct symbol
*sym
;
16016 for (child_die
= die
->child
;
16017 child_die
&& child_die
->tag
;
16018 child_die
= sibling_die (child_die
))
16021 size
= (sizeof (struct common_block
)
16022 + (n_entries
- 1) * sizeof (struct symbol
*));
16024 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16026 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16027 common_block
->n_entries
= 0;
16029 for (child_die
= die
->child
;
16030 child_die
&& child_die
->tag
;
16031 child_die
= sibling_die (child_die
))
16033 /* Create the symbol in the DW_TAG_common_block block in the current
16035 sym
= new_symbol (child_die
, NULL
, cu
);
16038 struct attribute
*member_loc
;
16040 common_block
->contents
[common_block
->n_entries
++] = sym
;
16042 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16046 /* GDB has handled this for a long time, but it is
16047 not specified by DWARF. It seems to have been
16048 emitted by gfortran at least as recently as:
16049 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16050 complaint (_("Variable in common block has "
16051 "DW_AT_data_member_location "
16052 "- DIE at %s [in module %s]"),
16053 sect_offset_str (child_die
->sect_off
),
16054 objfile_name (objfile
));
16056 if (member_loc
->form_is_section_offset ())
16057 dwarf2_complex_location_expr_complaint ();
16058 else if (member_loc
->form_is_constant ()
16059 || member_loc
->form_is_block ())
16061 if (attr
!= nullptr)
16062 mark_common_block_symbol_computed (sym
, die
, attr
,
16066 dwarf2_complex_location_expr_complaint ();
16071 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16072 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16076 /* Create a type for a C++ namespace. */
16078 static struct type
*
16079 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16081 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16082 const char *previous_prefix
, *name
;
16086 /* For extensions, reuse the type of the original namespace. */
16087 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16089 struct die_info
*ext_die
;
16090 struct dwarf2_cu
*ext_cu
= cu
;
16092 ext_die
= dwarf2_extension (die
, &ext_cu
);
16093 type
= read_type_die (ext_die
, ext_cu
);
16095 /* EXT_CU may not be the same as CU.
16096 Ensure TYPE is recorded with CU in die_type_hash. */
16097 return set_die_type (die
, type
, cu
);
16100 name
= namespace_name (die
, &is_anonymous
, cu
);
16102 /* Now build the name of the current namespace. */
16104 previous_prefix
= determine_prefix (die
, cu
);
16105 if (previous_prefix
[0] != '\0')
16106 name
= typename_concat (&objfile
->objfile_obstack
,
16107 previous_prefix
, name
, 0, cu
);
16109 /* Create the type. */
16110 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16112 return set_die_type (die
, type
, cu
);
16115 /* Read a namespace scope. */
16118 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16120 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16123 /* Add a symbol associated to this if we haven't seen the namespace
16124 before. Also, add a using directive if it's an anonymous
16127 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16131 type
= read_type_die (die
, cu
);
16132 new_symbol (die
, type
, cu
);
16134 namespace_name (die
, &is_anonymous
, cu
);
16137 const char *previous_prefix
= determine_prefix (die
, cu
);
16139 std::vector
<const char *> excludes
;
16140 add_using_directive (using_directives (cu
),
16141 previous_prefix
, TYPE_NAME (type
), NULL
,
16142 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16146 if (die
->child
!= NULL
)
16148 struct die_info
*child_die
= die
->child
;
16150 while (child_die
&& child_die
->tag
)
16152 process_die (child_die
, cu
);
16153 child_die
= sibling_die (child_die
);
16158 /* Read a Fortran module as type. This DIE can be only a declaration used for
16159 imported module. Still we need that type as local Fortran "use ... only"
16160 declaration imports depend on the created type in determine_prefix. */
16162 static struct type
*
16163 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16165 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16166 const char *module_name
;
16169 module_name
= dwarf2_name (die
, cu
);
16170 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16172 return set_die_type (die
, type
, cu
);
16175 /* Read a Fortran module. */
16178 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16180 struct die_info
*child_die
= die
->child
;
16183 type
= read_type_die (die
, cu
);
16184 new_symbol (die
, type
, cu
);
16186 while (child_die
&& child_die
->tag
)
16188 process_die (child_die
, cu
);
16189 child_die
= sibling_die (child_die
);
16193 /* Return the name of the namespace represented by DIE. Set
16194 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16197 static const char *
16198 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16200 struct die_info
*current_die
;
16201 const char *name
= NULL
;
16203 /* Loop through the extensions until we find a name. */
16205 for (current_die
= die
;
16206 current_die
!= NULL
;
16207 current_die
= dwarf2_extension (die
, &cu
))
16209 /* We don't use dwarf2_name here so that we can detect the absence
16210 of a name -> anonymous namespace. */
16211 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16217 /* Is it an anonymous namespace? */
16219 *is_anonymous
= (name
== NULL
);
16221 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16226 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16227 the user defined type vector. */
16229 static struct type
*
16230 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16232 struct gdbarch
*gdbarch
16233 = get_objfile_arch (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16234 struct comp_unit_head
*cu_header
= &cu
->header
;
16236 struct attribute
*attr_byte_size
;
16237 struct attribute
*attr_address_class
;
16238 int byte_size
, addr_class
;
16239 struct type
*target_type
;
16241 target_type
= die_type (die
, cu
);
16243 /* The die_type call above may have already set the type for this DIE. */
16244 type
= get_die_type (die
, cu
);
16248 type
= lookup_pointer_type (target_type
);
16250 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16251 if (attr_byte_size
)
16252 byte_size
= DW_UNSND (attr_byte_size
);
16254 byte_size
= cu_header
->addr_size
;
16256 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
16257 if (attr_address_class
)
16258 addr_class
= DW_UNSND (attr_address_class
);
16260 addr_class
= DW_ADDR_none
;
16262 ULONGEST alignment
= get_alignment (cu
, die
);
16264 /* If the pointer size, alignment, or address class is different
16265 than the default, create a type variant marked as such and set
16266 the length accordingly. */
16267 if (TYPE_LENGTH (type
) != byte_size
16268 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
16269 && alignment
!= TYPE_RAW_ALIGN (type
))
16270 || addr_class
!= DW_ADDR_none
)
16272 if (gdbarch_address_class_type_flags_p (gdbarch
))
16276 type_flags
= gdbarch_address_class_type_flags
16277 (gdbarch
, byte_size
, addr_class
);
16278 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
16280 type
= make_type_with_address_space (type
, type_flags
);
16282 else if (TYPE_LENGTH (type
) != byte_size
)
16284 complaint (_("invalid pointer size %d"), byte_size
);
16286 else if (TYPE_RAW_ALIGN (type
) != alignment
)
16288 complaint (_("Invalid DW_AT_alignment"
16289 " - DIE at %s [in module %s]"),
16290 sect_offset_str (die
->sect_off
),
16291 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16295 /* Should we also complain about unhandled address classes? */
16299 TYPE_LENGTH (type
) = byte_size
;
16300 set_type_align (type
, alignment
);
16301 return set_die_type (die
, type
, cu
);
16304 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
16305 the user defined type vector. */
16307 static struct type
*
16308 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16311 struct type
*to_type
;
16312 struct type
*domain
;
16314 to_type
= die_type (die
, cu
);
16315 domain
= die_containing_type (die
, cu
);
16317 /* The calls above may have already set the type for this DIE. */
16318 type
= get_die_type (die
, cu
);
16322 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
16323 type
= lookup_methodptr_type (to_type
);
16324 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
16326 struct type
*new_type
16327 = alloc_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16329 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
16330 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
16331 TYPE_VARARGS (to_type
));
16332 type
= lookup_methodptr_type (new_type
);
16335 type
= lookup_memberptr_type (to_type
, domain
);
16337 return set_die_type (die
, type
, cu
);
16340 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
16341 the user defined type vector. */
16343 static struct type
*
16344 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16345 enum type_code refcode
)
16347 struct comp_unit_head
*cu_header
= &cu
->header
;
16348 struct type
*type
, *target_type
;
16349 struct attribute
*attr
;
16351 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
16353 target_type
= die_type (die
, cu
);
16355 /* The die_type call above may have already set the type for this DIE. */
16356 type
= get_die_type (die
, cu
);
16360 type
= lookup_reference_type (target_type
, refcode
);
16361 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16362 if (attr
!= nullptr)
16364 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16368 TYPE_LENGTH (type
) = cu_header
->addr_size
;
16370 maybe_set_alignment (cu
, die
, type
);
16371 return set_die_type (die
, type
, cu
);
16374 /* Add the given cv-qualifiers to the element type of the array. GCC
16375 outputs DWARF type qualifiers that apply to an array, not the
16376 element type. But GDB relies on the array element type to carry
16377 the cv-qualifiers. This mimics section 6.7.3 of the C99
16380 static struct type
*
16381 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16382 struct type
*base_type
, int cnst
, int voltl
)
16384 struct type
*el_type
, *inner_array
;
16386 base_type
= copy_type (base_type
);
16387 inner_array
= base_type
;
16389 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
16391 TYPE_TARGET_TYPE (inner_array
) =
16392 copy_type (TYPE_TARGET_TYPE (inner_array
));
16393 inner_array
= TYPE_TARGET_TYPE (inner_array
);
16396 el_type
= TYPE_TARGET_TYPE (inner_array
);
16397 cnst
|= TYPE_CONST (el_type
);
16398 voltl
|= TYPE_VOLATILE (el_type
);
16399 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
16401 return set_die_type (die
, base_type
, cu
);
16404 static struct type
*
16405 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16407 struct type
*base_type
, *cv_type
;
16409 base_type
= die_type (die
, cu
);
16411 /* The die_type call above may have already set the type for this DIE. */
16412 cv_type
= get_die_type (die
, cu
);
16416 /* In case the const qualifier is applied to an array type, the element type
16417 is so qualified, not the array type (section 6.7.3 of C99). */
16418 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
16419 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
16421 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
16422 return set_die_type (die
, cv_type
, cu
);
16425 static struct type
*
16426 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16428 struct type
*base_type
, *cv_type
;
16430 base_type
= die_type (die
, cu
);
16432 /* The die_type call above may have already set the type for this DIE. */
16433 cv_type
= get_die_type (die
, cu
);
16437 /* In case the volatile qualifier is applied to an array type, the
16438 element type is so qualified, not the array type (section 6.7.3
16440 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
16441 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
16443 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
16444 return set_die_type (die
, cv_type
, cu
);
16447 /* Handle DW_TAG_restrict_type. */
16449 static struct type
*
16450 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16452 struct type
*base_type
, *cv_type
;
16454 base_type
= die_type (die
, cu
);
16456 /* The die_type call above may have already set the type for this DIE. */
16457 cv_type
= get_die_type (die
, cu
);
16461 cv_type
= make_restrict_type (base_type
);
16462 return set_die_type (die
, cv_type
, cu
);
16465 /* Handle DW_TAG_atomic_type. */
16467 static struct type
*
16468 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16470 struct type
*base_type
, *cv_type
;
16472 base_type
= die_type (die
, cu
);
16474 /* The die_type call above may have already set the type for this DIE. */
16475 cv_type
= get_die_type (die
, cu
);
16479 cv_type
= make_atomic_type (base_type
);
16480 return set_die_type (die
, cv_type
, cu
);
16483 /* Extract all information from a DW_TAG_string_type DIE and add to
16484 the user defined type vector. It isn't really a user defined type,
16485 but it behaves like one, with other DIE's using an AT_user_def_type
16486 attribute to reference it. */
16488 static struct type
*
16489 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16491 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16492 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16493 struct type
*type
, *range_type
, *index_type
, *char_type
;
16494 struct attribute
*attr
;
16495 struct dynamic_prop prop
;
16496 bool length_is_constant
= true;
16499 /* There are a couple of places where bit sizes might be made use of
16500 when parsing a DW_TAG_string_type, however, no producer that we know
16501 of make use of these. Handling bit sizes that are a multiple of the
16502 byte size is easy enough, but what about other bit sizes? Lets deal
16503 with that problem when we have to. Warn about these attributes being
16504 unsupported, then parse the type and ignore them like we always
16506 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
16507 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
16509 static bool warning_printed
= false;
16510 if (!warning_printed
)
16512 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
16513 "currently supported on DW_TAG_string_type."));
16514 warning_printed
= true;
16518 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
16519 if (attr
!= nullptr && !attr
->form_is_constant ())
16521 /* The string length describes the location at which the length of
16522 the string can be found. The size of the length field can be
16523 specified with one of the attributes below. */
16524 struct type
*prop_type
;
16525 struct attribute
*len
16526 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
16527 if (len
== nullptr)
16528 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16529 if (len
!= nullptr && len
->form_is_constant ())
16531 /* Pass 0 as the default as we know this attribute is constant
16532 and the default value will not be returned. */
16533 LONGEST sz
= dwarf2_get_attr_constant_value (len
, 0);
16534 prop_type
= cu
->per_cu
->int_type (sz
, true);
16538 /* If the size is not specified then we assume it is the size of
16539 an address on this target. */
16540 prop_type
= cu
->per_cu
->addr_sized_int_type (true);
16543 /* Convert the attribute into a dynamic property. */
16544 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
16547 length_is_constant
= false;
16549 else if (attr
!= nullptr)
16551 /* This DW_AT_string_length just contains the length with no
16552 indirection. There's no need to create a dynamic property in this
16553 case. Pass 0 for the default value as we know it will not be
16554 returned in this case. */
16555 length
= dwarf2_get_attr_constant_value (attr
, 0);
16557 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
16559 /* We don't currently support non-constant byte sizes for strings. */
16560 length
= dwarf2_get_attr_constant_value (attr
, 1);
16564 /* Use 1 as a fallback length if we have nothing else. */
16568 index_type
= objfile_type (objfile
)->builtin_int
;
16569 if (length_is_constant
)
16570 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
16573 struct dynamic_prop low_bound
;
16575 low_bound
.kind
= PROP_CONST
;
16576 low_bound
.data
.const_val
= 1;
16577 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
16579 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
16580 type
= create_string_type (NULL
, char_type
, range_type
);
16582 return set_die_type (die
, type
, cu
);
16585 /* Assuming that DIE corresponds to a function, returns nonzero
16586 if the function is prototyped. */
16589 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
16591 struct attribute
*attr
;
16593 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
16594 if (attr
&& (DW_UNSND (attr
) != 0))
16597 /* The DWARF standard implies that the DW_AT_prototyped attribute
16598 is only meaningful for C, but the concept also extends to other
16599 languages that allow unprototyped functions (Eg: Objective C).
16600 For all other languages, assume that functions are always
16602 if (cu
->language
!= language_c
16603 && cu
->language
!= language_objc
16604 && cu
->language
!= language_opencl
)
16607 /* RealView does not emit DW_AT_prototyped. We can not distinguish
16608 prototyped and unprototyped functions; default to prototyped,
16609 since that is more common in modern code (and RealView warns
16610 about unprototyped functions). */
16611 if (producer_is_realview (cu
->producer
))
16617 /* Handle DIES due to C code like:
16621 int (*funcp)(int a, long l);
16625 ('funcp' generates a DW_TAG_subroutine_type DIE). */
16627 static struct type
*
16628 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16630 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16631 struct type
*type
; /* Type that this function returns. */
16632 struct type
*ftype
; /* Function that returns above type. */
16633 struct attribute
*attr
;
16635 type
= die_type (die
, cu
);
16637 /* The die_type call above may have already set the type for this DIE. */
16638 ftype
= get_die_type (die
, cu
);
16642 ftype
= lookup_function_type (type
);
16644 if (prototyped_function_p (die
, cu
))
16645 TYPE_PROTOTYPED (ftype
) = 1;
16647 /* Store the calling convention in the type if it's available in
16648 the subroutine die. Otherwise set the calling convention to
16649 the default value DW_CC_normal. */
16650 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
16651 if (attr
!= nullptr
16652 && is_valid_DW_AT_calling_convention_for_subroutine (DW_UNSND (attr
)))
16653 TYPE_CALLING_CONVENTION (ftype
)
16654 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
16655 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
16656 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
16658 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
16660 /* Record whether the function returns normally to its caller or not
16661 if the DWARF producer set that information. */
16662 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
16663 if (attr
&& (DW_UNSND (attr
) != 0))
16664 TYPE_NO_RETURN (ftype
) = 1;
16666 /* We need to add the subroutine type to the die immediately so
16667 we don't infinitely recurse when dealing with parameters
16668 declared as the same subroutine type. */
16669 set_die_type (die
, ftype
, cu
);
16671 if (die
->child
!= NULL
)
16673 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
16674 struct die_info
*child_die
;
16675 int nparams
, iparams
;
16677 /* Count the number of parameters.
16678 FIXME: GDB currently ignores vararg functions, but knows about
16679 vararg member functions. */
16681 child_die
= die
->child
;
16682 while (child_die
&& child_die
->tag
)
16684 if (child_die
->tag
== DW_TAG_formal_parameter
)
16686 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
16687 TYPE_VARARGS (ftype
) = 1;
16688 child_die
= sibling_die (child_die
);
16691 /* Allocate storage for parameters and fill them in. */
16692 TYPE_NFIELDS (ftype
) = nparams
;
16693 TYPE_FIELDS (ftype
) = (struct field
*)
16694 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
16696 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
16697 even if we error out during the parameters reading below. */
16698 for (iparams
= 0; iparams
< nparams
; iparams
++)
16699 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
16702 child_die
= die
->child
;
16703 while (child_die
&& child_die
->tag
)
16705 if (child_die
->tag
== DW_TAG_formal_parameter
)
16707 struct type
*arg_type
;
16709 /* DWARF version 2 has no clean way to discern C++
16710 static and non-static member functions. G++ helps
16711 GDB by marking the first parameter for non-static
16712 member functions (which is the this pointer) as
16713 artificial. We pass this information to
16714 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
16716 DWARF version 3 added DW_AT_object_pointer, which GCC
16717 4.5 does not yet generate. */
16718 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
16719 if (attr
!= nullptr)
16720 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
16722 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
16723 arg_type
= die_type (child_die
, cu
);
16725 /* RealView does not mark THIS as const, which the testsuite
16726 expects. GCC marks THIS as const in method definitions,
16727 but not in the class specifications (GCC PR 43053). */
16728 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
16729 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
16732 struct dwarf2_cu
*arg_cu
= cu
;
16733 const char *name
= dwarf2_name (child_die
, cu
);
16735 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
16736 if (attr
!= nullptr)
16738 /* If the compiler emits this, use it. */
16739 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
16742 else if (name
&& strcmp (name
, "this") == 0)
16743 /* Function definitions will have the argument names. */
16745 else if (name
== NULL
&& iparams
== 0)
16746 /* Declarations may not have the names, so like
16747 elsewhere in GDB, assume an artificial first
16748 argument is "this". */
16752 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
16756 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
16759 child_die
= sibling_die (child_die
);
16766 static struct type
*
16767 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
16769 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16770 const char *name
= NULL
;
16771 struct type
*this_type
, *target_type
;
16773 name
= dwarf2_full_name (NULL
, die
, cu
);
16774 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
16775 TYPE_TARGET_STUB (this_type
) = 1;
16776 set_die_type (die
, this_type
, cu
);
16777 target_type
= die_type (die
, cu
);
16778 if (target_type
!= this_type
)
16779 TYPE_TARGET_TYPE (this_type
) = target_type
;
16782 /* Self-referential typedefs are, it seems, not allowed by the DWARF
16783 spec and cause infinite loops in GDB. */
16784 complaint (_("Self-referential DW_TAG_typedef "
16785 "- DIE at %s [in module %s]"),
16786 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
16787 TYPE_TARGET_TYPE (this_type
) = NULL
;
16792 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
16793 (which may be different from NAME) to the architecture back-end to allow
16794 it to guess the correct format if necessary. */
16796 static struct type
*
16797 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
16798 const char *name_hint
, enum bfd_endian byte_order
)
16800 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16801 const struct floatformat
**format
;
16804 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
16806 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
16808 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
16813 /* Allocate an integer type of size BITS and name NAME. */
16815 static struct type
*
16816 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
16817 int bits
, int unsigned_p
, const char *name
)
16821 /* Versions of Intel's C Compiler generate an integer type called "void"
16822 instead of using DW_TAG_unspecified_type. This has been seen on
16823 at least versions 14, 17, and 18. */
16824 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
16825 && strcmp (name
, "void") == 0)
16826 type
= objfile_type (objfile
)->builtin_void
;
16828 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
16833 /* Initialise and return a floating point type of size BITS suitable for
16834 use as a component of a complex number. The NAME_HINT is passed through
16835 when initialising the floating point type and is the name of the complex
16838 As DWARF doesn't currently provide an explicit name for the components
16839 of a complex number, but it can be helpful to have these components
16840 named, we try to select a suitable name based on the size of the
16842 static struct type
*
16843 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
16844 struct objfile
*objfile
,
16845 int bits
, const char *name_hint
,
16846 enum bfd_endian byte_order
)
16848 gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16849 struct type
*tt
= nullptr;
16851 /* Try to find a suitable floating point builtin type of size BITS.
16852 We're going to use the name of this type as the name for the complex
16853 target type that we are about to create. */
16854 switch (cu
->language
)
16856 case language_fortran
:
16860 tt
= builtin_f_type (gdbarch
)->builtin_real
;
16863 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
16865 case 96: /* The x86-32 ABI specifies 96-bit long double. */
16867 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
16875 tt
= builtin_type (gdbarch
)->builtin_float
;
16878 tt
= builtin_type (gdbarch
)->builtin_double
;
16880 case 96: /* The x86-32 ABI specifies 96-bit long double. */
16882 tt
= builtin_type (gdbarch
)->builtin_long_double
;
16888 /* If the type we found doesn't match the size we were looking for, then
16889 pretend we didn't find a type at all, the complex target type we
16890 create will then be nameless. */
16891 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
16894 const char *name
= (tt
== nullptr) ? nullptr : TYPE_NAME (tt
);
16895 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
16898 /* Find a representation of a given base type and install
16899 it in the TYPE field of the die. */
16901 static struct type
*
16902 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16904 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16906 struct attribute
*attr
;
16907 int encoding
= 0, bits
= 0;
16911 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
16912 if (attr
!= nullptr)
16913 encoding
= DW_UNSND (attr
);
16914 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16915 if (attr
!= nullptr)
16916 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
16917 name
= dwarf2_name (die
, cu
);
16919 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
16921 arch
= get_objfile_arch (objfile
);
16922 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
16924 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
16927 int endianity
= DW_UNSND (attr
);
16932 byte_order
= BFD_ENDIAN_BIG
;
16934 case DW_END_little
:
16935 byte_order
= BFD_ENDIAN_LITTLE
;
16938 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
16945 case DW_ATE_address
:
16946 /* Turn DW_ATE_address into a void * pointer. */
16947 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
16948 type
= init_pointer_type (objfile
, bits
, name
, type
);
16950 case DW_ATE_boolean
:
16951 type
= init_boolean_type (objfile
, bits
, 1, name
);
16953 case DW_ATE_complex_float
:
16954 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
16956 type
= init_complex_type (objfile
, name
, type
);
16958 case DW_ATE_decimal_float
:
16959 type
= init_decfloat_type (objfile
, bits
, name
);
16962 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
16964 case DW_ATE_signed
:
16965 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
16967 case DW_ATE_unsigned
:
16968 if (cu
->language
== language_fortran
16970 && startswith (name
, "character("))
16971 type
= init_character_type (objfile
, bits
, 1, name
);
16973 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
16975 case DW_ATE_signed_char
:
16976 if (cu
->language
== language_ada
|| cu
->language
== language_m2
16977 || cu
->language
== language_pascal
16978 || cu
->language
== language_fortran
)
16979 type
= init_character_type (objfile
, bits
, 0, name
);
16981 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
16983 case DW_ATE_unsigned_char
:
16984 if (cu
->language
== language_ada
|| cu
->language
== language_m2
16985 || cu
->language
== language_pascal
16986 || cu
->language
== language_fortran
16987 || cu
->language
== language_rust
)
16988 type
= init_character_type (objfile
, bits
, 1, name
);
16990 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
16995 type
= builtin_type (arch
)->builtin_char16
;
16996 else if (bits
== 32)
16997 type
= builtin_type (arch
)->builtin_char32
;
17000 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
17002 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17004 return set_die_type (die
, type
, cu
);
17009 complaint (_("unsupported DW_AT_encoding: '%s'"),
17010 dwarf_type_encoding_name (encoding
));
17011 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17015 if (name
&& strcmp (name
, "char") == 0)
17016 TYPE_NOSIGN (type
) = 1;
17018 maybe_set_alignment (cu
, die
, type
);
17020 TYPE_ENDIANITY_NOT_DEFAULT (type
) = gdbarch_byte_order (arch
) != byte_order
;
17022 return set_die_type (die
, type
, cu
);
17025 /* Parse dwarf attribute if it's a block, reference or constant and put the
17026 resulting value of the attribute into struct bound_prop.
17027 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17030 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17031 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
17032 struct type
*default_type
)
17034 struct dwarf2_property_baton
*baton
;
17035 struct obstack
*obstack
17036 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
17038 gdb_assert (default_type
!= NULL
);
17040 if (attr
== NULL
|| prop
== NULL
)
17043 if (attr
->form_is_block ())
17045 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17046 baton
->property_type
= default_type
;
17047 baton
->locexpr
.per_cu
= cu
->per_cu
;
17048 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17049 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17050 switch (attr
->name
)
17052 case DW_AT_string_length
:
17053 baton
->locexpr
.is_reference
= true;
17056 baton
->locexpr
.is_reference
= false;
17059 prop
->data
.baton
= baton
;
17060 prop
->kind
= PROP_LOCEXPR
;
17061 gdb_assert (prop
->data
.baton
!= NULL
);
17063 else if (attr
->form_is_ref ())
17065 struct dwarf2_cu
*target_cu
= cu
;
17066 struct die_info
*target_die
;
17067 struct attribute
*target_attr
;
17069 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17070 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17071 if (target_attr
== NULL
)
17072 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17074 if (target_attr
== NULL
)
17077 switch (target_attr
->name
)
17079 case DW_AT_location
:
17080 if (target_attr
->form_is_section_offset ())
17082 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17083 baton
->property_type
= die_type (target_die
, target_cu
);
17084 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17085 prop
->data
.baton
= baton
;
17086 prop
->kind
= PROP_LOCLIST
;
17087 gdb_assert (prop
->data
.baton
!= NULL
);
17089 else if (target_attr
->form_is_block ())
17091 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17092 baton
->property_type
= die_type (target_die
, target_cu
);
17093 baton
->locexpr
.per_cu
= cu
->per_cu
;
17094 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17095 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17096 baton
->locexpr
.is_reference
= true;
17097 prop
->data
.baton
= baton
;
17098 prop
->kind
= PROP_LOCEXPR
;
17099 gdb_assert (prop
->data
.baton
!= NULL
);
17103 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17104 "dynamic property");
17108 case DW_AT_data_member_location
:
17112 if (!handle_data_member_location (target_die
, target_cu
,
17116 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17117 baton
->property_type
= read_type_die (target_die
->parent
,
17119 baton
->offset_info
.offset
= offset
;
17120 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17121 prop
->data
.baton
= baton
;
17122 prop
->kind
= PROP_ADDR_OFFSET
;
17127 else if (attr
->form_is_constant ())
17129 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
17130 prop
->kind
= PROP_CONST
;
17134 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17135 dwarf2_name (die
, cu
));
17145 dwarf2_per_cu_data::int_type (int size_in_bytes
, bool unsigned_p
) const
17147 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17148 struct type
*int_type
;
17150 /* Helper macro to examine the various builtin types. */
17151 #define TRY_TYPE(F) \
17152 int_type = (unsigned_p \
17153 ? objfile_type (objfile)->builtin_unsigned_ ## F \
17154 : objfile_type (objfile)->builtin_ ## F); \
17155 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
17162 TRY_TYPE (long_long
);
17166 gdb_assert_not_reached ("unable to find suitable integer type");
17172 dwarf2_per_cu_data::addr_sized_int_type (bool unsigned_p
) const
17174 int addr_size
= this->addr_size ();
17175 return int_type (addr_size
, unsigned_p
);
17178 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
17179 present (which is valid) then compute the default type based on the
17180 compilation units address size. */
17182 static struct type
*
17183 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17185 struct type
*index_type
= die_type (die
, cu
);
17187 /* Dwarf-2 specifications explicitly allows to create subrange types
17188 without specifying a base type.
17189 In that case, the base type must be set to the type of
17190 the lower bound, upper bound or count, in that order, if any of these
17191 three attributes references an object that has a type.
17192 If no base type is found, the Dwarf-2 specifications say that
17193 a signed integer type of size equal to the size of an address should
17195 For the following C code: `extern char gdb_int [];'
17196 GCC produces an empty range DIE.
17197 FIXME: muller/2010-05-28: Possible references to object for low bound,
17198 high bound or count are not yet handled by this code. */
17199 if (TYPE_CODE (index_type
) == TYPE_CODE_VOID
)
17200 index_type
= cu
->per_cu
->addr_sized_int_type (false);
17205 /* Read the given DW_AT_subrange DIE. */
17207 static struct type
*
17208 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17210 struct type
*base_type
, *orig_base_type
;
17211 struct type
*range_type
;
17212 struct attribute
*attr
;
17213 struct dynamic_prop low
, high
;
17214 int low_default_is_valid
;
17215 int high_bound_is_count
= 0;
17217 ULONGEST negative_mask
;
17219 orig_base_type
= read_subrange_index_type (die
, cu
);
17221 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17222 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17223 creating the range type, but we use the result of check_typedef
17224 when examining properties of the type. */
17225 base_type
= check_typedef (orig_base_type
);
17227 /* The die_type call above may have already set the type for this DIE. */
17228 range_type
= get_die_type (die
, cu
);
17232 low
.kind
= PROP_CONST
;
17233 high
.kind
= PROP_CONST
;
17234 high
.data
.const_val
= 0;
17236 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17237 omitting DW_AT_lower_bound. */
17238 switch (cu
->language
)
17241 case language_cplus
:
17242 low
.data
.const_val
= 0;
17243 low_default_is_valid
= 1;
17245 case language_fortran
:
17246 low
.data
.const_val
= 1;
17247 low_default_is_valid
= 1;
17250 case language_objc
:
17251 case language_rust
:
17252 low
.data
.const_val
= 0;
17253 low_default_is_valid
= (cu
->header
.version
>= 4);
17257 case language_pascal
:
17258 low
.data
.const_val
= 1;
17259 low_default_is_valid
= (cu
->header
.version
>= 4);
17262 low
.data
.const_val
= 0;
17263 low_default_is_valid
= 0;
17267 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
17268 if (attr
!= nullptr)
17269 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
17270 else if (!low_default_is_valid
)
17271 complaint (_("Missing DW_AT_lower_bound "
17272 "- DIE at %s [in module %s]"),
17273 sect_offset_str (die
->sect_off
),
17274 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17276 struct attribute
*attr_ub
, *attr_count
;
17277 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
17278 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17280 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
17281 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17283 /* If bounds are constant do the final calculation here. */
17284 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
17285 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
17287 high_bound_is_count
= 1;
17291 if (attr_ub
!= NULL
)
17292 complaint (_("Unresolved DW_AT_upper_bound "
17293 "- DIE at %s [in module %s]"),
17294 sect_offset_str (die
->sect_off
),
17295 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17296 if (attr_count
!= NULL
)
17297 complaint (_("Unresolved DW_AT_count "
17298 "- DIE at %s [in module %s]"),
17299 sect_offset_str (die
->sect_off
),
17300 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17305 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
17306 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
17307 bias
= dwarf2_get_attr_constant_value (bias_attr
, 0);
17309 /* Normally, the DWARF producers are expected to use a signed
17310 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17311 But this is unfortunately not always the case, as witnessed
17312 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17313 is used instead. To work around that ambiguity, we treat
17314 the bounds as signed, and thus sign-extend their values, when
17315 the base type is signed. */
17317 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
17318 if (low
.kind
== PROP_CONST
17319 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
17320 low
.data
.const_val
|= negative_mask
;
17321 if (high
.kind
== PROP_CONST
17322 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
17323 high
.data
.const_val
|= negative_mask
;
17325 /* Check for bit and byte strides. */
17326 struct dynamic_prop byte_stride_prop
;
17327 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
17328 if (attr_byte_stride
!= nullptr)
17330 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
17331 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
17335 struct dynamic_prop bit_stride_prop
;
17336 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
17337 if (attr_bit_stride
!= nullptr)
17339 /* It only makes sense to have either a bit or byte stride. */
17340 if (attr_byte_stride
!= nullptr)
17342 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
17343 "- DIE at %s [in module %s]"),
17344 sect_offset_str (die
->sect_off
),
17345 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17346 attr_bit_stride
= nullptr;
17350 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
17351 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
17356 if (attr_byte_stride
!= nullptr
17357 || attr_bit_stride
!= nullptr)
17359 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
17360 struct dynamic_prop
*stride
17361 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
17364 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
17365 &high
, bias
, stride
, byte_stride_p
);
17368 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
17370 if (high_bound_is_count
)
17371 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
17373 /* Ada expects an empty array on no boundary attributes. */
17374 if (attr
== NULL
&& cu
->language
!= language_ada
)
17375 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
17377 name
= dwarf2_name (die
, cu
);
17379 TYPE_NAME (range_type
) = name
;
17381 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17382 if (attr
!= nullptr)
17383 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
17385 maybe_set_alignment (cu
, die
, range_type
);
17387 set_die_type (die
, range_type
, cu
);
17389 /* set_die_type should be already done. */
17390 set_descriptive_type (range_type
, die
, cu
);
17395 static struct type
*
17396 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17400 type
= init_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
, TYPE_CODE_VOID
,0,
17402 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
17404 /* In Ada, an unspecified type is typically used when the description
17405 of the type is deferred to a different unit. When encountering
17406 such a type, we treat it as a stub, and try to resolve it later on,
17408 if (cu
->language
== language_ada
)
17409 TYPE_STUB (type
) = 1;
17411 return set_die_type (die
, type
, cu
);
17414 /* Read a single die and all its descendents. Set the die's sibling
17415 field to NULL; set other fields in the die correctly, and set all
17416 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
17417 location of the info_ptr after reading all of those dies. PARENT
17418 is the parent of the die in question. */
17420 static struct die_info
*
17421 read_die_and_children (const struct die_reader_specs
*reader
,
17422 const gdb_byte
*info_ptr
,
17423 const gdb_byte
**new_info_ptr
,
17424 struct die_info
*parent
)
17426 struct die_info
*die
;
17427 const gdb_byte
*cur_ptr
;
17429 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
17432 *new_info_ptr
= cur_ptr
;
17435 store_in_ref_table (die
, reader
->cu
);
17437 if (die
->has_children
)
17438 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
17442 *new_info_ptr
= cur_ptr
;
17445 die
->sibling
= NULL
;
17446 die
->parent
= parent
;
17450 /* Read a die, all of its descendents, and all of its siblings; set
17451 all of the fields of all of the dies correctly. Arguments are as
17452 in read_die_and_children. */
17454 static struct die_info
*
17455 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
17456 const gdb_byte
*info_ptr
,
17457 const gdb_byte
**new_info_ptr
,
17458 struct die_info
*parent
)
17460 struct die_info
*first_die
, *last_sibling
;
17461 const gdb_byte
*cur_ptr
;
17463 cur_ptr
= info_ptr
;
17464 first_die
= last_sibling
= NULL
;
17468 struct die_info
*die
17469 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
17473 *new_info_ptr
= cur_ptr
;
17480 last_sibling
->sibling
= die
;
17482 last_sibling
= die
;
17486 /* Read a die, all of its descendents, and all of its siblings; set
17487 all of the fields of all of the dies correctly. Arguments are as
17488 in read_die_and_children.
17489 This the main entry point for reading a DIE and all its children. */
17491 static struct die_info
*
17492 read_die_and_siblings (const struct die_reader_specs
*reader
,
17493 const gdb_byte
*info_ptr
,
17494 const gdb_byte
**new_info_ptr
,
17495 struct die_info
*parent
)
17497 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
17498 new_info_ptr
, parent
);
17500 if (dwarf_die_debug
)
17502 fprintf_unfiltered (gdb_stdlog
,
17503 "Read die from %s@0x%x of %s:\n",
17504 reader
->die_section
->get_name (),
17505 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17506 bfd_get_filename (reader
->abfd
));
17507 dump_die (die
, dwarf_die_debug
);
17513 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
17515 The caller is responsible for filling in the extra attributes
17516 and updating (*DIEP)->num_attrs.
17517 Set DIEP to point to a newly allocated die with its information,
17518 except for its child, sibling, and parent fields. */
17520 static const gdb_byte
*
17521 read_full_die_1 (const struct die_reader_specs
*reader
,
17522 struct die_info
**diep
, const gdb_byte
*info_ptr
,
17523 int num_extra_attrs
)
17525 unsigned int abbrev_number
, bytes_read
, i
;
17526 struct abbrev_info
*abbrev
;
17527 struct die_info
*die
;
17528 struct dwarf2_cu
*cu
= reader
->cu
;
17529 bfd
*abfd
= reader
->abfd
;
17531 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
17532 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
17533 info_ptr
+= bytes_read
;
17534 if (!abbrev_number
)
17540 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
17542 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
17544 bfd_get_filename (abfd
));
17546 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
17547 die
->sect_off
= sect_off
;
17548 die
->tag
= abbrev
->tag
;
17549 die
->abbrev
= abbrev_number
;
17550 die
->has_children
= abbrev
->has_children
;
17552 /* Make the result usable.
17553 The caller needs to update num_attrs after adding the extra
17555 die
->num_attrs
= abbrev
->num_attrs
;
17557 std::vector
<int> indexes_that_need_reprocess
;
17558 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
17560 bool need_reprocess
;
17562 read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
17563 info_ptr
, &need_reprocess
);
17564 if (need_reprocess
)
17565 indexes_that_need_reprocess
.push_back (i
);
17568 struct attribute
*attr
= dwarf2_attr_no_follow (die
, DW_AT_str_offsets_base
);
17569 if (attr
!= nullptr)
17570 cu
->str_offsets_base
= DW_UNSND (attr
);
17572 auto maybe_addr_base
= lookup_addr_base(die
);
17573 if (maybe_addr_base
.has_value ())
17574 cu
->addr_base
= *maybe_addr_base
;
17575 for (int index
: indexes_that_need_reprocess
)
17576 read_attribute_reprocess (reader
, &die
->attrs
[index
]);
17581 /* Read a die and all its attributes.
17582 Set DIEP to point to a newly allocated die with its information,
17583 except for its child, sibling, and parent fields. */
17585 static const gdb_byte
*
17586 read_full_die (const struct die_reader_specs
*reader
,
17587 struct die_info
**diep
, const gdb_byte
*info_ptr
)
17589 const gdb_byte
*result
;
17591 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
17593 if (dwarf_die_debug
)
17595 fprintf_unfiltered (gdb_stdlog
,
17596 "Read die from %s@0x%x of %s:\n",
17597 reader
->die_section
->get_name (),
17598 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17599 bfd_get_filename (reader
->abfd
));
17600 dump_die (*diep
, dwarf_die_debug
);
17607 /* Returns nonzero if TAG represents a type that we might generate a partial
17611 is_type_tag_for_partial (int tag
)
17616 /* Some types that would be reasonable to generate partial symbols for,
17617 that we don't at present. */
17618 case DW_TAG_array_type
:
17619 case DW_TAG_file_type
:
17620 case DW_TAG_ptr_to_member_type
:
17621 case DW_TAG_set_type
:
17622 case DW_TAG_string_type
:
17623 case DW_TAG_subroutine_type
:
17625 case DW_TAG_base_type
:
17626 case DW_TAG_class_type
:
17627 case DW_TAG_interface_type
:
17628 case DW_TAG_enumeration_type
:
17629 case DW_TAG_structure_type
:
17630 case DW_TAG_subrange_type
:
17631 case DW_TAG_typedef
:
17632 case DW_TAG_union_type
:
17639 /* Load all DIEs that are interesting for partial symbols into memory. */
17641 static struct partial_die_info
*
17642 load_partial_dies (const struct die_reader_specs
*reader
,
17643 const gdb_byte
*info_ptr
, int building_psymtab
)
17645 struct dwarf2_cu
*cu
= reader
->cu
;
17646 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17647 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
17648 unsigned int bytes_read
;
17649 unsigned int load_all
= 0;
17650 int nesting_level
= 1;
17655 gdb_assert (cu
->per_cu
!= NULL
);
17656 if (cu
->per_cu
->load_all_dies
)
17660 = htab_create_alloc_ex (cu
->header
.length
/ 12,
17664 &cu
->comp_unit_obstack
,
17665 hashtab_obstack_allocate
,
17666 dummy_obstack_deallocate
);
17670 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
17672 /* A NULL abbrev means the end of a series of children. */
17673 if (abbrev
== NULL
)
17675 if (--nesting_level
== 0)
17678 info_ptr
+= bytes_read
;
17679 last_die
= parent_die
;
17680 parent_die
= parent_die
->die_parent
;
17684 /* Check for template arguments. We never save these; if
17685 they're seen, we just mark the parent, and go on our way. */
17686 if (parent_die
!= NULL
17687 && cu
->language
== language_cplus
17688 && (abbrev
->tag
== DW_TAG_template_type_param
17689 || abbrev
->tag
== DW_TAG_template_value_param
))
17691 parent_die
->has_template_arguments
= 1;
17695 /* We don't need a partial DIE for the template argument. */
17696 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17701 /* We only recurse into c++ subprograms looking for template arguments.
17702 Skip their other children. */
17704 && cu
->language
== language_cplus
17705 && parent_die
!= NULL
17706 && parent_die
->tag
== DW_TAG_subprogram
)
17708 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17712 /* Check whether this DIE is interesting enough to save. Normally
17713 we would not be interested in members here, but there may be
17714 later variables referencing them via DW_AT_specification (for
17715 static members). */
17717 && !is_type_tag_for_partial (abbrev
->tag
)
17718 && abbrev
->tag
!= DW_TAG_constant
17719 && abbrev
->tag
!= DW_TAG_enumerator
17720 && abbrev
->tag
!= DW_TAG_subprogram
17721 && abbrev
->tag
!= DW_TAG_inlined_subroutine
17722 && abbrev
->tag
!= DW_TAG_lexical_block
17723 && abbrev
->tag
!= DW_TAG_variable
17724 && abbrev
->tag
!= DW_TAG_namespace
17725 && abbrev
->tag
!= DW_TAG_module
17726 && abbrev
->tag
!= DW_TAG_member
17727 && abbrev
->tag
!= DW_TAG_imported_unit
17728 && abbrev
->tag
!= DW_TAG_imported_declaration
)
17730 /* Otherwise we skip to the next sibling, if any. */
17731 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17735 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
17738 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
17740 /* This two-pass algorithm for processing partial symbols has a
17741 high cost in cache pressure. Thus, handle some simple cases
17742 here which cover the majority of C partial symbols. DIEs
17743 which neither have specification tags in them, nor could have
17744 specification tags elsewhere pointing at them, can simply be
17745 processed and discarded.
17747 This segment is also optional; scan_partial_symbols and
17748 add_partial_symbol will handle these DIEs if we chain
17749 them in normally. When compilers which do not emit large
17750 quantities of duplicate debug information are more common,
17751 this code can probably be removed. */
17753 /* Any complete simple types at the top level (pretty much all
17754 of them, for a language without namespaces), can be processed
17756 if (parent_die
== NULL
17757 && pdi
.has_specification
== 0
17758 && pdi
.is_declaration
== 0
17759 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
17760 || pdi
.tag
== DW_TAG_base_type
17761 || pdi
.tag
== DW_TAG_subrange_type
))
17763 if (building_psymtab
&& pdi
.name
!= NULL
)
17764 add_psymbol_to_list (pdi
.name
, false,
17765 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
17766 psymbol_placement::STATIC
,
17767 0, cu
->language
, objfile
);
17768 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
17772 /* The exception for DW_TAG_typedef with has_children above is
17773 a workaround of GCC PR debug/47510. In the case of this complaint
17774 type_name_or_error will error on such types later.
17776 GDB skipped children of DW_TAG_typedef by the shortcut above and then
17777 it could not find the child DIEs referenced later, this is checked
17778 above. In correct DWARF DW_TAG_typedef should have no children. */
17780 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
17781 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
17782 "- DIE at %s [in module %s]"),
17783 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
17785 /* If we're at the second level, and we're an enumerator, and
17786 our parent has no specification (meaning possibly lives in a
17787 namespace elsewhere), then we can add the partial symbol now
17788 instead of queueing it. */
17789 if (pdi
.tag
== DW_TAG_enumerator
17790 && parent_die
!= NULL
17791 && parent_die
->die_parent
== NULL
17792 && parent_die
->tag
== DW_TAG_enumeration_type
17793 && parent_die
->has_specification
== 0)
17795 if (pdi
.name
== NULL
)
17796 complaint (_("malformed enumerator DIE ignored"));
17797 else if (building_psymtab
)
17798 add_psymbol_to_list (pdi
.name
, false,
17799 VAR_DOMAIN
, LOC_CONST
, -1,
17800 cu
->language
== language_cplus
17801 ? psymbol_placement::GLOBAL
17802 : psymbol_placement::STATIC
,
17803 0, cu
->language
, objfile
);
17805 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
17809 struct partial_die_info
*part_die
17810 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
17812 /* We'll save this DIE so link it in. */
17813 part_die
->die_parent
= parent_die
;
17814 part_die
->die_sibling
= NULL
;
17815 part_die
->die_child
= NULL
;
17817 if (last_die
&& last_die
== parent_die
)
17818 last_die
->die_child
= part_die
;
17820 last_die
->die_sibling
= part_die
;
17822 last_die
= part_die
;
17824 if (first_die
== NULL
)
17825 first_die
= part_die
;
17827 /* Maybe add the DIE to the hash table. Not all DIEs that we
17828 find interesting need to be in the hash table, because we
17829 also have the parent/sibling/child chains; only those that we
17830 might refer to by offset later during partial symbol reading.
17832 For now this means things that might have be the target of a
17833 DW_AT_specification, DW_AT_abstract_origin, or
17834 DW_AT_extension. DW_AT_extension will refer only to
17835 namespaces; DW_AT_abstract_origin refers to functions (and
17836 many things under the function DIE, but we do not recurse
17837 into function DIEs during partial symbol reading) and
17838 possibly variables as well; DW_AT_specification refers to
17839 declarations. Declarations ought to have the DW_AT_declaration
17840 flag. It happens that GCC forgets to put it in sometimes, but
17841 only for functions, not for types.
17843 Adding more things than necessary to the hash table is harmless
17844 except for the performance cost. Adding too few will result in
17845 wasted time in find_partial_die, when we reread the compilation
17846 unit with load_all_dies set. */
17849 || abbrev
->tag
== DW_TAG_constant
17850 || abbrev
->tag
== DW_TAG_subprogram
17851 || abbrev
->tag
== DW_TAG_variable
17852 || abbrev
->tag
== DW_TAG_namespace
17853 || part_die
->is_declaration
)
17857 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
17858 to_underlying (part_die
->sect_off
),
17863 /* For some DIEs we want to follow their children (if any). For C
17864 we have no reason to follow the children of structures; for other
17865 languages we have to, so that we can get at method physnames
17866 to infer fully qualified class names, for DW_AT_specification,
17867 and for C++ template arguments. For C++, we also look one level
17868 inside functions to find template arguments (if the name of the
17869 function does not already contain the template arguments).
17871 For Ada and Fortran, we need to scan the children of subprograms
17872 and lexical blocks as well because these languages allow the
17873 definition of nested entities that could be interesting for the
17874 debugger, such as nested subprograms for instance. */
17875 if (last_die
->has_children
17877 || last_die
->tag
== DW_TAG_namespace
17878 || last_die
->tag
== DW_TAG_module
17879 || last_die
->tag
== DW_TAG_enumeration_type
17880 || (cu
->language
== language_cplus
17881 && last_die
->tag
== DW_TAG_subprogram
17882 && (last_die
->name
== NULL
17883 || strchr (last_die
->name
, '<') == NULL
))
17884 || (cu
->language
!= language_c
17885 && (last_die
->tag
== DW_TAG_class_type
17886 || last_die
->tag
== DW_TAG_interface_type
17887 || last_die
->tag
== DW_TAG_structure_type
17888 || last_die
->tag
== DW_TAG_union_type
))
17889 || ((cu
->language
== language_ada
17890 || cu
->language
== language_fortran
)
17891 && (last_die
->tag
== DW_TAG_subprogram
17892 || last_die
->tag
== DW_TAG_lexical_block
))))
17895 parent_die
= last_die
;
17899 /* Otherwise we skip to the next sibling, if any. */
17900 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
17902 /* Back to the top, do it again. */
17906 partial_die_info::partial_die_info (sect_offset sect_off_
,
17907 struct abbrev_info
*abbrev
)
17908 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
17912 /* Read a minimal amount of information into the minimal die structure.
17913 INFO_PTR should point just after the initial uleb128 of a DIE. */
17916 partial_die_info::read (const struct die_reader_specs
*reader
,
17917 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
17919 struct dwarf2_cu
*cu
= reader
->cu
;
17920 struct dwarf2_per_objfile
*dwarf2_per_objfile
17921 = cu
->per_cu
->dwarf2_per_objfile
;
17923 int has_low_pc_attr
= 0;
17924 int has_high_pc_attr
= 0;
17925 int high_pc_relative
= 0;
17927 std::vector
<struct attribute
> attr_vec (abbrev
.num_attrs
);
17928 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
17930 bool need_reprocess
;
17931 info_ptr
= read_attribute (reader
, &attr_vec
[i
], &abbrev
.attrs
[i
],
17932 info_ptr
, &need_reprocess
);
17933 /* String and address offsets that need to do the reprocessing have
17934 already been read at this point, so there is no need to wait until
17935 the loop terminates to do the reprocessing. */
17936 if (need_reprocess
)
17937 read_attribute_reprocess (reader
, &attr_vec
[i
]);
17938 attribute
&attr
= attr_vec
[i
];
17939 /* Store the data if it is of an attribute we want to keep in a
17940 partial symbol table. */
17946 case DW_TAG_compile_unit
:
17947 case DW_TAG_partial_unit
:
17948 case DW_TAG_type_unit
:
17949 /* Compilation units have a DW_AT_name that is a filename, not
17950 a source language identifier. */
17951 case DW_TAG_enumeration_type
:
17952 case DW_TAG_enumerator
:
17953 /* These tags always have simple identifiers already; no need
17954 to canonicalize them. */
17955 name
= DW_STRING (&attr
);
17959 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17962 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
17963 &objfile
->per_bfd
->storage_obstack
);
17968 case DW_AT_linkage_name
:
17969 case DW_AT_MIPS_linkage_name
:
17970 /* Note that both forms of linkage name might appear. We
17971 assume they will be the same, and we only store the last
17973 linkage_name
= DW_STRING (&attr
);
17976 has_low_pc_attr
= 1;
17977 lowpc
= attr
.value_as_address ();
17979 case DW_AT_high_pc
:
17980 has_high_pc_attr
= 1;
17981 highpc
= attr
.value_as_address ();
17982 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
17983 high_pc_relative
= 1;
17985 case DW_AT_location
:
17986 /* Support the .debug_loc offsets. */
17987 if (attr
.form_is_block ())
17989 d
.locdesc
= DW_BLOCK (&attr
);
17991 else if (attr
.form_is_section_offset ())
17993 dwarf2_complex_location_expr_complaint ();
17997 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17998 "partial symbol information");
18001 case DW_AT_external
:
18002 is_external
= DW_UNSND (&attr
);
18004 case DW_AT_declaration
:
18005 is_declaration
= DW_UNSND (&attr
);
18010 case DW_AT_abstract_origin
:
18011 case DW_AT_specification
:
18012 case DW_AT_extension
:
18013 has_specification
= 1;
18014 spec_offset
= dwarf2_get_ref_die_offset (&attr
);
18015 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18016 || cu
->per_cu
->is_dwz
);
18018 case DW_AT_sibling
:
18019 /* Ignore absolute siblings, they might point outside of
18020 the current compile unit. */
18021 if (attr
.form
== DW_FORM_ref_addr
)
18022 complaint (_("ignoring absolute DW_AT_sibling"));
18025 const gdb_byte
*buffer
= reader
->buffer
;
18026 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
18027 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
18029 if (sibling_ptr
< info_ptr
)
18030 complaint (_("DW_AT_sibling points backwards"));
18031 else if (sibling_ptr
> reader
->buffer_end
)
18032 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
18034 sibling
= sibling_ptr
;
18037 case DW_AT_byte_size
:
18040 case DW_AT_const_value
:
18041 has_const_value
= 1;
18043 case DW_AT_calling_convention
:
18044 /* DWARF doesn't provide a way to identify a program's source-level
18045 entry point. DW_AT_calling_convention attributes are only meant
18046 to describe functions' calling conventions.
18048 However, because it's a necessary piece of information in
18049 Fortran, and before DWARF 4 DW_CC_program was the only
18050 piece of debugging information whose definition refers to
18051 a 'main program' at all, several compilers marked Fortran
18052 main programs with DW_CC_program --- even when those
18053 functions use the standard calling conventions.
18055 Although DWARF now specifies a way to provide this
18056 information, we support this practice for backward
18058 if (DW_UNSND (&attr
) == DW_CC_program
18059 && cu
->language
== language_fortran
)
18060 main_subprogram
= 1;
18063 if (DW_UNSND (&attr
) == DW_INL_inlined
18064 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
18065 may_be_inlined
= 1;
18069 if (tag
== DW_TAG_imported_unit
)
18071 d
.sect_off
= dwarf2_get_ref_die_offset (&attr
);
18072 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18073 || cu
->per_cu
->is_dwz
);
18077 case DW_AT_main_subprogram
:
18078 main_subprogram
= DW_UNSND (&attr
);
18083 /* It would be nice to reuse dwarf2_get_pc_bounds here,
18084 but that requires a full DIE, so instead we just
18086 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
18087 unsigned int ranges_offset
= (DW_UNSND (&attr
)
18088 + (need_ranges_base
18092 /* Value of the DW_AT_ranges attribute is the offset in the
18093 .debug_ranges section. */
18094 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
18105 /* For Ada, if both the name and the linkage name appear, we prefer
18106 the latter. This lets "catch exception" work better, regardless
18107 of the order in which the name and linkage name were emitted.
18108 Really, though, this is just a workaround for the fact that gdb
18109 doesn't store both the name and the linkage name. */
18110 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
18111 name
= linkage_name
;
18113 if (high_pc_relative
)
18116 if (has_low_pc_attr
&& has_high_pc_attr
)
18118 /* When using the GNU linker, .gnu.linkonce. sections are used to
18119 eliminate duplicate copies of functions and vtables and such.
18120 The linker will arbitrarily choose one and discard the others.
18121 The AT_*_pc values for such functions refer to local labels in
18122 these sections. If the section from that file was discarded, the
18123 labels are not in the output, so the relocs get a value of 0.
18124 If this is a discarded function, mark the pc bounds as invalid,
18125 so that GDB will ignore it. */
18126 if (lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
18128 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18129 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18131 complaint (_("DW_AT_low_pc %s is zero "
18132 "for DIE at %s [in module %s]"),
18133 paddress (gdbarch
, lowpc
),
18134 sect_offset_str (sect_off
),
18135 objfile_name (objfile
));
18137 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
18138 else if (lowpc
>= highpc
)
18140 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18141 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18143 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
18144 "for DIE at %s [in module %s]"),
18145 paddress (gdbarch
, lowpc
),
18146 paddress (gdbarch
, highpc
),
18147 sect_offset_str (sect_off
),
18148 objfile_name (objfile
));
18157 /* Find a cached partial DIE at OFFSET in CU. */
18159 struct partial_die_info
*
18160 dwarf2_cu::find_partial_die (sect_offset sect_off
)
18162 struct partial_die_info
*lookup_die
= NULL
;
18163 struct partial_die_info
part_die (sect_off
);
18165 lookup_die
= ((struct partial_die_info
*)
18166 htab_find_with_hash (partial_dies
, &part_die
,
18167 to_underlying (sect_off
)));
18172 /* Find a partial DIE at OFFSET, which may or may not be in CU,
18173 except in the case of .debug_types DIEs which do not reference
18174 outside their CU (they do however referencing other types via
18175 DW_FORM_ref_sig8). */
18177 static const struct cu_partial_die_info
18178 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
18180 struct dwarf2_per_objfile
*dwarf2_per_objfile
18181 = cu
->per_cu
->dwarf2_per_objfile
;
18182 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18183 struct dwarf2_per_cu_data
*per_cu
= NULL
;
18184 struct partial_die_info
*pd
= NULL
;
18186 if (offset_in_dwz
== cu
->per_cu
->is_dwz
18187 && cu
->header
.offset_in_cu_p (sect_off
))
18189 pd
= cu
->find_partial_die (sect_off
);
18192 /* We missed recording what we needed.
18193 Load all dies and try again. */
18194 per_cu
= cu
->per_cu
;
18198 /* TUs don't reference other CUs/TUs (except via type signatures). */
18199 if (cu
->per_cu
->is_debug_types
)
18201 error (_("Dwarf Error: Type Unit at offset %s contains"
18202 " external reference to offset %s [in module %s].\n"),
18203 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
18204 bfd_get_filename (objfile
->obfd
));
18206 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
18207 dwarf2_per_objfile
);
18209 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
18210 load_partial_comp_unit (per_cu
);
18212 per_cu
->cu
->last_used
= 0;
18213 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18216 /* If we didn't find it, and not all dies have been loaded,
18217 load them all and try again. */
18219 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
18221 per_cu
->load_all_dies
= 1;
18223 /* This is nasty. When we reread the DIEs, somewhere up the call chain
18224 THIS_CU->cu may already be in use. So we can't just free it and
18225 replace its DIEs with the ones we read in. Instead, we leave those
18226 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
18227 and clobber THIS_CU->cu->partial_dies with the hash table for the new
18229 load_partial_comp_unit (per_cu
);
18231 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18235 internal_error (__FILE__
, __LINE__
,
18236 _("could not find partial DIE %s "
18237 "in cache [from module %s]\n"),
18238 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
18239 return { per_cu
->cu
, pd
};
18242 /* See if we can figure out if the class lives in a namespace. We do
18243 this by looking for a member function; its demangled name will
18244 contain namespace info, if there is any. */
18247 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
18248 struct dwarf2_cu
*cu
)
18250 /* NOTE: carlton/2003-10-07: Getting the info this way changes
18251 what template types look like, because the demangler
18252 frequently doesn't give the same name as the debug info. We
18253 could fix this by only using the demangled name to get the
18254 prefix (but see comment in read_structure_type). */
18256 struct partial_die_info
*real_pdi
;
18257 struct partial_die_info
*child_pdi
;
18259 /* If this DIE (this DIE's specification, if any) has a parent, then
18260 we should not do this. We'll prepend the parent's fully qualified
18261 name when we create the partial symbol. */
18263 real_pdi
= struct_pdi
;
18264 while (real_pdi
->has_specification
)
18266 auto res
= find_partial_die (real_pdi
->spec_offset
,
18267 real_pdi
->spec_is_dwz
, cu
);
18268 real_pdi
= res
.pdi
;
18272 if (real_pdi
->die_parent
!= NULL
)
18275 for (child_pdi
= struct_pdi
->die_child
;
18277 child_pdi
= child_pdi
->die_sibling
)
18279 if (child_pdi
->tag
== DW_TAG_subprogram
18280 && child_pdi
->linkage_name
!= NULL
)
18282 gdb::unique_xmalloc_ptr
<char> actual_class_name
18283 (language_class_name_from_physname (cu
->language_defn
,
18284 child_pdi
->linkage_name
));
18285 if (actual_class_name
!= NULL
)
18287 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18289 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
18290 actual_class_name
.get ());
18298 partial_die_info::fixup (struct dwarf2_cu
*cu
)
18300 /* Once we've fixed up a die, there's no point in doing so again.
18301 This also avoids a memory leak if we were to call
18302 guess_partial_die_structure_name multiple times. */
18306 /* If we found a reference attribute and the DIE has no name, try
18307 to find a name in the referred to DIE. */
18309 if (name
== NULL
&& has_specification
)
18311 struct partial_die_info
*spec_die
;
18313 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18314 spec_die
= res
.pdi
;
18317 spec_die
->fixup (cu
);
18319 if (spec_die
->name
)
18321 name
= spec_die
->name
;
18323 /* Copy DW_AT_external attribute if it is set. */
18324 if (spec_die
->is_external
)
18325 is_external
= spec_die
->is_external
;
18329 /* Set default names for some unnamed DIEs. */
18331 if (name
== NULL
&& tag
== DW_TAG_namespace
)
18332 name
= CP_ANONYMOUS_NAMESPACE_STR
;
18334 /* If there is no parent die to provide a namespace, and there are
18335 children, see if we can determine the namespace from their linkage
18337 if (cu
->language
== language_cplus
18338 && !cu
->per_cu
->dwarf2_per_objfile
->types
.empty ()
18339 && die_parent
== NULL
18341 && (tag
== DW_TAG_class_type
18342 || tag
== DW_TAG_structure_type
18343 || tag
== DW_TAG_union_type
))
18344 guess_partial_die_structure_name (this, cu
);
18346 /* GCC might emit a nameless struct or union that has a linkage
18347 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
18349 && (tag
== DW_TAG_class_type
18350 || tag
== DW_TAG_interface_type
18351 || tag
== DW_TAG_structure_type
18352 || tag
== DW_TAG_union_type
)
18353 && linkage_name
!= NULL
)
18355 gdb::unique_xmalloc_ptr
<char> demangled
18356 (gdb_demangle (linkage_name
, DMGL_TYPES
));
18357 if (demangled
!= nullptr)
18361 /* Strip any leading namespaces/classes, keep only the base name.
18362 DW_AT_name for named DIEs does not contain the prefixes. */
18363 base
= strrchr (demangled
.get (), ':');
18364 if (base
&& base
> demangled
.get () && base
[-1] == ':')
18367 base
= demangled
.get ();
18369 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18370 name
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
, base
);
18377 /* Process the attributes that had to be skipped in the first round. These
18378 attributes are the ones that need str_offsets_base or addr_base attributes.
18379 They could not have been processed in the first round, because at the time
18380 the values of str_offsets_base or addr_base may not have been known. */
18381 void read_attribute_reprocess (const struct die_reader_specs
*reader
,
18382 struct attribute
*attr
)
18384 struct dwarf2_cu
*cu
= reader
->cu
;
18385 switch (attr
->form
)
18387 case DW_FORM_addrx
:
18388 case DW_FORM_GNU_addr_index
:
18389 DW_ADDR (attr
) = read_addr_index (cu
, DW_UNSND (attr
));
18392 case DW_FORM_strx1
:
18393 case DW_FORM_strx2
:
18394 case DW_FORM_strx3
:
18395 case DW_FORM_strx4
:
18396 case DW_FORM_GNU_str_index
:
18398 unsigned int str_index
= DW_UNSND (attr
);
18399 if (reader
->dwo_file
!= NULL
)
18401 DW_STRING (attr
) = read_dwo_str_index (reader
, str_index
);
18402 DW_STRING_IS_CANONICAL (attr
) = 0;
18406 DW_STRING (attr
) = read_stub_str_index (cu
, str_index
);
18407 DW_STRING_IS_CANONICAL (attr
) = 0;
18412 gdb_assert_not_reached (_("Unexpected DWARF form."));
18416 /* Read an attribute value described by an attribute form. */
18418 static const gdb_byte
*
18419 read_attribute_value (const struct die_reader_specs
*reader
,
18420 struct attribute
*attr
, unsigned form
,
18421 LONGEST implicit_const
, const gdb_byte
*info_ptr
,
18422 bool *need_reprocess
)
18424 struct dwarf2_cu
*cu
= reader
->cu
;
18425 struct dwarf2_per_objfile
*dwarf2_per_objfile
18426 = cu
->per_cu
->dwarf2_per_objfile
;
18427 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18428 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18429 bfd
*abfd
= reader
->abfd
;
18430 struct comp_unit_head
*cu_header
= &cu
->header
;
18431 unsigned int bytes_read
;
18432 struct dwarf_block
*blk
;
18433 *need_reprocess
= false;
18435 attr
->form
= (enum dwarf_form
) form
;
18438 case DW_FORM_ref_addr
:
18439 if (cu
->header
.version
== 2)
18440 DW_UNSND (attr
) = cu
->header
.read_address (abfd
, info_ptr
,
18443 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
,
18445 info_ptr
+= bytes_read
;
18447 case DW_FORM_GNU_ref_alt
:
18448 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
18449 info_ptr
+= bytes_read
;
18452 DW_ADDR (attr
) = cu
->header
.read_address (abfd
, info_ptr
, &bytes_read
);
18453 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
18454 info_ptr
+= bytes_read
;
18456 case DW_FORM_block2
:
18457 blk
= dwarf_alloc_block (cu
);
18458 blk
->size
= read_2_bytes (abfd
, info_ptr
);
18460 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18461 info_ptr
+= blk
->size
;
18462 DW_BLOCK (attr
) = blk
;
18464 case DW_FORM_block4
:
18465 blk
= dwarf_alloc_block (cu
);
18466 blk
->size
= read_4_bytes (abfd
, info_ptr
);
18468 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18469 info_ptr
+= blk
->size
;
18470 DW_BLOCK (attr
) = blk
;
18472 case DW_FORM_data2
:
18473 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
18476 case DW_FORM_data4
:
18477 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
18480 case DW_FORM_data8
:
18481 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
18484 case DW_FORM_data16
:
18485 blk
= dwarf_alloc_block (cu
);
18487 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
18489 DW_BLOCK (attr
) = blk
;
18491 case DW_FORM_sec_offset
:
18492 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
18493 info_ptr
+= bytes_read
;
18495 case DW_FORM_string
:
18496 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
18497 DW_STRING_IS_CANONICAL (attr
) = 0;
18498 info_ptr
+= bytes_read
;
18501 if (!cu
->per_cu
->is_dwz
)
18503 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
18504 abfd
, info_ptr
, cu_header
,
18506 DW_STRING_IS_CANONICAL (attr
) = 0;
18507 info_ptr
+= bytes_read
;
18511 case DW_FORM_line_strp
:
18512 if (!cu
->per_cu
->is_dwz
)
18514 DW_STRING (attr
) = read_indirect_line_string (dwarf2_per_objfile
,
18516 cu_header
, &bytes_read
);
18517 DW_STRING_IS_CANONICAL (attr
) = 0;
18518 info_ptr
+= bytes_read
;
18522 case DW_FORM_GNU_strp_alt
:
18524 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
18525 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
18528 DW_STRING (attr
) = read_indirect_string_from_dwz (objfile
,
18530 DW_STRING_IS_CANONICAL (attr
) = 0;
18531 info_ptr
+= bytes_read
;
18534 case DW_FORM_exprloc
:
18535 case DW_FORM_block
:
18536 blk
= dwarf_alloc_block (cu
);
18537 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18538 info_ptr
+= bytes_read
;
18539 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18540 info_ptr
+= blk
->size
;
18541 DW_BLOCK (attr
) = blk
;
18543 case DW_FORM_block1
:
18544 blk
= dwarf_alloc_block (cu
);
18545 blk
->size
= read_1_byte (abfd
, info_ptr
);
18547 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18548 info_ptr
+= blk
->size
;
18549 DW_BLOCK (attr
) = blk
;
18551 case DW_FORM_data1
:
18552 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
18556 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
18559 case DW_FORM_flag_present
:
18560 DW_UNSND (attr
) = 1;
18562 case DW_FORM_sdata
:
18563 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
18564 info_ptr
+= bytes_read
;
18566 case DW_FORM_udata
:
18567 case DW_FORM_rnglistx
:
18568 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18569 info_ptr
+= bytes_read
;
18572 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18573 + read_1_byte (abfd
, info_ptr
));
18577 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18578 + read_2_bytes (abfd
, info_ptr
));
18582 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18583 + read_4_bytes (abfd
, info_ptr
));
18587 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18588 + read_8_bytes (abfd
, info_ptr
));
18591 case DW_FORM_ref_sig8
:
18592 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
18595 case DW_FORM_ref_udata
:
18596 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18597 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
18598 info_ptr
+= bytes_read
;
18600 case DW_FORM_indirect
:
18601 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18602 info_ptr
+= bytes_read
;
18603 if (form
== DW_FORM_implicit_const
)
18605 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
18606 info_ptr
+= bytes_read
;
18608 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
18609 info_ptr
, need_reprocess
);
18611 case DW_FORM_implicit_const
:
18612 DW_SND (attr
) = implicit_const
;
18614 case DW_FORM_addrx
:
18615 case DW_FORM_GNU_addr_index
:
18616 *need_reprocess
= true;
18617 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18618 info_ptr
+= bytes_read
;
18621 case DW_FORM_strx1
:
18622 case DW_FORM_strx2
:
18623 case DW_FORM_strx3
:
18624 case DW_FORM_strx4
:
18625 case DW_FORM_GNU_str_index
:
18627 ULONGEST str_index
;
18628 if (form
== DW_FORM_strx1
)
18630 str_index
= read_1_byte (abfd
, info_ptr
);
18633 else if (form
== DW_FORM_strx2
)
18635 str_index
= read_2_bytes (abfd
, info_ptr
);
18638 else if (form
== DW_FORM_strx3
)
18640 str_index
= read_3_bytes (abfd
, info_ptr
);
18643 else if (form
== DW_FORM_strx4
)
18645 str_index
= read_4_bytes (abfd
, info_ptr
);
18650 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18651 info_ptr
+= bytes_read
;
18653 *need_reprocess
= true;
18654 DW_UNSND (attr
) = str_index
;
18658 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
18659 dwarf_form_name (form
),
18660 bfd_get_filename (abfd
));
18664 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
18665 attr
->form
= DW_FORM_GNU_ref_alt
;
18667 /* We have seen instances where the compiler tried to emit a byte
18668 size attribute of -1 which ended up being encoded as an unsigned
18669 0xffffffff. Although 0xffffffff is technically a valid size value,
18670 an object of this size seems pretty unlikely so we can relatively
18671 safely treat these cases as if the size attribute was invalid and
18672 treat them as zero by default. */
18673 if (attr
->name
== DW_AT_byte_size
18674 && form
== DW_FORM_data4
18675 && DW_UNSND (attr
) >= 0xffffffff)
18678 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
18679 hex_string (DW_UNSND (attr
)));
18680 DW_UNSND (attr
) = 0;
18686 /* Read an attribute described by an abbreviated attribute. */
18688 static const gdb_byte
*
18689 read_attribute (const struct die_reader_specs
*reader
,
18690 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
18691 const gdb_byte
*info_ptr
, bool *need_reprocess
)
18693 attr
->name
= abbrev
->name
;
18694 return read_attribute_value (reader
, attr
, abbrev
->form
,
18695 abbrev
->implicit_const
, info_ptr
,
18699 /* Cover function for read_initial_length.
18700 Returns the length of the object at BUF, and stores the size of the
18701 initial length in *BYTES_READ and stores the size that offsets will be in
18703 If the initial length size is not equivalent to that specified in
18704 CU_HEADER then issue a complaint.
18705 This is useful when reading non-comp-unit headers. */
18708 read_checked_initial_length_and_offset (bfd
*abfd
, const gdb_byte
*buf
,
18709 const struct comp_unit_head
*cu_header
,
18710 unsigned int *bytes_read
,
18711 unsigned int *offset_size
)
18713 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
18715 gdb_assert (cu_header
->initial_length_size
== 4
18716 || cu_header
->initial_length_size
== 8
18717 || cu_header
->initial_length_size
== 12);
18719 if (cu_header
->initial_length_size
!= *bytes_read
)
18720 complaint (_("intermixed 32-bit and 64-bit DWARF sections"));
18722 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
18726 /* Return pointer to string at section SECT offset STR_OFFSET with error
18727 reporting strings FORM_NAME and SECT_NAME. */
18729 static const char *
18730 read_indirect_string_at_offset_from (struct objfile
*objfile
,
18731 bfd
*abfd
, LONGEST str_offset
,
18732 struct dwarf2_section_info
*sect
,
18733 const char *form_name
,
18734 const char *sect_name
)
18736 sect
->read (objfile
);
18737 if (sect
->buffer
== NULL
)
18738 error (_("%s used without %s section [in module %s]"),
18739 form_name
, sect_name
, bfd_get_filename (abfd
));
18740 if (str_offset
>= sect
->size
)
18741 error (_("%s pointing outside of %s section [in module %s]"),
18742 form_name
, sect_name
, bfd_get_filename (abfd
));
18743 gdb_assert (HOST_CHAR_BIT
== 8);
18744 if (sect
->buffer
[str_offset
] == '\0')
18746 return (const char *) (sect
->buffer
+ str_offset
);
18749 /* Return pointer to string at .debug_str offset STR_OFFSET. */
18751 static const char *
18752 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18753 bfd
*abfd
, LONGEST str_offset
)
18755 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
18757 &dwarf2_per_objfile
->str
,
18758 "DW_FORM_strp", ".debug_str");
18761 /* Return pointer to string at .debug_line_str offset STR_OFFSET. */
18763 static const char *
18764 read_indirect_line_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18765 bfd
*abfd
, LONGEST str_offset
)
18767 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
18769 &dwarf2_per_objfile
->line_str
,
18770 "DW_FORM_line_strp",
18771 ".debug_line_str");
18774 /* Read a string at offset STR_OFFSET in the .debug_str section from
18775 the .dwz file DWZ. Throw an error if the offset is too large. If
18776 the string consists of a single NUL byte, return NULL; otherwise
18777 return a pointer to the string. */
18779 static const char *
18780 read_indirect_string_from_dwz (struct objfile
*objfile
, struct dwz_file
*dwz
,
18781 LONGEST str_offset
)
18783 dwz
->str
.read (objfile
);
18785 if (dwz
->str
.buffer
== NULL
)
18786 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
18787 "section [in module %s]"),
18788 bfd_get_filename (dwz
->dwz_bfd
.get ()));
18789 if (str_offset
>= dwz
->str
.size
)
18790 error (_("DW_FORM_GNU_strp_alt pointing outside of "
18791 ".debug_str section [in module %s]"),
18792 bfd_get_filename (dwz
->dwz_bfd
.get ()));
18793 gdb_assert (HOST_CHAR_BIT
== 8);
18794 if (dwz
->str
.buffer
[str_offset
] == '\0')
18796 return (const char *) (dwz
->str
.buffer
+ str_offset
);
18799 /* Return pointer to string at .debug_str offset as read from BUF.
18800 BUF is assumed to be in a compilation unit described by CU_HEADER.
18801 Return *BYTES_READ_PTR count of bytes read from BUF. */
18803 static const char *
18804 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
18805 const gdb_byte
*buf
,
18806 const struct comp_unit_head
*cu_header
,
18807 unsigned int *bytes_read_ptr
)
18809 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
18811 return read_indirect_string_at_offset (dwarf2_per_objfile
, abfd
, str_offset
);
18814 /* Return pointer to string at .debug_line_str offset as read from BUF.
18815 BUF is assumed to be in a compilation unit described by CU_HEADER.
18816 Return *BYTES_READ_PTR count of bytes read from BUF. */
18818 static const char *
18819 read_indirect_line_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18820 bfd
*abfd
, const gdb_byte
*buf
,
18821 const struct comp_unit_head
*cu_header
,
18822 unsigned int *bytes_read_ptr
)
18824 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
18826 return read_indirect_line_string_at_offset (dwarf2_per_objfile
, abfd
,
18830 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
18831 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
18832 ADDR_SIZE is the size of addresses from the CU header. */
18835 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18836 unsigned int addr_index
, gdb::optional
<ULONGEST
> addr_base
,
18839 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18840 bfd
*abfd
= objfile
->obfd
;
18841 const gdb_byte
*info_ptr
;
18842 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
18844 dwarf2_per_objfile
->addr
.read (objfile
);
18845 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
18846 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
18847 objfile_name (objfile
));
18848 if (addr_base_or_zero
+ addr_index
* addr_size
18849 >= dwarf2_per_objfile
->addr
.size
)
18850 error (_("DW_FORM_addr_index pointing outside of "
18851 ".debug_addr section [in module %s]"),
18852 objfile_name (objfile
));
18853 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
18854 + addr_base_or_zero
+ addr_index
* addr_size
);
18855 if (addr_size
== 4)
18856 return bfd_get_32 (abfd
, info_ptr
);
18858 return bfd_get_64 (abfd
, info_ptr
);
18861 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
18864 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
18866 return read_addr_index_1 (cu
->per_cu
->dwarf2_per_objfile
, addr_index
,
18867 cu
->addr_base
, cu
->header
.addr_size
);
18870 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
18873 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
18874 unsigned int *bytes_read
)
18876 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
18877 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
18879 return read_addr_index (cu
, addr_index
);
18882 /* Given an index in .debug_addr, fetch the value.
18883 NOTE: This can be called during dwarf expression evaluation,
18884 long after the debug information has been read, and thus per_cu->cu
18885 may no longer exist. */
18888 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
18889 unsigned int addr_index
)
18891 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
18892 struct dwarf2_cu
*cu
= per_cu
->cu
;
18893 gdb::optional
<ULONGEST
> addr_base
;
18896 /* We need addr_base and addr_size.
18897 If we don't have PER_CU->cu, we have to get it.
18898 Nasty, but the alternative is storing the needed info in PER_CU,
18899 which at this point doesn't seem justified: it's not clear how frequently
18900 it would get used and it would increase the size of every PER_CU.
18901 Entry points like dwarf2_per_cu_addr_size do a similar thing
18902 so we're not in uncharted territory here.
18903 Alas we need to be a bit more complicated as addr_base is contained
18906 We don't need to read the entire CU(/TU).
18907 We just need the header and top level die.
18909 IWBN to use the aging mechanism to let us lazily later discard the CU.
18910 For now we skip this optimization. */
18914 addr_base
= cu
->addr_base
;
18915 addr_size
= cu
->header
.addr_size
;
18919 cutu_reader
reader (per_cu
, NULL
, 0, 0, false);
18920 addr_base
= reader
.cu
->addr_base
;
18921 addr_size
= reader
.cu
->header
.addr_size
;
18924 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
18928 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
18929 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
18932 static const char *
18933 read_str_index (struct dwarf2_cu
*cu
,
18934 struct dwarf2_section_info
*str_section
,
18935 struct dwarf2_section_info
*str_offsets_section
,
18936 ULONGEST str_offsets_base
, ULONGEST str_index
)
18938 struct dwarf2_per_objfile
*dwarf2_per_objfile
18939 = cu
->per_cu
->dwarf2_per_objfile
;
18940 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18941 const char *objf_name
= objfile_name (objfile
);
18942 bfd
*abfd
= objfile
->obfd
;
18943 const gdb_byte
*info_ptr
;
18944 ULONGEST str_offset
;
18945 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
18947 str_section
->read (objfile
);
18948 str_offsets_section
->read (objfile
);
18949 if (str_section
->buffer
== NULL
)
18950 error (_("%s used without %s section"
18951 " in CU at offset %s [in module %s]"),
18952 form_name
, str_section
->get_name (),
18953 sect_offset_str (cu
->header
.sect_off
), objf_name
);
18954 if (str_offsets_section
->buffer
== NULL
)
18955 error (_("%s used without %s section"
18956 " in CU at offset %s [in module %s]"),
18957 form_name
, str_section
->get_name (),
18958 sect_offset_str (cu
->header
.sect_off
), objf_name
);
18959 info_ptr
= (str_offsets_section
->buffer
18961 + str_index
* cu
->header
.offset_size
);
18962 if (cu
->header
.offset_size
== 4)
18963 str_offset
= bfd_get_32 (abfd
, info_ptr
);
18965 str_offset
= bfd_get_64 (abfd
, info_ptr
);
18966 if (str_offset
>= str_section
->size
)
18967 error (_("Offset from %s pointing outside of"
18968 " .debug_str.dwo section in CU at offset %s [in module %s]"),
18969 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
18970 return (const char *) (str_section
->buffer
+ str_offset
);
18973 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
18975 static const char *
18976 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
18978 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
18979 ? reader
->cu
->header
.addr_size
: 0;
18980 return read_str_index (reader
->cu
,
18981 &reader
->dwo_file
->sections
.str
,
18982 &reader
->dwo_file
->sections
.str_offsets
,
18983 str_offsets_base
, str_index
);
18986 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
18988 static const char *
18989 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
18991 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18992 const char *objf_name
= objfile_name (objfile
);
18993 static const char form_name
[] = "DW_FORM_GNU_str_index";
18994 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
18996 if (!cu
->str_offsets_base
.has_value ())
18997 error (_("%s used in Fission stub without %s"
18998 " in CU at offset 0x%lx [in module %s]"),
18999 form_name
, str_offsets_attr_name
,
19000 (long) cu
->header
.offset_size
, objf_name
);
19002 return read_str_index (cu
,
19003 &cu
->per_cu
->dwarf2_per_objfile
->str
,
19004 &cu
->per_cu
->dwarf2_per_objfile
->str_offsets
,
19005 *cu
->str_offsets_base
, str_index
);
19008 /* Return the length of an LEB128 number in BUF. */
19011 leb128_size (const gdb_byte
*buf
)
19013 const gdb_byte
*begin
= buf
;
19019 if ((byte
& 128) == 0)
19020 return buf
- begin
;
19025 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
19034 cu
->language
= language_c
;
19037 case DW_LANG_C_plus_plus
:
19038 case DW_LANG_C_plus_plus_11
:
19039 case DW_LANG_C_plus_plus_14
:
19040 cu
->language
= language_cplus
;
19043 cu
->language
= language_d
;
19045 case DW_LANG_Fortran77
:
19046 case DW_LANG_Fortran90
:
19047 case DW_LANG_Fortran95
:
19048 case DW_LANG_Fortran03
:
19049 case DW_LANG_Fortran08
:
19050 cu
->language
= language_fortran
;
19053 cu
->language
= language_go
;
19055 case DW_LANG_Mips_Assembler
:
19056 cu
->language
= language_asm
;
19058 case DW_LANG_Ada83
:
19059 case DW_LANG_Ada95
:
19060 cu
->language
= language_ada
;
19062 case DW_LANG_Modula2
:
19063 cu
->language
= language_m2
;
19065 case DW_LANG_Pascal83
:
19066 cu
->language
= language_pascal
;
19069 cu
->language
= language_objc
;
19072 case DW_LANG_Rust_old
:
19073 cu
->language
= language_rust
;
19075 case DW_LANG_Cobol74
:
19076 case DW_LANG_Cobol85
:
19078 cu
->language
= language_minimal
;
19081 cu
->language_defn
= language_def (cu
->language
);
19084 /* Return the named attribute or NULL if not there. */
19086 static struct attribute
*
19087 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19092 struct attribute
*spec
= NULL
;
19094 for (i
= 0; i
< die
->num_attrs
; ++i
)
19096 if (die
->attrs
[i
].name
== name
)
19097 return &die
->attrs
[i
];
19098 if (die
->attrs
[i
].name
== DW_AT_specification
19099 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
19100 spec
= &die
->attrs
[i
];
19106 die
= follow_die_ref (die
, spec
, &cu
);
19112 /* Return the named attribute or NULL if not there,
19113 but do not follow DW_AT_specification, etc.
19114 This is for use in contexts where we're reading .debug_types dies.
19115 Following DW_AT_specification, DW_AT_abstract_origin will take us
19116 back up the chain, and we want to go down. */
19118 static struct attribute
*
19119 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
19123 for (i
= 0; i
< die
->num_attrs
; ++i
)
19124 if (die
->attrs
[i
].name
== name
)
19125 return &die
->attrs
[i
];
19130 /* Return the string associated with a string-typed attribute, or NULL if it
19131 is either not found or is of an incorrect type. */
19133 static const char *
19134 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19136 struct attribute
*attr
;
19137 const char *str
= NULL
;
19139 attr
= dwarf2_attr (die
, name
, cu
);
19143 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
19144 || attr
->form
== DW_FORM_string
19145 || attr
->form
== DW_FORM_strx
19146 || attr
->form
== DW_FORM_strx1
19147 || attr
->form
== DW_FORM_strx2
19148 || attr
->form
== DW_FORM_strx3
19149 || attr
->form
== DW_FORM_strx4
19150 || attr
->form
== DW_FORM_GNU_str_index
19151 || attr
->form
== DW_FORM_GNU_strp_alt
)
19152 str
= DW_STRING (attr
);
19154 complaint (_("string type expected for attribute %s for "
19155 "DIE at %s in module %s"),
19156 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
19157 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
19163 /* Return the dwo name or NULL if not present. If present, it is in either
19164 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
19165 static const char *
19166 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
19168 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
19169 if (dwo_name
== nullptr)
19170 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
19174 /* Return non-zero iff the attribute NAME is defined for the given DIE,
19175 and holds a non-zero value. This function should only be used for
19176 DW_FORM_flag or DW_FORM_flag_present attributes. */
19179 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
19181 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
19183 return (attr
&& DW_UNSND (attr
));
19187 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
19189 /* A DIE is a declaration if it has a DW_AT_declaration attribute
19190 which value is non-zero. However, we have to be careful with
19191 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
19192 (via dwarf2_flag_true_p) follows this attribute. So we may
19193 end up accidently finding a declaration attribute that belongs
19194 to a different DIE referenced by the specification attribute,
19195 even though the given DIE does not have a declaration attribute. */
19196 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
19197 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
19200 /* Return the die giving the specification for DIE, if there is
19201 one. *SPEC_CU is the CU containing DIE on input, and the CU
19202 containing the return value on output. If there is no
19203 specification, but there is an abstract origin, that is
19206 static struct die_info
*
19207 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
19209 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
19212 if (spec_attr
== NULL
)
19213 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
19215 if (spec_attr
== NULL
)
19218 return follow_die_ref (die
, spec_attr
, spec_cu
);
19221 /* Stub for free_line_header to match void * callback types. */
19224 free_line_header_voidp (void *arg
)
19226 struct line_header
*lh
= (struct line_header
*) arg
;
19231 /* A convenience function to find the proper .debug_line section for a CU. */
19233 static struct dwarf2_section_info
*
19234 get_debug_line_section (struct dwarf2_cu
*cu
)
19236 struct dwarf2_section_info
*section
;
19237 struct dwarf2_per_objfile
*dwarf2_per_objfile
19238 = cu
->per_cu
->dwarf2_per_objfile
;
19240 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
19242 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19243 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
19244 else if (cu
->per_cu
->is_dwz
)
19246 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19248 section
= &dwz
->line
;
19251 section
= &dwarf2_per_objfile
->line
;
19256 /* Read directory or file name entry format, starting with byte of
19257 format count entries, ULEB128 pairs of entry formats, ULEB128 of
19258 entries count and the entries themselves in the described entry
19262 read_formatted_entries (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19263 bfd
*abfd
, const gdb_byte
**bufp
,
19264 struct line_header
*lh
,
19265 const struct comp_unit_head
*cu_header
,
19266 void (*callback
) (struct line_header
*lh
,
19269 unsigned int mod_time
,
19270 unsigned int length
))
19272 gdb_byte format_count
, formati
;
19273 ULONGEST data_count
, datai
;
19274 const gdb_byte
*buf
= *bufp
;
19275 const gdb_byte
*format_header_data
;
19276 unsigned int bytes_read
;
19278 format_count
= read_1_byte (abfd
, buf
);
19280 format_header_data
= buf
;
19281 for (formati
= 0; formati
< format_count
; formati
++)
19283 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
19285 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
19289 data_count
= read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
19291 for (datai
= 0; datai
< data_count
; datai
++)
19293 const gdb_byte
*format
= format_header_data
;
19294 struct file_entry fe
;
19296 for (formati
= 0; formati
< format_count
; formati
++)
19298 ULONGEST content_type
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
19299 format
+= bytes_read
;
19301 ULONGEST form
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
19302 format
+= bytes_read
;
19304 gdb::optional
<const char *> string
;
19305 gdb::optional
<unsigned int> uint
;
19309 case DW_FORM_string
:
19310 string
.emplace (read_direct_string (abfd
, buf
, &bytes_read
));
19314 case DW_FORM_line_strp
:
19315 string
.emplace (read_indirect_line_string (dwarf2_per_objfile
,
19322 case DW_FORM_data1
:
19323 uint
.emplace (read_1_byte (abfd
, buf
));
19327 case DW_FORM_data2
:
19328 uint
.emplace (read_2_bytes (abfd
, buf
));
19332 case DW_FORM_data4
:
19333 uint
.emplace (read_4_bytes (abfd
, buf
));
19337 case DW_FORM_data8
:
19338 uint
.emplace (read_8_bytes (abfd
, buf
));
19342 case DW_FORM_data16
:
19343 /* This is used for MD5, but file_entry does not record MD5s. */
19347 case DW_FORM_udata
:
19348 uint
.emplace (read_unsigned_leb128 (abfd
, buf
, &bytes_read
));
19352 case DW_FORM_block
:
19353 /* It is valid only for DW_LNCT_timestamp which is ignored by
19358 switch (content_type
)
19361 if (string
.has_value ())
19364 case DW_LNCT_directory_index
:
19365 if (uint
.has_value ())
19366 fe
.d_index
= (dir_index
) *uint
;
19368 case DW_LNCT_timestamp
:
19369 if (uint
.has_value ())
19370 fe
.mod_time
= *uint
;
19373 if (uint
.has_value ())
19379 complaint (_("Unknown format content type %s"),
19380 pulongest (content_type
));
19384 callback (lh
, fe
.name
, fe
.d_index
, fe
.mod_time
, fe
.length
);
19390 /* Read the statement program header starting at OFFSET in
19391 .debug_line, or .debug_line.dwo. Return a pointer
19392 to a struct line_header, allocated using xmalloc.
19393 Returns NULL if there is a problem reading the header, e.g., if it
19394 has a version we don't understand.
19396 NOTE: the strings in the include directory and file name tables of
19397 the returned object point into the dwarf line section buffer,
19398 and must not be freed. */
19400 static line_header_up
19401 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
19403 const gdb_byte
*line_ptr
;
19404 unsigned int bytes_read
, offset_size
;
19406 const char *cur_dir
, *cur_file
;
19407 struct dwarf2_section_info
*section
;
19409 struct dwarf2_per_objfile
*dwarf2_per_objfile
19410 = cu
->per_cu
->dwarf2_per_objfile
;
19412 section
= get_debug_line_section (cu
);
19413 section
->read (dwarf2_per_objfile
->objfile
);
19414 if (section
->buffer
== NULL
)
19416 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19417 complaint (_("missing .debug_line.dwo section"));
19419 complaint (_("missing .debug_line section"));
19423 /* We can't do this until we know the section is non-empty.
19424 Only then do we know we have such a section. */
19425 abfd
= section
->get_bfd_owner ();
19427 /* Make sure that at least there's room for the total_length field.
19428 That could be 12 bytes long, but we're just going to fudge that. */
19429 if (to_underlying (sect_off
) + 4 >= section
->size
)
19431 dwarf2_statement_list_fits_in_line_number_section_complaint ();
19435 line_header_up
lh (new line_header ());
19437 lh
->sect_off
= sect_off
;
19438 lh
->offset_in_dwz
= cu
->per_cu
->is_dwz
;
19440 line_ptr
= section
->buffer
+ to_underlying (sect_off
);
19442 /* Read in the header. */
19444 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
19445 &bytes_read
, &offset_size
);
19446 line_ptr
+= bytes_read
;
19448 const gdb_byte
*start_here
= line_ptr
;
19450 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
19452 dwarf2_statement_list_fits_in_line_number_section_complaint ();
19455 lh
->statement_program_end
= start_here
+ lh
->total_length
;
19456 lh
->version
= read_2_bytes (abfd
, line_ptr
);
19458 if (lh
->version
> 5)
19460 /* This is a version we don't understand. The format could have
19461 changed in ways we don't handle properly so just punt. */
19462 complaint (_("unsupported version in .debug_line section"));
19465 if (lh
->version
>= 5)
19467 gdb_byte segment_selector_size
;
19469 /* Skip address size. */
19470 read_1_byte (abfd
, line_ptr
);
19473 segment_selector_size
= read_1_byte (abfd
, line_ptr
);
19475 if (segment_selector_size
!= 0)
19477 complaint (_("unsupported segment selector size %u "
19478 "in .debug_line section"),
19479 segment_selector_size
);
19483 lh
->header_length
= read_offset (abfd
, line_ptr
, offset_size
);
19484 line_ptr
+= offset_size
;
19485 lh
->statement_program_start
= line_ptr
+ lh
->header_length
;
19486 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
19488 if (lh
->version
>= 4)
19490 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
19494 lh
->maximum_ops_per_instruction
= 1;
19496 if (lh
->maximum_ops_per_instruction
== 0)
19498 lh
->maximum_ops_per_instruction
= 1;
19499 complaint (_("invalid maximum_ops_per_instruction "
19500 "in `.debug_line' section"));
19503 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
19505 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
19507 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
19509 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
19511 lh
->standard_opcode_lengths
.reset (new unsigned char[lh
->opcode_base
]);
19513 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
19514 for (i
= 1; i
< lh
->opcode_base
; ++i
)
19516 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
19520 if (lh
->version
>= 5)
19522 /* Read directory table. */
19523 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
19525 [] (struct line_header
*header
, const char *name
,
19526 dir_index d_index
, unsigned int mod_time
,
19527 unsigned int length
)
19529 header
->add_include_dir (name
);
19532 /* Read file name table. */
19533 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
19535 [] (struct line_header
*header
, const char *name
,
19536 dir_index d_index
, unsigned int mod_time
,
19537 unsigned int length
)
19539 header
->add_file_name (name
, d_index
, mod_time
, length
);
19544 /* Read directory table. */
19545 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
19547 line_ptr
+= bytes_read
;
19548 lh
->add_include_dir (cur_dir
);
19550 line_ptr
+= bytes_read
;
19552 /* Read file name table. */
19553 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
19555 unsigned int mod_time
, length
;
19558 line_ptr
+= bytes_read
;
19559 d_index
= (dir_index
) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19560 line_ptr
+= bytes_read
;
19561 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19562 line_ptr
+= bytes_read
;
19563 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19564 line_ptr
+= bytes_read
;
19566 lh
->add_file_name (cur_file
, d_index
, mod_time
, length
);
19568 line_ptr
+= bytes_read
;
19571 if (line_ptr
> (section
->buffer
+ section
->size
))
19572 complaint (_("line number info header doesn't "
19573 "fit in `.debug_line' section"));
19578 /* Subroutine of dwarf_decode_lines to simplify it.
19579 Return the file name of the psymtab for the given file_entry.
19580 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
19581 If space for the result is malloc'd, *NAME_HOLDER will be set.
19582 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
19584 static const char *
19585 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
19586 const dwarf2_psymtab
*pst
,
19587 const char *comp_dir
,
19588 gdb::unique_xmalloc_ptr
<char> *name_holder
)
19590 const char *include_name
= fe
.name
;
19591 const char *include_name_to_compare
= include_name
;
19592 const char *pst_filename
;
19595 const char *dir_name
= fe
.include_dir (lh
);
19597 gdb::unique_xmalloc_ptr
<char> hold_compare
;
19598 if (!IS_ABSOLUTE_PATH (include_name
)
19599 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
19601 /* Avoid creating a duplicate psymtab for PST.
19602 We do this by comparing INCLUDE_NAME and PST_FILENAME.
19603 Before we do the comparison, however, we need to account
19604 for DIR_NAME and COMP_DIR.
19605 First prepend dir_name (if non-NULL). If we still don't
19606 have an absolute path prepend comp_dir (if non-NULL).
19607 However, the directory we record in the include-file's
19608 psymtab does not contain COMP_DIR (to match the
19609 corresponding symtab(s)).
19614 bash$ gcc -g ./hello.c
19615 include_name = "hello.c"
19617 DW_AT_comp_dir = comp_dir = "/tmp"
19618 DW_AT_name = "./hello.c"
19622 if (dir_name
!= NULL
)
19624 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
19625 include_name
, (char *) NULL
));
19626 include_name
= name_holder
->get ();
19627 include_name_to_compare
= include_name
;
19629 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
19631 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
19632 include_name
, (char *) NULL
));
19633 include_name_to_compare
= hold_compare
.get ();
19637 pst_filename
= pst
->filename
;
19638 gdb::unique_xmalloc_ptr
<char> copied_name
;
19639 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
19641 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
19642 pst_filename
, (char *) NULL
));
19643 pst_filename
= copied_name
.get ();
19646 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
19650 return include_name
;
19653 /* State machine to track the state of the line number program. */
19655 class lnp_state_machine
19658 /* Initialize a machine state for the start of a line number
19660 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
19661 bool record_lines_p
);
19663 file_entry
*current_file ()
19665 /* lh->file_names is 0-based, but the file name numbers in the
19666 statement program are 1-based. */
19667 return m_line_header
->file_name_at (m_file
);
19670 /* Record the line in the state machine. END_SEQUENCE is true if
19671 we're processing the end of a sequence. */
19672 void record_line (bool end_sequence
);
19674 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
19675 nop-out rest of the lines in this sequence. */
19676 void check_line_address (struct dwarf2_cu
*cu
,
19677 const gdb_byte
*line_ptr
,
19678 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
19680 void handle_set_discriminator (unsigned int discriminator
)
19682 m_discriminator
= discriminator
;
19683 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
19686 /* Handle DW_LNE_set_address. */
19687 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
19690 address
+= baseaddr
;
19691 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
19694 /* Handle DW_LNS_advance_pc. */
19695 void handle_advance_pc (CORE_ADDR adjust
);
19697 /* Handle a special opcode. */
19698 void handle_special_opcode (unsigned char op_code
);
19700 /* Handle DW_LNS_advance_line. */
19701 void handle_advance_line (int line_delta
)
19703 advance_line (line_delta
);
19706 /* Handle DW_LNS_set_file. */
19707 void handle_set_file (file_name_index file
);
19709 /* Handle DW_LNS_negate_stmt. */
19710 void handle_negate_stmt ()
19712 m_is_stmt
= !m_is_stmt
;
19715 /* Handle DW_LNS_const_add_pc. */
19716 void handle_const_add_pc ();
19718 /* Handle DW_LNS_fixed_advance_pc. */
19719 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
19721 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19725 /* Handle DW_LNS_copy. */
19726 void handle_copy ()
19728 record_line (false);
19729 m_discriminator
= 0;
19732 /* Handle DW_LNE_end_sequence. */
19733 void handle_end_sequence ()
19735 m_currently_recording_lines
= true;
19739 /* Advance the line by LINE_DELTA. */
19740 void advance_line (int line_delta
)
19742 m_line
+= line_delta
;
19744 if (line_delta
!= 0)
19745 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
19748 struct dwarf2_cu
*m_cu
;
19750 gdbarch
*m_gdbarch
;
19752 /* True if we're recording lines.
19753 Otherwise we're building partial symtabs and are just interested in
19754 finding include files mentioned by the line number program. */
19755 bool m_record_lines_p
;
19757 /* The line number header. */
19758 line_header
*m_line_header
;
19760 /* These are part of the standard DWARF line number state machine,
19761 and initialized according to the DWARF spec. */
19763 unsigned char m_op_index
= 0;
19764 /* The line table index of the current file. */
19765 file_name_index m_file
= 1;
19766 unsigned int m_line
= 1;
19768 /* These are initialized in the constructor. */
19770 CORE_ADDR m_address
;
19772 unsigned int m_discriminator
;
19774 /* Additional bits of state we need to track. */
19776 /* The last file that we called dwarf2_start_subfile for.
19777 This is only used for TLLs. */
19778 unsigned int m_last_file
= 0;
19779 /* The last file a line number was recorded for. */
19780 struct subfile
*m_last_subfile
= NULL
;
19782 /* When true, record the lines we decode. */
19783 bool m_currently_recording_lines
= false;
19785 /* The last line number that was recorded, used to coalesce
19786 consecutive entries for the same line. This can happen, for
19787 example, when discriminators are present. PR 17276. */
19788 unsigned int m_last_line
= 0;
19789 bool m_line_has_non_zero_discriminator
= false;
19793 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
19795 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
19796 / m_line_header
->maximum_ops_per_instruction
)
19797 * m_line_header
->minimum_instruction_length
);
19798 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19799 m_op_index
= ((m_op_index
+ adjust
)
19800 % m_line_header
->maximum_ops_per_instruction
);
19804 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
19806 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
19807 CORE_ADDR addr_adj
= (((m_op_index
19808 + (adj_opcode
/ m_line_header
->line_range
))
19809 / m_line_header
->maximum_ops_per_instruction
)
19810 * m_line_header
->minimum_instruction_length
);
19811 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19812 m_op_index
= ((m_op_index
+ (adj_opcode
/ m_line_header
->line_range
))
19813 % m_line_header
->maximum_ops_per_instruction
);
19815 int line_delta
= (m_line_header
->line_base
19816 + (adj_opcode
% m_line_header
->line_range
));
19817 advance_line (line_delta
);
19818 record_line (false);
19819 m_discriminator
= 0;
19823 lnp_state_machine::handle_set_file (file_name_index file
)
19827 const file_entry
*fe
= current_file ();
19829 dwarf2_debug_line_missing_file_complaint ();
19830 else if (m_record_lines_p
)
19832 const char *dir
= fe
->include_dir (m_line_header
);
19834 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
19835 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
19836 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
19841 lnp_state_machine::handle_const_add_pc ()
19844 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
19847 = (((m_op_index
+ adjust
)
19848 / m_line_header
->maximum_ops_per_instruction
)
19849 * m_line_header
->minimum_instruction_length
);
19851 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19852 m_op_index
= ((m_op_index
+ adjust
)
19853 % m_line_header
->maximum_ops_per_instruction
);
19856 /* Return non-zero if we should add LINE to the line number table.
19857 LINE is the line to add, LAST_LINE is the last line that was added,
19858 LAST_SUBFILE is the subfile for LAST_LINE.
19859 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
19860 had a non-zero discriminator.
19862 We have to be careful in the presence of discriminators.
19863 E.g., for this line:
19865 for (i = 0; i < 100000; i++);
19867 clang can emit four line number entries for that one line,
19868 each with a different discriminator.
19869 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
19871 However, we want gdb to coalesce all four entries into one.
19872 Otherwise the user could stepi into the middle of the line and
19873 gdb would get confused about whether the pc really was in the
19874 middle of the line.
19876 Things are further complicated by the fact that two consecutive
19877 line number entries for the same line is a heuristic used by gcc
19878 to denote the end of the prologue. So we can't just discard duplicate
19879 entries, we have to be selective about it. The heuristic we use is
19880 that we only collapse consecutive entries for the same line if at least
19881 one of those entries has a non-zero discriminator. PR 17276.
19883 Note: Addresses in the line number state machine can never go backwards
19884 within one sequence, thus this coalescing is ok. */
19887 dwarf_record_line_p (struct dwarf2_cu
*cu
,
19888 unsigned int line
, unsigned int last_line
,
19889 int line_has_non_zero_discriminator
,
19890 struct subfile
*last_subfile
)
19892 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
19894 if (line
!= last_line
)
19896 /* Same line for the same file that we've seen already.
19897 As a last check, for pr 17276, only record the line if the line
19898 has never had a non-zero discriminator. */
19899 if (!line_has_non_zero_discriminator
)
19904 /* Use the CU's builder to record line number LINE beginning at
19905 address ADDRESS in the line table of subfile SUBFILE. */
19908 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
19909 unsigned int line
, CORE_ADDR address
,
19910 struct dwarf2_cu
*cu
)
19912 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
19914 if (dwarf_line_debug
)
19916 fprintf_unfiltered (gdb_stdlog
,
19917 "Recording line %u, file %s, address %s\n",
19918 line
, lbasename (subfile
->name
),
19919 paddress (gdbarch
, address
));
19923 cu
->get_builder ()->record_line (subfile
, line
, addr
);
19926 /* Subroutine of dwarf_decode_lines_1 to simplify it.
19927 Mark the end of a set of line number records.
19928 The arguments are the same as for dwarf_record_line_1.
19929 If SUBFILE is NULL the request is ignored. */
19932 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
19933 CORE_ADDR address
, struct dwarf2_cu
*cu
)
19935 if (subfile
== NULL
)
19938 if (dwarf_line_debug
)
19940 fprintf_unfiltered (gdb_stdlog
,
19941 "Finishing current line, file %s, address %s\n",
19942 lbasename (subfile
->name
),
19943 paddress (gdbarch
, address
));
19946 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, cu
);
19950 lnp_state_machine::record_line (bool end_sequence
)
19952 if (dwarf_line_debug
)
19954 fprintf_unfiltered (gdb_stdlog
,
19955 "Processing actual line %u: file %u,"
19956 " address %s, is_stmt %u, discrim %u%s\n",
19958 paddress (m_gdbarch
, m_address
),
19959 m_is_stmt
, m_discriminator
,
19960 (end_sequence
? "\t(end sequence)" : ""));
19963 file_entry
*fe
= current_file ();
19966 dwarf2_debug_line_missing_file_complaint ();
19967 /* For now we ignore lines not starting on an instruction boundary.
19968 But not when processing end_sequence for compatibility with the
19969 previous version of the code. */
19970 else if (m_op_index
== 0 || end_sequence
)
19972 fe
->included_p
= 1;
19973 if (m_record_lines_p
19974 && (producer_is_codewarrior (m_cu
) || m_is_stmt
|| end_sequence
))
19976 if (m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ()
19979 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
19980 m_currently_recording_lines
? m_cu
: nullptr);
19985 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
19986 m_line_has_non_zero_discriminator
,
19989 buildsym_compunit
*builder
= m_cu
->get_builder ();
19990 dwarf_record_line_1 (m_gdbarch
,
19991 builder
->get_current_subfile (),
19993 m_currently_recording_lines
? m_cu
: nullptr);
19995 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
19996 m_last_line
= m_line
;
20002 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
20003 line_header
*lh
, bool record_lines_p
)
20007 m_record_lines_p
= record_lines_p
;
20008 m_line_header
= lh
;
20010 m_currently_recording_lines
= true;
20012 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
20013 was a line entry for it so that the backend has a chance to adjust it
20014 and also record it in case it needs it. This is currently used by MIPS
20015 code, cf. `mips_adjust_dwarf2_line'. */
20016 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
20017 m_is_stmt
= lh
->default_is_stmt
;
20018 m_discriminator
= 0;
20022 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
20023 const gdb_byte
*line_ptr
,
20024 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
20026 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
20027 the pc range of the CU. However, we restrict the test to only ADDRESS
20028 values of zero to preserve GDB's previous behaviour which is to handle
20029 the specific case of a function being GC'd by the linker. */
20031 if (address
== 0 && address
< unrelocated_lowpc
)
20033 /* This line table is for a function which has been
20034 GCd by the linker. Ignore it. PR gdb/12528 */
20036 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20037 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
20039 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
20040 line_offset
, objfile_name (objfile
));
20041 m_currently_recording_lines
= false;
20042 /* Note: m_currently_recording_lines is left as false until we see
20043 DW_LNE_end_sequence. */
20047 /* Subroutine of dwarf_decode_lines to simplify it.
20048 Process the line number information in LH.
20049 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
20050 program in order to set included_p for every referenced header. */
20053 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
20054 const int decode_for_pst_p
, CORE_ADDR lowpc
)
20056 const gdb_byte
*line_ptr
, *extended_end
;
20057 const gdb_byte
*line_end
;
20058 unsigned int bytes_read
, extended_len
;
20059 unsigned char op_code
, extended_op
;
20060 CORE_ADDR baseaddr
;
20061 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20062 bfd
*abfd
= objfile
->obfd
;
20063 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
20064 /* True if we're recording line info (as opposed to building partial
20065 symtabs and just interested in finding include files mentioned by
20066 the line number program). */
20067 bool record_lines_p
= !decode_for_pst_p
;
20069 baseaddr
= objfile
->text_section_offset ();
20071 line_ptr
= lh
->statement_program_start
;
20072 line_end
= lh
->statement_program_end
;
20074 /* Read the statement sequences until there's nothing left. */
20075 while (line_ptr
< line_end
)
20077 /* The DWARF line number program state machine. Reset the state
20078 machine at the start of each sequence. */
20079 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
20080 bool end_sequence
= false;
20082 if (record_lines_p
)
20084 /* Start a subfile for the current file of the state
20086 const file_entry
*fe
= state_machine
.current_file ();
20089 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
20092 /* Decode the table. */
20093 while (line_ptr
< line_end
&& !end_sequence
)
20095 op_code
= read_1_byte (abfd
, line_ptr
);
20098 if (op_code
>= lh
->opcode_base
)
20100 /* Special opcode. */
20101 state_machine
.handle_special_opcode (op_code
);
20103 else switch (op_code
)
20105 case DW_LNS_extended_op
:
20106 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
20108 line_ptr
+= bytes_read
;
20109 extended_end
= line_ptr
+ extended_len
;
20110 extended_op
= read_1_byte (abfd
, line_ptr
);
20112 switch (extended_op
)
20114 case DW_LNE_end_sequence
:
20115 state_machine
.handle_end_sequence ();
20116 end_sequence
= true;
20118 case DW_LNE_set_address
:
20121 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
20122 line_ptr
+= bytes_read
;
20124 state_machine
.check_line_address (cu
, line_ptr
,
20125 lowpc
- baseaddr
, address
);
20126 state_machine
.handle_set_address (baseaddr
, address
);
20129 case DW_LNE_define_file
:
20131 const char *cur_file
;
20132 unsigned int mod_time
, length
;
20135 cur_file
= read_direct_string (abfd
, line_ptr
,
20137 line_ptr
+= bytes_read
;
20138 dindex
= (dir_index
)
20139 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20140 line_ptr
+= bytes_read
;
20142 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20143 line_ptr
+= bytes_read
;
20145 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20146 line_ptr
+= bytes_read
;
20147 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
20150 case DW_LNE_set_discriminator
:
20152 /* The discriminator is not interesting to the
20153 debugger; just ignore it. We still need to
20154 check its value though:
20155 if there are consecutive entries for the same
20156 (non-prologue) line we want to coalesce them.
20159 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20160 line_ptr
+= bytes_read
;
20162 state_machine
.handle_set_discriminator (discr
);
20166 complaint (_("mangled .debug_line section"));
20169 /* Make sure that we parsed the extended op correctly. If e.g.
20170 we expected a different address size than the producer used,
20171 we may have read the wrong number of bytes. */
20172 if (line_ptr
!= extended_end
)
20174 complaint (_("mangled .debug_line section"));
20179 state_machine
.handle_copy ();
20181 case DW_LNS_advance_pc
:
20184 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20185 line_ptr
+= bytes_read
;
20187 state_machine
.handle_advance_pc (adjust
);
20190 case DW_LNS_advance_line
:
20193 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
20194 line_ptr
+= bytes_read
;
20196 state_machine
.handle_advance_line (line_delta
);
20199 case DW_LNS_set_file
:
20201 file_name_index file
20202 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
20204 line_ptr
+= bytes_read
;
20206 state_machine
.handle_set_file (file
);
20209 case DW_LNS_set_column
:
20210 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20211 line_ptr
+= bytes_read
;
20213 case DW_LNS_negate_stmt
:
20214 state_machine
.handle_negate_stmt ();
20216 case DW_LNS_set_basic_block
:
20218 /* Add to the address register of the state machine the
20219 address increment value corresponding to special opcode
20220 255. I.e., this value is scaled by the minimum
20221 instruction length since special opcode 255 would have
20222 scaled the increment. */
20223 case DW_LNS_const_add_pc
:
20224 state_machine
.handle_const_add_pc ();
20226 case DW_LNS_fixed_advance_pc
:
20228 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
20231 state_machine
.handle_fixed_advance_pc (addr_adj
);
20236 /* Unknown standard opcode, ignore it. */
20239 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
20241 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20242 line_ptr
+= bytes_read
;
20249 dwarf2_debug_line_missing_end_sequence_complaint ();
20251 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
20252 in which case we still finish recording the last line). */
20253 state_machine
.record_line (true);
20257 /* Decode the Line Number Program (LNP) for the given line_header
20258 structure and CU. The actual information extracted and the type
20259 of structures created from the LNP depends on the value of PST.
20261 1. If PST is NULL, then this procedure uses the data from the program
20262 to create all necessary symbol tables, and their linetables.
20264 2. If PST is not NULL, this procedure reads the program to determine
20265 the list of files included by the unit represented by PST, and
20266 builds all the associated partial symbol tables.
20268 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20269 It is used for relative paths in the line table.
20270 NOTE: When processing partial symtabs (pst != NULL),
20271 comp_dir == pst->dirname.
20273 NOTE: It is important that psymtabs have the same file name (via strcmp)
20274 as the corresponding symtab. Since COMP_DIR is not used in the name of the
20275 symtab we don't use it in the name of the psymtabs we create.
20276 E.g. expand_line_sal requires this when finding psymtabs to expand.
20277 A good testcase for this is mb-inline.exp.
20279 LOWPC is the lowest address in CU (or 0 if not known).
20281 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
20282 for its PC<->lines mapping information. Otherwise only the filename
20283 table is read in. */
20286 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
20287 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
20288 CORE_ADDR lowpc
, int decode_mapping
)
20290 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20291 const int decode_for_pst_p
= (pst
!= NULL
);
20293 if (decode_mapping
)
20294 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
20296 if (decode_for_pst_p
)
20298 /* Now that we're done scanning the Line Header Program, we can
20299 create the psymtab of each included file. */
20300 for (auto &file_entry
: lh
->file_names ())
20301 if (file_entry
.included_p
== 1)
20303 gdb::unique_xmalloc_ptr
<char> name_holder
;
20304 const char *include_name
=
20305 psymtab_include_file_name (lh
, file_entry
, pst
,
20306 comp_dir
, &name_holder
);
20307 if (include_name
!= NULL
)
20308 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
20313 /* Make sure a symtab is created for every file, even files
20314 which contain only variables (i.e. no code with associated
20316 buildsym_compunit
*builder
= cu
->get_builder ();
20317 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
20319 for (auto &fe
: lh
->file_names ())
20321 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
20322 if (builder
->get_current_subfile ()->symtab
== NULL
)
20324 builder
->get_current_subfile ()->symtab
20325 = allocate_symtab (cust
,
20326 builder
->get_current_subfile ()->name
);
20328 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
20333 /* Start a subfile for DWARF. FILENAME is the name of the file and
20334 DIRNAME the name of the source directory which contains FILENAME
20335 or NULL if not known.
20336 This routine tries to keep line numbers from identical absolute and
20337 relative file names in a common subfile.
20339 Using the `list' example from the GDB testsuite, which resides in
20340 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
20341 of /srcdir/list0.c yields the following debugging information for list0.c:
20343 DW_AT_name: /srcdir/list0.c
20344 DW_AT_comp_dir: /compdir
20345 files.files[0].name: list0.h
20346 files.files[0].dir: /srcdir
20347 files.files[1].name: list0.c
20348 files.files[1].dir: /srcdir
20350 The line number information for list0.c has to end up in a single
20351 subfile, so that `break /srcdir/list0.c:1' works as expected.
20352 start_subfile will ensure that this happens provided that we pass the
20353 concatenation of files.files[1].dir and files.files[1].name as the
20357 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
20358 const char *dirname
)
20360 gdb::unique_xmalloc_ptr
<char> copy
;
20362 /* In order not to lose the line information directory,
20363 we concatenate it to the filename when it makes sense.
20364 Note that the Dwarf3 standard says (speaking of filenames in line
20365 information): ``The directory index is ignored for file names
20366 that represent full path names''. Thus ignoring dirname in the
20367 `else' branch below isn't an issue. */
20369 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
20371 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
20372 filename
= copy
.get ();
20375 cu
->get_builder ()->start_subfile (filename
);
20378 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
20379 buildsym_compunit constructor. */
20381 struct compunit_symtab
*
20382 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
20385 gdb_assert (m_builder
== nullptr);
20387 m_builder
.reset (new struct buildsym_compunit
20388 (per_cu
->dwarf2_per_objfile
->objfile
,
20389 name
, comp_dir
, language
, low_pc
));
20391 list_in_scope
= get_builder ()->get_file_symbols ();
20393 get_builder ()->record_debugformat ("DWARF 2");
20394 get_builder ()->record_producer (producer
);
20396 processing_has_namespace_info
= false;
20398 return get_builder ()->get_compunit_symtab ();
20402 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
20403 struct dwarf2_cu
*cu
)
20405 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20406 struct comp_unit_head
*cu_header
= &cu
->header
;
20408 /* NOTE drow/2003-01-30: There used to be a comment and some special
20409 code here to turn a symbol with DW_AT_external and a
20410 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
20411 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
20412 with some versions of binutils) where shared libraries could have
20413 relocations against symbols in their debug information - the
20414 minimal symbol would have the right address, but the debug info
20415 would not. It's no longer necessary, because we will explicitly
20416 apply relocations when we read in the debug information now. */
20418 /* A DW_AT_location attribute with no contents indicates that a
20419 variable has been optimized away. */
20420 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0)
20422 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20426 /* Handle one degenerate form of location expression specially, to
20427 preserve GDB's previous behavior when section offsets are
20428 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
20429 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
20431 if (attr
->form_is_block ()
20432 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
20433 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
20434 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
20435 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
20436 && (DW_BLOCK (attr
)->size
20437 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
20439 unsigned int dummy
;
20441 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
20442 SET_SYMBOL_VALUE_ADDRESS
20443 (sym
, cu
->header
.read_address (objfile
->obfd
,
20444 DW_BLOCK (attr
)->data
+ 1,
20447 SET_SYMBOL_VALUE_ADDRESS
20448 (sym
, read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1,
20450 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
20451 fixup_symbol_section (sym
, objfile
);
20452 SET_SYMBOL_VALUE_ADDRESS
20454 SYMBOL_VALUE_ADDRESS (sym
)
20455 + objfile
->section_offsets
[SYMBOL_SECTION (sym
)]);
20459 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
20460 expression evaluator, and use LOC_COMPUTED only when necessary
20461 (i.e. when the value of a register or memory location is
20462 referenced, or a thread-local block, etc.). Then again, it might
20463 not be worthwhile. I'm assuming that it isn't unless performance
20464 or memory numbers show me otherwise. */
20466 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
20468 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
20469 cu
->has_loclist
= true;
20472 /* Given a pointer to a DWARF information entry, figure out if we need
20473 to make a symbol table entry for it, and if so, create a new entry
20474 and return a pointer to it.
20475 If TYPE is NULL, determine symbol type from the die, otherwise
20476 used the passed type.
20477 If SPACE is not NULL, use it to hold the new symbol. If it is
20478 NULL, allocate a new symbol on the objfile's obstack. */
20480 static struct symbol
*
20481 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
20482 struct symbol
*space
)
20484 struct dwarf2_per_objfile
*dwarf2_per_objfile
20485 = cu
->per_cu
->dwarf2_per_objfile
;
20486 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20487 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
20488 struct symbol
*sym
= NULL
;
20490 struct attribute
*attr
= NULL
;
20491 struct attribute
*attr2
= NULL
;
20492 CORE_ADDR baseaddr
;
20493 struct pending
**list_to_add
= NULL
;
20495 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
20497 baseaddr
= objfile
->text_section_offset ();
20499 name
= dwarf2_name (die
, cu
);
20502 const char *linkagename
;
20503 int suppress_add
= 0;
20508 sym
= allocate_symbol (objfile
);
20509 OBJSTAT (objfile
, n_syms
++);
20511 /* Cache this symbol's name and the name's demangled form (if any). */
20512 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
20513 linkagename
= dwarf2_physname (name
, die
, cu
);
20514 sym
->compute_and_set_names (linkagename
, false, objfile
->per_bfd
);
20516 /* Fortran does not have mangling standard and the mangling does differ
20517 between gfortran, iFort etc. */
20518 if (cu
->language
== language_fortran
20519 && symbol_get_demangled_name (sym
) == NULL
)
20520 symbol_set_demangled_name (sym
,
20521 dwarf2_full_name (name
, die
, cu
),
20524 /* Default assumptions.
20525 Use the passed type or decode it from the die. */
20526 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20527 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20529 SYMBOL_TYPE (sym
) = type
;
20531 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
20532 attr
= dwarf2_attr (die
,
20533 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
20535 if (attr
!= nullptr)
20537 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
20540 attr
= dwarf2_attr (die
,
20541 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
20543 if (attr
!= nullptr)
20545 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
20546 struct file_entry
*fe
;
20548 if (cu
->line_header
!= NULL
)
20549 fe
= cu
->line_header
->file_name_at (file_index
);
20554 complaint (_("file index out of range"));
20556 symbol_set_symtab (sym
, fe
->symtab
);
20562 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
20563 if (attr
!= nullptr)
20567 addr
= attr
->value_as_address ();
20568 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
20569 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
20571 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
20572 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
20573 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
20574 add_symbol_to_list (sym
, cu
->list_in_scope
);
20576 case DW_TAG_subprogram
:
20577 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20579 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20580 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20581 if ((attr2
&& (DW_UNSND (attr2
) != 0))
20582 || cu
->language
== language_ada
20583 || cu
->language
== language_fortran
)
20585 /* Subprograms marked external are stored as a global symbol.
20586 Ada and Fortran subprograms, whether marked external or
20587 not, are always stored as a global symbol, because we want
20588 to be able to access them globally. For instance, we want
20589 to be able to break on a nested subprogram without having
20590 to specify the context. */
20591 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20595 list_to_add
= cu
->list_in_scope
;
20598 case DW_TAG_inlined_subroutine
:
20599 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20601 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20602 SYMBOL_INLINED (sym
) = 1;
20603 list_to_add
= cu
->list_in_scope
;
20605 case DW_TAG_template_value_param
:
20607 /* Fall through. */
20608 case DW_TAG_constant
:
20609 case DW_TAG_variable
:
20610 case DW_TAG_member
:
20611 /* Compilation with minimal debug info may result in
20612 variables with missing type entries. Change the
20613 misleading `void' type to something sensible. */
20614 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
20615 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
20617 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20618 /* In the case of DW_TAG_member, we should only be called for
20619 static const members. */
20620 if (die
->tag
== DW_TAG_member
)
20622 /* dwarf2_add_field uses die_is_declaration,
20623 so we do the same. */
20624 gdb_assert (die_is_declaration (die
, cu
));
20627 if (attr
!= nullptr)
20629 dwarf2_const_value (attr
, sym
, cu
);
20630 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20633 if (attr2
&& (DW_UNSND (attr2
) != 0))
20634 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20636 list_to_add
= cu
->list_in_scope
;
20640 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20641 if (attr
!= nullptr)
20643 var_decode_location (attr
, sym
, cu
);
20644 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20646 /* Fortran explicitly imports any global symbols to the local
20647 scope by DW_TAG_common_block. */
20648 if (cu
->language
== language_fortran
&& die
->parent
20649 && die
->parent
->tag
== DW_TAG_common_block
)
20652 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20653 && SYMBOL_VALUE_ADDRESS (sym
) == 0
20654 && !dwarf2_per_objfile
->has_section_at_zero
)
20656 /* When a static variable is eliminated by the linker,
20657 the corresponding debug information is not stripped
20658 out, but the variable address is set to null;
20659 do not add such variables into symbol table. */
20661 else if (attr2
&& (DW_UNSND (attr2
) != 0))
20663 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20664 && (objfile
->flags
& OBJF_MAINLINE
) == 0
20665 && dwarf2_per_objfile
->can_copy
)
20667 /* A global static variable might be subject to
20668 copy relocation. We first check for a local
20669 minsym, though, because maybe the symbol was
20670 marked hidden, in which case this would not
20672 bound_minimal_symbol found
20673 = (lookup_minimal_symbol_linkage
20674 (sym
->linkage_name (), objfile
));
20675 if (found
.minsym
!= nullptr)
20676 sym
->maybe_copied
= 1;
20679 /* A variable with DW_AT_external is never static,
20680 but it may be block-scoped. */
20682 = ((cu
->list_in_scope
20683 == cu
->get_builder ()->get_file_symbols ())
20684 ? cu
->get_builder ()->get_global_symbols ()
20685 : cu
->list_in_scope
);
20688 list_to_add
= cu
->list_in_scope
;
20692 /* We do not know the address of this symbol.
20693 If it is an external symbol and we have type information
20694 for it, enter the symbol as a LOC_UNRESOLVED symbol.
20695 The address of the variable will then be determined from
20696 the minimal symbol table whenever the variable is
20698 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20700 /* Fortran explicitly imports any global symbols to the local
20701 scope by DW_TAG_common_block. */
20702 if (cu
->language
== language_fortran
&& die
->parent
20703 && die
->parent
->tag
== DW_TAG_common_block
)
20705 /* SYMBOL_CLASS doesn't matter here because
20706 read_common_block is going to reset it. */
20708 list_to_add
= cu
->list_in_scope
;
20710 else if (attr2
&& (DW_UNSND (attr2
) != 0)
20711 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
20713 /* A variable with DW_AT_external is never static, but it
20714 may be block-scoped. */
20716 = ((cu
->list_in_scope
20717 == cu
->get_builder ()->get_file_symbols ())
20718 ? cu
->get_builder ()->get_global_symbols ()
20719 : cu
->list_in_scope
);
20721 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
20723 else if (!die_is_declaration (die
, cu
))
20725 /* Use the default LOC_OPTIMIZED_OUT class. */
20726 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
20728 list_to_add
= cu
->list_in_scope
;
20732 case DW_TAG_formal_parameter
:
20734 /* If we are inside a function, mark this as an argument. If
20735 not, we might be looking at an argument to an inlined function
20736 when we do not have enough information to show inlined frames;
20737 pretend it's a local variable in that case so that the user can
20739 struct context_stack
*curr
20740 = cu
->get_builder ()->get_current_context_stack ();
20741 if (curr
!= nullptr && curr
->name
!= nullptr)
20742 SYMBOL_IS_ARGUMENT (sym
) = 1;
20743 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20744 if (attr
!= nullptr)
20746 var_decode_location (attr
, sym
, cu
);
20748 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20749 if (attr
!= nullptr)
20751 dwarf2_const_value (attr
, sym
, cu
);
20754 list_to_add
= cu
->list_in_scope
;
20757 case DW_TAG_unspecified_parameters
:
20758 /* From varargs functions; gdb doesn't seem to have any
20759 interest in this information, so just ignore it for now.
20762 case DW_TAG_template_type_param
:
20764 /* Fall through. */
20765 case DW_TAG_class_type
:
20766 case DW_TAG_interface_type
:
20767 case DW_TAG_structure_type
:
20768 case DW_TAG_union_type
:
20769 case DW_TAG_set_type
:
20770 case DW_TAG_enumeration_type
:
20771 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20772 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
20775 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
20776 really ever be static objects: otherwise, if you try
20777 to, say, break of a class's method and you're in a file
20778 which doesn't mention that class, it won't work unless
20779 the check for all static symbols in lookup_symbol_aux
20780 saves you. See the OtherFileClass tests in
20781 gdb.c++/namespace.exp. */
20785 buildsym_compunit
*builder
= cu
->get_builder ();
20787 = (cu
->list_in_scope
== builder
->get_file_symbols ()
20788 && cu
->language
== language_cplus
20789 ? builder
->get_global_symbols ()
20790 : cu
->list_in_scope
);
20792 /* The semantics of C++ state that "struct foo {
20793 ... }" also defines a typedef for "foo". */
20794 if (cu
->language
== language_cplus
20795 || cu
->language
== language_ada
20796 || cu
->language
== language_d
20797 || cu
->language
== language_rust
)
20799 /* The symbol's name is already allocated along
20800 with this objfile, so we don't need to
20801 duplicate it for the type. */
20802 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
20803 TYPE_NAME (SYMBOL_TYPE (sym
)) = sym
->search_name ();
20808 case DW_TAG_typedef
:
20809 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20810 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20811 list_to_add
= cu
->list_in_scope
;
20813 case DW_TAG_base_type
:
20814 case DW_TAG_subrange_type
:
20815 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20816 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20817 list_to_add
= cu
->list_in_scope
;
20819 case DW_TAG_enumerator
:
20820 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20821 if (attr
!= nullptr)
20823 dwarf2_const_value (attr
, sym
, cu
);
20826 /* NOTE: carlton/2003-11-10: See comment above in the
20827 DW_TAG_class_type, etc. block. */
20830 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
20831 && cu
->language
== language_cplus
20832 ? cu
->get_builder ()->get_global_symbols ()
20833 : cu
->list_in_scope
);
20836 case DW_TAG_imported_declaration
:
20837 case DW_TAG_namespace
:
20838 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20839 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20841 case DW_TAG_module
:
20842 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20843 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
20844 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20846 case DW_TAG_common_block
:
20847 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
20848 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
20849 add_symbol_to_list (sym
, cu
->list_in_scope
);
20852 /* Not a tag we recognize. Hopefully we aren't processing
20853 trash data, but since we must specifically ignore things
20854 we don't recognize, there is nothing else we should do at
20856 complaint (_("unsupported tag: '%s'"),
20857 dwarf_tag_name (die
->tag
));
20863 sym
->hash_next
= objfile
->template_symbols
;
20864 objfile
->template_symbols
= sym
;
20865 list_to_add
= NULL
;
20868 if (list_to_add
!= NULL
)
20869 add_symbol_to_list (sym
, list_to_add
);
20871 /* For the benefit of old versions of GCC, check for anonymous
20872 namespaces based on the demangled name. */
20873 if (!cu
->processing_has_namespace_info
20874 && cu
->language
== language_cplus
)
20875 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
20880 /* Given an attr with a DW_FORM_dataN value in host byte order,
20881 zero-extend it as appropriate for the symbol's type. The DWARF
20882 standard (v4) is not entirely clear about the meaning of using
20883 DW_FORM_dataN for a constant with a signed type, where the type is
20884 wider than the data. The conclusion of a discussion on the DWARF
20885 list was that this is unspecified. We choose to always zero-extend
20886 because that is the interpretation long in use by GCC. */
20889 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
20890 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
20892 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20893 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
20894 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
20895 LONGEST l
= DW_UNSND (attr
);
20897 if (bits
< sizeof (*value
) * 8)
20899 l
&= ((LONGEST
) 1 << bits
) - 1;
20902 else if (bits
== sizeof (*value
) * 8)
20906 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
20907 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
20914 /* Read a constant value from an attribute. Either set *VALUE, or if
20915 the value does not fit in *VALUE, set *BYTES - either already
20916 allocated on the objfile obstack, or newly allocated on OBSTACK,
20917 or, set *BATON, if we translated the constant to a location
20921 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
20922 const char *name
, struct obstack
*obstack
,
20923 struct dwarf2_cu
*cu
,
20924 LONGEST
*value
, const gdb_byte
**bytes
,
20925 struct dwarf2_locexpr_baton
**baton
)
20927 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20928 struct comp_unit_head
*cu_header
= &cu
->header
;
20929 struct dwarf_block
*blk
;
20930 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
20931 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
20937 switch (attr
->form
)
20940 case DW_FORM_addrx
:
20941 case DW_FORM_GNU_addr_index
:
20945 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
20946 dwarf2_const_value_length_mismatch_complaint (name
,
20947 cu_header
->addr_size
,
20948 TYPE_LENGTH (type
));
20949 /* Symbols of this form are reasonably rare, so we just
20950 piggyback on the existing location code rather than writing
20951 a new implementation of symbol_computed_ops. */
20952 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
20953 (*baton
)->per_cu
= cu
->per_cu
;
20954 gdb_assert ((*baton
)->per_cu
);
20956 (*baton
)->size
= 2 + cu_header
->addr_size
;
20957 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
20958 (*baton
)->data
= data
;
20960 data
[0] = DW_OP_addr
;
20961 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
20962 byte_order
, DW_ADDR (attr
));
20963 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
20966 case DW_FORM_string
:
20969 case DW_FORM_GNU_str_index
:
20970 case DW_FORM_GNU_strp_alt
:
20971 /* DW_STRING is already allocated on the objfile obstack, point
20973 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
20975 case DW_FORM_block1
:
20976 case DW_FORM_block2
:
20977 case DW_FORM_block4
:
20978 case DW_FORM_block
:
20979 case DW_FORM_exprloc
:
20980 case DW_FORM_data16
:
20981 blk
= DW_BLOCK (attr
);
20982 if (TYPE_LENGTH (type
) != blk
->size
)
20983 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
20984 TYPE_LENGTH (type
));
20985 *bytes
= blk
->data
;
20988 /* The DW_AT_const_value attributes are supposed to carry the
20989 symbol's value "represented as it would be on the target
20990 architecture." By the time we get here, it's already been
20991 converted to host endianness, so we just need to sign- or
20992 zero-extend it as appropriate. */
20993 case DW_FORM_data1
:
20994 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
20996 case DW_FORM_data2
:
20997 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
20999 case DW_FORM_data4
:
21000 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
21002 case DW_FORM_data8
:
21003 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
21006 case DW_FORM_sdata
:
21007 case DW_FORM_implicit_const
:
21008 *value
= DW_SND (attr
);
21011 case DW_FORM_udata
:
21012 *value
= DW_UNSND (attr
);
21016 complaint (_("unsupported const value attribute form: '%s'"),
21017 dwarf_form_name (attr
->form
));
21024 /* Copy constant value from an attribute to a symbol. */
21027 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
21028 struct dwarf2_cu
*cu
)
21030 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21032 const gdb_byte
*bytes
;
21033 struct dwarf2_locexpr_baton
*baton
;
21035 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
21036 sym
->print_name (),
21037 &objfile
->objfile_obstack
, cu
,
21038 &value
, &bytes
, &baton
);
21042 SYMBOL_LOCATION_BATON (sym
) = baton
;
21043 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
21045 else if (bytes
!= NULL
)
21047 SYMBOL_VALUE_BYTES (sym
) = bytes
;
21048 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
21052 SYMBOL_VALUE (sym
) = value
;
21053 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
21057 /* Return the type of the die in question using its DW_AT_type attribute. */
21059 static struct type
*
21060 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21062 struct attribute
*type_attr
;
21064 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
21067 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21068 /* A missing DW_AT_type represents a void type. */
21069 return objfile_type (objfile
)->builtin_void
;
21072 return lookup_die_type (die
, type_attr
, cu
);
21075 /* True iff CU's producer generates GNAT Ada auxiliary information
21076 that allows to find parallel types through that information instead
21077 of having to do expensive parallel lookups by type name. */
21080 need_gnat_info (struct dwarf2_cu
*cu
)
21082 /* Assume that the Ada compiler was GNAT, which always produces
21083 the auxiliary information. */
21084 return (cu
->language
== language_ada
);
21087 /* Return the auxiliary type of the die in question using its
21088 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
21089 attribute is not present. */
21091 static struct type
*
21092 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21094 struct attribute
*type_attr
;
21096 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
21100 return lookup_die_type (die
, type_attr
, cu
);
21103 /* If DIE has a descriptive_type attribute, then set the TYPE's
21104 descriptive type accordingly. */
21107 set_descriptive_type (struct type
*type
, struct die_info
*die
,
21108 struct dwarf2_cu
*cu
)
21110 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
21112 if (descriptive_type
)
21114 ALLOCATE_GNAT_AUX_TYPE (type
);
21115 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
21119 /* Return the containing type of the die in question using its
21120 DW_AT_containing_type attribute. */
21122 static struct type
*
21123 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21125 struct attribute
*type_attr
;
21126 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21128 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
21130 error (_("Dwarf Error: Problem turning containing type into gdb type "
21131 "[in module %s]"), objfile_name (objfile
));
21133 return lookup_die_type (die
, type_attr
, cu
);
21136 /* Return an error marker type to use for the ill formed type in DIE/CU. */
21138 static struct type
*
21139 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
21141 struct dwarf2_per_objfile
*dwarf2_per_objfile
21142 = cu
->per_cu
->dwarf2_per_objfile
;
21143 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21146 std::string message
21147 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
21148 objfile_name (objfile
),
21149 sect_offset_str (cu
->header
.sect_off
),
21150 sect_offset_str (die
->sect_off
));
21151 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
21153 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
21156 /* Look up the type of DIE in CU using its type attribute ATTR.
21157 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
21158 DW_AT_containing_type.
21159 If there is no type substitute an error marker. */
21161 static struct type
*
21162 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
21163 struct dwarf2_cu
*cu
)
21165 struct dwarf2_per_objfile
*dwarf2_per_objfile
21166 = cu
->per_cu
->dwarf2_per_objfile
;
21167 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21168 struct type
*this_type
;
21170 gdb_assert (attr
->name
== DW_AT_type
21171 || attr
->name
== DW_AT_GNAT_descriptive_type
21172 || attr
->name
== DW_AT_containing_type
);
21174 /* First see if we have it cached. */
21176 if (attr
->form
== DW_FORM_GNU_ref_alt
)
21178 struct dwarf2_per_cu_data
*per_cu
;
21179 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
21181 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
21182 dwarf2_per_objfile
);
21183 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
21185 else if (attr
->form_is_ref ())
21187 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
21189 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
21191 else if (attr
->form
== DW_FORM_ref_sig8
)
21193 ULONGEST signature
= DW_SIGNATURE (attr
);
21195 return get_signatured_type (die
, signature
, cu
);
21199 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
21200 " at %s [in module %s]"),
21201 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
21202 objfile_name (objfile
));
21203 return build_error_marker_type (cu
, die
);
21206 /* If not cached we need to read it in. */
21208 if (this_type
== NULL
)
21210 struct die_info
*type_die
= NULL
;
21211 struct dwarf2_cu
*type_cu
= cu
;
21213 if (attr
->form_is_ref ())
21214 type_die
= follow_die_ref (die
, attr
, &type_cu
);
21215 if (type_die
== NULL
)
21216 return build_error_marker_type (cu
, die
);
21217 /* If we find the type now, it's probably because the type came
21218 from an inter-CU reference and the type's CU got expanded before
21220 this_type
= read_type_die (type_die
, type_cu
);
21223 /* If we still don't have a type use an error marker. */
21225 if (this_type
== NULL
)
21226 return build_error_marker_type (cu
, die
);
21231 /* Return the type in DIE, CU.
21232 Returns NULL for invalid types.
21234 This first does a lookup in die_type_hash,
21235 and only reads the die in if necessary.
21237 NOTE: This can be called when reading in partial or full symbols. */
21239 static struct type
*
21240 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
21242 struct type
*this_type
;
21244 this_type
= get_die_type (die
, cu
);
21248 return read_type_die_1 (die
, cu
);
21251 /* Read the type in DIE, CU.
21252 Returns NULL for invalid types. */
21254 static struct type
*
21255 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
21257 struct type
*this_type
= NULL
;
21261 case DW_TAG_class_type
:
21262 case DW_TAG_interface_type
:
21263 case DW_TAG_structure_type
:
21264 case DW_TAG_union_type
:
21265 this_type
= read_structure_type (die
, cu
);
21267 case DW_TAG_enumeration_type
:
21268 this_type
= read_enumeration_type (die
, cu
);
21270 case DW_TAG_subprogram
:
21271 case DW_TAG_subroutine_type
:
21272 case DW_TAG_inlined_subroutine
:
21273 this_type
= read_subroutine_type (die
, cu
);
21275 case DW_TAG_array_type
:
21276 this_type
= read_array_type (die
, cu
);
21278 case DW_TAG_set_type
:
21279 this_type
= read_set_type (die
, cu
);
21281 case DW_TAG_pointer_type
:
21282 this_type
= read_tag_pointer_type (die
, cu
);
21284 case DW_TAG_ptr_to_member_type
:
21285 this_type
= read_tag_ptr_to_member_type (die
, cu
);
21287 case DW_TAG_reference_type
:
21288 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
21290 case DW_TAG_rvalue_reference_type
:
21291 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
21293 case DW_TAG_const_type
:
21294 this_type
= read_tag_const_type (die
, cu
);
21296 case DW_TAG_volatile_type
:
21297 this_type
= read_tag_volatile_type (die
, cu
);
21299 case DW_TAG_restrict_type
:
21300 this_type
= read_tag_restrict_type (die
, cu
);
21302 case DW_TAG_string_type
:
21303 this_type
= read_tag_string_type (die
, cu
);
21305 case DW_TAG_typedef
:
21306 this_type
= read_typedef (die
, cu
);
21308 case DW_TAG_subrange_type
:
21309 this_type
= read_subrange_type (die
, cu
);
21311 case DW_TAG_base_type
:
21312 this_type
= read_base_type (die
, cu
);
21314 case DW_TAG_unspecified_type
:
21315 this_type
= read_unspecified_type (die
, cu
);
21317 case DW_TAG_namespace
:
21318 this_type
= read_namespace_type (die
, cu
);
21320 case DW_TAG_module
:
21321 this_type
= read_module_type (die
, cu
);
21323 case DW_TAG_atomic_type
:
21324 this_type
= read_tag_atomic_type (die
, cu
);
21327 complaint (_("unexpected tag in read_type_die: '%s'"),
21328 dwarf_tag_name (die
->tag
));
21335 /* See if we can figure out if the class lives in a namespace. We do
21336 this by looking for a member function; its demangled name will
21337 contain namespace info, if there is any.
21338 Return the computed name or NULL.
21339 Space for the result is allocated on the objfile's obstack.
21340 This is the full-die version of guess_partial_die_structure_name.
21341 In this case we know DIE has no useful parent. */
21343 static const char *
21344 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21346 struct die_info
*spec_die
;
21347 struct dwarf2_cu
*spec_cu
;
21348 struct die_info
*child
;
21349 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21352 spec_die
= die_specification (die
, &spec_cu
);
21353 if (spec_die
!= NULL
)
21359 for (child
= die
->child
;
21361 child
= child
->sibling
)
21363 if (child
->tag
== DW_TAG_subprogram
)
21365 const char *linkage_name
= dw2_linkage_name (child
, cu
);
21367 if (linkage_name
!= NULL
)
21369 gdb::unique_xmalloc_ptr
<char> actual_name
21370 (language_class_name_from_physname (cu
->language_defn
,
21372 const char *name
= NULL
;
21374 if (actual_name
!= NULL
)
21376 const char *die_name
= dwarf2_name (die
, cu
);
21378 if (die_name
!= NULL
21379 && strcmp (die_name
, actual_name
.get ()) != 0)
21381 /* Strip off the class name from the full name.
21382 We want the prefix. */
21383 int die_name_len
= strlen (die_name
);
21384 int actual_name_len
= strlen (actual_name
.get ());
21385 const char *ptr
= actual_name
.get ();
21387 /* Test for '::' as a sanity check. */
21388 if (actual_name_len
> die_name_len
+ 2
21389 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
21390 name
= obstack_strndup (
21391 &objfile
->per_bfd
->storage_obstack
,
21392 ptr
, actual_name_len
- die_name_len
- 2);
21403 /* GCC might emit a nameless typedef that has a linkage name. Determine the
21404 prefix part in such case. See
21405 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21407 static const char *
21408 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21410 struct attribute
*attr
;
21413 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
21414 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
21417 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
21420 attr
= dw2_linkage_name_attr (die
, cu
);
21421 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21424 /* dwarf2_name had to be already called. */
21425 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
21427 /* Strip the base name, keep any leading namespaces/classes. */
21428 base
= strrchr (DW_STRING (attr
), ':');
21429 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
21432 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21433 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
21435 &base
[-1] - DW_STRING (attr
));
21438 /* Return the name of the namespace/class that DIE is defined within,
21439 or "" if we can't tell. The caller should not xfree the result.
21441 For example, if we're within the method foo() in the following
21451 then determine_prefix on foo's die will return "N::C". */
21453 static const char *
21454 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21456 struct dwarf2_per_objfile
*dwarf2_per_objfile
21457 = cu
->per_cu
->dwarf2_per_objfile
;
21458 struct die_info
*parent
, *spec_die
;
21459 struct dwarf2_cu
*spec_cu
;
21460 struct type
*parent_type
;
21461 const char *retval
;
21463 if (cu
->language
!= language_cplus
21464 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
21465 && cu
->language
!= language_rust
)
21468 retval
= anonymous_struct_prefix (die
, cu
);
21472 /* We have to be careful in the presence of DW_AT_specification.
21473 For example, with GCC 3.4, given the code
21477 // Definition of N::foo.
21481 then we'll have a tree of DIEs like this:
21483 1: DW_TAG_compile_unit
21484 2: DW_TAG_namespace // N
21485 3: DW_TAG_subprogram // declaration of N::foo
21486 4: DW_TAG_subprogram // definition of N::foo
21487 DW_AT_specification // refers to die #3
21489 Thus, when processing die #4, we have to pretend that we're in
21490 the context of its DW_AT_specification, namely the contex of die
21493 spec_die
= die_specification (die
, &spec_cu
);
21494 if (spec_die
== NULL
)
21495 parent
= die
->parent
;
21498 parent
= spec_die
->parent
;
21502 if (parent
== NULL
)
21504 else if (parent
->building_fullname
)
21507 const char *parent_name
;
21509 /* It has been seen on RealView 2.2 built binaries,
21510 DW_TAG_template_type_param types actually _defined_ as
21511 children of the parent class:
21514 template class <class Enum> Class{};
21515 Class<enum E> class_e;
21517 1: DW_TAG_class_type (Class)
21518 2: DW_TAG_enumeration_type (E)
21519 3: DW_TAG_enumerator (enum1:0)
21520 3: DW_TAG_enumerator (enum2:1)
21522 2: DW_TAG_template_type_param
21523 DW_AT_type DW_FORM_ref_udata (E)
21525 Besides being broken debug info, it can put GDB into an
21526 infinite loop. Consider:
21528 When we're building the full name for Class<E>, we'll start
21529 at Class, and go look over its template type parameters,
21530 finding E. We'll then try to build the full name of E, and
21531 reach here. We're now trying to build the full name of E,
21532 and look over the parent DIE for containing scope. In the
21533 broken case, if we followed the parent DIE of E, we'd again
21534 find Class, and once again go look at its template type
21535 arguments, etc., etc. Simply don't consider such parent die
21536 as source-level parent of this die (it can't be, the language
21537 doesn't allow it), and break the loop here. */
21538 name
= dwarf2_name (die
, cu
);
21539 parent_name
= dwarf2_name (parent
, cu
);
21540 complaint (_("template param type '%s' defined within parent '%s'"),
21541 name
? name
: "<unknown>",
21542 parent_name
? parent_name
: "<unknown>");
21546 switch (parent
->tag
)
21548 case DW_TAG_namespace
:
21549 parent_type
= read_type_die (parent
, cu
);
21550 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
21551 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
21552 Work around this problem here. */
21553 if (cu
->language
== language_cplus
21554 && strcmp (TYPE_NAME (parent_type
), "::") == 0)
21556 /* We give a name to even anonymous namespaces. */
21557 return TYPE_NAME (parent_type
);
21558 case DW_TAG_class_type
:
21559 case DW_TAG_interface_type
:
21560 case DW_TAG_structure_type
:
21561 case DW_TAG_union_type
:
21562 case DW_TAG_module
:
21563 parent_type
= read_type_die (parent
, cu
);
21564 if (TYPE_NAME (parent_type
) != NULL
)
21565 return TYPE_NAME (parent_type
);
21567 /* An anonymous structure is only allowed non-static data
21568 members; no typedefs, no member functions, et cetera.
21569 So it does not need a prefix. */
21571 case DW_TAG_compile_unit
:
21572 case DW_TAG_partial_unit
:
21573 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
21574 if (cu
->language
== language_cplus
21575 && !dwarf2_per_objfile
->types
.empty ()
21576 && die
->child
!= NULL
21577 && (die
->tag
== DW_TAG_class_type
21578 || die
->tag
== DW_TAG_structure_type
21579 || die
->tag
== DW_TAG_union_type
))
21581 const char *name
= guess_full_die_structure_name (die
, cu
);
21586 case DW_TAG_subprogram
:
21587 /* Nested subroutines in Fortran get a prefix with the name
21588 of the parent's subroutine. */
21589 if (cu
->language
== language_fortran
)
21591 if ((die
->tag
== DW_TAG_subprogram
)
21592 && (dwarf2_name (parent
, cu
) != NULL
))
21593 return dwarf2_name (parent
, cu
);
21595 return determine_prefix (parent
, cu
);
21596 case DW_TAG_enumeration_type
:
21597 parent_type
= read_type_die (parent
, cu
);
21598 if (TYPE_DECLARED_CLASS (parent_type
))
21600 if (TYPE_NAME (parent_type
) != NULL
)
21601 return TYPE_NAME (parent_type
);
21604 /* Fall through. */
21606 return determine_prefix (parent
, cu
);
21610 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
21611 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
21612 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
21613 an obconcat, otherwise allocate storage for the result. The CU argument is
21614 used to determine the language and hence, the appropriate separator. */
21616 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
21619 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
21620 int physname
, struct dwarf2_cu
*cu
)
21622 const char *lead
= "";
21625 if (suffix
== NULL
|| suffix
[0] == '\0'
21626 || prefix
== NULL
|| prefix
[0] == '\0')
21628 else if (cu
->language
== language_d
)
21630 /* For D, the 'main' function could be defined in any module, but it
21631 should never be prefixed. */
21632 if (strcmp (suffix
, "D main") == 0)
21640 else if (cu
->language
== language_fortran
&& physname
)
21642 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
21643 DW_AT_MIPS_linkage_name is preferred and used instead. */
21651 if (prefix
== NULL
)
21653 if (suffix
== NULL
)
21660 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
21662 strcpy (retval
, lead
);
21663 strcat (retval
, prefix
);
21664 strcat (retval
, sep
);
21665 strcat (retval
, suffix
);
21670 /* We have an obstack. */
21671 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
21675 /* Return sibling of die, NULL if no sibling. */
21677 static struct die_info
*
21678 sibling_die (struct die_info
*die
)
21680 return die
->sibling
;
21683 /* Get name of a die, return NULL if not found. */
21685 static const char *
21686 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
21687 struct obstack
*obstack
)
21689 if (name
&& cu
->language
== language_cplus
)
21691 std::string canon_name
= cp_canonicalize_string (name
);
21693 if (!canon_name
.empty ())
21695 if (canon_name
!= name
)
21696 name
= obstack_strdup (obstack
, canon_name
);
21703 /* Get name of a die, return NULL if not found.
21704 Anonymous namespaces are converted to their magic string. */
21706 static const char *
21707 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21709 struct attribute
*attr
;
21710 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21712 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
21713 if ((!attr
|| !DW_STRING (attr
))
21714 && die
->tag
!= DW_TAG_namespace
21715 && die
->tag
!= DW_TAG_class_type
21716 && die
->tag
!= DW_TAG_interface_type
21717 && die
->tag
!= DW_TAG_structure_type
21718 && die
->tag
!= DW_TAG_union_type
)
21723 case DW_TAG_compile_unit
:
21724 case DW_TAG_partial_unit
:
21725 /* Compilation units have a DW_AT_name that is a filename, not
21726 a source language identifier. */
21727 case DW_TAG_enumeration_type
:
21728 case DW_TAG_enumerator
:
21729 /* These tags always have simple identifiers already; no need
21730 to canonicalize them. */
21731 return DW_STRING (attr
);
21733 case DW_TAG_namespace
:
21734 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
21735 return DW_STRING (attr
);
21736 return CP_ANONYMOUS_NAMESPACE_STR
;
21738 case DW_TAG_class_type
:
21739 case DW_TAG_interface_type
:
21740 case DW_TAG_structure_type
:
21741 case DW_TAG_union_type
:
21742 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
21743 structures or unions. These were of the form "._%d" in GCC 4.1,
21744 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
21745 and GCC 4.4. We work around this problem by ignoring these. */
21746 if (attr
&& DW_STRING (attr
)
21747 && (startswith (DW_STRING (attr
), "._")
21748 || startswith (DW_STRING (attr
), "<anonymous")))
21751 /* GCC might emit a nameless typedef that has a linkage name. See
21752 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21753 if (!attr
|| DW_STRING (attr
) == NULL
)
21755 attr
= dw2_linkage_name_attr (die
, cu
);
21756 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21759 /* Avoid demangling DW_STRING (attr) the second time on a second
21760 call for the same DIE. */
21761 if (!DW_STRING_IS_CANONICAL (attr
))
21763 gdb::unique_xmalloc_ptr
<char> demangled
21764 (gdb_demangle (DW_STRING (attr
), DMGL_TYPES
));
21768 /* FIXME: we already did this for the partial symbol... */
21770 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
21772 DW_STRING_IS_CANONICAL (attr
) = 1;
21774 /* Strip any leading namespaces/classes, keep only the base name.
21775 DW_AT_name for named DIEs does not contain the prefixes. */
21776 base
= strrchr (DW_STRING (attr
), ':');
21777 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
21780 return DW_STRING (attr
);
21789 if (!DW_STRING_IS_CANONICAL (attr
))
21792 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
21793 &objfile
->per_bfd
->storage_obstack
);
21794 DW_STRING_IS_CANONICAL (attr
) = 1;
21796 return DW_STRING (attr
);
21799 /* Return the die that this die in an extension of, or NULL if there
21800 is none. *EXT_CU is the CU containing DIE on input, and the CU
21801 containing the return value on output. */
21803 static struct die_info
*
21804 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
21806 struct attribute
*attr
;
21808 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
21812 return follow_die_ref (die
, attr
, ext_cu
);
21815 /* A convenience function that returns an "unknown" DWARF name,
21816 including the value of V. STR is the name of the entity being
21817 printed, e.g., "TAG". */
21819 static const char *
21820 dwarf_unknown (const char *str
, unsigned v
)
21822 char *cell
= get_print_cell ();
21823 xsnprintf (cell
, PRINT_CELL_SIZE
, "DW_%s_<unknown: %u>", str
, v
);
21827 /* Convert a DIE tag into its string name. */
21829 static const char *
21830 dwarf_tag_name (unsigned tag
)
21832 const char *name
= get_DW_TAG_name (tag
);
21835 return dwarf_unknown ("TAG", tag
);
21840 /* Convert a DWARF attribute code into its string name. */
21842 static const char *
21843 dwarf_attr_name (unsigned attr
)
21847 #ifdef MIPS /* collides with DW_AT_HP_block_index */
21848 if (attr
== DW_AT_MIPS_fde
)
21849 return "DW_AT_MIPS_fde";
21851 if (attr
== DW_AT_HP_block_index
)
21852 return "DW_AT_HP_block_index";
21855 name
= get_DW_AT_name (attr
);
21858 return dwarf_unknown ("AT", attr
);
21863 /* Convert a DWARF value form code into its string name. */
21865 static const char *
21866 dwarf_form_name (unsigned form
)
21868 const char *name
= get_DW_FORM_name (form
);
21871 return dwarf_unknown ("FORM", form
);
21876 static const char *
21877 dwarf_bool_name (unsigned mybool
)
21885 /* Convert a DWARF type code into its string name. */
21887 static const char *
21888 dwarf_type_encoding_name (unsigned enc
)
21890 const char *name
= get_DW_ATE_name (enc
);
21893 return dwarf_unknown ("ATE", enc
);
21899 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
21903 print_spaces (indent
, f
);
21904 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
21905 dwarf_tag_name (die
->tag
), die
->abbrev
,
21906 sect_offset_str (die
->sect_off
));
21908 if (die
->parent
!= NULL
)
21910 print_spaces (indent
, f
);
21911 fprintf_unfiltered (f
, " parent at offset: %s\n",
21912 sect_offset_str (die
->parent
->sect_off
));
21915 print_spaces (indent
, f
);
21916 fprintf_unfiltered (f
, " has children: %s\n",
21917 dwarf_bool_name (die
->child
!= NULL
));
21919 print_spaces (indent
, f
);
21920 fprintf_unfiltered (f
, " attributes:\n");
21922 for (i
= 0; i
< die
->num_attrs
; ++i
)
21924 print_spaces (indent
, f
);
21925 fprintf_unfiltered (f
, " %s (%s) ",
21926 dwarf_attr_name (die
->attrs
[i
].name
),
21927 dwarf_form_name (die
->attrs
[i
].form
));
21929 switch (die
->attrs
[i
].form
)
21932 case DW_FORM_addrx
:
21933 case DW_FORM_GNU_addr_index
:
21934 fprintf_unfiltered (f
, "address: ");
21935 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
21937 case DW_FORM_block2
:
21938 case DW_FORM_block4
:
21939 case DW_FORM_block
:
21940 case DW_FORM_block1
:
21941 fprintf_unfiltered (f
, "block: size %s",
21942 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
21944 case DW_FORM_exprloc
:
21945 fprintf_unfiltered (f
, "expression: size %s",
21946 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
21948 case DW_FORM_data16
:
21949 fprintf_unfiltered (f
, "constant of 16 bytes");
21951 case DW_FORM_ref_addr
:
21952 fprintf_unfiltered (f
, "ref address: ");
21953 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
21955 case DW_FORM_GNU_ref_alt
:
21956 fprintf_unfiltered (f
, "alt ref address: ");
21957 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
21963 case DW_FORM_ref_udata
:
21964 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
21965 (long) (DW_UNSND (&die
->attrs
[i
])));
21967 case DW_FORM_data1
:
21968 case DW_FORM_data2
:
21969 case DW_FORM_data4
:
21970 case DW_FORM_data8
:
21971 case DW_FORM_udata
:
21972 case DW_FORM_sdata
:
21973 fprintf_unfiltered (f
, "constant: %s",
21974 pulongest (DW_UNSND (&die
->attrs
[i
])));
21976 case DW_FORM_sec_offset
:
21977 fprintf_unfiltered (f
, "section offset: %s",
21978 pulongest (DW_UNSND (&die
->attrs
[i
])));
21980 case DW_FORM_ref_sig8
:
21981 fprintf_unfiltered (f
, "signature: %s",
21982 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
21984 case DW_FORM_string
:
21986 case DW_FORM_line_strp
:
21988 case DW_FORM_GNU_str_index
:
21989 case DW_FORM_GNU_strp_alt
:
21990 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
21991 DW_STRING (&die
->attrs
[i
])
21992 ? DW_STRING (&die
->attrs
[i
]) : "",
21993 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
21996 if (DW_UNSND (&die
->attrs
[i
]))
21997 fprintf_unfiltered (f
, "flag: TRUE");
21999 fprintf_unfiltered (f
, "flag: FALSE");
22001 case DW_FORM_flag_present
:
22002 fprintf_unfiltered (f
, "flag: TRUE");
22004 case DW_FORM_indirect
:
22005 /* The reader will have reduced the indirect form to
22006 the "base form" so this form should not occur. */
22007 fprintf_unfiltered (f
,
22008 "unexpected attribute form: DW_FORM_indirect");
22010 case DW_FORM_implicit_const
:
22011 fprintf_unfiltered (f
, "constant: %s",
22012 plongest (DW_SND (&die
->attrs
[i
])));
22015 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
22016 die
->attrs
[i
].form
);
22019 fprintf_unfiltered (f
, "\n");
22024 dump_die_for_error (struct die_info
*die
)
22026 dump_die_shallow (gdb_stderr
, 0, die
);
22030 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
22032 int indent
= level
* 4;
22034 gdb_assert (die
!= NULL
);
22036 if (level
>= max_level
)
22039 dump_die_shallow (f
, indent
, die
);
22041 if (die
->child
!= NULL
)
22043 print_spaces (indent
, f
);
22044 fprintf_unfiltered (f
, " Children:");
22045 if (level
+ 1 < max_level
)
22047 fprintf_unfiltered (f
, "\n");
22048 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
22052 fprintf_unfiltered (f
,
22053 " [not printed, max nesting level reached]\n");
22057 if (die
->sibling
!= NULL
&& level
> 0)
22059 dump_die_1 (f
, level
, max_level
, die
->sibling
);
22063 /* This is called from the pdie macro in gdbinit.in.
22064 It's not static so gcc will keep a copy callable from gdb. */
22067 dump_die (struct die_info
*die
, int max_level
)
22069 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
22073 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
22077 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
22078 to_underlying (die
->sect_off
),
22084 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
22088 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
22090 if (attr
->form_is_ref ())
22091 return (sect_offset
) DW_UNSND (attr
);
22093 complaint (_("unsupported die ref attribute form: '%s'"),
22094 dwarf_form_name (attr
->form
));
22098 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
22099 * the value held by the attribute is not constant. */
22102 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
22104 if (attr
->form
== DW_FORM_sdata
|| attr
->form
== DW_FORM_implicit_const
)
22105 return DW_SND (attr
);
22106 else if (attr
->form
== DW_FORM_udata
22107 || attr
->form
== DW_FORM_data1
22108 || attr
->form
== DW_FORM_data2
22109 || attr
->form
== DW_FORM_data4
22110 || attr
->form
== DW_FORM_data8
)
22111 return DW_UNSND (attr
);
22114 /* For DW_FORM_data16 see attribute::form_is_constant. */
22115 complaint (_("Attribute value is not a constant (%s)"),
22116 dwarf_form_name (attr
->form
));
22117 return default_value
;
22121 /* Follow reference or signature attribute ATTR of SRC_DIE.
22122 On entry *REF_CU is the CU of SRC_DIE.
22123 On exit *REF_CU is the CU of the result. */
22125 static struct die_info
*
22126 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22127 struct dwarf2_cu
**ref_cu
)
22129 struct die_info
*die
;
22131 if (attr
->form_is_ref ())
22132 die
= follow_die_ref (src_die
, attr
, ref_cu
);
22133 else if (attr
->form
== DW_FORM_ref_sig8
)
22134 die
= follow_die_sig (src_die
, attr
, ref_cu
);
22137 dump_die_for_error (src_die
);
22138 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
22139 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22145 /* Follow reference OFFSET.
22146 On entry *REF_CU is the CU of the source die referencing OFFSET.
22147 On exit *REF_CU is the CU of the result.
22148 Returns NULL if OFFSET is invalid. */
22150 static struct die_info
*
22151 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
22152 struct dwarf2_cu
**ref_cu
)
22154 struct die_info temp_die
;
22155 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
22156 struct dwarf2_per_objfile
*dwarf2_per_objfile
22157 = cu
->per_cu
->dwarf2_per_objfile
;
22159 gdb_assert (cu
->per_cu
!= NULL
);
22163 if (cu
->per_cu
->is_debug_types
)
22165 /* .debug_types CUs cannot reference anything outside their CU.
22166 If they need to, they have to reference a signatured type via
22167 DW_FORM_ref_sig8. */
22168 if (!cu
->header
.offset_in_cu_p (sect_off
))
22171 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
22172 || !cu
->header
.offset_in_cu_p (sect_off
))
22174 struct dwarf2_per_cu_data
*per_cu
;
22176 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
22177 dwarf2_per_objfile
);
22179 /* If necessary, add it to the queue and load its DIEs. */
22180 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
22181 load_full_comp_unit (per_cu
, false, cu
->language
);
22183 target_cu
= per_cu
->cu
;
22185 else if (cu
->dies
== NULL
)
22187 /* We're loading full DIEs during partial symbol reading. */
22188 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
22189 load_full_comp_unit (cu
->per_cu
, false, language_minimal
);
22192 *ref_cu
= target_cu
;
22193 temp_die
.sect_off
= sect_off
;
22195 if (target_cu
!= cu
)
22196 target_cu
->ancestor
= cu
;
22198 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
22200 to_underlying (sect_off
));
22203 /* Follow reference attribute ATTR of SRC_DIE.
22204 On entry *REF_CU is the CU of SRC_DIE.
22205 On exit *REF_CU is the CU of the result. */
22207 static struct die_info
*
22208 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
22209 struct dwarf2_cu
**ref_cu
)
22211 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22212 struct dwarf2_cu
*cu
= *ref_cu
;
22213 struct die_info
*die
;
22215 die
= follow_die_offset (sect_off
,
22216 (attr
->form
== DW_FORM_GNU_ref_alt
22217 || cu
->per_cu
->is_dwz
),
22220 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
22221 "at %s [in module %s]"),
22222 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
22223 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
22228 /* Return DWARF block referenced by DW_AT_location of DIE at SECT_OFF at PER_CU.
22229 Returned value is intended for DW_OP_call*. Returned
22230 dwarf2_locexpr_baton->data has lifetime of
22231 PER_CU->DWARF2_PER_OBJFILE->OBJFILE. */
22233 struct dwarf2_locexpr_baton
22234 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
22235 struct dwarf2_per_cu_data
*per_cu
,
22236 CORE_ADDR (*get_frame_pc
) (void *baton
),
22237 void *baton
, bool resolve_abstract_p
)
22239 struct dwarf2_cu
*cu
;
22240 struct die_info
*die
;
22241 struct attribute
*attr
;
22242 struct dwarf2_locexpr_baton retval
;
22243 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
22244 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22246 if (per_cu
->cu
== NULL
)
22247 load_cu (per_cu
, false);
22251 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22252 Instead just throw an error, not much else we can do. */
22253 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22254 sect_offset_str (sect_off
), objfile_name (objfile
));
22257 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22259 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22260 sect_offset_str (sect_off
), objfile_name (objfile
));
22262 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22263 if (!attr
&& resolve_abstract_p
22264 && (dwarf2_per_objfile
->abstract_to_concrete
.find (die
->sect_off
)
22265 != dwarf2_per_objfile
->abstract_to_concrete
.end ()))
22267 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22268 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
22269 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
22271 for (const auto &cand_off
22272 : dwarf2_per_objfile
->abstract_to_concrete
[die
->sect_off
])
22274 struct dwarf2_cu
*cand_cu
= cu
;
22275 struct die_info
*cand
22276 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
22279 || cand
->parent
->tag
!= DW_TAG_subprogram
)
22282 CORE_ADDR pc_low
, pc_high
;
22283 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
22284 if (pc_low
== ((CORE_ADDR
) -1))
22286 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
22287 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
22288 if (!(pc_low
<= pc
&& pc
< pc_high
))
22292 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22299 /* DWARF: "If there is no such attribute, then there is no effect.".
22300 DATA is ignored if SIZE is 0. */
22302 retval
.data
= NULL
;
22305 else if (attr
->form_is_section_offset ())
22307 struct dwarf2_loclist_baton loclist_baton
;
22308 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
22311 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
22313 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
22315 retval
.size
= size
;
22319 if (!attr
->form_is_block ())
22320 error (_("Dwarf Error: DIE at %s referenced in module %s "
22321 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
22322 sect_offset_str (sect_off
), objfile_name (objfile
));
22324 retval
.data
= DW_BLOCK (attr
)->data
;
22325 retval
.size
= DW_BLOCK (attr
)->size
;
22327 retval
.per_cu
= cu
->per_cu
;
22329 age_cached_comp_units (dwarf2_per_objfile
);
22334 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
22337 struct dwarf2_locexpr_baton
22338 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
22339 struct dwarf2_per_cu_data
*per_cu
,
22340 CORE_ADDR (*get_frame_pc
) (void *baton
),
22343 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
22345 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
22348 /* Write a constant of a given type as target-ordered bytes into
22351 static const gdb_byte
*
22352 write_constant_as_bytes (struct obstack
*obstack
,
22353 enum bfd_endian byte_order
,
22360 *len
= TYPE_LENGTH (type
);
22361 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22362 store_unsigned_integer (result
, *len
, byte_order
, value
);
22367 /* If the DIE at OFFSET in PER_CU has a DW_AT_const_value, return a
22368 pointer to the constant bytes and set LEN to the length of the
22369 data. If memory is needed, allocate it on OBSTACK. If the DIE
22370 does not have a DW_AT_const_value, return NULL. */
22373 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
22374 struct dwarf2_per_cu_data
*per_cu
,
22375 struct obstack
*obstack
,
22378 struct dwarf2_cu
*cu
;
22379 struct die_info
*die
;
22380 struct attribute
*attr
;
22381 const gdb_byte
*result
= NULL
;
22384 enum bfd_endian byte_order
;
22385 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
22387 if (per_cu
->cu
== NULL
)
22388 load_cu (per_cu
, false);
22392 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22393 Instead just throw an error, not much else we can do. */
22394 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22395 sect_offset_str (sect_off
), objfile_name (objfile
));
22398 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22400 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22401 sect_offset_str (sect_off
), objfile_name (objfile
));
22403 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22407 byte_order
= (bfd_big_endian (objfile
->obfd
)
22408 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22410 switch (attr
->form
)
22413 case DW_FORM_addrx
:
22414 case DW_FORM_GNU_addr_index
:
22418 *len
= cu
->header
.addr_size
;
22419 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22420 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
22424 case DW_FORM_string
:
22427 case DW_FORM_GNU_str_index
:
22428 case DW_FORM_GNU_strp_alt
:
22429 /* DW_STRING is already allocated on the objfile obstack, point
22431 result
= (const gdb_byte
*) DW_STRING (attr
);
22432 *len
= strlen (DW_STRING (attr
));
22434 case DW_FORM_block1
:
22435 case DW_FORM_block2
:
22436 case DW_FORM_block4
:
22437 case DW_FORM_block
:
22438 case DW_FORM_exprloc
:
22439 case DW_FORM_data16
:
22440 result
= DW_BLOCK (attr
)->data
;
22441 *len
= DW_BLOCK (attr
)->size
;
22444 /* The DW_AT_const_value attributes are supposed to carry the
22445 symbol's value "represented as it would be on the target
22446 architecture." By the time we get here, it's already been
22447 converted to host endianness, so we just need to sign- or
22448 zero-extend it as appropriate. */
22449 case DW_FORM_data1
:
22450 type
= die_type (die
, cu
);
22451 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
22452 if (result
== NULL
)
22453 result
= write_constant_as_bytes (obstack
, byte_order
,
22456 case DW_FORM_data2
:
22457 type
= die_type (die
, cu
);
22458 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
22459 if (result
== NULL
)
22460 result
= write_constant_as_bytes (obstack
, byte_order
,
22463 case DW_FORM_data4
:
22464 type
= die_type (die
, cu
);
22465 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
22466 if (result
== NULL
)
22467 result
= write_constant_as_bytes (obstack
, byte_order
,
22470 case DW_FORM_data8
:
22471 type
= die_type (die
, cu
);
22472 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
22473 if (result
== NULL
)
22474 result
= write_constant_as_bytes (obstack
, byte_order
,
22478 case DW_FORM_sdata
:
22479 case DW_FORM_implicit_const
:
22480 type
= die_type (die
, cu
);
22481 result
= write_constant_as_bytes (obstack
, byte_order
,
22482 type
, DW_SND (attr
), len
);
22485 case DW_FORM_udata
:
22486 type
= die_type (die
, cu
);
22487 result
= write_constant_as_bytes (obstack
, byte_order
,
22488 type
, DW_UNSND (attr
), len
);
22492 complaint (_("unsupported const value attribute form: '%s'"),
22493 dwarf_form_name (attr
->form
));
22500 /* Return the type of the die at OFFSET in PER_CU. Return NULL if no
22501 valid type for this die is found. */
22504 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
22505 struct dwarf2_per_cu_data
*per_cu
)
22507 struct dwarf2_cu
*cu
;
22508 struct die_info
*die
;
22510 if (per_cu
->cu
== NULL
)
22511 load_cu (per_cu
, false);
22516 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22520 return die_type (die
, cu
);
22523 /* Return the type of the DIE at DIE_OFFSET in the CU named by
22527 dwarf2_get_die_type (cu_offset die_offset
,
22528 struct dwarf2_per_cu_data
*per_cu
)
22530 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
22531 return get_die_type_at_offset (die_offset_sect
, per_cu
);
22534 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
22535 On entry *REF_CU is the CU of SRC_DIE.
22536 On exit *REF_CU is the CU of the result.
22537 Returns NULL if the referenced DIE isn't found. */
22539 static struct die_info
*
22540 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
22541 struct dwarf2_cu
**ref_cu
)
22543 struct die_info temp_die
;
22544 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
22545 struct die_info
*die
;
22547 /* While it might be nice to assert sig_type->type == NULL here,
22548 we can get here for DW_AT_imported_declaration where we need
22549 the DIE not the type. */
22551 /* If necessary, add it to the queue and load its DIEs. */
22553 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
22554 read_signatured_type (sig_type
);
22556 sig_cu
= sig_type
->per_cu
.cu
;
22557 gdb_assert (sig_cu
!= NULL
);
22558 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
22559 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
22560 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
22561 to_underlying (temp_die
.sect_off
));
22564 struct dwarf2_per_objfile
*dwarf2_per_objfile
22565 = (*ref_cu
)->per_cu
->dwarf2_per_objfile
;
22567 /* For .gdb_index version 7 keep track of included TUs.
22568 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
22569 if (dwarf2_per_objfile
->index_table
!= NULL
22570 && dwarf2_per_objfile
->index_table
->version
<= 7)
22572 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
22577 sig_cu
->ancestor
= cu
;
22585 /* Follow signatured type referenced by ATTR in SRC_DIE.
22586 On entry *REF_CU is the CU of SRC_DIE.
22587 On exit *REF_CU is the CU of the result.
22588 The result is the DIE of the type.
22589 If the referenced type cannot be found an error is thrown. */
22591 static struct die_info
*
22592 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22593 struct dwarf2_cu
**ref_cu
)
22595 ULONGEST signature
= DW_SIGNATURE (attr
);
22596 struct signatured_type
*sig_type
;
22597 struct die_info
*die
;
22599 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
22601 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
22602 /* sig_type will be NULL if the signatured type is missing from
22604 if (sig_type
== NULL
)
22606 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22607 " from DIE at %s [in module %s]"),
22608 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22609 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22612 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
22615 dump_die_for_error (src_die
);
22616 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22617 " from DIE at %s [in module %s]"),
22618 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22619 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22625 /* Get the type specified by SIGNATURE referenced in DIE/CU,
22626 reading in and processing the type unit if necessary. */
22628 static struct type
*
22629 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
22630 struct dwarf2_cu
*cu
)
22632 struct dwarf2_per_objfile
*dwarf2_per_objfile
22633 = cu
->per_cu
->dwarf2_per_objfile
;
22634 struct signatured_type
*sig_type
;
22635 struct dwarf2_cu
*type_cu
;
22636 struct die_info
*type_die
;
22639 sig_type
= lookup_signatured_type (cu
, signature
);
22640 /* sig_type will be NULL if the signatured type is missing from
22642 if (sig_type
== NULL
)
22644 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22645 " from DIE at %s [in module %s]"),
22646 hex_string (signature
), sect_offset_str (die
->sect_off
),
22647 objfile_name (dwarf2_per_objfile
->objfile
));
22648 return build_error_marker_type (cu
, die
);
22651 /* If we already know the type we're done. */
22652 if (sig_type
->type
!= NULL
)
22653 return sig_type
->type
;
22656 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
22657 if (type_die
!= NULL
)
22659 /* N.B. We need to call get_die_type to ensure only one type for this DIE
22660 is created. This is important, for example, because for c++ classes
22661 we need TYPE_NAME set which is only done by new_symbol. Blech. */
22662 type
= read_type_die (type_die
, type_cu
);
22665 complaint (_("Dwarf Error: Cannot build signatured type %s"
22666 " referenced from DIE at %s [in module %s]"),
22667 hex_string (signature
), sect_offset_str (die
->sect_off
),
22668 objfile_name (dwarf2_per_objfile
->objfile
));
22669 type
= build_error_marker_type (cu
, die
);
22674 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22675 " from DIE at %s [in module %s]"),
22676 hex_string (signature
), sect_offset_str (die
->sect_off
),
22677 objfile_name (dwarf2_per_objfile
->objfile
));
22678 type
= build_error_marker_type (cu
, die
);
22680 sig_type
->type
= type
;
22685 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
22686 reading in and processing the type unit if necessary. */
22688 static struct type
*
22689 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
22690 struct dwarf2_cu
*cu
) /* ARI: editCase function */
22692 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
22693 if (attr
->form_is_ref ())
22695 struct dwarf2_cu
*type_cu
= cu
;
22696 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
22698 return read_type_die (type_die
, type_cu
);
22700 else if (attr
->form
== DW_FORM_ref_sig8
)
22702 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
22706 struct dwarf2_per_objfile
*dwarf2_per_objfile
22707 = cu
->per_cu
->dwarf2_per_objfile
;
22709 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
22710 " at %s [in module %s]"),
22711 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
22712 objfile_name (dwarf2_per_objfile
->objfile
));
22713 return build_error_marker_type (cu
, die
);
22717 /* Load the DIEs associated with type unit PER_CU into memory. */
22720 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
22722 struct signatured_type
*sig_type
;
22724 /* Caller is responsible for ensuring type_unit_groups don't get here. */
22725 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
22727 /* We have the per_cu, but we need the signatured_type.
22728 Fortunately this is an easy translation. */
22729 gdb_assert (per_cu
->is_debug_types
);
22730 sig_type
= (struct signatured_type
*) per_cu
;
22732 gdb_assert (per_cu
->cu
== NULL
);
22734 read_signatured_type (sig_type
);
22736 gdb_assert (per_cu
->cu
!= NULL
);
22739 /* Read in a signatured type and build its CU and DIEs.
22740 If the type is a stub for the real type in a DWO file,
22741 read in the real type from the DWO file as well. */
22744 read_signatured_type (struct signatured_type
*sig_type
)
22746 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
22748 gdb_assert (per_cu
->is_debug_types
);
22749 gdb_assert (per_cu
->cu
== NULL
);
22751 cutu_reader
reader (per_cu
, NULL
, 0, 1, false);
22753 if (!reader
.dummy_p
)
22755 struct dwarf2_cu
*cu
= reader
.cu
;
22756 const gdb_byte
*info_ptr
= reader
.info_ptr
;
22758 gdb_assert (cu
->die_hash
== NULL
);
22760 htab_create_alloc_ex (cu
->header
.length
/ 12,
22764 &cu
->comp_unit_obstack
,
22765 hashtab_obstack_allocate
,
22766 dummy_obstack_deallocate
);
22768 if (reader
.comp_unit_die
->has_children
)
22769 reader
.comp_unit_die
->child
22770 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
22771 reader
.comp_unit_die
);
22772 cu
->dies
= reader
.comp_unit_die
;
22773 /* comp_unit_die is not stored in die_hash, no need. */
22775 /* We try not to read any attributes in this function, because
22776 not all CUs needed for references have been loaded yet, and
22777 symbol table processing isn't initialized. But we have to
22778 set the CU language, or we won't be able to build types
22779 correctly. Similarly, if we do not read the producer, we can
22780 not apply producer-specific interpretation. */
22781 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
22784 sig_type
->per_cu
.tu_read
= 1;
22787 /* Decode simple location descriptions.
22788 Given a pointer to a dwarf block that defines a location, compute
22789 the location and return the value.
22791 NOTE drow/2003-11-18: This function is called in two situations
22792 now: for the address of static or global variables (partial symbols
22793 only) and for offsets into structures which are expected to be
22794 (more or less) constant. The partial symbol case should go away,
22795 and only the constant case should remain. That will let this
22796 function complain more accurately. A few special modes are allowed
22797 without complaint for global variables (for instance, global
22798 register values and thread-local values).
22800 A location description containing no operations indicates that the
22801 object is optimized out. The return value is 0 for that case.
22802 FIXME drow/2003-11-16: No callers check for this case any more; soon all
22803 callers will only want a very basic result and this can become a
22806 Note that stack[0] is unused except as a default error return. */
22809 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
22811 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22813 size_t size
= blk
->size
;
22814 const gdb_byte
*data
= blk
->data
;
22815 CORE_ADDR stack
[64];
22817 unsigned int bytes_read
, unsnd
;
22823 stack
[++stacki
] = 0;
22862 stack
[++stacki
] = op
- DW_OP_lit0
;
22897 stack
[++stacki
] = op
- DW_OP_reg0
;
22899 dwarf2_complex_location_expr_complaint ();
22903 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
22905 stack
[++stacki
] = unsnd
;
22907 dwarf2_complex_location_expr_complaint ();
22911 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
22916 case DW_OP_const1u
:
22917 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
22921 case DW_OP_const1s
:
22922 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
22926 case DW_OP_const2u
:
22927 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
22931 case DW_OP_const2s
:
22932 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
22936 case DW_OP_const4u
:
22937 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
22941 case DW_OP_const4s
:
22942 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
22946 case DW_OP_const8u
:
22947 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
22952 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
22958 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
22963 stack
[stacki
+ 1] = stack
[stacki
];
22968 stack
[stacki
- 1] += stack
[stacki
];
22972 case DW_OP_plus_uconst
:
22973 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
22979 stack
[stacki
- 1] -= stack
[stacki
];
22984 /* If we're not the last op, then we definitely can't encode
22985 this using GDB's address_class enum. This is valid for partial
22986 global symbols, although the variable's address will be bogus
22989 dwarf2_complex_location_expr_complaint ();
22992 case DW_OP_GNU_push_tls_address
:
22993 case DW_OP_form_tls_address
:
22994 /* The top of the stack has the offset from the beginning
22995 of the thread control block at which the variable is located. */
22996 /* Nothing should follow this operator, so the top of stack would
22998 /* This is valid for partial global symbols, but the variable's
22999 address will be bogus in the psymtab. Make it always at least
23000 non-zero to not look as a variable garbage collected by linker
23001 which have DW_OP_addr 0. */
23003 dwarf2_complex_location_expr_complaint ();
23007 case DW_OP_GNU_uninit
:
23011 case DW_OP_GNU_addr_index
:
23012 case DW_OP_GNU_const_index
:
23013 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
23020 const char *name
= get_DW_OP_name (op
);
23023 complaint (_("unsupported stack op: '%s'"),
23026 complaint (_("unsupported stack op: '%02x'"),
23030 return (stack
[stacki
]);
23033 /* Enforce maximum stack depth of SIZE-1 to avoid writing
23034 outside of the allocated space. Also enforce minimum>0. */
23035 if (stacki
>= ARRAY_SIZE (stack
) - 1)
23037 complaint (_("location description stack overflow"));
23043 complaint (_("location description stack underflow"));
23047 return (stack
[stacki
]);
23050 /* memory allocation interface */
23052 static struct dwarf_block
*
23053 dwarf_alloc_block (struct dwarf2_cu
*cu
)
23055 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
23058 static struct die_info
*
23059 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
23061 struct die_info
*die
;
23062 size_t size
= sizeof (struct die_info
);
23065 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
23067 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
23068 memset (die
, 0, sizeof (struct die_info
));
23073 /* Macro support. */
23075 static struct macro_source_file
*
23076 macro_start_file (struct dwarf2_cu
*cu
,
23077 int file
, int line
,
23078 struct macro_source_file
*current_file
,
23079 struct line_header
*lh
)
23081 /* File name relative to the compilation directory of this source file. */
23082 gdb::unique_xmalloc_ptr
<char> file_name
= lh
->file_file_name (file
);
23084 if (! current_file
)
23086 /* Note: We don't create a macro table for this compilation unit
23087 at all until we actually get a filename. */
23088 struct macro_table
*macro_table
= cu
->get_builder ()->get_macro_table ();
23090 /* If we have no current file, then this must be the start_file
23091 directive for the compilation unit's main source file. */
23092 current_file
= macro_set_main (macro_table
, file_name
.get ());
23093 macro_define_special (macro_table
);
23096 current_file
= macro_include (current_file
, line
, file_name
.get ());
23098 return current_file
;
23101 static const char *
23102 consume_improper_spaces (const char *p
, const char *body
)
23106 complaint (_("macro definition contains spaces "
23107 "in formal argument list:\n`%s'"),
23119 parse_macro_definition (struct macro_source_file
*file
, int line
,
23124 /* The body string takes one of two forms. For object-like macro
23125 definitions, it should be:
23127 <macro name> " " <definition>
23129 For function-like macro definitions, it should be:
23131 <macro name> "() " <definition>
23133 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
23135 Spaces may appear only where explicitly indicated, and in the
23138 The Dwarf 2 spec says that an object-like macro's name is always
23139 followed by a space, but versions of GCC around March 2002 omit
23140 the space when the macro's definition is the empty string.
23142 The Dwarf 2 spec says that there should be no spaces between the
23143 formal arguments in a function-like macro's formal argument list,
23144 but versions of GCC around March 2002 include spaces after the
23148 /* Find the extent of the macro name. The macro name is terminated
23149 by either a space or null character (for an object-like macro) or
23150 an opening paren (for a function-like macro). */
23151 for (p
= body
; *p
; p
++)
23152 if (*p
== ' ' || *p
== '(')
23155 if (*p
== ' ' || *p
== '\0')
23157 /* It's an object-like macro. */
23158 int name_len
= p
- body
;
23159 std::string
name (body
, name_len
);
23160 const char *replacement
;
23163 replacement
= body
+ name_len
+ 1;
23166 dwarf2_macro_malformed_definition_complaint (body
);
23167 replacement
= body
+ name_len
;
23170 macro_define_object (file
, line
, name
.c_str (), replacement
);
23172 else if (*p
== '(')
23174 /* It's a function-like macro. */
23175 std::string
name (body
, p
- body
);
23178 char **argv
= XNEWVEC (char *, argv_size
);
23182 p
= consume_improper_spaces (p
, body
);
23184 /* Parse the formal argument list. */
23185 while (*p
&& *p
!= ')')
23187 /* Find the extent of the current argument name. */
23188 const char *arg_start
= p
;
23190 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
23193 if (! *p
|| p
== arg_start
)
23194 dwarf2_macro_malformed_definition_complaint (body
);
23197 /* Make sure argv has room for the new argument. */
23198 if (argc
>= argv_size
)
23201 argv
= XRESIZEVEC (char *, argv
, argv_size
);
23204 argv
[argc
++] = savestring (arg_start
, p
- arg_start
);
23207 p
= consume_improper_spaces (p
, body
);
23209 /* Consume the comma, if present. */
23214 p
= consume_improper_spaces (p
, body
);
23223 /* Perfectly formed definition, no complaints. */
23224 macro_define_function (file
, line
, name
.c_str (),
23225 argc
, (const char **) argv
,
23227 else if (*p
== '\0')
23229 /* Complain, but do define it. */
23230 dwarf2_macro_malformed_definition_complaint (body
);
23231 macro_define_function (file
, line
, name
.c_str (),
23232 argc
, (const char **) argv
,
23236 /* Just complain. */
23237 dwarf2_macro_malformed_definition_complaint (body
);
23240 /* Just complain. */
23241 dwarf2_macro_malformed_definition_complaint (body
);
23246 for (i
= 0; i
< argc
; i
++)
23252 dwarf2_macro_malformed_definition_complaint (body
);
23255 /* Skip some bytes from BYTES according to the form given in FORM.
23256 Returns the new pointer. */
23258 static const gdb_byte
*
23259 skip_form_bytes (bfd
*abfd
, const gdb_byte
*bytes
, const gdb_byte
*buffer_end
,
23260 enum dwarf_form form
,
23261 unsigned int offset_size
,
23262 struct dwarf2_section_info
*section
)
23264 unsigned int bytes_read
;
23268 case DW_FORM_data1
:
23273 case DW_FORM_data2
:
23277 case DW_FORM_data4
:
23281 case DW_FORM_data8
:
23285 case DW_FORM_data16
:
23289 case DW_FORM_string
:
23290 read_direct_string (abfd
, bytes
, &bytes_read
);
23291 bytes
+= bytes_read
;
23294 case DW_FORM_sec_offset
:
23296 case DW_FORM_GNU_strp_alt
:
23297 bytes
+= offset_size
;
23300 case DW_FORM_block
:
23301 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
23302 bytes
+= bytes_read
;
23305 case DW_FORM_block1
:
23306 bytes
+= 1 + read_1_byte (abfd
, bytes
);
23308 case DW_FORM_block2
:
23309 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
23311 case DW_FORM_block4
:
23312 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
23315 case DW_FORM_addrx
:
23316 case DW_FORM_sdata
:
23318 case DW_FORM_udata
:
23319 case DW_FORM_GNU_addr_index
:
23320 case DW_FORM_GNU_str_index
:
23321 bytes
= gdb_skip_leb128 (bytes
, buffer_end
);
23324 dwarf2_section_buffer_overflow_complaint (section
);
23329 case DW_FORM_implicit_const
:
23334 complaint (_("invalid form 0x%x in `%s'"),
23335 form
, section
->get_name ());
23343 /* A helper for dwarf_decode_macros that handles skipping an unknown
23344 opcode. Returns an updated pointer to the macro data buffer; or,
23345 on error, issues a complaint and returns NULL. */
23347 static const gdb_byte
*
23348 skip_unknown_opcode (unsigned int opcode
,
23349 const gdb_byte
**opcode_definitions
,
23350 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
23352 unsigned int offset_size
,
23353 struct dwarf2_section_info
*section
)
23355 unsigned int bytes_read
, i
;
23357 const gdb_byte
*defn
;
23359 if (opcode_definitions
[opcode
] == NULL
)
23361 complaint (_("unrecognized DW_MACFINO opcode 0x%x"),
23366 defn
= opcode_definitions
[opcode
];
23367 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
23368 defn
+= bytes_read
;
23370 for (i
= 0; i
< arg
; ++i
)
23372 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
,
23373 (enum dwarf_form
) defn
[i
], offset_size
,
23375 if (mac_ptr
== NULL
)
23377 /* skip_form_bytes already issued the complaint. */
23385 /* A helper function which parses the header of a macro section.
23386 If the macro section is the extended (for now called "GNU") type,
23387 then this updates *OFFSET_SIZE. Returns a pointer to just after
23388 the header, or issues a complaint and returns NULL on error. */
23390 static const gdb_byte
*
23391 dwarf_parse_macro_header (const gdb_byte
**opcode_definitions
,
23393 const gdb_byte
*mac_ptr
,
23394 unsigned int *offset_size
,
23395 int section_is_gnu
)
23397 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
23399 if (section_is_gnu
)
23401 unsigned int version
, flags
;
23403 version
= read_2_bytes (abfd
, mac_ptr
);
23404 if (version
!= 4 && version
!= 5)
23406 complaint (_("unrecognized version `%d' in .debug_macro section"),
23412 flags
= read_1_byte (abfd
, mac_ptr
);
23414 *offset_size
= (flags
& 1) ? 8 : 4;
23416 if ((flags
& 2) != 0)
23417 /* We don't need the line table offset. */
23418 mac_ptr
+= *offset_size
;
23420 /* Vendor opcode descriptions. */
23421 if ((flags
& 4) != 0)
23423 unsigned int i
, count
;
23425 count
= read_1_byte (abfd
, mac_ptr
);
23427 for (i
= 0; i
< count
; ++i
)
23429 unsigned int opcode
, bytes_read
;
23432 opcode
= read_1_byte (abfd
, mac_ptr
);
23434 opcode_definitions
[opcode
] = mac_ptr
;
23435 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23436 mac_ptr
+= bytes_read
;
23445 /* A helper for dwarf_decode_macros that handles the GNU extensions,
23446 including DW_MACRO_import. */
23449 dwarf_decode_macro_bytes (struct dwarf2_cu
*cu
,
23451 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
23452 struct macro_source_file
*current_file
,
23453 struct line_header
*lh
,
23454 struct dwarf2_section_info
*section
,
23455 int section_is_gnu
, int section_is_dwz
,
23456 unsigned int offset_size
,
23457 htab_t include_hash
)
23459 struct dwarf2_per_objfile
*dwarf2_per_objfile
23460 = cu
->per_cu
->dwarf2_per_objfile
;
23461 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23462 enum dwarf_macro_record_type macinfo_type
;
23463 int at_commandline
;
23464 const gdb_byte
*opcode_definitions
[256];
23466 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
23467 &offset_size
, section_is_gnu
);
23468 if (mac_ptr
== NULL
)
23470 /* We already issued a complaint. */
23474 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
23475 GDB is still reading the definitions from command line. First
23476 DW_MACINFO_start_file will need to be ignored as it was already executed
23477 to create CURRENT_FILE for the main source holding also the command line
23478 definitions. On first met DW_MACINFO_start_file this flag is reset to
23479 normally execute all the remaining DW_MACINFO_start_file macinfos. */
23481 at_commandline
= 1;
23485 /* Do we at least have room for a macinfo type byte? */
23486 if (mac_ptr
>= mac_end
)
23488 dwarf2_section_buffer_overflow_complaint (section
);
23492 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
23495 /* Note that we rely on the fact that the corresponding GNU and
23496 DWARF constants are the same. */
23498 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
23499 switch (macinfo_type
)
23501 /* A zero macinfo type indicates the end of the macro
23506 case DW_MACRO_define
:
23507 case DW_MACRO_undef
:
23508 case DW_MACRO_define_strp
:
23509 case DW_MACRO_undef_strp
:
23510 case DW_MACRO_define_sup
:
23511 case DW_MACRO_undef_sup
:
23513 unsigned int bytes_read
;
23518 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23519 mac_ptr
+= bytes_read
;
23521 if (macinfo_type
== DW_MACRO_define
23522 || macinfo_type
== DW_MACRO_undef
)
23524 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
23525 mac_ptr
+= bytes_read
;
23529 LONGEST str_offset
;
23531 str_offset
= read_offset (abfd
, mac_ptr
, offset_size
);
23532 mac_ptr
+= offset_size
;
23534 if (macinfo_type
== DW_MACRO_define_sup
23535 || macinfo_type
== DW_MACRO_undef_sup
23538 struct dwz_file
*dwz
23539 = dwarf2_get_dwz_file (dwarf2_per_objfile
);
23541 body
= read_indirect_string_from_dwz (objfile
,
23545 body
= read_indirect_string_at_offset (dwarf2_per_objfile
,
23549 is_define
= (macinfo_type
== DW_MACRO_define
23550 || macinfo_type
== DW_MACRO_define_strp
23551 || macinfo_type
== DW_MACRO_define_sup
);
23552 if (! current_file
)
23554 /* DWARF violation as no main source is present. */
23555 complaint (_("debug info with no main source gives macro %s "
23557 is_define
? _("definition") : _("undefinition"),
23561 if ((line
== 0 && !at_commandline
)
23562 || (line
!= 0 && at_commandline
))
23563 complaint (_("debug info gives %s macro %s with %s line %d: %s"),
23564 at_commandline
? _("command-line") : _("in-file"),
23565 is_define
? _("definition") : _("undefinition"),
23566 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
23570 /* Fedora's rpm-build's "debugedit" binary
23571 corrupted .debug_macro sections.
23574 https://bugzilla.redhat.com/show_bug.cgi?id=1708786 */
23575 complaint (_("debug info gives %s invalid macro %s "
23576 "without body (corrupted?) at line %d "
23578 at_commandline
? _("command-line") : _("in-file"),
23579 is_define
? _("definition") : _("undefinition"),
23580 line
, current_file
->filename
);
23582 else if (is_define
)
23583 parse_macro_definition (current_file
, line
, body
);
23586 gdb_assert (macinfo_type
== DW_MACRO_undef
23587 || macinfo_type
== DW_MACRO_undef_strp
23588 || macinfo_type
== DW_MACRO_undef_sup
);
23589 macro_undef (current_file
, line
, body
);
23594 case DW_MACRO_start_file
:
23596 unsigned int bytes_read
;
23599 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23600 mac_ptr
+= bytes_read
;
23601 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23602 mac_ptr
+= bytes_read
;
23604 if ((line
== 0 && !at_commandline
)
23605 || (line
!= 0 && at_commandline
))
23606 complaint (_("debug info gives source %d included "
23607 "from %s at %s line %d"),
23608 file
, at_commandline
? _("command-line") : _("file"),
23609 line
== 0 ? _("zero") : _("non-zero"), line
);
23611 if (at_commandline
)
23613 /* This DW_MACRO_start_file was executed in the
23615 at_commandline
= 0;
23618 current_file
= macro_start_file (cu
, file
, line
, current_file
,
23623 case DW_MACRO_end_file
:
23624 if (! current_file
)
23625 complaint (_("macro debug info has an unmatched "
23626 "`close_file' directive"));
23629 current_file
= current_file
->included_by
;
23630 if (! current_file
)
23632 enum dwarf_macro_record_type next_type
;
23634 /* GCC circa March 2002 doesn't produce the zero
23635 type byte marking the end of the compilation
23636 unit. Complain if it's not there, but exit no
23639 /* Do we at least have room for a macinfo type byte? */
23640 if (mac_ptr
>= mac_end
)
23642 dwarf2_section_buffer_overflow_complaint (section
);
23646 /* We don't increment mac_ptr here, so this is just
23649 = (enum dwarf_macro_record_type
) read_1_byte (abfd
,
23651 if (next_type
!= 0)
23652 complaint (_("no terminating 0-type entry for "
23653 "macros in `.debug_macinfo' section"));
23660 case DW_MACRO_import
:
23661 case DW_MACRO_import_sup
:
23665 bfd
*include_bfd
= abfd
;
23666 struct dwarf2_section_info
*include_section
= section
;
23667 const gdb_byte
*include_mac_end
= mac_end
;
23668 int is_dwz
= section_is_dwz
;
23669 const gdb_byte
*new_mac_ptr
;
23671 offset
= read_offset (abfd
, mac_ptr
, offset_size
);
23672 mac_ptr
+= offset_size
;
23674 if (macinfo_type
== DW_MACRO_import_sup
)
23676 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
23678 dwz
->macro
.read (objfile
);
23680 include_section
= &dwz
->macro
;
23681 include_bfd
= include_section
->get_bfd_owner ();
23682 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
23686 new_mac_ptr
= include_section
->buffer
+ offset
;
23687 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
23691 /* This has actually happened; see
23692 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
23693 complaint (_("recursive DW_MACRO_import in "
23694 ".debug_macro section"));
23698 *slot
= (void *) new_mac_ptr
;
23700 dwarf_decode_macro_bytes (cu
, include_bfd
, new_mac_ptr
,
23701 include_mac_end
, current_file
, lh
,
23702 section
, section_is_gnu
, is_dwz
,
23703 offset_size
, include_hash
);
23705 htab_remove_elt (include_hash
, (void *) new_mac_ptr
);
23710 case DW_MACINFO_vendor_ext
:
23711 if (!section_is_gnu
)
23713 unsigned int bytes_read
;
23715 /* This reads the constant, but since we don't recognize
23716 any vendor extensions, we ignore it. */
23717 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23718 mac_ptr
+= bytes_read
;
23719 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
23720 mac_ptr
+= bytes_read
;
23722 /* We don't recognize any vendor extensions. */
23728 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
23729 mac_ptr
, mac_end
, abfd
, offset_size
,
23731 if (mac_ptr
== NULL
)
23736 } while (macinfo_type
!= 0);
23740 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
23741 int section_is_gnu
)
23743 struct dwarf2_per_objfile
*dwarf2_per_objfile
23744 = cu
->per_cu
->dwarf2_per_objfile
;
23745 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23746 struct line_header
*lh
= cu
->line_header
;
23748 const gdb_byte
*mac_ptr
, *mac_end
;
23749 struct macro_source_file
*current_file
= 0;
23750 enum dwarf_macro_record_type macinfo_type
;
23751 unsigned int offset_size
= cu
->header
.offset_size
;
23752 const gdb_byte
*opcode_definitions
[256];
23754 struct dwarf2_section_info
*section
;
23755 const char *section_name
;
23757 if (cu
->dwo_unit
!= NULL
)
23759 if (section_is_gnu
)
23761 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
23762 section_name
= ".debug_macro.dwo";
23766 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
23767 section_name
= ".debug_macinfo.dwo";
23772 if (section_is_gnu
)
23774 section
= &dwarf2_per_objfile
->macro
;
23775 section_name
= ".debug_macro";
23779 section
= &dwarf2_per_objfile
->macinfo
;
23780 section_name
= ".debug_macinfo";
23784 section
->read (objfile
);
23785 if (section
->buffer
== NULL
)
23787 complaint (_("missing %s section"), section_name
);
23790 abfd
= section
->get_bfd_owner ();
23792 /* First pass: Find the name of the base filename.
23793 This filename is needed in order to process all macros whose definition
23794 (or undefinition) comes from the command line. These macros are defined
23795 before the first DW_MACINFO_start_file entry, and yet still need to be
23796 associated to the base file.
23798 To determine the base file name, we scan the macro definitions until we
23799 reach the first DW_MACINFO_start_file entry. We then initialize
23800 CURRENT_FILE accordingly so that any macro definition found before the
23801 first DW_MACINFO_start_file can still be associated to the base file. */
23803 mac_ptr
= section
->buffer
+ offset
;
23804 mac_end
= section
->buffer
+ section
->size
;
23806 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
23807 &offset_size
, section_is_gnu
);
23808 if (mac_ptr
== NULL
)
23810 /* We already issued a complaint. */
23816 /* Do we at least have room for a macinfo type byte? */
23817 if (mac_ptr
>= mac_end
)
23819 /* Complaint is printed during the second pass as GDB will probably
23820 stop the first pass earlier upon finding
23821 DW_MACINFO_start_file. */
23825 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
23828 /* Note that we rely on the fact that the corresponding GNU and
23829 DWARF constants are the same. */
23831 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
23832 switch (macinfo_type
)
23834 /* A zero macinfo type indicates the end of the macro
23839 case DW_MACRO_define
:
23840 case DW_MACRO_undef
:
23841 /* Only skip the data by MAC_PTR. */
23843 unsigned int bytes_read
;
23845 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23846 mac_ptr
+= bytes_read
;
23847 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
23848 mac_ptr
+= bytes_read
;
23852 case DW_MACRO_start_file
:
23854 unsigned int bytes_read
;
23857 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23858 mac_ptr
+= bytes_read
;
23859 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23860 mac_ptr
+= bytes_read
;
23862 current_file
= macro_start_file (cu
, file
, line
, current_file
, lh
);
23866 case DW_MACRO_end_file
:
23867 /* No data to skip by MAC_PTR. */
23870 case DW_MACRO_define_strp
:
23871 case DW_MACRO_undef_strp
:
23872 case DW_MACRO_define_sup
:
23873 case DW_MACRO_undef_sup
:
23875 unsigned int bytes_read
;
23877 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23878 mac_ptr
+= bytes_read
;
23879 mac_ptr
+= offset_size
;
23883 case DW_MACRO_import
:
23884 case DW_MACRO_import_sup
:
23885 /* Note that, according to the spec, a transparent include
23886 chain cannot call DW_MACRO_start_file. So, we can just
23887 skip this opcode. */
23888 mac_ptr
+= offset_size
;
23891 case DW_MACINFO_vendor_ext
:
23892 /* Only skip the data by MAC_PTR. */
23893 if (!section_is_gnu
)
23895 unsigned int bytes_read
;
23897 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
23898 mac_ptr
+= bytes_read
;
23899 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
23900 mac_ptr
+= bytes_read
;
23905 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
23906 mac_ptr
, mac_end
, abfd
, offset_size
,
23908 if (mac_ptr
== NULL
)
23913 } while (macinfo_type
!= 0 && current_file
== NULL
);
23915 /* Second pass: Process all entries.
23917 Use the AT_COMMAND_LINE flag to determine whether we are still processing
23918 command-line macro definitions/undefinitions. This flag is unset when we
23919 reach the first DW_MACINFO_start_file entry. */
23921 htab_up
include_hash (htab_create_alloc (1, htab_hash_pointer
,
23923 NULL
, xcalloc
, xfree
));
23924 mac_ptr
= section
->buffer
+ offset
;
23925 slot
= htab_find_slot (include_hash
.get (), mac_ptr
, INSERT
);
23926 *slot
= (void *) mac_ptr
;
23927 dwarf_decode_macro_bytes (cu
, abfd
, mac_ptr
, mac_end
,
23928 current_file
, lh
, section
,
23929 section_is_gnu
, 0, offset_size
,
23930 include_hash
.get ());
23933 /* Return the .debug_loc section to use for CU.
23934 For DWO files use .debug_loc.dwo. */
23936 static struct dwarf2_section_info
*
23937 cu_debug_loc_section (struct dwarf2_cu
*cu
)
23939 struct dwarf2_per_objfile
*dwarf2_per_objfile
23940 = cu
->per_cu
->dwarf2_per_objfile
;
23944 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
23946 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
23948 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
23949 : &dwarf2_per_objfile
->loc
);
23952 /* A helper function that fills in a dwarf2_loclist_baton. */
23955 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
23956 struct dwarf2_loclist_baton
*baton
,
23957 const struct attribute
*attr
)
23959 struct dwarf2_per_objfile
*dwarf2_per_objfile
23960 = cu
->per_cu
->dwarf2_per_objfile
;
23961 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
23963 section
->read (dwarf2_per_objfile
->objfile
);
23965 baton
->per_cu
= cu
->per_cu
;
23966 gdb_assert (baton
->per_cu
);
23967 /* We don't know how long the location list is, but make sure we
23968 don't run off the edge of the section. */
23969 baton
->size
= section
->size
- DW_UNSND (attr
);
23970 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
23971 baton
->base_address
= cu
->base_address
;
23972 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
23976 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
23977 struct dwarf2_cu
*cu
, int is_block
)
23979 struct dwarf2_per_objfile
*dwarf2_per_objfile
23980 = cu
->per_cu
->dwarf2_per_objfile
;
23981 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23982 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
23984 if (attr
->form_is_section_offset ()
23985 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
23986 the section. If so, fall through to the complaint in the
23988 && DW_UNSND (attr
) < section
->get_size (objfile
))
23990 struct dwarf2_loclist_baton
*baton
;
23992 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
23994 fill_in_loclist_baton (cu
, baton
, attr
);
23996 if (cu
->base_known
== 0)
23997 complaint (_("Location list used without "
23998 "specifying the CU base address."));
24000 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24001 ? dwarf2_loclist_block_index
24002 : dwarf2_loclist_index
);
24003 SYMBOL_LOCATION_BATON (sym
) = baton
;
24007 struct dwarf2_locexpr_baton
*baton
;
24009 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
24010 baton
->per_cu
= cu
->per_cu
;
24011 gdb_assert (baton
->per_cu
);
24013 if (attr
->form_is_block ())
24015 /* Note that we're just copying the block's data pointer
24016 here, not the actual data. We're still pointing into the
24017 info_buffer for SYM's objfile; right now we never release
24018 that buffer, but when we do clean up properly this may
24020 baton
->size
= DW_BLOCK (attr
)->size
;
24021 baton
->data
= DW_BLOCK (attr
)->data
;
24025 dwarf2_invalid_attrib_class_complaint ("location description",
24026 sym
->natural_name ());
24030 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24031 ? dwarf2_locexpr_block_index
24032 : dwarf2_locexpr_index
);
24033 SYMBOL_LOCATION_BATON (sym
) = baton
;
24040 dwarf2_per_cu_data::objfile () const
24042 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24044 /* Return the master objfile, so that we can report and look up the
24045 correct file containing this variable. */
24046 if (objfile
->separate_debug_objfile_backlink
)
24047 objfile
= objfile
->separate_debug_objfile_backlink
;
24052 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
24053 (CU_HEADERP is unused in such case) or prepare a temporary copy at
24054 CU_HEADERP first. */
24056 static const struct comp_unit_head
*
24057 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
24058 const struct dwarf2_per_cu_data
*per_cu
)
24060 const gdb_byte
*info_ptr
;
24063 return &per_cu
->cu
->header
;
24065 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
24067 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
24068 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
24069 rcuh_kind::COMPILE
);
24077 dwarf2_per_cu_data::addr_size () const
24079 struct comp_unit_head cu_header_local
;
24080 const struct comp_unit_head
*cu_headerp
;
24082 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
24084 return cu_headerp
->addr_size
;
24090 dwarf2_per_cu_data::offset_size () const
24092 struct comp_unit_head cu_header_local
;
24093 const struct comp_unit_head
*cu_headerp
;
24095 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
24097 return cu_headerp
->offset_size
;
24103 dwarf2_per_cu_data::ref_addr_size () const
24105 struct comp_unit_head cu_header_local
;
24106 const struct comp_unit_head
*cu_headerp
;
24108 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
24110 if (cu_headerp
->version
== 2)
24111 return cu_headerp
->addr_size
;
24113 return cu_headerp
->offset_size
;
24119 dwarf2_per_cu_data::text_offset () const
24121 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24123 return objfile
->text_section_offset ();
24129 dwarf2_per_cu_data::addr_type () const
24131 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24132 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
24133 struct type
*addr_type
= lookup_pointer_type (void_type
);
24134 int addr_size
= this->addr_size ();
24136 if (TYPE_LENGTH (addr_type
) == addr_size
)
24139 addr_type
= addr_sized_int_type (TYPE_UNSIGNED (addr_type
));
24143 /* Locate the .debug_info compilation unit from CU's objfile which contains
24144 the DIE at OFFSET. Raises an error on failure. */
24146 static struct dwarf2_per_cu_data
*
24147 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
24148 unsigned int offset_in_dwz
,
24149 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
24151 struct dwarf2_per_cu_data
*this_cu
;
24155 high
= dwarf2_per_objfile
->all_comp_units
.size () - 1;
24158 struct dwarf2_per_cu_data
*mid_cu
;
24159 int mid
= low
+ (high
- low
) / 2;
24161 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
24162 if (mid_cu
->is_dwz
> offset_in_dwz
24163 || (mid_cu
->is_dwz
== offset_in_dwz
24164 && mid_cu
->sect_off
+ mid_cu
->length
>= sect_off
))
24169 gdb_assert (low
== high
);
24170 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
24171 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
24173 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
24174 error (_("Dwarf Error: could not find partial DIE containing "
24175 "offset %s [in module %s]"),
24176 sect_offset_str (sect_off
),
24177 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
24179 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
24181 return dwarf2_per_objfile
->all_comp_units
[low
-1];
24185 if (low
== dwarf2_per_objfile
->all_comp_units
.size () - 1
24186 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
24187 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
24188 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
24193 /* Initialize dwarf2_cu CU, owned by PER_CU. */
24195 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data
*per_cu_
)
24196 : per_cu (per_cu_
),
24198 has_loclist (false),
24199 checked_producer (false),
24200 producer_is_gxx_lt_4_6 (false),
24201 producer_is_gcc_lt_4_3 (false),
24202 producer_is_icc (false),
24203 producer_is_icc_lt_14 (false),
24204 producer_is_codewarrior (false),
24205 processing_has_namespace_info (false)
24210 /* Destroy a dwarf2_cu. */
24212 dwarf2_cu::~dwarf2_cu ()
24217 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
24220 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
24221 enum language pretend_language
)
24223 struct attribute
*attr
;
24225 /* Set the language we're debugging. */
24226 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
24227 if (attr
!= nullptr)
24228 set_cu_language (DW_UNSND (attr
), cu
);
24231 cu
->language
= pretend_language
;
24232 cu
->language_defn
= language_def (cu
->language
);
24235 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
24238 /* Increase the age counter on each cached compilation unit, and free
24239 any that are too old. */
24242 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
24244 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
24246 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
24247 per_cu
= dwarf2_per_objfile
->read_in_chain
;
24248 while (per_cu
!= NULL
)
24250 per_cu
->cu
->last_used
++;
24251 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
24252 dwarf2_mark (per_cu
->cu
);
24253 per_cu
= per_cu
->cu
->read_in_chain
;
24256 per_cu
= dwarf2_per_objfile
->read_in_chain
;
24257 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
24258 while (per_cu
!= NULL
)
24260 struct dwarf2_per_cu_data
*next_cu
;
24262 next_cu
= per_cu
->cu
->read_in_chain
;
24264 if (!per_cu
->cu
->mark
)
24267 *last_chain
= next_cu
;
24270 last_chain
= &per_cu
->cu
->read_in_chain
;
24276 /* Remove a single compilation unit from the cache. */
24279 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
24281 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
24282 struct dwarf2_per_objfile
*dwarf2_per_objfile
24283 = target_per_cu
->dwarf2_per_objfile
;
24285 per_cu
= dwarf2_per_objfile
->read_in_chain
;
24286 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
24287 while (per_cu
!= NULL
)
24289 struct dwarf2_per_cu_data
*next_cu
;
24291 next_cu
= per_cu
->cu
->read_in_chain
;
24293 if (per_cu
== target_per_cu
)
24297 *last_chain
= next_cu
;
24301 last_chain
= &per_cu
->cu
->read_in_chain
;
24307 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
24308 We store these in a hash table separate from the DIEs, and preserve them
24309 when the DIEs are flushed out of cache.
24311 The CU "per_cu" pointer is needed because offset alone is not enough to
24312 uniquely identify the type. A file may have multiple .debug_types sections,
24313 or the type may come from a DWO file. Furthermore, while it's more logical
24314 to use per_cu->section+offset, with Fission the section with the data is in
24315 the DWO file but we don't know that section at the point we need it.
24316 We have to use something in dwarf2_per_cu_data (or the pointer to it)
24317 because we can enter the lookup routine, get_die_type_at_offset, from
24318 outside this file, and thus won't necessarily have PER_CU->cu.
24319 Fortunately, PER_CU is stable for the life of the objfile. */
24321 struct dwarf2_per_cu_offset_and_type
24323 const struct dwarf2_per_cu_data
*per_cu
;
24324 sect_offset sect_off
;
24328 /* Hash function for a dwarf2_per_cu_offset_and_type. */
24331 per_cu_offset_and_type_hash (const void *item
)
24333 const struct dwarf2_per_cu_offset_and_type
*ofs
24334 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
24336 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
24339 /* Equality function for a dwarf2_per_cu_offset_and_type. */
24342 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
24344 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
24345 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
24346 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
24347 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
24349 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
24350 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
24353 /* Set the type associated with DIE to TYPE. Save it in CU's hash
24354 table if necessary. For convenience, return TYPE.
24356 The DIEs reading must have careful ordering to:
24357 * Not cause infinite loops trying to read in DIEs as a prerequisite for
24358 reading current DIE.
24359 * Not trying to dereference contents of still incompletely read in types
24360 while reading in other DIEs.
24361 * Enable referencing still incompletely read in types just by a pointer to
24362 the type without accessing its fields.
24364 Therefore caller should follow these rules:
24365 * Try to fetch any prerequisite types we may need to build this DIE type
24366 before building the type and calling set_die_type.
24367 * After building type call set_die_type for current DIE as soon as
24368 possible before fetching more types to complete the current type.
24369 * Make the type as complete as possible before fetching more types. */
24371 static struct type
*
24372 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
24374 struct dwarf2_per_objfile
*dwarf2_per_objfile
24375 = cu
->per_cu
->dwarf2_per_objfile
;
24376 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
24377 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24378 struct attribute
*attr
;
24379 struct dynamic_prop prop
;
24381 /* For Ada types, make sure that the gnat-specific data is always
24382 initialized (if not already set). There are a few types where
24383 we should not be doing so, because the type-specific area is
24384 already used to hold some other piece of info (eg: TYPE_CODE_FLT
24385 where the type-specific area is used to store the floatformat).
24386 But this is not a problem, because the gnat-specific information
24387 is actually not needed for these types. */
24388 if (need_gnat_info (cu
)
24389 && TYPE_CODE (type
) != TYPE_CODE_FUNC
24390 && TYPE_CODE (type
) != TYPE_CODE_FLT
24391 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
24392 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
24393 && TYPE_CODE (type
) != TYPE_CODE_METHOD
24394 && !HAVE_GNAT_AUX_INFO (type
))
24395 INIT_GNAT_SPECIFIC (type
);
24397 /* Read DW_AT_allocated and set in type. */
24398 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
24399 if (attr
!= NULL
&& attr
->form_is_block ())
24401 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
24402 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
24403 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
);
24405 else if (attr
!= NULL
)
24407 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
24408 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
24409 sect_offset_str (die
->sect_off
));
24412 /* Read DW_AT_associated and set in type. */
24413 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
24414 if (attr
!= NULL
&& attr
->form_is_block ())
24416 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
24417 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
24418 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
);
24420 else if (attr
!= NULL
)
24422 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
24423 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
24424 sect_offset_str (die
->sect_off
));
24427 /* Read DW_AT_data_location and set in type. */
24428 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
24429 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
,
24430 cu
->per_cu
->addr_type ()))
24431 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
);
24433 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
24434 dwarf2_per_objfile
->die_type_hash
24435 = htab_up (htab_create_alloc (127,
24436 per_cu_offset_and_type_hash
,
24437 per_cu_offset_and_type_eq
,
24438 NULL
, xcalloc
, xfree
));
24440 ofs
.per_cu
= cu
->per_cu
;
24441 ofs
.sect_off
= die
->sect_off
;
24443 slot
= (struct dwarf2_per_cu_offset_and_type
**)
24444 htab_find_slot (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
24446 complaint (_("A problem internal to GDB: DIE %s has type already set"),
24447 sect_offset_str (die
->sect_off
));
24448 *slot
= XOBNEW (&objfile
->objfile_obstack
,
24449 struct dwarf2_per_cu_offset_and_type
);
24454 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
24455 or return NULL if the die does not have a saved type. */
24457 static struct type
*
24458 get_die_type_at_offset (sect_offset sect_off
,
24459 struct dwarf2_per_cu_data
*per_cu
)
24461 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
24462 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
24464 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
24467 ofs
.per_cu
= per_cu
;
24468 ofs
.sect_off
= sect_off
;
24469 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
24470 htab_find (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
));
24477 /* Look up the type for DIE in CU in die_type_hash,
24478 or return NULL if DIE does not have a saved type. */
24480 static struct type
*
24481 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
24483 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
24486 /* Add a dependence relationship from CU to REF_PER_CU. */
24489 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
24490 struct dwarf2_per_cu_data
*ref_per_cu
)
24494 if (cu
->dependencies
== NULL
)
24496 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
24497 NULL
, &cu
->comp_unit_obstack
,
24498 hashtab_obstack_allocate
,
24499 dummy_obstack_deallocate
);
24501 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
24503 *slot
= ref_per_cu
;
24506 /* Subroutine of dwarf2_mark to pass to htab_traverse.
24507 Set the mark field in every compilation unit in the
24508 cache that we must keep because we are keeping CU. */
24511 dwarf2_mark_helper (void **slot
, void *data
)
24513 struct dwarf2_per_cu_data
*per_cu
;
24515 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
24517 /* cu->dependencies references may not yet have been ever read if QUIT aborts
24518 reading of the chain. As such dependencies remain valid it is not much
24519 useful to track and undo them during QUIT cleanups. */
24520 if (per_cu
->cu
== NULL
)
24523 if (per_cu
->cu
->mark
)
24525 per_cu
->cu
->mark
= true;
24527 if (per_cu
->cu
->dependencies
!= NULL
)
24528 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
24533 /* Set the mark field in CU and in every other compilation unit in the
24534 cache that we must keep because we are keeping CU. */
24537 dwarf2_mark (struct dwarf2_cu
*cu
)
24542 if (cu
->dependencies
!= NULL
)
24543 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
24547 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
24551 per_cu
->cu
->mark
= false;
24552 per_cu
= per_cu
->cu
->read_in_chain
;
24556 /* Trivial hash function for partial_die_info: the hash value of a DIE
24557 is its offset in .debug_info for this objfile. */
24560 partial_die_hash (const void *item
)
24562 const struct partial_die_info
*part_die
24563 = (const struct partial_die_info
*) item
;
24565 return to_underlying (part_die
->sect_off
);
24568 /* Trivial comparison function for partial_die_info structures: two DIEs
24569 are equal if they have the same offset. */
24572 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
24574 const struct partial_die_info
*part_die_lhs
24575 = (const struct partial_die_info
*) item_lhs
;
24576 const struct partial_die_info
*part_die_rhs
24577 = (const struct partial_die_info
*) item_rhs
;
24579 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
24582 struct cmd_list_element
*set_dwarf_cmdlist
;
24583 struct cmd_list_element
*show_dwarf_cmdlist
;
24586 set_dwarf_cmd (const char *args
, int from_tty
)
24588 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
24593 show_dwarf_cmd (const char *args
, int from_tty
)
24595 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
24599 show_check_physname (struct ui_file
*file
, int from_tty
,
24600 struct cmd_list_element
*c
, const char *value
)
24602 fprintf_filtered (file
,
24603 _("Whether to check \"physname\" is %s.\n"),
24607 void _initialize_dwarf2_read ();
24609 _initialize_dwarf2_read ()
24611 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
24612 Set DWARF specific variables.\n\
24613 Configure DWARF variables such as the cache size."),
24614 &set_dwarf_cmdlist
, "maintenance set dwarf ",
24615 0/*allow-unknown*/, &maintenance_set_cmdlist
);
24617 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
24618 Show DWARF specific variables.\n\
24619 Show DWARF variables such as the cache size."),
24620 &show_dwarf_cmdlist
, "maintenance show dwarf ",
24621 0/*allow-unknown*/, &maintenance_show_cmdlist
);
24623 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
24624 &dwarf_max_cache_age
, _("\
24625 Set the upper bound on the age of cached DWARF compilation units."), _("\
24626 Show the upper bound on the age of cached DWARF compilation units."), _("\
24627 A higher limit means that cached compilation units will be stored\n\
24628 in memory longer, and more total memory will be used. Zero disables\n\
24629 caching, which can slow down startup."),
24631 show_dwarf_max_cache_age
,
24632 &set_dwarf_cmdlist
,
24633 &show_dwarf_cmdlist
);
24635 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
24636 Set debugging of the DWARF reader."), _("\
24637 Show debugging of the DWARF reader."), _("\
24638 When enabled (non-zero), debugging messages are printed during DWARF\n\
24639 reading and symtab expansion. A value of 1 (one) provides basic\n\
24640 information. A value greater than 1 provides more verbose information."),
24643 &setdebuglist
, &showdebuglist
);
24645 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
24646 Set debugging of the DWARF DIE reader."), _("\
24647 Show debugging of the DWARF DIE reader."), _("\
24648 When enabled (non-zero), DIEs are dumped after they are read in.\n\
24649 The value is the maximum depth to print."),
24652 &setdebuglist
, &showdebuglist
);
24654 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
24655 Set debugging of the dwarf line reader."), _("\
24656 Show debugging of the dwarf line reader."), _("\
24657 When enabled (non-zero), line number entries are dumped as they are read in.\n\
24658 A value of 1 (one) provides basic information.\n\
24659 A value greater than 1 provides more verbose information."),
24662 &setdebuglist
, &showdebuglist
);
24664 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
24665 Set cross-checking of \"physname\" code against demangler."), _("\
24666 Show cross-checking of \"physname\" code against demangler."), _("\
24667 When enabled, GDB's internal \"physname\" code is checked against\n\
24669 NULL
, show_check_physname
,
24670 &setdebuglist
, &showdebuglist
);
24672 add_setshow_boolean_cmd ("use-deprecated-index-sections",
24673 no_class
, &use_deprecated_index_sections
, _("\
24674 Set whether to use deprecated gdb_index sections."), _("\
24675 Show whether to use deprecated gdb_index sections."), _("\
24676 When enabled, deprecated .gdb_index sections are used anyway.\n\
24677 Normally they are ignored either because of a missing feature or\n\
24678 performance issue.\n\
24679 Warning: This option must be enabled before gdb reads the file."),
24682 &setlist
, &showlist
);
24684 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24685 &dwarf2_locexpr_funcs
);
24686 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
24687 &dwarf2_loclist_funcs
);
24689 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24690 &dwarf2_block_frame_base_locexpr_funcs
);
24691 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
24692 &dwarf2_block_frame_base_loclist_funcs
);
24695 selftests::register_test ("dw2_expand_symtabs_matching",
24696 selftests::dw2_expand_symtabs_matching::run_test
);