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 /* Print a "dwarf-read" debug statement if dwarf_read_debug is >= 1. */
98 #define dwarf_read_debug_printf(fmt, ...) \
99 debug_prefixed_printf_cond (dwarf_read_debug >= 1, "dwarf-read", fmt, \
102 /* Print a "dwarf-read" debug statement if dwarf_read_debug is >= 2. */
104 #define dwarf_read_debug_printf_v(fmt, ...) \
105 debug_prefixed_printf_cond (dwarf_read_debug >= 2, "dwarf-read", fmt, \
108 /* When non-zero, dump DIEs after they are read in. */
109 static unsigned int dwarf_die_debug
= 0;
111 /* When non-zero, dump line number entries as they are read in. */
112 unsigned int dwarf_line_debug
= 0;
114 /* When true, cross-check physname against demangler. */
115 static bool check_physname
= false;
117 /* When true, do not reject deprecated .gdb_index sections. */
118 static bool use_deprecated_index_sections
= false;
120 /* This is used to store the data that is always per objfile. */
121 static const objfile_key
<dwarf2_per_objfile
> dwarf2_objfile_data_key
;
123 /* These are used to store the dwarf2_per_bfd objects.
125 objfiles having the same BFD, which doesn't require relocations, are going to
126 share a dwarf2_per_bfd object, which is held in the _bfd_data_key version.
128 Other objfiles are not going to share a dwarf2_per_bfd with any other
129 objfiles, so they'll have their own version kept in the _objfile_data_key
131 static const struct bfd_key
<dwarf2_per_bfd
> dwarf2_per_bfd_bfd_data_key
;
132 static const struct objfile_key
<dwarf2_per_bfd
> dwarf2_per_bfd_objfile_data_key
;
134 /* The "aclass" indices for various kinds of computed DWARF symbols. */
136 static int dwarf2_locexpr_index
;
137 static int dwarf2_loclist_index
;
138 static int dwarf2_locexpr_block_index
;
139 static int dwarf2_loclist_block_index
;
141 /* Size of .debug_loclists section header for 32-bit DWARF format. */
142 #define LOCLIST_HEADER_SIZE32 12
144 /* Size of .debug_loclists section header for 64-bit DWARF format. */
145 #define LOCLIST_HEADER_SIZE64 20
147 /* Size of .debug_rnglists section header for 32-bit DWARF format. */
148 #define RNGLIST_HEADER_SIZE32 12
150 /* Size of .debug_rnglists section header for 64-bit DWARF format. */
151 #define RNGLIST_HEADER_SIZE64 20
153 /* An index into a (C++) symbol name component in a symbol name as
154 recorded in the mapped_index's symbol table. For each C++ symbol
155 in the symbol table, we record one entry for the start of each
156 component in the symbol in a table of name components, and then
157 sort the table, in order to be able to binary search symbol names,
158 ignoring leading namespaces, both completion and regular look up.
159 For example, for symbol "A::B::C", we'll have an entry that points
160 to "A::B::C", another that points to "B::C", and another for "C".
161 Note that function symbols in GDB index have no parameter
162 information, just the function/method names. You can convert a
163 name_component to a "const char *" using the
164 'mapped_index::symbol_name_at(offset_type)' method. */
166 struct name_component
168 /* Offset in the symbol name where the component starts. Stored as
169 a (32-bit) offset instead of a pointer to save memory and improve
170 locality on 64-bit architectures. */
171 offset_type name_offset
;
173 /* The symbol's index in the symbol and constant pool tables of a
178 /* Base class containing bits shared by both .gdb_index and
179 .debug_name indexes. */
181 struct mapped_index_base
183 mapped_index_base () = default;
184 DISABLE_COPY_AND_ASSIGN (mapped_index_base
);
186 /* The name_component table (a sorted vector). See name_component's
187 description above. */
188 std::vector
<name_component
> name_components
;
190 /* How NAME_COMPONENTS is sorted. */
191 enum case_sensitivity name_components_casing
;
193 /* Return the number of names in the symbol table. */
194 virtual size_t symbol_name_count () const = 0;
196 /* Get the name of the symbol at IDX in the symbol table. */
197 virtual const char *symbol_name_at
198 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const = 0;
200 /* Return whether the name at IDX in the symbol table should be
202 virtual bool symbol_name_slot_invalid (offset_type idx
) const
207 /* Build the symbol name component sorted vector, if we haven't
209 void build_name_components (dwarf2_per_objfile
*per_objfile
);
211 /* Returns the lower (inclusive) and upper (exclusive) bounds of the
212 possible matches for LN_NO_PARAMS in the name component
214 std::pair
<std::vector
<name_component
>::const_iterator
,
215 std::vector
<name_component
>::const_iterator
>
216 find_name_components_bounds (const lookup_name_info
&ln_no_params
,
218 dwarf2_per_objfile
*per_objfile
) const;
220 /* Prevent deleting/destroying via a base class pointer. */
222 ~mapped_index_base() = default;
225 /* A description of the mapped index. The file format is described in
226 a comment by the code that writes the index. */
227 struct mapped_index final
: public mapped_index_base
229 /* A slot/bucket in the symbol table hash. */
230 struct symbol_table_slot
232 const offset_type name
;
233 const offset_type vec
;
236 /* Index data format version. */
239 /* The address table data. */
240 gdb::array_view
<const gdb_byte
> address_table
;
242 /* The symbol table, implemented as a hash table. */
243 gdb::array_view
<symbol_table_slot
> symbol_table
;
245 /* A pointer to the constant pool. */
246 const char *constant_pool
= nullptr;
248 bool symbol_name_slot_invalid (offset_type idx
) const override
250 const auto &bucket
= this->symbol_table
[idx
];
251 return bucket
.name
== 0 && bucket
.vec
== 0;
254 /* Convenience method to get at the name of the symbol at IDX in the
256 const char *symbol_name_at
257 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
258 { return this->constant_pool
+ MAYBE_SWAP (this->symbol_table
[idx
].name
); }
260 size_t symbol_name_count () const override
261 { return this->symbol_table
.size (); }
264 /* A description of the mapped .debug_names.
265 Uninitialized map has CU_COUNT 0. */
266 struct mapped_debug_names final
: public mapped_index_base
268 bfd_endian dwarf5_byte_order
;
269 bool dwarf5_is_dwarf64
;
270 bool augmentation_is_gdb
;
272 uint32_t cu_count
= 0;
273 uint32_t tu_count
, bucket_count
, name_count
;
274 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
275 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
276 const gdb_byte
*name_table_string_offs_reordered
;
277 const gdb_byte
*name_table_entry_offs_reordered
;
278 const gdb_byte
*entry_pool
;
285 /* Attribute name DW_IDX_*. */
288 /* Attribute form DW_FORM_*. */
291 /* Value if FORM is DW_FORM_implicit_const. */
292 LONGEST implicit_const
;
294 std::vector
<attr
> attr_vec
;
297 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
299 const char *namei_to_name
300 (uint32_t namei
, dwarf2_per_objfile
*per_objfile
) const;
302 /* Implementation of the mapped_index_base virtual interface, for
303 the name_components cache. */
305 const char *symbol_name_at
306 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
307 { return namei_to_name (idx
, per_objfile
); }
309 size_t symbol_name_count () const override
310 { return this->name_count
; }
313 /* See dwarf2read.h. */
316 get_dwarf2_per_objfile (struct objfile
*objfile
)
318 return dwarf2_objfile_data_key
.get (objfile
);
321 /* Default names of the debugging sections. */
323 /* Note that if the debugging section has been compressed, it might
324 have a name like .zdebug_info. */
326 static const struct dwarf2_debug_sections dwarf2_elf_names
=
328 { ".debug_info", ".zdebug_info" },
329 { ".debug_abbrev", ".zdebug_abbrev" },
330 { ".debug_line", ".zdebug_line" },
331 { ".debug_loc", ".zdebug_loc" },
332 { ".debug_loclists", ".zdebug_loclists" },
333 { ".debug_macinfo", ".zdebug_macinfo" },
334 { ".debug_macro", ".zdebug_macro" },
335 { ".debug_str", ".zdebug_str" },
336 { ".debug_str_offsets", ".zdebug_str_offsets" },
337 { ".debug_line_str", ".zdebug_line_str" },
338 { ".debug_ranges", ".zdebug_ranges" },
339 { ".debug_rnglists", ".zdebug_rnglists" },
340 { ".debug_types", ".zdebug_types" },
341 { ".debug_addr", ".zdebug_addr" },
342 { ".debug_frame", ".zdebug_frame" },
343 { ".eh_frame", NULL
},
344 { ".gdb_index", ".zgdb_index" },
345 { ".debug_names", ".zdebug_names" },
346 { ".debug_aranges", ".zdebug_aranges" },
350 /* List of DWO/DWP sections. */
352 static const struct dwop_section_names
354 struct dwarf2_section_names abbrev_dwo
;
355 struct dwarf2_section_names info_dwo
;
356 struct dwarf2_section_names line_dwo
;
357 struct dwarf2_section_names loc_dwo
;
358 struct dwarf2_section_names loclists_dwo
;
359 struct dwarf2_section_names macinfo_dwo
;
360 struct dwarf2_section_names macro_dwo
;
361 struct dwarf2_section_names rnglists_dwo
;
362 struct dwarf2_section_names str_dwo
;
363 struct dwarf2_section_names str_offsets_dwo
;
364 struct dwarf2_section_names types_dwo
;
365 struct dwarf2_section_names cu_index
;
366 struct dwarf2_section_names tu_index
;
370 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
371 { ".debug_info.dwo", ".zdebug_info.dwo" },
372 { ".debug_line.dwo", ".zdebug_line.dwo" },
373 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
374 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
375 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
376 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
377 { ".debug_rnglists.dwo", ".zdebug_rnglists.dwo" },
378 { ".debug_str.dwo", ".zdebug_str.dwo" },
379 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
380 { ".debug_types.dwo", ".zdebug_types.dwo" },
381 { ".debug_cu_index", ".zdebug_cu_index" },
382 { ".debug_tu_index", ".zdebug_tu_index" },
385 /* local data types */
387 /* The location list and range list sections (.debug_loclists & .debug_rnglists)
388 begin with a header, which contains the following information. */
389 struct loclists_rnglists_header
391 /* A 4-byte or 12-byte length containing the length of the
392 set of entries for this compilation unit, not including the
393 length field itself. */
396 /* A 2-byte version identifier. */
399 /* A 1-byte unsigned integer containing the size in bytes of an address on
400 the target system. */
401 unsigned char addr_size
;
403 /* A 1-byte unsigned integer containing the size in bytes of a segment selector
404 on the target system. */
405 unsigned char segment_collector_size
;
407 /* A 4-byte count of the number of offsets that follow the header. */
408 unsigned int offset_entry_count
;
411 /* Type used for delaying computation of method physnames.
412 See comments for compute_delayed_physnames. */
413 struct delayed_method_info
415 /* The type to which the method is attached, i.e., its parent class. */
418 /* The index of the method in the type's function fieldlists. */
421 /* The index of the method in the fieldlist. */
424 /* The name of the DIE. */
427 /* The DIE associated with this method. */
428 struct die_info
*die
;
431 /* Internal state when decoding a particular compilation unit. */
434 explicit dwarf2_cu (dwarf2_per_cu_data
*per_cu
,
435 dwarf2_per_objfile
*per_objfile
);
437 DISABLE_COPY_AND_ASSIGN (dwarf2_cu
);
439 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
440 Create the set of symtabs used by this TU, or if this TU is sharing
441 symtabs with another TU and the symtabs have already been created
442 then restore those symtabs in the line header.
443 We don't need the pc/line-number mapping for type units. */
444 void setup_type_unit_groups (struct die_info
*die
);
446 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
447 buildsym_compunit constructor. */
448 struct compunit_symtab
*start_symtab (const char *name
,
449 const char *comp_dir
,
452 /* Reset the builder. */
453 void reset_builder () { m_builder
.reset (); }
455 /* Return a type that is a generic pointer type, the size of which
456 matches the address size given in the compilation unit header for
458 struct type
*addr_type () const;
460 /* Find an integer type the same size as the address size given in
461 the compilation unit header for this CU. UNSIGNED_P controls if
462 the integer is unsigned or not. */
463 struct type
*addr_sized_int_type (bool unsigned_p
) const;
465 /* The header of the compilation unit. */
466 struct comp_unit_head header
{};
468 /* Base address of this compilation unit. */
469 gdb::optional
<CORE_ADDR
> base_address
;
471 /* The language we are debugging. */
472 enum language language
= language_unknown
;
473 const struct language_defn
*language_defn
= nullptr;
475 const char *producer
= nullptr;
478 /* The symtab builder for this CU. This is only non-NULL when full
479 symbols are being read. */
480 std::unique_ptr
<buildsym_compunit
> m_builder
;
483 /* The generic symbol table building routines have separate lists for
484 file scope symbols and all all other scopes (local scopes). So
485 we need to select the right one to pass to add_symbol_to_list().
486 We do it by keeping a pointer to the correct list in list_in_scope.
488 FIXME: The original dwarf code just treated the file scope as the
489 first local scope, and all other local scopes as nested local
490 scopes, and worked fine. Check to see if we really need to
491 distinguish these in buildsym.c. */
492 struct pending
**list_in_scope
= nullptr;
494 /* Hash table holding all the loaded partial DIEs
495 with partial_die->offset.SECT_OFF as hash. */
496 htab_t partial_dies
= nullptr;
498 /* Storage for things with the same lifetime as this read-in compilation
499 unit, including partial DIEs. */
500 auto_obstack comp_unit_obstack
;
502 /* Backlink to our per_cu entry. */
503 struct dwarf2_per_cu_data
*per_cu
;
505 /* The dwarf2_per_objfile that owns this. */
506 dwarf2_per_objfile
*per_objfile
;
508 /* How many compilation units ago was this CU last referenced? */
511 /* A hash table of DIE cu_offset for following references with
512 die_info->offset.sect_off as hash. */
513 htab_t die_hash
= nullptr;
515 /* Full DIEs if read in. */
516 struct die_info
*dies
= nullptr;
518 /* A set of pointers to dwarf2_per_cu_data objects for compilation
519 units referenced by this one. Only set during full symbol processing;
520 partial symbol tables do not have dependencies. */
521 htab_t dependencies
= nullptr;
523 /* Header data from the line table, during full symbol processing. */
524 struct line_header
*line_header
= nullptr;
525 /* Non-NULL if LINE_HEADER is owned by this DWARF_CU. Otherwise,
526 it's owned by dwarf2_per_bfd::line_header_hash. If non-NULL,
527 this is the DW_TAG_compile_unit die for this CU. We'll hold on
528 to the line header as long as this DIE is being processed. See
529 process_die_scope. */
530 die_info
*line_header_die_owner
= nullptr;
532 /* A list of methods which need to have physnames computed
533 after all type information has been read. */
534 std::vector
<delayed_method_info
> method_list
;
536 /* To be copied to symtab->call_site_htab. */
537 htab_t call_site_htab
= nullptr;
539 /* Non-NULL if this CU came from a DWO file.
540 There is an invariant here that is important to remember:
541 Except for attributes copied from the top level DIE in the "main"
542 (or "stub") file in preparation for reading the DWO file
543 (e.g., DW_AT_addr_base), we KISS: there is only *one* CU.
544 Either there isn't a DWO file (in which case this is NULL and the point
545 is moot), or there is and either we're not going to read it (in which
546 case this is NULL) or there is and we are reading it (in which case this
548 struct dwo_unit
*dwo_unit
= nullptr;
550 /* The DW_AT_addr_base (DW_AT_GNU_addr_base) attribute if present.
551 Note this value comes from the Fission stub CU/TU's DIE. */
552 gdb::optional
<ULONGEST
> addr_base
;
554 /* The DW_AT_rnglists_base attribute if present.
555 Note this value comes from the Fission stub CU/TU's DIE.
556 Also note that the value is zero in the non-DWO case so this value can
557 be used without needing to know whether DWO files are in use or not.
558 N.B. This does not apply to DW_AT_ranges appearing in
559 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
560 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
561 DW_AT_rnglists_base *would* have to be applied, and we'd have to care
562 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
563 ULONGEST ranges_base
= 0;
565 /* The DW_AT_loclists_base attribute if present. */
566 ULONGEST loclist_base
= 0;
568 /* When reading debug info generated by older versions of rustc, we
569 have to rewrite some union types to be struct types with a
570 variant part. This rewriting must be done after the CU is fully
571 read in, because otherwise at the point of rewriting some struct
572 type might not have been fully processed. So, we keep a list of
573 all such types here and process them after expansion. */
574 std::vector
<struct type
*> rust_unions
;
576 /* The DW_AT_str_offsets_base attribute if present. For DWARF 4 version DWO
577 files, the value is implicitly zero. For DWARF 5 version DWO files, the
578 value is often implicit and is the size of the header of
579 .debug_str_offsets section (8 or 4, depending on the address size). */
580 gdb::optional
<ULONGEST
> str_offsets_base
;
582 /* Mark used when releasing cached dies. */
585 /* This CU references .debug_loc. See the symtab->locations_valid field.
586 This test is imperfect as there may exist optimized debug code not using
587 any location list and still facing inlining issues if handled as
588 unoptimized code. For a future better test see GCC PR other/32998. */
589 bool has_loclist
: 1;
591 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is true
592 if all the producer_is_* fields are valid. This information is cached
593 because profiling CU expansion showed excessive time spent in
594 producer_is_gxx_lt_4_6. */
595 bool checked_producer
: 1;
596 bool producer_is_gxx_lt_4_6
: 1;
597 bool producer_is_gcc_lt_4_3
: 1;
598 bool producer_is_icc
: 1;
599 bool producer_is_icc_lt_14
: 1;
600 bool producer_is_codewarrior
: 1;
602 /* When true, the file that we're processing is known to have
603 debugging info for C++ namespaces. GCC 3.3.x did not produce
604 this information, but later versions do. */
606 bool processing_has_namespace_info
: 1;
608 struct partial_die_info
*find_partial_die (sect_offset sect_off
);
610 /* If this CU was inherited by another CU (via specification,
611 abstract_origin, etc), this is the ancestor CU. */
614 /* Get the buildsym_compunit for this CU. */
615 buildsym_compunit
*get_builder ()
617 /* If this CU has a builder associated with it, use that. */
618 if (m_builder
!= nullptr)
619 return m_builder
.get ();
621 /* Otherwise, search ancestors for a valid builder. */
622 if (ancestor
!= nullptr)
623 return ancestor
->get_builder ();
629 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
630 This includes type_unit_group and quick_file_names. */
632 struct stmt_list_hash
634 /* The DWO unit this table is from or NULL if there is none. */
635 struct dwo_unit
*dwo_unit
;
637 /* Offset in .debug_line or .debug_line.dwo. */
638 sect_offset line_sect_off
;
641 /* Each element of dwarf2_per_bfd->type_unit_groups is a pointer to
642 an object of this type. This contains elements of type unit groups
643 that can be shared across objfiles. The non-shareable parts are in
644 type_unit_group_unshareable. */
646 struct type_unit_group
648 /* dwarf2read.c's main "handle" on a TU symtab.
649 To simplify things we create an artificial CU that "includes" all the
650 type units using this stmt_list so that the rest of the code still has
651 a "per_cu" handle on the symtab. */
652 struct dwarf2_per_cu_data per_cu
;
654 /* The TUs that share this DW_AT_stmt_list entry.
655 This is added to while parsing type units to build partial symtabs,
656 and is deleted afterwards and not used again. */
657 std::vector
<signatured_type
*> *tus
;
659 /* The data used to construct the hash key. */
660 struct stmt_list_hash hash
;
663 /* These sections are what may appear in a (real or virtual) DWO file. */
667 struct dwarf2_section_info abbrev
;
668 struct dwarf2_section_info line
;
669 struct dwarf2_section_info loc
;
670 struct dwarf2_section_info loclists
;
671 struct dwarf2_section_info macinfo
;
672 struct dwarf2_section_info macro
;
673 struct dwarf2_section_info rnglists
;
674 struct dwarf2_section_info str
;
675 struct dwarf2_section_info str_offsets
;
676 /* In the case of a virtual DWO file, these two are unused. */
677 struct dwarf2_section_info info
;
678 std::vector
<dwarf2_section_info
> types
;
681 /* CUs/TUs in DWP/DWO files. */
685 /* Backlink to the containing struct dwo_file. */
686 struct dwo_file
*dwo_file
;
688 /* The "id" that distinguishes this CU/TU.
689 .debug_info calls this "dwo_id", .debug_types calls this "signature".
690 Since signatures came first, we stick with it for consistency. */
693 /* The section this CU/TU lives in, in the DWO file. */
694 struct dwarf2_section_info
*section
;
696 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
697 sect_offset sect_off
;
700 /* For types, offset in the type's DIE of the type defined by this TU. */
701 cu_offset type_offset_in_tu
;
704 /* include/dwarf2.h defines the DWP section codes.
705 It defines a max value but it doesn't define a min value, which we
706 use for error checking, so provide one. */
708 enum dwp_v2_section_ids
713 /* Data for one DWO file.
715 This includes virtual DWO files (a virtual DWO file is a DWO file as it
716 appears in a DWP file). DWP files don't really have DWO files per se -
717 comdat folding of types "loses" the DWO file they came from, and from
718 a high level view DWP files appear to contain a mass of random types.
719 However, to maintain consistency with the non-DWP case we pretend DWP
720 files contain virtual DWO files, and we assign each TU with one virtual
721 DWO file (generally based on the line and abbrev section offsets -
722 a heuristic that seems to work in practice). */
726 dwo_file () = default;
727 DISABLE_COPY_AND_ASSIGN (dwo_file
);
729 /* The DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute.
730 For virtual DWO files the name is constructed from the section offsets
731 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
732 from related CU+TUs. */
733 const char *dwo_name
= nullptr;
735 /* The DW_AT_comp_dir attribute. */
736 const char *comp_dir
= nullptr;
738 /* The bfd, when the file is open. Otherwise this is NULL.
739 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
740 gdb_bfd_ref_ptr dbfd
;
742 /* The sections that make up this DWO file.
743 Remember that for virtual DWO files in DWP V2 or DWP V5, these are virtual
744 sections (for lack of a better name). */
745 struct dwo_sections sections
{};
747 /* The CUs in the file.
748 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
749 an extension to handle LLVM's Link Time Optimization output (where
750 multiple source files may be compiled into a single object/dwo pair). */
753 /* Table of TUs in the file.
754 Each element is a struct dwo_unit. */
758 /* These sections are what may appear in a DWP file. */
762 /* These are used by all DWP versions (1, 2 and 5). */
763 struct dwarf2_section_info str
;
764 struct dwarf2_section_info cu_index
;
765 struct dwarf2_section_info tu_index
;
767 /* These are only used by DWP version 2 and version 5 files.
768 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
769 sections are referenced by section number, and are not recorded here.
770 In DWP version 2 or 5 there is at most one copy of all these sections,
771 each section being (effectively) comprised of the concatenation of all of
772 the individual sections that exist in the version 1 format.
773 To keep the code simple we treat each of these concatenated pieces as a
774 section itself (a virtual section?). */
775 struct dwarf2_section_info abbrev
;
776 struct dwarf2_section_info info
;
777 struct dwarf2_section_info line
;
778 struct dwarf2_section_info loc
;
779 struct dwarf2_section_info loclists
;
780 struct dwarf2_section_info macinfo
;
781 struct dwarf2_section_info macro
;
782 struct dwarf2_section_info rnglists
;
783 struct dwarf2_section_info str_offsets
;
784 struct dwarf2_section_info types
;
787 /* These sections are what may appear in a virtual DWO file in DWP version 1.
788 A virtual DWO file is a DWO file as it appears in a DWP file. */
790 struct virtual_v1_dwo_sections
792 struct dwarf2_section_info abbrev
;
793 struct dwarf2_section_info line
;
794 struct dwarf2_section_info loc
;
795 struct dwarf2_section_info macinfo
;
796 struct dwarf2_section_info macro
;
797 struct dwarf2_section_info str_offsets
;
798 /* Each DWP hash table entry records one CU or one TU.
799 That is recorded here, and copied to dwo_unit.section. */
800 struct dwarf2_section_info info_or_types
;
803 /* Similar to virtual_v1_dwo_sections, but for DWP version 2 or 5.
804 In version 2, the sections of the DWO files are concatenated together
805 and stored in one section of that name. Thus each ELF section contains
806 several "virtual" sections. */
808 struct virtual_v2_or_v5_dwo_sections
810 bfd_size_type abbrev_offset
;
811 bfd_size_type abbrev_size
;
813 bfd_size_type line_offset
;
814 bfd_size_type line_size
;
816 bfd_size_type loc_offset
;
817 bfd_size_type loc_size
;
819 bfd_size_type loclists_offset
;
820 bfd_size_type loclists_size
;
822 bfd_size_type macinfo_offset
;
823 bfd_size_type macinfo_size
;
825 bfd_size_type macro_offset
;
826 bfd_size_type macro_size
;
828 bfd_size_type rnglists_offset
;
829 bfd_size_type rnglists_size
;
831 bfd_size_type str_offsets_offset
;
832 bfd_size_type str_offsets_size
;
834 /* Each DWP hash table entry records one CU or one TU.
835 That is recorded here, and copied to dwo_unit.section. */
836 bfd_size_type info_or_types_offset
;
837 bfd_size_type info_or_types_size
;
840 /* Contents of DWP hash tables. */
842 struct dwp_hash_table
844 uint32_t version
, nr_columns
;
845 uint32_t nr_units
, nr_slots
;
846 const gdb_byte
*hash_table
, *unit_table
;
851 const gdb_byte
*indices
;
855 /* This is indexed by column number and gives the id of the section
857 #define MAX_NR_V2_DWO_SECTIONS \
858 (1 /* .debug_info or .debug_types */ \
859 + 1 /* .debug_abbrev */ \
860 + 1 /* .debug_line */ \
861 + 1 /* .debug_loc */ \
862 + 1 /* .debug_str_offsets */ \
863 + 1 /* .debug_macro or .debug_macinfo */)
864 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
865 const gdb_byte
*offsets
;
866 const gdb_byte
*sizes
;
870 /* This is indexed by column number and gives the id of the section
872 #define MAX_NR_V5_DWO_SECTIONS \
873 (1 /* .debug_info */ \
874 + 1 /* .debug_abbrev */ \
875 + 1 /* .debug_line */ \
876 + 1 /* .debug_loclists */ \
877 + 1 /* .debug_str_offsets */ \
878 + 1 /* .debug_macro */ \
879 + 1 /* .debug_rnglists */)
880 int section_ids
[MAX_NR_V5_DWO_SECTIONS
];
881 const gdb_byte
*offsets
;
882 const gdb_byte
*sizes
;
887 /* Data for one DWP file. */
891 dwp_file (const char *name_
, gdb_bfd_ref_ptr
&&abfd
)
893 dbfd (std::move (abfd
))
897 /* Name of the file. */
900 /* File format version. */
904 gdb_bfd_ref_ptr dbfd
;
906 /* Section info for this file. */
907 struct dwp_sections sections
{};
909 /* Table of CUs in the file. */
910 const struct dwp_hash_table
*cus
= nullptr;
912 /* Table of TUs in the file. */
913 const struct dwp_hash_table
*tus
= nullptr;
915 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
919 /* Table to map ELF section numbers to their sections.
920 This is only needed for the DWP V1 file format. */
921 unsigned int num_sections
= 0;
922 asection
**elf_sections
= nullptr;
925 /* Struct used to pass misc. parameters to read_die_and_children, et
926 al. which are used for both .debug_info and .debug_types dies.
927 All parameters here are unchanging for the life of the call. This
928 struct exists to abstract away the constant parameters of die reading. */
930 struct die_reader_specs
932 /* The bfd of die_section. */
935 /* The CU of the DIE we are parsing. */
936 struct dwarf2_cu
*cu
;
938 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
939 struct dwo_file
*dwo_file
;
941 /* The section the die comes from.
942 This is either .debug_info or .debug_types, or the .dwo variants. */
943 struct dwarf2_section_info
*die_section
;
945 /* die_section->buffer. */
946 const gdb_byte
*buffer
;
948 /* The end of the buffer. */
949 const gdb_byte
*buffer_end
;
951 /* The abbreviation table to use when reading the DIEs. */
952 struct abbrev_table
*abbrev_table
;
955 /* A subclass of die_reader_specs that holds storage and has complex
956 constructor and destructor behavior. */
958 class cutu_reader
: public die_reader_specs
962 cutu_reader (dwarf2_per_cu_data
*this_cu
,
963 dwarf2_per_objfile
*per_objfile
,
964 struct abbrev_table
*abbrev_table
,
965 dwarf2_cu
*existing_cu
,
968 explicit cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
969 dwarf2_per_objfile
*per_objfile
,
970 struct dwarf2_cu
*parent_cu
= nullptr,
971 struct dwo_file
*dwo_file
= nullptr);
973 DISABLE_COPY_AND_ASSIGN (cutu_reader
);
975 const gdb_byte
*info_ptr
= nullptr;
976 struct die_info
*comp_unit_die
= nullptr;
977 bool dummy_p
= false;
979 /* Release the new CU, putting it on the chain. This cannot be done
984 void init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
985 dwarf2_per_objfile
*per_objfile
,
986 dwarf2_cu
*existing_cu
);
988 struct dwarf2_per_cu_data
*m_this_cu
;
989 std::unique_ptr
<dwarf2_cu
> m_new_cu
;
991 /* The ordinary abbreviation table. */
992 abbrev_table_up m_abbrev_table_holder
;
994 /* The DWO abbreviation table. */
995 abbrev_table_up m_dwo_abbrev_table
;
998 /* When we construct a partial symbol table entry we only
999 need this much information. */
1000 struct partial_die_info
: public allocate_on_obstack
1002 partial_die_info (sect_offset sect_off
, struct abbrev_info
*abbrev
);
1004 /* Disable assign but still keep copy ctor, which is needed
1005 load_partial_dies. */
1006 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
1008 /* Adjust the partial die before generating a symbol for it. This
1009 function may set the is_external flag or change the DIE's
1011 void fixup (struct dwarf2_cu
*cu
);
1013 /* Read a minimal amount of information into the minimal die
1015 const gdb_byte
*read (const struct die_reader_specs
*reader
,
1016 const struct abbrev_info
&abbrev
,
1017 const gdb_byte
*info_ptr
);
1019 /* Compute the name of this partial DIE. This memoizes the
1020 result, so it is safe to call multiple times. */
1021 const char *name (dwarf2_cu
*cu
);
1023 /* Offset of this DIE. */
1024 const sect_offset sect_off
;
1026 /* DWARF-2 tag for this DIE. */
1027 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1029 /* Assorted flags describing the data found in this DIE. */
1030 const unsigned int has_children
: 1;
1032 unsigned int is_external
: 1;
1033 unsigned int is_declaration
: 1;
1034 unsigned int has_type
: 1;
1035 unsigned int has_specification
: 1;
1036 unsigned int has_pc_info
: 1;
1037 unsigned int may_be_inlined
: 1;
1039 /* This DIE has been marked DW_AT_main_subprogram. */
1040 unsigned int main_subprogram
: 1;
1042 /* Flag set if the SCOPE field of this structure has been
1044 unsigned int scope_set
: 1;
1046 /* Flag set if the DIE has a byte_size attribute. */
1047 unsigned int has_byte_size
: 1;
1049 /* Flag set if the DIE has a DW_AT_const_value attribute. */
1050 unsigned int has_const_value
: 1;
1052 /* Flag set if any of the DIE's children are template arguments. */
1053 unsigned int has_template_arguments
: 1;
1055 /* Flag set if fixup has been called on this die. */
1056 unsigned int fixup_called
: 1;
1058 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1059 unsigned int is_dwz
: 1;
1061 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1062 unsigned int spec_is_dwz
: 1;
1064 unsigned int canonical_name
: 1;
1066 /* The name of this DIE. Normally the value of DW_AT_name, but
1067 sometimes a default name for unnamed DIEs. */
1068 const char *raw_name
= nullptr;
1070 /* The linkage name, if present. */
1071 const char *linkage_name
= nullptr;
1073 /* The scope to prepend to our children. This is generally
1074 allocated on the comp_unit_obstack, so will disappear
1075 when this compilation unit leaves the cache. */
1076 const char *scope
= nullptr;
1078 /* Some data associated with the partial DIE. The tag determines
1079 which field is live. */
1082 /* The location description associated with this DIE, if any. */
1083 struct dwarf_block
*locdesc
;
1084 /* The offset of an import, for DW_TAG_imported_unit. */
1085 sect_offset sect_off
;
1088 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1089 CORE_ADDR lowpc
= 0;
1090 CORE_ADDR highpc
= 0;
1092 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1093 DW_AT_sibling, if any. */
1094 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1095 could return DW_AT_sibling values to its caller load_partial_dies. */
1096 const gdb_byte
*sibling
= nullptr;
1098 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1099 DW_AT_specification (or DW_AT_abstract_origin or
1100 DW_AT_extension). */
1101 sect_offset spec_offset
{};
1103 /* Pointers to this DIE's parent, first child, and next sibling,
1105 struct partial_die_info
*die_parent
= nullptr;
1106 struct partial_die_info
*die_child
= nullptr;
1107 struct partial_die_info
*die_sibling
= nullptr;
1109 friend struct partial_die_info
*
1110 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1113 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1114 partial_die_info (sect_offset sect_off
)
1115 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1119 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1121 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1126 has_specification
= 0;
1129 main_subprogram
= 0;
1132 has_const_value
= 0;
1133 has_template_arguments
= 0;
1141 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1142 but this would require a corresponding change in unpack_field_as_long
1144 static int bits_per_byte
= 8;
1146 struct variant_part_builder
;
1148 /* When reading a variant, we track a bit more information about the
1149 field, and store it in an object of this type. */
1151 struct variant_field
1153 int first_field
= -1;
1154 int last_field
= -1;
1156 /* A variant can contain other variant parts. */
1157 std::vector
<variant_part_builder
> variant_parts
;
1159 /* If we see a DW_TAG_variant, then this will be set if this is the
1161 bool default_branch
= false;
1162 /* If we see a DW_AT_discr_value, then this will be the discriminant
1164 ULONGEST discriminant_value
= 0;
1165 /* If we see a DW_AT_discr_list, then this is a pointer to the list
1167 struct dwarf_block
*discr_list_data
= nullptr;
1170 /* This represents a DW_TAG_variant_part. */
1172 struct variant_part_builder
1174 /* The offset of the discriminant field. */
1175 sect_offset discriminant_offset
{};
1177 /* Variants that are direct children of this variant part. */
1178 std::vector
<variant_field
> variants
;
1180 /* True if we're currently reading a variant. */
1181 bool processing_variant
= false;
1186 int accessibility
= 0;
1188 /* Variant parts need to find the discriminant, which is a DIE
1189 reference. We track the section offset of each field to make
1192 struct field field
{};
1197 const char *name
= nullptr;
1198 std::vector
<struct fn_field
> fnfields
;
1201 /* The routines that read and process dies for a C struct or C++ class
1202 pass lists of data member fields and lists of member function fields
1203 in an instance of a field_info structure, as defined below. */
1206 /* List of data member and baseclasses fields. */
1207 std::vector
<struct nextfield
> fields
;
1208 std::vector
<struct nextfield
> baseclasses
;
1210 /* Set if the accessibility of one of the fields is not public. */
1211 bool non_public_fields
= false;
1213 /* Member function fieldlist array, contains name of possibly overloaded
1214 member function, number of overloaded member functions and a pointer
1215 to the head of the member function field chain. */
1216 std::vector
<struct fnfieldlist
> fnfieldlists
;
1218 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1219 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1220 std::vector
<struct decl_field
> typedef_field_list
;
1222 /* Nested types defined by this class and the number of elements in this
1224 std::vector
<struct decl_field
> nested_types_list
;
1226 /* If non-null, this is the variant part we are currently
1228 variant_part_builder
*current_variant_part
= nullptr;
1229 /* This holds all the top-level variant parts attached to the type
1231 std::vector
<variant_part_builder
> variant_parts
;
1233 /* Return the total number of fields (including baseclasses). */
1234 int nfields () const
1236 return fields
.size () + baseclasses
.size ();
1240 /* Loaded secondary compilation units are kept in memory until they
1241 have not been referenced for the processing of this many
1242 compilation units. Set this to zero to disable caching. Cache
1243 sizes of up to at least twenty will improve startup time for
1244 typical inter-CU-reference binaries, at an obvious memory cost. */
1245 static int dwarf_max_cache_age
= 5;
1247 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1248 struct cmd_list_element
*c
, const char *value
)
1250 fprintf_filtered (file
, _("The upper bound on the age of cached "
1251 "DWARF compilation units is %s.\n"),
1255 /* local function prototypes */
1257 static void dwarf2_find_base_address (struct die_info
*die
,
1258 struct dwarf2_cu
*cu
);
1260 static dwarf2_psymtab
*create_partial_symtab
1261 (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
1264 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1265 const gdb_byte
*info_ptr
,
1266 struct die_info
*type_unit_die
);
1268 static void dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
);
1270 static void scan_partial_symbols (struct partial_die_info
*,
1271 CORE_ADDR
*, CORE_ADDR
*,
1272 int, struct dwarf2_cu
*);
1274 static void add_partial_symbol (struct partial_die_info
*,
1275 struct dwarf2_cu
*);
1277 static void add_partial_namespace (struct partial_die_info
*pdi
,
1278 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1279 int set_addrmap
, struct dwarf2_cu
*cu
);
1281 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1282 CORE_ADDR
*highpc
, int set_addrmap
,
1283 struct dwarf2_cu
*cu
);
1285 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1286 struct dwarf2_cu
*cu
);
1288 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1289 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1290 int need_pc
, struct dwarf2_cu
*cu
);
1292 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1294 static struct partial_die_info
*load_partial_dies
1295 (const struct die_reader_specs
*, const gdb_byte
*, int);
1297 /* A pair of partial_die_info and compilation unit. */
1298 struct cu_partial_die_info
1300 /* The compilation unit of the partial_die_info. */
1301 struct dwarf2_cu
*cu
;
1302 /* A partial_die_info. */
1303 struct partial_die_info
*pdi
;
1305 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1311 cu_partial_die_info () = delete;
1314 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1315 struct dwarf2_cu
*);
1317 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1318 struct attribute
*, struct attr_abbrev
*,
1321 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1322 struct attribute
*attr
, dwarf_tag tag
);
1324 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1326 static sect_offset
read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
1327 dwarf2_section_info
*, sect_offset
);
1329 static const char *read_indirect_string
1330 (dwarf2_per_objfile
*per_objfile
, bfd
*, const gdb_byte
*,
1331 const struct comp_unit_head
*, unsigned int *);
1333 static const char *read_indirect_string_at_offset
1334 (dwarf2_per_objfile
*per_objfile
, LONGEST str_offset
);
1336 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1340 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1341 ULONGEST str_index
);
1343 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1344 ULONGEST str_index
);
1346 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1348 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1349 struct dwarf2_cu
*);
1351 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1352 struct dwarf2_cu
*cu
);
1354 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1356 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1357 struct dwarf2_cu
*cu
);
1359 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1361 static struct die_info
*die_specification (struct die_info
*die
,
1362 struct dwarf2_cu
**);
1364 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1365 struct dwarf2_cu
*cu
);
1367 static void dwarf_decode_lines (struct line_header
*, const char *,
1368 struct dwarf2_cu
*, dwarf2_psymtab
*,
1369 CORE_ADDR
, int decode_mapping
);
1371 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1374 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1375 struct dwarf2_cu
*, struct symbol
* = NULL
);
1377 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1378 struct dwarf2_cu
*);
1380 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1383 struct obstack
*obstack
,
1384 struct dwarf2_cu
*cu
, LONGEST
*value
,
1385 const gdb_byte
**bytes
,
1386 struct dwarf2_locexpr_baton
**baton
);
1388 static struct type
*read_subrange_index_type (struct die_info
*die
,
1389 struct dwarf2_cu
*cu
);
1391 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1393 static int need_gnat_info (struct dwarf2_cu
*);
1395 static struct type
*die_descriptive_type (struct die_info
*,
1396 struct dwarf2_cu
*);
1398 static void set_descriptive_type (struct type
*, struct die_info
*,
1399 struct dwarf2_cu
*);
1401 static struct type
*die_containing_type (struct die_info
*,
1402 struct dwarf2_cu
*);
1404 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1405 struct dwarf2_cu
*);
1407 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1409 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1411 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1413 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1414 const char *suffix
, int physname
,
1415 struct dwarf2_cu
*cu
);
1417 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1419 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1421 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1423 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1425 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1427 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1429 /* Return the .debug_loclists section to use for cu. */
1430 static struct dwarf2_section_info
*cu_debug_loc_section (struct dwarf2_cu
*cu
);
1432 /* Return the .debug_rnglists section to use for cu. */
1433 static struct dwarf2_section_info
*cu_debug_rnglists_section
1434 (struct dwarf2_cu
*cu
, dwarf_tag tag
);
1436 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1437 values. Keep the items ordered with increasing constraints compliance. */
1440 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1441 PC_BOUNDS_NOT_PRESENT
,
1443 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1444 were present but they do not form a valid range of PC addresses. */
1447 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1450 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1454 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1455 CORE_ADDR
*, CORE_ADDR
*,
1459 static void get_scope_pc_bounds (struct die_info
*,
1460 CORE_ADDR
*, CORE_ADDR
*,
1461 struct dwarf2_cu
*);
1463 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1464 CORE_ADDR
, struct dwarf2_cu
*);
1466 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1467 struct dwarf2_cu
*);
1469 static void dwarf2_attach_fields_to_type (struct field_info
*,
1470 struct type
*, struct dwarf2_cu
*);
1472 static void dwarf2_add_member_fn (struct field_info
*,
1473 struct die_info
*, struct type
*,
1474 struct dwarf2_cu
*);
1476 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1478 struct dwarf2_cu
*);
1480 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1482 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1484 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1486 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1488 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1490 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1492 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1494 static struct type
*read_module_type (struct die_info
*die
,
1495 struct dwarf2_cu
*cu
);
1497 static const char *namespace_name (struct die_info
*die
,
1498 int *is_anonymous
, struct dwarf2_cu
*);
1500 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1502 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*,
1505 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1506 struct dwarf2_cu
*);
1508 static struct die_info
*read_die_and_siblings_1
1509 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1512 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1513 const gdb_byte
*info_ptr
,
1514 const gdb_byte
**new_info_ptr
,
1515 struct die_info
*parent
);
1517 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1518 struct die_info
**, const gdb_byte
*,
1521 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1522 struct die_info
**, const gdb_byte
*);
1524 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1526 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1529 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1531 static const char *dwarf2_full_name (const char *name
,
1532 struct die_info
*die
,
1533 struct dwarf2_cu
*cu
);
1535 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1536 struct dwarf2_cu
*cu
);
1538 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1539 struct dwarf2_cu
**);
1541 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1543 static void dump_die_for_error (struct die_info
*);
1545 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1548 /*static*/ void dump_die (struct die_info
*, int max_level
);
1550 static void store_in_ref_table (struct die_info
*,
1551 struct dwarf2_cu
*);
1553 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1554 const struct attribute
*,
1555 struct dwarf2_cu
**);
1557 static struct die_info
*follow_die_ref (struct die_info
*,
1558 const struct attribute
*,
1559 struct dwarf2_cu
**);
1561 static struct die_info
*follow_die_sig (struct die_info
*,
1562 const struct attribute
*,
1563 struct dwarf2_cu
**);
1565 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1566 struct dwarf2_cu
*);
1568 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1569 const struct attribute
*,
1570 struct dwarf2_cu
*);
1572 static void load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
1573 dwarf2_per_objfile
*per_objfile
);
1575 static void read_signatured_type (signatured_type
*sig_type
,
1576 dwarf2_per_objfile
*per_objfile
);
1578 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1579 struct die_info
*die
, struct dwarf2_cu
*cu
,
1580 struct dynamic_prop
*prop
, struct type
*type
);
1582 /* memory allocation interface */
1584 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1586 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1588 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1590 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1591 struct dwarf2_loclist_baton
*baton
,
1592 const struct attribute
*attr
);
1594 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1596 struct dwarf2_cu
*cu
,
1599 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1600 const gdb_byte
*info_ptr
,
1601 struct abbrev_info
*abbrev
);
1603 static hashval_t
partial_die_hash (const void *item
);
1605 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1607 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1608 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1609 dwarf2_per_objfile
*per_objfile
);
1611 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1612 struct die_info
*comp_unit_die
,
1613 enum language pretend_language
);
1615 static struct type
*set_die_type (struct die_info
*, struct type
*,
1616 struct dwarf2_cu
*, bool = false);
1618 static void create_all_comp_units (dwarf2_per_objfile
*per_objfile
);
1620 static int create_all_type_units (dwarf2_per_objfile
*per_objfile
);
1622 static void load_full_comp_unit (dwarf2_per_cu_data
*per_cu
,
1623 dwarf2_per_objfile
*per_objfile
,
1624 dwarf2_cu
*existing_cu
,
1626 enum language pretend_language
);
1628 static void process_full_comp_unit (dwarf2_cu
*cu
,
1629 enum language pretend_language
);
1631 static void process_full_type_unit (dwarf2_cu
*cu
,
1632 enum language pretend_language
);
1634 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1635 struct dwarf2_per_cu_data
*);
1637 static void dwarf2_mark (struct dwarf2_cu
*);
1639 static struct type
*get_die_type_at_offset (sect_offset
,
1640 dwarf2_per_cu_data
*per_cu
,
1641 dwarf2_per_objfile
*per_objfile
);
1643 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1645 static void queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
1646 dwarf2_per_objfile
*per_objfile
,
1647 enum language pretend_language
);
1649 static void process_queue (dwarf2_per_objfile
*per_objfile
);
1651 /* Class, the destructor of which frees all allocated queue entries. This
1652 will only have work to do if an error was thrown while processing the
1653 dwarf. If no error was thrown then the queue entries should have all
1654 been processed, and freed, as we went along. */
1656 class dwarf2_queue_guard
1659 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1660 : m_per_objfile (per_objfile
)
1664 /* Free any entries remaining on the queue. There should only be
1665 entries left if we hit an error while processing the dwarf. */
1666 ~dwarf2_queue_guard ()
1668 /* Ensure that no memory is allocated by the queue. */
1669 std::queue
<dwarf2_queue_item
> empty
;
1670 std::swap (m_per_objfile
->per_bfd
->queue
, empty
);
1673 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1676 dwarf2_per_objfile
*m_per_objfile
;
1679 dwarf2_queue_item::~dwarf2_queue_item ()
1681 /* Anything still marked queued is likely to be in an
1682 inconsistent state, so discard it. */
1685 per_objfile
->remove_cu (per_cu
);
1690 /* The return type of find_file_and_directory. Note, the enclosed
1691 string pointers are only valid while this object is valid. */
1693 struct file_and_directory
1695 /* The filename. This is never NULL. */
1698 /* The compilation directory. NULL if not known. If we needed to
1699 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1700 points directly to the DW_AT_comp_dir string attribute owned by
1701 the obstack that owns the DIE. */
1702 const char *comp_dir
;
1704 /* If we needed to build a new string for comp_dir, this is what
1705 owns the storage. */
1706 std::string comp_dir_storage
;
1709 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1710 struct dwarf2_cu
*cu
);
1712 static htab_up
allocate_signatured_type_table ();
1714 static htab_up
allocate_dwo_unit_table ();
1716 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1717 (dwarf2_per_objfile
*per_objfile
, struct dwp_file
*dwp_file
,
1718 const char *comp_dir
, ULONGEST signature
, int is_debug_types
);
1720 static struct dwp_file
*get_dwp_file (dwarf2_per_objfile
*per_objfile
);
1722 static struct dwo_unit
*lookup_dwo_comp_unit
1723 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
1724 ULONGEST signature
);
1726 static struct dwo_unit
*lookup_dwo_type_unit
1727 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
);
1729 static void queue_and_load_all_dwo_tus (dwarf2_cu
*cu
);
1731 /* A unique pointer to a dwo_file. */
1733 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1735 static void process_cu_includes (dwarf2_per_objfile
*per_objfile
);
1737 static void check_producer (struct dwarf2_cu
*cu
);
1739 static void free_line_header_voidp (void *arg
);
1741 /* Various complaints about symbol reading that don't abort the process. */
1744 dwarf2_debug_line_missing_file_complaint (void)
1746 complaint (_(".debug_line section has line data without a file"));
1750 dwarf2_debug_line_missing_end_sequence_complaint (void)
1752 complaint (_(".debug_line section has line "
1753 "program sequence without an end"));
1757 dwarf2_complex_location_expr_complaint (void)
1759 complaint (_("location expression too complex"));
1763 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1766 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1771 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1773 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1777 /* Hash function for line_header_hash. */
1780 line_header_hash (const struct line_header
*ofs
)
1782 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1785 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1788 line_header_hash_voidp (const void *item
)
1790 const struct line_header
*ofs
= (const struct line_header
*) item
;
1792 return line_header_hash (ofs
);
1795 /* Equality function for line_header_hash. */
1798 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1800 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1801 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1803 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1804 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
1809 /* See declaration. */
1811 dwarf2_per_bfd::dwarf2_per_bfd (bfd
*obfd
, const dwarf2_debug_sections
*names
,
1814 can_copy (can_copy_
)
1817 names
= &dwarf2_elf_names
;
1819 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1820 locate_sections (obfd
, sec
, *names
);
1823 dwarf2_per_bfd::~dwarf2_per_bfd ()
1825 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
1826 per_cu
->imported_symtabs_free ();
1828 for (signatured_type
*sig_type
: all_type_units
)
1829 sig_type
->per_cu
.imported_symtabs_free ();
1831 /* Everything else should be on this->obstack. */
1837 dwarf2_per_objfile::remove_all_cus ()
1839 for (auto pair
: m_dwarf2_cus
)
1842 m_dwarf2_cus
.clear ();
1845 /* A helper class that calls free_cached_comp_units on
1848 class free_cached_comp_units
1852 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1853 : m_per_objfile (per_objfile
)
1857 ~free_cached_comp_units ()
1859 m_per_objfile
->remove_all_cus ();
1862 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1866 dwarf2_per_objfile
*m_per_objfile
;
1872 dwarf2_per_objfile::symtab_set_p (const dwarf2_per_cu_data
*per_cu
) const
1874 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1876 return this->m_symtabs
[per_cu
->index
] != nullptr;
1882 dwarf2_per_objfile::get_symtab (const dwarf2_per_cu_data
*per_cu
) const
1884 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1886 return this->m_symtabs
[per_cu
->index
];
1892 dwarf2_per_objfile::set_symtab (const dwarf2_per_cu_data
*per_cu
,
1893 compunit_symtab
*symtab
)
1895 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1896 gdb_assert (this->m_symtabs
[per_cu
->index
] == nullptr);
1898 this->m_symtabs
[per_cu
->index
] = symtab
;
1901 /* Try to locate the sections we need for DWARF 2 debugging
1902 information and return true if we have enough to do something.
1903 NAMES points to the dwarf2 section names, or is NULL if the standard
1904 ELF names are used. CAN_COPY is true for formats where symbol
1905 interposition is possible and so symbol values must follow copy
1906 relocation rules. */
1909 dwarf2_has_info (struct objfile
*objfile
,
1910 const struct dwarf2_debug_sections
*names
,
1913 if (objfile
->flags
& OBJF_READNEVER
)
1916 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
1918 if (per_objfile
== NULL
)
1920 dwarf2_per_bfd
*per_bfd
;
1922 /* We can share a "dwarf2_per_bfd" with other objfiles if the BFD
1923 doesn't require relocations and if there aren't partial symbols
1924 from some other reader. */
1925 if (!objfile_has_partial_symbols (objfile
)
1926 && !gdb_bfd_requires_relocations (objfile
->obfd
))
1928 /* See if one has been created for this BFD yet. */
1929 per_bfd
= dwarf2_per_bfd_bfd_data_key
.get (objfile
->obfd
);
1931 if (per_bfd
== nullptr)
1933 /* No, create it now. */
1934 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
1935 dwarf2_per_bfd_bfd_data_key
.set (objfile
->obfd
, per_bfd
);
1940 /* No sharing possible, create one specifically for this objfile. */
1941 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
1942 dwarf2_per_bfd_objfile_data_key
.set (objfile
, per_bfd
);
1945 per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
, per_bfd
);
1948 return (!per_objfile
->per_bfd
->info
.is_virtual
1949 && per_objfile
->per_bfd
->info
.s
.section
!= NULL
1950 && !per_objfile
->per_bfd
->abbrev
.is_virtual
1951 && per_objfile
->per_bfd
->abbrev
.s
.section
!= NULL
);
1954 /* When loading sections, we look either for uncompressed section or for
1955 compressed section names. */
1958 section_is_p (const char *section_name
,
1959 const struct dwarf2_section_names
*names
)
1961 if (names
->normal
!= NULL
1962 && strcmp (section_name
, names
->normal
) == 0)
1964 if (names
->compressed
!= NULL
1965 && strcmp (section_name
, names
->compressed
) == 0)
1970 /* See declaration. */
1973 dwarf2_per_bfd::locate_sections (bfd
*abfd
, asection
*sectp
,
1974 const dwarf2_debug_sections
&names
)
1976 flagword aflag
= bfd_section_flags (sectp
);
1978 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1981 else if (elf_section_data (sectp
)->this_hdr
.sh_size
1982 > bfd_get_file_size (abfd
))
1984 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
1985 warning (_("Discarding section %s which has a section size (%s"
1986 ") larger than the file size [in module %s]"),
1987 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
1988 bfd_get_filename (abfd
));
1990 else if (section_is_p (sectp
->name
, &names
.info
))
1992 this->info
.s
.section
= sectp
;
1993 this->info
.size
= bfd_section_size (sectp
);
1995 else if (section_is_p (sectp
->name
, &names
.abbrev
))
1997 this->abbrev
.s
.section
= sectp
;
1998 this->abbrev
.size
= bfd_section_size (sectp
);
2000 else if (section_is_p (sectp
->name
, &names
.line
))
2002 this->line
.s
.section
= sectp
;
2003 this->line
.size
= bfd_section_size (sectp
);
2005 else if (section_is_p (sectp
->name
, &names
.loc
))
2007 this->loc
.s
.section
= sectp
;
2008 this->loc
.size
= bfd_section_size (sectp
);
2010 else if (section_is_p (sectp
->name
, &names
.loclists
))
2012 this->loclists
.s
.section
= sectp
;
2013 this->loclists
.size
= bfd_section_size (sectp
);
2015 else if (section_is_p (sectp
->name
, &names
.macinfo
))
2017 this->macinfo
.s
.section
= sectp
;
2018 this->macinfo
.size
= bfd_section_size (sectp
);
2020 else if (section_is_p (sectp
->name
, &names
.macro
))
2022 this->macro
.s
.section
= sectp
;
2023 this->macro
.size
= bfd_section_size (sectp
);
2025 else if (section_is_p (sectp
->name
, &names
.str
))
2027 this->str
.s
.section
= sectp
;
2028 this->str
.size
= bfd_section_size (sectp
);
2030 else if (section_is_p (sectp
->name
, &names
.str_offsets
))
2032 this->str_offsets
.s
.section
= sectp
;
2033 this->str_offsets
.size
= bfd_section_size (sectp
);
2035 else if (section_is_p (sectp
->name
, &names
.line_str
))
2037 this->line_str
.s
.section
= sectp
;
2038 this->line_str
.size
= bfd_section_size (sectp
);
2040 else if (section_is_p (sectp
->name
, &names
.addr
))
2042 this->addr
.s
.section
= sectp
;
2043 this->addr
.size
= bfd_section_size (sectp
);
2045 else if (section_is_p (sectp
->name
, &names
.frame
))
2047 this->frame
.s
.section
= sectp
;
2048 this->frame
.size
= bfd_section_size (sectp
);
2050 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
2052 this->eh_frame
.s
.section
= sectp
;
2053 this->eh_frame
.size
= bfd_section_size (sectp
);
2055 else if (section_is_p (sectp
->name
, &names
.ranges
))
2057 this->ranges
.s
.section
= sectp
;
2058 this->ranges
.size
= bfd_section_size (sectp
);
2060 else if (section_is_p (sectp
->name
, &names
.rnglists
))
2062 this->rnglists
.s
.section
= sectp
;
2063 this->rnglists
.size
= bfd_section_size (sectp
);
2065 else if (section_is_p (sectp
->name
, &names
.types
))
2067 struct dwarf2_section_info type_section
;
2069 memset (&type_section
, 0, sizeof (type_section
));
2070 type_section
.s
.section
= sectp
;
2071 type_section
.size
= bfd_section_size (sectp
);
2073 this->types
.push_back (type_section
);
2075 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
2077 this->gdb_index
.s
.section
= sectp
;
2078 this->gdb_index
.size
= bfd_section_size (sectp
);
2080 else if (section_is_p (sectp
->name
, &names
.debug_names
))
2082 this->debug_names
.s
.section
= sectp
;
2083 this->debug_names
.size
= bfd_section_size (sectp
);
2085 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
2087 this->debug_aranges
.s
.section
= sectp
;
2088 this->debug_aranges
.size
= bfd_section_size (sectp
);
2091 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2092 && bfd_section_vma (sectp
) == 0)
2093 this->has_section_at_zero
= true;
2096 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2100 dwarf2_get_section_info (struct objfile
*objfile
,
2101 enum dwarf2_section_enum sect
,
2102 asection
**sectp
, const gdb_byte
**bufp
,
2103 bfd_size_type
*sizep
)
2105 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
2106 struct dwarf2_section_info
*info
;
2108 /* We may see an objfile without any DWARF, in which case we just
2110 if (per_objfile
== NULL
)
2119 case DWARF2_DEBUG_FRAME
:
2120 info
= &per_objfile
->per_bfd
->frame
;
2122 case DWARF2_EH_FRAME
:
2123 info
= &per_objfile
->per_bfd
->eh_frame
;
2126 gdb_assert_not_reached ("unexpected section");
2129 info
->read (objfile
);
2131 *sectp
= info
->get_bfd_section ();
2132 *bufp
= info
->buffer
;
2133 *sizep
= info
->size
;
2136 /* A helper function to find the sections for a .dwz file. */
2139 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, dwz_file
*dwz_file
)
2141 /* Note that we only support the standard ELF names, because .dwz
2142 is ELF-only (at the time of writing). */
2143 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2145 dwz_file
->abbrev
.s
.section
= sectp
;
2146 dwz_file
->abbrev
.size
= bfd_section_size (sectp
);
2148 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2150 dwz_file
->info
.s
.section
= sectp
;
2151 dwz_file
->info
.size
= bfd_section_size (sectp
);
2153 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2155 dwz_file
->str
.s
.section
= sectp
;
2156 dwz_file
->str
.size
= bfd_section_size (sectp
);
2158 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2160 dwz_file
->line
.s
.section
= sectp
;
2161 dwz_file
->line
.size
= bfd_section_size (sectp
);
2163 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2165 dwz_file
->macro
.s
.section
= sectp
;
2166 dwz_file
->macro
.size
= bfd_section_size (sectp
);
2168 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2170 dwz_file
->gdb_index
.s
.section
= sectp
;
2171 dwz_file
->gdb_index
.size
= bfd_section_size (sectp
);
2173 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2175 dwz_file
->debug_names
.s
.section
= sectp
;
2176 dwz_file
->debug_names
.size
= bfd_section_size (sectp
);
2180 /* Attempt to find a .dwz file (whose full path is represented by
2181 FILENAME) in all of the specified debug file directories provided.
2183 Return the equivalent gdb_bfd_ref_ptr of the .dwz file found, or
2184 nullptr if it could not find anything. */
2186 static gdb_bfd_ref_ptr
2187 dwz_search_other_debugdirs (std::string
&filename
, bfd_byte
*buildid
,
2190 /* Let's assume that the path represented by FILENAME has the
2191 "/.dwz/" subpath in it. This is what (most) GNU/Linux
2192 distributions do, anyway. */
2193 size_t dwz_pos
= filename
.find ("/.dwz/");
2195 if (dwz_pos
== std::string::npos
)
2198 /* This is an obvious assertion, but it's here more to educate
2199 future readers of this code that FILENAME at DWZ_POS *must*
2200 contain a directory separator. */
2201 gdb_assert (IS_DIR_SEPARATOR (filename
[dwz_pos
]));
2203 gdb_bfd_ref_ptr dwz_bfd
;
2204 std::vector
<gdb::unique_xmalloc_ptr
<char>> debugdir_vec
2205 = dirnames_to_char_ptr_vec (debug_file_directory
);
2207 for (const gdb::unique_xmalloc_ptr
<char> &debugdir
: debugdir_vec
)
2209 /* The idea is to iterate over the
2210 debug file directories provided by the user and
2211 replace the hard-coded path in the "filename" by each
2212 debug-file-directory.
2214 For example, suppose that filename is:
2216 /usr/lib/debug/.dwz/foo.dwz
2218 And suppose that we have "$HOME/bar" as the
2219 debug-file-directory. We would then adjust filename
2222 $HOME/bar/.dwz/foo.dwz
2224 which would hopefully allow us to find the alt debug
2226 std::string ddir
= debugdir
.get ();
2231 /* Make sure the current debug-file-directory ends with a
2232 directory separator. This is needed because, if FILENAME
2233 contains something like "/usr/lib/abcde/.dwz/foo.dwz" and
2234 DDIR is "/usr/lib/abc", then could wrongfully skip it
2236 if (!IS_DIR_SEPARATOR (ddir
.back ()))
2237 ddir
+= SLASH_STRING
;
2239 /* Check whether the beginning of FILENAME is DDIR. If it is,
2240 then we are dealing with a file which we already attempted to
2241 open before, so we just skip it and continue processing the
2242 remaining debug file directories. */
2243 if (filename
.size () > ddir
.size ()
2244 && filename
.compare (0, ddir
.size (), ddir
) == 0)
2247 /* Replace FILENAME's default debug-file-directory with
2249 std::string new_filename
= ddir
+ &filename
[dwz_pos
+ 1];
2251 dwz_bfd
= gdb_bfd_open (new_filename
.c_str (), gnutarget
);
2253 if (dwz_bfd
== nullptr)
2256 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2258 dwz_bfd
.reset (nullptr);
2269 /* See dwarf2read.h. */
2272 dwarf2_get_dwz_file (dwarf2_per_bfd
*per_bfd
)
2274 bfd_size_type buildid_len_arg
;
2278 if (per_bfd
->dwz_file
!= NULL
)
2279 return per_bfd
->dwz_file
.get ();
2281 bfd_set_error (bfd_error_no_error
);
2282 gdb::unique_xmalloc_ptr
<char> data
2283 (bfd_get_alt_debug_link_info (per_bfd
->obfd
,
2284 &buildid_len_arg
, &buildid
));
2287 if (bfd_get_error () == bfd_error_no_error
)
2289 error (_("could not read '.gnu_debugaltlink' section: %s"),
2290 bfd_errmsg (bfd_get_error ()));
2293 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2295 buildid_len
= (size_t) buildid_len_arg
;
2297 std::string filename
= data
.get ();
2299 if (!IS_ABSOLUTE_PATH (filename
.c_str ()))
2301 gdb::unique_xmalloc_ptr
<char> abs
2302 = gdb_realpath (bfd_get_filename (per_bfd
->obfd
));
2304 filename
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2307 /* First try the file name given in the section. If that doesn't
2308 work, try to use the build-id instead. */
2309 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
.c_str (), gnutarget
));
2310 if (dwz_bfd
!= NULL
)
2312 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2313 dwz_bfd
.reset (nullptr);
2316 if (dwz_bfd
== NULL
)
2317 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2319 if (dwz_bfd
== nullptr)
2321 /* If the user has provided us with different
2322 debug file directories, we can try them in order. */
2323 dwz_bfd
= dwz_search_other_debugdirs (filename
, buildid
, buildid_len
);
2326 if (dwz_bfd
== nullptr)
2328 gdb::unique_xmalloc_ptr
<char> alt_filename
;
2329 const char *origname
= bfd_get_filename (per_bfd
->obfd
);
2331 scoped_fd
fd (debuginfod_debuginfo_query (buildid
,
2338 /* File successfully retrieved from server. */
2339 dwz_bfd
= gdb_bfd_open (alt_filename
.get (), gnutarget
);
2341 if (dwz_bfd
== nullptr)
2342 warning (_("File \"%s\" from debuginfod cannot be opened as bfd"),
2343 alt_filename
.get ());
2344 else if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2345 dwz_bfd
.reset (nullptr);
2349 if (dwz_bfd
== NULL
)
2350 error (_("could not find '.gnu_debugaltlink' file for %s"),
2351 bfd_get_filename (per_bfd
->obfd
));
2353 std::unique_ptr
<struct dwz_file
> result
2354 (new struct dwz_file (std::move (dwz_bfd
)));
2356 for (asection
*sec
: gdb_bfd_sections (result
->dwz_bfd
))
2357 locate_dwz_sections (result
->dwz_bfd
.get (), sec
, result
.get ());
2359 gdb_bfd_record_inclusion (per_bfd
->obfd
, result
->dwz_bfd
.get ());
2360 per_bfd
->dwz_file
= std::move (result
);
2361 return per_bfd
->dwz_file
.get ();
2364 /* DWARF quick_symbols_functions support. */
2366 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2367 unique line tables, so we maintain a separate table of all .debug_line
2368 derived entries to support the sharing.
2369 All the quick functions need is the list of file names. We discard the
2370 line_header when we're done and don't need to record it here. */
2371 struct quick_file_names
2373 /* The data used to construct the hash key. */
2374 struct stmt_list_hash hash
;
2376 /* The number of entries in file_names, real_names. */
2377 unsigned int num_file_names
;
2379 /* The file names from the line table, after being run through
2381 const char **file_names
;
2383 /* The file names from the line table after being run through
2384 gdb_realpath. These are computed lazily. */
2385 const char **real_names
;
2388 /* When using the index (and thus not using psymtabs), each CU has an
2389 object of this type. This is used to hold information needed by
2390 the various "quick" methods. */
2391 struct dwarf2_per_cu_quick_data
2393 /* The file table. This can be NULL if there was no file table
2394 or it's currently not read in.
2395 NOTE: This points into dwarf2_per_objfile->per_bfd->quick_file_names_table. */
2396 struct quick_file_names
*file_names
;
2398 /* A temporary mark bit used when iterating over all CUs in
2399 expand_symtabs_matching. */
2400 unsigned int mark
: 1;
2402 /* True if we've tried to read the file table and found there isn't one.
2403 There will be no point in trying to read it again next time. */
2404 unsigned int no_file_data
: 1;
2407 /* Utility hash function for a stmt_list_hash. */
2410 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2414 if (stmt_list_hash
->dwo_unit
!= NULL
)
2415 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2416 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2420 /* Utility equality function for a stmt_list_hash. */
2423 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2424 const struct stmt_list_hash
*rhs
)
2426 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2428 if (lhs
->dwo_unit
!= NULL
2429 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2432 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2435 /* Hash function for a quick_file_names. */
2438 hash_file_name_entry (const void *e
)
2440 const struct quick_file_names
*file_data
2441 = (const struct quick_file_names
*) e
;
2443 return hash_stmt_list_entry (&file_data
->hash
);
2446 /* Equality function for a quick_file_names. */
2449 eq_file_name_entry (const void *a
, const void *b
)
2451 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2452 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2454 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2457 /* Delete function for a quick_file_names. */
2460 delete_file_name_entry (void *e
)
2462 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2465 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2467 xfree ((void*) file_data
->file_names
[i
]);
2468 if (file_data
->real_names
)
2469 xfree ((void*) file_data
->real_names
[i
]);
2472 /* The space for the struct itself lives on the obstack, so we don't
2476 /* Create a quick_file_names hash table. */
2479 create_quick_file_names_table (unsigned int nr_initial_entries
)
2481 return htab_up (htab_create_alloc (nr_initial_entries
,
2482 hash_file_name_entry
, eq_file_name_entry
,
2483 delete_file_name_entry
, xcalloc
, xfree
));
2486 /* Read in CU (dwarf2_cu object) for PER_CU in the context of PER_OBJFILE. This
2487 function is unrelated to symtabs, symtab would have to be created afterwards.
2488 You should call age_cached_comp_units after processing the CU. */
2491 load_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
2494 if (per_cu
->is_debug_types
)
2495 load_full_type_unit (per_cu
, per_objfile
);
2497 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
2498 skip_partial
, language_minimal
);
2500 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
2502 return nullptr; /* Dummy CU. */
2504 dwarf2_find_base_address (cu
->dies
, cu
);
2509 /* Read in the symbols for PER_CU in the context of PER_OBJFILE. */
2512 dw2_do_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2513 dwarf2_per_objfile
*per_objfile
, bool skip_partial
)
2515 /* Skip type_unit_groups, reading the type units they contain
2516 is handled elsewhere. */
2517 if (per_cu
->type_unit_group_p ())
2520 /* The destructor of dwarf2_queue_guard frees any entries left on
2521 the queue. After this point we're guaranteed to leave this function
2522 with the dwarf queue empty. */
2523 dwarf2_queue_guard
q_guard (per_objfile
);
2525 if (!per_objfile
->symtab_set_p (per_cu
))
2527 queue_comp_unit (per_cu
, per_objfile
, language_minimal
);
2528 dwarf2_cu
*cu
= load_cu (per_cu
, per_objfile
, skip_partial
);
2530 /* If we just loaded a CU from a DWO, and we're working with an index
2531 that may badly handle TUs, load all the TUs in that DWO as well.
2532 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2533 if (!per_cu
->is_debug_types
2535 && cu
->dwo_unit
!= NULL
2536 && per_objfile
->per_bfd
->index_table
!= NULL
2537 && per_objfile
->per_bfd
->index_table
->version
<= 7
2538 /* DWP files aren't supported yet. */
2539 && get_dwp_file (per_objfile
) == NULL
)
2540 queue_and_load_all_dwo_tus (cu
);
2543 process_queue (per_objfile
);
2545 /* Age the cache, releasing compilation units that have not
2546 been used recently. */
2547 per_objfile
->age_comp_units ();
2550 /* Ensure that the symbols for PER_CU have been read in. DWARF2_PER_OBJFILE is
2551 the per-objfile for which this symtab is instantiated.
2553 Returns the resulting symbol table. */
2555 static struct compunit_symtab
*
2556 dw2_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2557 dwarf2_per_objfile
*per_objfile
,
2560 gdb_assert (per_objfile
->per_bfd
->using_index
);
2562 if (!per_objfile
->symtab_set_p (per_cu
))
2564 free_cached_comp_units
freer (per_objfile
);
2565 scoped_restore decrementer
= increment_reading_symtab ();
2566 dw2_do_instantiate_symtab (per_cu
, per_objfile
, skip_partial
);
2567 process_cu_includes (per_objfile
);
2570 return per_objfile
->get_symtab (per_cu
);
2573 /* See declaration. */
2575 dwarf2_per_cu_data
*
2576 dwarf2_per_bfd::get_cutu (int index
)
2578 if (index
>= this->all_comp_units
.size ())
2580 index
-= this->all_comp_units
.size ();
2581 gdb_assert (index
< this->all_type_units
.size ());
2582 return &this->all_type_units
[index
]->per_cu
;
2585 return this->all_comp_units
[index
];
2588 /* See declaration. */
2590 dwarf2_per_cu_data
*
2591 dwarf2_per_bfd::get_cu (int index
)
2593 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2595 return this->all_comp_units
[index
];
2598 /* See declaration. */
2601 dwarf2_per_bfd::get_tu (int index
)
2603 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2605 return this->all_type_units
[index
];
2610 dwarf2_per_cu_data
*
2611 dwarf2_per_bfd::allocate_per_cu ()
2613 dwarf2_per_cu_data
*result
= OBSTACK_ZALLOC (&obstack
, dwarf2_per_cu_data
);
2614 result
->per_bfd
= this;
2615 result
->index
= m_num_psymtabs
++;
2622 dwarf2_per_bfd::allocate_signatured_type ()
2624 signatured_type
*result
= OBSTACK_ZALLOC (&obstack
, signatured_type
);
2625 result
->per_cu
.per_bfd
= this;
2626 result
->per_cu
.index
= m_num_psymtabs
++;
2630 /* Return a new dwarf2_per_cu_data allocated on the per-bfd
2631 obstack, and constructed with the specified field values. */
2633 static dwarf2_per_cu_data
*
2634 create_cu_from_index_list (dwarf2_per_bfd
*per_bfd
,
2635 struct dwarf2_section_info
*section
,
2637 sect_offset sect_off
, ULONGEST length
)
2639 dwarf2_per_cu_data
*the_cu
= per_bfd
->allocate_per_cu ();
2640 the_cu
->sect_off
= sect_off
;
2641 the_cu
->length
= length
;
2642 the_cu
->section
= section
;
2643 the_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
2644 struct dwarf2_per_cu_quick_data
);
2645 the_cu
->is_dwz
= is_dwz
;
2649 /* A helper for create_cus_from_index that handles a given list of
2653 create_cus_from_index_list (dwarf2_per_bfd
*per_bfd
,
2654 const gdb_byte
*cu_list
, offset_type n_elements
,
2655 struct dwarf2_section_info
*section
,
2658 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2660 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2662 sect_offset sect_off
2663 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2664 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2667 dwarf2_per_cu_data
*per_cu
2668 = create_cu_from_index_list (per_bfd
, section
, is_dwz
, sect_off
,
2670 per_bfd
->all_comp_units
.push_back (per_cu
);
2674 /* Read the CU list from the mapped index, and use it to create all
2675 the CU objects for PER_BFD. */
2678 create_cus_from_index (dwarf2_per_bfd
*per_bfd
,
2679 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2680 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2682 gdb_assert (per_bfd
->all_comp_units
.empty ());
2683 per_bfd
->all_comp_units
.reserve ((cu_list_elements
+ dwz_elements
) / 2);
2685 create_cus_from_index_list (per_bfd
, cu_list
, cu_list_elements
,
2688 if (dwz_elements
== 0)
2691 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
2692 create_cus_from_index_list (per_bfd
, dwz_list
, dwz_elements
,
2696 /* Create the signatured type hash table from the index. */
2699 create_signatured_type_table_from_index
2700 (dwarf2_per_bfd
*per_bfd
, struct dwarf2_section_info
*section
,
2701 const gdb_byte
*bytes
, offset_type elements
)
2703 gdb_assert (per_bfd
->all_type_units
.empty ());
2704 per_bfd
->all_type_units
.reserve (elements
/ 3);
2706 htab_up sig_types_hash
= allocate_signatured_type_table ();
2708 for (offset_type i
= 0; i
< elements
; i
+= 3)
2710 struct signatured_type
*sig_type
;
2713 cu_offset type_offset_in_tu
;
2715 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2716 sect_offset sect_off
2717 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2719 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2721 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2724 sig_type
= per_bfd
->allocate_signatured_type ();
2725 sig_type
->signature
= signature
;
2726 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2727 sig_type
->per_cu
.is_debug_types
= 1;
2728 sig_type
->per_cu
.section
= section
;
2729 sig_type
->per_cu
.sect_off
= sect_off
;
2730 sig_type
->per_cu
.v
.quick
2731 = OBSTACK_ZALLOC (&per_bfd
->obstack
,
2732 struct dwarf2_per_cu_quick_data
);
2734 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2737 per_bfd
->all_type_units
.push_back (sig_type
);
2740 per_bfd
->signatured_types
= std::move (sig_types_hash
);
2743 /* Create the signatured type hash table from .debug_names. */
2746 create_signatured_type_table_from_debug_names
2747 (dwarf2_per_objfile
*per_objfile
,
2748 const mapped_debug_names
&map
,
2749 struct dwarf2_section_info
*section
,
2750 struct dwarf2_section_info
*abbrev_section
)
2752 struct objfile
*objfile
= per_objfile
->objfile
;
2754 section
->read (objfile
);
2755 abbrev_section
->read (objfile
);
2757 gdb_assert (per_objfile
->per_bfd
->all_type_units
.empty ());
2758 per_objfile
->per_bfd
->all_type_units
.reserve (map
.tu_count
);
2760 htab_up sig_types_hash
= allocate_signatured_type_table ();
2762 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2764 struct signatured_type
*sig_type
;
2767 sect_offset sect_off
2768 = (sect_offset
) (extract_unsigned_integer
2769 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2771 map
.dwarf5_byte_order
));
2773 comp_unit_head cu_header
;
2774 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
2776 section
->buffer
+ to_underlying (sect_off
),
2779 sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
2780 sig_type
->signature
= cu_header
.signature
;
2781 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2782 sig_type
->per_cu
.is_debug_types
= 1;
2783 sig_type
->per_cu
.section
= section
;
2784 sig_type
->per_cu
.sect_off
= sect_off
;
2785 sig_type
->per_cu
.v
.quick
2786 = OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
2787 struct dwarf2_per_cu_quick_data
);
2789 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2792 per_objfile
->per_bfd
->all_type_units
.push_back (sig_type
);
2795 per_objfile
->per_bfd
->signatured_types
= std::move (sig_types_hash
);
2798 /* Read the address map data from the mapped index, and use it to
2799 populate the objfile's psymtabs_addrmap. */
2802 create_addrmap_from_index (dwarf2_per_objfile
*per_objfile
,
2803 struct mapped_index
*index
)
2805 struct objfile
*objfile
= per_objfile
->objfile
;
2806 struct gdbarch
*gdbarch
= objfile
->arch ();
2807 const gdb_byte
*iter
, *end
;
2808 struct addrmap
*mutable_map
;
2811 auto_obstack temp_obstack
;
2813 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2815 iter
= index
->address_table
.data ();
2816 end
= iter
+ index
->address_table
.size ();
2818 baseaddr
= objfile
->text_section_offset ();
2822 ULONGEST hi
, lo
, cu_index
;
2823 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2825 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2827 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2832 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2833 hex_string (lo
), hex_string (hi
));
2837 if (cu_index
>= per_objfile
->per_bfd
->all_comp_units
.size ())
2839 complaint (_(".gdb_index address table has invalid CU number %u"),
2840 (unsigned) cu_index
);
2844 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2845 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2846 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2847 per_objfile
->per_bfd
->get_cu (cu_index
));
2850 objfile
->partial_symtabs
->psymtabs_addrmap
2851 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2854 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2855 populate the objfile's psymtabs_addrmap. */
2858 create_addrmap_from_aranges (dwarf2_per_objfile
*per_objfile
,
2859 struct dwarf2_section_info
*section
)
2861 struct objfile
*objfile
= per_objfile
->objfile
;
2862 bfd
*abfd
= objfile
->obfd
;
2863 struct gdbarch
*gdbarch
= objfile
->arch ();
2864 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2866 auto_obstack temp_obstack
;
2867 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2869 std::unordered_map
<sect_offset
,
2870 dwarf2_per_cu_data
*,
2871 gdb::hash_enum
<sect_offset
>>
2872 debug_info_offset_to_per_cu
;
2873 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
2875 const auto insertpair
2876 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
2877 if (!insertpair
.second
)
2879 warning (_("Section .debug_aranges in %s has duplicate "
2880 "debug_info_offset %s, ignoring .debug_aranges."),
2881 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2886 section
->read (objfile
);
2888 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2890 const gdb_byte
*addr
= section
->buffer
;
2892 while (addr
< section
->buffer
+ section
->size
)
2894 const gdb_byte
*const entry_addr
= addr
;
2895 unsigned int bytes_read
;
2897 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2901 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2902 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2903 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2904 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2906 warning (_("Section .debug_aranges in %s entry at offset %s "
2907 "length %s exceeds section length %s, "
2908 "ignoring .debug_aranges."),
2909 objfile_name (objfile
),
2910 plongest (entry_addr
- section
->buffer
),
2911 plongest (bytes_read
+ entry_length
),
2912 pulongest (section
->size
));
2916 /* The version number. */
2917 const uint16_t version
= read_2_bytes (abfd
, addr
);
2921 warning (_("Section .debug_aranges in %s entry at offset %s "
2922 "has unsupported version %d, ignoring .debug_aranges."),
2923 objfile_name (objfile
),
2924 plongest (entry_addr
- section
->buffer
), version
);
2928 const uint64_t debug_info_offset
2929 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2930 addr
+= offset_size
;
2931 const auto per_cu_it
2932 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2933 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2935 warning (_("Section .debug_aranges in %s entry at offset %s "
2936 "debug_info_offset %s does not exists, "
2937 "ignoring .debug_aranges."),
2938 objfile_name (objfile
),
2939 plongest (entry_addr
- section
->buffer
),
2940 pulongest (debug_info_offset
));
2943 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2945 const uint8_t address_size
= *addr
++;
2946 if (address_size
< 1 || address_size
> 8)
2948 warning (_("Section .debug_aranges in %s entry at offset %s "
2949 "address_size %u is invalid, ignoring .debug_aranges."),
2950 objfile_name (objfile
),
2951 plongest (entry_addr
- section
->buffer
), address_size
);
2955 const uint8_t segment_selector_size
= *addr
++;
2956 if (segment_selector_size
!= 0)
2958 warning (_("Section .debug_aranges in %s entry at offset %s "
2959 "segment_selector_size %u is not supported, "
2960 "ignoring .debug_aranges."),
2961 objfile_name (objfile
),
2962 plongest (entry_addr
- section
->buffer
),
2963 segment_selector_size
);
2967 /* Must pad to an alignment boundary that is twice the address
2968 size. It is undocumented by the DWARF standard but GCC does
2970 for (size_t padding
= ((-(addr
- section
->buffer
))
2971 & (2 * address_size
- 1));
2972 padding
> 0; padding
--)
2975 warning (_("Section .debug_aranges in %s entry at offset %s "
2976 "padding is not zero, ignoring .debug_aranges."),
2977 objfile_name (objfile
),
2978 plongest (entry_addr
- section
->buffer
));
2984 if (addr
+ 2 * address_size
> entry_end
)
2986 warning (_("Section .debug_aranges in %s entry at offset %s "
2987 "address list is not properly terminated, "
2988 "ignoring .debug_aranges."),
2989 objfile_name (objfile
),
2990 plongest (entry_addr
- section
->buffer
));
2993 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
2995 addr
+= address_size
;
2996 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
2998 addr
+= address_size
;
2999 if (start
== 0 && length
== 0)
3001 if (start
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
3003 /* Symbol was eliminated due to a COMDAT group. */
3006 ULONGEST end
= start
+ length
;
3007 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
3009 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
3011 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
3015 objfile
->partial_symtabs
->psymtabs_addrmap
3016 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
3019 /* Find a slot in the mapped index INDEX for the object named NAME.
3020 If NAME is found, set *VEC_OUT to point to the CU vector in the
3021 constant pool and return true. If NAME cannot be found, return
3025 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
3026 offset_type
**vec_out
)
3029 offset_type slot
, step
;
3030 int (*cmp
) (const char *, const char *);
3032 gdb::unique_xmalloc_ptr
<char> without_params
;
3033 if (current_language
->la_language
== language_cplus
3034 || current_language
->la_language
== language_fortran
3035 || current_language
->la_language
== language_d
)
3037 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
3040 if (strchr (name
, '(') != NULL
)
3042 without_params
= cp_remove_params (name
);
3044 if (without_params
!= NULL
)
3045 name
= without_params
.get ();
3049 /* Index version 4 did not support case insensitive searches. But the
3050 indices for case insensitive languages are built in lowercase, therefore
3051 simulate our NAME being searched is also lowercased. */
3052 hash
= mapped_index_string_hash ((index
->version
== 4
3053 && case_sensitivity
== case_sensitive_off
3054 ? 5 : index
->version
),
3057 slot
= hash
& (index
->symbol_table
.size () - 1);
3058 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
3059 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
3065 const auto &bucket
= index
->symbol_table
[slot
];
3066 if (bucket
.name
== 0 && bucket
.vec
== 0)
3069 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
3070 if (!cmp (name
, str
))
3072 *vec_out
= (offset_type
*) (index
->constant_pool
3073 + MAYBE_SWAP (bucket
.vec
));
3077 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
3081 /* A helper function that reads the .gdb_index from BUFFER and fills
3082 in MAP. FILENAME is the name of the file containing the data;
3083 it is used for error reporting. DEPRECATED_OK is true if it is
3084 ok to use deprecated sections.
3086 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
3087 out parameters that are filled in with information about the CU and
3088 TU lists in the section.
3090 Returns true if all went well, false otherwise. */
3093 read_gdb_index_from_buffer (const char *filename
,
3095 gdb::array_view
<const gdb_byte
> buffer
,
3096 struct mapped_index
*map
,
3097 const gdb_byte
**cu_list
,
3098 offset_type
*cu_list_elements
,
3099 const gdb_byte
**types_list
,
3100 offset_type
*types_list_elements
)
3102 const gdb_byte
*addr
= &buffer
[0];
3104 /* Version check. */
3105 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
3106 /* Versions earlier than 3 emitted every copy of a psymbol. This
3107 causes the index to behave very poorly for certain requests. Version 3
3108 contained incomplete addrmap. So, it seems better to just ignore such
3112 static int warning_printed
= 0;
3113 if (!warning_printed
)
3115 warning (_("Skipping obsolete .gdb_index section in %s."),
3117 warning_printed
= 1;
3121 /* Index version 4 uses a different hash function than index version
3124 Versions earlier than 6 did not emit psymbols for inlined
3125 functions. Using these files will cause GDB not to be able to
3126 set breakpoints on inlined functions by name, so we ignore these
3127 indices unless the user has done
3128 "set use-deprecated-index-sections on". */
3129 if (version
< 6 && !deprecated_ok
)
3131 static int warning_printed
= 0;
3132 if (!warning_printed
)
3135 Skipping deprecated .gdb_index section in %s.\n\
3136 Do \"set use-deprecated-index-sections on\" before the file is read\n\
3137 to use the section anyway."),
3139 warning_printed
= 1;
3143 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3144 of the TU (for symbols coming from TUs),
3145 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3146 Plus gold-generated indices can have duplicate entries for global symbols,
3147 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3148 These are just performance bugs, and we can't distinguish gdb-generated
3149 indices from gold-generated ones, so issue no warning here. */
3151 /* Indexes with higher version than the one supported by GDB may be no
3152 longer backward compatible. */
3156 map
->version
= version
;
3158 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3161 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3162 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3166 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3167 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3168 - MAYBE_SWAP (metadata
[i
]))
3172 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3173 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3175 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
3178 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3179 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3181 = gdb::array_view
<mapped_index::symbol_table_slot
>
3182 ((mapped_index::symbol_table_slot
*) symbol_table
,
3183 (mapped_index::symbol_table_slot
*) symbol_table_end
);
3186 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3191 /* Callback types for dwarf2_read_gdb_index. */
3193 typedef gdb::function_view
3194 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_bfd
*)>
3195 get_gdb_index_contents_ftype
;
3196 typedef gdb::function_view
3197 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
3198 get_gdb_index_contents_dwz_ftype
;
3200 /* Read .gdb_index. If everything went ok, initialize the "quick"
3201 elements of all the CUs and return 1. Otherwise, return 0. */
3204 dwarf2_read_gdb_index
3205 (dwarf2_per_objfile
*per_objfile
,
3206 get_gdb_index_contents_ftype get_gdb_index_contents
,
3207 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
3209 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3210 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3211 struct dwz_file
*dwz
;
3212 struct objfile
*objfile
= per_objfile
->objfile
;
3213 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
3215 gdb::array_view
<const gdb_byte
> main_index_contents
3216 = get_gdb_index_contents (objfile
, per_bfd
);
3218 if (main_index_contents
.empty ())
3221 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3222 if (!read_gdb_index_from_buffer (objfile_name (objfile
),
3223 use_deprecated_index_sections
,
3224 main_index_contents
, map
.get (), &cu_list
,
3225 &cu_list_elements
, &types_list
,
3226 &types_list_elements
))
3229 /* Don't use the index if it's empty. */
3230 if (map
->symbol_table
.empty ())
3233 /* If there is a .dwz file, read it so we can get its CU list as
3235 dwz
= dwarf2_get_dwz_file (per_bfd
);
3238 struct mapped_index dwz_map
;
3239 const gdb_byte
*dwz_types_ignore
;
3240 offset_type dwz_types_elements_ignore
;
3242 gdb::array_view
<const gdb_byte
> dwz_index_content
3243 = get_gdb_index_contents_dwz (objfile
, dwz
);
3245 if (dwz_index_content
.empty ())
3248 if (!read_gdb_index_from_buffer (bfd_get_filename (dwz
->dwz_bfd
.get ()),
3249 1, dwz_index_content
, &dwz_map
,
3250 &dwz_list
, &dwz_list_elements
,
3252 &dwz_types_elements_ignore
))
3254 warning (_("could not read '.gdb_index' section from %s; skipping"),
3255 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3260 create_cus_from_index (per_bfd
, cu_list
, cu_list_elements
, dwz_list
,
3263 if (types_list_elements
)
3265 /* We can only handle a single .debug_types when we have an
3267 if (per_bfd
->types
.size () != 1)
3270 dwarf2_section_info
*section
= &per_bfd
->types
[0];
3272 create_signatured_type_table_from_index (per_bfd
, section
, types_list
,
3273 types_list_elements
);
3276 create_addrmap_from_index (per_objfile
, map
.get ());
3278 per_bfd
->index_table
= std::move (map
);
3279 per_bfd
->using_index
= 1;
3280 per_bfd
->quick_file_names_table
=
3281 create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
3283 /* Save partial symtabs in the per_bfd object, for the benefit of subsequent
3284 objfiles using the same BFD. */
3285 gdb_assert (per_bfd
->partial_symtabs
== nullptr);
3286 per_bfd
->partial_symtabs
= objfile
->partial_symtabs
;
3291 /* die_reader_func for dw2_get_file_names. */
3294 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3295 const gdb_byte
*info_ptr
,
3296 struct die_info
*comp_unit_die
)
3298 struct dwarf2_cu
*cu
= reader
->cu
;
3299 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3300 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
3301 struct dwarf2_per_cu_data
*lh_cu
;
3302 struct attribute
*attr
;
3304 struct quick_file_names
*qfn
;
3306 gdb_assert (! this_cu
->is_debug_types
);
3308 /* Our callers never want to match partial units -- instead they
3309 will match the enclosing full CU. */
3310 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3312 this_cu
->v
.quick
->no_file_data
= 1;
3320 sect_offset line_offset
{};
3322 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3323 if (attr
!= nullptr && attr
->form_is_unsigned ())
3325 struct quick_file_names find_entry
;
3327 line_offset
= (sect_offset
) attr
->as_unsigned ();
3329 /* We may have already read in this line header (TU line header sharing).
3330 If we have we're done. */
3331 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3332 find_entry
.hash
.line_sect_off
= line_offset
;
3333 slot
= htab_find_slot (per_objfile
->per_bfd
->quick_file_names_table
.get (),
3334 &find_entry
, INSERT
);
3337 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3341 lh
= dwarf_decode_line_header (line_offset
, cu
);
3345 lh_cu
->v
.quick
->no_file_data
= 1;
3349 qfn
= XOBNEW (&per_objfile
->per_bfd
->obstack
, struct quick_file_names
);
3350 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3351 qfn
->hash
.line_sect_off
= line_offset
;
3352 gdb_assert (slot
!= NULL
);
3355 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3358 if (strcmp (fnd
.name
, "<unknown>") != 0)
3361 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3363 XOBNEWVEC (&per_objfile
->per_bfd
->obstack
, const char *,
3364 qfn
->num_file_names
);
3366 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3367 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3368 qfn
->file_names
[i
+ offset
] = lh
->file_full_name (i
+ 1,
3369 fnd
.comp_dir
).release ();
3370 qfn
->real_names
= NULL
;
3372 lh_cu
->v
.quick
->file_names
= qfn
;
3375 /* A helper for the "quick" functions which attempts to read the line
3376 table for THIS_CU. */
3378 static struct quick_file_names
*
3379 dw2_get_file_names (dwarf2_per_cu_data
*this_cu
,
3380 dwarf2_per_objfile
*per_objfile
)
3382 /* This should never be called for TUs. */
3383 gdb_assert (! this_cu
->is_debug_types
);
3384 /* Nor type unit groups. */
3385 gdb_assert (! this_cu
->type_unit_group_p ());
3387 if (this_cu
->v
.quick
->file_names
!= NULL
)
3388 return this_cu
->v
.quick
->file_names
;
3389 /* If we know there is no line data, no point in looking again. */
3390 if (this_cu
->v
.quick
->no_file_data
)
3393 cutu_reader
reader (this_cu
, per_objfile
);
3394 if (!reader
.dummy_p
)
3395 dw2_get_file_names_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
);
3397 if (this_cu
->v
.quick
->no_file_data
)
3399 return this_cu
->v
.quick
->file_names
;
3402 /* A helper for the "quick" functions which computes and caches the
3403 real path for a given file name from the line table. */
3406 dw2_get_real_path (dwarf2_per_objfile
*per_objfile
,
3407 struct quick_file_names
*qfn
, int index
)
3409 if (qfn
->real_names
== NULL
)
3410 qfn
->real_names
= OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
3411 qfn
->num_file_names
, const char *);
3413 if (qfn
->real_names
[index
] == NULL
)
3414 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3416 return qfn
->real_names
[index
];
3419 static struct symtab
*
3420 dw2_find_last_source_symtab (struct objfile
*objfile
)
3422 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3423 dwarf2_per_cu_data
*dwarf_cu
= per_objfile
->per_bfd
->all_comp_units
.back ();
3424 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, per_objfile
, false);
3429 return compunit_primary_filetab (cust
);
3432 /* Traversal function for dw2_forget_cached_source_info. */
3435 dw2_free_cached_file_names (void **slot
, void *info
)
3437 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3439 if (file_data
->real_names
)
3443 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3445 xfree ((void*) file_data
->real_names
[i
]);
3446 file_data
->real_names
[i
] = NULL
;
3454 dw2_forget_cached_source_info (struct objfile
*objfile
)
3456 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3458 htab_traverse_noresize (per_objfile
->per_bfd
->quick_file_names_table
.get (),
3459 dw2_free_cached_file_names
, NULL
);
3462 /* Helper function for dw2_map_symtabs_matching_filename that expands
3463 the symtabs and calls the iterator. */
3466 dw2_map_expand_apply (struct objfile
*objfile
,
3467 struct dwarf2_per_cu_data
*per_cu
,
3468 const char *name
, const char *real_path
,
3469 gdb::function_view
<bool (symtab
*)> callback
)
3471 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3473 /* Don't visit already-expanded CUs. */
3474 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3475 if (per_objfile
->symtab_set_p (per_cu
))
3478 /* This may expand more than one symtab, and we want to iterate over
3480 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3482 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3483 last_made
, callback
);
3486 /* Implementation of the map_symtabs_matching_filename method. */
3489 dw2_map_symtabs_matching_filename
3490 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3491 gdb::function_view
<bool (symtab
*)> callback
)
3493 const char *name_basename
= lbasename (name
);
3494 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3496 /* The rule is CUs specify all the files, including those used by
3497 any TU, so there's no need to scan TUs here. */
3499 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
3501 /* We only need to look at symtabs not already expanded. */
3502 if (per_objfile
->symtab_set_p (per_cu
))
3505 quick_file_names
*file_data
= dw2_get_file_names (per_cu
, per_objfile
);
3506 if (file_data
== NULL
)
3509 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3511 const char *this_name
= file_data
->file_names
[j
];
3512 const char *this_real_name
;
3514 if (compare_filenames_for_search (this_name
, name
))
3516 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3522 /* Before we invoke realpath, which can get expensive when many
3523 files are involved, do a quick comparison of the basenames. */
3524 if (! basenames_may_differ
3525 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3528 this_real_name
= dw2_get_real_path (per_objfile
, file_data
, j
);
3529 if (compare_filenames_for_search (this_real_name
, name
))
3531 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3537 if (real_path
!= NULL
)
3539 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3540 gdb_assert (IS_ABSOLUTE_PATH (name
));
3541 if (this_real_name
!= NULL
3542 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3544 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3556 /* Struct used to manage iterating over all CUs looking for a symbol. */
3558 struct dw2_symtab_iterator
3560 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3561 dwarf2_per_objfile
*per_objfile
;
3562 /* If set, only look for symbols that match that block. Valid values are
3563 GLOBAL_BLOCK and STATIC_BLOCK. */
3564 gdb::optional
<block_enum
> block_index
;
3565 /* The kind of symbol we're looking for. */
3567 /* The list of CUs from the index entry of the symbol,
3568 or NULL if not found. */
3570 /* The next element in VEC to look at. */
3572 /* The number of elements in VEC, or zero if there is no match. */
3574 /* Have we seen a global version of the symbol?
3575 If so we can ignore all further global instances.
3576 This is to work around gold/15646, inefficient gold-generated
3581 /* Initialize the index symtab iterator ITER, common part. */
3584 dw2_symtab_iter_init_common (struct dw2_symtab_iterator
*iter
,
3585 dwarf2_per_objfile
*per_objfile
,
3586 gdb::optional
<block_enum
> block_index
,
3589 iter
->per_objfile
= per_objfile
;
3590 iter
->block_index
= block_index
;
3591 iter
->domain
= domain
;
3593 iter
->global_seen
= 0;
3598 /* Initialize the index symtab iterator ITER, const char *NAME variant. */
3601 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3602 dwarf2_per_objfile
*per_objfile
,
3603 gdb::optional
<block_enum
> block_index
,
3607 dw2_symtab_iter_init_common (iter
, per_objfile
, block_index
, domain
);
3609 mapped_index
*index
= per_objfile
->per_bfd
->index_table
.get ();
3610 /* index is NULL if OBJF_READNOW. */
3614 if (find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3615 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3618 /* Initialize the index symtab iterator ITER, offset_type NAMEI variant. */
3621 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3622 dwarf2_per_objfile
*per_objfile
,
3623 gdb::optional
<block_enum
> block_index
,
3624 domain_enum domain
, offset_type namei
)
3626 dw2_symtab_iter_init_common (iter
, per_objfile
, block_index
, domain
);
3628 mapped_index
*index
= per_objfile
->per_bfd
->index_table
.get ();
3629 /* index is NULL if OBJF_READNOW. */
3633 gdb_assert (!index
->symbol_name_slot_invalid (namei
));
3634 const auto &bucket
= index
->symbol_table
[namei
];
3636 iter
->vec
= (offset_type
*) (index
->constant_pool
3637 + MAYBE_SWAP (bucket
.vec
));
3638 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3641 /* Return the next matching CU or NULL if there are no more. */
3643 static struct dwarf2_per_cu_data
*
3644 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3646 dwarf2_per_objfile
*per_objfile
= iter
->per_objfile
;
3648 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3650 offset_type cu_index_and_attrs
=
3651 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3652 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3653 gdb_index_symbol_kind symbol_kind
=
3654 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3655 /* Only check the symbol attributes if they're present.
3656 Indices prior to version 7 don't record them,
3657 and indices >= 7 may elide them for certain symbols
3658 (gold does this). */
3660 (per_objfile
->per_bfd
->index_table
->version
>= 7
3661 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3663 /* Don't crash on bad data. */
3664 if (cu_index
>= (per_objfile
->per_bfd
->all_comp_units
.size ()
3665 + per_objfile
->per_bfd
->all_type_units
.size ()))
3667 complaint (_(".gdb_index entry has bad CU index"
3668 " [in module %s]"), objfile_name (per_objfile
->objfile
));
3672 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (cu_index
);
3674 /* Skip if already read in. */
3675 if (per_objfile
->symtab_set_p (per_cu
))
3678 /* Check static vs global. */
3681 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3683 if (iter
->block_index
.has_value ())
3685 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3687 if (is_static
!= want_static
)
3691 /* Work around gold/15646. */
3693 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
3695 if (iter
->global_seen
)
3698 iter
->global_seen
= 1;
3702 /* Only check the symbol's kind if it has one. */
3705 switch (iter
->domain
)
3708 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3709 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3710 /* Some types are also in VAR_DOMAIN. */
3711 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3715 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3719 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3723 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3738 static struct compunit_symtab
*
3739 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
3740 const char *name
, domain_enum domain
)
3742 struct compunit_symtab
*stab_best
= NULL
;
3743 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3745 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
3747 struct dw2_symtab_iterator iter
;
3748 struct dwarf2_per_cu_data
*per_cu
;
3750 dw2_symtab_iter_init (&iter
, per_objfile
, block_index
, domain
, name
);
3752 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3754 struct symbol
*sym
, *with_opaque
= NULL
;
3755 struct compunit_symtab
*stab
3756 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3757 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
3758 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3760 sym
= block_find_symbol (block
, name
, domain
,
3761 block_find_non_opaque_type_preferred
,
3764 /* Some caution must be observed with overloaded functions
3765 and methods, since the index will not contain any overload
3766 information (but NAME might contain it). */
3769 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
3771 if (with_opaque
!= NULL
3772 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
3775 /* Keep looking through other CUs. */
3782 dw2_print_stats (struct objfile
*objfile
)
3784 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3785 int total
= (per_objfile
->per_bfd
->all_comp_units
.size ()
3786 + per_objfile
->per_bfd
->all_type_units
.size ());
3789 for (int i
= 0; i
< total
; ++i
)
3791 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (i
);
3793 if (!per_objfile
->symtab_set_p (per_cu
))
3796 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3797 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3800 /* This dumps minimal information about the index.
3801 It is called via "mt print objfiles".
3802 One use is to verify .gdb_index has been loaded by the
3803 gdb.dwarf2/gdb-index.exp testcase. */
3806 dw2_dump (struct objfile
*objfile
)
3808 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3810 gdb_assert (per_objfile
->per_bfd
->using_index
);
3811 printf_filtered (".gdb_index:");
3812 if (per_objfile
->per_bfd
->index_table
!= NULL
)
3814 printf_filtered (" version %d\n",
3815 per_objfile
->per_bfd
->index_table
->version
);
3818 printf_filtered (" faked for \"readnow\"\n");
3819 printf_filtered ("\n");
3823 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3824 const char *func_name
)
3826 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3828 struct dw2_symtab_iterator iter
;
3829 struct dwarf2_per_cu_data
*per_cu
;
3831 dw2_symtab_iter_init (&iter
, per_objfile
, {}, VAR_DOMAIN
, func_name
);
3833 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3834 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3839 dw2_expand_all_symtabs (struct objfile
*objfile
)
3841 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3842 int total_units
= (per_objfile
->per_bfd
->all_comp_units
.size ()
3843 + per_objfile
->per_bfd
->all_type_units
.size ());
3845 for (int i
= 0; i
< total_units
; ++i
)
3847 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (i
);
3849 /* We don't want to directly expand a partial CU, because if we
3850 read it with the wrong language, then assertion failures can
3851 be triggered later on. See PR symtab/23010. So, tell
3852 dw2_instantiate_symtab to skip partial CUs -- any important
3853 partial CU will be read via DW_TAG_imported_unit anyway. */
3854 dw2_instantiate_symtab (per_cu
, per_objfile
, true);
3859 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
3860 const char *fullname
)
3862 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3864 /* We don't need to consider type units here.
3865 This is only called for examining code, e.g. expand_line_sal.
3866 There can be an order of magnitude (or more) more type units
3867 than comp units, and we avoid them if we can. */
3869 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
3871 /* We only need to look at symtabs not already expanded. */
3872 if (per_objfile
->symtab_set_p (per_cu
))
3875 quick_file_names
*file_data
= dw2_get_file_names (per_cu
, per_objfile
);
3876 if (file_data
== NULL
)
3879 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3881 const char *this_fullname
= file_data
->file_names
[j
];
3883 if (filename_cmp (this_fullname
, fullname
) == 0)
3885 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3893 dw2_expand_symtabs_matching_symbol
3894 (mapped_index_base
&index
,
3895 const lookup_name_info
&lookup_name_in
,
3896 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3897 enum search_domain kind
,
3898 gdb::function_view
<bool (offset_type
)> match_callback
,
3899 dwarf2_per_objfile
*per_objfile
);
3902 dw2_expand_symtabs_matching_one
3903 (dwarf2_per_cu_data
*per_cu
,
3904 dwarf2_per_objfile
*per_objfile
,
3905 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
3906 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
);
3909 dw2_map_matching_symbols
3910 (struct objfile
*objfile
,
3911 const lookup_name_info
&name
, domain_enum domain
,
3913 gdb::function_view
<symbol_found_callback_ftype
> callback
,
3914 symbol_compare_ftype
*ordered_compare
)
3917 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3919 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
3921 if (per_objfile
->per_bfd
->index_table
!= nullptr)
3923 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
3925 const char *match_name
= name
.ada ().lookup_name ().c_str ();
3926 auto matcher
= [&] (const char *symname
)
3928 if (ordered_compare
== nullptr)
3930 return ordered_compare (symname
, match_name
) == 0;
3933 dw2_expand_symtabs_matching_symbol (index
, name
, matcher
, ALL_DOMAIN
,
3934 [&] (offset_type namei
)
3936 struct dw2_symtab_iterator iter
;
3937 struct dwarf2_per_cu_data
*per_cu
;
3939 dw2_symtab_iter_init (&iter
, per_objfile
, block_kind
, domain
,
3941 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3942 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
3949 /* We have -readnow: no .gdb_index, but no partial symtabs either. So,
3950 proceed assuming all symtabs have been read in. */
3953 for (compunit_symtab
*cust
: objfile
->compunits ())
3955 const struct block
*block
;
3959 block
= BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
3960 if (!iterate_over_symbols_terminated (block
, name
,
3966 /* Starting from a search name, return the string that finds the upper
3967 bound of all strings that start with SEARCH_NAME in a sorted name
3968 list. Returns the empty string to indicate that the upper bound is
3969 the end of the list. */
3972 make_sort_after_prefix_name (const char *search_name
)
3974 /* When looking to complete "func", we find the upper bound of all
3975 symbols that start with "func" by looking for where we'd insert
3976 the closest string that would follow "func" in lexicographical
3977 order. Usually, that's "func"-with-last-character-incremented,
3978 i.e. "fund". Mind non-ASCII characters, though. Usually those
3979 will be UTF-8 multi-byte sequences, but we can't be certain.
3980 Especially mind the 0xff character, which is a valid character in
3981 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3982 rule out compilers allowing it in identifiers. Note that
3983 conveniently, strcmp/strcasecmp are specified to compare
3984 characters interpreted as unsigned char. So what we do is treat
3985 the whole string as a base 256 number composed of a sequence of
3986 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3987 to 0, and carries 1 to the following more-significant position.
3988 If the very first character in SEARCH_NAME ends up incremented
3989 and carries/overflows, then the upper bound is the end of the
3990 list. The string after the empty string is also the empty
3993 Some examples of this operation:
3995 SEARCH_NAME => "+1" RESULT
3999 "\xff" "a" "\xff" => "\xff" "b"
4004 Then, with these symbols for example:
4010 completing "func" looks for symbols between "func" and
4011 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
4012 which finds "func" and "func1", but not "fund".
4016 funcÿ (Latin1 'ÿ' [0xff])
4020 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
4021 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
4025 ÿÿ (Latin1 'ÿ' [0xff])
4028 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
4029 the end of the list.
4031 std::string after
= search_name
;
4032 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
4034 if (!after
.empty ())
4035 after
.back () = (unsigned char) after
.back () + 1;
4039 /* See declaration. */
4041 std::pair
<std::vector
<name_component
>::const_iterator
,
4042 std::vector
<name_component
>::const_iterator
>
4043 mapped_index_base::find_name_components_bounds
4044 (const lookup_name_info
&lookup_name_without_params
, language lang
,
4045 dwarf2_per_objfile
*per_objfile
) const
4048 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4050 const char *lang_name
4051 = lookup_name_without_params
.language_lookup_name (lang
);
4053 /* Comparison function object for lower_bound that matches against a
4054 given symbol name. */
4055 auto lookup_compare_lower
= [&] (const name_component
&elem
,
4058 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
4059 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4060 return name_cmp (elem_name
, name
) < 0;
4063 /* Comparison function object for upper_bound that matches against a
4064 given symbol name. */
4065 auto lookup_compare_upper
= [&] (const char *name
,
4066 const name_component
&elem
)
4068 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
4069 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4070 return name_cmp (name
, elem_name
) < 0;
4073 auto begin
= this->name_components
.begin ();
4074 auto end
= this->name_components
.end ();
4076 /* Find the lower bound. */
4079 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
4082 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
4085 /* Find the upper bound. */
4088 if (lookup_name_without_params
.completion_mode ())
4090 /* In completion mode, we want UPPER to point past all
4091 symbols names that have the same prefix. I.e., with
4092 these symbols, and completing "func":
4094 function << lower bound
4096 other_function << upper bound
4098 We find the upper bound by looking for the insertion
4099 point of "func"-with-last-character-incremented,
4101 std::string after
= make_sort_after_prefix_name (lang_name
);
4104 return std::lower_bound (lower
, end
, after
.c_str (),
4105 lookup_compare_lower
);
4108 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
4111 return {lower
, upper
};
4114 /* See declaration. */
4117 mapped_index_base::build_name_components (dwarf2_per_objfile
*per_objfile
)
4119 if (!this->name_components
.empty ())
4122 this->name_components_casing
= case_sensitivity
;
4124 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4126 /* The code below only knows how to break apart components of C++
4127 symbol names (and other languages that use '::' as
4128 namespace/module separator) and Ada symbol names. */
4129 auto count
= this->symbol_name_count ();
4130 for (offset_type idx
= 0; idx
< count
; idx
++)
4132 if (this->symbol_name_slot_invalid (idx
))
4135 const char *name
= this->symbol_name_at (idx
, per_objfile
);
4137 /* Add each name component to the name component table. */
4138 unsigned int previous_len
= 0;
4140 if (strstr (name
, "::") != nullptr)
4142 for (unsigned int current_len
= cp_find_first_component (name
);
4143 name
[current_len
] != '\0';
4144 current_len
+= cp_find_first_component (name
+ current_len
))
4146 gdb_assert (name
[current_len
] == ':');
4147 this->name_components
.push_back ({previous_len
, idx
});
4148 /* Skip the '::'. */
4150 previous_len
= current_len
;
4155 /* Handle the Ada encoded (aka mangled) form here. */
4156 for (const char *iter
= strstr (name
, "__");
4158 iter
= strstr (iter
, "__"))
4160 this->name_components
.push_back ({previous_len
, idx
});
4162 previous_len
= iter
- name
;
4166 this->name_components
.push_back ({previous_len
, idx
});
4169 /* Sort name_components elements by name. */
4170 auto name_comp_compare
= [&] (const name_component
&left
,
4171 const name_component
&right
)
4173 const char *left_qualified
4174 = this->symbol_name_at (left
.idx
, per_objfile
);
4175 const char *right_qualified
4176 = this->symbol_name_at (right
.idx
, per_objfile
);
4178 const char *left_name
= left_qualified
+ left
.name_offset
;
4179 const char *right_name
= right_qualified
+ right
.name_offset
;
4181 return name_cmp (left_name
, right_name
) < 0;
4184 std::sort (this->name_components
.begin (),
4185 this->name_components
.end (),
4189 /* Helper for dw2_expand_symtabs_matching that works with a
4190 mapped_index_base instead of the containing objfile. This is split
4191 to a separate function in order to be able to unit test the
4192 name_components matching using a mock mapped_index_base. For each
4193 symbol name that matches, calls MATCH_CALLBACK, passing it the
4194 symbol's index in the mapped_index_base symbol table. */
4197 dw2_expand_symtabs_matching_symbol
4198 (mapped_index_base
&index
,
4199 const lookup_name_info
&lookup_name_in
,
4200 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4201 enum search_domain kind
,
4202 gdb::function_view
<bool (offset_type
)> match_callback
,
4203 dwarf2_per_objfile
*per_objfile
)
4205 lookup_name_info lookup_name_without_params
4206 = lookup_name_in
.make_ignore_params ();
4208 /* Build the symbol name component sorted vector, if we haven't
4210 index
.build_name_components (per_objfile
);
4212 /* The same symbol may appear more than once in the range though.
4213 E.g., if we're looking for symbols that complete "w", and we have
4214 a symbol named "w1::w2", we'll find the two name components for
4215 that same symbol in the range. To be sure we only call the
4216 callback once per symbol, we first collect the symbol name
4217 indexes that matched in a temporary vector and ignore
4219 std::vector
<offset_type
> matches
;
4221 struct name_and_matcher
4223 symbol_name_matcher_ftype
*matcher
;
4226 bool operator== (const name_and_matcher
&other
) const
4228 return matcher
== other
.matcher
&& strcmp (name
, other
.name
) == 0;
4232 /* A vector holding all the different symbol name matchers, for all
4234 std::vector
<name_and_matcher
> matchers
;
4236 for (int i
= 0; i
< nr_languages
; i
++)
4238 enum language lang_e
= (enum language
) i
;
4240 const language_defn
*lang
= language_def (lang_e
);
4241 symbol_name_matcher_ftype
*name_matcher
4242 = lang
->get_symbol_name_matcher (lookup_name_without_params
);
4244 name_and_matcher key
{
4246 lookup_name_without_params
.language_lookup_name (lang_e
)
4249 /* Don't insert the same comparison routine more than once.
4250 Note that we do this linear walk. This is not a problem in
4251 practice because the number of supported languages is
4253 if (std::find (matchers
.begin (), matchers
.end (), key
)
4256 matchers
.push_back (std::move (key
));
4259 = index
.find_name_components_bounds (lookup_name_without_params
,
4260 lang_e
, per_objfile
);
4262 /* Now for each symbol name in range, check to see if we have a name
4263 match, and if so, call the MATCH_CALLBACK callback. */
4265 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
4267 const char *qualified
4268 = index
.symbol_name_at (bounds
.first
->idx
, per_objfile
);
4270 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
4271 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4274 matches
.push_back (bounds
.first
->idx
);
4278 std::sort (matches
.begin (), matches
.end ());
4280 /* Finally call the callback, once per match. */
4282 for (offset_type idx
: matches
)
4286 if (!match_callback (idx
))
4292 /* Above we use a type wider than idx's for 'prev', since 0 and
4293 (offset_type)-1 are both possible values. */
4294 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4299 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4301 /* A mock .gdb_index/.debug_names-like name index table, enough to
4302 exercise dw2_expand_symtabs_matching_symbol, which works with the
4303 mapped_index_base interface. Builds an index from the symbol list
4304 passed as parameter to the constructor. */
4305 class mock_mapped_index
: public mapped_index_base
4308 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4309 : m_symbol_table (symbols
)
4312 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4314 /* Return the number of names in the symbol table. */
4315 size_t symbol_name_count () const override
4317 return m_symbol_table
.size ();
4320 /* Get the name of the symbol at IDX in the symbol table. */
4321 const char *symbol_name_at
4322 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
4324 return m_symbol_table
[idx
];
4328 gdb::array_view
<const char *> m_symbol_table
;
4331 /* Convenience function that converts a NULL pointer to a "<null>"
4332 string, to pass to print routines. */
4335 string_or_null (const char *str
)
4337 return str
!= NULL
? str
: "<null>";
4340 /* Check if a lookup_name_info built from
4341 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4342 index. EXPECTED_LIST is the list of expected matches, in expected
4343 matching order. If no match expected, then an empty list is
4344 specified. Returns true on success. On failure prints a warning
4345 indicating the file:line that failed, and returns false. */
4348 check_match (const char *file
, int line
,
4349 mock_mapped_index
&mock_index
,
4350 const char *name
, symbol_name_match_type match_type
,
4351 bool completion_mode
,
4352 std::initializer_list
<const char *> expected_list
,
4353 dwarf2_per_objfile
*per_objfile
)
4355 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4357 bool matched
= true;
4359 auto mismatch
= [&] (const char *expected_str
,
4362 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4363 "expected=\"%s\", got=\"%s\"\n"),
4365 (match_type
== symbol_name_match_type::FULL
4367 name
, string_or_null (expected_str
), string_or_null (got
));
4371 auto expected_it
= expected_list
.begin ();
4372 auto expected_end
= expected_list
.end ();
4374 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4376 [&] (offset_type idx
)
4378 const char *matched_name
= mock_index
.symbol_name_at (idx
, per_objfile
);
4379 const char *expected_str
4380 = expected_it
== expected_end
? NULL
: *expected_it
++;
4382 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4383 mismatch (expected_str
, matched_name
);
4387 const char *expected_str
4388 = expected_it
== expected_end
? NULL
: *expected_it
++;
4389 if (expected_str
!= NULL
)
4390 mismatch (expected_str
, NULL
);
4395 /* The symbols added to the mock mapped_index for testing (in
4397 static const char *test_symbols
[] = {
4406 "ns2::tmpl<int>::foo2",
4407 "(anonymous namespace)::A::B::C",
4409 /* These are used to check that the increment-last-char in the
4410 matching algorithm for completion doesn't match "t1_fund" when
4411 completing "t1_func". */
4417 /* A UTF-8 name with multi-byte sequences to make sure that
4418 cp-name-parser understands this as a single identifier ("função"
4419 is "function" in PT). */
4422 /* \377 (0xff) is Latin1 'ÿ'. */
4425 /* \377 (0xff) is Latin1 'ÿ'. */
4429 /* A name with all sorts of complications. Starts with "z" to make
4430 it easier for the completion tests below. */
4431 #define Z_SYM_NAME \
4432 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4433 "::tuple<(anonymous namespace)::ui*, " \
4434 "std::default_delete<(anonymous namespace)::ui>, void>"
4439 /* Returns true if the mapped_index_base::find_name_component_bounds
4440 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4441 in completion mode. */
4444 check_find_bounds_finds (mapped_index_base
&index
,
4445 const char *search_name
,
4446 gdb::array_view
<const char *> expected_syms
,
4447 dwarf2_per_objfile
*per_objfile
)
4449 lookup_name_info
lookup_name (search_name
,
4450 symbol_name_match_type::FULL
, true);
4452 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4456 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4457 if (distance
!= expected_syms
.size ())
4460 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4462 auto nc_elem
= bounds
.first
+ exp_elem
;
4463 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
, per_objfile
);
4464 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4471 /* Test the lower-level mapped_index::find_name_component_bounds
4475 test_mapped_index_find_name_component_bounds ()
4477 mock_mapped_index
mock_index (test_symbols
);
4479 mock_index
.build_name_components (NULL
/* per_objfile */);
4481 /* Test the lower-level mapped_index::find_name_component_bounds
4482 method in completion mode. */
4484 static const char *expected_syms
[] = {
4489 SELF_CHECK (check_find_bounds_finds
4490 (mock_index
, "t1_func", expected_syms
,
4491 NULL
/* per_objfile */));
4494 /* Check that the increment-last-char in the name matching algorithm
4495 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4497 static const char *expected_syms1
[] = {
4501 SELF_CHECK (check_find_bounds_finds
4502 (mock_index
, "\377", expected_syms1
, NULL
/* per_objfile */));
4504 static const char *expected_syms2
[] = {
4507 SELF_CHECK (check_find_bounds_finds
4508 (mock_index
, "\377\377", expected_syms2
,
4509 NULL
/* per_objfile */));
4513 /* Test dw2_expand_symtabs_matching_symbol. */
4516 test_dw2_expand_symtabs_matching_symbol ()
4518 mock_mapped_index
mock_index (test_symbols
);
4520 /* We let all tests run until the end even if some fails, for debug
4522 bool any_mismatch
= false;
4524 /* Create the expected symbols list (an initializer_list). Needed
4525 because lists have commas, and we need to pass them to CHECK,
4526 which is a macro. */
4527 #define EXPECT(...) { __VA_ARGS__ }
4529 /* Wrapper for check_match that passes down the current
4530 __FILE__/__LINE__. */
4531 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4532 any_mismatch |= !check_match (__FILE__, __LINE__, \
4534 NAME, MATCH_TYPE, COMPLETION_MODE, \
4535 EXPECTED_LIST, NULL)
4537 /* Identity checks. */
4538 for (const char *sym
: test_symbols
)
4540 /* Should be able to match all existing symbols. */
4541 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4544 /* Should be able to match all existing symbols with
4546 std::string with_params
= std::string (sym
) + "(int)";
4547 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4550 /* Should be able to match all existing symbols with
4551 parameters and qualifiers. */
4552 with_params
= std::string (sym
) + " ( int ) const";
4553 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4556 /* This should really find sym, but cp-name-parser.y doesn't
4557 know about lvalue/rvalue qualifiers yet. */
4558 with_params
= std::string (sym
) + " ( int ) &&";
4559 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4563 /* Check that the name matching algorithm for completion doesn't get
4564 confused with Latin1 'ÿ' / 0xff. */
4566 static const char str
[] = "\377";
4567 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4568 EXPECT ("\377", "\377\377123"));
4571 /* Check that the increment-last-char in the matching algorithm for
4572 completion doesn't match "t1_fund" when completing "t1_func". */
4574 static const char str
[] = "t1_func";
4575 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4576 EXPECT ("t1_func", "t1_func1"));
4579 /* Check that completion mode works at each prefix of the expected
4582 static const char str
[] = "function(int)";
4583 size_t len
= strlen (str
);
4586 for (size_t i
= 1; i
< len
; i
++)
4588 lookup
.assign (str
, i
);
4589 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4590 EXPECT ("function"));
4594 /* While "w" is a prefix of both components, the match function
4595 should still only be called once. */
4597 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4599 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4603 /* Same, with a "complicated" symbol. */
4605 static const char str
[] = Z_SYM_NAME
;
4606 size_t len
= strlen (str
);
4609 for (size_t i
= 1; i
< len
; i
++)
4611 lookup
.assign (str
, i
);
4612 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4613 EXPECT (Z_SYM_NAME
));
4617 /* In FULL mode, an incomplete symbol doesn't match. */
4619 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4623 /* A complete symbol with parameters matches any overload, since the
4624 index has no overload info. */
4626 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4627 EXPECT ("std::zfunction", "std::zfunction2"));
4628 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4629 EXPECT ("std::zfunction", "std::zfunction2"));
4630 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4631 EXPECT ("std::zfunction", "std::zfunction2"));
4634 /* Check that whitespace is ignored appropriately. A symbol with a
4635 template argument list. */
4637 static const char expected
[] = "ns::foo<int>";
4638 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4640 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4644 /* Check that whitespace is ignored appropriately. A symbol with a
4645 template argument list that includes a pointer. */
4647 static const char expected
[] = "ns::foo<char*>";
4648 /* Try both completion and non-completion modes. */
4649 static const bool completion_mode
[2] = {false, true};
4650 for (size_t i
= 0; i
< 2; i
++)
4652 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4653 completion_mode
[i
], EXPECT (expected
));
4654 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4655 completion_mode
[i
], EXPECT (expected
));
4657 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4658 completion_mode
[i
], EXPECT (expected
));
4659 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4660 completion_mode
[i
], EXPECT (expected
));
4665 /* Check method qualifiers are ignored. */
4666 static const char expected
[] = "ns::foo<char*>";
4667 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4668 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4669 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4670 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4671 CHECK_MATCH ("foo < char * > ( int ) const",
4672 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4673 CHECK_MATCH ("foo < char * > ( int ) &&",
4674 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4677 /* Test lookup names that don't match anything. */
4679 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4682 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4686 /* Some wild matching tests, exercising "(anonymous namespace)",
4687 which should not be confused with a parameter list. */
4689 static const char *syms
[] = {
4693 "A :: B :: C ( int )",
4698 for (const char *s
: syms
)
4700 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4701 EXPECT ("(anonymous namespace)::A::B::C"));
4706 static const char expected
[] = "ns2::tmpl<int>::foo2";
4707 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4709 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4713 SELF_CHECK (!any_mismatch
);
4722 test_mapped_index_find_name_component_bounds ();
4723 test_dw2_expand_symtabs_matching_symbol ();
4726 }} // namespace selftests::dw2_expand_symtabs_matching
4728 #endif /* GDB_SELF_TEST */
4730 /* If FILE_MATCHER is NULL or if PER_CU has
4731 dwarf2_per_cu_quick_data::MARK set (see
4732 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4733 EXPANSION_NOTIFY on it. */
4736 dw2_expand_symtabs_matching_one
4737 (dwarf2_per_cu_data
*per_cu
,
4738 dwarf2_per_objfile
*per_objfile
,
4739 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4740 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4742 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4744 bool symtab_was_null
= !per_objfile
->symtab_set_p (per_cu
);
4746 compunit_symtab
*symtab
4747 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
4748 gdb_assert (symtab
!= nullptr);
4750 if (expansion_notify
!= NULL
&& symtab_was_null
)
4751 expansion_notify (symtab
);
4755 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4756 matched, to expand corresponding CUs that were marked. IDX is the
4757 index of the symbol name that matched. */
4760 dw2_expand_marked_cus
4761 (dwarf2_per_objfile
*per_objfile
, offset_type idx
,
4762 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4763 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4766 offset_type
*vec
, vec_len
, vec_idx
;
4767 bool global_seen
= false;
4768 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4770 vec
= (offset_type
*) (index
.constant_pool
4771 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
4772 vec_len
= MAYBE_SWAP (vec
[0]);
4773 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4775 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
4776 /* This value is only valid for index versions >= 7. */
4777 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4778 gdb_index_symbol_kind symbol_kind
=
4779 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4780 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4781 /* Only check the symbol attributes if they're present.
4782 Indices prior to version 7 don't record them,
4783 and indices >= 7 may elide them for certain symbols
4784 (gold does this). */
4787 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4789 /* Work around gold/15646. */
4792 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
4800 /* Only check the symbol's kind if it has one. */
4805 case VARIABLES_DOMAIN
:
4806 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4809 case FUNCTIONS_DOMAIN
:
4810 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4814 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4817 case MODULES_DOMAIN
:
4818 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4826 /* Don't crash on bad data. */
4827 if (cu_index
>= (per_objfile
->per_bfd
->all_comp_units
.size ()
4828 + per_objfile
->per_bfd
->all_type_units
.size ()))
4830 complaint (_(".gdb_index entry has bad CU index"
4831 " [in module %s]"), objfile_name (per_objfile
->objfile
));
4835 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (cu_index
);
4836 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
4841 /* If FILE_MATCHER is non-NULL, set all the
4842 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4843 that match FILE_MATCHER. */
4846 dw_expand_symtabs_matching_file_matcher
4847 (dwarf2_per_objfile
*per_objfile
,
4848 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4850 if (file_matcher
== NULL
)
4853 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4855 NULL
, xcalloc
, xfree
));
4856 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4858 NULL
, xcalloc
, xfree
));
4860 /* The rule is CUs specify all the files, including those used by
4861 any TU, so there's no need to scan TUs here. */
4863 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4867 per_cu
->v
.quick
->mark
= 0;
4869 /* We only need to look at symtabs not already expanded. */
4870 if (per_objfile
->symtab_set_p (per_cu
))
4873 quick_file_names
*file_data
= dw2_get_file_names (per_cu
, per_objfile
);
4874 if (file_data
== NULL
)
4877 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4879 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4881 per_cu
->v
.quick
->mark
= 1;
4885 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4887 const char *this_real_name
;
4889 if (file_matcher (file_data
->file_names
[j
], false))
4891 per_cu
->v
.quick
->mark
= 1;
4895 /* Before we invoke realpath, which can get expensive when many
4896 files are involved, do a quick comparison of the basenames. */
4897 if (!basenames_may_differ
4898 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4902 this_real_name
= dw2_get_real_path (per_objfile
, file_data
, j
);
4903 if (file_matcher (this_real_name
, false))
4905 per_cu
->v
.quick
->mark
= 1;
4910 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4911 ? visited_found
.get ()
4912 : visited_not_found
.get (),
4919 dw2_expand_symtabs_matching
4920 (struct objfile
*objfile
,
4921 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4922 const lookup_name_info
*lookup_name
,
4923 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4924 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4925 enum search_domain kind
)
4927 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4929 /* index_table is NULL if OBJF_READNOW. */
4930 if (!per_objfile
->per_bfd
->index_table
)
4933 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
4935 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
4937 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4941 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
,
4942 file_matcher
, expansion_notify
);
4947 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4949 dw2_expand_symtabs_matching_symbol (index
, *lookup_name
,
4951 kind
, [&] (offset_type idx
)
4953 dw2_expand_marked_cus (per_objfile
, idx
, file_matcher
, expansion_notify
,
4959 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4962 static struct compunit_symtab
*
4963 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4968 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4969 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4972 if (cust
->includes
== NULL
)
4975 for (i
= 0; cust
->includes
[i
]; ++i
)
4977 struct compunit_symtab
*s
= cust
->includes
[i
];
4979 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4987 static struct compunit_symtab
*
4988 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
4989 struct bound_minimal_symbol msymbol
,
4991 struct obj_section
*section
,
4994 struct dwarf2_per_cu_data
*data
;
4995 struct compunit_symtab
*result
;
4997 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
5000 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
5001 data
= (struct dwarf2_per_cu_data
*) addrmap_find
5002 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
5006 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5007 if (warn_if_readin
&& per_objfile
->symtab_set_p (data
))
5008 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
5009 paddress (objfile
->arch (), pc
));
5011 result
= recursively_find_pc_sect_compunit_symtab
5012 (dw2_instantiate_symtab (data
, per_objfile
, false), pc
);
5014 gdb_assert (result
!= NULL
);
5019 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
5020 void *data
, int need_fullname
)
5022 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5024 if (!per_objfile
->per_bfd
->filenames_cache
)
5026 per_objfile
->per_bfd
->filenames_cache
.emplace ();
5028 htab_up
visited (htab_create_alloc (10,
5029 htab_hash_pointer
, htab_eq_pointer
,
5030 NULL
, xcalloc
, xfree
));
5032 /* The rule is CUs specify all the files, including those used
5033 by any TU, so there's no need to scan TUs here. We can
5034 ignore file names coming from already-expanded CUs. */
5036 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
5038 if (per_objfile
->symtab_set_p (per_cu
))
5040 void **slot
= htab_find_slot (visited
.get (),
5041 per_cu
->v
.quick
->file_names
,
5044 *slot
= per_cu
->v
.quick
->file_names
;
5048 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
5050 /* We only need to look at symtabs not already expanded. */
5051 if (per_objfile
->symtab_set_p (per_cu
))
5054 quick_file_names
*file_data
5055 = dw2_get_file_names (per_cu
, per_objfile
);
5056 if (file_data
== NULL
)
5059 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
5062 /* Already visited. */
5067 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
5069 const char *filename
= file_data
->file_names
[j
];
5070 per_objfile
->per_bfd
->filenames_cache
->seen (filename
);
5075 per_objfile
->per_bfd
->filenames_cache
->traverse ([&] (const char *filename
)
5077 gdb::unique_xmalloc_ptr
<char> this_real_name
;
5080 this_real_name
= gdb_realpath (filename
);
5081 (*fun
) (filename
, this_real_name
.get (), data
);
5086 dw2_has_symbols (struct objfile
*objfile
)
5091 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
5094 dw2_find_last_source_symtab
,
5095 dw2_forget_cached_source_info
,
5096 dw2_map_symtabs_matching_filename
,
5101 dw2_expand_symtabs_for_function
,
5102 dw2_expand_all_symtabs
,
5103 dw2_expand_symtabs_with_fullname
,
5104 dw2_map_matching_symbols
,
5105 dw2_expand_symtabs_matching
,
5106 dw2_find_pc_sect_compunit_symtab
,
5108 dw2_map_symbol_filenames
5111 /* DWARF-5 debug_names reader. */
5113 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
5114 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
5116 /* A helper function that reads the .debug_names section in SECTION
5117 and fills in MAP. FILENAME is the name of the file containing the
5118 section; it is used for error reporting.
5120 Returns true if all went well, false otherwise. */
5123 read_debug_names_from_section (struct objfile
*objfile
,
5124 const char *filename
,
5125 struct dwarf2_section_info
*section
,
5126 mapped_debug_names
&map
)
5128 if (section
->empty ())
5131 /* Older elfutils strip versions could keep the section in the main
5132 executable while splitting it for the separate debug info file. */
5133 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5136 section
->read (objfile
);
5138 map
.dwarf5_byte_order
= gdbarch_byte_order (objfile
->arch ());
5140 const gdb_byte
*addr
= section
->buffer
;
5142 bfd
*const abfd
= section
->get_bfd_owner ();
5144 unsigned int bytes_read
;
5145 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
5148 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
5149 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
5150 if (bytes_read
+ length
!= section
->size
)
5152 /* There may be multiple per-CU indices. */
5153 warning (_("Section .debug_names in %s length %s does not match "
5154 "section length %s, ignoring .debug_names."),
5155 filename
, plongest (bytes_read
+ length
),
5156 pulongest (section
->size
));
5160 /* The version number. */
5161 uint16_t version
= read_2_bytes (abfd
, addr
);
5165 warning (_("Section .debug_names in %s has unsupported version %d, "
5166 "ignoring .debug_names."),
5172 uint16_t padding
= read_2_bytes (abfd
, addr
);
5176 warning (_("Section .debug_names in %s has unsupported padding %d, "
5177 "ignoring .debug_names."),
5182 /* comp_unit_count - The number of CUs in the CU list. */
5183 map
.cu_count
= read_4_bytes (abfd
, addr
);
5186 /* local_type_unit_count - The number of TUs in the local TU
5188 map
.tu_count
= read_4_bytes (abfd
, addr
);
5191 /* foreign_type_unit_count - The number of TUs in the foreign TU
5193 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
5195 if (foreign_tu_count
!= 0)
5197 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
5198 "ignoring .debug_names."),
5199 filename
, static_cast<unsigned long> (foreign_tu_count
));
5203 /* bucket_count - The number of hash buckets in the hash lookup
5205 map
.bucket_count
= read_4_bytes (abfd
, addr
);
5208 /* name_count - The number of unique names in the index. */
5209 map
.name_count
= read_4_bytes (abfd
, addr
);
5212 /* abbrev_table_size - The size in bytes of the abbreviations
5214 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
5217 /* augmentation_string_size - The size in bytes of the augmentation
5218 string. This value is rounded up to a multiple of 4. */
5219 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
5221 map
.augmentation_is_gdb
= ((augmentation_string_size
5222 == sizeof (dwarf5_augmentation
))
5223 && memcmp (addr
, dwarf5_augmentation
,
5224 sizeof (dwarf5_augmentation
)) == 0);
5225 augmentation_string_size
+= (-augmentation_string_size
) & 3;
5226 addr
+= augmentation_string_size
;
5229 map
.cu_table_reordered
= addr
;
5230 addr
+= map
.cu_count
* map
.offset_size
;
5232 /* List of Local TUs */
5233 map
.tu_table_reordered
= addr
;
5234 addr
+= map
.tu_count
* map
.offset_size
;
5236 /* Hash Lookup Table */
5237 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5238 addr
+= map
.bucket_count
* 4;
5239 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5240 addr
+= map
.name_count
* 4;
5243 map
.name_table_string_offs_reordered
= addr
;
5244 addr
+= map
.name_count
* map
.offset_size
;
5245 map
.name_table_entry_offs_reordered
= addr
;
5246 addr
+= map
.name_count
* map
.offset_size
;
5248 const gdb_byte
*abbrev_table_start
= addr
;
5251 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5256 const auto insertpair
5257 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
5258 if (!insertpair
.second
)
5260 warning (_("Section .debug_names in %s has duplicate index %s, "
5261 "ignoring .debug_names."),
5262 filename
, pulongest (index_num
));
5265 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
5266 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5271 mapped_debug_names::index_val::attr attr
;
5272 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5274 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5276 if (attr
.form
== DW_FORM_implicit_const
)
5278 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
5282 if (attr
.dw_idx
== 0 && attr
.form
== 0)
5284 indexval
.attr_vec
.push_back (std::move (attr
));
5287 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
5289 warning (_("Section .debug_names in %s has abbreviation_table "
5290 "of size %s vs. written as %u, ignoring .debug_names."),
5291 filename
, plongest (addr
- abbrev_table_start
),
5295 map
.entry_pool
= addr
;
5300 /* A helper for create_cus_from_debug_names that handles the MAP's CU
5304 create_cus_from_debug_names_list (dwarf2_per_bfd
*per_bfd
,
5305 const mapped_debug_names
&map
,
5306 dwarf2_section_info
§ion
,
5309 if (!map
.augmentation_is_gdb
)
5311 for (uint32_t i
= 0; i
< map
.cu_count
; ++i
)
5313 sect_offset sect_off
5314 = (sect_offset
) (extract_unsigned_integer
5315 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5317 map
.dwarf5_byte_order
));
5318 /* We don't know the length of the CU, because the CU list in a
5319 .debug_names index can be incomplete, so we can't use the start of
5320 the next CU as end of this CU. We create the CUs here with length 0,
5321 and in cutu_reader::cutu_reader we'll fill in the actual length. */
5322 dwarf2_per_cu_data
*per_cu
5323 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
, sect_off
, 0);
5324 per_bfd
->all_comp_units
.push_back (per_cu
);
5328 sect_offset sect_off_prev
;
5329 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5331 sect_offset sect_off_next
;
5332 if (i
< map
.cu_count
)
5335 = (sect_offset
) (extract_unsigned_integer
5336 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5338 map
.dwarf5_byte_order
));
5341 sect_off_next
= (sect_offset
) section
.size
;
5344 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5345 dwarf2_per_cu_data
*per_cu
5346 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
,
5347 sect_off_prev
, length
);
5348 per_bfd
->all_comp_units
.push_back (per_cu
);
5350 sect_off_prev
= sect_off_next
;
5354 /* Read the CU list from the mapped index, and use it to create all
5355 the CU objects for this dwarf2_per_objfile. */
5358 create_cus_from_debug_names (dwarf2_per_bfd
*per_bfd
,
5359 const mapped_debug_names
&map
,
5360 const mapped_debug_names
&dwz_map
)
5362 gdb_assert (per_bfd
->all_comp_units
.empty ());
5363 per_bfd
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5365 create_cus_from_debug_names_list (per_bfd
, map
, per_bfd
->info
,
5366 false /* is_dwz */);
5368 if (dwz_map
.cu_count
== 0)
5371 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
5372 create_cus_from_debug_names_list (per_bfd
, dwz_map
, dwz
->info
,
5376 /* Read .debug_names. If everything went ok, initialize the "quick"
5377 elements of all the CUs and return true. Otherwise, return false. */
5380 dwarf2_read_debug_names (dwarf2_per_objfile
*per_objfile
)
5382 std::unique_ptr
<mapped_debug_names
> map (new mapped_debug_names
);
5383 mapped_debug_names dwz_map
;
5384 struct objfile
*objfile
= per_objfile
->objfile
;
5385 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5387 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5388 &per_objfile
->per_bfd
->debug_names
, *map
))
5391 /* Don't use the index if it's empty. */
5392 if (map
->name_count
== 0)
5395 /* If there is a .dwz file, read it so we can get its CU list as
5397 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
5400 if (!read_debug_names_from_section (objfile
,
5401 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5402 &dwz
->debug_names
, dwz_map
))
5404 warning (_("could not read '.debug_names' section from %s; skipping"),
5405 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5410 create_cus_from_debug_names (per_bfd
, *map
, dwz_map
);
5412 if (map
->tu_count
!= 0)
5414 /* We can only handle a single .debug_types when we have an
5416 if (per_bfd
->types
.size () != 1)
5419 dwarf2_section_info
*section
= &per_bfd
->types
[0];
5421 create_signatured_type_table_from_debug_names
5422 (per_objfile
, *map
, section
, &per_bfd
->abbrev
);
5425 create_addrmap_from_aranges (per_objfile
, &per_bfd
->debug_aranges
);
5427 per_bfd
->debug_names_table
= std::move (map
);
5428 per_bfd
->using_index
= 1;
5429 per_bfd
->quick_file_names_table
=
5430 create_quick_file_names_table (per_objfile
->per_bfd
->all_comp_units
.size ());
5432 /* Save partial symtabs in the per_bfd object, for the benefit of subsequent
5433 objfiles using the same BFD. */
5434 gdb_assert (per_bfd
->partial_symtabs
== nullptr);
5435 per_bfd
->partial_symtabs
= objfile
->partial_symtabs
;
5440 /* Type used to manage iterating over all CUs looking for a symbol for
5443 class dw2_debug_names_iterator
5446 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5447 gdb::optional
<block_enum
> block_index
,
5449 const char *name
, dwarf2_per_objfile
*per_objfile
)
5450 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5451 m_addr (find_vec_in_debug_names (map
, name
, per_objfile
)),
5452 m_per_objfile (per_objfile
)
5455 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5456 search_domain search
, uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5459 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
5460 m_per_objfile (per_objfile
)
5463 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5464 block_enum block_index
, domain_enum domain
,
5465 uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5466 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5467 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
5468 m_per_objfile (per_objfile
)
5471 /* Return the next matching CU or NULL if there are no more. */
5472 dwarf2_per_cu_data
*next ();
5475 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5477 dwarf2_per_objfile
*per_objfile
);
5478 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5480 dwarf2_per_objfile
*per_objfile
);
5482 /* The internalized form of .debug_names. */
5483 const mapped_debug_names
&m_map
;
5485 /* If set, only look for symbols that match that block. Valid values are
5486 GLOBAL_BLOCK and STATIC_BLOCK. */
5487 const gdb::optional
<block_enum
> m_block_index
;
5489 /* The kind of symbol we're looking for. */
5490 const domain_enum m_domain
= UNDEF_DOMAIN
;
5491 const search_domain m_search
= ALL_DOMAIN
;
5493 /* The list of CUs from the index entry of the symbol, or NULL if
5495 const gdb_byte
*m_addr
;
5497 dwarf2_per_objfile
*m_per_objfile
;
5501 mapped_debug_names::namei_to_name
5502 (uint32_t namei
, dwarf2_per_objfile
*per_objfile
) const
5504 const ULONGEST namei_string_offs
5505 = extract_unsigned_integer ((name_table_string_offs_reordered
5506 + namei
* offset_size
),
5509 return read_indirect_string_at_offset (per_objfile
, namei_string_offs
);
5512 /* Find a slot in .debug_names for the object named NAME. If NAME is
5513 found, return pointer to its pool data. If NAME cannot be found,
5517 dw2_debug_names_iterator::find_vec_in_debug_names
5518 (const mapped_debug_names
&map
, const char *name
,
5519 dwarf2_per_objfile
*per_objfile
)
5521 int (*cmp
) (const char *, const char *);
5523 gdb::unique_xmalloc_ptr
<char> without_params
;
5524 if (current_language
->la_language
== language_cplus
5525 || current_language
->la_language
== language_fortran
5526 || current_language
->la_language
== language_d
)
5528 /* NAME is already canonical. Drop any qualifiers as
5529 .debug_names does not contain any. */
5531 if (strchr (name
, '(') != NULL
)
5533 without_params
= cp_remove_params (name
);
5534 if (without_params
!= NULL
)
5535 name
= without_params
.get ();
5539 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5541 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5543 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5544 (map
.bucket_table_reordered
5545 + (full_hash
% map
.bucket_count
)), 4,
5546 map
.dwarf5_byte_order
);
5550 if (namei
>= map
.name_count
)
5552 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5554 namei
, map
.name_count
,
5555 objfile_name (per_objfile
->objfile
));
5561 const uint32_t namei_full_hash
5562 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5563 (map
.hash_table_reordered
+ namei
), 4,
5564 map
.dwarf5_byte_order
);
5565 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5568 if (full_hash
== namei_full_hash
)
5570 const char *const namei_string
= map
.namei_to_name (namei
, per_objfile
);
5572 #if 0 /* An expensive sanity check. */
5573 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5575 complaint (_("Wrong .debug_names hash for string at index %u "
5577 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5582 if (cmp (namei_string
, name
) == 0)
5584 const ULONGEST namei_entry_offs
5585 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5586 + namei
* map
.offset_size
),
5587 map
.offset_size
, map
.dwarf5_byte_order
);
5588 return map
.entry_pool
+ namei_entry_offs
;
5593 if (namei
>= map
.name_count
)
5599 dw2_debug_names_iterator::find_vec_in_debug_names
5600 (const mapped_debug_names
&map
, uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5602 if (namei
>= map
.name_count
)
5604 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5606 namei
, map
.name_count
,
5607 objfile_name (per_objfile
->objfile
));
5611 const ULONGEST namei_entry_offs
5612 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5613 + namei
* map
.offset_size
),
5614 map
.offset_size
, map
.dwarf5_byte_order
);
5615 return map
.entry_pool
+ namei_entry_offs
;
5618 /* See dw2_debug_names_iterator. */
5620 dwarf2_per_cu_data
*
5621 dw2_debug_names_iterator::next ()
5626 dwarf2_per_bfd
*per_bfd
= m_per_objfile
->per_bfd
;
5627 struct objfile
*objfile
= m_per_objfile
->objfile
;
5628 bfd
*const abfd
= objfile
->obfd
;
5632 unsigned int bytes_read
;
5633 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5634 m_addr
+= bytes_read
;
5638 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5639 if (indexval_it
== m_map
.abbrev_map
.cend ())
5641 complaint (_("Wrong .debug_names undefined abbrev code %s "
5643 pulongest (abbrev
), objfile_name (objfile
));
5646 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5647 enum class symbol_linkage
{
5651 } symbol_linkage_
= symbol_linkage::unknown
;
5652 dwarf2_per_cu_data
*per_cu
= NULL
;
5653 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5658 case DW_FORM_implicit_const
:
5659 ull
= attr
.implicit_const
;
5661 case DW_FORM_flag_present
:
5665 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5666 m_addr
+= bytes_read
;
5669 ull
= read_4_bytes (abfd
, m_addr
);
5673 ull
= read_8_bytes (abfd
, m_addr
);
5676 case DW_FORM_ref_sig8
:
5677 ull
= read_8_bytes (abfd
, m_addr
);
5681 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5682 dwarf_form_name (attr
.form
),
5683 objfile_name (objfile
));
5686 switch (attr
.dw_idx
)
5688 case DW_IDX_compile_unit
:
5689 /* Don't crash on bad data. */
5690 if (ull
>= m_per_objfile
->per_bfd
->all_comp_units
.size ())
5692 complaint (_(".debug_names entry has bad CU index %s"
5695 objfile_name (objfile
));
5698 per_cu
= per_bfd
->get_cutu (ull
);
5700 case DW_IDX_type_unit
:
5701 /* Don't crash on bad data. */
5702 if (ull
>= per_bfd
->all_type_units
.size ())
5704 complaint (_(".debug_names entry has bad TU index %s"
5707 objfile_name (objfile
));
5710 per_cu
= &per_bfd
->get_tu (ull
)->per_cu
;
5712 case DW_IDX_die_offset
:
5713 /* In a per-CU index (as opposed to a per-module index), index
5714 entries without CU attribute implicitly refer to the single CU. */
5716 per_cu
= per_bfd
->get_cu (0);
5718 case DW_IDX_GNU_internal
:
5719 if (!m_map
.augmentation_is_gdb
)
5721 symbol_linkage_
= symbol_linkage::static_
;
5723 case DW_IDX_GNU_external
:
5724 if (!m_map
.augmentation_is_gdb
)
5726 symbol_linkage_
= symbol_linkage::extern_
;
5731 /* Skip if already read in. */
5732 if (m_per_objfile
->symtab_set_p (per_cu
))
5735 /* Check static vs global. */
5736 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5738 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5739 const bool symbol_is_static
=
5740 symbol_linkage_
== symbol_linkage::static_
;
5741 if (want_static
!= symbol_is_static
)
5745 /* Match dw2_symtab_iter_next, symbol_kind
5746 and debug_names::psymbol_tag. */
5750 switch (indexval
.dwarf_tag
)
5752 case DW_TAG_variable
:
5753 case DW_TAG_subprogram
:
5754 /* Some types are also in VAR_DOMAIN. */
5755 case DW_TAG_typedef
:
5756 case DW_TAG_structure_type
:
5763 switch (indexval
.dwarf_tag
)
5765 case DW_TAG_typedef
:
5766 case DW_TAG_structure_type
:
5773 switch (indexval
.dwarf_tag
)
5776 case DW_TAG_variable
:
5783 switch (indexval
.dwarf_tag
)
5795 /* Match dw2_expand_symtabs_matching, symbol_kind and
5796 debug_names::psymbol_tag. */
5799 case VARIABLES_DOMAIN
:
5800 switch (indexval
.dwarf_tag
)
5802 case DW_TAG_variable
:
5808 case FUNCTIONS_DOMAIN
:
5809 switch (indexval
.dwarf_tag
)
5811 case DW_TAG_subprogram
:
5818 switch (indexval
.dwarf_tag
)
5820 case DW_TAG_typedef
:
5821 case DW_TAG_structure_type
:
5827 case MODULES_DOMAIN
:
5828 switch (indexval
.dwarf_tag
)
5842 static struct compunit_symtab
*
5843 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
5844 const char *name
, domain_enum domain
)
5846 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5848 const auto &mapp
= per_objfile
->per_bfd
->debug_names_table
;
5851 /* index is NULL if OBJF_READNOW. */
5854 const auto &map
= *mapp
;
5856 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
, per_objfile
);
5858 struct compunit_symtab
*stab_best
= NULL
;
5859 struct dwarf2_per_cu_data
*per_cu
;
5860 while ((per_cu
= iter
.next ()) != NULL
)
5862 struct symbol
*sym
, *with_opaque
= NULL
;
5863 compunit_symtab
*stab
5864 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
5865 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
5866 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
5868 sym
= block_find_symbol (block
, name
, domain
,
5869 block_find_non_opaque_type_preferred
,
5872 /* Some caution must be observed with overloaded functions and
5873 methods, since the index will not contain any overload
5874 information (but NAME might contain it). */
5877 && strcmp_iw (sym
->search_name (), name
) == 0)
5879 if (with_opaque
!= NULL
5880 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
5883 /* Keep looking through other CUs. */
5889 /* This dumps minimal information about .debug_names. It is called
5890 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5891 uses this to verify that .debug_names has been loaded. */
5894 dw2_debug_names_dump (struct objfile
*objfile
)
5896 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5898 gdb_assert (per_objfile
->per_bfd
->using_index
);
5899 printf_filtered (".debug_names:");
5900 if (per_objfile
->per_bfd
->debug_names_table
)
5901 printf_filtered (" exists\n");
5903 printf_filtered (" faked for \"readnow\"\n");
5904 printf_filtered ("\n");
5908 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
5909 const char *func_name
)
5911 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5913 /* per_objfile->per_bfd->debug_names_table is NULL if OBJF_READNOW. */
5914 if (per_objfile
->per_bfd
->debug_names_table
)
5916 const mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5918 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
,
5921 struct dwarf2_per_cu_data
*per_cu
;
5922 while ((per_cu
= iter
.next ()) != NULL
)
5923 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
5928 dw2_debug_names_map_matching_symbols
5929 (struct objfile
*objfile
,
5930 const lookup_name_info
&name
, domain_enum domain
,
5932 gdb::function_view
<symbol_found_callback_ftype
> callback
,
5933 symbol_compare_ftype
*ordered_compare
)
5935 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5937 /* debug_names_table is NULL if OBJF_READNOW. */
5938 if (!per_objfile
->per_bfd
->debug_names_table
)
5941 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5942 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
5944 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5945 auto matcher
= [&] (const char *symname
)
5947 if (ordered_compare
== nullptr)
5949 return ordered_compare (symname
, match_name
) == 0;
5952 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
5953 [&] (offset_type namei
)
5955 /* The name was matched, now expand corresponding CUs that were
5957 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
,
5960 struct dwarf2_per_cu_data
*per_cu
;
5961 while ((per_cu
= iter
.next ()) != NULL
)
5962 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
5967 /* It's a shame we couldn't do this inside the
5968 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
5969 that have already been expanded. Instead, this loop matches what
5970 the psymtab code does. */
5971 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
5973 compunit_symtab
*symtab
= per_objfile
->get_symtab (per_cu
);
5974 if (symtab
!= nullptr)
5976 const struct block
*block
5977 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (symtab
), block_kind
);
5978 if (!iterate_over_symbols_terminated (block
, name
,
5986 dw2_debug_names_expand_symtabs_matching
5987 (struct objfile
*objfile
,
5988 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5989 const lookup_name_info
*lookup_name
,
5990 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5991 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5992 enum search_domain kind
)
5994 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5996 /* debug_names_table is NULL if OBJF_READNOW. */
5997 if (!per_objfile
->per_bfd
->debug_names_table
)
6000 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
6002 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
6004 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
6008 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
6014 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
6016 dw2_expand_symtabs_matching_symbol (map
, *lookup_name
,
6018 kind
, [&] (offset_type namei
)
6020 /* The name was matched, now expand corresponding CUs that were
6022 dw2_debug_names_iterator
iter (map
, kind
, namei
, per_objfile
);
6024 struct dwarf2_per_cu_data
*per_cu
;
6025 while ((per_cu
= iter
.next ()) != NULL
)
6026 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
6032 const struct quick_symbol_functions dwarf2_debug_names_functions
=
6035 dw2_find_last_source_symtab
,
6036 dw2_forget_cached_source_info
,
6037 dw2_map_symtabs_matching_filename
,
6038 dw2_debug_names_lookup_symbol
,
6041 dw2_debug_names_dump
,
6042 dw2_debug_names_expand_symtabs_for_function
,
6043 dw2_expand_all_symtabs
,
6044 dw2_expand_symtabs_with_fullname
,
6045 dw2_debug_names_map_matching_symbols
,
6046 dw2_debug_names_expand_symtabs_matching
,
6047 dw2_find_pc_sect_compunit_symtab
,
6049 dw2_map_symbol_filenames
6052 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
6053 to either a dwarf2_per_bfd or dwz_file object. */
6055 template <typename T
>
6056 static gdb::array_view
<const gdb_byte
>
6057 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
6059 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
6061 if (section
->empty ())
6064 /* Older elfutils strip versions could keep the section in the main
6065 executable while splitting it for the separate debug info file. */
6066 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
6069 section
->read (obj
);
6071 /* dwarf2_section_info::size is a bfd_size_type, while
6072 gdb::array_view works with size_t. On 32-bit hosts, with
6073 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
6074 is 32-bit. So we need an explicit narrowing conversion here.
6075 This is fine, because it's impossible to allocate or mmap an
6076 array/buffer larger than what size_t can represent. */
6077 return gdb::make_array_view (section
->buffer
, section
->size
);
6080 /* Lookup the index cache for the contents of the index associated to
6083 static gdb::array_view
<const gdb_byte
>
6084 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_bfd
*dwarf2_per_bfd
)
6086 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
6087 if (build_id
== nullptr)
6090 return global_index_cache
.lookup_gdb_index (build_id
,
6091 &dwarf2_per_bfd
->index_cache_res
);
6094 /* Same as the above, but for DWZ. */
6096 static gdb::array_view
<const gdb_byte
>
6097 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
6099 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
6100 if (build_id
== nullptr)
6103 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
6106 /* See symfile.h. */
6109 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
6111 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
6112 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6114 /* If we're about to read full symbols, don't bother with the
6115 indices. In this case we also don't care if some other debug
6116 format is making psymtabs, because they are all about to be
6118 if ((objfile
->flags
& OBJF_READNOW
))
6120 /* When using READNOW, the using_index flag (set below) indicates that
6121 PER_BFD was already initialized, when we loaded some other objfile. */
6122 if (per_bfd
->using_index
)
6124 *index_kind
= dw_index_kind::GDB_INDEX
;
6125 per_objfile
->resize_symtabs ();
6129 per_bfd
->using_index
= 1;
6130 create_all_comp_units (per_objfile
);
6131 create_all_type_units (per_objfile
);
6132 per_bfd
->quick_file_names_table
6133 = create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
6134 per_objfile
->resize_symtabs ();
6136 for (int i
= 0; i
< (per_bfd
->all_comp_units
.size ()
6137 + per_bfd
->all_type_units
.size ()); ++i
)
6139 dwarf2_per_cu_data
*per_cu
= per_bfd
->get_cutu (i
);
6141 per_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
6142 struct dwarf2_per_cu_quick_data
);
6145 /* Return 1 so that gdb sees the "quick" functions. However,
6146 these functions will be no-ops because we will have expanded
6148 *index_kind
= dw_index_kind::GDB_INDEX
;
6152 /* Was a debug names index already read when we processed an objfile sharing
6154 if (per_bfd
->debug_names_table
!= nullptr)
6156 *index_kind
= dw_index_kind::DEBUG_NAMES
;
6157 per_objfile
->objfile
->partial_symtabs
= per_bfd
->partial_symtabs
;
6158 per_objfile
->resize_symtabs ();
6162 /* Was a GDB index already read when we processed an objfile sharing
6164 if (per_bfd
->index_table
!= nullptr)
6166 *index_kind
= dw_index_kind::GDB_INDEX
;
6167 per_objfile
->objfile
->partial_symtabs
= per_bfd
->partial_symtabs
;
6168 per_objfile
->resize_symtabs ();
6172 /* There might already be partial symtabs built for this BFD. This happens
6173 when loading the same binary twice with the index-cache enabled. If so,
6174 don't try to read an index. The objfile / per_objfile initialization will
6175 be completed in dwarf2_build_psymtabs, in the standard partial symtabs
6177 if (per_bfd
->partial_symtabs
!= nullptr)
6180 if (dwarf2_read_debug_names (per_objfile
))
6182 *index_kind
= dw_index_kind::DEBUG_NAMES
;
6183 per_objfile
->resize_symtabs ();
6187 if (dwarf2_read_gdb_index (per_objfile
,
6188 get_gdb_index_contents_from_section
<struct dwarf2_per_bfd
>,
6189 get_gdb_index_contents_from_section
<dwz_file
>))
6191 *index_kind
= dw_index_kind::GDB_INDEX
;
6192 per_objfile
->resize_symtabs ();
6196 /* ... otherwise, try to find the index in the index cache. */
6197 if (dwarf2_read_gdb_index (per_objfile
,
6198 get_gdb_index_contents_from_cache
,
6199 get_gdb_index_contents_from_cache_dwz
))
6201 global_index_cache
.hit ();
6202 *index_kind
= dw_index_kind::GDB_INDEX
;
6203 per_objfile
->resize_symtabs ();
6207 global_index_cache
.miss ();
6213 /* Build a partial symbol table. */
6216 dwarf2_build_psymtabs (struct objfile
*objfile
)
6218 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
6219 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6221 if (per_bfd
->partial_symtabs
!= nullptr)
6223 /* Partial symbols were already read, so now we can simply
6225 objfile
->partial_symtabs
= per_bfd
->partial_symtabs
;
6226 per_objfile
->resize_symtabs ();
6232 /* This isn't really ideal: all the data we allocate on the
6233 objfile's obstack is still uselessly kept around. However,
6234 freeing it seems unsafe. */
6235 psymtab_discarder
psymtabs (objfile
);
6236 dwarf2_build_psymtabs_hard (per_objfile
);
6239 per_objfile
->resize_symtabs ();
6241 /* (maybe) store an index in the cache. */
6242 global_index_cache
.store (per_objfile
);
6244 catch (const gdb_exception_error
&except
)
6246 exception_print (gdb_stderr
, except
);
6249 /* Finish by setting the local reference to partial symtabs, so that
6250 we don't try to read them again if reading another objfile with the same
6251 BFD. If we can't in fact share, this won't make a difference anyway as
6252 the dwarf2_per_bfd object won't be shared. */
6253 per_bfd
->partial_symtabs
= objfile
->partial_symtabs
;
6256 /* Find the base address of the compilation unit for range lists and
6257 location lists. It will normally be specified by DW_AT_low_pc.
6258 In DWARF-3 draft 4, the base address could be overridden by
6259 DW_AT_entry_pc. It's been removed, but GCC still uses this for
6260 compilation units with discontinuous ranges. */
6263 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
6265 struct attribute
*attr
;
6267 cu
->base_address
.reset ();
6269 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
6270 if (attr
!= nullptr)
6271 cu
->base_address
= attr
->as_address ();
6274 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6275 if (attr
!= nullptr)
6276 cu
->base_address
= attr
->as_address ();
6280 /* Helper function that returns the proper abbrev section for
6283 static struct dwarf2_section_info
*
6284 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
6286 struct dwarf2_section_info
*abbrev
;
6287 dwarf2_per_bfd
*per_bfd
= this_cu
->per_bfd
;
6289 if (this_cu
->is_dwz
)
6290 abbrev
= &dwarf2_get_dwz_file (per_bfd
)->abbrev
;
6292 abbrev
= &per_bfd
->abbrev
;
6297 /* Fetch the abbreviation table offset from a comp or type unit header. */
6300 read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
6301 struct dwarf2_section_info
*section
,
6302 sect_offset sect_off
)
6304 bfd
*abfd
= section
->get_bfd_owner ();
6305 const gdb_byte
*info_ptr
;
6306 unsigned int initial_length_size
, offset_size
;
6309 section
->read (per_objfile
->objfile
);
6310 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
6311 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6312 offset_size
= initial_length_size
== 4 ? 4 : 8;
6313 info_ptr
+= initial_length_size
;
6315 version
= read_2_bytes (abfd
, info_ptr
);
6319 /* Skip unit type and address size. */
6323 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
6326 /* A partial symtab that is used only for include files. */
6327 struct dwarf2_include_psymtab
: public partial_symtab
6329 dwarf2_include_psymtab (const char *filename
, struct objfile
*objfile
)
6330 : partial_symtab (filename
, objfile
)
6334 void read_symtab (struct objfile
*objfile
) override
6336 /* It's an include file, no symbols to read for it.
6337 Everything is in the includer symtab. */
6339 /* The expansion of a dwarf2_include_psymtab is just a trigger for
6340 expansion of the includer psymtab. We use the dependencies[0] field to
6341 model the includer. But if we go the regular route of calling
6342 expand_psymtab here, and having expand_psymtab call expand_dependencies
6343 to expand the includer, we'll only use expand_psymtab on the includer
6344 (making it a non-toplevel psymtab), while if we expand the includer via
6345 another path, we'll use read_symtab (making it a toplevel psymtab).
6346 So, don't pretend a dwarf2_include_psymtab is an actual toplevel
6347 psymtab, and trigger read_symtab on the includer here directly. */
6348 includer ()->read_symtab (objfile
);
6351 void expand_psymtab (struct objfile
*objfile
) override
6353 /* This is not called by read_symtab, and should not be called by any
6354 expand_dependencies. */
6358 bool readin_p (struct objfile
*objfile
) const override
6360 return includer ()->readin_p (objfile
);
6363 compunit_symtab
*get_compunit_symtab (struct objfile
*objfile
) const override
6369 partial_symtab
*includer () const
6371 /* An include psymtab has exactly one dependency: the psymtab that
6373 gdb_assert (this->number_of_dependencies
== 1);
6374 return this->dependencies
[0];
6378 /* Allocate a new partial symtab for file named NAME and mark this new
6379 partial symtab as being an include of PST. */
6382 dwarf2_create_include_psymtab (const char *name
, dwarf2_psymtab
*pst
,
6383 struct objfile
*objfile
)
6385 dwarf2_include_psymtab
*subpst
= new dwarf2_include_psymtab (name
, objfile
);
6387 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6388 subpst
->dirname
= pst
->dirname
;
6390 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
6391 subpst
->dependencies
[0] = pst
;
6392 subpst
->number_of_dependencies
= 1;
6395 /* Read the Line Number Program data and extract the list of files
6396 included by the source file represented by PST. Build an include
6397 partial symtab for each of these included files. */
6400 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
6401 struct die_info
*die
,
6402 dwarf2_psymtab
*pst
)
6405 struct attribute
*attr
;
6407 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6408 if (attr
!= nullptr && attr
->form_is_unsigned ())
6409 lh
= dwarf_decode_line_header ((sect_offset
) attr
->as_unsigned (), cu
);
6411 return; /* No linetable, so no includes. */
6413 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
6414 that we pass in the raw text_low here; that is ok because we're
6415 only decoding the line table to make include partial symtabs, and
6416 so the addresses aren't really used. */
6417 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
6418 pst
->raw_text_low (), 1);
6422 hash_signatured_type (const void *item
)
6424 const struct signatured_type
*sig_type
6425 = (const struct signatured_type
*) item
;
6427 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6428 return sig_type
->signature
;
6432 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6434 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6435 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6437 return lhs
->signature
== rhs
->signature
;
6440 /* Allocate a hash table for signatured types. */
6443 allocate_signatured_type_table ()
6445 return htab_up (htab_create_alloc (41,
6446 hash_signatured_type
,
6448 NULL
, xcalloc
, xfree
));
6451 /* A helper function to add a signatured type CU to a table. */
6454 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6456 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6457 std::vector
<signatured_type
*> *all_type_units
6458 = (std::vector
<signatured_type
*> *) datum
;
6460 all_type_units
->push_back (sigt
);
6465 /* A helper for create_debug_types_hash_table. Read types from SECTION
6466 and fill them into TYPES_HTAB. It will process only type units,
6467 therefore DW_UT_type. */
6470 create_debug_type_hash_table (dwarf2_per_objfile
*per_objfile
,
6471 struct dwo_file
*dwo_file
,
6472 dwarf2_section_info
*section
, htab_up
&types_htab
,
6473 rcuh_kind section_kind
)
6475 struct objfile
*objfile
= per_objfile
->objfile
;
6476 struct dwarf2_section_info
*abbrev_section
;
6478 const gdb_byte
*info_ptr
, *end_ptr
;
6480 abbrev_section
= (dwo_file
!= NULL
6481 ? &dwo_file
->sections
.abbrev
6482 : &per_objfile
->per_bfd
->abbrev
);
6484 dwarf_read_debug_printf ("Reading %s for %s:",
6485 section
->get_name (),
6486 abbrev_section
->get_file_name ());
6488 section
->read (objfile
);
6489 info_ptr
= section
->buffer
;
6491 if (info_ptr
== NULL
)
6494 /* We can't set abfd until now because the section may be empty or
6495 not present, in which case the bfd is unknown. */
6496 abfd
= section
->get_bfd_owner ();
6498 /* We don't use cutu_reader here because we don't need to read
6499 any dies: the signature is in the header. */
6501 end_ptr
= info_ptr
+ section
->size
;
6502 while (info_ptr
< end_ptr
)
6504 struct signatured_type
*sig_type
;
6505 struct dwo_unit
*dwo_tu
;
6507 const gdb_byte
*ptr
= info_ptr
;
6508 struct comp_unit_head header
;
6509 unsigned int length
;
6511 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6513 /* Initialize it due to a false compiler warning. */
6514 header
.signature
= -1;
6515 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6517 /* We need to read the type's signature in order to build the hash
6518 table, but we don't need anything else just yet. */
6520 ptr
= read_and_check_comp_unit_head (per_objfile
, &header
, section
,
6521 abbrev_section
, ptr
, section_kind
);
6523 length
= header
.get_length ();
6525 /* Skip dummy type units. */
6526 if (ptr
>= info_ptr
+ length
6527 || peek_abbrev_code (abfd
, ptr
) == 0
6528 || (header
.unit_type
!= DW_UT_type
6529 && header
.unit_type
!= DW_UT_split_type
))
6535 if (types_htab
== NULL
)
6538 types_htab
= allocate_dwo_unit_table ();
6540 types_htab
= allocate_signatured_type_table ();
6546 dwo_tu
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, dwo_unit
);
6547 dwo_tu
->dwo_file
= dwo_file
;
6548 dwo_tu
->signature
= header
.signature
;
6549 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6550 dwo_tu
->section
= section
;
6551 dwo_tu
->sect_off
= sect_off
;
6552 dwo_tu
->length
= length
;
6556 /* N.B.: type_offset is not usable if this type uses a DWO file.
6557 The real type_offset is in the DWO file. */
6559 sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
6560 sig_type
->signature
= header
.signature
;
6561 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6562 sig_type
->per_cu
.is_debug_types
= 1;
6563 sig_type
->per_cu
.section
= section
;
6564 sig_type
->per_cu
.sect_off
= sect_off
;
6565 sig_type
->per_cu
.length
= length
;
6568 slot
= htab_find_slot (types_htab
.get (),
6569 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6571 gdb_assert (slot
!= NULL
);
6574 sect_offset dup_sect_off
;
6578 const struct dwo_unit
*dup_tu
6579 = (const struct dwo_unit
*) *slot
;
6581 dup_sect_off
= dup_tu
->sect_off
;
6585 const struct signatured_type
*dup_tu
6586 = (const struct signatured_type
*) *slot
;
6588 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6591 complaint (_("debug type entry at offset %s is duplicate to"
6592 " the entry at offset %s, signature %s"),
6593 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6594 hex_string (header
.signature
));
6596 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6598 dwarf_read_debug_printf_v (" offset %s, signature %s",
6599 sect_offset_str (sect_off
),
6600 hex_string (header
.signature
));
6606 /* Create the hash table of all entries in the .debug_types
6607 (or .debug_types.dwo) section(s).
6608 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6609 otherwise it is NULL.
6611 The result is a pointer to the hash table or NULL if there are no types.
6613 Note: This function processes DWO files only, not DWP files. */
6616 create_debug_types_hash_table (dwarf2_per_objfile
*per_objfile
,
6617 struct dwo_file
*dwo_file
,
6618 gdb::array_view
<dwarf2_section_info
> type_sections
,
6619 htab_up
&types_htab
)
6621 for (dwarf2_section_info
§ion
: type_sections
)
6622 create_debug_type_hash_table (per_objfile
, dwo_file
, §ion
, types_htab
,
6626 /* Create the hash table of all entries in the .debug_types section,
6627 and initialize all_type_units.
6628 The result is zero if there is an error (e.g. missing .debug_types section),
6629 otherwise non-zero. */
6632 create_all_type_units (dwarf2_per_objfile
*per_objfile
)
6636 create_debug_type_hash_table (per_objfile
, NULL
, &per_objfile
->per_bfd
->info
,
6637 types_htab
, rcuh_kind::COMPILE
);
6638 create_debug_types_hash_table (per_objfile
, NULL
, per_objfile
->per_bfd
->types
,
6640 if (types_htab
== NULL
)
6642 per_objfile
->per_bfd
->signatured_types
= NULL
;
6646 per_objfile
->per_bfd
->signatured_types
= std::move (types_htab
);
6648 gdb_assert (per_objfile
->per_bfd
->all_type_units
.empty ());
6649 per_objfile
->per_bfd
->all_type_units
.reserve
6650 (htab_elements (per_objfile
->per_bfd
->signatured_types
.get ()));
6652 htab_traverse_noresize (per_objfile
->per_bfd
->signatured_types
.get (),
6653 add_signatured_type_cu_to_table
,
6654 &per_objfile
->per_bfd
->all_type_units
);
6659 /* Add an entry for signature SIG to dwarf2_per_objfile->per_bfd->signatured_types.
6660 If SLOT is non-NULL, it is the entry to use in the hash table.
6661 Otherwise we find one. */
6663 static struct signatured_type
*
6664 add_type_unit (dwarf2_per_objfile
*per_objfile
, ULONGEST sig
, void **slot
)
6666 if (per_objfile
->per_bfd
->all_type_units
.size ()
6667 == per_objfile
->per_bfd
->all_type_units
.capacity ())
6668 ++per_objfile
->per_bfd
->tu_stats
.nr_all_type_units_reallocs
;
6670 signatured_type
*sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
6672 per_objfile
->resize_symtabs ();
6674 per_objfile
->per_bfd
->all_type_units
.push_back (sig_type
);
6675 sig_type
->signature
= sig
;
6676 sig_type
->per_cu
.is_debug_types
= 1;
6677 if (per_objfile
->per_bfd
->using_index
)
6679 sig_type
->per_cu
.v
.quick
=
6680 OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
6681 struct dwarf2_per_cu_quick_data
);
6686 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6689 gdb_assert (*slot
== NULL
);
6691 /* The rest of sig_type must be filled in by the caller. */
6695 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6696 Fill in SIG_ENTRY with DWO_ENTRY. */
6699 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
*per_objfile
,
6700 struct signatured_type
*sig_entry
,
6701 struct dwo_unit
*dwo_entry
)
6703 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6705 /* Make sure we're not clobbering something we don't expect to. */
6706 gdb_assert (! sig_entry
->per_cu
.queued
);
6707 gdb_assert (per_objfile
->get_cu (&sig_entry
->per_cu
) == NULL
);
6708 if (per_bfd
->using_index
)
6710 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6711 gdb_assert (!per_objfile
->symtab_set_p (&sig_entry
->per_cu
));
6714 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6715 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6716 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6717 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6718 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6720 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6721 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6722 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6723 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6724 sig_entry
->per_cu
.per_bfd
= per_bfd
;
6725 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6726 sig_entry
->dwo_unit
= dwo_entry
;
6729 /* Subroutine of lookup_signatured_type.
6730 If we haven't read the TU yet, create the signatured_type data structure
6731 for a TU to be read in directly from a DWO file, bypassing the stub.
6732 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6733 using .gdb_index, then when reading a CU we want to stay in the DWO file
6734 containing that CU. Otherwise we could end up reading several other DWO
6735 files (due to comdat folding) to process the transitive closure of all the
6736 mentioned TUs, and that can be slow. The current DWO file will have every
6737 type signature that it needs.
6738 We only do this for .gdb_index because in the psymtab case we already have
6739 to read all the DWOs to build the type unit groups. */
6741 static struct signatured_type
*
6742 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6744 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6745 struct dwo_file
*dwo_file
;
6746 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6747 struct signatured_type find_sig_entry
, *sig_entry
;
6750 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
6752 /* If TU skeletons have been removed then we may not have read in any
6754 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6755 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6757 /* We only ever need to read in one copy of a signatured type.
6758 Use the global signatured_types array to do our own comdat-folding
6759 of types. If this is the first time we're reading this TU, and
6760 the TU has an entry in .gdb_index, replace the recorded data from
6761 .gdb_index with this TU. */
6763 find_sig_entry
.signature
= sig
;
6764 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6765 &find_sig_entry
, INSERT
);
6766 sig_entry
= (struct signatured_type
*) *slot
;
6768 /* We can get here with the TU already read, *or* in the process of being
6769 read. Don't reassign the global entry to point to this DWO if that's
6770 the case. Also note that if the TU is already being read, it may not
6771 have come from a DWO, the program may be a mix of Fission-compiled
6772 code and non-Fission-compiled code. */
6774 /* Have we already tried to read this TU?
6775 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6776 needn't exist in the global table yet). */
6777 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
6780 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6781 dwo_unit of the TU itself. */
6782 dwo_file
= cu
->dwo_unit
->dwo_file
;
6784 /* Ok, this is the first time we're reading this TU. */
6785 if (dwo_file
->tus
== NULL
)
6787 find_dwo_entry
.signature
= sig
;
6788 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6790 if (dwo_entry
== NULL
)
6793 /* If the global table doesn't have an entry for this TU, add one. */
6794 if (sig_entry
== NULL
)
6795 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6797 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6798 sig_entry
->per_cu
.tu_read
= 1;
6802 /* Subroutine of lookup_signatured_type.
6803 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6804 then try the DWP file. If the TU stub (skeleton) has been removed then
6805 it won't be in .gdb_index. */
6807 static struct signatured_type
*
6808 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6810 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6811 struct dwp_file
*dwp_file
= get_dwp_file (per_objfile
);
6812 struct dwo_unit
*dwo_entry
;
6813 struct signatured_type find_sig_entry
, *sig_entry
;
6816 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
6817 gdb_assert (dwp_file
!= NULL
);
6819 /* If TU skeletons have been removed then we may not have read in any
6821 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6822 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6824 find_sig_entry
.signature
= sig
;
6825 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6826 &find_sig_entry
, INSERT
);
6827 sig_entry
= (struct signatured_type
*) *slot
;
6829 /* Have we already tried to read this TU?
6830 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6831 needn't exist in the global table yet). */
6832 if (sig_entry
!= NULL
)
6835 if (dwp_file
->tus
== NULL
)
6837 dwo_entry
= lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, NULL
, sig
,
6838 1 /* is_debug_types */);
6839 if (dwo_entry
== NULL
)
6842 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6843 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6848 /* Lookup a signature based type for DW_FORM_ref_sig8.
6849 Returns NULL if signature SIG is not present in the table.
6850 It is up to the caller to complain about this. */
6852 static struct signatured_type
*
6853 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6855 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6857 if (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
)
6859 /* We're in a DWO/DWP file, and we're using .gdb_index.
6860 These cases require special processing. */
6861 if (get_dwp_file (per_objfile
) == NULL
)
6862 return lookup_dwo_signatured_type (cu
, sig
);
6864 return lookup_dwp_signatured_type (cu
, sig
);
6868 struct signatured_type find_entry
, *entry
;
6870 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6872 find_entry
.signature
= sig
;
6873 entry
= ((struct signatured_type
*)
6874 htab_find (per_objfile
->per_bfd
->signatured_types
.get (),
6880 /* Low level DIE reading support. */
6882 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6885 init_cu_die_reader (struct die_reader_specs
*reader
,
6886 struct dwarf2_cu
*cu
,
6887 struct dwarf2_section_info
*section
,
6888 struct dwo_file
*dwo_file
,
6889 struct abbrev_table
*abbrev_table
)
6891 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6892 reader
->abfd
= section
->get_bfd_owner ();
6894 reader
->dwo_file
= dwo_file
;
6895 reader
->die_section
= section
;
6896 reader
->buffer
= section
->buffer
;
6897 reader
->buffer_end
= section
->buffer
+ section
->size
;
6898 reader
->abbrev_table
= abbrev_table
;
6901 /* Subroutine of cutu_reader to simplify it.
6902 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6903 There's just a lot of work to do, and cutu_reader is big enough
6906 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6907 from it to the DIE in the DWO. If NULL we are skipping the stub.
6908 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6909 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6910 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6911 STUB_COMP_DIR may be non-NULL.
6912 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6913 are filled in with the info of the DIE from the DWO file.
6914 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6915 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6916 kept around for at least as long as *RESULT_READER.
6918 The result is non-zero if a valid (non-dummy) DIE was found. */
6921 read_cutu_die_from_dwo (dwarf2_cu
*cu
,
6922 struct dwo_unit
*dwo_unit
,
6923 struct die_info
*stub_comp_unit_die
,
6924 const char *stub_comp_dir
,
6925 struct die_reader_specs
*result_reader
,
6926 const gdb_byte
**result_info_ptr
,
6927 struct die_info
**result_comp_unit_die
,
6928 abbrev_table_up
*result_dwo_abbrev_table
)
6930 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6931 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6932 struct objfile
*objfile
= per_objfile
->objfile
;
6934 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6935 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6936 int i
,num_extra_attrs
;
6937 struct dwarf2_section_info
*dwo_abbrev_section
;
6938 struct die_info
*comp_unit_die
;
6940 /* At most one of these may be provided. */
6941 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6943 /* These attributes aren't processed until later:
6944 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6945 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6946 referenced later. However, these attributes are found in the stub
6947 which we won't have later. In order to not impose this complication
6948 on the rest of the code, we read them here and copy them to the
6957 if (stub_comp_unit_die
!= NULL
)
6959 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6961 if (!per_cu
->is_debug_types
)
6962 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6963 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6964 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6965 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6966 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6968 cu
->addr_base
= stub_comp_unit_die
->addr_base ();
6970 /* There should be a DW_AT_rnglists_base (DW_AT_GNU_ranges_base) attribute
6971 here (if needed). We need the value before we can process
6973 cu
->ranges_base
= stub_comp_unit_die
->ranges_base ();
6975 else if (stub_comp_dir
!= NULL
)
6977 /* Reconstruct the comp_dir attribute to simplify the code below. */
6978 comp_dir
= OBSTACK_ZALLOC (&cu
->comp_unit_obstack
, struct attribute
);
6979 comp_dir
->name
= DW_AT_comp_dir
;
6980 comp_dir
->form
= DW_FORM_string
;
6981 comp_dir
->set_string_noncanonical (stub_comp_dir
);
6984 /* Set up for reading the DWO CU/TU. */
6985 cu
->dwo_unit
= dwo_unit
;
6986 dwarf2_section_info
*section
= dwo_unit
->section
;
6987 section
->read (objfile
);
6988 abfd
= section
->get_bfd_owner ();
6989 begin_info_ptr
= info_ptr
= (section
->buffer
6990 + to_underlying (dwo_unit
->sect_off
));
6991 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6993 if (per_cu
->is_debug_types
)
6995 signatured_type
*sig_type
= (struct signatured_type
*) per_cu
;
6997 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6998 section
, dwo_abbrev_section
,
6999 info_ptr
, rcuh_kind::TYPE
);
7000 /* This is not an assert because it can be caused by bad debug info. */
7001 if (sig_type
->signature
!= cu
->header
.signature
)
7003 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
7004 " TU at offset %s [in module %s]"),
7005 hex_string (sig_type
->signature
),
7006 hex_string (cu
->header
.signature
),
7007 sect_offset_str (dwo_unit
->sect_off
),
7008 bfd_get_filename (abfd
));
7010 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7011 /* For DWOs coming from DWP files, we don't know the CU length
7012 nor the type's offset in the TU until now. */
7013 dwo_unit
->length
= cu
->header
.get_length ();
7014 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
7016 /* Establish the type offset that can be used to lookup the type.
7017 For DWO files, we don't know it until now. */
7018 sig_type
->type_offset_in_section
7019 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
7023 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
7024 section
, dwo_abbrev_section
,
7025 info_ptr
, rcuh_kind::COMPILE
);
7026 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7027 /* For DWOs coming from DWP files, we don't know the CU length
7029 dwo_unit
->length
= cu
->header
.get_length ();
7032 dwo_abbrev_section
->read (objfile
);
7033 *result_dwo_abbrev_table
7034 = abbrev_table::read (dwo_abbrev_section
, cu
->header
.abbrev_sect_off
);
7035 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
7036 result_dwo_abbrev_table
->get ());
7038 /* Read in the die, but leave space to copy over the attributes
7039 from the stub. This has the benefit of simplifying the rest of
7040 the code - all the work to maintain the illusion of a single
7041 DW_TAG_{compile,type}_unit DIE is done here. */
7042 num_extra_attrs
= ((stmt_list
!= NULL
)
7046 + (comp_dir
!= NULL
));
7047 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
7050 /* Copy over the attributes from the stub to the DIE we just read in. */
7051 comp_unit_die
= *result_comp_unit_die
;
7052 i
= comp_unit_die
->num_attrs
;
7053 if (stmt_list
!= NULL
)
7054 comp_unit_die
->attrs
[i
++] = *stmt_list
;
7056 comp_unit_die
->attrs
[i
++] = *low_pc
;
7057 if (high_pc
!= NULL
)
7058 comp_unit_die
->attrs
[i
++] = *high_pc
;
7060 comp_unit_die
->attrs
[i
++] = *ranges
;
7061 if (comp_dir
!= NULL
)
7062 comp_unit_die
->attrs
[i
++] = *comp_dir
;
7063 comp_unit_die
->num_attrs
+= num_extra_attrs
;
7065 if (dwarf_die_debug
)
7067 fprintf_unfiltered (gdb_stdlog
,
7068 "Read die from %s@0x%x of %s:\n",
7069 section
->get_name (),
7070 (unsigned) (begin_info_ptr
- section
->buffer
),
7071 bfd_get_filename (abfd
));
7072 dump_die (comp_unit_die
, dwarf_die_debug
);
7075 /* Skip dummy compilation units. */
7076 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
7077 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7080 *result_info_ptr
= info_ptr
;
7084 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
7085 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
7086 signature is part of the header. */
7087 static gdb::optional
<ULONGEST
>
7088 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
7090 if (cu
->header
.version
>= 5)
7091 return cu
->header
.signature
;
7092 struct attribute
*attr
;
7093 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
7094 if (attr
== nullptr || !attr
->form_is_unsigned ())
7095 return gdb::optional
<ULONGEST
> ();
7096 return attr
->as_unsigned ();
7099 /* Subroutine of cutu_reader to simplify it.
7100 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
7101 Returns NULL if the specified DWO unit cannot be found. */
7103 static struct dwo_unit
*
7104 lookup_dwo_unit (dwarf2_cu
*cu
, die_info
*comp_unit_die
, const char *dwo_name
)
7106 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7107 struct dwo_unit
*dwo_unit
;
7108 const char *comp_dir
;
7110 gdb_assert (cu
!= NULL
);
7112 /* Yeah, we look dwo_name up again, but it simplifies the code. */
7113 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7114 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7116 if (per_cu
->is_debug_types
)
7117 dwo_unit
= lookup_dwo_type_unit (cu
, dwo_name
, comp_dir
);
7120 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
7122 if (!signature
.has_value ())
7123 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
7125 dwo_name
, bfd_get_filename (per_cu
->per_bfd
->obfd
));
7127 dwo_unit
= lookup_dwo_comp_unit (cu
, dwo_name
, comp_dir
, *signature
);
7133 /* Subroutine of cutu_reader to simplify it.
7134 See it for a description of the parameters.
7135 Read a TU directly from a DWO file, bypassing the stub. */
7138 cutu_reader::init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
7139 dwarf2_per_objfile
*per_objfile
,
7140 dwarf2_cu
*existing_cu
)
7142 struct signatured_type
*sig_type
;
7144 /* Verify we can do the following downcast, and that we have the
7146 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
7147 sig_type
= (struct signatured_type
*) this_cu
;
7148 gdb_assert (sig_type
->dwo_unit
!= NULL
);
7152 if (existing_cu
!= nullptr)
7155 gdb_assert (cu
->dwo_unit
== sig_type
->dwo_unit
);
7156 /* There's no need to do the rereading_dwo_cu handling that
7157 cutu_reader does since we don't read the stub. */
7161 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
7162 in per_objfile yet. */
7163 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
7164 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
7165 cu
= m_new_cu
.get ();
7168 /* A future optimization, if needed, would be to use an existing
7169 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
7170 could share abbrev tables. */
7172 if (read_cutu_die_from_dwo (cu
, sig_type
->dwo_unit
,
7173 NULL
/* stub_comp_unit_die */,
7174 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
7177 &m_dwo_abbrev_table
) == 0)
7184 /* Initialize a CU (or TU) and read its DIEs.
7185 If the CU defers to a DWO file, read the DWO file as well.
7187 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
7188 Otherwise the table specified in the comp unit header is read in and used.
7189 This is an optimization for when we already have the abbrev table.
7191 If EXISTING_CU is non-NULL, then use it. Otherwise, a new CU is
7194 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
7195 dwarf2_per_objfile
*per_objfile
,
7196 struct abbrev_table
*abbrev_table
,
7197 dwarf2_cu
*existing_cu
,
7199 : die_reader_specs
{},
7202 struct objfile
*objfile
= per_objfile
->objfile
;
7203 struct dwarf2_section_info
*section
= this_cu
->section
;
7204 bfd
*abfd
= section
->get_bfd_owner ();
7205 const gdb_byte
*begin_info_ptr
;
7206 struct signatured_type
*sig_type
= NULL
;
7207 struct dwarf2_section_info
*abbrev_section
;
7208 /* Non-zero if CU currently points to a DWO file and we need to
7209 reread it. When this happens we need to reread the skeleton die
7210 before we can reread the DWO file (this only applies to CUs, not TUs). */
7211 int rereading_dwo_cu
= 0;
7213 if (dwarf_die_debug
)
7214 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7215 this_cu
->is_debug_types
? "type" : "comp",
7216 sect_offset_str (this_cu
->sect_off
));
7218 /* If we're reading a TU directly from a DWO file, including a virtual DWO
7219 file (instead of going through the stub), short-circuit all of this. */
7220 if (this_cu
->reading_dwo_directly
)
7222 /* Narrow down the scope of possibilities to have to understand. */
7223 gdb_assert (this_cu
->is_debug_types
);
7224 gdb_assert (abbrev_table
== NULL
);
7225 init_tu_and_read_dwo_dies (this_cu
, per_objfile
, existing_cu
);
7229 /* This is cheap if the section is already read in. */
7230 section
->read (objfile
);
7232 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7234 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
7238 if (existing_cu
!= nullptr)
7241 /* If this CU is from a DWO file we need to start over, we need to
7242 refetch the attributes from the skeleton CU.
7243 This could be optimized by retrieving those attributes from when we
7244 were here the first time: the previous comp_unit_die was stored in
7245 comp_unit_obstack. But there's no data yet that we need this
7247 if (cu
->dwo_unit
!= NULL
)
7248 rereading_dwo_cu
= 1;
7252 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
7253 in per_objfile yet. */
7254 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
7255 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
7256 cu
= m_new_cu
.get ();
7259 /* Get the header. */
7260 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
7262 /* We already have the header, there's no need to read it in again. */
7263 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
7267 if (this_cu
->is_debug_types
)
7269 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
7270 section
, abbrev_section
,
7271 info_ptr
, rcuh_kind::TYPE
);
7273 /* Since per_cu is the first member of struct signatured_type,
7274 we can go from a pointer to one to a pointer to the other. */
7275 sig_type
= (struct signatured_type
*) this_cu
;
7276 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
7277 gdb_assert (sig_type
->type_offset_in_tu
7278 == cu
->header
.type_cu_offset_in_tu
);
7279 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7281 /* LENGTH has not been set yet for type units if we're
7282 using .gdb_index. */
7283 this_cu
->length
= cu
->header
.get_length ();
7285 /* Establish the type offset that can be used to lookup the type. */
7286 sig_type
->type_offset_in_section
=
7287 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
7289 this_cu
->dwarf_version
= cu
->header
.version
;
7293 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
7294 section
, abbrev_section
,
7296 rcuh_kind::COMPILE
);
7298 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7299 if (this_cu
->length
== 0)
7300 this_cu
->length
= cu
->header
.get_length ();
7302 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
7303 this_cu
->dwarf_version
= cu
->header
.version
;
7307 /* Skip dummy compilation units. */
7308 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7309 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7315 /* If we don't have them yet, read the abbrevs for this compilation unit.
7316 And if we need to read them now, make sure they're freed when we're
7318 if (abbrev_table
!= NULL
)
7319 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
7322 abbrev_section
->read (objfile
);
7323 m_abbrev_table_holder
7324 = abbrev_table::read (abbrev_section
, cu
->header
.abbrev_sect_off
);
7325 abbrev_table
= m_abbrev_table_holder
.get ();
7328 /* Read the top level CU/TU die. */
7329 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
7330 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7332 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
7338 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
7339 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
7340 table from the DWO file and pass the ownership over to us. It will be
7341 referenced from READER, so we must make sure to free it after we're done
7344 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
7345 DWO CU, that this test will fail (the attribute will not be present). */
7346 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7347 if (dwo_name
!= nullptr)
7349 struct dwo_unit
*dwo_unit
;
7350 struct die_info
*dwo_comp_unit_die
;
7352 if (comp_unit_die
->has_children
)
7354 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
7355 " has children (offset %s) [in module %s]"),
7356 sect_offset_str (this_cu
->sect_off
),
7357 bfd_get_filename (abfd
));
7359 dwo_unit
= lookup_dwo_unit (cu
, comp_unit_die
, dwo_name
);
7360 if (dwo_unit
!= NULL
)
7362 if (read_cutu_die_from_dwo (cu
, dwo_unit
,
7363 comp_unit_die
, NULL
,
7366 &m_dwo_abbrev_table
) == 0)
7372 comp_unit_die
= dwo_comp_unit_die
;
7376 /* Yikes, we couldn't find the rest of the DIE, we only have
7377 the stub. A complaint has already been logged. There's
7378 not much more we can do except pass on the stub DIE to
7379 die_reader_func. We don't want to throw an error on bad
7386 cutu_reader::keep ()
7388 /* Done, clean up. */
7389 gdb_assert (!dummy_p
);
7390 if (m_new_cu
!= NULL
)
7392 /* Save this dwarf2_cu in the per_objfile. The per_objfile owns it
7394 dwarf2_per_objfile
*per_objfile
= m_new_cu
->per_objfile
;
7395 per_objfile
->set_cu (m_this_cu
, m_new_cu
.release ());
7399 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
7400 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
7401 assumed to have already done the lookup to find the DWO file).
7403 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7404 THIS_CU->is_debug_types, but nothing else.
7406 We fill in THIS_CU->length.
7408 THIS_CU->cu is always freed when done.
7409 This is done in order to not leave THIS_CU->cu in a state where we have
7410 to care whether it refers to the "main" CU or the DWO CU.
7412 When parent_cu is passed, it is used to provide a default value for
7413 str_offsets_base and addr_base from the parent. */
7415 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
7416 dwarf2_per_objfile
*per_objfile
,
7417 struct dwarf2_cu
*parent_cu
,
7418 struct dwo_file
*dwo_file
)
7419 : die_reader_specs
{},
7422 struct objfile
*objfile
= per_objfile
->objfile
;
7423 struct dwarf2_section_info
*section
= this_cu
->section
;
7424 bfd
*abfd
= section
->get_bfd_owner ();
7425 struct dwarf2_section_info
*abbrev_section
;
7426 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7428 if (dwarf_die_debug
)
7429 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7430 this_cu
->is_debug_types
? "type" : "comp",
7431 sect_offset_str (this_cu
->sect_off
));
7433 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
7435 abbrev_section
= (dwo_file
!= NULL
7436 ? &dwo_file
->sections
.abbrev
7437 : get_abbrev_section_for_cu (this_cu
));
7439 /* This is cheap if the section is already read in. */
7440 section
->read (objfile
);
7442 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
7444 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7445 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &m_new_cu
->header
,
7446 section
, abbrev_section
, info_ptr
,
7447 (this_cu
->is_debug_types
7449 : rcuh_kind::COMPILE
));
7451 if (parent_cu
!= nullptr)
7453 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
7454 m_new_cu
->addr_base
= parent_cu
->addr_base
;
7456 this_cu
->length
= m_new_cu
->header
.get_length ();
7458 /* Skip dummy compilation units. */
7459 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7460 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7466 abbrev_section
->read (objfile
);
7467 m_abbrev_table_holder
7468 = abbrev_table::read (abbrev_section
, m_new_cu
->header
.abbrev_sect_off
);
7470 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
7471 m_abbrev_table_holder
.get ());
7472 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7476 /* Type Unit Groups.
7478 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7479 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7480 so that all types coming from the same compilation (.o file) are grouped
7481 together. A future step could be to put the types in the same symtab as
7482 the CU the types ultimately came from. */
7485 hash_type_unit_group (const void *item
)
7487 const struct type_unit_group
*tu_group
7488 = (const struct type_unit_group
*) item
;
7490 return hash_stmt_list_entry (&tu_group
->hash
);
7494 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7496 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7497 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7499 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7502 /* Allocate a hash table for type unit groups. */
7505 allocate_type_unit_groups_table ()
7507 return htab_up (htab_create_alloc (3,
7508 hash_type_unit_group
,
7510 NULL
, xcalloc
, xfree
));
7513 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7514 partial symtabs. We combine several TUs per psymtab to not let the size
7515 of any one psymtab grow too big. */
7516 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7517 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7519 /* Helper routine for get_type_unit_group.
7520 Create the type_unit_group object used to hold one or more TUs. */
7522 static struct type_unit_group
*
7523 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7525 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7526 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
7527 struct dwarf2_per_cu_data
*per_cu
;
7528 struct type_unit_group
*tu_group
;
7530 tu_group
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, type_unit_group
);
7531 per_cu
= &tu_group
->per_cu
;
7532 per_cu
->per_bfd
= per_bfd
;
7534 if (per_bfd
->using_index
)
7536 per_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
7537 struct dwarf2_per_cu_quick_data
);
7541 unsigned int line_offset
= to_underlying (line_offset_struct
);
7542 dwarf2_psymtab
*pst
;
7545 /* Give the symtab a useful name for debug purposes. */
7546 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7547 name
= string_printf ("<type_units_%d>",
7548 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7550 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7552 pst
= create_partial_symtab (per_cu
, per_objfile
, name
.c_str ());
7553 pst
->anonymous
= true;
7556 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7557 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7562 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7563 STMT_LIST is a DW_AT_stmt_list attribute. */
7565 static struct type_unit_group
*
7566 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7568 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7569 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7570 struct type_unit_group
*tu_group
;
7572 unsigned int line_offset
;
7573 struct type_unit_group type_unit_group_for_lookup
;
7575 if (per_objfile
->per_bfd
->type_unit_groups
== NULL
)
7576 per_objfile
->per_bfd
->type_unit_groups
= allocate_type_unit_groups_table ();
7578 /* Do we need to create a new group, or can we use an existing one? */
7580 if (stmt_list
!= nullptr && stmt_list
->form_is_unsigned ())
7582 line_offset
= stmt_list
->as_unsigned ();
7583 ++tu_stats
->nr_symtab_sharers
;
7587 /* Ugh, no stmt_list. Rare, but we have to handle it.
7588 We can do various things here like create one group per TU or
7589 spread them over multiple groups to split up the expansion work.
7590 To avoid worst case scenarios (too many groups or too large groups)
7591 we, umm, group them in bunches. */
7592 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7593 | (tu_stats
->nr_stmt_less_type_units
7594 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7595 ++tu_stats
->nr_stmt_less_type_units
;
7598 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7599 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7600 slot
= htab_find_slot (per_objfile
->per_bfd
->type_unit_groups
.get (),
7601 &type_unit_group_for_lookup
, INSERT
);
7604 tu_group
= (struct type_unit_group
*) *slot
;
7605 gdb_assert (tu_group
!= NULL
);
7609 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7610 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7612 ++tu_stats
->nr_symtabs
;
7618 /* Partial symbol tables. */
7620 /* Create a psymtab named NAME and assign it to PER_CU.
7622 The caller must fill in the following details:
7623 dirname, textlow, texthigh. */
7625 static dwarf2_psymtab
*
7626 create_partial_symtab (dwarf2_per_cu_data
*per_cu
,
7627 dwarf2_per_objfile
*per_objfile
,
7630 struct objfile
*objfile
= per_objfile
->objfile
;
7631 dwarf2_psymtab
*pst
;
7633 pst
= new dwarf2_psymtab (name
, objfile
, per_cu
);
7635 pst
->psymtabs_addrmap_supported
= true;
7637 /* This is the glue that links PST into GDB's symbol API. */
7638 per_cu
->v
.psymtab
= pst
;
7643 /* DIE reader function for process_psymtab_comp_unit. */
7646 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7647 const gdb_byte
*info_ptr
,
7648 struct die_info
*comp_unit_die
,
7649 enum language pretend_language
)
7651 struct dwarf2_cu
*cu
= reader
->cu
;
7652 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7653 struct objfile
*objfile
= per_objfile
->objfile
;
7654 struct gdbarch
*gdbarch
= objfile
->arch ();
7655 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7657 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7658 dwarf2_psymtab
*pst
;
7659 enum pc_bounds_kind cu_bounds_kind
;
7660 const char *filename
;
7662 gdb_assert (! per_cu
->is_debug_types
);
7664 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
7666 /* Allocate a new partial symbol table structure. */
7667 gdb::unique_xmalloc_ptr
<char> debug_filename
;
7668 static const char artificial
[] = "<artificial>";
7669 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7670 if (filename
== NULL
)
7672 else if (strcmp (filename
, artificial
) == 0)
7674 debug_filename
.reset (concat (artificial
, "@",
7675 sect_offset_str (per_cu
->sect_off
),
7677 filename
= debug_filename
.get ();
7680 pst
= create_partial_symtab (per_cu
, per_objfile
, filename
);
7682 /* This must be done before calling dwarf2_build_include_psymtabs. */
7683 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7685 baseaddr
= objfile
->text_section_offset ();
7687 dwarf2_find_base_address (comp_unit_die
, cu
);
7689 /* Possibly set the default values of LOWPC and HIGHPC from
7691 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7692 &best_highpc
, cu
, pst
);
7693 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7696 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7699 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7701 /* Store the contiguous range if it is not empty; it can be
7702 empty for CUs with no code. */
7703 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
7707 /* Check if comp unit has_children.
7708 If so, read the rest of the partial symbols from this comp unit.
7709 If not, there's no more debug_info for this comp unit. */
7710 if (comp_unit_die
->has_children
)
7712 struct partial_die_info
*first_die
;
7713 CORE_ADDR lowpc
, highpc
;
7715 lowpc
= ((CORE_ADDR
) -1);
7716 highpc
= ((CORE_ADDR
) 0);
7718 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7720 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7721 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7723 /* If we didn't find a lowpc, set it to highpc to avoid
7724 complaints from `maint check'. */
7725 if (lowpc
== ((CORE_ADDR
) -1))
7728 /* If the compilation unit didn't have an explicit address range,
7729 then use the information extracted from its child dies. */
7730 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7733 best_highpc
= highpc
;
7736 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7737 best_lowpc
+ baseaddr
)
7739 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7740 best_highpc
+ baseaddr
)
7745 if (!cu
->per_cu
->imported_symtabs_empty ())
7748 int len
= cu
->per_cu
->imported_symtabs_size ();
7750 /* Fill in 'dependencies' here; we fill in 'users' in a
7752 pst
->number_of_dependencies
= len
;
7754 = objfile
->partial_symtabs
->allocate_dependencies (len
);
7755 for (i
= 0; i
< len
; ++i
)
7757 pst
->dependencies
[i
]
7758 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7761 cu
->per_cu
->imported_symtabs_free ();
7764 /* Get the list of files included in the current compilation unit,
7765 and build a psymtab for each of them. */
7766 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
7768 dwarf_read_debug_printf ("Psymtab for %s unit @%s: %s - %s"
7769 ", %d global, %d static syms",
7770 per_cu
->is_debug_types
? "type" : "comp",
7771 sect_offset_str (per_cu
->sect_off
),
7772 paddress (gdbarch
, pst
->text_low (objfile
)),
7773 paddress (gdbarch
, pst
->text_high (objfile
)),
7774 (int) pst
->global_psymbols
.size (),
7775 (int) pst
->static_psymbols
.size ());
7778 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7779 Process compilation unit THIS_CU for a psymtab. */
7782 process_psymtab_comp_unit (dwarf2_per_cu_data
*this_cu
,
7783 dwarf2_per_objfile
*per_objfile
,
7784 bool want_partial_unit
,
7785 enum language pretend_language
)
7787 /* If this compilation unit was already read in, free the
7788 cached copy in order to read it in again. This is
7789 necessary because we skipped some symbols when we first
7790 read in the compilation unit (see load_partial_dies).
7791 This problem could be avoided, but the benefit is unclear. */
7792 per_objfile
->remove_cu (this_cu
);
7794 cutu_reader
reader (this_cu
, per_objfile
, nullptr, nullptr, false);
7796 switch (reader
.comp_unit_die
->tag
)
7798 case DW_TAG_compile_unit
:
7799 this_cu
->unit_type
= DW_UT_compile
;
7801 case DW_TAG_partial_unit
:
7802 this_cu
->unit_type
= DW_UT_partial
;
7812 else if (this_cu
->is_debug_types
)
7813 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7814 reader
.comp_unit_die
);
7815 else if (want_partial_unit
7816 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7817 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7818 reader
.comp_unit_die
,
7821 this_cu
->lang
= reader
.cu
->language
;
7823 /* Age out any secondary CUs. */
7824 per_objfile
->age_comp_units ();
7827 /* Reader function for build_type_psymtabs. */
7830 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7831 const gdb_byte
*info_ptr
,
7832 struct die_info
*type_unit_die
)
7834 dwarf2_per_objfile
*per_objfile
= reader
->cu
->per_objfile
;
7835 struct dwarf2_cu
*cu
= reader
->cu
;
7836 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7837 struct signatured_type
*sig_type
;
7838 struct type_unit_group
*tu_group
;
7839 struct attribute
*attr
;
7840 struct partial_die_info
*first_die
;
7841 CORE_ADDR lowpc
, highpc
;
7842 dwarf2_psymtab
*pst
;
7844 gdb_assert (per_cu
->is_debug_types
);
7845 sig_type
= (struct signatured_type
*) per_cu
;
7847 if (! type_unit_die
->has_children
)
7850 attr
= type_unit_die
->attr (DW_AT_stmt_list
);
7851 tu_group
= get_type_unit_group (cu
, attr
);
7853 if (tu_group
->tus
== nullptr)
7854 tu_group
->tus
= new std::vector
<signatured_type
*>;
7855 tu_group
->tus
->push_back (sig_type
);
7857 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7858 pst
= create_partial_symtab (per_cu
, per_objfile
, "");
7859 pst
->anonymous
= true;
7861 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7863 lowpc
= (CORE_ADDR
) -1;
7864 highpc
= (CORE_ADDR
) 0;
7865 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7870 /* Struct used to sort TUs by their abbreviation table offset. */
7872 struct tu_abbrev_offset
7874 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7875 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7878 signatured_type
*sig_type
;
7879 sect_offset abbrev_offset
;
7882 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
7885 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
7886 const struct tu_abbrev_offset
&b
)
7888 return a
.abbrev_offset
< b
.abbrev_offset
;
7891 /* Efficiently read all the type units.
7892 This does the bulk of the work for build_type_psymtabs.
7894 The efficiency is because we sort TUs by the abbrev table they use and
7895 only read each abbrev table once. In one program there are 200K TUs
7896 sharing 8K abbrev tables.
7898 The main purpose of this function is to support building the
7899 dwarf2_per_objfile->per_bfd->type_unit_groups table.
7900 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7901 can collapse the search space by grouping them by stmt_list.
7902 The savings can be significant, in the same program from above the 200K TUs
7903 share 8K stmt_list tables.
7905 FUNC is expected to call get_type_unit_group, which will create the
7906 struct type_unit_group if necessary and add it to
7907 dwarf2_per_objfile->per_bfd->type_unit_groups. */
7910 build_type_psymtabs_1 (dwarf2_per_objfile
*per_objfile
)
7912 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7913 abbrev_table_up abbrev_table
;
7914 sect_offset abbrev_offset
;
7916 /* It's up to the caller to not call us multiple times. */
7917 gdb_assert (per_objfile
->per_bfd
->type_unit_groups
== NULL
);
7919 if (per_objfile
->per_bfd
->all_type_units
.empty ())
7922 /* TUs typically share abbrev tables, and there can be way more TUs than
7923 abbrev tables. Sort by abbrev table to reduce the number of times we
7924 read each abbrev table in.
7925 Alternatives are to punt or to maintain a cache of abbrev tables.
7926 This is simpler and efficient enough for now.
7928 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7929 symtab to use). Typically TUs with the same abbrev offset have the same
7930 stmt_list value too so in practice this should work well.
7932 The basic algorithm here is:
7934 sort TUs by abbrev table
7935 for each TU with same abbrev table:
7936 read abbrev table if first user
7937 read TU top level DIE
7938 [IWBN if DWO skeletons had DW_AT_stmt_list]
7941 dwarf_read_debug_printf ("Building type unit groups ...");
7943 /* Sort in a separate table to maintain the order of all_type_units
7944 for .gdb_index: TU indices directly index all_type_units. */
7945 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7946 sorted_by_abbrev
.reserve (per_objfile
->per_bfd
->all_type_units
.size ());
7948 for (signatured_type
*sig_type
: per_objfile
->per_bfd
->all_type_units
)
7949 sorted_by_abbrev
.emplace_back
7950 (sig_type
, read_abbrev_offset (per_objfile
, sig_type
->per_cu
.section
,
7951 sig_type
->per_cu
.sect_off
));
7953 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
7954 sort_tu_by_abbrev_offset
);
7956 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7958 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7960 /* Switch to the next abbrev table if necessary. */
7961 if (abbrev_table
== NULL
7962 || tu
.abbrev_offset
!= abbrev_offset
)
7964 abbrev_offset
= tu
.abbrev_offset
;
7965 per_objfile
->per_bfd
->abbrev
.read (per_objfile
->objfile
);
7967 abbrev_table::read (&per_objfile
->per_bfd
->abbrev
, abbrev_offset
);
7968 ++tu_stats
->nr_uniq_abbrev_tables
;
7971 cutu_reader
reader (&tu
.sig_type
->per_cu
, per_objfile
,
7972 abbrev_table
.get (), nullptr, false);
7973 if (!reader
.dummy_p
)
7974 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7975 reader
.comp_unit_die
);
7979 /* Print collected type unit statistics. */
7982 print_tu_stats (dwarf2_per_objfile
*per_objfile
)
7984 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7986 dwarf_read_debug_printf ("Type unit statistics:");
7987 dwarf_read_debug_printf (" %zu TUs",
7988 per_objfile
->per_bfd
->all_type_units
.size ());
7989 dwarf_read_debug_printf (" %d uniq abbrev tables",
7990 tu_stats
->nr_uniq_abbrev_tables
);
7991 dwarf_read_debug_printf (" %d symtabs from stmt_list entries",
7992 tu_stats
->nr_symtabs
);
7993 dwarf_read_debug_printf (" %d symtab sharers",
7994 tu_stats
->nr_symtab_sharers
);
7995 dwarf_read_debug_printf (" %d type units without a stmt_list",
7996 tu_stats
->nr_stmt_less_type_units
);
7997 dwarf_read_debug_printf (" %d all_type_units reallocs",
7998 tu_stats
->nr_all_type_units_reallocs
);
8001 /* Traversal function for build_type_psymtabs. */
8004 build_type_psymtab_dependencies (void **slot
, void *info
)
8006 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
8007 struct objfile
*objfile
= per_objfile
->objfile
;
8008 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
8009 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
8010 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
8011 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
8014 gdb_assert (len
> 0);
8015 gdb_assert (per_cu
->type_unit_group_p ());
8017 pst
->number_of_dependencies
= len
;
8018 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
8019 for (i
= 0; i
< len
; ++i
)
8021 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
8022 gdb_assert (iter
->per_cu
.is_debug_types
);
8023 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
8024 iter
->type_unit_group
= tu_group
;
8027 delete tu_group
->tus
;
8028 tu_group
->tus
= nullptr;
8033 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8034 Build partial symbol tables for the .debug_types comp-units. */
8037 build_type_psymtabs (dwarf2_per_objfile
*per_objfile
)
8039 if (! create_all_type_units (per_objfile
))
8042 build_type_psymtabs_1 (per_objfile
);
8045 /* Traversal function for process_skeletonless_type_unit.
8046 Read a TU in a DWO file and build partial symbols for it. */
8049 process_skeletonless_type_unit (void **slot
, void *info
)
8051 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
8052 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
8053 struct signatured_type find_entry
, *entry
;
8055 /* If this TU doesn't exist in the global table, add it and read it in. */
8057 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
8058 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
8060 find_entry
.signature
= dwo_unit
->signature
;
8061 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
8062 &find_entry
, INSERT
);
8063 /* If we've already seen this type there's nothing to do. What's happening
8064 is we're doing our own version of comdat-folding here. */
8068 /* This does the job that create_all_type_units would have done for
8070 entry
= add_type_unit (per_objfile
, dwo_unit
->signature
, slot
);
8071 fill_in_sig_entry_from_dwo_entry (per_objfile
, entry
, dwo_unit
);
8074 /* This does the job that build_type_psymtabs_1 would have done. */
8075 cutu_reader
reader (&entry
->per_cu
, per_objfile
, nullptr, nullptr, false);
8076 if (!reader
.dummy_p
)
8077 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
8078 reader
.comp_unit_die
);
8083 /* Traversal function for process_skeletonless_type_units. */
8086 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
8088 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
8090 if (dwo_file
->tus
!= NULL
)
8091 htab_traverse_noresize (dwo_file
->tus
.get (),
8092 process_skeletonless_type_unit
, info
);
8097 /* Scan all TUs of DWO files, verifying we've processed them.
8098 This is needed in case a TU was emitted without its skeleton.
8099 Note: This can't be done until we know what all the DWO files are. */
8102 process_skeletonless_type_units (dwarf2_per_objfile
*per_objfile
)
8104 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
8105 if (get_dwp_file (per_objfile
) == NULL
8106 && per_objfile
->per_bfd
->dwo_files
!= NULL
)
8108 htab_traverse_noresize (per_objfile
->per_bfd
->dwo_files
.get (),
8109 process_dwo_file_for_skeletonless_type_units
,
8114 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
8117 set_partial_user (dwarf2_per_objfile
*per_objfile
)
8119 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
8121 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
8126 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
8128 /* Set the 'user' field only if it is not already set. */
8129 if (pst
->dependencies
[j
]->user
== NULL
)
8130 pst
->dependencies
[j
]->user
= pst
;
8135 /* Build the partial symbol table by doing a quick pass through the
8136 .debug_info and .debug_abbrev sections. */
8139 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
)
8141 struct objfile
*objfile
= per_objfile
->objfile
;
8143 dwarf_read_debug_printf ("Building psymtabs of objfile %s ...",
8144 objfile_name (objfile
));
8146 scoped_restore restore_reading_psyms
8147 = make_scoped_restore (&per_objfile
->per_bfd
->reading_partial_symbols
,
8150 per_objfile
->per_bfd
->info
.read (objfile
);
8152 /* Any cached compilation units will be linked by the per-objfile
8153 read_in_chain. Make sure to free them when we're done. */
8154 free_cached_comp_units
freer (per_objfile
);
8156 build_type_psymtabs (per_objfile
);
8158 create_all_comp_units (per_objfile
);
8160 /* Create a temporary address map on a temporary obstack. We later
8161 copy this to the final obstack. */
8162 auto_obstack temp_obstack
;
8164 scoped_restore save_psymtabs_addrmap
8165 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
8166 addrmap_create_mutable (&temp_obstack
));
8168 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
8170 if (per_cu
->v
.psymtab
!= NULL
)
8171 /* In case a forward DW_TAG_imported_unit has read the CU already. */
8173 process_psymtab_comp_unit (per_cu
, per_objfile
, false,
8177 /* This has to wait until we read the CUs, we need the list of DWOs. */
8178 process_skeletonless_type_units (per_objfile
);
8180 /* Now that all TUs have been processed we can fill in the dependencies. */
8181 if (per_objfile
->per_bfd
->type_unit_groups
!= NULL
)
8183 htab_traverse_noresize (per_objfile
->per_bfd
->type_unit_groups
.get (),
8184 build_type_psymtab_dependencies
, per_objfile
);
8187 if (dwarf_read_debug
> 0)
8188 print_tu_stats (per_objfile
);
8190 set_partial_user (per_objfile
);
8192 objfile
->partial_symtabs
->psymtabs_addrmap
8193 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
8194 objfile
->partial_symtabs
->obstack ());
8195 /* At this point we want to keep the address map. */
8196 save_psymtabs_addrmap
.release ();
8198 dwarf_read_debug_printf ("Done building psymtabs of %s",
8199 objfile_name (objfile
));
8202 /* Load the partial DIEs for a secondary CU into memory.
8203 This is also used when rereading a primary CU with load_all_dies. */
8206 load_partial_comp_unit (dwarf2_per_cu_data
*this_cu
,
8207 dwarf2_per_objfile
*per_objfile
,
8208 dwarf2_cu
*existing_cu
)
8210 cutu_reader
reader (this_cu
, per_objfile
, nullptr, existing_cu
, false);
8212 if (!reader
.dummy_p
)
8214 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
8217 /* Check if comp unit has_children.
8218 If so, read the rest of the partial symbols from this comp unit.
8219 If not, there's no more debug_info for this comp unit. */
8220 if (reader
.comp_unit_die
->has_children
)
8221 load_partial_dies (&reader
, reader
.info_ptr
, 0);
8228 read_comp_units_from_section (dwarf2_per_objfile
*per_objfile
,
8229 struct dwarf2_section_info
*section
,
8230 struct dwarf2_section_info
*abbrev_section
,
8231 unsigned int is_dwz
)
8233 const gdb_byte
*info_ptr
;
8234 struct objfile
*objfile
= per_objfile
->objfile
;
8236 dwarf_read_debug_printf ("Reading %s for %s",
8237 section
->get_name (),
8238 section
->get_file_name ());
8240 section
->read (objfile
);
8242 info_ptr
= section
->buffer
;
8244 while (info_ptr
< section
->buffer
+ section
->size
)
8246 struct dwarf2_per_cu_data
*this_cu
;
8248 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
8250 comp_unit_head cu_header
;
8251 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
8252 abbrev_section
, info_ptr
,
8253 rcuh_kind::COMPILE
);
8255 /* Save the compilation unit for later lookup. */
8256 if (cu_header
.unit_type
!= DW_UT_type
)
8257 this_cu
= per_objfile
->per_bfd
->allocate_per_cu ();
8260 auto sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
8261 sig_type
->signature
= cu_header
.signature
;
8262 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
8263 this_cu
= &sig_type
->per_cu
;
8265 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
8266 this_cu
->sect_off
= sect_off
;
8267 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
8268 this_cu
->is_dwz
= is_dwz
;
8269 this_cu
->section
= section
;
8271 per_objfile
->per_bfd
->all_comp_units
.push_back (this_cu
);
8273 info_ptr
= info_ptr
+ this_cu
->length
;
8277 /* Create a list of all compilation units in OBJFILE.
8278 This is only done for -readnow and building partial symtabs. */
8281 create_all_comp_units (dwarf2_per_objfile
*per_objfile
)
8283 gdb_assert (per_objfile
->per_bfd
->all_comp_units
.empty ());
8284 read_comp_units_from_section (per_objfile
, &per_objfile
->per_bfd
->info
,
8285 &per_objfile
->per_bfd
->abbrev
, 0);
8287 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
8289 read_comp_units_from_section (per_objfile
, &dwz
->info
, &dwz
->abbrev
, 1);
8292 /* Process all loaded DIEs for compilation unit CU, starting at
8293 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
8294 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
8295 DW_AT_ranges). See the comments of add_partial_subprogram on how
8296 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
8299 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
8300 CORE_ADDR
*highpc
, int set_addrmap
,
8301 struct dwarf2_cu
*cu
)
8303 struct partial_die_info
*pdi
;
8305 /* Now, march along the PDI's, descending into ones which have
8306 interesting children but skipping the children of the other ones,
8307 until we reach the end of the compilation unit. */
8315 /* Anonymous namespaces or modules have no name but have interesting
8316 children, so we need to look at them. Ditto for anonymous
8319 if (pdi
->raw_name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
8320 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
8321 || pdi
->tag
== DW_TAG_imported_unit
8322 || pdi
->tag
== DW_TAG_inlined_subroutine
)
8326 case DW_TAG_subprogram
:
8327 case DW_TAG_inlined_subroutine
:
8328 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8329 if (cu
->language
== language_cplus
)
8330 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8333 case DW_TAG_constant
:
8334 case DW_TAG_variable
:
8335 case DW_TAG_typedef
:
8336 case DW_TAG_union_type
:
8337 if (!pdi
->is_declaration
8338 || (pdi
->tag
== DW_TAG_variable
&& pdi
->is_external
))
8340 add_partial_symbol (pdi
, cu
);
8343 case DW_TAG_class_type
:
8344 case DW_TAG_interface_type
:
8345 case DW_TAG_structure_type
:
8346 if (!pdi
->is_declaration
)
8348 add_partial_symbol (pdi
, cu
);
8350 if ((cu
->language
== language_rust
8351 || cu
->language
== language_cplus
) && pdi
->has_children
)
8352 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8355 case DW_TAG_enumeration_type
:
8356 if (!pdi
->is_declaration
)
8357 add_partial_enumeration (pdi
, cu
);
8359 case DW_TAG_base_type
:
8360 case DW_TAG_subrange_type
:
8361 /* File scope base type definitions are added to the partial
8363 add_partial_symbol (pdi
, cu
);
8365 case DW_TAG_namespace
:
8366 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8369 if (!pdi
->is_declaration
)
8370 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8372 case DW_TAG_imported_unit
:
8374 struct dwarf2_per_cu_data
*per_cu
;
8376 /* For now we don't handle imported units in type units. */
8377 if (cu
->per_cu
->is_debug_types
)
8379 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8380 " supported in type units [in module %s]"),
8381 objfile_name (cu
->per_objfile
->objfile
));
8384 per_cu
= dwarf2_find_containing_comp_unit
8385 (pdi
->d
.sect_off
, pdi
->is_dwz
, cu
->per_objfile
);
8387 /* Go read the partial unit, if needed. */
8388 if (per_cu
->v
.psymtab
== NULL
)
8389 process_psymtab_comp_unit (per_cu
, cu
->per_objfile
, true,
8392 cu
->per_cu
->imported_symtabs_push (per_cu
);
8395 case DW_TAG_imported_declaration
:
8396 add_partial_symbol (pdi
, cu
);
8403 /* If the die has a sibling, skip to the sibling. */
8405 pdi
= pdi
->die_sibling
;
8409 /* Functions used to compute the fully scoped name of a partial DIE.
8411 Normally, this is simple. For C++, the parent DIE's fully scoped
8412 name is concatenated with "::" and the partial DIE's name.
8413 Enumerators are an exception; they use the scope of their parent
8414 enumeration type, i.e. the name of the enumeration type is not
8415 prepended to the enumerator.
8417 There are two complexities. One is DW_AT_specification; in this
8418 case "parent" means the parent of the target of the specification,
8419 instead of the direct parent of the DIE. The other is compilers
8420 which do not emit DW_TAG_namespace; in this case we try to guess
8421 the fully qualified name of structure types from their members'
8422 linkage names. This must be done using the DIE's children rather
8423 than the children of any DW_AT_specification target. We only need
8424 to do this for structures at the top level, i.e. if the target of
8425 any DW_AT_specification (if any; otherwise the DIE itself) does not
8428 /* Compute the scope prefix associated with PDI's parent, in
8429 compilation unit CU. The result will be allocated on CU's
8430 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8431 field. NULL is returned if no prefix is necessary. */
8433 partial_die_parent_scope (struct partial_die_info
*pdi
,
8434 struct dwarf2_cu
*cu
)
8436 const char *grandparent_scope
;
8437 struct partial_die_info
*parent
, *real_pdi
;
8439 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8440 then this means the parent of the specification DIE. */
8443 while (real_pdi
->has_specification
)
8445 auto res
= find_partial_die (real_pdi
->spec_offset
,
8446 real_pdi
->spec_is_dwz
, cu
);
8451 parent
= real_pdi
->die_parent
;
8455 if (parent
->scope_set
)
8456 return parent
->scope
;
8460 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8462 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8463 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8464 Work around this problem here. */
8465 if (cu
->language
== language_cplus
8466 && parent
->tag
== DW_TAG_namespace
8467 && strcmp (parent
->name (cu
), "::") == 0
8468 && grandparent_scope
== NULL
)
8470 parent
->scope
= NULL
;
8471 parent
->scope_set
= 1;
8475 /* Nested subroutines in Fortran get a prefix. */
8476 if (pdi
->tag
== DW_TAG_enumerator
)
8477 /* Enumerators should not get the name of the enumeration as a prefix. */
8478 parent
->scope
= grandparent_scope
;
8479 else if (parent
->tag
== DW_TAG_namespace
8480 || parent
->tag
== DW_TAG_module
8481 || parent
->tag
== DW_TAG_structure_type
8482 || parent
->tag
== DW_TAG_class_type
8483 || parent
->tag
== DW_TAG_interface_type
8484 || parent
->tag
== DW_TAG_union_type
8485 || parent
->tag
== DW_TAG_enumeration_type
8486 || (cu
->language
== language_fortran
8487 && parent
->tag
== DW_TAG_subprogram
8488 && pdi
->tag
== DW_TAG_subprogram
))
8490 if (grandparent_scope
== NULL
)
8491 parent
->scope
= parent
->name (cu
);
8493 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8495 parent
->name (cu
), 0, cu
);
8499 /* FIXME drow/2004-04-01: What should we be doing with
8500 function-local names? For partial symbols, we should probably be
8502 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8503 dwarf_tag_name (parent
->tag
),
8504 sect_offset_str (pdi
->sect_off
));
8505 parent
->scope
= grandparent_scope
;
8508 parent
->scope_set
= 1;
8509 return parent
->scope
;
8512 /* Return the fully scoped name associated with PDI, from compilation unit
8513 CU. The result will be allocated with malloc. */
8515 static gdb::unique_xmalloc_ptr
<char>
8516 partial_die_full_name (struct partial_die_info
*pdi
,
8517 struct dwarf2_cu
*cu
)
8519 const char *parent_scope
;
8521 /* If this is a template instantiation, we can not work out the
8522 template arguments from partial DIEs. So, unfortunately, we have
8523 to go through the full DIEs. At least any work we do building
8524 types here will be reused if full symbols are loaded later. */
8525 if (pdi
->has_template_arguments
)
8529 if (pdi
->name (cu
) != NULL
&& strchr (pdi
->name (cu
), '<') == NULL
)
8531 struct die_info
*die
;
8532 struct attribute attr
;
8533 struct dwarf2_cu
*ref_cu
= cu
;
8535 /* DW_FORM_ref_addr is using section offset. */
8536 attr
.name
= (enum dwarf_attribute
) 0;
8537 attr
.form
= DW_FORM_ref_addr
;
8538 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8539 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8541 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8545 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8546 if (parent_scope
== NULL
)
8549 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8555 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8557 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
8558 struct objfile
*objfile
= per_objfile
->objfile
;
8559 struct gdbarch
*gdbarch
= objfile
->arch ();
8561 const char *actual_name
= NULL
;
8564 baseaddr
= objfile
->text_section_offset ();
8566 gdb::unique_xmalloc_ptr
<char> built_actual_name
8567 = partial_die_full_name (pdi
, cu
);
8568 if (built_actual_name
!= NULL
)
8569 actual_name
= built_actual_name
.get ();
8571 if (actual_name
== NULL
)
8572 actual_name
= pdi
->name (cu
);
8574 partial_symbol psymbol
;
8575 memset (&psymbol
, 0, sizeof (psymbol
));
8576 psymbol
.ginfo
.set_language (cu
->language
, &objfile
->objfile_obstack
);
8577 psymbol
.ginfo
.section
= -1;
8579 /* The code below indicates that the psymbol should be installed by
8581 gdb::optional
<psymbol_placement
> where
;
8585 case DW_TAG_inlined_subroutine
:
8586 case DW_TAG_subprogram
:
8587 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8589 if (pdi
->is_external
8590 || cu
->language
== language_ada
8591 || (cu
->language
== language_fortran
8592 && pdi
->die_parent
!= NULL
8593 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8595 /* Normally, only "external" DIEs are part of the global scope.
8596 But in Ada and Fortran, we want to be able to access nested
8597 procedures globally. So all Ada and Fortran subprograms are
8598 stored in the global scope. */
8599 where
= psymbol_placement::GLOBAL
;
8602 where
= psymbol_placement::STATIC
;
8604 psymbol
.domain
= VAR_DOMAIN
;
8605 psymbol
.aclass
= LOC_BLOCK
;
8606 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8607 psymbol
.ginfo
.value
.address
= addr
;
8609 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8610 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8612 case DW_TAG_constant
:
8613 psymbol
.domain
= VAR_DOMAIN
;
8614 psymbol
.aclass
= LOC_STATIC
;
8615 where
= (pdi
->is_external
8616 ? psymbol_placement::GLOBAL
8617 : psymbol_placement::STATIC
);
8619 case DW_TAG_variable
:
8621 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8625 && !per_objfile
->per_bfd
->has_section_at_zero
)
8627 /* A global or static variable may also have been stripped
8628 out by the linker if unused, in which case its address
8629 will be nullified; do not add such variables into partial
8630 symbol table then. */
8632 else if (pdi
->is_external
)
8635 Don't enter into the minimal symbol tables as there is
8636 a minimal symbol table entry from the ELF symbols already.
8637 Enter into partial symbol table if it has a location
8638 descriptor or a type.
8639 If the location descriptor is missing, new_symbol will create
8640 a LOC_UNRESOLVED symbol, the address of the variable will then
8641 be determined from the minimal symbol table whenever the variable
8643 The address for the partial symbol table entry is not
8644 used by GDB, but it comes in handy for debugging partial symbol
8647 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8649 psymbol
.domain
= VAR_DOMAIN
;
8650 psymbol
.aclass
= LOC_STATIC
;
8651 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8652 psymbol
.ginfo
.value
.address
= addr
;
8653 where
= psymbol_placement::GLOBAL
;
8658 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8660 /* Static Variable. Skip symbols whose value we cannot know (those
8661 without location descriptors or constant values). */
8662 if (!has_loc
&& !pdi
->has_const_value
)
8665 psymbol
.domain
= VAR_DOMAIN
;
8666 psymbol
.aclass
= LOC_STATIC
;
8667 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8669 psymbol
.ginfo
.value
.address
= addr
;
8670 where
= psymbol_placement::STATIC
;
8673 case DW_TAG_array_type
:
8674 case DW_TAG_typedef
:
8675 case DW_TAG_base_type
:
8676 case DW_TAG_subrange_type
:
8677 psymbol
.domain
= VAR_DOMAIN
;
8678 psymbol
.aclass
= LOC_TYPEDEF
;
8679 where
= psymbol_placement::STATIC
;
8681 case DW_TAG_imported_declaration
:
8682 case DW_TAG_namespace
:
8683 psymbol
.domain
= VAR_DOMAIN
;
8684 psymbol
.aclass
= LOC_TYPEDEF
;
8685 where
= psymbol_placement::GLOBAL
;
8688 /* With Fortran 77 there might be a "BLOCK DATA" module
8689 available without any name. If so, we skip the module as it
8690 doesn't bring any value. */
8691 if (actual_name
!= nullptr)
8693 psymbol
.domain
= MODULE_DOMAIN
;
8694 psymbol
.aclass
= LOC_TYPEDEF
;
8695 where
= psymbol_placement::GLOBAL
;
8698 case DW_TAG_class_type
:
8699 case DW_TAG_interface_type
:
8700 case DW_TAG_structure_type
:
8701 case DW_TAG_union_type
:
8702 case DW_TAG_enumeration_type
:
8703 /* Skip external references. The DWARF standard says in the section
8704 about "Structure, Union, and Class Type Entries": "An incomplete
8705 structure, union or class type is represented by a structure,
8706 union or class entry that does not have a byte size attribute
8707 and that has a DW_AT_declaration attribute." */
8708 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8711 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8712 static vs. global. */
8713 psymbol
.domain
= STRUCT_DOMAIN
;
8714 psymbol
.aclass
= LOC_TYPEDEF
;
8715 where
= (cu
->language
== language_cplus
8716 ? psymbol_placement::GLOBAL
8717 : psymbol_placement::STATIC
);
8719 case DW_TAG_enumerator
:
8720 psymbol
.domain
= VAR_DOMAIN
;
8721 psymbol
.aclass
= LOC_CONST
;
8722 where
= (cu
->language
== language_cplus
8723 ? psymbol_placement::GLOBAL
8724 : psymbol_placement::STATIC
);
8730 if (where
.has_value ())
8732 if (built_actual_name
!= nullptr)
8733 actual_name
= objfile
->intern (actual_name
);
8734 if (pdi
->linkage_name
== nullptr || cu
->language
== language_ada
)
8735 psymbol
.ginfo
.set_linkage_name (actual_name
);
8738 psymbol
.ginfo
.set_demangled_name (actual_name
,
8739 &objfile
->objfile_obstack
);
8740 psymbol
.ginfo
.set_linkage_name (pdi
->linkage_name
);
8742 cu
->per_cu
->v
.psymtab
->add_psymbol (psymbol
, *where
, objfile
);
8746 /* Read a partial die corresponding to a namespace; also, add a symbol
8747 corresponding to that namespace to the symbol table. NAMESPACE is
8748 the name of the enclosing namespace. */
8751 add_partial_namespace (struct partial_die_info
*pdi
,
8752 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8753 int set_addrmap
, struct dwarf2_cu
*cu
)
8755 /* Add a symbol for the namespace. */
8757 add_partial_symbol (pdi
, cu
);
8759 /* Now scan partial symbols in that namespace. */
8761 if (pdi
->has_children
)
8762 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8765 /* Read a partial die corresponding to a Fortran module. */
8768 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8769 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8771 /* Add a symbol for the namespace. */
8773 add_partial_symbol (pdi
, cu
);
8775 /* Now scan partial symbols in that module. */
8777 if (pdi
->has_children
)
8778 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8781 /* Read a partial die corresponding to a subprogram or an inlined
8782 subprogram and create a partial symbol for that subprogram.
8783 When the CU language allows it, this routine also defines a partial
8784 symbol for each nested subprogram that this subprogram contains.
8785 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8786 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8788 PDI may also be a lexical block, in which case we simply search
8789 recursively for subprograms defined inside that lexical block.
8790 Again, this is only performed when the CU language allows this
8791 type of definitions. */
8794 add_partial_subprogram (struct partial_die_info
*pdi
,
8795 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8796 int set_addrmap
, struct dwarf2_cu
*cu
)
8798 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8800 if (pdi
->has_pc_info
)
8802 if (pdi
->lowpc
< *lowpc
)
8803 *lowpc
= pdi
->lowpc
;
8804 if (pdi
->highpc
> *highpc
)
8805 *highpc
= pdi
->highpc
;
8808 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8809 struct gdbarch
*gdbarch
= objfile
->arch ();
8811 CORE_ADDR this_highpc
;
8812 CORE_ADDR this_lowpc
;
8814 baseaddr
= objfile
->text_section_offset ();
8816 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8817 pdi
->lowpc
+ baseaddr
)
8820 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8821 pdi
->highpc
+ baseaddr
)
8823 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8824 this_lowpc
, this_highpc
- 1,
8825 cu
->per_cu
->v
.psymtab
);
8829 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8831 if (!pdi
->is_declaration
)
8832 /* Ignore subprogram DIEs that do not have a name, they are
8833 illegal. Do not emit a complaint at this point, we will
8834 do so when we convert this psymtab into a symtab. */
8836 add_partial_symbol (pdi
, cu
);
8840 if (! pdi
->has_children
)
8843 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
8845 pdi
= pdi
->die_child
;
8849 if (pdi
->tag
== DW_TAG_subprogram
8850 || pdi
->tag
== DW_TAG_inlined_subroutine
8851 || pdi
->tag
== DW_TAG_lexical_block
)
8852 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8853 pdi
= pdi
->die_sibling
;
8858 /* Read a partial die corresponding to an enumeration type. */
8861 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8862 struct dwarf2_cu
*cu
)
8864 struct partial_die_info
*pdi
;
8866 if (enum_pdi
->name (cu
) != NULL
)
8867 add_partial_symbol (enum_pdi
, cu
);
8869 pdi
= enum_pdi
->die_child
;
8872 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->raw_name
== NULL
)
8873 complaint (_("malformed enumerator DIE ignored"));
8875 add_partial_symbol (pdi
, cu
);
8876 pdi
= pdi
->die_sibling
;
8880 /* Return the initial uleb128 in the die at INFO_PTR. */
8883 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8885 unsigned int bytes_read
;
8887 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8890 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8891 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8893 Return the corresponding abbrev, or NULL if the number is zero (indicating
8894 an empty DIE). In either case *BYTES_READ will be set to the length of
8895 the initial number. */
8897 static struct abbrev_info
*
8898 peek_die_abbrev (const die_reader_specs
&reader
,
8899 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8901 dwarf2_cu
*cu
= reader
.cu
;
8902 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
8903 unsigned int abbrev_number
8904 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8906 if (abbrev_number
== 0)
8909 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8912 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8913 " at offset %s [in module %s]"),
8914 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8915 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8921 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8922 Returns a pointer to the end of a series of DIEs, terminated by an empty
8923 DIE. Any children of the skipped DIEs will also be skipped. */
8925 static const gdb_byte
*
8926 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8930 unsigned int bytes_read
;
8931 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
8934 return info_ptr
+ bytes_read
;
8936 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8940 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8941 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8942 abbrev corresponding to that skipped uleb128 should be passed in
8943 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8946 static const gdb_byte
*
8947 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8948 struct abbrev_info
*abbrev
)
8950 unsigned int bytes_read
;
8951 struct attribute attr
;
8952 bfd
*abfd
= reader
->abfd
;
8953 struct dwarf2_cu
*cu
= reader
->cu
;
8954 const gdb_byte
*buffer
= reader
->buffer
;
8955 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8956 unsigned int form
, i
;
8958 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8960 /* The only abbrev we care about is DW_AT_sibling. */
8961 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8963 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
8964 if (attr
.form
== DW_FORM_ref_addr
)
8965 complaint (_("ignoring absolute DW_AT_sibling"));
8968 sect_offset off
= attr
.get_ref_die_offset ();
8969 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8971 if (sibling_ptr
< info_ptr
)
8972 complaint (_("DW_AT_sibling points backwards"));
8973 else if (sibling_ptr
> reader
->buffer_end
)
8974 reader
->die_section
->overflow_complaint ();
8980 /* If it isn't DW_AT_sibling, skip this attribute. */
8981 form
= abbrev
->attrs
[i
].form
;
8985 case DW_FORM_ref_addr
:
8986 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8987 and later it is offset sized. */
8988 if (cu
->header
.version
== 2)
8989 info_ptr
+= cu
->header
.addr_size
;
8991 info_ptr
+= cu
->header
.offset_size
;
8993 case DW_FORM_GNU_ref_alt
:
8994 info_ptr
+= cu
->header
.offset_size
;
8997 info_ptr
+= cu
->header
.addr_size
;
9005 case DW_FORM_flag_present
:
9006 case DW_FORM_implicit_const
:
9023 case DW_FORM_ref_sig8
:
9026 case DW_FORM_data16
:
9029 case DW_FORM_string
:
9030 read_direct_string (abfd
, info_ptr
, &bytes_read
);
9031 info_ptr
+= bytes_read
;
9033 case DW_FORM_sec_offset
:
9035 case DW_FORM_GNU_strp_alt
:
9036 info_ptr
+= cu
->header
.offset_size
;
9038 case DW_FORM_exprloc
:
9040 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9041 info_ptr
+= bytes_read
;
9043 case DW_FORM_block1
:
9044 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
9046 case DW_FORM_block2
:
9047 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
9049 case DW_FORM_block4
:
9050 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
9056 case DW_FORM_ref_udata
:
9057 case DW_FORM_GNU_addr_index
:
9058 case DW_FORM_GNU_str_index
:
9059 case DW_FORM_rnglistx
:
9060 case DW_FORM_loclistx
:
9061 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
9063 case DW_FORM_indirect
:
9064 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9065 info_ptr
+= bytes_read
;
9066 /* We need to continue parsing from here, so just go back to
9068 goto skip_attribute
;
9071 error (_("Dwarf Error: Cannot handle %s "
9072 "in DWARF reader [in module %s]"),
9073 dwarf_form_name (form
),
9074 bfd_get_filename (abfd
));
9078 if (abbrev
->has_children
)
9079 return skip_children (reader
, info_ptr
);
9084 /* Locate ORIG_PDI's sibling.
9085 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
9087 static const gdb_byte
*
9088 locate_pdi_sibling (const struct die_reader_specs
*reader
,
9089 struct partial_die_info
*orig_pdi
,
9090 const gdb_byte
*info_ptr
)
9092 /* Do we know the sibling already? */
9094 if (orig_pdi
->sibling
)
9095 return orig_pdi
->sibling
;
9097 /* Are there any children to deal with? */
9099 if (!orig_pdi
->has_children
)
9102 /* Skip the children the long way. */
9104 return skip_children (reader
, info_ptr
);
9107 /* Expand this partial symbol table into a full symbol table. SELF is
9111 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
9113 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9115 gdb_assert (!per_objfile
->symtab_set_p (per_cu_data
));
9117 /* If this psymtab is constructed from a debug-only objfile, the
9118 has_section_at_zero flag will not necessarily be correct. We
9119 can get the correct value for this flag by looking at the data
9120 associated with the (presumably stripped) associated objfile. */
9121 if (objfile
->separate_debug_objfile_backlink
)
9123 dwarf2_per_objfile
*per_objfile_backlink
9124 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
9126 per_objfile
->per_bfd
->has_section_at_zero
9127 = per_objfile_backlink
->per_bfd
->has_section_at_zero
;
9130 expand_psymtab (objfile
);
9132 process_cu_includes (per_objfile
);
9135 /* Reading in full CUs. */
9137 /* Add PER_CU to the queue. */
9140 queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
9141 dwarf2_per_objfile
*per_objfile
,
9142 enum language pretend_language
)
9145 per_cu
->per_bfd
->queue
.emplace (per_cu
, per_objfile
, pretend_language
);
9148 /* If PER_CU is not yet queued, add it to the queue.
9149 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
9151 The result is non-zero if PER_CU was queued, otherwise the result is zero
9152 meaning either PER_CU is already queued or it is already loaded.
9154 N.B. There is an invariant here that if a CU is queued then it is loaded.
9155 The caller is required to load PER_CU if we return non-zero. */
9158 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
9159 dwarf2_per_cu_data
*per_cu
,
9160 dwarf2_per_objfile
*per_objfile
,
9161 enum language pretend_language
)
9163 /* We may arrive here during partial symbol reading, if we need full
9164 DIEs to process an unusual case (e.g. template arguments). Do
9165 not queue PER_CU, just tell our caller to load its DIEs. */
9166 if (per_cu
->per_bfd
->reading_partial_symbols
)
9168 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
9170 if (cu
== NULL
|| cu
->dies
== NULL
)
9175 /* Mark the dependence relation so that we don't flush PER_CU
9177 if (dependent_cu
!= NULL
)
9178 dwarf2_add_dependence (dependent_cu
, per_cu
);
9180 /* If it's already on the queue, we have nothing to do. */
9184 /* If the compilation unit is already loaded, just mark it as
9186 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
9193 /* Add it to the queue. */
9194 queue_comp_unit (per_cu
, per_objfile
, pretend_language
);
9199 /* Process the queue. */
9202 process_queue (dwarf2_per_objfile
*per_objfile
)
9204 dwarf_read_debug_printf ("Expanding one or more symtabs of objfile %s ...",
9205 objfile_name (per_objfile
->objfile
));
9207 /* The queue starts out with one item, but following a DIE reference
9208 may load a new CU, adding it to the end of the queue. */
9209 while (!per_objfile
->per_bfd
->queue
.empty ())
9211 dwarf2_queue_item
&item
= per_objfile
->per_bfd
->queue
.front ();
9212 dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
9214 if (!per_objfile
->symtab_set_p (per_cu
))
9216 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
9218 /* Skip dummy CUs. */
9221 unsigned int debug_print_threshold
;
9224 if (per_cu
->is_debug_types
)
9226 struct signatured_type
*sig_type
=
9227 (struct signatured_type
*) per_cu
;
9229 sprintf (buf
, "TU %s at offset %s",
9230 hex_string (sig_type
->signature
),
9231 sect_offset_str (per_cu
->sect_off
));
9232 /* There can be 100s of TUs.
9233 Only print them in verbose mode. */
9234 debug_print_threshold
= 2;
9238 sprintf (buf
, "CU at offset %s",
9239 sect_offset_str (per_cu
->sect_off
));
9240 debug_print_threshold
= 1;
9243 if (dwarf_read_debug
>= debug_print_threshold
)
9244 dwarf_read_debug_printf ("Expanding symtab of %s", buf
);
9246 if (per_cu
->is_debug_types
)
9247 process_full_type_unit (cu
, item
.pretend_language
);
9249 process_full_comp_unit (cu
, item
.pretend_language
);
9251 if (dwarf_read_debug
>= debug_print_threshold
)
9252 dwarf_read_debug_printf ("Done expanding %s", buf
);
9257 per_objfile
->per_bfd
->queue
.pop ();
9260 dwarf_read_debug_printf ("Done expanding symtabs of %s.",
9261 objfile_name (per_objfile
->objfile
));
9264 /* Read in full symbols for PST, and anything it depends on. */
9267 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
9269 gdb_assert (!readin_p (objfile
));
9271 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9272 free_cached_comp_units
freer (per_objfile
);
9273 expand_dependencies (objfile
);
9275 dw2_do_instantiate_symtab (per_cu_data
, per_objfile
, false);
9276 gdb_assert (get_compunit_symtab (objfile
) != nullptr);
9279 /* See psympriv.h. */
9282 dwarf2_psymtab::readin_p (struct objfile
*objfile
) const
9284 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9285 return per_objfile
->symtab_set_p (per_cu_data
);
9288 /* See psympriv.h. */
9291 dwarf2_psymtab::get_compunit_symtab (struct objfile
*objfile
) const
9293 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9294 return per_objfile
->get_symtab (per_cu_data
);
9297 /* Trivial hash function for die_info: the hash value of a DIE
9298 is its offset in .debug_info for this objfile. */
9301 die_hash (const void *item
)
9303 const struct die_info
*die
= (const struct die_info
*) item
;
9305 return to_underlying (die
->sect_off
);
9308 /* Trivial comparison function for die_info structures: two DIEs
9309 are equal if they have the same offset. */
9312 die_eq (const void *item_lhs
, const void *item_rhs
)
9314 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
9315 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
9317 return die_lhs
->sect_off
== die_rhs
->sect_off
;
9320 /* Load the DIEs associated with PER_CU into memory.
9322 In some cases, the caller, while reading partial symbols, will need to load
9323 the full symbols for the CU for some reason. It will already have a
9324 dwarf2_cu object for THIS_CU and pass it as EXISTING_CU, so it can be re-used
9325 rather than creating a new one. */
9328 load_full_comp_unit (dwarf2_per_cu_data
*this_cu
,
9329 dwarf2_per_objfile
*per_objfile
,
9330 dwarf2_cu
*existing_cu
,
9332 enum language pretend_language
)
9334 gdb_assert (! this_cu
->is_debug_types
);
9336 cutu_reader
reader (this_cu
, per_objfile
, NULL
, existing_cu
, skip_partial
);
9340 struct dwarf2_cu
*cu
= reader
.cu
;
9341 const gdb_byte
*info_ptr
= reader
.info_ptr
;
9343 gdb_assert (cu
->die_hash
== NULL
);
9345 htab_create_alloc_ex (cu
->header
.length
/ 12,
9349 &cu
->comp_unit_obstack
,
9350 hashtab_obstack_allocate
,
9351 dummy_obstack_deallocate
);
9353 if (reader
.comp_unit_die
->has_children
)
9354 reader
.comp_unit_die
->child
9355 = read_die_and_siblings (&reader
, reader
.info_ptr
,
9356 &info_ptr
, reader
.comp_unit_die
);
9357 cu
->dies
= reader
.comp_unit_die
;
9358 /* comp_unit_die is not stored in die_hash, no need. */
9360 /* We try not to read any attributes in this function, because not
9361 all CUs needed for references have been loaded yet, and symbol
9362 table processing isn't initialized. But we have to set the CU language,
9363 or we won't be able to build types correctly.
9364 Similarly, if we do not read the producer, we can not apply
9365 producer-specific interpretation. */
9366 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
9371 /* Add a DIE to the delayed physname list. */
9374 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
9375 const char *name
, struct die_info
*die
,
9376 struct dwarf2_cu
*cu
)
9378 struct delayed_method_info mi
;
9380 mi
.fnfield_index
= fnfield_index
;
9384 cu
->method_list
.push_back (mi
);
9387 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
9388 "const" / "volatile". If so, decrements LEN by the length of the
9389 modifier and return true. Otherwise return false. */
9393 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
9395 size_t mod_len
= sizeof (mod
) - 1;
9396 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
9404 /* Compute the physnames of any methods on the CU's method list.
9406 The computation of method physnames is delayed in order to avoid the
9407 (bad) condition that one of the method's formal parameters is of an as yet
9411 compute_delayed_physnames (struct dwarf2_cu
*cu
)
9413 /* Only C++ delays computing physnames. */
9414 if (cu
->method_list
.empty ())
9416 gdb_assert (cu
->language
== language_cplus
);
9418 for (const delayed_method_info
&mi
: cu
->method_list
)
9420 const char *physname
;
9421 struct fn_fieldlist
*fn_flp
9422 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9423 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9424 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9425 = physname
? physname
: "";
9427 /* Since there's no tag to indicate whether a method is a
9428 const/volatile overload, extract that information out of the
9430 if (physname
!= NULL
)
9432 size_t len
= strlen (physname
);
9436 if (physname
[len
] == ')') /* shortcut */
9438 else if (check_modifier (physname
, len
, " const"))
9439 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9440 else if (check_modifier (physname
, len
, " volatile"))
9441 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9448 /* The list is no longer needed. */
9449 cu
->method_list
.clear ();
9452 /* Go objects should be embedded in a DW_TAG_module DIE,
9453 and it's not clear if/how imported objects will appear.
9454 To keep Go support simple until that's worked out,
9455 go back through what we've read and create something usable.
9456 We could do this while processing each DIE, and feels kinda cleaner,
9457 but that way is more invasive.
9458 This is to, for example, allow the user to type "p var" or "b main"
9459 without having to specify the package name, and allow lookups
9460 of module.object to work in contexts that use the expression
9464 fixup_go_packaging (struct dwarf2_cu
*cu
)
9466 gdb::unique_xmalloc_ptr
<char> package_name
;
9467 struct pending
*list
;
9470 for (list
= *cu
->get_builder ()->get_global_symbols ();
9474 for (i
= 0; i
< list
->nsyms
; ++i
)
9476 struct symbol
*sym
= list
->symbol
[i
];
9478 if (sym
->language () == language_go
9479 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9481 gdb::unique_xmalloc_ptr
<char> this_package_name
9482 (go_symbol_package_name (sym
));
9484 if (this_package_name
== NULL
)
9486 if (package_name
== NULL
)
9487 package_name
= std::move (this_package_name
);
9490 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9491 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9492 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9493 (symbol_symtab (sym
) != NULL
9494 ? symtab_to_filename_for_display
9495 (symbol_symtab (sym
))
9496 : objfile_name (objfile
)),
9497 this_package_name
.get (), package_name
.get ());
9503 if (package_name
!= NULL
)
9505 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9506 const char *saved_package_name
= objfile
->intern (package_name
.get ());
9507 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9508 saved_package_name
);
9511 sym
= new (&objfile
->objfile_obstack
) symbol
;
9512 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9513 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9514 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9515 e.g., "main" finds the "main" module and not C's main(). */
9516 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9517 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9518 SYMBOL_TYPE (sym
) = type
;
9520 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9524 /* Allocate a fully-qualified name consisting of the two parts on the
9528 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9530 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9533 /* A helper that allocates a variant part to attach to a Rust enum
9534 type. OBSTACK is where the results should be allocated. TYPE is
9535 the type we're processing. DISCRIMINANT_INDEX is the index of the
9536 discriminant. It must be the index of one of the fields of TYPE,
9537 or -1 to mean there is no discriminant (univariant enum).
9538 DEFAULT_INDEX is the index of the default field; or -1 if there is
9539 no default. RANGES is indexed by "effective" field number (the
9540 field index, but omitting the discriminant and default fields) and
9541 must hold the discriminant values used by the variants. Note that
9542 RANGES must have a lifetime at least as long as OBSTACK -- either
9543 already allocated on it, or static. */
9546 alloc_rust_variant (struct obstack
*obstack
, struct type
*type
,
9547 int discriminant_index
, int default_index
,
9548 gdb::array_view
<discriminant_range
> ranges
)
9550 /* When DISCRIMINANT_INDEX == -1, we have a univariant enum. */
9551 gdb_assert (discriminant_index
== -1
9552 || (discriminant_index
>= 0
9553 && discriminant_index
< type
->num_fields ()));
9554 gdb_assert (default_index
== -1
9555 || (default_index
>= 0 && default_index
< type
->num_fields ()));
9557 /* We have one variant for each non-discriminant field. */
9558 int n_variants
= type
->num_fields ();
9559 if (discriminant_index
!= -1)
9562 variant
*variants
= new (obstack
) variant
[n_variants
];
9565 for (int i
= 0; i
< type
->num_fields (); ++i
)
9567 if (i
== discriminant_index
)
9570 variants
[var_idx
].first_field
= i
;
9571 variants
[var_idx
].last_field
= i
+ 1;
9573 /* The default field does not need a range, but other fields do.
9574 We skipped the discriminant above. */
9575 if (i
!= default_index
)
9577 variants
[var_idx
].discriminants
= ranges
.slice (range_idx
, 1);
9584 gdb_assert (range_idx
== ranges
.size ());
9585 gdb_assert (var_idx
== n_variants
);
9587 variant_part
*part
= new (obstack
) variant_part
;
9588 part
->discriminant_index
= discriminant_index
;
9589 /* If there is no discriminant, then whether it is signed is of no
9592 = (discriminant_index
== -1
9594 : type
->field (discriminant_index
).type ()->is_unsigned ());
9595 part
->variants
= gdb::array_view
<variant
> (variants
, n_variants
);
9597 void *storage
= obstack_alloc (obstack
, sizeof (gdb::array_view
<variant_part
>));
9598 gdb::array_view
<variant_part
> *prop_value
9599 = new (storage
) gdb::array_view
<variant_part
> (part
, 1);
9601 struct dynamic_prop prop
;
9602 prop
.set_variant_parts (prop_value
);
9604 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
9607 /* Some versions of rustc emitted enums in an unusual way.
9609 Ordinary enums were emitted as unions. The first element of each
9610 structure in the union was named "RUST$ENUM$DISR". This element
9611 held the discriminant.
9613 These versions of Rust also implemented the "non-zero"
9614 optimization. When the enum had two values, and one is empty and
9615 the other holds a pointer that cannot be zero, the pointer is used
9616 as the discriminant, with a zero value meaning the empty variant.
9617 Here, the union's first member is of the form
9618 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9619 where the fieldnos are the indices of the fields that should be
9620 traversed in order to find the field (which may be several fields deep)
9621 and the variantname is the name of the variant of the case when the
9624 This function recognizes whether TYPE is of one of these forms,
9625 and, if so, smashes it to be a variant type. */
9628 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9630 gdb_assert (type
->code () == TYPE_CODE_UNION
);
9632 /* We don't need to deal with empty enums. */
9633 if (type
->num_fields () == 0)
9636 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9637 if (type
->num_fields () == 1
9638 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9640 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9642 /* Decode the field name to find the offset of the
9644 ULONGEST bit_offset
= 0;
9645 struct type
*field_type
= type
->field (0).type ();
9646 while (name
[0] >= '0' && name
[0] <= '9')
9649 unsigned long index
= strtoul (name
, &tail
, 10);
9652 || index
>= field_type
->num_fields ()
9653 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9654 != FIELD_LOC_KIND_BITPOS
))
9656 complaint (_("Could not parse Rust enum encoding string \"%s\""
9658 TYPE_FIELD_NAME (type
, 0),
9659 objfile_name (objfile
));
9664 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9665 field_type
= field_type
->field (index
).type ();
9668 /* Smash this type to be a structure type. We have to do this
9669 because the type has already been recorded. */
9670 type
->set_code (TYPE_CODE_STRUCT
);
9671 type
->set_num_fields (3);
9672 /* Save the field we care about. */
9673 struct field saved_field
= type
->field (0);
9675 ((struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
)));
9677 /* Put the discriminant at index 0. */
9678 type
->field (0).set_type (field_type
);
9679 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9680 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9681 SET_FIELD_BITPOS (type
->field (0), bit_offset
);
9683 /* The order of fields doesn't really matter, so put the real
9684 field at index 1 and the data-less field at index 2. */
9685 type
->field (1) = saved_field
;
9686 TYPE_FIELD_NAME (type
, 1)
9687 = rust_last_path_segment (type
->field (1).type ()->name ());
9688 type
->field (1).type ()->set_name
9689 (rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9690 TYPE_FIELD_NAME (type
, 1)));
9692 const char *dataless_name
9693 = rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9695 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9697 type
->field (2).set_type (dataless_type
);
9698 /* NAME points into the original discriminant name, which
9699 already has the correct lifetime. */
9700 TYPE_FIELD_NAME (type
, 2) = name
;
9701 SET_FIELD_BITPOS (type
->field (2), 0);
9703 /* Indicate that this is a variant type. */
9704 static discriminant_range ranges
[1] = { { 0, 0 } };
9705 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1, ranges
);
9707 /* A union with a single anonymous field is probably an old-style
9709 else if (type
->num_fields () == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
9711 /* Smash this type to be a structure type. We have to do this
9712 because the type has already been recorded. */
9713 type
->set_code (TYPE_CODE_STRUCT
);
9715 struct type
*field_type
= type
->field (0).type ();
9716 const char *variant_name
9717 = rust_last_path_segment (field_type
->name ());
9718 TYPE_FIELD_NAME (type
, 0) = variant_name
;
9719 field_type
->set_name
9720 (rust_fully_qualify (&objfile
->objfile_obstack
,
9721 type
->name (), variant_name
));
9723 alloc_rust_variant (&objfile
->objfile_obstack
, type
, -1, 0, {});
9727 struct type
*disr_type
= nullptr;
9728 for (int i
= 0; i
< type
->num_fields (); ++i
)
9730 disr_type
= type
->field (i
).type ();
9732 if (disr_type
->code () != TYPE_CODE_STRUCT
)
9734 /* All fields of a true enum will be structs. */
9737 else if (disr_type
->num_fields () == 0)
9739 /* Could be data-less variant, so keep going. */
9740 disr_type
= nullptr;
9742 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9743 "RUST$ENUM$DISR") != 0)
9745 /* Not a Rust enum. */
9755 /* If we got here without a discriminant, then it's probably
9757 if (disr_type
== nullptr)
9760 /* Smash this type to be a structure type. We have to do this
9761 because the type has already been recorded. */
9762 type
->set_code (TYPE_CODE_STRUCT
);
9764 /* Make space for the discriminant field. */
9765 struct field
*disr_field
= &disr_type
->field (0);
9767 = (struct field
*) TYPE_ZALLOC (type
, ((type
->num_fields () + 1)
9768 * sizeof (struct field
)));
9769 memcpy (new_fields
+ 1, type
->fields (),
9770 type
->num_fields () * sizeof (struct field
));
9771 type
->set_fields (new_fields
);
9772 type
->set_num_fields (type
->num_fields () + 1);
9774 /* Install the discriminant at index 0 in the union. */
9775 type
->field (0) = *disr_field
;
9776 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9777 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9779 /* We need a way to find the correct discriminant given a
9780 variant name. For convenience we build a map here. */
9781 struct type
*enum_type
= disr_field
->type ();
9782 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9783 for (int i
= 0; i
< enum_type
->num_fields (); ++i
)
9785 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9788 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9789 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9793 int n_fields
= type
->num_fields ();
9794 /* We don't need a range entry for the discriminant, but we do
9795 need one for every other field, as there is no default
9797 discriminant_range
*ranges
= XOBNEWVEC (&objfile
->objfile_obstack
,
9800 /* Skip the discriminant here. */
9801 for (int i
= 1; i
< n_fields
; ++i
)
9803 /* Find the final word in the name of this variant's type.
9804 That name can be used to look up the correct
9806 const char *variant_name
9807 = rust_last_path_segment (type
->field (i
).type ()->name ());
9809 auto iter
= discriminant_map
.find (variant_name
);
9810 if (iter
!= discriminant_map
.end ())
9812 ranges
[i
- 1].low
= iter
->second
;
9813 ranges
[i
- 1].high
= iter
->second
;
9816 /* In Rust, each element should have the size of the
9818 TYPE_LENGTH (type
->field (i
).type ()) = TYPE_LENGTH (type
);
9820 /* Remove the discriminant field, if it exists. */
9821 struct type
*sub_type
= type
->field (i
).type ();
9822 if (sub_type
->num_fields () > 0)
9824 sub_type
->set_num_fields (sub_type
->num_fields () - 1);
9825 sub_type
->set_fields (sub_type
->fields () + 1);
9827 TYPE_FIELD_NAME (type
, i
) = variant_name
;
9829 (rust_fully_qualify (&objfile
->objfile_obstack
,
9830 type
->name (), variant_name
));
9833 /* Indicate that this is a variant type. */
9834 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, -1,
9835 gdb::array_view
<discriminant_range
> (ranges
,
9840 /* Rewrite some Rust unions to be structures with variants parts. */
9843 rust_union_quirks (struct dwarf2_cu
*cu
)
9845 gdb_assert (cu
->language
== language_rust
);
9846 for (type
*type_
: cu
->rust_unions
)
9847 quirk_rust_enum (type_
, cu
->per_objfile
->objfile
);
9848 /* We don't need this any more. */
9849 cu
->rust_unions
.clear ();
9854 type_unit_group_unshareable
*
9855 dwarf2_per_objfile::get_type_unit_group_unshareable (type_unit_group
*tu_group
)
9857 auto iter
= this->m_type_units
.find (tu_group
);
9858 if (iter
!= this->m_type_units
.end ())
9859 return iter
->second
.get ();
9861 type_unit_group_unshareable_up
uniq (new type_unit_group_unshareable
);
9862 type_unit_group_unshareable
*result
= uniq
.get ();
9863 this->m_type_units
[tu_group
] = std::move (uniq
);
9868 dwarf2_per_objfile::get_type_for_signatured_type
9869 (signatured_type
*sig_type
) const
9871 auto iter
= this->m_type_map
.find (sig_type
);
9872 if (iter
== this->m_type_map
.end ())
9875 return iter
->second
;
9878 void dwarf2_per_objfile::set_type_for_signatured_type
9879 (signatured_type
*sig_type
, struct type
*type
)
9881 gdb_assert (this->m_type_map
.find (sig_type
) == this->m_type_map
.end ());
9883 this->m_type_map
[sig_type
] = type
;
9886 /* A helper function for computing the list of all symbol tables
9887 included by PER_CU. */
9890 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9891 htab_t all_children
, htab_t all_type_symtabs
,
9892 dwarf2_per_cu_data
*per_cu
,
9893 dwarf2_per_objfile
*per_objfile
,
9894 struct compunit_symtab
*immediate_parent
)
9896 void **slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9899 /* This inclusion and its children have been processed. */
9905 /* Only add a CU if it has a symbol table. */
9906 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9909 /* If this is a type unit only add its symbol table if we haven't
9910 seen it yet (type unit per_cu's can share symtabs). */
9911 if (per_cu
->is_debug_types
)
9913 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9917 result
->push_back (cust
);
9918 if (cust
->user
== NULL
)
9919 cust
->user
= immediate_parent
;
9924 result
->push_back (cust
);
9925 if (cust
->user
== NULL
)
9926 cust
->user
= immediate_parent
;
9930 if (!per_cu
->imported_symtabs_empty ())
9931 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9933 recursively_compute_inclusions (result
, all_children
,
9934 all_type_symtabs
, ptr
, per_objfile
,
9939 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9943 compute_compunit_symtab_includes (dwarf2_per_cu_data
*per_cu
,
9944 dwarf2_per_objfile
*per_objfile
)
9946 gdb_assert (! per_cu
->is_debug_types
);
9948 if (!per_cu
->imported_symtabs_empty ())
9951 std::vector
<compunit_symtab
*> result_symtabs
;
9952 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9954 /* If we don't have a symtab, we can just skip this case. */
9958 htab_up
all_children (htab_create_alloc (1, htab_hash_pointer
,
9960 NULL
, xcalloc
, xfree
));
9961 htab_up
all_type_symtabs (htab_create_alloc (1, htab_hash_pointer
,
9963 NULL
, xcalloc
, xfree
));
9965 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9967 recursively_compute_inclusions (&result_symtabs
, all_children
.get (),
9968 all_type_symtabs
.get (), ptr
,
9972 /* Now we have a transitive closure of all the included symtabs. */
9973 len
= result_symtabs
.size ();
9975 = XOBNEWVEC (&per_objfile
->objfile
->objfile_obstack
,
9976 struct compunit_symtab
*, len
+ 1);
9977 memcpy (cust
->includes
, result_symtabs
.data (),
9978 len
* sizeof (compunit_symtab
*));
9979 cust
->includes
[len
] = NULL
;
9983 /* Compute the 'includes' field for the symtabs of all the CUs we just
9987 process_cu_includes (dwarf2_per_objfile
*per_objfile
)
9989 for (dwarf2_per_cu_data
*iter
: per_objfile
->per_bfd
->just_read_cus
)
9991 if (! iter
->is_debug_types
)
9992 compute_compunit_symtab_includes (iter
, per_objfile
);
9995 per_objfile
->per_bfd
->just_read_cus
.clear ();
9998 /* Generate full symbol information for CU, whose DIEs have
9999 already been loaded into memory. */
10002 process_full_comp_unit (dwarf2_cu
*cu
, enum language pretend_language
)
10004 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10005 struct objfile
*objfile
= per_objfile
->objfile
;
10006 struct gdbarch
*gdbarch
= objfile
->arch ();
10007 CORE_ADDR lowpc
, highpc
;
10008 struct compunit_symtab
*cust
;
10009 CORE_ADDR baseaddr
;
10010 struct block
*static_block
;
10013 baseaddr
= objfile
->text_section_offset ();
10015 /* Clear the list here in case something was left over. */
10016 cu
->method_list
.clear ();
10018 cu
->language
= pretend_language
;
10019 cu
->language_defn
= language_def (cu
->language
);
10021 dwarf2_find_base_address (cu
->dies
, cu
);
10023 /* Do line number decoding in read_file_scope () */
10024 process_die (cu
->dies
, cu
);
10026 /* For now fudge the Go package. */
10027 if (cu
->language
== language_go
)
10028 fixup_go_packaging (cu
);
10030 /* Now that we have processed all the DIEs in the CU, all the types
10031 should be complete, and it should now be safe to compute all of the
10033 compute_delayed_physnames (cu
);
10035 if (cu
->language
== language_rust
)
10036 rust_union_quirks (cu
);
10038 /* Some compilers don't define a DW_AT_high_pc attribute for the
10039 compilation unit. If the DW_AT_high_pc is missing, synthesize
10040 it, by scanning the DIE's below the compilation unit. */
10041 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
10043 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
10044 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
10046 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
10047 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
10048 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
10049 addrmap to help ensure it has an accurate map of pc values belonging to
10051 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
10053 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
10054 SECT_OFF_TEXT (objfile
),
10059 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
10061 /* Set symtab language to language from DW_AT_language. If the
10062 compilation is from a C file generated by language preprocessors, do
10063 not set the language if it was already deduced by start_subfile. */
10064 if (!(cu
->language
== language_c
10065 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
10066 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10068 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
10069 produce DW_AT_location with location lists but it can be possibly
10070 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
10071 there were bugs in prologue debug info, fixed later in GCC-4.5
10072 by "unwind info for epilogues" patch (which is not directly related).
10074 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
10075 needed, it would be wrong due to missing DW_AT_producer there.
10077 Still one can confuse GDB by using non-standard GCC compilation
10078 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
10080 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
10081 cust
->locations_valid
= 1;
10083 if (gcc_4_minor
>= 5)
10084 cust
->epilogue_unwind_valid
= 1;
10086 cust
->call_site_htab
= cu
->call_site_htab
;
10089 per_objfile
->set_symtab (cu
->per_cu
, cust
);
10091 /* Push it for inclusion processing later. */
10092 per_objfile
->per_bfd
->just_read_cus
.push_back (cu
->per_cu
);
10094 /* Not needed any more. */
10095 cu
->reset_builder ();
10098 /* Generate full symbol information for type unit CU, whose DIEs have
10099 already been loaded into memory. */
10102 process_full_type_unit (dwarf2_cu
*cu
,
10103 enum language pretend_language
)
10105 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10106 struct objfile
*objfile
= per_objfile
->objfile
;
10107 struct compunit_symtab
*cust
;
10108 struct signatured_type
*sig_type
;
10110 gdb_assert (cu
->per_cu
->is_debug_types
);
10111 sig_type
= (struct signatured_type
*) cu
->per_cu
;
10113 /* Clear the list here in case something was left over. */
10114 cu
->method_list
.clear ();
10116 cu
->language
= pretend_language
;
10117 cu
->language_defn
= language_def (cu
->language
);
10119 /* The symbol tables are set up in read_type_unit_scope. */
10120 process_die (cu
->dies
, cu
);
10122 /* For now fudge the Go package. */
10123 if (cu
->language
== language_go
)
10124 fixup_go_packaging (cu
);
10126 /* Now that we have processed all the DIEs in the CU, all the types
10127 should be complete, and it should now be safe to compute all of the
10129 compute_delayed_physnames (cu
);
10131 if (cu
->language
== language_rust
)
10132 rust_union_quirks (cu
);
10134 /* TUs share symbol tables.
10135 If this is the first TU to use this symtab, complete the construction
10136 of it with end_expandable_symtab. Otherwise, complete the addition of
10137 this TU's symbols to the existing symtab. */
10138 type_unit_group_unshareable
*tug_unshare
=
10139 per_objfile
->get_type_unit_group_unshareable (sig_type
->type_unit_group
);
10140 if (tug_unshare
->compunit_symtab
== NULL
)
10142 buildsym_compunit
*builder
= cu
->get_builder ();
10143 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
10144 tug_unshare
->compunit_symtab
= cust
;
10148 /* Set symtab language to language from DW_AT_language. If the
10149 compilation is from a C file generated by language preprocessors,
10150 do not set the language if it was already deduced by
10152 if (!(cu
->language
== language_c
10153 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
10154 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10159 cu
->get_builder ()->augment_type_symtab ();
10160 cust
= tug_unshare
->compunit_symtab
;
10163 per_objfile
->set_symtab (cu
->per_cu
, cust
);
10165 /* Not needed any more. */
10166 cu
->reset_builder ();
10169 /* Process an imported unit DIE. */
10172 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10174 struct attribute
*attr
;
10176 /* For now we don't handle imported units in type units. */
10177 if (cu
->per_cu
->is_debug_types
)
10179 error (_("Dwarf Error: DW_TAG_imported_unit is not"
10180 " supported in type units [in module %s]"),
10181 objfile_name (cu
->per_objfile
->objfile
));
10184 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10187 sect_offset sect_off
= attr
->get_ref_die_offset ();
10188 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
10189 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10190 dwarf2_per_cu_data
*per_cu
10191 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
, per_objfile
);
10193 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
10194 into another compilation unit, at root level. Regard this as a hint,
10196 if (die
->parent
&& die
->parent
->parent
== NULL
10197 && per_cu
->unit_type
== DW_UT_compile
10198 && per_cu
->lang
== language_cplus
)
10201 /* If necessary, add it to the queue and load its DIEs. */
10202 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->language
))
10203 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
10204 false, cu
->language
);
10206 cu
->per_cu
->imported_symtabs_push (per_cu
);
10210 /* RAII object that represents a process_die scope: i.e.,
10211 starts/finishes processing a DIE. */
10212 class process_die_scope
10215 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
10216 : m_die (die
), m_cu (cu
)
10218 /* We should only be processing DIEs not already in process. */
10219 gdb_assert (!m_die
->in_process
);
10220 m_die
->in_process
= true;
10223 ~process_die_scope ()
10225 m_die
->in_process
= false;
10227 /* If we're done processing the DIE for the CU that owns the line
10228 header, we don't need the line header anymore. */
10229 if (m_cu
->line_header_die_owner
== m_die
)
10231 delete m_cu
->line_header
;
10232 m_cu
->line_header
= NULL
;
10233 m_cu
->line_header_die_owner
= NULL
;
10242 /* Process a die and its children. */
10245 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10247 process_die_scope
scope (die
, cu
);
10251 case DW_TAG_padding
:
10253 case DW_TAG_compile_unit
:
10254 case DW_TAG_partial_unit
:
10255 read_file_scope (die
, cu
);
10257 case DW_TAG_type_unit
:
10258 read_type_unit_scope (die
, cu
);
10260 case DW_TAG_subprogram
:
10261 /* Nested subprograms in Fortran get a prefix. */
10262 if (cu
->language
== language_fortran
10263 && die
->parent
!= NULL
10264 && die
->parent
->tag
== DW_TAG_subprogram
)
10265 cu
->processing_has_namespace_info
= true;
10266 /* Fall through. */
10267 case DW_TAG_inlined_subroutine
:
10268 read_func_scope (die
, cu
);
10270 case DW_TAG_lexical_block
:
10271 case DW_TAG_try_block
:
10272 case DW_TAG_catch_block
:
10273 read_lexical_block_scope (die
, cu
);
10275 case DW_TAG_call_site
:
10276 case DW_TAG_GNU_call_site
:
10277 read_call_site_scope (die
, cu
);
10279 case DW_TAG_class_type
:
10280 case DW_TAG_interface_type
:
10281 case DW_TAG_structure_type
:
10282 case DW_TAG_union_type
:
10283 process_structure_scope (die
, cu
);
10285 case DW_TAG_enumeration_type
:
10286 process_enumeration_scope (die
, cu
);
10289 /* These dies have a type, but processing them does not create
10290 a symbol or recurse to process the children. Therefore we can
10291 read them on-demand through read_type_die. */
10292 case DW_TAG_subroutine_type
:
10293 case DW_TAG_set_type
:
10294 case DW_TAG_pointer_type
:
10295 case DW_TAG_ptr_to_member_type
:
10296 case DW_TAG_reference_type
:
10297 case DW_TAG_rvalue_reference_type
:
10298 case DW_TAG_string_type
:
10301 case DW_TAG_array_type
:
10302 /* We only need to handle this case for Ada -- in other
10303 languages, it's normal for the compiler to emit a typedef
10305 if (cu
->language
!= language_ada
)
10308 case DW_TAG_base_type
:
10309 case DW_TAG_subrange_type
:
10310 case DW_TAG_typedef
:
10311 /* Add a typedef symbol for the type definition, if it has a
10313 new_symbol (die
, read_type_die (die
, cu
), cu
);
10315 case DW_TAG_common_block
:
10316 read_common_block (die
, cu
);
10318 case DW_TAG_common_inclusion
:
10320 case DW_TAG_namespace
:
10321 cu
->processing_has_namespace_info
= true;
10322 read_namespace (die
, cu
);
10324 case DW_TAG_module
:
10325 cu
->processing_has_namespace_info
= true;
10326 read_module (die
, cu
);
10328 case DW_TAG_imported_declaration
:
10329 cu
->processing_has_namespace_info
= true;
10330 if (read_namespace_alias (die
, cu
))
10332 /* The declaration is not a global namespace alias. */
10333 /* Fall through. */
10334 case DW_TAG_imported_module
:
10335 cu
->processing_has_namespace_info
= true;
10336 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
10337 || cu
->language
!= language_fortran
))
10338 complaint (_("Tag '%s' has unexpected children"),
10339 dwarf_tag_name (die
->tag
));
10340 read_import_statement (die
, cu
);
10343 case DW_TAG_imported_unit
:
10344 process_imported_unit_die (die
, cu
);
10347 case DW_TAG_variable
:
10348 read_variable (die
, cu
);
10352 new_symbol (die
, NULL
, cu
);
10357 /* DWARF name computation. */
10359 /* A helper function for dwarf2_compute_name which determines whether DIE
10360 needs to have the name of the scope prepended to the name listed in the
10364 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10366 struct attribute
*attr
;
10370 case DW_TAG_namespace
:
10371 case DW_TAG_typedef
:
10372 case DW_TAG_class_type
:
10373 case DW_TAG_interface_type
:
10374 case DW_TAG_structure_type
:
10375 case DW_TAG_union_type
:
10376 case DW_TAG_enumeration_type
:
10377 case DW_TAG_enumerator
:
10378 case DW_TAG_subprogram
:
10379 case DW_TAG_inlined_subroutine
:
10380 case DW_TAG_member
:
10381 case DW_TAG_imported_declaration
:
10384 case DW_TAG_variable
:
10385 case DW_TAG_constant
:
10386 /* We only need to prefix "globally" visible variables. These include
10387 any variable marked with DW_AT_external or any variable that
10388 lives in a namespace. [Variables in anonymous namespaces
10389 require prefixing, but they are not DW_AT_external.] */
10391 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
10393 struct dwarf2_cu
*spec_cu
= cu
;
10395 return die_needs_namespace (die_specification (die
, &spec_cu
),
10399 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10400 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
10401 && die
->parent
->tag
!= DW_TAG_module
)
10403 /* A variable in a lexical block of some kind does not need a
10404 namespace, even though in C++ such variables may be external
10405 and have a mangled name. */
10406 if (die
->parent
->tag
== DW_TAG_lexical_block
10407 || die
->parent
->tag
== DW_TAG_try_block
10408 || die
->parent
->tag
== DW_TAG_catch_block
10409 || die
->parent
->tag
== DW_TAG_subprogram
)
10418 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
10419 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10420 defined for the given DIE. */
10422 static struct attribute
*
10423 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
10425 struct attribute
*attr
;
10427 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
10429 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10434 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10435 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10436 defined for the given DIE. */
10438 static const char *
10439 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10441 const char *linkage_name
;
10443 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10444 if (linkage_name
== NULL
)
10445 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10447 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
10448 See https://github.com/rust-lang/rust/issues/32925. */
10449 if (cu
->language
== language_rust
&& linkage_name
!= NULL
10450 && strchr (linkage_name
, '{') != NULL
)
10451 linkage_name
= NULL
;
10453 return linkage_name
;
10456 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10457 compute the physname for the object, which include a method's:
10458 - formal parameters (C++),
10459 - receiver type (Go),
10461 The term "physname" is a bit confusing.
10462 For C++, for example, it is the demangled name.
10463 For Go, for example, it's the mangled name.
10465 For Ada, return the DIE's linkage name rather than the fully qualified
10466 name. PHYSNAME is ignored..
10468 The result is allocated on the objfile->per_bfd's obstack and
10471 static const char *
10472 dwarf2_compute_name (const char *name
,
10473 struct die_info
*die
, struct dwarf2_cu
*cu
,
10476 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10479 name
= dwarf2_name (die
, cu
);
10481 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10482 but otherwise compute it by typename_concat inside GDB.
10483 FIXME: Actually this is not really true, or at least not always true.
10484 It's all very confusing. compute_and_set_names doesn't try to demangle
10485 Fortran names because there is no mangling standard. So new_symbol
10486 will set the demangled name to the result of dwarf2_full_name, and it is
10487 the demangled name that GDB uses if it exists. */
10488 if (cu
->language
== language_ada
10489 || (cu
->language
== language_fortran
&& physname
))
10491 /* For Ada unit, we prefer the linkage name over the name, as
10492 the former contains the exported name, which the user expects
10493 to be able to reference. Ideally, we want the user to be able
10494 to reference this entity using either natural or linkage name,
10495 but we haven't started looking at this enhancement yet. */
10496 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10498 if (linkage_name
!= NULL
)
10499 return linkage_name
;
10502 /* These are the only languages we know how to qualify names in. */
10504 && (cu
->language
== language_cplus
10505 || cu
->language
== language_fortran
|| cu
->language
== language_d
10506 || cu
->language
== language_rust
))
10508 if (die_needs_namespace (die
, cu
))
10510 const char *prefix
;
10511 const char *canonical_name
= NULL
;
10515 prefix
= determine_prefix (die
, cu
);
10516 if (*prefix
!= '\0')
10518 gdb::unique_xmalloc_ptr
<char> prefixed_name
10519 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10521 buf
.puts (prefixed_name
.get ());
10526 /* Template parameters may be specified in the DIE's DW_AT_name, or
10527 as children with DW_TAG_template_type_param or
10528 DW_TAG_value_type_param. If the latter, add them to the name
10529 here. If the name already has template parameters, then
10530 skip this step; some versions of GCC emit both, and
10531 it is more efficient to use the pre-computed name.
10533 Something to keep in mind about this process: it is very
10534 unlikely, or in some cases downright impossible, to produce
10535 something that will match the mangled name of a function.
10536 If the definition of the function has the same debug info,
10537 we should be able to match up with it anyway. But fallbacks
10538 using the minimal symbol, for instance to find a method
10539 implemented in a stripped copy of libstdc++, will not work.
10540 If we do not have debug info for the definition, we will have to
10541 match them up some other way.
10543 When we do name matching there is a related problem with function
10544 templates; two instantiated function templates are allowed to
10545 differ only by their return types, which we do not add here. */
10547 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10549 struct attribute
*attr
;
10550 struct die_info
*child
;
10553 die
->building_fullname
= 1;
10555 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10559 const gdb_byte
*bytes
;
10560 struct dwarf2_locexpr_baton
*baton
;
10563 if (child
->tag
!= DW_TAG_template_type_param
10564 && child
->tag
!= DW_TAG_template_value_param
)
10575 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10578 complaint (_("template parameter missing DW_AT_type"));
10579 buf
.puts ("UNKNOWN_TYPE");
10582 type
= die_type (child
, cu
);
10584 if (child
->tag
== DW_TAG_template_type_param
)
10586 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10587 &type_print_raw_options
);
10591 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10594 complaint (_("template parameter missing "
10595 "DW_AT_const_value"));
10596 buf
.puts ("UNKNOWN_VALUE");
10600 dwarf2_const_value_attr (attr
, type
, name
,
10601 &cu
->comp_unit_obstack
, cu
,
10602 &value
, &bytes
, &baton
);
10604 if (type
->has_no_signedness ())
10605 /* GDB prints characters as NUMBER 'CHAR'. If that's
10606 changed, this can use value_print instead. */
10607 c_printchar (value
, type
, &buf
);
10610 struct value_print_options opts
;
10613 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10617 baton
->per_objfile
);
10618 else if (bytes
!= NULL
)
10620 v
= allocate_value (type
);
10621 memcpy (value_contents_writeable (v
), bytes
,
10622 TYPE_LENGTH (type
));
10625 v
= value_from_longest (type
, value
);
10627 /* Specify decimal so that we do not depend on
10629 get_formatted_print_options (&opts
, 'd');
10631 value_print (v
, &buf
, &opts
);
10636 die
->building_fullname
= 0;
10640 /* Close the argument list, with a space if necessary
10641 (nested templates). */
10642 if (!buf
.empty () && buf
.string ().back () == '>')
10649 /* For C++ methods, append formal parameter type
10650 information, if PHYSNAME. */
10652 if (physname
&& die
->tag
== DW_TAG_subprogram
10653 && cu
->language
== language_cplus
)
10655 struct type
*type
= read_type_die (die
, cu
);
10657 c_type_print_args (type
, &buf
, 1, cu
->language
,
10658 &type_print_raw_options
);
10660 if (cu
->language
== language_cplus
)
10662 /* Assume that an artificial first parameter is
10663 "this", but do not crash if it is not. RealView
10664 marks unnamed (and thus unused) parameters as
10665 artificial; there is no way to differentiate
10667 if (type
->num_fields () > 0
10668 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10669 && type
->field (0).type ()->code () == TYPE_CODE_PTR
10670 && TYPE_CONST (TYPE_TARGET_TYPE (type
->field (0).type ())))
10671 buf
.puts (" const");
10675 const std::string
&intermediate_name
= buf
.string ();
10677 if (cu
->language
== language_cplus
)
10679 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10682 /* If we only computed INTERMEDIATE_NAME, or if
10683 INTERMEDIATE_NAME is already canonical, then we need to
10685 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10686 name
= objfile
->intern (intermediate_name
);
10688 name
= canonical_name
;
10695 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10696 If scope qualifiers are appropriate they will be added. The result
10697 will be allocated on the storage_obstack, or NULL if the DIE does
10698 not have a name. NAME may either be from a previous call to
10699 dwarf2_name or NULL.
10701 The output string will be canonicalized (if C++). */
10703 static const char *
10704 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10706 return dwarf2_compute_name (name
, die
, cu
, 0);
10709 /* Construct a physname for the given DIE in CU. NAME may either be
10710 from a previous call to dwarf2_name or NULL. The result will be
10711 allocated on the objfile_objstack or NULL if the DIE does not have a
10714 The output string will be canonicalized (if C++). */
10716 static const char *
10717 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10719 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10720 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10723 /* In this case dwarf2_compute_name is just a shortcut not building anything
10725 if (!die_needs_namespace (die
, cu
))
10726 return dwarf2_compute_name (name
, die
, cu
, 1);
10728 if (cu
->language
!= language_rust
)
10729 mangled
= dw2_linkage_name (die
, cu
);
10731 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10733 gdb::unique_xmalloc_ptr
<char> demangled
;
10734 if (mangled
!= NULL
)
10737 if (language_def (cu
->language
)->store_sym_names_in_linkage_form_p ())
10739 /* Do nothing (do not demangle the symbol name). */
10743 /* Use DMGL_RET_DROP for C++ template functions to suppress
10744 their return type. It is easier for GDB users to search
10745 for such functions as `name(params)' than `long name(params)'.
10746 In such case the minimal symbol names do not match the full
10747 symbol names but for template functions there is never a need
10748 to look up their definition from their declaration so
10749 the only disadvantage remains the minimal symbol variant
10750 `long name(params)' does not have the proper inferior type. */
10751 demangled
.reset (gdb_demangle (mangled
,
10752 (DMGL_PARAMS
| DMGL_ANSI
10753 | DMGL_RET_DROP
)));
10756 canon
= demangled
.get ();
10764 if (canon
== NULL
|| check_physname
)
10766 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10768 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10770 /* It may not mean a bug in GDB. The compiler could also
10771 compute DW_AT_linkage_name incorrectly. But in such case
10772 GDB would need to be bug-to-bug compatible. */
10774 complaint (_("Computed physname <%s> does not match demangled <%s> "
10775 "(from linkage <%s>) - DIE at %s [in module %s]"),
10776 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10777 objfile_name (objfile
));
10779 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10780 is available here - over computed PHYSNAME. It is safer
10781 against both buggy GDB and buggy compilers. */
10795 retval
= objfile
->intern (retval
);
10800 /* Inspect DIE in CU for a namespace alias. If one exists, record
10801 a new symbol for it.
10803 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10806 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10808 struct attribute
*attr
;
10810 /* If the die does not have a name, this is not a namespace
10812 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10816 struct die_info
*d
= die
;
10817 struct dwarf2_cu
*imported_cu
= cu
;
10819 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10820 keep inspecting DIEs until we hit the underlying import. */
10821 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10822 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10824 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10828 d
= follow_die_ref (d
, attr
, &imported_cu
);
10829 if (d
->tag
!= DW_TAG_imported_declaration
)
10833 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10835 complaint (_("DIE at %s has too many recursively imported "
10836 "declarations"), sect_offset_str (d
->sect_off
));
10843 sect_offset sect_off
= attr
->get_ref_die_offset ();
10845 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, cu
->per_objfile
);
10846 if (type
!= NULL
&& type
->code () == TYPE_CODE_NAMESPACE
)
10848 /* This declaration is a global namespace alias. Add
10849 a symbol for it whose type is the aliased namespace. */
10850 new_symbol (die
, type
, cu
);
10859 /* Return the using directives repository (global or local?) to use in the
10860 current context for CU.
10862 For Ada, imported declarations can materialize renamings, which *may* be
10863 global. However it is impossible (for now?) in DWARF to distinguish
10864 "external" imported declarations and "static" ones. As all imported
10865 declarations seem to be static in all other languages, make them all CU-wide
10866 global only in Ada. */
10868 static struct using_direct
**
10869 using_directives (struct dwarf2_cu
*cu
)
10871 if (cu
->language
== language_ada
10872 && cu
->get_builder ()->outermost_context_p ())
10873 return cu
->get_builder ()->get_global_using_directives ();
10875 return cu
->get_builder ()->get_local_using_directives ();
10878 /* Read the import statement specified by the given die and record it. */
10881 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10883 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10884 struct attribute
*import_attr
;
10885 struct die_info
*imported_die
, *child_die
;
10886 struct dwarf2_cu
*imported_cu
;
10887 const char *imported_name
;
10888 const char *imported_name_prefix
;
10889 const char *canonical_name
;
10890 const char *import_alias
;
10891 const char *imported_declaration
= NULL
;
10892 const char *import_prefix
;
10893 std::vector
<const char *> excludes
;
10895 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10896 if (import_attr
== NULL
)
10898 complaint (_("Tag '%s' has no DW_AT_import"),
10899 dwarf_tag_name (die
->tag
));
10904 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10905 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10906 if (imported_name
== NULL
)
10908 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10910 The import in the following code:
10924 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10925 <52> DW_AT_decl_file : 1
10926 <53> DW_AT_decl_line : 6
10927 <54> DW_AT_import : <0x75>
10928 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10929 <59> DW_AT_name : B
10930 <5b> DW_AT_decl_file : 1
10931 <5c> DW_AT_decl_line : 2
10932 <5d> DW_AT_type : <0x6e>
10934 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10935 <76> DW_AT_byte_size : 4
10936 <77> DW_AT_encoding : 5 (signed)
10938 imports the wrong die ( 0x75 instead of 0x58 ).
10939 This case will be ignored until the gcc bug is fixed. */
10943 /* Figure out the local name after import. */
10944 import_alias
= dwarf2_name (die
, cu
);
10946 /* Figure out where the statement is being imported to. */
10947 import_prefix
= determine_prefix (die
, cu
);
10949 /* Figure out what the scope of the imported die is and prepend it
10950 to the name of the imported die. */
10951 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10953 if (imported_die
->tag
!= DW_TAG_namespace
10954 && imported_die
->tag
!= DW_TAG_module
)
10956 imported_declaration
= imported_name
;
10957 canonical_name
= imported_name_prefix
;
10959 else if (strlen (imported_name_prefix
) > 0)
10960 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10961 imported_name_prefix
,
10962 (cu
->language
== language_d
? "." : "::"),
10963 imported_name
, (char *) NULL
);
10965 canonical_name
= imported_name
;
10967 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
10968 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10969 child_die
= child_die
->sibling
)
10971 /* DWARF-4: A Fortran use statement with a “rename list” may be
10972 represented by an imported module entry with an import attribute
10973 referring to the module and owned entries corresponding to those
10974 entities that are renamed as part of being imported. */
10976 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10978 complaint (_("child DW_TAG_imported_declaration expected "
10979 "- DIE at %s [in module %s]"),
10980 sect_offset_str (child_die
->sect_off
),
10981 objfile_name (objfile
));
10985 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10986 if (import_attr
== NULL
)
10988 complaint (_("Tag '%s' has no DW_AT_import"),
10989 dwarf_tag_name (child_die
->tag
));
10994 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10996 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10997 if (imported_name
== NULL
)
10999 complaint (_("child DW_TAG_imported_declaration has unknown "
11000 "imported name - DIE at %s [in module %s]"),
11001 sect_offset_str (child_die
->sect_off
),
11002 objfile_name (objfile
));
11006 excludes
.push_back (imported_name
);
11008 process_die (child_die
, cu
);
11011 add_using_directive (using_directives (cu
),
11015 imported_declaration
,
11018 &objfile
->objfile_obstack
);
11021 /* ICC<14 does not output the required DW_AT_declaration on incomplete
11022 types, but gives them a size of zero. Starting with version 14,
11023 ICC is compatible with GCC. */
11026 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
11028 if (!cu
->checked_producer
)
11029 check_producer (cu
);
11031 return cu
->producer_is_icc_lt_14
;
11034 /* ICC generates a DW_AT_type for C void functions. This was observed on
11035 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
11036 which says that void functions should not have a DW_AT_type. */
11039 producer_is_icc (struct dwarf2_cu
*cu
)
11041 if (!cu
->checked_producer
)
11042 check_producer (cu
);
11044 return cu
->producer_is_icc
;
11047 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
11048 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
11049 this, it was first present in GCC release 4.3.0. */
11052 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
11054 if (!cu
->checked_producer
)
11055 check_producer (cu
);
11057 return cu
->producer_is_gcc_lt_4_3
;
11060 static file_and_directory
11061 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
11063 file_and_directory res
;
11065 /* Find the filename. Do not use dwarf2_name here, since the filename
11066 is not a source language identifier. */
11067 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
11068 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
11070 if (res
.comp_dir
== NULL
11071 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
11072 && IS_ABSOLUTE_PATH (res
.name
))
11074 res
.comp_dir_storage
= ldirname (res
.name
);
11075 if (!res
.comp_dir_storage
.empty ())
11076 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
11078 if (res
.comp_dir
!= NULL
)
11080 /* Irix 6.2 native cc prepends <machine>.: to the compilation
11081 directory, get rid of it. */
11082 const char *cp
= strchr (res
.comp_dir
, ':');
11084 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
11085 res
.comp_dir
= cp
+ 1;
11088 if (res
.name
== NULL
)
11089 res
.name
= "<unknown>";
11094 /* Handle DW_AT_stmt_list for a compilation unit.
11095 DIE is the DW_TAG_compile_unit die for CU.
11096 COMP_DIR is the compilation directory. LOWPC is passed to
11097 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
11100 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
11101 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
11103 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
11104 struct attribute
*attr
;
11105 struct line_header line_header_local
;
11106 hashval_t line_header_local_hash
;
11108 int decode_mapping
;
11110 gdb_assert (! cu
->per_cu
->is_debug_types
);
11112 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
11113 if (attr
== NULL
|| !attr
->form_is_unsigned ())
11116 sect_offset line_offset
= (sect_offset
) attr
->as_unsigned ();
11118 /* The line header hash table is only created if needed (it exists to
11119 prevent redundant reading of the line table for partial_units).
11120 If we're given a partial_unit, we'll need it. If we're given a
11121 compile_unit, then use the line header hash table if it's already
11122 created, but don't create one just yet. */
11124 if (per_objfile
->line_header_hash
== NULL
11125 && die
->tag
== DW_TAG_partial_unit
)
11127 per_objfile
->line_header_hash
11128 .reset (htab_create_alloc (127, line_header_hash_voidp
,
11129 line_header_eq_voidp
,
11130 free_line_header_voidp
,
11134 line_header_local
.sect_off
= line_offset
;
11135 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
11136 line_header_local_hash
= line_header_hash (&line_header_local
);
11137 if (per_objfile
->line_header_hash
!= NULL
)
11139 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
11140 &line_header_local
,
11141 line_header_local_hash
, NO_INSERT
);
11143 /* For DW_TAG_compile_unit we need info like symtab::linetable which
11144 is not present in *SLOT (since if there is something in *SLOT then
11145 it will be for a partial_unit). */
11146 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
11148 gdb_assert (*slot
!= NULL
);
11149 cu
->line_header
= (struct line_header
*) *slot
;
11154 /* dwarf_decode_line_header does not yet provide sufficient information.
11155 We always have to call also dwarf_decode_lines for it. */
11156 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
11160 cu
->line_header
= lh
.release ();
11161 cu
->line_header_die_owner
= die
;
11163 if (per_objfile
->line_header_hash
== NULL
)
11167 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
11168 &line_header_local
,
11169 line_header_local_hash
, INSERT
);
11170 gdb_assert (slot
!= NULL
);
11172 if (slot
!= NULL
&& *slot
== NULL
)
11174 /* This newly decoded line number information unit will be owned
11175 by line_header_hash hash table. */
11176 *slot
= cu
->line_header
;
11177 cu
->line_header_die_owner
= NULL
;
11181 /* We cannot free any current entry in (*slot) as that struct line_header
11182 may be already used by multiple CUs. Create only temporary decoded
11183 line_header for this CU - it may happen at most once for each line
11184 number information unit. And if we're not using line_header_hash
11185 then this is what we want as well. */
11186 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
11188 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
11189 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
11194 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
11197 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11199 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
11200 struct objfile
*objfile
= per_objfile
->objfile
;
11201 struct gdbarch
*gdbarch
= objfile
->arch ();
11202 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
11203 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
11204 struct attribute
*attr
;
11205 struct die_info
*child_die
;
11206 CORE_ADDR baseaddr
;
11208 prepare_one_comp_unit (cu
, die
, cu
->language
);
11209 baseaddr
= objfile
->text_section_offset ();
11211 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
11213 /* If we didn't find a lowpc, set it to highpc to avoid complaints
11214 from finish_block. */
11215 if (lowpc
== ((CORE_ADDR
) -1))
11217 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11219 file_and_directory fnd
= find_file_and_directory (die
, cu
);
11221 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
11222 standardised yet. As a workaround for the language detection we fall
11223 back to the DW_AT_producer string. */
11224 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
11225 cu
->language
= language_opencl
;
11227 /* Similar hack for Go. */
11228 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
11229 set_cu_language (DW_LANG_Go
, cu
);
11231 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
11233 /* Decode line number information if present. We do this before
11234 processing child DIEs, so that the line header table is available
11235 for DW_AT_decl_file. */
11236 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
11238 /* Process all dies in compilation unit. */
11239 if (die
->child
!= NULL
)
11241 child_die
= die
->child
;
11242 while (child_die
&& child_die
->tag
)
11244 process_die (child_die
, cu
);
11245 child_die
= child_die
->sibling
;
11249 /* Decode macro information, if present. Dwarf 2 macro information
11250 refers to information in the line number info statement program
11251 header, so we can only read it if we've read the header
11253 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
11255 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
11256 if (attr
!= nullptr && attr
->form_is_unsigned () && cu
->line_header
)
11258 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
11259 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
11261 dwarf_decode_macros (cu
, attr
->as_unsigned (), 1);
11265 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
11266 if (attr
!= nullptr && attr
->form_is_unsigned () && cu
->line_header
)
11268 unsigned int macro_offset
= attr
->as_unsigned ();
11270 dwarf_decode_macros (cu
, macro_offset
, 0);
11276 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
11278 struct type_unit_group
*tu_group
;
11280 struct attribute
*attr
;
11282 struct signatured_type
*sig_type
;
11284 gdb_assert (per_cu
->is_debug_types
);
11285 sig_type
= (struct signatured_type
*) per_cu
;
11287 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
11289 /* If we're using .gdb_index (includes -readnow) then
11290 per_cu->type_unit_group may not have been set up yet. */
11291 if (sig_type
->type_unit_group
== NULL
)
11292 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
11293 tu_group
= sig_type
->type_unit_group
;
11295 /* If we've already processed this stmt_list there's no real need to
11296 do it again, we could fake it and just recreate the part we need
11297 (file name,index -> symtab mapping). If data shows this optimization
11298 is useful we can do it then. */
11299 type_unit_group_unshareable
*tug_unshare
11300 = per_objfile
->get_type_unit_group_unshareable (tu_group
);
11301 first_time
= tug_unshare
->compunit_symtab
== NULL
;
11303 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
11306 if (attr
!= NULL
&& attr
->form_is_unsigned ())
11308 sect_offset line_offset
= (sect_offset
) attr
->as_unsigned ();
11309 lh
= dwarf_decode_line_header (line_offset
, this);
11314 start_symtab ("", NULL
, 0);
11317 gdb_assert (tug_unshare
->symtabs
== NULL
);
11318 gdb_assert (m_builder
== nullptr);
11319 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
11320 m_builder
.reset (new struct buildsym_compunit
11321 (COMPUNIT_OBJFILE (cust
), "",
11322 COMPUNIT_DIRNAME (cust
),
11323 compunit_language (cust
),
11325 list_in_scope
= get_builder ()->get_file_symbols ();
11330 line_header
= lh
.release ();
11331 line_header_die_owner
= die
;
11335 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
11337 /* Note: We don't assign tu_group->compunit_symtab yet because we're
11338 still initializing it, and our caller (a few levels up)
11339 process_full_type_unit still needs to know if this is the first
11342 tug_unshare
->symtabs
11343 = XOBNEWVEC (&COMPUNIT_OBJFILE (cust
)->objfile_obstack
,
11344 struct symtab
*, line_header
->file_names_size ());
11346 auto &file_names
= line_header
->file_names ();
11347 for (i
= 0; i
< file_names
.size (); ++i
)
11349 file_entry
&fe
= file_names
[i
];
11350 dwarf2_start_subfile (this, fe
.name
,
11351 fe
.include_dir (line_header
));
11352 buildsym_compunit
*b
= get_builder ();
11353 if (b
->get_current_subfile ()->symtab
== NULL
)
11355 /* NOTE: start_subfile will recognize when it's been
11356 passed a file it has already seen. So we can't
11357 assume there's a simple mapping from
11358 cu->line_header->file_names to subfiles, plus
11359 cu->line_header->file_names may contain dups. */
11360 b
->get_current_subfile ()->symtab
11361 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
11364 fe
.symtab
= b
->get_current_subfile ()->symtab
;
11365 tug_unshare
->symtabs
[i
] = fe
.symtab
;
11370 gdb_assert (m_builder
== nullptr);
11371 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
11372 m_builder
.reset (new struct buildsym_compunit
11373 (COMPUNIT_OBJFILE (cust
), "",
11374 COMPUNIT_DIRNAME (cust
),
11375 compunit_language (cust
),
11377 list_in_scope
= get_builder ()->get_file_symbols ();
11379 auto &file_names
= line_header
->file_names ();
11380 for (i
= 0; i
< file_names
.size (); ++i
)
11382 file_entry
&fe
= file_names
[i
];
11383 fe
.symtab
= tug_unshare
->symtabs
[i
];
11387 /* The main symtab is allocated last. Type units don't have DW_AT_name
11388 so they don't have a "real" (so to speak) symtab anyway.
11389 There is later code that will assign the main symtab to all symbols
11390 that don't have one. We need to handle the case of a symbol with a
11391 missing symtab (DW_AT_decl_file) anyway. */
11394 /* Process DW_TAG_type_unit.
11395 For TUs we want to skip the first top level sibling if it's not the
11396 actual type being defined by this TU. In this case the first top
11397 level sibling is there to provide context only. */
11400 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11402 struct die_info
*child_die
;
11404 prepare_one_comp_unit (cu
, die
, language_minimal
);
11406 /* Initialize (or reinitialize) the machinery for building symtabs.
11407 We do this before processing child DIEs, so that the line header table
11408 is available for DW_AT_decl_file. */
11409 cu
->setup_type_unit_groups (die
);
11411 if (die
->child
!= NULL
)
11413 child_die
= die
->child
;
11414 while (child_die
&& child_die
->tag
)
11416 process_die (child_die
, cu
);
11417 child_die
= child_die
->sibling
;
11424 http://gcc.gnu.org/wiki/DebugFission
11425 http://gcc.gnu.org/wiki/DebugFissionDWP
11427 To simplify handling of both DWO files ("object" files with the DWARF info)
11428 and DWP files (a file with the DWOs packaged up into one file), we treat
11429 DWP files as having a collection of virtual DWO files. */
11432 hash_dwo_file (const void *item
)
11434 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11437 hash
= htab_hash_string (dwo_file
->dwo_name
);
11438 if (dwo_file
->comp_dir
!= NULL
)
11439 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11444 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11446 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11447 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11449 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11451 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11452 return lhs
->comp_dir
== rhs
->comp_dir
;
11453 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11456 /* Allocate a hash table for DWO files. */
11459 allocate_dwo_file_hash_table ()
11461 auto delete_dwo_file
= [] (void *item
)
11463 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
11468 return htab_up (htab_create_alloc (41,
11475 /* Lookup DWO file DWO_NAME. */
11478 lookup_dwo_file_slot (dwarf2_per_objfile
*per_objfile
,
11479 const char *dwo_name
,
11480 const char *comp_dir
)
11482 struct dwo_file find_entry
;
11485 if (per_objfile
->per_bfd
->dwo_files
== NULL
)
11486 per_objfile
->per_bfd
->dwo_files
= allocate_dwo_file_hash_table ();
11488 find_entry
.dwo_name
= dwo_name
;
11489 find_entry
.comp_dir
= comp_dir
;
11490 slot
= htab_find_slot (per_objfile
->per_bfd
->dwo_files
.get (), &find_entry
,
11497 hash_dwo_unit (const void *item
)
11499 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11501 /* This drops the top 32 bits of the id, but is ok for a hash. */
11502 return dwo_unit
->signature
;
11506 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11508 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11509 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11511 /* The signature is assumed to be unique within the DWO file.
11512 So while object file CU dwo_id's always have the value zero,
11513 that's OK, assuming each object file DWO file has only one CU,
11514 and that's the rule for now. */
11515 return lhs
->signature
== rhs
->signature
;
11518 /* Allocate a hash table for DWO CUs,TUs.
11519 There is one of these tables for each of CUs,TUs for each DWO file. */
11522 allocate_dwo_unit_table ()
11524 /* Start out with a pretty small number.
11525 Generally DWO files contain only one CU and maybe some TUs. */
11526 return htab_up (htab_create_alloc (3,
11529 NULL
, xcalloc
, xfree
));
11532 /* die_reader_func for create_dwo_cu. */
11535 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11536 const gdb_byte
*info_ptr
,
11537 struct die_info
*comp_unit_die
,
11538 struct dwo_file
*dwo_file
,
11539 struct dwo_unit
*dwo_unit
)
11541 struct dwarf2_cu
*cu
= reader
->cu
;
11542 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11543 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11545 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11546 if (!signature
.has_value ())
11548 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11549 " its dwo_id [in module %s]"),
11550 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11554 dwo_unit
->dwo_file
= dwo_file
;
11555 dwo_unit
->signature
= *signature
;
11556 dwo_unit
->section
= section
;
11557 dwo_unit
->sect_off
= sect_off
;
11558 dwo_unit
->length
= cu
->per_cu
->length
;
11560 dwarf_read_debug_printf (" offset %s, dwo_id %s",
11561 sect_offset_str (sect_off
),
11562 hex_string (dwo_unit
->signature
));
11565 /* Create the dwo_units for the CUs in a DWO_FILE.
11566 Note: This function processes DWO files only, not DWP files. */
11569 create_cus_hash_table (dwarf2_per_objfile
*per_objfile
,
11570 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11571 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
11573 struct objfile
*objfile
= per_objfile
->objfile
;
11574 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
11575 const gdb_byte
*info_ptr
, *end_ptr
;
11577 section
.read (objfile
);
11578 info_ptr
= section
.buffer
;
11580 if (info_ptr
== NULL
)
11583 dwarf_read_debug_printf ("Reading %s for %s:",
11584 section
.get_name (),
11585 section
.get_file_name ());
11587 end_ptr
= info_ptr
+ section
.size
;
11588 while (info_ptr
< end_ptr
)
11590 struct dwarf2_per_cu_data per_cu
;
11591 struct dwo_unit read_unit
{};
11592 struct dwo_unit
*dwo_unit
;
11594 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11596 memset (&per_cu
, 0, sizeof (per_cu
));
11597 per_cu
.per_bfd
= per_bfd
;
11598 per_cu
.is_debug_types
= 0;
11599 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11600 per_cu
.section
= §ion
;
11602 cutu_reader
reader (&per_cu
, per_objfile
, cu
, &dwo_file
);
11603 if (!reader
.dummy_p
)
11604 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11605 &dwo_file
, &read_unit
);
11606 info_ptr
+= per_cu
.length
;
11608 // If the unit could not be parsed, skip it.
11609 if (read_unit
.dwo_file
== NULL
)
11612 if (cus_htab
== NULL
)
11613 cus_htab
= allocate_dwo_unit_table ();
11615 dwo_unit
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
11617 *dwo_unit
= read_unit
;
11618 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11619 gdb_assert (slot
!= NULL
);
11622 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11623 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11625 complaint (_("debug cu entry at offset %s is duplicate to"
11626 " the entry at offset %s, signature %s"),
11627 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11628 hex_string (dwo_unit
->signature
));
11630 *slot
= (void *)dwo_unit
;
11634 /* DWP file .debug_{cu,tu}_index section format:
11635 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11636 [ref: http://dwarfstd.org/doc/DWARF5.pdf, sect 7.3.5 "DWARF Package Files"]
11638 DWP Versions 1 & 2 are older, pre-standard format versions. The first
11639 officially standard DWP format was published with DWARF v5 and is called
11640 Version 5. There are no versions 3 or 4.
11644 Both index sections have the same format, and serve to map a 64-bit
11645 signature to a set of section numbers. Each section begins with a header,
11646 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11647 indexes, and a pool of 32-bit section numbers. The index sections will be
11648 aligned at 8-byte boundaries in the file.
11650 The index section header consists of:
11652 V, 32 bit version number
11654 N, 32 bit number of compilation units or type units in the index
11655 M, 32 bit number of slots in the hash table
11657 Numbers are recorded using the byte order of the application binary.
11659 The hash table begins at offset 16 in the section, and consists of an array
11660 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11661 order of the application binary). Unused slots in the hash table are 0.
11662 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11664 The parallel table begins immediately after the hash table
11665 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11666 array of 32-bit indexes (using the byte order of the application binary),
11667 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11668 table contains a 32-bit index into the pool of section numbers. For unused
11669 hash table slots, the corresponding entry in the parallel table will be 0.
11671 The pool of section numbers begins immediately following the hash table
11672 (at offset 16 + 12 * M from the beginning of the section). The pool of
11673 section numbers consists of an array of 32-bit words (using the byte order
11674 of the application binary). Each item in the array is indexed starting
11675 from 0. The hash table entry provides the index of the first section
11676 number in the set. Additional section numbers in the set follow, and the
11677 set is terminated by a 0 entry (section number 0 is not used in ELF).
11679 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11680 section must be the first entry in the set, and the .debug_abbrev.dwo must
11681 be the second entry. Other members of the set may follow in any order.
11685 DWP Versions 2 and 5:
11687 DWP Versions 2 and 5 combine all the .debug_info, etc. sections into one,
11688 and the entries in the index tables are now offsets into these sections.
11689 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11692 Index Section Contents:
11694 Hash Table of Signatures dwp_hash_table.hash_table
11695 Parallel Table of Indices dwp_hash_table.unit_table
11696 Table of Section Offsets dwp_hash_table.{v2|v5}.{section_ids,offsets}
11697 Table of Section Sizes dwp_hash_table.{v2|v5}.sizes
11699 The index section header consists of:
11701 V, 32 bit version number
11702 L, 32 bit number of columns in the table of section offsets
11703 N, 32 bit number of compilation units or type units in the index
11704 M, 32 bit number of slots in the hash table
11706 Numbers are recorded using the byte order of the application binary.
11708 The hash table has the same format as version 1.
11709 The parallel table of indices has the same format as version 1,
11710 except that the entries are origin-1 indices into the table of sections
11711 offsets and the table of section sizes.
11713 The table of offsets begins immediately following the parallel table
11714 (at offset 16 + 12 * M from the beginning of the section). The table is
11715 a two-dimensional array of 32-bit words (using the byte order of the
11716 application binary), with L columns and N+1 rows, in row-major order.
11717 Each row in the array is indexed starting from 0. The first row provides
11718 a key to the remaining rows: each column in this row provides an identifier
11719 for a debug section, and the offsets in the same column of subsequent rows
11720 refer to that section. The section identifiers for Version 2 are:
11722 DW_SECT_INFO 1 .debug_info.dwo
11723 DW_SECT_TYPES 2 .debug_types.dwo
11724 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11725 DW_SECT_LINE 4 .debug_line.dwo
11726 DW_SECT_LOC 5 .debug_loc.dwo
11727 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11728 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11729 DW_SECT_MACRO 8 .debug_macro.dwo
11731 The section identifiers for Version 5 are:
11733 DW_SECT_INFO_V5 1 .debug_info.dwo
11734 DW_SECT_RESERVED_V5 2 --
11735 DW_SECT_ABBREV_V5 3 .debug_abbrev.dwo
11736 DW_SECT_LINE_V5 4 .debug_line.dwo
11737 DW_SECT_LOCLISTS_V5 5 .debug_loclists.dwo
11738 DW_SECT_STR_OFFSETS_V5 6 .debug_str_offsets.dwo
11739 DW_SECT_MACRO_V5 7 .debug_macro.dwo
11740 DW_SECT_RNGLISTS_V5 8 .debug_rnglists.dwo
11742 The offsets provided by the CU and TU index sections are the base offsets
11743 for the contributions made by each CU or TU to the corresponding section
11744 in the package file. Each CU and TU header contains an abbrev_offset
11745 field, used to find the abbreviations table for that CU or TU within the
11746 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11747 be interpreted as relative to the base offset given in the index section.
11748 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11749 should be interpreted as relative to the base offset for .debug_line.dwo,
11750 and offsets into other debug sections obtained from DWARF attributes should
11751 also be interpreted as relative to the corresponding base offset.
11753 The table of sizes begins immediately following the table of offsets.
11754 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11755 with L columns and N rows, in row-major order. Each row in the array is
11756 indexed starting from 1 (row 0 is shared by the two tables).
11760 Hash table lookup is handled the same in version 1 and 2:
11762 We assume that N and M will not exceed 2^32 - 1.
11763 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11765 Given a 64-bit compilation unit signature or a type signature S, an entry
11766 in the hash table is located as follows:
11768 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11769 the low-order k bits all set to 1.
11771 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11773 3) If the hash table entry at index H matches the signature, use that
11774 entry. If the hash table entry at index H is unused (all zeroes),
11775 terminate the search: the signature is not present in the table.
11777 4) Let H = (H + H') modulo M. Repeat at Step 3.
11779 Because M > N and H' and M are relatively prime, the search is guaranteed
11780 to stop at an unused slot or find the match. */
11782 /* Create a hash table to map DWO IDs to their CU/TU entry in
11783 .debug_{info,types}.dwo in DWP_FILE.
11784 Returns NULL if there isn't one.
11785 Note: This function processes DWP files only, not DWO files. */
11787 static struct dwp_hash_table
*
11788 create_dwp_hash_table (dwarf2_per_objfile
*per_objfile
,
11789 struct dwp_file
*dwp_file
, int is_debug_types
)
11791 struct objfile
*objfile
= per_objfile
->objfile
;
11792 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11793 const gdb_byte
*index_ptr
, *index_end
;
11794 struct dwarf2_section_info
*index
;
11795 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11796 struct dwp_hash_table
*htab
;
11798 if (is_debug_types
)
11799 index
= &dwp_file
->sections
.tu_index
;
11801 index
= &dwp_file
->sections
.cu_index
;
11803 if (index
->empty ())
11805 index
->read (objfile
);
11807 index_ptr
= index
->buffer
;
11808 index_end
= index_ptr
+ index
->size
;
11810 /* For Version 5, the version is really 2 bytes of data & 2 bytes of padding.
11811 For now it's safe to just read 4 bytes (particularly as it's difficult to
11812 tell if you're dealing with Version 5 before you've read the version). */
11813 version
= read_4_bytes (dbfd
, index_ptr
);
11815 if (version
== 2 || version
== 5)
11816 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11820 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11822 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11825 if (version
!= 1 && version
!= 2 && version
!= 5)
11827 error (_("Dwarf Error: unsupported DWP file version (%s)"
11828 " [in module %s]"),
11829 pulongest (version
), dwp_file
->name
);
11831 if (nr_slots
!= (nr_slots
& -nr_slots
))
11833 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11834 " is not power of 2 [in module %s]"),
11835 pulongest (nr_slots
), dwp_file
->name
);
11838 htab
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwp_hash_table
);
11839 htab
->version
= version
;
11840 htab
->nr_columns
= nr_columns
;
11841 htab
->nr_units
= nr_units
;
11842 htab
->nr_slots
= nr_slots
;
11843 htab
->hash_table
= index_ptr
;
11844 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11846 /* Exit early if the table is empty. */
11847 if (nr_slots
== 0 || nr_units
== 0
11848 || (version
== 2 && nr_columns
== 0)
11849 || (version
== 5 && nr_columns
== 0))
11851 /* All must be zero. */
11852 if (nr_slots
!= 0 || nr_units
!= 0
11853 || (version
== 2 && nr_columns
!= 0)
11854 || (version
== 5 && nr_columns
!= 0))
11856 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11857 " all zero [in modules %s]"),
11865 htab
->section_pool
.v1
.indices
=
11866 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11867 /* It's harder to decide whether the section is too small in v1.
11868 V1 is deprecated anyway so we punt. */
11870 else if (version
== 2)
11872 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11873 int *ids
= htab
->section_pool
.v2
.section_ids
;
11874 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11875 /* Reverse map for error checking. */
11876 int ids_seen
[DW_SECT_MAX
+ 1];
11879 if (nr_columns
< 2)
11881 error (_("Dwarf Error: bad DWP hash table, too few columns"
11882 " in section table [in module %s]"),
11885 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11887 error (_("Dwarf Error: bad DWP hash table, too many columns"
11888 " in section table [in module %s]"),
11891 memset (ids
, 255, sizeof_ids
);
11892 memset (ids_seen
, 255, sizeof (ids_seen
));
11893 for (i
= 0; i
< nr_columns
; ++i
)
11895 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11897 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11899 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11900 " in section table [in module %s]"),
11901 id
, dwp_file
->name
);
11903 if (ids_seen
[id
] != -1)
11905 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11906 " id %d in section table [in module %s]"),
11907 id
, dwp_file
->name
);
11912 /* Must have exactly one info or types section. */
11913 if (((ids_seen
[DW_SECT_INFO
] != -1)
11914 + (ids_seen
[DW_SECT_TYPES
] != -1))
11917 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11918 " DWO info/types section [in module %s]"),
11921 /* Must have an abbrev section. */
11922 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11924 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11925 " section [in module %s]"),
11928 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11929 htab
->section_pool
.v2
.sizes
=
11930 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11931 * nr_units
* nr_columns
);
11932 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11933 * nr_units
* nr_columns
))
11936 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11937 " [in module %s]"),
11941 else /* version == 5 */
11943 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11944 int *ids
= htab
->section_pool
.v5
.section_ids
;
11945 size_t sizeof_ids
= sizeof (htab
->section_pool
.v5
.section_ids
);
11946 /* Reverse map for error checking. */
11947 int ids_seen
[DW_SECT_MAX_V5
+ 1];
11949 if (nr_columns
< 2)
11951 error (_("Dwarf Error: bad DWP hash table, too few columns"
11952 " in section table [in module %s]"),
11955 if (nr_columns
> MAX_NR_V5_DWO_SECTIONS
)
11957 error (_("Dwarf Error: bad DWP hash table, too many columns"
11958 " in section table [in module %s]"),
11961 memset (ids
, 255, sizeof_ids
);
11962 memset (ids_seen
, 255, sizeof (ids_seen
));
11963 for (int i
= 0; i
< nr_columns
; ++i
)
11965 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11967 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX_V5
)
11969 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11970 " in section table [in module %s]"),
11971 id
, dwp_file
->name
);
11973 if (ids_seen
[id
] != -1)
11975 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11976 " id %d in section table [in module %s]"),
11977 id
, dwp_file
->name
);
11982 /* Must have seen an info section. */
11983 if (ids_seen
[DW_SECT_INFO_V5
] == -1)
11985 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11986 " DWO info/types section [in module %s]"),
11989 /* Must have an abbrev section. */
11990 if (ids_seen
[DW_SECT_ABBREV_V5
] == -1)
11992 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11993 " section [in module %s]"),
11996 htab
->section_pool
.v5
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11997 htab
->section_pool
.v5
.sizes
11998 = htab
->section_pool
.v5
.offsets
+ (sizeof (uint32_t)
11999 * nr_units
* nr_columns
);
12000 if ((htab
->section_pool
.v5
.sizes
+ (sizeof (uint32_t)
12001 * nr_units
* nr_columns
))
12004 error (_("Dwarf Error: DWP index section is corrupt (too small)"
12005 " [in module %s]"),
12013 /* Update SECTIONS with the data from SECTP.
12015 This function is like the other "locate" section routines, but in
12016 this context the sections to read comes from the DWP V1 hash table,
12017 not the full ELF section table.
12019 The result is non-zero for success, or zero if an error was found. */
12022 locate_v1_virtual_dwo_sections (asection
*sectp
,
12023 struct virtual_v1_dwo_sections
*sections
)
12025 const struct dwop_section_names
*names
= &dwop_section_names
;
12027 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12029 /* There can be only one. */
12030 if (sections
->abbrev
.s
.section
!= NULL
)
12032 sections
->abbrev
.s
.section
= sectp
;
12033 sections
->abbrev
.size
= bfd_section_size (sectp
);
12035 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
12036 || section_is_p (sectp
->name
, &names
->types_dwo
))
12038 /* There can be only one. */
12039 if (sections
->info_or_types
.s
.section
!= NULL
)
12041 sections
->info_or_types
.s
.section
= sectp
;
12042 sections
->info_or_types
.size
= bfd_section_size (sectp
);
12044 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12046 /* There can be only one. */
12047 if (sections
->line
.s
.section
!= NULL
)
12049 sections
->line
.s
.section
= sectp
;
12050 sections
->line
.size
= bfd_section_size (sectp
);
12052 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12054 /* There can be only one. */
12055 if (sections
->loc
.s
.section
!= NULL
)
12057 sections
->loc
.s
.section
= sectp
;
12058 sections
->loc
.size
= bfd_section_size (sectp
);
12060 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12062 /* There can be only one. */
12063 if (sections
->macinfo
.s
.section
!= NULL
)
12065 sections
->macinfo
.s
.section
= sectp
;
12066 sections
->macinfo
.size
= bfd_section_size (sectp
);
12068 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12070 /* There can be only one. */
12071 if (sections
->macro
.s
.section
!= NULL
)
12073 sections
->macro
.s
.section
= sectp
;
12074 sections
->macro
.size
= bfd_section_size (sectp
);
12076 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12078 /* There can be only one. */
12079 if (sections
->str_offsets
.s
.section
!= NULL
)
12081 sections
->str_offsets
.s
.section
= sectp
;
12082 sections
->str_offsets
.size
= bfd_section_size (sectp
);
12086 /* No other kind of section is valid. */
12093 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12094 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12095 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12096 This is for DWP version 1 files. */
12098 static struct dwo_unit
*
12099 create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
*per_objfile
,
12100 struct dwp_file
*dwp_file
,
12101 uint32_t unit_index
,
12102 const char *comp_dir
,
12103 ULONGEST signature
, int is_debug_types
)
12105 const struct dwp_hash_table
*dwp_htab
=
12106 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12107 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12108 const char *kind
= is_debug_types
? "TU" : "CU";
12109 struct dwo_file
*dwo_file
;
12110 struct dwo_unit
*dwo_unit
;
12111 struct virtual_v1_dwo_sections sections
;
12112 void **dwo_file_slot
;
12115 gdb_assert (dwp_file
->version
== 1);
12117 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V1 file: %s",
12118 kind
, pulongest (unit_index
), hex_string (signature
),
12121 /* Fetch the sections of this DWO unit.
12122 Put a limit on the number of sections we look for so that bad data
12123 doesn't cause us to loop forever. */
12125 #define MAX_NR_V1_DWO_SECTIONS \
12126 (1 /* .debug_info or .debug_types */ \
12127 + 1 /* .debug_abbrev */ \
12128 + 1 /* .debug_line */ \
12129 + 1 /* .debug_loc */ \
12130 + 1 /* .debug_str_offsets */ \
12131 + 1 /* .debug_macro or .debug_macinfo */ \
12132 + 1 /* trailing zero */)
12134 memset (§ions
, 0, sizeof (sections
));
12136 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
12139 uint32_t section_nr
=
12140 read_4_bytes (dbfd
,
12141 dwp_htab
->section_pool
.v1
.indices
12142 + (unit_index
+ i
) * sizeof (uint32_t));
12144 if (section_nr
== 0)
12146 if (section_nr
>= dwp_file
->num_sections
)
12148 error (_("Dwarf Error: bad DWP hash table, section number too large"
12149 " [in module %s]"),
12153 sectp
= dwp_file
->elf_sections
[section_nr
];
12154 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
12156 error (_("Dwarf Error: bad DWP hash table, invalid section found"
12157 " [in module %s]"),
12163 || sections
.info_or_types
.empty ()
12164 || sections
.abbrev
.empty ())
12166 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
12167 " [in module %s]"),
12170 if (i
== MAX_NR_V1_DWO_SECTIONS
)
12172 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
12173 " [in module %s]"),
12177 /* It's easier for the rest of the code if we fake a struct dwo_file and
12178 have dwo_unit "live" in that. At least for now.
12180 The DWP file can be made up of a random collection of CUs and TUs.
12181 However, for each CU + set of TUs that came from the same original DWO
12182 file, we can combine them back into a virtual DWO file to save space
12183 (fewer struct dwo_file objects to allocate). Remember that for really
12184 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12186 std::string virtual_dwo_name
=
12187 string_printf ("virtual-dwo/%d-%d-%d-%d",
12188 sections
.abbrev
.get_id (),
12189 sections
.line
.get_id (),
12190 sections
.loc
.get_id (),
12191 sections
.str_offsets
.get_id ());
12192 /* Can we use an existing virtual DWO file? */
12193 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
12195 /* Create one if necessary. */
12196 if (*dwo_file_slot
== NULL
)
12198 dwarf_read_debug_printf ("Creating virtual DWO: %s",
12199 virtual_dwo_name
.c_str ());
12201 dwo_file
= new struct dwo_file
;
12202 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
12203 dwo_file
->comp_dir
= comp_dir
;
12204 dwo_file
->sections
.abbrev
= sections
.abbrev
;
12205 dwo_file
->sections
.line
= sections
.line
;
12206 dwo_file
->sections
.loc
= sections
.loc
;
12207 dwo_file
->sections
.macinfo
= sections
.macinfo
;
12208 dwo_file
->sections
.macro
= sections
.macro
;
12209 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
12210 /* The "str" section is global to the entire DWP file. */
12211 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12212 /* The info or types section is assigned below to dwo_unit,
12213 there's no need to record it in dwo_file.
12214 Also, we can't simply record type sections in dwo_file because
12215 we record a pointer into the vector in dwo_unit. As we collect more
12216 types we'll grow the vector and eventually have to reallocate space
12217 for it, invalidating all copies of pointers into the previous
12219 *dwo_file_slot
= dwo_file
;
12223 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
12224 virtual_dwo_name
.c_str ());
12226 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12229 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12230 dwo_unit
->dwo_file
= dwo_file
;
12231 dwo_unit
->signature
= signature
;
12232 dwo_unit
->section
=
12233 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12234 *dwo_unit
->section
= sections
.info_or_types
;
12235 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12240 /* Subroutine of create_dwo_unit_in_dwp_v2 and create_dwo_unit_in_dwp_v5 to
12241 simplify them. Given a pointer to the containing section SECTION, and
12242 OFFSET,SIZE of the piece within that section used by a TU/CU, return a
12243 virtual section of just that piece. */
12245 static struct dwarf2_section_info
12246 create_dwp_v2_or_v5_section (dwarf2_per_objfile
*per_objfile
,
12247 struct dwarf2_section_info
*section
,
12248 bfd_size_type offset
, bfd_size_type size
)
12250 struct dwarf2_section_info result
;
12253 gdb_assert (section
!= NULL
);
12254 gdb_assert (!section
->is_virtual
);
12256 memset (&result
, 0, sizeof (result
));
12257 result
.s
.containing_section
= section
;
12258 result
.is_virtual
= true;
12263 sectp
= section
->get_bfd_section ();
12265 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
12266 bounds of the real section. This is a pretty-rare event, so just
12267 flag an error (easier) instead of a warning and trying to cope. */
12269 || offset
+ size
> bfd_section_size (sectp
))
12271 error (_("Dwarf Error: Bad DWP V2 or V5 section info, doesn't fit"
12272 " in section %s [in module %s]"),
12273 sectp
? bfd_section_name (sectp
) : "<unknown>",
12274 objfile_name (per_objfile
->objfile
));
12277 result
.virtual_offset
= offset
;
12278 result
.size
= size
;
12282 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12283 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12284 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12285 This is for DWP version 2 files. */
12287 static struct dwo_unit
*
12288 create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
*per_objfile
,
12289 struct dwp_file
*dwp_file
,
12290 uint32_t unit_index
,
12291 const char *comp_dir
,
12292 ULONGEST signature
, int is_debug_types
)
12294 const struct dwp_hash_table
*dwp_htab
=
12295 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12296 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12297 const char *kind
= is_debug_types
? "TU" : "CU";
12298 struct dwo_file
*dwo_file
;
12299 struct dwo_unit
*dwo_unit
;
12300 struct virtual_v2_or_v5_dwo_sections sections
;
12301 void **dwo_file_slot
;
12304 gdb_assert (dwp_file
->version
== 2);
12306 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V2 file: %s",
12307 kind
, pulongest (unit_index
), hex_string (signature
),
12310 /* Fetch the section offsets of this DWO unit. */
12312 memset (§ions
, 0, sizeof (sections
));
12314 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12316 uint32_t offset
= read_4_bytes (dbfd
,
12317 dwp_htab
->section_pool
.v2
.offsets
12318 + (((unit_index
- 1) * dwp_htab
->nr_columns
12320 * sizeof (uint32_t)));
12321 uint32_t size
= read_4_bytes (dbfd
,
12322 dwp_htab
->section_pool
.v2
.sizes
12323 + (((unit_index
- 1) * dwp_htab
->nr_columns
12325 * sizeof (uint32_t)));
12327 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
12330 case DW_SECT_TYPES
:
12331 sections
.info_or_types_offset
= offset
;
12332 sections
.info_or_types_size
= size
;
12334 case DW_SECT_ABBREV
:
12335 sections
.abbrev_offset
= offset
;
12336 sections
.abbrev_size
= size
;
12339 sections
.line_offset
= offset
;
12340 sections
.line_size
= size
;
12343 sections
.loc_offset
= offset
;
12344 sections
.loc_size
= size
;
12346 case DW_SECT_STR_OFFSETS
:
12347 sections
.str_offsets_offset
= offset
;
12348 sections
.str_offsets_size
= size
;
12350 case DW_SECT_MACINFO
:
12351 sections
.macinfo_offset
= offset
;
12352 sections
.macinfo_size
= size
;
12354 case DW_SECT_MACRO
:
12355 sections
.macro_offset
= offset
;
12356 sections
.macro_size
= size
;
12361 /* It's easier for the rest of the code if we fake a struct dwo_file and
12362 have dwo_unit "live" in that. At least for now.
12364 The DWP file can be made up of a random collection of CUs and TUs.
12365 However, for each CU + set of TUs that came from the same original DWO
12366 file, we can combine them back into a virtual DWO file to save space
12367 (fewer struct dwo_file objects to allocate). Remember that for really
12368 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12370 std::string virtual_dwo_name
=
12371 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
12372 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12373 (long) (sections
.line_size
? sections
.line_offset
: 0),
12374 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
12375 (long) (sections
.str_offsets_size
12376 ? sections
.str_offsets_offset
: 0));
12377 /* Can we use an existing virtual DWO file? */
12378 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
12380 /* Create one if necessary. */
12381 if (*dwo_file_slot
== NULL
)
12383 dwarf_read_debug_printf ("Creating virtual DWO: %s",
12384 virtual_dwo_name
.c_str ());
12386 dwo_file
= new struct dwo_file
;
12387 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
12388 dwo_file
->comp_dir
= comp_dir
;
12389 dwo_file
->sections
.abbrev
=
12390 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.abbrev
,
12391 sections
.abbrev_offset
,
12392 sections
.abbrev_size
);
12393 dwo_file
->sections
.line
=
12394 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.line
,
12395 sections
.line_offset
,
12396 sections
.line_size
);
12397 dwo_file
->sections
.loc
=
12398 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.loc
,
12399 sections
.loc_offset
, sections
.loc_size
);
12400 dwo_file
->sections
.macinfo
=
12401 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.macinfo
,
12402 sections
.macinfo_offset
,
12403 sections
.macinfo_size
);
12404 dwo_file
->sections
.macro
=
12405 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.macro
,
12406 sections
.macro_offset
,
12407 sections
.macro_size
);
12408 dwo_file
->sections
.str_offsets
=
12409 create_dwp_v2_or_v5_section (per_objfile
,
12410 &dwp_file
->sections
.str_offsets
,
12411 sections
.str_offsets_offset
,
12412 sections
.str_offsets_size
);
12413 /* The "str" section is global to the entire DWP file. */
12414 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12415 /* The info or types section is assigned below to dwo_unit,
12416 there's no need to record it in dwo_file.
12417 Also, we can't simply record type sections in dwo_file because
12418 we record a pointer into the vector in dwo_unit. As we collect more
12419 types we'll grow the vector and eventually have to reallocate space
12420 for it, invalidating all copies of pointers into the previous
12422 *dwo_file_slot
= dwo_file
;
12426 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
12427 virtual_dwo_name
.c_str ());
12429 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12432 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12433 dwo_unit
->dwo_file
= dwo_file
;
12434 dwo_unit
->signature
= signature
;
12435 dwo_unit
->section
=
12436 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12437 *dwo_unit
->section
= create_dwp_v2_or_v5_section
12440 ? &dwp_file
->sections
.types
12441 : &dwp_file
->sections
.info
,
12442 sections
.info_or_types_offset
,
12443 sections
.info_or_types_size
);
12444 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12449 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12450 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12451 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12452 This is for DWP version 5 files. */
12454 static struct dwo_unit
*
12455 create_dwo_unit_in_dwp_v5 (dwarf2_per_objfile
*per_objfile
,
12456 struct dwp_file
*dwp_file
,
12457 uint32_t unit_index
,
12458 const char *comp_dir
,
12459 ULONGEST signature
, int is_debug_types
)
12461 const struct dwp_hash_table
*dwp_htab
12462 = is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12463 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12464 const char *kind
= is_debug_types
? "TU" : "CU";
12465 struct dwo_file
*dwo_file
;
12466 struct dwo_unit
*dwo_unit
;
12467 struct virtual_v2_or_v5_dwo_sections sections
{};
12468 void **dwo_file_slot
;
12470 gdb_assert (dwp_file
->version
== 5);
12472 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V5 file: %s",
12473 kind
, pulongest (unit_index
), hex_string (signature
),
12476 /* Fetch the section offsets of this DWO unit. */
12478 /* memset (§ions, 0, sizeof (sections)); */
12480 for (int i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12482 uint32_t offset
= read_4_bytes (dbfd
,
12483 dwp_htab
->section_pool
.v5
.offsets
12484 + (((unit_index
- 1)
12485 * dwp_htab
->nr_columns
12487 * sizeof (uint32_t)));
12488 uint32_t size
= read_4_bytes (dbfd
,
12489 dwp_htab
->section_pool
.v5
.sizes
12490 + (((unit_index
- 1) * dwp_htab
->nr_columns
12492 * sizeof (uint32_t)));
12494 switch (dwp_htab
->section_pool
.v5
.section_ids
[i
])
12496 case DW_SECT_ABBREV_V5
:
12497 sections
.abbrev_offset
= offset
;
12498 sections
.abbrev_size
= size
;
12500 case DW_SECT_INFO_V5
:
12501 sections
.info_or_types_offset
= offset
;
12502 sections
.info_or_types_size
= size
;
12504 case DW_SECT_LINE_V5
:
12505 sections
.line_offset
= offset
;
12506 sections
.line_size
= size
;
12508 case DW_SECT_LOCLISTS_V5
:
12509 sections
.loclists_offset
= offset
;
12510 sections
.loclists_size
= size
;
12512 case DW_SECT_MACRO_V5
:
12513 sections
.macro_offset
= offset
;
12514 sections
.macro_size
= size
;
12516 case DW_SECT_RNGLISTS_V5
:
12517 sections
.rnglists_offset
= offset
;
12518 sections
.rnglists_size
= size
;
12520 case DW_SECT_STR_OFFSETS_V5
:
12521 sections
.str_offsets_offset
= offset
;
12522 sections
.str_offsets_size
= size
;
12524 case DW_SECT_RESERVED_V5
:
12530 /* It's easier for the rest of the code if we fake a struct dwo_file and
12531 have dwo_unit "live" in that. At least for now.
12533 The DWP file can be made up of a random collection of CUs and TUs.
12534 However, for each CU + set of TUs that came from the same original DWO
12535 file, we can combine them back into a virtual DWO file to save space
12536 (fewer struct dwo_file objects to allocate). Remember that for really
12537 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12539 std::string virtual_dwo_name
=
12540 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld-%ld-%ld",
12541 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12542 (long) (sections
.line_size
? sections
.line_offset
: 0),
12543 (long) (sections
.loclists_size
? sections
.loclists_offset
: 0),
12544 (long) (sections
.str_offsets_size
12545 ? sections
.str_offsets_offset
: 0),
12546 (long) (sections
.macro_size
? sections
.macro_offset
: 0),
12547 (long) (sections
.rnglists_size
? sections
.rnglists_offset
: 0));
12548 /* Can we use an existing virtual DWO file? */
12549 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
,
12550 virtual_dwo_name
.c_str (),
12552 /* Create one if necessary. */
12553 if (*dwo_file_slot
== NULL
)
12555 dwarf_read_debug_printf ("Creating virtual DWO: %s",
12556 virtual_dwo_name
.c_str ());
12558 dwo_file
= new struct dwo_file
;
12559 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
12560 dwo_file
->comp_dir
= comp_dir
;
12561 dwo_file
->sections
.abbrev
=
12562 create_dwp_v2_or_v5_section (per_objfile
,
12563 &dwp_file
->sections
.abbrev
,
12564 sections
.abbrev_offset
,
12565 sections
.abbrev_size
);
12566 dwo_file
->sections
.line
=
12567 create_dwp_v2_or_v5_section (per_objfile
,
12568 &dwp_file
->sections
.line
,
12569 sections
.line_offset
, sections
.line_size
);
12570 dwo_file
->sections
.macro
=
12571 create_dwp_v2_or_v5_section (per_objfile
,
12572 &dwp_file
->sections
.macro
,
12573 sections
.macro_offset
,
12574 sections
.macro_size
);
12575 dwo_file
->sections
.loclists
=
12576 create_dwp_v2_or_v5_section (per_objfile
,
12577 &dwp_file
->sections
.loclists
,
12578 sections
.loclists_offset
,
12579 sections
.loclists_size
);
12580 dwo_file
->sections
.rnglists
=
12581 create_dwp_v2_or_v5_section (per_objfile
,
12582 &dwp_file
->sections
.rnglists
,
12583 sections
.rnglists_offset
,
12584 sections
.rnglists_size
);
12585 dwo_file
->sections
.str_offsets
=
12586 create_dwp_v2_or_v5_section (per_objfile
,
12587 &dwp_file
->sections
.str_offsets
,
12588 sections
.str_offsets_offset
,
12589 sections
.str_offsets_size
);
12590 /* The "str" section is global to the entire DWP file. */
12591 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12592 /* The info or types section is assigned below to dwo_unit,
12593 there's no need to record it in dwo_file.
12594 Also, we can't simply record type sections in dwo_file because
12595 we record a pointer into the vector in dwo_unit. As we collect more
12596 types we'll grow the vector and eventually have to reallocate space
12597 for it, invalidating all copies of pointers into the previous
12599 *dwo_file_slot
= dwo_file
;
12603 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
12604 virtual_dwo_name
.c_str ());
12606 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12609 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12610 dwo_unit
->dwo_file
= dwo_file
;
12611 dwo_unit
->signature
= signature
;
12613 = XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12614 *dwo_unit
->section
= create_dwp_v2_or_v5_section (per_objfile
,
12615 &dwp_file
->sections
.info
,
12616 sections
.info_or_types_offset
,
12617 sections
.info_or_types_size
);
12618 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12623 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12624 Returns NULL if the signature isn't found. */
12626 static struct dwo_unit
*
12627 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
*per_objfile
,
12628 struct dwp_file
*dwp_file
, const char *comp_dir
,
12629 ULONGEST signature
, int is_debug_types
)
12631 const struct dwp_hash_table
*dwp_htab
=
12632 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12633 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12634 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12635 uint32_t hash
= signature
& mask
;
12636 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12639 struct dwo_unit find_dwo_cu
;
12641 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12642 find_dwo_cu
.signature
= signature
;
12643 slot
= htab_find_slot (is_debug_types
12644 ? dwp_file
->loaded_tus
.get ()
12645 : dwp_file
->loaded_cus
.get (),
12646 &find_dwo_cu
, INSERT
);
12649 return (struct dwo_unit
*) *slot
;
12651 /* Use a for loop so that we don't loop forever on bad debug info. */
12652 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12654 ULONGEST signature_in_table
;
12656 signature_in_table
=
12657 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12658 if (signature_in_table
== signature
)
12660 uint32_t unit_index
=
12661 read_4_bytes (dbfd
,
12662 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12664 if (dwp_file
->version
== 1)
12666 *slot
= create_dwo_unit_in_dwp_v1 (per_objfile
, dwp_file
,
12667 unit_index
, comp_dir
,
12668 signature
, is_debug_types
);
12670 else if (dwp_file
->version
== 2)
12672 *slot
= create_dwo_unit_in_dwp_v2 (per_objfile
, dwp_file
,
12673 unit_index
, comp_dir
,
12674 signature
, is_debug_types
);
12676 else /* version == 5 */
12678 *slot
= create_dwo_unit_in_dwp_v5 (per_objfile
, dwp_file
,
12679 unit_index
, comp_dir
,
12680 signature
, is_debug_types
);
12682 return (struct dwo_unit
*) *slot
;
12684 if (signature_in_table
== 0)
12686 hash
= (hash
+ hash2
) & mask
;
12689 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12690 " [in module %s]"),
12694 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12695 Open the file specified by FILE_NAME and hand it off to BFD for
12696 preliminary analysis. Return a newly initialized bfd *, which
12697 includes a canonicalized copy of FILE_NAME.
12698 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12699 SEARCH_CWD is true if the current directory is to be searched.
12700 It will be searched before debug-file-directory.
12701 If successful, the file is added to the bfd include table of the
12702 objfile's bfd (see gdb_bfd_record_inclusion).
12703 If unable to find/open the file, return NULL.
12704 NOTE: This function is derived from symfile_bfd_open. */
12706 static gdb_bfd_ref_ptr
12707 try_open_dwop_file (dwarf2_per_objfile
*per_objfile
,
12708 const char *file_name
, int is_dwp
, int search_cwd
)
12711 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12712 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12713 to debug_file_directory. */
12714 const char *search_path
;
12715 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12717 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12720 if (*debug_file_directory
!= '\0')
12722 search_path_holder
.reset (concat (".", dirname_separator_string
,
12723 debug_file_directory
,
12725 search_path
= search_path_holder
.get ();
12731 search_path
= debug_file_directory
;
12733 openp_flags flags
= OPF_RETURN_REALPATH
;
12735 flags
|= OPF_SEARCH_IN_PATH
;
12737 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12738 desc
= openp (search_path
, flags
, file_name
,
12739 O_RDONLY
| O_BINARY
, &absolute_name
);
12743 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12745 if (sym_bfd
== NULL
)
12747 bfd_set_cacheable (sym_bfd
.get (), 1);
12749 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12752 /* Success. Record the bfd as having been included by the objfile's bfd.
12753 This is important because things like demangled_names_hash lives in the
12754 objfile's per_bfd space and may have references to things like symbol
12755 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12756 gdb_bfd_record_inclusion (per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12761 /* Try to open DWO file FILE_NAME.
12762 COMP_DIR is the DW_AT_comp_dir attribute.
12763 The result is the bfd handle of the file.
12764 If there is a problem finding or opening the file, return NULL.
12765 Upon success, the canonicalized path of the file is stored in the bfd,
12766 same as symfile_bfd_open. */
12768 static gdb_bfd_ref_ptr
12769 open_dwo_file (dwarf2_per_objfile
*per_objfile
,
12770 const char *file_name
, const char *comp_dir
)
12772 if (IS_ABSOLUTE_PATH (file_name
))
12773 return try_open_dwop_file (per_objfile
, file_name
,
12774 0 /*is_dwp*/, 0 /*search_cwd*/);
12776 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12778 if (comp_dir
!= NULL
)
12780 gdb::unique_xmalloc_ptr
<char> path_to_try
12781 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12783 /* NOTE: If comp_dir is a relative path, this will also try the
12784 search path, which seems useful. */
12785 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, path_to_try
.get (),
12787 1 /*search_cwd*/));
12792 /* That didn't work, try debug-file-directory, which, despite its name,
12793 is a list of paths. */
12795 if (*debug_file_directory
== '\0')
12798 return try_open_dwop_file (per_objfile
, file_name
,
12799 0 /*is_dwp*/, 1 /*search_cwd*/);
12802 /* This function is mapped across the sections and remembers the offset and
12803 size of each of the DWO debugging sections we are interested in. */
12806 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
,
12807 dwo_sections
*dwo_sections
)
12809 const struct dwop_section_names
*names
= &dwop_section_names
;
12811 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12813 dwo_sections
->abbrev
.s
.section
= sectp
;
12814 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12816 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12818 dwo_sections
->info
.s
.section
= sectp
;
12819 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12821 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12823 dwo_sections
->line
.s
.section
= sectp
;
12824 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12826 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12828 dwo_sections
->loc
.s
.section
= sectp
;
12829 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12831 else if (section_is_p (sectp
->name
, &names
->loclists_dwo
))
12833 dwo_sections
->loclists
.s
.section
= sectp
;
12834 dwo_sections
->loclists
.size
= bfd_section_size (sectp
);
12836 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12838 dwo_sections
->macinfo
.s
.section
= sectp
;
12839 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12841 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12843 dwo_sections
->macro
.s
.section
= sectp
;
12844 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12846 else if (section_is_p (sectp
->name
, &names
->rnglists_dwo
))
12848 dwo_sections
->rnglists
.s
.section
= sectp
;
12849 dwo_sections
->rnglists
.size
= bfd_section_size (sectp
);
12851 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12853 dwo_sections
->str
.s
.section
= sectp
;
12854 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12856 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12858 dwo_sections
->str_offsets
.s
.section
= sectp
;
12859 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12861 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12863 struct dwarf2_section_info type_section
;
12865 memset (&type_section
, 0, sizeof (type_section
));
12866 type_section
.s
.section
= sectp
;
12867 type_section
.size
= bfd_section_size (sectp
);
12868 dwo_sections
->types
.push_back (type_section
);
12872 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12873 by PER_CU. This is for the non-DWP case.
12874 The result is NULL if DWO_NAME can't be found. */
12876 static struct dwo_file
*
12877 open_and_init_dwo_file (dwarf2_cu
*cu
, const char *dwo_name
,
12878 const char *comp_dir
)
12880 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
12882 gdb_bfd_ref_ptr dbfd
= open_dwo_file (per_objfile
, dwo_name
, comp_dir
);
12885 dwarf_read_debug_printf ("DWO file not found: %s", dwo_name
);
12890 dwo_file_up
dwo_file (new struct dwo_file
);
12891 dwo_file
->dwo_name
= dwo_name
;
12892 dwo_file
->comp_dir
= comp_dir
;
12893 dwo_file
->dbfd
= std::move (dbfd
);
12895 for (asection
*sec
: gdb_bfd_sections (dwo_file
->dbfd
))
12896 dwarf2_locate_dwo_sections (dwo_file
->dbfd
.get (), sec
,
12897 &dwo_file
->sections
);
12899 create_cus_hash_table (per_objfile
, cu
, *dwo_file
, dwo_file
->sections
.info
,
12902 if (cu
->per_cu
->dwarf_version
< 5)
12904 create_debug_types_hash_table (per_objfile
, dwo_file
.get (),
12905 dwo_file
->sections
.types
, dwo_file
->tus
);
12909 create_debug_type_hash_table (per_objfile
, dwo_file
.get (),
12910 &dwo_file
->sections
.info
, dwo_file
->tus
,
12914 dwarf_read_debug_printf ("DWO file found: %s", dwo_name
);
12916 return dwo_file
.release ();
12919 /* This function is mapped across the sections and remembers the offset and
12920 size of each of the DWP debugging sections common to version 1 and 2 that
12921 we are interested in. */
12924 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12925 dwp_file
*dwp_file
)
12927 const struct dwop_section_names
*names
= &dwop_section_names
;
12928 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12930 /* Record the ELF section number for later lookup: this is what the
12931 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12932 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12933 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12935 /* Look for specific sections that we need. */
12936 if (section_is_p (sectp
->name
, &names
->str_dwo
))
12938 dwp_file
->sections
.str
.s
.section
= sectp
;
12939 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12941 else if (section_is_p (sectp
->name
, &names
->cu_index
))
12943 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12944 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12946 else if (section_is_p (sectp
->name
, &names
->tu_index
))
12948 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12949 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12953 /* This function is mapped across the sections and remembers the offset and
12954 size of each of the DWP version 2 debugging sections that we are interested
12955 in. This is split into a separate function because we don't know if we
12956 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
12959 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12961 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12962 const struct dwop_section_names
*names
= &dwop_section_names
;
12963 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12965 /* Record the ELF section number for later lookup: this is what the
12966 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12967 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12968 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12970 /* Look for specific sections that we need. */
12971 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12973 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12974 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12976 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12978 dwp_file
->sections
.info
.s
.section
= sectp
;
12979 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12981 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12983 dwp_file
->sections
.line
.s
.section
= sectp
;
12984 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12986 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12988 dwp_file
->sections
.loc
.s
.section
= sectp
;
12989 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12991 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12993 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12994 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12996 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12998 dwp_file
->sections
.macro
.s
.section
= sectp
;
12999 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
13001 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
13003 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
13004 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
13006 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
13008 dwp_file
->sections
.types
.s
.section
= sectp
;
13009 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
13013 /* This function is mapped across the sections and remembers the offset and
13014 size of each of the DWP version 5 debugging sections that we are interested
13015 in. This is split into a separate function because we don't know if we
13016 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
13019 dwarf2_locate_v5_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
13021 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
13022 const struct dwop_section_names
*names
= &dwop_section_names
;
13023 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
13025 /* Record the ELF section number for later lookup: this is what the
13026 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
13027 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
13028 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
13030 /* Look for specific sections that we need. */
13031 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
13033 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
13034 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
13036 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
13038 dwp_file
->sections
.info
.s
.section
= sectp
;
13039 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
13041 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
13043 dwp_file
->sections
.line
.s
.section
= sectp
;
13044 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
13046 else if (section_is_p (sectp
->name
, &names
->loclists_dwo
))
13048 dwp_file
->sections
.loclists
.s
.section
= sectp
;
13049 dwp_file
->sections
.loclists
.size
= bfd_section_size (sectp
);
13051 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
13053 dwp_file
->sections
.macro
.s
.section
= sectp
;
13054 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
13056 else if (section_is_p (sectp
->name
, &names
->rnglists_dwo
))
13058 dwp_file
->sections
.rnglists
.s
.section
= sectp
;
13059 dwp_file
->sections
.rnglists
.size
= bfd_section_size (sectp
);
13061 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
13063 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
13064 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
13068 /* Hash function for dwp_file loaded CUs/TUs. */
13071 hash_dwp_loaded_cutus (const void *item
)
13073 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
13075 /* This drops the top 32 bits of the signature, but is ok for a hash. */
13076 return dwo_unit
->signature
;
13079 /* Equality function for dwp_file loaded CUs/TUs. */
13082 eq_dwp_loaded_cutus (const void *a
, const void *b
)
13084 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
13085 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
13087 return dua
->signature
== dub
->signature
;
13090 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
13093 allocate_dwp_loaded_cutus_table ()
13095 return htab_up (htab_create_alloc (3,
13096 hash_dwp_loaded_cutus
,
13097 eq_dwp_loaded_cutus
,
13098 NULL
, xcalloc
, xfree
));
13101 /* Try to open DWP file FILE_NAME.
13102 The result is the bfd handle of the file.
13103 If there is a problem finding or opening the file, return NULL.
13104 Upon success, the canonicalized path of the file is stored in the bfd,
13105 same as symfile_bfd_open. */
13107 static gdb_bfd_ref_ptr
13108 open_dwp_file (dwarf2_per_objfile
*per_objfile
, const char *file_name
)
13110 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, file_name
,
13112 1 /*search_cwd*/));
13116 /* Work around upstream bug 15652.
13117 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
13118 [Whether that's a "bug" is debatable, but it is getting in our way.]
13119 We have no real idea where the dwp file is, because gdb's realpath-ing
13120 of the executable's path may have discarded the needed info.
13121 [IWBN if the dwp file name was recorded in the executable, akin to
13122 .gnu_debuglink, but that doesn't exist yet.]
13123 Strip the directory from FILE_NAME and search again. */
13124 if (*debug_file_directory
!= '\0')
13126 /* Don't implicitly search the current directory here.
13127 If the user wants to search "." to handle this case,
13128 it must be added to debug-file-directory. */
13129 return try_open_dwop_file (per_objfile
, lbasename (file_name
),
13137 /* Initialize the use of the DWP file for the current objfile.
13138 By convention the name of the DWP file is ${objfile}.dwp.
13139 The result is NULL if it can't be found. */
13141 static std::unique_ptr
<struct dwp_file
>
13142 open_and_init_dwp_file (dwarf2_per_objfile
*per_objfile
)
13144 struct objfile
*objfile
= per_objfile
->objfile
;
13146 /* Try to find first .dwp for the binary file before any symbolic links
13149 /* If the objfile is a debug file, find the name of the real binary
13150 file and get the name of dwp file from there. */
13151 std::string dwp_name
;
13152 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
13154 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
13155 const char *backlink_basename
= lbasename (backlink
->original_name
);
13157 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
13160 dwp_name
= objfile
->original_name
;
13162 dwp_name
+= ".dwp";
13164 gdb_bfd_ref_ptr
dbfd (open_dwp_file (per_objfile
, dwp_name
.c_str ()));
13166 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
13168 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
13169 dwp_name
= objfile_name (objfile
);
13170 dwp_name
+= ".dwp";
13171 dbfd
= open_dwp_file (per_objfile
, dwp_name
.c_str ());
13176 dwarf_read_debug_printf ("DWP file not found: %s", dwp_name
.c_str ());
13178 return std::unique_ptr
<dwp_file
> ();
13181 const char *name
= bfd_get_filename (dbfd
.get ());
13182 std::unique_ptr
<struct dwp_file
> dwp_file
13183 (new struct dwp_file (name
, std::move (dbfd
)));
13185 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
13186 dwp_file
->elf_sections
=
13187 OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
13188 dwp_file
->num_sections
, asection
*);
13190 for (asection
*sec
: gdb_bfd_sections (dwp_file
->dbfd
))
13191 dwarf2_locate_common_dwp_sections (dwp_file
->dbfd
.get (), sec
,
13194 dwp_file
->cus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 0);
13196 dwp_file
->tus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 1);
13198 /* The DWP file version is stored in the hash table. Oh well. */
13199 if (dwp_file
->cus
&& dwp_file
->tus
13200 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
13202 /* Technically speaking, we should try to limp along, but this is
13203 pretty bizarre. We use pulongest here because that's the established
13204 portability solution (e.g, we cannot use %u for uint32_t). */
13205 error (_("Dwarf Error: DWP file CU version %s doesn't match"
13206 " TU version %s [in DWP file %s]"),
13207 pulongest (dwp_file
->cus
->version
),
13208 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
13212 dwp_file
->version
= dwp_file
->cus
->version
;
13213 else if (dwp_file
->tus
)
13214 dwp_file
->version
= dwp_file
->tus
->version
;
13216 dwp_file
->version
= 2;
13218 for (asection
*sec
: gdb_bfd_sections (dwp_file
->dbfd
))
13220 if (dwp_file
->version
== 2)
13221 dwarf2_locate_v2_dwp_sections (dwp_file
->dbfd
.get (), sec
,
13224 dwarf2_locate_v5_dwp_sections (dwp_file
->dbfd
.get (), sec
,
13228 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
13229 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
13231 dwarf_read_debug_printf ("DWP file found: %s", dwp_file
->name
);
13232 dwarf_read_debug_printf (" %s CUs, %s TUs",
13233 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
13234 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
13239 /* Wrapper around open_and_init_dwp_file, only open it once. */
13241 static struct dwp_file
*
13242 get_dwp_file (dwarf2_per_objfile
*per_objfile
)
13244 if (!per_objfile
->per_bfd
->dwp_checked
)
13246 per_objfile
->per_bfd
->dwp_file
= open_and_init_dwp_file (per_objfile
);
13247 per_objfile
->per_bfd
->dwp_checked
= 1;
13249 return per_objfile
->per_bfd
->dwp_file
.get ();
13252 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
13253 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
13254 or in the DWP file for the objfile, referenced by THIS_UNIT.
13255 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
13256 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
13258 This is called, for example, when wanting to read a variable with a
13259 complex location. Therefore we don't want to do file i/o for every call.
13260 Therefore we don't want to look for a DWO file on every call.
13261 Therefore we first see if we've already seen SIGNATURE in a DWP file,
13262 then we check if we've already seen DWO_NAME, and only THEN do we check
13265 The result is a pointer to the dwo_unit object or NULL if we didn't find it
13266 (dwo_id mismatch or couldn't find the DWO/DWP file). */
13268 static struct dwo_unit
*
13269 lookup_dwo_cutu (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
13270 ULONGEST signature
, int is_debug_types
)
13272 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13273 struct objfile
*objfile
= per_objfile
->objfile
;
13274 const char *kind
= is_debug_types
? "TU" : "CU";
13275 void **dwo_file_slot
;
13276 struct dwo_file
*dwo_file
;
13277 struct dwp_file
*dwp_file
;
13279 /* First see if there's a DWP file.
13280 If we have a DWP file but didn't find the DWO inside it, don't
13281 look for the original DWO file. It makes gdb behave differently
13282 depending on whether one is debugging in the build tree. */
13284 dwp_file
= get_dwp_file (per_objfile
);
13285 if (dwp_file
!= NULL
)
13287 const struct dwp_hash_table
*dwp_htab
=
13288 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
13290 if (dwp_htab
!= NULL
)
13292 struct dwo_unit
*dwo_cutu
=
13293 lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, comp_dir
, signature
,
13296 if (dwo_cutu
!= NULL
)
13298 dwarf_read_debug_printf ("Virtual DWO %s %s found: @%s",
13299 kind
, hex_string (signature
),
13300 host_address_to_string (dwo_cutu
));
13308 /* No DWP file, look for the DWO file. */
13310 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, dwo_name
, comp_dir
);
13311 if (*dwo_file_slot
== NULL
)
13313 /* Read in the file and build a table of the CUs/TUs it contains. */
13314 *dwo_file_slot
= open_and_init_dwo_file (cu
, dwo_name
, comp_dir
);
13316 /* NOTE: This will be NULL if unable to open the file. */
13317 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
13319 if (dwo_file
!= NULL
)
13321 struct dwo_unit
*dwo_cutu
= NULL
;
13323 if (is_debug_types
&& dwo_file
->tus
)
13325 struct dwo_unit find_dwo_cutu
;
13327 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13328 find_dwo_cutu
.signature
= signature
;
13330 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
13333 else if (!is_debug_types
&& dwo_file
->cus
)
13335 struct dwo_unit find_dwo_cutu
;
13337 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13338 find_dwo_cutu
.signature
= signature
;
13339 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
13343 if (dwo_cutu
!= NULL
)
13345 dwarf_read_debug_printf ("DWO %s %s(%s) found: @%s",
13346 kind
, dwo_name
, hex_string (signature
),
13347 host_address_to_string (dwo_cutu
));
13354 /* We didn't find it. This could mean a dwo_id mismatch, or
13355 someone deleted the DWO/DWP file, or the search path isn't set up
13356 correctly to find the file. */
13358 dwarf_read_debug_printf ("DWO %s %s(%s) not found",
13359 kind
, dwo_name
, hex_string (signature
));
13361 /* This is a warning and not a complaint because it can be caused by
13362 pilot error (e.g., user accidentally deleting the DWO). */
13364 /* Print the name of the DWP file if we looked there, helps the user
13365 better diagnose the problem. */
13366 std::string dwp_text
;
13368 if (dwp_file
!= NULL
)
13369 dwp_text
= string_printf (" [in DWP file %s]",
13370 lbasename (dwp_file
->name
));
13372 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
13373 " [in module %s]"),
13374 kind
, dwo_name
, hex_string (signature
), dwp_text
.c_str (), kind
,
13375 sect_offset_str (cu
->per_cu
->sect_off
), objfile_name (objfile
));
13380 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
13381 See lookup_dwo_cutu_unit for details. */
13383 static struct dwo_unit
*
13384 lookup_dwo_comp_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
13385 ULONGEST signature
)
13387 gdb_assert (!cu
->per_cu
->is_debug_types
);
13389 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, signature
, 0);
13392 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
13393 See lookup_dwo_cutu_unit for details. */
13395 static struct dwo_unit
*
13396 lookup_dwo_type_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
)
13398 gdb_assert (cu
->per_cu
->is_debug_types
);
13400 signatured_type
*sig_type
= (signatured_type
*) cu
->per_cu
;
13402 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, sig_type
->signature
, 1);
13405 /* Traversal function for queue_and_load_all_dwo_tus. */
13408 queue_and_load_dwo_tu (void **slot
, void *info
)
13410 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
13411 dwarf2_cu
*cu
= (dwarf2_cu
*) info
;
13412 ULONGEST signature
= dwo_unit
->signature
;
13413 signatured_type
*sig_type
= lookup_dwo_signatured_type (cu
, signature
);
13415 if (sig_type
!= NULL
)
13417 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
13419 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
13420 a real dependency of PER_CU on SIG_TYPE. That is detected later
13421 while processing PER_CU. */
13422 if (maybe_queue_comp_unit (NULL
, sig_cu
, cu
->per_objfile
, cu
->language
))
13423 load_full_type_unit (sig_cu
, cu
->per_objfile
);
13424 cu
->per_cu
->imported_symtabs_push (sig_cu
);
13430 /* Queue all TUs contained in the DWO of CU to be read in.
13431 The DWO may have the only definition of the type, though it may not be
13432 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
13433 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
13436 queue_and_load_all_dwo_tus (dwarf2_cu
*cu
)
13438 struct dwo_unit
*dwo_unit
;
13439 struct dwo_file
*dwo_file
;
13441 gdb_assert (cu
!= nullptr);
13442 gdb_assert (!cu
->per_cu
->is_debug_types
);
13443 gdb_assert (get_dwp_file (cu
->per_objfile
) == nullptr);
13445 dwo_unit
= cu
->dwo_unit
;
13446 gdb_assert (dwo_unit
!= NULL
);
13448 dwo_file
= dwo_unit
->dwo_file
;
13449 if (dwo_file
->tus
!= NULL
)
13450 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
, cu
);
13453 /* Read in various DIEs. */
13455 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
13456 Inherit only the children of the DW_AT_abstract_origin DIE not being
13457 already referenced by DW_AT_abstract_origin from the children of the
13461 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
13463 struct die_info
*child_die
;
13464 sect_offset
*offsetp
;
13465 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
13466 struct die_info
*origin_die
;
13467 /* Iterator of the ORIGIN_DIE children. */
13468 struct die_info
*origin_child_die
;
13469 struct attribute
*attr
;
13470 struct dwarf2_cu
*origin_cu
;
13471 struct pending
**origin_previous_list_in_scope
;
13473 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13477 /* Note that following die references may follow to a die in a
13481 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
13483 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
13485 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
13486 origin_cu
->list_in_scope
= cu
->list_in_scope
;
13488 if (die
->tag
!= origin_die
->tag
13489 && !(die
->tag
== DW_TAG_inlined_subroutine
13490 && origin_die
->tag
== DW_TAG_subprogram
))
13491 complaint (_("DIE %s and its abstract origin %s have different tags"),
13492 sect_offset_str (die
->sect_off
),
13493 sect_offset_str (origin_die
->sect_off
));
13495 std::vector
<sect_offset
> offsets
;
13497 for (child_die
= die
->child
;
13498 child_die
&& child_die
->tag
;
13499 child_die
= child_die
->sibling
)
13501 struct die_info
*child_origin_die
;
13502 struct dwarf2_cu
*child_origin_cu
;
13504 /* We are trying to process concrete instance entries:
13505 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
13506 it's not relevant to our analysis here. i.e. detecting DIEs that are
13507 present in the abstract instance but not referenced in the concrete
13509 if (child_die
->tag
== DW_TAG_call_site
13510 || child_die
->tag
== DW_TAG_GNU_call_site
)
13513 /* For each CHILD_DIE, find the corresponding child of
13514 ORIGIN_DIE. If there is more than one layer of
13515 DW_AT_abstract_origin, follow them all; there shouldn't be,
13516 but GCC versions at least through 4.4 generate this (GCC PR
13518 child_origin_die
= child_die
;
13519 child_origin_cu
= cu
;
13522 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
13526 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
13530 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
13531 counterpart may exist. */
13532 if (child_origin_die
!= child_die
)
13534 if (child_die
->tag
!= child_origin_die
->tag
13535 && !(child_die
->tag
== DW_TAG_inlined_subroutine
13536 && child_origin_die
->tag
== DW_TAG_subprogram
))
13537 complaint (_("Child DIE %s and its abstract origin %s have "
13539 sect_offset_str (child_die
->sect_off
),
13540 sect_offset_str (child_origin_die
->sect_off
));
13541 if (child_origin_die
->parent
!= origin_die
)
13542 complaint (_("Child DIE %s and its abstract origin %s have "
13543 "different parents"),
13544 sect_offset_str (child_die
->sect_off
),
13545 sect_offset_str (child_origin_die
->sect_off
));
13547 offsets
.push_back (child_origin_die
->sect_off
);
13550 std::sort (offsets
.begin (), offsets
.end ());
13551 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
13552 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
13553 if (offsetp
[-1] == *offsetp
)
13554 complaint (_("Multiple children of DIE %s refer "
13555 "to DIE %s as their abstract origin"),
13556 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
13558 offsetp
= offsets
.data ();
13559 origin_child_die
= origin_die
->child
;
13560 while (origin_child_die
&& origin_child_die
->tag
)
13562 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13563 while (offsetp
< offsets_end
13564 && *offsetp
< origin_child_die
->sect_off
)
13566 if (offsetp
>= offsets_end
13567 || *offsetp
> origin_child_die
->sect_off
)
13569 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13570 Check whether we're already processing ORIGIN_CHILD_DIE.
13571 This can happen with mutually referenced abstract_origins.
13573 if (!origin_child_die
->in_process
)
13574 process_die (origin_child_die
, origin_cu
);
13576 origin_child_die
= origin_child_die
->sibling
;
13578 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13580 if (cu
!= origin_cu
)
13581 compute_delayed_physnames (origin_cu
);
13585 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13587 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13588 struct gdbarch
*gdbarch
= objfile
->arch ();
13589 struct context_stack
*newobj
;
13592 struct die_info
*child_die
;
13593 struct attribute
*attr
, *call_line
, *call_file
;
13595 CORE_ADDR baseaddr
;
13596 struct block
*block
;
13597 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13598 std::vector
<struct symbol
*> template_args
;
13599 struct template_symbol
*templ_func
= NULL
;
13603 /* If we do not have call site information, we can't show the
13604 caller of this inlined function. That's too confusing, so
13605 only use the scope for local variables. */
13606 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13607 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13608 if (call_line
== NULL
|| call_file
== NULL
)
13610 read_lexical_block_scope (die
, cu
);
13615 baseaddr
= objfile
->text_section_offset ();
13617 name
= dwarf2_name (die
, cu
);
13619 /* Ignore functions with missing or empty names. These are actually
13620 illegal according to the DWARF standard. */
13623 complaint (_("missing name for subprogram DIE at %s"),
13624 sect_offset_str (die
->sect_off
));
13628 /* Ignore functions with missing or invalid low and high pc attributes. */
13629 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13630 <= PC_BOUNDS_INVALID
)
13632 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13633 if (attr
== nullptr || !attr
->as_boolean ())
13634 complaint (_("cannot get low and high bounds "
13635 "for subprogram DIE at %s"),
13636 sect_offset_str (die
->sect_off
));
13640 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13641 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13643 /* If we have any template arguments, then we must allocate a
13644 different sort of symbol. */
13645 for (child_die
= die
->child
; child_die
; child_die
= child_die
->sibling
)
13647 if (child_die
->tag
== DW_TAG_template_type_param
13648 || child_die
->tag
== DW_TAG_template_value_param
)
13650 templ_func
= new (&objfile
->objfile_obstack
) template_symbol
;
13651 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13656 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13657 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13658 (struct symbol
*) templ_func
);
13660 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13661 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
13664 /* If there is a location expression for DW_AT_frame_base, record
13666 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13667 if (attr
!= nullptr)
13668 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13670 /* If there is a location for the static link, record it. */
13671 newobj
->static_link
= NULL
;
13672 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13673 if (attr
!= nullptr)
13675 newobj
->static_link
13676 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13677 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13681 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13683 if (die
->child
!= NULL
)
13685 child_die
= die
->child
;
13686 while (child_die
&& child_die
->tag
)
13688 if (child_die
->tag
== DW_TAG_template_type_param
13689 || child_die
->tag
== DW_TAG_template_value_param
)
13691 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13694 template_args
.push_back (arg
);
13697 process_die (child_die
, cu
);
13698 child_die
= child_die
->sibling
;
13702 inherit_abstract_dies (die
, cu
);
13704 /* If we have a DW_AT_specification, we might need to import using
13705 directives from the context of the specification DIE. See the
13706 comment in determine_prefix. */
13707 if (cu
->language
== language_cplus
13708 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13710 struct dwarf2_cu
*spec_cu
= cu
;
13711 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13715 child_die
= spec_die
->child
;
13716 while (child_die
&& child_die
->tag
)
13718 if (child_die
->tag
== DW_TAG_imported_module
)
13719 process_die (child_die
, spec_cu
);
13720 child_die
= child_die
->sibling
;
13723 /* In some cases, GCC generates specification DIEs that
13724 themselves contain DW_AT_specification attributes. */
13725 spec_die
= die_specification (spec_die
, &spec_cu
);
13729 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13730 /* Make a block for the local symbols within. */
13731 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13732 cstk
.static_link
, lowpc
, highpc
);
13734 /* For C++, set the block's scope. */
13735 if ((cu
->language
== language_cplus
13736 || cu
->language
== language_fortran
13737 || cu
->language
== language_d
13738 || cu
->language
== language_rust
)
13739 && cu
->processing_has_namespace_info
)
13740 block_set_scope (block
, determine_prefix (die
, cu
),
13741 &objfile
->objfile_obstack
);
13743 /* If we have address ranges, record them. */
13744 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13746 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13748 /* Attach template arguments to function. */
13749 if (!template_args
.empty ())
13751 gdb_assert (templ_func
!= NULL
);
13753 templ_func
->n_template_arguments
= template_args
.size ();
13754 templ_func
->template_arguments
13755 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13756 templ_func
->n_template_arguments
);
13757 memcpy (templ_func
->template_arguments
,
13758 template_args
.data (),
13759 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13761 /* Make sure that the symtab is set on the new symbols. Even
13762 though they don't appear in this symtab directly, other parts
13763 of gdb assume that symbols do, and this is reasonably
13765 for (symbol
*sym
: template_args
)
13766 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13769 /* In C++, we can have functions nested inside functions (e.g., when
13770 a function declares a class that has methods). This means that
13771 when we finish processing a function scope, we may need to go
13772 back to building a containing block's symbol lists. */
13773 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13774 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13776 /* If we've finished processing a top-level function, subsequent
13777 symbols go in the file symbol list. */
13778 if (cu
->get_builder ()->outermost_context_p ())
13779 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13782 /* Process all the DIES contained within a lexical block scope. Start
13783 a new scope, process the dies, and then close the scope. */
13786 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13788 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13789 struct gdbarch
*gdbarch
= objfile
->arch ();
13790 CORE_ADDR lowpc
, highpc
;
13791 struct die_info
*child_die
;
13792 CORE_ADDR baseaddr
;
13794 baseaddr
= objfile
->text_section_offset ();
13796 /* Ignore blocks with missing or invalid low and high pc attributes. */
13797 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13798 as multiple lexical blocks? Handling children in a sane way would
13799 be nasty. Might be easier to properly extend generic blocks to
13800 describe ranges. */
13801 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13803 case PC_BOUNDS_NOT_PRESENT
:
13804 /* DW_TAG_lexical_block has no attributes, process its children as if
13805 there was no wrapping by that DW_TAG_lexical_block.
13806 GCC does no longer produces such DWARF since GCC r224161. */
13807 for (child_die
= die
->child
;
13808 child_die
!= NULL
&& child_die
->tag
;
13809 child_die
= child_die
->sibling
)
13811 /* We might already be processing this DIE. This can happen
13812 in an unusual circumstance -- where a subroutine A
13813 appears lexically in another subroutine B, but A actually
13814 inlines B. The recursion is broken here, rather than in
13815 inherit_abstract_dies, because it seems better to simply
13816 drop concrete children here. */
13817 if (!child_die
->in_process
)
13818 process_die (child_die
, cu
);
13821 case PC_BOUNDS_INVALID
:
13824 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13825 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13827 cu
->get_builder ()->push_context (0, lowpc
);
13828 if (die
->child
!= NULL
)
13830 child_die
= die
->child
;
13831 while (child_die
&& child_die
->tag
)
13833 process_die (child_die
, cu
);
13834 child_die
= child_die
->sibling
;
13837 inherit_abstract_dies (die
, cu
);
13838 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13840 if (*cu
->get_builder ()->get_local_symbols () != NULL
13841 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13843 struct block
*block
13844 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13845 cstk
.start_addr
, highpc
);
13847 /* Note that recording ranges after traversing children, as we
13848 do here, means that recording a parent's ranges entails
13849 walking across all its children's ranges as they appear in
13850 the address map, which is quadratic behavior.
13852 It would be nicer to record the parent's ranges before
13853 traversing its children, simply overriding whatever you find
13854 there. But since we don't even decide whether to create a
13855 block until after we've traversed its children, that's hard
13857 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13859 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13860 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13863 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13866 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13868 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13869 struct objfile
*objfile
= per_objfile
->objfile
;
13870 struct gdbarch
*gdbarch
= objfile
->arch ();
13871 CORE_ADDR pc
, baseaddr
;
13872 struct attribute
*attr
;
13873 struct call_site
*call_site
, call_site_local
;
13876 struct die_info
*child_die
;
13878 baseaddr
= objfile
->text_section_offset ();
13880 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13883 /* This was a pre-DWARF-5 GNU extension alias
13884 for DW_AT_call_return_pc. */
13885 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13889 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13890 "DIE %s [in module %s]"),
13891 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13894 pc
= attr
->as_address () + baseaddr
;
13895 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13897 if (cu
->call_site_htab
== NULL
)
13898 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13899 NULL
, &objfile
->objfile_obstack
,
13900 hashtab_obstack_allocate
, NULL
);
13901 call_site_local
.pc
= pc
;
13902 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13905 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13906 "DIE %s [in module %s]"),
13907 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13908 objfile_name (objfile
));
13912 /* Count parameters at the caller. */
13915 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13916 child_die
= child_die
->sibling
)
13918 if (child_die
->tag
!= DW_TAG_call_site_parameter
13919 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13921 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13922 "DW_TAG_call_site child DIE %s [in module %s]"),
13923 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13924 objfile_name (objfile
));
13932 = ((struct call_site
*)
13933 obstack_alloc (&objfile
->objfile_obstack
,
13934 sizeof (*call_site
)
13935 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13937 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13938 call_site
->pc
= pc
;
13940 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13941 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13943 struct die_info
*func_die
;
13945 /* Skip also over DW_TAG_inlined_subroutine. */
13946 for (func_die
= die
->parent
;
13947 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13948 && func_die
->tag
!= DW_TAG_subroutine_type
;
13949 func_die
= func_die
->parent
);
13951 /* DW_AT_call_all_calls is a superset
13952 of DW_AT_call_all_tail_calls. */
13954 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13955 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13956 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13957 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13959 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13960 not complete. But keep CALL_SITE for look ups via call_site_htab,
13961 both the initial caller containing the real return address PC and
13962 the final callee containing the current PC of a chain of tail
13963 calls do not need to have the tail call list complete. But any
13964 function candidate for a virtual tail call frame searched via
13965 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13966 determined unambiguously. */
13970 struct type
*func_type
= NULL
;
13973 func_type
= get_die_type (func_die
, cu
);
13974 if (func_type
!= NULL
)
13976 gdb_assert (func_type
->code () == TYPE_CODE_FUNC
);
13978 /* Enlist this call site to the function. */
13979 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13980 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13983 complaint (_("Cannot find function owning DW_TAG_call_site "
13984 "DIE %s [in module %s]"),
13985 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13989 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13991 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13993 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13996 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13997 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13999 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
14000 if (!attr
|| (attr
->form_is_block () && attr
->as_block ()->size
== 0))
14001 /* Keep NULL DWARF_BLOCK. */;
14002 else if (attr
->form_is_block ())
14004 struct dwarf2_locexpr_baton
*dlbaton
;
14005 struct dwarf_block
*block
= attr
->as_block ();
14007 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
14008 dlbaton
->data
= block
->data
;
14009 dlbaton
->size
= block
->size
;
14010 dlbaton
->per_objfile
= per_objfile
;
14011 dlbaton
->per_cu
= cu
->per_cu
;
14013 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
14015 else if (attr
->form_is_ref ())
14017 struct dwarf2_cu
*target_cu
= cu
;
14018 struct die_info
*target_die
;
14020 target_die
= follow_die_ref (die
, attr
, &target_cu
);
14021 gdb_assert (target_cu
->per_objfile
->objfile
== objfile
);
14022 if (die_is_declaration (target_die
, target_cu
))
14024 const char *target_physname
;
14026 /* Prefer the mangled name; otherwise compute the demangled one. */
14027 target_physname
= dw2_linkage_name (target_die
, target_cu
);
14028 if (target_physname
== NULL
)
14029 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
14030 if (target_physname
== NULL
)
14031 complaint (_("DW_AT_call_target target DIE has invalid "
14032 "physname, for referencing DIE %s [in module %s]"),
14033 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14035 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
14041 /* DW_AT_entry_pc should be preferred. */
14042 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
14043 <= PC_BOUNDS_INVALID
)
14044 complaint (_("DW_AT_call_target target DIE has invalid "
14045 "low pc, for referencing DIE %s [in module %s]"),
14046 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14049 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
14050 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
14055 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
14056 "block nor reference, for DIE %s [in module %s]"),
14057 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14059 call_site
->per_cu
= cu
->per_cu
;
14060 call_site
->per_objfile
= per_objfile
;
14062 for (child_die
= die
->child
;
14063 child_die
&& child_die
->tag
;
14064 child_die
= child_die
->sibling
)
14066 struct call_site_parameter
*parameter
;
14067 struct attribute
*loc
, *origin
;
14069 if (child_die
->tag
!= DW_TAG_call_site_parameter
14070 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
14072 /* Already printed the complaint above. */
14076 gdb_assert (call_site
->parameter_count
< nparams
);
14077 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
14079 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
14080 specifies DW_TAG_formal_parameter. Value of the data assumed for the
14081 register is contained in DW_AT_call_value. */
14083 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
14084 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
14085 if (origin
== NULL
)
14087 /* This was a pre-DWARF-5 GNU extension alias
14088 for DW_AT_call_parameter. */
14089 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
14091 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
14093 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
14095 sect_offset sect_off
= origin
->get_ref_die_offset ();
14096 if (!cu
->header
.offset_in_cu_p (sect_off
))
14098 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
14099 binding can be done only inside one CU. Such referenced DIE
14100 therefore cannot be even moved to DW_TAG_partial_unit. */
14101 complaint (_("DW_AT_call_parameter offset is not in CU for "
14102 "DW_TAG_call_site child DIE %s [in module %s]"),
14103 sect_offset_str (child_die
->sect_off
),
14104 objfile_name (objfile
));
14107 parameter
->u
.param_cu_off
14108 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
14110 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
14112 complaint (_("No DW_FORM_block* DW_AT_location for "
14113 "DW_TAG_call_site child DIE %s [in module %s]"),
14114 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
14119 struct dwarf_block
*block
= loc
->as_block ();
14121 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
14122 (block
->data
, &block
->data
[block
->size
]);
14123 if (parameter
->u
.dwarf_reg
!= -1)
14124 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
14125 else if (dwarf_block_to_sp_offset (gdbarch
, block
->data
,
14126 &block
->data
[block
->size
],
14127 ¶meter
->u
.fb_offset
))
14128 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
14131 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
14132 "for DW_FORM_block* DW_AT_location is supported for "
14133 "DW_TAG_call_site child DIE %s "
14135 sect_offset_str (child_die
->sect_off
),
14136 objfile_name (objfile
));
14141 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
14143 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
14144 if (attr
== NULL
|| !attr
->form_is_block ())
14146 complaint (_("No DW_FORM_block* DW_AT_call_value for "
14147 "DW_TAG_call_site child DIE %s [in module %s]"),
14148 sect_offset_str (child_die
->sect_off
),
14149 objfile_name (objfile
));
14153 struct dwarf_block
*block
= attr
->as_block ();
14154 parameter
->value
= block
->data
;
14155 parameter
->value_size
= block
->size
;
14157 /* Parameters are not pre-cleared by memset above. */
14158 parameter
->data_value
= NULL
;
14159 parameter
->data_value_size
= 0;
14160 call_site
->parameter_count
++;
14162 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
14164 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
14165 if (attr
!= nullptr)
14167 if (!attr
->form_is_block ())
14168 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
14169 "DW_TAG_call_site child DIE %s [in module %s]"),
14170 sect_offset_str (child_die
->sect_off
),
14171 objfile_name (objfile
));
14174 block
= attr
->as_block ();
14175 parameter
->data_value
= block
->data
;
14176 parameter
->data_value_size
= block
->size
;
14182 /* Helper function for read_variable. If DIE represents a virtual
14183 table, then return the type of the concrete object that is
14184 associated with the virtual table. Otherwise, return NULL. */
14186 static struct type
*
14187 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14189 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
14193 /* Find the type DIE. */
14194 struct die_info
*type_die
= NULL
;
14195 struct dwarf2_cu
*type_cu
= cu
;
14197 if (attr
->form_is_ref ())
14198 type_die
= follow_die_ref (die
, attr
, &type_cu
);
14199 if (type_die
== NULL
)
14202 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
14204 return die_containing_type (type_die
, type_cu
);
14207 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
14210 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
14212 struct rust_vtable_symbol
*storage
= NULL
;
14214 if (cu
->language
== language_rust
)
14216 struct type
*containing_type
= rust_containing_type (die
, cu
);
14218 if (containing_type
!= NULL
)
14220 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14222 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol
;
14223 storage
->concrete_type
= containing_type
;
14224 storage
->subclass
= SYMBOL_RUST_VTABLE
;
14228 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
14229 struct attribute
*abstract_origin
14230 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
14231 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
14232 if (res
== NULL
&& loc
&& abstract_origin
)
14234 /* We have a variable without a name, but with a location and an abstract
14235 origin. This may be a concrete instance of an abstract variable
14236 referenced from an DW_OP_GNU_variable_value, so save it to find it back
14238 struct dwarf2_cu
*origin_cu
= cu
;
14239 struct die_info
*origin_die
14240 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
14241 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14242 per_objfile
->per_bfd
->abstract_to_concrete
14243 [origin_die
->sect_off
].push_back (die
->sect_off
);
14247 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
14248 reading .debug_rnglists.
14249 Callback's type should be:
14250 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14251 Return true if the attributes are present and valid, otherwise,
14254 template <typename Callback
>
14256 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
14257 dwarf_tag tag
, Callback
&&callback
)
14259 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14260 struct objfile
*objfile
= per_objfile
->objfile
;
14261 bfd
*obfd
= objfile
->obfd
;
14262 /* Base address selection entry. */
14263 gdb::optional
<CORE_ADDR
> base
;
14264 const gdb_byte
*buffer
;
14265 CORE_ADDR baseaddr
;
14266 bool overflow
= false;
14267 ULONGEST addr_index
;
14268 struct dwarf2_section_info
*rnglists_section
;
14270 base
= cu
->base_address
;
14271 rnglists_section
= cu_debug_rnglists_section (cu
, tag
);
14272 rnglists_section
->read (objfile
);
14274 if (offset
>= rnglists_section
->size
)
14276 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14280 buffer
= rnglists_section
->buffer
+ offset
;
14282 baseaddr
= objfile
->text_section_offset ();
14286 /* Initialize it due to a false compiler warning. */
14287 CORE_ADDR range_beginning
= 0, range_end
= 0;
14288 const gdb_byte
*buf_end
= (rnglists_section
->buffer
14289 + rnglists_section
->size
);
14290 unsigned int bytes_read
;
14292 if (buffer
== buf_end
)
14297 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
14300 case DW_RLE_end_of_list
:
14302 case DW_RLE_base_address
:
14303 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14308 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
14309 buffer
+= bytes_read
;
14311 case DW_RLE_base_addressx
:
14312 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14313 buffer
+= bytes_read
;
14314 base
= read_addr_index (cu
, addr_index
);
14316 case DW_RLE_start_length
:
14317 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14322 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
14324 buffer
+= bytes_read
;
14325 range_end
= (range_beginning
14326 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
14327 buffer
+= bytes_read
;
14328 if (buffer
> buf_end
)
14334 case DW_RLE_startx_length
:
14335 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14336 buffer
+= bytes_read
;
14337 range_beginning
= read_addr_index (cu
, addr_index
);
14338 if (buffer
> buf_end
)
14343 range_end
= (range_beginning
14344 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
14345 buffer
+= bytes_read
;
14347 case DW_RLE_offset_pair
:
14348 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14349 buffer
+= bytes_read
;
14350 if (buffer
> buf_end
)
14355 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14356 buffer
+= bytes_read
;
14357 if (buffer
> buf_end
)
14363 case DW_RLE_start_end
:
14364 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
14369 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
14371 buffer
+= bytes_read
;
14372 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
14373 buffer
+= bytes_read
;
14375 case DW_RLE_startx_endx
:
14376 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14377 buffer
+= bytes_read
;
14378 range_beginning
= read_addr_index (cu
, addr_index
);
14379 if (buffer
> buf_end
)
14384 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14385 buffer
+= bytes_read
;
14386 range_end
= read_addr_index (cu
, addr_index
);
14389 complaint (_("Invalid .debug_rnglists data (no base address)"));
14392 if (rlet
== DW_RLE_end_of_list
|| overflow
)
14394 if (rlet
== DW_RLE_base_address
)
14397 if (range_beginning
> range_end
)
14399 /* Inverted range entries are invalid. */
14400 complaint (_("Invalid .debug_rnglists data (inverted range)"));
14404 /* Empty range entries have no effect. */
14405 if (range_beginning
== range_end
)
14408 /* Only DW_RLE_offset_pair needs the base address added. */
14409 if (rlet
== DW_RLE_offset_pair
)
14411 if (!base
.has_value ())
14413 /* We have no valid base address for the DW_RLE_offset_pair. */
14414 complaint (_("Invalid .debug_rnglists data (no base address for "
14415 "DW_RLE_offset_pair)"));
14419 range_beginning
+= *base
;
14420 range_end
+= *base
;
14423 /* A not-uncommon case of bad debug info.
14424 Don't pollute the addrmap with bad data. */
14425 if (range_beginning
+ baseaddr
== 0
14426 && !per_objfile
->per_bfd
->has_section_at_zero
)
14428 complaint (_(".debug_rnglists entry has start address of zero"
14429 " [in module %s]"), objfile_name (objfile
));
14433 callback (range_beginning
, range_end
);
14438 complaint (_("Offset %d is not terminated "
14439 "for DW_AT_ranges attribute"),
14447 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
14448 Callback's type should be:
14449 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14450 Return 1 if the attributes are present and valid, otherwise, return 0. */
14452 template <typename Callback
>
14454 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
, dwarf_tag tag
,
14455 Callback
&&callback
)
14457 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14458 struct objfile
*objfile
= per_objfile
->objfile
;
14459 struct comp_unit_head
*cu_header
= &cu
->header
;
14460 bfd
*obfd
= objfile
->obfd
;
14461 unsigned int addr_size
= cu_header
->addr_size
;
14462 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
14463 /* Base address selection entry. */
14464 gdb::optional
<CORE_ADDR
> base
;
14465 unsigned int dummy
;
14466 const gdb_byte
*buffer
;
14467 CORE_ADDR baseaddr
;
14469 if (cu_header
->version
>= 5)
14470 return dwarf2_rnglists_process (offset
, cu
, tag
, callback
);
14472 base
= cu
->base_address
;
14474 per_objfile
->per_bfd
->ranges
.read (objfile
);
14475 if (offset
>= per_objfile
->per_bfd
->ranges
.size
)
14477 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14481 buffer
= per_objfile
->per_bfd
->ranges
.buffer
+ offset
;
14483 baseaddr
= objfile
->text_section_offset ();
14487 CORE_ADDR range_beginning
, range_end
;
14489 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
14490 buffer
+= addr_size
;
14491 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
14492 buffer
+= addr_size
;
14493 offset
+= 2 * addr_size
;
14495 /* An end of list marker is a pair of zero addresses. */
14496 if (range_beginning
== 0 && range_end
== 0)
14497 /* Found the end of list entry. */
14500 /* Each base address selection entry is a pair of 2 values.
14501 The first is the largest possible address, the second is
14502 the base address. Check for a base address here. */
14503 if ((range_beginning
& mask
) == mask
)
14505 /* If we found the largest possible address, then we already
14506 have the base address in range_end. */
14511 if (!base
.has_value ())
14513 /* We have no valid base address for the ranges
14515 complaint (_("Invalid .debug_ranges data (no base address)"));
14519 if (range_beginning
> range_end
)
14521 /* Inverted range entries are invalid. */
14522 complaint (_("Invalid .debug_ranges data (inverted range)"));
14526 /* Empty range entries have no effect. */
14527 if (range_beginning
== range_end
)
14530 range_beginning
+= *base
;
14531 range_end
+= *base
;
14533 /* A not-uncommon case of bad debug info.
14534 Don't pollute the addrmap with bad data. */
14535 if (range_beginning
+ baseaddr
== 0
14536 && !per_objfile
->per_bfd
->has_section_at_zero
)
14538 complaint (_(".debug_ranges entry has start address of zero"
14539 " [in module %s]"), objfile_name (objfile
));
14543 callback (range_beginning
, range_end
);
14549 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
14550 Return 1 if the attributes are present and valid, otherwise, return 0.
14551 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
14554 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
14555 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
14556 dwarf2_psymtab
*ranges_pst
, dwarf_tag tag
)
14558 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14559 struct gdbarch
*gdbarch
= objfile
->arch ();
14560 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
14563 CORE_ADDR high
= 0;
14566 retval
= dwarf2_ranges_process (offset
, cu
, tag
,
14567 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
14569 if (ranges_pst
!= NULL
)
14574 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14575 range_beginning
+ baseaddr
)
14577 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14578 range_end
+ baseaddr
)
14580 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
14581 lowpc
, highpc
- 1, ranges_pst
);
14584 /* FIXME: This is recording everything as a low-high
14585 segment of consecutive addresses. We should have a
14586 data structure for discontiguous block ranges
14590 low
= range_beginning
;
14596 if (range_beginning
< low
)
14597 low
= range_beginning
;
14598 if (range_end
> high
)
14606 /* If the first entry is an end-of-list marker, the range
14607 describes an empty scope, i.e. no instructions. */
14613 *high_return
= high
;
14617 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14618 definition for the return value. *LOWPC and *HIGHPC are set iff
14619 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14621 static enum pc_bounds_kind
14622 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14623 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14624 dwarf2_psymtab
*pst
)
14626 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14627 struct attribute
*attr
;
14628 struct attribute
*attr_high
;
14630 CORE_ADDR high
= 0;
14631 enum pc_bounds_kind ret
;
14633 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14636 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14637 if (attr
!= nullptr)
14639 low
= attr
->as_address ();
14640 high
= attr_high
->as_address ();
14641 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14645 /* Found high w/o low attribute. */
14646 return PC_BOUNDS_INVALID
;
14648 /* Found consecutive range of addresses. */
14649 ret
= PC_BOUNDS_HIGH_LOW
;
14653 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14654 if (attr
!= nullptr && attr
->form_is_unsigned ())
14656 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14657 We take advantage of the fact that DW_AT_ranges does not appear
14658 in DW_TAG_compile_unit of DWO files.
14660 Attributes of the form DW_FORM_rnglistx have already had their
14661 value changed by read_rnglist_index and already include
14662 DW_AT_rnglists_base, so don't need to add the ranges base,
14664 int need_ranges_base
= (die
->tag
!= DW_TAG_compile_unit
14665 && attr
->form
!= DW_FORM_rnglistx
);
14666 unsigned int ranges_offset
= (attr
->as_unsigned ()
14667 + (need_ranges_base
14671 /* Value of the DW_AT_ranges attribute is the offset in the
14672 .debug_ranges section. */
14673 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
,
14675 return PC_BOUNDS_INVALID
;
14676 /* Found discontinuous range of addresses. */
14677 ret
= PC_BOUNDS_RANGES
;
14680 return PC_BOUNDS_NOT_PRESENT
;
14683 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14685 return PC_BOUNDS_INVALID
;
14687 /* When using the GNU linker, .gnu.linkonce. sections are used to
14688 eliminate duplicate copies of functions and vtables and such.
14689 The linker will arbitrarily choose one and discard the others.
14690 The AT_*_pc values for such functions refer to local labels in
14691 these sections. If the section from that file was discarded, the
14692 labels are not in the output, so the relocs get a value of 0.
14693 If this is a discarded function, mark the pc bounds as invalid,
14694 so that GDB will ignore it. */
14695 if (low
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
14696 return PC_BOUNDS_INVALID
;
14704 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14705 its low and high PC addresses. Do nothing if these addresses could not
14706 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14707 and HIGHPC to the high address if greater than HIGHPC. */
14710 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14711 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14712 struct dwarf2_cu
*cu
)
14714 CORE_ADDR low
, high
;
14715 struct die_info
*child
= die
->child
;
14717 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14719 *lowpc
= std::min (*lowpc
, low
);
14720 *highpc
= std::max (*highpc
, high
);
14723 /* If the language does not allow nested subprograms (either inside
14724 subprograms or lexical blocks), we're done. */
14725 if (cu
->language
!= language_ada
)
14728 /* Check all the children of the given DIE. If it contains nested
14729 subprograms, then check their pc bounds. Likewise, we need to
14730 check lexical blocks as well, as they may also contain subprogram
14732 while (child
&& child
->tag
)
14734 if (child
->tag
== DW_TAG_subprogram
14735 || child
->tag
== DW_TAG_lexical_block
)
14736 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14737 child
= child
->sibling
;
14741 /* Get the low and high pc's represented by the scope DIE, and store
14742 them in *LOWPC and *HIGHPC. If the correct values can't be
14743 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14746 get_scope_pc_bounds (struct die_info
*die
,
14747 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14748 struct dwarf2_cu
*cu
)
14750 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14751 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14752 CORE_ADDR current_low
, current_high
;
14754 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14755 >= PC_BOUNDS_RANGES
)
14757 best_low
= current_low
;
14758 best_high
= current_high
;
14762 struct die_info
*child
= die
->child
;
14764 while (child
&& child
->tag
)
14766 switch (child
->tag
) {
14767 case DW_TAG_subprogram
:
14768 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14770 case DW_TAG_namespace
:
14771 case DW_TAG_module
:
14772 /* FIXME: carlton/2004-01-16: Should we do this for
14773 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14774 that current GCC's always emit the DIEs corresponding
14775 to definitions of methods of classes as children of a
14776 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14777 the DIEs giving the declarations, which could be
14778 anywhere). But I don't see any reason why the
14779 standards says that they have to be there. */
14780 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14782 if (current_low
!= ((CORE_ADDR
) -1))
14784 best_low
= std::min (best_low
, current_low
);
14785 best_high
= std::max (best_high
, current_high
);
14793 child
= child
->sibling
;
14798 *highpc
= best_high
;
14801 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14805 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14806 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14808 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14809 struct gdbarch
*gdbarch
= objfile
->arch ();
14810 struct attribute
*attr
;
14811 struct attribute
*attr_high
;
14813 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14816 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14817 if (attr
!= nullptr)
14819 CORE_ADDR low
= attr
->as_address ();
14820 CORE_ADDR high
= attr_high
->as_address ();
14822 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14825 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14826 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14827 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14831 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14832 if (attr
!= nullptr && attr
->form_is_unsigned ())
14834 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14835 We take advantage of the fact that DW_AT_ranges does not appear
14836 in DW_TAG_compile_unit of DWO files.
14838 Attributes of the form DW_FORM_rnglistx have already had their
14839 value changed by read_rnglist_index and already include
14840 DW_AT_rnglists_base, so don't need to add the ranges base,
14842 int need_ranges_base
= (die
->tag
!= DW_TAG_compile_unit
14843 && attr
->form
!= DW_FORM_rnglistx
);
14845 /* The value of the DW_AT_ranges attribute is the offset of the
14846 address range list in the .debug_ranges section. */
14847 unsigned long offset
= (attr
->as_unsigned ()
14848 + (need_ranges_base
? cu
->ranges_base
: 0));
14850 std::vector
<blockrange
> blockvec
;
14851 dwarf2_ranges_process (offset
, cu
, die
->tag
,
14852 [&] (CORE_ADDR start
, CORE_ADDR end
)
14856 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14857 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14858 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14859 blockvec
.emplace_back (start
, end
);
14862 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14866 /* Check whether the producer field indicates either of GCC < 4.6, or the
14867 Intel C/C++ compiler, and cache the result in CU. */
14870 check_producer (struct dwarf2_cu
*cu
)
14874 if (cu
->producer
== NULL
)
14876 /* For unknown compilers expect their behavior is DWARF version
14879 GCC started to support .debug_types sections by -gdwarf-4 since
14880 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14881 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14882 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14883 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14885 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14887 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14888 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14890 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14892 cu
->producer_is_icc
= true;
14893 cu
->producer_is_icc_lt_14
= major
< 14;
14895 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14896 cu
->producer_is_codewarrior
= true;
14899 /* For other non-GCC compilers, expect their behavior is DWARF version
14903 cu
->checked_producer
= true;
14906 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14907 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14908 during 4.6.0 experimental. */
14911 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14913 if (!cu
->checked_producer
)
14914 check_producer (cu
);
14916 return cu
->producer_is_gxx_lt_4_6
;
14920 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14921 with incorrect is_stmt attributes. */
14924 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14926 if (!cu
->checked_producer
)
14927 check_producer (cu
);
14929 return cu
->producer_is_codewarrior
;
14932 /* Return the accessibility of DIE, as given by DW_AT_accessibility.
14933 If that attribute is not available, return the appropriate
14936 static enum dwarf_access_attribute
14937 dwarf2_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14939 attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14940 if (attr
!= nullptr)
14942 LONGEST value
= attr
->constant_value (-1);
14943 if (value
== DW_ACCESS_public
14944 || value
== DW_ACCESS_protected
14945 || value
== DW_ACCESS_private
)
14946 return (dwarf_access_attribute
) value
;
14947 complaint (_("Unhandled DW_AT_accessibility value (%s)"),
14951 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14953 /* The default DWARF 2 accessibility for members is public, the default
14954 accessibility for inheritance is private. */
14956 if (die
->tag
!= DW_TAG_inheritance
)
14957 return DW_ACCESS_public
;
14959 return DW_ACCESS_private
;
14963 /* DWARF 3+ defines the default accessibility a different way. The same
14964 rules apply now for DW_TAG_inheritance as for the members and it only
14965 depends on the container kind. */
14967 if (die
->parent
->tag
== DW_TAG_class_type
)
14968 return DW_ACCESS_private
;
14970 return DW_ACCESS_public
;
14974 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14975 offset. If the attribute was not found return 0, otherwise return
14976 1. If it was found but could not properly be handled, set *OFFSET
14980 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14983 struct attribute
*attr
;
14985 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14990 /* Note that we do not check for a section offset first here.
14991 This is because DW_AT_data_member_location is new in DWARF 4,
14992 so if we see it, we can assume that a constant form is really
14993 a constant and not a section offset. */
14994 if (attr
->form_is_constant ())
14995 *offset
= attr
->constant_value (0);
14996 else if (attr
->form_is_section_offset ())
14997 dwarf2_complex_location_expr_complaint ();
14998 else if (attr
->form_is_block ())
14999 *offset
= decode_locdesc (attr
->as_block (), cu
);
15001 dwarf2_complex_location_expr_complaint ();
15009 /* Look for DW_AT_data_member_location and store the results in FIELD. */
15012 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
15013 struct field
*field
)
15015 struct attribute
*attr
;
15017 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
15020 if (attr
->form_is_constant ())
15022 LONGEST offset
= attr
->constant_value (0);
15023 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
15025 else if (attr
->form_is_section_offset ())
15026 dwarf2_complex_location_expr_complaint ();
15027 else if (attr
->form_is_block ())
15030 CORE_ADDR offset
= decode_locdesc (attr
->as_block (), cu
, &handled
);
15032 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
15035 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
15036 struct objfile
*objfile
= per_objfile
->objfile
;
15037 struct dwarf2_locexpr_baton
*dlbaton
15038 = XOBNEW (&objfile
->objfile_obstack
,
15039 struct dwarf2_locexpr_baton
);
15040 dlbaton
->data
= attr
->as_block ()->data
;
15041 dlbaton
->size
= attr
->as_block ()->size
;
15042 /* When using this baton, we want to compute the address
15043 of the field, not the value. This is why
15044 is_reference is set to false here. */
15045 dlbaton
->is_reference
= false;
15046 dlbaton
->per_objfile
= per_objfile
;
15047 dlbaton
->per_cu
= cu
->per_cu
;
15049 SET_FIELD_DWARF_BLOCK (*field
, dlbaton
);
15053 dwarf2_complex_location_expr_complaint ();
15057 /* Add an aggregate field to the field list. */
15060 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
15061 struct dwarf2_cu
*cu
)
15063 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15064 struct gdbarch
*gdbarch
= objfile
->arch ();
15065 struct nextfield
*new_field
;
15066 struct attribute
*attr
;
15068 const char *fieldname
= "";
15070 if (die
->tag
== DW_TAG_inheritance
)
15072 fip
->baseclasses
.emplace_back ();
15073 new_field
= &fip
->baseclasses
.back ();
15077 fip
->fields
.emplace_back ();
15078 new_field
= &fip
->fields
.back ();
15081 new_field
->offset
= die
->sect_off
;
15083 new_field
->accessibility
= dwarf2_access_attribute (die
, cu
);
15084 if (new_field
->accessibility
!= DW_ACCESS_public
)
15085 fip
->non_public_fields
= true;
15087 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15088 if (attr
!= nullptr)
15089 new_field
->virtuality
= attr
->as_virtuality ();
15091 new_field
->virtuality
= DW_VIRTUALITY_none
;
15093 fp
= &new_field
->field
;
15095 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
15097 /* Data member other than a C++ static data member. */
15099 /* Get type of field. */
15100 fp
->set_type (die_type (die
, cu
));
15102 SET_FIELD_BITPOS (*fp
, 0);
15104 /* Get bit size of field (zero if none). */
15105 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
15106 if (attr
!= nullptr)
15108 FIELD_BITSIZE (*fp
) = attr
->constant_value (0);
15112 FIELD_BITSIZE (*fp
) = 0;
15115 /* Get bit offset of field. */
15116 handle_data_member_location (die
, cu
, fp
);
15117 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
15118 if (attr
!= nullptr && attr
->form_is_constant ())
15120 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
15122 /* For big endian bits, the DW_AT_bit_offset gives the
15123 additional bit offset from the MSB of the containing
15124 anonymous object to the MSB of the field. We don't
15125 have to do anything special since we don't need to
15126 know the size of the anonymous object. */
15127 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
15128 + attr
->constant_value (0)));
15132 /* For little endian bits, compute the bit offset to the
15133 MSB of the anonymous object, subtract off the number of
15134 bits from the MSB of the field to the MSB of the
15135 object, and then subtract off the number of bits of
15136 the field itself. The result is the bit offset of
15137 the LSB of the field. */
15138 int anonymous_size
;
15139 int bit_offset
= attr
->constant_value (0);
15141 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15142 if (attr
!= nullptr && attr
->form_is_constant ())
15144 /* The size of the anonymous object containing
15145 the bit field is explicit, so use the
15146 indicated size (in bytes). */
15147 anonymous_size
= attr
->constant_value (0);
15151 /* The size of the anonymous object containing
15152 the bit field must be inferred from the type
15153 attribute of the data member containing the
15155 anonymous_size
= TYPE_LENGTH (fp
->type ());
15157 SET_FIELD_BITPOS (*fp
,
15158 (FIELD_BITPOS (*fp
)
15159 + anonymous_size
* bits_per_byte
15160 - bit_offset
- FIELD_BITSIZE (*fp
)));
15163 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
15165 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
15166 + attr
->constant_value (0)));
15168 /* Get name of field. */
15169 fieldname
= dwarf2_name (die
, cu
);
15170 if (fieldname
== NULL
)
15173 /* The name is already allocated along with this objfile, so we don't
15174 need to duplicate it for the type. */
15175 fp
->name
= fieldname
;
15177 /* Change accessibility for artificial fields (e.g. virtual table
15178 pointer or virtual base class pointer) to private. */
15179 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
15181 FIELD_ARTIFICIAL (*fp
) = 1;
15182 new_field
->accessibility
= DW_ACCESS_private
;
15183 fip
->non_public_fields
= true;
15186 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
15188 /* C++ static member. */
15190 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
15191 is a declaration, but all versions of G++ as of this writing
15192 (so through at least 3.2.1) incorrectly generate
15193 DW_TAG_variable tags. */
15195 const char *physname
;
15197 /* Get name of field. */
15198 fieldname
= dwarf2_name (die
, cu
);
15199 if (fieldname
== NULL
)
15202 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15204 /* Only create a symbol if this is an external value.
15205 new_symbol checks this and puts the value in the global symbol
15206 table, which we want. If it is not external, new_symbol
15207 will try to put the value in cu->list_in_scope which is wrong. */
15208 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
15210 /* A static const member, not much different than an enum as far as
15211 we're concerned, except that we can support more types. */
15212 new_symbol (die
, NULL
, cu
);
15215 /* Get physical name. */
15216 physname
= dwarf2_physname (fieldname
, die
, cu
);
15218 /* The name is already allocated along with this objfile, so we don't
15219 need to duplicate it for the type. */
15220 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
15221 fp
->set_type (die_type (die
, cu
));
15222 FIELD_NAME (*fp
) = fieldname
;
15224 else if (die
->tag
== DW_TAG_inheritance
)
15226 /* C++ base class field. */
15227 handle_data_member_location (die
, cu
, fp
);
15228 FIELD_BITSIZE (*fp
) = 0;
15229 fp
->set_type (die_type (die
, cu
));
15230 FIELD_NAME (*fp
) = fp
->type ()->name ();
15233 gdb_assert_not_reached ("missing case in dwarf2_add_field");
15236 /* Can the type given by DIE define another type? */
15239 type_can_define_types (const struct die_info
*die
)
15243 case DW_TAG_typedef
:
15244 case DW_TAG_class_type
:
15245 case DW_TAG_structure_type
:
15246 case DW_TAG_union_type
:
15247 case DW_TAG_enumeration_type
:
15255 /* Add a type definition defined in the scope of the FIP's class. */
15258 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
15259 struct dwarf2_cu
*cu
)
15261 struct decl_field fp
;
15262 memset (&fp
, 0, sizeof (fp
));
15264 gdb_assert (type_can_define_types (die
));
15266 /* Get name of field. NULL is okay here, meaning an anonymous type. */
15267 fp
.name
= dwarf2_name (die
, cu
);
15268 fp
.type
= read_type_die (die
, cu
);
15270 /* Save accessibility. */
15271 dwarf_access_attribute accessibility
= dwarf2_access_attribute (die
, cu
);
15272 switch (accessibility
)
15274 case DW_ACCESS_public
:
15275 /* The assumed value if neither private nor protected. */
15277 case DW_ACCESS_private
:
15280 case DW_ACCESS_protected
:
15281 fp
.is_protected
= 1;
15285 if (die
->tag
== DW_TAG_typedef
)
15286 fip
->typedef_field_list
.push_back (fp
);
15288 fip
->nested_types_list
.push_back (fp
);
15291 /* A convenience typedef that's used when finding the discriminant
15292 field for a variant part. */
15293 typedef std::unordered_map
<sect_offset
, int, gdb::hash_enum
<sect_offset
>>
15296 /* Compute the discriminant range for a given variant. OBSTACK is
15297 where the results will be stored. VARIANT is the variant to
15298 process. IS_UNSIGNED indicates whether the discriminant is signed
15301 static const gdb::array_view
<discriminant_range
>
15302 convert_variant_range (struct obstack
*obstack
, const variant_field
&variant
,
15305 std::vector
<discriminant_range
> ranges
;
15307 if (variant
.default_branch
)
15310 if (variant
.discr_list_data
== nullptr)
15312 discriminant_range r
15313 = {variant
.discriminant_value
, variant
.discriminant_value
};
15314 ranges
.push_back (r
);
15318 gdb::array_view
<const gdb_byte
> data (variant
.discr_list_data
->data
,
15319 variant
.discr_list_data
->size
);
15320 while (!data
.empty ())
15322 if (data
[0] != DW_DSC_range
&& data
[0] != DW_DSC_label
)
15324 complaint (_("invalid discriminant marker: %d"), data
[0]);
15327 bool is_range
= data
[0] == DW_DSC_range
;
15328 data
= data
.slice (1);
15330 ULONGEST low
, high
;
15331 unsigned int bytes_read
;
15335 complaint (_("DW_AT_discr_list missing low value"));
15339 low
= read_unsigned_leb128 (nullptr, data
.data (), &bytes_read
);
15341 low
= (ULONGEST
) read_signed_leb128 (nullptr, data
.data (),
15343 data
= data
.slice (bytes_read
);
15349 complaint (_("DW_AT_discr_list missing high value"));
15353 high
= read_unsigned_leb128 (nullptr, data
.data (),
15356 high
= (LONGEST
) read_signed_leb128 (nullptr, data
.data (),
15358 data
= data
.slice (bytes_read
);
15363 ranges
.push_back ({ low
, high
});
15367 discriminant_range
*result
= XOBNEWVEC (obstack
, discriminant_range
,
15369 std::copy (ranges
.begin (), ranges
.end (), result
);
15370 return gdb::array_view
<discriminant_range
> (result
, ranges
.size ());
15373 static const gdb::array_view
<variant_part
> create_variant_parts
15374 (struct obstack
*obstack
,
15375 const offset_map_type
&offset_map
,
15376 struct field_info
*fi
,
15377 const std::vector
<variant_part_builder
> &variant_parts
);
15379 /* Fill in a "struct variant" for a given variant field. RESULT is
15380 the variant to fill in. OBSTACK is where any needed allocations
15381 will be done. OFFSET_MAP holds the mapping from section offsets to
15382 fields for the type. FI describes the fields of the type we're
15383 processing. FIELD is the variant field we're converting. */
15386 create_one_variant (variant
&result
, struct obstack
*obstack
,
15387 const offset_map_type
&offset_map
,
15388 struct field_info
*fi
, const variant_field
&field
)
15390 result
.discriminants
= convert_variant_range (obstack
, field
, false);
15391 result
.first_field
= field
.first_field
+ fi
->baseclasses
.size ();
15392 result
.last_field
= field
.last_field
+ fi
->baseclasses
.size ();
15393 result
.parts
= create_variant_parts (obstack
, offset_map
, fi
,
15394 field
.variant_parts
);
15397 /* Fill in a "struct variant_part" for a given variant part. RESULT
15398 is the variant part to fill in. OBSTACK is where any needed
15399 allocations will be done. OFFSET_MAP holds the mapping from
15400 section offsets to fields for the type. FI describes the fields of
15401 the type we're processing. BUILDER is the variant part to be
15405 create_one_variant_part (variant_part
&result
,
15406 struct obstack
*obstack
,
15407 const offset_map_type
&offset_map
,
15408 struct field_info
*fi
,
15409 const variant_part_builder
&builder
)
15411 auto iter
= offset_map
.find (builder
.discriminant_offset
);
15412 if (iter
== offset_map
.end ())
15414 result
.discriminant_index
= -1;
15415 /* Doesn't matter. */
15416 result
.is_unsigned
= false;
15420 result
.discriminant_index
= iter
->second
;
15422 = fi
->fields
[result
.discriminant_index
].field
.type ()->is_unsigned ();
15425 size_t n
= builder
.variants
.size ();
15426 variant
*output
= new (obstack
) variant
[n
];
15427 for (size_t i
= 0; i
< n
; ++i
)
15428 create_one_variant (output
[i
], obstack
, offset_map
, fi
,
15429 builder
.variants
[i
]);
15431 result
.variants
= gdb::array_view
<variant
> (output
, n
);
15434 /* Create a vector of variant parts that can be attached to a type.
15435 OBSTACK is where any needed allocations will be done. OFFSET_MAP
15436 holds the mapping from section offsets to fields for the type. FI
15437 describes the fields of the type we're processing. VARIANT_PARTS
15438 is the vector to convert. */
15440 static const gdb::array_view
<variant_part
>
15441 create_variant_parts (struct obstack
*obstack
,
15442 const offset_map_type
&offset_map
,
15443 struct field_info
*fi
,
15444 const std::vector
<variant_part_builder
> &variant_parts
)
15446 if (variant_parts
.empty ())
15449 size_t n
= variant_parts
.size ();
15450 variant_part
*result
= new (obstack
) variant_part
[n
];
15451 for (size_t i
= 0; i
< n
; ++i
)
15452 create_one_variant_part (result
[i
], obstack
, offset_map
, fi
,
15455 return gdb::array_view
<variant_part
> (result
, n
);
15458 /* Compute the variant part vector for FIP, attaching it to TYPE when
15462 add_variant_property (struct field_info
*fip
, struct type
*type
,
15463 struct dwarf2_cu
*cu
)
15465 /* Map section offsets of fields to their field index. Note the
15466 field index here does not take the number of baseclasses into
15468 offset_map_type offset_map
;
15469 for (int i
= 0; i
< fip
->fields
.size (); ++i
)
15470 offset_map
[fip
->fields
[i
].offset
] = i
;
15472 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15473 gdb::array_view
<variant_part
> parts
15474 = create_variant_parts (&objfile
->objfile_obstack
, offset_map
, fip
,
15475 fip
->variant_parts
);
15477 struct dynamic_prop prop
;
15478 prop
.set_variant_parts ((gdb::array_view
<variant_part
> *)
15479 obstack_copy (&objfile
->objfile_obstack
, &parts
,
15482 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
15485 /* Create the vector of fields, and attach it to the type. */
15488 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
15489 struct dwarf2_cu
*cu
)
15491 int nfields
= fip
->nfields ();
15493 /* Record the field count, allocate space for the array of fields,
15494 and create blank accessibility bitfields if necessary. */
15495 type
->set_num_fields (nfields
);
15497 ((struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
));
15499 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
15501 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15503 TYPE_FIELD_PRIVATE_BITS (type
) =
15504 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15505 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
15507 TYPE_FIELD_PROTECTED_BITS (type
) =
15508 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15509 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
15511 TYPE_FIELD_IGNORE_BITS (type
) =
15512 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15513 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
15516 /* If the type has baseclasses, allocate and clear a bit vector for
15517 TYPE_FIELD_VIRTUAL_BITS. */
15518 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
15520 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
15521 unsigned char *pointer
;
15523 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15524 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
15525 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
15526 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
15527 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
15530 if (!fip
->variant_parts
.empty ())
15531 add_variant_property (fip
, type
, cu
);
15533 /* Copy the saved-up fields into the field vector. */
15534 for (int i
= 0; i
< nfields
; ++i
)
15536 struct nextfield
&field
15537 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
15538 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
15540 type
->field (i
) = field
.field
;
15541 switch (field
.accessibility
)
15543 case DW_ACCESS_private
:
15544 if (cu
->language
!= language_ada
)
15545 SET_TYPE_FIELD_PRIVATE (type
, i
);
15548 case DW_ACCESS_protected
:
15549 if (cu
->language
!= language_ada
)
15550 SET_TYPE_FIELD_PROTECTED (type
, i
);
15553 case DW_ACCESS_public
:
15557 /* Unknown accessibility. Complain and treat it as public. */
15559 complaint (_("unsupported accessibility %d"),
15560 field
.accessibility
);
15564 if (i
< fip
->baseclasses
.size ())
15566 switch (field
.virtuality
)
15568 case DW_VIRTUALITY_virtual
:
15569 case DW_VIRTUALITY_pure_virtual
:
15570 if (cu
->language
== language_ada
)
15571 error (_("unexpected virtuality in component of Ada type"));
15572 SET_TYPE_FIELD_VIRTUAL (type
, i
);
15579 /* Return true if this member function is a constructor, false
15583 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15585 const char *fieldname
;
15586 const char *type_name
;
15589 if (die
->parent
== NULL
)
15592 if (die
->parent
->tag
!= DW_TAG_structure_type
15593 && die
->parent
->tag
!= DW_TAG_union_type
15594 && die
->parent
->tag
!= DW_TAG_class_type
)
15597 fieldname
= dwarf2_name (die
, cu
);
15598 type_name
= dwarf2_name (die
->parent
, cu
);
15599 if (fieldname
== NULL
|| type_name
== NULL
)
15602 len
= strlen (fieldname
);
15603 return (strncmp (fieldname
, type_name
, len
) == 0
15604 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15607 /* Add a member function to the proper fieldlist. */
15610 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15611 struct type
*type
, struct dwarf2_cu
*cu
)
15613 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15614 struct attribute
*attr
;
15616 struct fnfieldlist
*flp
= nullptr;
15617 struct fn_field
*fnp
;
15618 const char *fieldname
;
15619 struct type
*this_type
;
15621 if (cu
->language
== language_ada
)
15622 error (_("unexpected member function in Ada type"));
15624 /* Get name of member function. */
15625 fieldname
= dwarf2_name (die
, cu
);
15626 if (fieldname
== NULL
)
15629 /* Look up member function name in fieldlist. */
15630 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15632 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15634 flp
= &fip
->fnfieldlists
[i
];
15639 /* Create a new fnfieldlist if necessary. */
15640 if (flp
== nullptr)
15642 fip
->fnfieldlists
.emplace_back ();
15643 flp
= &fip
->fnfieldlists
.back ();
15644 flp
->name
= fieldname
;
15645 i
= fip
->fnfieldlists
.size () - 1;
15648 /* Create a new member function field and add it to the vector of
15650 flp
->fnfields
.emplace_back ();
15651 fnp
= &flp
->fnfields
.back ();
15653 /* Delay processing of the physname until later. */
15654 if (cu
->language
== language_cplus
)
15655 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15659 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15660 fnp
->physname
= physname
? physname
: "";
15663 fnp
->type
= alloc_type (objfile
);
15664 this_type
= read_type_die (die
, cu
);
15665 if (this_type
&& this_type
->code () == TYPE_CODE_FUNC
)
15667 int nparams
= this_type
->num_fields ();
15669 /* TYPE is the domain of this method, and THIS_TYPE is the type
15670 of the method itself (TYPE_CODE_METHOD). */
15671 smash_to_method_type (fnp
->type
, type
,
15672 TYPE_TARGET_TYPE (this_type
),
15673 this_type
->fields (),
15674 this_type
->num_fields (),
15675 this_type
->has_varargs ());
15677 /* Handle static member functions.
15678 Dwarf2 has no clean way to discern C++ static and non-static
15679 member functions. G++ helps GDB by marking the first
15680 parameter for non-static member functions (which is the this
15681 pointer) as artificial. We obtain this information from
15682 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15683 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15684 fnp
->voffset
= VOFFSET_STATIC
;
15687 complaint (_("member function type missing for '%s'"),
15688 dwarf2_full_name (fieldname
, die
, cu
));
15690 /* Get fcontext from DW_AT_containing_type if present. */
15691 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15692 fnp
->fcontext
= die_containing_type (die
, cu
);
15694 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15695 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15697 /* Get accessibility. */
15698 dwarf_access_attribute accessibility
= dwarf2_access_attribute (die
, cu
);
15699 switch (accessibility
)
15701 case DW_ACCESS_private
:
15702 fnp
->is_private
= 1;
15704 case DW_ACCESS_protected
:
15705 fnp
->is_protected
= 1;
15709 /* Check for artificial methods. */
15710 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15711 if (attr
&& attr
->as_boolean ())
15712 fnp
->is_artificial
= 1;
15714 /* Check for defaulted methods. */
15715 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
15716 if (attr
!= nullptr)
15717 fnp
->defaulted
= attr
->defaulted ();
15719 /* Check for deleted methods. */
15720 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
15721 if (attr
!= nullptr && attr
->as_boolean ())
15722 fnp
->is_deleted
= 1;
15724 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15726 /* Get index in virtual function table if it is a virtual member
15727 function. For older versions of GCC, this is an offset in the
15728 appropriate virtual table, as specified by DW_AT_containing_type.
15729 For everyone else, it is an expression to be evaluated relative
15730 to the object address. */
15732 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15733 if (attr
!= nullptr)
15735 if (attr
->form_is_block () && attr
->as_block ()->size
> 0)
15737 struct dwarf_block
*block
= attr
->as_block ();
15739 if (block
->data
[0] == DW_OP_constu
)
15741 /* Old-style GCC. */
15742 fnp
->voffset
= decode_locdesc (block
, cu
) + 2;
15744 else if (block
->data
[0] == DW_OP_deref
15745 || (block
->size
> 1
15746 && block
->data
[0] == DW_OP_deref_size
15747 && block
->data
[1] == cu
->header
.addr_size
))
15749 fnp
->voffset
= decode_locdesc (block
, cu
);
15750 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15751 dwarf2_complex_location_expr_complaint ();
15753 fnp
->voffset
/= cu
->header
.addr_size
;
15757 dwarf2_complex_location_expr_complaint ();
15759 if (!fnp
->fcontext
)
15761 /* If there is no `this' field and no DW_AT_containing_type,
15762 we cannot actually find a base class context for the
15764 if (this_type
->num_fields () == 0
15765 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15767 complaint (_("cannot determine context for virtual member "
15768 "function \"%s\" (offset %s)"),
15769 fieldname
, sect_offset_str (die
->sect_off
));
15774 = TYPE_TARGET_TYPE (this_type
->field (0).type ());
15778 else if (attr
->form_is_section_offset ())
15780 dwarf2_complex_location_expr_complaint ();
15784 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15790 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15791 if (attr
!= nullptr && attr
->as_virtuality () != DW_VIRTUALITY_none
)
15793 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15794 complaint (_("Member function \"%s\" (offset %s) is virtual "
15795 "but the vtable offset is not specified"),
15796 fieldname
, sect_offset_str (die
->sect_off
));
15797 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15798 TYPE_CPLUS_DYNAMIC (type
) = 1;
15803 /* Create the vector of member function fields, and attach it to the type. */
15806 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15807 struct dwarf2_cu
*cu
)
15809 if (cu
->language
== language_ada
)
15810 error (_("unexpected member functions in Ada type"));
15812 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15813 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15815 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15817 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15819 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15820 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15822 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15823 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15824 fn_flp
->fn_fields
= (struct fn_field
*)
15825 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15827 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15828 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15831 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15834 /* Returns non-zero if NAME is the name of a vtable member in CU's
15835 language, zero otherwise. */
15837 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15839 static const char vptr
[] = "_vptr";
15841 /* Look for the C++ form of the vtable. */
15842 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15848 /* GCC outputs unnamed structures that are really pointers to member
15849 functions, with the ABI-specified layout. If TYPE describes
15850 such a structure, smash it into a member function type.
15852 GCC shouldn't do this; it should just output pointer to member DIEs.
15853 This is GCC PR debug/28767. */
15856 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15858 struct type
*pfn_type
, *self_type
, *new_type
;
15860 /* Check for a structure with no name and two children. */
15861 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15864 /* Check for __pfn and __delta members. */
15865 if (TYPE_FIELD_NAME (type
, 0) == NULL
15866 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15867 || TYPE_FIELD_NAME (type
, 1) == NULL
15868 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15871 /* Find the type of the method. */
15872 pfn_type
= type
->field (0).type ();
15873 if (pfn_type
== NULL
15874 || pfn_type
->code () != TYPE_CODE_PTR
15875 || TYPE_TARGET_TYPE (pfn_type
)->code () != TYPE_CODE_FUNC
)
15878 /* Look for the "this" argument. */
15879 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15880 if (pfn_type
->num_fields () == 0
15881 /* || pfn_type->field (0).type () == NULL */
15882 || pfn_type
->field (0).type ()->code () != TYPE_CODE_PTR
)
15885 self_type
= TYPE_TARGET_TYPE (pfn_type
->field (0).type ());
15886 new_type
= alloc_type (objfile
);
15887 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15888 pfn_type
->fields (), pfn_type
->num_fields (),
15889 pfn_type
->has_varargs ());
15890 smash_to_methodptr_type (type
, new_type
);
15893 /* While some versions of GCC will generate complicated DWARF for an
15894 array (see quirk_ada_thick_pointer), more recent versions were
15895 modified to emit an explicit thick pointer structure. However, in
15896 this case, the array still has DWARF expressions for its ranges,
15897 and these must be ignored. */
15900 quirk_ada_thick_pointer_struct (struct die_info
*die
, struct dwarf2_cu
*cu
,
15903 gdb_assert (cu
->language
== language_ada
);
15905 /* Check for a structure with two children. */
15906 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15909 /* Check for P_ARRAY and P_BOUNDS members. */
15910 if (TYPE_FIELD_NAME (type
, 0) == NULL
15911 || strcmp (TYPE_FIELD_NAME (type
, 0), "P_ARRAY") != 0
15912 || TYPE_FIELD_NAME (type
, 1) == NULL
15913 || strcmp (TYPE_FIELD_NAME (type
, 1), "P_BOUNDS") != 0)
15916 /* Make sure we're looking at a pointer to an array. */
15917 if (type
->field (0).type ()->code () != TYPE_CODE_PTR
)
15919 struct type
*ary_type
= TYPE_TARGET_TYPE (type
->field (0).type ());
15921 while (ary_type
->code () == TYPE_CODE_ARRAY
)
15923 /* The Ada code already knows how to handle these types, so all
15924 that we need to do is turn the bounds into static bounds. */
15925 struct type
*index_type
= ary_type
->index_type ();
15927 index_type
->bounds ()->low
.set_const_val (1);
15928 index_type
->bounds ()->high
.set_const_val (0);
15930 /* Handle multi-dimensional arrays. */
15931 ary_type
= TYPE_TARGET_TYPE (ary_type
);
15935 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15936 appropriate error checking and issuing complaints if there is a
15940 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15942 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15944 if (attr
== nullptr)
15947 if (!attr
->form_is_constant ())
15949 complaint (_("DW_AT_alignment must have constant form"
15950 " - DIE at %s [in module %s]"),
15951 sect_offset_str (die
->sect_off
),
15952 objfile_name (cu
->per_objfile
->objfile
));
15956 LONGEST val
= attr
->constant_value (0);
15959 complaint (_("DW_AT_alignment value must not be negative"
15960 " - DIE at %s [in module %s]"),
15961 sect_offset_str (die
->sect_off
),
15962 objfile_name (cu
->per_objfile
->objfile
));
15965 ULONGEST align
= val
;
15969 complaint (_("DW_AT_alignment value must not be zero"
15970 " - DIE at %s [in module %s]"),
15971 sect_offset_str (die
->sect_off
),
15972 objfile_name (cu
->per_objfile
->objfile
));
15975 if ((align
& (align
- 1)) != 0)
15977 complaint (_("DW_AT_alignment value must be a power of 2"
15978 " - DIE at %s [in module %s]"),
15979 sect_offset_str (die
->sect_off
),
15980 objfile_name (cu
->per_objfile
->objfile
));
15987 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15988 the alignment for TYPE. */
15991 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15994 if (!set_type_align (type
, get_alignment (cu
, die
)))
15995 complaint (_("DW_AT_alignment value too large"
15996 " - DIE at %s [in module %s]"),
15997 sect_offset_str (die
->sect_off
),
15998 objfile_name (cu
->per_objfile
->objfile
));
16001 /* Check if the given VALUE is a valid enum dwarf_calling_convention
16002 constant for a type, according to DWARF5 spec, Table 5.5. */
16005 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
16010 case DW_CC_pass_by_reference
:
16011 case DW_CC_pass_by_value
:
16015 complaint (_("unrecognized DW_AT_calling_convention value "
16016 "(%s) for a type"), pulongest (value
));
16021 /* Check if the given VALUE is a valid enum dwarf_calling_convention
16022 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
16023 also according to GNU-specific values (see include/dwarf2.h). */
16026 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
16031 case DW_CC_program
:
16035 case DW_CC_GNU_renesas_sh
:
16036 case DW_CC_GNU_borland_fastcall_i386
:
16037 case DW_CC_GDB_IBM_OpenCL
:
16041 complaint (_("unrecognized DW_AT_calling_convention value "
16042 "(%s) for a subroutine"), pulongest (value
));
16047 /* Called when we find the DIE that starts a structure or union scope
16048 (definition) to create a type for the structure or union. Fill in
16049 the type's name and general properties; the members will not be
16050 processed until process_structure_scope. A symbol table entry for
16051 the type will also not be done until process_structure_scope (assuming
16052 the type has a name).
16054 NOTE: we need to call these functions regardless of whether or not the
16055 DIE has a DW_AT_name attribute, since it might be an anonymous
16056 structure or union. This gets the type entered into our set of
16057 user defined types. */
16059 static struct type
*
16060 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16062 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16064 struct attribute
*attr
;
16067 /* If the definition of this type lives in .debug_types, read that type.
16068 Don't follow DW_AT_specification though, that will take us back up
16069 the chain and we want to go down. */
16070 attr
= die
->attr (DW_AT_signature
);
16071 if (attr
!= nullptr)
16073 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16075 /* The type's CU may not be the same as CU.
16076 Ensure TYPE is recorded with CU in die_type_hash. */
16077 return set_die_type (die
, type
, cu
);
16080 type
= alloc_type (objfile
);
16081 INIT_CPLUS_SPECIFIC (type
);
16083 name
= dwarf2_name (die
, cu
);
16086 if (cu
->language
== language_cplus
16087 || cu
->language
== language_d
16088 || cu
->language
== language_rust
)
16090 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
16092 /* dwarf2_full_name might have already finished building the DIE's
16093 type. If so, there is no need to continue. */
16094 if (get_die_type (die
, cu
) != NULL
)
16095 return get_die_type (die
, cu
);
16097 type
->set_name (full_name
);
16101 /* The name is already allocated along with this objfile, so
16102 we don't need to duplicate it for the type. */
16103 type
->set_name (name
);
16107 if (die
->tag
== DW_TAG_structure_type
)
16109 type
->set_code (TYPE_CODE_STRUCT
);
16111 else if (die
->tag
== DW_TAG_union_type
)
16113 type
->set_code (TYPE_CODE_UNION
);
16117 type
->set_code (TYPE_CODE_STRUCT
);
16120 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
16121 TYPE_DECLARED_CLASS (type
) = 1;
16123 /* Store the calling convention in the type if it's available in
16124 the die. Otherwise the calling convention remains set to
16125 the default value DW_CC_normal. */
16126 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
16127 if (attr
!= nullptr
16128 && is_valid_DW_AT_calling_convention_for_type (attr
->constant_value (0)))
16130 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16131 TYPE_CPLUS_CALLING_CONVENTION (type
)
16132 = (enum dwarf_calling_convention
) (attr
->constant_value (0));
16135 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16136 if (attr
!= nullptr)
16138 if (attr
->form_is_constant ())
16139 TYPE_LENGTH (type
) = attr
->constant_value (0);
16142 struct dynamic_prop prop
;
16143 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
16144 type
->add_dyn_prop (DYN_PROP_BYTE_SIZE
, prop
);
16145 TYPE_LENGTH (type
) = 0;
16150 TYPE_LENGTH (type
) = 0;
16153 maybe_set_alignment (cu
, die
, type
);
16155 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
16157 /* ICC<14 does not output the required DW_AT_declaration on
16158 incomplete types, but gives them a size of zero. */
16159 type
->set_is_stub (true);
16162 type
->set_stub_is_supported (true);
16164 if (die_is_declaration (die
, cu
))
16165 type
->set_is_stub (true);
16166 else if (attr
== NULL
&& die
->child
== NULL
16167 && producer_is_realview (cu
->producer
))
16168 /* RealView does not output the required DW_AT_declaration
16169 on incomplete types. */
16170 type
->set_is_stub (true);
16172 /* We need to add the type field to the die immediately so we don't
16173 infinitely recurse when dealing with pointers to the structure
16174 type within the structure itself. */
16175 set_die_type (die
, type
, cu
);
16177 /* set_die_type should be already done. */
16178 set_descriptive_type (type
, die
, cu
);
16183 static void handle_struct_member_die
16184 (struct die_info
*child_die
,
16186 struct field_info
*fi
,
16187 std::vector
<struct symbol
*> *template_args
,
16188 struct dwarf2_cu
*cu
);
16190 /* A helper for handle_struct_member_die that handles
16191 DW_TAG_variant_part. */
16194 handle_variant_part (struct die_info
*die
, struct type
*type
,
16195 struct field_info
*fi
,
16196 std::vector
<struct symbol
*> *template_args
,
16197 struct dwarf2_cu
*cu
)
16199 variant_part_builder
*new_part
;
16200 if (fi
->current_variant_part
== nullptr)
16202 fi
->variant_parts
.emplace_back ();
16203 new_part
= &fi
->variant_parts
.back ();
16205 else if (!fi
->current_variant_part
->processing_variant
)
16207 complaint (_("nested DW_TAG_variant_part seen "
16208 "- DIE at %s [in module %s]"),
16209 sect_offset_str (die
->sect_off
),
16210 objfile_name (cu
->per_objfile
->objfile
));
16215 variant_field
¤t
= fi
->current_variant_part
->variants
.back ();
16216 current
.variant_parts
.emplace_back ();
16217 new_part
= ¤t
.variant_parts
.back ();
16220 /* When we recurse, we want callees to add to this new variant
16222 scoped_restore save_current_variant_part
16223 = make_scoped_restore (&fi
->current_variant_part
, new_part
);
16225 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
16228 /* It's a univariant form, an extension we support. */
16230 else if (discr
->form_is_ref ())
16232 struct dwarf2_cu
*target_cu
= cu
;
16233 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
16235 new_part
->discriminant_offset
= target_die
->sect_off
;
16239 complaint (_("DW_AT_discr does not have DIE reference form"
16240 " - DIE at %s [in module %s]"),
16241 sect_offset_str (die
->sect_off
),
16242 objfile_name (cu
->per_objfile
->objfile
));
16245 for (die_info
*child_die
= die
->child
;
16247 child_die
= child_die
->sibling
)
16248 handle_struct_member_die (child_die
, type
, fi
, template_args
, cu
);
16251 /* A helper for handle_struct_member_die that handles
16255 handle_variant (struct die_info
*die
, struct type
*type
,
16256 struct field_info
*fi
,
16257 std::vector
<struct symbol
*> *template_args
,
16258 struct dwarf2_cu
*cu
)
16260 if (fi
->current_variant_part
== nullptr)
16262 complaint (_("saw DW_TAG_variant outside DW_TAG_variant_part "
16263 "- DIE at %s [in module %s]"),
16264 sect_offset_str (die
->sect_off
),
16265 objfile_name (cu
->per_objfile
->objfile
));
16268 if (fi
->current_variant_part
->processing_variant
)
16270 complaint (_("nested DW_TAG_variant seen "
16271 "- DIE at %s [in module %s]"),
16272 sect_offset_str (die
->sect_off
),
16273 objfile_name (cu
->per_objfile
->objfile
));
16277 scoped_restore save_processing_variant
16278 = make_scoped_restore (&fi
->current_variant_part
->processing_variant
,
16281 fi
->current_variant_part
->variants
.emplace_back ();
16282 variant_field
&variant
= fi
->current_variant_part
->variants
.back ();
16283 variant
.first_field
= fi
->fields
.size ();
16285 /* In a variant we want to get the discriminant and also add a
16286 field for our sole member child. */
16287 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr_value
, cu
);
16288 if (discr
== nullptr || !discr
->form_is_constant ())
16290 discr
= dwarf2_attr (die
, DW_AT_discr_list
, cu
);
16291 if (discr
== nullptr || discr
->as_block ()->size
== 0)
16292 variant
.default_branch
= true;
16294 variant
.discr_list_data
= discr
->as_block ();
16297 variant
.discriminant_value
= discr
->constant_value (0);
16299 for (die_info
*variant_child
= die
->child
;
16300 variant_child
!= NULL
;
16301 variant_child
= variant_child
->sibling
)
16302 handle_struct_member_die (variant_child
, type
, fi
, template_args
, cu
);
16304 variant
.last_field
= fi
->fields
.size ();
16307 /* A helper for process_structure_scope that handles a single member
16311 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
16312 struct field_info
*fi
,
16313 std::vector
<struct symbol
*> *template_args
,
16314 struct dwarf2_cu
*cu
)
16316 if (child_die
->tag
== DW_TAG_member
16317 || child_die
->tag
== DW_TAG_variable
)
16319 /* NOTE: carlton/2002-11-05: A C++ static data member
16320 should be a DW_TAG_member that is a declaration, but
16321 all versions of G++ as of this writing (so through at
16322 least 3.2.1) incorrectly generate DW_TAG_variable
16323 tags for them instead. */
16324 dwarf2_add_field (fi
, child_die
, cu
);
16326 else if (child_die
->tag
== DW_TAG_subprogram
)
16328 /* Rust doesn't have member functions in the C++ sense.
16329 However, it does emit ordinary functions as children
16330 of a struct DIE. */
16331 if (cu
->language
== language_rust
)
16332 read_func_scope (child_die
, cu
);
16335 /* C++ member function. */
16336 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
16339 else if (child_die
->tag
== DW_TAG_inheritance
)
16341 /* C++ base class field. */
16342 dwarf2_add_field (fi
, child_die
, cu
);
16344 else if (type_can_define_types (child_die
))
16345 dwarf2_add_type_defn (fi
, child_die
, cu
);
16346 else if (child_die
->tag
== DW_TAG_template_type_param
16347 || child_die
->tag
== DW_TAG_template_value_param
)
16349 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
16352 template_args
->push_back (arg
);
16354 else if (child_die
->tag
== DW_TAG_variant_part
)
16355 handle_variant_part (child_die
, type
, fi
, template_args
, cu
);
16356 else if (child_die
->tag
== DW_TAG_variant
)
16357 handle_variant (child_die
, type
, fi
, template_args
, cu
);
16360 /* Finish creating a structure or union type, including filling in
16361 its members and creating a symbol for it. */
16364 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16366 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16367 struct die_info
*child_die
;
16370 type
= get_die_type (die
, cu
);
16372 type
= read_structure_type (die
, cu
);
16374 bool has_template_parameters
= false;
16375 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
16377 struct field_info fi
;
16378 std::vector
<struct symbol
*> template_args
;
16380 child_die
= die
->child
;
16382 while (child_die
&& child_die
->tag
)
16384 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
16385 child_die
= child_die
->sibling
;
16388 /* Attach template arguments to type. */
16389 if (!template_args
.empty ())
16391 has_template_parameters
= true;
16392 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16393 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
16394 TYPE_TEMPLATE_ARGUMENTS (type
)
16395 = XOBNEWVEC (&objfile
->objfile_obstack
,
16397 TYPE_N_TEMPLATE_ARGUMENTS (type
));
16398 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
16399 template_args
.data (),
16400 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
16401 * sizeof (struct symbol
*)));
16404 /* Attach fields and member functions to the type. */
16405 if (fi
.nfields () > 0)
16406 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
16407 if (!fi
.fnfieldlists
.empty ())
16409 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
16411 /* Get the type which refers to the base class (possibly this
16412 class itself) which contains the vtable pointer for the current
16413 class from the DW_AT_containing_type attribute. This use of
16414 DW_AT_containing_type is a GNU extension. */
16416 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
16418 struct type
*t
= die_containing_type (die
, cu
);
16420 set_type_vptr_basetype (type
, t
);
16425 /* Our own class provides vtbl ptr. */
16426 for (i
= t
->num_fields () - 1;
16427 i
>= TYPE_N_BASECLASSES (t
);
16430 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
16432 if (is_vtable_name (fieldname
, cu
))
16434 set_type_vptr_fieldno (type
, i
);
16439 /* Complain if virtual function table field not found. */
16440 if (i
< TYPE_N_BASECLASSES (t
))
16441 complaint (_("virtual function table pointer "
16442 "not found when defining class '%s'"),
16443 type
->name () ? type
->name () : "");
16447 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
16450 else if (cu
->producer
16451 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
16453 /* The IBM XLC compiler does not provide direct indication
16454 of the containing type, but the vtable pointer is
16455 always named __vfp. */
16459 for (i
= type
->num_fields () - 1;
16460 i
>= TYPE_N_BASECLASSES (type
);
16463 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
16465 set_type_vptr_fieldno (type
, i
);
16466 set_type_vptr_basetype (type
, type
);
16473 /* Copy fi.typedef_field_list linked list elements content into the
16474 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
16475 if (!fi
.typedef_field_list
.empty ())
16477 int count
= fi
.typedef_field_list
.size ();
16479 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16480 TYPE_TYPEDEF_FIELD_ARRAY (type
)
16481 = ((struct decl_field
*)
16483 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
16484 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
16486 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
16487 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
16490 /* Copy fi.nested_types_list linked list elements content into the
16491 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
16492 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
16494 int count
= fi
.nested_types_list
.size ();
16496 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16497 TYPE_NESTED_TYPES_ARRAY (type
)
16498 = ((struct decl_field
*)
16499 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
16500 TYPE_NESTED_TYPES_COUNT (type
) = count
;
16502 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
16503 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
16507 quirk_gcc_member_function_pointer (type
, objfile
);
16508 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
16509 cu
->rust_unions
.push_back (type
);
16510 else if (cu
->language
== language_ada
)
16511 quirk_ada_thick_pointer_struct (die
, cu
, type
);
16513 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
16514 snapshots) has been known to create a die giving a declaration
16515 for a class that has, as a child, a die giving a definition for a
16516 nested class. So we have to process our children even if the
16517 current die is a declaration. Normally, of course, a declaration
16518 won't have any children at all. */
16520 child_die
= die
->child
;
16522 while (child_die
!= NULL
&& child_die
->tag
)
16524 if (child_die
->tag
== DW_TAG_member
16525 || child_die
->tag
== DW_TAG_variable
16526 || child_die
->tag
== DW_TAG_inheritance
16527 || child_die
->tag
== DW_TAG_template_value_param
16528 || child_die
->tag
== DW_TAG_template_type_param
)
16533 process_die (child_die
, cu
);
16535 child_die
= child_die
->sibling
;
16538 /* Do not consider external references. According to the DWARF standard,
16539 these DIEs are identified by the fact that they have no byte_size
16540 attribute, and a declaration attribute. */
16541 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
16542 || !die_is_declaration (die
, cu
)
16543 || dwarf2_attr (die
, DW_AT_signature
, cu
) != NULL
)
16545 struct symbol
*sym
= new_symbol (die
, type
, cu
);
16547 if (has_template_parameters
)
16549 struct symtab
*symtab
;
16550 if (sym
!= nullptr)
16551 symtab
= symbol_symtab (sym
);
16552 else if (cu
->line_header
!= nullptr)
16554 /* Any related symtab will do. */
16556 = cu
->line_header
->file_names ()[0].symtab
;
16561 complaint (_("could not find suitable "
16562 "symtab for template parameter"
16563 " - DIE at %s [in module %s]"),
16564 sect_offset_str (die
->sect_off
),
16565 objfile_name (objfile
));
16568 if (symtab
!= nullptr)
16570 /* Make sure that the symtab is set on the new symbols.
16571 Even though they don't appear in this symtab directly,
16572 other parts of gdb assume that symbols do, and this is
16573 reasonably true. */
16574 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
16575 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
16581 /* Assuming DIE is an enumeration type, and TYPE is its associated
16582 type, update TYPE using some information only available in DIE's
16583 children. In particular, the fields are computed. */
16586 update_enumeration_type_from_children (struct die_info
*die
,
16588 struct dwarf2_cu
*cu
)
16590 struct die_info
*child_die
;
16591 int unsigned_enum
= 1;
16594 auto_obstack obstack
;
16595 std::vector
<struct field
> fields
;
16597 for (child_die
= die
->child
;
16598 child_die
!= NULL
&& child_die
->tag
;
16599 child_die
= child_die
->sibling
)
16601 struct attribute
*attr
;
16603 const gdb_byte
*bytes
;
16604 struct dwarf2_locexpr_baton
*baton
;
16607 if (child_die
->tag
!= DW_TAG_enumerator
)
16610 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16614 name
= dwarf2_name (child_die
, cu
);
16616 name
= "<anonymous enumerator>";
16618 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16619 &value
, &bytes
, &baton
);
16627 if (count_one_bits_ll (value
) >= 2)
16631 fields
.emplace_back ();
16632 struct field
&field
= fields
.back ();
16633 FIELD_NAME (field
) = dwarf2_physname (name
, child_die
, cu
);
16634 SET_FIELD_ENUMVAL (field
, value
);
16637 if (!fields
.empty ())
16639 type
->set_num_fields (fields
.size ());
16642 TYPE_ALLOC (type
, sizeof (struct field
) * fields
.size ()));
16643 memcpy (type
->fields (), fields
.data (),
16644 sizeof (struct field
) * fields
.size ());
16648 type
->set_is_unsigned (true);
16651 TYPE_FLAG_ENUM (type
) = 1;
16654 /* Given a DW_AT_enumeration_type die, set its type. We do not
16655 complete the type's fields yet, or create any symbols. */
16657 static struct type
*
16658 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16660 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16662 struct attribute
*attr
;
16665 /* If the definition of this type lives in .debug_types, read that type.
16666 Don't follow DW_AT_specification though, that will take us back up
16667 the chain and we want to go down. */
16668 attr
= die
->attr (DW_AT_signature
);
16669 if (attr
!= nullptr)
16671 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16673 /* The type's CU may not be the same as CU.
16674 Ensure TYPE is recorded with CU in die_type_hash. */
16675 return set_die_type (die
, type
, cu
);
16678 type
= alloc_type (objfile
);
16680 type
->set_code (TYPE_CODE_ENUM
);
16681 name
= dwarf2_full_name (NULL
, die
, cu
);
16683 type
->set_name (name
);
16685 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16688 struct type
*underlying_type
= die_type (die
, cu
);
16690 TYPE_TARGET_TYPE (type
) = underlying_type
;
16693 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16694 if (attr
!= nullptr)
16696 TYPE_LENGTH (type
) = attr
->constant_value (0);
16700 TYPE_LENGTH (type
) = 0;
16703 maybe_set_alignment (cu
, die
, type
);
16705 /* The enumeration DIE can be incomplete. In Ada, any type can be
16706 declared as private in the package spec, and then defined only
16707 inside the package body. Such types are known as Taft Amendment
16708 Types. When another package uses such a type, an incomplete DIE
16709 may be generated by the compiler. */
16710 if (die_is_declaration (die
, cu
))
16711 type
->set_is_stub (true);
16713 /* If this type has an underlying type that is not a stub, then we
16714 may use its attributes. We always use the "unsigned" attribute
16715 in this situation, because ordinarily we guess whether the type
16716 is unsigned -- but the guess can be wrong and the underlying type
16717 can tell us the reality. However, we defer to a local size
16718 attribute if one exists, because this lets the compiler override
16719 the underlying type if needed. */
16720 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_TARGET_TYPE (type
)->is_stub ())
16722 struct type
*underlying_type
= TYPE_TARGET_TYPE (type
);
16723 underlying_type
= check_typedef (underlying_type
);
16725 type
->set_is_unsigned (underlying_type
->is_unsigned ());
16727 if (TYPE_LENGTH (type
) == 0)
16728 TYPE_LENGTH (type
) = TYPE_LENGTH (underlying_type
);
16730 if (TYPE_RAW_ALIGN (type
) == 0
16731 && TYPE_RAW_ALIGN (underlying_type
) != 0)
16732 set_type_align (type
, TYPE_RAW_ALIGN (underlying_type
));
16735 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16737 set_die_type (die
, type
, cu
);
16739 /* Finish the creation of this type by using the enum's children.
16740 Note that, as usual, this must come after set_die_type to avoid
16741 infinite recursion when trying to compute the names of the
16743 update_enumeration_type_from_children (die
, type
, cu
);
16748 /* Given a pointer to a die which begins an enumeration, process all
16749 the dies that define the members of the enumeration, and create the
16750 symbol for the enumeration type.
16752 NOTE: We reverse the order of the element list. */
16755 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16757 struct type
*this_type
;
16759 this_type
= get_die_type (die
, cu
);
16760 if (this_type
== NULL
)
16761 this_type
= read_enumeration_type (die
, cu
);
16763 if (die
->child
!= NULL
)
16765 struct die_info
*child_die
;
16768 child_die
= die
->child
;
16769 while (child_die
&& child_die
->tag
)
16771 if (child_die
->tag
!= DW_TAG_enumerator
)
16773 process_die (child_die
, cu
);
16777 name
= dwarf2_name (child_die
, cu
);
16779 new_symbol (child_die
, this_type
, cu
);
16782 child_die
= child_die
->sibling
;
16786 /* If we are reading an enum from a .debug_types unit, and the enum
16787 is a declaration, and the enum is not the signatured type in the
16788 unit, then we do not want to add a symbol for it. Adding a
16789 symbol would in some cases obscure the true definition of the
16790 enum, giving users an incomplete type when the definition is
16791 actually available. Note that we do not want to do this for all
16792 enums which are just declarations, because C++0x allows forward
16793 enum declarations. */
16794 if (cu
->per_cu
->is_debug_types
16795 && die_is_declaration (die
, cu
))
16797 struct signatured_type
*sig_type
;
16799 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16800 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16801 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16805 new_symbol (die
, this_type
, cu
);
16808 /* Helper function for quirk_ada_thick_pointer that examines a bounds
16809 expression for an index type and finds the corresponding field
16810 offset in the hidden "P_BOUNDS" structure. Returns true on success
16811 and updates *FIELD, false if it fails to recognize an
16815 recognize_bound_expression (struct die_info
*die
, enum dwarf_attribute name
,
16816 int *bounds_offset
, struct field
*field
,
16817 struct dwarf2_cu
*cu
)
16819 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
16820 if (attr
== nullptr || !attr
->form_is_block ())
16823 const struct dwarf_block
*block
= attr
->as_block ();
16824 const gdb_byte
*start
= block
->data
;
16825 const gdb_byte
*end
= block
->data
+ block
->size
;
16827 /* The expression to recognize generally looks like:
16829 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16830 DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
16832 However, the second "plus_uconst" may be missing:
16834 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16835 DW_OP_deref_size: 4)
16837 This happens when the field is at the start of the structure.
16839 Also, the final deref may not be sized:
16841 (DW_OP_push_object_address; DW_OP_plus_uconst: 4; DW_OP_deref;
16844 This happens when the size of the index type happens to be the
16845 same as the architecture's word size. This can occur with or
16846 without the second plus_uconst. */
16848 if (end
- start
< 2)
16850 if (*start
++ != DW_OP_push_object_address
)
16852 if (*start
++ != DW_OP_plus_uconst
)
16855 uint64_t this_bound_off
;
16856 start
= gdb_read_uleb128 (start
, end
, &this_bound_off
);
16857 if (start
== nullptr || (int) this_bound_off
!= this_bound_off
)
16859 /* Update *BOUNDS_OFFSET if needed, or alternatively verify that it
16860 is consistent among all bounds. */
16861 if (*bounds_offset
== -1)
16862 *bounds_offset
= this_bound_off
;
16863 else if (*bounds_offset
!= this_bound_off
)
16866 if (start
== end
|| *start
++ != DW_OP_deref
)
16872 else if (*start
== DW_OP_deref_size
|| *start
== DW_OP_deref
)
16874 /* This means an offset of 0. */
16876 else if (*start
++ != DW_OP_plus_uconst
)
16880 /* The size is the parameter to DW_OP_plus_uconst. */
16882 start
= gdb_read_uleb128 (start
, end
, &val
);
16883 if (start
== nullptr)
16885 if ((int) val
!= val
)
16894 if (*start
== DW_OP_deref_size
)
16896 start
= gdb_read_uleb128 (start
+ 1, end
, &size
);
16897 if (start
== nullptr)
16900 else if (*start
== DW_OP_deref
)
16902 size
= cu
->header
.addr_size
;
16908 SET_FIELD_BITPOS (*field
, 8 * offset
);
16909 if (size
!= TYPE_LENGTH (field
->type ()))
16910 FIELD_BITSIZE (*field
) = 8 * size
;
16915 /* With -fgnat-encodings=minimal, gcc will emit some unusual DWARF for
16916 some kinds of Ada arrays:
16918 <1><11db>: Abbrev Number: 7 (DW_TAG_array_type)
16919 <11dc> DW_AT_name : (indirect string, offset: 0x1bb8): string
16920 <11e0> DW_AT_data_location: 2 byte block: 97 6
16921 (DW_OP_push_object_address; DW_OP_deref)
16922 <11e3> DW_AT_type : <0x1173>
16923 <11e7> DW_AT_sibling : <0x1201>
16924 <2><11eb>: Abbrev Number: 8 (DW_TAG_subrange_type)
16925 <11ec> DW_AT_type : <0x1206>
16926 <11f0> DW_AT_lower_bound : 6 byte block: 97 23 8 6 94 4
16927 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16928 DW_OP_deref_size: 4)
16929 <11f7> DW_AT_upper_bound : 8 byte block: 97 23 8 6 23 4 94 4
16930 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16931 DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
16933 This actually represents a "thick pointer", which is a structure
16934 with two elements: one that is a pointer to the array data, and one
16935 that is a pointer to another structure; this second structure holds
16938 This returns a new type on success, or nullptr if this didn't
16939 recognize the type. */
16941 static struct type
*
16942 quirk_ada_thick_pointer (struct die_info
*die
, struct dwarf2_cu
*cu
,
16945 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
16946 /* So far we've only seen this with block form. */
16947 if (attr
== nullptr || !attr
->form_is_block ())
16950 /* Note that this will fail if the structure layout is changed by
16951 the compiler. However, we have no good way to recognize some
16952 other layout, because we don't know what expression the compiler
16953 might choose to emit should this happen. */
16954 struct dwarf_block
*blk
= attr
->as_block ();
16956 || blk
->data
[0] != DW_OP_push_object_address
16957 || blk
->data
[1] != DW_OP_deref
)
16960 int bounds_offset
= -1;
16961 int max_align
= -1;
16962 std::vector
<struct field
> range_fields
;
16963 for (struct die_info
*child_die
= die
->child
;
16965 child_die
= child_die
->sibling
)
16967 if (child_die
->tag
== DW_TAG_subrange_type
)
16969 struct type
*underlying
= read_subrange_index_type (child_die
, cu
);
16971 int this_align
= type_align (underlying
);
16972 if (this_align
> max_align
)
16973 max_align
= this_align
;
16975 range_fields
.emplace_back ();
16976 range_fields
.emplace_back ();
16978 struct field
&lower
= range_fields
[range_fields
.size () - 2];
16979 struct field
&upper
= range_fields
[range_fields
.size () - 1];
16981 lower
.set_type (underlying
);
16982 FIELD_ARTIFICIAL (lower
) = 1;
16984 upper
.set_type (underlying
);
16985 FIELD_ARTIFICIAL (upper
) = 1;
16987 if (!recognize_bound_expression (child_die
, DW_AT_lower_bound
,
16988 &bounds_offset
, &lower
, cu
)
16989 || !recognize_bound_expression (child_die
, DW_AT_upper_bound
,
16990 &bounds_offset
, &upper
, cu
))
16995 /* This shouldn't really happen, but double-check that we found
16996 where the bounds are stored. */
16997 if (bounds_offset
== -1)
17000 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17001 for (int i
= 0; i
< range_fields
.size (); i
+= 2)
17005 /* Set the name of each field in the bounds. */
17006 xsnprintf (name
, sizeof (name
), "LB%d", i
/ 2);
17007 FIELD_NAME (range_fields
[i
]) = objfile
->intern (name
);
17008 xsnprintf (name
, sizeof (name
), "UB%d", i
/ 2);
17009 FIELD_NAME (range_fields
[i
+ 1]) = objfile
->intern (name
);
17012 struct type
*bounds
= alloc_type (objfile
);
17013 bounds
->set_code (TYPE_CODE_STRUCT
);
17015 bounds
->set_num_fields (range_fields
.size ());
17017 ((struct field
*) TYPE_ALLOC (bounds
, (bounds
->num_fields ()
17018 * sizeof (struct field
))));
17019 memcpy (bounds
->fields (), range_fields
.data (),
17020 bounds
->num_fields () * sizeof (struct field
));
17022 int last_fieldno
= range_fields
.size () - 1;
17023 int bounds_size
= (TYPE_FIELD_BITPOS (bounds
, last_fieldno
) / 8
17024 + TYPE_LENGTH (bounds
->field (last_fieldno
).type ()));
17025 TYPE_LENGTH (bounds
) = align_up (bounds_size
, max_align
);
17027 /* Rewrite the existing array type in place. Specifically, we
17028 remove any dynamic properties we might have read, and we replace
17029 the index types. */
17030 struct type
*iter
= type
;
17031 for (int i
= 0; i
< range_fields
.size (); i
+= 2)
17033 gdb_assert (iter
->code () == TYPE_CODE_ARRAY
);
17034 iter
->main_type
->dyn_prop_list
= nullptr;
17035 iter
->set_index_type
17036 (create_static_range_type (NULL
, bounds
->field (i
).type (), 1, 0));
17037 iter
= TYPE_TARGET_TYPE (iter
);
17040 struct type
*result
= alloc_type (objfile
);
17041 result
->set_code (TYPE_CODE_STRUCT
);
17043 result
->set_num_fields (2);
17045 ((struct field
*) TYPE_ZALLOC (result
, (result
->num_fields ()
17046 * sizeof (struct field
))));
17048 /* The names are chosen to coincide with what the compiler does with
17049 -fgnat-encodings=all, which the Ada code in gdb already
17051 TYPE_FIELD_NAME (result
, 0) = "P_ARRAY";
17052 result
->field (0).set_type (lookup_pointer_type (type
));
17054 TYPE_FIELD_NAME (result
, 1) = "P_BOUNDS";
17055 result
->field (1).set_type (lookup_pointer_type (bounds
));
17056 SET_FIELD_BITPOS (result
->field (1), 8 * bounds_offset
);
17058 result
->set_name (type
->name ());
17059 TYPE_LENGTH (result
) = (TYPE_LENGTH (result
->field (0).type ())
17060 + TYPE_LENGTH (result
->field (1).type ()));
17065 /* Extract all information from a DW_TAG_array_type DIE and put it in
17066 the DIE's type field. For now, this only handles one dimensional
17069 static struct type
*
17070 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17072 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17073 struct die_info
*child_die
;
17075 struct type
*element_type
, *range_type
, *index_type
;
17076 struct attribute
*attr
;
17078 struct dynamic_prop
*byte_stride_prop
= NULL
;
17079 unsigned int bit_stride
= 0;
17081 element_type
= die_type (die
, cu
);
17083 /* The die_type call above may have already set the type for this DIE. */
17084 type
= get_die_type (die
, cu
);
17088 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
17092 struct type
*prop_type
= cu
->addr_sized_int_type (false);
17095 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
17096 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
17100 complaint (_("unable to read array DW_AT_byte_stride "
17101 " - DIE at %s [in module %s]"),
17102 sect_offset_str (die
->sect_off
),
17103 objfile_name (cu
->per_objfile
->objfile
));
17104 /* Ignore this attribute. We will likely not be able to print
17105 arrays of this type correctly, but there is little we can do
17106 to help if we cannot read the attribute's value. */
17107 byte_stride_prop
= NULL
;
17111 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
17113 bit_stride
= attr
->constant_value (0);
17115 /* Irix 6.2 native cc creates array types without children for
17116 arrays with unspecified length. */
17117 if (die
->child
== NULL
)
17119 index_type
= objfile_type (objfile
)->builtin_int
;
17120 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
17121 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
17122 byte_stride_prop
, bit_stride
);
17123 return set_die_type (die
, type
, cu
);
17126 std::vector
<struct type
*> range_types
;
17127 child_die
= die
->child
;
17128 while (child_die
&& child_die
->tag
)
17130 if (child_die
->tag
== DW_TAG_subrange_type
)
17132 struct type
*child_type
= read_type_die (child_die
, cu
);
17134 if (child_type
!= NULL
)
17136 /* The range type was succesfully read. Save it for the
17137 array type creation. */
17138 range_types
.push_back (child_type
);
17141 child_die
= child_die
->sibling
;
17144 /* Dwarf2 dimensions are output from left to right, create the
17145 necessary array types in backwards order. */
17147 type
= element_type
;
17149 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
17153 while (i
< range_types
.size ())
17155 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
17156 byte_stride_prop
, bit_stride
);
17158 byte_stride_prop
= nullptr;
17163 size_t ndim
= range_types
.size ();
17166 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
17167 byte_stride_prop
, bit_stride
);
17169 byte_stride_prop
= nullptr;
17173 /* Understand Dwarf2 support for vector types (like they occur on
17174 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
17175 array type. This is not part of the Dwarf2/3 standard yet, but a
17176 custom vendor extension. The main difference between a regular
17177 array and the vector variant is that vectors are passed by value
17179 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
17180 if (attr
!= nullptr)
17181 make_vector_type (type
);
17183 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
17184 implementation may choose to implement triple vectors using this
17186 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17187 if (attr
!= nullptr && attr
->form_is_unsigned ())
17189 if (attr
->as_unsigned () >= TYPE_LENGTH (type
))
17190 TYPE_LENGTH (type
) = attr
->as_unsigned ();
17192 complaint (_("DW_AT_byte_size for array type smaller "
17193 "than the total size of elements"));
17196 name
= dwarf2_name (die
, cu
);
17198 type
->set_name (name
);
17200 maybe_set_alignment (cu
, die
, type
);
17202 struct type
*replacement_type
= nullptr;
17203 if (cu
->language
== language_ada
)
17205 replacement_type
= quirk_ada_thick_pointer (die
, cu
, type
);
17206 if (replacement_type
!= nullptr)
17207 type
= replacement_type
;
17210 /* Install the type in the die. */
17211 set_die_type (die
, type
, cu
, replacement_type
!= nullptr);
17213 /* set_die_type should be already done. */
17214 set_descriptive_type (type
, die
, cu
);
17219 static enum dwarf_array_dim_ordering
17220 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
17222 struct attribute
*attr
;
17224 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
17226 if (attr
!= nullptr)
17228 LONGEST val
= attr
->constant_value (-1);
17229 if (val
== DW_ORD_row_major
|| val
== DW_ORD_col_major
)
17230 return (enum dwarf_array_dim_ordering
) val
;
17233 /* GNU F77 is a special case, as at 08/2004 array type info is the
17234 opposite order to the dwarf2 specification, but data is still
17235 laid out as per normal fortran.
17237 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
17238 version checking. */
17240 if (cu
->language
== language_fortran
17241 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
17243 return DW_ORD_row_major
;
17246 switch (cu
->language_defn
->array_ordering ())
17248 case array_column_major
:
17249 return DW_ORD_col_major
;
17250 case array_row_major
:
17252 return DW_ORD_row_major
;
17256 /* Extract all information from a DW_TAG_set_type DIE and put it in
17257 the DIE's type field. */
17259 static struct type
*
17260 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17262 struct type
*domain_type
, *set_type
;
17263 struct attribute
*attr
;
17265 domain_type
= die_type (die
, cu
);
17267 /* The die_type call above may have already set the type for this DIE. */
17268 set_type
= get_die_type (die
, cu
);
17272 set_type
= create_set_type (NULL
, domain_type
);
17274 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17275 if (attr
!= nullptr && attr
->form_is_unsigned ())
17276 TYPE_LENGTH (set_type
) = attr
->as_unsigned ();
17278 maybe_set_alignment (cu
, die
, set_type
);
17280 return set_die_type (die
, set_type
, cu
);
17283 /* A helper for read_common_block that creates a locexpr baton.
17284 SYM is the symbol which we are marking as computed.
17285 COMMON_DIE is the DIE for the common block.
17286 COMMON_LOC is the location expression attribute for the common
17288 MEMBER_LOC is the location expression attribute for the particular
17289 member of the common block that we are processing.
17290 CU is the CU from which the above come. */
17293 mark_common_block_symbol_computed (struct symbol
*sym
,
17294 struct die_info
*common_die
,
17295 struct attribute
*common_loc
,
17296 struct attribute
*member_loc
,
17297 struct dwarf2_cu
*cu
)
17299 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
17300 struct objfile
*objfile
= per_objfile
->objfile
;
17301 struct dwarf2_locexpr_baton
*baton
;
17303 unsigned int cu_off
;
17304 enum bfd_endian byte_order
= gdbarch_byte_order (objfile
->arch ());
17305 LONGEST offset
= 0;
17307 gdb_assert (common_loc
&& member_loc
);
17308 gdb_assert (common_loc
->form_is_block ());
17309 gdb_assert (member_loc
->form_is_block ()
17310 || member_loc
->form_is_constant ());
17312 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
17313 baton
->per_objfile
= per_objfile
;
17314 baton
->per_cu
= cu
->per_cu
;
17315 gdb_assert (baton
->per_cu
);
17317 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
17319 if (member_loc
->form_is_constant ())
17321 offset
= member_loc
->constant_value (0);
17322 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
17325 baton
->size
+= member_loc
->as_block ()->size
;
17327 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
17330 *ptr
++ = DW_OP_call4
;
17331 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
17332 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
17335 if (member_loc
->form_is_constant ())
17337 *ptr
++ = DW_OP_addr
;
17338 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
17339 ptr
+= cu
->header
.addr_size
;
17343 /* We have to copy the data here, because DW_OP_call4 will only
17344 use a DW_AT_location attribute. */
17345 struct dwarf_block
*block
= member_loc
->as_block ();
17346 memcpy (ptr
, block
->data
, block
->size
);
17347 ptr
+= block
->size
;
17350 *ptr
++ = DW_OP_plus
;
17351 gdb_assert (ptr
- baton
->data
== baton
->size
);
17353 SYMBOL_LOCATION_BATON (sym
) = baton
;
17354 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
17357 /* Create appropriate locally-scoped variables for all the
17358 DW_TAG_common_block entries. Also create a struct common_block
17359 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
17360 is used to separate the common blocks name namespace from regular
17364 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
17366 struct attribute
*attr
;
17368 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
17369 if (attr
!= nullptr)
17371 /* Support the .debug_loc offsets. */
17372 if (attr
->form_is_block ())
17376 else if (attr
->form_is_section_offset ())
17378 dwarf2_complex_location_expr_complaint ();
17383 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17384 "common block member");
17389 if (die
->child
!= NULL
)
17391 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17392 struct die_info
*child_die
;
17393 size_t n_entries
= 0, size
;
17394 struct common_block
*common_block
;
17395 struct symbol
*sym
;
17397 for (child_die
= die
->child
;
17398 child_die
&& child_die
->tag
;
17399 child_die
= child_die
->sibling
)
17402 size
= (sizeof (struct common_block
)
17403 + (n_entries
- 1) * sizeof (struct symbol
*));
17405 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
17407 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
17408 common_block
->n_entries
= 0;
17410 for (child_die
= die
->child
;
17411 child_die
&& child_die
->tag
;
17412 child_die
= child_die
->sibling
)
17414 /* Create the symbol in the DW_TAG_common_block block in the current
17416 sym
= new_symbol (child_die
, NULL
, cu
);
17419 struct attribute
*member_loc
;
17421 common_block
->contents
[common_block
->n_entries
++] = sym
;
17423 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
17427 /* GDB has handled this for a long time, but it is
17428 not specified by DWARF. It seems to have been
17429 emitted by gfortran at least as recently as:
17430 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
17431 complaint (_("Variable in common block has "
17432 "DW_AT_data_member_location "
17433 "- DIE at %s [in module %s]"),
17434 sect_offset_str (child_die
->sect_off
),
17435 objfile_name (objfile
));
17437 if (member_loc
->form_is_section_offset ())
17438 dwarf2_complex_location_expr_complaint ();
17439 else if (member_loc
->form_is_constant ()
17440 || member_loc
->form_is_block ())
17442 if (attr
!= nullptr)
17443 mark_common_block_symbol_computed (sym
, die
, attr
,
17447 dwarf2_complex_location_expr_complaint ();
17452 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
17453 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
17457 /* Create a type for a C++ namespace. */
17459 static struct type
*
17460 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17462 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17463 const char *previous_prefix
, *name
;
17467 /* For extensions, reuse the type of the original namespace. */
17468 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
17470 struct die_info
*ext_die
;
17471 struct dwarf2_cu
*ext_cu
= cu
;
17473 ext_die
= dwarf2_extension (die
, &ext_cu
);
17474 type
= read_type_die (ext_die
, ext_cu
);
17476 /* EXT_CU may not be the same as CU.
17477 Ensure TYPE is recorded with CU in die_type_hash. */
17478 return set_die_type (die
, type
, cu
);
17481 name
= namespace_name (die
, &is_anonymous
, cu
);
17483 /* Now build the name of the current namespace. */
17485 previous_prefix
= determine_prefix (die
, cu
);
17486 if (previous_prefix
[0] != '\0')
17487 name
= typename_concat (&objfile
->objfile_obstack
,
17488 previous_prefix
, name
, 0, cu
);
17490 /* Create the type. */
17491 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
17493 return set_die_type (die
, type
, cu
);
17496 /* Read a namespace scope. */
17499 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
17501 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17504 /* Add a symbol associated to this if we haven't seen the namespace
17505 before. Also, add a using directive if it's an anonymous
17508 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
17512 type
= read_type_die (die
, cu
);
17513 new_symbol (die
, type
, cu
);
17515 namespace_name (die
, &is_anonymous
, cu
);
17518 const char *previous_prefix
= determine_prefix (die
, cu
);
17520 std::vector
<const char *> excludes
;
17521 add_using_directive (using_directives (cu
),
17522 previous_prefix
, type
->name (), NULL
,
17523 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
17527 if (die
->child
!= NULL
)
17529 struct die_info
*child_die
= die
->child
;
17531 while (child_die
&& child_die
->tag
)
17533 process_die (child_die
, cu
);
17534 child_die
= child_die
->sibling
;
17539 /* Read a Fortran module as type. This DIE can be only a declaration used for
17540 imported module. Still we need that type as local Fortran "use ... only"
17541 declaration imports depend on the created type in determine_prefix. */
17543 static struct type
*
17544 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17546 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17547 const char *module_name
;
17550 module_name
= dwarf2_name (die
, cu
);
17551 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
17553 return set_die_type (die
, type
, cu
);
17556 /* Read a Fortran module. */
17559 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
17561 struct die_info
*child_die
= die
->child
;
17564 type
= read_type_die (die
, cu
);
17565 new_symbol (die
, type
, cu
);
17567 while (child_die
&& child_die
->tag
)
17569 process_die (child_die
, cu
);
17570 child_die
= child_die
->sibling
;
17574 /* Return the name of the namespace represented by DIE. Set
17575 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
17578 static const char *
17579 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
17581 struct die_info
*current_die
;
17582 const char *name
= NULL
;
17584 /* Loop through the extensions until we find a name. */
17586 for (current_die
= die
;
17587 current_die
!= NULL
;
17588 current_die
= dwarf2_extension (die
, &cu
))
17590 /* We don't use dwarf2_name here so that we can detect the absence
17591 of a name -> anonymous namespace. */
17592 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
17598 /* Is it an anonymous namespace? */
17600 *is_anonymous
= (name
== NULL
);
17602 name
= CP_ANONYMOUS_NAMESPACE_STR
;
17607 /* Extract all information from a DW_TAG_pointer_type DIE and add to
17608 the user defined type vector. */
17610 static struct type
*
17611 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17613 struct gdbarch
*gdbarch
= cu
->per_objfile
->objfile
->arch ();
17614 struct comp_unit_head
*cu_header
= &cu
->header
;
17616 struct attribute
*attr_byte_size
;
17617 struct attribute
*attr_address_class
;
17618 int byte_size
, addr_class
;
17619 struct type
*target_type
;
17621 target_type
= die_type (die
, cu
);
17623 /* The die_type call above may have already set the type for this DIE. */
17624 type
= get_die_type (die
, cu
);
17628 type
= lookup_pointer_type (target_type
);
17630 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17631 if (attr_byte_size
)
17632 byte_size
= attr_byte_size
->constant_value (cu_header
->addr_size
);
17634 byte_size
= cu_header
->addr_size
;
17636 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
17637 if (attr_address_class
)
17638 addr_class
= attr_address_class
->constant_value (DW_ADDR_none
);
17640 addr_class
= DW_ADDR_none
;
17642 ULONGEST alignment
= get_alignment (cu
, die
);
17644 /* If the pointer size, alignment, or address class is different
17645 than the default, create a type variant marked as such and set
17646 the length accordingly. */
17647 if (TYPE_LENGTH (type
) != byte_size
17648 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
17649 && alignment
!= TYPE_RAW_ALIGN (type
))
17650 || addr_class
!= DW_ADDR_none
)
17652 if (gdbarch_address_class_type_flags_p (gdbarch
))
17654 type_instance_flags type_flags
17655 = gdbarch_address_class_type_flags (gdbarch
, byte_size
,
17657 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
17659 type
= make_type_with_address_space (type
, type_flags
);
17661 else if (TYPE_LENGTH (type
) != byte_size
)
17663 complaint (_("invalid pointer size %d"), byte_size
);
17665 else if (TYPE_RAW_ALIGN (type
) != alignment
)
17667 complaint (_("Invalid DW_AT_alignment"
17668 " - DIE at %s [in module %s]"),
17669 sect_offset_str (die
->sect_off
),
17670 objfile_name (cu
->per_objfile
->objfile
));
17674 /* Should we also complain about unhandled address classes? */
17678 TYPE_LENGTH (type
) = byte_size
;
17679 set_type_align (type
, alignment
);
17680 return set_die_type (die
, type
, cu
);
17683 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
17684 the user defined type vector. */
17686 static struct type
*
17687 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17690 struct type
*to_type
;
17691 struct type
*domain
;
17693 to_type
= die_type (die
, cu
);
17694 domain
= die_containing_type (die
, cu
);
17696 /* The calls above may have already set the type for this DIE. */
17697 type
= get_die_type (die
, cu
);
17701 if (check_typedef (to_type
)->code () == TYPE_CODE_METHOD
)
17702 type
= lookup_methodptr_type (to_type
);
17703 else if (check_typedef (to_type
)->code () == TYPE_CODE_FUNC
)
17705 struct type
*new_type
= alloc_type (cu
->per_objfile
->objfile
);
17707 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
17708 to_type
->fields (), to_type
->num_fields (),
17709 to_type
->has_varargs ());
17710 type
= lookup_methodptr_type (new_type
);
17713 type
= lookup_memberptr_type (to_type
, domain
);
17715 return set_die_type (die
, type
, cu
);
17718 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
17719 the user defined type vector. */
17721 static struct type
*
17722 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17723 enum type_code refcode
)
17725 struct comp_unit_head
*cu_header
= &cu
->header
;
17726 struct type
*type
, *target_type
;
17727 struct attribute
*attr
;
17729 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
17731 target_type
= die_type (die
, cu
);
17733 /* The die_type call above may have already set the type for this DIE. */
17734 type
= get_die_type (die
, cu
);
17738 type
= lookup_reference_type (target_type
, refcode
);
17739 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17740 if (attr
!= nullptr)
17742 TYPE_LENGTH (type
) = attr
->constant_value (cu_header
->addr_size
);
17746 TYPE_LENGTH (type
) = cu_header
->addr_size
;
17748 maybe_set_alignment (cu
, die
, type
);
17749 return set_die_type (die
, type
, cu
);
17752 /* Add the given cv-qualifiers to the element type of the array. GCC
17753 outputs DWARF type qualifiers that apply to an array, not the
17754 element type. But GDB relies on the array element type to carry
17755 the cv-qualifiers. This mimics section 6.7.3 of the C99
17758 static struct type
*
17759 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17760 struct type
*base_type
, int cnst
, int voltl
)
17762 struct type
*el_type
, *inner_array
;
17764 base_type
= copy_type (base_type
);
17765 inner_array
= base_type
;
17767 while (TYPE_TARGET_TYPE (inner_array
)->code () == TYPE_CODE_ARRAY
)
17769 TYPE_TARGET_TYPE (inner_array
) =
17770 copy_type (TYPE_TARGET_TYPE (inner_array
));
17771 inner_array
= TYPE_TARGET_TYPE (inner_array
);
17774 el_type
= TYPE_TARGET_TYPE (inner_array
);
17775 cnst
|= TYPE_CONST (el_type
);
17776 voltl
|= TYPE_VOLATILE (el_type
);
17777 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
17779 return set_die_type (die
, base_type
, cu
);
17782 static struct type
*
17783 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17785 struct type
*base_type
, *cv_type
;
17787 base_type
= die_type (die
, cu
);
17789 /* The die_type call above may have already set the type for this DIE. */
17790 cv_type
= get_die_type (die
, cu
);
17794 /* In case the const qualifier is applied to an array type, the element type
17795 is so qualified, not the array type (section 6.7.3 of C99). */
17796 if (base_type
->code () == TYPE_CODE_ARRAY
)
17797 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
17799 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
17800 return set_die_type (die
, cv_type
, cu
);
17803 static struct type
*
17804 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17806 struct type
*base_type
, *cv_type
;
17808 base_type
= die_type (die
, cu
);
17810 /* The die_type call above may have already set the type for this DIE. */
17811 cv_type
= get_die_type (die
, cu
);
17815 /* In case the volatile qualifier is applied to an array type, the
17816 element type is so qualified, not the array type (section 6.7.3
17818 if (base_type
->code () == TYPE_CODE_ARRAY
)
17819 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17821 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17822 return set_die_type (die
, cv_type
, cu
);
17825 /* Handle DW_TAG_restrict_type. */
17827 static struct type
*
17828 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17830 struct type
*base_type
, *cv_type
;
17832 base_type
= die_type (die
, cu
);
17834 /* The die_type call above may have already set the type for this DIE. */
17835 cv_type
= get_die_type (die
, cu
);
17839 cv_type
= make_restrict_type (base_type
);
17840 return set_die_type (die
, cv_type
, cu
);
17843 /* Handle DW_TAG_atomic_type. */
17845 static struct type
*
17846 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17848 struct type
*base_type
, *cv_type
;
17850 base_type
= die_type (die
, cu
);
17852 /* The die_type call above may have already set the type for this DIE. */
17853 cv_type
= get_die_type (die
, cu
);
17857 cv_type
= make_atomic_type (base_type
);
17858 return set_die_type (die
, cv_type
, cu
);
17861 /* Extract all information from a DW_TAG_string_type DIE and add to
17862 the user defined type vector. It isn't really a user defined type,
17863 but it behaves like one, with other DIE's using an AT_user_def_type
17864 attribute to reference it. */
17866 static struct type
*
17867 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17869 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17870 struct gdbarch
*gdbarch
= objfile
->arch ();
17871 struct type
*type
, *range_type
, *index_type
, *char_type
;
17872 struct attribute
*attr
;
17873 struct dynamic_prop prop
;
17874 bool length_is_constant
= true;
17877 /* There are a couple of places where bit sizes might be made use of
17878 when parsing a DW_TAG_string_type, however, no producer that we know
17879 of make use of these. Handling bit sizes that are a multiple of the
17880 byte size is easy enough, but what about other bit sizes? Lets deal
17881 with that problem when we have to. Warn about these attributes being
17882 unsupported, then parse the type and ignore them like we always
17884 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
17885 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
17887 static bool warning_printed
= false;
17888 if (!warning_printed
)
17890 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
17891 "currently supported on DW_TAG_string_type."));
17892 warning_printed
= true;
17896 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17897 if (attr
!= nullptr && !attr
->form_is_constant ())
17899 /* The string length describes the location at which the length of
17900 the string can be found. The size of the length field can be
17901 specified with one of the attributes below. */
17902 struct type
*prop_type
;
17903 struct attribute
*len
17904 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
17905 if (len
== nullptr)
17906 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17907 if (len
!= nullptr && len
->form_is_constant ())
17909 /* Pass 0 as the default as we know this attribute is constant
17910 and the default value will not be returned. */
17911 LONGEST sz
= len
->constant_value (0);
17912 prop_type
= cu
->per_objfile
->int_type (sz
, true);
17916 /* If the size is not specified then we assume it is the size of
17917 an address on this target. */
17918 prop_type
= cu
->addr_sized_int_type (true);
17921 /* Convert the attribute into a dynamic property. */
17922 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
17925 length_is_constant
= false;
17927 else if (attr
!= nullptr)
17929 /* This DW_AT_string_length just contains the length with no
17930 indirection. There's no need to create a dynamic property in this
17931 case. Pass 0 for the default value as we know it will not be
17932 returned in this case. */
17933 length
= attr
->constant_value (0);
17935 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
17937 /* We don't currently support non-constant byte sizes for strings. */
17938 length
= attr
->constant_value (1);
17942 /* Use 1 as a fallback length if we have nothing else. */
17946 index_type
= objfile_type (objfile
)->builtin_int
;
17947 if (length_is_constant
)
17948 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17951 struct dynamic_prop low_bound
;
17953 low_bound
.set_const_val (1);
17954 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
17956 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17957 type
= create_string_type (NULL
, char_type
, range_type
);
17959 return set_die_type (die
, type
, cu
);
17962 /* Assuming that DIE corresponds to a function, returns nonzero
17963 if the function is prototyped. */
17966 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17968 struct attribute
*attr
;
17970 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17971 if (attr
&& attr
->as_boolean ())
17974 /* The DWARF standard implies that the DW_AT_prototyped attribute
17975 is only meaningful for C, but the concept also extends to other
17976 languages that allow unprototyped functions (Eg: Objective C).
17977 For all other languages, assume that functions are always
17979 if (cu
->language
!= language_c
17980 && cu
->language
!= language_objc
17981 && cu
->language
!= language_opencl
)
17984 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17985 prototyped and unprototyped functions; default to prototyped,
17986 since that is more common in modern code (and RealView warns
17987 about unprototyped functions). */
17988 if (producer_is_realview (cu
->producer
))
17994 /* Handle DIES due to C code like:
17998 int (*funcp)(int a, long l);
18002 ('funcp' generates a DW_TAG_subroutine_type DIE). */
18004 static struct type
*
18005 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18007 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18008 struct type
*type
; /* Type that this function returns. */
18009 struct type
*ftype
; /* Function that returns above type. */
18010 struct attribute
*attr
;
18012 type
= die_type (die
, cu
);
18014 /* The die_type call above may have already set the type for this DIE. */
18015 ftype
= get_die_type (die
, cu
);
18019 ftype
= lookup_function_type (type
);
18021 if (prototyped_function_p (die
, cu
))
18022 ftype
->set_is_prototyped (true);
18024 /* Store the calling convention in the type if it's available in
18025 the subroutine die. Otherwise set the calling convention to
18026 the default value DW_CC_normal. */
18027 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
18028 if (attr
!= nullptr
18029 && is_valid_DW_AT_calling_convention_for_subroutine (attr
->constant_value (0)))
18030 TYPE_CALLING_CONVENTION (ftype
)
18031 = (enum dwarf_calling_convention
) attr
->constant_value (0);
18032 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
18033 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
18035 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
18037 /* Record whether the function returns normally to its caller or not
18038 if the DWARF producer set that information. */
18039 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
18040 if (attr
&& attr
->as_boolean ())
18041 TYPE_NO_RETURN (ftype
) = 1;
18043 /* We need to add the subroutine type to the die immediately so
18044 we don't infinitely recurse when dealing with parameters
18045 declared as the same subroutine type. */
18046 set_die_type (die
, ftype
, cu
);
18048 if (die
->child
!= NULL
)
18050 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
18051 struct die_info
*child_die
;
18052 int nparams
, iparams
;
18054 /* Count the number of parameters.
18055 FIXME: GDB currently ignores vararg functions, but knows about
18056 vararg member functions. */
18058 child_die
= die
->child
;
18059 while (child_die
&& child_die
->tag
)
18061 if (child_die
->tag
== DW_TAG_formal_parameter
)
18063 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
18064 ftype
->set_has_varargs (true);
18066 child_die
= child_die
->sibling
;
18069 /* Allocate storage for parameters and fill them in. */
18070 ftype
->set_num_fields (nparams
);
18072 ((struct field
*) TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
)));
18074 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
18075 even if we error out during the parameters reading below. */
18076 for (iparams
= 0; iparams
< nparams
; iparams
++)
18077 ftype
->field (iparams
).set_type (void_type
);
18080 child_die
= die
->child
;
18081 while (child_die
&& child_die
->tag
)
18083 if (child_die
->tag
== DW_TAG_formal_parameter
)
18085 struct type
*arg_type
;
18087 /* DWARF version 2 has no clean way to discern C++
18088 static and non-static member functions. G++ helps
18089 GDB by marking the first parameter for non-static
18090 member functions (which is the this pointer) as
18091 artificial. We pass this information to
18092 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
18094 DWARF version 3 added DW_AT_object_pointer, which GCC
18095 4.5 does not yet generate. */
18096 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
18097 if (attr
!= nullptr)
18098 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = attr
->as_boolean ();
18100 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
18101 arg_type
= die_type (child_die
, cu
);
18103 /* RealView does not mark THIS as const, which the testsuite
18104 expects. GCC marks THIS as const in method definitions,
18105 but not in the class specifications (GCC PR 43053). */
18106 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
18107 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
18110 struct dwarf2_cu
*arg_cu
= cu
;
18111 const char *name
= dwarf2_name (child_die
, cu
);
18113 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
18114 if (attr
!= nullptr)
18116 /* If the compiler emits this, use it. */
18117 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
18120 else if (name
&& strcmp (name
, "this") == 0)
18121 /* Function definitions will have the argument names. */
18123 else if (name
== NULL
&& iparams
== 0)
18124 /* Declarations may not have the names, so like
18125 elsewhere in GDB, assume an artificial first
18126 argument is "this". */
18130 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
18134 ftype
->field (iparams
).set_type (arg_type
);
18137 child_die
= child_die
->sibling
;
18144 static struct type
*
18145 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
18147 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18148 const char *name
= NULL
;
18149 struct type
*this_type
, *target_type
;
18151 name
= dwarf2_full_name (NULL
, die
, cu
);
18152 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
18153 this_type
->set_target_is_stub (true);
18154 set_die_type (die
, this_type
, cu
);
18155 target_type
= die_type (die
, cu
);
18156 if (target_type
!= this_type
)
18157 TYPE_TARGET_TYPE (this_type
) = target_type
;
18160 /* Self-referential typedefs are, it seems, not allowed by the DWARF
18161 spec and cause infinite loops in GDB. */
18162 complaint (_("Self-referential DW_TAG_typedef "
18163 "- DIE at %s [in module %s]"),
18164 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
18165 TYPE_TARGET_TYPE (this_type
) = NULL
;
18169 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
18170 anonymous typedefs, which is, strictly speaking, invalid DWARF.
18171 Handle these by just returning the target type, rather than
18172 constructing an anonymous typedef type and trying to handle this
18174 set_die_type (die
, target_type
, cu
);
18175 return target_type
;
18180 /* Assuming DIE is a rational DW_TAG_constant, read the DIE's
18181 numerator and denominator into NUMERATOR and DENOMINATOR (resp).
18183 If the numerator and/or numerator attribute is missing,
18184 a complaint is filed, and NUMERATOR and DENOMINATOR are left
18188 get_dwarf2_rational_constant (struct die_info
*die
, struct dwarf2_cu
*cu
,
18189 gdb_mpz
*numerator
, gdb_mpz
*denominator
)
18191 struct attribute
*num_attr
, *denom_attr
;
18193 num_attr
= dwarf2_attr (die
, DW_AT_GNU_numerator
, cu
);
18194 if (num_attr
== nullptr)
18195 complaint (_("DW_AT_GNU_numerator missing in %s DIE at %s"),
18196 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
18198 denom_attr
= dwarf2_attr (die
, DW_AT_GNU_denominator
, cu
);
18199 if (denom_attr
== nullptr)
18200 complaint (_("DW_AT_GNU_denominator missing in %s DIE at %s"),
18201 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
18203 if (num_attr
== nullptr || denom_attr
== nullptr)
18206 if (num_attr
->form_is_block ())
18208 dwarf_block
*blk
= num_attr
->as_block ();
18209 mpz_import (numerator
->val
, blk
->size
,
18210 bfd_big_endian (cu
->per_objfile
->objfile
->obfd
) ? 1 : -1,
18211 1, 0, 0, blk
->data
);
18214 *numerator
= gdb_mpz (num_attr
->constant_value (1));
18216 if (denom_attr
->form_is_block ())
18218 dwarf_block
*blk
= denom_attr
->as_block ();
18219 mpz_import (denominator
->val
, blk
->size
,
18220 bfd_big_endian (cu
->per_objfile
->objfile
->obfd
) ? 1 : -1,
18221 1, 0, 0, blk
->data
);
18224 *denominator
= gdb_mpz (denom_attr
->constant_value (1));
18227 /* Same as get_dwarf2_rational_constant, but extracting an unsigned
18228 rational constant, rather than a signed one.
18230 If the rational constant has a negative value, a complaint
18231 is filed, and NUMERATOR and DENOMINATOR are left untouched. */
18234 get_dwarf2_unsigned_rational_constant (struct die_info
*die
,
18235 struct dwarf2_cu
*cu
,
18236 gdb_mpz
*numerator
,
18237 gdb_mpz
*denominator
)
18242 get_dwarf2_rational_constant (die
, cu
, &num
, &denom
);
18243 if (mpz_sgn (num
.val
) == -1 && mpz_sgn (denom
.val
) == -1)
18245 mpz_neg (num
.val
, num
.val
);
18246 mpz_neg (denom
.val
, denom
.val
);
18248 else if (mpz_sgn (num
.val
) == -1)
18250 complaint (_("unexpected negative value for DW_AT_GNU_numerator"
18252 sect_offset_str (die
->sect_off
));
18255 else if (mpz_sgn (denom
.val
) == -1)
18257 complaint (_("unexpected negative value for DW_AT_GNU_denominator"
18259 sect_offset_str (die
->sect_off
));
18263 *numerator
= std::move (num
);
18264 *denominator
= std::move (denom
);
18267 /* Assuming DIE corresponds to a fixed point type, finish the creation
18268 of the corresponding TYPE by setting its type-specific data.
18269 CU is the DIE's CU. */
18272 finish_fixed_point_type (struct type
*type
, struct die_info
*die
,
18273 struct dwarf2_cu
*cu
)
18275 struct attribute
*attr
;
18277 gdb_assert (type
->code () == TYPE_CODE_FIXED_POINT
18278 && TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_FIXED_POINT
);
18280 attr
= dwarf2_attr (die
, DW_AT_binary_scale
, cu
);
18282 attr
= dwarf2_attr (die
, DW_AT_decimal_scale
, cu
);
18284 attr
= dwarf2_attr (die
, DW_AT_small
, cu
);
18286 /* Numerator and denominator of our fixed-point type's scaling factor.
18287 The default is a scaling factor of 1, which we use as a fallback
18288 when we are not able to decode it (problem with the debugging info,
18289 unsupported forms, bug in GDB, etc...). Using that as the default
18290 allows us to at least print the unscaled value, which might still
18291 be useful to a user. */
18292 gdb_mpz
scale_num (1);
18293 gdb_mpz
scale_denom (1);
18295 if (attr
== nullptr)
18297 /* Scaling factor not found. Assume a scaling factor of 1,
18298 and hope for the best. At least the user will be able to see
18299 the encoded value. */
18300 complaint (_("no scale found for fixed-point type (DIE at %s)"),
18301 sect_offset_str (die
->sect_off
));
18303 else if (attr
->name
== DW_AT_binary_scale
)
18305 LONGEST scale_exp
= attr
->constant_value (0);
18306 gdb_mpz
*num_or_denom
= scale_exp
> 0 ? &scale_num
: &scale_denom
;
18308 mpz_mul_2exp (num_or_denom
->val
, num_or_denom
->val
, std::abs (scale_exp
));
18310 else if (attr
->name
== DW_AT_decimal_scale
)
18312 LONGEST scale_exp
= attr
->constant_value (0);
18313 gdb_mpz
*num_or_denom
= scale_exp
> 0 ? &scale_num
: &scale_denom
;
18315 mpz_ui_pow_ui (num_or_denom
->val
, 10, std::abs (scale_exp
));
18317 else if (attr
->name
== DW_AT_small
)
18319 struct die_info
*scale_die
;
18320 struct dwarf2_cu
*scale_cu
= cu
;
18322 scale_die
= follow_die_ref (die
, attr
, &scale_cu
);
18323 if (scale_die
->tag
== DW_TAG_constant
)
18324 get_dwarf2_unsigned_rational_constant (scale_die
, scale_cu
,
18325 &scale_num
, &scale_denom
);
18327 complaint (_("%s DIE not supported as target of DW_AT_small attribute"
18329 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
18333 complaint (_("unsupported scale attribute %s for fixed-point type"
18335 dwarf_attr_name (attr
->name
),
18336 sect_offset_str (die
->sect_off
));
18339 gdb_mpq
&scaling_factor
= type
->fixed_point_info ().scaling_factor
;
18340 mpz_set (mpq_numref (scaling_factor
.val
), scale_num
.val
);
18341 mpz_set (mpq_denref (scaling_factor
.val
), scale_denom
.val
);
18342 mpq_canonicalize (scaling_factor
.val
);
18345 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
18346 (which may be different from NAME) to the architecture back-end to allow
18347 it to guess the correct format if necessary. */
18349 static struct type
*
18350 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
18351 const char *name_hint
, enum bfd_endian byte_order
)
18353 struct gdbarch
*gdbarch
= objfile
->arch ();
18354 const struct floatformat
**format
;
18357 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
18359 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
18361 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18366 /* Allocate an integer type of size BITS and name NAME. */
18368 static struct type
*
18369 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
18370 int bits
, int unsigned_p
, const char *name
)
18374 /* Versions of Intel's C Compiler generate an integer type called "void"
18375 instead of using DW_TAG_unspecified_type. This has been seen on
18376 at least versions 14, 17, and 18. */
18377 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
18378 && strcmp (name
, "void") == 0)
18379 type
= objfile_type (objfile
)->builtin_void
;
18381 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
18386 /* Return true if DIE has a DW_AT_small attribute whose value is
18387 a constant rational, where both the numerator and denominator
18390 CU is the DIE's Compilation Unit. */
18393 has_zero_over_zero_small_attribute (struct die_info
*die
,
18394 struct dwarf2_cu
*cu
)
18396 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_small
, cu
);
18397 if (attr
== nullptr)
18400 struct dwarf2_cu
*scale_cu
= cu
;
18401 struct die_info
*scale_die
18402 = follow_die_ref (die
, attr
, &scale_cu
);
18404 if (scale_die
->tag
!= DW_TAG_constant
)
18407 gdb_mpz
num (1), denom (1);
18408 get_dwarf2_rational_constant (scale_die
, cu
, &num
, &denom
);
18409 return mpz_sgn (num
.val
) == 0 && mpz_sgn (denom
.val
) == 0;
18412 /* Initialise and return a floating point type of size BITS suitable for
18413 use as a component of a complex number. The NAME_HINT is passed through
18414 when initialising the floating point type and is the name of the complex
18417 As DWARF doesn't currently provide an explicit name for the components
18418 of a complex number, but it can be helpful to have these components
18419 named, we try to select a suitable name based on the size of the
18421 static struct type
*
18422 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
18423 struct objfile
*objfile
,
18424 int bits
, const char *name_hint
,
18425 enum bfd_endian byte_order
)
18427 gdbarch
*gdbarch
= objfile
->arch ();
18428 struct type
*tt
= nullptr;
18430 /* Try to find a suitable floating point builtin type of size BITS.
18431 We're going to use the name of this type as the name for the complex
18432 target type that we are about to create. */
18433 switch (cu
->language
)
18435 case language_fortran
:
18439 tt
= builtin_f_type (gdbarch
)->builtin_real
;
18442 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
18444 case 96: /* The x86-32 ABI specifies 96-bit long double. */
18446 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
18454 tt
= builtin_type (gdbarch
)->builtin_float
;
18457 tt
= builtin_type (gdbarch
)->builtin_double
;
18459 case 96: /* The x86-32 ABI specifies 96-bit long double. */
18461 tt
= builtin_type (gdbarch
)->builtin_long_double
;
18467 /* If the type we found doesn't match the size we were looking for, then
18468 pretend we didn't find a type at all, the complex target type we
18469 create will then be nameless. */
18470 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
18473 const char *name
= (tt
== nullptr) ? nullptr : tt
->name ();
18474 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
18477 /* Find a representation of a given base type and install
18478 it in the TYPE field of the die. */
18480 static struct type
*
18481 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18483 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18485 struct attribute
*attr
;
18486 int encoding
= 0, bits
= 0;
18490 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
18491 if (attr
!= nullptr && attr
->form_is_constant ())
18492 encoding
= attr
->constant_value (0);
18493 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18494 if (attr
!= nullptr)
18495 bits
= attr
->constant_value (0) * TARGET_CHAR_BIT
;
18496 name
= dwarf2_name (die
, cu
);
18498 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
18500 arch
= objfile
->arch ();
18501 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
18503 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
18504 if (attr
!= nullptr && attr
->form_is_constant ())
18506 int endianity
= attr
->constant_value (0);
18511 byte_order
= BFD_ENDIAN_BIG
;
18513 case DW_END_little
:
18514 byte_order
= BFD_ENDIAN_LITTLE
;
18517 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
18522 if ((encoding
== DW_ATE_signed_fixed
|| encoding
== DW_ATE_unsigned_fixed
)
18523 && cu
->language
== language_ada
18524 && has_zero_over_zero_small_attribute (die
, cu
))
18526 /* brobecker/2018-02-24: This is a fixed point type for which
18527 the scaling factor is represented as fraction whose value
18528 does not make sense (zero divided by zero), so we should
18529 normally never see these. However, there is a small category
18530 of fixed point types for which GNAT is unable to provide
18531 the scaling factor via the standard DWARF mechanisms, and
18532 for which the info is provided via the GNAT encodings instead.
18533 This is likely what this DIE is about.
18535 Ideally, GNAT should be declaring this type the same way
18536 it declares other fixed point types when using the legacy
18537 GNAT encoding, which is to use a simple signed or unsigned
18538 base type. A report to the GNAT team has been created to
18539 look into it. In the meantime, pretend this type is a simple
18540 signed or unsigned integral, rather than a fixed point type,
18541 to avoid any confusion later on as to how to process this type. */
18542 encoding
= (encoding
== DW_ATE_signed_fixed
18544 : DW_ATE_unsigned
);
18549 case DW_ATE_address
:
18550 /* Turn DW_ATE_address into a void * pointer. */
18551 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
18552 type
= init_pointer_type (objfile
, bits
, name
, type
);
18554 case DW_ATE_boolean
:
18555 type
= init_boolean_type (objfile
, bits
, 1, name
);
18557 case DW_ATE_complex_float
:
18558 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
18560 if (type
->code () == TYPE_CODE_ERROR
)
18562 if (name
== nullptr)
18564 struct obstack
*obstack
18565 = &cu
->per_objfile
->objfile
->objfile_obstack
;
18566 name
= obconcat (obstack
, "_Complex ", type
->name (),
18569 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18572 type
= init_complex_type (name
, type
);
18574 case DW_ATE_decimal_float
:
18575 type
= init_decfloat_type (objfile
, bits
, name
);
18578 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
18580 case DW_ATE_signed
:
18581 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
18583 case DW_ATE_unsigned
:
18584 if (cu
->language
== language_fortran
18586 && startswith (name
, "character("))
18587 type
= init_character_type (objfile
, bits
, 1, name
);
18589 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18591 case DW_ATE_signed_char
:
18592 if (cu
->language
== language_ada
|| cu
->language
== language_m2
18593 || cu
->language
== language_pascal
18594 || cu
->language
== language_fortran
)
18595 type
= init_character_type (objfile
, bits
, 0, name
);
18597 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
18599 case DW_ATE_unsigned_char
:
18600 if (cu
->language
== language_ada
|| cu
->language
== language_m2
18601 || cu
->language
== language_pascal
18602 || cu
->language
== language_fortran
18603 || cu
->language
== language_rust
)
18604 type
= init_character_type (objfile
, bits
, 1, name
);
18606 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18611 type
= builtin_type (arch
)->builtin_char16
;
18612 else if (bits
== 32)
18613 type
= builtin_type (arch
)->builtin_char32
;
18616 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
18618 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18620 return set_die_type (die
, type
, cu
);
18623 case DW_ATE_signed_fixed
:
18624 type
= init_fixed_point_type (objfile
, bits
, 0, name
);
18625 finish_fixed_point_type (type
, die
, cu
);
18627 case DW_ATE_unsigned_fixed
:
18628 type
= init_fixed_point_type (objfile
, bits
, 1, name
);
18629 finish_fixed_point_type (type
, die
, cu
);
18633 complaint (_("unsupported DW_AT_encoding: '%s'"),
18634 dwarf_type_encoding_name (encoding
));
18635 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18639 if (name
&& strcmp (name
, "char") == 0)
18640 type
->set_has_no_signedness (true);
18642 maybe_set_alignment (cu
, die
, type
);
18644 type
->set_endianity_is_not_default (gdbarch_byte_order (arch
) != byte_order
);
18646 if (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_INT
)
18648 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
18649 if (attr
!= nullptr && attr
->as_unsigned () <= 8 * TYPE_LENGTH (type
))
18651 unsigned real_bit_size
= attr
->as_unsigned ();
18652 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
18653 /* Only use the attributes if they make sense together. */
18654 if (attr
== nullptr
18655 || (attr
->as_unsigned () + real_bit_size
18656 <= 8 * TYPE_LENGTH (type
)))
18658 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_size
18660 if (attr
!= nullptr)
18661 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_offset
18662 = attr
->as_unsigned ();
18667 return set_die_type (die
, type
, cu
);
18670 /* Parse dwarf attribute if it's a block, reference or constant and put the
18671 resulting value of the attribute into struct bound_prop.
18672 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
18675 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
18676 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
18677 struct type
*default_type
)
18679 struct dwarf2_property_baton
*baton
;
18680 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
18681 struct objfile
*objfile
= per_objfile
->objfile
;
18682 struct obstack
*obstack
= &objfile
->objfile_obstack
;
18684 gdb_assert (default_type
!= NULL
);
18686 if (attr
== NULL
|| prop
== NULL
)
18689 if (attr
->form_is_block ())
18691 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18692 baton
->property_type
= default_type
;
18693 baton
->locexpr
.per_cu
= cu
->per_cu
;
18694 baton
->locexpr
.per_objfile
= per_objfile
;
18696 struct dwarf_block
*block
= attr
->as_block ();
18697 baton
->locexpr
.size
= block
->size
;
18698 baton
->locexpr
.data
= block
->data
;
18699 switch (attr
->name
)
18701 case DW_AT_string_length
:
18702 baton
->locexpr
.is_reference
= true;
18705 baton
->locexpr
.is_reference
= false;
18709 prop
->set_locexpr (baton
);
18710 gdb_assert (prop
->baton () != NULL
);
18712 else if (attr
->form_is_ref ())
18714 struct dwarf2_cu
*target_cu
= cu
;
18715 struct die_info
*target_die
;
18716 struct attribute
*target_attr
;
18718 target_die
= follow_die_ref (die
, attr
, &target_cu
);
18719 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
18720 if (target_attr
== NULL
)
18721 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
18723 if (target_attr
== NULL
)
18726 switch (target_attr
->name
)
18728 case DW_AT_location
:
18729 if (target_attr
->form_is_section_offset ())
18731 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18732 baton
->property_type
= die_type (target_die
, target_cu
);
18733 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
18734 prop
->set_loclist (baton
);
18735 gdb_assert (prop
->baton () != NULL
);
18737 else if (target_attr
->form_is_block ())
18739 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18740 baton
->property_type
= die_type (target_die
, target_cu
);
18741 baton
->locexpr
.per_cu
= cu
->per_cu
;
18742 baton
->locexpr
.per_objfile
= per_objfile
;
18743 struct dwarf_block
*block
= target_attr
->as_block ();
18744 baton
->locexpr
.size
= block
->size
;
18745 baton
->locexpr
.data
= block
->data
;
18746 baton
->locexpr
.is_reference
= true;
18747 prop
->set_locexpr (baton
);
18748 gdb_assert (prop
->baton () != NULL
);
18752 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18753 "dynamic property");
18757 case DW_AT_data_member_location
:
18761 if (!handle_data_member_location (target_die
, target_cu
,
18765 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18766 baton
->property_type
= read_type_die (target_die
->parent
,
18768 baton
->offset_info
.offset
= offset
;
18769 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
18770 prop
->set_addr_offset (baton
);
18775 else if (attr
->form_is_constant ())
18776 prop
->set_const_val (attr
->constant_value (0));
18779 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
18780 dwarf2_name (die
, cu
));
18790 dwarf2_per_objfile::int_type (int size_in_bytes
, bool unsigned_p
) const
18792 struct type
*int_type
;
18794 /* Helper macro to examine the various builtin types. */
18795 #define TRY_TYPE(F) \
18796 int_type = (unsigned_p \
18797 ? objfile_type (objfile)->builtin_unsigned_ ## F \
18798 : objfile_type (objfile)->builtin_ ## F); \
18799 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
18806 TRY_TYPE (long_long
);
18810 gdb_assert_not_reached ("unable to find suitable integer type");
18816 dwarf2_cu::addr_sized_int_type (bool unsigned_p
) const
18818 int addr_size
= this->per_cu
->addr_size ();
18819 return this->per_objfile
->int_type (addr_size
, unsigned_p
);
18822 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
18823 present (which is valid) then compute the default type based on the
18824 compilation units address size. */
18826 static struct type
*
18827 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18829 struct type
*index_type
= die_type (die
, cu
);
18831 /* Dwarf-2 specifications explicitly allows to create subrange types
18832 without specifying a base type.
18833 In that case, the base type must be set to the type of
18834 the lower bound, upper bound or count, in that order, if any of these
18835 three attributes references an object that has a type.
18836 If no base type is found, the Dwarf-2 specifications say that
18837 a signed integer type of size equal to the size of an address should
18839 For the following C code: `extern char gdb_int [];'
18840 GCC produces an empty range DIE.
18841 FIXME: muller/2010-05-28: Possible references to object for low bound,
18842 high bound or count are not yet handled by this code. */
18843 if (index_type
->code () == TYPE_CODE_VOID
)
18844 index_type
= cu
->addr_sized_int_type (false);
18849 /* Read the given DW_AT_subrange DIE. */
18851 static struct type
*
18852 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18854 struct type
*base_type
, *orig_base_type
;
18855 struct type
*range_type
;
18856 struct attribute
*attr
;
18857 struct dynamic_prop low
, high
;
18858 int low_default_is_valid
;
18859 int high_bound_is_count
= 0;
18861 ULONGEST negative_mask
;
18863 orig_base_type
= read_subrange_index_type (die
, cu
);
18865 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
18866 whereas the real type might be. So, we use ORIG_BASE_TYPE when
18867 creating the range type, but we use the result of check_typedef
18868 when examining properties of the type. */
18869 base_type
= check_typedef (orig_base_type
);
18871 /* The die_type call above may have already set the type for this DIE. */
18872 range_type
= get_die_type (die
, cu
);
18876 high
.set_const_val (0);
18878 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
18879 omitting DW_AT_lower_bound. */
18880 switch (cu
->language
)
18883 case language_cplus
:
18884 low
.set_const_val (0);
18885 low_default_is_valid
= 1;
18887 case language_fortran
:
18888 low
.set_const_val (1);
18889 low_default_is_valid
= 1;
18892 case language_objc
:
18893 case language_rust
:
18894 low
.set_const_val (0);
18895 low_default_is_valid
= (cu
->header
.version
>= 4);
18899 case language_pascal
:
18900 low
.set_const_val (1);
18901 low_default_is_valid
= (cu
->header
.version
>= 4);
18904 low
.set_const_val (0);
18905 low_default_is_valid
= 0;
18909 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
18910 if (attr
!= nullptr)
18911 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
18912 else if (!low_default_is_valid
)
18913 complaint (_("Missing DW_AT_lower_bound "
18914 "- DIE at %s [in module %s]"),
18915 sect_offset_str (die
->sect_off
),
18916 objfile_name (cu
->per_objfile
->objfile
));
18918 struct attribute
*attr_ub
, *attr_count
;
18919 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
18920 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18922 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
18923 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18925 /* If bounds are constant do the final calculation here. */
18926 if (low
.kind () == PROP_CONST
&& high
.kind () == PROP_CONST
)
18927 high
.set_const_val (low
.const_val () + high
.const_val () - 1);
18929 high_bound_is_count
= 1;
18933 if (attr_ub
!= NULL
)
18934 complaint (_("Unresolved DW_AT_upper_bound "
18935 "- DIE at %s [in module %s]"),
18936 sect_offset_str (die
->sect_off
),
18937 objfile_name (cu
->per_objfile
->objfile
));
18938 if (attr_count
!= NULL
)
18939 complaint (_("Unresolved DW_AT_count "
18940 "- DIE at %s [in module %s]"),
18941 sect_offset_str (die
->sect_off
),
18942 objfile_name (cu
->per_objfile
->objfile
));
18947 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
18948 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
18949 bias
= bias_attr
->constant_value (0);
18951 /* Normally, the DWARF producers are expected to use a signed
18952 constant form (Eg. DW_FORM_sdata) to express negative bounds.
18953 But this is unfortunately not always the case, as witnessed
18954 with GCC, for instance, where the ambiguous DW_FORM_dataN form
18955 is used instead. To work around that ambiguity, we treat
18956 the bounds as signed, and thus sign-extend their values, when
18957 the base type is signed. */
18959 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
18960 if (low
.kind () == PROP_CONST
18961 && !base_type
->is_unsigned () && (low
.const_val () & negative_mask
))
18962 low
.set_const_val (low
.const_val () | negative_mask
);
18963 if (high
.kind () == PROP_CONST
18964 && !base_type
->is_unsigned () && (high
.const_val () & negative_mask
))
18965 high
.set_const_val (high
.const_val () | negative_mask
);
18967 /* Check for bit and byte strides. */
18968 struct dynamic_prop byte_stride_prop
;
18969 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
18970 if (attr_byte_stride
!= nullptr)
18972 struct type
*prop_type
= cu
->addr_sized_int_type (false);
18973 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
18977 struct dynamic_prop bit_stride_prop
;
18978 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
18979 if (attr_bit_stride
!= nullptr)
18981 /* It only makes sense to have either a bit or byte stride. */
18982 if (attr_byte_stride
!= nullptr)
18984 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
18985 "- DIE at %s [in module %s]"),
18986 sect_offset_str (die
->sect_off
),
18987 objfile_name (cu
->per_objfile
->objfile
));
18988 attr_bit_stride
= nullptr;
18992 struct type
*prop_type
= cu
->addr_sized_int_type (false);
18993 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
18998 if (attr_byte_stride
!= nullptr
18999 || attr_bit_stride
!= nullptr)
19001 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
19002 struct dynamic_prop
*stride
19003 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
19006 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
19007 &high
, bias
, stride
, byte_stride_p
);
19010 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
19012 if (high_bound_is_count
)
19013 range_type
->bounds ()->flag_upper_bound_is_count
= 1;
19015 /* Ada expects an empty array on no boundary attributes. */
19016 if (attr
== NULL
&& cu
->language
!= language_ada
)
19017 range_type
->bounds ()->high
.set_undefined ();
19019 name
= dwarf2_name (die
, cu
);
19021 range_type
->set_name (name
);
19023 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
19024 if (attr
!= nullptr)
19025 TYPE_LENGTH (range_type
) = attr
->constant_value (0);
19027 maybe_set_alignment (cu
, die
, range_type
);
19029 set_die_type (die
, range_type
, cu
);
19031 /* set_die_type should be already done. */
19032 set_descriptive_type (range_type
, die
, cu
);
19037 static struct type
*
19038 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
19042 type
= init_type (cu
->per_objfile
->objfile
, TYPE_CODE_VOID
, 0, NULL
);
19043 type
->set_name (dwarf2_name (die
, cu
));
19045 /* In Ada, an unspecified type is typically used when the description
19046 of the type is deferred to a different unit. When encountering
19047 such a type, we treat it as a stub, and try to resolve it later on,
19049 if (cu
->language
== language_ada
)
19050 type
->set_is_stub (true);
19052 return set_die_type (die
, type
, cu
);
19055 /* Read a single die and all its descendents. Set the die's sibling
19056 field to NULL; set other fields in the die correctly, and set all
19057 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
19058 location of the info_ptr after reading all of those dies. PARENT
19059 is the parent of the die in question. */
19061 static struct die_info
*
19062 read_die_and_children (const struct die_reader_specs
*reader
,
19063 const gdb_byte
*info_ptr
,
19064 const gdb_byte
**new_info_ptr
,
19065 struct die_info
*parent
)
19067 struct die_info
*die
;
19068 const gdb_byte
*cur_ptr
;
19070 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
19073 *new_info_ptr
= cur_ptr
;
19076 store_in_ref_table (die
, reader
->cu
);
19078 if (die
->has_children
)
19079 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
19083 *new_info_ptr
= cur_ptr
;
19086 die
->sibling
= NULL
;
19087 die
->parent
= parent
;
19091 /* Read a die, all of its descendents, and all of its siblings; set
19092 all of the fields of all of the dies correctly. Arguments are as
19093 in read_die_and_children. */
19095 static struct die_info
*
19096 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
19097 const gdb_byte
*info_ptr
,
19098 const gdb_byte
**new_info_ptr
,
19099 struct die_info
*parent
)
19101 struct die_info
*first_die
, *last_sibling
;
19102 const gdb_byte
*cur_ptr
;
19104 cur_ptr
= info_ptr
;
19105 first_die
= last_sibling
= NULL
;
19109 struct die_info
*die
19110 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
19114 *new_info_ptr
= cur_ptr
;
19121 last_sibling
->sibling
= die
;
19123 last_sibling
= die
;
19127 /* Read a die, all of its descendents, and all of its siblings; set
19128 all of the fields of all of the dies correctly. Arguments are as
19129 in read_die_and_children.
19130 This the main entry point for reading a DIE and all its children. */
19132 static struct die_info
*
19133 read_die_and_siblings (const struct die_reader_specs
*reader
,
19134 const gdb_byte
*info_ptr
,
19135 const gdb_byte
**new_info_ptr
,
19136 struct die_info
*parent
)
19138 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
19139 new_info_ptr
, parent
);
19141 if (dwarf_die_debug
)
19143 fprintf_unfiltered (gdb_stdlog
,
19144 "Read die from %s@0x%x of %s:\n",
19145 reader
->die_section
->get_name (),
19146 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
19147 bfd_get_filename (reader
->abfd
));
19148 dump_die (die
, dwarf_die_debug
);
19154 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
19156 The caller is responsible for filling in the extra attributes
19157 and updating (*DIEP)->num_attrs.
19158 Set DIEP to point to a newly allocated die with its information,
19159 except for its child, sibling, and parent fields. */
19161 static const gdb_byte
*
19162 read_full_die_1 (const struct die_reader_specs
*reader
,
19163 struct die_info
**diep
, const gdb_byte
*info_ptr
,
19164 int num_extra_attrs
)
19166 unsigned int abbrev_number
, bytes_read
, i
;
19167 struct abbrev_info
*abbrev
;
19168 struct die_info
*die
;
19169 struct dwarf2_cu
*cu
= reader
->cu
;
19170 bfd
*abfd
= reader
->abfd
;
19172 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
19173 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19174 info_ptr
+= bytes_read
;
19175 if (!abbrev_number
)
19181 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
19183 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
19185 bfd_get_filename (abfd
));
19187 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
19188 die
->sect_off
= sect_off
;
19189 die
->tag
= abbrev
->tag
;
19190 die
->abbrev
= abbrev_number
;
19191 die
->has_children
= abbrev
->has_children
;
19193 /* Make the result usable.
19194 The caller needs to update num_attrs after adding the extra
19196 die
->num_attrs
= abbrev
->num_attrs
;
19198 bool any_need_reprocess
= false;
19199 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
19201 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
19203 if (die
->attrs
[i
].requires_reprocessing_p ())
19204 any_need_reprocess
= true;
19207 struct attribute
*attr
= die
->attr (DW_AT_str_offsets_base
);
19208 if (attr
!= nullptr && attr
->form_is_unsigned ())
19209 cu
->str_offsets_base
= attr
->as_unsigned ();
19211 attr
= die
->attr (DW_AT_loclists_base
);
19212 if (attr
!= nullptr)
19213 cu
->loclist_base
= attr
->as_unsigned ();
19215 auto maybe_addr_base
= die
->addr_base ();
19216 if (maybe_addr_base
.has_value ())
19217 cu
->addr_base
= *maybe_addr_base
;
19219 attr
= die
->attr (DW_AT_rnglists_base
);
19220 if (attr
!= nullptr)
19221 cu
->ranges_base
= attr
->as_unsigned ();
19223 if (any_need_reprocess
)
19225 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
19227 if (die
->attrs
[i
].requires_reprocessing_p ())
19228 read_attribute_reprocess (reader
, &die
->attrs
[i
], die
->tag
);
19235 /* Read a die and all its attributes.
19236 Set DIEP to point to a newly allocated die with its information,
19237 except for its child, sibling, and parent fields. */
19239 static const gdb_byte
*
19240 read_full_die (const struct die_reader_specs
*reader
,
19241 struct die_info
**diep
, const gdb_byte
*info_ptr
)
19243 const gdb_byte
*result
;
19245 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
19247 if (dwarf_die_debug
)
19249 fprintf_unfiltered (gdb_stdlog
,
19250 "Read die from %s@0x%x of %s:\n",
19251 reader
->die_section
->get_name (),
19252 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
19253 bfd_get_filename (reader
->abfd
));
19254 dump_die (*diep
, dwarf_die_debug
);
19261 /* Returns nonzero if TAG represents a type that we might generate a partial
19265 is_type_tag_for_partial (int tag
, enum language lang
)
19270 /* Some types that would be reasonable to generate partial symbols for,
19271 that we don't at present. Note that normally this does not
19272 matter, mainly because C compilers don't give names to these
19273 types, but instead emit DW_TAG_typedef. */
19274 case DW_TAG_file_type
:
19275 case DW_TAG_ptr_to_member_type
:
19276 case DW_TAG_set_type
:
19277 case DW_TAG_string_type
:
19278 case DW_TAG_subroutine_type
:
19281 /* GNAT may emit an array with a name, but no typedef, so we
19282 need to make a symbol in this case. */
19283 case DW_TAG_array_type
:
19284 return lang
== language_ada
;
19286 case DW_TAG_base_type
:
19287 case DW_TAG_class_type
:
19288 case DW_TAG_interface_type
:
19289 case DW_TAG_enumeration_type
:
19290 case DW_TAG_structure_type
:
19291 case DW_TAG_subrange_type
:
19292 case DW_TAG_typedef
:
19293 case DW_TAG_union_type
:
19300 /* Load all DIEs that are interesting for partial symbols into memory. */
19302 static struct partial_die_info
*
19303 load_partial_dies (const struct die_reader_specs
*reader
,
19304 const gdb_byte
*info_ptr
, int building_psymtab
)
19306 struct dwarf2_cu
*cu
= reader
->cu
;
19307 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19308 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
19309 unsigned int bytes_read
;
19310 unsigned int load_all
= 0;
19311 int nesting_level
= 1;
19316 gdb_assert (cu
->per_cu
!= NULL
);
19317 if (cu
->per_cu
->load_all_dies
)
19321 = htab_create_alloc_ex (cu
->header
.length
/ 12,
19325 &cu
->comp_unit_obstack
,
19326 hashtab_obstack_allocate
,
19327 dummy_obstack_deallocate
);
19331 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
19333 /* A NULL abbrev means the end of a series of children. */
19334 if (abbrev
== NULL
)
19336 if (--nesting_level
== 0)
19339 info_ptr
+= bytes_read
;
19340 last_die
= parent_die
;
19341 parent_die
= parent_die
->die_parent
;
19345 /* Check for template arguments. We never save these; if
19346 they're seen, we just mark the parent, and go on our way. */
19347 if (parent_die
!= NULL
19348 && cu
->language
== language_cplus
19349 && (abbrev
->tag
== DW_TAG_template_type_param
19350 || abbrev
->tag
== DW_TAG_template_value_param
))
19352 parent_die
->has_template_arguments
= 1;
19356 /* We don't need a partial DIE for the template argument. */
19357 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
19362 /* We only recurse into c++ subprograms looking for template arguments.
19363 Skip their other children. */
19365 && cu
->language
== language_cplus
19366 && parent_die
!= NULL
19367 && parent_die
->tag
== DW_TAG_subprogram
19368 && abbrev
->tag
!= DW_TAG_inlined_subroutine
)
19370 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
19374 /* Check whether this DIE is interesting enough to save. Normally
19375 we would not be interested in members here, but there may be
19376 later variables referencing them via DW_AT_specification (for
19377 static members). */
19379 && !is_type_tag_for_partial (abbrev
->tag
, cu
->language
)
19380 && abbrev
->tag
!= DW_TAG_constant
19381 && abbrev
->tag
!= DW_TAG_enumerator
19382 && abbrev
->tag
!= DW_TAG_subprogram
19383 && abbrev
->tag
!= DW_TAG_inlined_subroutine
19384 && abbrev
->tag
!= DW_TAG_lexical_block
19385 && abbrev
->tag
!= DW_TAG_variable
19386 && abbrev
->tag
!= DW_TAG_namespace
19387 && abbrev
->tag
!= DW_TAG_module
19388 && abbrev
->tag
!= DW_TAG_member
19389 && abbrev
->tag
!= DW_TAG_imported_unit
19390 && abbrev
->tag
!= DW_TAG_imported_declaration
)
19392 /* Otherwise we skip to the next sibling, if any. */
19393 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
19397 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
19400 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
19402 /* This two-pass algorithm for processing partial symbols has a
19403 high cost in cache pressure. Thus, handle some simple cases
19404 here which cover the majority of C partial symbols. DIEs
19405 which neither have specification tags in them, nor could have
19406 specification tags elsewhere pointing at them, can simply be
19407 processed and discarded.
19409 This segment is also optional; scan_partial_symbols and
19410 add_partial_symbol will handle these DIEs if we chain
19411 them in normally. When compilers which do not emit large
19412 quantities of duplicate debug information are more common,
19413 this code can probably be removed. */
19415 /* Any complete simple types at the top level (pretty much all
19416 of them, for a language without namespaces), can be processed
19418 if (parent_die
== NULL
19419 && pdi
.has_specification
== 0
19420 && pdi
.is_declaration
== 0
19421 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
19422 || pdi
.tag
== DW_TAG_base_type
19423 || pdi
.tag
== DW_TAG_array_type
19424 || pdi
.tag
== DW_TAG_subrange_type
))
19426 if (building_psymtab
&& pdi
.raw_name
!= NULL
)
19427 add_partial_symbol (&pdi
, cu
);
19429 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
19433 /* The exception for DW_TAG_typedef with has_children above is
19434 a workaround of GCC PR debug/47510. In the case of this complaint
19435 type_name_or_error will error on such types later.
19437 GDB skipped children of DW_TAG_typedef by the shortcut above and then
19438 it could not find the child DIEs referenced later, this is checked
19439 above. In correct DWARF DW_TAG_typedef should have no children. */
19441 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
19442 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
19443 "- DIE at %s [in module %s]"),
19444 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
19446 /* If we're at the second level, and we're an enumerator, and
19447 our parent has no specification (meaning possibly lives in a
19448 namespace elsewhere), then we can add the partial symbol now
19449 instead of queueing it. */
19450 if (pdi
.tag
== DW_TAG_enumerator
19451 && parent_die
!= NULL
19452 && parent_die
->die_parent
== NULL
19453 && parent_die
->tag
== DW_TAG_enumeration_type
19454 && parent_die
->has_specification
== 0)
19456 if (pdi
.raw_name
== NULL
)
19457 complaint (_("malformed enumerator DIE ignored"));
19458 else if (building_psymtab
)
19459 add_partial_symbol (&pdi
, cu
);
19461 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
19465 struct partial_die_info
*part_die
19466 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
19468 /* We'll save this DIE so link it in. */
19469 part_die
->die_parent
= parent_die
;
19470 part_die
->die_sibling
= NULL
;
19471 part_die
->die_child
= NULL
;
19473 if (last_die
&& last_die
== parent_die
)
19474 last_die
->die_child
= part_die
;
19476 last_die
->die_sibling
= part_die
;
19478 last_die
= part_die
;
19480 if (first_die
== NULL
)
19481 first_die
= part_die
;
19483 /* Maybe add the DIE to the hash table. Not all DIEs that we
19484 find interesting need to be in the hash table, because we
19485 also have the parent/sibling/child chains; only those that we
19486 might refer to by offset later during partial symbol reading.
19488 For now this means things that might have be the target of a
19489 DW_AT_specification, DW_AT_abstract_origin, or
19490 DW_AT_extension. DW_AT_extension will refer only to
19491 namespaces; DW_AT_abstract_origin refers to functions (and
19492 many things under the function DIE, but we do not recurse
19493 into function DIEs during partial symbol reading) and
19494 possibly variables as well; DW_AT_specification refers to
19495 declarations. Declarations ought to have the DW_AT_declaration
19496 flag. It happens that GCC forgets to put it in sometimes, but
19497 only for functions, not for types.
19499 Adding more things than necessary to the hash table is harmless
19500 except for the performance cost. Adding too few will result in
19501 wasted time in find_partial_die, when we reread the compilation
19502 unit with load_all_dies set. */
19505 || abbrev
->tag
== DW_TAG_constant
19506 || abbrev
->tag
== DW_TAG_subprogram
19507 || abbrev
->tag
== DW_TAG_variable
19508 || abbrev
->tag
== DW_TAG_namespace
19509 || part_die
->is_declaration
)
19513 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
19514 to_underlying (part_die
->sect_off
),
19519 /* For some DIEs we want to follow their children (if any). For C
19520 we have no reason to follow the children of structures; for other
19521 languages we have to, so that we can get at method physnames
19522 to infer fully qualified class names, for DW_AT_specification,
19523 and for C++ template arguments. For C++, we also look one level
19524 inside functions to find template arguments (if the name of the
19525 function does not already contain the template arguments).
19527 For Ada and Fortran, we need to scan the children of subprograms
19528 and lexical blocks as well because these languages allow the
19529 definition of nested entities that could be interesting for the
19530 debugger, such as nested subprograms for instance. */
19531 if (last_die
->has_children
19533 || last_die
->tag
== DW_TAG_namespace
19534 || last_die
->tag
== DW_TAG_module
19535 || last_die
->tag
== DW_TAG_enumeration_type
19536 || (cu
->language
== language_cplus
19537 && last_die
->tag
== DW_TAG_subprogram
19538 && (last_die
->raw_name
== NULL
19539 || strchr (last_die
->raw_name
, '<') == NULL
))
19540 || (cu
->language
!= language_c
19541 && (last_die
->tag
== DW_TAG_class_type
19542 || last_die
->tag
== DW_TAG_interface_type
19543 || last_die
->tag
== DW_TAG_structure_type
19544 || last_die
->tag
== DW_TAG_union_type
))
19545 || ((cu
->language
== language_ada
19546 || cu
->language
== language_fortran
)
19547 && (last_die
->tag
== DW_TAG_subprogram
19548 || last_die
->tag
== DW_TAG_lexical_block
))))
19551 parent_die
= last_die
;
19555 /* Otherwise we skip to the next sibling, if any. */
19556 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
19558 /* Back to the top, do it again. */
19562 partial_die_info::partial_die_info (sect_offset sect_off_
,
19563 struct abbrev_info
*abbrev
)
19564 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
19568 /* See class definition. */
19571 partial_die_info::name (dwarf2_cu
*cu
)
19573 if (!canonical_name
&& raw_name
!= nullptr)
19575 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19576 raw_name
= dwarf2_canonicalize_name (raw_name
, cu
, objfile
);
19577 canonical_name
= 1;
19583 /* Read a minimal amount of information into the minimal die structure.
19584 INFO_PTR should point just after the initial uleb128 of a DIE. */
19587 partial_die_info::read (const struct die_reader_specs
*reader
,
19588 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
19590 struct dwarf2_cu
*cu
= reader
->cu
;
19591 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19593 int has_low_pc_attr
= 0;
19594 int has_high_pc_attr
= 0;
19595 int high_pc_relative
= 0;
19597 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
19600 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
], info_ptr
);
19601 /* String and address offsets that need to do the reprocessing have
19602 already been read at this point, so there is no need to wait until
19603 the loop terminates to do the reprocessing. */
19604 if (attr
.requires_reprocessing_p ())
19605 read_attribute_reprocess (reader
, &attr
, tag
);
19606 /* Store the data if it is of an attribute we want to keep in a
19607 partial symbol table. */
19613 case DW_TAG_compile_unit
:
19614 case DW_TAG_partial_unit
:
19615 case DW_TAG_type_unit
:
19616 /* Compilation units have a DW_AT_name that is a filename, not
19617 a source language identifier. */
19618 case DW_TAG_enumeration_type
:
19619 case DW_TAG_enumerator
:
19620 /* These tags always have simple identifiers already; no need
19621 to canonicalize them. */
19622 canonical_name
= 1;
19623 raw_name
= attr
.as_string ();
19626 canonical_name
= 0;
19627 raw_name
= attr
.as_string ();
19631 case DW_AT_linkage_name
:
19632 case DW_AT_MIPS_linkage_name
:
19633 /* Note that both forms of linkage name might appear. We
19634 assume they will be the same, and we only store the last
19636 linkage_name
= attr
.as_string ();
19639 has_low_pc_attr
= 1;
19640 lowpc
= attr
.as_address ();
19642 case DW_AT_high_pc
:
19643 has_high_pc_attr
= 1;
19644 highpc
= attr
.as_address ();
19645 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
19646 high_pc_relative
= 1;
19648 case DW_AT_location
:
19649 /* Support the .debug_loc offsets. */
19650 if (attr
.form_is_block ())
19652 d
.locdesc
= attr
.as_block ();
19654 else if (attr
.form_is_section_offset ())
19656 dwarf2_complex_location_expr_complaint ();
19660 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
19661 "partial symbol information");
19664 case DW_AT_external
:
19665 is_external
= attr
.as_boolean ();
19667 case DW_AT_declaration
:
19668 is_declaration
= attr
.as_boolean ();
19673 case DW_AT_abstract_origin
:
19674 case DW_AT_specification
:
19675 case DW_AT_extension
:
19676 has_specification
= 1;
19677 spec_offset
= attr
.get_ref_die_offset ();
19678 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19679 || cu
->per_cu
->is_dwz
);
19681 case DW_AT_sibling
:
19682 /* Ignore absolute siblings, they might point outside of
19683 the current compile unit. */
19684 if (attr
.form
== DW_FORM_ref_addr
)
19685 complaint (_("ignoring absolute DW_AT_sibling"));
19688 const gdb_byte
*buffer
= reader
->buffer
;
19689 sect_offset off
= attr
.get_ref_die_offset ();
19690 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
19692 if (sibling_ptr
< info_ptr
)
19693 complaint (_("DW_AT_sibling points backwards"));
19694 else if (sibling_ptr
> reader
->buffer_end
)
19695 reader
->die_section
->overflow_complaint ();
19697 sibling
= sibling_ptr
;
19700 case DW_AT_byte_size
:
19703 case DW_AT_const_value
:
19704 has_const_value
= 1;
19706 case DW_AT_calling_convention
:
19707 /* DWARF doesn't provide a way to identify a program's source-level
19708 entry point. DW_AT_calling_convention attributes are only meant
19709 to describe functions' calling conventions.
19711 However, because it's a necessary piece of information in
19712 Fortran, and before DWARF 4 DW_CC_program was the only
19713 piece of debugging information whose definition refers to
19714 a 'main program' at all, several compilers marked Fortran
19715 main programs with DW_CC_program --- even when those
19716 functions use the standard calling conventions.
19718 Although DWARF now specifies a way to provide this
19719 information, we support this practice for backward
19721 if (attr
.constant_value (0) == DW_CC_program
19722 && cu
->language
== language_fortran
)
19723 main_subprogram
= 1;
19727 LONGEST value
= attr
.constant_value (-1);
19728 if (value
== DW_INL_inlined
19729 || value
== DW_INL_declared_inlined
)
19730 may_be_inlined
= 1;
19735 if (tag
== DW_TAG_imported_unit
)
19737 d
.sect_off
= attr
.get_ref_die_offset ();
19738 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19739 || cu
->per_cu
->is_dwz
);
19743 case DW_AT_main_subprogram
:
19744 main_subprogram
= attr
.as_boolean ();
19749 /* DW_AT_rnglists_base does not apply to DIEs from the DWO
19750 skeleton. We take advantage of the fact the DW_AT_ranges
19751 does not appear in DW_TAG_compile_unit of DWO files.
19753 Attributes of the form DW_FORM_rnglistx have already had
19754 their value changed by read_rnglist_index and already
19755 include DW_AT_rnglists_base, so don't need to add the ranges
19757 int need_ranges_base
= (tag
!= DW_TAG_compile_unit
19758 && attr
.form
!= DW_FORM_rnglistx
);
19759 /* It would be nice to reuse dwarf2_get_pc_bounds here,
19760 but that requires a full DIE, so instead we just
19762 unsigned int ranges_offset
= (attr
.constant_value (0)
19763 + (need_ranges_base
19767 /* Value of the DW_AT_ranges attribute is the offset in the
19768 .debug_ranges section. */
19769 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
19780 /* For Ada, if both the name and the linkage name appear, we prefer
19781 the latter. This lets "catch exception" work better, regardless
19782 of the order in which the name and linkage name were emitted.
19783 Really, though, this is just a workaround for the fact that gdb
19784 doesn't store both the name and the linkage name. */
19785 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
19786 raw_name
= linkage_name
;
19788 if (high_pc_relative
)
19791 if (has_low_pc_attr
&& has_high_pc_attr
)
19793 /* When using the GNU linker, .gnu.linkonce. sections are used to
19794 eliminate duplicate copies of functions and vtables and such.
19795 The linker will arbitrarily choose one and discard the others.
19796 The AT_*_pc values for such functions refer to local labels in
19797 these sections. If the section from that file was discarded, the
19798 labels are not in the output, so the relocs get a value of 0.
19799 If this is a discarded function, mark the pc bounds as invalid,
19800 so that GDB will ignore it. */
19801 if (lowpc
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
19803 struct objfile
*objfile
= per_objfile
->objfile
;
19804 struct gdbarch
*gdbarch
= objfile
->arch ();
19806 complaint (_("DW_AT_low_pc %s is zero "
19807 "for DIE at %s [in module %s]"),
19808 paddress (gdbarch
, lowpc
),
19809 sect_offset_str (sect_off
),
19810 objfile_name (objfile
));
19812 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
19813 else if (lowpc
>= highpc
)
19815 struct objfile
*objfile
= per_objfile
->objfile
;
19816 struct gdbarch
*gdbarch
= objfile
->arch ();
19818 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
19819 "for DIE at %s [in module %s]"),
19820 paddress (gdbarch
, lowpc
),
19821 paddress (gdbarch
, highpc
),
19822 sect_offset_str (sect_off
),
19823 objfile_name (objfile
));
19832 /* Find a cached partial DIE at OFFSET in CU. */
19834 struct partial_die_info
*
19835 dwarf2_cu::find_partial_die (sect_offset sect_off
)
19837 struct partial_die_info
*lookup_die
= NULL
;
19838 struct partial_die_info
part_die (sect_off
);
19840 lookup_die
= ((struct partial_die_info
*)
19841 htab_find_with_hash (partial_dies
, &part_die
,
19842 to_underlying (sect_off
)));
19847 /* Find a partial DIE at OFFSET, which may or may not be in CU,
19848 except in the case of .debug_types DIEs which do not reference
19849 outside their CU (they do however referencing other types via
19850 DW_FORM_ref_sig8). */
19852 static const struct cu_partial_die_info
19853 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
19855 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19856 struct objfile
*objfile
= per_objfile
->objfile
;
19857 struct partial_die_info
*pd
= NULL
;
19859 if (offset_in_dwz
== cu
->per_cu
->is_dwz
19860 && cu
->header
.offset_in_cu_p (sect_off
))
19862 pd
= cu
->find_partial_die (sect_off
);
19865 /* We missed recording what we needed.
19866 Load all dies and try again. */
19870 /* TUs don't reference other CUs/TUs (except via type signatures). */
19871 if (cu
->per_cu
->is_debug_types
)
19873 error (_("Dwarf Error: Type Unit at offset %s contains"
19874 " external reference to offset %s [in module %s].\n"),
19875 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
19876 bfd_get_filename (objfile
->obfd
));
19878 dwarf2_per_cu_data
*per_cu
19879 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
19882 cu
= per_objfile
->get_cu (per_cu
);
19883 if (cu
== NULL
|| cu
->partial_dies
== NULL
)
19884 load_partial_comp_unit (per_cu
, per_objfile
, nullptr);
19886 cu
= per_objfile
->get_cu (per_cu
);
19889 pd
= cu
->find_partial_die (sect_off
);
19892 /* If we didn't find it, and not all dies have been loaded,
19893 load them all and try again. */
19895 if (pd
== NULL
&& cu
->per_cu
->load_all_dies
== 0)
19897 cu
->per_cu
->load_all_dies
= 1;
19899 /* This is nasty. When we reread the DIEs, somewhere up the call chain
19900 THIS_CU->cu may already be in use. So we can't just free it and
19901 replace its DIEs with the ones we read in. Instead, we leave those
19902 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
19903 and clobber THIS_CU->cu->partial_dies with the hash table for the new
19905 load_partial_comp_unit (cu
->per_cu
, per_objfile
, cu
);
19907 pd
= cu
->find_partial_die (sect_off
);
19911 error (_("Dwarf Error: Cannot not find DIE at %s [from module %s]\n"),
19912 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
19916 /* See if we can figure out if the class lives in a namespace. We do
19917 this by looking for a member function; its demangled name will
19918 contain namespace info, if there is any. */
19921 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
19922 struct dwarf2_cu
*cu
)
19924 /* NOTE: carlton/2003-10-07: Getting the info this way changes
19925 what template types look like, because the demangler
19926 frequently doesn't give the same name as the debug info. We
19927 could fix this by only using the demangled name to get the
19928 prefix (but see comment in read_structure_type). */
19930 struct partial_die_info
*real_pdi
;
19931 struct partial_die_info
*child_pdi
;
19933 /* If this DIE (this DIE's specification, if any) has a parent, then
19934 we should not do this. We'll prepend the parent's fully qualified
19935 name when we create the partial symbol. */
19937 real_pdi
= struct_pdi
;
19938 while (real_pdi
->has_specification
)
19940 auto res
= find_partial_die (real_pdi
->spec_offset
,
19941 real_pdi
->spec_is_dwz
, cu
);
19942 real_pdi
= res
.pdi
;
19946 if (real_pdi
->die_parent
!= NULL
)
19949 for (child_pdi
= struct_pdi
->die_child
;
19951 child_pdi
= child_pdi
->die_sibling
)
19953 if (child_pdi
->tag
== DW_TAG_subprogram
19954 && child_pdi
->linkage_name
!= NULL
)
19956 gdb::unique_xmalloc_ptr
<char> actual_class_name
19957 (cu
->language_defn
->class_name_from_physname
19958 (child_pdi
->linkage_name
));
19959 if (actual_class_name
!= NULL
)
19961 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19962 struct_pdi
->raw_name
= objfile
->intern (actual_class_name
.get ());
19963 struct_pdi
->canonical_name
= 1;
19970 /* Return true if a DIE with TAG may have the DW_AT_const_value
19974 can_have_DW_AT_const_value_p (enum dwarf_tag tag
)
19978 case DW_TAG_constant
:
19979 case DW_TAG_enumerator
:
19980 case DW_TAG_formal_parameter
:
19981 case DW_TAG_template_value_param
:
19982 case DW_TAG_variable
:
19990 partial_die_info::fixup (struct dwarf2_cu
*cu
)
19992 /* Once we've fixed up a die, there's no point in doing so again.
19993 This also avoids a memory leak if we were to call
19994 guess_partial_die_structure_name multiple times. */
19998 /* If we found a reference attribute and the DIE has no name, try
19999 to find a name in the referred to DIE. */
20001 if (raw_name
== NULL
&& has_specification
)
20003 struct partial_die_info
*spec_die
;
20005 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
20006 spec_die
= res
.pdi
;
20009 spec_die
->fixup (cu
);
20011 if (spec_die
->raw_name
)
20013 raw_name
= spec_die
->raw_name
;
20014 canonical_name
= spec_die
->canonical_name
;
20016 /* Copy DW_AT_external attribute if it is set. */
20017 if (spec_die
->is_external
)
20018 is_external
= spec_die
->is_external
;
20022 if (!has_const_value
&& has_specification
20023 && can_have_DW_AT_const_value_p (tag
))
20025 struct partial_die_info
*spec_die
;
20027 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
20028 spec_die
= res
.pdi
;
20031 spec_die
->fixup (cu
);
20033 if (spec_die
->has_const_value
)
20035 /* Copy DW_AT_const_value attribute if it is set. */
20036 has_const_value
= spec_die
->has_const_value
;
20040 /* Set default names for some unnamed DIEs. */
20042 if (raw_name
== NULL
&& tag
== DW_TAG_namespace
)
20044 raw_name
= CP_ANONYMOUS_NAMESPACE_STR
;
20045 canonical_name
= 1;
20048 /* If there is no parent die to provide a namespace, and there are
20049 children, see if we can determine the namespace from their linkage
20051 if (cu
->language
== language_cplus
20052 && !cu
->per_objfile
->per_bfd
->types
.empty ()
20053 && die_parent
== NULL
20055 && (tag
== DW_TAG_class_type
20056 || tag
== DW_TAG_structure_type
20057 || tag
== DW_TAG_union_type
))
20058 guess_partial_die_structure_name (this, cu
);
20060 /* GCC might emit a nameless struct or union that has a linkage
20061 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
20062 if (raw_name
== NULL
20063 && (tag
== DW_TAG_class_type
20064 || tag
== DW_TAG_interface_type
20065 || tag
== DW_TAG_structure_type
20066 || tag
== DW_TAG_union_type
)
20067 && linkage_name
!= NULL
)
20069 gdb::unique_xmalloc_ptr
<char> demangled
20070 (gdb_demangle (linkage_name
, DMGL_TYPES
));
20071 if (demangled
!= nullptr)
20075 /* Strip any leading namespaces/classes, keep only the base name.
20076 DW_AT_name for named DIEs does not contain the prefixes. */
20077 base
= strrchr (demangled
.get (), ':');
20078 if (base
&& base
> demangled
.get () && base
[-1] == ':')
20081 base
= demangled
.get ();
20083 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20084 raw_name
= objfile
->intern (base
);
20085 canonical_name
= 1;
20092 /* Read the .debug_loclists or .debug_rnglists header (they are the same format)
20093 contents from the given SECTION in the HEADER. */
20095 read_loclists_rnglists_header (struct loclists_rnglists_header
*header
,
20096 struct dwarf2_section_info
*section
)
20098 unsigned int bytes_read
;
20099 bfd
*abfd
= section
->get_bfd_owner ();
20100 const gdb_byte
*info_ptr
= section
->buffer
;
20101 header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
20102 info_ptr
+= bytes_read
;
20103 header
->version
= read_2_bytes (abfd
, info_ptr
);
20105 header
->addr_size
= read_1_byte (abfd
, info_ptr
);
20107 header
->segment_collector_size
= read_1_byte (abfd
, info_ptr
);
20109 header
->offset_entry_count
= read_4_bytes (abfd
, info_ptr
);
20112 /* Return the DW_AT_loclists_base value for the CU. */
20114 lookup_loclist_base (struct dwarf2_cu
*cu
)
20116 /* For the .dwo unit, the loclist_base points to the first offset following
20117 the header. The header consists of the following entities-
20118 1. Unit Length (4 bytes for 32 bit DWARF format, and 12 bytes for the 64
20120 2. version (2 bytes)
20121 3. address size (1 byte)
20122 4. segment selector size (1 byte)
20123 5. offset entry count (4 bytes)
20124 These sizes are derived as per the DWARFv5 standard. */
20125 if (cu
->dwo_unit
!= nullptr)
20127 if (cu
->header
.initial_length_size
== 4)
20128 return LOCLIST_HEADER_SIZE32
;
20129 return LOCLIST_HEADER_SIZE64
;
20131 return cu
->loclist_base
;
20134 /* Given a DW_FORM_loclistx value LOCLIST_INDEX, fetch the offset from the
20135 array of offsets in the .debug_loclists section. */
20137 read_loclist_index (struct dwarf2_cu
*cu
, ULONGEST loclist_index
)
20139 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20140 struct objfile
*objfile
= per_objfile
->objfile
;
20141 bfd
*abfd
= objfile
->obfd
;
20142 ULONGEST loclist_base
= lookup_loclist_base (cu
);
20143 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
20145 section
->read (objfile
);
20146 if (section
->buffer
== NULL
)
20147 complaint (_("DW_FORM_loclistx used without .debug_loclists "
20148 "section [in module %s]"), objfile_name (objfile
));
20149 struct loclists_rnglists_header header
;
20150 read_loclists_rnglists_header (&header
, section
);
20151 if (loclist_index
>= header
.offset_entry_count
)
20152 complaint (_("DW_FORM_loclistx pointing outside of "
20153 ".debug_loclists offset array [in module %s]"),
20154 objfile_name (objfile
));
20155 if (loclist_base
+ loclist_index
* cu
->header
.offset_size
20157 complaint (_("DW_FORM_loclistx pointing outside of "
20158 ".debug_loclists section [in module %s]"),
20159 objfile_name (objfile
));
20160 const gdb_byte
*info_ptr
20161 = section
->buffer
+ loclist_base
+ loclist_index
* cu
->header
.offset_size
;
20163 if (cu
->header
.offset_size
== 4)
20164 return bfd_get_32 (abfd
, info_ptr
) + loclist_base
;
20166 return bfd_get_64 (abfd
, info_ptr
) + loclist_base
;
20169 /* Given a DW_FORM_rnglistx value RNGLIST_INDEX, fetch the offset from the
20170 array of offsets in the .debug_rnglists section. */
20172 read_rnglist_index (struct dwarf2_cu
*cu
, ULONGEST rnglist_index
,
20175 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
20176 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20177 bfd
*abfd
= objfile
->obfd
;
20178 ULONGEST rnglist_header_size
=
20179 (cu
->header
.initial_length_size
== 4 ? RNGLIST_HEADER_SIZE32
20180 : RNGLIST_HEADER_SIZE64
);
20181 ULONGEST rnglist_base
=
20182 (cu
->dwo_unit
!= nullptr) ? rnglist_header_size
: cu
->ranges_base
;
20183 ULONGEST start_offset
=
20184 rnglist_base
+ rnglist_index
* cu
->header
.offset_size
;
20186 /* Get rnglists section. */
20187 struct dwarf2_section_info
*section
= cu_debug_rnglists_section (cu
, tag
);
20189 /* Read the rnglists section content. */
20190 section
->read (objfile
);
20191 if (section
->buffer
== nullptr)
20192 error (_("DW_FORM_rnglistx used without .debug_rnglists section "
20194 objfile_name (objfile
));
20196 /* Verify the rnglist index is valid. */
20197 struct loclists_rnglists_header header
;
20198 read_loclists_rnglists_header (&header
, section
);
20199 if (rnglist_index
>= header
.offset_entry_count
)
20200 error (_("DW_FORM_rnglistx index pointing outside of "
20201 ".debug_rnglists offset array [in module %s]"),
20202 objfile_name (objfile
));
20204 /* Validate that the offset is within the section's range. */
20205 if (start_offset
>= section
->size
)
20206 error (_("DW_FORM_rnglistx pointing outside of "
20207 ".debug_rnglists section [in module %s]"),
20208 objfile_name (objfile
));
20210 /* Validate that reading won't go beyond the end of the section. */
20211 if (start_offset
+ cu
->header
.offset_size
> rnglist_base
+ section
->size
)
20212 error (_("Reading DW_FORM_rnglistx index beyond end of"
20213 ".debug_rnglists section [in module %s]"),
20214 objfile_name (objfile
));
20216 const gdb_byte
*info_ptr
= section
->buffer
+ start_offset
;
20218 if (cu
->header
.offset_size
== 4)
20219 return read_4_bytes (abfd
, info_ptr
) + rnglist_base
;
20221 return read_8_bytes (abfd
, info_ptr
) + rnglist_base
;
20224 /* Process the attributes that had to be skipped in the first round. These
20225 attributes are the ones that need str_offsets_base or addr_base attributes.
20226 They could not have been processed in the first round, because at the time
20227 the values of str_offsets_base or addr_base may not have been known. */
20229 read_attribute_reprocess (const struct die_reader_specs
*reader
,
20230 struct attribute
*attr
, dwarf_tag tag
)
20232 struct dwarf2_cu
*cu
= reader
->cu
;
20233 switch (attr
->form
)
20235 case DW_FORM_addrx
:
20236 case DW_FORM_GNU_addr_index
:
20237 attr
->set_address (read_addr_index (cu
,
20238 attr
->as_unsigned_reprocess ()));
20240 case DW_FORM_loclistx
:
20241 attr
->set_address (read_loclist_index (cu
, attr
->as_unsigned ()));
20243 case DW_FORM_rnglistx
:
20244 attr
->set_address (read_rnglist_index (cu
, attr
->as_unsigned (), tag
));
20247 case DW_FORM_strx1
:
20248 case DW_FORM_strx2
:
20249 case DW_FORM_strx3
:
20250 case DW_FORM_strx4
:
20251 case DW_FORM_GNU_str_index
:
20253 unsigned int str_index
= attr
->as_unsigned_reprocess ();
20254 gdb_assert (!attr
->canonical_string_p ());
20255 if (reader
->dwo_file
!= NULL
)
20256 attr
->set_string_noncanonical (read_dwo_str_index (reader
,
20259 attr
->set_string_noncanonical (read_stub_str_index (cu
,
20264 gdb_assert_not_reached (_("Unexpected DWARF form."));
20268 /* Read an attribute value described by an attribute form. */
20270 static const gdb_byte
*
20271 read_attribute_value (const struct die_reader_specs
*reader
,
20272 struct attribute
*attr
, unsigned form
,
20273 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
20275 struct dwarf2_cu
*cu
= reader
->cu
;
20276 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20277 struct objfile
*objfile
= per_objfile
->objfile
;
20278 bfd
*abfd
= reader
->abfd
;
20279 struct comp_unit_head
*cu_header
= &cu
->header
;
20280 unsigned int bytes_read
;
20281 struct dwarf_block
*blk
;
20283 attr
->form
= (enum dwarf_form
) form
;
20286 case DW_FORM_ref_addr
:
20287 if (cu
->header
.version
== 2)
20288 attr
->set_unsigned (cu
->header
.read_address (abfd
, info_ptr
,
20291 attr
->set_unsigned (cu
->header
.read_offset (abfd
, info_ptr
,
20293 info_ptr
+= bytes_read
;
20295 case DW_FORM_GNU_ref_alt
:
20296 attr
->set_unsigned (cu
->header
.read_offset (abfd
, info_ptr
,
20298 info_ptr
+= bytes_read
;
20302 struct gdbarch
*gdbarch
= objfile
->arch ();
20303 CORE_ADDR addr
= cu
->header
.read_address (abfd
, info_ptr
, &bytes_read
);
20304 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
);
20305 attr
->set_address (addr
);
20306 info_ptr
+= bytes_read
;
20309 case DW_FORM_block2
:
20310 blk
= dwarf_alloc_block (cu
);
20311 blk
->size
= read_2_bytes (abfd
, info_ptr
);
20313 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20314 info_ptr
+= blk
->size
;
20315 attr
->set_block (blk
);
20317 case DW_FORM_block4
:
20318 blk
= dwarf_alloc_block (cu
);
20319 blk
->size
= read_4_bytes (abfd
, info_ptr
);
20321 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20322 info_ptr
+= blk
->size
;
20323 attr
->set_block (blk
);
20325 case DW_FORM_data2
:
20326 attr
->set_unsigned (read_2_bytes (abfd
, info_ptr
));
20329 case DW_FORM_data4
:
20330 attr
->set_unsigned (read_4_bytes (abfd
, info_ptr
));
20333 case DW_FORM_data8
:
20334 attr
->set_unsigned (read_8_bytes (abfd
, info_ptr
));
20337 case DW_FORM_data16
:
20338 blk
= dwarf_alloc_block (cu
);
20340 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
20342 attr
->set_block (blk
);
20344 case DW_FORM_sec_offset
:
20345 attr
->set_unsigned (cu
->header
.read_offset (abfd
, info_ptr
,
20347 info_ptr
+= bytes_read
;
20349 case DW_FORM_loclistx
:
20351 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20353 info_ptr
+= bytes_read
;
20356 case DW_FORM_string
:
20357 attr
->set_string_noncanonical (read_direct_string (abfd
, info_ptr
,
20359 info_ptr
+= bytes_read
;
20362 if (!cu
->per_cu
->is_dwz
)
20364 attr
->set_string_noncanonical
20365 (read_indirect_string (per_objfile
,
20366 abfd
, info_ptr
, cu_header
,
20368 info_ptr
+= bytes_read
;
20372 case DW_FORM_line_strp
:
20373 if (!cu
->per_cu
->is_dwz
)
20375 attr
->set_string_noncanonical
20376 (per_objfile
->read_line_string (info_ptr
, cu_header
,
20378 info_ptr
+= bytes_read
;
20382 case DW_FORM_GNU_strp_alt
:
20384 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
20385 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
20388 attr
->set_string_noncanonical
20389 (dwz
->read_string (objfile
, str_offset
));
20390 info_ptr
+= bytes_read
;
20393 case DW_FORM_exprloc
:
20394 case DW_FORM_block
:
20395 blk
= dwarf_alloc_block (cu
);
20396 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20397 info_ptr
+= bytes_read
;
20398 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20399 info_ptr
+= blk
->size
;
20400 attr
->set_block (blk
);
20402 case DW_FORM_block1
:
20403 blk
= dwarf_alloc_block (cu
);
20404 blk
->size
= read_1_byte (abfd
, info_ptr
);
20406 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20407 info_ptr
+= blk
->size
;
20408 attr
->set_block (blk
);
20410 case DW_FORM_data1
:
20412 attr
->set_unsigned (read_1_byte (abfd
, info_ptr
));
20415 case DW_FORM_flag_present
:
20416 attr
->set_unsigned (1);
20418 case DW_FORM_sdata
:
20419 attr
->set_signed (read_signed_leb128 (abfd
, info_ptr
, &bytes_read
));
20420 info_ptr
+= bytes_read
;
20422 case DW_FORM_rnglistx
:
20424 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20426 info_ptr
+= bytes_read
;
20429 case DW_FORM_udata
:
20430 attr
->set_unsigned (read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
20431 info_ptr
+= bytes_read
;
20434 attr
->set_unsigned ((to_underlying (cu
->header
.sect_off
)
20435 + read_1_byte (abfd
, info_ptr
)));
20439 attr
->set_unsigned ((to_underlying (cu
->header
.sect_off
)
20440 + read_2_bytes (abfd
, info_ptr
)));
20444 attr
->set_unsigned ((to_underlying (cu
->header
.sect_off
)
20445 + read_4_bytes (abfd
, info_ptr
)));
20449 attr
->set_unsigned ((to_underlying (cu
->header
.sect_off
)
20450 + read_8_bytes (abfd
, info_ptr
)));
20453 case DW_FORM_ref_sig8
:
20454 attr
->set_signature (read_8_bytes (abfd
, info_ptr
));
20457 case DW_FORM_ref_udata
:
20458 attr
->set_unsigned ((to_underlying (cu
->header
.sect_off
)
20459 + read_unsigned_leb128 (abfd
, info_ptr
,
20461 info_ptr
+= bytes_read
;
20463 case DW_FORM_indirect
:
20464 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20465 info_ptr
+= bytes_read
;
20466 if (form
== DW_FORM_implicit_const
)
20468 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
20469 info_ptr
+= bytes_read
;
20471 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
20474 case DW_FORM_implicit_const
:
20475 attr
->set_signed (implicit_const
);
20477 case DW_FORM_addrx
:
20478 case DW_FORM_GNU_addr_index
:
20479 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20481 info_ptr
+= bytes_read
;
20484 case DW_FORM_strx1
:
20485 case DW_FORM_strx2
:
20486 case DW_FORM_strx3
:
20487 case DW_FORM_strx4
:
20488 case DW_FORM_GNU_str_index
:
20490 ULONGEST str_index
;
20491 if (form
== DW_FORM_strx1
)
20493 str_index
= read_1_byte (abfd
, info_ptr
);
20496 else if (form
== DW_FORM_strx2
)
20498 str_index
= read_2_bytes (abfd
, info_ptr
);
20501 else if (form
== DW_FORM_strx3
)
20503 str_index
= read_3_bytes (abfd
, info_ptr
);
20506 else if (form
== DW_FORM_strx4
)
20508 str_index
= read_4_bytes (abfd
, info_ptr
);
20513 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20514 info_ptr
+= bytes_read
;
20516 attr
->set_unsigned_reprocess (str_index
);
20520 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
20521 dwarf_form_name (form
),
20522 bfd_get_filename (abfd
));
20526 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
20527 attr
->form
= DW_FORM_GNU_ref_alt
;
20529 /* We have seen instances where the compiler tried to emit a byte
20530 size attribute of -1 which ended up being encoded as an unsigned
20531 0xffffffff. Although 0xffffffff is technically a valid size value,
20532 an object of this size seems pretty unlikely so we can relatively
20533 safely treat these cases as if the size attribute was invalid and
20534 treat them as zero by default. */
20535 if (attr
->name
== DW_AT_byte_size
20536 && form
== DW_FORM_data4
20537 && attr
->as_unsigned () >= 0xffffffff)
20540 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
20541 hex_string (attr
->as_unsigned ()));
20542 attr
->set_unsigned (0);
20548 /* Read an attribute described by an abbreviated attribute. */
20550 static const gdb_byte
*
20551 read_attribute (const struct die_reader_specs
*reader
,
20552 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
20553 const gdb_byte
*info_ptr
)
20555 attr
->name
= abbrev
->name
;
20556 attr
->string_is_canonical
= 0;
20557 attr
->requires_reprocessing
= 0;
20558 return read_attribute_value (reader
, attr
, abbrev
->form
,
20559 abbrev
->implicit_const
, info_ptr
);
20562 /* Return pointer to string at .debug_str offset STR_OFFSET. */
20564 static const char *
20565 read_indirect_string_at_offset (dwarf2_per_objfile
*per_objfile
,
20566 LONGEST str_offset
)
20568 return per_objfile
->per_bfd
->str
.read_string (per_objfile
->objfile
,
20569 str_offset
, "DW_FORM_strp");
20572 /* Return pointer to string at .debug_str offset as read from BUF.
20573 BUF is assumed to be in a compilation unit described by CU_HEADER.
20574 Return *BYTES_READ_PTR count of bytes read from BUF. */
20576 static const char *
20577 read_indirect_string (dwarf2_per_objfile
*per_objfile
, bfd
*abfd
,
20578 const gdb_byte
*buf
,
20579 const struct comp_unit_head
*cu_header
,
20580 unsigned int *bytes_read_ptr
)
20582 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
20584 return read_indirect_string_at_offset (per_objfile
, str_offset
);
20590 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
20591 const struct comp_unit_head
*cu_header
,
20592 unsigned int *bytes_read_ptr
)
20594 bfd
*abfd
= objfile
->obfd
;
20595 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
20597 return per_bfd
->line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
20600 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
20601 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
20602 ADDR_SIZE is the size of addresses from the CU header. */
20605 read_addr_index_1 (dwarf2_per_objfile
*per_objfile
, unsigned int addr_index
,
20606 gdb::optional
<ULONGEST
> addr_base
, int addr_size
)
20608 struct objfile
*objfile
= per_objfile
->objfile
;
20609 bfd
*abfd
= objfile
->obfd
;
20610 const gdb_byte
*info_ptr
;
20611 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
20613 per_objfile
->per_bfd
->addr
.read (objfile
);
20614 if (per_objfile
->per_bfd
->addr
.buffer
== NULL
)
20615 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
20616 objfile_name (objfile
));
20617 if (addr_base_or_zero
+ addr_index
* addr_size
20618 >= per_objfile
->per_bfd
->addr
.size
)
20619 error (_("DW_FORM_addr_index pointing outside of "
20620 ".debug_addr section [in module %s]"),
20621 objfile_name (objfile
));
20622 info_ptr
= (per_objfile
->per_bfd
->addr
.buffer
+ addr_base_or_zero
20623 + addr_index
* addr_size
);
20624 if (addr_size
== 4)
20625 return bfd_get_32 (abfd
, info_ptr
);
20627 return bfd_get_64 (abfd
, info_ptr
);
20630 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
20633 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
20635 return read_addr_index_1 (cu
->per_objfile
, addr_index
,
20636 cu
->addr_base
, cu
->header
.addr_size
);
20639 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
20642 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
20643 unsigned int *bytes_read
)
20645 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
20646 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
20648 return read_addr_index (cu
, addr_index
);
20654 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
,
20655 dwarf2_per_objfile
*per_objfile
,
20656 unsigned int addr_index
)
20658 struct dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
20659 gdb::optional
<ULONGEST
> addr_base
;
20662 /* We need addr_base and addr_size.
20663 If we don't have PER_CU->cu, we have to get it.
20664 Nasty, but the alternative is storing the needed info in PER_CU,
20665 which at this point doesn't seem justified: it's not clear how frequently
20666 it would get used and it would increase the size of every PER_CU.
20667 Entry points like dwarf2_per_cu_addr_size do a similar thing
20668 so we're not in uncharted territory here.
20669 Alas we need to be a bit more complicated as addr_base is contained
20672 We don't need to read the entire CU(/TU).
20673 We just need the header and top level die.
20675 IWBN to use the aging mechanism to let us lazily later discard the CU.
20676 For now we skip this optimization. */
20680 addr_base
= cu
->addr_base
;
20681 addr_size
= cu
->header
.addr_size
;
20685 cutu_reader
reader (per_cu
, per_objfile
, nullptr, nullptr, false);
20686 addr_base
= reader
.cu
->addr_base
;
20687 addr_size
= reader
.cu
->header
.addr_size
;
20690 return read_addr_index_1 (per_objfile
, addr_index
, addr_base
, addr_size
);
20693 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
20694 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
20697 static const char *
20698 read_str_index (struct dwarf2_cu
*cu
,
20699 struct dwarf2_section_info
*str_section
,
20700 struct dwarf2_section_info
*str_offsets_section
,
20701 ULONGEST str_offsets_base
, ULONGEST str_index
)
20703 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20704 struct objfile
*objfile
= per_objfile
->objfile
;
20705 const char *objf_name
= objfile_name (objfile
);
20706 bfd
*abfd
= objfile
->obfd
;
20707 const gdb_byte
*info_ptr
;
20708 ULONGEST str_offset
;
20709 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
20711 str_section
->read (objfile
);
20712 str_offsets_section
->read (objfile
);
20713 if (str_section
->buffer
== NULL
)
20714 error (_("%s used without %s section"
20715 " in CU at offset %s [in module %s]"),
20716 form_name
, str_section
->get_name (),
20717 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20718 if (str_offsets_section
->buffer
== NULL
)
20719 error (_("%s used without %s section"
20720 " in CU at offset %s [in module %s]"),
20721 form_name
, str_section
->get_name (),
20722 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20723 info_ptr
= (str_offsets_section
->buffer
20725 + str_index
* cu
->header
.offset_size
);
20726 if (cu
->header
.offset_size
== 4)
20727 str_offset
= bfd_get_32 (abfd
, info_ptr
);
20729 str_offset
= bfd_get_64 (abfd
, info_ptr
);
20730 if (str_offset
>= str_section
->size
)
20731 error (_("Offset from %s pointing outside of"
20732 " .debug_str.dwo section in CU at offset %s [in module %s]"),
20733 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20734 return (const char *) (str_section
->buffer
+ str_offset
);
20737 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
20739 static const char *
20740 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
20742 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
20743 ? reader
->cu
->header
.addr_size
: 0;
20744 return read_str_index (reader
->cu
,
20745 &reader
->dwo_file
->sections
.str
,
20746 &reader
->dwo_file
->sections
.str_offsets
,
20747 str_offsets_base
, str_index
);
20750 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
20752 static const char *
20753 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
20755 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20756 const char *objf_name
= objfile_name (objfile
);
20757 static const char form_name
[] = "DW_FORM_GNU_str_index";
20758 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
20760 if (!cu
->str_offsets_base
.has_value ())
20761 error (_("%s used in Fission stub without %s"
20762 " in CU at offset 0x%lx [in module %s]"),
20763 form_name
, str_offsets_attr_name
,
20764 (long) cu
->header
.offset_size
, objf_name
);
20766 return read_str_index (cu
,
20767 &cu
->per_objfile
->per_bfd
->str
,
20768 &cu
->per_objfile
->per_bfd
->str_offsets
,
20769 *cu
->str_offsets_base
, str_index
);
20772 /* Return the length of an LEB128 number in BUF. */
20775 leb128_size (const gdb_byte
*buf
)
20777 const gdb_byte
*begin
= buf
;
20783 if ((byte
& 128) == 0)
20784 return buf
- begin
;
20789 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
20798 cu
->language
= language_c
;
20801 case DW_LANG_C_plus_plus
:
20802 case DW_LANG_C_plus_plus_11
:
20803 case DW_LANG_C_plus_plus_14
:
20804 cu
->language
= language_cplus
;
20807 cu
->language
= language_d
;
20809 case DW_LANG_Fortran77
:
20810 case DW_LANG_Fortran90
:
20811 case DW_LANG_Fortran95
:
20812 case DW_LANG_Fortran03
:
20813 case DW_LANG_Fortran08
:
20814 cu
->language
= language_fortran
;
20817 cu
->language
= language_go
;
20819 case DW_LANG_Mips_Assembler
:
20820 cu
->language
= language_asm
;
20822 case DW_LANG_Ada83
:
20823 case DW_LANG_Ada95
:
20824 cu
->language
= language_ada
;
20826 case DW_LANG_Modula2
:
20827 cu
->language
= language_m2
;
20829 case DW_LANG_Pascal83
:
20830 cu
->language
= language_pascal
;
20833 cu
->language
= language_objc
;
20836 case DW_LANG_Rust_old
:
20837 cu
->language
= language_rust
;
20839 case DW_LANG_Cobol74
:
20840 case DW_LANG_Cobol85
:
20842 cu
->language
= language_minimal
;
20845 cu
->language_defn
= language_def (cu
->language
);
20848 /* Return the named attribute or NULL if not there. */
20850 static struct attribute
*
20851 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20856 struct attribute
*spec
= NULL
;
20858 for (i
= 0; i
< die
->num_attrs
; ++i
)
20860 if (die
->attrs
[i
].name
== name
)
20861 return &die
->attrs
[i
];
20862 if (die
->attrs
[i
].name
== DW_AT_specification
20863 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
20864 spec
= &die
->attrs
[i
];
20870 die
= follow_die_ref (die
, spec
, &cu
);
20876 /* Return the string associated with a string-typed attribute, or NULL if it
20877 is either not found or is of an incorrect type. */
20879 static const char *
20880 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20882 struct attribute
*attr
;
20883 const char *str
= NULL
;
20885 attr
= dwarf2_attr (die
, name
, cu
);
20889 str
= attr
->as_string ();
20890 if (str
== nullptr)
20891 complaint (_("string type expected for attribute %s for "
20892 "DIE at %s in module %s"),
20893 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
20894 objfile_name (cu
->per_objfile
->objfile
));
20900 /* Return the dwo name or NULL if not present. If present, it is in either
20901 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
20902 static const char *
20903 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
20905 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
20906 if (dwo_name
== nullptr)
20907 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
20911 /* Return non-zero iff the attribute NAME is defined for the given DIE,
20912 and holds a non-zero value. This function should only be used for
20913 DW_FORM_flag or DW_FORM_flag_present attributes. */
20916 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
20918 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
20920 return attr
!= nullptr && attr
->as_boolean ();
20924 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
20926 /* A DIE is a declaration if it has a DW_AT_declaration attribute
20927 which value is non-zero. However, we have to be careful with
20928 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
20929 (via dwarf2_flag_true_p) follows this attribute. So we may
20930 end up accidently finding a declaration attribute that belongs
20931 to a different DIE referenced by the specification attribute,
20932 even though the given DIE does not have a declaration attribute. */
20933 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
20934 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
20937 /* Return the die giving the specification for DIE, if there is
20938 one. *SPEC_CU is the CU containing DIE on input, and the CU
20939 containing the return value on output. If there is no
20940 specification, but there is an abstract origin, that is
20943 static struct die_info
*
20944 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
20946 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
20949 if (spec_attr
== NULL
)
20950 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
20952 if (spec_attr
== NULL
)
20955 return follow_die_ref (die
, spec_attr
, spec_cu
);
20958 /* Stub for free_line_header to match void * callback types. */
20961 free_line_header_voidp (void *arg
)
20963 struct line_header
*lh
= (struct line_header
*) arg
;
20968 /* A convenience function to find the proper .debug_line section for a CU. */
20970 static struct dwarf2_section_info
*
20971 get_debug_line_section (struct dwarf2_cu
*cu
)
20973 struct dwarf2_section_info
*section
;
20974 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20976 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
20978 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20979 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
20980 else if (cu
->per_cu
->is_dwz
)
20982 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
20984 section
= &dwz
->line
;
20987 section
= &per_objfile
->per_bfd
->line
;
20992 /* Read the statement program header starting at OFFSET in
20993 .debug_line, or .debug_line.dwo. Return a pointer
20994 to a struct line_header, allocated using xmalloc.
20995 Returns NULL if there is a problem reading the header, e.g., if it
20996 has a version we don't understand.
20998 NOTE: the strings in the include directory and file name tables of
20999 the returned object point into the dwarf line section buffer,
21000 and must not be freed. */
21002 static line_header_up
21003 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
21005 struct dwarf2_section_info
*section
;
21006 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21008 section
= get_debug_line_section (cu
);
21009 section
->read (per_objfile
->objfile
);
21010 if (section
->buffer
== NULL
)
21012 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
21013 complaint (_("missing .debug_line.dwo section"));
21015 complaint (_("missing .debug_line section"));
21019 return dwarf_decode_line_header (sect_off
, cu
->per_cu
->is_dwz
,
21020 per_objfile
, section
, &cu
->header
);
21023 /* Subroutine of dwarf_decode_lines to simplify it.
21024 Return the file name of the psymtab for the given file_entry.
21025 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
21026 If space for the result is malloc'd, *NAME_HOLDER will be set.
21027 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
21029 static const char *
21030 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
21031 const dwarf2_psymtab
*pst
,
21032 const char *comp_dir
,
21033 gdb::unique_xmalloc_ptr
<char> *name_holder
)
21035 const char *include_name
= fe
.name
;
21036 const char *include_name_to_compare
= include_name
;
21037 const char *pst_filename
;
21040 const char *dir_name
= fe
.include_dir (lh
);
21042 gdb::unique_xmalloc_ptr
<char> hold_compare
;
21043 if (!IS_ABSOLUTE_PATH (include_name
)
21044 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
21046 /* Avoid creating a duplicate psymtab for PST.
21047 We do this by comparing INCLUDE_NAME and PST_FILENAME.
21048 Before we do the comparison, however, we need to account
21049 for DIR_NAME and COMP_DIR.
21050 First prepend dir_name (if non-NULL). If we still don't
21051 have an absolute path prepend comp_dir (if non-NULL).
21052 However, the directory we record in the include-file's
21053 psymtab does not contain COMP_DIR (to match the
21054 corresponding symtab(s)).
21059 bash$ gcc -g ./hello.c
21060 include_name = "hello.c"
21062 DW_AT_comp_dir = comp_dir = "/tmp"
21063 DW_AT_name = "./hello.c"
21067 if (dir_name
!= NULL
)
21069 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
21070 include_name
, (char *) NULL
));
21071 include_name
= name_holder
->get ();
21072 include_name_to_compare
= include_name
;
21074 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
21076 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
21077 include_name
, (char *) NULL
));
21078 include_name_to_compare
= hold_compare
.get ();
21082 pst_filename
= pst
->filename
;
21083 gdb::unique_xmalloc_ptr
<char> copied_name
;
21084 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
21086 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
21087 pst_filename
, (char *) NULL
));
21088 pst_filename
= copied_name
.get ();
21091 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
21095 return include_name
;
21098 /* State machine to track the state of the line number program. */
21100 class lnp_state_machine
21103 /* Initialize a machine state for the start of a line number
21105 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
21106 bool record_lines_p
);
21108 file_entry
*current_file ()
21110 /* lh->file_names is 0-based, but the file name numbers in the
21111 statement program are 1-based. */
21112 return m_line_header
->file_name_at (m_file
);
21115 /* Record the line in the state machine. END_SEQUENCE is true if
21116 we're processing the end of a sequence. */
21117 void record_line (bool end_sequence
);
21119 /* Check ADDRESS is -1, or zero and less than UNRELOCATED_LOWPC, and if true
21120 nop-out rest of the lines in this sequence. */
21121 void check_line_address (struct dwarf2_cu
*cu
,
21122 const gdb_byte
*line_ptr
,
21123 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
21125 void handle_set_discriminator (unsigned int discriminator
)
21127 m_discriminator
= discriminator
;
21128 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
21131 /* Handle DW_LNE_set_address. */
21132 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
21135 address
+= baseaddr
;
21136 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
21139 /* Handle DW_LNS_advance_pc. */
21140 void handle_advance_pc (CORE_ADDR adjust
);
21142 /* Handle a special opcode. */
21143 void handle_special_opcode (unsigned char op_code
);
21145 /* Handle DW_LNS_advance_line. */
21146 void handle_advance_line (int line_delta
)
21148 advance_line (line_delta
);
21151 /* Handle DW_LNS_set_file. */
21152 void handle_set_file (file_name_index file
);
21154 /* Handle DW_LNS_negate_stmt. */
21155 void handle_negate_stmt ()
21157 m_is_stmt
= !m_is_stmt
;
21160 /* Handle DW_LNS_const_add_pc. */
21161 void handle_const_add_pc ();
21163 /* Handle DW_LNS_fixed_advance_pc. */
21164 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
21166 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21170 /* Handle DW_LNS_copy. */
21171 void handle_copy ()
21173 record_line (false);
21174 m_discriminator
= 0;
21177 /* Handle DW_LNE_end_sequence. */
21178 void handle_end_sequence ()
21180 m_currently_recording_lines
= true;
21184 /* Advance the line by LINE_DELTA. */
21185 void advance_line (int line_delta
)
21187 m_line
+= line_delta
;
21189 if (line_delta
!= 0)
21190 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
21193 struct dwarf2_cu
*m_cu
;
21195 gdbarch
*m_gdbarch
;
21197 /* True if we're recording lines.
21198 Otherwise we're building partial symtabs and are just interested in
21199 finding include files mentioned by the line number program. */
21200 bool m_record_lines_p
;
21202 /* The line number header. */
21203 line_header
*m_line_header
;
21205 /* These are part of the standard DWARF line number state machine,
21206 and initialized according to the DWARF spec. */
21208 unsigned char m_op_index
= 0;
21209 /* The line table index of the current file. */
21210 file_name_index m_file
= 1;
21211 unsigned int m_line
= 1;
21213 /* These are initialized in the constructor. */
21215 CORE_ADDR m_address
;
21217 unsigned int m_discriminator
;
21219 /* Additional bits of state we need to track. */
21221 /* The last file that we called dwarf2_start_subfile for.
21222 This is only used for TLLs. */
21223 unsigned int m_last_file
= 0;
21224 /* The last file a line number was recorded for. */
21225 struct subfile
*m_last_subfile
= NULL
;
21227 /* The address of the last line entry. */
21228 CORE_ADDR m_last_address
;
21230 /* Set to true when a previous line at the same address (using
21231 m_last_address) had m_is_stmt true. This is reset to false when a
21232 line entry at a new address (m_address different to m_last_address) is
21234 bool m_stmt_at_address
= false;
21236 /* When true, record the lines we decode. */
21237 bool m_currently_recording_lines
= false;
21239 /* The last line number that was recorded, used to coalesce
21240 consecutive entries for the same line. This can happen, for
21241 example, when discriminators are present. PR 17276. */
21242 unsigned int m_last_line
= 0;
21243 bool m_line_has_non_zero_discriminator
= false;
21247 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
21249 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
21250 / m_line_header
->maximum_ops_per_instruction
)
21251 * m_line_header
->minimum_instruction_length
);
21252 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21253 m_op_index
= ((m_op_index
+ adjust
)
21254 % m_line_header
->maximum_ops_per_instruction
);
21258 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
21260 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
21261 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
21262 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
21263 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
21264 / m_line_header
->maximum_ops_per_instruction
)
21265 * m_line_header
->minimum_instruction_length
);
21266 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21267 m_op_index
= ((m_op_index
+ adj_opcode_d
)
21268 % m_line_header
->maximum_ops_per_instruction
);
21270 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
21271 advance_line (line_delta
);
21272 record_line (false);
21273 m_discriminator
= 0;
21277 lnp_state_machine::handle_set_file (file_name_index file
)
21281 const file_entry
*fe
= current_file ();
21283 dwarf2_debug_line_missing_file_complaint ();
21284 else if (m_record_lines_p
)
21286 const char *dir
= fe
->include_dir (m_line_header
);
21288 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21289 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
21290 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
21295 lnp_state_machine::handle_const_add_pc ()
21298 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
21301 = (((m_op_index
+ adjust
)
21302 / m_line_header
->maximum_ops_per_instruction
)
21303 * m_line_header
->minimum_instruction_length
);
21305 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21306 m_op_index
= ((m_op_index
+ adjust
)
21307 % m_line_header
->maximum_ops_per_instruction
);
21310 /* Return non-zero if we should add LINE to the line number table.
21311 LINE is the line to add, LAST_LINE is the last line that was added,
21312 LAST_SUBFILE is the subfile for LAST_LINE.
21313 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
21314 had a non-zero discriminator.
21316 We have to be careful in the presence of discriminators.
21317 E.g., for this line:
21319 for (i = 0; i < 100000; i++);
21321 clang can emit four line number entries for that one line,
21322 each with a different discriminator.
21323 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
21325 However, we want gdb to coalesce all four entries into one.
21326 Otherwise the user could stepi into the middle of the line and
21327 gdb would get confused about whether the pc really was in the
21328 middle of the line.
21330 Things are further complicated by the fact that two consecutive
21331 line number entries for the same line is a heuristic used by gcc
21332 to denote the end of the prologue. So we can't just discard duplicate
21333 entries, we have to be selective about it. The heuristic we use is
21334 that we only collapse consecutive entries for the same line if at least
21335 one of those entries has a non-zero discriminator. PR 17276.
21337 Note: Addresses in the line number state machine can never go backwards
21338 within one sequence, thus this coalescing is ok. */
21341 dwarf_record_line_p (struct dwarf2_cu
*cu
,
21342 unsigned int line
, unsigned int last_line
,
21343 int line_has_non_zero_discriminator
,
21344 struct subfile
*last_subfile
)
21346 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
21348 if (line
!= last_line
)
21350 /* Same line for the same file that we've seen already.
21351 As a last check, for pr 17276, only record the line if the line
21352 has never had a non-zero discriminator. */
21353 if (!line_has_non_zero_discriminator
)
21358 /* Use the CU's builder to record line number LINE beginning at
21359 address ADDRESS in the line table of subfile SUBFILE. */
21362 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21363 unsigned int line
, CORE_ADDR address
, bool is_stmt
,
21364 struct dwarf2_cu
*cu
)
21366 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
21368 if (dwarf_line_debug
)
21370 fprintf_unfiltered (gdb_stdlog
,
21371 "Recording line %u, file %s, address %s\n",
21372 line
, lbasename (subfile
->name
),
21373 paddress (gdbarch
, address
));
21377 cu
->get_builder ()->record_line (subfile
, line
, addr
, is_stmt
);
21380 /* Subroutine of dwarf_decode_lines_1 to simplify it.
21381 Mark the end of a set of line number records.
21382 The arguments are the same as for dwarf_record_line_1.
21383 If SUBFILE is NULL the request is ignored. */
21386 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21387 CORE_ADDR address
, struct dwarf2_cu
*cu
)
21389 if (subfile
== NULL
)
21392 if (dwarf_line_debug
)
21394 fprintf_unfiltered (gdb_stdlog
,
21395 "Finishing current line, file %s, address %s\n",
21396 lbasename (subfile
->name
),
21397 paddress (gdbarch
, address
));
21400 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, true, cu
);
21404 lnp_state_machine::record_line (bool end_sequence
)
21406 if (dwarf_line_debug
)
21408 fprintf_unfiltered (gdb_stdlog
,
21409 "Processing actual line %u: file %u,"
21410 " address %s, is_stmt %u, discrim %u%s\n",
21412 paddress (m_gdbarch
, m_address
),
21413 m_is_stmt
, m_discriminator
,
21414 (end_sequence
? "\t(end sequence)" : ""));
21417 file_entry
*fe
= current_file ();
21420 dwarf2_debug_line_missing_file_complaint ();
21421 /* For now we ignore lines not starting on an instruction boundary.
21422 But not when processing end_sequence for compatibility with the
21423 previous version of the code. */
21424 else if (m_op_index
== 0 || end_sequence
)
21426 fe
->included_p
= 1;
21427 if (m_record_lines_p
)
21429 /* When we switch files we insert an end maker in the first file,
21430 switch to the second file and add a new line entry. The
21431 problem is that the end marker inserted in the first file will
21432 discard any previous line entries at the same address. If the
21433 line entries in the first file are marked as is-stmt, while
21434 the new line in the second file is non-stmt, then this means
21435 the end marker will discard is-stmt lines so we can have a
21436 non-stmt line. This means that there are less addresses at
21437 which the user can insert a breakpoint.
21439 To improve this we track the last address in m_last_address,
21440 and whether we have seen an is-stmt at this address. Then
21441 when switching files, if we have seen a stmt at the current
21442 address, and we are switching to create a non-stmt line, then
21443 discard the new line. */
21445 = m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ();
21446 bool ignore_this_line
21447 = ((file_changed
&& !end_sequence
&& m_last_address
== m_address
21448 && !m_is_stmt
&& m_stmt_at_address
)
21449 || (!end_sequence
&& m_line
== 0));
21451 if ((file_changed
&& !ignore_this_line
) || end_sequence
)
21453 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
21454 m_currently_recording_lines
? m_cu
: nullptr);
21457 if (!end_sequence
&& !ignore_this_line
)
21459 bool is_stmt
= producer_is_codewarrior (m_cu
) || m_is_stmt
;
21461 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
21462 m_line_has_non_zero_discriminator
,
21465 buildsym_compunit
*builder
= m_cu
->get_builder ();
21466 dwarf_record_line_1 (m_gdbarch
,
21467 builder
->get_current_subfile (),
21468 m_line
, m_address
, is_stmt
,
21469 m_currently_recording_lines
? m_cu
: nullptr);
21471 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21472 m_last_line
= m_line
;
21477 /* Track whether we have seen any m_is_stmt true at m_address in case we
21478 have multiple line table entries all at m_address. */
21479 if (m_last_address
!= m_address
)
21481 m_stmt_at_address
= false;
21482 m_last_address
= m_address
;
21484 m_stmt_at_address
|= m_is_stmt
;
21487 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
21488 line_header
*lh
, bool record_lines_p
)
21492 m_record_lines_p
= record_lines_p
;
21493 m_line_header
= lh
;
21495 m_currently_recording_lines
= true;
21497 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
21498 was a line entry for it so that the backend has a chance to adjust it
21499 and also record it in case it needs it. This is currently used by MIPS
21500 code, cf. `mips_adjust_dwarf2_line'. */
21501 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
21502 m_is_stmt
= lh
->default_is_stmt
;
21503 m_discriminator
= 0;
21505 m_last_address
= m_address
;
21506 m_stmt_at_address
= false;
21510 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
21511 const gdb_byte
*line_ptr
,
21512 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
21514 /* Linkers resolve a symbolic relocation referencing a GC'd function to 0 or
21515 -1. If ADDRESS is 0, ignoring the opcode will err if the text section is
21516 located at 0x0. In this case, additionally check that if
21517 ADDRESS < UNRELOCATED_LOWPC. */
21519 if ((address
== 0 && address
< unrelocated_lowpc
)
21520 || address
== (CORE_ADDR
) -1)
21522 /* This line table is for a function which has been
21523 GCd by the linker. Ignore it. PR gdb/12528 */
21525 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21526 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
21528 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
21529 line_offset
, objfile_name (objfile
));
21530 m_currently_recording_lines
= false;
21531 /* Note: m_currently_recording_lines is left as false until we see
21532 DW_LNE_end_sequence. */
21536 /* Subroutine of dwarf_decode_lines to simplify it.
21537 Process the line number information in LH.
21538 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
21539 program in order to set included_p for every referenced header. */
21542 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
21543 const int decode_for_pst_p
, CORE_ADDR lowpc
)
21545 const gdb_byte
*line_ptr
, *extended_end
;
21546 const gdb_byte
*line_end
;
21547 unsigned int bytes_read
, extended_len
;
21548 unsigned char op_code
, extended_op
;
21549 CORE_ADDR baseaddr
;
21550 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21551 bfd
*abfd
= objfile
->obfd
;
21552 struct gdbarch
*gdbarch
= objfile
->arch ();
21553 /* True if we're recording line info (as opposed to building partial
21554 symtabs and just interested in finding include files mentioned by
21555 the line number program). */
21556 bool record_lines_p
= !decode_for_pst_p
;
21558 baseaddr
= objfile
->text_section_offset ();
21560 line_ptr
= lh
->statement_program_start
;
21561 line_end
= lh
->statement_program_end
;
21563 /* Read the statement sequences until there's nothing left. */
21564 while (line_ptr
< line_end
)
21566 /* The DWARF line number program state machine. Reset the state
21567 machine at the start of each sequence. */
21568 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
21569 bool end_sequence
= false;
21571 if (record_lines_p
)
21573 /* Start a subfile for the current file of the state
21575 const file_entry
*fe
= state_machine
.current_file ();
21578 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
21581 /* Decode the table. */
21582 while (line_ptr
< line_end
&& !end_sequence
)
21584 op_code
= read_1_byte (abfd
, line_ptr
);
21587 if (op_code
>= lh
->opcode_base
)
21589 /* Special opcode. */
21590 state_machine
.handle_special_opcode (op_code
);
21592 else switch (op_code
)
21594 case DW_LNS_extended_op
:
21595 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
21597 line_ptr
+= bytes_read
;
21598 extended_end
= line_ptr
+ extended_len
;
21599 extended_op
= read_1_byte (abfd
, line_ptr
);
21601 if (DW_LNE_lo_user
<= extended_op
21602 && extended_op
<= DW_LNE_hi_user
)
21604 /* Vendor extension, ignore. */
21605 line_ptr
= extended_end
;
21608 switch (extended_op
)
21610 case DW_LNE_end_sequence
:
21611 state_machine
.handle_end_sequence ();
21612 end_sequence
= true;
21614 case DW_LNE_set_address
:
21617 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
21618 line_ptr
+= bytes_read
;
21620 state_machine
.check_line_address (cu
, line_ptr
,
21621 lowpc
- baseaddr
, address
);
21622 state_machine
.handle_set_address (baseaddr
, address
);
21625 case DW_LNE_define_file
:
21627 const char *cur_file
;
21628 unsigned int mod_time
, length
;
21631 cur_file
= read_direct_string (abfd
, line_ptr
,
21633 line_ptr
+= bytes_read
;
21634 dindex
= (dir_index
)
21635 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21636 line_ptr
+= bytes_read
;
21638 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21639 line_ptr
+= bytes_read
;
21641 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21642 line_ptr
+= bytes_read
;
21643 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
21646 case DW_LNE_set_discriminator
:
21648 /* The discriminator is not interesting to the
21649 debugger; just ignore it. We still need to
21650 check its value though:
21651 if there are consecutive entries for the same
21652 (non-prologue) line we want to coalesce them.
21655 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21656 line_ptr
+= bytes_read
;
21658 state_machine
.handle_set_discriminator (discr
);
21662 complaint (_("mangled .debug_line section"));
21665 /* Make sure that we parsed the extended op correctly. If e.g.
21666 we expected a different address size than the producer used,
21667 we may have read the wrong number of bytes. */
21668 if (line_ptr
!= extended_end
)
21670 complaint (_("mangled .debug_line section"));
21675 state_machine
.handle_copy ();
21677 case DW_LNS_advance_pc
:
21680 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21681 line_ptr
+= bytes_read
;
21683 state_machine
.handle_advance_pc (adjust
);
21686 case DW_LNS_advance_line
:
21689 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
21690 line_ptr
+= bytes_read
;
21692 state_machine
.handle_advance_line (line_delta
);
21695 case DW_LNS_set_file
:
21697 file_name_index file
21698 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
21700 line_ptr
+= bytes_read
;
21702 state_machine
.handle_set_file (file
);
21705 case DW_LNS_set_column
:
21706 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21707 line_ptr
+= bytes_read
;
21709 case DW_LNS_negate_stmt
:
21710 state_machine
.handle_negate_stmt ();
21712 case DW_LNS_set_basic_block
:
21714 /* Add to the address register of the state machine the
21715 address increment value corresponding to special opcode
21716 255. I.e., this value is scaled by the minimum
21717 instruction length since special opcode 255 would have
21718 scaled the increment. */
21719 case DW_LNS_const_add_pc
:
21720 state_machine
.handle_const_add_pc ();
21722 case DW_LNS_fixed_advance_pc
:
21724 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
21727 state_machine
.handle_fixed_advance_pc (addr_adj
);
21732 /* Unknown standard opcode, ignore it. */
21735 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
21737 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21738 line_ptr
+= bytes_read
;
21745 dwarf2_debug_line_missing_end_sequence_complaint ();
21747 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
21748 in which case we still finish recording the last line). */
21749 state_machine
.record_line (true);
21753 /* Decode the Line Number Program (LNP) for the given line_header
21754 structure and CU. The actual information extracted and the type
21755 of structures created from the LNP depends on the value of PST.
21757 1. If PST is NULL, then this procedure uses the data from the program
21758 to create all necessary symbol tables, and their linetables.
21760 2. If PST is not NULL, this procedure reads the program to determine
21761 the list of files included by the unit represented by PST, and
21762 builds all the associated partial symbol tables.
21764 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
21765 It is used for relative paths in the line table.
21766 NOTE: When processing partial symtabs (pst != NULL),
21767 comp_dir == pst->dirname.
21769 NOTE: It is important that psymtabs have the same file name (via strcmp)
21770 as the corresponding symtab. Since COMP_DIR is not used in the name of the
21771 symtab we don't use it in the name of the psymtabs we create.
21772 E.g. expand_line_sal requires this when finding psymtabs to expand.
21773 A good testcase for this is mb-inline.exp.
21775 LOWPC is the lowest address in CU (or 0 if not known).
21777 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
21778 for its PC<->lines mapping information. Otherwise only the filename
21779 table is read in. */
21782 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
21783 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
21784 CORE_ADDR lowpc
, int decode_mapping
)
21786 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21787 const int decode_for_pst_p
= (pst
!= NULL
);
21789 if (decode_mapping
)
21790 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
21792 if (decode_for_pst_p
)
21794 /* Now that we're done scanning the Line Header Program, we can
21795 create the psymtab of each included file. */
21796 for (auto &file_entry
: lh
->file_names ())
21797 if (file_entry
.included_p
== 1)
21799 gdb::unique_xmalloc_ptr
<char> name_holder
;
21800 const char *include_name
=
21801 psymtab_include_file_name (lh
, file_entry
, pst
,
21802 comp_dir
, &name_holder
);
21803 if (include_name
!= NULL
)
21804 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
21809 /* Make sure a symtab is created for every file, even files
21810 which contain only variables (i.e. no code with associated
21812 buildsym_compunit
*builder
= cu
->get_builder ();
21813 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
21815 for (auto &fe
: lh
->file_names ())
21817 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
21818 if (builder
->get_current_subfile ()->symtab
== NULL
)
21820 builder
->get_current_subfile ()->symtab
21821 = allocate_symtab (cust
,
21822 builder
->get_current_subfile ()->name
);
21824 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
21829 /* Start a subfile for DWARF. FILENAME is the name of the file and
21830 DIRNAME the name of the source directory which contains FILENAME
21831 or NULL if not known.
21832 This routine tries to keep line numbers from identical absolute and
21833 relative file names in a common subfile.
21835 Using the `list' example from the GDB testsuite, which resides in
21836 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
21837 of /srcdir/list0.c yields the following debugging information for list0.c:
21839 DW_AT_name: /srcdir/list0.c
21840 DW_AT_comp_dir: /compdir
21841 files.files[0].name: list0.h
21842 files.files[0].dir: /srcdir
21843 files.files[1].name: list0.c
21844 files.files[1].dir: /srcdir
21846 The line number information for list0.c has to end up in a single
21847 subfile, so that `break /srcdir/list0.c:1' works as expected.
21848 start_subfile will ensure that this happens provided that we pass the
21849 concatenation of files.files[1].dir and files.files[1].name as the
21853 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
21854 const char *dirname
)
21856 gdb::unique_xmalloc_ptr
<char> copy
;
21858 /* In order not to lose the line information directory,
21859 we concatenate it to the filename when it makes sense.
21860 Note that the Dwarf3 standard says (speaking of filenames in line
21861 information): ``The directory index is ignored for file names
21862 that represent full path names''. Thus ignoring dirname in the
21863 `else' branch below isn't an issue. */
21865 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
21867 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
21868 filename
= copy
.get ();
21871 cu
->get_builder ()->start_subfile (filename
);
21874 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
21875 buildsym_compunit constructor. */
21877 struct compunit_symtab
*
21878 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
21881 gdb_assert (m_builder
== nullptr);
21883 m_builder
.reset (new struct buildsym_compunit
21884 (this->per_objfile
->objfile
,
21885 name
, comp_dir
, language
, low_pc
));
21887 list_in_scope
= get_builder ()->get_file_symbols ();
21889 get_builder ()->record_debugformat ("DWARF 2");
21890 get_builder ()->record_producer (producer
);
21892 processing_has_namespace_info
= false;
21894 return get_builder ()->get_compunit_symtab ();
21898 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
21899 struct dwarf2_cu
*cu
)
21901 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21902 struct comp_unit_head
*cu_header
= &cu
->header
;
21904 /* NOTE drow/2003-01-30: There used to be a comment and some special
21905 code here to turn a symbol with DW_AT_external and a
21906 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
21907 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
21908 with some versions of binutils) where shared libraries could have
21909 relocations against symbols in their debug information - the
21910 minimal symbol would have the right address, but the debug info
21911 would not. It's no longer necessary, because we will explicitly
21912 apply relocations when we read in the debug information now. */
21914 /* A DW_AT_location attribute with no contents indicates that a
21915 variable has been optimized away. */
21916 if (attr
->form_is_block () && attr
->as_block ()->size
== 0)
21918 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21922 /* Handle one degenerate form of location expression specially, to
21923 preserve GDB's previous behavior when section offsets are
21924 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
21925 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
21927 if (attr
->form_is_block ())
21929 struct dwarf_block
*block
= attr
->as_block ();
21931 if ((block
->data
[0] == DW_OP_addr
21932 && block
->size
== 1 + cu_header
->addr_size
)
21933 || ((block
->data
[0] == DW_OP_GNU_addr_index
21934 || block
->data
[0] == DW_OP_addrx
)
21936 == 1 + leb128_size (&block
->data
[1]))))
21938 unsigned int dummy
;
21940 if (block
->data
[0] == DW_OP_addr
)
21941 SET_SYMBOL_VALUE_ADDRESS
21942 (sym
, cu
->header
.read_address (objfile
->obfd
,
21946 SET_SYMBOL_VALUE_ADDRESS
21947 (sym
, read_addr_index_from_leb128 (cu
, block
->data
+ 1,
21949 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
21950 fixup_symbol_section (sym
, objfile
);
21951 SET_SYMBOL_VALUE_ADDRESS
21953 SYMBOL_VALUE_ADDRESS (sym
)
21954 + objfile
->section_offsets
[SYMBOL_SECTION (sym
)]);
21959 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
21960 expression evaluator, and use LOC_COMPUTED only when necessary
21961 (i.e. when the value of a register or memory location is
21962 referenced, or a thread-local block, etc.). Then again, it might
21963 not be worthwhile. I'm assuming that it isn't unless performance
21964 or memory numbers show me otherwise. */
21966 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
21968 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
21969 cu
->has_loclist
= true;
21972 /* Given a pointer to a DWARF information entry, figure out if we need
21973 to make a symbol table entry for it, and if so, create a new entry
21974 and return a pointer to it.
21975 If TYPE is NULL, determine symbol type from the die, otherwise
21976 used the passed type.
21977 If SPACE is not NULL, use it to hold the new symbol. If it is
21978 NULL, allocate a new symbol on the objfile's obstack. */
21980 static struct symbol
*
21981 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
21982 struct symbol
*space
)
21984 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21985 struct objfile
*objfile
= per_objfile
->objfile
;
21986 struct gdbarch
*gdbarch
= objfile
->arch ();
21987 struct symbol
*sym
= NULL
;
21989 struct attribute
*attr
= NULL
;
21990 struct attribute
*attr2
= NULL
;
21991 CORE_ADDR baseaddr
;
21992 struct pending
**list_to_add
= NULL
;
21994 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
21996 baseaddr
= objfile
->text_section_offset ();
21998 name
= dwarf2_name (die
, cu
);
22001 int suppress_add
= 0;
22006 sym
= new (&objfile
->objfile_obstack
) symbol
;
22007 OBJSTAT (objfile
, n_syms
++);
22009 /* Cache this symbol's name and the name's demangled form (if any). */
22010 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
22011 /* Fortran does not have mangling standard and the mangling does differ
22012 between gfortran, iFort etc. */
22013 const char *physname
22014 = (cu
->language
== language_fortran
22015 ? dwarf2_full_name (name
, die
, cu
)
22016 : dwarf2_physname (name
, die
, cu
));
22017 const char *linkagename
= dw2_linkage_name (die
, cu
);
22019 if (linkagename
== nullptr || cu
->language
== language_ada
)
22020 sym
->set_linkage_name (physname
);
22023 sym
->set_demangled_name (physname
, &objfile
->objfile_obstack
);
22024 sym
->set_linkage_name (linkagename
);
22027 /* Default assumptions.
22028 Use the passed type or decode it from the die. */
22029 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
22030 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
22032 SYMBOL_TYPE (sym
) = type
;
22034 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
22035 attr
= dwarf2_attr (die
,
22036 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
22038 if (attr
!= nullptr)
22039 SYMBOL_LINE (sym
) = attr
->constant_value (0);
22041 attr
= dwarf2_attr (die
,
22042 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
22044 if (attr
!= nullptr && attr
->form_is_unsigned ())
22046 file_name_index file_index
22047 = (file_name_index
) attr
->as_unsigned ();
22048 struct file_entry
*fe
;
22050 if (cu
->line_header
!= NULL
)
22051 fe
= cu
->line_header
->file_name_at (file_index
);
22056 complaint (_("file index out of range"));
22058 symbol_set_symtab (sym
, fe
->symtab
);
22064 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
22065 if (attr
!= nullptr)
22069 addr
= attr
->as_address ();
22070 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
22071 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
22072 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
22075 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
22076 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
22077 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
22078 add_symbol_to_list (sym
, cu
->list_in_scope
);
22080 case DW_TAG_subprogram
:
22081 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
22083 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
22084 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
22085 if ((attr2
!= nullptr && attr2
->as_boolean ())
22086 || cu
->language
== language_ada
22087 || cu
->language
== language_fortran
)
22089 /* Subprograms marked external are stored as a global symbol.
22090 Ada and Fortran subprograms, whether marked external or
22091 not, are always stored as a global symbol, because we want
22092 to be able to access them globally. For instance, we want
22093 to be able to break on a nested subprogram without having
22094 to specify the context. */
22095 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22099 list_to_add
= cu
->list_in_scope
;
22102 case DW_TAG_inlined_subroutine
:
22103 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
22105 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
22106 SYMBOL_INLINED (sym
) = 1;
22107 list_to_add
= cu
->list_in_scope
;
22109 case DW_TAG_template_value_param
:
22111 /* Fall through. */
22112 case DW_TAG_constant
:
22113 case DW_TAG_variable
:
22114 case DW_TAG_member
:
22115 /* Compilation with minimal debug info may result in
22116 variables with missing type entries. Change the
22117 misleading `void' type to something sensible. */
22118 if (SYMBOL_TYPE (sym
)->code () == TYPE_CODE_VOID
)
22119 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
22121 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22122 /* In the case of DW_TAG_member, we should only be called for
22123 static const members. */
22124 if (die
->tag
== DW_TAG_member
)
22126 /* dwarf2_add_field uses die_is_declaration,
22127 so we do the same. */
22128 gdb_assert (die_is_declaration (die
, cu
));
22131 if (attr
!= nullptr)
22133 dwarf2_const_value (attr
, sym
, cu
);
22134 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
22137 if (attr2
!= nullptr && attr2
->as_boolean ())
22138 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22140 list_to_add
= cu
->list_in_scope
;
22144 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22145 if (attr
!= nullptr)
22147 var_decode_location (attr
, sym
, cu
);
22148 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
22150 /* Fortran explicitly imports any global symbols to the local
22151 scope by DW_TAG_common_block. */
22152 if (cu
->language
== language_fortran
&& die
->parent
22153 && die
->parent
->tag
== DW_TAG_common_block
)
22156 if (SYMBOL_CLASS (sym
) == LOC_STATIC
22157 && SYMBOL_VALUE_ADDRESS (sym
) == 0
22158 && !per_objfile
->per_bfd
->has_section_at_zero
)
22160 /* When a static variable is eliminated by the linker,
22161 the corresponding debug information is not stripped
22162 out, but the variable address is set to null;
22163 do not add such variables into symbol table. */
22165 else if (attr2
!= nullptr && attr2
->as_boolean ())
22167 if (SYMBOL_CLASS (sym
) == LOC_STATIC
22168 && (objfile
->flags
& OBJF_MAINLINE
) == 0
22169 && per_objfile
->per_bfd
->can_copy
)
22171 /* A global static variable might be subject to
22172 copy relocation. We first check for a local
22173 minsym, though, because maybe the symbol was
22174 marked hidden, in which case this would not
22176 bound_minimal_symbol found
22177 = (lookup_minimal_symbol_linkage
22178 (sym
->linkage_name (), objfile
));
22179 if (found
.minsym
!= nullptr)
22180 sym
->maybe_copied
= 1;
22183 /* A variable with DW_AT_external is never static,
22184 but it may be block-scoped. */
22186 = ((cu
->list_in_scope
22187 == cu
->get_builder ()->get_file_symbols ())
22188 ? cu
->get_builder ()->get_global_symbols ()
22189 : cu
->list_in_scope
);
22192 list_to_add
= cu
->list_in_scope
;
22196 /* We do not know the address of this symbol.
22197 If it is an external symbol and we have type information
22198 for it, enter the symbol as a LOC_UNRESOLVED symbol.
22199 The address of the variable will then be determined from
22200 the minimal symbol table whenever the variable is
22202 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
22204 /* Fortran explicitly imports any global symbols to the local
22205 scope by DW_TAG_common_block. */
22206 if (cu
->language
== language_fortran
&& die
->parent
22207 && die
->parent
->tag
== DW_TAG_common_block
)
22209 /* SYMBOL_CLASS doesn't matter here because
22210 read_common_block is going to reset it. */
22212 list_to_add
= cu
->list_in_scope
;
22214 else if (attr2
!= nullptr && attr2
->as_boolean ()
22215 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
22217 /* A variable with DW_AT_external is never static, but it
22218 may be block-scoped. */
22220 = ((cu
->list_in_scope
22221 == cu
->get_builder ()->get_file_symbols ())
22222 ? cu
->get_builder ()->get_global_symbols ()
22223 : cu
->list_in_scope
);
22225 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
22227 else if (!die_is_declaration (die
, cu
))
22229 /* Use the default LOC_OPTIMIZED_OUT class. */
22230 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
22232 list_to_add
= cu
->list_in_scope
;
22236 case DW_TAG_formal_parameter
:
22238 /* If we are inside a function, mark this as an argument. If
22239 not, we might be looking at an argument to an inlined function
22240 when we do not have enough information to show inlined frames;
22241 pretend it's a local variable in that case so that the user can
22243 struct context_stack
*curr
22244 = cu
->get_builder ()->get_current_context_stack ();
22245 if (curr
!= nullptr && curr
->name
!= nullptr)
22246 SYMBOL_IS_ARGUMENT (sym
) = 1;
22247 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22248 if (attr
!= nullptr)
22250 var_decode_location (attr
, sym
, cu
);
22252 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22253 if (attr
!= nullptr)
22255 dwarf2_const_value (attr
, sym
, cu
);
22258 list_to_add
= cu
->list_in_scope
;
22261 case DW_TAG_unspecified_parameters
:
22262 /* From varargs functions; gdb doesn't seem to have any
22263 interest in this information, so just ignore it for now.
22266 case DW_TAG_template_type_param
:
22268 /* Fall through. */
22269 case DW_TAG_class_type
:
22270 case DW_TAG_interface_type
:
22271 case DW_TAG_structure_type
:
22272 case DW_TAG_union_type
:
22273 case DW_TAG_set_type
:
22274 case DW_TAG_enumeration_type
:
22275 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22276 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
22279 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
22280 really ever be static objects: otherwise, if you try
22281 to, say, break of a class's method and you're in a file
22282 which doesn't mention that class, it won't work unless
22283 the check for all static symbols in lookup_symbol_aux
22284 saves you. See the OtherFileClass tests in
22285 gdb.c++/namespace.exp. */
22289 buildsym_compunit
*builder
= cu
->get_builder ();
22291 = (cu
->list_in_scope
== builder
->get_file_symbols ()
22292 && cu
->language
== language_cplus
22293 ? builder
->get_global_symbols ()
22294 : cu
->list_in_scope
);
22296 /* The semantics of C++ state that "struct foo {
22297 ... }" also defines a typedef for "foo". */
22298 if (cu
->language
== language_cplus
22299 || cu
->language
== language_ada
22300 || cu
->language
== language_d
22301 || cu
->language
== language_rust
)
22303 /* The symbol's name is already allocated along
22304 with this objfile, so we don't need to
22305 duplicate it for the type. */
22306 if (SYMBOL_TYPE (sym
)->name () == 0)
22307 SYMBOL_TYPE (sym
)->set_name (sym
->search_name ());
22312 case DW_TAG_typedef
:
22313 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22314 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
22315 list_to_add
= cu
->list_in_scope
;
22317 case DW_TAG_array_type
:
22318 case DW_TAG_base_type
:
22319 case DW_TAG_subrange_type
:
22320 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22321 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
22322 list_to_add
= cu
->list_in_scope
;
22324 case DW_TAG_enumerator
:
22325 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22326 if (attr
!= nullptr)
22328 dwarf2_const_value (attr
, sym
, cu
);
22331 /* NOTE: carlton/2003-11-10: See comment above in the
22332 DW_TAG_class_type, etc. block. */
22335 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
22336 && cu
->language
== language_cplus
22337 ? cu
->get_builder ()->get_global_symbols ()
22338 : cu
->list_in_scope
);
22341 case DW_TAG_imported_declaration
:
22342 case DW_TAG_namespace
:
22343 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22344 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22346 case DW_TAG_module
:
22347 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22348 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
22349 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22351 case DW_TAG_common_block
:
22352 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
22353 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
22354 add_symbol_to_list (sym
, cu
->list_in_scope
);
22357 /* Not a tag we recognize. Hopefully we aren't processing
22358 trash data, but since we must specifically ignore things
22359 we don't recognize, there is nothing else we should do at
22361 complaint (_("unsupported tag: '%s'"),
22362 dwarf_tag_name (die
->tag
));
22368 sym
->hash_next
= objfile
->template_symbols
;
22369 objfile
->template_symbols
= sym
;
22370 list_to_add
= NULL
;
22373 if (list_to_add
!= NULL
)
22374 add_symbol_to_list (sym
, list_to_add
);
22376 /* For the benefit of old versions of GCC, check for anonymous
22377 namespaces based on the demangled name. */
22378 if (!cu
->processing_has_namespace_info
22379 && cu
->language
== language_cplus
)
22380 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
22385 /* Given an attr with a DW_FORM_dataN value in host byte order,
22386 zero-extend it as appropriate for the symbol's type. The DWARF
22387 standard (v4) is not entirely clear about the meaning of using
22388 DW_FORM_dataN for a constant with a signed type, where the type is
22389 wider than the data. The conclusion of a discussion on the DWARF
22390 list was that this is unspecified. We choose to always zero-extend
22391 because that is the interpretation long in use by GCC. */
22394 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
22395 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
22397 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22398 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
22399 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
22400 LONGEST l
= attr
->constant_value (0);
22402 if (bits
< sizeof (*value
) * 8)
22404 l
&= ((LONGEST
) 1 << bits
) - 1;
22407 else if (bits
== sizeof (*value
) * 8)
22411 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
22412 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
22419 /* Read a constant value from an attribute. Either set *VALUE, or if
22420 the value does not fit in *VALUE, set *BYTES - either already
22421 allocated on the objfile obstack, or newly allocated on OBSTACK,
22422 or, set *BATON, if we translated the constant to a location
22426 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
22427 const char *name
, struct obstack
*obstack
,
22428 struct dwarf2_cu
*cu
,
22429 LONGEST
*value
, const gdb_byte
**bytes
,
22430 struct dwarf2_locexpr_baton
**baton
)
22432 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22433 struct objfile
*objfile
= per_objfile
->objfile
;
22434 struct comp_unit_head
*cu_header
= &cu
->header
;
22435 struct dwarf_block
*blk
;
22436 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
22437 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22443 switch (attr
->form
)
22446 case DW_FORM_addrx
:
22447 case DW_FORM_GNU_addr_index
:
22451 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
22452 dwarf2_const_value_length_mismatch_complaint (name
,
22453 cu_header
->addr_size
,
22454 TYPE_LENGTH (type
));
22455 /* Symbols of this form are reasonably rare, so we just
22456 piggyback on the existing location code rather than writing
22457 a new implementation of symbol_computed_ops. */
22458 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
22459 (*baton
)->per_objfile
= per_objfile
;
22460 (*baton
)->per_cu
= cu
->per_cu
;
22461 gdb_assert ((*baton
)->per_cu
);
22463 (*baton
)->size
= 2 + cu_header
->addr_size
;
22464 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
22465 (*baton
)->data
= data
;
22467 data
[0] = DW_OP_addr
;
22468 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
22469 byte_order
, attr
->as_address ());
22470 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
22473 case DW_FORM_string
:
22476 case DW_FORM_GNU_str_index
:
22477 case DW_FORM_GNU_strp_alt
:
22478 /* The string is already allocated on the objfile obstack, point
22480 *bytes
= (const gdb_byte
*) attr
->as_string ();
22482 case DW_FORM_block1
:
22483 case DW_FORM_block2
:
22484 case DW_FORM_block4
:
22485 case DW_FORM_block
:
22486 case DW_FORM_exprloc
:
22487 case DW_FORM_data16
:
22488 blk
= attr
->as_block ();
22489 if (TYPE_LENGTH (type
) != blk
->size
)
22490 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
22491 TYPE_LENGTH (type
));
22492 *bytes
= blk
->data
;
22495 /* The DW_AT_const_value attributes are supposed to carry the
22496 symbol's value "represented as it would be on the target
22497 architecture." By the time we get here, it's already been
22498 converted to host endianness, so we just need to sign- or
22499 zero-extend it as appropriate. */
22500 case DW_FORM_data1
:
22501 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
22503 case DW_FORM_data2
:
22504 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
22506 case DW_FORM_data4
:
22507 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
22509 case DW_FORM_data8
:
22510 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
22513 case DW_FORM_sdata
:
22514 case DW_FORM_implicit_const
:
22515 *value
= attr
->as_signed ();
22518 case DW_FORM_udata
:
22519 *value
= attr
->as_unsigned ();
22523 complaint (_("unsupported const value attribute form: '%s'"),
22524 dwarf_form_name (attr
->form
));
22531 /* Copy constant value from an attribute to a symbol. */
22534 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
22535 struct dwarf2_cu
*cu
)
22537 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22539 const gdb_byte
*bytes
;
22540 struct dwarf2_locexpr_baton
*baton
;
22542 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
22543 sym
->print_name (),
22544 &objfile
->objfile_obstack
, cu
,
22545 &value
, &bytes
, &baton
);
22549 SYMBOL_LOCATION_BATON (sym
) = baton
;
22550 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
22552 else if (bytes
!= NULL
)
22554 SYMBOL_VALUE_BYTES (sym
) = bytes
;
22555 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
22559 SYMBOL_VALUE (sym
) = value
;
22560 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
22564 /* Return the type of the die in question using its DW_AT_type attribute. */
22566 static struct type
*
22567 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22569 struct attribute
*type_attr
;
22571 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
22574 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22575 /* A missing DW_AT_type represents a void type. */
22576 return objfile_type (objfile
)->builtin_void
;
22579 return lookup_die_type (die
, type_attr
, cu
);
22582 /* True iff CU's producer generates GNAT Ada auxiliary information
22583 that allows to find parallel types through that information instead
22584 of having to do expensive parallel lookups by type name. */
22587 need_gnat_info (struct dwarf2_cu
*cu
)
22589 /* Assume that the Ada compiler was GNAT, which always produces
22590 the auxiliary information. */
22591 return (cu
->language
== language_ada
);
22594 /* Return the auxiliary type of the die in question using its
22595 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
22596 attribute is not present. */
22598 static struct type
*
22599 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22601 struct attribute
*type_attr
;
22603 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
22607 return lookup_die_type (die
, type_attr
, cu
);
22610 /* If DIE has a descriptive_type attribute, then set the TYPE's
22611 descriptive type accordingly. */
22614 set_descriptive_type (struct type
*type
, struct die_info
*die
,
22615 struct dwarf2_cu
*cu
)
22617 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
22619 if (descriptive_type
)
22621 ALLOCATE_GNAT_AUX_TYPE (type
);
22622 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
22626 /* Return the containing type of the die in question using its
22627 DW_AT_containing_type attribute. */
22629 static struct type
*
22630 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22632 struct attribute
*type_attr
;
22633 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22635 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
22637 error (_("Dwarf Error: Problem turning containing type into gdb type "
22638 "[in module %s]"), objfile_name (objfile
));
22640 return lookup_die_type (die
, type_attr
, cu
);
22643 /* Return an error marker type to use for the ill formed type in DIE/CU. */
22645 static struct type
*
22646 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
22648 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22649 struct objfile
*objfile
= per_objfile
->objfile
;
22652 std::string message
22653 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
22654 objfile_name (objfile
),
22655 sect_offset_str (cu
->header
.sect_off
),
22656 sect_offset_str (die
->sect_off
));
22657 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
22659 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
22662 /* Look up the type of DIE in CU using its type attribute ATTR.
22663 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
22664 DW_AT_containing_type.
22665 If there is no type substitute an error marker. */
22667 static struct type
*
22668 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
22669 struct dwarf2_cu
*cu
)
22671 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22672 struct objfile
*objfile
= per_objfile
->objfile
;
22673 struct type
*this_type
;
22675 gdb_assert (attr
->name
== DW_AT_type
22676 || attr
->name
== DW_AT_GNAT_descriptive_type
22677 || attr
->name
== DW_AT_containing_type
);
22679 /* First see if we have it cached. */
22681 if (attr
->form
== DW_FORM_GNU_ref_alt
)
22683 struct dwarf2_per_cu_data
*per_cu
;
22684 sect_offset sect_off
= attr
->get_ref_die_offset ();
22686 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1, per_objfile
);
22687 this_type
= get_die_type_at_offset (sect_off
, per_cu
, per_objfile
);
22689 else if (attr
->form_is_ref ())
22691 sect_offset sect_off
= attr
->get_ref_die_offset ();
22693 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, per_objfile
);
22695 else if (attr
->form
== DW_FORM_ref_sig8
)
22697 ULONGEST signature
= attr
->as_signature ();
22699 return get_signatured_type (die
, signature
, cu
);
22703 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
22704 " at %s [in module %s]"),
22705 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
22706 objfile_name (objfile
));
22707 return build_error_marker_type (cu
, die
);
22710 /* If not cached we need to read it in. */
22712 if (this_type
== NULL
)
22714 struct die_info
*type_die
= NULL
;
22715 struct dwarf2_cu
*type_cu
= cu
;
22717 if (attr
->form_is_ref ())
22718 type_die
= follow_die_ref (die
, attr
, &type_cu
);
22719 if (type_die
== NULL
)
22720 return build_error_marker_type (cu
, die
);
22721 /* If we find the type now, it's probably because the type came
22722 from an inter-CU reference and the type's CU got expanded before
22724 this_type
= read_type_die (type_die
, type_cu
);
22727 /* If we still don't have a type use an error marker. */
22729 if (this_type
== NULL
)
22730 return build_error_marker_type (cu
, die
);
22735 /* Return the type in DIE, CU.
22736 Returns NULL for invalid types.
22738 This first does a lookup in die_type_hash,
22739 and only reads the die in if necessary.
22741 NOTE: This can be called when reading in partial or full symbols. */
22743 static struct type
*
22744 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
22746 struct type
*this_type
;
22748 this_type
= get_die_type (die
, cu
);
22752 return read_type_die_1 (die
, cu
);
22755 /* Read the type in DIE, CU.
22756 Returns NULL for invalid types. */
22758 static struct type
*
22759 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
22761 struct type
*this_type
= NULL
;
22765 case DW_TAG_class_type
:
22766 case DW_TAG_interface_type
:
22767 case DW_TAG_structure_type
:
22768 case DW_TAG_union_type
:
22769 this_type
= read_structure_type (die
, cu
);
22771 case DW_TAG_enumeration_type
:
22772 this_type
= read_enumeration_type (die
, cu
);
22774 case DW_TAG_subprogram
:
22775 case DW_TAG_subroutine_type
:
22776 case DW_TAG_inlined_subroutine
:
22777 this_type
= read_subroutine_type (die
, cu
);
22779 case DW_TAG_array_type
:
22780 this_type
= read_array_type (die
, cu
);
22782 case DW_TAG_set_type
:
22783 this_type
= read_set_type (die
, cu
);
22785 case DW_TAG_pointer_type
:
22786 this_type
= read_tag_pointer_type (die
, cu
);
22788 case DW_TAG_ptr_to_member_type
:
22789 this_type
= read_tag_ptr_to_member_type (die
, cu
);
22791 case DW_TAG_reference_type
:
22792 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
22794 case DW_TAG_rvalue_reference_type
:
22795 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
22797 case DW_TAG_const_type
:
22798 this_type
= read_tag_const_type (die
, cu
);
22800 case DW_TAG_volatile_type
:
22801 this_type
= read_tag_volatile_type (die
, cu
);
22803 case DW_TAG_restrict_type
:
22804 this_type
= read_tag_restrict_type (die
, cu
);
22806 case DW_TAG_string_type
:
22807 this_type
= read_tag_string_type (die
, cu
);
22809 case DW_TAG_typedef
:
22810 this_type
= read_typedef (die
, cu
);
22812 case DW_TAG_subrange_type
:
22813 this_type
= read_subrange_type (die
, cu
);
22815 case DW_TAG_base_type
:
22816 this_type
= read_base_type (die
, cu
);
22818 case DW_TAG_unspecified_type
:
22819 this_type
= read_unspecified_type (die
, cu
);
22821 case DW_TAG_namespace
:
22822 this_type
= read_namespace_type (die
, cu
);
22824 case DW_TAG_module
:
22825 this_type
= read_module_type (die
, cu
);
22827 case DW_TAG_atomic_type
:
22828 this_type
= read_tag_atomic_type (die
, cu
);
22831 complaint (_("unexpected tag in read_type_die: '%s'"),
22832 dwarf_tag_name (die
->tag
));
22839 /* See if we can figure out if the class lives in a namespace. We do
22840 this by looking for a member function; its demangled name will
22841 contain namespace info, if there is any.
22842 Return the computed name or NULL.
22843 Space for the result is allocated on the objfile's obstack.
22844 This is the full-die version of guess_partial_die_structure_name.
22845 In this case we know DIE has no useful parent. */
22847 static const char *
22848 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22850 struct die_info
*spec_die
;
22851 struct dwarf2_cu
*spec_cu
;
22852 struct die_info
*child
;
22853 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22856 spec_die
= die_specification (die
, &spec_cu
);
22857 if (spec_die
!= NULL
)
22863 for (child
= die
->child
;
22865 child
= child
->sibling
)
22867 if (child
->tag
== DW_TAG_subprogram
)
22869 const char *linkage_name
= dw2_linkage_name (child
, cu
);
22871 if (linkage_name
!= NULL
)
22873 gdb::unique_xmalloc_ptr
<char> actual_name
22874 (cu
->language_defn
->class_name_from_physname (linkage_name
));
22875 const char *name
= NULL
;
22877 if (actual_name
!= NULL
)
22879 const char *die_name
= dwarf2_name (die
, cu
);
22881 if (die_name
!= NULL
22882 && strcmp (die_name
, actual_name
.get ()) != 0)
22884 /* Strip off the class name from the full name.
22885 We want the prefix. */
22886 int die_name_len
= strlen (die_name
);
22887 int actual_name_len
= strlen (actual_name
.get ());
22888 const char *ptr
= actual_name
.get ();
22890 /* Test for '::' as a sanity check. */
22891 if (actual_name_len
> die_name_len
+ 2
22892 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
22893 name
= obstack_strndup (
22894 &objfile
->per_bfd
->storage_obstack
,
22895 ptr
, actual_name_len
- die_name_len
- 2);
22906 /* GCC might emit a nameless typedef that has a linkage name. Determine the
22907 prefix part in such case. See
22908 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22910 static const char *
22911 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22913 struct attribute
*attr
;
22916 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
22917 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
22920 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
22923 attr
= dw2_linkage_name_attr (die
, cu
);
22924 const char *attr_name
= attr
->as_string ();
22925 if (attr
== NULL
|| attr_name
== NULL
)
22928 /* dwarf2_name had to be already called. */
22929 gdb_assert (attr
->canonical_string_p ());
22931 /* Strip the base name, keep any leading namespaces/classes. */
22932 base
= strrchr (attr_name
, ':');
22933 if (base
== NULL
|| base
== attr_name
|| base
[-1] != ':')
22936 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22937 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
22939 &base
[-1] - attr_name
);
22942 /* Return the name of the namespace/class that DIE is defined within,
22943 or "" if we can't tell. The caller should not xfree the result.
22945 For example, if we're within the method foo() in the following
22955 then determine_prefix on foo's die will return "N::C". */
22957 static const char *
22958 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22960 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22961 struct die_info
*parent
, *spec_die
;
22962 struct dwarf2_cu
*spec_cu
;
22963 struct type
*parent_type
;
22964 const char *retval
;
22966 if (cu
->language
!= language_cplus
22967 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
22968 && cu
->language
!= language_rust
)
22971 retval
= anonymous_struct_prefix (die
, cu
);
22975 /* We have to be careful in the presence of DW_AT_specification.
22976 For example, with GCC 3.4, given the code
22980 // Definition of N::foo.
22984 then we'll have a tree of DIEs like this:
22986 1: DW_TAG_compile_unit
22987 2: DW_TAG_namespace // N
22988 3: DW_TAG_subprogram // declaration of N::foo
22989 4: DW_TAG_subprogram // definition of N::foo
22990 DW_AT_specification // refers to die #3
22992 Thus, when processing die #4, we have to pretend that we're in
22993 the context of its DW_AT_specification, namely the contex of die
22996 spec_die
= die_specification (die
, &spec_cu
);
22997 if (spec_die
== NULL
)
22998 parent
= die
->parent
;
23001 parent
= spec_die
->parent
;
23005 if (parent
== NULL
)
23007 else if (parent
->building_fullname
)
23010 const char *parent_name
;
23012 /* It has been seen on RealView 2.2 built binaries,
23013 DW_TAG_template_type_param types actually _defined_ as
23014 children of the parent class:
23017 template class <class Enum> Class{};
23018 Class<enum E> class_e;
23020 1: DW_TAG_class_type (Class)
23021 2: DW_TAG_enumeration_type (E)
23022 3: DW_TAG_enumerator (enum1:0)
23023 3: DW_TAG_enumerator (enum2:1)
23025 2: DW_TAG_template_type_param
23026 DW_AT_type DW_FORM_ref_udata (E)
23028 Besides being broken debug info, it can put GDB into an
23029 infinite loop. Consider:
23031 When we're building the full name for Class<E>, we'll start
23032 at Class, and go look over its template type parameters,
23033 finding E. We'll then try to build the full name of E, and
23034 reach here. We're now trying to build the full name of E,
23035 and look over the parent DIE for containing scope. In the
23036 broken case, if we followed the parent DIE of E, we'd again
23037 find Class, and once again go look at its template type
23038 arguments, etc., etc. Simply don't consider such parent die
23039 as source-level parent of this die (it can't be, the language
23040 doesn't allow it), and break the loop here. */
23041 name
= dwarf2_name (die
, cu
);
23042 parent_name
= dwarf2_name (parent
, cu
);
23043 complaint (_("template param type '%s' defined within parent '%s'"),
23044 name
? name
: "<unknown>",
23045 parent_name
? parent_name
: "<unknown>");
23049 switch (parent
->tag
)
23051 case DW_TAG_namespace
:
23052 parent_type
= read_type_die (parent
, cu
);
23053 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
23054 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
23055 Work around this problem here. */
23056 if (cu
->language
== language_cplus
23057 && strcmp (parent_type
->name (), "::") == 0)
23059 /* We give a name to even anonymous namespaces. */
23060 return parent_type
->name ();
23061 case DW_TAG_class_type
:
23062 case DW_TAG_interface_type
:
23063 case DW_TAG_structure_type
:
23064 case DW_TAG_union_type
:
23065 case DW_TAG_module
:
23066 parent_type
= read_type_die (parent
, cu
);
23067 if (parent_type
->name () != NULL
)
23068 return parent_type
->name ();
23070 /* An anonymous structure is only allowed non-static data
23071 members; no typedefs, no member functions, et cetera.
23072 So it does not need a prefix. */
23074 case DW_TAG_compile_unit
:
23075 case DW_TAG_partial_unit
:
23076 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
23077 if (cu
->language
== language_cplus
23078 && !per_objfile
->per_bfd
->types
.empty ()
23079 && die
->child
!= NULL
23080 && (die
->tag
== DW_TAG_class_type
23081 || die
->tag
== DW_TAG_structure_type
23082 || die
->tag
== DW_TAG_union_type
))
23084 const char *name
= guess_full_die_structure_name (die
, cu
);
23089 case DW_TAG_subprogram
:
23090 /* Nested subroutines in Fortran get a prefix with the name
23091 of the parent's subroutine. */
23092 if (cu
->language
== language_fortran
)
23094 if ((die
->tag
== DW_TAG_subprogram
)
23095 && (dwarf2_name (parent
, cu
) != NULL
))
23096 return dwarf2_name (parent
, cu
);
23098 return determine_prefix (parent
, cu
);
23099 case DW_TAG_enumeration_type
:
23100 parent_type
= read_type_die (parent
, cu
);
23101 if (TYPE_DECLARED_CLASS (parent_type
))
23103 if (parent_type
->name () != NULL
)
23104 return parent_type
->name ();
23107 /* Fall through. */
23109 return determine_prefix (parent
, cu
);
23113 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
23114 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
23115 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
23116 an obconcat, otherwise allocate storage for the result. The CU argument is
23117 used to determine the language and hence, the appropriate separator. */
23119 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
23122 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
23123 int physname
, struct dwarf2_cu
*cu
)
23125 const char *lead
= "";
23128 if (suffix
== NULL
|| suffix
[0] == '\0'
23129 || prefix
== NULL
|| prefix
[0] == '\0')
23131 else if (cu
->language
== language_d
)
23133 /* For D, the 'main' function could be defined in any module, but it
23134 should never be prefixed. */
23135 if (strcmp (suffix
, "D main") == 0)
23143 else if (cu
->language
== language_fortran
&& physname
)
23145 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
23146 DW_AT_MIPS_linkage_name is preferred and used instead. */
23154 if (prefix
== NULL
)
23156 if (suffix
== NULL
)
23163 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
23165 strcpy (retval
, lead
);
23166 strcat (retval
, prefix
);
23167 strcat (retval
, sep
);
23168 strcat (retval
, suffix
);
23173 /* We have an obstack. */
23174 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
23178 /* Get name of a die, return NULL if not found. */
23180 static const char *
23181 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
23182 struct objfile
*objfile
)
23184 if (name
&& cu
->language
== language_cplus
)
23186 gdb::unique_xmalloc_ptr
<char> canon_name
23187 = cp_canonicalize_string (name
);
23189 if (canon_name
!= nullptr)
23190 name
= objfile
->intern (canon_name
.get ());
23196 /* Get name of a die, return NULL if not found.
23197 Anonymous namespaces are converted to their magic string. */
23199 static const char *
23200 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
23202 struct attribute
*attr
;
23203 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
23205 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
23206 const char *attr_name
= attr
== nullptr ? nullptr : attr
->as_string ();
23207 if (attr_name
== nullptr
23208 && die
->tag
!= DW_TAG_namespace
23209 && die
->tag
!= DW_TAG_class_type
23210 && die
->tag
!= DW_TAG_interface_type
23211 && die
->tag
!= DW_TAG_structure_type
23212 && die
->tag
!= DW_TAG_union_type
)
23217 case DW_TAG_compile_unit
:
23218 case DW_TAG_partial_unit
:
23219 /* Compilation units have a DW_AT_name that is a filename, not
23220 a source language identifier. */
23221 case DW_TAG_enumeration_type
:
23222 case DW_TAG_enumerator
:
23223 /* These tags always have simple identifiers already; no need
23224 to canonicalize them. */
23227 case DW_TAG_namespace
:
23228 if (attr_name
!= nullptr)
23230 return CP_ANONYMOUS_NAMESPACE_STR
;
23232 case DW_TAG_class_type
:
23233 case DW_TAG_interface_type
:
23234 case DW_TAG_structure_type
:
23235 case DW_TAG_union_type
:
23236 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
23237 structures or unions. These were of the form "._%d" in GCC 4.1,
23238 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
23239 and GCC 4.4. We work around this problem by ignoring these. */
23240 if (attr_name
!= nullptr
23241 && (startswith (attr_name
, "._")
23242 || startswith (attr_name
, "<anonymous")))
23245 /* GCC might emit a nameless typedef that has a linkage name. See
23246 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
23247 if (!attr
|| attr_name
== NULL
)
23249 attr
= dw2_linkage_name_attr (die
, cu
);
23250 attr_name
= attr
== nullptr ? nullptr : attr
->as_string ();
23251 if (attr
== NULL
|| attr_name
== NULL
)
23254 /* Avoid demangling attr_name the second time on a second
23255 call for the same DIE. */
23256 if (!attr
->canonical_string_p ())
23258 gdb::unique_xmalloc_ptr
<char> demangled
23259 (gdb_demangle (attr_name
, DMGL_TYPES
));
23260 if (demangled
== nullptr)
23263 attr
->set_string_canonical (objfile
->intern (demangled
.get ()));
23264 attr_name
= attr
->as_string ();
23267 /* Strip any leading namespaces/classes, keep only the
23268 base name. DW_AT_name for named DIEs does not
23269 contain the prefixes. */
23270 const char *base
= strrchr (attr_name
, ':');
23271 if (base
&& base
> attr_name
&& base
[-1] == ':')
23282 if (!attr
->canonical_string_p ())
23283 attr
->set_string_canonical (dwarf2_canonicalize_name (attr_name
, cu
,
23285 return attr
->as_string ();
23288 /* Return the die that this die in an extension of, or NULL if there
23289 is none. *EXT_CU is the CU containing DIE on input, and the CU
23290 containing the return value on output. */
23292 static struct die_info
*
23293 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
23295 struct attribute
*attr
;
23297 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
23301 return follow_die_ref (die
, attr
, ext_cu
);
23305 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
23309 print_spaces (indent
, f
);
23310 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
23311 dwarf_tag_name (die
->tag
), die
->abbrev
,
23312 sect_offset_str (die
->sect_off
));
23314 if (die
->parent
!= NULL
)
23316 print_spaces (indent
, f
);
23317 fprintf_unfiltered (f
, " parent at offset: %s\n",
23318 sect_offset_str (die
->parent
->sect_off
));
23321 print_spaces (indent
, f
);
23322 fprintf_unfiltered (f
, " has children: %s\n",
23323 dwarf_bool_name (die
->child
!= NULL
));
23325 print_spaces (indent
, f
);
23326 fprintf_unfiltered (f
, " attributes:\n");
23328 for (i
= 0; i
< die
->num_attrs
; ++i
)
23330 print_spaces (indent
, f
);
23331 fprintf_unfiltered (f
, " %s (%s) ",
23332 dwarf_attr_name (die
->attrs
[i
].name
),
23333 dwarf_form_name (die
->attrs
[i
].form
));
23335 switch (die
->attrs
[i
].form
)
23338 case DW_FORM_addrx
:
23339 case DW_FORM_GNU_addr_index
:
23340 fprintf_unfiltered (f
, "address: ");
23341 fputs_filtered (hex_string (die
->attrs
[i
].as_address ()), f
);
23343 case DW_FORM_block2
:
23344 case DW_FORM_block4
:
23345 case DW_FORM_block
:
23346 case DW_FORM_block1
:
23347 fprintf_unfiltered (f
, "block: size %s",
23348 pulongest (die
->attrs
[i
].as_block ()->size
));
23350 case DW_FORM_exprloc
:
23351 fprintf_unfiltered (f
, "expression: size %s",
23352 pulongest (die
->attrs
[i
].as_block ()->size
));
23354 case DW_FORM_data16
:
23355 fprintf_unfiltered (f
, "constant of 16 bytes");
23357 case DW_FORM_ref_addr
:
23358 fprintf_unfiltered (f
, "ref address: ");
23359 fputs_filtered (hex_string (die
->attrs
[i
].as_unsigned ()), f
);
23361 case DW_FORM_GNU_ref_alt
:
23362 fprintf_unfiltered (f
, "alt ref address: ");
23363 fputs_filtered (hex_string (die
->attrs
[i
].as_unsigned ()), f
);
23369 case DW_FORM_ref_udata
:
23370 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
23371 (long) (die
->attrs
[i
].as_unsigned ()));
23373 case DW_FORM_data1
:
23374 case DW_FORM_data2
:
23375 case DW_FORM_data4
:
23376 case DW_FORM_data8
:
23377 case DW_FORM_udata
:
23378 fprintf_unfiltered (f
, "constant: %s",
23379 pulongest (die
->attrs
[i
].as_unsigned ()));
23381 case DW_FORM_sec_offset
:
23382 fprintf_unfiltered (f
, "section offset: %s",
23383 pulongest (die
->attrs
[i
].as_unsigned ()));
23385 case DW_FORM_ref_sig8
:
23386 fprintf_unfiltered (f
, "signature: %s",
23387 hex_string (die
->attrs
[i
].as_signature ()));
23389 case DW_FORM_string
:
23391 case DW_FORM_line_strp
:
23393 case DW_FORM_GNU_str_index
:
23394 case DW_FORM_GNU_strp_alt
:
23395 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
23396 die
->attrs
[i
].as_string ()
23397 ? die
->attrs
[i
].as_string () : "",
23398 die
->attrs
[i
].canonical_string_p () ? "is" : "not");
23401 if (die
->attrs
[i
].as_boolean ())
23402 fprintf_unfiltered (f
, "flag: TRUE");
23404 fprintf_unfiltered (f
, "flag: FALSE");
23406 case DW_FORM_flag_present
:
23407 fprintf_unfiltered (f
, "flag: TRUE");
23409 case DW_FORM_indirect
:
23410 /* The reader will have reduced the indirect form to
23411 the "base form" so this form should not occur. */
23412 fprintf_unfiltered (f
,
23413 "unexpected attribute form: DW_FORM_indirect");
23415 case DW_FORM_sdata
:
23416 case DW_FORM_implicit_const
:
23417 fprintf_unfiltered (f
, "constant: %s",
23418 plongest (die
->attrs
[i
].as_signed ()));
23421 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
23422 die
->attrs
[i
].form
);
23425 fprintf_unfiltered (f
, "\n");
23430 dump_die_for_error (struct die_info
*die
)
23432 dump_die_shallow (gdb_stderr
, 0, die
);
23436 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
23438 int indent
= level
* 4;
23440 gdb_assert (die
!= NULL
);
23442 if (level
>= max_level
)
23445 dump_die_shallow (f
, indent
, die
);
23447 if (die
->child
!= NULL
)
23449 print_spaces (indent
, f
);
23450 fprintf_unfiltered (f
, " Children:");
23451 if (level
+ 1 < max_level
)
23453 fprintf_unfiltered (f
, "\n");
23454 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
23458 fprintf_unfiltered (f
,
23459 " [not printed, max nesting level reached]\n");
23463 if (die
->sibling
!= NULL
&& level
> 0)
23465 dump_die_1 (f
, level
, max_level
, die
->sibling
);
23469 /* This is called from the pdie macro in gdbinit.in.
23470 It's not static so gcc will keep a copy callable from gdb. */
23473 dump_die (struct die_info
*die
, int max_level
)
23475 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
23479 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
23483 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
23484 to_underlying (die
->sect_off
),
23490 /* Follow reference or signature attribute ATTR of SRC_DIE.
23491 On entry *REF_CU is the CU of SRC_DIE.
23492 On exit *REF_CU is the CU of the result. */
23494 static struct die_info
*
23495 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23496 struct dwarf2_cu
**ref_cu
)
23498 struct die_info
*die
;
23500 if (attr
->form_is_ref ())
23501 die
= follow_die_ref (src_die
, attr
, ref_cu
);
23502 else if (attr
->form
== DW_FORM_ref_sig8
)
23503 die
= follow_die_sig (src_die
, attr
, ref_cu
);
23506 dump_die_for_error (src_die
);
23507 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
23508 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23514 /* Follow reference OFFSET.
23515 On entry *REF_CU is the CU of the source die referencing OFFSET.
23516 On exit *REF_CU is the CU of the result.
23517 Returns NULL if OFFSET is invalid. */
23519 static struct die_info
*
23520 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
23521 struct dwarf2_cu
**ref_cu
)
23523 struct die_info temp_die
;
23524 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
23525 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23527 gdb_assert (cu
->per_cu
!= NULL
);
23531 if (cu
->per_cu
->is_debug_types
)
23533 /* .debug_types CUs cannot reference anything outside their CU.
23534 If they need to, they have to reference a signatured type via
23535 DW_FORM_ref_sig8. */
23536 if (!cu
->header
.offset_in_cu_p (sect_off
))
23539 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
23540 || !cu
->header
.offset_in_cu_p (sect_off
))
23542 struct dwarf2_per_cu_data
*per_cu
;
23544 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23547 /* If necessary, add it to the queue and load its DIEs. */
23548 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->language
))
23549 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
23550 false, cu
->language
);
23552 target_cu
= per_objfile
->get_cu (per_cu
);
23554 else if (cu
->dies
== NULL
)
23556 /* We're loading full DIEs during partial symbol reading. */
23557 gdb_assert (per_objfile
->per_bfd
->reading_partial_symbols
);
23558 load_full_comp_unit (cu
->per_cu
, per_objfile
, cu
, false,
23562 *ref_cu
= target_cu
;
23563 temp_die
.sect_off
= sect_off
;
23565 if (target_cu
!= cu
)
23566 target_cu
->ancestor
= cu
;
23568 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
23570 to_underlying (sect_off
));
23573 /* Follow reference attribute ATTR of SRC_DIE.
23574 On entry *REF_CU is the CU of SRC_DIE.
23575 On exit *REF_CU is the CU of the result. */
23577 static struct die_info
*
23578 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
23579 struct dwarf2_cu
**ref_cu
)
23581 sect_offset sect_off
= attr
->get_ref_die_offset ();
23582 struct dwarf2_cu
*cu
= *ref_cu
;
23583 struct die_info
*die
;
23585 die
= follow_die_offset (sect_off
,
23586 (attr
->form
== DW_FORM_GNU_ref_alt
23587 || cu
->per_cu
->is_dwz
),
23590 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
23591 "at %s [in module %s]"),
23592 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
23593 objfile_name (cu
->per_objfile
->objfile
));
23600 struct dwarf2_locexpr_baton
23601 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
23602 dwarf2_per_cu_data
*per_cu
,
23603 dwarf2_per_objfile
*per_objfile
,
23604 gdb::function_view
<CORE_ADDR ()> get_frame_pc
,
23605 bool resolve_abstract_p
)
23607 struct die_info
*die
;
23608 struct attribute
*attr
;
23609 struct dwarf2_locexpr_baton retval
;
23610 struct objfile
*objfile
= per_objfile
->objfile
;
23612 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23614 cu
= load_cu (per_cu
, per_objfile
, false);
23618 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23619 Instead just throw an error, not much else we can do. */
23620 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23621 sect_offset_str (sect_off
), objfile_name (objfile
));
23624 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23626 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23627 sect_offset_str (sect_off
), objfile_name (objfile
));
23629 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23630 if (!attr
&& resolve_abstract_p
23631 && (per_objfile
->per_bfd
->abstract_to_concrete
.find (die
->sect_off
)
23632 != per_objfile
->per_bfd
->abstract_to_concrete
.end ()))
23634 CORE_ADDR pc
= get_frame_pc ();
23635 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
23636 struct gdbarch
*gdbarch
= objfile
->arch ();
23638 for (const auto &cand_off
23639 : per_objfile
->per_bfd
->abstract_to_concrete
[die
->sect_off
])
23641 struct dwarf2_cu
*cand_cu
= cu
;
23642 struct die_info
*cand
23643 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
23646 || cand
->parent
->tag
!= DW_TAG_subprogram
)
23649 CORE_ADDR pc_low
, pc_high
;
23650 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
23651 if (pc_low
== ((CORE_ADDR
) -1))
23653 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
23654 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
23655 if (!(pc_low
<= pc
&& pc
< pc_high
))
23659 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23666 /* DWARF: "If there is no such attribute, then there is no effect.".
23667 DATA is ignored if SIZE is 0. */
23669 retval
.data
= NULL
;
23672 else if (attr
->form_is_section_offset ())
23674 struct dwarf2_loclist_baton loclist_baton
;
23675 CORE_ADDR pc
= get_frame_pc ();
23678 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
23680 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
23682 retval
.size
= size
;
23686 if (!attr
->form_is_block ())
23687 error (_("Dwarf Error: DIE at %s referenced in module %s "
23688 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
23689 sect_offset_str (sect_off
), objfile_name (objfile
));
23691 struct dwarf_block
*block
= attr
->as_block ();
23692 retval
.data
= block
->data
;
23693 retval
.size
= block
->size
;
23695 retval
.per_objfile
= per_objfile
;
23696 retval
.per_cu
= cu
->per_cu
;
23698 per_objfile
->age_comp_units ();
23705 struct dwarf2_locexpr_baton
23706 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
23707 dwarf2_per_cu_data
*per_cu
,
23708 dwarf2_per_objfile
*per_objfile
,
23709 gdb::function_view
<CORE_ADDR ()> get_frame_pc
)
23711 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
23713 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, per_objfile
,
23717 /* Write a constant of a given type as target-ordered bytes into
23720 static const gdb_byte
*
23721 write_constant_as_bytes (struct obstack
*obstack
,
23722 enum bfd_endian byte_order
,
23729 *len
= TYPE_LENGTH (type
);
23730 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23731 store_unsigned_integer (result
, *len
, byte_order
, value
);
23739 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
23740 dwarf2_per_cu_data
*per_cu
,
23741 dwarf2_per_objfile
*per_objfile
,
23745 struct die_info
*die
;
23746 struct attribute
*attr
;
23747 const gdb_byte
*result
= NULL
;
23750 enum bfd_endian byte_order
;
23751 struct objfile
*objfile
= per_objfile
->objfile
;
23753 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23755 cu
= load_cu (per_cu
, per_objfile
, false);
23759 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23760 Instead just throw an error, not much else we can do. */
23761 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23762 sect_offset_str (sect_off
), objfile_name (objfile
));
23765 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23767 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23768 sect_offset_str (sect_off
), objfile_name (objfile
));
23770 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23774 byte_order
= (bfd_big_endian (objfile
->obfd
)
23775 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
23777 switch (attr
->form
)
23780 case DW_FORM_addrx
:
23781 case DW_FORM_GNU_addr_index
:
23785 *len
= cu
->header
.addr_size
;
23786 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23787 store_unsigned_integer (tem
, *len
, byte_order
, attr
->as_address ());
23791 case DW_FORM_string
:
23794 case DW_FORM_GNU_str_index
:
23795 case DW_FORM_GNU_strp_alt
:
23796 /* The string is already allocated on the objfile obstack, point
23799 const char *attr_name
= attr
->as_string ();
23800 result
= (const gdb_byte
*) attr_name
;
23801 *len
= strlen (attr_name
);
23804 case DW_FORM_block1
:
23805 case DW_FORM_block2
:
23806 case DW_FORM_block4
:
23807 case DW_FORM_block
:
23808 case DW_FORM_exprloc
:
23809 case DW_FORM_data16
:
23811 struct dwarf_block
*block
= attr
->as_block ();
23812 result
= block
->data
;
23813 *len
= block
->size
;
23817 /* The DW_AT_const_value attributes are supposed to carry the
23818 symbol's value "represented as it would be on the target
23819 architecture." By the time we get here, it's already been
23820 converted to host endianness, so we just need to sign- or
23821 zero-extend it as appropriate. */
23822 case DW_FORM_data1
:
23823 type
= die_type (die
, cu
);
23824 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
23825 if (result
== NULL
)
23826 result
= write_constant_as_bytes (obstack
, byte_order
,
23829 case DW_FORM_data2
:
23830 type
= die_type (die
, cu
);
23831 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
23832 if (result
== NULL
)
23833 result
= write_constant_as_bytes (obstack
, byte_order
,
23836 case DW_FORM_data4
:
23837 type
= die_type (die
, cu
);
23838 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
23839 if (result
== NULL
)
23840 result
= write_constant_as_bytes (obstack
, byte_order
,
23843 case DW_FORM_data8
:
23844 type
= die_type (die
, cu
);
23845 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
23846 if (result
== NULL
)
23847 result
= write_constant_as_bytes (obstack
, byte_order
,
23851 case DW_FORM_sdata
:
23852 case DW_FORM_implicit_const
:
23853 type
= die_type (die
, cu
);
23854 result
= write_constant_as_bytes (obstack
, byte_order
,
23855 type
, attr
->as_signed (), len
);
23858 case DW_FORM_udata
:
23859 type
= die_type (die
, cu
);
23860 result
= write_constant_as_bytes (obstack
, byte_order
,
23861 type
, attr
->as_unsigned (), len
);
23865 complaint (_("unsupported const value attribute form: '%s'"),
23866 dwarf_form_name (attr
->form
));
23876 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
23877 dwarf2_per_cu_data
*per_cu
,
23878 dwarf2_per_objfile
*per_objfile
)
23880 struct die_info
*die
;
23882 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23884 cu
= load_cu (per_cu
, per_objfile
, false);
23889 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23893 return die_type (die
, cu
);
23899 dwarf2_get_die_type (cu_offset die_offset
,
23900 dwarf2_per_cu_data
*per_cu
,
23901 dwarf2_per_objfile
*per_objfile
)
23903 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
23904 return get_die_type_at_offset (die_offset_sect
, per_cu
, per_objfile
);
23907 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
23908 On entry *REF_CU is the CU of SRC_DIE.
23909 On exit *REF_CU is the CU of the result.
23910 Returns NULL if the referenced DIE isn't found. */
23912 static struct die_info
*
23913 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
23914 struct dwarf2_cu
**ref_cu
)
23916 struct die_info temp_die
;
23917 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
23918 struct die_info
*die
;
23919 dwarf2_per_objfile
*per_objfile
= (*ref_cu
)->per_objfile
;
23922 /* While it might be nice to assert sig_type->type == NULL here,
23923 we can get here for DW_AT_imported_declaration where we need
23924 the DIE not the type. */
23926 /* If necessary, add it to the queue and load its DIEs. */
23928 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, per_objfile
,
23930 read_signatured_type (sig_type
, per_objfile
);
23932 sig_cu
= per_objfile
->get_cu (&sig_type
->per_cu
);
23933 gdb_assert (sig_cu
!= NULL
);
23934 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
23935 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
23936 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
23937 to_underlying (temp_die
.sect_off
));
23940 /* For .gdb_index version 7 keep track of included TUs.
23941 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
23942 if (per_objfile
->per_bfd
->index_table
!= NULL
23943 && per_objfile
->per_bfd
->index_table
->version
<= 7)
23945 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
23950 sig_cu
->ancestor
= cu
;
23958 /* Follow signatured type referenced by ATTR in SRC_DIE.
23959 On entry *REF_CU is the CU of SRC_DIE.
23960 On exit *REF_CU is the CU of the result.
23961 The result is the DIE of the type.
23962 If the referenced type cannot be found an error is thrown. */
23964 static struct die_info
*
23965 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23966 struct dwarf2_cu
**ref_cu
)
23968 ULONGEST signature
= attr
->as_signature ();
23969 struct signatured_type
*sig_type
;
23970 struct die_info
*die
;
23972 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
23974 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
23975 /* sig_type will be NULL if the signatured type is missing from
23977 if (sig_type
== NULL
)
23979 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23980 " from DIE at %s [in module %s]"),
23981 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23982 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23985 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
23988 dump_die_for_error (src_die
);
23989 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23990 " from DIE at %s [in module %s]"),
23991 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23992 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23998 /* Get the type specified by SIGNATURE referenced in DIE/CU,
23999 reading in and processing the type unit if necessary. */
24001 static struct type
*
24002 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
24003 struct dwarf2_cu
*cu
)
24005 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24006 struct signatured_type
*sig_type
;
24007 struct dwarf2_cu
*type_cu
;
24008 struct die_info
*type_die
;
24011 sig_type
= lookup_signatured_type (cu
, signature
);
24012 /* sig_type will be NULL if the signatured type is missing from
24014 if (sig_type
== NULL
)
24016 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
24017 " from DIE at %s [in module %s]"),
24018 hex_string (signature
), sect_offset_str (die
->sect_off
),
24019 objfile_name (per_objfile
->objfile
));
24020 return build_error_marker_type (cu
, die
);
24023 /* If we already know the type we're done. */
24024 type
= per_objfile
->get_type_for_signatured_type (sig_type
);
24025 if (type
!= nullptr)
24029 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
24030 if (type_die
!= NULL
)
24032 /* N.B. We need to call get_die_type to ensure only one type for this DIE
24033 is created. This is important, for example, because for c++ classes
24034 we need TYPE_NAME set which is only done by new_symbol. Blech. */
24035 type
= read_type_die (type_die
, type_cu
);
24038 complaint (_("Dwarf Error: Cannot build signatured type %s"
24039 " referenced from DIE at %s [in module %s]"),
24040 hex_string (signature
), sect_offset_str (die
->sect_off
),
24041 objfile_name (per_objfile
->objfile
));
24042 type
= build_error_marker_type (cu
, die
);
24047 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
24048 " from DIE at %s [in module %s]"),
24049 hex_string (signature
), sect_offset_str (die
->sect_off
),
24050 objfile_name (per_objfile
->objfile
));
24051 type
= build_error_marker_type (cu
, die
);
24054 per_objfile
->set_type_for_signatured_type (sig_type
, type
);
24059 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
24060 reading in and processing the type unit if necessary. */
24062 static struct type
*
24063 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
24064 struct dwarf2_cu
*cu
) /* ARI: editCase function */
24066 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
24067 if (attr
->form_is_ref ())
24069 struct dwarf2_cu
*type_cu
= cu
;
24070 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
24072 return read_type_die (type_die
, type_cu
);
24074 else if (attr
->form
== DW_FORM_ref_sig8
)
24076 return get_signatured_type (die
, attr
->as_signature (), cu
);
24080 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24082 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
24083 " at %s [in module %s]"),
24084 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
24085 objfile_name (per_objfile
->objfile
));
24086 return build_error_marker_type (cu
, die
);
24090 /* Load the DIEs associated with type unit PER_CU into memory. */
24093 load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
24094 dwarf2_per_objfile
*per_objfile
)
24096 struct signatured_type
*sig_type
;
24098 /* Caller is responsible for ensuring type_unit_groups don't get here. */
24099 gdb_assert (! per_cu
->type_unit_group_p ());
24101 /* We have the per_cu, but we need the signatured_type.
24102 Fortunately this is an easy translation. */
24103 gdb_assert (per_cu
->is_debug_types
);
24104 sig_type
= (struct signatured_type
*) per_cu
;
24106 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
24108 read_signatured_type (sig_type
, per_objfile
);
24110 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
24113 /* Read in a signatured type and build its CU and DIEs.
24114 If the type is a stub for the real type in a DWO file,
24115 read in the real type from the DWO file as well. */
24118 read_signatured_type (signatured_type
*sig_type
,
24119 dwarf2_per_objfile
*per_objfile
)
24121 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
24123 gdb_assert (per_cu
->is_debug_types
);
24124 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
24126 cutu_reader
reader (per_cu
, per_objfile
, nullptr, nullptr, false);
24128 if (!reader
.dummy_p
)
24130 struct dwarf2_cu
*cu
= reader
.cu
;
24131 const gdb_byte
*info_ptr
= reader
.info_ptr
;
24133 gdb_assert (cu
->die_hash
== NULL
);
24135 htab_create_alloc_ex (cu
->header
.length
/ 12,
24139 &cu
->comp_unit_obstack
,
24140 hashtab_obstack_allocate
,
24141 dummy_obstack_deallocate
);
24143 if (reader
.comp_unit_die
->has_children
)
24144 reader
.comp_unit_die
->child
24145 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
24146 reader
.comp_unit_die
);
24147 cu
->dies
= reader
.comp_unit_die
;
24148 /* comp_unit_die is not stored in die_hash, no need. */
24150 /* We try not to read any attributes in this function, because
24151 not all CUs needed for references have been loaded yet, and
24152 symbol table processing isn't initialized. But we have to
24153 set the CU language, or we won't be able to build types
24154 correctly. Similarly, if we do not read the producer, we can
24155 not apply producer-specific interpretation. */
24156 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
24161 sig_type
->per_cu
.tu_read
= 1;
24164 /* Decode simple location descriptions.
24165 Given a pointer to a dwarf block that defines a location, compute
24166 the location and return the value. If COMPUTED is non-null, it is
24167 set to true to indicate that decoding was successful, and false
24168 otherwise. If COMPUTED is null, then this function may emit a
24172 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
, bool *computed
)
24174 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
24176 size_t size
= blk
->size
;
24177 const gdb_byte
*data
= blk
->data
;
24178 CORE_ADDR stack
[64];
24180 unsigned int bytes_read
, unsnd
;
24183 if (computed
!= nullptr)
24189 stack
[++stacki
] = 0;
24228 stack
[++stacki
] = op
- DW_OP_lit0
;
24263 stack
[++stacki
] = op
- DW_OP_reg0
;
24266 if (computed
== nullptr)
24267 dwarf2_complex_location_expr_complaint ();
24274 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
24276 stack
[++stacki
] = unsnd
;
24279 if (computed
== nullptr)
24280 dwarf2_complex_location_expr_complaint ();
24287 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
24292 case DW_OP_const1u
:
24293 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
24297 case DW_OP_const1s
:
24298 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
24302 case DW_OP_const2u
:
24303 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
24307 case DW_OP_const2s
:
24308 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
24312 case DW_OP_const4u
:
24313 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
24317 case DW_OP_const4s
:
24318 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
24322 case DW_OP_const8u
:
24323 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
24328 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
24334 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
24339 stack
[stacki
+ 1] = stack
[stacki
];
24344 stack
[stacki
- 1] += stack
[stacki
];
24348 case DW_OP_plus_uconst
:
24349 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
24355 stack
[stacki
- 1] -= stack
[stacki
];
24360 /* If we're not the last op, then we definitely can't encode
24361 this using GDB's address_class enum. This is valid for partial
24362 global symbols, although the variable's address will be bogus
24366 if (computed
== nullptr)
24367 dwarf2_complex_location_expr_complaint ();
24373 case DW_OP_GNU_push_tls_address
:
24374 case DW_OP_form_tls_address
:
24375 /* The top of the stack has the offset from the beginning
24376 of the thread control block at which the variable is located. */
24377 /* Nothing should follow this operator, so the top of stack would
24379 /* This is valid for partial global symbols, but the variable's
24380 address will be bogus in the psymtab. Make it always at least
24381 non-zero to not look as a variable garbage collected by linker
24382 which have DW_OP_addr 0. */
24385 if (computed
== nullptr)
24386 dwarf2_complex_location_expr_complaint ();
24393 case DW_OP_GNU_uninit
:
24394 if (computed
!= nullptr)
24399 case DW_OP_GNU_addr_index
:
24400 case DW_OP_GNU_const_index
:
24401 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
24407 if (computed
== nullptr)
24409 const char *name
= get_DW_OP_name (op
);
24412 complaint (_("unsupported stack op: '%s'"),
24415 complaint (_("unsupported stack op: '%02x'"),
24419 return (stack
[stacki
]);
24422 /* Enforce maximum stack depth of SIZE-1 to avoid writing
24423 outside of the allocated space. Also enforce minimum>0. */
24424 if (stacki
>= ARRAY_SIZE (stack
) - 1)
24426 if (computed
== nullptr)
24427 complaint (_("location description stack overflow"));
24433 if (computed
== nullptr)
24434 complaint (_("location description stack underflow"));
24439 if (computed
!= nullptr)
24441 return (stack
[stacki
]);
24444 /* memory allocation interface */
24446 static struct dwarf_block
*
24447 dwarf_alloc_block (struct dwarf2_cu
*cu
)
24449 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
24452 static struct die_info
*
24453 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
24455 struct die_info
*die
;
24456 size_t size
= sizeof (struct die_info
);
24459 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
24461 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
24462 memset (die
, 0, sizeof (struct die_info
));
24468 /* Macro support. */
24470 /* An overload of dwarf_decode_macros that finds the correct section
24471 and ensures it is read in before calling the other overload. */
24474 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
24475 int section_is_gnu
)
24477 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24478 struct objfile
*objfile
= per_objfile
->objfile
;
24479 const struct line_header
*lh
= cu
->line_header
;
24480 unsigned int offset_size
= cu
->header
.offset_size
;
24481 struct dwarf2_section_info
*section
;
24482 const char *section_name
;
24484 if (cu
->dwo_unit
!= nullptr)
24486 if (section_is_gnu
)
24488 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
24489 section_name
= ".debug_macro.dwo";
24493 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
24494 section_name
= ".debug_macinfo.dwo";
24499 if (section_is_gnu
)
24501 section
= &per_objfile
->per_bfd
->macro
;
24502 section_name
= ".debug_macro";
24506 section
= &per_objfile
->per_bfd
->macinfo
;
24507 section_name
= ".debug_macinfo";
24511 section
->read (objfile
);
24512 if (section
->buffer
== nullptr)
24514 complaint (_("missing %s section"), section_name
);
24518 buildsym_compunit
*builder
= cu
->get_builder ();
24520 struct dwarf2_section_info
*str_offsets_section
;
24521 struct dwarf2_section_info
*str_section
;
24522 ULONGEST str_offsets_base
;
24524 if (cu
->dwo_unit
!= nullptr)
24526 str_offsets_section
= &cu
->dwo_unit
->dwo_file
24527 ->sections
.str_offsets
;
24528 str_section
= &cu
->dwo_unit
->dwo_file
->sections
.str
;
24529 str_offsets_base
= cu
->header
.addr_size
;
24533 str_offsets_section
= &per_objfile
->per_bfd
->str_offsets
;
24534 str_section
= &per_objfile
->per_bfd
->str
;
24535 str_offsets_base
= *cu
->str_offsets_base
;
24538 dwarf_decode_macros (per_objfile
, builder
, section
, lh
,
24539 offset_size
, offset
, str_section
, str_offsets_section
,
24540 str_offsets_base
, section_is_gnu
);
24543 /* Return the .debug_loc section to use for CU.
24544 For DWO files use .debug_loc.dwo. */
24546 static struct dwarf2_section_info
*
24547 cu_debug_loc_section (struct dwarf2_cu
*cu
)
24549 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24553 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24555 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
24557 return (cu
->header
.version
>= 5 ? &per_objfile
->per_bfd
->loclists
24558 : &per_objfile
->per_bfd
->loc
);
24561 /* Return the .debug_rnglists section to use for CU. */
24562 static struct dwarf2_section_info
*
24563 cu_debug_rnglists_section (struct dwarf2_cu
*cu
, dwarf_tag tag
)
24565 if (cu
->header
.version
< 5)
24566 error (_(".debug_rnglists section cannot be used in DWARF %d"),
24567 cu
->header
.version
);
24568 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
24570 /* Make sure we read the .debug_rnglists section from the file that
24571 contains the DW_AT_ranges attribute we are reading. Normally that
24572 would be the .dwo file, if there is one. However for DW_TAG_compile_unit
24573 or DW_TAG_skeleton unit, we always want to read from objfile/linked
24575 if (cu
->dwo_unit
!= nullptr
24576 && tag
!= DW_TAG_compile_unit
24577 && tag
!= DW_TAG_skeleton_unit
)
24579 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24581 if (sections
->rnglists
.size
> 0)
24582 return §ions
->rnglists
;
24584 error (_(".debug_rnglists section is missing from .dwo file."));
24586 return &dwarf2_per_objfile
->per_bfd
->rnglists
;
24589 /* A helper function that fills in a dwarf2_loclist_baton. */
24592 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
24593 struct dwarf2_loclist_baton
*baton
,
24594 const struct attribute
*attr
)
24596 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24597 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24599 section
->read (per_objfile
->objfile
);
24601 baton
->per_objfile
= per_objfile
;
24602 baton
->per_cu
= cu
->per_cu
;
24603 gdb_assert (baton
->per_cu
);
24604 /* We don't know how long the location list is, but make sure we
24605 don't run off the edge of the section. */
24606 baton
->size
= section
->size
- attr
->as_unsigned ();
24607 baton
->data
= section
->buffer
+ attr
->as_unsigned ();
24608 if (cu
->base_address
.has_value ())
24609 baton
->base_address
= *cu
->base_address
;
24611 baton
->base_address
= 0;
24612 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
24616 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
24617 struct dwarf2_cu
*cu
, int is_block
)
24619 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24620 struct objfile
*objfile
= per_objfile
->objfile
;
24621 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24623 if (attr
->form_is_section_offset ()
24624 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
24625 the section. If so, fall through to the complaint in the
24627 && attr
->as_unsigned () < section
->get_size (objfile
))
24629 struct dwarf2_loclist_baton
*baton
;
24631 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
24633 fill_in_loclist_baton (cu
, baton
, attr
);
24635 if (!cu
->base_address
.has_value ())
24636 complaint (_("Location list used without "
24637 "specifying the CU base address."));
24639 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24640 ? dwarf2_loclist_block_index
24641 : dwarf2_loclist_index
);
24642 SYMBOL_LOCATION_BATON (sym
) = baton
;
24646 struct dwarf2_locexpr_baton
*baton
;
24648 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
24649 baton
->per_objfile
= per_objfile
;
24650 baton
->per_cu
= cu
->per_cu
;
24651 gdb_assert (baton
->per_cu
);
24653 if (attr
->form_is_block ())
24655 /* Note that we're just copying the block's data pointer
24656 here, not the actual data. We're still pointing into the
24657 info_buffer for SYM's objfile; right now we never release
24658 that buffer, but when we do clean up properly this may
24660 struct dwarf_block
*block
= attr
->as_block ();
24661 baton
->size
= block
->size
;
24662 baton
->data
= block
->data
;
24666 dwarf2_invalid_attrib_class_complaint ("location description",
24667 sym
->natural_name ());
24671 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24672 ? dwarf2_locexpr_block_index
24673 : dwarf2_locexpr_index
);
24674 SYMBOL_LOCATION_BATON (sym
) = baton
;
24680 const comp_unit_head
*
24681 dwarf2_per_cu_data::get_header () const
24683 if (!m_header_read_in
)
24685 const gdb_byte
*info_ptr
24686 = this->section
->buffer
+ to_underlying (this->sect_off
);
24688 memset (&m_header
, 0, sizeof (m_header
));
24690 read_comp_unit_head (&m_header
, info_ptr
, this->section
,
24691 rcuh_kind::COMPILE
);
24700 dwarf2_per_cu_data::addr_size () const
24702 return this->get_header ()->addr_size
;
24708 dwarf2_per_cu_data::offset_size () const
24710 return this->get_header ()->offset_size
;
24716 dwarf2_per_cu_data::ref_addr_size () const
24718 const comp_unit_head
*header
= this->get_header ();
24720 if (header
->version
== 2)
24721 return header
->addr_size
;
24723 return header
->offset_size
;
24729 dwarf2_cu::addr_type () const
24731 struct objfile
*objfile
= this->per_objfile
->objfile
;
24732 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
24733 struct type
*addr_type
= lookup_pointer_type (void_type
);
24734 int addr_size
= this->per_cu
->addr_size ();
24736 if (TYPE_LENGTH (addr_type
) == addr_size
)
24739 addr_type
= addr_sized_int_type (addr_type
->is_unsigned ());
24743 /* A helper function for dwarf2_find_containing_comp_unit that returns
24744 the index of the result, and that searches a vector. It will
24745 return a result even if the offset in question does not actually
24746 occur in any CU. This is separate so that it can be unit
24750 dwarf2_find_containing_comp_unit
24751 (sect_offset sect_off
,
24752 unsigned int offset_in_dwz
,
24753 const std::vector
<dwarf2_per_cu_data
*> &all_comp_units
)
24758 high
= all_comp_units
.size () - 1;
24761 struct dwarf2_per_cu_data
*mid_cu
;
24762 int mid
= low
+ (high
- low
) / 2;
24764 mid_cu
= all_comp_units
[mid
];
24765 if (mid_cu
->is_dwz
> offset_in_dwz
24766 || (mid_cu
->is_dwz
== offset_in_dwz
24767 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
24772 gdb_assert (low
== high
);
24776 /* Locate the .debug_info compilation unit from CU's objfile which contains
24777 the DIE at OFFSET. Raises an error on failure. */
24779 static struct dwarf2_per_cu_data
*
24780 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
24781 unsigned int offset_in_dwz
,
24782 dwarf2_per_objfile
*per_objfile
)
24784 int low
= dwarf2_find_containing_comp_unit
24785 (sect_off
, offset_in_dwz
, per_objfile
->per_bfd
->all_comp_units
);
24786 dwarf2_per_cu_data
*this_cu
= per_objfile
->per_bfd
->all_comp_units
[low
];
24788 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
24790 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
24791 error (_("Dwarf Error: could not find partial DIE containing "
24792 "offset %s [in module %s]"),
24793 sect_offset_str (sect_off
),
24794 bfd_get_filename (per_objfile
->objfile
->obfd
));
24796 gdb_assert (per_objfile
->per_bfd
->all_comp_units
[low
-1]->sect_off
24798 return per_objfile
->per_bfd
->all_comp_units
[low
-1];
24802 if (low
== per_objfile
->per_bfd
->all_comp_units
.size () - 1
24803 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
24804 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
24805 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
24812 namespace selftests
{
24813 namespace find_containing_comp_unit
{
24818 struct dwarf2_per_cu_data one
{};
24819 struct dwarf2_per_cu_data two
{};
24820 struct dwarf2_per_cu_data three
{};
24821 struct dwarf2_per_cu_data four
{};
24824 two
.sect_off
= sect_offset (one
.length
);
24829 four
.sect_off
= sect_offset (three
.length
);
24833 std::vector
<dwarf2_per_cu_data
*> units
;
24834 units
.push_back (&one
);
24835 units
.push_back (&two
);
24836 units
.push_back (&three
);
24837 units
.push_back (&four
);
24841 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
24842 SELF_CHECK (units
[result
] == &one
);
24843 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
24844 SELF_CHECK (units
[result
] == &one
);
24845 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
24846 SELF_CHECK (units
[result
] == &two
);
24848 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
24849 SELF_CHECK (units
[result
] == &three
);
24850 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
24851 SELF_CHECK (units
[result
] == &three
);
24852 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
24853 SELF_CHECK (units
[result
] == &four
);
24859 #endif /* GDB_SELF_TEST */
24861 /* Initialize dwarf2_cu to read PER_CU, in the context of PER_OBJFILE. */
24863 dwarf2_cu::dwarf2_cu (dwarf2_per_cu_data
*per_cu
,
24864 dwarf2_per_objfile
*per_objfile
)
24866 per_objfile (per_objfile
),
24868 has_loclist (false),
24869 checked_producer (false),
24870 producer_is_gxx_lt_4_6 (false),
24871 producer_is_gcc_lt_4_3 (false),
24872 producer_is_icc (false),
24873 producer_is_icc_lt_14 (false),
24874 producer_is_codewarrior (false),
24875 processing_has_namespace_info (false)
24879 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
24882 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
24883 enum language pretend_language
)
24885 struct attribute
*attr
;
24887 /* Set the language we're debugging. */
24888 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
24889 if (attr
!= nullptr)
24890 set_cu_language (attr
->constant_value (0), cu
);
24893 cu
->language
= pretend_language
;
24894 cu
->language_defn
= language_def (cu
->language
);
24897 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
24903 dwarf2_per_objfile::get_cu (dwarf2_per_cu_data
*per_cu
)
24905 auto it
= m_dwarf2_cus
.find (per_cu
);
24906 if (it
== m_dwarf2_cus
.end ())
24915 dwarf2_per_objfile::set_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_cu
*cu
)
24917 gdb_assert (this->get_cu (per_cu
) == nullptr);
24919 m_dwarf2_cus
[per_cu
] = cu
;
24925 dwarf2_per_objfile::age_comp_units ()
24927 /* Start by clearing all marks. */
24928 for (auto pair
: m_dwarf2_cus
)
24929 pair
.second
->mark
= false;
24931 /* Traverse all CUs, mark them and their dependencies if used recently
24933 for (auto pair
: m_dwarf2_cus
)
24935 dwarf2_cu
*cu
= pair
.second
;
24938 if (cu
->last_used
<= dwarf_max_cache_age
)
24942 /* Delete all CUs still not marked. */
24943 for (auto it
= m_dwarf2_cus
.begin (); it
!= m_dwarf2_cus
.end ();)
24945 dwarf2_cu
*cu
= it
->second
;
24950 it
= m_dwarf2_cus
.erase (it
);
24960 dwarf2_per_objfile::remove_cu (dwarf2_per_cu_data
*per_cu
)
24962 auto it
= m_dwarf2_cus
.find (per_cu
);
24963 if (it
== m_dwarf2_cus
.end ())
24968 m_dwarf2_cus
.erase (it
);
24971 dwarf2_per_objfile::~dwarf2_per_objfile ()
24976 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
24977 We store these in a hash table separate from the DIEs, and preserve them
24978 when the DIEs are flushed out of cache.
24980 The CU "per_cu" pointer is needed because offset alone is not enough to
24981 uniquely identify the type. A file may have multiple .debug_types sections,
24982 or the type may come from a DWO file. Furthermore, while it's more logical
24983 to use per_cu->section+offset, with Fission the section with the data is in
24984 the DWO file but we don't know that section at the point we need it.
24985 We have to use something in dwarf2_per_cu_data (or the pointer to it)
24986 because we can enter the lookup routine, get_die_type_at_offset, from
24987 outside this file, and thus won't necessarily have PER_CU->cu.
24988 Fortunately, PER_CU is stable for the life of the objfile. */
24990 struct dwarf2_per_cu_offset_and_type
24992 const struct dwarf2_per_cu_data
*per_cu
;
24993 sect_offset sect_off
;
24997 /* Hash function for a dwarf2_per_cu_offset_and_type. */
25000 per_cu_offset_and_type_hash (const void *item
)
25002 const struct dwarf2_per_cu_offset_and_type
*ofs
25003 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
25005 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
25008 /* Equality function for a dwarf2_per_cu_offset_and_type. */
25011 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
25013 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
25014 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
25015 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
25016 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
25018 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
25019 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
25022 /* Set the type associated with DIE to TYPE. Save it in CU's hash
25023 table if necessary. For convenience, return TYPE.
25025 The DIEs reading must have careful ordering to:
25026 * Not cause infinite loops trying to read in DIEs as a prerequisite for
25027 reading current DIE.
25028 * Not trying to dereference contents of still incompletely read in types
25029 while reading in other DIEs.
25030 * Enable referencing still incompletely read in types just by a pointer to
25031 the type without accessing its fields.
25033 Therefore caller should follow these rules:
25034 * Try to fetch any prerequisite types we may need to build this DIE type
25035 before building the type and calling set_die_type.
25036 * After building type call set_die_type for current DIE as soon as
25037 possible before fetching more types to complete the current type.
25038 * Make the type as complete as possible before fetching more types. */
25040 static struct type
*
25041 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
25042 bool skip_data_location
)
25044 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
25045 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
25046 struct objfile
*objfile
= per_objfile
->objfile
;
25047 struct attribute
*attr
;
25048 struct dynamic_prop prop
;
25050 /* For Ada types, make sure that the gnat-specific data is always
25051 initialized (if not already set). There are a few types where
25052 we should not be doing so, because the type-specific area is
25053 already used to hold some other piece of info (eg: TYPE_CODE_FLT
25054 where the type-specific area is used to store the floatformat).
25055 But this is not a problem, because the gnat-specific information
25056 is actually not needed for these types. */
25057 if (need_gnat_info (cu
)
25058 && type
->code () != TYPE_CODE_FUNC
25059 && type
->code () != TYPE_CODE_FLT
25060 && type
->code () != TYPE_CODE_METHODPTR
25061 && type
->code () != TYPE_CODE_MEMBERPTR
25062 && type
->code () != TYPE_CODE_METHOD
25063 && type
->code () != TYPE_CODE_FIXED_POINT
25064 && !HAVE_GNAT_AUX_INFO (type
))
25065 INIT_GNAT_SPECIFIC (type
);
25067 /* Read DW_AT_allocated and set in type. */
25068 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
25071 struct type
*prop_type
= cu
->addr_sized_int_type (false);
25072 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
25073 type
->add_dyn_prop (DYN_PROP_ALLOCATED
, prop
);
25076 /* Read DW_AT_associated and set in type. */
25077 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
25080 struct type
*prop_type
= cu
->addr_sized_int_type (false);
25081 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
25082 type
->add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
);
25085 /* Read DW_AT_data_location and set in type. */
25086 if (!skip_data_location
)
25088 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
25089 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
25090 type
->add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
);
25093 if (per_objfile
->die_type_hash
== NULL
)
25094 per_objfile
->die_type_hash
25095 = htab_up (htab_create_alloc (127,
25096 per_cu_offset_and_type_hash
,
25097 per_cu_offset_and_type_eq
,
25098 NULL
, xcalloc
, xfree
));
25100 ofs
.per_cu
= cu
->per_cu
;
25101 ofs
.sect_off
= die
->sect_off
;
25103 slot
= (struct dwarf2_per_cu_offset_and_type
**)
25104 htab_find_slot (per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
25106 complaint (_("A problem internal to GDB: DIE %s has type already set"),
25107 sect_offset_str (die
->sect_off
));
25108 *slot
= XOBNEW (&objfile
->objfile_obstack
,
25109 struct dwarf2_per_cu_offset_and_type
);
25114 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
25115 or return NULL if the die does not have a saved type. */
25117 static struct type
*
25118 get_die_type_at_offset (sect_offset sect_off
,
25119 dwarf2_per_cu_data
*per_cu
,
25120 dwarf2_per_objfile
*per_objfile
)
25122 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
25124 if (per_objfile
->die_type_hash
== NULL
)
25127 ofs
.per_cu
= per_cu
;
25128 ofs
.sect_off
= sect_off
;
25129 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
25130 htab_find (per_objfile
->die_type_hash
.get (), &ofs
));
25137 /* Look up the type for DIE in CU in die_type_hash,
25138 or return NULL if DIE does not have a saved type. */
25140 static struct type
*
25141 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
25143 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
, cu
->per_objfile
);
25146 /* Add a dependence relationship from CU to REF_PER_CU. */
25149 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
25150 struct dwarf2_per_cu_data
*ref_per_cu
)
25154 if (cu
->dependencies
== NULL
)
25156 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
25157 NULL
, &cu
->comp_unit_obstack
,
25158 hashtab_obstack_allocate
,
25159 dummy_obstack_deallocate
);
25161 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
25163 *slot
= ref_per_cu
;
25166 /* Subroutine of dwarf2_mark to pass to htab_traverse.
25167 Set the mark field in every compilation unit in the
25168 cache that we must keep because we are keeping CU.
25170 DATA is the dwarf2_per_objfile object in which to look up CUs. */
25173 dwarf2_mark_helper (void **slot
, void *data
)
25175 dwarf2_per_cu_data
*per_cu
= (dwarf2_per_cu_data
*) *slot
;
25176 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) data
;
25177 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
25179 /* cu->dependencies references may not yet have been ever read if QUIT aborts
25180 reading of the chain. As such dependencies remain valid it is not much
25181 useful to track and undo them during QUIT cleanups. */
25190 if (cu
->dependencies
!= nullptr)
25191 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, per_objfile
);
25196 /* Set the mark field in CU and in every other compilation unit in the
25197 cache that we must keep because we are keeping CU. */
25200 dwarf2_mark (struct dwarf2_cu
*cu
)
25207 if (cu
->dependencies
!= nullptr)
25208 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, cu
->per_objfile
);
25211 /* Trivial hash function for partial_die_info: the hash value of a DIE
25212 is its offset in .debug_info for this objfile. */
25215 partial_die_hash (const void *item
)
25217 const struct partial_die_info
*part_die
25218 = (const struct partial_die_info
*) item
;
25220 return to_underlying (part_die
->sect_off
);
25223 /* Trivial comparison function for partial_die_info structures: two DIEs
25224 are equal if they have the same offset. */
25227 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
25229 const struct partial_die_info
*part_die_lhs
25230 = (const struct partial_die_info
*) item_lhs
;
25231 const struct partial_die_info
*part_die_rhs
25232 = (const struct partial_die_info
*) item_rhs
;
25234 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
25237 struct cmd_list_element
*set_dwarf_cmdlist
;
25238 struct cmd_list_element
*show_dwarf_cmdlist
;
25241 show_check_physname (struct ui_file
*file
, int from_tty
,
25242 struct cmd_list_element
*c
, const char *value
)
25244 fprintf_filtered (file
,
25245 _("Whether to check \"physname\" is %s.\n"),
25249 void _initialize_dwarf2_read ();
25251 _initialize_dwarf2_read ()
25253 add_basic_prefix_cmd ("dwarf", class_maintenance
, _("\
25254 Set DWARF specific variables.\n\
25255 Configure DWARF variables such as the cache size."),
25256 &set_dwarf_cmdlist
, "maintenance set dwarf ",
25257 0/*allow-unknown*/, &maintenance_set_cmdlist
);
25259 add_show_prefix_cmd ("dwarf", class_maintenance
, _("\
25260 Show DWARF specific variables.\n\
25261 Show DWARF variables such as the cache size."),
25262 &show_dwarf_cmdlist
, "maintenance show dwarf ",
25263 0/*allow-unknown*/, &maintenance_show_cmdlist
);
25265 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
25266 &dwarf_max_cache_age
, _("\
25267 Set the upper bound on the age of cached DWARF compilation units."), _("\
25268 Show the upper bound on the age of cached DWARF compilation units."), _("\
25269 A higher limit means that cached compilation units will be stored\n\
25270 in memory longer, and more total memory will be used. Zero disables\n\
25271 caching, which can slow down startup."),
25273 show_dwarf_max_cache_age
,
25274 &set_dwarf_cmdlist
,
25275 &show_dwarf_cmdlist
);
25277 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
25278 Set debugging of the DWARF reader."), _("\
25279 Show debugging of the DWARF reader."), _("\
25280 When enabled (non-zero), debugging messages are printed during DWARF\n\
25281 reading and symtab expansion. A value of 1 (one) provides basic\n\
25282 information. A value greater than 1 provides more verbose information."),
25285 &setdebuglist
, &showdebuglist
);
25287 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
25288 Set debugging of the DWARF DIE reader."), _("\
25289 Show debugging of the DWARF DIE reader."), _("\
25290 When enabled (non-zero), DIEs are dumped after they are read in.\n\
25291 The value is the maximum depth to print."),
25294 &setdebuglist
, &showdebuglist
);
25296 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
25297 Set debugging of the dwarf line reader."), _("\
25298 Show debugging of the dwarf line reader."), _("\
25299 When enabled (non-zero), line number entries are dumped as they are read in.\n\
25300 A value of 1 (one) provides basic information.\n\
25301 A value greater than 1 provides more verbose information."),
25304 &setdebuglist
, &showdebuglist
);
25306 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
25307 Set cross-checking of \"physname\" code against demangler."), _("\
25308 Show cross-checking of \"physname\" code against demangler."), _("\
25309 When enabled, GDB's internal \"physname\" code is checked against\n\
25311 NULL
, show_check_physname
,
25312 &setdebuglist
, &showdebuglist
);
25314 add_setshow_boolean_cmd ("use-deprecated-index-sections",
25315 no_class
, &use_deprecated_index_sections
, _("\
25316 Set whether to use deprecated gdb_index sections."), _("\
25317 Show whether to use deprecated gdb_index sections."), _("\
25318 When enabled, deprecated .gdb_index sections are used anyway.\n\
25319 Normally they are ignored either because of a missing feature or\n\
25320 performance issue.\n\
25321 Warning: This option must be enabled before gdb reads the file."),
25324 &setlist
, &showlist
);
25326 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
25327 &dwarf2_locexpr_funcs
);
25328 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
25329 &dwarf2_loclist_funcs
);
25331 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
25332 &dwarf2_block_frame_base_locexpr_funcs
);
25333 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
25334 &dwarf2_block_frame_base_loclist_funcs
);
25337 selftests::register_test ("dw2_expand_symtabs_matching",
25338 selftests::dw2_expand_symtabs_matching::run_test
);
25339 selftests::register_test ("dwarf2_find_containing_comp_unit",
25340 selftests::find_containing_comp_unit::run_test
);