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
= objfile
->arch ();
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
= objfile
->arch ();
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 (objfile
->arch (), 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 (objfile
->arch ());
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 /* It's an include file, no symbols to read for it.
5921 Everything is in the includer symtab. */
5923 /* The expansion of a dwarf2_include_psymtab is just a trigger for
5924 expansion of the includer psymtab. We use the dependencies[0] field to
5925 model the includer. But if we go the regular route of calling
5926 expand_psymtab here, and having expand_psymtab call expand_dependencies
5927 to expand the includer, we'll only use expand_psymtab on the includer
5928 (making it a non-toplevel psymtab), while if we expand the includer via
5929 another path, we'll use read_symtab (making it a toplevel psymtab).
5930 So, don't pretend a dwarf2_include_psymtab is an actual toplevel
5931 psymtab, and trigger read_symtab on the includer here directly. */
5932 includer ()->read_symtab (objfile
);
5935 void expand_psymtab (struct objfile
*objfile
) override
5937 /* This is not called by read_symtab, and should not be called by any
5938 expand_dependencies. */
5942 bool readin_p () const override
5944 return includer ()->readin_p ();
5947 struct compunit_symtab
*get_compunit_symtab () const override
5953 partial_symtab
*includer () const
5955 /* An include psymtab has exactly one dependency: the psymtab that
5957 gdb_assert (this->number_of_dependencies
== 1);
5958 return this->dependencies
[0];
5962 /* Allocate a new partial symtab for file named NAME and mark this new
5963 partial symtab as being an include of PST. */
5966 dwarf2_create_include_psymtab (const char *name
, dwarf2_psymtab
*pst
,
5967 struct objfile
*objfile
)
5969 dwarf2_include_psymtab
*subpst
= new dwarf2_include_psymtab (name
, objfile
);
5971 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
5973 /* It shares objfile->objfile_obstack. */
5974 subpst
->dirname
= pst
->dirname
;
5977 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
5978 subpst
->dependencies
[0] = pst
;
5979 subpst
->number_of_dependencies
= 1;
5982 /* Read the Line Number Program data and extract the list of files
5983 included by the source file represented by PST. Build an include
5984 partial symtab for each of these included files. */
5987 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
5988 struct die_info
*die
,
5989 dwarf2_psymtab
*pst
)
5992 struct attribute
*attr
;
5994 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5995 if (attr
!= nullptr)
5996 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
5998 return; /* No linetable, so no includes. */
6000 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
6001 that we pass in the raw text_low here; that is ok because we're
6002 only decoding the line table to make include partial symtabs, and
6003 so the addresses aren't really used. */
6004 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
6005 pst
->raw_text_low (), 1);
6009 hash_signatured_type (const void *item
)
6011 const struct signatured_type
*sig_type
6012 = (const struct signatured_type
*) item
;
6014 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6015 return sig_type
->signature
;
6019 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6021 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6022 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6024 return lhs
->signature
== rhs
->signature
;
6027 /* Allocate a hash table for signatured types. */
6030 allocate_signatured_type_table ()
6032 return htab_up (htab_create_alloc (41,
6033 hash_signatured_type
,
6035 NULL
, xcalloc
, xfree
));
6038 /* A helper function to add a signatured type CU to a table. */
6041 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6043 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6044 std::vector
<signatured_type
*> *all_type_units
6045 = (std::vector
<signatured_type
*> *) datum
;
6047 all_type_units
->push_back (sigt
);
6052 /* A helper for create_debug_types_hash_table. Read types from SECTION
6053 and fill them into TYPES_HTAB. It will process only type units,
6054 therefore DW_UT_type. */
6057 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6058 struct dwo_file
*dwo_file
,
6059 dwarf2_section_info
*section
, htab_up
&types_htab
,
6060 rcuh_kind section_kind
)
6062 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6063 struct dwarf2_section_info
*abbrev_section
;
6065 const gdb_byte
*info_ptr
, *end_ptr
;
6067 abbrev_section
= (dwo_file
!= NULL
6068 ? &dwo_file
->sections
.abbrev
6069 : &dwarf2_per_objfile
->abbrev
);
6071 if (dwarf_read_debug
)
6072 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6073 section
->get_name (),
6074 abbrev_section
->get_file_name ());
6076 section
->read (objfile
);
6077 info_ptr
= section
->buffer
;
6079 if (info_ptr
== NULL
)
6082 /* We can't set abfd until now because the section may be empty or
6083 not present, in which case the bfd is unknown. */
6084 abfd
= section
->get_bfd_owner ();
6086 /* We don't use cutu_reader here because we don't need to read
6087 any dies: the signature is in the header. */
6089 end_ptr
= info_ptr
+ section
->size
;
6090 while (info_ptr
< end_ptr
)
6092 struct signatured_type
*sig_type
;
6093 struct dwo_unit
*dwo_tu
;
6095 const gdb_byte
*ptr
= info_ptr
;
6096 struct comp_unit_head header
;
6097 unsigned int length
;
6099 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6101 /* Initialize it due to a false compiler warning. */
6102 header
.signature
= -1;
6103 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6105 /* We need to read the type's signature in order to build the hash
6106 table, but we don't need anything else just yet. */
6108 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
6109 abbrev_section
, ptr
, section_kind
);
6111 length
= header
.get_length ();
6113 /* Skip dummy type units. */
6114 if (ptr
>= info_ptr
+ length
6115 || peek_abbrev_code (abfd
, ptr
) == 0
6116 || header
.unit_type
!= DW_UT_type
)
6122 if (types_htab
== NULL
)
6125 types_htab
= allocate_dwo_unit_table ();
6127 types_htab
= allocate_signatured_type_table ();
6133 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6135 dwo_tu
->dwo_file
= dwo_file
;
6136 dwo_tu
->signature
= header
.signature
;
6137 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6138 dwo_tu
->section
= section
;
6139 dwo_tu
->sect_off
= sect_off
;
6140 dwo_tu
->length
= length
;
6144 /* N.B.: type_offset is not usable if this type uses a DWO file.
6145 The real type_offset is in the DWO file. */
6147 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6148 struct signatured_type
);
6149 sig_type
->signature
= header
.signature
;
6150 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6151 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6152 sig_type
->per_cu
.is_debug_types
= 1;
6153 sig_type
->per_cu
.section
= section
;
6154 sig_type
->per_cu
.sect_off
= sect_off
;
6155 sig_type
->per_cu
.length
= length
;
6158 slot
= htab_find_slot (types_htab
.get (),
6159 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6161 gdb_assert (slot
!= NULL
);
6164 sect_offset dup_sect_off
;
6168 const struct dwo_unit
*dup_tu
6169 = (const struct dwo_unit
*) *slot
;
6171 dup_sect_off
= dup_tu
->sect_off
;
6175 const struct signatured_type
*dup_tu
6176 = (const struct signatured_type
*) *slot
;
6178 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6181 complaint (_("debug type entry at offset %s is duplicate to"
6182 " the entry at offset %s, signature %s"),
6183 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6184 hex_string (header
.signature
));
6186 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6188 if (dwarf_read_debug
> 1)
6189 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6190 sect_offset_str (sect_off
),
6191 hex_string (header
.signature
));
6197 /* Create the hash table of all entries in the .debug_types
6198 (or .debug_types.dwo) section(s).
6199 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6200 otherwise it is NULL.
6202 The result is a pointer to the hash table or NULL if there are no types.
6204 Note: This function processes DWO files only, not DWP files. */
6207 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6208 struct dwo_file
*dwo_file
,
6209 gdb::array_view
<dwarf2_section_info
> type_sections
,
6210 htab_up
&types_htab
)
6212 for (dwarf2_section_info
§ion
: type_sections
)
6213 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, §ion
,
6214 types_htab
, rcuh_kind::TYPE
);
6217 /* Create the hash table of all entries in the .debug_types section,
6218 and initialize all_type_units.
6219 The result is zero if there is an error (e.g. missing .debug_types section),
6220 otherwise non-zero. */
6223 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6227 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
6228 &dwarf2_per_objfile
->info
, types_htab
,
6229 rcuh_kind::COMPILE
);
6230 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
6231 dwarf2_per_objfile
->types
, types_htab
);
6232 if (types_htab
== NULL
)
6234 dwarf2_per_objfile
->signatured_types
= NULL
;
6238 dwarf2_per_objfile
->signatured_types
= std::move (types_htab
);
6240 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
6241 dwarf2_per_objfile
->all_type_units
.reserve
6242 (htab_elements (dwarf2_per_objfile
->signatured_types
.get ()));
6244 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
.get (),
6245 add_signatured_type_cu_to_table
,
6246 &dwarf2_per_objfile
->all_type_units
);
6251 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
6252 If SLOT is non-NULL, it is the entry to use in the hash table.
6253 Otherwise we find one. */
6255 static struct signatured_type
*
6256 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
6259 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6261 if (dwarf2_per_objfile
->all_type_units
.size ()
6262 == dwarf2_per_objfile
->all_type_units
.capacity ())
6263 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
6265 signatured_type
*sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6266 struct signatured_type
);
6268 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
6269 sig_type
->signature
= sig
;
6270 sig_type
->per_cu
.is_debug_types
= 1;
6271 if (dwarf2_per_objfile
->using_index
)
6273 sig_type
->per_cu
.v
.quick
=
6274 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6275 struct dwarf2_per_cu_quick_data
);
6280 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6283 gdb_assert (*slot
== NULL
);
6285 /* The rest of sig_type must be filled in by the caller. */
6289 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6290 Fill in SIG_ENTRY with DWO_ENTRY. */
6293 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6294 struct signatured_type
*sig_entry
,
6295 struct dwo_unit
*dwo_entry
)
6297 /* Make sure we're not clobbering something we don't expect to. */
6298 gdb_assert (! sig_entry
->per_cu
.queued
);
6299 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
6300 if (dwarf2_per_objfile
->using_index
)
6302 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6303 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
6306 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6307 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6308 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6309 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6310 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6312 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6313 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6314 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6315 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6316 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6317 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6318 sig_entry
->dwo_unit
= dwo_entry
;
6321 /* Subroutine of lookup_signatured_type.
6322 If we haven't read the TU yet, create the signatured_type data structure
6323 for a TU to be read in directly from a DWO file, bypassing the stub.
6324 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6325 using .gdb_index, then when reading a CU we want to stay in the DWO file
6326 containing that CU. Otherwise we could end up reading several other DWO
6327 files (due to comdat folding) to process the transitive closure of all the
6328 mentioned TUs, and that can be slow. The current DWO file will have every
6329 type signature that it needs.
6330 We only do this for .gdb_index because in the psymtab case we already have
6331 to read all the DWOs to build the type unit groups. */
6333 static struct signatured_type
*
6334 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6336 struct dwarf2_per_objfile
*dwarf2_per_objfile
6337 = cu
->per_cu
->dwarf2_per_objfile
;
6338 struct dwo_file
*dwo_file
;
6339 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6340 struct signatured_type find_sig_entry
, *sig_entry
;
6343 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6345 /* If TU skeletons have been removed then we may not have read in any
6347 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6348 dwarf2_per_objfile
->signatured_types
= allocate_signatured_type_table ();
6350 /* We only ever need to read in one copy of a signatured type.
6351 Use the global signatured_types array to do our own comdat-folding
6352 of types. If this is the first time we're reading this TU, and
6353 the TU has an entry in .gdb_index, replace the recorded data from
6354 .gdb_index with this TU. */
6356 find_sig_entry
.signature
= sig
;
6357 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6358 &find_sig_entry
, INSERT
);
6359 sig_entry
= (struct signatured_type
*) *slot
;
6361 /* We can get here with the TU already read, *or* in the process of being
6362 read. Don't reassign the global entry to point to this DWO if that's
6363 the case. Also note that if the TU is already being read, it may not
6364 have come from a DWO, the program may be a mix of Fission-compiled
6365 code and non-Fission-compiled code. */
6367 /* Have we already tried to read this TU?
6368 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6369 needn't exist in the global table yet). */
6370 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
6373 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6374 dwo_unit of the TU itself. */
6375 dwo_file
= cu
->dwo_unit
->dwo_file
;
6377 /* Ok, this is the first time we're reading this TU. */
6378 if (dwo_file
->tus
== NULL
)
6380 find_dwo_entry
.signature
= sig
;
6381 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6383 if (dwo_entry
== NULL
)
6386 /* If the global table doesn't have an entry for this TU, add one. */
6387 if (sig_entry
== NULL
)
6388 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6390 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6391 sig_entry
->per_cu
.tu_read
= 1;
6395 /* Subroutine of lookup_signatured_type.
6396 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6397 then try the DWP file. If the TU stub (skeleton) has been removed then
6398 it won't be in .gdb_index. */
6400 static struct signatured_type
*
6401 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6403 struct dwarf2_per_objfile
*dwarf2_per_objfile
6404 = cu
->per_cu
->dwarf2_per_objfile
;
6405 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
6406 struct dwo_unit
*dwo_entry
;
6407 struct signatured_type find_sig_entry
, *sig_entry
;
6410 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6411 gdb_assert (dwp_file
!= NULL
);
6413 /* If TU skeletons have been removed then we may not have read in any
6415 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6416 dwarf2_per_objfile
->signatured_types
= allocate_signatured_type_table ();
6418 find_sig_entry
.signature
= sig
;
6419 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6420 &find_sig_entry
, INSERT
);
6421 sig_entry
= (struct signatured_type
*) *slot
;
6423 /* Have we already tried to read this TU?
6424 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6425 needn't exist in the global table yet). */
6426 if (sig_entry
!= NULL
)
6429 if (dwp_file
->tus
== NULL
)
6431 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
6432 sig
, 1 /* is_debug_types */);
6433 if (dwo_entry
== NULL
)
6436 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6437 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6442 /* Lookup a signature based type for DW_FORM_ref_sig8.
6443 Returns NULL if signature SIG is not present in the table.
6444 It is up to the caller to complain about this. */
6446 static struct signatured_type
*
6447 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6449 struct dwarf2_per_objfile
*dwarf2_per_objfile
6450 = cu
->per_cu
->dwarf2_per_objfile
;
6453 && dwarf2_per_objfile
->using_index
)
6455 /* We're in a DWO/DWP file, and we're using .gdb_index.
6456 These cases require special processing. */
6457 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
6458 return lookup_dwo_signatured_type (cu
, sig
);
6460 return lookup_dwp_signatured_type (cu
, sig
);
6464 struct signatured_type find_entry
, *entry
;
6466 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6468 find_entry
.signature
= sig
;
6469 entry
= ((struct signatured_type
*)
6470 htab_find (dwarf2_per_objfile
->signatured_types
.get (),
6476 /* Low level DIE reading support. */
6478 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6481 init_cu_die_reader (struct die_reader_specs
*reader
,
6482 struct dwarf2_cu
*cu
,
6483 struct dwarf2_section_info
*section
,
6484 struct dwo_file
*dwo_file
,
6485 struct abbrev_table
*abbrev_table
)
6487 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6488 reader
->abfd
= section
->get_bfd_owner ();
6490 reader
->dwo_file
= dwo_file
;
6491 reader
->die_section
= section
;
6492 reader
->buffer
= section
->buffer
;
6493 reader
->buffer_end
= section
->buffer
+ section
->size
;
6494 reader
->abbrev_table
= abbrev_table
;
6497 /* Subroutine of cutu_reader to simplify it.
6498 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6499 There's just a lot of work to do, and cutu_reader is big enough
6502 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6503 from it to the DIE in the DWO. If NULL we are skipping the stub.
6504 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6505 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6506 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6507 STUB_COMP_DIR may be non-NULL.
6508 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6509 are filled in with the info of the DIE from the DWO file.
6510 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6511 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6512 kept around for at least as long as *RESULT_READER.
6514 The result is non-zero if a valid (non-dummy) DIE was found. */
6517 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
6518 struct dwo_unit
*dwo_unit
,
6519 struct die_info
*stub_comp_unit_die
,
6520 const char *stub_comp_dir
,
6521 struct die_reader_specs
*result_reader
,
6522 const gdb_byte
**result_info_ptr
,
6523 struct die_info
**result_comp_unit_die
,
6524 abbrev_table_up
*result_dwo_abbrev_table
)
6526 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6527 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6528 struct dwarf2_cu
*cu
= this_cu
->cu
;
6530 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6531 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6532 int i
,num_extra_attrs
;
6533 struct dwarf2_section_info
*dwo_abbrev_section
;
6534 struct die_info
*comp_unit_die
;
6536 /* At most one of these may be provided. */
6537 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6539 /* These attributes aren't processed until later:
6540 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6541 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6542 referenced later. However, these attributes are found in the stub
6543 which we won't have later. In order to not impose this complication
6544 on the rest of the code, we read them here and copy them to the
6553 if (stub_comp_unit_die
!= NULL
)
6555 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6557 if (! this_cu
->is_debug_types
)
6558 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6559 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6560 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6561 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6562 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6564 cu
->addr_base
= stub_comp_unit_die
->addr_base ();
6566 /* There should be a DW_AT_rnglists_base (DW_AT_GNU_ranges_base) attribute
6567 here (if needed). We need the value before we can process
6569 cu
->ranges_base
= stub_comp_unit_die
->ranges_base ();
6571 else if (stub_comp_dir
!= NULL
)
6573 /* Reconstruct the comp_dir attribute to simplify the code below. */
6574 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
6575 comp_dir
->name
= DW_AT_comp_dir
;
6576 comp_dir
->form
= DW_FORM_string
;
6577 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
6578 DW_STRING (comp_dir
) = stub_comp_dir
;
6581 /* Set up for reading the DWO CU/TU. */
6582 cu
->dwo_unit
= dwo_unit
;
6583 dwarf2_section_info
*section
= dwo_unit
->section
;
6584 section
->read (objfile
);
6585 abfd
= section
->get_bfd_owner ();
6586 begin_info_ptr
= info_ptr
= (section
->buffer
6587 + to_underlying (dwo_unit
->sect_off
));
6588 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6590 if (this_cu
->is_debug_types
)
6592 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
6594 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6595 &cu
->header
, section
,
6597 info_ptr
, rcuh_kind::TYPE
);
6598 /* This is not an assert because it can be caused by bad debug info. */
6599 if (sig_type
->signature
!= cu
->header
.signature
)
6601 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6602 " TU at offset %s [in module %s]"),
6603 hex_string (sig_type
->signature
),
6604 hex_string (cu
->header
.signature
),
6605 sect_offset_str (dwo_unit
->sect_off
),
6606 bfd_get_filename (abfd
));
6608 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6609 /* For DWOs coming from DWP files, we don't know the CU length
6610 nor the type's offset in the TU until now. */
6611 dwo_unit
->length
= cu
->header
.get_length ();
6612 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6614 /* Establish the type offset that can be used to lookup the type.
6615 For DWO files, we don't know it until now. */
6616 sig_type
->type_offset_in_section
6617 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6621 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6622 &cu
->header
, section
,
6624 info_ptr
, rcuh_kind::COMPILE
);
6625 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6626 /* For DWOs coming from DWP files, we don't know the CU length
6628 dwo_unit
->length
= cu
->header
.get_length ();
6631 *result_dwo_abbrev_table
6632 = abbrev_table::read (objfile
, dwo_abbrev_section
,
6633 cu
->header
.abbrev_sect_off
);
6634 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6635 result_dwo_abbrev_table
->get ());
6637 /* Read in the die, but leave space to copy over the attributes
6638 from the stub. This has the benefit of simplifying the rest of
6639 the code - all the work to maintain the illusion of a single
6640 DW_TAG_{compile,type}_unit DIE is done here. */
6641 num_extra_attrs
= ((stmt_list
!= NULL
)
6645 + (comp_dir
!= NULL
));
6646 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6649 /* Copy over the attributes from the stub to the DIE we just read in. */
6650 comp_unit_die
= *result_comp_unit_die
;
6651 i
= comp_unit_die
->num_attrs
;
6652 if (stmt_list
!= NULL
)
6653 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6655 comp_unit_die
->attrs
[i
++] = *low_pc
;
6656 if (high_pc
!= NULL
)
6657 comp_unit_die
->attrs
[i
++] = *high_pc
;
6659 comp_unit_die
->attrs
[i
++] = *ranges
;
6660 if (comp_dir
!= NULL
)
6661 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6662 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6664 if (dwarf_die_debug
)
6666 fprintf_unfiltered (gdb_stdlog
,
6667 "Read die from %s@0x%x of %s:\n",
6668 section
->get_name (),
6669 (unsigned) (begin_info_ptr
- section
->buffer
),
6670 bfd_get_filename (abfd
));
6671 dump_die (comp_unit_die
, dwarf_die_debug
);
6674 /* Skip dummy compilation units. */
6675 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6676 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6679 *result_info_ptr
= info_ptr
;
6683 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
6684 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
6685 signature is part of the header. */
6686 static gdb::optional
<ULONGEST
>
6687 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
6689 if (cu
->header
.version
>= 5)
6690 return cu
->header
.signature
;
6691 struct attribute
*attr
;
6692 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6693 if (attr
== nullptr)
6694 return gdb::optional
<ULONGEST
> ();
6695 return DW_UNSND (attr
);
6698 /* Subroutine of cutu_reader to simplify it.
6699 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6700 Returns NULL if the specified DWO unit cannot be found. */
6702 static struct dwo_unit
*
6703 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
6704 struct die_info
*comp_unit_die
,
6705 const char *dwo_name
)
6707 struct dwarf2_cu
*cu
= this_cu
->cu
;
6708 struct dwo_unit
*dwo_unit
;
6709 const char *comp_dir
;
6711 gdb_assert (cu
!= NULL
);
6713 /* Yeah, we look dwo_name up again, but it simplifies the code. */
6714 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6715 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6717 if (this_cu
->is_debug_types
)
6719 struct signatured_type
*sig_type
;
6721 /* Since this_cu is the first member of struct signatured_type,
6722 we can go from a pointer to one to a pointer to the other. */
6723 sig_type
= (struct signatured_type
*) this_cu
;
6724 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
6728 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
6729 if (!signature
.has_value ())
6730 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
6732 dwo_name
, objfile_name (this_cu
->dwarf2_per_objfile
->objfile
));
6733 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
6740 /* Subroutine of cutu_reader to simplify it.
6741 See it for a description of the parameters.
6742 Read a TU directly from a DWO file, bypassing the stub. */
6745 cutu_reader::init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
6746 int use_existing_cu
)
6748 struct signatured_type
*sig_type
;
6750 /* Verify we can do the following downcast, and that we have the
6752 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
6753 sig_type
= (struct signatured_type
*) this_cu
;
6754 gdb_assert (sig_type
->dwo_unit
!= NULL
);
6756 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
6758 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
6759 /* There's no need to do the rereading_dwo_cu handling that
6760 cutu_reader does since we don't read the stub. */
6764 /* If !use_existing_cu, this_cu->cu must be NULL. */
6765 gdb_assert (this_cu
->cu
== NULL
);
6766 m_new_cu
.reset (new dwarf2_cu (this_cu
));
6769 /* A future optimization, if needed, would be to use an existing
6770 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
6771 could share abbrev tables. */
6773 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
6774 NULL
/* stub_comp_unit_die */,
6775 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
6778 &m_dwo_abbrev_table
) == 0)
6785 /* Initialize a CU (or TU) and read its DIEs.
6786 If the CU defers to a DWO file, read the DWO file as well.
6788 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
6789 Otherwise the table specified in the comp unit header is read in and used.
6790 This is an optimization for when we already have the abbrev table.
6792 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
6793 Otherwise, a new CU is allocated with xmalloc. */
6795 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
6796 struct abbrev_table
*abbrev_table
,
6797 int use_existing_cu
,
6799 : die_reader_specs
{},
6802 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6803 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6804 struct dwarf2_section_info
*section
= this_cu
->section
;
6805 bfd
*abfd
= section
->get_bfd_owner ();
6806 struct dwarf2_cu
*cu
;
6807 const gdb_byte
*begin_info_ptr
;
6808 struct signatured_type
*sig_type
= NULL
;
6809 struct dwarf2_section_info
*abbrev_section
;
6810 /* Non-zero if CU currently points to a DWO file and we need to
6811 reread it. When this happens we need to reread the skeleton die
6812 before we can reread the DWO file (this only applies to CUs, not TUs). */
6813 int rereading_dwo_cu
= 0;
6815 if (dwarf_die_debug
)
6816 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6817 this_cu
->is_debug_types
? "type" : "comp",
6818 sect_offset_str (this_cu
->sect_off
));
6820 /* If we're reading a TU directly from a DWO file, including a virtual DWO
6821 file (instead of going through the stub), short-circuit all of this. */
6822 if (this_cu
->reading_dwo_directly
)
6824 /* Narrow down the scope of possibilities to have to understand. */
6825 gdb_assert (this_cu
->is_debug_types
);
6826 gdb_assert (abbrev_table
== NULL
);
6827 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
);
6831 /* This is cheap if the section is already read in. */
6832 section
->read (objfile
);
6834 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6836 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
6838 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
6841 /* If this CU is from a DWO file we need to start over, we need to
6842 refetch the attributes from the skeleton CU.
6843 This could be optimized by retrieving those attributes from when we
6844 were here the first time: the previous comp_unit_die was stored in
6845 comp_unit_obstack. But there's no data yet that we need this
6847 if (cu
->dwo_unit
!= NULL
)
6848 rereading_dwo_cu
= 1;
6852 /* If !use_existing_cu, this_cu->cu must be NULL. */
6853 gdb_assert (this_cu
->cu
== NULL
);
6854 m_new_cu
.reset (new dwarf2_cu (this_cu
));
6855 cu
= m_new_cu
.get ();
6858 /* Get the header. */
6859 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
6861 /* We already have the header, there's no need to read it in again. */
6862 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
6866 if (this_cu
->is_debug_types
)
6868 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6869 &cu
->header
, section
,
6870 abbrev_section
, info_ptr
,
6873 /* Since per_cu is the first member of struct signatured_type,
6874 we can go from a pointer to one to a pointer to the other. */
6875 sig_type
= (struct signatured_type
*) this_cu
;
6876 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
6877 gdb_assert (sig_type
->type_offset_in_tu
6878 == cu
->header
.type_cu_offset_in_tu
);
6879 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6881 /* LENGTH has not been set yet for type units if we're
6882 using .gdb_index. */
6883 this_cu
->length
= cu
->header
.get_length ();
6885 /* Establish the type offset that can be used to lookup the type. */
6886 sig_type
->type_offset_in_section
=
6887 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
6889 this_cu
->dwarf_version
= cu
->header
.version
;
6893 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6894 &cu
->header
, section
,
6897 rcuh_kind::COMPILE
);
6899 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6900 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
6901 this_cu
->dwarf_version
= cu
->header
.version
;
6905 /* Skip dummy compilation units. */
6906 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6907 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6913 /* If we don't have them yet, read the abbrevs for this compilation unit.
6914 And if we need to read them now, make sure they're freed when we're
6916 if (abbrev_table
!= NULL
)
6917 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
6920 m_abbrev_table_holder
6921 = abbrev_table::read (objfile
, abbrev_section
,
6922 cu
->header
.abbrev_sect_off
);
6923 abbrev_table
= m_abbrev_table_holder
.get ();
6926 /* Read the top level CU/TU die. */
6927 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
6928 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
6930 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
6936 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
6937 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
6938 table from the DWO file and pass the ownership over to us. It will be
6939 referenced from READER, so we must make sure to free it after we're done
6942 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
6943 DWO CU, that this test will fail (the attribute will not be present). */
6944 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6945 if (dwo_name
!= nullptr)
6947 struct dwo_unit
*dwo_unit
;
6948 struct die_info
*dwo_comp_unit_die
;
6950 if (comp_unit_die
->has_children
)
6952 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
6953 " has children (offset %s) [in module %s]"),
6954 sect_offset_str (this_cu
->sect_off
),
6955 bfd_get_filename (abfd
));
6957 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
, dwo_name
);
6958 if (dwo_unit
!= NULL
)
6960 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
6961 comp_unit_die
, NULL
,
6964 &m_dwo_abbrev_table
) == 0)
6970 comp_unit_die
= dwo_comp_unit_die
;
6974 /* Yikes, we couldn't find the rest of the DIE, we only have
6975 the stub. A complaint has already been logged. There's
6976 not much more we can do except pass on the stub DIE to
6977 die_reader_func. We don't want to throw an error on bad
6984 cutu_reader::keep ()
6986 /* Done, clean up. */
6987 gdb_assert (!dummy_p
);
6988 if (m_new_cu
!= NULL
)
6990 struct dwarf2_per_objfile
*dwarf2_per_objfile
6991 = m_this_cu
->dwarf2_per_objfile
;
6992 /* Link this CU into read_in_chain. */
6993 m_this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
6994 dwarf2_per_objfile
->read_in_chain
= m_this_cu
;
6995 /* The chain owns it now. */
6996 m_new_cu
.release ();
7000 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
7001 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
7002 assumed to have already done the lookup to find the DWO file).
7004 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7005 THIS_CU->is_debug_types, but nothing else.
7007 We fill in THIS_CU->length.
7009 THIS_CU->cu is always freed when done.
7010 This is done in order to not leave THIS_CU->cu in a state where we have
7011 to care whether it refers to the "main" CU or the DWO CU.
7013 When parent_cu is passed, it is used to provide a default value for
7014 str_offsets_base and addr_base from the parent. */
7016 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
7017 struct dwarf2_cu
*parent_cu
,
7018 struct dwo_file
*dwo_file
)
7019 : die_reader_specs
{},
7022 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7023 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7024 struct dwarf2_section_info
*section
= this_cu
->section
;
7025 bfd
*abfd
= section
->get_bfd_owner ();
7026 struct dwarf2_section_info
*abbrev_section
;
7027 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7029 if (dwarf_die_debug
)
7030 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7031 this_cu
->is_debug_types
? "type" : "comp",
7032 sect_offset_str (this_cu
->sect_off
));
7034 gdb_assert (this_cu
->cu
== NULL
);
7036 abbrev_section
= (dwo_file
!= NULL
7037 ? &dwo_file
->sections
.abbrev
7038 : get_abbrev_section_for_cu (this_cu
));
7040 /* This is cheap if the section is already read in. */
7041 section
->read (objfile
);
7043 m_new_cu
.reset (new dwarf2_cu (this_cu
));
7045 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7046 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7047 &m_new_cu
->header
, section
,
7048 abbrev_section
, info_ptr
,
7049 (this_cu
->is_debug_types
7051 : rcuh_kind::COMPILE
));
7053 if (parent_cu
!= nullptr)
7055 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
7056 m_new_cu
->addr_base
= parent_cu
->addr_base
;
7058 this_cu
->length
= m_new_cu
->header
.get_length ();
7060 /* Skip dummy compilation units. */
7061 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7062 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7068 m_abbrev_table_holder
7069 = abbrev_table::read (objfile
, abbrev_section
,
7070 m_new_cu
->header
.abbrev_sect_off
);
7072 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
7073 m_abbrev_table_holder
.get ());
7074 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7078 /* Type Unit Groups.
7080 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7081 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7082 so that all types coming from the same compilation (.o file) are grouped
7083 together. A future step could be to put the types in the same symtab as
7084 the CU the types ultimately came from. */
7087 hash_type_unit_group (const void *item
)
7089 const struct type_unit_group
*tu_group
7090 = (const struct type_unit_group
*) item
;
7092 return hash_stmt_list_entry (&tu_group
->hash
);
7096 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7098 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7099 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7101 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7104 /* Allocate a hash table for type unit groups. */
7107 allocate_type_unit_groups_table ()
7109 return htab_up (htab_create_alloc (3,
7110 hash_type_unit_group
,
7112 NULL
, xcalloc
, xfree
));
7115 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7116 partial symtabs. We combine several TUs per psymtab to not let the size
7117 of any one psymtab grow too big. */
7118 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7119 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7121 /* Helper routine for get_type_unit_group.
7122 Create the type_unit_group object used to hold one or more TUs. */
7124 static struct type_unit_group
*
7125 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7127 struct dwarf2_per_objfile
*dwarf2_per_objfile
7128 = cu
->per_cu
->dwarf2_per_objfile
;
7129 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7130 struct dwarf2_per_cu_data
*per_cu
;
7131 struct type_unit_group
*tu_group
;
7133 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7134 struct type_unit_group
);
7135 per_cu
= &tu_group
->per_cu
;
7136 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7138 if (dwarf2_per_objfile
->using_index
)
7140 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7141 struct dwarf2_per_cu_quick_data
);
7145 unsigned int line_offset
= to_underlying (line_offset_struct
);
7146 dwarf2_psymtab
*pst
;
7149 /* Give the symtab a useful name for debug purposes. */
7150 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7151 name
= string_printf ("<type_units_%d>",
7152 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7154 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7156 pst
= create_partial_symtab (per_cu
, name
.c_str ());
7157 pst
->anonymous
= true;
7160 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7161 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7166 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7167 STMT_LIST is a DW_AT_stmt_list attribute. */
7169 static struct type_unit_group
*
7170 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7172 struct dwarf2_per_objfile
*dwarf2_per_objfile
7173 = cu
->per_cu
->dwarf2_per_objfile
;
7174 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7175 struct type_unit_group
*tu_group
;
7177 unsigned int line_offset
;
7178 struct type_unit_group type_unit_group_for_lookup
;
7180 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
7181 dwarf2_per_objfile
->type_unit_groups
= allocate_type_unit_groups_table ();
7183 /* Do we need to create a new group, or can we use an existing one? */
7187 line_offset
= DW_UNSND (stmt_list
);
7188 ++tu_stats
->nr_symtab_sharers
;
7192 /* Ugh, no stmt_list. Rare, but we have to handle it.
7193 We can do various things here like create one group per TU or
7194 spread them over multiple groups to split up the expansion work.
7195 To avoid worst case scenarios (too many groups or too large groups)
7196 we, umm, group them in bunches. */
7197 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7198 | (tu_stats
->nr_stmt_less_type_units
7199 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7200 ++tu_stats
->nr_stmt_less_type_units
;
7203 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7204 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7205 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
.get (),
7206 &type_unit_group_for_lookup
, INSERT
);
7209 tu_group
= (struct type_unit_group
*) *slot
;
7210 gdb_assert (tu_group
!= NULL
);
7214 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7215 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7217 ++tu_stats
->nr_symtabs
;
7223 /* Partial symbol tables. */
7225 /* Create a psymtab named NAME and assign it to PER_CU.
7227 The caller must fill in the following details:
7228 dirname, textlow, texthigh. */
7230 static dwarf2_psymtab
*
7231 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
7233 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
7234 dwarf2_psymtab
*pst
;
7236 pst
= new dwarf2_psymtab (name
, objfile
, per_cu
);
7238 pst
->psymtabs_addrmap_supported
= true;
7240 /* This is the glue that links PST into GDB's symbol API. */
7241 per_cu
->v
.psymtab
= pst
;
7246 /* DIE reader function for process_psymtab_comp_unit. */
7249 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7250 const gdb_byte
*info_ptr
,
7251 struct die_info
*comp_unit_die
,
7252 enum language pretend_language
)
7254 struct dwarf2_cu
*cu
= reader
->cu
;
7255 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
7256 struct gdbarch
*gdbarch
= objfile
->arch ();
7257 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7259 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7260 dwarf2_psymtab
*pst
;
7261 enum pc_bounds_kind cu_bounds_kind
;
7262 const char *filename
;
7264 gdb_assert (! per_cu
->is_debug_types
);
7266 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
7268 /* Allocate a new partial symbol table structure. */
7269 gdb::unique_xmalloc_ptr
<char> debug_filename
;
7270 static const char artificial
[] = "<artificial>";
7271 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7272 if (filename
== NULL
)
7274 else if (strcmp (filename
, artificial
) == 0)
7276 debug_filename
.reset (concat (artificial
, "@",
7277 sect_offset_str (per_cu
->sect_off
),
7279 filename
= debug_filename
.get ();
7282 pst
= create_partial_symtab (per_cu
, filename
);
7284 /* This must be done before calling dwarf2_build_include_psymtabs. */
7285 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7287 baseaddr
= objfile
->text_section_offset ();
7289 dwarf2_find_base_address (comp_unit_die
, cu
);
7291 /* Possibly set the default values of LOWPC and HIGHPC from
7293 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7294 &best_highpc
, cu
, pst
);
7295 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7298 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7301 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7303 /* Store the contiguous range if it is not empty; it can be
7304 empty for CUs with no code. */
7305 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
7309 /* Check if comp unit has_children.
7310 If so, read the rest of the partial symbols from this comp unit.
7311 If not, there's no more debug_info for this comp unit. */
7312 if (comp_unit_die
->has_children
)
7314 struct partial_die_info
*first_die
;
7315 CORE_ADDR lowpc
, highpc
;
7317 lowpc
= ((CORE_ADDR
) -1);
7318 highpc
= ((CORE_ADDR
) 0);
7320 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7322 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7323 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7325 /* If we didn't find a lowpc, set it to highpc to avoid
7326 complaints from `maint check'. */
7327 if (lowpc
== ((CORE_ADDR
) -1))
7330 /* If the compilation unit didn't have an explicit address range,
7331 then use the information extracted from its child dies. */
7332 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7335 best_highpc
= highpc
;
7338 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7339 best_lowpc
+ baseaddr
)
7341 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7342 best_highpc
+ baseaddr
)
7345 end_psymtab_common (objfile
, pst
);
7347 if (!cu
->per_cu
->imported_symtabs_empty ())
7350 int len
= cu
->per_cu
->imported_symtabs_size ();
7352 /* Fill in 'dependencies' here; we fill in 'users' in a
7354 pst
->number_of_dependencies
= len
;
7356 = objfile
->partial_symtabs
->allocate_dependencies (len
);
7357 for (i
= 0; i
< len
; ++i
)
7359 pst
->dependencies
[i
]
7360 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7363 cu
->per_cu
->imported_symtabs_free ();
7366 /* Get the list of files included in the current compilation unit,
7367 and build a psymtab for each of them. */
7368 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
7370 if (dwarf_read_debug
)
7371 fprintf_unfiltered (gdb_stdlog
,
7372 "Psymtab for %s unit @%s: %s - %s"
7373 ", %d global, %d static syms\n",
7374 per_cu
->is_debug_types
? "type" : "comp",
7375 sect_offset_str (per_cu
->sect_off
),
7376 paddress (gdbarch
, pst
->text_low (objfile
)),
7377 paddress (gdbarch
, pst
->text_high (objfile
)),
7378 pst
->n_global_syms
, pst
->n_static_syms
);
7381 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7382 Process compilation unit THIS_CU for a psymtab. */
7385 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
7386 bool want_partial_unit
,
7387 enum language pretend_language
)
7389 /* If this compilation unit was already read in, free the
7390 cached copy in order to read it in again. This is
7391 necessary because we skipped some symbols when we first
7392 read in the compilation unit (see load_partial_dies).
7393 This problem could be avoided, but the benefit is unclear. */
7394 if (this_cu
->cu
!= NULL
)
7395 free_one_cached_comp_unit (this_cu
);
7397 cutu_reader
reader (this_cu
, NULL
, 0, false);
7399 switch (reader
.comp_unit_die
->tag
)
7401 case DW_TAG_compile_unit
:
7402 this_cu
->unit_type
= DW_UT_compile
;
7404 case DW_TAG_partial_unit
:
7405 this_cu
->unit_type
= DW_UT_partial
;
7415 else if (this_cu
->is_debug_types
)
7416 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7417 reader
.comp_unit_die
);
7418 else if (want_partial_unit
7419 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7420 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7421 reader
.comp_unit_die
,
7424 this_cu
->lang
= this_cu
->cu
->language
;
7426 /* Age out any secondary CUs. */
7427 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
7430 /* Reader function for build_type_psymtabs. */
7433 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7434 const gdb_byte
*info_ptr
,
7435 struct die_info
*type_unit_die
)
7437 struct dwarf2_per_objfile
*dwarf2_per_objfile
7438 = reader
->cu
->per_cu
->dwarf2_per_objfile
;
7439 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7440 struct dwarf2_cu
*cu
= reader
->cu
;
7441 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7442 struct signatured_type
*sig_type
;
7443 struct type_unit_group
*tu_group
;
7444 struct attribute
*attr
;
7445 struct partial_die_info
*first_die
;
7446 CORE_ADDR lowpc
, highpc
;
7447 dwarf2_psymtab
*pst
;
7449 gdb_assert (per_cu
->is_debug_types
);
7450 sig_type
= (struct signatured_type
*) per_cu
;
7452 if (! type_unit_die
->has_children
)
7455 attr
= type_unit_die
->attr (DW_AT_stmt_list
);
7456 tu_group
= get_type_unit_group (cu
, attr
);
7458 if (tu_group
->tus
== nullptr)
7459 tu_group
->tus
= new std::vector
<signatured_type
*>;
7460 tu_group
->tus
->push_back (sig_type
);
7462 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7463 pst
= create_partial_symtab (per_cu
, "");
7464 pst
->anonymous
= true;
7466 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7468 lowpc
= (CORE_ADDR
) -1;
7469 highpc
= (CORE_ADDR
) 0;
7470 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7472 end_psymtab_common (objfile
, pst
);
7475 /* Struct used to sort TUs by their abbreviation table offset. */
7477 struct tu_abbrev_offset
7479 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7480 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7483 signatured_type
*sig_type
;
7484 sect_offset abbrev_offset
;
7487 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
7490 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
7491 const struct tu_abbrev_offset
&b
)
7493 return a
.abbrev_offset
< b
.abbrev_offset
;
7496 /* Efficiently read all the type units.
7497 This does the bulk of the work for build_type_psymtabs.
7499 The efficiency is because we sort TUs by the abbrev table they use and
7500 only read each abbrev table once. In one program there are 200K TUs
7501 sharing 8K abbrev tables.
7503 The main purpose of this function is to support building the
7504 dwarf2_per_objfile->type_unit_groups table.
7505 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7506 can collapse the search space by grouping them by stmt_list.
7507 The savings can be significant, in the same program from above the 200K TUs
7508 share 8K stmt_list tables.
7510 FUNC is expected to call get_type_unit_group, which will create the
7511 struct type_unit_group if necessary and add it to
7512 dwarf2_per_objfile->type_unit_groups. */
7515 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7517 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7518 abbrev_table_up abbrev_table
;
7519 sect_offset abbrev_offset
;
7521 /* It's up to the caller to not call us multiple times. */
7522 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
7524 if (dwarf2_per_objfile
->all_type_units
.empty ())
7527 /* TUs typically share abbrev tables, and there can be way more TUs than
7528 abbrev tables. Sort by abbrev table to reduce the number of times we
7529 read each abbrev table in.
7530 Alternatives are to punt or to maintain a cache of abbrev tables.
7531 This is simpler and efficient enough for now.
7533 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7534 symtab to use). Typically TUs with the same abbrev offset have the same
7535 stmt_list value too so in practice this should work well.
7537 The basic algorithm here is:
7539 sort TUs by abbrev table
7540 for each TU with same abbrev table:
7541 read abbrev table if first user
7542 read TU top level DIE
7543 [IWBN if DWO skeletons had DW_AT_stmt_list]
7546 if (dwarf_read_debug
)
7547 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
7549 /* Sort in a separate table to maintain the order of all_type_units
7550 for .gdb_index: TU indices directly index all_type_units. */
7551 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7552 sorted_by_abbrev
.reserve (dwarf2_per_objfile
->all_type_units
.size ());
7554 for (signatured_type
*sig_type
: dwarf2_per_objfile
->all_type_units
)
7555 sorted_by_abbrev
.emplace_back
7556 (sig_type
, read_abbrev_offset (dwarf2_per_objfile
,
7557 sig_type
->per_cu
.section
,
7558 sig_type
->per_cu
.sect_off
));
7560 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
7561 sort_tu_by_abbrev_offset
);
7563 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7565 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7567 /* Switch to the next abbrev table if necessary. */
7568 if (abbrev_table
== NULL
7569 || tu
.abbrev_offset
!= abbrev_offset
)
7571 abbrev_offset
= tu
.abbrev_offset
;
7573 abbrev_table::read (dwarf2_per_objfile
->objfile
,
7574 &dwarf2_per_objfile
->abbrev
,
7576 ++tu_stats
->nr_uniq_abbrev_tables
;
7579 cutu_reader
reader (&tu
.sig_type
->per_cu
, abbrev_table
.get (),
7581 if (!reader
.dummy_p
)
7582 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7583 reader
.comp_unit_die
);
7587 /* Print collected type unit statistics. */
7590 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7592 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7594 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
7595 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
7596 dwarf2_per_objfile
->all_type_units
.size ());
7597 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
7598 tu_stats
->nr_uniq_abbrev_tables
);
7599 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
7600 tu_stats
->nr_symtabs
);
7601 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
7602 tu_stats
->nr_symtab_sharers
);
7603 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
7604 tu_stats
->nr_stmt_less_type_units
);
7605 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
7606 tu_stats
->nr_all_type_units_reallocs
);
7609 /* Traversal function for build_type_psymtabs. */
7612 build_type_psymtab_dependencies (void **slot
, void *info
)
7614 struct dwarf2_per_objfile
*dwarf2_per_objfile
7615 = (struct dwarf2_per_objfile
*) info
;
7616 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7617 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7618 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
7619 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7620 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7623 gdb_assert (len
> 0);
7624 gdb_assert (per_cu
->type_unit_group_p ());
7626 pst
->number_of_dependencies
= len
;
7627 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
7628 for (i
= 0; i
< len
; ++i
)
7630 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7631 gdb_assert (iter
->per_cu
.is_debug_types
);
7632 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
7633 iter
->type_unit_group
= tu_group
;
7636 delete tu_group
->tus
;
7637 tu_group
->tus
= nullptr;
7642 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7643 Build partial symbol tables for the .debug_types comp-units. */
7646 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7648 if (! create_all_type_units (dwarf2_per_objfile
))
7651 build_type_psymtabs_1 (dwarf2_per_objfile
);
7654 /* Traversal function for process_skeletonless_type_unit.
7655 Read a TU in a DWO file and build partial symbols for it. */
7658 process_skeletonless_type_unit (void **slot
, void *info
)
7660 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7661 struct dwarf2_per_objfile
*dwarf2_per_objfile
7662 = (struct dwarf2_per_objfile
*) info
;
7663 struct signatured_type find_entry
, *entry
;
7665 /* If this TU doesn't exist in the global table, add it and read it in. */
7667 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7668 dwarf2_per_objfile
->signatured_types
= allocate_signatured_type_table ();
7670 find_entry
.signature
= dwo_unit
->signature
;
7671 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
7672 &find_entry
, INSERT
);
7673 /* If we've already seen this type there's nothing to do. What's happening
7674 is we're doing our own version of comdat-folding here. */
7678 /* This does the job that create_all_type_units would have done for
7680 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
7681 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
7684 /* This does the job that build_type_psymtabs_1 would have done. */
7685 cutu_reader
reader (&entry
->per_cu
, NULL
, 0, false);
7686 if (!reader
.dummy_p
)
7687 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7688 reader
.comp_unit_die
);
7693 /* Traversal function for process_skeletonless_type_units. */
7696 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7698 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7700 if (dwo_file
->tus
!= NULL
)
7701 htab_traverse_noresize (dwo_file
->tus
.get (),
7702 process_skeletonless_type_unit
, info
);
7707 /* Scan all TUs of DWO files, verifying we've processed them.
7708 This is needed in case a TU was emitted without its skeleton.
7709 Note: This can't be done until we know what all the DWO files are. */
7712 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7714 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
7715 if (get_dwp_file (dwarf2_per_objfile
) == NULL
7716 && dwarf2_per_objfile
->dwo_files
!= NULL
)
7718 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
.get (),
7719 process_dwo_file_for_skeletonless_type_units
,
7720 dwarf2_per_objfile
);
7724 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
7727 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7729 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
7731 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7736 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
7738 /* Set the 'user' field only if it is not already set. */
7739 if (pst
->dependencies
[j
]->user
== NULL
)
7740 pst
->dependencies
[j
]->user
= pst
;
7745 /* Build the partial symbol table by doing a quick pass through the
7746 .debug_info and .debug_abbrev sections. */
7749 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7751 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7753 if (dwarf_read_debug
)
7755 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
7756 objfile_name (objfile
));
7759 scoped_restore restore_reading_psyms
7760 = make_scoped_restore (&dwarf2_per_objfile
->reading_partial_symbols
,
7763 dwarf2_per_objfile
->info
.read (objfile
);
7765 /* Any cached compilation units will be linked by the per-objfile
7766 read_in_chain. Make sure to free them when we're done. */
7767 free_cached_comp_units
freer (dwarf2_per_objfile
);
7769 build_type_psymtabs (dwarf2_per_objfile
);
7771 create_all_comp_units (dwarf2_per_objfile
);
7773 /* Create a temporary address map on a temporary obstack. We later
7774 copy this to the final obstack. */
7775 auto_obstack temp_obstack
;
7777 scoped_restore save_psymtabs_addrmap
7778 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
7779 addrmap_create_mutable (&temp_obstack
));
7781 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
7783 if (per_cu
->v
.psymtab
!= NULL
)
7784 /* In case a forward DW_TAG_imported_unit has read the CU already. */
7786 process_psymtab_comp_unit (per_cu
, false, language_minimal
);
7789 /* This has to wait until we read the CUs, we need the list of DWOs. */
7790 process_skeletonless_type_units (dwarf2_per_objfile
);
7792 /* Now that all TUs have been processed we can fill in the dependencies. */
7793 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
7795 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
.get (),
7796 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
7799 if (dwarf_read_debug
)
7800 print_tu_stats (dwarf2_per_objfile
);
7802 set_partial_user (dwarf2_per_objfile
);
7804 objfile
->partial_symtabs
->psymtabs_addrmap
7805 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
7806 objfile
->partial_symtabs
->obstack ());
7807 /* At this point we want to keep the address map. */
7808 save_psymtabs_addrmap
.release ();
7810 if (dwarf_read_debug
)
7811 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
7812 objfile_name (objfile
));
7815 /* Load the partial DIEs for a secondary CU into memory.
7816 This is also used when rereading a primary CU with load_all_dies. */
7819 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
7821 cutu_reader
reader (this_cu
, NULL
, 1, false);
7823 if (!reader
.dummy_p
)
7825 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
7828 /* Check if comp unit has_children.
7829 If so, read the rest of the partial symbols from this comp unit.
7830 If not, there's no more debug_info for this comp unit. */
7831 if (reader
.comp_unit_die
->has_children
)
7832 load_partial_dies (&reader
, reader
.info_ptr
, 0);
7839 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
7840 struct dwarf2_section_info
*section
,
7841 struct dwarf2_section_info
*abbrev_section
,
7842 unsigned int is_dwz
)
7844 const gdb_byte
*info_ptr
;
7845 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7847 if (dwarf_read_debug
)
7848 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
7849 section
->get_name (),
7850 section
->get_file_name ());
7852 section
->read (objfile
);
7854 info_ptr
= section
->buffer
;
7856 while (info_ptr
< section
->buffer
+ section
->size
)
7858 struct dwarf2_per_cu_data
*this_cu
;
7860 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
7862 comp_unit_head cu_header
;
7863 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
7864 abbrev_section
, info_ptr
,
7865 rcuh_kind::COMPILE
);
7867 /* Save the compilation unit for later lookup. */
7868 if (cu_header
.unit_type
!= DW_UT_type
)
7870 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
7871 struct dwarf2_per_cu_data
);
7872 memset (this_cu
, 0, sizeof (*this_cu
));
7876 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
7877 struct signatured_type
);
7878 memset (sig_type
, 0, sizeof (*sig_type
));
7879 sig_type
->signature
= cu_header
.signature
;
7880 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
7881 this_cu
= &sig_type
->per_cu
;
7883 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
7884 this_cu
->sect_off
= sect_off
;
7885 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
7886 this_cu
->is_dwz
= is_dwz
;
7887 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7888 this_cu
->section
= section
;
7890 dwarf2_per_objfile
->all_comp_units
.push_back (this_cu
);
7892 info_ptr
= info_ptr
+ this_cu
->length
;
7896 /* Create a list of all compilation units in OBJFILE.
7897 This is only done for -readnow and building partial symtabs. */
7900 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7902 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
7903 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->info
,
7904 &dwarf2_per_objfile
->abbrev
, 0);
7906 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
7908 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
7912 /* Process all loaded DIEs for compilation unit CU, starting at
7913 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
7914 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
7915 DW_AT_ranges). See the comments of add_partial_subprogram on how
7916 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
7919 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
7920 CORE_ADDR
*highpc
, int set_addrmap
,
7921 struct dwarf2_cu
*cu
)
7923 struct partial_die_info
*pdi
;
7925 /* Now, march along the PDI's, descending into ones which have
7926 interesting children but skipping the children of the other ones,
7927 until we reach the end of the compilation unit. */
7935 /* Anonymous namespaces or modules have no name but have interesting
7936 children, so we need to look at them. Ditto for anonymous
7939 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
7940 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
7941 || pdi
->tag
== DW_TAG_imported_unit
7942 || pdi
->tag
== DW_TAG_inlined_subroutine
)
7946 case DW_TAG_subprogram
:
7947 case DW_TAG_inlined_subroutine
:
7948 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7950 case DW_TAG_constant
:
7951 case DW_TAG_variable
:
7952 case DW_TAG_typedef
:
7953 case DW_TAG_union_type
:
7954 if (!pdi
->is_declaration
)
7956 add_partial_symbol (pdi
, cu
);
7959 case DW_TAG_class_type
:
7960 case DW_TAG_interface_type
:
7961 case DW_TAG_structure_type
:
7962 if (!pdi
->is_declaration
)
7964 add_partial_symbol (pdi
, cu
);
7966 if ((cu
->language
== language_rust
7967 || cu
->language
== language_cplus
) && pdi
->has_children
)
7968 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
7971 case DW_TAG_enumeration_type
:
7972 if (!pdi
->is_declaration
)
7973 add_partial_enumeration (pdi
, cu
);
7975 case DW_TAG_base_type
:
7976 case DW_TAG_subrange_type
:
7977 /* File scope base type definitions are added to the partial
7979 add_partial_symbol (pdi
, cu
);
7981 case DW_TAG_namespace
:
7982 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7985 if (!pdi
->is_declaration
)
7986 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7988 case DW_TAG_imported_unit
:
7990 struct dwarf2_per_cu_data
*per_cu
;
7992 /* For now we don't handle imported units in type units. */
7993 if (cu
->per_cu
->is_debug_types
)
7995 error (_("Dwarf Error: DW_TAG_imported_unit is not"
7996 " supported in type units [in module %s]"),
7997 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
8000 per_cu
= dwarf2_find_containing_comp_unit
8001 (pdi
->d
.sect_off
, pdi
->is_dwz
,
8002 cu
->per_cu
->dwarf2_per_objfile
);
8004 /* Go read the partial unit, if needed. */
8005 if (per_cu
->v
.psymtab
== NULL
)
8006 process_psymtab_comp_unit (per_cu
, true, cu
->language
);
8008 cu
->per_cu
->imported_symtabs_push (per_cu
);
8011 case DW_TAG_imported_declaration
:
8012 add_partial_symbol (pdi
, cu
);
8019 /* If the die has a sibling, skip to the sibling. */
8021 pdi
= pdi
->die_sibling
;
8025 /* Functions used to compute the fully scoped name of a partial DIE.
8027 Normally, this is simple. For C++, the parent DIE's fully scoped
8028 name is concatenated with "::" and the partial DIE's name.
8029 Enumerators are an exception; they use the scope of their parent
8030 enumeration type, i.e. the name of the enumeration type is not
8031 prepended to the enumerator.
8033 There are two complexities. One is DW_AT_specification; in this
8034 case "parent" means the parent of the target of the specification,
8035 instead of the direct parent of the DIE. The other is compilers
8036 which do not emit DW_TAG_namespace; in this case we try to guess
8037 the fully qualified name of structure types from their members'
8038 linkage names. This must be done using the DIE's children rather
8039 than the children of any DW_AT_specification target. We only need
8040 to do this for structures at the top level, i.e. if the target of
8041 any DW_AT_specification (if any; otherwise the DIE itself) does not
8044 /* Compute the scope prefix associated with PDI's parent, in
8045 compilation unit CU. The result will be allocated on CU's
8046 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8047 field. NULL is returned if no prefix is necessary. */
8049 partial_die_parent_scope (struct partial_die_info
*pdi
,
8050 struct dwarf2_cu
*cu
)
8052 const char *grandparent_scope
;
8053 struct partial_die_info
*parent
, *real_pdi
;
8055 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8056 then this means the parent of the specification DIE. */
8059 while (real_pdi
->has_specification
)
8061 auto res
= find_partial_die (real_pdi
->spec_offset
,
8062 real_pdi
->spec_is_dwz
, cu
);
8067 parent
= real_pdi
->die_parent
;
8071 if (parent
->scope_set
)
8072 return parent
->scope
;
8076 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8078 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8079 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8080 Work around this problem here. */
8081 if (cu
->language
== language_cplus
8082 && parent
->tag
== DW_TAG_namespace
8083 && strcmp (parent
->name
, "::") == 0
8084 && grandparent_scope
== NULL
)
8086 parent
->scope
= NULL
;
8087 parent
->scope_set
= 1;
8091 /* Nested subroutines in Fortran get a prefix. */
8092 if (pdi
->tag
== DW_TAG_enumerator
)
8093 /* Enumerators should not get the name of the enumeration as a prefix. */
8094 parent
->scope
= grandparent_scope
;
8095 else if (parent
->tag
== DW_TAG_namespace
8096 || parent
->tag
== DW_TAG_module
8097 || parent
->tag
== DW_TAG_structure_type
8098 || parent
->tag
== DW_TAG_class_type
8099 || parent
->tag
== DW_TAG_interface_type
8100 || parent
->tag
== DW_TAG_union_type
8101 || parent
->tag
== DW_TAG_enumeration_type
8102 || (cu
->language
== language_fortran
8103 && parent
->tag
== DW_TAG_subprogram
8104 && pdi
->tag
== DW_TAG_subprogram
))
8106 if (grandparent_scope
== NULL
)
8107 parent
->scope
= parent
->name
;
8109 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8111 parent
->name
, 0, cu
);
8115 /* FIXME drow/2004-04-01: What should we be doing with
8116 function-local names? For partial symbols, we should probably be
8118 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8119 dwarf_tag_name (parent
->tag
),
8120 sect_offset_str (pdi
->sect_off
));
8121 parent
->scope
= grandparent_scope
;
8124 parent
->scope_set
= 1;
8125 return parent
->scope
;
8128 /* Return the fully scoped name associated with PDI, from compilation unit
8129 CU. The result will be allocated with malloc. */
8131 static gdb::unique_xmalloc_ptr
<char>
8132 partial_die_full_name (struct partial_die_info
*pdi
,
8133 struct dwarf2_cu
*cu
)
8135 const char *parent_scope
;
8137 /* If this is a template instantiation, we can not work out the
8138 template arguments from partial DIEs. So, unfortunately, we have
8139 to go through the full DIEs. At least any work we do building
8140 types here will be reused if full symbols are loaded later. */
8141 if (pdi
->has_template_arguments
)
8145 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
8147 struct die_info
*die
;
8148 struct attribute attr
;
8149 struct dwarf2_cu
*ref_cu
= cu
;
8151 /* DW_FORM_ref_addr is using section offset. */
8152 attr
.name
= (enum dwarf_attribute
) 0;
8153 attr
.form
= DW_FORM_ref_addr
;
8154 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8155 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8157 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8161 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8162 if (parent_scope
== NULL
)
8165 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8170 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8172 struct dwarf2_per_objfile
*dwarf2_per_objfile
8173 = cu
->per_cu
->dwarf2_per_objfile
;
8174 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8175 struct gdbarch
*gdbarch
= objfile
->arch ();
8177 const char *actual_name
= NULL
;
8180 baseaddr
= objfile
->text_section_offset ();
8182 gdb::unique_xmalloc_ptr
<char> built_actual_name
8183 = partial_die_full_name (pdi
, cu
);
8184 if (built_actual_name
!= NULL
)
8185 actual_name
= built_actual_name
.get ();
8187 if (actual_name
== NULL
)
8188 actual_name
= pdi
->name
;
8192 case DW_TAG_inlined_subroutine
:
8193 case DW_TAG_subprogram
:
8194 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8196 if (pdi
->is_external
8197 || cu
->language
== language_ada
8198 || (cu
->language
== language_fortran
8199 && pdi
->die_parent
!= NULL
8200 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8202 /* Normally, only "external" DIEs are part of the global scope.
8203 But in Ada and Fortran, we want to be able to access nested
8204 procedures globally. So all Ada and Fortran subprograms are
8205 stored in the global scope. */
8206 add_psymbol_to_list (actual_name
,
8207 built_actual_name
!= NULL
,
8208 VAR_DOMAIN
, LOC_BLOCK
,
8209 SECT_OFF_TEXT (objfile
),
8210 psymbol_placement::GLOBAL
,
8212 cu
->language
, objfile
);
8216 add_psymbol_to_list (actual_name
,
8217 built_actual_name
!= NULL
,
8218 VAR_DOMAIN
, LOC_BLOCK
,
8219 SECT_OFF_TEXT (objfile
),
8220 psymbol_placement::STATIC
,
8221 addr
, cu
->language
, objfile
);
8224 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8225 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8227 case DW_TAG_constant
:
8228 add_psymbol_to_list (actual_name
,
8229 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
8230 -1, (pdi
->is_external
8231 ? psymbol_placement::GLOBAL
8232 : psymbol_placement::STATIC
),
8233 0, cu
->language
, objfile
);
8235 case DW_TAG_variable
:
8237 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8241 && !dwarf2_per_objfile
->has_section_at_zero
)
8243 /* A global or static variable may also have been stripped
8244 out by the linker if unused, in which case its address
8245 will be nullified; do not add such variables into partial
8246 symbol table then. */
8248 else if (pdi
->is_external
)
8251 Don't enter into the minimal symbol tables as there is
8252 a minimal symbol table entry from the ELF symbols already.
8253 Enter into partial symbol table if it has a location
8254 descriptor or a type.
8255 If the location descriptor is missing, new_symbol will create
8256 a LOC_UNRESOLVED symbol, the address of the variable will then
8257 be determined from the minimal symbol table whenever the variable
8259 The address for the partial symbol table entry is not
8260 used by GDB, but it comes in handy for debugging partial symbol
8263 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8264 add_psymbol_to_list (actual_name
,
8265 built_actual_name
!= NULL
,
8266 VAR_DOMAIN
, LOC_STATIC
,
8267 SECT_OFF_TEXT (objfile
),
8268 psymbol_placement::GLOBAL
,
8269 addr
, cu
->language
, objfile
);
8273 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8275 /* Static Variable. Skip symbols whose value we cannot know (those
8276 without location descriptors or constant values). */
8277 if (!has_loc
&& !pdi
->has_const_value
)
8280 add_psymbol_to_list (actual_name
,
8281 built_actual_name
!= NULL
,
8282 VAR_DOMAIN
, LOC_STATIC
,
8283 SECT_OFF_TEXT (objfile
),
8284 psymbol_placement::STATIC
,
8286 cu
->language
, objfile
);
8289 case DW_TAG_typedef
:
8290 case DW_TAG_base_type
:
8291 case DW_TAG_subrange_type
:
8292 add_psymbol_to_list (actual_name
,
8293 built_actual_name
!= NULL
,
8294 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
8295 psymbol_placement::STATIC
,
8296 0, cu
->language
, objfile
);
8298 case DW_TAG_imported_declaration
:
8299 case DW_TAG_namespace
:
8300 add_psymbol_to_list (actual_name
,
8301 built_actual_name
!= NULL
,
8302 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
8303 psymbol_placement::GLOBAL
,
8304 0, cu
->language
, objfile
);
8307 /* With Fortran 77 there might be a "BLOCK DATA" module
8308 available without any name. If so, we skip the module as it
8309 doesn't bring any value. */
8310 if (actual_name
!= nullptr)
8311 add_psymbol_to_list (actual_name
,
8312 built_actual_name
!= NULL
,
8313 MODULE_DOMAIN
, LOC_TYPEDEF
, -1,
8314 psymbol_placement::GLOBAL
,
8315 0, cu
->language
, objfile
);
8317 case DW_TAG_class_type
:
8318 case DW_TAG_interface_type
:
8319 case DW_TAG_structure_type
:
8320 case DW_TAG_union_type
:
8321 case DW_TAG_enumeration_type
:
8322 /* Skip external references. The DWARF standard says in the section
8323 about "Structure, Union, and Class Type Entries": "An incomplete
8324 structure, union or class type is represented by a structure,
8325 union or class entry that does not have a byte size attribute
8326 and that has a DW_AT_declaration attribute." */
8327 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8330 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8331 static vs. global. */
8332 add_psymbol_to_list (actual_name
,
8333 built_actual_name
!= NULL
,
8334 STRUCT_DOMAIN
, LOC_TYPEDEF
, -1,
8335 cu
->language
== language_cplus
8336 ? psymbol_placement::GLOBAL
8337 : psymbol_placement::STATIC
,
8338 0, cu
->language
, objfile
);
8341 case DW_TAG_enumerator
:
8342 add_psymbol_to_list (actual_name
,
8343 built_actual_name
!= NULL
,
8344 VAR_DOMAIN
, LOC_CONST
, -1,
8345 cu
->language
== language_cplus
8346 ? psymbol_placement::GLOBAL
8347 : psymbol_placement::STATIC
,
8348 0, cu
->language
, objfile
);
8355 /* Read a partial die corresponding to a namespace; also, add a symbol
8356 corresponding to that namespace to the symbol table. NAMESPACE is
8357 the name of the enclosing namespace. */
8360 add_partial_namespace (struct partial_die_info
*pdi
,
8361 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8362 int set_addrmap
, struct dwarf2_cu
*cu
)
8364 /* Add a symbol for the namespace. */
8366 add_partial_symbol (pdi
, cu
);
8368 /* Now scan partial symbols in that namespace. */
8370 if (pdi
->has_children
)
8371 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8374 /* Read a partial die corresponding to a Fortran module. */
8377 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8378 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8380 /* Add a symbol for the namespace. */
8382 add_partial_symbol (pdi
, cu
);
8384 /* Now scan partial symbols in that module. */
8386 if (pdi
->has_children
)
8387 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8390 /* Read a partial die corresponding to a subprogram or an inlined
8391 subprogram and create a partial symbol for that subprogram.
8392 When the CU language allows it, this routine also defines a partial
8393 symbol for each nested subprogram that this subprogram contains.
8394 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8395 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8397 PDI may also be a lexical block, in which case we simply search
8398 recursively for subprograms defined inside that lexical block.
8399 Again, this is only performed when the CU language allows this
8400 type of definitions. */
8403 add_partial_subprogram (struct partial_die_info
*pdi
,
8404 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8405 int set_addrmap
, struct dwarf2_cu
*cu
)
8407 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8409 if (pdi
->has_pc_info
)
8411 if (pdi
->lowpc
< *lowpc
)
8412 *lowpc
= pdi
->lowpc
;
8413 if (pdi
->highpc
> *highpc
)
8414 *highpc
= pdi
->highpc
;
8417 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
8418 struct gdbarch
*gdbarch
= objfile
->arch ();
8420 CORE_ADDR this_highpc
;
8421 CORE_ADDR this_lowpc
;
8423 baseaddr
= objfile
->text_section_offset ();
8425 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8426 pdi
->lowpc
+ baseaddr
)
8429 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8430 pdi
->highpc
+ baseaddr
)
8432 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8433 this_lowpc
, this_highpc
- 1,
8434 cu
->per_cu
->v
.psymtab
);
8438 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8440 if (!pdi
->is_declaration
)
8441 /* Ignore subprogram DIEs that do not have a name, they are
8442 illegal. Do not emit a complaint at this point, we will
8443 do so when we convert this psymtab into a symtab. */
8445 add_partial_symbol (pdi
, cu
);
8449 if (! pdi
->has_children
)
8452 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
8454 pdi
= pdi
->die_child
;
8458 if (pdi
->tag
== DW_TAG_subprogram
8459 || pdi
->tag
== DW_TAG_inlined_subroutine
8460 || pdi
->tag
== DW_TAG_lexical_block
)
8461 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8462 pdi
= pdi
->die_sibling
;
8467 /* Read a partial die corresponding to an enumeration type. */
8470 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8471 struct dwarf2_cu
*cu
)
8473 struct partial_die_info
*pdi
;
8475 if (enum_pdi
->name
!= NULL
)
8476 add_partial_symbol (enum_pdi
, cu
);
8478 pdi
= enum_pdi
->die_child
;
8481 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
8482 complaint (_("malformed enumerator DIE ignored"));
8484 add_partial_symbol (pdi
, cu
);
8485 pdi
= pdi
->die_sibling
;
8489 /* Return the initial uleb128 in the die at INFO_PTR. */
8492 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8494 unsigned int bytes_read
;
8496 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8499 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8500 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8502 Return the corresponding abbrev, or NULL if the number is zero (indicating
8503 an empty DIE). In either case *BYTES_READ will be set to the length of
8504 the initial number. */
8506 static struct abbrev_info
*
8507 peek_die_abbrev (const die_reader_specs
&reader
,
8508 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8510 dwarf2_cu
*cu
= reader
.cu
;
8511 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
8512 unsigned int abbrev_number
8513 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8515 if (abbrev_number
== 0)
8518 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8521 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8522 " at offset %s [in module %s]"),
8523 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8524 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8530 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8531 Returns a pointer to the end of a series of DIEs, terminated by an empty
8532 DIE. Any children of the skipped DIEs will also be skipped. */
8534 static const gdb_byte
*
8535 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8539 unsigned int bytes_read
;
8540 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
8543 return info_ptr
+ bytes_read
;
8545 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8549 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8550 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8551 abbrev corresponding to that skipped uleb128 should be passed in
8552 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8555 static const gdb_byte
*
8556 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8557 struct abbrev_info
*abbrev
)
8559 unsigned int bytes_read
;
8560 struct attribute attr
;
8561 bfd
*abfd
= reader
->abfd
;
8562 struct dwarf2_cu
*cu
= reader
->cu
;
8563 const gdb_byte
*buffer
= reader
->buffer
;
8564 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8565 unsigned int form
, i
;
8567 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8569 /* The only abbrev we care about is DW_AT_sibling. */
8570 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8573 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
,
8575 if (attr
.form
== DW_FORM_ref_addr
)
8576 complaint (_("ignoring absolute DW_AT_sibling"));
8579 sect_offset off
= attr
.get_ref_die_offset ();
8580 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8582 if (sibling_ptr
< info_ptr
)
8583 complaint (_("DW_AT_sibling points backwards"));
8584 else if (sibling_ptr
> reader
->buffer_end
)
8585 reader
->die_section
->overflow_complaint ();
8591 /* If it isn't DW_AT_sibling, skip this attribute. */
8592 form
= abbrev
->attrs
[i
].form
;
8596 case DW_FORM_ref_addr
:
8597 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8598 and later it is offset sized. */
8599 if (cu
->header
.version
== 2)
8600 info_ptr
+= cu
->header
.addr_size
;
8602 info_ptr
+= cu
->header
.offset_size
;
8604 case DW_FORM_GNU_ref_alt
:
8605 info_ptr
+= cu
->header
.offset_size
;
8608 info_ptr
+= cu
->header
.addr_size
;
8616 case DW_FORM_flag_present
:
8617 case DW_FORM_implicit_const
:
8634 case DW_FORM_ref_sig8
:
8637 case DW_FORM_data16
:
8640 case DW_FORM_string
:
8641 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8642 info_ptr
+= bytes_read
;
8644 case DW_FORM_sec_offset
:
8646 case DW_FORM_GNU_strp_alt
:
8647 info_ptr
+= cu
->header
.offset_size
;
8649 case DW_FORM_exprloc
:
8651 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8652 info_ptr
+= bytes_read
;
8654 case DW_FORM_block1
:
8655 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8657 case DW_FORM_block2
:
8658 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8660 case DW_FORM_block4
:
8661 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8667 case DW_FORM_ref_udata
:
8668 case DW_FORM_GNU_addr_index
:
8669 case DW_FORM_GNU_str_index
:
8670 case DW_FORM_rnglistx
:
8671 case DW_FORM_loclistx
:
8672 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8674 case DW_FORM_indirect
:
8675 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8676 info_ptr
+= bytes_read
;
8677 /* We need to continue parsing from here, so just go back to
8679 goto skip_attribute
;
8682 error (_("Dwarf Error: Cannot handle %s "
8683 "in DWARF reader [in module %s]"),
8684 dwarf_form_name (form
),
8685 bfd_get_filename (abfd
));
8689 if (abbrev
->has_children
)
8690 return skip_children (reader
, info_ptr
);
8695 /* Locate ORIG_PDI's sibling.
8696 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8698 static const gdb_byte
*
8699 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8700 struct partial_die_info
*orig_pdi
,
8701 const gdb_byte
*info_ptr
)
8703 /* Do we know the sibling already? */
8705 if (orig_pdi
->sibling
)
8706 return orig_pdi
->sibling
;
8708 /* Are there any children to deal with? */
8710 if (!orig_pdi
->has_children
)
8713 /* Skip the children the long way. */
8715 return skip_children (reader
, info_ptr
);
8718 /* Expand this partial symbol table into a full symbol table. SELF is
8722 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
8724 struct dwarf2_per_objfile
*dwarf2_per_objfile
8725 = get_dwarf2_per_objfile (objfile
);
8727 gdb_assert (!readin
);
8728 /* If this psymtab is constructed from a debug-only objfile, the
8729 has_section_at_zero flag will not necessarily be correct. We
8730 can get the correct value for this flag by looking at the data
8731 associated with the (presumably stripped) associated objfile. */
8732 if (objfile
->separate_debug_objfile_backlink
)
8734 struct dwarf2_per_objfile
*dpo_backlink
8735 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
8737 dwarf2_per_objfile
->has_section_at_zero
8738 = dpo_backlink
->has_section_at_zero
;
8741 expand_psymtab (objfile
);
8743 process_cu_includes (dwarf2_per_objfile
);
8746 /* Reading in full CUs. */
8748 /* Add PER_CU to the queue. */
8751 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
8752 enum language pretend_language
)
8755 per_cu
->dwarf2_per_objfile
->queue
.emplace (per_cu
, pretend_language
);
8758 /* If PER_CU is not yet queued, add it to the queue.
8759 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
8761 The result is non-zero if PER_CU was queued, otherwise the result is zero
8762 meaning either PER_CU is already queued or it is already loaded.
8764 N.B. There is an invariant here that if a CU is queued then it is loaded.
8765 The caller is required to load PER_CU if we return non-zero. */
8768 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
8769 struct dwarf2_per_cu_data
*per_cu
,
8770 enum language pretend_language
)
8772 /* We may arrive here during partial symbol reading, if we need full
8773 DIEs to process an unusual case (e.g. template arguments). Do
8774 not queue PER_CU, just tell our caller to load its DIEs. */
8775 if (per_cu
->dwarf2_per_objfile
->reading_partial_symbols
)
8777 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
8782 /* Mark the dependence relation so that we don't flush PER_CU
8784 if (dependent_cu
!= NULL
)
8785 dwarf2_add_dependence (dependent_cu
, per_cu
);
8787 /* If it's already on the queue, we have nothing to do. */
8791 /* If the compilation unit is already loaded, just mark it as
8793 if (per_cu
->cu
!= NULL
)
8795 per_cu
->cu
->last_used
= 0;
8799 /* Add it to the queue. */
8800 queue_comp_unit (per_cu
, pretend_language
);
8805 /* Process the queue. */
8808 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8810 if (dwarf_read_debug
)
8812 fprintf_unfiltered (gdb_stdlog
,
8813 "Expanding one or more symtabs of objfile %s ...\n",
8814 objfile_name (dwarf2_per_objfile
->objfile
));
8817 /* The queue starts out with one item, but following a DIE reference
8818 may load a new CU, adding it to the end of the queue. */
8819 while (!dwarf2_per_objfile
->queue
.empty ())
8821 dwarf2_queue_item
&item
= dwarf2_per_objfile
->queue
.front ();
8823 if ((dwarf2_per_objfile
->using_index
8824 ? !item
.per_cu
->v
.quick
->compunit_symtab
8825 : (item
.per_cu
->v
.psymtab
&& !item
.per_cu
->v
.psymtab
->readin
))
8826 /* Skip dummy CUs. */
8827 && item
.per_cu
->cu
!= NULL
)
8829 struct dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
8830 unsigned int debug_print_threshold
;
8833 if (per_cu
->is_debug_types
)
8835 struct signatured_type
*sig_type
=
8836 (struct signatured_type
*) per_cu
;
8838 sprintf (buf
, "TU %s at offset %s",
8839 hex_string (sig_type
->signature
),
8840 sect_offset_str (per_cu
->sect_off
));
8841 /* There can be 100s of TUs.
8842 Only print them in verbose mode. */
8843 debug_print_threshold
= 2;
8847 sprintf (buf
, "CU at offset %s",
8848 sect_offset_str (per_cu
->sect_off
));
8849 debug_print_threshold
= 1;
8852 if (dwarf_read_debug
>= debug_print_threshold
)
8853 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
8855 if (per_cu
->is_debug_types
)
8856 process_full_type_unit (per_cu
, item
.pretend_language
);
8858 process_full_comp_unit (per_cu
, item
.pretend_language
);
8860 if (dwarf_read_debug
>= debug_print_threshold
)
8861 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
8864 item
.per_cu
->queued
= 0;
8865 dwarf2_per_objfile
->queue
.pop ();
8868 if (dwarf_read_debug
)
8870 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
8871 objfile_name (dwarf2_per_objfile
->objfile
));
8875 /* Read in full symbols for PST, and anything it depends on. */
8878 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
8880 gdb_assert (!readin
);
8882 expand_dependencies (objfile
);
8884 dw2_do_instantiate_symtab (per_cu_data
, false);
8885 gdb_assert (get_compunit_symtab () != nullptr);
8888 /* Trivial hash function for die_info: the hash value of a DIE
8889 is its offset in .debug_info for this objfile. */
8892 die_hash (const void *item
)
8894 const struct die_info
*die
= (const struct die_info
*) item
;
8896 return to_underlying (die
->sect_off
);
8899 /* Trivial comparison function for die_info structures: two DIEs
8900 are equal if they have the same offset. */
8903 die_eq (const void *item_lhs
, const void *item_rhs
)
8905 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
8906 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
8908 return die_lhs
->sect_off
== die_rhs
->sect_off
;
8911 /* Load the DIEs associated with PER_CU into memory. */
8914 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8916 enum language pretend_language
)
8918 gdb_assert (! this_cu
->is_debug_types
);
8920 cutu_reader
reader (this_cu
, NULL
, 1, skip_partial
);
8924 struct dwarf2_cu
*cu
= reader
.cu
;
8925 const gdb_byte
*info_ptr
= reader
.info_ptr
;
8927 gdb_assert (cu
->die_hash
== NULL
);
8929 htab_create_alloc_ex (cu
->header
.length
/ 12,
8933 &cu
->comp_unit_obstack
,
8934 hashtab_obstack_allocate
,
8935 dummy_obstack_deallocate
);
8937 if (reader
.comp_unit_die
->has_children
)
8938 reader
.comp_unit_die
->child
8939 = read_die_and_siblings (&reader
, reader
.info_ptr
,
8940 &info_ptr
, reader
.comp_unit_die
);
8941 cu
->dies
= reader
.comp_unit_die
;
8942 /* comp_unit_die is not stored in die_hash, no need. */
8944 /* We try not to read any attributes in this function, because not
8945 all CUs needed for references have been loaded yet, and symbol
8946 table processing isn't initialized. But we have to set the CU language,
8947 or we won't be able to build types correctly.
8948 Similarly, if we do not read the producer, we can not apply
8949 producer-specific interpretation. */
8950 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
8955 /* Add a DIE to the delayed physname list. */
8958 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
8959 const char *name
, struct die_info
*die
,
8960 struct dwarf2_cu
*cu
)
8962 struct delayed_method_info mi
;
8964 mi
.fnfield_index
= fnfield_index
;
8968 cu
->method_list
.push_back (mi
);
8971 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
8972 "const" / "volatile". If so, decrements LEN by the length of the
8973 modifier and return true. Otherwise return false. */
8977 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
8979 size_t mod_len
= sizeof (mod
) - 1;
8980 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
8988 /* Compute the physnames of any methods on the CU's method list.
8990 The computation of method physnames is delayed in order to avoid the
8991 (bad) condition that one of the method's formal parameters is of an as yet
8995 compute_delayed_physnames (struct dwarf2_cu
*cu
)
8997 /* Only C++ delays computing physnames. */
8998 if (cu
->method_list
.empty ())
9000 gdb_assert (cu
->language
== language_cplus
);
9002 for (const delayed_method_info
&mi
: cu
->method_list
)
9004 const char *physname
;
9005 struct fn_fieldlist
*fn_flp
9006 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9007 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9008 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9009 = physname
? physname
: "";
9011 /* Since there's no tag to indicate whether a method is a
9012 const/volatile overload, extract that information out of the
9014 if (physname
!= NULL
)
9016 size_t len
= strlen (physname
);
9020 if (physname
[len
] == ')') /* shortcut */
9022 else if (check_modifier (physname
, len
, " const"))
9023 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9024 else if (check_modifier (physname
, len
, " volatile"))
9025 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9032 /* The list is no longer needed. */
9033 cu
->method_list
.clear ();
9036 /* Go objects should be embedded in a DW_TAG_module DIE,
9037 and it's not clear if/how imported objects will appear.
9038 To keep Go support simple until that's worked out,
9039 go back through what we've read and create something usable.
9040 We could do this while processing each DIE, and feels kinda cleaner,
9041 but that way is more invasive.
9042 This is to, for example, allow the user to type "p var" or "b main"
9043 without having to specify the package name, and allow lookups
9044 of module.object to work in contexts that use the expression
9048 fixup_go_packaging (struct dwarf2_cu
*cu
)
9050 gdb::unique_xmalloc_ptr
<char> package_name
;
9051 struct pending
*list
;
9054 for (list
= *cu
->get_builder ()->get_global_symbols ();
9058 for (i
= 0; i
< list
->nsyms
; ++i
)
9060 struct symbol
*sym
= list
->symbol
[i
];
9062 if (sym
->language () == language_go
9063 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9065 gdb::unique_xmalloc_ptr
<char> this_package_name
9066 (go_symbol_package_name (sym
));
9068 if (this_package_name
== NULL
)
9070 if (package_name
== NULL
)
9071 package_name
= std::move (this_package_name
);
9074 struct objfile
*objfile
9075 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9076 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9077 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9078 (symbol_symtab (sym
) != NULL
9079 ? symtab_to_filename_for_display
9080 (symbol_symtab (sym
))
9081 : objfile_name (objfile
)),
9082 this_package_name
.get (), package_name
.get ());
9088 if (package_name
!= NULL
)
9090 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9091 const char *saved_package_name
= objfile
->intern (package_name
.get ());
9092 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9093 saved_package_name
);
9096 sym
= allocate_symbol (objfile
);
9097 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9098 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9099 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9100 e.g., "main" finds the "main" module and not C's main(). */
9101 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9102 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9103 SYMBOL_TYPE (sym
) = type
;
9105 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9109 /* Allocate a fully-qualified name consisting of the two parts on the
9113 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9115 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9118 /* A helper that allocates a struct discriminant_info to attach to a
9121 static struct discriminant_info
*
9122 alloc_discriminant_info (struct type
*type
, int discriminant_index
,
9125 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9126 gdb_assert (discriminant_index
== -1
9127 || (discriminant_index
>= 0
9128 && discriminant_index
< TYPE_NFIELDS (type
)));
9129 gdb_assert (default_index
== -1
9130 || (default_index
>= 0 && default_index
< TYPE_NFIELDS (type
)));
9132 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
9134 struct discriminant_info
*disc
9135 = ((struct discriminant_info
*)
9137 offsetof (struct discriminant_info
, discriminants
)
9138 + TYPE_NFIELDS (type
) * sizeof (disc
->discriminants
[0])));
9139 disc
->default_index
= default_index
;
9140 disc
->discriminant_index
= discriminant_index
;
9142 struct dynamic_prop prop
;
9143 prop
.kind
= PROP_UNDEFINED
;
9144 prop
.data
.baton
= disc
;
9146 add_dyn_prop (DYN_PROP_DISCRIMINATED
, prop
, type
);
9151 /* Some versions of rustc emitted enums in an unusual way.
9153 Ordinary enums were emitted as unions. The first element of each
9154 structure in the union was named "RUST$ENUM$DISR". This element
9155 held the discriminant.
9157 These versions of Rust also implemented the "non-zero"
9158 optimization. When the enum had two values, and one is empty and
9159 the other holds a pointer that cannot be zero, the pointer is used
9160 as the discriminant, with a zero value meaning the empty variant.
9161 Here, the union's first member is of the form
9162 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9163 where the fieldnos are the indices of the fields that should be
9164 traversed in order to find the field (which may be several fields deep)
9165 and the variantname is the name of the variant of the case when the
9168 This function recognizes whether TYPE is of one of these forms,
9169 and, if so, smashes it to be a variant type. */
9172 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9174 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9176 /* We don't need to deal with empty enums. */
9177 if (TYPE_NFIELDS (type
) == 0)
9180 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9181 if (TYPE_NFIELDS (type
) == 1
9182 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9184 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9186 /* Decode the field name to find the offset of the
9188 ULONGEST bit_offset
= 0;
9189 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9190 while (name
[0] >= '0' && name
[0] <= '9')
9193 unsigned long index
= strtoul (name
, &tail
, 10);
9196 || index
>= TYPE_NFIELDS (field_type
)
9197 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9198 != FIELD_LOC_KIND_BITPOS
))
9200 complaint (_("Could not parse Rust enum encoding string \"%s\""
9202 TYPE_FIELD_NAME (type
, 0),
9203 objfile_name (objfile
));
9208 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9209 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
9212 /* Make a union to hold the variants. */
9213 struct type
*union_type
= alloc_type (objfile
);
9214 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9215 TYPE_NFIELDS (union_type
) = 3;
9216 TYPE_FIELDS (union_type
)
9217 = (struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
));
9218 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9219 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9221 /* Put the discriminant must at index 0. */
9222 TYPE_FIELD_TYPE (union_type
, 0) = field_type
;
9223 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
9224 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
9225 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 0), bit_offset
);
9227 /* The order of fields doesn't really matter, so put the real
9228 field at index 1 and the data-less field at index 2. */
9229 struct discriminant_info
*disc
9230 = alloc_discriminant_info (union_type
, 0, 1);
9231 TYPE_FIELD (union_type
, 1) = TYPE_FIELD (type
, 0);
9232 TYPE_FIELD_NAME (union_type
, 1)
9233 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1)));
9234 TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1))
9235 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9236 TYPE_FIELD_NAME (union_type
, 1));
9238 const char *dataless_name
9239 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9241 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9243 TYPE_FIELD_TYPE (union_type
, 2) = dataless_type
;
9244 /* NAME points into the original discriminant name, which
9245 already has the correct lifetime. */
9246 TYPE_FIELD_NAME (union_type
, 2) = name
;
9247 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 2), 0);
9248 disc
->discriminants
[2] = 0;
9250 /* Smash this type to be a structure type. We have to do this
9251 because the type has already been recorded. */
9252 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9253 TYPE_NFIELDS (type
) = 1;
9255 = (struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
));
9257 /* Install the variant part. */
9258 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9259 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9260 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9262 /* A union with a single anonymous field is probably an old-style
9264 else if (TYPE_NFIELDS (type
) == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
9266 /* Smash this type to be a structure type. We have to do this
9267 because the type has already been recorded. */
9268 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9270 /* Make a union to hold the variants. */
9271 struct type
*union_type
= alloc_type (objfile
);
9272 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9273 TYPE_NFIELDS (union_type
) = TYPE_NFIELDS (type
);
9274 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9275 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9276 TYPE_FIELDS (union_type
) = TYPE_FIELDS (type
);
9278 struct type
*field_type
= TYPE_FIELD_TYPE (union_type
, 0);
9279 const char *variant_name
9280 = rust_last_path_segment (TYPE_NAME (field_type
));
9281 TYPE_FIELD_NAME (union_type
, 0) = variant_name
;
9282 TYPE_NAME (field_type
)
9283 = rust_fully_qualify (&objfile
->objfile_obstack
,
9284 TYPE_NAME (type
), variant_name
);
9286 /* Install the union in the outer struct type. */
9287 TYPE_NFIELDS (type
) = 1;
9289 = (struct field
*) TYPE_ZALLOC (union_type
, sizeof (struct field
));
9290 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9291 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9292 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9294 alloc_discriminant_info (union_type
, -1, 0);
9298 struct type
*disr_type
= nullptr;
9299 for (int i
= 0; i
< TYPE_NFIELDS (type
); ++i
)
9301 disr_type
= TYPE_FIELD_TYPE (type
, i
);
9303 if (TYPE_CODE (disr_type
) != TYPE_CODE_STRUCT
)
9305 /* All fields of a true enum will be structs. */
9308 else if (TYPE_NFIELDS (disr_type
) == 0)
9310 /* Could be data-less variant, so keep going. */
9311 disr_type
= nullptr;
9313 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9314 "RUST$ENUM$DISR") != 0)
9316 /* Not a Rust enum. */
9326 /* If we got here without a discriminant, then it's probably
9328 if (disr_type
== nullptr)
9331 /* Smash this type to be a structure type. We have to do this
9332 because the type has already been recorded. */
9333 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9335 /* Make a union to hold the variants. */
9336 struct field
*disr_field
= &TYPE_FIELD (disr_type
, 0);
9337 struct type
*union_type
= alloc_type (objfile
);
9338 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9339 TYPE_NFIELDS (union_type
) = 1 + TYPE_NFIELDS (type
);
9340 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9341 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9342 TYPE_FIELDS (union_type
)
9343 = (struct field
*) TYPE_ZALLOC (union_type
,
9344 (TYPE_NFIELDS (union_type
)
9345 * sizeof (struct field
)));
9347 memcpy (TYPE_FIELDS (union_type
) + 1, TYPE_FIELDS (type
),
9348 TYPE_NFIELDS (type
) * sizeof (struct field
));
9350 /* Install the discriminant at index 0 in the union. */
9351 TYPE_FIELD (union_type
, 0) = *disr_field
;
9352 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
9353 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
9355 /* Install the union in the outer struct type. */
9356 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9357 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9358 TYPE_NFIELDS (type
) = 1;
9360 /* Set the size and offset of the union type. */
9361 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9363 /* We need a way to find the correct discriminant given a
9364 variant name. For convenience we build a map here. */
9365 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
9366 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9367 for (int i
= 0; i
< TYPE_NFIELDS (enum_type
); ++i
)
9369 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9372 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9373 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9377 int n_fields
= TYPE_NFIELDS (union_type
);
9378 struct discriminant_info
*disc
9379 = alloc_discriminant_info (union_type
, 0, -1);
9380 /* Skip the discriminant here. */
9381 for (int i
= 1; i
< n_fields
; ++i
)
9383 /* Find the final word in the name of this variant's type.
9384 That name can be used to look up the correct
9386 const char *variant_name
9387 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
,
9390 auto iter
= discriminant_map
.find (variant_name
);
9391 if (iter
!= discriminant_map
.end ())
9392 disc
->discriminants
[i
] = iter
->second
;
9394 /* Remove the discriminant field, if it exists. */
9395 struct type
*sub_type
= TYPE_FIELD_TYPE (union_type
, i
);
9396 if (TYPE_NFIELDS (sub_type
) > 0)
9398 --TYPE_NFIELDS (sub_type
);
9399 ++TYPE_FIELDS (sub_type
);
9401 TYPE_FIELD_NAME (union_type
, i
) = variant_name
;
9402 TYPE_NAME (sub_type
)
9403 = rust_fully_qualify (&objfile
->objfile_obstack
,
9404 TYPE_NAME (type
), variant_name
);
9409 /* Rewrite some Rust unions to be structures with variants parts. */
9412 rust_union_quirks (struct dwarf2_cu
*cu
)
9414 gdb_assert (cu
->language
== language_rust
);
9415 for (type
*type_
: cu
->rust_unions
)
9416 quirk_rust_enum (type_
, cu
->per_cu
->dwarf2_per_objfile
->objfile
);
9417 /* We don't need this any more. */
9418 cu
->rust_unions
.clear ();
9421 /* Return the symtab for PER_CU. This works properly regardless of
9422 whether we're using the index or psymtabs. */
9424 static struct compunit_symtab
*
9425 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
9427 return (per_cu
->dwarf2_per_objfile
->using_index
9428 ? per_cu
->v
.quick
->compunit_symtab
9429 : per_cu
->v
.psymtab
->compunit_symtab
);
9432 /* A helper function for computing the list of all symbol tables
9433 included by PER_CU. */
9436 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9437 htab_t all_children
, htab_t all_type_symtabs
,
9438 struct dwarf2_per_cu_data
*per_cu
,
9439 struct compunit_symtab
*immediate_parent
)
9442 struct compunit_symtab
*cust
;
9444 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9447 /* This inclusion and its children have been processed. */
9452 /* Only add a CU if it has a symbol table. */
9453 cust
= get_compunit_symtab (per_cu
);
9456 /* If this is a type unit only add its symbol table if we haven't
9457 seen it yet (type unit per_cu's can share symtabs). */
9458 if (per_cu
->is_debug_types
)
9460 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9464 result
->push_back (cust
);
9465 if (cust
->user
== NULL
)
9466 cust
->user
= immediate_parent
;
9471 result
->push_back (cust
);
9472 if (cust
->user
== NULL
)
9473 cust
->user
= immediate_parent
;
9477 if (!per_cu
->imported_symtabs_empty ())
9478 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9480 recursively_compute_inclusions (result
, all_children
,
9481 all_type_symtabs
, ptr
, cust
);
9485 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9489 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
9491 gdb_assert (! per_cu
->is_debug_types
);
9493 if (!per_cu
->imported_symtabs_empty ())
9496 std::vector
<compunit_symtab
*> result_symtabs
;
9497 htab_t all_children
, all_type_symtabs
;
9498 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
9500 /* If we don't have a symtab, we can just skip this case. */
9504 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9505 NULL
, xcalloc
, xfree
);
9506 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9507 NULL
, xcalloc
, xfree
);
9509 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9511 recursively_compute_inclusions (&result_symtabs
, all_children
,
9512 all_type_symtabs
, ptr
, cust
);
9515 /* Now we have a transitive closure of all the included symtabs. */
9516 len
= result_symtabs
.size ();
9518 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
9519 struct compunit_symtab
*, len
+ 1);
9520 memcpy (cust
->includes
, result_symtabs
.data (),
9521 len
* sizeof (compunit_symtab
*));
9522 cust
->includes
[len
] = NULL
;
9524 htab_delete (all_children
);
9525 htab_delete (all_type_symtabs
);
9529 /* Compute the 'includes' field for the symtabs of all the CUs we just
9533 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9535 for (dwarf2_per_cu_data
*iter
: dwarf2_per_objfile
->just_read_cus
)
9537 if (! iter
->is_debug_types
)
9538 compute_compunit_symtab_includes (iter
);
9541 dwarf2_per_objfile
->just_read_cus
.clear ();
9544 /* Generate full symbol information for PER_CU, whose DIEs have
9545 already been loaded into memory. */
9548 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9549 enum language pretend_language
)
9551 struct dwarf2_cu
*cu
= per_cu
->cu
;
9552 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
9553 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9554 struct gdbarch
*gdbarch
= objfile
->arch ();
9555 CORE_ADDR lowpc
, highpc
;
9556 struct compunit_symtab
*cust
;
9558 struct block
*static_block
;
9561 baseaddr
= objfile
->text_section_offset ();
9563 /* Clear the list here in case something was left over. */
9564 cu
->method_list
.clear ();
9566 cu
->language
= pretend_language
;
9567 cu
->language_defn
= language_def (cu
->language
);
9569 /* Do line number decoding in read_file_scope () */
9570 process_die (cu
->dies
, cu
);
9572 /* For now fudge the Go package. */
9573 if (cu
->language
== language_go
)
9574 fixup_go_packaging (cu
);
9576 /* Now that we have processed all the DIEs in the CU, all the types
9577 should be complete, and it should now be safe to compute all of the
9579 compute_delayed_physnames (cu
);
9581 if (cu
->language
== language_rust
)
9582 rust_union_quirks (cu
);
9584 /* Some compilers don't define a DW_AT_high_pc attribute for the
9585 compilation unit. If the DW_AT_high_pc is missing, synthesize
9586 it, by scanning the DIE's below the compilation unit. */
9587 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9589 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9590 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
9592 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9593 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9594 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9595 addrmap to help ensure it has an accurate map of pc values belonging to
9597 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9599 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
9600 SECT_OFF_TEXT (objfile
),
9605 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9607 /* Set symtab language to language from DW_AT_language. If the
9608 compilation is from a C file generated by language preprocessors, do
9609 not set the language if it was already deduced by start_subfile. */
9610 if (!(cu
->language
== language_c
9611 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
9612 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9614 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9615 produce DW_AT_location with location lists but it can be possibly
9616 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9617 there were bugs in prologue debug info, fixed later in GCC-4.5
9618 by "unwind info for epilogues" patch (which is not directly related).
9620 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9621 needed, it would be wrong due to missing DW_AT_producer there.
9623 Still one can confuse GDB by using non-standard GCC compilation
9624 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9626 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9627 cust
->locations_valid
= 1;
9629 if (gcc_4_minor
>= 5)
9630 cust
->epilogue_unwind_valid
= 1;
9632 cust
->call_site_htab
= cu
->call_site_htab
;
9635 if (dwarf2_per_objfile
->using_index
)
9636 per_cu
->v
.quick
->compunit_symtab
= cust
;
9639 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
9640 pst
->compunit_symtab
= cust
;
9644 /* Push it for inclusion processing later. */
9645 dwarf2_per_objfile
->just_read_cus
.push_back (per_cu
);
9647 /* Not needed any more. */
9648 cu
->reset_builder ();
9651 /* Generate full symbol information for type unit PER_CU, whose DIEs have
9652 already been loaded into memory. */
9655 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
9656 enum language pretend_language
)
9658 struct dwarf2_cu
*cu
= per_cu
->cu
;
9659 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
9660 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9661 struct compunit_symtab
*cust
;
9662 struct signatured_type
*sig_type
;
9664 gdb_assert (per_cu
->is_debug_types
);
9665 sig_type
= (struct signatured_type
*) per_cu
;
9667 /* Clear the list here in case something was left over. */
9668 cu
->method_list
.clear ();
9670 cu
->language
= pretend_language
;
9671 cu
->language_defn
= language_def (cu
->language
);
9673 /* The symbol tables are set up in read_type_unit_scope. */
9674 process_die (cu
->dies
, cu
);
9676 /* For now fudge the Go package. */
9677 if (cu
->language
== language_go
)
9678 fixup_go_packaging (cu
);
9680 /* Now that we have processed all the DIEs in the CU, all the types
9681 should be complete, and it should now be safe to compute all of the
9683 compute_delayed_physnames (cu
);
9685 if (cu
->language
== language_rust
)
9686 rust_union_quirks (cu
);
9688 /* TUs share symbol tables.
9689 If this is the first TU to use this symtab, complete the construction
9690 of it with end_expandable_symtab. Otherwise, complete the addition of
9691 this TU's symbols to the existing symtab. */
9692 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
9694 buildsym_compunit
*builder
= cu
->get_builder ();
9695 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
9696 sig_type
->type_unit_group
->compunit_symtab
= cust
;
9700 /* Set symtab language to language from DW_AT_language. If the
9701 compilation is from a C file generated by language preprocessors,
9702 do not set the language if it was already deduced by
9704 if (!(cu
->language
== language_c
9705 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
9706 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9711 cu
->get_builder ()->augment_type_symtab ();
9712 cust
= sig_type
->type_unit_group
->compunit_symtab
;
9715 if (dwarf2_per_objfile
->using_index
)
9716 per_cu
->v
.quick
->compunit_symtab
= cust
;
9719 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
9720 pst
->compunit_symtab
= cust
;
9724 /* Not needed any more. */
9725 cu
->reset_builder ();
9728 /* Process an imported unit DIE. */
9731 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9733 struct attribute
*attr
;
9735 /* For now we don't handle imported units in type units. */
9736 if (cu
->per_cu
->is_debug_types
)
9738 error (_("Dwarf Error: DW_TAG_imported_unit is not"
9739 " supported in type units [in module %s]"),
9740 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
9743 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
9746 sect_offset sect_off
= attr
->get_ref_die_offset ();
9747 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
9748 dwarf2_per_cu_data
*per_cu
9749 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
9750 cu
->per_cu
->dwarf2_per_objfile
);
9752 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
9753 into another compilation unit, at root level. Regard this as a hint,
9755 if (die
->parent
&& die
->parent
->parent
== NULL
9756 && per_cu
->unit_type
== DW_UT_compile
9757 && per_cu
->lang
== language_cplus
)
9760 /* If necessary, add it to the queue and load its DIEs. */
9761 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
9762 load_full_comp_unit (per_cu
, false, cu
->language
);
9764 cu
->per_cu
->imported_symtabs_push (per_cu
);
9768 /* RAII object that represents a process_die scope: i.e.,
9769 starts/finishes processing a DIE. */
9770 class process_die_scope
9773 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
9774 : m_die (die
), m_cu (cu
)
9776 /* We should only be processing DIEs not already in process. */
9777 gdb_assert (!m_die
->in_process
);
9778 m_die
->in_process
= true;
9781 ~process_die_scope ()
9783 m_die
->in_process
= false;
9785 /* If we're done processing the DIE for the CU that owns the line
9786 header, we don't need the line header anymore. */
9787 if (m_cu
->line_header_die_owner
== m_die
)
9789 delete m_cu
->line_header
;
9790 m_cu
->line_header
= NULL
;
9791 m_cu
->line_header_die_owner
= NULL
;
9800 /* Process a die and its children. */
9803 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9805 process_die_scope
scope (die
, cu
);
9809 case DW_TAG_padding
:
9811 case DW_TAG_compile_unit
:
9812 case DW_TAG_partial_unit
:
9813 read_file_scope (die
, cu
);
9815 case DW_TAG_type_unit
:
9816 read_type_unit_scope (die
, cu
);
9818 case DW_TAG_subprogram
:
9819 /* Nested subprograms in Fortran get a prefix. */
9820 if (cu
->language
== language_fortran
9821 && die
->parent
!= NULL
9822 && die
->parent
->tag
== DW_TAG_subprogram
)
9823 cu
->processing_has_namespace_info
= true;
9825 case DW_TAG_inlined_subroutine
:
9826 read_func_scope (die
, cu
);
9828 case DW_TAG_lexical_block
:
9829 case DW_TAG_try_block
:
9830 case DW_TAG_catch_block
:
9831 read_lexical_block_scope (die
, cu
);
9833 case DW_TAG_call_site
:
9834 case DW_TAG_GNU_call_site
:
9835 read_call_site_scope (die
, cu
);
9837 case DW_TAG_class_type
:
9838 case DW_TAG_interface_type
:
9839 case DW_TAG_structure_type
:
9840 case DW_TAG_union_type
:
9841 process_structure_scope (die
, cu
);
9843 case DW_TAG_enumeration_type
:
9844 process_enumeration_scope (die
, cu
);
9847 /* These dies have a type, but processing them does not create
9848 a symbol or recurse to process the children. Therefore we can
9849 read them on-demand through read_type_die. */
9850 case DW_TAG_subroutine_type
:
9851 case DW_TAG_set_type
:
9852 case DW_TAG_array_type
:
9853 case DW_TAG_pointer_type
:
9854 case DW_TAG_ptr_to_member_type
:
9855 case DW_TAG_reference_type
:
9856 case DW_TAG_rvalue_reference_type
:
9857 case DW_TAG_string_type
:
9860 case DW_TAG_base_type
:
9861 case DW_TAG_subrange_type
:
9862 case DW_TAG_typedef
:
9863 /* Add a typedef symbol for the type definition, if it has a
9865 new_symbol (die
, read_type_die (die
, cu
), cu
);
9867 case DW_TAG_common_block
:
9868 read_common_block (die
, cu
);
9870 case DW_TAG_common_inclusion
:
9872 case DW_TAG_namespace
:
9873 cu
->processing_has_namespace_info
= true;
9874 read_namespace (die
, cu
);
9877 cu
->processing_has_namespace_info
= true;
9878 read_module (die
, cu
);
9880 case DW_TAG_imported_declaration
:
9881 cu
->processing_has_namespace_info
= true;
9882 if (read_namespace_alias (die
, cu
))
9884 /* The declaration is not a global namespace alias. */
9886 case DW_TAG_imported_module
:
9887 cu
->processing_has_namespace_info
= true;
9888 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
9889 || cu
->language
!= language_fortran
))
9890 complaint (_("Tag '%s' has unexpected children"),
9891 dwarf_tag_name (die
->tag
));
9892 read_import_statement (die
, cu
);
9895 case DW_TAG_imported_unit
:
9896 process_imported_unit_die (die
, cu
);
9899 case DW_TAG_variable
:
9900 read_variable (die
, cu
);
9904 new_symbol (die
, NULL
, cu
);
9909 /* DWARF name computation. */
9911 /* A helper function for dwarf2_compute_name which determines whether DIE
9912 needs to have the name of the scope prepended to the name listed in the
9916 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
9918 struct attribute
*attr
;
9922 case DW_TAG_namespace
:
9923 case DW_TAG_typedef
:
9924 case DW_TAG_class_type
:
9925 case DW_TAG_interface_type
:
9926 case DW_TAG_structure_type
:
9927 case DW_TAG_union_type
:
9928 case DW_TAG_enumeration_type
:
9929 case DW_TAG_enumerator
:
9930 case DW_TAG_subprogram
:
9931 case DW_TAG_inlined_subroutine
:
9933 case DW_TAG_imported_declaration
:
9936 case DW_TAG_variable
:
9937 case DW_TAG_constant
:
9938 /* We only need to prefix "globally" visible variables. These include
9939 any variable marked with DW_AT_external or any variable that
9940 lives in a namespace. [Variables in anonymous namespaces
9941 require prefixing, but they are not DW_AT_external.] */
9943 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
9945 struct dwarf2_cu
*spec_cu
= cu
;
9947 return die_needs_namespace (die_specification (die
, &spec_cu
),
9951 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
9952 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
9953 && die
->parent
->tag
!= DW_TAG_module
)
9955 /* A variable in a lexical block of some kind does not need a
9956 namespace, even though in C++ such variables may be external
9957 and have a mangled name. */
9958 if (die
->parent
->tag
== DW_TAG_lexical_block
9959 || die
->parent
->tag
== DW_TAG_try_block
9960 || die
->parent
->tag
== DW_TAG_catch_block
9961 || die
->parent
->tag
== DW_TAG_subprogram
)
9970 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
9971 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9972 defined for the given DIE. */
9974 static struct attribute
*
9975 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
9977 struct attribute
*attr
;
9979 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
9981 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9986 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
9987 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9988 defined for the given DIE. */
9991 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
9993 const char *linkage_name
;
9995 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
9996 if (linkage_name
== NULL
)
9997 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9999 return linkage_name
;
10002 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10003 compute the physname for the object, which include a method's:
10004 - formal parameters (C++),
10005 - receiver type (Go),
10007 The term "physname" is a bit confusing.
10008 For C++, for example, it is the demangled name.
10009 For Go, for example, it's the mangled name.
10011 For Ada, return the DIE's linkage name rather than the fully qualified
10012 name. PHYSNAME is ignored..
10014 The result is allocated on the objfile_obstack and canonicalized. */
10016 static const char *
10017 dwarf2_compute_name (const char *name
,
10018 struct die_info
*die
, struct dwarf2_cu
*cu
,
10021 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10024 name
= dwarf2_name (die
, cu
);
10026 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10027 but otherwise compute it by typename_concat inside GDB.
10028 FIXME: Actually this is not really true, or at least not always true.
10029 It's all very confusing. compute_and_set_names doesn't try to demangle
10030 Fortran names because there is no mangling standard. So new_symbol
10031 will set the demangled name to the result of dwarf2_full_name, and it is
10032 the demangled name that GDB uses if it exists. */
10033 if (cu
->language
== language_ada
10034 || (cu
->language
== language_fortran
&& physname
))
10036 /* For Ada unit, we prefer the linkage name over the name, as
10037 the former contains the exported name, which the user expects
10038 to be able to reference. Ideally, we want the user to be able
10039 to reference this entity using either natural or linkage name,
10040 but we haven't started looking at this enhancement yet. */
10041 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10043 if (linkage_name
!= NULL
)
10044 return linkage_name
;
10047 /* These are the only languages we know how to qualify names in. */
10049 && (cu
->language
== language_cplus
10050 || cu
->language
== language_fortran
|| cu
->language
== language_d
10051 || cu
->language
== language_rust
))
10053 if (die_needs_namespace (die
, cu
))
10055 const char *prefix
;
10056 const char *canonical_name
= NULL
;
10060 prefix
= determine_prefix (die
, cu
);
10061 if (*prefix
!= '\0')
10063 gdb::unique_xmalloc_ptr
<char> prefixed_name
10064 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10066 buf
.puts (prefixed_name
.get ());
10071 /* Template parameters may be specified in the DIE's DW_AT_name, or
10072 as children with DW_TAG_template_type_param or
10073 DW_TAG_value_type_param. If the latter, add them to the name
10074 here. If the name already has template parameters, then
10075 skip this step; some versions of GCC emit both, and
10076 it is more efficient to use the pre-computed name.
10078 Something to keep in mind about this process: it is very
10079 unlikely, or in some cases downright impossible, to produce
10080 something that will match the mangled name of a function.
10081 If the definition of the function has the same debug info,
10082 we should be able to match up with it anyway. But fallbacks
10083 using the minimal symbol, for instance to find a method
10084 implemented in a stripped copy of libstdc++, will not work.
10085 If we do not have debug info for the definition, we will have to
10086 match them up some other way.
10088 When we do name matching there is a related problem with function
10089 templates; two instantiated function templates are allowed to
10090 differ only by their return types, which we do not add here. */
10092 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10094 struct attribute
*attr
;
10095 struct die_info
*child
;
10098 die
->building_fullname
= 1;
10100 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10104 const gdb_byte
*bytes
;
10105 struct dwarf2_locexpr_baton
*baton
;
10108 if (child
->tag
!= DW_TAG_template_type_param
10109 && child
->tag
!= DW_TAG_template_value_param
)
10120 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10123 complaint (_("template parameter missing DW_AT_type"));
10124 buf
.puts ("UNKNOWN_TYPE");
10127 type
= die_type (child
, cu
);
10129 if (child
->tag
== DW_TAG_template_type_param
)
10131 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10132 &type_print_raw_options
);
10136 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10139 complaint (_("template parameter missing "
10140 "DW_AT_const_value"));
10141 buf
.puts ("UNKNOWN_VALUE");
10145 dwarf2_const_value_attr (attr
, type
, name
,
10146 &cu
->comp_unit_obstack
, cu
,
10147 &value
, &bytes
, &baton
);
10149 if (TYPE_NOSIGN (type
))
10150 /* GDB prints characters as NUMBER 'CHAR'. If that's
10151 changed, this can use value_print instead. */
10152 c_printchar (value
, type
, &buf
);
10155 struct value_print_options opts
;
10158 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10162 else if (bytes
!= NULL
)
10164 v
= allocate_value (type
);
10165 memcpy (value_contents_writeable (v
), bytes
,
10166 TYPE_LENGTH (type
));
10169 v
= value_from_longest (type
, value
);
10171 /* Specify decimal so that we do not depend on
10173 get_formatted_print_options (&opts
, 'd');
10175 value_print (v
, &buf
, &opts
);
10180 die
->building_fullname
= 0;
10184 /* Close the argument list, with a space if necessary
10185 (nested templates). */
10186 if (!buf
.empty () && buf
.string ().back () == '>')
10193 /* For C++ methods, append formal parameter type
10194 information, if PHYSNAME. */
10196 if (physname
&& die
->tag
== DW_TAG_subprogram
10197 && cu
->language
== language_cplus
)
10199 struct type
*type
= read_type_die (die
, cu
);
10201 c_type_print_args (type
, &buf
, 1, cu
->language
,
10202 &type_print_raw_options
);
10204 if (cu
->language
== language_cplus
)
10206 /* Assume that an artificial first parameter is
10207 "this", but do not crash if it is not. RealView
10208 marks unnamed (and thus unused) parameters as
10209 artificial; there is no way to differentiate
10211 if (TYPE_NFIELDS (type
) > 0
10212 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10213 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
10214 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
10216 buf
.puts (" const");
10220 const std::string
&intermediate_name
= buf
.string ();
10222 if (cu
->language
== language_cplus
)
10224 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10227 /* If we only computed INTERMEDIATE_NAME, or if
10228 INTERMEDIATE_NAME is already canonical, then we need to
10230 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10231 name
= objfile
->intern (intermediate_name
);
10233 name
= canonical_name
;
10240 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10241 If scope qualifiers are appropriate they will be added. The result
10242 will be allocated on the storage_obstack, or NULL if the DIE does
10243 not have a name. NAME may either be from a previous call to
10244 dwarf2_name or NULL.
10246 The output string will be canonicalized (if C++). */
10248 static const char *
10249 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10251 return dwarf2_compute_name (name
, die
, cu
, 0);
10254 /* Construct a physname for the given DIE in CU. NAME may either be
10255 from a previous call to dwarf2_name or NULL. The result will be
10256 allocated on the objfile_objstack or NULL if the DIE does not have a
10259 The output string will be canonicalized (if C++). */
10261 static const char *
10262 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10264 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10265 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10268 /* In this case dwarf2_compute_name is just a shortcut not building anything
10270 if (!die_needs_namespace (die
, cu
))
10271 return dwarf2_compute_name (name
, die
, cu
, 1);
10273 mangled
= dw2_linkage_name (die
, cu
);
10275 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
10276 See https://github.com/rust-lang/rust/issues/32925. */
10277 if (cu
->language
== language_rust
&& mangled
!= NULL
10278 && strchr (mangled
, '{') != NULL
)
10281 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10283 gdb::unique_xmalloc_ptr
<char> demangled
;
10284 if (mangled
!= NULL
)
10287 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
10289 /* Do nothing (do not demangle the symbol name). */
10291 else if (cu
->language
== language_go
)
10293 /* This is a lie, but we already lie to the caller new_symbol.
10294 new_symbol assumes we return the mangled name.
10295 This just undoes that lie until things are cleaned up. */
10299 /* Use DMGL_RET_DROP for C++ template functions to suppress
10300 their return type. It is easier for GDB users to search
10301 for such functions as `name(params)' than `long name(params)'.
10302 In such case the minimal symbol names do not match the full
10303 symbol names but for template functions there is never a need
10304 to look up their definition from their declaration so
10305 the only disadvantage remains the minimal symbol variant
10306 `long name(params)' does not have the proper inferior type. */
10307 demangled
.reset (gdb_demangle (mangled
,
10308 (DMGL_PARAMS
| DMGL_ANSI
10309 | DMGL_RET_DROP
)));
10312 canon
= demangled
.get ();
10320 if (canon
== NULL
|| check_physname
)
10322 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10324 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10326 /* It may not mean a bug in GDB. The compiler could also
10327 compute DW_AT_linkage_name incorrectly. But in such case
10328 GDB would need to be bug-to-bug compatible. */
10330 complaint (_("Computed physname <%s> does not match demangled <%s> "
10331 "(from linkage <%s>) - DIE at %s [in module %s]"),
10332 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10333 objfile_name (objfile
));
10335 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10336 is available here - over computed PHYSNAME. It is safer
10337 against both buggy GDB and buggy compilers. */
10351 retval
= objfile
->intern (retval
);
10356 /* Inspect DIE in CU for a namespace alias. If one exists, record
10357 a new symbol for it.
10359 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10362 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10364 struct attribute
*attr
;
10366 /* If the die does not have a name, this is not a namespace
10368 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10372 struct die_info
*d
= die
;
10373 struct dwarf2_cu
*imported_cu
= cu
;
10375 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10376 keep inspecting DIEs until we hit the underlying import. */
10377 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10378 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10380 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10384 d
= follow_die_ref (d
, attr
, &imported_cu
);
10385 if (d
->tag
!= DW_TAG_imported_declaration
)
10389 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10391 complaint (_("DIE at %s has too many recursively imported "
10392 "declarations"), sect_offset_str (d
->sect_off
));
10399 sect_offset sect_off
= attr
->get_ref_die_offset ();
10401 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
10402 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
10404 /* This declaration is a global namespace alias. Add
10405 a symbol for it whose type is the aliased namespace. */
10406 new_symbol (die
, type
, cu
);
10415 /* Return the using directives repository (global or local?) to use in the
10416 current context for CU.
10418 For Ada, imported declarations can materialize renamings, which *may* be
10419 global. However it is impossible (for now?) in DWARF to distinguish
10420 "external" imported declarations and "static" ones. As all imported
10421 declarations seem to be static in all other languages, make them all CU-wide
10422 global only in Ada. */
10424 static struct using_direct
**
10425 using_directives (struct dwarf2_cu
*cu
)
10427 if (cu
->language
== language_ada
10428 && cu
->get_builder ()->outermost_context_p ())
10429 return cu
->get_builder ()->get_global_using_directives ();
10431 return cu
->get_builder ()->get_local_using_directives ();
10434 /* Read the import statement specified by the given die and record it. */
10437 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10439 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10440 struct attribute
*import_attr
;
10441 struct die_info
*imported_die
, *child_die
;
10442 struct dwarf2_cu
*imported_cu
;
10443 const char *imported_name
;
10444 const char *imported_name_prefix
;
10445 const char *canonical_name
;
10446 const char *import_alias
;
10447 const char *imported_declaration
= NULL
;
10448 const char *import_prefix
;
10449 std::vector
<const char *> excludes
;
10451 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10452 if (import_attr
== NULL
)
10454 complaint (_("Tag '%s' has no DW_AT_import"),
10455 dwarf_tag_name (die
->tag
));
10460 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10461 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10462 if (imported_name
== NULL
)
10464 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10466 The import in the following code:
10480 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10481 <52> DW_AT_decl_file : 1
10482 <53> DW_AT_decl_line : 6
10483 <54> DW_AT_import : <0x75>
10484 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10485 <59> DW_AT_name : B
10486 <5b> DW_AT_decl_file : 1
10487 <5c> DW_AT_decl_line : 2
10488 <5d> DW_AT_type : <0x6e>
10490 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10491 <76> DW_AT_byte_size : 4
10492 <77> DW_AT_encoding : 5 (signed)
10494 imports the wrong die ( 0x75 instead of 0x58 ).
10495 This case will be ignored until the gcc bug is fixed. */
10499 /* Figure out the local name after import. */
10500 import_alias
= dwarf2_name (die
, cu
);
10502 /* Figure out where the statement is being imported to. */
10503 import_prefix
= determine_prefix (die
, cu
);
10505 /* Figure out what the scope of the imported die is and prepend it
10506 to the name of the imported die. */
10507 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10509 if (imported_die
->tag
!= DW_TAG_namespace
10510 && imported_die
->tag
!= DW_TAG_module
)
10512 imported_declaration
= imported_name
;
10513 canonical_name
= imported_name_prefix
;
10515 else if (strlen (imported_name_prefix
) > 0)
10516 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10517 imported_name_prefix
,
10518 (cu
->language
== language_d
? "." : "::"),
10519 imported_name
, (char *) NULL
);
10521 canonical_name
= imported_name
;
10523 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
10524 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10525 child_die
= child_die
->sibling
)
10527 /* DWARF-4: A Fortran use statement with a “rename list” may be
10528 represented by an imported module entry with an import attribute
10529 referring to the module and owned entries corresponding to those
10530 entities that are renamed as part of being imported. */
10532 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10534 complaint (_("child DW_TAG_imported_declaration expected "
10535 "- DIE at %s [in module %s]"),
10536 sect_offset_str (child_die
->sect_off
),
10537 objfile_name (objfile
));
10541 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10542 if (import_attr
== NULL
)
10544 complaint (_("Tag '%s' has no DW_AT_import"),
10545 dwarf_tag_name (child_die
->tag
));
10550 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10552 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10553 if (imported_name
== NULL
)
10555 complaint (_("child DW_TAG_imported_declaration has unknown "
10556 "imported name - DIE at %s [in module %s]"),
10557 sect_offset_str (child_die
->sect_off
),
10558 objfile_name (objfile
));
10562 excludes
.push_back (imported_name
);
10564 process_die (child_die
, cu
);
10567 add_using_directive (using_directives (cu
),
10571 imported_declaration
,
10574 &objfile
->objfile_obstack
);
10577 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10578 types, but gives them a size of zero. Starting with version 14,
10579 ICC is compatible with GCC. */
10582 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10584 if (!cu
->checked_producer
)
10585 check_producer (cu
);
10587 return cu
->producer_is_icc_lt_14
;
10590 /* ICC generates a DW_AT_type for C void functions. This was observed on
10591 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10592 which says that void functions should not have a DW_AT_type. */
10595 producer_is_icc (struct dwarf2_cu
*cu
)
10597 if (!cu
->checked_producer
)
10598 check_producer (cu
);
10600 return cu
->producer_is_icc
;
10603 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10604 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10605 this, it was first present in GCC release 4.3.0. */
10608 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10610 if (!cu
->checked_producer
)
10611 check_producer (cu
);
10613 return cu
->producer_is_gcc_lt_4_3
;
10616 static file_and_directory
10617 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10619 file_and_directory res
;
10621 /* Find the filename. Do not use dwarf2_name here, since the filename
10622 is not a source language identifier. */
10623 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
10624 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
10626 if (res
.comp_dir
== NULL
10627 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
10628 && IS_ABSOLUTE_PATH (res
.name
))
10630 res
.comp_dir_storage
= ldirname (res
.name
);
10631 if (!res
.comp_dir_storage
.empty ())
10632 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
10634 if (res
.comp_dir
!= NULL
)
10636 /* Irix 6.2 native cc prepends <machine>.: to the compilation
10637 directory, get rid of it. */
10638 const char *cp
= strchr (res
.comp_dir
, ':');
10640 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
10641 res
.comp_dir
= cp
+ 1;
10644 if (res
.name
== NULL
)
10645 res
.name
= "<unknown>";
10650 /* Handle DW_AT_stmt_list for a compilation unit.
10651 DIE is the DW_TAG_compile_unit die for CU.
10652 COMP_DIR is the compilation directory. LOWPC is passed to
10653 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
10656 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
10657 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
10659 struct dwarf2_per_objfile
*dwarf2_per_objfile
10660 = cu
->per_cu
->dwarf2_per_objfile
;
10661 struct attribute
*attr
;
10662 struct line_header line_header_local
;
10663 hashval_t line_header_local_hash
;
10665 int decode_mapping
;
10667 gdb_assert (! cu
->per_cu
->is_debug_types
);
10669 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
10673 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10675 /* The line header hash table is only created if needed (it exists to
10676 prevent redundant reading of the line table for partial_units).
10677 If we're given a partial_unit, we'll need it. If we're given a
10678 compile_unit, then use the line header hash table if it's already
10679 created, but don't create one just yet. */
10681 if (dwarf2_per_objfile
->line_header_hash
== NULL
10682 && die
->tag
== DW_TAG_partial_unit
)
10684 dwarf2_per_objfile
->line_header_hash
10685 .reset (htab_create_alloc (127, line_header_hash_voidp
,
10686 line_header_eq_voidp
,
10687 free_line_header_voidp
,
10691 line_header_local
.sect_off
= line_offset
;
10692 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
10693 line_header_local_hash
= line_header_hash (&line_header_local
);
10694 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
10696 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
.get (),
10697 &line_header_local
,
10698 line_header_local_hash
, NO_INSERT
);
10700 /* For DW_TAG_compile_unit we need info like symtab::linetable which
10701 is not present in *SLOT (since if there is something in *SLOT then
10702 it will be for a partial_unit). */
10703 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
10705 gdb_assert (*slot
!= NULL
);
10706 cu
->line_header
= (struct line_header
*) *slot
;
10711 /* dwarf_decode_line_header does not yet provide sufficient information.
10712 We always have to call also dwarf_decode_lines for it. */
10713 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
10717 cu
->line_header
= lh
.release ();
10718 cu
->line_header_die_owner
= die
;
10720 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
10724 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
.get (),
10725 &line_header_local
,
10726 line_header_local_hash
, INSERT
);
10727 gdb_assert (slot
!= NULL
);
10729 if (slot
!= NULL
&& *slot
== NULL
)
10731 /* This newly decoded line number information unit will be owned
10732 by line_header_hash hash table. */
10733 *slot
= cu
->line_header
;
10734 cu
->line_header_die_owner
= NULL
;
10738 /* We cannot free any current entry in (*slot) as that struct line_header
10739 may be already used by multiple CUs. Create only temporary decoded
10740 line_header for this CU - it may happen at most once for each line
10741 number information unit. And if we're not using line_header_hash
10742 then this is what we want as well. */
10743 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
10745 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
10746 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
10751 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
10754 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10756 struct dwarf2_per_objfile
*dwarf2_per_objfile
10757 = cu
->per_cu
->dwarf2_per_objfile
;
10758 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10759 struct gdbarch
*gdbarch
= objfile
->arch ();
10760 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
10761 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
10762 struct attribute
*attr
;
10763 struct die_info
*child_die
;
10764 CORE_ADDR baseaddr
;
10766 prepare_one_comp_unit (cu
, die
, cu
->language
);
10767 baseaddr
= objfile
->text_section_offset ();
10769 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
10771 /* If we didn't find a lowpc, set it to highpc to avoid complaints
10772 from finish_block. */
10773 if (lowpc
== ((CORE_ADDR
) -1))
10775 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
10777 file_and_directory fnd
= find_file_and_directory (die
, cu
);
10779 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
10780 standardised yet. As a workaround for the language detection we fall
10781 back to the DW_AT_producer string. */
10782 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
10783 cu
->language
= language_opencl
;
10785 /* Similar hack for Go. */
10786 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
10787 set_cu_language (DW_LANG_Go
, cu
);
10789 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
10791 /* Decode line number information if present. We do this before
10792 processing child DIEs, so that the line header table is available
10793 for DW_AT_decl_file. */
10794 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
10796 /* Process all dies in compilation unit. */
10797 if (die
->child
!= NULL
)
10799 child_die
= die
->child
;
10800 while (child_die
&& child_die
->tag
)
10802 process_die (child_die
, cu
);
10803 child_die
= child_die
->sibling
;
10807 /* Decode macro information, if present. Dwarf 2 macro information
10808 refers to information in the line number info statement program
10809 header, so we can only read it if we've read the header
10811 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
10813 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
10814 if (attr
&& cu
->line_header
)
10816 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
10817 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
10819 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
10823 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
10824 if (attr
&& cu
->line_header
)
10826 unsigned int macro_offset
= DW_UNSND (attr
);
10828 dwarf_decode_macros (cu
, macro_offset
, 0);
10834 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
10836 struct type_unit_group
*tu_group
;
10838 struct attribute
*attr
;
10840 struct signatured_type
*sig_type
;
10842 gdb_assert (per_cu
->is_debug_types
);
10843 sig_type
= (struct signatured_type
*) per_cu
;
10845 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
10847 /* If we're using .gdb_index (includes -readnow) then
10848 per_cu->type_unit_group may not have been set up yet. */
10849 if (sig_type
->type_unit_group
== NULL
)
10850 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
10851 tu_group
= sig_type
->type_unit_group
;
10853 /* If we've already processed this stmt_list there's no real need to
10854 do it again, we could fake it and just recreate the part we need
10855 (file name,index -> symtab mapping). If data shows this optimization
10856 is useful we can do it then. */
10857 first_time
= tu_group
->compunit_symtab
== NULL
;
10859 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
10864 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10865 lh
= dwarf_decode_line_header (line_offset
, this);
10870 start_symtab ("", NULL
, 0);
10873 gdb_assert (tu_group
->symtabs
== NULL
);
10874 gdb_assert (m_builder
== nullptr);
10875 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
10876 m_builder
.reset (new struct buildsym_compunit
10877 (COMPUNIT_OBJFILE (cust
), "",
10878 COMPUNIT_DIRNAME (cust
),
10879 compunit_language (cust
),
10885 line_header
= lh
.release ();
10886 line_header_die_owner
= die
;
10890 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
10892 /* Note: We don't assign tu_group->compunit_symtab yet because we're
10893 still initializing it, and our caller (a few levels up)
10894 process_full_type_unit still needs to know if this is the first
10898 = XOBNEWVEC (&COMPUNIT_OBJFILE (cust
)->objfile_obstack
,
10899 struct symtab
*, line_header
->file_names_size ());
10901 auto &file_names
= line_header
->file_names ();
10902 for (i
= 0; i
< file_names
.size (); ++i
)
10904 file_entry
&fe
= file_names
[i
];
10905 dwarf2_start_subfile (this, fe
.name
,
10906 fe
.include_dir (line_header
));
10907 buildsym_compunit
*b
= get_builder ();
10908 if (b
->get_current_subfile ()->symtab
== NULL
)
10910 /* NOTE: start_subfile will recognize when it's been
10911 passed a file it has already seen. So we can't
10912 assume there's a simple mapping from
10913 cu->line_header->file_names to subfiles, plus
10914 cu->line_header->file_names may contain dups. */
10915 b
->get_current_subfile ()->symtab
10916 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
10919 fe
.symtab
= b
->get_current_subfile ()->symtab
;
10920 tu_group
->symtabs
[i
] = fe
.symtab
;
10925 gdb_assert (m_builder
== nullptr);
10926 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
10927 m_builder
.reset (new struct buildsym_compunit
10928 (COMPUNIT_OBJFILE (cust
), "",
10929 COMPUNIT_DIRNAME (cust
),
10930 compunit_language (cust
),
10933 auto &file_names
= line_header
->file_names ();
10934 for (i
= 0; i
< file_names
.size (); ++i
)
10936 file_entry
&fe
= file_names
[i
];
10937 fe
.symtab
= tu_group
->symtabs
[i
];
10941 /* The main symtab is allocated last. Type units don't have DW_AT_name
10942 so they don't have a "real" (so to speak) symtab anyway.
10943 There is later code that will assign the main symtab to all symbols
10944 that don't have one. We need to handle the case of a symbol with a
10945 missing symtab (DW_AT_decl_file) anyway. */
10948 /* Process DW_TAG_type_unit.
10949 For TUs we want to skip the first top level sibling if it's not the
10950 actual type being defined by this TU. In this case the first top
10951 level sibling is there to provide context only. */
10954 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10956 struct die_info
*child_die
;
10958 prepare_one_comp_unit (cu
, die
, language_minimal
);
10960 /* Initialize (or reinitialize) the machinery for building symtabs.
10961 We do this before processing child DIEs, so that the line header table
10962 is available for DW_AT_decl_file. */
10963 cu
->setup_type_unit_groups (die
);
10965 if (die
->child
!= NULL
)
10967 child_die
= die
->child
;
10968 while (child_die
&& child_die
->tag
)
10970 process_die (child_die
, cu
);
10971 child_die
= child_die
->sibling
;
10978 http://gcc.gnu.org/wiki/DebugFission
10979 http://gcc.gnu.org/wiki/DebugFissionDWP
10981 To simplify handling of both DWO files ("object" files with the DWARF info)
10982 and DWP files (a file with the DWOs packaged up into one file), we treat
10983 DWP files as having a collection of virtual DWO files. */
10986 hash_dwo_file (const void *item
)
10988 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
10991 hash
= htab_hash_string (dwo_file
->dwo_name
);
10992 if (dwo_file
->comp_dir
!= NULL
)
10993 hash
+= htab_hash_string (dwo_file
->comp_dir
);
10998 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11000 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11001 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11003 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11005 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11006 return lhs
->comp_dir
== rhs
->comp_dir
;
11007 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11010 /* Allocate a hash table for DWO files. */
11013 allocate_dwo_file_hash_table ()
11015 auto delete_dwo_file
= [] (void *item
)
11017 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
11022 return htab_up (htab_create_alloc (41,
11029 /* Lookup DWO file DWO_NAME. */
11032 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11033 const char *dwo_name
,
11034 const char *comp_dir
)
11036 struct dwo_file find_entry
;
11039 if (dwarf2_per_objfile
->dwo_files
== NULL
)
11040 dwarf2_per_objfile
->dwo_files
= allocate_dwo_file_hash_table ();
11042 find_entry
.dwo_name
= dwo_name
;
11043 find_entry
.comp_dir
= comp_dir
;
11044 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
.get (), &find_entry
,
11051 hash_dwo_unit (const void *item
)
11053 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11055 /* This drops the top 32 bits of the id, but is ok for a hash. */
11056 return dwo_unit
->signature
;
11060 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11062 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11063 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11065 /* The signature is assumed to be unique within the DWO file.
11066 So while object file CU dwo_id's always have the value zero,
11067 that's OK, assuming each object file DWO file has only one CU,
11068 and that's the rule for now. */
11069 return lhs
->signature
== rhs
->signature
;
11072 /* Allocate a hash table for DWO CUs,TUs.
11073 There is one of these tables for each of CUs,TUs for each DWO file. */
11076 allocate_dwo_unit_table ()
11078 /* Start out with a pretty small number.
11079 Generally DWO files contain only one CU and maybe some TUs. */
11080 return htab_up (htab_create_alloc (3,
11083 NULL
, xcalloc
, xfree
));
11086 /* die_reader_func for create_dwo_cu. */
11089 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11090 const gdb_byte
*info_ptr
,
11091 struct die_info
*comp_unit_die
,
11092 struct dwo_file
*dwo_file
,
11093 struct dwo_unit
*dwo_unit
)
11095 struct dwarf2_cu
*cu
= reader
->cu
;
11096 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11097 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11099 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11100 if (!signature
.has_value ())
11102 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11103 " its dwo_id [in module %s]"),
11104 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11108 dwo_unit
->dwo_file
= dwo_file
;
11109 dwo_unit
->signature
= *signature
;
11110 dwo_unit
->section
= section
;
11111 dwo_unit
->sect_off
= sect_off
;
11112 dwo_unit
->length
= cu
->per_cu
->length
;
11114 if (dwarf_read_debug
)
11115 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11116 sect_offset_str (sect_off
),
11117 hex_string (dwo_unit
->signature
));
11120 /* Create the dwo_units for the CUs in a DWO_FILE.
11121 Note: This function processes DWO files only, not DWP files. */
11124 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11125 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11126 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
11128 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11129 const gdb_byte
*info_ptr
, *end_ptr
;
11131 section
.read (objfile
);
11132 info_ptr
= section
.buffer
;
11134 if (info_ptr
== NULL
)
11137 if (dwarf_read_debug
)
11139 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11140 section
.get_name (),
11141 section
.get_file_name ());
11144 end_ptr
= info_ptr
+ section
.size
;
11145 while (info_ptr
< end_ptr
)
11147 struct dwarf2_per_cu_data per_cu
;
11148 struct dwo_unit read_unit
{};
11149 struct dwo_unit
*dwo_unit
;
11151 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11153 memset (&per_cu
, 0, sizeof (per_cu
));
11154 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
11155 per_cu
.is_debug_types
= 0;
11156 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11157 per_cu
.section
= §ion
;
11159 cutu_reader
reader (&per_cu
, cu
, &dwo_file
);
11160 if (!reader
.dummy_p
)
11161 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11162 &dwo_file
, &read_unit
);
11163 info_ptr
+= per_cu
.length
;
11165 // If the unit could not be parsed, skip it.
11166 if (read_unit
.dwo_file
== NULL
)
11169 if (cus_htab
== NULL
)
11170 cus_htab
= allocate_dwo_unit_table ();
11172 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11173 *dwo_unit
= read_unit
;
11174 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11175 gdb_assert (slot
!= NULL
);
11178 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11179 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11181 complaint (_("debug cu entry at offset %s is duplicate to"
11182 " the entry at offset %s, signature %s"),
11183 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11184 hex_string (dwo_unit
->signature
));
11186 *slot
= (void *)dwo_unit
;
11190 /* DWP file .debug_{cu,tu}_index section format:
11191 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11195 Both index sections have the same format, and serve to map a 64-bit
11196 signature to a set of section numbers. Each section begins with a header,
11197 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11198 indexes, and a pool of 32-bit section numbers. The index sections will be
11199 aligned at 8-byte boundaries in the file.
11201 The index section header consists of:
11203 V, 32 bit version number
11205 N, 32 bit number of compilation units or type units in the index
11206 M, 32 bit number of slots in the hash table
11208 Numbers are recorded using the byte order of the application binary.
11210 The hash table begins at offset 16 in the section, and consists of an array
11211 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11212 order of the application binary). Unused slots in the hash table are 0.
11213 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11215 The parallel table begins immediately after the hash table
11216 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11217 array of 32-bit indexes (using the byte order of the application binary),
11218 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11219 table contains a 32-bit index into the pool of section numbers. For unused
11220 hash table slots, the corresponding entry in the parallel table will be 0.
11222 The pool of section numbers begins immediately following the hash table
11223 (at offset 16 + 12 * M from the beginning of the section). The pool of
11224 section numbers consists of an array of 32-bit words (using the byte order
11225 of the application binary). Each item in the array is indexed starting
11226 from 0. The hash table entry provides the index of the first section
11227 number in the set. Additional section numbers in the set follow, and the
11228 set is terminated by a 0 entry (section number 0 is not used in ELF).
11230 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11231 section must be the first entry in the set, and the .debug_abbrev.dwo must
11232 be the second entry. Other members of the set may follow in any order.
11238 DWP Version 2 combines all the .debug_info, etc. sections into one,
11239 and the entries in the index tables are now offsets into these sections.
11240 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11243 Index Section Contents:
11245 Hash Table of Signatures dwp_hash_table.hash_table
11246 Parallel Table of Indices dwp_hash_table.unit_table
11247 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
11248 Table of Section Sizes dwp_hash_table.v2.sizes
11250 The index section header consists of:
11252 V, 32 bit version number
11253 L, 32 bit number of columns in the table of section offsets
11254 N, 32 bit number of compilation units or type units in the index
11255 M, 32 bit number of slots in the hash table
11257 Numbers are recorded using the byte order of the application binary.
11259 The hash table has the same format as version 1.
11260 The parallel table of indices has the same format as version 1,
11261 except that the entries are origin-1 indices into the table of sections
11262 offsets and the table of section sizes.
11264 The table of offsets begins immediately following the parallel table
11265 (at offset 16 + 12 * M from the beginning of the section). The table is
11266 a two-dimensional array of 32-bit words (using the byte order of the
11267 application binary), with L columns and N+1 rows, in row-major order.
11268 Each row in the array is indexed starting from 0. The first row provides
11269 a key to the remaining rows: each column in this row provides an identifier
11270 for a debug section, and the offsets in the same column of subsequent rows
11271 refer to that section. The section identifiers are:
11273 DW_SECT_INFO 1 .debug_info.dwo
11274 DW_SECT_TYPES 2 .debug_types.dwo
11275 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11276 DW_SECT_LINE 4 .debug_line.dwo
11277 DW_SECT_LOC 5 .debug_loc.dwo
11278 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11279 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11280 DW_SECT_MACRO 8 .debug_macro.dwo
11282 The offsets provided by the CU and TU index sections are the base offsets
11283 for the contributions made by each CU or TU to the corresponding section
11284 in the package file. Each CU and TU header contains an abbrev_offset
11285 field, used to find the abbreviations table for that CU or TU within the
11286 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11287 be interpreted as relative to the base offset given in the index section.
11288 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11289 should be interpreted as relative to the base offset for .debug_line.dwo,
11290 and offsets into other debug sections obtained from DWARF attributes should
11291 also be interpreted as relative to the corresponding base offset.
11293 The table of sizes begins immediately following the table of offsets.
11294 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11295 with L columns and N rows, in row-major order. Each row in the array is
11296 indexed starting from 1 (row 0 is shared by the two tables).
11300 Hash table lookup is handled the same in version 1 and 2:
11302 We assume that N and M will not exceed 2^32 - 1.
11303 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11305 Given a 64-bit compilation unit signature or a type signature S, an entry
11306 in the hash table is located as follows:
11308 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11309 the low-order k bits all set to 1.
11311 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11313 3) If the hash table entry at index H matches the signature, use that
11314 entry. If the hash table entry at index H is unused (all zeroes),
11315 terminate the search: the signature is not present in the table.
11317 4) Let H = (H + H') modulo M. Repeat at Step 3.
11319 Because M > N and H' and M are relatively prime, the search is guaranteed
11320 to stop at an unused slot or find the match. */
11322 /* Create a hash table to map DWO IDs to their CU/TU entry in
11323 .debug_{info,types}.dwo in DWP_FILE.
11324 Returns NULL if there isn't one.
11325 Note: This function processes DWP files only, not DWO files. */
11327 static struct dwp_hash_table
*
11328 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11329 struct dwp_file
*dwp_file
, int is_debug_types
)
11331 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11332 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11333 const gdb_byte
*index_ptr
, *index_end
;
11334 struct dwarf2_section_info
*index
;
11335 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11336 struct dwp_hash_table
*htab
;
11338 if (is_debug_types
)
11339 index
= &dwp_file
->sections
.tu_index
;
11341 index
= &dwp_file
->sections
.cu_index
;
11343 if (index
->empty ())
11345 index
->read (objfile
);
11347 index_ptr
= index
->buffer
;
11348 index_end
= index_ptr
+ index
->size
;
11350 version
= read_4_bytes (dbfd
, index_ptr
);
11353 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11357 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11359 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11362 if (version
!= 1 && version
!= 2)
11364 error (_("Dwarf Error: unsupported DWP file version (%s)"
11365 " [in module %s]"),
11366 pulongest (version
), dwp_file
->name
);
11368 if (nr_slots
!= (nr_slots
& -nr_slots
))
11370 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11371 " is not power of 2 [in module %s]"),
11372 pulongest (nr_slots
), dwp_file
->name
);
11375 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
11376 htab
->version
= version
;
11377 htab
->nr_columns
= nr_columns
;
11378 htab
->nr_units
= nr_units
;
11379 htab
->nr_slots
= nr_slots
;
11380 htab
->hash_table
= index_ptr
;
11381 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11383 /* Exit early if the table is empty. */
11384 if (nr_slots
== 0 || nr_units
== 0
11385 || (version
== 2 && nr_columns
== 0))
11387 /* All must be zero. */
11388 if (nr_slots
!= 0 || nr_units
!= 0
11389 || (version
== 2 && nr_columns
!= 0))
11391 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11392 " all zero [in modules %s]"),
11400 htab
->section_pool
.v1
.indices
=
11401 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11402 /* It's harder to decide whether the section is too small in v1.
11403 V1 is deprecated anyway so we punt. */
11407 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11408 int *ids
= htab
->section_pool
.v2
.section_ids
;
11409 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11410 /* Reverse map for error checking. */
11411 int ids_seen
[DW_SECT_MAX
+ 1];
11414 if (nr_columns
< 2)
11416 error (_("Dwarf Error: bad DWP hash table, too few columns"
11417 " in section table [in module %s]"),
11420 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11422 error (_("Dwarf Error: bad DWP hash table, too many columns"
11423 " in section table [in module %s]"),
11426 memset (ids
, 255, sizeof_ids
);
11427 memset (ids_seen
, 255, sizeof (ids_seen
));
11428 for (i
= 0; i
< nr_columns
; ++i
)
11430 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11432 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11434 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11435 " in section table [in module %s]"),
11436 id
, dwp_file
->name
);
11438 if (ids_seen
[id
] != -1)
11440 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11441 " id %d in section table [in module %s]"),
11442 id
, dwp_file
->name
);
11447 /* Must have exactly one info or types section. */
11448 if (((ids_seen
[DW_SECT_INFO
] != -1)
11449 + (ids_seen
[DW_SECT_TYPES
] != -1))
11452 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11453 " DWO info/types section [in module %s]"),
11456 /* Must have an abbrev section. */
11457 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11459 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11460 " section [in module %s]"),
11463 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11464 htab
->section_pool
.v2
.sizes
=
11465 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11466 * nr_units
* nr_columns
);
11467 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11468 * nr_units
* nr_columns
))
11471 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11472 " [in module %s]"),
11480 /* Update SECTIONS with the data from SECTP.
11482 This function is like the other "locate" section routines that are
11483 passed to bfd_map_over_sections, but in this context the sections to
11484 read comes from the DWP V1 hash table, not the full ELF section table.
11486 The result is non-zero for success, or zero if an error was found. */
11489 locate_v1_virtual_dwo_sections (asection
*sectp
,
11490 struct virtual_v1_dwo_sections
*sections
)
11492 const struct dwop_section_names
*names
= &dwop_section_names
;
11494 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
11496 /* There can be only one. */
11497 if (sections
->abbrev
.s
.section
!= NULL
)
11499 sections
->abbrev
.s
.section
= sectp
;
11500 sections
->abbrev
.size
= bfd_section_size (sectp
);
11502 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
11503 || section_is_p (sectp
->name
, &names
->types_dwo
))
11505 /* There can be only one. */
11506 if (sections
->info_or_types
.s
.section
!= NULL
)
11508 sections
->info_or_types
.s
.section
= sectp
;
11509 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11511 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
11513 /* There can be only one. */
11514 if (sections
->line
.s
.section
!= NULL
)
11516 sections
->line
.s
.section
= sectp
;
11517 sections
->line
.size
= bfd_section_size (sectp
);
11519 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
11521 /* There can be only one. */
11522 if (sections
->loc
.s
.section
!= NULL
)
11524 sections
->loc
.s
.section
= sectp
;
11525 sections
->loc
.size
= bfd_section_size (sectp
);
11527 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
11529 /* There can be only one. */
11530 if (sections
->macinfo
.s
.section
!= NULL
)
11532 sections
->macinfo
.s
.section
= sectp
;
11533 sections
->macinfo
.size
= bfd_section_size (sectp
);
11535 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
11537 /* There can be only one. */
11538 if (sections
->macro
.s
.section
!= NULL
)
11540 sections
->macro
.s
.section
= sectp
;
11541 sections
->macro
.size
= bfd_section_size (sectp
);
11543 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
11545 /* There can be only one. */
11546 if (sections
->str_offsets
.s
.section
!= NULL
)
11548 sections
->str_offsets
.s
.section
= sectp
;
11549 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11553 /* No other kind of section is valid. */
11560 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11561 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11562 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11563 This is for DWP version 1 files. */
11565 static struct dwo_unit
*
11566 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11567 struct dwp_file
*dwp_file
,
11568 uint32_t unit_index
,
11569 const char *comp_dir
,
11570 ULONGEST signature
, int is_debug_types
)
11572 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11573 const struct dwp_hash_table
*dwp_htab
=
11574 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11575 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11576 const char *kind
= is_debug_types
? "TU" : "CU";
11577 struct dwo_file
*dwo_file
;
11578 struct dwo_unit
*dwo_unit
;
11579 struct virtual_v1_dwo_sections sections
;
11580 void **dwo_file_slot
;
11583 gdb_assert (dwp_file
->version
== 1);
11585 if (dwarf_read_debug
)
11587 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
11589 pulongest (unit_index
), hex_string (signature
),
11593 /* Fetch the sections of this DWO unit.
11594 Put a limit on the number of sections we look for so that bad data
11595 doesn't cause us to loop forever. */
11597 #define MAX_NR_V1_DWO_SECTIONS \
11598 (1 /* .debug_info or .debug_types */ \
11599 + 1 /* .debug_abbrev */ \
11600 + 1 /* .debug_line */ \
11601 + 1 /* .debug_loc */ \
11602 + 1 /* .debug_str_offsets */ \
11603 + 1 /* .debug_macro or .debug_macinfo */ \
11604 + 1 /* trailing zero */)
11606 memset (§ions
, 0, sizeof (sections
));
11608 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
11611 uint32_t section_nr
=
11612 read_4_bytes (dbfd
,
11613 dwp_htab
->section_pool
.v1
.indices
11614 + (unit_index
+ i
) * sizeof (uint32_t));
11616 if (section_nr
== 0)
11618 if (section_nr
>= dwp_file
->num_sections
)
11620 error (_("Dwarf Error: bad DWP hash table, section number too large"
11621 " [in module %s]"),
11625 sectp
= dwp_file
->elf_sections
[section_nr
];
11626 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
11628 error (_("Dwarf Error: bad DWP hash table, invalid section found"
11629 " [in module %s]"),
11635 || sections
.info_or_types
.empty ()
11636 || sections
.abbrev
.empty ())
11638 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
11639 " [in module %s]"),
11642 if (i
== MAX_NR_V1_DWO_SECTIONS
)
11644 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
11645 " [in module %s]"),
11649 /* It's easier for the rest of the code if we fake a struct dwo_file and
11650 have dwo_unit "live" in that. At least for now.
11652 The DWP file can be made up of a random collection of CUs and TUs.
11653 However, for each CU + set of TUs that came from the same original DWO
11654 file, we can combine them back into a virtual DWO file to save space
11655 (fewer struct dwo_file objects to allocate). Remember that for really
11656 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11658 std::string virtual_dwo_name
=
11659 string_printf ("virtual-dwo/%d-%d-%d-%d",
11660 sections
.abbrev
.get_id (),
11661 sections
.line
.get_id (),
11662 sections
.loc
.get_id (),
11663 sections
.str_offsets
.get_id ());
11664 /* Can we use an existing virtual DWO file? */
11665 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
11666 virtual_dwo_name
.c_str (),
11668 /* Create one if necessary. */
11669 if (*dwo_file_slot
== NULL
)
11671 if (dwarf_read_debug
)
11673 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11674 virtual_dwo_name
.c_str ());
11676 dwo_file
= new struct dwo_file
;
11677 dwo_file
->dwo_name
= objfile
->intern (virtual_dwo_name
);
11678 dwo_file
->comp_dir
= comp_dir
;
11679 dwo_file
->sections
.abbrev
= sections
.abbrev
;
11680 dwo_file
->sections
.line
= sections
.line
;
11681 dwo_file
->sections
.loc
= sections
.loc
;
11682 dwo_file
->sections
.macinfo
= sections
.macinfo
;
11683 dwo_file
->sections
.macro
= sections
.macro
;
11684 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
11685 /* The "str" section is global to the entire DWP file. */
11686 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11687 /* The info or types section is assigned below to dwo_unit,
11688 there's no need to record it in dwo_file.
11689 Also, we can't simply record type sections in dwo_file because
11690 we record a pointer into the vector in dwo_unit. As we collect more
11691 types we'll grow the vector and eventually have to reallocate space
11692 for it, invalidating all copies of pointers into the previous
11694 *dwo_file_slot
= dwo_file
;
11698 if (dwarf_read_debug
)
11700 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11701 virtual_dwo_name
.c_str ());
11703 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11706 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11707 dwo_unit
->dwo_file
= dwo_file
;
11708 dwo_unit
->signature
= signature
;
11709 dwo_unit
->section
=
11710 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
11711 *dwo_unit
->section
= sections
.info_or_types
;
11712 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11717 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
11718 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
11719 piece within that section used by a TU/CU, return a virtual section
11720 of just that piece. */
11722 static struct dwarf2_section_info
11723 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11724 struct dwarf2_section_info
*section
,
11725 bfd_size_type offset
, bfd_size_type size
)
11727 struct dwarf2_section_info result
;
11730 gdb_assert (section
!= NULL
);
11731 gdb_assert (!section
->is_virtual
);
11733 memset (&result
, 0, sizeof (result
));
11734 result
.s
.containing_section
= section
;
11735 result
.is_virtual
= true;
11740 sectp
= section
->get_bfd_section ();
11742 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
11743 bounds of the real section. This is a pretty-rare event, so just
11744 flag an error (easier) instead of a warning and trying to cope. */
11746 || offset
+ size
> bfd_section_size (sectp
))
11748 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
11749 " in section %s [in module %s]"),
11750 sectp
? bfd_section_name (sectp
) : "<unknown>",
11751 objfile_name (dwarf2_per_objfile
->objfile
));
11754 result
.virtual_offset
= offset
;
11755 result
.size
= size
;
11759 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11760 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11761 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11762 This is for DWP version 2 files. */
11764 static struct dwo_unit
*
11765 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11766 struct dwp_file
*dwp_file
,
11767 uint32_t unit_index
,
11768 const char *comp_dir
,
11769 ULONGEST signature
, int is_debug_types
)
11771 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11772 const struct dwp_hash_table
*dwp_htab
=
11773 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11774 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11775 const char *kind
= is_debug_types
? "TU" : "CU";
11776 struct dwo_file
*dwo_file
;
11777 struct dwo_unit
*dwo_unit
;
11778 struct virtual_v2_dwo_sections sections
;
11779 void **dwo_file_slot
;
11782 gdb_assert (dwp_file
->version
== 2);
11784 if (dwarf_read_debug
)
11786 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
11788 pulongest (unit_index
), hex_string (signature
),
11792 /* Fetch the section offsets of this DWO unit. */
11794 memset (§ions
, 0, sizeof (sections
));
11796 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11798 uint32_t offset
= read_4_bytes (dbfd
,
11799 dwp_htab
->section_pool
.v2
.offsets
11800 + (((unit_index
- 1) * dwp_htab
->nr_columns
11802 * sizeof (uint32_t)));
11803 uint32_t size
= read_4_bytes (dbfd
,
11804 dwp_htab
->section_pool
.v2
.sizes
11805 + (((unit_index
- 1) * dwp_htab
->nr_columns
11807 * sizeof (uint32_t)));
11809 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
11812 case DW_SECT_TYPES
:
11813 sections
.info_or_types_offset
= offset
;
11814 sections
.info_or_types_size
= size
;
11816 case DW_SECT_ABBREV
:
11817 sections
.abbrev_offset
= offset
;
11818 sections
.abbrev_size
= size
;
11821 sections
.line_offset
= offset
;
11822 sections
.line_size
= size
;
11825 sections
.loc_offset
= offset
;
11826 sections
.loc_size
= size
;
11828 case DW_SECT_STR_OFFSETS
:
11829 sections
.str_offsets_offset
= offset
;
11830 sections
.str_offsets_size
= size
;
11832 case DW_SECT_MACINFO
:
11833 sections
.macinfo_offset
= offset
;
11834 sections
.macinfo_size
= size
;
11836 case DW_SECT_MACRO
:
11837 sections
.macro_offset
= offset
;
11838 sections
.macro_size
= size
;
11843 /* It's easier for the rest of the code if we fake a struct dwo_file and
11844 have dwo_unit "live" in that. At least for now.
11846 The DWP file can be made up of a random collection of CUs and TUs.
11847 However, for each CU + set of TUs that came from the same original DWO
11848 file, we can combine them back into a virtual DWO file to save space
11849 (fewer struct dwo_file objects to allocate). Remember that for really
11850 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11852 std::string virtual_dwo_name
=
11853 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
11854 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
11855 (long) (sections
.line_size
? sections
.line_offset
: 0),
11856 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
11857 (long) (sections
.str_offsets_size
11858 ? sections
.str_offsets_offset
: 0));
11859 /* Can we use an existing virtual DWO file? */
11860 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
11861 virtual_dwo_name
.c_str (),
11863 /* Create one if necessary. */
11864 if (*dwo_file_slot
== NULL
)
11866 if (dwarf_read_debug
)
11868 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11869 virtual_dwo_name
.c_str ());
11871 dwo_file
= new struct dwo_file
;
11872 dwo_file
->dwo_name
= objfile
->intern (virtual_dwo_name
);
11873 dwo_file
->comp_dir
= comp_dir
;
11874 dwo_file
->sections
.abbrev
=
11875 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
11876 sections
.abbrev_offset
, sections
.abbrev_size
);
11877 dwo_file
->sections
.line
=
11878 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
11879 sections
.line_offset
, sections
.line_size
);
11880 dwo_file
->sections
.loc
=
11881 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
11882 sections
.loc_offset
, sections
.loc_size
);
11883 dwo_file
->sections
.macinfo
=
11884 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
11885 sections
.macinfo_offset
, sections
.macinfo_size
);
11886 dwo_file
->sections
.macro
=
11887 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
11888 sections
.macro_offset
, sections
.macro_size
);
11889 dwo_file
->sections
.str_offsets
=
11890 create_dwp_v2_section (dwarf2_per_objfile
,
11891 &dwp_file
->sections
.str_offsets
,
11892 sections
.str_offsets_offset
,
11893 sections
.str_offsets_size
);
11894 /* The "str" section is global to the entire DWP file. */
11895 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11896 /* The info or types section is assigned below to dwo_unit,
11897 there's no need to record it in dwo_file.
11898 Also, we can't simply record type sections in dwo_file because
11899 we record a pointer into the vector in dwo_unit. As we collect more
11900 types we'll grow the vector and eventually have to reallocate space
11901 for it, invalidating all copies of pointers into the previous
11903 *dwo_file_slot
= dwo_file
;
11907 if (dwarf_read_debug
)
11909 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11910 virtual_dwo_name
.c_str ());
11912 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11915 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11916 dwo_unit
->dwo_file
= dwo_file
;
11917 dwo_unit
->signature
= signature
;
11918 dwo_unit
->section
=
11919 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
11920 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
11922 ? &dwp_file
->sections
.types
11923 : &dwp_file
->sections
.info
,
11924 sections
.info_or_types_offset
,
11925 sections
.info_or_types_size
);
11926 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11931 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
11932 Returns NULL if the signature isn't found. */
11934 static struct dwo_unit
*
11935 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11936 struct dwp_file
*dwp_file
, const char *comp_dir
,
11937 ULONGEST signature
, int is_debug_types
)
11939 const struct dwp_hash_table
*dwp_htab
=
11940 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11941 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11942 uint32_t mask
= dwp_htab
->nr_slots
- 1;
11943 uint32_t hash
= signature
& mask
;
11944 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
11947 struct dwo_unit find_dwo_cu
;
11949 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
11950 find_dwo_cu
.signature
= signature
;
11951 slot
= htab_find_slot (is_debug_types
11952 ? dwp_file
->loaded_tus
.get ()
11953 : dwp_file
->loaded_cus
.get (),
11954 &find_dwo_cu
, INSERT
);
11957 return (struct dwo_unit
*) *slot
;
11959 /* Use a for loop so that we don't loop forever on bad debug info. */
11960 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
11962 ULONGEST signature_in_table
;
11964 signature_in_table
=
11965 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
11966 if (signature_in_table
== signature
)
11968 uint32_t unit_index
=
11969 read_4_bytes (dbfd
,
11970 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
11972 if (dwp_file
->version
== 1)
11974 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
11975 dwp_file
, unit_index
,
11976 comp_dir
, signature
,
11981 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
11982 dwp_file
, unit_index
,
11983 comp_dir
, signature
,
11986 return (struct dwo_unit
*) *slot
;
11988 if (signature_in_table
== 0)
11990 hash
= (hash
+ hash2
) & mask
;
11993 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
11994 " [in module %s]"),
11998 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
11999 Open the file specified by FILE_NAME and hand it off to BFD for
12000 preliminary analysis. Return a newly initialized bfd *, which
12001 includes a canonicalized copy of FILE_NAME.
12002 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12003 SEARCH_CWD is true if the current directory is to be searched.
12004 It will be searched before debug-file-directory.
12005 If successful, the file is added to the bfd include table of the
12006 objfile's bfd (see gdb_bfd_record_inclusion).
12007 If unable to find/open the file, return NULL.
12008 NOTE: This function is derived from symfile_bfd_open. */
12010 static gdb_bfd_ref_ptr
12011 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12012 const char *file_name
, int is_dwp
, int search_cwd
)
12015 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12016 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12017 to debug_file_directory. */
12018 const char *search_path
;
12019 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12021 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12024 if (*debug_file_directory
!= '\0')
12026 search_path_holder
.reset (concat (".", dirname_separator_string
,
12027 debug_file_directory
,
12029 search_path
= search_path_holder
.get ();
12035 search_path
= debug_file_directory
;
12037 openp_flags flags
= OPF_RETURN_REALPATH
;
12039 flags
|= OPF_SEARCH_IN_PATH
;
12041 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12042 desc
= openp (search_path
, flags
, file_name
,
12043 O_RDONLY
| O_BINARY
, &absolute_name
);
12047 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12049 if (sym_bfd
== NULL
)
12051 bfd_set_cacheable (sym_bfd
.get (), 1);
12053 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12056 /* Success. Record the bfd as having been included by the objfile's bfd.
12057 This is important because things like demangled_names_hash lives in the
12058 objfile's per_bfd space and may have references to things like symbol
12059 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12060 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12065 /* Try to open DWO file FILE_NAME.
12066 COMP_DIR is the DW_AT_comp_dir attribute.
12067 The result is the bfd handle of the file.
12068 If there is a problem finding or opening the file, return NULL.
12069 Upon success, the canonicalized path of the file is stored in the bfd,
12070 same as symfile_bfd_open. */
12072 static gdb_bfd_ref_ptr
12073 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12074 const char *file_name
, const char *comp_dir
)
12076 if (IS_ABSOLUTE_PATH (file_name
))
12077 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12078 0 /*is_dwp*/, 0 /*search_cwd*/);
12080 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12082 if (comp_dir
!= NULL
)
12084 gdb::unique_xmalloc_ptr
<char> path_to_try
12085 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12087 /* NOTE: If comp_dir is a relative path, this will also try the
12088 search path, which seems useful. */
12089 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
12090 path_to_try
.get (),
12092 1 /*search_cwd*/));
12097 /* That didn't work, try debug-file-directory, which, despite its name,
12098 is a list of paths. */
12100 if (*debug_file_directory
== '\0')
12103 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12104 0 /*is_dwp*/, 1 /*search_cwd*/);
12107 /* This function is mapped across the sections and remembers the offset and
12108 size of each of the DWO debugging sections we are interested in. */
12111 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12113 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12114 const struct dwop_section_names
*names
= &dwop_section_names
;
12116 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12118 dwo_sections
->abbrev
.s
.section
= sectp
;
12119 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12121 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12123 dwo_sections
->info
.s
.section
= sectp
;
12124 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12126 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12128 dwo_sections
->line
.s
.section
= sectp
;
12129 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12131 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12133 dwo_sections
->loc
.s
.section
= sectp
;
12134 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12136 else if (section_is_p (sectp
->name
, &names
->loclists_dwo
))
12138 dwo_sections
->loclists
.s
.section
= sectp
;
12139 dwo_sections
->loclists
.size
= bfd_section_size (sectp
);
12141 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12143 dwo_sections
->macinfo
.s
.section
= sectp
;
12144 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12146 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12148 dwo_sections
->macro
.s
.section
= sectp
;
12149 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12151 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12153 dwo_sections
->str
.s
.section
= sectp
;
12154 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12156 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12158 dwo_sections
->str_offsets
.s
.section
= sectp
;
12159 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12161 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12163 struct dwarf2_section_info type_section
;
12165 memset (&type_section
, 0, sizeof (type_section
));
12166 type_section
.s
.section
= sectp
;
12167 type_section
.size
= bfd_section_size (sectp
);
12168 dwo_sections
->types
.push_back (type_section
);
12172 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12173 by PER_CU. This is for the non-DWP case.
12174 The result is NULL if DWO_NAME can't be found. */
12176 static struct dwo_file
*
12177 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
12178 const char *dwo_name
, const char *comp_dir
)
12180 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
12182 gdb_bfd_ref_ptr dbfd
= open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
);
12185 if (dwarf_read_debug
)
12186 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
12190 dwo_file_up
dwo_file (new struct dwo_file
);
12191 dwo_file
->dwo_name
= dwo_name
;
12192 dwo_file
->comp_dir
= comp_dir
;
12193 dwo_file
->dbfd
= std::move (dbfd
);
12195 bfd_map_over_sections (dwo_file
->dbfd
.get (), dwarf2_locate_dwo_sections
,
12196 &dwo_file
->sections
);
12198 create_cus_hash_table (dwarf2_per_objfile
, per_cu
->cu
, *dwo_file
,
12199 dwo_file
->sections
.info
, dwo_file
->cus
);
12201 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
.get (),
12202 dwo_file
->sections
.types
, dwo_file
->tus
);
12204 if (dwarf_read_debug
)
12205 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
12207 return dwo_file
.release ();
12210 /* This function is mapped across the sections and remembers the offset and
12211 size of each of the DWP debugging sections common to version 1 and 2 that
12212 we are interested in. */
12215 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12216 void *dwp_file_ptr
)
12218 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12219 const struct dwop_section_names
*names
= &dwop_section_names
;
12220 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12222 /* Record the ELF section number for later lookup: this is what the
12223 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12224 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12225 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12227 /* Look for specific sections that we need. */
12228 if (section_is_p (sectp
->name
, &names
->str_dwo
))
12230 dwp_file
->sections
.str
.s
.section
= sectp
;
12231 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12233 else if (section_is_p (sectp
->name
, &names
->cu_index
))
12235 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12236 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12238 else if (section_is_p (sectp
->name
, &names
->tu_index
))
12240 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12241 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12245 /* This function is mapped across the sections and remembers the offset and
12246 size of each of the DWP version 2 debugging sections that we are interested
12247 in. This is split into a separate function because we don't know if we
12248 have version 1 or 2 until we parse the cu_index/tu_index sections. */
12251 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12253 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12254 const struct dwop_section_names
*names
= &dwop_section_names
;
12255 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12257 /* Record the ELF section number for later lookup: this is what the
12258 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12259 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12260 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12262 /* Look for specific sections that we need. */
12263 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12265 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12266 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12268 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12270 dwp_file
->sections
.info
.s
.section
= sectp
;
12271 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12273 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12275 dwp_file
->sections
.line
.s
.section
= sectp
;
12276 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12278 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12280 dwp_file
->sections
.loc
.s
.section
= sectp
;
12281 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12283 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12285 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12286 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12288 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12290 dwp_file
->sections
.macro
.s
.section
= sectp
;
12291 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12293 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12295 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12296 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12298 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12300 dwp_file
->sections
.types
.s
.section
= sectp
;
12301 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12305 /* Hash function for dwp_file loaded CUs/TUs. */
12308 hash_dwp_loaded_cutus (const void *item
)
12310 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12312 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12313 return dwo_unit
->signature
;
12316 /* Equality function for dwp_file loaded CUs/TUs. */
12319 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12321 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12322 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12324 return dua
->signature
== dub
->signature
;
12327 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12330 allocate_dwp_loaded_cutus_table ()
12332 return htab_up (htab_create_alloc (3,
12333 hash_dwp_loaded_cutus
,
12334 eq_dwp_loaded_cutus
,
12335 NULL
, xcalloc
, xfree
));
12338 /* Try to open DWP file FILE_NAME.
12339 The result is the bfd handle of the file.
12340 If there is a problem finding or opening the file, return NULL.
12341 Upon success, the canonicalized path of the file is stored in the bfd,
12342 same as symfile_bfd_open. */
12344 static gdb_bfd_ref_ptr
12345 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12346 const char *file_name
)
12348 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12350 1 /*search_cwd*/));
12354 /* Work around upstream bug 15652.
12355 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12356 [Whether that's a "bug" is debatable, but it is getting in our way.]
12357 We have no real idea where the dwp file is, because gdb's realpath-ing
12358 of the executable's path may have discarded the needed info.
12359 [IWBN if the dwp file name was recorded in the executable, akin to
12360 .gnu_debuglink, but that doesn't exist yet.]
12361 Strip the directory from FILE_NAME and search again. */
12362 if (*debug_file_directory
!= '\0')
12364 /* Don't implicitly search the current directory here.
12365 If the user wants to search "." to handle this case,
12366 it must be added to debug-file-directory. */
12367 return try_open_dwop_file (dwarf2_per_objfile
,
12368 lbasename (file_name
), 1 /*is_dwp*/,
12375 /* Initialize the use of the DWP file for the current objfile.
12376 By convention the name of the DWP file is ${objfile}.dwp.
12377 The result is NULL if it can't be found. */
12379 static std::unique_ptr
<struct dwp_file
>
12380 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12382 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12384 /* Try to find first .dwp for the binary file before any symbolic links
12387 /* If the objfile is a debug file, find the name of the real binary
12388 file and get the name of dwp file from there. */
12389 std::string dwp_name
;
12390 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
12392 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
12393 const char *backlink_basename
= lbasename (backlink
->original_name
);
12395 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
12398 dwp_name
= objfile
->original_name
;
12400 dwp_name
+= ".dwp";
12402 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
12404 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
12406 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
12407 dwp_name
= objfile_name (objfile
);
12408 dwp_name
+= ".dwp";
12409 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
12414 if (dwarf_read_debug
)
12415 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
12416 return std::unique_ptr
<dwp_file
> ();
12419 const char *name
= bfd_get_filename (dbfd
.get ());
12420 std::unique_ptr
<struct dwp_file
> dwp_file
12421 (new struct dwp_file (name
, std::move (dbfd
)));
12423 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
12424 dwp_file
->elf_sections
=
12425 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
12426 dwp_file
->num_sections
, asection
*);
12428 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12429 dwarf2_locate_common_dwp_sections
,
12432 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12435 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12438 /* The DWP file version is stored in the hash table. Oh well. */
12439 if (dwp_file
->cus
&& dwp_file
->tus
12440 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
12442 /* Technically speaking, we should try to limp along, but this is
12443 pretty bizarre. We use pulongest here because that's the established
12444 portability solution (e.g, we cannot use %u for uint32_t). */
12445 error (_("Dwarf Error: DWP file CU version %s doesn't match"
12446 " TU version %s [in DWP file %s]"),
12447 pulongest (dwp_file
->cus
->version
),
12448 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
12452 dwp_file
->version
= dwp_file
->cus
->version
;
12453 else if (dwp_file
->tus
)
12454 dwp_file
->version
= dwp_file
->tus
->version
;
12456 dwp_file
->version
= 2;
12458 if (dwp_file
->version
== 2)
12459 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12460 dwarf2_locate_v2_dwp_sections
,
12463 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
12464 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
12466 if (dwarf_read_debug
)
12468 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
12469 fprintf_unfiltered (gdb_stdlog
,
12470 " %s CUs, %s TUs\n",
12471 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
12472 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
12478 /* Wrapper around open_and_init_dwp_file, only open it once. */
12480 static struct dwp_file
*
12481 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12483 if (! dwarf2_per_objfile
->dwp_checked
)
12485 dwarf2_per_objfile
->dwp_file
12486 = open_and_init_dwp_file (dwarf2_per_objfile
);
12487 dwarf2_per_objfile
->dwp_checked
= 1;
12489 return dwarf2_per_objfile
->dwp_file
.get ();
12492 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
12493 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
12494 or in the DWP file for the objfile, referenced by THIS_UNIT.
12495 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
12496 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
12498 This is called, for example, when wanting to read a variable with a
12499 complex location. Therefore we don't want to do file i/o for every call.
12500 Therefore we don't want to look for a DWO file on every call.
12501 Therefore we first see if we've already seen SIGNATURE in a DWP file,
12502 then we check if we've already seen DWO_NAME, and only THEN do we check
12505 The result is a pointer to the dwo_unit object or NULL if we didn't find it
12506 (dwo_id mismatch or couldn't find the DWO/DWP file). */
12508 static struct dwo_unit
*
12509 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
12510 const char *dwo_name
, const char *comp_dir
,
12511 ULONGEST signature
, int is_debug_types
)
12513 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_unit
->dwarf2_per_objfile
;
12514 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12515 const char *kind
= is_debug_types
? "TU" : "CU";
12516 void **dwo_file_slot
;
12517 struct dwo_file
*dwo_file
;
12518 struct dwp_file
*dwp_file
;
12520 /* First see if there's a DWP file.
12521 If we have a DWP file but didn't find the DWO inside it, don't
12522 look for the original DWO file. It makes gdb behave differently
12523 depending on whether one is debugging in the build tree. */
12525 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
12526 if (dwp_file
!= NULL
)
12528 const struct dwp_hash_table
*dwp_htab
=
12529 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12531 if (dwp_htab
!= NULL
)
12533 struct dwo_unit
*dwo_cutu
=
12534 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
12535 signature
, is_debug_types
);
12537 if (dwo_cutu
!= NULL
)
12539 if (dwarf_read_debug
)
12541 fprintf_unfiltered (gdb_stdlog
,
12542 "Virtual DWO %s %s found: @%s\n",
12543 kind
, hex_string (signature
),
12544 host_address_to_string (dwo_cutu
));
12552 /* No DWP file, look for the DWO file. */
12554 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12555 dwo_name
, comp_dir
);
12556 if (*dwo_file_slot
== NULL
)
12558 /* Read in the file and build a table of the CUs/TUs it contains. */
12559 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
12561 /* NOTE: This will be NULL if unable to open the file. */
12562 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12564 if (dwo_file
!= NULL
)
12566 struct dwo_unit
*dwo_cutu
= NULL
;
12568 if (is_debug_types
&& dwo_file
->tus
)
12570 struct dwo_unit find_dwo_cutu
;
12572 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12573 find_dwo_cutu
.signature
= signature
;
12575 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
12578 else if (!is_debug_types
&& dwo_file
->cus
)
12580 struct dwo_unit find_dwo_cutu
;
12582 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12583 find_dwo_cutu
.signature
= signature
;
12584 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
12588 if (dwo_cutu
!= NULL
)
12590 if (dwarf_read_debug
)
12592 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
12593 kind
, dwo_name
, hex_string (signature
),
12594 host_address_to_string (dwo_cutu
));
12601 /* We didn't find it. This could mean a dwo_id mismatch, or
12602 someone deleted the DWO/DWP file, or the search path isn't set up
12603 correctly to find the file. */
12605 if (dwarf_read_debug
)
12607 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
12608 kind
, dwo_name
, hex_string (signature
));
12611 /* This is a warning and not a complaint because it can be caused by
12612 pilot error (e.g., user accidentally deleting the DWO). */
12614 /* Print the name of the DWP file if we looked there, helps the user
12615 better diagnose the problem. */
12616 std::string dwp_text
;
12618 if (dwp_file
!= NULL
)
12619 dwp_text
= string_printf (" [in DWP file %s]",
12620 lbasename (dwp_file
->name
));
12622 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
12623 " [in module %s]"),
12624 kind
, dwo_name
, hex_string (signature
),
12626 this_unit
->is_debug_types
? "TU" : "CU",
12627 sect_offset_str (this_unit
->sect_off
), objfile_name (objfile
));
12632 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
12633 See lookup_dwo_cutu_unit for details. */
12635 static struct dwo_unit
*
12636 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
12637 const char *dwo_name
, const char *comp_dir
,
12638 ULONGEST signature
)
12640 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
12643 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
12644 See lookup_dwo_cutu_unit for details. */
12646 static struct dwo_unit
*
12647 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
12648 const char *dwo_name
, const char *comp_dir
)
12650 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
12653 /* Traversal function for queue_and_load_all_dwo_tus. */
12656 queue_and_load_dwo_tu (void **slot
, void *info
)
12658 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
12659 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
12660 ULONGEST signature
= dwo_unit
->signature
;
12661 struct signatured_type
*sig_type
=
12662 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
12664 if (sig_type
!= NULL
)
12666 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
12668 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
12669 a real dependency of PER_CU on SIG_TYPE. That is detected later
12670 while processing PER_CU. */
12671 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
12672 load_full_type_unit (sig_cu
);
12673 per_cu
->imported_symtabs_push (sig_cu
);
12679 /* Queue all TUs contained in the DWO of PER_CU to be read in.
12680 The DWO may have the only definition of the type, though it may not be
12681 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
12682 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
12685 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
12687 struct dwo_unit
*dwo_unit
;
12688 struct dwo_file
*dwo_file
;
12690 gdb_assert (!per_cu
->is_debug_types
);
12691 gdb_assert (get_dwp_file (per_cu
->dwarf2_per_objfile
) == NULL
);
12692 gdb_assert (per_cu
->cu
!= NULL
);
12694 dwo_unit
= per_cu
->cu
->dwo_unit
;
12695 gdb_assert (dwo_unit
!= NULL
);
12697 dwo_file
= dwo_unit
->dwo_file
;
12698 if (dwo_file
->tus
!= NULL
)
12699 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
,
12703 /* Read in various DIEs. */
12705 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
12706 Inherit only the children of the DW_AT_abstract_origin DIE not being
12707 already referenced by DW_AT_abstract_origin from the children of the
12711 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
12713 struct die_info
*child_die
;
12714 sect_offset
*offsetp
;
12715 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
12716 struct die_info
*origin_die
;
12717 /* Iterator of the ORIGIN_DIE children. */
12718 struct die_info
*origin_child_die
;
12719 struct attribute
*attr
;
12720 struct dwarf2_cu
*origin_cu
;
12721 struct pending
**origin_previous_list_in_scope
;
12723 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
12727 /* Note that following die references may follow to a die in a
12731 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
12733 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
12735 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
12736 origin_cu
->list_in_scope
= cu
->list_in_scope
;
12738 if (die
->tag
!= origin_die
->tag
12739 && !(die
->tag
== DW_TAG_inlined_subroutine
12740 && origin_die
->tag
== DW_TAG_subprogram
))
12741 complaint (_("DIE %s and its abstract origin %s have different tags"),
12742 sect_offset_str (die
->sect_off
),
12743 sect_offset_str (origin_die
->sect_off
));
12745 std::vector
<sect_offset
> offsets
;
12747 for (child_die
= die
->child
;
12748 child_die
&& child_die
->tag
;
12749 child_die
= child_die
->sibling
)
12751 struct die_info
*child_origin_die
;
12752 struct dwarf2_cu
*child_origin_cu
;
12754 /* We are trying to process concrete instance entries:
12755 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
12756 it's not relevant to our analysis here. i.e. detecting DIEs that are
12757 present in the abstract instance but not referenced in the concrete
12759 if (child_die
->tag
== DW_TAG_call_site
12760 || child_die
->tag
== DW_TAG_GNU_call_site
)
12763 /* For each CHILD_DIE, find the corresponding child of
12764 ORIGIN_DIE. If there is more than one layer of
12765 DW_AT_abstract_origin, follow them all; there shouldn't be,
12766 but GCC versions at least through 4.4 generate this (GCC PR
12768 child_origin_die
= child_die
;
12769 child_origin_cu
= cu
;
12772 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
12776 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
12780 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
12781 counterpart may exist. */
12782 if (child_origin_die
!= child_die
)
12784 if (child_die
->tag
!= child_origin_die
->tag
12785 && !(child_die
->tag
== DW_TAG_inlined_subroutine
12786 && child_origin_die
->tag
== DW_TAG_subprogram
))
12787 complaint (_("Child DIE %s and its abstract origin %s have "
12789 sect_offset_str (child_die
->sect_off
),
12790 sect_offset_str (child_origin_die
->sect_off
));
12791 if (child_origin_die
->parent
!= origin_die
)
12792 complaint (_("Child DIE %s and its abstract origin %s have "
12793 "different parents"),
12794 sect_offset_str (child_die
->sect_off
),
12795 sect_offset_str (child_origin_die
->sect_off
));
12797 offsets
.push_back (child_origin_die
->sect_off
);
12800 std::sort (offsets
.begin (), offsets
.end ());
12801 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
12802 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
12803 if (offsetp
[-1] == *offsetp
)
12804 complaint (_("Multiple children of DIE %s refer "
12805 "to DIE %s as their abstract origin"),
12806 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
12808 offsetp
= offsets
.data ();
12809 origin_child_die
= origin_die
->child
;
12810 while (origin_child_die
&& origin_child_die
->tag
)
12812 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
12813 while (offsetp
< offsets_end
12814 && *offsetp
< origin_child_die
->sect_off
)
12816 if (offsetp
>= offsets_end
12817 || *offsetp
> origin_child_die
->sect_off
)
12819 /* Found that ORIGIN_CHILD_DIE is really not referenced.
12820 Check whether we're already processing ORIGIN_CHILD_DIE.
12821 This can happen with mutually referenced abstract_origins.
12823 if (!origin_child_die
->in_process
)
12824 process_die (origin_child_die
, origin_cu
);
12826 origin_child_die
= origin_child_die
->sibling
;
12828 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
12830 if (cu
!= origin_cu
)
12831 compute_delayed_physnames (origin_cu
);
12835 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12837 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
12838 struct gdbarch
*gdbarch
= objfile
->arch ();
12839 struct context_stack
*newobj
;
12842 struct die_info
*child_die
;
12843 struct attribute
*attr
, *call_line
, *call_file
;
12845 CORE_ADDR baseaddr
;
12846 struct block
*block
;
12847 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
12848 std::vector
<struct symbol
*> template_args
;
12849 struct template_symbol
*templ_func
= NULL
;
12853 /* If we do not have call site information, we can't show the
12854 caller of this inlined function. That's too confusing, so
12855 only use the scope for local variables. */
12856 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
12857 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
12858 if (call_line
== NULL
|| call_file
== NULL
)
12860 read_lexical_block_scope (die
, cu
);
12865 baseaddr
= objfile
->text_section_offset ();
12867 name
= dwarf2_name (die
, cu
);
12869 /* Ignore functions with missing or empty names. These are actually
12870 illegal according to the DWARF standard. */
12873 complaint (_("missing name for subprogram DIE at %s"),
12874 sect_offset_str (die
->sect_off
));
12878 /* Ignore functions with missing or invalid low and high pc attributes. */
12879 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
12880 <= PC_BOUNDS_INVALID
)
12882 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
12883 if (!attr
|| !DW_UNSND (attr
))
12884 complaint (_("cannot get low and high bounds "
12885 "for subprogram DIE at %s"),
12886 sect_offset_str (die
->sect_off
));
12890 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
12891 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
12893 /* If we have any template arguments, then we must allocate a
12894 different sort of symbol. */
12895 for (child_die
= die
->child
; child_die
; child_die
= child_die
->sibling
)
12897 if (child_die
->tag
== DW_TAG_template_type_param
12898 || child_die
->tag
== DW_TAG_template_value_param
)
12900 templ_func
= allocate_template_symbol (objfile
);
12901 templ_func
->subclass
= SYMBOL_TEMPLATE
;
12906 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
12907 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
12908 (struct symbol
*) templ_func
);
12910 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
12911 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
12914 /* If there is a location expression for DW_AT_frame_base, record
12916 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
12917 if (attr
!= nullptr)
12918 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
12920 /* If there is a location for the static link, record it. */
12921 newobj
->static_link
= NULL
;
12922 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
12923 if (attr
!= nullptr)
12925 newobj
->static_link
12926 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
12927 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
12928 cu
->per_cu
->addr_type ());
12931 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
12933 if (die
->child
!= NULL
)
12935 child_die
= die
->child
;
12936 while (child_die
&& child_die
->tag
)
12938 if (child_die
->tag
== DW_TAG_template_type_param
12939 || child_die
->tag
== DW_TAG_template_value_param
)
12941 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
12944 template_args
.push_back (arg
);
12947 process_die (child_die
, cu
);
12948 child_die
= child_die
->sibling
;
12952 inherit_abstract_dies (die
, cu
);
12954 /* If we have a DW_AT_specification, we might need to import using
12955 directives from the context of the specification DIE. See the
12956 comment in determine_prefix. */
12957 if (cu
->language
== language_cplus
12958 && dwarf2_attr (die
, DW_AT_specification
, cu
))
12960 struct dwarf2_cu
*spec_cu
= cu
;
12961 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
12965 child_die
= spec_die
->child
;
12966 while (child_die
&& child_die
->tag
)
12968 if (child_die
->tag
== DW_TAG_imported_module
)
12969 process_die (child_die
, spec_cu
);
12970 child_die
= child_die
->sibling
;
12973 /* In some cases, GCC generates specification DIEs that
12974 themselves contain DW_AT_specification attributes. */
12975 spec_die
= die_specification (spec_die
, &spec_cu
);
12979 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
12980 /* Make a block for the local symbols within. */
12981 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
12982 cstk
.static_link
, lowpc
, highpc
);
12984 /* For C++, set the block's scope. */
12985 if ((cu
->language
== language_cplus
12986 || cu
->language
== language_fortran
12987 || cu
->language
== language_d
12988 || cu
->language
== language_rust
)
12989 && cu
->processing_has_namespace_info
)
12990 block_set_scope (block
, determine_prefix (die
, cu
),
12991 &objfile
->objfile_obstack
);
12993 /* If we have address ranges, record them. */
12994 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
12996 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
12998 /* Attach template arguments to function. */
12999 if (!template_args
.empty ())
13001 gdb_assert (templ_func
!= NULL
);
13003 templ_func
->n_template_arguments
= template_args
.size ();
13004 templ_func
->template_arguments
13005 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13006 templ_func
->n_template_arguments
);
13007 memcpy (templ_func
->template_arguments
,
13008 template_args
.data (),
13009 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13011 /* Make sure that the symtab is set on the new symbols. Even
13012 though they don't appear in this symtab directly, other parts
13013 of gdb assume that symbols do, and this is reasonably
13015 for (symbol
*sym
: template_args
)
13016 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13019 /* In C++, we can have functions nested inside functions (e.g., when
13020 a function declares a class that has methods). This means that
13021 when we finish processing a function scope, we may need to go
13022 back to building a containing block's symbol lists. */
13023 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13024 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13026 /* If we've finished processing a top-level function, subsequent
13027 symbols go in the file symbol list. */
13028 if (cu
->get_builder ()->outermost_context_p ())
13029 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13032 /* Process all the DIES contained within a lexical block scope. Start
13033 a new scope, process the dies, and then close the scope. */
13036 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13038 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13039 struct gdbarch
*gdbarch
= objfile
->arch ();
13040 CORE_ADDR lowpc
, highpc
;
13041 struct die_info
*child_die
;
13042 CORE_ADDR baseaddr
;
13044 baseaddr
= objfile
->text_section_offset ();
13046 /* Ignore blocks with missing or invalid low and high pc attributes. */
13047 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13048 as multiple lexical blocks? Handling children in a sane way would
13049 be nasty. Might be easier to properly extend generic blocks to
13050 describe ranges. */
13051 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13053 case PC_BOUNDS_NOT_PRESENT
:
13054 /* DW_TAG_lexical_block has no attributes, process its children as if
13055 there was no wrapping by that DW_TAG_lexical_block.
13056 GCC does no longer produces such DWARF since GCC r224161. */
13057 for (child_die
= die
->child
;
13058 child_die
!= NULL
&& child_die
->tag
;
13059 child_die
= child_die
->sibling
)
13060 process_die (child_die
, cu
);
13062 case PC_BOUNDS_INVALID
:
13065 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13066 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13068 cu
->get_builder ()->push_context (0, lowpc
);
13069 if (die
->child
!= NULL
)
13071 child_die
= die
->child
;
13072 while (child_die
&& child_die
->tag
)
13074 process_die (child_die
, cu
);
13075 child_die
= child_die
->sibling
;
13078 inherit_abstract_dies (die
, cu
);
13079 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13081 if (*cu
->get_builder ()->get_local_symbols () != NULL
13082 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13084 struct block
*block
13085 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13086 cstk
.start_addr
, highpc
);
13088 /* Note that recording ranges after traversing children, as we
13089 do here, means that recording a parent's ranges entails
13090 walking across all its children's ranges as they appear in
13091 the address map, which is quadratic behavior.
13093 It would be nicer to record the parent's ranges before
13094 traversing its children, simply overriding whatever you find
13095 there. But since we don't even decide whether to create a
13096 block until after we've traversed its children, that's hard
13098 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13100 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13101 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13104 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13107 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13109 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13110 struct gdbarch
*gdbarch
= objfile
->arch ();
13111 CORE_ADDR pc
, baseaddr
;
13112 struct attribute
*attr
;
13113 struct call_site
*call_site
, call_site_local
;
13116 struct die_info
*child_die
;
13118 baseaddr
= objfile
->text_section_offset ();
13120 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13123 /* This was a pre-DWARF-5 GNU extension alias
13124 for DW_AT_call_return_pc. */
13125 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13129 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13130 "DIE %s [in module %s]"),
13131 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13134 pc
= attr
->value_as_address () + baseaddr
;
13135 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13137 if (cu
->call_site_htab
== NULL
)
13138 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13139 NULL
, &objfile
->objfile_obstack
,
13140 hashtab_obstack_allocate
, NULL
);
13141 call_site_local
.pc
= pc
;
13142 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13145 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13146 "DIE %s [in module %s]"),
13147 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13148 objfile_name (objfile
));
13152 /* Count parameters at the caller. */
13155 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13156 child_die
= child_die
->sibling
)
13158 if (child_die
->tag
!= DW_TAG_call_site_parameter
13159 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13161 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13162 "DW_TAG_call_site child DIE %s [in module %s]"),
13163 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13164 objfile_name (objfile
));
13172 = ((struct call_site
*)
13173 obstack_alloc (&objfile
->objfile_obstack
,
13174 sizeof (*call_site
)
13175 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13177 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13178 call_site
->pc
= pc
;
13180 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13181 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13183 struct die_info
*func_die
;
13185 /* Skip also over DW_TAG_inlined_subroutine. */
13186 for (func_die
= die
->parent
;
13187 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13188 && func_die
->tag
!= DW_TAG_subroutine_type
;
13189 func_die
= func_die
->parent
);
13191 /* DW_AT_call_all_calls is a superset
13192 of DW_AT_call_all_tail_calls. */
13194 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13195 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13196 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13197 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13199 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13200 not complete. But keep CALL_SITE for look ups via call_site_htab,
13201 both the initial caller containing the real return address PC and
13202 the final callee containing the current PC of a chain of tail
13203 calls do not need to have the tail call list complete. But any
13204 function candidate for a virtual tail call frame searched via
13205 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13206 determined unambiguously. */
13210 struct type
*func_type
= NULL
;
13213 func_type
= get_die_type (func_die
, cu
);
13214 if (func_type
!= NULL
)
13216 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
13218 /* Enlist this call site to the function. */
13219 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13220 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13223 complaint (_("Cannot find function owning DW_TAG_call_site "
13224 "DIE %s [in module %s]"),
13225 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13229 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13231 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13233 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13236 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13237 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13239 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13240 if (!attr
|| (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0))
13241 /* Keep NULL DWARF_BLOCK. */;
13242 else if (attr
->form_is_block ())
13244 struct dwarf2_locexpr_baton
*dlbaton
;
13246 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13247 dlbaton
->data
= DW_BLOCK (attr
)->data
;
13248 dlbaton
->size
= DW_BLOCK (attr
)->size
;
13249 dlbaton
->per_cu
= cu
->per_cu
;
13251 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13253 else if (attr
->form_is_ref ())
13255 struct dwarf2_cu
*target_cu
= cu
;
13256 struct die_info
*target_die
;
13258 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13259 gdb_assert (target_cu
->per_cu
->dwarf2_per_objfile
->objfile
== objfile
);
13260 if (die_is_declaration (target_die
, target_cu
))
13262 const char *target_physname
;
13264 /* Prefer the mangled name; otherwise compute the demangled one. */
13265 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13266 if (target_physname
== NULL
)
13267 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13268 if (target_physname
== NULL
)
13269 complaint (_("DW_AT_call_target target DIE has invalid "
13270 "physname, for referencing DIE %s [in module %s]"),
13271 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13273 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13279 /* DW_AT_entry_pc should be preferred. */
13280 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13281 <= PC_BOUNDS_INVALID
)
13282 complaint (_("DW_AT_call_target target DIE has invalid "
13283 "low pc, for referencing DIE %s [in module %s]"),
13284 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13287 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13288 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
13293 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13294 "block nor reference, for DIE %s [in module %s]"),
13295 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13297 call_site
->per_cu
= cu
->per_cu
;
13299 for (child_die
= die
->child
;
13300 child_die
&& child_die
->tag
;
13301 child_die
= child_die
->sibling
)
13303 struct call_site_parameter
*parameter
;
13304 struct attribute
*loc
, *origin
;
13306 if (child_die
->tag
!= DW_TAG_call_site_parameter
13307 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13309 /* Already printed the complaint above. */
13313 gdb_assert (call_site
->parameter_count
< nparams
);
13314 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13316 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13317 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13318 register is contained in DW_AT_call_value. */
13320 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13321 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13322 if (origin
== NULL
)
13324 /* This was a pre-DWARF-5 GNU extension alias
13325 for DW_AT_call_parameter. */
13326 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13328 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
13330 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13332 sect_offset sect_off
= origin
->get_ref_die_offset ();
13333 if (!cu
->header
.offset_in_cu_p (sect_off
))
13335 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13336 binding can be done only inside one CU. Such referenced DIE
13337 therefore cannot be even moved to DW_TAG_partial_unit. */
13338 complaint (_("DW_AT_call_parameter offset is not in CU for "
13339 "DW_TAG_call_site child DIE %s [in module %s]"),
13340 sect_offset_str (child_die
->sect_off
),
13341 objfile_name (objfile
));
13344 parameter
->u
.param_cu_off
13345 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13347 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
13349 complaint (_("No DW_FORM_block* DW_AT_location for "
13350 "DW_TAG_call_site child DIE %s [in module %s]"),
13351 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13356 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13357 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
13358 if (parameter
->u
.dwarf_reg
!= -1)
13359 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13360 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
13361 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
13362 ¶meter
->u
.fb_offset
))
13363 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13366 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13367 "for DW_FORM_block* DW_AT_location is supported for "
13368 "DW_TAG_call_site child DIE %s "
13370 sect_offset_str (child_die
->sect_off
),
13371 objfile_name (objfile
));
13376 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13378 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13379 if (attr
== NULL
|| !attr
->form_is_block ())
13381 complaint (_("No DW_FORM_block* DW_AT_call_value for "
13382 "DW_TAG_call_site child DIE %s [in module %s]"),
13383 sect_offset_str (child_die
->sect_off
),
13384 objfile_name (objfile
));
13387 parameter
->value
= DW_BLOCK (attr
)->data
;
13388 parameter
->value_size
= DW_BLOCK (attr
)->size
;
13390 /* Parameters are not pre-cleared by memset above. */
13391 parameter
->data_value
= NULL
;
13392 parameter
->data_value_size
= 0;
13393 call_site
->parameter_count
++;
13395 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
13397 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
13398 if (attr
!= nullptr)
13400 if (!attr
->form_is_block ())
13401 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
13402 "DW_TAG_call_site child DIE %s [in module %s]"),
13403 sect_offset_str (child_die
->sect_off
),
13404 objfile_name (objfile
));
13407 parameter
->data_value
= DW_BLOCK (attr
)->data
;
13408 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
13414 /* Helper function for read_variable. If DIE represents a virtual
13415 table, then return the type of the concrete object that is
13416 associated with the virtual table. Otherwise, return NULL. */
13418 static struct type
*
13419 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13421 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13425 /* Find the type DIE. */
13426 struct die_info
*type_die
= NULL
;
13427 struct dwarf2_cu
*type_cu
= cu
;
13429 if (attr
->form_is_ref ())
13430 type_die
= follow_die_ref (die
, attr
, &type_cu
);
13431 if (type_die
== NULL
)
13434 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
13436 return die_containing_type (type_die
, type_cu
);
13439 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
13442 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
13444 struct rust_vtable_symbol
*storage
= NULL
;
13446 if (cu
->language
== language_rust
)
13448 struct type
*containing_type
= rust_containing_type (die
, cu
);
13450 if (containing_type
!= NULL
)
13452 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13454 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol ();
13455 initialize_objfile_symbol (storage
);
13456 storage
->concrete_type
= containing_type
;
13457 storage
->subclass
= SYMBOL_RUST_VTABLE
;
13461 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
13462 struct attribute
*abstract_origin
13463 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13464 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
13465 if (res
== NULL
&& loc
&& abstract_origin
)
13467 /* We have a variable without a name, but with a location and an abstract
13468 origin. This may be a concrete instance of an abstract variable
13469 referenced from an DW_OP_GNU_variable_value, so save it to find it back
13471 struct dwarf2_cu
*origin_cu
= cu
;
13472 struct die_info
*origin_die
13473 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
13474 dwarf2_per_objfile
*dpo
= cu
->per_cu
->dwarf2_per_objfile
;
13475 dpo
->abstract_to_concrete
[origin_die
->sect_off
].push_back (die
->sect_off
);
13479 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
13480 reading .debug_rnglists.
13481 Callback's type should be:
13482 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13483 Return true if the attributes are present and valid, otherwise,
13486 template <typename Callback
>
13488 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
13489 Callback
&&callback
)
13491 struct dwarf2_per_objfile
*dwarf2_per_objfile
13492 = cu
->per_cu
->dwarf2_per_objfile
;
13493 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13494 bfd
*obfd
= objfile
->obfd
;
13495 /* Base address selection entry. */
13496 gdb::optional
<CORE_ADDR
> base
;
13497 const gdb_byte
*buffer
;
13498 CORE_ADDR baseaddr
;
13499 bool overflow
= false;
13501 base
= cu
->base_address
;
13503 dwarf2_per_objfile
->rnglists
.read (objfile
);
13504 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
13506 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13510 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
13512 baseaddr
= objfile
->text_section_offset ();
13516 /* Initialize it due to a false compiler warning. */
13517 CORE_ADDR range_beginning
= 0, range_end
= 0;
13518 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
13519 + dwarf2_per_objfile
->rnglists
.size
);
13520 unsigned int bytes_read
;
13522 if (buffer
== buf_end
)
13527 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
13530 case DW_RLE_end_of_list
:
13532 case DW_RLE_base_address
:
13533 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13538 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13539 buffer
+= bytes_read
;
13541 case DW_RLE_start_length
:
13542 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13547 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13549 buffer
+= bytes_read
;
13550 range_end
= (range_beginning
13551 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13552 buffer
+= bytes_read
;
13553 if (buffer
> buf_end
)
13559 case DW_RLE_offset_pair
:
13560 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13561 buffer
+= bytes_read
;
13562 if (buffer
> buf_end
)
13567 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13568 buffer
+= bytes_read
;
13569 if (buffer
> buf_end
)
13575 case DW_RLE_start_end
:
13576 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
13581 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13583 buffer
+= bytes_read
;
13584 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13585 buffer
+= bytes_read
;
13588 complaint (_("Invalid .debug_rnglists data (no base address)"));
13591 if (rlet
== DW_RLE_end_of_list
|| overflow
)
13593 if (rlet
== DW_RLE_base_address
)
13596 if (!base
.has_value ())
13598 /* We have no valid base address for the ranges
13600 complaint (_("Invalid .debug_rnglists data (no base address)"));
13604 if (range_beginning
> range_end
)
13606 /* Inverted range entries are invalid. */
13607 complaint (_("Invalid .debug_rnglists data (inverted range)"));
13611 /* Empty range entries have no effect. */
13612 if (range_beginning
== range_end
)
13615 range_beginning
+= *base
;
13616 range_end
+= *base
;
13618 /* A not-uncommon case of bad debug info.
13619 Don't pollute the addrmap with bad data. */
13620 if (range_beginning
+ baseaddr
== 0
13621 && !dwarf2_per_objfile
->has_section_at_zero
)
13623 complaint (_(".debug_rnglists entry has start address of zero"
13624 " [in module %s]"), objfile_name (objfile
));
13628 callback (range_beginning
, range_end
);
13633 complaint (_("Offset %d is not terminated "
13634 "for DW_AT_ranges attribute"),
13642 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
13643 Callback's type should be:
13644 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13645 Return 1 if the attributes are present and valid, otherwise, return 0. */
13647 template <typename Callback
>
13649 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
13650 Callback
&&callback
)
13652 struct dwarf2_per_objfile
*dwarf2_per_objfile
13653 = cu
->per_cu
->dwarf2_per_objfile
;
13654 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13655 struct comp_unit_head
*cu_header
= &cu
->header
;
13656 bfd
*obfd
= objfile
->obfd
;
13657 unsigned int addr_size
= cu_header
->addr_size
;
13658 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
13659 /* Base address selection entry. */
13660 gdb::optional
<CORE_ADDR
> base
;
13661 unsigned int dummy
;
13662 const gdb_byte
*buffer
;
13663 CORE_ADDR baseaddr
;
13665 if (cu_header
->version
>= 5)
13666 return dwarf2_rnglists_process (offset
, cu
, callback
);
13668 base
= cu
->base_address
;
13670 dwarf2_per_objfile
->ranges
.read (objfile
);
13671 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
13673 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13677 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
13679 baseaddr
= objfile
->text_section_offset ();
13683 CORE_ADDR range_beginning
, range_end
;
13685 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13686 buffer
+= addr_size
;
13687 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13688 buffer
+= addr_size
;
13689 offset
+= 2 * addr_size
;
13691 /* An end of list marker is a pair of zero addresses. */
13692 if (range_beginning
== 0 && range_end
== 0)
13693 /* Found the end of list entry. */
13696 /* Each base address selection entry is a pair of 2 values.
13697 The first is the largest possible address, the second is
13698 the base address. Check for a base address here. */
13699 if ((range_beginning
& mask
) == mask
)
13701 /* If we found the largest possible address, then we already
13702 have the base address in range_end. */
13707 if (!base
.has_value ())
13709 /* We have no valid base address for the ranges
13711 complaint (_("Invalid .debug_ranges data (no base address)"));
13715 if (range_beginning
> range_end
)
13717 /* Inverted range entries are invalid. */
13718 complaint (_("Invalid .debug_ranges data (inverted range)"));
13722 /* Empty range entries have no effect. */
13723 if (range_beginning
== range_end
)
13726 range_beginning
+= *base
;
13727 range_end
+= *base
;
13729 /* A not-uncommon case of bad debug info.
13730 Don't pollute the addrmap with bad data. */
13731 if (range_beginning
+ baseaddr
== 0
13732 && !dwarf2_per_objfile
->has_section_at_zero
)
13734 complaint (_(".debug_ranges entry has start address of zero"
13735 " [in module %s]"), objfile_name (objfile
));
13739 callback (range_beginning
, range_end
);
13745 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
13746 Return 1 if the attributes are present and valid, otherwise, return 0.
13747 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
13750 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
13751 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
13752 dwarf2_psymtab
*ranges_pst
)
13754 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13755 struct gdbarch
*gdbarch
= objfile
->arch ();
13756 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
13759 CORE_ADDR high
= 0;
13762 retval
= dwarf2_ranges_process (offset
, cu
,
13763 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
13765 if (ranges_pst
!= NULL
)
13770 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13771 range_beginning
+ baseaddr
)
13773 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13774 range_end
+ baseaddr
)
13776 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
13777 lowpc
, highpc
- 1, ranges_pst
);
13780 /* FIXME: This is recording everything as a low-high
13781 segment of consecutive addresses. We should have a
13782 data structure for discontiguous block ranges
13786 low
= range_beginning
;
13792 if (range_beginning
< low
)
13793 low
= range_beginning
;
13794 if (range_end
> high
)
13802 /* If the first entry is an end-of-list marker, the range
13803 describes an empty scope, i.e. no instructions. */
13809 *high_return
= high
;
13813 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
13814 definition for the return value. *LOWPC and *HIGHPC are set iff
13815 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
13817 static enum pc_bounds_kind
13818 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
13819 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
13820 dwarf2_psymtab
*pst
)
13822 struct dwarf2_per_objfile
*dwarf2_per_objfile
13823 = cu
->per_cu
->dwarf2_per_objfile
;
13824 struct attribute
*attr
;
13825 struct attribute
*attr_high
;
13827 CORE_ADDR high
= 0;
13828 enum pc_bounds_kind ret
;
13830 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
13833 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13834 if (attr
!= nullptr)
13836 low
= attr
->value_as_address ();
13837 high
= attr_high
->value_as_address ();
13838 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
13842 /* Found high w/o low attribute. */
13843 return PC_BOUNDS_INVALID
;
13845 /* Found consecutive range of addresses. */
13846 ret
= PC_BOUNDS_HIGH_LOW
;
13850 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
13853 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
13854 We take advantage of the fact that DW_AT_ranges does not appear
13855 in DW_TAG_compile_unit of DWO files. */
13856 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
13857 unsigned int ranges_offset
= (DW_UNSND (attr
)
13858 + (need_ranges_base
13862 /* Value of the DW_AT_ranges attribute is the offset in the
13863 .debug_ranges section. */
13864 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
13865 return PC_BOUNDS_INVALID
;
13866 /* Found discontinuous range of addresses. */
13867 ret
= PC_BOUNDS_RANGES
;
13870 return PC_BOUNDS_NOT_PRESENT
;
13873 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
13875 return PC_BOUNDS_INVALID
;
13877 /* When using the GNU linker, .gnu.linkonce. sections are used to
13878 eliminate duplicate copies of functions and vtables and such.
13879 The linker will arbitrarily choose one and discard the others.
13880 The AT_*_pc values for such functions refer to local labels in
13881 these sections. If the section from that file was discarded, the
13882 labels are not in the output, so the relocs get a value of 0.
13883 If this is a discarded function, mark the pc bounds as invalid,
13884 so that GDB will ignore it. */
13885 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
13886 return PC_BOUNDS_INVALID
;
13894 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
13895 its low and high PC addresses. Do nothing if these addresses could not
13896 be determined. Otherwise, set LOWPC to the low address if it is smaller,
13897 and HIGHPC to the high address if greater than HIGHPC. */
13900 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
13901 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
13902 struct dwarf2_cu
*cu
)
13904 CORE_ADDR low
, high
;
13905 struct die_info
*child
= die
->child
;
13907 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
13909 *lowpc
= std::min (*lowpc
, low
);
13910 *highpc
= std::max (*highpc
, high
);
13913 /* If the language does not allow nested subprograms (either inside
13914 subprograms or lexical blocks), we're done. */
13915 if (cu
->language
!= language_ada
)
13918 /* Check all the children of the given DIE. If it contains nested
13919 subprograms, then check their pc bounds. Likewise, we need to
13920 check lexical blocks as well, as they may also contain subprogram
13922 while (child
&& child
->tag
)
13924 if (child
->tag
== DW_TAG_subprogram
13925 || child
->tag
== DW_TAG_lexical_block
)
13926 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
13927 child
= child
->sibling
;
13931 /* Get the low and high pc's represented by the scope DIE, and store
13932 them in *LOWPC and *HIGHPC. If the correct values can't be
13933 determined, set *LOWPC to -1 and *HIGHPC to 0. */
13936 get_scope_pc_bounds (struct die_info
*die
,
13937 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
13938 struct dwarf2_cu
*cu
)
13940 CORE_ADDR best_low
= (CORE_ADDR
) -1;
13941 CORE_ADDR best_high
= (CORE_ADDR
) 0;
13942 CORE_ADDR current_low
, current_high
;
13944 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
13945 >= PC_BOUNDS_RANGES
)
13947 best_low
= current_low
;
13948 best_high
= current_high
;
13952 struct die_info
*child
= die
->child
;
13954 while (child
&& child
->tag
)
13956 switch (child
->tag
) {
13957 case DW_TAG_subprogram
:
13958 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
13960 case DW_TAG_namespace
:
13961 case DW_TAG_module
:
13962 /* FIXME: carlton/2004-01-16: Should we do this for
13963 DW_TAG_class_type/DW_TAG_structure_type, too? I think
13964 that current GCC's always emit the DIEs corresponding
13965 to definitions of methods of classes as children of a
13966 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
13967 the DIEs giving the declarations, which could be
13968 anywhere). But I don't see any reason why the
13969 standards says that they have to be there. */
13970 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
13972 if (current_low
!= ((CORE_ADDR
) -1))
13974 best_low
= std::min (best_low
, current_low
);
13975 best_high
= std::max (best_high
, current_high
);
13983 child
= child
->sibling
;
13988 *highpc
= best_high
;
13991 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
13995 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
13996 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
13998 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13999 struct gdbarch
*gdbarch
= objfile
->arch ();
14000 struct attribute
*attr
;
14001 struct attribute
*attr_high
;
14003 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14006 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14007 if (attr
!= nullptr)
14009 CORE_ADDR low
= attr
->value_as_address ();
14010 CORE_ADDR high
= attr_high
->value_as_address ();
14012 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14015 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14016 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14017 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14021 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14022 if (attr
!= nullptr)
14024 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14025 We take advantage of the fact that DW_AT_ranges does not appear
14026 in DW_TAG_compile_unit of DWO files. */
14027 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14029 /* The value of the DW_AT_ranges attribute is the offset of the
14030 address range list in the .debug_ranges section. */
14031 unsigned long offset
= (DW_UNSND (attr
)
14032 + (need_ranges_base
? cu
->ranges_base
: 0));
14034 std::vector
<blockrange
> blockvec
;
14035 dwarf2_ranges_process (offset
, cu
,
14036 [&] (CORE_ADDR start
, CORE_ADDR end
)
14040 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14041 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14042 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14043 blockvec
.emplace_back (start
, end
);
14046 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14050 /* Check whether the producer field indicates either of GCC < 4.6, or the
14051 Intel C/C++ compiler, and cache the result in CU. */
14054 check_producer (struct dwarf2_cu
*cu
)
14058 if (cu
->producer
== NULL
)
14060 /* For unknown compilers expect their behavior is DWARF version
14063 GCC started to support .debug_types sections by -gdwarf-4 since
14064 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14065 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14066 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14067 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14069 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14071 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14072 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14074 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14076 cu
->producer_is_icc
= true;
14077 cu
->producer_is_icc_lt_14
= major
< 14;
14079 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14080 cu
->producer_is_codewarrior
= true;
14083 /* For other non-GCC compilers, expect their behavior is DWARF version
14087 cu
->checked_producer
= true;
14090 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14091 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14092 during 4.6.0 experimental. */
14095 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14097 if (!cu
->checked_producer
)
14098 check_producer (cu
);
14100 return cu
->producer_is_gxx_lt_4_6
;
14104 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14105 with incorrect is_stmt attributes. */
14108 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14110 if (!cu
->checked_producer
)
14111 check_producer (cu
);
14113 return cu
->producer_is_codewarrior
;
14116 /* Return the default accessibility type if it is not overridden by
14117 DW_AT_accessibility. */
14119 static enum dwarf_access_attribute
14120 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14122 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14124 /* The default DWARF 2 accessibility for members is public, the default
14125 accessibility for inheritance is private. */
14127 if (die
->tag
!= DW_TAG_inheritance
)
14128 return DW_ACCESS_public
;
14130 return DW_ACCESS_private
;
14134 /* DWARF 3+ defines the default accessibility a different way. The same
14135 rules apply now for DW_TAG_inheritance as for the members and it only
14136 depends on the container kind. */
14138 if (die
->parent
->tag
== DW_TAG_class_type
)
14139 return DW_ACCESS_private
;
14141 return DW_ACCESS_public
;
14145 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14146 offset. If the attribute was not found return 0, otherwise return
14147 1. If it was found but could not properly be handled, set *OFFSET
14151 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14154 struct attribute
*attr
;
14156 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14161 /* Note that we do not check for a section offset first here.
14162 This is because DW_AT_data_member_location is new in DWARF 4,
14163 so if we see it, we can assume that a constant form is really
14164 a constant and not a section offset. */
14165 if (attr
->form_is_constant ())
14166 *offset
= attr
->constant_value (0);
14167 else if (attr
->form_is_section_offset ())
14168 dwarf2_complex_location_expr_complaint ();
14169 else if (attr
->form_is_block ())
14170 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14172 dwarf2_complex_location_expr_complaint ();
14180 /* Add an aggregate field to the field list. */
14183 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14184 struct dwarf2_cu
*cu
)
14186 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14187 struct gdbarch
*gdbarch
= objfile
->arch ();
14188 struct nextfield
*new_field
;
14189 struct attribute
*attr
;
14191 const char *fieldname
= "";
14193 if (die
->tag
== DW_TAG_inheritance
)
14195 fip
->baseclasses
.emplace_back ();
14196 new_field
= &fip
->baseclasses
.back ();
14200 fip
->fields
.emplace_back ();
14201 new_field
= &fip
->fields
.back ();
14204 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14205 if (attr
!= nullptr)
14206 new_field
->accessibility
= DW_UNSND (attr
);
14208 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
14209 if (new_field
->accessibility
!= DW_ACCESS_public
)
14210 fip
->non_public_fields
= 1;
14212 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14213 if (attr
!= nullptr)
14214 new_field
->virtuality
= DW_UNSND (attr
);
14216 new_field
->virtuality
= DW_VIRTUALITY_none
;
14218 fp
= &new_field
->field
;
14220 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14224 /* Data member other than a C++ static data member. */
14226 /* Get type of field. */
14227 fp
->type
= die_type (die
, cu
);
14229 SET_FIELD_BITPOS (*fp
, 0);
14231 /* Get bit size of field (zero if none). */
14232 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14233 if (attr
!= nullptr)
14235 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
14239 FIELD_BITSIZE (*fp
) = 0;
14242 /* Get bit offset of field. */
14243 if (handle_data_member_location (die
, cu
, &offset
))
14244 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
14245 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14246 if (attr
!= nullptr)
14248 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14250 /* For big endian bits, the DW_AT_bit_offset gives the
14251 additional bit offset from the MSB of the containing
14252 anonymous object to the MSB of the field. We don't
14253 have to do anything special since we don't need to
14254 know the size of the anonymous object. */
14255 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
14259 /* For little endian bits, compute the bit offset to the
14260 MSB of the anonymous object, subtract off the number of
14261 bits from the MSB of the field to the MSB of the
14262 object, and then subtract off the number of bits of
14263 the field itself. The result is the bit offset of
14264 the LSB of the field. */
14265 int anonymous_size
;
14266 int bit_offset
= DW_UNSND (attr
);
14268 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14269 if (attr
!= nullptr)
14271 /* The size of the anonymous object containing
14272 the bit field is explicit, so use the
14273 indicated size (in bytes). */
14274 anonymous_size
= DW_UNSND (attr
);
14278 /* The size of the anonymous object containing
14279 the bit field must be inferred from the type
14280 attribute of the data member containing the
14282 anonymous_size
= TYPE_LENGTH (fp
->type
);
14284 SET_FIELD_BITPOS (*fp
,
14285 (FIELD_BITPOS (*fp
)
14286 + anonymous_size
* bits_per_byte
14287 - bit_offset
- FIELD_BITSIZE (*fp
)));
14290 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14292 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14293 + attr
->constant_value (0)));
14295 /* Get name of field. */
14296 fieldname
= dwarf2_name (die
, cu
);
14297 if (fieldname
== NULL
)
14300 /* The name is already allocated along with this objfile, so we don't
14301 need to duplicate it for the type. */
14302 fp
->name
= fieldname
;
14304 /* Change accessibility for artificial fields (e.g. virtual table
14305 pointer or virtual base class pointer) to private. */
14306 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
14308 FIELD_ARTIFICIAL (*fp
) = 1;
14309 new_field
->accessibility
= DW_ACCESS_private
;
14310 fip
->non_public_fields
= 1;
14313 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
14315 /* C++ static member. */
14317 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
14318 is a declaration, but all versions of G++ as of this writing
14319 (so through at least 3.2.1) incorrectly generate
14320 DW_TAG_variable tags. */
14322 const char *physname
;
14324 /* Get name of field. */
14325 fieldname
= dwarf2_name (die
, cu
);
14326 if (fieldname
== NULL
)
14329 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14331 /* Only create a symbol if this is an external value.
14332 new_symbol checks this and puts the value in the global symbol
14333 table, which we want. If it is not external, new_symbol
14334 will try to put the value in cu->list_in_scope which is wrong. */
14335 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
14337 /* A static const member, not much different than an enum as far as
14338 we're concerned, except that we can support more types. */
14339 new_symbol (die
, NULL
, cu
);
14342 /* Get physical name. */
14343 physname
= dwarf2_physname (fieldname
, die
, cu
);
14345 /* The name is already allocated along with this objfile, so we don't
14346 need to duplicate it for the type. */
14347 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
14348 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14349 FIELD_NAME (*fp
) = fieldname
;
14351 else if (die
->tag
== DW_TAG_inheritance
)
14355 /* C++ base class field. */
14356 if (handle_data_member_location (die
, cu
, &offset
))
14357 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
14358 FIELD_BITSIZE (*fp
) = 0;
14359 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14360 FIELD_NAME (*fp
) = TYPE_NAME (fp
->type
);
14362 else if (die
->tag
== DW_TAG_variant_part
)
14364 /* process_structure_scope will treat this DIE as a union. */
14365 process_structure_scope (die
, cu
);
14367 /* The variant part is relative to the start of the enclosing
14369 SET_FIELD_BITPOS (*fp
, 0);
14370 fp
->type
= get_die_type (die
, cu
);
14371 fp
->artificial
= 1;
14372 fp
->name
= "<<variant>>";
14374 /* Normally a DW_TAG_variant_part won't have a size, but our
14375 representation requires one, so set it to the maximum of the
14376 child sizes, being sure to account for the offset at which
14377 each child is seen. */
14378 if (TYPE_LENGTH (fp
->type
) == 0)
14381 for (int i
= 0; i
< TYPE_NFIELDS (fp
->type
); ++i
)
14383 unsigned len
= ((TYPE_FIELD_BITPOS (fp
->type
, i
) + 7) / 8
14384 + TYPE_LENGTH (TYPE_FIELD_TYPE (fp
->type
, i
)));
14388 TYPE_LENGTH (fp
->type
) = max
;
14392 gdb_assert_not_reached ("missing case in dwarf2_add_field");
14395 /* Can the type given by DIE define another type? */
14398 type_can_define_types (const struct die_info
*die
)
14402 case DW_TAG_typedef
:
14403 case DW_TAG_class_type
:
14404 case DW_TAG_structure_type
:
14405 case DW_TAG_union_type
:
14406 case DW_TAG_enumeration_type
:
14414 /* Add a type definition defined in the scope of the FIP's class. */
14417 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
14418 struct dwarf2_cu
*cu
)
14420 struct decl_field fp
;
14421 memset (&fp
, 0, sizeof (fp
));
14423 gdb_assert (type_can_define_types (die
));
14425 /* Get name of field. NULL is okay here, meaning an anonymous type. */
14426 fp
.name
= dwarf2_name (die
, cu
);
14427 fp
.type
= read_type_die (die
, cu
);
14429 /* Save accessibility. */
14430 enum dwarf_access_attribute accessibility
;
14431 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14433 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14435 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14436 switch (accessibility
)
14438 case DW_ACCESS_public
:
14439 /* The assumed value if neither private nor protected. */
14441 case DW_ACCESS_private
:
14444 case DW_ACCESS_protected
:
14445 fp
.is_protected
= 1;
14448 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
14451 if (die
->tag
== DW_TAG_typedef
)
14452 fip
->typedef_field_list
.push_back (fp
);
14454 fip
->nested_types_list
.push_back (fp
);
14457 /* Create the vector of fields, and attach it to the type. */
14460 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
14461 struct dwarf2_cu
*cu
)
14463 int nfields
= fip
->nfields ();
14465 /* Record the field count, allocate space for the array of fields,
14466 and create blank accessibility bitfields if necessary. */
14467 TYPE_NFIELDS (type
) = nfields
;
14468 TYPE_FIELDS (type
) = (struct field
*)
14469 TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
);
14471 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
14473 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14475 TYPE_FIELD_PRIVATE_BITS (type
) =
14476 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14477 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
14479 TYPE_FIELD_PROTECTED_BITS (type
) =
14480 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14481 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
14483 TYPE_FIELD_IGNORE_BITS (type
) =
14484 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14485 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
14488 /* If the type has baseclasses, allocate and clear a bit vector for
14489 TYPE_FIELD_VIRTUAL_BITS. */
14490 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
14492 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
14493 unsigned char *pointer
;
14495 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14496 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
14497 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
14498 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
14499 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
14502 if (TYPE_FLAG_DISCRIMINATED_UNION (type
))
14504 struct discriminant_info
*di
= alloc_discriminant_info (type
, -1, -1);
14506 for (int index
= 0; index
< nfields
; ++index
)
14508 struct nextfield
&field
= fip
->fields
[index
];
14510 if (field
.variant
.is_discriminant
)
14511 di
->discriminant_index
= index
;
14512 else if (field
.variant
.default_branch
)
14513 di
->default_index
= index
;
14515 di
->discriminants
[index
] = field
.variant
.discriminant_value
;
14519 /* Copy the saved-up fields into the field vector. */
14520 for (int i
= 0; i
< nfields
; ++i
)
14522 struct nextfield
&field
14523 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
14524 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
14526 TYPE_FIELD (type
, i
) = field
.field
;
14527 switch (field
.accessibility
)
14529 case DW_ACCESS_private
:
14530 if (cu
->language
!= language_ada
)
14531 SET_TYPE_FIELD_PRIVATE (type
, i
);
14534 case DW_ACCESS_protected
:
14535 if (cu
->language
!= language_ada
)
14536 SET_TYPE_FIELD_PROTECTED (type
, i
);
14539 case DW_ACCESS_public
:
14543 /* Unknown accessibility. Complain and treat it as public. */
14545 complaint (_("unsupported accessibility %d"),
14546 field
.accessibility
);
14550 if (i
< fip
->baseclasses
.size ())
14552 switch (field
.virtuality
)
14554 case DW_VIRTUALITY_virtual
:
14555 case DW_VIRTUALITY_pure_virtual
:
14556 if (cu
->language
== language_ada
)
14557 error (_("unexpected virtuality in component of Ada type"));
14558 SET_TYPE_FIELD_VIRTUAL (type
, i
);
14565 /* Return true if this member function is a constructor, false
14569 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
14571 const char *fieldname
;
14572 const char *type_name
;
14575 if (die
->parent
== NULL
)
14578 if (die
->parent
->tag
!= DW_TAG_structure_type
14579 && die
->parent
->tag
!= DW_TAG_union_type
14580 && die
->parent
->tag
!= DW_TAG_class_type
)
14583 fieldname
= dwarf2_name (die
, cu
);
14584 type_name
= dwarf2_name (die
->parent
, cu
);
14585 if (fieldname
== NULL
|| type_name
== NULL
)
14588 len
= strlen (fieldname
);
14589 return (strncmp (fieldname
, type_name
, len
) == 0
14590 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
14593 /* Check if the given VALUE is a recognized enum
14594 dwarf_defaulted_attribute constant according to DWARF5 spec,
14598 is_valid_DW_AT_defaulted (ULONGEST value
)
14602 case DW_DEFAULTED_no
:
14603 case DW_DEFAULTED_in_class
:
14604 case DW_DEFAULTED_out_of_class
:
14608 complaint (_("unrecognized DW_AT_defaulted value (%s)"), pulongest (value
));
14612 /* Add a member function to the proper fieldlist. */
14615 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
14616 struct type
*type
, struct dwarf2_cu
*cu
)
14618 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14619 struct attribute
*attr
;
14621 struct fnfieldlist
*flp
= nullptr;
14622 struct fn_field
*fnp
;
14623 const char *fieldname
;
14624 struct type
*this_type
;
14625 enum dwarf_access_attribute accessibility
;
14627 if (cu
->language
== language_ada
)
14628 error (_("unexpected member function in Ada type"));
14630 /* Get name of member function. */
14631 fieldname
= dwarf2_name (die
, cu
);
14632 if (fieldname
== NULL
)
14635 /* Look up member function name in fieldlist. */
14636 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
14638 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
14640 flp
= &fip
->fnfieldlists
[i
];
14645 /* Create a new fnfieldlist if necessary. */
14646 if (flp
== nullptr)
14648 fip
->fnfieldlists
.emplace_back ();
14649 flp
= &fip
->fnfieldlists
.back ();
14650 flp
->name
= fieldname
;
14651 i
= fip
->fnfieldlists
.size () - 1;
14654 /* Create a new member function field and add it to the vector of
14656 flp
->fnfields
.emplace_back ();
14657 fnp
= &flp
->fnfields
.back ();
14659 /* Delay processing of the physname until later. */
14660 if (cu
->language
== language_cplus
)
14661 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
14665 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
14666 fnp
->physname
= physname
? physname
: "";
14669 fnp
->type
= alloc_type (objfile
);
14670 this_type
= read_type_die (die
, cu
);
14671 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
14673 int nparams
= TYPE_NFIELDS (this_type
);
14675 /* TYPE is the domain of this method, and THIS_TYPE is the type
14676 of the method itself (TYPE_CODE_METHOD). */
14677 smash_to_method_type (fnp
->type
, type
,
14678 TYPE_TARGET_TYPE (this_type
),
14679 TYPE_FIELDS (this_type
),
14680 TYPE_NFIELDS (this_type
),
14681 TYPE_VARARGS (this_type
));
14683 /* Handle static member functions.
14684 Dwarf2 has no clean way to discern C++ static and non-static
14685 member functions. G++ helps GDB by marking the first
14686 parameter for non-static member functions (which is the this
14687 pointer) as artificial. We obtain this information from
14688 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
14689 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
14690 fnp
->voffset
= VOFFSET_STATIC
;
14693 complaint (_("member function type missing for '%s'"),
14694 dwarf2_full_name (fieldname
, die
, cu
));
14696 /* Get fcontext from DW_AT_containing_type if present. */
14697 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
14698 fnp
->fcontext
= die_containing_type (die
, cu
);
14700 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
14701 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
14703 /* Get accessibility. */
14704 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14705 if (attr
!= nullptr)
14706 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14708 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14709 switch (accessibility
)
14711 case DW_ACCESS_private
:
14712 fnp
->is_private
= 1;
14714 case DW_ACCESS_protected
:
14715 fnp
->is_protected
= 1;
14719 /* Check for artificial methods. */
14720 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
14721 if (attr
&& DW_UNSND (attr
) != 0)
14722 fnp
->is_artificial
= 1;
14724 /* Check for defaulted methods. */
14725 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
14726 if (attr
!= nullptr && is_valid_DW_AT_defaulted (DW_UNSND (attr
)))
14727 fnp
->defaulted
= (enum dwarf_defaulted_attribute
) DW_UNSND (attr
);
14729 /* Check for deleted methods. */
14730 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
14731 if (attr
!= nullptr && DW_UNSND (attr
) != 0)
14732 fnp
->is_deleted
= 1;
14734 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
14736 /* Get index in virtual function table if it is a virtual member
14737 function. For older versions of GCC, this is an offset in the
14738 appropriate virtual table, as specified by DW_AT_containing_type.
14739 For everyone else, it is an expression to be evaluated relative
14740 to the object address. */
14742 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
14743 if (attr
!= nullptr)
14745 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
> 0)
14747 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
14749 /* Old-style GCC. */
14750 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
14752 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
14753 || (DW_BLOCK (attr
)->size
> 1
14754 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
14755 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
14757 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14758 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
14759 dwarf2_complex_location_expr_complaint ();
14761 fnp
->voffset
/= cu
->header
.addr_size
;
14765 dwarf2_complex_location_expr_complaint ();
14767 if (!fnp
->fcontext
)
14769 /* If there is no `this' field and no DW_AT_containing_type,
14770 we cannot actually find a base class context for the
14772 if (TYPE_NFIELDS (this_type
) == 0
14773 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
14775 complaint (_("cannot determine context for virtual member "
14776 "function \"%s\" (offset %s)"),
14777 fieldname
, sect_offset_str (die
->sect_off
));
14782 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
14786 else if (attr
->form_is_section_offset ())
14788 dwarf2_complex_location_expr_complaint ();
14792 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
14798 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14799 if (attr
&& DW_UNSND (attr
))
14801 /* GCC does this, as of 2008-08-25; PR debug/37237. */
14802 complaint (_("Member function \"%s\" (offset %s) is virtual "
14803 "but the vtable offset is not specified"),
14804 fieldname
, sect_offset_str (die
->sect_off
));
14805 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14806 TYPE_CPLUS_DYNAMIC (type
) = 1;
14811 /* Create the vector of member function fields, and attach it to the type. */
14814 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
14815 struct dwarf2_cu
*cu
)
14817 if (cu
->language
== language_ada
)
14818 error (_("unexpected member functions in Ada type"));
14820 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14821 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
14823 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
14825 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
14827 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
14828 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
14830 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
14831 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
14832 fn_flp
->fn_fields
= (struct fn_field
*)
14833 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
14835 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
14836 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
14839 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
14842 /* Returns non-zero if NAME is the name of a vtable member in CU's
14843 language, zero otherwise. */
14845 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
14847 static const char vptr
[] = "_vptr";
14849 /* Look for the C++ form of the vtable. */
14850 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
14856 /* GCC outputs unnamed structures that are really pointers to member
14857 functions, with the ABI-specified layout. If TYPE describes
14858 such a structure, smash it into a member function type.
14860 GCC shouldn't do this; it should just output pointer to member DIEs.
14861 This is GCC PR debug/28767. */
14864 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
14866 struct type
*pfn_type
, *self_type
, *new_type
;
14868 /* Check for a structure with no name and two children. */
14869 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
14872 /* Check for __pfn and __delta members. */
14873 if (TYPE_FIELD_NAME (type
, 0) == NULL
14874 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
14875 || TYPE_FIELD_NAME (type
, 1) == NULL
14876 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
14879 /* Find the type of the method. */
14880 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
14881 if (pfn_type
== NULL
14882 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
14883 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
14886 /* Look for the "this" argument. */
14887 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
14888 if (TYPE_NFIELDS (pfn_type
) == 0
14889 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
14890 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
14893 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
14894 new_type
= alloc_type (objfile
);
14895 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
14896 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
14897 TYPE_VARARGS (pfn_type
));
14898 smash_to_methodptr_type (type
, new_type
);
14901 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
14902 appropriate error checking and issuing complaints if there is a
14906 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
14908 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
14910 if (attr
== nullptr)
14913 if (!attr
->form_is_constant ())
14915 complaint (_("DW_AT_alignment must have constant form"
14916 " - DIE at %s [in module %s]"),
14917 sect_offset_str (die
->sect_off
),
14918 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14923 if (attr
->form
== DW_FORM_sdata
)
14925 LONGEST val
= DW_SND (attr
);
14928 complaint (_("DW_AT_alignment value must not be negative"
14929 " - DIE at %s [in module %s]"),
14930 sect_offset_str (die
->sect_off
),
14931 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14937 align
= DW_UNSND (attr
);
14941 complaint (_("DW_AT_alignment value must not be zero"
14942 " - DIE at %s [in module %s]"),
14943 sect_offset_str (die
->sect_off
),
14944 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14947 if ((align
& (align
- 1)) != 0)
14949 complaint (_("DW_AT_alignment value must be a power of 2"
14950 " - DIE at %s [in module %s]"),
14951 sect_offset_str (die
->sect_off
),
14952 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14959 /* If the DIE has a DW_AT_alignment attribute, use its value to set
14960 the alignment for TYPE. */
14963 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
14966 if (!set_type_align (type
, get_alignment (cu
, die
)))
14967 complaint (_("DW_AT_alignment value too large"
14968 " - DIE at %s [in module %s]"),
14969 sect_offset_str (die
->sect_off
),
14970 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14973 /* Check if the given VALUE is a valid enum dwarf_calling_convention
14974 constant for a type, according to DWARF5 spec, Table 5.5. */
14977 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
14982 case DW_CC_pass_by_reference
:
14983 case DW_CC_pass_by_value
:
14987 complaint (_("unrecognized DW_AT_calling_convention value "
14988 "(%s) for a type"), pulongest (value
));
14993 /* Check if the given VALUE is a valid enum dwarf_calling_convention
14994 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
14995 also according to GNU-specific values (see include/dwarf2.h). */
14998 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
15003 case DW_CC_program
:
15007 case DW_CC_GNU_renesas_sh
:
15008 case DW_CC_GNU_borland_fastcall_i386
:
15009 case DW_CC_GDB_IBM_OpenCL
:
15013 complaint (_("unrecognized DW_AT_calling_convention value "
15014 "(%s) for a subroutine"), pulongest (value
));
15019 /* Called when we find the DIE that starts a structure or union scope
15020 (definition) to create a type for the structure or union. Fill in
15021 the type's name and general properties; the members will not be
15022 processed until process_structure_scope. A symbol table entry for
15023 the type will also not be done until process_structure_scope (assuming
15024 the type has a name).
15026 NOTE: we need to call these functions regardless of whether or not the
15027 DIE has a DW_AT_name attribute, since it might be an anonymous
15028 structure or union. This gets the type entered into our set of
15029 user defined types. */
15031 static struct type
*
15032 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15034 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15036 struct attribute
*attr
;
15039 /* If the definition of this type lives in .debug_types, read that type.
15040 Don't follow DW_AT_specification though, that will take us back up
15041 the chain and we want to go down. */
15042 attr
= die
->attr (DW_AT_signature
);
15043 if (attr
!= nullptr)
15045 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15047 /* The type's CU may not be the same as CU.
15048 Ensure TYPE is recorded with CU in die_type_hash. */
15049 return set_die_type (die
, type
, cu
);
15052 type
= alloc_type (objfile
);
15053 INIT_CPLUS_SPECIFIC (type
);
15055 name
= dwarf2_name (die
, cu
);
15058 if (cu
->language
== language_cplus
15059 || cu
->language
== language_d
15060 || cu
->language
== language_rust
)
15062 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15064 /* dwarf2_full_name might have already finished building the DIE's
15065 type. If so, there is no need to continue. */
15066 if (get_die_type (die
, cu
) != NULL
)
15067 return get_die_type (die
, cu
);
15069 TYPE_NAME (type
) = full_name
;
15073 /* The name is already allocated along with this objfile, so
15074 we don't need to duplicate it for the type. */
15075 TYPE_NAME (type
) = name
;
15079 if (die
->tag
== DW_TAG_structure_type
)
15081 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15083 else if (die
->tag
== DW_TAG_union_type
)
15085 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15087 else if (die
->tag
== DW_TAG_variant_part
)
15089 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15090 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
15094 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15097 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15098 TYPE_DECLARED_CLASS (type
) = 1;
15100 /* Store the calling convention in the type if it's available in
15101 the die. Otherwise the calling convention remains set to
15102 the default value DW_CC_normal. */
15103 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15104 if (attr
!= nullptr
15105 && is_valid_DW_AT_calling_convention_for_type (DW_UNSND (attr
)))
15107 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15108 TYPE_CPLUS_CALLING_CONVENTION (type
)
15109 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
15112 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15113 if (attr
!= nullptr)
15115 if (attr
->form_is_constant ())
15116 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15119 /* For the moment, dynamic type sizes are not supported
15120 by GDB's struct type. The actual size is determined
15121 on-demand when resolving the type of a given object,
15122 so set the type's length to zero for now. Otherwise,
15123 we record an expression as the length, and that expression
15124 could lead to a very large value, which could eventually
15125 lead to us trying to allocate that much memory when creating
15126 a value of that type. */
15127 TYPE_LENGTH (type
) = 0;
15132 TYPE_LENGTH (type
) = 0;
15135 maybe_set_alignment (cu
, die
, type
);
15137 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15139 /* ICC<14 does not output the required DW_AT_declaration on
15140 incomplete types, but gives them a size of zero. */
15141 TYPE_STUB (type
) = 1;
15144 TYPE_STUB_SUPPORTED (type
) = 1;
15146 if (die_is_declaration (die
, cu
))
15147 TYPE_STUB (type
) = 1;
15148 else if (attr
== NULL
&& die
->child
== NULL
15149 && producer_is_realview (cu
->producer
))
15150 /* RealView does not output the required DW_AT_declaration
15151 on incomplete types. */
15152 TYPE_STUB (type
) = 1;
15154 /* We need to add the type field to the die immediately so we don't
15155 infinitely recurse when dealing with pointers to the structure
15156 type within the structure itself. */
15157 set_die_type (die
, type
, cu
);
15159 /* set_die_type should be already done. */
15160 set_descriptive_type (type
, die
, cu
);
15165 /* A helper for process_structure_scope that handles a single member
15169 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15170 struct field_info
*fi
,
15171 std::vector
<struct symbol
*> *template_args
,
15172 struct dwarf2_cu
*cu
)
15174 if (child_die
->tag
== DW_TAG_member
15175 || child_die
->tag
== DW_TAG_variable
15176 || child_die
->tag
== DW_TAG_variant_part
)
15178 /* NOTE: carlton/2002-11-05: A C++ static data member
15179 should be a DW_TAG_member that is a declaration, but
15180 all versions of G++ as of this writing (so through at
15181 least 3.2.1) incorrectly generate DW_TAG_variable
15182 tags for them instead. */
15183 dwarf2_add_field (fi
, child_die
, cu
);
15185 else if (child_die
->tag
== DW_TAG_subprogram
)
15187 /* Rust doesn't have member functions in the C++ sense.
15188 However, it does emit ordinary functions as children
15189 of a struct DIE. */
15190 if (cu
->language
== language_rust
)
15191 read_func_scope (child_die
, cu
);
15194 /* C++ member function. */
15195 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15198 else if (child_die
->tag
== DW_TAG_inheritance
)
15200 /* C++ base class field. */
15201 dwarf2_add_field (fi
, child_die
, cu
);
15203 else if (type_can_define_types (child_die
))
15204 dwarf2_add_type_defn (fi
, child_die
, cu
);
15205 else if (child_die
->tag
== DW_TAG_template_type_param
15206 || child_die
->tag
== DW_TAG_template_value_param
)
15208 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15211 template_args
->push_back (arg
);
15213 else if (child_die
->tag
== DW_TAG_variant
)
15215 /* In a variant we want to get the discriminant and also add a
15216 field for our sole member child. */
15217 struct attribute
*discr
= dwarf2_attr (child_die
, DW_AT_discr_value
, cu
);
15219 for (die_info
*variant_child
= child_die
->child
;
15220 variant_child
!= NULL
;
15221 variant_child
= variant_child
->sibling
)
15223 if (variant_child
->tag
== DW_TAG_member
)
15225 handle_struct_member_die (variant_child
, type
, fi
,
15226 template_args
, cu
);
15227 /* Only handle the one. */
15232 /* We don't handle this but we might as well report it if we see
15234 if (dwarf2_attr (child_die
, DW_AT_discr_list
, cu
) != nullptr)
15235 complaint (_("DW_AT_discr_list is not supported yet"
15236 " - DIE at %s [in module %s]"),
15237 sect_offset_str (child_die
->sect_off
),
15238 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15240 /* The first field was just added, so we can stash the
15241 discriminant there. */
15242 gdb_assert (!fi
->fields
.empty ());
15244 fi
->fields
.back ().variant
.default_branch
= true;
15246 fi
->fields
.back ().variant
.discriminant_value
= DW_UNSND (discr
);
15250 /* Finish creating a structure or union type, including filling in
15251 its members and creating a symbol for it. */
15254 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15256 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15257 struct die_info
*child_die
;
15260 type
= get_die_type (die
, cu
);
15262 type
= read_structure_type (die
, cu
);
15264 /* When reading a DW_TAG_variant_part, we need to notice when we
15265 read the discriminant member, so we can record it later in the
15266 discriminant_info. */
15267 bool is_variant_part
= TYPE_FLAG_DISCRIMINATED_UNION (type
);
15268 sect_offset discr_offset
{};
15269 bool has_template_parameters
= false;
15271 if (is_variant_part
)
15273 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15276 /* Maybe it's a univariant form, an extension we support.
15277 In this case arrange not to check the offset. */
15278 is_variant_part
= false;
15280 else if (discr
->form_is_ref ())
15282 struct dwarf2_cu
*target_cu
= cu
;
15283 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15285 discr_offset
= target_die
->sect_off
;
15289 complaint (_("DW_AT_discr does not have DIE reference form"
15290 " - DIE at %s [in module %s]"),
15291 sect_offset_str (die
->sect_off
),
15292 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15293 is_variant_part
= false;
15297 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15299 struct field_info fi
;
15300 std::vector
<struct symbol
*> template_args
;
15302 child_die
= die
->child
;
15304 while (child_die
&& child_die
->tag
)
15306 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15308 if (is_variant_part
&& discr_offset
== child_die
->sect_off
)
15309 fi
.fields
.back ().variant
.is_discriminant
= true;
15311 child_die
= child_die
->sibling
;
15314 /* Attach template arguments to type. */
15315 if (!template_args
.empty ())
15317 has_template_parameters
= true;
15318 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15319 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15320 TYPE_TEMPLATE_ARGUMENTS (type
)
15321 = XOBNEWVEC (&objfile
->objfile_obstack
,
15323 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15324 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15325 template_args
.data (),
15326 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15327 * sizeof (struct symbol
*)));
15330 /* Attach fields and member functions to the type. */
15331 if (fi
.nfields () > 0)
15332 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15333 if (!fi
.fnfieldlists
.empty ())
15335 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15337 /* Get the type which refers to the base class (possibly this
15338 class itself) which contains the vtable pointer for the current
15339 class from the DW_AT_containing_type attribute. This use of
15340 DW_AT_containing_type is a GNU extension. */
15342 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15344 struct type
*t
= die_containing_type (die
, cu
);
15346 set_type_vptr_basetype (type
, t
);
15351 /* Our own class provides vtbl ptr. */
15352 for (i
= TYPE_NFIELDS (t
) - 1;
15353 i
>= TYPE_N_BASECLASSES (t
);
15356 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
15358 if (is_vtable_name (fieldname
, cu
))
15360 set_type_vptr_fieldno (type
, i
);
15365 /* Complain if virtual function table field not found. */
15366 if (i
< TYPE_N_BASECLASSES (t
))
15367 complaint (_("virtual function table pointer "
15368 "not found when defining class '%s'"),
15369 TYPE_NAME (type
) ? TYPE_NAME (type
) : "");
15373 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
15376 else if (cu
->producer
15377 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
15379 /* The IBM XLC compiler does not provide direct indication
15380 of the containing type, but the vtable pointer is
15381 always named __vfp. */
15385 for (i
= TYPE_NFIELDS (type
) - 1;
15386 i
>= TYPE_N_BASECLASSES (type
);
15389 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
15391 set_type_vptr_fieldno (type
, i
);
15392 set_type_vptr_basetype (type
, type
);
15399 /* Copy fi.typedef_field_list linked list elements content into the
15400 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
15401 if (!fi
.typedef_field_list
.empty ())
15403 int count
= fi
.typedef_field_list
.size ();
15405 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15406 TYPE_TYPEDEF_FIELD_ARRAY (type
)
15407 = ((struct decl_field
*)
15409 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
15410 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
15412 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
15413 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
15416 /* Copy fi.nested_types_list linked list elements content into the
15417 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
15418 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
15420 int count
= fi
.nested_types_list
.size ();
15422 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15423 TYPE_NESTED_TYPES_ARRAY (type
)
15424 = ((struct decl_field
*)
15425 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
15426 TYPE_NESTED_TYPES_COUNT (type
) = count
;
15428 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
15429 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
15433 quirk_gcc_member_function_pointer (type
, objfile
);
15434 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
15435 cu
->rust_unions
.push_back (type
);
15437 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
15438 snapshots) has been known to create a die giving a declaration
15439 for a class that has, as a child, a die giving a definition for a
15440 nested class. So we have to process our children even if the
15441 current die is a declaration. Normally, of course, a declaration
15442 won't have any children at all. */
15444 child_die
= die
->child
;
15446 while (child_die
!= NULL
&& child_die
->tag
)
15448 if (child_die
->tag
== DW_TAG_member
15449 || child_die
->tag
== DW_TAG_variable
15450 || child_die
->tag
== DW_TAG_inheritance
15451 || child_die
->tag
== DW_TAG_template_value_param
15452 || child_die
->tag
== DW_TAG_template_type_param
)
15457 process_die (child_die
, cu
);
15459 child_die
= child_die
->sibling
;
15462 /* Do not consider external references. According to the DWARF standard,
15463 these DIEs are identified by the fact that they have no byte_size
15464 attribute, and a declaration attribute. */
15465 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
15466 || !die_is_declaration (die
, cu
))
15468 struct symbol
*sym
= new_symbol (die
, type
, cu
);
15470 if (has_template_parameters
)
15472 struct symtab
*symtab
;
15473 if (sym
!= nullptr)
15474 symtab
= symbol_symtab (sym
);
15475 else if (cu
->line_header
!= nullptr)
15477 /* Any related symtab will do. */
15479 = cu
->line_header
->file_names ()[0].symtab
;
15484 complaint (_("could not find suitable "
15485 "symtab for template parameter"
15486 " - DIE at %s [in module %s]"),
15487 sect_offset_str (die
->sect_off
),
15488 objfile_name (objfile
));
15491 if (symtab
!= nullptr)
15493 /* Make sure that the symtab is set on the new symbols.
15494 Even though they don't appear in this symtab directly,
15495 other parts of gdb assume that symbols do, and this is
15496 reasonably true. */
15497 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
15498 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
15504 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
15505 update TYPE using some information only available in DIE's children. */
15508 update_enumeration_type_from_children (struct die_info
*die
,
15510 struct dwarf2_cu
*cu
)
15512 struct die_info
*child_die
;
15513 int unsigned_enum
= 1;
15516 auto_obstack obstack
;
15518 for (child_die
= die
->child
;
15519 child_die
!= NULL
&& child_die
->tag
;
15520 child_die
= child_die
->sibling
)
15522 struct attribute
*attr
;
15524 const gdb_byte
*bytes
;
15525 struct dwarf2_locexpr_baton
*baton
;
15528 if (child_die
->tag
!= DW_TAG_enumerator
)
15531 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
15535 name
= dwarf2_name (child_die
, cu
);
15537 name
= "<anonymous enumerator>";
15539 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
15540 &value
, &bytes
, &baton
);
15548 if (count_one_bits_ll (value
) >= 2)
15552 /* If we already know that the enum type is neither unsigned, nor
15553 a flag type, no need to look at the rest of the enumerates. */
15554 if (!unsigned_enum
&& !flag_enum
)
15559 TYPE_UNSIGNED (type
) = 1;
15561 TYPE_FLAG_ENUM (type
) = 1;
15564 /* Given a DW_AT_enumeration_type die, set its type. We do not
15565 complete the type's fields yet, or create any symbols. */
15567 static struct type
*
15568 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15570 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15572 struct attribute
*attr
;
15575 /* If the definition of this type lives in .debug_types, read that type.
15576 Don't follow DW_AT_specification though, that will take us back up
15577 the chain and we want to go down. */
15578 attr
= die
->attr (DW_AT_signature
);
15579 if (attr
!= nullptr)
15581 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15583 /* The type's CU may not be the same as CU.
15584 Ensure TYPE is recorded with CU in die_type_hash. */
15585 return set_die_type (die
, type
, cu
);
15588 type
= alloc_type (objfile
);
15590 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
15591 name
= dwarf2_full_name (NULL
, die
, cu
);
15593 TYPE_NAME (type
) = name
;
15595 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
15598 struct type
*underlying_type
= die_type (die
, cu
);
15600 TYPE_TARGET_TYPE (type
) = underlying_type
;
15603 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15604 if (attr
!= nullptr)
15606 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15610 TYPE_LENGTH (type
) = 0;
15613 maybe_set_alignment (cu
, die
, type
);
15615 /* The enumeration DIE can be incomplete. In Ada, any type can be
15616 declared as private in the package spec, and then defined only
15617 inside the package body. Such types are known as Taft Amendment
15618 Types. When another package uses such a type, an incomplete DIE
15619 may be generated by the compiler. */
15620 if (die_is_declaration (die
, cu
))
15621 TYPE_STUB (type
) = 1;
15623 /* Finish the creation of this type by using the enum's children.
15624 We must call this even when the underlying type has been provided
15625 so that we can determine if we're looking at a "flag" enum. */
15626 update_enumeration_type_from_children (die
, type
, cu
);
15628 /* If this type has an underlying type that is not a stub, then we
15629 may use its attributes. We always use the "unsigned" attribute
15630 in this situation, because ordinarily we guess whether the type
15631 is unsigned -- but the guess can be wrong and the underlying type
15632 can tell us the reality. However, we defer to a local size
15633 attribute if one exists, because this lets the compiler override
15634 the underlying type if needed. */
15635 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
15637 struct type
*underlying_type
= TYPE_TARGET_TYPE (type
);
15638 underlying_type
= check_typedef (underlying_type
);
15639 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (underlying_type
);
15640 if (TYPE_LENGTH (type
) == 0)
15641 TYPE_LENGTH (type
) = TYPE_LENGTH (underlying_type
);
15642 if (TYPE_RAW_ALIGN (type
) == 0
15643 && TYPE_RAW_ALIGN (underlying_type
) != 0)
15644 set_type_align (type
, TYPE_RAW_ALIGN (underlying_type
));
15647 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
15649 return set_die_type (die
, type
, cu
);
15652 /* Given a pointer to a die which begins an enumeration, process all
15653 the dies that define the members of the enumeration, and create the
15654 symbol for the enumeration type.
15656 NOTE: We reverse the order of the element list. */
15659 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15661 struct type
*this_type
;
15663 this_type
= get_die_type (die
, cu
);
15664 if (this_type
== NULL
)
15665 this_type
= read_enumeration_type (die
, cu
);
15667 if (die
->child
!= NULL
)
15669 struct die_info
*child_die
;
15670 struct symbol
*sym
;
15671 std::vector
<struct field
> fields
;
15674 child_die
= die
->child
;
15675 while (child_die
&& child_die
->tag
)
15677 if (child_die
->tag
!= DW_TAG_enumerator
)
15679 process_die (child_die
, cu
);
15683 name
= dwarf2_name (child_die
, cu
);
15686 sym
= new_symbol (child_die
, this_type
, cu
);
15688 fields
.emplace_back ();
15689 struct field
&field
= fields
.back ();
15691 FIELD_NAME (field
) = sym
->linkage_name ();
15692 FIELD_TYPE (field
) = NULL
;
15693 SET_FIELD_ENUMVAL (field
, SYMBOL_VALUE (sym
));
15694 FIELD_BITSIZE (field
) = 0;
15698 child_die
= child_die
->sibling
;
15701 if (!fields
.empty ())
15703 TYPE_NFIELDS (this_type
) = fields
.size ();
15704 TYPE_FIELDS (this_type
) = (struct field
*)
15705 TYPE_ALLOC (this_type
, sizeof (struct field
) * fields
.size ());
15706 memcpy (TYPE_FIELDS (this_type
), fields
.data (),
15707 sizeof (struct field
) * fields
.size ());
15711 /* If we are reading an enum from a .debug_types unit, and the enum
15712 is a declaration, and the enum is not the signatured type in the
15713 unit, then we do not want to add a symbol for it. Adding a
15714 symbol would in some cases obscure the true definition of the
15715 enum, giving users an incomplete type when the definition is
15716 actually available. Note that we do not want to do this for all
15717 enums which are just declarations, because C++0x allows forward
15718 enum declarations. */
15719 if (cu
->per_cu
->is_debug_types
15720 && die_is_declaration (die
, cu
))
15722 struct signatured_type
*sig_type
;
15724 sig_type
= (struct signatured_type
*) cu
->per_cu
;
15725 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
15726 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
15730 new_symbol (die
, this_type
, cu
);
15733 /* Extract all information from a DW_TAG_array_type DIE and put it in
15734 the DIE's type field. For now, this only handles one dimensional
15737 static struct type
*
15738 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15740 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15741 struct die_info
*child_die
;
15743 struct type
*element_type
, *range_type
, *index_type
;
15744 struct attribute
*attr
;
15746 struct dynamic_prop
*byte_stride_prop
= NULL
;
15747 unsigned int bit_stride
= 0;
15749 element_type
= die_type (die
, cu
);
15751 /* The die_type call above may have already set the type for this DIE. */
15752 type
= get_die_type (die
, cu
);
15756 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
15760 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
15763 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
15764 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
15768 complaint (_("unable to read array DW_AT_byte_stride "
15769 " - DIE at %s [in module %s]"),
15770 sect_offset_str (die
->sect_off
),
15771 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15772 /* Ignore this attribute. We will likely not be able to print
15773 arrays of this type correctly, but there is little we can do
15774 to help if we cannot read the attribute's value. */
15775 byte_stride_prop
= NULL
;
15779 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
15781 bit_stride
= DW_UNSND (attr
);
15783 /* Irix 6.2 native cc creates array types without children for
15784 arrays with unspecified length. */
15785 if (die
->child
== NULL
)
15787 index_type
= objfile_type (objfile
)->builtin_int
;
15788 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
15789 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
15790 byte_stride_prop
, bit_stride
);
15791 return set_die_type (die
, type
, cu
);
15794 std::vector
<struct type
*> range_types
;
15795 child_die
= die
->child
;
15796 while (child_die
&& child_die
->tag
)
15798 if (child_die
->tag
== DW_TAG_subrange_type
)
15800 struct type
*child_type
= read_type_die (child_die
, cu
);
15802 if (child_type
!= NULL
)
15804 /* The range type was succesfully read. Save it for the
15805 array type creation. */
15806 range_types
.push_back (child_type
);
15809 child_die
= child_die
->sibling
;
15812 /* Dwarf2 dimensions are output from left to right, create the
15813 necessary array types in backwards order. */
15815 type
= element_type
;
15817 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
15821 while (i
< range_types
.size ())
15822 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
15823 byte_stride_prop
, bit_stride
);
15827 size_t ndim
= range_types
.size ();
15829 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
15830 byte_stride_prop
, bit_stride
);
15833 /* Understand Dwarf2 support for vector types (like they occur on
15834 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
15835 array type. This is not part of the Dwarf2/3 standard yet, but a
15836 custom vendor extension. The main difference between a regular
15837 array and the vector variant is that vectors are passed by value
15839 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
15840 if (attr
!= nullptr)
15841 make_vector_type (type
);
15843 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
15844 implementation may choose to implement triple vectors using this
15846 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15847 if (attr
!= nullptr)
15849 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
15850 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15852 complaint (_("DW_AT_byte_size for array type smaller "
15853 "than the total size of elements"));
15856 name
= dwarf2_name (die
, cu
);
15858 TYPE_NAME (type
) = name
;
15860 maybe_set_alignment (cu
, die
, type
);
15862 /* Install the type in the die. */
15863 set_die_type (die
, type
, cu
);
15865 /* set_die_type should be already done. */
15866 set_descriptive_type (type
, die
, cu
);
15871 static enum dwarf_array_dim_ordering
15872 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
15874 struct attribute
*attr
;
15876 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
15878 if (attr
!= nullptr)
15879 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
15881 /* GNU F77 is a special case, as at 08/2004 array type info is the
15882 opposite order to the dwarf2 specification, but data is still
15883 laid out as per normal fortran.
15885 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
15886 version checking. */
15888 if (cu
->language
== language_fortran
15889 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
15891 return DW_ORD_row_major
;
15894 switch (cu
->language_defn
->la_array_ordering
)
15896 case array_column_major
:
15897 return DW_ORD_col_major
;
15898 case array_row_major
:
15900 return DW_ORD_row_major
;
15904 /* Extract all information from a DW_TAG_set_type DIE and put it in
15905 the DIE's type field. */
15907 static struct type
*
15908 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15910 struct type
*domain_type
, *set_type
;
15911 struct attribute
*attr
;
15913 domain_type
= die_type (die
, cu
);
15915 /* The die_type call above may have already set the type for this DIE. */
15916 set_type
= get_die_type (die
, cu
);
15920 set_type
= create_set_type (NULL
, domain_type
);
15922 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15923 if (attr
!= nullptr)
15924 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
15926 maybe_set_alignment (cu
, die
, set_type
);
15928 return set_die_type (die
, set_type
, cu
);
15931 /* A helper for read_common_block that creates a locexpr baton.
15932 SYM is the symbol which we are marking as computed.
15933 COMMON_DIE is the DIE for the common block.
15934 COMMON_LOC is the location expression attribute for the common
15936 MEMBER_LOC is the location expression attribute for the particular
15937 member of the common block that we are processing.
15938 CU is the CU from which the above come. */
15941 mark_common_block_symbol_computed (struct symbol
*sym
,
15942 struct die_info
*common_die
,
15943 struct attribute
*common_loc
,
15944 struct attribute
*member_loc
,
15945 struct dwarf2_cu
*cu
)
15947 struct dwarf2_per_objfile
*dwarf2_per_objfile
15948 = cu
->per_cu
->dwarf2_per_objfile
;
15949 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
15950 struct dwarf2_locexpr_baton
*baton
;
15952 unsigned int cu_off
;
15953 enum bfd_endian byte_order
= gdbarch_byte_order (objfile
->arch ());
15954 LONGEST offset
= 0;
15956 gdb_assert (common_loc
&& member_loc
);
15957 gdb_assert (common_loc
->form_is_block ());
15958 gdb_assert (member_loc
->form_is_block ()
15959 || member_loc
->form_is_constant ());
15961 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
15962 baton
->per_cu
= cu
->per_cu
;
15963 gdb_assert (baton
->per_cu
);
15965 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
15967 if (member_loc
->form_is_constant ())
15969 offset
= member_loc
->constant_value (0);
15970 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
15973 baton
->size
+= DW_BLOCK (member_loc
)->size
;
15975 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
15978 *ptr
++ = DW_OP_call4
;
15979 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
15980 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
15983 if (member_loc
->form_is_constant ())
15985 *ptr
++ = DW_OP_addr
;
15986 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
15987 ptr
+= cu
->header
.addr_size
;
15991 /* We have to copy the data here, because DW_OP_call4 will only
15992 use a DW_AT_location attribute. */
15993 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
15994 ptr
+= DW_BLOCK (member_loc
)->size
;
15997 *ptr
++ = DW_OP_plus
;
15998 gdb_assert (ptr
- baton
->data
== baton
->size
);
16000 SYMBOL_LOCATION_BATON (sym
) = baton
;
16001 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16004 /* Create appropriate locally-scoped variables for all the
16005 DW_TAG_common_block entries. Also create a struct common_block
16006 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16007 is used to separate the common blocks name namespace from regular
16011 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16013 struct attribute
*attr
;
16015 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16016 if (attr
!= nullptr)
16018 /* Support the .debug_loc offsets. */
16019 if (attr
->form_is_block ())
16023 else if (attr
->form_is_section_offset ())
16025 dwarf2_complex_location_expr_complaint ();
16030 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16031 "common block member");
16036 if (die
->child
!= NULL
)
16038 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16039 struct die_info
*child_die
;
16040 size_t n_entries
= 0, size
;
16041 struct common_block
*common_block
;
16042 struct symbol
*sym
;
16044 for (child_die
= die
->child
;
16045 child_die
&& child_die
->tag
;
16046 child_die
= child_die
->sibling
)
16049 size
= (sizeof (struct common_block
)
16050 + (n_entries
- 1) * sizeof (struct symbol
*));
16052 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16054 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16055 common_block
->n_entries
= 0;
16057 for (child_die
= die
->child
;
16058 child_die
&& child_die
->tag
;
16059 child_die
= child_die
->sibling
)
16061 /* Create the symbol in the DW_TAG_common_block block in the current
16063 sym
= new_symbol (child_die
, NULL
, cu
);
16066 struct attribute
*member_loc
;
16068 common_block
->contents
[common_block
->n_entries
++] = sym
;
16070 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16074 /* GDB has handled this for a long time, but it is
16075 not specified by DWARF. It seems to have been
16076 emitted by gfortran at least as recently as:
16077 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16078 complaint (_("Variable in common block has "
16079 "DW_AT_data_member_location "
16080 "- DIE at %s [in module %s]"),
16081 sect_offset_str (child_die
->sect_off
),
16082 objfile_name (objfile
));
16084 if (member_loc
->form_is_section_offset ())
16085 dwarf2_complex_location_expr_complaint ();
16086 else if (member_loc
->form_is_constant ()
16087 || member_loc
->form_is_block ())
16089 if (attr
!= nullptr)
16090 mark_common_block_symbol_computed (sym
, die
, attr
,
16094 dwarf2_complex_location_expr_complaint ();
16099 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16100 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16104 /* Create a type for a C++ namespace. */
16106 static struct type
*
16107 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16109 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16110 const char *previous_prefix
, *name
;
16114 /* For extensions, reuse the type of the original namespace. */
16115 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16117 struct die_info
*ext_die
;
16118 struct dwarf2_cu
*ext_cu
= cu
;
16120 ext_die
= dwarf2_extension (die
, &ext_cu
);
16121 type
= read_type_die (ext_die
, ext_cu
);
16123 /* EXT_CU may not be the same as CU.
16124 Ensure TYPE is recorded with CU in die_type_hash. */
16125 return set_die_type (die
, type
, cu
);
16128 name
= namespace_name (die
, &is_anonymous
, cu
);
16130 /* Now build the name of the current namespace. */
16132 previous_prefix
= determine_prefix (die
, cu
);
16133 if (previous_prefix
[0] != '\0')
16134 name
= typename_concat (&objfile
->objfile_obstack
,
16135 previous_prefix
, name
, 0, cu
);
16137 /* Create the type. */
16138 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16140 return set_die_type (die
, type
, cu
);
16143 /* Read a namespace scope. */
16146 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16148 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16151 /* Add a symbol associated to this if we haven't seen the namespace
16152 before. Also, add a using directive if it's an anonymous
16155 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16159 type
= read_type_die (die
, cu
);
16160 new_symbol (die
, type
, cu
);
16162 namespace_name (die
, &is_anonymous
, cu
);
16165 const char *previous_prefix
= determine_prefix (die
, cu
);
16167 std::vector
<const char *> excludes
;
16168 add_using_directive (using_directives (cu
),
16169 previous_prefix
, TYPE_NAME (type
), NULL
,
16170 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16174 if (die
->child
!= NULL
)
16176 struct die_info
*child_die
= die
->child
;
16178 while (child_die
&& child_die
->tag
)
16180 process_die (child_die
, cu
);
16181 child_die
= child_die
->sibling
;
16186 /* Read a Fortran module as type. This DIE can be only a declaration used for
16187 imported module. Still we need that type as local Fortran "use ... only"
16188 declaration imports depend on the created type in determine_prefix. */
16190 static struct type
*
16191 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16193 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16194 const char *module_name
;
16197 module_name
= dwarf2_name (die
, cu
);
16198 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16200 return set_die_type (die
, type
, cu
);
16203 /* Read a Fortran module. */
16206 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16208 struct die_info
*child_die
= die
->child
;
16211 type
= read_type_die (die
, cu
);
16212 new_symbol (die
, type
, cu
);
16214 while (child_die
&& child_die
->tag
)
16216 process_die (child_die
, cu
);
16217 child_die
= child_die
->sibling
;
16221 /* Return the name of the namespace represented by DIE. Set
16222 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16225 static const char *
16226 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16228 struct die_info
*current_die
;
16229 const char *name
= NULL
;
16231 /* Loop through the extensions until we find a name. */
16233 for (current_die
= die
;
16234 current_die
!= NULL
;
16235 current_die
= dwarf2_extension (die
, &cu
))
16237 /* We don't use dwarf2_name here so that we can detect the absence
16238 of a name -> anonymous namespace. */
16239 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16245 /* Is it an anonymous namespace? */
16247 *is_anonymous
= (name
== NULL
);
16249 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16254 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16255 the user defined type vector. */
16257 static struct type
*
16258 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16260 struct gdbarch
*gdbarch
16261 = cu
->per_cu
->dwarf2_per_objfile
->objfile
->arch ();
16262 struct comp_unit_head
*cu_header
= &cu
->header
;
16264 struct attribute
*attr_byte_size
;
16265 struct attribute
*attr_address_class
;
16266 int byte_size
, addr_class
;
16267 struct type
*target_type
;
16269 target_type
= die_type (die
, cu
);
16271 /* The die_type call above may have already set the type for this DIE. */
16272 type
= get_die_type (die
, cu
);
16276 type
= lookup_pointer_type (target_type
);
16278 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16279 if (attr_byte_size
)
16280 byte_size
= DW_UNSND (attr_byte_size
);
16282 byte_size
= cu_header
->addr_size
;
16284 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
16285 if (attr_address_class
)
16286 addr_class
= DW_UNSND (attr_address_class
);
16288 addr_class
= DW_ADDR_none
;
16290 ULONGEST alignment
= get_alignment (cu
, die
);
16292 /* If the pointer size, alignment, or address class is different
16293 than the default, create a type variant marked as such and set
16294 the length accordingly. */
16295 if (TYPE_LENGTH (type
) != byte_size
16296 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
16297 && alignment
!= TYPE_RAW_ALIGN (type
))
16298 || addr_class
!= DW_ADDR_none
)
16300 if (gdbarch_address_class_type_flags_p (gdbarch
))
16304 type_flags
= gdbarch_address_class_type_flags
16305 (gdbarch
, byte_size
, addr_class
);
16306 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
16308 type
= make_type_with_address_space (type
, type_flags
);
16310 else if (TYPE_LENGTH (type
) != byte_size
)
16312 complaint (_("invalid pointer size %d"), byte_size
);
16314 else if (TYPE_RAW_ALIGN (type
) != alignment
)
16316 complaint (_("Invalid DW_AT_alignment"
16317 " - DIE at %s [in module %s]"),
16318 sect_offset_str (die
->sect_off
),
16319 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16323 /* Should we also complain about unhandled address classes? */
16327 TYPE_LENGTH (type
) = byte_size
;
16328 set_type_align (type
, alignment
);
16329 return set_die_type (die
, type
, cu
);
16332 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
16333 the user defined type vector. */
16335 static struct type
*
16336 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16339 struct type
*to_type
;
16340 struct type
*domain
;
16342 to_type
= die_type (die
, cu
);
16343 domain
= die_containing_type (die
, cu
);
16345 /* The calls above may have already set the type for this DIE. */
16346 type
= get_die_type (die
, cu
);
16350 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
16351 type
= lookup_methodptr_type (to_type
);
16352 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
16354 struct type
*new_type
16355 = alloc_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16357 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
16358 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
16359 TYPE_VARARGS (to_type
));
16360 type
= lookup_methodptr_type (new_type
);
16363 type
= lookup_memberptr_type (to_type
, domain
);
16365 return set_die_type (die
, type
, cu
);
16368 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
16369 the user defined type vector. */
16371 static struct type
*
16372 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16373 enum type_code refcode
)
16375 struct comp_unit_head
*cu_header
= &cu
->header
;
16376 struct type
*type
, *target_type
;
16377 struct attribute
*attr
;
16379 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
16381 target_type
= die_type (die
, cu
);
16383 /* The die_type call above may have already set the type for this DIE. */
16384 type
= get_die_type (die
, cu
);
16388 type
= lookup_reference_type (target_type
, refcode
);
16389 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16390 if (attr
!= nullptr)
16392 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16396 TYPE_LENGTH (type
) = cu_header
->addr_size
;
16398 maybe_set_alignment (cu
, die
, type
);
16399 return set_die_type (die
, type
, cu
);
16402 /* Add the given cv-qualifiers to the element type of the array. GCC
16403 outputs DWARF type qualifiers that apply to an array, not the
16404 element type. But GDB relies on the array element type to carry
16405 the cv-qualifiers. This mimics section 6.7.3 of the C99
16408 static struct type
*
16409 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16410 struct type
*base_type
, int cnst
, int voltl
)
16412 struct type
*el_type
, *inner_array
;
16414 base_type
= copy_type (base_type
);
16415 inner_array
= base_type
;
16417 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
16419 TYPE_TARGET_TYPE (inner_array
) =
16420 copy_type (TYPE_TARGET_TYPE (inner_array
));
16421 inner_array
= TYPE_TARGET_TYPE (inner_array
);
16424 el_type
= TYPE_TARGET_TYPE (inner_array
);
16425 cnst
|= TYPE_CONST (el_type
);
16426 voltl
|= TYPE_VOLATILE (el_type
);
16427 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
16429 return set_die_type (die
, base_type
, cu
);
16432 static struct type
*
16433 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16435 struct type
*base_type
, *cv_type
;
16437 base_type
= die_type (die
, cu
);
16439 /* The die_type call above may have already set the type for this DIE. */
16440 cv_type
= get_die_type (die
, cu
);
16444 /* In case the const qualifier is applied to an array type, the element type
16445 is so qualified, not the array type (section 6.7.3 of C99). */
16446 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
16447 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
16449 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
16450 return set_die_type (die
, cv_type
, cu
);
16453 static struct type
*
16454 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16456 struct type
*base_type
, *cv_type
;
16458 base_type
= die_type (die
, cu
);
16460 /* The die_type call above may have already set the type for this DIE. */
16461 cv_type
= get_die_type (die
, cu
);
16465 /* In case the volatile qualifier is applied to an array type, the
16466 element type is so qualified, not the array type (section 6.7.3
16468 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
16469 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
16471 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
16472 return set_die_type (die
, cv_type
, cu
);
16475 /* Handle DW_TAG_restrict_type. */
16477 static struct type
*
16478 read_tag_restrict_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_restrict_type (base_type
);
16490 return set_die_type (die
, cv_type
, cu
);
16493 /* Handle DW_TAG_atomic_type. */
16495 static struct type
*
16496 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16498 struct type
*base_type
, *cv_type
;
16500 base_type
= die_type (die
, cu
);
16502 /* The die_type call above may have already set the type for this DIE. */
16503 cv_type
= get_die_type (die
, cu
);
16507 cv_type
= make_atomic_type (base_type
);
16508 return set_die_type (die
, cv_type
, cu
);
16511 /* Extract all information from a DW_TAG_string_type DIE and add to
16512 the user defined type vector. It isn't really a user defined type,
16513 but it behaves like one, with other DIE's using an AT_user_def_type
16514 attribute to reference it. */
16516 static struct type
*
16517 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16519 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16520 struct gdbarch
*gdbarch
= objfile
->arch ();
16521 struct type
*type
, *range_type
, *index_type
, *char_type
;
16522 struct attribute
*attr
;
16523 struct dynamic_prop prop
;
16524 bool length_is_constant
= true;
16527 /* There are a couple of places where bit sizes might be made use of
16528 when parsing a DW_TAG_string_type, however, no producer that we know
16529 of make use of these. Handling bit sizes that are a multiple of the
16530 byte size is easy enough, but what about other bit sizes? Lets deal
16531 with that problem when we have to. Warn about these attributes being
16532 unsupported, then parse the type and ignore them like we always
16534 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
16535 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
16537 static bool warning_printed
= false;
16538 if (!warning_printed
)
16540 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
16541 "currently supported on DW_TAG_string_type."));
16542 warning_printed
= true;
16546 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
16547 if (attr
!= nullptr && !attr
->form_is_constant ())
16549 /* The string length describes the location at which the length of
16550 the string can be found. The size of the length field can be
16551 specified with one of the attributes below. */
16552 struct type
*prop_type
;
16553 struct attribute
*len
16554 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
16555 if (len
== nullptr)
16556 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16557 if (len
!= nullptr && len
->form_is_constant ())
16559 /* Pass 0 as the default as we know this attribute is constant
16560 and the default value will not be returned. */
16561 LONGEST sz
= len
->constant_value (0);
16562 prop_type
= cu
->per_cu
->int_type (sz
, true);
16566 /* If the size is not specified then we assume it is the size of
16567 an address on this target. */
16568 prop_type
= cu
->per_cu
->addr_sized_int_type (true);
16571 /* Convert the attribute into a dynamic property. */
16572 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
16575 length_is_constant
= false;
16577 else if (attr
!= nullptr)
16579 /* This DW_AT_string_length just contains the length with no
16580 indirection. There's no need to create a dynamic property in this
16581 case. Pass 0 for the default value as we know it will not be
16582 returned in this case. */
16583 length
= attr
->constant_value (0);
16585 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
16587 /* We don't currently support non-constant byte sizes for strings. */
16588 length
= attr
->constant_value (1);
16592 /* Use 1 as a fallback length if we have nothing else. */
16596 index_type
= objfile_type (objfile
)->builtin_int
;
16597 if (length_is_constant
)
16598 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
16601 struct dynamic_prop low_bound
;
16603 low_bound
.kind
= PROP_CONST
;
16604 low_bound
.data
.const_val
= 1;
16605 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
16607 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
16608 type
= create_string_type (NULL
, char_type
, range_type
);
16610 return set_die_type (die
, type
, cu
);
16613 /* Assuming that DIE corresponds to a function, returns nonzero
16614 if the function is prototyped. */
16617 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
16619 struct attribute
*attr
;
16621 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
16622 if (attr
&& (DW_UNSND (attr
) != 0))
16625 /* The DWARF standard implies that the DW_AT_prototyped attribute
16626 is only meaningful for C, but the concept also extends to other
16627 languages that allow unprototyped functions (Eg: Objective C).
16628 For all other languages, assume that functions are always
16630 if (cu
->language
!= language_c
16631 && cu
->language
!= language_objc
16632 && cu
->language
!= language_opencl
)
16635 /* RealView does not emit DW_AT_prototyped. We can not distinguish
16636 prototyped and unprototyped functions; default to prototyped,
16637 since that is more common in modern code (and RealView warns
16638 about unprototyped functions). */
16639 if (producer_is_realview (cu
->producer
))
16645 /* Handle DIES due to C code like:
16649 int (*funcp)(int a, long l);
16653 ('funcp' generates a DW_TAG_subroutine_type DIE). */
16655 static struct type
*
16656 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16658 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16659 struct type
*type
; /* Type that this function returns. */
16660 struct type
*ftype
; /* Function that returns above type. */
16661 struct attribute
*attr
;
16663 type
= die_type (die
, cu
);
16665 /* The die_type call above may have already set the type for this DIE. */
16666 ftype
= get_die_type (die
, cu
);
16670 ftype
= lookup_function_type (type
);
16672 if (prototyped_function_p (die
, cu
))
16673 TYPE_PROTOTYPED (ftype
) = 1;
16675 /* Store the calling convention in the type if it's available in
16676 the subroutine die. Otherwise set the calling convention to
16677 the default value DW_CC_normal. */
16678 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
16679 if (attr
!= nullptr
16680 && is_valid_DW_AT_calling_convention_for_subroutine (DW_UNSND (attr
)))
16681 TYPE_CALLING_CONVENTION (ftype
)
16682 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
16683 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
16684 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
16686 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
16688 /* Record whether the function returns normally to its caller or not
16689 if the DWARF producer set that information. */
16690 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
16691 if (attr
&& (DW_UNSND (attr
) != 0))
16692 TYPE_NO_RETURN (ftype
) = 1;
16694 /* We need to add the subroutine type to the die immediately so
16695 we don't infinitely recurse when dealing with parameters
16696 declared as the same subroutine type. */
16697 set_die_type (die
, ftype
, cu
);
16699 if (die
->child
!= NULL
)
16701 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
16702 struct die_info
*child_die
;
16703 int nparams
, iparams
;
16705 /* Count the number of parameters.
16706 FIXME: GDB currently ignores vararg functions, but knows about
16707 vararg member functions. */
16709 child_die
= die
->child
;
16710 while (child_die
&& child_die
->tag
)
16712 if (child_die
->tag
== DW_TAG_formal_parameter
)
16714 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
16715 TYPE_VARARGS (ftype
) = 1;
16716 child_die
= child_die
->sibling
;
16719 /* Allocate storage for parameters and fill them in. */
16720 TYPE_NFIELDS (ftype
) = nparams
;
16721 TYPE_FIELDS (ftype
) = (struct field
*)
16722 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
16724 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
16725 even if we error out during the parameters reading below. */
16726 for (iparams
= 0; iparams
< nparams
; iparams
++)
16727 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
16730 child_die
= die
->child
;
16731 while (child_die
&& child_die
->tag
)
16733 if (child_die
->tag
== DW_TAG_formal_parameter
)
16735 struct type
*arg_type
;
16737 /* DWARF version 2 has no clean way to discern C++
16738 static and non-static member functions. G++ helps
16739 GDB by marking the first parameter for non-static
16740 member functions (which is the this pointer) as
16741 artificial. We pass this information to
16742 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
16744 DWARF version 3 added DW_AT_object_pointer, which GCC
16745 4.5 does not yet generate. */
16746 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
16747 if (attr
!= nullptr)
16748 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
16750 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
16751 arg_type
= die_type (child_die
, cu
);
16753 /* RealView does not mark THIS as const, which the testsuite
16754 expects. GCC marks THIS as const in method definitions,
16755 but not in the class specifications (GCC PR 43053). */
16756 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
16757 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
16760 struct dwarf2_cu
*arg_cu
= cu
;
16761 const char *name
= dwarf2_name (child_die
, cu
);
16763 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
16764 if (attr
!= nullptr)
16766 /* If the compiler emits this, use it. */
16767 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
16770 else if (name
&& strcmp (name
, "this") == 0)
16771 /* Function definitions will have the argument names. */
16773 else if (name
== NULL
&& iparams
== 0)
16774 /* Declarations may not have the names, so like
16775 elsewhere in GDB, assume an artificial first
16776 argument is "this". */
16780 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
16784 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
16787 child_die
= child_die
->sibling
;
16794 static struct type
*
16795 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
16797 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16798 const char *name
= NULL
;
16799 struct type
*this_type
, *target_type
;
16801 name
= dwarf2_full_name (NULL
, die
, cu
);
16802 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
16803 TYPE_TARGET_STUB (this_type
) = 1;
16804 set_die_type (die
, this_type
, cu
);
16805 target_type
= die_type (die
, cu
);
16806 if (target_type
!= this_type
)
16807 TYPE_TARGET_TYPE (this_type
) = target_type
;
16810 /* Self-referential typedefs are, it seems, not allowed by the DWARF
16811 spec and cause infinite loops in GDB. */
16812 complaint (_("Self-referential DW_TAG_typedef "
16813 "- DIE at %s [in module %s]"),
16814 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
16815 TYPE_TARGET_TYPE (this_type
) = NULL
;
16819 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
16820 anonymous typedefs, which is, strictly speaking, invalid DWARF.
16821 Handle these by just returning the target type, rather than
16822 constructing an anonymous typedef type and trying to handle this
16824 set_die_type (die
, target_type
, cu
);
16825 return target_type
;
16830 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
16831 (which may be different from NAME) to the architecture back-end to allow
16832 it to guess the correct format if necessary. */
16834 static struct type
*
16835 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
16836 const char *name_hint
, enum bfd_endian byte_order
)
16838 struct gdbarch
*gdbarch
= objfile
->arch ();
16839 const struct floatformat
**format
;
16842 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
16844 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
16846 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
16851 /* Allocate an integer type of size BITS and name NAME. */
16853 static struct type
*
16854 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
16855 int bits
, int unsigned_p
, const char *name
)
16859 /* Versions of Intel's C Compiler generate an integer type called "void"
16860 instead of using DW_TAG_unspecified_type. This has been seen on
16861 at least versions 14, 17, and 18. */
16862 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
16863 && strcmp (name
, "void") == 0)
16864 type
= objfile_type (objfile
)->builtin_void
;
16866 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
16871 /* Initialise and return a floating point type of size BITS suitable for
16872 use as a component of a complex number. The NAME_HINT is passed through
16873 when initialising the floating point type and is the name of the complex
16876 As DWARF doesn't currently provide an explicit name for the components
16877 of a complex number, but it can be helpful to have these components
16878 named, we try to select a suitable name based on the size of the
16880 static struct type
*
16881 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
16882 struct objfile
*objfile
,
16883 int bits
, const char *name_hint
,
16884 enum bfd_endian byte_order
)
16886 gdbarch
*gdbarch
= objfile
->arch ();
16887 struct type
*tt
= nullptr;
16889 /* Try to find a suitable floating point builtin type of size BITS.
16890 We're going to use the name of this type as the name for the complex
16891 target type that we are about to create. */
16892 switch (cu
->language
)
16894 case language_fortran
:
16898 tt
= builtin_f_type (gdbarch
)->builtin_real
;
16901 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
16903 case 96: /* The x86-32 ABI specifies 96-bit long double. */
16905 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
16913 tt
= builtin_type (gdbarch
)->builtin_float
;
16916 tt
= builtin_type (gdbarch
)->builtin_double
;
16918 case 96: /* The x86-32 ABI specifies 96-bit long double. */
16920 tt
= builtin_type (gdbarch
)->builtin_long_double
;
16926 /* If the type we found doesn't match the size we were looking for, then
16927 pretend we didn't find a type at all, the complex target type we
16928 create will then be nameless. */
16929 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
16932 const char *name
= (tt
== nullptr) ? nullptr : TYPE_NAME (tt
);
16933 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
16936 /* Find a representation of a given base type and install
16937 it in the TYPE field of the die. */
16939 static struct type
*
16940 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16942 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16944 struct attribute
*attr
;
16945 int encoding
= 0, bits
= 0;
16949 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
16950 if (attr
!= nullptr)
16951 encoding
= DW_UNSND (attr
);
16952 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16953 if (attr
!= nullptr)
16954 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
16955 name
= dwarf2_name (die
, cu
);
16957 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
16959 arch
= objfile
->arch ();
16960 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
16962 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
16965 int endianity
= DW_UNSND (attr
);
16970 byte_order
= BFD_ENDIAN_BIG
;
16972 case DW_END_little
:
16973 byte_order
= BFD_ENDIAN_LITTLE
;
16976 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
16983 case DW_ATE_address
:
16984 /* Turn DW_ATE_address into a void * pointer. */
16985 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
16986 type
= init_pointer_type (objfile
, bits
, name
, type
);
16988 case DW_ATE_boolean
:
16989 type
= init_boolean_type (objfile
, bits
, 1, name
);
16991 case DW_ATE_complex_float
:
16992 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
16994 if (TYPE_CODE (type
) == TYPE_CODE_ERROR
)
16996 if (name
== nullptr)
16998 struct obstack
*obstack
16999 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
17000 name
= obconcat (obstack
, "_Complex ", TYPE_NAME (type
),
17003 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17006 type
= init_complex_type (name
, type
);
17008 case DW_ATE_decimal_float
:
17009 type
= init_decfloat_type (objfile
, bits
, name
);
17012 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
17014 case DW_ATE_signed
:
17015 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17017 case DW_ATE_unsigned
:
17018 if (cu
->language
== language_fortran
17020 && startswith (name
, "character("))
17021 type
= init_character_type (objfile
, bits
, 1, name
);
17023 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17025 case DW_ATE_signed_char
:
17026 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17027 || cu
->language
== language_pascal
17028 || cu
->language
== language_fortran
)
17029 type
= init_character_type (objfile
, bits
, 0, name
);
17031 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17033 case DW_ATE_unsigned_char
:
17034 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17035 || cu
->language
== language_pascal
17036 || cu
->language
== language_fortran
17037 || cu
->language
== language_rust
)
17038 type
= init_character_type (objfile
, bits
, 1, name
);
17040 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17045 type
= builtin_type (arch
)->builtin_char16
;
17046 else if (bits
== 32)
17047 type
= builtin_type (arch
)->builtin_char32
;
17050 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
17052 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17054 return set_die_type (die
, type
, cu
);
17059 complaint (_("unsupported DW_AT_encoding: '%s'"),
17060 dwarf_type_encoding_name (encoding
));
17061 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17065 if (name
&& strcmp (name
, "char") == 0)
17066 TYPE_NOSIGN (type
) = 1;
17068 maybe_set_alignment (cu
, die
, type
);
17070 TYPE_ENDIANITY_NOT_DEFAULT (type
) = gdbarch_byte_order (arch
) != byte_order
;
17072 return set_die_type (die
, type
, cu
);
17075 /* Parse dwarf attribute if it's a block, reference or constant and put the
17076 resulting value of the attribute into struct bound_prop.
17077 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17080 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17081 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
17082 struct type
*default_type
)
17084 struct dwarf2_property_baton
*baton
;
17085 struct obstack
*obstack
17086 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
17088 gdb_assert (default_type
!= NULL
);
17090 if (attr
== NULL
|| prop
== NULL
)
17093 if (attr
->form_is_block ())
17095 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17096 baton
->property_type
= default_type
;
17097 baton
->locexpr
.per_cu
= cu
->per_cu
;
17098 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17099 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17100 switch (attr
->name
)
17102 case DW_AT_string_length
:
17103 baton
->locexpr
.is_reference
= true;
17106 baton
->locexpr
.is_reference
= false;
17109 prop
->data
.baton
= baton
;
17110 prop
->kind
= PROP_LOCEXPR
;
17111 gdb_assert (prop
->data
.baton
!= NULL
);
17113 else if (attr
->form_is_ref ())
17115 struct dwarf2_cu
*target_cu
= cu
;
17116 struct die_info
*target_die
;
17117 struct attribute
*target_attr
;
17119 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17120 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17121 if (target_attr
== NULL
)
17122 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17124 if (target_attr
== NULL
)
17127 switch (target_attr
->name
)
17129 case DW_AT_location
:
17130 if (target_attr
->form_is_section_offset ())
17132 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17133 baton
->property_type
= die_type (target_die
, target_cu
);
17134 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17135 prop
->data
.baton
= baton
;
17136 prop
->kind
= PROP_LOCLIST
;
17137 gdb_assert (prop
->data
.baton
!= NULL
);
17139 else if (target_attr
->form_is_block ())
17141 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17142 baton
->property_type
= die_type (target_die
, target_cu
);
17143 baton
->locexpr
.per_cu
= cu
->per_cu
;
17144 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17145 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17146 baton
->locexpr
.is_reference
= true;
17147 prop
->data
.baton
= baton
;
17148 prop
->kind
= PROP_LOCEXPR
;
17149 gdb_assert (prop
->data
.baton
!= NULL
);
17153 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17154 "dynamic property");
17158 case DW_AT_data_member_location
:
17162 if (!handle_data_member_location (target_die
, target_cu
,
17166 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17167 baton
->property_type
= read_type_die (target_die
->parent
,
17169 baton
->offset_info
.offset
= offset
;
17170 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17171 prop
->data
.baton
= baton
;
17172 prop
->kind
= PROP_ADDR_OFFSET
;
17177 else if (attr
->form_is_constant ())
17179 prop
->data
.const_val
= attr
->constant_value (0);
17180 prop
->kind
= PROP_CONST
;
17184 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17185 dwarf2_name (die
, cu
));
17195 dwarf2_per_cu_data::int_type (int size_in_bytes
, bool unsigned_p
) const
17197 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17198 struct type
*int_type
;
17200 /* Helper macro to examine the various builtin types. */
17201 #define TRY_TYPE(F) \
17202 int_type = (unsigned_p \
17203 ? objfile_type (objfile)->builtin_unsigned_ ## F \
17204 : objfile_type (objfile)->builtin_ ## F); \
17205 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
17212 TRY_TYPE (long_long
);
17216 gdb_assert_not_reached ("unable to find suitable integer type");
17222 dwarf2_per_cu_data::addr_sized_int_type (bool unsigned_p
) const
17224 int addr_size
= this->addr_size ();
17225 return int_type (addr_size
, unsigned_p
);
17228 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
17229 present (which is valid) then compute the default type based on the
17230 compilation units address size. */
17232 static struct type
*
17233 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17235 struct type
*index_type
= die_type (die
, cu
);
17237 /* Dwarf-2 specifications explicitly allows to create subrange types
17238 without specifying a base type.
17239 In that case, the base type must be set to the type of
17240 the lower bound, upper bound or count, in that order, if any of these
17241 three attributes references an object that has a type.
17242 If no base type is found, the Dwarf-2 specifications say that
17243 a signed integer type of size equal to the size of an address should
17245 For the following C code: `extern char gdb_int [];'
17246 GCC produces an empty range DIE.
17247 FIXME: muller/2010-05-28: Possible references to object for low bound,
17248 high bound or count are not yet handled by this code. */
17249 if (TYPE_CODE (index_type
) == TYPE_CODE_VOID
)
17250 index_type
= cu
->per_cu
->addr_sized_int_type (false);
17255 /* Read the given DW_AT_subrange DIE. */
17257 static struct type
*
17258 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17260 struct type
*base_type
, *orig_base_type
;
17261 struct type
*range_type
;
17262 struct attribute
*attr
;
17263 struct dynamic_prop low
, high
;
17264 int low_default_is_valid
;
17265 int high_bound_is_count
= 0;
17267 ULONGEST negative_mask
;
17269 orig_base_type
= read_subrange_index_type (die
, cu
);
17271 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17272 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17273 creating the range type, but we use the result of check_typedef
17274 when examining properties of the type. */
17275 base_type
= check_typedef (orig_base_type
);
17277 /* The die_type call above may have already set the type for this DIE. */
17278 range_type
= get_die_type (die
, cu
);
17282 low
.kind
= PROP_CONST
;
17283 high
.kind
= PROP_CONST
;
17284 high
.data
.const_val
= 0;
17286 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17287 omitting DW_AT_lower_bound. */
17288 switch (cu
->language
)
17291 case language_cplus
:
17292 low
.data
.const_val
= 0;
17293 low_default_is_valid
= 1;
17295 case language_fortran
:
17296 low
.data
.const_val
= 1;
17297 low_default_is_valid
= 1;
17300 case language_objc
:
17301 case language_rust
:
17302 low
.data
.const_val
= 0;
17303 low_default_is_valid
= (cu
->header
.version
>= 4);
17307 case language_pascal
:
17308 low
.data
.const_val
= 1;
17309 low_default_is_valid
= (cu
->header
.version
>= 4);
17312 low
.data
.const_val
= 0;
17313 low_default_is_valid
= 0;
17317 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
17318 if (attr
!= nullptr)
17319 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
17320 else if (!low_default_is_valid
)
17321 complaint (_("Missing DW_AT_lower_bound "
17322 "- DIE at %s [in module %s]"),
17323 sect_offset_str (die
->sect_off
),
17324 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17326 struct attribute
*attr_ub
, *attr_count
;
17327 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
17328 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17330 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
17331 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17333 /* If bounds are constant do the final calculation here. */
17334 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
17335 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
17337 high_bound_is_count
= 1;
17341 if (attr_ub
!= NULL
)
17342 complaint (_("Unresolved DW_AT_upper_bound "
17343 "- DIE at %s [in module %s]"),
17344 sect_offset_str (die
->sect_off
),
17345 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17346 if (attr_count
!= NULL
)
17347 complaint (_("Unresolved DW_AT_count "
17348 "- DIE at %s [in module %s]"),
17349 sect_offset_str (die
->sect_off
),
17350 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17355 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
17356 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
17357 bias
= bias_attr
->constant_value (0);
17359 /* Normally, the DWARF producers are expected to use a signed
17360 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17361 But this is unfortunately not always the case, as witnessed
17362 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17363 is used instead. To work around that ambiguity, we treat
17364 the bounds as signed, and thus sign-extend their values, when
17365 the base type is signed. */
17367 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
17368 if (low
.kind
== PROP_CONST
17369 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
17370 low
.data
.const_val
|= negative_mask
;
17371 if (high
.kind
== PROP_CONST
17372 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
17373 high
.data
.const_val
|= negative_mask
;
17375 /* Check for bit and byte strides. */
17376 struct dynamic_prop byte_stride_prop
;
17377 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
17378 if (attr_byte_stride
!= nullptr)
17380 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
17381 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
17385 struct dynamic_prop bit_stride_prop
;
17386 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
17387 if (attr_bit_stride
!= nullptr)
17389 /* It only makes sense to have either a bit or byte stride. */
17390 if (attr_byte_stride
!= nullptr)
17392 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
17393 "- DIE at %s [in module %s]"),
17394 sect_offset_str (die
->sect_off
),
17395 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17396 attr_bit_stride
= nullptr;
17400 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
17401 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
17406 if (attr_byte_stride
!= nullptr
17407 || attr_bit_stride
!= nullptr)
17409 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
17410 struct dynamic_prop
*stride
17411 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
17414 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
17415 &high
, bias
, stride
, byte_stride_p
);
17418 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
17420 if (high_bound_is_count
)
17421 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
17423 /* Ada expects an empty array on no boundary attributes. */
17424 if (attr
== NULL
&& cu
->language
!= language_ada
)
17425 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
17427 name
= dwarf2_name (die
, cu
);
17429 TYPE_NAME (range_type
) = name
;
17431 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17432 if (attr
!= nullptr)
17433 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
17435 maybe_set_alignment (cu
, die
, range_type
);
17437 set_die_type (die
, range_type
, cu
);
17439 /* set_die_type should be already done. */
17440 set_descriptive_type (range_type
, die
, cu
);
17445 static struct type
*
17446 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17450 type
= init_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
, TYPE_CODE_VOID
,0,
17452 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
17454 /* In Ada, an unspecified type is typically used when the description
17455 of the type is deferred to a different unit. When encountering
17456 such a type, we treat it as a stub, and try to resolve it later on,
17458 if (cu
->language
== language_ada
)
17459 TYPE_STUB (type
) = 1;
17461 return set_die_type (die
, type
, cu
);
17464 /* Read a single die and all its descendents. Set the die's sibling
17465 field to NULL; set other fields in the die correctly, and set all
17466 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
17467 location of the info_ptr after reading all of those dies. PARENT
17468 is the parent of the die in question. */
17470 static struct die_info
*
17471 read_die_and_children (const struct die_reader_specs
*reader
,
17472 const gdb_byte
*info_ptr
,
17473 const gdb_byte
**new_info_ptr
,
17474 struct die_info
*parent
)
17476 struct die_info
*die
;
17477 const gdb_byte
*cur_ptr
;
17479 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
17482 *new_info_ptr
= cur_ptr
;
17485 store_in_ref_table (die
, reader
->cu
);
17487 if (die
->has_children
)
17488 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
17492 *new_info_ptr
= cur_ptr
;
17495 die
->sibling
= NULL
;
17496 die
->parent
= parent
;
17500 /* Read a die, all of its descendents, and all of its siblings; set
17501 all of the fields of all of the dies correctly. Arguments are as
17502 in read_die_and_children. */
17504 static struct die_info
*
17505 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
17506 const gdb_byte
*info_ptr
,
17507 const gdb_byte
**new_info_ptr
,
17508 struct die_info
*parent
)
17510 struct die_info
*first_die
, *last_sibling
;
17511 const gdb_byte
*cur_ptr
;
17513 cur_ptr
= info_ptr
;
17514 first_die
= last_sibling
= NULL
;
17518 struct die_info
*die
17519 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
17523 *new_info_ptr
= cur_ptr
;
17530 last_sibling
->sibling
= die
;
17532 last_sibling
= die
;
17536 /* Read a die, all of its descendents, and all of its siblings; set
17537 all of the fields of all of the dies correctly. Arguments are as
17538 in read_die_and_children.
17539 This the main entry point for reading a DIE and all its children. */
17541 static struct die_info
*
17542 read_die_and_siblings (const struct die_reader_specs
*reader
,
17543 const gdb_byte
*info_ptr
,
17544 const gdb_byte
**new_info_ptr
,
17545 struct die_info
*parent
)
17547 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
17548 new_info_ptr
, parent
);
17550 if (dwarf_die_debug
)
17552 fprintf_unfiltered (gdb_stdlog
,
17553 "Read die from %s@0x%x of %s:\n",
17554 reader
->die_section
->get_name (),
17555 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17556 bfd_get_filename (reader
->abfd
));
17557 dump_die (die
, dwarf_die_debug
);
17563 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
17565 The caller is responsible for filling in the extra attributes
17566 and updating (*DIEP)->num_attrs.
17567 Set DIEP to point to a newly allocated die with its information,
17568 except for its child, sibling, and parent fields. */
17570 static const gdb_byte
*
17571 read_full_die_1 (const struct die_reader_specs
*reader
,
17572 struct die_info
**diep
, const gdb_byte
*info_ptr
,
17573 int num_extra_attrs
)
17575 unsigned int abbrev_number
, bytes_read
, i
;
17576 struct abbrev_info
*abbrev
;
17577 struct die_info
*die
;
17578 struct dwarf2_cu
*cu
= reader
->cu
;
17579 bfd
*abfd
= reader
->abfd
;
17581 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
17582 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
17583 info_ptr
+= bytes_read
;
17584 if (!abbrev_number
)
17590 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
17592 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
17594 bfd_get_filename (abfd
));
17596 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
17597 die
->sect_off
= sect_off
;
17598 die
->tag
= abbrev
->tag
;
17599 die
->abbrev
= abbrev_number
;
17600 die
->has_children
= abbrev
->has_children
;
17602 /* Make the result usable.
17603 The caller needs to update num_attrs after adding the extra
17605 die
->num_attrs
= abbrev
->num_attrs
;
17607 std::vector
<int> indexes_that_need_reprocess
;
17608 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
17610 bool need_reprocess
;
17612 read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
17613 info_ptr
, &need_reprocess
);
17614 if (need_reprocess
)
17615 indexes_that_need_reprocess
.push_back (i
);
17618 struct attribute
*attr
= die
->attr (DW_AT_str_offsets_base
);
17619 if (attr
!= nullptr)
17620 cu
->str_offsets_base
= DW_UNSND (attr
);
17622 attr
= die
->attr (DW_AT_loclists_base
);
17623 if (attr
!= nullptr)
17624 cu
->loclist_base
= DW_UNSND (attr
);
17626 auto maybe_addr_base
= die
->addr_base ();
17627 if (maybe_addr_base
.has_value ())
17628 cu
->addr_base
= *maybe_addr_base
;
17629 for (int index
: indexes_that_need_reprocess
)
17630 read_attribute_reprocess (reader
, &die
->attrs
[index
]);
17635 /* Read a die and all its attributes.
17636 Set DIEP to point to a newly allocated die with its information,
17637 except for its child, sibling, and parent fields. */
17639 static const gdb_byte
*
17640 read_full_die (const struct die_reader_specs
*reader
,
17641 struct die_info
**diep
, const gdb_byte
*info_ptr
)
17643 const gdb_byte
*result
;
17645 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
17647 if (dwarf_die_debug
)
17649 fprintf_unfiltered (gdb_stdlog
,
17650 "Read die from %s@0x%x of %s:\n",
17651 reader
->die_section
->get_name (),
17652 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17653 bfd_get_filename (reader
->abfd
));
17654 dump_die (*diep
, dwarf_die_debug
);
17661 /* Returns nonzero if TAG represents a type that we might generate a partial
17665 is_type_tag_for_partial (int tag
)
17670 /* Some types that would be reasonable to generate partial symbols for,
17671 that we don't at present. */
17672 case DW_TAG_array_type
:
17673 case DW_TAG_file_type
:
17674 case DW_TAG_ptr_to_member_type
:
17675 case DW_TAG_set_type
:
17676 case DW_TAG_string_type
:
17677 case DW_TAG_subroutine_type
:
17679 case DW_TAG_base_type
:
17680 case DW_TAG_class_type
:
17681 case DW_TAG_interface_type
:
17682 case DW_TAG_enumeration_type
:
17683 case DW_TAG_structure_type
:
17684 case DW_TAG_subrange_type
:
17685 case DW_TAG_typedef
:
17686 case DW_TAG_union_type
:
17693 /* Load all DIEs that are interesting for partial symbols into memory. */
17695 static struct partial_die_info
*
17696 load_partial_dies (const struct die_reader_specs
*reader
,
17697 const gdb_byte
*info_ptr
, int building_psymtab
)
17699 struct dwarf2_cu
*cu
= reader
->cu
;
17700 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17701 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
17702 unsigned int bytes_read
;
17703 unsigned int load_all
= 0;
17704 int nesting_level
= 1;
17709 gdb_assert (cu
->per_cu
!= NULL
);
17710 if (cu
->per_cu
->load_all_dies
)
17714 = htab_create_alloc_ex (cu
->header
.length
/ 12,
17718 &cu
->comp_unit_obstack
,
17719 hashtab_obstack_allocate
,
17720 dummy_obstack_deallocate
);
17724 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
17726 /* A NULL abbrev means the end of a series of children. */
17727 if (abbrev
== NULL
)
17729 if (--nesting_level
== 0)
17732 info_ptr
+= bytes_read
;
17733 last_die
= parent_die
;
17734 parent_die
= parent_die
->die_parent
;
17738 /* Check for template arguments. We never save these; if
17739 they're seen, we just mark the parent, and go on our way. */
17740 if (parent_die
!= NULL
17741 && cu
->language
== language_cplus
17742 && (abbrev
->tag
== DW_TAG_template_type_param
17743 || abbrev
->tag
== DW_TAG_template_value_param
))
17745 parent_die
->has_template_arguments
= 1;
17749 /* We don't need a partial DIE for the template argument. */
17750 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17755 /* We only recurse into c++ subprograms looking for template arguments.
17756 Skip their other children. */
17758 && cu
->language
== language_cplus
17759 && parent_die
!= NULL
17760 && parent_die
->tag
== DW_TAG_subprogram
)
17762 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17766 /* Check whether this DIE is interesting enough to save. Normally
17767 we would not be interested in members here, but there may be
17768 later variables referencing them via DW_AT_specification (for
17769 static members). */
17771 && !is_type_tag_for_partial (abbrev
->tag
)
17772 && abbrev
->tag
!= DW_TAG_constant
17773 && abbrev
->tag
!= DW_TAG_enumerator
17774 && abbrev
->tag
!= DW_TAG_subprogram
17775 && abbrev
->tag
!= DW_TAG_inlined_subroutine
17776 && abbrev
->tag
!= DW_TAG_lexical_block
17777 && abbrev
->tag
!= DW_TAG_variable
17778 && abbrev
->tag
!= DW_TAG_namespace
17779 && abbrev
->tag
!= DW_TAG_module
17780 && abbrev
->tag
!= DW_TAG_member
17781 && abbrev
->tag
!= DW_TAG_imported_unit
17782 && abbrev
->tag
!= DW_TAG_imported_declaration
)
17784 /* Otherwise we skip to the next sibling, if any. */
17785 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17789 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
17792 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
17794 /* This two-pass algorithm for processing partial symbols has a
17795 high cost in cache pressure. Thus, handle some simple cases
17796 here which cover the majority of C partial symbols. DIEs
17797 which neither have specification tags in them, nor could have
17798 specification tags elsewhere pointing at them, can simply be
17799 processed and discarded.
17801 This segment is also optional; scan_partial_symbols and
17802 add_partial_symbol will handle these DIEs if we chain
17803 them in normally. When compilers which do not emit large
17804 quantities of duplicate debug information are more common,
17805 this code can probably be removed. */
17807 /* Any complete simple types at the top level (pretty much all
17808 of them, for a language without namespaces), can be processed
17810 if (parent_die
== NULL
17811 && pdi
.has_specification
== 0
17812 && pdi
.is_declaration
== 0
17813 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
17814 || pdi
.tag
== DW_TAG_base_type
17815 || pdi
.tag
== DW_TAG_subrange_type
))
17817 if (building_psymtab
&& pdi
.name
!= NULL
)
17818 add_psymbol_to_list (pdi
.name
, false,
17819 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
17820 psymbol_placement::STATIC
,
17821 0, cu
->language
, objfile
);
17822 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
17826 /* The exception for DW_TAG_typedef with has_children above is
17827 a workaround of GCC PR debug/47510. In the case of this complaint
17828 type_name_or_error will error on such types later.
17830 GDB skipped children of DW_TAG_typedef by the shortcut above and then
17831 it could not find the child DIEs referenced later, this is checked
17832 above. In correct DWARF DW_TAG_typedef should have no children. */
17834 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
17835 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
17836 "- DIE at %s [in module %s]"),
17837 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
17839 /* If we're at the second level, and we're an enumerator, and
17840 our parent has no specification (meaning possibly lives in a
17841 namespace elsewhere), then we can add the partial symbol now
17842 instead of queueing it. */
17843 if (pdi
.tag
== DW_TAG_enumerator
17844 && parent_die
!= NULL
17845 && parent_die
->die_parent
== NULL
17846 && parent_die
->tag
== DW_TAG_enumeration_type
17847 && parent_die
->has_specification
== 0)
17849 if (pdi
.name
== NULL
)
17850 complaint (_("malformed enumerator DIE ignored"));
17851 else if (building_psymtab
)
17852 add_psymbol_to_list (pdi
.name
, false,
17853 VAR_DOMAIN
, LOC_CONST
, -1,
17854 cu
->language
== language_cplus
17855 ? psymbol_placement::GLOBAL
17856 : psymbol_placement::STATIC
,
17857 0, cu
->language
, objfile
);
17859 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
17863 struct partial_die_info
*part_die
17864 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
17866 /* We'll save this DIE so link it in. */
17867 part_die
->die_parent
= parent_die
;
17868 part_die
->die_sibling
= NULL
;
17869 part_die
->die_child
= NULL
;
17871 if (last_die
&& last_die
== parent_die
)
17872 last_die
->die_child
= part_die
;
17874 last_die
->die_sibling
= part_die
;
17876 last_die
= part_die
;
17878 if (first_die
== NULL
)
17879 first_die
= part_die
;
17881 /* Maybe add the DIE to the hash table. Not all DIEs that we
17882 find interesting need to be in the hash table, because we
17883 also have the parent/sibling/child chains; only those that we
17884 might refer to by offset later during partial symbol reading.
17886 For now this means things that might have be the target of a
17887 DW_AT_specification, DW_AT_abstract_origin, or
17888 DW_AT_extension. DW_AT_extension will refer only to
17889 namespaces; DW_AT_abstract_origin refers to functions (and
17890 many things under the function DIE, but we do not recurse
17891 into function DIEs during partial symbol reading) and
17892 possibly variables as well; DW_AT_specification refers to
17893 declarations. Declarations ought to have the DW_AT_declaration
17894 flag. It happens that GCC forgets to put it in sometimes, but
17895 only for functions, not for types.
17897 Adding more things than necessary to the hash table is harmless
17898 except for the performance cost. Adding too few will result in
17899 wasted time in find_partial_die, when we reread the compilation
17900 unit with load_all_dies set. */
17903 || abbrev
->tag
== DW_TAG_constant
17904 || abbrev
->tag
== DW_TAG_subprogram
17905 || abbrev
->tag
== DW_TAG_variable
17906 || abbrev
->tag
== DW_TAG_namespace
17907 || part_die
->is_declaration
)
17911 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
17912 to_underlying (part_die
->sect_off
),
17917 /* For some DIEs we want to follow their children (if any). For C
17918 we have no reason to follow the children of structures; for other
17919 languages we have to, so that we can get at method physnames
17920 to infer fully qualified class names, for DW_AT_specification,
17921 and for C++ template arguments. For C++, we also look one level
17922 inside functions to find template arguments (if the name of the
17923 function does not already contain the template arguments).
17925 For Ada and Fortran, we need to scan the children of subprograms
17926 and lexical blocks as well because these languages allow the
17927 definition of nested entities that could be interesting for the
17928 debugger, such as nested subprograms for instance. */
17929 if (last_die
->has_children
17931 || last_die
->tag
== DW_TAG_namespace
17932 || last_die
->tag
== DW_TAG_module
17933 || last_die
->tag
== DW_TAG_enumeration_type
17934 || (cu
->language
== language_cplus
17935 && last_die
->tag
== DW_TAG_subprogram
17936 && (last_die
->name
== NULL
17937 || strchr (last_die
->name
, '<') == NULL
))
17938 || (cu
->language
!= language_c
17939 && (last_die
->tag
== DW_TAG_class_type
17940 || last_die
->tag
== DW_TAG_interface_type
17941 || last_die
->tag
== DW_TAG_structure_type
17942 || last_die
->tag
== DW_TAG_union_type
))
17943 || ((cu
->language
== language_ada
17944 || cu
->language
== language_fortran
)
17945 && (last_die
->tag
== DW_TAG_subprogram
17946 || last_die
->tag
== DW_TAG_lexical_block
))))
17949 parent_die
= last_die
;
17953 /* Otherwise we skip to the next sibling, if any. */
17954 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
17956 /* Back to the top, do it again. */
17960 partial_die_info::partial_die_info (sect_offset sect_off_
,
17961 struct abbrev_info
*abbrev
)
17962 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
17966 /* Read a minimal amount of information into the minimal die structure.
17967 INFO_PTR should point just after the initial uleb128 of a DIE. */
17970 partial_die_info::read (const struct die_reader_specs
*reader
,
17971 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
17973 struct dwarf2_cu
*cu
= reader
->cu
;
17974 struct dwarf2_per_objfile
*dwarf2_per_objfile
17975 = cu
->per_cu
->dwarf2_per_objfile
;
17977 int has_low_pc_attr
= 0;
17978 int has_high_pc_attr
= 0;
17979 int high_pc_relative
= 0;
17981 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
17984 bool need_reprocess
;
17985 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
],
17986 info_ptr
, &need_reprocess
);
17987 /* String and address offsets that need to do the reprocessing have
17988 already been read at this point, so there is no need to wait until
17989 the loop terminates to do the reprocessing. */
17990 if (need_reprocess
)
17991 read_attribute_reprocess (reader
, &attr
);
17992 /* Store the data if it is of an attribute we want to keep in a
17993 partial symbol table. */
17999 case DW_TAG_compile_unit
:
18000 case DW_TAG_partial_unit
:
18001 case DW_TAG_type_unit
:
18002 /* Compilation units have a DW_AT_name that is a filename, not
18003 a source language identifier. */
18004 case DW_TAG_enumeration_type
:
18005 case DW_TAG_enumerator
:
18006 /* These tags always have simple identifiers already; no need
18007 to canonicalize them. */
18008 name
= DW_STRING (&attr
);
18012 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18015 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
, objfile
);
18020 case DW_AT_linkage_name
:
18021 case DW_AT_MIPS_linkage_name
:
18022 /* Note that both forms of linkage name might appear. We
18023 assume they will be the same, and we only store the last
18025 linkage_name
= DW_STRING (&attr
);
18028 has_low_pc_attr
= 1;
18029 lowpc
= attr
.value_as_address ();
18031 case DW_AT_high_pc
:
18032 has_high_pc_attr
= 1;
18033 highpc
= attr
.value_as_address ();
18034 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
18035 high_pc_relative
= 1;
18037 case DW_AT_location
:
18038 /* Support the .debug_loc offsets. */
18039 if (attr
.form_is_block ())
18041 d
.locdesc
= DW_BLOCK (&attr
);
18043 else if (attr
.form_is_section_offset ())
18045 dwarf2_complex_location_expr_complaint ();
18049 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18050 "partial symbol information");
18053 case DW_AT_external
:
18054 is_external
= DW_UNSND (&attr
);
18056 case DW_AT_declaration
:
18057 is_declaration
= DW_UNSND (&attr
);
18062 case DW_AT_abstract_origin
:
18063 case DW_AT_specification
:
18064 case DW_AT_extension
:
18065 has_specification
= 1;
18066 spec_offset
= attr
.get_ref_die_offset ();
18067 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18068 || cu
->per_cu
->is_dwz
);
18070 case DW_AT_sibling
:
18071 /* Ignore absolute siblings, they might point outside of
18072 the current compile unit. */
18073 if (attr
.form
== DW_FORM_ref_addr
)
18074 complaint (_("ignoring absolute DW_AT_sibling"));
18077 const gdb_byte
*buffer
= reader
->buffer
;
18078 sect_offset off
= attr
.get_ref_die_offset ();
18079 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
18081 if (sibling_ptr
< info_ptr
)
18082 complaint (_("DW_AT_sibling points backwards"));
18083 else if (sibling_ptr
> reader
->buffer_end
)
18084 reader
->die_section
->overflow_complaint ();
18086 sibling
= sibling_ptr
;
18089 case DW_AT_byte_size
:
18092 case DW_AT_const_value
:
18093 has_const_value
= 1;
18095 case DW_AT_calling_convention
:
18096 /* DWARF doesn't provide a way to identify a program's source-level
18097 entry point. DW_AT_calling_convention attributes are only meant
18098 to describe functions' calling conventions.
18100 However, because it's a necessary piece of information in
18101 Fortran, and before DWARF 4 DW_CC_program was the only
18102 piece of debugging information whose definition refers to
18103 a 'main program' at all, several compilers marked Fortran
18104 main programs with DW_CC_program --- even when those
18105 functions use the standard calling conventions.
18107 Although DWARF now specifies a way to provide this
18108 information, we support this practice for backward
18110 if (DW_UNSND (&attr
) == DW_CC_program
18111 && cu
->language
== language_fortran
)
18112 main_subprogram
= 1;
18115 if (DW_UNSND (&attr
) == DW_INL_inlined
18116 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
18117 may_be_inlined
= 1;
18121 if (tag
== DW_TAG_imported_unit
)
18123 d
.sect_off
= attr
.get_ref_die_offset ();
18124 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18125 || cu
->per_cu
->is_dwz
);
18129 case DW_AT_main_subprogram
:
18130 main_subprogram
= DW_UNSND (&attr
);
18135 /* It would be nice to reuse dwarf2_get_pc_bounds here,
18136 but that requires a full DIE, so instead we just
18138 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
18139 unsigned int ranges_offset
= (DW_UNSND (&attr
)
18140 + (need_ranges_base
18144 /* Value of the DW_AT_ranges attribute is the offset in the
18145 .debug_ranges section. */
18146 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
18157 /* For Ada, if both the name and the linkage name appear, we prefer
18158 the latter. This lets "catch exception" work better, regardless
18159 of the order in which the name and linkage name were emitted.
18160 Really, though, this is just a workaround for the fact that gdb
18161 doesn't store both the name and the linkage name. */
18162 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
18163 name
= linkage_name
;
18165 if (high_pc_relative
)
18168 if (has_low_pc_attr
&& has_high_pc_attr
)
18170 /* When using the GNU linker, .gnu.linkonce. sections are used to
18171 eliminate duplicate copies of functions and vtables and such.
18172 The linker will arbitrarily choose one and discard the others.
18173 The AT_*_pc values for such functions refer to local labels in
18174 these sections. If the section from that file was discarded, the
18175 labels are not in the output, so the relocs get a value of 0.
18176 If this is a discarded function, mark the pc bounds as invalid,
18177 so that GDB will ignore it. */
18178 if (lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
18180 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18181 struct gdbarch
*gdbarch
= objfile
->arch ();
18183 complaint (_("DW_AT_low_pc %s is zero "
18184 "for DIE at %s [in module %s]"),
18185 paddress (gdbarch
, lowpc
),
18186 sect_offset_str (sect_off
),
18187 objfile_name (objfile
));
18189 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
18190 else if (lowpc
>= highpc
)
18192 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18193 struct gdbarch
*gdbarch
= objfile
->arch ();
18195 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
18196 "for DIE at %s [in module %s]"),
18197 paddress (gdbarch
, lowpc
),
18198 paddress (gdbarch
, highpc
),
18199 sect_offset_str (sect_off
),
18200 objfile_name (objfile
));
18209 /* Find a cached partial DIE at OFFSET in CU. */
18211 struct partial_die_info
*
18212 dwarf2_cu::find_partial_die (sect_offset sect_off
)
18214 struct partial_die_info
*lookup_die
= NULL
;
18215 struct partial_die_info
part_die (sect_off
);
18217 lookup_die
= ((struct partial_die_info
*)
18218 htab_find_with_hash (partial_dies
, &part_die
,
18219 to_underlying (sect_off
)));
18224 /* Find a partial DIE at OFFSET, which may or may not be in CU,
18225 except in the case of .debug_types DIEs which do not reference
18226 outside their CU (they do however referencing other types via
18227 DW_FORM_ref_sig8). */
18229 static const struct cu_partial_die_info
18230 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
18232 struct dwarf2_per_objfile
*dwarf2_per_objfile
18233 = cu
->per_cu
->dwarf2_per_objfile
;
18234 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18235 struct dwarf2_per_cu_data
*per_cu
= NULL
;
18236 struct partial_die_info
*pd
= NULL
;
18238 if (offset_in_dwz
== cu
->per_cu
->is_dwz
18239 && cu
->header
.offset_in_cu_p (sect_off
))
18241 pd
= cu
->find_partial_die (sect_off
);
18244 /* We missed recording what we needed.
18245 Load all dies and try again. */
18246 per_cu
= cu
->per_cu
;
18250 /* TUs don't reference other CUs/TUs (except via type signatures). */
18251 if (cu
->per_cu
->is_debug_types
)
18253 error (_("Dwarf Error: Type Unit at offset %s contains"
18254 " external reference to offset %s [in module %s].\n"),
18255 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
18256 bfd_get_filename (objfile
->obfd
));
18258 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
18259 dwarf2_per_objfile
);
18261 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
18262 load_partial_comp_unit (per_cu
);
18264 per_cu
->cu
->last_used
= 0;
18265 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18268 /* If we didn't find it, and not all dies have been loaded,
18269 load them all and try again. */
18271 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
18273 per_cu
->load_all_dies
= 1;
18275 /* This is nasty. When we reread the DIEs, somewhere up the call chain
18276 THIS_CU->cu may already be in use. So we can't just free it and
18277 replace its DIEs with the ones we read in. Instead, we leave those
18278 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
18279 and clobber THIS_CU->cu->partial_dies with the hash table for the new
18281 load_partial_comp_unit (per_cu
);
18283 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18287 internal_error (__FILE__
, __LINE__
,
18288 _("could not find partial DIE %s "
18289 "in cache [from module %s]\n"),
18290 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
18291 return { per_cu
->cu
, pd
};
18294 /* See if we can figure out if the class lives in a namespace. We do
18295 this by looking for a member function; its demangled name will
18296 contain namespace info, if there is any. */
18299 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
18300 struct dwarf2_cu
*cu
)
18302 /* NOTE: carlton/2003-10-07: Getting the info this way changes
18303 what template types look like, because the demangler
18304 frequently doesn't give the same name as the debug info. We
18305 could fix this by only using the demangled name to get the
18306 prefix (but see comment in read_structure_type). */
18308 struct partial_die_info
*real_pdi
;
18309 struct partial_die_info
*child_pdi
;
18311 /* If this DIE (this DIE's specification, if any) has a parent, then
18312 we should not do this. We'll prepend the parent's fully qualified
18313 name when we create the partial symbol. */
18315 real_pdi
= struct_pdi
;
18316 while (real_pdi
->has_specification
)
18318 auto res
= find_partial_die (real_pdi
->spec_offset
,
18319 real_pdi
->spec_is_dwz
, cu
);
18320 real_pdi
= res
.pdi
;
18324 if (real_pdi
->die_parent
!= NULL
)
18327 for (child_pdi
= struct_pdi
->die_child
;
18329 child_pdi
= child_pdi
->die_sibling
)
18331 if (child_pdi
->tag
== DW_TAG_subprogram
18332 && child_pdi
->linkage_name
!= NULL
)
18334 gdb::unique_xmalloc_ptr
<char> actual_class_name
18335 (language_class_name_from_physname (cu
->language_defn
,
18336 child_pdi
->linkage_name
));
18337 if (actual_class_name
!= NULL
)
18339 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18340 struct_pdi
->name
= objfile
->intern (actual_class_name
.get ());
18347 /* Return true if a DIE with TAG may have the DW_AT_const_value
18351 can_have_DW_AT_const_value_p (enum dwarf_tag tag
)
18355 case DW_TAG_constant
:
18356 case DW_TAG_enumerator
:
18357 case DW_TAG_formal_parameter
:
18358 case DW_TAG_template_value_param
:
18359 case DW_TAG_variable
:
18367 partial_die_info::fixup (struct dwarf2_cu
*cu
)
18369 /* Once we've fixed up a die, there's no point in doing so again.
18370 This also avoids a memory leak if we were to call
18371 guess_partial_die_structure_name multiple times. */
18375 /* If we found a reference attribute and the DIE has no name, try
18376 to find a name in the referred to DIE. */
18378 if (name
== NULL
&& has_specification
)
18380 struct partial_die_info
*spec_die
;
18382 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18383 spec_die
= res
.pdi
;
18386 spec_die
->fixup (cu
);
18388 if (spec_die
->name
)
18390 name
= spec_die
->name
;
18392 /* Copy DW_AT_external attribute if it is set. */
18393 if (spec_die
->is_external
)
18394 is_external
= spec_die
->is_external
;
18398 if (!has_const_value
&& has_specification
18399 && can_have_DW_AT_const_value_p (tag
))
18401 struct partial_die_info
*spec_die
;
18403 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18404 spec_die
= res
.pdi
;
18407 spec_die
->fixup (cu
);
18409 if (spec_die
->has_const_value
)
18411 /* Copy DW_AT_const_value attribute if it is set. */
18412 has_const_value
= spec_die
->has_const_value
;
18416 /* Set default names for some unnamed DIEs. */
18418 if (name
== NULL
&& tag
== DW_TAG_namespace
)
18419 name
= CP_ANONYMOUS_NAMESPACE_STR
;
18421 /* If there is no parent die to provide a namespace, and there are
18422 children, see if we can determine the namespace from their linkage
18424 if (cu
->language
== language_cplus
18425 && !cu
->per_cu
->dwarf2_per_objfile
->types
.empty ()
18426 && die_parent
== NULL
18428 && (tag
== DW_TAG_class_type
18429 || tag
== DW_TAG_structure_type
18430 || tag
== DW_TAG_union_type
))
18431 guess_partial_die_structure_name (this, cu
);
18433 /* GCC might emit a nameless struct or union that has a linkage
18434 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
18436 && (tag
== DW_TAG_class_type
18437 || tag
== DW_TAG_interface_type
18438 || tag
== DW_TAG_structure_type
18439 || tag
== DW_TAG_union_type
)
18440 && linkage_name
!= NULL
)
18442 gdb::unique_xmalloc_ptr
<char> demangled
18443 (gdb_demangle (linkage_name
, DMGL_TYPES
));
18444 if (demangled
!= nullptr)
18448 /* Strip any leading namespaces/classes, keep only the base name.
18449 DW_AT_name for named DIEs does not contain the prefixes. */
18450 base
= strrchr (demangled
.get (), ':');
18451 if (base
&& base
> demangled
.get () && base
[-1] == ':')
18454 base
= demangled
.get ();
18456 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18457 name
= objfile
->intern (base
);
18464 /* Read the .debug_loclists header contents from the given SECTION in the
18467 read_loclist_header (struct loclist_header
*header
,
18468 struct dwarf2_section_info
*section
)
18470 unsigned int bytes_read
;
18471 bfd
*abfd
= section
->get_bfd_owner ();
18472 const gdb_byte
*info_ptr
= section
->buffer
;
18473 header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
18474 info_ptr
+= bytes_read
;
18475 header
->version
= read_2_bytes (abfd
, info_ptr
);
18477 header
->addr_size
= read_1_byte (abfd
, info_ptr
);
18479 header
->segment_collector_size
= read_1_byte (abfd
, info_ptr
);
18481 header
->offset_entry_count
= read_4_bytes (abfd
, info_ptr
);
18484 /* Return the DW_AT_loclists_base value for the CU. */
18486 lookup_loclist_base (struct dwarf2_cu
*cu
)
18488 /* For the .dwo unit, the loclist_base points to the first offset following
18489 the header. The header consists of the following entities-
18490 1. Unit Length (4 bytes for 32 bit DWARF format, and 12 bytes for the 64
18492 2. version (2 bytes)
18493 3. address size (1 byte)
18494 4. segment selector size (1 byte)
18495 5. offset entry count (4 bytes)
18496 These sizes are derived as per the DWARFv5 standard. */
18497 if (cu
->dwo_unit
!= nullptr)
18499 if (cu
->header
.initial_length_size
== 4)
18500 return LOCLIST_HEADER_SIZE32
;
18501 return LOCLIST_HEADER_SIZE64
;
18503 return cu
->loclist_base
;
18506 /* Given a DW_FORM_loclistx value LOCLIST_INDEX, fetch the offset from the
18507 array of offsets in the .debug_loclists section. */
18509 read_loclist_index (struct dwarf2_cu
*cu
, ULONGEST loclist_index
)
18511 struct dwarf2_per_objfile
*dwarf2_per_objfile
18512 = cu
->per_cu
->dwarf2_per_objfile
;
18513 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18514 bfd
*abfd
= objfile
->obfd
;
18515 ULONGEST loclist_base
= lookup_loclist_base (cu
);
18516 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
18518 section
->read (objfile
);
18519 if (section
->buffer
== NULL
)
18520 complaint (_("DW_FORM_loclistx used without .debug_loclists "
18521 "section [in module %s]"), objfile_name (objfile
));
18522 struct loclist_header header
;
18523 read_loclist_header (&header
, section
);
18524 if (loclist_index
>= header
.offset_entry_count
)
18525 complaint (_("DW_FORM_loclistx pointing outside of "
18526 ".debug_loclists offset array [in module %s]"),
18527 objfile_name (objfile
));
18528 if (loclist_base
+ loclist_index
* cu
->header
.offset_size
18530 complaint (_("DW_FORM_loclistx pointing outside of "
18531 ".debug_loclists section [in module %s]"),
18532 objfile_name (objfile
));
18533 const gdb_byte
*info_ptr
18534 = section
->buffer
+ loclist_base
+ loclist_index
* cu
->header
.offset_size
;
18536 if (cu
->header
.offset_size
== 4)
18537 return bfd_get_32 (abfd
, info_ptr
) + loclist_base
;
18539 return bfd_get_64 (abfd
, info_ptr
) + loclist_base
;
18542 /* Process the attributes that had to be skipped in the first round. These
18543 attributes are the ones that need str_offsets_base or addr_base attributes.
18544 They could not have been processed in the first round, because at the time
18545 the values of str_offsets_base or addr_base may not have been known. */
18547 read_attribute_reprocess (const struct die_reader_specs
*reader
,
18548 struct attribute
*attr
)
18550 struct dwarf2_cu
*cu
= reader
->cu
;
18551 switch (attr
->form
)
18553 case DW_FORM_addrx
:
18554 case DW_FORM_GNU_addr_index
:
18555 DW_ADDR (attr
) = read_addr_index (cu
, DW_UNSND (attr
));
18557 case DW_FORM_loclistx
:
18558 DW_UNSND (attr
) = read_loclist_index (cu
, DW_UNSND (attr
));
18561 case DW_FORM_strx1
:
18562 case DW_FORM_strx2
:
18563 case DW_FORM_strx3
:
18564 case DW_FORM_strx4
:
18565 case DW_FORM_GNU_str_index
:
18567 unsigned int str_index
= DW_UNSND (attr
);
18568 if (reader
->dwo_file
!= NULL
)
18570 DW_STRING (attr
) = read_dwo_str_index (reader
, str_index
);
18571 DW_STRING_IS_CANONICAL (attr
) = 0;
18575 DW_STRING (attr
) = read_stub_str_index (cu
, str_index
);
18576 DW_STRING_IS_CANONICAL (attr
) = 0;
18581 gdb_assert_not_reached (_("Unexpected DWARF form."));
18585 /* Read an attribute value described by an attribute form. */
18587 static const gdb_byte
*
18588 read_attribute_value (const struct die_reader_specs
*reader
,
18589 struct attribute
*attr
, unsigned form
,
18590 LONGEST implicit_const
, const gdb_byte
*info_ptr
,
18591 bool *need_reprocess
)
18593 struct dwarf2_cu
*cu
= reader
->cu
;
18594 struct dwarf2_per_objfile
*dwarf2_per_objfile
18595 = cu
->per_cu
->dwarf2_per_objfile
;
18596 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18597 bfd
*abfd
= reader
->abfd
;
18598 struct comp_unit_head
*cu_header
= &cu
->header
;
18599 unsigned int bytes_read
;
18600 struct dwarf_block
*blk
;
18601 *need_reprocess
= false;
18603 attr
->form
= (enum dwarf_form
) form
;
18606 case DW_FORM_ref_addr
:
18607 if (cu
->header
.version
== 2)
18608 DW_UNSND (attr
) = cu
->header
.read_address (abfd
, info_ptr
,
18611 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
,
18613 info_ptr
+= bytes_read
;
18615 case DW_FORM_GNU_ref_alt
:
18616 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
18617 info_ptr
+= bytes_read
;
18621 struct gdbarch
*gdbarch
= objfile
->arch ();
18622 DW_ADDR (attr
) = cu
->header
.read_address (abfd
, info_ptr
, &bytes_read
);
18623 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
18624 info_ptr
+= bytes_read
;
18627 case DW_FORM_block2
:
18628 blk
= dwarf_alloc_block (cu
);
18629 blk
->size
= read_2_bytes (abfd
, info_ptr
);
18631 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18632 info_ptr
+= blk
->size
;
18633 DW_BLOCK (attr
) = blk
;
18635 case DW_FORM_block4
:
18636 blk
= dwarf_alloc_block (cu
);
18637 blk
->size
= read_4_bytes (abfd
, info_ptr
);
18639 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18640 info_ptr
+= blk
->size
;
18641 DW_BLOCK (attr
) = blk
;
18643 case DW_FORM_data2
:
18644 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
18647 case DW_FORM_data4
:
18648 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
18651 case DW_FORM_data8
:
18652 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
18655 case DW_FORM_data16
:
18656 blk
= dwarf_alloc_block (cu
);
18658 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
18660 DW_BLOCK (attr
) = blk
;
18662 case DW_FORM_sec_offset
:
18663 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
18664 info_ptr
+= bytes_read
;
18666 case DW_FORM_loclistx
:
18668 *need_reprocess
= true;
18669 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18670 info_ptr
+= bytes_read
;
18673 case DW_FORM_string
:
18674 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
18675 DW_STRING_IS_CANONICAL (attr
) = 0;
18676 info_ptr
+= bytes_read
;
18679 if (!cu
->per_cu
->is_dwz
)
18681 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
18682 abfd
, info_ptr
, cu_header
,
18684 DW_STRING_IS_CANONICAL (attr
) = 0;
18685 info_ptr
+= bytes_read
;
18689 case DW_FORM_line_strp
:
18690 if (!cu
->per_cu
->is_dwz
)
18693 = dwarf2_per_objfile
->read_line_string (info_ptr
, cu_header
,
18695 DW_STRING_IS_CANONICAL (attr
) = 0;
18696 info_ptr
+= bytes_read
;
18700 case DW_FORM_GNU_strp_alt
:
18702 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
18703 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
18706 DW_STRING (attr
) = dwz
->read_string (objfile
, str_offset
);
18707 DW_STRING_IS_CANONICAL (attr
) = 0;
18708 info_ptr
+= bytes_read
;
18711 case DW_FORM_exprloc
:
18712 case DW_FORM_block
:
18713 blk
= dwarf_alloc_block (cu
);
18714 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18715 info_ptr
+= bytes_read
;
18716 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18717 info_ptr
+= blk
->size
;
18718 DW_BLOCK (attr
) = blk
;
18720 case DW_FORM_block1
:
18721 blk
= dwarf_alloc_block (cu
);
18722 blk
->size
= read_1_byte (abfd
, info_ptr
);
18724 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18725 info_ptr
+= blk
->size
;
18726 DW_BLOCK (attr
) = blk
;
18728 case DW_FORM_data1
:
18729 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
18733 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
18736 case DW_FORM_flag_present
:
18737 DW_UNSND (attr
) = 1;
18739 case DW_FORM_sdata
:
18740 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
18741 info_ptr
+= bytes_read
;
18743 case DW_FORM_udata
:
18744 case DW_FORM_rnglistx
:
18745 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18746 info_ptr
+= bytes_read
;
18749 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18750 + read_1_byte (abfd
, info_ptr
));
18754 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18755 + read_2_bytes (abfd
, info_ptr
));
18759 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18760 + read_4_bytes (abfd
, info_ptr
));
18764 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18765 + read_8_bytes (abfd
, info_ptr
));
18768 case DW_FORM_ref_sig8
:
18769 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
18772 case DW_FORM_ref_udata
:
18773 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18774 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
18775 info_ptr
+= bytes_read
;
18777 case DW_FORM_indirect
:
18778 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18779 info_ptr
+= bytes_read
;
18780 if (form
== DW_FORM_implicit_const
)
18782 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
18783 info_ptr
+= bytes_read
;
18785 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
18786 info_ptr
, need_reprocess
);
18788 case DW_FORM_implicit_const
:
18789 DW_SND (attr
) = implicit_const
;
18791 case DW_FORM_addrx
:
18792 case DW_FORM_GNU_addr_index
:
18793 *need_reprocess
= true;
18794 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18795 info_ptr
+= bytes_read
;
18798 case DW_FORM_strx1
:
18799 case DW_FORM_strx2
:
18800 case DW_FORM_strx3
:
18801 case DW_FORM_strx4
:
18802 case DW_FORM_GNU_str_index
:
18804 ULONGEST str_index
;
18805 if (form
== DW_FORM_strx1
)
18807 str_index
= read_1_byte (abfd
, info_ptr
);
18810 else if (form
== DW_FORM_strx2
)
18812 str_index
= read_2_bytes (abfd
, info_ptr
);
18815 else if (form
== DW_FORM_strx3
)
18817 str_index
= read_3_bytes (abfd
, info_ptr
);
18820 else if (form
== DW_FORM_strx4
)
18822 str_index
= read_4_bytes (abfd
, info_ptr
);
18827 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18828 info_ptr
+= bytes_read
;
18830 *need_reprocess
= true;
18831 DW_UNSND (attr
) = str_index
;
18835 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
18836 dwarf_form_name (form
),
18837 bfd_get_filename (abfd
));
18841 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
18842 attr
->form
= DW_FORM_GNU_ref_alt
;
18844 /* We have seen instances where the compiler tried to emit a byte
18845 size attribute of -1 which ended up being encoded as an unsigned
18846 0xffffffff. Although 0xffffffff is technically a valid size value,
18847 an object of this size seems pretty unlikely so we can relatively
18848 safely treat these cases as if the size attribute was invalid and
18849 treat them as zero by default. */
18850 if (attr
->name
== DW_AT_byte_size
18851 && form
== DW_FORM_data4
18852 && DW_UNSND (attr
) >= 0xffffffff)
18855 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
18856 hex_string (DW_UNSND (attr
)));
18857 DW_UNSND (attr
) = 0;
18863 /* Read an attribute described by an abbreviated attribute. */
18865 static const gdb_byte
*
18866 read_attribute (const struct die_reader_specs
*reader
,
18867 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
18868 const gdb_byte
*info_ptr
, bool *need_reprocess
)
18870 attr
->name
= abbrev
->name
;
18871 return read_attribute_value (reader
, attr
, abbrev
->form
,
18872 abbrev
->implicit_const
, info_ptr
,
18876 /* Return pointer to string at .debug_str offset STR_OFFSET. */
18878 static const char *
18879 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18880 LONGEST str_offset
)
18882 return dwarf2_per_objfile
->str
.read_string (dwarf2_per_objfile
->objfile
,
18883 str_offset
, "DW_FORM_strp");
18886 /* Return pointer to string at .debug_str offset as read from BUF.
18887 BUF is assumed to be in a compilation unit described by CU_HEADER.
18888 Return *BYTES_READ_PTR count of bytes read from BUF. */
18890 static const char *
18891 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
18892 const gdb_byte
*buf
,
18893 const struct comp_unit_head
*cu_header
,
18894 unsigned int *bytes_read_ptr
)
18896 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
18898 return read_indirect_string_at_offset (dwarf2_per_objfile
, str_offset
);
18904 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
18905 const struct comp_unit_head
*cu_header
,
18906 unsigned int *bytes_read_ptr
)
18908 bfd
*abfd
= objfile
->obfd
;
18909 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
18911 return line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
18914 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
18915 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
18916 ADDR_SIZE is the size of addresses from the CU header. */
18919 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18920 unsigned int addr_index
, gdb::optional
<ULONGEST
> addr_base
,
18923 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18924 bfd
*abfd
= objfile
->obfd
;
18925 const gdb_byte
*info_ptr
;
18926 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
18928 dwarf2_per_objfile
->addr
.read (objfile
);
18929 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
18930 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
18931 objfile_name (objfile
));
18932 if (addr_base_or_zero
+ addr_index
* addr_size
18933 >= dwarf2_per_objfile
->addr
.size
)
18934 error (_("DW_FORM_addr_index pointing outside of "
18935 ".debug_addr section [in module %s]"),
18936 objfile_name (objfile
));
18937 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
18938 + addr_base_or_zero
+ addr_index
* addr_size
);
18939 if (addr_size
== 4)
18940 return bfd_get_32 (abfd
, info_ptr
);
18942 return bfd_get_64 (abfd
, info_ptr
);
18945 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
18948 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
18950 return read_addr_index_1 (cu
->per_cu
->dwarf2_per_objfile
, addr_index
,
18951 cu
->addr_base
, cu
->header
.addr_size
);
18954 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
18957 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
18958 unsigned int *bytes_read
)
18960 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
18961 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
18963 return read_addr_index (cu
, addr_index
);
18969 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
, unsigned int addr_index
)
18971 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
18972 struct dwarf2_cu
*cu
= per_cu
->cu
;
18973 gdb::optional
<ULONGEST
> addr_base
;
18976 /* We need addr_base and addr_size.
18977 If we don't have PER_CU->cu, we have to get it.
18978 Nasty, but the alternative is storing the needed info in PER_CU,
18979 which at this point doesn't seem justified: it's not clear how frequently
18980 it would get used and it would increase the size of every PER_CU.
18981 Entry points like dwarf2_per_cu_addr_size do a similar thing
18982 so we're not in uncharted territory here.
18983 Alas we need to be a bit more complicated as addr_base is contained
18986 We don't need to read the entire CU(/TU).
18987 We just need the header and top level die.
18989 IWBN to use the aging mechanism to let us lazily later discard the CU.
18990 For now we skip this optimization. */
18994 addr_base
= cu
->addr_base
;
18995 addr_size
= cu
->header
.addr_size
;
18999 cutu_reader
reader (per_cu
, NULL
, 0, false);
19000 addr_base
= reader
.cu
->addr_base
;
19001 addr_size
= reader
.cu
->header
.addr_size
;
19004 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
19008 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
19009 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
19012 static const char *
19013 read_str_index (struct dwarf2_cu
*cu
,
19014 struct dwarf2_section_info
*str_section
,
19015 struct dwarf2_section_info
*str_offsets_section
,
19016 ULONGEST str_offsets_base
, ULONGEST str_index
)
19018 struct dwarf2_per_objfile
*dwarf2_per_objfile
19019 = cu
->per_cu
->dwarf2_per_objfile
;
19020 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19021 const char *objf_name
= objfile_name (objfile
);
19022 bfd
*abfd
= objfile
->obfd
;
19023 const gdb_byte
*info_ptr
;
19024 ULONGEST str_offset
;
19025 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
19027 str_section
->read (objfile
);
19028 str_offsets_section
->read (objfile
);
19029 if (str_section
->buffer
== NULL
)
19030 error (_("%s used without %s section"
19031 " in CU at offset %s [in module %s]"),
19032 form_name
, str_section
->get_name (),
19033 sect_offset_str (cu
->header
.sect_off
), objf_name
);
19034 if (str_offsets_section
->buffer
== NULL
)
19035 error (_("%s used without %s section"
19036 " in CU at offset %s [in module %s]"),
19037 form_name
, str_section
->get_name (),
19038 sect_offset_str (cu
->header
.sect_off
), objf_name
);
19039 info_ptr
= (str_offsets_section
->buffer
19041 + str_index
* cu
->header
.offset_size
);
19042 if (cu
->header
.offset_size
== 4)
19043 str_offset
= bfd_get_32 (abfd
, info_ptr
);
19045 str_offset
= bfd_get_64 (abfd
, info_ptr
);
19046 if (str_offset
>= str_section
->size
)
19047 error (_("Offset from %s pointing outside of"
19048 " .debug_str.dwo section in CU at offset %s [in module %s]"),
19049 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19050 return (const char *) (str_section
->buffer
+ str_offset
);
19053 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
19055 static const char *
19056 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
19058 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
19059 ? reader
->cu
->header
.addr_size
: 0;
19060 return read_str_index (reader
->cu
,
19061 &reader
->dwo_file
->sections
.str
,
19062 &reader
->dwo_file
->sections
.str_offsets
,
19063 str_offsets_base
, str_index
);
19066 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
19068 static const char *
19069 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
19071 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19072 const char *objf_name
= objfile_name (objfile
);
19073 static const char form_name
[] = "DW_FORM_GNU_str_index";
19074 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
19076 if (!cu
->str_offsets_base
.has_value ())
19077 error (_("%s used in Fission stub without %s"
19078 " in CU at offset 0x%lx [in module %s]"),
19079 form_name
, str_offsets_attr_name
,
19080 (long) cu
->header
.offset_size
, objf_name
);
19082 return read_str_index (cu
,
19083 &cu
->per_cu
->dwarf2_per_objfile
->str
,
19084 &cu
->per_cu
->dwarf2_per_objfile
->str_offsets
,
19085 *cu
->str_offsets_base
, str_index
);
19088 /* Return the length of an LEB128 number in BUF. */
19091 leb128_size (const gdb_byte
*buf
)
19093 const gdb_byte
*begin
= buf
;
19099 if ((byte
& 128) == 0)
19100 return buf
- begin
;
19105 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
19114 cu
->language
= language_c
;
19117 case DW_LANG_C_plus_plus
:
19118 case DW_LANG_C_plus_plus_11
:
19119 case DW_LANG_C_plus_plus_14
:
19120 cu
->language
= language_cplus
;
19123 cu
->language
= language_d
;
19125 case DW_LANG_Fortran77
:
19126 case DW_LANG_Fortran90
:
19127 case DW_LANG_Fortran95
:
19128 case DW_LANG_Fortran03
:
19129 case DW_LANG_Fortran08
:
19130 cu
->language
= language_fortran
;
19133 cu
->language
= language_go
;
19135 case DW_LANG_Mips_Assembler
:
19136 cu
->language
= language_asm
;
19138 case DW_LANG_Ada83
:
19139 case DW_LANG_Ada95
:
19140 cu
->language
= language_ada
;
19142 case DW_LANG_Modula2
:
19143 cu
->language
= language_m2
;
19145 case DW_LANG_Pascal83
:
19146 cu
->language
= language_pascal
;
19149 cu
->language
= language_objc
;
19152 case DW_LANG_Rust_old
:
19153 cu
->language
= language_rust
;
19155 case DW_LANG_Cobol74
:
19156 case DW_LANG_Cobol85
:
19158 cu
->language
= language_minimal
;
19161 cu
->language_defn
= language_def (cu
->language
);
19164 /* Return the named attribute or NULL if not there. */
19166 static struct attribute
*
19167 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19172 struct attribute
*spec
= NULL
;
19174 for (i
= 0; i
< die
->num_attrs
; ++i
)
19176 if (die
->attrs
[i
].name
== name
)
19177 return &die
->attrs
[i
];
19178 if (die
->attrs
[i
].name
== DW_AT_specification
19179 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
19180 spec
= &die
->attrs
[i
];
19186 die
= follow_die_ref (die
, spec
, &cu
);
19192 /* Return the string associated with a string-typed attribute, or NULL if it
19193 is either not found or is of an incorrect type. */
19195 static const char *
19196 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19198 struct attribute
*attr
;
19199 const char *str
= NULL
;
19201 attr
= dwarf2_attr (die
, name
, cu
);
19205 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
19206 || attr
->form
== DW_FORM_string
19207 || attr
->form
== DW_FORM_strx
19208 || attr
->form
== DW_FORM_strx1
19209 || attr
->form
== DW_FORM_strx2
19210 || attr
->form
== DW_FORM_strx3
19211 || attr
->form
== DW_FORM_strx4
19212 || attr
->form
== DW_FORM_GNU_str_index
19213 || attr
->form
== DW_FORM_GNU_strp_alt
)
19214 str
= DW_STRING (attr
);
19216 complaint (_("string type expected for attribute %s for "
19217 "DIE at %s in module %s"),
19218 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
19219 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
19225 /* Return the dwo name or NULL if not present. If present, it is in either
19226 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
19227 static const char *
19228 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
19230 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
19231 if (dwo_name
== nullptr)
19232 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
19236 /* Return non-zero iff the attribute NAME is defined for the given DIE,
19237 and holds a non-zero value. This function should only be used for
19238 DW_FORM_flag or DW_FORM_flag_present attributes. */
19241 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
19243 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
19245 return (attr
&& DW_UNSND (attr
));
19249 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
19251 /* A DIE is a declaration if it has a DW_AT_declaration attribute
19252 which value is non-zero. However, we have to be careful with
19253 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
19254 (via dwarf2_flag_true_p) follows this attribute. So we may
19255 end up accidently finding a declaration attribute that belongs
19256 to a different DIE referenced by the specification attribute,
19257 even though the given DIE does not have a declaration attribute. */
19258 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
19259 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
19262 /* Return the die giving the specification for DIE, if there is
19263 one. *SPEC_CU is the CU containing DIE on input, and the CU
19264 containing the return value on output. If there is no
19265 specification, but there is an abstract origin, that is
19268 static struct die_info
*
19269 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
19271 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
19274 if (spec_attr
== NULL
)
19275 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
19277 if (spec_attr
== NULL
)
19280 return follow_die_ref (die
, spec_attr
, spec_cu
);
19283 /* Stub for free_line_header to match void * callback types. */
19286 free_line_header_voidp (void *arg
)
19288 struct line_header
*lh
= (struct line_header
*) arg
;
19293 /* A convenience function to find the proper .debug_line section for a CU. */
19295 static struct dwarf2_section_info
*
19296 get_debug_line_section (struct dwarf2_cu
*cu
)
19298 struct dwarf2_section_info
*section
;
19299 struct dwarf2_per_objfile
*dwarf2_per_objfile
19300 = cu
->per_cu
->dwarf2_per_objfile
;
19302 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
19304 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19305 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
19306 else if (cu
->per_cu
->is_dwz
)
19308 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19310 section
= &dwz
->line
;
19313 section
= &dwarf2_per_objfile
->line
;
19318 /* Read the statement program header starting at OFFSET in
19319 .debug_line, or .debug_line.dwo. Return a pointer
19320 to a struct line_header, allocated using xmalloc.
19321 Returns NULL if there is a problem reading the header, e.g., if it
19322 has a version we don't understand.
19324 NOTE: the strings in the include directory and file name tables of
19325 the returned object point into the dwarf line section buffer,
19326 and must not be freed. */
19328 static line_header_up
19329 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
19331 struct dwarf2_section_info
*section
;
19332 struct dwarf2_per_objfile
*dwarf2_per_objfile
19333 = cu
->per_cu
->dwarf2_per_objfile
;
19335 section
= get_debug_line_section (cu
);
19336 section
->read (dwarf2_per_objfile
->objfile
);
19337 if (section
->buffer
== NULL
)
19339 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19340 complaint (_("missing .debug_line.dwo section"));
19342 complaint (_("missing .debug_line section"));
19346 return dwarf_decode_line_header (sect_off
, cu
->per_cu
->is_dwz
,
19347 dwarf2_per_objfile
, section
,
19351 /* Subroutine of dwarf_decode_lines to simplify it.
19352 Return the file name of the psymtab for the given file_entry.
19353 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
19354 If space for the result is malloc'd, *NAME_HOLDER will be set.
19355 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
19357 static const char *
19358 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
19359 const dwarf2_psymtab
*pst
,
19360 const char *comp_dir
,
19361 gdb::unique_xmalloc_ptr
<char> *name_holder
)
19363 const char *include_name
= fe
.name
;
19364 const char *include_name_to_compare
= include_name
;
19365 const char *pst_filename
;
19368 const char *dir_name
= fe
.include_dir (lh
);
19370 gdb::unique_xmalloc_ptr
<char> hold_compare
;
19371 if (!IS_ABSOLUTE_PATH (include_name
)
19372 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
19374 /* Avoid creating a duplicate psymtab for PST.
19375 We do this by comparing INCLUDE_NAME and PST_FILENAME.
19376 Before we do the comparison, however, we need to account
19377 for DIR_NAME and COMP_DIR.
19378 First prepend dir_name (if non-NULL). If we still don't
19379 have an absolute path prepend comp_dir (if non-NULL).
19380 However, the directory we record in the include-file's
19381 psymtab does not contain COMP_DIR (to match the
19382 corresponding symtab(s)).
19387 bash$ gcc -g ./hello.c
19388 include_name = "hello.c"
19390 DW_AT_comp_dir = comp_dir = "/tmp"
19391 DW_AT_name = "./hello.c"
19395 if (dir_name
!= NULL
)
19397 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
19398 include_name
, (char *) NULL
));
19399 include_name
= name_holder
->get ();
19400 include_name_to_compare
= include_name
;
19402 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
19404 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
19405 include_name
, (char *) NULL
));
19406 include_name_to_compare
= hold_compare
.get ();
19410 pst_filename
= pst
->filename
;
19411 gdb::unique_xmalloc_ptr
<char> copied_name
;
19412 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
19414 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
19415 pst_filename
, (char *) NULL
));
19416 pst_filename
= copied_name
.get ();
19419 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
19423 return include_name
;
19426 /* State machine to track the state of the line number program. */
19428 class lnp_state_machine
19431 /* Initialize a machine state for the start of a line number
19433 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
19434 bool record_lines_p
);
19436 file_entry
*current_file ()
19438 /* lh->file_names is 0-based, but the file name numbers in the
19439 statement program are 1-based. */
19440 return m_line_header
->file_name_at (m_file
);
19443 /* Record the line in the state machine. END_SEQUENCE is true if
19444 we're processing the end of a sequence. */
19445 void record_line (bool end_sequence
);
19447 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
19448 nop-out rest of the lines in this sequence. */
19449 void check_line_address (struct dwarf2_cu
*cu
,
19450 const gdb_byte
*line_ptr
,
19451 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
19453 void handle_set_discriminator (unsigned int discriminator
)
19455 m_discriminator
= discriminator
;
19456 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
19459 /* Handle DW_LNE_set_address. */
19460 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
19463 address
+= baseaddr
;
19464 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
19467 /* Handle DW_LNS_advance_pc. */
19468 void handle_advance_pc (CORE_ADDR adjust
);
19470 /* Handle a special opcode. */
19471 void handle_special_opcode (unsigned char op_code
);
19473 /* Handle DW_LNS_advance_line. */
19474 void handle_advance_line (int line_delta
)
19476 advance_line (line_delta
);
19479 /* Handle DW_LNS_set_file. */
19480 void handle_set_file (file_name_index file
);
19482 /* Handle DW_LNS_negate_stmt. */
19483 void handle_negate_stmt ()
19485 m_is_stmt
= !m_is_stmt
;
19488 /* Handle DW_LNS_const_add_pc. */
19489 void handle_const_add_pc ();
19491 /* Handle DW_LNS_fixed_advance_pc. */
19492 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
19494 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19498 /* Handle DW_LNS_copy. */
19499 void handle_copy ()
19501 record_line (false);
19502 m_discriminator
= 0;
19505 /* Handle DW_LNE_end_sequence. */
19506 void handle_end_sequence ()
19508 m_currently_recording_lines
= true;
19512 /* Advance the line by LINE_DELTA. */
19513 void advance_line (int line_delta
)
19515 m_line
+= line_delta
;
19517 if (line_delta
!= 0)
19518 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
19521 struct dwarf2_cu
*m_cu
;
19523 gdbarch
*m_gdbarch
;
19525 /* True if we're recording lines.
19526 Otherwise we're building partial symtabs and are just interested in
19527 finding include files mentioned by the line number program. */
19528 bool m_record_lines_p
;
19530 /* The line number header. */
19531 line_header
*m_line_header
;
19533 /* These are part of the standard DWARF line number state machine,
19534 and initialized according to the DWARF spec. */
19536 unsigned char m_op_index
= 0;
19537 /* The line table index of the current file. */
19538 file_name_index m_file
= 1;
19539 unsigned int m_line
= 1;
19541 /* These are initialized in the constructor. */
19543 CORE_ADDR m_address
;
19545 unsigned int m_discriminator
;
19547 /* Additional bits of state we need to track. */
19549 /* The last file that we called dwarf2_start_subfile for.
19550 This is only used for TLLs. */
19551 unsigned int m_last_file
= 0;
19552 /* The last file a line number was recorded for. */
19553 struct subfile
*m_last_subfile
= NULL
;
19555 /* When true, record the lines we decode. */
19556 bool m_currently_recording_lines
= false;
19558 /* The last line number that was recorded, used to coalesce
19559 consecutive entries for the same line. This can happen, for
19560 example, when discriminators are present. PR 17276. */
19561 unsigned int m_last_line
= 0;
19562 bool m_line_has_non_zero_discriminator
= false;
19566 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
19568 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
19569 / m_line_header
->maximum_ops_per_instruction
)
19570 * m_line_header
->minimum_instruction_length
);
19571 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19572 m_op_index
= ((m_op_index
+ adjust
)
19573 % m_line_header
->maximum_ops_per_instruction
);
19577 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
19579 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
19580 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
19581 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
19582 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
19583 / m_line_header
->maximum_ops_per_instruction
)
19584 * m_line_header
->minimum_instruction_length
);
19585 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19586 m_op_index
= ((m_op_index
+ adj_opcode_d
)
19587 % m_line_header
->maximum_ops_per_instruction
);
19589 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
19590 advance_line (line_delta
);
19591 record_line (false);
19592 m_discriminator
= 0;
19596 lnp_state_machine::handle_set_file (file_name_index file
)
19600 const file_entry
*fe
= current_file ();
19602 dwarf2_debug_line_missing_file_complaint ();
19603 else if (m_record_lines_p
)
19605 const char *dir
= fe
->include_dir (m_line_header
);
19607 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
19608 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
19609 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
19614 lnp_state_machine::handle_const_add_pc ()
19617 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
19620 = (((m_op_index
+ adjust
)
19621 / m_line_header
->maximum_ops_per_instruction
)
19622 * m_line_header
->minimum_instruction_length
);
19624 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19625 m_op_index
= ((m_op_index
+ adjust
)
19626 % m_line_header
->maximum_ops_per_instruction
);
19629 /* Return non-zero if we should add LINE to the line number table.
19630 LINE is the line to add, LAST_LINE is the last line that was added,
19631 LAST_SUBFILE is the subfile for LAST_LINE.
19632 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
19633 had a non-zero discriminator.
19635 We have to be careful in the presence of discriminators.
19636 E.g., for this line:
19638 for (i = 0; i < 100000; i++);
19640 clang can emit four line number entries for that one line,
19641 each with a different discriminator.
19642 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
19644 However, we want gdb to coalesce all four entries into one.
19645 Otherwise the user could stepi into the middle of the line and
19646 gdb would get confused about whether the pc really was in the
19647 middle of the line.
19649 Things are further complicated by the fact that two consecutive
19650 line number entries for the same line is a heuristic used by gcc
19651 to denote the end of the prologue. So we can't just discard duplicate
19652 entries, we have to be selective about it. The heuristic we use is
19653 that we only collapse consecutive entries for the same line if at least
19654 one of those entries has a non-zero discriminator. PR 17276.
19656 Note: Addresses in the line number state machine can never go backwards
19657 within one sequence, thus this coalescing is ok. */
19660 dwarf_record_line_p (struct dwarf2_cu
*cu
,
19661 unsigned int line
, unsigned int last_line
,
19662 int line_has_non_zero_discriminator
,
19663 struct subfile
*last_subfile
)
19665 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
19667 if (line
!= last_line
)
19669 /* Same line for the same file that we've seen already.
19670 As a last check, for pr 17276, only record the line if the line
19671 has never had a non-zero discriminator. */
19672 if (!line_has_non_zero_discriminator
)
19677 /* Use the CU's builder to record line number LINE beginning at
19678 address ADDRESS in the line table of subfile SUBFILE. */
19681 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
19682 unsigned int line
, CORE_ADDR address
, bool is_stmt
,
19683 struct dwarf2_cu
*cu
)
19685 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
19687 if (dwarf_line_debug
)
19689 fprintf_unfiltered (gdb_stdlog
,
19690 "Recording line %u, file %s, address %s\n",
19691 line
, lbasename (subfile
->name
),
19692 paddress (gdbarch
, address
));
19696 cu
->get_builder ()->record_line (subfile
, line
, addr
, is_stmt
);
19699 /* Subroutine of dwarf_decode_lines_1 to simplify it.
19700 Mark the end of a set of line number records.
19701 The arguments are the same as for dwarf_record_line_1.
19702 If SUBFILE is NULL the request is ignored. */
19705 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
19706 CORE_ADDR address
, struct dwarf2_cu
*cu
)
19708 if (subfile
== NULL
)
19711 if (dwarf_line_debug
)
19713 fprintf_unfiltered (gdb_stdlog
,
19714 "Finishing current line, file %s, address %s\n",
19715 lbasename (subfile
->name
),
19716 paddress (gdbarch
, address
));
19719 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, true, cu
);
19723 lnp_state_machine::record_line (bool end_sequence
)
19725 if (dwarf_line_debug
)
19727 fprintf_unfiltered (gdb_stdlog
,
19728 "Processing actual line %u: file %u,"
19729 " address %s, is_stmt %u, discrim %u%s\n",
19731 paddress (m_gdbarch
, m_address
),
19732 m_is_stmt
, m_discriminator
,
19733 (end_sequence
? "\t(end sequence)" : ""));
19736 file_entry
*fe
= current_file ();
19739 dwarf2_debug_line_missing_file_complaint ();
19740 /* For now we ignore lines not starting on an instruction boundary.
19741 But not when processing end_sequence for compatibility with the
19742 previous version of the code. */
19743 else if (m_op_index
== 0 || end_sequence
)
19745 fe
->included_p
= 1;
19746 if (m_record_lines_p
)
19748 if (m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ()
19751 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
19752 m_currently_recording_lines
? m_cu
: nullptr);
19757 bool is_stmt
= producer_is_codewarrior (m_cu
) || m_is_stmt
;
19759 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
19760 m_line_has_non_zero_discriminator
,
19763 buildsym_compunit
*builder
= m_cu
->get_builder ();
19764 dwarf_record_line_1 (m_gdbarch
,
19765 builder
->get_current_subfile (),
19766 m_line
, m_address
, is_stmt
,
19767 m_currently_recording_lines
? m_cu
: nullptr);
19769 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
19770 m_last_line
= m_line
;
19776 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
19777 line_header
*lh
, bool record_lines_p
)
19781 m_record_lines_p
= record_lines_p
;
19782 m_line_header
= lh
;
19784 m_currently_recording_lines
= true;
19786 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
19787 was a line entry for it so that the backend has a chance to adjust it
19788 and also record it in case it needs it. This is currently used by MIPS
19789 code, cf. `mips_adjust_dwarf2_line'. */
19790 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
19791 m_is_stmt
= lh
->default_is_stmt
;
19792 m_discriminator
= 0;
19796 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
19797 const gdb_byte
*line_ptr
,
19798 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
19800 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
19801 the pc range of the CU. However, we restrict the test to only ADDRESS
19802 values of zero to preserve GDB's previous behaviour which is to handle
19803 the specific case of a function being GC'd by the linker. */
19805 if (address
== 0 && address
< unrelocated_lowpc
)
19807 /* This line table is for a function which has been
19808 GCd by the linker. Ignore it. PR gdb/12528 */
19810 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19811 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
19813 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
19814 line_offset
, objfile_name (objfile
));
19815 m_currently_recording_lines
= false;
19816 /* Note: m_currently_recording_lines is left as false until we see
19817 DW_LNE_end_sequence. */
19821 /* Subroutine of dwarf_decode_lines to simplify it.
19822 Process the line number information in LH.
19823 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
19824 program in order to set included_p for every referenced header. */
19827 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
19828 const int decode_for_pst_p
, CORE_ADDR lowpc
)
19830 const gdb_byte
*line_ptr
, *extended_end
;
19831 const gdb_byte
*line_end
;
19832 unsigned int bytes_read
, extended_len
;
19833 unsigned char op_code
, extended_op
;
19834 CORE_ADDR baseaddr
;
19835 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19836 bfd
*abfd
= objfile
->obfd
;
19837 struct gdbarch
*gdbarch
= objfile
->arch ();
19838 /* True if we're recording line info (as opposed to building partial
19839 symtabs and just interested in finding include files mentioned by
19840 the line number program). */
19841 bool record_lines_p
= !decode_for_pst_p
;
19843 baseaddr
= objfile
->text_section_offset ();
19845 line_ptr
= lh
->statement_program_start
;
19846 line_end
= lh
->statement_program_end
;
19848 /* Read the statement sequences until there's nothing left. */
19849 while (line_ptr
< line_end
)
19851 /* The DWARF line number program state machine. Reset the state
19852 machine at the start of each sequence. */
19853 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
19854 bool end_sequence
= false;
19856 if (record_lines_p
)
19858 /* Start a subfile for the current file of the state
19860 const file_entry
*fe
= state_machine
.current_file ();
19863 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
19866 /* Decode the table. */
19867 while (line_ptr
< line_end
&& !end_sequence
)
19869 op_code
= read_1_byte (abfd
, line_ptr
);
19872 if (op_code
>= lh
->opcode_base
)
19874 /* Special opcode. */
19875 state_machine
.handle_special_opcode (op_code
);
19877 else switch (op_code
)
19879 case DW_LNS_extended_op
:
19880 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
19882 line_ptr
+= bytes_read
;
19883 extended_end
= line_ptr
+ extended_len
;
19884 extended_op
= read_1_byte (abfd
, line_ptr
);
19886 switch (extended_op
)
19888 case DW_LNE_end_sequence
:
19889 state_machine
.handle_end_sequence ();
19890 end_sequence
= true;
19892 case DW_LNE_set_address
:
19895 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
19896 line_ptr
+= bytes_read
;
19898 state_machine
.check_line_address (cu
, line_ptr
,
19899 lowpc
- baseaddr
, address
);
19900 state_machine
.handle_set_address (baseaddr
, address
);
19903 case DW_LNE_define_file
:
19905 const char *cur_file
;
19906 unsigned int mod_time
, length
;
19909 cur_file
= read_direct_string (abfd
, line_ptr
,
19911 line_ptr
+= bytes_read
;
19912 dindex
= (dir_index
)
19913 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19914 line_ptr
+= bytes_read
;
19916 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19917 line_ptr
+= bytes_read
;
19919 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19920 line_ptr
+= bytes_read
;
19921 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
19924 case DW_LNE_set_discriminator
:
19926 /* The discriminator is not interesting to the
19927 debugger; just ignore it. We still need to
19928 check its value though:
19929 if there are consecutive entries for the same
19930 (non-prologue) line we want to coalesce them.
19933 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19934 line_ptr
+= bytes_read
;
19936 state_machine
.handle_set_discriminator (discr
);
19940 complaint (_("mangled .debug_line section"));
19943 /* Make sure that we parsed the extended op correctly. If e.g.
19944 we expected a different address size than the producer used,
19945 we may have read the wrong number of bytes. */
19946 if (line_ptr
!= extended_end
)
19948 complaint (_("mangled .debug_line section"));
19953 state_machine
.handle_copy ();
19955 case DW_LNS_advance_pc
:
19958 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19959 line_ptr
+= bytes_read
;
19961 state_machine
.handle_advance_pc (adjust
);
19964 case DW_LNS_advance_line
:
19967 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
19968 line_ptr
+= bytes_read
;
19970 state_machine
.handle_advance_line (line_delta
);
19973 case DW_LNS_set_file
:
19975 file_name_index file
19976 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
19978 line_ptr
+= bytes_read
;
19980 state_machine
.handle_set_file (file
);
19983 case DW_LNS_set_column
:
19984 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19985 line_ptr
+= bytes_read
;
19987 case DW_LNS_negate_stmt
:
19988 state_machine
.handle_negate_stmt ();
19990 case DW_LNS_set_basic_block
:
19992 /* Add to the address register of the state machine the
19993 address increment value corresponding to special opcode
19994 255. I.e., this value is scaled by the minimum
19995 instruction length since special opcode 255 would have
19996 scaled the increment. */
19997 case DW_LNS_const_add_pc
:
19998 state_machine
.handle_const_add_pc ();
20000 case DW_LNS_fixed_advance_pc
:
20002 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
20005 state_machine
.handle_fixed_advance_pc (addr_adj
);
20010 /* Unknown standard opcode, ignore it. */
20013 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
20015 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20016 line_ptr
+= bytes_read
;
20023 dwarf2_debug_line_missing_end_sequence_complaint ();
20025 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
20026 in which case we still finish recording the last line). */
20027 state_machine
.record_line (true);
20031 /* Decode the Line Number Program (LNP) for the given line_header
20032 structure and CU. The actual information extracted and the type
20033 of structures created from the LNP depends on the value of PST.
20035 1. If PST is NULL, then this procedure uses the data from the program
20036 to create all necessary symbol tables, and their linetables.
20038 2. If PST is not NULL, this procedure reads the program to determine
20039 the list of files included by the unit represented by PST, and
20040 builds all the associated partial symbol tables.
20042 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20043 It is used for relative paths in the line table.
20044 NOTE: When processing partial symtabs (pst != NULL),
20045 comp_dir == pst->dirname.
20047 NOTE: It is important that psymtabs have the same file name (via strcmp)
20048 as the corresponding symtab. Since COMP_DIR is not used in the name of the
20049 symtab we don't use it in the name of the psymtabs we create.
20050 E.g. expand_line_sal requires this when finding psymtabs to expand.
20051 A good testcase for this is mb-inline.exp.
20053 LOWPC is the lowest address in CU (or 0 if not known).
20055 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
20056 for its PC<->lines mapping information. Otherwise only the filename
20057 table is read in. */
20060 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
20061 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
20062 CORE_ADDR lowpc
, int decode_mapping
)
20064 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20065 const int decode_for_pst_p
= (pst
!= NULL
);
20067 if (decode_mapping
)
20068 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
20070 if (decode_for_pst_p
)
20072 /* Now that we're done scanning the Line Header Program, we can
20073 create the psymtab of each included file. */
20074 for (auto &file_entry
: lh
->file_names ())
20075 if (file_entry
.included_p
== 1)
20077 gdb::unique_xmalloc_ptr
<char> name_holder
;
20078 const char *include_name
=
20079 psymtab_include_file_name (lh
, file_entry
, pst
,
20080 comp_dir
, &name_holder
);
20081 if (include_name
!= NULL
)
20082 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
20087 /* Make sure a symtab is created for every file, even files
20088 which contain only variables (i.e. no code with associated
20090 buildsym_compunit
*builder
= cu
->get_builder ();
20091 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
20093 for (auto &fe
: lh
->file_names ())
20095 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
20096 if (builder
->get_current_subfile ()->symtab
== NULL
)
20098 builder
->get_current_subfile ()->symtab
20099 = allocate_symtab (cust
,
20100 builder
->get_current_subfile ()->name
);
20102 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
20107 /* Start a subfile for DWARF. FILENAME is the name of the file and
20108 DIRNAME the name of the source directory which contains FILENAME
20109 or NULL if not known.
20110 This routine tries to keep line numbers from identical absolute and
20111 relative file names in a common subfile.
20113 Using the `list' example from the GDB testsuite, which resides in
20114 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
20115 of /srcdir/list0.c yields the following debugging information for list0.c:
20117 DW_AT_name: /srcdir/list0.c
20118 DW_AT_comp_dir: /compdir
20119 files.files[0].name: list0.h
20120 files.files[0].dir: /srcdir
20121 files.files[1].name: list0.c
20122 files.files[1].dir: /srcdir
20124 The line number information for list0.c has to end up in a single
20125 subfile, so that `break /srcdir/list0.c:1' works as expected.
20126 start_subfile will ensure that this happens provided that we pass the
20127 concatenation of files.files[1].dir and files.files[1].name as the
20131 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
20132 const char *dirname
)
20134 gdb::unique_xmalloc_ptr
<char> copy
;
20136 /* In order not to lose the line information directory,
20137 we concatenate it to the filename when it makes sense.
20138 Note that the Dwarf3 standard says (speaking of filenames in line
20139 information): ``The directory index is ignored for file names
20140 that represent full path names''. Thus ignoring dirname in the
20141 `else' branch below isn't an issue. */
20143 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
20145 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
20146 filename
= copy
.get ();
20149 cu
->get_builder ()->start_subfile (filename
);
20152 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
20153 buildsym_compunit constructor. */
20155 struct compunit_symtab
*
20156 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
20159 gdb_assert (m_builder
== nullptr);
20161 m_builder
.reset (new struct buildsym_compunit
20162 (per_cu
->dwarf2_per_objfile
->objfile
,
20163 name
, comp_dir
, language
, low_pc
));
20165 list_in_scope
= get_builder ()->get_file_symbols ();
20167 get_builder ()->record_debugformat ("DWARF 2");
20168 get_builder ()->record_producer (producer
);
20170 processing_has_namespace_info
= false;
20172 return get_builder ()->get_compunit_symtab ();
20176 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
20177 struct dwarf2_cu
*cu
)
20179 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20180 struct comp_unit_head
*cu_header
= &cu
->header
;
20182 /* NOTE drow/2003-01-30: There used to be a comment and some special
20183 code here to turn a symbol with DW_AT_external and a
20184 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
20185 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
20186 with some versions of binutils) where shared libraries could have
20187 relocations against symbols in their debug information - the
20188 minimal symbol would have the right address, but the debug info
20189 would not. It's no longer necessary, because we will explicitly
20190 apply relocations when we read in the debug information now. */
20192 /* A DW_AT_location attribute with no contents indicates that a
20193 variable has been optimized away. */
20194 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0)
20196 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20200 /* Handle one degenerate form of location expression specially, to
20201 preserve GDB's previous behavior when section offsets are
20202 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
20203 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
20205 if (attr
->form_is_block ()
20206 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
20207 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
20208 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
20209 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
20210 && (DW_BLOCK (attr
)->size
20211 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
20213 unsigned int dummy
;
20215 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
20216 SET_SYMBOL_VALUE_ADDRESS
20217 (sym
, cu
->header
.read_address (objfile
->obfd
,
20218 DW_BLOCK (attr
)->data
+ 1,
20221 SET_SYMBOL_VALUE_ADDRESS
20222 (sym
, read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1,
20224 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
20225 fixup_symbol_section (sym
, objfile
);
20226 SET_SYMBOL_VALUE_ADDRESS
20228 SYMBOL_VALUE_ADDRESS (sym
)
20229 + objfile
->section_offsets
[SYMBOL_SECTION (sym
)]);
20233 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
20234 expression evaluator, and use LOC_COMPUTED only when necessary
20235 (i.e. when the value of a register or memory location is
20236 referenced, or a thread-local block, etc.). Then again, it might
20237 not be worthwhile. I'm assuming that it isn't unless performance
20238 or memory numbers show me otherwise. */
20240 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
20242 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
20243 cu
->has_loclist
= true;
20246 /* Given a pointer to a DWARF information entry, figure out if we need
20247 to make a symbol table entry for it, and if so, create a new entry
20248 and return a pointer to it.
20249 If TYPE is NULL, determine symbol type from the die, otherwise
20250 used the passed type.
20251 If SPACE is not NULL, use it to hold the new symbol. If it is
20252 NULL, allocate a new symbol on the objfile's obstack. */
20254 static struct symbol
*
20255 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
20256 struct symbol
*space
)
20258 struct dwarf2_per_objfile
*dwarf2_per_objfile
20259 = cu
->per_cu
->dwarf2_per_objfile
;
20260 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20261 struct gdbarch
*gdbarch
= objfile
->arch ();
20262 struct symbol
*sym
= NULL
;
20264 struct attribute
*attr
= NULL
;
20265 struct attribute
*attr2
= NULL
;
20266 CORE_ADDR baseaddr
;
20267 struct pending
**list_to_add
= NULL
;
20269 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
20271 baseaddr
= objfile
->text_section_offset ();
20273 name
= dwarf2_name (die
, cu
);
20276 const char *linkagename
;
20277 int suppress_add
= 0;
20282 sym
= allocate_symbol (objfile
);
20283 OBJSTAT (objfile
, n_syms
++);
20285 /* Cache this symbol's name and the name's demangled form (if any). */
20286 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
20287 linkagename
= dwarf2_physname (name
, die
, cu
);
20288 sym
->compute_and_set_names (linkagename
, false, objfile
->per_bfd
);
20290 /* Fortran does not have mangling standard and the mangling does differ
20291 between gfortran, iFort etc. */
20292 if (cu
->language
== language_fortran
20293 && symbol_get_demangled_name (sym
) == NULL
)
20294 symbol_set_demangled_name (sym
,
20295 dwarf2_full_name (name
, die
, cu
),
20298 /* Default assumptions.
20299 Use the passed type or decode it from the die. */
20300 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20301 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20303 SYMBOL_TYPE (sym
) = type
;
20305 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
20306 attr
= dwarf2_attr (die
,
20307 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
20309 if (attr
!= nullptr)
20311 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
20314 attr
= dwarf2_attr (die
,
20315 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
20317 if (attr
!= nullptr)
20319 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
20320 struct file_entry
*fe
;
20322 if (cu
->line_header
!= NULL
)
20323 fe
= cu
->line_header
->file_name_at (file_index
);
20328 complaint (_("file index out of range"));
20330 symbol_set_symtab (sym
, fe
->symtab
);
20336 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
20337 if (attr
!= nullptr)
20341 addr
= attr
->value_as_address ();
20342 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
20343 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
20345 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
20346 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
20347 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
20348 add_symbol_to_list (sym
, cu
->list_in_scope
);
20350 case DW_TAG_subprogram
:
20351 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20353 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20354 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20355 if ((attr2
&& (DW_UNSND (attr2
) != 0))
20356 || cu
->language
== language_ada
20357 || cu
->language
== language_fortran
)
20359 /* Subprograms marked external are stored as a global symbol.
20360 Ada and Fortran subprograms, whether marked external or
20361 not, are always stored as a global symbol, because we want
20362 to be able to access them globally. For instance, we want
20363 to be able to break on a nested subprogram without having
20364 to specify the context. */
20365 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20369 list_to_add
= cu
->list_in_scope
;
20372 case DW_TAG_inlined_subroutine
:
20373 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20375 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20376 SYMBOL_INLINED (sym
) = 1;
20377 list_to_add
= cu
->list_in_scope
;
20379 case DW_TAG_template_value_param
:
20381 /* Fall through. */
20382 case DW_TAG_constant
:
20383 case DW_TAG_variable
:
20384 case DW_TAG_member
:
20385 /* Compilation with minimal debug info may result in
20386 variables with missing type entries. Change the
20387 misleading `void' type to something sensible. */
20388 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
20389 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
20391 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20392 /* In the case of DW_TAG_member, we should only be called for
20393 static const members. */
20394 if (die
->tag
== DW_TAG_member
)
20396 /* dwarf2_add_field uses die_is_declaration,
20397 so we do the same. */
20398 gdb_assert (die_is_declaration (die
, cu
));
20401 if (attr
!= nullptr)
20403 dwarf2_const_value (attr
, sym
, cu
);
20404 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20407 if (attr2
&& (DW_UNSND (attr2
) != 0))
20408 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20410 list_to_add
= cu
->list_in_scope
;
20414 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20415 if (attr
!= nullptr)
20417 var_decode_location (attr
, sym
, cu
);
20418 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20420 /* Fortran explicitly imports any global symbols to the local
20421 scope by DW_TAG_common_block. */
20422 if (cu
->language
== language_fortran
&& die
->parent
20423 && die
->parent
->tag
== DW_TAG_common_block
)
20426 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20427 && SYMBOL_VALUE_ADDRESS (sym
) == 0
20428 && !dwarf2_per_objfile
->has_section_at_zero
)
20430 /* When a static variable is eliminated by the linker,
20431 the corresponding debug information is not stripped
20432 out, but the variable address is set to null;
20433 do not add such variables into symbol table. */
20435 else if (attr2
&& (DW_UNSND (attr2
) != 0))
20437 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20438 && (objfile
->flags
& OBJF_MAINLINE
) == 0
20439 && dwarf2_per_objfile
->can_copy
)
20441 /* A global static variable might be subject to
20442 copy relocation. We first check for a local
20443 minsym, though, because maybe the symbol was
20444 marked hidden, in which case this would not
20446 bound_minimal_symbol found
20447 = (lookup_minimal_symbol_linkage
20448 (sym
->linkage_name (), objfile
));
20449 if (found
.minsym
!= nullptr)
20450 sym
->maybe_copied
= 1;
20453 /* A variable with DW_AT_external is never static,
20454 but it may be block-scoped. */
20456 = ((cu
->list_in_scope
20457 == cu
->get_builder ()->get_file_symbols ())
20458 ? cu
->get_builder ()->get_global_symbols ()
20459 : cu
->list_in_scope
);
20462 list_to_add
= cu
->list_in_scope
;
20466 /* We do not know the address of this symbol.
20467 If it is an external symbol and we have type information
20468 for it, enter the symbol as a LOC_UNRESOLVED symbol.
20469 The address of the variable will then be determined from
20470 the minimal symbol table whenever the variable is
20472 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20474 /* Fortran explicitly imports any global symbols to the local
20475 scope by DW_TAG_common_block. */
20476 if (cu
->language
== language_fortran
&& die
->parent
20477 && die
->parent
->tag
== DW_TAG_common_block
)
20479 /* SYMBOL_CLASS doesn't matter here because
20480 read_common_block is going to reset it. */
20482 list_to_add
= cu
->list_in_scope
;
20484 else if (attr2
&& (DW_UNSND (attr2
) != 0)
20485 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
20487 /* A variable with DW_AT_external is never static, but it
20488 may be block-scoped. */
20490 = ((cu
->list_in_scope
20491 == cu
->get_builder ()->get_file_symbols ())
20492 ? cu
->get_builder ()->get_global_symbols ()
20493 : cu
->list_in_scope
);
20495 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
20497 else if (!die_is_declaration (die
, cu
))
20499 /* Use the default LOC_OPTIMIZED_OUT class. */
20500 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
20502 list_to_add
= cu
->list_in_scope
;
20506 case DW_TAG_formal_parameter
:
20508 /* If we are inside a function, mark this as an argument. If
20509 not, we might be looking at an argument to an inlined function
20510 when we do not have enough information to show inlined frames;
20511 pretend it's a local variable in that case so that the user can
20513 struct context_stack
*curr
20514 = cu
->get_builder ()->get_current_context_stack ();
20515 if (curr
!= nullptr && curr
->name
!= nullptr)
20516 SYMBOL_IS_ARGUMENT (sym
) = 1;
20517 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20518 if (attr
!= nullptr)
20520 var_decode_location (attr
, sym
, cu
);
20522 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20523 if (attr
!= nullptr)
20525 dwarf2_const_value (attr
, sym
, cu
);
20528 list_to_add
= cu
->list_in_scope
;
20531 case DW_TAG_unspecified_parameters
:
20532 /* From varargs functions; gdb doesn't seem to have any
20533 interest in this information, so just ignore it for now.
20536 case DW_TAG_template_type_param
:
20538 /* Fall through. */
20539 case DW_TAG_class_type
:
20540 case DW_TAG_interface_type
:
20541 case DW_TAG_structure_type
:
20542 case DW_TAG_union_type
:
20543 case DW_TAG_set_type
:
20544 case DW_TAG_enumeration_type
:
20545 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20546 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
20549 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
20550 really ever be static objects: otherwise, if you try
20551 to, say, break of a class's method and you're in a file
20552 which doesn't mention that class, it won't work unless
20553 the check for all static symbols in lookup_symbol_aux
20554 saves you. See the OtherFileClass tests in
20555 gdb.c++/namespace.exp. */
20559 buildsym_compunit
*builder
= cu
->get_builder ();
20561 = (cu
->list_in_scope
== builder
->get_file_symbols ()
20562 && cu
->language
== language_cplus
20563 ? builder
->get_global_symbols ()
20564 : cu
->list_in_scope
);
20566 /* The semantics of C++ state that "struct foo {
20567 ... }" also defines a typedef for "foo". */
20568 if (cu
->language
== language_cplus
20569 || cu
->language
== language_ada
20570 || cu
->language
== language_d
20571 || cu
->language
== language_rust
)
20573 /* The symbol's name is already allocated along
20574 with this objfile, so we don't need to
20575 duplicate it for the type. */
20576 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
20577 TYPE_NAME (SYMBOL_TYPE (sym
)) = sym
->search_name ();
20582 case DW_TAG_typedef
:
20583 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20584 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20585 list_to_add
= cu
->list_in_scope
;
20587 case DW_TAG_base_type
:
20588 case DW_TAG_subrange_type
:
20589 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20590 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20591 list_to_add
= cu
->list_in_scope
;
20593 case DW_TAG_enumerator
:
20594 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20595 if (attr
!= nullptr)
20597 dwarf2_const_value (attr
, sym
, cu
);
20600 /* NOTE: carlton/2003-11-10: See comment above in the
20601 DW_TAG_class_type, etc. block. */
20604 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
20605 && cu
->language
== language_cplus
20606 ? cu
->get_builder ()->get_global_symbols ()
20607 : cu
->list_in_scope
);
20610 case DW_TAG_imported_declaration
:
20611 case DW_TAG_namespace
:
20612 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20613 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20615 case DW_TAG_module
:
20616 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20617 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
20618 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20620 case DW_TAG_common_block
:
20621 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
20622 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
20623 add_symbol_to_list (sym
, cu
->list_in_scope
);
20626 /* Not a tag we recognize. Hopefully we aren't processing
20627 trash data, but since we must specifically ignore things
20628 we don't recognize, there is nothing else we should do at
20630 complaint (_("unsupported tag: '%s'"),
20631 dwarf_tag_name (die
->tag
));
20637 sym
->hash_next
= objfile
->template_symbols
;
20638 objfile
->template_symbols
= sym
;
20639 list_to_add
= NULL
;
20642 if (list_to_add
!= NULL
)
20643 add_symbol_to_list (sym
, list_to_add
);
20645 /* For the benefit of old versions of GCC, check for anonymous
20646 namespaces based on the demangled name. */
20647 if (!cu
->processing_has_namespace_info
20648 && cu
->language
== language_cplus
)
20649 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
20654 /* Given an attr with a DW_FORM_dataN value in host byte order,
20655 zero-extend it as appropriate for the symbol's type. The DWARF
20656 standard (v4) is not entirely clear about the meaning of using
20657 DW_FORM_dataN for a constant with a signed type, where the type is
20658 wider than the data. The conclusion of a discussion on the DWARF
20659 list was that this is unspecified. We choose to always zero-extend
20660 because that is the interpretation long in use by GCC. */
20663 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
20664 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
20666 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20667 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
20668 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
20669 LONGEST l
= DW_UNSND (attr
);
20671 if (bits
< sizeof (*value
) * 8)
20673 l
&= ((LONGEST
) 1 << bits
) - 1;
20676 else if (bits
== sizeof (*value
) * 8)
20680 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
20681 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
20688 /* Read a constant value from an attribute. Either set *VALUE, or if
20689 the value does not fit in *VALUE, set *BYTES - either already
20690 allocated on the objfile obstack, or newly allocated on OBSTACK,
20691 or, set *BATON, if we translated the constant to a location
20695 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
20696 const char *name
, struct obstack
*obstack
,
20697 struct dwarf2_cu
*cu
,
20698 LONGEST
*value
, const gdb_byte
**bytes
,
20699 struct dwarf2_locexpr_baton
**baton
)
20701 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20702 struct comp_unit_head
*cu_header
= &cu
->header
;
20703 struct dwarf_block
*blk
;
20704 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
20705 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
20711 switch (attr
->form
)
20714 case DW_FORM_addrx
:
20715 case DW_FORM_GNU_addr_index
:
20719 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
20720 dwarf2_const_value_length_mismatch_complaint (name
,
20721 cu_header
->addr_size
,
20722 TYPE_LENGTH (type
));
20723 /* Symbols of this form are reasonably rare, so we just
20724 piggyback on the existing location code rather than writing
20725 a new implementation of symbol_computed_ops. */
20726 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
20727 (*baton
)->per_cu
= cu
->per_cu
;
20728 gdb_assert ((*baton
)->per_cu
);
20730 (*baton
)->size
= 2 + cu_header
->addr_size
;
20731 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
20732 (*baton
)->data
= data
;
20734 data
[0] = DW_OP_addr
;
20735 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
20736 byte_order
, DW_ADDR (attr
));
20737 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
20740 case DW_FORM_string
:
20743 case DW_FORM_GNU_str_index
:
20744 case DW_FORM_GNU_strp_alt
:
20745 /* DW_STRING is already allocated on the objfile obstack, point
20747 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
20749 case DW_FORM_block1
:
20750 case DW_FORM_block2
:
20751 case DW_FORM_block4
:
20752 case DW_FORM_block
:
20753 case DW_FORM_exprloc
:
20754 case DW_FORM_data16
:
20755 blk
= DW_BLOCK (attr
);
20756 if (TYPE_LENGTH (type
) != blk
->size
)
20757 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
20758 TYPE_LENGTH (type
));
20759 *bytes
= blk
->data
;
20762 /* The DW_AT_const_value attributes are supposed to carry the
20763 symbol's value "represented as it would be on the target
20764 architecture." By the time we get here, it's already been
20765 converted to host endianness, so we just need to sign- or
20766 zero-extend it as appropriate. */
20767 case DW_FORM_data1
:
20768 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
20770 case DW_FORM_data2
:
20771 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
20773 case DW_FORM_data4
:
20774 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
20776 case DW_FORM_data8
:
20777 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
20780 case DW_FORM_sdata
:
20781 case DW_FORM_implicit_const
:
20782 *value
= DW_SND (attr
);
20785 case DW_FORM_udata
:
20786 *value
= DW_UNSND (attr
);
20790 complaint (_("unsupported const value attribute form: '%s'"),
20791 dwarf_form_name (attr
->form
));
20798 /* Copy constant value from an attribute to a symbol. */
20801 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
20802 struct dwarf2_cu
*cu
)
20804 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20806 const gdb_byte
*bytes
;
20807 struct dwarf2_locexpr_baton
*baton
;
20809 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
20810 sym
->print_name (),
20811 &objfile
->objfile_obstack
, cu
,
20812 &value
, &bytes
, &baton
);
20816 SYMBOL_LOCATION_BATON (sym
) = baton
;
20817 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
20819 else if (bytes
!= NULL
)
20821 SYMBOL_VALUE_BYTES (sym
) = bytes
;
20822 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
20826 SYMBOL_VALUE (sym
) = value
;
20827 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
20831 /* Return the type of the die in question using its DW_AT_type attribute. */
20833 static struct type
*
20834 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
20836 struct attribute
*type_attr
;
20838 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
20841 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20842 /* A missing DW_AT_type represents a void type. */
20843 return objfile_type (objfile
)->builtin_void
;
20846 return lookup_die_type (die
, type_attr
, cu
);
20849 /* True iff CU's producer generates GNAT Ada auxiliary information
20850 that allows to find parallel types through that information instead
20851 of having to do expensive parallel lookups by type name. */
20854 need_gnat_info (struct dwarf2_cu
*cu
)
20856 /* Assume that the Ada compiler was GNAT, which always produces
20857 the auxiliary information. */
20858 return (cu
->language
== language_ada
);
20861 /* Return the auxiliary type of the die in question using its
20862 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
20863 attribute is not present. */
20865 static struct type
*
20866 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
20868 struct attribute
*type_attr
;
20870 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
20874 return lookup_die_type (die
, type_attr
, cu
);
20877 /* If DIE has a descriptive_type attribute, then set the TYPE's
20878 descriptive type accordingly. */
20881 set_descriptive_type (struct type
*type
, struct die_info
*die
,
20882 struct dwarf2_cu
*cu
)
20884 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
20886 if (descriptive_type
)
20888 ALLOCATE_GNAT_AUX_TYPE (type
);
20889 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
20893 /* Return the containing type of the die in question using its
20894 DW_AT_containing_type attribute. */
20896 static struct type
*
20897 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
20899 struct attribute
*type_attr
;
20900 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20902 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
20904 error (_("Dwarf Error: Problem turning containing type into gdb type "
20905 "[in module %s]"), objfile_name (objfile
));
20907 return lookup_die_type (die
, type_attr
, cu
);
20910 /* Return an error marker type to use for the ill formed type in DIE/CU. */
20912 static struct type
*
20913 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
20915 struct dwarf2_per_objfile
*dwarf2_per_objfile
20916 = cu
->per_cu
->dwarf2_per_objfile
;
20917 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20920 std::string message
20921 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
20922 objfile_name (objfile
),
20923 sect_offset_str (cu
->header
.sect_off
),
20924 sect_offset_str (die
->sect_off
));
20925 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
20927 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
20930 /* Look up the type of DIE in CU using its type attribute ATTR.
20931 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
20932 DW_AT_containing_type.
20933 If there is no type substitute an error marker. */
20935 static struct type
*
20936 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
20937 struct dwarf2_cu
*cu
)
20939 struct dwarf2_per_objfile
*dwarf2_per_objfile
20940 = cu
->per_cu
->dwarf2_per_objfile
;
20941 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20942 struct type
*this_type
;
20944 gdb_assert (attr
->name
== DW_AT_type
20945 || attr
->name
== DW_AT_GNAT_descriptive_type
20946 || attr
->name
== DW_AT_containing_type
);
20948 /* First see if we have it cached. */
20950 if (attr
->form
== DW_FORM_GNU_ref_alt
)
20952 struct dwarf2_per_cu_data
*per_cu
;
20953 sect_offset sect_off
= attr
->get_ref_die_offset ();
20955 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
20956 dwarf2_per_objfile
);
20957 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
20959 else if (attr
->form_is_ref ())
20961 sect_offset sect_off
= attr
->get_ref_die_offset ();
20963 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
20965 else if (attr
->form
== DW_FORM_ref_sig8
)
20967 ULONGEST signature
= DW_SIGNATURE (attr
);
20969 return get_signatured_type (die
, signature
, cu
);
20973 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
20974 " at %s [in module %s]"),
20975 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
20976 objfile_name (objfile
));
20977 return build_error_marker_type (cu
, die
);
20980 /* If not cached we need to read it in. */
20982 if (this_type
== NULL
)
20984 struct die_info
*type_die
= NULL
;
20985 struct dwarf2_cu
*type_cu
= cu
;
20987 if (attr
->form_is_ref ())
20988 type_die
= follow_die_ref (die
, attr
, &type_cu
);
20989 if (type_die
== NULL
)
20990 return build_error_marker_type (cu
, die
);
20991 /* If we find the type now, it's probably because the type came
20992 from an inter-CU reference and the type's CU got expanded before
20994 this_type
= read_type_die (type_die
, type_cu
);
20997 /* If we still don't have a type use an error marker. */
20999 if (this_type
== NULL
)
21000 return build_error_marker_type (cu
, die
);
21005 /* Return the type in DIE, CU.
21006 Returns NULL for invalid types.
21008 This first does a lookup in die_type_hash,
21009 and only reads the die in if necessary.
21011 NOTE: This can be called when reading in partial or full symbols. */
21013 static struct type
*
21014 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
21016 struct type
*this_type
;
21018 this_type
= get_die_type (die
, cu
);
21022 return read_type_die_1 (die
, cu
);
21025 /* Read the type in DIE, CU.
21026 Returns NULL for invalid types. */
21028 static struct type
*
21029 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
21031 struct type
*this_type
= NULL
;
21035 case DW_TAG_class_type
:
21036 case DW_TAG_interface_type
:
21037 case DW_TAG_structure_type
:
21038 case DW_TAG_union_type
:
21039 this_type
= read_structure_type (die
, cu
);
21041 case DW_TAG_enumeration_type
:
21042 this_type
= read_enumeration_type (die
, cu
);
21044 case DW_TAG_subprogram
:
21045 case DW_TAG_subroutine_type
:
21046 case DW_TAG_inlined_subroutine
:
21047 this_type
= read_subroutine_type (die
, cu
);
21049 case DW_TAG_array_type
:
21050 this_type
= read_array_type (die
, cu
);
21052 case DW_TAG_set_type
:
21053 this_type
= read_set_type (die
, cu
);
21055 case DW_TAG_pointer_type
:
21056 this_type
= read_tag_pointer_type (die
, cu
);
21058 case DW_TAG_ptr_to_member_type
:
21059 this_type
= read_tag_ptr_to_member_type (die
, cu
);
21061 case DW_TAG_reference_type
:
21062 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
21064 case DW_TAG_rvalue_reference_type
:
21065 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
21067 case DW_TAG_const_type
:
21068 this_type
= read_tag_const_type (die
, cu
);
21070 case DW_TAG_volatile_type
:
21071 this_type
= read_tag_volatile_type (die
, cu
);
21073 case DW_TAG_restrict_type
:
21074 this_type
= read_tag_restrict_type (die
, cu
);
21076 case DW_TAG_string_type
:
21077 this_type
= read_tag_string_type (die
, cu
);
21079 case DW_TAG_typedef
:
21080 this_type
= read_typedef (die
, cu
);
21082 case DW_TAG_subrange_type
:
21083 this_type
= read_subrange_type (die
, cu
);
21085 case DW_TAG_base_type
:
21086 this_type
= read_base_type (die
, cu
);
21088 case DW_TAG_unspecified_type
:
21089 this_type
= read_unspecified_type (die
, cu
);
21091 case DW_TAG_namespace
:
21092 this_type
= read_namespace_type (die
, cu
);
21094 case DW_TAG_module
:
21095 this_type
= read_module_type (die
, cu
);
21097 case DW_TAG_atomic_type
:
21098 this_type
= read_tag_atomic_type (die
, cu
);
21101 complaint (_("unexpected tag in read_type_die: '%s'"),
21102 dwarf_tag_name (die
->tag
));
21109 /* See if we can figure out if the class lives in a namespace. We do
21110 this by looking for a member function; its demangled name will
21111 contain namespace info, if there is any.
21112 Return the computed name or NULL.
21113 Space for the result is allocated on the objfile's obstack.
21114 This is the full-die version of guess_partial_die_structure_name.
21115 In this case we know DIE has no useful parent. */
21117 static const char *
21118 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21120 struct die_info
*spec_die
;
21121 struct dwarf2_cu
*spec_cu
;
21122 struct die_info
*child
;
21123 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21126 spec_die
= die_specification (die
, &spec_cu
);
21127 if (spec_die
!= NULL
)
21133 for (child
= die
->child
;
21135 child
= child
->sibling
)
21137 if (child
->tag
== DW_TAG_subprogram
)
21139 const char *linkage_name
= dw2_linkage_name (child
, cu
);
21141 if (linkage_name
!= NULL
)
21143 gdb::unique_xmalloc_ptr
<char> actual_name
21144 (language_class_name_from_physname (cu
->language_defn
,
21146 const char *name
= NULL
;
21148 if (actual_name
!= NULL
)
21150 const char *die_name
= dwarf2_name (die
, cu
);
21152 if (die_name
!= NULL
21153 && strcmp (die_name
, actual_name
.get ()) != 0)
21155 /* Strip off the class name from the full name.
21156 We want the prefix. */
21157 int die_name_len
= strlen (die_name
);
21158 int actual_name_len
= strlen (actual_name
.get ());
21159 const char *ptr
= actual_name
.get ();
21161 /* Test for '::' as a sanity check. */
21162 if (actual_name_len
> die_name_len
+ 2
21163 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
21164 name
= obstack_strndup (
21165 &objfile
->per_bfd
->storage_obstack
,
21166 ptr
, actual_name_len
- die_name_len
- 2);
21177 /* GCC might emit a nameless typedef that has a linkage name. Determine the
21178 prefix part in such case. See
21179 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21181 static const char *
21182 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21184 struct attribute
*attr
;
21187 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
21188 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
21191 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
21194 attr
= dw2_linkage_name_attr (die
, cu
);
21195 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21198 /* dwarf2_name had to be already called. */
21199 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
21201 /* Strip the base name, keep any leading namespaces/classes. */
21202 base
= strrchr (DW_STRING (attr
), ':');
21203 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
21206 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21207 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
21209 &base
[-1] - DW_STRING (attr
));
21212 /* Return the name of the namespace/class that DIE is defined within,
21213 or "" if we can't tell. The caller should not xfree the result.
21215 For example, if we're within the method foo() in the following
21225 then determine_prefix on foo's die will return "N::C". */
21227 static const char *
21228 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21230 struct dwarf2_per_objfile
*dwarf2_per_objfile
21231 = cu
->per_cu
->dwarf2_per_objfile
;
21232 struct die_info
*parent
, *spec_die
;
21233 struct dwarf2_cu
*spec_cu
;
21234 struct type
*parent_type
;
21235 const char *retval
;
21237 if (cu
->language
!= language_cplus
21238 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
21239 && cu
->language
!= language_rust
)
21242 retval
= anonymous_struct_prefix (die
, cu
);
21246 /* We have to be careful in the presence of DW_AT_specification.
21247 For example, with GCC 3.4, given the code
21251 // Definition of N::foo.
21255 then we'll have a tree of DIEs like this:
21257 1: DW_TAG_compile_unit
21258 2: DW_TAG_namespace // N
21259 3: DW_TAG_subprogram // declaration of N::foo
21260 4: DW_TAG_subprogram // definition of N::foo
21261 DW_AT_specification // refers to die #3
21263 Thus, when processing die #4, we have to pretend that we're in
21264 the context of its DW_AT_specification, namely the contex of die
21267 spec_die
= die_specification (die
, &spec_cu
);
21268 if (spec_die
== NULL
)
21269 parent
= die
->parent
;
21272 parent
= spec_die
->parent
;
21276 if (parent
== NULL
)
21278 else if (parent
->building_fullname
)
21281 const char *parent_name
;
21283 /* It has been seen on RealView 2.2 built binaries,
21284 DW_TAG_template_type_param types actually _defined_ as
21285 children of the parent class:
21288 template class <class Enum> Class{};
21289 Class<enum E> class_e;
21291 1: DW_TAG_class_type (Class)
21292 2: DW_TAG_enumeration_type (E)
21293 3: DW_TAG_enumerator (enum1:0)
21294 3: DW_TAG_enumerator (enum2:1)
21296 2: DW_TAG_template_type_param
21297 DW_AT_type DW_FORM_ref_udata (E)
21299 Besides being broken debug info, it can put GDB into an
21300 infinite loop. Consider:
21302 When we're building the full name for Class<E>, we'll start
21303 at Class, and go look over its template type parameters,
21304 finding E. We'll then try to build the full name of E, and
21305 reach here. We're now trying to build the full name of E,
21306 and look over the parent DIE for containing scope. In the
21307 broken case, if we followed the parent DIE of E, we'd again
21308 find Class, and once again go look at its template type
21309 arguments, etc., etc. Simply don't consider such parent die
21310 as source-level parent of this die (it can't be, the language
21311 doesn't allow it), and break the loop here. */
21312 name
= dwarf2_name (die
, cu
);
21313 parent_name
= dwarf2_name (parent
, cu
);
21314 complaint (_("template param type '%s' defined within parent '%s'"),
21315 name
? name
: "<unknown>",
21316 parent_name
? parent_name
: "<unknown>");
21320 switch (parent
->tag
)
21322 case DW_TAG_namespace
:
21323 parent_type
= read_type_die (parent
, cu
);
21324 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
21325 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
21326 Work around this problem here. */
21327 if (cu
->language
== language_cplus
21328 && strcmp (TYPE_NAME (parent_type
), "::") == 0)
21330 /* We give a name to even anonymous namespaces. */
21331 return TYPE_NAME (parent_type
);
21332 case DW_TAG_class_type
:
21333 case DW_TAG_interface_type
:
21334 case DW_TAG_structure_type
:
21335 case DW_TAG_union_type
:
21336 case DW_TAG_module
:
21337 parent_type
= read_type_die (parent
, cu
);
21338 if (TYPE_NAME (parent_type
) != NULL
)
21339 return TYPE_NAME (parent_type
);
21341 /* An anonymous structure is only allowed non-static data
21342 members; no typedefs, no member functions, et cetera.
21343 So it does not need a prefix. */
21345 case DW_TAG_compile_unit
:
21346 case DW_TAG_partial_unit
:
21347 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
21348 if (cu
->language
== language_cplus
21349 && !dwarf2_per_objfile
->types
.empty ()
21350 && die
->child
!= NULL
21351 && (die
->tag
== DW_TAG_class_type
21352 || die
->tag
== DW_TAG_structure_type
21353 || die
->tag
== DW_TAG_union_type
))
21355 const char *name
= guess_full_die_structure_name (die
, cu
);
21360 case DW_TAG_subprogram
:
21361 /* Nested subroutines in Fortran get a prefix with the name
21362 of the parent's subroutine. */
21363 if (cu
->language
== language_fortran
)
21365 if ((die
->tag
== DW_TAG_subprogram
)
21366 && (dwarf2_name (parent
, cu
) != NULL
))
21367 return dwarf2_name (parent
, cu
);
21369 return determine_prefix (parent
, cu
);
21370 case DW_TAG_enumeration_type
:
21371 parent_type
= read_type_die (parent
, cu
);
21372 if (TYPE_DECLARED_CLASS (parent_type
))
21374 if (TYPE_NAME (parent_type
) != NULL
)
21375 return TYPE_NAME (parent_type
);
21378 /* Fall through. */
21380 return determine_prefix (parent
, cu
);
21384 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
21385 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
21386 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
21387 an obconcat, otherwise allocate storage for the result. The CU argument is
21388 used to determine the language and hence, the appropriate separator. */
21390 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
21393 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
21394 int physname
, struct dwarf2_cu
*cu
)
21396 const char *lead
= "";
21399 if (suffix
== NULL
|| suffix
[0] == '\0'
21400 || prefix
== NULL
|| prefix
[0] == '\0')
21402 else if (cu
->language
== language_d
)
21404 /* For D, the 'main' function could be defined in any module, but it
21405 should never be prefixed. */
21406 if (strcmp (suffix
, "D main") == 0)
21414 else if (cu
->language
== language_fortran
&& physname
)
21416 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
21417 DW_AT_MIPS_linkage_name is preferred and used instead. */
21425 if (prefix
== NULL
)
21427 if (suffix
== NULL
)
21434 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
21436 strcpy (retval
, lead
);
21437 strcat (retval
, prefix
);
21438 strcat (retval
, sep
);
21439 strcat (retval
, suffix
);
21444 /* We have an obstack. */
21445 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
21449 /* Get name of a die, return NULL if not found. */
21451 static const char *
21452 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
21453 struct objfile
*objfile
)
21455 if (name
&& cu
->language
== language_cplus
)
21457 std::string canon_name
= cp_canonicalize_string (name
);
21459 if (!canon_name
.empty ())
21461 if (canon_name
!= name
)
21462 name
= objfile
->intern (canon_name
);
21469 /* Get name of a die, return NULL if not found.
21470 Anonymous namespaces are converted to their magic string. */
21472 static const char *
21473 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21475 struct attribute
*attr
;
21476 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21478 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
21479 if ((!attr
|| !DW_STRING (attr
))
21480 && die
->tag
!= DW_TAG_namespace
21481 && die
->tag
!= DW_TAG_class_type
21482 && die
->tag
!= DW_TAG_interface_type
21483 && die
->tag
!= DW_TAG_structure_type
21484 && die
->tag
!= DW_TAG_union_type
)
21489 case DW_TAG_compile_unit
:
21490 case DW_TAG_partial_unit
:
21491 /* Compilation units have a DW_AT_name that is a filename, not
21492 a source language identifier. */
21493 case DW_TAG_enumeration_type
:
21494 case DW_TAG_enumerator
:
21495 /* These tags always have simple identifiers already; no need
21496 to canonicalize them. */
21497 return DW_STRING (attr
);
21499 case DW_TAG_namespace
:
21500 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
21501 return DW_STRING (attr
);
21502 return CP_ANONYMOUS_NAMESPACE_STR
;
21504 case DW_TAG_class_type
:
21505 case DW_TAG_interface_type
:
21506 case DW_TAG_structure_type
:
21507 case DW_TAG_union_type
:
21508 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
21509 structures or unions. These were of the form "._%d" in GCC 4.1,
21510 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
21511 and GCC 4.4. We work around this problem by ignoring these. */
21512 if (attr
&& DW_STRING (attr
)
21513 && (startswith (DW_STRING (attr
), "._")
21514 || startswith (DW_STRING (attr
), "<anonymous")))
21517 /* GCC might emit a nameless typedef that has a linkage name. See
21518 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21519 if (!attr
|| DW_STRING (attr
) == NULL
)
21521 attr
= dw2_linkage_name_attr (die
, cu
);
21522 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21525 /* Avoid demangling DW_STRING (attr) the second time on a second
21526 call for the same DIE. */
21527 if (!DW_STRING_IS_CANONICAL (attr
))
21529 gdb::unique_xmalloc_ptr
<char> demangled
21530 (gdb_demangle (DW_STRING (attr
), DMGL_TYPES
));
21531 if (demangled
== nullptr)
21534 DW_STRING (attr
) = objfile
->intern (demangled
.get ());
21535 DW_STRING_IS_CANONICAL (attr
) = 1;
21538 /* Strip any leading namespaces/classes, keep only the base name.
21539 DW_AT_name for named DIEs does not contain the prefixes. */
21540 const char *base
= strrchr (DW_STRING (attr
), ':');
21541 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
21544 return DW_STRING (attr
);
21552 if (!DW_STRING_IS_CANONICAL (attr
))
21554 DW_STRING (attr
) = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
21556 DW_STRING_IS_CANONICAL (attr
) = 1;
21558 return DW_STRING (attr
);
21561 /* Return the die that this die in an extension of, or NULL if there
21562 is none. *EXT_CU is the CU containing DIE on input, and the CU
21563 containing the return value on output. */
21565 static struct die_info
*
21566 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
21568 struct attribute
*attr
;
21570 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
21574 return follow_die_ref (die
, attr
, ext_cu
);
21578 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
21582 print_spaces (indent
, f
);
21583 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
21584 dwarf_tag_name (die
->tag
), die
->abbrev
,
21585 sect_offset_str (die
->sect_off
));
21587 if (die
->parent
!= NULL
)
21589 print_spaces (indent
, f
);
21590 fprintf_unfiltered (f
, " parent at offset: %s\n",
21591 sect_offset_str (die
->parent
->sect_off
));
21594 print_spaces (indent
, f
);
21595 fprintf_unfiltered (f
, " has children: %s\n",
21596 dwarf_bool_name (die
->child
!= NULL
));
21598 print_spaces (indent
, f
);
21599 fprintf_unfiltered (f
, " attributes:\n");
21601 for (i
= 0; i
< die
->num_attrs
; ++i
)
21603 print_spaces (indent
, f
);
21604 fprintf_unfiltered (f
, " %s (%s) ",
21605 dwarf_attr_name (die
->attrs
[i
].name
),
21606 dwarf_form_name (die
->attrs
[i
].form
));
21608 switch (die
->attrs
[i
].form
)
21611 case DW_FORM_addrx
:
21612 case DW_FORM_GNU_addr_index
:
21613 fprintf_unfiltered (f
, "address: ");
21614 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
21616 case DW_FORM_block2
:
21617 case DW_FORM_block4
:
21618 case DW_FORM_block
:
21619 case DW_FORM_block1
:
21620 fprintf_unfiltered (f
, "block: size %s",
21621 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
21623 case DW_FORM_exprloc
:
21624 fprintf_unfiltered (f
, "expression: size %s",
21625 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
21627 case DW_FORM_data16
:
21628 fprintf_unfiltered (f
, "constant of 16 bytes");
21630 case DW_FORM_ref_addr
:
21631 fprintf_unfiltered (f
, "ref address: ");
21632 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
21634 case DW_FORM_GNU_ref_alt
:
21635 fprintf_unfiltered (f
, "alt ref address: ");
21636 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
21642 case DW_FORM_ref_udata
:
21643 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
21644 (long) (DW_UNSND (&die
->attrs
[i
])));
21646 case DW_FORM_data1
:
21647 case DW_FORM_data2
:
21648 case DW_FORM_data4
:
21649 case DW_FORM_data8
:
21650 case DW_FORM_udata
:
21651 case DW_FORM_sdata
:
21652 fprintf_unfiltered (f
, "constant: %s",
21653 pulongest (DW_UNSND (&die
->attrs
[i
])));
21655 case DW_FORM_sec_offset
:
21656 fprintf_unfiltered (f
, "section offset: %s",
21657 pulongest (DW_UNSND (&die
->attrs
[i
])));
21659 case DW_FORM_ref_sig8
:
21660 fprintf_unfiltered (f
, "signature: %s",
21661 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
21663 case DW_FORM_string
:
21665 case DW_FORM_line_strp
:
21667 case DW_FORM_GNU_str_index
:
21668 case DW_FORM_GNU_strp_alt
:
21669 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
21670 DW_STRING (&die
->attrs
[i
])
21671 ? DW_STRING (&die
->attrs
[i
]) : "",
21672 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
21675 if (DW_UNSND (&die
->attrs
[i
]))
21676 fprintf_unfiltered (f
, "flag: TRUE");
21678 fprintf_unfiltered (f
, "flag: FALSE");
21680 case DW_FORM_flag_present
:
21681 fprintf_unfiltered (f
, "flag: TRUE");
21683 case DW_FORM_indirect
:
21684 /* The reader will have reduced the indirect form to
21685 the "base form" so this form should not occur. */
21686 fprintf_unfiltered (f
,
21687 "unexpected attribute form: DW_FORM_indirect");
21689 case DW_FORM_implicit_const
:
21690 fprintf_unfiltered (f
, "constant: %s",
21691 plongest (DW_SND (&die
->attrs
[i
])));
21694 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
21695 die
->attrs
[i
].form
);
21698 fprintf_unfiltered (f
, "\n");
21703 dump_die_for_error (struct die_info
*die
)
21705 dump_die_shallow (gdb_stderr
, 0, die
);
21709 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
21711 int indent
= level
* 4;
21713 gdb_assert (die
!= NULL
);
21715 if (level
>= max_level
)
21718 dump_die_shallow (f
, indent
, die
);
21720 if (die
->child
!= NULL
)
21722 print_spaces (indent
, f
);
21723 fprintf_unfiltered (f
, " Children:");
21724 if (level
+ 1 < max_level
)
21726 fprintf_unfiltered (f
, "\n");
21727 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
21731 fprintf_unfiltered (f
,
21732 " [not printed, max nesting level reached]\n");
21736 if (die
->sibling
!= NULL
&& level
> 0)
21738 dump_die_1 (f
, level
, max_level
, die
->sibling
);
21742 /* This is called from the pdie macro in gdbinit.in.
21743 It's not static so gcc will keep a copy callable from gdb. */
21746 dump_die (struct die_info
*die
, int max_level
)
21748 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
21752 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
21756 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
21757 to_underlying (die
->sect_off
),
21763 /* Follow reference or signature attribute ATTR of SRC_DIE.
21764 On entry *REF_CU is the CU of SRC_DIE.
21765 On exit *REF_CU is the CU of the result. */
21767 static struct die_info
*
21768 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
21769 struct dwarf2_cu
**ref_cu
)
21771 struct die_info
*die
;
21773 if (attr
->form_is_ref ())
21774 die
= follow_die_ref (src_die
, attr
, ref_cu
);
21775 else if (attr
->form
== DW_FORM_ref_sig8
)
21776 die
= follow_die_sig (src_die
, attr
, ref_cu
);
21779 dump_die_for_error (src_die
);
21780 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
21781 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
21787 /* Follow reference OFFSET.
21788 On entry *REF_CU is the CU of the source die referencing OFFSET.
21789 On exit *REF_CU is the CU of the result.
21790 Returns NULL if OFFSET is invalid. */
21792 static struct die_info
*
21793 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
21794 struct dwarf2_cu
**ref_cu
)
21796 struct die_info temp_die
;
21797 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
21798 struct dwarf2_per_objfile
*dwarf2_per_objfile
21799 = cu
->per_cu
->dwarf2_per_objfile
;
21801 gdb_assert (cu
->per_cu
!= NULL
);
21805 if (cu
->per_cu
->is_debug_types
)
21807 /* .debug_types CUs cannot reference anything outside their CU.
21808 If they need to, they have to reference a signatured type via
21809 DW_FORM_ref_sig8. */
21810 if (!cu
->header
.offset_in_cu_p (sect_off
))
21813 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
21814 || !cu
->header
.offset_in_cu_p (sect_off
))
21816 struct dwarf2_per_cu_data
*per_cu
;
21818 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
21819 dwarf2_per_objfile
);
21821 /* If necessary, add it to the queue and load its DIEs. */
21822 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
21823 load_full_comp_unit (per_cu
, false, cu
->language
);
21825 target_cu
= per_cu
->cu
;
21827 else if (cu
->dies
== NULL
)
21829 /* We're loading full DIEs during partial symbol reading. */
21830 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
21831 load_full_comp_unit (cu
->per_cu
, false, language_minimal
);
21834 *ref_cu
= target_cu
;
21835 temp_die
.sect_off
= sect_off
;
21837 if (target_cu
!= cu
)
21838 target_cu
->ancestor
= cu
;
21840 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
21842 to_underlying (sect_off
));
21845 /* Follow reference attribute ATTR of SRC_DIE.
21846 On entry *REF_CU is the CU of SRC_DIE.
21847 On exit *REF_CU is the CU of the result. */
21849 static struct die_info
*
21850 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
21851 struct dwarf2_cu
**ref_cu
)
21853 sect_offset sect_off
= attr
->get_ref_die_offset ();
21854 struct dwarf2_cu
*cu
= *ref_cu
;
21855 struct die_info
*die
;
21857 die
= follow_die_offset (sect_off
,
21858 (attr
->form
== DW_FORM_GNU_ref_alt
21859 || cu
->per_cu
->is_dwz
),
21862 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
21863 "at %s [in module %s]"),
21864 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
21865 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
21872 struct dwarf2_locexpr_baton
21873 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
21874 dwarf2_per_cu_data
*per_cu
,
21875 CORE_ADDR (*get_frame_pc
) (void *baton
),
21876 void *baton
, bool resolve_abstract_p
)
21878 struct dwarf2_cu
*cu
;
21879 struct die_info
*die
;
21880 struct attribute
*attr
;
21881 struct dwarf2_locexpr_baton retval
;
21882 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
21883 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21885 if (per_cu
->cu
== NULL
)
21886 load_cu (per_cu
, false);
21890 /* We shouldn't get here for a dummy CU, but don't crash on the user.
21891 Instead just throw an error, not much else we can do. */
21892 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
21893 sect_offset_str (sect_off
), objfile_name (objfile
));
21896 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
21898 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
21899 sect_offset_str (sect_off
), objfile_name (objfile
));
21901 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21902 if (!attr
&& resolve_abstract_p
21903 && (dwarf2_per_objfile
->abstract_to_concrete
.find (die
->sect_off
)
21904 != dwarf2_per_objfile
->abstract_to_concrete
.end ()))
21906 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
21907 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
21908 struct gdbarch
*gdbarch
= objfile
->arch ();
21910 for (const auto &cand_off
21911 : dwarf2_per_objfile
->abstract_to_concrete
[die
->sect_off
])
21913 struct dwarf2_cu
*cand_cu
= cu
;
21914 struct die_info
*cand
21915 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
21918 || cand
->parent
->tag
!= DW_TAG_subprogram
)
21921 CORE_ADDR pc_low
, pc_high
;
21922 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
21923 if (pc_low
== ((CORE_ADDR
) -1))
21925 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
21926 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
21927 if (!(pc_low
<= pc
&& pc
< pc_high
))
21931 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21938 /* DWARF: "If there is no such attribute, then there is no effect.".
21939 DATA is ignored if SIZE is 0. */
21941 retval
.data
= NULL
;
21944 else if (attr
->form_is_section_offset ())
21946 struct dwarf2_loclist_baton loclist_baton
;
21947 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
21950 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
21952 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
21954 retval
.size
= size
;
21958 if (!attr
->form_is_block ())
21959 error (_("Dwarf Error: DIE at %s referenced in module %s "
21960 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
21961 sect_offset_str (sect_off
), objfile_name (objfile
));
21963 retval
.data
= DW_BLOCK (attr
)->data
;
21964 retval
.size
= DW_BLOCK (attr
)->size
;
21966 retval
.per_cu
= cu
->per_cu
;
21968 age_cached_comp_units (dwarf2_per_objfile
);
21975 struct dwarf2_locexpr_baton
21976 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
21977 dwarf2_per_cu_data
*per_cu
,
21978 CORE_ADDR (*get_frame_pc
) (void *baton
),
21981 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
21983 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
21986 /* Write a constant of a given type as target-ordered bytes into
21989 static const gdb_byte
*
21990 write_constant_as_bytes (struct obstack
*obstack
,
21991 enum bfd_endian byte_order
,
21998 *len
= TYPE_LENGTH (type
);
21999 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22000 store_unsigned_integer (result
, *len
, byte_order
, value
);
22008 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
22009 dwarf2_per_cu_data
*per_cu
,
22013 struct dwarf2_cu
*cu
;
22014 struct die_info
*die
;
22015 struct attribute
*attr
;
22016 const gdb_byte
*result
= NULL
;
22019 enum bfd_endian byte_order
;
22020 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
22022 if (per_cu
->cu
== NULL
)
22023 load_cu (per_cu
, false);
22027 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22028 Instead just throw an error, not much else we can do. */
22029 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
22030 sect_offset_str (sect_off
), objfile_name (objfile
));
22033 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22035 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
22036 sect_offset_str (sect_off
), objfile_name (objfile
));
22038 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22042 byte_order
= (bfd_big_endian (objfile
->obfd
)
22043 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22045 switch (attr
->form
)
22048 case DW_FORM_addrx
:
22049 case DW_FORM_GNU_addr_index
:
22053 *len
= cu
->header
.addr_size
;
22054 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
22055 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
22059 case DW_FORM_string
:
22062 case DW_FORM_GNU_str_index
:
22063 case DW_FORM_GNU_strp_alt
:
22064 /* DW_STRING is already allocated on the objfile obstack, point
22066 result
= (const gdb_byte
*) DW_STRING (attr
);
22067 *len
= strlen (DW_STRING (attr
));
22069 case DW_FORM_block1
:
22070 case DW_FORM_block2
:
22071 case DW_FORM_block4
:
22072 case DW_FORM_block
:
22073 case DW_FORM_exprloc
:
22074 case DW_FORM_data16
:
22075 result
= DW_BLOCK (attr
)->data
;
22076 *len
= DW_BLOCK (attr
)->size
;
22079 /* The DW_AT_const_value attributes are supposed to carry the
22080 symbol's value "represented as it would be on the target
22081 architecture." By the time we get here, it's already been
22082 converted to host endianness, so we just need to sign- or
22083 zero-extend it as appropriate. */
22084 case DW_FORM_data1
:
22085 type
= die_type (die
, cu
);
22086 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
22087 if (result
== NULL
)
22088 result
= write_constant_as_bytes (obstack
, byte_order
,
22091 case DW_FORM_data2
:
22092 type
= die_type (die
, cu
);
22093 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
22094 if (result
== NULL
)
22095 result
= write_constant_as_bytes (obstack
, byte_order
,
22098 case DW_FORM_data4
:
22099 type
= die_type (die
, cu
);
22100 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
22101 if (result
== NULL
)
22102 result
= write_constant_as_bytes (obstack
, byte_order
,
22105 case DW_FORM_data8
:
22106 type
= die_type (die
, cu
);
22107 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
22108 if (result
== NULL
)
22109 result
= write_constant_as_bytes (obstack
, byte_order
,
22113 case DW_FORM_sdata
:
22114 case DW_FORM_implicit_const
:
22115 type
= die_type (die
, cu
);
22116 result
= write_constant_as_bytes (obstack
, byte_order
,
22117 type
, DW_SND (attr
), len
);
22120 case DW_FORM_udata
:
22121 type
= die_type (die
, cu
);
22122 result
= write_constant_as_bytes (obstack
, byte_order
,
22123 type
, DW_UNSND (attr
), len
);
22127 complaint (_("unsupported const value attribute form: '%s'"),
22128 dwarf_form_name (attr
->form
));
22138 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
22139 dwarf2_per_cu_data
*per_cu
)
22141 struct dwarf2_cu
*cu
;
22142 struct die_info
*die
;
22144 if (per_cu
->cu
== NULL
)
22145 load_cu (per_cu
, false);
22150 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22154 return die_type (die
, cu
);
22160 dwarf2_get_die_type (cu_offset die_offset
,
22161 struct dwarf2_per_cu_data
*per_cu
)
22163 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
22164 return get_die_type_at_offset (die_offset_sect
, per_cu
);
22167 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
22168 On entry *REF_CU is the CU of SRC_DIE.
22169 On exit *REF_CU is the CU of the result.
22170 Returns NULL if the referenced DIE isn't found. */
22172 static struct die_info
*
22173 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
22174 struct dwarf2_cu
**ref_cu
)
22176 struct die_info temp_die
;
22177 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
22178 struct die_info
*die
;
22180 /* While it might be nice to assert sig_type->type == NULL here,
22181 we can get here for DW_AT_imported_declaration where we need
22182 the DIE not the type. */
22184 /* If necessary, add it to the queue and load its DIEs. */
22186 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
22187 read_signatured_type (sig_type
);
22189 sig_cu
= sig_type
->per_cu
.cu
;
22190 gdb_assert (sig_cu
!= NULL
);
22191 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
22192 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
22193 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
22194 to_underlying (temp_die
.sect_off
));
22197 struct dwarf2_per_objfile
*dwarf2_per_objfile
22198 = (*ref_cu
)->per_cu
->dwarf2_per_objfile
;
22200 /* For .gdb_index version 7 keep track of included TUs.
22201 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
22202 if (dwarf2_per_objfile
->index_table
!= NULL
22203 && dwarf2_per_objfile
->index_table
->version
<= 7)
22205 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
22210 sig_cu
->ancestor
= cu
;
22218 /* Follow signatured type referenced by ATTR in SRC_DIE.
22219 On entry *REF_CU is the CU of SRC_DIE.
22220 On exit *REF_CU is the CU of the result.
22221 The result is the DIE of the type.
22222 If the referenced type cannot be found an error is thrown. */
22224 static struct die_info
*
22225 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22226 struct dwarf2_cu
**ref_cu
)
22228 ULONGEST signature
= DW_SIGNATURE (attr
);
22229 struct signatured_type
*sig_type
;
22230 struct die_info
*die
;
22232 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
22234 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
22235 /* sig_type will be NULL if the signatured type is missing from
22237 if (sig_type
== NULL
)
22239 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22240 " from DIE at %s [in module %s]"),
22241 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22242 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22245 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
22248 dump_die_for_error (src_die
);
22249 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22250 " from DIE at %s [in module %s]"),
22251 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22252 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22258 /* Get the type specified by SIGNATURE referenced in DIE/CU,
22259 reading in and processing the type unit if necessary. */
22261 static struct type
*
22262 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
22263 struct dwarf2_cu
*cu
)
22265 struct dwarf2_per_objfile
*dwarf2_per_objfile
22266 = cu
->per_cu
->dwarf2_per_objfile
;
22267 struct signatured_type
*sig_type
;
22268 struct dwarf2_cu
*type_cu
;
22269 struct die_info
*type_die
;
22272 sig_type
= lookup_signatured_type (cu
, signature
);
22273 /* sig_type will be NULL if the signatured type is missing from
22275 if (sig_type
== NULL
)
22277 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22278 " from DIE at %s [in module %s]"),
22279 hex_string (signature
), sect_offset_str (die
->sect_off
),
22280 objfile_name (dwarf2_per_objfile
->objfile
));
22281 return build_error_marker_type (cu
, die
);
22284 /* If we already know the type we're done. */
22285 if (sig_type
->type
!= NULL
)
22286 return sig_type
->type
;
22289 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
22290 if (type_die
!= NULL
)
22292 /* N.B. We need to call get_die_type to ensure only one type for this DIE
22293 is created. This is important, for example, because for c++ classes
22294 we need TYPE_NAME set which is only done by new_symbol. Blech. */
22295 type
= read_type_die (type_die
, type_cu
);
22298 complaint (_("Dwarf Error: Cannot build signatured type %s"
22299 " referenced from DIE at %s [in module %s]"),
22300 hex_string (signature
), sect_offset_str (die
->sect_off
),
22301 objfile_name (dwarf2_per_objfile
->objfile
));
22302 type
= build_error_marker_type (cu
, die
);
22307 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22308 " from DIE at %s [in module %s]"),
22309 hex_string (signature
), sect_offset_str (die
->sect_off
),
22310 objfile_name (dwarf2_per_objfile
->objfile
));
22311 type
= build_error_marker_type (cu
, die
);
22313 sig_type
->type
= type
;
22318 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
22319 reading in and processing the type unit if necessary. */
22321 static struct type
*
22322 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
22323 struct dwarf2_cu
*cu
) /* ARI: editCase function */
22325 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
22326 if (attr
->form_is_ref ())
22328 struct dwarf2_cu
*type_cu
= cu
;
22329 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
22331 return read_type_die (type_die
, type_cu
);
22333 else if (attr
->form
== DW_FORM_ref_sig8
)
22335 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
22339 struct dwarf2_per_objfile
*dwarf2_per_objfile
22340 = cu
->per_cu
->dwarf2_per_objfile
;
22342 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
22343 " at %s [in module %s]"),
22344 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
22345 objfile_name (dwarf2_per_objfile
->objfile
));
22346 return build_error_marker_type (cu
, die
);
22350 /* Load the DIEs associated with type unit PER_CU into memory. */
22353 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
22355 struct signatured_type
*sig_type
;
22357 /* Caller is responsible for ensuring type_unit_groups don't get here. */
22358 gdb_assert (! per_cu
->type_unit_group_p ());
22360 /* We have the per_cu, but we need the signatured_type.
22361 Fortunately this is an easy translation. */
22362 gdb_assert (per_cu
->is_debug_types
);
22363 sig_type
= (struct signatured_type
*) per_cu
;
22365 gdb_assert (per_cu
->cu
== NULL
);
22367 read_signatured_type (sig_type
);
22369 gdb_assert (per_cu
->cu
!= NULL
);
22372 /* Read in a signatured type and build its CU and DIEs.
22373 If the type is a stub for the real type in a DWO file,
22374 read in the real type from the DWO file as well. */
22377 read_signatured_type (struct signatured_type
*sig_type
)
22379 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
22381 gdb_assert (per_cu
->is_debug_types
);
22382 gdb_assert (per_cu
->cu
== NULL
);
22384 cutu_reader
reader (per_cu
, NULL
, 0, false);
22386 if (!reader
.dummy_p
)
22388 struct dwarf2_cu
*cu
= reader
.cu
;
22389 const gdb_byte
*info_ptr
= reader
.info_ptr
;
22391 gdb_assert (cu
->die_hash
== NULL
);
22393 htab_create_alloc_ex (cu
->header
.length
/ 12,
22397 &cu
->comp_unit_obstack
,
22398 hashtab_obstack_allocate
,
22399 dummy_obstack_deallocate
);
22401 if (reader
.comp_unit_die
->has_children
)
22402 reader
.comp_unit_die
->child
22403 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
22404 reader
.comp_unit_die
);
22405 cu
->dies
= reader
.comp_unit_die
;
22406 /* comp_unit_die is not stored in die_hash, no need. */
22408 /* We try not to read any attributes in this function, because
22409 not all CUs needed for references have been loaded yet, and
22410 symbol table processing isn't initialized. But we have to
22411 set the CU language, or we won't be able to build types
22412 correctly. Similarly, if we do not read the producer, we can
22413 not apply producer-specific interpretation. */
22414 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
22419 sig_type
->per_cu
.tu_read
= 1;
22422 /* Decode simple location descriptions.
22423 Given a pointer to a dwarf block that defines a location, compute
22424 the location and return the value.
22426 NOTE drow/2003-11-18: This function is called in two situations
22427 now: for the address of static or global variables (partial symbols
22428 only) and for offsets into structures which are expected to be
22429 (more or less) constant. The partial symbol case should go away,
22430 and only the constant case should remain. That will let this
22431 function complain more accurately. A few special modes are allowed
22432 without complaint for global variables (for instance, global
22433 register values and thread-local values).
22435 A location description containing no operations indicates that the
22436 object is optimized out. The return value is 0 for that case.
22437 FIXME drow/2003-11-16: No callers check for this case any more; soon all
22438 callers will only want a very basic result and this can become a
22441 Note that stack[0] is unused except as a default error return. */
22444 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
22446 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22448 size_t size
= blk
->size
;
22449 const gdb_byte
*data
= blk
->data
;
22450 CORE_ADDR stack
[64];
22452 unsigned int bytes_read
, unsnd
;
22458 stack
[++stacki
] = 0;
22497 stack
[++stacki
] = op
- DW_OP_lit0
;
22532 stack
[++stacki
] = op
- DW_OP_reg0
;
22534 dwarf2_complex_location_expr_complaint ();
22538 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
22540 stack
[++stacki
] = unsnd
;
22542 dwarf2_complex_location_expr_complaint ();
22546 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
22551 case DW_OP_const1u
:
22552 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
22556 case DW_OP_const1s
:
22557 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
22561 case DW_OP_const2u
:
22562 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
22566 case DW_OP_const2s
:
22567 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
22571 case DW_OP_const4u
:
22572 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
22576 case DW_OP_const4s
:
22577 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
22581 case DW_OP_const8u
:
22582 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
22587 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
22593 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
22598 stack
[stacki
+ 1] = stack
[stacki
];
22603 stack
[stacki
- 1] += stack
[stacki
];
22607 case DW_OP_plus_uconst
:
22608 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
22614 stack
[stacki
- 1] -= stack
[stacki
];
22619 /* If we're not the last op, then we definitely can't encode
22620 this using GDB's address_class enum. This is valid for partial
22621 global symbols, although the variable's address will be bogus
22624 dwarf2_complex_location_expr_complaint ();
22627 case DW_OP_GNU_push_tls_address
:
22628 case DW_OP_form_tls_address
:
22629 /* The top of the stack has the offset from the beginning
22630 of the thread control block at which the variable is located. */
22631 /* Nothing should follow this operator, so the top of stack would
22633 /* This is valid for partial global symbols, but the variable's
22634 address will be bogus in the psymtab. Make it always at least
22635 non-zero to not look as a variable garbage collected by linker
22636 which have DW_OP_addr 0. */
22638 dwarf2_complex_location_expr_complaint ();
22642 case DW_OP_GNU_uninit
:
22646 case DW_OP_GNU_addr_index
:
22647 case DW_OP_GNU_const_index
:
22648 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
22655 const char *name
= get_DW_OP_name (op
);
22658 complaint (_("unsupported stack op: '%s'"),
22661 complaint (_("unsupported stack op: '%02x'"),
22665 return (stack
[stacki
]);
22668 /* Enforce maximum stack depth of SIZE-1 to avoid writing
22669 outside of the allocated space. Also enforce minimum>0. */
22670 if (stacki
>= ARRAY_SIZE (stack
) - 1)
22672 complaint (_("location description stack overflow"));
22678 complaint (_("location description stack underflow"));
22682 return (stack
[stacki
]);
22685 /* memory allocation interface */
22687 static struct dwarf_block
*
22688 dwarf_alloc_block (struct dwarf2_cu
*cu
)
22690 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
22693 static struct die_info
*
22694 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
22696 struct die_info
*die
;
22697 size_t size
= sizeof (struct die_info
);
22700 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
22702 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
22703 memset (die
, 0, sizeof (struct die_info
));
22709 /* Macro support. */
22711 /* An overload of dwarf_decode_macros that finds the correct section
22712 and ensures it is read in before calling the other overload. */
22715 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
22716 int section_is_gnu
)
22718 struct dwarf2_per_objfile
*dwarf2_per_objfile
22719 = cu
->per_cu
->dwarf2_per_objfile
;
22720 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22721 const struct line_header
*lh
= cu
->line_header
;
22722 unsigned int offset_size
= cu
->header
.offset_size
;
22723 struct dwarf2_section_info
*section
;
22724 const char *section_name
;
22726 if (cu
->dwo_unit
!= nullptr)
22728 if (section_is_gnu
)
22730 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
22731 section_name
= ".debug_macro.dwo";
22735 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
22736 section_name
= ".debug_macinfo.dwo";
22741 if (section_is_gnu
)
22743 section
= &dwarf2_per_objfile
->macro
;
22744 section_name
= ".debug_macro";
22748 section
= &dwarf2_per_objfile
->macinfo
;
22749 section_name
= ".debug_macinfo";
22753 section
->read (objfile
);
22754 if (section
->buffer
== nullptr)
22756 complaint (_("missing %s section"), section_name
);
22760 buildsym_compunit
*builder
= cu
->get_builder ();
22762 dwarf_decode_macros (dwarf2_per_objfile
, builder
, section
, lh
,
22763 offset_size
, offset
, section_is_gnu
);
22766 /* Return the .debug_loc section to use for CU.
22767 For DWO files use .debug_loc.dwo. */
22769 static struct dwarf2_section_info
*
22770 cu_debug_loc_section (struct dwarf2_cu
*cu
)
22772 struct dwarf2_per_objfile
*dwarf2_per_objfile
22773 = cu
->per_cu
->dwarf2_per_objfile
;
22777 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
22779 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
22781 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
22782 : &dwarf2_per_objfile
->loc
);
22785 /* A helper function that fills in a dwarf2_loclist_baton. */
22788 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
22789 struct dwarf2_loclist_baton
*baton
,
22790 const struct attribute
*attr
)
22792 struct dwarf2_per_objfile
*dwarf2_per_objfile
22793 = cu
->per_cu
->dwarf2_per_objfile
;
22794 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
22796 section
->read (dwarf2_per_objfile
->objfile
);
22798 baton
->per_cu
= cu
->per_cu
;
22799 gdb_assert (baton
->per_cu
);
22800 /* We don't know how long the location list is, but make sure we
22801 don't run off the edge of the section. */
22802 baton
->size
= section
->size
- DW_UNSND (attr
);
22803 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
22804 if (cu
->base_address
.has_value ())
22805 baton
->base_address
= *cu
->base_address
;
22807 baton
->base_address
= 0;
22808 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
22812 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
22813 struct dwarf2_cu
*cu
, int is_block
)
22815 struct dwarf2_per_objfile
*dwarf2_per_objfile
22816 = cu
->per_cu
->dwarf2_per_objfile
;
22817 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22818 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
22820 if (attr
->form_is_section_offset ()
22821 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
22822 the section. If so, fall through to the complaint in the
22824 && DW_UNSND (attr
) < section
->get_size (objfile
))
22826 struct dwarf2_loclist_baton
*baton
;
22828 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
22830 fill_in_loclist_baton (cu
, baton
, attr
);
22832 if (!cu
->base_address
.has_value ())
22833 complaint (_("Location list used without "
22834 "specifying the CU base address."));
22836 SYMBOL_ACLASS_INDEX (sym
) = (is_block
22837 ? dwarf2_loclist_block_index
22838 : dwarf2_loclist_index
);
22839 SYMBOL_LOCATION_BATON (sym
) = baton
;
22843 struct dwarf2_locexpr_baton
*baton
;
22845 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
22846 baton
->per_cu
= cu
->per_cu
;
22847 gdb_assert (baton
->per_cu
);
22849 if (attr
->form_is_block ())
22851 /* Note that we're just copying the block's data pointer
22852 here, not the actual data. We're still pointing into the
22853 info_buffer for SYM's objfile; right now we never release
22854 that buffer, but when we do clean up properly this may
22856 baton
->size
= DW_BLOCK (attr
)->size
;
22857 baton
->data
= DW_BLOCK (attr
)->data
;
22861 dwarf2_invalid_attrib_class_complaint ("location description",
22862 sym
->natural_name ());
22866 SYMBOL_ACLASS_INDEX (sym
) = (is_block
22867 ? dwarf2_locexpr_block_index
22868 : dwarf2_locexpr_index
);
22869 SYMBOL_LOCATION_BATON (sym
) = baton
;
22876 dwarf2_per_cu_data::objfile () const
22878 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22880 /* Return the master objfile, so that we can report and look up the
22881 correct file containing this variable. */
22882 if (objfile
->separate_debug_objfile_backlink
)
22883 objfile
= objfile
->separate_debug_objfile_backlink
;
22888 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
22889 (CU_HEADERP is unused in such case) or prepare a temporary copy at
22890 CU_HEADERP first. */
22892 static const struct comp_unit_head
*
22893 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
22894 const struct dwarf2_per_cu_data
*per_cu
)
22896 const gdb_byte
*info_ptr
;
22899 return &per_cu
->cu
->header
;
22901 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
22903 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
22904 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
22905 rcuh_kind::COMPILE
);
22913 dwarf2_per_cu_data::addr_size () const
22915 struct comp_unit_head cu_header_local
;
22916 const struct comp_unit_head
*cu_headerp
;
22918 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
22920 return cu_headerp
->addr_size
;
22926 dwarf2_per_cu_data::offset_size () const
22928 struct comp_unit_head cu_header_local
;
22929 const struct comp_unit_head
*cu_headerp
;
22931 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
22933 return cu_headerp
->offset_size
;
22939 dwarf2_per_cu_data::ref_addr_size () const
22941 struct comp_unit_head cu_header_local
;
22942 const struct comp_unit_head
*cu_headerp
;
22944 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
22946 if (cu_headerp
->version
== 2)
22947 return cu_headerp
->addr_size
;
22949 return cu_headerp
->offset_size
;
22955 dwarf2_per_cu_data::text_offset () const
22957 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22959 return objfile
->text_section_offset ();
22965 dwarf2_per_cu_data::addr_type () const
22967 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22968 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
22969 struct type
*addr_type
= lookup_pointer_type (void_type
);
22970 int addr_size
= this->addr_size ();
22972 if (TYPE_LENGTH (addr_type
) == addr_size
)
22975 addr_type
= addr_sized_int_type (TYPE_UNSIGNED (addr_type
));
22979 /* A helper function for dwarf2_find_containing_comp_unit that returns
22980 the index of the result, and that searches a vector. It will
22981 return a result even if the offset in question does not actually
22982 occur in any CU. This is separate so that it can be unit
22986 dwarf2_find_containing_comp_unit
22987 (sect_offset sect_off
,
22988 unsigned int offset_in_dwz
,
22989 const std::vector
<dwarf2_per_cu_data
*> &all_comp_units
)
22994 high
= all_comp_units
.size () - 1;
22997 struct dwarf2_per_cu_data
*mid_cu
;
22998 int mid
= low
+ (high
- low
) / 2;
23000 mid_cu
= all_comp_units
[mid
];
23001 if (mid_cu
->is_dwz
> offset_in_dwz
23002 || (mid_cu
->is_dwz
== offset_in_dwz
23003 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
23008 gdb_assert (low
== high
);
23012 /* Locate the .debug_info compilation unit from CU's objfile which contains
23013 the DIE at OFFSET. Raises an error on failure. */
23015 static struct dwarf2_per_cu_data
*
23016 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
23017 unsigned int offset_in_dwz
,
23018 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
23021 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23022 dwarf2_per_objfile
->all_comp_units
);
23023 struct dwarf2_per_cu_data
*this_cu
23024 = dwarf2_per_objfile
->all_comp_units
[low
];
23026 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
23028 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
23029 error (_("Dwarf Error: could not find partial DIE containing "
23030 "offset %s [in module %s]"),
23031 sect_offset_str (sect_off
),
23032 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
23034 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
23036 return dwarf2_per_objfile
->all_comp_units
[low
-1];
23040 if (low
== dwarf2_per_objfile
->all_comp_units
.size () - 1
23041 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
23042 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
23043 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
23050 namespace selftests
{
23051 namespace find_containing_comp_unit
{
23056 struct dwarf2_per_cu_data one
{};
23057 struct dwarf2_per_cu_data two
{};
23058 struct dwarf2_per_cu_data three
{};
23059 struct dwarf2_per_cu_data four
{};
23062 two
.sect_off
= sect_offset (one
.length
);
23067 four
.sect_off
= sect_offset (three
.length
);
23071 std::vector
<dwarf2_per_cu_data
*> units
;
23072 units
.push_back (&one
);
23073 units
.push_back (&two
);
23074 units
.push_back (&three
);
23075 units
.push_back (&four
);
23079 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
23080 SELF_CHECK (units
[result
] == &one
);
23081 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
23082 SELF_CHECK (units
[result
] == &one
);
23083 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
23084 SELF_CHECK (units
[result
] == &two
);
23086 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
23087 SELF_CHECK (units
[result
] == &three
);
23088 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
23089 SELF_CHECK (units
[result
] == &three
);
23090 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
23091 SELF_CHECK (units
[result
] == &four
);
23097 #endif /* GDB_SELF_TEST */
23099 /* Initialize dwarf2_cu CU, owned by PER_CU. */
23101 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data
*per_cu_
)
23102 : per_cu (per_cu_
),
23104 has_loclist (false),
23105 checked_producer (false),
23106 producer_is_gxx_lt_4_6 (false),
23107 producer_is_gcc_lt_4_3 (false),
23108 producer_is_icc (false),
23109 producer_is_icc_lt_14 (false),
23110 producer_is_codewarrior (false),
23111 processing_has_namespace_info (false)
23116 /* Destroy a dwarf2_cu. */
23118 dwarf2_cu::~dwarf2_cu ()
23123 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
23126 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
23127 enum language pretend_language
)
23129 struct attribute
*attr
;
23131 /* Set the language we're debugging. */
23132 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
23133 if (attr
!= nullptr)
23134 set_cu_language (DW_UNSND (attr
), cu
);
23137 cu
->language
= pretend_language
;
23138 cu
->language_defn
= language_def (cu
->language
);
23141 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
23144 /* Increase the age counter on each cached compilation unit, and free
23145 any that are too old. */
23148 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
23150 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
23152 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
23153 per_cu
= dwarf2_per_objfile
->read_in_chain
;
23154 while (per_cu
!= NULL
)
23156 per_cu
->cu
->last_used
++;
23157 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
23158 dwarf2_mark (per_cu
->cu
);
23159 per_cu
= per_cu
->cu
->read_in_chain
;
23162 per_cu
= dwarf2_per_objfile
->read_in_chain
;
23163 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
23164 while (per_cu
!= NULL
)
23166 struct dwarf2_per_cu_data
*next_cu
;
23168 next_cu
= per_cu
->cu
->read_in_chain
;
23170 if (!per_cu
->cu
->mark
)
23173 *last_chain
= next_cu
;
23176 last_chain
= &per_cu
->cu
->read_in_chain
;
23182 /* Remove a single compilation unit from the cache. */
23185 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
23187 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
23188 struct dwarf2_per_objfile
*dwarf2_per_objfile
23189 = target_per_cu
->dwarf2_per_objfile
;
23191 per_cu
= dwarf2_per_objfile
->read_in_chain
;
23192 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
23193 while (per_cu
!= NULL
)
23195 struct dwarf2_per_cu_data
*next_cu
;
23197 next_cu
= per_cu
->cu
->read_in_chain
;
23199 if (per_cu
== target_per_cu
)
23203 *last_chain
= next_cu
;
23207 last_chain
= &per_cu
->cu
->read_in_chain
;
23213 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
23214 We store these in a hash table separate from the DIEs, and preserve them
23215 when the DIEs are flushed out of cache.
23217 The CU "per_cu" pointer is needed because offset alone is not enough to
23218 uniquely identify the type. A file may have multiple .debug_types sections,
23219 or the type may come from a DWO file. Furthermore, while it's more logical
23220 to use per_cu->section+offset, with Fission the section with the data is in
23221 the DWO file but we don't know that section at the point we need it.
23222 We have to use something in dwarf2_per_cu_data (or the pointer to it)
23223 because we can enter the lookup routine, get_die_type_at_offset, from
23224 outside this file, and thus won't necessarily have PER_CU->cu.
23225 Fortunately, PER_CU is stable for the life of the objfile. */
23227 struct dwarf2_per_cu_offset_and_type
23229 const struct dwarf2_per_cu_data
*per_cu
;
23230 sect_offset sect_off
;
23234 /* Hash function for a dwarf2_per_cu_offset_and_type. */
23237 per_cu_offset_and_type_hash (const void *item
)
23239 const struct dwarf2_per_cu_offset_and_type
*ofs
23240 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
23242 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
23245 /* Equality function for a dwarf2_per_cu_offset_and_type. */
23248 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
23250 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
23251 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
23252 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
23253 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
23255 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
23256 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
23259 /* Set the type associated with DIE to TYPE. Save it in CU's hash
23260 table if necessary. For convenience, return TYPE.
23262 The DIEs reading must have careful ordering to:
23263 * Not cause infinite loops trying to read in DIEs as a prerequisite for
23264 reading current DIE.
23265 * Not trying to dereference contents of still incompletely read in types
23266 while reading in other DIEs.
23267 * Enable referencing still incompletely read in types just by a pointer to
23268 the type without accessing its fields.
23270 Therefore caller should follow these rules:
23271 * Try to fetch any prerequisite types we may need to build this DIE type
23272 before building the type and calling set_die_type.
23273 * After building type call set_die_type for current DIE as soon as
23274 possible before fetching more types to complete the current type.
23275 * Make the type as complete as possible before fetching more types. */
23277 static struct type
*
23278 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
23280 struct dwarf2_per_objfile
*dwarf2_per_objfile
23281 = cu
->per_cu
->dwarf2_per_objfile
;
23282 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
23283 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23284 struct attribute
*attr
;
23285 struct dynamic_prop prop
;
23287 /* For Ada types, make sure that the gnat-specific data is always
23288 initialized (if not already set). There are a few types where
23289 we should not be doing so, because the type-specific area is
23290 already used to hold some other piece of info (eg: TYPE_CODE_FLT
23291 where the type-specific area is used to store the floatformat).
23292 But this is not a problem, because the gnat-specific information
23293 is actually not needed for these types. */
23294 if (need_gnat_info (cu
)
23295 && TYPE_CODE (type
) != TYPE_CODE_FUNC
23296 && TYPE_CODE (type
) != TYPE_CODE_FLT
23297 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
23298 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
23299 && TYPE_CODE (type
) != TYPE_CODE_METHOD
23300 && !HAVE_GNAT_AUX_INFO (type
))
23301 INIT_GNAT_SPECIFIC (type
);
23303 /* Read DW_AT_allocated and set in type. */
23304 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
23305 if (attr
!= NULL
&& attr
->form_is_block ())
23307 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
23308 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23309 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
);
23311 else if (attr
!= NULL
)
23313 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
23314 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23315 sect_offset_str (die
->sect_off
));
23318 /* Read DW_AT_associated and set in type. */
23319 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
23320 if (attr
!= NULL
&& attr
->form_is_block ())
23322 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
23323 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23324 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
);
23326 else if (attr
!= NULL
)
23328 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
23329 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23330 sect_offset_str (die
->sect_off
));
23333 /* Read DW_AT_data_location and set in type. */
23334 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
23335 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
,
23336 cu
->per_cu
->addr_type ()))
23337 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
);
23339 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
23340 dwarf2_per_objfile
->die_type_hash
23341 = htab_up (htab_create_alloc (127,
23342 per_cu_offset_and_type_hash
,
23343 per_cu_offset_and_type_eq
,
23344 NULL
, xcalloc
, xfree
));
23346 ofs
.per_cu
= cu
->per_cu
;
23347 ofs
.sect_off
= die
->sect_off
;
23349 slot
= (struct dwarf2_per_cu_offset_and_type
**)
23350 htab_find_slot (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
23352 complaint (_("A problem internal to GDB: DIE %s has type already set"),
23353 sect_offset_str (die
->sect_off
));
23354 *slot
= XOBNEW (&objfile
->objfile_obstack
,
23355 struct dwarf2_per_cu_offset_and_type
);
23360 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
23361 or return NULL if the die does not have a saved type. */
23363 static struct type
*
23364 get_die_type_at_offset (sect_offset sect_off
,
23365 struct dwarf2_per_cu_data
*per_cu
)
23367 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
23368 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
23370 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
23373 ofs
.per_cu
= per_cu
;
23374 ofs
.sect_off
= sect_off
;
23375 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
23376 htab_find (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
));
23383 /* Look up the type for DIE in CU in die_type_hash,
23384 or return NULL if DIE does not have a saved type. */
23386 static struct type
*
23387 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
23389 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
23392 /* Add a dependence relationship from CU to REF_PER_CU. */
23395 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
23396 struct dwarf2_per_cu_data
*ref_per_cu
)
23400 if (cu
->dependencies
== NULL
)
23402 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
23403 NULL
, &cu
->comp_unit_obstack
,
23404 hashtab_obstack_allocate
,
23405 dummy_obstack_deallocate
);
23407 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
23409 *slot
= ref_per_cu
;
23412 /* Subroutine of dwarf2_mark to pass to htab_traverse.
23413 Set the mark field in every compilation unit in the
23414 cache that we must keep because we are keeping CU. */
23417 dwarf2_mark_helper (void **slot
, void *data
)
23419 struct dwarf2_per_cu_data
*per_cu
;
23421 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
23423 /* cu->dependencies references may not yet have been ever read if QUIT aborts
23424 reading of the chain. As such dependencies remain valid it is not much
23425 useful to track and undo them during QUIT cleanups. */
23426 if (per_cu
->cu
== NULL
)
23429 if (per_cu
->cu
->mark
)
23431 per_cu
->cu
->mark
= true;
23433 if (per_cu
->cu
->dependencies
!= NULL
)
23434 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
23439 /* Set the mark field in CU and in every other compilation unit in the
23440 cache that we must keep because we are keeping CU. */
23443 dwarf2_mark (struct dwarf2_cu
*cu
)
23448 if (cu
->dependencies
!= NULL
)
23449 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
23453 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
23457 per_cu
->cu
->mark
= false;
23458 per_cu
= per_cu
->cu
->read_in_chain
;
23462 /* Trivial hash function for partial_die_info: the hash value of a DIE
23463 is its offset in .debug_info for this objfile. */
23466 partial_die_hash (const void *item
)
23468 const struct partial_die_info
*part_die
23469 = (const struct partial_die_info
*) item
;
23471 return to_underlying (part_die
->sect_off
);
23474 /* Trivial comparison function for partial_die_info structures: two DIEs
23475 are equal if they have the same offset. */
23478 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
23480 const struct partial_die_info
*part_die_lhs
23481 = (const struct partial_die_info
*) item_lhs
;
23482 const struct partial_die_info
*part_die_rhs
23483 = (const struct partial_die_info
*) item_rhs
;
23485 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
23488 struct cmd_list_element
*set_dwarf_cmdlist
;
23489 struct cmd_list_element
*show_dwarf_cmdlist
;
23492 show_check_physname (struct ui_file
*file
, int from_tty
,
23493 struct cmd_list_element
*c
, const char *value
)
23495 fprintf_filtered (file
,
23496 _("Whether to check \"physname\" is %s.\n"),
23500 void _initialize_dwarf2_read ();
23502 _initialize_dwarf2_read ()
23504 add_basic_prefix_cmd ("dwarf", class_maintenance
, _("\
23505 Set DWARF specific variables.\n\
23506 Configure DWARF variables such as the cache size."),
23507 &set_dwarf_cmdlist
, "maintenance set dwarf ",
23508 0/*allow-unknown*/, &maintenance_set_cmdlist
);
23510 add_show_prefix_cmd ("dwarf", class_maintenance
, _("\
23511 Show DWARF specific variables.\n\
23512 Show DWARF variables such as the cache size."),
23513 &show_dwarf_cmdlist
, "maintenance show dwarf ",
23514 0/*allow-unknown*/, &maintenance_show_cmdlist
);
23516 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
23517 &dwarf_max_cache_age
, _("\
23518 Set the upper bound on the age of cached DWARF compilation units."), _("\
23519 Show the upper bound on the age of cached DWARF compilation units."), _("\
23520 A higher limit means that cached compilation units will be stored\n\
23521 in memory longer, and more total memory will be used. Zero disables\n\
23522 caching, which can slow down startup."),
23524 show_dwarf_max_cache_age
,
23525 &set_dwarf_cmdlist
,
23526 &show_dwarf_cmdlist
);
23528 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
23529 Set debugging of the DWARF reader."), _("\
23530 Show debugging of the DWARF reader."), _("\
23531 When enabled (non-zero), debugging messages are printed during DWARF\n\
23532 reading and symtab expansion. A value of 1 (one) provides basic\n\
23533 information. A value greater than 1 provides more verbose information."),
23536 &setdebuglist
, &showdebuglist
);
23538 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
23539 Set debugging of the DWARF DIE reader."), _("\
23540 Show debugging of the DWARF DIE reader."), _("\
23541 When enabled (non-zero), DIEs are dumped after they are read in.\n\
23542 The value is the maximum depth to print."),
23545 &setdebuglist
, &showdebuglist
);
23547 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
23548 Set debugging of the dwarf line reader."), _("\
23549 Show debugging of the dwarf line reader."), _("\
23550 When enabled (non-zero), line number entries are dumped as they are read in.\n\
23551 A value of 1 (one) provides basic information.\n\
23552 A value greater than 1 provides more verbose information."),
23555 &setdebuglist
, &showdebuglist
);
23557 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
23558 Set cross-checking of \"physname\" code against demangler."), _("\
23559 Show cross-checking of \"physname\" code against demangler."), _("\
23560 When enabled, GDB's internal \"physname\" code is checked against\n\
23562 NULL
, show_check_physname
,
23563 &setdebuglist
, &showdebuglist
);
23565 add_setshow_boolean_cmd ("use-deprecated-index-sections",
23566 no_class
, &use_deprecated_index_sections
, _("\
23567 Set whether to use deprecated gdb_index sections."), _("\
23568 Show whether to use deprecated gdb_index sections."), _("\
23569 When enabled, deprecated .gdb_index sections are used anyway.\n\
23570 Normally they are ignored either because of a missing feature or\n\
23571 performance issue.\n\
23572 Warning: This option must be enabled before gdb reads the file."),
23575 &setlist
, &showlist
);
23577 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
23578 &dwarf2_locexpr_funcs
);
23579 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
23580 &dwarf2_loclist_funcs
);
23582 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
23583 &dwarf2_block_frame_base_locexpr_funcs
);
23584 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
23585 &dwarf2_block_frame_base_loclist_funcs
);
23588 selftests::register_test ("dw2_expand_symtabs_matching",
23589 selftests::dw2_expand_symtabs_matching::run_test
);
23590 selftests::register_test ("dwarf2_find_containing_comp_unit",
23591 selftests::find_containing_comp_unit::run_test
);