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"
40 #include "dwarf2/dwz.h"
41 #include "dwarf2/macro.h"
42 #include "dwarf2/die.h"
43 #include "dwarf2/stringify.h"
52 #include "gdb-demangle.h"
53 #include "filenames.h" /* for DOSish file names */
55 #include "complaints.h"
56 #include "dwarf2/expr.h"
57 #include "dwarf2/loc.h"
58 #include "cp-support.h"
64 #include "typeprint.h"
69 #include "gdbcore.h" /* for gnutarget */
70 #include "gdb/gdb-index.h"
75 #include "namespace.h"
76 #include "gdbsupport/function-view.h"
77 #include "gdbsupport/gdb_optional.h"
78 #include "gdbsupport/underlying.h"
79 #include "gdbsupport/hash_enum.h"
80 #include "filename-seen-cache.h"
84 #include <unordered_map>
85 #include "gdbsupport/selftest.h"
86 #include "rust-lang.h"
87 #include "gdbsupport/pathstuff.h"
88 #include "count-one-bits.h"
89 #include "debuginfod-support.h"
91 /* When == 1, print basic high level tracing messages.
92 When > 1, be more verbose.
93 This is in contrast to the low level DIE reading of dwarf_die_debug. */
94 static unsigned int dwarf_read_debug
= 0;
96 /* When non-zero, dump DIEs after they are read in. */
97 static unsigned int dwarf_die_debug
= 0;
99 /* When non-zero, dump line number entries as they are read in. */
100 unsigned int dwarf_line_debug
= 0;
102 /* When true, cross-check physname against demangler. */
103 static bool check_physname
= false;
105 /* When true, do not reject deprecated .gdb_index sections. */
106 static bool use_deprecated_index_sections
= false;
108 static const struct objfile_key
<dwarf2_per_objfile
> dwarf2_objfile_data_key
;
110 /* The "aclass" indices for various kinds of computed DWARF symbols. */
112 static int dwarf2_locexpr_index
;
113 static int dwarf2_loclist_index
;
114 static int dwarf2_locexpr_block_index
;
115 static int dwarf2_loclist_block_index
;
117 /* Size of .debug_loclists section header for 32-bit DWARF format. */
118 #define LOCLIST_HEADER_SIZE32 12
120 /* Size of .debug_loclists section header for 64-bit DWARF format. */
121 #define LOCLIST_HEADER_SIZE64 20
123 /* An index into a (C++) symbol name component in a symbol name as
124 recorded in the mapped_index's symbol table. For each C++ symbol
125 in the symbol table, we record one entry for the start of each
126 component in the symbol in a table of name components, and then
127 sort the table, in order to be able to binary search symbol names,
128 ignoring leading namespaces, both completion and regular look up.
129 For example, for symbol "A::B::C", we'll have an entry that points
130 to "A::B::C", another that points to "B::C", and another for "C".
131 Note that function symbols in GDB index have no parameter
132 information, just the function/method names. You can convert a
133 name_component to a "const char *" using the
134 'mapped_index::symbol_name_at(offset_type)' method. */
136 struct name_component
138 /* Offset in the symbol name where the component starts. Stored as
139 a (32-bit) offset instead of a pointer to save memory and improve
140 locality on 64-bit architectures. */
141 offset_type name_offset
;
143 /* The symbol's index in the symbol and constant pool tables of a
148 /* Base class containing bits shared by both .gdb_index and
149 .debug_name indexes. */
151 struct mapped_index_base
153 mapped_index_base () = default;
154 DISABLE_COPY_AND_ASSIGN (mapped_index_base
);
156 /* The name_component table (a sorted vector). See name_component's
157 description above. */
158 std::vector
<name_component
> name_components
;
160 /* How NAME_COMPONENTS is sorted. */
161 enum case_sensitivity name_components_casing
;
163 /* Return the number of names in the symbol table. */
164 virtual size_t symbol_name_count () const = 0;
166 /* Get the name of the symbol at IDX in the symbol table. */
167 virtual const char *symbol_name_at (offset_type idx
) const = 0;
169 /* Return whether the name at IDX in the symbol table should be
171 virtual bool symbol_name_slot_invalid (offset_type idx
) const
176 /* Build the symbol name component sorted vector, if we haven't
178 void build_name_components ();
180 /* Returns the lower (inclusive) and upper (exclusive) bounds of the
181 possible matches for LN_NO_PARAMS in the name component
183 std::pair
<std::vector
<name_component
>::const_iterator
,
184 std::vector
<name_component
>::const_iterator
>
185 find_name_components_bounds (const lookup_name_info
&ln_no_params
,
186 enum language lang
) const;
188 /* Prevent deleting/destroying via a base class pointer. */
190 ~mapped_index_base() = default;
193 /* A description of the mapped index. The file format is described in
194 a comment by the code that writes the index. */
195 struct mapped_index final
: public mapped_index_base
197 /* A slot/bucket in the symbol table hash. */
198 struct symbol_table_slot
200 const offset_type name
;
201 const offset_type vec
;
204 /* Index data format version. */
207 /* The address table data. */
208 gdb::array_view
<const gdb_byte
> address_table
;
210 /* The symbol table, implemented as a hash table. */
211 gdb::array_view
<symbol_table_slot
> symbol_table
;
213 /* A pointer to the constant pool. */
214 const char *constant_pool
= nullptr;
216 bool symbol_name_slot_invalid (offset_type idx
) const override
218 const auto &bucket
= this->symbol_table
[idx
];
219 return bucket
.name
== 0 && bucket
.vec
== 0;
222 /* Convenience method to get at the name of the symbol at IDX in the
224 const char *symbol_name_at (offset_type idx
) const override
225 { return this->constant_pool
+ MAYBE_SWAP (this->symbol_table
[idx
].name
); }
227 size_t symbol_name_count () const override
228 { return this->symbol_table
.size (); }
231 /* A description of the mapped .debug_names.
232 Uninitialized map has CU_COUNT 0. */
233 struct mapped_debug_names final
: public mapped_index_base
235 mapped_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile_
)
236 : dwarf2_per_objfile (dwarf2_per_objfile_
)
239 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
240 bfd_endian dwarf5_byte_order
;
241 bool dwarf5_is_dwarf64
;
242 bool augmentation_is_gdb
;
244 uint32_t cu_count
= 0;
245 uint32_t tu_count
, bucket_count
, name_count
;
246 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
247 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
248 const gdb_byte
*name_table_string_offs_reordered
;
249 const gdb_byte
*name_table_entry_offs_reordered
;
250 const gdb_byte
*entry_pool
;
257 /* Attribute name DW_IDX_*. */
260 /* Attribute form DW_FORM_*. */
263 /* Value if FORM is DW_FORM_implicit_const. */
264 LONGEST implicit_const
;
266 std::vector
<attr
> attr_vec
;
269 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
271 const char *namei_to_name (uint32_t namei
) const;
273 /* Implementation of the mapped_index_base virtual interface, for
274 the name_components cache. */
276 const char *symbol_name_at (offset_type idx
) const override
277 { return namei_to_name (idx
); }
279 size_t symbol_name_count () const override
280 { return this->name_count
; }
283 /* See dwarf2read.h. */
286 get_dwarf2_per_objfile (struct objfile
*objfile
)
288 return dwarf2_objfile_data_key
.get (objfile
);
291 /* Default names of the debugging sections. */
293 /* Note that if the debugging section has been compressed, it might
294 have a name like .zdebug_info. */
296 static const struct dwarf2_debug_sections dwarf2_elf_names
=
298 { ".debug_info", ".zdebug_info" },
299 { ".debug_abbrev", ".zdebug_abbrev" },
300 { ".debug_line", ".zdebug_line" },
301 { ".debug_loc", ".zdebug_loc" },
302 { ".debug_loclists", ".zdebug_loclists" },
303 { ".debug_macinfo", ".zdebug_macinfo" },
304 { ".debug_macro", ".zdebug_macro" },
305 { ".debug_str", ".zdebug_str" },
306 { ".debug_str_offsets", ".zdebug_str_offsets" },
307 { ".debug_line_str", ".zdebug_line_str" },
308 { ".debug_ranges", ".zdebug_ranges" },
309 { ".debug_rnglists", ".zdebug_rnglists" },
310 { ".debug_types", ".zdebug_types" },
311 { ".debug_addr", ".zdebug_addr" },
312 { ".debug_frame", ".zdebug_frame" },
313 { ".eh_frame", NULL
},
314 { ".gdb_index", ".zgdb_index" },
315 { ".debug_names", ".zdebug_names" },
316 { ".debug_aranges", ".zdebug_aranges" },
320 /* List of DWO/DWP sections. */
322 static const struct dwop_section_names
324 struct dwarf2_section_names abbrev_dwo
;
325 struct dwarf2_section_names info_dwo
;
326 struct dwarf2_section_names line_dwo
;
327 struct dwarf2_section_names loc_dwo
;
328 struct dwarf2_section_names loclists_dwo
;
329 struct dwarf2_section_names macinfo_dwo
;
330 struct dwarf2_section_names macro_dwo
;
331 struct dwarf2_section_names str_dwo
;
332 struct dwarf2_section_names str_offsets_dwo
;
333 struct dwarf2_section_names types_dwo
;
334 struct dwarf2_section_names cu_index
;
335 struct dwarf2_section_names tu_index
;
339 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
340 { ".debug_info.dwo", ".zdebug_info.dwo" },
341 { ".debug_line.dwo", ".zdebug_line.dwo" },
342 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
343 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
344 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
345 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
346 { ".debug_str.dwo", ".zdebug_str.dwo" },
347 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
348 { ".debug_types.dwo", ".zdebug_types.dwo" },
349 { ".debug_cu_index", ".zdebug_cu_index" },
350 { ".debug_tu_index", ".zdebug_tu_index" },
353 /* local data types */
355 /* The location list section (.debug_loclists) begins with a header,
356 which contains the following information. */
357 struct loclist_header
359 /* A 4-byte or 12-byte length containing the length of the
360 set of entries for this compilation unit, not including the
361 length field itself. */
364 /* A 2-byte version identifier. */
367 /* A 1-byte unsigned integer containing the size in bytes of an address on
368 the target system. */
369 unsigned char addr_size
;
371 /* A 1-byte unsigned integer containing the size in bytes of a segment selector
372 on the target system. */
373 unsigned char segment_collector_size
;
375 /* A 4-byte count of the number of offsets that follow the header. */
376 unsigned int offset_entry_count
;
379 /* Type used for delaying computation of method physnames.
380 See comments for compute_delayed_physnames. */
381 struct delayed_method_info
383 /* The type to which the method is attached, i.e., its parent class. */
386 /* The index of the method in the type's function fieldlists. */
389 /* The index of the method in the fieldlist. */
392 /* The name of the DIE. */
395 /* The DIE associated with this method. */
396 struct die_info
*die
;
399 /* Internal state when decoding a particular compilation unit. */
402 explicit dwarf2_cu (struct dwarf2_per_cu_data
*per_cu
);
405 DISABLE_COPY_AND_ASSIGN (dwarf2_cu
);
407 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
408 Create the set of symtabs used by this TU, or if this TU is sharing
409 symtabs with another TU and the symtabs have already been created
410 then restore those symtabs in the line header.
411 We don't need the pc/line-number mapping for type units. */
412 void setup_type_unit_groups (struct die_info
*die
);
414 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
415 buildsym_compunit constructor. */
416 struct compunit_symtab
*start_symtab (const char *name
,
417 const char *comp_dir
,
420 /* Reset the builder. */
421 void reset_builder () { m_builder
.reset (); }
423 /* The header of the compilation unit. */
424 struct comp_unit_head header
{};
426 /* Base address of this compilation unit. */
427 gdb::optional
<CORE_ADDR
> base_address
;
429 /* The language we are debugging. */
430 enum language language
= language_unknown
;
431 const struct language_defn
*language_defn
= nullptr;
433 const char *producer
= nullptr;
436 /* The symtab builder for this CU. This is only non-NULL when full
437 symbols are being read. */
438 std::unique_ptr
<buildsym_compunit
> m_builder
;
441 /* The generic symbol table building routines have separate lists for
442 file scope symbols and all all other scopes (local scopes). So
443 we need to select the right one to pass to add_symbol_to_list().
444 We do it by keeping a pointer to the correct list in list_in_scope.
446 FIXME: The original dwarf code just treated the file scope as the
447 first local scope, and all other local scopes as nested local
448 scopes, and worked fine. Check to see if we really need to
449 distinguish these in buildsym.c. */
450 struct pending
**list_in_scope
= nullptr;
452 /* Hash table holding all the loaded partial DIEs
453 with partial_die->offset.SECT_OFF as hash. */
454 htab_t partial_dies
= nullptr;
456 /* Storage for things with the same lifetime as this read-in compilation
457 unit, including partial DIEs. */
458 auto_obstack comp_unit_obstack
;
460 /* When multiple dwarf2_cu structures are living in memory, this field
461 chains them all together, so that they can be released efficiently.
462 We will probably also want a generation counter so that most-recently-used
463 compilation units are cached... */
464 struct dwarf2_per_cu_data
*read_in_chain
= nullptr;
466 /* Backlink to our per_cu entry. */
467 struct dwarf2_per_cu_data
*per_cu
;
469 /* How many compilation units ago was this CU last referenced? */
472 /* A hash table of DIE cu_offset for following references with
473 die_info->offset.sect_off as hash. */
474 htab_t die_hash
= nullptr;
476 /* Full DIEs if read in. */
477 struct die_info
*dies
= nullptr;
479 /* A set of pointers to dwarf2_per_cu_data objects for compilation
480 units referenced by this one. Only set during full symbol processing;
481 partial symbol tables do not have dependencies. */
482 htab_t dependencies
= nullptr;
484 /* Header data from the line table, during full symbol processing. */
485 struct line_header
*line_header
= nullptr;
486 /* Non-NULL if LINE_HEADER is owned by this DWARF_CU. Otherwise,
487 it's owned by dwarf2_per_objfile::line_header_hash. If non-NULL,
488 this is the DW_TAG_compile_unit die for this CU. We'll hold on
489 to the line header as long as this DIE is being processed. See
490 process_die_scope. */
491 die_info
*line_header_die_owner
= nullptr;
493 /* A list of methods which need to have physnames computed
494 after all type information has been read. */
495 std::vector
<delayed_method_info
> method_list
;
497 /* To be copied to symtab->call_site_htab. */
498 htab_t call_site_htab
= nullptr;
500 /* Non-NULL if this CU came from a DWO file.
501 There is an invariant here that is important to remember:
502 Except for attributes copied from the top level DIE in the "main"
503 (or "stub") file in preparation for reading the DWO file
504 (e.g., DW_AT_addr_base), we KISS: there is only *one* CU.
505 Either there isn't a DWO file (in which case this is NULL and the point
506 is moot), or there is and either we're not going to read it (in which
507 case this is NULL) or there is and we are reading it (in which case this
509 struct dwo_unit
*dwo_unit
= nullptr;
511 /* The DW_AT_addr_base (DW_AT_GNU_addr_base) attribute if present.
512 Note this value comes from the Fission stub CU/TU's DIE. */
513 gdb::optional
<ULONGEST
> addr_base
;
515 /* The DW_AT_rnglists_base attribute if present.
516 Note this value comes from the Fission stub CU/TU's DIE.
517 Also note that the value is zero in the non-DWO case so this value can
518 be used without needing to know whether DWO files are in use or not.
519 N.B. This does not apply to DW_AT_ranges appearing in
520 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
521 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
522 DW_AT_rnglists_base *would* have to be applied, and we'd have to care
523 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
524 ULONGEST ranges_base
= 0;
526 /* The DW_AT_loclists_base attribute if present. */
527 ULONGEST loclist_base
= 0;
529 /* When reading debug info generated by older versions of rustc, we
530 have to rewrite some union types to be struct types with a
531 variant part. This rewriting must be done after the CU is fully
532 read in, because otherwise at the point of rewriting some struct
533 type might not have been fully processed. So, we keep a list of
534 all such types here and process them after expansion. */
535 std::vector
<struct type
*> rust_unions
;
537 /* The DW_AT_str_offsets_base attribute if present. For DWARF 4 version DWO
538 files, the value is implicitly zero. For DWARF 5 version DWO files, the
539 value is often implicit and is the size of the header of
540 .debug_str_offsets section (8 or 4, depending on the address size). */
541 gdb::optional
<ULONGEST
> str_offsets_base
;
543 /* Mark used when releasing cached dies. */
546 /* This CU references .debug_loc. See the symtab->locations_valid field.
547 This test is imperfect as there may exist optimized debug code not using
548 any location list and still facing inlining issues if handled as
549 unoptimized code. For a future better test see GCC PR other/32998. */
550 bool has_loclist
: 1;
552 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is true
553 if all the producer_is_* fields are valid. This information is cached
554 because profiling CU expansion showed excessive time spent in
555 producer_is_gxx_lt_4_6. */
556 bool checked_producer
: 1;
557 bool producer_is_gxx_lt_4_6
: 1;
558 bool producer_is_gcc_lt_4_3
: 1;
559 bool producer_is_icc
: 1;
560 bool producer_is_icc_lt_14
: 1;
561 bool producer_is_codewarrior
: 1;
563 /* When true, the file that we're processing is known to have
564 debugging info for C++ namespaces. GCC 3.3.x did not produce
565 this information, but later versions do. */
567 bool processing_has_namespace_info
: 1;
569 struct partial_die_info
*find_partial_die (sect_offset sect_off
);
571 /* If this CU was inherited by another CU (via specification,
572 abstract_origin, etc), this is the ancestor CU. */
575 /* Get the buildsym_compunit for this CU. */
576 buildsym_compunit
*get_builder ()
578 /* If this CU has a builder associated with it, use that. */
579 if (m_builder
!= nullptr)
580 return m_builder
.get ();
582 /* Otherwise, search ancestors for a valid builder. */
583 if (ancestor
!= nullptr)
584 return ancestor
->get_builder ();
590 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
591 This includes type_unit_group and quick_file_names. */
593 struct stmt_list_hash
595 /* The DWO unit this table is from or NULL if there is none. */
596 struct dwo_unit
*dwo_unit
;
598 /* Offset in .debug_line or .debug_line.dwo. */
599 sect_offset line_sect_off
;
602 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
603 an object of this type. */
605 struct type_unit_group
607 /* dwarf2read.c's main "handle" on a TU symtab.
608 To simplify things we create an artificial CU that "includes" all the
609 type units using this stmt_list so that the rest of the code still has
610 a "per_cu" handle on the symtab. */
611 struct dwarf2_per_cu_data per_cu
;
613 /* The TUs that share this DW_AT_stmt_list entry.
614 This is added to while parsing type units to build partial symtabs,
615 and is deleted afterwards and not used again. */
616 std::vector
<signatured_type
*> *tus
;
618 /* The compunit symtab.
619 Type units in a group needn't all be defined in the same source file,
620 so we create an essentially anonymous symtab as the compunit symtab. */
621 struct compunit_symtab
*compunit_symtab
;
623 /* The data used to construct the hash key. */
624 struct stmt_list_hash hash
;
626 /* The symbol tables for this TU (obtained from the files listed in
628 WARNING: The order of entries here must match the order of entries
629 in the line header. After the first TU using this type_unit_group, the
630 line header for the subsequent TUs is recreated from this. This is done
631 because we need to use the same symtabs for each TU using the same
632 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
633 there's no guarantee the line header doesn't have duplicate entries. */
634 struct symtab
**symtabs
;
637 /* These sections are what may appear in a (real or virtual) DWO file. */
641 struct dwarf2_section_info abbrev
;
642 struct dwarf2_section_info line
;
643 struct dwarf2_section_info loc
;
644 struct dwarf2_section_info loclists
;
645 struct dwarf2_section_info macinfo
;
646 struct dwarf2_section_info macro
;
647 struct dwarf2_section_info str
;
648 struct dwarf2_section_info str_offsets
;
649 /* In the case of a virtual DWO file, these two are unused. */
650 struct dwarf2_section_info info
;
651 std::vector
<dwarf2_section_info
> types
;
654 /* CUs/TUs in DWP/DWO files. */
658 /* Backlink to the containing struct dwo_file. */
659 struct dwo_file
*dwo_file
;
661 /* The "id" that distinguishes this CU/TU.
662 .debug_info calls this "dwo_id", .debug_types calls this "signature".
663 Since signatures came first, we stick with it for consistency. */
666 /* The section this CU/TU lives in, in the DWO file. */
667 struct dwarf2_section_info
*section
;
669 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
670 sect_offset sect_off
;
673 /* For types, offset in the type's DIE of the type defined by this TU. */
674 cu_offset type_offset_in_tu
;
677 /* include/dwarf2.h defines the DWP section codes.
678 It defines a max value but it doesn't define a min value, which we
679 use for error checking, so provide one. */
681 enum dwp_v2_section_ids
686 /* Data for one DWO file.
688 This includes virtual DWO files (a virtual DWO file is a DWO file as it
689 appears in a DWP file). DWP files don't really have DWO files per se -
690 comdat folding of types "loses" the DWO file they came from, and from
691 a high level view DWP files appear to contain a mass of random types.
692 However, to maintain consistency with the non-DWP case we pretend DWP
693 files contain virtual DWO files, and we assign each TU with one virtual
694 DWO file (generally based on the line and abbrev section offsets -
695 a heuristic that seems to work in practice). */
699 dwo_file () = default;
700 DISABLE_COPY_AND_ASSIGN (dwo_file
);
702 /* The DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute.
703 For virtual DWO files the name is constructed from the section offsets
704 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
705 from related CU+TUs. */
706 const char *dwo_name
= nullptr;
708 /* The DW_AT_comp_dir attribute. */
709 const char *comp_dir
= nullptr;
711 /* The bfd, when the file is open. Otherwise this is NULL.
712 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
713 gdb_bfd_ref_ptr dbfd
;
715 /* The sections that make up this DWO file.
716 Remember that for virtual DWO files in DWP V2, these are virtual
717 sections (for lack of a better name). */
718 struct dwo_sections sections
{};
720 /* The CUs in the file.
721 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
722 an extension to handle LLVM's Link Time Optimization output (where
723 multiple source files may be compiled into a single object/dwo pair). */
726 /* Table of TUs in the file.
727 Each element is a struct dwo_unit. */
731 /* These sections are what may appear in a DWP file. */
735 /* These are used by both DWP version 1 and 2. */
736 struct dwarf2_section_info str
;
737 struct dwarf2_section_info cu_index
;
738 struct dwarf2_section_info tu_index
;
740 /* These are only used by DWP version 2 files.
741 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
742 sections are referenced by section number, and are not recorded here.
743 In DWP version 2 there is at most one copy of all these sections, each
744 section being (effectively) comprised of the concatenation of all of the
745 individual sections that exist in the version 1 format.
746 To keep the code simple we treat each of these concatenated pieces as a
747 section itself (a virtual section?). */
748 struct dwarf2_section_info abbrev
;
749 struct dwarf2_section_info info
;
750 struct dwarf2_section_info line
;
751 struct dwarf2_section_info loc
;
752 struct dwarf2_section_info macinfo
;
753 struct dwarf2_section_info macro
;
754 struct dwarf2_section_info str_offsets
;
755 struct dwarf2_section_info types
;
758 /* These sections are what may appear in a virtual DWO file in DWP version 1.
759 A virtual DWO file is a DWO file as it appears in a DWP file. */
761 struct virtual_v1_dwo_sections
763 struct dwarf2_section_info abbrev
;
764 struct dwarf2_section_info line
;
765 struct dwarf2_section_info loc
;
766 struct dwarf2_section_info macinfo
;
767 struct dwarf2_section_info macro
;
768 struct dwarf2_section_info str_offsets
;
769 /* Each DWP hash table entry records one CU or one TU.
770 That is recorded here, and copied to dwo_unit.section. */
771 struct dwarf2_section_info info_or_types
;
774 /* Similar to virtual_v1_dwo_sections, but for DWP version 2.
775 In version 2, the sections of the DWO files are concatenated together
776 and stored in one section of that name. Thus each ELF section contains
777 several "virtual" sections. */
779 struct virtual_v2_dwo_sections
781 bfd_size_type abbrev_offset
;
782 bfd_size_type abbrev_size
;
784 bfd_size_type line_offset
;
785 bfd_size_type line_size
;
787 bfd_size_type loc_offset
;
788 bfd_size_type loc_size
;
790 bfd_size_type macinfo_offset
;
791 bfd_size_type macinfo_size
;
793 bfd_size_type macro_offset
;
794 bfd_size_type macro_size
;
796 bfd_size_type str_offsets_offset
;
797 bfd_size_type str_offsets_size
;
799 /* Each DWP hash table entry records one CU or one TU.
800 That is recorded here, and copied to dwo_unit.section. */
801 bfd_size_type info_or_types_offset
;
802 bfd_size_type info_or_types_size
;
805 /* Contents of DWP hash tables. */
807 struct dwp_hash_table
809 uint32_t version
, nr_columns
;
810 uint32_t nr_units
, nr_slots
;
811 const gdb_byte
*hash_table
, *unit_table
;
816 const gdb_byte
*indices
;
820 /* This is indexed by column number and gives the id of the section
822 #define MAX_NR_V2_DWO_SECTIONS \
823 (1 /* .debug_info or .debug_types */ \
824 + 1 /* .debug_abbrev */ \
825 + 1 /* .debug_line */ \
826 + 1 /* .debug_loc */ \
827 + 1 /* .debug_str_offsets */ \
828 + 1 /* .debug_macro or .debug_macinfo */)
829 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
830 const gdb_byte
*offsets
;
831 const gdb_byte
*sizes
;
836 /* Data for one DWP file. */
840 dwp_file (const char *name_
, gdb_bfd_ref_ptr
&&abfd
)
842 dbfd (std::move (abfd
))
846 /* Name of the file. */
849 /* File format version. */
853 gdb_bfd_ref_ptr dbfd
;
855 /* Section info for this file. */
856 struct dwp_sections sections
{};
858 /* Table of CUs in the file. */
859 const struct dwp_hash_table
*cus
= nullptr;
861 /* Table of TUs in the file. */
862 const struct dwp_hash_table
*tus
= nullptr;
864 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
868 /* Table to map ELF section numbers to their sections.
869 This is only needed for the DWP V1 file format. */
870 unsigned int num_sections
= 0;
871 asection
**elf_sections
= nullptr;
874 /* Struct used to pass misc. parameters to read_die_and_children, et
875 al. which are used for both .debug_info and .debug_types dies.
876 All parameters here are unchanging for the life of the call. This
877 struct exists to abstract away the constant parameters of die reading. */
879 struct die_reader_specs
881 /* The bfd of die_section. */
884 /* The CU of the DIE we are parsing. */
885 struct dwarf2_cu
*cu
;
887 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
888 struct dwo_file
*dwo_file
;
890 /* The section the die comes from.
891 This is either .debug_info or .debug_types, or the .dwo variants. */
892 struct dwarf2_section_info
*die_section
;
894 /* die_section->buffer. */
895 const gdb_byte
*buffer
;
897 /* The end of the buffer. */
898 const gdb_byte
*buffer_end
;
900 /* The abbreviation table to use when reading the DIEs. */
901 struct abbrev_table
*abbrev_table
;
904 /* A subclass of die_reader_specs that holds storage and has complex
905 constructor and destructor behavior. */
907 class cutu_reader
: public die_reader_specs
911 cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
912 struct abbrev_table
*abbrev_table
,
916 explicit cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
917 struct dwarf2_cu
*parent_cu
= nullptr,
918 struct dwo_file
*dwo_file
= nullptr);
920 DISABLE_COPY_AND_ASSIGN (cutu_reader
);
922 const gdb_byte
*info_ptr
= nullptr;
923 struct die_info
*comp_unit_die
= nullptr;
924 bool dummy_p
= false;
926 /* Release the new CU, putting it on the chain. This cannot be done
931 void init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
932 int use_existing_cu
);
934 struct dwarf2_per_cu_data
*m_this_cu
;
935 std::unique_ptr
<dwarf2_cu
> m_new_cu
;
937 /* The ordinary abbreviation table. */
938 abbrev_table_up m_abbrev_table_holder
;
940 /* The DWO abbreviation table. */
941 abbrev_table_up m_dwo_abbrev_table
;
944 /* When we construct a partial symbol table entry we only
945 need this much information. */
946 struct partial_die_info
: public allocate_on_obstack
948 partial_die_info (sect_offset sect_off
, struct abbrev_info
*abbrev
);
950 /* Disable assign but still keep copy ctor, which is needed
951 load_partial_dies. */
952 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
954 /* Adjust the partial die before generating a symbol for it. This
955 function may set the is_external flag or change the DIE's
957 void fixup (struct dwarf2_cu
*cu
);
959 /* Read a minimal amount of information into the minimal die
961 const gdb_byte
*read (const struct die_reader_specs
*reader
,
962 const struct abbrev_info
&abbrev
,
963 const gdb_byte
*info_ptr
);
965 /* Offset of this DIE. */
966 const sect_offset sect_off
;
968 /* DWARF-2 tag for this DIE. */
969 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
971 /* Assorted flags describing the data found in this DIE. */
972 const unsigned int has_children
: 1;
974 unsigned int is_external
: 1;
975 unsigned int is_declaration
: 1;
976 unsigned int has_type
: 1;
977 unsigned int has_specification
: 1;
978 unsigned int has_pc_info
: 1;
979 unsigned int may_be_inlined
: 1;
981 /* This DIE has been marked DW_AT_main_subprogram. */
982 unsigned int main_subprogram
: 1;
984 /* Flag set if the SCOPE field of this structure has been
986 unsigned int scope_set
: 1;
988 /* Flag set if the DIE has a byte_size attribute. */
989 unsigned int has_byte_size
: 1;
991 /* Flag set if the DIE has a DW_AT_const_value attribute. */
992 unsigned int has_const_value
: 1;
994 /* Flag set if any of the DIE's children are template arguments. */
995 unsigned int has_template_arguments
: 1;
997 /* Flag set if fixup has been called on this die. */
998 unsigned int fixup_called
: 1;
1000 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1001 unsigned int is_dwz
: 1;
1003 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1004 unsigned int spec_is_dwz
: 1;
1006 /* The name of this DIE. Normally the value of DW_AT_name, but
1007 sometimes a default name for unnamed DIEs. */
1008 const char *name
= nullptr;
1010 /* The linkage name, if present. */
1011 const char *linkage_name
= nullptr;
1013 /* The scope to prepend to our children. This is generally
1014 allocated on the comp_unit_obstack, so will disappear
1015 when this compilation unit leaves the cache. */
1016 const char *scope
= nullptr;
1018 /* Some data associated with the partial DIE. The tag determines
1019 which field is live. */
1022 /* The location description associated with this DIE, if any. */
1023 struct dwarf_block
*locdesc
;
1024 /* The offset of an import, for DW_TAG_imported_unit. */
1025 sect_offset sect_off
;
1028 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1029 CORE_ADDR lowpc
= 0;
1030 CORE_ADDR highpc
= 0;
1032 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1033 DW_AT_sibling, if any. */
1034 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1035 could return DW_AT_sibling values to its caller load_partial_dies. */
1036 const gdb_byte
*sibling
= nullptr;
1038 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1039 DW_AT_specification (or DW_AT_abstract_origin or
1040 DW_AT_extension). */
1041 sect_offset spec_offset
{};
1043 /* Pointers to this DIE's parent, first child, and next sibling,
1045 struct partial_die_info
*die_parent
= nullptr;
1046 struct partial_die_info
*die_child
= nullptr;
1047 struct partial_die_info
*die_sibling
= nullptr;
1049 friend struct partial_die_info
*
1050 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1053 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1054 partial_die_info (sect_offset sect_off
)
1055 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1059 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1061 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1066 has_specification
= 0;
1069 main_subprogram
= 0;
1072 has_const_value
= 0;
1073 has_template_arguments
= 0;
1080 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1081 but this would require a corresponding change in unpack_field_as_long
1083 static int bits_per_byte
= 8;
1085 /* When reading a variant or variant part, we track a bit more
1086 information about the field, and store it in an object of this
1089 struct variant_field
1091 /* If we see a DW_TAG_variant, then this will be the discriminant
1093 ULONGEST discriminant_value
;
1094 /* If we see a DW_TAG_variant, then this will be set if this is the
1096 bool default_branch
;
1097 /* While reading a DW_TAG_variant_part, this will be set if this
1098 field is the discriminant. */
1099 bool is_discriminant
;
1104 int accessibility
= 0;
1106 /* Extra information to describe a variant or variant part. */
1107 struct variant_field variant
{};
1108 struct field field
{};
1113 const char *name
= nullptr;
1114 std::vector
<struct fn_field
> fnfields
;
1117 /* The routines that read and process dies for a C struct or C++ class
1118 pass lists of data member fields and lists of member function fields
1119 in an instance of a field_info structure, as defined below. */
1122 /* List of data member and baseclasses fields. */
1123 std::vector
<struct nextfield
> fields
;
1124 std::vector
<struct nextfield
> baseclasses
;
1126 /* Set if the accessibility of one of the fields is not public. */
1127 int non_public_fields
= 0;
1129 /* Member function fieldlist array, contains name of possibly overloaded
1130 member function, number of overloaded member functions and a pointer
1131 to the head of the member function field chain. */
1132 std::vector
<struct fnfieldlist
> fnfieldlists
;
1134 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1135 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1136 std::vector
<struct decl_field
> typedef_field_list
;
1138 /* Nested types defined by this class and the number of elements in this
1140 std::vector
<struct decl_field
> nested_types_list
;
1142 /* Return the total number of fields (including baseclasses). */
1143 int nfields () const
1145 return fields
.size () + baseclasses
.size ();
1149 /* Loaded secondary compilation units are kept in memory until they
1150 have not been referenced for the processing of this many
1151 compilation units. Set this to zero to disable caching. Cache
1152 sizes of up to at least twenty will improve startup time for
1153 typical inter-CU-reference binaries, at an obvious memory cost. */
1154 static int dwarf_max_cache_age
= 5;
1156 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1157 struct cmd_list_element
*c
, const char *value
)
1159 fprintf_filtered (file
, _("The upper bound on the age of cached "
1160 "DWARF compilation units is %s.\n"),
1164 /* local function prototypes */
1166 static void dwarf2_find_base_address (struct die_info
*die
,
1167 struct dwarf2_cu
*cu
);
1169 static dwarf2_psymtab
*create_partial_symtab
1170 (struct dwarf2_per_cu_data
*per_cu
, const char *name
);
1172 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1173 const gdb_byte
*info_ptr
,
1174 struct die_info
*type_unit_die
);
1176 static void dwarf2_build_psymtabs_hard
1177 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1179 static void scan_partial_symbols (struct partial_die_info
*,
1180 CORE_ADDR
*, CORE_ADDR
*,
1181 int, struct dwarf2_cu
*);
1183 static void add_partial_symbol (struct partial_die_info
*,
1184 struct dwarf2_cu
*);
1186 static void add_partial_namespace (struct partial_die_info
*pdi
,
1187 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1188 int set_addrmap
, struct dwarf2_cu
*cu
);
1190 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1191 CORE_ADDR
*highpc
, int set_addrmap
,
1192 struct dwarf2_cu
*cu
);
1194 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1195 struct dwarf2_cu
*cu
);
1197 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1198 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1199 int need_pc
, struct dwarf2_cu
*cu
);
1201 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1203 static struct partial_die_info
*load_partial_dies
1204 (const struct die_reader_specs
*, const gdb_byte
*, int);
1206 /* A pair of partial_die_info and compilation unit. */
1207 struct cu_partial_die_info
1209 /* The compilation unit of the partial_die_info. */
1210 struct dwarf2_cu
*cu
;
1211 /* A partial_die_info. */
1212 struct partial_die_info
*pdi
;
1214 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1220 cu_partial_die_info () = delete;
1223 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1224 struct dwarf2_cu
*);
1226 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1227 struct attribute
*, struct attr_abbrev
*,
1228 const gdb_byte
*, bool *need_reprocess
);
1230 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1231 struct attribute
*attr
);
1233 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1235 static sect_offset read_abbrev_offset
1236 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1237 struct dwarf2_section_info
*, sect_offset
);
1239 static const char *read_indirect_string
1240 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1241 const struct comp_unit_head
*, unsigned int *);
1243 static const char *read_indirect_string_at_offset
1244 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, LONGEST str_offset
);
1246 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1250 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1251 ULONGEST str_index
);
1253 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1254 ULONGEST str_index
);
1256 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1258 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1259 struct dwarf2_cu
*);
1261 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1262 struct dwarf2_cu
*cu
);
1264 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1266 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1267 struct dwarf2_cu
*cu
);
1269 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1271 static struct die_info
*die_specification (struct die_info
*die
,
1272 struct dwarf2_cu
**);
1274 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1275 struct dwarf2_cu
*cu
);
1277 static void dwarf_decode_lines (struct line_header
*, const char *,
1278 struct dwarf2_cu
*, dwarf2_psymtab
*,
1279 CORE_ADDR
, int decode_mapping
);
1281 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1284 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1285 struct dwarf2_cu
*, struct symbol
* = NULL
);
1287 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1288 struct dwarf2_cu
*);
1290 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1293 struct obstack
*obstack
,
1294 struct dwarf2_cu
*cu
, LONGEST
*value
,
1295 const gdb_byte
**bytes
,
1296 struct dwarf2_locexpr_baton
**baton
);
1298 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1300 static int need_gnat_info (struct dwarf2_cu
*);
1302 static struct type
*die_descriptive_type (struct die_info
*,
1303 struct dwarf2_cu
*);
1305 static void set_descriptive_type (struct type
*, struct die_info
*,
1306 struct dwarf2_cu
*);
1308 static struct type
*die_containing_type (struct die_info
*,
1309 struct dwarf2_cu
*);
1311 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1312 struct dwarf2_cu
*);
1314 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1316 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1318 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1320 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1321 const char *suffix
, int physname
,
1322 struct dwarf2_cu
*cu
);
1324 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1326 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1328 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1330 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1332 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1334 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1336 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1337 struct dwarf2_cu
*, dwarf2_psymtab
*);
1339 /* Return the .debug_loclists section to use for cu. */
1340 static struct dwarf2_section_info
*cu_debug_loc_section (struct dwarf2_cu
*cu
);
1342 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1343 values. Keep the items ordered with increasing constraints compliance. */
1346 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1347 PC_BOUNDS_NOT_PRESENT
,
1349 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1350 were present but they do not form a valid range of PC addresses. */
1353 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1356 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1360 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1361 CORE_ADDR
*, CORE_ADDR
*,
1365 static void get_scope_pc_bounds (struct die_info
*,
1366 CORE_ADDR
*, CORE_ADDR
*,
1367 struct dwarf2_cu
*);
1369 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1370 CORE_ADDR
, struct dwarf2_cu
*);
1372 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1373 struct dwarf2_cu
*);
1375 static void dwarf2_attach_fields_to_type (struct field_info
*,
1376 struct type
*, struct dwarf2_cu
*);
1378 static void dwarf2_add_member_fn (struct field_info
*,
1379 struct die_info
*, struct type
*,
1380 struct dwarf2_cu
*);
1382 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1384 struct dwarf2_cu
*);
1386 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1388 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1390 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1392 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1394 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1396 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1398 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1400 static struct type
*read_module_type (struct die_info
*die
,
1401 struct dwarf2_cu
*cu
);
1403 static const char *namespace_name (struct die_info
*die
,
1404 int *is_anonymous
, struct dwarf2_cu
*);
1406 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1408 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1410 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1411 struct dwarf2_cu
*);
1413 static struct die_info
*read_die_and_siblings_1
1414 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1417 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1418 const gdb_byte
*info_ptr
,
1419 const gdb_byte
**new_info_ptr
,
1420 struct die_info
*parent
);
1422 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1423 struct die_info
**, const gdb_byte
*,
1426 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1427 struct die_info
**, const gdb_byte
*);
1429 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1431 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1434 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1436 static const char *dwarf2_full_name (const char *name
,
1437 struct die_info
*die
,
1438 struct dwarf2_cu
*cu
);
1440 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1441 struct dwarf2_cu
*cu
);
1443 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1444 struct dwarf2_cu
**);
1446 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1448 static void dump_die_for_error (struct die_info
*);
1450 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1453 /*static*/ void dump_die (struct die_info
*, int max_level
);
1455 static void store_in_ref_table (struct die_info
*,
1456 struct dwarf2_cu
*);
1458 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1459 const struct attribute
*,
1460 struct dwarf2_cu
**);
1462 static struct die_info
*follow_die_ref (struct die_info
*,
1463 const struct attribute
*,
1464 struct dwarf2_cu
**);
1466 static struct die_info
*follow_die_sig (struct die_info
*,
1467 const struct attribute
*,
1468 struct dwarf2_cu
**);
1470 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1471 struct dwarf2_cu
*);
1473 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1474 const struct attribute
*,
1475 struct dwarf2_cu
*);
1477 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1479 static void read_signatured_type (struct signatured_type
*);
1481 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1482 struct die_info
*die
, struct dwarf2_cu
*cu
,
1483 struct dynamic_prop
*prop
, struct type
*type
);
1485 /* memory allocation interface */
1487 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1489 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1491 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1493 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1494 struct dwarf2_loclist_baton
*baton
,
1495 const struct attribute
*attr
);
1497 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1499 struct dwarf2_cu
*cu
,
1502 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1503 const gdb_byte
*info_ptr
,
1504 struct abbrev_info
*abbrev
);
1506 static hashval_t
partial_die_hash (const void *item
);
1508 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1510 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1511 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1512 struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1514 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1515 struct die_info
*comp_unit_die
,
1516 enum language pretend_language
);
1518 static void age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1520 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1522 static struct type
*set_die_type (struct die_info
*, struct type
*,
1523 struct dwarf2_cu
*);
1525 static void create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1527 static int create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1529 static void load_full_comp_unit (struct dwarf2_per_cu_data
*, bool,
1532 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1535 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1538 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1539 struct dwarf2_per_cu_data
*);
1541 static void dwarf2_mark (struct dwarf2_cu
*);
1543 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1545 static struct type
*get_die_type_at_offset (sect_offset
,
1546 struct dwarf2_per_cu_data
*);
1548 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1550 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1551 enum language pretend_language
);
1553 static void process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1555 /* Class, the destructor of which frees all allocated queue entries. This
1556 will only have work to do if an error was thrown while processing the
1557 dwarf. If no error was thrown then the queue entries should have all
1558 been processed, and freed, as we went along. */
1560 class dwarf2_queue_guard
1563 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1564 : m_per_objfile (per_objfile
)
1568 /* Free any entries remaining on the queue. There should only be
1569 entries left if we hit an error while processing the dwarf. */
1570 ~dwarf2_queue_guard ()
1572 /* Ensure that no memory is allocated by the queue. */
1573 std::queue
<dwarf2_queue_item
> empty
;
1574 std::swap (m_per_objfile
->queue
, empty
);
1577 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1580 dwarf2_per_objfile
*m_per_objfile
;
1583 dwarf2_queue_item::~dwarf2_queue_item ()
1585 /* Anything still marked queued is likely to be in an
1586 inconsistent state, so discard it. */
1589 if (per_cu
->cu
!= NULL
)
1590 free_one_cached_comp_unit (per_cu
);
1595 /* The return type of find_file_and_directory. Note, the enclosed
1596 string pointers are only valid while this object is valid. */
1598 struct file_and_directory
1600 /* The filename. This is never NULL. */
1603 /* The compilation directory. NULL if not known. If we needed to
1604 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1605 points directly to the DW_AT_comp_dir string attribute owned by
1606 the obstack that owns the DIE. */
1607 const char *comp_dir
;
1609 /* If we needed to build a new string for comp_dir, this is what
1610 owns the storage. */
1611 std::string comp_dir_storage
;
1614 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1615 struct dwarf2_cu
*cu
);
1617 static htab_up
allocate_signatured_type_table ();
1619 static htab_up
allocate_dwo_unit_table ();
1621 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1622 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1623 struct dwp_file
*dwp_file
, const char *comp_dir
,
1624 ULONGEST signature
, int is_debug_types
);
1626 static struct dwp_file
*get_dwp_file
1627 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1629 static struct dwo_unit
*lookup_dwo_comp_unit
1630 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
1632 static struct dwo_unit
*lookup_dwo_type_unit
1633 (struct signatured_type
*, const char *, const char *);
1635 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
1637 /* A unique pointer to a dwo_file. */
1639 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1641 static void process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1643 static void check_producer (struct dwarf2_cu
*cu
);
1645 static void free_line_header_voidp (void *arg
);
1647 /* Various complaints about symbol reading that don't abort the process. */
1650 dwarf2_debug_line_missing_file_complaint (void)
1652 complaint (_(".debug_line section has line data without a file"));
1656 dwarf2_debug_line_missing_end_sequence_complaint (void)
1658 complaint (_(".debug_line section has line "
1659 "program sequence without an end"));
1663 dwarf2_complex_location_expr_complaint (void)
1665 complaint (_("location expression too complex"));
1669 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1672 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1677 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1679 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1683 /* Hash function for line_header_hash. */
1686 line_header_hash (const struct line_header
*ofs
)
1688 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1691 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1694 line_header_hash_voidp (const void *item
)
1696 const struct line_header
*ofs
= (const struct line_header
*) item
;
1698 return line_header_hash (ofs
);
1701 /* Equality function for line_header_hash. */
1704 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1706 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1707 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1709 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1710 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
1715 /* See declaration. */
1717 dwarf2_per_objfile::dwarf2_per_objfile (struct objfile
*objfile_
,
1718 const dwarf2_debug_sections
*names
,
1720 : objfile (objfile_
),
1721 can_copy (can_copy_
)
1724 names
= &dwarf2_elf_names
;
1726 bfd
*obfd
= objfile
->obfd
;
1728 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1729 locate_sections (obfd
, sec
, *names
);
1732 dwarf2_per_objfile::~dwarf2_per_objfile ()
1734 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
1735 free_cached_comp_units ();
1737 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
1738 per_cu
->imported_symtabs_free ();
1740 for (signatured_type
*sig_type
: all_type_units
)
1741 sig_type
->per_cu
.imported_symtabs_free ();
1743 /* Everything else should be on the objfile obstack. */
1746 /* See declaration. */
1749 dwarf2_per_objfile::free_cached_comp_units ()
1751 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
1752 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
1753 while (per_cu
!= NULL
)
1755 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
1758 *last_chain
= next_cu
;
1763 /* A helper class that calls free_cached_comp_units on
1766 class free_cached_comp_units
1770 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1771 : m_per_objfile (per_objfile
)
1775 ~free_cached_comp_units ()
1777 m_per_objfile
->free_cached_comp_units ();
1780 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1784 dwarf2_per_objfile
*m_per_objfile
;
1787 /* Try to locate the sections we need for DWARF 2 debugging
1788 information and return true if we have enough to do something.
1789 NAMES points to the dwarf2 section names, or is NULL if the standard
1790 ELF names are used. CAN_COPY is true for formats where symbol
1791 interposition is possible and so symbol values must follow copy
1792 relocation rules. */
1795 dwarf2_has_info (struct objfile
*objfile
,
1796 const struct dwarf2_debug_sections
*names
,
1799 if (objfile
->flags
& OBJF_READNEVER
)
1802 struct dwarf2_per_objfile
*dwarf2_per_objfile
1803 = get_dwarf2_per_objfile (objfile
);
1805 if (dwarf2_per_objfile
== NULL
)
1806 dwarf2_per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
,
1810 return (!dwarf2_per_objfile
->info
.is_virtual
1811 && dwarf2_per_objfile
->info
.s
.section
!= NULL
1812 && !dwarf2_per_objfile
->abbrev
.is_virtual
1813 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
1816 /* When loading sections, we look either for uncompressed section or for
1817 compressed section names. */
1820 section_is_p (const char *section_name
,
1821 const struct dwarf2_section_names
*names
)
1823 if (names
->normal
!= NULL
1824 && strcmp (section_name
, names
->normal
) == 0)
1826 if (names
->compressed
!= NULL
1827 && strcmp (section_name
, names
->compressed
) == 0)
1832 /* See declaration. */
1835 dwarf2_per_objfile::locate_sections (bfd
*abfd
, asection
*sectp
,
1836 const dwarf2_debug_sections
&names
)
1838 flagword aflag
= bfd_section_flags (sectp
);
1840 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1843 else if (elf_section_data (sectp
)->this_hdr
.sh_size
1844 > bfd_get_file_size (abfd
))
1846 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
1847 warning (_("Discarding section %s which has a section size (%s"
1848 ") larger than the file size [in module %s]"),
1849 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
1850 bfd_get_filename (abfd
));
1852 else if (section_is_p (sectp
->name
, &names
.info
))
1854 this->info
.s
.section
= sectp
;
1855 this->info
.size
= bfd_section_size (sectp
);
1857 else if (section_is_p (sectp
->name
, &names
.abbrev
))
1859 this->abbrev
.s
.section
= sectp
;
1860 this->abbrev
.size
= bfd_section_size (sectp
);
1862 else if (section_is_p (sectp
->name
, &names
.line
))
1864 this->line
.s
.section
= sectp
;
1865 this->line
.size
= bfd_section_size (sectp
);
1867 else if (section_is_p (sectp
->name
, &names
.loc
))
1869 this->loc
.s
.section
= sectp
;
1870 this->loc
.size
= bfd_section_size (sectp
);
1872 else if (section_is_p (sectp
->name
, &names
.loclists
))
1874 this->loclists
.s
.section
= sectp
;
1875 this->loclists
.size
= bfd_section_size (sectp
);
1877 else if (section_is_p (sectp
->name
, &names
.macinfo
))
1879 this->macinfo
.s
.section
= sectp
;
1880 this->macinfo
.size
= bfd_section_size (sectp
);
1882 else if (section_is_p (sectp
->name
, &names
.macro
))
1884 this->macro
.s
.section
= sectp
;
1885 this->macro
.size
= bfd_section_size (sectp
);
1887 else if (section_is_p (sectp
->name
, &names
.str
))
1889 this->str
.s
.section
= sectp
;
1890 this->str
.size
= bfd_section_size (sectp
);
1892 else if (section_is_p (sectp
->name
, &names
.str_offsets
))
1894 this->str_offsets
.s
.section
= sectp
;
1895 this->str_offsets
.size
= bfd_section_size (sectp
);
1897 else if (section_is_p (sectp
->name
, &names
.line_str
))
1899 this->line_str
.s
.section
= sectp
;
1900 this->line_str
.size
= bfd_section_size (sectp
);
1902 else if (section_is_p (sectp
->name
, &names
.addr
))
1904 this->addr
.s
.section
= sectp
;
1905 this->addr
.size
= bfd_section_size (sectp
);
1907 else if (section_is_p (sectp
->name
, &names
.frame
))
1909 this->frame
.s
.section
= sectp
;
1910 this->frame
.size
= bfd_section_size (sectp
);
1912 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
1914 this->eh_frame
.s
.section
= sectp
;
1915 this->eh_frame
.size
= bfd_section_size (sectp
);
1917 else if (section_is_p (sectp
->name
, &names
.ranges
))
1919 this->ranges
.s
.section
= sectp
;
1920 this->ranges
.size
= bfd_section_size (sectp
);
1922 else if (section_is_p (sectp
->name
, &names
.rnglists
))
1924 this->rnglists
.s
.section
= sectp
;
1925 this->rnglists
.size
= bfd_section_size (sectp
);
1927 else if (section_is_p (sectp
->name
, &names
.types
))
1929 struct dwarf2_section_info type_section
;
1931 memset (&type_section
, 0, sizeof (type_section
));
1932 type_section
.s
.section
= sectp
;
1933 type_section
.size
= bfd_section_size (sectp
);
1935 this->types
.push_back (type_section
);
1937 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
1939 this->gdb_index
.s
.section
= sectp
;
1940 this->gdb_index
.size
= bfd_section_size (sectp
);
1942 else if (section_is_p (sectp
->name
, &names
.debug_names
))
1944 this->debug_names
.s
.section
= sectp
;
1945 this->debug_names
.size
= bfd_section_size (sectp
);
1947 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
1949 this->debug_aranges
.s
.section
= sectp
;
1950 this->debug_aranges
.size
= bfd_section_size (sectp
);
1953 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
1954 && bfd_section_vma (sectp
) == 0)
1955 this->has_section_at_zero
= true;
1958 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1962 dwarf2_get_section_info (struct objfile
*objfile
,
1963 enum dwarf2_section_enum sect
,
1964 asection
**sectp
, const gdb_byte
**bufp
,
1965 bfd_size_type
*sizep
)
1967 struct dwarf2_per_objfile
*data
= dwarf2_objfile_data_key
.get (objfile
);
1968 struct dwarf2_section_info
*info
;
1970 /* We may see an objfile without any DWARF, in which case we just
1981 case DWARF2_DEBUG_FRAME
:
1982 info
= &data
->frame
;
1984 case DWARF2_EH_FRAME
:
1985 info
= &data
->eh_frame
;
1988 gdb_assert_not_reached ("unexpected section");
1991 info
->read (objfile
);
1993 *sectp
= info
->get_bfd_section ();
1994 *bufp
= info
->buffer
;
1995 *sizep
= info
->size
;
1998 /* A helper function to find the sections for a .dwz file. */
2001 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2003 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2005 /* Note that we only support the standard ELF names, because .dwz
2006 is ELF-only (at the time of writing). */
2007 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2009 dwz_file
->abbrev
.s
.section
= sectp
;
2010 dwz_file
->abbrev
.size
= bfd_section_size (sectp
);
2012 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2014 dwz_file
->info
.s
.section
= sectp
;
2015 dwz_file
->info
.size
= bfd_section_size (sectp
);
2017 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2019 dwz_file
->str
.s
.section
= sectp
;
2020 dwz_file
->str
.size
= bfd_section_size (sectp
);
2022 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2024 dwz_file
->line
.s
.section
= sectp
;
2025 dwz_file
->line
.size
= bfd_section_size (sectp
);
2027 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2029 dwz_file
->macro
.s
.section
= sectp
;
2030 dwz_file
->macro
.size
= bfd_section_size (sectp
);
2032 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2034 dwz_file
->gdb_index
.s
.section
= sectp
;
2035 dwz_file
->gdb_index
.size
= bfd_section_size (sectp
);
2037 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2039 dwz_file
->debug_names
.s
.section
= sectp
;
2040 dwz_file
->debug_names
.size
= bfd_section_size (sectp
);
2044 /* See dwarf2read.h. */
2047 dwarf2_get_dwz_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
2049 const char *filename
;
2050 bfd_size_type buildid_len_arg
;
2054 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2055 return dwarf2_per_objfile
->dwz_file
.get ();
2057 bfd_set_error (bfd_error_no_error
);
2058 gdb::unique_xmalloc_ptr
<char> data
2059 (bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2060 &buildid_len_arg
, &buildid
));
2063 if (bfd_get_error () == bfd_error_no_error
)
2065 error (_("could not read '.gnu_debugaltlink' section: %s"),
2066 bfd_errmsg (bfd_get_error ()));
2069 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2071 buildid_len
= (size_t) buildid_len_arg
;
2073 filename
= data
.get ();
2075 std::string abs_storage
;
2076 if (!IS_ABSOLUTE_PATH (filename
))
2078 gdb::unique_xmalloc_ptr
<char> abs
2079 = gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2081 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2082 filename
= abs_storage
.c_str ();
2085 /* First try the file name given in the section. If that doesn't
2086 work, try to use the build-id instead. */
2087 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
, -1));
2088 if (dwz_bfd
!= NULL
)
2090 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2091 dwz_bfd
.reset (nullptr);
2094 if (dwz_bfd
== NULL
)
2095 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2097 if (dwz_bfd
== nullptr)
2099 gdb::unique_xmalloc_ptr
<char> alt_filename
;
2100 const char *origname
= dwarf2_per_objfile
->objfile
->original_name
;
2102 scoped_fd
fd (debuginfod_debuginfo_query (buildid
,
2109 /* File successfully retrieved from server. */
2110 dwz_bfd
= gdb_bfd_open (alt_filename
.get (), gnutarget
, -1);
2112 if (dwz_bfd
== nullptr)
2113 warning (_("File \"%s\" from debuginfod cannot be opened as bfd"),
2114 alt_filename
.get ());
2115 else if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2116 dwz_bfd
.reset (nullptr);
2120 if (dwz_bfd
== NULL
)
2121 error (_("could not find '.gnu_debugaltlink' file for %s"),
2122 objfile_name (dwarf2_per_objfile
->objfile
));
2124 std::unique_ptr
<struct dwz_file
> result
2125 (new struct dwz_file (std::move (dwz_bfd
)));
2127 bfd_map_over_sections (result
->dwz_bfd
.get (), locate_dwz_sections
,
2130 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
,
2131 result
->dwz_bfd
.get ());
2132 dwarf2_per_objfile
->dwz_file
= std::move (result
);
2133 return dwarf2_per_objfile
->dwz_file
.get ();
2136 /* DWARF quick_symbols_functions support. */
2138 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2139 unique line tables, so we maintain a separate table of all .debug_line
2140 derived entries to support the sharing.
2141 All the quick functions need is the list of file names. We discard the
2142 line_header when we're done and don't need to record it here. */
2143 struct quick_file_names
2145 /* The data used to construct the hash key. */
2146 struct stmt_list_hash hash
;
2148 /* The number of entries in file_names, real_names. */
2149 unsigned int num_file_names
;
2151 /* The file names from the line table, after being run through
2153 const char **file_names
;
2155 /* The file names from the line table after being run through
2156 gdb_realpath. These are computed lazily. */
2157 const char **real_names
;
2160 /* When using the index (and thus not using psymtabs), each CU has an
2161 object of this type. This is used to hold information needed by
2162 the various "quick" methods. */
2163 struct dwarf2_per_cu_quick_data
2165 /* The file table. This can be NULL if there was no file table
2166 or it's currently not read in.
2167 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2168 struct quick_file_names
*file_names
;
2170 /* The corresponding symbol table. This is NULL if symbols for this
2171 CU have not yet been read. */
2172 struct compunit_symtab
*compunit_symtab
;
2174 /* A temporary mark bit used when iterating over all CUs in
2175 expand_symtabs_matching. */
2176 unsigned int mark
: 1;
2178 /* True if we've tried to read the file table and found there isn't one.
2179 There will be no point in trying to read it again next time. */
2180 unsigned int no_file_data
: 1;
2183 /* Utility hash function for a stmt_list_hash. */
2186 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2190 if (stmt_list_hash
->dwo_unit
!= NULL
)
2191 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2192 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2196 /* Utility equality function for a stmt_list_hash. */
2199 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2200 const struct stmt_list_hash
*rhs
)
2202 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2204 if (lhs
->dwo_unit
!= NULL
2205 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2208 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2211 /* Hash function for a quick_file_names. */
2214 hash_file_name_entry (const void *e
)
2216 const struct quick_file_names
*file_data
2217 = (const struct quick_file_names
*) e
;
2219 return hash_stmt_list_entry (&file_data
->hash
);
2222 /* Equality function for a quick_file_names. */
2225 eq_file_name_entry (const void *a
, const void *b
)
2227 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2228 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2230 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2233 /* Delete function for a quick_file_names. */
2236 delete_file_name_entry (void *e
)
2238 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2241 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2243 xfree ((void*) file_data
->file_names
[i
]);
2244 if (file_data
->real_names
)
2245 xfree ((void*) file_data
->real_names
[i
]);
2248 /* The space for the struct itself lives on objfile_obstack,
2249 so we don't free it here. */
2252 /* Create a quick_file_names hash table. */
2255 create_quick_file_names_table (unsigned int nr_initial_entries
)
2257 return htab_up (htab_create_alloc (nr_initial_entries
,
2258 hash_file_name_entry
, eq_file_name_entry
,
2259 delete_file_name_entry
, xcalloc
, xfree
));
2262 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2263 have to be created afterwards. You should call age_cached_comp_units after
2264 processing PER_CU->CU. dw2_setup must have been already called. */
2267 load_cu (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2269 if (per_cu
->is_debug_types
)
2270 load_full_type_unit (per_cu
);
2272 load_full_comp_unit (per_cu
, skip_partial
, language_minimal
);
2274 if (per_cu
->cu
== NULL
)
2275 return; /* Dummy CU. */
2277 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2280 /* Read in the symbols for PER_CU. */
2283 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2285 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2287 /* Skip type_unit_groups, reading the type units they contain
2288 is handled elsewhere. */
2289 if (per_cu
->type_unit_group_p ())
2292 /* The destructor of dwarf2_queue_guard frees any entries left on
2293 the queue. After this point we're guaranteed to leave this function
2294 with the dwarf queue empty. */
2295 dwarf2_queue_guard
q_guard (dwarf2_per_objfile
);
2297 if (dwarf2_per_objfile
->using_index
2298 ? per_cu
->v
.quick
->compunit_symtab
== NULL
2299 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2301 queue_comp_unit (per_cu
, language_minimal
);
2302 load_cu (per_cu
, skip_partial
);
2304 /* If we just loaded a CU from a DWO, and we're working with an index
2305 that may badly handle TUs, load all the TUs in that DWO as well.
2306 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2307 if (!per_cu
->is_debug_types
2308 && per_cu
->cu
!= NULL
2309 && per_cu
->cu
->dwo_unit
!= NULL
2310 && dwarf2_per_objfile
->index_table
!= NULL
2311 && dwarf2_per_objfile
->index_table
->version
<= 7
2312 /* DWP files aren't supported yet. */
2313 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
2314 queue_and_load_all_dwo_tus (per_cu
);
2317 process_queue (dwarf2_per_objfile
);
2319 /* Age the cache, releasing compilation units that have not
2320 been used recently. */
2321 age_cached_comp_units (dwarf2_per_objfile
);
2324 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2325 the objfile from which this CU came. Returns the resulting symbol
2328 static struct compunit_symtab
*
2329 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2331 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2333 gdb_assert (dwarf2_per_objfile
->using_index
);
2334 if (!per_cu
->v
.quick
->compunit_symtab
)
2336 free_cached_comp_units
freer (dwarf2_per_objfile
);
2337 scoped_restore decrementer
= increment_reading_symtab ();
2338 dw2_do_instantiate_symtab (per_cu
, skip_partial
);
2339 process_cu_includes (dwarf2_per_objfile
);
2342 return per_cu
->v
.quick
->compunit_symtab
;
2345 /* See declaration. */
2347 dwarf2_per_cu_data
*
2348 dwarf2_per_objfile::get_cutu (int index
)
2350 if (index
>= this->all_comp_units
.size ())
2352 index
-= this->all_comp_units
.size ();
2353 gdb_assert (index
< this->all_type_units
.size ());
2354 return &this->all_type_units
[index
]->per_cu
;
2357 return this->all_comp_units
[index
];
2360 /* See declaration. */
2362 dwarf2_per_cu_data
*
2363 dwarf2_per_objfile::get_cu (int index
)
2365 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2367 return this->all_comp_units
[index
];
2370 /* See declaration. */
2373 dwarf2_per_objfile::get_tu (int index
)
2375 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2377 return this->all_type_units
[index
];
2380 /* Return a new dwarf2_per_cu_data allocated on OBJFILE's
2381 objfile_obstack, and constructed with the specified field
2384 static dwarf2_per_cu_data
*
2385 create_cu_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2386 struct dwarf2_section_info
*section
,
2388 sect_offset sect_off
, ULONGEST length
)
2390 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2391 dwarf2_per_cu_data
*the_cu
2392 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2393 struct dwarf2_per_cu_data
);
2394 the_cu
->sect_off
= sect_off
;
2395 the_cu
->length
= length
;
2396 the_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
2397 the_cu
->section
= section
;
2398 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2399 struct dwarf2_per_cu_quick_data
);
2400 the_cu
->is_dwz
= is_dwz
;
2404 /* A helper for create_cus_from_index that handles a given list of
2408 create_cus_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2409 const gdb_byte
*cu_list
, offset_type n_elements
,
2410 struct dwarf2_section_info
*section
,
2413 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2415 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2417 sect_offset sect_off
2418 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2419 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2422 dwarf2_per_cu_data
*per_cu
2423 = create_cu_from_index_list (dwarf2_per_objfile
, section
, is_dwz
,
2425 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
2429 /* Read the CU list from the mapped index, and use it to create all
2430 the CU objects for this objfile. */
2433 create_cus_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2434 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2435 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2437 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
2438 dwarf2_per_objfile
->all_comp_units
.reserve
2439 ((cu_list_elements
+ dwz_elements
) / 2);
2441 create_cus_from_index_list (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
2442 &dwarf2_per_objfile
->info
, 0);
2444 if (dwz_elements
== 0)
2447 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
2448 create_cus_from_index_list (dwarf2_per_objfile
, dwz_list
, dwz_elements
,
2452 /* Create the signatured type hash table from the index. */
2455 create_signatured_type_table_from_index
2456 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2457 struct dwarf2_section_info
*section
,
2458 const gdb_byte
*bytes
,
2459 offset_type elements
)
2461 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2463 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
2464 dwarf2_per_objfile
->all_type_units
.reserve (elements
/ 3);
2466 htab_up sig_types_hash
= allocate_signatured_type_table ();
2468 for (offset_type i
= 0; i
< elements
; i
+= 3)
2470 struct signatured_type
*sig_type
;
2473 cu_offset type_offset_in_tu
;
2475 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2476 sect_offset sect_off
2477 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2479 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2481 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2484 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2485 struct signatured_type
);
2486 sig_type
->signature
= signature
;
2487 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2488 sig_type
->per_cu
.is_debug_types
= 1;
2489 sig_type
->per_cu
.section
= section
;
2490 sig_type
->per_cu
.sect_off
= sect_off
;
2491 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
2492 sig_type
->per_cu
.v
.quick
2493 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2494 struct dwarf2_per_cu_quick_data
);
2496 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2499 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
2502 dwarf2_per_objfile
->signatured_types
= std::move (sig_types_hash
);
2505 /* Create the signatured type hash table from .debug_names. */
2508 create_signatured_type_table_from_debug_names
2509 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2510 const mapped_debug_names
&map
,
2511 struct dwarf2_section_info
*section
,
2512 struct dwarf2_section_info
*abbrev_section
)
2514 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2516 section
->read (objfile
);
2517 abbrev_section
->read (objfile
);
2519 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
2520 dwarf2_per_objfile
->all_type_units
.reserve (map
.tu_count
);
2522 htab_up sig_types_hash
= allocate_signatured_type_table ();
2524 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2526 struct signatured_type
*sig_type
;
2529 sect_offset sect_off
2530 = (sect_offset
) (extract_unsigned_integer
2531 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2533 map
.dwarf5_byte_order
));
2535 comp_unit_head cu_header
;
2536 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
2538 section
->buffer
+ to_underlying (sect_off
),
2541 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2542 struct signatured_type
);
2543 sig_type
->signature
= cu_header
.signature
;
2544 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2545 sig_type
->per_cu
.is_debug_types
= 1;
2546 sig_type
->per_cu
.section
= section
;
2547 sig_type
->per_cu
.sect_off
= sect_off
;
2548 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
2549 sig_type
->per_cu
.v
.quick
2550 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2551 struct dwarf2_per_cu_quick_data
);
2553 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2556 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
2559 dwarf2_per_objfile
->signatured_types
= std::move (sig_types_hash
);
2562 /* Read the address map data from the mapped index, and use it to
2563 populate the objfile's psymtabs_addrmap. */
2566 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2567 struct mapped_index
*index
)
2569 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2570 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2571 const gdb_byte
*iter
, *end
;
2572 struct addrmap
*mutable_map
;
2575 auto_obstack temp_obstack
;
2577 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2579 iter
= index
->address_table
.data ();
2580 end
= iter
+ index
->address_table
.size ();
2582 baseaddr
= objfile
->text_section_offset ();
2586 ULONGEST hi
, lo
, cu_index
;
2587 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2589 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2591 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2596 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2597 hex_string (lo
), hex_string (hi
));
2601 if (cu_index
>= dwarf2_per_objfile
->all_comp_units
.size ())
2603 complaint (_(".gdb_index address table has invalid CU number %u"),
2604 (unsigned) cu_index
);
2608 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2609 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2610 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2611 dwarf2_per_objfile
->get_cu (cu_index
));
2614 objfile
->partial_symtabs
->psymtabs_addrmap
2615 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2618 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2619 populate the objfile's psymtabs_addrmap. */
2622 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2623 struct dwarf2_section_info
*section
)
2625 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2626 bfd
*abfd
= objfile
->obfd
;
2627 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2628 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2630 auto_obstack temp_obstack
;
2631 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2633 std::unordered_map
<sect_offset
,
2634 dwarf2_per_cu_data
*,
2635 gdb::hash_enum
<sect_offset
>>
2636 debug_info_offset_to_per_cu
;
2637 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
2639 const auto insertpair
2640 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
2641 if (!insertpair
.second
)
2643 warning (_("Section .debug_aranges in %s has duplicate "
2644 "debug_info_offset %s, ignoring .debug_aranges."),
2645 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2650 section
->read (objfile
);
2652 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2654 const gdb_byte
*addr
= section
->buffer
;
2656 while (addr
< section
->buffer
+ section
->size
)
2658 const gdb_byte
*const entry_addr
= addr
;
2659 unsigned int bytes_read
;
2661 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2665 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2666 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2667 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2668 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2670 warning (_("Section .debug_aranges in %s entry at offset %s "
2671 "length %s exceeds section length %s, "
2672 "ignoring .debug_aranges."),
2673 objfile_name (objfile
),
2674 plongest (entry_addr
- section
->buffer
),
2675 plongest (bytes_read
+ entry_length
),
2676 pulongest (section
->size
));
2680 /* The version number. */
2681 const uint16_t version
= read_2_bytes (abfd
, addr
);
2685 warning (_("Section .debug_aranges in %s entry at offset %s "
2686 "has unsupported version %d, ignoring .debug_aranges."),
2687 objfile_name (objfile
),
2688 plongest (entry_addr
- section
->buffer
), version
);
2692 const uint64_t debug_info_offset
2693 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2694 addr
+= offset_size
;
2695 const auto per_cu_it
2696 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2697 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2699 warning (_("Section .debug_aranges in %s entry at offset %s "
2700 "debug_info_offset %s does not exists, "
2701 "ignoring .debug_aranges."),
2702 objfile_name (objfile
),
2703 plongest (entry_addr
- section
->buffer
),
2704 pulongest (debug_info_offset
));
2707 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2709 const uint8_t address_size
= *addr
++;
2710 if (address_size
< 1 || address_size
> 8)
2712 warning (_("Section .debug_aranges in %s entry at offset %s "
2713 "address_size %u is invalid, ignoring .debug_aranges."),
2714 objfile_name (objfile
),
2715 plongest (entry_addr
- section
->buffer
), address_size
);
2719 const uint8_t segment_selector_size
= *addr
++;
2720 if (segment_selector_size
!= 0)
2722 warning (_("Section .debug_aranges in %s entry at offset %s "
2723 "segment_selector_size %u is not supported, "
2724 "ignoring .debug_aranges."),
2725 objfile_name (objfile
),
2726 plongest (entry_addr
- section
->buffer
),
2727 segment_selector_size
);
2731 /* Must pad to an alignment boundary that is twice the address
2732 size. It is undocumented by the DWARF standard but GCC does
2734 for (size_t padding
= ((-(addr
- section
->buffer
))
2735 & (2 * address_size
- 1));
2736 padding
> 0; padding
--)
2739 warning (_("Section .debug_aranges in %s entry at offset %s "
2740 "padding is not zero, ignoring .debug_aranges."),
2741 objfile_name (objfile
),
2742 plongest (entry_addr
- section
->buffer
));
2748 if (addr
+ 2 * address_size
> entry_end
)
2750 warning (_("Section .debug_aranges in %s entry at offset %s "
2751 "address list is not properly terminated, "
2752 "ignoring .debug_aranges."),
2753 objfile_name (objfile
),
2754 plongest (entry_addr
- section
->buffer
));
2757 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
2759 addr
+= address_size
;
2760 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
2762 addr
+= address_size
;
2763 if (start
== 0 && length
== 0)
2765 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
2767 /* Symbol was eliminated due to a COMDAT group. */
2770 ULONGEST end
= start
+ length
;
2771 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
2773 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
2775 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
2779 objfile
->partial_symtabs
->psymtabs_addrmap
2780 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2783 /* Find a slot in the mapped index INDEX for the object named NAME.
2784 If NAME is found, set *VEC_OUT to point to the CU vector in the
2785 constant pool and return true. If NAME cannot be found, return
2789 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2790 offset_type
**vec_out
)
2793 offset_type slot
, step
;
2794 int (*cmp
) (const char *, const char *);
2796 gdb::unique_xmalloc_ptr
<char> without_params
;
2797 if (current_language
->la_language
== language_cplus
2798 || current_language
->la_language
== language_fortran
2799 || current_language
->la_language
== language_d
)
2801 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2804 if (strchr (name
, '(') != NULL
)
2806 without_params
= cp_remove_params (name
);
2808 if (without_params
!= NULL
)
2809 name
= without_params
.get ();
2813 /* Index version 4 did not support case insensitive searches. But the
2814 indices for case insensitive languages are built in lowercase, therefore
2815 simulate our NAME being searched is also lowercased. */
2816 hash
= mapped_index_string_hash ((index
->version
== 4
2817 && case_sensitivity
== case_sensitive_off
2818 ? 5 : index
->version
),
2821 slot
= hash
& (index
->symbol_table
.size () - 1);
2822 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
2823 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2829 const auto &bucket
= index
->symbol_table
[slot
];
2830 if (bucket
.name
== 0 && bucket
.vec
== 0)
2833 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
2834 if (!cmp (name
, str
))
2836 *vec_out
= (offset_type
*) (index
->constant_pool
2837 + MAYBE_SWAP (bucket
.vec
));
2841 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
2845 /* A helper function that reads the .gdb_index from BUFFER and fills
2846 in MAP. FILENAME is the name of the file containing the data;
2847 it is used for error reporting. DEPRECATED_OK is true if it is
2848 ok to use deprecated sections.
2850 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2851 out parameters that are filled in with information about the CU and
2852 TU lists in the section.
2854 Returns true if all went well, false otherwise. */
2857 read_gdb_index_from_buffer (const char *filename
,
2859 gdb::array_view
<const gdb_byte
> buffer
,
2860 struct mapped_index
*map
,
2861 const gdb_byte
**cu_list
,
2862 offset_type
*cu_list_elements
,
2863 const gdb_byte
**types_list
,
2864 offset_type
*types_list_elements
)
2866 const gdb_byte
*addr
= &buffer
[0];
2868 /* Version check. */
2869 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
2870 /* Versions earlier than 3 emitted every copy of a psymbol. This
2871 causes the index to behave very poorly for certain requests. Version 3
2872 contained incomplete addrmap. So, it seems better to just ignore such
2876 static int warning_printed
= 0;
2877 if (!warning_printed
)
2879 warning (_("Skipping obsolete .gdb_index section in %s."),
2881 warning_printed
= 1;
2885 /* Index version 4 uses a different hash function than index version
2888 Versions earlier than 6 did not emit psymbols for inlined
2889 functions. Using these files will cause GDB not to be able to
2890 set breakpoints on inlined functions by name, so we ignore these
2891 indices unless the user has done
2892 "set use-deprecated-index-sections on". */
2893 if (version
< 6 && !deprecated_ok
)
2895 static int warning_printed
= 0;
2896 if (!warning_printed
)
2899 Skipping deprecated .gdb_index section in %s.\n\
2900 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2901 to use the section anyway."),
2903 warning_printed
= 1;
2907 /* Version 7 indices generated by gold refer to the CU for a symbol instead
2908 of the TU (for symbols coming from TUs),
2909 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
2910 Plus gold-generated indices can have duplicate entries for global symbols,
2911 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
2912 These are just performance bugs, and we can't distinguish gdb-generated
2913 indices from gold-generated ones, so issue no warning here. */
2915 /* Indexes with higher version than the one supported by GDB may be no
2916 longer backward compatible. */
2920 map
->version
= version
;
2922 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2925 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2926 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2930 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2931 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2932 - MAYBE_SWAP (metadata
[i
]))
2936 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2937 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
2939 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
2942 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2943 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
2945 = gdb::array_view
<mapped_index::symbol_table_slot
>
2946 ((mapped_index::symbol_table_slot
*) symbol_table
,
2947 (mapped_index::symbol_table_slot
*) symbol_table_end
);
2950 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
2955 /* Callback types for dwarf2_read_gdb_index. */
2957 typedef gdb::function_view
2958 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_objfile
*)>
2959 get_gdb_index_contents_ftype
;
2960 typedef gdb::function_view
2961 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
2962 get_gdb_index_contents_dwz_ftype
;
2964 /* Read .gdb_index. If everything went ok, initialize the "quick"
2965 elements of all the CUs and return 1. Otherwise, return 0. */
2968 dwarf2_read_gdb_index
2969 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2970 get_gdb_index_contents_ftype get_gdb_index_contents
,
2971 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
2973 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
2974 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
2975 struct dwz_file
*dwz
;
2976 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2978 gdb::array_view
<const gdb_byte
> main_index_contents
2979 = get_gdb_index_contents (objfile
, dwarf2_per_objfile
);
2981 if (main_index_contents
.empty ())
2984 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
2985 if (!read_gdb_index_from_buffer (objfile_name (objfile
),
2986 use_deprecated_index_sections
,
2987 main_index_contents
, map
.get (), &cu_list
,
2988 &cu_list_elements
, &types_list
,
2989 &types_list_elements
))
2992 /* Don't use the index if it's empty. */
2993 if (map
->symbol_table
.empty ())
2996 /* If there is a .dwz file, read it so we can get its CU list as
2998 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3001 struct mapped_index dwz_map
;
3002 const gdb_byte
*dwz_types_ignore
;
3003 offset_type dwz_types_elements_ignore
;
3005 gdb::array_view
<const gdb_byte
> dwz_index_content
3006 = get_gdb_index_contents_dwz (objfile
, dwz
);
3008 if (dwz_index_content
.empty ())
3011 if (!read_gdb_index_from_buffer (bfd_get_filename (dwz
->dwz_bfd
.get ()),
3012 1, dwz_index_content
, &dwz_map
,
3013 &dwz_list
, &dwz_list_elements
,
3015 &dwz_types_elements_ignore
))
3017 warning (_("could not read '.gdb_index' section from %s; skipping"),
3018 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3023 create_cus_from_index (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3024 dwz_list
, dwz_list_elements
);
3026 if (types_list_elements
)
3028 /* We can only handle a single .debug_types when we have an
3030 if (dwarf2_per_objfile
->types
.size () != 1)
3033 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
3035 create_signatured_type_table_from_index (dwarf2_per_objfile
, section
,
3036 types_list
, types_list_elements
);
3039 create_addrmap_from_index (dwarf2_per_objfile
, map
.get ());
3041 dwarf2_per_objfile
->index_table
= std::move (map
);
3042 dwarf2_per_objfile
->using_index
= 1;
3043 dwarf2_per_objfile
->quick_file_names_table
=
3044 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
3049 /* die_reader_func for dw2_get_file_names. */
3052 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3053 const gdb_byte
*info_ptr
,
3054 struct die_info
*comp_unit_die
)
3056 struct dwarf2_cu
*cu
= reader
->cu
;
3057 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3058 struct dwarf2_per_objfile
*dwarf2_per_objfile
3059 = cu
->per_cu
->dwarf2_per_objfile
;
3060 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3061 struct dwarf2_per_cu_data
*lh_cu
;
3062 struct attribute
*attr
;
3064 struct quick_file_names
*qfn
;
3066 gdb_assert (! this_cu
->is_debug_types
);
3068 /* Our callers never want to match partial units -- instead they
3069 will match the enclosing full CU. */
3070 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3072 this_cu
->v
.quick
->no_file_data
= 1;
3080 sect_offset line_offset
{};
3082 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3083 if (attr
!= nullptr)
3085 struct quick_file_names find_entry
;
3087 line_offset
= (sect_offset
) DW_UNSND (attr
);
3089 /* We may have already read in this line header (TU line header sharing).
3090 If we have we're done. */
3091 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3092 find_entry
.hash
.line_sect_off
= line_offset
;
3093 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
.get (),
3094 &find_entry
, INSERT
);
3097 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3101 lh
= dwarf_decode_line_header (line_offset
, cu
);
3105 lh_cu
->v
.quick
->no_file_data
= 1;
3109 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
3110 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3111 qfn
->hash
.line_sect_off
= line_offset
;
3112 gdb_assert (slot
!= NULL
);
3115 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3118 if (strcmp (fnd
.name
, "<unknown>") != 0)
3121 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3123 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, qfn
->num_file_names
);
3125 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3126 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3127 qfn
->file_names
[i
+ offset
] = lh
->file_full_name (i
+ 1,
3128 fnd
.comp_dir
).release ();
3129 qfn
->real_names
= NULL
;
3131 lh_cu
->v
.quick
->file_names
= qfn
;
3134 /* A helper for the "quick" functions which attempts to read the line
3135 table for THIS_CU. */
3137 static struct quick_file_names
*
3138 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3140 /* This should never be called for TUs. */
3141 gdb_assert (! this_cu
->is_debug_types
);
3142 /* Nor type unit groups. */
3143 gdb_assert (! this_cu
->type_unit_group_p ());
3145 if (this_cu
->v
.quick
->file_names
!= NULL
)
3146 return this_cu
->v
.quick
->file_names
;
3147 /* If we know there is no line data, no point in looking again. */
3148 if (this_cu
->v
.quick
->no_file_data
)
3151 cutu_reader
reader (this_cu
);
3152 if (!reader
.dummy_p
)
3153 dw2_get_file_names_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
);
3155 if (this_cu
->v
.quick
->no_file_data
)
3157 return this_cu
->v
.quick
->file_names
;
3160 /* A helper for the "quick" functions which computes and caches the
3161 real path for a given file name from the line table. */
3164 dw2_get_real_path (struct objfile
*objfile
,
3165 struct quick_file_names
*qfn
, int index
)
3167 if (qfn
->real_names
== NULL
)
3168 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3169 qfn
->num_file_names
, const char *);
3171 if (qfn
->real_names
[index
] == NULL
)
3172 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3174 return qfn
->real_names
[index
];
3177 static struct symtab
*
3178 dw2_find_last_source_symtab (struct objfile
*objfile
)
3180 struct dwarf2_per_objfile
*dwarf2_per_objfile
3181 = get_dwarf2_per_objfile (objfile
);
3182 dwarf2_per_cu_data
*dwarf_cu
= dwarf2_per_objfile
->all_comp_units
.back ();
3183 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, false);
3188 return compunit_primary_filetab (cust
);
3191 /* Traversal function for dw2_forget_cached_source_info. */
3194 dw2_free_cached_file_names (void **slot
, void *info
)
3196 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3198 if (file_data
->real_names
)
3202 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3204 xfree ((void*) file_data
->real_names
[i
]);
3205 file_data
->real_names
[i
] = NULL
;
3213 dw2_forget_cached_source_info (struct objfile
*objfile
)
3215 struct dwarf2_per_objfile
*dwarf2_per_objfile
3216 = get_dwarf2_per_objfile (objfile
);
3218 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
.get (),
3219 dw2_free_cached_file_names
, NULL
);
3222 /* Helper function for dw2_map_symtabs_matching_filename that expands
3223 the symtabs and calls the iterator. */
3226 dw2_map_expand_apply (struct objfile
*objfile
,
3227 struct dwarf2_per_cu_data
*per_cu
,
3228 const char *name
, const char *real_path
,
3229 gdb::function_view
<bool (symtab
*)> callback
)
3231 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3233 /* Don't visit already-expanded CUs. */
3234 if (per_cu
->v
.quick
->compunit_symtab
)
3237 /* This may expand more than one symtab, and we want to iterate over
3239 dw2_instantiate_symtab (per_cu
, false);
3241 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3242 last_made
, callback
);
3245 /* Implementation of the map_symtabs_matching_filename method. */
3248 dw2_map_symtabs_matching_filename
3249 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3250 gdb::function_view
<bool (symtab
*)> callback
)
3252 const char *name_basename
= lbasename (name
);
3253 struct dwarf2_per_objfile
*dwarf2_per_objfile
3254 = get_dwarf2_per_objfile (objfile
);
3256 /* The rule is CUs specify all the files, including those used by
3257 any TU, so there's no need to scan TUs here. */
3259 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3261 /* We only need to look at symtabs not already expanded. */
3262 if (per_cu
->v
.quick
->compunit_symtab
)
3265 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3266 if (file_data
== NULL
)
3269 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3271 const char *this_name
= file_data
->file_names
[j
];
3272 const char *this_real_name
;
3274 if (compare_filenames_for_search (this_name
, name
))
3276 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3282 /* Before we invoke realpath, which can get expensive when many
3283 files are involved, do a quick comparison of the basenames. */
3284 if (! basenames_may_differ
3285 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3288 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3289 if (compare_filenames_for_search (this_real_name
, name
))
3291 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3297 if (real_path
!= NULL
)
3299 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3300 gdb_assert (IS_ABSOLUTE_PATH (name
));
3301 if (this_real_name
!= NULL
3302 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3304 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3316 /* Struct used to manage iterating over all CUs looking for a symbol. */
3318 struct dw2_symtab_iterator
3320 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3321 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
3322 /* If set, only look for symbols that match that block. Valid values are
3323 GLOBAL_BLOCK and STATIC_BLOCK. */
3324 gdb::optional
<block_enum
> block_index
;
3325 /* The kind of symbol we're looking for. */
3327 /* The list of CUs from the index entry of the symbol,
3328 or NULL if not found. */
3330 /* The next element in VEC to look at. */
3332 /* The number of elements in VEC, or zero if there is no match. */
3334 /* Have we seen a global version of the symbol?
3335 If so we can ignore all further global instances.
3336 This is to work around gold/15646, inefficient gold-generated
3341 /* Initialize the index symtab iterator ITER. */
3344 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3345 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3346 gdb::optional
<block_enum
> block_index
,
3350 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3351 iter
->block_index
= block_index
;
3352 iter
->domain
= domain
;
3354 iter
->global_seen
= 0;
3356 mapped_index
*index
= dwarf2_per_objfile
->index_table
.get ();
3358 /* index is NULL if OBJF_READNOW. */
3359 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3360 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3368 /* Return the next matching CU or NULL if there are no more. */
3370 static struct dwarf2_per_cu_data
*
3371 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3373 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
3375 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3377 offset_type cu_index_and_attrs
=
3378 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3379 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3380 gdb_index_symbol_kind symbol_kind
=
3381 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3382 /* Only check the symbol attributes if they're present.
3383 Indices prior to version 7 don't record them,
3384 and indices >= 7 may elide them for certain symbols
3385 (gold does this). */
3387 (dwarf2_per_objfile
->index_table
->version
>= 7
3388 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3390 /* Don't crash on bad data. */
3391 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
3392 + dwarf2_per_objfile
->all_type_units
.size ()))
3394 complaint (_(".gdb_index entry has bad CU index"
3396 objfile_name (dwarf2_per_objfile
->objfile
));
3400 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
3402 /* Skip if already read in. */
3403 if (per_cu
->v
.quick
->compunit_symtab
)
3406 /* Check static vs global. */
3409 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3411 if (iter
->block_index
.has_value ())
3413 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3415 if (is_static
!= want_static
)
3419 /* Work around gold/15646. */
3420 if (!is_static
&& iter
->global_seen
)
3423 iter
->global_seen
= 1;
3426 /* Only check the symbol's kind if it has one. */
3429 switch (iter
->domain
)
3432 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3433 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3434 /* Some types are also in VAR_DOMAIN. */
3435 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3439 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3443 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3447 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3462 static struct compunit_symtab
*
3463 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
3464 const char *name
, domain_enum domain
)
3466 struct compunit_symtab
*stab_best
= NULL
;
3467 struct dwarf2_per_objfile
*dwarf2_per_objfile
3468 = get_dwarf2_per_objfile (objfile
);
3470 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
3472 struct dw2_symtab_iterator iter
;
3473 struct dwarf2_per_cu_data
*per_cu
;
3475 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, block_index
, domain
, name
);
3477 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3479 struct symbol
*sym
, *with_opaque
= NULL
;
3480 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
3481 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
3482 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3484 sym
= block_find_symbol (block
, name
, domain
,
3485 block_find_non_opaque_type_preferred
,
3488 /* Some caution must be observed with overloaded functions
3489 and methods, since the index will not contain any overload
3490 information (but NAME might contain it). */
3493 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
3495 if (with_opaque
!= NULL
3496 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
3499 /* Keep looking through other CUs. */
3506 dw2_print_stats (struct objfile
*objfile
)
3508 struct dwarf2_per_objfile
*dwarf2_per_objfile
3509 = get_dwarf2_per_objfile (objfile
);
3510 int total
= (dwarf2_per_objfile
->all_comp_units
.size ()
3511 + dwarf2_per_objfile
->all_type_units
.size ());
3514 for (int i
= 0; i
< total
; ++i
)
3516 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
3518 if (!per_cu
->v
.quick
->compunit_symtab
)
3521 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3522 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3525 /* This dumps minimal information about the index.
3526 It is called via "mt print objfiles".
3527 One use is to verify .gdb_index has been loaded by the
3528 gdb.dwarf2/gdb-index.exp testcase. */
3531 dw2_dump (struct objfile
*objfile
)
3533 struct dwarf2_per_objfile
*dwarf2_per_objfile
3534 = get_dwarf2_per_objfile (objfile
);
3536 gdb_assert (dwarf2_per_objfile
->using_index
);
3537 printf_filtered (".gdb_index:");
3538 if (dwarf2_per_objfile
->index_table
!= NULL
)
3540 printf_filtered (" version %d\n",
3541 dwarf2_per_objfile
->index_table
->version
);
3544 printf_filtered (" faked for \"readnow\"\n");
3545 printf_filtered ("\n");
3549 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3550 const char *func_name
)
3552 struct dwarf2_per_objfile
*dwarf2_per_objfile
3553 = get_dwarf2_per_objfile (objfile
);
3555 struct dw2_symtab_iterator iter
;
3556 struct dwarf2_per_cu_data
*per_cu
;
3558 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, {}, VAR_DOMAIN
, func_name
);
3560 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3561 dw2_instantiate_symtab (per_cu
, false);
3566 dw2_expand_all_symtabs (struct objfile
*objfile
)
3568 struct dwarf2_per_objfile
*dwarf2_per_objfile
3569 = get_dwarf2_per_objfile (objfile
);
3570 int total_units
= (dwarf2_per_objfile
->all_comp_units
.size ()
3571 + dwarf2_per_objfile
->all_type_units
.size ());
3573 for (int i
= 0; i
< total_units
; ++i
)
3575 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
3577 /* We don't want to directly expand a partial CU, because if we
3578 read it with the wrong language, then assertion failures can
3579 be triggered later on. See PR symtab/23010. So, tell
3580 dw2_instantiate_symtab to skip partial CUs -- any important
3581 partial CU will be read via DW_TAG_imported_unit anyway. */
3582 dw2_instantiate_symtab (per_cu
, true);
3587 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
3588 const char *fullname
)
3590 struct dwarf2_per_objfile
*dwarf2_per_objfile
3591 = get_dwarf2_per_objfile (objfile
);
3593 /* We don't need to consider type units here.
3594 This is only called for examining code, e.g. expand_line_sal.
3595 There can be an order of magnitude (or more) more type units
3596 than comp units, and we avoid them if we can. */
3598 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3600 /* We only need to look at symtabs not already expanded. */
3601 if (per_cu
->v
.quick
->compunit_symtab
)
3604 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3605 if (file_data
== NULL
)
3608 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3610 const char *this_fullname
= file_data
->file_names
[j
];
3612 if (filename_cmp (this_fullname
, fullname
) == 0)
3614 dw2_instantiate_symtab (per_cu
, false);
3622 dw2_map_matching_symbols
3623 (struct objfile
*objfile
,
3624 const lookup_name_info
&name
, domain_enum domain
,
3626 gdb::function_view
<symbol_found_callback_ftype
> callback
,
3627 symbol_compare_ftype
*ordered_compare
)
3630 struct dwarf2_per_objfile
*dwarf2_per_objfile
3631 = get_dwarf2_per_objfile (objfile
);
3633 if (dwarf2_per_objfile
->index_table
!= nullptr)
3635 /* Ada currently doesn't support .gdb_index (see PR24713). We can get
3636 here though if the current language is Ada for a non-Ada objfile
3637 using GNU index. As Ada does not look for non-Ada symbols this
3638 function should just return. */
3642 /* We have -readnow: no .gdb_index, but no partial symtabs either. So,
3643 inline psym_map_matching_symbols here, assuming all partial symtabs have
3645 const int block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
3647 for (compunit_symtab
*cust
: objfile
->compunits ())
3649 const struct block
*block
;
3653 block
= BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
3654 if (!iterate_over_symbols_terminated (block
, name
,
3660 /* Starting from a search name, return the string that finds the upper
3661 bound of all strings that start with SEARCH_NAME in a sorted name
3662 list. Returns the empty string to indicate that the upper bound is
3663 the end of the list. */
3666 make_sort_after_prefix_name (const char *search_name
)
3668 /* When looking to complete "func", we find the upper bound of all
3669 symbols that start with "func" by looking for where we'd insert
3670 the closest string that would follow "func" in lexicographical
3671 order. Usually, that's "func"-with-last-character-incremented,
3672 i.e. "fund". Mind non-ASCII characters, though. Usually those
3673 will be UTF-8 multi-byte sequences, but we can't be certain.
3674 Especially mind the 0xff character, which is a valid character in
3675 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3676 rule out compilers allowing it in identifiers. Note that
3677 conveniently, strcmp/strcasecmp are specified to compare
3678 characters interpreted as unsigned char. So what we do is treat
3679 the whole string as a base 256 number composed of a sequence of
3680 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3681 to 0, and carries 1 to the following more-significant position.
3682 If the very first character in SEARCH_NAME ends up incremented
3683 and carries/overflows, then the upper bound is the end of the
3684 list. The string after the empty string is also the empty
3687 Some examples of this operation:
3689 SEARCH_NAME => "+1" RESULT
3693 "\xff" "a" "\xff" => "\xff" "b"
3698 Then, with these symbols for example:
3704 completing "func" looks for symbols between "func" and
3705 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3706 which finds "func" and "func1", but not "fund".
3710 funcÿ (Latin1 'ÿ' [0xff])
3714 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3715 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3719 ÿÿ (Latin1 'ÿ' [0xff])
3722 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3723 the end of the list.
3725 std::string after
= search_name
;
3726 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3728 if (!after
.empty ())
3729 after
.back () = (unsigned char) after
.back () + 1;
3733 /* See declaration. */
3735 std::pair
<std::vector
<name_component
>::const_iterator
,
3736 std::vector
<name_component
>::const_iterator
>
3737 mapped_index_base::find_name_components_bounds
3738 (const lookup_name_info
&lookup_name_without_params
, language lang
) const
3741 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3743 const char *lang_name
3744 = lookup_name_without_params
.language_lookup_name (lang
);
3746 /* Comparison function object for lower_bound that matches against a
3747 given symbol name. */
3748 auto lookup_compare_lower
= [&] (const name_component
&elem
,
3751 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
3752 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3753 return name_cmp (elem_name
, name
) < 0;
3756 /* Comparison function object for upper_bound that matches against a
3757 given symbol name. */
3758 auto lookup_compare_upper
= [&] (const char *name
,
3759 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 (name
, elem_name
) < 0;
3766 auto begin
= this->name_components
.begin ();
3767 auto end
= this->name_components
.end ();
3769 /* Find the lower bound. */
3772 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3775 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
3778 /* Find the upper bound. */
3781 if (lookup_name_without_params
.completion_mode ())
3783 /* In completion mode, we want UPPER to point past all
3784 symbols names that have the same prefix. I.e., with
3785 these symbols, and completing "func":
3787 function << lower bound
3789 other_function << upper bound
3791 We find the upper bound by looking for the insertion
3792 point of "func"-with-last-character-incremented,
3794 std::string after
= make_sort_after_prefix_name (lang_name
);
3797 return std::lower_bound (lower
, end
, after
.c_str (),
3798 lookup_compare_lower
);
3801 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
3804 return {lower
, upper
};
3807 /* See declaration. */
3810 mapped_index_base::build_name_components ()
3812 if (!this->name_components
.empty ())
3815 this->name_components_casing
= case_sensitivity
;
3817 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3819 /* The code below only knows how to break apart components of C++
3820 symbol names (and other languages that use '::' as
3821 namespace/module separator) and Ada symbol names. */
3822 auto count
= this->symbol_name_count ();
3823 for (offset_type idx
= 0; idx
< count
; idx
++)
3825 if (this->symbol_name_slot_invalid (idx
))
3828 const char *name
= this->symbol_name_at (idx
);
3830 /* Add each name component to the name component table. */
3831 unsigned int previous_len
= 0;
3833 if (strstr (name
, "::") != nullptr)
3835 for (unsigned int current_len
= cp_find_first_component (name
);
3836 name
[current_len
] != '\0';
3837 current_len
+= cp_find_first_component (name
+ current_len
))
3839 gdb_assert (name
[current_len
] == ':');
3840 this->name_components
.push_back ({previous_len
, idx
});
3841 /* Skip the '::'. */
3843 previous_len
= current_len
;
3848 /* Handle the Ada encoded (aka mangled) form here. */
3849 for (const char *iter
= strstr (name
, "__");
3851 iter
= strstr (iter
, "__"))
3853 this->name_components
.push_back ({previous_len
, idx
});
3855 previous_len
= iter
- name
;
3859 this->name_components
.push_back ({previous_len
, idx
});
3862 /* Sort name_components elements by name. */
3863 auto name_comp_compare
= [&] (const name_component
&left
,
3864 const name_component
&right
)
3866 const char *left_qualified
= this->symbol_name_at (left
.idx
);
3867 const char *right_qualified
= this->symbol_name_at (right
.idx
);
3869 const char *left_name
= left_qualified
+ left
.name_offset
;
3870 const char *right_name
= right_qualified
+ right
.name_offset
;
3872 return name_cmp (left_name
, right_name
) < 0;
3875 std::sort (this->name_components
.begin (),
3876 this->name_components
.end (),
3880 /* Helper for dw2_expand_symtabs_matching that works with a
3881 mapped_index_base instead of the containing objfile. This is split
3882 to a separate function in order to be able to unit test the
3883 name_components matching using a mock mapped_index_base. For each
3884 symbol name that matches, calls MATCH_CALLBACK, passing it the
3885 symbol's index in the mapped_index_base symbol table. */
3888 dw2_expand_symtabs_matching_symbol
3889 (mapped_index_base
&index
,
3890 const lookup_name_info
&lookup_name_in
,
3891 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3892 enum search_domain kind
,
3893 gdb::function_view
<bool (offset_type
)> match_callback
)
3895 lookup_name_info lookup_name_without_params
3896 = lookup_name_in
.make_ignore_params ();
3898 /* Build the symbol name component sorted vector, if we haven't
3900 index
.build_name_components ();
3902 /* The same symbol may appear more than once in the range though.
3903 E.g., if we're looking for symbols that complete "w", and we have
3904 a symbol named "w1::w2", we'll find the two name components for
3905 that same symbol in the range. To be sure we only call the
3906 callback once per symbol, we first collect the symbol name
3907 indexes that matched in a temporary vector and ignore
3909 std::vector
<offset_type
> matches
;
3911 struct name_and_matcher
3913 symbol_name_matcher_ftype
*matcher
;
3914 const std::string
&name
;
3916 bool operator== (const name_and_matcher
&other
) const
3918 return matcher
== other
.matcher
&& name
== other
.name
;
3922 /* A vector holding all the different symbol name matchers, for all
3924 std::vector
<name_and_matcher
> matchers
;
3926 for (int i
= 0; i
< nr_languages
; i
++)
3928 enum language lang_e
= (enum language
) i
;
3930 const language_defn
*lang
= language_def (lang_e
);
3931 symbol_name_matcher_ftype
*name_matcher
3932 = get_symbol_name_matcher (lang
, lookup_name_without_params
);
3934 name_and_matcher key
{
3936 lookup_name_without_params
.language_lookup_name (lang_e
)
3939 /* Don't insert the same comparison routine more than once.
3940 Note that we do this linear walk. This is not a problem in
3941 practice because the number of supported languages is
3943 if (std::find (matchers
.begin (), matchers
.end (), key
)
3946 matchers
.push_back (std::move (key
));
3949 = index
.find_name_components_bounds (lookup_name_without_params
,
3952 /* Now for each symbol name in range, check to see if we have a name
3953 match, and if so, call the MATCH_CALLBACK callback. */
3955 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
3957 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
3959 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
3960 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
3963 matches
.push_back (bounds
.first
->idx
);
3967 std::sort (matches
.begin (), matches
.end ());
3969 /* Finally call the callback, once per match. */
3971 for (offset_type idx
: matches
)
3975 if (!match_callback (idx
))
3981 /* Above we use a type wider than idx's for 'prev', since 0 and
3982 (offset_type)-1 are both possible values. */
3983 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
3988 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
3990 /* A mock .gdb_index/.debug_names-like name index table, enough to
3991 exercise dw2_expand_symtabs_matching_symbol, which works with the
3992 mapped_index_base interface. Builds an index from the symbol list
3993 passed as parameter to the constructor. */
3994 class mock_mapped_index
: public mapped_index_base
3997 mock_mapped_index (gdb::array_view
<const char *> symbols
)
3998 : m_symbol_table (symbols
)
4001 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4003 /* Return the number of names in the symbol table. */
4004 size_t symbol_name_count () const override
4006 return m_symbol_table
.size ();
4009 /* Get the name of the symbol at IDX in the symbol table. */
4010 const char *symbol_name_at (offset_type idx
) const override
4012 return m_symbol_table
[idx
];
4016 gdb::array_view
<const char *> m_symbol_table
;
4019 /* Convenience function that converts a NULL pointer to a "<null>"
4020 string, to pass to print routines. */
4023 string_or_null (const char *str
)
4025 return str
!= NULL
? str
: "<null>";
4028 /* Check if a lookup_name_info built from
4029 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4030 index. EXPECTED_LIST is the list of expected matches, in expected
4031 matching order. If no match expected, then an empty list is
4032 specified. Returns true on success. On failure prints a warning
4033 indicating the file:line that failed, and returns false. */
4036 check_match (const char *file
, int line
,
4037 mock_mapped_index
&mock_index
,
4038 const char *name
, symbol_name_match_type match_type
,
4039 bool completion_mode
,
4040 std::initializer_list
<const char *> expected_list
)
4042 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4044 bool matched
= true;
4046 auto mismatch
= [&] (const char *expected_str
,
4049 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4050 "expected=\"%s\", got=\"%s\"\n"),
4052 (match_type
== symbol_name_match_type::FULL
4054 name
, string_or_null (expected_str
), string_or_null (got
));
4058 auto expected_it
= expected_list
.begin ();
4059 auto expected_end
= expected_list
.end ();
4061 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4063 [&] (offset_type idx
)
4065 const char *matched_name
= mock_index
.symbol_name_at (idx
);
4066 const char *expected_str
4067 = expected_it
== expected_end
? NULL
: *expected_it
++;
4069 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4070 mismatch (expected_str
, matched_name
);
4074 const char *expected_str
4075 = expected_it
== expected_end
? NULL
: *expected_it
++;
4076 if (expected_str
!= NULL
)
4077 mismatch (expected_str
, NULL
);
4082 /* The symbols added to the mock mapped_index for testing (in
4084 static const char *test_symbols
[] = {
4093 "ns2::tmpl<int>::foo2",
4094 "(anonymous namespace)::A::B::C",
4096 /* These are used to check that the increment-last-char in the
4097 matching algorithm for completion doesn't match "t1_fund" when
4098 completing "t1_func". */
4104 /* A UTF-8 name with multi-byte sequences to make sure that
4105 cp-name-parser understands this as a single identifier ("função"
4106 is "function" in PT). */
4109 /* \377 (0xff) is Latin1 'ÿ'. */
4112 /* \377 (0xff) is Latin1 'ÿ'. */
4116 /* A name with all sorts of complications. Starts with "z" to make
4117 it easier for the completion tests below. */
4118 #define Z_SYM_NAME \
4119 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4120 "::tuple<(anonymous namespace)::ui*, " \
4121 "std::default_delete<(anonymous namespace)::ui>, void>"
4126 /* Returns true if the mapped_index_base::find_name_component_bounds
4127 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4128 in completion mode. */
4131 check_find_bounds_finds (mapped_index_base
&index
,
4132 const char *search_name
,
4133 gdb::array_view
<const char *> expected_syms
)
4135 lookup_name_info
lookup_name (search_name
,
4136 symbol_name_match_type::FULL
, true);
4138 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4141 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4142 if (distance
!= expected_syms
.size ())
4145 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4147 auto nc_elem
= bounds
.first
+ exp_elem
;
4148 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
4149 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4156 /* Test the lower-level mapped_index::find_name_component_bounds
4160 test_mapped_index_find_name_component_bounds ()
4162 mock_mapped_index
mock_index (test_symbols
);
4164 mock_index
.build_name_components ();
4166 /* Test the lower-level mapped_index::find_name_component_bounds
4167 method in completion mode. */
4169 static const char *expected_syms
[] = {
4174 SELF_CHECK (check_find_bounds_finds (mock_index
,
4175 "t1_func", expected_syms
));
4178 /* Check that the increment-last-char in the name matching algorithm
4179 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4181 static const char *expected_syms1
[] = {
4185 SELF_CHECK (check_find_bounds_finds (mock_index
,
4186 "\377", expected_syms1
));
4188 static const char *expected_syms2
[] = {
4191 SELF_CHECK (check_find_bounds_finds (mock_index
,
4192 "\377\377", expected_syms2
));
4196 /* Test dw2_expand_symtabs_matching_symbol. */
4199 test_dw2_expand_symtabs_matching_symbol ()
4201 mock_mapped_index
mock_index (test_symbols
);
4203 /* We let all tests run until the end even if some fails, for debug
4205 bool any_mismatch
= false;
4207 /* Create the expected symbols list (an initializer_list). Needed
4208 because lists have commas, and we need to pass them to CHECK,
4209 which is a macro. */
4210 #define EXPECT(...) { __VA_ARGS__ }
4212 /* Wrapper for check_match that passes down the current
4213 __FILE__/__LINE__. */
4214 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4215 any_mismatch |= !check_match (__FILE__, __LINE__, \
4217 NAME, MATCH_TYPE, COMPLETION_MODE, \
4220 /* Identity checks. */
4221 for (const char *sym
: test_symbols
)
4223 /* Should be able to match all existing symbols. */
4224 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4227 /* Should be able to match all existing symbols with
4229 std::string with_params
= std::string (sym
) + "(int)";
4230 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4233 /* Should be able to match all existing symbols with
4234 parameters and qualifiers. */
4235 with_params
= std::string (sym
) + " ( int ) const";
4236 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4239 /* This should really find sym, but cp-name-parser.y doesn't
4240 know about lvalue/rvalue qualifiers yet. */
4241 with_params
= std::string (sym
) + " ( int ) &&";
4242 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4246 /* Check that the name matching algorithm for completion doesn't get
4247 confused with Latin1 'ÿ' / 0xff. */
4249 static const char str
[] = "\377";
4250 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4251 EXPECT ("\377", "\377\377123"));
4254 /* Check that the increment-last-char in the matching algorithm for
4255 completion doesn't match "t1_fund" when completing "t1_func". */
4257 static const char str
[] = "t1_func";
4258 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4259 EXPECT ("t1_func", "t1_func1"));
4262 /* Check that completion mode works at each prefix of the expected
4265 static const char str
[] = "function(int)";
4266 size_t len
= strlen (str
);
4269 for (size_t i
= 1; i
< len
; i
++)
4271 lookup
.assign (str
, i
);
4272 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4273 EXPECT ("function"));
4277 /* While "w" is a prefix of both components, the match function
4278 should still only be called once. */
4280 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4282 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4286 /* Same, with a "complicated" symbol. */
4288 static const char str
[] = Z_SYM_NAME
;
4289 size_t len
= strlen (str
);
4292 for (size_t i
= 1; i
< len
; i
++)
4294 lookup
.assign (str
, i
);
4295 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4296 EXPECT (Z_SYM_NAME
));
4300 /* In FULL mode, an incomplete symbol doesn't match. */
4302 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4306 /* A complete symbol with parameters matches any overload, since the
4307 index has no overload info. */
4309 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4310 EXPECT ("std::zfunction", "std::zfunction2"));
4311 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4312 EXPECT ("std::zfunction", "std::zfunction2"));
4313 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4314 EXPECT ("std::zfunction", "std::zfunction2"));
4317 /* Check that whitespace is ignored appropriately. A symbol with a
4318 template argument list. */
4320 static const char expected
[] = "ns::foo<int>";
4321 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4323 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4327 /* Check that whitespace is ignored appropriately. A symbol with a
4328 template argument list that includes a pointer. */
4330 static const char expected
[] = "ns::foo<char*>";
4331 /* Try both completion and non-completion modes. */
4332 static const bool completion_mode
[2] = {false, true};
4333 for (size_t i
= 0; i
< 2; i
++)
4335 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4336 completion_mode
[i
], EXPECT (expected
));
4337 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4338 completion_mode
[i
], EXPECT (expected
));
4340 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4341 completion_mode
[i
], EXPECT (expected
));
4342 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4343 completion_mode
[i
], EXPECT (expected
));
4348 /* Check method qualifiers are ignored. */
4349 static const char expected
[] = "ns::foo<char*>";
4350 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4351 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4352 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4353 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4354 CHECK_MATCH ("foo < char * > ( int ) const",
4355 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4356 CHECK_MATCH ("foo < char * > ( int ) &&",
4357 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4360 /* Test lookup names that don't match anything. */
4362 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4365 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4369 /* Some wild matching tests, exercising "(anonymous namespace)",
4370 which should not be confused with a parameter list. */
4372 static const char *syms
[] = {
4376 "A :: B :: C ( int )",
4381 for (const char *s
: syms
)
4383 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4384 EXPECT ("(anonymous namespace)::A::B::C"));
4389 static const char expected
[] = "ns2::tmpl<int>::foo2";
4390 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4392 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4396 SELF_CHECK (!any_mismatch
);
4405 test_mapped_index_find_name_component_bounds ();
4406 test_dw2_expand_symtabs_matching_symbol ();
4409 }} // namespace selftests::dw2_expand_symtabs_matching
4411 #endif /* GDB_SELF_TEST */
4413 /* If FILE_MATCHER is NULL or if PER_CU has
4414 dwarf2_per_cu_quick_data::MARK set (see
4415 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4416 EXPANSION_NOTIFY on it. */
4419 dw2_expand_symtabs_matching_one
4420 (struct dwarf2_per_cu_data
*per_cu
,
4421 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4422 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4424 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4426 bool symtab_was_null
4427 = (per_cu
->v
.quick
->compunit_symtab
== NULL
);
4429 dw2_instantiate_symtab (per_cu
, false);
4431 if (expansion_notify
!= NULL
4433 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
4434 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
4438 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4439 matched, to expand corresponding CUs that were marked. IDX is the
4440 index of the symbol name that matched. */
4443 dw2_expand_marked_cus
4444 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
4445 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4446 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4449 offset_type
*vec
, vec_len
, vec_idx
;
4450 bool global_seen
= false;
4451 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
4453 vec
= (offset_type
*) (index
.constant_pool
4454 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
4455 vec_len
= MAYBE_SWAP (vec
[0]);
4456 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4458 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
4459 /* This value is only valid for index versions >= 7. */
4460 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4461 gdb_index_symbol_kind symbol_kind
=
4462 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4463 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4464 /* Only check the symbol attributes if they're present.
4465 Indices prior to version 7 don't record them,
4466 and indices >= 7 may elide them for certain symbols
4467 (gold does this). */
4470 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4472 /* Work around gold/15646. */
4475 if (!is_static
&& global_seen
)
4481 /* Only check the symbol's kind if it has one. */
4486 case VARIABLES_DOMAIN
:
4487 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4490 case FUNCTIONS_DOMAIN
:
4491 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4495 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4498 case MODULES_DOMAIN
:
4499 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4507 /* Don't crash on bad data. */
4508 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
4509 + dwarf2_per_objfile
->all_type_units
.size ()))
4511 complaint (_(".gdb_index entry has bad CU index"
4513 objfile_name (dwarf2_per_objfile
->objfile
));
4517 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
4518 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
4523 /* If FILE_MATCHER is non-NULL, set all the
4524 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4525 that match FILE_MATCHER. */
4528 dw_expand_symtabs_matching_file_matcher
4529 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4530 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4532 if (file_matcher
== NULL
)
4535 objfile
*const objfile
= dwarf2_per_objfile
->objfile
;
4537 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4539 NULL
, xcalloc
, xfree
));
4540 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4542 NULL
, xcalloc
, xfree
));
4544 /* The rule is CUs specify all the files, including those used by
4545 any TU, so there's no need to scan TUs here. */
4547 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4551 per_cu
->v
.quick
->mark
= 0;
4553 /* We only need to look at symtabs not already expanded. */
4554 if (per_cu
->v
.quick
->compunit_symtab
)
4557 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4558 if (file_data
== NULL
)
4561 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4563 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4565 per_cu
->v
.quick
->mark
= 1;
4569 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4571 const char *this_real_name
;
4573 if (file_matcher (file_data
->file_names
[j
], false))
4575 per_cu
->v
.quick
->mark
= 1;
4579 /* Before we invoke realpath, which can get expensive when many
4580 files are involved, do a quick comparison of the basenames. */
4581 if (!basenames_may_differ
4582 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4586 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
4587 if (file_matcher (this_real_name
, false))
4589 per_cu
->v
.quick
->mark
= 1;
4594 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4595 ? visited_found
.get ()
4596 : visited_not_found
.get (),
4603 dw2_expand_symtabs_matching
4604 (struct objfile
*objfile
,
4605 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4606 const lookup_name_info
*lookup_name
,
4607 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4608 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4609 enum search_domain kind
)
4611 struct dwarf2_per_objfile
*dwarf2_per_objfile
4612 = get_dwarf2_per_objfile (objfile
);
4614 /* index_table is NULL if OBJF_READNOW. */
4615 if (!dwarf2_per_objfile
->index_table
)
4618 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
4620 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
4622 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4626 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
4632 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
4634 dw2_expand_symtabs_matching_symbol (index
, *lookup_name
,
4636 kind
, [&] (offset_type idx
)
4638 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
4639 expansion_notify
, kind
);
4644 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4647 static struct compunit_symtab
*
4648 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4653 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4654 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4657 if (cust
->includes
== NULL
)
4660 for (i
= 0; cust
->includes
[i
]; ++i
)
4662 struct compunit_symtab
*s
= cust
->includes
[i
];
4664 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4672 static struct compunit_symtab
*
4673 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
4674 struct bound_minimal_symbol msymbol
,
4676 struct obj_section
*section
,
4679 struct dwarf2_per_cu_data
*data
;
4680 struct compunit_symtab
*result
;
4682 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
4685 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4686 data
= (struct dwarf2_per_cu_data
*) addrmap_find
4687 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
4691 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
4692 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4693 paddress (get_objfile_arch (objfile
), pc
));
4696 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
,
4699 gdb_assert (result
!= NULL
);
4704 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
4705 void *data
, int need_fullname
)
4707 struct dwarf2_per_objfile
*dwarf2_per_objfile
4708 = get_dwarf2_per_objfile (objfile
);
4710 if (!dwarf2_per_objfile
->filenames_cache
)
4712 dwarf2_per_objfile
->filenames_cache
.emplace ();
4714 htab_up
visited (htab_create_alloc (10,
4715 htab_hash_pointer
, htab_eq_pointer
,
4716 NULL
, xcalloc
, xfree
));
4718 /* The rule is CUs specify all the files, including those used
4719 by any TU, so there's no need to scan TUs here. We can
4720 ignore file names coming from already-expanded CUs. */
4722 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4724 if (per_cu
->v
.quick
->compunit_symtab
)
4726 void **slot
= htab_find_slot (visited
.get (),
4727 per_cu
->v
.quick
->file_names
,
4730 *slot
= per_cu
->v
.quick
->file_names
;
4734 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4736 /* We only need to look at symtabs not already expanded. */
4737 if (per_cu
->v
.quick
->compunit_symtab
)
4740 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4741 if (file_data
== NULL
)
4744 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
4747 /* Already visited. */
4752 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4754 const char *filename
= file_data
->file_names
[j
];
4755 dwarf2_per_objfile
->filenames_cache
->seen (filename
);
4760 dwarf2_per_objfile
->filenames_cache
->traverse ([&] (const char *filename
)
4762 gdb::unique_xmalloc_ptr
<char> this_real_name
;
4765 this_real_name
= gdb_realpath (filename
);
4766 (*fun
) (filename
, this_real_name
.get (), data
);
4771 dw2_has_symbols (struct objfile
*objfile
)
4776 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
4779 dw2_find_last_source_symtab
,
4780 dw2_forget_cached_source_info
,
4781 dw2_map_symtabs_matching_filename
,
4786 dw2_expand_symtabs_for_function
,
4787 dw2_expand_all_symtabs
,
4788 dw2_expand_symtabs_with_fullname
,
4789 dw2_map_matching_symbols
,
4790 dw2_expand_symtabs_matching
,
4791 dw2_find_pc_sect_compunit_symtab
,
4793 dw2_map_symbol_filenames
4796 /* DWARF-5 debug_names reader. */
4798 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
4799 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
4801 /* A helper function that reads the .debug_names section in SECTION
4802 and fills in MAP. FILENAME is the name of the file containing the
4803 section; it is used for error reporting.
4805 Returns true if all went well, false otherwise. */
4808 read_debug_names_from_section (struct objfile
*objfile
,
4809 const char *filename
,
4810 struct dwarf2_section_info
*section
,
4811 mapped_debug_names
&map
)
4813 if (section
->empty ())
4816 /* Older elfutils strip versions could keep the section in the main
4817 executable while splitting it for the separate debug info file. */
4818 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
4821 section
->read (objfile
);
4823 map
.dwarf5_byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
4825 const gdb_byte
*addr
= section
->buffer
;
4827 bfd
*const abfd
= section
->get_bfd_owner ();
4829 unsigned int bytes_read
;
4830 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
4833 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
4834 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
4835 if (bytes_read
+ length
!= section
->size
)
4837 /* There may be multiple per-CU indices. */
4838 warning (_("Section .debug_names in %s length %s does not match "
4839 "section length %s, ignoring .debug_names."),
4840 filename
, plongest (bytes_read
+ length
),
4841 pulongest (section
->size
));
4845 /* The version number. */
4846 uint16_t version
= read_2_bytes (abfd
, addr
);
4850 warning (_("Section .debug_names in %s has unsupported version %d, "
4851 "ignoring .debug_names."),
4857 uint16_t padding
= read_2_bytes (abfd
, addr
);
4861 warning (_("Section .debug_names in %s has unsupported padding %d, "
4862 "ignoring .debug_names."),
4867 /* comp_unit_count - The number of CUs in the CU list. */
4868 map
.cu_count
= read_4_bytes (abfd
, addr
);
4871 /* local_type_unit_count - The number of TUs in the local TU
4873 map
.tu_count
= read_4_bytes (abfd
, addr
);
4876 /* foreign_type_unit_count - The number of TUs in the foreign TU
4878 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
4880 if (foreign_tu_count
!= 0)
4882 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
4883 "ignoring .debug_names."),
4884 filename
, static_cast<unsigned long> (foreign_tu_count
));
4888 /* bucket_count - The number of hash buckets in the hash lookup
4890 map
.bucket_count
= read_4_bytes (abfd
, addr
);
4893 /* name_count - The number of unique names in the index. */
4894 map
.name_count
= read_4_bytes (abfd
, addr
);
4897 /* abbrev_table_size - The size in bytes of the abbreviations
4899 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
4902 /* augmentation_string_size - The size in bytes of the augmentation
4903 string. This value is rounded up to a multiple of 4. */
4904 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
4906 map
.augmentation_is_gdb
= ((augmentation_string_size
4907 == sizeof (dwarf5_augmentation
))
4908 && memcmp (addr
, dwarf5_augmentation
,
4909 sizeof (dwarf5_augmentation
)) == 0);
4910 augmentation_string_size
+= (-augmentation_string_size
) & 3;
4911 addr
+= augmentation_string_size
;
4914 map
.cu_table_reordered
= addr
;
4915 addr
+= map
.cu_count
* map
.offset_size
;
4917 /* List of Local TUs */
4918 map
.tu_table_reordered
= addr
;
4919 addr
+= map
.tu_count
* map
.offset_size
;
4921 /* Hash Lookup Table */
4922 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4923 addr
+= map
.bucket_count
* 4;
4924 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4925 addr
+= map
.name_count
* 4;
4928 map
.name_table_string_offs_reordered
= addr
;
4929 addr
+= map
.name_count
* map
.offset_size
;
4930 map
.name_table_entry_offs_reordered
= addr
;
4931 addr
+= map
.name_count
* map
.offset_size
;
4933 const gdb_byte
*abbrev_table_start
= addr
;
4936 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4941 const auto insertpair
4942 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
4943 if (!insertpair
.second
)
4945 warning (_("Section .debug_names in %s has duplicate index %s, "
4946 "ignoring .debug_names."),
4947 filename
, pulongest (index_num
));
4950 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
4951 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4956 mapped_debug_names::index_val::attr attr
;
4957 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4959 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4961 if (attr
.form
== DW_FORM_implicit_const
)
4963 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
4967 if (attr
.dw_idx
== 0 && attr
.form
== 0)
4969 indexval
.attr_vec
.push_back (std::move (attr
));
4972 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
4974 warning (_("Section .debug_names in %s has abbreviation_table "
4975 "of size %s vs. written as %u, ignoring .debug_names."),
4976 filename
, plongest (addr
- abbrev_table_start
),
4980 map
.entry_pool
= addr
;
4985 /* A helper for create_cus_from_debug_names that handles the MAP's CU
4989 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4990 const mapped_debug_names
&map
,
4991 dwarf2_section_info
§ion
,
4994 sect_offset sect_off_prev
;
4995 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
4997 sect_offset sect_off_next
;
4998 if (i
< map
.cu_count
)
5001 = (sect_offset
) (extract_unsigned_integer
5002 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5004 map
.dwarf5_byte_order
));
5007 sect_off_next
= (sect_offset
) section
.size
;
5010 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5011 dwarf2_per_cu_data
*per_cu
5012 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
5013 sect_off_prev
, length
);
5014 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
5016 sect_off_prev
= sect_off_next
;
5020 /* Read the CU list from the mapped index, and use it to create all
5021 the CU objects for this dwarf2_per_objfile. */
5024 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5025 const mapped_debug_names
&map
,
5026 const mapped_debug_names
&dwz_map
)
5028 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
5029 dwarf2_per_objfile
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5031 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
5032 dwarf2_per_objfile
->info
,
5033 false /* is_dwz */);
5035 if (dwz_map
.cu_count
== 0)
5038 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5039 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
5043 /* Read .debug_names. If everything went ok, initialize the "quick"
5044 elements of all the CUs and return true. Otherwise, return false. */
5047 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
5049 std::unique_ptr
<mapped_debug_names
> map
5050 (new mapped_debug_names (dwarf2_per_objfile
));
5051 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
5052 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5054 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5055 &dwarf2_per_objfile
->debug_names
,
5059 /* Don't use the index if it's empty. */
5060 if (map
->name_count
== 0)
5063 /* If there is a .dwz file, read it so we can get its CU list as
5065 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5068 if (!read_debug_names_from_section (objfile
,
5069 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5070 &dwz
->debug_names
, dwz_map
))
5072 warning (_("could not read '.debug_names' section from %s; skipping"),
5073 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5078 create_cus_from_debug_names (dwarf2_per_objfile
, *map
, dwz_map
);
5080 if (map
->tu_count
!= 0)
5082 /* We can only handle a single .debug_types when we have an
5084 if (dwarf2_per_objfile
->types
.size () != 1)
5087 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
5089 create_signatured_type_table_from_debug_names
5090 (dwarf2_per_objfile
, *map
, section
, &dwarf2_per_objfile
->abbrev
);
5093 create_addrmap_from_aranges (dwarf2_per_objfile
,
5094 &dwarf2_per_objfile
->debug_aranges
);
5096 dwarf2_per_objfile
->debug_names_table
= std::move (map
);
5097 dwarf2_per_objfile
->using_index
= 1;
5098 dwarf2_per_objfile
->quick_file_names_table
=
5099 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
5104 /* Type used to manage iterating over all CUs looking for a symbol for
5107 class dw2_debug_names_iterator
5110 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5111 gdb::optional
<block_enum
> block_index
,
5114 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5115 m_addr (find_vec_in_debug_names (map
, name
))
5118 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5119 search_domain search
, uint32_t namei
)
5122 m_addr (find_vec_in_debug_names (map
, namei
))
5125 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5126 block_enum block_index
, domain_enum domain
,
5128 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5129 m_addr (find_vec_in_debug_names (map
, namei
))
5132 /* Return the next matching CU or NULL if there are no more. */
5133 dwarf2_per_cu_data
*next ();
5136 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5138 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5141 /* The internalized form of .debug_names. */
5142 const mapped_debug_names
&m_map
;
5144 /* If set, only look for symbols that match that block. Valid values are
5145 GLOBAL_BLOCK and STATIC_BLOCK. */
5146 const gdb::optional
<block_enum
> m_block_index
;
5148 /* The kind of symbol we're looking for. */
5149 const domain_enum m_domain
= UNDEF_DOMAIN
;
5150 const search_domain m_search
= ALL_DOMAIN
;
5152 /* The list of CUs from the index entry of the symbol, or NULL if
5154 const gdb_byte
*m_addr
;
5158 mapped_debug_names::namei_to_name (uint32_t namei
) const
5160 const ULONGEST namei_string_offs
5161 = extract_unsigned_integer ((name_table_string_offs_reordered
5162 + namei
* offset_size
),
5165 return read_indirect_string_at_offset (dwarf2_per_objfile
,
5169 /* Find a slot in .debug_names for the object named NAME. If NAME is
5170 found, return pointer to its pool data. If NAME cannot be found,
5174 dw2_debug_names_iterator::find_vec_in_debug_names
5175 (const mapped_debug_names
&map
, const char *name
)
5177 int (*cmp
) (const char *, const char *);
5179 gdb::unique_xmalloc_ptr
<char> without_params
;
5180 if (current_language
->la_language
== language_cplus
5181 || current_language
->la_language
== language_fortran
5182 || current_language
->la_language
== language_d
)
5184 /* NAME is already canonical. Drop any qualifiers as
5185 .debug_names does not contain any. */
5187 if (strchr (name
, '(') != NULL
)
5189 without_params
= cp_remove_params (name
);
5190 if (without_params
!= NULL
)
5191 name
= without_params
.get ();
5195 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5197 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5199 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5200 (map
.bucket_table_reordered
5201 + (full_hash
% map
.bucket_count
)), 4,
5202 map
.dwarf5_byte_order
);
5206 if (namei
>= map
.name_count
)
5208 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5210 namei
, map
.name_count
,
5211 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5217 const uint32_t namei_full_hash
5218 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5219 (map
.hash_table_reordered
+ namei
), 4,
5220 map
.dwarf5_byte_order
);
5221 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5224 if (full_hash
== namei_full_hash
)
5226 const char *const namei_string
= map
.namei_to_name (namei
);
5228 #if 0 /* An expensive sanity check. */
5229 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5231 complaint (_("Wrong .debug_names hash for string at index %u "
5233 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5238 if (cmp (namei_string
, name
) == 0)
5240 const ULONGEST namei_entry_offs
5241 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5242 + namei
* map
.offset_size
),
5243 map
.offset_size
, map
.dwarf5_byte_order
);
5244 return map
.entry_pool
+ namei_entry_offs
;
5249 if (namei
>= map
.name_count
)
5255 dw2_debug_names_iterator::find_vec_in_debug_names
5256 (const mapped_debug_names
&map
, uint32_t namei
)
5258 if (namei
>= map
.name_count
)
5260 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5262 namei
, map
.name_count
,
5263 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5267 const ULONGEST namei_entry_offs
5268 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5269 + namei
* map
.offset_size
),
5270 map
.offset_size
, map
.dwarf5_byte_order
);
5271 return map
.entry_pool
+ namei_entry_offs
;
5274 /* See dw2_debug_names_iterator. */
5276 dwarf2_per_cu_data
*
5277 dw2_debug_names_iterator::next ()
5282 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
5283 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5284 bfd
*const abfd
= objfile
->obfd
;
5288 unsigned int bytes_read
;
5289 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5290 m_addr
+= bytes_read
;
5294 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5295 if (indexval_it
== m_map
.abbrev_map
.cend ())
5297 complaint (_("Wrong .debug_names undefined abbrev code %s "
5299 pulongest (abbrev
), objfile_name (objfile
));
5302 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5303 enum class symbol_linkage
{
5307 } symbol_linkage_
= symbol_linkage::unknown
;
5308 dwarf2_per_cu_data
*per_cu
= NULL
;
5309 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5314 case DW_FORM_implicit_const
:
5315 ull
= attr
.implicit_const
;
5317 case DW_FORM_flag_present
:
5321 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5322 m_addr
+= bytes_read
;
5325 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5326 dwarf_form_name (attr
.form
),
5327 objfile_name (objfile
));
5330 switch (attr
.dw_idx
)
5332 case DW_IDX_compile_unit
:
5333 /* Don't crash on bad data. */
5334 if (ull
>= dwarf2_per_objfile
->all_comp_units
.size ())
5336 complaint (_(".debug_names entry has bad CU index %s"
5339 objfile_name (dwarf2_per_objfile
->objfile
));
5342 per_cu
= dwarf2_per_objfile
->get_cutu (ull
);
5344 case DW_IDX_type_unit
:
5345 /* Don't crash on bad data. */
5346 if (ull
>= dwarf2_per_objfile
->all_type_units
.size ())
5348 complaint (_(".debug_names entry has bad TU index %s"
5351 objfile_name (dwarf2_per_objfile
->objfile
));
5354 per_cu
= &dwarf2_per_objfile
->get_tu (ull
)->per_cu
;
5356 case DW_IDX_GNU_internal
:
5357 if (!m_map
.augmentation_is_gdb
)
5359 symbol_linkage_
= symbol_linkage::static_
;
5361 case DW_IDX_GNU_external
:
5362 if (!m_map
.augmentation_is_gdb
)
5364 symbol_linkage_
= symbol_linkage::extern_
;
5369 /* Skip if already read in. */
5370 if (per_cu
->v
.quick
->compunit_symtab
)
5373 /* Check static vs global. */
5374 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5376 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5377 const bool symbol_is_static
=
5378 symbol_linkage_
== symbol_linkage::static_
;
5379 if (want_static
!= symbol_is_static
)
5383 /* Match dw2_symtab_iter_next, symbol_kind
5384 and debug_names::psymbol_tag. */
5388 switch (indexval
.dwarf_tag
)
5390 case DW_TAG_variable
:
5391 case DW_TAG_subprogram
:
5392 /* Some types are also in VAR_DOMAIN. */
5393 case DW_TAG_typedef
:
5394 case DW_TAG_structure_type
:
5401 switch (indexval
.dwarf_tag
)
5403 case DW_TAG_typedef
:
5404 case DW_TAG_structure_type
:
5411 switch (indexval
.dwarf_tag
)
5414 case DW_TAG_variable
:
5421 switch (indexval
.dwarf_tag
)
5433 /* Match dw2_expand_symtabs_matching, symbol_kind and
5434 debug_names::psymbol_tag. */
5437 case VARIABLES_DOMAIN
:
5438 switch (indexval
.dwarf_tag
)
5440 case DW_TAG_variable
:
5446 case FUNCTIONS_DOMAIN
:
5447 switch (indexval
.dwarf_tag
)
5449 case DW_TAG_subprogram
:
5456 switch (indexval
.dwarf_tag
)
5458 case DW_TAG_typedef
:
5459 case DW_TAG_structure_type
:
5465 case MODULES_DOMAIN
:
5466 switch (indexval
.dwarf_tag
)
5480 static struct compunit_symtab
*
5481 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
5482 const char *name
, domain_enum domain
)
5484 struct dwarf2_per_objfile
*dwarf2_per_objfile
5485 = get_dwarf2_per_objfile (objfile
);
5487 const auto &mapp
= dwarf2_per_objfile
->debug_names_table
;
5490 /* index is NULL if OBJF_READNOW. */
5493 const auto &map
= *mapp
;
5495 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
);
5497 struct compunit_symtab
*stab_best
= NULL
;
5498 struct dwarf2_per_cu_data
*per_cu
;
5499 while ((per_cu
= iter
.next ()) != NULL
)
5501 struct symbol
*sym
, *with_opaque
= NULL
;
5502 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
5503 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
5504 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
5506 sym
= block_find_symbol (block
, name
, domain
,
5507 block_find_non_opaque_type_preferred
,
5510 /* Some caution must be observed with overloaded functions and
5511 methods, since the index will not contain any overload
5512 information (but NAME might contain it). */
5515 && strcmp_iw (sym
->search_name (), name
) == 0)
5517 if (with_opaque
!= NULL
5518 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
5521 /* Keep looking through other CUs. */
5527 /* This dumps minimal information about .debug_names. It is called
5528 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5529 uses this to verify that .debug_names has been loaded. */
5532 dw2_debug_names_dump (struct objfile
*objfile
)
5534 struct dwarf2_per_objfile
*dwarf2_per_objfile
5535 = get_dwarf2_per_objfile (objfile
);
5537 gdb_assert (dwarf2_per_objfile
->using_index
);
5538 printf_filtered (".debug_names:");
5539 if (dwarf2_per_objfile
->debug_names_table
)
5540 printf_filtered (" exists\n");
5542 printf_filtered (" faked for \"readnow\"\n");
5543 printf_filtered ("\n");
5547 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
5548 const char *func_name
)
5550 struct dwarf2_per_objfile
*dwarf2_per_objfile
5551 = get_dwarf2_per_objfile (objfile
);
5553 /* dwarf2_per_objfile->debug_names_table is NULL if OBJF_READNOW. */
5554 if (dwarf2_per_objfile
->debug_names_table
)
5556 const mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5558 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
);
5560 struct dwarf2_per_cu_data
*per_cu
;
5561 while ((per_cu
= iter
.next ()) != NULL
)
5562 dw2_instantiate_symtab (per_cu
, false);
5567 dw2_debug_names_map_matching_symbols
5568 (struct objfile
*objfile
,
5569 const lookup_name_info
&name
, domain_enum domain
,
5571 gdb::function_view
<symbol_found_callback_ftype
> callback
,
5572 symbol_compare_ftype
*ordered_compare
)
5574 struct dwarf2_per_objfile
*dwarf2_per_objfile
5575 = get_dwarf2_per_objfile (objfile
);
5577 /* debug_names_table is NULL if OBJF_READNOW. */
5578 if (!dwarf2_per_objfile
->debug_names_table
)
5581 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5582 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
5584 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5585 auto matcher
= [&] (const char *symname
)
5587 if (ordered_compare
== nullptr)
5589 return ordered_compare (symname
, match_name
) == 0;
5592 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
5593 [&] (offset_type namei
)
5595 /* The name was matched, now expand corresponding CUs that were
5597 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
);
5599 struct dwarf2_per_cu_data
*per_cu
;
5600 while ((per_cu
= iter
.next ()) != NULL
)
5601 dw2_expand_symtabs_matching_one (per_cu
, nullptr, nullptr);
5605 /* It's a shame we couldn't do this inside the
5606 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
5607 that have already been expanded. Instead, this loop matches what
5608 the psymtab code does. */
5609 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5611 struct compunit_symtab
*cust
= per_cu
->v
.quick
->compunit_symtab
;
5612 if (cust
!= nullptr)
5614 const struct block
*block
5615 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
5616 if (!iterate_over_symbols_terminated (block
, name
,
5624 dw2_debug_names_expand_symtabs_matching
5625 (struct objfile
*objfile
,
5626 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5627 const lookup_name_info
*lookup_name
,
5628 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5629 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5630 enum search_domain kind
)
5632 struct dwarf2_per_objfile
*dwarf2_per_objfile
5633 = get_dwarf2_per_objfile (objfile
);
5635 /* debug_names_table is NULL if OBJF_READNOW. */
5636 if (!dwarf2_per_objfile
->debug_names_table
)
5639 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5641 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
5643 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5647 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5653 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5655 dw2_expand_symtabs_matching_symbol (map
, *lookup_name
,
5657 kind
, [&] (offset_type namei
)
5659 /* The name was matched, now expand corresponding CUs that were
5661 dw2_debug_names_iterator
iter (map
, kind
, namei
);
5663 struct dwarf2_per_cu_data
*per_cu
;
5664 while ((per_cu
= iter
.next ()) != NULL
)
5665 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5671 const struct quick_symbol_functions dwarf2_debug_names_functions
=
5674 dw2_find_last_source_symtab
,
5675 dw2_forget_cached_source_info
,
5676 dw2_map_symtabs_matching_filename
,
5677 dw2_debug_names_lookup_symbol
,
5680 dw2_debug_names_dump
,
5681 dw2_debug_names_expand_symtabs_for_function
,
5682 dw2_expand_all_symtabs
,
5683 dw2_expand_symtabs_with_fullname
,
5684 dw2_debug_names_map_matching_symbols
,
5685 dw2_debug_names_expand_symtabs_matching
,
5686 dw2_find_pc_sect_compunit_symtab
,
5688 dw2_map_symbol_filenames
5691 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5692 to either a dwarf2_per_objfile or dwz_file object. */
5694 template <typename T
>
5695 static gdb::array_view
<const gdb_byte
>
5696 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5698 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5700 if (section
->empty ())
5703 /* Older elfutils strip versions could keep the section in the main
5704 executable while splitting it for the separate debug info file. */
5705 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5708 section
->read (obj
);
5710 /* dwarf2_section_info::size is a bfd_size_type, while
5711 gdb::array_view works with size_t. On 32-bit hosts, with
5712 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5713 is 32-bit. So we need an explicit narrowing conversion here.
5714 This is fine, because it's impossible to allocate or mmap an
5715 array/buffer larger than what size_t can represent. */
5716 return gdb::make_array_view (section
->buffer
, section
->size
);
5719 /* Lookup the index cache for the contents of the index associated to
5722 static gdb::array_view
<const gdb_byte
>
5723 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_objfile
*dwarf2_obj
)
5725 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5726 if (build_id
== nullptr)
5729 return global_index_cache
.lookup_gdb_index (build_id
,
5730 &dwarf2_obj
->index_cache_res
);
5733 /* Same as the above, but for DWZ. */
5735 static gdb::array_view
<const gdb_byte
>
5736 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5738 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5739 if (build_id
== nullptr)
5742 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5745 /* See symfile.h. */
5748 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
5750 struct dwarf2_per_objfile
*dwarf2_per_objfile
5751 = get_dwarf2_per_objfile (objfile
);
5753 /* If we're about to read full symbols, don't bother with the
5754 indices. In this case we also don't care if some other debug
5755 format is making psymtabs, because they are all about to be
5757 if ((objfile
->flags
& OBJF_READNOW
))
5759 dwarf2_per_objfile
->using_index
= 1;
5760 create_all_comp_units (dwarf2_per_objfile
);
5761 create_all_type_units (dwarf2_per_objfile
);
5762 dwarf2_per_objfile
->quick_file_names_table
5763 = create_quick_file_names_table
5764 (dwarf2_per_objfile
->all_comp_units
.size ());
5766 for (int i
= 0; i
< (dwarf2_per_objfile
->all_comp_units
.size ()
5767 + dwarf2_per_objfile
->all_type_units
.size ()); ++i
)
5769 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
5771 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5772 struct dwarf2_per_cu_quick_data
);
5775 /* Return 1 so that gdb sees the "quick" functions. However,
5776 these functions will be no-ops because we will have expanded
5778 *index_kind
= dw_index_kind::GDB_INDEX
;
5782 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
5784 *index_kind
= dw_index_kind::DEBUG_NAMES
;
5788 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5789 get_gdb_index_contents_from_section
<struct dwarf2_per_objfile
>,
5790 get_gdb_index_contents_from_section
<dwz_file
>))
5792 *index_kind
= dw_index_kind::GDB_INDEX
;
5796 /* ... otherwise, try to find the index in the index cache. */
5797 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5798 get_gdb_index_contents_from_cache
,
5799 get_gdb_index_contents_from_cache_dwz
))
5801 global_index_cache
.hit ();
5802 *index_kind
= dw_index_kind::GDB_INDEX
;
5806 global_index_cache
.miss ();
5812 /* Build a partial symbol table. */
5815 dwarf2_build_psymtabs (struct objfile
*objfile
)
5817 struct dwarf2_per_objfile
*dwarf2_per_objfile
5818 = get_dwarf2_per_objfile (objfile
);
5820 init_psymbol_list (objfile
, 1024);
5824 /* This isn't really ideal: all the data we allocate on the
5825 objfile's obstack is still uselessly kept around. However,
5826 freeing it seems unsafe. */
5827 psymtab_discarder
psymtabs (objfile
);
5828 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
5831 /* (maybe) store an index in the cache. */
5832 global_index_cache
.store (dwarf2_per_objfile
);
5834 catch (const gdb_exception_error
&except
)
5836 exception_print (gdb_stderr
, except
);
5840 /* Find the base address of the compilation unit for range lists and
5841 location lists. It will normally be specified by DW_AT_low_pc.
5842 In DWARF-3 draft 4, the base address could be overridden by
5843 DW_AT_entry_pc. It's been removed, but GCC still uses this for
5844 compilation units with discontinuous ranges. */
5847 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
5849 struct attribute
*attr
;
5851 cu
->base_address
.reset ();
5853 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
5854 if (attr
!= nullptr)
5855 cu
->base_address
= attr
->value_as_address ();
5858 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5859 if (attr
!= nullptr)
5860 cu
->base_address
= attr
->value_as_address ();
5864 /* Helper function that returns the proper abbrev section for
5867 static struct dwarf2_section_info
*
5868 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
5870 struct dwarf2_section_info
*abbrev
;
5871 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
5873 if (this_cu
->is_dwz
)
5874 abbrev
= &dwarf2_get_dwz_file (dwarf2_per_objfile
)->abbrev
;
5876 abbrev
= &dwarf2_per_objfile
->abbrev
;
5881 /* Fetch the abbreviation table offset from a comp or type unit header. */
5884 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5885 struct dwarf2_section_info
*section
,
5886 sect_offset sect_off
)
5888 bfd
*abfd
= section
->get_bfd_owner ();
5889 const gdb_byte
*info_ptr
;
5890 unsigned int initial_length_size
, offset_size
;
5893 section
->read (dwarf2_per_objfile
->objfile
);
5894 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
5895 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
5896 offset_size
= initial_length_size
== 4 ? 4 : 8;
5897 info_ptr
+= initial_length_size
;
5899 version
= read_2_bytes (abfd
, info_ptr
);
5903 /* Skip unit type and address size. */
5907 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
5910 /* A partial symtab that is used only for include files. */
5911 struct dwarf2_include_psymtab
: public partial_symtab
5913 dwarf2_include_psymtab (const char *filename
, struct objfile
*objfile
)
5914 : partial_symtab (filename
, objfile
)
5918 void read_symtab (struct objfile
*objfile
) override
5920 expand_psymtab (objfile
);
5923 void expand_psymtab (struct objfile
*objfile
) override
5927 /* It's an include file, no symbols to read for it.
5928 Everything is in the parent symtab. */
5929 expand_dependencies (objfile
);
5933 bool readin_p () const override
5938 struct compunit_symtab
*get_compunit_symtab () const override
5945 bool m_readin
= false;
5948 /* Allocate a new partial symtab for file named NAME and mark this new
5949 partial symtab as being an include of PST. */
5952 dwarf2_create_include_psymtab (const char *name
, dwarf2_psymtab
*pst
,
5953 struct objfile
*objfile
)
5955 dwarf2_include_psymtab
*subpst
= new dwarf2_include_psymtab (name
, objfile
);
5957 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
5959 /* It shares objfile->objfile_obstack. */
5960 subpst
->dirname
= pst
->dirname
;
5963 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
5964 subpst
->dependencies
[0] = pst
;
5965 subpst
->number_of_dependencies
= 1;
5968 /* Read the Line Number Program data and extract the list of files
5969 included by the source file represented by PST. Build an include
5970 partial symtab for each of these included files. */
5973 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
5974 struct die_info
*die
,
5975 dwarf2_psymtab
*pst
)
5978 struct attribute
*attr
;
5980 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5981 if (attr
!= nullptr)
5982 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
5984 return; /* No linetable, so no includes. */
5986 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
5987 that we pass in the raw text_low here; that is ok because we're
5988 only decoding the line table to make include partial symtabs, and
5989 so the addresses aren't really used. */
5990 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
5991 pst
->raw_text_low (), 1);
5995 hash_signatured_type (const void *item
)
5997 const struct signatured_type
*sig_type
5998 = (const struct signatured_type
*) item
;
6000 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6001 return sig_type
->signature
;
6005 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6007 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6008 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6010 return lhs
->signature
== rhs
->signature
;
6013 /* Allocate a hash table for signatured types. */
6016 allocate_signatured_type_table ()
6018 return htab_up (htab_create_alloc (41,
6019 hash_signatured_type
,
6021 NULL
, xcalloc
, xfree
));
6024 /* A helper function to add a signatured type CU to a table. */
6027 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6029 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6030 std::vector
<signatured_type
*> *all_type_units
6031 = (std::vector
<signatured_type
*> *) datum
;
6033 all_type_units
->push_back (sigt
);
6038 /* A helper for create_debug_types_hash_table. Read types from SECTION
6039 and fill them into TYPES_HTAB. It will process only type units,
6040 therefore DW_UT_type. */
6043 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6044 struct dwo_file
*dwo_file
,
6045 dwarf2_section_info
*section
, htab_up
&types_htab
,
6046 rcuh_kind section_kind
)
6048 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6049 struct dwarf2_section_info
*abbrev_section
;
6051 const gdb_byte
*info_ptr
, *end_ptr
;
6053 abbrev_section
= (dwo_file
!= NULL
6054 ? &dwo_file
->sections
.abbrev
6055 : &dwarf2_per_objfile
->abbrev
);
6057 if (dwarf_read_debug
)
6058 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6059 section
->get_name (),
6060 abbrev_section
->get_file_name ());
6062 section
->read (objfile
);
6063 info_ptr
= section
->buffer
;
6065 if (info_ptr
== NULL
)
6068 /* We can't set abfd until now because the section may be empty or
6069 not present, in which case the bfd is unknown. */
6070 abfd
= section
->get_bfd_owner ();
6072 /* We don't use cutu_reader here because we don't need to read
6073 any dies: the signature is in the header. */
6075 end_ptr
= info_ptr
+ section
->size
;
6076 while (info_ptr
< end_ptr
)
6078 struct signatured_type
*sig_type
;
6079 struct dwo_unit
*dwo_tu
;
6081 const gdb_byte
*ptr
= info_ptr
;
6082 struct comp_unit_head header
;
6083 unsigned int length
;
6085 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6087 /* Initialize it due to a false compiler warning. */
6088 header
.signature
= -1;
6089 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6091 /* We need to read the type's signature in order to build the hash
6092 table, but we don't need anything else just yet. */
6094 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
6095 abbrev_section
, ptr
, section_kind
);
6097 length
= header
.get_length ();
6099 /* Skip dummy type units. */
6100 if (ptr
>= info_ptr
+ length
6101 || peek_abbrev_code (abfd
, ptr
) == 0
6102 || header
.unit_type
!= DW_UT_type
)
6108 if (types_htab
== NULL
)
6111 types_htab
= allocate_dwo_unit_table ();
6113 types_htab
= allocate_signatured_type_table ();
6119 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6121 dwo_tu
->dwo_file
= dwo_file
;
6122 dwo_tu
->signature
= header
.signature
;
6123 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6124 dwo_tu
->section
= section
;
6125 dwo_tu
->sect_off
= sect_off
;
6126 dwo_tu
->length
= length
;
6130 /* N.B.: type_offset is not usable if this type uses a DWO file.
6131 The real type_offset is in the DWO file. */
6133 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6134 struct signatured_type
);
6135 sig_type
->signature
= header
.signature
;
6136 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6137 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6138 sig_type
->per_cu
.is_debug_types
= 1;
6139 sig_type
->per_cu
.section
= section
;
6140 sig_type
->per_cu
.sect_off
= sect_off
;
6141 sig_type
->per_cu
.length
= length
;
6144 slot
= htab_find_slot (types_htab
.get (),
6145 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6147 gdb_assert (slot
!= NULL
);
6150 sect_offset dup_sect_off
;
6154 const struct dwo_unit
*dup_tu
6155 = (const struct dwo_unit
*) *slot
;
6157 dup_sect_off
= dup_tu
->sect_off
;
6161 const struct signatured_type
*dup_tu
6162 = (const struct signatured_type
*) *slot
;
6164 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6167 complaint (_("debug type entry at offset %s is duplicate to"
6168 " the entry at offset %s, signature %s"),
6169 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6170 hex_string (header
.signature
));
6172 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6174 if (dwarf_read_debug
> 1)
6175 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6176 sect_offset_str (sect_off
),
6177 hex_string (header
.signature
));
6183 /* Create the hash table of all entries in the .debug_types
6184 (or .debug_types.dwo) section(s).
6185 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6186 otherwise it is NULL.
6188 The result is a pointer to the hash table or NULL if there are no types.
6190 Note: This function processes DWO files only, not DWP files. */
6193 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6194 struct dwo_file
*dwo_file
,
6195 gdb::array_view
<dwarf2_section_info
> type_sections
,
6196 htab_up
&types_htab
)
6198 for (dwarf2_section_info
§ion
: type_sections
)
6199 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, §ion
,
6200 types_htab
, rcuh_kind::TYPE
);
6203 /* Create the hash table of all entries in the .debug_types section,
6204 and initialize all_type_units.
6205 The result is zero if there is an error (e.g. missing .debug_types section),
6206 otherwise non-zero. */
6209 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6213 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
6214 &dwarf2_per_objfile
->info
, types_htab
,
6215 rcuh_kind::COMPILE
);
6216 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
6217 dwarf2_per_objfile
->types
, types_htab
);
6218 if (types_htab
== NULL
)
6220 dwarf2_per_objfile
->signatured_types
= NULL
;
6224 dwarf2_per_objfile
->signatured_types
= std::move (types_htab
);
6226 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
6227 dwarf2_per_objfile
->all_type_units
.reserve
6228 (htab_elements (dwarf2_per_objfile
->signatured_types
.get ()));
6230 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
.get (),
6231 add_signatured_type_cu_to_table
,
6232 &dwarf2_per_objfile
->all_type_units
);
6237 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
6238 If SLOT is non-NULL, it is the entry to use in the hash table.
6239 Otherwise we find one. */
6241 static struct signatured_type
*
6242 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
6245 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6247 if (dwarf2_per_objfile
->all_type_units
.size ()
6248 == dwarf2_per_objfile
->all_type_units
.capacity ())
6249 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
6251 signatured_type
*sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6252 struct signatured_type
);
6254 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
6255 sig_type
->signature
= sig
;
6256 sig_type
->per_cu
.is_debug_types
= 1;
6257 if (dwarf2_per_objfile
->using_index
)
6259 sig_type
->per_cu
.v
.quick
=
6260 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6261 struct dwarf2_per_cu_quick_data
);
6266 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6269 gdb_assert (*slot
== NULL
);
6271 /* The rest of sig_type must be filled in by the caller. */
6275 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6276 Fill in SIG_ENTRY with DWO_ENTRY. */
6279 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6280 struct signatured_type
*sig_entry
,
6281 struct dwo_unit
*dwo_entry
)
6283 /* Make sure we're not clobbering something we don't expect to. */
6284 gdb_assert (! sig_entry
->per_cu
.queued
);
6285 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
6286 if (dwarf2_per_objfile
->using_index
)
6288 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6289 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
6292 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6293 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6294 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6295 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6296 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6298 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6299 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6300 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6301 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6302 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6303 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6304 sig_entry
->dwo_unit
= dwo_entry
;
6307 /* Subroutine of lookup_signatured_type.
6308 If we haven't read the TU yet, create the signatured_type data structure
6309 for a TU to be read in directly from a DWO file, bypassing the stub.
6310 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6311 using .gdb_index, then when reading a CU we want to stay in the DWO file
6312 containing that CU. Otherwise we could end up reading several other DWO
6313 files (due to comdat folding) to process the transitive closure of all the
6314 mentioned TUs, and that can be slow. The current DWO file will have every
6315 type signature that it needs.
6316 We only do this for .gdb_index because in the psymtab case we already have
6317 to read all the DWOs to build the type unit groups. */
6319 static struct signatured_type
*
6320 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6322 struct dwarf2_per_objfile
*dwarf2_per_objfile
6323 = cu
->per_cu
->dwarf2_per_objfile
;
6324 struct dwo_file
*dwo_file
;
6325 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6326 struct signatured_type find_sig_entry
, *sig_entry
;
6329 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6331 /* If TU skeletons have been removed then we may not have read in any
6333 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6334 dwarf2_per_objfile
->signatured_types
= allocate_signatured_type_table ();
6336 /* We only ever need to read in one copy of a signatured type.
6337 Use the global signatured_types array to do our own comdat-folding
6338 of types. If this is the first time we're reading this TU, and
6339 the TU has an entry in .gdb_index, replace the recorded data from
6340 .gdb_index with this TU. */
6342 find_sig_entry
.signature
= sig
;
6343 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6344 &find_sig_entry
, INSERT
);
6345 sig_entry
= (struct signatured_type
*) *slot
;
6347 /* We can get here with the TU already read, *or* in the process of being
6348 read. Don't reassign the global entry to point to this DWO if that's
6349 the case. Also note that if the TU is already being read, it may not
6350 have come from a DWO, the program may be a mix of Fission-compiled
6351 code and non-Fission-compiled code. */
6353 /* Have we already tried to read this TU?
6354 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6355 needn't exist in the global table yet). */
6356 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
6359 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6360 dwo_unit of the TU itself. */
6361 dwo_file
= cu
->dwo_unit
->dwo_file
;
6363 /* Ok, this is the first time we're reading this TU. */
6364 if (dwo_file
->tus
== NULL
)
6366 find_dwo_entry
.signature
= sig
;
6367 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6369 if (dwo_entry
== NULL
)
6372 /* If the global table doesn't have an entry for this TU, add one. */
6373 if (sig_entry
== NULL
)
6374 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6376 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6377 sig_entry
->per_cu
.tu_read
= 1;
6381 /* Subroutine of lookup_signatured_type.
6382 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6383 then try the DWP file. If the TU stub (skeleton) has been removed then
6384 it won't be in .gdb_index. */
6386 static struct signatured_type
*
6387 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6389 struct dwarf2_per_objfile
*dwarf2_per_objfile
6390 = cu
->per_cu
->dwarf2_per_objfile
;
6391 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
6392 struct dwo_unit
*dwo_entry
;
6393 struct signatured_type find_sig_entry
, *sig_entry
;
6396 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6397 gdb_assert (dwp_file
!= NULL
);
6399 /* If TU skeletons have been removed then we may not have read in any
6401 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6402 dwarf2_per_objfile
->signatured_types
= allocate_signatured_type_table ();
6404 find_sig_entry
.signature
= sig
;
6405 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6406 &find_sig_entry
, INSERT
);
6407 sig_entry
= (struct signatured_type
*) *slot
;
6409 /* Have we already tried to read this TU?
6410 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6411 needn't exist in the global table yet). */
6412 if (sig_entry
!= NULL
)
6415 if (dwp_file
->tus
== NULL
)
6417 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
6418 sig
, 1 /* is_debug_types */);
6419 if (dwo_entry
== NULL
)
6422 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6423 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6428 /* Lookup a signature based type for DW_FORM_ref_sig8.
6429 Returns NULL if signature SIG is not present in the table.
6430 It is up to the caller to complain about this. */
6432 static struct signatured_type
*
6433 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6435 struct dwarf2_per_objfile
*dwarf2_per_objfile
6436 = cu
->per_cu
->dwarf2_per_objfile
;
6439 && dwarf2_per_objfile
->using_index
)
6441 /* We're in a DWO/DWP file, and we're using .gdb_index.
6442 These cases require special processing. */
6443 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
6444 return lookup_dwo_signatured_type (cu
, sig
);
6446 return lookup_dwp_signatured_type (cu
, sig
);
6450 struct signatured_type find_entry
, *entry
;
6452 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6454 find_entry
.signature
= sig
;
6455 entry
= ((struct signatured_type
*)
6456 htab_find (dwarf2_per_objfile
->signatured_types
.get (),
6462 /* Low level DIE reading support. */
6464 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6467 init_cu_die_reader (struct die_reader_specs
*reader
,
6468 struct dwarf2_cu
*cu
,
6469 struct dwarf2_section_info
*section
,
6470 struct dwo_file
*dwo_file
,
6471 struct abbrev_table
*abbrev_table
)
6473 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6474 reader
->abfd
= section
->get_bfd_owner ();
6476 reader
->dwo_file
= dwo_file
;
6477 reader
->die_section
= section
;
6478 reader
->buffer
= section
->buffer
;
6479 reader
->buffer_end
= section
->buffer
+ section
->size
;
6480 reader
->abbrev_table
= abbrev_table
;
6483 /* Subroutine of cutu_reader to simplify it.
6484 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6485 There's just a lot of work to do, and cutu_reader is big enough
6488 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6489 from it to the DIE in the DWO. If NULL we are skipping the stub.
6490 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6491 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6492 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6493 STUB_COMP_DIR may be non-NULL.
6494 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6495 are filled in with the info of the DIE from the DWO file.
6496 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6497 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6498 kept around for at least as long as *RESULT_READER.
6500 The result is non-zero if a valid (non-dummy) DIE was found. */
6503 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
6504 struct dwo_unit
*dwo_unit
,
6505 struct die_info
*stub_comp_unit_die
,
6506 const char *stub_comp_dir
,
6507 struct die_reader_specs
*result_reader
,
6508 const gdb_byte
**result_info_ptr
,
6509 struct die_info
**result_comp_unit_die
,
6510 abbrev_table_up
*result_dwo_abbrev_table
)
6512 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6513 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6514 struct dwarf2_cu
*cu
= this_cu
->cu
;
6516 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6517 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6518 int i
,num_extra_attrs
;
6519 struct dwarf2_section_info
*dwo_abbrev_section
;
6520 struct die_info
*comp_unit_die
;
6522 /* At most one of these may be provided. */
6523 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6525 /* These attributes aren't processed until later:
6526 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6527 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6528 referenced later. However, these attributes are found in the stub
6529 which we won't have later. In order to not impose this complication
6530 on the rest of the code, we read them here and copy them to the
6539 if (stub_comp_unit_die
!= NULL
)
6541 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6543 if (! this_cu
->is_debug_types
)
6544 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6545 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6546 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6547 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6548 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6550 cu
->addr_base
= stub_comp_unit_die
->addr_base ();
6552 /* There should be a DW_AT_rnglists_base (DW_AT_GNU_ranges_base) attribute
6553 here (if needed). We need the value before we can process
6555 cu
->ranges_base
= stub_comp_unit_die
->ranges_base ();
6557 else if (stub_comp_dir
!= NULL
)
6559 /* Reconstruct the comp_dir attribute to simplify the code below. */
6560 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
6561 comp_dir
->name
= DW_AT_comp_dir
;
6562 comp_dir
->form
= DW_FORM_string
;
6563 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
6564 DW_STRING (comp_dir
) = stub_comp_dir
;
6567 /* Set up for reading the DWO CU/TU. */
6568 cu
->dwo_unit
= dwo_unit
;
6569 dwarf2_section_info
*section
= dwo_unit
->section
;
6570 section
->read (objfile
);
6571 abfd
= section
->get_bfd_owner ();
6572 begin_info_ptr
= info_ptr
= (section
->buffer
6573 + to_underlying (dwo_unit
->sect_off
));
6574 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6576 if (this_cu
->is_debug_types
)
6578 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
6580 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6581 &cu
->header
, section
,
6583 info_ptr
, rcuh_kind::TYPE
);
6584 /* This is not an assert because it can be caused by bad debug info. */
6585 if (sig_type
->signature
!= cu
->header
.signature
)
6587 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6588 " TU at offset %s [in module %s]"),
6589 hex_string (sig_type
->signature
),
6590 hex_string (cu
->header
.signature
),
6591 sect_offset_str (dwo_unit
->sect_off
),
6592 bfd_get_filename (abfd
));
6594 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6595 /* For DWOs coming from DWP files, we don't know the CU length
6596 nor the type's offset in the TU until now. */
6597 dwo_unit
->length
= cu
->header
.get_length ();
6598 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6600 /* Establish the type offset that can be used to lookup the type.
6601 For DWO files, we don't know it until now. */
6602 sig_type
->type_offset_in_section
6603 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6607 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6608 &cu
->header
, section
,
6610 info_ptr
, rcuh_kind::COMPILE
);
6611 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6612 /* For DWOs coming from DWP files, we don't know the CU length
6614 dwo_unit
->length
= cu
->header
.get_length ();
6617 *result_dwo_abbrev_table
6618 = abbrev_table::read (objfile
, dwo_abbrev_section
,
6619 cu
->header
.abbrev_sect_off
);
6620 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6621 result_dwo_abbrev_table
->get ());
6623 /* Read in the die, but leave space to copy over the attributes
6624 from the stub. This has the benefit of simplifying the rest of
6625 the code - all the work to maintain the illusion of a single
6626 DW_TAG_{compile,type}_unit DIE is done here. */
6627 num_extra_attrs
= ((stmt_list
!= NULL
)
6631 + (comp_dir
!= NULL
));
6632 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6635 /* Copy over the attributes from the stub to the DIE we just read in. */
6636 comp_unit_die
= *result_comp_unit_die
;
6637 i
= comp_unit_die
->num_attrs
;
6638 if (stmt_list
!= NULL
)
6639 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6641 comp_unit_die
->attrs
[i
++] = *low_pc
;
6642 if (high_pc
!= NULL
)
6643 comp_unit_die
->attrs
[i
++] = *high_pc
;
6645 comp_unit_die
->attrs
[i
++] = *ranges
;
6646 if (comp_dir
!= NULL
)
6647 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6648 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6650 if (dwarf_die_debug
)
6652 fprintf_unfiltered (gdb_stdlog
,
6653 "Read die from %s@0x%x of %s:\n",
6654 section
->get_name (),
6655 (unsigned) (begin_info_ptr
- section
->buffer
),
6656 bfd_get_filename (abfd
));
6657 dump_die (comp_unit_die
, dwarf_die_debug
);
6660 /* Skip dummy compilation units. */
6661 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6662 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6665 *result_info_ptr
= info_ptr
;
6669 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
6670 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
6671 signature is part of the header. */
6672 static gdb::optional
<ULONGEST
>
6673 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
6675 if (cu
->header
.version
>= 5)
6676 return cu
->header
.signature
;
6677 struct attribute
*attr
;
6678 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6679 if (attr
== nullptr)
6680 return gdb::optional
<ULONGEST
> ();
6681 return DW_UNSND (attr
);
6684 /* Subroutine of cutu_reader to simplify it.
6685 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6686 Returns NULL if the specified DWO unit cannot be found. */
6688 static struct dwo_unit
*
6689 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
6690 struct die_info
*comp_unit_die
,
6691 const char *dwo_name
)
6693 struct dwarf2_cu
*cu
= this_cu
->cu
;
6694 struct dwo_unit
*dwo_unit
;
6695 const char *comp_dir
;
6697 gdb_assert (cu
!= NULL
);
6699 /* Yeah, we look dwo_name up again, but it simplifies the code. */
6700 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6701 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6703 if (this_cu
->is_debug_types
)
6705 struct signatured_type
*sig_type
;
6707 /* Since this_cu is the first member of struct signatured_type,
6708 we can go from a pointer to one to a pointer to the other. */
6709 sig_type
= (struct signatured_type
*) this_cu
;
6710 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
6714 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
6715 if (!signature
.has_value ())
6716 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
6718 dwo_name
, objfile_name (this_cu
->dwarf2_per_objfile
->objfile
));
6719 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
6726 /* Subroutine of cutu_reader to simplify it.
6727 See it for a description of the parameters.
6728 Read a TU directly from a DWO file, bypassing the stub. */
6731 cutu_reader::init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
6732 int use_existing_cu
)
6734 struct signatured_type
*sig_type
;
6736 /* Verify we can do the following downcast, and that we have the
6738 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
6739 sig_type
= (struct signatured_type
*) this_cu
;
6740 gdb_assert (sig_type
->dwo_unit
!= NULL
);
6742 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
6744 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
6745 /* There's no need to do the rereading_dwo_cu handling that
6746 cutu_reader does since we don't read the stub. */
6750 /* If !use_existing_cu, this_cu->cu must be NULL. */
6751 gdb_assert (this_cu
->cu
== NULL
);
6752 m_new_cu
.reset (new dwarf2_cu (this_cu
));
6755 /* A future optimization, if needed, would be to use an existing
6756 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
6757 could share abbrev tables. */
6759 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
6760 NULL
/* stub_comp_unit_die */,
6761 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
6764 &m_dwo_abbrev_table
) == 0)
6771 /* Initialize a CU (or TU) and read its DIEs.
6772 If the CU defers to a DWO file, read the DWO file as well.
6774 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
6775 Otherwise the table specified in the comp unit header is read in and used.
6776 This is an optimization for when we already have the abbrev table.
6778 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
6779 Otherwise, a new CU is allocated with xmalloc. */
6781 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
6782 struct abbrev_table
*abbrev_table
,
6783 int use_existing_cu
,
6785 : die_reader_specs
{},
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 we're reading a TU directly from a DWO file, including a virtual DWO
6807 file (instead of going through the stub), short-circuit all of this. */
6808 if (this_cu
->reading_dwo_directly
)
6810 /* Narrow down the scope of possibilities to have to understand. */
6811 gdb_assert (this_cu
->is_debug_types
);
6812 gdb_assert (abbrev_table
== NULL
);
6813 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
);
6817 /* This is cheap if the section is already read in. */
6818 section
->read (objfile
);
6820 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6822 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
6824 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
6827 /* If this CU is from a DWO file we need to start over, we need to
6828 refetch the attributes from the skeleton CU.
6829 This could be optimized by retrieving those attributes from when we
6830 were here the first time: the previous comp_unit_die was stored in
6831 comp_unit_obstack. But there's no data yet that we need this
6833 if (cu
->dwo_unit
!= NULL
)
6834 rereading_dwo_cu
= 1;
6838 /* If !use_existing_cu, this_cu->cu must be NULL. */
6839 gdb_assert (this_cu
->cu
== NULL
);
6840 m_new_cu
.reset (new dwarf2_cu (this_cu
));
6841 cu
= m_new_cu
.get ();
6844 /* Get the header. */
6845 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
6847 /* We already have the header, there's no need to read it in again. */
6848 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
6852 if (this_cu
->is_debug_types
)
6854 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6855 &cu
->header
, section
,
6856 abbrev_section
, info_ptr
,
6859 /* Since per_cu is the first member of struct signatured_type,
6860 we can go from a pointer to one to a pointer to the other. */
6861 sig_type
= (struct signatured_type
*) this_cu
;
6862 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
6863 gdb_assert (sig_type
->type_offset_in_tu
6864 == cu
->header
.type_cu_offset_in_tu
);
6865 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6867 /* LENGTH has not been set yet for type units if we're
6868 using .gdb_index. */
6869 this_cu
->length
= cu
->header
.get_length ();
6871 /* Establish the type offset that can be used to lookup the type. */
6872 sig_type
->type_offset_in_section
=
6873 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
6875 this_cu
->dwarf_version
= cu
->header
.version
;
6879 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6880 &cu
->header
, section
,
6883 rcuh_kind::COMPILE
);
6885 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6886 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
6887 this_cu
->dwarf_version
= cu
->header
.version
;
6891 /* Skip dummy compilation units. */
6892 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6893 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6899 /* If we don't have them yet, read the abbrevs for this compilation unit.
6900 And if we need to read them now, make sure they're freed when we're
6902 if (abbrev_table
!= NULL
)
6903 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
6906 m_abbrev_table_holder
6907 = abbrev_table::read (objfile
, abbrev_section
,
6908 cu
->header
.abbrev_sect_off
);
6909 abbrev_table
= m_abbrev_table_holder
.get ();
6912 /* Read the top level CU/TU die. */
6913 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
6914 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
6916 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
6922 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
6923 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
6924 table from the DWO file and pass the ownership over to us. It will be
6925 referenced from READER, so we must make sure to free it after we're done
6928 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
6929 DWO CU, that this test will fail (the attribute will not be present). */
6930 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6931 if (dwo_name
!= nullptr)
6933 struct dwo_unit
*dwo_unit
;
6934 struct die_info
*dwo_comp_unit_die
;
6936 if (comp_unit_die
->has_children
)
6938 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
6939 " has children (offset %s) [in module %s]"),
6940 sect_offset_str (this_cu
->sect_off
),
6941 bfd_get_filename (abfd
));
6943 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
, dwo_name
);
6944 if (dwo_unit
!= NULL
)
6946 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
6947 comp_unit_die
, NULL
,
6950 &m_dwo_abbrev_table
) == 0)
6956 comp_unit_die
= dwo_comp_unit_die
;
6960 /* Yikes, we couldn't find the rest of the DIE, we only have
6961 the stub. A complaint has already been logged. There's
6962 not much more we can do except pass on the stub DIE to
6963 die_reader_func. We don't want to throw an error on bad
6970 cutu_reader::keep ()
6972 /* Done, clean up. */
6973 gdb_assert (!dummy_p
);
6974 if (m_new_cu
!= NULL
)
6976 struct dwarf2_per_objfile
*dwarf2_per_objfile
6977 = m_this_cu
->dwarf2_per_objfile
;
6978 /* Link this CU into read_in_chain. */
6979 m_this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
6980 dwarf2_per_objfile
->read_in_chain
= m_this_cu
;
6981 /* The chain owns it now. */
6982 m_new_cu
.release ();
6986 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
6987 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
6988 assumed to have already done the lookup to find the DWO file).
6990 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
6991 THIS_CU->is_debug_types, but nothing else.
6993 We fill in THIS_CU->length.
6995 THIS_CU->cu is always freed when done.
6996 This is done in order to not leave THIS_CU->cu in a state where we have
6997 to care whether it refers to the "main" CU or the DWO CU.
6999 When parent_cu is passed, it is used to provide a default value for
7000 str_offsets_base and addr_base from the parent. */
7002 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
7003 struct dwarf2_cu
*parent_cu
,
7004 struct dwo_file
*dwo_file
)
7005 : die_reader_specs
{},
7008 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7009 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7010 struct dwarf2_section_info
*section
= this_cu
->section
;
7011 bfd
*abfd
= section
->get_bfd_owner ();
7012 struct dwarf2_section_info
*abbrev_section
;
7013 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7015 if (dwarf_die_debug
)
7016 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7017 this_cu
->is_debug_types
? "type" : "comp",
7018 sect_offset_str (this_cu
->sect_off
));
7020 gdb_assert (this_cu
->cu
== NULL
);
7022 abbrev_section
= (dwo_file
!= NULL
7023 ? &dwo_file
->sections
.abbrev
7024 : get_abbrev_section_for_cu (this_cu
));
7026 /* This is cheap if the section is already read in. */
7027 section
->read (objfile
);
7029 m_new_cu
.reset (new dwarf2_cu (this_cu
));
7031 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7032 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7033 &m_new_cu
->header
, section
,
7034 abbrev_section
, info_ptr
,
7035 (this_cu
->is_debug_types
7037 : rcuh_kind::COMPILE
));
7039 if (parent_cu
!= nullptr)
7041 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
7042 m_new_cu
->addr_base
= parent_cu
->addr_base
;
7044 this_cu
->length
= m_new_cu
->header
.get_length ();
7046 /* Skip dummy compilation units. */
7047 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7048 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7054 m_abbrev_table_holder
7055 = abbrev_table::read (objfile
, abbrev_section
,
7056 m_new_cu
->header
.abbrev_sect_off
);
7058 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
7059 m_abbrev_table_holder
.get ());
7060 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7064 /* Type Unit Groups.
7066 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7067 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7068 so that all types coming from the same compilation (.o file) are grouped
7069 together. A future step could be to put the types in the same symtab as
7070 the CU the types ultimately came from. */
7073 hash_type_unit_group (const void *item
)
7075 const struct type_unit_group
*tu_group
7076 = (const struct type_unit_group
*) item
;
7078 return hash_stmt_list_entry (&tu_group
->hash
);
7082 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7084 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7085 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7087 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7090 /* Allocate a hash table for type unit groups. */
7093 allocate_type_unit_groups_table ()
7095 return htab_up (htab_create_alloc (3,
7096 hash_type_unit_group
,
7098 NULL
, xcalloc
, xfree
));
7101 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7102 partial symtabs. We combine several TUs per psymtab to not let the size
7103 of any one psymtab grow too big. */
7104 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7105 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7107 /* Helper routine for get_type_unit_group.
7108 Create the type_unit_group object used to hold one or more TUs. */
7110 static struct type_unit_group
*
7111 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7113 struct dwarf2_per_objfile
*dwarf2_per_objfile
7114 = cu
->per_cu
->dwarf2_per_objfile
;
7115 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7116 struct dwarf2_per_cu_data
*per_cu
;
7117 struct type_unit_group
*tu_group
;
7119 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7120 struct type_unit_group
);
7121 per_cu
= &tu_group
->per_cu
;
7122 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7124 if (dwarf2_per_objfile
->using_index
)
7126 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7127 struct dwarf2_per_cu_quick_data
);
7131 unsigned int line_offset
= to_underlying (line_offset_struct
);
7132 dwarf2_psymtab
*pst
;
7135 /* Give the symtab a useful name for debug purposes. */
7136 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7137 name
= string_printf ("<type_units_%d>",
7138 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7140 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7142 pst
= create_partial_symtab (per_cu
, name
.c_str ());
7143 pst
->anonymous
= true;
7146 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7147 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7152 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7153 STMT_LIST is a DW_AT_stmt_list attribute. */
7155 static struct type_unit_group
*
7156 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7158 struct dwarf2_per_objfile
*dwarf2_per_objfile
7159 = cu
->per_cu
->dwarf2_per_objfile
;
7160 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7161 struct type_unit_group
*tu_group
;
7163 unsigned int line_offset
;
7164 struct type_unit_group type_unit_group_for_lookup
;
7166 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
7167 dwarf2_per_objfile
->type_unit_groups
= allocate_type_unit_groups_table ();
7169 /* Do we need to create a new group, or can we use an existing one? */
7173 line_offset
= DW_UNSND (stmt_list
);
7174 ++tu_stats
->nr_symtab_sharers
;
7178 /* Ugh, no stmt_list. Rare, but we have to handle it.
7179 We can do various things here like create one group per TU or
7180 spread them over multiple groups to split up the expansion work.
7181 To avoid worst case scenarios (too many groups or too large groups)
7182 we, umm, group them in bunches. */
7183 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7184 | (tu_stats
->nr_stmt_less_type_units
7185 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7186 ++tu_stats
->nr_stmt_less_type_units
;
7189 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7190 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7191 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
.get (),
7192 &type_unit_group_for_lookup
, INSERT
);
7195 tu_group
= (struct type_unit_group
*) *slot
;
7196 gdb_assert (tu_group
!= NULL
);
7200 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7201 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7203 ++tu_stats
->nr_symtabs
;
7209 /* Partial symbol tables. */
7211 /* Create a psymtab named NAME and assign it to PER_CU.
7213 The caller must fill in the following details:
7214 dirname, textlow, texthigh. */
7216 static dwarf2_psymtab
*
7217 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
7219 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
7220 dwarf2_psymtab
*pst
;
7222 pst
= new dwarf2_psymtab (name
, objfile
, per_cu
);
7224 pst
->psymtabs_addrmap_supported
= true;
7226 /* This is the glue that links PST into GDB's symbol API. */
7227 per_cu
->v
.psymtab
= pst
;
7232 /* DIE reader function for process_psymtab_comp_unit. */
7235 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7236 const gdb_byte
*info_ptr
,
7237 struct die_info
*comp_unit_die
,
7238 enum language pretend_language
)
7240 struct dwarf2_cu
*cu
= reader
->cu
;
7241 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
7242 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7243 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7245 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7246 dwarf2_psymtab
*pst
;
7247 enum pc_bounds_kind cu_bounds_kind
;
7248 const char *filename
;
7250 gdb_assert (! per_cu
->is_debug_types
);
7252 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
7254 /* Allocate a new partial symbol table structure. */
7255 gdb::unique_xmalloc_ptr
<char> debug_filename
;
7256 static const char artificial
[] = "<artificial>";
7257 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7258 if (filename
== NULL
)
7260 else if (strcmp (filename
, artificial
) == 0)
7262 debug_filename
.reset (concat (artificial
, "@",
7263 sect_offset_str (per_cu
->sect_off
),
7265 filename
= debug_filename
.get ();
7268 pst
= create_partial_symtab (per_cu
, filename
);
7270 /* This must be done before calling dwarf2_build_include_psymtabs. */
7271 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7273 baseaddr
= objfile
->text_section_offset ();
7275 dwarf2_find_base_address (comp_unit_die
, cu
);
7277 /* Possibly set the default values of LOWPC and HIGHPC from
7279 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7280 &best_highpc
, cu
, pst
);
7281 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7284 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7287 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7289 /* Store the contiguous range if it is not empty; it can be
7290 empty for CUs with no code. */
7291 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
7295 /* Check if comp unit has_children.
7296 If so, read the rest of the partial symbols from this comp unit.
7297 If not, there's no more debug_info for this comp unit. */
7298 if (comp_unit_die
->has_children
)
7300 struct partial_die_info
*first_die
;
7301 CORE_ADDR lowpc
, highpc
;
7303 lowpc
= ((CORE_ADDR
) -1);
7304 highpc
= ((CORE_ADDR
) 0);
7306 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7308 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7309 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7311 /* If we didn't find a lowpc, set it to highpc to avoid
7312 complaints from `maint check'. */
7313 if (lowpc
== ((CORE_ADDR
) -1))
7316 /* If the compilation unit didn't have an explicit address range,
7317 then use the information extracted from its child dies. */
7318 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7321 best_highpc
= highpc
;
7324 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7325 best_lowpc
+ baseaddr
)
7327 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7328 best_highpc
+ baseaddr
)
7331 end_psymtab_common (objfile
, pst
);
7333 if (!cu
->per_cu
->imported_symtabs_empty ())
7336 int len
= cu
->per_cu
->imported_symtabs_size ();
7338 /* Fill in 'dependencies' here; we fill in 'users' in a
7340 pst
->number_of_dependencies
= len
;
7342 = objfile
->partial_symtabs
->allocate_dependencies (len
);
7343 for (i
= 0; i
< len
; ++i
)
7345 pst
->dependencies
[i
]
7346 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7349 cu
->per_cu
->imported_symtabs_free ();
7352 /* Get the list of files included in the current compilation unit,
7353 and build a psymtab for each of them. */
7354 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
7356 if (dwarf_read_debug
)
7357 fprintf_unfiltered (gdb_stdlog
,
7358 "Psymtab for %s unit @%s: %s - %s"
7359 ", %d global, %d static syms\n",
7360 per_cu
->is_debug_types
? "type" : "comp",
7361 sect_offset_str (per_cu
->sect_off
),
7362 paddress (gdbarch
, pst
->text_low (objfile
)),
7363 paddress (gdbarch
, pst
->text_high (objfile
)),
7364 pst
->n_global_syms
, pst
->n_static_syms
);
7367 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7368 Process compilation unit THIS_CU for a psymtab. */
7371 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
7372 bool want_partial_unit
,
7373 enum language pretend_language
)
7375 /* If this compilation unit was already read in, free the
7376 cached copy in order to read it in again. This is
7377 necessary because we skipped some symbols when we first
7378 read in the compilation unit (see load_partial_dies).
7379 This problem could be avoided, but the benefit is unclear. */
7380 if (this_cu
->cu
!= NULL
)
7381 free_one_cached_comp_unit (this_cu
);
7383 cutu_reader
reader (this_cu
, NULL
, 0, false);
7385 switch (reader
.comp_unit_die
->tag
)
7387 case DW_TAG_compile_unit
:
7388 this_cu
->unit_type
= DW_UT_compile
;
7390 case DW_TAG_partial_unit
:
7391 this_cu
->unit_type
= DW_UT_partial
;
7401 else if (this_cu
->is_debug_types
)
7402 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7403 reader
.comp_unit_die
);
7404 else if (want_partial_unit
7405 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7406 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7407 reader
.comp_unit_die
,
7410 this_cu
->lang
= this_cu
->cu
->language
;
7412 /* Age out any secondary CUs. */
7413 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
7416 /* Reader function for build_type_psymtabs. */
7419 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7420 const gdb_byte
*info_ptr
,
7421 struct die_info
*type_unit_die
)
7423 struct dwarf2_per_objfile
*dwarf2_per_objfile
7424 = reader
->cu
->per_cu
->dwarf2_per_objfile
;
7425 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7426 struct dwarf2_cu
*cu
= reader
->cu
;
7427 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7428 struct signatured_type
*sig_type
;
7429 struct type_unit_group
*tu_group
;
7430 struct attribute
*attr
;
7431 struct partial_die_info
*first_die
;
7432 CORE_ADDR lowpc
, highpc
;
7433 dwarf2_psymtab
*pst
;
7435 gdb_assert (per_cu
->is_debug_types
);
7436 sig_type
= (struct signatured_type
*) per_cu
;
7438 if (! type_unit_die
->has_children
)
7441 attr
= type_unit_die
->attr (DW_AT_stmt_list
);
7442 tu_group
= get_type_unit_group (cu
, attr
);
7444 if (tu_group
->tus
== nullptr)
7445 tu_group
->tus
= new std::vector
<signatured_type
*>;
7446 tu_group
->tus
->push_back (sig_type
);
7448 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7449 pst
= create_partial_symtab (per_cu
, "");
7450 pst
->anonymous
= true;
7452 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7454 lowpc
= (CORE_ADDR
) -1;
7455 highpc
= (CORE_ADDR
) 0;
7456 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7458 end_psymtab_common (objfile
, pst
);
7461 /* Struct used to sort TUs by their abbreviation table offset. */
7463 struct tu_abbrev_offset
7465 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7466 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7469 signatured_type
*sig_type
;
7470 sect_offset abbrev_offset
;
7473 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
7476 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
7477 const struct tu_abbrev_offset
&b
)
7479 return a
.abbrev_offset
< b
.abbrev_offset
;
7482 /* Efficiently read all the type units.
7483 This does the bulk of the work for build_type_psymtabs.
7485 The efficiency is because we sort TUs by the abbrev table they use and
7486 only read each abbrev table once. In one program there are 200K TUs
7487 sharing 8K abbrev tables.
7489 The main purpose of this function is to support building the
7490 dwarf2_per_objfile->type_unit_groups table.
7491 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7492 can collapse the search space by grouping them by stmt_list.
7493 The savings can be significant, in the same program from above the 200K TUs
7494 share 8K stmt_list tables.
7496 FUNC is expected to call get_type_unit_group, which will create the
7497 struct type_unit_group if necessary and add it to
7498 dwarf2_per_objfile->type_unit_groups. */
7501 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7503 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7504 abbrev_table_up abbrev_table
;
7505 sect_offset abbrev_offset
;
7507 /* It's up to the caller to not call us multiple times. */
7508 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
7510 if (dwarf2_per_objfile
->all_type_units
.empty ())
7513 /* TUs typically share abbrev tables, and there can be way more TUs than
7514 abbrev tables. Sort by abbrev table to reduce the number of times we
7515 read each abbrev table in.
7516 Alternatives are to punt or to maintain a cache of abbrev tables.
7517 This is simpler and efficient enough for now.
7519 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7520 symtab to use). Typically TUs with the same abbrev offset have the same
7521 stmt_list value too so in practice this should work well.
7523 The basic algorithm here is:
7525 sort TUs by abbrev table
7526 for each TU with same abbrev table:
7527 read abbrev table if first user
7528 read TU top level DIE
7529 [IWBN if DWO skeletons had DW_AT_stmt_list]
7532 if (dwarf_read_debug
)
7533 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
7535 /* Sort in a separate table to maintain the order of all_type_units
7536 for .gdb_index: TU indices directly index all_type_units. */
7537 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7538 sorted_by_abbrev
.reserve (dwarf2_per_objfile
->all_type_units
.size ());
7540 for (signatured_type
*sig_type
: dwarf2_per_objfile
->all_type_units
)
7541 sorted_by_abbrev
.emplace_back
7542 (sig_type
, read_abbrev_offset (dwarf2_per_objfile
,
7543 sig_type
->per_cu
.section
,
7544 sig_type
->per_cu
.sect_off
));
7546 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
7547 sort_tu_by_abbrev_offset
);
7549 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7551 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7553 /* Switch to the next abbrev table if necessary. */
7554 if (abbrev_table
== NULL
7555 || tu
.abbrev_offset
!= abbrev_offset
)
7557 abbrev_offset
= tu
.abbrev_offset
;
7559 abbrev_table::read (dwarf2_per_objfile
->objfile
,
7560 &dwarf2_per_objfile
->abbrev
,
7562 ++tu_stats
->nr_uniq_abbrev_tables
;
7565 cutu_reader
reader (&tu
.sig_type
->per_cu
, abbrev_table
.get (),
7567 if (!reader
.dummy_p
)
7568 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7569 reader
.comp_unit_die
);
7573 /* Print collected type unit statistics. */
7576 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7578 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7580 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
7581 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
7582 dwarf2_per_objfile
->all_type_units
.size ());
7583 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
7584 tu_stats
->nr_uniq_abbrev_tables
);
7585 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
7586 tu_stats
->nr_symtabs
);
7587 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
7588 tu_stats
->nr_symtab_sharers
);
7589 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
7590 tu_stats
->nr_stmt_less_type_units
);
7591 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
7592 tu_stats
->nr_all_type_units_reallocs
);
7595 /* Traversal function for build_type_psymtabs. */
7598 build_type_psymtab_dependencies (void **slot
, void *info
)
7600 struct dwarf2_per_objfile
*dwarf2_per_objfile
7601 = (struct dwarf2_per_objfile
*) info
;
7602 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7603 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7604 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
7605 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7606 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7609 gdb_assert (len
> 0);
7610 gdb_assert (per_cu
->type_unit_group_p ());
7612 pst
->number_of_dependencies
= len
;
7613 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
7614 for (i
= 0; i
< len
; ++i
)
7616 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7617 gdb_assert (iter
->per_cu
.is_debug_types
);
7618 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
7619 iter
->type_unit_group
= tu_group
;
7622 delete tu_group
->tus
;
7623 tu_group
->tus
= nullptr;
7628 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7629 Build partial symbol tables for the .debug_types comp-units. */
7632 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7634 if (! create_all_type_units (dwarf2_per_objfile
))
7637 build_type_psymtabs_1 (dwarf2_per_objfile
);
7640 /* Traversal function for process_skeletonless_type_unit.
7641 Read a TU in a DWO file and build partial symbols for it. */
7644 process_skeletonless_type_unit (void **slot
, void *info
)
7646 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7647 struct dwarf2_per_objfile
*dwarf2_per_objfile
7648 = (struct dwarf2_per_objfile
*) info
;
7649 struct signatured_type find_entry
, *entry
;
7651 /* If this TU doesn't exist in the global table, add it and read it in. */
7653 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7654 dwarf2_per_objfile
->signatured_types
= allocate_signatured_type_table ();
7656 find_entry
.signature
= dwo_unit
->signature
;
7657 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
7658 &find_entry
, INSERT
);
7659 /* If we've already seen this type there's nothing to do. What's happening
7660 is we're doing our own version of comdat-folding here. */
7664 /* This does the job that create_all_type_units would have done for
7666 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
7667 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
7670 /* This does the job that build_type_psymtabs_1 would have done. */
7671 cutu_reader
reader (&entry
->per_cu
, NULL
, 0, false);
7672 if (!reader
.dummy_p
)
7673 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7674 reader
.comp_unit_die
);
7679 /* Traversal function for process_skeletonless_type_units. */
7682 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7684 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7686 if (dwo_file
->tus
!= NULL
)
7687 htab_traverse_noresize (dwo_file
->tus
.get (),
7688 process_skeletonless_type_unit
, info
);
7693 /* Scan all TUs of DWO files, verifying we've processed them.
7694 This is needed in case a TU was emitted without its skeleton.
7695 Note: This can't be done until we know what all the DWO files are. */
7698 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7700 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
7701 if (get_dwp_file (dwarf2_per_objfile
) == NULL
7702 && dwarf2_per_objfile
->dwo_files
!= NULL
)
7704 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
.get (),
7705 process_dwo_file_for_skeletonless_type_units
,
7706 dwarf2_per_objfile
);
7710 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
7713 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7715 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
7717 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7722 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
7724 /* Set the 'user' field only if it is not already set. */
7725 if (pst
->dependencies
[j
]->user
== NULL
)
7726 pst
->dependencies
[j
]->user
= pst
;
7731 /* Build the partial symbol table by doing a quick pass through the
7732 .debug_info and .debug_abbrev sections. */
7735 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7737 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7739 if (dwarf_read_debug
)
7741 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
7742 objfile_name (objfile
));
7745 scoped_restore restore_reading_psyms
7746 = make_scoped_restore (&dwarf2_per_objfile
->reading_partial_symbols
,
7749 dwarf2_per_objfile
->info
.read (objfile
);
7751 /* Any cached compilation units will be linked by the per-objfile
7752 read_in_chain. Make sure to free them when we're done. */
7753 free_cached_comp_units
freer (dwarf2_per_objfile
);
7755 build_type_psymtabs (dwarf2_per_objfile
);
7757 create_all_comp_units (dwarf2_per_objfile
);
7759 /* Create a temporary address map on a temporary obstack. We later
7760 copy this to the final obstack. */
7761 auto_obstack temp_obstack
;
7763 scoped_restore save_psymtabs_addrmap
7764 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
7765 addrmap_create_mutable (&temp_obstack
));
7767 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
7768 process_psymtab_comp_unit (per_cu
, false, language_minimal
);
7770 /* This has to wait until we read the CUs, we need the list of DWOs. */
7771 process_skeletonless_type_units (dwarf2_per_objfile
);
7773 /* Now that all TUs have been processed we can fill in the dependencies. */
7774 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
7776 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
.get (),
7777 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
7780 if (dwarf_read_debug
)
7781 print_tu_stats (dwarf2_per_objfile
);
7783 set_partial_user (dwarf2_per_objfile
);
7785 objfile
->partial_symtabs
->psymtabs_addrmap
7786 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
7787 objfile
->partial_symtabs
->obstack ());
7788 /* At this point we want to keep the address map. */
7789 save_psymtabs_addrmap
.release ();
7791 if (dwarf_read_debug
)
7792 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
7793 objfile_name (objfile
));
7796 /* Load the partial DIEs for a secondary CU into memory.
7797 This is also used when rereading a primary CU with load_all_dies. */
7800 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
7802 cutu_reader
reader (this_cu
, NULL
, 1, false);
7804 if (!reader
.dummy_p
)
7806 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
7809 /* Check if comp unit has_children.
7810 If so, read the rest of the partial symbols from this comp unit.
7811 If not, there's no more debug_info for this comp unit. */
7812 if (reader
.comp_unit_die
->has_children
)
7813 load_partial_dies (&reader
, reader
.info_ptr
, 0);
7820 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
7821 struct dwarf2_section_info
*section
,
7822 struct dwarf2_section_info
*abbrev_section
,
7823 unsigned int is_dwz
)
7825 const gdb_byte
*info_ptr
;
7826 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7828 if (dwarf_read_debug
)
7829 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
7830 section
->get_name (),
7831 section
->get_file_name ());
7833 section
->read (objfile
);
7835 info_ptr
= section
->buffer
;
7837 while (info_ptr
< section
->buffer
+ section
->size
)
7839 struct dwarf2_per_cu_data
*this_cu
;
7841 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
7843 comp_unit_head cu_header
;
7844 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
7845 abbrev_section
, info_ptr
,
7846 rcuh_kind::COMPILE
);
7848 /* Save the compilation unit for later lookup. */
7849 if (cu_header
.unit_type
!= DW_UT_type
)
7851 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
7852 struct dwarf2_per_cu_data
);
7853 memset (this_cu
, 0, sizeof (*this_cu
));
7857 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
7858 struct signatured_type
);
7859 memset (sig_type
, 0, sizeof (*sig_type
));
7860 sig_type
->signature
= cu_header
.signature
;
7861 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
7862 this_cu
= &sig_type
->per_cu
;
7864 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
7865 this_cu
->sect_off
= sect_off
;
7866 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
7867 this_cu
->is_dwz
= is_dwz
;
7868 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7869 this_cu
->section
= section
;
7871 dwarf2_per_objfile
->all_comp_units
.push_back (this_cu
);
7873 info_ptr
= info_ptr
+ this_cu
->length
;
7877 /* Create a list of all compilation units in OBJFILE.
7878 This is only done for -readnow and building partial symtabs. */
7881 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7883 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
7884 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->info
,
7885 &dwarf2_per_objfile
->abbrev
, 0);
7887 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
7889 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
7893 /* Process all loaded DIEs for compilation unit CU, starting at
7894 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
7895 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
7896 DW_AT_ranges). See the comments of add_partial_subprogram on how
7897 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
7900 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
7901 CORE_ADDR
*highpc
, int set_addrmap
,
7902 struct dwarf2_cu
*cu
)
7904 struct partial_die_info
*pdi
;
7906 /* Now, march along the PDI's, descending into ones which have
7907 interesting children but skipping the children of the other ones,
7908 until we reach the end of the compilation unit. */
7916 /* Anonymous namespaces or modules have no name but have interesting
7917 children, so we need to look at them. Ditto for anonymous
7920 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
7921 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
7922 || pdi
->tag
== DW_TAG_imported_unit
7923 || pdi
->tag
== DW_TAG_inlined_subroutine
)
7927 case DW_TAG_subprogram
:
7928 case DW_TAG_inlined_subroutine
:
7929 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7931 case DW_TAG_constant
:
7932 case DW_TAG_variable
:
7933 case DW_TAG_typedef
:
7934 case DW_TAG_union_type
:
7935 if (!pdi
->is_declaration
)
7937 add_partial_symbol (pdi
, cu
);
7940 case DW_TAG_class_type
:
7941 case DW_TAG_interface_type
:
7942 case DW_TAG_structure_type
:
7943 if (!pdi
->is_declaration
)
7945 add_partial_symbol (pdi
, cu
);
7947 if ((cu
->language
== language_rust
7948 || cu
->language
== language_cplus
) && pdi
->has_children
)
7949 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
7952 case DW_TAG_enumeration_type
:
7953 if (!pdi
->is_declaration
)
7954 add_partial_enumeration (pdi
, cu
);
7956 case DW_TAG_base_type
:
7957 case DW_TAG_subrange_type
:
7958 /* File scope base type definitions are added to the partial
7960 add_partial_symbol (pdi
, cu
);
7962 case DW_TAG_namespace
:
7963 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7966 if (!pdi
->is_declaration
)
7967 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7969 case DW_TAG_imported_unit
:
7971 struct dwarf2_per_cu_data
*per_cu
;
7973 /* For now we don't handle imported units in type units. */
7974 if (cu
->per_cu
->is_debug_types
)
7976 error (_("Dwarf Error: DW_TAG_imported_unit is not"
7977 " supported in type units [in module %s]"),
7978 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
7981 per_cu
= dwarf2_find_containing_comp_unit
7982 (pdi
->d
.sect_off
, pdi
->is_dwz
,
7983 cu
->per_cu
->dwarf2_per_objfile
);
7985 /* Go read the partial unit, if needed. */
7986 if (per_cu
->v
.psymtab
== NULL
)
7987 process_psymtab_comp_unit (per_cu
, true, cu
->language
);
7989 cu
->per_cu
->imported_symtabs_push (per_cu
);
7992 case DW_TAG_imported_declaration
:
7993 add_partial_symbol (pdi
, cu
);
8000 /* If the die has a sibling, skip to the sibling. */
8002 pdi
= pdi
->die_sibling
;
8006 /* Functions used to compute the fully scoped name of a partial DIE.
8008 Normally, this is simple. For C++, the parent DIE's fully scoped
8009 name is concatenated with "::" and the partial DIE's name.
8010 Enumerators are an exception; they use the scope of their parent
8011 enumeration type, i.e. the name of the enumeration type is not
8012 prepended to the enumerator.
8014 There are two complexities. One is DW_AT_specification; in this
8015 case "parent" means the parent of the target of the specification,
8016 instead of the direct parent of the DIE. The other is compilers
8017 which do not emit DW_TAG_namespace; in this case we try to guess
8018 the fully qualified name of structure types from their members'
8019 linkage names. This must be done using the DIE's children rather
8020 than the children of any DW_AT_specification target. We only need
8021 to do this for structures at the top level, i.e. if the target of
8022 any DW_AT_specification (if any; otherwise the DIE itself) does not
8025 /* Compute the scope prefix associated with PDI's parent, in
8026 compilation unit CU. The result will be allocated on CU's
8027 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8028 field. NULL is returned if no prefix is necessary. */
8030 partial_die_parent_scope (struct partial_die_info
*pdi
,
8031 struct dwarf2_cu
*cu
)
8033 const char *grandparent_scope
;
8034 struct partial_die_info
*parent
, *real_pdi
;
8036 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8037 then this means the parent of the specification DIE. */
8040 while (real_pdi
->has_specification
)
8042 auto res
= find_partial_die (real_pdi
->spec_offset
,
8043 real_pdi
->spec_is_dwz
, cu
);
8048 parent
= real_pdi
->die_parent
;
8052 if (parent
->scope_set
)
8053 return parent
->scope
;
8057 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8059 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8060 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8061 Work around this problem here. */
8062 if (cu
->language
== language_cplus
8063 && parent
->tag
== DW_TAG_namespace
8064 && strcmp (parent
->name
, "::") == 0
8065 && grandparent_scope
== NULL
)
8067 parent
->scope
= NULL
;
8068 parent
->scope_set
= 1;
8072 /* Nested subroutines in Fortran get a prefix. */
8073 if (pdi
->tag
== DW_TAG_enumerator
)
8074 /* Enumerators should not get the name of the enumeration as a prefix. */
8075 parent
->scope
= grandparent_scope
;
8076 else if (parent
->tag
== DW_TAG_namespace
8077 || parent
->tag
== DW_TAG_module
8078 || parent
->tag
== DW_TAG_structure_type
8079 || parent
->tag
== DW_TAG_class_type
8080 || parent
->tag
== DW_TAG_interface_type
8081 || parent
->tag
== DW_TAG_union_type
8082 || parent
->tag
== DW_TAG_enumeration_type
8083 || (cu
->language
== language_fortran
8084 && parent
->tag
== DW_TAG_subprogram
8085 && pdi
->tag
== DW_TAG_subprogram
))
8087 if (grandparent_scope
== NULL
)
8088 parent
->scope
= parent
->name
;
8090 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8092 parent
->name
, 0, cu
);
8096 /* FIXME drow/2004-04-01: What should we be doing with
8097 function-local names? For partial symbols, we should probably be
8099 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8100 dwarf_tag_name (parent
->tag
),
8101 sect_offset_str (pdi
->sect_off
));
8102 parent
->scope
= grandparent_scope
;
8105 parent
->scope_set
= 1;
8106 return parent
->scope
;
8109 /* Return the fully scoped name associated with PDI, from compilation unit
8110 CU. The result will be allocated with malloc. */
8112 static gdb::unique_xmalloc_ptr
<char>
8113 partial_die_full_name (struct partial_die_info
*pdi
,
8114 struct dwarf2_cu
*cu
)
8116 const char *parent_scope
;
8118 /* If this is a template instantiation, we can not work out the
8119 template arguments from partial DIEs. So, unfortunately, we have
8120 to go through the full DIEs. At least any work we do building
8121 types here will be reused if full symbols are loaded later. */
8122 if (pdi
->has_template_arguments
)
8126 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
8128 struct die_info
*die
;
8129 struct attribute attr
;
8130 struct dwarf2_cu
*ref_cu
= cu
;
8132 /* DW_FORM_ref_addr is using section offset. */
8133 attr
.name
= (enum dwarf_attribute
) 0;
8134 attr
.form
= DW_FORM_ref_addr
;
8135 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8136 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8138 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8142 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8143 if (parent_scope
== NULL
)
8146 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8151 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8153 struct dwarf2_per_objfile
*dwarf2_per_objfile
8154 = cu
->per_cu
->dwarf2_per_objfile
;
8155 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8156 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8158 const char *actual_name
= NULL
;
8161 baseaddr
= objfile
->text_section_offset ();
8163 gdb::unique_xmalloc_ptr
<char> built_actual_name
8164 = partial_die_full_name (pdi
, cu
);
8165 if (built_actual_name
!= NULL
)
8166 actual_name
= built_actual_name
.get ();
8168 if (actual_name
== NULL
)
8169 actual_name
= pdi
->name
;
8173 case DW_TAG_inlined_subroutine
:
8174 case DW_TAG_subprogram
:
8175 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8177 if (pdi
->is_external
8178 || cu
->language
== language_ada
8179 || (cu
->language
== language_fortran
8180 && pdi
->die_parent
!= NULL
8181 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8183 /* Normally, only "external" DIEs are part of the global scope.
8184 But in Ada and Fortran, we want to be able to access nested
8185 procedures globally. So all Ada and Fortran subprograms are
8186 stored in the global scope. */
8187 add_psymbol_to_list (actual_name
,
8188 built_actual_name
!= NULL
,
8189 VAR_DOMAIN
, LOC_BLOCK
,
8190 SECT_OFF_TEXT (objfile
),
8191 psymbol_placement::GLOBAL
,
8193 cu
->language
, objfile
);
8197 add_psymbol_to_list (actual_name
,
8198 built_actual_name
!= NULL
,
8199 VAR_DOMAIN
, LOC_BLOCK
,
8200 SECT_OFF_TEXT (objfile
),
8201 psymbol_placement::STATIC
,
8202 addr
, cu
->language
, objfile
);
8205 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8206 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8208 case DW_TAG_constant
:
8209 add_psymbol_to_list (actual_name
,
8210 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
8211 -1, (pdi
->is_external
8212 ? psymbol_placement::GLOBAL
8213 : psymbol_placement::STATIC
),
8214 0, cu
->language
, objfile
);
8216 case DW_TAG_variable
:
8218 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8222 && !dwarf2_per_objfile
->has_section_at_zero
)
8224 /* A global or static variable may also have been stripped
8225 out by the linker if unused, in which case its address
8226 will be nullified; do not add such variables into partial
8227 symbol table then. */
8229 else if (pdi
->is_external
)
8232 Don't enter into the minimal symbol tables as there is
8233 a minimal symbol table entry from the ELF symbols already.
8234 Enter into partial symbol table if it has a location
8235 descriptor or a type.
8236 If the location descriptor is missing, new_symbol will create
8237 a LOC_UNRESOLVED symbol, the address of the variable will then
8238 be determined from the minimal symbol table whenever the variable
8240 The address for the partial symbol table entry is not
8241 used by GDB, but it comes in handy for debugging partial symbol
8244 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8245 add_psymbol_to_list (actual_name
,
8246 built_actual_name
!= NULL
,
8247 VAR_DOMAIN
, LOC_STATIC
,
8248 SECT_OFF_TEXT (objfile
),
8249 psymbol_placement::GLOBAL
,
8250 addr
, cu
->language
, objfile
);
8254 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8256 /* Static Variable. Skip symbols whose value we cannot know (those
8257 without location descriptors or constant values). */
8258 if (!has_loc
&& !pdi
->has_const_value
)
8261 add_psymbol_to_list (actual_name
,
8262 built_actual_name
!= NULL
,
8263 VAR_DOMAIN
, LOC_STATIC
,
8264 SECT_OFF_TEXT (objfile
),
8265 psymbol_placement::STATIC
,
8267 cu
->language
, objfile
);
8270 case DW_TAG_typedef
:
8271 case DW_TAG_base_type
:
8272 case DW_TAG_subrange_type
:
8273 add_psymbol_to_list (actual_name
,
8274 built_actual_name
!= NULL
,
8275 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
8276 psymbol_placement::STATIC
,
8277 0, cu
->language
, objfile
);
8279 case DW_TAG_imported_declaration
:
8280 case DW_TAG_namespace
:
8281 add_psymbol_to_list (actual_name
,
8282 built_actual_name
!= NULL
,
8283 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
8284 psymbol_placement::GLOBAL
,
8285 0, cu
->language
, objfile
);
8288 /* With Fortran 77 there might be a "BLOCK DATA" module
8289 available without any name. If so, we skip the module as it
8290 doesn't bring any value. */
8291 if (actual_name
!= nullptr)
8292 add_psymbol_to_list (actual_name
,
8293 built_actual_name
!= NULL
,
8294 MODULE_DOMAIN
, LOC_TYPEDEF
, -1,
8295 psymbol_placement::GLOBAL
,
8296 0, cu
->language
, objfile
);
8298 case DW_TAG_class_type
:
8299 case DW_TAG_interface_type
:
8300 case DW_TAG_structure_type
:
8301 case DW_TAG_union_type
:
8302 case DW_TAG_enumeration_type
:
8303 /* Skip external references. The DWARF standard says in the section
8304 about "Structure, Union, and Class Type Entries": "An incomplete
8305 structure, union or class type is represented by a structure,
8306 union or class entry that does not have a byte size attribute
8307 and that has a DW_AT_declaration attribute." */
8308 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8311 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8312 static vs. global. */
8313 add_psymbol_to_list (actual_name
,
8314 built_actual_name
!= NULL
,
8315 STRUCT_DOMAIN
, LOC_TYPEDEF
, -1,
8316 cu
->language
== language_cplus
8317 ? psymbol_placement::GLOBAL
8318 : psymbol_placement::STATIC
,
8319 0, cu
->language
, objfile
);
8322 case DW_TAG_enumerator
:
8323 add_psymbol_to_list (actual_name
,
8324 built_actual_name
!= NULL
,
8325 VAR_DOMAIN
, LOC_CONST
, -1,
8326 cu
->language
== language_cplus
8327 ? psymbol_placement::GLOBAL
8328 : psymbol_placement::STATIC
,
8329 0, cu
->language
, objfile
);
8336 /* Read a partial die corresponding to a namespace; also, add a symbol
8337 corresponding to that namespace to the symbol table. NAMESPACE is
8338 the name of the enclosing namespace. */
8341 add_partial_namespace (struct partial_die_info
*pdi
,
8342 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8343 int set_addrmap
, struct dwarf2_cu
*cu
)
8345 /* Add a symbol for the namespace. */
8347 add_partial_symbol (pdi
, cu
);
8349 /* Now scan partial symbols in that namespace. */
8351 if (pdi
->has_children
)
8352 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8355 /* Read a partial die corresponding to a Fortran module. */
8358 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8359 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8361 /* Add a symbol for the namespace. */
8363 add_partial_symbol (pdi
, cu
);
8365 /* Now scan partial symbols in that module. */
8367 if (pdi
->has_children
)
8368 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8371 /* Read a partial die corresponding to a subprogram or an inlined
8372 subprogram and create a partial symbol for that subprogram.
8373 When the CU language allows it, this routine also defines a partial
8374 symbol for each nested subprogram that this subprogram contains.
8375 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8376 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8378 PDI may also be a lexical block, in which case we simply search
8379 recursively for subprograms defined inside that lexical block.
8380 Again, this is only performed when the CU language allows this
8381 type of definitions. */
8384 add_partial_subprogram (struct partial_die_info
*pdi
,
8385 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8386 int set_addrmap
, struct dwarf2_cu
*cu
)
8388 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8390 if (pdi
->has_pc_info
)
8392 if (pdi
->lowpc
< *lowpc
)
8393 *lowpc
= pdi
->lowpc
;
8394 if (pdi
->highpc
> *highpc
)
8395 *highpc
= pdi
->highpc
;
8398 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
8399 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8401 CORE_ADDR this_highpc
;
8402 CORE_ADDR this_lowpc
;
8404 baseaddr
= objfile
->text_section_offset ();
8406 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8407 pdi
->lowpc
+ baseaddr
)
8410 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8411 pdi
->highpc
+ baseaddr
)
8413 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8414 this_lowpc
, this_highpc
- 1,
8415 cu
->per_cu
->v
.psymtab
);
8419 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8421 if (!pdi
->is_declaration
)
8422 /* Ignore subprogram DIEs that do not have a name, they are
8423 illegal. Do not emit a complaint at this point, we will
8424 do so when we convert this psymtab into a symtab. */
8426 add_partial_symbol (pdi
, cu
);
8430 if (! pdi
->has_children
)
8433 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
8435 pdi
= pdi
->die_child
;
8439 if (pdi
->tag
== DW_TAG_subprogram
8440 || pdi
->tag
== DW_TAG_inlined_subroutine
8441 || pdi
->tag
== DW_TAG_lexical_block
)
8442 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8443 pdi
= pdi
->die_sibling
;
8448 /* Read a partial die corresponding to an enumeration type. */
8451 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8452 struct dwarf2_cu
*cu
)
8454 struct partial_die_info
*pdi
;
8456 if (enum_pdi
->name
!= NULL
)
8457 add_partial_symbol (enum_pdi
, cu
);
8459 pdi
= enum_pdi
->die_child
;
8462 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
8463 complaint (_("malformed enumerator DIE ignored"));
8465 add_partial_symbol (pdi
, cu
);
8466 pdi
= pdi
->die_sibling
;
8470 /* Return the initial uleb128 in the die at INFO_PTR. */
8473 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8475 unsigned int bytes_read
;
8477 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8480 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8481 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8483 Return the corresponding abbrev, or NULL if the number is zero (indicating
8484 an empty DIE). In either case *BYTES_READ will be set to the length of
8485 the initial number. */
8487 static struct abbrev_info
*
8488 peek_die_abbrev (const die_reader_specs
&reader
,
8489 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8491 dwarf2_cu
*cu
= reader
.cu
;
8492 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
8493 unsigned int abbrev_number
8494 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8496 if (abbrev_number
== 0)
8499 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8502 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8503 " at offset %s [in module %s]"),
8504 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8505 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8511 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8512 Returns a pointer to the end of a series of DIEs, terminated by an empty
8513 DIE. Any children of the skipped DIEs will also be skipped. */
8515 static const gdb_byte
*
8516 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8520 unsigned int bytes_read
;
8521 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
8524 return info_ptr
+ bytes_read
;
8526 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8530 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8531 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8532 abbrev corresponding to that skipped uleb128 should be passed in
8533 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8536 static const gdb_byte
*
8537 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8538 struct abbrev_info
*abbrev
)
8540 unsigned int bytes_read
;
8541 struct attribute attr
;
8542 bfd
*abfd
= reader
->abfd
;
8543 struct dwarf2_cu
*cu
= reader
->cu
;
8544 const gdb_byte
*buffer
= reader
->buffer
;
8545 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8546 unsigned int form
, i
;
8548 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8550 /* The only abbrev we care about is DW_AT_sibling. */
8551 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8554 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
,
8556 if (attr
.form
== DW_FORM_ref_addr
)
8557 complaint (_("ignoring absolute DW_AT_sibling"));
8560 sect_offset off
= attr
.get_ref_die_offset ();
8561 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8563 if (sibling_ptr
< info_ptr
)
8564 complaint (_("DW_AT_sibling points backwards"));
8565 else if (sibling_ptr
> reader
->buffer_end
)
8566 reader
->die_section
->overflow_complaint ();
8572 /* If it isn't DW_AT_sibling, skip this attribute. */
8573 form
= abbrev
->attrs
[i
].form
;
8577 case DW_FORM_ref_addr
:
8578 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8579 and later it is offset sized. */
8580 if (cu
->header
.version
== 2)
8581 info_ptr
+= cu
->header
.addr_size
;
8583 info_ptr
+= cu
->header
.offset_size
;
8585 case DW_FORM_GNU_ref_alt
:
8586 info_ptr
+= cu
->header
.offset_size
;
8589 info_ptr
+= cu
->header
.addr_size
;
8597 case DW_FORM_flag_present
:
8598 case DW_FORM_implicit_const
:
8615 case DW_FORM_ref_sig8
:
8618 case DW_FORM_data16
:
8621 case DW_FORM_string
:
8622 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8623 info_ptr
+= bytes_read
;
8625 case DW_FORM_sec_offset
:
8627 case DW_FORM_GNU_strp_alt
:
8628 info_ptr
+= cu
->header
.offset_size
;
8630 case DW_FORM_exprloc
:
8632 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8633 info_ptr
+= bytes_read
;
8635 case DW_FORM_block1
:
8636 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8638 case DW_FORM_block2
:
8639 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8641 case DW_FORM_block4
:
8642 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8648 case DW_FORM_ref_udata
:
8649 case DW_FORM_GNU_addr_index
:
8650 case DW_FORM_GNU_str_index
:
8651 case DW_FORM_rnglistx
:
8652 case DW_FORM_loclistx
:
8653 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8655 case DW_FORM_indirect
:
8656 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8657 info_ptr
+= bytes_read
;
8658 /* We need to continue parsing from here, so just go back to
8660 goto skip_attribute
;
8663 error (_("Dwarf Error: Cannot handle %s "
8664 "in DWARF reader [in module %s]"),
8665 dwarf_form_name (form
),
8666 bfd_get_filename (abfd
));
8670 if (abbrev
->has_children
)
8671 return skip_children (reader
, info_ptr
);
8676 /* Locate ORIG_PDI's sibling.
8677 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8679 static const gdb_byte
*
8680 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8681 struct partial_die_info
*orig_pdi
,
8682 const gdb_byte
*info_ptr
)
8684 /* Do we know the sibling already? */
8686 if (orig_pdi
->sibling
)
8687 return orig_pdi
->sibling
;
8689 /* Are there any children to deal with? */
8691 if (!orig_pdi
->has_children
)
8694 /* Skip the children the long way. */
8696 return skip_children (reader
, info_ptr
);
8699 /* Expand this partial symbol table into a full symbol table. SELF is
8703 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
8705 struct dwarf2_per_objfile
*dwarf2_per_objfile
8706 = get_dwarf2_per_objfile (objfile
);
8708 gdb_assert (!readin
);
8709 /* If this psymtab is constructed from a debug-only objfile, the
8710 has_section_at_zero flag will not necessarily be correct. We
8711 can get the correct value for this flag by looking at the data
8712 associated with the (presumably stripped) associated objfile. */
8713 if (objfile
->separate_debug_objfile_backlink
)
8715 struct dwarf2_per_objfile
*dpo_backlink
8716 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
8718 dwarf2_per_objfile
->has_section_at_zero
8719 = dpo_backlink
->has_section_at_zero
;
8722 expand_psymtab (objfile
);
8724 process_cu_includes (dwarf2_per_objfile
);
8727 /* Reading in full CUs. */
8729 /* Add PER_CU to the queue. */
8732 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
8733 enum language pretend_language
)
8736 per_cu
->dwarf2_per_objfile
->queue
.emplace (per_cu
, pretend_language
);
8739 /* If PER_CU is not yet queued, add it to the queue.
8740 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
8742 The result is non-zero if PER_CU was queued, otherwise the result is zero
8743 meaning either PER_CU is already queued or it is already loaded.
8745 N.B. There is an invariant here that if a CU is queued then it is loaded.
8746 The caller is required to load PER_CU if we return non-zero. */
8749 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
8750 struct dwarf2_per_cu_data
*per_cu
,
8751 enum language pretend_language
)
8753 /* We may arrive here during partial symbol reading, if we need full
8754 DIEs to process an unusual case (e.g. template arguments). Do
8755 not queue PER_CU, just tell our caller to load its DIEs. */
8756 if (per_cu
->dwarf2_per_objfile
->reading_partial_symbols
)
8758 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
8763 /* Mark the dependence relation so that we don't flush PER_CU
8765 if (dependent_cu
!= NULL
)
8766 dwarf2_add_dependence (dependent_cu
, per_cu
);
8768 /* If it's already on the queue, we have nothing to do. */
8772 /* If the compilation unit is already loaded, just mark it as
8774 if (per_cu
->cu
!= NULL
)
8776 per_cu
->cu
->last_used
= 0;
8780 /* Add it to the queue. */
8781 queue_comp_unit (per_cu
, pretend_language
);
8786 /* Process the queue. */
8789 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8791 if (dwarf_read_debug
)
8793 fprintf_unfiltered (gdb_stdlog
,
8794 "Expanding one or more symtabs of objfile %s ...\n",
8795 objfile_name (dwarf2_per_objfile
->objfile
));
8798 /* The queue starts out with one item, but following a DIE reference
8799 may load a new CU, adding it to the end of the queue. */
8800 while (!dwarf2_per_objfile
->queue
.empty ())
8802 dwarf2_queue_item
&item
= dwarf2_per_objfile
->queue
.front ();
8804 if ((dwarf2_per_objfile
->using_index
8805 ? !item
.per_cu
->v
.quick
->compunit_symtab
8806 : (item
.per_cu
->v
.psymtab
&& !item
.per_cu
->v
.psymtab
->readin
))
8807 /* Skip dummy CUs. */
8808 && item
.per_cu
->cu
!= NULL
)
8810 struct dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
8811 unsigned int debug_print_threshold
;
8814 if (per_cu
->is_debug_types
)
8816 struct signatured_type
*sig_type
=
8817 (struct signatured_type
*) per_cu
;
8819 sprintf (buf
, "TU %s at offset %s",
8820 hex_string (sig_type
->signature
),
8821 sect_offset_str (per_cu
->sect_off
));
8822 /* There can be 100s of TUs.
8823 Only print them in verbose mode. */
8824 debug_print_threshold
= 2;
8828 sprintf (buf
, "CU at offset %s",
8829 sect_offset_str (per_cu
->sect_off
));
8830 debug_print_threshold
= 1;
8833 if (dwarf_read_debug
>= debug_print_threshold
)
8834 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
8836 if (per_cu
->is_debug_types
)
8837 process_full_type_unit (per_cu
, item
.pretend_language
);
8839 process_full_comp_unit (per_cu
, item
.pretend_language
);
8841 if (dwarf_read_debug
>= debug_print_threshold
)
8842 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
8845 item
.per_cu
->queued
= 0;
8846 dwarf2_per_objfile
->queue
.pop ();
8849 if (dwarf_read_debug
)
8851 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
8852 objfile_name (dwarf2_per_objfile
->objfile
));
8856 /* Read in full symbols for PST, and anything it depends on. */
8859 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
8864 expand_dependencies (objfile
);
8866 dw2_do_instantiate_symtab (per_cu_data
, false);
8867 gdb_assert (get_compunit_symtab () != nullptr);
8870 /* Trivial hash function for die_info: the hash value of a DIE
8871 is its offset in .debug_info for this objfile. */
8874 die_hash (const void *item
)
8876 const struct die_info
*die
= (const struct die_info
*) item
;
8878 return to_underlying (die
->sect_off
);
8881 /* Trivial comparison function for die_info structures: two DIEs
8882 are equal if they have the same offset. */
8885 die_eq (const void *item_lhs
, const void *item_rhs
)
8887 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
8888 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
8890 return die_lhs
->sect_off
== die_rhs
->sect_off
;
8893 /* Load the DIEs associated with PER_CU into memory. */
8896 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8898 enum language pretend_language
)
8900 gdb_assert (! this_cu
->is_debug_types
);
8902 cutu_reader
reader (this_cu
, NULL
, 1, skip_partial
);
8906 struct dwarf2_cu
*cu
= reader
.cu
;
8907 const gdb_byte
*info_ptr
= reader
.info_ptr
;
8909 gdb_assert (cu
->die_hash
== NULL
);
8911 htab_create_alloc_ex (cu
->header
.length
/ 12,
8915 &cu
->comp_unit_obstack
,
8916 hashtab_obstack_allocate
,
8917 dummy_obstack_deallocate
);
8919 if (reader
.comp_unit_die
->has_children
)
8920 reader
.comp_unit_die
->child
8921 = read_die_and_siblings (&reader
, reader
.info_ptr
,
8922 &info_ptr
, reader
.comp_unit_die
);
8923 cu
->dies
= reader
.comp_unit_die
;
8924 /* comp_unit_die is not stored in die_hash, no need. */
8926 /* We try not to read any attributes in this function, because not
8927 all CUs needed for references have been loaded yet, and symbol
8928 table processing isn't initialized. But we have to set the CU language,
8929 or we won't be able to build types correctly.
8930 Similarly, if we do not read the producer, we can not apply
8931 producer-specific interpretation. */
8932 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
8937 /* Add a DIE to the delayed physname list. */
8940 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
8941 const char *name
, struct die_info
*die
,
8942 struct dwarf2_cu
*cu
)
8944 struct delayed_method_info mi
;
8946 mi
.fnfield_index
= fnfield_index
;
8950 cu
->method_list
.push_back (mi
);
8953 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
8954 "const" / "volatile". If so, decrements LEN by the length of the
8955 modifier and return true. Otherwise return false. */
8959 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
8961 size_t mod_len
= sizeof (mod
) - 1;
8962 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
8970 /* Compute the physnames of any methods on the CU's method list.
8972 The computation of method physnames is delayed in order to avoid the
8973 (bad) condition that one of the method's formal parameters is of an as yet
8977 compute_delayed_physnames (struct dwarf2_cu
*cu
)
8979 /* Only C++ delays computing physnames. */
8980 if (cu
->method_list
.empty ())
8982 gdb_assert (cu
->language
== language_cplus
);
8984 for (const delayed_method_info
&mi
: cu
->method_list
)
8986 const char *physname
;
8987 struct fn_fieldlist
*fn_flp
8988 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
8989 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
8990 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
8991 = physname
? physname
: "";
8993 /* Since there's no tag to indicate whether a method is a
8994 const/volatile overload, extract that information out of the
8996 if (physname
!= NULL
)
8998 size_t len
= strlen (physname
);
9002 if (physname
[len
] == ')') /* shortcut */
9004 else if (check_modifier (physname
, len
, " const"))
9005 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9006 else if (check_modifier (physname
, len
, " volatile"))
9007 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9014 /* The list is no longer needed. */
9015 cu
->method_list
.clear ();
9018 /* Go objects should be embedded in a DW_TAG_module DIE,
9019 and it's not clear if/how imported objects will appear.
9020 To keep Go support simple until that's worked out,
9021 go back through what we've read and create something usable.
9022 We could do this while processing each DIE, and feels kinda cleaner,
9023 but that way is more invasive.
9024 This is to, for example, allow the user to type "p var" or "b main"
9025 without having to specify the package name, and allow lookups
9026 of module.object to work in contexts that use the expression
9030 fixup_go_packaging (struct dwarf2_cu
*cu
)
9032 gdb::unique_xmalloc_ptr
<char> package_name
;
9033 struct pending
*list
;
9036 for (list
= *cu
->get_builder ()->get_global_symbols ();
9040 for (i
= 0; i
< list
->nsyms
; ++i
)
9042 struct symbol
*sym
= list
->symbol
[i
];
9044 if (sym
->language () == language_go
9045 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9047 gdb::unique_xmalloc_ptr
<char> this_package_name
9048 (go_symbol_package_name (sym
));
9050 if (this_package_name
== NULL
)
9052 if (package_name
== NULL
)
9053 package_name
= std::move (this_package_name
);
9056 struct objfile
*objfile
9057 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9058 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9059 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9060 (symbol_symtab (sym
) != NULL
9061 ? symtab_to_filename_for_display
9062 (symbol_symtab (sym
))
9063 : objfile_name (objfile
)),
9064 this_package_name
.get (), package_name
.get ());
9070 if (package_name
!= NULL
)
9072 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9073 const char *saved_package_name
= objfile
->intern (package_name
.get ());
9074 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9075 saved_package_name
);
9078 sym
= allocate_symbol (objfile
);
9079 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9080 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9081 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9082 e.g., "main" finds the "main" module and not C's main(). */
9083 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9084 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9085 SYMBOL_TYPE (sym
) = type
;
9087 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9091 /* Allocate a fully-qualified name consisting of the two parts on the
9095 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9097 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9100 /* A helper that allocates a struct discriminant_info to attach to a
9103 static struct discriminant_info
*
9104 alloc_discriminant_info (struct type
*type
, int discriminant_index
,
9107 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9108 gdb_assert (discriminant_index
== -1
9109 || (discriminant_index
>= 0
9110 && discriminant_index
< TYPE_NFIELDS (type
)));
9111 gdb_assert (default_index
== -1
9112 || (default_index
>= 0 && default_index
< TYPE_NFIELDS (type
)));
9114 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
9116 struct discriminant_info
*disc
9117 = ((struct discriminant_info
*)
9119 offsetof (struct discriminant_info
, discriminants
)
9120 + TYPE_NFIELDS (type
) * sizeof (disc
->discriminants
[0])));
9121 disc
->default_index
= default_index
;
9122 disc
->discriminant_index
= discriminant_index
;
9124 struct dynamic_prop prop
;
9125 prop
.kind
= PROP_UNDEFINED
;
9126 prop
.data
.baton
= disc
;
9128 add_dyn_prop (DYN_PROP_DISCRIMINATED
, prop
, type
);
9133 /* Some versions of rustc emitted enums in an unusual way.
9135 Ordinary enums were emitted as unions. The first element of each
9136 structure in the union was named "RUST$ENUM$DISR". This element
9137 held the discriminant.
9139 These versions of Rust also implemented the "non-zero"
9140 optimization. When the enum had two values, and one is empty and
9141 the other holds a pointer that cannot be zero, the pointer is used
9142 as the discriminant, with a zero value meaning the empty variant.
9143 Here, the union's first member is of the form
9144 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9145 where the fieldnos are the indices of the fields that should be
9146 traversed in order to find the field (which may be several fields deep)
9147 and the variantname is the name of the variant of the case when the
9150 This function recognizes whether TYPE is of one of these forms,
9151 and, if so, smashes it to be a variant type. */
9154 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9156 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9158 /* We don't need to deal with empty enums. */
9159 if (TYPE_NFIELDS (type
) == 0)
9162 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9163 if (TYPE_NFIELDS (type
) == 1
9164 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9166 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9168 /* Decode the field name to find the offset of the
9170 ULONGEST bit_offset
= 0;
9171 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9172 while (name
[0] >= '0' && name
[0] <= '9')
9175 unsigned long index
= strtoul (name
, &tail
, 10);
9178 || index
>= TYPE_NFIELDS (field_type
)
9179 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9180 != FIELD_LOC_KIND_BITPOS
))
9182 complaint (_("Could not parse Rust enum encoding string \"%s\""
9184 TYPE_FIELD_NAME (type
, 0),
9185 objfile_name (objfile
));
9190 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9191 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
9194 /* Make a union to hold the variants. */
9195 struct type
*union_type
= alloc_type (objfile
);
9196 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9197 TYPE_NFIELDS (union_type
) = 3;
9198 TYPE_FIELDS (union_type
)
9199 = (struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
));
9200 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9201 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9203 /* Put the discriminant must at index 0. */
9204 TYPE_FIELD_TYPE (union_type
, 0) = field_type
;
9205 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
9206 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
9207 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 0), bit_offset
);
9209 /* The order of fields doesn't really matter, so put the real
9210 field at index 1 and the data-less field at index 2. */
9211 struct discriminant_info
*disc
9212 = alloc_discriminant_info (union_type
, 0, 1);
9213 TYPE_FIELD (union_type
, 1) = TYPE_FIELD (type
, 0);
9214 TYPE_FIELD_NAME (union_type
, 1)
9215 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1)));
9216 TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1))
9217 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9218 TYPE_FIELD_NAME (union_type
, 1));
9220 const char *dataless_name
9221 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9223 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9225 TYPE_FIELD_TYPE (union_type
, 2) = dataless_type
;
9226 /* NAME points into the original discriminant name, which
9227 already has the correct lifetime. */
9228 TYPE_FIELD_NAME (union_type
, 2) = name
;
9229 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 2), 0);
9230 disc
->discriminants
[2] = 0;
9232 /* Smash this type to be a structure type. We have to do this
9233 because the type has already been recorded. */
9234 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9235 TYPE_NFIELDS (type
) = 1;
9237 = (struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
));
9239 /* Install the variant part. */
9240 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9241 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9242 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9244 /* A union with a single anonymous field is probably an old-style
9246 else if (TYPE_NFIELDS (type
) == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
9248 /* Smash this type to be a structure type. We have to do this
9249 because the type has already been recorded. */
9250 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9252 /* Make a union to hold the variants. */
9253 struct type
*union_type
= alloc_type (objfile
);
9254 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9255 TYPE_NFIELDS (union_type
) = TYPE_NFIELDS (type
);
9256 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9257 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9258 TYPE_FIELDS (union_type
) = TYPE_FIELDS (type
);
9260 struct type
*field_type
= TYPE_FIELD_TYPE (union_type
, 0);
9261 const char *variant_name
9262 = rust_last_path_segment (TYPE_NAME (field_type
));
9263 TYPE_FIELD_NAME (union_type
, 0) = variant_name
;
9264 TYPE_NAME (field_type
)
9265 = rust_fully_qualify (&objfile
->objfile_obstack
,
9266 TYPE_NAME (type
), variant_name
);
9268 /* Install the union in the outer struct type. */
9269 TYPE_NFIELDS (type
) = 1;
9271 = (struct field
*) TYPE_ZALLOC (union_type
, sizeof (struct field
));
9272 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9273 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9274 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9276 alloc_discriminant_info (union_type
, -1, 0);
9280 struct type
*disr_type
= nullptr;
9281 for (int i
= 0; i
< TYPE_NFIELDS (type
); ++i
)
9283 disr_type
= TYPE_FIELD_TYPE (type
, i
);
9285 if (TYPE_CODE (disr_type
) != TYPE_CODE_STRUCT
)
9287 /* All fields of a true enum will be structs. */
9290 else if (TYPE_NFIELDS (disr_type
) == 0)
9292 /* Could be data-less variant, so keep going. */
9293 disr_type
= nullptr;
9295 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9296 "RUST$ENUM$DISR") != 0)
9298 /* Not a Rust enum. */
9308 /* If we got here without a discriminant, then it's probably
9310 if (disr_type
== nullptr)
9313 /* Smash this type to be a structure type. We have to do this
9314 because the type has already been recorded. */
9315 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9317 /* Make a union to hold the variants. */
9318 struct field
*disr_field
= &TYPE_FIELD (disr_type
, 0);
9319 struct type
*union_type
= alloc_type (objfile
);
9320 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9321 TYPE_NFIELDS (union_type
) = 1 + TYPE_NFIELDS (type
);
9322 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9323 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9324 TYPE_FIELDS (union_type
)
9325 = (struct field
*) TYPE_ZALLOC (union_type
,
9326 (TYPE_NFIELDS (union_type
)
9327 * sizeof (struct field
)));
9329 memcpy (TYPE_FIELDS (union_type
) + 1, TYPE_FIELDS (type
),
9330 TYPE_NFIELDS (type
) * sizeof (struct field
));
9332 /* Install the discriminant at index 0 in the union. */
9333 TYPE_FIELD (union_type
, 0) = *disr_field
;
9334 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
9335 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
9337 /* Install the union in the outer struct type. */
9338 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9339 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9340 TYPE_NFIELDS (type
) = 1;
9342 /* Set the size and offset of the union type. */
9343 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9345 /* We need a way to find the correct discriminant given a
9346 variant name. For convenience we build a map here. */
9347 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
9348 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9349 for (int i
= 0; i
< TYPE_NFIELDS (enum_type
); ++i
)
9351 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9354 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9355 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9359 int n_fields
= TYPE_NFIELDS (union_type
);
9360 struct discriminant_info
*disc
9361 = alloc_discriminant_info (union_type
, 0, -1);
9362 /* Skip the discriminant here. */
9363 for (int i
= 1; i
< n_fields
; ++i
)
9365 /* Find the final word in the name of this variant's type.
9366 That name can be used to look up the correct
9368 const char *variant_name
9369 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
,
9372 auto iter
= discriminant_map
.find (variant_name
);
9373 if (iter
!= discriminant_map
.end ())
9374 disc
->discriminants
[i
] = iter
->second
;
9376 /* Remove the discriminant field, if it exists. */
9377 struct type
*sub_type
= TYPE_FIELD_TYPE (union_type
, i
);
9378 if (TYPE_NFIELDS (sub_type
) > 0)
9380 --TYPE_NFIELDS (sub_type
);
9381 ++TYPE_FIELDS (sub_type
);
9383 TYPE_FIELD_NAME (union_type
, i
) = variant_name
;
9384 TYPE_NAME (sub_type
)
9385 = rust_fully_qualify (&objfile
->objfile_obstack
,
9386 TYPE_NAME (type
), variant_name
);
9391 /* Rewrite some Rust unions to be structures with variants parts. */
9394 rust_union_quirks (struct dwarf2_cu
*cu
)
9396 gdb_assert (cu
->language
== language_rust
);
9397 for (type
*type_
: cu
->rust_unions
)
9398 quirk_rust_enum (type_
, cu
->per_cu
->dwarf2_per_objfile
->objfile
);
9399 /* We don't need this any more. */
9400 cu
->rust_unions
.clear ();
9403 /* Return the symtab for PER_CU. This works properly regardless of
9404 whether we're using the index or psymtabs. */
9406 static struct compunit_symtab
*
9407 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
9409 return (per_cu
->dwarf2_per_objfile
->using_index
9410 ? per_cu
->v
.quick
->compunit_symtab
9411 : per_cu
->v
.psymtab
->compunit_symtab
);
9414 /* A helper function for computing the list of all symbol tables
9415 included by PER_CU. */
9418 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9419 htab_t all_children
, htab_t all_type_symtabs
,
9420 struct dwarf2_per_cu_data
*per_cu
,
9421 struct compunit_symtab
*immediate_parent
)
9424 struct compunit_symtab
*cust
;
9426 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9429 /* This inclusion and its children have been processed. */
9434 /* Only add a CU if it has a symbol table. */
9435 cust
= get_compunit_symtab (per_cu
);
9438 /* If this is a type unit only add its symbol table if we haven't
9439 seen it yet (type unit per_cu's can share symtabs). */
9440 if (per_cu
->is_debug_types
)
9442 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9446 result
->push_back (cust
);
9447 if (cust
->user
== NULL
)
9448 cust
->user
= immediate_parent
;
9453 result
->push_back (cust
);
9454 if (cust
->user
== NULL
)
9455 cust
->user
= immediate_parent
;
9459 if (!per_cu
->imported_symtabs_empty ())
9460 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9462 recursively_compute_inclusions (result
, all_children
,
9463 all_type_symtabs
, ptr
, cust
);
9467 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9471 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
9473 gdb_assert (! per_cu
->is_debug_types
);
9475 if (!per_cu
->imported_symtabs_empty ())
9478 std::vector
<compunit_symtab
*> result_symtabs
;
9479 htab_t all_children
, all_type_symtabs
;
9480 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
9482 /* If we don't have a symtab, we can just skip this case. */
9486 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9487 NULL
, xcalloc
, xfree
);
9488 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9489 NULL
, xcalloc
, xfree
);
9491 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9493 recursively_compute_inclusions (&result_symtabs
, all_children
,
9494 all_type_symtabs
, ptr
, cust
);
9497 /* Now we have a transitive closure of all the included symtabs. */
9498 len
= result_symtabs
.size ();
9500 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
9501 struct compunit_symtab
*, len
+ 1);
9502 memcpy (cust
->includes
, result_symtabs
.data (),
9503 len
* sizeof (compunit_symtab
*));
9504 cust
->includes
[len
] = NULL
;
9506 htab_delete (all_children
);
9507 htab_delete (all_type_symtabs
);
9511 /* Compute the 'includes' field for the symtabs of all the CUs we just
9515 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9517 for (dwarf2_per_cu_data
*iter
: dwarf2_per_objfile
->just_read_cus
)
9519 if (! iter
->is_debug_types
)
9520 compute_compunit_symtab_includes (iter
);
9523 dwarf2_per_objfile
->just_read_cus
.clear ();
9526 /* Generate full symbol information for PER_CU, whose DIEs have
9527 already been loaded into memory. */
9530 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9531 enum language pretend_language
)
9533 struct dwarf2_cu
*cu
= per_cu
->cu
;
9534 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
9535 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9536 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9537 CORE_ADDR lowpc
, highpc
;
9538 struct compunit_symtab
*cust
;
9540 struct block
*static_block
;
9543 baseaddr
= objfile
->text_section_offset ();
9545 /* Clear the list here in case something was left over. */
9546 cu
->method_list
.clear ();
9548 cu
->language
= pretend_language
;
9549 cu
->language_defn
= language_def (cu
->language
);
9551 /* Do line number decoding in read_file_scope () */
9552 process_die (cu
->dies
, cu
);
9554 /* For now fudge the Go package. */
9555 if (cu
->language
== language_go
)
9556 fixup_go_packaging (cu
);
9558 /* Now that we have processed all the DIEs in the CU, all the types
9559 should be complete, and it should now be safe to compute all of the
9561 compute_delayed_physnames (cu
);
9563 if (cu
->language
== language_rust
)
9564 rust_union_quirks (cu
);
9566 /* Some compilers don't define a DW_AT_high_pc attribute for the
9567 compilation unit. If the DW_AT_high_pc is missing, synthesize
9568 it, by scanning the DIE's below the compilation unit. */
9569 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9571 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9572 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
9574 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9575 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9576 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9577 addrmap to help ensure it has an accurate map of pc values belonging to
9579 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9581 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
9582 SECT_OFF_TEXT (objfile
),
9587 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9589 /* Set symtab language to language from DW_AT_language. If the
9590 compilation is from a C file generated by language preprocessors, do
9591 not set the language if it was already deduced by start_subfile. */
9592 if (!(cu
->language
== language_c
9593 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
9594 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9596 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9597 produce DW_AT_location with location lists but it can be possibly
9598 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9599 there were bugs in prologue debug info, fixed later in GCC-4.5
9600 by "unwind info for epilogues" patch (which is not directly related).
9602 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9603 needed, it would be wrong due to missing DW_AT_producer there.
9605 Still one can confuse GDB by using non-standard GCC compilation
9606 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9608 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9609 cust
->locations_valid
= 1;
9611 if (gcc_4_minor
>= 5)
9612 cust
->epilogue_unwind_valid
= 1;
9614 cust
->call_site_htab
= cu
->call_site_htab
;
9617 if (dwarf2_per_objfile
->using_index
)
9618 per_cu
->v
.quick
->compunit_symtab
= cust
;
9621 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
9622 pst
->compunit_symtab
= cust
;
9626 /* Push it for inclusion processing later. */
9627 dwarf2_per_objfile
->just_read_cus
.push_back (per_cu
);
9629 /* Not needed any more. */
9630 cu
->reset_builder ();
9633 /* Generate full symbol information for type unit PER_CU, whose DIEs have
9634 already been loaded into memory. */
9637 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
9638 enum language pretend_language
)
9640 struct dwarf2_cu
*cu
= per_cu
->cu
;
9641 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
9642 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9643 struct compunit_symtab
*cust
;
9644 struct signatured_type
*sig_type
;
9646 gdb_assert (per_cu
->is_debug_types
);
9647 sig_type
= (struct signatured_type
*) per_cu
;
9649 /* Clear the list here in case something was left over. */
9650 cu
->method_list
.clear ();
9652 cu
->language
= pretend_language
;
9653 cu
->language_defn
= language_def (cu
->language
);
9655 /* The symbol tables are set up in read_type_unit_scope. */
9656 process_die (cu
->dies
, cu
);
9658 /* For now fudge the Go package. */
9659 if (cu
->language
== language_go
)
9660 fixup_go_packaging (cu
);
9662 /* Now that we have processed all the DIEs in the CU, all the types
9663 should be complete, and it should now be safe to compute all of the
9665 compute_delayed_physnames (cu
);
9667 if (cu
->language
== language_rust
)
9668 rust_union_quirks (cu
);
9670 /* TUs share symbol tables.
9671 If this is the first TU to use this symtab, complete the construction
9672 of it with end_expandable_symtab. Otherwise, complete the addition of
9673 this TU's symbols to the existing symtab. */
9674 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
9676 buildsym_compunit
*builder
= cu
->get_builder ();
9677 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
9678 sig_type
->type_unit_group
->compunit_symtab
= cust
;
9682 /* Set symtab language to language from DW_AT_language. If the
9683 compilation is from a C file generated by language preprocessors,
9684 do not set the language if it was already deduced by
9686 if (!(cu
->language
== language_c
9687 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
9688 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9693 cu
->get_builder ()->augment_type_symtab ();
9694 cust
= sig_type
->type_unit_group
->compunit_symtab
;
9697 if (dwarf2_per_objfile
->using_index
)
9698 per_cu
->v
.quick
->compunit_symtab
= cust
;
9701 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
9702 pst
->compunit_symtab
= cust
;
9706 /* Not needed any more. */
9707 cu
->reset_builder ();
9710 /* Process an imported unit DIE. */
9713 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9715 struct attribute
*attr
;
9717 /* For now we don't handle imported units in type units. */
9718 if (cu
->per_cu
->is_debug_types
)
9720 error (_("Dwarf Error: DW_TAG_imported_unit is not"
9721 " supported in type units [in module %s]"),
9722 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
9725 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
9728 sect_offset sect_off
= attr
->get_ref_die_offset ();
9729 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
9730 dwarf2_per_cu_data
*per_cu
9731 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
9732 cu
->per_cu
->dwarf2_per_objfile
);
9734 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
9735 into another compilation unit, at root level. Regard this as a hint,
9737 if (die
->parent
&& die
->parent
->parent
== NULL
9738 && per_cu
->unit_type
== DW_UT_compile
9739 && per_cu
->lang
== language_cplus
)
9742 /* If necessary, add it to the queue and load its DIEs. */
9743 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
9744 load_full_comp_unit (per_cu
, false, cu
->language
);
9746 cu
->per_cu
->imported_symtabs_push (per_cu
);
9750 /* RAII object that represents a process_die scope: i.e.,
9751 starts/finishes processing a DIE. */
9752 class process_die_scope
9755 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
9756 : m_die (die
), m_cu (cu
)
9758 /* We should only be processing DIEs not already in process. */
9759 gdb_assert (!m_die
->in_process
);
9760 m_die
->in_process
= true;
9763 ~process_die_scope ()
9765 m_die
->in_process
= false;
9767 /* If we're done processing the DIE for the CU that owns the line
9768 header, we don't need the line header anymore. */
9769 if (m_cu
->line_header_die_owner
== m_die
)
9771 delete m_cu
->line_header
;
9772 m_cu
->line_header
= NULL
;
9773 m_cu
->line_header_die_owner
= NULL
;
9782 /* Process a die and its children. */
9785 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9787 process_die_scope
scope (die
, cu
);
9791 case DW_TAG_padding
:
9793 case DW_TAG_compile_unit
:
9794 case DW_TAG_partial_unit
:
9795 read_file_scope (die
, cu
);
9797 case DW_TAG_type_unit
:
9798 read_type_unit_scope (die
, cu
);
9800 case DW_TAG_subprogram
:
9801 /* Nested subprograms in Fortran get a prefix. */
9802 if (cu
->language
== language_fortran
9803 && die
->parent
!= NULL
9804 && die
->parent
->tag
== DW_TAG_subprogram
)
9805 cu
->processing_has_namespace_info
= true;
9807 case DW_TAG_inlined_subroutine
:
9808 read_func_scope (die
, cu
);
9810 case DW_TAG_lexical_block
:
9811 case DW_TAG_try_block
:
9812 case DW_TAG_catch_block
:
9813 read_lexical_block_scope (die
, cu
);
9815 case DW_TAG_call_site
:
9816 case DW_TAG_GNU_call_site
:
9817 read_call_site_scope (die
, cu
);
9819 case DW_TAG_class_type
:
9820 case DW_TAG_interface_type
:
9821 case DW_TAG_structure_type
:
9822 case DW_TAG_union_type
:
9823 process_structure_scope (die
, cu
);
9825 case DW_TAG_enumeration_type
:
9826 process_enumeration_scope (die
, cu
);
9829 /* These dies have a type, but processing them does not create
9830 a symbol or recurse to process the children. Therefore we can
9831 read them on-demand through read_type_die. */
9832 case DW_TAG_subroutine_type
:
9833 case DW_TAG_set_type
:
9834 case DW_TAG_array_type
:
9835 case DW_TAG_pointer_type
:
9836 case DW_TAG_ptr_to_member_type
:
9837 case DW_TAG_reference_type
:
9838 case DW_TAG_rvalue_reference_type
:
9839 case DW_TAG_string_type
:
9842 case DW_TAG_base_type
:
9843 case DW_TAG_subrange_type
:
9844 case DW_TAG_typedef
:
9845 /* Add a typedef symbol for the type definition, if it has a
9847 new_symbol (die
, read_type_die (die
, cu
), cu
);
9849 case DW_TAG_common_block
:
9850 read_common_block (die
, cu
);
9852 case DW_TAG_common_inclusion
:
9854 case DW_TAG_namespace
:
9855 cu
->processing_has_namespace_info
= true;
9856 read_namespace (die
, cu
);
9859 cu
->processing_has_namespace_info
= true;
9860 read_module (die
, cu
);
9862 case DW_TAG_imported_declaration
:
9863 cu
->processing_has_namespace_info
= true;
9864 if (read_namespace_alias (die
, cu
))
9866 /* The declaration is not a global namespace alias. */
9868 case DW_TAG_imported_module
:
9869 cu
->processing_has_namespace_info
= true;
9870 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
9871 || cu
->language
!= language_fortran
))
9872 complaint (_("Tag '%s' has unexpected children"),
9873 dwarf_tag_name (die
->tag
));
9874 read_import_statement (die
, cu
);
9877 case DW_TAG_imported_unit
:
9878 process_imported_unit_die (die
, cu
);
9881 case DW_TAG_variable
:
9882 read_variable (die
, cu
);
9886 new_symbol (die
, NULL
, cu
);
9891 /* DWARF name computation. */
9893 /* A helper function for dwarf2_compute_name which determines whether DIE
9894 needs to have the name of the scope prepended to the name listed in the
9898 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
9900 struct attribute
*attr
;
9904 case DW_TAG_namespace
:
9905 case DW_TAG_typedef
:
9906 case DW_TAG_class_type
:
9907 case DW_TAG_interface_type
:
9908 case DW_TAG_structure_type
:
9909 case DW_TAG_union_type
:
9910 case DW_TAG_enumeration_type
:
9911 case DW_TAG_enumerator
:
9912 case DW_TAG_subprogram
:
9913 case DW_TAG_inlined_subroutine
:
9915 case DW_TAG_imported_declaration
:
9918 case DW_TAG_variable
:
9919 case DW_TAG_constant
:
9920 /* We only need to prefix "globally" visible variables. These include
9921 any variable marked with DW_AT_external or any variable that
9922 lives in a namespace. [Variables in anonymous namespaces
9923 require prefixing, but they are not DW_AT_external.] */
9925 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
9927 struct dwarf2_cu
*spec_cu
= cu
;
9929 return die_needs_namespace (die_specification (die
, &spec_cu
),
9933 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
9934 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
9935 && die
->parent
->tag
!= DW_TAG_module
)
9937 /* A variable in a lexical block of some kind does not need a
9938 namespace, even though in C++ such variables may be external
9939 and have a mangled name. */
9940 if (die
->parent
->tag
== DW_TAG_lexical_block
9941 || die
->parent
->tag
== DW_TAG_try_block
9942 || die
->parent
->tag
== DW_TAG_catch_block
9943 || die
->parent
->tag
== DW_TAG_subprogram
)
9952 /* Return the DIE's linkage name attribute, 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. */
9956 static struct attribute
*
9957 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
9959 struct attribute
*attr
;
9961 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
9963 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9968 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
9969 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9970 defined for the given DIE. */
9973 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
9975 const char *linkage_name
;
9977 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
9978 if (linkage_name
== NULL
)
9979 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9981 return linkage_name
;
9984 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
9985 compute the physname for the object, which include a method's:
9986 - formal parameters (C++),
9987 - receiver type (Go),
9989 The term "physname" is a bit confusing.
9990 For C++, for example, it is the demangled name.
9991 For Go, for example, it's the mangled name.
9993 For Ada, return the DIE's linkage name rather than the fully qualified
9994 name. PHYSNAME is ignored..
9996 The result is allocated on the objfile_obstack and canonicalized. */
9999 dwarf2_compute_name (const char *name
,
10000 struct die_info
*die
, struct dwarf2_cu
*cu
,
10003 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10006 name
= dwarf2_name (die
, cu
);
10008 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10009 but otherwise compute it by typename_concat inside GDB.
10010 FIXME: Actually this is not really true, or at least not always true.
10011 It's all very confusing. compute_and_set_names doesn't try to demangle
10012 Fortran names because there is no mangling standard. So new_symbol
10013 will set the demangled name to the result of dwarf2_full_name, and it is
10014 the demangled name that GDB uses if it exists. */
10015 if (cu
->language
== language_ada
10016 || (cu
->language
== language_fortran
&& physname
))
10018 /* For Ada unit, we prefer the linkage name over the name, as
10019 the former contains the exported name, which the user expects
10020 to be able to reference. Ideally, we want the user to be able
10021 to reference this entity using either natural or linkage name,
10022 but we haven't started looking at this enhancement yet. */
10023 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10025 if (linkage_name
!= NULL
)
10026 return linkage_name
;
10029 /* These are the only languages we know how to qualify names in. */
10031 && (cu
->language
== language_cplus
10032 || cu
->language
== language_fortran
|| cu
->language
== language_d
10033 || cu
->language
== language_rust
))
10035 if (die_needs_namespace (die
, cu
))
10037 const char *prefix
;
10038 const char *canonical_name
= NULL
;
10042 prefix
= determine_prefix (die
, cu
);
10043 if (*prefix
!= '\0')
10045 gdb::unique_xmalloc_ptr
<char> prefixed_name
10046 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10048 buf
.puts (prefixed_name
.get ());
10053 /* Template parameters may be specified in the DIE's DW_AT_name, or
10054 as children with DW_TAG_template_type_param or
10055 DW_TAG_value_type_param. If the latter, add them to the name
10056 here. If the name already has template parameters, then
10057 skip this step; some versions of GCC emit both, and
10058 it is more efficient to use the pre-computed name.
10060 Something to keep in mind about this process: it is very
10061 unlikely, or in some cases downright impossible, to produce
10062 something that will match the mangled name of a function.
10063 If the definition of the function has the same debug info,
10064 we should be able to match up with it anyway. But fallbacks
10065 using the minimal symbol, for instance to find a method
10066 implemented in a stripped copy of libstdc++, will not work.
10067 If we do not have debug info for the definition, we will have to
10068 match them up some other way.
10070 When we do name matching there is a related problem with function
10071 templates; two instantiated function templates are allowed to
10072 differ only by their return types, which we do not add here. */
10074 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10076 struct attribute
*attr
;
10077 struct die_info
*child
;
10080 die
->building_fullname
= 1;
10082 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10086 const gdb_byte
*bytes
;
10087 struct dwarf2_locexpr_baton
*baton
;
10090 if (child
->tag
!= DW_TAG_template_type_param
10091 && child
->tag
!= DW_TAG_template_value_param
)
10102 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10105 complaint (_("template parameter missing DW_AT_type"));
10106 buf
.puts ("UNKNOWN_TYPE");
10109 type
= die_type (child
, cu
);
10111 if (child
->tag
== DW_TAG_template_type_param
)
10113 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10114 &type_print_raw_options
);
10118 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10121 complaint (_("template parameter missing "
10122 "DW_AT_const_value"));
10123 buf
.puts ("UNKNOWN_VALUE");
10127 dwarf2_const_value_attr (attr
, type
, name
,
10128 &cu
->comp_unit_obstack
, cu
,
10129 &value
, &bytes
, &baton
);
10131 if (TYPE_NOSIGN (type
))
10132 /* GDB prints characters as NUMBER 'CHAR'. If that's
10133 changed, this can use value_print instead. */
10134 c_printchar (value
, type
, &buf
);
10137 struct value_print_options opts
;
10140 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10144 else if (bytes
!= NULL
)
10146 v
= allocate_value (type
);
10147 memcpy (value_contents_writeable (v
), bytes
,
10148 TYPE_LENGTH (type
));
10151 v
= value_from_longest (type
, value
);
10153 /* Specify decimal so that we do not depend on
10155 get_formatted_print_options (&opts
, 'd');
10157 value_print (v
, &buf
, &opts
);
10162 die
->building_fullname
= 0;
10166 /* Close the argument list, with a space if necessary
10167 (nested templates). */
10168 if (!buf
.empty () && buf
.string ().back () == '>')
10175 /* For C++ methods, append formal parameter type
10176 information, if PHYSNAME. */
10178 if (physname
&& die
->tag
== DW_TAG_subprogram
10179 && cu
->language
== language_cplus
)
10181 struct type
*type
= read_type_die (die
, cu
);
10183 c_type_print_args (type
, &buf
, 1, cu
->language
,
10184 &type_print_raw_options
);
10186 if (cu
->language
== language_cplus
)
10188 /* Assume that an artificial first parameter is
10189 "this", but do not crash if it is not. RealView
10190 marks unnamed (and thus unused) parameters as
10191 artificial; there is no way to differentiate
10193 if (TYPE_NFIELDS (type
) > 0
10194 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10195 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
10196 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
10198 buf
.puts (" const");
10202 const std::string
&intermediate_name
= buf
.string ();
10204 if (cu
->language
== language_cplus
)
10206 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10209 /* If we only computed INTERMEDIATE_NAME, or if
10210 INTERMEDIATE_NAME is already canonical, then we need to
10212 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10213 name
= objfile
->intern (intermediate_name
);
10215 name
= canonical_name
;
10222 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10223 If scope qualifiers are appropriate they will be added. The result
10224 will be allocated on the storage_obstack, or NULL if the DIE does
10225 not have a name. NAME may either be from a previous call to
10226 dwarf2_name or NULL.
10228 The output string will be canonicalized (if C++). */
10230 static const char *
10231 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10233 return dwarf2_compute_name (name
, die
, cu
, 0);
10236 /* Construct a physname for the given DIE in CU. NAME may either be
10237 from a previous call to dwarf2_name or NULL. The result will be
10238 allocated on the objfile_objstack or NULL if the DIE does not have a
10241 The output string will be canonicalized (if C++). */
10243 static const char *
10244 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10246 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10247 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10250 /* In this case dwarf2_compute_name is just a shortcut not building anything
10252 if (!die_needs_namespace (die
, cu
))
10253 return dwarf2_compute_name (name
, die
, cu
, 1);
10255 mangled
= dw2_linkage_name (die
, cu
);
10257 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
10258 See https://github.com/rust-lang/rust/issues/32925. */
10259 if (cu
->language
== language_rust
&& mangled
!= NULL
10260 && strchr (mangled
, '{') != NULL
)
10263 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10265 gdb::unique_xmalloc_ptr
<char> demangled
;
10266 if (mangled
!= NULL
)
10269 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
10271 /* Do nothing (do not demangle the symbol name). */
10273 else if (cu
->language
== language_go
)
10275 /* This is a lie, but we already lie to the caller new_symbol.
10276 new_symbol assumes we return the mangled name.
10277 This just undoes that lie until things are cleaned up. */
10281 /* Use DMGL_RET_DROP for C++ template functions to suppress
10282 their return type. It is easier for GDB users to search
10283 for such functions as `name(params)' than `long name(params)'.
10284 In such case the minimal symbol names do not match the full
10285 symbol names but for template functions there is never a need
10286 to look up their definition from their declaration so
10287 the only disadvantage remains the minimal symbol variant
10288 `long name(params)' does not have the proper inferior type. */
10289 demangled
.reset (gdb_demangle (mangled
,
10290 (DMGL_PARAMS
| DMGL_ANSI
10291 | DMGL_RET_DROP
)));
10294 canon
= demangled
.get ();
10302 if (canon
== NULL
|| check_physname
)
10304 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10306 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10308 /* It may not mean a bug in GDB. The compiler could also
10309 compute DW_AT_linkage_name incorrectly. But in such case
10310 GDB would need to be bug-to-bug compatible. */
10312 complaint (_("Computed physname <%s> does not match demangled <%s> "
10313 "(from linkage <%s>) - DIE at %s [in module %s]"),
10314 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10315 objfile_name (objfile
));
10317 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10318 is available here - over computed PHYSNAME. It is safer
10319 against both buggy GDB and buggy compilers. */
10333 retval
= objfile
->intern (retval
);
10338 /* Inspect DIE in CU for a namespace alias. If one exists, record
10339 a new symbol for it.
10341 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10344 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10346 struct attribute
*attr
;
10348 /* If the die does not have a name, this is not a namespace
10350 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10354 struct die_info
*d
= die
;
10355 struct dwarf2_cu
*imported_cu
= cu
;
10357 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10358 keep inspecting DIEs until we hit the underlying import. */
10359 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10360 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10362 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10366 d
= follow_die_ref (d
, attr
, &imported_cu
);
10367 if (d
->tag
!= DW_TAG_imported_declaration
)
10371 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10373 complaint (_("DIE at %s has too many recursively imported "
10374 "declarations"), sect_offset_str (d
->sect_off
));
10381 sect_offset sect_off
= attr
->get_ref_die_offset ();
10383 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
10384 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
10386 /* This declaration is a global namespace alias. Add
10387 a symbol for it whose type is the aliased namespace. */
10388 new_symbol (die
, type
, cu
);
10397 /* Return the using directives repository (global or local?) to use in the
10398 current context for CU.
10400 For Ada, imported declarations can materialize renamings, which *may* be
10401 global. However it is impossible (for now?) in DWARF to distinguish
10402 "external" imported declarations and "static" ones. As all imported
10403 declarations seem to be static in all other languages, make them all CU-wide
10404 global only in Ada. */
10406 static struct using_direct
**
10407 using_directives (struct dwarf2_cu
*cu
)
10409 if (cu
->language
== language_ada
10410 && cu
->get_builder ()->outermost_context_p ())
10411 return cu
->get_builder ()->get_global_using_directives ();
10413 return cu
->get_builder ()->get_local_using_directives ();
10416 /* Read the import statement specified by the given die and record it. */
10419 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10421 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10422 struct attribute
*import_attr
;
10423 struct die_info
*imported_die
, *child_die
;
10424 struct dwarf2_cu
*imported_cu
;
10425 const char *imported_name
;
10426 const char *imported_name_prefix
;
10427 const char *canonical_name
;
10428 const char *import_alias
;
10429 const char *imported_declaration
= NULL
;
10430 const char *import_prefix
;
10431 std::vector
<const char *> excludes
;
10433 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10434 if (import_attr
== NULL
)
10436 complaint (_("Tag '%s' has no DW_AT_import"),
10437 dwarf_tag_name (die
->tag
));
10442 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10443 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10444 if (imported_name
== NULL
)
10446 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10448 The import in the following code:
10462 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10463 <52> DW_AT_decl_file : 1
10464 <53> DW_AT_decl_line : 6
10465 <54> DW_AT_import : <0x75>
10466 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10467 <59> DW_AT_name : B
10468 <5b> DW_AT_decl_file : 1
10469 <5c> DW_AT_decl_line : 2
10470 <5d> DW_AT_type : <0x6e>
10472 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10473 <76> DW_AT_byte_size : 4
10474 <77> DW_AT_encoding : 5 (signed)
10476 imports the wrong die ( 0x75 instead of 0x58 ).
10477 This case will be ignored until the gcc bug is fixed. */
10481 /* Figure out the local name after import. */
10482 import_alias
= dwarf2_name (die
, cu
);
10484 /* Figure out where the statement is being imported to. */
10485 import_prefix
= determine_prefix (die
, cu
);
10487 /* Figure out what the scope of the imported die is and prepend it
10488 to the name of the imported die. */
10489 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10491 if (imported_die
->tag
!= DW_TAG_namespace
10492 && imported_die
->tag
!= DW_TAG_module
)
10494 imported_declaration
= imported_name
;
10495 canonical_name
= imported_name_prefix
;
10497 else if (strlen (imported_name_prefix
) > 0)
10498 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10499 imported_name_prefix
,
10500 (cu
->language
== language_d
? "." : "::"),
10501 imported_name
, (char *) NULL
);
10503 canonical_name
= imported_name
;
10505 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
10506 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10507 child_die
= child_die
->sibling
)
10509 /* DWARF-4: A Fortran use statement with a “rename list” may be
10510 represented by an imported module entry with an import attribute
10511 referring to the module and owned entries corresponding to those
10512 entities that are renamed as part of being imported. */
10514 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10516 complaint (_("child DW_TAG_imported_declaration expected "
10517 "- DIE at %s [in module %s]"),
10518 sect_offset_str (child_die
->sect_off
),
10519 objfile_name (objfile
));
10523 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10524 if (import_attr
== NULL
)
10526 complaint (_("Tag '%s' has no DW_AT_import"),
10527 dwarf_tag_name (child_die
->tag
));
10532 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10534 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10535 if (imported_name
== NULL
)
10537 complaint (_("child DW_TAG_imported_declaration has unknown "
10538 "imported name - DIE at %s [in module %s]"),
10539 sect_offset_str (child_die
->sect_off
),
10540 objfile_name (objfile
));
10544 excludes
.push_back (imported_name
);
10546 process_die (child_die
, cu
);
10549 add_using_directive (using_directives (cu
),
10553 imported_declaration
,
10556 &objfile
->objfile_obstack
);
10559 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10560 types, but gives them a size of zero. Starting with version 14,
10561 ICC is compatible with GCC. */
10564 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10566 if (!cu
->checked_producer
)
10567 check_producer (cu
);
10569 return cu
->producer_is_icc_lt_14
;
10572 /* ICC generates a DW_AT_type for C void functions. This was observed on
10573 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10574 which says that void functions should not have a DW_AT_type. */
10577 producer_is_icc (struct dwarf2_cu
*cu
)
10579 if (!cu
->checked_producer
)
10580 check_producer (cu
);
10582 return cu
->producer_is_icc
;
10585 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10586 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10587 this, it was first present in GCC release 4.3.0. */
10590 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10592 if (!cu
->checked_producer
)
10593 check_producer (cu
);
10595 return cu
->producer_is_gcc_lt_4_3
;
10598 static file_and_directory
10599 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10601 file_and_directory res
;
10603 /* Find the filename. Do not use dwarf2_name here, since the filename
10604 is not a source language identifier. */
10605 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
10606 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
10608 if (res
.comp_dir
== NULL
10609 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
10610 && IS_ABSOLUTE_PATH (res
.name
))
10612 res
.comp_dir_storage
= ldirname (res
.name
);
10613 if (!res
.comp_dir_storage
.empty ())
10614 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
10616 if (res
.comp_dir
!= NULL
)
10618 /* Irix 6.2 native cc prepends <machine>.: to the compilation
10619 directory, get rid of it. */
10620 const char *cp
= strchr (res
.comp_dir
, ':');
10622 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
10623 res
.comp_dir
= cp
+ 1;
10626 if (res
.name
== NULL
)
10627 res
.name
= "<unknown>";
10632 /* Handle DW_AT_stmt_list for a compilation unit.
10633 DIE is the DW_TAG_compile_unit die for CU.
10634 COMP_DIR is the compilation directory. LOWPC is passed to
10635 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
10638 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
10639 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
10641 struct dwarf2_per_objfile
*dwarf2_per_objfile
10642 = cu
->per_cu
->dwarf2_per_objfile
;
10643 struct attribute
*attr
;
10644 struct line_header line_header_local
;
10645 hashval_t line_header_local_hash
;
10647 int decode_mapping
;
10649 gdb_assert (! cu
->per_cu
->is_debug_types
);
10651 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
10655 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10657 /* The line header hash table is only created if needed (it exists to
10658 prevent redundant reading of the line table for partial_units).
10659 If we're given a partial_unit, we'll need it. If we're given a
10660 compile_unit, then use the line header hash table if it's already
10661 created, but don't create one just yet. */
10663 if (dwarf2_per_objfile
->line_header_hash
== NULL
10664 && die
->tag
== DW_TAG_partial_unit
)
10666 dwarf2_per_objfile
->line_header_hash
10667 .reset (htab_create_alloc (127, line_header_hash_voidp
,
10668 line_header_eq_voidp
,
10669 free_line_header_voidp
,
10673 line_header_local
.sect_off
= line_offset
;
10674 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
10675 line_header_local_hash
= line_header_hash (&line_header_local
);
10676 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
10678 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
.get (),
10679 &line_header_local
,
10680 line_header_local_hash
, NO_INSERT
);
10682 /* For DW_TAG_compile_unit we need info like symtab::linetable which
10683 is not present in *SLOT (since if there is something in *SLOT then
10684 it will be for a partial_unit). */
10685 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
10687 gdb_assert (*slot
!= NULL
);
10688 cu
->line_header
= (struct line_header
*) *slot
;
10693 /* dwarf_decode_line_header does not yet provide sufficient information.
10694 We always have to call also dwarf_decode_lines for it. */
10695 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
10699 cu
->line_header
= lh
.release ();
10700 cu
->line_header_die_owner
= die
;
10702 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
10706 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
.get (),
10707 &line_header_local
,
10708 line_header_local_hash
, INSERT
);
10709 gdb_assert (slot
!= NULL
);
10711 if (slot
!= NULL
&& *slot
== NULL
)
10713 /* This newly decoded line number information unit will be owned
10714 by line_header_hash hash table. */
10715 *slot
= cu
->line_header
;
10716 cu
->line_header_die_owner
= NULL
;
10720 /* We cannot free any current entry in (*slot) as that struct line_header
10721 may be already used by multiple CUs. Create only temporary decoded
10722 line_header for this CU - it may happen at most once for each line
10723 number information unit. And if we're not using line_header_hash
10724 then this is what we want as well. */
10725 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
10727 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
10728 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
10733 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
10736 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10738 struct dwarf2_per_objfile
*dwarf2_per_objfile
10739 = cu
->per_cu
->dwarf2_per_objfile
;
10740 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10741 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10742 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
10743 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
10744 struct attribute
*attr
;
10745 struct die_info
*child_die
;
10746 CORE_ADDR baseaddr
;
10748 prepare_one_comp_unit (cu
, die
, cu
->language
);
10749 baseaddr
= objfile
->text_section_offset ();
10751 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
10753 /* If we didn't find a lowpc, set it to highpc to avoid complaints
10754 from finish_block. */
10755 if (lowpc
== ((CORE_ADDR
) -1))
10757 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
10759 file_and_directory fnd
= find_file_and_directory (die
, cu
);
10761 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
10762 standardised yet. As a workaround for the language detection we fall
10763 back to the DW_AT_producer string. */
10764 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
10765 cu
->language
= language_opencl
;
10767 /* Similar hack for Go. */
10768 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
10769 set_cu_language (DW_LANG_Go
, cu
);
10771 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
10773 /* Decode line number information if present. We do this before
10774 processing child DIEs, so that the line header table is available
10775 for DW_AT_decl_file. */
10776 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
10778 /* Process all dies in compilation unit. */
10779 if (die
->child
!= NULL
)
10781 child_die
= die
->child
;
10782 while (child_die
&& child_die
->tag
)
10784 process_die (child_die
, cu
);
10785 child_die
= child_die
->sibling
;
10789 /* Decode macro information, if present. Dwarf 2 macro information
10790 refers to information in the line number info statement program
10791 header, so we can only read it if we've read the header
10793 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
10795 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
10796 if (attr
&& cu
->line_header
)
10798 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
10799 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
10801 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
10805 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
10806 if (attr
&& cu
->line_header
)
10808 unsigned int macro_offset
= DW_UNSND (attr
);
10810 dwarf_decode_macros (cu
, macro_offset
, 0);
10816 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
10818 struct type_unit_group
*tu_group
;
10820 struct attribute
*attr
;
10822 struct signatured_type
*sig_type
;
10824 gdb_assert (per_cu
->is_debug_types
);
10825 sig_type
= (struct signatured_type
*) per_cu
;
10827 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
10829 /* If we're using .gdb_index (includes -readnow) then
10830 per_cu->type_unit_group may not have been set up yet. */
10831 if (sig_type
->type_unit_group
== NULL
)
10832 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
10833 tu_group
= sig_type
->type_unit_group
;
10835 /* If we've already processed this stmt_list there's no real need to
10836 do it again, we could fake it and just recreate the part we need
10837 (file name,index -> symtab mapping). If data shows this optimization
10838 is useful we can do it then. */
10839 first_time
= tu_group
->compunit_symtab
== NULL
;
10841 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
10846 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10847 lh
= dwarf_decode_line_header (line_offset
, this);
10852 start_symtab ("", NULL
, 0);
10855 gdb_assert (tu_group
->symtabs
== NULL
);
10856 gdb_assert (m_builder
== nullptr);
10857 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
10858 m_builder
.reset (new struct buildsym_compunit
10859 (COMPUNIT_OBJFILE (cust
), "",
10860 COMPUNIT_DIRNAME (cust
),
10861 compunit_language (cust
),
10867 line_header
= lh
.release ();
10868 line_header_die_owner
= die
;
10872 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
10874 /* Note: We don't assign tu_group->compunit_symtab yet because we're
10875 still initializing it, and our caller (a few levels up)
10876 process_full_type_unit still needs to know if this is the first
10880 = XOBNEWVEC (&COMPUNIT_OBJFILE (cust
)->objfile_obstack
,
10881 struct symtab
*, line_header
->file_names_size ());
10883 auto &file_names
= line_header
->file_names ();
10884 for (i
= 0; i
< file_names
.size (); ++i
)
10886 file_entry
&fe
= file_names
[i
];
10887 dwarf2_start_subfile (this, fe
.name
,
10888 fe
.include_dir (line_header
));
10889 buildsym_compunit
*b
= get_builder ();
10890 if (b
->get_current_subfile ()->symtab
== NULL
)
10892 /* NOTE: start_subfile will recognize when it's been
10893 passed a file it has already seen. So we can't
10894 assume there's a simple mapping from
10895 cu->line_header->file_names to subfiles, plus
10896 cu->line_header->file_names may contain dups. */
10897 b
->get_current_subfile ()->symtab
10898 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
10901 fe
.symtab
= b
->get_current_subfile ()->symtab
;
10902 tu_group
->symtabs
[i
] = fe
.symtab
;
10907 gdb_assert (m_builder
== nullptr);
10908 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
10909 m_builder
.reset (new struct buildsym_compunit
10910 (COMPUNIT_OBJFILE (cust
), "",
10911 COMPUNIT_DIRNAME (cust
),
10912 compunit_language (cust
),
10915 auto &file_names
= line_header
->file_names ();
10916 for (i
= 0; i
< file_names
.size (); ++i
)
10918 file_entry
&fe
= file_names
[i
];
10919 fe
.symtab
= tu_group
->symtabs
[i
];
10923 /* The main symtab is allocated last. Type units don't have DW_AT_name
10924 so they don't have a "real" (so to speak) symtab anyway.
10925 There is later code that will assign the main symtab to all symbols
10926 that don't have one. We need to handle the case of a symbol with a
10927 missing symtab (DW_AT_decl_file) anyway. */
10930 /* Process DW_TAG_type_unit.
10931 For TUs we want to skip the first top level sibling if it's not the
10932 actual type being defined by this TU. In this case the first top
10933 level sibling is there to provide context only. */
10936 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10938 struct die_info
*child_die
;
10940 prepare_one_comp_unit (cu
, die
, language_minimal
);
10942 /* Initialize (or reinitialize) the machinery for building symtabs.
10943 We do this before processing child DIEs, so that the line header table
10944 is available for DW_AT_decl_file. */
10945 cu
->setup_type_unit_groups (die
);
10947 if (die
->child
!= NULL
)
10949 child_die
= die
->child
;
10950 while (child_die
&& child_die
->tag
)
10952 process_die (child_die
, cu
);
10953 child_die
= child_die
->sibling
;
10960 http://gcc.gnu.org/wiki/DebugFission
10961 http://gcc.gnu.org/wiki/DebugFissionDWP
10963 To simplify handling of both DWO files ("object" files with the DWARF info)
10964 and DWP files (a file with the DWOs packaged up into one file), we treat
10965 DWP files as having a collection of virtual DWO files. */
10968 hash_dwo_file (const void *item
)
10970 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
10973 hash
= htab_hash_string (dwo_file
->dwo_name
);
10974 if (dwo_file
->comp_dir
!= NULL
)
10975 hash
+= htab_hash_string (dwo_file
->comp_dir
);
10980 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
10982 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
10983 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
10985 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
10987 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
10988 return lhs
->comp_dir
== rhs
->comp_dir
;
10989 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
10992 /* Allocate a hash table for DWO files. */
10995 allocate_dwo_file_hash_table ()
10997 auto delete_dwo_file
= [] (void *item
)
10999 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
11004 return htab_up (htab_create_alloc (41,
11011 /* Lookup DWO file DWO_NAME. */
11014 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11015 const char *dwo_name
,
11016 const char *comp_dir
)
11018 struct dwo_file find_entry
;
11021 if (dwarf2_per_objfile
->dwo_files
== NULL
)
11022 dwarf2_per_objfile
->dwo_files
= allocate_dwo_file_hash_table ();
11024 find_entry
.dwo_name
= dwo_name
;
11025 find_entry
.comp_dir
= comp_dir
;
11026 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
.get (), &find_entry
,
11033 hash_dwo_unit (const void *item
)
11035 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11037 /* This drops the top 32 bits of the id, but is ok for a hash. */
11038 return dwo_unit
->signature
;
11042 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11044 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11045 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11047 /* The signature is assumed to be unique within the DWO file.
11048 So while object file CU dwo_id's always have the value zero,
11049 that's OK, assuming each object file DWO file has only one CU,
11050 and that's the rule for now. */
11051 return lhs
->signature
== rhs
->signature
;
11054 /* Allocate a hash table for DWO CUs,TUs.
11055 There is one of these tables for each of CUs,TUs for each DWO file. */
11058 allocate_dwo_unit_table ()
11060 /* Start out with a pretty small number.
11061 Generally DWO files contain only one CU and maybe some TUs. */
11062 return htab_up (htab_create_alloc (3,
11065 NULL
, xcalloc
, xfree
));
11068 /* die_reader_func for create_dwo_cu. */
11071 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11072 const gdb_byte
*info_ptr
,
11073 struct die_info
*comp_unit_die
,
11074 struct dwo_file
*dwo_file
,
11075 struct dwo_unit
*dwo_unit
)
11077 struct dwarf2_cu
*cu
= reader
->cu
;
11078 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11079 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11081 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11082 if (!signature
.has_value ())
11084 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11085 " its dwo_id [in module %s]"),
11086 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11090 dwo_unit
->dwo_file
= dwo_file
;
11091 dwo_unit
->signature
= *signature
;
11092 dwo_unit
->section
= section
;
11093 dwo_unit
->sect_off
= sect_off
;
11094 dwo_unit
->length
= cu
->per_cu
->length
;
11096 if (dwarf_read_debug
)
11097 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11098 sect_offset_str (sect_off
),
11099 hex_string (dwo_unit
->signature
));
11102 /* Create the dwo_units for the CUs in a DWO_FILE.
11103 Note: This function processes DWO files only, not DWP files. */
11106 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11107 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11108 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
11110 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11111 const gdb_byte
*info_ptr
, *end_ptr
;
11113 section
.read (objfile
);
11114 info_ptr
= section
.buffer
;
11116 if (info_ptr
== NULL
)
11119 if (dwarf_read_debug
)
11121 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11122 section
.get_name (),
11123 section
.get_file_name ());
11126 end_ptr
= info_ptr
+ section
.size
;
11127 while (info_ptr
< end_ptr
)
11129 struct dwarf2_per_cu_data per_cu
;
11130 struct dwo_unit read_unit
{};
11131 struct dwo_unit
*dwo_unit
;
11133 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11135 memset (&per_cu
, 0, sizeof (per_cu
));
11136 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
11137 per_cu
.is_debug_types
= 0;
11138 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11139 per_cu
.section
= §ion
;
11141 cutu_reader
reader (&per_cu
, cu
, &dwo_file
);
11142 if (!reader
.dummy_p
)
11143 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11144 &dwo_file
, &read_unit
);
11145 info_ptr
+= per_cu
.length
;
11147 // If the unit could not be parsed, skip it.
11148 if (read_unit
.dwo_file
== NULL
)
11151 if (cus_htab
== NULL
)
11152 cus_htab
= allocate_dwo_unit_table ();
11154 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11155 *dwo_unit
= read_unit
;
11156 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11157 gdb_assert (slot
!= NULL
);
11160 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11161 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11163 complaint (_("debug cu entry at offset %s is duplicate to"
11164 " the entry at offset %s, signature %s"),
11165 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11166 hex_string (dwo_unit
->signature
));
11168 *slot
= (void *)dwo_unit
;
11172 /* DWP file .debug_{cu,tu}_index section format:
11173 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11177 Both index sections have the same format, and serve to map a 64-bit
11178 signature to a set of section numbers. Each section begins with a header,
11179 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11180 indexes, and a pool of 32-bit section numbers. The index sections will be
11181 aligned at 8-byte boundaries in the file.
11183 The index section header consists of:
11185 V, 32 bit version number
11187 N, 32 bit number of compilation units or type units in the index
11188 M, 32 bit number of slots in the hash table
11190 Numbers are recorded using the byte order of the application binary.
11192 The hash table begins at offset 16 in the section, and consists of an array
11193 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11194 order of the application binary). Unused slots in the hash table are 0.
11195 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11197 The parallel table begins immediately after the hash table
11198 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11199 array of 32-bit indexes (using the byte order of the application binary),
11200 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11201 table contains a 32-bit index into the pool of section numbers. For unused
11202 hash table slots, the corresponding entry in the parallel table will be 0.
11204 The pool of section numbers begins immediately following the hash table
11205 (at offset 16 + 12 * M from the beginning of the section). The pool of
11206 section numbers consists of an array of 32-bit words (using the byte order
11207 of the application binary). Each item in the array is indexed starting
11208 from 0. The hash table entry provides the index of the first section
11209 number in the set. Additional section numbers in the set follow, and the
11210 set is terminated by a 0 entry (section number 0 is not used in ELF).
11212 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11213 section must be the first entry in the set, and the .debug_abbrev.dwo must
11214 be the second entry. Other members of the set may follow in any order.
11220 DWP Version 2 combines all the .debug_info, etc. sections into one,
11221 and the entries in the index tables are now offsets into these sections.
11222 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11225 Index Section Contents:
11227 Hash Table of Signatures dwp_hash_table.hash_table
11228 Parallel Table of Indices dwp_hash_table.unit_table
11229 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
11230 Table of Section Sizes dwp_hash_table.v2.sizes
11232 The index section header consists of:
11234 V, 32 bit version number
11235 L, 32 bit number of columns in the table of section offsets
11236 N, 32 bit number of compilation units or type units in the index
11237 M, 32 bit number of slots in the hash table
11239 Numbers are recorded using the byte order of the application binary.
11241 The hash table has the same format as version 1.
11242 The parallel table of indices has the same format as version 1,
11243 except that the entries are origin-1 indices into the table of sections
11244 offsets and the table of section sizes.
11246 The table of offsets begins immediately following the parallel table
11247 (at offset 16 + 12 * M from the beginning of the section). The table is
11248 a two-dimensional array of 32-bit words (using the byte order of the
11249 application binary), with L columns and N+1 rows, in row-major order.
11250 Each row in the array is indexed starting from 0. The first row provides
11251 a key to the remaining rows: each column in this row provides an identifier
11252 for a debug section, and the offsets in the same column of subsequent rows
11253 refer to that section. The section identifiers are:
11255 DW_SECT_INFO 1 .debug_info.dwo
11256 DW_SECT_TYPES 2 .debug_types.dwo
11257 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11258 DW_SECT_LINE 4 .debug_line.dwo
11259 DW_SECT_LOC 5 .debug_loc.dwo
11260 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11261 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11262 DW_SECT_MACRO 8 .debug_macro.dwo
11264 The offsets provided by the CU and TU index sections are the base offsets
11265 for the contributions made by each CU or TU to the corresponding section
11266 in the package file. Each CU and TU header contains an abbrev_offset
11267 field, used to find the abbreviations table for that CU or TU within the
11268 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11269 be interpreted as relative to the base offset given in the index section.
11270 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11271 should be interpreted as relative to the base offset for .debug_line.dwo,
11272 and offsets into other debug sections obtained from DWARF attributes should
11273 also be interpreted as relative to the corresponding base offset.
11275 The table of sizes begins immediately following the table of offsets.
11276 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11277 with L columns and N rows, in row-major order. Each row in the array is
11278 indexed starting from 1 (row 0 is shared by the two tables).
11282 Hash table lookup is handled the same in version 1 and 2:
11284 We assume that N and M will not exceed 2^32 - 1.
11285 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11287 Given a 64-bit compilation unit signature or a type signature S, an entry
11288 in the hash table is located as follows:
11290 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11291 the low-order k bits all set to 1.
11293 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11295 3) If the hash table entry at index H matches the signature, use that
11296 entry. If the hash table entry at index H is unused (all zeroes),
11297 terminate the search: the signature is not present in the table.
11299 4) Let H = (H + H') modulo M. Repeat at Step 3.
11301 Because M > N and H' and M are relatively prime, the search is guaranteed
11302 to stop at an unused slot or find the match. */
11304 /* Create a hash table to map DWO IDs to their CU/TU entry in
11305 .debug_{info,types}.dwo in DWP_FILE.
11306 Returns NULL if there isn't one.
11307 Note: This function processes DWP files only, not DWO files. */
11309 static struct dwp_hash_table
*
11310 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11311 struct dwp_file
*dwp_file
, int is_debug_types
)
11313 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11314 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11315 const gdb_byte
*index_ptr
, *index_end
;
11316 struct dwarf2_section_info
*index
;
11317 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11318 struct dwp_hash_table
*htab
;
11320 if (is_debug_types
)
11321 index
= &dwp_file
->sections
.tu_index
;
11323 index
= &dwp_file
->sections
.cu_index
;
11325 if (index
->empty ())
11327 index
->read (objfile
);
11329 index_ptr
= index
->buffer
;
11330 index_end
= index_ptr
+ index
->size
;
11332 version
= read_4_bytes (dbfd
, index_ptr
);
11335 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11339 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11341 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11344 if (version
!= 1 && version
!= 2)
11346 error (_("Dwarf Error: unsupported DWP file version (%s)"
11347 " [in module %s]"),
11348 pulongest (version
), dwp_file
->name
);
11350 if (nr_slots
!= (nr_slots
& -nr_slots
))
11352 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11353 " is not power of 2 [in module %s]"),
11354 pulongest (nr_slots
), dwp_file
->name
);
11357 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
11358 htab
->version
= version
;
11359 htab
->nr_columns
= nr_columns
;
11360 htab
->nr_units
= nr_units
;
11361 htab
->nr_slots
= nr_slots
;
11362 htab
->hash_table
= index_ptr
;
11363 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11365 /* Exit early if the table is empty. */
11366 if (nr_slots
== 0 || nr_units
== 0
11367 || (version
== 2 && nr_columns
== 0))
11369 /* All must be zero. */
11370 if (nr_slots
!= 0 || nr_units
!= 0
11371 || (version
== 2 && nr_columns
!= 0))
11373 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11374 " all zero [in modules %s]"),
11382 htab
->section_pool
.v1
.indices
=
11383 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11384 /* It's harder to decide whether the section is too small in v1.
11385 V1 is deprecated anyway so we punt. */
11389 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11390 int *ids
= htab
->section_pool
.v2
.section_ids
;
11391 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11392 /* Reverse map for error checking. */
11393 int ids_seen
[DW_SECT_MAX
+ 1];
11396 if (nr_columns
< 2)
11398 error (_("Dwarf Error: bad DWP hash table, too few columns"
11399 " in section table [in module %s]"),
11402 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11404 error (_("Dwarf Error: bad DWP hash table, too many columns"
11405 " in section table [in module %s]"),
11408 memset (ids
, 255, sizeof_ids
);
11409 memset (ids_seen
, 255, sizeof (ids_seen
));
11410 for (i
= 0; i
< nr_columns
; ++i
)
11412 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11414 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11416 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11417 " in section table [in module %s]"),
11418 id
, dwp_file
->name
);
11420 if (ids_seen
[id
] != -1)
11422 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11423 " id %d in section table [in module %s]"),
11424 id
, dwp_file
->name
);
11429 /* Must have exactly one info or types section. */
11430 if (((ids_seen
[DW_SECT_INFO
] != -1)
11431 + (ids_seen
[DW_SECT_TYPES
] != -1))
11434 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11435 " DWO info/types section [in module %s]"),
11438 /* Must have an abbrev section. */
11439 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11441 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11442 " section [in module %s]"),
11445 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11446 htab
->section_pool
.v2
.sizes
=
11447 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11448 * nr_units
* nr_columns
);
11449 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11450 * nr_units
* nr_columns
))
11453 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11454 " [in module %s]"),
11462 /* Update SECTIONS with the data from SECTP.
11464 This function is like the other "locate" section routines that are
11465 passed to bfd_map_over_sections, but in this context the sections to
11466 read comes from the DWP V1 hash table, not the full ELF section table.
11468 The result is non-zero for success, or zero if an error was found. */
11471 locate_v1_virtual_dwo_sections (asection
*sectp
,
11472 struct virtual_v1_dwo_sections
*sections
)
11474 const struct dwop_section_names
*names
= &dwop_section_names
;
11476 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
11478 /* There can be only one. */
11479 if (sections
->abbrev
.s
.section
!= NULL
)
11481 sections
->abbrev
.s
.section
= sectp
;
11482 sections
->abbrev
.size
= bfd_section_size (sectp
);
11484 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
11485 || section_is_p (sectp
->name
, &names
->types_dwo
))
11487 /* There can be only one. */
11488 if (sections
->info_or_types
.s
.section
!= NULL
)
11490 sections
->info_or_types
.s
.section
= sectp
;
11491 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11493 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
11495 /* There can be only one. */
11496 if (sections
->line
.s
.section
!= NULL
)
11498 sections
->line
.s
.section
= sectp
;
11499 sections
->line
.size
= bfd_section_size (sectp
);
11501 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
11503 /* There can be only one. */
11504 if (sections
->loc
.s
.section
!= NULL
)
11506 sections
->loc
.s
.section
= sectp
;
11507 sections
->loc
.size
= bfd_section_size (sectp
);
11509 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
11511 /* There can be only one. */
11512 if (sections
->macinfo
.s
.section
!= NULL
)
11514 sections
->macinfo
.s
.section
= sectp
;
11515 sections
->macinfo
.size
= bfd_section_size (sectp
);
11517 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
11519 /* There can be only one. */
11520 if (sections
->macro
.s
.section
!= NULL
)
11522 sections
->macro
.s
.section
= sectp
;
11523 sections
->macro
.size
= bfd_section_size (sectp
);
11525 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
11527 /* There can be only one. */
11528 if (sections
->str_offsets
.s
.section
!= NULL
)
11530 sections
->str_offsets
.s
.section
= sectp
;
11531 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11535 /* No other kind of section is valid. */
11542 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11543 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11544 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11545 This is for DWP version 1 files. */
11547 static struct dwo_unit
*
11548 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11549 struct dwp_file
*dwp_file
,
11550 uint32_t unit_index
,
11551 const char *comp_dir
,
11552 ULONGEST signature
, int is_debug_types
)
11554 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11555 const struct dwp_hash_table
*dwp_htab
=
11556 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11557 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11558 const char *kind
= is_debug_types
? "TU" : "CU";
11559 struct dwo_file
*dwo_file
;
11560 struct dwo_unit
*dwo_unit
;
11561 struct virtual_v1_dwo_sections sections
;
11562 void **dwo_file_slot
;
11565 gdb_assert (dwp_file
->version
== 1);
11567 if (dwarf_read_debug
)
11569 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
11571 pulongest (unit_index
), hex_string (signature
),
11575 /* Fetch the sections of this DWO unit.
11576 Put a limit on the number of sections we look for so that bad data
11577 doesn't cause us to loop forever. */
11579 #define MAX_NR_V1_DWO_SECTIONS \
11580 (1 /* .debug_info or .debug_types */ \
11581 + 1 /* .debug_abbrev */ \
11582 + 1 /* .debug_line */ \
11583 + 1 /* .debug_loc */ \
11584 + 1 /* .debug_str_offsets */ \
11585 + 1 /* .debug_macro or .debug_macinfo */ \
11586 + 1 /* trailing zero */)
11588 memset (§ions
, 0, sizeof (sections
));
11590 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
11593 uint32_t section_nr
=
11594 read_4_bytes (dbfd
,
11595 dwp_htab
->section_pool
.v1
.indices
11596 + (unit_index
+ i
) * sizeof (uint32_t));
11598 if (section_nr
== 0)
11600 if (section_nr
>= dwp_file
->num_sections
)
11602 error (_("Dwarf Error: bad DWP hash table, section number too large"
11603 " [in module %s]"),
11607 sectp
= dwp_file
->elf_sections
[section_nr
];
11608 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
11610 error (_("Dwarf Error: bad DWP hash table, invalid section found"
11611 " [in module %s]"),
11617 || sections
.info_or_types
.empty ()
11618 || sections
.abbrev
.empty ())
11620 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
11621 " [in module %s]"),
11624 if (i
== MAX_NR_V1_DWO_SECTIONS
)
11626 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
11627 " [in module %s]"),
11631 /* It's easier for the rest of the code if we fake a struct dwo_file and
11632 have dwo_unit "live" in that. At least for now.
11634 The DWP file can be made up of a random collection of CUs and TUs.
11635 However, for each CU + set of TUs that came from the same original DWO
11636 file, we can combine them back into a virtual DWO file to save space
11637 (fewer struct dwo_file objects to allocate). Remember that for really
11638 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11640 std::string virtual_dwo_name
=
11641 string_printf ("virtual-dwo/%d-%d-%d-%d",
11642 sections
.abbrev
.get_id (),
11643 sections
.line
.get_id (),
11644 sections
.loc
.get_id (),
11645 sections
.str_offsets
.get_id ());
11646 /* Can we use an existing virtual DWO file? */
11647 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
11648 virtual_dwo_name
.c_str (),
11650 /* Create one if necessary. */
11651 if (*dwo_file_slot
== NULL
)
11653 if (dwarf_read_debug
)
11655 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11656 virtual_dwo_name
.c_str ());
11658 dwo_file
= new struct dwo_file
;
11659 dwo_file
->dwo_name
= objfile
->intern (virtual_dwo_name
);
11660 dwo_file
->comp_dir
= comp_dir
;
11661 dwo_file
->sections
.abbrev
= sections
.abbrev
;
11662 dwo_file
->sections
.line
= sections
.line
;
11663 dwo_file
->sections
.loc
= sections
.loc
;
11664 dwo_file
->sections
.macinfo
= sections
.macinfo
;
11665 dwo_file
->sections
.macro
= sections
.macro
;
11666 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
11667 /* The "str" section is global to the entire DWP file. */
11668 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11669 /* The info or types section is assigned below to dwo_unit,
11670 there's no need to record it in dwo_file.
11671 Also, we can't simply record type sections in dwo_file because
11672 we record a pointer into the vector in dwo_unit. As we collect more
11673 types we'll grow the vector and eventually have to reallocate space
11674 for it, invalidating all copies of pointers into the previous
11676 *dwo_file_slot
= dwo_file
;
11680 if (dwarf_read_debug
)
11682 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11683 virtual_dwo_name
.c_str ());
11685 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11688 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11689 dwo_unit
->dwo_file
= dwo_file
;
11690 dwo_unit
->signature
= signature
;
11691 dwo_unit
->section
=
11692 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
11693 *dwo_unit
->section
= sections
.info_or_types
;
11694 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11699 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
11700 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
11701 piece within that section used by a TU/CU, return a virtual section
11702 of just that piece. */
11704 static struct dwarf2_section_info
11705 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11706 struct dwarf2_section_info
*section
,
11707 bfd_size_type offset
, bfd_size_type size
)
11709 struct dwarf2_section_info result
;
11712 gdb_assert (section
!= NULL
);
11713 gdb_assert (!section
->is_virtual
);
11715 memset (&result
, 0, sizeof (result
));
11716 result
.s
.containing_section
= section
;
11717 result
.is_virtual
= true;
11722 sectp
= section
->get_bfd_section ();
11724 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
11725 bounds of the real section. This is a pretty-rare event, so just
11726 flag an error (easier) instead of a warning and trying to cope. */
11728 || offset
+ size
> bfd_section_size (sectp
))
11730 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
11731 " in section %s [in module %s]"),
11732 sectp
? bfd_section_name (sectp
) : "<unknown>",
11733 objfile_name (dwarf2_per_objfile
->objfile
));
11736 result
.virtual_offset
= offset
;
11737 result
.size
= size
;
11741 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11742 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11743 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11744 This is for DWP version 2 files. */
11746 static struct dwo_unit
*
11747 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11748 struct dwp_file
*dwp_file
,
11749 uint32_t unit_index
,
11750 const char *comp_dir
,
11751 ULONGEST signature
, int is_debug_types
)
11753 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11754 const struct dwp_hash_table
*dwp_htab
=
11755 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11756 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11757 const char *kind
= is_debug_types
? "TU" : "CU";
11758 struct dwo_file
*dwo_file
;
11759 struct dwo_unit
*dwo_unit
;
11760 struct virtual_v2_dwo_sections sections
;
11761 void **dwo_file_slot
;
11764 gdb_assert (dwp_file
->version
== 2);
11766 if (dwarf_read_debug
)
11768 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
11770 pulongest (unit_index
), hex_string (signature
),
11774 /* Fetch the section offsets of this DWO unit. */
11776 memset (§ions
, 0, sizeof (sections
));
11778 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11780 uint32_t offset
= read_4_bytes (dbfd
,
11781 dwp_htab
->section_pool
.v2
.offsets
11782 + (((unit_index
- 1) * dwp_htab
->nr_columns
11784 * sizeof (uint32_t)));
11785 uint32_t size
= read_4_bytes (dbfd
,
11786 dwp_htab
->section_pool
.v2
.sizes
11787 + (((unit_index
- 1) * dwp_htab
->nr_columns
11789 * sizeof (uint32_t)));
11791 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
11794 case DW_SECT_TYPES
:
11795 sections
.info_or_types_offset
= offset
;
11796 sections
.info_or_types_size
= size
;
11798 case DW_SECT_ABBREV
:
11799 sections
.abbrev_offset
= offset
;
11800 sections
.abbrev_size
= size
;
11803 sections
.line_offset
= offset
;
11804 sections
.line_size
= size
;
11807 sections
.loc_offset
= offset
;
11808 sections
.loc_size
= size
;
11810 case DW_SECT_STR_OFFSETS
:
11811 sections
.str_offsets_offset
= offset
;
11812 sections
.str_offsets_size
= size
;
11814 case DW_SECT_MACINFO
:
11815 sections
.macinfo_offset
= offset
;
11816 sections
.macinfo_size
= size
;
11818 case DW_SECT_MACRO
:
11819 sections
.macro_offset
= offset
;
11820 sections
.macro_size
= size
;
11825 /* It's easier for the rest of the code if we fake a struct dwo_file and
11826 have dwo_unit "live" in that. At least for now.
11828 The DWP file can be made up of a random collection of CUs and TUs.
11829 However, for each CU + set of TUs that came from the same original DWO
11830 file, we can combine them back into a virtual DWO file to save space
11831 (fewer struct dwo_file objects to allocate). Remember that for really
11832 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11834 std::string virtual_dwo_name
=
11835 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
11836 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
11837 (long) (sections
.line_size
? sections
.line_offset
: 0),
11838 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
11839 (long) (sections
.str_offsets_size
11840 ? sections
.str_offsets_offset
: 0));
11841 /* Can we use an existing virtual DWO file? */
11842 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
11843 virtual_dwo_name
.c_str (),
11845 /* Create one if necessary. */
11846 if (*dwo_file_slot
== NULL
)
11848 if (dwarf_read_debug
)
11850 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11851 virtual_dwo_name
.c_str ());
11853 dwo_file
= new struct dwo_file
;
11854 dwo_file
->dwo_name
= objfile
->intern (virtual_dwo_name
);
11855 dwo_file
->comp_dir
= comp_dir
;
11856 dwo_file
->sections
.abbrev
=
11857 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
11858 sections
.abbrev_offset
, sections
.abbrev_size
);
11859 dwo_file
->sections
.line
=
11860 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
11861 sections
.line_offset
, sections
.line_size
);
11862 dwo_file
->sections
.loc
=
11863 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
11864 sections
.loc_offset
, sections
.loc_size
);
11865 dwo_file
->sections
.macinfo
=
11866 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
11867 sections
.macinfo_offset
, sections
.macinfo_size
);
11868 dwo_file
->sections
.macro
=
11869 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
11870 sections
.macro_offset
, sections
.macro_size
);
11871 dwo_file
->sections
.str_offsets
=
11872 create_dwp_v2_section (dwarf2_per_objfile
,
11873 &dwp_file
->sections
.str_offsets
,
11874 sections
.str_offsets_offset
,
11875 sections
.str_offsets_size
);
11876 /* The "str" section is global to the entire DWP file. */
11877 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11878 /* The info or types section is assigned below to dwo_unit,
11879 there's no need to record it in dwo_file.
11880 Also, we can't simply record type sections in dwo_file because
11881 we record a pointer into the vector in dwo_unit. As we collect more
11882 types we'll grow the vector and eventually have to reallocate space
11883 for it, invalidating all copies of pointers into the previous
11885 *dwo_file_slot
= dwo_file
;
11889 if (dwarf_read_debug
)
11891 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11892 virtual_dwo_name
.c_str ());
11894 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11897 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11898 dwo_unit
->dwo_file
= dwo_file
;
11899 dwo_unit
->signature
= signature
;
11900 dwo_unit
->section
=
11901 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
11902 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
11904 ? &dwp_file
->sections
.types
11905 : &dwp_file
->sections
.info
,
11906 sections
.info_or_types_offset
,
11907 sections
.info_or_types_size
);
11908 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11913 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
11914 Returns NULL if the signature isn't found. */
11916 static struct dwo_unit
*
11917 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11918 struct dwp_file
*dwp_file
, const char *comp_dir
,
11919 ULONGEST signature
, int is_debug_types
)
11921 const struct dwp_hash_table
*dwp_htab
=
11922 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11923 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11924 uint32_t mask
= dwp_htab
->nr_slots
- 1;
11925 uint32_t hash
= signature
& mask
;
11926 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
11929 struct dwo_unit find_dwo_cu
;
11931 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
11932 find_dwo_cu
.signature
= signature
;
11933 slot
= htab_find_slot (is_debug_types
11934 ? dwp_file
->loaded_tus
.get ()
11935 : dwp_file
->loaded_cus
.get (),
11936 &find_dwo_cu
, INSERT
);
11939 return (struct dwo_unit
*) *slot
;
11941 /* Use a for loop so that we don't loop forever on bad debug info. */
11942 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
11944 ULONGEST signature_in_table
;
11946 signature_in_table
=
11947 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
11948 if (signature_in_table
== signature
)
11950 uint32_t unit_index
=
11951 read_4_bytes (dbfd
,
11952 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
11954 if (dwp_file
->version
== 1)
11956 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
11957 dwp_file
, unit_index
,
11958 comp_dir
, signature
,
11963 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
11964 dwp_file
, unit_index
,
11965 comp_dir
, signature
,
11968 return (struct dwo_unit
*) *slot
;
11970 if (signature_in_table
== 0)
11972 hash
= (hash
+ hash2
) & mask
;
11975 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
11976 " [in module %s]"),
11980 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
11981 Open the file specified by FILE_NAME and hand it off to BFD for
11982 preliminary analysis. Return a newly initialized bfd *, which
11983 includes a canonicalized copy of FILE_NAME.
11984 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
11985 SEARCH_CWD is true if the current directory is to be searched.
11986 It will be searched before debug-file-directory.
11987 If successful, the file is added to the bfd include table of the
11988 objfile's bfd (see gdb_bfd_record_inclusion).
11989 If unable to find/open the file, return NULL.
11990 NOTE: This function is derived from symfile_bfd_open. */
11992 static gdb_bfd_ref_ptr
11993 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11994 const char *file_name
, int is_dwp
, int search_cwd
)
11997 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
11998 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
11999 to debug_file_directory. */
12000 const char *search_path
;
12001 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12003 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12006 if (*debug_file_directory
!= '\0')
12008 search_path_holder
.reset (concat (".", dirname_separator_string
,
12009 debug_file_directory
,
12011 search_path
= search_path_holder
.get ();
12017 search_path
= debug_file_directory
;
12019 openp_flags flags
= OPF_RETURN_REALPATH
;
12021 flags
|= OPF_SEARCH_IN_PATH
;
12023 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12024 desc
= openp (search_path
, flags
, file_name
,
12025 O_RDONLY
| O_BINARY
, &absolute_name
);
12029 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12031 if (sym_bfd
== NULL
)
12033 bfd_set_cacheable (sym_bfd
.get (), 1);
12035 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12038 /* Success. Record the bfd as having been included by the objfile's bfd.
12039 This is important because things like demangled_names_hash lives in the
12040 objfile's per_bfd space and may have references to things like symbol
12041 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12042 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12047 /* Try to open DWO file FILE_NAME.
12048 COMP_DIR is the DW_AT_comp_dir attribute.
12049 The result is the bfd handle of the file.
12050 If there is a problem finding or opening the file, return NULL.
12051 Upon success, the canonicalized path of the file is stored in the bfd,
12052 same as symfile_bfd_open. */
12054 static gdb_bfd_ref_ptr
12055 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12056 const char *file_name
, const char *comp_dir
)
12058 if (IS_ABSOLUTE_PATH (file_name
))
12059 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12060 0 /*is_dwp*/, 0 /*search_cwd*/);
12062 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12064 if (comp_dir
!= NULL
)
12066 gdb::unique_xmalloc_ptr
<char> path_to_try
12067 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12069 /* NOTE: If comp_dir is a relative path, this will also try the
12070 search path, which seems useful. */
12071 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
12072 path_to_try
.get (),
12074 1 /*search_cwd*/));
12079 /* That didn't work, try debug-file-directory, which, despite its name,
12080 is a list of paths. */
12082 if (*debug_file_directory
== '\0')
12085 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12086 0 /*is_dwp*/, 1 /*search_cwd*/);
12089 /* This function is mapped across the sections and remembers the offset and
12090 size of each of the DWO debugging sections we are interested in. */
12093 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12095 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12096 const struct dwop_section_names
*names
= &dwop_section_names
;
12098 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12100 dwo_sections
->abbrev
.s
.section
= sectp
;
12101 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12103 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12105 dwo_sections
->info
.s
.section
= sectp
;
12106 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12108 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12110 dwo_sections
->line
.s
.section
= sectp
;
12111 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12113 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12115 dwo_sections
->loc
.s
.section
= sectp
;
12116 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12118 else if (section_is_p (sectp
->name
, &names
->loclists_dwo
))
12120 dwo_sections
->loclists
.s
.section
= sectp
;
12121 dwo_sections
->loclists
.size
= bfd_section_size (sectp
);
12123 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12125 dwo_sections
->macinfo
.s
.section
= sectp
;
12126 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12128 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12130 dwo_sections
->macro
.s
.section
= sectp
;
12131 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12133 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12135 dwo_sections
->str
.s
.section
= sectp
;
12136 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12138 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12140 dwo_sections
->str_offsets
.s
.section
= sectp
;
12141 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12143 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12145 struct dwarf2_section_info type_section
;
12147 memset (&type_section
, 0, sizeof (type_section
));
12148 type_section
.s
.section
= sectp
;
12149 type_section
.size
= bfd_section_size (sectp
);
12150 dwo_sections
->types
.push_back (type_section
);
12154 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12155 by PER_CU. This is for the non-DWP case.
12156 The result is NULL if DWO_NAME can't be found. */
12158 static struct dwo_file
*
12159 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
12160 const char *dwo_name
, const char *comp_dir
)
12162 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
12164 gdb_bfd_ref_ptr dbfd
= open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
);
12167 if (dwarf_read_debug
)
12168 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
12172 dwo_file_up
dwo_file (new struct dwo_file
);
12173 dwo_file
->dwo_name
= dwo_name
;
12174 dwo_file
->comp_dir
= comp_dir
;
12175 dwo_file
->dbfd
= std::move (dbfd
);
12177 bfd_map_over_sections (dwo_file
->dbfd
.get (), dwarf2_locate_dwo_sections
,
12178 &dwo_file
->sections
);
12180 create_cus_hash_table (dwarf2_per_objfile
, per_cu
->cu
, *dwo_file
,
12181 dwo_file
->sections
.info
, dwo_file
->cus
);
12183 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
.get (),
12184 dwo_file
->sections
.types
, dwo_file
->tus
);
12186 if (dwarf_read_debug
)
12187 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
12189 return dwo_file
.release ();
12192 /* This function is mapped across the sections and remembers the offset and
12193 size of each of the DWP debugging sections common to version 1 and 2 that
12194 we are interested in. */
12197 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12198 void *dwp_file_ptr
)
12200 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12201 const struct dwop_section_names
*names
= &dwop_section_names
;
12202 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12204 /* Record the ELF section number for later lookup: this is what the
12205 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12206 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12207 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12209 /* Look for specific sections that we need. */
12210 if (section_is_p (sectp
->name
, &names
->str_dwo
))
12212 dwp_file
->sections
.str
.s
.section
= sectp
;
12213 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12215 else if (section_is_p (sectp
->name
, &names
->cu_index
))
12217 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12218 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12220 else if (section_is_p (sectp
->name
, &names
->tu_index
))
12222 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12223 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12227 /* This function is mapped across the sections and remembers the offset and
12228 size of each of the DWP version 2 debugging sections that we are interested
12229 in. This is split into a separate function because we don't know if we
12230 have version 1 or 2 until we parse the cu_index/tu_index sections. */
12233 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12235 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12236 const struct dwop_section_names
*names
= &dwop_section_names
;
12237 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12239 /* Record the ELF section number for later lookup: this is what the
12240 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12241 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12242 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12244 /* Look for specific sections that we need. */
12245 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12247 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12248 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12250 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12252 dwp_file
->sections
.info
.s
.section
= sectp
;
12253 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12255 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12257 dwp_file
->sections
.line
.s
.section
= sectp
;
12258 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12260 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12262 dwp_file
->sections
.loc
.s
.section
= sectp
;
12263 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12265 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12267 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12268 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12270 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12272 dwp_file
->sections
.macro
.s
.section
= sectp
;
12273 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12275 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12277 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12278 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12280 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12282 dwp_file
->sections
.types
.s
.section
= sectp
;
12283 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12287 /* Hash function for dwp_file loaded CUs/TUs. */
12290 hash_dwp_loaded_cutus (const void *item
)
12292 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12294 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12295 return dwo_unit
->signature
;
12298 /* Equality function for dwp_file loaded CUs/TUs. */
12301 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12303 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12304 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12306 return dua
->signature
== dub
->signature
;
12309 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12312 allocate_dwp_loaded_cutus_table ()
12314 return htab_up (htab_create_alloc (3,
12315 hash_dwp_loaded_cutus
,
12316 eq_dwp_loaded_cutus
,
12317 NULL
, xcalloc
, xfree
));
12320 /* Try to open DWP file FILE_NAME.
12321 The result is the bfd handle of the file.
12322 If there is a problem finding or opening the file, return NULL.
12323 Upon success, the canonicalized path of the file is stored in the bfd,
12324 same as symfile_bfd_open. */
12326 static gdb_bfd_ref_ptr
12327 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12328 const char *file_name
)
12330 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12332 1 /*search_cwd*/));
12336 /* Work around upstream bug 15652.
12337 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12338 [Whether that's a "bug" is debatable, but it is getting in our way.]
12339 We have no real idea where the dwp file is, because gdb's realpath-ing
12340 of the executable's path may have discarded the needed info.
12341 [IWBN if the dwp file name was recorded in the executable, akin to
12342 .gnu_debuglink, but that doesn't exist yet.]
12343 Strip the directory from FILE_NAME and search again. */
12344 if (*debug_file_directory
!= '\0')
12346 /* Don't implicitly search the current directory here.
12347 If the user wants to search "." to handle this case,
12348 it must be added to debug-file-directory. */
12349 return try_open_dwop_file (dwarf2_per_objfile
,
12350 lbasename (file_name
), 1 /*is_dwp*/,
12357 /* Initialize the use of the DWP file for the current objfile.
12358 By convention the name of the DWP file is ${objfile}.dwp.
12359 The result is NULL if it can't be found. */
12361 static std::unique_ptr
<struct dwp_file
>
12362 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12364 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12366 /* Try to find first .dwp for the binary file before any symbolic links
12369 /* If the objfile is a debug file, find the name of the real binary
12370 file and get the name of dwp file from there. */
12371 std::string dwp_name
;
12372 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
12374 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
12375 const char *backlink_basename
= lbasename (backlink
->original_name
);
12377 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
12380 dwp_name
= objfile
->original_name
;
12382 dwp_name
+= ".dwp";
12384 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
12386 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
12388 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
12389 dwp_name
= objfile_name (objfile
);
12390 dwp_name
+= ".dwp";
12391 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
12396 if (dwarf_read_debug
)
12397 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
12398 return std::unique_ptr
<dwp_file
> ();
12401 const char *name
= bfd_get_filename (dbfd
.get ());
12402 std::unique_ptr
<struct dwp_file
> dwp_file
12403 (new struct dwp_file (name
, std::move (dbfd
)));
12405 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
12406 dwp_file
->elf_sections
=
12407 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
12408 dwp_file
->num_sections
, asection
*);
12410 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12411 dwarf2_locate_common_dwp_sections
,
12414 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12417 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12420 /* The DWP file version is stored in the hash table. Oh well. */
12421 if (dwp_file
->cus
&& dwp_file
->tus
12422 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
12424 /* Technically speaking, we should try to limp along, but this is
12425 pretty bizarre. We use pulongest here because that's the established
12426 portability solution (e.g, we cannot use %u for uint32_t). */
12427 error (_("Dwarf Error: DWP file CU version %s doesn't match"
12428 " TU version %s [in DWP file %s]"),
12429 pulongest (dwp_file
->cus
->version
),
12430 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
12434 dwp_file
->version
= dwp_file
->cus
->version
;
12435 else if (dwp_file
->tus
)
12436 dwp_file
->version
= dwp_file
->tus
->version
;
12438 dwp_file
->version
= 2;
12440 if (dwp_file
->version
== 2)
12441 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12442 dwarf2_locate_v2_dwp_sections
,
12445 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
12446 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
12448 if (dwarf_read_debug
)
12450 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
12451 fprintf_unfiltered (gdb_stdlog
,
12452 " %s CUs, %s TUs\n",
12453 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
12454 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
12460 /* Wrapper around open_and_init_dwp_file, only open it once. */
12462 static struct dwp_file
*
12463 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12465 if (! dwarf2_per_objfile
->dwp_checked
)
12467 dwarf2_per_objfile
->dwp_file
12468 = open_and_init_dwp_file (dwarf2_per_objfile
);
12469 dwarf2_per_objfile
->dwp_checked
= 1;
12471 return dwarf2_per_objfile
->dwp_file
.get ();
12474 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
12475 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
12476 or in the DWP file for the objfile, referenced by THIS_UNIT.
12477 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
12478 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
12480 This is called, for example, when wanting to read a variable with a
12481 complex location. Therefore we don't want to do file i/o for every call.
12482 Therefore we don't want to look for a DWO file on every call.
12483 Therefore we first see if we've already seen SIGNATURE in a DWP file,
12484 then we check if we've already seen DWO_NAME, and only THEN do we check
12487 The result is a pointer to the dwo_unit object or NULL if we didn't find it
12488 (dwo_id mismatch or couldn't find the DWO/DWP file). */
12490 static struct dwo_unit
*
12491 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
12492 const char *dwo_name
, const char *comp_dir
,
12493 ULONGEST signature
, int is_debug_types
)
12495 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_unit
->dwarf2_per_objfile
;
12496 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12497 const char *kind
= is_debug_types
? "TU" : "CU";
12498 void **dwo_file_slot
;
12499 struct dwo_file
*dwo_file
;
12500 struct dwp_file
*dwp_file
;
12502 /* First see if there's a DWP file.
12503 If we have a DWP file but didn't find the DWO inside it, don't
12504 look for the original DWO file. It makes gdb behave differently
12505 depending on whether one is debugging in the build tree. */
12507 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
12508 if (dwp_file
!= NULL
)
12510 const struct dwp_hash_table
*dwp_htab
=
12511 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12513 if (dwp_htab
!= NULL
)
12515 struct dwo_unit
*dwo_cutu
=
12516 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
12517 signature
, is_debug_types
);
12519 if (dwo_cutu
!= NULL
)
12521 if (dwarf_read_debug
)
12523 fprintf_unfiltered (gdb_stdlog
,
12524 "Virtual DWO %s %s found: @%s\n",
12525 kind
, hex_string (signature
),
12526 host_address_to_string (dwo_cutu
));
12534 /* No DWP file, look for the DWO file. */
12536 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12537 dwo_name
, comp_dir
);
12538 if (*dwo_file_slot
== NULL
)
12540 /* Read in the file and build a table of the CUs/TUs it contains. */
12541 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
12543 /* NOTE: This will be NULL if unable to open the file. */
12544 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12546 if (dwo_file
!= NULL
)
12548 struct dwo_unit
*dwo_cutu
= NULL
;
12550 if (is_debug_types
&& dwo_file
->tus
)
12552 struct dwo_unit find_dwo_cutu
;
12554 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12555 find_dwo_cutu
.signature
= signature
;
12557 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
12560 else if (!is_debug_types
&& dwo_file
->cus
)
12562 struct dwo_unit find_dwo_cutu
;
12564 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12565 find_dwo_cutu
.signature
= signature
;
12566 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
12570 if (dwo_cutu
!= NULL
)
12572 if (dwarf_read_debug
)
12574 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
12575 kind
, dwo_name
, hex_string (signature
),
12576 host_address_to_string (dwo_cutu
));
12583 /* We didn't find it. This could mean a dwo_id mismatch, or
12584 someone deleted the DWO/DWP file, or the search path isn't set up
12585 correctly to find the file. */
12587 if (dwarf_read_debug
)
12589 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
12590 kind
, dwo_name
, hex_string (signature
));
12593 /* This is a warning and not a complaint because it can be caused by
12594 pilot error (e.g., user accidentally deleting the DWO). */
12596 /* Print the name of the DWP file if we looked there, helps the user
12597 better diagnose the problem. */
12598 std::string dwp_text
;
12600 if (dwp_file
!= NULL
)
12601 dwp_text
= string_printf (" [in DWP file %s]",
12602 lbasename (dwp_file
->name
));
12604 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
12605 " [in module %s]"),
12606 kind
, dwo_name
, hex_string (signature
),
12608 this_unit
->is_debug_types
? "TU" : "CU",
12609 sect_offset_str (this_unit
->sect_off
), objfile_name (objfile
));
12614 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
12615 See lookup_dwo_cutu_unit for details. */
12617 static struct dwo_unit
*
12618 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
12619 const char *dwo_name
, const char *comp_dir
,
12620 ULONGEST signature
)
12622 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
12625 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
12626 See lookup_dwo_cutu_unit for details. */
12628 static struct dwo_unit
*
12629 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
12630 const char *dwo_name
, const char *comp_dir
)
12632 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
12635 /* Traversal function for queue_and_load_all_dwo_tus. */
12638 queue_and_load_dwo_tu (void **slot
, void *info
)
12640 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
12641 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
12642 ULONGEST signature
= dwo_unit
->signature
;
12643 struct signatured_type
*sig_type
=
12644 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
12646 if (sig_type
!= NULL
)
12648 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
12650 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
12651 a real dependency of PER_CU on SIG_TYPE. That is detected later
12652 while processing PER_CU. */
12653 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
12654 load_full_type_unit (sig_cu
);
12655 per_cu
->imported_symtabs_push (sig_cu
);
12661 /* Queue all TUs contained in the DWO of PER_CU to be read in.
12662 The DWO may have the only definition of the type, though it may not be
12663 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
12664 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
12667 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
12669 struct dwo_unit
*dwo_unit
;
12670 struct dwo_file
*dwo_file
;
12672 gdb_assert (!per_cu
->is_debug_types
);
12673 gdb_assert (get_dwp_file (per_cu
->dwarf2_per_objfile
) == NULL
);
12674 gdb_assert (per_cu
->cu
!= NULL
);
12676 dwo_unit
= per_cu
->cu
->dwo_unit
;
12677 gdb_assert (dwo_unit
!= NULL
);
12679 dwo_file
= dwo_unit
->dwo_file
;
12680 if (dwo_file
->tus
!= NULL
)
12681 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
,
12685 /* Read in various DIEs. */
12687 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
12688 Inherit only the children of the DW_AT_abstract_origin DIE not being
12689 already referenced by DW_AT_abstract_origin from the children of the
12693 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
12695 struct die_info
*child_die
;
12696 sect_offset
*offsetp
;
12697 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
12698 struct die_info
*origin_die
;
12699 /* Iterator of the ORIGIN_DIE children. */
12700 struct die_info
*origin_child_die
;
12701 struct attribute
*attr
;
12702 struct dwarf2_cu
*origin_cu
;
12703 struct pending
**origin_previous_list_in_scope
;
12705 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
12709 /* Note that following die references may follow to a die in a
12713 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
12715 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
12717 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
12718 origin_cu
->list_in_scope
= cu
->list_in_scope
;
12720 if (die
->tag
!= origin_die
->tag
12721 && !(die
->tag
== DW_TAG_inlined_subroutine
12722 && origin_die
->tag
== DW_TAG_subprogram
))
12723 complaint (_("DIE %s and its abstract origin %s have different tags"),
12724 sect_offset_str (die
->sect_off
),
12725 sect_offset_str (origin_die
->sect_off
));
12727 std::vector
<sect_offset
> offsets
;
12729 for (child_die
= die
->child
;
12730 child_die
&& child_die
->tag
;
12731 child_die
= child_die
->sibling
)
12733 struct die_info
*child_origin_die
;
12734 struct dwarf2_cu
*child_origin_cu
;
12736 /* We are trying to process concrete instance entries:
12737 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
12738 it's not relevant to our analysis here. i.e. detecting DIEs that are
12739 present in the abstract instance but not referenced in the concrete
12741 if (child_die
->tag
== DW_TAG_call_site
12742 || child_die
->tag
== DW_TAG_GNU_call_site
)
12745 /* For each CHILD_DIE, find the corresponding child of
12746 ORIGIN_DIE. If there is more than one layer of
12747 DW_AT_abstract_origin, follow them all; there shouldn't be,
12748 but GCC versions at least through 4.4 generate this (GCC PR
12750 child_origin_die
= child_die
;
12751 child_origin_cu
= cu
;
12754 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
12758 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
12762 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
12763 counterpart may exist. */
12764 if (child_origin_die
!= child_die
)
12766 if (child_die
->tag
!= child_origin_die
->tag
12767 && !(child_die
->tag
== DW_TAG_inlined_subroutine
12768 && child_origin_die
->tag
== DW_TAG_subprogram
))
12769 complaint (_("Child DIE %s and its abstract origin %s have "
12771 sect_offset_str (child_die
->sect_off
),
12772 sect_offset_str (child_origin_die
->sect_off
));
12773 if (child_origin_die
->parent
!= origin_die
)
12774 complaint (_("Child DIE %s and its abstract origin %s have "
12775 "different parents"),
12776 sect_offset_str (child_die
->sect_off
),
12777 sect_offset_str (child_origin_die
->sect_off
));
12779 offsets
.push_back (child_origin_die
->sect_off
);
12782 std::sort (offsets
.begin (), offsets
.end ());
12783 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
12784 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
12785 if (offsetp
[-1] == *offsetp
)
12786 complaint (_("Multiple children of DIE %s refer "
12787 "to DIE %s as their abstract origin"),
12788 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
12790 offsetp
= offsets
.data ();
12791 origin_child_die
= origin_die
->child
;
12792 while (origin_child_die
&& origin_child_die
->tag
)
12794 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
12795 while (offsetp
< offsets_end
12796 && *offsetp
< origin_child_die
->sect_off
)
12798 if (offsetp
>= offsets_end
12799 || *offsetp
> origin_child_die
->sect_off
)
12801 /* Found that ORIGIN_CHILD_DIE is really not referenced.
12802 Check whether we're already processing ORIGIN_CHILD_DIE.
12803 This can happen with mutually referenced abstract_origins.
12805 if (!origin_child_die
->in_process
)
12806 process_die (origin_child_die
, origin_cu
);
12808 origin_child_die
= origin_child_die
->sibling
;
12810 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
12812 if (cu
!= origin_cu
)
12813 compute_delayed_physnames (origin_cu
);
12817 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12819 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
12820 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12821 struct context_stack
*newobj
;
12824 struct die_info
*child_die
;
12825 struct attribute
*attr
, *call_line
, *call_file
;
12827 CORE_ADDR baseaddr
;
12828 struct block
*block
;
12829 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
12830 std::vector
<struct symbol
*> template_args
;
12831 struct template_symbol
*templ_func
= NULL
;
12835 /* If we do not have call site information, we can't show the
12836 caller of this inlined function. That's too confusing, so
12837 only use the scope for local variables. */
12838 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
12839 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
12840 if (call_line
== NULL
|| call_file
== NULL
)
12842 read_lexical_block_scope (die
, cu
);
12847 baseaddr
= objfile
->text_section_offset ();
12849 name
= dwarf2_name (die
, cu
);
12851 /* Ignore functions with missing or empty names. These are actually
12852 illegal according to the DWARF standard. */
12855 complaint (_("missing name for subprogram DIE at %s"),
12856 sect_offset_str (die
->sect_off
));
12860 /* Ignore functions with missing or invalid low and high pc attributes. */
12861 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
12862 <= PC_BOUNDS_INVALID
)
12864 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
12865 if (!attr
|| !DW_UNSND (attr
))
12866 complaint (_("cannot get low and high bounds "
12867 "for subprogram DIE at %s"),
12868 sect_offset_str (die
->sect_off
));
12872 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
12873 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
12875 /* If we have any template arguments, then we must allocate a
12876 different sort of symbol. */
12877 for (child_die
= die
->child
; child_die
; child_die
= child_die
->sibling
)
12879 if (child_die
->tag
== DW_TAG_template_type_param
12880 || child_die
->tag
== DW_TAG_template_value_param
)
12882 templ_func
= allocate_template_symbol (objfile
);
12883 templ_func
->subclass
= SYMBOL_TEMPLATE
;
12888 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
12889 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
12890 (struct symbol
*) templ_func
);
12892 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
12893 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
12896 /* If there is a location expression for DW_AT_frame_base, record
12898 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
12899 if (attr
!= nullptr)
12900 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
12902 /* If there is a location for the static link, record it. */
12903 newobj
->static_link
= NULL
;
12904 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
12905 if (attr
!= nullptr)
12907 newobj
->static_link
12908 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
12909 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
12910 cu
->per_cu
->addr_type ());
12913 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
12915 if (die
->child
!= NULL
)
12917 child_die
= die
->child
;
12918 while (child_die
&& child_die
->tag
)
12920 if (child_die
->tag
== DW_TAG_template_type_param
12921 || child_die
->tag
== DW_TAG_template_value_param
)
12923 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
12926 template_args
.push_back (arg
);
12929 process_die (child_die
, cu
);
12930 child_die
= child_die
->sibling
;
12934 inherit_abstract_dies (die
, cu
);
12936 /* If we have a DW_AT_specification, we might need to import using
12937 directives from the context of the specification DIE. See the
12938 comment in determine_prefix. */
12939 if (cu
->language
== language_cplus
12940 && dwarf2_attr (die
, DW_AT_specification
, cu
))
12942 struct dwarf2_cu
*spec_cu
= cu
;
12943 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
12947 child_die
= spec_die
->child
;
12948 while (child_die
&& child_die
->tag
)
12950 if (child_die
->tag
== DW_TAG_imported_module
)
12951 process_die (child_die
, spec_cu
);
12952 child_die
= child_die
->sibling
;
12955 /* In some cases, GCC generates specification DIEs that
12956 themselves contain DW_AT_specification attributes. */
12957 spec_die
= die_specification (spec_die
, &spec_cu
);
12961 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
12962 /* Make a block for the local symbols within. */
12963 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
12964 cstk
.static_link
, lowpc
, highpc
);
12966 /* For C++, set the block's scope. */
12967 if ((cu
->language
== language_cplus
12968 || cu
->language
== language_fortran
12969 || cu
->language
== language_d
12970 || cu
->language
== language_rust
)
12971 && cu
->processing_has_namespace_info
)
12972 block_set_scope (block
, determine_prefix (die
, cu
),
12973 &objfile
->objfile_obstack
);
12975 /* If we have address ranges, record them. */
12976 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
12978 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
12980 /* Attach template arguments to function. */
12981 if (!template_args
.empty ())
12983 gdb_assert (templ_func
!= NULL
);
12985 templ_func
->n_template_arguments
= template_args
.size ();
12986 templ_func
->template_arguments
12987 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
12988 templ_func
->n_template_arguments
);
12989 memcpy (templ_func
->template_arguments
,
12990 template_args
.data (),
12991 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
12993 /* Make sure that the symtab is set on the new symbols. Even
12994 though they don't appear in this symtab directly, other parts
12995 of gdb assume that symbols do, and this is reasonably
12997 for (symbol
*sym
: template_args
)
12998 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13001 /* In C++, we can have functions nested inside functions (e.g., when
13002 a function declares a class that has methods). This means that
13003 when we finish processing a function scope, we may need to go
13004 back to building a containing block's symbol lists. */
13005 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13006 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13008 /* If we've finished processing a top-level function, subsequent
13009 symbols go in the file symbol list. */
13010 if (cu
->get_builder ()->outermost_context_p ())
13011 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13014 /* Process all the DIES contained within a lexical block scope. Start
13015 a new scope, process the dies, and then close the scope. */
13018 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13020 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13021 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13022 CORE_ADDR lowpc
, highpc
;
13023 struct die_info
*child_die
;
13024 CORE_ADDR baseaddr
;
13026 baseaddr
= objfile
->text_section_offset ();
13028 /* Ignore blocks with missing or invalid low and high pc attributes. */
13029 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13030 as multiple lexical blocks? Handling children in a sane way would
13031 be nasty. Might be easier to properly extend generic blocks to
13032 describe ranges. */
13033 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13035 case PC_BOUNDS_NOT_PRESENT
:
13036 /* DW_TAG_lexical_block has no attributes, process its children as if
13037 there was no wrapping by that DW_TAG_lexical_block.
13038 GCC does no longer produces such DWARF since GCC r224161. */
13039 for (child_die
= die
->child
;
13040 child_die
!= NULL
&& child_die
->tag
;
13041 child_die
= child_die
->sibling
)
13042 process_die (child_die
, cu
);
13044 case PC_BOUNDS_INVALID
:
13047 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13048 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13050 cu
->get_builder ()->push_context (0, lowpc
);
13051 if (die
->child
!= NULL
)
13053 child_die
= die
->child
;
13054 while (child_die
&& child_die
->tag
)
13056 process_die (child_die
, cu
);
13057 child_die
= child_die
->sibling
;
13060 inherit_abstract_dies (die
, cu
);
13061 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13063 if (*cu
->get_builder ()->get_local_symbols () != NULL
13064 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13066 struct block
*block
13067 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13068 cstk
.start_addr
, highpc
);
13070 /* Note that recording ranges after traversing children, as we
13071 do here, means that recording a parent's ranges entails
13072 walking across all its children's ranges as they appear in
13073 the address map, which is quadratic behavior.
13075 It would be nicer to record the parent's ranges before
13076 traversing its children, simply overriding whatever you find
13077 there. But since we don't even decide whether to create a
13078 block until after we've traversed its children, that's hard
13080 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13082 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13083 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13086 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13089 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13091 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13092 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13093 CORE_ADDR pc
, baseaddr
;
13094 struct attribute
*attr
;
13095 struct call_site
*call_site
, call_site_local
;
13098 struct die_info
*child_die
;
13100 baseaddr
= objfile
->text_section_offset ();
13102 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13105 /* This was a pre-DWARF-5 GNU extension alias
13106 for DW_AT_call_return_pc. */
13107 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13111 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13112 "DIE %s [in module %s]"),
13113 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13116 pc
= attr
->value_as_address () + baseaddr
;
13117 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13119 if (cu
->call_site_htab
== NULL
)
13120 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13121 NULL
, &objfile
->objfile_obstack
,
13122 hashtab_obstack_allocate
, NULL
);
13123 call_site_local
.pc
= pc
;
13124 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13127 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13128 "DIE %s [in module %s]"),
13129 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13130 objfile_name (objfile
));
13134 /* Count parameters at the caller. */
13137 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13138 child_die
= child_die
->sibling
)
13140 if (child_die
->tag
!= DW_TAG_call_site_parameter
13141 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13143 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13144 "DW_TAG_call_site child DIE %s [in module %s]"),
13145 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13146 objfile_name (objfile
));
13154 = ((struct call_site
*)
13155 obstack_alloc (&objfile
->objfile_obstack
,
13156 sizeof (*call_site
)
13157 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13159 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13160 call_site
->pc
= pc
;
13162 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13163 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13165 struct die_info
*func_die
;
13167 /* Skip also over DW_TAG_inlined_subroutine. */
13168 for (func_die
= die
->parent
;
13169 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13170 && func_die
->tag
!= DW_TAG_subroutine_type
;
13171 func_die
= func_die
->parent
);
13173 /* DW_AT_call_all_calls is a superset
13174 of DW_AT_call_all_tail_calls. */
13176 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13177 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13178 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13179 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13181 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13182 not complete. But keep CALL_SITE for look ups via call_site_htab,
13183 both the initial caller containing the real return address PC and
13184 the final callee containing the current PC of a chain of tail
13185 calls do not need to have the tail call list complete. But any
13186 function candidate for a virtual tail call frame searched via
13187 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13188 determined unambiguously. */
13192 struct type
*func_type
= NULL
;
13195 func_type
= get_die_type (func_die
, cu
);
13196 if (func_type
!= NULL
)
13198 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
13200 /* Enlist this call site to the function. */
13201 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13202 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13205 complaint (_("Cannot find function owning DW_TAG_call_site "
13206 "DIE %s [in module %s]"),
13207 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13211 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13213 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13215 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13218 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13219 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13221 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13222 if (!attr
|| (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0))
13223 /* Keep NULL DWARF_BLOCK. */;
13224 else if (attr
->form_is_block ())
13226 struct dwarf2_locexpr_baton
*dlbaton
;
13228 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13229 dlbaton
->data
= DW_BLOCK (attr
)->data
;
13230 dlbaton
->size
= DW_BLOCK (attr
)->size
;
13231 dlbaton
->per_cu
= cu
->per_cu
;
13233 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13235 else if (attr
->form_is_ref ())
13237 struct dwarf2_cu
*target_cu
= cu
;
13238 struct die_info
*target_die
;
13240 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13241 gdb_assert (target_cu
->per_cu
->dwarf2_per_objfile
->objfile
== objfile
);
13242 if (die_is_declaration (target_die
, target_cu
))
13244 const char *target_physname
;
13246 /* Prefer the mangled name; otherwise compute the demangled one. */
13247 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13248 if (target_physname
== NULL
)
13249 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13250 if (target_physname
== NULL
)
13251 complaint (_("DW_AT_call_target target DIE has invalid "
13252 "physname, for referencing DIE %s [in module %s]"),
13253 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13255 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13261 /* DW_AT_entry_pc should be preferred. */
13262 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13263 <= PC_BOUNDS_INVALID
)
13264 complaint (_("DW_AT_call_target target DIE has invalid "
13265 "low pc, for referencing DIE %s [in module %s]"),
13266 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13269 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13270 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
13275 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13276 "block nor reference, for DIE %s [in module %s]"),
13277 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13279 call_site
->per_cu
= cu
->per_cu
;
13281 for (child_die
= die
->child
;
13282 child_die
&& child_die
->tag
;
13283 child_die
= child_die
->sibling
)
13285 struct call_site_parameter
*parameter
;
13286 struct attribute
*loc
, *origin
;
13288 if (child_die
->tag
!= DW_TAG_call_site_parameter
13289 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13291 /* Already printed the complaint above. */
13295 gdb_assert (call_site
->parameter_count
< nparams
);
13296 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13298 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13299 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13300 register is contained in DW_AT_call_value. */
13302 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13303 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13304 if (origin
== NULL
)
13306 /* This was a pre-DWARF-5 GNU extension alias
13307 for DW_AT_call_parameter. */
13308 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13310 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
13312 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13314 sect_offset sect_off
= origin
->get_ref_die_offset ();
13315 if (!cu
->header
.offset_in_cu_p (sect_off
))
13317 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13318 binding can be done only inside one CU. Such referenced DIE
13319 therefore cannot be even moved to DW_TAG_partial_unit. */
13320 complaint (_("DW_AT_call_parameter offset is not in CU for "
13321 "DW_TAG_call_site child DIE %s [in module %s]"),
13322 sect_offset_str (child_die
->sect_off
),
13323 objfile_name (objfile
));
13326 parameter
->u
.param_cu_off
13327 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13329 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
13331 complaint (_("No DW_FORM_block* DW_AT_location for "
13332 "DW_TAG_call_site child DIE %s [in module %s]"),
13333 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13338 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13339 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
13340 if (parameter
->u
.dwarf_reg
!= -1)
13341 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13342 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
13343 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
13344 ¶meter
->u
.fb_offset
))
13345 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13348 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13349 "for DW_FORM_block* DW_AT_location is supported for "
13350 "DW_TAG_call_site child DIE %s "
13352 sect_offset_str (child_die
->sect_off
),
13353 objfile_name (objfile
));
13358 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13360 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13361 if (attr
== NULL
|| !attr
->form_is_block ())
13363 complaint (_("No DW_FORM_block* DW_AT_call_value for "
13364 "DW_TAG_call_site child DIE %s [in module %s]"),
13365 sect_offset_str (child_die
->sect_off
),
13366 objfile_name (objfile
));
13369 parameter
->value
= DW_BLOCK (attr
)->data
;
13370 parameter
->value_size
= DW_BLOCK (attr
)->size
;
13372 /* Parameters are not pre-cleared by memset above. */
13373 parameter
->data_value
= NULL
;
13374 parameter
->data_value_size
= 0;
13375 call_site
->parameter_count
++;
13377 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
13379 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
13380 if (attr
!= nullptr)
13382 if (!attr
->form_is_block ())
13383 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
13384 "DW_TAG_call_site child DIE %s [in module %s]"),
13385 sect_offset_str (child_die
->sect_off
),
13386 objfile_name (objfile
));
13389 parameter
->data_value
= DW_BLOCK (attr
)->data
;
13390 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
13396 /* Helper function for read_variable. If DIE represents a virtual
13397 table, then return the type of the concrete object that is
13398 associated with the virtual table. Otherwise, return NULL. */
13400 static struct type
*
13401 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13403 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13407 /* Find the type DIE. */
13408 struct die_info
*type_die
= NULL
;
13409 struct dwarf2_cu
*type_cu
= cu
;
13411 if (attr
->form_is_ref ())
13412 type_die
= follow_die_ref (die
, attr
, &type_cu
);
13413 if (type_die
== NULL
)
13416 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
13418 return die_containing_type (type_die
, type_cu
);
13421 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
13424 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
13426 struct rust_vtable_symbol
*storage
= NULL
;
13428 if (cu
->language
== language_rust
)
13430 struct type
*containing_type
= rust_containing_type (die
, cu
);
13432 if (containing_type
!= NULL
)
13434 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13436 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol ();
13437 initialize_objfile_symbol (storage
);
13438 storage
->concrete_type
= containing_type
;
13439 storage
->subclass
= SYMBOL_RUST_VTABLE
;
13443 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
13444 struct attribute
*abstract_origin
13445 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13446 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
13447 if (res
== NULL
&& loc
&& abstract_origin
)
13449 /* We have a variable without a name, but with a location and an abstract
13450 origin. This may be a concrete instance of an abstract variable
13451 referenced from an DW_OP_GNU_variable_value, so save it to find it back
13453 struct dwarf2_cu
*origin_cu
= cu
;
13454 struct die_info
*origin_die
13455 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
13456 dwarf2_per_objfile
*dpo
= cu
->per_cu
->dwarf2_per_objfile
;
13457 dpo
->abstract_to_concrete
[origin_die
->sect_off
].push_back (die
->sect_off
);
13461 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
13462 reading .debug_rnglists.
13463 Callback's type should be:
13464 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13465 Return true if the attributes are present and valid, otherwise,
13468 template <typename Callback
>
13470 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
13471 Callback
&&callback
)
13473 struct dwarf2_per_objfile
*dwarf2_per_objfile
13474 = cu
->per_cu
->dwarf2_per_objfile
;
13475 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13476 bfd
*obfd
= objfile
->obfd
;
13477 /* Base address selection entry. */
13478 gdb::optional
<CORE_ADDR
> base
;
13479 const gdb_byte
*buffer
;
13480 CORE_ADDR baseaddr
;
13481 bool overflow
= false;
13483 base
= cu
->base_address
;
13485 dwarf2_per_objfile
->rnglists
.read (objfile
);
13486 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
13488 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13492 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
13494 baseaddr
= objfile
->text_section_offset ();
13498 /* Initialize it due to a false compiler warning. */
13499 CORE_ADDR range_beginning
= 0, range_end
= 0;
13500 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
13501 + dwarf2_per_objfile
->rnglists
.size
);
13502 unsigned int bytes_read
;
13504 if (buffer
== buf_end
)
13509 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
13512 case DW_RLE_end_of_list
:
13514 case DW_RLE_base_address
:
13515 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13520 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13521 buffer
+= bytes_read
;
13523 case DW_RLE_start_length
:
13524 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13529 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13531 buffer
+= bytes_read
;
13532 range_end
= (range_beginning
13533 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13534 buffer
+= bytes_read
;
13535 if (buffer
> buf_end
)
13541 case DW_RLE_offset_pair
:
13542 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13543 buffer
+= bytes_read
;
13544 if (buffer
> buf_end
)
13549 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13550 buffer
+= bytes_read
;
13551 if (buffer
> buf_end
)
13557 case DW_RLE_start_end
:
13558 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
13563 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13565 buffer
+= bytes_read
;
13566 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13567 buffer
+= bytes_read
;
13570 complaint (_("Invalid .debug_rnglists data (no base address)"));
13573 if (rlet
== DW_RLE_end_of_list
|| overflow
)
13575 if (rlet
== DW_RLE_base_address
)
13578 if (!base
.has_value ())
13580 /* We have no valid base address for the ranges
13582 complaint (_("Invalid .debug_rnglists data (no base address)"));
13586 if (range_beginning
> range_end
)
13588 /* Inverted range entries are invalid. */
13589 complaint (_("Invalid .debug_rnglists data (inverted range)"));
13593 /* Empty range entries have no effect. */
13594 if (range_beginning
== range_end
)
13597 range_beginning
+= *base
;
13598 range_end
+= *base
;
13600 /* A not-uncommon case of bad debug info.
13601 Don't pollute the addrmap with bad data. */
13602 if (range_beginning
+ baseaddr
== 0
13603 && !dwarf2_per_objfile
->has_section_at_zero
)
13605 complaint (_(".debug_rnglists entry has start address of zero"
13606 " [in module %s]"), objfile_name (objfile
));
13610 callback (range_beginning
, range_end
);
13615 complaint (_("Offset %d is not terminated "
13616 "for DW_AT_ranges attribute"),
13624 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
13625 Callback's type should be:
13626 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13627 Return 1 if the attributes are present and valid, otherwise, return 0. */
13629 template <typename Callback
>
13631 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
13632 Callback
&&callback
)
13634 struct dwarf2_per_objfile
*dwarf2_per_objfile
13635 = cu
->per_cu
->dwarf2_per_objfile
;
13636 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13637 struct comp_unit_head
*cu_header
= &cu
->header
;
13638 bfd
*obfd
= objfile
->obfd
;
13639 unsigned int addr_size
= cu_header
->addr_size
;
13640 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
13641 /* Base address selection entry. */
13642 gdb::optional
<CORE_ADDR
> base
;
13643 unsigned int dummy
;
13644 const gdb_byte
*buffer
;
13645 CORE_ADDR baseaddr
;
13647 if (cu_header
->version
>= 5)
13648 return dwarf2_rnglists_process (offset
, cu
, callback
);
13650 base
= cu
->base_address
;
13652 dwarf2_per_objfile
->ranges
.read (objfile
);
13653 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
13655 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13659 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
13661 baseaddr
= objfile
->text_section_offset ();
13665 CORE_ADDR range_beginning
, range_end
;
13667 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13668 buffer
+= addr_size
;
13669 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13670 buffer
+= addr_size
;
13671 offset
+= 2 * addr_size
;
13673 /* An end of list marker is a pair of zero addresses. */
13674 if (range_beginning
== 0 && range_end
== 0)
13675 /* Found the end of list entry. */
13678 /* Each base address selection entry is a pair of 2 values.
13679 The first is the largest possible address, the second is
13680 the base address. Check for a base address here. */
13681 if ((range_beginning
& mask
) == mask
)
13683 /* If we found the largest possible address, then we already
13684 have the base address in range_end. */
13689 if (!base
.has_value ())
13691 /* We have no valid base address for the ranges
13693 complaint (_("Invalid .debug_ranges data (no base address)"));
13697 if (range_beginning
> range_end
)
13699 /* Inverted range entries are invalid. */
13700 complaint (_("Invalid .debug_ranges data (inverted range)"));
13704 /* Empty range entries have no effect. */
13705 if (range_beginning
== range_end
)
13708 range_beginning
+= *base
;
13709 range_end
+= *base
;
13711 /* A not-uncommon case of bad debug info.
13712 Don't pollute the addrmap with bad data. */
13713 if (range_beginning
+ baseaddr
== 0
13714 && !dwarf2_per_objfile
->has_section_at_zero
)
13716 complaint (_(".debug_ranges entry has start address of zero"
13717 " [in module %s]"), objfile_name (objfile
));
13721 callback (range_beginning
, range_end
);
13727 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
13728 Return 1 if the attributes are present and valid, otherwise, return 0.
13729 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
13732 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
13733 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
13734 dwarf2_psymtab
*ranges_pst
)
13736 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13737 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13738 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
13741 CORE_ADDR high
= 0;
13744 retval
= dwarf2_ranges_process (offset
, cu
,
13745 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
13747 if (ranges_pst
!= NULL
)
13752 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13753 range_beginning
+ baseaddr
)
13755 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13756 range_end
+ baseaddr
)
13758 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
13759 lowpc
, highpc
- 1, ranges_pst
);
13762 /* FIXME: This is recording everything as a low-high
13763 segment of consecutive addresses. We should have a
13764 data structure for discontiguous block ranges
13768 low
= range_beginning
;
13774 if (range_beginning
< low
)
13775 low
= range_beginning
;
13776 if (range_end
> high
)
13784 /* If the first entry is an end-of-list marker, the range
13785 describes an empty scope, i.e. no instructions. */
13791 *high_return
= high
;
13795 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
13796 definition for the return value. *LOWPC and *HIGHPC are set iff
13797 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
13799 static enum pc_bounds_kind
13800 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
13801 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
13802 dwarf2_psymtab
*pst
)
13804 struct dwarf2_per_objfile
*dwarf2_per_objfile
13805 = cu
->per_cu
->dwarf2_per_objfile
;
13806 struct attribute
*attr
;
13807 struct attribute
*attr_high
;
13809 CORE_ADDR high
= 0;
13810 enum pc_bounds_kind ret
;
13812 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
13815 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13816 if (attr
!= nullptr)
13818 low
= attr
->value_as_address ();
13819 high
= attr_high
->value_as_address ();
13820 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
13824 /* Found high w/o low attribute. */
13825 return PC_BOUNDS_INVALID
;
13827 /* Found consecutive range of addresses. */
13828 ret
= PC_BOUNDS_HIGH_LOW
;
13832 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
13835 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
13836 We take advantage of the fact that DW_AT_ranges does not appear
13837 in DW_TAG_compile_unit of DWO files. */
13838 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
13839 unsigned int ranges_offset
= (DW_UNSND (attr
)
13840 + (need_ranges_base
13844 /* Value of the DW_AT_ranges attribute is the offset in the
13845 .debug_ranges section. */
13846 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
13847 return PC_BOUNDS_INVALID
;
13848 /* Found discontinuous range of addresses. */
13849 ret
= PC_BOUNDS_RANGES
;
13852 return PC_BOUNDS_NOT_PRESENT
;
13855 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
13857 return PC_BOUNDS_INVALID
;
13859 /* When using the GNU linker, .gnu.linkonce. sections are used to
13860 eliminate duplicate copies of functions and vtables and such.
13861 The linker will arbitrarily choose one and discard the others.
13862 The AT_*_pc values for such functions refer to local labels in
13863 these sections. If the section from that file was discarded, the
13864 labels are not in the output, so the relocs get a value of 0.
13865 If this is a discarded function, mark the pc bounds as invalid,
13866 so that GDB will ignore it. */
13867 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
13868 return PC_BOUNDS_INVALID
;
13876 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
13877 its low and high PC addresses. Do nothing if these addresses could not
13878 be determined. Otherwise, set LOWPC to the low address if it is smaller,
13879 and HIGHPC to the high address if greater than HIGHPC. */
13882 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
13883 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
13884 struct dwarf2_cu
*cu
)
13886 CORE_ADDR low
, high
;
13887 struct die_info
*child
= die
->child
;
13889 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
13891 *lowpc
= std::min (*lowpc
, low
);
13892 *highpc
= std::max (*highpc
, high
);
13895 /* If the language does not allow nested subprograms (either inside
13896 subprograms or lexical blocks), we're done. */
13897 if (cu
->language
!= language_ada
)
13900 /* Check all the children of the given DIE. If it contains nested
13901 subprograms, then check their pc bounds. Likewise, we need to
13902 check lexical blocks as well, as they may also contain subprogram
13904 while (child
&& child
->tag
)
13906 if (child
->tag
== DW_TAG_subprogram
13907 || child
->tag
== DW_TAG_lexical_block
)
13908 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
13909 child
= child
->sibling
;
13913 /* Get the low and high pc's represented by the scope DIE, and store
13914 them in *LOWPC and *HIGHPC. If the correct values can't be
13915 determined, set *LOWPC to -1 and *HIGHPC to 0. */
13918 get_scope_pc_bounds (struct die_info
*die
,
13919 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
13920 struct dwarf2_cu
*cu
)
13922 CORE_ADDR best_low
= (CORE_ADDR
) -1;
13923 CORE_ADDR best_high
= (CORE_ADDR
) 0;
13924 CORE_ADDR current_low
, current_high
;
13926 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
13927 >= PC_BOUNDS_RANGES
)
13929 best_low
= current_low
;
13930 best_high
= current_high
;
13934 struct die_info
*child
= die
->child
;
13936 while (child
&& child
->tag
)
13938 switch (child
->tag
) {
13939 case DW_TAG_subprogram
:
13940 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
13942 case DW_TAG_namespace
:
13943 case DW_TAG_module
:
13944 /* FIXME: carlton/2004-01-16: Should we do this for
13945 DW_TAG_class_type/DW_TAG_structure_type, too? I think
13946 that current GCC's always emit the DIEs corresponding
13947 to definitions of methods of classes as children of a
13948 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
13949 the DIEs giving the declarations, which could be
13950 anywhere). But I don't see any reason why the
13951 standards says that they have to be there. */
13952 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
13954 if (current_low
!= ((CORE_ADDR
) -1))
13956 best_low
= std::min (best_low
, current_low
);
13957 best_high
= std::max (best_high
, current_high
);
13965 child
= child
->sibling
;
13970 *highpc
= best_high
;
13973 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
13977 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
13978 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
13980 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13981 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13982 struct attribute
*attr
;
13983 struct attribute
*attr_high
;
13985 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
13988 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13989 if (attr
!= nullptr)
13991 CORE_ADDR low
= attr
->value_as_address ();
13992 CORE_ADDR high
= attr_high
->value_as_address ();
13994 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
13997 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
13998 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
13999 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14003 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14004 if (attr
!= nullptr)
14006 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14007 We take advantage of the fact that DW_AT_ranges does not appear
14008 in DW_TAG_compile_unit of DWO files. */
14009 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14011 /* The value of the DW_AT_ranges attribute is the offset of the
14012 address range list in the .debug_ranges section. */
14013 unsigned long offset
= (DW_UNSND (attr
)
14014 + (need_ranges_base
? cu
->ranges_base
: 0));
14016 std::vector
<blockrange
> blockvec
;
14017 dwarf2_ranges_process (offset
, cu
,
14018 [&] (CORE_ADDR start
, CORE_ADDR end
)
14022 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14023 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14024 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14025 blockvec
.emplace_back (start
, end
);
14028 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14032 /* Check whether the producer field indicates either of GCC < 4.6, or the
14033 Intel C/C++ compiler, and cache the result in CU. */
14036 check_producer (struct dwarf2_cu
*cu
)
14040 if (cu
->producer
== NULL
)
14042 /* For unknown compilers expect their behavior is DWARF version
14045 GCC started to support .debug_types sections by -gdwarf-4 since
14046 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14047 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14048 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14049 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14051 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14053 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14054 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14056 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14058 cu
->producer_is_icc
= true;
14059 cu
->producer_is_icc_lt_14
= major
< 14;
14061 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14062 cu
->producer_is_codewarrior
= true;
14065 /* For other non-GCC compilers, expect their behavior is DWARF version
14069 cu
->checked_producer
= true;
14072 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14073 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14074 during 4.6.0 experimental. */
14077 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14079 if (!cu
->checked_producer
)
14080 check_producer (cu
);
14082 return cu
->producer_is_gxx_lt_4_6
;
14086 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14087 with incorrect is_stmt attributes. */
14090 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14092 if (!cu
->checked_producer
)
14093 check_producer (cu
);
14095 return cu
->producer_is_codewarrior
;
14098 /* Return the default accessibility type if it is not overridden by
14099 DW_AT_accessibility. */
14101 static enum dwarf_access_attribute
14102 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14104 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14106 /* The default DWARF 2 accessibility for members is public, the default
14107 accessibility for inheritance is private. */
14109 if (die
->tag
!= DW_TAG_inheritance
)
14110 return DW_ACCESS_public
;
14112 return DW_ACCESS_private
;
14116 /* DWARF 3+ defines the default accessibility a different way. The same
14117 rules apply now for DW_TAG_inheritance as for the members and it only
14118 depends on the container kind. */
14120 if (die
->parent
->tag
== DW_TAG_class_type
)
14121 return DW_ACCESS_private
;
14123 return DW_ACCESS_public
;
14127 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14128 offset. If the attribute was not found return 0, otherwise return
14129 1. If it was found but could not properly be handled, set *OFFSET
14133 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14136 struct attribute
*attr
;
14138 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14143 /* Note that we do not check for a section offset first here.
14144 This is because DW_AT_data_member_location is new in DWARF 4,
14145 so if we see it, we can assume that a constant form is really
14146 a constant and not a section offset. */
14147 if (attr
->form_is_constant ())
14148 *offset
= attr
->constant_value (0);
14149 else if (attr
->form_is_section_offset ())
14150 dwarf2_complex_location_expr_complaint ();
14151 else if (attr
->form_is_block ())
14152 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14154 dwarf2_complex_location_expr_complaint ();
14162 /* Add an aggregate field to the field list. */
14165 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14166 struct dwarf2_cu
*cu
)
14168 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14169 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14170 struct nextfield
*new_field
;
14171 struct attribute
*attr
;
14173 const char *fieldname
= "";
14175 if (die
->tag
== DW_TAG_inheritance
)
14177 fip
->baseclasses
.emplace_back ();
14178 new_field
= &fip
->baseclasses
.back ();
14182 fip
->fields
.emplace_back ();
14183 new_field
= &fip
->fields
.back ();
14186 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14187 if (attr
!= nullptr)
14188 new_field
->accessibility
= DW_UNSND (attr
);
14190 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
14191 if (new_field
->accessibility
!= DW_ACCESS_public
)
14192 fip
->non_public_fields
= 1;
14194 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14195 if (attr
!= nullptr)
14196 new_field
->virtuality
= DW_UNSND (attr
);
14198 new_field
->virtuality
= DW_VIRTUALITY_none
;
14200 fp
= &new_field
->field
;
14202 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14206 /* Data member other than a C++ static data member. */
14208 /* Get type of field. */
14209 fp
->type
= die_type (die
, cu
);
14211 SET_FIELD_BITPOS (*fp
, 0);
14213 /* Get bit size of field (zero if none). */
14214 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14215 if (attr
!= nullptr)
14217 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
14221 FIELD_BITSIZE (*fp
) = 0;
14224 /* Get bit offset of field. */
14225 if (handle_data_member_location (die
, cu
, &offset
))
14226 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
14227 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14228 if (attr
!= nullptr)
14230 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14232 /* For big endian bits, the DW_AT_bit_offset gives the
14233 additional bit offset from the MSB of the containing
14234 anonymous object to the MSB of the field. We don't
14235 have to do anything special since we don't need to
14236 know the size of the anonymous object. */
14237 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
14241 /* For little endian bits, compute the bit offset to the
14242 MSB of the anonymous object, subtract off the number of
14243 bits from the MSB of the field to the MSB of the
14244 object, and then subtract off the number of bits of
14245 the field itself. The result is the bit offset of
14246 the LSB of the field. */
14247 int anonymous_size
;
14248 int bit_offset
= DW_UNSND (attr
);
14250 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14251 if (attr
!= nullptr)
14253 /* The size of the anonymous object containing
14254 the bit field is explicit, so use the
14255 indicated size (in bytes). */
14256 anonymous_size
= DW_UNSND (attr
);
14260 /* The size of the anonymous object containing
14261 the bit field must be inferred from the type
14262 attribute of the data member containing the
14264 anonymous_size
= TYPE_LENGTH (fp
->type
);
14266 SET_FIELD_BITPOS (*fp
,
14267 (FIELD_BITPOS (*fp
)
14268 + anonymous_size
* bits_per_byte
14269 - bit_offset
- FIELD_BITSIZE (*fp
)));
14272 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14274 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14275 + attr
->constant_value (0)));
14277 /* Get name of field. */
14278 fieldname
= dwarf2_name (die
, cu
);
14279 if (fieldname
== NULL
)
14282 /* The name is already allocated along with this objfile, so we don't
14283 need to duplicate it for the type. */
14284 fp
->name
= fieldname
;
14286 /* Change accessibility for artificial fields (e.g. virtual table
14287 pointer or virtual base class pointer) to private. */
14288 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
14290 FIELD_ARTIFICIAL (*fp
) = 1;
14291 new_field
->accessibility
= DW_ACCESS_private
;
14292 fip
->non_public_fields
= 1;
14295 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
14297 /* C++ static member. */
14299 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
14300 is a declaration, but all versions of G++ as of this writing
14301 (so through at least 3.2.1) incorrectly generate
14302 DW_TAG_variable tags. */
14304 const char *physname
;
14306 /* Get name of field. */
14307 fieldname
= dwarf2_name (die
, cu
);
14308 if (fieldname
== NULL
)
14311 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14313 /* Only create a symbol if this is an external value.
14314 new_symbol checks this and puts the value in the global symbol
14315 table, which we want. If it is not external, new_symbol
14316 will try to put the value in cu->list_in_scope which is wrong. */
14317 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
14319 /* A static const member, not much different than an enum as far as
14320 we're concerned, except that we can support more types. */
14321 new_symbol (die
, NULL
, cu
);
14324 /* Get physical name. */
14325 physname
= dwarf2_physname (fieldname
, die
, cu
);
14327 /* The name is already allocated along with this objfile, so we don't
14328 need to duplicate it for the type. */
14329 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
14330 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14331 FIELD_NAME (*fp
) = fieldname
;
14333 else if (die
->tag
== DW_TAG_inheritance
)
14337 /* C++ base class field. */
14338 if (handle_data_member_location (die
, cu
, &offset
))
14339 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
14340 FIELD_BITSIZE (*fp
) = 0;
14341 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14342 FIELD_NAME (*fp
) = TYPE_NAME (fp
->type
);
14344 else if (die
->tag
== DW_TAG_variant_part
)
14346 /* process_structure_scope will treat this DIE as a union. */
14347 process_structure_scope (die
, cu
);
14349 /* The variant part is relative to the start of the enclosing
14351 SET_FIELD_BITPOS (*fp
, 0);
14352 fp
->type
= get_die_type (die
, cu
);
14353 fp
->artificial
= 1;
14354 fp
->name
= "<<variant>>";
14356 /* Normally a DW_TAG_variant_part won't have a size, but our
14357 representation requires one, so set it to the maximum of the
14358 child sizes, being sure to account for the offset at which
14359 each child is seen. */
14360 if (TYPE_LENGTH (fp
->type
) == 0)
14363 for (int i
= 0; i
< TYPE_NFIELDS (fp
->type
); ++i
)
14365 unsigned len
= ((TYPE_FIELD_BITPOS (fp
->type
, i
) + 7) / 8
14366 + TYPE_LENGTH (TYPE_FIELD_TYPE (fp
->type
, i
)));
14370 TYPE_LENGTH (fp
->type
) = max
;
14374 gdb_assert_not_reached ("missing case in dwarf2_add_field");
14377 /* Can the type given by DIE define another type? */
14380 type_can_define_types (const struct die_info
*die
)
14384 case DW_TAG_typedef
:
14385 case DW_TAG_class_type
:
14386 case DW_TAG_structure_type
:
14387 case DW_TAG_union_type
:
14388 case DW_TAG_enumeration_type
:
14396 /* Add a type definition defined in the scope of the FIP's class. */
14399 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
14400 struct dwarf2_cu
*cu
)
14402 struct decl_field fp
;
14403 memset (&fp
, 0, sizeof (fp
));
14405 gdb_assert (type_can_define_types (die
));
14407 /* Get name of field. NULL is okay here, meaning an anonymous type. */
14408 fp
.name
= dwarf2_name (die
, cu
);
14409 fp
.type
= read_type_die (die
, cu
);
14411 /* Save accessibility. */
14412 enum dwarf_access_attribute accessibility
;
14413 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14415 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14417 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14418 switch (accessibility
)
14420 case DW_ACCESS_public
:
14421 /* The assumed value if neither private nor protected. */
14423 case DW_ACCESS_private
:
14426 case DW_ACCESS_protected
:
14427 fp
.is_protected
= 1;
14430 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
14433 if (die
->tag
== DW_TAG_typedef
)
14434 fip
->typedef_field_list
.push_back (fp
);
14436 fip
->nested_types_list
.push_back (fp
);
14439 /* Create the vector of fields, and attach it to the type. */
14442 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
14443 struct dwarf2_cu
*cu
)
14445 int nfields
= fip
->nfields ();
14447 /* Record the field count, allocate space for the array of fields,
14448 and create blank accessibility bitfields if necessary. */
14449 TYPE_NFIELDS (type
) = nfields
;
14450 TYPE_FIELDS (type
) = (struct field
*)
14451 TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
);
14453 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
14455 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14457 TYPE_FIELD_PRIVATE_BITS (type
) =
14458 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14459 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
14461 TYPE_FIELD_PROTECTED_BITS (type
) =
14462 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14463 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
14465 TYPE_FIELD_IGNORE_BITS (type
) =
14466 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14467 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
14470 /* If the type has baseclasses, allocate and clear a bit vector for
14471 TYPE_FIELD_VIRTUAL_BITS. */
14472 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
14474 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
14475 unsigned char *pointer
;
14477 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14478 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
14479 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
14480 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
14481 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
14484 if (TYPE_FLAG_DISCRIMINATED_UNION (type
))
14486 struct discriminant_info
*di
= alloc_discriminant_info (type
, -1, -1);
14488 for (int index
= 0; index
< nfields
; ++index
)
14490 struct nextfield
&field
= fip
->fields
[index
];
14492 if (field
.variant
.is_discriminant
)
14493 di
->discriminant_index
= index
;
14494 else if (field
.variant
.default_branch
)
14495 di
->default_index
= index
;
14497 di
->discriminants
[index
] = field
.variant
.discriminant_value
;
14501 /* Copy the saved-up fields into the field vector. */
14502 for (int i
= 0; i
< nfields
; ++i
)
14504 struct nextfield
&field
14505 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
14506 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
14508 TYPE_FIELD (type
, i
) = field
.field
;
14509 switch (field
.accessibility
)
14511 case DW_ACCESS_private
:
14512 if (cu
->language
!= language_ada
)
14513 SET_TYPE_FIELD_PRIVATE (type
, i
);
14516 case DW_ACCESS_protected
:
14517 if (cu
->language
!= language_ada
)
14518 SET_TYPE_FIELD_PROTECTED (type
, i
);
14521 case DW_ACCESS_public
:
14525 /* Unknown accessibility. Complain and treat it as public. */
14527 complaint (_("unsupported accessibility %d"),
14528 field
.accessibility
);
14532 if (i
< fip
->baseclasses
.size ())
14534 switch (field
.virtuality
)
14536 case DW_VIRTUALITY_virtual
:
14537 case DW_VIRTUALITY_pure_virtual
:
14538 if (cu
->language
== language_ada
)
14539 error (_("unexpected virtuality in component of Ada type"));
14540 SET_TYPE_FIELD_VIRTUAL (type
, i
);
14547 /* Return true if this member function is a constructor, false
14551 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
14553 const char *fieldname
;
14554 const char *type_name
;
14557 if (die
->parent
== NULL
)
14560 if (die
->parent
->tag
!= DW_TAG_structure_type
14561 && die
->parent
->tag
!= DW_TAG_union_type
14562 && die
->parent
->tag
!= DW_TAG_class_type
)
14565 fieldname
= dwarf2_name (die
, cu
);
14566 type_name
= dwarf2_name (die
->parent
, cu
);
14567 if (fieldname
== NULL
|| type_name
== NULL
)
14570 len
= strlen (fieldname
);
14571 return (strncmp (fieldname
, type_name
, len
) == 0
14572 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
14575 /* Check if the given VALUE is a recognized enum
14576 dwarf_defaulted_attribute constant according to DWARF5 spec,
14580 is_valid_DW_AT_defaulted (ULONGEST value
)
14584 case DW_DEFAULTED_no
:
14585 case DW_DEFAULTED_in_class
:
14586 case DW_DEFAULTED_out_of_class
:
14590 complaint (_("unrecognized DW_AT_defaulted value (%s)"), pulongest (value
));
14594 /* Add a member function to the proper fieldlist. */
14597 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
14598 struct type
*type
, struct dwarf2_cu
*cu
)
14600 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14601 struct attribute
*attr
;
14603 struct fnfieldlist
*flp
= nullptr;
14604 struct fn_field
*fnp
;
14605 const char *fieldname
;
14606 struct type
*this_type
;
14607 enum dwarf_access_attribute accessibility
;
14609 if (cu
->language
== language_ada
)
14610 error (_("unexpected member function in Ada type"));
14612 /* Get name of member function. */
14613 fieldname
= dwarf2_name (die
, cu
);
14614 if (fieldname
== NULL
)
14617 /* Look up member function name in fieldlist. */
14618 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
14620 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
14622 flp
= &fip
->fnfieldlists
[i
];
14627 /* Create a new fnfieldlist if necessary. */
14628 if (flp
== nullptr)
14630 fip
->fnfieldlists
.emplace_back ();
14631 flp
= &fip
->fnfieldlists
.back ();
14632 flp
->name
= fieldname
;
14633 i
= fip
->fnfieldlists
.size () - 1;
14636 /* Create a new member function field and add it to the vector of
14638 flp
->fnfields
.emplace_back ();
14639 fnp
= &flp
->fnfields
.back ();
14641 /* Delay processing of the physname until later. */
14642 if (cu
->language
== language_cplus
)
14643 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
14647 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
14648 fnp
->physname
= physname
? physname
: "";
14651 fnp
->type
= alloc_type (objfile
);
14652 this_type
= read_type_die (die
, cu
);
14653 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
14655 int nparams
= TYPE_NFIELDS (this_type
);
14657 /* TYPE is the domain of this method, and THIS_TYPE is the type
14658 of the method itself (TYPE_CODE_METHOD). */
14659 smash_to_method_type (fnp
->type
, type
,
14660 TYPE_TARGET_TYPE (this_type
),
14661 TYPE_FIELDS (this_type
),
14662 TYPE_NFIELDS (this_type
),
14663 TYPE_VARARGS (this_type
));
14665 /* Handle static member functions.
14666 Dwarf2 has no clean way to discern C++ static and non-static
14667 member functions. G++ helps GDB by marking the first
14668 parameter for non-static member functions (which is the this
14669 pointer) as artificial. We obtain this information from
14670 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
14671 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
14672 fnp
->voffset
= VOFFSET_STATIC
;
14675 complaint (_("member function type missing for '%s'"),
14676 dwarf2_full_name (fieldname
, die
, cu
));
14678 /* Get fcontext from DW_AT_containing_type if present. */
14679 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
14680 fnp
->fcontext
= die_containing_type (die
, cu
);
14682 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
14683 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
14685 /* Get accessibility. */
14686 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14687 if (attr
!= nullptr)
14688 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14690 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14691 switch (accessibility
)
14693 case DW_ACCESS_private
:
14694 fnp
->is_private
= 1;
14696 case DW_ACCESS_protected
:
14697 fnp
->is_protected
= 1;
14701 /* Check for artificial methods. */
14702 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
14703 if (attr
&& DW_UNSND (attr
) != 0)
14704 fnp
->is_artificial
= 1;
14706 /* Check for defaulted methods. */
14707 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
14708 if (attr
!= nullptr && is_valid_DW_AT_defaulted (DW_UNSND (attr
)))
14709 fnp
->defaulted
= (enum dwarf_defaulted_attribute
) DW_UNSND (attr
);
14711 /* Check for deleted methods. */
14712 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
14713 if (attr
!= nullptr && DW_UNSND (attr
) != 0)
14714 fnp
->is_deleted
= 1;
14716 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
14718 /* Get index in virtual function table if it is a virtual member
14719 function. For older versions of GCC, this is an offset in the
14720 appropriate virtual table, as specified by DW_AT_containing_type.
14721 For everyone else, it is an expression to be evaluated relative
14722 to the object address. */
14724 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
14725 if (attr
!= nullptr)
14727 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
> 0)
14729 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
14731 /* Old-style GCC. */
14732 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
14734 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
14735 || (DW_BLOCK (attr
)->size
> 1
14736 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
14737 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
14739 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14740 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
14741 dwarf2_complex_location_expr_complaint ();
14743 fnp
->voffset
/= cu
->header
.addr_size
;
14747 dwarf2_complex_location_expr_complaint ();
14749 if (!fnp
->fcontext
)
14751 /* If there is no `this' field and no DW_AT_containing_type,
14752 we cannot actually find a base class context for the
14754 if (TYPE_NFIELDS (this_type
) == 0
14755 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
14757 complaint (_("cannot determine context for virtual member "
14758 "function \"%s\" (offset %s)"),
14759 fieldname
, sect_offset_str (die
->sect_off
));
14764 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
14768 else if (attr
->form_is_section_offset ())
14770 dwarf2_complex_location_expr_complaint ();
14774 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
14780 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14781 if (attr
&& DW_UNSND (attr
))
14783 /* GCC does this, as of 2008-08-25; PR debug/37237. */
14784 complaint (_("Member function \"%s\" (offset %s) is virtual "
14785 "but the vtable offset is not specified"),
14786 fieldname
, sect_offset_str (die
->sect_off
));
14787 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14788 TYPE_CPLUS_DYNAMIC (type
) = 1;
14793 /* Create the vector of member function fields, and attach it to the type. */
14796 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
14797 struct dwarf2_cu
*cu
)
14799 if (cu
->language
== language_ada
)
14800 error (_("unexpected member functions in Ada type"));
14802 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14803 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
14805 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
14807 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
14809 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
14810 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
14812 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
14813 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
14814 fn_flp
->fn_fields
= (struct fn_field
*)
14815 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
14817 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
14818 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
14821 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
14824 /* Returns non-zero if NAME is the name of a vtable member in CU's
14825 language, zero otherwise. */
14827 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
14829 static const char vptr
[] = "_vptr";
14831 /* Look for the C++ form of the vtable. */
14832 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
14838 /* GCC outputs unnamed structures that are really pointers to member
14839 functions, with the ABI-specified layout. If TYPE describes
14840 such a structure, smash it into a member function type.
14842 GCC shouldn't do this; it should just output pointer to member DIEs.
14843 This is GCC PR debug/28767. */
14846 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
14848 struct type
*pfn_type
, *self_type
, *new_type
;
14850 /* Check for a structure with no name and two children. */
14851 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
14854 /* Check for __pfn and __delta members. */
14855 if (TYPE_FIELD_NAME (type
, 0) == NULL
14856 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
14857 || TYPE_FIELD_NAME (type
, 1) == NULL
14858 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
14861 /* Find the type of the method. */
14862 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
14863 if (pfn_type
== NULL
14864 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
14865 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
14868 /* Look for the "this" argument. */
14869 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
14870 if (TYPE_NFIELDS (pfn_type
) == 0
14871 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
14872 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
14875 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
14876 new_type
= alloc_type (objfile
);
14877 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
14878 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
14879 TYPE_VARARGS (pfn_type
));
14880 smash_to_methodptr_type (type
, new_type
);
14883 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
14884 appropriate error checking and issuing complaints if there is a
14888 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
14890 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
14892 if (attr
== nullptr)
14895 if (!attr
->form_is_constant ())
14897 complaint (_("DW_AT_alignment must have constant form"
14898 " - DIE at %s [in module %s]"),
14899 sect_offset_str (die
->sect_off
),
14900 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14905 if (attr
->form
== DW_FORM_sdata
)
14907 LONGEST val
= DW_SND (attr
);
14910 complaint (_("DW_AT_alignment value must not be negative"
14911 " - DIE at %s [in module %s]"),
14912 sect_offset_str (die
->sect_off
),
14913 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14919 align
= DW_UNSND (attr
);
14923 complaint (_("DW_AT_alignment value must not be zero"
14924 " - DIE at %s [in module %s]"),
14925 sect_offset_str (die
->sect_off
),
14926 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14929 if ((align
& (align
- 1)) != 0)
14931 complaint (_("DW_AT_alignment value must be a power of 2"
14932 " - DIE at %s [in module %s]"),
14933 sect_offset_str (die
->sect_off
),
14934 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14941 /* If the DIE has a DW_AT_alignment attribute, use its value to set
14942 the alignment for TYPE. */
14945 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
14948 if (!set_type_align (type
, get_alignment (cu
, die
)))
14949 complaint (_("DW_AT_alignment value too large"
14950 " - DIE at %s [in module %s]"),
14951 sect_offset_str (die
->sect_off
),
14952 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14955 /* Check if the given VALUE is a valid enum dwarf_calling_convention
14956 constant for a type, according to DWARF5 spec, Table 5.5. */
14959 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
14964 case DW_CC_pass_by_reference
:
14965 case DW_CC_pass_by_value
:
14969 complaint (_("unrecognized DW_AT_calling_convention value "
14970 "(%s) for a type"), pulongest (value
));
14975 /* Check if the given VALUE is a valid enum dwarf_calling_convention
14976 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
14977 also according to GNU-specific values (see include/dwarf2.h). */
14980 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
14985 case DW_CC_program
:
14989 case DW_CC_GNU_renesas_sh
:
14990 case DW_CC_GNU_borland_fastcall_i386
:
14991 case DW_CC_GDB_IBM_OpenCL
:
14995 complaint (_("unrecognized DW_AT_calling_convention value "
14996 "(%s) for a subroutine"), pulongest (value
));
15001 /* Called when we find the DIE that starts a structure or union scope
15002 (definition) to create a type for the structure or union. Fill in
15003 the type's name and general properties; the members will not be
15004 processed until process_structure_scope. A symbol table entry for
15005 the type will also not be done until process_structure_scope (assuming
15006 the type has a name).
15008 NOTE: we need to call these functions regardless of whether or not the
15009 DIE has a DW_AT_name attribute, since it might be an anonymous
15010 structure or union. This gets the type entered into our set of
15011 user defined types. */
15013 static struct type
*
15014 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15016 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15018 struct attribute
*attr
;
15021 /* If the definition of this type lives in .debug_types, read that type.
15022 Don't follow DW_AT_specification though, that will take us back up
15023 the chain and we want to go down. */
15024 attr
= die
->attr (DW_AT_signature
);
15025 if (attr
!= nullptr)
15027 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15029 /* The type's CU may not be the same as CU.
15030 Ensure TYPE is recorded with CU in die_type_hash. */
15031 return set_die_type (die
, type
, cu
);
15034 type
= alloc_type (objfile
);
15035 INIT_CPLUS_SPECIFIC (type
);
15037 name
= dwarf2_name (die
, cu
);
15040 if (cu
->language
== language_cplus
15041 || cu
->language
== language_d
15042 || cu
->language
== language_rust
)
15044 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15046 /* dwarf2_full_name might have already finished building the DIE's
15047 type. If so, there is no need to continue. */
15048 if (get_die_type (die
, cu
) != NULL
)
15049 return get_die_type (die
, cu
);
15051 TYPE_NAME (type
) = full_name
;
15055 /* The name is already allocated along with this objfile, so
15056 we don't need to duplicate it for the type. */
15057 TYPE_NAME (type
) = name
;
15061 if (die
->tag
== DW_TAG_structure_type
)
15063 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15065 else if (die
->tag
== DW_TAG_union_type
)
15067 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15069 else if (die
->tag
== DW_TAG_variant_part
)
15071 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15072 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
15076 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15079 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15080 TYPE_DECLARED_CLASS (type
) = 1;
15082 /* Store the calling convention in the type if it's available in
15083 the die. Otherwise the calling convention remains set to
15084 the default value DW_CC_normal. */
15085 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15086 if (attr
!= nullptr
15087 && is_valid_DW_AT_calling_convention_for_type (DW_UNSND (attr
)))
15089 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15090 TYPE_CPLUS_CALLING_CONVENTION (type
)
15091 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
15094 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15095 if (attr
!= nullptr)
15097 if (attr
->form_is_constant ())
15098 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15101 /* For the moment, dynamic type sizes are not supported
15102 by GDB's struct type. The actual size is determined
15103 on-demand when resolving the type of a given object,
15104 so set the type's length to zero for now. Otherwise,
15105 we record an expression as the length, and that expression
15106 could lead to a very large value, which could eventually
15107 lead to us trying to allocate that much memory when creating
15108 a value of that type. */
15109 TYPE_LENGTH (type
) = 0;
15114 TYPE_LENGTH (type
) = 0;
15117 maybe_set_alignment (cu
, die
, type
);
15119 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15121 /* ICC<14 does not output the required DW_AT_declaration on
15122 incomplete types, but gives them a size of zero. */
15123 TYPE_STUB (type
) = 1;
15126 TYPE_STUB_SUPPORTED (type
) = 1;
15128 if (die_is_declaration (die
, cu
))
15129 TYPE_STUB (type
) = 1;
15130 else if (attr
== NULL
&& die
->child
== NULL
15131 && producer_is_realview (cu
->producer
))
15132 /* RealView does not output the required DW_AT_declaration
15133 on incomplete types. */
15134 TYPE_STUB (type
) = 1;
15136 /* We need to add the type field to the die immediately so we don't
15137 infinitely recurse when dealing with pointers to the structure
15138 type within the structure itself. */
15139 set_die_type (die
, type
, cu
);
15141 /* set_die_type should be already done. */
15142 set_descriptive_type (type
, die
, cu
);
15147 /* A helper for process_structure_scope that handles a single member
15151 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15152 struct field_info
*fi
,
15153 std::vector
<struct symbol
*> *template_args
,
15154 struct dwarf2_cu
*cu
)
15156 if (child_die
->tag
== DW_TAG_member
15157 || child_die
->tag
== DW_TAG_variable
15158 || child_die
->tag
== DW_TAG_variant_part
)
15160 /* NOTE: carlton/2002-11-05: A C++ static data member
15161 should be a DW_TAG_member that is a declaration, but
15162 all versions of G++ as of this writing (so through at
15163 least 3.2.1) incorrectly generate DW_TAG_variable
15164 tags for them instead. */
15165 dwarf2_add_field (fi
, child_die
, cu
);
15167 else if (child_die
->tag
== DW_TAG_subprogram
)
15169 /* Rust doesn't have member functions in the C++ sense.
15170 However, it does emit ordinary functions as children
15171 of a struct DIE. */
15172 if (cu
->language
== language_rust
)
15173 read_func_scope (child_die
, cu
);
15176 /* C++ member function. */
15177 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15180 else if (child_die
->tag
== DW_TAG_inheritance
)
15182 /* C++ base class field. */
15183 dwarf2_add_field (fi
, child_die
, cu
);
15185 else if (type_can_define_types (child_die
))
15186 dwarf2_add_type_defn (fi
, child_die
, cu
);
15187 else if (child_die
->tag
== DW_TAG_template_type_param
15188 || child_die
->tag
== DW_TAG_template_value_param
)
15190 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15193 template_args
->push_back (arg
);
15195 else if (child_die
->tag
== DW_TAG_variant
)
15197 /* In a variant we want to get the discriminant and also add a
15198 field for our sole member child. */
15199 struct attribute
*discr
= dwarf2_attr (child_die
, DW_AT_discr_value
, cu
);
15201 for (die_info
*variant_child
= child_die
->child
;
15202 variant_child
!= NULL
;
15203 variant_child
= variant_child
->sibling
)
15205 if (variant_child
->tag
== DW_TAG_member
)
15207 handle_struct_member_die (variant_child
, type
, fi
,
15208 template_args
, cu
);
15209 /* Only handle the one. */
15214 /* We don't handle this but we might as well report it if we see
15216 if (dwarf2_attr (child_die
, DW_AT_discr_list
, cu
) != nullptr)
15217 complaint (_("DW_AT_discr_list is not supported yet"
15218 " - DIE at %s [in module %s]"),
15219 sect_offset_str (child_die
->sect_off
),
15220 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15222 /* The first field was just added, so we can stash the
15223 discriminant there. */
15224 gdb_assert (!fi
->fields
.empty ());
15226 fi
->fields
.back ().variant
.default_branch
= true;
15228 fi
->fields
.back ().variant
.discriminant_value
= DW_UNSND (discr
);
15232 /* Finish creating a structure or union type, including filling in
15233 its members and creating a symbol for it. */
15236 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15238 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15239 struct die_info
*child_die
;
15242 type
= get_die_type (die
, cu
);
15244 type
= read_structure_type (die
, cu
);
15246 /* When reading a DW_TAG_variant_part, we need to notice when we
15247 read the discriminant member, so we can record it later in the
15248 discriminant_info. */
15249 bool is_variant_part
= TYPE_FLAG_DISCRIMINATED_UNION (type
);
15250 sect_offset discr_offset
{};
15251 bool has_template_parameters
= false;
15253 if (is_variant_part
)
15255 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15258 /* Maybe it's a univariant form, an extension we support.
15259 In this case arrange not to check the offset. */
15260 is_variant_part
= false;
15262 else if (discr
->form_is_ref ())
15264 struct dwarf2_cu
*target_cu
= cu
;
15265 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15267 discr_offset
= target_die
->sect_off
;
15271 complaint (_("DW_AT_discr does not have DIE reference form"
15272 " - DIE at %s [in module %s]"),
15273 sect_offset_str (die
->sect_off
),
15274 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15275 is_variant_part
= false;
15279 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15281 struct field_info fi
;
15282 std::vector
<struct symbol
*> template_args
;
15284 child_die
= die
->child
;
15286 while (child_die
&& child_die
->tag
)
15288 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15290 if (is_variant_part
&& discr_offset
== child_die
->sect_off
)
15291 fi
.fields
.back ().variant
.is_discriminant
= true;
15293 child_die
= child_die
->sibling
;
15296 /* Attach template arguments to type. */
15297 if (!template_args
.empty ())
15299 has_template_parameters
= true;
15300 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15301 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15302 TYPE_TEMPLATE_ARGUMENTS (type
)
15303 = XOBNEWVEC (&objfile
->objfile_obstack
,
15305 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15306 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15307 template_args
.data (),
15308 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15309 * sizeof (struct symbol
*)));
15312 /* Attach fields and member functions to the type. */
15313 if (fi
.nfields () > 0)
15314 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15315 if (!fi
.fnfieldlists
.empty ())
15317 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15319 /* Get the type which refers to the base class (possibly this
15320 class itself) which contains the vtable pointer for the current
15321 class from the DW_AT_containing_type attribute. This use of
15322 DW_AT_containing_type is a GNU extension. */
15324 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15326 struct type
*t
= die_containing_type (die
, cu
);
15328 set_type_vptr_basetype (type
, t
);
15333 /* Our own class provides vtbl ptr. */
15334 for (i
= TYPE_NFIELDS (t
) - 1;
15335 i
>= TYPE_N_BASECLASSES (t
);
15338 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
15340 if (is_vtable_name (fieldname
, cu
))
15342 set_type_vptr_fieldno (type
, i
);
15347 /* Complain if virtual function table field not found. */
15348 if (i
< TYPE_N_BASECLASSES (t
))
15349 complaint (_("virtual function table pointer "
15350 "not found when defining class '%s'"),
15351 TYPE_NAME (type
) ? TYPE_NAME (type
) : "");
15355 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
15358 else if (cu
->producer
15359 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
15361 /* The IBM XLC compiler does not provide direct indication
15362 of the containing type, but the vtable pointer is
15363 always named __vfp. */
15367 for (i
= TYPE_NFIELDS (type
) - 1;
15368 i
>= TYPE_N_BASECLASSES (type
);
15371 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
15373 set_type_vptr_fieldno (type
, i
);
15374 set_type_vptr_basetype (type
, type
);
15381 /* Copy fi.typedef_field_list linked list elements content into the
15382 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
15383 if (!fi
.typedef_field_list
.empty ())
15385 int count
= fi
.typedef_field_list
.size ();
15387 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15388 TYPE_TYPEDEF_FIELD_ARRAY (type
)
15389 = ((struct decl_field
*)
15391 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
15392 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
15394 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
15395 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
15398 /* Copy fi.nested_types_list linked list elements content into the
15399 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
15400 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
15402 int count
= fi
.nested_types_list
.size ();
15404 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15405 TYPE_NESTED_TYPES_ARRAY (type
)
15406 = ((struct decl_field
*)
15407 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
15408 TYPE_NESTED_TYPES_COUNT (type
) = count
;
15410 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
15411 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
15415 quirk_gcc_member_function_pointer (type
, objfile
);
15416 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
15417 cu
->rust_unions
.push_back (type
);
15419 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
15420 snapshots) has been known to create a die giving a declaration
15421 for a class that has, as a child, a die giving a definition for a
15422 nested class. So we have to process our children even if the
15423 current die is a declaration. Normally, of course, a declaration
15424 won't have any children at all. */
15426 child_die
= die
->child
;
15428 while (child_die
!= NULL
&& child_die
->tag
)
15430 if (child_die
->tag
== DW_TAG_member
15431 || child_die
->tag
== DW_TAG_variable
15432 || child_die
->tag
== DW_TAG_inheritance
15433 || child_die
->tag
== DW_TAG_template_value_param
15434 || child_die
->tag
== DW_TAG_template_type_param
)
15439 process_die (child_die
, cu
);
15441 child_die
= child_die
->sibling
;
15444 /* Do not consider external references. According to the DWARF standard,
15445 these DIEs are identified by the fact that they have no byte_size
15446 attribute, and a declaration attribute. */
15447 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
15448 || !die_is_declaration (die
, cu
))
15450 struct symbol
*sym
= new_symbol (die
, type
, cu
);
15452 if (has_template_parameters
)
15454 struct symtab
*symtab
;
15455 if (sym
!= nullptr)
15456 symtab
= symbol_symtab (sym
);
15457 else if (cu
->line_header
!= nullptr)
15459 /* Any related symtab will do. */
15461 = cu
->line_header
->file_names ()[0].symtab
;
15466 complaint (_("could not find suitable "
15467 "symtab for template parameter"
15468 " - DIE at %s [in module %s]"),
15469 sect_offset_str (die
->sect_off
),
15470 objfile_name (objfile
));
15473 if (symtab
!= nullptr)
15475 /* Make sure that the symtab is set on the new symbols.
15476 Even though they don't appear in this symtab directly,
15477 other parts of gdb assume that symbols do, and this is
15478 reasonably true. */
15479 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
15480 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
15486 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
15487 update TYPE using some information only available in DIE's children. */
15490 update_enumeration_type_from_children (struct die_info
*die
,
15492 struct dwarf2_cu
*cu
)
15494 struct die_info
*child_die
;
15495 int unsigned_enum
= 1;
15498 auto_obstack obstack
;
15500 for (child_die
= die
->child
;
15501 child_die
!= NULL
&& child_die
->tag
;
15502 child_die
= child_die
->sibling
)
15504 struct attribute
*attr
;
15506 const gdb_byte
*bytes
;
15507 struct dwarf2_locexpr_baton
*baton
;
15510 if (child_die
->tag
!= DW_TAG_enumerator
)
15513 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
15517 name
= dwarf2_name (child_die
, cu
);
15519 name
= "<anonymous enumerator>";
15521 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
15522 &value
, &bytes
, &baton
);
15530 if (count_one_bits_ll (value
) >= 2)
15534 /* If we already know that the enum type is neither unsigned, nor
15535 a flag type, no need to look at the rest of the enumerates. */
15536 if (!unsigned_enum
&& !flag_enum
)
15541 TYPE_UNSIGNED (type
) = 1;
15543 TYPE_FLAG_ENUM (type
) = 1;
15546 /* Given a DW_AT_enumeration_type die, set its type. We do not
15547 complete the type's fields yet, or create any symbols. */
15549 static struct type
*
15550 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15552 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15554 struct attribute
*attr
;
15557 /* If the definition of this type lives in .debug_types, read that type.
15558 Don't follow DW_AT_specification though, that will take us back up
15559 the chain and we want to go down. */
15560 attr
= die
->attr (DW_AT_signature
);
15561 if (attr
!= nullptr)
15563 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15565 /* The type's CU may not be the same as CU.
15566 Ensure TYPE is recorded with CU in die_type_hash. */
15567 return set_die_type (die
, type
, cu
);
15570 type
= alloc_type (objfile
);
15572 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
15573 name
= dwarf2_full_name (NULL
, die
, cu
);
15575 TYPE_NAME (type
) = name
;
15577 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
15580 struct type
*underlying_type
= die_type (die
, cu
);
15582 TYPE_TARGET_TYPE (type
) = underlying_type
;
15585 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15586 if (attr
!= nullptr)
15588 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15592 TYPE_LENGTH (type
) = 0;
15595 maybe_set_alignment (cu
, die
, type
);
15597 /* The enumeration DIE can be incomplete. In Ada, any type can be
15598 declared as private in the package spec, and then defined only
15599 inside the package body. Such types are known as Taft Amendment
15600 Types. When another package uses such a type, an incomplete DIE
15601 may be generated by the compiler. */
15602 if (die_is_declaration (die
, cu
))
15603 TYPE_STUB (type
) = 1;
15605 /* Finish the creation of this type by using the enum's children.
15606 We must call this even when the underlying type has been provided
15607 so that we can determine if we're looking at a "flag" enum. */
15608 update_enumeration_type_from_children (die
, type
, cu
);
15610 /* If this type has an underlying type that is not a stub, then we
15611 may use its attributes. We always use the "unsigned" attribute
15612 in this situation, because ordinarily we guess whether the type
15613 is unsigned -- but the guess can be wrong and the underlying type
15614 can tell us the reality. However, we defer to a local size
15615 attribute if one exists, because this lets the compiler override
15616 the underlying type if needed. */
15617 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
15619 struct type
*underlying_type
= TYPE_TARGET_TYPE (type
);
15620 underlying_type
= check_typedef (underlying_type
);
15621 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (underlying_type
);
15622 if (TYPE_LENGTH (type
) == 0)
15623 TYPE_LENGTH (type
) = TYPE_LENGTH (underlying_type
);
15624 if (TYPE_RAW_ALIGN (type
) == 0
15625 && TYPE_RAW_ALIGN (underlying_type
) != 0)
15626 set_type_align (type
, TYPE_RAW_ALIGN (underlying_type
));
15629 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
15631 return set_die_type (die
, type
, cu
);
15634 /* Given a pointer to a die which begins an enumeration, process all
15635 the dies that define the members of the enumeration, and create the
15636 symbol for the enumeration type.
15638 NOTE: We reverse the order of the element list. */
15641 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15643 struct type
*this_type
;
15645 this_type
= get_die_type (die
, cu
);
15646 if (this_type
== NULL
)
15647 this_type
= read_enumeration_type (die
, cu
);
15649 if (die
->child
!= NULL
)
15651 struct die_info
*child_die
;
15652 struct symbol
*sym
;
15653 std::vector
<struct field
> fields
;
15656 child_die
= die
->child
;
15657 while (child_die
&& child_die
->tag
)
15659 if (child_die
->tag
!= DW_TAG_enumerator
)
15661 process_die (child_die
, cu
);
15665 name
= dwarf2_name (child_die
, cu
);
15668 sym
= new_symbol (child_die
, this_type
, cu
);
15670 fields
.emplace_back ();
15671 struct field
&field
= fields
.back ();
15673 FIELD_NAME (field
) = sym
->linkage_name ();
15674 FIELD_TYPE (field
) = NULL
;
15675 SET_FIELD_ENUMVAL (field
, SYMBOL_VALUE (sym
));
15676 FIELD_BITSIZE (field
) = 0;
15680 child_die
= child_die
->sibling
;
15683 if (!fields
.empty ())
15685 TYPE_NFIELDS (this_type
) = fields
.size ();
15686 TYPE_FIELDS (this_type
) = (struct field
*)
15687 TYPE_ALLOC (this_type
, sizeof (struct field
) * fields
.size ());
15688 memcpy (TYPE_FIELDS (this_type
), fields
.data (),
15689 sizeof (struct field
) * fields
.size ());
15693 /* If we are reading an enum from a .debug_types unit, and the enum
15694 is a declaration, and the enum is not the signatured type in the
15695 unit, then we do not want to add a symbol for it. Adding a
15696 symbol would in some cases obscure the true definition of the
15697 enum, giving users an incomplete type when the definition is
15698 actually available. Note that we do not want to do this for all
15699 enums which are just declarations, because C++0x allows forward
15700 enum declarations. */
15701 if (cu
->per_cu
->is_debug_types
15702 && die_is_declaration (die
, cu
))
15704 struct signatured_type
*sig_type
;
15706 sig_type
= (struct signatured_type
*) cu
->per_cu
;
15707 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
15708 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
15712 new_symbol (die
, this_type
, cu
);
15715 /* Extract all information from a DW_TAG_array_type DIE and put it in
15716 the DIE's type field. For now, this only handles one dimensional
15719 static struct type
*
15720 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15722 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15723 struct die_info
*child_die
;
15725 struct type
*element_type
, *range_type
, *index_type
;
15726 struct attribute
*attr
;
15728 struct dynamic_prop
*byte_stride_prop
= NULL
;
15729 unsigned int bit_stride
= 0;
15731 element_type
= die_type (die
, cu
);
15733 /* The die_type call above may have already set the type for this DIE. */
15734 type
= get_die_type (die
, cu
);
15738 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
15742 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
15745 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
15746 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
15750 complaint (_("unable to read array DW_AT_byte_stride "
15751 " - DIE at %s [in module %s]"),
15752 sect_offset_str (die
->sect_off
),
15753 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15754 /* Ignore this attribute. We will likely not be able to print
15755 arrays of this type correctly, but there is little we can do
15756 to help if we cannot read the attribute's value. */
15757 byte_stride_prop
= NULL
;
15761 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
15763 bit_stride
= DW_UNSND (attr
);
15765 /* Irix 6.2 native cc creates array types without children for
15766 arrays with unspecified length. */
15767 if (die
->child
== NULL
)
15769 index_type
= objfile_type (objfile
)->builtin_int
;
15770 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
15771 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
15772 byte_stride_prop
, bit_stride
);
15773 return set_die_type (die
, type
, cu
);
15776 std::vector
<struct type
*> range_types
;
15777 child_die
= die
->child
;
15778 while (child_die
&& child_die
->tag
)
15780 if (child_die
->tag
== DW_TAG_subrange_type
)
15782 struct type
*child_type
= read_type_die (child_die
, cu
);
15784 if (child_type
!= NULL
)
15786 /* The range type was succesfully read. Save it for the
15787 array type creation. */
15788 range_types
.push_back (child_type
);
15791 child_die
= child_die
->sibling
;
15794 /* Dwarf2 dimensions are output from left to right, create the
15795 necessary array types in backwards order. */
15797 type
= element_type
;
15799 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
15803 while (i
< range_types
.size ())
15804 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
15805 byte_stride_prop
, bit_stride
);
15809 size_t ndim
= range_types
.size ();
15811 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
15812 byte_stride_prop
, bit_stride
);
15815 /* Understand Dwarf2 support for vector types (like they occur on
15816 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
15817 array type. This is not part of the Dwarf2/3 standard yet, but a
15818 custom vendor extension. The main difference between a regular
15819 array and the vector variant is that vectors are passed by value
15821 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
15822 if (attr
!= nullptr)
15823 make_vector_type (type
);
15825 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
15826 implementation may choose to implement triple vectors using this
15828 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15829 if (attr
!= nullptr)
15831 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
15832 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15834 complaint (_("DW_AT_byte_size for array type smaller "
15835 "than the total size of elements"));
15838 name
= dwarf2_name (die
, cu
);
15840 TYPE_NAME (type
) = name
;
15842 maybe_set_alignment (cu
, die
, type
);
15844 /* Install the type in the die. */
15845 set_die_type (die
, type
, cu
);
15847 /* set_die_type should be already done. */
15848 set_descriptive_type (type
, die
, cu
);
15853 static enum dwarf_array_dim_ordering
15854 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
15856 struct attribute
*attr
;
15858 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
15860 if (attr
!= nullptr)
15861 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
15863 /* GNU F77 is a special case, as at 08/2004 array type info is the
15864 opposite order to the dwarf2 specification, but data is still
15865 laid out as per normal fortran.
15867 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
15868 version checking. */
15870 if (cu
->language
== language_fortran
15871 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
15873 return DW_ORD_row_major
;
15876 switch (cu
->language_defn
->la_array_ordering
)
15878 case array_column_major
:
15879 return DW_ORD_col_major
;
15880 case array_row_major
:
15882 return DW_ORD_row_major
;
15886 /* Extract all information from a DW_TAG_set_type DIE and put it in
15887 the DIE's type field. */
15889 static struct type
*
15890 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15892 struct type
*domain_type
, *set_type
;
15893 struct attribute
*attr
;
15895 domain_type
= die_type (die
, cu
);
15897 /* The die_type call above may have already set the type for this DIE. */
15898 set_type
= get_die_type (die
, cu
);
15902 set_type
= create_set_type (NULL
, domain_type
);
15904 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15905 if (attr
!= nullptr)
15906 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
15908 maybe_set_alignment (cu
, die
, set_type
);
15910 return set_die_type (die
, set_type
, cu
);
15913 /* A helper for read_common_block that creates a locexpr baton.
15914 SYM is the symbol which we are marking as computed.
15915 COMMON_DIE is the DIE for the common block.
15916 COMMON_LOC is the location expression attribute for the common
15918 MEMBER_LOC is the location expression attribute for the particular
15919 member of the common block that we are processing.
15920 CU is the CU from which the above come. */
15923 mark_common_block_symbol_computed (struct symbol
*sym
,
15924 struct die_info
*common_die
,
15925 struct attribute
*common_loc
,
15926 struct attribute
*member_loc
,
15927 struct dwarf2_cu
*cu
)
15929 struct dwarf2_per_objfile
*dwarf2_per_objfile
15930 = cu
->per_cu
->dwarf2_per_objfile
;
15931 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
15932 struct dwarf2_locexpr_baton
*baton
;
15934 unsigned int cu_off
;
15935 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
15936 LONGEST offset
= 0;
15938 gdb_assert (common_loc
&& member_loc
);
15939 gdb_assert (common_loc
->form_is_block ());
15940 gdb_assert (member_loc
->form_is_block ()
15941 || member_loc
->form_is_constant ());
15943 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
15944 baton
->per_cu
= cu
->per_cu
;
15945 gdb_assert (baton
->per_cu
);
15947 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
15949 if (member_loc
->form_is_constant ())
15951 offset
= member_loc
->constant_value (0);
15952 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
15955 baton
->size
+= DW_BLOCK (member_loc
)->size
;
15957 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
15960 *ptr
++ = DW_OP_call4
;
15961 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
15962 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
15965 if (member_loc
->form_is_constant ())
15967 *ptr
++ = DW_OP_addr
;
15968 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
15969 ptr
+= cu
->header
.addr_size
;
15973 /* We have to copy the data here, because DW_OP_call4 will only
15974 use a DW_AT_location attribute. */
15975 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
15976 ptr
+= DW_BLOCK (member_loc
)->size
;
15979 *ptr
++ = DW_OP_plus
;
15980 gdb_assert (ptr
- baton
->data
== baton
->size
);
15982 SYMBOL_LOCATION_BATON (sym
) = baton
;
15983 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
15986 /* Create appropriate locally-scoped variables for all the
15987 DW_TAG_common_block entries. Also create a struct common_block
15988 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
15989 is used to separate the common blocks name namespace from regular
15993 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
15995 struct attribute
*attr
;
15997 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
15998 if (attr
!= nullptr)
16000 /* Support the .debug_loc offsets. */
16001 if (attr
->form_is_block ())
16005 else if (attr
->form_is_section_offset ())
16007 dwarf2_complex_location_expr_complaint ();
16012 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16013 "common block member");
16018 if (die
->child
!= NULL
)
16020 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16021 struct die_info
*child_die
;
16022 size_t n_entries
= 0, size
;
16023 struct common_block
*common_block
;
16024 struct symbol
*sym
;
16026 for (child_die
= die
->child
;
16027 child_die
&& child_die
->tag
;
16028 child_die
= child_die
->sibling
)
16031 size
= (sizeof (struct common_block
)
16032 + (n_entries
- 1) * sizeof (struct symbol
*));
16034 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16036 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16037 common_block
->n_entries
= 0;
16039 for (child_die
= die
->child
;
16040 child_die
&& child_die
->tag
;
16041 child_die
= child_die
->sibling
)
16043 /* Create the symbol in the DW_TAG_common_block block in the current
16045 sym
= new_symbol (child_die
, NULL
, cu
);
16048 struct attribute
*member_loc
;
16050 common_block
->contents
[common_block
->n_entries
++] = sym
;
16052 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16056 /* GDB has handled this for a long time, but it is
16057 not specified by DWARF. It seems to have been
16058 emitted by gfortran at least as recently as:
16059 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16060 complaint (_("Variable in common block has "
16061 "DW_AT_data_member_location "
16062 "- DIE at %s [in module %s]"),
16063 sect_offset_str (child_die
->sect_off
),
16064 objfile_name (objfile
));
16066 if (member_loc
->form_is_section_offset ())
16067 dwarf2_complex_location_expr_complaint ();
16068 else if (member_loc
->form_is_constant ()
16069 || member_loc
->form_is_block ())
16071 if (attr
!= nullptr)
16072 mark_common_block_symbol_computed (sym
, die
, attr
,
16076 dwarf2_complex_location_expr_complaint ();
16081 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16082 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16086 /* Create a type for a C++ namespace. */
16088 static struct type
*
16089 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16091 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16092 const char *previous_prefix
, *name
;
16096 /* For extensions, reuse the type of the original namespace. */
16097 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16099 struct die_info
*ext_die
;
16100 struct dwarf2_cu
*ext_cu
= cu
;
16102 ext_die
= dwarf2_extension (die
, &ext_cu
);
16103 type
= read_type_die (ext_die
, ext_cu
);
16105 /* EXT_CU may not be the same as CU.
16106 Ensure TYPE is recorded with CU in die_type_hash. */
16107 return set_die_type (die
, type
, cu
);
16110 name
= namespace_name (die
, &is_anonymous
, cu
);
16112 /* Now build the name of the current namespace. */
16114 previous_prefix
= determine_prefix (die
, cu
);
16115 if (previous_prefix
[0] != '\0')
16116 name
= typename_concat (&objfile
->objfile_obstack
,
16117 previous_prefix
, name
, 0, cu
);
16119 /* Create the type. */
16120 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16122 return set_die_type (die
, type
, cu
);
16125 /* Read a namespace scope. */
16128 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16130 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16133 /* Add a symbol associated to this if we haven't seen the namespace
16134 before. Also, add a using directive if it's an anonymous
16137 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16141 type
= read_type_die (die
, cu
);
16142 new_symbol (die
, type
, cu
);
16144 namespace_name (die
, &is_anonymous
, cu
);
16147 const char *previous_prefix
= determine_prefix (die
, cu
);
16149 std::vector
<const char *> excludes
;
16150 add_using_directive (using_directives (cu
),
16151 previous_prefix
, TYPE_NAME (type
), NULL
,
16152 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16156 if (die
->child
!= NULL
)
16158 struct die_info
*child_die
= die
->child
;
16160 while (child_die
&& child_die
->tag
)
16162 process_die (child_die
, cu
);
16163 child_die
= child_die
->sibling
;
16168 /* Read a Fortran module as type. This DIE can be only a declaration used for
16169 imported module. Still we need that type as local Fortran "use ... only"
16170 declaration imports depend on the created type in determine_prefix. */
16172 static struct type
*
16173 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16175 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16176 const char *module_name
;
16179 module_name
= dwarf2_name (die
, cu
);
16180 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16182 return set_die_type (die
, type
, cu
);
16185 /* Read a Fortran module. */
16188 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16190 struct die_info
*child_die
= die
->child
;
16193 type
= read_type_die (die
, cu
);
16194 new_symbol (die
, type
, cu
);
16196 while (child_die
&& child_die
->tag
)
16198 process_die (child_die
, cu
);
16199 child_die
= child_die
->sibling
;
16203 /* Return the name of the namespace represented by DIE. Set
16204 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16207 static const char *
16208 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16210 struct die_info
*current_die
;
16211 const char *name
= NULL
;
16213 /* Loop through the extensions until we find a name. */
16215 for (current_die
= die
;
16216 current_die
!= NULL
;
16217 current_die
= dwarf2_extension (die
, &cu
))
16219 /* We don't use dwarf2_name here so that we can detect the absence
16220 of a name -> anonymous namespace. */
16221 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16227 /* Is it an anonymous namespace? */
16229 *is_anonymous
= (name
== NULL
);
16231 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16236 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16237 the user defined type vector. */
16239 static struct type
*
16240 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16242 struct gdbarch
*gdbarch
16243 = get_objfile_arch (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16244 struct comp_unit_head
*cu_header
= &cu
->header
;
16246 struct attribute
*attr_byte_size
;
16247 struct attribute
*attr_address_class
;
16248 int byte_size
, addr_class
;
16249 struct type
*target_type
;
16251 target_type
= die_type (die
, cu
);
16253 /* The die_type call above may have already set the type for this DIE. */
16254 type
= get_die_type (die
, cu
);
16258 type
= lookup_pointer_type (target_type
);
16260 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16261 if (attr_byte_size
)
16262 byte_size
= DW_UNSND (attr_byte_size
);
16264 byte_size
= cu_header
->addr_size
;
16266 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
16267 if (attr_address_class
)
16268 addr_class
= DW_UNSND (attr_address_class
);
16270 addr_class
= DW_ADDR_none
;
16272 ULONGEST alignment
= get_alignment (cu
, die
);
16274 /* If the pointer size, alignment, or address class is different
16275 than the default, create a type variant marked as such and set
16276 the length accordingly. */
16277 if (TYPE_LENGTH (type
) != byte_size
16278 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
16279 && alignment
!= TYPE_RAW_ALIGN (type
))
16280 || addr_class
!= DW_ADDR_none
)
16282 if (gdbarch_address_class_type_flags_p (gdbarch
))
16286 type_flags
= gdbarch_address_class_type_flags
16287 (gdbarch
, byte_size
, addr_class
);
16288 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
16290 type
= make_type_with_address_space (type
, type_flags
);
16292 else if (TYPE_LENGTH (type
) != byte_size
)
16294 complaint (_("invalid pointer size %d"), byte_size
);
16296 else if (TYPE_RAW_ALIGN (type
) != alignment
)
16298 complaint (_("Invalid DW_AT_alignment"
16299 " - DIE at %s [in module %s]"),
16300 sect_offset_str (die
->sect_off
),
16301 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16305 /* Should we also complain about unhandled address classes? */
16309 TYPE_LENGTH (type
) = byte_size
;
16310 set_type_align (type
, alignment
);
16311 return set_die_type (die
, type
, cu
);
16314 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
16315 the user defined type vector. */
16317 static struct type
*
16318 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16321 struct type
*to_type
;
16322 struct type
*domain
;
16324 to_type
= die_type (die
, cu
);
16325 domain
= die_containing_type (die
, cu
);
16327 /* The calls above may have already set the type for this DIE. */
16328 type
= get_die_type (die
, cu
);
16332 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
16333 type
= lookup_methodptr_type (to_type
);
16334 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
16336 struct type
*new_type
16337 = alloc_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16339 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
16340 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
16341 TYPE_VARARGS (to_type
));
16342 type
= lookup_methodptr_type (new_type
);
16345 type
= lookup_memberptr_type (to_type
, domain
);
16347 return set_die_type (die
, type
, cu
);
16350 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
16351 the user defined type vector. */
16353 static struct type
*
16354 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16355 enum type_code refcode
)
16357 struct comp_unit_head
*cu_header
= &cu
->header
;
16358 struct type
*type
, *target_type
;
16359 struct attribute
*attr
;
16361 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
16363 target_type
= die_type (die
, cu
);
16365 /* The die_type call above may have already set the type for this DIE. */
16366 type
= get_die_type (die
, cu
);
16370 type
= lookup_reference_type (target_type
, refcode
);
16371 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16372 if (attr
!= nullptr)
16374 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16378 TYPE_LENGTH (type
) = cu_header
->addr_size
;
16380 maybe_set_alignment (cu
, die
, type
);
16381 return set_die_type (die
, type
, cu
);
16384 /* Add the given cv-qualifiers to the element type of the array. GCC
16385 outputs DWARF type qualifiers that apply to an array, not the
16386 element type. But GDB relies on the array element type to carry
16387 the cv-qualifiers. This mimics section 6.7.3 of the C99
16390 static struct type
*
16391 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16392 struct type
*base_type
, int cnst
, int voltl
)
16394 struct type
*el_type
, *inner_array
;
16396 base_type
= copy_type (base_type
);
16397 inner_array
= base_type
;
16399 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
16401 TYPE_TARGET_TYPE (inner_array
) =
16402 copy_type (TYPE_TARGET_TYPE (inner_array
));
16403 inner_array
= TYPE_TARGET_TYPE (inner_array
);
16406 el_type
= TYPE_TARGET_TYPE (inner_array
);
16407 cnst
|= TYPE_CONST (el_type
);
16408 voltl
|= TYPE_VOLATILE (el_type
);
16409 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
16411 return set_die_type (die
, base_type
, cu
);
16414 static struct type
*
16415 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16417 struct type
*base_type
, *cv_type
;
16419 base_type
= die_type (die
, cu
);
16421 /* The die_type call above may have already set the type for this DIE. */
16422 cv_type
= get_die_type (die
, cu
);
16426 /* In case the const qualifier is applied to an array type, the element type
16427 is so qualified, not the array type (section 6.7.3 of C99). */
16428 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
16429 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
16431 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
16432 return set_die_type (die
, cv_type
, cu
);
16435 static struct type
*
16436 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16438 struct type
*base_type
, *cv_type
;
16440 base_type
= die_type (die
, cu
);
16442 /* The die_type call above may have already set the type for this DIE. */
16443 cv_type
= get_die_type (die
, cu
);
16447 /* In case the volatile qualifier is applied to an array type, the
16448 element type is so qualified, not the array type (section 6.7.3
16450 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
16451 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
16453 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
16454 return set_die_type (die
, cv_type
, cu
);
16457 /* Handle DW_TAG_restrict_type. */
16459 static struct type
*
16460 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16462 struct type
*base_type
, *cv_type
;
16464 base_type
= die_type (die
, cu
);
16466 /* The die_type call above may have already set the type for this DIE. */
16467 cv_type
= get_die_type (die
, cu
);
16471 cv_type
= make_restrict_type (base_type
);
16472 return set_die_type (die
, cv_type
, cu
);
16475 /* Handle DW_TAG_atomic_type. */
16477 static struct type
*
16478 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16480 struct type
*base_type
, *cv_type
;
16482 base_type
= die_type (die
, cu
);
16484 /* The die_type call above may have already set the type for this DIE. */
16485 cv_type
= get_die_type (die
, cu
);
16489 cv_type
= make_atomic_type (base_type
);
16490 return set_die_type (die
, cv_type
, cu
);
16493 /* Extract all information from a DW_TAG_string_type DIE and add to
16494 the user defined type vector. It isn't really a user defined type,
16495 but it behaves like one, with other DIE's using an AT_user_def_type
16496 attribute to reference it. */
16498 static struct type
*
16499 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16501 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16502 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16503 struct type
*type
, *range_type
, *index_type
, *char_type
;
16504 struct attribute
*attr
;
16505 struct dynamic_prop prop
;
16506 bool length_is_constant
= true;
16509 /* There are a couple of places where bit sizes might be made use of
16510 when parsing a DW_TAG_string_type, however, no producer that we know
16511 of make use of these. Handling bit sizes that are a multiple of the
16512 byte size is easy enough, but what about other bit sizes? Lets deal
16513 with that problem when we have to. Warn about these attributes being
16514 unsupported, then parse the type and ignore them like we always
16516 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
16517 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
16519 static bool warning_printed
= false;
16520 if (!warning_printed
)
16522 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
16523 "currently supported on DW_TAG_string_type."));
16524 warning_printed
= true;
16528 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
16529 if (attr
!= nullptr && !attr
->form_is_constant ())
16531 /* The string length describes the location at which the length of
16532 the string can be found. The size of the length field can be
16533 specified with one of the attributes below. */
16534 struct type
*prop_type
;
16535 struct attribute
*len
16536 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
16537 if (len
== nullptr)
16538 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16539 if (len
!= nullptr && len
->form_is_constant ())
16541 /* Pass 0 as the default as we know this attribute is constant
16542 and the default value will not be returned. */
16543 LONGEST sz
= len
->constant_value (0);
16544 prop_type
= cu
->per_cu
->int_type (sz
, true);
16548 /* If the size is not specified then we assume it is the size of
16549 an address on this target. */
16550 prop_type
= cu
->per_cu
->addr_sized_int_type (true);
16553 /* Convert the attribute into a dynamic property. */
16554 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
16557 length_is_constant
= false;
16559 else if (attr
!= nullptr)
16561 /* This DW_AT_string_length just contains the length with no
16562 indirection. There's no need to create a dynamic property in this
16563 case. Pass 0 for the default value as we know it will not be
16564 returned in this case. */
16565 length
= attr
->constant_value (0);
16567 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
16569 /* We don't currently support non-constant byte sizes for strings. */
16570 length
= attr
->constant_value (1);
16574 /* Use 1 as a fallback length if we have nothing else. */
16578 index_type
= objfile_type (objfile
)->builtin_int
;
16579 if (length_is_constant
)
16580 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
16583 struct dynamic_prop low_bound
;
16585 low_bound
.kind
= PROP_CONST
;
16586 low_bound
.data
.const_val
= 1;
16587 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
16589 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
16590 type
= create_string_type (NULL
, char_type
, range_type
);
16592 return set_die_type (die
, type
, cu
);
16595 /* Assuming that DIE corresponds to a function, returns nonzero
16596 if the function is prototyped. */
16599 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
16601 struct attribute
*attr
;
16603 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
16604 if (attr
&& (DW_UNSND (attr
) != 0))
16607 /* The DWARF standard implies that the DW_AT_prototyped attribute
16608 is only meaningful for C, but the concept also extends to other
16609 languages that allow unprototyped functions (Eg: Objective C).
16610 For all other languages, assume that functions are always
16612 if (cu
->language
!= language_c
16613 && cu
->language
!= language_objc
16614 && cu
->language
!= language_opencl
)
16617 /* RealView does not emit DW_AT_prototyped. We can not distinguish
16618 prototyped and unprototyped functions; default to prototyped,
16619 since that is more common in modern code (and RealView warns
16620 about unprototyped functions). */
16621 if (producer_is_realview (cu
->producer
))
16627 /* Handle DIES due to C code like:
16631 int (*funcp)(int a, long l);
16635 ('funcp' generates a DW_TAG_subroutine_type DIE). */
16637 static struct type
*
16638 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16640 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16641 struct type
*type
; /* Type that this function returns. */
16642 struct type
*ftype
; /* Function that returns above type. */
16643 struct attribute
*attr
;
16645 type
= die_type (die
, cu
);
16647 /* The die_type call above may have already set the type for this DIE. */
16648 ftype
= get_die_type (die
, cu
);
16652 ftype
= lookup_function_type (type
);
16654 if (prototyped_function_p (die
, cu
))
16655 TYPE_PROTOTYPED (ftype
) = 1;
16657 /* Store the calling convention in the type if it's available in
16658 the subroutine die. Otherwise set the calling convention to
16659 the default value DW_CC_normal. */
16660 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
16661 if (attr
!= nullptr
16662 && is_valid_DW_AT_calling_convention_for_subroutine (DW_UNSND (attr
)))
16663 TYPE_CALLING_CONVENTION (ftype
)
16664 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
16665 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
16666 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
16668 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
16670 /* Record whether the function returns normally to its caller or not
16671 if the DWARF producer set that information. */
16672 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
16673 if (attr
&& (DW_UNSND (attr
) != 0))
16674 TYPE_NO_RETURN (ftype
) = 1;
16676 /* We need to add the subroutine type to the die immediately so
16677 we don't infinitely recurse when dealing with parameters
16678 declared as the same subroutine type. */
16679 set_die_type (die
, ftype
, cu
);
16681 if (die
->child
!= NULL
)
16683 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
16684 struct die_info
*child_die
;
16685 int nparams
, iparams
;
16687 /* Count the number of parameters.
16688 FIXME: GDB currently ignores vararg functions, but knows about
16689 vararg member functions. */
16691 child_die
= die
->child
;
16692 while (child_die
&& child_die
->tag
)
16694 if (child_die
->tag
== DW_TAG_formal_parameter
)
16696 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
16697 TYPE_VARARGS (ftype
) = 1;
16698 child_die
= child_die
->sibling
;
16701 /* Allocate storage for parameters and fill them in. */
16702 TYPE_NFIELDS (ftype
) = nparams
;
16703 TYPE_FIELDS (ftype
) = (struct field
*)
16704 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
16706 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
16707 even if we error out during the parameters reading below. */
16708 for (iparams
= 0; iparams
< nparams
; iparams
++)
16709 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
16712 child_die
= die
->child
;
16713 while (child_die
&& child_die
->tag
)
16715 if (child_die
->tag
== DW_TAG_formal_parameter
)
16717 struct type
*arg_type
;
16719 /* DWARF version 2 has no clean way to discern C++
16720 static and non-static member functions. G++ helps
16721 GDB by marking the first parameter for non-static
16722 member functions (which is the this pointer) as
16723 artificial. We pass this information to
16724 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
16726 DWARF version 3 added DW_AT_object_pointer, which GCC
16727 4.5 does not yet generate. */
16728 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
16729 if (attr
!= nullptr)
16730 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
16732 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
16733 arg_type
= die_type (child_die
, cu
);
16735 /* RealView does not mark THIS as const, which the testsuite
16736 expects. GCC marks THIS as const in method definitions,
16737 but not in the class specifications (GCC PR 43053). */
16738 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
16739 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
16742 struct dwarf2_cu
*arg_cu
= cu
;
16743 const char *name
= dwarf2_name (child_die
, cu
);
16745 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
16746 if (attr
!= nullptr)
16748 /* If the compiler emits this, use it. */
16749 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
16752 else if (name
&& strcmp (name
, "this") == 0)
16753 /* Function definitions will have the argument names. */
16755 else if (name
== NULL
&& iparams
== 0)
16756 /* Declarations may not have the names, so like
16757 elsewhere in GDB, assume an artificial first
16758 argument is "this". */
16762 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
16766 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
16769 child_die
= child_die
->sibling
;
16776 static struct type
*
16777 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
16779 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16780 const char *name
= NULL
;
16781 struct type
*this_type
, *target_type
;
16783 name
= dwarf2_full_name (NULL
, die
, cu
);
16784 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
16785 TYPE_TARGET_STUB (this_type
) = 1;
16786 set_die_type (die
, this_type
, cu
);
16787 target_type
= die_type (die
, cu
);
16788 if (target_type
!= this_type
)
16789 TYPE_TARGET_TYPE (this_type
) = target_type
;
16792 /* Self-referential typedefs are, it seems, not allowed by the DWARF
16793 spec and cause infinite loops in GDB. */
16794 complaint (_("Self-referential DW_TAG_typedef "
16795 "- DIE at %s [in module %s]"),
16796 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
16797 TYPE_TARGET_TYPE (this_type
) = NULL
;
16801 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
16802 anonymous typedefs, which is, strictly speaking, invalid DWARF.
16803 Handle these by just returning the target type, rather than
16804 constructing an anonymous typedef type and trying to handle this
16806 set_die_type (die
, target_type
, cu
);
16807 return target_type
;
16812 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
16813 (which may be different from NAME) to the architecture back-end to allow
16814 it to guess the correct format if necessary. */
16816 static struct type
*
16817 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
16818 const char *name_hint
, enum bfd_endian byte_order
)
16820 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16821 const struct floatformat
**format
;
16824 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
16826 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
16828 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
16833 /* Allocate an integer type of size BITS and name NAME. */
16835 static struct type
*
16836 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
16837 int bits
, int unsigned_p
, const char *name
)
16841 /* Versions of Intel's C Compiler generate an integer type called "void"
16842 instead of using DW_TAG_unspecified_type. This has been seen on
16843 at least versions 14, 17, and 18. */
16844 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
16845 && strcmp (name
, "void") == 0)
16846 type
= objfile_type (objfile
)->builtin_void
;
16848 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
16853 /* Initialise and return a floating point type of size BITS suitable for
16854 use as a component of a complex number. The NAME_HINT is passed through
16855 when initialising the floating point type and is the name of the complex
16858 As DWARF doesn't currently provide an explicit name for the components
16859 of a complex number, but it can be helpful to have these components
16860 named, we try to select a suitable name based on the size of the
16862 static struct type
*
16863 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
16864 struct objfile
*objfile
,
16865 int bits
, const char *name_hint
,
16866 enum bfd_endian byte_order
)
16868 gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16869 struct type
*tt
= nullptr;
16871 /* Try to find a suitable floating point builtin type of size BITS.
16872 We're going to use the name of this type as the name for the complex
16873 target type that we are about to create. */
16874 switch (cu
->language
)
16876 case language_fortran
:
16880 tt
= builtin_f_type (gdbarch
)->builtin_real
;
16883 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
16885 case 96: /* The x86-32 ABI specifies 96-bit long double. */
16887 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
16895 tt
= builtin_type (gdbarch
)->builtin_float
;
16898 tt
= builtin_type (gdbarch
)->builtin_double
;
16900 case 96: /* The x86-32 ABI specifies 96-bit long double. */
16902 tt
= builtin_type (gdbarch
)->builtin_long_double
;
16908 /* If the type we found doesn't match the size we were looking for, then
16909 pretend we didn't find a type at all, the complex target type we
16910 create will then be nameless. */
16911 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
16914 const char *name
= (tt
== nullptr) ? nullptr : TYPE_NAME (tt
);
16915 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
16918 /* Find a representation of a given base type and install
16919 it in the TYPE field of the die. */
16921 static struct type
*
16922 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16924 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16926 struct attribute
*attr
;
16927 int encoding
= 0, bits
= 0;
16931 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
16932 if (attr
!= nullptr)
16933 encoding
= DW_UNSND (attr
);
16934 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16935 if (attr
!= nullptr)
16936 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
16937 name
= dwarf2_name (die
, cu
);
16939 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
16941 arch
= get_objfile_arch (objfile
);
16942 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
16944 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
16947 int endianity
= DW_UNSND (attr
);
16952 byte_order
= BFD_ENDIAN_BIG
;
16954 case DW_END_little
:
16955 byte_order
= BFD_ENDIAN_LITTLE
;
16958 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
16965 case DW_ATE_address
:
16966 /* Turn DW_ATE_address into a void * pointer. */
16967 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
16968 type
= init_pointer_type (objfile
, bits
, name
, type
);
16970 case DW_ATE_boolean
:
16971 type
= init_boolean_type (objfile
, bits
, 1, name
);
16973 case DW_ATE_complex_float
:
16974 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
16976 if (TYPE_CODE (type
) == TYPE_CODE_ERROR
)
16978 if (name
== nullptr)
16980 struct obstack
*obstack
16981 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
16982 name
= obconcat (obstack
, "_Complex ", TYPE_NAME (type
),
16985 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
16988 type
= init_complex_type (name
, type
);
16990 case DW_ATE_decimal_float
:
16991 type
= init_decfloat_type (objfile
, bits
, name
);
16994 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
16996 case DW_ATE_signed
:
16997 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
16999 case DW_ATE_unsigned
:
17000 if (cu
->language
== language_fortran
17002 && startswith (name
, "character("))
17003 type
= init_character_type (objfile
, bits
, 1, name
);
17005 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17007 case DW_ATE_signed_char
:
17008 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17009 || cu
->language
== language_pascal
17010 || cu
->language
== language_fortran
)
17011 type
= init_character_type (objfile
, bits
, 0, name
);
17013 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17015 case DW_ATE_unsigned_char
:
17016 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17017 || cu
->language
== language_pascal
17018 || cu
->language
== language_fortran
17019 || cu
->language
== language_rust
)
17020 type
= init_character_type (objfile
, bits
, 1, name
);
17022 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17027 type
= builtin_type (arch
)->builtin_char16
;
17028 else if (bits
== 32)
17029 type
= builtin_type (arch
)->builtin_char32
;
17032 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
17034 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17036 return set_die_type (die
, type
, cu
);
17041 complaint (_("unsupported DW_AT_encoding: '%s'"),
17042 dwarf_type_encoding_name (encoding
));
17043 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17047 if (name
&& strcmp (name
, "char") == 0)
17048 TYPE_NOSIGN (type
) = 1;
17050 maybe_set_alignment (cu
, die
, type
);
17052 TYPE_ENDIANITY_NOT_DEFAULT (type
) = gdbarch_byte_order (arch
) != byte_order
;
17054 return set_die_type (die
, type
, cu
);
17057 /* Parse dwarf attribute if it's a block, reference or constant and put the
17058 resulting value of the attribute into struct bound_prop.
17059 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17062 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17063 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
17064 struct type
*default_type
)
17066 struct dwarf2_property_baton
*baton
;
17067 struct obstack
*obstack
17068 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
17070 gdb_assert (default_type
!= NULL
);
17072 if (attr
== NULL
|| prop
== NULL
)
17075 if (attr
->form_is_block ())
17077 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17078 baton
->property_type
= default_type
;
17079 baton
->locexpr
.per_cu
= cu
->per_cu
;
17080 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17081 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17082 switch (attr
->name
)
17084 case DW_AT_string_length
:
17085 baton
->locexpr
.is_reference
= true;
17088 baton
->locexpr
.is_reference
= false;
17091 prop
->data
.baton
= baton
;
17092 prop
->kind
= PROP_LOCEXPR
;
17093 gdb_assert (prop
->data
.baton
!= NULL
);
17095 else if (attr
->form_is_ref ())
17097 struct dwarf2_cu
*target_cu
= cu
;
17098 struct die_info
*target_die
;
17099 struct attribute
*target_attr
;
17101 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17102 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17103 if (target_attr
== NULL
)
17104 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17106 if (target_attr
== NULL
)
17109 switch (target_attr
->name
)
17111 case DW_AT_location
:
17112 if (target_attr
->form_is_section_offset ())
17114 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17115 baton
->property_type
= die_type (target_die
, target_cu
);
17116 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17117 prop
->data
.baton
= baton
;
17118 prop
->kind
= PROP_LOCLIST
;
17119 gdb_assert (prop
->data
.baton
!= NULL
);
17121 else if (target_attr
->form_is_block ())
17123 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17124 baton
->property_type
= die_type (target_die
, target_cu
);
17125 baton
->locexpr
.per_cu
= cu
->per_cu
;
17126 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17127 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17128 baton
->locexpr
.is_reference
= true;
17129 prop
->data
.baton
= baton
;
17130 prop
->kind
= PROP_LOCEXPR
;
17131 gdb_assert (prop
->data
.baton
!= NULL
);
17135 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17136 "dynamic property");
17140 case DW_AT_data_member_location
:
17144 if (!handle_data_member_location (target_die
, target_cu
,
17148 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17149 baton
->property_type
= read_type_die (target_die
->parent
,
17151 baton
->offset_info
.offset
= offset
;
17152 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17153 prop
->data
.baton
= baton
;
17154 prop
->kind
= PROP_ADDR_OFFSET
;
17159 else if (attr
->form_is_constant ())
17161 prop
->data
.const_val
= attr
->constant_value (0);
17162 prop
->kind
= PROP_CONST
;
17166 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17167 dwarf2_name (die
, cu
));
17177 dwarf2_per_cu_data::int_type (int size_in_bytes
, bool unsigned_p
) const
17179 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17180 struct type
*int_type
;
17182 /* Helper macro to examine the various builtin types. */
17183 #define TRY_TYPE(F) \
17184 int_type = (unsigned_p \
17185 ? objfile_type (objfile)->builtin_unsigned_ ## F \
17186 : objfile_type (objfile)->builtin_ ## F); \
17187 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
17194 TRY_TYPE (long_long
);
17198 gdb_assert_not_reached ("unable to find suitable integer type");
17204 dwarf2_per_cu_data::addr_sized_int_type (bool unsigned_p
) const
17206 int addr_size
= this->addr_size ();
17207 return int_type (addr_size
, unsigned_p
);
17210 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
17211 present (which is valid) then compute the default type based on the
17212 compilation units address size. */
17214 static struct type
*
17215 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17217 struct type
*index_type
= die_type (die
, cu
);
17219 /* Dwarf-2 specifications explicitly allows to create subrange types
17220 without specifying a base type.
17221 In that case, the base type must be set to the type of
17222 the lower bound, upper bound or count, in that order, if any of these
17223 three attributes references an object that has a type.
17224 If no base type is found, the Dwarf-2 specifications say that
17225 a signed integer type of size equal to the size of an address should
17227 For the following C code: `extern char gdb_int [];'
17228 GCC produces an empty range DIE.
17229 FIXME: muller/2010-05-28: Possible references to object for low bound,
17230 high bound or count are not yet handled by this code. */
17231 if (TYPE_CODE (index_type
) == TYPE_CODE_VOID
)
17232 index_type
= cu
->per_cu
->addr_sized_int_type (false);
17237 /* Read the given DW_AT_subrange DIE. */
17239 static struct type
*
17240 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17242 struct type
*base_type
, *orig_base_type
;
17243 struct type
*range_type
;
17244 struct attribute
*attr
;
17245 struct dynamic_prop low
, high
;
17246 int low_default_is_valid
;
17247 int high_bound_is_count
= 0;
17249 ULONGEST negative_mask
;
17251 orig_base_type
= read_subrange_index_type (die
, cu
);
17253 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17254 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17255 creating the range type, but we use the result of check_typedef
17256 when examining properties of the type. */
17257 base_type
= check_typedef (orig_base_type
);
17259 /* The die_type call above may have already set the type for this DIE. */
17260 range_type
= get_die_type (die
, cu
);
17264 low
.kind
= PROP_CONST
;
17265 high
.kind
= PROP_CONST
;
17266 high
.data
.const_val
= 0;
17268 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17269 omitting DW_AT_lower_bound. */
17270 switch (cu
->language
)
17273 case language_cplus
:
17274 low
.data
.const_val
= 0;
17275 low_default_is_valid
= 1;
17277 case language_fortran
:
17278 low
.data
.const_val
= 1;
17279 low_default_is_valid
= 1;
17282 case language_objc
:
17283 case language_rust
:
17284 low
.data
.const_val
= 0;
17285 low_default_is_valid
= (cu
->header
.version
>= 4);
17289 case language_pascal
:
17290 low
.data
.const_val
= 1;
17291 low_default_is_valid
= (cu
->header
.version
>= 4);
17294 low
.data
.const_val
= 0;
17295 low_default_is_valid
= 0;
17299 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
17300 if (attr
!= nullptr)
17301 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
17302 else if (!low_default_is_valid
)
17303 complaint (_("Missing DW_AT_lower_bound "
17304 "- DIE at %s [in module %s]"),
17305 sect_offset_str (die
->sect_off
),
17306 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17308 struct attribute
*attr_ub
, *attr_count
;
17309 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
17310 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17312 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
17313 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17315 /* If bounds are constant do the final calculation here. */
17316 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
17317 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
17319 high_bound_is_count
= 1;
17323 if (attr_ub
!= NULL
)
17324 complaint (_("Unresolved DW_AT_upper_bound "
17325 "- DIE at %s [in module %s]"),
17326 sect_offset_str (die
->sect_off
),
17327 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17328 if (attr_count
!= NULL
)
17329 complaint (_("Unresolved DW_AT_count "
17330 "- DIE at %s [in module %s]"),
17331 sect_offset_str (die
->sect_off
),
17332 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17337 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
17338 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
17339 bias
= bias_attr
->constant_value (0);
17341 /* Normally, the DWARF producers are expected to use a signed
17342 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17343 But this is unfortunately not always the case, as witnessed
17344 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17345 is used instead. To work around that ambiguity, we treat
17346 the bounds as signed, and thus sign-extend their values, when
17347 the base type is signed. */
17349 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
17350 if (low
.kind
== PROP_CONST
17351 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
17352 low
.data
.const_val
|= negative_mask
;
17353 if (high
.kind
== PROP_CONST
17354 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
17355 high
.data
.const_val
|= negative_mask
;
17357 /* Check for bit and byte strides. */
17358 struct dynamic_prop byte_stride_prop
;
17359 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
17360 if (attr_byte_stride
!= nullptr)
17362 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
17363 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
17367 struct dynamic_prop bit_stride_prop
;
17368 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
17369 if (attr_bit_stride
!= nullptr)
17371 /* It only makes sense to have either a bit or byte stride. */
17372 if (attr_byte_stride
!= nullptr)
17374 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
17375 "- DIE at %s [in module %s]"),
17376 sect_offset_str (die
->sect_off
),
17377 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17378 attr_bit_stride
= nullptr;
17382 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
17383 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
17388 if (attr_byte_stride
!= nullptr
17389 || attr_bit_stride
!= nullptr)
17391 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
17392 struct dynamic_prop
*stride
17393 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
17396 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
17397 &high
, bias
, stride
, byte_stride_p
);
17400 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
17402 if (high_bound_is_count
)
17403 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
17405 /* Ada expects an empty array on no boundary attributes. */
17406 if (attr
== NULL
&& cu
->language
!= language_ada
)
17407 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
17409 name
= dwarf2_name (die
, cu
);
17411 TYPE_NAME (range_type
) = name
;
17413 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17414 if (attr
!= nullptr)
17415 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
17417 maybe_set_alignment (cu
, die
, range_type
);
17419 set_die_type (die
, range_type
, cu
);
17421 /* set_die_type should be already done. */
17422 set_descriptive_type (range_type
, die
, cu
);
17427 static struct type
*
17428 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17432 type
= init_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
, TYPE_CODE_VOID
,0,
17434 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
17436 /* In Ada, an unspecified type is typically used when the description
17437 of the type is deferred to a different unit. When encountering
17438 such a type, we treat it as a stub, and try to resolve it later on,
17440 if (cu
->language
== language_ada
)
17441 TYPE_STUB (type
) = 1;
17443 return set_die_type (die
, type
, cu
);
17446 /* Read a single die and all its descendents. Set the die's sibling
17447 field to NULL; set other fields in the die correctly, and set all
17448 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
17449 location of the info_ptr after reading all of those dies. PARENT
17450 is the parent of the die in question. */
17452 static struct die_info
*
17453 read_die_and_children (const struct die_reader_specs
*reader
,
17454 const gdb_byte
*info_ptr
,
17455 const gdb_byte
**new_info_ptr
,
17456 struct die_info
*parent
)
17458 struct die_info
*die
;
17459 const gdb_byte
*cur_ptr
;
17461 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
17464 *new_info_ptr
= cur_ptr
;
17467 store_in_ref_table (die
, reader
->cu
);
17469 if (die
->has_children
)
17470 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
17474 *new_info_ptr
= cur_ptr
;
17477 die
->sibling
= NULL
;
17478 die
->parent
= parent
;
17482 /* Read a die, all of its descendents, and all of its siblings; set
17483 all of the fields of all of the dies correctly. Arguments are as
17484 in read_die_and_children. */
17486 static struct die_info
*
17487 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
17488 const gdb_byte
*info_ptr
,
17489 const gdb_byte
**new_info_ptr
,
17490 struct die_info
*parent
)
17492 struct die_info
*first_die
, *last_sibling
;
17493 const gdb_byte
*cur_ptr
;
17495 cur_ptr
= info_ptr
;
17496 first_die
= last_sibling
= NULL
;
17500 struct die_info
*die
17501 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
17505 *new_info_ptr
= cur_ptr
;
17512 last_sibling
->sibling
= die
;
17514 last_sibling
= die
;
17518 /* Read a die, all of its descendents, and all of its siblings; set
17519 all of the fields of all of the dies correctly. Arguments are as
17520 in read_die_and_children.
17521 This the main entry point for reading a DIE and all its children. */
17523 static struct die_info
*
17524 read_die_and_siblings (const struct die_reader_specs
*reader
,
17525 const gdb_byte
*info_ptr
,
17526 const gdb_byte
**new_info_ptr
,
17527 struct die_info
*parent
)
17529 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
17530 new_info_ptr
, parent
);
17532 if (dwarf_die_debug
)
17534 fprintf_unfiltered (gdb_stdlog
,
17535 "Read die from %s@0x%x of %s:\n",
17536 reader
->die_section
->get_name (),
17537 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17538 bfd_get_filename (reader
->abfd
));
17539 dump_die (die
, dwarf_die_debug
);
17545 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
17547 The caller is responsible for filling in the extra attributes
17548 and updating (*DIEP)->num_attrs.
17549 Set DIEP to point to a newly allocated die with its information,
17550 except for its child, sibling, and parent fields. */
17552 static const gdb_byte
*
17553 read_full_die_1 (const struct die_reader_specs
*reader
,
17554 struct die_info
**diep
, const gdb_byte
*info_ptr
,
17555 int num_extra_attrs
)
17557 unsigned int abbrev_number
, bytes_read
, i
;
17558 struct abbrev_info
*abbrev
;
17559 struct die_info
*die
;
17560 struct dwarf2_cu
*cu
= reader
->cu
;
17561 bfd
*abfd
= reader
->abfd
;
17563 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
17564 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
17565 info_ptr
+= bytes_read
;
17566 if (!abbrev_number
)
17572 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
17574 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
17576 bfd_get_filename (abfd
));
17578 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
17579 die
->sect_off
= sect_off
;
17580 die
->tag
= abbrev
->tag
;
17581 die
->abbrev
= abbrev_number
;
17582 die
->has_children
= abbrev
->has_children
;
17584 /* Make the result usable.
17585 The caller needs to update num_attrs after adding the extra
17587 die
->num_attrs
= abbrev
->num_attrs
;
17589 std::vector
<int> indexes_that_need_reprocess
;
17590 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
17592 bool need_reprocess
;
17594 read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
17595 info_ptr
, &need_reprocess
);
17596 if (need_reprocess
)
17597 indexes_that_need_reprocess
.push_back (i
);
17600 struct attribute
*attr
= die
->attr (DW_AT_str_offsets_base
);
17601 if (attr
!= nullptr)
17602 cu
->str_offsets_base
= DW_UNSND (attr
);
17604 attr
= die
->attr (DW_AT_loclists_base
);
17605 if (attr
!= nullptr)
17606 cu
->loclist_base
= DW_UNSND (attr
);
17608 auto maybe_addr_base
= die
->addr_base ();
17609 if (maybe_addr_base
.has_value ())
17610 cu
->addr_base
= *maybe_addr_base
;
17611 for (int index
: indexes_that_need_reprocess
)
17612 read_attribute_reprocess (reader
, &die
->attrs
[index
]);
17617 /* Read a die and all its attributes.
17618 Set DIEP to point to a newly allocated die with its information,
17619 except for its child, sibling, and parent fields. */
17621 static const gdb_byte
*
17622 read_full_die (const struct die_reader_specs
*reader
,
17623 struct die_info
**diep
, const gdb_byte
*info_ptr
)
17625 const gdb_byte
*result
;
17627 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
17629 if (dwarf_die_debug
)
17631 fprintf_unfiltered (gdb_stdlog
,
17632 "Read die from %s@0x%x of %s:\n",
17633 reader
->die_section
->get_name (),
17634 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17635 bfd_get_filename (reader
->abfd
));
17636 dump_die (*diep
, dwarf_die_debug
);
17643 /* Returns nonzero if TAG represents a type that we might generate a partial
17647 is_type_tag_for_partial (int tag
)
17652 /* Some types that would be reasonable to generate partial symbols for,
17653 that we don't at present. */
17654 case DW_TAG_array_type
:
17655 case DW_TAG_file_type
:
17656 case DW_TAG_ptr_to_member_type
:
17657 case DW_TAG_set_type
:
17658 case DW_TAG_string_type
:
17659 case DW_TAG_subroutine_type
:
17661 case DW_TAG_base_type
:
17662 case DW_TAG_class_type
:
17663 case DW_TAG_interface_type
:
17664 case DW_TAG_enumeration_type
:
17665 case DW_TAG_structure_type
:
17666 case DW_TAG_subrange_type
:
17667 case DW_TAG_typedef
:
17668 case DW_TAG_union_type
:
17675 /* Load all DIEs that are interesting for partial symbols into memory. */
17677 static struct partial_die_info
*
17678 load_partial_dies (const struct die_reader_specs
*reader
,
17679 const gdb_byte
*info_ptr
, int building_psymtab
)
17681 struct dwarf2_cu
*cu
= reader
->cu
;
17682 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17683 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
17684 unsigned int bytes_read
;
17685 unsigned int load_all
= 0;
17686 int nesting_level
= 1;
17691 gdb_assert (cu
->per_cu
!= NULL
);
17692 if (cu
->per_cu
->load_all_dies
)
17696 = htab_create_alloc_ex (cu
->header
.length
/ 12,
17700 &cu
->comp_unit_obstack
,
17701 hashtab_obstack_allocate
,
17702 dummy_obstack_deallocate
);
17706 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
17708 /* A NULL abbrev means the end of a series of children. */
17709 if (abbrev
== NULL
)
17711 if (--nesting_level
== 0)
17714 info_ptr
+= bytes_read
;
17715 last_die
= parent_die
;
17716 parent_die
= parent_die
->die_parent
;
17720 /* Check for template arguments. We never save these; if
17721 they're seen, we just mark the parent, and go on our way. */
17722 if (parent_die
!= NULL
17723 && cu
->language
== language_cplus
17724 && (abbrev
->tag
== DW_TAG_template_type_param
17725 || abbrev
->tag
== DW_TAG_template_value_param
))
17727 parent_die
->has_template_arguments
= 1;
17731 /* We don't need a partial DIE for the template argument. */
17732 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17737 /* We only recurse into c++ subprograms looking for template arguments.
17738 Skip their other children. */
17740 && cu
->language
== language_cplus
17741 && parent_die
!= NULL
17742 && parent_die
->tag
== DW_TAG_subprogram
)
17744 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17748 /* Check whether this DIE is interesting enough to save. Normally
17749 we would not be interested in members here, but there may be
17750 later variables referencing them via DW_AT_specification (for
17751 static members). */
17753 && !is_type_tag_for_partial (abbrev
->tag
)
17754 && abbrev
->tag
!= DW_TAG_constant
17755 && abbrev
->tag
!= DW_TAG_enumerator
17756 && abbrev
->tag
!= DW_TAG_subprogram
17757 && abbrev
->tag
!= DW_TAG_inlined_subroutine
17758 && abbrev
->tag
!= DW_TAG_lexical_block
17759 && abbrev
->tag
!= DW_TAG_variable
17760 && abbrev
->tag
!= DW_TAG_namespace
17761 && abbrev
->tag
!= DW_TAG_module
17762 && abbrev
->tag
!= DW_TAG_member
17763 && abbrev
->tag
!= DW_TAG_imported_unit
17764 && abbrev
->tag
!= DW_TAG_imported_declaration
)
17766 /* Otherwise we skip to the next sibling, if any. */
17767 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17771 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
17774 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
17776 /* This two-pass algorithm for processing partial symbols has a
17777 high cost in cache pressure. Thus, handle some simple cases
17778 here which cover the majority of C partial symbols. DIEs
17779 which neither have specification tags in them, nor could have
17780 specification tags elsewhere pointing at them, can simply be
17781 processed and discarded.
17783 This segment is also optional; scan_partial_symbols and
17784 add_partial_symbol will handle these DIEs if we chain
17785 them in normally. When compilers which do not emit large
17786 quantities of duplicate debug information are more common,
17787 this code can probably be removed. */
17789 /* Any complete simple types at the top level (pretty much all
17790 of them, for a language without namespaces), can be processed
17792 if (parent_die
== NULL
17793 && pdi
.has_specification
== 0
17794 && pdi
.is_declaration
== 0
17795 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
17796 || pdi
.tag
== DW_TAG_base_type
17797 || pdi
.tag
== DW_TAG_subrange_type
))
17799 if (building_psymtab
&& pdi
.name
!= NULL
)
17800 add_psymbol_to_list (pdi
.name
, false,
17801 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
17802 psymbol_placement::STATIC
,
17803 0, cu
->language
, objfile
);
17804 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
17808 /* The exception for DW_TAG_typedef with has_children above is
17809 a workaround of GCC PR debug/47510. In the case of this complaint
17810 type_name_or_error will error on such types later.
17812 GDB skipped children of DW_TAG_typedef by the shortcut above and then
17813 it could not find the child DIEs referenced later, this is checked
17814 above. In correct DWARF DW_TAG_typedef should have no children. */
17816 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
17817 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
17818 "- DIE at %s [in module %s]"),
17819 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
17821 /* If we're at the second level, and we're an enumerator, and
17822 our parent has no specification (meaning possibly lives in a
17823 namespace elsewhere), then we can add the partial symbol now
17824 instead of queueing it. */
17825 if (pdi
.tag
== DW_TAG_enumerator
17826 && parent_die
!= NULL
17827 && parent_die
->die_parent
== NULL
17828 && parent_die
->tag
== DW_TAG_enumeration_type
17829 && parent_die
->has_specification
== 0)
17831 if (pdi
.name
== NULL
)
17832 complaint (_("malformed enumerator DIE ignored"));
17833 else if (building_psymtab
)
17834 add_psymbol_to_list (pdi
.name
, false,
17835 VAR_DOMAIN
, LOC_CONST
, -1,
17836 cu
->language
== language_cplus
17837 ? psymbol_placement::GLOBAL
17838 : psymbol_placement::STATIC
,
17839 0, cu
->language
, objfile
);
17841 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
17845 struct partial_die_info
*part_die
17846 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
17848 /* We'll save this DIE so link it in. */
17849 part_die
->die_parent
= parent_die
;
17850 part_die
->die_sibling
= NULL
;
17851 part_die
->die_child
= NULL
;
17853 if (last_die
&& last_die
== parent_die
)
17854 last_die
->die_child
= part_die
;
17856 last_die
->die_sibling
= part_die
;
17858 last_die
= part_die
;
17860 if (first_die
== NULL
)
17861 first_die
= part_die
;
17863 /* Maybe add the DIE to the hash table. Not all DIEs that we
17864 find interesting need to be in the hash table, because we
17865 also have the parent/sibling/child chains; only those that we
17866 might refer to by offset later during partial symbol reading.
17868 For now this means things that might have be the target of a
17869 DW_AT_specification, DW_AT_abstract_origin, or
17870 DW_AT_extension. DW_AT_extension will refer only to
17871 namespaces; DW_AT_abstract_origin refers to functions (and
17872 many things under the function DIE, but we do not recurse
17873 into function DIEs during partial symbol reading) and
17874 possibly variables as well; DW_AT_specification refers to
17875 declarations. Declarations ought to have the DW_AT_declaration
17876 flag. It happens that GCC forgets to put it in sometimes, but
17877 only for functions, not for types.
17879 Adding more things than necessary to the hash table is harmless
17880 except for the performance cost. Adding too few will result in
17881 wasted time in find_partial_die, when we reread the compilation
17882 unit with load_all_dies set. */
17885 || abbrev
->tag
== DW_TAG_constant
17886 || abbrev
->tag
== DW_TAG_subprogram
17887 || abbrev
->tag
== DW_TAG_variable
17888 || abbrev
->tag
== DW_TAG_namespace
17889 || part_die
->is_declaration
)
17893 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
17894 to_underlying (part_die
->sect_off
),
17899 /* For some DIEs we want to follow their children (if any). For C
17900 we have no reason to follow the children of structures; for other
17901 languages we have to, so that we can get at method physnames
17902 to infer fully qualified class names, for DW_AT_specification,
17903 and for C++ template arguments. For C++, we also look one level
17904 inside functions to find template arguments (if the name of the
17905 function does not already contain the template arguments).
17907 For Ada and Fortran, we need to scan the children of subprograms
17908 and lexical blocks as well because these languages allow the
17909 definition of nested entities that could be interesting for the
17910 debugger, such as nested subprograms for instance. */
17911 if (last_die
->has_children
17913 || last_die
->tag
== DW_TAG_namespace
17914 || last_die
->tag
== DW_TAG_module
17915 || last_die
->tag
== DW_TAG_enumeration_type
17916 || (cu
->language
== language_cplus
17917 && last_die
->tag
== DW_TAG_subprogram
17918 && (last_die
->name
== NULL
17919 || strchr (last_die
->name
, '<') == NULL
))
17920 || (cu
->language
!= language_c
17921 && (last_die
->tag
== DW_TAG_class_type
17922 || last_die
->tag
== DW_TAG_interface_type
17923 || last_die
->tag
== DW_TAG_structure_type
17924 || last_die
->tag
== DW_TAG_union_type
))
17925 || ((cu
->language
== language_ada
17926 || cu
->language
== language_fortran
)
17927 && (last_die
->tag
== DW_TAG_subprogram
17928 || last_die
->tag
== DW_TAG_lexical_block
))))
17931 parent_die
= last_die
;
17935 /* Otherwise we skip to the next sibling, if any. */
17936 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
17938 /* Back to the top, do it again. */
17942 partial_die_info::partial_die_info (sect_offset sect_off_
,
17943 struct abbrev_info
*abbrev
)
17944 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
17948 /* Read a minimal amount of information into the minimal die structure.
17949 INFO_PTR should point just after the initial uleb128 of a DIE. */
17952 partial_die_info::read (const struct die_reader_specs
*reader
,
17953 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
17955 struct dwarf2_cu
*cu
= reader
->cu
;
17956 struct dwarf2_per_objfile
*dwarf2_per_objfile
17957 = cu
->per_cu
->dwarf2_per_objfile
;
17959 int has_low_pc_attr
= 0;
17960 int has_high_pc_attr
= 0;
17961 int high_pc_relative
= 0;
17963 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
17966 bool need_reprocess
;
17967 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
],
17968 info_ptr
, &need_reprocess
);
17969 /* String and address offsets that need to do the reprocessing have
17970 already been read at this point, so there is no need to wait until
17971 the loop terminates to do the reprocessing. */
17972 if (need_reprocess
)
17973 read_attribute_reprocess (reader
, &attr
);
17974 /* Store the data if it is of an attribute we want to keep in a
17975 partial symbol table. */
17981 case DW_TAG_compile_unit
:
17982 case DW_TAG_partial_unit
:
17983 case DW_TAG_type_unit
:
17984 /* Compilation units have a DW_AT_name that is a filename, not
17985 a source language identifier. */
17986 case DW_TAG_enumeration_type
:
17987 case DW_TAG_enumerator
:
17988 /* These tags always have simple identifiers already; no need
17989 to canonicalize them. */
17990 name
= DW_STRING (&attr
);
17994 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17997 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
, objfile
);
18002 case DW_AT_linkage_name
:
18003 case DW_AT_MIPS_linkage_name
:
18004 /* Note that both forms of linkage name might appear. We
18005 assume they will be the same, and we only store the last
18007 linkage_name
= DW_STRING (&attr
);
18010 has_low_pc_attr
= 1;
18011 lowpc
= attr
.value_as_address ();
18013 case DW_AT_high_pc
:
18014 has_high_pc_attr
= 1;
18015 highpc
= attr
.value_as_address ();
18016 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
18017 high_pc_relative
= 1;
18019 case DW_AT_location
:
18020 /* Support the .debug_loc offsets. */
18021 if (attr
.form_is_block ())
18023 d
.locdesc
= DW_BLOCK (&attr
);
18025 else if (attr
.form_is_section_offset ())
18027 dwarf2_complex_location_expr_complaint ();
18031 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18032 "partial symbol information");
18035 case DW_AT_external
:
18036 is_external
= DW_UNSND (&attr
);
18038 case DW_AT_declaration
:
18039 is_declaration
= DW_UNSND (&attr
);
18044 case DW_AT_abstract_origin
:
18045 case DW_AT_specification
:
18046 case DW_AT_extension
:
18047 has_specification
= 1;
18048 spec_offset
= attr
.get_ref_die_offset ();
18049 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18050 || cu
->per_cu
->is_dwz
);
18052 case DW_AT_sibling
:
18053 /* Ignore absolute siblings, they might point outside of
18054 the current compile unit. */
18055 if (attr
.form
== DW_FORM_ref_addr
)
18056 complaint (_("ignoring absolute DW_AT_sibling"));
18059 const gdb_byte
*buffer
= reader
->buffer
;
18060 sect_offset off
= attr
.get_ref_die_offset ();
18061 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
18063 if (sibling_ptr
< info_ptr
)
18064 complaint (_("DW_AT_sibling points backwards"));
18065 else if (sibling_ptr
> reader
->buffer_end
)
18066 reader
->die_section
->overflow_complaint ();
18068 sibling
= sibling_ptr
;
18071 case DW_AT_byte_size
:
18074 case DW_AT_const_value
:
18075 has_const_value
= 1;
18077 case DW_AT_calling_convention
:
18078 /* DWARF doesn't provide a way to identify a program's source-level
18079 entry point. DW_AT_calling_convention attributes are only meant
18080 to describe functions' calling conventions.
18082 However, because it's a necessary piece of information in
18083 Fortran, and before DWARF 4 DW_CC_program was the only
18084 piece of debugging information whose definition refers to
18085 a 'main program' at all, several compilers marked Fortran
18086 main programs with DW_CC_program --- even when those
18087 functions use the standard calling conventions.
18089 Although DWARF now specifies a way to provide this
18090 information, we support this practice for backward
18092 if (DW_UNSND (&attr
) == DW_CC_program
18093 && cu
->language
== language_fortran
)
18094 main_subprogram
= 1;
18097 if (DW_UNSND (&attr
) == DW_INL_inlined
18098 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
18099 may_be_inlined
= 1;
18103 if (tag
== DW_TAG_imported_unit
)
18105 d
.sect_off
= attr
.get_ref_die_offset ();
18106 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18107 || cu
->per_cu
->is_dwz
);
18111 case DW_AT_main_subprogram
:
18112 main_subprogram
= DW_UNSND (&attr
);
18117 /* It would be nice to reuse dwarf2_get_pc_bounds here,
18118 but that requires a full DIE, so instead we just
18120 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
18121 unsigned int ranges_offset
= (DW_UNSND (&attr
)
18122 + (need_ranges_base
18126 /* Value of the DW_AT_ranges attribute is the offset in the
18127 .debug_ranges section. */
18128 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
18139 /* For Ada, if both the name and the linkage name appear, we prefer
18140 the latter. This lets "catch exception" work better, regardless
18141 of the order in which the name and linkage name were emitted.
18142 Really, though, this is just a workaround for the fact that gdb
18143 doesn't store both the name and the linkage name. */
18144 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
18145 name
= linkage_name
;
18147 if (high_pc_relative
)
18150 if (has_low_pc_attr
&& has_high_pc_attr
)
18152 /* When using the GNU linker, .gnu.linkonce. sections are used to
18153 eliminate duplicate copies of functions and vtables and such.
18154 The linker will arbitrarily choose one and discard the others.
18155 The AT_*_pc values for such functions refer to local labels in
18156 these sections. If the section from that file was discarded, the
18157 labels are not in the output, so the relocs get a value of 0.
18158 If this is a discarded function, mark the pc bounds as invalid,
18159 so that GDB will ignore it. */
18160 if (lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
18162 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18163 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18165 complaint (_("DW_AT_low_pc %s is zero "
18166 "for DIE at %s [in module %s]"),
18167 paddress (gdbarch
, lowpc
),
18168 sect_offset_str (sect_off
),
18169 objfile_name (objfile
));
18171 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
18172 else if (lowpc
>= highpc
)
18174 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18175 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18177 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
18178 "for DIE at %s [in module %s]"),
18179 paddress (gdbarch
, lowpc
),
18180 paddress (gdbarch
, highpc
),
18181 sect_offset_str (sect_off
),
18182 objfile_name (objfile
));
18191 /* Find a cached partial DIE at OFFSET in CU. */
18193 struct partial_die_info
*
18194 dwarf2_cu::find_partial_die (sect_offset sect_off
)
18196 struct partial_die_info
*lookup_die
= NULL
;
18197 struct partial_die_info
part_die (sect_off
);
18199 lookup_die
= ((struct partial_die_info
*)
18200 htab_find_with_hash (partial_dies
, &part_die
,
18201 to_underlying (sect_off
)));
18206 /* Find a partial DIE at OFFSET, which may or may not be in CU,
18207 except in the case of .debug_types DIEs which do not reference
18208 outside their CU (they do however referencing other types via
18209 DW_FORM_ref_sig8). */
18211 static const struct cu_partial_die_info
18212 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
18214 struct dwarf2_per_objfile
*dwarf2_per_objfile
18215 = cu
->per_cu
->dwarf2_per_objfile
;
18216 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18217 struct dwarf2_per_cu_data
*per_cu
= NULL
;
18218 struct partial_die_info
*pd
= NULL
;
18220 if (offset_in_dwz
== cu
->per_cu
->is_dwz
18221 && cu
->header
.offset_in_cu_p (sect_off
))
18223 pd
= cu
->find_partial_die (sect_off
);
18226 /* We missed recording what we needed.
18227 Load all dies and try again. */
18228 per_cu
= cu
->per_cu
;
18232 /* TUs don't reference other CUs/TUs (except via type signatures). */
18233 if (cu
->per_cu
->is_debug_types
)
18235 error (_("Dwarf Error: Type Unit at offset %s contains"
18236 " external reference to offset %s [in module %s].\n"),
18237 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
18238 bfd_get_filename (objfile
->obfd
));
18240 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
18241 dwarf2_per_objfile
);
18243 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
18244 load_partial_comp_unit (per_cu
);
18246 per_cu
->cu
->last_used
= 0;
18247 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18250 /* If we didn't find it, and not all dies have been loaded,
18251 load them all and try again. */
18253 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
18255 per_cu
->load_all_dies
= 1;
18257 /* This is nasty. When we reread the DIEs, somewhere up the call chain
18258 THIS_CU->cu may already be in use. So we can't just free it and
18259 replace its DIEs with the ones we read in. Instead, we leave those
18260 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
18261 and clobber THIS_CU->cu->partial_dies with the hash table for the new
18263 load_partial_comp_unit (per_cu
);
18265 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18269 internal_error (__FILE__
, __LINE__
,
18270 _("could not find partial DIE %s "
18271 "in cache [from module %s]\n"),
18272 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
18273 return { per_cu
->cu
, pd
};
18276 /* See if we can figure out if the class lives in a namespace. We do
18277 this by looking for a member function; its demangled name will
18278 contain namespace info, if there is any. */
18281 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
18282 struct dwarf2_cu
*cu
)
18284 /* NOTE: carlton/2003-10-07: Getting the info this way changes
18285 what template types look like, because the demangler
18286 frequently doesn't give the same name as the debug info. We
18287 could fix this by only using the demangled name to get the
18288 prefix (but see comment in read_structure_type). */
18290 struct partial_die_info
*real_pdi
;
18291 struct partial_die_info
*child_pdi
;
18293 /* If this DIE (this DIE's specification, if any) has a parent, then
18294 we should not do this. We'll prepend the parent's fully qualified
18295 name when we create the partial symbol. */
18297 real_pdi
= struct_pdi
;
18298 while (real_pdi
->has_specification
)
18300 auto res
= find_partial_die (real_pdi
->spec_offset
,
18301 real_pdi
->spec_is_dwz
, cu
);
18302 real_pdi
= res
.pdi
;
18306 if (real_pdi
->die_parent
!= NULL
)
18309 for (child_pdi
= struct_pdi
->die_child
;
18311 child_pdi
= child_pdi
->die_sibling
)
18313 if (child_pdi
->tag
== DW_TAG_subprogram
18314 && child_pdi
->linkage_name
!= NULL
)
18316 gdb::unique_xmalloc_ptr
<char> actual_class_name
18317 (language_class_name_from_physname (cu
->language_defn
,
18318 child_pdi
->linkage_name
));
18319 if (actual_class_name
!= NULL
)
18321 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18322 struct_pdi
->name
= objfile
->intern (actual_class_name
.get ());
18329 /* Return true if a DIE with TAG may have the DW_AT_const_value
18333 can_have_DW_AT_const_value_p (enum dwarf_tag tag
)
18337 case DW_TAG_constant
:
18338 case DW_TAG_enumerator
:
18339 case DW_TAG_formal_parameter
:
18340 case DW_TAG_template_value_param
:
18341 case DW_TAG_variable
:
18349 partial_die_info::fixup (struct dwarf2_cu
*cu
)
18351 /* Once we've fixed up a die, there's no point in doing so again.
18352 This also avoids a memory leak if we were to call
18353 guess_partial_die_structure_name multiple times. */
18357 /* If we found a reference attribute and the DIE has no name, try
18358 to find a name in the referred to DIE. */
18360 if (name
== NULL
&& has_specification
)
18362 struct partial_die_info
*spec_die
;
18364 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18365 spec_die
= res
.pdi
;
18368 spec_die
->fixup (cu
);
18370 if (spec_die
->name
)
18372 name
= spec_die
->name
;
18374 /* Copy DW_AT_external attribute if it is set. */
18375 if (spec_die
->is_external
)
18376 is_external
= spec_die
->is_external
;
18380 if (!has_const_value
&& has_specification
18381 && can_have_DW_AT_const_value_p (tag
))
18383 struct partial_die_info
*spec_die
;
18385 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18386 spec_die
= res
.pdi
;
18389 spec_die
->fixup (cu
);
18391 if (spec_die
->has_const_value
)
18393 /* Copy DW_AT_const_value attribute if it is set. */
18394 has_const_value
= spec_die
->has_const_value
;
18398 /* Set default names for some unnamed DIEs. */
18400 if (name
== NULL
&& tag
== DW_TAG_namespace
)
18401 name
= CP_ANONYMOUS_NAMESPACE_STR
;
18403 /* If there is no parent die to provide a namespace, and there are
18404 children, see if we can determine the namespace from their linkage
18406 if (cu
->language
== language_cplus
18407 && !cu
->per_cu
->dwarf2_per_objfile
->types
.empty ()
18408 && die_parent
== NULL
18410 && (tag
== DW_TAG_class_type
18411 || tag
== DW_TAG_structure_type
18412 || tag
== DW_TAG_union_type
))
18413 guess_partial_die_structure_name (this, cu
);
18415 /* GCC might emit a nameless struct or union that has a linkage
18416 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
18418 && (tag
== DW_TAG_class_type
18419 || tag
== DW_TAG_interface_type
18420 || tag
== DW_TAG_structure_type
18421 || tag
== DW_TAG_union_type
)
18422 && linkage_name
!= NULL
)
18424 gdb::unique_xmalloc_ptr
<char> demangled
18425 (gdb_demangle (linkage_name
, DMGL_TYPES
));
18426 if (demangled
!= nullptr)
18430 /* Strip any leading namespaces/classes, keep only the base name.
18431 DW_AT_name for named DIEs does not contain the prefixes. */
18432 base
= strrchr (demangled
.get (), ':');
18433 if (base
&& base
> demangled
.get () && base
[-1] == ':')
18436 base
= demangled
.get ();
18438 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18439 name
= objfile
->intern (base
);
18446 /* Read the .debug_loclists header contents from the given SECTION in the
18449 read_loclist_header (struct loclist_header
*header
,
18450 struct dwarf2_section_info
*section
)
18452 unsigned int bytes_read
;
18453 bfd
*abfd
= section
->get_bfd_owner ();
18454 const gdb_byte
*info_ptr
= section
->buffer
;
18455 header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
18456 info_ptr
+= bytes_read
;
18457 header
->version
= read_2_bytes (abfd
, info_ptr
);
18459 header
->addr_size
= read_1_byte (abfd
, info_ptr
);
18461 header
->segment_collector_size
= read_1_byte (abfd
, info_ptr
);
18463 header
->offset_entry_count
= read_4_bytes (abfd
, info_ptr
);
18466 /* Return the DW_AT_loclists_base value for the CU. */
18468 lookup_loclist_base (struct dwarf2_cu
*cu
)
18470 /* For the .dwo unit, the loclist_base points to the first offset following
18471 the header. The header consists of the following entities-
18472 1. Unit Length (4 bytes for 32 bit DWARF format, and 12 bytes for the 64
18474 2. version (2 bytes)
18475 3. address size (1 byte)
18476 4. segment selector size (1 byte)
18477 5. offset entry count (4 bytes)
18478 These sizes are derived as per the DWARFv5 standard. */
18479 if (cu
->dwo_unit
!= nullptr)
18481 if (cu
->header
.initial_length_size
== 4)
18482 return LOCLIST_HEADER_SIZE32
;
18483 return LOCLIST_HEADER_SIZE64
;
18485 return cu
->loclist_base
;
18488 /* Given a DW_FORM_loclistx value LOCLIST_INDEX, fetch the offset from the
18489 array of offsets in the .debug_loclists section. */
18491 read_loclist_index (struct dwarf2_cu
*cu
, ULONGEST loclist_index
)
18493 struct dwarf2_per_objfile
*dwarf2_per_objfile
18494 = cu
->per_cu
->dwarf2_per_objfile
;
18495 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18496 bfd
*abfd
= objfile
->obfd
;
18497 ULONGEST loclist_base
= lookup_loclist_base (cu
);
18498 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
18500 section
->read (objfile
);
18501 if (section
->buffer
== NULL
)
18502 complaint (_("DW_FORM_loclistx used without .debug_loclists "
18503 "section [in module %s]"), objfile_name (objfile
));
18504 struct loclist_header header
;
18505 read_loclist_header (&header
, section
);
18506 if (loclist_index
>= header
.offset_entry_count
)
18507 complaint (_("DW_FORM_loclistx pointing outside of "
18508 ".debug_loclists offset array [in module %s]"),
18509 objfile_name (objfile
));
18510 if (loclist_base
+ loclist_index
* cu
->header
.offset_size
18512 complaint (_("DW_FORM_loclistx pointing outside of "
18513 ".debug_loclists section [in module %s]"),
18514 objfile_name (objfile
));
18515 const gdb_byte
*info_ptr
18516 = section
->buffer
+ loclist_base
+ loclist_index
* cu
->header
.offset_size
;
18518 if (cu
->header
.offset_size
== 4)
18519 return bfd_get_32 (abfd
, info_ptr
) + loclist_base
;
18521 return bfd_get_64 (abfd
, info_ptr
) + loclist_base
;
18524 /* Process the attributes that had to be skipped in the first round. These
18525 attributes are the ones that need str_offsets_base or addr_base attributes.
18526 They could not have been processed in the first round, because at the time
18527 the values of str_offsets_base or addr_base may not have been known. */
18529 read_attribute_reprocess (const struct die_reader_specs
*reader
,
18530 struct attribute
*attr
)
18532 struct dwarf2_cu
*cu
= reader
->cu
;
18533 switch (attr
->form
)
18535 case DW_FORM_addrx
:
18536 case DW_FORM_GNU_addr_index
:
18537 DW_ADDR (attr
) = read_addr_index (cu
, DW_UNSND (attr
));
18539 case DW_FORM_loclistx
:
18540 DW_UNSND (attr
) = read_loclist_index (cu
, DW_UNSND (attr
));
18543 case DW_FORM_strx1
:
18544 case DW_FORM_strx2
:
18545 case DW_FORM_strx3
:
18546 case DW_FORM_strx4
:
18547 case DW_FORM_GNU_str_index
:
18549 unsigned int str_index
= DW_UNSND (attr
);
18550 if (reader
->dwo_file
!= NULL
)
18552 DW_STRING (attr
) = read_dwo_str_index (reader
, str_index
);
18553 DW_STRING_IS_CANONICAL (attr
) = 0;
18557 DW_STRING (attr
) = read_stub_str_index (cu
, str_index
);
18558 DW_STRING_IS_CANONICAL (attr
) = 0;
18563 gdb_assert_not_reached (_("Unexpected DWARF form."));
18567 /* Read an attribute value described by an attribute form. */
18569 static const gdb_byte
*
18570 read_attribute_value (const struct die_reader_specs
*reader
,
18571 struct attribute
*attr
, unsigned form
,
18572 LONGEST implicit_const
, const gdb_byte
*info_ptr
,
18573 bool *need_reprocess
)
18575 struct dwarf2_cu
*cu
= reader
->cu
;
18576 struct dwarf2_per_objfile
*dwarf2_per_objfile
18577 = cu
->per_cu
->dwarf2_per_objfile
;
18578 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18579 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18580 bfd
*abfd
= reader
->abfd
;
18581 struct comp_unit_head
*cu_header
= &cu
->header
;
18582 unsigned int bytes_read
;
18583 struct dwarf_block
*blk
;
18584 *need_reprocess
= false;
18586 attr
->form
= (enum dwarf_form
) form
;
18589 case DW_FORM_ref_addr
:
18590 if (cu
->header
.version
== 2)
18591 DW_UNSND (attr
) = cu
->header
.read_address (abfd
, info_ptr
,
18594 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
,
18596 info_ptr
+= bytes_read
;
18598 case DW_FORM_GNU_ref_alt
:
18599 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
18600 info_ptr
+= bytes_read
;
18603 DW_ADDR (attr
) = cu
->header
.read_address (abfd
, info_ptr
, &bytes_read
);
18604 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
18605 info_ptr
+= bytes_read
;
18607 case DW_FORM_block2
:
18608 blk
= dwarf_alloc_block (cu
);
18609 blk
->size
= read_2_bytes (abfd
, info_ptr
);
18611 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18612 info_ptr
+= blk
->size
;
18613 DW_BLOCK (attr
) = blk
;
18615 case DW_FORM_block4
:
18616 blk
= dwarf_alloc_block (cu
);
18617 blk
->size
= read_4_bytes (abfd
, info_ptr
);
18619 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18620 info_ptr
+= blk
->size
;
18621 DW_BLOCK (attr
) = blk
;
18623 case DW_FORM_data2
:
18624 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
18627 case DW_FORM_data4
:
18628 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
18631 case DW_FORM_data8
:
18632 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
18635 case DW_FORM_data16
:
18636 blk
= dwarf_alloc_block (cu
);
18638 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
18640 DW_BLOCK (attr
) = blk
;
18642 case DW_FORM_sec_offset
:
18643 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
18644 info_ptr
+= bytes_read
;
18646 case DW_FORM_loclistx
:
18648 *need_reprocess
= true;
18649 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18650 info_ptr
+= bytes_read
;
18653 case DW_FORM_string
:
18654 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
18655 DW_STRING_IS_CANONICAL (attr
) = 0;
18656 info_ptr
+= bytes_read
;
18659 if (!cu
->per_cu
->is_dwz
)
18661 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
18662 abfd
, info_ptr
, cu_header
,
18664 DW_STRING_IS_CANONICAL (attr
) = 0;
18665 info_ptr
+= bytes_read
;
18669 case DW_FORM_line_strp
:
18670 if (!cu
->per_cu
->is_dwz
)
18673 = dwarf2_per_objfile
->read_line_string (info_ptr
, cu_header
,
18675 DW_STRING_IS_CANONICAL (attr
) = 0;
18676 info_ptr
+= bytes_read
;
18680 case DW_FORM_GNU_strp_alt
:
18682 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
18683 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
18686 DW_STRING (attr
) = dwz
->read_string (objfile
, str_offset
);
18687 DW_STRING_IS_CANONICAL (attr
) = 0;
18688 info_ptr
+= bytes_read
;
18691 case DW_FORM_exprloc
:
18692 case DW_FORM_block
:
18693 blk
= dwarf_alloc_block (cu
);
18694 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18695 info_ptr
+= bytes_read
;
18696 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18697 info_ptr
+= blk
->size
;
18698 DW_BLOCK (attr
) = blk
;
18700 case DW_FORM_block1
:
18701 blk
= dwarf_alloc_block (cu
);
18702 blk
->size
= read_1_byte (abfd
, info_ptr
);
18704 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18705 info_ptr
+= blk
->size
;
18706 DW_BLOCK (attr
) = blk
;
18708 case DW_FORM_data1
:
18709 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
18713 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
18716 case DW_FORM_flag_present
:
18717 DW_UNSND (attr
) = 1;
18719 case DW_FORM_sdata
:
18720 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
18721 info_ptr
+= bytes_read
;
18723 case DW_FORM_udata
:
18724 case DW_FORM_rnglistx
:
18725 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18726 info_ptr
+= bytes_read
;
18729 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18730 + read_1_byte (abfd
, info_ptr
));
18734 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18735 + read_2_bytes (abfd
, info_ptr
));
18739 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18740 + read_4_bytes (abfd
, info_ptr
));
18744 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18745 + read_8_bytes (abfd
, info_ptr
));
18748 case DW_FORM_ref_sig8
:
18749 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
18752 case DW_FORM_ref_udata
:
18753 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18754 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
18755 info_ptr
+= bytes_read
;
18757 case DW_FORM_indirect
:
18758 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18759 info_ptr
+= bytes_read
;
18760 if (form
== DW_FORM_implicit_const
)
18762 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
18763 info_ptr
+= bytes_read
;
18765 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
18766 info_ptr
, need_reprocess
);
18768 case DW_FORM_implicit_const
:
18769 DW_SND (attr
) = implicit_const
;
18771 case DW_FORM_addrx
:
18772 case DW_FORM_GNU_addr_index
:
18773 *need_reprocess
= true;
18774 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18775 info_ptr
+= bytes_read
;
18778 case DW_FORM_strx1
:
18779 case DW_FORM_strx2
:
18780 case DW_FORM_strx3
:
18781 case DW_FORM_strx4
:
18782 case DW_FORM_GNU_str_index
:
18784 ULONGEST str_index
;
18785 if (form
== DW_FORM_strx1
)
18787 str_index
= read_1_byte (abfd
, info_ptr
);
18790 else if (form
== DW_FORM_strx2
)
18792 str_index
= read_2_bytes (abfd
, info_ptr
);
18795 else if (form
== DW_FORM_strx3
)
18797 str_index
= read_3_bytes (abfd
, info_ptr
);
18800 else if (form
== DW_FORM_strx4
)
18802 str_index
= read_4_bytes (abfd
, info_ptr
);
18807 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18808 info_ptr
+= bytes_read
;
18810 *need_reprocess
= true;
18811 DW_UNSND (attr
) = str_index
;
18815 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
18816 dwarf_form_name (form
),
18817 bfd_get_filename (abfd
));
18821 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
18822 attr
->form
= DW_FORM_GNU_ref_alt
;
18824 /* We have seen instances where the compiler tried to emit a byte
18825 size attribute of -1 which ended up being encoded as an unsigned
18826 0xffffffff. Although 0xffffffff is technically a valid size value,
18827 an object of this size seems pretty unlikely so we can relatively
18828 safely treat these cases as if the size attribute was invalid and
18829 treat them as zero by default. */
18830 if (attr
->name
== DW_AT_byte_size
18831 && form
== DW_FORM_data4
18832 && DW_UNSND (attr
) >= 0xffffffff)
18835 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
18836 hex_string (DW_UNSND (attr
)));
18837 DW_UNSND (attr
) = 0;
18843 /* Read an attribute described by an abbreviated attribute. */
18845 static const gdb_byte
*
18846 read_attribute (const struct die_reader_specs
*reader
,
18847 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
18848 const gdb_byte
*info_ptr
, bool *need_reprocess
)
18850 attr
->name
= abbrev
->name
;
18851 return read_attribute_value (reader
, attr
, abbrev
->form
,
18852 abbrev
->implicit_const
, info_ptr
,
18856 /* Return pointer to string at .debug_str offset STR_OFFSET. */
18858 static const char *
18859 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18860 LONGEST str_offset
)
18862 return dwarf2_per_objfile
->str
.read_string (dwarf2_per_objfile
->objfile
,
18863 str_offset
, "DW_FORM_strp");
18866 /* Return pointer to string at .debug_str offset as read from BUF.
18867 BUF is assumed to be in a compilation unit described by CU_HEADER.
18868 Return *BYTES_READ_PTR count of bytes read from BUF. */
18870 static const char *
18871 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
18872 const gdb_byte
*buf
,
18873 const struct comp_unit_head
*cu_header
,
18874 unsigned int *bytes_read_ptr
)
18876 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
18878 return read_indirect_string_at_offset (dwarf2_per_objfile
, str_offset
);
18884 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
18885 const struct comp_unit_head
*cu_header
,
18886 unsigned int *bytes_read_ptr
)
18888 bfd
*abfd
= objfile
->obfd
;
18889 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
18891 return line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
18894 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
18895 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
18896 ADDR_SIZE is the size of addresses from the CU header. */
18899 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18900 unsigned int addr_index
, gdb::optional
<ULONGEST
> addr_base
,
18903 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18904 bfd
*abfd
= objfile
->obfd
;
18905 const gdb_byte
*info_ptr
;
18906 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
18908 dwarf2_per_objfile
->addr
.read (objfile
);
18909 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
18910 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
18911 objfile_name (objfile
));
18912 if (addr_base_or_zero
+ addr_index
* addr_size
18913 >= dwarf2_per_objfile
->addr
.size
)
18914 error (_("DW_FORM_addr_index pointing outside of "
18915 ".debug_addr section [in module %s]"),
18916 objfile_name (objfile
));
18917 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
18918 + addr_base_or_zero
+ addr_index
* addr_size
);
18919 if (addr_size
== 4)
18920 return bfd_get_32 (abfd
, info_ptr
);
18922 return bfd_get_64 (abfd
, info_ptr
);
18925 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
18928 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
18930 return read_addr_index_1 (cu
->per_cu
->dwarf2_per_objfile
, addr_index
,
18931 cu
->addr_base
, cu
->header
.addr_size
);
18934 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
18937 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
18938 unsigned int *bytes_read
)
18940 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
18941 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
18943 return read_addr_index (cu
, addr_index
);
18949 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
, unsigned int addr_index
)
18951 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
18952 struct dwarf2_cu
*cu
= per_cu
->cu
;
18953 gdb::optional
<ULONGEST
> addr_base
;
18956 /* We need addr_base and addr_size.
18957 If we don't have PER_CU->cu, we have to get it.
18958 Nasty, but the alternative is storing the needed info in PER_CU,
18959 which at this point doesn't seem justified: it's not clear how frequently
18960 it would get used and it would increase the size of every PER_CU.
18961 Entry points like dwarf2_per_cu_addr_size do a similar thing
18962 so we're not in uncharted territory here.
18963 Alas we need to be a bit more complicated as addr_base is contained
18966 We don't need to read the entire CU(/TU).
18967 We just need the header and top level die.
18969 IWBN to use the aging mechanism to let us lazily later discard the CU.
18970 For now we skip this optimization. */
18974 addr_base
= cu
->addr_base
;
18975 addr_size
= cu
->header
.addr_size
;
18979 cutu_reader
reader (per_cu
, NULL
, 0, false);
18980 addr_base
= reader
.cu
->addr_base
;
18981 addr_size
= reader
.cu
->header
.addr_size
;
18984 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
18988 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
18989 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
18992 static const char *
18993 read_str_index (struct dwarf2_cu
*cu
,
18994 struct dwarf2_section_info
*str_section
,
18995 struct dwarf2_section_info
*str_offsets_section
,
18996 ULONGEST str_offsets_base
, ULONGEST str_index
)
18998 struct dwarf2_per_objfile
*dwarf2_per_objfile
18999 = cu
->per_cu
->dwarf2_per_objfile
;
19000 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19001 const char *objf_name
= objfile_name (objfile
);
19002 bfd
*abfd
= objfile
->obfd
;
19003 const gdb_byte
*info_ptr
;
19004 ULONGEST str_offset
;
19005 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
19007 str_section
->read (objfile
);
19008 str_offsets_section
->read (objfile
);
19009 if (str_section
->buffer
== NULL
)
19010 error (_("%s used without %s section"
19011 " in CU at offset %s [in module %s]"),
19012 form_name
, str_section
->get_name (),
19013 sect_offset_str (cu
->header
.sect_off
), objf_name
);
19014 if (str_offsets_section
->buffer
== NULL
)
19015 error (_("%s used without %s section"
19016 " in CU at offset %s [in module %s]"),
19017 form_name
, str_section
->get_name (),
19018 sect_offset_str (cu
->header
.sect_off
), objf_name
);
19019 info_ptr
= (str_offsets_section
->buffer
19021 + str_index
* cu
->header
.offset_size
);
19022 if (cu
->header
.offset_size
== 4)
19023 str_offset
= bfd_get_32 (abfd
, info_ptr
);
19025 str_offset
= bfd_get_64 (abfd
, info_ptr
);
19026 if (str_offset
>= str_section
->size
)
19027 error (_("Offset from %s pointing outside of"
19028 " .debug_str.dwo section in CU at offset %s [in module %s]"),
19029 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19030 return (const char *) (str_section
->buffer
+ str_offset
);
19033 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
19035 static const char *
19036 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
19038 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
19039 ? reader
->cu
->header
.addr_size
: 0;
19040 return read_str_index (reader
->cu
,
19041 &reader
->dwo_file
->sections
.str
,
19042 &reader
->dwo_file
->sections
.str_offsets
,
19043 str_offsets_base
, str_index
);
19046 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
19048 static const char *
19049 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
19051 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19052 const char *objf_name
= objfile_name (objfile
);
19053 static const char form_name
[] = "DW_FORM_GNU_str_index";
19054 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
19056 if (!cu
->str_offsets_base
.has_value ())
19057 error (_("%s used in Fission stub without %s"
19058 " in CU at offset 0x%lx [in module %s]"),
19059 form_name
, str_offsets_attr_name
,
19060 (long) cu
->header
.offset_size
, objf_name
);
19062 return read_str_index (cu
,
19063 &cu
->per_cu
->dwarf2_per_objfile
->str
,
19064 &cu
->per_cu
->dwarf2_per_objfile
->str_offsets
,
19065 *cu
->str_offsets_base
, str_index
);
19068 /* Return the length of an LEB128 number in BUF. */
19071 leb128_size (const gdb_byte
*buf
)
19073 const gdb_byte
*begin
= buf
;
19079 if ((byte
& 128) == 0)
19080 return buf
- begin
;
19085 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
19094 cu
->language
= language_c
;
19097 case DW_LANG_C_plus_plus
:
19098 case DW_LANG_C_plus_plus_11
:
19099 case DW_LANG_C_plus_plus_14
:
19100 cu
->language
= language_cplus
;
19103 cu
->language
= language_d
;
19105 case DW_LANG_Fortran77
:
19106 case DW_LANG_Fortran90
:
19107 case DW_LANG_Fortran95
:
19108 case DW_LANG_Fortran03
:
19109 case DW_LANG_Fortran08
:
19110 cu
->language
= language_fortran
;
19113 cu
->language
= language_go
;
19115 case DW_LANG_Mips_Assembler
:
19116 cu
->language
= language_asm
;
19118 case DW_LANG_Ada83
:
19119 case DW_LANG_Ada95
:
19120 cu
->language
= language_ada
;
19122 case DW_LANG_Modula2
:
19123 cu
->language
= language_m2
;
19125 case DW_LANG_Pascal83
:
19126 cu
->language
= language_pascal
;
19129 cu
->language
= language_objc
;
19132 case DW_LANG_Rust_old
:
19133 cu
->language
= language_rust
;
19135 case DW_LANG_Cobol74
:
19136 case DW_LANG_Cobol85
:
19138 cu
->language
= language_minimal
;
19141 cu
->language_defn
= language_def (cu
->language
);
19144 /* Return the named attribute or NULL if not there. */
19146 static struct attribute
*
19147 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19152 struct attribute
*spec
= NULL
;
19154 for (i
= 0; i
< die
->num_attrs
; ++i
)
19156 if (die
->attrs
[i
].name
== name
)
19157 return &die
->attrs
[i
];
19158 if (die
->attrs
[i
].name
== DW_AT_specification
19159 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
19160 spec
= &die
->attrs
[i
];
19166 die
= follow_die_ref (die
, spec
, &cu
);
19172 /* Return the string associated with a string-typed attribute, or NULL if it
19173 is either not found or is of an incorrect type. */
19175 static const char *
19176 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19178 struct attribute
*attr
;
19179 const char *str
= NULL
;
19181 attr
= dwarf2_attr (die
, name
, cu
);
19185 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
19186 || attr
->form
== DW_FORM_string
19187 || attr
->form
== DW_FORM_strx
19188 || attr
->form
== DW_FORM_strx1
19189 || attr
->form
== DW_FORM_strx2
19190 || attr
->form
== DW_FORM_strx3
19191 || attr
->form
== DW_FORM_strx4
19192 || attr
->form
== DW_FORM_GNU_str_index
19193 || attr
->form
== DW_FORM_GNU_strp_alt
)
19194 str
= DW_STRING (attr
);
19196 complaint (_("string type expected for attribute %s for "
19197 "DIE at %s in module %s"),
19198 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
19199 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
19205 /* Return the dwo name or NULL if not present. If present, it is in either
19206 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
19207 static const char *
19208 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
19210 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
19211 if (dwo_name
== nullptr)
19212 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
19216 /* Return non-zero iff the attribute NAME is defined for the given DIE,
19217 and holds a non-zero value. This function should only be used for
19218 DW_FORM_flag or DW_FORM_flag_present attributes. */
19221 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
19223 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
19225 return (attr
&& DW_UNSND (attr
));
19229 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
19231 /* A DIE is a declaration if it has a DW_AT_declaration attribute
19232 which value is non-zero. However, we have to be careful with
19233 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
19234 (via dwarf2_flag_true_p) follows this attribute. So we may
19235 end up accidently finding a declaration attribute that belongs
19236 to a different DIE referenced by the specification attribute,
19237 even though the given DIE does not have a declaration attribute. */
19238 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
19239 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
19242 /* Return the die giving the specification for DIE, if there is
19243 one. *SPEC_CU is the CU containing DIE on input, and the CU
19244 containing the return value on output. If there is no
19245 specification, but there is an abstract origin, that is
19248 static struct die_info
*
19249 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
19251 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
19254 if (spec_attr
== NULL
)
19255 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
19257 if (spec_attr
== NULL
)
19260 return follow_die_ref (die
, spec_attr
, spec_cu
);
19263 /* Stub for free_line_header to match void * callback types. */
19266 free_line_header_voidp (void *arg
)
19268 struct line_header
*lh
= (struct line_header
*) arg
;
19273 /* A convenience function to find the proper .debug_line section for a CU. */
19275 static struct dwarf2_section_info
*
19276 get_debug_line_section (struct dwarf2_cu
*cu
)
19278 struct dwarf2_section_info
*section
;
19279 struct dwarf2_per_objfile
*dwarf2_per_objfile
19280 = cu
->per_cu
->dwarf2_per_objfile
;
19282 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
19284 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19285 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
19286 else if (cu
->per_cu
->is_dwz
)
19288 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19290 section
= &dwz
->line
;
19293 section
= &dwarf2_per_objfile
->line
;
19298 /* Read the statement program header starting at OFFSET in
19299 .debug_line, or .debug_line.dwo. Return a pointer
19300 to a struct line_header, allocated using xmalloc.
19301 Returns NULL if there is a problem reading the header, e.g., if it
19302 has a version we don't understand.
19304 NOTE: the strings in the include directory and file name tables of
19305 the returned object point into the dwarf line section buffer,
19306 and must not be freed. */
19308 static line_header_up
19309 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
19311 struct dwarf2_section_info
*section
;
19312 struct dwarf2_per_objfile
*dwarf2_per_objfile
19313 = cu
->per_cu
->dwarf2_per_objfile
;
19315 section
= get_debug_line_section (cu
);
19316 section
->read (dwarf2_per_objfile
->objfile
);
19317 if (section
->buffer
== NULL
)
19319 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19320 complaint (_("missing .debug_line.dwo section"));
19322 complaint (_("missing .debug_line section"));
19326 return dwarf_decode_line_header (sect_off
, cu
->per_cu
->is_dwz
,
19327 dwarf2_per_objfile
, section
,
19331 /* Subroutine of dwarf_decode_lines to simplify it.
19332 Return the file name of the psymtab for the given file_entry.
19333 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
19334 If space for the result is malloc'd, *NAME_HOLDER will be set.
19335 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
19337 static const char *
19338 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
19339 const dwarf2_psymtab
*pst
,
19340 const char *comp_dir
,
19341 gdb::unique_xmalloc_ptr
<char> *name_holder
)
19343 const char *include_name
= fe
.name
;
19344 const char *include_name_to_compare
= include_name
;
19345 const char *pst_filename
;
19348 const char *dir_name
= fe
.include_dir (lh
);
19350 gdb::unique_xmalloc_ptr
<char> hold_compare
;
19351 if (!IS_ABSOLUTE_PATH (include_name
)
19352 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
19354 /* Avoid creating a duplicate psymtab for PST.
19355 We do this by comparing INCLUDE_NAME and PST_FILENAME.
19356 Before we do the comparison, however, we need to account
19357 for DIR_NAME and COMP_DIR.
19358 First prepend dir_name (if non-NULL). If we still don't
19359 have an absolute path prepend comp_dir (if non-NULL).
19360 However, the directory we record in the include-file's
19361 psymtab does not contain COMP_DIR (to match the
19362 corresponding symtab(s)).
19367 bash$ gcc -g ./hello.c
19368 include_name = "hello.c"
19370 DW_AT_comp_dir = comp_dir = "/tmp"
19371 DW_AT_name = "./hello.c"
19375 if (dir_name
!= NULL
)
19377 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
19378 include_name
, (char *) NULL
));
19379 include_name
= name_holder
->get ();
19380 include_name_to_compare
= include_name
;
19382 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
19384 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
19385 include_name
, (char *) NULL
));
19386 include_name_to_compare
= hold_compare
.get ();
19390 pst_filename
= pst
->filename
;
19391 gdb::unique_xmalloc_ptr
<char> copied_name
;
19392 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
19394 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
19395 pst_filename
, (char *) NULL
));
19396 pst_filename
= copied_name
.get ();
19399 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
19403 return include_name
;
19406 /* State machine to track the state of the line number program. */
19408 class lnp_state_machine
19411 /* Initialize a machine state for the start of a line number
19413 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
19414 bool record_lines_p
);
19416 file_entry
*current_file ()
19418 /* lh->file_names is 0-based, but the file name numbers in the
19419 statement program are 1-based. */
19420 return m_line_header
->file_name_at (m_file
);
19423 /* Record the line in the state machine. END_SEQUENCE is true if
19424 we're processing the end of a sequence. */
19425 void record_line (bool end_sequence
);
19427 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
19428 nop-out rest of the lines in this sequence. */
19429 void check_line_address (struct dwarf2_cu
*cu
,
19430 const gdb_byte
*line_ptr
,
19431 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
19433 void handle_set_discriminator (unsigned int discriminator
)
19435 m_discriminator
= discriminator
;
19436 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
19439 /* Handle DW_LNE_set_address. */
19440 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
19443 address
+= baseaddr
;
19444 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
19447 /* Handle DW_LNS_advance_pc. */
19448 void handle_advance_pc (CORE_ADDR adjust
);
19450 /* Handle a special opcode. */
19451 void handle_special_opcode (unsigned char op_code
);
19453 /* Handle DW_LNS_advance_line. */
19454 void handle_advance_line (int line_delta
)
19456 advance_line (line_delta
);
19459 /* Handle DW_LNS_set_file. */
19460 void handle_set_file (file_name_index file
);
19462 /* Handle DW_LNS_negate_stmt. */
19463 void handle_negate_stmt ()
19465 m_is_stmt
= !m_is_stmt
;
19468 /* Handle DW_LNS_const_add_pc. */
19469 void handle_const_add_pc ();
19471 /* Handle DW_LNS_fixed_advance_pc. */
19472 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
19474 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19478 /* Handle DW_LNS_copy. */
19479 void handle_copy ()
19481 record_line (false);
19482 m_discriminator
= 0;
19485 /* Handle DW_LNE_end_sequence. */
19486 void handle_end_sequence ()
19488 m_currently_recording_lines
= true;
19492 /* Advance the line by LINE_DELTA. */
19493 void advance_line (int line_delta
)
19495 m_line
+= line_delta
;
19497 if (line_delta
!= 0)
19498 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
19501 struct dwarf2_cu
*m_cu
;
19503 gdbarch
*m_gdbarch
;
19505 /* True if we're recording lines.
19506 Otherwise we're building partial symtabs and are just interested in
19507 finding include files mentioned by the line number program. */
19508 bool m_record_lines_p
;
19510 /* The line number header. */
19511 line_header
*m_line_header
;
19513 /* These are part of the standard DWARF line number state machine,
19514 and initialized according to the DWARF spec. */
19516 unsigned char m_op_index
= 0;
19517 /* The line table index of the current file. */
19518 file_name_index m_file
= 1;
19519 unsigned int m_line
= 1;
19521 /* These are initialized in the constructor. */
19523 CORE_ADDR m_address
;
19525 unsigned int m_discriminator
;
19527 /* Additional bits of state we need to track. */
19529 /* The last file that we called dwarf2_start_subfile for.
19530 This is only used for TLLs. */
19531 unsigned int m_last_file
= 0;
19532 /* The last file a line number was recorded for. */
19533 struct subfile
*m_last_subfile
= NULL
;
19535 /* When true, record the lines we decode. */
19536 bool m_currently_recording_lines
= false;
19538 /* The last line number that was recorded, used to coalesce
19539 consecutive entries for the same line. This can happen, for
19540 example, when discriminators are present. PR 17276. */
19541 unsigned int m_last_line
= 0;
19542 bool m_line_has_non_zero_discriminator
= false;
19546 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
19548 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
19549 / m_line_header
->maximum_ops_per_instruction
)
19550 * m_line_header
->minimum_instruction_length
);
19551 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19552 m_op_index
= ((m_op_index
+ adjust
)
19553 % m_line_header
->maximum_ops_per_instruction
);
19557 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
19559 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
19560 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
19561 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
19562 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
19563 / m_line_header
->maximum_ops_per_instruction
)
19564 * m_line_header
->minimum_instruction_length
);
19565 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19566 m_op_index
= ((m_op_index
+ adj_opcode_d
)
19567 % m_line_header
->maximum_ops_per_instruction
);
19569 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
19570 advance_line (line_delta
);
19571 record_line (false);
19572 m_discriminator
= 0;
19576 lnp_state_machine::handle_set_file (file_name_index file
)
19580 const file_entry
*fe
= current_file ();
19582 dwarf2_debug_line_missing_file_complaint ();
19583 else if (m_record_lines_p
)
19585 const char *dir
= fe
->include_dir (m_line_header
);
19587 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
19588 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
19589 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
19594 lnp_state_machine::handle_const_add_pc ()
19597 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
19600 = (((m_op_index
+ adjust
)
19601 / m_line_header
->maximum_ops_per_instruction
)
19602 * m_line_header
->minimum_instruction_length
);
19604 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19605 m_op_index
= ((m_op_index
+ adjust
)
19606 % m_line_header
->maximum_ops_per_instruction
);
19609 /* Return non-zero if we should add LINE to the line number table.
19610 LINE is the line to add, LAST_LINE is the last line that was added,
19611 LAST_SUBFILE is the subfile for LAST_LINE.
19612 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
19613 had a non-zero discriminator.
19615 We have to be careful in the presence of discriminators.
19616 E.g., for this line:
19618 for (i = 0; i < 100000; i++);
19620 clang can emit four line number entries for that one line,
19621 each with a different discriminator.
19622 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
19624 However, we want gdb to coalesce all four entries into one.
19625 Otherwise the user could stepi into the middle of the line and
19626 gdb would get confused about whether the pc really was in the
19627 middle of the line.
19629 Things are further complicated by the fact that two consecutive
19630 line number entries for the same line is a heuristic used by gcc
19631 to denote the end of the prologue. So we can't just discard duplicate
19632 entries, we have to be selective about it. The heuristic we use is
19633 that we only collapse consecutive entries for the same line if at least
19634 one of those entries has a non-zero discriminator. PR 17276.
19636 Note: Addresses in the line number state machine can never go backwards
19637 within one sequence, thus this coalescing is ok. */
19640 dwarf_record_line_p (struct dwarf2_cu
*cu
,
19641 unsigned int line
, unsigned int last_line
,
19642 int line_has_non_zero_discriminator
,
19643 struct subfile
*last_subfile
)
19645 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
19647 if (line
!= last_line
)
19649 /* Same line for the same file that we've seen already.
19650 As a last check, for pr 17276, only record the line if the line
19651 has never had a non-zero discriminator. */
19652 if (!line_has_non_zero_discriminator
)
19657 /* Use the CU's builder to record line number LINE beginning at
19658 address ADDRESS in the line table of subfile SUBFILE. */
19661 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
19662 unsigned int line
, CORE_ADDR address
, bool is_stmt
,
19663 struct dwarf2_cu
*cu
)
19665 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
19667 if (dwarf_line_debug
)
19669 fprintf_unfiltered (gdb_stdlog
,
19670 "Recording line %u, file %s, address %s\n",
19671 line
, lbasename (subfile
->name
),
19672 paddress (gdbarch
, address
));
19676 cu
->get_builder ()->record_line (subfile
, line
, addr
, is_stmt
);
19679 /* Subroutine of dwarf_decode_lines_1 to simplify it.
19680 Mark the end of a set of line number records.
19681 The arguments are the same as for dwarf_record_line_1.
19682 If SUBFILE is NULL the request is ignored. */
19685 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
19686 CORE_ADDR address
, struct dwarf2_cu
*cu
)
19688 if (subfile
== NULL
)
19691 if (dwarf_line_debug
)
19693 fprintf_unfiltered (gdb_stdlog
,
19694 "Finishing current line, file %s, address %s\n",
19695 lbasename (subfile
->name
),
19696 paddress (gdbarch
, address
));
19699 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, true, cu
);
19703 lnp_state_machine::record_line (bool end_sequence
)
19705 if (dwarf_line_debug
)
19707 fprintf_unfiltered (gdb_stdlog
,
19708 "Processing actual line %u: file %u,"
19709 " address %s, is_stmt %u, discrim %u%s\n",
19711 paddress (m_gdbarch
, m_address
),
19712 m_is_stmt
, m_discriminator
,
19713 (end_sequence
? "\t(end sequence)" : ""));
19716 file_entry
*fe
= current_file ();
19719 dwarf2_debug_line_missing_file_complaint ();
19720 /* For now we ignore lines not starting on an instruction boundary.
19721 But not when processing end_sequence for compatibility with the
19722 previous version of the code. */
19723 else if (m_op_index
== 0 || end_sequence
)
19725 fe
->included_p
= 1;
19726 if (m_record_lines_p
)
19728 if (m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ()
19731 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
19732 m_currently_recording_lines
? m_cu
: nullptr);
19737 bool is_stmt
= producer_is_codewarrior (m_cu
) || m_is_stmt
;
19739 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
19740 m_line_has_non_zero_discriminator
,
19743 buildsym_compunit
*builder
= m_cu
->get_builder ();
19744 dwarf_record_line_1 (m_gdbarch
,
19745 builder
->get_current_subfile (),
19746 m_line
, m_address
, is_stmt
,
19747 m_currently_recording_lines
? m_cu
: nullptr);
19749 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
19750 m_last_line
= m_line
;
19756 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
19757 line_header
*lh
, bool record_lines_p
)
19761 m_record_lines_p
= record_lines_p
;
19762 m_line_header
= lh
;
19764 m_currently_recording_lines
= true;
19766 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
19767 was a line entry for it so that the backend has a chance to adjust it
19768 and also record it in case it needs it. This is currently used by MIPS
19769 code, cf. `mips_adjust_dwarf2_line'. */
19770 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
19771 m_is_stmt
= lh
->default_is_stmt
;
19772 m_discriminator
= 0;
19776 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
19777 const gdb_byte
*line_ptr
,
19778 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
19780 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
19781 the pc range of the CU. However, we restrict the test to only ADDRESS
19782 values of zero to preserve GDB's previous behaviour which is to handle
19783 the specific case of a function being GC'd by the linker. */
19785 if (address
== 0 && address
< unrelocated_lowpc
)
19787 /* This line table is for a function which has been
19788 GCd by the linker. Ignore it. PR gdb/12528 */
19790 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19791 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
19793 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
19794 line_offset
, objfile_name (objfile
));
19795 m_currently_recording_lines
= false;
19796 /* Note: m_currently_recording_lines is left as false until we see
19797 DW_LNE_end_sequence. */
19801 /* Subroutine of dwarf_decode_lines to simplify it.
19802 Process the line number information in LH.
19803 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
19804 program in order to set included_p for every referenced header. */
19807 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
19808 const int decode_for_pst_p
, CORE_ADDR lowpc
)
19810 const gdb_byte
*line_ptr
, *extended_end
;
19811 const gdb_byte
*line_end
;
19812 unsigned int bytes_read
, extended_len
;
19813 unsigned char op_code
, extended_op
;
19814 CORE_ADDR baseaddr
;
19815 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19816 bfd
*abfd
= objfile
->obfd
;
19817 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19818 /* True if we're recording line info (as opposed to building partial
19819 symtabs and just interested in finding include files mentioned by
19820 the line number program). */
19821 bool record_lines_p
= !decode_for_pst_p
;
19823 baseaddr
= objfile
->text_section_offset ();
19825 line_ptr
= lh
->statement_program_start
;
19826 line_end
= lh
->statement_program_end
;
19828 /* Read the statement sequences until there's nothing left. */
19829 while (line_ptr
< line_end
)
19831 /* The DWARF line number program state machine. Reset the state
19832 machine at the start of each sequence. */
19833 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
19834 bool end_sequence
= false;
19836 if (record_lines_p
)
19838 /* Start a subfile for the current file of the state
19840 const file_entry
*fe
= state_machine
.current_file ();
19843 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
19846 /* Decode the table. */
19847 while (line_ptr
< line_end
&& !end_sequence
)
19849 op_code
= read_1_byte (abfd
, line_ptr
);
19852 if (op_code
>= lh
->opcode_base
)
19854 /* Special opcode. */
19855 state_machine
.handle_special_opcode (op_code
);
19857 else switch (op_code
)
19859 case DW_LNS_extended_op
:
19860 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
19862 line_ptr
+= bytes_read
;
19863 extended_end
= line_ptr
+ extended_len
;
19864 extended_op
= read_1_byte (abfd
, line_ptr
);
19866 switch (extended_op
)
19868 case DW_LNE_end_sequence
:
19869 state_machine
.handle_end_sequence ();
19870 end_sequence
= true;
19872 case DW_LNE_set_address
:
19875 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
19876 line_ptr
+= bytes_read
;
19878 state_machine
.check_line_address (cu
, line_ptr
,
19879 lowpc
- baseaddr
, address
);
19880 state_machine
.handle_set_address (baseaddr
, address
);
19883 case DW_LNE_define_file
:
19885 const char *cur_file
;
19886 unsigned int mod_time
, length
;
19889 cur_file
= read_direct_string (abfd
, line_ptr
,
19891 line_ptr
+= bytes_read
;
19892 dindex
= (dir_index
)
19893 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19894 line_ptr
+= bytes_read
;
19896 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19897 line_ptr
+= bytes_read
;
19899 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19900 line_ptr
+= bytes_read
;
19901 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
19904 case DW_LNE_set_discriminator
:
19906 /* The discriminator is not interesting to the
19907 debugger; just ignore it. We still need to
19908 check its value though:
19909 if there are consecutive entries for the same
19910 (non-prologue) line we want to coalesce them.
19913 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19914 line_ptr
+= bytes_read
;
19916 state_machine
.handle_set_discriminator (discr
);
19920 complaint (_("mangled .debug_line section"));
19923 /* Make sure that we parsed the extended op correctly. If e.g.
19924 we expected a different address size than the producer used,
19925 we may have read the wrong number of bytes. */
19926 if (line_ptr
!= extended_end
)
19928 complaint (_("mangled .debug_line section"));
19933 state_machine
.handle_copy ();
19935 case DW_LNS_advance_pc
:
19938 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19939 line_ptr
+= bytes_read
;
19941 state_machine
.handle_advance_pc (adjust
);
19944 case DW_LNS_advance_line
:
19947 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
19948 line_ptr
+= bytes_read
;
19950 state_machine
.handle_advance_line (line_delta
);
19953 case DW_LNS_set_file
:
19955 file_name_index file
19956 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
19958 line_ptr
+= bytes_read
;
19960 state_machine
.handle_set_file (file
);
19963 case DW_LNS_set_column
:
19964 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19965 line_ptr
+= bytes_read
;
19967 case DW_LNS_negate_stmt
:
19968 state_machine
.handle_negate_stmt ();
19970 case DW_LNS_set_basic_block
:
19972 /* Add to the address register of the state machine the
19973 address increment value corresponding to special opcode
19974 255. I.e., this value is scaled by the minimum
19975 instruction length since special opcode 255 would have
19976 scaled the increment. */
19977 case DW_LNS_const_add_pc
:
19978 state_machine
.handle_const_add_pc ();
19980 case DW_LNS_fixed_advance_pc
:
19982 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
19985 state_machine
.handle_fixed_advance_pc (addr_adj
);
19990 /* Unknown standard opcode, ignore it. */
19993 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
19995 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19996 line_ptr
+= bytes_read
;
20003 dwarf2_debug_line_missing_end_sequence_complaint ();
20005 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
20006 in which case we still finish recording the last line). */
20007 state_machine
.record_line (true);
20011 /* Decode the Line Number Program (LNP) for the given line_header
20012 structure and CU. The actual information extracted and the type
20013 of structures created from the LNP depends on the value of PST.
20015 1. If PST is NULL, then this procedure uses the data from the program
20016 to create all necessary symbol tables, and their linetables.
20018 2. If PST is not NULL, this procedure reads the program to determine
20019 the list of files included by the unit represented by PST, and
20020 builds all the associated partial symbol tables.
20022 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20023 It is used for relative paths in the line table.
20024 NOTE: When processing partial symtabs (pst != NULL),
20025 comp_dir == pst->dirname.
20027 NOTE: It is important that psymtabs have the same file name (via strcmp)
20028 as the corresponding symtab. Since COMP_DIR is not used in the name of the
20029 symtab we don't use it in the name of the psymtabs we create.
20030 E.g. expand_line_sal requires this when finding psymtabs to expand.
20031 A good testcase for this is mb-inline.exp.
20033 LOWPC is the lowest address in CU (or 0 if not known).
20035 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
20036 for its PC<->lines mapping information. Otherwise only the filename
20037 table is read in. */
20040 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
20041 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
20042 CORE_ADDR lowpc
, int decode_mapping
)
20044 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20045 const int decode_for_pst_p
= (pst
!= NULL
);
20047 if (decode_mapping
)
20048 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
20050 if (decode_for_pst_p
)
20052 /* Now that we're done scanning the Line Header Program, we can
20053 create the psymtab of each included file. */
20054 for (auto &file_entry
: lh
->file_names ())
20055 if (file_entry
.included_p
== 1)
20057 gdb::unique_xmalloc_ptr
<char> name_holder
;
20058 const char *include_name
=
20059 psymtab_include_file_name (lh
, file_entry
, pst
,
20060 comp_dir
, &name_holder
);
20061 if (include_name
!= NULL
)
20062 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
20067 /* Make sure a symtab is created for every file, even files
20068 which contain only variables (i.e. no code with associated
20070 buildsym_compunit
*builder
= cu
->get_builder ();
20071 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
20073 for (auto &fe
: lh
->file_names ())
20075 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
20076 if (builder
->get_current_subfile ()->symtab
== NULL
)
20078 builder
->get_current_subfile ()->symtab
20079 = allocate_symtab (cust
,
20080 builder
->get_current_subfile ()->name
);
20082 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
20087 /* Start a subfile for DWARF. FILENAME is the name of the file and
20088 DIRNAME the name of the source directory which contains FILENAME
20089 or NULL if not known.
20090 This routine tries to keep line numbers from identical absolute and
20091 relative file names in a common subfile.
20093 Using the `list' example from the GDB testsuite, which resides in
20094 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
20095 of /srcdir/list0.c yields the following debugging information for list0.c:
20097 DW_AT_name: /srcdir/list0.c
20098 DW_AT_comp_dir: /compdir
20099 files.files[0].name: list0.h
20100 files.files[0].dir: /srcdir
20101 files.files[1].name: list0.c
20102 files.files[1].dir: /srcdir
20104 The line number information for list0.c has to end up in a single
20105 subfile, so that `break /srcdir/list0.c:1' works as expected.
20106 start_subfile will ensure that this happens provided that we pass the
20107 concatenation of files.files[1].dir and files.files[1].name as the
20111 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
20112 const char *dirname
)
20114 gdb::unique_xmalloc_ptr
<char> copy
;
20116 /* In order not to lose the line information directory,
20117 we concatenate it to the filename when it makes sense.
20118 Note that the Dwarf3 standard says (speaking of filenames in line
20119 information): ``The directory index is ignored for file names
20120 that represent full path names''. Thus ignoring dirname in the
20121 `else' branch below isn't an issue. */
20123 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
20125 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
20126 filename
= copy
.get ();
20129 cu
->get_builder ()->start_subfile (filename
);
20132 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
20133 buildsym_compunit constructor. */
20135 struct compunit_symtab
*
20136 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
20139 gdb_assert (m_builder
== nullptr);
20141 m_builder
.reset (new struct buildsym_compunit
20142 (per_cu
->dwarf2_per_objfile
->objfile
,
20143 name
, comp_dir
, language
, low_pc
));
20145 list_in_scope
= get_builder ()->get_file_symbols ();
20147 get_builder ()->record_debugformat ("DWARF 2");
20148 get_builder ()->record_producer (producer
);
20150 processing_has_namespace_info
= false;
20152 return get_builder ()->get_compunit_symtab ();
20156 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
20157 struct dwarf2_cu
*cu
)
20159 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20160 struct comp_unit_head
*cu_header
= &cu
->header
;
20162 /* NOTE drow/2003-01-30: There used to be a comment and some special
20163 code here to turn a symbol with DW_AT_external and a
20164 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
20165 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
20166 with some versions of binutils) where shared libraries could have
20167 relocations against symbols in their debug information - the
20168 minimal symbol would have the right address, but the debug info
20169 would not. It's no longer necessary, because we will explicitly
20170 apply relocations when we read in the debug information now. */
20172 /* A DW_AT_location attribute with no contents indicates that a
20173 variable has been optimized away. */
20174 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0)
20176 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20180 /* Handle one degenerate form of location expression specially, to
20181 preserve GDB's previous behavior when section offsets are
20182 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
20183 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
20185 if (attr
->form_is_block ()
20186 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
20187 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
20188 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
20189 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
20190 && (DW_BLOCK (attr
)->size
20191 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
20193 unsigned int dummy
;
20195 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
20196 SET_SYMBOL_VALUE_ADDRESS
20197 (sym
, cu
->header
.read_address (objfile
->obfd
,
20198 DW_BLOCK (attr
)->data
+ 1,
20201 SET_SYMBOL_VALUE_ADDRESS
20202 (sym
, read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1,
20204 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
20205 fixup_symbol_section (sym
, objfile
);
20206 SET_SYMBOL_VALUE_ADDRESS
20208 SYMBOL_VALUE_ADDRESS (sym
)
20209 + objfile
->section_offsets
[SYMBOL_SECTION (sym
)]);
20213 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
20214 expression evaluator, and use LOC_COMPUTED only when necessary
20215 (i.e. when the value of a register or memory location is
20216 referenced, or a thread-local block, etc.). Then again, it might
20217 not be worthwhile. I'm assuming that it isn't unless performance
20218 or memory numbers show me otherwise. */
20220 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
20222 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
20223 cu
->has_loclist
= true;
20226 /* Given a pointer to a DWARF information entry, figure out if we need
20227 to make a symbol table entry for it, and if so, create a new entry
20228 and return a pointer to it.
20229 If TYPE is NULL, determine symbol type from the die, otherwise
20230 used the passed type.
20231 If SPACE is not NULL, use it to hold the new symbol. If it is
20232 NULL, allocate a new symbol on the objfile's obstack. */
20234 static struct symbol
*
20235 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
20236 struct symbol
*space
)
20238 struct dwarf2_per_objfile
*dwarf2_per_objfile
20239 = cu
->per_cu
->dwarf2_per_objfile
;
20240 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20241 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
20242 struct symbol
*sym
= NULL
;
20244 struct attribute
*attr
= NULL
;
20245 struct attribute
*attr2
= NULL
;
20246 CORE_ADDR baseaddr
;
20247 struct pending
**list_to_add
= NULL
;
20249 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
20251 baseaddr
= objfile
->text_section_offset ();
20253 name
= dwarf2_name (die
, cu
);
20256 const char *linkagename
;
20257 int suppress_add
= 0;
20262 sym
= allocate_symbol (objfile
);
20263 OBJSTAT (objfile
, n_syms
++);
20265 /* Cache this symbol's name and the name's demangled form (if any). */
20266 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
20267 linkagename
= dwarf2_physname (name
, die
, cu
);
20268 sym
->compute_and_set_names (linkagename
, false, objfile
->per_bfd
);
20270 /* Fortran does not have mangling standard and the mangling does differ
20271 between gfortran, iFort etc. */
20272 if (cu
->language
== language_fortran
20273 && symbol_get_demangled_name (sym
) == NULL
)
20274 symbol_set_demangled_name (sym
,
20275 dwarf2_full_name (name
, die
, cu
),
20278 /* Default assumptions.
20279 Use the passed type or decode it from the die. */
20280 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20281 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20283 SYMBOL_TYPE (sym
) = type
;
20285 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
20286 attr
= dwarf2_attr (die
,
20287 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
20289 if (attr
!= nullptr)
20291 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
20294 attr
= dwarf2_attr (die
,
20295 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
20297 if (attr
!= nullptr)
20299 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
20300 struct file_entry
*fe
;
20302 if (cu
->line_header
!= NULL
)
20303 fe
= cu
->line_header
->file_name_at (file_index
);
20308 complaint (_("file index out of range"));
20310 symbol_set_symtab (sym
, fe
->symtab
);
20316 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
20317 if (attr
!= nullptr)
20321 addr
= attr
->value_as_address ();
20322 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
20323 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
20325 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
20326 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
20327 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
20328 add_symbol_to_list (sym
, cu
->list_in_scope
);
20330 case DW_TAG_subprogram
:
20331 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20333 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20334 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20335 if ((attr2
&& (DW_UNSND (attr2
) != 0))
20336 || cu
->language
== language_ada
20337 || cu
->language
== language_fortran
)
20339 /* Subprograms marked external are stored as a global symbol.
20340 Ada and Fortran subprograms, whether marked external or
20341 not, are always stored as a global symbol, because we want
20342 to be able to access them globally. For instance, we want
20343 to be able to break on a nested subprogram without having
20344 to specify the context. */
20345 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20349 list_to_add
= cu
->list_in_scope
;
20352 case DW_TAG_inlined_subroutine
:
20353 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20355 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20356 SYMBOL_INLINED (sym
) = 1;
20357 list_to_add
= cu
->list_in_scope
;
20359 case DW_TAG_template_value_param
:
20361 /* Fall through. */
20362 case DW_TAG_constant
:
20363 case DW_TAG_variable
:
20364 case DW_TAG_member
:
20365 /* Compilation with minimal debug info may result in
20366 variables with missing type entries. Change the
20367 misleading `void' type to something sensible. */
20368 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
20369 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
20371 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20372 /* In the case of DW_TAG_member, we should only be called for
20373 static const members. */
20374 if (die
->tag
== DW_TAG_member
)
20376 /* dwarf2_add_field uses die_is_declaration,
20377 so we do the same. */
20378 gdb_assert (die_is_declaration (die
, cu
));
20381 if (attr
!= nullptr)
20383 dwarf2_const_value (attr
, sym
, cu
);
20384 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20387 if (attr2
&& (DW_UNSND (attr2
) != 0))
20388 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20390 list_to_add
= cu
->list_in_scope
;
20394 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20395 if (attr
!= nullptr)
20397 var_decode_location (attr
, sym
, cu
);
20398 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20400 /* Fortran explicitly imports any global symbols to the local
20401 scope by DW_TAG_common_block. */
20402 if (cu
->language
== language_fortran
&& die
->parent
20403 && die
->parent
->tag
== DW_TAG_common_block
)
20406 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20407 && SYMBOL_VALUE_ADDRESS (sym
) == 0
20408 && !dwarf2_per_objfile
->has_section_at_zero
)
20410 /* When a static variable is eliminated by the linker,
20411 the corresponding debug information is not stripped
20412 out, but the variable address is set to null;
20413 do not add such variables into symbol table. */
20415 else if (attr2
&& (DW_UNSND (attr2
) != 0))
20417 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20418 && (objfile
->flags
& OBJF_MAINLINE
) == 0
20419 && dwarf2_per_objfile
->can_copy
)
20421 /* A global static variable might be subject to
20422 copy relocation. We first check for a local
20423 minsym, though, because maybe the symbol was
20424 marked hidden, in which case this would not
20426 bound_minimal_symbol found
20427 = (lookup_minimal_symbol_linkage
20428 (sym
->linkage_name (), objfile
));
20429 if (found
.minsym
!= nullptr)
20430 sym
->maybe_copied
= 1;
20433 /* A variable with DW_AT_external is never static,
20434 but it may be block-scoped. */
20436 = ((cu
->list_in_scope
20437 == cu
->get_builder ()->get_file_symbols ())
20438 ? cu
->get_builder ()->get_global_symbols ()
20439 : cu
->list_in_scope
);
20442 list_to_add
= cu
->list_in_scope
;
20446 /* We do not know the address of this symbol.
20447 If it is an external symbol and we have type information
20448 for it, enter the symbol as a LOC_UNRESOLVED symbol.
20449 The address of the variable will then be determined from
20450 the minimal symbol table whenever the variable is
20452 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20454 /* Fortran explicitly imports any global symbols to the local
20455 scope by DW_TAG_common_block. */
20456 if (cu
->language
== language_fortran
&& die
->parent
20457 && die
->parent
->tag
== DW_TAG_common_block
)
20459 /* SYMBOL_CLASS doesn't matter here because
20460 read_common_block is going to reset it. */
20462 list_to_add
= cu
->list_in_scope
;
20464 else if (attr2
&& (DW_UNSND (attr2
) != 0)
20465 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
20467 /* A variable with DW_AT_external is never static, but it
20468 may be block-scoped. */
20470 = ((cu
->list_in_scope
20471 == cu
->get_builder ()->get_file_symbols ())
20472 ? cu
->get_builder ()->get_global_symbols ()
20473 : cu
->list_in_scope
);
20475 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
20477 else if (!die_is_declaration (die
, cu
))
20479 /* Use the default LOC_OPTIMIZED_OUT class. */
20480 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
20482 list_to_add
= cu
->list_in_scope
;
20486 case DW_TAG_formal_parameter
:
20488 /* If we are inside a function, mark this as an argument. If
20489 not, we might be looking at an argument to an inlined function
20490 when we do not have enough information to show inlined frames;
20491 pretend it's a local variable in that case so that the user can
20493 struct context_stack
*curr
20494 = cu
->get_builder ()->get_current_context_stack ();
20495 if (curr
!= nullptr && curr
->name
!= nullptr)
20496 SYMBOL_IS_ARGUMENT (sym
) = 1;
20497 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20498 if (attr
!= nullptr)
20500 var_decode_location (attr
, sym
, cu
);
20502 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20503 if (attr
!= nullptr)
20505 dwarf2_const_value (attr
, sym
, cu
);
20508 list_to_add
= cu
->list_in_scope
;
20511 case DW_TAG_unspecified_parameters
:
20512 /* From varargs functions; gdb doesn't seem to have any
20513 interest in this information, so just ignore it for now.
20516 case DW_TAG_template_type_param
:
20518 /* Fall through. */
20519 case DW_TAG_class_type
:
20520 case DW_TAG_interface_type
:
20521 case DW_TAG_structure_type
:
20522 case DW_TAG_union_type
:
20523 case DW_TAG_set_type
:
20524 case DW_TAG_enumeration_type
:
20525 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20526 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
20529 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
20530 really ever be static objects: otherwise, if you try
20531 to, say, break of a class's method and you're in a file
20532 which doesn't mention that class, it won't work unless
20533 the check for all static symbols in lookup_symbol_aux
20534 saves you. See the OtherFileClass tests in
20535 gdb.c++/namespace.exp. */
20539 buildsym_compunit
*builder
= cu
->get_builder ();
20541 = (cu
->list_in_scope
== builder
->get_file_symbols ()
20542 && cu
->language
== language_cplus
20543 ? builder
->get_global_symbols ()
20544 : cu
->list_in_scope
);
20546 /* The semantics of C++ state that "struct foo {
20547 ... }" also defines a typedef for "foo". */
20548 if (cu
->language
== language_cplus
20549 || cu
->language
== language_ada
20550 || cu
->language
== language_d
20551 || cu
->language
== language_rust
)
20553 /* The symbol's name is already allocated along
20554 with this objfile, so we don't need to
20555 duplicate it for the type. */
20556 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
20557 TYPE_NAME (SYMBOL_TYPE (sym
)) = sym
->search_name ();
20562 case DW_TAG_typedef
:
20563 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20564 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20565 list_to_add
= cu
->list_in_scope
;
20567 case DW_TAG_base_type
:
20568 case DW_TAG_subrange_type
:
20569 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20570 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20571 list_to_add
= cu
->list_in_scope
;
20573 case DW_TAG_enumerator
:
20574 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20575 if (attr
!= nullptr)
20577 dwarf2_const_value (attr
, sym
, cu
);
20580 /* NOTE: carlton/2003-11-10: See comment above in the
20581 DW_TAG_class_type, etc. block. */
20584 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
20585 && cu
->language
== language_cplus
20586 ? cu
->get_builder ()->get_global_symbols ()
20587 : cu
->list_in_scope
);
20590 case DW_TAG_imported_declaration
:
20591 case DW_TAG_namespace
:
20592 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20593 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20595 case DW_TAG_module
:
20596 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20597 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
20598 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20600 case DW_TAG_common_block
:
20601 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
20602 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
20603 add_symbol_to_list (sym
, cu
->list_in_scope
);
20606 /* Not a tag we recognize. Hopefully we aren't processing
20607 trash data, but since we must specifically ignore things
20608 we don't recognize, there is nothing else we should do at
20610 complaint (_("unsupported tag: '%s'"),
20611 dwarf_tag_name (die
->tag
));
20617 sym
->hash_next
= objfile
->template_symbols
;
20618 objfile
->template_symbols
= sym
;
20619 list_to_add
= NULL
;
20622 if (list_to_add
!= NULL
)
20623 add_symbol_to_list (sym
, list_to_add
);
20625 /* For the benefit of old versions of GCC, check for anonymous
20626 namespaces based on the demangled name. */
20627 if (!cu
->processing_has_namespace_info
20628 && cu
->language
== language_cplus
)
20629 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
20634 /* Given an attr with a DW_FORM_dataN value in host byte order,
20635 zero-extend it as appropriate for the symbol's type. The DWARF
20636 standard (v4) is not entirely clear about the meaning of using
20637 DW_FORM_dataN for a constant with a signed type, where the type is
20638 wider than the data. The conclusion of a discussion on the DWARF
20639 list was that this is unspecified. We choose to always zero-extend
20640 because that is the interpretation long in use by GCC. */
20643 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
20644 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
20646 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20647 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
20648 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
20649 LONGEST l
= DW_UNSND (attr
);
20651 if (bits
< sizeof (*value
) * 8)
20653 l
&= ((LONGEST
) 1 << bits
) - 1;
20656 else if (bits
== sizeof (*value
) * 8)
20660 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
20661 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
20668 /* Read a constant value from an attribute. Either set *VALUE, or if
20669 the value does not fit in *VALUE, set *BYTES - either already
20670 allocated on the objfile obstack, or newly allocated on OBSTACK,
20671 or, set *BATON, if we translated the constant to a location
20675 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
20676 const char *name
, struct obstack
*obstack
,
20677 struct dwarf2_cu
*cu
,
20678 LONGEST
*value
, const gdb_byte
**bytes
,
20679 struct dwarf2_locexpr_baton
**baton
)
20681 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20682 struct comp_unit_head
*cu_header
= &cu
->header
;
20683 struct dwarf_block
*blk
;
20684 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
20685 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
20691 switch (attr
->form
)
20694 case DW_FORM_addrx
:
20695 case DW_FORM_GNU_addr_index
:
20699 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
20700 dwarf2_const_value_length_mismatch_complaint (name
,
20701 cu_header
->addr_size
,
20702 TYPE_LENGTH (type
));
20703 /* Symbols of this form are reasonably rare, so we just
20704 piggyback on the existing location code rather than writing
20705 a new implementation of symbol_computed_ops. */
20706 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
20707 (*baton
)->per_cu
= cu
->per_cu
;
20708 gdb_assert ((*baton
)->per_cu
);
20710 (*baton
)->size
= 2 + cu_header
->addr_size
;
20711 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
20712 (*baton
)->data
= data
;
20714 data
[0] = DW_OP_addr
;
20715 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
20716 byte_order
, DW_ADDR (attr
));
20717 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
20720 case DW_FORM_string
:
20723 case DW_FORM_GNU_str_index
:
20724 case DW_FORM_GNU_strp_alt
:
20725 /* DW_STRING is already allocated on the objfile obstack, point
20727 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
20729 case DW_FORM_block1
:
20730 case DW_FORM_block2
:
20731 case DW_FORM_block4
:
20732 case DW_FORM_block
:
20733 case DW_FORM_exprloc
:
20734 case DW_FORM_data16
:
20735 blk
= DW_BLOCK (attr
);
20736 if (TYPE_LENGTH (type
) != blk
->size
)
20737 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
20738 TYPE_LENGTH (type
));
20739 *bytes
= blk
->data
;
20742 /* The DW_AT_const_value attributes are supposed to carry the
20743 symbol's value "represented as it would be on the target
20744 architecture." By the time we get here, it's already been
20745 converted to host endianness, so we just need to sign- or
20746 zero-extend it as appropriate. */
20747 case DW_FORM_data1
:
20748 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
20750 case DW_FORM_data2
:
20751 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
20753 case DW_FORM_data4
:
20754 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
20756 case DW_FORM_data8
:
20757 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
20760 case DW_FORM_sdata
:
20761 case DW_FORM_implicit_const
:
20762 *value
= DW_SND (attr
);
20765 case DW_FORM_udata
:
20766 *value
= DW_UNSND (attr
);
20770 complaint (_("unsupported const value attribute form: '%s'"),
20771 dwarf_form_name (attr
->form
));
20778 /* Copy constant value from an attribute to a symbol. */
20781 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
20782 struct dwarf2_cu
*cu
)
20784 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20786 const gdb_byte
*bytes
;
20787 struct dwarf2_locexpr_baton
*baton
;
20789 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
20790 sym
->print_name (),
20791 &objfile
->objfile_obstack
, cu
,
20792 &value
, &bytes
, &baton
);
20796 SYMBOL_LOCATION_BATON (sym
) = baton
;
20797 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
20799 else if (bytes
!= NULL
)
20801 SYMBOL_VALUE_BYTES (sym
) = bytes
;
20802 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
20806 SYMBOL_VALUE (sym
) = value
;
20807 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
20811 /* Return the type of the die in question using its DW_AT_type attribute. */
20813 static struct type
*
20814 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
20816 struct attribute
*type_attr
;
20818 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
20821 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20822 /* A missing DW_AT_type represents a void type. */
20823 return objfile_type (objfile
)->builtin_void
;
20826 return lookup_die_type (die
, type_attr
, cu
);
20829 /* True iff CU's producer generates GNAT Ada auxiliary information
20830 that allows to find parallel types through that information instead
20831 of having to do expensive parallel lookups by type name. */
20834 need_gnat_info (struct dwarf2_cu
*cu
)
20836 /* Assume that the Ada compiler was GNAT, which always produces
20837 the auxiliary information. */
20838 return (cu
->language
== language_ada
);
20841 /* Return the auxiliary type of the die in question using its
20842 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
20843 attribute is not present. */
20845 static struct type
*
20846 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
20848 struct attribute
*type_attr
;
20850 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
20854 return lookup_die_type (die
, type_attr
, cu
);
20857 /* If DIE has a descriptive_type attribute, then set the TYPE's
20858 descriptive type accordingly. */
20861 set_descriptive_type (struct type
*type
, struct die_info
*die
,
20862 struct dwarf2_cu
*cu
)
20864 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
20866 if (descriptive_type
)
20868 ALLOCATE_GNAT_AUX_TYPE (type
);
20869 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
20873 /* Return the containing type of the die in question using its
20874 DW_AT_containing_type attribute. */
20876 static struct type
*
20877 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
20879 struct attribute
*type_attr
;
20880 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20882 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
20884 error (_("Dwarf Error: Problem turning containing type into gdb type "
20885 "[in module %s]"), objfile_name (objfile
));
20887 return lookup_die_type (die
, type_attr
, cu
);
20890 /* Return an error marker type to use for the ill formed type in DIE/CU. */
20892 static struct type
*
20893 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
20895 struct dwarf2_per_objfile
*dwarf2_per_objfile
20896 = cu
->per_cu
->dwarf2_per_objfile
;
20897 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20900 std::string message
20901 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
20902 objfile_name (objfile
),
20903 sect_offset_str (cu
->header
.sect_off
),
20904 sect_offset_str (die
->sect_off
));
20905 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
20907 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
20910 /* Look up the type of DIE in CU using its type attribute ATTR.
20911 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
20912 DW_AT_containing_type.
20913 If there is no type substitute an error marker. */
20915 static struct type
*
20916 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
20917 struct dwarf2_cu
*cu
)
20919 struct dwarf2_per_objfile
*dwarf2_per_objfile
20920 = cu
->per_cu
->dwarf2_per_objfile
;
20921 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20922 struct type
*this_type
;
20924 gdb_assert (attr
->name
== DW_AT_type
20925 || attr
->name
== DW_AT_GNAT_descriptive_type
20926 || attr
->name
== DW_AT_containing_type
);
20928 /* First see if we have it cached. */
20930 if (attr
->form
== DW_FORM_GNU_ref_alt
)
20932 struct dwarf2_per_cu_data
*per_cu
;
20933 sect_offset sect_off
= attr
->get_ref_die_offset ();
20935 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
20936 dwarf2_per_objfile
);
20937 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
20939 else if (attr
->form_is_ref ())
20941 sect_offset sect_off
= attr
->get_ref_die_offset ();
20943 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
20945 else if (attr
->form
== DW_FORM_ref_sig8
)
20947 ULONGEST signature
= DW_SIGNATURE (attr
);
20949 return get_signatured_type (die
, signature
, cu
);
20953 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
20954 " at %s [in module %s]"),
20955 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
20956 objfile_name (objfile
));
20957 return build_error_marker_type (cu
, die
);
20960 /* If not cached we need to read it in. */
20962 if (this_type
== NULL
)
20964 struct die_info
*type_die
= NULL
;
20965 struct dwarf2_cu
*type_cu
= cu
;
20967 if (attr
->form_is_ref ())
20968 type_die
= follow_die_ref (die
, attr
, &type_cu
);
20969 if (type_die
== NULL
)
20970 return build_error_marker_type (cu
, die
);
20971 /* If we find the type now, it's probably because the type came
20972 from an inter-CU reference and the type's CU got expanded before
20974 this_type
= read_type_die (type_die
, type_cu
);
20977 /* If we still don't have a type use an error marker. */
20979 if (this_type
== NULL
)
20980 return build_error_marker_type (cu
, die
);
20985 /* Return the type in DIE, CU.
20986 Returns NULL for invalid types.
20988 This first does a lookup in die_type_hash,
20989 and only reads the die in if necessary.
20991 NOTE: This can be called when reading in partial or full symbols. */
20993 static struct type
*
20994 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
20996 struct type
*this_type
;
20998 this_type
= get_die_type (die
, cu
);
21002 return read_type_die_1 (die
, cu
);
21005 /* Read the type in DIE, CU.
21006 Returns NULL for invalid types. */
21008 static struct type
*
21009 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
21011 struct type
*this_type
= NULL
;
21015 case DW_TAG_class_type
:
21016 case DW_TAG_interface_type
:
21017 case DW_TAG_structure_type
:
21018 case DW_TAG_union_type
:
21019 this_type
= read_structure_type (die
, cu
);
21021 case DW_TAG_enumeration_type
:
21022 this_type
= read_enumeration_type (die
, cu
);
21024 case DW_TAG_subprogram
:
21025 case DW_TAG_subroutine_type
:
21026 case DW_TAG_inlined_subroutine
:
21027 this_type
= read_subroutine_type (die
, cu
);
21029 case DW_TAG_array_type
:
21030 this_type
= read_array_type (die
, cu
);
21032 case DW_TAG_set_type
:
21033 this_type
= read_set_type (die
, cu
);
21035 case DW_TAG_pointer_type
:
21036 this_type
= read_tag_pointer_type (die
, cu
);
21038 case DW_TAG_ptr_to_member_type
:
21039 this_type
= read_tag_ptr_to_member_type (die
, cu
);
21041 case DW_TAG_reference_type
:
21042 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
21044 case DW_TAG_rvalue_reference_type
:
21045 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
21047 case DW_TAG_const_type
:
21048 this_type
= read_tag_const_type (die
, cu
);
21050 case DW_TAG_volatile_type
:
21051 this_type
= read_tag_volatile_type (die
, cu
);
21053 case DW_TAG_restrict_type
:
21054 this_type
= read_tag_restrict_type (die
, cu
);
21056 case DW_TAG_string_type
:
21057 this_type
= read_tag_string_type (die
, cu
);
21059 case DW_TAG_typedef
:
21060 this_type
= read_typedef (die
, cu
);
21062 case DW_TAG_subrange_type
:
21063 this_type
= read_subrange_type (die
, cu
);
21065 case DW_TAG_base_type
:
21066 this_type
= read_base_type (die
, cu
);
21068 case DW_TAG_unspecified_type
:
21069 this_type
= read_unspecified_type (die
, cu
);
21071 case DW_TAG_namespace
:
21072 this_type
= read_namespace_type (die
, cu
);
21074 case DW_TAG_module
:
21075 this_type
= read_module_type (die
, cu
);
21077 case DW_TAG_atomic_type
:
21078 this_type
= read_tag_atomic_type (die
, cu
);
21081 complaint (_("unexpected tag in read_type_die: '%s'"),
21082 dwarf_tag_name (die
->tag
));
21089 /* See if we can figure out if the class lives in a namespace. We do
21090 this by looking for a member function; its demangled name will
21091 contain namespace info, if there is any.
21092 Return the computed name or NULL.
21093 Space for the result is allocated on the objfile's obstack.
21094 This is the full-die version of guess_partial_die_structure_name.
21095 In this case we know DIE has no useful parent. */
21097 static const char *
21098 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21100 struct die_info
*spec_die
;
21101 struct dwarf2_cu
*spec_cu
;
21102 struct die_info
*child
;
21103 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21106 spec_die
= die_specification (die
, &spec_cu
);
21107 if (spec_die
!= NULL
)
21113 for (child
= die
->child
;
21115 child
= child
->sibling
)
21117 if (child
->tag
== DW_TAG_subprogram
)
21119 const char *linkage_name
= dw2_linkage_name (child
, cu
);
21121 if (linkage_name
!= NULL
)
21123 gdb::unique_xmalloc_ptr
<char> actual_name
21124 (language_class_name_from_physname (cu
->language_defn
,
21126 const char *name
= NULL
;
21128 if (actual_name
!= NULL
)
21130 const char *die_name
= dwarf2_name (die
, cu
);
21132 if (die_name
!= NULL
21133 && strcmp (die_name
, actual_name
.get ()) != 0)
21135 /* Strip off the class name from the full name.
21136 We want the prefix. */
21137 int die_name_len
= strlen (die_name
);
21138 int actual_name_len
= strlen (actual_name
.get ());
21139 const char *ptr
= actual_name
.get ();
21141 /* Test for '::' as a sanity check. */
21142 if (actual_name_len
> die_name_len
+ 2
21143 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
21144 name
= obstack_strndup (
21145 &objfile
->per_bfd
->storage_obstack
,
21146 ptr
, actual_name_len
- die_name_len
- 2);
21157 /* GCC might emit a nameless typedef that has a linkage name. Determine the
21158 prefix part in such case. See
21159 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21161 static const char *
21162 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21164 struct attribute
*attr
;
21167 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
21168 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
21171 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
21174 attr
= dw2_linkage_name_attr (die
, cu
);
21175 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21178 /* dwarf2_name had to be already called. */
21179 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
21181 /* Strip the base name, keep any leading namespaces/classes. */
21182 base
= strrchr (DW_STRING (attr
), ':');
21183 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
21186 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21187 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
21189 &base
[-1] - DW_STRING (attr
));
21192 /* Return the name of the namespace/class that DIE is defined within,
21193 or "" if we can't tell. The caller should not xfree the result.
21195 For example, if we're within the method foo() in the following
21205 then determine_prefix on foo's die will return "N::C". */
21207 static const char *
21208 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21210 struct dwarf2_per_objfile
*dwarf2_per_objfile
21211 = cu
->per_cu
->dwarf2_per_objfile
;
21212 struct die_info
*parent
, *spec_die
;
21213 struct dwarf2_cu
*spec_cu
;
21214 struct type
*parent_type
;
21215 const char *retval
;
21217 if (cu
->language
!= language_cplus
21218 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
21219 && cu
->language
!= language_rust
)
21222 retval
= anonymous_struct_prefix (die
, cu
);
21226 /* We have to be careful in the presence of DW_AT_specification.
21227 For example, with GCC 3.4, given the code
21231 // Definition of N::foo.
21235 then we'll have a tree of DIEs like this:
21237 1: DW_TAG_compile_unit
21238 2: DW_TAG_namespace // N
21239 3: DW_TAG_subprogram // declaration of N::foo
21240 4: DW_TAG_subprogram // definition of N::foo
21241 DW_AT_specification // refers to die #3
21243 Thus, when processing die #4, we have to pretend that we're in
21244 the context of its DW_AT_specification, namely the contex of die
21247 spec_die
= die_specification (die
, &spec_cu
);
21248 if (spec_die
== NULL
)
21249 parent
= die
->parent
;
21252 parent
= spec_die
->parent
;
21256 if (parent
== NULL
)
21258 else if (parent
->building_fullname
)
21261 const char *parent_name
;
21263 /* It has been seen on RealView 2.2 built binaries,
21264 DW_TAG_template_type_param types actually _defined_ as
21265 children of the parent class:
21268 template class <class Enum> Class{};
21269 Class<enum E> class_e;
21271 1: DW_TAG_class_type (Class)
21272 2: DW_TAG_enumeration_type (E)
21273 3: DW_TAG_enumerator (enum1:0)
21274 3: DW_TAG_enumerator (enum2:1)
21276 2: DW_TAG_template_type_param
21277 DW_AT_type DW_FORM_ref_udata (E)
21279 Besides being broken debug info, it can put GDB into an
21280 infinite loop. Consider:
21282 When we're building the full name for Class<E>, we'll start
21283 at Class, and go look over its template type parameters,
21284 finding E. We'll then try to build the full name of E, and
21285 reach here. We're now trying to build the full name of E,
21286 and look over the parent DIE for containing scope. In the
21287 broken case, if we followed the parent DIE of E, we'd again
21288 find Class, and once again go look at its template type
21289 arguments, etc., etc. Simply don't consider such parent die
21290 as source-level parent of this die (it can't be, the language
21291 doesn't allow it), and break the loop here. */
21292 name
= dwarf2_name (die
, cu
);
21293 parent_name
= dwarf2_name (parent
, cu
);
21294 complaint (_("template param type '%s' defined within parent '%s'"),
21295 name
? name
: "<unknown>",
21296 parent_name
? parent_name
: "<unknown>");
21300 switch (parent
->tag
)
21302 case DW_TAG_namespace
:
21303 parent_type
= read_type_die (parent
, cu
);
21304 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
21305 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
21306 Work around this problem here. */
21307 if (cu
->language
== language_cplus
21308 && strcmp (TYPE_NAME (parent_type
), "::") == 0)
21310 /* We give a name to even anonymous namespaces. */
21311 return TYPE_NAME (parent_type
);
21312 case DW_TAG_class_type
:
21313 case DW_TAG_interface_type
:
21314 case DW_TAG_structure_type
:
21315 case DW_TAG_union_type
:
21316 case DW_TAG_module
:
21317 parent_type
= read_type_die (parent
, cu
);
21318 if (TYPE_NAME (parent_type
) != NULL
)
21319 return TYPE_NAME (parent_type
);
21321 /* An anonymous structure is only allowed non-static data
21322 members; no typedefs, no member functions, et cetera.
21323 So it does not need a prefix. */
21325 case DW_TAG_compile_unit
:
21326 case DW_TAG_partial_unit
:
21327 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
21328 if (cu
->language
== language_cplus
21329 && !dwarf2_per_objfile
->types
.empty ()
21330 && die
->child
!= NULL
21331 && (die
->tag
== DW_TAG_class_type
21332 || die
->tag
== DW_TAG_structure_type
21333 || die
->tag
== DW_TAG_union_type
))
21335 const char *name
= guess_full_die_structure_name (die
, cu
);
21340 case DW_TAG_subprogram
:
21341 /* Nested subroutines in Fortran get a prefix with the name
21342 of the parent's subroutine. */
21343 if (cu
->language
== language_fortran
)
21345 if ((die
->tag
== DW_TAG_subprogram
)
21346 && (dwarf2_name (parent
, cu
) != NULL
))
21347 return dwarf2_name (parent
, cu
);
21349 return determine_prefix (parent
, cu
);
21350 case DW_TAG_enumeration_type
:
21351 parent_type
= read_type_die (parent
, cu
);
21352 if (TYPE_DECLARED_CLASS (parent_type
))
21354 if (TYPE_NAME (parent_type
) != NULL
)
21355 return TYPE_NAME (parent_type
);
21358 /* Fall through. */
21360 return determine_prefix (parent
, cu
);
21364 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
21365 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
21366 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
21367 an obconcat, otherwise allocate storage for the result. The CU argument is
21368 used to determine the language and hence, the appropriate separator. */
21370 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
21373 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
21374 int physname
, struct dwarf2_cu
*cu
)
21376 const char *lead
= "";
21379 if (suffix
== NULL
|| suffix
[0] == '\0'
21380 || prefix
== NULL
|| prefix
[0] == '\0')
21382 else if (cu
->language
== language_d
)
21384 /* For D, the 'main' function could be defined in any module, but it
21385 should never be prefixed. */
21386 if (strcmp (suffix
, "D main") == 0)
21394 else if (cu
->language
== language_fortran
&& physname
)
21396 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
21397 DW_AT_MIPS_linkage_name is preferred and used instead. */
21405 if (prefix
== NULL
)
21407 if (suffix
== NULL
)
21414 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
21416 strcpy (retval
, lead
);
21417 strcat (retval
, prefix
);
21418 strcat (retval
, sep
);
21419 strcat (retval
, suffix
);
21424 /* We have an obstack. */
21425 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
21429 /* Get name of a die, return NULL if not found. */
21431 static const char *
21432 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
21433 struct objfile
*objfile
)
21435 if (name
&& cu
->language
== language_cplus
)
21437 std::string canon_name
= cp_canonicalize_string (name
);
21439 if (!canon_name
.empty ())
21441 if (canon_name
!= name
)
21442 name
= objfile
->intern (canon_name
);
21449 /* Get name of a die, return NULL if not found.
21450 Anonymous namespaces are converted to their magic string. */
21452 static const char *
21453 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21455 struct attribute
*attr
;
21456 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21458 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
21459 if ((!attr
|| !DW_STRING (attr
))
21460 && die
->tag
!= DW_TAG_namespace
21461 && die
->tag
!= DW_TAG_class_type
21462 && die
->tag
!= DW_TAG_interface_type
21463 && die
->tag
!= DW_TAG_structure_type
21464 && die
->tag
!= DW_TAG_union_type
)
21469 case DW_TAG_compile_unit
:
21470 case DW_TAG_partial_unit
:
21471 /* Compilation units have a DW_AT_name that is a filename, not
21472 a source language identifier. */
21473 case DW_TAG_enumeration_type
:
21474 case DW_TAG_enumerator
:
21475 /* These tags always have simple identifiers already; no need
21476 to canonicalize them. */
21477 return DW_STRING (attr
);
21479 case DW_TAG_namespace
:
21480 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
21481 return DW_STRING (attr
);
21482 return CP_ANONYMOUS_NAMESPACE_STR
;
21484 case DW_TAG_class_type
:
21485 case DW_TAG_interface_type
:
21486 case DW_TAG_structure_type
:
21487 case DW_TAG_union_type
:
21488 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
21489 structures or unions. These were of the form "._%d" in GCC 4.1,
21490 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
21491 and GCC 4.4. We work around this problem by ignoring these. */
21492 if (attr
&& DW_STRING (attr
)
21493 && (startswith (DW_STRING (attr
), "._")
21494 || startswith (DW_STRING (attr
), "<anonymous")))
21497 /* GCC might emit a nameless typedef that has a linkage name. See
21498 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21499 if (!attr
|| DW_STRING (attr
) == NULL
)
21501 attr
= dw2_linkage_name_attr (die
, cu
);
21502 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21505 /* Avoid demangling DW_STRING (attr) the second time on a second
21506 call for the same DIE. */
21507 if (!DW_STRING_IS_CANONICAL (attr
))
21509 gdb::unique_xmalloc_ptr
<char> demangled
21510 (gdb_demangle (DW_STRING (attr
), DMGL_TYPES
));
21511 if (demangled
== nullptr)
21514 DW_STRING (attr
) = objfile
->intern (demangled
.get ());
21515 DW_STRING_IS_CANONICAL (attr
) = 1;
21518 /* Strip any leading namespaces/classes, keep only the base name.
21519 DW_AT_name for named DIEs does not contain the prefixes. */
21520 const char *base
= strrchr (DW_STRING (attr
), ':');
21521 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
21524 return DW_STRING (attr
);
21532 if (!DW_STRING_IS_CANONICAL (attr
))
21534 DW_STRING (attr
) = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
21536 DW_STRING_IS_CANONICAL (attr
) = 1;
21538 return DW_STRING (attr
);
21541 /* Return the die that this die in an extension of, or NULL if there
21542 is none. *EXT_CU is the CU containing DIE on input, and the CU
21543 containing the return value on output. */
21545 static struct die_info
*
21546 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
21548 struct attribute
*attr
;
21550 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
21554 return follow_die_ref (die
, attr
, ext_cu
);
21558 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
21562 print_spaces (indent
, f
);
21563 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
21564 dwarf_tag_name (die
->tag
), die
->abbrev
,
21565 sect_offset_str (die
->sect_off
));
21567 if (die
->parent
!= NULL
)
21569 print_spaces (indent
, f
);
21570 fprintf_unfiltered (f
, " parent at offset: %s\n",
21571 sect_offset_str (die
->parent
->sect_off
));
21574 print_spaces (indent
, f
);
21575 fprintf_unfiltered (f
, " has children: %s\n",
21576 dwarf_bool_name (die
->child
!= NULL
));
21578 print_spaces (indent
, f
);
21579 fprintf_unfiltered (f
, " attributes:\n");
21581 for (i
= 0; i
< die
->num_attrs
; ++i
)
21583 print_spaces (indent
, f
);
21584 fprintf_unfiltered (f
, " %s (%s) ",
21585 dwarf_attr_name (die
->attrs
[i
].name
),
21586 dwarf_form_name (die
->attrs
[i
].form
));
21588 switch (die
->attrs
[i
].form
)
21591 case DW_FORM_addrx
:
21592 case DW_FORM_GNU_addr_index
:
21593 fprintf_unfiltered (f
, "address: ");
21594 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
21596 case DW_FORM_block2
:
21597 case DW_FORM_block4
:
21598 case DW_FORM_block
:
21599 case DW_FORM_block1
:
21600 fprintf_unfiltered (f
, "block: size %s",
21601 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
21603 case DW_FORM_exprloc
:
21604 fprintf_unfiltered (f
, "expression: size %s",
21605 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
21607 case DW_FORM_data16
:
21608 fprintf_unfiltered (f
, "constant of 16 bytes");
21610 case DW_FORM_ref_addr
:
21611 fprintf_unfiltered (f
, "ref address: ");
21612 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
21614 case DW_FORM_GNU_ref_alt
:
21615 fprintf_unfiltered (f
, "alt ref address: ");
21616 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
21622 case DW_FORM_ref_udata
:
21623 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
21624 (long) (DW_UNSND (&die
->attrs
[i
])));
21626 case DW_FORM_data1
:
21627 case DW_FORM_data2
:
21628 case DW_FORM_data4
:
21629 case DW_FORM_data8
:
21630 case DW_FORM_udata
:
21631 case DW_FORM_sdata
:
21632 fprintf_unfiltered (f
, "constant: %s",
21633 pulongest (DW_UNSND (&die
->attrs
[i
])));
21635 case DW_FORM_sec_offset
:
21636 fprintf_unfiltered (f
, "section offset: %s",
21637 pulongest (DW_UNSND (&die
->attrs
[i
])));
21639 case DW_FORM_ref_sig8
:
21640 fprintf_unfiltered (f
, "signature: %s",
21641 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
21643 case DW_FORM_string
:
21645 case DW_FORM_line_strp
:
21647 case DW_FORM_GNU_str_index
:
21648 case DW_FORM_GNU_strp_alt
:
21649 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
21650 DW_STRING (&die
->attrs
[i
])
21651 ? DW_STRING (&die
->attrs
[i
]) : "",
21652 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
21655 if (DW_UNSND (&die
->attrs
[i
]))
21656 fprintf_unfiltered (f
, "flag: TRUE");
21658 fprintf_unfiltered (f
, "flag: FALSE");
21660 case DW_FORM_flag_present
:
21661 fprintf_unfiltered (f
, "flag: TRUE");
21663 case DW_FORM_indirect
:
21664 /* The reader will have reduced the indirect form to
21665 the "base form" so this form should not occur. */
21666 fprintf_unfiltered (f
,
21667 "unexpected attribute form: DW_FORM_indirect");
21669 case DW_FORM_implicit_const
:
21670 fprintf_unfiltered (f
, "constant: %s",
21671 plongest (DW_SND (&die
->attrs
[i
])));
21674 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
21675 die
->attrs
[i
].form
);
21678 fprintf_unfiltered (f
, "\n");
21683 dump_die_for_error (struct die_info
*die
)
21685 dump_die_shallow (gdb_stderr
, 0, die
);
21689 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
21691 int indent
= level
* 4;
21693 gdb_assert (die
!= NULL
);
21695 if (level
>= max_level
)
21698 dump_die_shallow (f
, indent
, die
);
21700 if (die
->child
!= NULL
)
21702 print_spaces (indent
, f
);
21703 fprintf_unfiltered (f
, " Children:");
21704 if (level
+ 1 < max_level
)
21706 fprintf_unfiltered (f
, "\n");
21707 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
21711 fprintf_unfiltered (f
,
21712 " [not printed, max nesting level reached]\n");
21716 if (die
->sibling
!= NULL
&& level
> 0)
21718 dump_die_1 (f
, level
, max_level
, die
->sibling
);
21722 /* This is called from the pdie macro in gdbinit.in.
21723 It's not static so gcc will keep a copy callable from gdb. */
21726 dump_die (struct die_info
*die
, int max_level
)
21728 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
21732 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
21736 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
21737 to_underlying (die
->sect_off
),
21743 /* Follow reference or signature attribute ATTR of SRC_DIE.
21744 On entry *REF_CU is the CU of SRC_DIE.
21745 On exit *REF_CU is the CU of the result. */
21747 static struct die_info
*
21748 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
21749 struct dwarf2_cu
**ref_cu
)
21751 struct die_info
*die
;
21753 if (attr
->form_is_ref ())
21754 die
= follow_die_ref (src_die
, attr
, ref_cu
);
21755 else if (attr
->form
== DW_FORM_ref_sig8
)
21756 die
= follow_die_sig (src_die
, attr
, ref_cu
);
21759 dump_die_for_error (src_die
);
21760 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
21761 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
21767 /* Follow reference OFFSET.
21768 On entry *REF_CU is the CU of the source die referencing OFFSET.
21769 On exit *REF_CU is the CU of the result.
21770 Returns NULL if OFFSET is invalid. */
21772 static struct die_info
*
21773 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
21774 struct dwarf2_cu
**ref_cu
)
21776 struct die_info temp_die
;
21777 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
21778 struct dwarf2_per_objfile
*dwarf2_per_objfile
21779 = cu
->per_cu
->dwarf2_per_objfile
;
21781 gdb_assert (cu
->per_cu
!= NULL
);
21785 if (cu
->per_cu
->is_debug_types
)
21787 /* .debug_types CUs cannot reference anything outside their CU.
21788 If they need to, they have to reference a signatured type via
21789 DW_FORM_ref_sig8. */
21790 if (!cu
->header
.offset_in_cu_p (sect_off
))
21793 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
21794 || !cu
->header
.offset_in_cu_p (sect_off
))
21796 struct dwarf2_per_cu_data
*per_cu
;
21798 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
21799 dwarf2_per_objfile
);
21801 /* If necessary, add it to the queue and load its DIEs. */
21802 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
21803 load_full_comp_unit (per_cu
, false, cu
->language
);
21805 target_cu
= per_cu
->cu
;
21807 else if (cu
->dies
== NULL
)
21809 /* We're loading full DIEs during partial symbol reading. */
21810 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
21811 load_full_comp_unit (cu
->per_cu
, false, language_minimal
);
21814 *ref_cu
= target_cu
;
21815 temp_die
.sect_off
= sect_off
;
21817 if (target_cu
!= cu
)
21818 target_cu
->ancestor
= cu
;
21820 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
21822 to_underlying (sect_off
));
21825 /* Follow reference attribute ATTR of SRC_DIE.
21826 On entry *REF_CU is the CU of SRC_DIE.
21827 On exit *REF_CU is the CU of the result. */
21829 static struct die_info
*
21830 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
21831 struct dwarf2_cu
**ref_cu
)
21833 sect_offset sect_off
= attr
->get_ref_die_offset ();
21834 struct dwarf2_cu
*cu
= *ref_cu
;
21835 struct die_info
*die
;
21837 die
= follow_die_offset (sect_off
,
21838 (attr
->form
== DW_FORM_GNU_ref_alt
21839 || cu
->per_cu
->is_dwz
),
21842 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
21843 "at %s [in module %s]"),
21844 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
21845 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
21852 struct dwarf2_locexpr_baton
21853 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
21854 dwarf2_per_cu_data
*per_cu
,
21855 CORE_ADDR (*get_frame_pc
) (void *baton
),
21856 void *baton
, bool resolve_abstract_p
)
21858 struct dwarf2_cu
*cu
;
21859 struct die_info
*die
;
21860 struct attribute
*attr
;
21861 struct dwarf2_locexpr_baton retval
;
21862 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
21863 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21865 if (per_cu
->cu
== NULL
)
21866 load_cu (per_cu
, false);
21870 /* We shouldn't get here for a dummy CU, but don't crash on the user.
21871 Instead just throw an error, not much else we can do. */
21872 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
21873 sect_offset_str (sect_off
), objfile_name (objfile
));
21876 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
21878 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
21879 sect_offset_str (sect_off
), objfile_name (objfile
));
21881 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21882 if (!attr
&& resolve_abstract_p
21883 && (dwarf2_per_objfile
->abstract_to_concrete
.find (die
->sect_off
)
21884 != dwarf2_per_objfile
->abstract_to_concrete
.end ()))
21886 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
21887 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
21888 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21890 for (const auto &cand_off
21891 : dwarf2_per_objfile
->abstract_to_concrete
[die
->sect_off
])
21893 struct dwarf2_cu
*cand_cu
= cu
;
21894 struct die_info
*cand
21895 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
21898 || cand
->parent
->tag
!= DW_TAG_subprogram
)
21901 CORE_ADDR pc_low
, pc_high
;
21902 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
21903 if (pc_low
== ((CORE_ADDR
) -1))
21905 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
21906 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
21907 if (!(pc_low
<= pc
&& pc
< pc_high
))
21911 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21918 /* DWARF: "If there is no such attribute, then there is no effect.".
21919 DATA is ignored if SIZE is 0. */
21921 retval
.data
= NULL
;
21924 else if (attr
->form_is_section_offset ())
21926 struct dwarf2_loclist_baton loclist_baton
;
21927 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
21930 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
21932 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
21934 retval
.size
= size
;
21938 if (!attr
->form_is_block ())
21939 error (_("Dwarf Error: DIE at %s referenced in module %s "
21940 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
21941 sect_offset_str (sect_off
), objfile_name (objfile
));
21943 retval
.data
= DW_BLOCK (attr
)->data
;
21944 retval
.size
= DW_BLOCK (attr
)->size
;
21946 retval
.per_cu
= cu
->per_cu
;
21948 age_cached_comp_units (dwarf2_per_objfile
);
21955 struct dwarf2_locexpr_baton
21956 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
21957 dwarf2_per_cu_data
*per_cu
,
21958 CORE_ADDR (*get_frame_pc
) (void *baton
),
21961 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
21963 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
21966 /* Write a constant of a given type as target-ordered bytes into
21969 static const gdb_byte
*
21970 write_constant_as_bytes (struct obstack
*obstack
,
21971 enum bfd_endian byte_order
,
21978 *len
= TYPE_LENGTH (type
);
21979 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
21980 store_unsigned_integer (result
, *len
, byte_order
, value
);
21988 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
21989 dwarf2_per_cu_data
*per_cu
,
21993 struct dwarf2_cu
*cu
;
21994 struct die_info
*die
;
21995 struct attribute
*attr
;
21996 const gdb_byte
*result
= NULL
;
21999 enum bfd_endian byte_order
;
22000 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
22002 if (per_cu
->cu
== NULL
)
22003 load_cu (per_cu
, false);
22007 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22008 Instead just throw an error, not much else we can do. */
22009 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22010 sect_offset_str (sect_off
), objfile_name (objfile
));
22013 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22015 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22016 sect_offset_str (sect_off
), objfile_name (objfile
));
22018 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22022 byte_order
= (bfd_big_endian (objfile
->obfd
)
22023 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22025 switch (attr
->form
)
22028 case DW_FORM_addrx
:
22029 case DW_FORM_GNU_addr_index
:
22033 *len
= cu
->header
.addr_size
;
22034 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22035 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
22039 case DW_FORM_string
:
22042 case DW_FORM_GNU_str_index
:
22043 case DW_FORM_GNU_strp_alt
:
22044 /* DW_STRING is already allocated on the objfile obstack, point
22046 result
= (const gdb_byte
*) DW_STRING (attr
);
22047 *len
= strlen (DW_STRING (attr
));
22049 case DW_FORM_block1
:
22050 case DW_FORM_block2
:
22051 case DW_FORM_block4
:
22052 case DW_FORM_block
:
22053 case DW_FORM_exprloc
:
22054 case DW_FORM_data16
:
22055 result
= DW_BLOCK (attr
)->data
;
22056 *len
= DW_BLOCK (attr
)->size
;
22059 /* The DW_AT_const_value attributes are supposed to carry the
22060 symbol's value "represented as it would be on the target
22061 architecture." By the time we get here, it's already been
22062 converted to host endianness, so we just need to sign- or
22063 zero-extend it as appropriate. */
22064 case DW_FORM_data1
:
22065 type
= die_type (die
, cu
);
22066 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
22067 if (result
== NULL
)
22068 result
= write_constant_as_bytes (obstack
, byte_order
,
22071 case DW_FORM_data2
:
22072 type
= die_type (die
, cu
);
22073 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
22074 if (result
== NULL
)
22075 result
= write_constant_as_bytes (obstack
, byte_order
,
22078 case DW_FORM_data4
:
22079 type
= die_type (die
, cu
);
22080 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
22081 if (result
== NULL
)
22082 result
= write_constant_as_bytes (obstack
, byte_order
,
22085 case DW_FORM_data8
:
22086 type
= die_type (die
, cu
);
22087 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
22088 if (result
== NULL
)
22089 result
= write_constant_as_bytes (obstack
, byte_order
,
22093 case DW_FORM_sdata
:
22094 case DW_FORM_implicit_const
:
22095 type
= die_type (die
, cu
);
22096 result
= write_constant_as_bytes (obstack
, byte_order
,
22097 type
, DW_SND (attr
), len
);
22100 case DW_FORM_udata
:
22101 type
= die_type (die
, cu
);
22102 result
= write_constant_as_bytes (obstack
, byte_order
,
22103 type
, DW_UNSND (attr
), len
);
22107 complaint (_("unsupported const value attribute form: '%s'"),
22108 dwarf_form_name (attr
->form
));
22118 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
22119 dwarf2_per_cu_data
*per_cu
)
22121 struct dwarf2_cu
*cu
;
22122 struct die_info
*die
;
22124 if (per_cu
->cu
== NULL
)
22125 load_cu (per_cu
, false);
22130 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22134 return die_type (die
, cu
);
22140 dwarf2_get_die_type (cu_offset die_offset
,
22141 struct dwarf2_per_cu_data
*per_cu
)
22143 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
22144 return get_die_type_at_offset (die_offset_sect
, per_cu
);
22147 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
22148 On entry *REF_CU is the CU of SRC_DIE.
22149 On exit *REF_CU is the CU of the result.
22150 Returns NULL if the referenced DIE isn't found. */
22152 static struct die_info
*
22153 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
22154 struct dwarf2_cu
**ref_cu
)
22156 struct die_info temp_die
;
22157 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
22158 struct die_info
*die
;
22160 /* While it might be nice to assert sig_type->type == NULL here,
22161 we can get here for DW_AT_imported_declaration where we need
22162 the DIE not the type. */
22164 /* If necessary, add it to the queue and load its DIEs. */
22166 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
22167 read_signatured_type (sig_type
);
22169 sig_cu
= sig_type
->per_cu
.cu
;
22170 gdb_assert (sig_cu
!= NULL
);
22171 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
22172 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
22173 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
22174 to_underlying (temp_die
.sect_off
));
22177 struct dwarf2_per_objfile
*dwarf2_per_objfile
22178 = (*ref_cu
)->per_cu
->dwarf2_per_objfile
;
22180 /* For .gdb_index version 7 keep track of included TUs.
22181 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
22182 if (dwarf2_per_objfile
->index_table
!= NULL
22183 && dwarf2_per_objfile
->index_table
->version
<= 7)
22185 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
22190 sig_cu
->ancestor
= cu
;
22198 /* Follow signatured type referenced by ATTR in SRC_DIE.
22199 On entry *REF_CU is the CU of SRC_DIE.
22200 On exit *REF_CU is the CU of the result.
22201 The result is the DIE of the type.
22202 If the referenced type cannot be found an error is thrown. */
22204 static struct die_info
*
22205 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22206 struct dwarf2_cu
**ref_cu
)
22208 ULONGEST signature
= DW_SIGNATURE (attr
);
22209 struct signatured_type
*sig_type
;
22210 struct die_info
*die
;
22212 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
22214 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
22215 /* sig_type will be NULL if the signatured type is missing from
22217 if (sig_type
== NULL
)
22219 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22220 " from DIE at %s [in module %s]"),
22221 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22222 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22225 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
22228 dump_die_for_error (src_die
);
22229 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22230 " from DIE at %s [in module %s]"),
22231 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22232 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22238 /* Get the type specified by SIGNATURE referenced in DIE/CU,
22239 reading in and processing the type unit if necessary. */
22241 static struct type
*
22242 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
22243 struct dwarf2_cu
*cu
)
22245 struct dwarf2_per_objfile
*dwarf2_per_objfile
22246 = cu
->per_cu
->dwarf2_per_objfile
;
22247 struct signatured_type
*sig_type
;
22248 struct dwarf2_cu
*type_cu
;
22249 struct die_info
*type_die
;
22252 sig_type
= lookup_signatured_type (cu
, signature
);
22253 /* sig_type will be NULL if the signatured type is missing from
22255 if (sig_type
== NULL
)
22257 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22258 " from DIE at %s [in module %s]"),
22259 hex_string (signature
), sect_offset_str (die
->sect_off
),
22260 objfile_name (dwarf2_per_objfile
->objfile
));
22261 return build_error_marker_type (cu
, die
);
22264 /* If we already know the type we're done. */
22265 if (sig_type
->type
!= NULL
)
22266 return sig_type
->type
;
22269 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
22270 if (type_die
!= NULL
)
22272 /* N.B. We need to call get_die_type to ensure only one type for this DIE
22273 is created. This is important, for example, because for c++ classes
22274 we need TYPE_NAME set which is only done by new_symbol. Blech. */
22275 type
= read_type_die (type_die
, type_cu
);
22278 complaint (_("Dwarf Error: Cannot build signatured type %s"
22279 " referenced from DIE at %s [in module %s]"),
22280 hex_string (signature
), sect_offset_str (die
->sect_off
),
22281 objfile_name (dwarf2_per_objfile
->objfile
));
22282 type
= build_error_marker_type (cu
, die
);
22287 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22288 " from DIE at %s [in module %s]"),
22289 hex_string (signature
), sect_offset_str (die
->sect_off
),
22290 objfile_name (dwarf2_per_objfile
->objfile
));
22291 type
= build_error_marker_type (cu
, die
);
22293 sig_type
->type
= type
;
22298 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
22299 reading in and processing the type unit if necessary. */
22301 static struct type
*
22302 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
22303 struct dwarf2_cu
*cu
) /* ARI: editCase function */
22305 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
22306 if (attr
->form_is_ref ())
22308 struct dwarf2_cu
*type_cu
= cu
;
22309 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
22311 return read_type_die (type_die
, type_cu
);
22313 else if (attr
->form
== DW_FORM_ref_sig8
)
22315 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
22319 struct dwarf2_per_objfile
*dwarf2_per_objfile
22320 = cu
->per_cu
->dwarf2_per_objfile
;
22322 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
22323 " at %s [in module %s]"),
22324 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
22325 objfile_name (dwarf2_per_objfile
->objfile
));
22326 return build_error_marker_type (cu
, die
);
22330 /* Load the DIEs associated with type unit PER_CU into memory. */
22333 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
22335 struct signatured_type
*sig_type
;
22337 /* Caller is responsible for ensuring type_unit_groups don't get here. */
22338 gdb_assert (! per_cu
->type_unit_group_p ());
22340 /* We have the per_cu, but we need the signatured_type.
22341 Fortunately this is an easy translation. */
22342 gdb_assert (per_cu
->is_debug_types
);
22343 sig_type
= (struct signatured_type
*) per_cu
;
22345 gdb_assert (per_cu
->cu
== NULL
);
22347 read_signatured_type (sig_type
);
22349 gdb_assert (per_cu
->cu
!= NULL
);
22352 /* Read in a signatured type and build its CU and DIEs.
22353 If the type is a stub for the real type in a DWO file,
22354 read in the real type from the DWO file as well. */
22357 read_signatured_type (struct signatured_type
*sig_type
)
22359 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
22361 gdb_assert (per_cu
->is_debug_types
);
22362 gdb_assert (per_cu
->cu
== NULL
);
22364 cutu_reader
reader (per_cu
, NULL
, 0, false);
22366 if (!reader
.dummy_p
)
22368 struct dwarf2_cu
*cu
= reader
.cu
;
22369 const gdb_byte
*info_ptr
= reader
.info_ptr
;
22371 gdb_assert (cu
->die_hash
== NULL
);
22373 htab_create_alloc_ex (cu
->header
.length
/ 12,
22377 &cu
->comp_unit_obstack
,
22378 hashtab_obstack_allocate
,
22379 dummy_obstack_deallocate
);
22381 if (reader
.comp_unit_die
->has_children
)
22382 reader
.comp_unit_die
->child
22383 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
22384 reader
.comp_unit_die
);
22385 cu
->dies
= reader
.comp_unit_die
;
22386 /* comp_unit_die is not stored in die_hash, no need. */
22388 /* We try not to read any attributes in this function, because
22389 not all CUs needed for references have been loaded yet, and
22390 symbol table processing isn't initialized. But we have to
22391 set the CU language, or we won't be able to build types
22392 correctly. Similarly, if we do not read the producer, we can
22393 not apply producer-specific interpretation. */
22394 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
22399 sig_type
->per_cu
.tu_read
= 1;
22402 /* Decode simple location descriptions.
22403 Given a pointer to a dwarf block that defines a location, compute
22404 the location and return the value.
22406 NOTE drow/2003-11-18: This function is called in two situations
22407 now: for the address of static or global variables (partial symbols
22408 only) and for offsets into structures which are expected to be
22409 (more or less) constant. The partial symbol case should go away,
22410 and only the constant case should remain. That will let this
22411 function complain more accurately. A few special modes are allowed
22412 without complaint for global variables (for instance, global
22413 register values and thread-local values).
22415 A location description containing no operations indicates that the
22416 object is optimized out. The return value is 0 for that case.
22417 FIXME drow/2003-11-16: No callers check for this case any more; soon all
22418 callers will only want a very basic result and this can become a
22421 Note that stack[0] is unused except as a default error return. */
22424 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
22426 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22428 size_t size
= blk
->size
;
22429 const gdb_byte
*data
= blk
->data
;
22430 CORE_ADDR stack
[64];
22432 unsigned int bytes_read
, unsnd
;
22438 stack
[++stacki
] = 0;
22477 stack
[++stacki
] = op
- DW_OP_lit0
;
22512 stack
[++stacki
] = op
- DW_OP_reg0
;
22514 dwarf2_complex_location_expr_complaint ();
22518 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
22520 stack
[++stacki
] = unsnd
;
22522 dwarf2_complex_location_expr_complaint ();
22526 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
22531 case DW_OP_const1u
:
22532 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
22536 case DW_OP_const1s
:
22537 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
22541 case DW_OP_const2u
:
22542 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
22546 case DW_OP_const2s
:
22547 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
22551 case DW_OP_const4u
:
22552 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
22556 case DW_OP_const4s
:
22557 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
22561 case DW_OP_const8u
:
22562 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
22567 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
22573 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
22578 stack
[stacki
+ 1] = stack
[stacki
];
22583 stack
[stacki
- 1] += stack
[stacki
];
22587 case DW_OP_plus_uconst
:
22588 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
22594 stack
[stacki
- 1] -= stack
[stacki
];
22599 /* If we're not the last op, then we definitely can't encode
22600 this using GDB's address_class enum. This is valid for partial
22601 global symbols, although the variable's address will be bogus
22604 dwarf2_complex_location_expr_complaint ();
22607 case DW_OP_GNU_push_tls_address
:
22608 case DW_OP_form_tls_address
:
22609 /* The top of the stack has the offset from the beginning
22610 of the thread control block at which the variable is located. */
22611 /* Nothing should follow this operator, so the top of stack would
22613 /* This is valid for partial global symbols, but the variable's
22614 address will be bogus in the psymtab. Make it always at least
22615 non-zero to not look as a variable garbage collected by linker
22616 which have DW_OP_addr 0. */
22618 dwarf2_complex_location_expr_complaint ();
22622 case DW_OP_GNU_uninit
:
22626 case DW_OP_GNU_addr_index
:
22627 case DW_OP_GNU_const_index
:
22628 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
22635 const char *name
= get_DW_OP_name (op
);
22638 complaint (_("unsupported stack op: '%s'"),
22641 complaint (_("unsupported stack op: '%02x'"),
22645 return (stack
[stacki
]);
22648 /* Enforce maximum stack depth of SIZE-1 to avoid writing
22649 outside of the allocated space. Also enforce minimum>0. */
22650 if (stacki
>= ARRAY_SIZE (stack
) - 1)
22652 complaint (_("location description stack overflow"));
22658 complaint (_("location description stack underflow"));
22662 return (stack
[stacki
]);
22665 /* memory allocation interface */
22667 static struct dwarf_block
*
22668 dwarf_alloc_block (struct dwarf2_cu
*cu
)
22670 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
22673 static struct die_info
*
22674 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
22676 struct die_info
*die
;
22677 size_t size
= sizeof (struct die_info
);
22680 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
22682 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
22683 memset (die
, 0, sizeof (struct die_info
));
22689 /* Macro support. */
22691 /* An overload of dwarf_decode_macros that finds the correct section
22692 and ensures it is read in before calling the other overload. */
22695 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
22696 int section_is_gnu
)
22698 struct dwarf2_per_objfile
*dwarf2_per_objfile
22699 = cu
->per_cu
->dwarf2_per_objfile
;
22700 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22701 const struct line_header
*lh
= cu
->line_header
;
22702 unsigned int offset_size
= cu
->header
.offset_size
;
22703 struct dwarf2_section_info
*section
;
22704 const char *section_name
;
22706 if (cu
->dwo_unit
!= nullptr)
22708 if (section_is_gnu
)
22710 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
22711 section_name
= ".debug_macro.dwo";
22715 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
22716 section_name
= ".debug_macinfo.dwo";
22721 if (section_is_gnu
)
22723 section
= &dwarf2_per_objfile
->macro
;
22724 section_name
= ".debug_macro";
22728 section
= &dwarf2_per_objfile
->macinfo
;
22729 section_name
= ".debug_macinfo";
22733 section
->read (objfile
);
22734 if (section
->buffer
== nullptr)
22736 complaint (_("missing %s section"), section_name
);
22740 buildsym_compunit
*builder
= cu
->get_builder ();
22742 dwarf_decode_macros (dwarf2_per_objfile
, builder
, section
, lh
,
22743 offset_size
, offset
, section_is_gnu
);
22746 /* Return the .debug_loc section to use for CU.
22747 For DWO files use .debug_loc.dwo. */
22749 static struct dwarf2_section_info
*
22750 cu_debug_loc_section (struct dwarf2_cu
*cu
)
22752 struct dwarf2_per_objfile
*dwarf2_per_objfile
22753 = cu
->per_cu
->dwarf2_per_objfile
;
22757 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
22759 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
22761 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
22762 : &dwarf2_per_objfile
->loc
);
22765 /* A helper function that fills in a dwarf2_loclist_baton. */
22768 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
22769 struct dwarf2_loclist_baton
*baton
,
22770 const struct attribute
*attr
)
22772 struct dwarf2_per_objfile
*dwarf2_per_objfile
22773 = cu
->per_cu
->dwarf2_per_objfile
;
22774 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
22776 section
->read (dwarf2_per_objfile
->objfile
);
22778 baton
->per_cu
= cu
->per_cu
;
22779 gdb_assert (baton
->per_cu
);
22780 /* We don't know how long the location list is, but make sure we
22781 don't run off the edge of the section. */
22782 baton
->size
= section
->size
- DW_UNSND (attr
);
22783 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
22784 if (cu
->base_address
.has_value ())
22785 baton
->base_address
= *cu
->base_address
;
22787 baton
->base_address
= 0;
22788 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
22792 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
22793 struct dwarf2_cu
*cu
, int is_block
)
22795 struct dwarf2_per_objfile
*dwarf2_per_objfile
22796 = cu
->per_cu
->dwarf2_per_objfile
;
22797 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22798 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
22800 if (attr
->form_is_section_offset ()
22801 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
22802 the section. If so, fall through to the complaint in the
22804 && DW_UNSND (attr
) < section
->get_size (objfile
))
22806 struct dwarf2_loclist_baton
*baton
;
22808 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
22810 fill_in_loclist_baton (cu
, baton
, attr
);
22812 if (!cu
->base_address
.has_value ())
22813 complaint (_("Location list used without "
22814 "specifying the CU base address."));
22816 SYMBOL_ACLASS_INDEX (sym
) = (is_block
22817 ? dwarf2_loclist_block_index
22818 : dwarf2_loclist_index
);
22819 SYMBOL_LOCATION_BATON (sym
) = baton
;
22823 struct dwarf2_locexpr_baton
*baton
;
22825 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
22826 baton
->per_cu
= cu
->per_cu
;
22827 gdb_assert (baton
->per_cu
);
22829 if (attr
->form_is_block ())
22831 /* Note that we're just copying the block's data pointer
22832 here, not the actual data. We're still pointing into the
22833 info_buffer for SYM's objfile; right now we never release
22834 that buffer, but when we do clean up properly this may
22836 baton
->size
= DW_BLOCK (attr
)->size
;
22837 baton
->data
= DW_BLOCK (attr
)->data
;
22841 dwarf2_invalid_attrib_class_complaint ("location description",
22842 sym
->natural_name ());
22846 SYMBOL_ACLASS_INDEX (sym
) = (is_block
22847 ? dwarf2_locexpr_block_index
22848 : dwarf2_locexpr_index
);
22849 SYMBOL_LOCATION_BATON (sym
) = baton
;
22856 dwarf2_per_cu_data::objfile () const
22858 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22860 /* Return the master objfile, so that we can report and look up the
22861 correct file containing this variable. */
22862 if (objfile
->separate_debug_objfile_backlink
)
22863 objfile
= objfile
->separate_debug_objfile_backlink
;
22868 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
22869 (CU_HEADERP is unused in such case) or prepare a temporary copy at
22870 CU_HEADERP first. */
22872 static const struct comp_unit_head
*
22873 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
22874 const struct dwarf2_per_cu_data
*per_cu
)
22876 const gdb_byte
*info_ptr
;
22879 return &per_cu
->cu
->header
;
22881 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
22883 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
22884 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
22885 rcuh_kind::COMPILE
);
22893 dwarf2_per_cu_data::addr_size () const
22895 struct comp_unit_head cu_header_local
;
22896 const struct comp_unit_head
*cu_headerp
;
22898 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
22900 return cu_headerp
->addr_size
;
22906 dwarf2_per_cu_data::offset_size () const
22908 struct comp_unit_head cu_header_local
;
22909 const struct comp_unit_head
*cu_headerp
;
22911 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
22913 return cu_headerp
->offset_size
;
22919 dwarf2_per_cu_data::ref_addr_size () const
22921 struct comp_unit_head cu_header_local
;
22922 const struct comp_unit_head
*cu_headerp
;
22924 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
22926 if (cu_headerp
->version
== 2)
22927 return cu_headerp
->addr_size
;
22929 return cu_headerp
->offset_size
;
22935 dwarf2_per_cu_data::text_offset () const
22937 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22939 return objfile
->text_section_offset ();
22945 dwarf2_per_cu_data::addr_type () const
22947 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22948 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
22949 struct type
*addr_type
= lookup_pointer_type (void_type
);
22950 int addr_size
= this->addr_size ();
22952 if (TYPE_LENGTH (addr_type
) == addr_size
)
22955 addr_type
= addr_sized_int_type (TYPE_UNSIGNED (addr_type
));
22959 /* A helper function for dwarf2_find_containing_comp_unit that returns
22960 the index of the result, and that searches a vector. It will
22961 return a result even if the offset in question does not actually
22962 occur in any CU. This is separate so that it can be unit
22966 dwarf2_find_containing_comp_unit
22967 (sect_offset sect_off
,
22968 unsigned int offset_in_dwz
,
22969 const std::vector
<dwarf2_per_cu_data
*> &all_comp_units
)
22974 high
= all_comp_units
.size () - 1;
22977 struct dwarf2_per_cu_data
*mid_cu
;
22978 int mid
= low
+ (high
- low
) / 2;
22980 mid_cu
= all_comp_units
[mid
];
22981 if (mid_cu
->is_dwz
> offset_in_dwz
22982 || (mid_cu
->is_dwz
== offset_in_dwz
22983 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
22988 gdb_assert (low
== high
);
22992 /* Locate the .debug_info compilation unit from CU's objfile which contains
22993 the DIE at OFFSET. Raises an error on failure. */
22995 static struct dwarf2_per_cu_data
*
22996 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
22997 unsigned int offset_in_dwz
,
22998 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
23001 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23002 dwarf2_per_objfile
->all_comp_units
);
23003 struct dwarf2_per_cu_data
*this_cu
23004 = dwarf2_per_objfile
->all_comp_units
[low
];
23006 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
23008 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
23009 error (_("Dwarf Error: could not find partial DIE containing "
23010 "offset %s [in module %s]"),
23011 sect_offset_str (sect_off
),
23012 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
23014 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
23016 return dwarf2_per_objfile
->all_comp_units
[low
-1];
23020 if (low
== dwarf2_per_objfile
->all_comp_units
.size () - 1
23021 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
23022 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
23023 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
23030 namespace selftests
{
23031 namespace find_containing_comp_unit
{
23036 struct dwarf2_per_cu_data one
{};
23037 struct dwarf2_per_cu_data two
{};
23038 struct dwarf2_per_cu_data three
{};
23039 struct dwarf2_per_cu_data four
{};
23042 two
.sect_off
= sect_offset (one
.length
);
23047 four
.sect_off
= sect_offset (three
.length
);
23051 std::vector
<dwarf2_per_cu_data
*> units
;
23052 units
.push_back (&one
);
23053 units
.push_back (&two
);
23054 units
.push_back (&three
);
23055 units
.push_back (&four
);
23059 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
23060 SELF_CHECK (units
[result
] == &one
);
23061 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
23062 SELF_CHECK (units
[result
] == &one
);
23063 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
23064 SELF_CHECK (units
[result
] == &two
);
23066 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
23067 SELF_CHECK (units
[result
] == &three
);
23068 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
23069 SELF_CHECK (units
[result
] == &three
);
23070 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
23071 SELF_CHECK (units
[result
] == &four
);
23077 #endif /* GDB_SELF_TEST */
23079 /* Initialize dwarf2_cu CU, owned by PER_CU. */
23081 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data
*per_cu_
)
23082 : per_cu (per_cu_
),
23084 has_loclist (false),
23085 checked_producer (false),
23086 producer_is_gxx_lt_4_6 (false),
23087 producer_is_gcc_lt_4_3 (false),
23088 producer_is_icc (false),
23089 producer_is_icc_lt_14 (false),
23090 producer_is_codewarrior (false),
23091 processing_has_namespace_info (false)
23096 /* Destroy a dwarf2_cu. */
23098 dwarf2_cu::~dwarf2_cu ()
23103 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
23106 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
23107 enum language pretend_language
)
23109 struct attribute
*attr
;
23111 /* Set the language we're debugging. */
23112 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
23113 if (attr
!= nullptr)
23114 set_cu_language (DW_UNSND (attr
), cu
);
23117 cu
->language
= pretend_language
;
23118 cu
->language_defn
= language_def (cu
->language
);
23121 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
23124 /* Increase the age counter on each cached compilation unit, and free
23125 any that are too old. */
23128 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
23130 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
23132 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
23133 per_cu
= dwarf2_per_objfile
->read_in_chain
;
23134 while (per_cu
!= NULL
)
23136 per_cu
->cu
->last_used
++;
23137 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
23138 dwarf2_mark (per_cu
->cu
);
23139 per_cu
= per_cu
->cu
->read_in_chain
;
23142 per_cu
= dwarf2_per_objfile
->read_in_chain
;
23143 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
23144 while (per_cu
!= NULL
)
23146 struct dwarf2_per_cu_data
*next_cu
;
23148 next_cu
= per_cu
->cu
->read_in_chain
;
23150 if (!per_cu
->cu
->mark
)
23153 *last_chain
= next_cu
;
23156 last_chain
= &per_cu
->cu
->read_in_chain
;
23162 /* Remove a single compilation unit from the cache. */
23165 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
23167 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
23168 struct dwarf2_per_objfile
*dwarf2_per_objfile
23169 = target_per_cu
->dwarf2_per_objfile
;
23171 per_cu
= dwarf2_per_objfile
->read_in_chain
;
23172 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
23173 while (per_cu
!= NULL
)
23175 struct dwarf2_per_cu_data
*next_cu
;
23177 next_cu
= per_cu
->cu
->read_in_chain
;
23179 if (per_cu
== target_per_cu
)
23183 *last_chain
= next_cu
;
23187 last_chain
= &per_cu
->cu
->read_in_chain
;
23193 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
23194 We store these in a hash table separate from the DIEs, and preserve them
23195 when the DIEs are flushed out of cache.
23197 The CU "per_cu" pointer is needed because offset alone is not enough to
23198 uniquely identify the type. A file may have multiple .debug_types sections,
23199 or the type may come from a DWO file. Furthermore, while it's more logical
23200 to use per_cu->section+offset, with Fission the section with the data is in
23201 the DWO file but we don't know that section at the point we need it.
23202 We have to use something in dwarf2_per_cu_data (or the pointer to it)
23203 because we can enter the lookup routine, get_die_type_at_offset, from
23204 outside this file, and thus won't necessarily have PER_CU->cu.
23205 Fortunately, PER_CU is stable for the life of the objfile. */
23207 struct dwarf2_per_cu_offset_and_type
23209 const struct dwarf2_per_cu_data
*per_cu
;
23210 sect_offset sect_off
;
23214 /* Hash function for a dwarf2_per_cu_offset_and_type. */
23217 per_cu_offset_and_type_hash (const void *item
)
23219 const struct dwarf2_per_cu_offset_and_type
*ofs
23220 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
23222 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
23225 /* Equality function for a dwarf2_per_cu_offset_and_type. */
23228 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
23230 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
23231 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
23232 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
23233 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
23235 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
23236 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
23239 /* Set the type associated with DIE to TYPE. Save it in CU's hash
23240 table if necessary. For convenience, return TYPE.
23242 The DIEs reading must have careful ordering to:
23243 * Not cause infinite loops trying to read in DIEs as a prerequisite for
23244 reading current DIE.
23245 * Not trying to dereference contents of still incompletely read in types
23246 while reading in other DIEs.
23247 * Enable referencing still incompletely read in types just by a pointer to
23248 the type without accessing its fields.
23250 Therefore caller should follow these rules:
23251 * Try to fetch any prerequisite types we may need to build this DIE type
23252 before building the type and calling set_die_type.
23253 * After building type call set_die_type for current DIE as soon as
23254 possible before fetching more types to complete the current type.
23255 * Make the type as complete as possible before fetching more types. */
23257 static struct type
*
23258 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
23260 struct dwarf2_per_objfile
*dwarf2_per_objfile
23261 = cu
->per_cu
->dwarf2_per_objfile
;
23262 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
23263 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23264 struct attribute
*attr
;
23265 struct dynamic_prop prop
;
23267 /* For Ada types, make sure that the gnat-specific data is always
23268 initialized (if not already set). There are a few types where
23269 we should not be doing so, because the type-specific area is
23270 already used to hold some other piece of info (eg: TYPE_CODE_FLT
23271 where the type-specific area is used to store the floatformat).
23272 But this is not a problem, because the gnat-specific information
23273 is actually not needed for these types. */
23274 if (need_gnat_info (cu
)
23275 && TYPE_CODE (type
) != TYPE_CODE_FUNC
23276 && TYPE_CODE (type
) != TYPE_CODE_FLT
23277 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
23278 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
23279 && TYPE_CODE (type
) != TYPE_CODE_METHOD
23280 && !HAVE_GNAT_AUX_INFO (type
))
23281 INIT_GNAT_SPECIFIC (type
);
23283 /* Read DW_AT_allocated and set in type. */
23284 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
23285 if (attr
!= NULL
&& attr
->form_is_block ())
23287 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
23288 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23289 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
);
23291 else if (attr
!= NULL
)
23293 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
23294 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23295 sect_offset_str (die
->sect_off
));
23298 /* Read DW_AT_associated and set in type. */
23299 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
23300 if (attr
!= NULL
&& attr
->form_is_block ())
23302 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
23303 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23304 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
);
23306 else if (attr
!= NULL
)
23308 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
23309 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23310 sect_offset_str (die
->sect_off
));
23313 /* Read DW_AT_data_location and set in type. */
23314 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
23315 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
,
23316 cu
->per_cu
->addr_type ()))
23317 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
);
23319 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
23320 dwarf2_per_objfile
->die_type_hash
23321 = htab_up (htab_create_alloc (127,
23322 per_cu_offset_and_type_hash
,
23323 per_cu_offset_and_type_eq
,
23324 NULL
, xcalloc
, xfree
));
23326 ofs
.per_cu
= cu
->per_cu
;
23327 ofs
.sect_off
= die
->sect_off
;
23329 slot
= (struct dwarf2_per_cu_offset_and_type
**)
23330 htab_find_slot (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
23332 complaint (_("A problem internal to GDB: DIE %s has type already set"),
23333 sect_offset_str (die
->sect_off
));
23334 *slot
= XOBNEW (&objfile
->objfile_obstack
,
23335 struct dwarf2_per_cu_offset_and_type
);
23340 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
23341 or return NULL if the die does not have a saved type. */
23343 static struct type
*
23344 get_die_type_at_offset (sect_offset sect_off
,
23345 struct dwarf2_per_cu_data
*per_cu
)
23347 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
23348 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
23350 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
23353 ofs
.per_cu
= per_cu
;
23354 ofs
.sect_off
= sect_off
;
23355 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
23356 htab_find (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
));
23363 /* Look up the type for DIE in CU in die_type_hash,
23364 or return NULL if DIE does not have a saved type. */
23366 static struct type
*
23367 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
23369 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
23372 /* Add a dependence relationship from CU to REF_PER_CU. */
23375 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
23376 struct dwarf2_per_cu_data
*ref_per_cu
)
23380 if (cu
->dependencies
== NULL
)
23382 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
23383 NULL
, &cu
->comp_unit_obstack
,
23384 hashtab_obstack_allocate
,
23385 dummy_obstack_deallocate
);
23387 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
23389 *slot
= ref_per_cu
;
23392 /* Subroutine of dwarf2_mark to pass to htab_traverse.
23393 Set the mark field in every compilation unit in the
23394 cache that we must keep because we are keeping CU. */
23397 dwarf2_mark_helper (void **slot
, void *data
)
23399 struct dwarf2_per_cu_data
*per_cu
;
23401 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
23403 /* cu->dependencies references may not yet have been ever read if QUIT aborts
23404 reading of the chain. As such dependencies remain valid it is not much
23405 useful to track and undo them during QUIT cleanups. */
23406 if (per_cu
->cu
== NULL
)
23409 if (per_cu
->cu
->mark
)
23411 per_cu
->cu
->mark
= true;
23413 if (per_cu
->cu
->dependencies
!= NULL
)
23414 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
23419 /* Set the mark field in CU and in every other compilation unit in the
23420 cache that we must keep because we are keeping CU. */
23423 dwarf2_mark (struct dwarf2_cu
*cu
)
23428 if (cu
->dependencies
!= NULL
)
23429 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
23433 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
23437 per_cu
->cu
->mark
= false;
23438 per_cu
= per_cu
->cu
->read_in_chain
;
23442 /* Trivial hash function for partial_die_info: the hash value of a DIE
23443 is its offset in .debug_info for this objfile. */
23446 partial_die_hash (const void *item
)
23448 const struct partial_die_info
*part_die
23449 = (const struct partial_die_info
*) item
;
23451 return to_underlying (part_die
->sect_off
);
23454 /* Trivial comparison function for partial_die_info structures: two DIEs
23455 are equal if they have the same offset. */
23458 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
23460 const struct partial_die_info
*part_die_lhs
23461 = (const struct partial_die_info
*) item_lhs
;
23462 const struct partial_die_info
*part_die_rhs
23463 = (const struct partial_die_info
*) item_rhs
;
23465 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
23468 struct cmd_list_element
*set_dwarf_cmdlist
;
23469 struct cmd_list_element
*show_dwarf_cmdlist
;
23472 set_dwarf_cmd (const char *args
, int from_tty
)
23474 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
23479 show_dwarf_cmd (const char *args
, int from_tty
)
23481 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
23485 show_check_physname (struct ui_file
*file
, int from_tty
,
23486 struct cmd_list_element
*c
, const char *value
)
23488 fprintf_filtered (file
,
23489 _("Whether to check \"physname\" is %s.\n"),
23493 void _initialize_dwarf2_read ();
23495 _initialize_dwarf2_read ()
23497 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
23498 Set DWARF specific variables.\n\
23499 Configure DWARF variables such as the cache size."),
23500 &set_dwarf_cmdlist
, "maintenance set dwarf ",
23501 0/*allow-unknown*/, &maintenance_set_cmdlist
);
23503 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
23504 Show DWARF specific variables.\n\
23505 Show DWARF variables such as the cache size."),
23506 &show_dwarf_cmdlist
, "maintenance show dwarf ",
23507 0/*allow-unknown*/, &maintenance_show_cmdlist
);
23509 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
23510 &dwarf_max_cache_age
, _("\
23511 Set the upper bound on the age of cached DWARF compilation units."), _("\
23512 Show the upper bound on the age of cached DWARF compilation units."), _("\
23513 A higher limit means that cached compilation units will be stored\n\
23514 in memory longer, and more total memory will be used. Zero disables\n\
23515 caching, which can slow down startup."),
23517 show_dwarf_max_cache_age
,
23518 &set_dwarf_cmdlist
,
23519 &show_dwarf_cmdlist
);
23521 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
23522 Set debugging of the DWARF reader."), _("\
23523 Show debugging of the DWARF reader."), _("\
23524 When enabled (non-zero), debugging messages are printed during DWARF\n\
23525 reading and symtab expansion. A value of 1 (one) provides basic\n\
23526 information. A value greater than 1 provides more verbose information."),
23529 &setdebuglist
, &showdebuglist
);
23531 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
23532 Set debugging of the DWARF DIE reader."), _("\
23533 Show debugging of the DWARF DIE reader."), _("\
23534 When enabled (non-zero), DIEs are dumped after they are read in.\n\
23535 The value is the maximum depth to print."),
23538 &setdebuglist
, &showdebuglist
);
23540 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
23541 Set debugging of the dwarf line reader."), _("\
23542 Show debugging of the dwarf line reader."), _("\
23543 When enabled (non-zero), line number entries are dumped as they are read in.\n\
23544 A value of 1 (one) provides basic information.\n\
23545 A value greater than 1 provides more verbose information."),
23548 &setdebuglist
, &showdebuglist
);
23550 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
23551 Set cross-checking of \"physname\" code against demangler."), _("\
23552 Show cross-checking of \"physname\" code against demangler."), _("\
23553 When enabled, GDB's internal \"physname\" code is checked against\n\
23555 NULL
, show_check_physname
,
23556 &setdebuglist
, &showdebuglist
);
23558 add_setshow_boolean_cmd ("use-deprecated-index-sections",
23559 no_class
, &use_deprecated_index_sections
, _("\
23560 Set whether to use deprecated gdb_index sections."), _("\
23561 Show whether to use deprecated gdb_index sections."), _("\
23562 When enabled, deprecated .gdb_index sections are used anyway.\n\
23563 Normally they are ignored either because of a missing feature or\n\
23564 performance issue.\n\
23565 Warning: This option must be enabled before gdb reads the file."),
23568 &setlist
, &showlist
);
23570 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
23571 &dwarf2_locexpr_funcs
);
23572 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
23573 &dwarf2_loclist_funcs
);
23575 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
23576 &dwarf2_block_frame_base_locexpr_funcs
);
23577 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
23578 &dwarf2_block_frame_base_loclist_funcs
);
23581 selftests::register_test ("dw2_expand_symtabs_matching",
23582 selftests::dw2_expand_symtabs_matching::run_test
);
23583 selftests::register_test ("dwarf2_find_containing_comp_unit",
23584 selftests::find_containing_comp_unit::run_test
);